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

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 (61) hide show
  1. package/CHANGELOG.md +22 -0
  2. package/dist/cjs/editor-commands/index.js +2 -2
  3. package/dist/cjs/nodeviews/bodiedSyncedBlock.js +13 -2
  4. package/dist/cjs/nodeviews/syncedBlock.js +21 -2
  5. package/dist/cjs/pm-plugins/experience-tracking/create-reference-experience.js +26 -26
  6. package/dist/cjs/pm-plugins/experience-tracking/create-source-experience.js +14 -30
  7. package/dist/cjs/pm-plugins/experience-tracking/delete-reference-experience.js +175 -0
  8. package/dist/cjs/pm-plugins/experience-tracking/delete-source-experience.js +103 -0
  9. package/dist/cjs/pm-plugins/experience-tracking/get-experience-tracking-plugins.js +30 -0
  10. package/dist/cjs/pm-plugins/experience-tracking/provider-only-experiences.js +128 -0
  11. package/dist/cjs/pm-plugins/utils/experience-tracking-utils.js +85 -0
  12. package/dist/cjs/types/index.js +5 -2
  13. package/dist/cjs/ui/CreateSyncedBlockDropdownItem.js +40 -8
  14. package/dist/cjs/ui/DeleteConfirmationModal.js +3 -1
  15. package/dist/cjs/ui/floating-toolbar.js +4 -2
  16. package/dist/es2019/editor-commands/index.js +2 -2
  17. package/dist/es2019/nodeviews/bodiedSyncedBlock.js +13 -2
  18. package/dist/es2019/nodeviews/syncedBlock.js +19 -4
  19. package/dist/es2019/pm-plugins/experience-tracking/create-reference-experience.js +27 -23
  20. package/dist/es2019/pm-plugins/experience-tracking/create-source-experience.js +14 -27
  21. package/dist/es2019/pm-plugins/experience-tracking/delete-reference-experience.js +181 -0
  22. package/dist/es2019/pm-plugins/experience-tracking/delete-source-experience.js +98 -0
  23. package/dist/es2019/pm-plugins/experience-tracking/get-experience-tracking-plugins.js +24 -0
  24. package/dist/es2019/pm-plugins/experience-tracking/provider-only-experiences.js +127 -0
  25. package/dist/es2019/pm-plugins/utils/experience-tracking-utils.js +65 -0
  26. package/dist/es2019/types/index.js +4 -1
  27. package/dist/es2019/ui/CreateSyncedBlockDropdownItem.js +38 -3
  28. package/dist/es2019/ui/DeleteConfirmationModal.js +3 -1
  29. package/dist/es2019/ui/floating-toolbar.js +3 -1
  30. package/dist/esm/editor-commands/index.js +2 -2
  31. package/dist/esm/nodeviews/bodiedSyncedBlock.js +13 -2
  32. package/dist/esm/nodeviews/syncedBlock.js +21 -2
  33. package/dist/esm/pm-plugins/experience-tracking/create-reference-experience.js +26 -25
  34. package/dist/esm/pm-plugins/experience-tracking/create-source-experience.js +14 -29
  35. package/dist/esm/pm-plugins/experience-tracking/delete-reference-experience.js +169 -0
  36. package/dist/esm/pm-plugins/experience-tracking/delete-source-experience.js +97 -0
  37. package/dist/esm/pm-plugins/experience-tracking/get-experience-tracking-plugins.js +30 -0
  38. package/dist/esm/pm-plugins/experience-tracking/provider-only-experiences.js +122 -0
  39. package/dist/esm/pm-plugins/utils/experience-tracking-utils.js +79 -0
  40. package/dist/esm/types/index.js +4 -1
  41. package/dist/esm/ui/CreateSyncedBlockDropdownItem.js +40 -8
  42. package/dist/esm/ui/DeleteConfirmationModal.js +3 -1
  43. package/dist/esm/ui/floating-toolbar.js +4 -2
  44. package/dist/types/pm-plugins/experience-tracking/create-reference-experience.d.ts +2 -9
  45. package/dist/types/pm-plugins/experience-tracking/create-source-experience.d.ts +4 -15
  46. package/dist/types/pm-plugins/experience-tracking/delete-reference-experience.d.ts +13 -0
  47. package/dist/types/pm-plugins/experience-tracking/delete-source-experience.d.ts +12 -0
  48. package/dist/types/pm-plugins/experience-tracking/get-experience-tracking-plugins.d.ts +2 -13
  49. package/dist/types/pm-plugins/experience-tracking/provider-only-experiences.d.ts +3 -0
  50. package/dist/types/pm-plugins/utils/experience-tracking-utils.d.ts +9 -0
  51. package/dist/types/types/index.d.ts +15 -0
  52. package/dist/types-ts4.5/pm-plugins/experience-tracking/create-reference-experience.d.ts +2 -9
  53. package/dist/types-ts4.5/pm-plugins/experience-tracking/create-source-experience.d.ts +4 -15
  54. package/dist/types-ts4.5/pm-plugins/experience-tracking/delete-reference-experience.d.ts +13 -0
  55. package/dist/types-ts4.5/pm-plugins/experience-tracking/delete-source-experience.d.ts +12 -0
  56. package/dist/types-ts4.5/pm-plugins/experience-tracking/get-experience-tracking-plugins.d.ts +2 -13
  57. package/dist/types-ts4.5/pm-plugins/experience-tracking/provider-only-experiences.d.ts +3 -0
  58. package/dist/types-ts4.5/pm-plugins/utils/experience-tracking-utils.d.ts +9 -0
  59. package/dist/types-ts4.5/types/index.d.ts +15 -0
  60. package/package.json +5 -5
  61. package/build/tsconfig.json +0 -22
