@atlaskit/editor-plugin-hyperlink 1.7.2 → 2.0.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.
@@ -85,7 +85,9 @@ export function HyperlinkAddToolbarWithState(_ref) {
85
85
  onClose: onClose,
86
86
  onEscapeCallback: onEscapeCallback,
87
87
  onClickAwayCallback: onClickAwayCallback,
88
- hyperlinkPluginState: hyperlinkState
88
+ timesViewed: hyperlinkState.timesViewed,
89
+ inputMethod: hyperlinkState.inputMethod,
90
+ searchSessionId: hyperlinkState.searchSessionId
89
91
  });
90
92
  }
91
93
  var getSettingsButtonGroup = function getSettingsButtonGroup(intl, editorAnalyticsApi) {
@@ -101,34 +103,15 @@ var getSettingsButtonGroup = function getSettingsButtonGroup(intl, editorAnalyti
101
103
  target: '_blank'
102
104
  }];
103
105
  };
104
- export var mergeAddedItems = function mergeAddedItems(link) {
105
- for (var _len = arguments.length, handlerParams = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
106
- handlerParams[_key - 1] = arguments[_key];
107
- }
108
- return function (items, toolbarItemsState) {
109
- var positions = toolbarItemsState === null || toolbarItemsState === void 0 ? void 0 : toolbarItemsState.items_next;
110
- if (!positions) {
111
- return items;
112
- }
113
- var start = positions.start;
114
- var end = positions.end;
115
- var reduceItems = function reduceItems() {
116
- var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
117
- return items.reduce(function (acc, fn) {
118
- return [].concat(_toConsumableArray(acc), _toConsumableArray(fn.apply(void 0, handlerParams.concat([link]))));
119
- }, []);
120
- };
121
- return [].concat(_toConsumableArray(reduceItems(start)), _toConsumableArray(items), _toConsumableArray(reduceItems(end)));
122
- };
123
- };
124
106
  export var getToolbarConfig = function getToolbarConfig(options, pluginInjectionApi) {
125
107
  return function (state, intl, providerFactory) {
126
- var _pluginInjectionApi$a, _options$lpLinkPicker;
108
+ var _pluginInjectionApi$c, _pluginInjectionApi$a, _options$lpLinkPicker;
127
109
  if (options.disableFloatingToolbar) {
128
110
  return;
129
111
  }
130
112
  var formatMessage = intl.formatMessage;
131
113
  var linkState = stateKey.getState(state);
114
+ var editorCardActions = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c = pluginInjectionApi.card) === null || _pluginInjectionApi$c === void 0 ? void 0 : _pluginInjectionApi$c.actions;
132
115
  var editorAnalyticsApi = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions;
133
116
  var lpLinkPicker = (_options$lpLinkPicker = options.lpLinkPicker) !== null && _options$lpLinkPicker !== void 0 ? _options$lpLinkPicker : true;
134
117
  if (linkState && linkState.activeLinkMark) {
@@ -145,7 +128,7 @@ export var getToolbarConfig = function getToolbarConfig(options, pluginInjection
145
128
  switch (activeLinkMark.type) {
146
129
  case 'EDIT':
147
130
  {
148
- var _toolbarKey$getState$, _toolbarKey$getState;
131
+ var _pluginInjectionApi$c2, _cardActions$getStart, _cardActions$getEndin;
149
132
  var pos = activeLinkMark.pos,
150
133
  node = activeLinkMark.node;
151
134
  var linkMark = node.marks.filter(function (mark) {
@@ -164,7 +147,8 @@ export var getToolbarConfig = function getToolbarConfig(options, pluginInjection
164
147
  if (activeLinkMark.node.text) {
165
148
  metadata.title = activeLinkMark.node.text;
166
149
  }
167
- var baseItems = [].concat(_toConsumableArray((_toolbarKey$getState$ = (_toolbarKey$getState = toolbarKey.getState(state)) === null || _toolbarKey$getState === void 0 ? void 0 : _toolbarKey$getState.items(state, intl, providerFactory, link)) !== null && _toolbarKey$getState$ !== void 0 ? _toolbarKey$getState$ : []), [{
150
+ var cardActions = pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$c2 = pluginInjectionApi.card) === null || _pluginInjectionApi$c2 === void 0 ? void 0 : _pluginInjectionApi$c2.actions;
151
+ var startingToolbarItems = (_cardActions$getStart = cardActions === null || cardActions === void 0 ? void 0 : cardActions.getStartingToolbarItems(intl, link, providerFactory, editInsertedLink(editorAnalyticsApi), metadata)) !== null && _cardActions$getStart !== void 0 ? _cardActions$getStart : [{
168
152
  id: 'editor.link.edit',
169
153
  testId: 'editor.link.edit',
170
154
  type: 'button',
@@ -172,7 +156,8 @@ export var getToolbarConfig = function getToolbarConfig(options, pluginInjection
172
156
  title: editLink,
173
157
  showTitle: true,
174
158
  metadata: metadata
175
- }, {
159
+ }];
160
+ var items = [].concat(_toConsumableArray(startingToolbarItems), [{
176
161
  type: 'separator'
177
162
  }, {
178
163
  id: 'editor.link.openLink',
@@ -209,8 +194,7 @@ export var getToolbarConfig = function getToolbarConfig(options, pluginInjection
209
194
  formatMessage: formatMessage,
210
195
  markType: state.schema.marks.link
211
196
  }]
212
- }], _toConsumableArray(getBooleanFF('platform.editor.card.inject-settings-button') ? [] : getSettingsButtonGroup(intl, editorAnalyticsApi)));
213
- var items = getBooleanFF('platform.editor.card.inject-settings-button') ? mergeAddedItems(link, state, intl, providerFactory)(baseItems, toolbarKey.getState(state)) : baseItems;
197
+ }], _toConsumableArray((_cardActions$getEndin = cardActions === null || cardActions === void 0 ? void 0 : cardActions.getEndingToolbarItems(intl, link)) !== null && _cardActions$getEndin !== void 0 ? _cardActions$getEndin : []), _toConsumableArray(getBooleanFF('platform.editor.card.inject-settings-button') ? [] : getSettingsButtonGroup(intl, editorAnalyticsApi)));
214
198
  return _objectSpread(_objectSpread({}, hyperLinkToolbar), {}, {
215
199
  height: 32,
216
200
  width: 250,
@@ -254,22 +238,22 @@ export var getToolbarConfig = function getToolbarConfig(options, pluginInjection
254
238
  onCancel: function onCancel() {
255
239
  return view.focus();
256
240
  },
257
- onEscapeCallback: onEscapeCallback,
241
+ onEscapeCallback: onEscapeCallback(editorCardActions),
258
242
  onClickAwayCallback: onClickAwayCallback,
259
243
  onSubmit: function onSubmit(href) {
260
- var _toolbarKey$getState$2, _toolbarKey$getState2;
244
+ var _toolbarKey$getState$, _toolbarKey$getState;
261
245
  var title = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
262
246
  var displayText = arguments.length > 2 ? arguments[2] : undefined;
263
247
  var inputMethod = arguments.length > 3 ? arguments[3] : undefined;
264
248
  var analytic = arguments.length > 4 ? arguments[4] : undefined;
265
249
  var isEdit = isEditLink(activeLinkMark);
266
250
  var action = isEdit ? ACTION.UPDATED : ACTION.INSERTED;
267
- var skipAnalytics = (_toolbarKey$getState$2 = (_toolbarKey$getState2 = toolbarKey.getState(state)) === null || _toolbarKey$getState2 === void 0 ? void 0 : _toolbarKey$getState2.skipAnalytics) !== null && _toolbarKey$getState$2 !== void 0 ? _toolbarKey$getState$2 : false;
251
+ var skipAnalytics = (_toolbarKey$getState$ = (_toolbarKey$getState = toolbarKey.getState(state)) === null || _toolbarKey$getState === void 0 ? void 0 : _toolbarKey$getState.skipAnalytics) !== null && _toolbarKey$getState$ !== void 0 ? _toolbarKey$getState$ : false;
268
252
  var command = isEdit ? commandWithMetadata(updateLink(href, displayText || title, activeLinkMark.pos), {
269
253
  action: action,
270
254
  inputMethod: inputMethod,
271
255
  sourceEvent: analytic
272
- }) : insertLinkWithAnalytics(inputMethod, activeLinkMark.from, activeLinkMark.to, href, editorAnalyticsApi, title, displayText, skipAnalytics, analytic);
256
+ }) : insertLinkWithAnalytics(inputMethod, activeLinkMark.from, activeLinkMark.to, href, editorCardActions, editorAnalyticsApi, title, displayText, skipAnalytics, analytic);
273
257
  command(view.state, view.dispatch, view);
274
258
  view.focus();
275
259
  }
@@ -8,7 +8,6 @@ import { isTextAtPos, LinkAction } from '@atlaskit/editor-common/link';
8
8
  import { filterCommand as filter, getLinkCreationAnalyticsEvent, normalizeUrl } from '@atlaskit/editor-common/utils';
9
9
  import { Selection } from '@atlaskit/editor-prosemirror/state';
10
10
  import { stateKey } from './pm-plugins/main';
11
- import { toolbarKey } from './pm-plugins/toolbar-buttons';
12
11
  export function setLinkHref(href, pos, editorAnalyticsApi, to, isTabPressed) {
13
12
  return filter(isTextAtPos(pos), function (state, dispatch) {
14
13
  var $pos = state.doc.resolve(pos);
@@ -75,6 +74,7 @@ export function updateLink(href, text, pos, to) {
75
74
  }
76
75
  export function insertLink(from, to, incomingHref, incomingTitle, displayText, source, sourceEvent) {
77
76
  var appearance = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : 'inline';
77
+ var cardApiActions = arguments.length > 8 ? arguments[8] : undefined;
78
78
  return function (state, dispatch) {
79
79
  var link = state.schema.marks.link;
80
80
  var tr = state.tr;
@@ -99,8 +99,7 @@ export function insertLink(from, to, incomingHref, incomingTitle, displayText, s
99
99
  }));
100
100
  tr.setSelection(Selection.near(tr.doc.resolve(markEnd)));
101
101
  if (!displayText || displayText === incomingHref) {
102
- var _toolbarKey$getState;
103
- var queueCardsFromChangedTr = (_toolbarKey$getState = toolbarKey.getState(state)) === null || _toolbarKey$getState === void 0 ? void 0 : _toolbarKey$getState.onInsertLinkCallback;
102
+ var queueCardsFromChangedTr = cardApiActions === null || cardApiActions === void 0 ? void 0 : cardApiActions.queueCardsFromChangedTr;
104
103
  if (queueCardsFromChangedTr) {
105
104
  queueCardsFromChangedTr === null || queueCardsFromChangedTr === void 0 || queueCardsFromChangedTr(state, tr, source, ACTION.INSERTED, false, sourceEvent, appearance);
106
105
  } else {
@@ -137,15 +136,15 @@ export function insertLink(from, to, incomingHref, incomingTitle, displayText, s
137
136
  return false;
138
137
  };
139
138
  }
140
- export var insertLinkWithAnalytics = function insertLinkWithAnalytics(inputMethod, from, to, href, editorAnalyticsApi, title, displayText) {
141
- var cardsAvailable = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : false;
142
- var sourceEvent = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : undefined;
143
- var appearance = arguments.length > 9 ? arguments[9] : undefined;
139
+ export var insertLinkWithAnalytics = function insertLinkWithAnalytics(inputMethod, from, to, href, cardActions, editorAnalyticsApi, title, displayText) {
140
+ var cardsAvailable = arguments.length > 8 && arguments[8] !== undefined ? arguments[8] : false;
141
+ var sourceEvent = arguments.length > 9 && arguments[9] !== undefined ? arguments[9] : undefined;
142
+ var appearance = arguments.length > 10 ? arguments[10] : undefined;
144
143
  // If smart cards are available, we send analytics for hyperlinks when a smart link is rejected.
145
144
  if (cardsAvailable && !title && !displayText) {
146
- return insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance);
145
+ return insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance, cardActions);
147
146
  }
148
- return withAnalytics(editorAnalyticsApi, getLinkCreationAnalyticsEvent(inputMethod, href))(insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance));
147
+ return withAnalytics(editorAnalyticsApi, getLinkCreationAnalyticsEvent(inputMethod, href))(insertLink(from, to, href, title, displayText, inputMethod, sourceEvent, appearance, cardActions));
149
148
  };
150
149
  export function removeLink(pos, editorAnalyticsApi) {
151
150
  return commandWithMetadata(setLinkHref('', pos, editorAnalyticsApi), {
@@ -198,16 +197,18 @@ export var hideLinkToolbarSetMeta = function hideLinkToolbarSetMeta(tr) {
198
197
  type: LinkAction.HIDE_TOOLBAR
199
198
  });
200
199
  };
201
- export var onEscapeCallback = function onEscapeCallback(state, dispatch) {
202
- var _toolbarKey$getState2, _toolbarKey$getState3;
203
- var tr = state.tr;
204
- hideLinkToolbarSetMeta(tr);
205
- (_toolbarKey$getState2 = toolbarKey.getState(state)) === null || _toolbarKey$getState2 === void 0 || (_toolbarKey$getState3 = _toolbarKey$getState2.onEscapeCallback) === null || _toolbarKey$getState3 === void 0 || _toolbarKey$getState3.call(_toolbarKey$getState2, tr);
206
- if (dispatch) {
207
- dispatch(tr);
208
- return true;
209
- }
210
- return false;
200
+ export var onEscapeCallback = function onEscapeCallback(cardActions) {
201
+ return function (state, dispatch) {
202
+ var _cardActions$hideLink;
203
+ var tr = state.tr;
204
+ hideLinkToolbarSetMeta(tr);
205
+ cardActions === null || cardActions === void 0 || (_cardActions$hideLink = cardActions.hideLinkToolbar) === null || _cardActions$hideLink === void 0 || _cardActions$hideLink.call(cardActions, tr);
206
+ if (dispatch) {
207
+ dispatch(tr);
208
+ return true;
209
+ }
210
+ return false;
211
+ };
211
212
  };
212
213
  export var onClickAwayCallback = function onClickAwayCallback(state, dispatch) {
213
214
  if (dispatch) {
@@ -10,7 +10,7 @@ import fakeCursorToolbarPlugin from './pm-plugins/fake-cursor-for-toolbar';
10
10
  import { createInputRulePlugin } from './pm-plugins/input-rule';
11
11
  import { createKeymapPlugin } from './pm-plugins/keymap';
12
12
  import { plugin as _plugin, stateKey } from './pm-plugins/main';
13
- import { addToolbarItems, prependToolbarButtons, toolbarButtonsPlugin } from './pm-plugins/toolbar-buttons';
13
+ import { toolbarButtonsPlugin } from './pm-plugins/toolbar-buttons';
14
14
  import { getToolbarConfig } from './Toolbar';
15
15
  /**
16
16
  * Hyperlink plugin to be added to an `EditorPresetBuilder` and used with `ComposableEditor`
@@ -36,15 +36,13 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
36
36
  }
37
37
  },
38
38
  actions: {
39
- prependToolbarButtons: prependToolbarButtons,
40
- addToolbarItems: addToolbarItems,
41
39
  hideLinkToolbar: hideLinkToolbarSetMeta,
42
40
  insertLink: function insertLink(inputMethod, from, to, href, title, displayText) {
43
- var _api$analytics2;
41
+ var _api$card, _api$analytics2;
44
42
  var cardsAvailable = arguments.length > 6 && arguments[6] !== undefined ? arguments[6] : false;
45
43
  var sourceEvent = arguments.length > 7 && arguments[7] !== undefined ? arguments[7] : undefined;
46
44
  var appearance = arguments.length > 8 ? arguments[8] : undefined;
47
- return insertLinkWithAnalytics(inputMethod, from, to, href, api === null || api === void 0 || (_api$analytics2 = api.analytics) === null || _api$analytics2 === void 0 ? void 0 : _api$analytics2.actions, title, displayText, cardsAvailable, sourceEvent, appearance);
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);
48
46
  },
49
47
  updateLink: updateLink
50
48
  },
@@ -81,7 +79,13 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
81
79
  }
82
80
  }, {
83
81
  name: 'hyperlinkToolbarButtons',
84
- plugin: toolbarButtonsPlugin
82
+ plugin: function plugin() {
83
+ var _api$card2;
84
+ var hasCard = !!(api !== null && api !== void 0 && (_api$card2 = api.card) !== null && _api$card2 !== void 0 && _api$card2.actions);
85
+ return toolbarButtonsPlugin(hasCard ? {
86
+ skipAnalytics: true
87
+ } : undefined);
88
+ }
85
89
  }];
86
90
  },
87
91
  pluginsOptions: {
@@ -1,79 +1,14 @@
1
- import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
- import _typeof from "@babel/runtime/helpers/typeof";
4
- 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; }
5
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
8
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
-
10
- /**
11
- * Relative placement of an item
12
- */
13
-
14
3
  export var toolbarKey = new PluginKey('hyperlinkToolbarItems');
15
- export var prependToolbarButtons = function prependToolbarButtons(_ref) {
16
- var items = _ref.items,
17
- onEscapeCallback = _ref.onEscapeCallback,
18
- onInsertLinkCallback = _ref.onInsertLinkCallback,
19
- skipAnalytics = _ref.skipAnalytics,
20
- view = _ref.view;
21
- var tr = view.state.tr,
22
- dispatch = view.dispatch;
23
- tr.setMeta(toolbarKey, {
24
- items: items,
25
- onEscapeCallback: onEscapeCallback,
26
- onInsertLinkCallback: onInsertLinkCallback,
27
- skipAnalytics: skipAnalytics
28
- });
29
- dispatch(tr);
30
- };
31
- export var addToolbarItems = function addToolbarItems(_ref2) {
32
- var items = _ref2.items,
33
- placement = _ref2.placement,
34
- view = _ref2.view;
35
- var tr = view.state.tr,
36
- dispatch = view.dispatch;
37
- tr.setMeta(toolbarKey, {
38
- items: items,
39
- placement: placement
40
- });
41
- dispatch(tr);
42
- };
43
- var VALID_PLACEMENTS = ['start', 'end'];
44
- var isValidPlacement = function isValidPlacement(placement) {
45
- return VALID_PLACEMENTS.some(function (p) {
46
- return p === placement;
47
- });
48
- };
49
- export var toolbarButtonsPlugin = function toolbarButtonsPlugin() {
4
+ export var toolbarButtonsPlugin = function toolbarButtonsPlugin(initialState) {
50
5
  return new SafePlugin({
51
6
  key: toolbarKey,
52
7
  state: {
53
8
  init: function init(_, __) {
54
- return undefined;
9
+ return initialState;
55
10
  },
56
- apply: getBooleanFF('platform.editor.card.inject-settings-button') ? function (tr, pluginState) {
57
- var metaState = tr.getMeta(toolbarKey);
58
- if (metaState) {
59
- if (_typeof(metaState) === 'object' && 'placement' in metaState) {
60
- var _pluginState$items_ne;
61
- var placement = metaState.placement;
62
- if (!isValidPlacement(placement)) {
63
- return pluginState;
64
- }
65
- var previous = (_pluginState$items_ne = pluginState === null || pluginState === void 0 ? void 0 : pluginState.items_next) !== null && _pluginState$items_ne !== void 0 ? _pluginState$items_ne : {
66
- start: [],
67
- end: []
68
- };
69
- return _objectSpread(_objectSpread({}, pluginState), {}, {
70
- items_next: _objectSpread(_objectSpread({}, previous), {}, _defineProperty({}, placement, [].concat(_toConsumableArray(previous[placement]), [metaState.items])))
71
- });
72
- }
73
- return metaState;
74
- }
75
- return pluginState;
76
- } : function (tr, pluginState) {
11
+ apply: function apply(tr, pluginState) {
77
12
  var metaState = tr.getMeta(toolbarKey);
78
13
  if (metaState) {
79
14
  return metaState;
@@ -1,12 +1,8 @@
1
1
  /// <reference types="react" />
2
- import type { IntlShape } from 'react-intl-next';
3
2
  import type { HyperlinkAddToolbarProps } from '@atlaskit/editor-common/link';
4
- import type { Command, ExtractInjectionAPI, FloatingToolbarHandler, FloatingToolbarItem, HyperlinkPluginOptions } from '@atlaskit/editor-common/types';
5
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
6
- import { type HyperlinkToolbarItemsState } from './pm-plugins/toolbar-buttons';
3
+ import type { ExtractInjectionAPI, FloatingToolbarHandler, HyperlinkPluginOptions } from '@atlaskit/editor-common/types';
7
4
  import type { hyperlinkPlugin } from './index';
8
5
  export declare function HyperlinkAddToolbarWithState({ linkPickerOptions, onSubmit, displayText, displayUrl, providerFactory, view, onCancel, invokeMethod, lpLinkPicker, onClose, onEscapeCallback, onClickAwayCallback, pluginInjectionApi, }: HyperlinkAddToolbarProps & {
9
6
  pluginInjectionApi: any;
10
7
  }): JSX.Element;
11
- export declare const mergeAddedItems: (link: string, state: EditorState, intl: IntlShape, providerFactory: import("@atlaskit/editor-common/provider-factory").ProviderFactory) => (items: Array<FloatingToolbarItem<Command>>, toolbarItemsState: HyperlinkToolbarItemsState | undefined) => Array<FloatingToolbarItem<Command>>;
12
8
  export declare const getToolbarConfig: (options: HyperlinkPluginOptions, pluginInjectionApi: ExtractInjectionAPI<typeof hyperlinkPlugin> | undefined) => FloatingToolbarHandler;
@@ -1,15 +1,16 @@
1
1
  import type { UIAnalyticsEvent } from '@atlaskit/analytics-next';
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { type CardPluginActions } from '@atlaskit/editor-common/card';
4
5
  import type { CardAppearance } from '@atlaskit/editor-common/provider-factory';
5
6
  import type { Command, EditorCommand, LinkInputType } from '@atlaskit/editor-common/types';
6
7
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
7
8
  export declare function setLinkHref(href: string, pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined, to?: number, isTabPressed?: boolean): Command;
8
9
  export type UpdateLink = (href: string, text: string, pos: number, to?: number) => Command;
9
10
  export declare function updateLink(href: string, text: string, pos: number, to?: number): Command;
10
- export declare function insertLink(from: number, to: number, incomingHref: string, incomingTitle?: string, displayText?: string, source?: LinkInputType, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance): Command;
11
+ 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;
11
12
  export type InsertLink = (inputMethod: LinkInputType, from: number, to: number, href: string, title?: string, displayText?: string, cardsAvailable?: boolean, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance) => Command;
12
- export declare const insertLinkWithAnalytics: (inputMethod: LinkInputType, from: number, to: number, href: string, editorAnalyticsApi: EditorAnalyticsAPI | undefined, title?: string, displayText?: string, cardsAvailable?: boolean, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance) => Command;
13
+ 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;
13
14
  export declare function removeLink(pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
14
15
  export declare function editInsertedLink(editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
15
16
  type InputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.SHORTCUT | INPUT_METHOD.INSERT_MENU;
@@ -18,6 +19,6 @@ export declare function showLinkToolbar(inputMethod: InputMethod, editorAnalytic
18
19
  export declare function hideLinkToolbar(): Command;
19
20
  export type HideLinkToolbar = (tr: Transaction) => Transaction;
20
21
  export declare const hideLinkToolbarSetMeta: HideLinkToolbar;
21
- export declare const onEscapeCallback: Command;
22
+ export declare const onEscapeCallback: (cardActions?: CardPluginActions) => Command;
22
23
  export declare const onClickAwayCallback: Command;
23
24
  export {};
@@ -1,4 +1,3 @@
1
1
  export { hyperlinkPlugin } from './plugin';
2
2
  export type { HyperlinkPlugin } from './plugin';
3
3
  export type { HideLinkToolbar, ShowLinkToolbar, InsertLink, UpdateLink, } from './commands';
4
- export type { PrependToolbarButtons, AddToolbarItems, } from './pm-plugins/toolbar-buttons';
@@ -1,25 +1,12 @@
1
1
  import type { HyperlinkState } from '@atlaskit/editor-common/link';
2
2
  import type { HyperlinkPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
3
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
+ import type { CardPlugin } from '@atlaskit/editor-plugin-card';
4
5
  import type { HideLinkToolbar, InsertLink, ShowLinkToolbar, UpdateLink } from './commands';
5
- import type { AddToolbarItems, PrependToolbarButtons } from './pm-plugins/toolbar-buttons';
6
6
  export type HyperlinkPlugin = NextEditorPlugin<'hyperlink', {
7
7
  pluginConfiguration: HyperlinkPluginOptions | undefined;
8
- dependencies: [OptionalPlugin<AnalyticsPlugin>];
8
+ dependencies: [OptionalPlugin<AnalyticsPlugin>, OptionalPlugin<CardPlugin>];
9
9
  actions: {
10
- /**
11
- * Add items to the left of the hyperlink floating toolbar
12
- * @param props
13
- * -
14
- * - items: Retrieve floating toolbar items to add
15
- * - onEscapeCallback (optional): To be called when the link picker is escaped.
16
- * - onInsertLinkCallback (optional): To be called when a link is inserted and it can be changed into a card.
17
- */
18
- prependToolbarButtons: PrependToolbarButtons;
19
- /**
20
- * Add items before or after any default hyperlink floating toolbar items
21
- */
22
- addToolbarItems: AddToolbarItems;
23
10
  hideLinkToolbar: HideLinkToolbar;
24
11
  insertLink: InsertLink;
25
12
  updateLink: UpdateLink;
@@ -1,21 +1,6 @@
1
- import type { IntlShape } from 'react-intl-next';
2
- import type { QueueCardsFromTransactionAction } from '@atlaskit/editor-common/card';
3
- import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
4
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
- import type { FloatingToolbarItem } from '@atlaskit/editor-common/types';
6
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
7
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
8
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
- /**
10
- * Relative placement of an item
11
- */
12
- type PlacementType = 'start' | 'end';
13
- type AdditionalToolbarItems = Record<PlacementType, GetToolbarItems[]>;
14
3
  export type HyperlinkToolbarItemsState = {
15
- items: GetToolbarItems;
16
- items_next?: AdditionalToolbarItems;
17
- onEscapeCallback: ((tr: Transaction) => Transaction) | undefined;
18
- onInsertLinkCallback: QueueCardsFromTransactionAction | undefined;
19
4
  /**
20
5
  * If you are mounting your own items to the hyperlink toolbar you may decide
21
6
  * you want to replace the hyperlink analytics with your own
@@ -24,18 +9,6 @@ export type HyperlinkToolbarItemsState = {
24
9
  skipAnalytics?: boolean;
25
10
  };
26
11
  export declare const toolbarKey: PluginKey<HyperlinkToolbarItemsState | undefined>;
27
- type GetToolbarItems = (state: EditorState, intl: IntlShape, providerFactory: ProviderFactory, link: string) => FloatingToolbarItem<any>[];
28
- interface PrependToolbarButtonsProps extends HyperlinkToolbarItemsState {
29
- view: EditorView;
30
- }
31
- export type PrependToolbarButtons = (props: PrependToolbarButtonsProps) => void;
32
- export declare const prependToolbarButtons: ({ items, onEscapeCallback, onInsertLinkCallback, skipAnalytics, view, }: PrependToolbarButtonsProps) => void;
33
- type AddToolbarItemsProps = {
34
- items: GetToolbarItems;
35
- placement: PlacementType;
36
- view: EditorView;
37
- };
38
- export type AddToolbarItems = (props: AddToolbarItemsProps) => void;
39
- export declare const addToolbarItems: ({ items, placement, view, }: AddToolbarItemsProps) => void;
40
- export declare const toolbarButtonsPlugin: () => SafePlugin<HyperlinkToolbarItemsState | undefined>;
41
- export {};
12
+ export declare const toolbarButtonsPlugin: (initialState?: {
13
+ skipAnalytics: boolean;
14
+ }) => SafePlugin<HyperlinkToolbarItemsState | undefined>;
@@ -1,12 +1,8 @@
1
1
  /// <reference types="react" />
2
- import type { IntlShape } from 'react-intl-next';
3
2
  import type { HyperlinkAddToolbarProps } from '@atlaskit/editor-common/link';
4
- import type { Command, ExtractInjectionAPI, FloatingToolbarHandler, FloatingToolbarItem, HyperlinkPluginOptions } from '@atlaskit/editor-common/types';
5
- import type { EditorState } from '@atlaskit/editor-prosemirror/state';
6
- import { type HyperlinkToolbarItemsState } from './pm-plugins/toolbar-buttons';
3
+ import type { ExtractInjectionAPI, FloatingToolbarHandler, HyperlinkPluginOptions } from '@atlaskit/editor-common/types';
7
4
  import type { hyperlinkPlugin } from './index';
8
5
  export declare function HyperlinkAddToolbarWithState({ linkPickerOptions, onSubmit, displayText, displayUrl, providerFactory, view, onCancel, invokeMethod, lpLinkPicker, onClose, onEscapeCallback, onClickAwayCallback, pluginInjectionApi, }: HyperlinkAddToolbarProps & {
9
6
  pluginInjectionApi: any;
10
7
  }): JSX.Element;
11
- export declare const mergeAddedItems: (link: string, state: EditorState, intl: IntlShape, providerFactory: import("@atlaskit/editor-common/provider-factory").ProviderFactory) => (items: Array<FloatingToolbarItem<Command>>, toolbarItemsState: HyperlinkToolbarItemsState | undefined) => Array<FloatingToolbarItem<Command>>;
12
8
  export declare const getToolbarConfig: (options: HyperlinkPluginOptions, pluginInjectionApi: ExtractInjectionAPI<typeof hyperlinkPlugin> | undefined) => FloatingToolbarHandler;
@@ -1,15 +1,16 @@
1
1
  import type { UIAnalyticsEvent } from '@atlaskit/analytics-next';
2
2
  import type { EditorAnalyticsAPI } from '@atlaskit/editor-common/analytics';
3
3
  import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { type CardPluginActions } from '@atlaskit/editor-common/card';
4
5
  import type { CardAppearance } from '@atlaskit/editor-common/provider-factory';
5
6
  import type { Command, EditorCommand, LinkInputType } from '@atlaskit/editor-common/types';
6
7
  import type { Transaction } from '@atlaskit/editor-prosemirror/state';
7
8
  export declare function setLinkHref(href: string, pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined, to?: number, isTabPressed?: boolean): Command;
8
9
  export type UpdateLink = (href: string, text: string, pos: number, to?: number) => Command;
9
10
  export declare function updateLink(href: string, text: string, pos: number, to?: number): Command;
10
- export declare function insertLink(from: number, to: number, incomingHref: string, incomingTitle?: string, displayText?: string, source?: LinkInputType, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance): Command;
11
+ 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;
11
12
  export type InsertLink = (inputMethod: LinkInputType, from: number, to: number, href: string, title?: string, displayText?: string, cardsAvailable?: boolean, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance) => Command;
12
- export declare const insertLinkWithAnalytics: (inputMethod: LinkInputType, from: number, to: number, href: string, editorAnalyticsApi: EditorAnalyticsAPI | undefined, title?: string, displayText?: string, cardsAvailable?: boolean, sourceEvent?: UIAnalyticsEvent | null | undefined, appearance?: CardAppearance) => Command;
13
+ 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;
13
14
  export declare function removeLink(pos: number, editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
14
15
  export declare function editInsertedLink(editorAnalyticsApi: EditorAnalyticsAPI | undefined): Command;
15
16
  type InputMethod = INPUT_METHOD.TOOLBAR | INPUT_METHOD.QUICK_INSERT | INPUT_METHOD.SHORTCUT | INPUT_METHOD.INSERT_MENU;
@@ -18,6 +19,6 @@ export declare function showLinkToolbar(inputMethod: InputMethod, editorAnalytic
18
19
  export declare function hideLinkToolbar(): Command;
19
20
  export type HideLinkToolbar = (tr: Transaction) => Transaction;
20
21
  export declare const hideLinkToolbarSetMeta: HideLinkToolbar;
21
- export declare const onEscapeCallback: Command;
22
+ export declare const onEscapeCallback: (cardActions?: CardPluginActions) => Command;
22
23
  export declare const onClickAwayCallback: Command;
23
24
  export {};
@@ -1,4 +1,3 @@
1
1
  export { hyperlinkPlugin } from './plugin';
2
2
  export type { HyperlinkPlugin } from './plugin';
3
3
  export type { HideLinkToolbar, ShowLinkToolbar, InsertLink, UpdateLink, } from './commands';
4
- export type { PrependToolbarButtons, AddToolbarItems, } from './pm-plugins/toolbar-buttons';
@@ -1,27 +1,15 @@
1
1
  import type { HyperlinkState } from '@atlaskit/editor-common/link';
2
2
  import type { HyperlinkPluginOptions, NextEditorPlugin, OptionalPlugin } from '@atlaskit/editor-common/types';
3
3
  import type { AnalyticsPlugin } from '@atlaskit/editor-plugin-analytics';
4
+ import type { CardPlugin } from '@atlaskit/editor-plugin-card';
4
5
  import type { HideLinkToolbar, InsertLink, ShowLinkToolbar, UpdateLink } from './commands';
5
- import type { AddToolbarItems, PrependToolbarButtons } from './pm-plugins/toolbar-buttons';
6
6
  export type HyperlinkPlugin = NextEditorPlugin<'hyperlink', {
7
7
  pluginConfiguration: HyperlinkPluginOptions | undefined;
8
8
  dependencies: [
9
- OptionalPlugin<AnalyticsPlugin>
9
+ OptionalPlugin<AnalyticsPlugin>,
10
+ OptionalPlugin<CardPlugin>
10
11
  ];
11
12
  actions: {
12
- /**
13
- * Add items to the left of the hyperlink floating toolbar
14
- * @param props
15
- * -
16
- * - items: Retrieve floating toolbar items to add
17
- * - onEscapeCallback (optional): To be called when the link picker is escaped.
18
- * - onInsertLinkCallback (optional): To be called when a link is inserted and it can be changed into a card.
19
- */
20
- prependToolbarButtons: PrependToolbarButtons;
21
- /**
22
- * Add items before or after any default hyperlink floating toolbar items
23
- */
24
- addToolbarItems: AddToolbarItems;
25
13
  hideLinkToolbar: HideLinkToolbar;
26
14
  insertLink: InsertLink;
27
15
  updateLink: UpdateLink;
@@ -1,21 +1,6 @@
1
- import type { IntlShape } from 'react-intl-next';
2
- import type { QueueCardsFromTransactionAction } from '@atlaskit/editor-common/card';
3
- import type { ProviderFactory } from '@atlaskit/editor-common/provider-factory';
4
1
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
- import type { FloatingToolbarItem } from '@atlaskit/editor-common/types';
6
2
  import { PluginKey } from '@atlaskit/editor-prosemirror/state';
7
- import type { EditorState, Transaction } from '@atlaskit/editor-prosemirror/state';
8
- import type { EditorView } from '@atlaskit/editor-prosemirror/view';
9
- /**
10
- * Relative placement of an item
11
- */
12
- type PlacementType = 'start' | 'end';
13
- type AdditionalToolbarItems = Record<PlacementType, GetToolbarItems[]>;
14
3
  export type HyperlinkToolbarItemsState = {
15
- items: GetToolbarItems;
16
- items_next?: AdditionalToolbarItems;
17
- onEscapeCallback: ((tr: Transaction) => Transaction) | undefined;
18
- onInsertLinkCallback: QueueCardsFromTransactionAction | undefined;
19
4
  /**
20
5
  * If you are mounting your own items to the hyperlink toolbar you may decide
21
6
  * you want to replace the hyperlink analytics with your own
@@ -24,18 +9,6 @@ export type HyperlinkToolbarItemsState = {
24
9
  skipAnalytics?: boolean;
25
10
  };
26
11
  export declare const toolbarKey: PluginKey<HyperlinkToolbarItemsState | undefined>;
27
- type GetToolbarItems = (state: EditorState, intl: IntlShape, providerFactory: ProviderFactory, link: string) => FloatingToolbarItem<any>[];
28
- interface PrependToolbarButtonsProps extends HyperlinkToolbarItemsState {
29
- view: EditorView;
30
- }
31
- export type PrependToolbarButtons = (props: PrependToolbarButtonsProps) => void;
32
- export declare const prependToolbarButtons: ({ items, onEscapeCallback, onInsertLinkCallback, skipAnalytics, view, }: PrependToolbarButtonsProps) => void;
33
- type AddToolbarItemsProps = {
34
- items: GetToolbarItems;
35
- placement: PlacementType;
36
- view: EditorView;
37
- };
38
- export type AddToolbarItems = (props: AddToolbarItemsProps) => void;
39
- export declare const addToolbarItems: ({ items, placement, view, }: AddToolbarItemsProps) => void;
40
- export declare const toolbarButtonsPlugin: () => SafePlugin<HyperlinkToolbarItemsState | undefined>;
41
- export {};
12
+ export declare const toolbarButtonsPlugin: (initialState?: {
13
+ skipAnalytics: boolean;
14
+ }) => SafePlugin<HyperlinkToolbarItemsState | undefined>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-hyperlink",
3
- "version": "1.7.2",
3
+ "version": "2.0.1",
4
4
  "description": "Hyperlink plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,8 +34,9 @@
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^36.10.7",
36
36
  "@atlaskit/analytics-next": "^9.3.0",
37
- "@atlaskit/editor-common": "^81.0.0",
37
+ "@atlaskit/editor-common": "^82.0.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^1.2.0",
39
+ "@atlaskit/editor-plugin-card": "2.0.1",
39
40
  "@atlaskit/editor-prosemirror": "4.0.1",
40
41
  "@atlaskit/icon": "^22.3.0",
41
42
  "@atlaskit/platform-feature-flags": "^0.2.5",
@@ -54,7 +55,6 @@
54
55
  "@atlaskit/ssr": "*",
55
56
  "@atlaskit/util-data-test": "^17.9.0",
56
57
  "@atlaskit/visual-regression": "*",
57
- "@atlassian/atlassian-frontend-prettier-config-1.0.0": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.0",
58
58
  "@testing-library/react": "^12.1.5",
59
59
  "raf-stub": "^2.0.1",
60
60
  "react-dom": "^16.8.0",
@@ -91,7 +91,6 @@
91
91
  ]
92
92
  }
93
93
  },
94
- "prettier": "@atlassian/atlassian-frontend-prettier-config-1.0.0",
95
94
  "platform-feature-flags": {
96
95
  "platform.linking-platform.prevent-suspicious-linkification": {
97
96
  "type": "boolean"