@atlaskit/editor-plugin-block-controls 1.10.4 → 1.10.6
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 +19 -0
- package/dist/cjs/pm-plugins/decorations.js +6 -53
- package/dist/cjs/pm-plugins/main.js +38 -80
- package/dist/cjs/ui/drag-handle.js +20 -44
- package/dist/cjs/ui/drag-preview.js +1 -4
- package/dist/cjs/ui/global-styles.js +1 -1
- package/dist/cjs/utils/getSelection.js +8 -21
- package/dist/es2019/pm-plugins/decorations.js +5 -52
- package/dist/es2019/pm-plugins/main.js +37 -79
- package/dist/es2019/ui/drag-handle.js +14 -39
- package/dist/es2019/ui/drag-preview.js +1 -4
- package/dist/es2019/ui/global-styles.js +1 -1
- package/dist/es2019/utils/getSelection.js +8 -21
- package/dist/esm/pm-plugins/decorations.js +5 -52
- package/dist/esm/pm-plugins/main.js +39 -81
- package/dist/esm/ui/drag-handle.js +20 -44
- package/dist/esm/ui/drag-preview.js +1 -4
- package/dist/esm/ui/global-styles.js +1 -1
- package/dist/esm/utils/getSelection.js +8 -21
- package/dist/types/pm-plugins/decorations.d.ts +0 -6
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +0 -6
- package/package.json +3 -12
- package/dist/cjs/ui/mouse-move-wrapper.js +0 -148
- package/dist/es2019/ui/mouse-move-wrapper.js +0 -133
- package/dist/esm/ui/mouse-move-wrapper.js +0 -140
- package/dist/types/ui/mouse-move-wrapper.d.ts +0 -11
- package/dist/types-ts4.5/ui/mouse-move-wrapper.d.ts +0 -11
|
@@ -59,7 +59,7 @@ var selectedStyles = css({
|
|
|
59
59
|
color: "var(--ds-icon-selected, #0C66E4)"
|
|
60
60
|
});
|
|
61
61
|
var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
62
|
-
var _api$core2, _api$analytics2, _api$
|
|
62
|
+
var _api$core2, _api$analytics2, _api$core4, _api$core6;
|
|
63
63
|
var view = _ref.view,
|
|
64
64
|
api = _ref.api,
|
|
65
65
|
getPos = _ref.getPos,
|
|
@@ -128,32 +128,13 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
128
128
|
view.focus();
|
|
129
129
|
}, [dragHandleSelected, api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 ? void 0 : _api$core2.actions, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, view, getPos, start, nodeType]);
|
|
130
130
|
|
|
131
|
-
//
|
|
132
|
-
//
|
|
133
|
-
//
|
|
131
|
+
// TODO - This needs to be investigated further. Drag preview generation is not always working
|
|
132
|
+
// as expected with a node selection. This workaround sets the selection to the node on mouseDown,
|
|
133
|
+
// but ensures the preview is generated correctly.
|
|
134
134
|
var handleMouseDown = useCallback(function () {
|
|
135
135
|
var _api$core3;
|
|
136
136
|
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref3) {
|
|
137
137
|
var tr = _ref3.tr;
|
|
138
|
-
if (start === undefined) {
|
|
139
|
-
return tr;
|
|
140
|
-
}
|
|
141
|
-
tr = selectNode(tr, start, nodeType);
|
|
142
|
-
tr.setMeta(key, {
|
|
143
|
-
pos: start
|
|
144
|
-
});
|
|
145
|
-
return tr;
|
|
146
|
-
});
|
|
147
|
-
view.focus();
|
|
148
|
-
}, [start, api, view, nodeType]);
|
|
149
|
-
|
|
150
|
-
// TODO - This needs to be investigated further. Drag preview generation is not always working
|
|
151
|
-
// as expected with a node selection. This workaround sets the selection to the node on mouseDown,
|
|
152
|
-
// but ensures the preview is generated correctly.
|
|
153
|
-
var handleMouseDownWrapperRemoved = useCallback(function () {
|
|
154
|
-
var _api$core4;
|
|
155
|
-
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref4) {
|
|
156
|
-
var tr = _ref4.tr;
|
|
157
138
|
var startPos = fg('platform_editor_element_drag_and_drop_ed_24304') ? getPos() : start;
|
|
158
139
|
if (startPos === undefined) {
|
|
159
140
|
return tr;
|
|
@@ -170,16 +151,16 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
170
151
|
});
|
|
171
152
|
return tr;
|
|
172
153
|
});
|
|
173
|
-
}, [api === null || api === void 0 || (_api$
|
|
154
|
+
}, [api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 ? void 0 : _api$core4.actions, getPos, start]);
|
|
174
155
|
var handleKeyDown = useCallback(function (e) {
|
|
175
156
|
if (fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
176
157
|
// allow user to use spacebar to select the node
|
|
177
158
|
|
|
178
159
|
if (!e.repeat && e.key === ' ') {
|
|
179
|
-
var _api$
|
|
160
|
+
var _api$core5;
|
|
180
161
|
var startPos = fg('platform_editor_element_drag_and_drop_ed_24304') ? getPos() : start;
|
|
181
|
-
api === null || api === void 0 || (_api$
|
|
182
|
-
var tr =
|
|
162
|
+
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.execute(function (_ref4) {
|
|
163
|
+
var tr = _ref4.tr;
|
|
183
164
|
if (startPos === undefined) {
|
|
184
165
|
return tr;
|
|
185
166
|
}
|
|
@@ -203,7 +184,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
203
184
|
view.focus();
|
|
204
185
|
}
|
|
205
186
|
}
|
|
206
|
-
}, [getPos, start, api === null || api === void 0 || (_api$
|
|
187
|
+
}, [getPos, start, api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 ? void 0 : _api$core6.actions, view]);
|
|
207
188
|
useEffect(function () {
|
|
208
189
|
var element = buttonRef.current;
|
|
209
190
|
if (!element) {
|
|
@@ -217,11 +198,11 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
217
198
|
start: start
|
|
218
199
|
};
|
|
219
200
|
},
|
|
220
|
-
onGenerateDragPreview: function onGenerateDragPreview(
|
|
221
|
-
var nativeSetDragImage =
|
|
201
|
+
onGenerateDragPreview: function onGenerateDragPreview(_ref5) {
|
|
202
|
+
var nativeSetDragImage = _ref5.nativeSetDragImage;
|
|
222
203
|
setCustomNativeDragPreview({
|
|
223
|
-
render: function render(
|
|
224
|
-
var container =
|
|
204
|
+
render: function render(_ref6) {
|
|
205
|
+
var container = _ref6.container;
|
|
225
206
|
var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
|
|
226
207
|
if (!dom) {
|
|
227
208
|
return;
|
|
@@ -232,13 +213,13 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
232
213
|
});
|
|
233
214
|
},
|
|
234
215
|
onDragStart: function onDragStart() {
|
|
235
|
-
var _api$
|
|
216
|
+
var _api$core7;
|
|
236
217
|
if (start === undefined) {
|
|
237
218
|
return;
|
|
238
219
|
}
|
|
239
|
-
api === null || api === void 0 || (_api$
|
|
220
|
+
api === null || api === void 0 || (_api$core7 = api.core) === null || _api$core7 === void 0 || _api$core7.actions.execute(function (_ref7) {
|
|
240
221
|
var _api$blockControls, _api$analytics3;
|
|
241
|
-
var tr =
|
|
222
|
+
var tr = _ref7.tr;
|
|
242
223
|
api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 || _api$blockControls.commands.setNodeDragged(start, anchorName, nodeType)({
|
|
243
224
|
tr: tr
|
|
244
225
|
});
|
|
@@ -283,20 +264,14 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
283
264
|
}
|
|
284
265
|
}
|
|
285
266
|
if (supportsAnchor) {
|
|
286
|
-
return
|
|
267
|
+
return {
|
|
287
268
|
left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(anchor(".concat(anchorName, " start) + ").concat(getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : "calc(anchor(".concat(anchorName, " start) - ").concat(DRAG_HANDLE_WIDTH, "px - ").concat(dragHandleGap(nodeType), "px)"),
|
|
288
269
|
top: fg('platform_editor_elements_dnd_ed_23674') ? "calc(anchor(".concat(anchorName, " start) + ").concat(topPositionAdjustment(nodeType), "px)") : anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
|
|
289
|
-
} : {
|
|
290
|
-
left: hasResizer || isExtension || isBlockCard || isEmbedCard ? getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates) : "calc(anchor(".concat(anchorName, " start) - ").concat(DRAG_HANDLE_WIDTH, "px - ").concat(dragHandleGap(nodeType), "px)"),
|
|
291
|
-
top: fg('platform_editor_elements_dnd_ed_23674') ? "calc(anchor(".concat(anchorName, " start) + ").concat(topPositionAdjustment(nodeType), "px)") : anchorName.includes('table') ? "calc(anchor(".concat(anchorName, " start) + ").concat(DRAG_HANDLE_HEIGHT, "px)") : "anchor(".concat(anchorName, " start)")
|
|
292
270
|
};
|
|
293
271
|
}
|
|
294
|
-
return
|
|
272
|
+
return {
|
|
295
273
|
left: hasResizer || isExtension || isEmbedCard || isBlockCard && innerContainer ? "calc(".concat((dom === null || dom === void 0 ? void 0 : dom.offsetLeft) || 0, "px + ").concat(getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates), ")") : getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates),
|
|
296
274
|
top: fg('platform_editor_elements_dnd_ed_23674') ? getTopPosition(dom, nodeType) : getTopPosition(dom)
|
|
297
|
-
} : {
|
|
298
|
-
left: getLeftPosition(dom, nodeType, innerContainer, macroInteractionUpdates),
|
|
299
|
-
top: fg('platform_editor_elements_dnd_ed_23674') ? getTopPosition(dom, nodeType) : getTopPosition(dom)
|
|
300
275
|
};
|
|
301
276
|
}, [anchorName, nodeType, view, blockCardWidth, macroInteractionUpdates]);
|
|
302
277
|
var _useState5 = useState({
|
|
@@ -372,7 +347,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
372
347
|
,
|
|
373
348
|
style: fg('platform_editor_element_drag_and_drop_ed_23896') ? newPositionStyles : positionStyles,
|
|
374
349
|
onClick: handleOnClick,
|
|
375
|
-
onMouseDown:
|
|
350
|
+
onMouseDown: handleMouseDown,
|
|
376
351
|
onKeyDown: handleKeyDown,
|
|
377
352
|
"data-testid": "block-ctrl-drag-handle"
|
|
378
353
|
}, jsx(DragHandlerIcon, {
|
|
@@ -385,6 +360,7 @@ var DragHandleInternal = function DragHandleInternal(_ref) {
|
|
|
385
360
|
content: jsx(TooltipContentWithMultipleShortcuts, {
|
|
386
361
|
helpDescriptors: helpDescriptors
|
|
387
362
|
}),
|
|
363
|
+
ignoreTooltipPointerEvents: true,
|
|
388
364
|
onShow: function onShow() {
|
|
389
365
|
var _api$accessibilityUti;
|
|
390
366
|
api === null || api === void 0 || (_api$accessibilityUti = api.accessibilityUtils) === null || _api$accessibilityUti === void 0 || _api$accessibilityUti.actions.ariaNotify(message, {
|
|
@@ -13,10 +13,7 @@ export var dragPreview = function dragPreview(container, dom, nodeType) {
|
|
|
13
13
|
container.style.pointerEvents = 'none';
|
|
14
14
|
var parent = document.createElement('div');
|
|
15
15
|
// ProseMirror class is required to make sure the cloned dom is styled correctly
|
|
16
|
-
parent.classList.add('ProseMirror');
|
|
17
|
-
if (fg('platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2')) {
|
|
18
|
-
parent.classList.add('block-ctrl-drag-preview');
|
|
19
|
-
}
|
|
16
|
+
parent.classList.add('ProseMirror', 'block-ctrl-drag-preview');
|
|
20
17
|
var embedCard = dom.querySelector('.embedCardView-content-wrap');
|
|
21
18
|
var shouldBeGenericPreview = nodeType === 'embedCard' || nodeType === 'extension' || !!embedCard;
|
|
22
19
|
if (fg('platform_editor_elements_drag_and_drop_ed_23189')) {
|
|
@@ -122,6 +122,6 @@ var getTextNodeStyle = function getTextNodeStyle() {
|
|
|
122
122
|
};
|
|
123
123
|
export var GlobalStylesWrapper = function GlobalStylesWrapper() {
|
|
124
124
|
return jsx(Global, {
|
|
125
|
-
styles: [globalStyles, fg('
|
|
125
|
+
styles: [globalStyles, fg('platform_editor_elements_dnd_nested') ? extendedHoverZoneNested : extendedHoverZone, getTextNodeStyle(), withDeleteLinesStyleFix, withMediaSingleStyleFix]
|
|
126
126
|
});
|
|
127
127
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
2
2
|
import { selectTableClosestToPos } from '@atlaskit/editor-tables/utils';
|
|
3
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
4
3
|
export var getSelection = function getSelection(tr, start) {
|
|
5
4
|
var node = tr.doc.nodeAt(start);
|
|
6
5
|
var isNodeSelection = node && NodeSelection.isSelectable(node);
|
|
@@ -16,7 +15,7 @@ export var getSelection = function getSelection(tr, start) {
|
|
|
16
15
|
} else if (
|
|
17
16
|
// Even though mediaGroup is not selectable,
|
|
18
17
|
// we need a quick way to make all child media nodes appear as selected without the need for a custom selection
|
|
19
|
-
(node === null || node === void 0 ? void 0 : node.type.name) === 'mediaGroup'
|
|
18
|
+
(node === null || node === void 0 ? void 0 : node.type.name) === 'mediaGroup') {
|
|
20
19
|
return new NodeSelection($startPos);
|
|
21
20
|
} else {
|
|
22
21
|
// To trigger the annotation floating toolbar for non-selectable node, we need to select inline nodes
|
|
@@ -25,28 +24,16 @@ export var getSelection = function getSelection(tr, start) {
|
|
|
25
24
|
var foundInlineNode = false;
|
|
26
25
|
var inlineNodeEndPos = 0;
|
|
27
26
|
tr.doc.nodesBetween($startPos.pos, $startPos.pos + nodeSize, function (n, pos) {
|
|
28
|
-
if (
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
foundInlineNode = true;
|
|
35
|
-
}
|
|
36
|
-
} else {
|
|
37
|
-
if (foundInlineNode) {
|
|
38
|
-
return false;
|
|
39
|
-
}
|
|
40
|
-
if (n.isInline) {
|
|
41
|
-
inlineNodePos = pos;
|
|
42
|
-
foundInlineNode = true;
|
|
43
|
-
return false;
|
|
44
|
-
}
|
|
27
|
+
if (n.isInline) {
|
|
28
|
+
inlineNodeEndPos = pos + n.nodeSize;
|
|
29
|
+
}
|
|
30
|
+
if (n.isInline && !foundInlineNode) {
|
|
31
|
+
inlineNodePos = pos;
|
|
32
|
+
foundInlineNode = true;
|
|
45
33
|
}
|
|
46
34
|
return true;
|
|
47
35
|
});
|
|
48
|
-
|
|
49
|
-
return new TextSelection(tr.doc.resolve(fg('platform.editor.elements.drag-and-drop-ed-23905') ? inlineNodeEndPos : start + nodeSize - inlineNodeDepth), tr.doc.resolve(inlineNodePos));
|
|
36
|
+
return new TextSelection(tr.doc.resolve(inlineNodeEndPos), tr.doc.resolve(inlineNodePos));
|
|
50
37
|
}
|
|
51
38
|
};
|
|
52
39
|
export var selectNode = function selectNode(tr, start, nodeType) {
|
|
@@ -12,10 +12,4 @@ export declare const dropTargetDecorations: (oldState: EditorState, newState: Ed
|
|
|
12
12
|
};
|
|
13
13
|
export declare const emptyParagraphNodeDecorations: () => Decoration;
|
|
14
14
|
export declare const nodeDecorations: (newState: EditorState) => Decoration[];
|
|
15
|
-
/**
|
|
16
|
-
* Setting up decorations around each node to track mousemove events into each node
|
|
17
|
-
* When a mouseenter event is triggered on the node, we will set the activeNode to the node
|
|
18
|
-
* And show the drag handle
|
|
19
|
-
*/
|
|
20
|
-
export declare const mouseMoveWrapperDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => Decoration[];
|
|
21
15
|
export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape, pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
|
|
@@ -12,10 +12,4 @@ export declare const dropTargetDecorations: (oldState: EditorState, newState: Ed
|
|
|
12
12
|
};
|
|
13
13
|
export declare const emptyParagraphNodeDecorations: () => Decoration;
|
|
14
14
|
export declare const nodeDecorations: (newState: EditorState) => Decoration[];
|
|
15
|
-
/**
|
|
16
|
-
* Setting up decorations around each node to track mousemove events into each node
|
|
17
|
-
* When a mouseenter event is triggered on the node, we will set the activeNode to the node
|
|
18
|
-
* And show the drag handle
|
|
19
|
-
*/
|
|
20
|
-
export declare const mouseMoveWrapperDecorations: (newState: EditorState, api: ExtractInjectionAPI<BlockControlsPlugin>) => Decoration[];
|
|
21
15
|
export declare const dragHandleDecoration: (api: ExtractInjectionAPI<BlockControlsPlugin>, getIntl: () => IntlShape, pos: number, anchorName: string, nodeType: string, handleOptions?: HandleOptions) => Decoration;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "1.10.
|
|
3
|
+
"version": "1.10.6",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"@atlaskit/adf-schema": "^40.3.0",
|
|
35
|
-
"@atlaskit/editor-common": "^87.
|
|
35
|
+
"@atlaskit/editor-common": "^87.5.0",
|
|
36
36
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^1.6.0",
|
|
38
38
|
"@atlaskit/editor-plugin-editor-disabled": "^1.2.0",
|
|
@@ -48,7 +48,7 @@
|
|
|
48
48
|
"@atlaskit/pragmatic-drag-and-drop-react-drop-indicator": "^1.1.0",
|
|
49
49
|
"@atlaskit/theme": "^12.11.0",
|
|
50
50
|
"@atlaskit/tokens": "^1.57.0",
|
|
51
|
-
"@atlaskit/tooltip": "^18.
|
|
51
|
+
"@atlaskit/tooltip": "^18.6.0",
|
|
52
52
|
"@babel/runtime": "^7.0.0",
|
|
53
53
|
"@emotion/react": "^11.7.1",
|
|
54
54
|
"bind-event-listener": "^3.0.0",
|
|
@@ -95,9 +95,6 @@
|
|
|
95
95
|
}
|
|
96
96
|
},
|
|
97
97
|
"platform-feature-flags": {
|
|
98
|
-
"platform.editor.elements.drag-and-drop-remove-wrapper_fyqr2": {
|
|
99
|
-
"type": "boolean"
|
|
100
|
-
},
|
|
101
98
|
"platform.editor.elements.drag-and-drop-long-node-scroll": {
|
|
102
99
|
"type": "boolean"
|
|
103
100
|
},
|
|
@@ -111,9 +108,6 @@
|
|
|
111
108
|
"platform.editor.elements.drag-and-drop-ed-23816": {
|
|
112
109
|
"type": "boolean"
|
|
113
110
|
},
|
|
114
|
-
"platform.editor.elements.drag-and-drop-ed-23905": {
|
|
115
|
-
"type": "boolean"
|
|
116
|
-
},
|
|
117
111
|
"platform_editor_elements_drag_and_drop_ed_23189": {
|
|
118
112
|
"type": "boolean"
|
|
119
113
|
},
|
|
@@ -123,9 +117,6 @@
|
|
|
123
117
|
"platform_editor_element_drag_and_drop_ed_23873": {
|
|
124
118
|
"type": "boolean"
|
|
125
119
|
},
|
|
126
|
-
"platform_editor_element_drag_and_drop_ed_23842": {
|
|
127
|
-
"type": "boolean"
|
|
128
|
-
},
|
|
129
120
|
"platform_editor_elements_drag_and_drop_ed_23394": {
|
|
130
121
|
"type": "boolean"
|
|
131
122
|
},
|
|
@@ -1,148 +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.MouseMoveWrapper = void 0;
|
|
8
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
|
-
var _react = require("react");
|
|
10
|
-
var _react2 = require("@emotion/react");
|
|
11
|
-
var _bindEventListener = require("bind-event-listener");
|
|
12
|
-
var _main = require("../pm-plugins/main");
|
|
13
|
-
var _dragHandlePositions = require("../utils/drag-handle-positions");
|
|
14
|
-
var _consts = require("./consts");
|
|
15
|
-
/**
|
|
16
|
-
* @jsxRuntime classic
|
|
17
|
-
* @jsx jsx
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
21
|
-
|
|
22
|
-
var basicStyles = (0, _react2.css)({
|
|
23
|
-
position: 'absolute',
|
|
24
|
-
width: '100%',
|
|
25
|
-
left: '0',
|
|
26
|
-
display: 'block',
|
|
27
|
-
zIndex: -1
|
|
28
|
-
});
|
|
29
|
-
var mouseMoveWrapperStyles = (0, _react2.css)({
|
|
30
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
31
|
-
zIndex: _consts.DRAG_HANDLE_ZINDEX
|
|
32
|
-
});
|
|
33
|
-
var MouseMoveWrapper = exports.MouseMoveWrapper = function MouseMoveWrapper(_ref) {
|
|
34
|
-
var view = _ref.view,
|
|
35
|
-
api = _ref.api,
|
|
36
|
-
anchorName = _ref.anchorName,
|
|
37
|
-
nodeType = _ref.nodeType,
|
|
38
|
-
getPos = _ref.getPos;
|
|
39
|
-
// Using a ref for isDragging reduce re-renders
|
|
40
|
-
var isDragging = (0, _react.useRef)(false);
|
|
41
|
-
var _useState = (0, _react.useState)(false),
|
|
42
|
-
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
43
|
-
hideWrapper = _useState2[0],
|
|
44
|
-
setHideWrapper = _useState2[1];
|
|
45
|
-
var ref = (0, _react.useRef)(null);
|
|
46
|
-
var _useState3 = (0, _react.useState)(),
|
|
47
|
-
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
48
|
-
pos = _useState4[0],
|
|
49
|
-
setPos = _useState4[1];
|
|
50
|
-
(0, _react.useEffect)(function () {
|
|
51
|
-
// Adding this event listener to fix issue where wrapper isn't hidden if user navigates to node before page finishes loading
|
|
52
|
-
// This will be removed when we refactor to remove this component
|
|
53
|
-
var unbind;
|
|
54
|
-
if (ref.current) {
|
|
55
|
-
unbind = (0, _bindEventListener.bind)(ref.current, {
|
|
56
|
-
type: 'mousemove',
|
|
57
|
-
listener: function listener() {
|
|
58
|
-
setHideWrapper(true);
|
|
59
|
-
unbind();
|
|
60
|
-
}
|
|
61
|
-
});
|
|
62
|
-
}
|
|
63
|
-
return function () {
|
|
64
|
-
var _unbind;
|
|
65
|
-
return (_unbind = unbind) === null || _unbind === void 0 ? void 0 : _unbind();
|
|
66
|
-
};
|
|
67
|
-
}, []);
|
|
68
|
-
var _onMouseEnter = (0, _react.useCallback)(function () {
|
|
69
|
-
if (!isDragging.current) {
|
|
70
|
-
setHideWrapper(true);
|
|
71
|
-
}
|
|
72
|
-
var pos = getPos();
|
|
73
|
-
if (pos === undefined) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (api && api.blockControls && !isDragging.current) {
|
|
77
|
-
var _api$core;
|
|
78
|
-
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(api.blockControls.commands.showDragHandleAt(pos, anchorName, nodeType));
|
|
79
|
-
}
|
|
80
|
-
}, [getPos, isDragging, api, anchorName, nodeType]);
|
|
81
|
-
|
|
82
|
-
//THIS IS TRIGGERED A LOT!
|
|
83
|
-
var onSharedStateChange = (0, _react.useCallback)(function (_ref2) {
|
|
84
|
-
var _nextSharedState$acti;
|
|
85
|
-
var nextSharedState = _ref2.nextSharedState;
|
|
86
|
-
if ((nextSharedState === null || nextSharedState === void 0 || (_nextSharedState$acti = nextSharedState.activeNode) === null || _nextSharedState$acti === void 0 ? void 0 : _nextSharedState$acti.anchorName) !== anchorName && !isDragging.current) {
|
|
87
|
-
setHideWrapper(false);
|
|
88
|
-
}
|
|
89
|
-
if (nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.isDragging && !isDragging.current) {
|
|
90
|
-
isDragging.current = true;
|
|
91
|
-
setHideWrapper(true);
|
|
92
|
-
}
|
|
93
|
-
if ((nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isDragging) === false && isDragging.current) {
|
|
94
|
-
isDragging.current = false;
|
|
95
|
-
setHideWrapper(false);
|
|
96
|
-
}
|
|
97
|
-
}, [anchorName]);
|
|
98
|
-
(0, _react.useEffect)(function () {
|
|
99
|
-
var _api$blockControls;
|
|
100
|
-
var unbind = api === null || api === void 0 || (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.onChange(onSharedStateChange);
|
|
101
|
-
return function () {
|
|
102
|
-
unbind === null || unbind === void 0 || unbind();
|
|
103
|
-
};
|
|
104
|
-
}, [onSharedStateChange, api]);
|
|
105
|
-
(0, _react.useLayoutEffect)(function () {
|
|
106
|
-
var supportsAnchor = CSS.supports('height', "anchor-size(".concat(anchorName, " height)")) && CSS.supports('top', "anchor(".concat(anchorName, " start)"));
|
|
107
|
-
if (supportsAnchor) {
|
|
108
|
-
setPos({
|
|
109
|
-
height: "anchor-size(".concat(anchorName, " height)"),
|
|
110
|
-
top: "anchor(".concat(anchorName, " start)")
|
|
111
|
-
});
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
var calcPos = requestAnimationFrame(function () {
|
|
115
|
-
var dom = view.dom.querySelector("[data-drag-handler-anchor-name=\"".concat(anchorName, "\"]"));
|
|
116
|
-
if (!dom) {
|
|
117
|
-
return;
|
|
118
|
-
}
|
|
119
|
-
setPos({
|
|
120
|
-
height: "".concat(dom.offsetHeight, "px"),
|
|
121
|
-
top: (0, _dragHandlePositions.getTopPosition)(dom)
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
return function () {
|
|
125
|
-
return cancelAnimationFrame(calcPos);
|
|
126
|
-
};
|
|
127
|
-
}, [view, anchorName]);
|
|
128
|
-
return (0, _react2.jsx)("div", {
|
|
129
|
-
ref: ref,
|
|
130
|
-
onMouseEnter: function onMouseEnter() {
|
|
131
|
-
var _key$getState;
|
|
132
|
-
// Once onDragEnter handler is processed, wrapper for drop target is hidden
|
|
133
|
-
// This means wrapper for draggable is shown, triggering onMouseEnter and showing draggable's drag handle again
|
|
134
|
-
// hence we want to ignore it while we still dragging
|
|
135
|
-
if (!((_key$getState = _main.key.getState(view.state)) !== null && _key$getState !== void 0 && _key$getState.isPMDragging)) {
|
|
136
|
-
_onMouseEnter();
|
|
137
|
-
}
|
|
138
|
-
},
|
|
139
|
-
css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles]
|
|
140
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
141
|
-
,
|
|
142
|
-
style: pos
|
|
143
|
-
// we want achieve the same result as onMouseEnter: make wrapper inactive and display drag handle next to drop target
|
|
144
|
-
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop
|
|
145
|
-
,
|
|
146
|
-
onDragEnter: _onMouseEnter
|
|
147
|
-
});
|
|
148
|
-
};
|
|
@@ -1,133 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @jsxRuntime classic
|
|
3
|
-
* @jsx jsx
|
|
4
|
-
*/
|
|
5
|
-
import { useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
6
|
-
|
|
7
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/use-compiled -- Ignored via go/DSP-18766
|
|
8
|
-
import { css, jsx } from '@emotion/react';
|
|
9
|
-
import { bind } from 'bind-event-listener';
|
|
10
|
-
import { key } from '../pm-plugins/main';
|
|
11
|
-
import { getTopPosition } from '../utils/drag-handle-positions';
|
|
12
|
-
import { DRAG_HANDLE_ZINDEX } from './consts';
|
|
13
|
-
const basicStyles = css({
|
|
14
|
-
position: 'absolute',
|
|
15
|
-
width: '100%',
|
|
16
|
-
left: '0',
|
|
17
|
-
display: 'block',
|
|
18
|
-
zIndex: -1
|
|
19
|
-
});
|
|
20
|
-
const mouseMoveWrapperStyles = css({
|
|
21
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/no-imported-style-values, @atlaskit/ui-styling-standard/no-unsafe-values -- Ignored via go/DSP-18766
|
|
22
|
-
zIndex: DRAG_HANDLE_ZINDEX
|
|
23
|
-
});
|
|
24
|
-
export const MouseMoveWrapper = ({
|
|
25
|
-
view,
|
|
26
|
-
api,
|
|
27
|
-
anchorName,
|
|
28
|
-
nodeType,
|
|
29
|
-
getPos
|
|
30
|
-
}) => {
|
|
31
|
-
// Using a ref for isDragging reduce re-renders
|
|
32
|
-
const isDragging = useRef(false);
|
|
33
|
-
const [hideWrapper, setHideWrapper] = useState(false);
|
|
34
|
-
const ref = useRef(null);
|
|
35
|
-
const [pos, setPos] = useState();
|
|
36
|
-
useEffect(() => {
|
|
37
|
-
// Adding this event listener to fix issue where wrapper isn't hidden if user navigates to node before page finishes loading
|
|
38
|
-
// This will be removed when we refactor to remove this component
|
|
39
|
-
let unbind;
|
|
40
|
-
if (ref.current) {
|
|
41
|
-
unbind = bind(ref.current, {
|
|
42
|
-
type: 'mousemove',
|
|
43
|
-
listener: () => {
|
|
44
|
-
setHideWrapper(true);
|
|
45
|
-
unbind();
|
|
46
|
-
}
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
return () => {
|
|
50
|
-
var _unbind;
|
|
51
|
-
return (_unbind = unbind) === null || _unbind === void 0 ? void 0 : _unbind();
|
|
52
|
-
};
|
|
53
|
-
}, []);
|
|
54
|
-
const onMouseEnter = useCallback(() => {
|
|
55
|
-
if (!isDragging.current) {
|
|
56
|
-
setHideWrapper(true);
|
|
57
|
-
}
|
|
58
|
-
const pos = getPos();
|
|
59
|
-
if (pos === undefined) {
|
|
60
|
-
return;
|
|
61
|
-
}
|
|
62
|
-
if (api && api.blockControls && !isDragging.current) {
|
|
63
|
-
var _api$core;
|
|
64
|
-
api === null || api === void 0 ? void 0 : (_api$core = api.core) === null || _api$core === void 0 ? void 0 : _api$core.actions.execute(api.blockControls.commands.showDragHandleAt(pos, anchorName, nodeType));
|
|
65
|
-
}
|
|
66
|
-
}, [getPos, isDragging, api, anchorName, nodeType]);
|
|
67
|
-
|
|
68
|
-
//THIS IS TRIGGERED A LOT!
|
|
69
|
-
const onSharedStateChange = useCallback(({
|
|
70
|
-
nextSharedState
|
|
71
|
-
}) => {
|
|
72
|
-
var _nextSharedState$acti;
|
|
73
|
-
if ((nextSharedState === null || nextSharedState === void 0 ? void 0 : (_nextSharedState$acti = nextSharedState.activeNode) === null || _nextSharedState$acti === void 0 ? void 0 : _nextSharedState$acti.anchorName) !== anchorName && !isDragging.current) {
|
|
74
|
-
setHideWrapper(false);
|
|
75
|
-
}
|
|
76
|
-
if (nextSharedState !== null && nextSharedState !== void 0 && nextSharedState.isDragging && !isDragging.current) {
|
|
77
|
-
isDragging.current = true;
|
|
78
|
-
setHideWrapper(true);
|
|
79
|
-
}
|
|
80
|
-
if ((nextSharedState === null || nextSharedState === void 0 ? void 0 : nextSharedState.isDragging) === false && isDragging.current) {
|
|
81
|
-
isDragging.current = false;
|
|
82
|
-
setHideWrapper(false);
|
|
83
|
-
}
|
|
84
|
-
}, [anchorName]);
|
|
85
|
-
useEffect(() => {
|
|
86
|
-
var _api$blockControls;
|
|
87
|
-
const unbind = api === null || api === void 0 ? void 0 : (_api$blockControls = api.blockControls) === null || _api$blockControls === void 0 ? void 0 : _api$blockControls.sharedState.onChange(onSharedStateChange);
|
|
88
|
-
return () => {
|
|
89
|
-
unbind === null || unbind === void 0 ? void 0 : unbind();
|
|
90
|
-
};
|
|
91
|
-
}, [onSharedStateChange, api]);
|
|
92
|
-
useLayoutEffect(() => {
|
|
93
|
-
const supportsAnchor = CSS.supports('height', `anchor-size(${anchorName} height)`) && CSS.supports('top', `anchor(${anchorName} start)`);
|
|
94
|
-
if (supportsAnchor) {
|
|
95
|
-
setPos({
|
|
96
|
-
height: `anchor-size(${anchorName} height)`,
|
|
97
|
-
top: `anchor(${anchorName} start)`
|
|
98
|
-
});
|
|
99
|
-
return;
|
|
100
|
-
}
|
|
101
|
-
const calcPos = requestAnimationFrame(() => {
|
|
102
|
-
const dom = view.dom.querySelector(`[data-drag-handler-anchor-name="${anchorName}"]`);
|
|
103
|
-
if (!dom) {
|
|
104
|
-
return;
|
|
105
|
-
}
|
|
106
|
-
setPos({
|
|
107
|
-
height: `${dom.offsetHeight}px`,
|
|
108
|
-
top: getTopPosition(dom)
|
|
109
|
-
});
|
|
110
|
-
});
|
|
111
|
-
return () => cancelAnimationFrame(calcPos);
|
|
112
|
-
}, [view, anchorName]);
|
|
113
|
-
return jsx("div", {
|
|
114
|
-
ref: ref,
|
|
115
|
-
onMouseEnter: () => {
|
|
116
|
-
var _key$getState;
|
|
117
|
-
// Once onDragEnter handler is processed, wrapper for drop target is hidden
|
|
118
|
-
// This means wrapper for draggable is shown, triggering onMouseEnter and showing draggable's drag handle again
|
|
119
|
-
// hence we want to ignore it while we still dragging
|
|
120
|
-
if (!((_key$getState = key.getState(view.state)) !== null && _key$getState !== void 0 && _key$getState.isPMDragging)) {
|
|
121
|
-
onMouseEnter();
|
|
122
|
-
}
|
|
123
|
-
},
|
|
124
|
-
css: [basicStyles, !hideWrapper && mouseMoveWrapperStyles]
|
|
125
|
-
// eslint-disable-next-line @atlaskit/ui-styling-standard/enforce-style-prop -- Ignored via go/DSP-18766
|
|
126
|
-
,
|
|
127
|
-
style: pos
|
|
128
|
-
// we want achieve the same result as onMouseEnter: make wrapper inactive and display drag handle next to drop target
|
|
129
|
-
// eslint-disable-next-line @atlaskit/design-system/no-direct-use-of-web-platform-drag-and-drop
|
|
130
|
-
,
|
|
131
|
-
onDragEnter: onMouseEnter
|
|
132
|
-
});
|
|
133
|
-
};
|