@atlaskit/editor-plugin-hyperlink 2.3.23 → 2.4.1
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 +18 -0
- package/dist/cjs/commands.js +48 -27
- package/dist/cjs/plugin.js +47 -9
- package/dist/cjs/pm-plugins/main.js +38 -34
- package/dist/es2019/commands.js +48 -26
- package/dist/es2019/plugin.js +43 -10
- package/dist/es2019/pm-plugins/main.js +41 -37
- package/dist/esm/commands.js +47 -28
- package/dist/esm/plugin.js +48 -10
- package/dist/esm/pm-plugins/main.js +38 -34
- package/dist/types/commands.d.ts +2 -0
- package/dist/types/plugin.d.ts +31 -2
- package/dist/types/pm-plugins/main.d.ts +3 -2
- package/dist/types-ts4.5/commands.d.ts +2 -0
- package/dist/types-ts4.5/plugin.d.ts +28 -2
- package/dist/types-ts4.5/pm-plugins/main.d.ts +3 -2
- package/package.json +4 -3
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-hyperlink
|
|
2
2
|
|
|
3
|
+
## 2.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#122063](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/122063)
|
|
8
|
+
[`c136e556d086d`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/c136e556d086d) -
|
|
9
|
+
[ux] Apply live page and check for live view in card and hyperlink plugin
|
|
10
|
+
- Updated dependencies
|
|
11
|
+
|
|
12
|
+
## 2.4.0
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- [#121941](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/121941)
|
|
17
|
+
[`9db19df977817`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9db19df977817) -
|
|
18
|
+
Added new commands for hyperlink plugin: removeLink and updateLink. These can be used on an active
|
|
19
|
+
link to remove the hyperlink mark or update the text/href on the link.
|
|
20
|
+
|
|
3
21
|
## 2.3.23
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/cjs/commands.js
CHANGED
|
@@ -10,31 +10,40 @@ exports.hideLinkToolbarSetMeta = void 0;
|
|
|
10
10
|
exports.insertLink = insertLink;
|
|
11
11
|
exports.onEscapeCallback = exports.onClickAwayCallback = exports.insertLinkWithAnalytics = void 0;
|
|
12
12
|
exports.removeLink = removeLink;
|
|
13
|
+
exports.removeLinkEditorCommand = removeLinkEditorCommand;
|
|
13
14
|
exports.setLinkHref = setLinkHref;
|
|
14
15
|
exports.showLinkToolbar = showLinkToolbar;
|
|
15
16
|
exports.updateLink = updateLink;
|
|
17
|
+
exports.updateLinkEditorCommand = updateLinkEditorCommand;
|
|
16
18
|
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
17
19
|
var _analytics = require("@atlaskit/editor-common/analytics");
|
|
18
20
|
var _card = require("@atlaskit/editor-common/card");
|
|
19
21
|
var _editorAnalytics = require("@atlaskit/editor-common/editor-analytics");
|
|
20
22
|
var _link = require("@atlaskit/editor-common/link");
|
|
23
|
+
var _preset = require("@atlaskit/editor-common/preset");
|
|
21
24
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
22
25
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
23
26
|
var _main = require("./pm-plugins/main");
|
|
24
27
|
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; }
|
|
25
28
|
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; }
|
|
26
|
-
function
|
|
27
|
-
return
|
|
28
|
-
var
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
function setLinkHrefEditorCommand(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
30
|
+
return function (_ref) {
|
|
31
|
+
var tr = _ref.tr;
|
|
32
|
+
if (!(0, _link.isTextAtPos)(pos)({
|
|
33
|
+
tr: tr
|
|
34
|
+
})) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
var $pos = tr.doc.resolve(pos);
|
|
38
|
+
var node = tr.doc.nodeAt(pos);
|
|
39
|
+
var linkMark = tr.doc.type.schema.marks.link;
|
|
31
40
|
var mark = linkMark.isInSet(node.marks);
|
|
32
41
|
var url = (0, _utils.normalizeUrl)(href);
|
|
33
42
|
if (mark && mark.attrs.href === url) {
|
|
34
|
-
return
|
|
43
|
+
return null;
|
|
35
44
|
}
|
|
36
45
|
var rightBound = to && pos !== to ? to : pos - $pos.textOffset + node.nodeSize;
|
|
37
|
-
|
|
46
|
+
tr.removeMark(pos, rightBound, linkMark);
|
|
38
47
|
if (href.trim()) {
|
|
39
48
|
tr.addMark(pos, rightBound, linkMark.create(_objectSpread(_objectSpread({}, mark && mark.attrs || {}), {}, {
|
|
40
49
|
href: url
|
|
@@ -47,29 +56,29 @@ function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
|
47
56
|
type: _link.LinkAction.HIDE_TOOLBAR
|
|
48
57
|
});
|
|
49
58
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
}
|
|
53
|
-
return true;
|
|
54
|
-
});
|
|
59
|
+
return tr;
|
|
60
|
+
};
|
|
55
61
|
}
|
|
56
|
-
function
|
|
57
|
-
return
|
|
58
|
-
|
|
59
|
-
|
|
62
|
+
function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
63
|
+
return (0, _preset.editorCommandToPMCommand)(setLinkHrefEditorCommand(href, pos, editorAnalyticsApi, to, isTabPressed));
|
|
64
|
+
}
|
|
65
|
+
function updateLinkEditorCommand(href, text, pos, to) {
|
|
66
|
+
return function (_ref2) {
|
|
67
|
+
var tr = _ref2.tr;
|
|
68
|
+
var $pos = tr.doc.resolve(pos);
|
|
69
|
+
var node = tr.doc.nodeAt(pos);
|
|
60
70
|
if (!node) {
|
|
61
|
-
return
|
|
71
|
+
return null;
|
|
62
72
|
}
|
|
63
73
|
var url = (0, _utils.normalizeUrl)(href);
|
|
64
|
-
var mark =
|
|
65
|
-
var linkMark =
|
|
74
|
+
var mark = tr.doc.type.schema.marks.link.isInSet(node.marks);
|
|
75
|
+
var linkMark = tr.doc.type.schema.marks.link;
|
|
66
76
|
var rightBound = to && pos !== to ? to : pos - $pos.textOffset + node.nodeSize;
|
|
67
|
-
var tr = state.tr;
|
|
68
77
|
if (!url && text) {
|
|
69
78
|
tr.removeMark(pos, rightBound, linkMark);
|
|
70
79
|
tr.insertText(text, pos, rightBound);
|
|
71
80
|
} else if (!url) {
|
|
72
|
-
return
|
|
81
|
+
return null;
|
|
73
82
|
} else {
|
|
74
83
|
tr.insertText(text, pos, rightBound);
|
|
75
84
|
// Casting to LinkAttributes to prevent wrong attributes been passed (Example ED-7951)
|
|
@@ -81,12 +90,12 @@ function updateLink(href, text, pos, to) {
|
|
|
81
90
|
type: _link.LinkAction.HIDE_TOOLBAR
|
|
82
91
|
});
|
|
83
92
|
}
|
|
84
|
-
|
|
85
|
-
dispatch(tr);
|
|
86
|
-
}
|
|
87
|
-
return true;
|
|
93
|
+
return tr;
|
|
88
94
|
};
|
|
89
95
|
}
|
|
96
|
+
function updateLink(href, text, pos, to) {
|
|
97
|
+
return (0, _preset.editorCommandToPMCommand)(updateLinkEditorCommand(href, text, pos, to));
|
|
98
|
+
}
|
|
90
99
|
function insertLink(from, to, incomingHref, incomingTitle, displayText, source, sourceEvent) {
|
|
91
100
|
var appearance = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 'inline';
|
|
92
101
|
var cardApiActions = arguments.length > 8 ? arguments[8] : undefined;
|
|
@@ -166,6 +175,18 @@ function removeLink(pos, editorAnalyticsApi) {
|
|
|
166
175
|
action: _analytics.ACTION.UNLINK
|
|
167
176
|
});
|
|
168
177
|
}
|
|
178
|
+
function removeLinkEditorCommand(pos, editorAnalyticsApi) {
|
|
179
|
+
return function (_ref3) {
|
|
180
|
+
var tr = _ref3.tr;
|
|
181
|
+
setLinkHrefEditorCommand('', pos, editorAnalyticsApi)({
|
|
182
|
+
tr: tr
|
|
183
|
+
});
|
|
184
|
+
(0, _card.addLinkMetadata)(tr.selection, tr, {
|
|
185
|
+
action: _analytics.ACTION.UNLINK
|
|
186
|
+
});
|
|
187
|
+
return tr;
|
|
188
|
+
};
|
|
189
|
+
}
|
|
169
190
|
function editInsertedLink(editorAnalyticsApi) {
|
|
170
191
|
return function (state, dispatch) {
|
|
171
192
|
if (dispatch) {
|
|
@@ -181,8 +202,8 @@ function editInsertedLink(editorAnalyticsApi) {
|
|
|
181
202
|
};
|
|
182
203
|
}
|
|
183
204
|
function showLinkToolbar(inputMethod, editorAnalyticsApi) {
|
|
184
|
-
return function (
|
|
185
|
-
var tr =
|
|
205
|
+
return function (_ref4) {
|
|
206
|
+
var tr = _ref4.tr;
|
|
186
207
|
var newTr = tr.setMeta(_main.stateKey, {
|
|
187
208
|
type: _link.LinkAction.SHOW_INSERT_TOOLBAR,
|
|
188
209
|
inputMethod: inputMethod
|
package/dist/cjs/plugin.js
CHANGED
|
@@ -19,6 +19,19 @@ var _keymap = require("./pm-plugins/keymap");
|
|
|
19
19
|
var _main = require("./pm-plugins/main");
|
|
20
20
|
var _toolbarButtons = require("./pm-plugins/toolbar-buttons");
|
|
21
21
|
var _Toolbar = require("./Toolbar");
|
|
22
|
+
var getPosFromActiveLinkMark = function getPosFromActiveLinkMark(state) {
|
|
23
|
+
if (state === undefined) {
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
switch (state.type) {
|
|
27
|
+
case 'EDIT':
|
|
28
|
+
case 'EDIT_INSERTED':
|
|
29
|
+
return state.pos;
|
|
30
|
+
case 'INSERT':
|
|
31
|
+
return undefined;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
22
35
|
/**
|
|
23
36
|
* Hyperlink plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
|
|
24
37
|
* from `@atlaskit/editor-core`.
|
|
@@ -40,16 +53,38 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
40
53
|
var _api$analytics;
|
|
41
54
|
var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : _analytics.INPUT_METHOD.TOOLBAR;
|
|
42
55
|
return (0, _commands.showLinkToolbar)(inputMethod, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
56
|
+
},
|
|
57
|
+
updateLink: function updateLink(href, text) {
|
|
58
|
+
var _api$hyperlink;
|
|
59
|
+
var linkMark = api === null || api === void 0 || (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 || (_api$hyperlink = _api$hyperlink.sharedState.currentState()) === null || _api$hyperlink === void 0 ? void 0 : _api$hyperlink.activeLinkMark;
|
|
60
|
+
var pos = getPosFromActiveLinkMark(linkMark);
|
|
61
|
+
if (pos === undefined) {
|
|
62
|
+
return function () {
|
|
63
|
+
return null;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
return (0, _commands.updateLinkEditorCommand)(href, text, pos);
|
|
67
|
+
},
|
|
68
|
+
removeLink: function removeLink() {
|
|
69
|
+
var _api$hyperlink2, _api$analytics2;
|
|
70
|
+
var linkMark = api === null || api === void 0 || (_api$hyperlink2 = api.hyperlink) === null || _api$hyperlink2 === void 0 || (_api$hyperlink2 = _api$hyperlink2.sharedState.currentState()) === null || _api$hyperlink2 === void 0 ? void 0 : _api$hyperlink2.activeLinkMark;
|
|
71
|
+
var pos = getPosFromActiveLinkMark(linkMark);
|
|
72
|
+
if (pos === undefined) {
|
|
73
|
+
return function () {
|
|
74
|
+
return null;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
return (0, _commands.removeLinkEditorCommand)(pos, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
43
78
|
}
|
|
44
79
|
},
|
|
45
80
|
actions: {
|
|
46
81
|
hideLinkToolbar: _commands.hideLinkToolbarSetMeta,
|
|
47
82
|
insertLink: function insertLink(inputMethod, from, to, href, title, displayText) {
|
|
48
|
-
var _api$card, _api$
|
|
83
|
+
var _api$card, _api$analytics3;
|
|
49
84
|
var cardsAvailable = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
50
85
|
var sourceEvent = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : undefined;
|
|
51
86
|
var appearance = arguments.length > 8 ? arguments[8] : undefined;
|
|
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$
|
|
87
|
+
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$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
|
|
53
88
|
},
|
|
54
89
|
updateLink: _commands.updateLink
|
|
55
90
|
},
|
|
@@ -65,7 +100,10 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
65
100
|
plugin: function plugin(_ref2) {
|
|
66
101
|
var dispatch = _ref2.dispatch,
|
|
67
102
|
getIntl = _ref2.getIntl;
|
|
68
|
-
return (
|
|
103
|
+
return (
|
|
104
|
+
// @ts-ignore Temporary solution to check for Live Page editor.
|
|
105
|
+
(0, _main.plugin)(dispatch, getIntl(), options === null || options === void 0 ? void 0 : options.editorAppearance, api, options.__livePage)
|
|
106
|
+
);
|
|
69
107
|
}
|
|
70
108
|
}, {
|
|
71
109
|
name: 'fakeCursorToolbarPlugin',
|
|
@@ -75,15 +113,15 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
75
113
|
}, {
|
|
76
114
|
name: 'hyperlinkInputRule',
|
|
77
115
|
plugin: function plugin(_ref3) {
|
|
78
|
-
var _api$
|
|
116
|
+
var _api$analytics4;
|
|
79
117
|
var schema = _ref3.schema;
|
|
80
|
-
return (0, _inputRule.createInputRulePlugin)(schema, api === null || api === void 0 || (_api$
|
|
118
|
+
return (0, _inputRule.createInputRulePlugin)(schema, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
|
|
81
119
|
}
|
|
82
120
|
}, {
|
|
83
121
|
name: 'hyperlinkKeymap',
|
|
84
122
|
plugin: function plugin() {
|
|
85
|
-
var _api$
|
|
86
|
-
return (0, _keymap.createKeymapPlugin)(api === null || api === void 0 || (_api$
|
|
123
|
+
var _api$analytics5;
|
|
124
|
+
return (0, _keymap.createKeymapPlugin)(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
|
|
87
125
|
}
|
|
88
126
|
}, {
|
|
89
127
|
name: 'hyperlinkToolbarButtons',
|
|
@@ -110,13 +148,13 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
110
148
|
return /*#__PURE__*/_react.default.createElement(_quickInsert.IconLink, null);
|
|
111
149
|
},
|
|
112
150
|
action: function action(insert, state) {
|
|
113
|
-
var _api$
|
|
151
|
+
var _api$analytics6, _api$analytics6$attac;
|
|
114
152
|
var tr = insert(undefined);
|
|
115
153
|
tr.setMeta(_main.stateKey, {
|
|
116
154
|
type: _link.LinkAction.SHOW_INSERT_TOOLBAR,
|
|
117
155
|
inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
|
|
118
156
|
});
|
|
119
|
-
var analyticsAttached = api === null || api === void 0 || (_api$
|
|
157
|
+
var analyticsAttached = api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 || (_api$analytics6 = _api$analytics6.actions) === null || _api$analytics6 === void 0 || (_api$analytics6$attac = _api$analytics6.attachAnalyticsEvent) === null || _api$analytics6$attac === void 0 ? void 0 : _api$analytics6$attac.call(_api$analytics6, {
|
|
120
158
|
action: _analytics.ACTION.INVOKED,
|
|
121
159
|
actionSubject: _analytics.ACTION_SUBJECT.TYPEAHEAD,
|
|
122
160
|
actionSubjectId: _analytics.ACTION_SUBJECT_ID.TYPEAHEAD_LINK,
|
|
@@ -158,7 +158,7 @@ var getActiveText = function getActiveText(selection) {
|
|
|
158
158
|
return;
|
|
159
159
|
};
|
|
160
160
|
var stateKey = exports.stateKey = new _state.PluginKey('hyperlinkPlugin');
|
|
161
|
-
var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance) {
|
|
161
|
+
var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance, pluginInjectionApi, __livePage) {
|
|
162
162
|
return new _safePlugin.SafePlugin({
|
|
163
163
|
state: {
|
|
164
164
|
init: function init(_, state) {
|
|
@@ -193,7 +193,7 @@ var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance)
|
|
|
193
193
|
timesViewed: state.timesViewed,
|
|
194
194
|
searchSessionId: state.searchSessionId
|
|
195
195
|
};
|
|
196
|
-
state = _objectSpread(_objectSpread({}, (0, _platformFeatureFlags.fg)('platform.linking-platform.smart-links-in-live-pages') && state), {}, {
|
|
196
|
+
state = _objectSpread(_objectSpread({}, __livePage && (0, _platformFeatureFlags.fg)('platform.linking-platform.smart-links-in-live-pages') && state), {}, {
|
|
197
197
|
activeText: state.activeText,
|
|
198
198
|
canInsertLink: state.canInsertLink,
|
|
199
199
|
inputMethod: inputMethod,
|
|
@@ -201,39 +201,43 @@ var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance)
|
|
|
201
201
|
editorAppearance: editorAppearance
|
|
202
202
|
}, stateForAnalytics);
|
|
203
203
|
if ((0, _platformFeatureFlags.fg)('platform.linking-platform.smart-links-in-live-pages')) {
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
204
|
+
var _pluginInjectionApi$e;
|
|
205
|
+
var isViewMode = (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 || (_pluginInjectionApi$e = _pluginInjectionApi$e.sharedState.currentState()) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.mode) === 'view';
|
|
206
|
+
if (__livePage && !isViewMode) {
|
|
207
|
+
if (action === _link3.LinkAction.SET_CONFIGURE_DROPDOWN_OPEN) {
|
|
208
|
+
var configureDropdownOpen = tr.getMeta(stateKey).isOpen;
|
|
209
|
+
// Hide overlay when the dropdown is closed (state is updated to false)
|
|
210
|
+
var decorations = configureDropdownOpen ? {} : {
|
|
211
|
+
decorations: _view.DecorationSet.empty
|
|
212
|
+
};
|
|
213
|
+
state = _objectSpread(_objectSpread(_objectSpread({}, state), decorations), {}, {
|
|
214
|
+
configureDropdownOpen: configureDropdownOpen
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
if (action === _link3.LinkAction.SET_CONFIGURE_BUTTON_TARGET_POS) {
|
|
218
|
+
var configureButtonTargetPos = tr.getMeta(stateKey).pos;
|
|
219
|
+
var targetPosHasChanged = pluginState.configureButtonTargetPos !== configureButtonTargetPos;
|
|
220
|
+
var _decorations = pluginState.decorations;
|
|
221
|
+
if (targetPosHasChanged && state.configureDropdownOpen !== true) {
|
|
222
|
+
if (configureButtonTargetPos === undefined) {
|
|
223
|
+
_decorations = _view.DecorationSet.empty;
|
|
224
|
+
} else {
|
|
225
|
+
var decoration = _view.Decoration.widget(configureButtonTargetPos, function (view) {
|
|
226
|
+
return (0, _decorations2.ButtonWrapper)({
|
|
227
|
+
editorView: view,
|
|
228
|
+
pos: configureButtonTargetPos,
|
|
229
|
+
stateKey: stateKey,
|
|
230
|
+
intl: intl
|
|
231
|
+
});
|
|
228
232
|
});
|
|
229
|
-
|
|
230
|
-
|
|
233
|
+
_decorations = _view.DecorationSet.create(newState.doc, [decoration]);
|
|
234
|
+
}
|
|
231
235
|
}
|
|
236
|
+
state = _objectSpread(_objectSpread({}, state), {}, {
|
|
237
|
+
configureButtonTargetPos: configureButtonTargetPos,
|
|
238
|
+
decorations: _decorations
|
|
239
|
+
});
|
|
232
240
|
}
|
|
233
|
-
state = _objectSpread(_objectSpread({}, state), {}, {
|
|
234
|
-
configureButtonTargetPos: configureButtonTargetPos,
|
|
235
|
-
decorations: _decorations
|
|
236
|
-
});
|
|
237
241
|
}
|
|
238
242
|
}
|
|
239
243
|
}
|
|
@@ -258,7 +262,7 @@ var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance)
|
|
|
258
262
|
key: stateKey,
|
|
259
263
|
props: _objectSpread({
|
|
260
264
|
decorations: function decorations(state) {
|
|
261
|
-
if ((0, _platformFeatureFlags.fg)('platform.linking-platform.smart-links-in-live-pages')) {
|
|
265
|
+
if (__livePage && (0, _platformFeatureFlags.fg)('platform.linking-platform.smart-links-in-live-pages')) {
|
|
262
266
|
var _stateKey$getState;
|
|
263
267
|
var _ref = (_stateKey$getState = stateKey.getState(state)) !== null && _stateKey$getState !== void 0 ? _stateKey$getState : {},
|
|
264
268
|
decorations = _ref.decorations;
|
|
@@ -297,7 +301,7 @@ var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance)
|
|
|
297
301
|
return false;
|
|
298
302
|
}
|
|
299
303
|
}
|
|
300
|
-
}, (0, _platformFeatureFlags.fg)('platform.linking-platform.smart-links-in-live-pages') && {
|
|
304
|
+
}, __livePage && (0, _platformFeatureFlags.fg)('platform.linking-platform.smart-links-in-live-pages') && {
|
|
301
305
|
markViews: {
|
|
302
306
|
link: function link(mark, view, inline) {
|
|
303
307
|
var toDOM = mark.type.spec.toDOM;
|
package/dist/es2019/commands.js
CHANGED
|
@@ -2,21 +2,29 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, buildEditLinkPayload, EVENT_
|
|
|
2
2
|
import { addLinkMetadata, commandWithMetadata } from '@atlaskit/editor-common/card';
|
|
3
3
|
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
4
4
|
import { isTextAtPos, LinkAction } from '@atlaskit/editor-common/link';
|
|
5
|
-
import {
|
|
5
|
+
import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
|
|
6
|
+
import { getLinkCreationAnalyticsEvent, normalizeUrl } from '@atlaskit/editor-common/utils';
|
|
6
7
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
7
8
|
import { stateKey } from './pm-plugins/main';
|
|
8
|
-
|
|
9
|
-
return
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
function setLinkHrefEditorCommand(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
10
|
+
return ({
|
|
11
|
+
tr
|
|
12
|
+
}) => {
|
|
13
|
+
if (!isTextAtPos(pos)({
|
|
14
|
+
tr
|
|
15
|
+
})) {
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
const $pos = tr.doc.resolve(pos);
|
|
19
|
+
const node = tr.doc.nodeAt(pos);
|
|
20
|
+
const linkMark = tr.doc.type.schema.marks.link;
|
|
13
21
|
const mark = linkMark.isInSet(node.marks);
|
|
14
22
|
const url = normalizeUrl(href);
|
|
15
23
|
if (mark && mark.attrs.href === url) {
|
|
16
|
-
return
|
|
24
|
+
return null;
|
|
17
25
|
}
|
|
18
26
|
const rightBound = to && pos !== to ? to : pos - $pos.textOffset + node.nodeSize;
|
|
19
|
-
|
|
27
|
+
tr.removeMark(pos, rightBound, linkMark);
|
|
20
28
|
if (href.trim()) {
|
|
21
29
|
tr.addMark(pos, rightBound, linkMark.create({
|
|
22
30
|
...(mark && mark.attrs || {}),
|
|
@@ -30,29 +38,30 @@ export function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
|
30
38
|
type: LinkAction.HIDE_TOOLBAR
|
|
31
39
|
});
|
|
32
40
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
}
|
|
36
|
-
return true;
|
|
37
|
-
});
|
|
41
|
+
return tr;
|
|
42
|
+
};
|
|
38
43
|
}
|
|
39
|
-
export function
|
|
40
|
-
return (
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
export function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
45
|
+
return editorCommandToPMCommand(setLinkHrefEditorCommand(href, pos, editorAnalyticsApi, to, isTabPressed));
|
|
46
|
+
}
|
|
47
|
+
export function updateLinkEditorCommand(href, text, pos, to) {
|
|
48
|
+
return ({
|
|
49
|
+
tr
|
|
50
|
+
}) => {
|
|
51
|
+
const $pos = tr.doc.resolve(pos);
|
|
52
|
+
const node = tr.doc.nodeAt(pos);
|
|
43
53
|
if (!node) {
|
|
44
|
-
return
|
|
54
|
+
return null;
|
|
45
55
|
}
|
|
46
56
|
const url = normalizeUrl(href);
|
|
47
|
-
const mark =
|
|
48
|
-
const linkMark =
|
|
57
|
+
const mark = tr.doc.type.schema.marks.link.isInSet(node.marks);
|
|
58
|
+
const linkMark = tr.doc.type.schema.marks.link;
|
|
49
59
|
const rightBound = to && pos !== to ? to : pos - $pos.textOffset + node.nodeSize;
|
|
50
|
-
const tr = state.tr;
|
|
51
60
|
if (!url && text) {
|
|
52
61
|
tr.removeMark(pos, rightBound, linkMark);
|
|
53
62
|
tr.insertText(text, pos, rightBound);
|
|
54
63
|
} else if (!url) {
|
|
55
|
-
return
|
|
64
|
+
return null;
|
|
56
65
|
} else {
|
|
57
66
|
tr.insertText(text, pos, rightBound);
|
|
58
67
|
// Casting to LinkAttributes to prevent wrong attributes been passed (Example ED-7951)
|
|
@@ -65,12 +74,12 @@ export function updateLink(href, text, pos, to) {
|
|
|
65
74
|
type: LinkAction.HIDE_TOOLBAR
|
|
66
75
|
});
|
|
67
76
|
}
|
|
68
|
-
|
|
69
|
-
dispatch(tr);
|
|
70
|
-
}
|
|
71
|
-
return true;
|
|
77
|
+
return tr;
|
|
72
78
|
};
|
|
73
79
|
}
|
|
80
|
+
export function updateLink(href, text, pos, to) {
|
|
81
|
+
return editorCommandToPMCommand(updateLinkEditorCommand(href, text, pos, to));
|
|
82
|
+
}
|
|
74
83
|
export function insertLink(from, to, incomingHref, incomingTitle, displayText, source, sourceEvent, appearance = 'inline', cardApiActions) {
|
|
75
84
|
return (state, dispatch) => {
|
|
76
85
|
const link = state.schema.marks.link;
|
|
@@ -147,6 +156,19 @@ export function removeLink(pos, editorAnalyticsApi) {
|
|
|
147
156
|
action: ACTION.UNLINK
|
|
148
157
|
});
|
|
149
158
|
}
|
|
159
|
+
export function removeLinkEditorCommand(pos, editorAnalyticsApi) {
|
|
160
|
+
return ({
|
|
161
|
+
tr
|
|
162
|
+
}) => {
|
|
163
|
+
setLinkHrefEditorCommand('', pos, editorAnalyticsApi)({
|
|
164
|
+
tr
|
|
165
|
+
});
|
|
166
|
+
addLinkMetadata(tr.selection, tr, {
|
|
167
|
+
action: ACTION.UNLINK
|
|
168
|
+
});
|
|
169
|
+
return tr;
|
|
170
|
+
};
|
|
171
|
+
}
|
|
150
172
|
export function editInsertedLink(editorAnalyticsApi) {
|
|
151
173
|
return (state, dispatch) => {
|
|
152
174
|
if (dispatch) {
|
package/dist/es2019/plugin.js
CHANGED
|
@@ -5,13 +5,26 @@ import { addLink, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
|
5
5
|
import { LinkAction } from '@atlaskit/editor-common/link';
|
|
6
6
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
7
7
|
import { IconLink } from '@atlaskit/editor-common/quick-insert';
|
|
8
|
-
import { hideLinkToolbarSetMeta, insertLinkWithAnalytics, showLinkToolbar, updateLink } from './commands';
|
|
8
|
+
import { hideLinkToolbarSetMeta, insertLinkWithAnalytics, removeLinkEditorCommand, showLinkToolbar, updateLink, updateLinkEditorCommand } from './commands';
|
|
9
9
|
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
13
|
import { toolbarButtonsPlugin } from './pm-plugins/toolbar-buttons';
|
|
14
14
|
import { getToolbarConfig } from './Toolbar';
|
|
15
|
+
const getPosFromActiveLinkMark = state => {
|
|
16
|
+
if (state === undefined) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
switch (state.type) {
|
|
20
|
+
case 'EDIT':
|
|
21
|
+
case 'EDIT_INSERTED':
|
|
22
|
+
return state.pos;
|
|
23
|
+
case 'INSERT':
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
15
28
|
/**
|
|
16
29
|
* Hyperlink plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
|
|
17
30
|
* from `@atlaskit/editor-core`.
|
|
@@ -32,13 +45,31 @@ export const hyperlinkPlugin = ({
|
|
|
32
45
|
showLinkToolbar: (inputMethod = INPUT_METHOD.TOOLBAR) => {
|
|
33
46
|
var _api$analytics;
|
|
34
47
|
return showLinkToolbar(inputMethod, api === null || api === void 0 ? void 0 : (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
48
|
+
},
|
|
49
|
+
updateLink: (href, text) => {
|
|
50
|
+
var _api$hyperlink, _api$hyperlink$shared;
|
|
51
|
+
const linkMark = api === null || api === void 0 ? void 0 : (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 ? void 0 : (_api$hyperlink$shared = _api$hyperlink.sharedState.currentState()) === null || _api$hyperlink$shared === void 0 ? void 0 : _api$hyperlink$shared.activeLinkMark;
|
|
52
|
+
const pos = getPosFromActiveLinkMark(linkMark);
|
|
53
|
+
if (pos === undefined) {
|
|
54
|
+
return () => null;
|
|
55
|
+
}
|
|
56
|
+
return updateLinkEditorCommand(href, text, pos);
|
|
57
|
+
},
|
|
58
|
+
removeLink: () => {
|
|
59
|
+
var _api$hyperlink2, _api$hyperlink2$share, _api$analytics2;
|
|
60
|
+
const linkMark = api === null || api === void 0 ? void 0 : (_api$hyperlink2 = api.hyperlink) === null || _api$hyperlink2 === void 0 ? void 0 : (_api$hyperlink2$share = _api$hyperlink2.sharedState.currentState()) === null || _api$hyperlink2$share === void 0 ? void 0 : _api$hyperlink2$share.activeLinkMark;
|
|
61
|
+
const pos = getPosFromActiveLinkMark(linkMark);
|
|
62
|
+
if (pos === undefined) {
|
|
63
|
+
return () => null;
|
|
64
|
+
}
|
|
65
|
+
return removeLinkEditorCommand(pos, api === null || api === void 0 ? void 0 : (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
35
66
|
}
|
|
36
67
|
},
|
|
37
68
|
actions: {
|
|
38
69
|
hideLinkToolbar: hideLinkToolbarSetMeta,
|
|
39
70
|
insertLink: (inputMethod, from, to, href, title, displayText, cardsAvailable = false, sourceEvent = undefined, appearance) => {
|
|
40
|
-
var _api$card, _api$
|
|
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$
|
|
71
|
+
var _api$card, _api$analytics3;
|
|
72
|
+
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$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
|
|
42
73
|
},
|
|
43
74
|
updateLink: updateLink
|
|
44
75
|
},
|
|
@@ -54,7 +85,9 @@ export const hyperlinkPlugin = ({
|
|
|
54
85
|
plugin: ({
|
|
55
86
|
dispatch,
|
|
56
87
|
getIntl
|
|
57
|
-
}) =>
|
|
88
|
+
}) =>
|
|
89
|
+
// @ts-ignore Temporary solution to check for Live Page editor.
|
|
90
|
+
plugin(dispatch, getIntl(), options === null || options === void 0 ? void 0 : options.editorAppearance, api, options.__livePage)
|
|
58
91
|
}, {
|
|
59
92
|
name: 'fakeCursorToolbarPlugin',
|
|
60
93
|
plugin: () => fakeCursorToolbarPlugin
|
|
@@ -63,14 +96,14 @@ export const hyperlinkPlugin = ({
|
|
|
63
96
|
plugin: ({
|
|
64
97
|
schema
|
|
65
98
|
}) => {
|
|
66
|
-
var _api$
|
|
67
|
-
return createInputRulePlugin(schema, api === null || api === void 0 ? void 0 : (_api$
|
|
99
|
+
var _api$analytics4;
|
|
100
|
+
return createInputRulePlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
|
|
68
101
|
}
|
|
69
102
|
}, {
|
|
70
103
|
name: 'hyperlinkKeymap',
|
|
71
104
|
plugin: () => {
|
|
72
|
-
var _api$
|
|
73
|
-
return createKeymapPlugin(api === null || api === void 0 ? void 0 : (_api$
|
|
105
|
+
var _api$analytics5;
|
|
106
|
+
return createKeymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
|
|
74
107
|
}
|
|
75
108
|
}, {
|
|
76
109
|
name: 'hyperlinkToolbarButtons',
|
|
@@ -95,13 +128,13 @@ export const hyperlinkPlugin = ({
|
|
|
95
128
|
keyshortcut: tooltip(addLink),
|
|
96
129
|
icon: () => /*#__PURE__*/React.createElement(IconLink, null),
|
|
97
130
|
action(insert, state) {
|
|
98
|
-
var _api$
|
|
131
|
+
var _api$analytics6, _api$analytics6$actio, _api$analytics6$actio2;
|
|
99
132
|
const tr = insert(undefined);
|
|
100
133
|
tr.setMeta(stateKey, {
|
|
101
134
|
type: LinkAction.SHOW_INSERT_TOOLBAR,
|
|
102
135
|
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
103
136
|
});
|
|
104
|
-
const analyticsAttached = api === null || api === void 0 ? void 0 : (_api$
|
|
137
|
+
const analyticsAttached = api === null || api === void 0 ? void 0 : (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 ? void 0 : (_api$analytics6$actio = _api$analytics6.actions) === null || _api$analytics6$actio === void 0 ? void 0 : (_api$analytics6$actio2 = _api$analytics6$actio.attachAnalyticsEvent) === null || _api$analytics6$actio2 === void 0 ? void 0 : _api$analytics6$actio2.call(_api$analytics6$actio, {
|
|
105
138
|
action: ACTION.INVOKED,
|
|
106
139
|
actionSubject: ACTION_SUBJECT.TYPEAHEAD,
|
|
107
140
|
actionSubjectId: ACTION_SUBJECT_ID.TYPEAHEAD_LINK,
|
|
@@ -159,7 +159,7 @@ const getActiveText = selection => {
|
|
|
159
159
|
return;
|
|
160
160
|
};
|
|
161
161
|
export const stateKey = new PluginKey('hyperlinkPlugin');
|
|
162
|
-
export const plugin = (dispatch, intl, editorAppearance) => new SafePlugin({
|
|
162
|
+
export const plugin = (dispatch, intl, editorAppearance, pluginInjectionApi, __livePage) => new SafePlugin({
|
|
163
163
|
state: {
|
|
164
164
|
init(_, state) {
|
|
165
165
|
const canInsertLink = canLinkBeCreatedInRange(state.selection.from, state.selection.to)(state);
|
|
@@ -194,7 +194,7 @@ export const plugin = (dispatch, intl, editorAppearance) => new SafePlugin({
|
|
|
194
194
|
searchSessionId: state.searchSessionId
|
|
195
195
|
};
|
|
196
196
|
state = {
|
|
197
|
-
...(fg('platform.linking-platform.smart-links-in-live-pages') && state),
|
|
197
|
+
...(__livePage && fg('platform.linking-platform.smart-links-in-live-pages') && state),
|
|
198
198
|
activeText: state.activeText,
|
|
199
199
|
canInsertLink: state.canInsertLink,
|
|
200
200
|
inputMethod,
|
|
@@ -203,42 +203,46 @@ export const plugin = (dispatch, intl, editorAppearance) => new SafePlugin({
|
|
|
203
203
|
...stateForAnalytics
|
|
204
204
|
};
|
|
205
205
|
if (fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
206
|
+
var _pluginInjectionApi$e, _pluginInjectionApi$e2;
|
|
207
|
+
const isViewMode = (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 ? void 0 : (_pluginInjectionApi$e2 = _pluginInjectionApi$e.sharedState.currentState()) === null || _pluginInjectionApi$e2 === void 0 ? void 0 : _pluginInjectionApi$e2.mode) === 'view';
|
|
208
|
+
if (__livePage && !isViewMode) {
|
|
209
|
+
if (action === LinkAction.SET_CONFIGURE_DROPDOWN_OPEN) {
|
|
210
|
+
const configureDropdownOpen = tr.getMeta(stateKey).isOpen;
|
|
211
|
+
// Hide overlay when the dropdown is closed (state is updated to false)
|
|
212
|
+
const decorations = configureDropdownOpen ? {} : {
|
|
213
|
+
decorations: DecorationSet.empty
|
|
214
|
+
};
|
|
215
|
+
state = {
|
|
216
|
+
...state,
|
|
217
|
+
...decorations,
|
|
218
|
+
configureDropdownOpen
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
if (action === LinkAction.SET_CONFIGURE_BUTTON_TARGET_POS) {
|
|
222
|
+
const configureButtonTargetPos = tr.getMeta(stateKey).pos;
|
|
223
|
+
const targetPosHasChanged = pluginState.configureButtonTargetPos !== configureButtonTargetPos;
|
|
224
|
+
let decorations = pluginState.decorations;
|
|
225
|
+
if (targetPosHasChanged && state.configureDropdownOpen !== true) {
|
|
226
|
+
if (configureButtonTargetPos === undefined) {
|
|
227
|
+
decorations = DecorationSet.empty;
|
|
228
|
+
} else {
|
|
229
|
+
const decoration = Decoration.widget(configureButtonTargetPos, view => {
|
|
230
|
+
return ButtonWrapper({
|
|
231
|
+
editorView: view,
|
|
232
|
+
pos: configureButtonTargetPos,
|
|
233
|
+
stateKey,
|
|
234
|
+
intl
|
|
235
|
+
});
|
|
232
236
|
});
|
|
233
|
-
|
|
234
|
-
|
|
237
|
+
decorations = DecorationSet.create(newState.doc, [decoration]);
|
|
238
|
+
}
|
|
235
239
|
}
|
|
240
|
+
state = {
|
|
241
|
+
...state,
|
|
242
|
+
configureButtonTargetPos,
|
|
243
|
+
decorations
|
|
244
|
+
};
|
|
236
245
|
}
|
|
237
|
-
state = {
|
|
238
|
-
...state,
|
|
239
|
-
configureButtonTargetPos,
|
|
240
|
-
decorations
|
|
241
|
-
};
|
|
242
246
|
}
|
|
243
247
|
}
|
|
244
248
|
}
|
|
@@ -263,7 +267,7 @@ export const plugin = (dispatch, intl, editorAppearance) => new SafePlugin({
|
|
|
263
267
|
key: stateKey,
|
|
264
268
|
props: {
|
|
265
269
|
decorations: state => {
|
|
266
|
-
if (fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
270
|
+
if (__livePage && fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
267
271
|
var _stateKey$getState;
|
|
268
272
|
const {
|
|
269
273
|
decorations
|
|
@@ -309,7 +313,7 @@ export const plugin = (dispatch, intl, editorAppearance) => new SafePlugin({
|
|
|
309
313
|
return false;
|
|
310
314
|
}
|
|
311
315
|
},
|
|
312
|
-
...(fg('platform.linking-platform.smart-links-in-live-pages') && {
|
|
316
|
+
...(__livePage && fg('platform.linking-platform.smart-links-in-live-pages') && {
|
|
313
317
|
markViews: {
|
|
314
318
|
link: (mark, view, inline) => {
|
|
315
319
|
const toDOM = mark.type.spec.toDOM;
|
package/dist/esm/commands.js
CHANGED
|
@@ -5,21 +5,28 @@ import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, buildEditLinkPayload, EVENT_
|
|
|
5
5
|
import { addLinkMetadata, commandWithMetadata } from '@atlaskit/editor-common/card';
|
|
6
6
|
import { withAnalytics } from '@atlaskit/editor-common/editor-analytics';
|
|
7
7
|
import { isTextAtPos, LinkAction } from '@atlaskit/editor-common/link';
|
|
8
|
-
import {
|
|
8
|
+
import { editorCommandToPMCommand } from '@atlaskit/editor-common/preset';
|
|
9
|
+
import { getLinkCreationAnalyticsEvent, normalizeUrl } from '@atlaskit/editor-common/utils';
|
|
9
10
|
import { Selection } from '@atlaskit/editor-prosemirror/state';
|
|
10
11
|
import { stateKey } from './pm-plugins/main';
|
|
11
|
-
|
|
12
|
-
return
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
function setLinkHrefEditorCommand(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
13
|
+
return function (_ref) {
|
|
14
|
+
var tr = _ref.tr;
|
|
15
|
+
if (!isTextAtPos(pos)({
|
|
16
|
+
tr: tr
|
|
17
|
+
})) {
|
|
18
|
+
return null;
|
|
19
|
+
}
|
|
20
|
+
var $pos = tr.doc.resolve(pos);
|
|
21
|
+
var node = tr.doc.nodeAt(pos);
|
|
22
|
+
var linkMark = tr.doc.type.schema.marks.link;
|
|
16
23
|
var mark = linkMark.isInSet(node.marks);
|
|
17
24
|
var url = normalizeUrl(href);
|
|
18
25
|
if (mark && mark.attrs.href === url) {
|
|
19
|
-
return
|
|
26
|
+
return null;
|
|
20
27
|
}
|
|
21
28
|
var rightBound = to && pos !== to ? to : pos - $pos.textOffset + node.nodeSize;
|
|
22
|
-
|
|
29
|
+
tr.removeMark(pos, rightBound, linkMark);
|
|
23
30
|
if (href.trim()) {
|
|
24
31
|
tr.addMark(pos, rightBound, linkMark.create(_objectSpread(_objectSpread({}, mark && mark.attrs || {}), {}, {
|
|
25
32
|
href: url
|
|
@@ -32,29 +39,29 @@ export function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
|
32
39
|
type: LinkAction.HIDE_TOOLBAR
|
|
33
40
|
});
|
|
34
41
|
}
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
return true;
|
|
39
|
-
});
|
|
42
|
+
return tr;
|
|
43
|
+
};
|
|
40
44
|
}
|
|
41
|
-
export function
|
|
42
|
-
return
|
|
43
|
-
|
|
44
|
-
|
|
45
|
+
export function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
|
|
46
|
+
return editorCommandToPMCommand(setLinkHrefEditorCommand(href, pos, editorAnalyticsApi, to, isTabPressed));
|
|
47
|
+
}
|
|
48
|
+
export function updateLinkEditorCommand(href, text, pos, to) {
|
|
49
|
+
return function (_ref2) {
|
|
50
|
+
var tr = _ref2.tr;
|
|
51
|
+
var $pos = tr.doc.resolve(pos);
|
|
52
|
+
var node = tr.doc.nodeAt(pos);
|
|
45
53
|
if (!node) {
|
|
46
|
-
return
|
|
54
|
+
return null;
|
|
47
55
|
}
|
|
48
56
|
var url = normalizeUrl(href);
|
|
49
|
-
var mark =
|
|
50
|
-
var linkMark =
|
|
57
|
+
var mark = tr.doc.type.schema.marks.link.isInSet(node.marks);
|
|
58
|
+
var linkMark = tr.doc.type.schema.marks.link;
|
|
51
59
|
var rightBound = to && pos !== to ? to : pos - $pos.textOffset + node.nodeSize;
|
|
52
|
-
var tr = state.tr;
|
|
53
60
|
if (!url && text) {
|
|
54
61
|
tr.removeMark(pos, rightBound, linkMark);
|
|
55
62
|
tr.insertText(text, pos, rightBound);
|
|
56
63
|
} else if (!url) {
|
|
57
|
-
return
|
|
64
|
+
return null;
|
|
58
65
|
} else {
|
|
59
66
|
tr.insertText(text, pos, rightBound);
|
|
60
67
|
// Casting to LinkAttributes to prevent wrong attributes been passed (Example ED-7951)
|
|
@@ -66,12 +73,12 @@ export function updateLink(href, text, pos, to) {
|
|
|
66
73
|
type: LinkAction.HIDE_TOOLBAR
|
|
67
74
|
});
|
|
68
75
|
}
|
|
69
|
-
|
|
70
|
-
dispatch(tr);
|
|
71
|
-
}
|
|
72
|
-
return true;
|
|
76
|
+
return tr;
|
|
73
77
|
};
|
|
74
78
|
}
|
|
79
|
+
export function updateLink(href, text, pos, to) {
|
|
80
|
+
return editorCommandToPMCommand(updateLinkEditorCommand(href, text, pos, to));
|
|
81
|
+
}
|
|
75
82
|
export function insertLink(from, to, incomingHref, incomingTitle, displayText, source, sourceEvent) {
|
|
76
83
|
var appearance = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 'inline';
|
|
77
84
|
var cardApiActions = arguments.length > 8 ? arguments[8] : undefined;
|
|
@@ -151,6 +158,18 @@ export function removeLink(pos, editorAnalyticsApi) {
|
|
|
151
158
|
action: ACTION.UNLINK
|
|
152
159
|
});
|
|
153
160
|
}
|
|
161
|
+
export function removeLinkEditorCommand(pos, editorAnalyticsApi) {
|
|
162
|
+
return function (_ref3) {
|
|
163
|
+
var tr = _ref3.tr;
|
|
164
|
+
setLinkHrefEditorCommand('', pos, editorAnalyticsApi)({
|
|
165
|
+
tr: tr
|
|
166
|
+
});
|
|
167
|
+
addLinkMetadata(tr.selection, tr, {
|
|
168
|
+
action: ACTION.UNLINK
|
|
169
|
+
});
|
|
170
|
+
return tr;
|
|
171
|
+
};
|
|
172
|
+
}
|
|
154
173
|
export function editInsertedLink(editorAnalyticsApi) {
|
|
155
174
|
return function (state, dispatch) {
|
|
156
175
|
if (dispatch) {
|
|
@@ -166,8 +185,8 @@ export function editInsertedLink(editorAnalyticsApi) {
|
|
|
166
185
|
};
|
|
167
186
|
}
|
|
168
187
|
export function showLinkToolbar(inputMethod, editorAnalyticsApi) {
|
|
169
|
-
return function (
|
|
170
|
-
var tr =
|
|
188
|
+
return function (_ref4) {
|
|
189
|
+
var tr = _ref4.tr;
|
|
171
190
|
var newTr = tr.setMeta(stateKey, {
|
|
172
191
|
type: LinkAction.SHOW_INSERT_TOOLBAR,
|
|
173
192
|
inputMethod: inputMethod
|
package/dist/esm/plugin.js
CHANGED
|
@@ -5,13 +5,26 @@ import { addLink, tooltip } from '@atlaskit/editor-common/keymaps';
|
|
|
5
5
|
import { LinkAction } from '@atlaskit/editor-common/link';
|
|
6
6
|
import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
|
|
7
7
|
import { IconLink } from '@atlaskit/editor-common/quick-insert';
|
|
8
|
-
import { hideLinkToolbarSetMeta, insertLinkWithAnalytics, showLinkToolbar as _showLinkToolbar, updateLink } from './commands';
|
|
8
|
+
import { hideLinkToolbarSetMeta, insertLinkWithAnalytics, removeLinkEditorCommand, showLinkToolbar as _showLinkToolbar, updateLink, updateLinkEditorCommand } from './commands';
|
|
9
9
|
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 as _plugin, stateKey } from './pm-plugins/main';
|
|
13
13
|
import { toolbarButtonsPlugin } from './pm-plugins/toolbar-buttons';
|
|
14
14
|
import { getToolbarConfig } from './Toolbar';
|
|
15
|
+
var getPosFromActiveLinkMark = function getPosFromActiveLinkMark(state) {
|
|
16
|
+
if (state === undefined) {
|
|
17
|
+
return undefined;
|
|
18
|
+
}
|
|
19
|
+
switch (state.type) {
|
|
20
|
+
case 'EDIT':
|
|
21
|
+
case 'EDIT_INSERTED':
|
|
22
|
+
return state.pos;
|
|
23
|
+
case 'INSERT':
|
|
24
|
+
return undefined;
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
|
|
15
28
|
/**
|
|
16
29
|
* Hyperlink plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
|
|
17
30
|
* from `@atlaskit/editor-core`.
|
|
@@ -33,16 +46,38 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
33
46
|
var _api$analytics;
|
|
34
47
|
var inputMethod = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : INPUT_METHOD.TOOLBAR;
|
|
35
48
|
return _showLinkToolbar(inputMethod, api === null || api === void 0 || (_api$analytics = api.analytics) === null || _api$analytics === void 0 ? void 0 : _api$analytics.actions);
|
|
49
|
+
},
|
|
50
|
+
updateLink: function updateLink(href, text) {
|
|
51
|
+
var _api$hyperlink;
|
|
52
|
+
var linkMark = api === null || api === void 0 || (_api$hyperlink = api.hyperlink) === null || _api$hyperlink === void 0 || (_api$hyperlink = _api$hyperlink.sharedState.currentState()) === null || _api$hyperlink === void 0 ? void 0 : _api$hyperlink.activeLinkMark;
|
|
53
|
+
var pos = getPosFromActiveLinkMark(linkMark);
|
|
54
|
+
if (pos === undefined) {
|
|
55
|
+
return function () {
|
|
56
|
+
return null;
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
return updateLinkEditorCommand(href, text, pos);
|
|
60
|
+
},
|
|
61
|
+
removeLink: function removeLink() {
|
|
62
|
+
var _api$hyperlink2, _api$analytics2;
|
|
63
|
+
var linkMark = api === null || api === void 0 || (_api$hyperlink2 = api.hyperlink) === null || _api$hyperlink2 === void 0 || (_api$hyperlink2 = _api$hyperlink2.sharedState.currentState()) === null || _api$hyperlink2 === void 0 ? void 0 : _api$hyperlink2.activeLinkMark;
|
|
64
|
+
var pos = getPosFromActiveLinkMark(linkMark);
|
|
65
|
+
if (pos === undefined) {
|
|
66
|
+
return function () {
|
|
67
|
+
return null;
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
return removeLinkEditorCommand(pos, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions);
|
|
36
71
|
}
|
|
37
72
|
},
|
|
38
73
|
actions: {
|
|
39
74
|
hideLinkToolbar: hideLinkToolbarSetMeta,
|
|
40
75
|
insertLink: function insertLink(inputMethod, from, to, href, title, displayText) {
|
|
41
|
-
var _api$card, _api$
|
|
76
|
+
var _api$card, _api$analytics3;
|
|
42
77
|
var cardsAvailable = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
|
|
43
78
|
var sourceEvent = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : undefined;
|
|
44
79
|
var appearance = arguments.length > 8 ? arguments[8] : undefined;
|
|
45
|
-
return 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$
|
|
80
|
+
return 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$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
|
|
46
81
|
},
|
|
47
82
|
updateLink: updateLink
|
|
48
83
|
},
|
|
@@ -58,7 +93,10 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
58
93
|
plugin: function plugin(_ref2) {
|
|
59
94
|
var dispatch = _ref2.dispatch,
|
|
60
95
|
getIntl = _ref2.getIntl;
|
|
61
|
-
return
|
|
96
|
+
return (
|
|
97
|
+
// @ts-ignore Temporary solution to check for Live Page editor.
|
|
98
|
+
_plugin(dispatch, getIntl(), options === null || options === void 0 ? void 0 : options.editorAppearance, api, options.__livePage)
|
|
99
|
+
);
|
|
62
100
|
}
|
|
63
101
|
}, {
|
|
64
102
|
name: 'fakeCursorToolbarPlugin',
|
|
@@ -68,15 +106,15 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
68
106
|
}, {
|
|
69
107
|
name: 'hyperlinkInputRule',
|
|
70
108
|
plugin: function plugin(_ref3) {
|
|
71
|
-
var _api$
|
|
109
|
+
var _api$analytics4;
|
|
72
110
|
var schema = _ref3.schema;
|
|
73
|
-
return createInputRulePlugin(schema, api === null || api === void 0 || (_api$
|
|
111
|
+
return createInputRulePlugin(schema, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
|
|
74
112
|
}
|
|
75
113
|
}, {
|
|
76
114
|
name: 'hyperlinkKeymap',
|
|
77
115
|
plugin: function plugin() {
|
|
78
|
-
var _api$
|
|
79
|
-
return createKeymapPlugin(api === null || api === void 0 || (_api$
|
|
116
|
+
var _api$analytics5;
|
|
117
|
+
return createKeymapPlugin(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
|
|
80
118
|
}
|
|
81
119
|
}, {
|
|
82
120
|
name: 'hyperlinkToolbarButtons',
|
|
@@ -103,13 +141,13 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
|
|
|
103
141
|
return /*#__PURE__*/React.createElement(IconLink, null);
|
|
104
142
|
},
|
|
105
143
|
action: function action(insert, state) {
|
|
106
|
-
var _api$
|
|
144
|
+
var _api$analytics6, _api$analytics6$attac;
|
|
107
145
|
var tr = insert(undefined);
|
|
108
146
|
tr.setMeta(stateKey, {
|
|
109
147
|
type: LinkAction.SHOW_INSERT_TOOLBAR,
|
|
110
148
|
inputMethod: INPUT_METHOD.QUICK_INSERT
|
|
111
149
|
});
|
|
112
|
-
var analyticsAttached = api === null || api === void 0 || (_api$
|
|
150
|
+
var analyticsAttached = api === null || api === void 0 || (_api$analytics6 = api.analytics) === null || _api$analytics6 === void 0 || (_api$analytics6 = _api$analytics6.actions) === null || _api$analytics6 === void 0 || (_api$analytics6$attac = _api$analytics6.attachAnalyticsEvent) === null || _api$analytics6$attac === void 0 ? void 0 : _api$analytics6$attac.call(_api$analytics6, {
|
|
113
151
|
action: ACTION.INVOKED,
|
|
114
152
|
actionSubject: ACTION_SUBJECT.TYPEAHEAD,
|
|
115
153
|
actionSubjectId: ACTION_SUBJECT_ID.TYPEAHEAD_LINK,
|
|
@@ -151,7 +151,7 @@ var getActiveText = function getActiveText(selection) {
|
|
|
151
151
|
return;
|
|
152
152
|
};
|
|
153
153
|
export var stateKey = new PluginKey('hyperlinkPlugin');
|
|
154
|
-
export var plugin = function plugin(dispatch, intl, editorAppearance) {
|
|
154
|
+
export var plugin = function plugin(dispatch, intl, editorAppearance, pluginInjectionApi, __livePage) {
|
|
155
155
|
return new SafePlugin({
|
|
156
156
|
state: {
|
|
157
157
|
init: function init(_, state) {
|
|
@@ -186,7 +186,7 @@ export var plugin = function plugin(dispatch, intl, editorAppearance) {
|
|
|
186
186
|
timesViewed: state.timesViewed,
|
|
187
187
|
searchSessionId: state.searchSessionId
|
|
188
188
|
};
|
|
189
|
-
state = _objectSpread(_objectSpread({}, fg('platform.linking-platform.smart-links-in-live-pages') && state), {}, {
|
|
189
|
+
state = _objectSpread(_objectSpread({}, __livePage && fg('platform.linking-platform.smart-links-in-live-pages') && state), {}, {
|
|
190
190
|
activeText: state.activeText,
|
|
191
191
|
canInsertLink: state.canInsertLink,
|
|
192
192
|
inputMethod: inputMethod,
|
|
@@ -194,39 +194,43 @@ export var plugin = function plugin(dispatch, intl, editorAppearance) {
|
|
|
194
194
|
editorAppearance: editorAppearance
|
|
195
195
|
}, stateForAnalytics);
|
|
196
196
|
if (fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
197
|
+
var _pluginInjectionApi$e;
|
|
198
|
+
var isViewMode = (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 || (_pluginInjectionApi$e = _pluginInjectionApi$e.sharedState.currentState()) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.mode) === 'view';
|
|
199
|
+
if (__livePage && !isViewMode) {
|
|
200
|
+
if (action === LinkAction.SET_CONFIGURE_DROPDOWN_OPEN) {
|
|
201
|
+
var configureDropdownOpen = tr.getMeta(stateKey).isOpen;
|
|
202
|
+
// Hide overlay when the dropdown is closed (state is updated to false)
|
|
203
|
+
var decorations = configureDropdownOpen ? {} : {
|
|
204
|
+
decorations: DecorationSet.empty
|
|
205
|
+
};
|
|
206
|
+
state = _objectSpread(_objectSpread(_objectSpread({}, state), decorations), {}, {
|
|
207
|
+
configureDropdownOpen: configureDropdownOpen
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
if (action === LinkAction.SET_CONFIGURE_BUTTON_TARGET_POS) {
|
|
211
|
+
var configureButtonTargetPos = tr.getMeta(stateKey).pos;
|
|
212
|
+
var targetPosHasChanged = pluginState.configureButtonTargetPos !== configureButtonTargetPos;
|
|
213
|
+
var _decorations = pluginState.decorations;
|
|
214
|
+
if (targetPosHasChanged && state.configureDropdownOpen !== true) {
|
|
215
|
+
if (configureButtonTargetPos === undefined) {
|
|
216
|
+
_decorations = DecorationSet.empty;
|
|
217
|
+
} else {
|
|
218
|
+
var decoration = Decoration.widget(configureButtonTargetPos, function (view) {
|
|
219
|
+
return ButtonWrapper({
|
|
220
|
+
editorView: view,
|
|
221
|
+
pos: configureButtonTargetPos,
|
|
222
|
+
stateKey: stateKey,
|
|
223
|
+
intl: intl
|
|
224
|
+
});
|
|
221
225
|
});
|
|
222
|
-
|
|
223
|
-
|
|
226
|
+
_decorations = DecorationSet.create(newState.doc, [decoration]);
|
|
227
|
+
}
|
|
224
228
|
}
|
|
229
|
+
state = _objectSpread(_objectSpread({}, state), {}, {
|
|
230
|
+
configureButtonTargetPos: configureButtonTargetPos,
|
|
231
|
+
decorations: _decorations
|
|
232
|
+
});
|
|
225
233
|
}
|
|
226
|
-
state = _objectSpread(_objectSpread({}, state), {}, {
|
|
227
|
-
configureButtonTargetPos: configureButtonTargetPos,
|
|
228
|
-
decorations: _decorations
|
|
229
|
-
});
|
|
230
234
|
}
|
|
231
235
|
}
|
|
232
236
|
}
|
|
@@ -251,7 +255,7 @@ export var plugin = function plugin(dispatch, intl, editorAppearance) {
|
|
|
251
255
|
key: stateKey,
|
|
252
256
|
props: _objectSpread({
|
|
253
257
|
decorations: function decorations(state) {
|
|
254
|
-
if (fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
258
|
+
if (__livePage && fg('platform.linking-platform.smart-links-in-live-pages')) {
|
|
255
259
|
var _stateKey$getState;
|
|
256
260
|
var _ref = (_stateKey$getState = stateKey.getState(state)) !== null && _stateKey$getState !== void 0 ? _stateKey$getState : {},
|
|
257
261
|
decorations = _ref.decorations;
|
|
@@ -290,7 +294,7 @@ export var plugin = function plugin(dispatch, intl, editorAppearance) {
|
|
|
290
294
|
return false;
|
|
291
295
|
}
|
|
292
296
|
}
|
|
293
|
-
}, fg('platform.linking-platform.smart-links-in-live-pages') && {
|
|
297
|
+
}, __livePage && fg('platform.linking-platform.smart-links-in-live-pages') && {
|
|
294
298
|
markViews: {
|
|
295
299
|
link: function link(mark, view, inline) {
|
|
296
300
|
var toDOM = mark.type.spec.toDOM;
|
package/dist/types/commands.d.ts
CHANGED
|
@@ -7,11 +7,13 @@ import type { Command, EditorCommand, LinkInputType } from '@atlaskit/editor-com
|
|
|
7
7
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
8
8
|
export declare function setLinkHref(href: string, pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined, to?: number, isTabPressed?: boolean): Command;
|
|
9
9
|
export type UpdateLink = (href: string, text: string, pos: number, to?: number) => Command;
|
|
10
|
+
export declare function updateLinkEditorCommand(href: string, text: string, pos: number, to?: number): EditorCommand;
|
|
10
11
|
export declare function updateLink(href: string, text: string, pos: number, to?: number): Command;
|
|
11
12
|
export declare function insertLink(from: number, to: number, incomingHref: string, incomingTitle?: string, displayText?: string, source?: LinkInputType, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance, cardApiActions?: CardPluginActions): Command;
|
|
12
13
|
export type InsertLink = (inputMethod: LinkInputType, from: number, to: number, href: string, title?: string, displayText?: string, cardsAvailable?: boolean, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance) => Command;
|
|
13
14
|
export declare const insertLinkWithAnalytics: (inputMethod: LinkInputType, from: number, to: number, href: string, cardActions: CardPluginActions | undefined, editorAnalyticsApi: EditorAnalyticsAPI | undefined, title?: string, displayText?: string, cardsAvailable?: boolean, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance) => Command;
|
|
14
15
|
export declare function removeLink(pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
|
|
16
|
+
export declare function removeLinkEditorCommand(pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
|
|
15
17
|
export declare function editInsertedLink(editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
|
|
16
18
|
type InputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.SHORTCUT | INPUT_METHOD.INSERT_MENU;
|
|
17
19
|
export type ShowLinkToolbar = (inputMethod: InputMethod) => EditorCommand;
|
package/dist/types/plugin.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import type { HyperlinkState } from '@atlaskit/editor-common/link';
|
|
2
|
-
import type { HyperlinkPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorCommand, HyperlinkPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
4
|
import type { CardPlugin } from '@atlaskit/editor-plugin-card';
|
|
5
|
+
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
5
6
|
import type { HideLinkToolbar, InsertLink, ShowLinkToolbar, UpdateLink } from './commands';
|
|
6
7
|
export type HyperlinkPlugin = NextEditorPlugin<'hyperlink', {
|
|
7
8
|
pluginConfiguration: HyperlinkPluginOptions | undefined;
|
|
8
|
-
dependencies: [
|
|
9
|
+
dependencies: [
|
|
10
|
+
OptionalPlugin<AnalyticsPlugin>,
|
|
11
|
+
OptionalPlugin<CardPlugin>,
|
|
12
|
+
OptionalPlugin<EditorViewModePlugin>
|
|
13
|
+
];
|
|
9
14
|
actions: {
|
|
10
15
|
hideLinkToolbar: HideLinkToolbar;
|
|
11
16
|
insertLink: InsertLink;
|
|
@@ -24,6 +29,30 @@ export type HyperlinkPlugin = NextEditorPlugin<'hyperlink', {
|
|
|
24
29
|
* ```
|
|
25
30
|
*/
|
|
26
31
|
showLinkToolbar: ShowLinkToolbar;
|
|
32
|
+
/**
|
|
33
|
+
* EditorCommand to edit the current active link.
|
|
34
|
+
*
|
|
35
|
+
* Example:
|
|
36
|
+
*
|
|
37
|
+
* ```
|
|
38
|
+
* api.core.actions.execute(
|
|
39
|
+
* api.hyperlink.commands.updateLink(href, text)
|
|
40
|
+
* )
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
updateLink: (href: string, text: string) => EditorCommand;
|
|
44
|
+
/**
|
|
45
|
+
* EditorCommand to remove the current active link.
|
|
46
|
+
*
|
|
47
|
+
* Example:
|
|
48
|
+
*
|
|
49
|
+
* ```
|
|
50
|
+
* api.core.actions.execute(
|
|
51
|
+
* api.hyperlink.commands.removeLink()
|
|
52
|
+
* )
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
removeLink: () => EditorCommand;
|
|
27
56
|
};
|
|
28
57
|
sharedState: HyperlinkState | undefined;
|
|
29
58
|
}>;
|
|
@@ -2,7 +2,8 @@ import { type IntlShape } from 'react-intl-next';
|
|
|
2
2
|
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
3
3
|
import type { HyperlinkState } from '@atlaskit/editor-common/link';
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
-
import type { EditorAppearance } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { EditorAppearance, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
6
6
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import type { HyperlinkPlugin } from '../plugin';
|
|
7
8
|
export declare const stateKey: PluginKey<HyperlinkState>;
|
|
8
|
-
export declare const plugin: (dispatch: Dispatch, intl: IntlShape, editorAppearance?: EditorAppearance) => SafePlugin<HyperlinkState>;
|
|
9
|
+
export declare const plugin: (dispatch: Dispatch, intl: IntlShape, editorAppearance?: EditorAppearance, pluginInjectionApi?: ExtractInjectionAPI<HyperlinkPlugin> | undefined, __livePage?: boolean) => SafePlugin<HyperlinkState>;
|
|
@@ -7,11 +7,13 @@ import type { Command, EditorCommand, LinkInputType } from '@atlaskit/editor-com
|
|
|
7
7
|
import type { Transaction } from '@atlaskit/editor-prosemirror/state';
|
|
8
8
|
export declare function setLinkHref(href: string, pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined, to?: number, isTabPressed?: boolean): Command;
|
|
9
9
|
export type UpdateLink = (href: string, text: string, pos: number, to?: number) => Command;
|
|
10
|
+
export declare function updateLinkEditorCommand(href: string, text: string, pos: number, to?: number): EditorCommand;
|
|
10
11
|
export declare function updateLink(href: string, text: string, pos: number, to?: number): Command;
|
|
11
12
|
export declare function insertLink(from: number, to: number, incomingHref: string, incomingTitle?: string, displayText?: string, source?: LinkInputType, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance, cardApiActions?: CardPluginActions): Command;
|
|
12
13
|
export type InsertLink = (inputMethod: LinkInputType, from: number, to: number, href: string, title?: string, displayText?: string, cardsAvailable?: boolean, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance) => Command;
|
|
13
14
|
export declare const insertLinkWithAnalytics: (inputMethod: LinkInputType, from: number, to: number, href: string, cardActions: CardPluginActions | undefined, editorAnalyticsApi: EditorAnalyticsAPI | undefined, title?: string, displayText?: string, cardsAvailable?: boolean, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance) => Command;
|
|
14
15
|
export declare function removeLink(pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
|
|
16
|
+
export declare function removeLinkEditorCommand(pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined): EditorCommand;
|
|
15
17
|
export declare function editInsertedLink(editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
|
|
16
18
|
type InputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.SHORTCUT | INPUT_METHOD.INSERT_MENU;
|
|
17
19
|
export type ShowLinkToolbar = (inputMethod: InputMethod) => EditorCommand;
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import type { HyperlinkState } from '@atlaskit/editor-common/link';
|
|
2
|
-
import type { HyperlinkPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
2
|
+
import type { EditorCommand, HyperlinkPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
|
|
3
3
|
import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
|
|
4
4
|
import type { CardPlugin } from '@atlaskit/editor-plugin-card';
|
|
5
|
+
import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
|
|
5
6
|
import type { HideLinkToolbar, InsertLink, ShowLinkToolbar, UpdateLink } from './commands';
|
|
6
7
|
export type HyperlinkPlugin = NextEditorPlugin<'hyperlink', {
|
|
7
8
|
pluginConfiguration: HyperlinkPluginOptions | undefined;
|
|
8
9
|
dependencies: [
|
|
9
10
|
OptionalPlugin<AnalyticsPlugin>,
|
|
10
|
-
OptionalPlugin<CardPlugin
|
|
11
|
+
OptionalPlugin<CardPlugin>,
|
|
12
|
+
OptionalPlugin<EditorViewModePlugin>
|
|
11
13
|
];
|
|
12
14
|
actions: {
|
|
13
15
|
hideLinkToolbar: HideLinkToolbar;
|
|
@@ -27,6 +29,30 @@ export type HyperlinkPlugin = NextEditorPlugin<'hyperlink', {
|
|
|
27
29
|
* ```
|
|
28
30
|
*/
|
|
29
31
|
showLinkToolbar: ShowLinkToolbar;
|
|
32
|
+
/**
|
|
33
|
+
* EditorCommand to edit the current active link.
|
|
34
|
+
*
|
|
35
|
+
* Example:
|
|
36
|
+
*
|
|
37
|
+
* ```
|
|
38
|
+
* api.core.actions.execute(
|
|
39
|
+
* api.hyperlink.commands.updateLink(href, text)
|
|
40
|
+
* )
|
|
41
|
+
* ```
|
|
42
|
+
*/
|
|
43
|
+
updateLink: (href: string, text: string) => EditorCommand;
|
|
44
|
+
/**
|
|
45
|
+
* EditorCommand to remove the current active link.
|
|
46
|
+
*
|
|
47
|
+
* Example:
|
|
48
|
+
*
|
|
49
|
+
* ```
|
|
50
|
+
* api.core.actions.execute(
|
|
51
|
+
* api.hyperlink.commands.removeLink()
|
|
52
|
+
* )
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
removeLink: () => EditorCommand;
|
|
30
56
|
};
|
|
31
57
|
sharedState: HyperlinkState | undefined;
|
|
32
58
|
}>;
|
|
@@ -2,7 +2,8 @@ import { type IntlShape } from 'react-intl-next';
|
|
|
2
2
|
import type { Dispatch } from '@atlaskit/editor-common/event-dispatcher';
|
|
3
3
|
import type { HyperlinkState } from '@atlaskit/editor-common/link';
|
|
4
4
|
import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
|
|
5
|
-
import type { EditorAppearance } from '@atlaskit/editor-common/types';
|
|
5
|
+
import type { EditorAppearance, ExtractInjectionAPI } from '@atlaskit/editor-common/types';
|
|
6
6
|
import { PluginKey } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
+
import type { HyperlinkPlugin } from '../plugin';
|
|
7
8
|
export declare const stateKey: PluginKey<HyperlinkState>;
|
|
8
|
-
export declare const plugin: (dispatch: Dispatch, intl: IntlShape, editorAppearance?: EditorAppearance) => SafePlugin<HyperlinkState>;
|
|
9
|
+
export declare const plugin: (dispatch: Dispatch, intl: IntlShape, editorAppearance?: EditorAppearance, pluginInjectionApi?: ExtractInjectionAPI<HyperlinkPlugin> | undefined, __livePage?: boolean) => SafePlugin<HyperlinkState>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-hyperlink",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "Hyperlink plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -34,9 +34,10 @@
|
|
|
34
34
|
"dependencies": {
|
|
35
35
|
"@atlaskit/adf-schema": "^39.0.3",
|
|
36
36
|
"@atlaskit/analytics-next": "^9.3.0",
|
|
37
|
-
"@atlaskit/editor-common": "^86.
|
|
37
|
+
"@atlaskit/editor-common": "^86.3.0",
|
|
38
38
|
"@atlaskit/editor-plugin-analytics": "^1.4.0",
|
|
39
|
-
"@atlaskit/editor-plugin-card": "2.6.
|
|
39
|
+
"@atlaskit/editor-plugin-card": "2.6.4",
|
|
40
|
+
"@atlaskit/editor-plugin-editor-viewmode": "^2.0.0",
|
|
40
41
|
"@atlaskit/editor-prosemirror": "4.0.1",
|
|
41
42
|
"@atlaskit/icon": "^22.6.0",
|
|
42
43
|
"@atlaskit/platform-feature-flags": "^0.3.0",
|