@atlaskit/editor-plugin-card 0.3.4 → 0.3.6

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 (104) 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/nodeviews/datasource.js +1 -8
  8. package/dist/cjs/plugin.js +7 -4
  9. package/dist/cjs/pm-plugins/actions.js +1 -10
  10. package/dist/cjs/pm-plugins/doc.js +3 -0
  11. package/dist/cjs/pm-plugins/main.js +15 -13
  12. package/dist/cjs/pm-plugins/reducers.js +0 -7
  13. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +52 -0
  14. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/LinkEvents.js +132 -0
  15. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/common.js +65 -0
  16. package/dist/cjs/ui/EditorLinkingPlatformAnalytics/index.js +54 -0
  17. package/dist/cjs/version.json +1 -1
  18. package/dist/es2019/analytics/create-events-queue.js +43 -0
  19. package/dist/es2019/{pm-plugins/analytics → analytics}/events-from-tr.js +82 -72
  20. package/dist/es2019/analytics/index.js +2 -0
  21. package/dist/es2019/analytics/types.js +17 -0
  22. package/dist/es2019/analytics/utils.js +118 -0
  23. package/dist/es2019/nodeviews/datasource.js +2 -9
  24. package/dist/es2019/plugin.js +7 -6
  25. package/dist/es2019/pm-plugins/actions.js +0 -4
  26. package/dist/es2019/pm-plugins/doc.js +3 -0
  27. package/dist/es2019/pm-plugins/main.js +15 -15
  28. package/dist/es2019/pm-plugins/reducers.js +0 -8
  29. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +46 -0
  30. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/LinkEvents.js +127 -0
  31. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/common.js +60 -0
  32. package/dist/es2019/ui/EditorLinkingPlatformAnalytics/index.js +30 -0
  33. package/dist/es2019/version.json +1 -1
  34. package/dist/esm/analytics/create-events-queue.js +48 -0
  35. package/dist/esm/{pm-plugins/analytics → analytics}/events-from-tr.js +90 -80
  36. package/dist/esm/analytics/index.js +2 -0
  37. package/dist/esm/analytics/types.js +17 -0
  38. package/dist/esm/analytics/utils.js +118 -0
  39. package/dist/esm/nodeviews/datasource.js +2 -9
  40. package/dist/esm/plugin.js +7 -4
  41. package/dist/esm/pm-plugins/actions.js +0 -8
  42. package/dist/esm/pm-plugins/doc.js +3 -0
  43. package/dist/esm/pm-plugins/main.js +15 -13
  44. package/dist/esm/pm-plugins/reducers.js +0 -7
  45. package/dist/esm/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +44 -0
  46. package/dist/esm/ui/EditorLinkingPlatformAnalytics/LinkEvents.js +125 -0
  47. package/dist/esm/ui/EditorLinkingPlatformAnalytics/common.js +55 -0
  48. package/dist/esm/ui/EditorLinkingPlatformAnalytics/index.js +47 -0
  49. package/dist/esm/version.json +1 -1
  50. package/dist/types/analytics/create-events-queue.d.ts +21 -0
  51. package/dist/types/analytics/events-from-tr.d.ts +19 -0
  52. package/dist/types/analytics/index.d.ts +2 -0
  53. package/dist/types/analytics/types.d.ts +66 -0
  54. package/dist/types/analytics/utils.d.ts +22 -0
  55. package/dist/types/nodeviews/datasource.d.ts +0 -2
  56. package/dist/types/pm-plugins/actions.d.ts +1 -2
  57. package/dist/types/pm-plugins/util/state.d.ts +0 -1
  58. package/dist/types/types.d.ts +4 -34
  59. package/dist/types/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +6 -0
  60. package/dist/types/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +6 -0
  61. package/dist/types/ui/EditorLinkingPlatformAnalytics/common.d.ts +20 -0
  62. package/dist/types/ui/EditorLinkingPlatformAnalytics/index.d.ts +9 -0
  63. package/dist/types-ts4.5/analytics/create-events-queue.d.ts +21 -0
  64. package/dist/types-ts4.5/analytics/events-from-tr.d.ts +19 -0
  65. package/dist/types-ts4.5/analytics/index.d.ts +2 -0
  66. package/dist/types-ts4.5/analytics/types.d.ts +66 -0
  67. package/dist/types-ts4.5/analytics/utils.d.ts +22 -0
  68. package/dist/types-ts4.5/nodeviews/datasource.d.ts +0 -2
  69. package/dist/types-ts4.5/pm-plugins/actions.d.ts +1 -2
  70. package/dist/types-ts4.5/pm-plugins/util/state.d.ts +0 -1
  71. package/dist/types-ts4.5/types.d.ts +4 -34
  72. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +6 -0
  73. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +6 -0
  74. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/common.d.ts +20 -0
  75. package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/index.d.ts +9 -0
  76. package/package.json +3 -3
  77. package/report.api.md +84 -8
  78. package/tmp/api-report-tmp.d.ts +81 -8
  79. package/dist/cjs/pm-plugins/analytics/create-analytics-queue.js +0 -48
  80. package/dist/cjs/pm-plugins/analytics/types.js +0 -5
  81. package/dist/cjs/pm-plugins/analytics/utils.js +0 -178
  82. package/dist/cjs/ui/EditorSmartCardEventsNext.js +0 -204
  83. package/dist/es2019/pm-plugins/analytics/create-analytics-queue.js +0 -38
  84. package/dist/es2019/pm-plugins/analytics/index.js +0 -2
  85. package/dist/es2019/pm-plugins/analytics/types.js +0 -1
  86. package/dist/es2019/pm-plugins/analytics/utils.js +0 -160
  87. package/dist/es2019/ui/EditorSmartCardEventsNext.js +0 -188
  88. package/dist/esm/pm-plugins/analytics/create-analytics-queue.js +0 -41
  89. package/dist/esm/pm-plugins/analytics/index.js +0 -2
  90. package/dist/esm/pm-plugins/analytics/types.js +0 -1
  91. package/dist/esm/pm-plugins/analytics/utils.js +0 -160
  92. package/dist/esm/ui/EditorSmartCardEventsNext.js +0 -192
  93. package/dist/types/pm-plugins/analytics/create-analytics-queue.d.ts +0 -10
  94. package/dist/types/pm-plugins/analytics/events-from-tr.d.ts +0 -17
  95. package/dist/types/pm-plugins/analytics/index.d.ts +0 -2
  96. package/dist/types/pm-plugins/analytics/types.d.ts +0 -12
  97. package/dist/types/pm-plugins/analytics/utils.d.ts +0 -32
  98. package/dist/types/ui/EditorSmartCardEventsNext.d.ts +0 -18
  99. package/dist/types-ts4.5/pm-plugins/analytics/create-analytics-queue.d.ts +0 -10
  100. package/dist/types-ts4.5/pm-plugins/analytics/events-from-tr.d.ts +0 -17
  101. package/dist/types-ts4.5/pm-plugins/analytics/index.d.ts +0 -2
  102. package/dist/types-ts4.5/pm-plugins/analytics/types.d.ts +0 -12
  103. package/dist/types-ts4.5/pm-plugins/analytics/utils.d.ts +0 -32
  104. package/dist/types-ts4.5/ui/EditorSmartCardEventsNext.d.ts +0 -18
