@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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/analytics/create-events-queue.js +55 -0
- package/dist/cjs/{pm-plugins/analytics → analytics}/events-from-tr.js +90 -81
- package/dist/cjs/{pm-plugins/analytics → analytics}/index.js +3 -3
- package/dist/cjs/analytics/types.js +24 -0
- package/dist/cjs/analytics/utils.js +134 -0
- package/dist/cjs/nodeviews/datasource.js +1 -8
- package/dist/cjs/plugin.js +7 -4
- package/dist/cjs/pm-plugins/actions.js +1 -10
- package/dist/cjs/pm-plugins/doc.js +3 -0
- package/dist/cjs/pm-plugins/main.js +15 -13
- package/dist/cjs/pm-plugins/reducers.js +0 -7
- package/dist/cjs/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +52 -0
- package/dist/cjs/ui/EditorLinkingPlatformAnalytics/LinkEvents.js +132 -0
- package/dist/cjs/ui/EditorLinkingPlatformAnalytics/common.js +65 -0
- package/dist/cjs/ui/EditorLinkingPlatformAnalytics/index.js +54 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/analytics/create-events-queue.js +43 -0
- package/dist/es2019/{pm-plugins/analytics → analytics}/events-from-tr.js +82 -72
- package/dist/es2019/analytics/index.js +2 -0
- package/dist/es2019/analytics/types.js +17 -0
- package/dist/es2019/analytics/utils.js +118 -0
- package/dist/es2019/nodeviews/datasource.js +2 -9
- package/dist/es2019/plugin.js +7 -6
- package/dist/es2019/pm-plugins/actions.js +0 -4
- package/dist/es2019/pm-plugins/doc.js +3 -0
- package/dist/es2019/pm-plugins/main.js +15 -15
- package/dist/es2019/pm-plugins/reducers.js +0 -8
- package/dist/es2019/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +46 -0
- package/dist/es2019/ui/EditorLinkingPlatformAnalytics/LinkEvents.js +127 -0
- package/dist/es2019/ui/EditorLinkingPlatformAnalytics/common.js +60 -0
- package/dist/es2019/ui/EditorLinkingPlatformAnalytics/index.js +30 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/analytics/create-events-queue.js +48 -0
- package/dist/esm/{pm-plugins/analytics → analytics}/events-from-tr.js +90 -80
- package/dist/esm/analytics/index.js +2 -0
- package/dist/esm/analytics/types.js +17 -0
- package/dist/esm/analytics/utils.js +118 -0
- package/dist/esm/nodeviews/datasource.js +2 -9
- package/dist/esm/plugin.js +7 -4
- package/dist/esm/pm-plugins/actions.js +0 -8
- package/dist/esm/pm-plugins/doc.js +3 -0
- package/dist/esm/pm-plugins/main.js +15 -13
- package/dist/esm/pm-plugins/reducers.js +0 -7
- package/dist/esm/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.js +44 -0
- package/dist/esm/ui/EditorLinkingPlatformAnalytics/LinkEvents.js +125 -0
- package/dist/esm/ui/EditorLinkingPlatformAnalytics/common.js +55 -0
- package/dist/esm/ui/EditorLinkingPlatformAnalytics/index.js +47 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/analytics/create-events-queue.d.ts +21 -0
- package/dist/types/analytics/events-from-tr.d.ts +19 -0
- package/dist/types/analytics/index.d.ts +2 -0
- package/dist/types/analytics/types.d.ts +66 -0
- package/dist/types/analytics/utils.d.ts +22 -0
- package/dist/types/nodeviews/datasource.d.ts +0 -2
- package/dist/types/pm-plugins/actions.d.ts +1 -2
- package/dist/types/pm-plugins/util/state.d.ts +0 -1
- package/dist/types/types.d.ts +4 -34
- package/dist/types/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +6 -0
- package/dist/types/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +6 -0
- package/dist/types/ui/EditorLinkingPlatformAnalytics/common.d.ts +20 -0
- package/dist/types/ui/EditorLinkingPlatformAnalytics/index.d.ts +9 -0
- package/dist/types-ts4.5/analytics/create-events-queue.d.ts +21 -0
- package/dist/types-ts4.5/analytics/events-from-tr.d.ts +19 -0
- package/dist/types-ts4.5/analytics/index.d.ts +2 -0
- package/dist/types-ts4.5/analytics/types.d.ts +66 -0
- package/dist/types-ts4.5/analytics/utils.d.ts +22 -0
- package/dist/types-ts4.5/nodeviews/datasource.d.ts +0 -2
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +1 -2
- package/dist/types-ts4.5/pm-plugins/util/state.d.ts +0 -1
- package/dist/types-ts4.5/types.d.ts +4 -34
- package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/DatasourceEvents.d.ts +6 -0
- package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/LinkEvents.d.ts +6 -0
- package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/common.d.ts +20 -0
- package/dist/types-ts4.5/ui/EditorLinkingPlatformAnalytics/index.d.ts +9 -0
- package/package.json +3 -3
- package/report.api.md +84 -8
- package/tmp/api-report-tmp.d.ts +81 -8
- package/dist/cjs/pm-plugins/analytics/create-analytics-queue.js +0 -48
- package/dist/cjs/pm-plugins/analytics/types.js +0 -5
- package/dist/cjs/pm-plugins/analytics/utils.js +0 -178
- package/dist/cjs/ui/EditorSmartCardEventsNext.js +0 -204
- package/dist/es2019/pm-plugins/analytics/create-analytics-queue.js +0 -38
- package/dist/es2019/pm-plugins/analytics/index.js +0 -2
- package/dist/es2019/pm-plugins/analytics/types.js +0 -1
- package/dist/es2019/pm-plugins/analytics/utils.js +0 -160
- package/dist/es2019/ui/EditorSmartCardEventsNext.js +0 -188
- package/dist/esm/pm-plugins/analytics/create-analytics-queue.js +0 -41
- package/dist/esm/pm-plugins/analytics/index.js +0 -2
- package/dist/esm/pm-plugins/analytics/types.js +0 -1
- package/dist/esm/pm-plugins/analytics/utils.js +0 -160
- package/dist/esm/ui/EditorSmartCardEventsNext.js +0 -192
- package/dist/types/pm-plugins/analytics/create-analytics-queue.d.ts +0 -10
- package/dist/types/pm-plugins/analytics/events-from-tr.d.ts +0 -17
- package/dist/types/pm-plugins/analytics/index.d.ts +0 -2
- package/dist/types/pm-plugins/analytics/types.d.ts +0 -12
- package/dist/types/pm-plugins/analytics/utils.d.ts +0 -32
- package/dist/types/ui/EditorSmartCardEventsNext.d.ts +0 -18
- package/dist/types-ts4.5/pm-plugins/analytics/create-analytics-queue.d.ts +0 -10
- package/dist/types-ts4.5/pm-plugins/analytics/events-from-tr.d.ts +0 -17
- package/dist/types-ts4.5/pm-plugins/analytics/index.d.ts +0 -2
- package/dist/types-ts4.5/pm-plugins/analytics/types.d.ts +0 -12
- package/dist/types-ts4.5/pm-plugins/analytics/utils.d.ts +0 -32
- package/dist/types-ts4.5/ui/EditorSmartCardEventsNext.d.ts +0 -18
|
@@ -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 +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
|
-
var appearance = appearanceForNodeType(link.node.type);
|
|
17
|
-
if (appearance) {
|
|
18
|
-
return appearance;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
return 'url';
|
|
22
|
-
}
|
|
23
|
-
var nodeHasLinkMark = function nodeHasLinkMark(schema, node) {
|
|
24
|
-
if (node.marks) {
|
|
25
|
-
for (var i = 0; i < node.marks.length; i++) {
|
|
26
|
-
var 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 var isLink = function 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
|
-
var links = [];
|
|
53
|
-
node.descendants(function (node, pos) {
|
|
54
|
-
var nodeContext = getLinkNodeContext(doc, pos);
|
|
55
|
-
|
|
56
|
-
// Nodes
|
|
57
|
-
if (isLinkNode(node)) {
|
|
58
|
-
links.push({
|
|
59
|
-
type: 'node',
|
|
60
|
-
pos: pos + offset,
|
|
61
|
-
node: node,
|
|
62
|
-
nodeContext: nodeContext
|
|
63
|
-
});
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
// Marks
|
|
67
|
-
if (node.marks) {
|
|
68
|
-
for (var i = 0; i < node.marks.length; i++) {
|
|
69
|
-
var mark = node.marks[i];
|
|
70
|
-
if (isLinkMark(mark, schema)) {
|
|
71
|
-
links.push({
|
|
72
|
-
type: 'mark',
|
|
73
|
-
pos: pos + offset,
|
|
74
|
-
mark: mark,
|
|
75
|
-
nodeContext: 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 var getLinkNodeContext = function getLinkNodeContext(doc, pos) {
|
|
92
|
-
var $pos = doc.resolve(pos);
|
|
93
|
-
var maxDepth = 3;
|
|
94
|
-
for (var i = 0; i <= maxDepth; i++) {
|
|
95
|
-
var 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 var linkObjectFromNode = function linkObjectFromNode(doc, schema, node, pos) {
|
|
103
|
-
var nodeContext = getLinkNodeContext(doc, pos);
|
|
104
|
-
if (isLinkNode(node)) {
|
|
105
|
-
return {
|
|
106
|
-
type: 'node',
|
|
107
|
-
pos: pos,
|
|
108
|
-
node: node,
|
|
109
|
-
nodeContext: nodeContext
|
|
110
|
-
};
|
|
111
|
-
}
|
|
112
|
-
if (node.marks) {
|
|
113
|
-
for (var i = 0; i < node.marks.length; i++) {
|
|
114
|
-
var mark = node.marks[i];
|
|
115
|
-
if (isLinkMark(mark, schema)) {
|
|
116
|
-
return {
|
|
117
|
-
type: 'mark',
|
|
118
|
-
pos: pos,
|
|
119
|
-
mark: mark,
|
|
120
|
-
nodeContext: nodeContext
|
|
121
|
-
};
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
};
|
|
126
|
-
export var findLinksAtPositions = function findLinksAtPositions(tr, positions) {
|
|
127
|
-
var schema = tr.doc.type.schema;
|
|
128
|
-
var links = [];
|
|
129
|
-
for (var i = 0; i < positions.length; i++) {
|
|
130
|
-
var pos = positions[i];
|
|
131
|
-
var node = tr.doc.nodeAt(pos);
|
|
132
|
-
if (!node) {
|
|
133
|
-
continue;
|
|
134
|
-
}
|
|
135
|
-
var 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 var areSameLinks = function areSameLinks(linksA, linksB) {
|
|
149
|
-
if (linksA.length !== linksB.length) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
for (var i = 0; i < linksA.length; i++) {
|
|
153
|
-
var linkA = linksA[i];
|
|
154
|
-
var linkB = linksB[i];
|
|
155
|
-
if (getLinkUrl(linkA) !== getLinkUrl(linkB) || appearanceForLink(linkA) !== appearanceForLink(linkB)) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
return true;
|
|
160
|
-
};
|