@atlaskit/editor-plugin-card 0.3.3 → 0.3.5

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 (99) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/analytics/create-events-queue.js +55 -0
  3. package/dist/cjs/{pm-plugins/analytics → analytics}/events-from-tr.js +90 -81
  4. package/dist/cjs/{pm-plugins/analytics → analytics}/index.js +3 -3
  5. package/dist/cjs/analytics/types.js +24 -0
  6. package/dist/cjs/analytics/utils.js +134 -0
  7. package/dist/cjs/plugin.js +7 -4
  8. package/dist/cjs/pm-plugins/actions.js +1 -10
  9. package/dist/cjs/pm-plugins/doc.js +3 -0
  10. package/dist/cjs/pm-plugins/main.js +15 -13
  11. package/dist/cjs/pm-plugins/reducers.js +0 -7
  12. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +52 -0
  13. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/LinkEvents.js +132 -0
  14. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/common.js +65 -0
  15. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/index.js +54 -0
  16. package/dist/cjs/version.json +1 -1
  17. package/dist/es2019/analytics/create-events-queue.js +43 -0
  18. package/dist/es2019/{pm-plugins/analytics → analytics}/events-from-tr.js +82 -72
  19. package/dist/es2019/analytics/index.js +2 -0
  20. package/dist/es2019/analytics/types.js +17 -0
  21. package/dist/es2019/analytics/utils.js +118 -0
  22. package/dist/es2019/plugin.js +7 -6
  23. package/dist/es2019/pm-plugins/actions.js +0 -4
  24. package/dist/es2019/pm-plugins/doc.js +3 -0
  25. package/dist/es2019/pm-plugins/main.js +15 -15
  26. package/dist/es2019/pm-plugins/reducers.js +0 -8
  27. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +46 -0
  28. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/LinkEvents.js +127 -0
  29. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/common.js +60 -0
  30. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/index.js +30 -0
  31. package/dist/es2019/version.json +1 -1
  32. package/dist/esm/analytics/create-events-queue.js +48 -0
  33. package/dist/esm/{pm-plugins/analytics → analytics}/events-from-tr.js +90 -80
  34. package/dist/esm/analytics/index.js +2 -0
  35. package/dist/esm/analytics/types.js +17 -0
  36. package/dist/esm/analytics/utils.js +118 -0
  37. package/dist/esm/plugin.js +7 -4
  38. package/dist/esm/pm-plugins/actions.js +0 -8
  39. package/dist/esm/pm-plugins/doc.js +3 -0
  40. package/dist/esm/pm-plugins/main.js +15 -13
  41. package/dist/esm/pm-plugins/reducers.js +0 -7
  42. package/dist/esm/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +44 -0
  43. package/dist/esm/ui/EditorLinkingPlatformAnalytics/LinkEvents.js +125 -0
  44. package/dist/esm/ui/EditorLinkingPlatformAnalytics/common.js +55 -0
  45. package/dist/esm/ui/EditorLinkingPlatformAnalytics/index.js +47 -0
  46. package/dist/esm/version.json +1 -1
  47. package/dist/types/analytics/create-events-queue.d.ts +21 -0
  48. package/dist/types/analytics/events-from-tr.d.ts +19 -0
  49. package/dist/types/analytics/index.d.ts +2 -0
  50. package/dist/types/analytics/types.d.ts +66 -0
  51. package/dist/types/analytics/utils.d.ts +22 -0
  52. package/dist/types/pm-plugins/actions.d.ts +1 -2
  53. package/dist/types/pm-plugins/util/state.d.ts +0 -1
  54. package/dist/types/types.d.ts +4 -34
  55. package/dist/types/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +6 -0
  56. package/dist/types/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +6 -0
  57. package/dist/types/ui/EditorLinkingPlatformAnalytics/common.d.ts +20 -0
  58. package/dist/types/ui/EditorLinkingPlatformAnalytics/index.d.ts +9 -0
  59. package/dist/types-ts4.5/analytics/create-events-queue.d.ts +21 -0
  60. package/dist/types-ts4.5/analytics/events-from-tr.d.ts +19 -0
  61. package/dist/types-ts4.5/analytics/index.d.ts +2 -0
  62. package/dist/types-ts4.5/analytics/types.d.ts +66 -0
  63. package/dist/types-ts4.5/analytics/utils.d.ts +22 -0
  64. package/dist/types-ts4.5/pm-plugins/actions.d.ts +1 -2
  65. package/dist/types-ts4.5/pm-plugins/util/state.d.ts +0 -1
  66. package/dist/types-ts4.5/types.d.ts +4 -34
  67. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +6 -0
  68. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +6 -0
  69. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/common.d.ts +20 -0
  70. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/index.d.ts +9 -0
  71. package/package.json +3 -3
  72. package/report.api.md +84 -8
  73. package/tmp/api-report-tmp.d.ts +81 -8
  74. package/dist/cjs/pm-plugins/analytics/create-analytics-queue.js +0 -48
  75. package/dist/cjs/pm-plugins/analytics/types.js +0 -5
  76. package/dist/cjs/pm-plugins/analytics/utils.js +0 -178
  77. package/dist/cjs/ui/EditorSmartCardEventsNext.js +0 -204
  78. package/dist/es2019/pm-plugins/analytics/create-analytics-queue.js +0 -38
  79. package/dist/es2019/pm-plugins/analytics/index.js +0 -2
  80. package/dist/es2019/pm-plugins/analytics/types.js +0 -1
  81. package/dist/es2019/pm-plugins/analytics/utils.js +0 -160
  82. package/dist/es2019/ui/EditorSmartCardEventsNext.js +0 -188
  83. package/dist/esm/pm-plugins/analytics/create-analytics-queue.js +0 -41
  84. package/dist/esm/pm-plugins/analytics/index.js +0 -2
  85. package/dist/esm/pm-plugins/analytics/types.js +0 -1
  86. package/dist/esm/pm-plugins/analytics/utils.js +0 -160
  87. package/dist/esm/ui/EditorSmartCardEventsNext.js +0 -192
  88. package/dist/types/pm-plugins/analytics/create-analytics-queue.d.ts +0 -10
  89. package/dist/types/pm-plugins/analytics/events-from-tr.d.ts +0 -17
  90. package/dist/types/pm-plugins/analytics/index.d.ts +0 -2
  91. package/dist/types/pm-plugins/analytics/types.d.ts +0 -12
  92. package/dist/types/pm-plugins/analytics/utils.d.ts +0 -32
  93. package/dist/types/ui/EditorSmartCardEventsNext.d.ts +0 -18
  94. package/dist/types-ts4.5/pm-plugins/analytics/create-analytics-queue.d.ts +0 -10
  95. package/dist/types-ts4.5/pm-plugins/analytics/events-from-tr.d.ts +0 -17
  96. package/dist/types-ts4.5/pm-plugins/analytics/index.d.ts +0 -2
  97. package/dist/types-ts4.5/pm-plugins/analytics/types.d.ts +0 -12
  98. package/dist/types-ts4.5/pm-plugins/analytics/utils.d.ts +0 -32
  99. package/dist/types-ts4.5/ui/EditorSmartCardEventsNext.d.ts +0 -18
