@atlaskit/editor-plugin-hyperlink 2.3.22 → 2.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @atlaskit/editor-plugin-hyperlink
2
2
 
3
+ ## 2.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#121941](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/pull-requests/121941)
8
+ [`9db19df977817`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/9db19df977817) -
9
+ Added new commands for hyperlink plugin: removeLink and updateLink. These can be used on an active
10
+ link to remove the hyperlink mark or update the text/href on the link.
11
+
12
+ ## 2.3.23
13
+
14
+ ### Patch Changes
15
+
16
+ - Updated dependencies
17
+
3
18
  ## 2.3.22
4
19
 
5
20
  ### Patch Changes
@@ -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 setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
27
- return (0, _utils.filterCommand)((0, _link.isTextAtPos)(pos), function (state, dispatch) {
28
- var $pos = state.doc.resolve(pos);
29
- var node = state.doc.nodeAt(pos);
30
- var linkMark = state.schema.marks.link;
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 false;
43
+ return null;
35
44
  }
36
45
  var rightBound = to && pos !== to ? to : pos - $pos.textOffset + node.nodeSize;
37
- var tr = state.tr.removeMark(pos, rightBound, linkMark);
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
- if (dispatch) {
51
- dispatch(tr);
52
- }
53
- return true;
54
- });
59
+ return tr;
60
+ };
55
61
  }
