@atlaskit/editor-core 190.1.15 → 190.1.16

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/afm-cc/tsconfig.json +3 -0
  3. package/dist/cjs/plugins/index.js +0 -7
  4. package/dist/cjs/presets/universal.js +2 -1
  5. package/dist/cjs/version-wrapper.js +1 -1
  6. package/dist/es2019/plugins/index.js +0 -1
  7. package/dist/es2019/presets/universal.js +2 -1
  8. package/dist/es2019/version-wrapper.js +1 -1
  9. package/dist/esm/plugins/index.js +0 -1
  10. package/dist/esm/presets/universal.js +2 -1
  11. package/dist/esm/version-wrapper.js +1 -1
  12. package/dist/types/plugins/index.d.ts +0 -1
  13. package/dist/types-ts4.5/plugins/index.d.ts +0 -1
  14. package/package.json +2 -1
  15. package/tsconfig.json +1 -1
  16. package/dist/cjs/plugins/breakout/commands/remove-breakout.js +0 -30
  17. package/dist/cjs/plugins/breakout/commands/set-breakout-mode.js +0 -29
  18. package/dist/cjs/plugins/breakout/index.js +0 -218
  19. package/dist/cjs/plugins/breakout/plugin-key.js +0 -11
  20. package/dist/cjs/plugins/breakout/types.js +0 -5
  21. package/dist/cjs/plugins/breakout/ui/LayoutButton.js +0 -133
  22. package/dist/cjs/plugins/breakout/utils/find-breakout-node.js +0 -42
  23. package/dist/cjs/plugins/breakout/utils/get-breakout-mode.js +0 -24
  24. package/dist/cjs/plugins/breakout/utils/is-breakout-mark-allowed.js +0 -27
  25. package/dist/cjs/plugins/breakout/utils/is-supported-node.js +0 -15
  26. package/dist/es2019/plugins/breakout/commands/remove-breakout.js +0 -22
  27. package/dist/es2019/plugins/breakout/commands/set-breakout-mode.js +0 -23
  28. package/dist/es2019/plugins/breakout/index.js +0 -208
  29. package/dist/es2019/plugins/breakout/plugin-key.js +0 -3
  30. package/dist/es2019/plugins/breakout/types.js +0 -1
  31. package/dist/es2019/plugins/breakout/ui/LayoutButton.js +0 -117
  32. package/dist/es2019/plugins/breakout/utils/find-breakout-node.js +0 -37
  33. package/dist/es2019/plugins/breakout/utils/get-breakout-mode.js +0 -16
  34. package/dist/es2019/plugins/breakout/utils/is-breakout-mark-allowed.js +0 -22
  35. package/dist/es2019/plugins/breakout/utils/is-supported-node.js +0 -9
  36. package/dist/esm/plugins/breakout/commands/remove-breakout.js +0 -24
  37. package/dist/esm/plugins/breakout/commands/set-breakout-mode.js +0 -23
  38. package/dist/esm/plugins/breakout/index.js +0 -211
  39. package/dist/esm/plugins/breakout/plugin-key.js +0 -5
  40. package/dist/esm/plugins/breakout/types.js +0 -1
  41. package/dist/esm/plugins/breakout/ui/LayoutButton.js +0 -126
  42. package/dist/esm/plugins/breakout/utils/find-breakout-node.js +0 -37
  43. package/dist/esm/plugins/breakout/utils/get-breakout-mode.js +0 -18
  44. package/dist/esm/plugins/breakout/utils/is-breakout-mark-allowed.js +0 -22
  45. package/dist/esm/plugins/breakout/utils/is-supported-node.js +0 -9
  46. package/dist/types/plugins/breakout/commands/remove-breakout.d.ts +0 -2
  47. package/dist/types/plugins/breakout/commands/set-breakout-mode.d.ts +0 -3
  48. package/dist/types/plugins/breakout/index.d.ts +0 -12
  49. package/dist/types/plugins/breakout/plugin-key.d.ts +0 -5
  50. package/dist/types/plugins/breakout/types.d.ts +0 -4
  51. package/dist/types/plugins/breakout/ui/LayoutButton.d.ts +0 -17
  52. package/dist/types/plugins/breakout/utils/find-breakout-node.d.ts +0 -9
  53. package/dist/types/plugins/breakout/utils/get-breakout-mode.d.ts +0 -7
  54. package/dist/types/plugins/breakout/utils/is-breakout-mark-allowed.d.ts +0 -9
  55. package/dist/types/plugins/breakout/utils/is-supported-node.d.ts +0 -6
  56. package/dist/types-ts4.5/plugins/breakout/commands/remove-breakout.d.ts +0 -2
  57. package/dist/types-ts4.5/plugins/breakout/commands/set-breakout-mode.d.ts +0 -3
  58. package/dist/types-ts4.5/plugins/breakout/index.d.ts +0 -14
  59. package/dist/types-ts4.5/plugins/breakout/plugin-key.d.ts +0 -5
  60. package/dist/types-ts4.5/plugins/breakout/types.d.ts +0 -4
  61. package/dist/types-ts4.5/plugins/breakout/ui/LayoutButton.d.ts +0 -17
  62. package/dist/types-ts4.5/plugins/breakout/utils/find-breakout-node.d.ts +0 -9
  63. package/dist/types-ts4.5/plugins/breakout/utils/get-breakout-mode.d.ts +0 -7
  64. package/dist/types-ts4.5/plugins/breakout/utils/is-breakout-mark-allowed.d.ts +0 -9
  65. package/dist/types-ts4.5/plugins/breakout/utils/is-supported-node.d.ts +0 -6