@@ -3,28 +3,24 @@ import { ACTION } from '@atlaskit/editor-common/analytics';
3
3
  import { getLinkMetadataFromTransaction } from '@atlaskit/editor-common/card';
4
4
  import { isLinkMark, pmHistoryPluginKey } from '@atlaskit/editor-common/utils';
5
5
  import { AddMarkStep, RemoveMarkStep } from '@atlaskit/editor-prosemirror/transform';
6
- import { pluginKey } from '../plugin-key';
7
- import { getPluginState } from '../util/state';
8
- import { appearanceForLink, areSameLinks, findLinksAtPositions, getLinkNodeContext, getLinkUrl, isLink, linkObjectFromNode } from './utils';
9
- const findLinksInNodeRange = (doc, schema, from, to) => {
10
- const links = [];
11
- doc.nodesBetween(from, to, (node, pos) => {
12
- if (isLink(schema, node)) {
13
- const entireLinkInRange = pos >= from && pos + node.nodeSize <= to;
14
- if (entireLinkInRange) {
15
- const link = linkObjectFromNode(doc, schema, node, pos);
16
- if (link) {
17
- links.push(link);
18
- }
19
- }
20
- }
21
- });
22
- return links;
23
- };
24
- export const findChangedLinks = (tr, state) => {
6
+ import { pluginKey } from '../pm-plugins/plugin-key';
7
+ import { getPluginState } from '../pm-plugins/util/state';
8
+ import { EVENT } from './types';
9
+ import { appearanceForLink, areSameNodes, findAtPositions, findInNodeRange, getNodeContext, getNodeSubject } from './utils';
10
+
11
+ /**
12
+ * Find the links, smartLinks, datasources that were changed in a transaction
13
+ */
14
+ export const findChanged = (tr, state) => {
25
15
  const schema = tr.doc.type.schema;
26
16
  const removed = [];
27
17
  const inserted = [];
18
+ /**
19
+ * Ideally we have the "before" and "after" states of the "entity"
20
+ * being updated, but if the update is via a "queue for upgrade"
21
+ * then we no longer have access to the "before" state, because the "before"
22
+ * state was replaced with a blue link to be upgraded
23
+ */
28
24
  const updated = [];
29
25
  const queuedForUpgrade = isTransactionQueuedForUpgrade(tr);
30
26
  const isResolveReplace = isTransactionResolveReplace(tr);
@@ -51,26 +47,30 @@ export const findChangedLinks = (tr, state) => {
51
47
  if (step instanceof AddMarkStep) {
52
48
  const addMarkStep = step;
53
49
  if (isLinkMark(addMarkStep.mark, schema)) {
54
- /**
55
- * For url text pasted on plain text
56
- */
57
- insertedInStep.push({
58
- type: 'mark',
59
- pos: addMarkStep.from,
60
- mark: addMarkStep.mark,
61
- nodeContext: getLinkNodeContext(after, addMarkStep.from)
62
- });
50
+ const node = after.nodeAt(addMarkStep.from);
51
+ if (node) {
52
+ /**
53
+ * For url text pasted on plain text
54
+ */
55
+ insertedInStep.push({
56
+ pos: addMarkStep.from,
57
+ node,
58
+ nodeContext: getNodeContext(after, addMarkStep.from)
59
+ });
60
+ }
63
61
  }
64
62
  }
65
63
  if (step instanceof RemoveMarkStep) {
66
64
  const removeMarkStep = step;
67
65
  if (isLinkMark(removeMarkStep.mark, schema)) {
68
- removedInStep.push({
69
- type: 'mark',
70
- pos: removeMarkStep.from,
71
- mark: removeMarkStep.mark,
72
- nodeContext: getLinkNodeContext(before, removeMarkStep.from)
73
- });
66
+ const node = before.nodeAt(removeMarkStep.from);
67
+ if (node) {
68
+ removedInStep.push({
69
+ pos: removeMarkStep.from,
70
+ node,
71
+ nodeContext: getNodeContext(before, removeMarkStep.from)
72
+ });
73
+ }
74
74
  }
75
75
  }
76
76
  stepMap.forEach((oldStart, oldEnd, newStart, newEnd) => {
@@ -81,13 +81,13 @@ export const findChangedLinks = (tr, state) => {
81
81
  const insertedInRange = [];
82
82
 
83
83
  // Removed
84
- removedInRange.push(...findLinksInNodeRange(before, schema, oldStart, oldEnd));
84
+ removedInRange.push(...findInNodeRange(before, oldStart, oldEnd, node => !!getNodeSubject(node)));
85
85
  // Inserted
86
- insertedInRange.push(...findLinksInNodeRange(after, schema, newStart, newEnd));
86
+ insertedInRange.push(...findInNodeRange(after, newStart, newEnd, node => !!getNodeSubject(node)));
87
87
  removedInStep.push(...removedInRange);
88
88
  insertedInStep.push(...insertedInRange);
89
89
  });
90
- const omitQueuedLinks = links => {
90
+ const omitRequestsForUpgrade = links => {
91
91
  if (!queuedForUpgrade) {
92
92
  return links;
93
93
  }
@@ -107,7 +107,7 @@ export const findChangedLinks = (tr, state) => {
107
107
  if (!isResolveReplace) {
108
108
  removed.push(...removedInStep);
109
109
  }
110
- inserted.push(...omitQueuedLinks(insertedInStep));
110
+ inserted.push(...omitRequestsForUpgrade(insertedInStep));
111
111
  }
112
112
 
113
113
  /**
@@ -117,7 +117,7 @@ export const findChangedLinks = (tr, state) => {
117
117
  */
118
118
  if (inserted.length === 0 && isResolveReplace) {
119
119
  const positions = getResolvePositions(tr, state);
120
- inserted.push(...findLinksAtPositions(tr, positions));
120
+ inserted.push(...findAtPositions(tr, positions));
121
121
  }
122
122
  if (!isUpdate) {
123
123
  const {
@@ -127,7 +127,7 @@ export const findChangedLinks = (tr, state) => {
127
127
  * If there is no identifiable input method, and the links inserted and removed appear to be the same,
128
128
  * then this transaction likely is not intended to be consided to be the insertion and removal of links
129
129
  */
130
- if (!inputMethod && areSameLinks(removed, inserted)) {
130
+ if (!inputMethod && areSameNodes(removed, inserted)) {
131
131
  return {
132
132
  removed: [],
133
133
  inserted: [],
@@ -275,18 +275,11 @@ export function eventsFromTransaction(tr, state) {
275
275
  inputMethod,
276
276
  sourceEvent
277
277
  } = getLinkMetadataFromTransaction(tr);
278
- const contextualData = {
279
- action,
280
- inputMethod,
281
- sourceEvent,
282
- isUndo,
283
- isRedo
284
- };
285
278
  const {
286
279
  removed,
287
280
  inserted,
288
281
  updated
289
- } = findChangedLinks(tr, state);
282
+ } = findChanged(tr, state);
290
283
  const MAX_LINK_EVENTS = 50;
291
284
  if ([removed, inserted, updated].some(arr => arr.length > MAX_LINK_EVENTS)) {
292
285
  return [];
@@ -295,44 +288,61 @@ export function eventsFromTransaction(tr, state) {
295
288
  var _update$previous$disp;
296
289
  const update = updated[i];
297
290
  const {
298
- inserted: link
291
+ inserted
299
292
  } = update;
300
- const url = getLinkUrl(link);
301
- const display = appearanceForLink(link);
302
- const previousDisplay = 'removed' in update ? appearanceForLink(update.removed) : (_update$previous$disp = update.previous.display) !== null && _update$previous$disp !== void 0 ? _update$previous$disp : 'unknown';
303
- if (url) {
293
+ const {
294
+ node,
295
+ nodeContext
296
+ } = inserted;
297
+ const subject = getNodeSubject(node);
298
+
299
+ /**
300
+ * Not great, wish we had the previous node but we never stored it
301
+ */
302
+ const previousDisplay = 'removed' in update ? appearanceForLink(update.removed.node) : (_update$previous$disp = update.previous.display) !== null && _update$previous$disp !== void 0 ? _update$previous$disp : 'unknown';
303
+ if (subject) {
304
304
  events.push({
305
- type: 'updated',
305
+ event: EVENT.UPDATED,
306
+ subject,
306
307
  data: {
307
- ...contextualData,
308
- url,
309
- display,
310
- previousDisplay,
311
- nodeContext: link.nodeContext
308
+ node,
309
+ nodeContext,
310
+ action,
311
+ inputMethod,
312
+ sourceEvent,
313
+ isUndo,
314
+ isRedo,
315
+ previousDisplay
312
316
  }
313
317
  });
314
318
  }
315
319
  }
316
- const pushEvents = (links, type) => {
317
- for (let i = 0; i < links.length; i++) {
318
- const link = links[i];
319
- const url = getLinkUrl(link);
320
- const display = appearanceForLink(link);
321
- if (url) {
320
+ const pushEvents = (entities, event) => {
321
+ for (let i = 0; i < entities.length; i++) {
322
+ const {
323
+ node,
324
+ nodeContext
325
+ } = entities[i];
326
+ const subject = getNodeSubject(node);
327
+ if (subject) {
322
328
  events.push({
323
- type,
329
+ event,
330
+ subject,
324
331
  data: {
325
- ...contextualData,
326
- url,
327
- display,
328
- nodeContext: link.nodeContext
332
+ node,
333
+ nodeContext,
334
+ action,
335
+ inputMethod,
336
+ sourceEvent,
337
+ isUndo,
338
+ isRedo
329
339
  }
330
340
  });
331
341
  }
332
342
  }
333
343
  };
334
- pushEvents(removed, 'deleted');
335
- pushEvents(inserted, 'created');
344
+ pushEvents(removed, EVENT.DELETED);
345
+ pushEvents(inserted, EVENT.CREATED);
336
346
  return events;
337
347
  } catch (err) {
338
348
  return events;
@@ -0,0 +1,2 @@
1
+ export { createEventsQueue } from './create-events-queue';
2
+ export { eventsFromTransaction } from './events-from-tr';
@@ -0,0 +1,17 @@
1
+ export let EVENT = /*#__PURE__*/function (EVENT) {
2
+ EVENT["CREATED"] = "created";
3
+ EVENT["UPDATED"] = "updated";
4
+ EVENT["DELETED"] = "deleted";
5
+ return EVENT;
6
+ }({});
7
+ export let EVENT_SUBJECT = /*#__PURE__*/function (EVENT_SUBJECT) {
8
+ EVENT_SUBJECT["LINK"] = "link";
9
+ EVENT_SUBJECT["DATASOURCE"] = "datasource";
10
+ return EVENT_SUBJECT;
11
+ }({});
12
+
13
+ /**
14
+ * These are not GASv3 events
15
+ * But they share a similar in shape so that GASv3
16
+ * events can be derived from them / think of them in the same way
17
+ */
@@ -0,0 +1,118 @@
1
+ import { appearanceForNodeType } from '../utils';
2
+ import { EVENT_SUBJECT } from './types';
3
+ export function isDatasourceNode(node) {
4
+ return 'datasource' in node.attrs && !!node.attrs.datasource;
5
+ }
6
+
7
+ /**
8
+ * Determine if a node is considered to be a link
9
+ */
10
+ export const isLinkNode = node => {
11
+ if (isDatasourceNode(node)) {
12
+ return false;
13
+ }
14
+ if (!!appearanceForNodeType(node.type)) {
15
+ return true;
16
+ }
17
+ return hasLinkMark(node);
18
+ };
19
+ export function getNodeSubject(node) {
20
+ if (isDatasourceNode(node)) {
21
+ return EVENT_SUBJECT.DATASOURCE;
22
+ }
23
+ if (isLinkNode(node)) {
24
+ return EVENT_SUBJECT.LINK;
25
+ }
26
+ return null;
27
+ }
28
+
29
+ /**
30
+ * Analytics appearance for link object
31
+ */
32
+ export function appearanceForLink(node) {
33
+ const appearance = appearanceForNodeType(node.type);
34
+ if (appearance) {
35
+ return appearance;
36
+ }
37
+ return 'url';
38
+ }
39
+ const getLinkMark = node => {
40
+ if (node.marks) {
41
+ for (let i = 0; i < node.marks.length; i++) {
42
+ const mark = node.marks[i];
43
+ if (mark.type.name === 'link') {
44
+ return mark;
45
+ }
46
+ }
47
+ }
48
+ };
49
+ const hasLinkMark = node => {
50
+ return !!getLinkMark(node);
51
+ };
52
+ export function getUrl(node) {
53
+ var _node$attrs$url, _node$attrs, _getLinkMark, _getLinkMark$attrs;
54
+ return (_node$attrs$url = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.url) !== null && _node$attrs$url !== void 0 ? _node$attrs$url : (_getLinkMark = getLinkMark(node)) === null || _getLinkMark === void 0 ? void 0 : (_getLinkMark$attrs = _getLinkMark.attrs) === null || _getLinkMark$attrs === void 0 ? void 0 : _getLinkMark$attrs.href;
55
+ }
56
+ export const getNodeContext = (doc, pos) => {
57
+ const $pos = doc.resolve(pos);
58
+ const maxDepth = 3;
59
+ for (let i = 0; i <= maxDepth; i++) {
60
+ const node = $pos.node($pos.depth - i);
61
+ if (node && node.type.name !== 'paragraph') {
62
+ return node.type.name;
63
+ }
64
+ }
65
+ return 'unknown';
66
+ };
67
+ export const findAtPositions = (tr, positions) => {
68
+ const entities = [];
69
+ for (let i = 0; i < positions.length; i++) {
70
+ const pos = positions[i];
71
+ const node = tr.doc.nodeAt(pos);
72
+ if (!node) {
73
+ continue;
74
+ }
75
+ const nodeContext = getNodeContext(tr.doc, pos);
76
+ entities.push({
77
+ pos,
78
+ node,
79
+ nodeContext
80
+ });
81
+ }
82
+ return entities;
83
+ };
84
+ export const findInNodeRange = (doc, from, to, predicate) => {
85
+ const entities = [];
86
+ doc.nodesBetween(from, to, (node, pos) => {
87
+ if (predicate(node)) {
88
+ const entirelyInRange = pos >= from && pos + node.nodeSize <= to;
89
+ if (entirelyInRange) {
90
+ const nodeContext = getNodeContext(doc, pos);
91
+ entities.push({
92
+ pos,
93
+ node,
94
+ nodeContext
95
+ });
96
+ }
97
+ }
98
+ });
99
+ return entities;
100
+ };
101
+
102
+ /**
103
+ * Returns whether or not two sets of links appear to likely be the same set of links
104
+ * That they are in the same order and that both their hrefs and appearances match
105
+ */
106
+ export const areSameNodes = (setA, setB) => {
107
+ if (setA.length !== setB.length) {
108
+ return false;
109
+ }
110
+ for (let i = 0; i < setA.length; i++) {
111
+ const a = setA[i];
112
+ const b = setB[i];
113
+ if (getUrl(a.node) !== getUrl(b.node) || appearanceForLink(a.node) !== appearanceForLink(b.node)) {
114
+ return false;
115
+ }
116
+ }
117
+ return true;
118
+ };
@@ -5,7 +5,7 @@ import { jsx } from '@emotion/react';
5
5
  import PropTypes from 'prop-types';
6
6
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
7
7
  import { DATASOURCE_INNER_CONTAINER_CLASSNAME, SmartCardSharedCssClassName } from '@atlaskit/editor-common/styles';
8
- import { calcBreakoutWidthPx } from '@atlaskit/editor-common/utils';
8
+ import { calcBreakoutWidth } from '@atlaskit/editor-common/utils';
9
9
  import { DatasourceTableView } from '@atlaskit/link-datasource';
10
10
  // eslint-disable-next-line @repo/internal/react/no-class-components
11
11
  export class DatasourceComponent extends React.PureComponent {
@@ -90,12 +90,6 @@ export class Datasource extends ReactNodeView {
90
90
  constructor(props) {
91
91
  var _props$pluginInjectio, _props$pluginInjectio2, _props$pluginInjectio3, _sharedState$currentS;
92
92
  super(props.node, props.view, props.getPos, props.portalProviderAPI, props.eventDispatcher, props, undefined, true, undefined, props.hasIntlContext);
93
- _defineProperty(this, "calcTableWidth", (layout, containerWidth) => {
94
- if (layout === 'center') {
95
- return 'inherit';
96
- }
97
- return calcBreakoutWidthPx(layout, containerWidth);
98
- });
99
93
  const sharedState = props === null || props === void 0 ? void 0 : (_props$pluginInjectio = props.pluginInjectionApi) === null || _props$pluginInjectio === void 0 ? void 0 : (_props$pluginInjectio2 = _props$pluginInjectio.dependencies) === null || _props$pluginInjectio2 === void 0 ? void 0 : (_props$pluginInjectio3 = _props$pluginInjectio2.width) === null || _props$pluginInjectio3 === void 0 ? void 0 : _props$pluginInjectio3.sharedState;
100
94
  this.tableWidth = sharedState === null || sharedState === void 0 ? void 0 : (_sharedState$currentS = sharedState.currentState()) === null || _sharedState$currentS === void 0 ? void 0 : _sharedState$currentS.width;
101
95
  sharedState === null || sharedState === void 0 ? void 0 : sharedState.onChange(({
@@ -117,11 +111,10 @@ export class Datasource extends ReactNodeView {
117
111
  const {
118
112
  attrs
119
113
  } = this.node;
120
- const calculatedWidth = this.calcTableWidth(attrs.layout, this.tableWidth);
121
114
  return jsx("div", {
122
115
  className: DATASOURCE_INNER_CONTAINER_CLASSNAME,
123
116
  style: {
124
- minWidth: calculatedWidth
117
+ minWidth: calcBreakoutWidth(attrs.layout, this.tableWidth)
125
118
  }
126
119
  }, jsx(DatasourceComponent, {
127
120
  node: this.node,
@@ -3,6 +3,7 @@ import { blockCard, embedCard, inlineCard } from '@atlaskit/adf-schema';
3
3
  import { IconDatasourceAssetsObjects, IconDatasourceJiraIssue } from '@atlaskit/editor-common/quick-insert';
4
4
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
5
5
  import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, JIRA_LIST_OF_LINKS_DATASOURCE_ID } from '@atlaskit/link-datasource';
6
+ import { createEventsQueue } from './analytics/create-events-queue';
6
7
  import { messages } from './messages';
7
8
  import { hideLinkToolbar, showDatasourceModal } from './pm-plugins/actions';
8
9
  import { changeSelectedCardToLink, queueCardsFromChangedTr, setSelectedCardAppearance } from './pm-plugins/doc';
@@ -12,12 +13,13 @@ import { mountHyperlinkPlugin } from './pm-plugins/mountHyperlink';
12
13
  import { pluginKey } from './pm-plugins/plugin-key';
13
14
  import { floatingToolbar } from './toolbar';
14
15
  import DatasourceModalWithState from './ui/DatasourceModal/ModalWithState';
16
+ import { EditorLinkingPlatformAnalytics } from './ui/EditorLinkingPlatformAnalytics';
15
17
  import { EditorSmartCardEvents } from './ui/EditorSmartCardEvents';
16
- import { EditorSmartCardEventsNext } from './ui/EditorSmartCardEventsNext';
17
18
  import LayoutButton from './ui/LayoutButton';
18
19
  export const cardPlugin = (options, api) => {
19
20
  var _api$dependencies, _api$dependencies$fea;
20
21
  const 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()) || {};
22
+ const cardPluginEvents = featureFlags !== null && featureFlags !== void 0 && featureFlags.lpAnalyticsEventsNext ? createEventsQueue() : undefined;
21
23
  return {
22
24
  name: 'card',
23
25
  getSharedState(editorState) {
@@ -59,7 +61,8 @@ export const cardPlugin = (options, api) => {
59
61
  useAlternativePreloader,
60
62
  allowWrapping,
61
63
  allowAlignment,
62
- allowDatasource
64
+ allowDatasource,
65
+ cardPluginEvents
63
66
  }, api)
64
67
  }, {
65
68
  name: 'cardHyperlink',
@@ -81,12 +84,10 @@ export const cardPlugin = (options, api) => {
81
84
  popupsScrollableElement,
82
85
  popupsBoundariesElement
83
86
  }) {
84
- const {
85
- lpAnalyticsEventsNext
86
- } = featureFlags;
87
87
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(EditorSmartCardEvents, {
88
88
  editorView: editorView
89
- }), lpAnalyticsEventsNext && /*#__PURE__*/React.createElement(EditorSmartCardEventsNext, {
89
+ }), cardPluginEvents && /*#__PURE__*/React.createElement(EditorLinkingPlatformAnalytics, {
90
+ cardPluginEvents: cardPluginEvents,
90
91
  editorView: editorView
91
92
  }), /*#__PURE__*/React.createElement(LayoutButton, {
92
93
  api: api,
@@ -18,10 +18,6 @@ export const registerSmartCardEvents = smartLinkEvents => tr => cardAction(tr, {
18
18
  type: 'REGISTER_EVENTS',
19
19
  smartLinkEvents
20
20
  });
21
- export const registerSmartCardEventsNext = smartLinkEvents => tr => cardAction(tr, {
22
- type: 'REGISTER_EVENTS_NEXT',
23
- smartLinkEvents
24
- });
25
21
  export const setProvider = cardProvider => tr => cardAction(tr, {
26
22
  type: 'SET_PROVIDER',
27
23
  provider: cardProvider
@@ -419,6 +419,9 @@ export const updateExistingDatasource = (state, node, newAdf, view) => {
419
419
  ...node.attrs,
420
420
  ...newAdf.attrs
421
421
  });
422
+ addLinkMetadata(state.selection, tr, {
423
+ action: ACTION.UPDATED
424
+ });
422
425
  }
423
426
  } else if (newAdf.type === 'inlineCard') {
424
427
  // datasource to inline
@@ -5,29 +5,26 @@ import { DATASOURCE_INNER_CONTAINER_CLASSNAME } from '@atlaskit/editor-common/st
5
5
  import { canRenderDatasource } from '@atlaskit/editor-common/utils';
6
6
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
7
7
  import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
8
+ import { eventsFromTransaction } from '../analytics/events-from-tr';
8
9
  import { BlockCard } from '../nodeviews/blockCard';
9
10
  import { Datasource } from '../nodeviews/datasource';
10
11
  import { EmbedCard } from '../nodeviews/embedCard';
11
12
  import { InlineCardNodeView } from '../nodeviews/inlineCard';
12
13
  import { setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
13
- import { createAnalyticsQueue, eventsFromTransaction } from './analytics';
14
14
  import { pluginKey } from './plugin-key';
15
15
  import reducer from './reducers';
16
16
  import { handleProvider, resolveWithProvider } from './util/resolve';
17
17
  import { getNewRequests, getPluginState, getPluginStateWithUpdatedPos } from './util/state';
18
18
  export { pluginKey } from './plugin-key';
19
19
  export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryParams => {
20
- const {
21
- lpAnalyticsEventsNext
22
- } = pmPluginFactoryParams.featureFlags;
23
- const analyticsQueue = createAnalyticsQueue(!!lpAnalyticsEventsNext);
24
20
  const {
25
21
  editorAppearance,
26
22
  platform,
27
23
  allowResizing,
28
24
  useAlternativePreloader,
29
25
  fullWidthMode,
30
- showServerActions
26
+ showServerActions,
27
+ cardPluginEvents
31
28
  } = options;
32
29
  const inlineCardViewProducer = getInlineNodeViewProducer({
33
30
  pmPluginFactoryParams,
@@ -46,7 +43,6 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
46
43
  cards: [],
47
44
  showLinkingToolbar: false,
48
45
  smartLinkEvents: undefined,
49
- smartLinkEventsNext: undefined,
50
46
  editorAppearance,
51
47
  showDatasourceModal: false,
52
48
  datasourceModalType: undefined,
@@ -61,14 +57,12 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
61
57
 
62
58
  // apply any actions
63
59
  const meta = tr.getMeta(pluginKey);
64
- const events = eventsFromTransaction(tr, prevEditorState);
65
- analyticsQueue.push(...events);
60
+ if (cardPluginEvents) {
61
+ const events = eventsFromTransaction(tr, prevEditorState);
62
+ cardPluginEvents.push(...events);
63
+ }
66
64
  if (meta) {
67
- const nextState = reducer(pluginStateWithUpdatedPos, meta);
68
- if (!pluginState.smartLinkEventsNext && nextState.smartLinkEventsNext) {
69
- analyticsQueue.setCallbacks(nextState.smartLinkEventsNext);
70
- }
71
- return nextState;
65
+ return reducer(pluginStateWithUpdatedPos, meta);
72
66
  }
73
67
  return pluginStateWithUpdatedPos;
74
68
  }
@@ -142,7 +136,13 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
142
136
  invoke();
143
137
  });
144
138
  }
145
- analyticsQueue.flush();
139
+
140
+ /**
141
+ * If there have been any events queued, flush them
142
+ * so subscribers can now be notified and dispatch
143
+ * analytics events
144
+ */
145
+ cardPluginEvents === null || cardPluginEvents === void 0 ? void 0 : cardPluginEvents.flush();
146
146
  },
147
147
  destroy() {
148
148
  // Cancel any outstanding raf callbacks.
@@ -53,12 +53,6 @@ const registerEvents = (state, action) => {
53
53
  smartLinkEvents: action.smartLinkEvents
54
54
  };
55
55
  };
56
- const registerEventsNext = (state, action) => {
57
- return {
58
- ...state,
59
- smartLinkEventsNext: action.smartLinkEvents
60
- };
61
- };
62
56
  const setLinkToolbar = (state, action) => {
63
57
  return {
64
58
  ...state,
@@ -91,8 +85,6 @@ export default ((state, action) => {
91
85
  return register(state, action);
92
86
  case 'REGISTER_EVENTS':
93
87
  return registerEvents(state, action);
94
- case 'REGISTER_EVENTS_NEXT':
95
- return registerEventsNext(state, action);
96
88
  case 'SET_DATASOURCE_TABLE_REF':
97
89
  return setDatasourceTableRef(state, action);
98
90
  case 'SET_CARD_LAYOUT':
@@ -0,0 +1,46 @@
1
+ import { useEffect, useMemo } from 'react';
2
+ import { EVENT, EVENT_SUBJECT } from '../../analytics/types';
3
+ /**
4
+ * Subscribes to the events occuring in the card
5
+ * plugin and fires analytics events accordingly
6
+ */
7
+ export const DatasourceEventsBinding = ({
8
+ cardPluginEvents
9
+ }) => {
10
+ const eventHandlers = useMemo(() => {
11
+ return {
12
+ [EVENT.CREATED]: 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
+ },
17
+ [EVENT.UPDATED]: metadata => {
18
+ // TODO Impl as part of https://product-fabric.atlassian.net/browse/EDM-7072
19
+ // eslint-disable-next-line no-console
20
+ console.log('UPDATED', metadata.node, metadata.nodeContext);
21
+ },
22
+ [EVENT.DELETED]: metadata => {
23
+ // TODO Impl as part of https://product-fabric.atlassian.net/browse/EDM-7072
24
+ // eslint-disable-next-line no-console
25
+ console.log('DELETED', metadata.node, metadata.nodeContext);
26
+ }
27
+ };
28
+ }, []);
29
+
30
+ /**
31
+ * Subscribe to datasource events
32
+ */
33
+ useEffect(() => {
34
+ const unsubscribe = cardPluginEvents.subscribe(({
35
+ event,
36
+ subject,
37
+ data
38
+ }) => {
39
+ if (subject === EVENT_SUBJECT.DATASOURCE) {
40
+ eventHandlers[event](data);
41
+ }
42
+ });
43
+ return () => unsubscribe();
44
+ }, [eventHandlers, cardPluginEvents]);
45
+ return null;
46
+ };