@atlaskit/editor-plugin-synced-block 5.3.13 → 5.3.14
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/editor-commands/index.js +7 -5
- package/dist/cjs/pm-plugins/main.js +87 -25
- package/dist/cjs/pm-plugins/utils/handle-bodied-sync-block-creation.js +141 -0
- package/dist/cjs/pm-plugins/utils/track-sync-blocks.js +1 -0
- package/dist/cjs/syncedBlockPlugin.js +4 -2
- package/dist/cjs/types/index.js +1 -0
- package/dist/cjs/ui/Flag.js +5 -1
- package/dist/cjs/ui/floating-toolbar.js +3 -0
- package/dist/es2019/editor-commands/index.js +7 -5
- package/dist/es2019/pm-plugins/main.js +67 -17
- package/dist/es2019/pm-plugins/utils/handle-bodied-sync-block-creation.js +134 -0
- package/dist/es2019/pm-plugins/utils/track-sync-blocks.js +1 -0
- package/dist/es2019/syncedBlockPlugin.js +4 -2
- package/dist/es2019/types/index.js +1 -0
- package/dist/es2019/ui/Flag.js +5 -0
- package/dist/es2019/ui/floating-toolbar.js +3 -0
- package/dist/esm/editor-commands/index.js +7 -5
- package/dist/esm/pm-plugins/main.js +87 -25
- package/dist/esm/pm-plugins/utils/handle-bodied-sync-block-creation.js +134 -0
- package/dist/esm/pm-plugins/utils/track-sync-blocks.js +1 -0
- package/dist/esm/syncedBlockPlugin.js +4 -2
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/ui/Flag.js +5 -1
- package/dist/esm/ui/floating-toolbar.js +3 -0
- package/dist/types/pm-plugins/main.d.ts +2 -1
- package/dist/types/pm-plugins/utils/handle-bodied-sync-block-creation.d.ts +9 -0
- package/dist/types/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +2 -2
- package/dist/types/types/index.d.ts +19 -1
- package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -1
- package/dist/types-ts4.5/pm-plugins/utils/handle-bodied-sync-block-creation.d.ts +9 -0
- package/dist/types-ts4.5/pm-plugins/utils/handle-bodied-sync-block-removal.d.ts +2 -2
- package/dist/types-ts4.5/types/index.d.ts +19 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-synced-block
|
|
2
2
|
|
|
3
|
+
## 5.3.14
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`ab4e4e442ad49`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/ab4e4e442ad49) -
|
|
8
|
+
[ux] [EDITOR-3694] Add loading state to bodiedSyncBlock for when saving new block to BE
|
|
9
|
+
- Updated dependencies
|
|
10
|
+
|
|
3
11
|
## 5.3.13
|
|
4
12
|
|
|
5
13
|
### Patch Changes
|
|
@@ -44,7 +44,9 @@ var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(_
|
|
|
44
44
|
|
|
45
45
|
// Save the new node with empty content to backend
|
|
46
46
|
// This is so that the node can be copied and referenced without the source being saved/published
|
|
47
|
-
|
|
47
|
+
if (!(0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
48
|
+
syncBlockStore.sourceManager.createBodiedSyncBlockNode(attrs, function () {});
|
|
49
|
+
}
|
|
48
50
|
if (typeAheadInsert) {
|
|
49
51
|
tr = typeAheadInsert(newBodiedSyncBlockNode);
|
|
50
52
|
} else {
|
|
@@ -81,15 +83,15 @@ var createSyncedBlock = exports.createSyncedBlock = function createSyncedBlock(_
|
|
|
81
83
|
|
|
82
84
|
// Save the new node with empty content to backend
|
|
83
85
|
// This is so that the node can be copied and referenced without the source being saved/published
|
|
84
|
-
|
|
86
|
+
if (!(0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
87
|
+
// Moved to appendTransaction
|
|
88
|
+
syncBlockStore.sourceManager.createBodiedSyncBlockNode(_attrs, function () {}, _newBodiedSyncBlockNode);
|
|
89
|
+
}
|
|
85
90
|
tr.replaceWith(conversionInfo.from, conversionInfo.to, _newBodiedSyncBlockNode).scrollIntoView();
|
|
86
91
|
|
|
87
92
|
// set selection to the start of the previous selection for the position taken up by the start of the new synced block
|
|
88
93
|
tr.setSelection(_state.TextSelection.create(tr.doc, conversionInfo.from));
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
// This transaction will be intercepted in filterTransaction and dispatched when saving to backend succeeds
|
|
92
|
-
// see filterTransaction for more details
|
|
93
95
|
return tr;
|
|
94
96
|
};
|
|
95
97
|
var copySyncedBlockReferenceToClipboardEditorCommand = exports.copySyncedBlockReferenceToClipboardEditorCommand = function copySyncedBlockReferenceToClipboardEditorCommand(syncBlockStore, inputMethod, api) {
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.syncedBlockPluginKey = exports.createPlugin = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
9
10
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
10
11
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
11
12
|
var _selection = require("@atlaskit/editor-common/selection");
|
|
@@ -15,20 +16,55 @@ var _editorPluginConnectivity = require("@atlaskit/editor-plugin-connectivity");
|
|
|
15
16
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
16
17
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
17
18
|
var _editorSyncedBlockProvider = require("@atlaskit/editor-synced-block-provider");
|
|
19
|
+
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
18
20
|
var _bodiedLazySyncedBlock = require("../nodeviews/bodiedLazySyncedBlock");
|
|
19
21
|
var _syncedBlock = require("../nodeviews/syncedBlock");
|
|
20
22
|
var _types = require("../types");
|
|
23
|
+
var _handleBodiedSyncBlockCreation = require("./utils/handle-bodied-sync-block-creation");
|
|
21
24
|
var _handleBodiedSyncBlockRemoval = require("./utils/handle-bodied-sync-block-removal");
|
|
22
25
|
var _ignoreDomEvent = require("./utils/ignore-dom-event");
|
|
23
26
|
var _selectionDecorations = require("./utils/selection-decorations");
|
|
24
27
|
var _trackSyncBlocks6 = require("./utils/track-sync-blocks");
|
|
25
28
|
var _utils2 = require("./utils/utils");
|
|
29
|
+
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; }
|
|
30
|
+
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; }
|
|
26
31
|
function _createForOfIteratorHelper(r, e) { var t = "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (!t) { if (Array.isArray(r) || (t = _unsupportedIterableToArray(r)) || e && r && "number" == typeof r.length) { t && (r = t); var _n = 0, F = function F() {}; return { s: F, n: function n() { return _n >= r.length ? { done: !0 } : { done: !1, value: r[_n++] }; }, e: function e(r) { throw r; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var o, a = !0, u = !1; return { s: function s() { t = t.call(r); }, n: function n() { var r = t.next(); return a = r.done, r; }, e: function e(r) { u = !0, o = r; }, f: function f() { try { a || null == t.return || t.return(); } finally { if (u) throw o; } } }; }
|
|
27
32
|
function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
|
|
28
33
|
function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
|
|
29
|
-
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; }
|
|
30
|
-
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; }
|
|
31
34
|
var syncedBlockPluginKey = exports.syncedBlockPluginKey = new _state.PluginKey('syncedBlockPlugin');
|
|
35
|
+
var mapRetryCreationPosMap = function mapRetryCreationPosMap(oldMap, newRetryCreationPos, mapPos) {
|
|
36
|
+
var resourceId = newRetryCreationPos === null || newRetryCreationPos === void 0 ? void 0 : newRetryCreationPos.resourceId;
|
|
37
|
+
var newMap = new Map(oldMap);
|
|
38
|
+
if (resourceId) {
|
|
39
|
+
var pos = newRetryCreationPos.pos;
|
|
40
|
+
if (!pos) {
|
|
41
|
+
newMap.delete(resourceId);
|
|
42
|
+
} else {
|
|
43
|
+
newMap.set(resourceId, pos);
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
if (newMap.size === 0) {
|
|
47
|
+
return newMap;
|
|
48
|
+
}
|
|
49
|
+
var _iterator = _createForOfIteratorHelper(newMap.entries()),
|
|
50
|
+
_step;
|
|
51
|
+
try {
|
|
52
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
53
|
+
var _step$value = (0, _slicedToArray2.default)(_step.value, 2),
|
|
54
|
+
id = _step$value[0],
|
|
55
|
+
_pos = _step$value[1];
|
|
56
|
+
newMap.set(id, {
|
|
57
|
+
from: mapPos(_pos.from),
|
|
58
|
+
to: mapPos(_pos.to)
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
} catch (err) {
|
|
62
|
+
_iterator.e(err);
|
|
63
|
+
} finally {
|
|
64
|
+
_iterator.f();
|
|
65
|
+
}
|
|
66
|
+
return newMap;
|
|
67
|
+
};
|
|
32
68
|
var showCopiedFlag = function showCopiedFlag(api) {
|
|
33
69
|
// Use setTimeout to dispatch transaction in next tick and avoid re-entrant dispatch
|
|
34
70
|
setTimeout(function () {
|
|
@@ -90,7 +126,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
90
126
|
return {
|
|
91
127
|
selectionDecorationSet: (0, _selectionDecorations.calculateDecorations)(instance.doc, instance.selection, instance.schema),
|
|
92
128
|
activeFlag: false,
|
|
93
|
-
syncBlockStore: syncBlockStore
|
|
129
|
+
syncBlockStore: syncBlockStore,
|
|
130
|
+
retryCreationPosMap: new Map()
|
|
94
131
|
};
|
|
95
132
|
},
|
|
96
133
|
apply: function apply(tr, currentPluginState, oldEditorState) {
|
|
@@ -98,15 +135,22 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
98
135
|
var meta = tr.getMeta(syncedBlockPluginKey);
|
|
99
136
|
var activeFlag = currentPluginState.activeFlag,
|
|
100
137
|
selectionDecorationSet = currentPluginState.selectionDecorationSet,
|
|
101
|
-
bodiedSyncBlockDeletionStatus = currentPluginState.bodiedSyncBlockDeletionStatus
|
|
138
|
+
bodiedSyncBlockDeletionStatus = currentPluginState.bodiedSyncBlockDeletionStatus,
|
|
139
|
+
retryCreationPosMap = currentPluginState.retryCreationPosMap;
|
|
102
140
|
var newDecorationSet = selectionDecorationSet.map(tr.mapping, tr.doc);
|
|
103
141
|
if (!tr.selection.eq(oldEditorState.selection)) {
|
|
104
142
|
newDecorationSet = (0, _selectionDecorations.calculateDecorations)(tr.doc, tr.selection, tr.doc.type.schema);
|
|
105
143
|
}
|
|
144
|
+
var newRetryCreationPosMap = retryCreationPosMap;
|
|
145
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
146
|
+
var newPosEntry = meta === null || meta === void 0 ? void 0 : meta.retryCreationPos;
|
|
147
|
+
newRetryCreationPosMap = mapRetryCreationPosMap(retryCreationPosMap, newPosEntry, tr.mapping.map.bind(tr.mapping));
|
|
148
|
+
}
|
|
106
149
|
return {
|
|
107
150
|
activeFlag: (_meta$activeFlag = meta === null || meta === void 0 ? void 0 : meta.activeFlag) !== null && _meta$activeFlag !== void 0 ? _meta$activeFlag : activeFlag,
|
|
108
151
|
selectionDecorationSet: newDecorationSet,
|
|
109
152
|
syncBlockStore: syncBlockStore,
|
|
153
|
+
retryCreationPosMap: newRetryCreationPosMap,
|
|
110
154
|
bodiedSyncBlockDeletionStatus: (_meta$bodiedSyncBlock = meta === null || meta === void 0 ? void 0 : meta.bodiedSyncBlockDeletionStatus) !== null && _meta$bodiedSyncBlock !== void 0 ? _meta$bodiedSyncBlock : bodiedSyncBlockDeletionStatus
|
|
111
155
|
};
|
|
112
156
|
}
|
|
@@ -136,13 +180,16 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
136
180
|
})
|
|
137
181
|
},
|
|
138
182
|
decorations: function decorations(state) {
|
|
139
|
-
var
|
|
140
|
-
var
|
|
183
|
+
var _currentPluginState$s, _api$connectivity, _api$editorViewMode;
|
|
184
|
+
var currentPluginState = syncedBlockPluginKey.getState(state);
|
|
185
|
+
var selectionDecorationSet = (_currentPluginState$s = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.selectionDecorationSet) !== null && _currentPluginState$s !== void 0 ? _currentPluginState$s : _view.DecorationSet.empty;
|
|
186
|
+
var syncBlockStore = currentPluginState === null || currentPluginState === void 0 ? void 0 : currentPluginState.syncBlockStore;
|
|
141
187
|
var doc = state.doc;
|
|
142
188
|
var isOffline = (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);
|
|
143
189
|
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';
|
|
144
190
|
var offlineDecorations = [];
|
|
145
191
|
var viewModeDecorations = [];
|
|
192
|
+
var loadingDecorations = [];
|
|
146
193
|
state.doc.descendants(function (node, pos) {
|
|
147
194
|
if (node.type.name === 'bodiedSyncBlock' && isOffline) {
|
|
148
195
|
offlineDecorations.push(_view.Decoration.node(pos, pos + node.nodeSize, {
|
|
@@ -154,8 +201,13 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
154
201
|
class: _syncBlock.SyncBlockStateCssClassName.viewModeClassName
|
|
155
202
|
}));
|
|
156
203
|
}
|
|
204
|
+
if (node.type.name === 'bodiedSyncBlock' && syncBlockStore.sourceManager.isPendingCreation(node.attrs.resourceId) && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
205
|
+
loadingDecorations.push(_view.Decoration.node(pos, pos + node.nodeSize, {
|
|
206
|
+
class: _syncBlock.SyncBlockStateCssClassName.creationLoadingClassName
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
157
209
|
});
|
|
158
|
-
return selectionDecorationSet.add(doc, offlineDecorations).add(doc, viewModeDecorations);
|
|
210
|
+
return selectionDecorationSet.add(doc, offlineDecorations).add(doc, viewModeDecorations).add(doc, loadingDecorations);
|
|
159
211
|
},
|
|
160
212
|
handleClickOn: (0, _selection.createSelectionClickHandler)(['bodiedSyncBlock'], function (target) {
|
|
161
213
|
return !!target.closest(".".concat(_syncBlock.BodiedSyncBlockSharedCssClassName.prefix));
|
|
@@ -216,6 +268,12 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
216
268
|
var _api$connectivity2;
|
|
217
269
|
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);
|
|
218
270
|
var isConfirmedSyncBlockDeletion = Boolean(tr.getMeta('isConfirmedSyncBlockDeletion'));
|
|
271
|
+
var hasNoPendingRequest = (0, _platformFeatureFlags.fg)('platform_synced_block_patch_1') ? false :
|
|
272
|
+
// requireConfirmationBeforeDelete is always true, so this evaluates to false and hence redundant
|
|
273
|
+
!(syncBlockStore !== null && syncBlockStore !== void 0 && syncBlockStore.sourceManager.requireConfirmationBeforeDelete()) && !syncBlockStore.sourceManager.hasPendingCreation();
|
|
274
|
+
var isCommitsCreation = (0, _platformFeatureFlags.fg)('platform_synced_block_patch_1') ? false :
|
|
275
|
+
// For patch 1, we don't intercept the insert transaction, hence it's redundant
|
|
276
|
+
Boolean(tr.getMeta('isCommitSyncBlockCreation'));
|
|
219
277
|
|
|
220
278
|
// Track newly added reference sync blocks before processing the transaction
|
|
221
279
|
if (tr.docChanged && !tr.getMeta('isRemote')) {
|
|
@@ -236,7 +294,7 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
236
294
|
// or are from remote (collab) or already confirmed sync block deletion
|
|
237
295
|
// We only care about local changes that change the document
|
|
238
296
|
// and are not yet confirmed for sync block deletion
|
|
239
|
-
if (!tr.docChanged ||
|
|
297
|
+
if (!tr.docChanged || hasNoPendingRequest || Boolean(tr.getMeta('isRemote')) || isCommitsCreation || !isOffline && isConfirmedSyncBlockDeletion) {
|
|
240
298
|
return true;
|
|
241
299
|
}
|
|
242
300
|
var _trackSyncBlocks2 = (0, _trackSyncBlocks6.trackSyncBlocks)(syncBlockStore.sourceManager.isSourceBlock, tr, state),
|
|
@@ -285,18 +343,22 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
285
343
|
// After true is returned here and the node is created, we delete the node in the filterTransaction immediately, which cancels out the creation
|
|
286
344
|
return true;
|
|
287
345
|
}
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
346
|
+
if ((0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
347
|
+
(0, _handleBodiedSyncBlockCreation.handleBodiedSyncBlockCreation)(bodiedSyncBlockAdded, state, api);
|
|
348
|
+
return true;
|
|
349
|
+
} else {
|
|
350
|
+
// If there is bodiedSyncBlock node addition and it's waiting for the result of saving the node to backend (syncBlockStore.hasPendingCreation()),
|
|
351
|
+
// we need to intercept the transaction and save it in insert callback so that we only insert it to the document when backend call if backend call is successful
|
|
352
|
+
// The callback will be evoked by in SourceSyncBlockStoreManager.commitPendingCreation
|
|
353
|
+
syncBlockStore.sourceManager.registerCreationCallback(function () {
|
|
354
|
+
var _api$core;
|
|
355
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.execute(function () {
|
|
356
|
+
return tr.setMeta('isCommitSyncBlockCreation', true);
|
|
357
|
+
});
|
|
358
|
+
api === null || api === void 0 || api.core.actions.focus();
|
|
296
359
|
});
|
|
297
|
-
|
|
298
|
-
}
|
|
299
|
-
return false;
|
|
360
|
+
return false;
|
|
361
|
+
}
|
|
300
362
|
}
|
|
301
363
|
} else {
|
|
302
364
|
var _trackSyncBlocks4 = (0, _trackSyncBlocks6.trackSyncBlocks)(function (node) {
|
|
@@ -339,11 +401,11 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
339
401
|
confirmationTransactionRef.current = (0, _editorSyncedBlockProvider.rebaseTransaction)(confirmationTransactionRef.current, tr, newState);
|
|
340
402
|
}
|
|
341
403
|
});
|
|
342
|
-
var
|
|
343
|
-
|
|
404
|
+
var _iterator2 = _createForOfIteratorHelper(trs),
|
|
405
|
+
_step2;
|
|
344
406
|
try {
|
|
345
407
|
var _loop = function _loop() {
|
|
346
|
-
var tr =
|
|
408
|
+
var tr = _step2.value;
|
|
347
409
|
if (!tr.getMeta(_utils.pmHistoryPluginKey)) {
|
|
348
410
|
return 0; // continue
|
|
349
411
|
}
|
|
@@ -364,15 +426,15 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pmPlugi
|
|
|
364
426
|
}
|
|
365
427
|
},
|
|
366
428
|
_ret;
|
|
367
|
-
for (
|
|
429
|
+
for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
|
|
368
430
|
_ret = _loop();
|
|
369
431
|
if (_ret === 0) continue;
|
|
370
432
|
if (_ret) return _ret.v;
|
|
371
433
|
}
|
|
372
434
|
} catch (err) {
|
|
373
|
-
|
|
435
|
+
_iterator2.e(err);
|
|
374
436
|
} finally {
|
|
375
|
-
|
|
437
|
+
_iterator2.f();
|
|
376
438
|
}
|
|
377
439
|
return null;
|
|
378
440
|
}
|
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.handleBodiedSyncBlockCreation = void 0;
|
|
8
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
|
+
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
10
|
+
var _types = require("../../types");
|
|
11
|
+
var _main = require("../main");
|
|
12
|
+
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; }
|
|
13
|
+
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; }
|
|
14
|
+
var onRetry = function onRetry(api, resourceId) {
|
|
15
|
+
return function () {
|
|
16
|
+
var _api$core, _api$core2;
|
|
17
|
+
api === null || api === void 0 || (_api$core = api.core) === null || _api$core === void 0 || _api$core.actions.focus();
|
|
18
|
+
api === null || api === void 0 || (_api$core2 = api.core) === null || _api$core2 === void 0 || _api$core2.actions.execute(function (_ref) {
|
|
19
|
+
var _api$syncedBlock, _api$syncedBlock2;
|
|
20
|
+
var tr = _ref.tr;
|
|
21
|
+
var pos = api === null || api === void 0 || (_api$syncedBlock = api.syncedBlock) === null || _api$syncedBlock === void 0 || (_api$syncedBlock = _api$syncedBlock.sharedState.currentState()) === null || _api$syncedBlock === void 0 || (_api$syncedBlock = _api$syncedBlock.retryCreationPosMap) === null || _api$syncedBlock === void 0 ? void 0 : _api$syncedBlock.get(resourceId);
|
|
22
|
+
var from = pos === null || pos === void 0 ? void 0 : pos.from;
|
|
23
|
+
var to = pos === null || pos === void 0 ? void 0 : pos.to;
|
|
24
|
+
if (from === undefined || to === undefined) {
|
|
25
|
+
return tr;
|
|
26
|
+
}
|
|
27
|
+
tr.setSelection(_state.TextSelection.create(tr.doc, from, to)).setMeta(_main.syncedBlockPluginKey, {
|
|
28
|
+
activeFlag: false
|
|
29
|
+
});
|
|
30
|
+
api === null || api === void 0 || (_api$syncedBlock2 = api.syncedBlock) === null || _api$syncedBlock2 === void 0 || _api$syncedBlock2.commands.insertSyncedBlock()({
|
|
31
|
+
tr: tr
|
|
32
|
+
});
|
|
33
|
+
return tr;
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
var getRevertCreationPos = function getRevertCreationPos(api, doc, resourceId) {
|
|
38
|
+
var _api$syncedBlock3;
|
|
39
|
+
var retryCreationPos = api === null || api === void 0 || (_api$syncedBlock3 = api.syncedBlock) === null || _api$syncedBlock3 === void 0 || (_api$syncedBlock3 = _api$syncedBlock3.sharedState.currentState()) === null || _api$syncedBlock3 === void 0 || (_api$syncedBlock3 = _api$syncedBlock3.retryCreationPosMap) === null || _api$syncedBlock3 === void 0 ? void 0 : _api$syncedBlock3.get(resourceId);
|
|
40
|
+
if (retryCreationPos) {
|
|
41
|
+
return retryCreationPos;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Fallback to find the positions in case BE call returns before plugin state becomes available
|
|
45
|
+
// which is highly unlikely
|
|
46
|
+
var currentPos;
|
|
47
|
+
doc.descendants(function (node, pos) {
|
|
48
|
+
if (currentPos) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
if (node.type.name === 'bodiedSyncBlock' && resourceId === node.attrs.resourceId) {
|
|
52
|
+
currentPos = {
|
|
53
|
+
from: pos,
|
|
54
|
+
to: pos + node.nodeSize
|
|
55
|
+
};
|
|
56
|
+
return false;
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return currentPos;
|
|
60
|
+
};
|
|
61
|
+
var buildRevertCreationTr = function buildRevertCreationTr(tr, pos) {
|
|
62
|
+
var _tr$doc$nodeAt;
|
|
63
|
+
var content = (_tr$doc$nodeAt = tr.doc.nodeAt(pos.from)) === null || _tr$doc$nodeAt === void 0 ? void 0 : _tr$doc$nodeAt.content;
|
|
64
|
+
if (content) {
|
|
65
|
+
tr.replaceWith(pos.from, pos.to, content);
|
|
66
|
+
var contentFrom = tr.mapping.map(pos.from);
|
|
67
|
+
tr.setSelection(_state.TextSelection.create(tr.doc, contentFrom, contentFrom + content.size));
|
|
68
|
+
} else {
|
|
69
|
+
tr.delete(pos.from, pos.to);
|
|
70
|
+
}
|
|
71
|
+
return tr;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
*
|
|
76
|
+
* Save the new bodiedSyncBlock to backend with empty content and handles revert (if failed) and retry flow
|
|
77
|
+
*/
|
|
78
|
+
var handleBodiedSyncBlockCreation = exports.handleBodiedSyncBlockCreation = function handleBodiedSyncBlockCreation(bodiedSyncBlockAdded, editorState, api) {
|
|
79
|
+
var syncBlockStore = _main.syncedBlockPluginKey.getState(editorState).syncBlockStore;
|
|
80
|
+
bodiedSyncBlockAdded.forEach(function (node) {
|
|
81
|
+
if (node.from === undefined || node.to === undefined) {
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
var retryCreationPos = {
|
|
85
|
+
from: node.from,
|
|
86
|
+
to: node.to
|
|
87
|
+
};
|
|
88
|
+
var resourceId = node.attrs.resourceId;
|
|
89
|
+
setTimeout(function () {
|
|
90
|
+
var _api$core3;
|
|
91
|
+
api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(function (_ref2) {
|
|
92
|
+
var tr = _ref2.tr;
|
|
93
|
+
return tr.setMeta(_main.syncedBlockPluginKey, {
|
|
94
|
+
retryCreationPos: {
|
|
95
|
+
resourceId: resourceId,
|
|
96
|
+
pos: retryCreationPos
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
syncBlockStore.sourceManager.createBodiedSyncBlockNode(node.attrs, function (success) {
|
|
102
|
+
if (success) {
|
|
103
|
+
var _api$core4, _api$core5;
|
|
104
|
+
api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(function (_ref3) {
|
|
105
|
+
var tr = _ref3.tr;
|
|
106
|
+
return tr.setMeta(_main.syncedBlockPluginKey, {
|
|
107
|
+
retryCreationPos: {
|
|
108
|
+
resourceId: resourceId,
|
|
109
|
+
pos: undefined
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
});
|
|
113
|
+
api === null || api === void 0 || (_api$core5 = api.core) === null || _api$core5 === void 0 || _api$core5.actions.focus();
|
|
114
|
+
} else {
|
|
115
|
+
var _api$core6;
|
|
116
|
+
api === null || api === void 0 || (_api$core6 = api.core) === null || _api$core6 === void 0 || _api$core6.actions.execute(function (_ref4) {
|
|
117
|
+
var tr = _ref4.tr;
|
|
118
|
+
var revertCreationPos = getRevertCreationPos(api, tr.doc, resourceId);
|
|
119
|
+
if (!revertCreationPos) {
|
|
120
|
+
return tr;
|
|
121
|
+
}
|
|
122
|
+
var revertTr = buildRevertCreationTr(tr, revertCreationPos);
|
|
123
|
+
return revertTr.setMeta('isConfirmedSyncBlockDeletion', true).setMeta('addToHistory', false).setMeta(_main.syncedBlockPluginKey, {
|
|
124
|
+
activeFlag: {
|
|
125
|
+
id: _types.FLAG_ID.CANNOT_CREATE_SYNC_BLOCK,
|
|
126
|
+
onRetry: onRetry(api, resourceId),
|
|
127
|
+
onDismissed: function onDismissed(tr) {
|
|
128
|
+
return tr.setMeta(_main.syncedBlockPluginKey, _objectSpread(_objectSpread({}, tr.getMeta(_main.syncedBlockPluginKey)), {}, {
|
|
129
|
+
retryCreationPos: {
|
|
130
|
+
resourceId: resourceId,
|
|
131
|
+
pos: undefined
|
|
132
|
+
}
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
});
|
|
138
|
+
}
|
|
139
|
+
}, node.node);
|
|
140
|
+
});
|
|
141
|
+
};
|
|
@@ -150,11 +150,13 @@ var syncedBlockPlugin = exports.syncedBlockPlugin = function syncedBlockPlugin(_
|
|
|
150
150
|
var _syncedBlockPluginKey = _main.syncedBlockPluginKey.getState(editorState),
|
|
151
151
|
activeFlag = _syncedBlockPluginKey.activeFlag,
|
|
152
152
|
currentSyncBlockStore = _syncedBlockPluginKey.syncBlockStore,
|
|
153
|
-
bodiedSyncBlockDeletionStatus = _syncedBlockPluginKey.bodiedSyncBlockDeletionStatus
|
|
153
|
+
bodiedSyncBlockDeletionStatus = _syncedBlockPluginKey.bodiedSyncBlockDeletionStatus,
|
|
154
|
+
retryCreationPosMap = _syncedBlockPluginKey.retryCreationPosMap;
|
|
154
155
|
return {
|
|
155
156
|
activeFlag: activeFlag,
|
|
156
157
|
syncBlockStore: currentSyncBlockStore,
|
|
157
|
-
bodiedSyncBlockDeletionStatus: bodiedSyncBlockDeletionStatus
|
|
158
|
+
bodiedSyncBlockDeletionStatus: bodiedSyncBlockDeletionStatus,
|
|
159
|
+
retryCreationPosMap: retryCreationPosMap
|
|
158
160
|
};
|
|
159
161
|
}
|
|
160
162
|
};
|
package/dist/cjs/types/index.js
CHANGED
|
@@ -11,6 +11,7 @@ var FLAG_ID = exports.FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
|
|
|
11
11
|
FLAG_ID["FAIL_TO_DELETE"] = "fail-to-delete";
|
|
12
12
|
FLAG_ID["SYNC_BLOCK_COPIED"] = "sync-block-copied";
|
|
13
13
|
FLAG_ID["UNPUBLISHED_SYNC_BLOCK_PASTED"] = "unpublished-sync-block-pasted";
|
|
14
|
+
FLAG_ID["CANNOT_CREATE_SYNC_BLOCK"] = "cannot-create-sync-block";
|
|
14
15
|
return FLAG_ID;
|
|
15
16
|
}({});
|
|
16
17
|
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)({}, _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)({}, _types.FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE, {
|
|
24
24
|
title: _messages.syncBlockMessages.failToDeleteTitle,
|
|
25
25
|
description: _messages.syncBlockMessages.failToDeleteWhenOfflineDescription,
|
|
26
26
|
type: 'error'
|
|
@@ -43,6 +43,10 @@ var flagMap = (0, _defineProperty2.default)((0, _defineProperty2.default)((0, _d
|
|
|
43
43
|
title: _messages.syncBlockMessages.unpublishedSyncBlockPastedTitle,
|
|
44
44
|
description: _messages.syncBlockMessages.unpublishedSyncBlockPastedDescription,
|
|
45
45
|
type: 'info'
|
|
46
|
+
}), _types.FLAG_ID.CANNOT_CREATE_SYNC_BLOCK, {
|
|
47
|
+
title: _messages.syncBlockMessages.cannotCreateSyncBlockTitle,
|
|
48
|
+
description: _messages.syncBlockMessages.CannotCreateSyncBlockDescription,
|
|
49
|
+
type: 'error'
|
|
46
50
|
});
|
|
47
51
|
var Flag = exports.Flag = function Flag(_ref) {
|
|
48
52
|
var api = _ref.api;
|
|
@@ -32,6 +32,9 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(stat
|
|
|
32
32
|
if (!syncBlockObject) {
|
|
33
33
|
return;
|
|
34
34
|
}
|
|
35
|
+
if (syncBlockStore.sourceManager.isPendingCreation(syncBlockObject.node.attrs.resourceId) && (0, _platformFeatureFlags.fg)('platform_synced_block_patch_1')) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
35
38
|
var syncBlockInstance = syncBlockStore.referenceManager.getFromCache(syncBlockObject.node.attrs.resourceId);
|
|
36
39
|
var isUnsyncedBlock = (syncBlockInstance === null || syncBlockInstance === void 0 || (_syncBlockInstance$er = syncBlockInstance.error) === null || _syncBlockInstance$er === void 0 ? void 0 : _syncBlockInstance$er.type) === _editorSyncedBlockProvider.SyncBlockError.NotFound;
|
|
37
40
|
var isErroredBlock = syncBlockInstance === null || syncBlockInstance === void 0 ? void 0 : syncBlockInstance.error;
|
|
@@ -44,7 +44,9 @@ export const createSyncedBlock = ({
|
|
|
44
44
|
|
|
45
45
|
// Save the new node with empty content to backend
|
|
46
46
|
// This is so that the node can be copied and referenced without the source being saved/published
|
|
47
|
-
|
|
47
|
+
if (!fg('platform_synced_block_patch_1')) {
|
|
48
|
+
syncBlockStore.sourceManager.createBodiedSyncBlockNode(attrs, () => {});
|
|
49
|
+
}
|
|
48
50
|
if (typeAheadInsert) {
|
|
49
51
|
tr = typeAheadInsert(newBodiedSyncBlockNode);
|
|
50
52
|
} else {
|
|
@@ -81,15 +83,15 @@ export const createSyncedBlock = ({
|
|
|
81
83
|
|
|
82
84
|
// Save the new node with empty content to backend
|
|
83
85
|
// This is so that the node can be copied and referenced without the source being saved/published
|
|
84
|
-
|
|
86
|
+
if (!fg('platform_synced_block_patch_1')) {
|
|
87
|
+
// Moved to appendTransaction
|
|
88
|
+
syncBlockStore.sourceManager.createBodiedSyncBlockNode(attrs, () => {}, newBodiedSyncBlockNode);
|
|
89
|
+
}
|
|
85
90
|
tr.replaceWith(conversionInfo.from, conversionInfo.to, newBodiedSyncBlockNode).scrollIntoView();
|
|
86
91
|
|
|
87
92
|
// set selection to the start of the previous selection for the position taken up by the start of the new synced block
|
|
88
93
|
tr.setSelection(TextSelection.create(tr.doc, conversionInfo.from));
|
|
89
94
|
}
|
|
90
|
-
|
|
91
|
-
// This transaction will be intercepted in filterTransaction and dispatched when saving to backend succeeds
|
|
92
|
-
// see filterTransaction for more details
|
|
93
95
|
return tr;
|
|
94
96
|
};
|
|
95
97
|
export const copySyncedBlockReferenceToClipboardEditorCommand = (syncBlockStore, inputMethod, api) => ({
|