@atlaskit/editor-plugin-card 16.10.3 → 16.11.1

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 (30) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/cardPlugin.js +19 -2
  3. package/dist/cjs/pm-plugins/doc.js +2 -2
  4. package/dist/cjs/ui/PasteDisplayAsMenu.compiled.css +31 -0
  5. package/dist/cjs/ui/PasteDisplayAsMenu.js +368 -0
  6. package/dist/cjs/ui/currentPastedSmartLink.js +52 -0
  7. package/dist/cjs/ui/pasteDisplayAsUtils.js +30 -0
  8. package/dist/es2019/cardPlugin.js +17 -2
  9. package/dist/es2019/pm-plugins/doc.js +2 -2
  10. package/dist/es2019/ui/PasteDisplayAsMenu.compiled.css +31 -0
  11. package/dist/es2019/ui/PasteDisplayAsMenu.js +366 -0
  12. package/dist/es2019/ui/currentPastedSmartLink.js +46 -0
  13. package/dist/es2019/ui/pasteDisplayAsUtils.js +24 -0
  14. package/dist/esm/cardPlugin.js +19 -2
  15. package/dist/esm/pm-plugins/doc.js +2 -2
  16. package/dist/esm/ui/PasteDisplayAsMenu.compiled.css +31 -0
  17. package/dist/esm/ui/PasteDisplayAsMenu.js +359 -0
  18. package/dist/esm/ui/currentPastedSmartLink.js +46 -0
  19. package/dist/esm/ui/pasteDisplayAsUtils.js +24 -0
  20. package/dist/types/cardPluginType.d.ts +3 -1
  21. package/dist/types/types/index.d.ts +1 -0
  22. package/dist/types/ui/PasteDisplayAsMenu.d.ts +25 -0
  23. package/dist/types/ui/currentPastedSmartLink.d.ts +2 -0
  24. package/dist/types/ui/pasteDisplayAsUtils.d.ts +7 -0
  25. package/dist/types-ts4.5/cardPluginType.d.ts +3 -1
  26. package/dist/types-ts4.5/types/index.d.ts +1 -0
  27. package/dist/types-ts4.5/ui/PasteDisplayAsMenu.d.ts +25 -0
  28. package/dist/types-ts4.5/ui/currentPastedSmartLink.d.ts +2 -0
  29. package/dist/types-ts4.5/ui/pasteDisplayAsUtils.d.ts +12 -0
  30. package/package.json +9 -5