@@ -6,6 +6,7 @@ import { blockCard, embedCard, inlineCard } from '@atlaskit/adf-schema';
6
6
  import { IconDatasourceAssetsObjects, IconDatasourceJiraIssue } from '@atlaskit/editor-common/quick-insert';
7
7
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
8
8
  import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, JIRA_LIST_OF_LINKS_DATASOURCE_ID } from '@atlaskit/link-datasource';
9
+ import { createEventsQueue } from './analytics/create-events-queue';
9
10
  import { messages } from './messages';
10
11
  import { hideLinkToolbar, showDatasourceModal } from './pm-plugins/actions';
11
12
  import { changeSelectedCardToLink, queueCardsFromChangedTr, setSelectedCardAppearance } from './pm-plugins/doc';
@@ -15,12 +16,13 @@ import { mountHyperlinkPlugin } from './pm-plugins/mountHyperlink';
15
16
  import { pluginKey } from './pm-plugins/plugin-key';
16
17
  import { floatingToolbar } from './toolbar';
17
18
  import DatasourceModalWithState from './ui/DatasourceModal/ModalWithState';
19
+ import { EditorLinkingPlatformAnalytics } from './ui/EditorLinkingPlatformAnalytics';
18
20
  import { EditorSmartCardEvents } from './ui/EditorSmartCardEvents';
19
- import { EditorSmartCardEventsNext } from './ui/EditorSmartCardEventsNext';
20
21
  import LayoutButton from './ui/LayoutButton';
