@atlaskit/editor-plugin-synced-block 5.1.9 → 5.1.10

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.
Files changed (55) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/dist/cjs/editor-commands/index.js +2 -2
  3. package/dist/cjs/pm-plugins/experience-tracking/create-reference-experience.js +26 -26
  4. package/dist/cjs/pm-plugins/experience-tracking/create-source-experience.js +14 -30
  5. package/dist/cjs/pm-plugins/experience-tracking/delete-reference-experience.js +175 -0
  6. package/dist/cjs/pm-plugins/experience-tracking/delete-source-experience.js +103 -0
  7. package/dist/cjs/pm-plugins/experience-tracking/get-experience-tracking-plugins.js +30 -0
  8. package/dist/cjs/pm-plugins/experience-tracking/provider-only-experiences.js +128 -0
  9. package/dist/cjs/pm-plugins/utils/experience-tracking-utils.js +85 -0
  10. package/dist/cjs/types/index.js +5 -2
  11. package/dist/cjs/ui/CreateSyncedBlockDropdownItem.js +40 -8
  12. package/dist/cjs/ui/DeleteConfirmationModal.js +3 -1
  13. package/dist/cjs/ui/floating-toolbar.js +4 -2
  14. package/dist/es2019/editor-commands/index.js +2 -2
  15. package/dist/es2019/pm-plugins/experience-tracking/create-reference-experience.js +27 -23
  16. package/dist/es2019/pm-plugins/experience-tracking/create-source-experience.js +14 -27
  17. package/dist/es2019/pm-plugins/experience-tracking/delete-reference-experience.js +181 -0
  18. package/dist/es2019/pm-plugins/experience-tracking/delete-source-experience.js +98 -0
  19. package/dist/es2019/pm-plugins/experience-tracking/get-experience-tracking-plugins.js +24 -0
  20. package/dist/es2019/pm-plugins/experience-tracking/provider-only-experiences.js +127 -0
  21. package/dist/es2019/pm-plugins/utils/experience-tracking-utils.js +65 -0
  22. package/dist/es2019/types/index.js +4 -1
  23. package/dist/es2019/ui/CreateSyncedBlockDropdownItem.js +38 -3
  24. package/dist/es2019/ui/DeleteConfirmationModal.js +3 -1
  25. package/dist/es2019/ui/floating-toolbar.js +3 -1
  26. package/dist/esm/editor-commands/index.js +2 -2
  27. package/dist/esm/pm-plugins/experience-tracking/create-reference-experience.js +26 -25
  28. package/dist/esm/pm-plugins/experience-tracking/create-source-experience.js +14 -29
  29. package/dist/esm/pm-plugins/experience-tracking/delete-reference-experience.js +169 -0
  30. package/dist/esm/pm-plugins/experience-tracking/delete-source-experience.js +97 -0
  31. package/dist/esm/pm-plugins/experience-tracking/get-experience-tracking-plugins.js +30 -0
  32. package/dist/esm/pm-plugins/experience-tracking/provider-only-experiences.js +122 -0
  33. package/dist/esm/pm-plugins/utils/experience-tracking-utils.js +79 -0
  34. package/dist/esm/types/index.js +4 -1
  35. package/dist/esm/ui/CreateSyncedBlockDropdownItem.js +40 -8
  36. package/dist/esm/ui/DeleteConfirmationModal.js +3 -1
  37. package/dist/esm/ui/floating-toolbar.js +4 -2
  38. package/dist/types/pm-plugins/experience-tracking/create-reference-experience.d.ts +2 -9
  39. package/dist/types/pm-plugins/experience-tracking/create-source-experience.d.ts +4 -15
  40. package/dist/types/pm-plugins/experience-tracking/delete-reference-experience.d.ts +13 -0
  41. package/dist/types/pm-plugins/experience-tracking/delete-source-experience.d.ts +12 -0
  42. package/dist/types/pm-plugins/experience-tracking/get-experience-tracking-plugins.d.ts +2 -13
  43. package/dist/types/pm-plugins/experience-tracking/provider-only-experiences.d.ts +3 -0
  44. package/dist/types/pm-plugins/utils/experience-tracking-utils.d.ts +9 -0
  45. package/dist/types/types/index.d.ts +15 -0
  46. package/dist/types-ts4.5/pm-plugins/experience-tracking/create-reference-experience.d.ts +2 -9
  47. package/dist/types-ts4.5/pm-plugins/experience-tracking/create-source-experience.d.ts +4 -15
  48. package/dist/types-ts4.5/pm-plugins/experience-tracking/delete-reference-experience.d.ts +13 -0
  49. package/dist/types-ts4.5/pm-plugins/experience-tracking/delete-source-experience.d.ts +12 -0
  50. package/dist/types-ts4.5/pm-plugins/experience-tracking/get-experience-tracking-plugins.d.ts +2 -13
  51. package/dist/types-ts4.5/pm-plugins/experience-tracking/provider-only-experiences.d.ts +3 -0
  52. package/dist/types-ts4.5/pm-plugins/utils/experience-tracking-utils.d.ts +9 -0
  53. package/dist/types-ts4.5/types/index.d.ts +15 -0
  54. package/package.json +5 -5
  55. package/build/tsconfig.json +0 -22
