@atlaskit/editor-plugin-card 1.14.2 → 1.14.4

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 (46) hide show
  1. package/CHANGELOG.md +17 -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 +10 -5
  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 +8 -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 +8 -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/analytics/utils.d.ts +3 -3
  27. package/dist/types/pm-plugins/plugin-key.d.ts +1 -1
  28. package/dist/types/pm-plugins/shouldReplaceLink.d.ts +1 -1
  29. package/dist/types/pm-plugins/util/resolve.d.ts +1 -1
  30. package/dist/types/pm-plugins/util/state.d.ts +3 -3
  31. package/dist/types/types.d.ts +6 -1
  32. package/dist/types/ui/EditorAnalyticsContext.d.ts +1 -1
  33. package/dist/types/ui/LayoutButton/types.d.ts +6 -5
  34. package/dist/types/ui/LayoutButton/utils.d.ts +7 -1
  35. package/dist/types/utils.d.ts +16 -1
  36. package/dist/types-ts4.5/analytics/utils.d.ts +3 -3
  37. package/dist/types-ts4.5/pm-plugins/plugin-key.d.ts +1 -1
  38. package/dist/types-ts4.5/pm-plugins/shouldReplaceLink.d.ts +1 -1
  39. package/dist/types-ts4.5/pm-plugins/util/resolve.d.ts +1 -1
  40. package/dist/types-ts4.5/pm-plugins/util/state.d.ts +3 -3
  41. package/dist/types-ts4.5/types.d.ts +6 -1
  42. package/dist/types-ts4.5/ui/EditorAnalyticsContext.d.ts +1 -1
  43. package/dist/types-ts4.5/ui/LayoutButton/types.d.ts +10 -5
  44. package/dist/types-ts4.5/ui/LayoutButton/utils.d.ts +7 -1
  45. package/dist/types-ts4.5/utils.d.ts +16 -1
  46. package/package.json +7 -4
package/CHANGELOG.md CHANGED
@@ -1,5 +1,22 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 1.14.4
4
+
5
+ ### Patch Changes
6
+
7
+ - [#102478](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102478)
8
+ [`3378951608b0`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/3378951608b0) -
9
+ [ED-23332] Update adf-schema package to 36.10.1
10
+ - Updated dependencies
11
+
12
+ ## 1.14.3
13
+
14
+ ### Patch Changes
15
+
16
+ - [#102406](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/102406)
17
+ [`4e5db5fc8294`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/4e5db5fc8294) -
18
+ Minor refactors to improve type-safety. No expected functional changes.
19
+
3
20
  ## 1.14.2
4
21
 
5
22
  ### Patch Changes
@@ -19,8 +19,10 @@ var _rafSchd = _interopRequireDefault(require("raf-schd"));
19
19
  var _reactNodeView = _interopRequireDefault(require("@atlaskit/editor-common/react-node-view"));
20
20
  var _ui = require("@atlaskit/editor-common/ui");
21
21
  var _utils = require("@atlaskit/editor-common/utils");
22
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
22
23
  var _smartCard = require("@atlaskit/smart-card");
23
24
  var _actions = require("../pm-plugins/actions");
25
+ var _utils2 = require("../utils");
24
26
  var _genericCard = require("./genericCard");
25
27
  function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = (0, _getPrototypeOf2.default)(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = (0, _getPrototypeOf2.default)(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return (0, _possibleConstructorReturn2.default)(this, result); }; }
26
28
  function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); } catch (t) {} return (_isNativeReflectConstruct = function _isNativeReflectConstruct() { return !!t; })(); }
@@ -153,6 +155,13 @@ var BlockCard = exports.BlockCard = /*#__PURE__*/function (_ReactNodeView) {
153
155
  key: "validUpdate",
154
156
  value: function validUpdate(currentNode, newNode) {
155
157
  var _currentNode$attrs, _newNode$attrs;
158
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor-datasource-typeguards')) {
159
+ var _isCurrentNodeBlockCard = !(0, _utils2.isDatasourceNode)(currentNode);
160
+ var _isNewNodeDatasource = (0, _utils2.isDatasourceNode)(newNode);
161
+
162
+ // need to return falsy to update node
163
+ return !(_isCurrentNodeBlockCard && _isNewNodeDatasource);
164
+ }
156
165
  var isCurrentNodeBlockCard = !((_currentNode$attrs = currentNode.attrs) !== null && _currentNode$attrs !== void 0 && _currentNode$attrs.datasource);
157
166
  var isNewNodeDatasource = (_newNode$attrs = newNode.attrs) === null || _newNode$attrs === void 0 ? void 0 : _newNode$attrs.datasource;
158
167
 
@@ -497,7 +497,9 @@ var updateCardViaDatasource = exports.updateCardViaDatasource = function updateC
497
497
  inputMethod: inputMethod
498
498
  });
