UNPKG

@atlaskit/editor-plugin-expand

Version:

Expand plugin for @atlaskit/editor-core

64 lines • 3.91 kB
import { expandedState } from '@atlaskit/editor-common/expand'; import { expandClassNames } from '@atlaskit/editor-common/styles'; import { expandMessages } from '@atlaskit/editor-common/ui'; import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled'; import { fg } from '@atlaskit/platform-feature-flags/fg'; export const buildExpandClassName = (type, expanded) => { return `${expandClassNames.prefix} ${expandClassNames.type(type)} ${expanded ? expandClassNames.expanded : ''}`; }; export const getExpandBodyAriaLabel = (title, intl) => { const safeTitle = title.trim() || (intl === null || intl === void 0 ? void 0 : intl.formatMessage(expandMessages.expandBodyAriaLabelUntitled)) || expandMessages.expandBodyAriaLabelUntitled.defaultMessage; return (intl === null || intl === void 0 ? void 0 : intl.formatMessage(expandMessages.expandBodyAriaLabel, { title: safeTitle })) || expandMessages.expandBodyAriaLabel.defaultMessage.replace('{title}', safeTitle); }; export const toDOM = (node, __livePage, intl, titleReadOnly, contentEditable) => { var _expandedState$get, _node$attrs$title, _intl$formatMessage; 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 }]]], [isExperimentEnabled('platform_editor_expand_content_a11y_2') ? 'section' : 'div', { // prettier-ignore class: `${expandClassNames.content} ${expandedState.get(node) ? '' : expandClassNames.contentCollapsed}`, contenteditable: contentEditable !== undefined ? contentEditable ? 'true' : 'false' : undefined, ...(!isExperimentEnabled('platform_editor_expand_content_a11y_2') && { role: 'textbox', 'aria-multiline': 'true', 'aria-label': intl && intl.formatMessage(expandMessages.expandBodyAriaLabelOriginal) || expandMessages.expandBodyAriaLabelOriginal.defaultMessage }), ...(isExperimentEnabled('platform_editor_expand_content_a11y_2') && { 'aria-label': getExpandBodyAriaLabel((_node$attrs$title = node.attrs.title) !== null && _node$attrs$title !== void 0 ? _node$attrs$title : '', intl), 'aria-description': (intl === null || intl === void 0 ? void 0 : intl.formatMessage(expandMessages.expandBodyAriaDescription)) || expandMessages.expandBodyAriaDescription.defaultMessage, 'aria-roledescription': (_intl$formatMessage = intl === null || intl === void 0 ? void 0 : intl.formatMessage(expandMessages.expandBodyRoleDescription)) !== null && _intl$formatMessage !== void 0 ? _intl$formatMessage : expandMessages.expandBodyRoleDescription.defaultMessage }) }, 0]]; };