@atlaskit/editor-plugin-card 1.0.1 → 1.0.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/editor-plugin-card
2
2
 
3
+ ## 1.0.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#72875](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/72875) [`0d1e8b03af0b`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/0d1e8b03af0b) - Adding datasource stash to save datasource views when switching to inline/block and then back to datasource view
8
+
9
+ ## 1.0.2
10
+
11
+ ### Patch Changes
12
+
13
+ - Updated dependencies
14
+
3
15
  ## 1.0.1
4
16
 
5
17
  ### Patch Changes
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.showLinkToolbar = exports.showDatasourceModal = exports.setProvider = exports.setDatasourceTableRef = exports.setCardLayoutAndDatasourceTableRef = exports.setCardLayout = exports.resolveCard = exports.registerSmartCardEvents = exports.registerRemoveOverlay = exports.registerCard = exports.queueCards = exports.hideLinkToolbar = exports.hideDatasourceModal = exports.clearOverlayCandidate = exports.cardAction = void 0;
6
+ exports.showLinkToolbar = exports.showDatasourceModal = exports.setProvider = exports.setDatasourceTableRef = exports.setDatasourceStash = exports.setCardLayoutAndDatasourceTableRef = exports.setCardLayout = exports.resolveCard = exports.removeDatasourceStash = exports.registerSmartCardEvents = exports.registerRemoveOverlay = exports.registerCard = exports.queueCards = exports.hideLinkToolbar = exports.hideDatasourceModal = exports.clearOverlayCandidate = exports.cardAction = void 0;
7
7
  var _pluginKey = require("./plugin-key");
8
8
  var cardAction = exports.cardAction = function cardAction(tr, action) {
9
9
  return tr.setMeta(_pluginKey.pluginKey, action);
@@ -110,4 +110,16 @@ var clearOverlayCandidate = exports.clearOverlayCandidate = function clearOverla
110
110
  return cardAction(tr, {
111
111
  type: 'CLEAR_OVERLAY_CANDIDATE'
112
112
  });
113
+ };
114
+ var setDatasourceStash = exports.setDatasourceStash = function setDatasourceStash(tr, datasourceStash) {
115
+ return cardAction(tr, {
116
+ type: 'SET_DATASOURCE_STASH',
117
+ datasourceStash: datasourceStash
118
+ });
119
+ };
120
+ var removeDatasourceStash = exports.removeDatasourceStash = function removeDatasourceStash(tr, url) {
121
+ return cardAction(tr, {
122
+ type: 'REMOVE_DATASOURCE_STASH',
123
+ url: url
124
+ });
113
125
  };
@@ -258,6 +258,12 @@ var changeSelectedCardToLink = exports.changeSelectedCardToLink = function chang
258
258
  tr = cardToLinkWithTransaction(state, text, href);
259
259
  }
260
260
  var selectedNode = state.selection instanceof _state.NodeSelection && state.selection.node;
261
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-appearance-toolbar') && selectedNode && !(0, _utils2.isDatasourceConfigEditable)(selectedNode.attrs.datasource.id)) {
262
+ (0, _actions.setDatasourceStash)(tr, {
263
+ url: selectedNode.attrs.url,
264
+ views: selectedNode.attrs.datasource.views
265
+ });
266
+ }
261
267
  if (sendAnalytics) {
262
268
  if (selectedNode) {
263
269
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
@@ -389,6 +395,12 @@ var setSelectedCardAppearance = exports.setSelectedCardAppearance = function set
389
395
  to = _state$selection.to;
390
396
  var nodeType = getLinkNodeType(appearance, state.schema.nodes);
391
397
  var tr = state.tr.setNodeMarkup(from, nodeType, attrs, selectedNode.marks);
398
+ if ((0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.enable-datasource-appearance-toolbar') && selectedNode && !(0, _utils2.isDatasourceConfigEditable)(selectedNode.attrs.datasource.id)) {
399
+ (0, _actions.setDatasourceStash)(tr, {
400
+ url: selectedNode.attrs.url,
401
+ views: selectedNode.attrs.datasource.views
402
+ });
403
+ }
392
404
 
393
405
  // When the selected card is the last element in the doc we add a new paragraph after it for consistent replacement
394
406
  if (tr.doc.nodeSize - 2 === to) {
@@ -430,7 +442,7 @@ var getLinkNodeType = exports.getLinkNodeType = function getLinkNodeType(appeara
430
442
  };
431
443
 
432
444
  // Apply an update made from a datasource ui interaction
433
- var updateCardViaDatasource = exports.updateCardViaDatasource = function updateCardViaDatasource(state, node, newAdf, view, sourceEvent) {
445
+ var updateCardViaDatasource = exports.updateCardViaDatasource = function updateCardViaDatasource(state, node, newAdf, view, sourceEvent, isDeletingConfig) {
434
446
  var tr = state.tr,
435
447
  from = state.selection.from,
436
448
  schemaNodes = state.schema.nodes;
@@ -468,7 +480,11 @@ var updateCardViaDatasource = exports.updateCardViaDatasource = function updateC
468
480
  action: _analytics.ACTION.UPDATED,
469
481
  sourceEvent: sourceEvent
470
482
  });
471
- (0, _actions.hideDatasourceModal)(tr);
483
+ if (isDeletingConfig) {
484
+ (0, _actions.removeDatasourceStash)(tr, node.attrs.url);
485
+ } else {
486
+ (0, _actions.hideDatasourceModal)(tr);
487
+ }
472
488
  view.dispatch(tr.scrollIntoView());
473
489
  };
474
490
  var insertDatasource = exports.insertDatasource = function insertDatasource(state, adf, view, sourceEvent) {
@@ -82,6 +82,7 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
82
82
  requests: [],
83
83
  provider: null,
84
84
  cards: [],
85
+ datasourceStash: {},
85
86
  showLinkingToolbar: false,
86
87
  smartLinkEvents: undefined,
87
88
  editorAppearance: editorAppearance,
@@ -1,11 +1,15 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
8
  exports.default = void 0;
9
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
8
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
12
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
9
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; }
10
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; }
11
15
  var queue = function queue(state, action) {
@@ -84,6 +88,22 @@ var registerRemoveOverlayOnInsertedLink = function registerRemoveOverlayOnInsert
84
88
  removeOverlay: action.callback
85
89
  });
86
90
  };