@@ -8,6 +8,8 @@ function _callSuper(t, o, e) { return o = _getPrototypeOf(o), _possibleConstruct
8
8
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
9
9
  function _superPropGet(t, o, e, r) { var p = _get(_getPrototypeOf(1 & r ? t.prototype : t), o, e); return 2 & r && "function" == typeof p ? function (t) { return p.apply(e, t); } : p; }
10
10
  import React from 'react';
11
+ import { ACTION_SUBJECT } from '@atlaskit/editor-common/analytics';
12
+ import { ErrorBoundary } from '@atlaskit/editor-common/error-boundary';
11
13
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
12
14
  import { SyncBlockSharedCssClassName } from '@atlaskit/editor-common/sync-block';
13
15
  import { useFetchSyncBlockData as _useFetchSyncBlockData, useFetchSyncBlockTitle as _useFetchSyncBlockTitle } from '@atlaskit/editor-synced-block-provider';
@@ -37,8 +39,10 @@ export var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
37
39
  var _this$options,
38
40
  _this$api$syncedBlock,
39
41
  _this$api,
42
+ _this$api2,
40
43
  _this$options2,
41
- _this2 = this;
44
+ _this2 = this,
45
+ _this$options3;
42
46
  if (!((_this$options = this.options) !== null && _this$options !== void 0 && _this$options.syncedBlockRenderer)) {
43
47
  return null;
44
48
  }
@@ -55,7 +59,11 @@ export var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
55
59
  }
56
60
 
57
61
  // get document node from data provider