499
499
  if (isDeletingConfig) {
500
- (0, _actions.removeDatasourceStash)(tr, node.attrs.url);
500
+ if (typeof node.attrs.url === 'string') {
501
+ (0, _actions.removeDatasourceStash)(tr, node.attrs.url);
502
+ }
501
503
  } else {
502
504
  (0, _actions.hideDatasourceModal)(tr);
503
505
  }
@@ -531,19 +533,38 @@ var getAttrsForAppearance = exports.getAttrsForAppearance = function getAttrsFor
531
533
  layout: 'center'
532
534
  });
533
535
  }
534
- if (selectedNode.attrs.datasource) {
535
- return {
536
- url: selectedNode.attrs.url
537
- };
536
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor-datasource-typeguards')) {
537
+ if ((0, _utils2.isDatasourceNode)(selectedNode)) {
538
+ return {
539
+ url: selectedNode.attrs.url
540
+ };
541
+ }
542
+ } else {
543
+ if (selectedNode.attrs.datasource) {
544
+ return {
545
+ url: selectedNode.attrs.url
546
+ };
547
+ }
538
548
  }
539
549
  return selectedNode.attrs;
540
550
  };
541
551
  var updateDatasourceStash = function updateDatasourceStash(tr, selectedNode) {
542
- var _selectedNode$attrs;
543
- if ((0, _platformFeatureFlags.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 && !(0, _utils2.isDatasourceConfigEditable)(selectedNode.attrs.datasource.id)) {
544
- (0, _actions.setDatasourceStash)(tr, {
545
- url: selectedNode.attrs.url,
546
- views: selectedNode.attrs.datasource.views
547
- });
552
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-appearance-toolbar')) {
553
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor-datasource-typeguards')) {
554
+ if ((0, _utils2.isDatasourceNode)(selectedNode) && !(0, _utils2.isDatasourceConfigEditable)(selectedNode.attrs.datasource.id) && selectedNode.attrs.url) {
555
+ (0, _actions.setDatasourceStash)(tr, {
556
+ url: selectedNode.attrs.url,
557
+ views: selectedNode.attrs.datasource.views
558
+ });
559
+ }
560
+ } else {
561
+ var _selectedNode$attrs;
562
+ if (selectedNode !== null && selectedNode !== void 0 && (_selectedNode$attrs = selectedNode.attrs) !== null && _selectedNode$attrs !== void 0 && _selectedNode$attrs.datasource && !(0, _utils2.isDatasourceConfigEditable)(selectedNode.attrs.datasource.id)) {
563
+ (0, _actions.setDatasourceStash)(tr, {
564
+ url: selectedNode.attrs.url,
565
+ views: selectedNode.attrs.datasource.views
566
+ });
567
+ }
568
+ }
548
569
  }
549
570
  };
@@ -29,7 +29,8 @@ var _blockCard = require("../nodeviews/blockCard");
29
29
  var _datasource = require("../nodeviews/datasource");
30
30
  var _embedCard = require("../nodeviews/embedCard");
31
31
  var _inlineCard = require("../nodeviews/inlineCard");
32
- var _utils3 = require("../utils");
32
+ var _utils3 = require("../ui/LayoutButton/utils");
33
+ var _utils4 = require("../utils");
33
34
  var _actions = require("./actions");
34
35
  var _pluginKey = require("./plugin-key");
35
36
  var _reducers = _interopRequireDefault(require("./reducers"));
@@ -148,8 +149,8 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
148
149
  return newState;
149
150
  }
150
151
  var linkPosition = pluginState.requests[0].pos;
