@atlaskit/editor-plugin-card 1.10.3 → 1.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.
@@ -7,50 +7,61 @@ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbol
7
7
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
8
  import React, { useCallback } from 'react';
9
9
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
10
- import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, CONFLUENCE_SEARCH_DATASOURCE_ID, ConfluenceSearchConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
11
10
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
11
  import { hideDatasourceModal } from '../../pm-plugins/actions';
13
12
  import { insertDatasource, updateCardViaDatasource } from '../../pm-plugins/doc';
14
13
  import { useFetchDatasourceInfo } from '../useFetchDatasourceInfo';
15
14
  export var DatasourceModal = function DatasourceModal(_ref) {
16
- var _existingNode, _existingNode2, _existingNode3;
15
+ var _existingNode$attrs, _existingNode$attrs2;
17
16
  var view = _ref.view,
18
- modalType = _ref.modalType,
19
- cardContext = _ref.cardContext;
17
+ cardContext = _ref.cardContext,
18
+ defaultDatasourceId = _ref.datasourceId,
19
+ Component = _ref.componentType;
20
+ var state = view.state;
21
+ var existingNode = getExistingNode(state);
20
22
  var dispatch = view.dispatch,
21
- state = view.state;
22
- var selection = state.selection;
23
- var existingNode;
24
- if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar')) {
25
- // Check if the selection contains a link mark
26
- var $pos = state.doc.resolve(selection.from);
27
- var isLinkMark = $pos.marks().some(function (mark) {
28
- return mark.type === state.schema.marks.link;
29
- });
30
-
31
- // When selection is a TextNode and a link Mark is present return that node
32
- if (selection instanceof NodeSelection) {
33
- existingNode = selection.node;
34
- } else if (isLinkMark) {
35
- var _state$doc$nodeAt;
36
- existingNode = (_state$doc$nodeAt = state.doc.nodeAt(selection.from)) !== null && _state$doc$nodeAt !== void 0 ? _state$doc$nodeAt : undefined;
37
- }
38
- } else {
39
- existingNode = selection instanceof NodeSelection ? selection.node : undefined;
40
- }
41
- var isRegularCardNode = !!(existingNode && !((_existingNode = existingNode) !== null && _existingNode !== void 0 && (_existingNode = _existingNode.attrs) !== null && _existingNode !== void 0 && _existingNode.datasource));
23
+ transaction = view.state.tr;
24
+ var onClose = useCallback(function () {
25
+ dispatch(hideDatasourceModal(transaction));
26
+ }, [dispatch, transaction]);
27
+ var onInsert = useOnInsert(view, existingNode);
28
+ var isRegularCardNode = !!(existingNode && !(existingNode !== null && existingNode !== void 0 && (_existingNode$attrs = existingNode.attrs) !== null && _existingNode$attrs !== void 0 && _existingNode$attrs.datasource));
29
+ var _ref2 = (existingNode === null || existingNode === void 0 || (_existingNode$attrs2 = existingNode.attrs) === null || _existingNode$attrs2 === void 0 ? void 0 : _existingNode$attrs2.datasource) || {},
30
+ _ref2$id = _ref2.id,
31
+ datasourceId = _ref2$id === void 0 ? defaultDatasourceId : _ref2$id,
32
+ _ref2$views = _ref2.views,
33
+ views = _ref2$views === void 0 ? [] : _ref2$views,
34
+ nodeParameters = _ref2.parameters;
35
+ var _resolveColumnsConfig = resolveColumnsConfig(views),
36
+ visibleColumnKeys = _resolveColumnsConfig.visibleColumnKeys,
37
+ wrappedColumnKeys = _resolveColumnsConfig.wrappedColumnKeys,
38
+ columnCustomSizes = _resolveColumnsConfig.columnCustomSizes;
42
39
  var _useFetchDatasourceIn = useFetchDatasourceInfo({
43
40
  isRegularCardNode: isRegularCardNode,
44
- url: (_existingNode2 = existingNode) === null || _existingNode2 === void 0 ? void 0 : _existingNode2.attrs.url,
41
+ url: existingNode === null || existingNode === void 0 ? void 0 : existingNode.attrs.url,
45
42
  cardContext: cardContext,
46
- nodeParameters: (_existingNode3 = existingNode) === null || _existingNode3 === void 0 || (_existingNode3 = _existingNode3.attrs) === null || _existingNode3 === void 0 || (_existingNode3 = _existingNode3.datasource) === null || _existingNode3 === void 0 ? void 0 : _existingNode3.parameters
43
+ nodeParameters: nodeParameters
47
44
  }),
