@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.
Files changed (200) hide show
  1. package/.eslintrc.js +15 -0
  2. package/CHANGELOG.md +1 -0
  3. package/LICENSE.md +13 -0
  4. package/README.md +7 -0
  5. package/dist/cjs/index.js +12 -0
  6. package/dist/cjs/messages.js +20 -0
  7. package/dist/cjs/nodeviews/blockCard.js +164 -0
  8. package/dist/cjs/nodeviews/datasource.js +173 -0
  9. package/dist/cjs/nodeviews/embedCard.js +398 -0
  10. package/dist/cjs/nodeviews/genericCard.js +118 -0
  11. package/dist/cjs/nodeviews/inlineCard.js +132 -0
  12. package/dist/cjs/plugin.js +138 -0
  13. package/dist/cjs/pm-plugins/actions.js +122 -0
  14. package/dist/cjs/pm-plugins/analytics/create-analytics-queue.js +48 -0
  15. package/dist/cjs/pm-plugins/analytics/events-from-tr.js +359 -0
  16. package/dist/cjs/pm-plugins/analytics/index.js +19 -0
  17. package/dist/cjs/pm-plugins/analytics/types.js +5 -0
  18. package/dist/cjs/pm-plugins/analytics/utils.js +178 -0
  19. package/dist/cjs/pm-plugins/doc.js +479 -0
  20. package/dist/cjs/pm-plugins/keymap.js +64 -0
  21. package/dist/cjs/pm-plugins/main.js +212 -0
  22. package/dist/cjs/pm-plugins/mountHyperlink.js +47 -0
  23. package/dist/cjs/pm-plugins/plugin-key.js +9 -0
  24. package/dist/cjs/pm-plugins/reducers.js +111 -0
  25. package/dist/cjs/pm-plugins/shouldReplaceLink.js +35 -0
  26. package/dist/cjs/pm-plugins/util/resolve.js +59 -0
  27. package/dist/cjs/pm-plugins/util/state.js +49 -0
  28. package/dist/cjs/toolbar.js +364 -0
  29. package/dist/cjs/types.js +5 -0
  30. package/dist/cjs/ui/DatasourceModal/ModalWithState.js +25 -0
  31. package/dist/cjs/ui/DatasourceModal/index.js +60 -0
  32. package/dist/cjs/ui/EditLinkToolbar.js +258 -0
  33. package/dist/cjs/ui/EditorSmartCardEvents.js +21 -0
  34. package/dist/cjs/ui/EditorSmartCardEventsNext.js +215 -0
  35. package/dist/cjs/ui/HyperlinkToolbarAppearance.js +174 -0
  36. package/dist/cjs/ui/LayoutButton/index.js +121 -0
  37. package/dist/cjs/ui/LayoutButton/types.js +5 -0
  38. package/dist/cjs/ui/LayoutButton/utils.js +19 -0
  39. package/dist/cjs/ui/LinkToolbarAppearance.js +152 -0
  40. package/dist/cjs/ui/ResizableEmbedCard.js +364 -0
  41. package/dist/cjs/ui/SmallerEditIcon.js +22 -0
  42. package/dist/cjs/utils.js +60 -0
  43. package/dist/cjs/version.json +5 -0
  44. package/dist/es2019/index.js +1 -0
  45. package/dist/es2019/messages.js +13 -0
  46. package/dist/es2019/nodeviews/blockCard.js +131 -0
  47. package/dist/es2019/nodeviews/datasource.js +137 -0
  48. package/dist/es2019/nodeviews/embedCard.js +370 -0
  49. package/dist/es2019/nodeviews/genericCard.js +92 -0
  50. package/dist/es2019/nodeviews/inlineCard.js +113 -0
  51. package/dist/es2019/plugin.js +129 -0
  52. package/dist/es2019/pm-plugins/actions.js +57 -0
  53. package/dist/es2019/pm-plugins/analytics/create-analytics-queue.js +38 -0
  54. package/dist/es2019/pm-plugins/analytics/events-from-tr.js +339 -0
  55. package/dist/es2019/pm-plugins/analytics/index.js +2 -0
  56. package/dist/es2019/pm-plugins/analytics/types.js +1 -0
  57. package/dist/es2019/pm-plugins/analytics/utils.js +160 -0
  58. package/dist/es2019/pm-plugins/doc.js +451 -0
  59. package/dist/es2019/pm-plugins/keymap.js +59 -0
  60. package/dist/es2019/pm-plugins/main.js +208 -0
  61. package/dist/es2019/pm-plugins/mountHyperlink.js +37 -0
  62. package/dist/es2019/pm-plugins/plugin-key.js +2 -0
  63. package/dist/es2019/pm-plugins/reducers.js +110 -0
  64. package/dist/es2019/pm-plugins/shouldReplaceLink.js +25 -0
  65. package/dist/es2019/pm-plugins/util/resolve.js +50 -0
  66. package/dist/es2019/pm-plugins/util/state.js +26 -0
  67. package/dist/es2019/toolbar.js +359 -0
  68. package/dist/es2019/types.js +1 -0
  69. package/dist/es2019/ui/DatasourceModal/ModalWithState.js +19 -0
  70. package/dist/es2019/ui/DatasourceModal/index.js +48 -0
  71. package/dist/es2019/ui/EditLinkToolbar.js +226 -0
  72. package/dist/es2019/ui/EditorSmartCardEvents.js +15 -0
  73. package/dist/es2019/ui/EditorSmartCardEventsNext.js +199 -0
  74. package/dist/es2019/ui/HyperlinkToolbarAppearance.js +86 -0
  75. package/dist/es2019/ui/LayoutButton/index.js +114 -0
  76. package/dist/es2019/ui/LayoutButton/types.js +1 -0
  77. package/dist/es2019/ui/LayoutButton/utils.js +15 -0
  78. package/dist/es2019/ui/LinkToolbarAppearance.js +118 -0
  79. package/dist/es2019/ui/ResizableEmbedCard.js +335 -0
  80. package/dist/es2019/ui/SmallerEditIcon.js +14 -0
  81. package/dist/es2019/utils.js +46 -0
  82. package/dist/es2019/version.json +5 -0
  83. package/dist/esm/index.js +1 -0
  84. package/dist/esm/messages.js +13 -0
  85. package/dist/esm/nodeviews/blockCard.js +156 -0
  86. package/dist/esm/nodeviews/datasource.js +165 -0
  87. package/dist/esm/nodeviews/embedCard.js +389 -0
  88. package/dist/esm/nodeviews/genericCard.js +111 -0
  89. package/dist/esm/nodeviews/inlineCard.js +124 -0
  90. package/dist/esm/plugin.js +130 -0
  91. package/dist/esm/pm-plugins/actions.js +102 -0
  92. package/dist/esm/pm-plugins/analytics/create-analytics-queue.js +41 -0
  93. package/dist/esm/pm-plugins/analytics/events-from-tr.js +350 -0
  94. package/dist/esm/pm-plugins/analytics/index.js +2 -0
  95. package/dist/esm/pm-plugins/analytics/types.js +1 -0
  96. package/dist/esm/pm-plugins/analytics/utils.js +160 -0
  97. package/dist/esm/pm-plugins/doc.js +460 -0
  98. package/dist/esm/pm-plugins/keymap.js +58 -0
  99. package/dist/esm/pm-plugins/main.js +199 -0
  100. package/dist/esm/pm-plugins/mountHyperlink.js +39 -0
  101. package/dist/esm/pm-plugins/plugin-key.js +2 -0
  102. package/dist/esm/pm-plugins/reducers.js +103 -0
  103. package/dist/esm/pm-plugins/shouldReplaceLink.js +29 -0
  104. package/dist/esm/pm-plugins/util/resolve.js +52 -0
  105. package/dist/esm/pm-plugins/util/state.js +40 -0
  106. package/dist/esm/toolbar.js +350 -0
  107. package/dist/esm/types.js +1 -0
  108. package/dist/esm/ui/DatasourceModal/ModalWithState.js +17 -0
  109. package/dist/esm/ui/DatasourceModal/index.js +49 -0
  110. package/dist/esm/ui/EditLinkToolbar.js +244 -0
  111. package/dist/esm/ui/EditorSmartCardEvents.js +14 -0
  112. package/dist/esm/ui/EditorSmartCardEventsNext.js +203 -0
  113. package/dist/esm/ui/HyperlinkToolbarAppearance.js +163 -0
  114. package/dist/esm/ui/LayoutButton/index.js +110 -0
  115. package/dist/esm/ui/LayoutButton/types.js +1 -0
  116. package/dist/esm/ui/LayoutButton/utils.js +12 -0
  117. package/dist/esm/ui/LinkToolbarAppearance.js +141 -0
  118. package/dist/esm/ui/ResizableEmbedCard.js +358 -0
  119. package/dist/esm/ui/SmallerEditIcon.js +14 -0
  120. package/dist/esm/utils.js +48 -0
  121. package/dist/esm/version.json +5 -0
  122. package/dist/types/index.d.ts +2 -0
  123. package/dist/types/messages.d.ts +12 -0
  124. package/dist/types/nodeviews/blockCard.d.ts +26 -0
  125. package/dist/types/nodeviews/datasource.d.ts +42 -0
  126. package/dist/types/nodeviews/embedCard.d.ts +46 -0
  127. package/dist/types/nodeviews/genericCard.d.ts +37 -0
  128. package/dist/types/nodeviews/inlineCard.d.ts +23 -0
  129. package/dist/types/plugin.d.ts +24 -0
  130. package/dist/types/pm-plugins/actions.d.ts +23 -0
  131. package/dist/types/pm-plugins/analytics/create-analytics-queue.d.ts +10 -0
  132. package/dist/types/pm-plugins/analytics/events-from-tr.d.ts +17 -0
  133. package/dist/types/pm-plugins/analytics/index.d.ts +2 -0
  134. package/dist/types/pm-plugins/analytics/types.d.ts +12 -0
  135. package/dist/types/pm-plugins/analytics/utils.d.ts +32 -0
  136. package/dist/types/pm-plugins/doc.d.ts +22 -0
  137. package/dist/types/pm-plugins/keymap.d.ts +3 -0
  138. package/dist/types/pm-plugins/main.d.ts +6 -0
  139. package/dist/types/pm-plugins/mountHyperlink.d.ts +5 -0
  140. package/dist/types/pm-plugins/plugin-key.d.ts +3 -0
  141. package/dist/types/pm-plugins/reducers.d.ts +3 -0
  142. package/dist/types/pm-plugins/shouldReplaceLink.d.ts +2 -0
  143. package/dist/types/pm-plugins/util/resolve.d.ts +8 -0
  144. package/dist/types/pm-plugins/util/state.d.ts +31 -0
  145. package/dist/types/toolbar.d.ts +9 -0
  146. package/dist/types/types.d.ts +163 -0
  147. package/dist/types/ui/DatasourceModal/ModalWithState.d.ts +9 -0
  148. package/dist/types/ui/DatasourceModal/index.d.ts +11 -0
  149. package/dist/types/ui/EditLinkToolbar.d.ts +47 -0
  150. package/dist/types/ui/EditorSmartCardEvents.d.ts +5 -0
  151. package/dist/types/ui/EditorSmartCardEventsNext.d.ts +18 -0
  152. package/dist/types/ui/HyperlinkToolbarAppearance.d.ts +32 -0
  153. package/dist/types/ui/LayoutButton/index.d.ts +9 -0
  154. package/dist/types/ui/LayoutButton/types.d.ts +19 -0
  155. package/dist/types/ui/LayoutButton/utils.d.ts +5 -0
  156. package/dist/types/ui/LinkToolbarAppearance.d.ts +29 -0
  157. package/dist/types/ui/ResizableEmbedCard.d.ts +61 -0
  158. package/dist/types/ui/SmallerEditIcon.d.ts +3 -0
  159. package/dist/types/utils.d.ts +19 -0
  160. package/dist/types-ts4.5/index.d.ts +2 -0
  161. package/dist/types-ts4.5/messages.d.ts +12 -0
  162. package/dist/types-ts4.5/nodeviews/blockCard.d.ts +26 -0
  163. package/dist/types-ts4.5/nodeviews/datasource.d.ts +42 -0
  164. package/dist/types-ts4.5/nodeviews/embedCard.d.ts +46 -0
  165. package/dist/types-ts4.5/nodeviews/genericCard.d.ts +37 -0
  166. package/dist/types-ts4.5/nodeviews/inlineCard.d.ts +23 -0
  167. package/dist/types-ts4.5/plugin.d.ts +24 -0
  168. package/dist/types-ts4.5/pm-plugins/actions.d.ts +23 -0
  169. package/dist/types-ts4.5/pm-plugins/analytics/create-analytics-queue.d.ts +10 -0
  170. package/dist/types-ts4.5/pm-plugins/analytics/events-from-tr.d.ts +17 -0
  171. package/dist/types-ts4.5/pm-plugins/analytics/index.d.ts +2 -0
  172. package/dist/types-ts4.5/pm-plugins/analytics/types.d.ts +12 -0
  173. package/dist/types-ts4.5/pm-plugins/analytics/utils.d.ts +32 -0
  174. package/dist/types-ts4.5/pm-plugins/doc.d.ts +22 -0
  175. package/dist/types-ts4.5/pm-plugins/keymap.d.ts +3 -0
  176. package/dist/types-ts4.5/pm-plugins/main.d.ts +6 -0
  177. package/dist/types-ts4.5/pm-plugins/mountHyperlink.d.ts +5 -0
  178. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +3 -0
  179. package/dist/types-ts4.5/pm-plugins/reducers.d.ts +3 -0
  180. package/dist/types-ts4.5/pm-plugins/shouldReplaceLink.d.ts +2 -0
  181. package/dist/types-ts4.5/pm-plugins/util/resolve.d.ts +8 -0
  182. package/dist/types-ts4.5/pm-plugins/util/state.d.ts +31 -0
  183. package/dist/types-ts4.5/toolbar.d.ts +9 -0
  184. package/dist/types-ts4.5/types.d.ts +163 -0
  185. package/dist/types-ts4.5/ui/DatasourceModal/ModalWithState.d.ts +9 -0
  186. package/dist/types-ts4.5/ui/DatasourceModal/index.d.ts +11 -0
  187. package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +47 -0
  188. package/dist/types-ts4.5/ui/EditorSmartCardEvents.d.ts +5 -0
  189. package/dist/types-ts4.5/ui/EditorSmartCardEventsNext.d.ts +18 -0
  190. package/dist/types-ts4.5/ui/HyperlinkToolbarAppearance.d.ts +32 -0
  191. package/dist/types-ts4.5/ui/LayoutButton/index.d.ts +9 -0
  192. package/dist/types-ts4.5/ui/LayoutButton/types.d.ts +19 -0
  193. package/dist/types-ts4.5/ui/LayoutButton/utils.d.ts +5 -0
  194. package/dist/types-ts4.5/ui/LinkToolbarAppearance.d.ts +29 -0
  195. package/dist/types-ts4.5/ui/ResizableEmbedCard.d.ts +61 -0
  196. package/dist/types-ts4.5/ui/SmallerEditIcon.d.ts +3 -0
  197. package/dist/types-ts4.5/utils.d.ts +19 -0
  198. package/package.json +126 -0
  199. package/report.api.md +146 -0
  200. package/tmp/api-report-tmp.d.ts +117 -0
