@atlaskit/editor-plugin-card 16.10.2 → 16.11.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 (38) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/dist/cjs/cardPlugin.js +50 -33
  3. package/dist/cjs/pm-plugins/doc.js +2 -2
  4. package/dist/cjs/ui/HyperlinkToolbarAppearance.js +37 -37
  5. package/dist/cjs/ui/HyperlinkToolbarAppearanceDropdown.js +37 -37
  6. package/dist/cjs/ui/PasteDisplayAsMenu.compiled.css +31 -0
  7. package/dist/cjs/ui/PasteDisplayAsMenu.js +368 -0
  8. package/dist/cjs/ui/currentPastedSmartLink.js +52 -0
  9. package/dist/cjs/ui/pasteDisplayAsUtils.js +30 -0
  10. package/dist/cjs/ui/useFetchDatasourceDataInfo.js +13 -13
  11. package/dist/cjs/ui/useFetchDatasourceInfo.js +12 -12
  12. package/dist/es2019/cardPlugin.js +17 -2
  13. package/dist/es2019/pm-plugins/doc.js +2 -2
  14. package/dist/es2019/ui/PasteDisplayAsMenu.compiled.css +31 -0
  15. package/dist/es2019/ui/PasteDisplayAsMenu.js +366 -0
  16. package/dist/es2019/ui/currentPastedSmartLink.js +46 -0
  17. package/dist/es2019/ui/pasteDisplayAsUtils.js +24 -0
  18. package/dist/esm/cardPlugin.js +50 -33
  19. package/dist/esm/pm-plugins/doc.js +2 -2
  20. package/dist/esm/ui/HyperlinkToolbarAppearance.js +36 -36
  21. package/dist/esm/ui/HyperlinkToolbarAppearanceDropdown.js +36 -36
  22. package/dist/esm/ui/PasteDisplayAsMenu.compiled.css +31 -0
  23. package/dist/esm/ui/PasteDisplayAsMenu.js +359 -0
  24. package/dist/esm/ui/currentPastedSmartLink.js +46 -0
  25. package/dist/esm/ui/pasteDisplayAsUtils.js +24 -0
  26. package/dist/esm/ui/useFetchDatasourceDataInfo.js +13 -13
  27. package/dist/esm/ui/useFetchDatasourceInfo.js +12 -12
  28. package/dist/types/cardPluginType.d.ts +3 -1
  29. package/dist/types/types/index.d.ts +1 -0
  30. package/dist/types/ui/PasteDisplayAsMenu.d.ts +25 -0
  31. package/dist/types/ui/currentPastedSmartLink.d.ts +2 -0
  32. package/dist/types/ui/pasteDisplayAsUtils.d.ts +7 -0
  33. package/dist/types-ts4.5/cardPluginType.d.ts +3 -1
  34. package/dist/types-ts4.5/types/index.d.ts +1 -0
  35. package/dist/types-ts4.5/ui/PasteDisplayAsMenu.d.ts +25 -0
  36. package/dist/types-ts4.5/ui/currentPastedSmartLink.d.ts +2 -0
  37. package/dist/types-ts4.5/ui/pasteDisplayAsUtils.d.ts +12 -0
  38. package/package.json +11 -7