@@ -0,0 +1,169 @@
1
+ import { bind } from 'bind-event-listener';
2
+ import { ACTION_SUBJECT, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
3
+ import { Experience, ExperienceCheckDomMutation, ExperienceCheckTimeout } from '@atlaskit/editor-common/experiences';
4
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
+ import { EXPERIENCE_ABORT_REASON } from '../../types';
7
+ import { getRemovedResourceIds, getTarget, wasSyncBlockDeletedOrAddedByHistory } from '../utils/experience-tracking-utils';
8
+ var pluginKey = new PluginKey('deleteReferenceSyncBlockExperience');
9
+ var START_METHOD = {
10
+ ELEMENT_TOOLBAR: 'element-toolbar',
11
+ DELETE: 'delete',
12
+ TYPED_OVER: 'typed-over',
13
+ CUT: 'cut',
14
+ UNDO: 'undo',
15
+ REDO: 'redo'
16
+ };
17
+
18
+ /**
19
+ * This experience tracks when a reference sync block is deleted.
20
+ *
21
+ * Start: When user deletes ref sync block from toolbar, presses delete when cursor is in front of ref sync block,
22
+ * presses any key with a ref sync block selected, cuts with a ref sync block selected, triggers undo/redo that deletes a ref sync block
23
+ * Success: When the sync block is removed from the DOM within 2000ms of start
24
+ * Failure: When 2000ms passes without the reference sync block being removed from the DOM
25
+ */
26
+ export var getDeleteReferenceExperiencePlugin = function getDeleteReferenceExperiencePlugin(_ref) {
27
+ var refs = _ref.refs,
28
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
29
+ syncBlockStore = _ref.syncBlockStore;
30
+ var experience = getDeleteReferenceExperience({
31
+ refs: refs,
32
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent
33
+ });
34
+ syncBlockStore.sourceManager.setDeleteExperience(experience);
35
+ var unbindClickListener = bind(document, {
36
+ type: 'click',
37
+ listener: function listener(event) {
38
+ var target = event.target;
39
+ if (!target) {
40
+ return;
41
+ }
42
+ var button = target.closest('button[data-testid]');
43
+ if (!button || !(button instanceof HTMLButtonElement)) {
44
+ return;
45
+ }
46
+ var testId = button.dataset.testid;
47
+ if (isReferenceSyncedBlockDeleteButtonId(testId)) {
48
+ experience.start({
49
+ method: START_METHOD.ELEMENT_TOOLBAR
50
+ });
51
+ }
52
+ }
53
+ });
54
+ return new SafePlugin({
55
+ key: pluginKey,
56
+ props: {
57
+ handleDOMEvents: {
58
+ cut: function cut(view) {
59
+ var state = view.state;
60
+ if (hasSyncBlockInSelection(state.selection)) {
61
+ experience.start({
62
+ method: START_METHOD.CUT
63
+ });
64
+ }
65
+ return false;
66
+ },
67
+ keydown: function keydown(view, event) {
68
+ var state = view.state;
69
+ var hasSelection = hasSyncBlockInSelection(state.selection);
70
+ var hasAdjacent = hasSyncBlockBeforeCursor(state.selection);
71
+ if (hasSelection) {
72
+ experience.start({
73
+ method: START_METHOD.TYPED_OVER
74
+ });
75
+ }
76
+ if (isDeleteKey(event.key) && hasAdjacent) {
77
+ experience.start({
78
+ method: START_METHOD.DELETE
79
+ });
80
+ }
81
+ return false;
82
+ }
83
+ }
84
+ },
85
+ appendTransaction: function appendTransaction(transactions, oldState, newState) {
86
+ transactions.forEach(function (tr) {
87
+ var _wasSyncBlockDeletedO = wasSyncBlockDeletedOrAddedByHistory(tr, oldState, newState),
88
+ hasDeletedSyncBlock = _wasSyncBlockDeletedO.hasDeletedSyncBlock,
89
+ isUndo = _wasSyncBlockDeletedO.isUndo;
90
+ if (hasDeletedSyncBlock) {
91
+ experience.start({
92
+ method: isUndo ? START_METHOD.UNDO : START_METHOD.REDO
93
+ });
94
+ }
95
+ });
96
+ return null;
97
+ },
98
+ view: function view() {
99
+ return {
100
+ destroy: function destroy() {
101
+ experience.abort({
102
+ reason: EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
103
+ });
104
+ unbindClickListener();
105
+ }
106
+ };
107
+ }
108
+ });
109
+ };
110
+ export var getDeleteReferenceExperience = function getDeleteReferenceExperience(_ref2) {
111
+ var refs = _ref2.refs,
112
+ dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
113
+ return new Experience(ACTION_SUBJECT.SYNCED_BLOCK, {
114
+ actionSubjectId: ACTION_SUBJECT_ID.REFERENCE_SYNCED_BLOCK_DELETE,
115
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
116
+ checks: [new ExperienceCheckTimeout({
117
+ durationMs: 2000
118
+ }), new ExperienceCheckDomMutation({
119
+ onDomMutation: function onDomMutation(_ref3) {
120
+ var mutations = _ref3.mutations;
121
+ var deletedResourceIds = getRemovedResourceIds(mutations, '[data-prosemirror-node-name="syncBlock"]');
122
+ if (deletedResourceIds.length > 0) {
123
+ return {
124
+ status: 'success',
125
+ metadata: {
126
+ deletedResourceIds: deletedResourceIds
127
+ }
128
+ };
129
+ }
130
+ return undefined;
131
+ },
132
+ observeConfig: function observeConfig() {
133
+ return {
134
+ target: getTarget(refs.containerElement),
135
+ options: {
136
+ childList: true
137
+ }
138
+ };
139
+ }
140
+ })]
141
+ });
142
+ };
143
+ var isReferenceSyncedBlockDeleteButtonId = function isReferenceSyncedBlockDeleteButtonId(testId) {
144
+ return testId === 'reference-synced-block-delete-button';
145
+ };
146
+ var isDeleteKey = function isDeleteKey(key) {
147
+ return key === 'Delete' || key === 'Backspace';
148
+ };
149
+ var hasSyncBlockInSelection = function hasSyncBlockInSelection(selection) {
150
+ var syncBlock = selection.$from.doc.type.schema.nodes.syncBlock;
151
+ var found = false;
152
+ selection.$from.doc.nodesBetween(selection.from, selection.to, function (node) {
153
+ if (node.type === syncBlock) {
154
+ found = true;
155
+ return false;
156
+ }
157
+ // sync block nodes can only be found at the top level
158
+ return false;
159
+ });
160
+ return found;
161
+ };
162
+ var hasSyncBlockBeforeCursor = function hasSyncBlockBeforeCursor(selection) {
163
+ if (!selection.empty) {
164
+ return false;
165
+ }
166
+ var syncBlock = selection.$from.doc.type.schema.nodes.syncBlock;
167
+ var nodeBefore = selection.$from.nodeBefore;
168
+ return (nodeBefore === null || nodeBefore === void 0 ? void 0 : nodeBefore.type) === syncBlock;
169
+ };
@@ -0,0 +1,97 @@
1
+ import { bind } from 'bind-event-listener';
2
+ import { ACTION_SUBJECT, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
3
+ import { Experience, ExperienceCheckDomMutation, ExperienceCheckTimeout } from '@atlaskit/editor-common/experiences';
4
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
+ import { EXPERIENCE_ABORT_REASON } from '../../types';
7
+ import { getRemovedResourceIds, getTarget } from '../utils/experience-tracking-utils';
8
+ var pluginKey = new PluginKey('deleteSourceSyncBlockExperience');
9
+ var START_METHOD = {
10
+ DELETE_CONFIRM_BUTTON: 'delete-confirm-button'
11
+ };
12
+
13
+ /**
14
+ * This experience tracks when a source sync block is deleted.
15
+ *
16
+ * Start: When user clicks the delete button in the delete modal
17
+ * Success: When the sync block is removed from the DOM within 2000ms of start
18
+ * Failure: When 2000ms passes without the source sync block being removed from the DOM
19
+ */
20
+ export var getDeleteSourceExperiencePlugin = function getDeleteSourceExperiencePlugin(_ref) {
21
+ var refs = _ref.refs,
22
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
23
+ syncBlockStore = _ref.syncBlockStore;
24
+ var experience = getDeleteSourceExperience({
25
+ refs: refs,
26
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent
27
+ });
28
+ syncBlockStore.sourceManager.setDeleteExperience(experience);
29
+ var unbindClickListener = bind(document, {
30
+ type: 'click',
31
+ listener: function listener(event) {
32
+ var target = event.target;
33
+ if (!target) {
34
+ return;
35
+ }
36
+ var button = target.closest('button[data-testid]');
37
+ if (!button || !(button instanceof HTMLButtonElement)) {
38
+ return;
39
+ }
40
+ var testId = button.dataset.testid;
41
+ if (isSyncedBlockDeleteButtonId(testId)) {
42
+ experience.start({
43
+ method: START_METHOD.DELETE_CONFIRM_BUTTON
44
+ });
45
+ }
46
+ }
47
+ });
48
+ return new SafePlugin({
49
+ key: pluginKey,
50
+ view: function view() {
51
+ return {
52
+ destroy: function destroy() {
53
+ experience.abort({
54
+ reason: EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
55
+ });
56
+ unbindClickListener();
57
+ }
58
+ };
59
+ }
60
+ });
61
+ };
62
+ export var getDeleteSourceExperience = function getDeleteSourceExperience(_ref2) {
63
+ var refs = _ref2.refs,
64
+ dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
65
+ return new Experience(ACTION_SUBJECT.SYNCED_BLOCK, {
66
+ actionSubjectId: ACTION_SUBJECT_ID.SYNCED_BLOCK_DELETE,
67
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
68
+ checks: [new ExperienceCheckTimeout({
69
+ durationMs: 2000
70
+ }), new ExperienceCheckDomMutation({
71
+ onDomMutation: function onDomMutation(_ref3) {
72
+ var mutations = _ref3.mutations;
73
+ var deletedResourceIds = getRemovedResourceIds(mutations, '[data-prosemirror-node-name="bodiedSyncBlock"]');
74
+ if (deletedResourceIds.length > 0) {
75
+ return {
76
+ status: 'success',
77
+ metadata: {
78
+ deletedResourceIds: deletedResourceIds
79
+ }
80
+ };
81
+ }
82
+ return undefined;
83
+ },
84
+ observeConfig: function observeConfig() {
85
+ return {
86
+ target: getTarget(refs.containerElement),
87
+ options: {
88
+ childList: true
89
+ }
90
+ };
91
+ }
92
+ })]
93
+ });
94
+ };
95
+ var isSyncedBlockDeleteButtonId = function isSyncedBlockDeleteButtonId(testId) {
96
+ return testId === 'synced-block-delete-confirmation-modal-delete-button';
97
+ };
@@ -1,5 +1,8 @@
1
1
  import { getCreateReferenceExperiencePlugin } from "./create-reference-experience";
2
2
  import { getCreateSourceExperiencePlugin } from "./create-source-experience";
3
+ import { getDeleteReferenceExperiencePlugin } from "./delete-reference-experience";
4
+ import { getDeleteSourceExperiencePlugin } from "./delete-source-experience";
5
+ import { getProviderOnlyExperiencesPlugin } from "./provider-only-experiences";
3
6
  export var getExperienceTrackingPlugins = function getExperienceTrackingPlugins(_ref) {
4
7
  var refs = _ref.refs,
5
8
  dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
@@ -21,5 +24,32 @@ export var getExperienceTrackingPlugins = function getExperienceTrackingPlugins(
21
24
  syncBlockStore: syncBlockStore
22
25
  });
23
26
  }
27
+ }, {
28
+ name: 'deleteSourceExperiencePlugin',
29
+ plugin: function plugin() {
30
+ return getDeleteSourceExperiencePlugin({
31
+ refs: refs,
32
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
33
+ syncBlockStore: syncBlockStore
34
+ });
35
+ }
36
+ }, {
37
+ name: 'deleteReferenceExperiencePlugin',
38
+ plugin: function plugin() {
39
+ return getDeleteReferenceExperiencePlugin({
40
+ refs: refs,
41
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
42
+ syncBlockStore: syncBlockStore
43
+ });
44
+ }
45
+ }, {
46
+ name: 'providerOnlySyncedBlockExperiencesPlugin',
47
+ plugin: function plugin() {
48
+ return getProviderOnlyExperiencesPlugin({
49
+ refs: refs,
50
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
51
+ syncBlockStore: syncBlockStore
52
+ });
53
+ }
24
54
  }];
