@atlaskit/editor-plugin-synced-block 5.2.1 → 5.3.0

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 (76) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/afm-jira/tsconfig.json +1 -1
  3. package/dist/cjs/editor-commands/index.js +43 -5
  4. package/dist/cjs/editor-commands/utils.js +20 -0
  5. package/dist/cjs/pm-plugins/menu-and-toolbar-experiences.js +267 -0
  6. package/dist/cjs/syncedBlockPlugin.js +21 -12
  7. package/dist/cjs/types/index.js +6 -3
  8. package/dist/cjs/ui/CreateSyncedBlockButton.js +2 -1
  9. package/dist/cjs/ui/CreateSyncedBlockDropdownItem.js +2 -1
  10. package/dist/cjs/ui/SyncBlockRefresher.js +18 -4
  11. package/dist/cjs/ui/SyncedLocationDropdown.js +14 -11
  12. package/dist/cjs/ui/floating-toolbar.js +21 -2
  13. package/dist/es2019/editor-commands/index.js +44 -4
  14. package/dist/es2019/editor-commands/utils.js +14 -0
  15. package/dist/es2019/pm-plugins/menu-and-toolbar-experiences.js +261 -0
  16. package/dist/es2019/syncedBlockPlugin.js +19 -12
  17. package/dist/es2019/types/index.js +5 -2
  18. package/dist/es2019/ui/CreateSyncedBlockButton.js +2 -1
  19. package/dist/es2019/ui/CreateSyncedBlockDropdownItem.js +2 -1
  20. package/dist/es2019/ui/SyncBlockRefresher.js +18 -4
  21. package/dist/es2019/ui/SyncedLocationDropdown.js +14 -11
  22. package/dist/es2019/ui/floating-toolbar.js +20 -3
  23. package/dist/esm/editor-commands/index.js +42 -4
  24. package/dist/esm/editor-commands/utils.js +14 -0
  25. package/dist/esm/pm-plugins/menu-and-toolbar-experiences.js +260 -0
  26. package/dist/esm/syncedBlockPlugin.js +21 -12
  27. package/dist/esm/types/index.js +5 -2
  28. package/dist/esm/ui/CreateSyncedBlockButton.js +2 -1
  29. package/dist/esm/ui/CreateSyncedBlockDropdownItem.js +2 -1
  30. package/dist/esm/ui/SyncBlockRefresher.js +18 -4
  31. package/dist/esm/ui/SyncedLocationDropdown.js +14 -11
  32. package/dist/esm/ui/floating-toolbar.js +22 -3
  33. package/dist/types/editor-commands/index.d.ts +8 -1
  34. package/dist/types/editor-commands/utils.d.ts +2 -0
  35. package/dist/types/pm-plugins/menu-and-toolbar-experiences.d.ts +12 -0
  36. package/dist/types/types/index.d.ts +5 -14
  37. package/dist/types-ts4.5/editor-commands/index.d.ts +8 -1
  38. package/dist/types-ts4.5/editor-commands/utils.d.ts +2 -0
  39. package/dist/types-ts4.5/pm-plugins/menu-and-toolbar-experiences.d.ts +12 -0
  40. package/dist/types-ts4.5/types/index.d.ts +5 -14
  41. package/package.json +3 -3
  42. package/dist/cjs/pm-plugins/experience-tracking/create-reference-experience.js +0 -113
  43. package/dist/cjs/pm-plugins/experience-tracking/create-source-experience.js +0 -169
  44. package/dist/cjs/pm-plugins/experience-tracking/delete-reference-experience.js +0 -175
  45. package/dist/cjs/pm-plugins/experience-tracking/delete-source-experience.js +0 -103
  46. package/dist/cjs/pm-plugins/experience-tracking/get-experience-tracking-plugins.js +0 -61
  47. package/dist/cjs/pm-plugins/experience-tracking/provider-only-experiences.js +0 -128
  48. package/dist/cjs/pm-plugins/utils/experience-tracking-utils.js +0 -85
  49. package/dist/es2019/pm-plugins/experience-tracking/create-reference-experience.js +0 -109
  50. package/dist/es2019/pm-plugins/experience-tracking/create-source-experience.js +0 -166
  51. package/dist/es2019/pm-plugins/experience-tracking/delete-reference-experience.js +0 -181
  52. package/dist/es2019/pm-plugins/experience-tracking/delete-source-experience.js +0 -98
  53. package/dist/es2019/pm-plugins/experience-tracking/get-experience-tracking-plugins.js +0 -46
  54. package/dist/es2019/pm-plugins/experience-tracking/provider-only-experiences.js +0 -127
  55. package/dist/es2019/pm-plugins/utils/experience-tracking-utils.js +0 -65
  56. package/dist/esm/pm-plugins/experience-tracking/create-reference-experience.js +0 -107
  57. package/dist/esm/pm-plugins/experience-tracking/create-source-experience.js +0 -163
  58. package/dist/esm/pm-plugins/experience-tracking/delete-reference-experience.js +0 -169
  59. package/dist/esm/pm-plugins/experience-tracking/delete-source-experience.js +0 -97
  60. package/dist/esm/pm-plugins/experience-tracking/get-experience-tracking-plugins.js +0 -55
  61. package/dist/esm/pm-plugins/experience-tracking/provider-only-experiences.js +0 -122
  62. package/dist/esm/pm-plugins/utils/experience-tracking-utils.js +0 -79
  63. package/dist/types/pm-plugins/experience-tracking/create-reference-experience.d.ts +0 -10
  64. package/dist/types/pm-plugins/experience-tracking/create-source-experience.d.ts +0 -10
  65. package/dist/types/pm-plugins/experience-tracking/delete-reference-experience.d.ts +0 -13
  66. package/dist/types/pm-plugins/experience-tracking/delete-source-experience.d.ts +0 -12
  67. package/dist/types/pm-plugins/experience-tracking/get-experience-tracking-plugins.d.ts +0 -5
  68. package/dist/types/pm-plugins/experience-tracking/provider-only-experiences.d.ts +0 -3
  69. package/dist/types/pm-plugins/utils/experience-tracking-utils.d.ts +0 -9
  70. package/dist/types-ts4.5/pm-plugins/experience-tracking/create-reference-experience.d.ts +0 -10
  71. package/dist/types-ts4.5/pm-plugins/experience-tracking/create-source-experience.d.ts +0 -10
  72. package/dist/types-ts4.5/pm-plugins/experience-tracking/delete-reference-experience.d.ts +0 -13
  73. package/dist/types-ts4.5/pm-plugins/experience-tracking/delete-source-experience.d.ts +0 -12
  74. package/dist/types-ts4.5/pm-plugins/experience-tracking/get-experience-tracking-plugins.d.ts +0 -5
  75. package/dist/types-ts4.5/pm-plugins/experience-tracking/provider-only-experiences.d.ts +0 -3
  76. package/dist/types-ts4.5/pm-plugins/utils/experience-tracking-utils.d.ts +0 -9
