@atlaskit/editor-plugin-synced-block 6.0.11 → 6.0.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 +22 -0
- package/dist/cjs/nodeviews/bodiedSyncedBlock.js +1 -2
- package/dist/cjs/pm-plugins/main.js +39 -136
- package/dist/cjs/pm-plugins/menu-and-toolbar-experiences.js +43 -25
- package/dist/cjs/pm-plugins/utils/utils.js +1 -6
- package/dist/cjs/syncedBlockPlugin.js +1 -2
- package/dist/cjs/ui/SyncBlockRefresher.js +1 -17
- package/dist/es2019/nodeviews/bodiedSyncedBlock.js +1 -2
- package/dist/es2019/pm-plugins/main.js +31 -125
- package/dist/es2019/pm-plugins/menu-and-toolbar-experiences.js +47 -26
- package/dist/es2019/pm-plugins/utils/utils.js +1 -6
- package/dist/es2019/syncedBlockPlugin.js +1 -2
- package/dist/es2019/ui/SyncBlockRefresher.js +0 -16
- package/dist/esm/nodeviews/bodiedSyncedBlock.js +1 -2
- package/dist/esm/pm-plugins/main.js +33 -130
- package/dist/esm/pm-plugins/menu-and-toolbar-experiences.js +44 -26
- package/dist/esm/pm-plugins/utils/utils.js +1 -6
- package/dist/esm/syncedBlockPlugin.js +1 -2
- package/dist/esm/ui/SyncBlockRefresher.js +0 -16
- package/dist/types/ui/SyncBlockRefresher.d.ts +0 -1
- package/dist/types-ts4.5/ui/SyncBlockRefresher.d.ts +0 -1
- package/docs/0-intro.tsx +10 -10
- package/package.json +11 -11
- package/dist/cjs/nodeviews/bodiedLazySyncedBlock.js +0 -27
- package/dist/es2019/nodeviews/bodiedLazySyncedBlock.js +0 -17
- package/dist/esm/nodeviews/bodiedLazySyncedBlock.js +0 -16
- package/dist/types/nodeviews/bodiedLazySyncedBlock.d.ts +0 -3
- package/dist/types-ts4.5/nodeviews/bodiedLazySyncedBlock.d.ts +0 -3
|
@@ -8,9 +8,7 @@ import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
|
|
|
8
8
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
9
9
|
import { DecorationSet, Decoration } from '@atlaskit/editor-prosemirror/view';
|
|
10
10
|
import { convertPMNodesToSyncBlockNodes, rebaseTransaction } from '@atlaskit/editor-synced-block-provider';
|
|
11
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
12
11
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
13
|
-
import { lazyBodiedSyncBlockView } from '../nodeviews/bodiedLazySyncedBlock';
|
|
14
12
|
import { bodiedSyncBlockNodeView, bodiedSyncBlockNodeViewOld } from '../nodeviews/bodiedSyncedBlock';
|
|
15
13
|
import { SyncBlock as SyncBlockView } from '../nodeviews/syncedBlock';
|
|
16
14
|
import { FLAG_ID } from '../types';
|
|
@@ -205,17 +203,13 @@ class SyncedBlockPluginContext {
|
|
|
205
203
|
}
|
|
206
204
|
}
|
|
207
205
|
export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api) => {
|
|
208
|
-
var _ctx$confirmationTran, _ctx$unpublishedFlagS, _ctx$extensionFlagSho;
|
|
209
206
|
const {
|
|
210
207
|
useLongPressSelection = false
|
|
211
208
|
} = options || {};
|
|
212
|
-
const ctx =
|
|
213
|
-
const confirmationTransactionRef =
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
let isCopyEvent = false;
|
|
217
|
-
const unpublishedFlagShown = (_ctx$unpublishedFlagS = ctx === null || ctx === void 0 ? void 0 : ctx.unpublishedFlagShown) !== null && _ctx$unpublishedFlagS !== void 0 ? _ctx$unpublishedFlagS : new Set();
|
|
218
|
-
const extensionFlagShown = (_ctx$extensionFlagSho = ctx === null || ctx === void 0 ? void 0 : ctx.extensionFlagShown) !== null && _ctx$extensionFlagSho !== void 0 ? _ctx$extensionFlagSho : new Set();
|
|
209
|
+
const ctx = new SyncedBlockPluginContext();
|
|
210
|
+
const confirmationTransactionRef = ctx.confirmationTransactionRef;
|
|
211
|
+
const unpublishedFlagShown = ctx.unpublishedFlagShown;
|
|
212
|
+
const extensionFlagShown = ctx.extensionFlagShown;
|
|
219
213
|
|
|
220
214
|
// Set up callback to detect unpublished sync blocks when they're fetched
|
|
221
215
|
syncBlockStore.referenceManager.setOnUnpublishedSyncBlockDetected(resourceId => {
|
|
@@ -244,7 +238,7 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
244
238
|
activeFlag: false,
|
|
245
239
|
syncBlockStore: syncBlockStore,
|
|
246
240
|
retryCreationPosMap: new Map(),
|
|
247
|
-
hasUnsavedBodiedSyncBlockChanges:
|
|
241
|
+
hasUnsavedBodiedSyncBlockChanges: syncBlockStore.sourceManager.hasUnsavedChanges()
|
|
248
242
|
};
|
|
249
243
|
},
|
|
250
244
|
apply: (tr, currentPluginState, oldEditorState) => {
|
|
@@ -256,11 +250,11 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
256
250
|
bodiedSyncBlockDeletionStatus,
|
|
257
251
|
retryCreationPosMap
|
|
258
252
|
} = currentPluginState;
|
|
259
|
-
let newDecorationSet =
|
|
260
|
-
: selectionDecorationSet
|
|
253
|
+
let newDecorationSet = tr.docChanged ? selectionDecorationSet.map(tr.mapping, tr.doc) // only map if document changed
|
|
254
|
+
: selectionDecorationSet;
|
|
261
255
|
if (!tr.selection.eq(oldEditorState.selection)) {
|
|
262
256
|
newDecorationSet = calculateDecorations(tr.doc, tr.selection, tr.doc.type.schema);
|
|
263
|
-
} else if (tr.docChanged
|
|
257
|
+
} else if (tr.docChanged) {
|
|
264
258
|
const existingDecorationsLength = selectionDecorationSet.find().length;
|
|
265
259
|
const newDecorationsLength = newDecorationSet.find().length;
|
|
266
260
|
|
|
@@ -279,7 +273,7 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
279
273
|
syncBlockStore: syncBlockStore,
|
|
280
274
|
retryCreationPosMap: newRetryCreationPosMap,
|
|
281
275
|
bodiedSyncBlockDeletionStatus: (_meta$bodiedSyncBlock = meta === null || meta === void 0 ? void 0 : meta.bodiedSyncBlockDeletionStatus) !== null && _meta$bodiedSyncBlock !== void 0 ? _meta$bodiedSyncBlock : bodiedSyncBlockDeletionStatus,
|
|
282
|
-
hasUnsavedBodiedSyncBlockChanges:
|
|
276
|
+
hasUnsavedBodiedSyncBlockChanges: syncBlockStore.sourceManager.hasUnsavedChanges()
|
|
283
277
|
};
|
|
284
278
|
}
|
|
285
279
|
},
|
|
@@ -300,7 +294,7 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
300
294
|
eventDispatcher: pmPluginFactoryParams.eventDispatcher,
|
|
301
295
|
syncBlockStore: syncBlockStore
|
|
302
296
|
}).init(),
|
|
303
|
-
bodiedSyncBlock:
|
|
297
|
+
bodiedSyncBlock: editorExperiment('platform_synced_block_use_new_source_nodeview', true, {
|
|
304
298
|
exposure: true
|
|
305
299
|
}) ? bodiedSyncBlockNodeView({
|
|
306
300
|
pluginOptions: options,
|
|
@@ -312,10 +306,6 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
312
306
|
pmPluginFactoryParams,
|
|
313
307
|
api,
|
|
314
308
|
syncBlockStore
|
|
315
|
-
}) : lazyBodiedSyncBlockView({
|
|
316
|
-
pluginOptions: options,
|
|
317
|
-
pmPluginFactoryParams,
|
|
318
|
-
api
|
|
319
309
|
})
|
|
320
310
|
},
|
|
321
311
|
decorations: state => {
|
|
@@ -328,7 +318,7 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
328
318
|
} = state;
|
|
329
319
|
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);
|
|
330
320
|
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';
|
|
331
|
-
const isDragging =
|
|
321
|
+
const isDragging = (api === null || api === void 0 ? void 0 : (_api$userIntent = api.userIntent) === null || _api$userIntent === void 0 ? void 0 : (_api$userIntent$share = _api$userIntent.sharedState.currentState()) === null || _api$userIntent$share === void 0 ? void 0 : _api$userIntent$share.currentUserIntent) === 'dragging';
|
|
332
322
|
const offlineDecorations = [];
|
|
333
323
|
const viewModeDecorations = [];
|
|
334
324
|
const loadingDecorations = [];
|
|
@@ -351,7 +341,7 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
351
341
|
}
|
|
352
342
|
|
|
353
343
|
// Show sync block border while the user is dragging
|
|
354
|
-
if (isDragging && (node.type.name === 'bodiedSyncBlock' || node.type.name === 'syncBlock')
|
|
344
|
+
if (isDragging && (node.type.name === 'bodiedSyncBlock' || node.type.name === 'syncBlock')) {
|
|
355
345
|
dragDecorations.push(Decoration.node(pos, pos + node.nodeSize, {
|
|
356
346
|
class: SyncBlockStateCssClassName.draggingClassName
|
|
357
347
|
}));
|
|
@@ -377,11 +367,7 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
377
367
|
return shouldIgnoreDomEvent(view, event, api);
|
|
378
368
|
},
|
|
379
369
|
copy: () => {
|
|
380
|
-
|
|
381
|
-
ctx.markCopyEvent();
|
|
382
|
-
} else {
|
|
383
|
-
isCopyEvent = true;
|
|
384
|
-
}
|
|
370
|
+
ctx.markCopyEvent();
|
|
385
371
|
return false;
|
|
386
372
|
}
|
|
387
373
|
},
|
|
@@ -393,10 +379,7 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
393
379
|
const {
|
|
394
380
|
schema
|
|
395
381
|
} = state;
|
|
396
|
-
const isCopy = ctx
|
|
397
|
-
if (!ctx) {
|
|
398
|
-
isCopyEvent = false;
|
|
399
|
-
}
|
|
382
|
+
const isCopy = ctx.consumeCopyEvent();
|
|
400
383
|
if (!syncBlockStore || !isCopy) {
|
|
401
384
|
return slice;
|
|
402
385
|
}
|
|
@@ -453,100 +436,23 @@ export const createPlugin = (options, pmPluginFactoryParams, syncBlockStore, api
|
|
|
453
436
|
removed: bodiedSyncBlockRemoved,
|
|
454
437
|
added: bodiedSyncBlockAdded
|
|
455
438
|
} = trackSyncBlocks(syncBlockStore.sourceManager.isSourceBlock, tr, state);
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
});
|
|
474
|
-
}
|
|
475
|
-
if (!isOffline) {
|
|
476
|
-
const {
|
|
477
|
-
removed: syncBlockRemoved,
|
|
478
|
-
added: syncBlockAdded
|
|
479
|
-
} = trackSyncBlocks(node => node.type.name === 'syncBlock', tr, state);
|
|
480
|
-
syncBlockRemoved.forEach(syncBlock => {
|
|
481
|
-
var _api$analytics3, _api$analytics3$actio;
|
|
482
|
-
api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : (_api$analytics3$actio = _api$analytics3.actions) === null || _api$analytics3$actio === void 0 ? void 0 : _api$analytics3$actio.fireAnalyticsEvent({
|
|
483
|
-
action: ACTION.DELETED,
|
|
484
|
-
actionSubject: ACTION_SUBJECT.SYNCED_BLOCK,
|
|
485
|
-
actionSubjectId: ACTION_SUBJECT_ID.REFERENCE_SYNCED_BLOCK_DELETE,
|
|
486
|
-
attributes: {
|
|
487
|
-
resourceId: syncBlock.attrs.resourceId,
|
|
488
|
-
blockInstanceId: syncBlock.attrs.localId
|
|
489
|
-
},
|
|
490
|
-
eventType: EVENT_TYPE.OPERATIONAL
|
|
491
|
-
});
|
|
492
|
-
});
|
|
493
|
-
syncBlockAdded.forEach(syncBlock => {
|
|
494
|
-
var _api$analytics4, _api$analytics4$actio;
|
|
495
|
-
api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : (_api$analytics4$actio = _api$analytics4.actions) === null || _api$analytics4$actio === void 0 ? void 0 : _api$analytics4$actio.fireAnalyticsEvent({
|
|
496
|
-
action: ACTION.INSERTED,
|
|
497
|
-
actionSubject: ACTION_SUBJECT.DOCUMENT,
|
|
498
|
-
actionSubjectId: ACTION_SUBJECT_ID.SYNCED_BLOCK,
|
|
499
|
-
attributes: {
|
|
500
|
-
resourceId: syncBlock.attrs.resourceId,
|
|
501
|
-
blockInstanceId: syncBlock.attrs.localId
|
|
502
|
-
},
|
|
503
|
-
eventType: EVENT_TYPE.TRACK
|
|
504
|
-
});
|
|
505
|
-
});
|
|
506
|
-
if (bodiedSyncBlockRemoved.length > 0) {
|
|
507
|
-
confirmationTransactionRef.current = tr;
|
|
508
|
-
return handleBodiedSyncBlockRemoval(bodiedSyncBlockRemoved, syncBlockStore, api, confirmationTransactionRef, getDeleteReason(tr));
|
|
509
|
-
}
|
|
510
|
-
if (bodiedSyncBlockAdded.length > 0) {
|
|
511
|
-
if (tr.getMeta(pmHistoryPluginKey)) {
|
|
512
|
-
// We don't allow bodiedSyncBlock creation via redo, however, we need to return true here to let transaction through so history can be updated properly.
|
|
513
|
-
// If we simply returns false, creation from redo is blocked as desired, but this results in editor showing redo as possible even though it's not.
|
|
514
|
-
// After true is returned here and the node is created, we delete the node in the filterTransaction immediately, which cancels out the creation
|
|
515
|
-
return true;
|
|
516
|
-
}
|
|
517
|
-
handleBodiedSyncBlockCreation(bodiedSyncBlockAdded, state, api);
|
|
518
|
-
return true;
|
|
519
|
-
}
|
|
520
|
-
showExtensionInSyncBlockWarningIfNeeded(tr, state, api, extensionFlagShown);
|
|
521
|
-
return true;
|
|
522
|
-
}
|
|
523
|
-
const {
|
|
524
|
-
removed: syncBlockRemoved,
|
|
525
|
-
added: syncBlockAdded
|
|
526
|
-
} = trackSyncBlocks(node => node.type.name === 'syncBlock', tr, state);
|
|
527
|
-
let errorFlag = false;
|
|
528
|
-
|
|
529
|
-
// Disable (bodied)syncBlock node deletion/creation/edition in offline mode and trigger an error flag instead
|
|
530
|
-
if (isConfirmedSyncBlockDeletion || bodiedSyncBlockRemoved.length > 0 || syncBlockRemoved.length > 0) {
|
|
531
|
-
errorFlag = FLAG_ID.CANNOT_DELETE_WHEN_OFFLINE;
|
|
532
|
-
} else if (bodiedSyncBlockAdded.length > 0 || syncBlockAdded.length > 0) {
|
|
533
|
-
errorFlag = FLAG_ID.CANNOT_CREATE_WHEN_OFFLINE;
|
|
534
|
-
} else if (hasEditInSyncBlock(tr, state)) {
|
|
535
|
-
errorFlag = FLAG_ID.CANNOT_EDIT_WHEN_OFFLINE;
|
|
536
|
-
}
|
|
537
|
-
if (errorFlag) {
|
|
538
|
-
deferDispatch(() => {
|
|
539
|
-
api === null || api === void 0 ? void 0 : api.core.actions.execute(({
|
|
540
|
-
tr
|
|
541
|
-
}) => tr.setMeta(syncedBlockPluginKey, {
|
|
542
|
-
activeFlag: {
|
|
543
|
-
id: errorFlag
|
|
544
|
-
}
|
|
545
|
-
}));
|
|
546
|
-
});
|
|
547
|
-
return false;
|
|
548
|
-
}
|
|
549
|
-
return true;
|
|
439
|
+
return isOffline ? filterTransactionOffline({
|
|
440
|
+
tr,
|
|
441
|
+
state,
|
|
442
|
+
api,
|
|
443
|
+
isConfirmedSyncBlockDeletion,
|
|
444
|
+
bodiedSyncBlockRemoved,
|
|
445
|
+
bodiedSyncBlockAdded
|
|
446
|
+
}) : filterTransactionOnline({
|
|
447
|
+
tr,
|
|
448
|
+
state,
|
|
449
|
+
syncBlockStore,
|
|
450
|
+
api,
|
|
451
|
+
confirmationTransactionRef,
|
|
452
|
+
bodiedSyncBlockRemoved,
|
|
453
|
+
bodiedSyncBlockAdded,
|
|
454
|
+
extensionFlagShown
|
|
455
|
+
});
|
|
550
456
|
},
|
|
551
457
|
appendTransaction: (trs, oldState, newState) => {
|
|
552
458
|
trs.filter(tr => tr.docChanged).forEach(tr => {
|
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import { bind } from 'bind-event-listener';
|
|
2
2
|
import { ACTION, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
|
|
3
|
-
import { Experience, EXPERIENCE_ID, ExperienceCheckDomMutation, ExperienceCheckTimeout, getNodeQuery, getPopupContainerFromEditorView, popupWithNestedElement } from '@atlaskit/editor-common/experiences';
|
|
3
|
+
import { Experience, EXPERIENCE_ID, ExperienceCheckDomMutation, ExperienceCheckTimeout, getNodeQuery, getPopupContainerFromEditorView, popupWithNestedElement, getSelectionAncestorDOM } from '@atlaskit/editor-common/experiences';
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
5
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
6
|
+
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
7
|
import { SYNCED_BLOCK_BUTTON_TEST_ID } from '../types';
|
|
7
8
|
const TIMEOUT_DURATION = 30000;
|
|
8
9
|
const pluginKey = new PluginKey('syncedBlockMenuAndToolbarExperience');
|
|
@@ -14,10 +15,13 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
14
15
|
dispatchAnalyticsEvent
|
|
15
16
|
}) => {
|
|
16
17
|
let popupsTargetEl;
|
|
17
|
-
|
|
18
|
+
const editorViewRef = {
|
|
19
|
+
current: undefined
|
|
20
|
+
};
|
|
18
21
|
const getPopupsTarget = () => {
|
|
19
22
|
if (!popupsTargetEl) {
|
|
20
|
-
|
|
23
|
+
var _editorViewRef$curren;
|
|
24
|
+
popupsTargetEl = refs.popupsMountPoint || refs.wrapperElement || getPopupContainerFromEditorView(editorViewRef === null || editorViewRef === void 0 ? void 0 : (_editorViewRef$curren = editorViewRef.current) === null || _editorViewRef$curren === void 0 ? void 0 : _editorViewRef$curren.dom);
|
|
21
25
|
}
|
|
22
26
|
return popupsTargetEl;
|
|
23
27
|
};
|
|
@@ -27,7 +31,7 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
27
31
|
dispatchAnalyticsEvent,
|
|
28
32
|
checks: [new ExperienceCheckTimeout({
|
|
29
33
|
durationMs: TIMEOUT_DURATION
|
|
30
|
-
}), syncedBlockAddedToDomCheck(refs)]
|
|
34
|
+
}), syncedBlockAddedToDomCheck(refs, editorViewRef)]
|
|
31
35
|
});
|
|
32
36
|
const createSourceBlockMenuExperience = new Experience(EXPERIENCE_ID.MENU_ACTION, {
|
|
33
37
|
action: ACTION.SYNCED_BLOCK_CREATE,
|
|
@@ -35,7 +39,7 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
35
39
|
dispatchAnalyticsEvent,
|
|
36
40
|
checks: [new ExperienceCheckTimeout({
|
|
37
41
|
durationMs: TIMEOUT_DURATION
|
|
38
|
-
}), syncedBlockAddedToDomCheck(refs)]
|
|
42
|
+
}), syncedBlockAddedToDomCheck(refs, editorViewRef)]
|
|
39
43
|
});
|
|
40
44
|
const createSourceQuickInsertMenuExperience = new Experience(EXPERIENCE_ID.MENU_ACTION, {
|
|
41
45
|
action: ACTION.SYNCED_BLOCK_CREATE,
|
|
@@ -43,7 +47,7 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
43
47
|
dispatchAnalyticsEvent,
|
|
44
48
|
checks: [new ExperienceCheckTimeout({
|
|
45
49
|
durationMs: TIMEOUT_DURATION
|
|
46
|
-
}), syncedBlockAddedToDomCheck(refs)]
|
|
50
|
+
}), syncedBlockAddedToDomCheck(refs, editorViewRef)]
|
|
47
51
|
});
|
|
48
52
|
const deleteReferenceSyncedBlockExperience = new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
49
53
|
action: ACTION.REFERENCE_SYNCED_BLOCK_DELETE,
|
|
@@ -51,7 +55,7 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
51
55
|
dispatchAnalyticsEvent,
|
|
52
56
|
checks: [new ExperienceCheckTimeout({
|
|
53
57
|
durationMs: TIMEOUT_DURATION
|
|
54
|
-
}), referenceSyncBlockRemovedFromDomCheck(refs)]
|
|
58
|
+
}), referenceSyncBlockRemovedFromDomCheck(refs, editorViewRef)]
|
|
55
59
|
});
|
|
56
60
|
const unsyncReferenceSyncedBlockExperience = new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
57
61
|
action: ACTION.REFERENCE_SYNCED_BLOCK_UNSYNC,
|
|
@@ -59,7 +63,7 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
59
63
|
dispatchAnalyticsEvent,
|
|
60
64
|
checks: [new ExperienceCheckTimeout({
|
|
61
65
|
durationMs: TIMEOUT_DURATION
|
|
62
|
-
}), referenceSyncBlockRemovedFromDomCheck(refs)]
|
|
66
|
+
}), referenceSyncBlockRemovedFromDomCheck(refs, editorViewRef)]
|
|
63
67
|
});
|
|
64
68
|
const unsyncSourceSyncedBlockExperience = new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
65
69
|
action: ACTION.SYNCED_BLOCK_UNSYNC,
|
|
@@ -67,7 +71,7 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
67
71
|
dispatchAnalyticsEvent,
|
|
68
72
|
checks: [new ExperienceCheckTimeout({
|
|
69
73
|
durationMs: TIMEOUT_DURATION
|
|
70
|
-
}), syncBlockDeleteConfirmationModalAddedCheck(
|
|
74
|
+
}), syncBlockDeleteConfirmationModalAddedCheck()]
|
|
71
75
|
});
|
|
72
76
|
const deleteSourceSyncedBlockExperience = new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
73
77
|
action: ACTION.SYNCED_BLOCK_DELETE,
|
|
@@ -75,7 +79,7 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
75
79
|
dispatchAnalyticsEvent,
|
|
76
80
|
checks: [new ExperienceCheckTimeout({
|
|
77
81
|
durationMs: TIMEOUT_DURATION
|
|
78
|
-
}), syncBlockDeleteConfirmationModalAddedCheck(
|
|
82
|
+
}), syncBlockDeleteConfirmationModalAddedCheck()]
|
|
79
83
|
});
|
|
80
84
|
const syncedLocationsExperience = new Experience(EXPERIENCE_ID.TOOLBAR_ACTION, {
|
|
81
85
|
action: ACTION.SYNCED_BLOCK_VIEW_SYNCED_LOCATIONS,
|
|
@@ -83,7 +87,7 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
83
87
|
dispatchAnalyticsEvent,
|
|
84
88
|
checks: [new ExperienceCheckTimeout({
|
|
85
89
|
durationMs: TIMEOUT_DURATION
|
|
86
|
-
}), syncedLocationsDropdownOpenedCheck(
|
|
90
|
+
}), syncedLocationsDropdownOpenedCheck()]
|
|
87
91
|
});
|
|
88
92
|
const unbindClickListener = bind(document, {
|
|
89
93
|
type: 'click',
|
|
@@ -128,11 +132,11 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
128
132
|
if (!typeaheadPopup || !(typeaheadPopup instanceof HTMLElement)) {
|
|
129
133
|
return;
|
|
130
134
|
}
|
|
131
|
-
const
|
|
132
|
-
if (!
|
|
135
|
+
const targetElement = fg('platform_synced_block_fix_experience_tracking') ? typeaheadPopup.querySelector('[role="option"][aria-selected="true"]') : typeaheadPopup.querySelector('[role="option"]');
|
|
136
|
+
if (!targetElement || !(targetElement instanceof HTMLElement)) {
|
|
133
137
|
return;
|
|
134
138
|
}
|
|
135
|
-
const testId =
|
|
139
|
+
const testId = targetElement.dataset.testid;
|
|
136
140
|
if (testId === SYNCED_BLOCK_BUTTON_TEST_ID.quickInsertCreate) {
|
|
137
141
|
createSourceQuickInsertMenuExperience.start();
|
|
138
142
|
}
|
|
@@ -144,8 +148,8 @@ export const getMenuAndToolbarExperiencesPlugin = ({
|
|
|
144
148
|
});
|
|
145
149
|
return new SafePlugin({
|
|
146
150
|
key: pluginKey,
|
|
147
|
-
view:
|
|
148
|
-
|
|
151
|
+
view: view => {
|
|
152
|
+
editorViewRef.current = view;
|
|
149
153
|
return {
|
|
150
154
|
destroy: () => {
|
|
151
155
|
createSourcePrimaryToolbarExperience.abort({
|
|
@@ -260,7 +264,7 @@ const getTarget = containerElement => {
|
|
|
260
264
|
}
|
|
261
265
|
return targetEl;
|
|
262
266
|
};
|
|
263
|
-
const syncedBlockAddedToDomCheck = refs => new ExperienceCheckDomMutation({
|
|
267
|
+
const syncedBlockAddedToDomCheck = (refs, editorViewRef) => new ExperienceCheckDomMutation({
|
|
264
268
|
onDomMutation: ({
|
|
265
269
|
mutations
|
|
266
270
|
}) => {
|
|
@@ -272,12 +276,22 @@ const syncedBlockAddedToDomCheck = refs => new ExperienceCheckDomMutation({
|
|
|
272
276
|
return undefined;
|
|
273
277
|
},
|
|
274
278
|
observeConfig: () => {
|
|
275
|
-
|
|
276
|
-
|
|
279
|
+
var _editorViewRef$curren2;
|
|
280
|
+
return [{
|
|
281
|
+
target: fg('platform_synced_block_fix_experience_tracking') ? editorViewRef === null || editorViewRef === void 0 ? void 0 : (_editorViewRef$curren2 = editorViewRef.current) === null || _editorViewRef$curren2 === void 0 ? void 0 : _editorViewRef$curren2.dom : getTarget(refs.containerElement),
|
|
277
282
|
options: {
|
|
278
283
|
childList: true
|
|
279
284
|
}
|
|
280
|
-
}
|
|
285
|
+
},
|
|
286
|
+
// When wrapping a node with breakout mark with sync block, breakout dom is reused
|
|
287
|
+
// hence we need to observe subtree to catch sync block mutation
|
|
288
|
+
...(fg('platform_synced_block_fix_experience_tracking') ? [{
|
|
289
|
+
target: getSelectionAncestorDOM(editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current),
|
|
290
|
+
options: {
|
|
291
|
+
childList: true,
|
|
292
|
+
subtree: true
|
|
293
|
+
}
|
|
294
|
+
}] : [])];
|
|
281
295
|
}
|
|
282
296
|
});
|
|
283
297
|
const isBodiedSyncBlockAddedInMutation = ({
|
|
@@ -287,7 +301,7 @@ const isBodiedSyncBlockAddedInMutation = ({
|
|
|
287
301
|
return type === 'childList' && [...addedNodes].some(isBodiedSyncBlockWithinNode);
|
|
288
302
|
};
|
|
289
303
|
const isBodiedSyncBlockWithinNode = node => getNodeQuery('[data-prosemirror-node-name="bodiedSyncBlock"]')(node);
|
|
290
|
-
const referenceSyncBlockRemovedFromDomCheck = refs => new ExperienceCheckDomMutation({
|
|
304
|
+
const referenceSyncBlockRemovedFromDomCheck = (refs, editorViewRef) => new ExperienceCheckDomMutation({
|
|
291
305
|
onDomMutation: ({
|
|
292
306
|
mutations
|
|
293
307
|
}) => {
|
|
@@ -299,12 +313,19 @@ const referenceSyncBlockRemovedFromDomCheck = refs => new ExperienceCheckDomMuta
|
|
|
299
313
|
return undefined;
|
|
300
314
|
},
|
|
301
315
|
observeConfig: () => {
|
|
302
|
-
|
|
303
|
-
|
|
316
|
+
var _editorViewRef$curren3;
|
|
317
|
+
return [{
|
|
318
|
+
target: fg('platform_synced_block_fix_experience_tracking') ? editorViewRef === null || editorViewRef === void 0 ? void 0 : (_editorViewRef$curren3 = editorViewRef.current) === null || _editorViewRef$curren3 === void 0 ? void 0 : _editorViewRef$curren3.dom : getTarget(refs.containerElement),
|
|
304
319
|
options: {
|
|
305
320
|
childList: true
|
|
306
321
|
}
|
|
307
|
-
}
|
|
322
|
+
}, ...(fg('platform_synced_block_fix_experience_tracking') ? [{
|
|
323
|
+
target: getSelectionAncestorDOM(editorViewRef === null || editorViewRef === void 0 ? void 0 : editorViewRef.current),
|
|
324
|
+
options: {
|
|
325
|
+
childList: true,
|
|
326
|
+
subtree: true
|
|
327
|
+
}
|
|
328
|
+
}] : [])];
|
|
308
329
|
}
|
|
309
330
|
});
|
|
310
331
|
const isSyncBlockRemovedInMutation = ({
|
|
@@ -314,7 +335,7 @@ const isSyncBlockRemovedInMutation = ({
|
|
|
314
335
|
return type === 'childList' && [...removedNodes].some(isSyncBlockWithinNode);
|
|
315
336
|
};
|
|
316
337
|
const isSyncBlockWithinNode = node => getNodeQuery('[data-prosemirror-node-name="syncBlock"]')(node);
|
|
317
|
-
const syncBlockDeleteConfirmationModalAddedCheck =
|
|
338
|
+
const syncBlockDeleteConfirmationModalAddedCheck = () => new ExperienceCheckDomMutation({
|
|
318
339
|
onDomMutation: ({
|
|
319
340
|
mutations
|
|
320
341
|
}) => {
|
|
@@ -342,7 +363,7 @@ const isDeleteConfirmationModalAddedInMutation = ({
|
|
|
342
363
|
return type === 'childList' && [...addedNodes].some(isDeleteConfirmationModalWithinNode);
|
|
343
364
|
};
|
|
344
365
|
const isDeleteConfirmationModalWithinNode = node => getNodeQuery('[data-testid="sync-block-delete-confirmation"]')(node);
|
|
345
|
-
const syncedLocationsDropdownOpenedCheck =
|
|
366
|
+
const syncedLocationsDropdownOpenedCheck = () => new ExperienceCheckDomMutation({
|
|
346
367
|
onDomMutation: ({
|
|
347
368
|
mutations
|
|
348
369
|
}) => {
|
|
@@ -2,7 +2,6 @@ import { expandSelectionToBlockRange } from '@atlaskit/editor-common/selection';
|
|
|
2
2
|
import { Fragment } from '@atlaskit/editor-prosemirror/model';
|
|
3
3
|
import { ReplaceAroundStep, ReplaceStep } from '@atlaskit/editor-prosemirror/transform';
|
|
4
4
|
import { findParentNodeOfType, findParentNodeOfTypeClosestToPos, findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
|
|
5
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
6
5
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
7
6
|
|
|
8
7
|
/**
|
|
@@ -10,11 +9,7 @@ import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
|
10
9
|
* Used to avoid re-entrant ProseMirror dispatch cycles.
|
|
11
10
|
*/
|
|
12
11
|
export const deferDispatch = fn => {
|
|
13
|
-
|
|
14
|
-
queueMicrotask(fn);
|
|
15
|
-
} else {
|
|
16
|
-
setTimeout(fn, 0);
|
|
17
|
-
}
|
|
12
|
+
queueMicrotask(fn);
|
|
18
13
|
};
|
|
19
14
|
export const findSyncBlock = (schema, selection) => {
|
|
20
15
|
const {
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { syncBlock, bodiedSyncBlock } from '@atlaskit/adf-schema';
|
|
3
3
|
import { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
|
|
4
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
5
4
|
import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
|
|
6
5
|
import { flushBodiedSyncBlocks, flushSyncBlocks } from './editor-actions';
|
|
7
6
|
import { copySyncedBlockReferenceToClipboardEditorCommand, createSyncedBlock } from './editor-commands';
|
|
@@ -117,7 +116,7 @@ export const syncedBlockPlugin = ({
|
|
|
117
116
|
syncBlockStore: currentSyncBlockStore,
|
|
118
117
|
bodiedSyncBlockDeletionStatus,
|
|
119
118
|
retryCreationPosMap,
|
|
120
|
-
hasUnsavedBodiedSyncBlockChanges
|
|
119
|
+
hasUnsavedBodiedSyncBlockChanges
|
|
121
120
|
};
|
|
122
121
|
}
|
|
123
122
|
};
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import { useEffect } from 'react';
|
|
2
2
|
import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
|
|
3
3
|
import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
|
|
4
|
-
export const SYNC_BLOCK_FETCH_INTERVAL = 3000;
|
|
5
|
-
|
|
6
4
|
// Component that manages synced block data synchronization.
|
|
7
5
|
// Uses provider-based GraphQL subscriptions for updates when online.
|
|
8
6
|
// Falls back to polling at regular intervals when offline.
|
|
@@ -23,19 +21,5 @@ export const SyncBlockRefresher = ({
|
|
|
23
21
|
const useRealTimeSubscriptions = isOnline;
|
|
24
22
|
syncBlockStoreManager.referenceManager.setRealTimeSubscriptionsEnabled(useRealTimeSubscriptions);
|
|
25
23
|
}, [syncBlockStoreManager, isOnline]);
|
|
26
|
-
useEffect(() => {
|
|
27
|
-
if (isOnline) {
|
|
28
|
-
return;
|
|
29
|
-
}
|
|
30
|
-
const interval = window.setInterval(() => {
|
|
31
|
-
var _document;
|
|
32
|
-
if (((_document = document) === null || _document === void 0 ? void 0 : _document.visibilityState) === 'visible') {
|
|
33
|
-
syncBlockStoreManager.referenceManager.refreshSubscriptions();
|
|
34
|
-
}
|
|
35
|
-
}, SYNC_BLOCK_FETCH_INTERVAL);
|
|
36
|
-
return () => {
|
|
37
|
-
window.clearInterval(interval);
|
|
38
|
-
};
|
|
39
|
-
}, [syncBlockStoreManager, isOnline]);
|
|
40
24
|
return null;
|
|
41
25
|
};
|
|
@@ -12,7 +12,6 @@ import ReactNodeView from '@atlaskit/editor-common/react-node-view';
|
|
|
12
12
|
import { BodiedSyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
|
|
13
13
|
import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
|
|
14
14
|
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
15
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
16
15
|
import { BodiedSyncBlockWrapper } from '../ui/BodiedSyncBlockWrapper';
|
|
17
16
|
import { SyncBlockLabel } from '../ui/SyncBlockLabel';
|
|
18
17
|
var toDOMOld = function toDOMOld() {
|
|
@@ -110,7 +109,7 @@ var BodiedSyncBlockOld = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
110
109
|
dom = _DOMSerializer$render.dom,
|
|
111
110
|
contentDOM = _DOMSerializer$render.contentDOM;
|
|
112
111
|
// In SSR, the first check won't work, so fallback to nodeType check
|
|
113
|
-
if (dom instanceof HTMLElement || dom.nodeType === 1
|
|
112
|
+
if (dom instanceof HTMLElement || dom.nodeType === 1) {
|
|
114
113
|
this.updateContentEditable({
|
|
115
114
|
contentDOM: contentDOM
|
|
116
115
|
});
|