@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,350 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
4
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
5
+ import React from 'react';
6
+ import { NodeSelection } from 'prosemirror-state';
7
+ import { findDomRefAtPos, removeSelectedNode } from 'prosemirror-utils';
8
+ import { isSafeUrl } from '@atlaskit/adf-schema';
9
+ import { ACTION, ACTION_SUBJECT, buildOpenedSettingsPayload, buildVisitedLinkPayload, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
10
+ import { buildLayoutButtons, commandWithMetadata } from '@atlaskit/editor-common/card';
11
+ import commonMessages, { linkMessages, linkToolbarMessages, cardMessages as messages } from '@atlaskit/editor-common/messages';
12
+ import { FLOATING_TOOLBAR_LINKPICKER_CLASSNAME, richMediaClassName } from '@atlaskit/editor-common/styles';
13
+ import { canRenderDatasource } from '@atlaskit/editor-common/utils';
14
+ import RemoveIcon from '@atlaskit/icon/glyph/editor/remove';
15
+ import CogIcon from '@atlaskit/icon/glyph/editor/settings';
16
+ import UnlinkIcon from '@atlaskit/icon/glyph/editor/unlink';
17
+ import OpenIcon from '@atlaskit/icon/glyph/shortcut';
18
+ import { changeSelectedCardToText } from './pm-plugins/doc';
19
+ import { pluginKey } from './pm-plugins/main';
20
+ import { buildEditLinkToolbar, editDatasource, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
21
+ import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
22
+ import { SmallerEditIcon } from './ui/SmallerEditIcon';
23
+ import { appearanceForNodeType, displayInfoForCard, findCardInfo, titleUrlPairFromNode } from './utils';
24
+ export var removeCard = function removeCard(editorAnalyticsApi) {
25
+ return commandWithMetadata(function (state, dispatch) {
26
+ if (!(state.selection instanceof NodeSelection)) {
27
+ return false;
28
+ }
29
+ var type = state.selection.node.type.name;
30
+ var payload = {
31
+ action: ACTION.DELETED,
32
+ actionSubject: ACTION_SUBJECT.SMART_LINK,
33
+ actionSubjectId: type,
34
+ attributes: {
35
+ inputMethod: INPUT_METHOD.TOOLBAR,
36
+ displayMode: type
37
+ },
38
+ eventType: EVENT_TYPE.TRACK
39
+ };
40
+ if (dispatch) {
41
+ var tr = state.tr;
42
+ removeSelectedNode(tr);
43
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent(payload)(tr);
44
+ dispatch(tr);
45
+ }
46
+ return true;
47
+ }, {
48
+ action: ACTION.DELETED
49
+ });
50
+ };
51
+ export var visitCardLink = function visitCardLink(editorAnalyticsApi) {
52
+ return function (state, dispatch) {
53
+ if (!(state.selection instanceof NodeSelection)) {
54
+ return false;
55
+ }
56
+ var type = state.selection.node.type;
57
+ var _titleUrlPairFromNode = titleUrlPairFromNode(state.selection.node),
58
+ url = _titleUrlPairFromNode.url;
59
+
60
+ // All card links should open in the same tab per https://product-fabric.atlassian.net/browse/MS-1583.
61
+ // We are in edit mode here, open the smart card URL in a new window.
62
+ window.open(url);
63
+ if (dispatch) {
64
+ var tr = state.tr;
65
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent(buildVisitedLinkPayload(type.name))(tr);
66
+ dispatch(tr);
67
+ }
68
+ return true;
69
+ };
70
+ };
71
+ export var openLinkSettings = function openLinkSettings(editorAnalyticsApi) {
72
+ return function (state, dispatch) {
73
+ if (!(state.selection instanceof NodeSelection)) {
74
+ return false;
75
+ }
76
+ window.open('https://id.atlassian.com/manage-profile/link-preferences');
77
+ if (dispatch) {
78
+ var tr = state.tr,
79
+ type = state.selection.node.type;
80
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent(buildOpenedSettingsPayload(type.name))(tr);
81
+ dispatch(tr);
82
+ }
83
+ return true;
84
+ };
85
+ };
86
+ export var floatingToolbar = function floatingToolbar(cardOptions, featureFlags, platform, linkPickerOptions, pluginInjectionApi) {
87
+ return function (state, intl, providerFactory) {
88
+ var _state$schema$nodes = state.schema.nodes,
89
+ inlineCard = _state$schema$nodes.inlineCard,
90
+ blockCard = _state$schema$nodes.blockCard,
91
+ embedCard = _state$schema$nodes.embedCard;
92
+ var nodeType = [inlineCard, blockCard, embedCard];
93
+ var pluginState = pluginKey.getState(state);
94
+ if (!(state.selection instanceof NodeSelection)) {
95
+ return;
96
+ }
97
+ var selectedNode = state.selection.node;
98
+ if (!selectedNode) {
99
+ return;
100
+ }
101
+ var isEmbedCard = appearanceForNodeType(selectedNode.type) === 'embed';
102
+
103
+ /* add an offset to embeds due to extra padding */
104
+ var toolbarOffset = isEmbedCard ? {
105
+ offset: [0, 24]
106
+ } : {};
107
+
108
+ // Applies padding override for when link picker is currently displayed
109
+ var className = pluginState !== null && pluginState !== void 0 && pluginState.showLinkingToolbar ? FLOATING_TOOLBAR_LINKPICKER_CLASSNAME : undefined;
110
+
111
+ /**
112
+ * Enable focus trap only if feature flag is enabled AND for the new version of the picker
113
+ */
114
+ var lpLinkPicker = featureFlags.lpLinkPicker,
115
+ lpLinkPickerFocusTrap = featureFlags.lpLinkPickerFocusTrap,
116
+ preventPopupOverflow = featureFlags.preventPopupOverflow;
117
+ var shouldEnableFocusTrap = lpLinkPicker && lpLinkPickerFocusTrap;
118
+ var isLinkPickerEnabled = !!lpLinkPicker;
119
+ return _objectSpread(_objectSpread({
120
+ title: intl.formatMessage(messages.card),
121
+ className: className,
122
+ nodeType: nodeType,
123
+ preventPopupOverflow: preventPopupOverflow
124
+ }, toolbarOffset), {}, {
125
+ getDomRef: function getDomRef(view) {
126
+ var element = findDomRefAtPos(view.state.selection.from, view.domAtPos.bind(view));
127
+ if (!element) {
128
+ return undefined;
129
+ }
130
+ if (isEmbedCard) {
131
+ return element.querySelector(".".concat(richMediaClassName));
132
+ }
133
+ return element;
134
+ },
135
+ items: generateToolbarItems(state, featureFlags, intl, providerFactory, cardOptions, platform, linkPickerOptions, pluginInjectionApi),
136
+ scrollable: pluginState !== null && pluginState !== void 0 && pluginState.showLinkingToolbar ? false : true,
137
+ focusTrap: shouldEnableFocusTrap && (pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLinkingToolbar)
138
+ }, editLinkToolbarConfig(Boolean(pluginState === null || pluginState === void 0 ? void 0 : pluginState.showLinkingToolbar), isLinkPickerEnabled));
139
+ };
140
+ };
141
+ var unlinkCard = function unlinkCard(node, state, editorAnalyticsApi) {
142
+ var displayInfo = displayInfoForCard(node, findCardInfo(state));
143
+ var text = displayInfo.title || displayInfo.url;
144
+ if (text) {
145
+ return commandWithMetadata(changeSelectedCardToText(text, editorAnalyticsApi), {
146
+ action: ACTION.UNLINK
147
+ });
148
+ }
149
+ return function () {
150
+ return false;
151
+ };
152
+ };
153
+ var buildAlignmentOptions = function buildAlignmentOptions(state, intl, widthPluginDependencyApi, analyticsApi, cardOptions) {
154
+ return buildLayoutButtons(state, intl, state.schema.nodes.embedCard, widthPluginDependencyApi, analyticsApi, true, true, cardOptions === null || cardOptions === void 0 ? void 0 : cardOptions.allowWrapping, cardOptions === null || cardOptions === void 0 ? void 0 : cardOptions.allowAlignment);
155
+ };
156
+ var withToolbarMetadata = function withToolbarMetadata(command) {
157
+ return commandWithMetadata(command, {
158
+ inputMethod: INPUT_METHOD.FLOATING_TB
159
+ });
160
+ };
161
+ var generateToolbarItems = function generateToolbarItems(state, featureFlags, intl, providerFactory, cardOptions, platform, linkPicker, pluginInjectionApi) {
162
+ return function (node) {
163
+ var _pluginInjectionApi$d, _pluginInjectionApi$d2, _pluginInjectionApi$d3, _pluginInjectionApi$d4, _pluginInjectionApi$d5, _node$attrs, _node$attrs2, _node$attrs2$datasour;
164
+ var _titleUrlPairFromNode2 = titleUrlPairFromNode(node),
165
+ url = _titleUrlPairFromNode2.url;
166
+ var _ref = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d2 = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.analytics) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {},
167
+ editorAnalyticsApi = _ref.actions;
168
+ var metadata = {};
169
+ if (url && !isSafeUrl(url)) {
170
+ return [];
171
+ } else {
172
+ var _displayInfoForCard = displayInfoForCard(node, findCardInfo(state)),
173
+ title = _displayInfoForCard.title;
174
+ metadata = {
175
+ url: url,
176
+ title: title
177
+ };
178
+ }
179
+ var pluginState = pluginKey.getState(state);
180
+ var currentAppearance = appearanceForNodeType(node.type);
181
+ var _ref2 = (_pluginInjectionApi$d3 = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d4 = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d4 === void 0 ? void 0 : (_pluginInjectionApi$d5 = _pluginInjectionApi$d4.decorations) === null || _pluginInjectionApi$d5 === void 0 ? void 0 : _pluginInjectionApi$d5.actions) !== null && _pluginInjectionApi$d3 !== void 0 ? _pluginInjectionApi$d3 : {},
182
+ hoverDecoration = _ref2.hoverDecoration;
183
+ var isDatasource = currentAppearance === 'block' && (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource);
184
+ var shouldRenderDatasourceToolbar = isDatasource &&
185
+ // not showing toolbar in mobile for now since not sure what our plans are for it
186
+ platform !== 'mobile' && canRenderDatasource(node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : (_node$attrs2$datasour = _node$attrs2.datasource) === null || _node$attrs2$datasour === void 0 ? void 0 : _node$attrs2$datasour.id);
187
+
188
+ /* mobile builds toolbar natively using toolbarItems */
189
+ if (pluginState !== null && pluginState !== void 0 && pluginState.showLinkingToolbar && platform !== 'mobile') {
190
+ return [buildEditLinkToolbar({
191
+ providerFactory: providerFactory,
192
+ linkPicker: linkPicker,
193
+ node: node,
194
+ featureFlags: featureFlags,
195
+ pluginInjectionApi: pluginInjectionApi
196
+ })];
197
+ } else if (shouldRenderDatasourceToolbar) {
198
+ return getDatasourceButtonGroup(state, metadata, intl, editorAnalyticsApi, node, hoverDecoration);
199
+ } else {
200
+ var inlineCard = state.schema.nodes.inlineCard;
201
+ var toolbarItems = [{
202
+ id: 'editor.link.edit',
203
+ type: 'button',
204
+ selected: false,
205
+ metadata: metadata,
206
+ title: intl.formatMessage(linkToolbarMessages.editLink),
207
+ showTitle: true,
208
+ testId: 'link-toolbar-edit-link-button',
209
+ onClick: editLink(editorAnalyticsApi)
210
+ }, {
211
+ type: 'separator'
212
+ }, {
213
+ id: 'editor.link.openLink',
214
+ type: 'button',
215
+ icon: OpenIcon,
216
+ metadata: metadata,
217
+ className: 'hyperlink-open-link',
218
+ title: intl.formatMessage(linkMessages.openLink),
219
+ onClick: visitCardLink(editorAnalyticsApi)
220
+ }, {
221
+ type: 'separator'
222
+ }].concat(_toConsumableArray(getUnlinkButtonGroup(state, intl, node, inlineCard, editorAnalyticsApi)), [{
223
+ type: 'copy-button',
224
+ items: [{
225
+ state: state,
226
+ formatMessage: intl.formatMessage,
227
+ nodeType: node.type
228
+ }, {
229
+ type: 'separator'
230
+ }]
231
+ }], _toConsumableArray(getSettingsButtonGroup(state, featureFlags, intl, editorAnalyticsApi)), [{
232
+ id: 'editor.link.delete',
233
+ focusEditoronEnter: true,
234
+ type: 'button',
235
+ appearance: 'danger',
236
+ icon: RemoveIcon,
237
+ onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, true),
238
+ onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, false),
239
+ onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, true),
240
+ onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, false),
241
+ title: intl.formatMessage(commonMessages.remove),
242
+ onClick: withToolbarMetadata(removeCard(editorAnalyticsApi))
243
+ }]);
244
+ if (currentAppearance === 'embed') {
245
+ var _pluginInjectionApi$d6, _pluginInjectionApi$d7, _pluginInjectionApi$d8;
246
+ var alignmentOptions = buildAlignmentOptions(state, intl, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d6 = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d6 === void 0 ? void 0 : _pluginInjectionApi$d6.width, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d7 = pluginInjectionApi.dependencies) === null || _pluginInjectionApi$d7 === void 0 ? void 0 : (_pluginInjectionApi$d8 = _pluginInjectionApi$d7.analytics) === null || _pluginInjectionApi$d8 === void 0 ? void 0 : _pluginInjectionApi$d8.actions, cardOptions);
247
+ if (alignmentOptions.length) {
248
+ alignmentOptions.push({
249
+ type: 'separator'
250
+ });
251
+ }
252
+ toolbarItems.unshift.apply(toolbarItems, _toConsumableArray(alignmentOptions));
253
+ }
254
+ var allowBlockCards = cardOptions.allowBlockCards,
255
+ allowEmbeds = cardOptions.allowEmbeds;
256
+
257
+ // This code will be executed only for appearances such as "inline", "block" & "embed"
258
+ // For url appearance, please see HyperlinkToolbarAppearanceProps
259
+ if (currentAppearance) {
260
+ toolbarItems.unshift({
261
+ type: 'custom',
262
+ fallback: [],
263
+ render: function render(editorView) {
264
+ return /*#__PURE__*/React.createElement(LinkToolbarAppearance, {
265
+ key: "link-appearance",
266
+ url: url,
267
+ intl: intl,
268
+ currentAppearance: currentAppearance,
269
+ editorView: editorView,
270
+ editorState: state,
271
+ allowEmbeds: allowEmbeds,
272
+ allowBlockCards: allowBlockCards,
273
+ platform: platform,
274
+ editorAnalyticsApi: editorAnalyticsApi,
275
+ cardActions: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.card.actions
276
+ });
277
+ }
278
+ }, {
279
+ type: 'separator'
280
+ });
281
+ }
282
+ return toolbarItems;
283
+ }
284
+ };
285
+ };
286
+ var getUnlinkButtonGroup = function getUnlinkButtonGroup(state, intl, node, inlineCard, editorAnalyticsApi) {
287
+ return node.type === inlineCard ? [{
288
+ id: 'editor.link.unlink',
289
+ focusEditoronEnter: true,
290
+ type: 'button',
291
+ title: intl.formatMessage(linkToolbarMessages.unlink),
292
+ icon: UnlinkIcon,
293
+ onClick: withToolbarMetadata(unlinkCard(node, state, editorAnalyticsApi))
294
+ }, {
295
+ type: 'separator'
296
+ }] : [];
297
+ };
298
+ var getSettingsButtonGroup = function getSettingsButtonGroup(state, featureFlags, intl, editorAnalyticsApi) {
299
+ var floatingToolbarLinkSettingsButton = featureFlags.floatingToolbarLinkSettingsButton;
300
+ return floatingToolbarLinkSettingsButton === 'true' ? [{
301
+ id: 'editor.link.settings',
302
+ type: 'button',
303
+ icon: CogIcon,
304
+ title: intl.formatMessage(linkToolbarMessages.settingsLink),
305
+ onClick: openLinkSettings(editorAnalyticsApi)
306
+ }, {
307
+ type: 'separator'
308
+ }] : [];
309
+ };
310
+ var getDatasourceButtonGroup = function getDatasourceButtonGroup(state, metadata, intl, editorAnalyticsApi, node, hoverDecoration) {
311
+ var _node$attrs3;
312
+ var toolbarItems = [{
313
+ id: 'editor.edit.datasource',
314
+ type: 'button',
315
+ icon: SmallerEditIcon,
316
+ metadata: metadata,
317
+ className: 'datasource-edit',
318
+ title: intl.formatMessage(linkToolbarMessages.editDatasource),
319
+ onClick: editDatasource(node, editorAnalyticsApi)
320
+ }];
321
+ if (node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.url) {
322
+ toolbarItems.push({
323
+ type: 'separator'
324
+ }, {
325
+ id: 'editor.link.openLink',
326
+ type: 'button',
327
+ icon: OpenIcon,
328
+ metadata: metadata,
329
+ className: 'hyperlink-open-link',
330
+ title: intl.formatMessage(linkMessages.openLink),
331
+ onClick: visitCardLink(editorAnalyticsApi)
332
+ });
333
+ }
334
+ toolbarItems.push({
335
+ type: 'separator'
336
+ }, {
337
+ id: 'editor.link.delete',
338
+ focusEditoronEnter: true,
339
+ type: 'button',
340
+ appearance: 'danger',
341
+ icon: RemoveIcon,
342
+ onMouseEnter: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, true),
343
+ onMouseLeave: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, false),
344
+ onFocus: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, true),
345
+ onBlur: hoverDecoration === null || hoverDecoration === void 0 ? void 0 : hoverDecoration(node.type, false),
346
+ title: intl.formatMessage(commonMessages.remove),
347
+ onClick: withToolbarMetadata(removeCard(editorAnalyticsApi))
348
+ });
349
+ return toolbarItems;
350
+ };
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,17 @@
1
+ import React from 'react';
2
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
3
+ import { DatasourceModal } from './index';
4
+ var ModalWithState = function ModalWithState(_ref) {
5
+ var api = _ref.api,
6
+ editorView = _ref.editorView;
7
+ var _useSharedPluginState = useSharedPluginState(api, ['card']),
8
+ cardState = _useSharedPluginState.cardState;
9
+ if (!(cardState !== null && cardState !== void 0 && cardState.showDatasourceModal)) {
10
+ return null;
11
+ }
12
+ return /*#__PURE__*/React.createElement(DatasourceModal, {
13
+ view: editorView,
14
+ modalType: cardState === null || cardState === void 0 ? void 0 : cardState.datasourceModalType
15
+ });
16
+ };
17
+ export default ModalWithState;
@@ -0,0 +1,49 @@
1
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
+ import React, { useCallback } from 'react';
3
+ import { NodeSelection } from 'prosemirror-state';
4
+ import { JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
5
+ import { hideDatasourceModal } from '../../pm-plugins/actions';
6
+ import { insertDatasource, updateExistingDatasource } from '../../pm-plugins/doc';
7
+ export var DatasourceModal = function DatasourceModal(_ref) {
8
+ var view = _ref.view,
9
+ modalType = _ref.modalType;
10
+ var dispatch = view.dispatch,
11
+ state = view.state;
12
+ var selection = state.selection;
13
+ var existingNode = selection instanceof NodeSelection ? selection.node : undefined;
14
+ var onClose = useCallback(function () {
15
+ dispatch(hideDatasourceModal(state.tr));
16
+ }, [dispatch, state.tr]);
17
+ var onInsert = useCallback(function (newAdf) {
18
+ if (existingNode) {
19
+ updateExistingDatasource(state, existingNode, newAdf, view);
20
+ } else {
21
+ insertDatasource(state, newAdf, view);
22
+ }
23
+ }, [existingNode, state, view]);
24
+ if (modalType === 'jira') {
25
+ var _existingNode$attrs, _tableView$properties;
26
+ var _ref2 = (existingNode === null || existingNode === void 0 ? void 0 : (_existingNode$attrs = existingNode.attrs) === null || _existingNode$attrs === void 0 ? void 0 : _existingNode$attrs.datasource) || {},
27
+ _ref2$id = _ref2.id,
28
+ datasourceId = _ref2$id === void 0 ? JIRA_LIST_OF_LINKS_DATASOURCE_ID : _ref2$id,
29
+ parameters = _ref2.parameters,
30
+ _ref2$views = _ref2.views,
31
+ views = _ref2$views === void 0 ? [] : _ref2$views;
32
+ var _ref3 = views,
33
+ _ref4 = _slicedToArray(_ref3, 1),
34
+ tableView = _ref4[0];
35
+ var visibleColumnKeys = tableView === null || tableView === void 0 ? void 0 : (_tableView$properties = tableView.properties) === null || _tableView$properties === void 0 ? void 0 : _tableView$properties.columns.map(function (column) {
36
+ return column.key;
37
+ });
38
+ return /*#__PURE__*/React.createElement("div", {
39
+ "data-testid": "jira-config-modal"
40
+ }, /*#__PURE__*/React.createElement(JiraIssuesConfigModal, {
41
+ datasourceId: datasourceId,
42
+ visibleColumnKeys: visibleColumnKeys,
43
+ parameters: parameters,
44
+ onCancel: onClose,
45
+ onInsert: onInsert
46
+ }));
47
+ }
48
+ return null; // null for now until we have modal component that handles other datasources
49
+ };
@@ -0,0 +1,244 @@
1
+ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
+ import _createClass from "@babel/runtime/helpers/createClass";
3
+ import _assertThisInitialized from "@babel/runtime/helpers/assertThisInitialized";
4
+ import _inherits from "@babel/runtime/helpers/inherits";
5
+ import _possibleConstructorReturn from "@babel/runtime/helpers/possibleConstructorReturn";
6
+ import _getPrototypeOf from "@babel/runtime/helpers/getPrototypeOf";
7
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
8
+ function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
9
+ 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; } }
10
+ import React from 'react';
11
+ import { NodeSelection } from 'prosemirror-state';
12
+ import { ACTION, buildEditLinkPayload, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
13
+ import { commandWithMetadata } from '@atlaskit/editor-common/card';
14
+ import { useSharedPluginState } from '@atlaskit/editor-common/hooks';
15
+ import { HyperlinkAddToolbar as HyperlinkToolbar } from '@atlaskit/editor-common/link';
16
+ import { linkToolbarMessages } from '@atlaskit/editor-common/messages';
17
+ import { LINKPICKER_HEIGHT_IN_PX, RECENT_SEARCH_HEIGHT_IN_PX, RECENT_SEARCH_WIDTH_IN_PX, withOuterListeners } from '@atlaskit/editor-common/ui';
18
+ import { JIRA_LIST_OF_LINKS_DATASOURCE_ID } from '@atlaskit/link-datasource';
19
+ import { hideLinkToolbar as _hideLinkToolbar, showDatasourceModal, showLinkToolbar } from '../pm-plugins/actions';
20
+ import { changeSelectedCardToLink, updateCard } from '../pm-plugins/doc';
21
+ import { displayInfoForCard, findCardInfo } from '../utils';
22
+ var HyperLinkToolbarWithListeners = withOuterListeners(HyperlinkAddToolbarWithState);
23
+ export function HyperlinkAddToolbarWithState(_ref) {
24
+ var _ref$linkPickerOption = _ref.linkPickerOptions,
25
+ linkPickerOptions = _ref$linkPickerOption === void 0 ? {} : _ref$linkPickerOption,
26
+ onSubmit = _ref.onSubmit,
27
+ displayText = _ref.displayText,
28
+ displayUrl = _ref.displayUrl,
29
+ providerFactory = _ref.providerFactory,
30
+ view = _ref.view,
31
+ onCancel = _ref.onCancel,
32
+ invokeMethod = _ref.invokeMethod,
33
+ featureFlags = _ref.featureFlags,
34
+ onClose = _ref.onClose,
35
+ onEscapeCallback = _ref.onEscapeCallback,
36
+ onClickAwayCallback = _ref.onClickAwayCallback,
37
+ pluginInjectionApi = _ref.pluginInjectionApi;
38
+ var _useSharedPluginState = useSharedPluginState(pluginInjectionApi, ['hyperlink']),
39
+ hyperlinkState = _useSharedPluginState.hyperlinkState;
40
+ return /*#__PURE__*/React.createElement(HyperlinkToolbar, {
41
+ linkPickerOptions: linkPickerOptions,
42
+ onSubmit: onSubmit,
43
+ displayText: displayText,
44
+ displayUrl: displayUrl,
45
+ providerFactory: providerFactory,
46
+ view: view,
47
+ onCancel: onCancel,
48
+ invokeMethod: invokeMethod,
49
+ featureFlags: featureFlags,
50
+ onClose: onClose,
51
+ onEscapeCallback: onEscapeCallback,
52
+ onClickAwayCallback: onClickAwayCallback,
53
+ hyperlinkPluginState: hyperlinkState
54
+ });
55
+ }
56
+
57
+ // eslint-disable-next-line @repo/internal/react/no-class-components
58
+ export var EditLinkToolbar = /*#__PURE__*/function (_React$Component) {
59
+ _inherits(EditLinkToolbar, _React$Component);
60
+ var _super = _createSuper(EditLinkToolbar);
61
+ function EditLinkToolbar() {
62
+ var _this;
63
+ _classCallCheck(this, EditLinkToolbar);
64
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
65
+ args[_key] = arguments[_key];
66
+ }
67
+ _this = _super.call.apply(_super, [this].concat(args));
68
+ /** Focus should move to the 'Edit link' button when the toolbar closes
69
+ * and not close the floating toolbar.
70
+ */
71
+ _defineProperty(_assertThisInitialized(_this), "handleEsc", function (e) {
72
+ var _this$props$forceFocu, _this$props;
73
+ (_this$props$forceFocu = (_this$props = _this.props).forceFocusSelector) === null || _this$props$forceFocu === void 0 ? void 0 : _this$props$forceFocu.call(_this$props, "[aria-label=\"".concat(linkToolbarMessages.editLink.defaultMessage, "\"]"), _this.props.view);
74
+ });
75
+ return _this;
76
+ }
77
+ _createClass(EditLinkToolbar, [{
78
+ key: "componentDidUpdate",
79
+ value: function componentDidUpdate(prevProps) {
80
+ if (prevProps.node !== this.props.node) {
81
+ this.hideLinkToolbar();
82
+ }
83
+ }
84
+ }, {
85
+ key: "componentWillUnmount",
86
+ value: function componentWillUnmount() {
87
+ this.hideLinkToolbar();
88
+ }
89
+ }, {
90
+ key: "hideLinkToolbar",
91
+ value: function hideLinkToolbar() {
92
+ var view = this.props.view;
93
+ view.dispatch(_hideLinkToolbar(view.state.tr));
94
+ }
95
+ }, {
96
+ key: "render",
97
+ value: function render() {
98
+ var _this2 = this;
99
+ var _this$props2 = this.props,
100
+ linkPickerOptions = _this$props2.linkPickerOptions,
101
+ providerFactory = _this$props2.providerFactory,
102
+ url = _this$props2.url,
103
+ text = _this$props2.text,
104
+ view = _this$props2.view,
105
+ featureFlags = _this$props2.featureFlags,
106
+ _onSubmit = _this$props2.onSubmit,
107
+ pluginInjectionApi = _this$props2.pluginInjectionApi;
108
+ return /*#__PURE__*/React.createElement(HyperLinkToolbarWithListeners, {
109
+ pluginInjectionApi: pluginInjectionApi,
110
+ view: view,
111
+ linkPickerOptions: linkPickerOptions,
112
+ providerFactory: providerFactory,
113
+ displayUrl: url,
114
+ displayText: text,
115
+ handleEscapeKeydown: this.handleEsc
116
+ // Assumes that the smart card link picker can only ever be invoked by clicking "edit"
117
+ // via the floating toolbar
118
+ ,
119
+ invokeMethod: INPUT_METHOD.FLOATING_TB,
120
+ featureFlags: featureFlags,
121
+ onSubmit: function onSubmit(href, title, displayText, inputMethod, analytic) {
122
+ _this2.hideLinkToolbar();
123
+ if (_onSubmit) {
124
+ _onSubmit(href, displayText || title, inputMethod, analytic);
125
+ }
126
+ },
127
+ onEscapeCallback: function onEscapeCallback(state, dispatch) {
128
+ var tr = state.tr;
129
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.hyperlink.actions.hideLinkToolbar(tr);
130
+ _hideLinkToolbar(tr);
131
+ if (dispatch) {
132
+ dispatch(tr);
133
+ return true;
134
+ }
135
+ return false;
136
+ },
137
+ onClickAwayCallback: function onClickAwayCallback(state, dispatch) {
138
+ var tr = state.tr;
139
+ pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : pluginInjectionApi.dependencies.hyperlink.actions.hideLinkToolbar(tr);
140
+ if (dispatch) {
141
+ dispatch(tr);
142
+ return true;
143
+ }
144
+ return false;
145
+ }
146
+ });
147
+ }
148
+ }]);
149
+ return EditLinkToolbar;
150
+ }(React.Component);
151
+ export var editLink = function editLink(editorAnalyticsApi) {
152
+ return function (state, dispatch) {
153
+ var type = 'hyperlink';
154
+ if (state.selection instanceof NodeSelection) {
155
+ type = state.selection.node.type.name;
156
+ }
157
+ if (dispatch) {
158
+ var tr = state.tr;
159
+ showLinkToolbar(tr);
160
+ editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent(buildEditLinkPayload(type))(tr);
161
+ dispatch(tr);
162
+ return true;
163
+ }
164
+ return false;
165
+ };
166
+ };
167
+ export var buildEditLinkToolbar = function buildEditLinkToolbar(_ref2) {
168
+ var providerFactory = _ref2.providerFactory,
169
+ node = _ref2.node,
170
+ linkPicker = _ref2.linkPicker,
171
+ featureFlags = _ref2.featureFlags,
172
+ pluginInjectionApi = _ref2.pluginInjectionApi;
173
+ return {
174
+ type: 'custom',
175
+ disableArrowNavigation: true,
176
+ fallback: [],
177
+ render: function render(view, idx) {
178
+ var _pluginInjectionApi$d;
179
+ if (!view || !providerFactory) {
180
+ return null;
181
+ }
182
+ var displayInfo = displayInfoForCard(node, findCardInfo(view.state));
183
+ return /*#__PURE__*/React.createElement(EditLinkToolbar, {
184
+ pluginInjectionApi: pluginInjectionApi,
185
+ key: idx,
186
+ view: view,
187
+ linkPickerOptions: linkPicker,
188
+ providerFactory: providerFactory,
189
+ url: displayInfo.url,
190
+ text: displayInfo.title || '',
191
+ node: node,
192
+ featureFlags: featureFlags,
193
+ forceFocusSelector: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d = pluginInjectionApi.dependencies.floatingToolbar.actions) === null || _pluginInjectionApi$d === void 0 ? void 0 : _pluginInjectionApi$d.forceFocusSelector,
194
+ onSubmit: function onSubmit(newHref, newText, inputMethod, analytic) {
195
+ var urlChanged = newHref !== displayInfo.url;
196
+ var titleChanged = newText !== displayInfo.title;
197
+
198
+ // If the title is changed in a smartlink, convert to standard blue hyperlink
199
+ // (even if the url was also changed) - we don't want to lose the custom title.
200
+ if (titleChanged) {
201
+ var _pluginInjectionApi$d2;
202
+ return commandWithMetadata(changeSelectedCardToLink(newText, newHref, undefined, undefined, undefined, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d2 = pluginInjectionApi.dependencies.analytics) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions), {
203
+ action: ACTION.UPDATED,
204
+ inputMethod: inputMethod,
205
+ sourceEvent: analytic
206
+ })(view.state, view.dispatch);
207
+ }
208
+ if (urlChanged) {
209
+ // If *only* the url is changed in a smart link, reresolve
210
+ return updateCard(newHref, analytic)(view.state, view.dispatch);
211
+ }
212
+ }
213
+ });
214
+ }
215
+ };
216
+ };
217
+ export var editLinkToolbarConfig = function editLinkToolbarConfig(showLinkingToolbar, lpLinkPicker) {
218
+ return showLinkingToolbar ? {
219
+ height: lpLinkPicker ? LINKPICKER_HEIGHT_IN_PX : RECENT_SEARCH_HEIGHT_IN_PX,
220
+ width: RECENT_SEARCH_WIDTH_IN_PX,
221
+ forcePlacement: true
222
+ } : {};
223
+ };
224
+ export var editDatasource = function editDatasource(node, editorAnalyticsApi) {
225
+ return function (state, dispatch) {
226
+ var _node$attrs;
227
+ var modalType = ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource.id) === JIRA_LIST_OF_LINKS_DATASOURCE_ID ? 'jira' : undefined;
228
+ if (dispatch && modalType) {
229
+ var tr = state.tr;
230
+ showDatasourceModal(modalType)(tr);
231
+ // editorAnalyticsApi?.attachAnalyticsEvent(
232
+ // buildEditLinkPayload(
233
+ // type as
234
+ // | ACTION_SUBJECT_ID.CARD_INLINE
235
+ // | ACTION_SUBJECT_ID.CARD_BLOCK
236
+ // | ACTION_SUBJECT_ID.EMBEDS,
237
+ // ),
238
+ // )(tr);
239
+ dispatch(tr);
240
+ return true;
241
+ }
242
+ return false;
243
+ };
244
+ };