@atlaskit/editor-plugin-block-controls 2.5.0 → 2.6.0
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 +21 -0
- package/dist/cjs/commands/move-node.js +7 -6
- package/dist/cjs/commands/show-drag-handle.js +2 -1
- package/dist/cjs/pm-plugins/decorations.js +93 -32
- package/dist/cjs/pm-plugins/keymap.js +5 -2
- package/dist/cjs/pm-plugins/main.js +349 -203
- package/dist/cjs/ui/drag-handle.js +4 -6
- package/dist/cjs/ui/drop-target-v2.js +32 -6
- package/dist/cjs/ui/global-styles.js +1 -7
- package/dist/cjs/utils/transactions.js +63 -0
- package/dist/es2019/commands/move-node.js +7 -6
- package/dist/es2019/commands/show-drag-handle.js +2 -1
- package/dist/es2019/pm-plugins/decorations.js +86 -31
- package/dist/es2019/pm-plugins/keymap.js +5 -2
- package/dist/es2019/pm-plugins/main.js +332 -179
- package/dist/es2019/ui/drag-handle.js +4 -8
- package/dist/es2019/ui/drop-target-v2.js +32 -6
- package/dist/es2019/ui/global-styles.js +1 -7
- package/dist/es2019/utils/transactions.js +57 -0
- package/dist/esm/commands/move-node.js +7 -6
- package/dist/esm/commands/show-drag-handle.js +2 -1
- package/dist/esm/pm-plugins/decorations.js +92 -31
- package/dist/esm/pm-plugins/keymap.js +5 -2
- package/dist/esm/pm-plugins/main.js +350 -204
- package/dist/esm/ui/drag-handle.js +4 -6
- package/dist/esm/ui/drop-target-v2.js +32 -6
- package/dist/esm/ui/global-styles.js +1 -7
- package/dist/esm/utils/transactions.js +57 -0
- package/dist/types/pm-plugins/decorations.d.ts +24 -4
- package/dist/types/pm-plugins/main.d.ts +32 -0
- package/dist/types/ui/drag-handle.d.ts +5 -14
- package/dist/types/ui/drop-target-v2.d.ts +1 -1
- package/dist/types/ui/drop-target.d.ts +2 -0
- package/dist/types/utils/transactions.d.ts +29 -0
- package/dist/types-ts4.5/pm-plugins/decorations.d.ts +24 -4
- package/dist/types-ts4.5/pm-plugins/main.d.ts +32 -0
- package/dist/types-ts4.5/ui/drag-handle.d.ts +5 -14
- package/dist/types-ts4.5/ui/drop-target-v2.d.ts +1 -1
- package/dist/types-ts4.5/ui/drop-target.d.ts +2 -0
- package/dist/types-ts4.5/utils/transactions.d.ts +29 -0
- package/package.json +4 -7
|
@@ -4,7 +4,7 @@ import { AnalyticsStep } from '@atlaskit/adf-schema/steps';
|
|
|
4
4
|
import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE } from '@atlaskit/editor-common/analytics';
|
|
5
5
|
import { browser } from '@atlaskit/editor-common/browser';
|
|
6
6
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
7
|
-
import { isTextInput } from '@atlaskit/editor-common/utils';
|
|
7
|
+
import { isEmptyDocument, isTextInput } from '@atlaskit/editor-common/utils';
|
|
8
8
|
import { NodeSelection, PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
9
9
|
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
10
10
|
import { fg } from '@atlaskit/platform-feature-flags';
|
|
@@ -14,7 +14,8 @@ import { monitorForElements } from '@atlaskit/pragmatic-drag-and-drop/element/ad
|
|
|
14
14
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
15
15
|
import { AnchorHeightsCache, isAnchorSupported } from '../utils/anchor-utils';
|
|
16
16
|
import { isBlocksDragTargetDebug } from '../utils/drag-target-debug';
|
|
17
|
-
import {
|
|
17
|
+
import { getTrMetadata } from '../utils/transactions';
|
|
18
|
+
import { dragHandleDecoration, dropTargetDecorations, emptyParagraphNodeDecorations, findDropTargetDecs, findHandleDec, findNodeDecs, nodeDecorations } from './decorations';
|
|
18
19
|
import { handleMouseOver } from './handle-mouse-over';
|
|
19
20
|
import { boundKeydownHandler } from './keymap';
|
|
20
21
|
export var key = new PluginKey('blockControls');
|
|
@@ -87,12 +88,346 @@ var initialState = {
|
|
|
87
88
|
isDocSizeLimitEnabled: null,
|
|
88
89
|
isPMDragging: false
|
|
89
90
|
};
|
|
91
|
+
export var newApply = function newApply(api, formatMessage, tr, currentState, newState, flags, anchorHeightsCache) {
|
|
92
|
+
var _meta$activeNode, _activeNode, _activeNode2, _meta$activeNode$hand, _meta$isDragging, _meta$isDragging2, _meta$editorHeight, _meta$editorWidthLeft, _meta$editorWidthRigh, _meta$isPMDragging;
|
|
93
|
+
var isTitleEnterImprovementEnabled = flags.isTitleEnterImprovementEnabled;
|
|
94
|
+
var activeNode = currentState.activeNode,
|
|
95
|
+
decorations = currentState.decorations,
|
|
96
|
+
editorHeight = currentState.editorHeight,
|
|
97
|
+
editorWidthLeft = currentState.editorWidthLeft,
|
|
98
|
+
editorWidthRight = currentState.editorWidthRight,
|
|
99
|
+
isDragging = currentState.isDragging,
|
|
100
|
+
isMenuOpen = currentState.isMenuOpen,
|
|
101
|
+
isPMDragging = currentState.isPMDragging,
|
|
102
|
+
isResizerResizing = currentState.isResizerResizing;
|
|
103
|
+
var isActiveNodeDeleted = false;
|
|
104
|
+
|
|
105
|
+
// Remap existing decorations and activeNode when steps exist
|
|
106
|
+
if (tr.docChanged) {
|
|
107
|
+
decorations = decorations.map(tr.mapping, tr.doc);
|
|
108
|
+
if (activeNode) {
|
|
109
|
+
var mappedPos = tr.mapping.mapResult(activeNode.pos);
|
|
110
|
+
isActiveNodeDeleted = mappedPos.deleted;
|
|
111
|
+
activeNode = {
|
|
112
|
+
pos: mappedPos.pos,
|
|
113
|
+
anchorName: activeNode.anchorName,
|
|
114
|
+
nodeType: activeNode.nodeType
|
|
115
|
+
};
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
var meta = tr.getMeta(key);
|
|
119
|
+
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
120
|
+
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
121
|
+
var _getTrMetadata = getTrMetadata(tr),
|
|
122
|
+
from = _getTrMetadata.from,
|
|
123
|
+
to = _getTrMetadata.to,
|
|
124
|
+
numReplaceSteps = _getTrMetadata.numReplaceSteps,
|
|
125
|
+
isAllText = _getTrMetadata.isAllText;
|
|
126
|
+
var maybeNodeCountChanged = !isAllText && numReplaceSteps > 0;
|
|
127
|
+
var latestActiveNode = (_meta$activeNode = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode !== void 0 ? _meta$activeNode : activeNode;
|
|
128
|
+
|
|
129
|
+
// Re-create node decorations
|
|
130
|
+
var isDecSetEmpty = decorations === DecorationSet.empty;
|
|
131
|
+
var isNodeDecsMissing = isDecSetEmpty || maybeNodeCountChanged;
|
|
132
|
+
var shouldRedrawNodeDecs = !isResizerResizing && isNodeDecsMissing;
|
|
133
|
+
var isActiveNodeModified = false;
|
|
134
|
+
if (api && shouldRedrawNodeDecs) {
|
|
135
|
+
var oldNodeDecs = findNodeDecs(decorations, from, to);
|
|
136
|
+
decorations = decorations.remove(oldNodeDecs);
|
|
137
|
+
var newNodeDecs = nodeDecorations(newState, isDecSetEmpty ? undefined : from, isDecSetEmpty ? undefined : to);
|
|
138
|
+
decorations = decorations.add(newState.doc, newNodeDecs);
|
|
139
|
+
if (latestActiveNode && !isActiveNodeDeleted) {
|
|
140
|
+
// Find the newly minted node decs that touch the active node
|
|
141
|
+
var findNewNodeDecs = findNodeDecs(decorations, latestActiveNode.pos - 1, to);
|
|
142
|
+
|
|
143
|
+
// Find the specific dec that the active node corresponds to
|
|
144
|
+
var nodeDecsAtActivePos = findNewNodeDecs.filter(function (dec) {
|
|
145
|
+
return (dec === null || dec === void 0 ? void 0 : dec.from) === latestActiveNode.pos;
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
// If multiple decorations at the active node pos, we want the last one
|
|
149
|
+
var nodeDecAtActivePos = nodeDecsAtActivePos.pop();
|
|
150
|
+
|
|
151
|
+
// Update the active node anchor-name and type for accurate positioning
|
|
152
|
+
if (nodeDecAtActivePos) {
|
|
153
|
+
isActiveNodeModified = true;
|
|
154
|
+
latestActiveNode.anchorName = nodeDecAtActivePos.spec.anchorName;
|
|
155
|
+
latestActiveNode.nodeType = nodeDecAtActivePos.spec.nodeType;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
// Check if editor dimensions have changed
|
|
161
|
+
var editorSizeChanged = (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;
|
|
162
|
+
|
|
163
|
+
// Check if there's a new active node, and it differs from the last
|
|
164
|
+
var activeNodeChanged = (meta === null || meta === void 0 ? void 0 : meta.activeNode) && ((meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== ((_activeNode = activeNode) === null || _activeNode === void 0 ? void 0 : _activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== ((_activeNode2 = activeNode) === null || _activeNode2 === void 0 ? void 0 : _activeNode2.anchorName) || (meta === null || meta === void 0 || (_meta$activeNode$hand = meta.activeNode.handleOptions) === null || _meta$activeNode$hand === void 0 ? void 0 : _meta$activeNode$hand.isFocused));
|
|
165
|
+
|
|
166
|
+
// Some browsers don't support anchor positioning, meaning we need to replace the handle when nodes change
|
|
167
|
+
var handleNeedsRedraw = shouldRedrawNodeDecs && !isAnchorSupported();
|
|
168
|
+
|
|
169
|
+
// Create/recreate handle dec when the active node is missing/changes, or the editor viewport has changed (non-anchor pos workaround)
|
|
170
|
+
var shouldRecreateHandle = latestActiveNode && (activeNodeChanged || isActiveNodeModified || editorSizeChanged || handleNeedsRedraw);
|
|
171
|
+
|
|
172
|
+
// Remove handle dec when explicitly hidden, a node is resizing, activeNode pos was deleted, or DnD moved a node
|
|
173
|
+
var shouldRemoveHandle = latestActiveNode && ((meta === null || meta === void 0 ? void 0 : meta.hideDragHandle) && isTitleEnterImprovementEnabled || isResizerResizing || isActiveNodeDeleted || (meta === null || meta === void 0 ? void 0 : meta.nodeMoved));
|
|
174
|
+
if (shouldRemoveHandle) {
|
|
175
|
+
var _activeNode3, _activeNode4;
|
|
176
|
+
var oldHandle = findHandleDec(decorations, (_activeNode3 = activeNode) === null || _activeNode3 === void 0 ? void 0 : _activeNode3.pos, (_activeNode4 = activeNode) === null || _activeNode4 === void 0 ? void 0 : _activeNode4.pos);
|
|
177
|
+
decorations = decorations.remove(oldHandle);
|
|
178
|
+
} else if (api && shouldRecreateHandle) {
|
|
179
|
+
var _activeNode5, _activeNode6;
|
|
180
|
+
var _oldHandle = findHandleDec(decorations, (_activeNode5 = activeNode) === null || _activeNode5 === void 0 ? void 0 : _activeNode5.pos, (_activeNode6 = activeNode) === null || _activeNode6 === void 0 ? void 0 : _activeNode6.pos);
|
|
181
|
+
decorations = decorations.remove(_oldHandle);
|
|
182
|
+
var handleDec = dragHandleDecoration(api, formatMessage, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.anchorName, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.nodeType, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.handleOptions);
|
|
183
|
+
decorations = decorations.add(newState.doc, [handleDec]);
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// Drop targets may be missing when the node count is being changed during a drag
|
|
187
|
+
var 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);
|
|
188
|
+
|
|
189
|
+
// Remove drop target decorations when dragging stops or they need to be redrawn
|
|
190
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
191
|
+
var dropTargetDecs = findDropTargetDecs(decorations);
|
|
192
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// Add drop targets when dragging starts or some are missing
|
|
196
|
+
if (api) {
|
|
197
|
+
if (meta !== null && meta !== void 0 && meta.isDragging || isDropTargetsMissing || isBlocksDragTargetDebug()) {
|
|
198
|
+
var decs = dropTargetDecorations(newState, api, formatMessage, latestActiveNode, anchorHeightsCache);
|
|
199
|
+
decorations = decorations.add(newState.doc, decs);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
var isEmptyDoc = isEmptyDocument(newState.doc);
|
|
203
|
+
if (isEmptyDoc) {
|
|
204
|
+
var hasNodeDecoration = !!findNodeDecs(decorations).length;
|
|
205
|
+
if (!hasNodeDecoration) {
|
|
206
|
+
decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
var newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && findHandleDec(decorations, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos, latestActiveNode === null || latestActiveNode === void 0 ? void 0 : latestActiveNode.pos).length === 0 ? null : latestActiveNode;
|
|
210
|
+
return {
|
|
211
|
+
decorations: decorations,
|
|
212
|
+
activeNode: newActiveNode,
|
|
213
|
+
isDragging: (_meta$isDragging2 = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging2 !== void 0 ? _meta$isDragging2 : isDragging,
|
|
214
|
+
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
215
|
+
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : editorHeight,
|
|
216
|
+
editorWidthLeft: (_meta$editorWidthLeft = meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== null && _meta$editorWidthLeft !== void 0 ? _meta$editorWidthLeft : editorWidthLeft,
|
|
217
|
+
editorWidthRight: (_meta$editorWidthRigh = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh !== void 0 ? _meta$editorWidthRigh : editorWidthRight,
|
|
218
|
+
isResizerResizing: isResizerResizing,
|
|
219
|
+
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
220
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
221
|
+
};
|
|
222
|
+
};
|
|
223
|
+
export var oldApply = function oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorHeightsCache) {
|
|
224
|
+
var _meta$activeNode2, _meta$activeNode$hand2, _activeNodeWithNewNod, _meta$activeNode8, _meta$isDragging4, _meta$editorHeight2, _meta$editorWidthLeft2, _meta$editorWidthRigh2, _meta$isPMDragging2;
|
|
225
|
+
var isNestedEnabled = flags.isNestedEnabled,
|
|
226
|
+
isTitleEnterImprovementEnabled = flags.isTitleEnterImprovementEnabled;
|
|
227
|
+
var activeNode = currentState.activeNode,
|
|
228
|
+
decorations = currentState.decorations,
|
|
229
|
+
isMenuOpen = currentState.isMenuOpen,
|
|
230
|
+
editorHeight = currentState.editorHeight,
|
|
231
|
+
editorWidthLeft = currentState.editorWidthLeft,
|
|
232
|
+
editorWidthRight = currentState.editorWidthRight,
|
|
233
|
+
isResizerResizing = currentState.isResizerResizing,
|
|
234
|
+
isDragging = currentState.isDragging,
|
|
235
|
+
isPMDragging = currentState.isPMDragging;
|
|
236
|
+
|
|
237
|
+
// Remap existing decorations when steps exist
|
|
238
|
+
if (tr.docChanged) {
|
|
239
|
+
decorations = decorations.map(tr.mapping, tr.doc);
|
|
240
|
+
}
|
|
241
|
+
var meta = tr.getMeta(key);
|
|
242
|
+
var isPerformanceFix = isNestedEnabled || editorExperiment('dnd-input-performance-optimisation', true, {
|
|
243
|
+
exposure: true
|
|
244
|
+
});
|
|
245
|
+
var activeNodeWithNewNodeType = null;
|
|
246
|
+
|
|
247
|
+
// If tables or media are being resized, we want to hide the drag handle
|
|
248
|
+
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
249
|
+
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
250
|
+
var canIgnoreTr = function canIgnoreTr() {
|
|
251
|
+
return !tr.steps.every(function (e) {
|
|
252
|
+
return e instanceof AnalyticsStep;
|
|
253
|
+
});
|
|
254
|
+
};
|
|
255
|
+
var maybeNodeCountChanged = isNestedEnabled ? !isTextInput(tr) && tr.docChanged && canIgnoreTr() : oldState.doc.childCount !== newState.doc.childCount;
|
|
256
|
+
var shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
257
|
+
|
|
258
|
+
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
259
|
+
// Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
|
|
260
|
+
// Don't remove the handle if remote changes are changing the node count, its prosemirror position can be mapped instead
|
|
261
|
+
if (meta !== null && meta !== void 0 && meta.hideDragHandle && isTitleEnterImprovementEnabled || isResizerResizing || maybeNodeCountChanged && shouldRemoveHandle || meta !== null && meta !== void 0 && meta.nodeMoved) {
|
|
262
|
+
var oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
263
|
+
return spec.type === 'drag-handle';
|
|
264
|
+
});
|
|
265
|
+
decorations = decorations.remove(oldHandle);
|
|
266
|
+
}
|
|
267
|
+
var decsLength = isNestedEnabled ? decorations.find(undefined, undefined, function (spec) {
|
|
268
|
+
return spec.type === 'node-decoration';
|
|
269
|
+
}).length : decorations.find().filter(function (_ref5) {
|
|
270
|
+
var spec = _ref5.spec;
|
|
271
|
+
return spec.type !== 'drag-handle';
|
|
272
|
+
}).length;
|
|
273
|
+
var isDecsMissing = false;
|
|
274
|
+
var isDropTargetsMissing = false;
|
|
275
|
+
if (isNestedEnabled) {
|
|
276
|
+
var _meta$isDragging3;
|
|
277
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && maybeNodeCountChanged;
|
|
278
|
+
isDropTargetsMissing = ((_meta$isDragging3 = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging3 !== void 0 ? _meta$isDragging3 : isDragging) && maybeNodeCountChanged && !(meta !== null && meta !== void 0 && meta.nodeMoved);
|
|
279
|
+
} else {
|
|
280
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
281
|
+
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
282
|
+
return spec.type === 'drop-target-decoration';
|
|
283
|
+
}).length;
|
|
284
|
+
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
// This is not targeted enough - it's trying to catch events like expand being set to breakout
|
|
288
|
+
var maybeWidthUpdated = tr.docChanged && oldState.doc.nodeSize === newState.doc.nodeSize && !maybeNodeCountChanged;
|
|
289
|
+
|
|
290
|
+
// This addresses scenarios such as undoing table resizing,
|
|
291
|
+
// where a keyboard shortcut triggers a width change, and
|
|
292
|
+
// the node's actual width is then updated in a separate renderering cycle.
|
|
293
|
+
// The tr.meta.activeNode is triggered by the showDragHandleAt function during the mouse entry event
|
|
294
|
+
// (when the table node rerenders)
|
|
295
|
+
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
296
|
+
var maybeTableWidthUpdated = (meta === null || meta === void 0 ? void 0 : meta.activeNode) && (meta === null || meta === void 0 || (_meta$activeNode2 = meta.activeNode) === null || _meta$activeNode2 === void 0 ? void 0 : _meta$activeNode2.nodeType) === 'table' && meta.activeNode.anchorName === (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName);
|
|
297
|
+
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;
|
|
298
|
+
|
|
299
|
+
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
300
|
+
if (redrawDecorations && !isResizerResizing && api) {
|
|
301
|
+
var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
|
|
302
|
+
return spec.type !== 'drop-target-decoration';
|
|
303
|
+
});
|
|
304
|
+
decorations = decorations.remove(oldNodeDecs);
|
|
305
|
+
var newNodeDecs = nodeDecorations(newState);
|
|
306
|
+
decorations = decorations.add(newState.doc, _toConsumableArray(newNodeDecs));
|
|
307
|
+
if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved) && !isDecsMissing) {
|
|
308
|
+
var mappedPosisiton = tr.mapping.map(activeNode.pos);
|
|
309
|
+
var prevMappedPos = oldState.tr.mapping.map(activeNode.pos);
|
|
310
|
+
|
|
311
|
+
// When a node type changed to be nested inside another node, the position of the active node is off by 1
|
|
312
|
+
// This is a workaround to fix the position of the active node when it is nested
|
|
313
|
+
if (tr.docChanged && !maybeNodeCountChanged && mappedPosisiton === prevMappedPos + 1) {
|
|
314
|
+
mappedPosisiton = prevMappedPos;
|
|
315
|
+
}
|
|
316
|
+
var _newActiveNode = tr.doc.nodeAt(mappedPosisiton);
|
|
317
|
+
var draghandleDec;
|
|
318
|
+
if (isPerformanceFix) {
|
|
319
|
+
var _meta$activeNode$pos, _meta$activeNode3, _ref6, _meta$activeNode$anch, _meta$activeNode4, _decAtPos$spec, _ref7, _meta$activeNode$node, _meta$activeNode5, _decAtPos$spec2, _meta$activeNode6;
|
|
320
|
+
if (_newActiveNode && (_newActiveNode === null || _newActiveNode === void 0 ? void 0 : _newActiveNode.type.name) !== activeNode.nodeType) {
|
|
321
|
+
var _oldHandle2 = decorations.find(undefined, undefined, function (spec) {
|
|
322
|
+
return spec.type === 'drag-handle';
|
|
323
|
+
});
|
|
324
|
+
decorations = decorations.remove(_oldHandle2);
|
|
325
|
+
}
|
|
326
|
+
var decAtPos = newNodeDecs.find(function (dec) {
|
|
327
|
+
return dec.from === mappedPosisiton;
|
|
328
|
+
});
|
|
329
|
+
draghandleDec = dragHandleDecoration(api, formatMessage, (_meta$activeNode$pos = meta === null || meta === void 0 || (_meta$activeNode3 = meta.activeNode) === null || _meta$activeNode3 === void 0 ? void 0 : _meta$activeNode3.pos) !== null && _meta$activeNode$pos !== void 0 ? _meta$activeNode$pos : mappedPosisiton, (_ref6 = (_meta$activeNode$anch = meta === null || meta === void 0 || (_meta$activeNode4 = meta.activeNode) === null || _meta$activeNode4 === void 0 ? void 0 : _meta$activeNode4.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$activeNode5 = meta.activeNode) === null || _meta$activeNode5 === void 0 ? void 0 : _meta$activeNode5.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$activeNode6 = meta.activeNode) === null || _meta$activeNode6 === void 0 ? void 0 : _meta$activeNode6.handleOptions);
|
|
330
|
+
} else {
|
|
331
|
+
var nodeType = activeNode.nodeType;
|
|
332
|
+
var anchorName = activeNode.anchorName;
|
|
333
|
+
if (_newActiveNode && (_newActiveNode === null || _newActiveNode === void 0 ? void 0 : _newActiveNode.type.name) !== activeNode.nodeType) {
|
|
334
|
+
nodeType = _newActiveNode.type.name;
|
|
335
|
+
anchorName = activeNode.anchorName.replace(activeNode.nodeType, nodeType);
|
|
336
|
+
activeNodeWithNewNodeType = {
|
|
337
|
+
pos: prevMappedPos,
|
|
338
|
+
nodeType: nodeType,
|
|
339
|
+
anchorName: anchorName
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
draghandleDec = dragHandleDecoration(api, formatMessage, activeNode.pos, anchorName, nodeType);
|
|
343
|
+
}
|
|
344
|
+
decorations = decorations.add(newState.doc, [draghandleDec]);
|
|
345
|
+
}
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
// Remove previous drag handle widget and draw new drag handle widget when activeNode changes
|
|
349
|
+
if (api && meta !== null && meta !== void 0 && meta.activeNode && ((meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) || meta !== null && meta !== void 0 && (_meta$activeNode$hand2 = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand2 !== void 0 && _meta$activeNode$hand2.isFocused)) {
|
|
350
|
+
var _oldHandle3 = decorations.find(undefined, undefined, function (spec) {
|
|
351
|
+
return spec.type === 'drag-handle';
|
|
352
|
+
});
|
|
353
|
+
decorations = decorations.remove(_oldHandle3);
|
|
354
|
+
var decs = dragHandleDecoration(api, formatMessage, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
|
|
355
|
+
decorations = decorations.add(newState.doc, [decs]);
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
// Remove previous drag handle widget and draw new drag handle widget when node type changes
|
|
359
|
+
if (!isPerformanceFix && activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
|
|
360
|
+
var _oldHandle4 = decorations.find(undefined, undefined, function (spec) {
|
|
361
|
+
return spec.type === 'drag-handle';
|
|
362
|
+
});
|
|
363
|
+
decorations = decorations.remove(_oldHandle4);
|
|
364
|
+
var _decs = dragHandleDecoration(api, formatMessage, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
|
|
365
|
+
decorations = decorations.add(newState.doc, [_decs]);
|
|
366
|
+
}
|
|
367
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
368
|
+
// Remove drop target decoration when dragging stops
|
|
369
|
+
var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
|
|
370
|
+
return spec.type === 'drop-target-decoration';
|
|
371
|
+
});
|
|
372
|
+
decorations = decorations.remove(dropTargetDecs);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// Map active node position when the document changes
|
|
376
|
+
var mappedActiveNodePos = tr.docChanged && activeNode ? !isPerformanceFix && activeNodeWithNewNodeType || {
|
|
377
|
+
pos: tr.mapping.map(activeNode.pos),
|
|
378
|
+
anchorName: activeNode.anchorName,
|
|
379
|
+
nodeType: activeNode.nodeType
|
|
380
|
+
} : activeNode;
|
|
381
|
+
var shouldCreateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
382
|
+
if (api) {
|
|
383
|
+
// Add drop targets when node is being dragged
|
|
384
|
+
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
385
|
+
if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
|
|
386
|
+
var _meta$activeNode7;
|
|
387
|
+
var _decs2 = dropTargetDecorations(newState, api, formatMessage, isNestedEnabled ? (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos : meta === null || meta === void 0 ? void 0 : meta.activeNode, anchorHeightsCache);
|
|
388
|
+
decorations = decorations.add(newState.doc, _decs2);
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
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;
|
|
392
|
+
if (isEmptyDoc) {
|
|
393
|
+
var hasNodeDecoration = !!decorations.find(undefined, undefined, function (spec) {
|
|
394
|
+
return spec.type === 'node-decoration';
|
|
395
|
+
}).length;
|
|
396
|
+
if (!hasNodeDecoration) {
|
|
397
|
+
decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
var newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && decorations.find(undefined, undefined, function (spec) {
|
|
401
|
+
return spec.type === 'drag-handle';
|
|
402
|
+
}).length === 0 ? null : (_meta$activeNode8 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode8 !== void 0 ? _meta$activeNode8 : mappedActiveNodePos;
|
|
403
|
+
return {
|
|
404
|
+
decorations: decorations,
|
|
405
|
+
activeNode: newActiveNode,
|
|
406
|
+
isDragging: (_meta$isDragging4 = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging4 !== void 0 ? _meta$isDragging4 : isDragging,
|
|
407
|
+
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
408
|
+
editorHeight: (_meta$editorHeight2 = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight2 !== void 0 ? _meta$editorHeight2 : currentState.editorHeight,
|
|
409
|
+
editorWidthLeft: (_meta$editorWidthLeft2 = meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== null && _meta$editorWidthLeft2 !== void 0 ? _meta$editorWidthLeft2 : currentState.editorWidthLeft,
|
|
410
|
+
editorWidthRight: (_meta$editorWidthRigh2 = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh2 !== void 0 ? _meta$editorWidthRigh2 : currentState.editorWidthRight,
|
|
411
|
+
isResizerResizing: isResizerResizing,
|
|
412
|
+
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
413
|
+
isPMDragging: (_meta$isPMDragging2 = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging2 !== void 0 ? _meta$isPMDragging2 : isPMDragging
|
|
414
|
+
};
|
|
415
|
+
};
|
|
90
416
|
export var createPlugin = function createPlugin(api, getIntl) {
|
|
91
417
|
var _getIntl = getIntl(),
|
|
92
418
|
formatMessage = _getIntl.formatMessage;
|
|
93
419
|
var isNestedEnabled = editorExperiment('nested-dnd', true, {
|
|
94
420
|
exposure: true
|
|
95
421
|
});
|
|
422
|
+
var isOptimisedApply = isNestedEnabled && editorExperiment('optimised-apply-dnd', true, {
|
|
423
|
+
exposure: true
|
|
424
|
+
});
|
|
425
|
+
var isTitleEnterImprovementEnabled = fg('confluence_frontend_page_title_enter_improvements');
|
|
426
|
+
var flags = {
|
|
427
|
+
isNestedEnabled: isNestedEnabled,
|
|
428
|
+
isOptimisedApply: isOptimisedApply,
|
|
429
|
+
isTitleEnterImprovementEnabled: isTitleEnterImprovementEnabled
|
|
430
|
+
};
|
|
96
431
|
if (fg('platform_editor_element_dnd_nested_fix_patch_2')) {
|
|
97
432
|
// TODO: Remove this once FG is used in code
|
|
98
433
|
}
|
|
@@ -107,195 +442,10 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
107
442
|
return initialState;
|
|
108
443
|
},
|
|
109
444
|
apply: function apply(tr, currentState, oldState, newState) {
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
decorations = currentState.decorations,
|
|
113
|
-
isMenuOpen = currentState.isMenuOpen,
|
|
114
|
-
editorHeight = currentState.editorHeight,
|
|
115
|
-
editorWidthLeft = currentState.editorWidthLeft,
|
|
116
|
-
editorWidthRight = currentState.editorWidthRight,
|
|
117
|
-
isResizerResizing = currentState.isResizerResizing,
|
|
118
|
-
isDragging = currentState.isDragging,
|
|
119
|
-
isPMDragging = currentState.isPMDragging;
|
|
120
|
-
|
|
121
|
-
// Remap existing decorations when steps exist
|
|
122
|
-
if (tr.docChanged) {
|
|
123
|
-
decorations = decorations.map(tr.mapping, tr.doc);
|
|
124
|
-
}
|
|
125
|
-
var meta = tr.getMeta(key);
|
|
126
|
-
var isPerformanceFix = isNestedEnabled || editorExperiment('dnd-input-performance-optimisation', true, {
|
|
127
|
-
exposure: true
|
|
128
|
-
});
|
|
129
|
-
var activeNodeWithNewNodeType = null;
|
|
130
|
-
|
|
131
|
-
// If tables or media are being resized, we want to hide the drag handle
|
|
132
|
-
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
133
|
-
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
134
|
-
var canIgnoreTr = function canIgnoreTr() {
|
|
135
|
-
return !tr.steps.every(function (e) {
|
|
136
|
-
return e instanceof AnalyticsStep;
|
|
137
|
-
});
|
|
138
|
-
};
|
|
139
|
-
var maybeNodeCountChanged = isNestedEnabled ? !isTextInput(tr) && tr.docChanged && canIgnoreTr() : oldState.doc.childCount !== newState.doc.childCount;
|
|
140
|
-
var shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
141
|
-
|
|
142
|
-
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
143
|
-
// Also remove the handle when the node is moved or the node count changes. This helps prevent incorrect positioning
|
|
144
|
-
// Don't remove the handle if remote changes are changing the node count, its prosemirror position can be mapped instead
|
|
145
|
-
if (meta !== null && meta !== void 0 && meta.hideDragHandle && fg('confluence_frontend_page_title_enter_improvements') || isResizerResizing || maybeNodeCountChanged && shouldRemoveHandle || meta !== null && meta !== void 0 && meta.nodeMoved) {
|
|
146
|
-
var oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
147
|
-
return spec.id === 'drag-handle';
|
|
148
|
-
});
|
|
149
|
-
decorations = decorations.remove(oldHandle);
|
|
150
|
-
}
|
|
151
|
-
var decsLength = isNestedEnabled ? decorations.find(undefined, undefined, function (spec) {
|
|
152
|
-
return spec.type === 'node-decoration';
|
|
153
|
-
}).length : decorations.find().filter(function (_ref5) {
|
|
154
|
-
var spec = _ref5.spec;
|
|
155
|
-
return spec.id !== 'drag-handle';
|
|
156
|
-
}).length;
|
|
157
|
-
var isDecsMissing = false;
|
|
158
|
-
var isDropTargetsMissing = false;
|
|
159
|
-
if (isNestedEnabled) {
|
|
160
|
-
var _meta$isDragging;
|
|
161
|
-
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && maybeNodeCountChanged;
|
|
162
|
-
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);
|
|
163
|
-
} else {
|
|
164
|
-
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
165
|
-
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
166
|
-
return spec.type === 'drop-target-decoration';
|
|
167
|
-
}).length;
|
|
168
|
-
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
// This is not targeted enough - it's trying to catch events like expand being set to breakout
|
|
172
|
-
var maybeWidthUpdated = tr.docChanged && oldState.doc.nodeSize === newState.doc.nodeSize && !maybeNodeCountChanged;
|
|
173
|
-
|
|
174
|
-
// This addresses scenarios such as undoing table resizing,
|
|
175
|
-
// where a keyboard shortcut triggers a width change, and
|
|
176
|
-
// the node's actual width is then updated in a separate renderering cycle.
|
|
177
|
-
// The tr.meta.activeNode is triggered by the showDragHandleAt function during the mouse entry event
|
|
178
|
-
// (when the table node rerenders)
|
|
179
|
-
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
180
|
-
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);
|
|
181
|
-
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;
|
|
182
|
-
|
|
183
|
-
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
184
|
-
if (redrawDecorations && !isResizerResizing && api) {
|
|
185
|
-
var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
|
|
186
|
-
return spec.type !== 'drop-target-decoration';
|
|
187
|
-
});
|
|
188
|
-
decorations = decorations.remove(oldNodeDecs);
|
|
189
|
-
var newNodeDecs = nodeDecorations(newState);
|
|
190
|
-
decorations = decorations.add(newState.doc, _toConsumableArray(newNodeDecs));
|
|
191
|
-
if (activeNode && !(meta !== null && meta !== void 0 && meta.nodeMoved) && !isDecsMissing) {
|
|
192
|
-
var mappedPosisiton = tr.mapping.map(activeNode.pos);
|
|
193
|
-
var prevMappedPos = oldState.tr.mapping.map(activeNode.pos);
|
|
194
|
-
|
|
195
|
-
// When a node type changed to be nested inside another node, the position of the active node is off by 1
|
|
196
|
-
// This is a workaround to fix the position of the active node when it is nested
|
|
197
|
-
if (tr.docChanged && !maybeNodeCountChanged && mappedPosisiton === prevMappedPos + 1) {
|
|
198
|
-
mappedPosisiton = prevMappedPos;
|
|
199
|
-
}
|
|
200
|
-
var _newActiveNode = tr.doc.nodeAt(mappedPosisiton);
|
|
201
|
-
var draghandleDec;
|
|
202
|
-
if (isPerformanceFix) {
|
|
203
|
-
var _meta$activeNode$pos, _meta$activeNode2, _ref6, _meta$activeNode$anch, _meta$activeNode3, _decAtPos$spec, _ref7, _meta$activeNode$node, _meta$activeNode4, _decAtPos$spec2, _meta$activeNode5;
|
|
204
|
-
if (_newActiveNode && (_newActiveNode === null || _newActiveNode === void 0 ? void 0 : _newActiveNode.type.name) !== activeNode.nodeType) {
|
|
205
|
-
var _oldHandle = decorations.find(undefined, undefined, function (spec) {
|
|
206
|
-
return spec.id === 'drag-handle';
|
|
207
|
-
});
|
|
208
|
-
decorations = decorations.remove(_oldHandle);
|
|
209
|
-
}
|
|
210
|
-
var decAtPos = newNodeDecs.find(function (dec) {
|
|
211
|
-
return dec.from === mappedPosisiton;
|
|
212
|
-
});
|
|
213
|
-
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);
|
|
214
|
-
} else {
|
|
215
|
-
var nodeType = activeNode.nodeType;
|
|
216
|
-
var anchorName = activeNode.anchorName;
|
|
217
|
-
if (_newActiveNode && (_newActiveNode === null || _newActiveNode === void 0 ? void 0 : _newActiveNode.type.name) !== activeNode.nodeType) {
|
|
218
|
-
nodeType = _newActiveNode.type.name;
|
|
219
|
-
anchorName = activeNode.anchorName.replace(activeNode.nodeType, nodeType);
|
|
220
|
-
activeNodeWithNewNodeType = {
|
|
221
|
-
pos: prevMappedPos,
|
|
222
|
-
nodeType: nodeType,
|
|
223
|
-
anchorName: anchorName
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
draghandleDec = dragHandleDecoration(api, getIntl, activeNode.pos, anchorName, nodeType);
|
|
227
|
-
}
|
|
228
|
-
decorations = decorations.add(newState.doc, [draghandleDec]);
|
|
229
|
-
}
|
|
230
|
-
}
|
|
231
|
-
|
|
232
|
-
// Remove previous drag handle widget and draw new drag handle widget when activeNode changes
|
|
233
|
-
if (api && meta !== null && meta !== void 0 && meta.activeNode && ((meta === null || meta === void 0 ? void 0 : meta.activeNode.pos) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.pos) && (meta === null || meta === void 0 ? void 0 : meta.activeNode.anchorName) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.anchorName) || meta !== null && meta !== void 0 && (_meta$activeNode$hand = meta.activeNode.handleOptions) !== null && _meta$activeNode$hand !== void 0 && _meta$activeNode$hand.isFocused)) {
|
|
234
|
-
var _oldHandle2 = decorations.find(undefined, undefined, function (spec) {
|
|
235
|
-
return spec.id === 'drag-handle';
|
|
236
|
-
});
|
|
237
|
-
decorations = decorations.remove(_oldHandle2);
|
|
238
|
-
var decs = dragHandleDecoration(api, getIntl, meta.activeNode.pos, meta.activeNode.anchorName, meta.activeNode.nodeType, meta.activeNode.handleOptions);
|
|
239
|
-
decorations = decorations.add(newState.doc, [decs]);
|
|
445
|
+
if (isOptimisedApply) {
|
|
446
|
+
return newApply(api, formatMessage, tr, currentState, newState, flags, anchorHeightsCache);
|
|
240
447
|
}
|
|
241
|
-
|
|
242
|
-
// Remove previous drag handle widget and draw new drag handle widget when node type changes
|
|
243
|
-
if (!isPerformanceFix && activeNodeWithNewNodeType && ((_activeNodeWithNewNod = activeNodeWithNewNodeType) === null || _activeNodeWithNewNod === void 0 ? void 0 : _activeNodeWithNewNod.nodeType) !== (activeNode === null || activeNode === void 0 ? void 0 : activeNode.nodeType) && api) {
|
|
244
|
-
var _oldHandle3 = decorations.find(undefined, undefined, function (spec) {
|
|
245
|
-
return spec.id === 'drag-handle';
|
|
246
|
-
});
|
|
247
|
-
decorations = decorations.remove(_oldHandle3);
|
|
248
|
-
var _decs = dragHandleDecoration(api, getIntl, activeNodeWithNewNodeType.pos, activeNodeWithNewNodeType.anchorName, activeNodeWithNewNodeType.nodeType);
|
|
249
|
-
decorations = decorations.add(newState.doc, [_decs]);
|
|
250
|
-
}
|
|
251
|
-
if ((meta === null || meta === void 0 ? void 0 : meta.isDragging) === false || isDropTargetsMissing) {
|
|
252
|
-
// Remove drop target decoration when dragging stops
|
|
253
|
-
var dropTargetDecs = decorations.find(undefined, undefined, function (spec) {
|
|
254
|
-
return spec.type === 'drop-target-decoration';
|
|
255
|
-
});
|
|
256
|
-
decorations = decorations.remove(dropTargetDecs);
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
// Map active node position when the document changes
|
|
260
|
-
var mappedActiveNodePos = tr.docChanged && activeNode ? !isPerformanceFix && activeNodeWithNewNodeType || {
|
|
261
|
-
pos: tr.mapping.map(activeNode.pos),
|
|
262
|
-
anchorName: activeNode.anchorName,
|
|
263
|
-
nodeType: activeNode.nodeType
|
|
264
|
-
} : activeNode;
|
|
265
|
-
var shouldCreateDropTargets = (meta === null || meta === void 0 ? void 0 : meta.isDragging) || isDropTargetsMissing;
|
|
266
|
-
if (api) {
|
|
267
|
-
// Add drop targets when node is being dragged
|
|
268
|
-
// if the transaction is only for analytics and user is dragging, continue to draw drop targets
|
|
269
|
-
if (shouldCreateDropTargets || isBlocksDragTargetDebug()) {
|
|
270
|
-
var _meta$activeNode6;
|
|
271
|
-
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, anchorHeightsCache);
|
|
272
|
-
decorations = decorations.add(newState.doc, _decs2);
|
|
273
|
-
}
|
|
274
|
-
}
|
|
275
|
-
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;
|
|
276
|
-
if (isEmptyDoc) {
|
|
277
|
-
var hasNodeDecoration = !!decorations.find(undefined, undefined, function (spec) {
|
|
278
|
-
return spec.type === 'node-decoration';
|
|
279
|
-
}).length;
|
|
280
|
-
if (!hasNodeDecoration) {
|
|
281
|
-
decorations = decorations.add(newState.doc, [emptyParagraphNodeDecorations()]);
|
|
282
|
-
}
|
|
283
|
-
}
|
|
284
|
-
var newActiveNode = isEmptyDoc || !(meta !== null && meta !== void 0 && meta.activeNode) && decorations.find(undefined, undefined, function (spec) {
|
|
285
|
-
return spec.id === 'drag-handle';
|
|
286
|
-
}).length === 0 ? null : (_meta$activeNode7 = meta === null || meta === void 0 ? void 0 : meta.activeNode) !== null && _meta$activeNode7 !== void 0 ? _meta$activeNode7 : mappedActiveNodePos;
|
|
287
|
-
return {
|
|
288
|
-
decorations: decorations,
|
|
289
|
-
activeNode: newActiveNode,
|
|
290
|
-
isDragging: (_meta$isDragging2 = meta === null || meta === void 0 ? void 0 : meta.isDragging) !== null && _meta$isDragging2 !== void 0 ? _meta$isDragging2 : isDragging,
|
|
291
|
-
isMenuOpen: meta !== null && meta !== void 0 && meta.toggleMenu ? !isMenuOpen : isMenuOpen,
|
|
292
|
-
editorHeight: (_meta$editorHeight = meta === null || meta === void 0 ? void 0 : meta.editorHeight) !== null && _meta$editorHeight !== void 0 ? _meta$editorHeight : currentState.editorHeight,
|
|
293
|
-
editorWidthLeft: (_meta$editorWidthLeft = meta === null || meta === void 0 ? void 0 : meta.editorWidthLeft) !== null && _meta$editorWidthLeft !== void 0 ? _meta$editorWidthLeft : currentState.editorWidthLeft,
|
|
294
|
-
editorWidthRight: (_meta$editorWidthRigh = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh !== void 0 ? _meta$editorWidthRigh : currentState.editorWidthRight,
|
|
295
|
-
isResizerResizing: isResizerResizing,
|
|
296
|
-
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
297
|
-
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
298
|
-
};
|
|
448
|
+
return oldApply(api, formatMessage, tr, currentState, oldState, newState, flags, anchorHeightsCache);
|
|
299
449
|
}
|
|
300
450
|
},
|
|
301
451
|
props: {
|
|
@@ -394,13 +544,8 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
394
544
|
var dom = editorView.dom;
|
|
395
545
|
var editorContentArea = editorView.dom.closest('.fabric-editor-popup-scroll-parent');
|
|
396
546
|
|
|
397
|
-
// Use ResizeObserver to observe width changes
|
|
547
|
+
// Use ResizeObserver to observe resizer (scroll-parent typically grows when resizing) and editor width changes
|
|
398
548
|
var resizeObserverWidth = new ResizeObserver(rafSchedule(function (entries) {
|
|
399
|
-
var editorContentArea = entries[0].target;
|
|
400
|
-
var editorWidthRight = editorContentArea.getBoundingClientRect().right;
|
|
401
|
-
var editorWidthLeft = editorContentArea.getBoundingClientRect().left;
|
|
402
|
-
|
|
403
|
-
// Update the plugin state when the height changes
|
|
404
549
|
var pluginState = key.getState(editorView.state);
|
|
405
550
|
if (!(pluginState !== null && pluginState !== void 0 && pluginState.isDragging)) {
|
|
406
551
|
var isResizerResizing = !!dom.querySelector('.is-resizing');
|
|
@@ -409,17 +554,18 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
409
554
|
transaction.setMeta('is-resizer-resizing', isResizerResizing);
|
|
410
555
|
}
|
|
411
556
|
if (!isResizerResizing) {
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
557
|
+
var _editorContentArea = entries[0].target;
|
|
558
|
+
var editorWidthRight = _editorContentArea.getBoundingClientRect().right;
|
|
559
|
+
var editorWidthLeft = _editorContentArea.getBoundingClientRect().left;
|
|
560
|
+
transaction.setMeta(key, {
|
|
561
|
+
editorWidthLeft: editorWidthLeft,
|
|
562
|
+
editorWidthRight: editorWidthRight
|
|
563
|
+
});
|
|
418
564
|
}
|
|
419
565
|
editorView.dispatch(transaction);
|
|
420
566
|
}
|
|
421
567
|
}));
|
|
422
|
-
if (editorContentArea
|
|
568
|
+
if (editorContentArea) {
|
|
423
569
|
resizeObserverWidth.observe(editorContentArea);
|
|
424
570
|
}
|
|
425
571
|
|
|
@@ -427,7 +573,7 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
427
573
|
var pragmaticCleanup = destroyFn(api);
|
|
428
574
|
return {
|
|
429
575
|
destroy: function destroy() {
|
|
430
|
-
if (editorContentArea
|
|
576
|
+
if (editorContentArea) {
|
|
431
577
|
resizeObserverWidth.unobserve(editorContentArea);
|
|
432
578
|
}
|
|
433
579
|
pragmaticCleanup();
|