@atlaskit/editor-plugin-card 1.14.1 → 1.14.3

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 (42) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/cjs/nodeviews/blockCard.js +9 -0
  3. package/dist/cjs/pm-plugins/doc.js +32 -11
  4. package/dist/cjs/pm-plugins/main.js +28 -6
  5. package/dist/cjs/toolbar.js +1 -1
  6. package/dist/cjs/ui/LayoutButton/index.js +11 -9
  7. package/dist/cjs/ui/LayoutButton/types.js +3 -1
  8. package/dist/cjs/ui/LayoutButton/utils.js +25 -1
  9. package/dist/cjs/utils.js +39 -1
  10. package/dist/es2019/nodeviews/blockCard.js +9 -0
  11. package/dist/es2019/pm-plugins/doc.js +33 -12
  12. package/dist/es2019/pm-plugins/main.js +24 -3
  13. package/dist/es2019/toolbar.js +2 -2
  14. package/dist/es2019/ui/LayoutButton/index.js +9 -7
  15. package/dist/es2019/ui/LayoutButton/types.js +1 -1
  16. package/dist/es2019/ui/LayoutButton/utils.js +19 -0
  17. package/dist/es2019/utils.js +36 -0
  18. package/dist/esm/nodeviews/blockCard.js +9 -0
  19. package/dist/esm/pm-plugins/doc.js +33 -12
  20. package/dist/esm/pm-plugins/main.js +24 -3
  21. package/dist/esm/toolbar.js +2 -2
  22. package/dist/esm/ui/LayoutButton/index.js +9 -7
  23. package/dist/esm/ui/LayoutButton/types.js +1 -1
  24. package/dist/esm/ui/LayoutButton/utils.js +23 -0
  25. package/dist/esm/utils.js +37 -0
  26. package/dist/types/pm-plugins/main.d.ts +2 -0
  27. package/dist/types/pm-plugins/shouldReplaceLink.d.ts +1 -1
  28. package/dist/types/pm-plugins/util/resolve.d.ts +1 -1
  29. package/dist/types/pm-plugins/util/state.d.ts +1 -1
  30. package/dist/types/types.d.ts +6 -1
  31. package/dist/types/ui/LayoutButton/types.d.ts +6 -5
  32. package/dist/types/ui/LayoutButton/utils.d.ts +7 -1
  33. package/dist/types/utils.d.ts +16 -1
  34. package/dist/types-ts4.5/pm-plugins/main.d.ts +2 -0
  35. package/dist/types-ts4.5/pm-plugins/shouldReplaceLink.d.ts +1 -1
  36. package/dist/types-ts4.5/pm-plugins/util/resolve.d.ts +1 -1
  37. package/dist/types-ts4.5/pm-plugins/util/state.d.ts +1 -1
  38. package/dist/types-ts4.5/types.d.ts +6 -1
  39. package/dist/types-ts4.5/ui/LayoutButton/types.d.ts +10 -5
  40. package/dist/types-ts4.5/ui/LayoutButton/utils.d.ts +7 -1
  41. package/dist/types-ts4.5/utils.d.ts +16 -1
  42. package/package.json +7 -4