@@ -3,15 +3,18 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
3
3
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
4
  import React from 'react';
5
5
  import commonMessages, { syncBlockMessages as messages } from '@atlaskit/editor-common/messages';
6
+ import { FloatingToolbarButton as Button } from '@atlaskit/editor-common/ui';
6
7
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
7
8
  import { akEditorSelectedNodeClassName } from '@atlaskit/editor-shared-styles/consts';
8
9
  import { SyncBlockError } from '@atlaskit/editor-synced-block-provider';
9
10
  import CopyIcon from '@atlaskit/icon/core/copy';
10
11
  import DeleteIcon from '@atlaskit/icon/core/delete';
11
12
  import EditIcon from '@atlaskit/icon/core/edit';
13
+ import LinkBrokenIcon from '@atlaskit/icon/core/link-broken';
12
14
  import { fg } from '@atlaskit/platform-feature-flags';
13
- import { copySyncedBlockReferenceToClipboard, editSyncedBlockSource, removeSyncedBlock } from '../editor-commands';
15
+ import { copySyncedBlockReferenceToClipboard, editSyncedBlockSource, removeSyncedBlock, unsync } from '../editor-commands';
14
16
  import { findSyncBlockOrBodiedSyncBlock, isBodiedSyncBlockNode } from '../pm-plugins/utils/utils';