21
22
  export var cardPlugin = function cardPlugin(options, api) {
22
23
  var _api$dependencies, _api$dependencies$fea;
23
24
  var featureFlags = (api === null || api === void 0 ? void 0 : (_api$dependencies = api.dependencies) === null || _api$dependencies === void 0 ? void 0 : (_api$dependencies$fea = _api$dependencies.featureFlags) === null || _api$dependencies$fea === void 0 ? void 0 : _api$dependencies$fea.sharedState.currentState()) || {};
25
+ var cardPluginEvents = featureFlags !== null && featureFlags !== void 0 && featureFlags.lpAnalyticsEventsNext ? createEventsQueue() : undefined;
24
26
  return {
25
27
  name: 'card',
26
28
  getSharedState: function getSharedState(editorState) {
@@ -61,7 +63,8 @@ export var cardPlugin = function cardPlugin(options, api) {
61
63
  useAlternativePreloader: useAlternativePreloader,
62
64
  allowWrapping: allowWrapping,
63
65
  allowAlignment: allowAlignment,
64
- allowDatasource: allowDatasource
66
+ allowDatasource: allowDatasource,
67
+ cardPluginEvents: cardPluginEvents
65
68
  }), api)
66
69
  }, {
67
70
  name: 'cardHyperlink',
@@ -83,10 +86,10 @@ export var cardPlugin = function cardPlugin(options, api) {
83
86
  popupsMountPoint = _ref2.popupsMountPoint,
84
87
  popupsScrollableElement = _ref2.popupsScrollableElement,
85
88
  popupsBoundariesElement = _ref2.popupsBoundariesElement;
86
- var lpAnalyticsEventsNext = featureFlags.lpAnalyticsEventsNext;
87
89
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorSmartCardEvents, {
88
90
  editorView: editorView
89
- }), lpAnalyticsEventsNext && /*#__PURE__*/React.createElement(EditorSmartCardEventsNext, {
91
+ }), cardPluginEvents && /*#__PURE__*/React.createElement(EditorLinkingPlatformAnalytics, {
92
+ cardPluginEvents: cardPluginEvents,
90
93
  editorView: editorView
91
94
  }), /*#__PURE__*/React.createElement(LayoutButton, {
92
95
  api: api,
@@ -34,14 +34,6 @@ export var registerSmartCardEvents = function registerSmartCardEvents(smartLinkE
34
34
  });
35
35
  };
36
36
  };
