@atlaskit/editor-plugin-synced-block 5.3.23 → 5.3.24
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 +8 -0
- package/dist/cjs/pm-plugins/main.js +42 -13
- package/dist/cjs/pm-plugins/utils/utils.js +85 -1
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/ui/Flag.js +5 -1
- package/dist/es2019/pm-plugins/main.js +35 -5
- package/dist/es2019/pm-plugins/utils/utils.js +85 -1
- package/dist/es2019/types/index.js +1 -0
- package/dist/es2019/ui/Flag.js +5 -0
- package/dist/esm/pm-plugins/main.js +43 -14
- package/dist/esm/pm-plugins/utils/utils.js +85 -1
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/ui/Flag.js +5 -1
- package/dist/types/pm-plugins/utils/utils.d.ts +6 -1
- package/dist/types/types/index.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/utils/utils.d.ts +6 -1
- package/dist/types-ts4.5/types/index.d.ts +2 -1
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-synced-block
|
|
2
2
|
|
|
3
|
+
## 5.3.24
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`3a0ebffbfb871`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3a0ebffbfb871) -
|
|
8
|
+
[ux] Add flag message for when inline extensions added to synced block
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 5.3.23
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -78,6 +78,31 @@ var showCopiedFlag = function showCopiedFlag(api) {
|
|
|
78
78
|
});
|
|
79
79
|
}, 0);
|
|
80
80
|
};
|
|
81
|
+
var showInlineExtensionInSyncBlockWarningIfNeeded = function showInlineExtensionInSyncBlockWarningIfNeeded(tr, state, api, inlineExtensionFlagShown) {
|
|
82
|
+
var _api$connectivity;
|
|
83
|
+
if (!(0, _platformFeatureFlags.fg)('platform_synced_block_patch_3')) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!tr.docChanged || tr.getMeta('isRemote') || Boolean(tr.getMeta(_utils.pmHistoryPluginKey)) || (0, _editorPluginConnectivity.isOfflineMode)(api === null || api === void 0 || (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.sharedState.currentState()) === null || _api$connectivity === void 0 ? void 0 : _api$connectivity.mode)) {
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
var resourceId = (0, _utils2.wasInlineExtensionInsertedInBodiedSyncBlock)(tr, state);
|
|
90
|
+
// Only show the flag on the first instance per sync block (same as UNPUBLISHED_SYNC_BLOCK_PASTED)
|
|
91
|
+
if (resourceId && !inlineExtensionFlagShown.has(resourceId)) {
|
|
92
|
+
inlineExtensionFlagShown.add(resourceId);
|
|
93
|
+
// Use setTimeout to dispatch in next tick and avoid re-entrant dispatch from filterTransaction
|
|
94
|
+
setTimeout(function () {
|
|
95
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
|
|
96
|
+
var tr = _ref2.tr;
|
|
97
|
+
return tr.setMeta(syncedBlockPluginKey, {
|
|
98
|
+
activeFlag: {
|
|
99
|
+
id: _types.FLAG_ID.INLINE_EXTENSION_IN_SYNC_BLOCK
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
}, 0);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
81
106
|
var getDeleteReason = function getDeleteReason(tr) {
|
|
82
107
|
var reason = tr.getMeta('deletionReason');
|
|
83
108
|
if (!reason) {
|
|
@@ -86,9 +111,9 @@ var getDeleteReason = function getDeleteReason(tr) {
|
|
|
86
111
|
return reason;
|
|
87
112
|
};
|
|
88
113
|
var createPlugin = exports.createPlugin = function createPlugin(options, pmPluginFactoryParams, syncBlockStore, api) {
|
|
89
|
-
var
|
|
90
|
-
|
|
91
|
-
useLongPressSelection =
|
|
114
|
+
var _ref3 = options || {},
|
|
115
|
+
_ref3$useLongPressSel = _ref3.useLongPressSelection,
|
|
116
|
+
useLongPressSelection = _ref3$useLongPressSel === void 0 ? false : _ref3$useLongPressSel;
|
|
92
117
|
var confirmationTransactionRef = {
|
|
93
118
|
current: undefined
|
|
94
119
|
};
|
|
@@ -96,6 +121,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
96
121
|
var isCopyEvent = false;
|
|
97
122
|
// Track which sync blocks have already triggered the unpublished flag
|
|
98
123
|
var unpublishedFlagShown = new Set();
|
|
124
|
+
// Track which sync blocks have already triggered the inline extension in sync block flag
|
|
125
|
+
var inlineExtensionFlagShown = new Set();
|
|
99
126
|
|
|
100
127
|
// Set up callback to detect unpublished sync blocks when they're fetched
|
|
101
128
|
syncBlockStore.referenceManager.setOnUnpublishedSyncBlockDetected(function (resourceId) {
|
|
@@ -104,8 +131,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
104
131
|
unpublishedFlagShown.add(resourceId);
|
|
105
132
|
// Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
|
|
106
133
|
setTimeout(function () {
|
|
107
|
-
api === null || api === void 0 || api.core.actions.execute(function (
|
|
108
|
-
var tr =
|
|
134
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
|
|
135
|
+
var tr = _ref4.tr;
|
|
109
136
|
return tr.setMeta(syncedBlockPluginKey, {
|
|
110
137
|
activeFlag: {
|
|
111
138
|
id: _types.FLAG_ID.UNPUBLISHED_SYNC_BLOCK_PASTED
|
|
@@ -177,12 +204,12 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
177
204
|
})
|
|
178
205
|
},
|
|
179
206
|
decorations: function decorations(state) {
|
|
180
|
-
var _currentPluginState$s, _api$
|
|
207
|
+
var _currentPluginState$s, _api$connectivity2, _api$editorViewMode;
|
|
181
208
|
var currentPluginState = syncedBlockPluginKey.getState(state);
|
|
182
209
|
var selectionDecorationSet = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.selectionDecorationSet) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : _view.DecorationSet.empty;
|
|
183
210
|
var syncBlockStore = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.syncBlockStore;
|
|
184
211
|
var doc = state.doc;
|
|
185
|
-
var isOffline = (0, _editorPluginConnectivity.isOfflineMode)(api === null || api === void 0 || (_api$
|
|
212
|
+
var isOffline = (0, _editorPluginConnectivity.isOfflineMode)(api === null || api === void 0 || (_api$connectivity2 = api.connectivity) === null || _api$connectivity2 === void 0 || (_api$connectivity2 = _api$connectivity2.sharedState.currentState()) === null || _api$connectivity2 === void 0 ? void 0 : _api$connectivity2.mode);
|
|
186
213
|
var isViewMode = (api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode) === 'view';
|
|
187
214
|
var offlineDecorations = [];
|
|
188
215
|
var viewModeDecorations = [];
|
|
@@ -223,8 +250,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
223
250
|
return false;
|
|
224
251
|
}
|
|
225
252
|
},
|
|
226
|
-
transformCopied: function transformCopied(slice,
|
|
227
|
-
var state =
|
|
253
|
+
transformCopied: function transformCopied(slice, _ref5) {
|
|
254
|
+
var state = _ref5.state;
|
|
228
255
|
var pluginState = syncedBlockPluginKey.getState(state);
|
|
229
256
|
var syncBlockStore = pluginState === null || pluginState === void 0 ? void 0 : pluginState.syncBlockStore;
|
|
230
257
|
var schema = state.schema;
|
|
@@ -262,8 +289,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
262
289
|
}
|
|
263
290
|
},
|
|
264
291
|
filterTransaction: function filterTransaction(tr, state) {
|
|
265
|
-
var _api$
|
|
266
|
-
var isOffline = (0, _editorPluginConnectivity.isOfflineMode)(api === null || api === void 0 || (_api$
|
|
292
|
+
var _api$connectivity3;
|
|
293
|
+
var isOffline = (0, _editorPluginConnectivity.isOfflineMode)(api === null || api === void 0 || (_api$connectivity3 = api.connectivity) === null || _api$connectivity3 === void 0 || (_api$connectivity3 = _api$connectivity3.sharedState.currentState()) === null || _api$connectivity3 === void 0 ? void 0 : _api$connectivity3.mode);
|
|
267
294
|
var isConfirmedSyncBlockDeletion = Boolean(tr.getMeta('isConfirmedSyncBlockDeletion'));
|
|
268
295
|
|
|
269
296
|
// Track newly added reference sync blocks before processing the transaction
|
|
@@ -351,6 +378,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
351
378
|
(0, _handleBodiedSyncBlockCreation.handleBodiedSyncBlockCreation)(bodiedSyncBlockAdded, state, api);
|
|
352
379
|
return true;
|
|
353
380
|
}
|
|
381
|
+
showInlineExtensionInSyncBlockWarningIfNeeded(tr, state, api, inlineExtensionFlagShown);
|
|
382
|
+
return true;
|
|
354
383
|
} else {
|
|
355
384
|
var _trackSyncBlocks4 = (0, _trackSyncBlocks6.trackSyncBlocks)(function (node) {
|
|
356
385
|
return node.type.name === 'syncBlock';
|
|
@@ -370,8 +399,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
370
399
|
if (errorFlag) {
|
|
371
400
|
// Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
|
|
372
401
|
setTimeout(function () {
|
|
373
|
-
api === null || api === void 0 || api.core.actions.execute(function (
|
|
374
|
-
var tr =
|
|
402
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref6) {
|
|
403
|
+
var tr = _ref6.tr;
|
|
375
404
|
return tr.setMeta(syncedBlockPluginKey, {
|
|
376
405
|
activeFlag: {
|
|
377
406
|
id: errorFlag
|
|
@@ -3,9 +3,10 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.sliceFullyContainsNode = exports.isBodiedSyncBlockNode = exports.findSyncBlockOrBodiedSyncBlock = exports.findSyncBlock = exports.findBodiedSyncBlock = exports.canBeConvertedToSyncBlock = void 0;
|
|
6
|
+
exports.wasInlineExtensionInsertedInBodiedSyncBlock = exports.sliceFullyContainsNode = exports.isBodiedSyncBlockNode = exports.findSyncBlockOrBodiedSyncBlock = exports.findSyncBlock = exports.findBodiedSyncBlock = exports.canBeConvertedToSyncBlock = void 0;
|
|
7
7
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
8
8
|
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
9
|
+
var _transform = require("@atlaskit/editor-prosemirror/transform");
|
|
9
10
|
var _utils = require("@atlaskit/editor-prosemirror/utils");
|
|
10
11
|
var findSyncBlock = exports.findSyncBlock = function findSyncBlock(schema, selection) {
|
|
11
12
|
var syncBlock = schema.nodes.syncBlock;
|
|
@@ -83,4 +84,87 @@ var sliceFullyContainsNode = exports.sliceFullyContainsNode = function sliceFull
|
|
|
83
84
|
return false;
|
|
84
85
|
}
|
|
85
86
|
return true;
|
|
87
|
+
};
|
|
88
|
+
var _fragmentContainsInlineExtension = function fragmentContainsInlineExtension(fragment) {
|
|
89
|
+
var found = false;
|
|
90
|
+
fragment.forEach(function (node) {
|
|
91
|
+
if (found) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
if (node.type.name === 'inlineExtension') {
|
|
95
|
+
found = true;
|
|
96
|
+
} else if (node.content.size) {
|
|
97
|
+
if (_fragmentContainsInlineExtension(node.content)) {
|
|
98
|
+
found = true;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
return found;
|
|
103
|
+
};
|
|
104
|
+
var sliceContainsInlineExtension = function sliceContainsInlineExtension(slice) {
|
|
105
|
+
return _fragmentContainsInlineExtension(slice.content);
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Returns the resourceId of the bodied sync block where an inline extension was inserted, or undefined.
|
|
110
|
+
* Used to show a warning flag only on the first instance per sync block.
|
|
111
|
+
*/
|
|
112
|
+
var wasInlineExtensionInsertedInBodiedSyncBlock = exports.wasInlineExtensionInsertedInBodiedSyncBlock = function wasInlineExtensionInsertedInBodiedSyncBlock(tr, state) {
|
|
113
|
+
if (!tr.docChanged || tr.getMeta('isRemote')) {
|
|
114
|
+
return undefined;
|
|
115
|
+
}
|
|
116
|
+
var bodiedSyncBlock = state.schema.nodes.bodiedSyncBlock;
|
|
117
|
+
if (!bodiedSyncBlock) {
|
|
118
|
+
return undefined;
|
|
119
|
+
}
|
|
120
|
+
var docs = tr.docs;
|
|
121
|
+
|
|
122
|
+
// When docs is available (e.g. from history plugin), check each replace step
|
|
123
|
+
if (docs && docs.length > 0) {
|
|
124
|
+
for (var i = 0; i < tr.steps.length; i++) {
|
|
125
|
+
var _docs;
|
|
126
|
+
var step = tr.steps[i];
|
|
127
|
+
var isReplaceStep = step instanceof _transform.ReplaceStep || step instanceof _transform.ReplaceAroundStep;
|
|
128
|
+
if (!isReplaceStep || !('slice' in step) || !('from' in step)) {
|
|
129
|
+
continue;
|
|
130
|
+
}
|
|
131
|
+
var replaceStep = step;
|
|
132
|
+
if (!sliceContainsInlineExtension(replaceStep.slice)) {
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
var docAfterStep = (_docs = docs[i + 1]) !== null && _docs !== void 0 ? _docs : tr.doc;
|
|
136
|
+
try {
|
|
137
|
+
var $pos = docAfterStep.resolve(replaceStep.from);
|
|
138
|
+
var parent = (0, _utils.findParentNodeOfTypeClosestToPos)($pos, bodiedSyncBlock);
|
|
139
|
+
if (parent !== null && parent !== void 0 && parent.node.attrs.resourceId) {
|
|
140
|
+
return parent.node.attrs.resourceId;
|
|
141
|
+
}
|
|
142
|
+
} catch (_unused) {
|
|
143
|
+
// resolve() can throw if position is invalid
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
return undefined;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// Fallback: scan final doc for inline extensions inside bodied sync block that were added
|
|
150
|
+
var resourceId;
|
|
151
|
+
tr.doc.descendants(function (node, pos) {
|
|
152
|
+
if (resourceId !== undefined) {
|
|
153
|
+
return false;
|
|
154
|
+
}
|
|
155
|
+
if (node.type.name === 'inlineExtension') {
|
|
156
|
+
var _$pos = tr.doc.resolve(pos);
|
|
157
|
+
var _parent = (0, _utils.findParentNodeOfTypeClosestToPos)(_$pos, bodiedSyncBlock);
|
|
158
|
+
if (_parent !== null && _parent !== void 0 && _parent.node.attrs.resourceId) {
|
|
159
|
+
var mappedPos = tr.mapping.invert().map(pos);
|
|
160
|
+
var nodeBefore = state.doc.nodeAt(mappedPos);
|
|
161
|
+
if (!nodeBefore || nodeBefore.type.name !== 'inlineExtension') {
|
|
162
|
+
resourceId = _parent.node.attrs.resourceId;
|
|
163
|
+
return false;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return true;
|
|
168
|
+
});
|
|
169
|
+
return resourceId;
|
|
86
170
|
};
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -12,6 +12,7 @@ var FLAG_ID = exports.FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
|
|
|
12
12
|
FLAG_ID["SYNC_BLOCK_COPIED"] = "sync-block-copied";
|
|
13
13
|
FLAG_ID["UNPUBLISHED_SYNC_BLOCK_PASTED"] = "unpublished-sync-block-pasted";
|
|
14
14
|
FLAG_ID["CANNOT_CREATE_SYNC_BLOCK"] = "cannot-create-sync-block";
|
|
15
|
+
FLAG_ID["INLINE_EXTENSION_IN_SYNC_BLOCK"] = "inline-extension-in-sync-block";
|
|
15
16
|
return FLAG_ID;
|
|
16
17
|
}({});
|
|
17
18
|
var SYNCED_BLOCK_BUTTON_TEST_ID = exports.SYNCED_BLOCK_BUTTON_TEST_ID = {
|
package/dist/cjs/ui/Flag.js
CHANGED
|
@@ -20,7 +20,7 @@ var _types = require("../types");
|
|
|
20
20
|
function _interopRequireWildcard(e, t) { if ("function" == typeof WeakMap) var r = new WeakMap(), n = new WeakMap(); return (_interopRequireWildcard = function _interopRequireWildcard(e, t) { if (!t && e && e.__esModule) return e; var o, i, f = { __proto__: null, default: e }; if (null === e || "object" != _typeof(e) && "function" != typeof e) return f; if (o = t ? n : r) { if (o.has(e)) return o.get(e); o.set(e, f); } for (var _t in e) "default" !== _t && {}.hasOwnProperty.call(e, _t) && ((i = (o = Object.defineProperty) && Object.getOwnPropertyDescriptor(e, _t)) && (i.get || i.set) ? o(f, _t, i) : f[_t] = e[_t]); return f; })(e, t); }
|
|
21
21
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
22
22
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
23
|
-
var flagMap = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _types.FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE, {
|
|
23
|
+
var flagMap = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)((0, _defineProperty2.default)({}, _types.FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE, {
|
|
24
24
|
title: _messages.syncBlockMessages.failToDeleteTitle,
|
|
25
25
|
description: _messages.syncBlockMessages.failToDeleteWhenOfflineDescription,
|
|
26
26
|
type: 'error'
|
|
@@ -47,6 +47,10 @@ var flagMap = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _d
|
|
|
47
47
|
title: _messages.syncBlockMessages.cannotCreateSyncBlockTitle,
|
|
48
48
|
description: _messages.syncBlockMessages.CannotCreateSyncBlockDescription,
|
|
49
49
|
type: 'error'
|
|
50
|
+
}), _types.FLAG_ID.INLINE_EXTENSION_IN_SYNC_BLOCK, {
|
|
51
|
+
title: _messages.syncBlockMessages.inlineExtensionInSyncBlockTitle,
|
|
52
|
+
description: _messages.syncBlockMessages.inlineExtensionInSyncBlockDescription,
|
|
53
|
+
type: 'error'
|
|
50
54
|
});
|
|
51
55
|
var Flag = exports.Flag = function Flag(_ref) {
|
|
52
56
|
var api = _ref.api;
|
|
@@ -16,7 +16,7 @@ import { handleBodiedSyncBlockRemoval } from './utils/handle-bodied-sync-block-r
|
|
|
16
16
|
import { shouldIgnoreDomEvent } from './utils/ignore-dom-event';
|
|
17
17
|
import { calculateDecorations } from './utils/selection-decorations';
|
|
18
18
|
import { hasEditInSyncBlock, trackSyncBlocks } from './utils/track-sync-blocks';
|
|
19
|
-
import { sliceFullyContainsNode } from './utils/utils';
|
|
19
|
+
import { wasInlineExtensionInsertedInBodiedSyncBlock, sliceFullyContainsNode } from './utils/utils';
|
|
20
20
|
export const syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
21
21
|
const mapRetryCreationPosMap = (oldMap, newRetryCreationPos, mapPos) => {
|
|
22
22
|
const resourceId = newRetryCreationPos === null || newRetryCreationPos === void 0 ? void 0 : newRetryCreationPos.resourceId;
|
|
@@ -54,6 +54,32 @@ const showCopiedFlag = api => {
|
|
|
54
54
|
});
|
|
55
55
|
}, 0);
|
|
56
56
|
};
|
|
57
|
+
const showInlineExtensionInSyncBlockWarningIfNeeded = (tr, state, api, inlineExtensionFlagShown) => {
|
|
58
|
+
var _api$connectivity, _api$connectivity$sha;
|
|
59
|
+
if (!fg('platform_synced_block_patch_3')) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
if (!tr.docChanged || tr.getMeta('isRemote') || Boolean(tr.getMeta(pmHistoryPluginKey)) || isOfflineMode(api === null || api === void 0 ? void 0 : (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 ? void 0 : (_api$connectivity$sha = _api$connectivity.sharedState.currentState()) === null || _api$connectivity$sha === void 0 ? void 0 : _api$connectivity$sha.mode)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const resourceId = wasInlineExtensionInsertedInBodiedSyncBlock(tr, state);
|
|
66
|
+
// Only show the flag on the first instance per sync block (same as UNPUBLISHED_SYNC_BLOCK_PASTED)
|
|
67
|
+
if (resourceId && !inlineExtensionFlagShown.has(resourceId)) {
|
|
68
|
+
inlineExtensionFlagShown.add(resourceId);
|
|
69
|
+
// Use setTimeout to dispatch in next tick and avoid re-entrant dispatch from filterTransaction
|
|
70
|
+
setTimeout(() => {
|
|
71
|
+
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
72
|
+
tr
|
|
73
|
+
}) => {
|
|
74
|
+
return tr.setMeta(syncedBlockPluginKey, {
|
|
75
|
+
activeFlag: {
|
|
76
|
+
id: FLAG_ID.INLINE_EXTENSION_IN_SYNC_BLOCK
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
});
|
|
80
|
+
}, 0);
|
|
81
|
+
}
|
|
82
|
+
};
|
|
57
83
|
const getDeleteReason = tr => {
|
|
58
84
|
const reason = tr.getMeta('deletionReason');
|
|
59
85
|
if (!reason) {
|
|
@@ -72,6 +98,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
72
98
|
let isCopyEvent = false;
|
|
73
99
|
// Track which sync blocks have already triggered the unpublished flag
|
|
74
100
|
const unpublishedFlagShown = new Set();
|
|
101
|
+
// Track which sync blocks have already triggered the inline extension in sync block flag
|
|
102
|
+
const inlineExtensionFlagShown = new Set();
|
|
75
103
|
|
|
76
104
|
// Set up callback to detect unpublished sync blocks when they're fetched
|
|
77
105
|
syncBlockStore.referenceManager.setOnUnpublishedSyncBlockDetected(resourceId => {
|
|
@@ -154,14 +182,14 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
154
182
|
})
|
|
155
183
|
},
|
|
156
184
|
decorations: state => {
|
|
157
|
-
var _currentPluginState$s, _api$
|
|
185
|
+
var _currentPluginState$s, _api$connectivity2, _api$connectivity2$sh, _api$editorViewMode, _api$editorViewMode$s;
|
|
158
186
|
const currentPluginState = syncedBlockPluginKey.getState(state);
|
|
159
187
|
const selectionDecorationSet = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.selectionDecorationSet) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : DecorationSet.empty;
|
|
160
188
|
const syncBlockStore = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.syncBlockStore;
|
|
161
189
|
const {
|
|
162
190
|
doc
|
|
163
191
|
} = state;
|
|
164
|
-
const isOffline = isOfflineMode(api === null || api === void 0 ? void 0 : (_api$
|
|
192
|
+
const isOffline = isOfflineMode(api === null || api === void 0 ? void 0 : (_api$connectivity2 = api.connectivity) === null || _api$connectivity2 === void 0 ? void 0 : (_api$connectivity2$sh = _api$connectivity2.sharedState.currentState()) === null || _api$connectivity2$sh === void 0 ? void 0 : _api$connectivity2$sh.mode);
|
|
165
193
|
const isViewMode = (api === null || api === void 0 ? void 0 : (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 ? void 0 : (_api$editorViewMode$s = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode$s === void 0 ? void 0 : _api$editorViewMode$s.mode) === 'view';
|
|
166
194
|
const offlineDecorations = [];
|
|
167
195
|
const viewModeDecorations = [];
|
|
@@ -243,8 +271,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
243
271
|
}
|
|
244
272
|
},
|
|
245
273
|
filterTransaction: (tr, state) => {
|
|
246
|
-
var _api$
|
|
247
|
-
const isOffline = isOfflineMode(api === null || api === void 0 ? void 0 : (_api$
|
|
274
|
+
var _api$connectivity3, _api$connectivity3$sh;
|
|
275
|
+
const isOffline = isOfflineMode(api === null || api === void 0 ? void 0 : (_api$connectivity3 = api.connectivity) === null || _api$connectivity3 === void 0 ? void 0 : (_api$connectivity3$sh = _api$connectivity3.sharedState.currentState()) === null || _api$connectivity3$sh === void 0 ? void 0 : _api$connectivity3$sh.mode);
|
|
248
276
|
const isConfirmedSyncBlockDeletion = Boolean(tr.getMeta('isConfirmedSyncBlockDeletion'));
|
|
249
277
|
|
|
250
278
|
// Track newly added reference sync blocks before processing the transaction
|
|
@@ -331,6 +359,8 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
331
359
|
handleBodiedSyncBlockCreation(bodiedSyncBlockAdded, state, api);
|
|
332
360
|
return true;
|
|
333
361
|
}
|
|
362
|
+
showInlineExtensionInSyncBlockWarningIfNeeded(tr, state, api, inlineExtensionFlagShown);
|
|
363
|
+
return true;
|
|
334
364
|
} else {
|
|
335
365
|
const {
|
|
336
366
|
removed: syncBlockRemoved,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import {
|
|
3
|
+
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
import { findParentNodeOfType, findParentNodeOfTypeClosestToPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
5
|
export const findSyncBlock = (schema, selection) => {
|
|
5
6
|
const {
|
|
6
7
|
syncBlock
|
|
@@ -76,4 +77,87 @@ export const sliceFullyContainsNode = (slice, node) => {
|
|
|
76
77
|
return false;
|
|
77
78
|
}
|
|
78
79
|
return true;
|
|
80
|
+
};
|
|
81
|
+
const fragmentContainsInlineExtension = fragment => {
|
|
82
|
+
let found = false;
|
|
83
|
+
fragment.forEach(node => {
|
|
84
|
+
if (found) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
if (node.type.name === 'inlineExtension') {
|
|
88
|
+
found = true;
|
|
89
|
+
} else if (node.content.size) {
|
|
90
|
+
if (fragmentContainsInlineExtension(node.content)) {
|
|
91
|
+
found = true;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
return found;
|
|
96
|
+
};
|
|
97
|
+
const sliceContainsInlineExtension = slice => fragmentContainsInlineExtension(slice.content);
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* Returns the resourceId of the bodied sync block where an inline extension was inserted, or undefined.
|
|
101
|
+
* Used to show a warning flag only on the first instance per sync block.
|
|
102
|
+
*/
|
|
103
|
+
export const wasInlineExtensionInsertedInBodiedSyncBlock = (tr, state) => {
|
|
104
|
+
if (!tr.docChanged || tr.getMeta('isRemote')) {
|
|
105
|
+
return undefined;
|
|
106
|
+
}
|
|
107
|
+
const {
|
|
108
|
+
bodiedSyncBlock
|
|
109
|
+
} = state.schema.nodes;
|
|
110
|
+
if (!bodiedSyncBlock) {
|
|
111
|
+
return undefined;
|
|
112
|
+
}
|
|
113
|
+
const docs = tr.docs;
|
|
114
|
+
|
|
115
|
+
// When docs is available (e.g. from history plugin), check each replace step
|
|
116
|
+
if (docs && docs.length > 0) {
|
|
117
|
+
for (let i = 0; i < tr.steps.length; i++) {
|
|
118
|
+
var _docs;
|
|
119
|
+
const step = tr.steps[i];
|
|
120
|
+
const isReplaceStep = step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
|
|
121
|
+
if (!isReplaceStep || !('slice' in step) || !('from' in step)) {
|
|
122
|
+
continue;
|
|
123
|
+
}
|
|
124
|
+
const replaceStep = step;
|
|
125
|
+
if (!sliceContainsInlineExtension(replaceStep.slice)) {
|
|
126
|
+
continue;
|
|
127
|
+
}
|
|
128
|
+
const docAfterStep = (_docs = docs[i + 1]) !== null && _docs !== void 0 ? _docs : tr.doc;
|
|
129
|
+
try {
|
|
130
|
+
const $pos = docAfterStep.resolve(replaceStep.from);
|
|
131
|
+
const parent = findParentNodeOfTypeClosestToPos($pos, bodiedSyncBlock);
|
|
132
|
+
if (parent !== null && parent !== void 0 && parent.node.attrs.resourceId) {
|
|
133
|
+
return parent.node.attrs.resourceId;
|
|
134
|
+
}
|
|
135
|
+
} catch {
|
|
136
|
+
// resolve() can throw if position is invalid
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
// Fallback: scan final doc for inline extensions inside bodied sync block that were added
|
|
143
|
+
let resourceId;
|
|
144
|
+
tr.doc.descendants((node, pos) => {
|
|
145
|
+
if (resourceId !== undefined) {
|
|
146
|
+
return false;
|
|
147
|
+
}
|
|
148
|
+
if (node.type.name === 'inlineExtension') {
|
|
149
|
+
const $pos = tr.doc.resolve(pos);
|
|
150
|
+
const parent = findParentNodeOfTypeClosestToPos($pos, bodiedSyncBlock);
|
|
151
|
+
if (parent !== null && parent !== void 0 && parent.node.attrs.resourceId) {
|
|
152
|
+
const mappedPos = tr.mapping.invert().map(pos);
|
|
153
|
+
const nodeBefore = state.doc.nodeAt(mappedPos);
|
|
154
|
+
if (!nodeBefore || nodeBefore.type.name !== 'inlineExtension') {
|
|
155
|
+
resourceId = parent.node.attrs.resourceId;
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
return true;
|
|
161
|
+
});
|
|
162
|
+
return resourceId;
|
|
79
163
|
};
|
|
@@ -6,6 +6,7 @@ export let FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
|
|
|
6
6
|
FLAG_ID["SYNC_BLOCK_COPIED"] = "sync-block-copied";
|
|
7
7
|
FLAG_ID["UNPUBLISHED_SYNC_BLOCK_PASTED"] = "unpublished-sync-block-pasted";
|
|
8
8
|
FLAG_ID["CANNOT_CREATE_SYNC_BLOCK"] = "cannot-create-sync-block";
|
|
9
|
+
FLAG_ID["INLINE_EXTENSION_IN_SYNC_BLOCK"] = "inline-extension-in-sync-block";
|
|
9
10
|
return FLAG_ID;
|
|
10
11
|
}({});
|
|
11
12
|
export const SYNCED_BLOCK_BUTTON_TEST_ID = {
|
package/dist/es2019/ui/Flag.js
CHANGED
|
@@ -42,6 +42,11 @@ const flagMap = {
|
|
|
42
42
|
title: messages.cannotCreateSyncBlockTitle,
|
|
43
43
|
description: messages.CannotCreateSyncBlockDescription,
|
|
44
44
|
type: 'error'
|
|
45
|
+
},
|
|
46
|
+
[FLAG_ID.INLINE_EXTENSION_IN_SYNC_BLOCK]: {
|
|
47
|
+
title: messages.inlineExtensionInSyncBlockTitle,
|
|
48
|
+
description: messages.inlineExtensionInSyncBlockDescription,
|
|
49
|
+
type: 'error'
|
|
45
50
|
}
|
|
46
51
|
};
|
|
47
52
|
export const Flag = ({
|
|
@@ -23,7 +23,7 @@ import { handleBodiedSyncBlockRemoval } from './utils/handle-bodied-sync-block-r
|
|
|
23
23
|
import { shouldIgnoreDomEvent } from './utils/ignore-dom-event';
|
|
24
24
|
import { calculateDecorations } from './utils/selection-decorations';
|
|
25
25
|
import { hasEditInSyncBlock, trackSyncBlocks } from './utils/track-sync-blocks';
|
|
26
|
-
import { sliceFullyContainsNode } from './utils/utils';
|
|
26
|
+
import { wasInlineExtensionInsertedInBodiedSyncBlock, sliceFullyContainsNode } from './utils/utils';
|
|
27
27
|
export var syncedBlockPluginKey = new PluginKey('syncedBlockPlugin');
|
|
28
28
|
var mapRetryCreationPosMap = function mapRetryCreationPosMap(oldMap, newRetryCreationPos, mapPos) {
|
|
29
29
|
var resourceId = newRetryCreationPos === null || newRetryCreationPos === void 0 ? void 0 : newRetryCreationPos.resourceId;
|
|
@@ -71,6 +71,31 @@ var showCopiedFlag = function showCopiedFlag(api) {
|
|
|
71
71
|
});
|
|
72
72
|
}, 0);
|
|
73
73
|
};
|
|
74
|
+
var showInlineExtensionInSyncBlockWarningIfNeeded = function showInlineExtensionInSyncBlockWarningIfNeeded(tr, state, api, inlineExtensionFlagShown) {
|
|
75
|
+
var _api$connectivity;
|
|
76
|
+
if (!fg('platform_synced_block_patch_3')) {
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
if (!tr.docChanged || tr.getMeta('isRemote') || Boolean(tr.getMeta(pmHistoryPluginKey)) || isOfflineMode(api === null || api === void 0 || (_api$connectivity = api.connectivity) === null || _api$connectivity === void 0 || (_api$connectivity = _api$connectivity.sharedState.currentState()) === null || _api$connectivity === void 0 ? void 0 : _api$connectivity.mode)) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
var resourceId = wasInlineExtensionInsertedInBodiedSyncBlock(tr, state);
|
|
83
|
+
// Only show the flag on the first instance per sync block (same as UNPUBLISHED_SYNC_BLOCK_PASTED)
|
|
84
|
+
if (resourceId && !inlineExtensionFlagShown.has(resourceId)) {
|
|
85
|
+
inlineExtensionFlagShown.add(resourceId);
|
|
86
|
+
// Use setTimeout to dispatch in next tick and avoid re-entrant dispatch from filterTransaction
|
|
87
|
+
setTimeout(function () {
|
|
88
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref2) {
|
|
89
|
+
var tr = _ref2.tr;
|
|
90
|
+
return tr.setMeta(syncedBlockPluginKey, {
|
|
91
|
+
activeFlag: {
|
|
92
|
+
id: FLAG_ID.INLINE_EXTENSION_IN_SYNC_BLOCK
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
});
|
|
96
|
+
}, 0);
|
|
97
|
+
}
|
|
98
|
+
};
|
|
74
99
|
var getDeleteReason = function getDeleteReason(tr) {
|
|
75
100
|
var reason = tr.getMeta('deletionReason');
|
|
76
101
|
if (!reason) {
|
|
@@ -79,9 +104,9 @@ var getDeleteReason = function getDeleteReason(tr) {
|
|
|
79
104
|
return reason;
|
|
80
105
|
};
|
|
81
106
|
export var createPlugin = function createPlugin(options, pmPluginFactoryParams, syncBlockStore, api) {
|
|
82
|
-
var
|
|
83
|
-
|
|
84
|
-
useLongPressSelection =
|
|
107
|
+
var _ref3 = options || {},
|
|
108
|
+
_ref3$useLongPressSel = _ref3.useLongPressSelection,
|
|
109
|
+
useLongPressSelection = _ref3$useLongPressSel === void 0 ? false : _ref3$useLongPressSel;
|
|
85
110
|
var confirmationTransactionRef = {
|
|
86
111
|
current: undefined
|
|
87
112
|
};
|
|
@@ -89,6 +114,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
89
114
|
var isCopyEvent = false;
|
|
90
115
|
// Track which sync blocks have already triggered the unpublished flag
|
|
91
116
|
var unpublishedFlagShown = new Set();
|
|
117
|
+
// Track which sync blocks have already triggered the inline extension in sync block flag
|
|
118
|
+
var inlineExtensionFlagShown = new Set();
|
|
92
119
|
|
|
93
120
|
// Set up callback to detect unpublished sync blocks when they're fetched
|
|
94
121
|
syncBlockStore.referenceManager.setOnUnpublishedSyncBlockDetected(function (resourceId) {
|
|
@@ -97,8 +124,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
97
124
|
unpublishedFlagShown.add(resourceId);
|
|
98
125
|
// Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
|
|
99
126
|
setTimeout(function () {
|
|
100
|
-
api === null || api === void 0 || api.core.actions.execute(function (
|
|
101
|
-
var tr =
|
|
127
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref4) {
|
|
128
|
+
var tr = _ref4.tr;
|
|
102
129
|
return tr.setMeta(syncedBlockPluginKey, {
|
|
103
130
|
activeFlag: {
|
|
104
131
|
id: FLAG_ID.UNPUBLISHED_SYNC_BLOCK_PASTED
|
|
@@ -170,12 +197,12 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
170
197
|
})
|
|
171
198
|
},
|
|
172
199
|
decorations: function decorations(state) {
|
|
173
|
-
var _currentPluginState$s, _api$
|
|
200
|
+
var _currentPluginState$s, _api$connectivity2, _api$editorViewMode;
|
|
174
201
|
var currentPluginState = syncedBlockPluginKey.getState(state);
|
|
175
202
|
var selectionDecorationSet = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.selectionDecorationSet) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : DecorationSet.empty;
|
|
176
203
|
var syncBlockStore = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.syncBlockStore;
|
|
177
204
|
var doc = state.doc;
|
|
178
|
-
var isOffline = isOfflineMode(api === null || api === void 0 || (_api$
|
|
205
|
+
var isOffline = isOfflineMode(api === null || api === void 0 || (_api$connectivity2 = api.connectivity) === null || _api$connectivity2 === void 0 || (_api$connectivity2 = _api$connectivity2.sharedState.currentState()) === null || _api$connectivity2 === void 0 ? void 0 : _api$connectivity2.mode);
|
|
179
206
|
var isViewMode = (api === null || api === void 0 || (_api$editorViewMode = api.editorViewMode) === null || _api$editorViewMode === void 0 || (_api$editorViewMode = _api$editorViewMode.sharedState.currentState()) === null || _api$editorViewMode === void 0 ? void 0 : _api$editorViewMode.mode) === 'view';
|
|
180
207
|
var offlineDecorations = [];
|
|
181
208
|
var viewModeDecorations = [];
|
|
@@ -216,8 +243,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
216
243
|
return false;
|
|
217
244
|
}
|
|
218
245
|
},
|
|
219
|
-
transformCopied: function transformCopied(slice,
|
|
220
|
-
var state =
|
|
246
|
+
transformCopied: function transformCopied(slice, _ref5) {
|
|
247
|
+
var state = _ref5.state;
|
|
221
248
|
var pluginState = syncedBlockPluginKey.getState(state);
|
|
222
249
|
var syncBlockStore = pluginState === null || pluginState === void 0 ? void 0 : pluginState.syncBlockStore;
|
|
223
250
|
var schema = state.schema;
|
|
@@ -255,8 +282,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
255
282
|
}
|
|
256
283
|
},
|
|
257
284
|
filterTransaction: function filterTransaction(tr, state) {
|
|
258
|
-
var _api$
|
|
259
|
-
var isOffline = isOfflineMode(api === null || api === void 0 || (_api$
|
|
285
|
+
var _api$connectivity3;
|
|
286
|
+
var isOffline = isOfflineMode(api === null || api === void 0 || (_api$connectivity3 = api.connectivity) === null || _api$connectivity3 === void 0 || (_api$connectivity3 = _api$connectivity3.sharedState.currentState()) === null || _api$connectivity3 === void 0 ? void 0 : _api$connectivity3.mode);
|
|
260
287
|
var isConfirmedSyncBlockDeletion = Boolean(tr.getMeta('isConfirmedSyncBlockDeletion'));
|
|
261
288
|
|
|
262
289
|
// Track newly added reference sync blocks before processing the transaction
|
|
@@ -344,6 +371,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
344
371
|
handleBodiedSyncBlockCreation(bodiedSyncBlockAdded, state, api);
|
|
345
372
|
return true;
|
|
346
373
|
}
|
|
374
|
+
showInlineExtensionInSyncBlockWarningIfNeeded(tr, state, api, inlineExtensionFlagShown);
|
|
375
|
+
return true;
|
|
347
376
|
} else {
|
|
348
377
|
var _trackSyncBlocks4 = trackSyncBlocks(function (node) {
|
|
349
378
|
return node.type.name === 'syncBlock';
|
|
@@ -363,8 +392,8 @@ export var createPlugin = function createPlugin(options, pmPluginFactoryParams,
|
|
|
363
392
|
if (errorFlag) {
|
|
364
393
|
// Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
|
|
365
394
|
setTimeout(function () {
|
|
366
|
-
api === null || api === void 0 || api.core.actions.execute(function (
|
|
367
|
-
var tr =
|
|
395
|
+
api === null || api === void 0 || api.core.actions.execute(function (_ref6) {
|
|
396
|
+
var tr = _ref6.tr;
|
|
368
397
|
return tr.setMeta(syncedBlockPluginKey, {
|
|
369
398
|
activeFlag: {
|
|
370
399
|
id: errorFlag
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
|
|
2
2
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import {
|
|
3
|
+
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
|
+
import { findParentNodeOfType, findParentNodeOfTypeClosestToPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
4
5
|
export var findSyncBlock = function findSyncBlock(schema, selection) {
|
|
5
6
|
var syncBlock = schema.nodes.syncBlock;
|
|
6
7
|
return findSelectedNodeOfType(syncBlock)(selection);
|
|
@@ -77,4 +78,87 @@ export var sliceFullyContainsNode = function sliceFullyContainsNode(slice, node)
|
|
|
77
78
|
return false;
|
|
78
79
|
}
|
|
79
80
|
return true;
|
|
81
|
+
};
|
|
82
|
+
var _fragmentContainsInlineExtension = function fragmentContainsInlineExtension(fragment) {
|
|
83
|
+
var found = false;
|
|
84
|
+
fragment.forEach(function (node) {
|
|
85
|
+
if (found) {
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
if (node.type.name === 'inlineExtension') {
|
|
89
|
+
found = true;
|
|
90
|
+
} else if (node.content.size) {
|
|
91
|
+
if (_fragmentContainsInlineExtension(node.content)) {
|
|
92
|
+
found = true;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
});
|
|
96
|
+
return found;
|
|
97
|
+
};
|
|
98
|
+
var sliceContainsInlineExtension = function sliceContainsInlineExtension(slice) {
|
|
99
|
+
return _fragmentContainsInlineExtension(slice.content);
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Returns the resourceId of the bodied sync block where an inline extension was inserted, or undefined.
|
|
104
|
+
* Used to show a warning flag only on the first instance per sync block.
|
|
105
|
+
*/
|
|
106
|
+
export var wasInlineExtensionInsertedInBodiedSyncBlock = function wasInlineExtensionInsertedInBodiedSyncBlock(tr, state) {
|
|
107
|
+
if (!tr.docChanged || tr.getMeta('isRemote')) {
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
var bodiedSyncBlock = state.schema.nodes.bodiedSyncBlock;
|
|
111
|
+
if (!bodiedSyncBlock) {
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
var docs = tr.docs;
|
|
115
|
+
|
|
116
|
+
// When docs is available (e.g. from history plugin), check each replace step
|
|
117
|
+
if (docs && docs.length > 0) {
|
|
118
|
+
for (var i = 0; i < tr.steps.length; i++) {
|
|
119
|
+
var _docs;
|
|
120
|
+
var step = tr.steps[i];
|
|
121
|
+
var isReplaceStep = step instanceof ReplaceStep || step instanceof ReplaceAroundStep;
|
|
122
|
+
if (!isReplaceStep || !('slice' in step) || !('from' in step)) {
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
var replaceStep = step;
|
|
126
|
+
if (!sliceContainsInlineExtension(replaceStep.slice)) {
|
|
127
|
+
continue;
|
|
128
|
+
}
|
|
129
|
+
var docAfterStep = (_docs = docs[i + 1]) !== null && _docs !== void 0 ? _docs : tr.doc;
|
|
130
|
+
try {
|
|
131
|
+
var $pos = docAfterStep.resolve(replaceStep.from);
|
|
132
|
+
var parent = findParentNodeOfTypeClosestToPos($pos, bodiedSyncBlock);
|
|
133
|
+
if (parent !== null && parent !== void 0 && parent.node.attrs.resourceId) {
|
|
134
|
+
return parent.node.attrs.resourceId;
|
|
135
|
+
}
|
|
136
|
+
} catch (_unused) {
|
|
137
|
+
// resolve() can throw if position is invalid
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
return undefined;
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// Fallback: scan final doc for inline extensions inside bodied sync block that were added
|
|
144
|
+
var resourceId;
|
|
145
|
+
tr.doc.descendants(function (node, pos) {
|
|
146
|
+
if (resourceId !== undefined) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
if (node.type.name === 'inlineExtension') {
|
|
150
|
+
var _$pos = tr.doc.resolve(pos);
|
|
151
|
+
var _parent = findParentNodeOfTypeClosestToPos(_$pos, bodiedSyncBlock);
|
|
152
|
+
if (_parent !== null && _parent !== void 0 && _parent.node.attrs.resourceId) {
|
|
153
|
+
var mappedPos = tr.mapping.invert().map(pos);
|
|
154
|
+
var nodeBefore = state.doc.nodeAt(mappedPos);
|
|
155
|
+
if (!nodeBefore || nodeBefore.type.name !== 'inlineExtension') {
|
|
156
|
+
resourceId = _parent.node.attrs.resourceId;
|
|
157
|
+
return false;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return true;
|
|
162
|
+
});
|
|
163
|
+
return resourceId;
|
|
80
164
|
};
|
package/dist/esm/types/index.js
CHANGED
|
@@ -6,6 +6,7 @@ export var FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
|
|
|
6
6
|
FLAG_ID["SYNC_BLOCK_COPIED"] = "sync-block-copied";
|
|
7
7
|
FLAG_ID["UNPUBLISHED_SYNC_BLOCK_PASTED"] = "unpublished-sync-block-pasted";
|
|
8
8
|
FLAG_ID["CANNOT_CREATE_SYNC_BLOCK"] = "cannot-create-sync-block";
|
|
9
|
+
FLAG_ID["INLINE_EXTENSION_IN_SYNC_BLOCK"] = "inline-extension-in-sync-block";
|
|
9
10
|
return FLAG_ID;
|
|
10
11
|
}({});
|
|
11
12
|
export var SYNCED_BLOCK_BUTTON_TEST_ID = {
|
package/dist/esm/ui/Flag.js
CHANGED
|
@@ -11,7 +11,7 @@ import StatusSuccessIcon from '@atlaskit/icon/core/status-success';
|
|
|
11
11
|
import StatusWarningIcon from '@atlaskit/icon/core/status-warning';
|
|
12
12
|
import { syncedBlockPluginKey } from '../pm-plugins/main';
|
|
13
13
|
import { FLAG_ID } from '../types';
|
|
14
|
-
var flagMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE, {
|
|
14
|
+
var flagMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE, {
|
|
15
15
|
title: messages.failToDeleteTitle,
|
|
16
16
|
description: messages.failToDeleteWhenOfflineDescription,
|
|
17
17
|
type: 'error'
|
|
@@ -38,6 +38,10 @@ var flagMap = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_d
|
|
|
38
38
|
title: messages.cannotCreateSyncBlockTitle,
|
|
39
39
|
description: messages.CannotCreateSyncBlockDescription,
|
|
40
40
|
type: 'error'
|
|
41
|
+
}), FLAG_ID.INLINE_EXTENSION_IN_SYNC_BLOCK, {
|
|
42
|
+
title: messages.inlineExtensionInSyncBlockTitle,
|
|
43
|
+
description: messages.inlineExtensionInSyncBlockDescription,
|
|
44
|
+
type: 'error'
|
|
41
45
|
});
|
|
42
46
|
export var Flag = function Flag(_ref) {
|
|
43
47
|
var api = _ref.api;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { NodeType, Node as PMNode, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
5
5
|
export declare const findSyncBlock: (schema: Schema, selection: Selection) => ContentNodeWithPos | undefined;
|
|
6
6
|
export declare const findBodiedSyncBlock: (schema: Schema, selection: Selection) => ContentNodeWithPos | undefined;
|
|
@@ -21,3 +21,8 @@ export interface SyncBlockConversionInfo {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare const canBeConvertedToSyncBlock: (selection: Selection) => SyncBlockConversionInfo | false;
|
|
23
23
|
export declare const sliceFullyContainsNode: (slice: Slice, node: PMNode) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the resourceId of the bodied sync block where an inline extension was inserted, or undefined.
|
|
26
|
+
* Used to show a warning flag only on the first instance per sync block.
|
|
27
|
+
*/
|
|
28
|
+
export declare const wasInlineExtensionInsertedInBodiedSyncBlock: (tr: Transaction, state: EditorState) => string | undefined;
|
|
@@ -8,7 +8,8 @@ export declare enum FLAG_ID {
|
|
|
8
8
|
FAIL_TO_DELETE = "fail-to-delete",
|
|
9
9
|
SYNC_BLOCK_COPIED = "sync-block-copied",
|
|
10
10
|
UNPUBLISHED_SYNC_BLOCK_PASTED = "unpublished-sync-block-pasted",
|
|
11
|
-
CANNOT_CREATE_SYNC_BLOCK = "cannot-create-sync-block"
|
|
11
|
+
CANNOT_CREATE_SYNC_BLOCK = "cannot-create-sync-block",
|
|
12
|
+
INLINE_EXTENSION_IN_SYNC_BLOCK = "inline-extension-in-sync-block"
|
|
12
13
|
}
|
|
13
14
|
type FlagConfig = {
|
|
14
15
|
id: FLAG_ID;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
2
2
|
import type { NodeType, Node as PMNode, Schema, Slice } from '@atlaskit/editor-prosemirror/model';
|
|
3
|
-
import type { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
+
import type { EditorState, Selection, Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
4
|
import type { ContentNodeWithPos } from '@atlaskit/editor-prosemirror/utils';
|
|
5
5
|
export declare const findSyncBlock: (schema: Schema, selection: Selection) => ContentNodeWithPos | undefined;
|
|
6
6
|
export declare const findBodiedSyncBlock: (schema: Schema, selection: Selection) => ContentNodeWithPos | undefined;
|
|
@@ -21,3 +21,8 @@ export interface SyncBlockConversionInfo {
|
|
|
21
21
|
*/
|
|
22
22
|
export declare const canBeConvertedToSyncBlock: (selection: Selection) => SyncBlockConversionInfo | false;
|
|
23
23
|
export declare const sliceFullyContainsNode: (slice: Slice, node: PMNode) => boolean;
|
|
24
|
+
/**
|
|
25
|
+
* Returns the resourceId of the bodied sync block where an inline extension was inserted, or undefined.
|
|
26
|
+
* Used to show a warning flag only on the first instance per sync block.
|
|
27
|
+
*/
|
|
28
|
+
export declare const wasInlineExtensionInsertedInBodiedSyncBlock: (tr: Transaction, state: EditorState) => string | undefined;
|
|
@@ -8,7 +8,8 @@ export declare enum FLAG_ID {
|
|
|
8
8
|
FAIL_TO_DELETE = "fail-to-delete",
|
|
9
9
|
SYNC_BLOCK_COPIED = "sync-block-copied",
|
|
10
10
|
UNPUBLISHED_SYNC_BLOCK_PASTED = "unpublished-sync-block-pasted",
|
|
11
|
-
CANNOT_CREATE_SYNC_BLOCK = "cannot-create-sync-block"
|
|
11
|
+
CANNOT_CREATE_SYNC_BLOCK = "cannot-create-sync-block",
|
|
12
|
+
INLINE_EXTENSION_IN_SYNC_BLOCK = "inline-extension-in-sync-block"
|
|
12
13
|
}
|
|
13
14
|
type FlagConfig = {
|
|
14
15
|
id: FLAG_ID;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-synced-block",
|
|
3
|
-
"version": "5.3.
|
|
3
|
+
"version": "5.3.24",
|
|
4
4
|
"description": "SyncedBlock plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -40,7 +40,7 @@
|
|
|
40
40
|
"@atlaskit/editor-plugin-selection": "^7.0.0",
|
|
41
41
|
"@atlaskit/editor-prosemirror": "^7.3.0",
|
|
42
42
|
"@atlaskit/editor-shared-styles": "^3.10.0",
|
|
43
|
-
"@atlaskit/editor-synced-block-provider": "^3.
|
|
43
|
+
"@atlaskit/editor-synced-block-provider": "^3.30.0",
|
|
44
44
|
"@atlaskit/editor-toolbar": "^0.19.0",
|
|
45
45
|
"@atlaskit/flag": "^17.8.0",
|
|
46
46
|
"@atlaskit/icon": "31.0.0",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
62
62
|
},
|
|
63
63
|
"peerDependencies": {
|
|
64
|
-
"@atlaskit/editor-common": "^111.
|
|
64
|
+
"@atlaskit/editor-common": "^111.16.0",
|
|
65
65
|
"react": "^18.2.0"
|
|
66
66
|
},
|
|
67
67
|
"devDependencies": {
|