@@ -1,4 +1,7 @@
1
1
  import { findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
+ import { isDatasourceNode } from '../../utils';
4
+ import { DATASOURCE_TABLE_LAYOUTS } from './types';
2
5
  export const getDatasource = editorView => {
3
6
  var _findSelectedNodeOfTy;
4
7
  const {
@@ -8,8 +11,24 @@ export const getDatasource = editorView => {
8
11
  const {
9
12
  blockCard
10
13
  } = schema.nodes;
14
+ if (getBooleanFF('platform.linking-platform.editor-datasource-typeguards')) {
15
+ const findResult = findSelectedNodeOfType([blockCard])(selection);
16
+ if (findResult && isDatasourceNode(findResult.node)) {
17
+ return {
18
+ ...findResult,
19
+ node: findResult.node
20
+ };
21
+ }
22
+ return {
23
+ node: undefined,
24
+ pos: undefined
25
+ };
26
+ }
11
27
  return (_findSelectedNodeOfTy = findSelectedNodeOfType([blockCard])(selection)) !== null && _findSelectedNodeOfTy !== void 0 ? _findSelectedNodeOfTy : {
12
28
  node: undefined,
13
29
  pos: undefined
14
30
  };
31
+ };
32
+ export const isDatasourceTableLayout = layout => {
33
+ return DATASOURCE_TABLE_LAYOUTS.some(l => l === layout);
15
34
  };
@@ -72,4 +72,40 @@ export const isDatasourceConfigEditable = datasourceId => {
72
72
  datasourcesWithConfigModal.push(CONFLUENCE_SEARCH_DATASOURCE_ID);
73
73
  }
74
74
  return datasourcesWithConfigModal.includes(datasourceId);
75
+ };
76
+
77
+ /**
78
+ * Typeguard that checks node attributes are datasource node attributes
79
+ * ** WARNING ** Typeguards are not a guarantee, if the asserted type changes
80
+ * this function will not be updated automatically
81
+ */
82
+ export const isDatasourceAdfAttributes = attrs => {
83
+ // Check is attributes object
84
+ if (!(typeof attrs === 'object' && attrs !== null)) {
85
+ return false;
86
+ }
87
+
88
+ // Check datasource attribute is an object
89
+ if (!('datasource' in attrs)) {
90
+ return false;
91
+ }
92
+ if (typeof attrs.datasource !== 'object' || attrs.datasource === null) {
93
+ return false;
94
+ }
95
+ const hasId = 'id' in attrs.datasource && typeof attrs.datasource.id === 'string';
96
+ const hasParameters = 'parameters' in attrs.datasource && typeof attrs.datasource.parameters === 'object' && attrs.datasource.parameters !== null && !Array.isArray(attrs.datasource.parameters);
97
+ const hasViews = 'views' in attrs.datasource && Array.isArray(attrs.datasource.views);
98
+ return hasId && hasParameters && hasViews;
99
+ };
100
+
101
+ /**
102
+ * Typeguard that checks a node is a datasource node (blockCard and has datasource attributes)
103
+ * ** WARNING ** Typeguards are not a guarantee, if the asserted type changes
104
+ * this function will not be updated automatically
105
+ */
106
+ export const isDatasourceNode = node => {
107
+ if (!node) {
108
+ return false;
109
+ }
110
+ return node.type.name === 'blockCard' && isDatasourceAdfAttributes(node.attrs);
75
111
  };
@@ -14,8 +14,10 @@ import rafSchedule from 'raf-schd';
14
14
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
15
15
  import { findOverflowScrollParent, UnsupportedBlock } from '@atlaskit/editor-common/ui';
16
16
  import { browser } from '@atlaskit/editor-common/utils';
17
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
17
18
  import { Card as SmartCard } from '@atlaskit/smart-card';
18
19
  import { registerCard } from '../pm-plugins/actions';
20
+ import { isDatasourceNode } from '../utils';
19
21
  import { Card } from './genericCard';
20
22
 
21
23
  // eslint-disable-next-line @repo/internal/react/no-class-components
@@ -147,6 +149,13 @@ export var BlockCard = /*#__PURE__*/function (_ReactNodeView) {
147
149
  key: "validUpdate",
148
150
  value: function validUpdate(currentNode, newNode) {
149
151
  var _currentNode$attrs, _newNode$attrs;
152
+ if (getBooleanFF('platform.linking-platform.editor-datasource-typeguards')) {
153
+ var _isCurrentNodeBlockCard = !isDatasourceNode(currentNode);
154
+ var _isNewNodeDatasource = isDatasourceNode(newNode);
155
+
156
+ // need to return falsy to update node
157
+ return !(_isCurrentNodeBlockCard && _isNewNodeDatasource);
158
+ }
150
159
  var isCurrentNodeBlockCard = !((_currentNode$attrs = currentNode.attrs) !== null && _currentNode$attrs !== void 0 && _currentNode$attrs.datasource);
151
160
  var isNewNodeDatasource = (_newNode$attrs = newNode.attrs) === null || _newNode$attrs === void 0 ? void 0 : _newNode$attrs.datasource;
152
161
 
@@ -10,7 +10,7 @@ import { getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged
10
10
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
11
11
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
12
12
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
13
- import { appearanceForNodeType, isDatasourceConfigEditable, selectedCardAppearance } from '../utils';
13
+ import { appearanceForNodeType, isDatasourceConfigEditable, isDatasourceNode, selectedCardAppearance } from '../utils';
14
14
  import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash } from './actions';
15
15
  import { pluginKey } from './plugin-key';
16
16
  import { shouldReplaceLink } from './shouldReplaceLink';
@@ -490,7 +490,9 @@ export var updateCardViaDatasource = function updateCardViaDatasource(args) {
490
490
  inputMethod: inputMethod
491
491
  });
492
492
  if (isDeletingConfig) {
493
- removeDatasourceStash(tr, node.attrs.url);
493
+ if (typeof node.attrs.url === 'string') {
494
+ removeDatasourceStash(tr, node.attrs.url);
495
+ }
494
496
  } else {
495
497
  hideDatasourceModal(tr);
496
498
  }
@@ -524,19 +526,38 @@ export var getAttrsForAppearance = function getAttrsForAppearance(appearance, se
524
526
  layout: 'center'
525
527
  });
526
528
  }
527
- if (selectedNode.attrs.datasource) {
528
- return {
529
- url: selectedNode.attrs.url
530
- };
529
+ if (getBooleanFF('platform.linking-platform.editor-datasource-typeguards')) {
530
+ if (isDatasourceNode(selectedNode)) {
531
+ return {
532
+ url: selectedNode.attrs.url
533
+ };
534
+ }
535
+ } else {
536
+ if (selectedNode.attrs.datasource) {
537
+ return {
538
+ url: selectedNode.attrs.url
539
+ };
540
+ }
531
541
  }
532
542
  return selectedNode.attrs;
533
543
  };
534
544
  var updateDatasourceStash = function updateDatasourceStash(tr, selectedNode) {
535
- var _selectedNode$attrs;
536
- if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar') && selectedNode !== null && selectedNode !== void 0 && (_selectedNode$attrs = selectedNode.attrs) !== null && _selectedNode$attrs !== void 0 && _selectedNode$attrs.datasource && !isDatasourceConfigEditable(selectedNode.attrs.datasource.id)) {
537
- setDatasourceStash(tr, {
538
- url: selectedNode.attrs.url,
539
- views: selectedNode.attrs.datasource.views
540
- });
545
+ if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar')) {
546
+ if (getBooleanFF('platform.linking-platform.editor-datasource-typeguards')) {
547
+ if (isDatasourceNode(selectedNode) && !isDatasourceConfigEditable(selectedNode.attrs.datasource.id) && selectedNode.attrs.url) {
548
+ setDatasourceStash(tr, {
549
+ url: selectedNode.attrs.url,
550
+ views: selectedNode.attrs.datasource.views
551
+ });
552
+ }
553
+ } else {
554
+ var _selectedNode$attrs;
555
+ if (selectedNode !== null && selectedNode !== void 0 && (_selectedNode$attrs = selectedNode.attrs) !== null && _selectedNode$attrs !== void 0 && _selectedNode$attrs.datasource && !isDatasourceConfigEditable(selectedNode.attrs.datasource.id)) {
556
+ setDatasourceStash(tr, {
557
+ url: selectedNode.attrs.url,
558
+ views: selectedNode.attrs.datasource.views
559
+ });
560
+ }
561
+ }
541
562
  }
542
563
  };