58
- return /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
62
+ return fg('platform_synced_block_dogfooding') ? /*#__PURE__*/React.createElement(ErrorBoundary, {
63
+ component: ACTION_SUBJECT.SYNCED_BLOCK,
64
+ dispatchAnalyticsEvent: (_this$api2 = this.api) === null || _this$api2 === void 0 || (_this$api2 = _this$api2.analytics) === null || _this$api2 === void 0 ? void 0 : _this$api2.actions.fireAnalyticsEvent,
65
+ fallbackComponent: null
66
+ }, /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
59
67
  localId: this.node.attrs.localId,
60
68
  syncedBlockRenderer: (_this$options2 = this.options) === null || _this$options2 === void 0 ? void 0 : _this$options2.syncedBlockRenderer,
61
69
  useFetchSyncBlockTitle: function useFetchSyncBlockTitle() {
@@ -66,6 +74,17 @@ export var SyncBlock = /*#__PURE__*/function (_ReactNodeView) {
66
74
  return _useFetchSyncBlockData(syncBlockStore, resourceId, localId, (_this2$api = _this2.api) === null || _this2$api === void 0 || (_this2$api = _this2$api.analytics) === null || _this2$api === void 0 || (_this2$api = _this2$api.actions) === null || _this2$api === void 0 ? void 0 : _this2$api.fireAnalyticsEvent);
67
75
  },
68
76
  api: this.api
77
+ })) : /*#__PURE__*/React.createElement(SyncBlockRendererWrapper, {
78
+ localId: this.node.attrs.localId,
79
+ syncedBlockRenderer: (_this$options3 = this.options) === null || _this$options3 === void 0 ? void 0 : _this$options3.syncedBlockRenderer,
80
+ useFetchSyncBlockTitle: function useFetchSyncBlockTitle() {
81
+ return _useFetchSyncBlockTitle(syncBlockStore, _this2.node);
82
+ },
83
+ useFetchSyncBlockData: function useFetchSyncBlockData() {
84
+ var _this2$api2;
85
+ return _useFetchSyncBlockData(syncBlockStore, resourceId, localId, (_this2$api2 = _this2.api) === null || _this2$api2 === void 0 || (_this2$api2 = _this2$api2.analytics) === null || _this2$api2 === void 0 || (_this2$api2 = _this2$api2.actions) === null || _this2$api2 === void 0 ? void 0 : _this2$api2.fireAnalyticsEvent);
86
+ },
87
+ api: this.api
69
88
  });
70
89
  }
