UNPKG

@atlaskit/editor-plugin-expand

Version:

Expand plugin for @atlaskit/editor-core

47 lines 2.2 kB
import { expandedState } from '@atlaskit/editor-common/expand'; import { expandClassNames } from '@atlaskit/editor-common/styles'; import { expandMessages } from '@atlaskit/editor-common/ui'; import { fg } from '@atlaskit/platform-feature-flags'; export const buildExpandClassName = (type, expanded) => { return `${expandClassNames.prefix} ${expandClassNames.type(type)} ${expanded ? expandClassNames.expanded : ''}`; }; export const toDOM = (node, __livePage, intl, titleReadOnly, contentEditable) => { var _expandedState$get; return ['div', { // prettier-ignore 'class': buildExpandClassName(node.type.name, (_expandedState$get = expandedState.get(node)) !== null && _expandedState$get !== void 0 ? _expandedState$get : false), 'data-node-type': node.type.name, 'data-title': node.attrs.title, ...(fg('platform_editor_adf_with_localid') && { 'data-local-id': node.attrs.localId }) }, ['div', { // prettier-ignore 'class': expandClassNames.titleContainer, contenteditable: 'false', // Element gains access to focus events. // This is needed to prevent PM gaining access // on interacting with our controls. tabindex: '-1' }, // prettier-ignore ['div', { 'class': expandClassNames.icon, style: `display: flex; width: ${"var(--ds-space-300, 24px)"}; height: ${"var(--ds-space-300, 24px)"}` }], ['div', { // prettier-ignore 'class': expandClassNames.inputContainer }, ['input', { // prettier-ignore 'class': expandClassNames.titleInput, 'aria-label': intl && intl.formatMessage(expandMessages.expandArialabel) || expandMessages.expandArialabel.defaultMessage, value: node.attrs.title, placeholder: intl && typeof intl.formatMessage === 'function' && intl.formatMessage(expandMessages.expandPlaceholderText) || expandMessages.expandPlaceholderText.defaultMessage, type: 'text', readonly: titleReadOnly ? 'true' : undefined }]]], ['div', { // prettier-ignore class: `${expandClassNames.content} ${expandedState.get(node) ? '' : expandClassNames.contentCollapsed}`, contenteditable: contentEditable !== undefined ? contentEditable ? 'true' : 'false' : undefined }, 0]]; };