@atlaskit/editor-plugin-hyperlink 1.7.2 → 2.0.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/.eslintrc.js +3 -3
- package/CHANGELOG.md +342 -333
- package/LICENSE.md +6 -8
- package/dist/cjs/Toolbar.js +16 -32
- package/dist/cjs/commands.js +20 -19
- package/dist/cjs/plugin.js +9 -5
- package/dist/cjs/pm-plugins/toolbar-buttons.js +4 -69
- package/dist/es2019/Toolbar.js +15 -21
- package/dist/es2019/commands.js +8 -10
- package/dist/es2019/plugin.js +10 -6
- package/dist/es2019/pm-plugins/toolbar-buttons.js +3 -75
- package/dist/esm/Toolbar.js +15 -31
- package/dist/esm/commands.js +20 -19
- package/dist/esm/plugin.js +10 -6
- package/dist/esm/pm-plugins/toolbar-buttons.js +3 -68
- package/dist/types/Toolbar.d.ts +1 -5
- package/dist/types/commands.d.ts +4 -3
- package/dist/types/index.d.ts +0 -1
- package/dist/types/plugin.d.ts +2 -15
- package/dist/types/pm-plugins/toolbar-buttons.d.ts +3 -30
- package/dist/types-ts4.5/Toolbar.d.ts +1 -5
- package/dist/types-ts4.5/commands.d.ts +4 -3
- package/dist/types-ts4.5/index.d.ts +0 -1
- package/dist/types-ts4.5/plugin.d.ts +3 -15
- package/dist/types-ts4.5/pm-plugins/toolbar-buttons.d.ts +3 -30
- package/package.json +3 -4
- package/report.api.md +38 -47
package/LICENSE.md
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
Copyright 2023 Atlassian Pty Ltd
|
|
2
2
|
|
|
3
|
-
Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
|
|
5
|
-
You may obtain a copy of the License at
|
|
3
|
+
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in
|
|
4
|
+
compliance with the License. You may obtain a copy of the License at
|
|
6
5
|
|
|
7
6
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
8
7
|
|
|
9
|
-
Unless required by applicable law or agreed to in writing, software
|
|
10
|
-
distributed
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
limitations under the License.
|
|
8
|
+
Unless required by applicable law or agreed to in writing, software distributed under the License is
|
|
9
|
+
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
10
|
+
implied. See the License for the specific language governing permissions and limitations under the
|
|
11
|
+
License.
|
package/dist/cjs/Toolbar.js
CHANGED
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
value: true
|
|
6
6
|
});
|
|
7
7
|
exports.HyperlinkAddToolbarWithState = HyperlinkAddToolbarWithState;
|
|
8
|
-
exports.
|
|
8
|
+
exports.getToolbarConfig = void 0;
|
|
9
9
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
10
|
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
11
|
var _react = _interopRequireDefault(require("react"));
|
|
@@ -93,7 +93,9 @@ function HyperlinkAddToolbarWithState(_ref) {
|
|
|
93
93
|
onClose: onClose,
|
|
94
94
|
onEscapeCallback: onEscapeCallback,
|
|
95
95
|
onClickAwayCallback: onClickAwayCallback,
|
|
96
|
-
|
|
96
|
+
timesViewed: hyperlinkState.timesViewed,
|
|
97
|
+
inputMethod: hyperlinkState.inputMethod,
|
|
98
|
+
searchSessionId: hyperlinkState.searchSessionId
|
|
97
99
|
});
|
|
98
100
|
}
|
|
99
101
|
var getSettingsButtonGroup = function getSettingsButtonGroup(intl, editorAnalyticsApi) {
|
|
@@ -109,34 +111,15 @@ var getSettingsButtonGroup = function getSettingsButtonGroup(intl, editorAnalyti
|
|
|
109
111
|
target: '_blank'
|
|
110
112
|
}];
|
|
111
113
|
};
|
|
112
|
-
var mergeAddedItems = exports.mergeAddedItems = function mergeAddedItems(link) {
|
|
113
|
-
for (var _len = arguments.length, handlerParams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
|
114
|
-
handlerParams[_key - 1] = arguments[_key];
|
|
115
|
-
}
|
|
116
|
-
return function (items, toolbarItemsState) {
|
|
117
|
-
var positions = toolbarItemsState === null || toolbarItemsState === void 0 ? void 0 : toolbarItemsState.items_next;
|
|
118
|
-
if (!positions) {
|
|
119
|
-
return items;
|
|
120
|
-
}
|
|
121
|
-
var start = positions.start;
|
|
122
|
-
var end = positions.end;
|
|
123
|
-
var reduceItems = function reduceItems() {
|
|
124
|
-
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
125
|
-
return items.reduce(function (acc, fn) {
|
|
126
|
-
return [].concat((0, _toConsumableArray2.default)(acc), (0, _toConsumableArray2.default)(fn.apply(void 0, handlerParams.concat([link]))));
|
|
127
|
-
}, []);
|
|
128
|
-
};
|
|
129
|
-
return [].concat((0, _toConsumableArray2.default)(reduceItems(start)), (0, _toConsumableArray2.default)(items), (0, _toConsumableArray2.default)(reduceItems(end)));
|
|
130
|
-
};
|
|
131
|
-
};
|
|
132
114
|
var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(options, pluginInjectionApi) {
|
|
133
115
|
return function (state, intl, providerFactory) {
|
|
134
|
-
var _pluginInjectionApi$a, _options$lpLinkPicker;
|
|
116
|
+
var _pluginInjectionApi$c, _pluginInjectionApi$a, _options$lpLinkPicker;
|
|
135
117
|
if (options.disableFloatingToolbar) {
|
|
136
118
|
return;
|
|
137
119
|
}
|
|
138
120
|
var formatMessage = intl.formatMessage;
|
|
139
121
|
var linkState = _main.stateKey.getState(state);
|
|
122
|
+
var editorCardActions = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.card) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions;
|
|
140
123
|
var editorAnalyticsApi = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
141
124
|
var lpLinkPicker = (_options$lpLinkPicker = options.lpLinkPicker) !== null && _options$lpLinkPicker !== void 0 ? _options$lpLinkPicker : true;
|
|
142
125
|
if (linkState && linkState.activeLinkMark) {
|
|
@@ -153,7 +136,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(opti
|
|
|
153
136
|
switch (activeLinkMark.type) {
|
|
154
137
|
case 'EDIT':
|
|
155
138
|
{
|
|
156
|
-
var
|
|
139
|
+
var _pluginInjectionApi$c2, _cardActions$getStart, _cardActions$getEndin;
|
|
157
140
|
var pos = activeLinkMark.pos,
|
|
158
141
|
node = activeLinkMark.node;
|
|
159
142
|
var linkMark = node.marks.filter(function (mark) {
|
|
@@ -172,7 +155,8 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(opti
|
|
|
172
155
|
if (activeLinkMark.node.text) {
|
|
173
156
|
metadata.title = activeLinkMark.node.text;
|
|
174
157
|
}
|
|
175
|
-
var
|
|
158
|
+
var cardActions = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.card) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.actions;
|
|
159
|
+
var startingToolbarItems = (_cardActions$getStart = cardActions === null || cardActions === void 0 ? void 0 : cardActions.getStartingToolbarItems(intl, link, providerFactory, (0, _commands.editInsertedLink)(editorAnalyticsApi), metadata)) !== null && _cardActions$getStart !== void 0 ? _cardActions$getStart : [{
|
|
176
160
|
id: 'editor.link.edit',
|
|
177
161
|
testId: 'editor.link.edit',
|
|
178
162
|
type: 'button',
|
|
@@ -180,7 +164,8 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(opti
|
|
|
180
164
|
title: editLink,
|
|
181
165
|
showTitle: true,
|
|
182
166
|
metadata: metadata
|
|
183
|
-
}
|
|
167
|
+
}];
|
|
168
|
+
var items = [].concat((0, _toConsumableArray2.default)(startingToolbarItems), [{
|
|
184
169
|
type: 'separator'
|
|
185
170
|
}, {
|
|
186
171
|
id: 'editor.link.openLink',
|
|
@@ -217,8 +202,7 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(opti
|
|
|
217
202
|
formatMessage: formatMessage,
|
|
218
203
|
markType: state.schema.marks.link
|
|
219
204
|
}]
|
|
220
|
-
}], (0, _toConsumableArray2.default)((0, _platformFeatureFlags.getBooleanFF)('platform.editor.card.inject-settings-button') ? [] : getSettingsButtonGroup(intl, editorAnalyticsApi)));
|
|
221
|
-
var items = (0, _platformFeatureFlags.getBooleanFF)('platform.editor.card.inject-settings-button') ? mergeAddedItems(link, state, intl, providerFactory)(baseItems, _toolbarButtons.toolbarKey.getState(state)) : baseItems;
|
|
205
|
+
}], (0, _toConsumableArray2.default)((_cardActions$getEndin = cardActions === null || cardActions === void 0 ? void 0 : cardActions.getEndingToolbarItems(intl, link)) !== null && _cardActions$getEndin !== void 0 ? _cardActions$getEndin : []), (0, _toConsumableArray2.default)((0, _platformFeatureFlags.getBooleanFF)('platform.editor.card.inject-settings-button') ? [] : getSettingsButtonGroup(intl, editorAnalyticsApi)));
|
|
222
206
|
return _objectSpread(_objectSpread({}, hyperLinkToolbar), {}, {
|
|
223
207
|
height: 32,
|
|
224
208
|
width: 250,
|
|
@@ -262,22 +246,22 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(opti
|
|
|
262
246
|
onCancel: function onCancel() {
|
|
263
247
|
return view.focus();
|
|
264
248
|
},
|
|
265
|
-
onEscapeCallback: _commands.onEscapeCallback,
|
|
249
|
+
onEscapeCallback: (0, _commands.onEscapeCallback)(editorCardActions),
|
|
266
250
|
onClickAwayCallback: _commands.onClickAwayCallback,
|
|
267
251
|
onSubmit: function onSubmit(href) {
|
|
268
|
-
var _toolbarKey$getState
|
|
252
|
+
var _toolbarKey$getState$, _toolbarKey$getState;
|
|
269
253
|
var title = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
270
254
|
var displayText = arguments.length > 2 ? arguments[2] : undefined;
|
|
271
255
|
var inputMethod = arguments.length > 3 ? arguments[3] : undefined;
|
|
272
256
|
var analytic = arguments.length > 4 ? arguments[4] : undefined;
|
|
273
257
|
var isEdit = isEditLink(activeLinkMark);
|
|
274
258
|
var action = isEdit ? _analytics.ACTION.UPDATED : _analytics.ACTION.INSERTED;
|
|
275
|
-
var skipAnalytics = (_toolbarKey$getState$
|
|
259
|
+
var skipAnalytics = (_toolbarKey$getState$ = (_toolbarKey$getState = _toolbarButtons.toolbarKey.getState(state)) === null || _toolbarKey$getState === void 0 ? void 0 : _toolbarKey$getState.skipAnalytics) !== null && _toolbarKey$getState$ !== void 0 ? _toolbarKey$getState$ : false;
|
|
276
260
|
var command = isEdit ? (0, _card.commandWithMetadata)((0, _commands.updateLink)(href, displayText || title, activeLinkMark.pos), {
|
|
277
261
|
action: action,
|
|
278
262
|
inputMethod: inputMethod,
|
|
279
263
|
sourceEvent: analytic
|
|
280
|
-
}) : (0, _commands.insertLinkWithAnalytics)(inputMethod, activeLinkMark.from, activeLinkMark.to, href, editorAnalyticsApi, title, displayText, skipAnalytics, analytic);
|
|
264
|
+
}) : (0, _commands.insertLinkWithAnalytics)(inputMethod, activeLinkMark.from, activeLinkMark.to, href, editorCardActions, editorAnalyticsApi, title, displayText, skipAnalytics, analytic);
|
|
281
265
|
command(view.state, view.dispatch, view);
|
|
282
266
|
view.focus();
|
|
283
267
|
}
|
package/dist/cjs/commands.js
CHANGED
|
@@ -21,7 +21,6 @@ var _link = require("@atlaskit/editor-common/link");
|
|
|
21
21
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
22
22
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
23
23
|
var _main = require("./pm-plugins/main");
|
|
24
|
-
var _toolbarButtons = require("./pm-plugins/toolbar-buttons");
|
|
25
24
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
26
25
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { (0, _defineProperty2.default)(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
27
26
|
function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
@@ -90,6 +89,7 @@ function updateLink(href, text, pos, to) {
|
|
|
90
89
|
}
|
|
91
90
|
function insertLink(from, to, incomingHref, incomingTitle, displayText, source, sourceEvent) {
|
|
92
91
|
var appearance = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 'inline';
|
|
92
|
+
var cardApiActions = arguments.length > 8 ? arguments[8] : undefined;
|
|
93
93
|
return function (state, dispatch) {
|
|
94
94
|
var link = state.schema.marks.link;
|
|
95
95
|
var tr = state.tr;
|
|
@@ -114,8 +114,7 @@ function insertLink(from, to, incomingHref, incomingTitle, displayText, source,
|
|
|
114
114
|
}));
|
|
115
115
|
tr.setSelection(_state.Selection.near(tr.doc.resolve(markEnd)));
|
|
116
116
|
if (!displayText || displayText === incomingHref) {
|
|
117
|
-
var
|
|
118
|
-
var queueCardsFromChangedTr = (_toolbarKey$getState = _toolbarButtons.toolbarKey.getState(state)) === null || _toolbarKey$getState === void 0 ? void 0 : _toolbarKey$getState.onInsertLinkCallback;
|
|
117
|
+
var queueCardsFromChangedTr = cardApiActions === null || cardApiActions === void 0 ? void 0 : cardApiActions.queueCardsFromChangedTr;
|
|
119
118
|
if (queueCardsFromChangedTr) {
|
|
120
119
|
queueCardsFromChangedTr === null || queueCardsFromChangedTr === void 0 || queueCardsFromChangedTr(state, tr, source, _analytics.ACTION.INSERTED, false, sourceEvent, appearance);
|
|
121
120
|
} else {
|
|
@@ -152,15 +151,15 @@ function insertLink(from, to, incomingHref, incomingTitle, displayText, source,
|
|
|
152
151
|
return false;
|
|
153
152
|
};
|
|
154
153
|
}
|
|
155
|
-
var insertLinkWithAnalytics = exports.insertLinkWithAnalytics = function insertLinkWithAnalytics(inputMethod, from, to, href, editorAnalyticsApi, title, displayText) {
|
|
156
|
-
var cardsAvailable = arguments.length >
|
|
157
|
-
var sourceEvent = arguments.length >
|
|
158
|
-
var appearance = arguments.length >
|
|
154
|
+
var insertLinkWithAnalytics = exports.insertLinkWithAnalytics = function insertLinkWithAnalytics(inputMethod, from, to, href, cardActions, editorAnalyticsApi, title, displayText) {
|
|
155
|
+
var cardsAvailable = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
|
|
156
|
+
var sourceEvent = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : undefined;
|
|
157
|
+
var appearance = arguments.length > 10 ? arguments[10] : undefined;
|
|
159
158
|
// If smart cards are available, we send analytics for hyperlinks when a smart link is rejected.
|
|
160
159
|
if (cardsAvailable && !title && !displayText) {
|
|
161
|
-
return insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance);
|
|
160
|
+
return insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance, cardActions);
|
|
162
161
|
}
|
|
163
|
-
return (0, _editorAnalytics.withAnalytics)(editorAnalyticsApi, (0, _utils.getLinkCreationAnalyticsEvent)(inputMethod, href))(insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance));
|
|
162
|
+
return (0, _editorAnalytics.withAnalytics)(editorAnalyticsApi, (0, _utils.getLinkCreationAnalyticsEvent)(inputMethod, href))(insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance, cardActions));
|
|
164
163
|
};
|
|
165
164
|
function removeLink(pos, editorAnalyticsApi) {
|
|
166
165
|
return (0, _card.commandWithMetadata)(setLinkHref('', pos, editorAnalyticsApi), {
|
|
@@ -213,16 +212,18 @@ var hideLinkToolbarSetMeta = exports.hideLinkToolbarSetMeta = function hideLinkT
|
|
|
213
212
|
type: _link.LinkAction.HIDE_TOOLBAR
|
|
214
213
|
});
|
|
215
214
|
};
|
|
216
|
-
var onEscapeCallback = exports.onEscapeCallback = function onEscapeCallback(
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
dispatch
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
215
|
+
var onEscapeCallback = exports.onEscapeCallback = function onEscapeCallback(cardActions) {
|
|
216
|
+
return function (state, dispatch) {
|
|
217
|
+
var _cardActions$hideLink;
|
|
218
|
+
var tr = state.tr;
|
|
219
|
+
hideLinkToolbarSetMeta(tr);
|
|
220
|
+
cardActions === null || cardActions === void 0 || (_cardActions$hideLink = cardActions.hideLinkToolbar) === null || _cardActions$hideLink === void 0 || _cardActions$hideLink.call(cardActions, tr);
|
|
221
|
+
if (dispatch) {
|
|
222
|
+
dispatch(tr);
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
return false;
|
|
226
|
+
};
|
|
226
227
|
};
|
|
227
228
|
var onClickAwayCallback = exports.onClickAwayCallback = function onClickAwayCallback(state, dispatch) {
|
|
228
229
|
if (dispatch) {
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -43,15 +43,13 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
actions: {
|
|
46
|
-
prependToolbarButtons: _toolbarButtons.prependToolbarButtons,
|
|
47
|
-
addToolbarItems: _toolbarButtons.addToolbarItems,
|
|
48
46
|
hideLinkToolbar: _commands.hideLinkToolbarSetMeta,
|
|
49
47
|
insertLink: function insertLink(inputMethod, from, to, href, title, displayText) {
|
|
50
|
-
var _api$analytics2;
|
|
48
|
+
var _api$card, _api$analytics2;
|
|
51
49
|
var cardsAvailable = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
52
50
|
var sourceEvent = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : undefined;
|
|
53
51
|
var appearance = arguments.length > 8 ? arguments[8] : undefined;
|
|
54
|
-
return (0, _commands.insertLinkWithAnalytics)(inputMethod, from, to, href, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
|
|
52
|
+
return (0, _commands.insertLinkWithAnalytics)(inputMethod, from, to, href, api === null || api === void 0 || (_api$card = api.card) === null || _api$card === void 0 ? void 0 : _api$card.actions, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
|
|
55
53
|
},
|
|
56
54
|
updateLink: _commands.updateLink
|
|
57
55
|
},
|
|
@@ -88,7 +86,13 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
88
86
|
}
|
|
89
87
|
}, {
|
|
90
88
|
name: 'hyperlinkToolbarButtons',
|
|
91
|
-
plugin:
|
|
89
|
+
plugin: function plugin() {
|
|
90
|
+
var _api$card2;
|
|
91
|
+
var hasCard = !!(api !== null && api !== void 0 && (_api$card2 = api.card) !== null && _api$card2 !== void 0 && _api$card2.actions);
|
|
92
|
+
return (0, _toolbarButtons.toolbarButtonsPlugin)(hasCard ? {
|
|
93
|
+
skipAnalytics: true
|
|
94
|
+
} : undefined);
|
|
95
|
+
}
|
|
92
96
|
}];
|
|
93
97
|
},
|
|
94
98
|
pluginsOptions: {
|
|
@@ -1,85 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
|
-
exports.toolbarKey = exports.toolbarButtonsPlugin =
|
|
8
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
9
|
-
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
10
|
-
var _typeof2 = _interopRequireDefault(require("@babel/runtime/helpers/typeof"));
|
|
6
|
+
exports.toolbarKey = exports.toolbarButtonsPlugin = void 0;
|
|
11
7
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
12
8
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
13
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
14
|
-
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; }
|
|
15
|
-
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; }
|
|
16
|
-
/**
|
|
17
|
-
* Relative placement of an item
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
9
|
var toolbarKey = exports.toolbarKey = new _state.PluginKey('hyperlinkToolbarItems');
|
|
21
|
-
var
|
|
22
|
-
var items = _ref.items,
|
|
23
|
-
onEscapeCallback = _ref.onEscapeCallback,
|
|
24
|
-
onInsertLinkCallback = _ref.onInsertLinkCallback,
|
|
25
|
-
skipAnalytics = _ref.skipAnalytics,
|
|
26
|
-
view = _ref.view;
|
|
27
|
-
var tr = view.state.tr,
|
|
28
|
-
dispatch = view.dispatch;
|
|
29
|
-
tr.setMeta(toolbarKey, {
|
|
30
|
-
items: items,
|
|
31
|
-
onEscapeCallback: onEscapeCallback,
|
|
32
|
-
onInsertLinkCallback: onInsertLinkCallback,
|
|
33
|
-
skipAnalytics: skipAnalytics
|
|
34
|
-
});
|
|
35
|
-
dispatch(tr);
|
|
36
|
-
};
|
|
37
|
-
var addToolbarItems = exports.addToolbarItems = function addToolbarItems(_ref2) {
|
|
38
|
-
var items = _ref2.items,
|
|
39
|
-
placement = _ref2.placement,
|
|
40
|
-
view = _ref2.view;
|
|
41
|
-
var tr = view.state.tr,
|
|
42
|
-
dispatch = view.dispatch;
|
|
43
|
-
tr.setMeta(toolbarKey, {
|
|
44
|
-
items: items,
|
|
45
|
-
placement: placement
|
|
46
|
-
});
|
|
47
|
-
dispatch(tr);
|
|
48
|
-
};
|
|
49
|
-
var VALID_PLACEMENTS = ['start', 'end'];
|
|
50
|
-
var isValidPlacement = function isValidPlacement(placement) {
|
|
51
|
-
return VALID_PLACEMENTS.some(function (p) {
|
|
52
|
-
return p === placement;
|
|
53
|
-
});
|
|
54
|
-
};
|
|
55
|
-
var toolbarButtonsPlugin = exports.toolbarButtonsPlugin = function toolbarButtonsPlugin() {
|
|
10
|
+
var toolbarButtonsPlugin = exports.toolbarButtonsPlugin = function toolbarButtonsPlugin(initialState) {
|
|
56
11
|
return new _safePlugin.SafePlugin({
|
|
57
12
|
key: toolbarKey,
|
|
58
13
|
state: {
|
|
59
14
|
init: function init(_, __) {
|
|
60
|
-
return
|
|
15
|
+
return initialState;
|
|
61
16
|
},
|
|
62
|
-
apply:
|
|
63
|
-
var metaState = tr.getMeta(toolbarKey);
|
|
64
|
-
if (metaState) {
|
|
65
|
-
if ((0, _typeof2.default)(metaState) === 'object' && 'placement' in metaState) {
|
|
66
|
-
var _pluginState$items_ne;
|
|
67
|
-
var placement = metaState.placement;
|
|
68
|
-
if (!isValidPlacement(placement)) {
|
|
69
|
-
return pluginState;
|
|
70
|
-
}
|
|
71
|
-
var previous = (_pluginState$items_ne = pluginState === null || pluginState === void 0 ? void 0 : pluginState.items_next) !== null && _pluginState$items_ne !== void 0 ? _pluginState$items_ne : {
|
|
72
|
-
start: [],
|
|
73
|
-
end: []
|
|
74
|
-
};
|
|
75
|
-
return _objectSpread(_objectSpread({}, pluginState), {}, {
|
|
76
|
-
items_next: _objectSpread(_objectSpread({}, previous), {}, (0, _defineProperty2.default)({}, placement, [].concat((0, _toConsumableArray2.default)(previous[placement]), [metaState.items])))
|
|
77
|
-
});
|
|
78
|
-
}
|
|
79
|
-
return metaState;
|
|
80
|
-
}
|
|
81
|
-
return pluginState;
|
|
82
|
-
} : function (tr, pluginState) {
|
|
17
|
+
apply: function apply(tr, pluginState) {
|
|
83
18
|
var metaState = tr.getMeta(toolbarKey);
|
|
84
19
|
if (metaState) {
|
|
85
20
|
return metaState;
|
package/dist/es2019/Toolbar.js
CHANGED
|
@@ -78,7 +78,9 @@ export function HyperlinkAddToolbarWithState({
|
|
|
78
78
|
onClose: onClose,
|
|
79
79
|
onEscapeCallback: onEscapeCallback,
|
|
80
80
|
onClickAwayCallback: onClickAwayCallback,
|
|
81
|
-
|
|
81
|
+
timesViewed: hyperlinkState.timesViewed,
|
|
82
|
+
inputMethod: hyperlinkState.inputMethod,
|
|
83
|
+
searchSessionId: hyperlinkState.searchSessionId
|
|
82
84
|
});
|
|
83
85
|
}
|
|
84
86
|
const getSettingsButtonGroup = (intl, editorAnalyticsApi) => [{
|
|
@@ -92,18 +94,8 @@ const getSettingsButtonGroup = (intl, editorAnalyticsApi) => [{
|
|
|
92
94
|
href: getLinkPreferencesURLFromENV(),
|
|
93
95
|
target: '_blank'
|
|
94
96
|
}];
|
|
95
|
-
export const mergeAddedItems = (link, ...handlerParams) => (items, toolbarItemsState) => {
|
|
96
|
-
const positions = toolbarItemsState === null || toolbarItemsState === void 0 ? void 0 : toolbarItemsState.items_next;
|
|
97
|
-
if (!positions) {
|
|
98
|
-
return items;
|
|
99
|
-
}
|
|
100
|
-
const start = positions.start;
|
|
101
|
-
const end = positions.end;
|
|
102
|
-
const reduceItems = (items = []) => items.reduce((acc, fn) => [...acc, ...fn(...handlerParams, link)], []);
|
|
103
|
-
return [...reduceItems(start), ...items, ...reduceItems(end)];
|
|
104
|
-
};
|
|
105
97
|
export const getToolbarConfig = (options, pluginInjectionApi) => (state, intl, providerFactory) => {
|
|
106
|
-
var _pluginInjectionApi$a, _options$lpLinkPicker;
|
|
98
|
+
var _pluginInjectionApi$c, _pluginInjectionApi$a, _options$lpLinkPicker;
|
|
107
99
|
if (options.disableFloatingToolbar) {
|
|
108
100
|
return;
|
|
109
101
|
}
|
|
@@ -111,6 +103,7 @@ export const getToolbarConfig = (options, pluginInjectionApi) => (state, intl, p
|
|
|
111
103
|
formatMessage
|
|
112
104
|
} = intl;
|
|
113
105
|
const linkState = stateKey.getState(state);
|
|
106
|
+
const editorCardActions = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c = pluginInjectionApi.card) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions;
|
|
114
107
|
const editorAnalyticsApi = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
|
|
115
108
|
const lpLinkPicker = (_options$lpLinkPicker = options.lpLinkPicker) !== null && _options$lpLinkPicker !== void 0 ? _options$lpLinkPicker : true;
|
|
116
109
|
if (linkState && linkState.activeLinkMark) {
|
|
@@ -127,7 +120,7 @@ export const getToolbarConfig = (options, pluginInjectionApi) => (state, intl, p
|
|
|
127
120
|
switch (activeLinkMark.type) {
|
|
128
121
|
case 'EDIT':
|
|
129
122
|
{
|
|
130
|
-
var
|
|
123
|
+
var _pluginInjectionApi$c2, _cardActions$getStart, _cardActions$getEndin;
|
|
131
124
|
const {
|
|
132
125
|
pos,
|
|
133
126
|
node
|
|
@@ -146,7 +139,8 @@ export const getToolbarConfig = (options, pluginInjectionApi) => (state, intl, p
|
|
|
146
139
|
if (activeLinkMark.node.text) {
|
|
147
140
|
metadata.title = activeLinkMark.node.text;
|
|
148
141
|
}
|
|
149
|
-
const
|
|
142
|
+
const cardActions = pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$c2 = pluginInjectionApi.card) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.actions;
|
|
143
|
+
const startingToolbarItems = (_cardActions$getStart = cardActions === null || cardActions === void 0 ? void 0 : cardActions.getStartingToolbarItems(intl, link, providerFactory, editInsertedLink(editorAnalyticsApi), metadata)) !== null && _cardActions$getStart !== void 0 ? _cardActions$getStart : [{
|
|
150
144
|
id: 'editor.link.edit',
|
|
151
145
|
testId: 'editor.link.edit',
|
|
152
146
|
type: 'button',
|
|
@@ -154,7 +148,8 @@ export const getToolbarConfig = (options, pluginInjectionApi) => (state, intl, p
|
|
|
154
148
|
title: editLink,
|
|
155
149
|
showTitle: true,
|
|
156
150
|
metadata: metadata
|
|
157
|
-
}
|
|
151
|
+
}];
|
|
152
|
+
const items = [...startingToolbarItems, {
|
|
158
153
|
type: 'separator'
|
|
159
154
|
}, {
|
|
160
155
|
id: 'editor.link.openLink',
|
|
@@ -191,8 +186,7 @@ export const getToolbarConfig = (options, pluginInjectionApi) => (state, intl, p
|
|
|
191
186
|
formatMessage: formatMessage,
|
|
192
187
|
markType: state.schema.marks.link
|
|
193
188
|
}]
|
|
194
|
-
}, ...(getBooleanFF('platform.editor.card.inject-settings-button') ? [] : getSettingsButtonGroup(intl, editorAnalyticsApi))];
|
|
195
|
-
const items = getBooleanFF('platform.editor.card.inject-settings-button') ? mergeAddedItems(link, state, intl, providerFactory)(baseItems, toolbarKey.getState(state)) : baseItems;
|
|
189
|
+
}, ...((_cardActions$getEndin = cardActions === null || cardActions === void 0 ? void 0 : cardActions.getEndingToolbarItems(intl, link)) !== null && _cardActions$getEndin !== void 0 ? _cardActions$getEndin : []), ...(getBooleanFF('platform.editor.card.inject-settings-button') ? [] : getSettingsButtonGroup(intl, editorAnalyticsApi))];
|
|
196
190
|
return {
|
|
197
191
|
...hyperLinkToolbar,
|
|
198
192
|
height: 32,
|
|
@@ -234,18 +228,18 @@ export const getToolbarConfig = (options, pluginInjectionApi) => (state, intl, p
|
|
|
234
228
|
displayText: displayText || '',
|
|
235
229
|
providerFactory: providerFactory,
|
|
236
230
|
onCancel: () => view.focus(),
|
|
237
|
-
onEscapeCallback: onEscapeCallback,
|
|
231
|
+
onEscapeCallback: onEscapeCallback(editorCardActions),
|
|
238
232
|
onClickAwayCallback: onClickAwayCallback,
|
|
239
233
|
onSubmit: (href, title = '', displayText, inputMethod, analytic) => {
|
|
240
|
-
var _toolbarKey$getState
|
|
234
|
+
var _toolbarKey$getState$, _toolbarKey$getState;
|
|
241
235
|
const isEdit = isEditLink(activeLinkMark);
|
|
242
236
|
const action = isEdit ? ACTION.UPDATED : ACTION.INSERTED;
|
|
243
|
-
const skipAnalytics = (_toolbarKey$getState$
|
|
237
|
+
const skipAnalytics = (_toolbarKey$getState$ = (_toolbarKey$getState = toolbarKey.getState(state)) === null || _toolbarKey$getState === void 0 ? void 0 : _toolbarKey$getState.skipAnalytics) !== null && _toolbarKey$getState$ !== void 0 ? _toolbarKey$getState$ : false;
|
|
244
238
|
const command = isEdit ? commandWithMetadata(updateLink(href, displayText || title, activeLinkMark.pos), {
|
|
245
239
|
action,
|
|
246
240
|
inputMethod,
|
|
247
241
|
sourceEvent: analytic
|
|
248
|
-
}) : insertLinkWithAnalytics(inputMethod, activeLinkMark.from, activeLinkMark.to, href, editorAnalyticsApi, title, displayText, skipAnalytics, analytic);
|
|
242
|
+
}) : insertLinkWithAnalytics(inputMethod, activeLinkMark.from, activeLinkMark.to, href, editorCardActions, editorAnalyticsApi, title, displayText, skipAnalytics, analytic);
|
|
249
243
|
command(view.state, view.dispatch, view);
|
|
250
244
|
view.focus();
|
|
251
245
|
}
|
package/dist/es2019/commands.js
CHANGED
|
@@ -5,7 +5,6 @@ import { isTextAtPos, LinkAction } from '@atlaskit/editor-common/link';
|
|
|
5
5
|
import { filterCommand as filter, getLinkCreationAnalyticsEvent, normalizeUrl } from '@atlaskit/editor-common/utils';
|
|
6
6
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
7
7
|
import { stateKey } from './pm-plugins/main';
|
|
8
|
-
import { toolbarKey } from './pm-plugins/toolbar-buttons';
|
|
9
8
|
export function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
10
9
|
return filter(isTextAtPos(pos), (state, dispatch) => {
|
|
11
10
|
const $pos = state.doc.resolve(pos);
|
|
@@ -72,7 +71,7 @@ export function updateLink(href, text, pos, to) {
|
|
|
72
71
|
return true;
|
|
73
72
|
};
|
|
74
73
|
}
|
|
75
|
-
export function insertLink(from, to, incomingHref, incomingTitle, displayText, source, sourceEvent, appearance = 'inline') {
|
|
74
|
+
export function insertLink(from, to, incomingHref, incomingTitle, displayText, source, sourceEvent, appearance = 'inline', cardApiActions) {
|
|
76
75
|
return (state, dispatch) => {
|
|
77
76
|
const link = state.schema.marks.link;
|
|
78
77
|
const {
|
|
@@ -99,8 +98,7 @@ export function insertLink(from, to, incomingHref, incomingTitle, displayText, s
|
|
|
99
98
|
}));
|
|
100
99
|
tr.setSelection(Selection.near(tr.doc.resolve(markEnd)));
|
|
101
100
|
if (!displayText || displayText === incomingHref) {
|
|
102
|
-
|
|
103
|
-
const queueCardsFromChangedTr = (_toolbarKey$getState = toolbarKey.getState(state)) === null || _toolbarKey$getState === void 0 ? void 0 : _toolbarKey$getState.onInsertLinkCallback;
|
|
101
|
+
const queueCardsFromChangedTr = cardApiActions === null || cardApiActions === void 0 ? void 0 : cardApiActions.queueCardsFromChangedTr;
|
|
104
102
|
if (queueCardsFromChangedTr) {
|
|
105
103
|
queueCardsFromChangedTr === null || queueCardsFromChangedTr === void 0 ? void 0 : queueCardsFromChangedTr(state, tr, source, ACTION.INSERTED, false, sourceEvent, appearance);
|
|
106
104
|
} else {
|
|
@@ -137,12 +135,12 @@ export function insertLink(from, to, incomingHref, incomingTitle, displayText, s
|
|
|
137
135
|
return false;
|
|
138
136
|
};
|
|
139
137
|
}
|
|
140
|
-
export const insertLinkWithAnalytics = (inputMethod, from, to, href, editorAnalyticsApi, title, displayText, cardsAvailable = false, sourceEvent = undefined, appearance) => {
|
|
138
|
+
export const insertLinkWithAnalytics = (inputMethod, from, to, href, cardActions, editorAnalyticsApi, title, displayText, cardsAvailable = false, sourceEvent = undefined, appearance) => {
|
|
141
139
|
// If smart cards are available, we send analytics for hyperlinks when a smart link is rejected.
|
|
142
140
|
if (cardsAvailable && !title && !displayText) {
|
|
143
|
-
return insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance);
|
|
141
|
+
return insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance, cardActions);
|
|
144
142
|
}
|
|
145
|
-
return withAnalytics(editorAnalyticsApi, getLinkCreationAnalyticsEvent(inputMethod, href))(insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance));
|
|
143
|
+
return withAnalytics(editorAnalyticsApi, getLinkCreationAnalyticsEvent(inputMethod, href))(insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance, cardActions));
|
|
146
144
|
};
|
|
147
145
|
export function removeLink(pos, editorAnalyticsApi) {
|
|
148
146
|
return commandWithMetadata(setLinkHref('', pos, editorAnalyticsApi), {
|
|
@@ -198,13 +196,13 @@ export const hideLinkToolbarSetMeta = tr => {
|
|
|
198
196
|
type: LinkAction.HIDE_TOOLBAR
|
|
199
197
|
});
|
|
200
198
|
};
|
|
201
|
-
export const onEscapeCallback = (state, dispatch) => {
|
|
202
|
-
var
|
|
199
|
+
export const onEscapeCallback = cardActions => (state, dispatch) => {
|
|
200
|
+
var _cardActions$hideLink;
|
|
203
201
|
const {
|
|
204
202
|
tr
|
|
205
203
|
} = state;
|
|
206
204
|
hideLinkToolbarSetMeta(tr);
|
|
207
|
-
|
|
205
|
+
cardActions === null || cardActions === void 0 ? void 0 : (_cardActions$hideLink = cardActions.hideLinkToolbar) === null || _cardActions$hideLink === void 0 ? void 0 : _cardActions$hideLink.call(cardActions, tr);
|
|
208
206
|
if (dispatch) {
|
|
209
207
|
dispatch(tr);
|
|
210
208
|
return true;
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -10,7 +10,7 @@ import fakeCursorToolbarPlugin from './pm-plugins/fake-cursor-for-toolbar';
|
|
|
10
10
|
import { createInputRulePlugin } from './pm-plugins/input-rule';
|
|
11
11
|
import { createKeymapPlugin } from './pm-plugins/keymap';
|
|
12
12
|
import { plugin, stateKey } from './pm-plugins/main';
|
|
13
|
-
import {
|
|
13
|
+
import { toolbarButtonsPlugin } from './pm-plugins/toolbar-buttons';
|
|
14
14
|
import { getToolbarConfig } from './Toolbar';
|
|
15
15
|
/**
|
|
16
16
|
* Hyperlink plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
|
|
@@ -35,12 +35,10 @@ export const hyperlinkPlugin = ({
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
actions: {
|
|
38
|
-
prependToolbarButtons,
|
|
39
|
-
addToolbarItems,
|
|
40
38
|
hideLinkToolbar: hideLinkToolbarSetMeta,
|
|
41
39
|
insertLink: (inputMethod, from, to, href, title, displayText, cardsAvailable = false, sourceEvent = undefined, appearance) => {
|
|
42
|
-
var _api$analytics2;
|
|
43
|
-
return insertLinkWithAnalytics(inputMethod, from, to, href, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
|
|
40
|
+
var _api$card, _api$analytics2;
|
|
41
|
+
return insertLinkWithAnalytics(inputMethod, from, to, href, api === null || api === void 0 ? void 0 : (_api$card = api.card) === null || _api$card === void 0 ? void 0 : _api$card.actions, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
|
|
44
42
|
},
|
|
45
43
|
updateLink: updateLink
|
|
46
44
|
},
|
|
@@ -75,7 +73,13 @@ export const hyperlinkPlugin = ({
|
|
|
75
73
|
}
|
|
76
74
|
}, {
|
|
77
75
|
name: 'hyperlinkToolbarButtons',
|
|
78
|
-
plugin:
|
|
76
|
+
plugin: () => {
|
|
77
|
+
var _api$card2;
|
|
78
|
+
const hasCard = !!(api !== null && api !== void 0 && (_api$card2 = api.card) !== null && _api$card2 !== void 0 && _api$card2.actions);
|
|
79
|
+
return toolbarButtonsPlugin(hasCard ? {
|
|
80
|
+
skipAnalytics: true
|
|
81
|
+
} : undefined);
|
|
82
|
+
}
|
|
79
83
|
}];
|
|
80
84
|
},
|
|
81
85
|
pluginsOptions: {
|
|
@@ -1,86 +1,14 @@
|
|
|
1
1
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
2
2
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
3
|
-
import { getBooleanFF } from '@atlaskit/platform-feature-flags';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Relative placement of an item
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
3
|
export const toolbarKey = new PluginKey('hyperlinkToolbarItems');
|
|
10
|
-
export const
|
|
11
|
-
items,
|
|
12
|
-
onEscapeCallback,
|
|
13
|
-
onInsertLinkCallback,
|
|
14
|
-
skipAnalytics,
|
|
15
|
-
view
|
|
16
|
-
}) => {
|
|
17
|
-
const {
|
|
18
|
-
state: {
|
|
19
|
-
tr
|
|
20
|
-
},
|
|
21
|
-
dispatch
|
|
22
|
-
} = view;
|
|
23
|
-
tr.setMeta(toolbarKey, {
|
|
24
|
-
items,
|
|
25
|
-
onEscapeCallback,
|
|
26
|
-
onInsertLinkCallback,
|
|
27
|
-
skipAnalytics
|
|
28
|
-
});
|
|
29
|
-
dispatch(tr);
|
|
30
|
-
};
|
|
31
|
-
export const addToolbarItems = ({
|
|
32
|
-
items,
|
|
33
|
-
placement,
|
|
34
|
-
view
|
|
35
|
-
}) => {
|
|
36
|
-
const {
|
|
37
|
-
state: {
|
|
38
|
-
tr
|
|
39
|
-
},
|
|
40
|
-
dispatch
|
|
41
|
-
} = view;
|
|
42
|
-
tr.setMeta(toolbarKey, {
|
|
43
|
-
items,
|
|
44
|
-
placement
|
|
45
|
-
});
|
|
46
|
-
dispatch(tr);
|
|
47
|
-
};
|
|
48
|
-
const VALID_PLACEMENTS = ['start', 'end'];
|
|
49
|
-
const isValidPlacement = placement => {
|
|
50
|
-
return VALID_PLACEMENTS.some(p => p === placement);
|
|
51
|
-
};
|
|
52
|
-
export const toolbarButtonsPlugin = () => {
|
|
4
|
+
export const toolbarButtonsPlugin = initialState => {
|
|
53
5
|
return new SafePlugin({
|
|
54
6
|
key: toolbarKey,
|
|
55
7
|
state: {
|
|
56
8
|
init: (_, __) => {
|
|
57
|
-
return
|
|
9
|
+
return initialState;
|
|
58
10
|
},
|
|
59
|
-
apply:
|
|
60
|
-
const metaState = tr.getMeta(toolbarKey);
|
|
61
|
-
if (metaState) {
|
|
62
|
-
if (typeof metaState === 'object' && 'placement' in metaState) {
|
|
63
|
-
var _pluginState$items_ne;
|
|
64
|
-
const placement = metaState.placement;
|
|
65
|
-
if (!isValidPlacement(placement)) {
|
|
66
|
-
return pluginState;
|
|
67
|
-
}
|
|
68
|
-
const previous = (_pluginState$items_ne = pluginState === null || pluginState === void 0 ? void 0 : pluginState.items_next) !== null && _pluginState$items_ne !== void 0 ? _pluginState$items_ne : {
|
|
69
|
-
start: [],
|
|
70
|
-
end: []
|
|
71
|
-
};
|
|
72
|
-
return {
|
|
73
|
-
...pluginState,
|
|
74
|
-
items_next: {
|
|
75
|
-
...previous,
|
|
76
|
-
[placement]: [...previous[placement], metaState.items]
|
|
77
|
-
}
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
return metaState;
|
|
81
|
-
}
|
|
82
|
-
return pluginState;
|
|
83
|
-
} : (tr, pluginState) => {
|
|
11
|
+
apply: (tr, pluginState) => {
|
|
84
12
|
const metaState = tr.getMeta(toolbarKey);
|
|
85
13
|
if (metaState) {
|
|
86
14
|
return metaState;
|