@atlaskit/editor-plugin-hyperlink 2.6.2 → 2.7.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,16 @@
1
1
  # @atlaskit/editor-plugin-hyperlink
2
2
 
3
+ ## 2.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`aef5432662b58`](https://stash.atlassian.com/projects/CONFCLOUD/repos/confluence-frontend/commits/aef5432662b58) -
8
+ [ux] EDM-10363 Implement opening links via configure overlay dropdown open link button
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
3
14
  ## 2.6.2
4
15
 
5
16
  ### Patch Changes
@@ -13,7 +13,8 @@ var ButtonWrapper = exports.ButtonWrapper = function ButtonWrapper(_ref) {
13
13
  var editorView = _ref.editorView,
14
14
  pos = _ref.pos,
15
15
  stateKey = _ref.stateKey,
16
- intl = _ref.intl;
16
+ intl = _ref.intl,
17
+ onOpenLinkClick = _ref.onOpenLinkClick;
17
18
  var wrapper = document.createElement('span');
18
19
  wrapper.style.position = 'relative';
19
20
  var nonBreakingCharacter = "\u2060";
@@ -30,7 +31,8 @@ var ButtonWrapper = exports.ButtonWrapper = function ButtonWrapper(_ref) {
30
31
  }, /*#__PURE__*/_react.default.createElement(_link.OverlayButton, {
31
32
  targetElementPos: pos,
32
33
  editorView: editorView,
33
- onDropdownChange: onDropdownChange
34
+ onDropdownChange: onDropdownChange,
35
+ onOpenLinkClick: onOpenLinkClick
34
36
  }), nonBreakingCharacter), wrapper);
35
37
  return wrapper;
36
38
  };
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.stateKey = exports.plugin = void 0;
8
8
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
9
  var _uuid = _interopRequireDefault(require("uuid"));
10
- var _analytics = require("@atlaskit/editor-common/analytics");
11
10
  var _link3 = require("@atlaskit/editor-common/link");
12
11
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
13
12
  var _utils = require("@atlaskit/editor-common/utils");
@@ -228,7 +227,29 @@ var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance,
228
227
  editorView: view,
229
228
  pos: configureButtonTargetPos,
230
229
  stateKey: stateKey,
231
- intl: intl
230
+ intl: intl,
231
+ onOpenLinkClick: function onOpenLinkClick(event) {
232
+ var _node$marks$find, _pluginInjectionApi$a;
233
+ if (configureButtonTargetPos === undefined || typeof configureButtonTargetPos !== 'number') {
234
+ return;
235
+ }
236
+ var node = view.state.tr.doc.nodeAt(configureButtonTargetPos);
237
+ if (node === null) {
238
+ return;
239
+ }
240
+ var url = (_node$marks$find = node.marks.find(function (mark) {
241
+ return mark.type.name === 'link';
242
+ })) === null || _node$marks$find === void 0 ? void 0 : _node$marks$find.attrs.href;
243
+ if (!url) {
244
+ return;
245
+ }
246
+ (0, _link3.handleNavigation)({
247
+ fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.fireAnalyticsEvent,
248
+ onClickCallback: onClickCallback,
249
+ url: url,
250
+ event: event
251
+ });
252
+ }
232
253
  });
233
254
  });
234
255
  _decorations = _view.DecorationSet.create(newState.doc, [decoration]);
@@ -343,34 +364,17 @@ var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance,
343
364
  };
