UNPKG

@atlaskit/editor-plugin-layout

Version:

Layout plugin for @atlaskit/editor-core

70 lines (69 loc) 3.8 kB
import _classCallCheck from "@babel/runtime/helpers/classCallCheck"; import _createClass from "@babel/runtime/helpers/createClass"; 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 { ignoreResizerMutations } from '@atlaskit/editor-common/resizer'; import { DOMSerializer } from '@atlaskit/editor-prosemirror/model'; import { fg } from '@atlaskit/platform-feature-flags/fg'; import { isEmptyLayout } from './utils'; var toDOM = function toDOM(node) { var _node$attrs$columnRul, _node$attrs$localId; return ['div', { class: 'layoutSectionView-content-wrap' }, ['div', { class: 'layout-section-container' }, ['div', _objectSpread({ 'data-layout-section': true, // `?? ''` keeps unset attributes out of the DOM as `"null"`, which adf-schema's`parseDOM` // reads back as a truthy string. 'data-column-rule-style': (_node$attrs$columnRul = node.attrs.columnRuleStyle) !== null && _node$attrs$columnRul !== void 0 ? _node$attrs$columnRul : '', 'data-empty-layout': String(isEmptyLayout(node)) }, fg('platform_editor_adf_with_localid') && { 'data-local-id': (_node$attrs$localId = node.attrs.localId) !== null && _node$attrs$localId !== void 0 ? _node$attrs$localId : '' }), 0]]]; }; /** * Requires `platform_editor_breakout_resizing` as well as * `platform_editor_vanilla_node_views_phase1`, because it cannot render the * React `<BreakoutResizer>` the old view mounts when that experiment is off. * * Also used for SSR, where it needs no `NodeViewContentHole` / * `data-ssr-content-dom-ref` handling — that exists only because the React * portal overwrites `container.innerHTML`. */ export var LayoutSectionView = /*#__PURE__*/function () { function LayoutSectionView(node) { _classCallCheck(this, LayoutSectionView); var _ref = DOMSerializer.renderSpec(document, toDOM(node)), dom = _ref.dom, contentDOM = _ref.contentDOM; this.dom = dom; this.contentDOM = contentDOM; this.node = node; } return _createClass(LayoutSectionView, [{ key: "update", value: function update(node) { if (node.attrs.columnRuleStyle !== this.node.attrs.columnRuleStyle) { var _node$attrs$columnRul2; this.contentDOM.setAttribute('data-column-rule-style', (_node$attrs$columnRul2 = node.attrs.columnRuleStyle) !== null && _node$attrs$columnRul2 !== void 0 ? _node$attrs$columnRul2 : ''); } var isEmpty = isEmptyLayout(node); if (isEmpty !== isEmptyLayout(this.node)) { this.contentDOM.setAttribute('data-empty-layout', String(isEmpty)); } if (fg('platform_editor_adf_with_localid') && node.attrs.localId !== this.node.attrs.localId) { var _node$attrs$localId2; this.contentDOM.setAttribute('data-local-id', (_node$attrs$localId2 = node.attrs.localId) !== null && _node$attrs$localId2 !== void 0 ? _node$attrs$localId2 : ''); } this.node = node; return true; } }, { key: "ignoreMutation", value: function ignoreMutation(mutation) { return ignoreResizerMutations(mutation); } }]); }();