@atlaskit/editor-plugin-card 0.6.0 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +10 -0
- package/dist/cjs/nodeviews/blockCard.js +20 -0
- package/dist/cjs/pm-plugins/doc.js +33 -28
- package/dist/cjs/toolbar.js +24 -6
- package/dist/cjs/ui/DatasourceModal/index.js +1 -1
- package/dist/cjs/ui/EditDatasourceButton.js +144 -0
- package/dist/cjs/ui/EditLinkToolbar.js +4 -27
- package/dist/es2019/nodeviews/blockCard.js +15 -0
- package/dist/es2019/pm-plugins/doc.js +27 -22
- package/dist/es2019/toolbar.js +22 -6
- package/dist/es2019/ui/DatasourceModal/index.js +2 -2
- package/dist/es2019/ui/EditDatasourceButton.js +101 -0
- package/dist/es2019/ui/EditLinkToolbar.js +1 -23
- package/dist/esm/nodeviews/blockCard.js +20 -0
- package/dist/esm/pm-plugins/doc.js +31 -26
- package/dist/esm/toolbar.js +24 -6
- package/dist/esm/ui/DatasourceModal/index.js +2 -2
- package/dist/esm/ui/EditDatasourceButton.js +134 -0
- package/dist/esm/ui/EditLinkToolbar.js +1 -23
- package/dist/types/nodeviews/blockCard.d.ts +5 -1
- package/dist/types/pm-plugins/doc.d.ts +1 -1
- package/dist/types/ui/EditDatasourceButton.d.ts +17 -0
- package/dist/types/ui/EditLinkToolbar.d.ts +0 -1
- package/dist/types-ts4.5/nodeviews/blockCard.d.ts +5 -1
- package/dist/types-ts4.5/pm-plugins/doc.d.ts +1 -1
- package/dist/types-ts4.5/ui/EditDatasourceButton.d.ts +17 -0
- package/dist/types-ts4.5/ui/EditLinkToolbar.d.ts +0 -1
- package/package.json +2 -2
- package/dist/cjs/ui/SmallerEditIcon.js +0 -22
- package/dist/es2019/ui/SmallerEditIcon.js +0 -14
- package/dist/esm/ui/SmallerEditIcon.js +0 -14
- package/dist/types/ui/SmallerEditIcon.d.ts +0 -3
- package/dist/types-ts4.5/ui/SmallerEditIcon.d.ts +0 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-card
|
|
2
2
|
|
|
3
|
+
## 0.7.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [`50b3bf73ed3`](https://bitbucket.org/atlassian/atlassian-frontend/commits/50b3bf73ed3) - [ux] Add edit datasource button to toolbar for cards which can resolve into datasources
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- Updated dependencies
|
|
12
|
+
|
|
3
13
|
## 0.6.0
|
|
4
14
|
|
|
5
15
|
### Minor Changes
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.BlockCardComponent = exports.BlockCard = void 0;
|
|
8
|
+
var _get2 = _interopRequireDefault(require("@babel/runtime/helpers/get"));
|
|
8
9
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
9
10
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
10
11
|
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
|
|
@@ -144,6 +145,25 @@ var BlockCard = /*#__PURE__*/function (_ReactNodeView) {
|
|
|
144
145
|
}
|
|
145
146
|
return domRef;
|
|
146
147
|
}
|
|
148
|
+
|
|
149
|
+
// Need this function to check if the datasource attribute was added or not to a blockCard.
|
|
150
|
+
// If so, we return false so we can get the node to re-render properly as a datasource node instead.
|
|
151
|
+
// Otherwise, the node view will still consider the node as a blockCard and render a regular blockCard.
|
|
152
|
+
}, {
|
|
153
|
+
key: "validUpdate",
|
|
154
|
+
value: function validUpdate(currentNode, newNode) {
|
|
155
|
+
var _currentNode$attrs, _newNode$attrs;
|
|
156
|
+
var isCurrentNodeBlockCard = !((_currentNode$attrs = currentNode.attrs) !== null && _currentNode$attrs !== void 0 && _currentNode$attrs.datasource);
|
|
157
|
+
var isNewNodeDatasource = (_newNode$attrs = newNode.attrs) === null || _newNode$attrs === void 0 ? void 0 : _newNode$attrs.datasource;
|
|
158
|
+
|
|
159
|
+
// need to return falsy to update node
|
|
160
|
+
return !(isCurrentNodeBlockCard && isNewNodeDatasource);
|
|
161
|
+
}
|
|
162
|
+
}, {
|
|
163
|
+
key: "update",
|
|
164
|
+
value: function update(node, decorations, _innerDecorations) {
|
|
165
|
+
return (0, _get2.default)((0, _getPrototypeOf2.default)(BlockCard.prototype), "update", this).call(this, node, decorations, _innerDecorations, this.validUpdate);
|
|
166
|
+
}
|
|
147
167
|
}, {
|
|
148
168
|
key: "render",
|
|
149
169
|
value: function render() {
|
|
@@ -4,7 +4,7 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
|
|
|
4
4
|
Object.defineProperty(exports, "__esModule", {
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
|
-
exports.
|
|
7
|
+
exports.updateCardFromDatasourceModal = exports.updateCard = exports.setSelectedCardAppearance = exports.replaceQueuedUrlWithCard = exports.queueCardsFromChangedTr = exports.queueCardFromChangedTr = exports.insertDatasource = exports.handleFallbackWithAnalytics = exports.getLinkNodeType = exports.convertHyperlinkToSmartCard = exports.changeSelectedCardToText = exports.changeSelectedCardToLinkFallback = exports.changeSelectedCardToLink = void 0;
|
|
8
8
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
9
9
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
10
10
|
var _isEqual = _interopRequireDefault(require("lodash/isEqual"));
|
|
@@ -428,39 +428,44 @@ var getLinkNodeType = function getLinkNodeType(appearance, linkNodes) {
|
|
|
428
428
|
}
|
|
429
429
|
};
|
|
430
430
|
|
|
431
|
-
// Apply an update
|
|
431
|
+
// Apply an update made from the datasource edit modal to a card
|
|
432
432
|
exports.getLinkNodeType = getLinkNodeType;
|
|
433
|
-
var
|
|
433
|
+
var updateCardFromDatasourceModal = function updateCardFromDatasourceModal(state, node, newAdf, view, sourceEvent) {
|
|
434
434
|
var tr = state.tr,
|
|
435
435
|
from = state.selection.from,
|
|
436
436
|
schemaNodes = state.schema.nodes;
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
var oldColumnKeys = oldViews === null || oldViews === void 0 ? void 0 : (_oldViews$properties = oldViews.properties) === null || _oldViews$properties === void 0 ? void 0 : _oldViews$properties.columns.map(function (column) {
|
|
451
|
-
return column.key;
|
|
452
|
-
});
|
|
453
|
-
var isColumnChange = !(0, _isEqual.default)(oldColumnKeys, newColumnKeys);
|
|
454
|
-
var isUrlChange = ((_newAdf$attrs = newAdf.attrs) === null || _newAdf$attrs === void 0 ? void 0 : _newAdf$attrs.url) !== ((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.url);
|
|
455
|
-
if (isColumnChange || isUrlChange) {
|
|
456
|
-
tr.setNodeMarkup(from, schemaNodes.blockCard, _objectSpread(_objectSpread({}, node.attrs), newAdf.attrs));
|
|
457
|
-
(0, _card.addLinkMetadata)(state.selection, tr, {
|
|
458
|
-
action: _analytics.ACTION.UPDATED,
|
|
459
|
-
sourceEvent: sourceEvent
|
|
437
|
+
if (newAdf.type === 'blockCard') {
|
|
438
|
+
var _node$attrs, _newAdf$attrs;
|
|
439
|
+
if ((_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.datasource && (_newAdf$attrs = newAdf.attrs) !== null && _newAdf$attrs !== void 0 && _newAdf$attrs.datasource) {
|
|
440
|
+
var _ref3, _ref6, _newViews$properties, _oldViews$properties, _newAdf$attrs2, _node$attrs2;
|
|
441
|
+
// datasource to datasource
|
|
442
|
+
var _ref = (_ref3 = newAdf.attrs.datasource.views) !== null && _ref3 !== void 0 ? _ref3 : [],
|
|
443
|
+
_ref2 = (0, _slicedToArray2.default)(_ref, 1),
|
|
444
|
+
newViews = _ref2[0];
|
|
445
|
+
var _ref4 = (_ref6 = node.attrs.datasource.views) !== null && _ref6 !== void 0 ? _ref6 : [],
|
|
446
|
+
_ref5 = (0, _slicedToArray2.default)(_ref4, 1),
|
|
447
|
+
oldViews = _ref5[0];
|
|
448
|
+
var newColumnKeys = newViews === null || newViews === void 0 ? void 0 : (_newViews$properties = newViews.properties) === null || _newViews$properties === void 0 ? void 0 : _newViews$properties.columns.map(function (column) {
|
|
449
|
+
return column.key;
|
|
460
450
|
});
|
|
451
|
+
var oldColumnKeys = oldViews === null || oldViews === void 0 ? void 0 : (_oldViews$properties = oldViews.properties) === null || _oldViews$properties === void 0 ? void 0 : _oldViews$properties.columns.map(function (column) {
|
|
452
|
+
return column.key;
|
|
453
|
+
});
|
|
454
|
+
var isColumnChange = !(0, _isEqual.default)(oldColumnKeys, newColumnKeys);
|
|
455
|
+
var isUrlChange = ((_newAdf$attrs2 = newAdf.attrs) === null || _newAdf$attrs2 === void 0 ? void 0 : _newAdf$attrs2.url) !== ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.url);
|
|
456
|
+
if (isColumnChange || isUrlChange) {
|
|
457
|
+
tr.setNodeMarkup(from, schemaNodes.blockCard, _objectSpread(_objectSpread({}, node.attrs), newAdf.attrs));
|
|
458
|
+
(0, _card.addLinkMetadata)(state.selection, tr, {
|
|
459
|
+
action: _analytics.ACTION.UPDATED,
|
|
460
|
+
sourceEvent: sourceEvent
|
|
461
|
+
});
|
|
462
|
+
}
|
|
463
|
+
} else {
|
|
464
|
+
// inline or blockCard to datasource
|
|
465
|
+
tr.setNodeMarkup(from, schemaNodes.blockCard, newAdf.attrs);
|
|
461
466
|
}
|
|
462
467
|
} else if (newAdf.type === 'inlineCard') {
|
|
463
|
-
//
|
|
468
|
+
// card type to inlineCard
|
|
464
469
|
tr.setNodeMarkup(from, schemaNodes.inlineCard, newAdf.attrs);
|
|
465
470
|
(0, _card.addLinkMetadata)(state.selection, tr, {
|
|
466
471
|
action: _analytics.ACTION.UPDATED,
|
|
@@ -470,7 +475,7 @@ var updateExistingDatasource = function updateExistingDatasource(state, node, ne
|
|
|
470
475
|
(0, _actions.hideDatasourceModal)(tr);
|
|
471
476
|
view.dispatch(tr.scrollIntoView());
|
|
472
477
|
};
|
|
473
|
-
exports.
|
|
478
|
+
exports.updateCardFromDatasourceModal = updateCardFromDatasourceModal;
|
|
474
479
|
var insertDatasource = function insertDatasource(state, adf, view, sourceEvent) {
|
|
475
480
|
var tr = state.tr,
|
|
476
481
|
from = state.selection.from,
|
package/dist/cjs/toolbar.js
CHANGED
|
@@ -14,6 +14,7 @@ var _analytics = require("@atlaskit/editor-common/analytics");
|
|
|
14
14
|
var _card = require("@atlaskit/editor-common/card");
|
|
15
15
|
var _messages = _interopRequireWildcard(require("@atlaskit/editor-common/messages"));
|
|
16
16
|
var _styles = require("@atlaskit/editor-common/styles");
|
|
17
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
17
18
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
18
19
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
19
20
|
var _utils2 = require("@atlaskit/editor-prosemirror/utils");
|
|
@@ -24,9 +25,9 @@ var _shortcut = _interopRequireDefault(require("@atlaskit/icon/glyph/shortcut"))
|
|
|
24
25
|
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
25
26
|
var _doc = require("./pm-plugins/doc");
|
|
26
27
|
var _main = require("./pm-plugins/main");
|
|
28
|
+
var _EditDatasourceButton = require("./ui/EditDatasourceButton");
|
|
27
29
|
var _EditLinkToolbar = require("./ui/EditLinkToolbar");
|
|
28
30
|
var _LinkToolbarAppearance = require("./ui/LinkToolbarAppearance");
|
|
29
|
-
var _SmallerEditIcon = require("./ui/SmallerEditIcon");
|
|
30
31
|
var _ToolbarViewedEvent = require("./ui/ToolbarViewedEvent");
|
|
31
32
|
var _utils3 = require("./utils");
|
|
32
33
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
@@ -231,7 +232,7 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
|
|
|
231
232
|
pluginInjectionApi: pluginInjectionApi
|
|
232
233
|
})];
|
|
233
234
|
} else if (shouldRenderDatasourceToolbar) {
|
|
234
|
-
return getDatasourceButtonGroup(
|
|
235
|
+
return getDatasourceButtonGroup(metadata, intl, editorAnalyticsApi, node, hoverDecoration, node.attrs.datasource.id);
|
|
235
236
|
} else {
|
|
236
237
|
var inlineCard = state.schema.nodes.inlineCard;
|
|
237
238
|
var toolbarItems = [{
|
|
@@ -288,7 +289,8 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
|
|
|
288
289
|
toolbarItems.unshift.apply(toolbarItems, (0, _toConsumableArray2.default)(alignmentOptions));
|
|
289
290
|
}
|
|
290
291
|
var allowBlockCards = cardOptions.allowBlockCards,
|
|
291
|
-
allowEmbeds = cardOptions.allowEmbeds
|
|
292
|
+
allowEmbeds = cardOptions.allowEmbeds,
|
|
293
|
+
allowDatasource = cardOptions.allowDatasource;
|
|
292
294
|
|
|
293
295
|
// This code will be executed only for appearances such as "inline", "block" & "embed"
|
|
294
296
|
// For url appearance, please see HyperlinkToolbarAppearanceProps
|
|
@@ -315,6 +317,22 @@ var generateToolbarItems = function generateToolbarItems(state, featureFlags, in
|
|
|
315
317
|
type: 'separator'
|
|
316
318
|
}]));
|
|
317
319
|
}
|
|
320
|
+
var shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource;
|
|
321
|
+
if (shouldShowDatasourceEditButton) {
|
|
322
|
+
toolbarItems.unshift({
|
|
323
|
+
type: 'custom',
|
|
324
|
+
fallback: [],
|
|
325
|
+
render: function render(editorView) {
|
|
326
|
+
return /*#__PURE__*/_react.default.createElement(_EditDatasourceButton.EditDatasourceButton, {
|
|
327
|
+
intl: intl,
|
|
328
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
329
|
+
url: url,
|
|
330
|
+
editorView: editorView,
|
|
331
|
+
editorState: state
|
|
332
|
+
});
|
|
333
|
+
}
|
|
334
|
+
});
|
|
335
|
+
}
|
|
318
336
|
return toolbarItems;
|
|
319
337
|
}
|
|
320
338
|
};
|
|
@@ -343,16 +361,16 @@ var getSettingsButtonGroup = function getSettingsButtonGroup(state, featureFlags
|
|
|
343
361
|
type: 'separator'
|
|
344
362
|
}] : [];
|
|
345
363
|
};
|
|
346
|
-
var getDatasourceButtonGroup = function getDatasourceButtonGroup(
|
|
364
|
+
var getDatasourceButtonGroup = function getDatasourceButtonGroup(metadata, intl, editorAnalyticsApi, node, hoverDecoration, datasourceId) {
|
|
347
365
|
var _node$attrs3;
|
|
348
366
|
var toolbarItems = [{
|
|
349
367
|
id: 'editor.edit.datasource',
|
|
350
368
|
type: 'button',
|
|
351
|
-
icon:
|
|
369
|
+
icon: _ui.SmallerEditIcon,
|
|
352
370
|
metadata: metadata,
|
|
353
371
|
className: 'datasource-edit',
|
|
354
372
|
title: intl.formatMessage(_messages.linkToolbarMessages.editDatasource),
|
|
355
|
-
onClick: (0,
|
|
373
|
+
onClick: (0, _EditDatasourceButton.editDatasource)(datasourceId, editorAnalyticsApi),
|
|
356
374
|
testId: 'datasource-edit-button'
|
|
357
375
|
}];
|
|
358
376
|
if (node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.url) {
|
|
@@ -26,7 +26,7 @@ var DatasourceModal = function DatasourceModal(_ref) {
|
|
|
26
26
|
}, [dispatch, state.tr]);
|
|
27
27
|
var onInsert = (0, _react.useCallback)(function (newAdf) {
|
|
28
28
|
if (existingNode) {
|
|
29
|
-
(0, _doc.
|
|
29
|
+
(0, _doc.updateCardFromDatasourceModal)(state, existingNode, newAdf, view);
|
|
30
30
|
} else {
|
|
31
31
|
(0, _doc.insertDatasource)(state, newAdf, view);
|
|
32
32
|
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.editDatasource = exports.EditDatasourceButton = void 0;
|
|
8
|
+
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
9
|
+
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
10
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
+
var _react = require("react");
|
|
12
|
+
var _react2 = require("@emotion/react");
|
|
13
|
+
var _messages = require("@atlaskit/editor-common/messages");
|
|
14
|
+
var _ui = require("@atlaskit/editor-common/ui");
|
|
15
|
+
var _utils = require("@atlaskit/editor-common/utils");
|
|
16
|
+
var _actions = require("../pm-plugins/actions");
|
|
17
|
+
var _CardContextProvider = require("./CardContextProvider");
|
|
18
|
+
/** @jsx jsx */
|
|
19
|
+
|
|
20
|
+
var buttonStyles = (0, _react2.css)({
|
|
21
|
+
pointerEvents: 'auto'
|
|
22
|
+
});
|
|
23
|
+
var buttonWrapperStyles = (0, _react2.css)({
|
|
24
|
+
display: 'flex'
|
|
25
|
+
});
|
|
26
|
+
var EditDatasourceButtonWithCardContext = function EditDatasourceButtonWithCardContext(_ref) {
|
|
27
|
+
var cardContext = _ref.cardContext,
|
|
28
|
+
intl = _ref.intl,
|
|
29
|
+
editorAnalyticsApi = _ref.editorAnalyticsApi,
|
|
30
|
+
url = _ref.url,
|
|
31
|
+
editorView = _ref.editorView,
|
|
32
|
+
editorState = _ref.editorState;
|
|
33
|
+
var _useState = (0, _react.useState)(null),
|
|
34
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
35
|
+
datasourceId = _useState2[0],
|
|
36
|
+
setDatasourceId = _useState2[1];
|
|
37
|
+
(0, _react.useEffect)(function () {
|
|
38
|
+
var fetchDatasource = /*#__PURE__*/function () {
|
|
39
|
+
var _ref2 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee() {
|
|
40
|
+
var _cardContext$connecti, _cardContext$connecti2, _datasources$, response, datasources;
|
|
41
|
+
return _regenerator.default.wrap(function _callee$(_context) {
|
|
42
|
+
while (1) switch (_context.prev = _context.next) {
|
|
43
|
+
case 0:
|
|
44
|
+
_context.prev = 0;
|
|
45
|
+
_context.t0 = url && cardContext;
|
|
46
|
+
if (!_context.t0) {
|
|
47
|
+
_context.next = 6;
|
|
48
|
+
break;
|
|
49
|
+
}
|
|
50
|
+
_context.next = 5;
|
|
51
|
+
return cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$connecti = cardContext.connections) === null || _cardContext$connecti === void 0 ? void 0 : (_cardContext$connecti2 = _cardContext$connecti.client) === null || _cardContext$connecti2 === void 0 ? void 0 : _cardContext$connecti2.fetchData(url);
|
|
52
|
+
case 5:
|
|
53
|
+
_context.t0 = _context.sent;
|
|
54
|
+
case 6:
|
|
55
|
+
response = _context.t0;
|
|
56
|
+
datasources = response && response.datasources || [];
|
|
57
|
+
setDatasourceId(((_datasources$ = datasources[0]) === null || _datasources$ === void 0 ? void 0 : _datasources$.id) || null);
|
|
58
|
+
_context.next = 14;
|
|
59
|
+
break;
|
|
60
|
+
case 11:
|
|
61
|
+
_context.prev = 11;
|
|
62
|
+
_context.t1 = _context["catch"](0);
|
|
63
|
+
setDatasourceId(null);
|
|
64
|
+
case 14:
|
|
65
|
+
case "end":
|
|
66
|
+
return _context.stop();
|
|
67
|
+
}
|
|
68
|
+
}, _callee, null, [[0, 11]]);
|
|
69
|
+
}));
|
|
70
|
+
return function fetchDatasource() {
|
|
71
|
+
return _ref2.apply(this, arguments);
|
|
72
|
+
};
|
|
73
|
+
}();
|
|
74
|
+
void fetchDatasource();
|
|
75
|
+
}, [cardContext, url]);
|
|
76
|
+
if (!datasourceId || !(0, _utils.canRenderDatasource)(datasourceId, false)) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
if (url) {
|
|
80
|
+
var _cardContext$store, _urlState$error;
|
|
81
|
+
var urlState = cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url];
|
|
82
|
+
if ((urlState === null || urlState === void 0 ? void 0 : (_urlState$error = urlState.error) === null || _urlState$error === void 0 ? void 0 : _urlState$error.kind) === 'fatal') {
|
|
83
|
+
return null;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
var dispatchCommand = function dispatchCommand(fn) {
|
|
87
|
+
fn && fn(editorState, editorView && editorView.dispatch);
|
|
88
|
+
if (editorView && !editorView.hasFocus()) {
|
|
89
|
+
editorView.focus();
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
return (0, _react2.jsx)("div", {
|
|
93
|
+
css: buttonWrapperStyles
|
|
94
|
+
}, (0, _react2.jsx)(_ui.FloatingToolbarButton, {
|
|
95
|
+
css: buttonStyles,
|
|
96
|
+
title: intl.formatMessage(_messages.cardMessages.datasourceTitle),
|
|
97
|
+
icon: (0, _react2.jsx)(_ui.SmallerEditIcon, null),
|
|
98
|
+
selected: false,
|
|
99
|
+
onClick: function onClick() {
|
|
100
|
+
return dispatchCommand(editDatasource(datasourceId, editorAnalyticsApi));
|
|
101
|
+
},
|
|
102
|
+
testId: 'card-edit-datasource-button'
|
|
103
|
+
}), (0, _react2.jsx)(_ui.FloatingToolbarSeparator, null));
|
|
104
|
+
};
|
|
105
|
+
var EditDatasourceButton = function EditDatasourceButton(_ref3) {
|
|
106
|
+
var intl = _ref3.intl,
|
|
107
|
+
editorAnalyticsApi = _ref3.editorAnalyticsApi,
|
|
108
|
+
url = _ref3.url,
|
|
109
|
+
editorView = _ref3.editorView,
|
|
110
|
+
editorState = _ref3.editorState;
|
|
111
|
+
return (0, _react2.jsx)(_CardContextProvider.CardContextProvider, null, function (_ref4) {
|
|
112
|
+
var cardContext = _ref4.cardContext;
|
|
113
|
+
return (0, _react2.jsx)(EditDatasourceButtonWithCardContext, {
|
|
114
|
+
url: url,
|
|
115
|
+
intl: intl,
|
|
116
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
117
|
+
editorView: editorView,
|
|
118
|
+
editorState: editorState,
|
|
119
|
+
cardContext: cardContext
|
|
120
|
+
});
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
exports.EditDatasourceButton = EditDatasourceButton;
|
|
124
|
+
var editDatasource = function editDatasource(datasourceId, editorAnalyticsApi) {
|
|
125
|
+
return function (state, dispatch) {
|
|
126
|
+
var datasourceType = (0, _utils.getDatasourceType)(datasourceId);
|
|
127
|
+
if (dispatch && datasourceType) {
|
|
128
|
+
var tr = state.tr;
|
|
129
|
+
(0, _actions.showDatasourceModal)(datasourceType)(tr);
|
|
130
|
+
// editorAnalyticsApi?.attachAnalyticsEvent(
|
|
131
|
+
// buildEditLinkPayload(
|
|
132
|
+
// type as
|
|
133
|
+
// | ACTION_SUBJECT_ID.CARD_INLINE
|
|
134
|
+
// | ACTION_SUBJECT_ID.CARD_BLOCK
|
|
135
|
+
// | ACTION_SUBJECT_ID.EMBEDS,
|
|
136
|
+
// ),
|
|
137
|
+
// )(tr);
|
|
138
|
+
dispatch(tr);
|
|
139
|
+
return true;
|
|
140
|
+
}
|
|
141
|
+
return false;
|
|
142
|
+
};
|
|
143
|
+
};
|
|
144
|
+
exports.editDatasource = editDatasource;
|
|
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
});
|
|
7
7
|
exports.EditLinkToolbar = void 0;
|
|
8
8
|
exports.HyperlinkAddToolbarWithState = HyperlinkAddToolbarWithState;
|
|
9
|
-
exports.editLinkToolbarConfig = exports.editLink = exports.
|
|
9
|
+
exports.editLinkToolbarConfig = exports.editLink = exports.buildEditLinkToolbar = void 0;
|
|
10
10
|
var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
|
|
11
11
|
var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
|
|
12
12
|
var _inherits2 = _interopRequireDefault(require("@babel/runtime/helpers/inherits"));
|
|
@@ -19,11 +19,10 @@ var _hooks = require("@atlaskit/editor-common/hooks");
|
|
|
19
19
|
var _link = require("@atlaskit/editor-common/link");
|
|
20
20
|
var _messages = require("@atlaskit/editor-common/messages");
|
|
21
21
|
var _ui = require("@atlaskit/editor-common/ui");
|
|
22
|
-
var _utils = require("@atlaskit/editor-common/utils");
|
|
23
22
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
24
23
|
var _actions = require("../pm-plugins/actions");
|
|
25
24
|
var _doc = require("../pm-plugins/doc");
|
|
26
|
-
var
|
|
25
|
+
var _utils = require("../utils");
|
|
27
26
|
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); }; }
|
|
28
27
|
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
|
29
28
|
function HyperlinkAddToolbarWithState(_ref) {
|
|
@@ -176,7 +175,7 @@ var buildEditLinkToolbar = function buildEditLinkToolbar(_ref2) {
|
|
|
176
175
|
if (!view || !providerFactory) {
|
|
177
176
|
return null;
|
|
178
177
|
}
|
|
179
|
-
var displayInfo = (0,
|
|
178
|
+
var displayInfo = (0, _utils.displayInfoForCard)(node, (0, _utils.findCardInfo)(view.state));
|
|
180
179
|
return /*#__PURE__*/_react.default.createElement(EditLinkToolbar, {
|
|
181
180
|
pluginInjectionApi: pluginInjectionApi,
|
|
182
181
|
key: idx,
|
|
@@ -219,26 +218,4 @@ var editLinkToolbarConfig = function editLinkToolbarConfig(showLinkingToolbar, l
|
|
|
219
218
|
forcePlacement: true
|
|
220
219
|
} : {};
|
|
221
220
|
};
|
|
222
|
-
exports.editLinkToolbarConfig = editLinkToolbarConfig;
|
|
223
|
-
var editDatasource = function editDatasource(node, editorAnalyticsApi) {
|
|
224
|
-
return function (state, dispatch) {
|
|
225
|
-
var _node$attrs;
|
|
226
|
-
var modalType = (0, _utils.getDatasourceType)((_node$attrs = node.attrs) === null || _node$attrs === void 0 ? void 0 : _node$attrs.datasource.id);
|
|
227
|
-
if (dispatch && modalType) {
|
|
228
|
-
var tr = state.tr;
|
|
229
|
-
(0, _actions.showDatasourceModal)(modalType)(tr);
|
|
230
|
-
// editorAnalyticsApi?.attachAnalyticsEvent(
|
|
231
|
-
// buildEditLinkPayload(
|
|
232
|
-
// type as
|
|
233
|
-
// | ACTION_SUBJECT_ID.CARD_INLINE
|
|
234
|
-
// | ACTION_SUBJECT_ID.CARD_BLOCK
|
|
235
|
-
// | ACTION_SUBJECT_ID.EMBEDS,
|
|
236
|
-
// ),
|
|
237
|
-
// )(tr);
|
|
238
|
-
dispatch(tr);
|
|
239
|
-
return true;
|
|
240
|
-
}
|
|
241
|
-
return false;
|
|
242
|
-
};
|
|
243
|
-
};
|
|
244
|
-
exports.editDatasource = editDatasource;
|
|
221
|
+
exports.editLinkToolbarConfig = editLinkToolbarConfig;
|
|
@@ -115,6 +115,21 @@ export class BlockCard extends ReactNodeView {
|
|
|
115
115
|
}
|
|
116
116
|
return domRef;
|
|
117
117
|
}
|
|
118
|
+
|
|
119
|
+
// Need this function to check if the datasource attribute was added or not to a blockCard.
|
|
120
|
+
// If so, we return false so we can get the node to re-render properly as a datasource node instead.
|
|
121
|
+
// Otherwise, the node view will still consider the node as a blockCard and render a regular blockCard.
|
|
122
|
+
validUpdate(currentNode, newNode) {
|
|
123
|
+
var _currentNode$attrs, _newNode$attrs;
|
|
124
|
+
const isCurrentNodeBlockCard = !((_currentNode$attrs = currentNode.attrs) !== null && _currentNode$attrs !== void 0 && _currentNode$attrs.datasource);
|
|
125
|
+
const isNewNodeDatasource = (_newNode$attrs = newNode.attrs) === null || _newNode$attrs === void 0 ? void 0 : _newNode$attrs.datasource;
|
|
126
|
+
|
|
127
|
+
// need to return falsy to update node
|
|
128
|
+
return !(isCurrentNodeBlockCard && isNewNodeDatasource);
|
|
129
|
+
}
|
|
130
|
+
update(node, decorations, _innerDecorations) {
|
|
131
|
+
return super.update(node, decorations, _innerDecorations, this.validUpdate);
|
|
132
|
+
}
|
|
118
133
|
render() {
|
|
119
134
|
const {
|
|
120
135
|
platform,
|
|
@@ -393,8 +393,8 @@ export const getLinkNodeType = (appearance, linkNodes) => {
|
|
|
393
393
|
}
|
|
394
394
|
};
|
|
395
395
|
|
|
396
|
-
// Apply an update
|
|
397
|
-
export const
|
|
396
|
+
// Apply an update made from the datasource edit modal to a card
|
|
397
|
+
export const updateCardFromDatasourceModal = (state, node, newAdf, view, sourceEvent) => {
|
|
398
398
|
const {
|
|
399
399
|
tr,
|
|
400
400
|
selection: {
|
|
@@ -404,28 +404,33 @@ export const updateExistingDatasource = (state, node, newAdf, view, sourceEvent)
|
|
|
404
404
|
nodes: schemaNodes
|
|
405
405
|
}
|
|
406
406
|
} = state;
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
407
|
+
if (newAdf.type === 'blockCard') {
|
|
408
|
+
var _node$attrs, _newAdf$attrs;
|
|
409
|
+
if ((_node$attrs = node.attrs) !== null && _node$attrs !== void 0 && _node$attrs.datasource && (_newAdf$attrs = newAdf.attrs) !== null && _newAdf$attrs !== void 0 && _newAdf$attrs.datasource) {
|
|
410
|
+
var _ref, _ref2, _newViews$properties, _oldViews$properties, _newAdf$attrs2, _node$attrs2;
|
|
411
|
+
// datasource to datasource
|
|
412
|
+
const [newViews] = (_ref = newAdf.attrs.datasource.views) !== null && _ref !== void 0 ? _ref : [];
|
|
413
|
+
const [oldViews] = (_ref2 = node.attrs.datasource.views) !== null && _ref2 !== void 0 ? _ref2 : [];
|
|
414
|
+
const newColumnKeys = newViews === null || newViews === void 0 ? void 0 : (_newViews$properties = newViews.properties) === null || _newViews$properties === void 0 ? void 0 : _newViews$properties.columns.map(column => column.key);
|
|
415
|
+
const oldColumnKeys = oldViews === null || oldViews === void 0 ? void 0 : (_oldViews$properties = oldViews.properties) === null || _oldViews$properties === void 0 ? void 0 : _oldViews$properties.columns.map(column => column.key);
|
|
416
|
+
const isColumnChange = !isEqual(oldColumnKeys, newColumnKeys);
|
|
417
|
+
const isUrlChange = ((_newAdf$attrs2 = newAdf.attrs) === null || _newAdf$attrs2 === void 0 ? void 0 : _newAdf$attrs2.url) !== ((_node$attrs2 = node.attrs) === null || _node$attrs2 === void 0 ? void 0 : _node$attrs2.url);
|
|
418
|
+
if (isColumnChange || isUrlChange) {
|
|
419
|
+
tr.setNodeMarkup(from, schemaNodes.blockCard, {
|
|
420
|
+
...node.attrs,
|
|
421
|
+
...newAdf.attrs
|
|
422
|
+
});
|
|
423
|
+
addLinkMetadata(state.selection, tr, {
|
|
424
|
+
action: ACTION.UPDATED,
|
|
425
|
+
sourceEvent
|
|
426
|
+
});
|
|
427
|
+
}
|
|
428
|
+
} else {
|
|
429
|
+
// inline or blockCard to datasource
|
|
430
|
+
tr.setNodeMarkup(from, schemaNodes.blockCard, newAdf.attrs);
|
|
426
431
|
}
|
|
427
432
|
} else if (newAdf.type === 'inlineCard') {
|
|
428
|
-
//
|
|
433
|
+
// card type to inlineCard
|
|
429
434
|
tr.setNodeMarkup(from, schemaNodes.inlineCard, newAdf.attrs);
|
|
430
435
|
addLinkMetadata(state.selection, tr, {
|
|
431
436
|
action: ACTION.UPDATED,
|
package/dist/es2019/toolbar.js
CHANGED
|
@@ -4,6 +4,7 @@ import { ACTION, ACTION_SUBJECT, buildOpenedSettingsPayload, buildVisitedLinkPay
|
|
|
4
4
|
import { buildLayoutButtons, commandWithMetadata } from '@atlaskit/editor-common/card';
|
|
5
5
|
import commonMessages, { linkMessages, linkToolbarMessages, cardMessages as messages } from '@atlaskit/editor-common/messages';
|
|
6
6
|
import { FLOATING_TOOLBAR_LINKPICKER_CLASSNAME, richMediaClassName } from '@atlaskit/editor-common/styles';
|
|
7
|
+
import { SmallerEditIcon } from '@atlaskit/editor-common/ui';
|
|
7
8
|
import { canRenderDatasource } from '@atlaskit/editor-common/utils';
|
|
8
9
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
9
10
|
import { findDomRefAtPos, removeSelectedNode } from '@atlaskit/editor-prosemirror/utils';
|
|
@@ -14,9 +15,9 @@ import OpenIcon from '@atlaskit/icon/glyph/shortcut';
|
|
|
14
15
|
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
15
16
|
import { changeSelectedCardToText } from './pm-plugins/doc';
|
|
16
17
|
import { pluginKey } from './pm-plugins/main';
|
|
17
|
-
import {
|
|
18
|
+
import { editDatasource, EditDatasourceButton } from './ui/EditDatasourceButton';
|
|
19
|
+
import { buildEditLinkToolbar, editLink, editLinkToolbarConfig } from './ui/EditLinkToolbar';
|
|
18
20
|
import { LinkToolbarAppearance } from './ui/LinkToolbarAppearance';
|
|
19
|
-
import { SmallerEditIcon } from './ui/SmallerEditIcon';
|
|
20
21
|
import { ToolbarViewedEvent } from './ui/ToolbarViewedEvent';
|
|
21
22
|
import { appearanceForNodeType, displayInfoForCard, findCardInfo, titleUrlPairFromNode } from './utils';
|
|
22
23
|
export const removeCard = editorAnalyticsApi => commandWithMetadata((state, dispatch) => {
|
|
@@ -221,7 +222,7 @@ const generateToolbarItems = (state, featureFlags, intl, providerFactory, cardOp
|
|
|
221
222
|
pluginInjectionApi
|
|
222
223
|
})];
|
|
223
224
|
} else if (shouldRenderDatasourceToolbar) {
|
|
224
|
-
return getDatasourceButtonGroup(
|
|
225
|
+
return getDatasourceButtonGroup(metadata, intl, editorAnalyticsApi, node, hoverDecoration, node.attrs.datasource.id);
|
|
225
226
|
} else {
|
|
226
227
|
const {
|
|
227
228
|
inlineCard
|
|
@@ -281,7 +282,8 @@ const generateToolbarItems = (state, featureFlags, intl, providerFactory, cardOp
|
|
|
281
282
|
}
|
|
282
283
|
const {
|
|
283
284
|
allowBlockCards,
|
|
284
|
-
allowEmbeds
|
|
285
|
+
allowEmbeds,
|
|
286
|
+
allowDatasource
|
|
285
287
|
} = cardOptions;
|
|
286
288
|
|
|
287
289
|
// This code will be executed only for appearances such as "inline", "block" & "embed"
|
|
@@ -307,6 +309,20 @@ const generateToolbarItems = (state, featureFlags, intl, providerFactory, cardOp
|
|
|
307
309
|
type: 'separator'
|
|
308
310
|
});
|
|
309
311
|
}
|
|
312
|
+
const shouldShowDatasourceEditButton = platform !== 'mobile' && allowDatasource;
|
|
313
|
+
if (shouldShowDatasourceEditButton) {
|
|
314
|
+
toolbarItems.unshift({
|
|
315
|
+
type: 'custom',
|
|
316
|
+
fallback: [],
|
|
317
|
+
render: editorView => /*#__PURE__*/React.createElement(EditDatasourceButton, {
|
|
318
|
+
intl: intl,
|
|
319
|
+
editorAnalyticsApi: editorAnalyticsApi,
|
|
320
|
+
url: url,
|
|
321
|
+
editorView: editorView,
|
|
322
|
+
editorState: state
|
|
323
|
+
})
|
|
324
|
+
});
|
|
325
|
+
}
|
|
310
326
|
return toolbarItems;
|
|
311
327
|
}
|
|
312
328
|
};
|
|
@@ -336,7 +352,7 @@ const getSettingsButtonGroup = (state, featureFlags, intl, editorAnalyticsApi) =
|
|
|
336
352
|
type: 'separator'
|
|
337
353
|
}] : [];
|
|
338
354
|
};
|
|
339
|
-
const getDatasourceButtonGroup = (
|
|
355
|
+
const getDatasourceButtonGroup = (metadata, intl, editorAnalyticsApi, node, hoverDecoration, datasourceId) => {
|
|
340
356
|
var _node$attrs3;
|
|
341
357
|
const toolbarItems = [{
|
|
342
358
|
id: 'editor.edit.datasource',
|
|
@@ -345,7 +361,7 @@ const getDatasourceButtonGroup = (state, metadata, intl, editorAnalyticsApi, nod
|
|
|
345
361
|
metadata: metadata,
|
|
346
362
|
className: 'datasource-edit',
|
|
347
363
|
title: intl.formatMessage(linkToolbarMessages.editDatasource),
|
|
348
|
-
onClick: editDatasource(
|
|
364
|
+
onClick: editDatasource(datasourceId, editorAnalyticsApi),
|
|
349
365
|
testId: 'datasource-edit-button'
|
|
350
366
|
}];
|
|
351
367
|
if (node !== null && node !== void 0 && (_node$attrs3 = node.attrs) !== null && _node$attrs3 !== void 0 && _node$attrs3.url) {
|
|
@@ -2,7 +2,7 @@ import React, { useCallback } from 'react';
|
|
|
2
2
|
import { NodeSelection } from '@atlaskit/editor-prosemirror/state';
|
|
3
3
|
import { ASSETS_LIST_OF_LINKS_DATASOURCE_ID, AssetsConfigModal, JIRA_LIST_OF_LINKS_DATASOURCE_ID, JiraIssuesConfigModal } from '@atlaskit/link-datasource';
|
|
4
4
|
import { hideDatasourceModal } from '../../pm-plugins/actions';
|
|
5
|
-
import { insertDatasource,
|
|
5
|
+
import { insertDatasource, updateCardFromDatasourceModal } from '../../pm-plugins/doc';
|
|
6
6
|
export const DatasourceModal = ({
|
|
7
7
|
view,
|
|
8
8
|
modalType
|
|
@@ -20,7 +20,7 @@ export const DatasourceModal = ({
|
|
|
20
20
|
}, [dispatch, state.tr]);
|
|
21
21
|
const onInsert = useCallback(newAdf => {
|
|
22
22
|
if (existingNode) {
|
|
23
|
-
|
|
23
|
+
updateCardFromDatasourceModal(state, existingNode, newAdf, view);
|
|
24
24
|
} else {
|
|
25
25
|
insertDatasource(state, newAdf, view);
|
|
26
26
|
}
|