@@ -17,7 +17,8 @@ import { BlockCard } from '../nodeviews/blockCard';
17
17
  import { Datasource } from '../nodeviews/datasource';
18
18
  import { EmbedCard } from '../nodeviews/embedCard';
19
19
  import { InlineCardNodeView } from '../nodeviews/inlineCard';
20
- import { isBlockSupportedAtPosition, isEmbedSupportedAtPosition } from '../utils';
20
+ import { isDatasourceTableLayout } from '../ui/LayoutButton/utils';
21
+ import { isBlockSupportedAtPosition, isDatasourceNode, isEmbedSupportedAtPosition } from '../utils';
21
22
  import { clearOverlayCandidate, setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
22
23
  import { pluginKey } from './plugin-key';
23
24
  import reducer from './reducers';
@@ -25,6 +26,19 @@ import { handleProvider, resolveWithProvider } from './util/resolve';
25
26
  import { getNewRequests, getPluginState, getPluginStateWithUpdatedPos } from './util/state';
26
27
  export { pluginKey } from './plugin-key';
27
28
  var LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK = 'smart-link-upgrade-pulse';
29
+ export var ALLOW_EVENTS_CLASSNAME = 'card-plugin-element-allow-events';
30
+ export var stopEvent = function stopEvent(event) {
31
+ if (!getBooleanFF('platform.linking-platform.smart-links-in-live-pages')) {
32
+ return false;
33
+ }
34
+ var target = event.target;
35
+ // Stop events from propogating to prose-mirror and selecting the node and/or
36
+ // opening the toolbar, unless a parent of the target has a defined className
37
+ if (target instanceof HTMLElement && target.closest(".".concat(ALLOW_EVENTS_CLASSNAME))) {
38
+ return false;
39
+ }
40
+ return true;
41
+ };
28
42
  var handleAwarenessOverlay = function handleAwarenessOverlay(view) {
29
43
  var currentState = getPluginState(view.state);
30
44
  var overlayCandidatePos = currentState === null || currentState === void 0 ? void 0 : currentState.overlayCandidatePosition;
@@ -63,6 +77,9 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
63
77
  allowBlockCards: allowBlockCards,
64
78
  pluginInjectionApi: pluginInjectionApi,
65
79
  onClickCallback: onClickCallback
80
+ },
81
+ extraNodeViewProps: {
82
+ stopEvent: stopEvent
66
83
  }
67
84
  });