56
- function updateLink(href, text, pos, to) {
57
- return function (state, dispatch) {
58
- var $pos = state.doc.resolve(pos);
59
- var node = state.doc.nodeAt(pos);
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 false;
71
+ return null;
62
72
  }
63
73
  var url = (0, _utils.normalizeUrl)(href);
64
- var mark = state.schema.marks.link.isInSet(node.marks);
65
- var linkMark = state.schema.marks.link;
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 false;
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
- if (dispatch) {
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 (_ref) {
185
- var tr = _ref.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
@@ -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$analytics2;
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$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
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
  },
@@ -75,15 +110,15 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
75
110
  }, {
76
111
  name: 'hyperlinkInputRule',
77
112
  plugin: function plugin(_ref3) {
78
- var _api$analytics3;
113
+ var _api$analytics4;
79
114
  var schema = _ref3.schema;
80
- return (0, _inputRule.createInputRulePlugin)(schema, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
115
+ 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
116
  }
82
117
  }, {
83
118
  name: 'hyperlinkKeymap',
84
119
  plugin: function plugin() {
85
- var _api$analytics4;
86
- return (0, _keymap.createKeymapPlugin)(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
120
+ var _api$analytics5;
121
+ return (0, _keymap.createKeymapPlugin)(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
87
122
  }
88
123
  }, {
89
124
  name: 'hyperlinkToolbarButtons',
@@ -110,13 +145,13 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
110
145
  return /*#__PURE__*/_react.default.createElement(_quickInsert.IconLink, null);
111
146
  },
112
147
  action: function action(insert, state) {
113
- var _api$analytics5, _api$analytics5$attac;
148
+ var _api$analytics6, _api$analytics6$attac;
114
149
  var tr = insert(undefined);
115
150
  tr.setMeta(_main.stateKey, {
116
151
  type: _link.LinkAction.SHOW_INSERT_TOOLBAR,
117
152
  inputMethod: _analytics.INPUT_METHOD.QUICK_INSERT
118
153
  });
119
- var analyticsAttached = api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 || (_api$analytics5 = _api$analytics5.actions) === null || _api$analytics5 === void 0 || (_api$analytics5$attac = _api$analytics5.attachAnalyticsEvent) === null || _api$analytics5$attac === void 0 ? void 0 : _api$analytics5$attac.call(_api$analytics5, {
154
+ 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
155
  action: _analytics.ACTION.INVOKED,
121
156
  actionSubject: _analytics.ACTION_SUBJECT.TYPEAHEAD,
122
157
  actionSubjectId: _analytics.ACTION_SUBJECT_ID.TYPEAHEAD_LINK,
@@ -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 { filterCommand as filter, getLinkCreationAnalyticsEvent, normalizeUrl } from '@atlaskit/editor-common/utils';
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
- export function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
9
- return filter(isTextAtPos(pos), (state, dispatch) => {
10
- const $pos = state.doc.resolve(pos);
11
- const node = state.doc.nodeAt(pos);
12
- const linkMark = state.schema.marks.link;
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 false;
24
+ return null;
17
25
  }
18
26
  const rightBound = to && pos !== to ? to : pos - $pos.textOffset + node.nodeSize;
19
- const tr = state.tr.removeMark(pos, rightBound, linkMark);
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
- if (dispatch) {
34
- dispatch(tr);
35
- }
36
- return true;
37
- });
41
+ return tr;
42
+ };
38
43
  }
39
- export function updateLink(href, text, pos, to) {
40
- return (state, dispatch) => {
41
- const $pos = state.doc.resolve(pos);
42
- const node = state.doc.nodeAt(pos);
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 false;
54
+ return null;
45
55
  }
46
56
  const url = normalizeUrl(href);
47
- const mark = state.schema.marks.link.isInSet(node.marks);
48
- const linkMark = state.schema.marks.link;
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 false;
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
- if (dispatch) {
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) {
@@ -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$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);
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
  },
@@ -63,14 +94,14 @@ export const hyperlinkPlugin = ({
63
94
  plugin: ({
64
95
  schema
65
96
  }) => {
66
- var _api$analytics3;
67
- return createInputRulePlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
97
+ var _api$analytics4;
98
+ 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
99
  }
69
100
  }, {
70
101
  name: 'hyperlinkKeymap',
71
102
  plugin: () => {
72
- var _api$analytics4;
73
- return createKeymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
103
+ var _api$analytics5;
104
+ return createKeymapPlugin(api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
74
105
  }
75
106
  }, {
76
107
  name: 'hyperlinkToolbarButtons',
@@ -95,13 +126,13 @@ export const hyperlinkPlugin = ({
95
126
  keyshortcut: tooltip(addLink),
96
127
  icon: () => /*#__PURE__*/React.createElement(IconLink, null),
97
128
  action(insert, state) {
98
- var _api$analytics5, _api$analytics5$actio, _api$analytics5$actio2;
129
+ var _api$analytics6, _api$analytics6$actio, _api$analytics6$actio2;
99
130
  const tr = insert(undefined);
100
131
  tr.setMeta(stateKey, {
101
132
  type: LinkAction.SHOW_INSERT_TOOLBAR,
102
133
  inputMethod: INPUT_METHOD.QUICK_INSERT
103
134
  });
104
- const analyticsAttached = api === null || api === void 0 ? void 0 : (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : (_api$analytics5$actio = _api$analytics5.actions) === null || _api$analytics5$actio === void 0 ? void 0 : (_api$analytics5$actio2 = _api$analytics5$actio.attachAnalyticsEvent) === null || _api$analytics5$actio2 === void 0 ? void 0 : _api$analytics5$actio2.call(_api$analytics5$actio, {
135
+ 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
136
  action: ACTION.INVOKED,
106
137
  actionSubject: ACTION_SUBJECT.TYPEAHEAD,
107
138
  actionSubjectId: ACTION_SUBJECT_ID.TYPEAHEAD_LINK,
@@ -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 { filterCommand as filter, getLinkCreationAnalyticsEvent, normalizeUrl } from '@atlaskit/editor-common/utils';
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
- export function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
12
- return filter(isTextAtPos(pos), function (state, dispatch) {
13
- var $pos = state.doc.resolve(pos);
14
- var node = state.doc.nodeAt(pos);
15
- var linkMark = state.schema.marks.link;
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 false;
26
+ return null;
20
27
  }
21
28
  var rightBound = to && pos !== to ? to : pos - $pos.textOffset + node.nodeSize;
22
- var tr = state.tr.removeMark(pos, rightBound, linkMark);
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
- if (dispatch) {
36
- dispatch(tr);
37
- }
38
- return true;
39
- });
42
+ return tr;
43
+ };
40
44
  }
41
- export function updateLink(href, text, pos, to) {
42
- return function (state, dispatch) {
43
- var $pos = state.doc.resolve(pos);
44
- var node = state.doc.nodeAt(pos);
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 false;
54
+ return null;
47
55
  }
48
56
  var url = normalizeUrl(href);
49
- var mark = state.schema.marks.link.isInSet(node.marks);
50
- var linkMark = state.schema.marks.link;
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 false;
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
- if (dispatch) {
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 (_ref) {
170
- var tr = _ref.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
@@ -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$analytics2;
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$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
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
  },
@@ -68,15 +103,15 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
68
103
  }, {
69
104
  name: 'hyperlinkInputRule',
70
105
  plugin: function plugin(_ref3) {
71
- var _api$analytics3;
106
+ var _api$analytics4;
72
107
  var schema = _ref3.schema;
73
- return createInputRulePlugin(schema, api === null || api === void 0 || (_api$analytics3 = api.analytics) === null || _api$analytics3 === void 0 ? void 0 : _api$analytics3.actions);
108
+ return createInputRulePlugin(schema, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
74
109
  }
75
110
  }, {
76
111
  name: 'hyperlinkKeymap',
77
112
  plugin: function plugin() {
78
- var _api$analytics4;
79
- return createKeymapPlugin(api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
113
+ var _api$analytics5;
114
+ return createKeymapPlugin(api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 ? void 0 : _api$analytics5.actions);
80
115
  }
81
116
  }, {
82
117
  name: 'hyperlinkToolbarButtons',
@@ -103,13 +138,13 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
103
138
  return /*#__PURE__*/React.createElement(IconLink, null);
104
139
  },
105
140
  action: function action(insert, state) {
106
- var _api$analytics5, _api$analytics5$attac;
141
+ var _api$analytics6, _api$analytics6$attac;
107
142
  var tr = insert(undefined);
108
143
  tr.setMeta(stateKey, {
109
144
  type: LinkAction.SHOW_INSERT_TOOLBAR,
110
145
  inputMethod: INPUT_METHOD.QUICK_INSERT
111
146
  });
112
- var analyticsAttached = api === null || api === void 0 || (_api$analytics5 = api.analytics) === null || _api$analytics5 === void 0 || (_api$analytics5 = _api$analytics5.actions) === null || _api$analytics5 === void 0 || (_api$analytics5$attac = _api$analytics5.attachAnalyticsEvent) === null || _api$analytics5$attac === void 0 ? void 0 : _api$analytics5$attac.call(_api$analytics5, {
147
+ 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
148
  action: ACTION.INVOKED,
114
149
  actionSubject: ACTION_SUBJECT.TYPEAHEAD,
115
150
  actionSubjectId: ACTION_SUBJECT_ID.TYPEAHEAD_LINK,
@@ -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,5 +1,5 @@
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
5
  import type { HideLinkToolbar, InsertLink, ShowLinkToolbar, UpdateLink } from './commands';
@@ -24,6 +24,30 @@ export type HyperlinkPlugin = NextEditorPlugin<'hyperlink', {
24
24
  * ```
25
25
  */
26
26
  showLinkToolbar: ShowLinkToolbar;
27
+ /**
28
+ * EditorCommand to edit the current active link.
29
+ *
30
+ * Example:
31
+ *
32
+ * ```
33
+ * api.core.actions.execute(
34
+ * api.hyperlink.commands.updateLink(href, text)
35
+ * )
36
+ * ```
37
+ */
38
+ updateLink: (href: string, text: string) => EditorCommand;
39
+ /**
40
+ * EditorCommand to remove the current active link.
41
+ *
42
+ * Example:
43
+ *
44
+ * ```
45
+ * api.core.actions.execute(
46
+ * api.hyperlink.commands.removeLink()
47
+ * )
48
+ * ```
49
+ */
50
+ removeLink: () => EditorCommand;
27
51
  };
28
52
  sharedState: HyperlinkState | undefined;
29
53
  }>;
@@ -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,5 +1,5 @@
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
5
  import type { HideLinkToolbar, InsertLink, ShowLinkToolbar, UpdateLink } from './commands';
@@ -27,6 +27,30 @@ export type HyperlinkPlugin = NextEditorPlugin<'hyperlink', {
27
27
  * ```
28
28
  */
29
29
  showLinkToolbar: ShowLinkToolbar;
30
+ /**
31
+ * EditorCommand to edit the current active link.
32
+ *
33
+ * Example:
34
+ *
35
+ * ```
36
+ * api.core.actions.execute(
37
+ * api.hyperlink.commands.updateLink(href, text)
38
+ * )
39
+ * ```
40
+ */
41
+ updateLink: (href: string, text: string) => EditorCommand;
42
+ /**
43
+ * EditorCommand to remove the current active link.
44
+ *
45
+ * Example:
46
+ *
47
+ * ```
48
+ * api.core.actions.execute(
49
+ * api.hyperlink.commands.removeLink()
50
+ * )
51
+ * ```
52
+ */
53
+ removeLink: () => EditorCommand;
30
54
  };
31
55
  sharedState: HyperlinkState | undefined;
32
56
  }>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-hyperlink",
3
- "version": "2.3.22",
3
+ "version": "2.4.0",
4
4
  "description": "Hyperlink plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -36,7 +36,7 @@
36
36
  "@atlaskit/analytics-next": "^9.3.0",
37
37
  "@atlaskit/editor-common": "^86.2.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^1.4.0",
39
- "@atlaskit/editor-plugin-card": "2.6.2",
39
+ "@atlaskit/editor-plugin-card": "2.6.3",
40
40
  "@atlaskit/editor-prosemirror": "4.0.1",
41
41
  "@atlaskit/icon": "^22.6.0",
42
42
  "@atlaskit/platform-feature-flags": "^0.3.0",