25
55
  };
@@ -0,0 +1,122 @@
1
+ import { ACTION_SUBJECT, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
2
+ import { Experience, ExperienceCheckTimeout } from '@atlaskit/editor-common/experiences';
3
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
+ import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
+ import { EXPERIENCE_ABORT_REASON } from '../../types';
6
+ var pluginKey = new PluginKey('providerOnlySyncBlockExperiences');
7
+ export var getProviderOnlyExperiencesPlugin = function getProviderOnlyExperiencesPlugin(_ref) {
8
+ var refs = _ref.refs,
9
+ dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
10
+ syncBlockStore = _ref.syncBlockStore;
11
+ var saveSourceExperience = getSaveSourceExperience({
12
+ refs: refs,
13
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent
14
+ });
15
+ syncBlockStore.sourceManager.setSaveExperience(saveSourceExperience);
16
+ var saveReferenceExperience = getSaveReferenceExperience({
17
+ refs: refs,
18
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent
19
+ });
20
+ var fetchExperience = getFetchExperience({
21
+ refs: refs,
22
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent
23
+ });
24
+ var fetchSourceInfoExperience = getFetchSourceInfoExperience({
25
+ refs: refs,
26
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent
27
+ });
28
+ syncBlockStore.referenceManager.setExperiences(fetchExperience, fetchSourceInfoExperience, saveReferenceExperience);
29
+ return new SafePlugin({
30
+ key: pluginKey,
31
+ view: function view() {
32
+ return {
33
+ destroy: function destroy() {
34
+ saveSourceExperience.abort({
35
+ reason: EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
36
+ });
37
+ saveReferenceExperience.abort({
38
+ reason: EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
39
+ });
40
+ fetchExperience.abort({
41
+ reason: EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
42
+ });
43
+ fetchSourceInfoExperience.abort({
44
+ reason: EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
45
+ });
46
+ }
47
+ };
48
+ }
49
+ });
50
+ };
51
+
52
+ /**
53
+ * This experience tracks when a source sync block is saved to the BE.
54
+ *
55
+ * Start: When the flush source sync block function is called.
56
+ * Success: When the sync block save is successful within 1500ms of start.
57
+ * Failure: When 1500ms passes without the sync block being successfully saved
58
+ */
59
+ var getSaveSourceExperience = function getSaveSourceExperience(_ref2) {
60
+ var dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
61
+ return new Experience(ACTION_SUBJECT.SYNCED_BLOCK, {
62
+ actionSubjectId: ACTION_SUBJECT_ID.SYNCED_BLOCK_UPDATE,
63
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
64
+ checks: [new ExperienceCheckTimeout({
65
+ durationMs: 1500
66
+ })]
67
+ });
68
+ };
69
+
70
+ /**
71
+ * This experience tracks when a reference sync block is saved to the BE.
72
+ *
73
+ * Start: When the flush sync block function is called.
74
+ * Success: When the sync block save is successful within 1500ms of start.
75
+ * Failure: When 1500ms passes without the sync block being successfully saved
76
+ */
77
+ var getSaveReferenceExperience = function getSaveReferenceExperience(_ref3) {
78
+ var dispatchAnalyticsEvent = _ref3.dispatchAnalyticsEvent;
79
+ return new Experience(ACTION_SUBJECT.SYNCED_BLOCK, {
80
+ actionSubjectId: ACTION_SUBJECT_ID.REFERENCE_SYNCED_BLOCK_UPDATE,
81
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
82
+ checks: [new ExperienceCheckTimeout({
83
+ durationMs: 1500
84
+ })]
85
+ });
86
+ };
87
+
88
+ /**
89
+ * This experience tracks when a reference sync block data is fetched from the BE.
90
+ *
91
+ * Start: When the fetchNodesData function is called.
92
+ * Success: When the fetching the data is successful within 1500ms of start.
93
+ * Failure: When 1500ms passes without the data being successfully fetched, or the fetch fails
94
+ */
95
+ var getFetchExperience = function getFetchExperience(_ref4) {
96
+ var dispatchAnalyticsEvent = _ref4.dispatchAnalyticsEvent;
97
+ return new Experience(ACTION_SUBJECT.SYNCED_BLOCK, {
98
+ actionSubjectId: ACTION_SUBJECT_ID.SYNCED_BLOCK_FETCH,
99
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
100
+ checks: [new ExperienceCheckTimeout({
101
+ durationMs: 1500
102
+ })]
103
+ });
104
+ };
105
+
106
+ /**
107
+ * This experience tracks when a reference sync block source info data (title, url) is fetched from the BE.
108
+ *
109
+ * Start: When the fetchSourceInfo function is called.
110
+ * Success: When the fetching the data is successful within 2500ms of start.
111
+ * Failure: When 2500ms passes without the data being successfully fetched, or the fetch fails
112
+ */
113
+ var getFetchSourceInfoExperience = function getFetchSourceInfoExperience(_ref5) {
114
+ var dispatchAnalyticsEvent = _ref5.dispatchAnalyticsEvent;
115
+ return new Experience(ACTION_SUBJECT.SYNCED_BLOCK, {
116
+ actionSubjectId: ACTION_SUBJECT_ID.SYNCED_BLOCK_GET_SOURCE_INFO,
117
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent,
118
+ checks: [new ExperienceCheckTimeout({
119
+ durationMs: 2500
120
+ })]
121
+ });
122
+ };
@@ -0,0 +1,79 @@
1
+ import { pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
2
+ import { findChildren } from '@atlaskit/editor-prosemirror/utils';
3
+ var targetEl;
4
+ export var getTarget = function getTarget(containerElement) {
5
+ if (!targetEl) {
6
+ var element = containerElement === null || containerElement === void 0 ? void 0 : containerElement.querySelector('.ProseMirror');
7
+ if (!element || !(element instanceof HTMLElement)) {
8
+ return null;
9
+ }
10
+ targetEl = element;
11
+ }
12
+ return targetEl;
13
+ };
14
+ export var wasSyncBlockDeletedOrAddedByHistory = function wasSyncBlockDeletedOrAddedByHistory(tr, oldState, newState) {
15
+ var historyMeta = tr.getMeta(pmHistoryPluginKey);
16
+ if (!Boolean(historyMeta)) {
17
+ return {};
18
+ }
19
+ var syncBlock = newState.schema.nodes.syncBlock;
20
+ var oldSyncBlockNodes = findChildren(oldState.doc, function (node) {
21
+ return node.type === syncBlock;
22
+ });
23
+ var newSyncBlockNodes = findChildren(newState.doc, function (node) {
24
+ return node.type === syncBlock;
25
+ });
26
+ var oldSyncBlockIds = new Set(oldSyncBlockNodes.map(function (nodeWithPos) {
27
+ return nodeWithPos.node.attrs.localId;
28
+ }).filter(function (localId) {
29
+ return Boolean(localId);
30
+ }));
31
+ var newSyncBlockIds = new Set(newSyncBlockNodes.map(function (nodeWithPos) {
32
+ return nodeWithPos.node.attrs.localId;
33
+ }).filter(function (localId) {
34
+ return Boolean(localId);
35
+ }));
36
+ var hasDeletedSyncBlock = Array.from(oldSyncBlockIds).some(function (localId) {
37
+ return !newSyncBlockIds.has(localId);
38
+ });
39
+ var hasAddedSyncBlock = Array.from(newSyncBlockIds).some(function (localId) {
40
+ return !oldSyncBlockIds.has(localId);
41
+ });
42
+ return {
43
+ hasDeletedSyncBlock: hasDeletedSyncBlock,
44
+ hasAddedSyncBlock: hasAddedSyncBlock,
45
+ isUndo: historyMeta.redo === false
46
+ };
47
+ };
48
+ var getResourceIds = function getResourceIds(nodes, resourceIds, query) {
49
+ nodes.forEach(function (node) {
50
+ if (!(node instanceof HTMLElement)) {
51
+ return;
52
+ }
53
+ var syncBlockElements = node.querySelectorAll(query);
54
+ syncBlockElements.forEach(function (element) {
55
+ var resourceId = element.getAttribute('resourceid');
56
+ if (resourceId) {
57
+ resourceIds.push(resourceId);
58
+ }
59
+ });
60
+ });
61
+ };
62
+ export var getAddedResourceIds = function getAddedResourceIds(mutations, query) {
63
+ var resourceIds = [];
64
+ mutations.forEach(function (mutation) {
65
+ if (mutation.type === 'childList') {
66
+ getResourceIds(mutation.addedNodes, resourceIds, query);
67
+ }
68
+ });
69
+ return resourceIds;
70
+ };
71
+ export var getRemovedResourceIds = function getRemovedResourceIds(mutations, query) {
72
+ var resourceIds = [];
73
+ mutations.forEach(function (mutation) {
74
+ if (mutation.type === 'childList') {
75
+ getResourceIds(mutation.removedNodes, resourceIds, query);
76
+ }
77
+ });
78
+ return resourceIds;
79
+ };
@@ -5,4 +5,7 @@ export var FLAG_ID = /*#__PURE__*/function (FLAG_ID) {
5
5
  FLAG_ID["FAIL_TO_DELETE"] = "fail-to-delete";
6
6
  FLAG_ID["SYNC_BLOCK_COPIED"] = "sync-block-copied";
7
7
  return FLAG_ID;
8
- }({});
8
+ }({});
9
+ export var EXPERIENCE_ABORT_REASON = {
10
+ EDITOR_DESTROYED: 'editor-destroyed'
11
+ };
@@ -42,24 +42,56 @@ var CreateSyncedBlockDropdownItem = function CreateSyncedBlockDropdownItem(_ref)
42
42
  }),
