@atlaskit/editor-plugin-card 0.14.2 → 0.14.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/dist/cjs/common/hooks/useLinkUpgradeDiscoverability.js +5 -2
- package/dist/cjs/nodeviews/inlineCard.js +4 -2
- package/dist/cjs/nodeviews/inlineCardWithAwareness.js +17 -6
- package/dist/cjs/pm-plugins/actions.js +14 -1
- package/dist/cjs/pm-plugins/main.js +31 -4
- package/dist/cjs/pm-plugins/reducers.js +14 -0
- package/dist/es2019/common/hooks/useLinkUpgradeDiscoverability.js +5 -2
- package/dist/es2019/nodeviews/inlineCard.js +4 -2
- package/dist/es2019/nodeviews/inlineCardWithAwareness.js +13 -7
- package/dist/es2019/pm-plugins/actions.js +7 -0
- package/dist/es2019/pm-plugins/main.js +30 -5
- package/dist/es2019/pm-plugins/reducers.js +16 -0
- package/dist/esm/common/hooks/useLinkUpgradeDiscoverability.js +5 -2
- package/dist/esm/nodeviews/inlineCard.js +4 -2
- package/dist/esm/nodeviews/inlineCardWithAwareness.js +18 -7
- package/dist/esm/pm-plugins/actions.js +13 -0
- package/dist/esm/pm-plugins/main.js +33 -6
- package/dist/esm/pm-plugins/reducers.js +14 -0
- package/dist/types/common/hooks/useLinkUpgradeDiscoverability.d.ts +1 -0
- package/dist/types/pm-plugins/actions.d.ts +7 -5
- package/dist/types/pm-plugins/reducers.d.ts +1 -1
- package/dist/types/pm-plugins/util/state.d.ts +2 -0
- package/dist/types/types.d.ts +10 -1
- package/dist/types-ts4.5/common/hooks/useLinkUpgradeDiscoverability.d.ts +1 -0
- package/dist/types-ts4.5/pm-plugins/actions.d.ts +7 -5
- package/dist/types-ts4.5/pm-plugins/reducers.d.ts +1 -1
- package/dist/types-ts4.5/pm-plugins/util/state.d.ts +2 -0
- package/dist/types-ts4.5/types.d.ts +10 -1
- package/package.json +1 -1
- package/report.api.md +2 -0
- package/tmp/api-report-tmp.d.ts +2 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-card
|
|
2
2
|
|
|
3
|
+
## 0.14.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#43494](https://bitbucket.org/atlassian/atlassian-frontend/pull-requests/43494) [`7c59a134595`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7c59a134595) - [ux] Show inline card upgrade discoverability overlay on insertion. The functionality behind the inline switcher feature flag
|
|
8
|
+
|
|
3
9
|
## 0.14.2
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
|
@@ -9,7 +9,7 @@ var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/sli
|
|
|
9
9
|
var _react = require("react");
|
|
10
10
|
var _localStorage = require("../local-storage");
|
|
11
11
|
var useLinkUpgradeDiscoverability = function useLinkUpgradeDiscoverability(_ref) {
|
|
12
|
-
var _cardContext$store, _pluginInjectionApi$c2;
|
|
12
|
+
var _cardContext$store, _pluginInjectionApi$c2, _pluginInjectionApi$c3;
|
|
13
13
|
var url = _ref.url,
|
|
14
14
|
linkPosition = _ref.linkPosition,
|
|
15
15
|
cardContext = _ref.cardContext,
|
|
@@ -43,13 +43,16 @@ var useLinkUpgradeDiscoverability = function useLinkUpgradeDiscoverability(_ref)
|
|
|
43
43
|
return isPulseEnabled && linkPosition === awarenessCandidatePosition && canBeUpgradedToEmbed;
|
|
44
44
|
}, [canBeUpgradedToEmbed, isPulseEnabled, linkPosition, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.card) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.sharedState]);
|
|
45
45
|
var shouldShowLinkOverlay = (urlState === null || urlState === void 0 ? void 0 : urlState.status) === 'resolved' && isOverlayEnabled;
|
|
46
|
+
var overlayCandidatePos = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c3 = pluginInjectionApi.card) === null || _pluginInjectionApi$c3 === void 0 || (_pluginInjectionApi$c3 = _pluginInjectionApi$c3.sharedState) === null || _pluginInjectionApi$c3 === void 0 || (_pluginInjectionApi$c3 = _pluginInjectionApi$c3.currentState()) === null || _pluginInjectionApi$c3 === void 0 ? void 0 : _pluginInjectionApi$c3.overlayCandidatePosition;
|
|
47
|
+
var isLinkMostRecentlyInserted = overlayCandidatePos === linkPosition;
|
|
46
48
|
var shouldShowToolbarPulse = (0, _react.useMemo)(function () {
|
|
47
49
|
return isPulseEnabled && !(0, _localStorage.isLocalStorageKeyDiscovered)(_localStorage.LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR) && canBeUpgradedToEmbed;
|
|
48
50
|
}, [canBeUpgradedToEmbed, isPulseEnabled]);
|
|
49
51
|
return {
|
|
50
52
|
shouldShowToolbarPulse: shouldShowToolbarPulse,
|
|
51
53
|
shouldShowLinkPulse: shouldShowLinkPulse,
|
|
52
|
-
shouldShowLinkOverlay: shouldShowLinkOverlay
|
|
54
|
+
shouldShowLinkOverlay: shouldShowLinkOverlay,
|
|
55
|
+
isLinkMostRecentlyInserted: isLinkMostRecentlyInserted
|
|
53
56
|
};
|
|
54
57
|
};
|
|
55
58
|
var _default = exports.default = useLinkUpgradeDiscoverability;
|
|
@@ -55,11 +55,13 @@ var InlineCardComponent = exports.InlineCardComponent = /*#__PURE__*/function (_
|
|
|
55
55
|
if (typeof pos !== 'number') {
|
|
56
56
|
return;
|
|
57
57
|
}
|
|
58
|
-
view.
|
|
58
|
+
var tr = view.state.tr;
|
|
59
|
+
(0, _actions.registerCard)({
|
|
59
60
|
title: title,
|
|
60
61
|
url: url,
|
|
61
62
|
pos: pos
|
|
62
|
-
})(
|
|
63
|
+
})(tr);
|
|
64
|
+
view.dispatch(tr);
|
|
63
65
|
})();
|
|
64
66
|
});
|
|
65
67
|
(0, _defineProperty2.default)((0, _assertThisInitialized2.default)(_this), "onError", function (data) {
|
|
@@ -47,6 +47,10 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
47
47
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
48
48
|
isHovered = _useState2[0],
|
|
49
49
|
setIsHovered = _useState2[1];
|
|
50
|
+
var _useState3 = (0, _react.useState)(false),
|
|
51
|
+
_useState4 = (0, _slicedToArray2.default)(_useState3, 2),
|
|
52
|
+
isInserted = _useState4[0],
|
|
53
|
+
setIsInserted = _useState4[1];
|
|
50
54
|
var linkPosition = (0, _react.useMemo)(function () {
|
|
51
55
|
if (!getPos || typeof getPos === 'boolean') {
|
|
52
56
|
return undefined;
|
|
@@ -64,7 +68,8 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
64
68
|
}),
|
|
65
69
|
shouldShowLinkPulse = _useLinkUpgradeDiscov.shouldShowLinkPulse,
|
|
66
70
|
shouldShowToolbarPulse = _useLinkUpgradeDiscov.shouldShowToolbarPulse,
|
|
67
|
-
shouldShowLinkOverlay = _useLinkUpgradeDiscov.shouldShowLinkOverlay
|
|
71
|
+
shouldShowLinkOverlay = _useLinkUpgradeDiscov.shouldShowLinkOverlay,
|
|
72
|
+
isLinkMostRecentlyInserted = _useLinkUpgradeDiscov.isLinkMostRecentlyInserted;
|
|
68
73
|
|
|
69
74
|
// If the toolbar pulse has not yet been invalidated and this is a case where we will be showing it,
|
|
70
75
|
// we need to invalidate the link pulse too. Toolbar pulse will be invalidated in the corresponding component.
|
|
@@ -90,13 +95,19 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
90
95
|
if (typeof pos !== 'number') {
|
|
91
96
|
return;
|
|
92
97
|
}
|
|
93
|
-
view.
|
|
98
|
+
var tr = view.state.tr;
|
|
99
|
+
(0, _actions.registerCard)({
|
|
94
100
|
title: title,
|
|
95
101
|
url: url,
|
|
96
102
|
pos: pos
|
|
97
|
-
})(
|
|
103
|
+
})(tr);
|
|
104
|
+
(0, _actions.registerRemoveOverlay)(function () {
|
|
105
|
+
return setIsInserted(false);
|
|
106
|
+
})(tr);
|
|
107
|
+
view.dispatch(tr);
|
|
98
108
|
})();
|
|
99
|
-
|
|
109
|
+
setIsInserted(isLinkMostRecentlyInserted);
|
|
110
|
+
}, [view, getPos, isLinkMostRecentlyInserted]);
|
|
100
111
|
var onError = (0, _react.useCallback)(function (data) {
|
|
101
112
|
var url = data.url,
|
|
102
113
|
err = data.err;
|
|
@@ -126,7 +137,7 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
126
137
|
var cardWithOverlay = (0, _react.useMemo)(function () {
|
|
127
138
|
return shouldShowLinkOverlay ? (0, _react2.jsx)(_InlineCardOverlay.default, {
|
|
128
139
|
isSelected: isSelected,
|
|
129
|
-
isVisible: isHovered || isSelected,
|
|
140
|
+
isVisible: isInserted || isHovered || isSelected,
|
|
130
141
|
onMouseEnter: function onMouseEnter() {
|
|
131
142
|
return setIsHovered(true);
|
|
132
143
|
},
|
|
@@ -135,7 +146,7 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
135
146
|
},
|
|
136
147
|
url: url
|
|
137
148
|
}, innerCard) : innerCard;
|
|
138
|
-
}, [innerCard, isHovered, isSelected, shouldShowLinkOverlay, url]);
|
|
149
|
+
}, [innerCard, isHovered, isSelected, isInserted, shouldShowLinkOverlay, url]);
|
|
139
150
|
var card = (0, _react.useMemo)(function () {
|
|
140
151
|
return (0, _react2.jsx)("span", {
|
|
141
152
|
css: shouldShowLinkPulse && loaderWrapperStyles,
|
|
@@ -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.registerCard = exports.queueCards = exports.hideLinkToolbar = exports.hideDatasourceModal = exports.cardAction = void 0;
|
|
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;
|
|
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);
|
|
@@ -32,6 +32,14 @@ var registerCard = exports.registerCard = function registerCard(info) {
|
|
|
32
32
|
});
|
|
33
33
|
};
|
|
34
34
|
};
|
|
35
|
+
var registerRemoveOverlay = exports.registerRemoveOverlay = function registerRemoveOverlay(callback) {
|
|
36
|
+
return function (tr) {
|
|
37
|
+
return cardAction(tr, {
|
|
38
|
+
type: 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK',
|
|
39
|
+
callback: callback
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
};
|
|
35
43
|
var registerSmartCardEvents = exports.registerSmartCardEvents = function registerSmartCardEvents(smartLinkEvents) {
|
|
36
44
|
return function (tr) {
|
|
37
45
|
return cardAction(tr, {
|
|
@@ -97,4 +105,9 @@ var hideDatasourceModal = exports.hideDatasourceModal = function hideDatasourceM
|
|
|
97
105
|
return cardAction(tr, {
|
|
98
106
|
type: 'HIDE_DATASOURCE_MODAL'
|
|
99
107
|
});
|
|
108
|
+
};
|
|
109
|
+
var clearOverlayCandidate = exports.clearOverlayCandidate = function clearOverlayCandidate(tr) {
|
|
110
|
+
return cardAction(tr, {
|
|
111
|
+
type: 'CLEAR_OVERLAY_CANDIDATE'
|
|
112
|
+
});
|
|
100
113
|
};
|
|
@@ -11,6 +11,7 @@ Object.defineProperty(exports, "pluginKey", {
|
|
|
11
11
|
return _pluginKey.pluginKey;
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
14
15
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
15
16
|
var _rafSchd = _interopRequireDefault(require("raf-schd"));
|
|
16
17
|
var _reactNodeView = require("@atlaskit/editor-common/react-node-view");
|
|
@@ -32,7 +33,20 @@ var _pluginKey = require("./plugin-key");
|
|
|
32
33
|
var _reducers = _interopRequireDefault(require("./reducers"));
|
|
33
34
|
var _resolve = require("./util/resolve");
|
|
34
35
|
var _state2 = require("./util/state");
|
|
36
|
+
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; }
|
|
37
|
+
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; }
|
|
35
38
|
var LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK = 'smart-link-upgrade-pulse';
|
|
39
|
+
var handleAwarenessOverlay = function handleAwarenessOverlay(view) {
|
|
40
|
+
var currentState = (0, _state2.getPluginState)(view.state);
|
|
41
|
+
var overlayCandidatePos = currentState === null || currentState === void 0 ? void 0 : currentState.overlayCandidatePosition;
|
|
42
|
+
if (overlayCandidatePos) {
|
|
43
|
+
var _currentState$removeO;
|
|
44
|
+
(_currentState$removeO = currentState.removeOverlay) === null || _currentState$removeO === void 0 || _currentState$removeO.call(currentState);
|
|
45
|
+
var tr = view.state.tr;
|
|
46
|
+
(0, _actions.clearOverlayCandidate)(tr);
|
|
47
|
+
view.dispatch(tr);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
36
50
|
var createPlugin = exports.createPlugin = function createPlugin(options, pluginInjectionApi) {
|
|
37
51
|
return function (pmPluginFactoryParams) {
|
|
38
52
|
var editorAppearance = options.editorAppearance,
|
|
@@ -97,12 +111,16 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
|
|
|
97
111
|
// the code below is related to the "Inline Switcher" project, for more information pls see EDM-7984
|
|
98
112
|
var isSingleInlineLink = (pluginState === null || pluginState === void 0 || (_pluginState$requests = pluginState.requests) === null || _pluginState$requests === void 0 ? void 0 : _pluginState$requests.length) === 1 && pluginState.requests[0].appearance === 'inline';
|
|
99
113
|
var isSmartLinkPulseDiscovered = (0, _localStorage.isLocalStorageKeyDiscovered)(LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
|
|
100
|
-
if (meta.type !== 'RESOLVE' || !enableInlineUpgradeFeatures ||
|
|
114
|
+
if (meta.type !== 'RESOLVE' || !enableInlineUpgradeFeatures || !isSingleInlineLink) {
|
|
101
115
|
return newState;
|
|
102
116
|
}
|
|
103
117
|
var linkPosition = pluginState.requests[0].pos;
|
|
118
|
+
var canBeUpgradedToBlock = allowBlockCards && (0, _utils3.isBlockSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
|
|
104
119
|
var canBeUpgradedToEmbed = allowEmbeds && (0, _utils3.isEmbedSupportedAtPosition)(linkPosition, prevEditorState, 'inline');
|
|
105
|
-
if (canBeUpgradedToEmbed) {
|
|
120
|
+
if (canBeUpgradedToBlock || canBeUpgradedToEmbed) {
|
|
121
|
+
newState.overlayCandidatePosition = linkPosition;
|
|
122
|
+
}
|
|
123
|
+
if (!isSmartLinkPulseDiscovered && canBeUpgradedToEmbed) {
|
|
106
124
|
newState.inlineCardAwarenessCandidatePosition = linkPosition;
|
|
107
125
|
}
|
|
108
126
|
return newState;
|
|
@@ -188,7 +206,7 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
|
|
|
188
206
|
}
|
|
189
207
|
};
|
|
190
208
|
},
|
|
191
|
-
props: {
|
|
209
|
+
props: _objectSpread({
|
|
192
210
|
nodeViews: {
|
|
193
211
|
inlineCard: inlineCardViewProducer,
|
|
194
212
|
blockCard: function blockCard(node, view, getPos, decorations) {
|
|
@@ -235,7 +253,16 @@ var createPlugin = exports.createPlugin = function createPlugin(options, pluginI
|
|
|
235
253
|
return new _embedCard.EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
|
|
236
254
|
}
|
|
237
255
|
}
|
|
238
|
-
},
|
|
256
|
+
}, (0, _platformFeatureFlags.getBooleanFF)('platform.linking-platform.smart-card.inline-switcher') && {
|
|
257
|
+
handleKeyDown: function handleKeyDown(view) {
|
|
258
|
+
handleAwarenessOverlay(view);
|
|
259
|
+
return false;
|
|
260
|
+
},
|
|
261
|
+
handleClick: function handleClick(view) {
|
|
262
|
+
handleAwarenessOverlay(view);
|
|
263
|
+
return false;
|
|
264
|
+
}
|
|
265
|
+
}),
|
|
239
266
|
key: _pluginKey.pluginKey
|
|
240
267
|
});
|
|
241
268
|
};
|
|
@@ -74,6 +74,16 @@ var hideDatasourceModal = function hideDatasourceModal(state) {
|
|
|
74
74
|
datasourceModalType: undefined
|
|
75
75
|
});
|
|
76
76
|
};
|
|
77
|
+
var clearOverlayCandidate = function clearOverlayCandidate(state) {
|
|
78
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
79
|
+
overlayCandidatePosition: undefined
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
var registerRemoveOverlayOnInsertedLink = function registerRemoveOverlayOnInsertedLink(state, action) {
|
|
83
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
84
|
+
removeOverlay: action.callback
|
|
85
|
+
});
|
|
86
|
+
};
|
|
77
87
|
var _default = exports.default = function _default(state, action) {
|
|
78
88
|
switch (action.type) {
|
|
79
89
|
case 'QUEUE':
|
|
@@ -99,5 +109,9 @@ var _default = exports.default = function _default(state, action) {
|
|
|
99
109
|
return showDatasourceModal(state, action);
|
|
100
110
|
case 'HIDE_DATASOURCE_MODAL':
|
|
101
111
|
return hideDatasourceModal(state);
|
|
112
|
+
case 'CLEAR_OVERLAY_CANDIDATE':
|
|
113
|
+
return clearOverlayCandidate(state);
|
|
114
|
+
case 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK':
|
|
115
|
+
return registerRemoveOverlayOnInsertedLink(state, action);
|
|
102
116
|
}
|
|
103
117
|
};
|
|
@@ -8,7 +8,7 @@ const useLinkUpgradeDiscoverability = ({
|
|
|
8
8
|
isPulseEnabled,
|
|
9
9
|
isOverlayEnabled
|
|
10
10
|
}) => {
|
|
11
|
-
var _cardContext$store, _pluginInjectionApi$c4;
|
|
11
|
+
var _cardContext$store, _pluginInjectionApi$c4, _pluginInjectionApi$c5, _pluginInjectionApi$c6, _pluginInjectionApi$c7;
|
|
12
12
|
const [urlState, setUrlState] = useState(cardContext === null || cardContext === void 0 ? void 0 : (_cardContext$store = cardContext.store) === null || _cardContext$store === void 0 ? void 0 : _cardContext$store.getState()[url]);
|
|
13
13
|
useEffect(() => {
|
|
14
14
|
var _cardContext$store2;
|
|
@@ -33,11 +33,14 @@ const useLinkUpgradeDiscoverability = ({
|
|
|
33
33
|
return isPulseEnabled && linkPosition === awarenessCandidatePosition && canBeUpgradedToEmbed;
|
|
34
34
|
}, [canBeUpgradedToEmbed, isPulseEnabled, linkPosition, pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c4 = pluginInjectionApi.card) === null || _pluginInjectionApi$c4 === void 0 ? void 0 : _pluginInjectionApi$c4.sharedState]);
|
|
35
35
|
const shouldShowLinkOverlay = (urlState === null || urlState === void 0 ? void 0 : urlState.status) === 'resolved' && isOverlayEnabled;
|
|
36
|
+
const overlayCandidatePos = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c5 = pluginInjectionApi.card) === null || _pluginInjectionApi$c5 === void 0 ? void 0 : (_pluginInjectionApi$c6 = _pluginInjectionApi$c5.sharedState) === null || _pluginInjectionApi$c6 === void 0 ? void 0 : (_pluginInjectionApi$c7 = _pluginInjectionApi$c6.currentState()) === null || _pluginInjectionApi$c7 === void 0 ? void 0 : _pluginInjectionApi$c7.overlayCandidatePosition;
|
|
37
|
+
const isLinkMostRecentlyInserted = overlayCandidatePos === linkPosition;
|
|
36
38
|
const shouldShowToolbarPulse = useMemo(() => isPulseEnabled && !isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR) && canBeUpgradedToEmbed, [canBeUpgradedToEmbed, isPulseEnabled]);
|
|
37
39
|
return {
|
|
38
40
|
shouldShowToolbarPulse,
|
|
39
41
|
shouldShowLinkPulse,
|
|
40
|
-
shouldShowLinkOverlay
|
|
42
|
+
shouldShowLinkOverlay,
|
|
43
|
+
isLinkMostRecentlyInserted
|
|
41
44
|
};
|
|
42
45
|
};
|
|
43
46
|
export default useLinkUpgradeDiscoverability;
|
|
@@ -36,11 +36,13 @@ export class InlineCardComponent extends React.PureComponent {
|
|
|
36
36
|
if (typeof pos !== 'number') {
|
|
37
37
|
return;
|
|
38
38
|
}
|
|
39
|
-
view.
|
|
39
|
+
const tr = view.state.tr;
|
|
40
|
+
registerCard({
|
|
40
41
|
title,
|
|
41
42
|
url,
|
|
42
43
|
pos
|
|
43
|
-
})(
|
|
44
|
+
})(tr);
|
|
45
|
+
view.dispatch(tr);
|
|
44
46
|
})();
|
|
45
47
|
});
|
|
46
48
|
_defineProperty(this, "onError", data => {
|
|
@@ -7,7 +7,7 @@ import { Card as SmartCard } from '@atlaskit/smart-card';
|
|
|
7
7
|
import useLinkUpgradeDiscoverability from '../common/hooks/useLinkUpgradeDiscoverability';
|
|
8
8
|
import { isLocalStorageKeyDiscovered, LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK, LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR, markLocalStorageKeyDiscovered, ONE_DAY_IN_MILLISECONDS } from '../common/local-storage';
|
|
9
9
|
import { DiscoveryPulse } from '../common/pulse';
|
|
10
|
-
import { registerCard } from '../pm-plugins/actions';
|
|
10
|
+
import { registerCard, registerRemoveOverlay } from '../pm-plugins/actions';
|
|
11
11
|
import InlineCardOverlay from '../ui/InlineCardOverlay';
|
|
12
12
|
// editor adds a standard line-height that is bigger than an inline smart link
|
|
13
13
|
// due to that the link has a bit of white space around it, which doesn't look right when there is pulse around it
|
|
@@ -36,6 +36,7 @@ const InlineCard = ({
|
|
|
36
36
|
|
|
37
37
|
// BEGIN: Awareness (To be revisited in EDM-8508)
|
|
38
38
|
const [isHovered, setIsHovered] = useState(false);
|
|
39
|
+
const [isInserted, setIsInserted] = useState(false);
|
|
39
40
|
const linkPosition = useMemo(() => {
|
|
40
41
|
if (!getPos || typeof getPos === 'boolean') {
|
|
41
42
|
return undefined;
|
|
@@ -46,7 +47,8 @@ const InlineCard = ({
|
|
|
46
47
|
const {
|
|
47
48
|
shouldShowLinkPulse,
|
|
48
49
|
shouldShowToolbarPulse,
|
|
49
|
-
shouldShowLinkOverlay
|
|
50
|
+
shouldShowLinkOverlay,
|
|
51
|
+
isLinkMostRecentlyInserted
|
|
50
52
|
} = useLinkUpgradeDiscoverability({
|
|
51
53
|
url,
|
|
52
54
|
linkPosition: linkPosition || -1,
|
|
@@ -80,13 +82,17 @@ const InlineCard = ({
|
|
|
80
82
|
if (typeof pos !== 'number') {
|
|
81
83
|
return;
|
|
82
84
|
}
|
|
83
|
-
view.
|
|
85
|
+
const tr = view.state.tr;
|
|
86
|
+
registerCard({
|
|
84
87
|
title,
|
|
85
88
|
url,
|
|
86
89
|
pos
|
|
87
|
-
})(
|
|
90
|
+
})(tr);
|
|
91
|
+
registerRemoveOverlay(() => setIsInserted(false))(tr);
|
|
92
|
+
view.dispatch(tr);
|
|
88
93
|
})();
|
|
89
|
-
|
|
94
|
+
setIsInserted(isLinkMostRecentlyInserted);
|
|
95
|
+
}, [view, getPos, isLinkMostRecentlyInserted]);
|
|
90
96
|
const onError = useCallback(data => {
|
|
91
97
|
const {
|
|
92
98
|
url,
|
|
@@ -115,11 +121,11 @@ const InlineCard = ({
|
|
|
115
121
|
// BEGIN: Awareness (To be revisited in EDM-8508)
|
|
116
122
|
const cardWithOverlay = useMemo(() => shouldShowLinkOverlay ? jsx(InlineCardOverlay, {
|
|
117
123
|
isSelected: isSelected,
|
|
118
|
-
isVisible: isHovered || isSelected,
|
|
124
|
+
isVisible: isInserted || isHovered || isSelected,
|
|
119
125
|
onMouseEnter: () => setIsHovered(true),
|
|
120
126
|
onMouseLeave: () => setIsHovered(false),
|
|
121
127
|
url: url
|
|
122
|
-
}, innerCard) : innerCard, [innerCard, isHovered, isSelected, shouldShowLinkOverlay, url]);
|
|
128
|
+
}, innerCard) : innerCard, [innerCard, isHovered, isSelected, isInserted, shouldShowLinkOverlay, url]);
|
|
123
129
|
const card = useMemo(() => jsx("span", {
|
|
124
130
|
css: shouldShowLinkPulse && loaderWrapperStyles,
|
|
125
131
|
className: "card"
|
|
@@ -14,6 +14,10 @@ export const registerCard = info => tr => cardAction(tr, {
|
|
|
14
14
|
type: 'REGISTER',
|
|
15
15
|
info
|
|
16
16
|
});
|
|
17
|
+
export const registerRemoveOverlay = callback => tr => cardAction(tr, {
|
|
18
|
+
type: 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK',
|
|
19
|
+
callback
|
|
20
|
+
});
|
|
17
21
|
export const registerSmartCardEvents = smartLinkEvents => tr => cardAction(tr, {
|
|
18
22
|
type: 'REGISTER_EVENTS',
|
|
19
23
|
smartLinkEvents
|
|
@@ -50,4 +54,7 @@ export const showDatasourceModal = modalType => tr => cardAction(tr, {
|
|
|
50
54
|
});
|
|
51
55
|
export const hideDatasourceModal = tr => cardAction(tr, {
|
|
52
56
|
type: 'HIDE_DATASOURCE_MODAL'
|
|
57
|
+
});
|
|
58
|
+
export const clearOverlayCandidate = tr => cardAction(tr, {
|
|
59
|
+
type: 'CLEAR_OVERLAY_CANDIDATE'
|
|
53
60
|
});
|
|
@@ -12,14 +12,25 @@ import { BlockCard } from '../nodeviews/blockCard';
|
|
|
12
12
|
import { Datasource } from '../nodeviews/datasource';
|
|
13
13
|
import { EmbedCard } from '../nodeviews/embedCard';
|
|
14
14
|
import { InlineCardNodeView } from '../nodeviews/inlineCard';
|
|
15
|
-
import { isEmbedSupportedAtPosition } from '../utils';
|
|
16
|
-
import { setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
|
|
15
|
+
import { isBlockSupportedAtPosition, isEmbedSupportedAtPosition } from '../utils';
|
|
16
|
+
import { clearOverlayCandidate, setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
|
|
17
17
|
import { pluginKey } from './plugin-key';
|
|
18
18
|
import reducer from './reducers';
|
|
19
19
|
import { handleProvider, resolveWithProvider } from './util/resolve';
|
|
20
20
|
import { getNewRequests, getPluginState, getPluginStateWithUpdatedPos } from './util/state';
|
|
21
21
|
export { pluginKey } from './plugin-key';
|
|
22
22
|
const LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK = 'smart-link-upgrade-pulse';
|
|
23
|
+
const handleAwarenessOverlay = view => {
|
|
24
|
+
const currentState = getPluginState(view.state);
|
|
25
|
+
const overlayCandidatePos = currentState === null || currentState === void 0 ? void 0 : currentState.overlayCandidatePosition;
|
|
26
|
+
if (overlayCandidatePos) {
|
|
27
|
+
var _currentState$removeO;
|
|
28
|
+
(_currentState$removeO = currentState.removeOverlay) === null || _currentState$removeO === void 0 ? void 0 : _currentState$removeO.call(currentState);
|
|
29
|
+
const tr = view.state.tr;
|
|
30
|
+
clearOverlayCandidate(tr);
|
|
31
|
+
view.dispatch(tr);
|
|
32
|
+
}
|
|
33
|
+
};
|
|
23
34
|
export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryParams => {
|
|
24
35
|
const {
|
|
25
36
|
editorAppearance,
|
|
@@ -85,12 +96,16 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
|
|
|
85
96
|
// the code below is related to the "Inline Switcher" project, for more information pls see EDM-7984
|
|
86
97
|
const isSingleInlineLink = (pluginState === null || pluginState === void 0 ? void 0 : (_pluginState$requests = pluginState.requests) === null || _pluginState$requests === void 0 ? void 0 : _pluginState$requests.length) === 1 && pluginState.requests[0].appearance === 'inline';
|
|
87
98
|
const isSmartLinkPulseDiscovered = isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
|
|
88
|
-
if (meta.type !== 'RESOLVE' || !enableInlineUpgradeFeatures ||
|
|
99
|
+
if (meta.type !== 'RESOLVE' || !enableInlineUpgradeFeatures || !isSingleInlineLink) {
|
|
89
100
|
return newState;
|
|
90
101
|
}
|
|
91
102
|
const linkPosition = pluginState.requests[0].pos;
|
|
103
|
+
const canBeUpgradedToBlock = allowBlockCards && isBlockSupportedAtPosition(linkPosition, prevEditorState, 'inline');
|
|
92
104
|
const canBeUpgradedToEmbed = allowEmbeds && isEmbedSupportedAtPosition(linkPosition, prevEditorState, 'inline');
|
|
93
|
-
if (canBeUpgradedToEmbed) {
|
|
105
|
+
if (canBeUpgradedToBlock || canBeUpgradedToEmbed) {
|
|
106
|
+
newState.overlayCandidatePosition = linkPosition;
|
|
107
|
+
}
|
|
108
|
+
if (!isSmartLinkPulseDiscovered && canBeUpgradedToEmbed) {
|
|
94
109
|
newState.inlineCardAwarenessCandidatePosition = linkPosition;
|
|
95
110
|
}
|
|
96
111
|
return newState;
|
|
@@ -230,7 +245,17 @@ export const createPlugin = (options, pluginInjectionApi) => pmPluginFactoryPara
|
|
|
230
245
|
const hasIntlContext = true;
|
|
231
246
|
return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
|
|
232
247
|
}
|
|
233
|
-
}
|
|
248
|
+
},
|
|
249
|
+
...(getBooleanFF('platform.linking-platform.smart-card.inline-switcher') && {
|
|
250
|
+
handleKeyDown: view => {
|
|
251
|
+
handleAwarenessOverlay(view);
|
|
252
|
+
return false;
|
|
253
|
+
},
|
|
254
|
+
handleClick: view => {
|
|
255
|
+
handleAwarenessOverlay(view);
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
})
|
|
234
259
|
},
|
|
235
260
|
key: pluginKey
|
|
236
261
|
});
|
|
@@ -73,6 +73,18 @@ const hideDatasourceModal = state => {
|
|
|
73
73
|
datasourceModalType: undefined
|
|
74
74
|
};
|
|
75
75
|
};
|
|
76
|
+
const clearOverlayCandidate = state => {
|
|
77
|
+
return {
|
|
78
|
+
...state,
|
|
79
|
+
overlayCandidatePosition: undefined
|
|
80
|
+
};
|
|
81
|
+
};
|
|
82
|
+
const registerRemoveOverlayOnInsertedLink = (state, action) => {
|
|
83
|
+
return {
|
|
84
|
+
...state,
|
|
85
|
+
removeOverlay: action.callback
|
|
86
|
+
};
|
|
87
|
+
};
|
|
76
88
|
export default ((state, action) => {
|
|
77
89
|
switch (action.type) {
|
|
78
90
|
case 'QUEUE':
|
|
@@ -98,5 +110,9 @@ export default ((state, action) => {
|
|
|
98
110
|
return showDatasourceModal(state, action);
|
|
99
111
|
case 'HIDE_DATASOURCE_MODAL':
|
|
100
112
|
return hideDatasourceModal(state);
|
|
113
|
+
case 'CLEAR_OVERLAY_CANDIDATE':
|
|
114
|
+
return clearOverlayCandidate(state);
|
|
115
|
+
case 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK':
|
|
116
|
+
return registerRemoveOverlayOnInsertedLink(state, action);
|
|
101
117
|
}
|
|
102
118
|
});
|
|
@@ -2,7 +2,7 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
2
2
|
import { useEffect, useMemo, useState } from 'react';
|
|
3
3
|
import { isLocalStorageKeyDiscovered, LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR } from '../local-storage';
|
|
4
4
|
var useLinkUpgradeDiscoverability = function useLinkUpgradeDiscoverability(_ref) {
|
|
5
|
-
var _cardContext$store, _pluginInjectionApi$c2;
|
|
5
|
+
var _cardContext$store, _pluginInjectionApi$c2, _pluginInjectionApi$c3;
|
|
6
6
|
var url = _ref.url,
|
|
7
7
|
linkPosition = _ref.linkPosition,
|
|
8
8
|
cardContext = _ref.cardContext,
|
|
@@ -36,13 +36,16 @@ var useLinkUpgradeDiscoverability = function useLinkUpgradeDiscoverability(_ref)
|
|
|
36
36
|
return isPulseEnabled && linkPosition === awarenessCandidatePosition && canBeUpgradedToEmbed;
|
|
37
37
|
}, [canBeUpgradedToEmbed, isPulseEnabled, linkPosition, pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.card) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.sharedState]);
|
|
38
38
|
var shouldShowLinkOverlay = (urlState === null || urlState === void 0 ? void 0 : urlState.status) === 'resolved' && isOverlayEnabled;
|
|
39
|
+
var overlayCandidatePos = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c3 = pluginInjectionApi.card) === null || _pluginInjectionApi$c3 === void 0 || (_pluginInjectionApi$c3 = _pluginInjectionApi$c3.sharedState) === null || _pluginInjectionApi$c3 === void 0 || (_pluginInjectionApi$c3 = _pluginInjectionApi$c3.currentState()) === null || _pluginInjectionApi$c3 === void 0 ? void 0 : _pluginInjectionApi$c3.overlayCandidatePosition;
|
|
40
|
+
var isLinkMostRecentlyInserted = overlayCandidatePos === linkPosition;
|
|
39
41
|
var shouldShowToolbarPulse = useMemo(function () {
|
|
40
42
|
return isPulseEnabled && !isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR) && canBeUpgradedToEmbed;
|
|
41
43
|
}, [canBeUpgradedToEmbed, isPulseEnabled]);
|
|
42
44
|
return {
|
|
43
45
|
shouldShowToolbarPulse: shouldShowToolbarPulse,
|
|
44
46
|
shouldShowLinkPulse: shouldShowLinkPulse,
|
|
45
|
-
shouldShowLinkOverlay: shouldShowLinkOverlay
|
|
47
|
+
shouldShowLinkOverlay: shouldShowLinkOverlay,
|
|
48
|
+
isLinkMostRecentlyInserted: isLinkMostRecentlyInserted
|
|
46
49
|
};
|
|
47
50
|
};
|
|
48
51
|
export default useLinkUpgradeDiscoverability;
|
|
@@ -48,11 +48,13 @@ export var InlineCardComponent = /*#__PURE__*/function (_React$PureComponent) {
|
|
|
48
48
|
if (typeof pos !== 'number') {
|
|
49
49
|
return;
|
|
50
50
|
}
|
|
51
|
-
view.
|
|
51
|
+
var tr = view.state.tr;
|
|
52
|
+
registerCard({
|
|
52
53
|
title: title,
|
|
53
54
|
url: url,
|
|
54
55
|
pos: pos
|
|
55
|
-
})(
|
|
56
|
+
})(tr);
|
|
57
|
+
view.dispatch(tr);
|
|
56
58
|
})();
|
|
57
59
|
});
|
|
58
60
|
_defineProperty(_assertThisInitialized(_this), "onError", function (data) {
|
|
@@ -8,7 +8,7 @@ import { Card as SmartCard } from '@atlaskit/smart-card';
|
|
|
8
8
|
import useLinkUpgradeDiscoverability from '../common/hooks/useLinkUpgradeDiscoverability';
|
|
9
9
|
import { isLocalStorageKeyDiscovered, LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK, LOCAL_STORAGE_DISCOVERY_KEY_TOOLBAR, markLocalStorageKeyDiscovered, ONE_DAY_IN_MILLISECONDS } from '../common/local-storage';
|
|
10
10
|
import { DiscoveryPulse } from '../common/pulse';
|
|
11
|
-
import { registerCard } from '../pm-plugins/actions';
|
|
11
|
+
import { registerCard, registerRemoveOverlay } from '../pm-plugins/actions';
|
|
12
12
|
import InlineCardOverlay from '../ui/InlineCardOverlay';
|
|
13
13
|
// editor adds a standard line-height that is bigger than an inline smart link
|
|
14
14
|
// due to that the link has a bit of white space around it, which doesn't look right when there is pulse around it
|
|
@@ -39,6 +39,10 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
39
39
|
_useState2 = _slicedToArray(_useState, 2),
|
|
40
40
|
isHovered = _useState2[0],
|
|
41
41
|
setIsHovered = _useState2[1];
|
|
42
|
+
var _useState3 = useState(false),
|
|
43
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
44
|
+
isInserted = _useState4[0],
|
|
45
|
+
setIsInserted = _useState4[1];
|
|
42
46
|
var linkPosition = useMemo(function () {
|
|
43
47
|
if (!getPos || typeof getPos === 'boolean') {
|
|
44
48
|
return undefined;
|
|
@@ -56,7 +60,8 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
56
60
|
}),
|
|
57
61
|
shouldShowLinkPulse = _useLinkUpgradeDiscov.shouldShowLinkPulse,
|
|
58
62
|
shouldShowToolbarPulse = _useLinkUpgradeDiscov.shouldShowToolbarPulse,
|
|
59
|
-
shouldShowLinkOverlay = _useLinkUpgradeDiscov.shouldShowLinkOverlay
|
|
63
|
+
shouldShowLinkOverlay = _useLinkUpgradeDiscov.shouldShowLinkOverlay,
|
|
64
|
+
isLinkMostRecentlyInserted = _useLinkUpgradeDiscov.isLinkMostRecentlyInserted;
|
|
60
65
|
|
|
61
66
|
// If the toolbar pulse has not yet been invalidated and this is a case where we will be showing it,
|
|
62
67
|
// we need to invalidate the link pulse too. Toolbar pulse will be invalidated in the corresponding component.
|
|
@@ -82,13 +87,19 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
82
87
|
if (typeof pos !== 'number') {
|
|
83
88
|
return;
|
|
84
89
|
}
|
|
85
|
-
view.
|
|
90
|
+
var tr = view.state.tr;
|
|
91
|
+
registerCard({
|
|
86
92
|
title: title,
|
|
87
93
|
url: url,
|
|
88
94
|
pos: pos
|
|
89
|
-
})(
|
|
95
|
+
})(tr);
|
|
96
|
+
registerRemoveOverlay(function () {
|
|
97
|
+
return setIsInserted(false);
|
|
98
|
+
})(tr);
|
|
99
|
+
view.dispatch(tr);
|
|
90
100
|
})();
|
|
91
|
-
|
|
101
|
+
setIsInserted(isLinkMostRecentlyInserted);
|
|
102
|
+
}, [view, getPos, isLinkMostRecentlyInserted]);
|
|
92
103
|
var onError = useCallback(function (data) {
|
|
93
104
|
var url = data.url,
|
|
94
105
|
err = data.err;
|
|
@@ -118,7 +129,7 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
118
129
|
var cardWithOverlay = useMemo(function () {
|
|
119
130
|
return shouldShowLinkOverlay ? jsx(InlineCardOverlay, {
|
|
120
131
|
isSelected: isSelected,
|
|
121
|
-
isVisible: isHovered || isSelected,
|
|
132
|
+
isVisible: isInserted || isHovered || isSelected,
|
|
122
133
|
onMouseEnter: function onMouseEnter() {
|
|
123
134
|
return setIsHovered(true);
|
|
124
135
|
},
|
|
@@ -127,7 +138,7 @@ var InlineCard = function InlineCard(_ref) {
|
|
|
127
138
|
},
|
|
128
139
|
url: url
|
|
129
140
|
}, innerCard) : innerCard;
|
|
130
|
-
}, [innerCard, isHovered, isSelected, shouldShowLinkOverlay, url]);
|
|
141
|
+
}, [innerCard, isHovered, isSelected, isInserted, shouldShowLinkOverlay, url]);
|
|
131
142
|
var card = useMemo(function () {
|
|
132
143
|
return jsx("span", {
|
|
133
144
|
css: shouldShowLinkPulse && loaderWrapperStyles,
|
|
@@ -26,6 +26,14 @@ export var registerCard = function registerCard(info) {
|
|
|
26
26
|
});
|
|
27
27
|
};
|
|
28
28
|
};
|
|
29
|
+
export var registerRemoveOverlay = function registerRemoveOverlay(callback) {
|
|
30
|
+
return function (tr) {
|
|
31
|
+
return cardAction(tr, {
|
|
32
|
+
type: 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK',
|
|
33
|
+
callback: callback
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
};
|
|
29
37
|
export var registerSmartCardEvents = function registerSmartCardEvents(smartLinkEvents) {
|
|
30
38
|
return function (tr) {
|
|
31
39
|
return cardAction(tr, {
|
|
@@ -91,4 +99,9 @@ export var hideDatasourceModal = function hideDatasourceModal(tr) {
|
|
|
91
99
|
return cardAction(tr, {
|
|
92
100
|
type: 'HIDE_DATASOURCE_MODAL'
|
|
93
101
|
});
|
|
102
|
+
};
|
|
103
|
+
export var clearOverlayCandidate = function clearOverlayCandidate(tr) {
|
|
104
|
+
return cardAction(tr, {
|
|
105
|
+
type: 'CLEAR_OVERLAY_CANDIDATE'
|
|
106
|
+
});
|
|
94
107
|
};
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
1
2
|
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
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; }
|
|
4
|
+
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; }
|
|
2
5
|
import rafSchedule from 'raf-schd';
|
|
3
6
|
import { getInlineNodeViewProducer } from '@atlaskit/editor-common/react-node-view';
|
|
4
7
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
@@ -13,14 +16,25 @@ import { BlockCard } from '../nodeviews/blockCard';
|
|
|
13
16
|
import { Datasource } from '../nodeviews/datasource';
|
|
14
17
|
import { EmbedCard } from '../nodeviews/embedCard';
|
|
15
18
|
import { InlineCardNodeView } from '../nodeviews/inlineCard';
|
|
16
|
-
import { isEmbedSupportedAtPosition } from '../utils';
|
|
17
|
-
import { setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
|
|
19
|
+
import { isBlockSupportedAtPosition, isEmbedSupportedAtPosition } from '../utils';
|
|
20
|
+
import { clearOverlayCandidate, setCardLayoutAndDatasourceTableRef, setDatasourceTableRef } from './actions';
|
|
18
21
|
import { pluginKey } from './plugin-key';
|
|
19
22
|
import reducer from './reducers';
|
|
20
23
|
import { handleProvider, resolveWithProvider } from './util/resolve';
|
|
21
24
|
import { getNewRequests, getPluginState, getPluginStateWithUpdatedPos } from './util/state';
|
|
22
25
|
export { pluginKey } from './plugin-key';
|
|
23
26
|
var LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK = 'smart-link-upgrade-pulse';
|
|
27
|
+
var handleAwarenessOverlay = function handleAwarenessOverlay(view) {
|
|
28
|
+
var currentState = getPluginState(view.state);
|
|
29
|
+
var overlayCandidatePos = currentState === null || currentState === void 0 ? void 0 : currentState.overlayCandidatePosition;
|
|
30
|
+
if (overlayCandidatePos) {
|
|
31
|
+
var _currentState$removeO;
|
|
32
|
+
(_currentState$removeO = currentState.removeOverlay) === null || _currentState$removeO === void 0 || _currentState$removeO.call(currentState);
|
|
33
|
+
var tr = view.state.tr;
|
|
34
|
+
clearOverlayCandidate(tr);
|
|
35
|
+
view.dispatch(tr);
|
|
36
|
+
}
|
|
37
|
+
};
|
|
24
38
|
export var createPlugin = function createPlugin(options, pluginInjectionApi) {
|
|
25
39
|
return function (pmPluginFactoryParams) {
|
|
26
40
|
var editorAppearance = options.editorAppearance,
|
|
@@ -85,12 +99,16 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
|
|
|
85
99
|
// the code below is related to the "Inline Switcher" project, for more information pls see EDM-7984
|
|
86
100
|
var isSingleInlineLink = (pluginState === null || pluginState === void 0 || (_pluginState$requests = pluginState.requests) === null || _pluginState$requests === void 0 ? void 0 : _pluginState$requests.length) === 1 && pluginState.requests[0].appearance === 'inline';
|
|
87
101
|
var isSmartLinkPulseDiscovered = isLocalStorageKeyDiscovered(LOCAL_STORAGE_DISCOVERY_KEY_SMART_LINK);
|
|
88
|
-
if (meta.type !== 'RESOLVE' || !enableInlineUpgradeFeatures ||
|
|
102
|
+
if (meta.type !== 'RESOLVE' || !enableInlineUpgradeFeatures || !isSingleInlineLink) {
|
|
89
103
|
return newState;
|
|
90
104
|
}
|
|
91
105
|
var linkPosition = pluginState.requests[0].pos;
|
|
106
|
+
var canBeUpgradedToBlock = allowBlockCards && isBlockSupportedAtPosition(linkPosition, prevEditorState, 'inline');
|
|
92
107
|
var canBeUpgradedToEmbed = allowEmbeds && isEmbedSupportedAtPosition(linkPosition, prevEditorState, 'inline');
|
|
93
|
-
if (canBeUpgradedToEmbed) {
|
|
108
|
+
if (canBeUpgradedToBlock || canBeUpgradedToEmbed) {
|
|
109
|
+
newState.overlayCandidatePosition = linkPosition;
|
|
110
|
+
}
|
|
111
|
+
if (!isSmartLinkPulseDiscovered && canBeUpgradedToEmbed) {
|
|
94
112
|
newState.inlineCardAwarenessCandidatePosition = linkPosition;
|
|
95
113
|
}
|
|
96
114
|
return newState;
|
|
@@ -176,7 +194,7 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
|
|
|
176
194
|
}
|
|
177
195
|
};
|
|
178
196
|
},
|
|
179
|
-
props: {
|
|
197
|
+
props: _objectSpread({
|
|
180
198
|
nodeViews: {
|
|
181
199
|
inlineCard: inlineCardViewProducer,
|
|
182
200
|
blockCard: function blockCard(node, view, getPos, decorations) {
|
|
@@ -223,7 +241,16 @@ export var createPlugin = function createPlugin(options, pluginInjectionApi) {
|
|
|
223
241
|
return new EmbedCard(node, view, getPos, portalProviderAPI, eventDispatcher, reactComponentProps, undefined, true, undefined, hasIntlContext).init();
|
|
224
242
|
}
|
|
225
243
|
}
|
|
226
|
-
},
|
|
244
|
+
}, getBooleanFF('platform.linking-platform.smart-card.inline-switcher') && {
|
|
245
|
+
handleKeyDown: function handleKeyDown(view) {
|
|
246
|
+
handleAwarenessOverlay(view);
|
|
247
|
+
return false;
|
|
248
|
+
},
|
|
249
|
+
handleClick: function handleClick(view) {
|
|
250
|
+
handleAwarenessOverlay(view);
|
|
251
|
+
return false;
|
|
252
|
+
}
|
|
253
|
+
}),
|
|
227
254
|
key: pluginKey
|
|
228
255
|
});
|
|
229
256
|
};
|
|
@@ -67,6 +67,16 @@ var hideDatasourceModal = function hideDatasourceModal(state) {
|
|
|
67
67
|
datasourceModalType: undefined
|
|
68
68
|
});
|
|
69
69
|
};
|
|
70
|
+
var clearOverlayCandidate = function clearOverlayCandidate(state) {
|
|
71
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
72
|
+
overlayCandidatePosition: undefined
|
|
73
|
+
});
|
|
74
|
+
};
|
|
75
|
+
var registerRemoveOverlayOnInsertedLink = function registerRemoveOverlayOnInsertedLink(state, action) {
|
|
76
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
77
|
+
removeOverlay: action.callback
|
|
78
|
+
});
|
|
79
|
+
};
|
|
70
80
|
export default (function (state, action) {
|
|
71
81
|
switch (action.type) {
|
|
72
82
|
case 'QUEUE':
|
|
@@ -92,5 +102,9 @@ export default (function (state, action) {
|
|
|
92
102
|
return showDatasourceModal(state, action);
|
|
93
103
|
case 'HIDE_DATASOURCE_MODAL':
|
|
94
104
|
return hideDatasourceModal(state);
|
|
105
|
+
case 'CLEAR_OVERLAY_CANDIDATE':
|
|
106
|
+
return clearOverlayCandidate(state);
|
|
107
|
+
case 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK':
|
|
108
|
+
return registerRemoveOverlayOnInsertedLink(state, action);
|
|
95
109
|
}
|
|
96
110
|
});
|
|
@@ -13,5 +13,6 @@ declare const useLinkUpgradeDiscoverability: ({ url, linkPosition, cardContext,
|
|
|
13
13
|
shouldShowToolbarPulse: boolean | undefined;
|
|
14
14
|
shouldShowLinkPulse: boolean | undefined;
|
|
15
15
|
shouldShowLinkOverlay: boolean | undefined;
|
|
16
|
+
isLinkMostRecentlyInserted: boolean;
|
|
16
17
|
};
|
|
17
18
|
export default useLinkUpgradeDiscoverability;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { CardProvider } from '@atlaskit/editor-common/provider-factory';
|
|
1
|
+
import type { CardProvider } from '@atlaskit/editor-common/provider-factory';
|
|
2
2
|
import type { DatasourceModalType } from '@atlaskit/editor-common/types';
|
|
3
|
-
import { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { SmartLinkEvents } from '@atlaskit/smart-card';
|
|
5
|
-
import { CardInfo, CardPluginAction, Request } from '../types';
|
|
6
|
-
import { DatasourceTableLayout } from '../ui/LayoutButton/types';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { SmartLinkEvents } from '@atlaskit/smart-card';
|
|
5
|
+
import type { CardInfo, CardPluginAction, Request } from '../types';
|
|
6
|
+
import type { DatasourceTableLayout } from '../ui/LayoutButton/types';
|
|
7
7
|
export declare const cardAction: (tr: Transaction, action: CardPluginAction) => Transaction;
|
|
8
8
|
export declare const resolveCard: (url: string) => (tr: Transaction) => Transaction;
|
|
9
9
|
export declare const queueCards: (requests: Request[]) => (tr: Transaction) => Transaction;
|
|
10
10
|
export declare const registerCard: (info: CardInfo) => (tr: Transaction) => Transaction;
|
|
11
|
+
export declare const registerRemoveOverlay: (callback: () => void) => (tr: Transaction) => Transaction;
|
|
11
12
|
export declare const registerSmartCardEvents: (smartLinkEvents: SmartLinkEvents) => (tr: Transaction) => Transaction;
|
|
12
13
|
export declare const setProvider: (cardProvider: CardProvider | null) => (tr: Transaction) => Transaction;
|
|
13
14
|
export declare const setDatasourceTableRef: (datasourceTableRef?: HTMLElement) => (tr: Transaction) => Transaction;
|
|
@@ -20,3 +21,4 @@ export declare const showLinkToolbar: (tr: Transaction) => Transaction;
|
|
|
20
21
|
export declare const hideLinkToolbar: (tr: Transaction) => Transaction;
|
|
21
22
|
export declare const showDatasourceModal: (modalType: DatasourceModalType) => (tr: Transaction) => Transaction;
|
|
22
23
|
export declare const hideDatasourceModal: (tr: Transaction) => Transaction;
|
|
24
|
+
export declare const clearOverlayCandidate: (tr: Transaction) => Transaction;
|
|
@@ -27,6 +27,8 @@ export declare const getPluginStateWithUpdatedPos: (pluginState: CardPluginState
|
|
|
27
27
|
datasourceTableRef?: HTMLElement | undefined;
|
|
28
28
|
layout?: import("../../ui/LayoutButton/types").DatasourceTableLayout | undefined;
|
|
29
29
|
inlineCardAwarenessCandidatePosition?: number | undefined;
|
|
30
|
+
overlayCandidatePosition?: number | undefined;
|
|
31
|
+
removeOverlay?: (() => void) | undefined;
|
|
30
32
|
selectedInlineLinkPosition?: number | undefined;
|
|
31
33
|
allowEmbeds?: boolean | undefined;
|
|
32
34
|
allowBlockCards?: boolean | undefined;
|
package/dist/types/types.d.ts
CHANGED
|
@@ -77,6 +77,8 @@ export type CardPluginState = {
|
|
|
77
77
|
datasourceTableRef?: HTMLElement;
|
|
78
78
|
layout?: DatasourceTableLayout;
|
|
79
79
|
inlineCardAwarenessCandidatePosition?: number;
|
|
80
|
+
overlayCandidatePosition?: number;
|
|
81
|
+
removeOverlay?: () => void;
|
|
80
82
|
selectedInlineLinkPosition?: number;
|
|
81
83
|
allowEmbeds?: boolean;
|
|
82
84
|
allowBlockCards?: boolean;
|
|
@@ -134,4 +136,11 @@ export type SetCardLayoutAndDatasourceTableRef = {
|
|
|
134
136
|
layout: DatasourceTableLayout;
|
|
135
137
|
datasourceTableRef?: HTMLElement;
|
|
136
138
|
};
|
|
137
|
-
export type
|
|
139
|
+
export type ClearOverlayCandidate = {
|
|
140
|
+
type: 'CLEAR_OVERLAY_CANDIDATE';
|
|
141
|
+
};
|
|
142
|
+
export type RegisterRemoveOverlayOnInsertedLink = {
|
|
143
|
+
type: 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK';
|
|
144
|
+
callback: () => void;
|
|
145
|
+
};
|
|
146
|
+
export type CardPluginAction = SetProvider | Queue | Resolve | Register | ShowLinkToolbar | HideLinkToolbar | ShowDatasourceModal | HideDatasourceModal | RegisterSmartCardEvents | SetDatasourceTableRef | SetCardLayout | SetCardLayoutAndDatasourceTableRef | ClearOverlayCandidate | RegisterRemoveOverlayOnInsertedLink;
|
|
@@ -13,5 +13,6 @@ declare const useLinkUpgradeDiscoverability: ({ url, linkPosition, cardContext,
|
|
|
13
13
|
shouldShowToolbarPulse: boolean | undefined;
|
|
14
14
|
shouldShowLinkPulse: boolean | undefined;
|
|
15
15
|
shouldShowLinkOverlay: boolean | undefined;
|
|
16
|
+
isLinkMostRecentlyInserted: boolean;
|
|
16
17
|
};
|
|
17
18
|
export default useLinkUpgradeDiscoverability;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
|
-
import { CardProvider } from '@atlaskit/editor-common/provider-factory';
|
|
1
|
+
import type { CardProvider } from '@atlaskit/editor-common/provider-factory';
|
|
2
2
|
import type { DatasourceModalType } from '@atlaskit/editor-common/types';
|
|
3
|
-
import { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
-
import { SmartLinkEvents } from '@atlaskit/smart-card';
|
|
5
|
-
import { CardInfo, CardPluginAction, Request } from '../types';
|
|
6
|
-
import { DatasourceTableLayout } from '../ui/LayoutButton/types';
|
|
3
|
+
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
4
|
+
import type { SmartLinkEvents } from '@atlaskit/smart-card';
|
|
5
|
+
import type { CardInfo, CardPluginAction, Request } from '../types';
|
|
6
|
+
import type { DatasourceTableLayout } from '../ui/LayoutButton/types';
|
|
7
7
|
export declare const cardAction: (tr: Transaction, action: CardPluginAction) => Transaction;
|
|
8
8
|
export declare const resolveCard: (url: string) => (tr: Transaction) => Transaction;
|
|
9
9
|
export declare const queueCards: (requests: Request[]) => (tr: Transaction) => Transaction;
|
|
10
10
|
export declare const registerCard: (info: CardInfo) => (tr: Transaction) => Transaction;
|
|
11
|
+
export declare const registerRemoveOverlay: (callback: () => void) => (tr: Transaction) => Transaction;
|
|
11
12
|
export declare const registerSmartCardEvents: (smartLinkEvents: SmartLinkEvents) => (tr: Transaction) => Transaction;
|
|
12
13
|
export declare const setProvider: (cardProvider: CardProvider | null) => (tr: Transaction) => Transaction;
|
|
13
14
|
export declare const setDatasourceTableRef: (datasourceTableRef?: HTMLElement) => (tr: Transaction) => Transaction;
|
|
@@ -20,3 +21,4 @@ export declare const showLinkToolbar: (tr: Transaction) => Transaction;
|
|
|
20
21
|
export declare const hideLinkToolbar: (tr: Transaction) => Transaction;
|
|
21
22
|
export declare const showDatasourceModal: (modalType: DatasourceModalType) => (tr: Transaction) => Transaction;
|
|
22
23
|
export declare const hideDatasourceModal: (tr: Transaction) => Transaction;
|
|
24
|
+
export declare const clearOverlayCandidate: (tr: Transaction) => Transaction;
|
|
@@ -27,6 +27,8 @@ export declare const getPluginStateWithUpdatedPos: (pluginState: CardPluginState
|
|
|
27
27
|
datasourceTableRef?: HTMLElement | undefined;
|
|
28
28
|
layout?: import("../../ui/LayoutButton/types").DatasourceTableLayout | undefined;
|
|
29
29
|
inlineCardAwarenessCandidatePosition?: number | undefined;
|
|
30
|
+
overlayCandidatePosition?: number | undefined;
|
|
31
|
+
removeOverlay?: (() => void) | undefined;
|
|
30
32
|
selectedInlineLinkPosition?: number | undefined;
|
|
31
33
|
allowEmbeds?: boolean | undefined;
|
|
32
34
|
allowBlockCards?: boolean | undefined;
|
|
@@ -77,6 +77,8 @@ export type CardPluginState = {
|
|
|
77
77
|
datasourceTableRef?: HTMLElement;
|
|
78
78
|
layout?: DatasourceTableLayout;
|
|
79
79
|
inlineCardAwarenessCandidatePosition?: number;
|
|
80
|
+
overlayCandidatePosition?: number;
|
|
81
|
+
removeOverlay?: () => void;
|
|
80
82
|
selectedInlineLinkPosition?: number;
|
|
81
83
|
allowEmbeds?: boolean;
|
|
82
84
|
allowBlockCards?: boolean;
|
|
@@ -134,4 +136,11 @@ export type SetCardLayoutAndDatasourceTableRef = {
|
|
|
134
136
|
layout: DatasourceTableLayout;
|
|
135
137
|
datasourceTableRef?: HTMLElement;
|
|
136
138
|
};
|
|
137
|
-
export type
|
|
139
|
+
export type ClearOverlayCandidate = {
|
|
140
|
+
type: 'CLEAR_OVERLAY_CANDIDATE';
|
|
141
|
+
};
|
|
142
|
+
export type RegisterRemoveOverlayOnInsertedLink = {
|
|
143
|
+
type: 'REGISTER_REMOVE_OVERLAY_ON_INSERTED_LINK';
|
|
144
|
+
callback: () => void;
|
|
145
|
+
};
|
|
146
|
+
export type CardPluginAction = SetProvider | Queue | Resolve | Register | ShowLinkToolbar | HideLinkToolbar | ShowDatasourceModal | HideDatasourceModal | RegisterSmartCardEvents | SetDatasourceTableRef | SetCardLayout | SetCardLayoutAndDatasourceTableRef | ClearOverlayCandidate | RegisterRemoveOverlayOnInsertedLink;
|
package/package.json
CHANGED
package/report.api.md
CHANGED
|
@@ -91,6 +91,8 @@ type CardPluginState = {
|
|
|
91
91
|
datasourceTableRef?: HTMLElement;
|
|
92
92
|
layout?: DatasourceTableLayout;
|
|
93
93
|
inlineCardAwarenessCandidatePosition?: number;
|
|
94
|
+
overlayCandidatePosition?: number;
|
|
95
|
+
removeOverlay?: () => void;
|
|
94
96
|
selectedInlineLinkPosition?: number;
|
|
95
97
|
allowEmbeds?: boolean;
|
|
96
98
|
allowBlockCards?: boolean;
|
package/tmp/api-report-tmp.d.ts
CHANGED
|
@@ -77,6 +77,8 @@ type CardPluginState = {
|
|
|
77
77
|
datasourceTableRef?: HTMLElement;
|
|
78
78
|
layout?: DatasourceTableLayout;
|
|
79
79
|
inlineCardAwarenessCandidatePosition?: number;
|
|
80
|
+
overlayCandidatePosition?: number;
|
|
81
|
+
removeOverlay?: () => void;
|
|
80
82
|
selectedInlineLinkPosition?: number;
|
|
81
83
|
allowEmbeds?: boolean;
|
|
82
84
|
allowBlockCards?: boolean;
|