@@ -1,42 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findSupportedNodeForBreakout = findSupportedNodeForBreakout;
7
- var _state = require("@atlaskit/editor-prosemirror/state");
8
- var _utils = require("@atlaskit/editor-prosemirror/utils");
9
- var _isSupportedNode = require("./is-supported-node");
10
- /**
11
- * Find the nearest parent node to the selection that supports breakout, or if the nearest
12
- * matching parent node is the doc, return undefined.
13
- * For depth, if a node is selected and supports breakout, return the depth of the node.
14
- * @param selection Current editor selection
15
- */
16
- function findSupportedNodeForBreakout(selection) {
17
- if (selection instanceof _state.NodeSelection) {
18
- var supportsBreakout = (0, _isSupportedNode.isSupportedNodeForBreakout)(selection.node);
19
- if (supportsBreakout) {
20
- return {
21
- pos: selection.from,
22
- start: selection.from,
23
- node: selection.node,
24
- // If a selected expand is in a doc, the depth of that expand is 0. Therefore
25
- // we don't need to subtract 1 or instantly return false if the depth is 0
26
- depth: selection.$anchor.depth
27
- };
28
- }
29
- }
30
- var breakoutNode = (0, _utils.findParentNode)(_isSupportedNode.isSupportedNodeForBreakout)(selection);
31
- if (!breakoutNode || breakoutNode.depth === 0) {
32
- // If this node doesn't exist or the only supporting node is the document
33
- // (with depth 0), then we're not inside a node that supports breakout
34
- return undefined;
35
- }
36
- return {
37
- node: breakoutNode.node,
38
- start: breakoutNode.start,
39
- pos: breakoutNode.pos,
40
- depth: breakoutNode.depth - 1
41
- };
42
- }
@@ -1,24 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getBreakoutMode = getBreakoutMode;
7
- var _findBreakoutNode = require("./find-breakout-node");
8
- /**
9
- * Get the current mode of the breakout at the selection
10
- * @param state Current EditorState
11
- */
12
- function getBreakoutMode(state) {
13
- var node = (0, _findBreakoutNode.findSupportedNodeForBreakout)(state.selection);
14
- if (!node) {
15
- return;
16
- }
17
- var breakoutMark = node.node.marks.find(function (m) {
18
- return m.type.name === 'breakout';
19
- });
20
- if (!breakoutMark) {
21
- return;
22
- }
23
- return breakoutMark.attrs.mode;
24
- }
@@ -1,27 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isBreakoutMarkAllowed = isBreakoutMarkAllowed;
7
- var _findBreakoutNode = require("./find-breakout-node");
8
- /**
9
- * Check if breakout should be allowed for the current selection. If a node is selected,
10
- * can this node be broken out, if text, can the enclosing parent node be broken out.
11
- *
12
- * Currently breakout of a node is not possible if it's nested in anything but the document, however
13
- * this logic supports this changing.
14
- */
15
- function isBreakoutMarkAllowed(state) {
16
- if (!state.schema.marks.breakout) {
17
- return false;
18
- }
19
- var supportedNodeParent = (0, _findBreakoutNode.findSupportedNodeForBreakout)(state.selection);
20
- if (!supportedNodeParent) {
21
- return false;
22
- }
23
- // At the moment we can only breakout when the depth is 0, ie. doc is the only node
24
- // that supports breakout. This *could* change though.
25
- var parent = state.selection.$from.node(supportedNodeParent.depth);
26
- return parent.type.allowsMarkType(state.schema.marks.breakout);
27
- }
@@ -1,15 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.isSupportedNodeForBreakout = isSupportedNodeForBreakout;
7
- var supportedNodesForBreakout = ['codeBlock', 'layoutSection', 'expand'];
8
-
9
- /**
10
- * Check if breakout can be applied to a node
11
- * @param node Node to check
12
- */
13
- function isSupportedNodeForBreakout(node) {
14
- return supportedNodesForBreakout.indexOf(node.type.name) !== -1;
15
- }
@@ -1,22 +0,0 @@
1
- import { findSupportedNodeForBreakout } from '../utils/find-breakout-node';
2
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- export function removeBreakout() {
4
- return (state, dispatch) => {
5
- const node = findSupportedNodeForBreakout(state.selection);
6
- if (!node) {
7
- return false;
8
- }
9
- const marks = node.node.marks.filter(m => m.type.name !== 'breakout');
10
- const tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, marks);
11
- tr.setMeta('scrollIntoView', false);
12
- if (state.selection instanceof NodeSelection) {
13
- if (state.selection.$anchor.pos === node.pos) {
14
- tr.setSelection(NodeSelection.create(tr.doc, node.pos));
15
- }
16
- }
17
- if (dispatch) {
18
- dispatch(tr);
19
- }
20
- return true;
21
- };
22
- }
@@ -1,23 +0,0 @@
1
- import { findSupportedNodeForBreakout } from '../utils/find-breakout-node';
2
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- export function setBreakoutMode(mode) {
4
- return (state, dispatch) => {
5
- const node = findSupportedNodeForBreakout(state.selection);
6
- if (!node) {
7
- return false;
8
- }
9
- const tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, [state.schema.marks.breakout.create({
10
- mode
11
- })]);
12
- tr.setMeta('scrollIntoView', false);
13
- if (state.selection instanceof NodeSelection) {
14
- if (state.selection.$anchor.pos === node.pos) {
15
- tr.setSelection(NodeSelection.create(tr.doc, node.pos));
16
- }
17
- }
18
- if (dispatch) {
19
- dispatch(tr);
20
- }
21
- return true;
22
- };
23
- }
@@ -1,208 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React from 'react';
3
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
- import { breakout } from '@atlaskit/adf-schema';
5
- import { calcBreakoutWidthPx } from '@atlaskit/editor-common/utils';
6
- import LayoutButton from './ui/LayoutButton';
7
- import { pluginKey } from './plugin-key';
8
- import { findSupportedNodeForBreakout } from './utils/find-breakout-node';
9
- import { akEditorSwoopCubicBezier } from '@atlaskit/editor-shared-styles';
10
- import { BreakoutCssClassName } from '@atlaskit/editor-common/styles';
11
- import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
12
- class BreakoutView {
13
- constructor(
14
- /**
15
- * Note: this is actually a PMMark -- however our version
16
- * of the prosemirror and prosemirror types mean using PMNode
17
- * is not problematic.
18
- */
19
- mark, view, pluginInjectionApi) {
20
- _defineProperty(this, "updateWidth", widthState => {
21
- // we skip updating the width of breakout nodes if the editorView dom
22
- // element was hidden (to avoid breakout width and button thrashing
23
- // when an editor is hidden, re-rendered and unhidden).
24
- if (widthState === undefined || widthState.width === 0) {
25
- return;
26
- }
27
- let containerStyle = ``;
28
- let contentStyle = ``;
29
- let breakoutWidthPx = calcBreakoutWidthPx(this.mark.attrs.mode, widthState.width);
30
- if (widthState.lineLength) {
31
- if (breakoutWidthPx < widthState.lineLength) {
32
- breakoutWidthPx = widthState.lineLength;
33
- }
34
- containerStyle += `
35
- transform: none;
36
- display: flex;
37
- justify-content: center;
38
- `;
39
-
40
- // There is a delay in the animation because widthState is delayed.
41
- // When the editor goes full width the animation for the editor
42
- // begins and finishes before widthState can update the new dimensions.
43
- contentStyle += `
44
- min-width: ${breakoutWidthPx}px;
45
- transition: min-width 0.5s ${akEditorSwoopCubicBezier};
46
- `;
47
- } else {
48
- // fallback method
49
- // (lineLength is not normally undefined, but might be in e.g. SSR or initial render)
50
- //
51
- // this approach doesn't work well with position: fixed, so
52
- // it breaks things like sticky headers
53
- containerStyle += `width: ${breakoutWidthPx}px; transform: translateX(-50%); margin-left: 50%;`;
54
- }
55
-
56
- // NOTE: This is a hack to ignore mutation since mark NodeView doesn't support
57
- // `ignoreMutation` life-cycle event. @see ED-9947
58
- const viewDomObserver = this.view.domObserver;
59
- if (viewDomObserver && this.view.dom) {
60
- viewDomObserver.stop();
61
- setTimeout(() => {
62
- viewDomObserver.start();
63
- }, 0);
64
- }
65
- if (typeof this.dom.style.cssText !== 'undefined') {
66
- this.dom.style.cssText = containerStyle;
67
- this.contentDOM.style.cssText = contentStyle;
68
- } else {
69
- this.dom.setAttribute('style', containerStyle);
70
- this.contentDOM.setAttribute('style', contentStyle);
71
- }
72
- });
73
- const contentDOM = document.createElement('div');
74
- contentDOM.className = BreakoutCssClassName.BREAKOUT_MARK_DOM;
75
- const dom = document.createElement('div');
76
- dom.className = BreakoutCssClassName.BREAKOUT_MARK;
77
- dom.setAttribute('data-layout', mark.attrs.mode);
78
- dom.appendChild(contentDOM);
79
- this.dom = dom;
80
- this.mark = mark;
81
- this.view = view;
82
- this.contentDOM = contentDOM;
83
- this.unsubscribe = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.width.sharedState.onChange(({
84
- nextSharedState
85
- }) => this.updateWidth(nextSharedState));
86
- this.updateWidth(pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.width.sharedState.currentState());
87
- }
88
- // NOTE: Lifecycle events doesn't work for mark NodeView. So currently this is a no-op.
89
- // @see https://github.com/ProseMirror/prosemirror/issues/1082
90
- destroy() {
91
- var _this$unsubscribe;
92
- (_this$unsubscribe = this.unsubscribe) === null || _this$unsubscribe === void 0 ? void 0 : _this$unsubscribe.call(this);
93
- }
94
- }
95
- function shouldPluginStateUpdate(newBreakoutNode, currentBreakoutNode) {
96
- if (newBreakoutNode && currentBreakoutNode) {
97
- return newBreakoutNode !== currentBreakoutNode;
98
- }
99
- return newBreakoutNode || currentBreakoutNode ? true : false;
100
- }
101
- function createPlugin(pluginInjectionApi, {
102
- dispatch
103
- }) {
104
- return new SafePlugin({
105
- state: {
106
- init() {
107
- return {
108
- breakoutNode: undefined
109
- };
110
- },
111
- apply(tr, pluginState) {
112
- const breakoutNode = findSupportedNodeForBreakout(tr.selection);
113
- if (shouldPluginStateUpdate(breakoutNode, pluginState.breakoutNode)) {
114
- const nextPluginState = {
115
- ...pluginState,
116
- breakoutNode
117
- };
118
- dispatch(pluginKey, nextPluginState);
119
- return nextPluginState;
120
- }
121
- return pluginState;
122
- }
123
- },
124
- key: pluginKey,
125
- props: {
126
- nodeViews: {
127
- // Note: When we upgrade to prosemirror 1.27.2 -- we should
128
- // move this to markViews.
129
- // See the following link for more details:
130
- // https://prosemirror.net/docs/ref/#view.EditorProps.nodeViews.
131
- breakout: (mark, view) => {
132
- return new BreakoutView(mark, view, pluginInjectionApi);
133
- }
134
- }
135
- }
136
- });
137
- }
138
- const LayoutButtonWrapper = ({
139
- api,
140
- editorView,
141
- boundariesElement,
142
- scrollableElement,
143
- mountPoint
144
- }) => {
145
- var _breakoutState$breako, _breakoutState$breako2;
146
- // Re-render with `width` (but don't use state) due to https://bitbucket.org/atlassian/%7Bc8e2f021-38d2-46d0-9b7a-b3f7b428f724%7D/pull-requests/24272
147
- const {
148
- breakoutState
149
- } = useSharedPluginState(api, ['width', 'breakout']);
150
- return /*#__PURE__*/React.createElement(LayoutButton, {
151
- editorView: editorView,
152
- mountPoint: mountPoint,
153
- boundariesElement: boundariesElement,
154
- scrollableElement: scrollableElement,
155
- node: (_breakoutState$breako = breakoutState === null || breakoutState === void 0 ? void 0 : (_breakoutState$breako2 = breakoutState.breakoutNode) === null || _breakoutState$breako2 === void 0 ? void 0 : _breakoutState$breako2.node) !== null && _breakoutState$breako !== void 0 ? _breakoutState$breako : null
156
- });
157
- };
158
- const breakoutPlugin = ({
159
- config: options,
160
- api
161
- }) => ({
162
- name: 'breakout',
163
- pmPlugins() {
164
- return [{
165
- name: 'breakout',
166
- plugin: props => createPlugin(api, props)
167
- }];
168
- },
169
- marks() {
170
- return [{
171
- name: 'breakout',
172
- mark: breakout
173
- }];
174
- },
175
- getSharedState(editorState) {
176
- if (!editorState) {
177
- return {
178
- breakoutNode: undefined
179
- };
180
- }
181
- const pluginState = pluginKey.getState(editorState);
182
- if (!pluginState) {
183
- return {
184
- breakoutNode: undefined
185
- };
186
- }
187
- return pluginState;
188
- },
189
- contentComponent({
190
- editorView,
191
- popupsMountPoint,
192
- popupsBoundariesElement,
193
- popupsScrollableElement
194
- }) {
195
- // This is a bit crappy, but should be resolved once we move to a static schema.
196
- if (options && !options.allowBreakoutButton) {
197
- return null;
198
- }
199
- return /*#__PURE__*/React.createElement(LayoutButtonWrapper, {
200
- api: api,
201
- mountPoint: popupsMountPoint,
202
- editorView: editorView,
203
- boundariesElement: popupsBoundariesElement,
204
- scrollableElement: popupsScrollableElement
205
- });
206
- }
207
- });
208
- export default breakoutPlugin;
@@ -1,3 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export const pluginKey = new PluginKey('breakoutPlugin');
3
- export const getPluginState = state => pluginKey.getState(state) || undefined;
@@ -1 +0,0 @@
1
- export {};
@@ -1,117 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- /** @jsx jsx */
3
- import React from 'react';
4
- import { css, jsx } from '@emotion/react';
5
- import { B300, N300, N20A } from '@atlaskit/theme/colors';
6
- import { injectIntl } from 'react-intl-next';
7
- import { findParentDomRefOfType, findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
8
- import { Popup } from '@atlaskit/editor-common/ui';
9
- import CollapseIcon from '@atlaskit/icon/glyph/editor/collapse';
10
- import ExpandIcon from '@atlaskit/icon/glyph/editor/expand';
11
- import ToolbarButton from '../../../ui/ToolbarButton';
12
- import { getBreakoutMode } from '../utils/get-breakout-mode';
13
- import { setBreakoutMode } from '../commands/set-breakout-mode';
14
- import { removeBreakout } from '../commands/remove-breakout';
15
- import { BreakoutCssClassName } from '@atlaskit/editor-common/styles';
16
- import { isBreakoutMarkAllowed } from '../utils/is-breakout-mark-allowed';
17
- import { getPluginState } from '../plugin-key';
18
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
19
- import { isSupportedNodeForBreakout } from '../utils/is-supported-node';
20
- import { layers } from '@atlaskit/theme/constants';
21
- import { getNextBreakoutMode, getTitle } from '@atlaskit/editor-common/utils';
22
- const toolbarButtonWrapper = css`
23
- && button {
24
- background: ${`var(--ds-background-neutral, ${N20A})`};
25
- color: ${`var(--ds-icon, ${N300})`};
26
- :hover {
27
- background: ${`var(--ds-background-neutral-hovered, ${B300})`};
28
- color: ${"var(--ds-icon, white)"} !important;
29
- }
30
- }
31
- `;
32
- function getBreakoutNodeElement(pluginState, selection, editorView) {
33
- if (!pluginState.breakoutNode) {
34
- return undefined;
35
- }
36
- if (selection instanceof NodeSelection && isSupportedNodeForBreakout(selection.node)) {
37
- return findDomRefAtPos(selection.from, editorView.domAtPos.bind(editorView));
38
- }
39
- return findParentDomRefOfType(pluginState.breakoutNode.node.type, editorView.domAtPos.bind(editorView))(selection);
40
- }
41
- class LayoutButton extends React.Component {
42
- constructor(...args) {
43
- super(...args);
44
- _defineProperty(this, "handleClick", breakoutMode => () => {
45
- const {
46
- state,
47
- dispatch
48
- } = this.props.editorView;
49
- if (['wide', 'full-width'].indexOf(breakoutMode) !== -1) {
50
- setBreakoutMode(breakoutMode)(state, dispatch);
51
- } else {
52
- removeBreakout()(state, dispatch);
53
- }
54
- });
55
- }
56
- render() {
57
- const {
58
- intl: {
59
- formatMessage
60
- },
61
- mountPoint,
62
- boundariesElement,
63
- scrollableElement,
64
- editorView,
65
- node
66
- } = this.props;
67
- const {
68
- state
69
- } = editorView;
70
- if (!node || !isBreakoutMarkAllowed(state)) {
71
- return null;
72
- }
73
- const breakoutMode = getBreakoutMode(editorView.state);
74
- const titleMessage = getTitle(breakoutMode);
75
- const title = formatMessage(titleMessage);
76
- const nextBreakoutMode = getNextBreakoutMode(breakoutMode);
77
- const belowOtherPopupsZIndex = layers.layer() - 1;
78
- let pluginState = getPluginState(state);
79
- if (!pluginState) {
80
- return null;
81
- }
82
- let element = getBreakoutNodeElement(pluginState, state.selection, editorView);
83
- if (!element) {
84
- return null;
85
- }
86
- const closestEl = element.querySelector(`.${BreakoutCssClassName.BREAKOUT_MARK_DOM}`);
87
- if (closestEl && closestEl.firstChild) {
88
- element = closestEl.firstChild;
89
- }
90
- return jsx(Popup, {
91
- ariaLabel: title,
92
- target: element,
93
- offset: [5, 0],
94
- alignY: "start",
95
- alignX: "end",
96
- mountTo: mountPoint,
97
- boundariesElement: boundariesElement,
98
- scrollableElement: scrollableElement,
99
- stick: true,
100
- forcePlacement: true,
101
- zIndex: belowOtherPopupsZIndex
102
- }, jsx("div", {
103
- css: toolbarButtonWrapper
104
- }, jsx(ToolbarButton, {
105
- title: title,
106
- testId: titleMessage.id,
107
- onClick: this.handleClick(nextBreakoutMode),
108
- iconBefore: breakoutMode === 'full-width' ? jsx(CollapseIcon, {
109
- label: title
110
- }) : jsx(ExpandIcon, {
111
- label: title
112
- })
113
- })));
114
- }
115
- }
116
- _defineProperty(LayoutButton, "displayName", 'LayoutButton');
117
- export default injectIntl(LayoutButton);
@@ -1,37 +0,0 @@
1
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
2
- import { findParentNode } from '@atlaskit/editor-prosemirror/utils';
3
- import { isSupportedNodeForBreakout } from './is-supported-node';
4
-
5
- /**
6
- * Find the nearest parent node to the selection that supports breakout, or if the nearest
7
- * matching parent node is the doc, return undefined.
8
- * For depth, if a node is selected and supports breakout, return the depth of the node.
9
- * @param selection Current editor selection
10
- */
11
- export function findSupportedNodeForBreakout(selection) {
12
- if (selection instanceof NodeSelection) {
13
- const supportsBreakout = isSupportedNodeForBreakout(selection.node);
14
- if (supportsBreakout) {
15
- return {
16
- pos: selection.from,
17
- start: selection.from,
18
- node: selection.node,
19
- // If a selected expand is in a doc, the depth of that expand is 0. Therefore
20
- // we don't need to subtract 1 or instantly return false if the depth is 0
21
- depth: selection.$anchor.depth
22
- };
23
- }
24
- }
25
- const breakoutNode = findParentNode(isSupportedNodeForBreakout)(selection);
26
- if (!breakoutNode || breakoutNode.depth === 0) {
27
- // If this node doesn't exist or the only supporting node is the document
28
- // (with depth 0), then we're not inside a node that supports breakout
29
- return undefined;
30
- }
31
- return {
32
- node: breakoutNode.node,
33
- start: breakoutNode.start,
34
- pos: breakoutNode.pos,
35
- depth: breakoutNode.depth - 1
36
- };
37
- }
@@ -1,16 +0,0 @@
1
- import { findSupportedNodeForBreakout } from './find-breakout-node';
2
- /**
3
- * Get the current mode of the breakout at the selection
4
- * @param state Current EditorState
5
- */
6
- export function getBreakoutMode(state) {
7
- const node = findSupportedNodeForBreakout(state.selection);
8
- if (!node) {
9
- return;
10
- }
11
- const breakoutMark = node.node.marks.find(m => m.type.name === 'breakout');
12
- if (!breakoutMark) {
13
- return;
14
- }
15
- return breakoutMark.attrs.mode;
16
- }
@@ -1,22 +0,0 @@
1
- import { findSupportedNodeForBreakout } from './find-breakout-node';
2
-
3
- /**
4
- * Check if breakout should be allowed for the current selection. If a node is selected,
5
- * can this node be broken out, if text, can the enclosing parent node be broken out.
6
- *
7
- * Currently breakout of a node is not possible if it's nested in anything but the document, however
8
- * this logic supports this changing.
9
- */
10
- export function isBreakoutMarkAllowed(state) {
11
- if (!state.schema.marks.breakout) {
12
- return false;
13
- }
14
- const supportedNodeParent = findSupportedNodeForBreakout(state.selection);
15
- if (!supportedNodeParent) {
16
- return false;
17
- }
18
- // At the moment we can only breakout when the depth is 0, ie. doc is the only node
19
- // that supports breakout. This *could* change though.
20
- const parent = state.selection.$from.node(supportedNodeParent.depth);
21
- return parent.type.allowsMarkType(state.schema.marks.breakout);
22
- }
@@ -1,9 +0,0 @@
1
- const supportedNodesForBreakout = ['codeBlock', 'layoutSection', 'expand'];
2
-
3
- /**
4
- * Check if breakout can be applied to a node
5
- * @param node Node to check
6
- */
7
- export function isSupportedNodeForBreakout(node) {
8
- return supportedNodesForBreakout.indexOf(node.type.name) !== -1;
9
- }
@@ -1,24 +0,0 @@
1
- import { findSupportedNodeForBreakout } from '../utils/find-breakout-node';
2
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- export function removeBreakout() {
4
- return function (state, dispatch) {
5
- var node = findSupportedNodeForBreakout(state.selection);
6
- if (!node) {
7
- return false;
8
- }
9
- var marks = node.node.marks.filter(function (m) {
10
- return m.type.name !== 'breakout';
11
- });
12
- var tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, marks);
13
- tr.setMeta('scrollIntoView', false);
14
- if (state.selection instanceof NodeSelection) {
15
- if (state.selection.$anchor.pos === node.pos) {
16
- tr.setSelection(NodeSelection.create(tr.doc, node.pos));
17
- }
18
- }
19
- if (dispatch) {
20
- dispatch(tr);
21
- }
22
- return true;
23
- };
24
- }
@@ -1,23 +0,0 @@
1
- import { findSupportedNodeForBreakout } from '../utils/find-breakout-node';
2
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- export function setBreakoutMode(mode) {
4
- return function (state, dispatch) {
5
- var node = findSupportedNodeForBreakout(state.selection);
6
- if (!node) {
7
- return false;
8
- }
9
- var tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, [state.schema.marks.breakout.create({
10
- mode: mode
11
- })]);
12
- tr.setMeta('scrollIntoView', false);
13
- if (state.selection instanceof NodeSelection) {
14
- if (state.selection.$anchor.pos === node.pos) {
15
- tr.setSelection(NodeSelection.create(tr.doc, node.pos));
16
- }
17
- }
18
- if (dispatch) {
19
- dispatch(tr);
20
- }
21
- return true;
22
- };
23
- }