43
43
  onClick: onClick,
44
44
  isDisabled: isOffline,
45
- testId: 'create-synced-block-block-menu-btn',
45
+ testId: "create-synced-block-block-menu-btn",
46
46
  elemAfter: /*#__PURE__*/React.createElement(Lozenge, {
47
47
  appearance: "new"
48
48
  }, formatMessage(blockMenuMessages.newLozenge))
49
49
  }, formatMessage(blockMenuMessages.createSyncedBlock));
50
50
  };
51
- export var CreateOrCopySyncedBlockDropdownItem = function CreateOrCopySyncedBlockDropdownItem(_ref2) {
52
- var _menuTriggerByNode$no;
53
- var api = _ref2.api,
54
- enableSourceSyncedBlockCreation = _ref2.enableSourceSyncedBlockCreation;
55
- var _useSharedPluginState2 = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
51
+ var CopySyncedBlockDropdownItem = function CopySyncedBlockDropdownItem(_ref2) {
52
+ var api = _ref2.api;
53
+ var _useIntl2 = useIntl(),
54
+ formatMessage = _useIntl2.formatMessage;
55
+ var _useSharedPluginState2 = useSharedPluginStateWithSelector(api, ['connectivity'], function (states) {
56
+ var _states$connectivityS2;
57
+ return {
58
+ mode: (_states$connectivityS2 = states.connectivityState) === null || _states$connectivityS2 === void 0 ? void 0 : _states$connectivityS2.mode
59
+ };
60
+ }),
61
+ mode = _useSharedPluginState2.mode;
62
+ var onClick = function onClick() {
63
+ var _api$core3, _api$core4, _api$blockControls2;
64
+ api === null || api === void 0 || (_api$core3 = api.core) === null || _api$core3 === void 0 || _api$core3.actions.execute(api === null || api === void 0 ? void 0 : api.syncedBlock.commands.copySyncedBlockReferenceToClipboard());
65
+ api === null || api === void 0 || (_api$core4 = api.core) === null || _api$core4 === void 0 || _api$core4.actions.execute(api === null || api === void 0 || (_api$blockControls2 = api.blockControls) === null || _api$blockControls2 === void 0 || (_api$blockControls2 = _api$blockControls2.commands) === null || _api$blockControls2 === void 0 ? void 0 : _api$blockControls2.toggleBlockMenu({
66
+ closeMenu: true
67
+ }));
68
+ };
69
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItem, {
70
+ elemBefore: /*#__PURE__*/React.createElement(SyncBlocksIcon, {
71
+ label: ""
72
+ }),
73
+ onClick: onClick,
74
+ isDisabled: isOfflineMode(mode),
75
+ elemAfter: /*#__PURE__*/React.createElement(Lozenge, {
76
+ appearance: "new"
77
+ }, formatMessage(blockMenuMessages.newLozenge))
78
+ }, formatMessage(blockMenuMessages.copySyncedBlock));
79
+ };
80
+ export var CreateOrCopySyncedBlockDropdownItem = function CreateOrCopySyncedBlockDropdownItem(_ref3) {
81
+ var api = _ref3.api,
82
+ enableSourceSyncedBlockCreation = _ref3.enableSourceSyncedBlockCreation;
83
+ var _useSharedPluginState3 = useSharedPluginStateWithSelector(api, ['blockControls'], function (states) {
56
84
  var _states$blockControls3, _states$blockControls4;
57
85
  return {
58
86
  menuTriggerByNode: (_states$blockControls3 = (_states$blockControls4 = states.blockControlsState) === null || _states$blockControls4 === void 0 ? void 0 : _states$blockControls4.menuTriggerByNode) !== null && _states$blockControls3 !== void 0 ? _states$blockControls3 : undefined
59
87
  };
60
88
  }),
61
- menuTriggerByNode = _useSharedPluginState2.menuTriggerByNode;
62
- if (!['syncBlock', 'bodiedSyncBlock'].includes((_menuTriggerByNode$no = menuTriggerByNode === null || menuTriggerByNode === void 0 ? void 0 : menuTriggerByNode.nodeType) !== null && _menuTriggerByNode$no !== void 0 ? _menuTriggerByNode$no : '') && enableSourceSyncedBlockCreation) {
89
+ menuTriggerByNode = _useSharedPluginState3.menuTriggerByNode;
90
+ if ((menuTriggerByNode === null || menuTriggerByNode === void 0 ? void 0 : menuTriggerByNode.nodeType) === 'syncBlock' || (menuTriggerByNode === null || menuTriggerByNode === void 0 ? void 0 : menuTriggerByNode.nodeType) === 'bodiedSyncBlock') {
91
+ return /*#__PURE__*/React.createElement(CopySyncedBlockDropdownItem, {
92
+ api: api
93
+ });
94
+ } else if (enableSourceSyncedBlockCreation) {
63
95
  return /*#__PURE__*/React.createElement(CreateSyncedBlockDropdownItem, {
64
96
  api: api
65
97
  });
@@ -6,6 +6,7 @@ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks'
6
6
  import { syncBlockMessages as messages } from '@atlaskit/editor-common/messages';
7
7
  import { isOfflineMode } from '@atlaskit/editor-plugin-connectivity';
8
8
  import ModalDialog, { ModalBody, ModalFooter, ModalHeader, ModalTitle, ModalTransition } from '@atlaskit/modal-dialog';
9
+ import { fg } from '@atlaskit/platform-feature-flags';
9
10
  import { Text } from '@atlaskit/primitives/compiled';
10
11
  import { syncedBlockPluginKey } from '../pm-plugins/main';
11
12
  export var DeleteConfirmationModal = function DeleteConfirmationModal(_ref) {
@@ -108,6 +109,7 @@ export var DeleteConfirmationModal = function DeleteConfirmationModal(_ref) {
108
109
  onClick: handleClick(true),
109
110
  autoFocus: true,
110
111
  isDisabled: isOfflineMode(mode),
111
- isLoading: bodiedSyncBlockDeletionStatus === 'processing'
112
+ isLoading: bodiedSyncBlockDeletionStatus === 'processing',
113
+ testId: fg('platform_synced_block_dogfooding') ? 'synced-block-delete-confirmation-modal-delete-button' : undefined
112
114
  }, formatMessage(messages.deleteConfirmationModalDeleteButton)))));