37
- export var registerSmartCardEventsNext = function registerSmartCardEventsNext(smartLinkEvents) {
38
- return function (tr) {
39
- return cardAction(tr, {
40
- type: 'REGISTER_EVENTS_NEXT',
41
- smartLinkEvents: smartLinkEvents
42
- });
43
- };
44
- };
45
37
  export var setProvider = function setProvider(cardProvider) {
46
38
  return function (tr) {
47
39
  return cardAction(tr, {
@@ -436,6 +436,9 @@ export var updateExistingDatasource = function updateExistingDatasource(state, n
436
436
  var isUrlChange = ((_newAdf$attrs = newAdf.attrs) === null || _newAdf$attrs === void 0 ? void 0 : _newAdf$attrs.url) !== ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.url);
437
437
  if (isColumnChange || isUrlChange) {
438
438
  tr.setNodeMarkup(from, schemaNodes.blockCard, _objectSpread(_objectSpread({}, node.attrs), newAdf.attrs));
439
+ addLinkMetadata(state.selection, tr, {
440
+ action: ACTION.UPDATED
441
+ });
439
442
  }
440
443
  } else if (newAdf.type === 'inlineCard') {
441
444
  // datasource to inline
@@ -6,12 +6,12 @@ import { DATASOURCE_INNER_CONTAINER_CLASSNAME } from '@atlaskit/editor-common/st
6
6
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
7
7
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
8
8
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
9
+ import { eventsFromTransaction } from '../analytics/events-from-tr';
9
10
  import { BlockCard } from '../nodeviews/blockCard';
10
11
  import { Datasource } from '../nodeviews/datasource';
11
12
  import { EmbedCard } from '../nodeviews/embedCard';
12
13
  import { InlineCardNodeView } from '../nodeviews/inlineCard';
13
14
  import { setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
14
- import { createAnalyticsQueue, eventsFromTransaction } from './analytics';
15
15
  import { pluginKey } from './plugin-key';
16
16
  import reducer from './reducers';
17
17
  import { handleProvider, resolveWithProvider } from './util/resolve';
@@ -19,14 +19,13 @@ import { getNewRequests, getPluginState, getPluginStateWithUpdatedPos } from './
19
19
  export { pluginKey } from './plugin-key';
20
20
  export var createPlugin = function createPlugin(options, pluginInjectionApi) {
21
21
  return function (pmPluginFactoryParams) {
22
- var lpAnalyticsEventsNext = pmPluginFactoryParams.featureFlags.lpAnalyticsEventsNext;
23
- var analyticsQueue = createAnalyticsQueue(!!lpAnalyticsEventsNext);
24
22
  var editorAppearance = options.editorAppearance,
25
23
  platform = options.platform,
26
24
  allowResizing = options.allowResizing,
27
25
  useAlternativePreloader = options.useAlternativePreloader,
28
26
  fullWidthMode = options.fullWidthMode,
29
- showServerActions = options.showServerActions;
27
+ showServerActions = options.showServerActions,
28
+ cardPluginEvents = options.cardPluginEvents;
30
29
  var inlineCardViewProducer = getInlineNodeViewProducer({
31
30
  pmPluginFactoryParams: pmPluginFactoryParams,
32
31
  Component: InlineCardNodeView,
@@ -44,7 +43,6 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
44
43
  cards: [],
45
44
  showLinkingToolbar: false,
46
45
  smartLinkEvents: undefined,
47
- smartLinkEventsNext: undefined,
48
46
  editorAppearance: editorAppearance,
49
47
  showDatasourceModal: false,
50
48
  datasourceModalType: undefined,
@@ -59,14 +57,12 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
59
57
 
60
58
  // apply any actions
61
59
  var meta = tr.getMeta(pluginKey);
62
- var events = eventsFromTransaction(tr, prevEditorState);
63
- analyticsQueue.push.apply(analyticsQueue, _toConsumableArray(events));
60
+ if (cardPluginEvents) {
61
+ var events = eventsFromTransaction(tr, prevEditorState);
62
+ cardPluginEvents.push.apply(cardPluginEvents, _toConsumableArray(events));
63
+ }
64
64
  if (meta) {
65
- var nextState = reducer(pluginStateWithUpdatedPos, meta);
66
- if (!pluginState.smartLinkEventsNext && nextState.smartLinkEventsNext) {
67
- analyticsQueue.setCallbacks(nextState.smartLinkEventsNext);
68
- }
69
- return nextState;
65
+ return reducer(pluginStateWithUpdatedPos, meta);
70
66
  }
71
67
  return pluginStateWithUpdatedPos;
72
68
  }
@@ -134,7 +130,13 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
134
130
  invoke();
135
131
  });
136
132
  }
137
- analyticsQueue.flush();
133
+
134
+ /**
135
+ * If there have been any events queued, flush them
136
+ * so subscribers can now be notified and dispatch
137
+ * analytics events
138
+ */
139
+ cardPluginEvents === null || cardPluginEvents === void 0 ? void 0 : cardPluginEvents.flush();
138
140
  },
139
141
  destroy: function destroy() {
140
142
  // Cancel any outstanding raf callbacks.
@@ -50,11 +50,6 @@ var registerEvents = function registerEvents(state, action) {
50
50
  smartLinkEvents: action.smartLinkEvents
51
51
  });
52
52
  };
53
- var registerEventsNext = function registerEventsNext(state, action) {
54
- return _objectSpread(_objectSpread({}, state), {}, {
55
- smartLinkEventsNext: action.smartLinkEvents
56
- });
57
- };
58
53
  var setLinkToolbar = function setLinkToolbar(state, action) {
59
54
  return _objectSpread(_objectSpread({}, state), {}, {
60
55
  showLinkingToolbar: action.type === 'SHOW_LINK_TOOLBAR'
@@ -84,8 +79,6 @@ export default (function (state, action) {
84
79
  return register(state, action);
85
80
  case 'REGISTER_EVENTS':
86
81
  return registerEvents(state, action);
87
- case 'REGISTER_EVENTS_NEXT':
88
- return registerEventsNext(state, action);
89
82
  case 'SET_DATASOURCE_TABLE_REF':
90
83
  return setDatasourceTableRef(state, action);
91
84
  case 'SET_CARD_LAYOUT':
@@ -0,0 +1,44 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import { useEffect, useMemo } from 'react';
3
+ import { EVENT, EVENT_SUBJECT } from '../../analytics/types';
4
+ /**
5
+ * Subscribes to the events occuring in the card
6
+ * plugin and fires analytics events accordingly
7
+ */
8
+ export var DatasourceEventsBinding = function DatasourceEventsBinding(_ref) {
9
+ var cardPluginEvents = _ref.cardPluginEvents;
10
+ var eventHandlers = useMemo(function () {
11
+ var _ref2;
12
+ return _ref2 = {}, _defineProperty(_ref2, EVENT.CREATED, function (metadata) {
13
+ // TODO Impl as part of https://product-fabric.atlassian.net/browse/EDM-7072
14
+ // eslint-disable-next-line no-console
15
+ console.log('CREATED', metadata.node, metadata.nodeContext);
16
+ }), _defineProperty(_ref2, EVENT.UPDATED, function (metadata) {
17
+ // TODO Impl as part of https://product-fabric.atlassian.net/browse/EDM-7072
18
+ // eslint-disable-next-line no-console
19
+ console.log('UPDATED', metadata.node, metadata.nodeContext);
20
+ }), _defineProperty(_ref2, EVENT.DELETED, function (metadata) {
21
+ // TODO Impl as part of https://product-fabric.atlassian.net/browse/EDM-7072
22
+ // eslint-disable-next-line no-console
23
+ console.log('DELETED', metadata.node, metadata.nodeContext);
24
+ }), _ref2;
25
+ }, []);
26
+
27
+ /**
28
+ * Subscribe to datasource events
29
+ */
30
+ useEffect(function () {
31
+ var unsubscribe = cardPluginEvents.subscribe(function (_ref3) {
32
+ var event = _ref3.event,
33
+ subject = _ref3.subject,
34
+ data = _ref3.data;
35
+ if (subject === EVENT_SUBJECT.DATASOURCE) {
36
+ eventHandlers[event](data);
37
+ }
38
+ });
39
+ return function () {
40
+ return unsubscribe();
41
+ };
42
+ }, [eventHandlers, cardPluginEvents]);
43
+ return null;
44
+ };
@@ -0,0 +1,125 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ var _excluded = ["node", "nodeContext"],
4
+ _excluded2 = ["node", "nodeContext", "previousDisplay"],
5
+ _excluded3 = ["node", "nodeContext"];
6
+ import { useEffect, useMemo } from 'react';
7
+ import { useSmartLinkLifecycleAnalytics } from '@atlaskit/link-analytics';
8
+ import { EVENT, EVENT_SUBJECT } from '../../analytics/types';
9
+ import { appearanceForLink, getUrl } from '../../analytics/utils';
10
+ import { getDeleteType, getMethod, getSourceEventFromMetadata, getUpdateType } from './common';
11
+
12
+ /**
13
+ * Set display category as `link` if not displaying the link as a smart card
14
+ */
15
+ var displayCategoryFromDisplay = function displayCategoryFromDisplay(display) {
16
+ if (display === 'url') {
17
+ return 'link';
18
+ }
19
+ };
20
+ /**
21
+ * Subscribes to the events occuring in the card
22
+ * plugin and fires analytics events accordingly
23
+ */
24
+ export var LinkEventsBinding = function LinkEventsBinding(_ref) {
25
+ var cardPluginEvents = _ref.cardPluginEvents;
26
+ /**
27
+ * These callbacks internally use window.requestIdleCallback/requestAnimationFrame
28
+ * to defer any heavy operations involving network
29
+ *
30
+ * The callbacks themselves should not be deferred, they should be called syncronously the moment
31
+ * the events take place.
32
+ */
33
+ var _useSmartLinkLifecycl = useSmartLinkLifecycleAnalytics(),
34
+ linkCreated = _useSmartLinkLifecycl.linkCreated,
35
+ linkUpdated = _useSmartLinkLifecycl.linkUpdated,
36
+ linkDeleted = _useSmartLinkLifecycl.linkDeleted;
37
+ var linkEvents = useMemo(function () {
38
+ var _ref5;
39
+ return _ref5 = {}, _defineProperty(_ref5, EVENT.CREATED, function (_ref2) {
40
+ var node = _ref2.node,
41
+ nodeContext = _ref2.nodeContext,
42
+ metadata = _objectWithoutProperties(_ref2, _excluded);
43
+ var url = getUrl(node);
44
+ if (!url) {
45
+ return;
46
+ }
47
+ var display = appearanceForLink(node);
48
+ var displayCategory = displayCategoryFromDisplay(display);
49
+ var sourceEvent = getSourceEventFromMetadata(metadata);
50
+ var creationMethod = getMethod(metadata);
51
+ linkCreated({
52
+ url: url,
53
+ displayCategory: displayCategory
54
+ }, sourceEvent, {
55
+ display: display,
56
+ nodeContext: nodeContext,
57
+ creationMethod: creationMethod
58
+ });
59
+ }), _defineProperty(_ref5, EVENT.UPDATED, function (_ref3) {
60
+ var node = _ref3.node,
61
+ nodeContext = _ref3.nodeContext,
62
+ previousDisplay = _ref3.previousDisplay,
63
+ metadata = _objectWithoutProperties(_ref3, _excluded2);
64
+ var url = getUrl(node);
65
+ if (!url) {
66
+ return;
67
+ }
68
+ var display = appearanceForLink(node);
69
+ var displayCategory = displayCategoryFromDisplay(display);
70
+ var sourceEvent = getSourceEventFromMetadata(metadata);
71
+ var updateMethod = getMethod(metadata);
72
+ var updateType = getUpdateType(metadata);
73
+ linkUpdated({
74
+ url: url,
75
+ displayCategory: displayCategory
76
+ }, sourceEvent, {
77
+ display: display,
78
+ previousDisplay: previousDisplay,
79
+ nodeContext: nodeContext,
80
+ updateMethod: updateMethod,
81
+ updateType: updateType
82
+ });
83
+ }), _defineProperty(_ref5, EVENT.DELETED, function (_ref4) {
84
+ var node = _ref4.node,
85
+ nodeContext = _ref4.nodeContext,
86
+ metadata = _objectWithoutProperties(_ref4, _excluded3);
87
+ var url = getUrl(node);
88
+ if (!url) {
89
+ return;
90
+ }
91
+ var display = appearanceForLink(node);
92
+ var displayCategory = displayCategoryFromDisplay(display);
93
+ var sourceEvent = getSourceEventFromMetadata(metadata);
94
+ var deleteMethod = getMethod(metadata);
95
+ var deleteType = getDeleteType(metadata);
96
+ linkDeleted({
97
+ url: url,
98
+ displayCategory: displayCategory
99
+ }, sourceEvent, {
100
+ display: display,
101
+ nodeContext: nodeContext,
102
+ deleteMethod: deleteMethod,
103
+ deleteType: deleteType
104
+ });
105
+ }), _ref5;
106
+ }, [linkCreated, linkUpdated, linkDeleted]);
107
+
108
+ /**
109
+ * Subscribe to link events
110
+ */
111
+ useEffect(function () {
112
+ var unsubscribe = cardPluginEvents.subscribe(function (_ref6) {
113
+ var event = _ref6.event,
114
+ subject = _ref6.subject,
115
+ data = _ref6.data;
116
+ if (subject === EVENT_SUBJECT.LINK) {
117
+ linkEvents[event](data);
118
+ }
119
+ });
120
+ return function () {
121
+ return unsubscribe();
122
+ };
123
+ }, [linkEvents, cardPluginEvents]);
124
+ return null;
125
+ };
@@ -0,0 +1,55 @@
1
+ import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
2
+ import { ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
3
+ /**
4
+ * If the metadata is for a history event,
5
+ * returns undo/redo instead of instead of what fn(metadata) would have otherwise
6
+ * returned
7
+ */
8
+ var withHistoryMethod = function withHistoryMethod(fn) {
9
+ return function (metadata) {
10
+ var isUndo = metadata.isUndo,
11
+ isRedo = metadata.isRedo;
12
+ if (isUndo) {
13
+ return 'undo';
14
+ }
15
+ if (isRedo) {
16
+ return 'redo';
17
+ }
18
+ return fn(metadata);
19
+ };
20
+ };
21
+ export var getMethod = withHistoryMethod(function (_ref) {
22
+ var inputMethod = _ref.inputMethod;
23
+ switch (inputMethod) {
24
+ case INPUT_METHOD.CLIPBOARD:
25
+ return 'editor_paste';
26
+ case INPUT_METHOD.FLOATING_TB:
27
+ return 'editor_floatingToolbar';
28
+ case INPUT_METHOD.AUTO_DETECT:
29
+ case INPUT_METHOD.FORMATTING:
30
+ return 'editor_type';
31
+ default:
32
+ return 'unknown';
33
+ }
34
+ });
35
+ export var getUpdateType = withHistoryMethod(function (_ref2) {
36
+ var action = _ref2.action;
37
+ switch (action) {
38
+ case ACTION.CHANGED_TYPE:
39
+ return 'display_update';
40
+ case ACTION.UPDATED:
41
+ return 'link_update';
42
+ default:
43
+ return 'unknown';
44
+ }
45
+ });
46
+ export var getDeleteType = withHistoryMethod(function (_ref3) {
47
+ var action = _ref3.action;
48
+ if (action === ACTION.UNLINK) {
49
+ return 'unlink';
50
+ }
51
+ return 'delete';
52
+ });
53
+ export var getSourceEventFromMetadata = function getSourceEventFromMetadata(metadata) {
54
+ return metadata.sourceEvent instanceof UIAnalyticsEvent ? metadata.sourceEvent : null;
55
+ };
@@ -0,0 +1,47 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _inherits from "@babel/runtime/helpers/inherits";
4
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
5
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
6
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
7
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
8
+ function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
9
+ import React from 'react';
10
+ import PropTypes from 'prop-types';
11
+ import { EditorAnalyticsContext } from '../EditorAnalyticsContext';
12
+ import { DatasourceEventsBinding } from './DatasourceEvents';
13
+ import { LinkEventsBinding } from './LinkEvents';
14
+
15
+ // eslint-disable-next-line @repo/internal/react/no-class-components
16
+ export var EditorLinkingPlatformAnalytics = /*#__PURE__*/function (_React$PureComponent) {
17
+ _inherits(EditorLinkingPlatformAnalytics, _React$PureComponent);
18
+ var _super = _createSuper(EditorLinkingPlatformAnalytics);
19
+ function EditorLinkingPlatformAnalytics() {
20
+ _classCallCheck(this, EditorLinkingPlatformAnalytics);
21
+ return _super.apply(this, arguments);
22
+ }
23
+ _createClass(EditorLinkingPlatformAnalytics, [{
24
+ key: "render",
25
+ value: function render() {
26
+ var cardContext = this.context.contextAdapter.card;
27
+
28
+ /**
29
+ * The analytics hook needs to be able to communicate with the card context
30
+ * If we can't access it, don't mount the event bindings
31
+ * This effectively entirely disables all tracking behaviour
32
+ */
33
+ if (!cardContext) {
34
+ return null;
35
+ }
36
+ return /*#__PURE__*/React.createElement(cardContext.Provider, {
37
+ value: cardContext.value
38
+ }, /*#__PURE__*/React.createElement(EditorAnalyticsContext, {
39
+ editorView: this.props.editorView
40
+ }, /*#__PURE__*/React.createElement(LinkEventsBinding, this.props), /*#__PURE__*/React.createElement(DatasourceEventsBinding, this.props)));
41
+ }
42
+ }]);
43
+ return EditorLinkingPlatformAnalytics;
44
+ }(React.PureComponent);
45
+ _defineProperty(EditorLinkingPlatformAnalytics, "contextTypes", {
46
+ contextAdapter: PropTypes.object
47
+ });
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "0.3.3",
3
+ "version": "0.3.5",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,21 @@
1
+ export type Subscriber<T> = (event: T) => void;
2
+ export type EditorCardPluginEvents<T> = {
3
+ push: (...events: T[]) => void;
4
+ subscribe: (listener: Subscriber<T>) => () => void;
5
+ flush: () => void;
6
+ getSize: () => number;
7
+ };
8
+ /**
9
+ * Simple mechanism to defer event related callbacks
10
+ *
11
+ * Probably think twice whether your event should use this instead of
12
+ * editor's built-in `editor-plugin-analytics`
13
+ *
14
+ * Editor-Plugin-Analytics provides methods methods to dispatch events, and attach events into prosemiror transactions
15
+ * However we do not have access to the smart card context in prosemirror
16
+ *
17
+ * We are using this queue to relay events occurring in prosemirror (which does not have access to the react context)
18
+ * to be subscribed to elsewhere where the react context is available (contentComponent or otherwise) (smart card context)
19
+ * in order to be able to annotate events with additional attributes to events
20
+ */
21
+ export declare const createEventsQueue: <T extends unknown>() => EditorCardPluginEvents<T>;
@@ -0,0 +1,19 @@
1
+ import { EditorState, ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
2
+ import { CardPluginEvent, Entity } from './types';
3
+ /**
4
+ * Find the links, smartLinks, datasources that were changed in a transaction
5
+ */
6
+ export declare const findChanged: (tr: Transaction | ReadonlyTransaction, state: EditorState) => {
7
+ removed: Entity[];
8
+ inserted: Entity[];
9
+ updated: ({
10
+ removed: Entity;
11
+ inserted: Entity;
12
+ } | {
13
+ inserted: Entity;
14
+ previous: {
15
+ display?: string;
16
+ };
17
+ })[];
18
+ };
19
+ export declare function eventsFromTransaction(tr: ReadonlyTransaction, state: EditorState): CardPluginEvent[];
@@ -0,0 +1,2 @@
1
+ export { createEventsQueue } from './create-events-queue';
2
+ export { eventsFromTransaction } from './events-from-tr';
@@ -0,0 +1,66 @@
1
+ import { Node } from '@atlaskit/editor-prosemirror/model';
2
+ export type Entity = {
3
+ pos: number;
4
+ node: Node;
5
+ nodeContext: string;
6
+ };
7
+ type Metadata<T = {}> = {
8
+ node: Node;
9
+ isUndo?: boolean;
10
+ isRedo?: boolean;
11
+ action?: string;
12
+ inputMethod?: string;
13
+ sourceEvent?: unknown;
14
+ nodeContext?: string;
15
+ } & T;
16
+ type UpdateMetadata = {
17
+ previousDisplay?: string;
18
+ };
19
+ export declare enum EVENT {
20
+ CREATED = "created",
21
+ UPDATED = "updated",
22
+ DELETED = "deleted"
23
+ }
24
+ export declare enum EVENT_SUBJECT {
25
+ LINK = "link",
26
+ DATASOURCE = "datasource"
27
+ }
28
+ /**
29
+ * These are not GASv3 events
30
+ * But they share a similar in shape so that GASv3
31
+ * events can be derived from them / think of them in the same way
32
+ */
33
+ export type LinkCreatedEvent = {
34
+ event: EVENT.CREATED;
35
+ subject: EVENT_SUBJECT.LINK;
36
+ data: Metadata;
37
+ };
38
+ export type LinkUpdatedEvent = {
39
+ event: EVENT.UPDATED;
40
+ subject: EVENT_SUBJECT.LINK;
41
+ data: Metadata<UpdateMetadata>;
42
+ };
43
+ export type LinkDeletedEvent = {
44
+ event: EVENT.DELETED;
45
+ subject: EVENT_SUBJECT.LINK;
46
+ data: Metadata;
47
+ };
48
+ export type DatasourceCreatedEvent = {
49
+ event: EVENT.CREATED;
50
+ subject: EVENT_SUBJECT.DATASOURCE;
51
+ data: Metadata;
52
+ };
53
+ export type DatasourceUpdatedEvent = {
54
+ event: EVENT.UPDATED;
55
+ subject: EVENT_SUBJECT.DATASOURCE;
56
+ data: Metadata<UpdateMetadata>;
57
+ };
58
+ export type DatasourceDeletedEvent = {
59
+ event: EVENT.DELETED;
60
+ subject: EVENT_SUBJECT.DATASOURCE;
61
+ data: Metadata;
62
+ };
63
+ export type LinkEvent = LinkCreatedEvent | LinkUpdatedEvent | LinkDeletedEvent;
64
+ export type DatasourceEvent = DatasourceCreatedEvent | DatasourceUpdatedEvent | DatasourceDeletedEvent;
65
+ export type CardPluginEvent = LinkEvent | DatasourceEvent;
66
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Node } from '@atlaskit/editor-prosemirror/model';
2
+ import { ReadonlyTransaction, Transaction } from '@atlaskit/editor-prosemirror/state';
3
+ import { Entity, EVENT_SUBJECT } from './types';
4
+ export declare function isDatasourceNode(node: Node): boolean;
5
+ /**
6
+ * Determine if a node is considered to be a link
7
+ */
8
+ export declare const isLinkNode: (node: Node) => boolean;
9
+ export declare function getNodeSubject(node: Node): EVENT_SUBJECT | null;
10
+ /**
11
+ * Analytics appearance for link object
12
+ */
13
+ export declare function appearanceForLink(node: Node): "url" | import("@atlaskit/editor-common/provider-factory").CardAppearance;
14
+ export declare function getUrl(node: Node): string | undefined;
15
+ export declare const getNodeContext: (doc: Node, pos: number) => string;
16
+ export declare const findAtPositions: (tr: Transaction | ReadonlyTransaction, positions: number[]) => Entity[];
17
+ export declare const findInNodeRange: (doc: Node, from: number, to: number, predicate: (node: Node) => boolean) => Entity[];
18
+ /**
19
+ * Returns whether or not two sets of links appear to likely be the same set of links
20
+ * That they are in the same order and that both their hrefs and appearances match
21
+ */
22
+ export declare const areSameNodes: (setA: Entity[], setB: Entity[]) => boolean;
@@ -2,14 +2,13 @@ import { CardProvider } from '@atlaskit/editor-common/provider-factory';
2
2
  import type { DatasourceModalType } from '@atlaskit/editor-common/types';
3
3
  import { Transaction } from '@atlaskit/editor-prosemirror/state';
4
4
  import { SmartLinkEvents } from '@atlaskit/smart-card';
5
- import { CardInfo, CardPluginAction, Request, SmartLinkEventsNext } from '../types';
5
+ import { CardInfo, CardPluginAction, Request } from '../types';
6
6
  import { DatasourceTableLayout } from '../ui/LayoutButton/types';
7
7
  export declare const cardAction: (tr: Transaction, action: CardPluginAction) => Transaction;
8
8
  export declare const resolveCard: (url: string) => (tr: Transaction) => Transaction;
9
9
  export declare const queueCards: (requests: Request[]) => (tr: Transaction) => Transaction;
10
10
  export declare const registerCard: (info: CardInfo) => (tr: Transaction) => Transaction;
11
11
  export declare const registerSmartCardEvents: (smartLinkEvents: SmartLinkEvents) => (tr: Transaction) => Transaction;
12
- export declare const registerSmartCardEventsNext: (smartLinkEvents: SmartLinkEventsNext) => (tr: Transaction) => Transaction;
13
12
  export declare const setProvider: (cardProvider: CardProvider | null) => (tr: Transaction) => Transaction;
14
13
  export declare const setDatasourceTableRef: (datasourceTableRef?: HTMLElement) => (tr: Transaction) => Transaction;
15
14
  export declare const setCardLayout: (layout: DatasourceTableLayout) => (tr: Transaction) => Transaction;
@@ -21,7 +21,6 @@ export declare const getPluginStateWithUpdatedPos: (pluginState: CardPluginState
21
21
  provider: import("@atlaskit/editor-common/provider-factory").CardProvider | null;
22
22
  showLinkingToolbar: boolean;
23
23
  smartLinkEvents?: import("@atlaskit/smart-card").SmartLinkEvents | undefined;
24
- smartLinkEventsNext?: import("../../types").SmartLinkEventsNext | undefined;
25
24
  editorAppearance?: import("@atlaskit/editor-common/types").EditorAppearance | undefined;
26
25
  showDatasourceModal: boolean;
27
26
  datasourceModalType?: import("@atlaskit/editor-common/types").DatasourceModalType | undefined;