@atlaskit/editor-plugin-breakout 24.0.2 → 24.0.4

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 (40) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/breakoutPlugin.js +21 -229
  3. package/dist/cjs/pm-plugins/utils/single-player-expand.js +6 -17
  4. package/dist/es2019/breakoutPlugin.js +13 -211
  5. package/dist/es2019/pm-plugins/utils/single-player-expand.js +6 -17
  6. package/dist/esm/breakoutPlugin.js +21 -227
  7. package/dist/esm/pm-plugins/utils/single-player-expand.js +6 -17
  8. package/package.json +2 -2
  9. package/dist/cjs/editor-commands/remove-breakout.js +0 -41
  10. package/dist/cjs/editor-commands/set-breakout-mode.js +0 -49
  11. package/dist/cjs/pm-plugins/plugin-key.js +0 -11
  12. package/dist/cjs/pm-plugins/utils/find-breakout-node.js +0 -42
  13. package/dist/cjs/pm-plugins/utils/get-breakout-mode.js +0 -24
  14. package/dist/cjs/pm-plugins/utils/is-breakout-mark-allowed.js +0 -27
  15. package/dist/cjs/pm-plugins/utils/is-supported-node.js +0 -20
  16. package/dist/cjs/ui/LayoutButton.js +0 -176
  17. package/dist/es2019/editor-commands/remove-breakout.js +0 -33
  18. package/dist/es2019/editor-commands/set-breakout-mode.js +0 -43
  19. package/dist/es2019/pm-plugins/plugin-key.js +0 -3
  20. package/dist/es2019/pm-plugins/utils/find-breakout-node.js +0 -37
  21. package/dist/es2019/pm-plugins/utils/get-breakout-mode.js +0 -17
  22. package/dist/es2019/pm-plugins/utils/is-breakout-mark-allowed.js +0 -22
  23. package/dist/es2019/pm-plugins/utils/is-supported-node.js +0 -14
  24. package/dist/es2019/ui/LayoutButton.js +0 -171
  25. package/dist/esm/editor-commands/remove-breakout.js +0 -35
  26. package/dist/esm/editor-commands/set-breakout-mode.js +0 -43
  27. package/dist/esm/pm-plugins/plugin-key.js +0 -5
  28. package/dist/esm/pm-plugins/utils/find-breakout-node.js +0 -37
  29. package/dist/esm/pm-plugins/utils/get-breakout-mode.js +0 -19
  30. package/dist/esm/pm-plugins/utils/is-breakout-mark-allowed.js +0 -22
  31. package/dist/esm/pm-plugins/utils/is-supported-node.js +0 -14
  32. package/dist/esm/ui/LayoutButton.js +0 -166
  33. package/dist/types/editor-commands/remove-breakout.d.ts +0 -2
  34. package/dist/types/editor-commands/set-breakout-mode.d.ts +0 -2
  35. package/dist/types/pm-plugins/plugin-key.d.ts +0 -5
  36. package/dist/types/pm-plugins/utils/find-breakout-node.d.ts +0 -9
  37. package/dist/types/pm-plugins/utils/get-breakout-mode.d.ts +0 -7
  38. package/dist/types/pm-plugins/utils/is-breakout-mark-allowed.d.ts +0 -9
  39. package/dist/types/pm-plugins/utils/is-supported-node.d.ts +0 -6
  40. package/dist/types/ui/LayoutButton.d.ts +0 -20
