@atlaskit/editor-plugin-card 0.1.0
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/.eslintrc.js +15 -0
- package/CHANGELOG.md +1 -0
- package/LICENSE.md +13 -0
- package/README.md +7 -0
- package/dist/cjs/index.js +12 -0
- package/dist/cjs/messages.js +20 -0
- package/dist/cjs/nodeviews/blockCard.js +164 -0
- package/dist/cjs/nodeviews/datasource.js +173 -0
- package/dist/cjs/nodeviews/embedCard.js +398 -0
- package/dist/cjs/nodeviews/genericCard.js +118 -0
- package/dist/cjs/nodeviews/inlineCard.js +132 -0
- package/dist/cjs/plugin.js +138 -0
- package/dist/cjs/pm-plugins/actions.js +122 -0
- package/dist/cjs/pm-plugins/analytics/create-analytics-queue.js +48 -0
- package/dist/cjs/pm-plugins/analytics/events-from-tr.js +359 -0
- package/dist/cjs/pm-plugins/analytics/index.js +19 -0
- package/dist/cjs/pm-plugins/analytics/types.js +5 -0
- package/dist/cjs/pm-plugins/analytics/utils.js +178 -0
- package/dist/cjs/pm-plugins/doc.js +479 -0
- package/dist/cjs/pm-plugins/keymap.js +64 -0
- package/dist/cjs/pm-plugins/main.js +212 -0
- package/dist/cjs/pm-plugins/mountHyperlink.js +47 -0
- package/dist/cjs/pm-plugins/plugin-key.js +9 -0
- package/dist/cjs/pm-plugins/reducers.js +111 -0
- package/dist/cjs/pm-plugins/shouldReplaceLink.js +35 -0
- package/dist/cjs/pm-plugins/util/resolve.js +59 -0
- package/dist/cjs/pm-plugins/util/state.js +49 -0
- package/dist/cjs/toolbar.js +364 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/ui/DatasourceModal/ModalWithState.js +25 -0
- package/dist/cjs/ui/DatasourceModal/index.js +60 -0
- package/dist/cjs/ui/EditLinkToolbar.js +258 -0
- package/dist/cjs/ui/EditorSmartCardEvents.js +21 -0
- package/dist/cjs/ui/EditorSmartCardEventsNext.js +215 -0
- package/dist/cjs/ui/HyperlinkToolbarAppearance.js +174 -0
- package/dist/cjs/ui/LayoutButton/index.js +121 -0
- package/dist/cjs/ui/LayoutButton/types.js +5 -0
- package/dist/cjs/ui/LayoutButton/utils.js +19 -0
- package/dist/cjs/ui/LinkToolbarAppearance.js +152 -0
- package/dist/cjs/ui/ResizableEmbedCard.js +364 -0
- package/dist/cjs/ui/SmallerEditIcon.js +22 -0
- package/dist/cjs/utils.js +60 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/messages.js +13 -0
- package/dist/es2019/nodeviews/blockCard.js +131 -0
- package/dist/es2019/nodeviews/datasource.js +137 -0
- package/dist/es2019/nodeviews/embedCard.js +370 -0
- package/dist/es2019/nodeviews/genericCard.js +92 -0
- package/dist/es2019/nodeviews/inlineCard.js +113 -0
- package/dist/es2019/plugin.js +129 -0
- package/dist/es2019/pm-plugins/actions.js +57 -0
- package/dist/es2019/pm-plugins/analytics/create-analytics-queue.js +38 -0
- package/dist/es2019/pm-plugins/analytics/events-from-tr.js +339 -0
- package/dist/es2019/pm-plugins/analytics/index.js +2 -0
- package/dist/es2019/pm-plugins/analytics/types.js +1 -0
- package/dist/es2019/pm-plugins/analytics/utils.js +160 -0
- package/dist/es2019/pm-plugins/doc.js +451 -0
- package/dist/es2019/pm-plugins/keymap.js +59 -0
- package/dist/es2019/pm-plugins/main.js +208 -0
- package/dist/es2019/pm-plugins/mountHyperlink.js +37 -0
- package/dist/es2019/pm-plugins/plugin-key.js +2 -0
- package/dist/es2019/pm-plugins/reducers.js +110 -0
- package/dist/es2019/pm-plugins/shouldReplaceLink.js +25 -0
- package/dist/es2019/pm-plugins/util/resolve.js +50 -0
- package/dist/es2019/pm-plugins/util/state.js +26 -0
- package/dist/es2019/toolbar.js +359 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/ui/DatasourceModal/ModalWithState.js +19 -0
- package/dist/es2019/ui/DatasourceModal/index.js +48 -0
- package/dist/es2019/ui/EditLinkToolbar.js +226 -0
- package/dist/es2019/ui/EditorSmartCardEvents.js +15 -0
- package/dist/es2019/ui/EditorSmartCardEventsNext.js +199 -0
- package/dist/es2019/ui/HyperlinkToolbarAppearance.js +86 -0
- package/dist/es2019/ui/LayoutButton/index.js +114 -0
- package/dist/es2019/ui/LayoutButton/types.js +1 -0
- package/dist/es2019/ui/LayoutButton/utils.js +15 -0
- package/dist/es2019/ui/LinkToolbarAppearance.js +118 -0
- package/dist/es2019/ui/ResizableEmbedCard.js +335 -0
- package/dist/es2019/ui/SmallerEditIcon.js +14 -0
- package/dist/es2019/utils.js +46 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/index.js +1 -0
- package/dist/esm/messages.js +13 -0
- package/dist/esm/nodeviews/blockCard.js +156 -0
- package/dist/esm/nodeviews/datasource.js +165 -0
- package/dist/esm/nodeviews/embedCard.js +389 -0
- package/dist/esm/nodeviews/genericCard.js +111 -0
- package/dist/esm/nodeviews/inlineCard.js +124 -0
- package/dist/esm/plugin.js +130 -0
- package/dist/esm/pm-plugins/actions.js +102 -0
- package/dist/esm/pm-plugins/analytics/create-analytics-queue.js +41 -0
- package/dist/esm/pm-plugins/analytics/events-from-tr.js +350 -0
- package/dist/esm/pm-plugins/analytics/index.js +2 -0
- package/dist/esm/pm-plugins/analytics/types.js +1 -0
- package/dist/esm/pm-plugins/analytics/utils.js +160 -0
- package/dist/esm/pm-plugins/doc.js +460 -0
- package/dist/esm/pm-plugins/keymap.js +58 -0
- package/dist/esm/pm-plugins/main.js +199 -0
- package/dist/esm/pm-plugins/mountHyperlink.js +39 -0
- package/dist/esm/pm-plugins/plugin-key.js +2 -0
- package/dist/esm/pm-plugins/reducers.js +103 -0
- package/dist/esm/pm-plugins/shouldReplaceLink.js +29 -0
- package/dist/esm/pm-plugins/util/resolve.js +52 -0
- package/dist/esm/pm-plugins/util/state.js +40 -0
- package/dist/esm/toolbar.js +350 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/ui/DatasourceModal/ModalWithState.js +17 -0
- package/dist/esm/ui/DatasourceModal/index.js +49 -0
- package/dist/esm/ui/EditLinkToolbar.js +244 -0
- package/dist/esm/ui/EditorSmartCardEvents.js +14 -0
- package/dist/esm/ui/EditorSmartCardEventsNext.js +203 -0
- package/dist/esm/ui/HyperlinkToolbarAppearance.js +163 -0
- package/dist/esm/ui/LayoutButton/index.js +110 -0
- package/dist/esm/ui/LayoutButton/types.js +1 -0
- package/dist/esm/ui/LayoutButton/utils.js +12 -0
- package/dist/esm/ui/LinkToolbarAppearance.js +141 -0
- package/dist/esm/ui/ResizableEmbedCard.js +358 -0
- package/dist/esm/ui/SmallerEditIcon.js +14 -0
- package/dist/esm/utils.js +48 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/messages.d.ts +12 -0
- package/dist/types/nodeviews/blockCard.d.ts +26 -0
- package/dist/types/nodeviews/datasource.d.ts +42 -0
- package/dist/types/nodeviews/embedCard.d.ts +46 -0
- package/dist/types/nodeviews/genericCard.d.ts +37 -0
- package/dist/types/nodeviews/inlineCard.d.ts +23 -0
- package/dist/types/plugin.d.ts +24 -0
- package/dist/types/pm-plugins/actions.d.ts +23 -0
- package/dist/types/pm-plugins/analytics/create-analytics-queue.d.ts +10 -0
- package/dist/types/pm-plugins/analytics/events-from-tr.d.ts +17 -0
- package/dist/types/pm-plugins/analytics/index.d.ts +2 -0
- package/dist/types/pm-plugins/analytics/types.d.ts +12 -0
- package/dist/types/pm-plugins/analytics/utils.d.ts +32 -0
- package/dist/types/pm-plugins/doc.d.ts +22 -0
- package/dist/types/pm-plugins/keymap.d.ts +3 -0
- package/dist/types/pm-plugins/main.d.ts +6 -0
- package/dist/types/pm-plugins/mountHyperlink.d.ts +5 -0
- package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types/pm-plugins/reducers.d.ts +3 -0
- package/dist/types/pm-plugins/shouldReplaceLink.d.ts +2 -0
- package/dist/types/pm-plugins/util/resolve.d.ts +8 -0
- package/dist/types/pm-plugins/util/state.d.ts +31 -0
- package/dist/types/toolbar.d.ts +9 -0
- package/dist/types/types.d.ts +163 -0
- package/dist/types/ui/DatasourceModal/ModalWithState.d.ts +9 -0
- package/dist/types/ui/DatasourceModal/index.d.ts +11 -0
- package/dist/types/ui/EditLinkToolbar.d.ts +47 -0
- package/dist/types/ui/EditorSmartCardEvents.d.ts +5 -0
- package/dist/types/ui/EditorSmartCardEventsNext.d.ts +18 -0
- package/dist/types/ui/HyperlinkToolbarAppearance.d.ts +32 -0
- package/dist/types/ui/LayoutButton/index.d.ts +9 -0
- package/dist/types/ui/LayoutButton/types.d.ts +19 -0
- package/dist/types/ui/LayoutButton/utils.d.ts +5 -0
- package/dist/types/ui/LinkToolbarAppearance.d.ts +29 -0
- package/dist/types/ui/ResizableEmbedCard.d.ts +61 -0
- package/dist/types/ui/SmallerEditIcon.d.ts +3 -0
- package/dist/types/utils.d.ts +19 -0
- package/dist/types-ts4.5/index.d.ts +2 -0
- package/dist/types-ts4.5/messages.d.ts +12 -0
- package/dist/types-ts4.5/nodeviews/blockCard.d.ts +26 -0
- package/dist/types-ts4.5/nodeviews/datasource.d.ts +42 -0
- package/dist/types-ts4.5/nodeviews/embedCard.d.ts +46 -0
- package/dist/types-ts4.5/nodeviews/genericCard.d.ts +37 -0
- package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +23 -0
- package/dist/types-ts4.5/plugin.d.ts +24 -0
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +23 -0
- package/dist/types-ts4.5/pm-plugins/analytics/create-analytics-queue.d.ts +10 -0
- package/dist/types-ts4.5/pm-plugins/analytics/events-from-tr.d.ts +17 -0
- package/dist/types-ts4.5/pm-plugins/analytics/index.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/analytics/types.d.ts +12 -0
- package/dist/types-ts4.5/pm-plugins/analytics/utils.d.ts +32 -0
- package/dist/types-ts4.5/pm-plugins/doc.d.ts +22 -0
- package/dist/types-ts4.5/pm-plugins/keymap.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
- package/dist/types-ts4.5/pm-plugins/mountHyperlink.d.ts +5 -0
- package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/reducers.d.ts +3 -0
- package/dist/types-ts4.5/pm-plugins/shouldReplaceLink.d.ts +2 -0
- package/dist/types-ts4.5/pm-plugins/util/resolve.d.ts +8 -0
- package/dist/types-ts4.5/pm-plugins/util/state.d.ts +31 -0
- package/dist/types-ts4.5/toolbar.d.ts +9 -0
- package/dist/types-ts4.5/types.d.ts +163 -0
- package/dist/types-ts4.5/ui/DatasourceModal/ModalWithState.d.ts +9 -0
- package/dist/types-ts4.5/ui/DatasourceModal/index.d.ts +11 -0
- package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +47 -0
- package/dist/types-ts4.5/ui/EditorSmartCardEvents.d.ts +5 -0
- package/dist/types-ts4.5/ui/EditorSmartCardEventsNext.d.ts +18 -0
- package/dist/types-ts4.5/ui/HyperlinkToolbarAppearance.d.ts +32 -0
- package/dist/types-ts4.5/ui/LayoutButton/index.d.ts +9 -0
- package/dist/types-ts4.5/ui/LayoutButton/types.d.ts +19 -0
- package/dist/types-ts4.5/ui/LayoutButton/utils.d.ts +5 -0
- package/dist/types-ts4.5/ui/LinkToolbarAppearance.d.ts +29 -0
- package/dist/types-ts4.5/ui/ResizableEmbedCard.d.ts +61 -0
- package/dist/types-ts4.5/ui/SmallerEditIcon.d.ts +3 -0
- package/dist/types-ts4.5/utils.d.ts +19 -0
- package/package.json +126 -0
- package/report.api.md +146 -0
- package/tmp/api-report-tmp.d.ts +117 -0
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import React, { useEffect, useMemo } from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { AnalyticsContext, UIAnalyticsEvent } from '@atlaskit/analytics-next';
|
|
5
|
+
import { ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
+
import { getAnalyticsEditorAppearance } from '@atlaskit/editor-common/utils';
|
|
7
|
+
import { useSmartLinkLifecycleAnalytics } from '@atlaskit/link-analytics';
|
|
8
|
+
import { registerSmartCardEventsNext } from '../pm-plugins/actions';
|
|
9
|
+
import { getPluginState } from '../pm-plugins/util/state';
|
|
10
|
+
/**
|
|
11
|
+
* If the metadata is for a history event,
|
|
12
|
+
* returns undo/redo instead of instead of what fn(metadata) would have otherwise
|
|
13
|
+
* returned
|
|
14
|
+
*/
|
|
15
|
+
const withHistoryMethod = fn => {
|
|
16
|
+
return metadata => {
|
|
17
|
+
const {
|
|
18
|
+
isUndo,
|
|
19
|
+
isRedo
|
|
20
|
+
} = metadata;
|
|
21
|
+
if (isUndo) {
|
|
22
|
+
return 'undo';
|
|
23
|
+
}
|
|
24
|
+
if (isRedo) {
|
|
25
|
+
return 'redo';
|
|
26
|
+
}
|
|
27
|
+
return fn(metadata);
|
|
28
|
+
};
|
|
29
|
+
};
|
|
30
|
+
const getMethod = withHistoryMethod(({
|
|
31
|
+
inputMethod
|
|
32
|
+
}) => {
|
|
33
|
+
switch (inputMethod) {
|
|
34
|
+
case INPUT_METHOD.CLIPBOARD:
|
|
35
|
+
return 'editor_paste';
|
|
36
|
+
case INPUT_METHOD.FLOATING_TB:
|
|
37
|
+
return 'editor_floatingToolbar';
|
|
38
|
+
case INPUT_METHOD.AUTO_DETECT:
|
|
39
|
+
case INPUT_METHOD.FORMATTING:
|
|
40
|
+
return 'editor_type';
|
|
41
|
+
default:
|
|
42
|
+
return 'unknown';
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const getUpdateType = withHistoryMethod(({
|
|
46
|
+
action
|
|
47
|
+
}) => {
|
|
48
|
+
switch (action) {
|
|
49
|
+
case ACTION.CHANGED_TYPE:
|
|
50
|
+
return 'display_update';
|
|
51
|
+
case ACTION.UPDATED:
|
|
52
|
+
return 'link_update';
|
|
53
|
+
default:
|
|
54
|
+
return 'unknown';
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
const getDeleteType = withHistoryMethod(({
|
|
58
|
+
action
|
|
59
|
+
}) => {
|
|
60
|
+
if (action === ACTION.UNLINK) {
|
|
61
|
+
return 'unlink';
|
|
62
|
+
}
|
|
63
|
+
return 'delete';
|
|
64
|
+
});
|
|
65
|
+
const getSourceEventFromMetadata = metadata => {
|
|
66
|
+
return metadata.sourceEvent instanceof UIAnalyticsEvent ? metadata.sourceEvent : null;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Set display category as `link` if not displaying the link as a smart card
|
|
71
|
+
*/
|
|
72
|
+
const displayCategoryFromDisplay = display => {
|
|
73
|
+
if (display === 'url') {
|
|
74
|
+
return 'link';
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Binds the @atlaskit/link-analytics callbacks
|
|
80
|
+
* to the editor card plugin state events callbacks interfaces
|
|
81
|
+
*/
|
|
82
|
+
export const EventsBinding = ({
|
|
83
|
+
editorView
|
|
84
|
+
}) => {
|
|
85
|
+
/**
|
|
86
|
+
* These callbacks internally use window.requestIdleCallback/requestAnimationFrame
|
|
87
|
+
* to defer any heavy operations involving network
|
|
88
|
+
*
|
|
89
|
+
* The callbacks themselves should not be deferred, they should be called syncronously the moment
|
|
90
|
+
* the events take place.
|
|
91
|
+
*/
|
|
92
|
+
const {
|
|
93
|
+
linkCreated,
|
|
94
|
+
linkUpdated,
|
|
95
|
+
linkDeleted
|
|
96
|
+
} = useSmartLinkLifecycleAnalytics();
|
|
97
|
+
const events = useMemo(() => {
|
|
98
|
+
return {
|
|
99
|
+
created: metadata => {
|
|
100
|
+
const {
|
|
101
|
+
url,
|
|
102
|
+
display,
|
|
103
|
+
nodeContext
|
|
104
|
+
} = metadata;
|
|
105
|
+
const displayCategory = displayCategoryFromDisplay(display);
|
|
106
|
+
const sourceEvent = getSourceEventFromMetadata(metadata);
|
|
107
|
+
const creationMethod = getMethod(metadata);
|
|
108
|
+
linkCreated({
|
|
109
|
+
url,
|
|
110
|
+
displayCategory
|
|
111
|
+
}, sourceEvent, {
|
|
112
|
+
display,
|
|
113
|
+
nodeContext,
|
|
114
|
+
creationMethod
|
|
115
|
+
});
|
|
116
|
+
},
|
|
117
|
+
updated: metadata => {
|
|
118
|
+
const {
|
|
119
|
+
url,
|
|
120
|
+
display,
|
|
121
|
+
previousDisplay,
|
|
122
|
+
nodeContext
|
|
123
|
+
} = metadata;
|
|
124
|
+
const displayCategory = displayCategoryFromDisplay(display);
|
|
125
|
+
const sourceEvent = getSourceEventFromMetadata(metadata);
|
|
126
|
+
const updateMethod = getMethod(metadata);
|
|
127
|
+
const updateType = getUpdateType(metadata);
|
|
128
|
+
linkUpdated({
|
|
129
|
+
url,
|
|
130
|
+
displayCategory
|
|
131
|
+
}, sourceEvent, {
|
|
132
|
+
display,
|
|
133
|
+
previousDisplay,
|
|
134
|
+
nodeContext,
|
|
135
|
+
updateMethod,
|
|
136
|
+
updateType
|
|
137
|
+
});
|
|
138
|
+
},
|
|
139
|
+
deleted: metadata => {
|
|
140
|
+
const {
|
|
141
|
+
url,
|
|
142
|
+
display,
|
|
143
|
+
nodeContext
|
|
144
|
+
} = metadata;
|
|
145
|
+
const displayCategory = displayCategoryFromDisplay(display);
|
|
146
|
+
const sourceEvent = getSourceEventFromMetadata(metadata);
|
|
147
|
+
const deleteMethod = getMethod(metadata);
|
|
148
|
+
const deleteType = getDeleteType(metadata);
|
|
149
|
+
linkDeleted({
|
|
150
|
+
url,
|
|
151
|
+
displayCategory
|
|
152
|
+
}, sourceEvent, {
|
|
153
|
+
display,
|
|
154
|
+
nodeContext,
|
|
155
|
+
deleteMethod,
|
|
156
|
+
deleteType
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
}, [linkCreated, linkUpdated, linkDeleted]);
|
|
161
|
+
useEffect(() => {
|
|
162
|
+
editorView.dispatch(registerSmartCardEventsNext(events)(editorView.state.tr));
|
|
163
|
+
}, [events, editorView]);
|
|
164
|
+
return null;
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
168
|
+
export class EditorSmartCardEventsNext extends React.PureComponent {
|
|
169
|
+
render() {
|
|
170
|
+
var _getPluginState;
|
|
171
|
+
const cardContext = this.context.contextAdapter.card;
|
|
172
|
+
|
|
173
|
+
/**
|
|
174
|
+
* The analytics hook needs to be able to communicate with the card context
|
|
175
|
+
* If we can't access it, don't mount the event bindings
|
|
176
|
+
* This effectively entirely disables all tracking behaviour
|
|
177
|
+
*/
|
|
178
|
+
if (!cardContext) {
|
|
179
|
+
return null;
|
|
180
|
+
}
|
|
181
|
+
const editorAppearance = (_getPluginState = getPluginState(this.props.editorView.state)) === null || _getPluginState === void 0 ? void 0 : _getPluginState.editorAppearance;
|
|
182
|
+
const analyticsEditorAppearance = getAnalyticsEditorAppearance(editorAppearance);
|
|
183
|
+
const analyticsData = {
|
|
184
|
+
attributes: {
|
|
185
|
+
location: analyticsEditorAppearance
|
|
186
|
+
},
|
|
187
|
+
// Below is added for the future implementation of Linking Platform namespaced analytic context
|
|
188
|
+
location: analyticsEditorAppearance
|
|
189
|
+
};
|
|
190
|
+
return /*#__PURE__*/React.createElement(cardContext.Provider, {
|
|
191
|
+
value: cardContext.value
|
|
192
|
+
}, /*#__PURE__*/React.createElement(AnalyticsContext, {
|
|
193
|
+
data: analyticsData
|
|
194
|
+
}, /*#__PURE__*/React.createElement(EventsBinding, this.props)));
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
_defineProperty(EditorSmartCardEventsNext, "contextTypes", {
|
|
198
|
+
contextAdapter: PropTypes.object
|
|
199
|
+
});
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import React, { Component } from 'react';
|
|
3
|
+
import { LinkToolbarAppearance } from './LinkToolbarAppearance';
|
|
4
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
5
|
+
export class HyperlinkToolbarAppearance extends Component {
|
|
6
|
+
constructor(...args) {
|
|
7
|
+
super(...args);
|
|
8
|
+
_defineProperty(this, "state", {
|
|
9
|
+
supportedUrlsMap: new Map()
|
|
10
|
+
});
|
|
11
|
+
_defineProperty(this, "getProvider", async () => {
|
|
12
|
+
if (this.cardProvider) {
|
|
13
|
+
return this.cardProvider;
|
|
14
|
+
}
|
|
15
|
+
return new Promise(resolve => {
|
|
16
|
+
const {
|
|
17
|
+
providerFactory
|
|
18
|
+
} = this.props;
|
|
19
|
+
providerFactory.subscribe('cardProvider', async (_, cardProvider) => {
|
|
20
|
+
if (!cardProvider) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
this.cardProvider = await cardProvider;
|
|
24
|
+
resolve(this.cardProvider);
|
|
25
|
+
});
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
_defineProperty(this, "resolveUrl", async url => {
|
|
29
|
+
const {
|
|
30
|
+
supportedUrlsMap
|
|
31
|
+
} = this.state;
|
|
32
|
+
if (supportedUrlsMap.has(url)) {
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
let isUrlSupported = false;
|
|
36
|
+
try {
|
|
37
|
+
const provider = await this.getProvider();
|
|
38
|
+
isUrlSupported = await provider.findPattern(url);
|
|
39
|
+
} catch (error) {
|
|
40
|
+
isUrlSupported = false;
|
|
41
|
+
}
|
|
42
|
+
supportedUrlsMap.set(url, isUrlSupported);
|
|
43
|
+
this.setState({
|
|
44
|
+
supportedUrlsMap
|
|
45
|
+
});
|
|
46
|
+
});
|
|
47
|
+
_defineProperty(this, "componentDidMount", () => this.resolveUrl(this.props.url));
|
|
48
|
+
}
|
|
49
|
+
// needed so we display the right state on the Toolbar while the same Toolbar
|
|
50
|
+
// instance is visible and we click other link
|
|
51
|
+
UNSAFE_componentWillReceiveProps(nextProps) {
|
|
52
|
+
if (nextProps.url !== this.props.url) {
|
|
53
|
+
this.resolveUrl(nextProps.url);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
render() {
|
|
57
|
+
const {
|
|
58
|
+
url,
|
|
59
|
+
intl,
|
|
60
|
+
editorView,
|
|
61
|
+
editorState,
|
|
62
|
+
cardOptions,
|
|
63
|
+
platform,
|
|
64
|
+
editorAnalyticsApi,
|
|
65
|
+
cardActions
|
|
66
|
+
} = this.props;
|
|
67
|
+
const {
|
|
68
|
+
supportedUrlsMap
|
|
69
|
+
} = this.state;
|
|
70
|
+
if (!supportedUrlsMap.get(url)) {
|
|
71
|
+
return null;
|
|
72
|
+
}
|
|
73
|
+
return /*#__PURE__*/React.createElement(LinkToolbarAppearance, {
|
|
74
|
+
key: "link-appearance",
|
|
75
|
+
url: url,
|
|
76
|
+
intl: intl,
|
|
77
|
+
editorView: editorView,
|
|
78
|
+
editorState: editorState,
|
|
79
|
+
allowEmbeds: cardOptions === null || cardOptions === void 0 ? void 0 : cardOptions.allowEmbeds,
|
|
80
|
+
allowBlockCards: cardOptions === null || cardOptions === void 0 ? void 0 : cardOptions.allowBlockCards,
|
|
81
|
+
platform: platform,
|
|
82
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
83
|
+
cardActions: cardActions
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React, { useCallback, useMemo } from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/react';
|
|
4
|
+
import { injectIntl } from 'react-intl-next';
|
|
5
|
+
import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
|
|
6
|
+
import { Popup } from '@atlaskit/editor-common/ui';
|
|
7
|
+
import { ToolbarButton } from '@atlaskit/editor-common/ui-menu';
|
|
8
|
+
import { getNextBreakoutMode, getTitle } from '@atlaskit/editor-common/utils';
|
|
9
|
+
import CollapseIcon from '@atlaskit/icon/glyph/editor/collapse';
|
|
10
|
+
import ExpandIcon from '@atlaskit/icon/glyph/editor/expand';
|
|
11
|
+
import { B300, N20A, N300 } from '@atlaskit/theme/colors';
|
|
12
|
+
import { setCardLayout } from '../../pm-plugins/actions';
|
|
13
|
+
import { getDatasource } from './utils';
|
|
14
|
+
const toolbarButtonWrapperStyles = css({
|
|
15
|
+
background: `${`var(--ds-background-neutral, ${N20A})`}`,
|
|
16
|
+
color: `${`var(--ds-icon, ${N300})`}`,
|
|
17
|
+
':hover': {
|
|
18
|
+
background: `${`var(--ds-background-neutral-hovered, ${B300})`}`,
|
|
19
|
+
color: `${"var(--ds-icon, white)"} !important`
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
export const LayoutButton = ({
|
|
23
|
+
onLayoutChange,
|
|
24
|
+
layout = 'center',
|
|
25
|
+
intl: {
|
|
26
|
+
formatMessage
|
|
27
|
+
},
|
|
28
|
+
mountPoint,
|
|
29
|
+
boundariesElement,
|
|
30
|
+
scrollableElement,
|
|
31
|
+
targetElement,
|
|
32
|
+
testId = 'datasource-table-layout-button'
|
|
33
|
+
}) => {
|
|
34
|
+
const handleClick = useCallback(() => {
|
|
35
|
+
onLayoutChange && onLayoutChange(getNextBreakoutMode(layout));
|
|
36
|
+
}, [layout, onLayoutChange]);
|
|
37
|
+
const title = useMemo(() => {
|
|
38
|
+
return formatMessage(getTitle(layout));
|
|
39
|
+
}, [formatMessage, layout]);
|
|
40
|
+
if (!targetElement) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
return jsx(Popup, {
|
|
44
|
+
mountTo: mountPoint,
|
|
45
|
+
boundariesElement: boundariesElement,
|
|
46
|
+
scrollableElement: scrollableElement,
|
|
47
|
+
target: targetElement,
|
|
48
|
+
alignY: "start",
|
|
49
|
+
alignX: "end",
|
|
50
|
+
forcePlacement: true,
|
|
51
|
+
stick: true,
|
|
52
|
+
ariaLabel: title
|
|
53
|
+
}, jsx(ToolbarButton, {
|
|
54
|
+
testId: testId,
|
|
55
|
+
css: toolbarButtonWrapperStyles,
|
|
56
|
+
title: title,
|
|
57
|
+
onClick: handleClick,
|
|
58
|
+
iconBefore: layout === 'full-width' ? jsx(CollapseIcon, {
|
|
59
|
+
label: title
|
|
60
|
+
}) : jsx(ExpandIcon, {
|
|
61
|
+
label: title
|
|
62
|
+
})
|
|
63
|
+
}));
|
|
64
|
+
};
|
|
65
|
+
const LayoutButtonWrapper = ({
|
|
66
|
+
editorView,
|
|
67
|
+
mountPoint,
|
|
68
|
+
scrollableElement,
|
|
69
|
+
boundariesElement,
|
|
70
|
+
intl,
|
|
71
|
+
api
|
|
72
|
+
}) => {
|
|
73
|
+
var _node$attrs, _node$attrs2;
|
|
74
|
+
const {
|
|
75
|
+
cardState
|
|
76
|
+
} = useSharedPluginState(api, ['card']);
|
|
77
|
+
const {
|
|
78
|
+
node,
|
|
79
|
+
pos
|
|
80
|
+
} = getDatasource(editorView);
|
|
81
|
+
const {
|
|
82
|
+
datasourceTableRef,
|
|
83
|
+
layout = (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.layout) || 'center'
|
|
84
|
+
} = cardState !== null && cardState !== void 0 ? cardState : {};
|
|
85
|
+
const isDatasource = !!(node !== null && node !== void 0 && (_node$attrs2 = node.attrs) !== null && _node$attrs2 !== void 0 && _node$attrs2.datasource);
|
|
86
|
+
const onLayoutChange = layout => {
|
|
87
|
+
if (pos === undefined) {
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
const {
|
|
91
|
+
state,
|
|
92
|
+
dispatch
|
|
93
|
+
} = editorView;
|
|
94
|
+
const tr = state.tr.setNodeMarkup(pos, undefined, {
|
|
95
|
+
...(node === null || node === void 0 ? void 0 : node.attrs),
|
|
96
|
+
layout
|
|
97
|
+
});
|
|
98
|
+
tr.setMeta('scrollIntoView', false);
|
|
99
|
+
dispatch(setCardLayout(layout)(tr));
|
|
100
|
+
};
|
|
101
|
+
if (!isDatasource) {
|
|
102
|
+
return null;
|
|
103
|
+
}
|
|
104
|
+
return jsx(LayoutButton, {
|
|
105
|
+
mountPoint: mountPoint,
|
|
106
|
+
scrollableElement: scrollableElement,
|
|
107
|
+
boundariesElement: boundariesElement,
|
|
108
|
+
targetElement: datasourceTableRef,
|
|
109
|
+
layout: layout,
|
|
110
|
+
onLayoutChange: onLayoutChange,
|
|
111
|
+
intl: intl
|
|
112
|
+
});
|
|
113
|
+
};
|
|
114
|
+
export default injectIntl(LayoutButtonWrapper);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { findSelectedNodeOfType } from 'prosemirror-utils';
|
|
2
|
+
export const getDatasource = editorView => {
|
|
3
|
+
var _findSelectedNodeOfTy;
|
|
4
|
+
const {
|
|
5
|
+
selection,
|
|
6
|
+
schema
|
|
7
|
+
} = editorView.state;
|
|
8
|
+
const {
|
|
9
|
+
blockCard
|
|
10
|
+
} = schema.nodes;
|
|
11
|
+
return (_findSelectedNodeOfTy = findSelectedNodeOfType([blockCard])(selection)) !== null && _findSelectedNodeOfTy !== void 0 ? _findSelectedNodeOfTy : {
|
|
12
|
+
node: undefined,
|
|
13
|
+
pos: undefined
|
|
14
|
+
};
|
|
15
|
+
};
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import PropTypes from 'prop-types';
|
|
4
|
+
import { Fragment } from 'prosemirror-model';
|
|
5
|
+
import { ACTION, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
|
|
6
|
+
import { commandWithMetadata, getButtonGroupOption, LinkToolbarButtonGroup } from '@atlaskit/editor-common/card';
|
|
7
|
+
import nodeNames, { cardMessages as messages } from '@atlaskit/editor-common/messages';
|
|
8
|
+
import { isSupportedInParent } from '@atlaskit/editor-common/utils';
|
|
9
|
+
// eslint-disable-next-line @repo/internal/react/no-class-components
|
|
10
|
+
export class LinkToolbarAppearance extends React.Component {
|
|
11
|
+
constructor(...args) {
|
|
12
|
+
super(...args);
|
|
13
|
+
_defineProperty(this, "renderDropdown", (view, cardContext) => {
|
|
14
|
+
var _cardActions$setSelec, _cardActions$setSelec2, _cardActions$changeSe, _cardActions$setSelec3;
|
|
15
|
+
const {
|
|
16
|
+
url,
|
|
17
|
+
intl,
|
|
18
|
+
currentAppearance,
|
|
19
|
+
editorState,
|
|
20
|
+
allowEmbeds,
|
|
21
|
+
allowBlockCards = true,
|
|
22
|
+
platform,
|
|
23
|
+
editorAnalyticsApi,
|
|
24
|
+
cardActions
|
|
25
|
+
} = this.props;
|
|
26
|
+
const preview = allowEmbeds && cardContext && url && cardContext.extractors.getPreview(url, platform);
|
|
27
|
+
const defaultCommand = () => false;
|
|
28
|
+
if (url) {
|
|
29
|
+
var _cardContext$store, _urlState$error;
|
|
30
|
+
const urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
31
|
+
if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const isBlockCardLinkSupportedInParent = allowBlockCards ? isSupportedInParent(editorState, Fragment.from(editorState.schema.nodes.blockCard.createChecked({})), currentAppearance) : false;
|
|
36
|
+
const isEmbedCardLinkSupportedInParent = allowEmbeds ? isSupportedInParent(editorState, Fragment.from(editorState.schema.nodes.embedCard.createChecked({})), currentAppearance) : false;
|
|
37
|
+
const embedOption = allowEmbeds && preview && {
|
|
38
|
+
appearance: 'embed',
|
|
39
|
+
title: intl.formatMessage(messages.embed),
|
|
40
|
+
onClick: (_cardActions$setSelec = cardActions === null || cardActions === void 0 ? void 0 : cardActions.setSelectedCardAppearance('embed', editorAnalyticsApi)) !== null && _cardActions$setSelec !== void 0 ? _cardActions$setSelec : defaultCommand,
|
|
41
|
+
selected: currentAppearance === 'embed',
|
|
42
|
+
hidden: false,
|
|
43
|
+
testId: 'embed-appearance',
|
|
44
|
+
disabled: !isEmbedCardLinkSupportedInParent,
|
|
45
|
+
tooltip: isEmbedCardLinkSupportedInParent ? undefined : getUnavailableMessage(editorState, intl)
|
|
46
|
+
};
|
|
47
|
+
const blockCardOption = allowBlockCards && {
|
|
48
|
+
appearance: 'block',
|
|
49
|
+
title: intl.formatMessage(messages.block),
|
|
50
|
+
onClick: (_cardActions$setSelec2 = cardActions === null || cardActions === void 0 ? void 0 : cardActions.setSelectedCardAppearance('block', editorAnalyticsApi)) !== null && _cardActions$setSelec2 !== void 0 ? _cardActions$setSelec2 : defaultCommand,
|
|
51
|
+
selected: currentAppearance === 'block',
|
|
52
|
+
testId: 'block-appearance',
|
|
53
|
+
disabled: !isBlockCardLinkSupportedInParent,
|
|
54
|
+
tooltip: isBlockCardLinkSupportedInParent ? undefined : getUnavailableMessage(editorState, intl)
|
|
55
|
+
};
|
|
56
|
+
const options = [{
|
|
57
|
+
title: intl.formatMessage(messages.url),
|
|
58
|
+
onClick: commandWithMetadata((_cardActions$changeSe = cardActions === null || cardActions === void 0 ? void 0 : cardActions.changeSelectedCardToLink(url, url, true, undefined, undefined, editorAnalyticsApi)) !== null && _cardActions$changeSe !== void 0 ? _cardActions$changeSe : defaultCommand, {
|
|
59
|
+
action: ACTION.CHANGED_TYPE
|
|
60
|
+
}),
|
|
61
|
+
selected: !currentAppearance,
|
|
62
|
+
testId: 'url-appearance'
|
|
63
|
+
}, {
|
|
64
|
+
appearance: 'inline',
|
|
65
|
+
title: intl.formatMessage(messages.inline),
|
|
66
|
+
onClick: (_cardActions$setSelec3 = cardActions === null || cardActions === void 0 ? void 0 : cardActions.setSelectedCardAppearance('inline', editorAnalyticsApi)) !== null && _cardActions$setSelec3 !== void 0 ? _cardActions$setSelec3 : defaultCommand,
|
|
67
|
+
selected: currentAppearance === 'inline',
|
|
68
|
+
testId: 'inline-appearance'
|
|
69
|
+
}];
|
|
70
|
+
const dispatchCommand = fn => {
|
|
71
|
+
fn && fn(editorState, view && view.dispatch);
|
|
72
|
+
// Refocus the view to ensure the editor has focus
|
|
73
|
+
if (view && !view.hasFocus()) {
|
|
74
|
+
view.focus();
|
|
75
|
+
}
|
|
76
|
+
};
|
|
77
|
+
if (blockCardOption) {
|
|
78
|
+
options.push(blockCardOption);
|
|
79
|
+
}
|
|
80
|
+
if (embedOption) {
|
|
81
|
+
options.push(embedOption);
|
|
82
|
+
}
|
|
83
|
+
return /*#__PURE__*/React.createElement(LinkToolbarButtonGroup, {
|
|
84
|
+
key: "link-toolbar-button-group",
|
|
85
|
+
options: options.map(option => getButtonGroupOption(intl, dispatchCommand, {
|
|
86
|
+
...option,
|
|
87
|
+
onClick: commandWithMetadata(option.onClick, {
|
|
88
|
+
inputMethod: INPUT_METHOD.FLOATING_TB
|
|
89
|
+
})
|
|
90
|
+
}))
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
render() {
|
|
95
|
+
const cardContext = this.context.contextAdapter ? this.context.contextAdapter.card : undefined;
|
|
96
|
+
const {
|
|
97
|
+
editorView
|
|
98
|
+
} = this.props;
|
|
99
|
+
return this.renderDropdown(editorView, cardContext && cardContext.value);
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
_defineProperty(LinkToolbarAppearance, "contextTypes", {
|
|
103
|
+
contextAdapter: PropTypes.object
|
|
104
|
+
});
|
|
105
|
+
const getUnavailableMessage = (state, intl) => {
|
|
106
|
+
try {
|
|
107
|
+
const parentNode = state.selection.$from.node(1);
|
|
108
|
+
const parentName = intl.formatMessage(nodeNames[parentNode.type.name]);
|
|
109
|
+
const tooltip = intl.formatMessage(messages.displayOptionUnavailableInParentNode, {
|
|
110
|
+
node: parentName
|
|
111
|
+
});
|
|
112
|
+
return tooltip;
|
|
113
|
+
} catch (e) {
|
|
114
|
+
return intl.formatMessage(messages.displayOptionUnavailableInParentNode, {
|
|
115
|
+
node: intl.formatMessage(nodeNames.defaultBlockNode)
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
};
|