344
365
  dom.onclick = function (event) {
345
366
  if (isDirectTarget(event, dom)) {
346
- var _pluginInjectionApi$a, _pluginInjectionApi$a2;
367
+ var _pluginInjectionApi$a2;
347
368
  var url = mark.attrs.href;
348
- pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a2 = _pluginInjectionApi$a.fireAnalyticsEvent) === null || _pluginInjectionApi$a2 === void 0 || _pluginInjectionApi$a2.call(_pluginInjectionApi$a, {
349
- action: _analytics.ACTION.VISITED,
350
- actionSubject: _analytics.ACTION_SUBJECT.LINK,
351
- eventType: _analytics.EVENT_TYPE.TRACK,
352
- attributes: {
353
- platform: _analytics.PLATFORMS.WEB,
354
- mode: _analytics.MODE.EDITOR
355
- }
369
+ // event is globalThis.MouseEvent, while handleNavigation
370
+ // (and editor-common OnClickCallback) require React.MouseEvent
371
+ var reactMouseEvent = event;
372
+ (0, _link3.handleNavigation)({
373
+ fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions.fireAnalyticsEvent,
374
+ onClickCallback: onClickCallback,
375
+ url: url,
376
+ event: reactMouseEvent
356
377
  });
357
- if (url) {
358
- try {
359
- onClickCallback === null || onClickCallback === void 0 || onClickCallback({
360
- event: event,
361
- url: url
362
- });
363
- } catch (_unused) {}
364
-
365
- /**
366
- * Links should navigate by default in live pages if:
367
- * - the link is the direct target of the click event
368
- * - default handling wasn't prevented with `event.preventDefault()`
369
- */
370
- if (!event.defaultPrevented) {
371
- window.location.href = url;
372
- }
373
- }
374
378
  }
375
379
  };
376
380
  return {
@@ -6,7 +6,8 @@ export const ButtonWrapper = ({
6
6
  editorView,
7
7
  pos,
8
8
  stateKey,
9
- intl
9
+ intl,
10
+ onOpenLinkClick
10
11
  }) => {
11
12
  const wrapper = document.createElement('span');
12
13
  wrapper.style.position = 'relative';
@@ -24,7 +25,8 @@ export const ButtonWrapper = ({
24
25
  }, /*#__PURE__*/React.createElement(OverlayButton, {
25
26
  targetElementPos: pos,
26
27
  editorView: editorView,
27
- onDropdownChange: onDropdownChange
28
+ onDropdownChange: onDropdownChange,
29
+ onOpenLinkClick: onOpenLinkClick
28
30
  }), nonBreakingCharacter), wrapper);
29
31
  return wrapper;
30
32
  };
@@ -1,6 +1,5 @@
1
1
  import uuid from 'uuid';
2
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, MODE, PLATFORMS } from '@atlaskit/editor-common/analytics';
3
- import { InsertStatus, LinkAction } from '@atlaskit/editor-common/link';
2
+ import { handleNavigation, InsertStatus, LinkAction } from '@atlaskit/editor-common/link';
4
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
4
  import { canLinkBeCreatedInRange, shallowEqual } from '@atlaskit/editor-common/utils';
6
5
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
@@ -232,7 +231,27 @@ export const plugin = (dispatch, intl, editorAppearance, pluginInjectionApi, onC
232
231
  editorView: view,
233
232
  pos: configureButtonTargetPos,
234
233
  stateKey,
235
- intl
234
+ intl,
235
+ onOpenLinkClick: event => {
236
+ var _node$marks$find, _pluginInjectionApi$a;
237
+ if (configureButtonTargetPos === undefined || typeof configureButtonTargetPos !== 'number') {
238
+ return;
239
+ }
240
+ const node = view.state.tr.doc.nodeAt(configureButtonTargetPos);
241
+ if (node === null) {
242
+ return;
243
+ }
244
+ const url = (_node$marks$find = node.marks.find(mark => mark.type.name === 'link')) === null || _node$marks$find === void 0 ? void 0 : _node$marks$find.attrs.href;
245
+ if (!url) {
246
+ return;
247
+ }
248
+ handleNavigation({
249
+ fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.fireAnalyticsEvent,
250
+ onClickCallback,
251
+ url,
252
+ event
253
+ });
254
+ }
236
255
  });
237
256
  });
238
257
  decorations = DecorationSet.create(newState.doc, [decoration]);
@@ -357,34 +376,17 @@ export const plugin = (dispatch, intl, editorAppearance, pluginInjectionApi, onC
357
376
  };