@@ -0,0 +1,208 @@
1
+ import { NodeSelection } from 'prosemirror-state';
2
+ import { findDomRefAtPos } from 'prosemirror-utils';
3
+ import rafSchedule from 'raf-schd';
4
+ import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
5
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
6
+ import { DATASOURCE_INNER_CONTAINER_CLASSNAME } from '@atlaskit/editor-common/styles';
7
+ import { canRenderDatasource } from '@atlaskit/editor-common/utils';
8
+ import { BlockCard } from '../nodeviews/blockCard';
9
+ import { Datasource } from '../nodeviews/datasource';
10
+ import { EmbedCard } from '../nodeviews/embedCard';
11
+ import { InlineCardNodeView } from '../nodeviews/inlineCard';
12
+ import { setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
13
+ import { createAnalyticsQueue, eventsFromTransaction } from './analytics';
14
+ import { pluginKey } from './plugin-key';
15
+ import reducer from './reducers';
16
+ import { handleProvider, resolveWithProvider } from './util/resolve';
17
+ import { getNewRequests, getPluginState, getPluginStateWithUpdatedPos } from './util/state';
18
+ export { pluginKey } from './plugin-key';
19
+ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryParams => {
20
+ const {
21
+ lpAnalyticsEventsNext
22
+ } = pmPluginFactoryParams.featureFlags;
23
+ const analyticsQueue = createAnalyticsQueue(!!lpAnalyticsEventsNext);
24
+ const {
25
+ editorAppearance,
26
+ platform,
27
+ allowResizing,
28
+ useAlternativePreloader,
29
+ fullWidthMode,
30
+ showServerActions
31
+ } = options;
32
+ const inlineCardViewProducer = getInlineNodeViewProducer({
33
+ pmPluginFactoryParams,
34
+ Component: InlineCardNodeView,
35
+ extraComponentProps: {
36
+ useAlternativePreloader,
37
+ showServerActions
38
+ }
39
+ });
40
+ return new SafePlugin({
41
+ state: {
42
+ init() {
43
+ return {
44
+ requests: [],
45
+ provider: null,
46
+ cards: [],
47
+ showLinkingToolbar: false,
48
+ smartLinkEvents: undefined,
49
+ smartLinkEventsNext: undefined,
50
+ editorAppearance,
51
+ showDatasourceModal: false,
52
+ datasourceModalType: undefined,
53
+ datasourceTableRef: undefined,
54
+ layout: undefined
55
+ };
56
+ },
57
+ apply(tr, pluginState, prevEditorState) {
58
+ // Update all the positions of outstanding requests and
59
+ // cards in the plugin state.
60
+ const pluginStateWithUpdatedPos = getPluginStateWithUpdatedPos(pluginState, tr);
61
+
62
+ // apply any actions
63
+ const meta = tr.getMeta(pluginKey);
64
+ const events = eventsFromTransaction(tr, prevEditorState);
65
+ analyticsQueue.push(...events);
66
+ if (meta) {
67
+ const nextState = reducer(pluginStateWithUpdatedPos, meta);
68
+ if (!pluginState.smartLinkEventsNext && nextState.smartLinkEventsNext) {
69
+ analyticsQueue.setCallbacks(nextState.smartLinkEventsNext);
70
+ }
71
+ return nextState;
72
+ }
73
+ return pluginStateWithUpdatedPos;
74
+ }
75
+ },
76
+ view(view) {
77
+ const subscriptionHandler = (name, provider) => handleProvider(name, provider, view);
78
+ const domAtPos = view.domAtPos.bind(view);
79
+ const rafCancellationCallbacks = [];
80
+ pmPluginFactoryParams.providerFactory.subscribe('cardProvider', subscriptionHandler);
81
+ return {
82
+ update(view, prevState) {
83
+ var _selection$node;
84
+ const currentState = getPluginState(view.state);
85
+ const oldState = getPluginState(prevState);
86
+ const {
87
+ state,
88
+ dispatch
89
+ } = view;
90
+ const {
91
+ selection,
92
+ tr,
93
+ schema
94
+ } = state;
95
+ const isBlockCardSelected = selection instanceof NodeSelection && ((_selection$node = selection.node) === null || _selection$node === void 0 ? void 0 : _selection$node.type) === schema.nodes.blockCard;
96
+ if (isBlockCardSelected) {
97
+ var _findDomRefAtPos, _node$attrs;
98
+ const datasourceTableRef = (_findDomRefAtPos = findDomRefAtPos(selection.from, domAtPos)) === null || _findDomRefAtPos === void 0 ? void 0 : _findDomRefAtPos.querySelector(`.${DATASOURCE_INNER_CONTAINER_CLASSNAME}`);
99
+ const {
100
+ node
101
+ } = selection;
102
+ const isDatasource = !!(node !== null && node !== void 0 && (_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.datasource);
103
+ const shouldUpdateTableRef = datasourceTableRef && (currentState === null || currentState === void 0 ? void 0 : currentState.datasourceTableRef) !== datasourceTableRef;
104
+ if (isDatasource && shouldUpdateTableRef) {
105
+ var _node$attrs2;
106
+ // since we use the plugin state, which is a shared state, we need to update the datasourceTableRef, layout on each selection
107
+ const layout = (node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.layout) || 'center';
108
+
109
+ // we use cardAction to set the same meta, hence, we will need to combine both layout+datasourceTableRef in one transaction
110
+ dispatch(setCardLayoutAndDatasourceTableRef({
111
+ datasourceTableRef,
112
+ layout
113
+ })(tr));
114
+ }
115
+ } else {
116
+ if (currentState !== null && currentState !== void 0 && currentState.datasourceTableRef) {
117
+ dispatch(setDatasourceTableRef(undefined)(tr));
118
+ }
119
+ }
120
+ if (currentState && currentState.provider) {
121
+ // Find requests in this state that weren't in the old one.
122
+ const newRequests = getNewRequests(oldState, currentState);
123
+ // Ask the CardProvider to resolve all new requests.
124
+ const {
125
+ provider
126
+ } = currentState;
127
+ newRequests.forEach(request => {
128
+ /**
129
+ * Queue each asynchronous resolve request on separate frames.
130
+ * ---
131
+ * NB: The promise for each request is queued to take place on separate animation frames. This avoids
132
+ * the scenario debugged and discovered in EDM-668, wherein the queuing of too many promises in quick succession
133
+ * leads to the browser's macrotask queue being overwhelmed, locking interactivity of the browser tab.
134
+ * By using this approach, the browser is free to schedule the resolution of the promises below in between rendering/network/
135
+ * other tasks as per common implementations of the JavaScript event loop in browsers.
136
+ */
137
+ const invoke = rafSchedule(() => {
138
+ var _pluginInjectionApi$d, _pluginInjectionApi$d2, _pluginInjectionApi$d3, _pluginInjectionApi$d4;
139
+ return resolveWithProvider(view, provider, request, options, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.analytics) === null || _pluginInjectionApi$d === void 0 ? void 0 : _pluginInjectionApi$d.actions, (_pluginInjectionApi$d2 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d3 = pluginInjectionApi.dependencies.analytics) === null || _pluginInjectionApi$d3 === void 0 ? void 0 : (_pluginInjectionApi$d4 = _pluginInjectionApi$d3.sharedState.currentState()) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.createAnalyticsEvent) !== null && _pluginInjectionApi$d2 !== void 0 ? _pluginInjectionApi$d2 : undefined);
140
+ });
141
+ rafCancellationCallbacks.push(invoke.cancel);
142
+ invoke();
143
+ });
144
+ }
145
+ analyticsQueue.flush();
146
+ },
147
+ destroy() {
148
+ // Cancel any outstanding raf callbacks.
149
+ rafCancellationCallbacks.forEach(cancellationCallback => cancellationCallback());
150
+ pmPluginFactoryParams.providerFactory.unsubscribe('cardProvider', subscriptionHandler);
151
+ }
152
+ };
153
+ },
154
+ props: {
155
+ nodeViews: {
156
+ inlineCard: inlineCardViewProducer,
157
+ blockCard: (node, view, getPos, decorations) => {
158
+ var _node$attrs3;
159
+ const {
160
+ portalProviderAPI,
161
+ eventDispatcher
162
+ } = pmPluginFactoryParams;
163
+ const reactComponentProps = {
164
+ platform,
165
+ showServerActions
166
+ };
167
+ const hasIntlContext = true;
168
+ const isDatasource = !!(node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.datasource);
169
+ if (isDatasource) {
170
+ var _node$attrs4, _node$attrs4$datasour;
171
+ if (platform !== 'mobile' && canRenderDatasource(node === null || node === void 0 ? void 0 : (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 ? void 0 : (_node$attrs4$datasour = _node$attrs4.datasource) === null || _node$attrs4$datasour === void 0 ? void 0 : _node$attrs4$datasour.id)) {
172
+ return new Datasource({
173
+ node,
174
+ view,
175
+ getPos,
176
+ portalProviderAPI,
177
+ eventDispatcher,
178
+ hasIntlContext,
179
+ pluginInjectionApi
180
+ }).init();
181
+ } else {
182
+ return inlineCardViewProducer(node, view, getPos, decorations);
183
+ }
184
+ }
185
+ return new BlockCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
186
+ },
187
+ embedCard: (node, view, getPos) => {
188
+ const {
189
+ portalProviderAPI,
190
+ eventDispatcher,
191
+ dispatchAnalyticsEvent
192
+ } = pmPluginFactoryParams;
193
+ const reactComponentProps = {
194
+ eventDispatcher,
195
+ allowResizing,
196
+ platform,
197
+ fullWidthMode,
198
+ dispatchAnalyticsEvent,
199
+ pluginInjectionApi
200
+ };
201
+ const hasIntlContext = true;
202
+ return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
203
+ }
204
+ }
205
+ },
206
+ key: pluginKey
207
+ });
208
+ };
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
3
+ import { HyperlinkToolbarAppearance } from '../ui/HyperlinkToolbarAppearance';
4
+ export const mountHyperlinkPlugin = (pluginInjectionApi, options) => {
5
+ return new SafePlugin({
6
+ view(editorView) {
7
+ requestAnimationFrame(() => {
8
+ var _pluginInjectionApi$d, _pluginInjectionApi$d2;
9
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.hyperlink) === null || _pluginInjectionApi$d === void 0 ? void 0 : (_pluginInjectionApi$d2 = _pluginInjectionApi$d.actions) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.prependToolbarButtons({
10
+ items: (state, intl, providerFactory, link) => [{
11
+ type: 'custom',
12
+ fallback: [],
13
+ render: editorView => {
14
+ var _pluginInjectionApi$d3, _pluginInjectionApi$d4;
15
+ return /*#__PURE__*/React.createElement(HyperlinkToolbarAppearance, {
16
+ key: "link-appearance",
17
+ url: link,
18
+ intl: intl,
19
+ editorView: editorView,
20
+ editorState: state,
21
+ cardOptions: options,
22
+ providerFactory: providerFactory,
23
+ platform: options === null || options === void 0 ? void 0 : options.platform,
24
+ editorAnalyticsApi: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d3 = pluginInjectionApi.dependencies.analytics) === null || _pluginInjectionApi$d3 === void 0 ? void 0 : _pluginInjectionApi$d3.actions,
25
+ cardActions: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d4 = pluginInjectionApi.dependencies.card) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : _pluginInjectionApi$d4.actions
26
+ });
27
+ }
28
+ }],
29
+ onEscapeCallback: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.card.actions.hideLinkToolbar,
30
+ onInsertLinkCallback: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.card.actions.queueCardsFromChangedTr,
31
+ view: editorView
32
+ });
33
+ });
34
+ return {};
35
+ }
36
+ });
37
+ };
@@ -0,0 +1,2 @@
1
+ import { PluginKey } from 'prosemirror-state';
2
+ export const pluginKey = new PluginKey('cardPlugin');
@@ -0,0 +1,110 @@
1
+ const queue = (state, action) => {
2
+ return {
3
+ ...state,
4
+ requests: state.requests.concat(action.requests)
5
+ };
6
+ };
7
+ const resolve = (state, action) => {
8
+ const requests = state.requests.reduce((requests, request) => {
9
+ if (request.url !== action.url) {
10
+ requests.push(request);
11
+ }
12
+ return requests;
13
+ }, []);
14
+ return {
15
+ ...state,
16
+ requests
17
+ };
18
+ };
19
+ const register = (state, action) => {
20
+ return {
21
+ ...state,
22
+ cards: state.cards.filter(card => card.pos !== action.info.pos).concat(action.info)
23
+ };
24
+ };
25
+ const setProvider = (state, action) => {
26
+ return {
27
+ ...state,
28
+ provider: action.provider
29
+ };
30
+ };
31
+ const setCardLayout = (state, action) => {
32
+ return {
33
+ ...state,
34
+ layout: action.layout
35
+ };
36
+ };
37
+ const setDatasourceTableRef = (state, action) => {
38
+ return {
39
+ ...state,
40
+ datasourceTableRef: action.datasourceTableRef
41
+ };
42
+ };
43
+ const setCardLayoutDatasourceTableRef = (state, action) => {
44
+ return {
45
+ ...state,
46
+ datasourceTableRef: action.datasourceTableRef,
47
+ layout: action.layout
48
+ };
49
+ };
50
+ const registerEvents = (state, action) => {
51
+ return {
52
+ ...state,
53
+ smartLinkEvents: action.smartLinkEvents
54
+ };
55
+ };
56
+ const registerEventsNext = (state, action) => {
57
+ return {
58
+ ...state,
59
+ smartLinkEventsNext: action.smartLinkEvents
60
+ };
61
+ };
62
+ const setLinkToolbar = (state, action) => {
63
+ return {
64
+ ...state,
65
+ showLinkingToolbar: action.type === 'SHOW_LINK_TOOLBAR'
66
+ };
67
+ };
68
+ const showDatasourceModal = (state, action) => {
69
+ return {
70
+ ...state,
71
+ showDatasourceModal: true,
72
+ datasourceModalType: action.type === 'SHOW_DATASOURCE_MODAL' ? action.modalType : undefined
73
+ };
74
+ };
75
+ const hideDatasourceModal = state => {
76
+ return {
77
+ ...state,
78
+ showDatasourceModal: false,
79
+ datasourceModalType: undefined
80
+ };
81
+ };
82
+ export default ((state, action) => {
83
+ switch (action.type) {
84
+ case 'QUEUE':
85
+ return queue(state, action);
86
+ case 'SET_PROVIDER':
87
+ return setProvider(state, action);
88
+ case 'RESOLVE':
89
+ return resolve(state, action);
90
+ case 'REGISTER':
91
+ return register(state, action);
92
+ case 'REGISTER_EVENTS':
93
+ return registerEvents(state, action);
94
+ case 'REGISTER_EVENTS_NEXT':
95
+ return registerEventsNext(state, action);
96
+ case 'SET_DATASOURCE_TABLE_REF':
97
+ return setDatasourceTableRef(state, action);
98
+ case 'SET_CARD_LAYOUT':
99
+ return setCardLayout(state, action);
100
+ case 'SET_CARD_LAYOUT_AND_DATASOURCE_TABLE_REF':
101
+ return setCardLayoutDatasourceTableRef(state, action);
102
+ case 'SHOW_LINK_TOOLBAR':
103
+ case 'HIDE_LINK_TOOLBAR':
104
+ return setLinkToolbar(state, action);
105
+ case 'SHOW_DATASOURCE_MODAL':
106
+ return showDatasourceModal(state, action);
107
+ case 'HIDE_DATASOURCE_MODAL':
108
+ return hideDatasourceModal(state);
109
+ }
110
+ });
@@ -0,0 +1,25 @@
1
+ import { normalizeUrl } from '@atlaskit/adf-schema';
2
+ import { md } from '@atlaskit/editor-common/paste';
3
+ export function shouldReplaceLink(node, compareLinkText = true, compareToUrl) {
4
+ const linkMark = node.marks.find(mark => mark.type.name === 'link');
5
+ if (!linkMark) {
6
+ // not a link anymore
7
+ return false;
8
+ }
9
+
10
+ // ED-6041: compare normalised link text after linkfy from Markdown transformer
11
+ // instead, since it always decodes URL ('%20' -> ' ') on the link text
12
+
13
+ const normalisedHref = normalizeUrl(md.normalizeLinkText(linkMark.attrs.href));
14
+ const normalizedLinkText = normalizeUrl(md.normalizeLinkText(node.text || ''));
15
+ if (compareLinkText && normalisedHref !== normalizedLinkText) {
16
+ return false;
17
+ }
18
+ if (compareToUrl) {
19
+ const normalizedUrl = normalizeUrl(md.normalizeLinkText(compareToUrl));
20
+ if (normalizedUrl !== normalisedHref) {
21
+ return false;
22
+ }
23
+ }
24
+ return true;
25
+ }
@@ -0,0 +1,50 @@
1
+ import { setProvider } from '../actions';
2
+ import { handleFallbackWithAnalytics, replaceQueuedUrlWithCard } from '../doc';
3
+
4
+ // ============================================================================ //
5
+ // ============================== PROVIDER UTILS ============================== //
6
+ // ============================================================================ //
7
+ // Used for all interactions with the EditorCardProvider.
8
+ // ============================================================================ //
9
+ export const resolveWithProvider = (view, provider, request, options, editorAnalyticsApi, createAnalyticsEvent) => {
10
+ // When user manually changes appearance from blue link to smart link, we should respect that,
11
+ let shouldForceAppearance =
12
+ // This flag is set to true only in one place atm:
13
+ // packages/editor/editor-core/src/plugins/card/pm-plugins/doc.ts @ convertHyperlinkToSmartCard
14
+ // Which is used when user switching from URL to smart link appearance.
15
+ !!request.shouldReplaceLink;
16
+ const handleResolve = provider.resolve(request.url, request.appearance, shouldForceAppearance).then(handleResolved(view, request, editorAnalyticsApi, createAnalyticsEvent, options), handleRejected(view, request, editorAnalyticsApi));
17
+ return handleResolve;
18
+ };
19
+ const updateCardType = (resolvedCard, options) => {
20
+ if ((resolvedCard === null || resolvedCard === void 0 ? void 0 : resolvedCard.type) === 'blockCard' && !options.allowBlockCards || (resolvedCard === null || resolvedCard === void 0 ? void 0 : resolvedCard.type) === 'embedCard' && !options.allowEmbeds) {
21
+ // clean out the 'layout' attr from an embedCard type that should be transformed into the inlineCard type.
22
+ if (resolvedCard.type === 'embedCard') {
23
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
24
+ delete resolvedCard.attrs.layout;
25
+ }
26
+ resolvedCard.type = 'inlineCard';
27
+ }
28
+ };
29
+ const handleResolved = (view, request, editorAnalyticsApi, createAnalyticsEvent, options) => resolvedCard => {
30
+ updateCardType(resolvedCard, options);
31
+ replaceQueuedUrlWithCard(request.url, resolvedCard, request.analyticsAction, editorAnalyticsApi, createAnalyticsEvent)(view.state, view.dispatch);
32
+ return resolvedCard;
33
+ };
34
+ const handleRejected = (view, request, editorAnalyticsApi) => () => {
35
+ handleFallbackWithAnalytics(request, editorAnalyticsApi)(view.state, view.dispatch);
36
+ };
37
+
38
+ // listen for card provider changes
39
+ export const handleProvider = (_, provider, view) => {
40
+ if (!provider) {
41
+ return;
42
+ }
43
+ provider.then(cardProvider => {
44
+ const {
45
+ state,
46
+ dispatch
47
+ } = view;
48
+ dispatch(setProvider(cardProvider)(state.tr));
49
+ });
50
+ };
@@ -0,0 +1,26 @@
1
+ import { pluginKey } from '../plugin-key';
2
+
3
+ // ============================================================================ //
4
+ // ============================== PLUGIN STATE ================================ //
5
+ // ============================================================================ //
6
+ // Used for interactions with the Card Plugin's state.
7
+ // ============================================================================ //
8
+ export const getPluginState = editorState => pluginKey.getState(editorState);
9
+ export const getPluginStateWithUpdatedPos = (pluginState, tr) => ({
10
+ ...pluginState,
11
+ requests: pluginState.requests.map(request => ({
12
+ ...request,
13
+ pos: tr.mapping.map(request.pos)
14
+ })),
15
+ cards: pluginState.cards.map(card => ({
16
+ ...card,
17
+ pos: tr.mapping.map(card.pos)
18
+ }))
19
+ });
20
+ export const getNewRequests = (oldState, currentState) => {
21
+ if (oldState) {
22
+ return currentState.requests.filter(req => !oldState.requests.find(oldReq => isSameRequest(oldReq, req)));
23
+ }
24
+ return currentState.requests;
25
+ };
26
+ const isSameRequest = (requestA, requestB) => requestA.url === requestB.url && requestA.pos === requestB.pos;