@atlaskit/editor-plugin-breakout 24.0.3 → 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 +12 -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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-breakout
2
2
 
3
+ ## 24.0.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [`0a81f6fa7cbf8`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/0a81f6fa7cbf8) -
8
+ Clean up experiment `platform_editor_breakout_resizing`. Behind the
9
+ `platform_editor_list_join_strip_breakout` experiment, strip the breakout mark from a code block
10
+ before nesting it into a list item when joining from a gap cursor. Behind the
11
+ `platform_editor_resizer_selector_jsdom_fix` experiment, make the panel and rule breakout resizer
12
+ selectors parseable by jsdom (`> *[data-prosemirror-node-name=…]`).
13
+ - Updated dependencies
14
+
3
15
  ## 24.0.3
4
16
 
5
17
  ### Patch Changes
@@ -1,211 +1,26 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.breakoutPlugin = void 0;
9
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
12
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
13
- var _react = _interopRequireWildcard(require("react"));
8
+ var _react = _interopRequireDefault(require("react"));
14
9
  var _breakout = require("@atlaskit/adf-schema/breakout");
15
- var _hooks = require("@atlaskit/editor-common/hooks");
16
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
17
- var _styles = require("@atlaskit/editor-common/styles");
18
- var _usePluginStateEffect = require("@atlaskit/editor-common/use-plugin-state-effect");
19
- var _useSharedPluginStateSelector = require("@atlaskit/editor-common/use-shared-plugin-state-selector");
20
- var _editorSharedStyles = require("@atlaskit/editor-shared-styles");
21
- var _editorExperiment = require("@atlaskit/tmp-editor-statsig/editor-experiment");
22
- var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
23
- var _pluginKey = require("./pm-plugins/plugin-key");
24
10
  var _resizingPlugin = require("./pm-plugins/resizing-plugin");
25
- var _findBreakoutNode = require("./pm-plugins/utils/find-breakout-node");
26
- var _getBreakoutMode = require("./pm-plugins/utils/get-breakout-mode");
27
11
  var _GuidelineLabel = require("./ui/GuidelineLabel");