71
90
  }, {
@@ -1,17 +1,17 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  import { ACTION_SUBJECT, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
3
2
  import { Experience, ExperienceCheckDomMutation, ExperienceCheckTimeout } from '@atlaskit/editor-common/experiences';
4
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
4
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
5
+ import { EXPERIENCE_ABORT_REASON } from '../../types';
6
+ import { getAddedResourceIds, wasSyncBlockDeletedOrAddedByHistory, getTarget } from '../utils/experience-tracking-utils';
6
7
  var isPastedFromFabricEditor = function isPastedFromFabricEditor(html) {
7
8
  return !!html && html.indexOf('data-pm-slice="') >= 0;
8
9
  };
9
10
  var pluginKey = new PluginKey('createReferenceSyncBlockExperience');
10
11
  var START_METHOD = {
11
- PASTE: 'paste'
12
- };
13
- var ABORT_REASON = {
14
- EDITOR_DESTROYED: 'editor-destroyed'
12
+ PASTE: 'paste',
13
+ UNDO: 'undo',
14
+ REDO: 'redo'
15
15
  };
16
16
 
17
17
  /**
@@ -34,7 +34,7 @@ export var getCreateReferenceExperiencePlugin = function getCreateReferenceExper
34
34
  return {
35
35
  destroy: function destroy() {
36
36
  experience.abort({
37
- reason: ABORT_REASON.EDITOR_DESTROYED
37
+ reason: EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
38
38
  });
39
39
  }
40
40
  };
@@ -56,6 +56,19 @@ export var getCreateReferenceExperiencePlugin = function getCreateReferenceExper
56
56
  });
57
57
  }
58
58
  }
59
+ },
60
+ appendTransaction: function appendTransaction(transactions, oldState, newState) {
61
+ transactions.forEach(function (tr) {
62
+ var _wasSyncBlockDeletedO = wasSyncBlockDeletedOrAddedByHistory(tr, oldState, newState),
63
+ hasAddedSyncBlock = _wasSyncBlockDeletedO.hasAddedSyncBlock,
64
+ isUndo = _wasSyncBlockDeletedO.isUndo;
65
+ if (hasAddedSyncBlock) {
66
+ experience.start({
67
+ method: isUndo ? START_METHOD.UNDO : START_METHOD.REDO
68
+ });
69
+ }
70
+ });
71
+ return null;
59
72
  }
60
73
  });
61
74
  };
@@ -70,21 +83,20 @@ var getCreateReferenceExperience = function getCreateReferenceExperience(_ref2)
70
83
  }), new ExperienceCheckDomMutation({
71
84
  onDomMutation: function onDomMutation(_ref3) {
72
85
  var mutations = _ref3.mutations;
73
- if (mutations.some(isReferenceSyncBlockAddedInMutation)) {
86
+ var insertedResourceIds = getAddedResourceIds(mutations, '[data-prosemirror-node-name="syncBlock"]');
87
+ if (insertedResourceIds.length > 0) {
74
88
  return {
75
- status: 'success'
89
+ status: 'success',
90
+ metadata: {
91
+ insertedResourceIds: insertedResourceIds
92
+ }
76
93
  };
77
94
  }
78
95
  return undefined;
79
96
  },
80
97
  observeConfig: function observeConfig() {
81
- var _refs$containerElemen;
82
- var proseMirrorElement = (_refs$containerElemen = refs.containerElement) === null || _refs$containerElemen === void 0 ? void 0 : _refs$containerElemen.querySelector('.ProseMirror');
83
- if (!proseMirrorElement || !(proseMirrorElement instanceof HTMLElement)) {
84
- return null;
85
- }
86
98
  return {
87
- target: proseMirrorElement,
99
+ target: getTarget(refs.containerElement),
88
100
  options: {
89
101
  childList: true
90
102
  }
@@ -92,15 +104,4 @@ var getCreateReferenceExperience = function getCreateReferenceExperience(_ref2)
92
104
  }
93
105
  })]
94
106
  });
95
- };
96
- var isReferenceSyncBlockAddedInMutation = function isReferenceSyncBlockAddedInMutation(_ref4) {
97
- var type = _ref4.type,
98
- addedNodes = _ref4.addedNodes;
99
- return type === 'childList' && _toConsumableArray(addedNodes).some(isReferenceSyncBlockNode);
100
- };
101
- var isReferenceSyncBlockNode = function isReferenceSyncBlockNode(node) {
102
- if (!(node instanceof HTMLElement)) {
103
- return false;
104
- }
105
- return !!node.querySelector('[data-prosemirror-node-name="syncBlock"]');
106
107
  };
@@ -1,13 +1,11 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
1
  import { bind } from 'bind-event-listener';
3
2
  import { ACTION_SUBJECT, ACTION_SUBJECT_ID } from '@atlaskit/editor-common/analytics';
4
3
  import { Experience, ExperienceCheckDomMutation, ExperienceCheckTimeout, getPopupContainerFromEditorView, popupWithNestedElement } from '@atlaskit/editor-common/experiences';
5
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
5
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
6
+ import { EXPERIENCE_ABORT_REASON } from '../../types';
7
+ import { getAddedResourceIds, getTarget } from '../utils/experience-tracking-utils';
7
8
  var pluginKey = new PluginKey('createSourceSyncBlockExperience');
8
- var ABORT_REASON = {
9
- EDITOR_DESTROYED: 'editor-destroyed'
10
- };
11
9
  var START_METHOD = {
12
10
  BLOCK_MENU: 'block-menu',
13
11
  PINNED_TOOLBAR: 'pinned-toolbar',
@@ -20,8 +18,8 @@ var syncedBlockCreateButtonIds = new Set(SYNCED_BLOCK_CREATE_BUTTON_IDS);
20
18
  * This experience tracks when a source sync block is inserted.
21
19
  *
22
20
  * Start: When user inserts a sync block via block menu, quick insert or pinned toolbar
23
- * Success: When the sync block is added to the DOM within 2000ms of start
24
- * Failure: When 500ms passes without the source sync block being added to the DOM
21
+ * Success: When the sync block is added to the DOM within 3000ms of start
22
+ * Failure: When 3000ms passes without the source sync block being added to the DOM
25
23
  */
26
24
  export var getCreateSourceExperiencePlugin = function getCreateSourceExperiencePlugin(_ref) {
27
25
  var refs = _ref.refs,
@@ -37,8 +35,7 @@ export var getCreateSourceExperiencePlugin = function getCreateSourceExperienceP
37
35
  };
38
36
  var experience = getCreateSourceExperience({
39
37
  refs: refs,
40
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
41
- syncBlockStore: syncBlockStore
38
+ dispatchAnalyticsEvent: dispatchAnalyticsEvent
42
39
  });
43
40
  syncBlockStore.sourceManager.setCreateExperience(experience);
44
41
  var unbindClickListener = bind(document, {
@@ -90,7 +87,7 @@ export var getCreateSourceExperiencePlugin = function getCreateSourceExperienceP
90
87
  return {
91
88
  destroy: function destroy() {
92
89
  experience.abort({
93
- reason: ABORT_REASON.EDITOR_DESTROYED
90
+ reason: EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
94
91
  });
95
92
  unbindClickListener();
96
93
  unbindKeydownListener();
@@ -106,25 +103,24 @@ var getCreateSourceExperience = function getCreateSourceExperience(_ref2) {
106
103
  actionSubjectId: ACTION_SUBJECT_ID.SYNCED_BLOCK_CREATE,
107
104
  dispatchAnalyticsEvent: dispatchAnalyticsEvent,
108
105
  checks: [new ExperienceCheckTimeout({
109
- durationMs: 2000
106
+ durationMs: 3000
110
107
  }), new ExperienceCheckDomMutation({
111
108
  onDomMutation: function onDomMutation(_ref3) {
112
109
  var mutations = _ref3.mutations;
113
- if (mutations.some(isSourceSyncBlockAddedInMutation)) {
110
+ var createdResourceIds = getAddedResourceIds(mutations, '[data-prosemirror-node-name="bodiedSyncBlock"]');
111
+ if (createdResourceIds.length > 0) {
114
112
  return {
115
- status: 'success'
113
+ status: 'success',
114
+ metadata: {
115
+ createdResourceIds: createdResourceIds
116
+ }
116
117
  };
117
118
  }
118
119
  return undefined;
119
120
  },
120
121
  observeConfig: function observeConfig() {
121
- var _refs$containerElemen;
122
- var proseMirrorElement = (_refs$containerElemen = refs.containerElement) === null || _refs$containerElemen === void 0 ? void 0 : _refs$containerElemen.querySelector('.ProseMirror');
123
- if (!proseMirrorElement || !(proseMirrorElement instanceof HTMLElement)) {
124
- return null;
125
- }
126
122
  return {
127
- target: proseMirrorElement,
123
+ target: getTarget(refs.containerElement),
128
124
  options: {
129
125
  childList: true
130
126
  }
@@ -164,15 +160,4 @@ var handleButtonClick = function handleButtonClick(testId, experience) {
164
160
  };
165
161
  var isEnterKey = function isEnterKey(key) {
166
162
  return key === 'Enter';
167
- };
168
- var isSourceSyncBlockAddedInMutation = function isSourceSyncBlockAddedInMutation(_ref4) {
169
- var type = _ref4.type,
170
- addedNodes = _ref4.addedNodes;
171
- return type === 'childList' && _toConsumableArray(addedNodes).some(isSourceSyncBlockNode);
172
- };
173
- var isSourceSyncBlockNode = function isSourceSyncBlockNode(node) {
174
- if (!(node instanceof HTMLElement)) {
175
- return false;
176
- }
177
- return !!node.querySelector('[data-prosemirror-node-name="bodiedSyncBlock"]');
178
163
  };
@@ -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
+ };