@@ -377,7 +377,7 @@ export var changeSelectedCardToLink = function changeSelectedCardToLink(text, hr
377
377
  return function (state, dispatch) {
378
378
  var selectedNode = state.selection instanceof NodeSelection ? state.selection.node : undefined;
379
379
  var tr;
380
- if (node && pos) {
380
+ if (node && pos !== undefined) {
381
381
  tr = cardNodeToLinkWithTransaction(state, text, href, node, pos);
382
382
  } else {
383
383
  tr = cardToLinkWithTransaction(state, text, href);
@@ -405,7 +405,7 @@ export var changeSelectedCardToLink = function changeSelectedCardToLink(text, hr
405
405
  export var changeSelectedCardToLinkFallback = function changeSelectedCardToLinkFallback(text, href, sendAnalytics, node, pos, editorAnalyticsApi) {
406
406
  return function (state, dispatch) {
407
407
  var tr;
408
- if (node && pos) {
408
+ if (node && pos !== undefined) {
409
409
  tr = cardNodeToLinkWithTransaction(state, text, href, node, pos);
410
410
  } else {
411
411
  tr = cardToLinkWithTransaction(state, text, href);
@@ -28,21 +28,21 @@ export function HyperlinkToolbarAppearance(props) {
28
28
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
29
29
  var _props$cardOptions;
30
30
  var _props$cardOptions2;
31
- return _regeneratorRuntime.wrap(function _callee$(_context) {
31
+ return _regeneratorRuntime.wrap(function (_context) {
32
32
  while (1) switch (_context.prev = _context.next) {
33
33
  case 0:
34
34
  if (!((_props$cardOptions = props.cardOptions) !== null && _props$cardOptions !== void 0 && _props$cardOptions.provider)) {
35
- _context.next = 2;
35
+ _context.next = 1;
36
36
  break;
37
37
  }
38
38
  return _context.abrupt("return", (_props$cardOptions2 = props.cardOptions) === null || _props$cardOptions2 === void 0 ? void 0 : _props$cardOptions2.provider);
39
- case 2:
39
+ case 1:
40
40
  if (!cardProvider.current) {
41
- _context.next = 4;
41
+ _context.next = 2;
42
42
  break;
43
43
  }
44
44
  return _context.abrupt("return", cardProvider.current);
45
- case 4:
45
+ case 2:
46
46
  return _context.abrupt("return", new Promise(function (resolve) {
47
47
  var _props$editorPluginAp;
48
48
  var cardProvider = (_props$editorPluginAp = props.editorPluginApi) === null || _props$editorPluginAp === void 0 || (_props$editorPluginAp = _props$editorPluginAp.card) === null || _props$editorPluginAp === void 0 || (_props$editorPluginAp = _props$editorPluginAp.sharedState) === null || _props$editorPluginAp === void 0 || (_props$editorPluginAp = _props$editorPluginAp.currentState()) === null || _props$editorPluginAp === void 0 ? void 0 : _props$editorPluginAp.provider;
@@ -50,7 +50,7 @@ export function HyperlinkToolbarAppearance(props) {
50
50
  resolve(cardProvider);
51
51
  }
52
52
  }));
53
- case 5:
53
+ case 3:
54
54
  case "end":
55
55
  return _context.stop();
56
56
  }
@@ -62,59 +62,59 @@ export function HyperlinkToolbarAppearance(props) {
62
62
  }();
63
63
  var resolveUrl = /*#__PURE__*/function () {
64
64
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(url) {
65
- var isUrlSupported, _yield$provider$findP, provider, newMap;
66
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
65
+ var isUrlSupported, _yield$provider$findP, provider, newMap, _t, _t2, _t3, _t4;
66
+ return _regeneratorRuntime.wrap(function (_context2) {
67
67
  while (1) switch (_context2.prev = _context2.next) {
68
68
  case 0:
69
69
  if (!supportedUrlsMap.has(url)) {
70
- _context2.next = 2;
70
+ _context2.next = 1;
71
71
  break;
72
72
  }
73
73
  return _context2.abrupt("return");
74
- case 2:
74
+ case 1:
75
75
  isUrlSupported = false;
76
- _context2.prev = 3;
77
- _context2.next = 6;
76
+ _context2.prev = 2;
77
+ _context2.next = 3;
78
78
  return getProvider();
79
- case 6:
79
+ case 3:
80
80
  provider = _context2.sent;
81
- _context2.next = 9;
81
+ _context2.next = 4;
82
82
  return provider === null || provider === void 0 ? void 0 : provider.findPattern(url);
83
- case 9:
84
- _context2.t1 = _yield$provider$findP = _context2.sent;
85
- _context2.t0 = _context2.t1 !== null;
86
- if (!_context2.t0) {
87
- _context2.next = 13;
83
+ case 4:
84
+ _t2 = _yield$provider$findP = _context2.sent;
85
+ _t = _t2 !== null;
86
+ if (!_t) {
87
+ _context2.next = 5;
88
88
  break;
89
89
  }
90
- _context2.t0 = _yield$provider$findP !== void 0;
91
- case 13:
92
- if (!_context2.t0) {
93
- _context2.next = 17;
90
+ _t = _yield$provider$findP !== void 0;
91
+ case 5:
92
+ if (!_t) {
93
+ _context2.next = 6;
94
94
  break;
95
95
  }
96
- _context2.t2 = _yield$provider$findP;
97
- _context2.next = 18;
96
+ _t3 = _yield$provider$findP;
97
+ _context2.next = 7;
98
98
  break;
99
- case 17:
100
- _context2.t2 = false;
101
- case 18:
102
- isUrlSupported = _context2.t2;
103
- _context2.next = 24;
99
+ case 6:
100
+ _t3 = false;
101
+ case 7:
102
+ isUrlSupported = _t3;
103
+ _context2.next = 9;
104
104
  break;
105
- case 21:
106
- _context2.prev = 21;
107
- _context2.t3 = _context2["catch"](3);
105
+ case 8:
106
+ _context2.prev = 8;
107
+ _t4 = _context2["catch"](2);
108
108
  isUrlSupported = false;
109
- case 24:
109
+ case 9:
110
110
  newMap = new Map(supportedUrlsMap);
111
111
  newMap.set(url, isUrlSupported);
112
112
  setSupportedUrlsMap(newMap);
113
- case 27:
113
+ case 10:
114
114
  case "end":
115
115
  return _context2.stop();
116
116
  }
117
- }, _callee2, null, [[3, 21]]);
117
+ }, _callee2, null, [[2, 8]]);
118
118
  }));
119
119
  return function resolveUrl(_x) {
120
120
  return _ref2.apply(this, arguments);
@@ -36,21 +36,21 @@ var CustomHyperlinkDropdown = function CustomHyperlinkDropdown(props) {
36
36
  var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
37
37
  var _props$cardOptions;
38
38
  var _props$cardOptions2;
39
- return _regeneratorRuntime.wrap(function _callee$(_context) {
39
+ return _regeneratorRuntime.wrap(function (_context) {
40
40
  while (1) switch (_context.prev = _context.next) {
41
41
  case 0:
42
42
  if (!((_props$cardOptions = props.cardOptions) !== null && _props$cardOptions !== void 0 && _props$cardOptions.provider)) {
43
- _context.next = 2;
43
+ _context.next = 1;
44
44
  break;
45
45
  }
46
46
  return _context.abrupt("return", (_props$cardOptions2 = props.cardOptions) === null || _props$cardOptions2 === void 0 ? void 0 : _props$cardOptions2.provider);
47
- case 2:
47
+ case 1:
48
48
  if (!cardProvider.current) {
49
- _context.next = 4;
49
+ _context.next = 2;
50
50
  break;
51
51
  }
52
52
  return _context.abrupt("return", cardProvider.current);
53
- case 4:
53
+ case 2:
54
54
  return _context.abrupt("return", new Promise(function (resolve) {
55
55
  var _props$editorPluginAp2;
56
56
  var cardProvider = (_props$editorPluginAp2 = props.editorPluginApi) === null || _props$editorPluginAp2 === void 0 || (_props$editorPluginAp2 = _props$editorPluginAp2.card) === null || _props$editorPluginAp2 === void 0 || (_props$editorPluginAp2 = _props$editorPluginAp2.sharedState) === null || _props$editorPluginAp2 === void 0 || (_props$editorPluginAp2 = _props$editorPluginAp2.currentState()) === null || _props$editorPluginAp2 === void 0 ? void 0 : _props$editorPluginAp2.provider;
@@ -58,7 +58,7 @@ var CustomHyperlinkDropdown = function CustomHyperlinkDropdown(props) {
58
58
  resolve(cardProvider);
59
59
  }
60
60
  }));
61
- case 5:
61
+ case 3:
62
62
  case "end":
63
63
  return _context.stop();
64
64
  }
@@ -70,60 +70,60 @@ var CustomHyperlinkDropdown = function CustomHyperlinkDropdown(props) {
70
70
  }();
71
71
  var resolveUrl = /*#__PURE__*/function () {
72
72
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(url) {
73
- var isUrlSupported, _yield$provider$findP, provider, newMap;
74
- return _regeneratorRuntime.wrap(function _callee2$(_context2) {
73
+ var isUrlSupported, _yield$provider$findP, provider, newMap, _t, _t2, _t3, _t4;
74
+ return _regeneratorRuntime.wrap(function (_context2) {
75
75
  while (1) switch (_context2.prev = _context2.next) {
76
76
  case 0:
77
77
  if (!supportedUrlsMap.has(url)) {
78
- _context2.next = 2;
78
+ _context2.next = 1;
79
79
  break;
80
80
  }
81
81
  return _context2.abrupt("return");
82
- case 2:
82
+ case 1:
83
83
  isUrlSupported = false;
84
- _context2.prev = 3;
85
- _context2.next = 6;
84
+ _context2.prev = 2;
85
+ _context2.next = 3;
86
86
  return getProvider();
87
- case 6:
87
+ case 3:
88
88
  provider = _context2.sent;
89
- _context2.next = 9;
89
+ _context2.next = 4;
90
90
  return provider === null || provider === void 0 ? void 0 : provider.findPattern(url);
91
- case 9:
92
- _context2.t1 = _yield$provider$findP = _context2.sent;
93
- _context2.t0 = _context2.t1 !== null;
94
- if (!_context2.t0) {
95
- _context2.next = 13;
91
+ case 4:
92
+ _t2 = _yield$provider$findP = _context2.sent;
93
+ _t = _t2 !== null;
94
+ if (!_t) {
95
+ _context2.next = 5;
96
96
  break;
97
97
  }
98
- _context2.t0 = _yield$provider$findP !== void 0;
99
- case 13:
100
- if (!_context2.t0) {
101
- _context2.next = 17;
98
+ _t = _yield$provider$findP !== void 0;
99
+ case 5:
100
+ if (!_t) {
101
+ _context2.next = 6;
102
102
  break;
103
103
  }
104
- _context2.t2 = _yield$provider$findP;
105
- _context2.next = 18;
104
+ _t3 = _yield$provider$findP;
105
+ _context2.next = 7;
106
106
  break;
107
- case 17:
108
- _context2.t2 = false;
109
- case 18:
110
- isUrlSupported = _context2.t2;
111
- _context2.next = 24;
107
+ case 6:
108
+ _t3 = false;
109
+ case 7:
110
+ isUrlSupported = _t3;
111
+ _context2.next = 9;
112
112
  break;
113
- case 21:
114
- _context2.prev = 21;
115
- _context2.t3 = _context2["catch"](3);
113
+ case 8:
114
+ _context2.prev = 8;
115
+ _t4 = _context2["catch"](2);
116
116
  // eslint-disable-line no-unused-vars
117
117
  isUrlSupported = false;
118
- case 24:
118
+ case 9:
119
119
  newMap = new Map(supportedUrlsMap);
120
120
  newMap.set(url, isUrlSupported);
121
121
  setSupportedUrlsMap(newMap);
122
- case 27:
122
+ case 10:
123
123
  case "end":
124
124
  return _context2.stop();
125
125
  }
126
- }, _callee2, null, [[3, 21]]);
126
+ }, _callee2, null, [[2, 8]]);
127
127
  }));
128
128
  return function resolveUrl(_x) {
129
129
  return _ref2.apply(this, arguments);
@@ -0,0 +1,31 @@
1
+
2
+ ._2rko1qi0{border-radius:var(--ds-radius-medium,6px)}._189ee4h9{border-width:var(--ds-border-width,1px)}
3
+ ._1dqonqa1{border-style:solid}
4
+ ._1h6d1l7x{border-color:var(--ds-border,#0b120e24)}
5
+ ._1h6dbk0g{border-color:var(--ds-border-disabled,#0515240f)}
6
+ ._1h6dq98m{border-color:var(--ds-border-selected,#1868db)}
7
+ ._18u0u2gc{margin-left:var(--ds-space-100,8px)}
8
+ ._19bv1b66{padding-left:var(--ds-space-050,4px)}
9
+ ._19pku2gc{margin-top:var(--ds-space-100,8px)}
10
+ ._1bah1b1v{justify-content:space-around}
11
+ ._1bah1h6o{justify-content:center}
12
+ ._1bsb1osq{width:100%}
13
+ ._1e0c1txw{display:flex}
14
+ ._2hwxu2gc{margin-right:var(--ds-space-100,8px)}
15
+ ._4cvr1h6o{align-items:center}
16
+ ._4t3izwfg{height:2pc}
17
+ ._bfhk15s3{background-color:var(--ds-background-selected,#e9f2fe)}
18
+ ._bfhk187o{background-color:var(--ds-background-disabled,#0515240f)}
19
+ ._bfhkhfxm{background-color:var(--ds-surface-sunken,#f8f8f8)}
20
+ ._bfhksm61{background-color:var(--ds-background-neutral-subtle,#00000000)}
21
+ ._bfhkvuon{background-color:var(--ds-surface,#fff)}
22
+ ._ca0q1b66{padding-top:var(--ds-space-050,4px)}
23
+ ._n3td1b66{padding-bottom:var(--ds-space-050,4px)}
24
+ ._otyru2gc{margin-bottom:var(--ds-space-100,8px)}
25
+ ._syaz1gmx{color:var(--ds-text-disabled,#080f214a)}
26
+ ._syazi7uo{color:var(--ds-text,#292a2e)}
27
+ ._u5f31b66{padding-right:var(--ds-space-050,4px)}
28
+ ._irr31dpa:hover{background-color:var(--ds-background-neutral-subtle-hovered,#0515240f)}
29
+ ._irr3ufnl:hover{background-color:var(--ds-background-selected-hovered,#cfe1fd)}
30
+ ._1di6fcek:active{background-color:var(--ds-background-neutral-subtle-pressed,#0b120e24)}
31
+ ._1di6nozp:active{background-color:var(--ds-background-selected-pressed,#8fb8f6)}
@@ -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
+ };