28
- var _LayoutButton = _interopRequireDefault(require("./ui/LayoutButton"));
29
- function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
30
- 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; }
31
- 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) { (0, _defineProperty2.default)(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; }
32
- var BreakoutView = /*#__PURE__*/(0, _createClass2.default)(function BreakoutView(
33
- /**
34
- * Note: this is actually a PMMark -- however our version
35
- * of the prosemirror and prosemirror types mean using PMNode
36
- * is not problematic.
37
- */
38
- mark, view, appearance) {
39
- (0, _classCallCheck2.default)(this, BreakoutView);
40
- var dom = document.createElement('div');
41
- var contentDOM = document.createElement('div');
42
- contentDOM.className = _styles.BreakoutCssClassName.BREAKOUT_MARK_DOM;
43
- contentDOM.setAttribute('data-testid', 'ak-editor-breakout-mark-dom');
44
- dom.className = _styles.BreakoutCssClassName.BREAKOUT_MARK;
45
- dom.setAttribute('data-layout', mark.attrs.mode);
46
- dom.setAttribute('data-testid', 'ak-editor-breakout-mark');
47
- dom.appendChild(contentDOM);
48
- dom.style.transform = 'none';
49
- dom.style.display = 'flex';
50
- dom.style.justifyContent = 'center';
51
- contentDOM.style.transition = "min-width 0.5s ".concat(_editorSharedStyles.akEditorSwoopCubicBezier);
52
- if ((0, _editorExperiment.editorExperiment)('advanced_layouts', true)) {
53
- if (mark.attrs.width) {
54
- contentDOM.style.minWidth = "min(".concat(mark.attrs.width, "px, calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding)))");
55
- } else {
56
- // original breakout algorithm is in calcBreakoutWidth from platform/packages/editor/editor-common/src/utils/breakout.ts
57
- if (mark.attrs.mode === 'full-width') {
58
- contentDOM.style.minWidth = "max(var(--ak-editor--line-length), min(var(--ak-editor--full-width-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding))))";
59
- }
60
- if (mark.attrs.mode === 'wide') {
61
- if (appearance && appearance === 'full-width' && (0, _editorExperiment.editorExperiment)('single_column_layouts', true) && true) {
62
- contentDOM.style.minWidth = "min(var(--ak-editor--breakout-wide-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding)))";
63
- } else {
64
- contentDOM.style.minWidth = "max(var(--ak-editor--line-length), min(var(--ak-editor--breakout-wide-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding))))";
65
- }
66
- }
67
- }
68
- } else {
69
- // original breakout algorithm is in calcBreakoutWidth from platform/packages/editor/editor-common/src/utils/breakout.ts
70
- if (mark.attrs.mode === 'full-width') {
71
- contentDOM.style.minWidth = "max(var(--ak-editor--line-length), min(var(--ak-editor--full-width-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding))))";
72
- }
73
- if (mark.attrs.mode === 'wide') {
74
- contentDOM.style.minWidth = "max(var(--ak-editor--line-length), min(var(--ak-editor--breakout-wide-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding))))";
75
- }
76
- }
77
- this.dom = dom;
78
- this.mark = mark;
79
- this.view = view;
80
- this.contentDOM = contentDOM;
81
- });
82
- function shouldPluginStateUpdate(newBreakoutNode, currentBreakoutNode) {
83
- if (newBreakoutNode && currentBreakoutNode) {
84
- return newBreakoutNode !== currentBreakoutNode;
85
- }
86
- return newBreakoutNode || currentBreakoutNode ? true : false;
87
- }
88
- function createPlugin(api, _ref, appearance) {
89
- var dispatch = _ref.dispatch;
90
- return new _safePlugin.SafePlugin({
91
- state: {
92
- init: function init() {
93
- return {
94
- breakoutNode: undefined,
95
- activeGuidelineKey: undefined
96
- };
97
- },
98
- apply: function apply(tr, pluginState) {
99
- var breakoutNode = (0, _findBreakoutNode.findSupportedNodeForBreakout)(tr.selection);
100
- if (shouldPluginStateUpdate(breakoutNode, pluginState.breakoutNode)) {
101
- var nextPluginState = _objectSpread(_objectSpread({}, pluginState), {}, {
102
- breakoutNode: breakoutNode
103
- });
104
- dispatch(_pluginKey.pluginKey, nextPluginState);
105
- return nextPluginState;
106
- }
107
- return pluginState;
108
- }
109
- },
110
- key: _pluginKey.pluginKey,
111
- props: {
112
- nodeViews: {
113
- // Note: When we upgrade to prosemirror 1.27.2 -- we should
114
- // move this to markViews.
115
- // See the following link for more details:
116
- // https://prosemirror.net/docs/ref/#view.EditorProps.nodeViews.
117
- breakout: function breakout(mark, view) {
118
- return new BreakoutView(mark, view, appearance);
119
- }
120
- }
121
- }
122
- });
123
- }
124
- var LayoutButtonWrapper = function LayoutButtonWrapper(_ref2) {
125
- var api = _ref2.api,
126
- editorView = _ref2.editorView,
127
- boundariesElement = _ref2.boundariesElement,
128
- scrollableElement = _ref2.scrollableElement,
129
- mountPoint = _ref2.mountPoint;
130
- var _useSharedPluginState = (0, _hooks.useSharedPluginStateWithSelector)(api, ['editorViewMode', 'editorDisabled', 'blockControls'], function (states) {
131
- var _states$blockControls, _states$blockControls2, _states$editorViewMod, _states$editorDisable;
132
- return {
133
- isDragging: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.isDragging,
134
- isPMDragging: (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.isPMDragging,
135
- mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode,
136
- editorDisabled: (_states$editorDisable = states.editorDisabledState) === null || _states$editorDisable === void 0 ? void 0 : _states$editorDisable.editorDisabled
137
- };
138
- }),
139
- editorDisabled = _useSharedPluginState.editorDisabled,
140
- isDragging = _useSharedPluginState.isDragging,
141
- isPMDragging = _useSharedPluginState.isPMDragging,
142
- mode = _useSharedPluginState.mode;
143
- var _useState = (0, _react.useState)(false),
144
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
145
- breakoutNodePresent = _useState2[0],
146
- setBreakoutNodePresent = _useState2[1];
147
- var _useState3 = (0, _react.useState)(editorView ? (0, _getBreakoutMode.getBreakoutMode)(editorView.state) : undefined),
148
- _useState4 = (0, _slicedToArray2.default)(_useState3, 2),
149
- breakoutMode = _useState4[0],
150
- setBreakoutMode = _useState4[1];
151
- (0, _usePluginStateEffect.usePluginStateEffect)(api, ['breakout'], function (_ref3) {
152
- var breakoutState = _ref3.breakoutState;
153
- if (!editorView) {
154
- return;
155
- }
156
- if (breakoutState !== null && breakoutState !== void 0 && breakoutState.breakoutNode && !breakoutNodePresent) {
157
- setBreakoutNodePresent(true);
158
- }
159
- if (!(breakoutState !== null && breakoutState !== void 0 && breakoutState.breakoutNode) && breakoutNodePresent) {
160
- setBreakoutNodePresent(false);
161
- }
162
- var nextBreakoutMode = (0, _getBreakoutMode.getBreakoutMode)(editorView.state);
163
- if (nextBreakoutMode !== breakoutMode) {
164
- setBreakoutMode(nextBreakoutMode);
165
- }
166
- });
167
- var interactionState = (0, _useSharedPluginStateSelector.useSharedPluginStateSelector)(api, 'interaction.interactionState');
168
- if (interactionState === 'hasNotHadInteraction') {
169
- return null;
170
- }
171
- if (isDragging || isPMDragging) {
172
- if ((0, _editorExperiment.editorExperiment)('advanced_layouts', true)) {
173
- return null;
174
- }
175
- }
176
- var isViewMode = mode === 'view';
177
- var isEditMode = mode === 'edit';
178
- return !isViewMode && editorDisabled === false ? /*#__PURE__*/_react.default.createElement(_LayoutButton.default, {
179
- editorView: editorView,
180
- mountPoint: mountPoint,
181
- boundariesElement: boundariesElement,
182
- scrollableElement: scrollableElement,
183
- isLivePage: isEditMode,
184
- isBreakoutNodePresent: breakoutNodePresent,
185
- breakoutMode: breakoutMode,
186
- api: api
187
- }) : null;
188
- };
189
- var breakoutPlugin = exports.breakoutPlugin = function breakoutPlugin(_ref4) {
190
- var options = _ref4.config,
191
- api = _ref4.api;
12
+ var breakoutPlugin = exports.breakoutPlugin = function breakoutPlugin(_ref) {
13
+ var options = _ref.config,
14
+ api = _ref.api;
192
15
  return {
193
16
  name: 'breakout',
194
17
  pmPlugins: function pmPlugins() {
195
- if ((0, _expValEquals.expValEquals)('platform_editor_breakout_resizing', 'isEnabled', true)) {
196
- return [{
197
- name: 'breakout-resizing',
198
- plugin: function plugin(_ref5) {
199
- var getIntl = _ref5.getIntl,
200
- nodeViewPortalProviderAPI = _ref5.nodeViewPortalProviderAPI;
201
- return (0, _resizingPlugin.createResizingPlugin)(api, getIntl, nodeViewPortalProviderAPI, options);
202
- }
203
- }];
204
- }
205
18
  return [{
206
- name: 'breakout',
207
- plugin: function plugin(props) {
208
- return createPlugin(api, props, options === null || options === void 0 ? void 0 : options.appearance);
19
+ name: 'breakout-resizing',
20
+ plugin: function plugin(_ref2) {
21
+ var getIntl = _ref2.getIntl,
22
+ nodeViewPortalProviderAPI = _ref2.nodeViewPortalProviderAPI;
23
+ return (0, _resizingPlugin.createResizingPlugin)(api, getIntl, nodeViewPortalProviderAPI, options);
209
24
  }
210
25
  }];
211
26
  },
@@ -221,50 +36,27 @@ var breakoutPlugin = exports.breakoutPlugin = function breakoutPlugin(_ref4) {
221
36
  breakoutNode: undefined
222
37
  };
223
38
  }
224
- if ((0, _expValEquals.expValEquals)('platform_editor_breakout_resizing', 'isEnabled', true)) {
225
- var resizingPluginState = _resizingPlugin.resizingPluginKey.getState(editorState);
226
- if (!resizingPluginState) {
227
- return {
228
- breakoutNode: undefined,
229
- activeGuidelineKey: undefined
230
- };
231
- }
232
- return resizingPluginState;
233
- }
234
- var pluginState = _pluginKey.pluginKey.getState(editorState);
235
- if (!pluginState) {
39
+ var resizingPluginState = _resizingPlugin.resizingPluginKey.getState(editorState);
40
+ if (!resizingPluginState) {
236
41
  return {
237
- breakoutNode: undefined
42
+ breakoutNode: undefined,
43
+ activeGuidelineKey: undefined
238
44
  };
239
45
  }
240
- return pluginState;
46
+ return resizingPluginState;
241
47
  },
242
- contentComponent: function contentComponent(_ref6) {
243
- var editorView = _ref6.editorView,
244
- popupsMountPoint = _ref6.popupsMountPoint,
245
- popupsBoundariesElement = _ref6.popupsBoundariesElement,
246
- popupsScrollableElement = _ref6.popupsScrollableElement;
48
+ contentComponent: function contentComponent(_ref3) {
49
+ var editorView = _ref3.editorView,
50
+ popupsMountPoint = _ref3.popupsMountPoint,
51
+ popupsBoundariesElement = _ref3.popupsBoundariesElement,
52
+ popupsScrollableElement = _ref3.popupsScrollableElement;
247
53
  if (!editorView) {
248
54
  return null;
249
55
  }
250
- if ((0, _expValEquals.expValEquals)('platform_editor_breakout_resizing', 'isEnabled', true)) {
251
- return /*#__PURE__*/_react.default.createElement(_GuidelineLabel.GuidelineLabel, {
252
- api: api,
253
- editorView: editorView,
254
- mountPoint: popupsMountPoint,
255
- boundariesElement: popupsBoundariesElement,
256
- scrollableElement: popupsScrollableElement
257
- });
258
- }
259
-
260
- // This is a bit crappy, but should be resolved once we move to a static schema.
261
- if (options && !options.allowBreakoutButton) {
262
- return null;
263
- }
264
- return /*#__PURE__*/_react.default.createElement(LayoutButtonWrapper, {
56
+ return /*#__PURE__*/_react.default.createElement(_GuidelineLabel.GuidelineLabel, {
265
57
  api: api,
266
- mountPoint: popupsMountPoint,
267
58
  editorView: editorView,
59
+ mountPoint: popupsMountPoint,
268
60
  boundariesElement: popupsBoundariesElement,
269
61
  scrollableElement: popupsScrollableElement
270
62
  });
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.updateExpandedStateNew = exports.updateExpandedState = void 0;
7
7
  var _expand = require("@atlaskit/editor-common/expand");
8
- var _editorExperiment = require("@atlaskit/tmp-editor-statsig/editor-experiment");
9
8
  var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
10
9
  var updateExpandedStateNew = exports.updateExpandedStateNew = function updateExpandedStateNew(_ref) {
11
10
  var tr = _ref.tr,
@@ -21,20 +20,10 @@ var updateExpandedStateNew = exports.updateExpandedStateNew = function updateExp
21
20
  }
22
21
  };
23
22
  var updateExpandedState = exports.updateExpandedState = function updateExpandedState(tr, node, isLivePage) {
24
- if ((0, _editorExperiment.editorExperiment)('platform_editor_breakout_resizing', true)) {
25
- updateExpandedStateNew({
26
- tr: tr,
27
- node: node.node,
28
- pos: node.pos,
29
- isLivePage: isLivePage
30
- });
31
- } else {
32
- if (isLivePage || (0, _expValEquals.expValEquals)('platform_editor_single_player_expand', 'isEnabled', true)) {
33
- var wasExpandExpanded = _expand.expandedState.get(node.node);
34
- var newExpand = tr.doc.nodeAt(node.pos);
35
- if (wasExpandExpanded !== undefined && newExpand) {
36
- _expand.expandedState.set(newExpand, wasExpandExpanded);
37
- }
38
- }
39
- }
23
+ updateExpandedStateNew({
24
+ tr: tr,
25
+ node: node.node,
26
+ pos: node.pos,
27
+ isLivePage: isLivePage
28
+ });
40
29
  };
@@ -1,194 +1,19 @@
1
- import React, { useState } from 'react';
1
+ import React from 'react';
2
2
  import { breakout } from '@atlaskit/adf-schema/breakout';
3
- import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
4
- import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
- import { BreakoutCssClassName } from '@atlaskit/editor-common/styles';
6
- import { usePluginStateEffect } from '@atlaskit/editor-common/use-plugin-state-effect';
7
- import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
8
- import { akEditorSwoopCubicBezier } from '@atlaskit/editor-shared-styles';
9
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
10
- import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
11
- import { pluginKey } from './pm-plugins/plugin-key';
12
3
  import { createResizingPlugin, resizingPluginKey } from './pm-plugins/resizing-plugin';
13
- import { findSupportedNodeForBreakout } from './pm-plugins/utils/find-breakout-node';
14
- import { getBreakoutMode } from './pm-plugins/utils/get-breakout-mode';
15
4
  import { GuidelineLabel } from './ui/GuidelineLabel';
16
- import LayoutButton from './ui/LayoutButton';
17
- class BreakoutView {
18
- constructor(
19
- /**
20
- * Note: this is actually a PMMark -- however our version
21
- * of the prosemirror and prosemirror types mean using PMNode
22
- * is not problematic.
23
- */
24
- mark, view, appearance) {
25
- const dom = document.createElement('div');
26
- const contentDOM = document.createElement('div');
27
- contentDOM.className = BreakoutCssClassName.BREAKOUT_MARK_DOM;
28
- contentDOM.setAttribute('data-testid', 'ak-editor-breakout-mark-dom');
29
- dom.className = BreakoutCssClassName.BREAKOUT_MARK;
30
- dom.setAttribute('data-layout', mark.attrs.mode);
31
- dom.setAttribute('data-testid', 'ak-editor-breakout-mark');
32
- dom.appendChild(contentDOM);
33
- dom.style.transform = 'none';
34
- dom.style.display = 'flex';
35
- dom.style.justifyContent = 'center';
36
- contentDOM.style.transition = `min-width 0.5s ${akEditorSwoopCubicBezier}`;
37
- if (editorExperiment('advanced_layouts', true)) {
38
- if (mark.attrs.width) {
39
- contentDOM.style.minWidth = `min(${mark.attrs.width}px, calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding)))`;
40
- } else {
41
- // original breakout algorithm is in calcBreakoutWidth from platform/packages/editor/editor-common/src/utils/breakout.ts
42
- if (mark.attrs.mode === 'full-width') {
43
- contentDOM.style.minWidth = `max(var(--ak-editor--line-length), min(var(--ak-editor--full-width-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding))))`;
44
- }
45
- if (mark.attrs.mode === 'wide') {
46
- if (appearance && appearance === 'full-width' && editorExperiment('single_column_layouts', true) && true) {
47
- contentDOM.style.minWidth = `min(var(--ak-editor--breakout-wide-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding)))`;
48
- } else {
49
- contentDOM.style.minWidth = `max(var(--ak-editor--line-length), min(var(--ak-editor--breakout-wide-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding))))`;
50
- }
51
- }
52
- }
53
- } else {
54
- // original breakout algorithm is in calcBreakoutWidth from platform/packages/editor/editor-common/src/utils/breakout.ts
55
- if (mark.attrs.mode === 'full-width') {
56
- contentDOM.style.minWidth = `max(var(--ak-editor--line-length), min(var(--ak-editor--full-width-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding))))`;
57
- }
58
- if (mark.attrs.mode === 'wide') {
59
- contentDOM.style.minWidth = `max(var(--ak-editor--line-length), min(var(--ak-editor--breakout-wide-layout-width), calc(100cqw - var(--ak-editor--breakout-full-page-guttering-padding))))`;
60
- }
61
- }
62
- this.dom = dom;
63
- this.mark = mark;
64
- this.view = view;
65
- this.contentDOM = contentDOM;
66
- }
67
- }
68
- function shouldPluginStateUpdate(newBreakoutNode, currentBreakoutNode) {
69
- if (newBreakoutNode && currentBreakoutNode) {
70
- return newBreakoutNode !== currentBreakoutNode;
71
- }
72
- return newBreakoutNode || currentBreakoutNode ? true : false;
73
- }
74
- function createPlugin(api, {
75
- dispatch
76
- }, appearance) {
77
- return new SafePlugin({
78
- state: {
79
- init() {
80
- return {
81
- breakoutNode: undefined,
82
- activeGuidelineKey: undefined
83
- };
84
- },
85
- apply(tr, pluginState) {
86
- const breakoutNode = findSupportedNodeForBreakout(tr.selection);
87
- if (shouldPluginStateUpdate(breakoutNode, pluginState.breakoutNode)) {
88
- const nextPluginState = {
89
- ...pluginState,
90
- breakoutNode
91
- };
92
- dispatch(pluginKey, nextPluginState);
93
- return nextPluginState;
94
- }
95
- return pluginState;
96
- }
97
- },
98
- key: pluginKey,
99
- props: {
100
- nodeViews: {
101
- // Note: When we upgrade to prosemirror 1.27.2 -- we should
102
- // move this to markViews.
103
- // See the following link for more details:
104
- // https://prosemirror.net/docs/ref/#view.EditorProps.nodeViews.
105
- breakout: (mark, view) => {
106
- return new BreakoutView(mark, view, appearance);
107
- }
108
- }
109
- }
110
- });
111
- }
112
- const LayoutButtonWrapper = ({
113
- api,
114
- editorView,
115
- boundariesElement,
116
- scrollableElement,
117
- mountPoint
118
- }) => {
119
- const {
120
- editorDisabled,
121
- isDragging,
122
- isPMDragging,
123
- mode
124
- } = useSharedPluginStateWithSelector(api, ['editorViewMode', 'editorDisabled', 'blockControls'], states => {
125
- var _states$blockControls, _states$blockControls2, _states$editorViewMod, _states$editorDisable;
126
- return {
127
- isDragging: (_states$blockControls = states.blockControlsState) === null || _states$blockControls === void 0 ? void 0 : _states$blockControls.isDragging,
128
- isPMDragging: (_states$blockControls2 = states.blockControlsState) === null || _states$blockControls2 === void 0 ? void 0 : _states$blockControls2.isPMDragging,
129
- mode: (_states$editorViewMod = states.editorViewModeState) === null || _states$editorViewMod === void 0 ? void 0 : _states$editorViewMod.mode,
130
- editorDisabled: (_states$editorDisable = states.editorDisabledState) === null || _states$editorDisable === void 0 ? void 0 : _states$editorDisable.editorDisabled
131
- };
132
- });
133
- const [breakoutNodePresent, setBreakoutNodePresent] = useState(false);
134
- const [breakoutMode, setBreakoutMode] = useState(editorView ? getBreakoutMode(editorView.state) : undefined);
135
- usePluginStateEffect(api, ['breakout'], ({
136
- breakoutState
137
- }) => {
138
- if (!editorView) {
139
- return;
140
- }
141
- if (breakoutState !== null && breakoutState !== void 0 && breakoutState.breakoutNode && !breakoutNodePresent) {
142
- setBreakoutNodePresent(true);
143
- }
144
- if (!(breakoutState !== null && breakoutState !== void 0 && breakoutState.breakoutNode) && breakoutNodePresent) {
145
- setBreakoutNodePresent(false);
146
- }
147
- const nextBreakoutMode = getBreakoutMode(editorView.state);
148
- if (nextBreakoutMode !== breakoutMode) {
149
- setBreakoutMode(nextBreakoutMode);
150
- }
151
- });
152
- const interactionState = useSharedPluginStateSelector(api, 'interaction.interactionState');
153
- if (interactionState === 'hasNotHadInteraction') {
154
- return null;
155
- }
156
- if (isDragging || isPMDragging) {
157
- if (editorExperiment('advanced_layouts', true)) {
158
- return null;
159
- }
160
- }
161
- const isViewMode = mode === 'view';
162
- const isEditMode = mode === 'edit';
163
- return !isViewMode && editorDisabled === false ? /*#__PURE__*/React.createElement(LayoutButton, {
164
- editorView: editorView,
165
- mountPoint: mountPoint,
166
- boundariesElement: boundariesElement,
167
- scrollableElement: scrollableElement,
168
- isLivePage: isEditMode,
169
- isBreakoutNodePresent: breakoutNodePresent,
170
- breakoutMode: breakoutMode,
171
- api: api
172
- }) : null;
173
- };
174
5
  export const breakoutPlugin = ({
175
6
  config: options,
176
7
  api
177
8
  }) => ({
178
9
  name: 'breakout',
179
10
  pmPlugins() {
180
- if (expValEquals('platform_editor_breakout_resizing', 'isEnabled', true)) {
181
- return [{
182
- name: 'breakout-resizing',
183
- plugin: ({
184
- getIntl,
185
- nodeViewPortalProviderAPI
186
- }) => createResizingPlugin(api, getIntl, nodeViewPortalProviderAPI, options)
187
- }];
188
- }
189
11
  return [{
190
- name: 'breakout',
191
- plugin: props => createPlugin(api, props, options === null || options === void 0 ? void 0 : options.appearance)
12
+ name: 'breakout-resizing',
13
+ plugin: ({
14
+ getIntl,
15
+ nodeViewPortalProviderAPI
16
+ }) => createResizingPlugin(api, getIntl, nodeViewPortalProviderAPI, options)
192
17
  }];
193
18
  },
194
19
  marks() {
@@ -203,23 +28,14 @@ export const breakoutPlugin = ({
203
28
  breakoutNode: undefined
204
29
  };
205
30
  }
206
- if (expValEquals('platform_editor_breakout_resizing', 'isEnabled', true)) {
207
- const resizingPluginState = resizingPluginKey.getState(editorState);
208
- if (!resizingPluginState) {
209
- return {
210
- breakoutNode: undefined,
211
- activeGuidelineKey: undefined
212
- };
213
- }
214
- return resizingPluginState;
215
- }
216
- const pluginState = pluginKey.getState(editorState);
217
- if (!pluginState) {
31
+ const resizingPluginState = resizingPluginKey.getState(editorState);
32
+ if (!resizingPluginState) {
218
33
  return {
219
- breakoutNode: undefined
34
+ breakoutNode: undefined,
35
+ activeGuidelineKey: undefined
220
36
  };
221
37
  }
222
- return pluginState;
38
+ return resizingPluginState;
223
39
  },
224
40
  contentComponent({
225
41
  editorView,
@@ -230,24 +46,10 @@ export const breakoutPlugin = ({
230
46
  if (!editorView) {
231
47
  return null;
232
48
  }
233
- if (expValEquals('platform_editor_breakout_resizing', 'isEnabled', true)) {
234
- return /*#__PURE__*/React.createElement(GuidelineLabel, {
235
- api: api,
236
- editorView: editorView,
237
- mountPoint: popupsMountPoint,
238
- boundariesElement: popupsBoundariesElement,
239
- scrollableElement: popupsScrollableElement
240
- });
241
- }
242
-
243
- // This is a bit crappy, but should be resolved once we move to a static schema.
244
- if (options && !options.allowBreakoutButton) {
245
- return null;
246
- }
247
- return /*#__PURE__*/React.createElement(LayoutButtonWrapper, {
49
+ return /*#__PURE__*/React.createElement(GuidelineLabel, {
248
50
  api: api,
249
- mountPoint: popupsMountPoint,
250
51
  editorView: editorView,
52
+ mountPoint: popupsMountPoint,
251
53
  boundariesElement: popupsBoundariesElement,
252
54
  scrollableElement: popupsScrollableElement
253
55
  });
@@ -1,5 +1,4 @@
1
1
  import { expandedState } from '@atlaskit/editor-common/expand';
2
- import { editorExperiment } from '@atlaskit/tmp-editor-statsig/editor-experiment';
3
2
  import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
4
3
  export const updateExpandedStateNew = ({
5
4
  tr,
@@ -16,20 +15,10 @@ export const updateExpandedStateNew = ({
16
15
  }
17
16
  };
18
17
  export const updateExpandedState = (tr, node, isLivePage) => {
19
- if (editorExperiment('platform_editor_breakout_resizing', true)) {
20
- updateExpandedStateNew({
21
- tr,
22
- node: node.node,
23
- pos: node.pos,
24
- isLivePage
25
- });
26
- } else {
27
- if (isLivePage || expValEquals('platform_editor_single_player_expand', 'isEnabled', true)) {
28
- const wasExpandExpanded = expandedState.get(node.node);
29
- const newExpand = tr.doc.nodeAt(node.pos);
30
- if (wasExpandExpanded !== undefined && newExpand) {
31
- expandedState.set(newExpand, wasExpandExpanded);
32
- }
33
- }
34
- }
18
+ updateExpandedStateNew({
19
+ tr,
20
+ node: node.node,
21
+ pos: node.pos,
22
+ isLivePage
23
+ });
35
24
  };