@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
@@ -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
+ };
@@ -20,17 +20,17 @@ export var useFetchDatasourceDataInfo = function useFetchDatasourceDataInfo(_ref
20
20
  useEffect(function () {
21
21
  var fetchDatasource = /*#__PURE__*/function () {
22
22
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
23
- var datasourceDataRequest, _yield$getDatasourceD, meta;
24
- return _regeneratorRuntime.wrap(function _callee$(_context) {
23
+ var datasourceDataRequest, _yield$getDatasourceD, meta, _t;
24
+ return _regeneratorRuntime.wrap(function (_context) {
25
25
  while (1) switch (_context.prev = _context.next) {
26
26
  case 0:
27
27
  _context.prev = 0;
28
28
  if (!(!datasourceId || !parameters || !visibleColumnKeys)) {
29
- _context.next = 3;
29
+ _context.next = 1;
30
30
  break;
31
31
  }
32
32
  return _context.abrupt("return");
33
- case 3:
33
+ case 1:
34
34
  datasourceDataRequest = {
35
35
  parameters: parameters,
36
36
  pageSize: DEFAULT_GET_DATASOURCE_DATA_PAGE_SIZE,
@@ -38,25 +38,25 @@ export var useFetchDatasourceDataInfo = function useFetchDatasourceDataInfo(_ref
38
38
  fields: visibleColumnKeys,
39
39
  includeSchema: true
40
40
  };
41
- _context.next = 6;
41
+ _context.next = 2;
42
42
  return getDatasourceData(datasourceId, datasourceDataRequest, false);
43
- case 6:
43
+ case 2:
44
44
  _yield$getDatasourceD = _context.sent;
45
45
  meta = _yield$getDatasourceD.meta;
46
46
  setExtensionKey(meta.extensionKey);
47
- _context.next = 15;
47
+ _context.next = 4;
48
48
  break;
49
- case 11:
50
- _context.prev = 11;
51
- _context.t0 = _context["catch"](0);
49
+ case 3:
50
+ _context.prev = 3;
51
+ _t = _context["catch"](0);
52
52
  // eslint-disable-next-line no-console
53
- console.error(_context.t0);
53
+ console.error(_t);
54
54
  setExtensionKey(undefined);
55
- case 15:
55
+ case 4:
56
56
  case "end":
57
57
  return _context.stop();
58
58
  }
59
- }, _callee, null, [[0, 11]]);
59
+ }, _callee, null, [[0, 3]]);
60
60
  }));
61
61
  return function fetchDatasource() {
62
62
  return _ref2.apply(this, arguments);
@@ -32,44 +32,44 @@ export var useFetchDatasourceInfo = function useFetchDatasourceInfo(_ref) {
32
32
  useEffect(function () {
33
33
  var fetchDatasource = /*#__PURE__*/function () {
34
34
  var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
35
- var _cardContext$connecti, _datasources$, _datasources$2, response, datasources;
36
- return _regeneratorRuntime.wrap(function _callee$(_context) {
35
+ var _cardContext$connecti, _datasources$, _datasources$2, response, datasources, _t;
36
+ return _regeneratorRuntime.wrap(function (_context) {
37
37
  while (1) switch (_context.prev = _context.next) {
38
38
  case 0:
39
39
  _context.prev = 0;
40
40
  if (!(!url || !cardContext)) {
41
- _context.next = 4;
41
+ _context.next = 1;
42
42
  break;
43
43
  }
44
44
  // Don't block rendering of modal of somehow we don't get these two args --> just open with empty params
45
45
  setReady(true);
46
46
  return _context.abrupt("return");
47
- case 4:
48
- _context.next = 6;
47
+ case 1:
48
+ _context.next = 2;
49
49
  return cardContext === null || cardContext === void 0 || (_cardContext$connecti = cardContext.connections) === null || _cardContext$connecti === void 0 || (_cardContext$connecti = _cardContext$connecti.client) === null || _cardContext$connecti === void 0 ? void 0 : _cardContext$connecti.fetchData(url);
50
- case 6:
50
+ case 2:
51
51
  response = _context.sent;
52
52
  datasources = response && response.datasources || [];
53
53
  setExtensionKey(response === null || response === void 0 ? void 0 : response.meta.key);
54
54
  setDatasourceId((_datasources$ = datasources[0]) === null || _datasources$ === void 0 ? void 0 : _datasources$.id);
55
55
  setParameters((_datasources$2 = datasources[0]) === null || _datasources$2 === void 0 ? void 0 : _datasources$2.parameters);
56
56
  setReady(true);
57
- _context.next = 20;
57
+ _context.next = 4;
58
58
  break;
59
- case 14:
60
- _context.prev = 14;
61
- _context.t0 = _context["catch"](0);
59
+ case 3:
60
+ _context.prev = 3;
61
+ _t = _context["catch"](0);
62
62
  setDatasourceId(undefined);
63
63
  setParameters(undefined);
64
64
  setExtensionKey(undefined);
65
65
  // If fetch somehow errors, still set ready as true so we don't block the rendering of the modal.
66
66
  // It will just open with empty params.
67
67
  setReady(true);
68
- case 20:
68
+ case 4:
69
69
  case "end":
70
70
  return _context.stop();
71
71
  }
72
- }, _callee, null, [[0, 14]]);
72
+ }, _callee, null, [[0, 3]]);
73
73
  }));
74
74
  return function fetchDatasource() {
75
75
  return _ref2.apply(this, arguments);
@@ -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.2",
3
+ "version": "16.11.0",
4
4
  "description": "Card plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -29,8 +29,10 @@
29
29
  ],
30
30
  "atlaskit:src": "src/index.ts",
31
31
  "dependencies": {
32
- "@atlaskit/adf-schema": "^52.14.0",
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,9 +65,9 @@
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": "^84.0.0",
66
- "@atlaskit/tokens": "^13.0.0",
68
+ "@atlaskit/smart-card": "^44.19.0",
69
+ "@atlaskit/tmp-editor-statsig": "^86.0.0",
70
+ "@atlaskit/tokens": "^13.1.0",
67
71
  "@babel/runtime": "^7.0.0",
68
72
  "@emotion/react": "^11.7.1",
69
73
  "lodash": "^4.17.21",
@@ -72,7 +76,7 @@
72
76
  "uuid": "^3.1.0"
73
77
  },
74
78
  "peerDependencies": {
75
- "@atlaskit/editor-common": "^114.47.0",
79
+ "@atlaskit/editor-common": "^114.54.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"