@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
@@ -20,6 +20,7 @@ import type { gridPlugin } from '@atlaskit/editor-plugin-grid';
20
20
  import type { hyperlinkPlugin } from '@atlaskit/editor-plugin-hyperlink';
21
21
  import type { LinkPickerOptions } from '@atlaskit/editor-common/types';
22
22
  import type { NextEditorPlugin } from '@atlaskit/editor-common/types';
23
+ import { Node as Node_2 } from '@atlaskit/editor-prosemirror/model';
23
24
  import type { OptionalPlugin } from '@atlaskit/editor-common/types';
24
25
  import { SmartLinkEvents } from '@atlaskit/smart-card';
25
26
  import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
@@ -48,12 +49,16 @@ export const cardPlugin: NextEditorPlugin<'card', {
48
49
  actions: CardPluginActions;
49
50
  }>;
50
51
 
52
+ // @public (undocumented)
53
+ type CardPluginEvent = DatasourceEvent | LinkEvent;
54
+
51
55
  // @public (undocumented)
52
56
  type CardPluginOptions = CardOptions & {
53
57
  editorAppearance?: EditorAppearance;
54
58
  platform: 'mobile' | 'web';
55
59
  fullWidthMode?: boolean;
56
60
  linkPicker?: LinkPickerOptions;
61
+ cardPluginEvents?: EditorCardPluginEvents<CardPluginEvent>;
57
62
  };
58
63
 
59
64
  // @public (undocumented)
