UNPKG

@atlaskit/editor-plugin-expand

Version:

Expand plugin for @atlaskit/editor-core

49 lines 3.05 kB
import _defineProperty from "@babel/runtime/helpers/defineProperty"; function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } 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 var buildExpandClassName = function buildExpandClassName(type, expanded) { return "".concat(expandClassNames.prefix, " ").concat(expandClassNames.type(type), " ").concat(expanded ? expandClassNames.expanded : ''); }; export var toDOM = function toDOM(node, __livePage, intl, titleReadOnly, contentEditable) { var _expandedState$get; return ['div', _objectSpread({ // 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: ".concat("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: "".concat(expandClassNames.content, " ").concat(expandedState.get(node) ? '' : expandClassNames.contentCollapsed), contenteditable: contentEditable !== undefined ? contentEditable ? 'true' : 'false' : undefined }, 0]]; };