113
115
  };
@@ -9,6 +9,7 @@ import { SyncBlockError } from '@atlaskit/editor-synced-block-provider';
9
9
  import CopyIcon from '@atlaskit/icon/core/copy';
10
10
  import DeleteIcon from '@atlaskit/icon/core/delete';
11
11
  import EditIcon from '@atlaskit/icon/core/edit';
12
+ import { fg } from '@atlaskit/platform-feature-flags';
12
13
  import { copySyncedBlockReferenceToClipboard, editSyncedBlockSource, removeSyncedBlock } from '../editor-commands';
13
14
  import { findSyncBlockOrBodiedSyncBlock, isBodiedSyncBlockNode } from '../pm-plugins/utils/utils';
14
15
  export var getToolbarConfig = function getToolbarConfig(state, intl, api, syncBlockStore) {
@@ -38,7 +39,8 @@ export var getToolbarConfig = function getToolbarConfig(state, intl, api, syncBl
38
39
  type: 'button',
39
40
  title: formatMessage(commonMessages.delete),
40
41
  onClick: removeSyncedBlock(api),
41
- icon: DeleteIcon
42
+ icon: DeleteIcon,
43
+ testId: fg('platform_synced_block_dogfooding') ? 'reference-synced-block-delete-button' : undefined
42
44
  }, hoverDecorationProps(nodeType, akEditorSelectedNodeClassName));
