@atlaskit/editor-plugin-block-controls 1.12.0 → 1.12.1
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 +12 -0
- package/dist/cjs/pm-plugins/main.js +36 -21
- package/dist/cjs/utils/validation.js +5 -2
- package/dist/es2019/pm-plugins/main.js +31 -17
- package/dist/es2019/utils/validation.js +4 -1
- package/dist/esm/pm-plugins/main.js +36 -21
- package/dist/esm/utils/validation.js +4 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/types/utils/validation.d.ts +1 -0
- package/dist/types-ts4.5/types.d.ts +1 -0
- package/dist/types-ts4.5/utils/validation.d.ts +1 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-block-controls
|
|
2
2
|
|
|
3
|
+
## 1.12.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#130485](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130485)
|
|
8
|
+
[`5b6725b15e18e`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/5b6725b15e18e) -
|
|
9
|
+
Update node decorations when document changes for nested dnd scenarios
|
|
10
|
+
- [#130711](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/130711)
|
|
11
|
+
[`f878c5be1ed97`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/f878c5be1ed97) -
|
|
12
|
+
ED-24455 additional fix and tests
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 1.12.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -71,6 +71,13 @@ var destroyFn = function destroyFn(api) {
|
|
|
71
71
|
}));
|
|
72
72
|
return _combine.combine.apply(void 0, cleanupFn);
|
|
73
73
|
};
|
|
74
|
+
function getDocChildrenCount(newState) {
|
|
75
|
+
var size = 0;
|
|
76
|
+
newState.doc.descendants(function (node) {
|
|
77
|
+
size += node.childCount;
|
|
78
|
+
});
|
|
79
|
+
return size;
|
|
80
|
+
}
|
|
74
81
|
var initialState = {
|
|
75
82
|
decorations: _view.DecorationSet.empty,
|
|
76
83
|
decorationState: [],
|
|
@@ -82,7 +89,8 @@ var initialState = {
|
|
|
82
89
|
editorWidthRight: 0,
|
|
83
90
|
isResizerResizing: false,
|
|
84
91
|
isDocSizeLimitEnabled: null,
|
|
85
|
-
isPMDragging: false
|
|
92
|
+
isPMDragging: false,
|
|
93
|
+
childCount: 0
|
|
86
94
|
};
|
|
87
95
|
var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
88
96
|
return new _safePlugin.SafePlugin({
|
|
@@ -102,14 +110,15 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
102
110
|
editorWidthRight = currentState.editorWidthRight,
|
|
103
111
|
isResizerResizing = currentState.isResizerResizing,
|
|
104
112
|
isDragging = currentState.isDragging,
|
|
105
|
-
isPMDragging = currentState.isPMDragging
|
|
113
|
+
isPMDragging = currentState.isPMDragging,
|
|
114
|
+
childCount = currentState.childCount;
|
|
106
115
|
var activeNodeWithNewNodeType = null;
|
|
107
116
|
var meta = tr.getMeta(key);
|
|
108
|
-
|
|
117
|
+
var newChildCount = tr.docChanged && (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? getDocChildrenCount(newState) : childCount;
|
|
109
118
|
// If tables or media are being resized, we want to hide the drag handle
|
|
110
119
|
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
111
120
|
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
112
|
-
var nodeCountChanged = oldState.doc.childCount !== newState.doc.childCount;
|
|
121
|
+
var nodeCountChanged = (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? childCount !== newChildCount : oldState.doc.childCount !== newState.doc.childCount;
|
|
113
122
|
var shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
114
123
|
|
|
115
124
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
@@ -129,20 +138,26 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
129
138
|
var spec = _ref6.spec;
|
|
130
139
|
return spec.id === 'drag-handle';
|
|
131
140
|
});
|
|
132
|
-
var decsLength = decorations.find().filter(function (_ref7) {
|
|
141
|
+
var decsLength = (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? decorations.find().filter(function (_ref7) {
|
|
133
142
|
var spec = _ref7.spec;
|
|
143
|
+
return spec.type === 'node-decoration';
|
|
144
|
+
}).length : decorations.find().filter(function (_ref8) {
|
|
145
|
+
var spec = _ref8.spec;
|
|
134
146
|
return spec.id !== 'drag-handle';
|
|
135
147
|
}).length;
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
148
|
+
var newNodeDecs;
|
|
149
|
+
if ((0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
150
|
+
// naive solution while we work on performance optimised approach under ED-24503
|
|
151
|
+
newNodeDecs = (0, _decorations.nodeDecorations)(newState);
|
|
152
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newNodeDecs.length;
|
|
153
|
+
} else {
|
|
139
154
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
140
155
|
}
|
|
141
156
|
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
142
157
|
return spec.type === 'drop-target-decoration';
|
|
143
158
|
}).length;
|
|
144
|
-
|
|
145
|
-
|
|
159
|
+
var _getIntl = getIntl(),
|
|
160
|
+
formatMessage = _getIntl.formatMessage;
|
|
146
161
|
if (!(0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested')) {
|
|
147
162
|
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
148
163
|
}
|
|
@@ -158,17 +173,16 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
158
173
|
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
159
174
|
var maybeNodeWidthUpdated = (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);
|
|
160
175
|
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 || nodeCountChanged || maybeNodeWidthUpdated || resizerMeta === false || isDecsMissing || !!(meta !== null && meta !== void 0 && meta.nodeMoved) && tr.docChanged;
|
|
161
|
-
var _getIntl = getIntl(),
|
|
162
|
-
formatMessage = _getIntl.formatMessage;
|
|
163
176
|
|
|
164
177
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
165
178
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
179
|
+
var _newNodeDecs;
|
|
166
180
|
var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
|
|
167
181
|
return spec.type !== 'drop-target-decoration';
|
|
168
182
|
});
|
|
169
183
|
decorations = decorations.remove(oldNodeDecs);
|
|
170
|
-
|
|
171
|
-
decorations = decorations.add(newState.doc, (0, _toConsumableArray2.default)(
|
|
184
|
+
newNodeDecs = (_newNodeDecs = newNodeDecs) !== null && _newNodeDecs !== void 0 ? _newNodeDecs : (0, _decorations.nodeDecorations)(newState);
|
|
185
|
+
decorations = decorations.add(newState.doc, (0, _toConsumableArray2.default)(newNodeDecs));
|
|
172
186
|
|
|
173
187
|
// Note: Quite often the handle is not in the right position after a node is moved
|
|
174
188
|
// it is safer for now to not show it when a node is moved
|
|
@@ -247,9 +261,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
247
261
|
|
|
248
262
|
//Map drop target decoration positions when the document changes
|
|
249
263
|
if (shouldMapDropTargets) {
|
|
250
|
-
decorationState = decorationState.map(function (
|
|
251
|
-
var id =
|
|
252
|
-
pos =
|
|
264
|
+
decorationState = decorationState.map(function (_ref9) {
|
|
265
|
+
var id = _ref9.id,
|
|
266
|
+
pos = _ref9.pos;
|
|
253
267
|
return {
|
|
254
268
|
id: id,
|
|
255
269
|
pos: tr.mapping.map(pos)
|
|
@@ -261,9 +275,9 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
261
275
|
if (shouldMapDropTargets || tr.docChanged && !redrawDecorations) {
|
|
262
276
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
263
277
|
}
|
|
264
|
-
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
265
|
-
var hasNodeDecoration = decorations.find().some(function (
|
|
266
|
-
var spec =
|
|
278
|
+
var isEmptyDoc = (0, _platformFeatureFlags.fg)('platform_editor_elements_dnd_nested') ? 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;
|
|
279
|
+
var hasNodeDecoration = decorations.find().some(function (_ref10) {
|
|
280
|
+
var spec = _ref10.spec;
|
|
267
281
|
return spec.type === 'node-decoration';
|
|
268
282
|
});
|
|
269
283
|
if (!hasNodeDecoration && isEmptyDoc) {
|
|
@@ -287,7 +301,8 @@ var createPlugin = exports.createPlugin = function createPlugin(api, getIntl) {
|
|
|
287
301
|
editorWidthRight: (_meta$editorWidthRigh = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh !== void 0 ? _meta$editorWidthRigh : currentState.editorWidthRight,
|
|
288
302
|
isResizerResizing: isResizerResizing,
|
|
289
303
|
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
290
|
-
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
304
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging,
|
|
305
|
+
childCount: newChildCount
|
|
291
306
|
};
|
|
292
307
|
}
|
|
293
308
|
},
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.canMoveNodeToIndex = canMoveNodeToIndex;
|
|
8
|
-
exports.transformSliceExpandToNestedExpand = exports.transformExpandToNestedExpand = exports.memoizedTransformExpandToNestedExpand = exports.isNestedExpand = exports.isInsideTable = exports.isExpand = exports.isDoc = void 0;
|
|
8
|
+
exports.transformSliceExpandToNestedExpand = exports.transformExpandToNestedExpand = exports.memoizedTransformExpandToNestedExpand = exports.isNestedExpand = exports.isLayoutColumn = exports.isInsideTable = exports.isExpand = exports.isDoc = void 0;
|
|
9
9
|
var _memoizeOne = _interopRequireDefault(require("memoize-one"));
|
|
10
10
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
11
11
|
var isInsideTable = exports.isInsideTable = function isInsideTable(nodeType) {
|
|
@@ -14,6 +14,9 @@ var isInsideTable = exports.isInsideTable = function isInsideTable(nodeType) {
|
|
|
14
14
|
tableHeader = _nodeType$schema$node.tableHeader;
|
|
15
15
|
return [tableCell, tableHeader].indexOf(nodeType) >= 0;
|
|
16
16
|
};
|
|
17
|
+
var isLayoutColumn = exports.isLayoutColumn = function isLayoutColumn(nodeType) {
|
|
18
|
+
return nodeType === nodeType.schema.nodes.layoutColumn;
|
|
19
|
+
};
|
|
17
20
|
var isDoc = exports.isDoc = function isDoc(nodeType) {
|
|
18
21
|
return nodeType === nodeType.schema.nodes.doc;
|
|
19
22
|
};
|
|
@@ -73,7 +76,7 @@ function canMoveNodeToIndex(destParent, indexIntoParent, srcNode) {
|
|
|
73
76
|
} else {
|
|
74
77
|
return false;
|
|
75
78
|
}
|
|
76
|
-
} else if (isDoc(destParent.type) && isNestedExpand(srcNodeType)) {
|
|
79
|
+
} else if ((isDoc(destParent.type) || isLayoutColumn(destParent.type)) && isNestedExpand(srcNodeType)) {
|
|
77
80
|
srcNodeType = srcNodeType.schema.nodes.expand;
|
|
78
81
|
}
|
|
79
82
|
return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
|
|
@@ -65,6 +65,13 @@ const destroyFn = api => {
|
|
|
65
65
|
}));
|
|
66
66
|
return combine(...cleanupFn);
|
|
67
67
|
};
|
|
68
|
+
function getDocChildrenCount(newState) {
|
|
69
|
+
let size = 0;
|
|
70
|
+
newState.doc.descendants(node => {
|
|
71
|
+
size += node.childCount;
|
|
72
|
+
});
|
|
73
|
+
return size;
|
|
74
|
+
}
|
|
68
75
|
const initialState = {
|
|
69
76
|
decorations: DecorationSet.empty,
|
|
70
77
|
decorationState: [],
|
|
@@ -76,7 +83,8 @@ const initialState = {
|
|
|
76
83
|
editorWidthRight: 0,
|
|
77
84
|
isResizerResizing: false,
|
|
78
85
|
isDocSizeLimitEnabled: null,
|
|
79
|
-
isPMDragging: false
|
|
86
|
+
isPMDragging: false,
|
|
87
|
+
childCount: 0
|
|
80
88
|
};
|
|
81
89
|
export const createPlugin = (api, getIntl) => {
|
|
82
90
|
return new SafePlugin({
|
|
@@ -97,15 +105,16 @@ export const createPlugin = (api, getIntl) => {
|
|
|
97
105
|
editorWidthRight,
|
|
98
106
|
isResizerResizing,
|
|
99
107
|
isDragging,
|
|
100
|
-
isPMDragging
|
|
108
|
+
isPMDragging,
|
|
109
|
+
childCount
|
|
101
110
|
} = currentState;
|
|
102
111
|
let activeNodeWithNewNodeType = null;
|
|
103
112
|
const meta = tr.getMeta(key);
|
|
104
|
-
|
|
113
|
+
const newChildCount = tr.docChanged && fg('platform_editor_elements_dnd_nested') ? getDocChildrenCount(newState) : childCount;
|
|
105
114
|
// If tables or media are being resized, we want to hide the drag handle
|
|
106
115
|
const resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
107
116
|
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
108
|
-
const nodeCountChanged = oldState.doc.childCount !== newState.doc.childCount;
|
|
117
|
+
const nodeCountChanged = fg('platform_editor_elements_dnd_nested') ? childCount !== newChildCount : oldState.doc.childCount !== newState.doc.childCount;
|
|
109
118
|
const shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
110
119
|
|
|
111
120
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
@@ -123,17 +132,23 @@ export const createPlugin = (api, getIntl) => {
|
|
|
123
132
|
const isHandleMissing = !(meta !== null && meta !== void 0 && meta.activeNode) && !decorations.find().some(({
|
|
124
133
|
spec
|
|
125
134
|
}) => spec.id === 'drag-handle');
|
|
126
|
-
const decsLength = decorations.find().filter(({
|
|
135
|
+
const decsLength = fg('platform_editor_elements_dnd_nested') ? decorations.find().filter(({
|
|
136
|
+
spec
|
|
137
|
+
}) => spec.type === 'node-decoration').length : decorations.find().filter(({
|
|
127
138
|
spec
|
|
128
139
|
}) => spec.id !== 'drag-handle').length;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
140
|
+
let newNodeDecs;
|
|
141
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
142
|
+
// naive solution while we work on performance optimised approach under ED-24503
|
|
143
|
+
newNodeDecs = nodeDecorations(newState);
|
|
144
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newNodeDecs.length;
|
|
145
|
+
} else {
|
|
132
146
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
133
147
|
}
|
|
134
148
|
const dropTargetLen = decorations.find(undefined, undefined, spec => spec.type === 'drop-target-decoration').length;
|
|
135
|
-
|
|
136
|
-
|
|
149
|
+
const {
|
|
150
|
+
formatMessage
|
|
151
|
+
} = getIntl();
|
|
137
152
|
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
138
153
|
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
139
154
|
}
|
|
@@ -149,16 +164,14 @@ export const createPlugin = (api, getIntl) => {
|
|
|
149
164
|
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
150
165
|
const maybeNodeWidthUpdated = (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);
|
|
151
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 || nodeCountChanged || maybeNodeWidthUpdated || resizerMeta === false || isDecsMissing || !!(meta !== null && meta !== void 0 && meta.nodeMoved) && tr.docChanged;
|
|
152
|
-
const {
|
|
153
|
-
formatMessage
|
|
154
|
-
} = getIntl();
|
|
155
167
|
|
|
156
168
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
157
169
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
170
|
+
var _newNodeDecs;
|
|
158
171
|
const oldNodeDecs = decorations.find(undefined, undefined, spec => spec.type !== 'drop-target-decoration');
|
|
159
172
|
decorations = decorations.remove(oldNodeDecs);
|
|
160
|
-
|
|
161
|
-
decorations = decorations.add(newState.doc, [...
|
|
173
|
+
newNodeDecs = (_newNodeDecs = newNodeDecs) !== null && _newNodeDecs !== void 0 ? _newNodeDecs : nodeDecorations(newState);
|
|
174
|
+
decorations = decorations.add(newState.doc, [...newNodeDecs]);
|
|
162
175
|
|
|
163
176
|
// Note: Quite often the handle is not in the right position after a node is moved
|
|
164
177
|
// it is safer for now to not show it when a node is moved
|
|
@@ -245,7 +258,7 @@ export const createPlugin = (api, getIntl) => {
|
|
|
245
258
|
if (shouldMapDropTargets || tr.docChanged && !redrawDecorations) {
|
|
246
259
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
247
260
|
}
|
|
248
|
-
const isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
261
|
+
const isEmptyDoc = fg('platform_editor_elements_dnd_nested') ? 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
262
|
const hasNodeDecoration = decorations.find().some(({
|
|
250
263
|
spec
|
|
251
264
|
}) => spec.type === 'node-decoration');
|
|
@@ -270,7 +283,8 @@ export const createPlugin = (api, getIntl) => {
|
|
|
270
283
|
editorWidthRight: (_meta$editorWidthRigh = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh !== void 0 ? _meta$editorWidthRigh : currentState.editorWidthRight,
|
|
271
284
|
isResizerResizing: isResizerResizing,
|
|
272
285
|
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
273
|
-
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
286
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging,
|
|
287
|
+
childCount: newChildCount
|
|
274
288
|
};
|
|
275
289
|
}
|
|
276
290
|
},
|
|
@@ -7,6 +7,9 @@ export const isInsideTable = nodeType => {
|
|
|
7
7
|
} = nodeType.schema.nodes;
|
|
8
8
|
return [tableCell, tableHeader].indexOf(nodeType) >= 0;
|
|
9
9
|
};
|
|
10
|
+
export const isLayoutColumn = nodeType => {
|
|
11
|
+
return nodeType === nodeType.schema.nodes.layoutColumn;
|
|
12
|
+
};
|
|
10
13
|
export const isDoc = nodeType => {
|
|
11
14
|
return nodeType === nodeType.schema.nodes.doc;
|
|
12
15
|
};
|
|
@@ -67,7 +70,7 @@ export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode) {
|
|
|
67
70
|
} else {
|
|
68
71
|
return false;
|
|
69
72
|
}
|
|
70
|
-
} else if (isDoc(destParent.type) && isNestedExpand(srcNodeType)) {
|
|
73
|
+
} else if ((isDoc(destParent.type) || isLayoutColumn(destParent.type)) && isNestedExpand(srcNodeType)) {
|
|
71
74
|
srcNodeType = srcNodeType.schema.nodes.expand;
|
|
72
75
|
}
|
|
73
76
|
return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
|
|
@@ -64,6 +64,13 @@ var destroyFn = function destroyFn(api) {
|
|
|
64
64
|
}));
|
|
65
65
|
return combine.apply(void 0, cleanupFn);
|
|
66
66
|
};
|
|
67
|
+
function getDocChildrenCount(newState) {
|
|
68
|
+
var size = 0;
|
|
69
|
+
newState.doc.descendants(function (node) {
|
|
70
|
+
size += node.childCount;
|
|
71
|
+
});
|
|
72
|
+
return size;
|
|
73
|
+
}
|
|
67
74
|
var initialState = {
|
|
68
75
|
decorations: DecorationSet.empty,
|
|
69
76
|
decorationState: [],
|
|
@@ -75,7 +82,8 @@ var initialState = {
|
|
|
75
82
|
editorWidthRight: 0,
|
|
76
83
|
isResizerResizing: false,
|
|
77
84
|
isDocSizeLimitEnabled: null,
|
|
78
|
-
isPMDragging: false
|
|
85
|
+
isPMDragging: false,
|
|
86
|
+
childCount: 0
|
|
79
87
|
};
|
|
80
88
|
export var createPlugin = function createPlugin(api, getIntl) {
|
|
81
89
|
return new SafePlugin({
|
|
@@ -95,14 +103,15 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
95
103
|
editorWidthRight = currentState.editorWidthRight,
|
|
96
104
|
isResizerResizing = currentState.isResizerResizing,
|
|
97
105
|
isDragging = currentState.isDragging,
|
|
98
|
-
isPMDragging = currentState.isPMDragging
|
|
106
|
+
isPMDragging = currentState.isPMDragging,
|
|
107
|
+
childCount = currentState.childCount;
|
|
99
108
|
var activeNodeWithNewNodeType = null;
|
|
100
109
|
var meta = tr.getMeta(key);
|
|
101
|
-
|
|
110
|
+
var newChildCount = tr.docChanged && fg('platform_editor_elements_dnd_nested') ? getDocChildrenCount(newState) : childCount;
|
|
102
111
|
// If tables or media are being resized, we want to hide the drag handle
|
|
103
112
|
var resizerMeta = tr.getMeta('is-resizer-resizing');
|
|
104
113
|
isResizerResizing = resizerMeta !== null && resizerMeta !== void 0 ? resizerMeta : isResizerResizing;
|
|
105
|
-
var nodeCountChanged = oldState.doc.childCount !== newState.doc.childCount;
|
|
114
|
+
var nodeCountChanged = fg('platform_editor_elements_dnd_nested') ? childCount !== newChildCount : oldState.doc.childCount !== newState.doc.childCount;
|
|
106
115
|
var shouldRemoveHandle = !tr.getMeta('isRemote');
|
|
107
116
|
|
|
108
117
|
// During resize, remove the drag handle widget so its dom positioning doesn't need to be maintained
|
|
@@ -122,20 +131,26 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
122
131
|
var spec = _ref6.spec;
|
|
123
132
|
return spec.id === 'drag-handle';
|
|
124
133
|
});
|
|
125
|
-
var decsLength = decorations.find().filter(function (_ref7) {
|
|
134
|
+
var decsLength = fg('platform_editor_elements_dnd_nested') ? decorations.find().filter(function (_ref7) {
|
|
126
135
|
var spec = _ref7.spec;
|
|
136
|
+
return spec.type === 'node-decoration';
|
|
137
|
+
}).length : decorations.find().filter(function (_ref8) {
|
|
138
|
+
var spec = _ref8.spec;
|
|
127
139
|
return spec.id !== 'drag-handle';
|
|
128
140
|
}).length;
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
141
|
+
var newNodeDecs;
|
|
142
|
+
if (fg('platform_editor_elements_dnd_nested')) {
|
|
143
|
+
// naive solution while we work on performance optimised approach under ED-24503
|
|
144
|
+
newNodeDecs = nodeDecorations(newState);
|
|
145
|
+
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newNodeDecs.length;
|
|
146
|
+
} else {
|
|
132
147
|
isDecsMissing = !(isDragging || meta !== null && meta !== void 0 && meta.isDragging) && decsLength !== newState.doc.childCount;
|
|
133
148
|
}
|
|
134
149
|
var dropTargetLen = decorations.find(undefined, undefined, function (spec) {
|
|
135
150
|
return spec.type === 'drop-target-decoration';
|
|
136
151
|
}).length;
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
var _getIntl = getIntl(),
|
|
153
|
+
formatMessage = _getIntl.formatMessage;
|
|
139
154
|
if (!fg('platform_editor_elements_dnd_nested')) {
|
|
140
155
|
isDropTargetsMissing = isDragging && (meta === null || meta === void 0 ? void 0 : meta.isDragging) !== false && dropTargetLen !== newState.doc.childCount + 1;
|
|
141
156
|
}
|
|
@@ -151,17 +166,16 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
151
166
|
// The activeNode is from the previous rendering cycle, and verify if they share the same anchor.
|
|
152
167
|
var maybeNodeWidthUpdated = (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);
|
|
153
168
|
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 || nodeCountChanged || maybeNodeWidthUpdated || resizerMeta === false || isDecsMissing || !!(meta !== null && meta !== void 0 && meta.nodeMoved) && tr.docChanged;
|
|
154
|
-
var _getIntl = getIntl(),
|
|
155
|
-
formatMessage = _getIntl.formatMessage;
|
|
156
169
|
|
|
157
170
|
// Draw node and mouseWrapper decorations at top level node if decorations is empty, editor height changes or node is moved
|
|
158
171
|
if (redrawDecorations && !isResizerResizing && api) {
|
|
172
|
+
var _newNodeDecs;
|
|
159
173
|
var oldNodeDecs = decorations.find(undefined, undefined, function (spec) {
|
|
160
174
|
return spec.type !== 'drop-target-decoration';
|
|
161
175
|
});
|
|
162
176
|
decorations = decorations.remove(oldNodeDecs);
|
|
163
|
-
|
|
164
|
-
decorations = decorations.add(newState.doc, _toConsumableArray(
|
|
177
|
+
newNodeDecs = (_newNodeDecs = newNodeDecs) !== null && _newNodeDecs !== void 0 ? _newNodeDecs : nodeDecorations(newState);
|
|
178
|
+
decorations = decorations.add(newState.doc, _toConsumableArray(newNodeDecs));
|
|
165
179
|
|
|
166
180
|
// Note: Quite often the handle is not in the right position after a node is moved
|
|
167
181
|
// it is safer for now to not show it when a node is moved
|
|
@@ -240,9 +254,9 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
240
254
|
|
|
241
255
|
//Map drop target decoration positions when the document changes
|
|
242
256
|
if (shouldMapDropTargets) {
|
|
243
|
-
decorationState = decorationState.map(function (
|
|
244
|
-
var id =
|
|
245
|
-
pos =
|
|
257
|
+
decorationState = decorationState.map(function (_ref9) {
|
|
258
|
+
var id = _ref9.id,
|
|
259
|
+
pos = _ref9.pos;
|
|
246
260
|
return {
|
|
247
261
|
id: id,
|
|
248
262
|
pos: tr.mapping.map(pos)
|
|
@@ -254,9 +268,9 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
254
268
|
if (shouldMapDropTargets || tr.docChanged && !redrawDecorations) {
|
|
255
269
|
decorations = decorations.map(tr.mapping, tr.doc);
|
|
256
270
|
}
|
|
257
|
-
var isEmptyDoc = newState.doc.childCount === 1 && newState.doc.nodeSize <= 4;
|
|
258
|
-
var hasNodeDecoration = decorations.find().some(function (
|
|
259
|
-
var spec =
|
|
271
|
+
var isEmptyDoc = fg('platform_editor_elements_dnd_nested') ? 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;
|
|
272
|
+
var hasNodeDecoration = decorations.find().some(function (_ref10) {
|
|
273
|
+
var spec = _ref10.spec;
|
|
260
274
|
return spec.type === 'node-decoration';
|
|
261
275
|
});
|
|
262
276
|
if (!hasNodeDecoration && isEmptyDoc) {
|
|
@@ -280,7 +294,8 @@ export var createPlugin = function createPlugin(api, getIntl) {
|
|
|
280
294
|
editorWidthRight: (_meta$editorWidthRigh = meta === null || meta === void 0 ? void 0 : meta.editorWidthRight) !== null && _meta$editorWidthRigh !== void 0 ? _meta$editorWidthRigh : currentState.editorWidthRight,
|
|
281
295
|
isResizerResizing: isResizerResizing,
|
|
282
296
|
isDocSizeLimitEnabled: initialState.isDocSizeLimitEnabled,
|
|
283
|
-
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging
|
|
297
|
+
isPMDragging: (_meta$isPMDragging = meta === null || meta === void 0 ? void 0 : meta.isPMDragging) !== null && _meta$isPMDragging !== void 0 ? _meta$isPMDragging : isPMDragging,
|
|
298
|
+
childCount: newChildCount
|
|
284
299
|
};
|
|
285
300
|
}
|
|
286
301
|
},
|
|
@@ -6,6 +6,9 @@ export var isInsideTable = function isInsideTable(nodeType) {
|
|
|
6
6
|
tableHeader = _nodeType$schema$node.tableHeader;
|
|
7
7
|
return [tableCell, tableHeader].indexOf(nodeType) >= 0;
|
|
8
8
|
};
|
|
9
|
+
export var isLayoutColumn = function isLayoutColumn(nodeType) {
|
|
10
|
+
return nodeType === nodeType.schema.nodes.layoutColumn;
|
|
11
|
+
};
|
|
9
12
|
export var isDoc = function isDoc(nodeType) {
|
|
10
13
|
return nodeType === nodeType.schema.nodes.doc;
|
|
11
14
|
};
|
|
@@ -65,7 +68,7 @@ export function canMoveNodeToIndex(destParent, indexIntoParent, srcNode) {
|
|
|
65
68
|
} else {
|
|
66
69
|
return false;
|
|
67
70
|
}
|
|
68
|
-
} else if (isDoc(destParent.type) && isNestedExpand(srcNodeType)) {
|
|
71
|
+
} else if ((isDoc(destParent.type) || isLayoutColumn(destParent.type)) && isNestedExpand(srcNodeType)) {
|
|
69
72
|
srcNodeType = srcNodeType.schema.nodes.expand;
|
|
70
73
|
}
|
|
71
74
|
return destParent.canReplaceWith(indexIntoParent, indexIntoParent, srcNodeType);
|
package/dist/types/types.d.ts
CHANGED
|
@@ -32,6 +32,7 @@ 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;
|
|
35
36
|
}
|
|
36
37
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
37
38
|
export type BlockControlsSharedState = {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
export declare const isInsideTable: (nodeType: NodeType) => Boolean;
|
|
4
|
+
export declare const isLayoutColumn: (nodeType: NodeType) => Boolean;
|
|
4
5
|
export declare const isDoc: (nodeType: NodeType) => Boolean;
|
|
5
6
|
export declare const isExpand: (nodeType: NodeType) => Boolean;
|
|
6
7
|
export declare const isNestedExpand: (nodeType: NodeType) => Boolean;
|
|
@@ -32,6 +32,7 @@ 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;
|
|
35
36
|
}
|
|
36
37
|
export type ReleaseHiddenDecoration = () => boolean | undefined;
|
|
37
38
|
export type BlockControlsSharedState = {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { Slice } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { NodeType, Node as PMNode } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
export declare const isInsideTable: (nodeType: NodeType) => Boolean;
|
|
4
|
+
export declare const isLayoutColumn: (nodeType: NodeType) => Boolean;
|
|
4
5
|
export declare const isDoc: (nodeType: NodeType) => Boolean;
|
|
5
6
|
export declare const isExpand: (nodeType: NodeType) => Boolean;
|
|
6
7
|
export declare const isNestedExpand: (nodeType: NodeType) => Boolean;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-block-controls",
|
|
3
|
-
"version": "1.12.
|
|
3
|
+
"version": "1.12.1",
|
|
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
|
".": "./src/index.ts"
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
|
-
"@atlaskit/editor-common": "^87.
|
|
34
|
+
"@atlaskit/editor-common": "^87.12.0",
|
|
35
35
|
"@atlaskit/editor-plugin-accessibility-utils": "^1.2.0",
|
|
36
36
|
"@atlaskit/editor-plugin-analytics": "^1.7.0",
|
|
37
37
|
"@atlaskit/editor-plugin-editor-disabled": "^1.2.0",
|