@atlaskit/editor-plugin-breakout 2.7.1 → 2.7.3
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.
- package/CHANGELOG.md +23 -0
- package/dist/cjs/breakoutPlugin.js +25 -2
- package/dist/cjs/pm-plugins/get-guidelines.js +37 -17
- package/dist/cjs/pm-plugins/resizer-callbacks.js +61 -9
- package/dist/cjs/pm-plugins/resizing-plugin.js +39 -0
- package/dist/cjs/pm-plugins/utils/analytics.js +16 -1
- package/dist/cjs/ui/GuidelineLabel.js +44 -0
- package/dist/es2019/breakoutPlugin.js +26 -3
- package/dist/es2019/pm-plugins/get-guidelines.js +36 -16
- package/dist/es2019/pm-plugins/resizer-callbacks.js +57 -5
- package/dist/es2019/pm-plugins/resizing-plugin.js +38 -0
- package/dist/es2019/pm-plugins/utils/analytics.js +16 -0
- package/dist/es2019/ui/GuidelineLabel.js +38 -0
- package/dist/esm/breakoutPlugin.js +26 -3
- package/dist/esm/pm-plugins/get-guidelines.js +36 -16
- package/dist/esm/pm-plugins/resizer-callbacks.js +62 -10
- package/dist/esm/pm-plugins/resizing-plugin.js +38 -0
- package/dist/esm/pm-plugins/utils/analytics.js +15 -0
- package/dist/esm/ui/GuidelineLabel.js +37 -0
- package/dist/types/breakoutPluginType.d.ts +2 -0
- package/dist/types/pm-plugins/get-guidelines.d.ts +8 -0
- package/dist/types/pm-plugins/resizing-plugin.d.ts +8 -3
- package/dist/types/pm-plugins/utils/analytics.d.ts +5 -0
- package/dist/types/ui/GuidelineLabel.d.ts +13 -0
- package/dist/types-ts4.5/breakoutPluginType.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/get-guidelines.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/resizing-plugin.d.ts +8 -3
- package/dist/types-ts4.5/pm-plugins/utils/analytics.d.ts +5 -0
- package/dist/types-ts4.5/ui/GuidelineLabel.d.ts +13 -0
- package/package.json +4 -4
|
@@ -3,7 +3,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
3
3
|
import { setBreakoutWidth } from '../editor-commands/set-breakout-width';
|
|
4
4
|
import { getGuidelines } from './get-guidelines';
|
|
5
5
|
import { LOCAL_RESIZE_PROPERTY } from './resizing-mark-view';
|
|
6
|
-
import {
|
|
6
|
+
import { resizingPluginKey } from './resizing-plugin';
|
|
7
|
+
import { generateResizeFrameRatePayloads, generateResizedEventPayload } from './utils/analytics';
|
|
7
8
|
import { measureFramerate, reduceResizeFrameRateSamples } from './utils/measure-framerate';
|
|
8
9
|
const RESIZE_RATIO = 2;
|
|
9
10
|
const SNAP_GAP = 10;
|
|
@@ -58,6 +59,8 @@ export function createResizerCallbacks({
|
|
|
58
59
|
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
59
60
|
startMeasure();
|
|
60
61
|
}
|
|
62
|
+
const pos = view.posAtDOM(dom, 0);
|
|
63
|
+
node = view.state.doc.nodeAt(pos);
|
|
61
64
|
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
62
65
|
tr
|
|
63
66
|
}) => {
|
|
@@ -66,10 +69,19 @@ export function createResizerCallbacks({
|
|
|
66
69
|
tr
|
|
67
70
|
});
|
|
68
71
|
tr.setMeta('is-resizer-resizing', true);
|
|
72
|
+
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
73
|
+
tr.setMeta(resizingPluginKey, {
|
|
74
|
+
type: 'UPDATE_BREAKOUT_NODE',
|
|
75
|
+
data: {
|
|
76
|
+
node,
|
|
77
|
+
pos,
|
|
78
|
+
start: pos,
|
|
79
|
+
depth: 0
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
}
|
|
69
83
|
return tr;
|
|
70
84
|
});
|
|
71
|
-
const pos = view.posAtDOM(dom, 0);
|
|
72
|
-
node = view.state.doc.nodeAt(pos);
|
|
73
85
|
},
|
|
74
86
|
onDrag: ({
|
|
75
87
|
location,
|
|
@@ -90,6 +102,33 @@ export function createResizerCallbacks({
|
|
|
90
102
|
api === null || api === void 0 ? void 0 : (_api$guideline = api.guideline) === null || _api$guideline === void 0 ? void 0 : (_api$guideline$action = _api$guideline.actions) === null || _api$guideline$action === void 0 ? void 0 : _api$guideline$action.displayGuideline(view)({
|
|
91
103
|
guidelines
|
|
92
104
|
});
|
|
105
|
+
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
106
|
+
var _api$breakout$sharedS;
|
|
107
|
+
const activeGuideline = guidelines.find(guideline => guideline.active && !guideline.key.startsWith('grid'));
|
|
108
|
+
if (activeGuideline) {
|
|
109
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
110
|
+
tr
|
|
111
|
+
}) => {
|
|
112
|
+
tr.setMeta(resizingPluginKey, {
|
|
113
|
+
type: 'UPDATE_ACTIVE_GUIDELINE_KEY',
|
|
114
|
+
data: {
|
|
115
|
+
activeGuidelineKey: activeGuideline.key
|
|
116
|
+
}
|
|
117
|
+
});
|
|
118
|
+
return tr;
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (!activeGuideline && api !== null && api !== void 0 && (_api$breakout$sharedS = api.breakout.sharedState.currentState()) !== null && _api$breakout$sharedS !== void 0 && _api$breakout$sharedS.activeGuidelineKey) {
|
|
122
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
123
|
+
tr
|
|
124
|
+
}) => {
|
|
125
|
+
tr.setMeta(resizingPluginKey, {
|
|
126
|
+
type: 'CLEAR_ACTIVE_GUIDELINE_KEY'
|
|
127
|
+
});
|
|
128
|
+
return tr;
|
|
129
|
+
});
|
|
130
|
+
}
|
|
131
|
+
}
|
|
93
132
|
contentDOM.style.setProperty(LOCAL_RESIZE_PROPERTY, `${newWidth}px`);
|
|
94
133
|
},
|
|
95
134
|
onDrop({
|
|
@@ -106,7 +145,7 @@ export function createResizerCallbacks({
|
|
|
106
145
|
originalNode: node
|
|
107
146
|
});
|
|
108
147
|
}
|
|
109
|
-
const isResizedToFullWidth = !!guidelines.find(guideline => guideline.key.
|
|
148
|
+
const isResizedToFullWidth = !!guidelines.find(guideline => guideline.key.startsWith('full_width') && guideline.active);
|
|
110
149
|
guidelines = getGuidelines(false, 0, getEditorWidth);
|
|
111
150
|
api === null || api === void 0 ? void 0 : (_api$guideline2 = api.guideline) === null || _api$guideline2 === void 0 ? void 0 : (_api$guideline2$actio = _api$guideline2.actions) === null || _api$guideline2$actio === void 0 ? void 0 : _api$guideline2$actio.displayGuideline(view)({
|
|
112
151
|
guidelines
|
|
@@ -122,6 +161,14 @@ export function createResizerCallbacks({
|
|
|
122
161
|
});
|
|
123
162
|
setBreakoutWidth(newWidth, mode, pos)(view.state, view.dispatch);
|
|
124
163
|
contentDOM.style.removeProperty(LOCAL_RESIZE_PROPERTY);
|
|
164
|
+
if (node && fg('platform_editor_breakout_resizing_hello_release')) {
|
|
165
|
+
const resizedPayload = generateResizedEventPayload({
|
|
166
|
+
node,
|
|
167
|
+
prevWidth: initialWidth,
|
|
168
|
+
newWidth
|
|
169
|
+
});
|
|
170
|
+
payloads.push(resizedPayload);
|
|
171
|
+
}
|
|
125
172
|
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
126
173
|
tr
|
|
127
174
|
}) => {
|
|
@@ -129,11 +176,16 @@ export function createResizerCallbacks({
|
|
|
129
176
|
(_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 ? void 0 : _api$userIntent2.commands.setCurrentUserIntent('default')({
|
|
130
177
|
tr
|
|
131
178
|
});
|
|
132
|
-
tr.setMeta('is-resizer-resizing', false).setMeta('scrollIntoView', false);
|
|
133
179
|
payloads.forEach(payload => {
|
|
134
180
|
var _api$analytics, _api$analytics$action;
|
|
135
181
|
(_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : (_api$analytics$action = _api$analytics.actions) === null || _api$analytics$action === void 0 ? void 0 : _api$analytics$action.attachAnalyticsEvent(payload)(tr);
|
|
136
182
|
});
|
|
183
|
+
tr.setMeta('is-resizer-resizing', false).setMeta('scrollIntoView', false);
|
|
184
|
+
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
185
|
+
tr.setMeta(resizingPluginKey, {
|
|
186
|
+
type: 'RESET_STATE'
|
|
187
|
+
});
|
|
188
|
+
}
|
|
137
189
|
return tr;
|
|
138
190
|
});
|
|
139
191
|
}
|
|
@@ -3,6 +3,7 @@ import { stepAddsOneOf } from '@atlaskit/editor-common/utils';
|
|
|
3
3
|
import { getChangedNodes, isReplaceDocOperation } from '@atlaskit/editor-common/utils/document';
|
|
4
4
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
5
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorCalculatedWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
6
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
7
|
import { handleKeyDown } from './handle-key-down';
|
|
7
8
|
import { ResizingMarkView } from './resizing-mark-view';
|
|
8
9
|
const addBreakoutToResizableNode = ({
|
|
@@ -44,9 +45,46 @@ const addBreakoutToResizableNode = ({
|
|
|
44
45
|
};
|
|
45
46
|
};
|
|
46
47
|
export const resizingPluginKey = new PluginKey('breakout-resizing');
|
|
48
|
+
const pluginState = {
|
|
49
|
+
init() {
|
|
50
|
+
return {
|
|
51
|
+
breakoutNode: undefined,
|
|
52
|
+
activeGuidelineLabel: undefined
|
|
53
|
+
};
|
|
54
|
+
},
|
|
55
|
+
apply(tr, pluginState) {
|
|
56
|
+
const meta = tr.getMeta(resizingPluginKey);
|
|
57
|
+
if (meta) {
|
|
58
|
+
switch (meta.type) {
|
|
59
|
+
case 'UPDATE_BREAKOUT_NODE':
|
|
60
|
+
return {
|
|
61
|
+
...pluginState,
|
|
62
|
+
breakoutNode: meta.data
|
|
63
|
+
};
|
|
64
|
+
case 'UPDATE_ACTIVE_GUIDELINE_KEY':
|
|
65
|
+
return {
|
|
66
|
+
...pluginState,
|
|
67
|
+
activeGuidelineKey: meta.data.activeGuidelineKey
|
|
68
|
+
};
|
|
69
|
+
case 'CLEAR_ACTIVE_GUIDELINE_KEY':
|
|
70
|
+
return {
|
|
71
|
+
...pluginState,
|
|
72
|
+
activeGuidelineKey: undefined
|
|
73
|
+
};
|
|
74
|
+
case 'RESET_STATE':
|
|
75
|
+
return {
|
|
76
|
+
activeGuidelineLabel: undefined,
|
|
77
|
+
breakoutNode: undefined
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
return pluginState;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
47
84
|
export const createResizingPlugin = (api, getIntl, nodeViewPortalProviderAPI, options) => {
|
|
48
85
|
return new SafePlugin({
|
|
49
86
|
key: resizingPluginKey,
|
|
87
|
+
state: fg('platform_editor_breakout_resizing_hello_release') ? pluginState : undefined,
|
|
50
88
|
props: {
|
|
51
89
|
markViews: {
|
|
52
90
|
breakout: (mark, view) => {
|
|
@@ -12,4 +12,20 @@ export const generateResizeFrameRatePayloads = props => {
|
|
|
12
12
|
isInitialSample: index === 0
|
|
13
13
|
}
|
|
14
14
|
}));
|
|
15
|
+
};
|
|
16
|
+
export const generateResizedEventPayload = ({
|
|
17
|
+
node,
|
|
18
|
+
prevWidth,
|
|
19
|
+
newWidth
|
|
20
|
+
}) => {
|
|
21
|
+
return {
|
|
22
|
+
action: ACTION.RESIZED,
|
|
23
|
+
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
24
|
+
eventType: EVENT_TYPE.TRACK,
|
|
25
|
+
attributes: {
|
|
26
|
+
nodeType: node.type.name,
|
|
27
|
+
prevWidth,
|
|
28
|
+
newWidth
|
|
29
|
+
}
|
|
30
|
+
};
|
|
15
31
|
};
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ResizerBreakoutModeLabel } from '@atlaskit/editor-common/resizer';
|
|
3
|
+
import { Popup } from '@atlaskit/editor-common/ui';
|
|
4
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
5
|
+
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
+
const GUIDELINE_KEY_TO_LAYOUT = {
|
|
7
|
+
wide_left: 'wide',
|
|
8
|
+
wide_right: 'wide',
|
|
9
|
+
full_width_left: 'full-width',
|
|
10
|
+
full_width_right: 'full-width'
|
|
11
|
+
};
|
|
12
|
+
export const GuidelineLabel = ({
|
|
13
|
+
api,
|
|
14
|
+
editorView,
|
|
15
|
+
mountPoint,
|
|
16
|
+
boundariesElement,
|
|
17
|
+
scrollableElement
|
|
18
|
+
}) => {
|
|
19
|
+
const breakoutNode = useSharedPluginStateSelector(api, 'breakout.breakoutNode');
|
|
20
|
+
const activeGuidelineKey = useSharedPluginStateSelector(api, 'breakout.activeGuidelineKey');
|
|
21
|
+
if (!breakoutNode || !activeGuidelineKey) {
|
|
22
|
+
return null;
|
|
23
|
+
}
|
|
24
|
+
const element = findDomRefAtPos(breakoutNode.pos, editorView.domAtPos.bind(editorView));
|
|
25
|
+
return /*#__PURE__*/React.createElement(Popup, {
|
|
26
|
+
target: element && element instanceof HTMLElement ? element : undefined,
|
|
27
|
+
offset: [0, 10],
|
|
28
|
+
alignY: "bottom",
|
|
29
|
+
alignX: "center",
|
|
30
|
+
mountTo: mountPoint,
|
|
31
|
+
boundariesElement: boundariesElement,
|
|
32
|
+
scrollableElement: scrollableElement,
|
|
33
|
+
stick: true,
|
|
34
|
+
forcePlacement: true
|
|
35
|
+
}, /*#__PURE__*/React.createElement(ResizerBreakoutModeLabel, {
|
|
36
|
+
layout: GUIDELINE_KEY_TO_LAYOUT[activeGuidelineKey]
|
|
37
|
+
}));
|
|
38
|
+
};
|
|
@@ -13,11 +13,13 @@ import { usePluginStateEffect } from '@atlaskit/editor-common/use-plugin-state-e
|
|
|
13
13
|
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
14
14
|
import { akEditorSwoopCubicBezier } from '@atlaskit/editor-shared-styles';
|
|
15
15
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
16
|
+
import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
|
|
16
17
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
17
18
|
import { pluginKey } from './pm-plugins/plugin-key';
|
|
18
|
-
import { createResizingPlugin } from './pm-plugins/resizing-plugin';
|
|
19
|
+
import { createResizingPlugin, resizingPluginKey } from './pm-plugins/resizing-plugin';
|
|
19
20
|
import { findSupportedNodeForBreakout } from './pm-plugins/utils/find-breakout-node';
|
|
20
21
|
import { getBreakoutMode } from './pm-plugins/utils/get-breakout-mode';
|
|
22
|
+
import { GuidelineLabel } from './ui/GuidelineLabel';
|
|
21
23
|
import LayoutButton from './ui/LayoutButton';
|
|
22
24
|
var BreakoutView = /*#__PURE__*/_createClass(function BreakoutView(
|
|
23
25
|
/**
|
|
@@ -77,7 +79,8 @@ function createPlugin(api, _ref) {
|
|
|
77
79
|
state: {
|
|
78
80
|
init: function init() {
|
|
79
81
|
return {
|
|
80
|
-
breakoutNode: undefined
|
|
82
|
+
breakoutNode: undefined,
|
|
83
|
+
activeGuidelineKey: undefined
|
|
81
84
|
};
|
|
82
85
|
},
|
|
83
86
|
apply: function apply(tr, pluginState) {
|
|
@@ -197,7 +200,7 @@ export var breakoutPlugin = function breakoutPlugin(_ref4) {
|
|
|
197
200
|
return {
|
|
198
201
|
name: 'breakout',
|
|
199
202
|
pmPlugins: function pmPlugins() {
|
|
200
|
-
if (
|
|
203
|
+
if (expValEquals('platform_editor_breakout_resizing', 'isEnabled', true)) {
|
|
201
204
|
return [{
|
|
202
205
|
name: 'breakout-resizing',
|
|
203
206
|
plugin: function plugin(_ref5) {
|
|
@@ -226,6 +229,16 @@ export var breakoutPlugin = function breakoutPlugin(_ref4) {
|
|
|
226
229
|
breakoutNode: undefined
|
|
227
230
|
};
|
|
228
231
|
}
|
|
232
|
+
if (expValEquals('platform_editor_breakout_resizing', 'isEnabled', true) && fg('platform_editor_breakout_resizing_hello_release')) {
|
|
233
|
+
var resizingPluginState = resizingPluginKey.getState(editorState);
|
|
234
|
+
if (!resizingPluginState) {
|
|
235
|
+
return {
|
|
236
|
+
breakoutNode: undefined,
|
|
237
|
+
activeGuidelineKey: undefined
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
return resizingPluginState;
|
|
241
|
+
}
|
|
229
242
|
var pluginState = pluginKey.getState(editorState);
|
|
230
243
|
if (!pluginState) {
|
|
231
244
|
return {
|
|
@@ -239,6 +252,16 @@ export var breakoutPlugin = function breakoutPlugin(_ref4) {
|
|
|
239
252
|
popupsMountPoint = _ref6.popupsMountPoint,
|
|
240
253
|
popupsBoundariesElement = _ref6.popupsBoundariesElement,
|
|
241
254
|
popupsScrollableElement = _ref6.popupsScrollableElement;
|
|
255
|
+
if (expValEquals('platform_editor_breakout_resizing', 'isEnabled', true) && fg('platform_editor_breakout_resizing_hello_release')) {
|
|
256
|
+
return /*#__PURE__*/React.createElement(GuidelineLabel, {
|
|
257
|
+
api: api,
|
|
258
|
+
editorView: editorView,
|
|
259
|
+
mountPoint: popupsMountPoint,
|
|
260
|
+
boundariesElement: popupsBoundariesElement,
|
|
261
|
+
scrollableElement: popupsScrollableElement
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
|
|
242
265
|
// This is a bit crappy, but should be resolved once we move to a static schema.
|
|
243
266
|
if (options && !options.allowBreakoutButton) {
|
|
244
267
|
return null;
|
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
import memoizeOne from 'memoize-one';
|
|
2
2
|
import { EXPAND_CONTAINER_PADDING, LAYOUT_COLUMN_PADDING, resizerHandleThumbWidth } from '@atlaskit/editor-common/styles';
|
|
3
3
|
import { akEditorGutterPaddingDynamic, akEditorGutterPadding, akEditorCalculatedWideLayoutWidth, akEditorFullWidthLayoutWidth, akEditorDefaultLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
4
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
5
|
var WIDTHS = {
|
|
5
6
|
MIN: akEditorDefaultLayoutWidth,
|
|
6
7
|
WIDE: akEditorCalculatedWideLayoutWidth,
|
|
7
8
|
MAX: akEditorFullWidthLayoutWidth
|
|
8
9
|
};
|
|
9
|
-
var GUIDELINE_KEYS = {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
export var GUIDELINE_KEYS = {
|
|
11
|
+
lineLengthLeft: 'grid_left',
|
|
12
|
+
lineLengthRight: 'grid_right',
|
|
13
|
+
wideLeft: 'wide_left',
|
|
14
|
+
wideRight: 'wide_right',
|
|
15
|
+
fullWidthLeft: 'full_width_left',
|
|
16
|
+
fullWidthRight: 'full_width_right'
|
|
13
17
|
};
|
|
14
18
|
var AK_NESTED_DND_GUTTER_OFFSET = 8;
|
|
15
19
|
var roundToNearest = function roundToNearest(value) {
|
|
@@ -37,33 +41,49 @@ export var getGuidelines = memoizeOne(function (isResizing, newWidth, getEditorW
|
|
|
37
41
|
var _ref = getEditorWidth() || {},
|
|
38
42
|
width = _ref.width,
|
|
39
43
|
lineLength = _ref.lineLength;
|
|
40
|
-
// TODO: ED-28109 - use breakoutWideScaleRatio to calculate wide guideline
|
|
41
44
|
var fullWidth = width ? Math.min(WIDTHS.MAX, width - 2 * akEditorGutterPaddingDynamic() - akEditorGutterPadding) : undefined;
|
|
42
|
-
if (
|
|
45
|
+
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
43
46
|
guidelines.push({
|
|
44
|
-
key:
|
|
47
|
+
key: GUIDELINE_KEYS.lineLengthLeft,
|
|
45
48
|
position: {
|
|
46
|
-
x: -roundToNearest(
|
|
49
|
+
x: -roundToNearest(WIDTHS.MIN / 2 + innerPaddingOffset)
|
|
47
50
|
},
|
|
48
|
-
active: newWidth ===
|
|
51
|
+
active: newWidth === WIDTHS.MIN
|
|
49
52
|
});
|
|
50
53
|
guidelines.push({
|
|
51
|
-
key:
|
|
54
|
+
key: GUIDELINE_KEYS.lineLengthRight,
|
|
52
55
|
position: {
|
|
53
|
-
x: roundToNearest(
|
|
56
|
+
x: roundToNearest(WIDTHS.MIN / 2 + innerPaddingOffset)
|
|
54
57
|
},
|
|
55
|
-
active: newWidth ===
|
|
58
|
+
active: newWidth === WIDTHS.MIN
|
|
56
59
|
});
|
|
60
|
+
} else {
|
|
61
|
+
if (lineLength) {
|
|
62
|
+
guidelines.push({
|
|
63
|
+
key: GUIDELINE_KEYS.lineLengthLeft,
|
|
64
|
+
position: {
|
|
65
|
+
x: -roundToNearest(lineLength / 2 + innerPaddingOffset)
|
|
66
|
+
},
|
|
67
|
+
active: newWidth === lineLength
|
|
68
|
+
});
|
|
69
|
+
guidelines.push({
|
|
70
|
+
key: GUIDELINE_KEYS.lineLengthRight,
|
|
71
|
+
position: {
|
|
72
|
+
x: roundToNearest(lineLength / 2 + innerPaddingOffset)
|
|
73
|
+
},
|
|
74
|
+
active: newWidth === lineLength
|
|
75
|
+
});
|
|
76
|
+
}
|
|
57
77
|
}
|
|
58
78
|
guidelines.push({
|
|
59
|
-
key:
|
|
79
|
+
key: GUIDELINE_KEYS.wideLeft,
|
|
60
80
|
position: {
|
|
61
81
|
x: -roundToNearest(WIDTHS.WIDE / 2 + innerPaddingOffset)
|
|
62
82
|
},
|
|
63
83
|
active: newWidth === WIDTHS.WIDE
|
|
64
84
|
});
|
|
65
85
|
guidelines.push({
|
|
66
|
-
key:
|
|
86
|
+
key: GUIDELINE_KEYS.wideRight,
|
|
67
87
|
position: {
|
|
68
88
|
x: roundToNearest(WIDTHS.WIDE / 2 + innerPaddingOffset)
|
|
69
89
|
},
|
|
@@ -71,14 +91,14 @@ export var getGuidelines = memoizeOne(function (isResizing, newWidth, getEditorW
|
|
|
71
91
|
});
|
|
72
92
|
if (fullWidth) {
|
|
73
93
|
guidelines.push({
|
|
74
|
-
key:
|
|
94
|
+
key: GUIDELINE_KEYS.fullWidthLeft,
|
|
75
95
|
position: {
|
|
76
96
|
x: -roundToNearest(fullWidth / 2 + innerPaddingOffset)
|
|
77
97
|
},
|
|
78
98
|
active: newWidth === fullWidth
|
|
79
99
|
});
|
|
80
100
|
guidelines.push({
|
|
81
|
-
key:
|
|
101
|
+
key: GUIDELINE_KEYS.fullWidthRight,
|
|
82
102
|
position: {
|
|
83
103
|
x: roundToNearest(fullWidth / 2 + innerPaddingOffset)
|
|
84
104
|
},
|
|
@@ -3,7 +3,8 @@ import { fg } from '@atlaskit/platform-feature-flags';
|
|
|
3
3
|
import { setBreakoutWidth } from '../editor-commands/set-breakout-width';
|
|
4
4
|
import { getGuidelines } from './get-guidelines';
|
|
5
5
|
import { LOCAL_RESIZE_PROPERTY } from './resizing-mark-view';
|
|
6
|
-
import {
|
|
6
|
+
import { resizingPluginKey } from './resizing-plugin';
|
|
7
|
+
import { generateResizeFrameRatePayloads, generateResizedEventPayload } from './utils/analytics';
|
|
7
8
|
import { measureFramerate, reduceResizeFrameRateSamples } from './utils/measure-framerate';
|
|
8
9
|
var RESIZE_RATIO = 2;
|
|
9
10
|
var SNAP_GAP = 10;
|
|
@@ -56,6 +57,8 @@ export function createResizerCallbacks(_ref2) {
|
|
|
56
57
|
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
57
58
|
startMeasure();
|
|
58
59
|
}
|
|
60
|
+
var pos = view.posAtDOM(dom, 0);
|
|
61
|
+
node = view.state.doc.nodeAt(pos);
|
|
59
62
|
api === null || api === void 0 || api.core.actions.execute(function (_ref3) {
|
|
60
63
|
var _api$userIntent;
|
|
61
64
|
var tr = _ref3.tr;
|
|
@@ -63,10 +66,19 @@ export function createResizerCallbacks(_ref2) {
|
|
|
63
66
|
tr: tr
|
|
64
67
|
});
|
|
65
68
|
tr.setMeta('is-resizer-resizing', true);
|
|
69
|
+
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
70
|
+
tr.setMeta(resizingPluginKey, {
|
|
71
|
+
type: 'UPDATE_BREAKOUT_NODE',
|
|
72
|
+
data: {
|
|
73
|
+
node: node,
|
|
74
|
+
pos: pos,
|
|
75
|
+
start: pos,
|
|
76
|
+
depth: 0
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
66
80
|
return tr;
|
|
67
81
|
});
|
|
68
|
-
var pos = view.posAtDOM(dom, 0);
|
|
69
|
-
node = view.state.doc.nodeAt(pos);
|
|
70
82
|
},
|
|
71
83
|
onDrag: function onDrag(_ref4) {
|
|
72
84
|
var _node, _api$guideline;
|
|
@@ -86,12 +98,39 @@ export function createResizerCallbacks(_ref2) {
|
|
|
86
98
|
api === null || api === void 0 || (_api$guideline = api.guideline) === null || _api$guideline === void 0 || (_api$guideline = _api$guideline.actions) === null || _api$guideline === void 0 || _api$guideline.displayGuideline(view)({
|
|
87
99
|
guidelines: guidelines
|
|
88
100
|
});
|
|
101
|
+
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
102
|
+
var _api$breakout$sharedS;
|
|
103
|
+
var activeGuideline = guidelines.find(function (guideline) {
|
|
104
|
+
return guideline.active && !guideline.key.startsWith('grid');
|
|
105
|
+
});
|
|
106
|
+
if (activeGuideline) {
|
|
107
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref5) {
|
|
108
|
+
var tr = _ref5.tr;
|
|
109
|
+
tr.setMeta(resizingPluginKey, {
|
|
110
|
+
type: 'UPDATE_ACTIVE_GUIDELINE_KEY',
|
|
111
|
+
data: {
|
|
112
|
+
activeGuidelineKey: activeGuideline.key
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
return tr;
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
if (!activeGuideline && api !== null && api !== void 0 && (_api$breakout$sharedS = api.breakout.sharedState.currentState()) !== null && _api$breakout$sharedS !== void 0 && _api$breakout$sharedS.activeGuidelineKey) {
|
|
119
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref6) {
|
|
120
|
+
var tr = _ref6.tr;
|
|
121
|
+
tr.setMeta(resizingPluginKey, {
|
|
122
|
+
type: 'CLEAR_ACTIVE_GUIDELINE_KEY'
|
|
123
|
+
});
|
|
124
|
+
return tr;
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
}
|
|
89
128
|
contentDOM.style.setProperty(LOCAL_RESIZE_PROPERTY, "".concat(newWidth, "px"));
|
|
90
129
|
},
|
|
91
|
-
onDrop: function onDrop(
|
|
130
|
+
onDrop: function onDrop(_ref7) {
|
|
92
131
|
var _api$guideline2;
|
|
93
|
-
var location =
|
|
94
|
-
source =
|
|
132
|
+
var location = _ref7.location,
|
|
133
|
+
source = _ref7.source;
|
|
95
134
|
var payloads = [];
|
|
96
135
|
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
97
136
|
var frameRateSamples = endMeasure();
|
|
@@ -102,7 +141,7 @@ export function createResizerCallbacks(_ref2) {
|
|
|
102
141
|
});
|
|
103
142
|
}
|
|
104
143
|
var isResizedToFullWidth = !!guidelines.find(function (guideline) {
|
|
105
|
-
return guideline.key.
|
|
144
|
+
return guideline.key.startsWith('full_width') && guideline.active;
|
|
106
145
|
});
|
|
107
146
|
guidelines = getGuidelines(false, 0, getEditorWidth);
|
|
108
147
|
api === null || api === void 0 || (_api$guideline2 = api.guideline) === null || _api$guideline2 === void 0 || (_api$guideline2 = _api$guideline2.actions) === null || _api$guideline2 === void 0 || _api$guideline2.displayGuideline(view)({
|
|
@@ -119,17 +158,30 @@ export function createResizerCallbacks(_ref2) {
|
|
|
119
158
|
});
|
|
120
159
|
setBreakoutWidth(newWidth, mode, pos)(view.state, view.dispatch);
|
|
121
160
|
contentDOM.style.removeProperty(LOCAL_RESIZE_PROPERTY);
|
|
122
|
-
|
|
161
|
+
if (node && fg('platform_editor_breakout_resizing_hello_release')) {
|
|
162
|
+
var resizedPayload = generateResizedEventPayload({
|
|
163
|
+
node: node,
|
|
164
|
+
prevWidth: initialWidth,
|
|
165
|
+
newWidth: newWidth
|
|
166
|
+
});
|
|
167
|
+
payloads.push(resizedPayload);
|
|
168
|
+
}
|
|
169
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref8) {
|
|
123
170
|
var _api$userIntent2;
|
|
124
|
-
var tr =
|
|
171
|
+
var tr = _ref8.tr;
|
|
125
172
|
(_api$userIntent2 = api.userIntent) === null || _api$userIntent2 === void 0 || _api$userIntent2.commands.setCurrentUserIntent('default')({
|
|
126
173
|
tr: tr
|
|
127
174
|
});
|
|
128
|
-
tr.setMeta('is-resizer-resizing', false).setMeta('scrollIntoView', false);
|
|
129
175
|
payloads.forEach(function (payload) {
|
|
130
176
|
var _api$analytics;
|
|
131
177
|
(_api$analytics = api.analytics) === null || _api$analytics === void 0 || (_api$analytics = _api$analytics.actions) === null || _api$analytics === void 0 || _api$analytics.attachAnalyticsEvent(payload)(tr);
|
|
132
178
|
});
|
|
179
|
+
tr.setMeta('is-resizer-resizing', false).setMeta('scrollIntoView', false);
|
|
180
|
+
if (fg('platform_editor_breakout_resizing_hello_release')) {
|
|
181
|
+
tr.setMeta(resizingPluginKey, {
|
|
182
|
+
type: 'RESET_STATE'
|
|
183
|
+
});
|
|
184
|
+
}
|
|
133
185
|
return tr;
|
|
134
186
|
});
|
|
135
187
|
}
|
|
@@ -1,8 +1,12 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
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; }
|
|
3
|
+
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; }
|
|
1
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
5
|
import { stepAddsOneOf } from '@atlaskit/editor-common/utils';
|
|
3
6
|
import { getChangedNodes, isReplaceDocOperation } from '@atlaskit/editor-common/utils/document';
|
|
4
7
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
5
8
|
import { akEditorDefaultLayoutWidth, akEditorFullWidthLayoutWidth, akEditorCalculatedWideLayoutWidth } from '@atlaskit/editor-shared-styles';
|
|
9
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
10
|
import { handleKeyDown } from './handle-key-down';
|
|
7
11
|
import { ResizingMarkView } from './resizing-mark-view';
|
|
8
12
|
var addBreakoutToResizableNode = function addBreakoutToResizableNode(_ref) {
|
|
@@ -43,9 +47,43 @@ var addBreakoutToResizableNode = function addBreakoutToResizableNode(_ref) {
|
|
|
43
47
|
};
|
|
44
48
|
};
|
|
45
49
|
export var resizingPluginKey = new PluginKey('breakout-resizing');
|
|
50
|
+
var pluginState = {
|
|
51
|
+
init: function init() {
|
|
52
|
+
return {
|
|
53
|
+
breakoutNode: undefined,
|
|
54
|
+
activeGuidelineLabel: undefined
|
|
55
|
+
};
|
|
56
|
+
},
|
|
57
|
+
apply: function apply(tr, pluginState) {
|
|
58
|
+
var meta = tr.getMeta(resizingPluginKey);
|
|
59
|
+
if (meta) {
|
|
60
|
+
switch (meta.type) {
|
|
61
|
+
case 'UPDATE_BREAKOUT_NODE':
|
|
62
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
63
|
+
breakoutNode: meta.data
|
|
64
|
+
});
|
|
65
|
+
case 'UPDATE_ACTIVE_GUIDELINE_KEY':
|
|
66
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
67
|
+
activeGuidelineKey: meta.data.activeGuidelineKey
|
|
68
|
+
});
|
|
69
|
+
case 'CLEAR_ACTIVE_GUIDELINE_KEY':
|
|
70
|
+
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
71
|
+
activeGuidelineKey: undefined
|
|
72
|
+
});
|
|
73
|
+
case 'RESET_STATE':
|
|
74
|
+
return {
|
|
75
|
+
activeGuidelineLabel: undefined,
|
|
76
|
+
breakoutNode: undefined
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
return pluginState;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
46
83
|
export var createResizingPlugin = function createResizingPlugin(api, getIntl, nodeViewPortalProviderAPI, options) {
|
|
47
84
|
return new SafePlugin({
|
|
48
85
|
key: resizingPluginKey,
|
|
86
|
+
state: fg('platform_editor_breakout_resizing_hello_release') ? pluginState : undefined,
|
|
49
87
|
props: {
|
|
50
88
|
markViews: {
|
|
51
89
|
breakout: function breakout(mark, view) {
|
|
@@ -14,4 +14,19 @@ export var generateResizeFrameRatePayloads = function generateResizeFrameRatePay
|
|
|
14
14
|
}
|
|
15
15
|
};
|
|
16
16
|
});
|
|
17
|
+
};
|
|
18
|
+
export var generateResizedEventPayload = function generateResizedEventPayload(_ref) {
|
|
19
|
+
var node = _ref.node,
|
|
20
|
+
prevWidth = _ref.prevWidth,
|
|
21
|
+
newWidth = _ref.newWidth;
|
|
22
|
+
return {
|
|
23
|
+
action: ACTION.RESIZED,
|
|
24
|
+
actionSubject: ACTION_SUBJECT.ELEMENT,
|
|
25
|
+
eventType: EVENT_TYPE.TRACK,
|
|
26
|
+
attributes: {
|
|
27
|
+
nodeType: node.type.name,
|
|
28
|
+
prevWidth: prevWidth,
|
|
29
|
+
newWidth: newWidth
|
|
30
|
+
}
|
|
31
|
+
};
|
|
17
32
|
};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { ResizerBreakoutModeLabel } from '@atlaskit/editor-common/resizer';
|
|
3
|
+
import { Popup } from '@atlaskit/editor-common/ui';
|
|
4
|
+
import { useSharedPluginStateSelector } from '@atlaskit/editor-common/use-shared-plugin-state-selector';
|
|
5
|
+
import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
|
|
6
|
+
var GUIDELINE_KEY_TO_LAYOUT = {
|
|
7
|
+
wide_left: 'wide',
|
|
8
|
+
wide_right: 'wide',
|
|
9
|
+
full_width_left: 'full-width',
|
|
10
|
+
full_width_right: 'full-width'
|
|
11
|
+
};
|
|
12
|
+
export var GuidelineLabel = function GuidelineLabel(_ref) {
|
|
13
|
+
var api = _ref.api,
|
|
14
|
+
editorView = _ref.editorView,
|
|
15
|
+
mountPoint = _ref.mountPoint,
|
|
16
|
+
boundariesElement = _ref.boundariesElement,
|
|
17
|
+
scrollableElement = _ref.scrollableElement;
|
|
18
|
+
var breakoutNode = useSharedPluginStateSelector(api, 'breakout.breakoutNode');
|
|
19
|
+
var activeGuidelineKey = useSharedPluginStateSelector(api, 'breakout.activeGuidelineKey');
|
|
20
|
+
if (!breakoutNode || !activeGuidelineKey) {
|
|
21
|
+
return null;
|
|
22
|
+
}
|
|
23
|
+
var element = findDomRefAtPos(breakoutNode.pos, editorView.domAtPos.bind(editorView));
|
|
24
|
+
return /*#__PURE__*/React.createElement(Popup, {
|
|
25
|
+
target: element && element instanceof HTMLElement ? element : undefined,
|
|
26
|
+
offset: [0, 10],
|
|
27
|
+
alignY: "bottom",
|
|
28
|
+
alignX: "center",
|
|
29
|
+
mountTo: mountPoint,
|
|
30
|
+
boundariesElement: boundariesElement,
|
|
31
|
+
scrollableElement: scrollableElement,
|
|
32
|
+
stick: true,
|
|
33
|
+
forcePlacement: true
|
|
34
|
+
}, /*#__PURE__*/React.createElement(ResizerBreakoutModeLabel, {
|
|
35
|
+
layout: GUIDELINE_KEY_TO_LAYOUT[activeGuidelineKey]
|
|
36
|
+
}));
|
|
37
|
+
};
|
|
@@ -8,8 +8,10 @@ import type { InteractionPlugin } from '@atlaskit/editor-plugin-interaction';
|
|
|
8
8
|
import type { UserIntentPlugin } from '@atlaskit/editor-plugin-user-intent';
|
|
9
9
|
import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
|
|
10
10
|
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
11
|
+
import { ActiveGuidelineKey } from './pm-plugins/resizing-plugin';
|
|
11
12
|
export interface BreakoutPluginState {
|
|
12
13
|
breakoutNode: ContentNodeWithPos | undefined;
|
|
14
|
+
activeGuidelineKey: ActiveGuidelineKey | undefined;
|
|
13
15
|
}
|
|
14
16
|
export interface BreakoutPluginOptions {
|
|
15
17
|
allowBreakoutButton?: boolean;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
1
|
import { GuidelineConfig } from '@atlaskit/editor-common/guideline';
|
|
2
2
|
import { EditorContainerWidth } from '@atlaskit/editor-common/types';
|
|
3
3
|
import { NodeType } from '@atlaskit/editor-prosemirror/model';
|
|
4
|
+
export declare const GUIDELINE_KEYS: {
|
|
5
|
+
readonly lineLengthLeft: "grid_left";
|
|
6
|
+
readonly lineLengthRight: "grid_right";
|
|
7
|
+
readonly wideLeft: "wide_left";
|
|
8
|
+
readonly wideRight: "wide_right";
|
|
9
|
+
readonly fullWidthLeft: "full_width_left";
|
|
10
|
+
readonly fullWidthRight: "full_width_right";
|
|
11
|
+
};
|
|
4
12
|
export declare const getGuidelines: import("memoize-one").MemoizedFn<(isResizing: boolean, newWidth: number, getEditorWidth: () => EditorContainerWidth | undefined, nodeType?: NodeType | undefined) => GuidelineConfig[]>;
|