91
+ var setDatasourceStash = function setDatasourceStash(state, action) {
92
+ return _objectSpread(_objectSpread({}, state), {}, {
93
+ datasourceStash: _objectSpread(_objectSpread({}, state.datasourceStash), {}, (0, _defineProperty2.default)({}, action.datasourceStash.url, {
94
+ views: action.datasourceStash.views
95
+ }))
96
+ });
97
+ };
98
+ var removeDatasourceStash = function removeDatasourceStash(state, action) {
99
+ var _state$datasourceStas = state.datasourceStash,
100
+ _action$url = action.url,
101
+ _ = _state$datasourceStas[_action$url],
102
+ datasourceStash = (0, _objectWithoutProperties2.default)(_state$datasourceStas, [_action$url].map(_toPropertyKey));
103
+ return _objectSpread(_objectSpread({}, state), {}, {
104
+ datasourceStash: datasourceStash
105
+ });
106
+ };
87
107
  var _default = exports.default = function _default(state, action) {
88
108
  switch (action.type) {
89
109
  case 'QUEUE':
@@ -113,5 +133,9 @@ var _default = exports.default = function _default(state, action) {
113
133
  return clearOverlayCandidate(state);
114
134
  case 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK':
115
135
  return registerRemoveOverlayOnInsertedLink(state, action);
136
+ case 'SET_DATASOURCE_STASH':
137
+ return setDatasourceStash(state, action);
138
+ case 'REMOVE_DATASOURCE_STASH':
139
+ return removeDatasourceStash(state, action);
116
140
  }
117
141
  };
@@ -15,6 +15,7 @@ var _table = _interopRequireDefault(require("@atlaskit/icon/glyph/table"));
15
15
  var _linkDatasource = require("@atlaskit/link-datasource");
16
16
  var _primitives = require("@atlaskit/primitives");
17
17
  var _doc = require("../pm-plugins/doc");
18
+ var _pluginKey = require("../pm-plugins/plugin-key");
18
19
  var _CardContextProvider = require("./CardContextProvider");
19
20
  var _useFetchDatasourceInfo = require("./useFetchDatasourceInfo");
20
21
  /** @jsx jsx */
@@ -37,20 +38,22 @@ var DatasourceAppearanceButtonWithCardContext = function DatasourceAppearanceBut
37
38
  datasourceId = _useFetchDatasourceIn.datasourceId,
38
39
  parameters = _useFetchDatasourceIn.parameters;
39
40
  var onChangeAppearance = (0, _react.useCallback)(function () {
41
+ var _state$datasourceStas, _state$datasourceStas2;
40
42
  if (!editorView || !datasourceId || !parameters) {
41
43
  return;
42
44
  }
45
+ var state = _pluginKey.pluginKey.getState(editorState);
43
46
  var newAdf = (0, _linkDatasource.buildDatasourceAdf)({
44
47
  id: datasourceId,
45
48
  parameters: parameters,
46
- views: [{
49
+ views: (_state$datasourceStas = state === null || state === void 0 || (_state$datasourceStas2 = state.datasourceStash[url]) === null || _state$datasourceStas2 === void 0 ? void 0 : _state$datasourceStas2.views) !== null && _state$datasourceStas !== void 0 ? _state$datasourceStas : [{
47
50
  type: 'table'
48
51
  }]
49
52
  }, url);
50
53
  var selection = editorState.selection;
51
54
  var existingNode = selection instanceof _state.NodeSelection ? selection.node : undefined;
52
55
  if (existingNode) {
53
- (0, _doc.updateCardViaDatasource)(editorState, existingNode, newAdf, editorView, undefined);
56
+ (0, _doc.updateCardViaDatasource)(editorState, existingNode, newAdf, editorView, undefined, true);
54
57
  }
55
58
  }, [parameters, datasourceId, editorState, editorView, url]);
56
59
  if (!parameters || !datasourceId || !(0, _utils.canRenderDatasource)(datasourceId)) {
@@ -57,4 +57,12 @@ export const hideDatasourceModal = tr => cardAction(tr, {
57
57
  });
58
58
  export const clearOverlayCandidate = tr => cardAction(tr, {
59
59
  type: 'CLEAR_OVERLAY_CANDIDATE'
60
+ });
61
+ export const setDatasourceStash = (tr, datasourceStash) => cardAction(tr, {
62
+ type: 'SET_DATASOURCE_STASH',
63
+ datasourceStash
64
+ });
65
+ export const removeDatasourceStash = (tr, url) => cardAction(tr, {
66
+ type: 'REMOVE_DATASOURCE_STASH',
67
+ url
60
68
  });
@@ -6,8 +6,8 @@ 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, selectedCardAppearance } from '../utils';
10
- import { hideDatasourceModal, queueCards, resolveCard } from './actions';
9
+ import { appearanceForNodeType, isDatasourceConfigEditable, selectedCardAppearance } from '../utils';
10
+ import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash } from './actions';
11
11
  import { pluginKey } from './plugin-key';
12
12
  import { shouldReplaceLink } from './shouldReplaceLink';
13
13
  /**
@@ -235,6 +235,12 @@ export const changeSelectedCardToLink = (text, href, sendAnalytics, node, pos, e
235
235
  tr = cardToLinkWithTransaction(state, text, href);
236
236
  }
237
237
  const selectedNode = state.selection instanceof NodeSelection && state.selection.node;
238
+ if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar') && selectedNode && !isDatasourceConfigEditable(selectedNode.attrs.datasource.id)) {
239
+ setDatasourceStash(tr, {
240
+ url: selectedNode.attrs.url,
241
+ views: selectedNode.attrs.datasource.views
242
+ });
243
+ }
238
244
  if (sendAnalytics) {
239
245
  if (selectedNode) {
240
246
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent({
@@ -364,6 +370,12 @@ export const setSelectedCardAppearance = (appearance, editorAnalyticsApi) => (st
364
370
  } = state.selection;
365
371
  const nodeType = getLinkNodeType(appearance, state.schema.nodes);
366
372
  const tr = state.tr.setNodeMarkup(from, nodeType, attrs, selectedNode.marks);
373
+ if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar') && selectedNode && !isDatasourceConfigEditable(selectedNode.attrs.datasource.id)) {
374
+ setDatasourceStash(tr, {
375
+ url: selectedNode.attrs.url,
376
+ views: selectedNode.attrs.datasource.views
377
+ });
378
+ }
367
379
 
368
380
  // When the selected card is the last element in the doc we add a new paragraph after it for consistent replacement
369
381
  if (tr.doc.nodeSize - 2 === to) {
@@ -404,7 +416,7 @@ export const getLinkNodeType = (appearance, linkNodes) => {
404
416
  };
405
417
 
406
418
  // Apply an update made from a datasource ui interaction
407
- export const updateCardViaDatasource = (state, node, newAdf, view, sourceEvent) => {
419
+ export const updateCardViaDatasource = (state, node, newAdf, view, sourceEvent, isDeletingConfig) => {
408
420
  const {
409
421
  tr,
410
422
  selection: {
@@ -443,7 +455,11 @@ export const updateCardViaDatasource = (state, node, newAdf, view, sourceEvent)
443
455
  action: ACTION.UPDATED,
444
456
  sourceEvent
445
457
  });
446
- hideDatasourceModal(tr);
458
+ if (isDeletingConfig) {
459
+ removeDatasourceStash(tr, node.attrs.url);
460
+ } else {
461
+ hideDatasourceModal(tr);
462
+ }
447
463
  view.dispatch(tr.scrollIntoView());
448
464
  };
449
465
  export const insertDatasource = (state, adf, view, sourceEvent) => {
@@ -67,6 +67,7 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
67
67
  requests: [],
68
68
  provider: null,
69
69
  cards: [],
70
+ datasourceStash: {},
70
71
  showLinkingToolbar: false,
71
72
  smartLinkEvents: undefined,
72
73
  editorAppearance,
@@ -85,6 +85,27 @@ const registerRemoveOverlayOnInsertedLink = (state, action) => {
85
85
  removeOverlay: action.callback
86
86
  };
87
87
  };
88
+ const setDatasourceStash = (state, action) => {
89
+ return {
90
+ ...state,
91
+ datasourceStash: {
92
+ ...state.datasourceStash,
93
+ [action.datasourceStash.url]: {
94
+ views: action.datasourceStash.views
95
+ }
96
+ }
97
+ };
98
+ };
99
+ const removeDatasourceStash = (state, action) => {
100
+ const {
101
+ [action.url]: _,
102
+ ...datasourceStash
103
+ } = state.datasourceStash;
104
+ return {
105
+ ...state,
106
+ datasourceStash
107
+ };
108
+ };
88
109
  export default ((state, action) => {
89
110
  switch (action.type) {
90
111
  case 'QUEUE':
@@ -114,5 +135,9 @@ export default ((state, action) => {
114
135
  return clearOverlayCandidate(state);
115
136
  case 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK':
116
137
  return registerRemoveOverlayOnInsertedLink(state, action);
138
+ case 'SET_DATASOURCE_STASH':
139
+ return setDatasourceStash(state, action);
140
+ case 'REMOVE_DATASOURCE_STASH':
141
+ return removeDatasourceStash(state, action);
117
142
  }
118
143
  });
@@ -9,6 +9,7 @@ import TableIcon from '@atlaskit/icon/glyph/table';
9
9
  import { buildDatasourceAdf } from '@atlaskit/link-datasource';
10
10
  import { Flex } from '@atlaskit/primitives';
11
11
  import { updateCardViaDatasource } from '../pm-plugins/doc';
12
+ import { pluginKey } from '../pm-plugins/plugin-key';
12
13
  import { CardContextProvider } from './CardContextProvider';
13
14
  import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
14
15
  const buttonStyles = css({
@@ -31,13 +32,15 @@ const DatasourceAppearanceButtonWithCardContext = ({
31
32
  cardContext
32
33
  });
33
34
  const onChangeAppearance = useCallback(() => {
35
+ var _state$datasourceStas, _state$datasourceStas2;
34
36
  if (!editorView || !datasourceId || !parameters) {
35
37
  return;
36
38
  }
39
+ const state = pluginKey.getState(editorState);
37
40
  const newAdf = buildDatasourceAdf({
38
41
  id: datasourceId,
39
42
  parameters,
40
- views: [{
43
+ views: (_state$datasourceStas = state === null || state === void 0 ? void 0 : (_state$datasourceStas2 = state.datasourceStash[url]) === null || _state$datasourceStas2 === void 0 ? void 0 : _state$datasourceStas2.views) !== null && _state$datasourceStas !== void 0 ? _state$datasourceStas : [{
41
44
  type: 'table'
42
45
  }]
43
46
  }, url);
@@ -46,7 +49,7 @@ const DatasourceAppearanceButtonWithCardContext = ({
46
49
  } = editorState;
47
50
  const existingNode = selection instanceof NodeSelection ? selection.node : undefined;
48
51
  if (existingNode) {
49
- updateCardViaDatasource(editorState, existingNode, newAdf, editorView, undefined);
52
+ updateCardViaDatasource(editorState, existingNode, newAdf, editorView, undefined, true);
50
53
  }
51
54
  }, [parameters, datasourceId, editorState, editorView, url]);
52
55
  if (!parameters || !datasourceId || !canRenderDatasource(datasourceId)) {
@@ -104,4 +104,16 @@ export var clearOverlayCandidate = function clearOverlayCandidate(tr) {
104
104
  return cardAction(tr, {
105
105
  type: 'CLEAR_OVERLAY_CANDIDATE'
106
106
  });
107
+ };
108
+ export var setDatasourceStash = function setDatasourceStash(tr, datasourceStash) {
109
+ return cardAction(tr, {
110
+ type: 'SET_DATASOURCE_STASH',
111
+ datasourceStash: datasourceStash
112
+ });
113
+ };
114
+ export var removeDatasourceStash = function removeDatasourceStash(tr, url) {
115
+ return cardAction(tr, {
116
+ type: 'REMOVE_DATASOURCE_STASH',
117
+ url: url
118
+ });
107
119
  };
@@ -10,8 +10,8 @@ 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, selectedCardAppearance } from '../utils';
14
- import { hideDatasourceModal, queueCards, resolveCard } from './actions';
13
+ import { appearanceForNodeType, isDatasourceConfigEditable, selectedCardAppearance } from '../utils';
14
+ import { hideDatasourceModal, queueCards, removeDatasourceStash, resolveCard, setDatasourceStash } from './actions';
15
15
  import { pluginKey } from './plugin-key';
16
16
  import { shouldReplaceLink } from './shouldReplaceLink';
17
17
  /**
@@ -251,6 +251,12 @@ export var changeSelectedCardToLink = function changeSelectedCardToLink(text, hr
251
251
  tr = cardToLinkWithTransaction(state, text, href);
252
252
  }
253
253
  var selectedNode = state.selection instanceof NodeSelection && state.selection.node;
254
+ if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar') && selectedNode && !isDatasourceConfigEditable(selectedNode.attrs.datasource.id)) {
255
+ setDatasourceStash(tr, {
256
+ url: selectedNode.attrs.url,
257
+ views: selectedNode.attrs.datasource.views
258
+ });
259
+ }
254
260
  if (sendAnalytics) {
255
261
  if (selectedNode) {
256
262
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent({
@@ -382,6 +388,12 @@ export var setSelectedCardAppearance = function setSelectedCardAppearance(appear
382
388
  to = _state$selection.to;
383
389
  var nodeType = getLinkNodeType(appearance, state.schema.nodes);
384
390
  var tr = state.tr.setNodeMarkup(from, nodeType, attrs, selectedNode.marks);
391
+ if (getBooleanFF('platform.linking-platform.enable-datasource-appearance-toolbar') && selectedNode && !isDatasourceConfigEditable(selectedNode.attrs.datasource.id)) {
392
+ setDatasourceStash(tr, {
393
+ url: selectedNode.attrs.url,
394
+ views: selectedNode.attrs.datasource.views
395
+ });
396
+ }
385
397
 
386
398
  // When the selected card is the last element in the doc we add a new paragraph after it for consistent replacement
387
399
  if (tr.doc.nodeSize - 2 === to) {
@@ -423,7 +435,7 @@ export var getLinkNodeType = function getLinkNodeType(appearance, linkNodes) {
423
435
  };
424
436
 
425
437
  // Apply an update made from a datasource ui interaction
426
- export var updateCardViaDatasource = function updateCardViaDatasource(state, node, newAdf, view, sourceEvent) {
438
+ export var updateCardViaDatasource = function updateCardViaDatasource(state, node, newAdf, view, sourceEvent, isDeletingConfig) {
427
439
  var tr = state.tr,
428
440
  from = state.selection.from,
429
441
  schemaNodes = state.schema.nodes;
@@ -461,7 +473,11 @@ export var updateCardViaDatasource = function updateCardViaDatasource(state, nod
461
473
  action: ACTION.UPDATED,
462
474
  sourceEvent: sourceEvent
463
475
  });
464
- hideDatasourceModal(tr);
476
+ if (isDeletingConfig) {
477
+ removeDatasourceStash(tr, node.attrs.url);
478
+ } else {
479
+ hideDatasourceModal(tr);
480
+ }
465
481
  view.dispatch(tr.scrollIntoView());
466
482
  };
467
483
  export var insertDatasource = function insertDatasource(state, adf, view, sourceEvent) {
@@ -70,6 +70,7 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
70
70
  requests: [],
71
71
  provider: null,
72
72
  cards: [],
73
+ datasourceStash: {},
73
74
  showLinkingToolbar: false,
74
75
  smartLinkEvents: undefined,
75
76
  editorAppearance: editorAppearance,
@@ -1,4 +1,8 @@
1
+ import _typeof from "@babel/runtime/helpers/typeof";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
1
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
5
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
2
6
  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
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; }
4
8
  var queue = function queue(state, action) {
@@ -77,6 +81,22 @@ var registerRemoveOverlayOnInsertedLink = function registerRemoveOverlayOnInsert
77
81
  removeOverlay: action.callback
78
82
  });
79
83
  };
84
+ var setDatasourceStash = function setDatasourceStash(state, action) {
85
+ return _objectSpread(_objectSpread({}, state), {}, {
86
+ datasourceStash: _objectSpread(_objectSpread({}, state.datasourceStash), {}, _defineProperty({}, action.datasourceStash.url, {
87
+ views: action.datasourceStash.views
88
+ }))
89
+ });
90
+ };
91
+ var removeDatasourceStash = function removeDatasourceStash(state, action) {
92
+ var _state$datasourceStas = state.datasourceStash,
93
+ _action$url = action.url,
94
+ _ = _state$datasourceStas[_action$url],
95
+ datasourceStash = _objectWithoutProperties(_state$datasourceStas, [_action$url].map(_toPropertyKey));
96
+ return _objectSpread(_objectSpread({}, state), {}, {
97
+ datasourceStash: datasourceStash
98
+ });
99
+ };
80
100
  export default (function (state, action) {
81
101
  switch (action.type) {
82
102
  case 'QUEUE':
@@ -106,5 +126,9 @@ export default (function (state, action) {
106
126
  return clearOverlayCandidate(state);
107
127
  case 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK':
108
128
  return registerRemoveOverlayOnInsertedLink(state, action);
129
+ case 'SET_DATASOURCE_STASH':
130
+ return setDatasourceStash(state, action);
131
+ case 'REMOVE_DATASOURCE_STASH':
132
+ return removeDatasourceStash(state, action);
109
133
  }
110
134
  });
@@ -9,6 +9,7 @@ import TableIcon from '@atlaskit/icon/glyph/table';
9
9
  import { buildDatasourceAdf } from '@atlaskit/link-datasource';
10
10
  import { Flex } from '@atlaskit/primitives';
11
11
  import { updateCardViaDatasource } from '../pm-plugins/doc';
12
+ import { pluginKey } from '../pm-plugins/plugin-key';
12
13
  import { CardContextProvider } from './CardContextProvider';
13
14
  import { useFetchDatasourceInfo } from './useFetchDatasourceInfo';
14
15
  var buttonStyles = css({
@@ -29,20 +30,22 @@ var DatasourceAppearanceButtonWithCardContext = function DatasourceAppearanceBut
29
30
  datasourceId = _useFetchDatasourceIn.datasourceId,
30
31
  parameters = _useFetchDatasourceIn.parameters;
31
32
  var onChangeAppearance = useCallback(function () {
33
+ var _state$datasourceStas, _state$datasourceStas2;
32
34
  if (!editorView || !datasourceId || !parameters) {
33
35
  return;
34
36
  }
37
+ var state = pluginKey.getState(editorState);
35
38
  var newAdf = buildDatasourceAdf({
36
39
  id: datasourceId,
37
40
  parameters: parameters,
38
- views: [{
41
+ views: (_state$datasourceStas = state === null || state === void 0 || (_state$datasourceStas2 = state.datasourceStash[url]) === null || _state$datasourceStas2 === void 0 ? void 0 : _state$datasourceStas2.views) !== null && _state$datasourceStas !== void 0 ? _state$datasourceStas : [{
39
42
  type: 'table'
40
43
  }]
41
44
  }, url);
42
45
  var selection = editorState.selection;
43
46
  var existingNode = selection instanceof NodeSelection ? selection.node : undefined;
44
47
  if (existingNode) {
45
- updateCardViaDatasource(editorState, existingNode, newAdf, editorView, undefined);
48
+ updateCardViaDatasource(editorState, existingNode, newAdf, editorView, undefined, true);
46
49
  }
47
50
  }, [parameters, datasourceId, editorState, editorView, url]);
48
51
  if (!parameters || !datasourceId || !canRenderDatasource(datasourceId)) {
@@ -1,6 +1,7 @@
1
1
  import type { CardProvider } from '@atlaskit/editor-common/provider-factory';
2
2
  import type { DatasourceModalType } from '@atlaskit/editor-common/types';
3
3
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ import type { DatasourceAdfView } from '@atlaskit/linking-common';
4
5
  import type { SmartLinkEvents } from '@atlaskit/smart-card';
5
6
  import type { CardInfo, CardPluginAction, Request } from '../types';
6
7
  import type { DatasourceTableLayout } from '../ui/LayoutButton/types';
@@ -22,3 +23,8 @@ export declare const hideLinkToolbar: (tr: Transaction) => Transaction;
22
23
  export declare const showDatasourceModal: (modalType: DatasourceModalType) => (tr: Transaction) => Transaction;
23
24
  export declare const hideDatasourceModal: (tr: Transaction) => Transaction;
24
25
  export declare const clearOverlayCandidate: (tr: Transaction) => Transaction;
26
+ export declare const setDatasourceStash: (tr: Transaction, datasourceStash: {
27
+ url: string;
28
+ views: DatasourceAdfView[];
29
+ }) => Transaction;
30
+ export declare const removeDatasourceStash: (tr: Transaction, url: string) => Transaction;
@@ -23,7 +23,7 @@ export type LinkNodes = {
23
23
  [key in 'inlineCard' | 'blockCard' | 'embedCard']: NodeType;
24
24
  };
25
25
  export declare const getLinkNodeType: (appearance: CardAppearance, linkNodes: LinkNodes) => NodeType;
26
- export declare const updateCardViaDatasource: (state: EditorState, node: Node, newAdf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent) => void;
26
+ export declare const updateCardViaDatasource: (state: EditorState, node: Node, newAdf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent, isDeletingConfig?: boolean) => void;
27
27
  export declare const insertDatasource: (state: EditorState, adf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent) => void;
28
28
  /**
29
29
  * Get attributes for new Card Appearance
@@ -19,6 +19,11 @@ export declare const getPluginStateWithUpdatedPos: (pluginState: CardPluginState
19
19
  url?: string | undefined;
20
20
  }[];
21
21
  provider: import("@atlaskit/editor-common/provider-factory").CardProvider | null;
22
+ datasourceStash: {
23
+ [x: string]: {
24
+ views: import("@atlaskit/linking-common").DatasourceAdfTableView[];
25
+ };
26
+ };
22
27
  showLinkingToolbar: boolean;
23
28
  smartLinkEvents?: import("@atlaskit/smart-card").SmartLinkEvents | undefined;
24
29
  editorAppearance?: import("@atlaskit/editor-common/types").EditorAppearance | undefined;
@@ -3,6 +3,7 @@ import type { ACTION } from '@atlaskit/editor-common/analytics';
3
3
  import type { CardOptions, CardReplacementInputMethod } from '@atlaskit/editor-common/card';
4
4
  import type { CardAppearance, CardProvider } from '@atlaskit/editor-common/provider-factory';
5
5
  import type { DatasourceModalType, EditorAppearance, LinkPickerOptions } from '@atlaskit/editor-common/types';
6
+ import type { DatasourceAdfView } from '@atlaskit/linking-common';
6
7
  import type { SmartLinkEvents } from '@atlaskit/smart-card';
7
8
  import type { EditorCardPluginEvents } from './analytics/create-events-queue';
8
9
  import type { CardPluginEvent } from './analytics/types';
@@ -65,10 +66,18 @@ export type Request = {
65
66
  */
66
67
  sourceEvent?: UIAnalyticsEvent | null | undefined;
67
68
  };
69
+ /**
70
+ * Each key in the stash is URL.
71
+ * For any given URL we might temporarily stash some user preferences, like view settings for the datasource.
72
+ */
73
+ type DatasourceStash = Record<string, {
74
+ views: DatasourceAdfView[];
75
+ }>;
68
76
  export type CardPluginState = {
69
77
  requests: Request[];
70
78
  provider: CardProvider | null;
71
79
  cards: CardInfo[];
80
+ datasourceStash: DatasourceStash;
72
81
  showLinkingToolbar: boolean;
73
82
  smartLinkEvents?: SmartLinkEvents;
74
83
  editorAppearance?: EditorAppearance;
@@ -144,4 +153,16 @@ export type RegisterRemoveOverlayOnInsertedLink = {
144
153
  type: 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK';
145
154
  callback: () => void;
146
155
  };
147
- export type CardPluginAction = SetProvider | Queue | Resolve | Register | ShowLinkToolbar | HideLinkToolbar | ShowDatasourceModal | HideDatasourceModal | RegisterSmartCardEvents | SetDatasourceTableRef | SetCardLayout | SetCardLayoutAndDatasourceTableRef | ClearOverlayCandidate | RegisterRemoveOverlayOnInsertedLink;
156
+ export type SetDatasourceStash = {
157
+ type: 'SET_DATASOURCE_STASH';
158
+ datasourceStash: {
159
+ url: string;
160
+ views: DatasourceAdfView[];
161
+ };
162
+ };
163
+ export type RemoveDatasourceStash = {
164
+ type: 'REMOVE_DATASOURCE_STASH';
165
+ url: string;
166
+ };
167
+ export type CardPluginAction = SetProvider | Queue | Resolve | Register | ShowLinkToolbar | HideLinkToolbar | ShowDatasourceModal | HideDatasourceModal | RegisterSmartCardEvents | SetDatasourceTableRef | SetCardLayout | SetCardLayoutAndDatasourceTableRef | ClearOverlayCandidate | RegisterRemoveOverlayOnInsertedLink | SetDatasourceStash | RemoveDatasourceStash;
168
+ export {};
@@ -1,6 +1,7 @@
1
1
  import type { CardProvider } from '@atlaskit/editor-common/provider-factory';
2
2
  import type { DatasourceModalType } from '@atlaskit/editor-common/types';
3
3
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
4
+ import type { DatasourceAdfView } from '@atlaskit/linking-common';
4
5
  import type { SmartLinkEvents } from '@atlaskit/smart-card';
5
6
  import type { CardInfo, CardPluginAction, Request } from '../types';
6
7
  import type { DatasourceTableLayout } from '../ui/LayoutButton/types';
@@ -22,3 +23,8 @@ export declare const hideLinkToolbar: (tr: Transaction) => Transaction;
22
23
  export declare const showDatasourceModal: (modalType: DatasourceModalType) => (tr: Transaction) => Transaction;
23
24
  export declare const hideDatasourceModal: (tr: Transaction) => Transaction;
24
25
  export declare const clearOverlayCandidate: (tr: Transaction) => Transaction;
26
+ export declare const setDatasourceStash: (tr: Transaction, datasourceStash: {
27
+ url: string;
28
+ views: DatasourceAdfView[];
29
+ }) => Transaction;
30
+ export declare const removeDatasourceStash: (tr: Transaction, url: string) => Transaction;
@@ -23,7 +23,7 @@ export type LinkNodes = {
23
23
  [key in 'inlineCard' | 'blockCard' | 'embedCard']: NodeType;
24
24
  };
25
25
  export declare const getLinkNodeType: (appearance: CardAppearance, linkNodes: LinkNodes) => NodeType;
26
- export declare const updateCardViaDatasource: (state: EditorState, node: Node, newAdf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent) => void;
26
+ export declare const updateCardViaDatasource: (state: EditorState, node: Node, newAdf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent, isDeletingConfig?: boolean) => void;
27
27
  export declare const insertDatasource: (state: EditorState, adf: DatasourceAdf | InlineCardAdf, view: EditorView, sourceEvent?: UIAnalyticsEvent) => void;
28
28
  /**
29
29
  * Get attributes for new Card Appearance
@@ -19,6 +19,11 @@ export declare const getPluginStateWithUpdatedPos: (pluginState: CardPluginState
19
19
  url?: string | undefined;
20
20
  }[];
21
21
  provider: import("@atlaskit/editor-common/provider-factory").CardProvider | null;
22
+ datasourceStash: {
23
+ [x: string]: {
24
+ views: import("@atlaskit/linking-common").DatasourceAdfTableView[];
25
+ };
26
+ };
22
27
  showLinkingToolbar: boolean;
23
28
  smartLinkEvents?: import("@atlaskit/smart-card").SmartLinkEvents | undefined;
24
29
  editorAppearance?: import("@atlaskit/editor-common/types").EditorAppearance | undefined;
@@ -3,6 +3,7 @@ import type { ACTION } from '@atlaskit/editor-common/analytics';
3
3
  import type { CardOptions, CardReplacementInputMethod } from '@atlaskit/editor-common/card';
4
4
  import type { CardAppearance, CardProvider } from '@atlaskit/editor-common/provider-factory';
5
5
  import type { DatasourceModalType, EditorAppearance, LinkPickerOptions } from '@atlaskit/editor-common/types';
6
+ import type { DatasourceAdfView } from '@atlaskit/linking-common';
6
7
  import type { SmartLinkEvents } from '@atlaskit/smart-card';
7
8
  import type { EditorCardPluginEvents } from './analytics/create-events-queue';
8
9
  import type { CardPluginEvent } from './analytics/types';
@@ -65,10 +66,18 @@ export type Request = {
65
66
  */
66
67
  sourceEvent?: UIAnalyticsEvent | null | undefined;
67
68
  };
69
+ /**
70
+ * Each key in the stash is URL.
71
+ * For any given URL we might temporarily stash some user preferences, like view settings for the datasource.
72
+ */
73
+ type DatasourceStash = Record<string, {
74
+ views: DatasourceAdfView[];
75
+ }>;
68
76
  export type CardPluginState = {
69
77
  requests: Request[];
70
78
  provider: CardProvider | null;
71
79
  cards: CardInfo[];
80
+ datasourceStash: DatasourceStash;
72
81
  showLinkingToolbar: boolean;
73
82
  smartLinkEvents?: SmartLinkEvents;
74
83
  editorAppearance?: EditorAppearance;
@@ -144,4 +153,16 @@ export type RegisterRemoveOverlayOnInsertedLink = {
144
153
  type: 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK';
145
154
  callback: () => void;
146
155
  };
147
- export type CardPluginAction = SetProvider | Queue | Resolve | Register | ShowLinkToolbar | HideLinkToolbar | ShowDatasourceModal | HideDatasourceModal | RegisterSmartCardEvents | SetDatasourceTableRef | SetCardLayout | SetCardLayoutAndDatasourceTableRef | ClearOverlayCandidate | RegisterRemoveOverlayOnInsertedLink;
156
+ export type SetDatasourceStash = {
157
+ type: 'SET_DATASOURCE_STASH';
158
+ datasourceStash: {
159
+ url: string;
160
+ views: DatasourceAdfView[];
161
+ };
162
+ };
163
+ export type RemoveDatasourceStash = {
164
+ type: 'REMOVE_DATASOURCE_STASH';
165
+ url: string;
166
+ };
167
+ export type CardPluginAction = SetProvider | Queue | Resolve | Register | ShowLinkToolbar | HideLinkToolbar | ShowDatasourceModal | HideDatasourceModal | RegisterSmartCardEvents | SetDatasourceTableRef | SetCardLayout | SetCardLayoutAndDatasourceTableRef | ClearOverlayCandidate | RegisterRemoveOverlayOnInsertedLink | SetDatasourceStash | RemoveDatasourceStash;
168
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-card",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Card plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,11 +35,11 @@
35
35
  "@atlaskit/adf-schema": "^35.5.1",
36
36
  "@atlaskit/analytics-next": "^9.2.0",
37
37
  "@atlaskit/custom-steps": "^0.0.13",
38
- "@atlaskit/editor-common": "^77.5.0",
38
+ "@atlaskit/editor-common": "^78.2.0",
39
39
  "@atlaskit/editor-plugin-analytics": "^1.0.0",
40
40
  "@atlaskit/editor-plugin-decorations": "^1.0.0",
41
41
  "@atlaskit/editor-plugin-feature-flags": "^1.0.0",
42
- "@atlaskit/editor-plugin-floating-toolbar": "^1.0.0",
42
+ "@atlaskit/editor-plugin-floating-toolbar": "^1.1.0",
43
43
  "@atlaskit/editor-plugin-grid": "^1.0.0",
44
44
  "@atlaskit/editor-plugin-hyperlink": "^1.0.0",
45
45
  "@atlaskit/editor-plugin-width": "^1.0.0",