@atlaskit/editor-plugin-card 0.3.4 → 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 +7 -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 +2 -2
  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
@@ -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 {};
@@ -1,160 +0,0 @@
1
- import { isLinkMark } from '@atlaskit/editor-common/utils';
2
- import { appearanceForNodeType } from '../../utils';
3
- /**
4
- * Whether a node is a "link" node, ie inline card, block card, embed card
5
- * (but not a text node with a link mark)
6
- */
7
- export function isLinkNode(node) {
8
- return !!appearanceForNodeType(node.type);
9
- }
10
-
11
- /**
12
- * Analytics appearance for link object
13
- */
14
- export function appearanceForLink(link) {
15
- if (link.type === 'node') {
16
- const appearance = appearanceForNodeType(link.node.type);
17
- if (appearance) {
18
- return appearance;
19
- }
20
- }
21
- return 'url';
22
- }
23
- const nodeHasLinkMark = (schema, node) => {
24
- if (node.marks) {
25
- for (let i = 0; i < node.marks.length; i++) {
26
- const mark = node.marks[i];
27
- if (isLinkMark(mark, schema)) {
28
- return true;
29
- }
30
- }
31
- }
32
- return false;
33
- };
34
-
35
- /**
36
- * Determine if a node is considered to be a link
37
- */
38
- export const isLink = (schema, node) => {
39
- if (isLinkNode(node)) {
40
- return true;
41
- }
42
- return nodeHasLinkMark(schema, node);
43
- };
44
-
45
- /**
46
- * Given a node, find all nodes and marks that are considered "links"
47
- * @param state EditorState
48
- * @param fragment Fragment to search
49
- * @returns Array of nodes and marks found in the fragment that are "links"
50
- */
51
- export function findLinksInNode(doc, schema, node, offset) {
52
- const links = [];
53
- node.descendants((node, pos) => {
54
- const nodeContext = getLinkNodeContext(doc, pos);
55
-
56
- // Nodes
57
- if (isLinkNode(node)) {
58
- links.push({
59
- type: 'node',
60
- pos: pos + offset,
61
- node,
62
- nodeContext
63
- });
64
- }
65
-
66
- // Marks
67
- if (node.marks) {
68
- for (let i = 0; i < node.marks.length; i++) {
69
- const mark = node.marks[i];
70
- if (isLinkMark(mark, schema)) {
71
- links.push({
72
- type: 'mark',
73
- pos: pos + offset,
74
- mark,
75
- nodeContext
76
- });
77
- }
78
- }
79
- }
80
- });
81
- return links;
82
- }
83
- export function getLinkUrl(link) {
84
- var _link$mark$attrs;
85
- if (link.type === 'node') {
86
- var _link$node$attrs;
87
- return (_link$node$attrs = link.node.attrs) === null || _link$node$attrs === void 0 ? void 0 : _link$node$attrs.url;
88
- }
89
- return (_link$mark$attrs = link.mark.attrs) === null || _link$mark$attrs === void 0 ? void 0 : _link$mark$attrs.href;
90
- }
91
- export const getLinkNodeContext = (doc, pos) => {
92
- const $pos = doc.resolve(pos);
93
- const maxDepth = 3;
94
- for (let i = 0; i <= maxDepth; i++) {
95
- const node = $pos.node($pos.depth - i);
96
- if (node && node.type.name !== 'paragraph') {
97
- return node.type.name;
98
- }
99
- }
100
- return 'unknown';
101
- };
102
- export const linkObjectFromNode = (doc, schema, node, pos) => {
103
- const nodeContext = getLinkNodeContext(doc, pos);
104
- if (isLinkNode(node)) {
105
- return {
106
- type: 'node',
107
- pos,
108
- node,
109
- nodeContext
110
- };
111
- }
112
- if (node.marks) {
113
- for (let i = 0; i < node.marks.length; i++) {
114
- const mark = node.marks[i];
115
- if (isLinkMark(mark, schema)) {
116
- return {
117
- type: 'mark',
118
- pos,
119
- mark,
120
- nodeContext
121
- };
122
- }
123
- }
124
- }
125
- };
126
- export const findLinksAtPositions = (tr, positions) => {
127
- const schema = tr.doc.type.schema;
128
- const links = [];
129
- for (let i = 0; i < positions.length; i++) {
130
- const pos = positions[i];
131
- const node = tr.doc.nodeAt(pos);
132
- if (!node) {
133
- continue;
134
- }
135
- const link = linkObjectFromNode(tr.doc, schema, node, pos);
136
- if (!link) {
137
- continue;
138
- }
139
- links.push(link);
140
- }
141
- return links;
142
- };
143
-
144
- /**
145
- * Returns whether or not two sets of links appear to likely be the same set of links
146
- * That they are in the same order and that both their hrefs and appearances match
147
- */
148
- export const areSameLinks = (linksA, linksB) => {
149
- if (linksA.length !== linksB.length) {
150
- return false;
151
- }
152
- for (let i = 0; i < linksA.length; i++) {
153
- const linkA = linksA[i];
154
- const linkB = linksB[i];
155
- if (getLinkUrl(linkA) !== getLinkUrl(linkB) || appearanceForLink(linkA) !== appearanceForLink(linkB)) {
156
- return false;
157
- }
158
- }
159
- return true;
160
- };
@@ -1,188 +0,0 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import React, { useEffect, useMemo } from 'react';
3
- import PropTypes from 'prop-types';
4
- import { UIAnalyticsEvent } from '@atlaskit/analytics-next';
5
- import { ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
6
- import { useSmartLinkLifecycleAnalytics } from '@atlaskit/link-analytics';
7
- import { registerSmartCardEventsNext } from '../pm-plugins/actions';
8
- import { EditorAnalyticsContext } from './EditorAnalyticsContext';
9
- /**
10
- * If the metadata is for a history event,
11
- * returns undo/redo instead of instead of what fn(metadata) would have otherwise
12
- * returned
13
- */
14
- const withHistoryMethod = fn => {
15
- return metadata => {
16
- const {
17
- isUndo,
18
- isRedo
19
- } = metadata;
20
- if (isUndo) {
21
- return 'undo';
22
- }
23
- if (isRedo) {
24
- return 'redo';
25
- }
26
- return fn(metadata);
27
- };
28
- };
29
- const getMethod = withHistoryMethod(({
30
- inputMethod
31
- }) => {
32
- switch (inputMethod) {
33
- case INPUT_METHOD.CLIPBOARD:
34
- return 'editor_paste';
35
- case INPUT_METHOD.FLOATING_TB:
36
- return 'editor_floatingToolbar';
37
- case INPUT_METHOD.AUTO_DETECT:
38
- case INPUT_METHOD.FORMATTING:
39
- return 'editor_type';
40
- default:
41
- return 'unknown';
42
- }
43
- });
44
- const getUpdateType = withHistoryMethod(({
45
- action
46
- }) => {
47
- switch (action) {
48
- case ACTION.CHANGED_TYPE:
49
- return 'display_update';
50
- case ACTION.UPDATED:
51
- return 'link_update';
52
- default:
53
- return 'unknown';
54
- }
55
- });
56
- const getDeleteType = withHistoryMethod(({
57
- action
58
- }) => {
59
- if (action === ACTION.UNLINK) {
60
- return 'unlink';
61
- }
62
- return 'delete';
63
- });
64
- const getSourceEventFromMetadata = metadata => {
65
- return metadata.sourceEvent instanceof UIAnalyticsEvent ? metadata.sourceEvent : null;
66
- };
67
-
68
- /**
69
- * Set display category as `link` if not displaying the link as a smart card
70
- */
71
- const displayCategoryFromDisplay = display => {
72
- if (display === 'url') {
73
- return 'link';
74
- }
75
- };
76
-
77
- /**
78
- * Binds the @atlaskit/link-analytics callbacks
79
- * to the editor card plugin state events callbacks interfaces
80
- */
81
- export const EventsBinding = ({
82
- editorView
83
- }) => {
84
- /**
85
- * These callbacks internally use window.requestIdleCallback/requestAnimationFrame
86
- * to defer any heavy operations involving network
87
- *
88
- * The callbacks themselves should not be deferred, they should be called syncronously the moment
89
- * the events take place.
90
- */
91
- const {
92
- linkCreated,
93
- linkUpdated,
94
- linkDeleted
95
- } = useSmartLinkLifecycleAnalytics();
96
- const events = useMemo(() => {
97
- return {
98
- created: metadata => {
99
- const {
100
- url,
101
- display,
102
- nodeContext
103
- } = metadata;
104
- const displayCategory = displayCategoryFromDisplay(display);
105
- const sourceEvent = getSourceEventFromMetadata(metadata);
106
- const creationMethod = getMethod(metadata);
107
- linkCreated({
108
- url,
109
- displayCategory
110
- }, sourceEvent, {
111
- display,
112
- nodeContext,
113
- creationMethod
114
- });
115
- },
116
- updated: metadata => {
117
- const {
118
- url,
119
- display,
120
- previousDisplay,
121
- nodeContext
122
- } = metadata;
123
- const displayCategory = displayCategoryFromDisplay(display);
124
- const sourceEvent = getSourceEventFromMetadata(metadata);
125
- const updateMethod = getMethod(metadata);
126
- const updateType = getUpdateType(metadata);
127
- linkUpdated({
128
- url,
129
- displayCategory
130
- }, sourceEvent, {
131
- display,
132
- previousDisplay,
133
- nodeContext,
134
- updateMethod,
135
- updateType
136
- });
137
- },
138
- deleted: metadata => {
139
- const {
140
- url,
141
- display,
142
- nodeContext
143
- } = metadata;
144
- const displayCategory = displayCategoryFromDisplay(display);
145
- const sourceEvent = getSourceEventFromMetadata(metadata);
146
- const deleteMethod = getMethod(metadata);
147
- const deleteType = getDeleteType(metadata);
148
- linkDeleted({
149
- url,
150
- displayCategory
151
- }, sourceEvent, {
152
- display,
153
- nodeContext,
154
- deleteMethod,
155
- deleteType
156
- });
157
- }
158
- };
159
- }, [linkCreated, linkUpdated, linkDeleted]);
160
- useEffect(() => {
161
- editorView.dispatch(registerSmartCardEventsNext(events)(editorView.state.tr));
162
- }, [events, editorView]);
163
- return null;
164
- };
165
-
166
- // eslint-disable-next-line @repo/internal/react/no-class-components
167
- export class EditorSmartCardEventsNext extends React.PureComponent {
168
- render() {
169
- const cardContext = this.context.contextAdapter.card;
170
-
171
- /**
172
- * The analytics hook needs to be able to communicate with the card context
173
- * If we can't access it, don't mount the event bindings
174
- * This effectively entirely disables all tracking behaviour
175
- */
176
- if (!cardContext) {
177
- return null;
178
- }
179
- return /*#__PURE__*/React.createElement(cardContext.Provider, {
180
- value: cardContext.value
181
- }, /*#__PURE__*/React.createElement(EditorAnalyticsContext, {
182
- editorView: this.props.editorView
183
- }, /*#__PURE__*/React.createElement(EventsBinding, this.props)));
184
- }
185
- }
186
- _defineProperty(EditorSmartCardEventsNext, "contextTypes", {
187
- contextAdapter: PropTypes.object
188
- });
@@ -1,41 +0,0 @@
1
- /**
2
- * Simple mechanism to defer analytics related callbacks
3
- */
4
- export var createAnalyticsQueue = function createAnalyticsQueue() {
5
- var enabled = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
6
- var queue = [];
7
- var callbacksRef = {
8
- current: null
9
- };
10
- var setCallbacks = function setCallbacks(callbacks) {
11
- callbacksRef.current = callbacks;
12
- };
13
- var push = function push() {
14
- var callbacks = callbacksRef.current;
15
- if (!enabled || !callbacks) {
16
- return;
17
- }
18
- queue.push.apply(queue, arguments);
19
- };
20
- var flush = function flush() {
21
- var callbacks = callbacksRef.current;
22
- if (!enabled || !callbacks) {
23
- return;
24
- }
25
- while (queue.length) {
26
- var event = queue.pop();
27
- if (event) {
28
- callbacks[event.type](event.data);
29
- }
30
- }
31
- };
32
- var getSize = function getSize() {
33
- return queue.length;
34
- };
35
- return {
36
- push: push,
37
- flush: flush,
38
- setCallbacks: setCallbacks,
39
- getSize: getSize
40
- };
41
- };
@@ -1,2 +0,0 @@
1
- export { createAnalyticsQueue } from './create-analytics-queue';
2
- export { eventsFromTransaction } from './events-from-tr';
@@ -1 +0,0 @@
1
- export {};