43
45
  items.push(deleteButton);
44
46
  } else {
@@ -49,7 +51,7 @@ export var getToolbarConfig = function getToolbarConfig(state, intl, api, syncBl
49
51
  icon: CopyIcon,
50
52
  title: formatMessage(messages.copySyncBlockLabel),
51
53
  showTitle: false,
52
- tooltipContent: formatMessage(messages.copySyncBlockTooltip),
54
+ tooltipContent: formatMessage(messages.copySyncedBlockTooltip),
53
55
  onClick: copySyncedBlockReferenceToClipboard(syncBlockStore, api)
54
56
  }, hoverDecorationProps(nodeType, akEditorSelectedNodeClassName));
55
57
  items.push(copyButton);
@@ -1,11 +1,5 @@
1
- import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- type CreateReferenceExperienceOptions = {
4
- dispatchAnalyticsEvent: DispatchAnalyticsEvent;
5
- refs: {
6
- containerElement?: HTMLElement;
7
- };
8
- };
2
+ import { type ExperienceOptions } from '../../types';
9
3
  /**
10
4
  * This experience tracks when a reference sync block is inserted.
11
5
  *
@@ -13,5 +7,4 @@ type CreateReferenceExperienceOptions = {
13
7
  * Success: When the sync block is added to the DOM within 500ms of start
14
8
  * Failure: When 500ms passes without the reference sync block being added to the DOM
15
9
  */