48
45
  parameters = _useFetchDatasourceIn.parameters,
49
46
  ready = _useFetchDatasourceIn.ready;
50
- var onClose = useCallback(function () {
51
- dispatch(hideDatasourceModal(view.state.tr));
52
- }, [dispatch, view.state.tr]);
53
- var onInsert = useCallback(function (newAdf, analyticEvent) {
47
+ if (!ready) {
48
+ return null;
49
+ }
50
+ return /*#__PURE__*/React.createElement(Component, {
51
+ datasourceId: datasourceId,
52
+ viewMode: isRegularCardNode ? 'inline' : 'table' // Want non-datasource cards to open in inline view since they are in table view
53
+ ,
54
+ parameters: parameters,
55
+ url: existingNode === null || existingNode === void 0 ? void 0 : existingNode.attrs.url,
56
+ visibleColumnKeys: visibleColumnKeys,
57
+ columnCustomSizes: columnCustomSizes,
58
+ wrappedColumnKeys: wrappedColumnKeys,
59
+ onCancel: onClose,
60
+ onInsert: onInsert
61
+ });
62
+ };
63
+ var useOnInsert = function useOnInsert(view, existingNode) {
64
+ return useCallback(function (newAdf, analyticEvent) {
54
65
  if (analyticEvent) {
55
66
  analyticEvent.update(function (payload) {
56
67
  return _objectSpread(_objectSpread({}, payload), {}, {
@@ -72,143 +83,63 @@ export var DatasourceModal = function DatasourceModal(_ref) {
72
83
  insertDatasource(view.state, newAdf, view, analyticEvent);
73
84
  }
74
85
  }, [existingNode, view]);
75
- if (modalType === 'jira') {
76
- var _existingNode4, _tableView$properties, _existingNode5;
77
- if (!ready) {
78
- return null;
79
- }
80
- var _ref2 = ((_existingNode4 = existingNode) === null || _existingNode4 === void 0 || (_existingNode4 = _existingNode4.attrs) === null || _existingNode4 === void 0 ? void 0 : _existingNode4.datasource) || {},
81
- _ref2$id = _ref2.id,
82
- datasourceId = _ref2$id === void 0 ? JIRA_LIST_OF_LINKS_DATASOURCE_ID : _ref2$id,
83
- _ref2$views = _ref2.views,
84
- views = _ref2$views === void 0 ? [] : _ref2$views;
85
- var _ref3 = views,
86
- _ref4 = _slicedToArray(_ref3, 1),
87
- tableView = _ref4[0];
88
- var visibleColumnKeys = [];
89
- var wrappedColumnKeys = [];
90
- var columnCustomSizes;
91
- var columns = tableView === null || tableView === void 0 || (_tableView$properties = tableView.properties) === null || _tableView$properties === void 0 ? void 0 : _tableView$properties.columns;
92
- if (columns) {
93
- columnCustomSizes = {};
94
- var _iterator = _createForOfIteratorHelper(columns),
95
- _step;
96
- try {
97
- for (_iterator.s(); !(_step = _iterator.n()).done;) {
98
- var _step$value = _step.value,
99
- _key = _step$value.key,
100
- width = _step$value.width,
101
- isWrapped = _step$value.isWrapped;
102
- visibleColumnKeys.push(_key);
103
- if (width) {
104
- columnCustomSizes[_key] = width;
105
- }
106
- if (isWrapped) {
107
- wrappedColumnKeys.push(_key);
108
- }
109
- }
110
- } catch (err) {
111
- _iterator.e(err);
112
- } finally {
113
- _iterator.f();
114
- }
115
- }
116
- return /*#__PURE__*/React.createElement("div", {
117
- "data-testid": "jira-config-modal"
118
- }, /*#__PURE__*/React.createElement(JiraIssuesConfigModal, {
119
- datasourceId: datasourceId,
120
- viewMode: isRegularCardNode ? 'inline' : 'table' // Want non-datasource cards to open in inline view since they are in table view
121
- ,
122
- visibleColumnKeys: visibleColumnKeys,
123
- parameters: parameters,
124
- url: (_existingNode5 = existingNode) === null || _existingNode5 === void 0 ? void 0 : _existingNode5.attrs.url,
125
- columnCustomSizes: columnCustomSizes,
126
- wrappedColumnKeys: wrappedColumnKeys,
127
- onCancel: onClose,
128
- onInsert: onInsert
129
- }));
130
- }
131
- if (modalType === 'assets') {
132
- var _existingNode6, _tableView$properties2;
133
- var _ref5 = ((_existingNode6 = existingNode) === null || _existingNode6 === void 0 || (_existingNode6 = _existingNode6.attrs) === null || _existingNode6 === void 0 ? void 0 : _existingNode6.datasource) || {},
134
- _ref5$id = _ref5.id,
135
- _datasourceId = _ref5$id === void 0 ? ASSETS_LIST_OF_LINKS_DATASOURCE_ID : _ref5$id,
136
- _parameters = _ref5.parameters,
137
- _ref5$views = _ref5.views,
138
- _views = _ref5$views === void 0 ? [] : _ref5$views;
139
- var _ref6 = _views,
140
- _ref7 = _slicedToArray(_ref6, 1),
141
- _tableView = _ref7[0];
142
- var _visibleColumnKeys = _tableView === null || _tableView === void 0 || (_tableView$properties2 = _tableView.properties) === null || _tableView$properties2 === void 0 ? void 0 : _tableView$properties2.columns.map(function (column) {
143
- return column.key;
86
+ };
87
+ var getExistingNode = function getExistingNode(state) {
88
+ var selection = state.selection;
89
+ var existingNode;
90
+ if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar')) {
91
+ // Check if the selection contains a link mark
92
+ var isLinkMark = state.doc.resolve(selection.from).marks().some(function (mark) {
93
+ return mark.type === state.schema.marks.link;
144
94
  });
145
- return /*#__PURE__*/React.createElement("div", {
146
- "data-testid": "assets-config-modal"
147
- }, /*#__PURE__*/React.createElement(AssetsConfigModal, {
148
- datasourceId: _datasourceId,
149
- visibleColumnKeys: _visibleColumnKeys,
150
- parameters: _parameters,
151
- onCancel: onClose,
152
- onInsert: onInsert
153
- }));
154
- }
155
95
 
156
- // TODO: further refactor in https://product-fabric.atlassian.net/browse/EDM-9637
157
- if (modalType === 'confluence-search') {
158
- var _existingNode7, _tableView2$propertie, _existingNode8;
159
- if (!ready) {
160
- return null;
96
+ // When selection is a TextNode and a link Mark is present return that node
97
+ if (selection instanceof NodeSelection) {
98
+ existingNode = selection.node;
99
+ } else if (isLinkMark) {
100
+ var _state$doc$nodeAt;
101
+ existingNode = (_state$doc$nodeAt = state.doc.nodeAt(selection.from)) !== null && _state$doc$nodeAt !== void 0 ? _state$doc$nodeAt : undefined;
161
102
  }
162
- var _ref8 = ((_existingNode7 = existingNode) === null || _existingNode7 === void 0 || (_existingNode7 = _existingNode7.attrs) === null || _existingNode7 === void 0 ? void 0 : _existingNode7.datasource) || {},
163
- _ref8$id = _ref8.id,
164
- _datasourceId2 = _ref8$id === void 0 ? CONFLUENCE_SEARCH_DATASOURCE_ID : _ref8$id,
165
- _parameters2 = _ref8.parameters,
166
- _ref8$views = _ref8.views,
167
- _views2 = _ref8$views === void 0 ? [] : _ref8$views;
168
- var _ref9 = _views2,
169
- _ref10 = _slicedToArray(_ref9, 1),
170
- _tableView2 = _ref10[0];
171
- var _visibleColumnKeys2 = [];
172
- var _wrappedColumnKeys = [];
173
- var _columnCustomSizes;
174
- var _columns = _tableView2 === null || _tableView2 === void 0 || (_tableView2$propertie = _tableView2.properties) === null || _tableView2$propertie === void 0 ? void 0 : _tableView2$propertie.columns;
175
- if (_columns) {
176
- _columnCustomSizes = {};
177
- var _iterator2 = _createForOfIteratorHelper(_columns),
178
- _step2;
179
- try {
180
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
181
- var _step2$value = _step2.value,
182
- _key2 = _step2$value.key,
183
- _width = _step2$value.width,
184
- _isWrapped = _step2$value.isWrapped;
185
- _visibleColumnKeys2.push(_key2);
186
- if (_width) {
187
- _columnCustomSizes[_key2] = _width;
188
- }
189
- if (_isWrapped) {
190
- _wrappedColumnKeys.push(_key2);
191
- }
103
+ } else {
104
+ existingNode = selection instanceof NodeSelection ? selection.node : undefined;
105
+ }
106
+ return existingNode;
107
+ };
108
+ var resolveColumnsConfig = function resolveColumnsConfig(views) {
109
+ var _tableView$properties;
110
+ var _views = _slicedToArray(views, 1),
111
+ tableView = _views[0];
112
+ var visibleColumnKeys = [];
113
+ var wrappedColumnKeys = [];
114
+ var columnCustomSizes;
115
+ var columns = tableView === null || tableView === void 0 || (_tableView$properties = tableView.properties) === null || _tableView$properties === void 0 ? void 0 : _tableView$properties.columns;
116
+ if (columns) {
117
+ columnCustomSizes = {};
118
+ var _iterator = _createForOfIteratorHelper(columns),
119
+ _step;
120
+ try {
121
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
122
+ var _step$value = _step.value,
123
+ _key = _step$value.key,
124
+ width = _step$value.width,
125
+ isWrapped = _step$value.isWrapped;
126
+ visibleColumnKeys.push(_key);
127
+ if (width) {
128
+ columnCustomSizes[_key] = width;
129
+ }
130
+ if (isWrapped) {
131
+ wrappedColumnKeys.push(_key);
192
132
  }
193
- } catch (err) {
194
- _iterator2.e(err);
195
- } finally {
196
- _iterator2.f();
197
133
  }
134
+ } catch (err) {
135
+ _iterator.e(err);
136
+ } finally {
137
+ _iterator.f();
198
138
  }
199
- return /*#__PURE__*/React.createElement("div", {
200
- "data-testid": "confluence-search-config-modal"
201
- }, /*#__PURE__*/React.createElement(ConfluenceSearchConfigModal, {
202
- datasourceId: _datasourceId2,
203
- viewMode: isRegularCardNode ? 'inline' : 'table',
204
- visibleColumnKeys: _visibleColumnKeys2,
205
- parameters: _parameters2,
206
- url: (_existingNode8 = existingNode) === null || _existingNode8 === void 0 ? void 0 : _existingNode8.attrs.url,
207
- columnCustomSizes: _columnCustomSizes,
208
- wrappedColumnKeys: _wrappedColumnKeys,
209
- onCancel: onClose,
210
- onInsert: onInsert
211
- }));
212
139
  }
213
- return null; // null for now until we have modal component that handles other datasources
140
+ return {
141
+ visibleColumnKeys: visibleColumnKeys,
142
+ wrappedColumnKeys: wrappedColumnKeys,
143
+ columnCustomSizes: columnCustomSizes
144
+ };
214
145
  };
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { GlyphProps } from '@atlaskit/icon/types';
3
+ export declare const DatasourceIcon: (props: GlyphProps) => JSX.Element;
@@ -1,9 +1,19 @@
1
- /// <reference types="react" />
2
- import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
1
+ import React from 'react';
2
+ import type { DatasourceModalType, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { ConfigModalProps } from '@atlaskit/link-datasource/src/common/types';
5
+ import type { DatasourceAdf, InlineCardAdf } from '@atlaskit/linking-common';
6
+ import type { DatasourceParameters } from '@atlaskit/linking-types';
4
7
  import type { cardPlugin } from '../../plugin';
5
8
  declare const ModalWithState: ({ api, editorView, }: {
6
9
  api: ExtractInjectionAPI<typeof cardPlugin> | undefined;
7
10
  editorView: EditorView;
8
11
  }) => JSX.Element | null;
12
+ export type ModalTypeToComponentMap = {
13
+ componentType: React.ComponentType<ConfigModalProps<InlineCardAdf | DatasourceAdf, DatasourceParameters>>;
14
+ datasourceId: string;
15
+ };
16
+ export declare const modalTypeToComponentMap: {
17
+ [key in DatasourceModalType]: ModalTypeToComponentMap;
18
+ };
9
19
  export default ModalWithState;
@@ -1,13 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
- import type { DatasourceModalType } from '@atlaskit/editor-common/types';
4
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
4
  import type { CardContext } from '@atlaskit/smart-card';
5
+ import type { ModalTypeToComponentMap } from './ModalWithState';
6
6
  type DatasourceModalProps = {
7
7
  view: EditorView;
8
8
  editorAnalyticsApi?: EditorAnalyticsAPI;
9
- modalType?: DatasourceModalType;
10
9
  cardContext?: CardContext;
11
- };
12
- export declare const DatasourceModal: ({ view, modalType, cardContext, }: DatasourceModalProps) => JSX.Element | null;
10
+ } & ModalTypeToComponentMap;
11
+ export declare const DatasourceModal: ({ view, cardContext, datasourceId: defaultDatasourceId, componentType: Component, }: DatasourceModalProps) => JSX.Element | null;
13
12
  export {};
@@ -0,0 +1,3 @@
1
+ /// <reference types="react" />
2
+ import type { GlyphProps } from '@atlaskit/icon/types';
3
+ export declare const DatasourceIcon: (props: GlyphProps) => JSX.Element;
@@ -1,9 +1,19 @@
1
- /// <reference types="react" />
2
- import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
1
+ import React from 'react';
2
+ import type { DatasourceModalType, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
+ import type { ConfigModalProps } from '@atlaskit/link-datasource/src/common/types';
5
+ import type { DatasourceAdf, InlineCardAdf } from '@atlaskit/linking-common';
6
+ import type { DatasourceParameters } from '@atlaskit/linking-types';
4
7
  import type { cardPlugin } from '../../plugin';
5
8
  declare const ModalWithState: ({ api, editorView, }: {
6
9
  api: ExtractInjectionAPI<typeof cardPlugin> | undefined;
7
10
  editorView: EditorView;
8
11
  }) => JSX.Element | null;
12
+ export type ModalTypeToComponentMap = {
13
+ componentType: React.ComponentType<ConfigModalProps<InlineCardAdf | DatasourceAdf, DatasourceParameters>>;
14
+ datasourceId: string;
15
+ };
16
+ export declare const modalTypeToComponentMap: {
17
+ [key in DatasourceModalType]: ModalTypeToComponentMap;
18
+ };
9
19
  export default ModalWithState;
@@ -1,13 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
- import type { DatasourceModalType } from '@atlaskit/editor-common/types';
4
3
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
5
4
  import type { CardContext } from '@atlaskit/smart-card';
5
+ import type { ModalTypeToComponentMap } from './ModalWithState';
6
6
  type DatasourceModalProps = {
7
7
  view: EditorView;
8
8
  editorAnalyticsApi?: EditorAnalyticsAPI;
9
- modalType?: DatasourceModalType;
10
9
  cardContext?: CardContext;
11
- };
12
- export declare const DatasourceModal: ({ view, modalType, cardContext, }: DatasourceModalProps) => JSX.Element | null;
10
+ } & ModalTypeToComponentMap;
11
+ export declare const DatasourceModal: ({ view, cardContext, datasourceId: defaultDatasourceId, componentType: Component, }: DatasourceModalProps) => JSX.Element | null;
13
12
  export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "1.10.3",
3
+ "version": "1.11.1",
4
4
  "description": "Card plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,7 +35,7 @@
35
35
  "@atlaskit/adf-schema": "^35.12.2",
36
36
  "@atlaskit/analytics-next": "^9.3.0",
37
37
  "@atlaskit/custom-steps": "^0.1.0",
38
- "@atlaskit/editor-common": "^79.1.0",
38
+ "@atlaskit/editor-common": "^79.2.0",
39
39
  "@atlaskit/editor-plugin-analytics": "^1.1.0",
40
40
  "@atlaskit/editor-plugin-decorations": "^1.1.0",
41
41
  "@atlaskit/editor-plugin-editor-viewmode": "^1.1.0",
@@ -50,12 +50,12 @@
50
50
  "@atlaskit/icon": "^22.1.0",
51
51
  "@atlaskit/link-analytics": "^8.3.0",
52
52
  "@atlaskit/link-client-extension": "^1.8.0",
53
- "@atlaskit/link-datasource": "^2.0.0",
53
+ "@atlaskit/link-datasource": "^2.1.0",
54
54
  "@atlaskit/linking-common": "^5.6.0",
55
55
  "@atlaskit/linking-types": "^8.8.0",
56
56
  "@atlaskit/platform-feature-flags": "^0.2.0",
57
57
  "@atlaskit/primitives": "^6.1.0",
58
- "@atlaskit/smart-card": "^26.60.0",
58
+ "@atlaskit/smart-card": "^26.62.0",
59
59
  "@atlaskit/theme": "^12.7.0",
60
60
  "@atlaskit/tokens": "^1.45.0",
61
61
  "@babel/runtime": "^7.0.0",