68
85
  return new SafePlugin({
@@ -156,8 +173,12 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
156
173
  var shouldUpdateTableRef = datasourceTableRef && (currentState === null || currentState === void 0 ? void 0 : currentState.datasourceTableRef) !== datasourceTableRef;
157
174
  if (isDatasource && shouldUpdateTableRef) {
158
175
  var _node$attrs2;
176
+ var getLayout = function getLayout() {
177
+ return isDatasourceTableLayout(node.attrs.layout) ? node.attrs.layout : DATASOURCE_DEFAULT_LAYOUT;
178
+ };
179
+
159
180
  // since we use the plugin state, which is a shared state, we need to update the datasourceTableRef, layout on each selection
160
- var layout = (node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.layout) || DATASOURCE_DEFAULT_LAYOUT;
181
+ var layout = getBooleanFF('platform.linking-platform.editor-datasource-typeguards') ? getLayout() : (node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.layout) || DATASOURCE_DEFAULT_LAYOUT;
161
182
  var isNested = selection.$anchor.depth > 0;
162
183
 
163
184
  // we want to disable resize button when datasource table is nested by not setting then datasourceTableRef on selection
@@ -229,7 +250,7 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
229
250
  onClickCallback: options.onClickCallback
230
251
  };
231
252
  var hasIntlContext = true;
232
- var isDatasource = !!(node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.datasource);
253
+ var isDatasource = getBooleanFF('platform.linking-platform.editor-datasource-typeguards') ? isDatasourceNode(node) : !!(node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.datasource);
233
254
  if (isDatasource) {
234
255
  var _node$attrs4;
235
256
  if (options.allowDatasource && platform !== 'mobile' && canRenderDatasource(node === null || node === void 0 || (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 || (_node$attrs4 = _node$attrs4.datasource) === null || _node$attrs4 === void 0 ? void 0 : _node$attrs4.id)) {
@@ -25,7 +25,7 @@ import { editDatasource, EditDatasourceButton } from './ui/EditDatasourceButton'
25
25
  import { buildEditLinkToolbar, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
26
26
  import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
27
27
  import { ToolbarViewedEvent } from './ui/ToolbarViewedEvent';
28
- import { appearanceForNodeType, displayInfoForCard, findCardInfo, isDatasourceConfigEditable, titleUrlPairFromNode } from './utils';
28
+ import { appearanceForNodeType, displayInfoForCard, findCardInfo, isDatasourceConfigEditable, isDatasourceNode, titleUrlPairFromNode } from './utils';
29
29
  export var removeCard = function removeCard(editorAnalyticsApi) {
30
30
  return commandWithMetadata(function (state, dispatch) {
31
31
  if (!(state.selection instanceof NodeSelection)) {
@@ -196,7 +196,7 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
196
196
  var currentAppearance = appearanceForNodeType(node.type);
197
197
  var _ref2 = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$d2 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {},
198
198
  hoverDecoration = _ref2.hoverDecoration;
199
- var isDatasource = currentAppearance === 'block' && (node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource);
199
+ var isDatasource = getBooleanFF('platform.linking-platform.editor-datasource-typeguards') ? isDatasourceNode(node) : currentAppearance === 'block' && (node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource);
200
200
  var shouldRenderDatasourceToolbar = isDatasource &&
201
201
  // not showing toolbar in mobile for now since not sure what our plans are for it
202
202
  platform !== 'mobile' && cardOptions.allowDatasource && canRenderDatasource(node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 || (_node$attrs2 = _node$attrs2.datasource) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.id);
@@ -12,9 +12,11 @@ import { getNextBreakoutMode, getTitle } from '@atlaskit/editor-common/utils';
12
12
  import CollapseIcon from '@atlaskit/icon/glyph/editor/collapse';
13
13
  import ExpandIcon from '@atlaskit/icon/glyph/editor/expand';
14
14
  import { DATASOURCE_DEFAULT_LAYOUT } from '@atlaskit/linking-common';
15
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
15
16
  import { B300, N20A, N300 } from '@atlaskit/theme/colors';
16
17
  import { setCardLayout } from '../../pm-plugins/actions';
17
- import { getDatasource } from './utils';
18
+ import { isDatasourceNode } from '../../utils';
19
+ import { getDatasource, isDatasourceTableLayout } from './utils';
18
20
  var toolbarButtonWrapperStyles = css({
19
21
  background: "".concat("var(--ds-background-neutral, ".concat(N20A, ")")),
20
22
  color: "".concat("var(--ds-icon, ".concat(N300, ")")),
@@ -78,14 +80,17 @@ var LayoutButtonWrapper = function LayoutButtonWrapper(_ref2) {
78
80
  var _getDatasource = getDatasource(editorView),
79
81
  node = _getDatasource.node,
80
82
  pos = _getDatasource.pos;
83
+ var isDatasource = getBooleanFF('platform.linking-platform.editor-datasource-typeguards') ? isDatasourceNode(node) : !!(node !== null && node !== void 0 && (_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.datasource);
84
+ if (!isDatasource) {
85
+ return null;
86
+ }
81
87
 
82
88
  // If layout doesn't exist in ADF it returns null, we want to change to undefined
83
89
  // which results in default parameter value being used in LayoutButton.
84
90
  var _ref3 = cardState !== null && cardState !== void 0 ? cardState : {},
85
91
  datasourceTableRef = _ref3.datasourceTableRef,
86
92
  _ref3$layout = _ref3.layout,
87
- layout = _ref3$layout === void 0 ? (node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.layout) || undefined : _ref3$layout;
88
- var isDatasource = !!(node !== null && node !== void 0 && (_node$attrs2 = node.attrs) !== null && _node$attrs2 !== void 0 && _node$attrs2.datasource);
93
+ layout = _ref3$layout === void 0 ? (node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.layout) || undefined : _ref3$layout;
89
94
  var onLayoutChange = function onLayoutChange(layout) {
90
95
  var _getDatasource$node;
91
96
  if (pos === undefined) {
@@ -101,15 +106,12 @@ var LayoutButtonWrapper = function LayoutButtonWrapper(_ref2) {
101
106
  tr.setMeta('scrollIntoView', false);
102
107
  dispatch(setCardLayout(layout)(tr));
103
108
  };
104
- if (!isDatasource) {
105
- return null;
106
- }
107
109
  return jsx(LayoutButton, {
108
110
  mountPoint: mountPoint,
109
111
  scrollableElement: scrollableElement,
110
112
  boundariesElement: boundariesElement,
111
113
  targetElement: datasourceTableRef,
112
- layout: layout,
114
+ layout: isDatasourceTableLayout(layout) ? layout : undefined,
113
115
  onLayoutChange: onLayoutChange,
114
116
  intl: intl
115
117
  });
@@ -1 +1 @@
1
- export {};
1
+ export var DATASOURCE_TABLE_LAYOUTS = ['full-width', 'center', 'wide'];
@@ -1,12 +1,35 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ 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; }
1
4
  import { findSelectedNodeOfType } from '@atlaskit/editor-prosemirror/utils';
5
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
6
+ import { isDatasourceNode } from '../../utils';
7
+ import { DATASOURCE_TABLE_LAYOUTS } from './types';
2
8
  export var getDatasource = function getDatasource(editorView) {
3
9
  var _findSelectedNodeOfTy;
4
10
  var _editorView$state = editorView.state,
5
11
  selection = _editorView$state.selection,
6
12
  schema = _editorView$state.schema;
7
13
  var blockCard = schema.nodes.blockCard;
14
+ if (getBooleanFF('platform.linking-platform.editor-datasource-typeguards')) {
15
+ var findResult = findSelectedNodeOfType([blockCard])(selection);
16
+ if (findResult && isDatasourceNode(findResult.node)) {
17
+ return _objectSpread(_objectSpread({}, findResult), {}, {
18
+ node: findResult.node
19
+ });
20
+ }
21
+ return {
22
+ node: undefined,
23
+ pos: undefined
24
+ };
25
+ }
8
26
  return (_findSelectedNodeOfTy = findSelectedNodeOfType([blockCard])(selection)) !== null && _findSelectedNodeOfTy !== void 0 ? _findSelectedNodeOfTy : {
9
27
  node: undefined,
10
28
  pos: undefined
11
29
  };
30
+ };
31
+ export var isDatasourceTableLayout = function isDatasourceTableLayout(layout) {
32
+ return DATASOURCE_TABLE_LAYOUTS.some(function (l) {
33
+ return l === layout;
34
+ });
12
35
  };
package/dist/esm/utils.js CHANGED
@@ -1,3 +1,4 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
1
2
  import { Fragment } from '@atlaskit/editor-prosemirror/model';
2
3
  import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
3
4
  import { getResolvedAttributes } from '@atlaskit/link-analytics/resolved-attributes';
@@ -78,4 +79,40 @@ export var isDatasourceConfigEditable = function isDatasourceConfigEditable(data
78
79
  datasourcesWithConfigModal.push(CONFLUENCE_SEARCH_DATASOURCE_ID);
79
80
  }
80
81
  return datasourcesWithConfigModal.includes(datasourceId);
82
+ };
83
+
84
+ /**
85
+ * Typeguard that checks node attributes are datasource node attributes
86
+ * ** WARNING ** Typeguards are not a guarantee, if the asserted type changes
87
+ * this function will not be updated automatically
88
+ */
89
+ export var isDatasourceAdfAttributes = function isDatasourceAdfAttributes(attrs) {
90
+ // Check is attributes object
91
+ if (!(_typeof(attrs) === 'object' && attrs !== null)) {
92
+ return false;
93
+ }
94
+
95
+ // Check datasource attribute is an object
96
+ if (!('datasource' in attrs)) {
97
+ return false;
98
+ }
99
+ if (_typeof(attrs.datasource) !== 'object' || attrs.datasource === null) {
100
+ return false;
101
+ }
102
+ var hasId = 'id' in attrs.datasource && typeof attrs.datasource.id === 'string';
103
+ var hasParameters = 'parameters' in attrs.datasource && _typeof(attrs.datasource.parameters) === 'object' && attrs.datasource.parameters !== null && !Array.isArray(attrs.datasource.parameters);
104
+ var hasViews = 'views' in attrs.datasource && Array.isArray(attrs.datasource.views);
105
+ return hasId && hasParameters && hasViews;
106
+ };
107
+
108
+ /**
109
+ * Typeguard that checks a node is a datasource node (blockCard and has datasource attributes)
110
+ * ** WARNING ** Typeguards are not a guarantee, if the asserted type changes
111
+ * this function will not be updated automatically
112
+ */
113
+ export var isDatasourceNode = function isDatasourceNode(node) {
114
+ if (!node) {
115
+ return false;
116
+ }
117
+ return node.type.name === 'blockCard' && isDatasourceAdfAttributes(node.attrs);
81
118
  };
@@ -3,4 +3,6 @@ import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/edito
3
3
  import type { cardPlugin } from '../index';
4
4
  import type { CardPluginOptions, CardPluginState } from '../types';
5
5
  export { pluginKey } from './plugin-key';
6
+ export declare const ALLOW_EVENTS_CLASSNAME = "card-plugin-element-allow-events";
7
+ export declare const stopEvent: (event: Event) => boolean;
6
8
  export declare const createPlugin: (options: CardPluginOptions, pluginInjectionApi: ExtractInjectionAPI<typeof cardPlugin> | undefined) => (pmPluginFactoryParams: PMPluginFactoryParams) => SafePlugin<CardPluginState>;
@@ -1,2 +1,2 @@
1
- import { Node } from '@atlaskit/editor-prosemirror/model';
1
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
2
2
  export declare function shouldReplaceLink(node: Node, compareLinkText?: boolean, compareToUrl?: string): boolean;
@@ -4,5 +4,5 @@ import type { CardOptions } from '@atlaskit/editor-common/card';
4
4
  import type { CardProvider, DatasourceAdf } from '@atlaskit/editor-common/provider-factory';
5
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
6
  import type { Request } from '../../types';
7
- export declare const resolveWithProvider: (view: EditorView, provider: CardProvider, request: Request, options: CardOptions, editorAnalyticsApi: EditorAnalyticsAPI | undefined, createAnalyticsEvent: CreateUIAnalyticsEvent | undefined) => Promise<void | import("@atlaskit/linking-common").InlineCardAdf | import("@atlaskit/linking-common").BlockCardAdf | import("@atlaskit/linking-common").EmbedCardAdf | DatasourceAdf<Record<string, unknown>>>;
7
+ export declare const resolveWithProvider: (view: EditorView, provider: CardProvider, request: Request, options: CardOptions, editorAnalyticsApi: EditorAnalyticsAPI | undefined, createAnalyticsEvent: CreateUIAnalyticsEvent | undefined) => Promise<void | DatasourceAdf<Record<string, unknown>> | import("@atlaskit/linking-common").InlineCardAdf | import("@atlaskit/linking-common").BlockCardAdf | import("@atlaskit/linking-common").EmbedCardAdf>;
8
8
  export declare const handleProvider: (_: 'cardProvider', provider: Promise<CardProvider> | undefined, view: EditorView) => void;
@@ -30,7 +30,7 @@ export declare const getPluginStateWithUpdatedPos: (pluginState: CardPluginState
30
30
  showDatasourceModal: boolean;
31
31
  datasourceModalType?: import("@atlaskit/editor-common/types").DatasourceModalType | undefined;
32
32
  datasourceTableRef?: HTMLElement | undefined;
33
- layout?: import("../../ui/LayoutButton/types").DatasourceTableLayout | undefined;
33
+ layout?: "full-width" | "center" | "wide" | undefined;
34
34
  inlineCardAwarenessCandidatePosition?: number | undefined;
35
35
  overlayCandidatePosition?: number | undefined;
36
36
  removeOverlay?: (() => void) | undefined;
@@ -1,13 +1,18 @@
1
+ import type { RichMediaAttributes } from '@atlaskit/adf-schema';
1
2
  import type { UIAnalyticsEvent } from '@atlaskit/analytics-next';
2
3
  import type { ACTION } from '@atlaskit/editor-common/analytics';
3
4
  import type { CardOptions, CardReplacementInputMethod, OnClickCallback } from '@atlaskit/editor-common/card';
4
5
  import type { CardAppearance, CardProvider } from '@atlaskit/editor-common/provider-factory';
5
6
  import type { DatasourceModalType, EditorAppearance, LinkPickerOptions } from '@atlaskit/editor-common/types';
6
- import type { DatasourceAdfView } from '@atlaskit/linking-common';
7
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
8
+ import type { DatasourceAdf, DatasourceAdfView } from '@atlaskit/linking-common';
7
9
  import type { SmartLinkEvents } from '@atlaskit/smart-card';
8
10
  import type { EditorCardPluginEvents } from './analytics/create-events-queue';
9
11
  import type { CardPluginEvent } from './analytics/types';
10
12
  import type { DatasourceTableLayout } from './ui/LayoutButton/types';
13
+ export type DatasourceNode = Omit<Node, 'attrs'> & {
14
+ readonly attrs: DatasourceAdf['attrs'] & Partial<RichMediaAttributes>;
15
+ };
11
16
  export type CardInfo = {
12
17
  title?: string;
13
18
  url?: string;
@@ -1,14 +1,15 @@
1
- import { IntlShape } from 'react-intl-next';
2
- import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
1
+ import type { IntlShape } from 'react-intl-next';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { cardPlugin } from '../../index';
5
- export type DatasourceTableLayout = 'full-width' | 'center' | 'wide';
5
+ export declare const DATASOURCE_TABLE_LAYOUTS: readonly ["full-width", "center", "wide"];
6
+ export type DatasourceTableLayout = (typeof DATASOURCE_TABLE_LAYOUTS)[number];
6
7
  export type LayoutButtonProps = {
7
8
  mountPoint?: HTMLElement;
8
9
  boundariesElement?: HTMLElement;
9
10
  scrollableElement?: HTMLElement;
10
11
  targetElement?: HTMLElement;
11
- layout: DatasourceTableLayout;
12
+ layout?: DatasourceTableLayout;
12
13
  onLayoutChange?: (layout: DatasourceTableLayout) => void;
13
14
  testId?: string;
14
15
  intl: IntlShape;
@@ -1,5 +1,11 @@
1
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
2
  export declare const getDatasource: (editorView: EditorView) => import("prosemirror-utils/dist/types").ContentNodeWithPos | {
3
+ node: import("../../types").DatasourceNode;
4
+ start: number;
5
+ depth: number;
6
+ pos: number;
7
+ } | {
3
8
  node: undefined;
4
9
  pos: undefined;
5
10
  };
11
+ export declare const isDatasourceTableLayout: (layout: unknown) => layout is "full-width" | "center" | "wide";
@@ -2,7 +2,7 @@ import type { CardAppearance } from '@atlaskit/editor-common/provider-factory';
2
2
  import type { Node, NodeType } from '@atlaskit/editor-prosemirror/model';
3
3
  import type { EditorState } from '@atlaskit/editor-prosemirror/state';
4
4
  import type { CardContext } from '@atlaskit/link-provider';
5
- import type { CardInfo } from './types';
5
+ import type { CardInfo, DatasourceNode } from './types';
6
6
  export declare const appearanceForNodeType: (spec: NodeType) => CardAppearance | undefined;
7
7
  export declare const selectedCardAppearance: (state: EditorState) => CardAppearance | undefined;
8
8
  export type TitleUrlPair = {
@@ -22,3 +22,18 @@ export declare const isEmbedSupportedAtPosition: (currentNodePosition: number, e
22
22
  export declare const isBlockSupportedAtPosition: (currentNodePosition: number, editorState: EditorState, currentAppearance?: CardAppearance) => boolean;
23
23
  export declare const getResolvedAttributesFromStore: (url: string, display: string | null, store?: CardContext['store']) => {};
24
24
  export declare const isDatasourceConfigEditable: (datasourceId: string) => boolean;
25
+ /**
26
+ * Typeguard that checks node attributes are datasource node attributes
27
+ * ** WARNING ** Typeguards are not a guarantee, if the asserted type changes
28
+ * this function will not be updated automatically
29
+ */
30
+ export declare const isDatasourceAdfAttributes: (attrs: Record<string, unknown> | undefined) => attrs is {
31
+ url?: string | undefined;
32
+ datasource: import("@atlaskit/linking-common").Datasource<Record<string, unknown>>;
33
+ } & Partial<import("@atlaskit/adf-schema").RichMediaAttributes>;
34
+ /**
35
+ * Typeguard that checks a node is a datasource node (blockCard and has datasource attributes)
36
+ * ** WARNING ** Typeguards are not a guarantee, if the asserted type changes
37
+ * this function will not be updated automatically
38
+ */
39
+ export declare const isDatasourceNode: (node?: Node) => node is DatasourceNode;
@@ -3,4 +3,6 @@ import type { ExtractInjectionAPI, PMPluginFactoryParams } from '@atlaskit/edito
3
3
  import type { cardPlugin } from '../index';
4
4
  import type { CardPluginOptions, CardPluginState } from '../types';
5
5
  export { pluginKey } from './plugin-key';
6
+ export declare const ALLOW_EVENTS_CLASSNAME = "card-plugin-element-allow-events";
7
+ export declare const stopEvent: (event: Event) => boolean;
6
8
  export declare const createPlugin: (options: CardPluginOptions, pluginInjectionApi: ExtractInjectionAPI<typeof cardPlugin> | undefined) => (pmPluginFactoryParams: PMPluginFactoryParams) => SafePlugin<CardPluginState>;
@@ -1,2 +1,2 @@
1
- import { Node } from '@atlaskit/editor-prosemirror/model';
1
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
2
2
  export declare function shouldReplaceLink(node: Node, compareLinkText?: boolean, compareToUrl?: string): boolean;
@@ -4,5 +4,5 @@ import type { CardOptions } from '@atlaskit/editor-common/card';
4
4
  import type { CardProvider, DatasourceAdf } from '@atlaskit/editor-common/provider-factory';
5
5
  import type { EditorView } from '@atlaskit/editor-prosemirror/view';
6
6
  import type { Request } from '../../types';
7
- export declare const resolveWithProvider: (view: EditorView, provider: CardProvider, request: Request, options: CardOptions, editorAnalyticsApi: EditorAnalyticsAPI | undefined, createAnalyticsEvent: CreateUIAnalyticsEvent | undefined) => Promise<void | import("@atlaskit/linking-common").InlineCardAdf | import("@atlaskit/linking-common").BlockCardAdf | import("@atlaskit/linking-common").EmbedCardAdf | DatasourceAdf<Record<string, unknown>>>;
7
+ export declare const resolveWithProvider: (view: EditorView, provider: CardProvider, request: Request, options: CardOptions, editorAnalyticsApi: EditorAnalyticsAPI | undefined, createAnalyticsEvent: CreateUIAnalyticsEvent | undefined) => Promise<void | DatasourceAdf<Record<string, unknown>> | import("@atlaskit/linking-common").InlineCardAdf | import("@atlaskit/linking-common").BlockCardAdf | import("@atlaskit/linking-common").EmbedCardAdf>;
8
8
  export declare const handleProvider: (_: 'cardProvider', provider: Promise<CardProvider> | undefined, view: EditorView) => void;
@@ -30,7 +30,7 @@ export declare const getPluginStateWithUpdatedPos: (pluginState: CardPluginState
30
30
  showDatasourceModal: boolean;
31
31
  datasourceModalType?: import("@atlaskit/editor-common/types").DatasourceModalType | undefined;
32
32
  datasourceTableRef?: HTMLElement | undefined;
33
- layout?: import("../../ui/LayoutButton/types").DatasourceTableLayout | undefined;
33
+ layout?: "full-width" | "center" | "wide" | undefined;
34
34
  inlineCardAwarenessCandidatePosition?: number | undefined;
35
35
  overlayCandidatePosition?: number | undefined;
36
36
  removeOverlay?: (() => void) | undefined;
@@ -1,13 +1,18 @@
1
+ import type { RichMediaAttributes } from '@atlaskit/adf-schema';
1
2
  import type { UIAnalyticsEvent } from '@atlaskit/analytics-next';
2
3
  import type { ACTION } from '@atlaskit/editor-common/analytics';
3
4
  import type { CardOptions, CardReplacementInputMethod, OnClickCallback } from '@atlaskit/editor-common/card';
4
5
  import type { CardAppearance, CardProvider } from '@atlaskit/editor-common/provider-factory';
5
6
  import type { DatasourceModalType, EditorAppearance, LinkPickerOptions } from '@atlaskit/editor-common/types';
6
- import type { DatasourceAdfView } from '@atlaskit/linking-common';
7
+ import type { Node } from '@atlaskit/editor-prosemirror/model';
8
+ import type { DatasourceAdf, DatasourceAdfView } from '@atlaskit/linking-common';
7
9
  import type { SmartLinkEvents } from '@atlaskit/smart-card';
8
10
  import type { EditorCardPluginEvents } from './analytics/create-events-queue';
9
11
  import type { CardPluginEvent } from './analytics/types';
10
12
  import type { DatasourceTableLayout } from './ui/LayoutButton/types';
13
+ export type DatasourceNode = Omit<Node, 'attrs'> & {
14
+ readonly attrs: DatasourceAdf['attrs'] & Partial<RichMediaAttributes>;
15
+ };
11
16
  export type CardInfo = {
12
17
  title?: string;
13
18
  url?: string;
@@ -1,14 +1,19 @@
1
- import { IntlShape } from 'react-intl-next';
2
- import { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
1
+ import type { IntlShape } from 'react-intl-next';
2
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
3
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
4
4
  import type { cardPlugin } from '../../index';
5
- export type DatasourceTableLayout = 'full-width' | 'center' | 'wide';
5
+ export declare const DATASOURCE_TABLE_LAYOUTS: readonly [
6
+ "full-width",
7
+ "center",
8
+ "wide"
9
+ ];
10
+ export type DatasourceTableLayout = (typeof DATASOURCE_TABLE_LAYOUTS)[number];
6
11
  export type LayoutButtonProps = {
7
12
  mountPoint?: HTMLElement;
8
13
  boundariesElement?: HTMLElement;
9
14
  scrollableElement?: HTMLElement;
10
15
  targetElement?: HTMLElement;
11
- layout: DatasourceTableLayout;
16
+ layout?: DatasourceTableLayout;
12
17
  onLayoutChange?: (layout: DatasourceTableLayout) => void;
13
18
  testId?: string;
14
19
  intl: IntlShape;
@@ -1,5 +1,11 @@
1
- import { EditorView } from '@atlaskit/editor-prosemirror/view';
1
+ import type { EditorView } from '@atlaskit/editor-prosemirror/view';
2
2
  export declare const getDatasource: (editorView: EditorView) => import("prosemirror-utils/dist/types").ContentNodeWithPos | {
3
+ node: import("../../types").DatasourceNode;
4
+ start: number;
5
+ depth: number;
6
+ pos: number;
7
+ } | {
3
8
  node: undefined;
4
9
  pos: undefined;
5
10
  };
11
+ export declare const isDatasourceTableLayout: (layout: unknown) => layout is "full-width" | "center" | "wide";