@@ -1,176 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.default = void 0;
8
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
- var _react = require("react");
10
- var _react2 = require("@emotion/react");
11
- var _reactIntl = require("react-intl");
12
- var _analytics = require("@atlaskit/editor-common/analytics");
13
- var _styles = require("@atlaskit/editor-common/styles");
14
- var _ui = require("@atlaskit/editor-common/ui");
15
- var _uiMenu = require("@atlaskit/editor-common/ui-menu");
16
- var _utils = require("@atlaskit/editor-common/utils");
17
- var _state = require("@atlaskit/editor-prosemirror/state");
18
- var _utils2 = require("@atlaskit/editor-prosemirror/utils");
19
- var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
20
- var _growHorizontal = _interopRequireDefault(require("@atlaskit/icon/core/grow-horizontal"));
21
- var _shrinkHorizontal = _interopRequireDefault(require("@atlaskit/icon/core/shrink-horizontal"));
22
- var _constants = require("@atlaskit/theme/constants");
23
- var _editorExperiment = require("@atlaskit/tmp-editor-statsig/editor-experiment");
24
- var _removeBreakout = require("../editor-commands/remove-breakout");
25
- var _setBreakoutMode = require("../editor-commands/set-breakout-mode");
26
- var _pluginKey = require("../pm-plugins/plugin-key");
27
- var _isBreakoutMarkAllowed = require("../pm-plugins/utils/is-breakout-mark-allowed");
28
- var _isSupportedNode = require("../pm-plugins/utils/is-supported-node");
29
- /**
30
- * @jsxRuntime classic
31
- * @jsx jsx
32
- */
33
-
34
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
35
-
36
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-atlaskit-theme
37
-
38
- var toolbarButtonWrapperStyles = (0, _react2.css)({
39
- // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
40
- '&& button': {
41
- background: "var(--ds-background-neutral, #0515240F)",
42
- color: "var(--ds-icon, #292A2E)",
43
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
44
- ':hover': {
45
- background: "var(--ds-background-neutral-hovered, #0B120E24)",
46
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
47
- color: "var(--ds-icon, #292A2E)".concat(" !important")
48
- }
49
- }
50
- });
51
- var toolbarButtonNarrowScreenStyles = (0, _react2.css)((0, _defineProperty2.default)({}, "@container editor-area (max-width: ".concat(_editorSharedStyles.akEditorFullPageNarrowBreakout, "px)"), {
52
- // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
53
- '&& button': {
54
- visibility: 'hidden',
55
- opacity: 0
56
- }
57
- }));
58
- function getBreakoutNodeElement(pluginState, selection, editorView) {
59
- if (!pluginState.breakoutNode) {
60
- return undefined;
61
- }
62
- if (selection instanceof _state.NodeSelection && (0, _isSupportedNode.isSupportedNodeForBreakout)(selection.node)) {
63
- // Ignored via go/ees005
64
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
65
- return (0, _utils2.findDomRefAtPos)(selection.from, editorView.domAtPos.bind(editorView));
66
- }
67
- // Ignored via go/ees005
68
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
69
- return (0, _utils2.findParentDomRefOfType)(pluginState.breakoutNode.node.type, editorView.domAtPos.bind(editorView))(selection);
70
- }
71
- var LayoutButton = function LayoutButton(_ref) {
72
- var _api$analytics3;
73
- var formatMessage = _ref.intl.formatMessage,
74
- mountPoint = _ref.mountPoint,
75
- boundariesElement = _ref.boundariesElement,
76
- scrollableElement = _ref.scrollableElement,
77
- editorView = _ref.editorView,
78
- isLivePage = _ref.isLivePage,
79
- isBreakoutNodePresent = _ref.isBreakoutNodePresent,
80
- breakoutModeProp = _ref.breakoutMode,
81
- api = _ref.api;
82
- var handleClick = (0, _react.useCallback)(function (breakoutMode) {
83
- var _getPluginState;
84
- if (!editorView) {
85
- return;
86
- }
87
- var state = editorView.state,
88
- dispatch = editorView.dispatch;
89
- var breakoutNode = (_getPluginState = (0, _pluginKey.getPluginState)(state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.breakoutNode;
90
- if (['wide', 'full-width'].indexOf(breakoutMode) !== -1) {
91
- var _api$analytics;
92
- (0, _setBreakoutMode.setBreakoutMode)(breakoutMode, isLivePage)(state, dispatch);
93
- api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 || _api$analytics.actions.fireAnalyticsEvent({
94
- action: _analytics.ACTION.CHANGED_BREAKOUT_MODE,
95
- actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
96
- eventType: _analytics.EVENT_TYPE.TRACK,
97
- attributes: {
98
- mode: breakoutMode,
99
- nodeType: breakoutNode === null || breakoutNode === void 0 ? void 0 : breakoutNode.node.type.name
100
- }
101
- });
102
- } else {
103
- var _api$analytics2;
104
- (0, _removeBreakout.removeBreakout)(isLivePage)(state, dispatch);
105
- api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 || _api$analytics2.actions.fireAnalyticsEvent({
106
- action: _analytics.ACTION.CHANGED_BREAKOUT_MODE,
107
- actionSubject: _analytics.ACTION_SUBJECT.ELEMENT,
108
- eventType: _analytics.EVENT_TYPE.TRACK,
109
- attributes: {
110
- mode: 'center',
111
- nodeType: breakoutNode === null || breakoutNode === void 0 ? void 0 : breakoutNode.node.type.name
112
- }
113
- });
114
- }
115
- }, [api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, editorView, isLivePage]);
116
- if (!editorView) {
117
- return null;
118
- }
119
- if (!isBreakoutNodePresent || !(0, _isBreakoutMarkAllowed.isBreakoutMarkAllowed)(editorView.state)) {
120
- return null;
121
- }
122
- var breakoutMode = breakoutModeProp;
123
- var titleMessage = (0, _utils.getTitle)(breakoutMode);
124
- var title = formatMessage(titleMessage);
125
- var nextBreakoutMode = (0, _utils.getNextBreakoutMode)(breakoutMode);
126
- var belowOtherPopupsZIndex = _constants.layers.layer() - 1;
127
- var pluginState = (0, _pluginKey.getPluginState)(editorView.state);
128
- if (!pluginState) {
129
- return null;
130
- }
131
- var element = getBreakoutNodeElement(pluginState, editorView.state.selection, editorView);
132
- if (!element) {
133
- return null;
134
- }
135
- var closestEl = element.querySelector(".".concat(_styles.BreakoutCssClassName.BREAKOUT_MARK_DOM));
136
- if (closestEl && closestEl.firstChild) {
137
- // Ignored via go/ees005
138
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
139
- element = closestEl.firstChild;
140
- }
141
- return (0, _react2.jsx)(_ui.Popup, {
142
- ariaLabel: title,
143
- target: element
144
- // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
145
- ,
146
- offset: [5, 0],
147
- alignY: "start",
148
- alignX: "end",
149
- mountTo: mountPoint,
150
- boundariesElement: boundariesElement,
151
- scrollableElement: scrollableElement,
152
- stick: true,
153
- forcePlacement: true,
154
- zIndex: belowOtherPopupsZIndex
155
- }, (0, _react2.jsx)("div", {
156
- css: [toolbarButtonWrapperStyles, (0, _editorExperiment.editorExperiment)('platform_editor_preview_panel_responsiveness', true) && toolbarButtonNarrowScreenStyles]
157
- }, (0, _react2.jsx)(_uiMenu.ToolbarButton, {
158
- title: title,
159
- testId: titleMessage.id
160
- // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
161
- ,
162
- onClick: function onClick() {
163
- return handleClick(nextBreakoutMode);
164
- },
165
- iconBefore: breakoutMode === 'full-width' ? (0, _react2.jsx)(_shrinkHorizontal.default, {
166
- label: title,
167
- spacing: "spacious"
168
- }) : (0, _react2.jsx)(_growHorizontal.default, {
169
- label: title,
170
- spacing: "spacious"
171
- })
172
- })));
173
- };
174
- LayoutButton.displayName = 'LayoutButton';
175
- var _default_1 = (0, _reactIntl.injectIntl)(LayoutButton);
176
- var _default = exports.default = _default_1;
@@ -1,33 +0,0 @@
1
- import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
2
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { findSupportedNodeForBreakout } from '../pm-plugins/utils/find-breakout-node';
4
- import { updateExpandedState } from '../pm-plugins/utils/single-player-expand';
5
- export function removeBreakout(isLivePage) {
6
- return (state, dispatch) => {
7
- const node = findSupportedNodeForBreakout(state.selection);
8
- if (!node) {
9
- return false;
10
- }
11
- const marks = node.node.marks.filter(m => m.type.name !== 'breakout');
12
- const tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, marks);
13
- if (node.node.type === state.schema.nodes.expand) {
14
- updateExpandedState(tr, node, isLivePage);
15
- } else if (node.node.type === state.schema.nodes.codeBlock) {
16
- const newNode = tr.doc.nodeAt(node.pos);
17
- const oldNode = node.node;
18
- if (newNode) {
19
- transferCodeBlockWrappedValue(oldNode, newNode);
20
- }
21
- }
22
- tr.setMeta('scrollIntoView', false);
23
- if (state.selection instanceof NodeSelection) {
24
- if (state.selection.$anchor.pos === node.pos) {
25
- tr.setSelection(NodeSelection.create(tr.doc, node.pos));
26
- }
27
- }
28
- if (dispatch) {
29
- dispatch(tr);
30
- }
31
- return true;
32
- };
33
- }
@@ -1,43 +0,0 @@
1
- import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
2
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
4
- import { findSupportedNodeForBreakout } from '../pm-plugins/utils/find-breakout-node';
5
- import { updateExpandedState } from '../pm-plugins/utils/single-player-expand';
6
- export function setBreakoutMode(mode, isLivePage) {
7
- return (state, dispatch) => {
8
- const node = findSupportedNodeForBreakout(state.selection);
9
- if (!node) {
10
- return false;
11
- }
12
- let tr;
13
- if (isExperimentEnabled('platform_editor_lovability_resize_extensions')) {
14
- const marks = state.schema.marks.breakout.create({
15
- mode
16
- }).addToSet(node.node.marks);
17
- tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, marks);
18
- } else {
19
- tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, [state.schema.marks.breakout.create({
20
- mode
21
- })]);
22
- }
23
- if (node.node.type === state.schema.nodes.expand) {
24
- updateExpandedState(tr, node, isLivePage);
25
- } else if (node.node.type === state.schema.nodes.codeBlock) {
26
- const newNode = tr.doc.nodeAt(node.pos);
27
- const oldNode = node.node;
28
- if (newNode) {
29
- transferCodeBlockWrappedValue(oldNode, newNode);
30
- }
31
- }
32
- tr.setMeta('scrollIntoView', false);
33
- if (state.selection instanceof NodeSelection) {
34
- if (state.selection.$anchor.pos === node.pos) {
35
- tr.setSelection(NodeSelection.create(tr.doc, node.pos));
36
- }
37
- }
38
- if (dispatch) {
39
- dispatch(tr);
40
- }
41
- return true;
42
- };
43
- }
@@ -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,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,17 +0,0 @@
1
- import { findSupportedNodeForBreakout } from './find-breakout-node';
2
-
3
- /**
4
- * Get the current mode of the breakout at the selection
5
- * @param state Current EditorState
6
- */
7
- export function getBreakoutMode(state) {
8
- const node = findSupportedNodeForBreakout(state.selection);
9
- if (!node) {
10
- return;
11
- }
12
- const breakoutMark = node.node.marks.find(m => m.type.name === 'breakout');
13
- if (!breakoutMark) {
14
- return;
15
- }
16
- return breakoutMark.attrs.mode;
17
- }
@@ -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,14 +0,0 @@
1
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
2
- const supportedNodesForBreakout = ['codeBlock', 'layoutSection', 'expand'];
3
- const supportedNodesForBreakoutAdvancedLayouts = ['codeBlock', 'expand'];
4
-
5
- /**
6
- * Check if breakout can be applied to a node
7
- * @param node Node to check
8
- */
9
- export function isSupportedNodeForBreakout(node) {
10
- if (editorExperiment('advanced_layouts', true)) {
11
- return supportedNodesForBreakoutAdvancedLayouts.indexOf(node.type.name) !== -1;
12
- }
13
- return supportedNodesForBreakout.indexOf(node.type.name) !== -1;
14
- }
@@ -1,171 +0,0 @@
1
- /**
2
- * @jsxRuntime classic
3
- * @jsx jsx
4
- */
5
- import { useCallback } from 'react';
6
- // eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
7
- import { css, jsx } from '@emotion/react';
8
- import { injectIntl } from 'react-intl';
9
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
10
- import { BreakoutCssClassName } from '@atlaskit/editor-common/styles';
11
- import { Popup } from '@atlaskit/editor-common/ui';
12
- import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
13
- import { getNextBreakoutMode, getTitle } from '@atlaskit/editor-common/utils';
14
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
15
- import { findDomRefAtPos, findParentDomRefOfType } from '@atlaskit/editor-prosemirror/utils';
16
- import { akEditorFullPageNarrowBreakout } from '@atlaskit/editor-shared-styles';
17
- import GrowHorizontalIcon from '@atlaskit/icon/core/grow-horizontal';
18
- import ShrinkHorizontalIcon from '@atlaskit/icon/core/shrink-horizontal';
19
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-atlaskit-theme
20
- import { layers } from '@atlaskit/theme/constants';
21
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
22
- import { removeBreakout } from '../editor-commands/remove-breakout';
23
- import { setBreakoutMode } from '../editor-commands/set-breakout-mode';
24
- import { getPluginState } from '../pm-plugins/plugin-key';
25
- import { isBreakoutMarkAllowed } from '../pm-plugins/utils/is-breakout-mark-allowed';
26
- import { isSupportedNodeForBreakout } from '../pm-plugins/utils/is-supported-node';
27
- const toolbarButtonWrapperStyles = css({
28
- // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
29
- '&& button': {
30
- background: "var(--ds-background-neutral, #0515240F)",
31
- color: "var(--ds-icon, #292A2E)",
32
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
33
- ':hover': {
34
- background: "var(--ds-background-neutral-hovered, #0B120E24)",
35
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-important-styles -- Ignored via go/DSP-18766
36
- color: `${"var(--ds-icon, #292A2E)"} !important`
37
- }
38
- }
39
- });
40
- const toolbarButtonNarrowScreenStyles = css({
41
- // eslint-disable-next-line @atlaskit/ui-styling-standard/no-container-queries, @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-unsafe-values, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
42
- [`@container editor-area (max-width: ${akEditorFullPageNarrowBreakout}px)`]: {
43
- // eslint-disable-next-line @atlaskit/design-system/no-nested-styles, @atlaskit/ui-styling-standard/no-nested-selectors, @atlaskit/ui-styling-standard/no-unsafe-selectors -- Ignored via go/DSP-18766
44
- '&& button': {
45
- visibility: 'hidden',
46
- opacity: 0
47
- }
48
- }
49
- });
50
- function getBreakoutNodeElement(pluginState, selection, editorView) {
51
- if (!pluginState.breakoutNode) {
52
- return undefined;
53
- }
54
- if (selection instanceof NodeSelection && isSupportedNodeForBreakout(selection.node)) {
55
- // Ignored via go/ees005
56
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
57
- return findDomRefAtPos(selection.from, editorView.domAtPos.bind(editorView));
58
- }
59
- // Ignored via go/ees005
60
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
61
- return findParentDomRefOfType(pluginState.breakoutNode.node.type, editorView.domAtPos.bind(editorView))(selection);
62
- }
63
- const LayoutButton = ({
64
- intl: {
65
- formatMessage
66
- },
67
- mountPoint,
68
- boundariesElement,
69
- scrollableElement,
70
- editorView,
71
- isLivePage,
72
- isBreakoutNodePresent,
73
- breakoutMode: breakoutModeProp,
74
- api
75
- }) => {
76
- var _api$analytics3;
77
- const handleClick = useCallback(breakoutMode => {
78
- var _getPluginState;
79
- if (!editorView) {
80
- return;
81
- }
82
- const {
83
- state,
84
- dispatch
85
- } = editorView;
86
- const breakoutNode = (_getPluginState = getPluginState(state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.breakoutNode;
87
- if (['wide', 'full-width'].indexOf(breakoutMode) !== -1) {
88
- var _api$analytics;
89
- setBreakoutMode(breakoutMode, isLivePage)(state, dispatch);
90
- api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions.fireAnalyticsEvent({
91
- action: ACTION.CHANGED_BREAKOUT_MODE,
92
- actionSubject: ACTION_SUBJECT.ELEMENT,
93
- eventType: EVENT_TYPE.TRACK,
94
- attributes: {
95
- mode: breakoutMode,
96
- nodeType: breakoutNode === null || breakoutNode === void 0 ? void 0 : breakoutNode.node.type.name
97
- }
98
- });
99
- } else {
100
- var _api$analytics2;
101
- removeBreakout(isLivePage)(state, dispatch);
102
- api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions.fireAnalyticsEvent({
103
- action: ACTION.CHANGED_BREAKOUT_MODE,
104
- actionSubject: ACTION_SUBJECT.ELEMENT,
105
- eventType: EVENT_TYPE.TRACK,
106
- attributes: {
107
- mode: 'center',
108
- nodeType: breakoutNode === null || breakoutNode === void 0 ? void 0 : breakoutNode.node.type.name
109
- }
110
- });
111
- }
112
- }, [api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, editorView, isLivePage]);
113
- if (!editorView) {
114
- return null;
115
- }
116
- if (!isBreakoutNodePresent || !isBreakoutMarkAllowed(editorView.state)) {
117
- return null;
118
- }
119
- const breakoutMode = breakoutModeProp;
120
- const titleMessage = getTitle(breakoutMode);
121
- const title = formatMessage(titleMessage);
122
- const nextBreakoutMode = getNextBreakoutMode(breakoutMode);
123
- const belowOtherPopupsZIndex = layers.layer() - 1;
124
- const pluginState = getPluginState(editorView.state);
125
- if (!pluginState) {
126
- return null;
127
- }
128
- let element = getBreakoutNodeElement(pluginState, editorView.state.selection, editorView);
129
- if (!element) {
130
- return null;
131
- }
132
- const closestEl = element.querySelector(`.${BreakoutCssClassName.BREAKOUT_MARK_DOM}`);
133
- if (closestEl && closestEl.firstChild) {
134
- // Ignored via go/ees005
135
- // eslint-disable-next-line @atlaskit/editor/no-as-casting
136
- element = closestEl.firstChild;
137
- }
138
- return jsx(Popup, {
139
- ariaLabel: title,
140
- target: element
141
- // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
142
- ,
143
- offset: [5, 0],
144
- alignY: "start",
145
- alignX: "end",
146
- mountTo: mountPoint,
147
- boundariesElement: boundariesElement,
148
- scrollableElement: scrollableElement,
149
- stick: true,
150
- forcePlacement: true,
151
- zIndex: belowOtherPopupsZIndex
152
- }, jsx("div", {
153
- css: [toolbarButtonWrapperStyles, editorExperiment('platform_editor_preview_panel_responsiveness', true) && toolbarButtonNarrowScreenStyles]
154
- }, jsx(ToolbarButton, {
155
- title: title,
156
- testId: titleMessage.id
157
- // eslint-disable-next-line @atlassian/perf-linting/no-unstable-inline-props -- Ignored via go/ees017 (to be fixed)
158
- ,
159
- onClick: () => handleClick(nextBreakoutMode),
160
- iconBefore: breakoutMode === 'full-width' ? jsx(ShrinkHorizontalIcon, {
161
- label: title,
162
- spacing: "spacious"
163
- }) : jsx(GrowHorizontalIcon, {
164
- label: title,
165
- spacing: "spacious"
166
- })
167
- })));
168
- };
169
- LayoutButton.displayName = 'LayoutButton';
170
- const _default_1 = injectIntl(LayoutButton);
171
- export default _default_1;
@@ -1,35 +0,0 @@
1
- import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
2
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { findSupportedNodeForBreakout } from '../pm-plugins/utils/find-breakout-node';
4
- import { updateExpandedState } from '../pm-plugins/utils/single-player-expand';
5
- export function removeBreakout(isLivePage) {
6
- return function (state, dispatch) {
7
- var node = findSupportedNodeForBreakout(state.selection);
8
- if (!node) {
9
- return false;
10
- }
11
- var marks = node.node.marks.filter(function (m) {
12
- return m.type.name !== 'breakout';
13
- });
14
- var tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, marks);
15
- if (node.node.type === state.schema.nodes.expand) {
16
- updateExpandedState(tr, node, isLivePage);
17
- } else if (node.node.type === state.schema.nodes.codeBlock) {
18
- var newNode = tr.doc.nodeAt(node.pos);
19
- var oldNode = node.node;
20
- if (newNode) {
21
- transferCodeBlockWrappedValue(oldNode, newNode);
22
- }
23
- }
24
- tr.setMeta('scrollIntoView', false);
25
- if (state.selection instanceof NodeSelection) {
26
- if (state.selection.$anchor.pos === node.pos) {
27
- tr.setSelection(NodeSelection.create(tr.doc, node.pos));
28
- }
29
- }
30
- if (dispatch) {
31
- dispatch(tr);
32
- }
33
- return true;
34
- };
35
- }
@@ -1,43 +0,0 @@
1
- import { transferCodeBlockWrappedValue } from '@atlaskit/editor-common/code-block';
2
- import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
- import { isExperimentEnabled } from '@atlaskit/platform-feature-experiments/is-experiment-enabled';
4
- import { findSupportedNodeForBreakout } from '../pm-plugins/utils/find-breakout-node';
5
- import { updateExpandedState } from '../pm-plugins/utils/single-player-expand';
6
- export function setBreakoutMode(mode, isLivePage) {
7
- return function (state, dispatch) {
8
- var node = findSupportedNodeForBreakout(state.selection);
9
- if (!node) {
10
- return false;
11
- }
12
- var tr;
13
- if (isExperimentEnabled('platform_editor_lovability_resize_extensions')) {
14
- var marks = state.schema.marks.breakout.create({
15
- mode: mode
16
- }).addToSet(node.node.marks);
17
- tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, marks);
18
- } else {
19
- tr = state.tr.setNodeMarkup(node.pos, node.node.type, node.node.attrs, [state.schema.marks.breakout.create({
20
- mode: mode
21
- })]);
22
- }
23
- if (node.node.type === state.schema.nodes.expand) {
24
- updateExpandedState(tr, node, isLivePage);
25
- } else if (node.node.type === state.schema.nodes.codeBlock) {
26
- var newNode = tr.doc.nodeAt(node.pos);
27
- var oldNode = node.node;
28
- if (newNode) {
29
- transferCodeBlockWrappedValue(oldNode, newNode);
30
- }
31
- }
32
- tr.setMeta('scrollIntoView', false);
33
- if (state.selection instanceof NodeSelection) {
34
- if (state.selection.$anchor.pos === node.pos) {
35
- tr.setSelection(NodeSelection.create(tr.doc, node.pos));
36
- }
37
- }
38
- if (dispatch) {
39
- dispatch(tr);
40
- }
41
- return true;
42
- };
43
- }
@@ -1,5 +0,0 @@
1
- import { PluginKey } from '@atlaskit/editor-prosemirror/state';
2
- export var pluginKey = new PluginKey('breakoutPlugin');
3
- export var getPluginState = function getPluginState(state) {
4
- return pluginKey.getState(state) || undefined;
5
- };
@@ -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
- var 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
- var 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,19 +0,0 @@
1
- import { findSupportedNodeForBreakout } from './find-breakout-node';
2
-
3
- /**
4
- * Get the current mode of the breakout at the selection
5
- * @param state Current EditorState
6
- */
7
- export function getBreakoutMode(state) {
8
- var node = findSupportedNodeForBreakout(state.selection);
9
- if (!node) {
10
- return;
11
- }
12
- var breakoutMark = node.node.marks.find(function (m) {
13
- return m.type.name === 'breakout';
14
- });
15
- if (!breakoutMark) {
16
- return;
17
- }
18
- return breakoutMark.attrs.mode;
19
- }