17
+ import { SYNCED_BLOCK_BUTTON_TEST_ID } from '../types';
15
18
  import { SyncedLocationDropdown } from './SyncedLocationDropdown';
16
19
  export var getToolbarConfig = function getToolbarConfig(state, intl, api, syncBlockStore) {
17
20
  var _api$decorations, _api$connectivity;
@@ -45,7 +48,7 @@ export var getToolbarConfig = function getToolbarConfig(state, intl, api, syncBl
45
48
  title: formatMessage(commonMessages.delete),
46
49
  onClick: removeSyncedBlock(api),
47
50
  icon: DeleteIcon,
48
- testId: fg('platform_synced_block_dogfooding') ? 'reference-synced-block-delete-button' : undefined
51
+ testId: fg('platform_synced_block_dogfooding') ? SYNCED_BLOCK_BUTTON_TEST_ID.syncedBlockToolbarReferenceDelete : undefined
49
52
  }, hoverDecorationProps(nodeType, akEditorSelectedNodeClassName));
50
53
  items.push(deleteButton);
51
54
  } else {
@@ -63,7 +66,23 @@ export var getToolbarConfig = function getToolbarConfig(state, intl, api, syncBl
63
66
  });
64
67
  }
65
68
  };
66
- items.push(syncedLocation);
69
+ var unsyncButton = {
70
+ type: 'custom',
71
+ fallback: [],
72
+ render: function render(view) {
73
+ return /*#__PURE__*/React.createElement(Button, {
74
+ areAnyNewToolbarFlagsEnabled: true,
75
+ icon: /*#__PURE__*/React.createElement(LinkBrokenIcon, {
76
+ label: ""
77
+ }),
78
+ title: formatMessage(messages.unsyncButton),
79
+ onClick: function onClick() {
80
+ return unsync(syncBlockStore, isBodiedSyncBlock, view);
81
+ }
82
+ });
83
+ }
84
+ };
85
+ items.push(syncedLocation, unsyncButton);
67
86
  }