16
- export declare const getCreateReferenceExperiencePlugin: ({ refs, dispatchAnalyticsEvent, }: CreateReferenceExperienceOptions) => SafePlugin<any>;
17
- export {};
10
+ export declare const getCreateReferenceExperiencePlugin: ({ refs, dispatchAnalyticsEvent, }: ExperienceOptions) => SafePlugin<any>;
@@ -1,21 +1,10 @@
1
- import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
- import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
- type CreateSourceExperienceOptions = {
5
- dispatchAnalyticsEvent: DispatchAnalyticsEvent;
6
- refs: {
7
- containerElement?: HTMLElement;
8
- popupsMountPoint?: HTMLElement;
9
- wrapperElement?: HTMLElement;
10
- };
11
- syncBlockStore: SyncBlockStoreManager;
12
- };
2
+ import { type ProviderExperienceOptions } from '../../types';
13
3
  /**
14
4
  * This experience tracks when a source sync block is inserted.
15
5
  *
16
6
  * Start: When user inserts a sync block via block menu, quick insert or pinned toolbar
17
- * Success: When the sync block is added to the DOM within 2000ms of start
18
- * Failure: When 500ms passes without the source sync block being added to the DOM
7
+ * Success: When the sync block is added to the DOM within 3000ms of start
8
+ * Failure: When 3000ms passes without the source sync block being added to the DOM
19
9
  */
20
- export declare const getCreateSourceExperiencePlugin: ({ refs, dispatchAnalyticsEvent, syncBlockStore, }: CreateSourceExperienceOptions) => SafePlugin<any>;
21
- export {};
10
+ export declare const getCreateSourceExperiencePlugin: ({ refs, dispatchAnalyticsEvent, syncBlockStore, }: ProviderExperienceOptions) => SafePlugin<any>;