151
- var canBeUpgradedToBlock = allowBlockCards && (0, _utils3.isBlockSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
152
- var canBeUpgradedToEmbed = allowEmbeds && (0, _utils3.isEmbedSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
152
+ var canBeUpgradedToBlock = allowBlockCards && (0, _utils4.isBlockSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
153
+ var canBeUpgradedToEmbed = allowEmbeds && (0, _utils4.isEmbedSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
153
154
  if (canBeUpgradedToBlock || canBeUpgradedToEmbed) {
154
155
  newState.overlayCandidatePosition = linkPosition;
155
156
  }
@@ -185,8 +186,12 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
185
186
  var shouldUpdateTableRef = datasourceTableRef && (currentState === null || currentState === void 0 ? void 0 : currentState.datasourceTableRef) !== datasourceTableRef;
186
187
  if (isDatasource && shouldUpdateTableRef) {
187
188
  var _node$attrs2;
189
+ var getLayout = function getLayout() {
190
+ return (0, _utils3.isDatasourceTableLayout)(node.attrs.layout) ? node.attrs.layout : _linkingCommon.DATASOURCE_DEFAULT_LAYOUT;
191
+ };
192
+
188
193
  // since we use the plugin state, which is a shared state, we need to update the datasourceTableRef, layout on each selection
189
- var layout = (node === null || node === void 0 || (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.layout) || _linkingCommon.DATASOURCE_DEFAULT_LAYOUT;
194
+ var layout = (0, _platformFeatureFlags.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) || _linkingCommon.DATASOURCE_DEFAULT_LAYOUT;
190
195
  var isNested = selection.$anchor.depth > 0;
191
196
 
192
197
  // we want to disable resize button when datasource table is nested by not setting then datasourceTableRef on selection
@@ -258,7 +263,7 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
258
263
  onClickCallback: options.onClickCallback
259
264
  };
260
265
  var hasIntlContext = true;
261
- var isDatasource = !!(node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.datasource);
266
+ var isDatasource = (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor-datasource-typeguards') ? (0, _utils4.isDatasourceNode)(node) : !!(node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.datasource);
262
267
  if (isDatasource) {
263
268
  var _node$attrs4;
264
269
  if (options.allowDatasource && platform !== 'mobile' && (0, _utils.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)) {
@@ -206,7 +206,7 @@ var generateToolbarItems = function generateToolbarItems(state, intl, providerFa
206
206
  var currentAppearance = (0, _utils3.appearanceForNodeType)(node.type);
207
207
  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 : {},
208
208
  hoverDecoration = _ref2.hoverDecoration;
209
- var isDatasource = currentAppearance === 'block' && (node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource);
209
+ var isDatasource = (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor-datasource-typeguards') ? (0, _utils3.isDatasourceNode)(node) : currentAppearance === 'block' && (node === null || node === void 0 || (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource);
210
210
  var shouldRenderDatasourceToolbar = isDatasource &&
211
211
  // not showing toolbar in mobile for now since not sure what our plans are for it
212
212
  platform !== 'mobile' && cardOptions.allowDatasource && (0, _utils.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);
@@ -16,9 +16,11 @@ var _utils = require("@atlaskit/editor-common/utils");
16
16
  var _collapse = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/collapse"));
17
17
  var _expand = _interopRequireDefault(require("@atlaskit/icon/glyph/editor/expand"));
18
18
  var _linkingCommon = require("@atlaskit/linking-common");
19
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
19
20
  var _colors = require("@atlaskit/theme/colors");
20
21
  var _actions = require("../../pm-plugins/actions");
21
- var _utils2 = require("./utils");
22
+ var _utils2 = require("../../utils");
23
+ var _utils3 = require("./utils");
22
24
  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; }
23
25
  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) { (0, _defineProperty2.default)(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; } /** @jsx jsx */
24
26
  var toolbarButtonWrapperStyles = (0, _react2.css)({
@@ -81,17 +83,20 @@ var LayoutButtonWrapper = function LayoutButtonWrapper(_ref2) {
81
83
  api = _ref2.api;
82
84
  var _useSharedPluginState = (0, _hooks.useSharedPluginState)(api, ['card']),
83
85
  cardState = _useSharedPluginState.cardState;
84
- var _getDatasource = (0, _utils2.getDatasource)(editorView),
86
+ var _getDatasource = (0, _utils3.getDatasource)(editorView),
85
87
  node = _getDatasource.node,
86
88
  pos = _getDatasource.pos;
89
+ var isDatasource = (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor-datasource-typeguards') ? (0, _utils2.isDatasourceNode)(node) : !!(node !== null && node !== void 0 && (_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.datasource);
90
+ if (!isDatasource) {
91
+ return null;
92
+ }
87
93
 
88
94
  // If layout doesn't exist in ADF it returns null, we want to change to undefined
89
95
  // which results in default parameter value being used in LayoutButton.
90
96
  var _ref3 = cardState !== null && cardState !== void 0 ? cardState : {},
91
97
  datasourceTableRef = _ref3.datasourceTableRef,
92
98
  _ref3$layout = _ref3.layout,
93
- 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;
94
- var isDatasource = !!(node !== null && node !== void 0 && (_node$attrs2 = node.attrs) !== null && _node$attrs2 !== void 0 && _node$attrs2.datasource);
99
+ 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;
95
100
  var onLayoutChange = function onLayoutChange(layout) {
96
101
  var _getDatasource$node;
97
102
  if (pos === undefined) {
@@ -100,22 +105,19 @@ var LayoutButtonWrapper = function LayoutButtonWrapper(_ref2) {
100
105
  var state = editorView.state,
101
106
  dispatch = editorView.dispatch;
102
107
  // If the button does not re-render due to no card state change, node reference will be stale
103
- var datasourceNode = (_getDatasource$node = (0, _utils2.getDatasource)(editorView).node) !== null && _getDatasource$node !== void 0 ? _getDatasource$node : node;
108
+ var datasourceNode = (_getDatasource$node = (0, _utils3.getDatasource)(editorView).node) !== null && _getDatasource$node !== void 0 ? _getDatasource$node : node;
104
109
  var tr = state.tr.setNodeMarkup(pos, undefined, _objectSpread(_objectSpread({}, datasourceNode === null || datasourceNode === void 0 ? void 0 : datasourceNode.attrs), {}, {
105
110
  layout: layout
106
111
  }));
107
112
  tr.setMeta('scrollIntoView', false);
108
113
  dispatch((0, _actions.setCardLayout)(layout)(tr));
109
114
  };
110
- if (!isDatasource) {
111
- return null;
112
- }
113
115
  return (0, _react2.jsx)(LayoutButton, {
114
116
  mountPoint: mountPoint,
115
117
  scrollableElement: scrollableElement,
116
118
  boundariesElement: boundariesElement,
117
119
  targetElement: datasourceTableRef,
118
- layout: layout,
120
+ layout: (0, _utils3.isDatasourceTableLayout)(layout) ? layout : undefined,
119
121
  onLayoutChange: onLayoutChange,
120
122
  intl: intl
121
123
  });
@@ -2,4 +2,6 @@
2
2
 
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
- });
5
+ });
6
+ exports.DATASOURCE_TABLE_LAYOUTS = void 0;
7
+ var DATASOURCE_TABLE_LAYOUTS = exports.DATASOURCE_TABLE_LAYOUTS = ['full-width', 'center', 'wide'];
@@ -1,18 +1,42 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.getDatasource = void 0;
7
+ exports.isDatasourceTableLayout = exports.getDatasource = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
7
9
  var _utils = require("@atlaskit/editor-prosemirror/utils");
10
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
11
+ var _utils2 = require("../../utils");
12
+ var _types = require("./types");
13
+ 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; }
14
+ 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) { (0, _defineProperty2.default)(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
15
  var getDatasource = exports.getDatasource = function getDatasource(editorView) {
9
16
  var _findSelectedNodeOfTy;
10
17
  var _editorView$state = editorView.state,
11
18
  selection = _editorView$state.selection,
12
19
  schema = _editorView$state.schema;
13
20
  var blockCard = schema.nodes.blockCard;
21
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.editor-datasource-typeguards')) {
22
+ var findResult = (0, _utils.findSelectedNodeOfType)([blockCard])(selection);
23
+ if (findResult && (0, _utils2.isDatasourceNode)(findResult.node)) {
24
+ return _objectSpread(_objectSpread({}, findResult), {}, {
25
+ node: findResult.node
26
+ });
27
+ }
28
+ return {
29
+ node: undefined,
30
+ pos: undefined
31
+ };
32
+ }
14
33
  return (_findSelectedNodeOfTy = (0, _utils.findSelectedNodeOfType)([blockCard])(selection)) !== null && _findSelectedNodeOfTy !== void 0 ? _findSelectedNodeOfTy : {
15
34
  node: undefined,
16
35
  pos: undefined
17
36
  };
37
+ };
38
+ var isDatasourceTableLayout = exports.isDatasourceTableLayout = function isDatasourceTableLayout(layout) {
39
+ return _types.DATASOURCE_TABLE_LAYOUTS.some(function (l) {
40
+ return l === layout;
41
+ });
18
42
  };
package/dist/cjs/utils.js CHANGED
@@ -1,9 +1,11 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.titleUrlPairFromNode = exports.selectedCardAppearance = exports.mergeCardInfo = exports.isEmbedSupportedAtPosition = exports.isDatasourceConfigEditable = exports.isBlockSupportedAtPosition = exports.getResolvedAttributesFromStore = exports.findCardInfo = exports.displayInfoForCard = exports.appearanceForNodeType = void 0;
7
+ exports.titleUrlPairFromNode = exports.selectedCardAppearance = exports.mergeCardInfo = exports.isEmbedSupportedAtPosition = exports.isDatasourceNode = exports.isDatasourceConfigEditable = exports.isDatasourceAdfAttributes = exports.isBlockSupportedAtPosition = exports.getResolvedAttributesFromStore = exports.findCardInfo = exports.displayInfoForCard = exports.appearanceForNodeType = void 0;
8
+ var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
7
9
  var _model = require("@atlaskit/editor-prosemirror/model");
8
10
  var _state = require("@atlaskit/editor-prosemirror/state");
9
11
  var _resolvedAttributes = require("@atlaskit/link-analytics/resolved-attributes");
@@ -84,4 +86,40 @@ var isDatasourceConfigEditable = exports.isDatasourceConfigEditable = function i
84
86
  datasourcesWithConfigModal.push(_linkDatasource.CONFLUENCE_SEARCH_DATASOURCE_ID);
85
87
  }
86
88
  return datasourcesWithConfigModal.includes(datasourceId);
89
+ };
90
+
91
+ /**
92
+ * Typeguard that checks node attributes are datasource node attributes
93
+ * ** WARNING ** Typeguards are not a guarantee, if the asserted type changes
94
+ * this function will not be updated automatically
95
+ */
96
+ var isDatasourceAdfAttributes = exports.isDatasourceAdfAttributes = function isDatasourceAdfAttributes(attrs) {
97
+ // Check is attributes object
98
+ if (!((0, _typeof2.default)(attrs) === 'object' && attrs !== null)) {
99
+ return false;
100
+ }
101
+
102
+ // Check datasource attribute is an object
103
+ if (!('datasource' in attrs)) {
104
+ return false;
105
+ }
106
+ if ((0, _typeof2.default)(attrs.datasource) !== 'object' || attrs.datasource === null) {
107
+ return false;
108
+ }
109
+ var hasId = 'id' in attrs.datasource && typeof attrs.datasource.id === 'string';
110
+ var hasParameters = 'parameters' in attrs.datasource && (0, _typeof2.default)(attrs.datasource.parameters) === 'object' && attrs.datasource.parameters !== null && !Array.isArray(attrs.datasource.parameters);
111
+ var hasViews = 'views' in attrs.datasource && Array.isArray(attrs.datasource.views);
112
+ return hasId && hasParameters && hasViews;
113
+ };
114
+
115
+ /**
116
+ * Typeguard that checks a node is a datasource node (blockCard and has datasource attributes)
117
+ * ** WARNING ** Typeguards are not a guarantee, if the asserted type changes
118
+ * this function will not be updated automatically
119
+ */
120
+ var isDatasourceNode = exports.isDatasourceNode = function isDatasourceNode(node) {
121
+ if (!node) {
122
+ return false;
123
+ }
124
+ return node.type.name === 'blockCard' && isDatasourceAdfAttributes(node.attrs);
87
125
  };
@@ -5,8 +5,10 @@ import rafSchedule from 'raf-schd';
5
5
  import ReactNodeView from '@atlaskit/editor-common/react-node-view';
6
6
  import { findOverflowScrollParent, UnsupportedBlock } from '@atlaskit/editor-common/ui';
7
7
  import { browser } from '@atlaskit/editor-common/utils';
8
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
8
9
  import { Card as SmartCard } from '@atlaskit/smart-card';
9
10
  import { registerCard } from '../pm-plugins/actions';
11
+ import { isDatasourceNode } from '../utils';
10
12
  import { Card } from './genericCard';
11
13
 
12
14
  // eslint-disable-next-line @repo/internal/react/no-class-components
@@ -122,6 +124,13 @@ export class BlockCard extends ReactNodeView {
122
124
  // Otherwise, the node view will still consider the node as a blockCard and render a regular blockCard.
123
125
  validUpdate(currentNode, newNode) {
124
126
  var _currentNode$attrs, _newNode$attrs;
127
+ if (getBooleanFF('platform.linking-platform.editor-datasource-typeguards')) {
128
+ const isCurrentNodeBlockCard = !isDatasourceNode(currentNode);
129
+ const isNewNodeDatasource = isDatasourceNode(newNode);
130
+
131
+ // need to return falsy to update node
132
+ return !(isCurrentNodeBlockCard && isNewNodeDatasource);
133
+ }
125
134
  const isCurrentNodeBlockCard = !((_currentNode$attrs = currentNode.attrs) !== null && _currentNode$attrs !== void 0 && _currentNode$attrs.datasource);
126
135
  const isNewNodeDatasource = (_newNode$attrs = newNode.attrs) === null || _newNode$attrs === void 0 ? void 0 : _newNode$attrs.datasource;
127
136
 
@@ -6,7 +6,7 @@ import { getLinkCreationAnalyticsEvent, isFromCurrentDomain, nodesBetweenChanged
6
6
  import { closeHistory } from '@atlaskit/editor-prosemirror/history';
7
7
  import { NodeSelection, TextSelection } from '@atlaskit/editor-prosemirror/state';
8
8
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
- import { appearanceForNodeType, isDatasourceConfigEditable, selectedCardAppearance } from '../utils';
9
+ import { appearanceForNodeType, isDatasourceConfigEditable, isDatasourceNode, selectedCardAppearance } from '../utils';
10
10
  import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash } from './actions';
11
11
  import { pluginKey } from './plugin-key';
12
12
  import { shouldReplaceLink } from './shouldReplaceLink';
@@ -475,7 +475,9 @@ export const updateCardViaDatasource = args => {
475
475
  inputMethod
476
476
  });
477
477
  if (isDeletingConfig) {
478
- removeDatasourceStash(tr, node.attrs.url);
478
+ if (typeof node.attrs.url === 'string') {
479
+ removeDatasourceStash(tr, node.attrs.url);
480
+ }
479
481
  } else {
480
482
  hideDatasourceModal(tr);
481
483
  }
@@ -518,19 +520,38 @@ export const getAttrsForAppearance = (appearance, selectedNode) => {
518
520
  layout: 'center'
519
521
  };
520
522
  }
521
- if (selectedNode.attrs.datasource) {
522
- return {
523
- url: selectedNode.attrs.url
524
- };
523
+ if (getBooleanFF('platform.linking-platform.editor-datasource-typeguards')) {
524
+ if (isDatasourceNode(selectedNode)) {
525
+ return {
526
+ url: selectedNode.attrs.url
527
+ };
528
+ }
529
+ } else {
530
+ if (selectedNode.attrs.datasource) {
531
+ return {
532
+ url: selectedNode.attrs.url
533
+ };
534
+ }
525
535
  }
526
536
  return selectedNode.attrs;
527
537
  };
528
538
  const updateDatasourceStash = (tr, selectedNode) => {
529
- var _selectedNode$attrs;
530
- 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)) {
531
- setDatasourceStash(tr, {
532
- url: selectedNode.attrs.url,
533
- views: selectedNode.attrs.datasource.views
534
- });
539
+ if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar')) {
540
+ if (getBooleanFF('platform.linking-platform.editor-datasource-typeguards')) {
541
+ if (isDatasourceNode(selectedNode) && !isDatasourceConfigEditable(selectedNode.attrs.datasource.id) && selectedNode.attrs.url) {
542
+ setDatasourceStash(tr, {
543
+ url: selectedNode.attrs.url,
544
+ views: selectedNode.attrs.datasource.views
545
+ });
546
+ }
547
+ } else {
548
+ var _selectedNode$attrs;
549
+ if (selectedNode !== null && selectedNode !== void 0 && (_selectedNode$attrs = selectedNode.attrs) !== null && _selectedNode$attrs !== void 0 && _selectedNode$attrs.datasource && !isDatasourceConfigEditable(selectedNode.attrs.datasource.id)) {
550
+ setDatasourceStash(tr, {
551
+ url: selectedNode.attrs.url,
552
+ views: selectedNode.attrs.datasource.views
553
+ });
554
+ }
555
+ }
535
556
  }
536
557
  };
@@ -13,7 +13,8 @@ import { BlockCard } from '../nodeviews/blockCard';
13
13
  import { Datasource } from '../nodeviews/datasource';
14
14
  import { EmbedCard } from '../nodeviews/embedCard';
15
15
  import { InlineCardNodeView } from '../nodeviews/inlineCard';
16
- import { isBlockSupportedAtPosition, isEmbedSupportedAtPosition } from '../utils';
16
+ import { isDatasourceTableLayout } from '../ui/LayoutButton/utils';
17
+ import { isBlockSupportedAtPosition, isDatasourceNode, isEmbedSupportedAtPosition } from '../utils';
17
18
  import { clearOverlayCandidate, setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
18
19
  import { pluginKey } from './plugin-key';
19
20
  import reducer from './reducers';
@@ -174,8 +175,12 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
174
175
  const shouldUpdateTableRef = datasourceTableRef && (currentState === null || currentState === void 0 ? void 0 : currentState.datasourceTableRef) !== datasourceTableRef;
175
176
  if (isDatasource && shouldUpdateTableRef) {
176
177
  var _node$attrs2;
178
+ const getLayout = () => {
179
+ return isDatasourceTableLayout(node.attrs.layout) ? node.attrs.layout : DATASOURCE_DEFAULT_LAYOUT;
180
+ };
181
+
177
182
  // since we use the plugin state, which is a shared state, we need to update the datasourceTableRef, layout on each selection
178
- const layout = (node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.layout) || DATASOURCE_DEFAULT_LAYOUT;
183
+ const layout = getBooleanFF('platform.linking-platform.editor-datasource-typeguards') ? getLayout() : (node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.layout) || DATASOURCE_DEFAULT_LAYOUT;
179
184
  const isNested = selection.$anchor.depth > 0;
180
185
 
181
186
  // we want to disable resize button when datasource table is nested by not setting then datasourceTableRef on selection
@@ -249,7 +254,7 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
249
254
  onClickCallback: options.onClickCallback
250
255
  };
251
256
  const hasIntlContext = true;
252
- const isDatasource = !!(node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.datasource);
257
+ const 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);
253
258
  if (isDatasource) {
254
259
  var _node$attrs4, _node$attrs4$datasour;
255
260
  if (options.allowDatasource && platform !== 'mobile' && canRenderDatasource(node === null || node === void 0 ? void 0 : (_node$attrs4 = node.attrs) === null || _node$attrs4 === void 0 ? void 0 : (_node$attrs4$datasour = _node$attrs4.datasource) === null || _node$attrs4$datasour === void 0 ? void 0 : _node$attrs4$datasour.id)) {
@@ -21,7 +21,7 @@ import { editDatasource, EditDatasourceButton } from './ui/EditDatasourceButton'
21
21
  import { buildEditLinkToolbar, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
22
22
  import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
23
23
  import { ToolbarViewedEvent } from './ui/ToolbarViewedEvent';
24
- import { appearanceForNodeType, displayInfoForCard, findCardInfo, isDatasourceConfigEditable, titleUrlPairFromNode } from './utils';
24
+ import { appearanceForNodeType, displayInfoForCard, findCardInfo, isDatasourceConfigEditable, isDatasourceNode, titleUrlPairFromNode } from './utils';
25
25
  export const removeCard = editorAnalyticsApi => commandWithMetadata((state, dispatch) => {
26
26
  if (!(state.selection instanceof NodeSelection)) {
27
27
  return false;
@@ -198,7 +198,7 @@ const generateToolbarItems = (state, intl, providerFactory, cardOptions, lpLinkP
198
198
  const {
199
199
  hoverDecoration
200
200
  } = (_pluginInjectionApi$d = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$d2 = pluginInjectionApi.decorations) === null || _pluginInjectionApi$d2 === void 0 ? void 0 : _pluginInjectionApi$d2.actions) !== null && _pluginInjectionApi$d !== void 0 ? _pluginInjectionApi$d : {};
201
- const isDatasource = currentAppearance === 'block' && (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource);
201
+ const isDatasource = getBooleanFF('platform.linking-platform.editor-datasource-typeguards') ? isDatasourceNode(node) : currentAppearance === 'block' && (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource);
202
202
  const shouldRenderDatasourceToolbar = isDatasource &&
203
203
  // not showing toolbar in mobile for now since not sure what our plans are for it
204
204
  platform !== 'mobile' && cardOptions.allowDatasource && canRenderDatasource(node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : (_node$attrs2$datasour = _node$attrs2.datasource) === null || _node$attrs2$datasour === void 0 ? void 0 : _node$attrs2$datasour.id);
@@ -9,9 +9,11 @@ import { getNextBreakoutMode, getTitle } from '@atlaskit/editor-common/utils';
9
9
  import CollapseIcon from '@atlaskit/icon/glyph/editor/collapse';
10
10
  import ExpandIcon from '@atlaskit/icon/glyph/editor/expand';
11
11
  import { DATASOURCE_DEFAULT_LAYOUT } from '@atlaskit/linking-common';
12
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
12
13
  import { B300, N20A, N300 } from '@atlaskit/theme/colors';
13
14
  import { setCardLayout } from '../../pm-plugins/actions';
14
- import { getDatasource } from './utils';
15
+ import { isDatasourceNode } from '../../utils';
16
+ import { getDatasource, isDatasourceTableLayout } from './utils';
15
17
  const toolbarButtonWrapperStyles = css({
16
18
  background: `${`var(--ds-background-neutral, ${N20A})`}`,
17
19
  color: `${`var(--ds-icon, ${N300})`}`,
@@ -79,14 +81,17 @@ const LayoutButtonWrapper = ({
79
81
  node,
80
82
  pos
81
83
  } = getDatasource(editorView);
84
+ const 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);
85
+ if (!isDatasource) {
86
+ return null;
87
+ }
82
88
 
83
89
  // If layout doesn't exist in ADF it returns null, we want to change to undefined
84
90
  // which results in default parameter value being used in LayoutButton.
85
91
  const {
86
92
  datasourceTableRef,
87
- layout = (node === null || node === void 0 ? void 0 : (_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.layout) || undefined
93
+ layout = (node === null || node === void 0 ? void 0 : (_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.layout) || undefined
88
94
  } = cardState !== null && cardState !== void 0 ? cardState : {};
89
- const isDatasource = !!(node !== null && node !== void 0 && (_node$attrs2 = node.attrs) !== null && _node$attrs2 !== void 0 && _node$attrs2.datasource);
90
95
  const onLayoutChange = layout => {
91
96
  var _getDatasource$node;
92
97
  if (pos === undefined) {
@@ -105,15 +110,12 @@ const LayoutButtonWrapper = ({
105
110
  tr.setMeta('scrollIntoView', false);
106
111
  dispatch(setCardLayout(layout)(tr));
107
112
  };
108
- if (!isDatasource) {
109
- return null;
110
- }
111
113
  return jsx(LayoutButton, {
112
114
  mountPoint: mountPoint,
113
115
  scrollableElement: scrollableElement,
114
116
  boundariesElement: boundariesElement,
115
117
  targetElement: datasourceTableRef,
116
- layout: layout,
118
+ layout: isDatasourceTableLayout(layout) ? layout : undefined,
117
119
  onLayoutChange: onLayoutChange,
118
120
  intl: intl
119
121
  });
@@ -1 +1 @@
1
- export {};
1
+ export const DATASOURCE_TABLE_LAYOUTS = ['full-width', 'center', 'wide'];
@@ -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
  };