358
377
  dom.onclick = event => {
359
378
  if (isDirectTarget(event, dom)) {
360
- var _pluginInjectionApi$a, _pluginInjectionApi$a2, _pluginInjectionApi$a3;
379
+ var _pluginInjectionApi$a2;
361
380
  const url = mark.attrs.href;
362
- pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : (_pluginInjectionApi$a2 = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : (_pluginInjectionApi$a3 = _pluginInjectionApi$a2.fireAnalyticsEvent) === null || _pluginInjectionApi$a3 === void 0 ? void 0 : _pluginInjectionApi$a3.call(_pluginInjectionApi$a2, {
363
- action: ACTION.VISITED,
364
- actionSubject: ACTION_SUBJECT.LINK,
365
- eventType: EVENT_TYPE.TRACK,
366
- attributes: {
367
- platform: PLATFORMS.WEB,
368
- mode: MODE.EDITOR
369
- }
381
+ // event is globalThis.MouseEvent, while handleNavigation
382
+ // (and editor-common OnClickCallback) require React.MouseEvent
383
+ const reactMouseEvent = event;
384
+ handleNavigation({
385
+ fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions.fireAnalyticsEvent,
386
+ onClickCallback,
387
+ url,
388
+ event: reactMouseEvent
370
389
  });
371
- if (url) {
372
- try {
373
- onClickCallback === null || onClickCallback === void 0 ? void 0 : onClickCallback({
374
- event,
375
- url
376
- });
377
- } catch {}
378
-
379
- /**
380
- * Links should navigate by default in live pages if:
381
- * - the link is the direct target of the click event
382
- * - default handling wasn't prevented with `event.preventDefault()`
383
- */
384
- if (!event.defaultPrevented) {
385
- window.location.href = url;
386
- }
387
- }
388
390
  }
389
391
  };
390
392
  return {
@@ -6,7 +6,8 @@ export var ButtonWrapper = function ButtonWrapper(_ref) {
6
6
  var editorView = _ref.editorView,
7
7
  pos = _ref.pos,
8
8
  stateKey = _ref.stateKey,
9
- intl = _ref.intl;
9
+ intl = _ref.intl,
10
+ onOpenLinkClick = _ref.onOpenLinkClick;
10
11
  var wrapper = document.createElement('span');
11
12
  wrapper.style.position = 'relative';
12
13
  var nonBreakingCharacter = "\u2060";
@@ -23,7 +24,8 @@ export var ButtonWrapper = function ButtonWrapper(_ref) {
23
24
  }, /*#__PURE__*/React.createElement(OverlayButton, {
24
25
  targetElementPos: pos,
25
26
  editorView: editorView,
26
- onDropdownChange: onDropdownChange
27
+ onDropdownChange: onDropdownChange,
28
+ onOpenLinkClick: onOpenLinkClick
27
29
  }), nonBreakingCharacter), wrapper);
28
30
  return wrapper;
29
31
  };
@@ -2,8 +2,7 @@ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
2
  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; }
3
3
  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; }
4
4
  import uuid from 'uuid';
5
- import { ACTION, ACTION_SUBJECT, EVENT_TYPE, MODE, PLATFORMS } from '@atlaskit/editor-common/analytics';
6
- import { InsertStatus, LinkAction } from '@atlaskit/editor-common/link';
5
+ import { handleNavigation, InsertStatus, LinkAction } from '@atlaskit/editor-common/link';
7
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
8
7
  import { canLinkBeCreatedInRange, shallowEqual } from '@atlaskit/editor-common/utils';
9
8
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
@@ -221,7 +220,29 @@ export var plugin = function plugin(dispatch, intl, editorAppearance, pluginInje
221
220
  editorView: view,
222
221
  pos: configureButtonTargetPos,
223
222
  stateKey: stateKey,
224
- intl: intl
223
+ intl: intl,
224
+ onOpenLinkClick: function onOpenLinkClick(event) {
225
+ var _node$marks$find, _pluginInjectionApi$a;
226
+ if (configureButtonTargetPos === undefined || typeof configureButtonTargetPos !== 'number') {
227
+ return;
228
+ }
229
+ var node = view.state.tr.doc.nodeAt(configureButtonTargetPos);
230
+ if (node === null) {
231
+ return;
232
+ }
233
+ var url = (_node$marks$find = node.marks.find(function (mark) {
234
+ return mark.type.name === 'link';
235
+ })) === null || _node$marks$find === void 0 ? void 0 : _node$marks$find.attrs.href;
236
+ if (!url) {
237
+ return;
238
+ }
239
+ handleNavigation({
240
+ fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.fireAnalyticsEvent,
241
+ onClickCallback: onClickCallback,
242
+ url: url,
243
+ event: event
244
+ });
245
+ }
225
246
  });
226
247
  });
227
248
  _decorations = DecorationSet.create(newState.doc, [decoration]);
@@ -336,34 +357,17 @@ export var plugin = function plugin(dispatch, intl, editorAppearance, pluginInje
336
357
  };