68
87
  var copyButton = _objectSpread({
69
88
  id: 'editor.syncedBlock.copy',
@@ -1,15 +1,22 @@
1
+ import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
1
2
  import type { Command, EditorCommand, ExtractInjectionAPI, TypeAheadInsert } from '@atlaskit/editor-common/types';
2
3
  import { type Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
5
  import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
6
  import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
5
7
  type createSyncedBlockProps = {
8
+ fireAnalyticsEvent?: DispatchAnalyticsEvent;
6
9
  syncBlockStore: SyncBlockStoreManager;
7
10
  tr: Transaction;
8
11
  typeAheadInsert?: TypeAheadInsert;
9
12
  };
10
- export declare const createSyncedBlock: ({ tr, syncBlockStore, typeAheadInsert, }: createSyncedBlockProps) => false | Transaction;
13
+ export declare const createSyncedBlock: ({ tr, syncBlockStore, typeAheadInsert, fireAnalyticsEvent, }: createSyncedBlockProps) => false | Transaction;
11
14
  export declare const copySyncedBlockReferenceToClipboardEditorCommand: (syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => EditorCommand;
12
15
  export declare const copySyncedBlockReferenceToClipboard: (syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
13
16
  export declare const editSyncedBlockSource: (syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
14
17
  export declare const removeSyncedBlock: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
18
+ /**
19
+ * Deletes (bodied)SyncBlock node and paste its content to the editor
20
+ */
21
+ export declare const unsync: (storeManager: SyncBlockStoreManager, isBodiedSyncBlock: boolean, view?: EditorView) => boolean;
15
22
  export {};
@@ -0,0 +1,2 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ export declare const pasteSyncBlockHTMLContent: (contentDOM: HTMLElement | DocumentFragment, view: EditorView) => boolean;
@@ -0,0 +1,12 @@
1
+ import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ type ExperienceOptions = {
4
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent;
5
+ refs: {
6
+ containerElement?: HTMLElement;
7
+ popupsMountPoint?: HTMLElement;
8
+ wrapperElement?: HTMLElement;
9
+ };
10
+ };
11
+ export declare const getMenuAndToolbarExperiencesPlugin: ({ refs, dispatchAnalyticsEvent, }: ExperienceOptions) => SafePlugin<any>;
12
+ export {};
@@ -1,4 +1,3 @@
1
- import type { DispatchAnalyticsEvent } from "@atlaskit/editor-common/analytics";
2
1
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
2
  import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
3
  export declare enum FLAG_ID {
@@ -41,18 +40,10 @@ export type SyncBlockInfo = {
41
40
  export type SyncBlockMap = {
42
41
  [key: string]: SyncBlockInfo;
43
42
  };
44
- export type ExperienceOptions = {
45
- dispatchAnalyticsEvent: DispatchAnalyticsEvent;
46
- refs: {
47
- containerElement?: HTMLElement;
48
- popupsMountPoint?: HTMLElement;
49
- wrapperElement?: HTMLElement;
50
- };
51
- };
52
- export type ProviderExperienceOptions = ExperienceOptions & {
53
- syncBlockStore: SyncBlockStoreManager;
54
- };
55
- export declare const EXPERIENCE_ABORT_REASON: {
56
- EDITOR_DESTROYED: string;
43
+ export declare const SYNCED_BLOCK_BUTTON_TEST_ID: {
44
+ readonly primaryToolbarCreate: "create-synced-block-toolbar-btn";
45
+ readonly blockMenuCreate: "create-synced-block-block-menu-btn";
46
+ readonly quickInsertCreate: "create-synced-block-quick-insert-btn";
47
+ readonly syncedBlockToolbarReferenceDelete: "reference-synced-block-delete-btn";
57
48
  };
58
49
  export {};
@@ -1,15 +1,22 @@
1
+ import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
1
2
  import type { Command, EditorCommand, ExtractInjectionAPI, TypeAheadInsert } from '@atlaskit/editor-common/types';
2
3
  import { type Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
5
  import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
6
  import type { SyncedBlockPlugin } from '../syncedBlockPluginType';
5
7
  type createSyncedBlockProps = {
8
+ fireAnalyticsEvent?: DispatchAnalyticsEvent;
6
9
  syncBlockStore: SyncBlockStoreManager;
7
10
  tr: Transaction;
8
11
  typeAheadInsert?: TypeAheadInsert;
9
12
  };
10
- export declare const createSyncedBlock: ({ tr, syncBlockStore, typeAheadInsert, }: createSyncedBlockProps) => false | Transaction;
13
+ export declare const createSyncedBlock: ({ tr, syncBlockStore, typeAheadInsert, fireAnalyticsEvent, }: createSyncedBlockProps) => false | Transaction;
11
14
  export declare const copySyncedBlockReferenceToClipboardEditorCommand: (syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => EditorCommand;
12
15
  export declare const copySyncedBlockReferenceToClipboard: (syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
13
16
  export declare const editSyncedBlockSource: (syncBlockStore: SyncBlockStoreManager, api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
14
17
  export declare const removeSyncedBlock: (api?: ExtractInjectionAPI<SyncedBlockPlugin>) => Command;
18
+ /**
19
+ * Deletes (bodied)SyncBlock node and paste its content to the editor
20
+ */
21
+ export declare const unsync: (storeManager: SyncBlockStoreManager, isBodiedSyncBlock: boolean, view?: EditorView) => boolean;
15
22
  export {};
@@ -0,0 +1,2 @@
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
+ export declare const pasteSyncBlockHTMLContent: (contentDOM: HTMLElement | DocumentFragment, view: EditorView) => boolean;
@@ -0,0 +1,12 @@
1
+ import { type DispatchAnalyticsEvent } from '@atlaskit/editor-common/analytics';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ type ExperienceOptions = {
4
+ dispatchAnalyticsEvent: DispatchAnalyticsEvent;
5
+ refs: {
6
+ containerElement?: HTMLElement;
7
+ popupsMountPoint?: HTMLElement;
8
+ wrapperElement?: HTMLElement;
9
+ };
10
+ };
11
+ export declare const getMenuAndToolbarExperiencesPlugin: ({ refs, dispatchAnalyticsEvent, }: ExperienceOptions) => SafePlugin<any>;
12
+ export {};
@@ -1,4 +1,3 @@
1
- import type { DispatchAnalyticsEvent } from "@atlaskit/editor-common/analytics";
2
1
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
3
2
  import type { SyncBlockStoreManager } from '@atlaskit/editor-synced-block-provider';
4
3
  export declare enum FLAG_ID {
@@ -41,18 +40,10 @@ export type SyncBlockInfo = {
41
40
  export type SyncBlockMap = {
42
41
  [key: string]: SyncBlockInfo;
43
42
  };
44
- export type ExperienceOptions = {
45
- dispatchAnalyticsEvent: DispatchAnalyticsEvent;
46
- refs: {
47
- containerElement?: HTMLElement;
48
- popupsMountPoint?: HTMLElement;
49
- wrapperElement?: HTMLElement;
50
- };
51
- };
52
- export type ProviderExperienceOptions = ExperienceOptions & {
53
- syncBlockStore: SyncBlockStoreManager;
54
- };
55
- export declare const EXPERIENCE_ABORT_REASON: {
56
- EDITOR_DESTROYED: string;
43
+ export declare const SYNCED_BLOCK_BUTTON_TEST_ID: {
44
+ readonly primaryToolbarCreate: "create-synced-block-toolbar-btn";
45
+ readonly blockMenuCreate: "create-synced-block-block-menu-btn";
46
+ readonly quickInsertCreate: "create-synced-block-quick-insert-btn";
47
+ readonly syncedBlockToolbarReferenceDelete: "reference-synced-block-delete-btn";
57
48
  };
58
49
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-synced-block",
3
- "version": "5.2.1",
3
+ "version": "5.3.0",
4
4
  "description": "SyncedBlock plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -40,7 +40,7 @@
40
40
  "@atlaskit/editor-plugin-selection": "^7.0.0",
41
41
  "@atlaskit/editor-prosemirror": "^7.2.0",
42
42
  "@atlaskit/editor-shared-styles": "^3.10.0",
43
- "@atlaskit/editor-synced-block-provider": "^3.11.0",
43
+ "@atlaskit/editor-synced-block-provider": "^3.13.0",
44
44
  "@atlaskit/editor-tables": "^2.9.0",
45
45
  "@atlaskit/editor-toolbar": "^0.19.0",
46
46
  "@atlaskit/flag": "^17.8.0",
@@ -52,7 +52,7 @@
52
52
  "@atlaskit/platform-feature-flags": "^1.1.0",
53
53
  "@atlaskit/primitives": "^17.1.0",
54
54
  "@atlaskit/spinner": "19.0.9",
55
- "@atlaskit/tmp-editor-statsig": "^16.26.0",
55
+ "@atlaskit/tmp-editor-statsig": "^16.30.0",
56
56
  "@atlaskit/tokens": "10.1.0",
57
57
  "@atlaskit/tooltip": "^20.14.0",
58
58
  "@atlaskit/visually-hidden": "^3.0.0",
@@ -1,113 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getCreateReferenceExperiencePlugin = void 0;
7
- var _analytics = require("@atlaskit/editor-common/analytics");
8
- var _experiences = require("@atlaskit/editor-common/experiences");
9
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
10
- var _state = require("@atlaskit/editor-prosemirror/state");
11
- var _types = require("../../types");
12
- var _experienceTrackingUtils = require("../utils/experience-tracking-utils");
13
- var isPastedFromFabricEditor = function isPastedFromFabricEditor(html) {
14
- return !!html && html.indexOf('data-pm-slice="') >= 0;
15
- };
16
- var pluginKey = new _state.PluginKey('createReferenceSyncBlockExperience');
17
- var START_METHOD = {
18
- PASTE: 'paste',
19
- UNDO: 'undo',
20
- REDO: 'redo'
21
- };
22
-
23
- /**
24
- * This experience tracks when a reference sync block is inserted.
25
- *
26
- * Start: When user pastes a sync block from editor and createSyncedBlock is called
27
- * Success: When the sync block is added to the DOM within 500ms of start
28
- * Failure: When 500ms passes without the reference sync block being added to the DOM
29
- */
30
- var getCreateReferenceExperiencePlugin = exports.getCreateReferenceExperiencePlugin = function getCreateReferenceExperiencePlugin(_ref) {
31
- var refs = _ref.refs,
32
- dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent;
33
- var experience = getCreateReferenceExperience({
34
- refs: refs,
35
- dispatchAnalyticsEvent: dispatchAnalyticsEvent
36
- });
37
- return new _safePlugin.SafePlugin({
38
- key: pluginKey,
39
- view: function view() {
40
- return {
41
- destroy: function destroy() {
42
- experience.abort({
43
- reason: _types.EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
44
- });
45
- }
46
- };
47
- },
48
- props: {
49
- handlePaste: function handlePaste(_view, rawEvent, slice) {
50
- var _event$clipboardData;
51
- var event = rawEvent;
52
- var html = (_event$clipboardData = event.clipboardData) === null || _event$clipboardData === void 0 ? void 0 : _event$clipboardData.getData('text/html');
53
-
54
- // do not start on paste from renderer, because this flattens the content and does not create a reference block
55
- if (isPastedFromFabricEditor(html)) {
56
- slice.content.forEach(function (node) {
57
- if (node.type.name === 'syncBlock' || node.type.name === 'bodiedSyncBlock') {
58
- experience.start({
59
- method: START_METHOD.PASTE
60
- });
61
- }
62
- });
63
- }
64
- }
65
- },
66
- appendTransaction: function appendTransaction(transactions, oldState, newState) {
67
- transactions.forEach(function (tr) {
68
- var _wasSyncBlockDeletedO = (0, _experienceTrackingUtils.wasSyncBlockDeletedOrAddedByHistory)(tr, oldState, newState),
69
- hasAddedSyncBlock = _wasSyncBlockDeletedO.hasAddedSyncBlock,
70
- isUndo = _wasSyncBlockDeletedO.isUndo;
71
- if (hasAddedSyncBlock) {
72
- experience.start({
73
- method: isUndo ? START_METHOD.UNDO : START_METHOD.REDO
74
- });
75
- }
76
- });
77
- return null;
78
- }
79
- });
80
- };
81
- var getCreateReferenceExperience = function getCreateReferenceExperience(_ref2) {
82
- var refs = _ref2.refs,
83
- dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
84
- return new _experiences.Experience(_analytics.ACTION_SUBJECT.SYNCED_BLOCK, {
85
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.REFERENCE_SYNCED_BLOCK_CREATE,
86
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
87
- checks: [new _experiences.ExperienceCheckTimeout({
88
- durationMs: 500
89
- }), new _experiences.ExperienceCheckDomMutation({
90
- onDomMutation: function onDomMutation(_ref3) {
91
- var mutations = _ref3.mutations;
92
- var insertedResourceIds = (0, _experienceTrackingUtils.getAddedResourceIds)(mutations, '[data-prosemirror-node-name="syncBlock"]');
93
- if (insertedResourceIds.length > 0) {
94
- return {
95
- status: 'success',
96
- metadata: {
97
- insertedResourceIds: insertedResourceIds
98
- }
99
- };
100
- }
101
- return undefined;
102
- },
103
- observeConfig: function observeConfig() {
104
- return {
105
- target: (0, _experienceTrackingUtils.getTarget)(refs.containerElement),
106
- options: {
107
- childList: true
108
- }
109
- };
110
- }
111
- })]
112
- });
113
- };
@@ -1,169 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.getCreateSourceExperiencePlugin = void 0;
7
- var _bindEventListener = require("bind-event-listener");
8
- var _analytics = require("@atlaskit/editor-common/analytics");
9
- var _experiences = require("@atlaskit/editor-common/experiences");
10
- var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
11
- var _state = require("@atlaskit/editor-prosemirror/state");
12
- var _types = require("../../types");
13
- var _experienceTrackingUtils = require("../utils/experience-tracking-utils");
14
- var pluginKey = new _state.PluginKey('createSourceSyncBlockExperience');
15
- var START_METHOD = {
16
- BLOCK_MENU: 'block-menu',
17
- PINNED_TOOLBAR: 'pinned-toolbar',
18
- QUICK_INSERT: 'quick-insert'
19
- };
20
- var SYNCED_BLOCK_CREATE_BUTTON_IDS = ['create-synced-block-toolbar-btn', 'create-synced-block-block-menu-btn', 'create-synced-block-quick-insert-btn'];
21
- var syncedBlockCreateButtonIds = new Set(SYNCED_BLOCK_CREATE_BUTTON_IDS);
22
-
23
- /**
24
- * This experience tracks when a source sync block is inserted.
25
- *
26
- * Start: When user inserts a sync block via block menu, quick insert or pinned toolbar
27
- * Success: When the sync block is added to the DOM within 3000ms of start
28
- * Failure: When 3000ms passes without the source sync block being added to the DOM
29
- */
30
- var getCreateSourceExperiencePlugin = exports.getCreateSourceExperiencePlugin = function getCreateSourceExperiencePlugin(_ref) {
31
- var refs = _ref.refs,
32
- dispatchAnalyticsEvent = _ref.dispatchAnalyticsEvent,
33
- syncBlockStore = _ref.syncBlockStore;
34
- var popupsTargetEl;
35
- var editorViewEl;
36
- var getPopupsTarget = function getPopupsTarget() {
37
- if (!popupsTargetEl) {
38
- popupsTargetEl = refs.popupsMountPoint || refs.wrapperElement || (0, _experiences.getPopupContainerFromEditorView)(editorViewEl);
39
- }
40
- return popupsTargetEl;
41
- };
42
- var experience = getCreateSourceExperience({
43
- refs: refs,
44
- dispatchAnalyticsEvent: dispatchAnalyticsEvent
45
- });
46
- syncBlockStore.sourceManager.setCreateExperience(experience);
47
- var unbindClickListener = (0, _bindEventListener.bind)(document, {
48
- type: 'click',
49
- listener: function listener(event) {
50
- var target = event.target;
51
- if (!target) {
52
- return;
53
- }
54
- var button = target.closest('button[data-testid]');
55
- if (!button || !(button instanceof HTMLButtonElement)) {
56
- return;
57
- }
58
- var testId = button.dataset.testid;
59
- if (!isSyncedBlockCreateButtonId(testId)) {
60
- return;
61
- }
62
- handleButtonClick(testId, experience);
63
- }
64
- });
65
- var unbindKeydownListener = (0, _bindEventListener.bind)(document, {
66
- type: 'keydown',
67
- listener: function listener(event) {
68
- if (isEnterKey(event.key)) {
69
- var typeaheadPopup = (0, _experiences.popupWithNestedElement)(getPopupsTarget(), '.fabric-editor-typeahead');
70
- if (!typeaheadPopup || !(typeaheadPopup instanceof HTMLElement)) {
71
- return;
72
- }
73
- var firstItem = typeaheadPopup.querySelector('[role="option"]');
74
- if (!firstItem || !(firstItem instanceof HTMLElement)) {
75
- return;
76
- }
77
- var testId = firstItem.dataset.testid;
78
- if (testId === 'create-synced-block-quick-insert-btn') {
79
- experience.start({
80
- method: START_METHOD.QUICK_INSERT
81
- });
82
- }
83
- }
84
- },
85
- options: {
86
- capture: true
87
- }
88
- });
89
- return new _safePlugin.SafePlugin({
90
- key: pluginKey,
91
- view: function view(editorView) {
92
- editorViewEl = editorView.dom;
93
- return {
94
- destroy: function destroy() {
95
- experience.abort({
96
- reason: _types.EXPERIENCE_ABORT_REASON.EDITOR_DESTROYED
97
- });
98
- unbindClickListener();
99
- unbindKeydownListener();
100
- }
101
- };
102
- }
103
- });
104
- };
105
- var getCreateSourceExperience = function getCreateSourceExperience(_ref2) {
106
- var refs = _ref2.refs,
107
- dispatchAnalyticsEvent = _ref2.dispatchAnalyticsEvent;
108
- return new _experiences.Experience(_analytics.ACTION_SUBJECT.SYNCED_BLOCK, {
109
- actionSubjectId: _analytics.ACTION_SUBJECT_ID.SYNCED_BLOCK_CREATE,
110
- dispatchAnalyticsEvent: dispatchAnalyticsEvent,
111
- checks: [new _experiences.ExperienceCheckTimeout({
112
- durationMs: 3000
113
- }), new _experiences.ExperienceCheckDomMutation({
114
- onDomMutation: function onDomMutation(_ref3) {
115
- var mutations = _ref3.mutations;
116
- var createdResourceIds = (0, _experienceTrackingUtils.getAddedResourceIds)(mutations, '[data-prosemirror-node-name="bodiedSyncBlock"]');
117
- if (createdResourceIds.length > 0) {
118
- return {
119
- status: 'success',
120
- metadata: {
121
- createdResourceIds: createdResourceIds
122
- }
123
- };
124
- }
125
- return undefined;
126
- },
127
- observeConfig: function observeConfig() {
128
- return {
129
- target: (0, _experienceTrackingUtils.getTarget)(refs.containerElement),
130
- options: {
131
- childList: true
132
- }
133
- };
134
- }
135
- })]
136
- });
137
- };
138
- var isSyncedBlockCreateButtonId = function isSyncedBlockCreateButtonId(value) {
139
- return !!value && syncedBlockCreateButtonIds.has(value);
140
- };
141
- var handleButtonClick = function handleButtonClick(testId, experience) {
142
- switch (testId) {
143
- case 'create-synced-block-toolbar-btn':
144
- experience.start({
145
- method: START_METHOD.PINNED_TOOLBAR
146
- });
147
- break;
148
- case 'create-synced-block-block-menu-btn':
149
- experience.start({
150
- method: START_METHOD.BLOCK_MENU
151
- });
152
- break;
153
- case 'create-synced-block-quick-insert-btn':
154
- experience.start({
155
- method: START_METHOD.QUICK_INSERT
156
- });
157
- break;
158
- default:
159
- {
160
- // Exhaustiveness check: if a new SyncedBlockToolbarButtonId is added
161
- // but not handled above, TypeScript will error here.
162
- var _exhaustiveCheck = testId;
163
- return _exhaustiveCheck;
164
- }
165
- }
166
- };
167
- var isEnterKey = function isEnterKey(key) {
168
- return key === 'Enter';
169
- };