@atlaskit/editor-plugin-block-controls 2.1.1 → 2.1.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 +14 -0
- package/dist/cjs/pm-plugins/main.js +49 -65
- package/dist/es2019/pm-plugins/main.js +38 -57
- package/dist/esm/pm-plugins/main.js +49 -65
- package/dist/types/types.d.ts +0 -1
- package/dist/types-ts4.5/types.d.ts +0 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 2.1.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#144997](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/144997)
|
|
8
|
+
[`8bf63082ba73e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/8bf63082ba73e) -
|
|
9
|
+
Reduce cost of apply method to improve input latency
|
|
10
|
+
|
|
11
|
+
## 2.1.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies
|
|
16
|
+
|
|
3
17
|
## 2.1.1
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -91,10 +91,14 @@ var initialState = {
|
|
|
91
91
|
editorWidthRight: 0,
|
|
92
92
|
isResizerResizing: false,
|
|
93
93
|
isDocSizeLimitEnabled: null,
|
|
94
|
-
isPMDragging: false
|
|
95
|
-
childCount: 0
|
|
94
|
+
isPMDragging: false
|
|
96
95
|
};
|
|
97
96
|
var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
97
|
+
var _getIntl = getIntl(),
|
|
98
|
+
formatMessage = _getIntl.formatMessage;
|
|
99
|
+
var isNestedEnabled = (0, _experiments.editorExperiment)('nested-dnd', true, {
|
|
100
|
+
exposure: true
|
|
101
|
+
});
|
|
98
102
|
return new _safePlugin.SafePlugin({
|
|
99
103
|
key: key,
|
|
100
104
|
state: {
|
|
@@ -111,19 +115,18 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
111
115
|
editorWidthRight = currentState.editorWidthRight,
|
|
112
116
|
isResizerResizing = currentState.isResizerResizing,
|
|
113
117
|
isDragging = currentState.isDragging,
|
|
114
|
-
isPMDragging = currentState.isPMDragging
|
|
115
|
-
childCount = currentState.childCount;
|
|
118
|
+
isPMDragging = currentState.isPMDragging;
|
|
116
119
|
|
|
117
|
-
// Remap existing decorations when
|
|
120
|
+
// Remap existing decorations when steps exist
|
|
118
121
|
if (tr.docChanged) {
|
|
119
122
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
120
123
|
}
|
|
121
124
|
var meta = tr.getMeta(key);
|
|
122
|
-
var isPerformanceFix = (0, _experiments.editorExperiment)('dnd-input-performance-optimisation', true, {
|
|
125
|
+
var isPerformanceFix = isNestedEnabled || (0, _experiments.editorExperiment)('dnd-input-performance-optimisation', true, {
|
|
123
126
|
exposure: true
|
|
124
|
-
})
|
|
127
|
+
});
|
|
125
128
|
var activeNodeWithNewNodeType = null;
|
|
126
|
-
|
|
129
|
+
|
|
127
130
|
// If tables or media are being resized, we want to hide the drag handle
|
|
128
131
|
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
129
132
|
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
@@ -132,52 +135,40 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
132
135
|
return e instanceof _steps.AnalyticsStep;
|
|
133
136
|
});
|
|
134
137
|
};
|
|
135
|
-
var
|
|
138
|
+
var maybeNodeCountChanged = isNestedEnabled ? !(0, _utils.isTextInput)(tr) && tr.docChanged && canIgnoreTr() : oldState.doc.childCount !== newState.doc.childCount;
|
|
136
139
|
var shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
137
140
|
|
|
138
141
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
139
142
|
// Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
|
|
140
143
|
// Don't remove the handle if remote changes are changing the node count, its prosemirror position can be mapped instead
|
|
141
|
-
if (isResizerResizing ||
|
|
142
|
-
var oldHandle = decorations.find(
|
|
143
|
-
var spec = _ref5.spec;
|
|
144
|
+
if (isResizerResizing || maybeNodeCountChanged && shouldRemoveHandle || meta !== null && meta !== void 0 && meta.nodeMoved) {
|
|
145
|
+
var oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
144
146
|
return spec.id === 'drag-handle';
|
|
145
147
|
});
|
|
146
148
|
decorations = decorations.remove(oldHandle);
|
|
147
149
|
}
|
|
148
|
-
var
|
|
149
|
-
var isDropTargetsMissing = false;
|
|
150
|
-
// Ensure decorations stay in sync when nodes are added or removed from the doc
|
|
151
|
-
var isHandleMissing = !(meta !== null && meta !== void 0 && meta.activeNode) && !decorations.find().some(function (_ref6) {
|
|
152
|
-
var spec = _ref6.spec;
|
|
153
|
-
return spec.id === 'drag-handle';
|
|
154
|
-
});
|
|
155
|
-
var decsLength = (0, _experiments.editorExperiment)('nested-dnd', true) ? decorations.find().filter(function (_ref7) {
|
|
156
|
-
var spec = _ref7.spec;
|
|
150
|
+
var decsLength = isNestedEnabled ? decorations.find(undefined, undefined, function (spec) {
|
|
157
151
|
return spec.type === 'node-decoration';
|
|
158
|
-
}).length : decorations.find().filter(function (
|
|
159
|
-
var spec =
|
|
152
|
+
}).length : decorations.find().filter(function (_ref5) {
|
|
153
|
+
var spec = _ref5.spec;
|
|
160
154
|
return spec.id !== 'drag-handle';
|
|
161
155
|
}).length;
|
|
162
|
-
var
|
|
163
|
-
|
|
156
|
+
var isDecsMissing = false;
|
|
157
|
+
var isDropTargetsMissing = false;
|
|
158
|
+
if (isNestedEnabled) {
|
|
164
159
|
var _meta$isDragging;
|
|
165
|
-
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) &&
|
|
166
|
-
isDropTargetsMissing = ((_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging) &&
|
|
160
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && maybeNodeCountChanged;
|
|
161
|
+
isDropTargetsMissing = ((_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging) && maybeNodeCountChanged && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
167
162
|
} else {
|
|
168
163
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
}).length;
|
|
173
|
-
var _getIntl = getIntl(),
|
|
174
|
-
formatMessage = _getIntl.formatMessage;
|
|
175
|
-
if ((0, _experiments.editorExperiment)('nested-dnd', false)) {
|
|
164
|
+
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
165
|
+
return spec.type === 'drop-target-decoration';
|
|
166
|
+
}).length;
|
|
176
167
|
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
177
168
|
}
|
|
178
169
|
|
|
179
170
|
// This is not targeted enough - it's trying to catch events like expand being set to breakout
|
|
180
|
-
var maybeWidthUpdated = tr.docChanged && oldState.doc.nodeSize === newState.doc.nodeSize && !
|
|
171
|
+
var maybeWidthUpdated = tr.docChanged && oldState.doc.nodeSize === newState.doc.nodeSize && !maybeNodeCountChanged;
|
|
181
172
|
|
|
182
173
|
// This addresses scenarios such as undoing table resizing,
|
|
183
174
|
// where a keyboard shortcut triggers a width change, and
|
|
@@ -186,7 +177,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
186
177
|
// (when the table node rerenders)
|
|
187
178
|
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
188
179
|
var maybeTableWidthUpdated = (meta === null || meta === void 0 ? void 0 : meta.activeNode) && (meta === null || meta === void 0 || (_meta$activeNode = meta.activeNode) === null || _meta$activeNode === void 0 ? void 0 : _meta$activeNode.nodeType) === 'table' && meta.activeNode.anchorName === (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName);
|
|
189
|
-
var redrawDecorations = decorations === _view.DecorationSet.empty || (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== editorHeight || (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== editorWidthLeft || (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== editorWidthRight || maybeWidthUpdated ||
|
|
180
|
+
var redrawDecorations = decorations === _view.DecorationSet.empty || (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== editorHeight || (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== editorWidthLeft || (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== editorWidthRight || maybeWidthUpdated || maybeNodeCountChanged || maybeTableWidthUpdated || resizerMeta === false || isDecsMissing || !!(meta !== null && meta !== void 0 && meta.nodeMoved) && tr.docChanged;
|
|
190
181
|
|
|
191
182
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
192
183
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
@@ -194,7 +185,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
194
185
|
return spec.type !== 'drop-target-decoration';
|
|
195
186
|
});
|
|
196
187
|
decorations = decorations.remove(oldNodeDecs);
|
|
197
|
-
newNodeDecs = (0, _decorations.nodeDecorations)(newState);
|
|
188
|
+
var newNodeDecs = (0, _decorations.nodeDecorations)(newState);
|
|
198
189
|
decorations = decorations.add(newState.doc, (0, _toConsumableArray2.default)(newNodeDecs));
|
|
199
190
|
if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved) && !isDecsMissing) {
|
|
200
191
|
var mappedPosisiton = tr.mapping.map(activeNode.pos);
|
|
@@ -202,13 +193,13 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
202
193
|
|
|
203
194
|
// When a node type changed to be nested inside another node, the position of the active node is off by 1
|
|
204
195
|
// This is a workaround to fix the position of the active node when it is nested
|
|
205
|
-
if (tr.docChanged && !
|
|
196
|
+
if (tr.docChanged && !maybeNodeCountChanged && mappedPosisiton === prevMappedPos + 1) {
|
|
206
197
|
mappedPosisiton = prevMappedPos;
|
|
207
198
|
}
|
|
208
199
|
var _newActiveNode = tr.doc.nodeAt(mappedPosisiton);
|
|
209
200
|
var draghandleDec;
|
|
210
201
|
if (isPerformanceFix) {
|
|
211
|
-
var _meta$activeNode$pos, _meta$activeNode2,
|
|
202
|
+
var _meta$activeNode$pos, _meta$activeNode2, _ref6, _meta$activeNode$anch, _meta$activeNode3, _decAtPos$spec, _ref7, _meta$activeNode$node, _meta$activeNode4, _decAtPos$spec2, _meta$activeNode5;
|
|
212
203
|
if (_newActiveNode && (_newActiveNode === null || _newActiveNode === void 0 ? void 0 : _newActiveNode.type.name) !== activeNode.nodeType) {
|
|
213
204
|
var _oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
214
205
|
return spec.id === 'drag-handle';
|
|
@@ -218,7 +209,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
218
209
|
var decAtPos = newNodeDecs.find(function (dec) {
|
|
219
210
|
return dec.from === mappedPosisiton;
|
|
220
211
|
});
|
|
221
|
-
draghandleDec = (0, _decorations.dragHandleDecoration)(api, getIntl, (_meta$activeNode$pos = meta === null || meta === void 0 || (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.pos) !== null && _meta$activeNode$pos !== void 0 ? _meta$activeNode$pos : mappedPosisiton, (
|
|
212
|
+
draghandleDec = (0, _decorations.dragHandleDecoration)(api, getIntl, (_meta$activeNode$pos = meta === null || meta === void 0 || (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.pos) !== null && _meta$activeNode$pos !== void 0 ? _meta$activeNode$pos : mappedPosisiton, (_ref6 = (_meta$activeNode$anch = meta === null || meta === void 0 || (_meta$activeNode3 = meta.activeNode) === null || _meta$activeNode3 === void 0 ? void 0 : _meta$activeNode3.anchorName) !== null && _meta$activeNode$anch !== void 0 ? _meta$activeNode$anch : decAtPos === null || decAtPos === void 0 || (_decAtPos$spec = decAtPos.spec) === null || _decAtPos$spec === void 0 ? void 0 : _decAtPos$spec.anchorName) !== null && _ref6 !== void 0 ? _ref6 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName, (_ref7 = (_meta$activeNode$node = meta === null || meta === void 0 || (_meta$activeNode4 = meta.activeNode) === null || _meta$activeNode4 === void 0 ? void 0 : _meta$activeNode4.nodeType) !== null && _meta$activeNode$node !== void 0 ? _meta$activeNode$node : decAtPos === null || decAtPos === void 0 || (_decAtPos$spec2 = decAtPos.spec) === null || _decAtPos$spec2 === void 0 ? void 0 : _decAtPos$spec2.nodeType) !== null && _ref7 !== void 0 ? _ref7 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType, meta === null || meta === void 0 || (_meta$activeNode5 = meta.activeNode) === null || _meta$activeNode5 === void 0 ? void 0 : _meta$activeNode5.handleOptions);
|
|
222
213
|
} else {
|
|
223
214
|
var nodeType = activeNode.nodeType;
|
|
224
215
|
var anchorName = activeNode.anchorName;
|
|
@@ -257,18 +248,11 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
257
248
|
decorations = decorations.add(newState.doc, [_decs]);
|
|
258
249
|
}
|
|
259
250
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
} else {
|
|
266
|
-
// Remove drop target decoration when dragging stops
|
|
267
|
-
var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
|
|
268
|
-
return spec.type === 'drop-target-decoration';
|
|
269
|
-
});
|
|
270
|
-
decorations = decorations.remove(dropTargetDecs);
|
|
271
|
-
}
|
|
251
|
+
// Remove drop target decoration when dragging stops
|
|
252
|
+
var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
|
|
253
|
+
return spec.type === 'drop-target-decoration';
|
|
254
|
+
});
|
|
255
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
272
256
|
}
|
|
273
257
|
|
|
274
258
|
// Map active node position when the document changes
|
|
@@ -283,19 +267,22 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
283
267
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
284
268
|
if (shouldCreateDropTargets || (0, _dragTargetDebug.isBlocksDragTargetDebug)()) {
|
|
285
269
|
var _meta$activeNode6;
|
|
286
|
-
var _decs2 = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage,
|
|
270
|
+
var _decs2 = (0, _decorations.dropTargetDecorations)(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode6 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode6 !== void 0 ? _meta$activeNode6 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode);
|
|
287
271
|
decorations = decorations.add(newState.doc, _decs2);
|
|
288
272
|
}
|
|
289
273
|
}
|
|
290
|
-
var isEmptyDoc =
|
|
291
|
-
|
|
292
|
-
var
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
274
|
+
var isEmptyDoc = isNestedEnabled ? newState.doc.childCount === 1 && newState.doc.nodeSize <= 4 && (newState.doc.firstChild === null || newState.doc.firstChild.nodeSize <= 2) : newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
275
|
+
if (isEmptyDoc) {
|
|
276
|
+
var hasNodeDecoration = !!decorations.find(undefined, undefined, function (spec) {
|
|
277
|
+
return spec.type === 'node-decoration';
|
|
278
|
+
}).length;
|
|
279
|
+
if (!hasNodeDecoration) {
|
|
280
|
+
decorations = decorations.add(newState.doc, [(0, _decorations.emptyParagraphNodeDecorations)()]);
|
|
281
|
+
}
|
|
297
282
|
}
|
|
298
|
-
var newActiveNode = isEmptyDoc ||
|
|
283
|
+
var newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && decorations.find(undefined, undefined, function (spec) {
|
|
284
|
+
return spec.id === 'drag-handle';
|
|
285
|
+
}).length === 0 ? null : (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos;
|
|
299
286
|
return {
|
|
300
287
|
decorations: decorations,
|
|
301
288
|
activeNode: newActiveNode,
|
|
@@ -306,8 +293,7 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
306
293
|
editorWidthRight: (_meta$editorWidthRigh = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh !== void 0 ? _meta$editorWidthRigh : currentState.editorWidthRight,
|
|
307
294
|
isResizerResizing: isResizerResizing,
|
|
308
295
|
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
309
|
-
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
310
|
-
childCount: newChildCount
|
|
296
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
311
297
|
};
|
|
312
298
|
}
|
|
313
299
|
},
|
|
@@ -391,8 +377,6 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
391
377
|
}
|
|
392
378
|
}
|
|
393
379
|
if (event.shiftKey && event.ctrlKey && (0, _platformFeatureFlags.fg)('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
394
|
-
var _getIntl2 = getIntl(),
|
|
395
|
-
formatMessage = _getIntl2.formatMessage;
|
|
396
380
|
//prevent holding down key combo from firing repeatedly
|
|
397
381
|
if (!event.repeat && (0, _keymap.boundKeydownHandler)(api, formatMessage)(view, event)) {
|
|
398
382
|
event.preventDefault();
|
|
@@ -85,10 +85,15 @@ const initialState = {
|
|
|
85
85
|
editorWidthRight: 0,
|
|
86
86
|
isResizerResizing: false,
|
|
87
87
|
isDocSizeLimitEnabled: null,
|
|
88
|
-
isPMDragging: false
|
|
89
|
-
childCount: 0
|
|
88
|
+
isPMDragging: false
|
|
90
89
|
};
|
|
91
90
|
export const createPlugin = (api, getIntl) => {
|
|
91
|
+
const {
|
|
92
|
+
formatMessage
|
|
93
|
+
} = getIntl();
|
|
94
|
+
const isNestedEnabled = editorExperiment('nested-dnd', true, {
|
|
95
|
+
exposure: true
|
|
96
|
+
});
|
|
92
97
|
return new SafePlugin({
|
|
93
98
|
key,
|
|
94
99
|
state: {
|
|
@@ -106,65 +111,50 @@ export const createPlugin = (api, getIntl) => {
|
|
|
106
111
|
editorWidthRight,
|
|
107
112
|
isResizerResizing,
|
|
108
113
|
isDragging,
|
|
109
|
-
isPMDragging
|
|
110
|
-
childCount
|
|
114
|
+
isPMDragging
|
|
111
115
|
} = currentState;
|
|
112
116
|
|
|
113
|
-
// Remap existing decorations when
|
|
117
|
+
// Remap existing decorations when steps exist
|
|
114
118
|
if (tr.docChanged) {
|
|
115
119
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
116
120
|
}
|
|
117
121
|
const meta = tr.getMeta(key);
|
|
118
|
-
const isPerformanceFix = editorExperiment('dnd-input-performance-optimisation', true, {
|
|
122
|
+
const isPerformanceFix = isNestedEnabled || editorExperiment('dnd-input-performance-optimisation', true, {
|
|
119
123
|
exposure: true
|
|
120
|
-
})
|
|
124
|
+
});
|
|
121
125
|
let activeNodeWithNewNodeType = null;
|
|
122
|
-
|
|
126
|
+
|
|
123
127
|
// If tables or media are being resized, we want to hide the drag handle
|
|
124
128
|
const resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
125
129
|
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
126
130
|
const canIgnoreTr = () => !tr.steps.every(e => e instanceof AnalyticsStep);
|
|
127
|
-
const
|
|
131
|
+
const maybeNodeCountChanged = isNestedEnabled ? !isTextInput(tr) && tr.docChanged && canIgnoreTr() : oldState.doc.childCount !== newState.doc.childCount;
|
|
128
132
|
const shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
129
133
|
|
|
130
134
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
131
135
|
// Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
|
|
132
136
|
// Don't remove the handle if remote changes are changing the node count, its prosemirror position can be mapped instead
|
|
133
|
-
if (isResizerResizing ||
|
|
134
|
-
const oldHandle = decorations.find()
|
|
135
|
-
spec
|
|
136
|
-
}) => spec.id === 'drag-handle');
|
|
137
|
+
if (isResizerResizing || maybeNodeCountChanged && shouldRemoveHandle || meta !== null && meta !== void 0 && meta.nodeMoved) {
|
|
138
|
+
const oldHandle = decorations.find(undefined, undefined, spec => spec.id === 'drag-handle');
|
|
137
139
|
decorations = decorations.remove(oldHandle);
|
|
138
140
|
}
|
|
139
|
-
|
|
140
|
-
let isDropTargetsMissing = false;
|
|
141
|
-
// Ensure decorations stay in sync when nodes are added or removed from the doc
|
|
142
|
-
const isHandleMissing = !(meta !== null && meta !== void 0 && meta.activeNode) && !decorations.find().some(({
|
|
143
|
-
spec
|
|
144
|
-
}) => spec.id === 'drag-handle');
|
|
145
|
-
const decsLength = editorExperiment('nested-dnd', true) ? decorations.find().filter(({
|
|
146
|
-
spec
|
|
147
|
-
}) => spec.type === 'node-decoration').length : decorations.find().filter(({
|
|
141
|
+
const decsLength = isNestedEnabled ? decorations.find(undefined, undefined, spec => spec.type === 'node-decoration').length : decorations.find().filter(({
|
|
148
142
|
spec
|
|
149
143
|
}) => spec.id !== 'drag-handle').length;
|
|
150
|
-
let
|
|
151
|
-
|
|
144
|
+
let isDecsMissing = false;
|
|
145
|
+
let isDropTargetsMissing = false;
|
|
146
|
+
if (isNestedEnabled) {
|
|
152
147
|
var _meta$isDragging;
|
|
153
|
-
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) &&
|
|
154
|
-
isDropTargetsMissing = ((_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging) &&
|
|
148
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && maybeNodeCountChanged;
|
|
149
|
+
isDropTargetsMissing = ((_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging) && maybeNodeCountChanged && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
155
150
|
} else {
|
|
156
151
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
157
|
-
|
|
158
|
-
const dropTargetLen = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration').length;
|
|
159
|
-
const {
|
|
160
|
-
formatMessage
|
|
161
|
-
} = getIntl();
|
|
162
|
-
if (editorExperiment('nested-dnd', false)) {
|
|
152
|
+
const dropTargetLen = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration').length;
|
|
163
153
|
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
164
154
|
}
|
|
165
155
|
|
|
166
156
|
// This is not targeted enough - it's trying to catch events like expand being set to breakout
|
|
167
|
-
const maybeWidthUpdated = tr.docChanged && oldState.doc.nodeSize === newState.doc.nodeSize && !
|
|
157
|
+
const maybeWidthUpdated = tr.docChanged && oldState.doc.nodeSize === newState.doc.nodeSize && !maybeNodeCountChanged;
|
|
168
158
|
|
|
169
159
|
// This addresses scenarios such as undoing table resizing,
|
|
170
160
|
// where a keyboard shortcut triggers a width change, and
|
|
@@ -173,13 +163,13 @@ export const createPlugin = (api, getIntl) => {
|
|
|
173
163
|
// (when the table node rerenders)
|
|
174
164
|
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
175
165
|
const maybeTableWidthUpdated = (meta === null || meta === void 0 ? void 0 : meta.activeNode) && (meta === null || meta === void 0 ? void 0 : (_meta$activeNode = meta.activeNode) === null || _meta$activeNode === void 0 ? void 0 : _meta$activeNode.nodeType) === 'table' && meta.activeNode.anchorName === (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName);
|
|
176
|
-
const redrawDecorations = decorations === DecorationSet.empty || (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== editorHeight || (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== editorWidthLeft || (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== editorWidthRight || maybeWidthUpdated ||
|
|
166
|
+
const redrawDecorations = decorations === DecorationSet.empty || (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== editorHeight || (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== editorWidthLeft || (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== editorWidthRight || maybeWidthUpdated || maybeNodeCountChanged || maybeTableWidthUpdated || resizerMeta === false || isDecsMissing || !!(meta !== null && meta !== void 0 && meta.nodeMoved) && tr.docChanged;
|
|
177
167
|
|
|
178
168
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
179
169
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
180
170
|
const oldNodeDecs = decorations.find(undefined, undefined, spec => spec.type !== 'drop-target-decoration');
|
|
181
171
|
decorations = decorations.remove(oldNodeDecs);
|
|
182
|
-
newNodeDecs = nodeDecorations(newState);
|
|
172
|
+
const newNodeDecs = nodeDecorations(newState);
|
|
183
173
|
decorations = decorations.add(newState.doc, [...newNodeDecs]);
|
|
184
174
|
if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved) && !isDecsMissing) {
|
|
185
175
|
let mappedPosisiton = tr.mapping.map(activeNode.pos);
|
|
@@ -187,7 +177,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
187
177
|
|
|
188
178
|
// When a node type changed to be nested inside another node, the position of the active node is off by 1
|
|
189
179
|
// This is a workaround to fix the position of the active node when it is nested
|
|
190
|
-
if (tr.docChanged && !
|
|
180
|
+
if (tr.docChanged && !maybeNodeCountChanged && mappedPosisiton === prevMappedPos + 1) {
|
|
191
181
|
mappedPosisiton = prevMappedPos;
|
|
192
182
|
}
|
|
193
183
|
const newActiveNode = tr.doc.nodeAt(mappedPosisiton);
|
|
@@ -234,14 +224,9 @@ export const createPlugin = (api, getIntl) => {
|
|
|
234
224
|
decorations = decorations.add(newState.doc, [decs]);
|
|
235
225
|
}
|
|
236
226
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
} else {
|
|
241
|
-
// Remove drop target decoration when dragging stops
|
|
242
|
-
const dropTargetDecs = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration');
|
|
243
|
-
decorations = decorations.remove(dropTargetDecs);
|
|
244
|
-
}
|
|
227
|
+
// Remove drop target decoration when dragging stops
|
|
228
|
+
const dropTargetDecs = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration');
|
|
229
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
245
230
|
}
|
|
246
231
|
|
|
247
232
|
// Map active node position when the document changes
|
|
@@ -256,18 +241,18 @@ export const createPlugin = (api, getIntl) => {
|
|
|
256
241
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
257
242
|
if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
|
|
258
243
|
var _meta$activeNode6;
|
|
259
|
-
const decs = dropTargetDecorations(newState, api, formatMessage,
|
|
244
|
+
const decs = dropTargetDecorations(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode6 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode6 !== void 0 ? _meta$activeNode6 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode);
|
|
260
245
|
decorations = decorations.add(newState.doc, decs);
|
|
261
246
|
}
|
|
262
247
|
}
|
|
263
|
-
const isEmptyDoc =
|
|
264
|
-
|
|
265
|
-
spec
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
248
|
+
const isEmptyDoc = isNestedEnabled ? newState.doc.childCount === 1 && newState.doc.nodeSize <= 4 && (newState.doc.firstChild === null || newState.doc.firstChild.nodeSize <= 2) : newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
249
|
+
if (isEmptyDoc) {
|
|
250
|
+
const hasNodeDecoration = !!decorations.find(undefined, undefined, spec => spec.type === 'node-decoration').length;
|
|
251
|
+
if (!hasNodeDecoration) {
|
|
252
|
+
decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
|
|
253
|
+
}
|
|
269
254
|
}
|
|
270
|
-
const newActiveNode = isEmptyDoc ||
|
|
255
|
+
const newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && decorations.find(undefined, undefined, spec => spec.id === 'drag-handle').length === 0 ? null : (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos;
|
|
271
256
|
return {
|
|
272
257
|
decorations,
|
|
273
258
|
activeNode: newActiveNode,
|
|
@@ -278,8 +263,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
278
263
|
editorWidthRight: (_meta$editorWidthRigh = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh !== void 0 ? _meta$editorWidthRigh : currentState.editorWidthRight,
|
|
279
264
|
isResizerResizing: isResizerResizing,
|
|
280
265
|
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
281
|
-
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
282
|
-
childCount: newChildCount
|
|
266
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
283
267
|
};
|
|
284
268
|
}
|
|
285
269
|
},
|
|
@@ -368,9 +352,6 @@ export const createPlugin = (api, getIntl) => {
|
|
|
368
352
|
}
|
|
369
353
|
}
|
|
370
354
|
if (event.shiftKey && event.ctrlKey && fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
371
|
-
const {
|
|
372
|
-
formatMessage
|
|
373
|
-
} = getIntl();
|
|
374
355
|
//prevent holding down key combo from firing repeatedly
|
|
375
356
|
if (!event.repeat && boundKeydownHandler(api, formatMessage)(view, event)) {
|
|
376
357
|
event.preventDefault();
|
|
@@ -84,10 +84,14 @@ var initialState = {
|
|
|
84
84
|
editorWidthRight: 0,
|
|
85
85
|
isResizerResizing: false,
|
|
86
86
|
isDocSizeLimitEnabled: null,
|
|
87
|
-
isPMDragging: false
|
|
88
|
-
childCount: 0
|
|
87
|
+
isPMDragging: false
|
|
89
88
|
};
|
|
90
89
|
export var createPlugin = function createPlugin(api, getIntl) {
|
|
90
|
+
var _getIntl = getIntl(),
|
|
91
|
+
formatMessage = _getIntl.formatMessage;
|
|
92
|
+
var isNestedEnabled = editorExperiment('nested-dnd', true, {
|
|
93
|
+
exposure: true
|
|
94
|
+
});
|
|
91
95
|
return new SafePlugin({
|
|
92
96
|
key: key,
|
|
93
97
|
state: {
|
|
@@ -104,19 +108,18 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
104
108
|
editorWidthRight = currentState.editorWidthRight,
|
|
105
109
|
isResizerResizing = currentState.isResizerResizing,
|
|
106
110
|
isDragging = currentState.isDragging,
|
|
107
|
-
isPMDragging = currentState.isPMDragging
|
|
108
|
-
childCount = currentState.childCount;
|
|
111
|
+
isPMDragging = currentState.isPMDragging;
|
|
109
112
|
|
|
110
|
-
// Remap existing decorations when
|
|
113
|
+
// Remap existing decorations when steps exist
|
|
111
114
|
if (tr.docChanged) {
|
|
112
115
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
113
116
|
}
|
|
114
117
|
var meta = tr.getMeta(key);
|
|
115
|
-
var isPerformanceFix = editorExperiment('dnd-input-performance-optimisation', true, {
|
|
118
|
+
var isPerformanceFix = isNestedEnabled || editorExperiment('dnd-input-performance-optimisation', true, {
|
|
116
119
|
exposure: true
|
|
117
|
-
})
|
|
120
|
+
});
|
|
118
121
|
var activeNodeWithNewNodeType = null;
|
|
119
|
-
|
|
122
|
+
|
|
120
123
|
// If tables or media are being resized, we want to hide the drag handle
|
|
121
124
|
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
122
125
|
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
@@ -125,52 +128,40 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
125
128
|
return e instanceof AnalyticsStep;
|
|
126
129
|
});
|
|
127
130
|
};
|
|
128
|
-
var
|
|
131
|
+
var maybeNodeCountChanged = isNestedEnabled ? !isTextInput(tr) && tr.docChanged && canIgnoreTr() : oldState.doc.childCount !== newState.doc.childCount;
|
|
129
132
|
var shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
130
133
|
|
|
131
134
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
132
135
|
// Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
|
|
133
136
|
// Don't remove the handle if remote changes are changing the node count, its prosemirror position can be mapped instead
|
|
134
|
-
if (isResizerResizing ||
|
|
135
|
-
var oldHandle = decorations.find(
|
|
136
|
-
var spec = _ref5.spec;
|
|
137
|
+
if (isResizerResizing || maybeNodeCountChanged && shouldRemoveHandle || meta !== null && meta !== void 0 && meta.nodeMoved) {
|
|
138
|
+
var oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
137
139
|
return spec.id === 'drag-handle';
|
|
138
140
|
});
|
|
139
141
|
decorations = decorations.remove(oldHandle);
|
|
140
142
|
}
|
|
141
|
-
var
|
|
142
|
-
var isDropTargetsMissing = false;
|
|
143
|
-
// Ensure decorations stay in sync when nodes are added or removed from the doc
|
|
144
|
-
var isHandleMissing = !(meta !== null && meta !== void 0 && meta.activeNode) && !decorations.find().some(function (_ref6) {
|
|
145
|
-
var spec = _ref6.spec;
|
|
146
|
-
return spec.id === 'drag-handle';
|
|
147
|
-
});
|
|
148
|
-
var decsLength = editorExperiment('nested-dnd', true) ? decorations.find().filter(function (_ref7) {
|
|
149
|
-
var spec = _ref7.spec;
|
|
143
|
+
var decsLength = isNestedEnabled ? decorations.find(undefined, undefined, function (spec) {
|
|
150
144
|
return spec.type === 'node-decoration';
|
|
151
|
-
}).length : decorations.find().filter(function (
|
|
152
|
-
var spec =
|
|
145
|
+
}).length : decorations.find().filter(function (_ref5) {
|
|
146
|
+
var spec = _ref5.spec;
|
|
153
147
|
return spec.id !== 'drag-handle';
|
|
154
148
|
}).length;
|
|
155
|
-
var
|
|
156
|
-
|
|
149
|
+
var isDecsMissing = false;
|
|
150
|
+
var isDropTargetsMissing = false;
|
|
151
|
+
if (isNestedEnabled) {
|
|
157
152
|
var _meta$isDragging;
|
|
158
|
-
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) &&
|
|
159
|
-
isDropTargetsMissing = ((_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging) &&
|
|
153
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && maybeNodeCountChanged;
|
|
154
|
+
isDropTargetsMissing = ((_meta$isDragging = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging !== void 0 ? _meta$isDragging : isDragging) && maybeNodeCountChanged && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
160
155
|
} else {
|
|
161
156
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}).length;
|
|
166
|
-
var _getIntl = getIntl(),
|
|
167
|
-
formatMessage = _getIntl.formatMessage;
|
|
168
|
-
if (editorExperiment('nested-dnd', false)) {
|
|
157
|
+
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
158
|
+
return spec.type === 'drop-target-decoration';
|
|
159
|
+
}).length;
|
|
169
160
|
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
170
161
|
}
|
|
171
162
|
|
|
172
163
|
// This is not targeted enough - it's trying to catch events like expand being set to breakout
|
|
173
|
-
var maybeWidthUpdated = tr.docChanged && oldState.doc.nodeSize === newState.doc.nodeSize && !
|
|
164
|
+
var maybeWidthUpdated = tr.docChanged && oldState.doc.nodeSize === newState.doc.nodeSize && !maybeNodeCountChanged;
|
|
174
165
|
|
|
175
166
|
// This addresses scenarios such as undoing table resizing,
|
|
176
167
|
// where a keyboard shortcut triggers a width change, and
|
|
@@ -179,7 +170,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
179
170
|
// (when the table node rerenders)
|
|
180
171
|
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
181
172
|
var maybeTableWidthUpdated = (meta === null || meta === void 0 ? void 0 : meta.activeNode) && (meta === null || meta === void 0 || (_meta$activeNode = meta.activeNode) === null || _meta$activeNode === void 0 ? void 0 : _meta$activeNode.nodeType) === 'table' && meta.activeNode.anchorName === (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName);
|
|
182
|
-
var redrawDecorations = decorations === DecorationSet.empty || (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== editorHeight || (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== editorWidthLeft || (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== editorWidthRight || maybeWidthUpdated ||
|
|
173
|
+
var redrawDecorations = decorations === DecorationSet.empty || (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== editorHeight || (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== editorWidthLeft || (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== undefined && (meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== editorWidthRight || maybeWidthUpdated || maybeNodeCountChanged || maybeTableWidthUpdated || resizerMeta === false || isDecsMissing || !!(meta !== null && meta !== void 0 && meta.nodeMoved) && tr.docChanged;
|
|
183
174
|
|
|
184
175
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
185
176
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
@@ -187,7 +178,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
187
178
|
return spec.type !== 'drop-target-decoration';
|
|
188
179
|
});
|
|
189
180
|
decorations = decorations.remove(oldNodeDecs);
|
|
190
|
-
newNodeDecs = nodeDecorations(newState);
|
|
181
|
+
var newNodeDecs = nodeDecorations(newState);
|
|
191
182
|
decorations = decorations.add(newState.doc, _toConsumableArray(newNodeDecs));
|
|
192
183
|
if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved) && !isDecsMissing) {
|
|
193
184
|
var mappedPosisiton = tr.mapping.map(activeNode.pos);
|
|
@@ -195,13 +186,13 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
195
186
|
|
|
196
187
|
// When a node type changed to be nested inside another node, the position of the active node is off by 1
|
|
197
188
|
// This is a workaround to fix the position of the active node when it is nested
|
|
198
|
-
if (tr.docChanged && !
|
|
189
|
+
if (tr.docChanged && !maybeNodeCountChanged && mappedPosisiton === prevMappedPos + 1) {
|
|
199
190
|
mappedPosisiton = prevMappedPos;
|
|
200
191
|
}
|
|
201
192
|
var _newActiveNode = tr.doc.nodeAt(mappedPosisiton);
|
|
202
193
|
var draghandleDec;
|
|
203
194
|
if (isPerformanceFix) {
|
|
204
|
-
var _meta$activeNode$pos, _meta$activeNode2,
|
|
195
|
+
var _meta$activeNode$pos, _meta$activeNode2, _ref6, _meta$activeNode$anch, _meta$activeNode3, _decAtPos$spec, _ref7, _meta$activeNode$node, _meta$activeNode4, _decAtPos$spec2, _meta$activeNode5;
|
|
205
196
|
if (_newActiveNode && (_newActiveNode === null || _newActiveNode === void 0 ? void 0 : _newActiveNode.type.name) !== activeNode.nodeType) {
|
|
206
197
|
var _oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
207
198
|
return spec.id === 'drag-handle';
|
|
@@ -211,7 +202,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
211
202
|
var decAtPos = newNodeDecs.find(function (dec) {
|
|
212
203
|
return dec.from === mappedPosisiton;
|
|
213
204
|
});
|
|
214
|
-
draghandleDec = dragHandleDecoration(api, getIntl, (_meta$activeNode$pos = meta === null || meta === void 0 || (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.pos) !== null && _meta$activeNode$pos !== void 0 ? _meta$activeNode$pos : mappedPosisiton, (
|
|
205
|
+
draghandleDec = dragHandleDecoration(api, getIntl, (_meta$activeNode$pos = meta === null || meta === void 0 || (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.pos) !== null && _meta$activeNode$pos !== void 0 ? _meta$activeNode$pos : mappedPosisiton, (_ref6 = (_meta$activeNode$anch = meta === null || meta === void 0 || (_meta$activeNode3 = meta.activeNode) === null || _meta$activeNode3 === void 0 ? void 0 : _meta$activeNode3.anchorName) !== null && _meta$activeNode$anch !== void 0 ? _meta$activeNode$anch : decAtPos === null || decAtPos === void 0 || (_decAtPos$spec = decAtPos.spec) === null || _decAtPos$spec === void 0 ? void 0 : _decAtPos$spec.anchorName) !== null && _ref6 !== void 0 ? _ref6 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName, (_ref7 = (_meta$activeNode$node = meta === null || meta === void 0 || (_meta$activeNode4 = meta.activeNode) === null || _meta$activeNode4 === void 0 ? void 0 : _meta$activeNode4.nodeType) !== null && _meta$activeNode$node !== void 0 ? _meta$activeNode$node : decAtPos === null || decAtPos === void 0 || (_decAtPos$spec2 = decAtPos.spec) === null || _decAtPos$spec2 === void 0 ? void 0 : _decAtPos$spec2.nodeType) !== null && _ref7 !== void 0 ? _ref7 : activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType, meta === null || meta === void 0 || (_meta$activeNode5 = meta.activeNode) === null || _meta$activeNode5 === void 0 ? void 0 : _meta$activeNode5.handleOptions);
|
|
215
206
|
} else {
|
|
216
207
|
var nodeType = activeNode.nodeType;
|
|
217
208
|
var anchorName = activeNode.anchorName;
|
|
@@ -250,18 +241,11 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
250
241
|
decorations = decorations.add(newState.doc, [_decs]);
|
|
251
242
|
}
|
|
252
243
|
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
} else {
|
|
259
|
-
// Remove drop target decoration when dragging stops
|
|
260
|
-
var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
|
|
261
|
-
return spec.type === 'drop-target-decoration';
|
|
262
|
-
});
|
|
263
|
-
decorations = decorations.remove(dropTargetDecs);
|
|
264
|
-
}
|
|
244
|
+
// Remove drop target decoration when dragging stops
|
|
245
|
+
var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
|
|
246
|
+
return spec.type === 'drop-target-decoration';
|
|
247
|
+
});
|
|
248
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
265
249
|
}
|
|
266
250
|
|
|
267
251
|
// Map active node position when the document changes
|
|
@@ -276,19 +260,22 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
276
260
|
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
277
261
|
if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
|
|
278
262
|
var _meta$activeNode6;
|
|
279
|
-
var _decs2 = dropTargetDecorations(newState, api, formatMessage,
|
|
263
|
+
var _decs2 = dropTargetDecorations(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode6 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode6 !== void 0 ? _meta$activeNode6 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode);
|
|
280
264
|
decorations = decorations.add(newState.doc, _decs2);
|
|
281
265
|
}
|
|
282
266
|
}
|
|
283
|
-
var isEmptyDoc =
|
|
284
|
-
|
|
285
|
-
var
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
267
|
+
var isEmptyDoc = isNestedEnabled ? newState.doc.childCount === 1 && newState.doc.nodeSize <= 4 && (newState.doc.firstChild === null || newState.doc.firstChild.nodeSize <= 2) : newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
268
|
+
if (isEmptyDoc) {
|
|
269
|
+
var hasNodeDecoration = !!decorations.find(undefined, undefined, function (spec) {
|
|
270
|
+
return spec.type === 'node-decoration';
|
|
271
|
+
}).length;
|
|
272
|
+
if (!hasNodeDecoration) {
|
|
273
|
+
decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
|
|
274
|
+
}
|
|
290
275
|
}
|
|
291
|
-
var newActiveNode = isEmptyDoc ||
|
|
276
|
+
var newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && decorations.find(undefined, undefined, function (spec) {
|
|
277
|
+
return spec.id === 'drag-handle';
|
|
278
|
+
}).length === 0 ? null : (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos;
|
|
292
279
|
return {
|
|
293
280
|
decorations: decorations,
|
|
294
281
|
activeNode: newActiveNode,
|
|
@@ -299,8 +286,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
299
286
|
editorWidthRight: (_meta$editorWidthRigh = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh !== void 0 ? _meta$editorWidthRigh : currentState.editorWidthRight,
|
|
300
287
|
isResizerResizing: isResizerResizing,
|
|
301
288
|
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
302
|
-
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
303
|
-
childCount: newChildCount
|
|
289
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
304
290
|
};
|
|
305
291
|
}
|
|
306
292
|
},
|
|
@@ -384,8 +370,6 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
384
370
|
}
|
|
385
371
|
}
|
|
386
372
|
if (event.shiftKey && event.ctrlKey && fg('platform_editor_element_drag_and_drop_ed_23873')) {
|
|
387
|
-
var _getIntl2 = getIntl(),
|
|
388
|
-
formatMessage = _getIntl2.formatMessage;
|
|
389
373
|
//prevent holding down key combo from firing repeatedly
|
|
390
374
|
if (!event.repeat && boundKeydownHandler(api, formatMessage)(view, event)) {
|
|
391
375
|
event.preventDefault();
|
package/dist/types/types.d.ts
CHANGED
|
@@ -32,7 +32,6 @@ export interface PluginState {
|
|
|
32
32
|
* is dragging the node without using drag handle, i,e, native prosemirror DnD
|
|
33
33
|
*/
|
|
34
34
|
isPMDragging: boolean;
|
|
35
|
-
childCount: number;
|
|
36
35
|
}
|
|
37
36
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
38
37
|
export type BlockControlsSharedState = {
|
|
@@ -32,7 +32,6 @@ export interface PluginState {
|
|
|
32
32
|
* is dragging the node without using drag handle, i,e, native prosemirror DnD
|
|
33
33
|
*/
|
|
34
34
|
isPMDragging: boolean;
|
|
35
|
-
childCount: number;
|
|
36
35
|
}
|
|
37
36
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
38
37
|
export type BlockControlsSharedState = {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3",
|
|
4
4
|
"description": "Block controls plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@atlaskit/adf-schema": "^40.9.0",
|
|
34
|
-
"@atlaskit/editor-common": "^
|
|
34
|
+
"@atlaskit/editor-common": "^91.0.0",
|
|
35
35
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
|
|
36
36
|
"@atlaskit/editor-plugin-analytics": "^1.8.0",
|
|
37
37
|
"@atlaskit/editor-plugin-editor-disabled": "^1.3.0",
|