@@ -63,7 +68,6 @@ type CardPluginState = {
63
68
  cards: CardInfo[];
64
69
  showLinkingToolbar: boolean;
65
70
  smartLinkEvents?: SmartLinkEvents;
66
- smartLinkEventsNext?: SmartLinkEventsNext;
67
71
  editorAppearance?: EditorAppearance;
68
72
  showDatasourceModal: boolean;
69
73
  datasourceModalType?: DatasourceModalType;
@@ -71,13 +75,86 @@ type CardPluginState = {
71
75
  layout?: DatasourceTableLayout;
72
76
  };
73
77
 
78
+ // @public (undocumented)
79
+ type DatasourceCreatedEvent = {
80
+ event: EVENT.CREATED;
81
+ subject: EVENT_SUBJECT.DATASOURCE;
82
+ data: Metadata_2;
83
+ };
84
+
85
+ // @public (undocumented)
86
+ type DatasourceDeletedEvent = {
87
+ event: EVENT.DELETED;
88
+ subject: EVENT_SUBJECT.DATASOURCE;
89
+ data: Metadata_2;
90
+ };
91
+
92
+ // @public (undocumented)
93
+ type DatasourceEvent = DatasourceCreatedEvent | DatasourceDeletedEvent | DatasourceUpdatedEvent;
94
+
74
95
  // @public (undocumented)
75
96
  type DatasourceTableLayout = 'center' | 'full-width' | 'wide';
76
97
 
98
+ // @public (undocumented)
99
+ type DatasourceUpdatedEvent = {
100
+ event: EVENT.UPDATED;
101
+ subject: EVENT_SUBJECT.DATASOURCE;
102
+ data: Metadata_2<UpdateMetadata>;
103
+ };
104
+
105
+ // @public (undocumented)
106
+ type EditorCardPluginEvents<T> = {
107
+ push: (...events: T[]) => void;
108
+ subscribe: (listener: Subscriber<T>) => () => void;
109
+ flush: () => void;
110
+ getSize: () => number;
111
+ };
112
+
113
+ // @public (undocumented)
114
+ enum EVENT {
115
+ // (undocumented)
116
+ CREATED = "created",
117
+ // (undocumented)
118
+ DELETED = "deleted",
119
+ // (undocumented)
120
+ UPDATED = "updated"
121
+ }
122
+
123
+ // @public (undocumented)
124
+ enum EVENT_SUBJECT {
125
+ // (undocumented)
126
+ DATASOURCE = "datasource",
127
+ // (undocumented)
128
+ LINK = "link"
129
+ }
130
+
131
+ // @public
132
+ type LinkCreatedEvent = {
133
+ event: EVENT.CREATED;
134
+ subject: EVENT_SUBJECT.LINK;
135
+ data: Metadata_2;
136
+ };
137
+
138
+ // @public (undocumented)
139
+ type LinkDeletedEvent = {
140
+ event: EVENT.DELETED;
141
+ subject: EVENT_SUBJECT.LINK;
142
+ data: Metadata_2;
143
+ };
144
+
145
+ // @public (undocumented)
146
+ type LinkEvent = LinkCreatedEvent | LinkDeletedEvent | LinkUpdatedEvent;
147
+
148
+ // @public (undocumented)
149
+ type LinkUpdatedEvent = {
150
+ event: EVENT.UPDATED;
151
+ subject: EVENT_SUBJECT.LINK;
152
+ data: Metadata_2<UpdateMetadata>;
153
+ };
154
+
77
155
  // @public (undocumented)
78
156
  type Metadata_2<T = {}> = {
79
- url: string;
80
- display: string;
157
+ node: Node_2;
81
158
  isUndo?: boolean;
82
159
  isRedo?: boolean;
83
160
  action?: string;
@@ -101,11 +178,7 @@ type Request_2 = {
101
178
  export { Request_2 as Request }
102
179
 
103
180
  // @public (undocumented)
104
- type SmartLinkEventsNext = {
105
- created: (metadata: Metadata_2) => void;
106
- updated: (metadata: Metadata_2<UpdateMetadata>) => void;
107
- deleted: (metadata: Metadata_2) => void;
108
- };
181
+ type Subscriber<T> = (event: T) => void;
109
182
 
110
183
  // @public (undocumented)
111
184
  type UpdateMetadata = {
@@ -1,48 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.createAnalyticsQueue = void 0;
7
- /**
8
- * Simple mechanism to defer analytics related callbacks
9
- */
10
- var createAnalyticsQueue = function createAnalyticsQueue() {
11
- var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
12
- var queue = [];
13
- var callbacksRef = {
14
- current: null
15
- };
16
- var setCallbacks = function setCallbacks(callbacks) {
17
- callbacksRef.current = callbacks;
18
- };
19
- var push = function push() {
20
- var callbacks = callbacksRef.current;
21
- if (!enabled || !callbacks) {
22
- return;
23
- }
24
- queue.push.apply(queue, arguments);
25
- };
26
- var flush = function flush() {
27
- var callbacks = callbacksRef.current;
28
- if (!enabled || !callbacks) {
29
- return;
30
- }
31
- while (queue.length) {
32
- var event = queue.pop();
33
- if (event) {
34
- callbacks[event.type](event.data);
35
- }
36
- }
37
- };
38
- var getSize = function getSize() {
39
- return queue.length;
40
- };
41
- return {
42
- push: push,
43
- flush: flush,
44
- setCallbacks: setCallbacks,
45
- getSize: getSize
46
- };
47
- };
48
- exports.createAnalyticsQueue = createAnalyticsQueue;
@@ -1,5 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
@@ -1,178 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.appearanceForLink = appearanceForLink;
7
- exports.findLinksAtPositions = exports.areSameLinks = void 0;
8
- exports.findLinksInNode = findLinksInNode;
9
- exports.getLinkNodeContext = void 0;
10
- exports.getLinkUrl = getLinkUrl;
11
- exports.isLink = void 0;
12
- exports.isLinkNode = isLinkNode;
13
- exports.linkObjectFromNode = void 0;
14
- var _utils = require("@atlaskit/editor-common/utils");
15
- var _utils2 = require("../../utils");
16
- /**
17
- * Whether a node is a "link" node, ie inline card, block card, embed card
18
- * (but not a text node with a link mark)
19
- */
20
- function isLinkNode(node) {
21
- return !!(0, _utils2.appearanceForNodeType)(node.type);
22
- }
23
-
24
- /**
25
- * Analytics appearance for link object
26
- */
27
- function appearanceForLink(link) {
28
- if (link.type === 'node') {
29
- var appearance = (0, _utils2.appearanceForNodeType)(link.node.type);
30
- if (appearance) {
31
- return appearance;
32
- }
33
- }
34
- return 'url';
35
- }
36
- var nodeHasLinkMark = function nodeHasLinkMark(schema, node) {
37
- if (node.marks) {
38
- for (var i = 0; i < node.marks.length; i++) {
39
- var mark = node.marks[i];
40
- if ((0, _utils.isLinkMark)(mark, schema)) {
41
- return true;
42
- }
43
- }
44
- }
45
- return false;
46
- };
47
-
48
- /**
49
- * Determine if a node is considered to be a link
50
- */
51
- var isLink = function isLink(schema, node) {
52
- if (isLinkNode(node)) {
53
- return true;
54
- }
55
- return nodeHasLinkMark(schema, node);
56
- };
57
-
58
- /**
59
- * Given a node, find all nodes and marks that are considered "links"
60
- * @param state EditorState
61
- * @param fragment Fragment to search
62
- * @returns Array of nodes and marks found in the fragment that are "links"
63
- */
64
- exports.isLink = isLink;
65
- function findLinksInNode(doc, schema, node, offset) {
66
- var links = [];
67
- node.descendants(function (node, pos) {
68
- var nodeContext = getLinkNodeContext(doc, pos);
69
-
70
- // Nodes
71
- if (isLinkNode(node)) {
72
- links.push({
73
- type: 'node',
74
- pos: pos + offset,
75
- node: node,
76
- nodeContext: nodeContext
77
- });
78
- }
79
-
80
- // Marks
81
- if (node.marks) {
82
- for (var i = 0; i < node.marks.length; i++) {
83
- var mark = node.marks[i];
84
- if ((0, _utils.isLinkMark)(mark, schema)) {
85
- links.push({
86
- type: 'mark',
87
- pos: pos + offset,
88
- mark: mark,
89
- nodeContext: nodeContext
90
- });
91
- }
92
- }
93
- }
94
- });
95
- return links;
96
- }
97
- function getLinkUrl(link) {
98
- var _link$mark$attrs;
99
- if (link.type === 'node') {
100
- var _link$node$attrs;
101
- return (_link$node$attrs = link.node.attrs) === null || _link$node$attrs === void 0 ? void 0 : _link$node$attrs.url;
102
- }
103
- return (_link$mark$attrs = link.mark.attrs) === null || _link$mark$attrs === void 0 ? void 0 : _link$mark$attrs.href;
104
- }
105
- var getLinkNodeContext = function getLinkNodeContext(doc, pos) {
106
- var $pos = doc.resolve(pos);
107
- var maxDepth = 3;
108
- for (var i = 0; i <= maxDepth; i++) {
109
- var node = $pos.node($pos.depth - i);
110
- if (node && node.type.name !== 'paragraph') {
111
- return node.type.name;
112
- }
113
- }
114
- return 'unknown';
115
- };
116
- exports.getLinkNodeContext = getLinkNodeContext;
117
- var linkObjectFromNode = function linkObjectFromNode(doc, schema, node, pos) {
118
- var nodeContext = getLinkNodeContext(doc, pos);
119
- if (isLinkNode(node)) {
120
- return {
121
- type: 'node',
122
- pos: pos,
123
- node: node,
124
- nodeContext: nodeContext
125
- };
126
- }
127
- if (node.marks) {
128
- for (var i = 0; i < node.marks.length; i++) {
129
- var mark = node.marks[i];
130
- if ((0, _utils.isLinkMark)(mark, schema)) {
131
- return {
132
- type: 'mark',
133
- pos: pos,
134
- mark: mark,
135
- nodeContext: nodeContext
136
- };
137
- }
138
- }
139
- }
140
- };
141
- exports.linkObjectFromNode = linkObjectFromNode;
142
- var findLinksAtPositions = function findLinksAtPositions(tr, positions) {
143
- var schema = tr.doc.type.schema;
144
- var links = [];
145
- for (var i = 0; i < positions.length; i++) {
146
- var pos = positions[i];
147
- var node = tr.doc.nodeAt(pos);
148
- if (!node) {
149
- continue;
150
- }
151
- var link = linkObjectFromNode(tr.doc, schema, node, pos);
152
- if (!link) {
153
- continue;
154
- }
155
- links.push(link);
156
- }
157
- return links;
158
- };
159
-
160
- /**
161
- * Returns whether or not two sets of links appear to likely be the same set of links
162
- * That they are in the same order and that both their hrefs and appearances match
163
- */
164
- exports.findLinksAtPositions = findLinksAtPositions;
165
- var areSameLinks = function areSameLinks(linksA, linksB) {
166
- if (linksA.length !== linksB.length) {
167
- return false;
168
- }
169
- for (var i = 0; i < linksA.length; i++) {
170
- var linkA = linksA[i];
171
- var linkB = linksB[i];
172
- if (getLinkUrl(linkA) !== getLinkUrl(linkB) || appearanceForLink(linkA) !== appearanceForLink(linkB)) {
173
- return false;
174
- }
175
- }
176
- return true;
177
- };
178
- exports.areSameLinks = areSameLinks;
@@ -1,204 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- var _typeof = require("@babel/runtime/helpers/typeof");
5
- Object.defineProperty(exports, "__esModule", {
6
- value: true
7
- });
8
- exports.EventsBinding = exports.EditorSmartCardEventsNext = void 0;
9
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
10
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
11
- var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
12
- var _possibleConstructorReturn2 = _interopRequireDefault(require("@babel/runtime/helpers/possibleConstructorReturn"));
13
- var _getPrototypeOf2 = _interopRequireDefault(require("@babel/runtime/helpers/getPrototypeOf"));
14
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
15
- var _react = _interopRequireWildcard(require("react"));
16
- var _propTypes = _interopRequireDefault(require("prop-types"));
17
- var _analyticsNext = require("@atlaskit/analytics-next");
18
- var _analytics = require("@atlaskit/editor-common/analytics");
19
- var _linkAnalytics = require("@atlaskit/link-analytics");
20
- var _actions = require("../pm-plugins/actions");
21
- var _EditorAnalyticsContext = require("./EditorAnalyticsContext");
22
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
- function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
25
- 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; } }
26
- /**
27
- * If the metadata is for a history event,
28
- * returns undo/redo instead of instead of what fn(metadata) would have otherwise
29
- * returned
30
- */
31
- var withHistoryMethod = function withHistoryMethod(fn) {
32
- return function (metadata) {
33
- var isUndo = metadata.isUndo,
34
- isRedo = metadata.isRedo;
35
- if (isUndo) {
36
- return 'undo';
37
- }
38
- if (isRedo) {
39
- return 'redo';
40
- }
41
- return fn(metadata);
42
- };
43
- };
44
- var getMethod = withHistoryMethod(function (_ref) {
45
- var inputMethod = _ref.inputMethod;
46
- switch (inputMethod) {
47
- case _analytics.INPUT_METHOD.CLIPBOARD:
48
- return 'editor_paste';
49
- case _analytics.INPUT_METHOD.FLOATING_TB:
50
- return 'editor_floatingToolbar';
51
- case _analytics.INPUT_METHOD.AUTO_DETECT:
52
- case _analytics.INPUT_METHOD.FORMATTING:
53
- return 'editor_type';
54
- default:
55
- return 'unknown';
56
- }
57
- });
58
- var getUpdateType = withHistoryMethod(function (_ref2) {
59
- var action = _ref2.action;
60
- switch (action) {
61
- case _analytics.ACTION.CHANGED_TYPE:
62
- return 'display_update';
63
- case _analytics.ACTION.UPDATED:
64
- return 'link_update';
65
- default:
66
- return 'unknown';
67
- }
68
- });
69
- var getDeleteType = withHistoryMethod(function (_ref3) {
70
- var action = _ref3.action;
71
- if (action === _analytics.ACTION.UNLINK) {
72
- return 'unlink';
73
- }
74
- return 'delete';
75
- });
76
- var getSourceEventFromMetadata = function getSourceEventFromMetadata(metadata) {
77
- return metadata.sourceEvent instanceof _analyticsNext.UIAnalyticsEvent ? metadata.sourceEvent : null;
78
- };
79
-
80
- /**
81
- * Set display category as `link` if not displaying the link as a smart card
82
- */
83
- var displayCategoryFromDisplay = function displayCategoryFromDisplay(display) {
84
- if (display === 'url') {
85
- return 'link';
86
- }
87
- };
88
-
89
- /**
90
- * Binds the @atlaskit/link-analytics callbacks
91
- * to the editor card plugin state events callbacks interfaces
92
- */
93
- var EventsBinding = function EventsBinding(_ref4) {
94
- var editorView = _ref4.editorView;
95
- /**
96
- * These callbacks internally use window.requestIdleCallback/requestAnimationFrame
97
- * to defer any heavy operations involving network
98
- *
99
- * The callbacks themselves should not be deferred, they should be called syncronously the moment
100
- * the events take place.
101
- */
102
- var _useSmartLinkLifecycl = (0, _linkAnalytics.useSmartLinkLifecycleAnalytics)(),
103
- linkCreated = _useSmartLinkLifecycl.linkCreated,
104
- linkUpdated = _useSmartLinkLifecycl.linkUpdated,
105
- linkDeleted = _useSmartLinkLifecycl.linkDeleted;
106
- var events = (0, _react.useMemo)(function () {
107
- return {
108
- created: function created(metadata) {
109
- var url = metadata.url,
110
- display = metadata.display,
111
- nodeContext = metadata.nodeContext;
112
- var displayCategory = displayCategoryFromDisplay(display);
113
- var sourceEvent = getSourceEventFromMetadata(metadata);
114
- var creationMethod = getMethod(metadata);
115
- linkCreated({
116
- url: url,
117
- displayCategory: displayCategory
118
- }, sourceEvent, {
119
- display: display,
120
- nodeContext: nodeContext,
121
- creationMethod: creationMethod
122
- });
123
- },
124
- updated: function updated(metadata) {
125
- var url = metadata.url,
126
- display = metadata.display,
127
- previousDisplay = metadata.previousDisplay,
128
- nodeContext = metadata.nodeContext;
129
- var displayCategory = displayCategoryFromDisplay(display);
130
- var sourceEvent = getSourceEventFromMetadata(metadata);
131
- var updateMethod = getMethod(metadata);
132
- var updateType = getUpdateType(metadata);
133
- linkUpdated({
134
- url: url,
135
- displayCategory: displayCategory
136
- }, sourceEvent, {
137
- display: display,
138
- previousDisplay: previousDisplay,
139
- nodeContext: nodeContext,
140
- updateMethod: updateMethod,
141
- updateType: updateType
142
- });
143
- },
144
- deleted: function deleted(metadata) {
145
- var url = metadata.url,
146
- display = metadata.display,
147
- nodeContext = metadata.nodeContext;
148
- var displayCategory = displayCategoryFromDisplay(display);
149
- var sourceEvent = getSourceEventFromMetadata(metadata);
150
- var deleteMethod = getMethod(metadata);
151
- var deleteType = getDeleteType(metadata);
152
- linkDeleted({
153
- url: url,
154
- displayCategory: displayCategory
155
- }, sourceEvent, {
156
- display: display,
157
- nodeContext: nodeContext,
158
- deleteMethod: deleteMethod,
159
- deleteType: deleteType
160
- });
161
- }
162
- };
163
- }, [linkCreated, linkUpdated, linkDeleted]);
164
- (0, _react.useEffect)(function () {
165
- editorView.dispatch((0, _actions.registerSmartCardEventsNext)(events)(editorView.state.tr));
166
- }, [events, editorView]);
167
- return null;
168
- };
169
-
170
- // eslint-disable-next-line @repo/internal/react/no-class-components
171
- exports.EventsBinding = EventsBinding;
172
- var EditorSmartCardEventsNext = /*#__PURE__*/function (_React$PureComponent) {
173
- (0, _inherits2.default)(EditorSmartCardEventsNext, _React$PureComponent);
174
- var _super = _createSuper(EditorSmartCardEventsNext);
175
- function EditorSmartCardEventsNext() {
176
- (0, _classCallCheck2.default)(this, EditorSmartCardEventsNext);
177
- return _super.apply(this, arguments);
178
- }
179
- (0, _createClass2.default)(EditorSmartCardEventsNext, [{
180
- key: "render",
181
- value: function render() {
182
- var cardContext = this.context.contextAdapter.card;
183
-
184
- /**
185
- * The analytics hook needs to be able to communicate with the card context
186
- * If we can't access it, don't mount the event bindings
187
- * This effectively entirely disables all tracking behaviour
188
- */
189
- if (!cardContext) {
190
- return null;
191
- }
192
- return /*#__PURE__*/_react.default.createElement(cardContext.Provider, {
193
- value: cardContext.value
194
- }, /*#__PURE__*/_react.default.createElement(_EditorAnalyticsContext.EditorAnalyticsContext, {
195
- editorView: this.props.editorView
196
- }, /*#__PURE__*/_react.default.createElement(EventsBinding, this.props)));
197
- }
198
- }]);
199
- return EditorSmartCardEventsNext;
200
- }(_react.default.PureComponent);
201
- exports.EditorSmartCardEventsNext = EditorSmartCardEventsNext;
202
- (0, _defineProperty2.default)(EditorSmartCardEventsNext, "contextTypes", {
203
- contextAdapter: _propTypes.default.object
204
- });
@@ -1,38 +0,0 @@
1
- /**
2
- * Simple mechanism to defer analytics related callbacks
3
- */
4
- export const createAnalyticsQueue = (enabled = true) => {
5
- const queue = [];
6
- const callbacksRef = {
7
- current: null
8
- };
9
- const setCallbacks = callbacks => {
10
- callbacksRef.current = callbacks;
11
- };
12
- const push = (...events) => {
13
- const callbacks = callbacksRef.current;
14
- if (!enabled || !callbacks) {
15
- return;
16
- }
17
- queue.push(...events);
18
- };
19
- const flush = () => {
20
- const callbacks = callbacksRef.current;
21
- if (!enabled || !callbacks) {
22
- return;
23
- }
24
- while (queue.length) {
25
- const event = queue.pop();
26
- if (event) {
27
- callbacks[event.type](event.data);
28
- }
29
- }
30
- };
31
- const getSize = () => queue.length;
32
- return {
33
- push,
34
- flush,
35
- setCallbacks,
36
- getSize
37
- };
38
- };
@@ -1,2 +0,0 @@
1
- export { createAnalyticsQueue } from './create-analytics-queue';
2
- export { eventsFromTransaction } from './events-from-tr';
@@ -1 +0,0 @@
1
- export {};