337
358
  dom.onclick = function (event) {
338
359
  if (isDirectTarget(event, dom)) {
339
- var _pluginInjectionApi$a, _pluginInjectionApi$a2;
360
+ var _pluginInjectionApi$a2;
340
361
  var url = mark.attrs.href;
341
- pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a = _pluginInjectionApi$a.actions) === null || _pluginInjectionApi$a === void 0 || (_pluginInjectionApi$a2 = _pluginInjectionApi$a.fireAnalyticsEvent) === null || _pluginInjectionApi$a2 === void 0 || _pluginInjectionApi$a2.call(_pluginInjectionApi$a, {
342
- action: ACTION.VISITED,
343
- actionSubject: ACTION_SUBJECT.LINK,
344
- eventType: EVENT_TYPE.TRACK,
345
- attributes: {
346
- platform: PLATFORMS.WEB,
347
- mode: MODE.EDITOR
348
- }
362
+ // event is globalThis.MouseEvent, while handleNavigation
363
+ // (and editor-common OnClickCallback) require React.MouseEvent
364
+ var reactMouseEvent = event;
365
+ handleNavigation({
366
+ fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions.fireAnalyticsEvent,
367
+ onClickCallback: onClickCallback,
368
+ url: url,
369
+ event: reactMouseEvent
349
370
  });
350
- if (url) {
351
- try {
352
- onClickCallback === null || onClickCallback === void 0 || onClickCallback({
353
- event: event,
354
- url: url
355
- });
356
- } catch (_unused) {}
357
-
358
- /**
359
- * Links should navigate by default in live pages if:
360
- * - the link is the direct target of the click event
361
- * - default handling wasn't prevented with `event.preventDefault()`
362
- */
363
- if (!event.defaultPrevented) {
364
- window.location.href = url;
365
- }
366
- }
367
371
  }
368
372
  };
369
373
  return {
@@ -1,10 +1,13 @@
1
+ import { type MouseEvent } from 'react';
1
2
  import { type IntlShape } from 'react-intl-next';
2
3
  import { type HyperlinkState } from '@atlaskit/editor-common/link';
3
4
  import { type PluginKey } from '@atlaskit/editor-prosemirror/state';
4
5
  import { type EditorView } from '@atlaskit/editor-prosemirror/view';
5
- export declare const ButtonWrapper: ({ editorView, pos, stateKey, intl, }: {
6
+ export declare const ButtonWrapper: ({ editorView, pos, stateKey, intl, onOpenLinkClick, }: {
6
7
  editorView: EditorView;
7
8
  pos?: number | undefined;
8
9
  stateKey: PluginKey<HyperlinkState>;
9
10
  intl: IntlShape;
11
+ /** Callback fired when the Open Link dropdown item is clicked */
12
+ onOpenLinkClick: (event: MouseEvent<HTMLAnchorElement>) => void;
10
13
  }) => HTMLSpanElement;
@@ -1,10 +1,13 @@
1
+ import { type MouseEvent } from 'react';
1
2
  import { type IntlShape } from 'react-intl-next';
2
3
  import { type HyperlinkState } from '@atlaskit/editor-common/link';
3
4
  import { type PluginKey } from '@atlaskit/editor-prosemirror/state';
4
5
  import { type EditorView } from '@atlaskit/editor-prosemirror/view';
5
- export declare const ButtonWrapper: ({ editorView, pos, stateKey, intl, }: {
6
+ export declare const ButtonWrapper: ({ editorView, pos, stateKey, intl, onOpenLinkClick, }: {
6
7
  editorView: EditorView;
7
8
  pos?: number | undefined;
8
9
  stateKey: PluginKey<HyperlinkState>;
9
10
  intl: IntlShape;
11
+ /** Callback fired when the Open Link dropdown item is clicked */
12
+ onOpenLinkClick: (event: MouseEvent<HTMLAnchorElement>) => void;
10
13
  }) => HTMLSpanElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-hyperlink",
3
- "version": "2.6.2",
3
+ "version": "2.7.0",
4
4
  "description": "Hyperlink plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -34,12 +34,12 @@
34
34
  "dependencies": {
35
35
  "@atlaskit/adf-schema": "^40.3.0",
36
36
  "@atlaskit/analytics-next": "^9.3.0",
37
- "@atlaskit/editor-common": "^87.0.0",
37
+ "@atlaskit/editor-common": "^87.2.0",
38
38
  "@atlaskit/editor-plugin-analytics": "^1.6.0",
39
- "@atlaskit/editor-plugin-card": "2.8.2",
39
+ "@atlaskit/editor-plugin-card": "2.9.0",
40
40
  "@atlaskit/editor-plugin-editor-viewmode": "^2.1.0",
41
41
  "@atlaskit/editor-prosemirror": "5.0.1",
42
- "@atlaskit/icon": "^22.7.0",
42
+ "@atlaskit/icon": "^22.8.0",
43
43
  "@atlaskit/platform-feature-flags": "^0.3.0",
44
44
  "@atlaskit/prosemirror-input-rules": "^3.2.0",
45
45
  "@babel/runtime": "^7.0.0",