@@ -0,0 +1,359 @@
1
+ /* PasteDisplayAsMenu.tsx generated by @compiled/babel-plugin v0.39.1 */
2
+ import "./PasteDisplayAsMenu.compiled.css";
3
+ import { ax, ix } from "@compiled/react/runtime";
4
+ import React, { useCallback, useEffect, useRef } from 'react';
5
+ import { useIntl } from 'react-intl';
6
+ import { cx } from '@atlaskit/css';
7
+ import { appearancePropsMap } from '@atlaskit/editor-common/card';
8
+ import { useSharedPluginStateWithSelector } from '@atlaskit/editor-common/hooks';
9
+ import { getActiveLinkMark } from '@atlaskit/editor-common/link';
10
+ import { PASTE_MENU, useEditorToolbar } from '@atlaskit/editor-common/toolbar';
11
+ import { isSupportedInParent } from '@atlaskit/editor-common/utils';
12
+ import { Fragment } from '@atlaskit/editor-prosemirror/model';
13
+ import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
14
+ import { ToolbarDropdownItemSection, useToolbarDropdownMenu } from '@atlaskit/editor-toolbar';
15
+ import MinusIcon from '@atlaskit/icon/core/minus';
16
+ import SmartLinkCardIcon from '@atlaskit/icon/core/smart-link-card';
17
+ import SmartLinkEmbedIcon from '@atlaskit/icon/core/smart-link-embed';
18
+ import SmartLinkInlineIcon from '@atlaskit/icon/core/smart-link-inline';
19
+ import { useSmartCardContext } from '@atlaskit/link-provider';
20
+ import { Box, Flex, Pressable } from '@atlaskit/primitives/compiled';
21
+ import { changeSelectedCardToLink, setSelectedCardAppearance } from '../pm-plugins/doc';
22
+ import { getSingleSmartLinkUrlFromSlice } from './currentPastedSmartLink';
23
+ import { getCardAtPasteRange } from './pasteDisplayAsUtils';
24
+ export var SMART_LINK_DISPLAY_AS_PASTE_MENU_SECTION_KEY = 'smart-link-display-as-paste-menu-section';
25
+
26
+ // `pasteOptionsToolbarPlugin` is intentionally NOT declared in `CardPluginDependencies`
27
+ // because doing so introduces a runtime package cycle
28
+ // (editor-plugin-card -> editor-plugin-paste-options-toolbar -> editor-plugin-paste
29
+ // -> editor-plugin-card) AND a TS2719 "two different types with this name exist" error
30
+ // at downstream consumers (e.g. Jira's `EditorAfterBanner.tsx`). We instead augment the
31
+ // `api` shape locally at the call sites that need to read the plugin's shared state.
32
+
33
+ var styles = {
34
+ appearanceBox: "_2rko1qi0 _bfhkhfxm _19pku2gc _2hwxu2gc _otyru2gc _18u0u2gc _ca0q1b66 _u5f31b66 _n3td1b66 _19bv1b66",
35
+ iconWrapper: "_bfhkvuon _1e0c1txw _1bsb1osq _1bah1b1v",
36
+ iconButton: "_2rko1qi0 _1h6d1l7x _1dqonqa1 _189ee4h9 _4cvr1h6o _syazi7uo _1e0c1txw _4t3izwfg _1bah1h6o _1bsb1osq _bfhksm61 _irr31dpa _1di6fcek",
37
+ iconButtonSelected: "_2rko1qi0 _1h6dq98m _1dqonqa1 _189ee4h9 _4cvr1h6o _bfhk15s3 _syazi7uo _1e0c1txw _4t3izwfg _1bah1h6o _1bsb1osq _irr3ufnl _1di6nozp",
38
+ iconButtonDisabled: "_2rko1qi0 _1h6dbk0g _1dqonqa1 _189ee4h9 _4cvr1h6o _bfhk187o _syaz1gmx _1e0c1txw _4t3izwfg _1bah1h6o _1bsb1osq"
39
+ };
40
+ var AppearanceOptionIconButton = function AppearanceOptionIconButton(_ref) {
41
+ var appearance = _ref.appearance,
42
+ currentAppearance = _ref.currentAppearance,
43
+ isDisabled = _ref.isDisabled,
44
+ label = _ref.label,
45
+ Icon = _ref.Icon,
46
+ onClick = _ref.onClick;
47
+ return /*#__PURE__*/React.createElement(Box, {
48
+ xcss: styles.iconWrapper
49
+ }, /*#__PURE__*/React.createElement(Pressable, {
50
+ xcss: cx(styles.iconButton, isDisabled && styles.iconButtonDisabled, !isDisabled && currentAppearance === appearance && styles.iconButtonSelected),
51
+ "aria-label": label,
52
+ "aria-pressed": currentAppearance === appearance,
53
+ isDisabled: isDisabled,
54
+ onClick: onClick
55
+ }, /*#__PURE__*/React.createElement(Icon, {
56
+ label: label
57
+ })));
58
+ };
59
+ var InlineAppearanceIconButton = function InlineAppearanceIconButton(_ref2) {
60
+ var currentAppearance = _ref2.currentAppearance,
61
+ isDisabled = _ref2.isDisabled,
62
+ label = _ref2.label,
63
+ onClick = _ref2.onClick;
64
+ return /*#__PURE__*/React.createElement(AppearanceOptionIconButton, {
65
+ appearance: "inline",
66
+ currentAppearance: currentAppearance,
67
+ isDisabled: isDisabled,
68
+ label: label,
69
+ Icon: SmartLinkInlineIcon,
70
+ onClick: onClick
71
+ });
72
+ };
73
+ var BlockAppearanceIconButton = function BlockAppearanceIconButton(_ref3) {
74
+ var currentAppearance = _ref3.currentAppearance,
75
+ isDisabled = _ref3.isDisabled,
76
+ label = _ref3.label,
77
+ onClick = _ref3.onClick;
78
+ return /*#__PURE__*/React.createElement(AppearanceOptionIconButton, {
79
+ appearance: "block",
80
+ currentAppearance: currentAppearance,
81
+ isDisabled: isDisabled,
82
+ label: label,
83
+ Icon: SmartLinkCardIcon,
84
+ onClick: onClick
85
+ });
86
+ };
87
+ var EmbedAppearanceIconButton = function EmbedAppearanceIconButton(_ref4) {
88
+ var currentAppearance = _ref4.currentAppearance,
89
+ isDisabled = _ref4.isDisabled,
90
+ label = _ref4.label,
91
+ onClick = _ref4.onClick;
92
+ return /*#__PURE__*/React.createElement(AppearanceOptionIconButton, {
93
+ appearance: "embed",
94
+ currentAppearance: currentAppearance,
95
+ isDisabled: isDisabled,
96
+ label: label,
97
+ Icon: SmartLinkEmbedIcon,
98
+ onClick: onClick
99
+ });
100
+ };
101
+ var getCurrentPastedSlice = function getCurrentPastedSlice(api) {
102
+ var _apiWithPaste$paste, _pasteState$lastConte;
103
+ var apiWithPaste = api;
104
+ var pasteState = apiWithPaste === null || apiWithPaste === void 0 || (_apiWithPaste$paste = apiWithPaste.paste) === null || _apiWithPaste$paste === void 0 ? void 0 : _apiWithPaste$paste.sharedState.currentState();
105
+ var slice = pasteState === null || pasteState === void 0 || (_pasteState$lastConte = pasteState.lastContentPasted) === null || _pasteState$lastConte === void 0 ? void 0 : _pasteState$lastConte.pastedSlice;
106
+ return slice;
107
+ };
108
+ var getCardUrlAtPasteRange = function getCardUrlAtPasteRange(_ref5) {
109
+ var _editorView$state$doc, _maybeAttrs$url, _maybeAttrs$data;
110
+ var editorView = _ref5.editorView,
111
+ pasteStartPos = _ref5.pasteStartPos,
112
+ pasteEndPos = _ref5.pasteEndPos;
113
+ var cardAtPasteRange = getCardAtPasteRange(editorView.state, pasteStartPos, pasteEndPos);
114
+ var maybeAttrs = cardAtPasteRange ? (_editorView$state$doc = editorView.state.doc.nodeAt(cardAtPasteRange.pos)) === null || _editorView$state$doc === void 0 ? void 0 : _editorView$state$doc.attrs : undefined;
115
+ var maybeUrl = (_maybeAttrs$url = maybeAttrs === null || maybeAttrs === void 0 ? void 0 : maybeAttrs.url) !== null && _maybeAttrs$url !== void 0 ? _maybeAttrs$url : maybeAttrs === null || maybeAttrs === void 0 || (_maybeAttrs$data = maybeAttrs.data) === null || _maybeAttrs$data === void 0 ? void 0 : _maybeAttrs$data.url;
116
+ return typeof maybeUrl === 'string' ? maybeUrl : undefined;
117
+ };
118
+ export var setAppearanceSelection = function setAppearanceSelection(_ref6) {
119
+ var editorView = _ref6.editorView,
120
+ pasteStartPos = _ref6.pasteStartPos,
121
+ pasteEndPos = _ref6.pasteEndPos,
122
+ targetPos = _ref6.targetPos;
123
+ var state = editorView.state,
124
+ dispatch = editorView.dispatch;
125
+ var maxPos = state.doc.content.size;
126
+ var clampedStart = Math.max(0, Math.min(pasteStartPos, maxPos));
127
+ var clampedEnd = Math.max(0, Math.min(pasteEndPos, maxPos));
128
+ var from = Math.min(clampedStart, clampedEnd);
129
+ var to = Math.max(clampedStart, clampedEnd);
130
+ var isTargetPosInBounds = targetPos !== undefined && targetPos >= 0 && targetPos <= state.doc.content.size;
131
+ try {
132
+ var nextSelection = isTargetPosInBounds && targetPos !== undefined ? NodeSelection.create(state.doc, targetPos) : TextSelection.create(state.doc, from, to);
133
+ var tr = state.tr.setSelection(nextSelection);
134
+ dispatch(tr);
135
+ return true;
136
+ } catch (_unused) {
137
+ return false;
138
+ }
139
+ };
140
+ export var getFirstLinkRangeInSelection = function getFirstLinkRangeInSelection(editorView) {
141
+ var state = editorView.state;
142
+ var linkMarkType = state.schema.marks.link;
143
+ if (!linkMarkType) {
144
+ return;
145
+ }
146
+ var firstLinkRange;
147
+ state.doc.nodesBetween(state.selection.from, state.selection.to, function (node, pos) {
148
+ if (firstLinkRange || !node.isText) {
149
+ return;
150
+ }
151
+ if (linkMarkType.isInSet(node.marks)) {
152
+ firstLinkRange = {
153
+ from: pos,
154
+ to: pos + node.nodeSize
155
+ };
156
+ }
157
+ });
158
+ return firstLinkRange;
159
+ };
160
+ export var normalizeSelectionToLinkRangeForUrlAppearance = function normalizeSelectionToLinkRangeForUrlAppearance(_ref7) {
161
+ var editorView = _ref7.editorView,
162
+ targetPos = _ref7.targetPos;
163
+ if (targetPos !== undefined || getActiveLinkMark(editorView.state)) {
164
+ return;
165
+ }
166
+ var firstLinkRange = getFirstLinkRangeInSelection(editorView);
167
+ if (!firstLinkRange) {
168
+ return;
169
+ }
170
+ var linkRangeSelectionTr = editorView.state.tr.setSelection(TextSelection.create(editorView.state.doc, firstLinkRange.from, firstLinkRange.to));
171
+ editorView.dispatch(linkRangeSelectionTr);
172
+ };
173
+ var PasteDisplayAsMenuHorizontalView = function PasteDisplayAsMenuHorizontalView(_ref8) {
174
+ var _smartCardContext$val, _getCardAtPasteRange$, _getCardAtPasteRange, _smartCardContext$val2;
175
+ var api = _ref8.api,
176
+ allowBlockCards = _ref8.allowBlockCards,
177
+ allowEmbeds = _ref8.allowEmbeds;
178
+ var intl = useIntl();
179
+ var _useEditorToolbar = useEditorToolbar(),
180
+ editorView = _useEditorToolbar.editorView;
181
+ var toolbarDropdownMenu = useToolbarDropdownMenu();
182
+ var smartCardContext = useSmartCardContext();
183
+ var frameRef = useRef(null);
184
+ var isApplyingRef = useRef(false);
185
+ var apiWithPasteOptionsToolbar = api;
186
+ var pasteRange = useSharedPluginStateWithSelector(apiWithPasteOptionsToolbar, ['pasteOptionsToolbarPlugin'], function (states) {
187
+ var pluginState = states.pasteOptionsToolbarPluginState;
188
+ return pluginState ? {
189
+ pasteEndPos: pluginState.pasteEndPos,
190
+ pasteStartPos: pluginState.pasteStartPos
191
+ } : undefined;
192
+ });
193
+ // Subscribe to card state so the menu re-renders when resolved card metadata updates.
194
+ useSharedPluginStateWithSelector(api, ['card'], function (states) {
195
+ return states.cardState;
196
+ });
197
+ var pastedLinkUrlFromSlice = getSingleSmartLinkUrlFromSlice(getCurrentPastedSlice(api));
198
+ var pastedLinkUrlFromCard = editorView && pasteRange ? getCardUrlAtPasteRange({
199
+ editorView: editorView,
200
+ pasteStartPos: pasteRange.pasteStartPos,
201
+ pasteEndPos: pasteRange.pasteEndPos
202
+ }) : undefined;
203
+ var pastedLinkUrl = pastedLinkUrlFromSlice !== null && pastedLinkUrlFromSlice !== void 0 ? pastedLinkUrlFromSlice : pastedLinkUrlFromCard;
204
+ var pastedLinkUrlState = pastedLinkUrl ? (_smartCardContext$val = smartCardContext.value) === null || _smartCardContext$val === void 0 || (_smartCardContext$val = _smartCardContext$val.store) === null || _smartCardContext$val === void 0 || (_smartCardContext$val = _smartCardContext$val.getState()) === null || _smartCardContext$val === void 0 ? void 0 : _smartCardContext$val[pastedLinkUrl] : undefined;
205
+ var hasResolvedSmartLinkData = Boolean(pastedLinkUrlState === null || pastedLinkUrlState === void 0 ? void 0 : pastedLinkUrlState.details);
206
+ var currentAppearance = editorView && pasteRange ? (_getCardAtPasteRange$ = (_getCardAtPasteRange = getCardAtPasteRange(editorView.state, pasteRange.pasteStartPos, pasteRange.pasteEndPos)) === null || _getCardAtPasteRange === void 0 ? void 0 : _getCardAtPasteRange.appearance) !== null && _getCardAtPasteRange$ !== void 0 ? _getCardAtPasteRange$ : 'url' : undefined;
207
+ var handleClick = useCallback(function (appearance) {
208
+ return function () {
209
+ if (!editorView || !pasteRange || !pastedLinkUrl || !currentAppearance || isApplyingRef.current) {
210
+ return;
211
+ }
212
+ isApplyingRef.current = true;
213
+ var state = editorView.state,
214
+ dispatch = editorView.dispatch;
215
+ var pasteStartPos = pasteRange.pasteStartPos,
216
+ pasteEndPos = pasteRange.pasteEndPos;
217
+ var cardAtPasteRange = getCardAtPasteRange(state, pasteStartPos, pasteEndPos);
218
+ if (appearance === 'url') {
219
+ if (cardAtPasteRange) {
220
+ var _state$doc$nodeAt, _api$analytics;
221
+ changeSelectedCardToLink(pastedLinkUrl, pastedLinkUrl, true, (_state$doc$nodeAt = state.doc.nodeAt(cardAtPasteRange.pos)) !== null && _state$doc$nodeAt !== void 0 ? _state$doc$nodeAt : undefined, cardAtPasteRange.pos, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions)(state, dispatch, editorView);
222
+ }
223
+ toolbarDropdownMenu === null || toolbarDropdownMenu === void 0 || toolbarDropdownMenu.closeMenu(null);
224
+ isApplyingRef.current = false;
225
+ return;
226
+ }
227
+ var targetPos = cardAtPasteRange === null || cardAtPasteRange === void 0 ? void 0 : cardAtPasteRange.pos;
228
+ if (targetPos !== undefined && targetPos < pasteStartPos) {
229
+ isApplyingRef.current = false;
230
+ return;
231
+ }
232
+ var didApplySelection = setAppearanceSelection({
233
+ editorView: editorView,
234
+ pasteStartPos: pasteStartPos,
235
+ pasteEndPos: pasteEndPos,
236
+ targetPos: targetPos
237
+ });
238
+ if (!didApplySelection) {
239
+ toolbarDropdownMenu === null || toolbarDropdownMenu === void 0 || toolbarDropdownMenu.closeMenu(null);
240
+ isApplyingRef.current = false;
241
+ return;
242
+ }
243
+ normalizeSelectionToLinkRangeForUrlAppearance({
244
+ editorView: editorView,
245
+ targetPos: targetPos
246
+ });
247
+ frameRef.current = requestAnimationFrame(function () {
248
+ var _api$analytics2;
249
+ frameRef.current = null;
250
+ setSelectedCardAppearance(appearance, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions)(editorView.state, editorView.dispatch, editorView);
251
+ toolbarDropdownMenu === null || toolbarDropdownMenu === void 0 || toolbarDropdownMenu.closeMenu(null);
252
+ isApplyingRef.current = false;
253
+ });
254
+ };
255
+ }, [api, currentAppearance, editorView, pasteRange, pastedLinkUrl, toolbarDropdownMenu]);
256
+ useEffect(function () {
257
+ return function () {
258
+ if (frameRef.current !== null) {
259
+ cancelAnimationFrame(frameRef.current);
260
+ }
261
+ isApplyingRef.current = false;
262
+ };
263
+ }, []);
264
+ if (!editorView || !pasteRange || !pastedLinkUrl || !currentAppearance) {
265
+ return null;
266
+ }
267
+ var preview = allowEmbeds && pastedLinkUrl && ((_smartCardContext$val2 = smartCardContext.value) === null || _smartCardContext$val2 === void 0 ? void 0 : _smartCardContext$val2.extractors.getPreview(pastedLinkUrl, 'web'));
268
+ var blockCardNodeType = editorView.state.schema.nodes.blockCard;
269
+ var embedCardNodeType = editorView.state.schema.nodes.embedCard;
270
+ var isBlockSupportedFromAppearanceContext = allowBlockCards && blockCardNodeType && isSupportedInParent(editorView.state, Fragment.from(blockCardNodeType.createChecked({})), currentAppearance === 'url' || currentAppearance === 'inline' ? undefined : currentAppearance);
271
+ var isEmbedSupportedFromAppearanceContext = allowEmbeds && preview && embedCardNodeType && isSupportedInParent(editorView.state, Fragment.from(embedCardNodeType.createChecked({})), currentAppearance === 'url' || currentAppearance === 'inline' ? undefined : currentAppearance);
272
+ var isSmartLinkConvertible = hasResolvedSmartLinkData;
273
+ var isBlockSupportedFromSelection = allowBlockCards && blockCardNodeType && isSupportedInParent(editorView.state, Fragment.from(blockCardNodeType.createChecked({})), undefined);
274
+ var isEmbedSupportedFromSelection = allowEmbeds && preview && embedCardNodeType && isSupportedInParent(editorView.state, Fragment.from(embedCardNodeType.createChecked({})), undefined);
275
+ var isBlockSupported = Boolean(isBlockSupportedFromAppearanceContext || isBlockSupportedFromSelection);
276
+ var isEmbedSupported = Boolean(isEmbedSupportedFromAppearanceContext || isEmbedSupportedFromSelection);
277
+ return /*#__PURE__*/React.createElement(Flex, {
278
+ xcss: styles.appearanceBox,
279
+ gap: "space.050"
280
+ }, /*#__PURE__*/React.createElement(AppearanceOptionIconButton, {
281
+ appearance: "url",
282
+ currentAppearance: currentAppearance,
283
+ isDisabled: false,
284
+ label: intl.formatMessage(appearancePropsMap.url.title),
285
+ Icon: MinusIcon,
286
+ onClick: handleClick('url')
287
+ }), /*#__PURE__*/React.createElement(InlineAppearanceIconButton, {
288
+ currentAppearance: currentAppearance,
289
+ isDisabled: !isSmartLinkConvertible,
290
+ label: intl.formatMessage(appearancePropsMap.inline.title),
291
+ onClick: handleClick('inline')
292
+ }), /*#__PURE__*/React.createElement(BlockAppearanceIconButton, {
293
+ currentAppearance: currentAppearance,
294
+ isDisabled: !isSmartLinkConvertible || !isBlockSupported,
295
+ label: intl.formatMessage(appearancePropsMap.block.title),
296
+ onClick: handleClick('block')
297
+ }), /*#__PURE__*/React.createElement(EmbedAppearanceIconButton, {
298
+ currentAppearance: currentAppearance,
299
+ isDisabled: !isEmbedSupported,
300
+ label: intl.formatMessage(appearancePropsMap.embed.title),
301
+ onClick: handleClick('embed')
302
+ }));
303
+ };
304
+ var PasteDisplayAsMenuSection = function PasteDisplayAsMenuSection(_ref9) {
305
+ var api = _ref9.api,
306
+ allowBlockCards = _ref9.allowBlockCards,
307
+ allowEmbeds = _ref9.allowEmbeds;
308
+ var intl = useIntl();
309
+ return /*#__PURE__*/React.createElement(ToolbarDropdownItemSection, {
310
+ title: intl.formatMessage({
311
+ defaultMessage: 'Display as',
312
+ description: 'Section title for Smart Link display options in the paste actions menu.',
313
+ id: 'fabric.editor.pasteDisplayAsMenu.displayAs'
314
+ })
315
+ }, /*#__PURE__*/React.createElement(PasteDisplayAsMenuHorizontalView, {
316
+ api: api,
317
+ allowBlockCards: allowBlockCards,
318
+ allowEmbeds: allowEmbeds
319
+ }));
320
+ };
321
+ export var getPasteDisplayAsMenuComponents = function getPasteDisplayAsMenuComponents(_ref0) {
322
+ var api = _ref0.api,
323
+ allowBlockCards = _ref0.allowBlockCards,
324
+ allowEmbeds = _ref0.allowEmbeds,
325
+ getEditorView = _ref0.getEditorView;
326
+ return [{
327
+ type: 'menu-section',
328
+ key: SMART_LINK_DISPLAY_AS_PASTE_MENU_SECTION_KEY,
329
+ parents: [{
330
+ type: PASTE_MENU.type,
331
+ key: PASTE_MENU.key,
332
+ rank: 60
333
+ }],
334
+ isHidden: function isHidden() {
335
+ var _apiWithPasteOptionsT;
336
+ var apiWithPasteOptionsToolbar = api;
337
+ var pasteRange = apiWithPasteOptionsToolbar === null || apiWithPasteOptionsToolbar === void 0 || (_apiWithPasteOptionsT = apiWithPasteOptionsToolbar.pasteOptionsToolbarPlugin) === null || _apiWithPasteOptionsT === void 0 ? void 0 : _apiWithPasteOptionsT.sharedState.currentState();
338
+ var editorView = getEditorView();
339
+ if (!editorView || !pasteRange) {
340
+ return true;
341
+ }
342
+ var pastedSlice = getCurrentPastedSlice(api);
343
+ var urlFromSlice = getSingleSmartLinkUrlFromSlice(pastedSlice);
344
+ var urlFromCard = getCardUrlAtPasteRange({
345
+ editorView: editorView,
346
+ pasteStartPos: pasteRange.pasteStartPos,
347
+ pasteEndPos: pasteRange.pasteEndPos
348
+ });
349
+ return !urlFromSlice && !urlFromCard;
350
+ },
351
+ component: function component() {
352
+ return /*#__PURE__*/React.createElement(PasteDisplayAsMenuSection, {
353
+ api: api,
354
+ allowBlockCards: allowBlockCards,
355
+ allowEmbeds: allowEmbeds
356
+ });
357
+ }
358
+ }];
359
+ };
@@ -0,0 +1,46 @@
1
+ var getUrlFromTextLinkNode = function getUrlFromTextLinkNode(node) {
2
+ var _node$marks$0$attrs;
3
+ if (!node.isText || node.marks.length !== 1 || node.marks[0].type.name !== 'link') {
4
+ return undefined;
5
+ }
6
+ var href = (_node$marks$0$attrs = node.marks[0].attrs) === null || _node$marks$0$attrs === void 0 ? void 0 : _node$marks$0$attrs.href;
7
+ return typeof href === 'string' && node.text === href ? href : undefined;
8
+ };
9
+ var getUrlFromInlineCardNode = function getUrlFromInlineCardNode(node) {
10
+ var _node$attrs;
11
+ if (node.type.name !== 'inlineCard') {
12
+ return undefined;
13
+ }
14
+ var url = (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.url;
15
+ return typeof url === 'string' ? url : undefined;
16
+ };
17
+ var significantChildren = function significantChildren(fragment) {
18
+ var children = [];
19
+ fragment.forEach(function (child) {
20
+ var _child$text;
21
+ if (child.isText && ((_child$text = child.text) === null || _child$text === void 0 ? void 0 : _child$text.trim()) === '') {
22
+ return;
23
+ }
24
+ children.push(child);
25
+ });
26
+ return children;
27
+ };
28
+ export var getSingleSmartLinkUrlFromSlice = function getSingleSmartLinkUrlFromSlice(slice) {
29
+ var _getUrlFromTextLinkNo, _getUrlFromTextLinkNo2;
30
+ if (!slice || slice.content.childCount !== 1) {
31
+ return undefined;
32
+ }
33
+ var topNode = slice.content.child(0);
34
+ var topNodeUrl = (_getUrlFromTextLinkNo = getUrlFromTextLinkNode(topNode)) !== null && _getUrlFromTextLinkNo !== void 0 ? _getUrlFromTextLinkNo : getUrlFromInlineCardNode(topNode);
35
+ if (topNodeUrl) {
36
+ return topNodeUrl;
37
+ }
38
+ if (topNode.type.name !== 'paragraph') {
39
+ return undefined;
40
+ }
41
+ var children = significantChildren(topNode.content);
42
+ if (children.length !== 1) {
43
+ return undefined;
44
+ }
45
+ return (_getUrlFromTextLinkNo2 = getUrlFromTextLinkNode(children[0])) !== null && _getUrlFromTextLinkNo2 !== void 0 ? _getUrlFromTextLinkNo2 : getUrlFromInlineCardNode(children[0]);
46
+ };
@@ -0,0 +1,24 @@
1
+ export var DISPLAY_AS_OPTIONS = ['url', 'inline', 'block', 'embed'];
2
+ export var getCardAtPasteRange = function getCardAtPasteRange(state, pasteStartPos, pasteEndPos) {
3
+ var result;
4
+ var docContentSize = state.doc.content.size;
5
+ var clampedStart = Math.max(0, Math.min(pasteStartPos, docContentSize));
6
+ var clampedEnd = Math.max(0, Math.min(pasteEndPos, docContentSize));
7
+ var from = Math.min(clampedStart, clampedEnd);
8
+ var to = Math.max(clampedStart, clampedEnd);
9
+ try {
10
+ state.doc.nodesBetween(from, to, function (node, pos) {
11
+ if (node.type.name === 'inlineCard' || node.type.name === 'blockCard' || node.type.name === 'embedCard') {
12
+ result = {
13
+ appearance: node.type.name === 'inlineCard' ? 'inline' : node.type.name === 'blockCard' ? 'block' : 'embed',
14
+ pos: pos
15
+ };
16
+ return false;
17
+ }
18
+ return true;
19
+ });
20
+ } catch (_unused) {
21
+ return;
22
+ }
23
+ return result;
24
+ };
@@ -15,6 +15,7 @@ import type { FloatingToolbarPlugin } from '@atlaskit/editor-plugin-floating-too
15
15
  import type { GridPlugin } from '@atlaskit/editor-plugin-grid';
16
16
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
17
17
  import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
18
+ import type { UiControlRegistryPlugin } from '@atlaskit/editor-plugin-ui-control-registry';
18
19
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
19
20
  import type { CardPluginOptions, CardPluginState } from './types';
20
21
  type DummyAnnotationPlugin = NextEditorPlugin<'annotation', {
@@ -36,7 +37,8 @@ export type CardPluginDependencies = [
36
37
  OptionalPlugin<DummyAnnotationPlugin>,
37
38
  OptionalPlugin<ConnectivityPlugin>,
38
39
  OptionalPlugin<BasePlugin>,
39
- OptionalPlugin<ToolbarPlugin>
40
+ OptionalPlugin<ToolbarPlugin>,
41
+ OptionalPlugin<UiControlRegistryPlugin>
40
42
  ];
41
43
  export type CardPlugin = NextEditorPlugin<'card', {
42
44
  actions: CardPluginActions;
@@ -122,6 +122,7 @@ export type CardPluginOptions = CardOptions & {
122
122
  disableFloatingToolbar?: boolean;
123
123
  editorAppearance?: EditorAppearance;
124
124
  embedCardTransformers?: EmbedCardTransformers;
125
+ enablePasteDisplayAsMenu?: boolean;
125
126
  fullWidthMode?: boolean;
126
127
  isPageSSRed?: boolean;
127
128
  linkPicker?: LinkPickerOptions;
@@ -0,0 +1,25 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
4
+ import type { CardPlugin } from '../cardPluginType';
5
+ export declare const SMART_LINK_DISPLAY_AS_PASTE_MENU_SECTION_KEY = "smart-link-display-as-paste-menu-section";
6
+ export declare const setAppearanceSelection: ({ editorView, pasteStartPos, pasteEndPos, targetPos, }: {
7
+ editorView: EditorView;
8
+ pasteEndPos: number;
9
+ pasteStartPos: number;
10
+ targetPos: number | undefined;
11
+ }) => boolean;
12
+ export declare const getFirstLinkRangeInSelection: (editorView: EditorView) => {
13
+ from: number;
14
+ to: number;
15
+ } | undefined;
16
+ export declare const normalizeSelectionToLinkRangeForUrlAppearance: ({ editorView, targetPos, }: {
17
+ editorView: EditorView;
18
+ targetPos: number | undefined;
19
+ }) => void;
20
+ export declare const getPasteDisplayAsMenuComponents: ({ api, allowBlockCards, allowEmbeds, getEditorView, }: {
21
+ allowBlockCards: boolean;
22
+ allowEmbeds?: boolean;
23
+ api: ExtractInjectionAPI<CardPlugin> | undefined;
24
+ getEditorView: () => EditorView | undefined;
25
+ }) => RegisterComponent[];
@@ -0,0 +1,2 @@
1
+ import type { Slice } from '@atlaskit/editor-prosemirror/model';
2
+ export declare const getSingleSmartLinkUrlFromSlice: (slice: Slice | undefined) => string | undefined;
@@ -0,0 +1,7 @@
1
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const DISPLAY_AS_OPTIONS: readonly ["url", "inline", "block", "embed"];
3
+ export type DisplayAsOption = (typeof DISPLAY_AS_OPTIONS)[number];
4
+ export declare const getCardAtPasteRange: (state: EditorState, pasteStartPos: number, pasteEndPos: number) => {
5
+ appearance: Exclude<DisplayAsOption, "url">;
6
+ pos: number;
7
+ } | undefined;
@@ -15,6 +15,7 @@ import type { FloatingToolbarPlugin } from '@atlaskit/editor-plugin-floating-too
15
15
  import type { GridPlugin } from '@atlaskit/editor-plugin-grid';
16
16
  import type { SelectionPlugin } from '@atlaskit/editor-plugin-selection';
17
17
  import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
18
+ import type { UiControlRegistryPlugin } from '@atlaskit/editor-plugin-ui-control-registry';
18
19
  import type { WidthPlugin } from '@atlaskit/editor-plugin-width';
19
20
  import type { CardPluginOptions, CardPluginState } from './types';
20
21
  type DummyAnnotationPlugin = NextEditorPlugin<'annotation', {
@@ -36,7 +37,8 @@ export type CardPluginDependencies = [
36
37
  OptionalPlugin<DummyAnnotationPlugin>,
37
38
  OptionalPlugin<ConnectivityPlugin>,
38
39
  OptionalPlugin<BasePlugin>,
39
- OptionalPlugin<ToolbarPlugin>
40
+ OptionalPlugin<ToolbarPlugin>,
41
+ OptionalPlugin<UiControlRegistryPlugin>
40
42
  ];
41
43
  export type CardPlugin = NextEditorPlugin<'card', {
42
44
  actions: CardPluginActions;
@@ -122,6 +122,7 @@ export type CardPluginOptions = CardOptions & {
122
122
  disableFloatingToolbar?: boolean;
123
123
  editorAppearance?: EditorAppearance;
124
124
  embedCardTransformers?: EmbedCardTransformers;
125
+ enablePasteDisplayAsMenu?: boolean;
125
126
  fullWidthMode?: boolean;
126
127
  isPageSSRed?: boolean;
127
128
  linkPicker?: LinkPickerOptions;
@@ -0,0 +1,25 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
3
+ import type { RegisterComponent } from '@atlaskit/editor-ui-control-model';
4
+ import type { CardPlugin } from '../cardPluginType';
5
+ export declare const SMART_LINK_DISPLAY_AS_PASTE_MENU_SECTION_KEY = "smart-link-display-as-paste-menu-section";
6
+ export declare const setAppearanceSelection: ({ editorView, pasteStartPos, pasteEndPos, targetPos, }: {
7
+ editorView: EditorView;
8
+ pasteEndPos: number;
9
+ pasteStartPos: number;
10
+ targetPos: number | undefined;
11
+ }) => boolean;
12
+ export declare const getFirstLinkRangeInSelection: (editorView: EditorView) => {
13
+ from: number;
14
+ to: number;
15
+ } | undefined;
16
+ export declare const normalizeSelectionToLinkRangeForUrlAppearance: ({ editorView, targetPos, }: {
17
+ editorView: EditorView;
18
+ targetPos: number | undefined;
19
+ }) => void;
20
+ export declare const getPasteDisplayAsMenuComponents: ({ api, allowBlockCards, allowEmbeds, getEditorView, }: {
21
+ allowBlockCards: boolean;
22
+ allowEmbeds?: boolean;
23
+ api: ExtractInjectionAPI<CardPlugin> | undefined;
24
+ getEditorView: () => EditorView | undefined;
25
+ }) => RegisterComponent[];
@@ -0,0 +1,2 @@
1
+ import type { Slice } from '@atlaskit/editor-prosemirror/model';
2
+ export declare const getSingleSmartLinkUrlFromSlice: (slice: Slice | undefined) => string | undefined;
@@ -0,0 +1,12 @@
1
+ import type { EditorState } from '@atlaskit/editor-prosemirror/state';
2
+ export declare const DISPLAY_AS_OPTIONS: readonly [
3
+ "url",
4
+ "inline",
5
+ "block",
6
+ "embed"
7
+ ];
8
+ export type DisplayAsOption = (typeof DISPLAY_AS_OPTIONS)[number];
9
+ export declare const getCardAtPasteRange: (state: EditorState, pasteStartPos: number, pasteEndPos: number) => {
10
+ appearance: Exclude<DisplayAsOption, "url">;
11
+ pos: number;
12
+ } | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "16.10.3",
3
+ "version": "16.11.1",
4
4
  "description": "Card plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -31,6 +31,8 @@
31
31
  "dependencies": {
32
32
  "@atlaskit/adf-schema": "^52.15.0",
33
33
  "@atlaskit/analytics-next": "^11.2.0",
34
+ "@atlaskit/button": "^23.11.0",
35
+ "@atlaskit/css": "^0.19.0",
34
36
  "@atlaskit/custom-steps": "^0.17.0",
35
37
  "@atlaskit/editor-card-provider": "^6.8.0",
36
38
  "@atlaskit/editor-plugin-analytics": "^10.1.0",
@@ -43,16 +45,18 @@
43
45
  "@atlaskit/editor-plugin-floating-toolbar": "^12.2.0",
44
46
  "@atlaskit/editor-plugin-grid": "^10.2.0",
45
47
  "@atlaskit/editor-plugin-toolbar": "^7.3.0",
48
+ "@atlaskit/editor-plugin-ui-control-registry": "^4.1.0",
46
49
  "@atlaskit/editor-plugin-width": "^11.1.0",
47
50
  "@atlaskit/editor-prosemirror": "^7.3.0",
48
51
  "@atlaskit/editor-shared-styles": "^3.11.0",
49
52
  "@atlaskit/editor-smart-link-draggable": "^0.5.0",
53
+ "@atlaskit/editor-toolbar": "^1.9.0",
50
54
  "@atlaskit/frontend-utilities": "^3.3.0",
51
55
  "@atlaskit/icon": "^35.3.0",
52
56
  "@atlaskit/link": "^3.4.0",
53
57
  "@atlaskit/link-analytics": "^11.1.0",
54
58
  "@atlaskit/link-client-extension": "^6.1.0",
55
- "@atlaskit/link-datasource": "^5.4.0",
59
+ "@atlaskit/link-datasource": "^5.5.0",
56
60
  "@atlaskit/link-extractors": "^2.7.0",
57
61
  "@atlaskit/linking-common": "^9.12.0",
58
62
  "@atlaskit/linking-types": "^14.4.0",
@@ -61,8 +65,8 @@
61
65
  "@atlaskit/platform-feature-flags-react": "^0.5.0",
62
66
  "@atlaskit/primitives": "^19.0.0",
63
67
  "@atlaskit/prosemirror-history": "^0.2.0",
64
- "@atlaskit/smart-card": "^44.16.0",
65
- "@atlaskit/tmp-editor-statsig": "^85.0.0",
68
+ "@atlaskit/smart-card": "^44.20.0",
69
+ "@atlaskit/tmp-editor-statsig": "^87.0.0",
66
70
  "@atlaskit/tokens": "^13.1.0",
67
71
  "@babel/runtime": "^7.0.0",
68
72
  "@emotion/react": "^11.7.1",
@@ -72,7 +76,7 @@
72
76
  "uuid": "^3.1.0"
73
77
  },
74
78
  "peerDependencies": {
75
- "@atlaskit/editor-common": "^114.50.0",
79
+ "@atlaskit/editor-common": "^114.55.0",
76
80
  "@atlaskit/link-provider": "^4.4.0",
77
81
  "react": "^18.2.0",
78
82
  "react-intl": "^5.25.1 || ^6.0.0 || ^7.0.0"