@atlaskit/editor-plugin-hyperlink 4.3.1 → 4.3.3

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,21 @@
1
1
  # @atlaskit/editor-plugin-hyperlink
2
2
 
3
+ ## 4.3.3
4
+
5
+ ### Patch Changes
6
+
7
+ - [#135151](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/135151)
8
+ [`5c16edacc0116`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/5c16edacc0116) -
9
+ [ux] Show link floating toolbar when user clicks right before or after the link (solving one char
10
+ link issue)
11
+ - Updated dependencies
12
+
13
+ ## 4.3.2
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+
3
19
  ## 4.3.1
4
20
 
5
21
  ### Patch Changes
@@ -17,16 +17,6 @@ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
17
17
  var _decorations2 = require("./decorations");
18
18
  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; }
19
19
  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; }
20
- var isSelectionInsideLink = function isSelectionInsideLink(state) {
21
- return !!state.doc.type.schema.marks.link.isInSet(state.selection.$from.marks());
22
- };
23
- var isSelectionAroundLink = function isSelectionAroundLink(state) {
24
- var _state$selection = state.selection,
25
- $from = _state$selection.$from,
26
- $to = _state$selection.$to;
27
- var node = $from.nodeAfter;
28
- return !!node && $from.textOffset === 0 && $to.pos - $from.pos === node.nodeSize && !!state.doc.type.schema.marks.link.isInSet(node.marks);
29
- };
30
20
  var mapTransactionToState = function mapTransactionToState(state, tr) {
31
21
  if (!state) {
32
22
  return undefined;
@@ -75,7 +65,7 @@ var toState = function toState(state, action, editorState) {
75
65
  }
76
66
  case _link3.LinkAction.SELECTION_CHANGE:
77
67
  // If the user has moved their cursor, see if they're in a link
78
- var link = getActiveLinkMark(editorState);
68
+ var link = (0, _link3.getActiveLinkMark)(editorState);
79
69
  if (link) {
80
70
  return _objectSpread(_objectSpread({}, link), {}, {
81
71
  type: _link3.InsertStatus.EDIT_LINK_TOOLBAR
@@ -91,7 +81,7 @@ var toState = function toState(state, action, editorState) {
91
81
  switch (action) {
92
82
  case _link3.LinkAction.EDIT_INSERTED_TOOLBAR:
93
83
  {
94
- var _link = getActiveLinkMark(editorState);
84
+ var _link = (0, _link3.getActiveLinkMark)(editorState);
95
85
  if (_link) {
96
86
  if (_link.pos === state.pos && _link.node === state.node) {
97
87
  return _objectSpread(_objectSpread({}, state), {}, {
@@ -105,7 +95,7 @@ var toState = function toState(state, action, editorState) {
105
95
  return undefined;
106
96
  }
107
97
  case _link3.LinkAction.SELECTION_CHANGE:
108
- var _link2 = getActiveLinkMark(editorState);
98
+ var _link2 = (0, _link3.getActiveLinkMark)(editorState);
109
99
  if (_link2) {
110
100
  if (_link2.pos === state.pos && _link2.node === state.node) {
111
101
  // Make sure we return the same object, if it's the same link
@@ -135,18 +125,6 @@ var toState = function toState(state, action, editorState) {
135
125
  }
136
126
  return;
137
127
  };
138
- var getActiveLinkMark = function getActiveLinkMark(state) {
139
- var $from = state.selection.$from;
140
- if (isSelectionInsideLink(state) || isSelectionAroundLink(state)) {
141
- var pos = $from.pos - $from.textOffset;
142
- var node = state.doc.nodeAt(pos);
143
- return node && node.isText ? {
144
- node: node,
145
- pos: pos
146
- } : undefined;
147
- }
148
- return undefined;
149
- };
150
128
  var getActiveText = function getActiveText(selection) {
151
129
  var currentSlice = selection.content();
152
130
  if (currentSlice.size === 0) {
@@ -19,9 +19,11 @@ var _messages = require("@atlaskit/editor-common/messages");
19
19
  var _ui = require("@atlaskit/editor-common/ui");
20
20
  var _utils = require("@atlaskit/editor-common/utils");
21
21
  var _state = require("@atlaskit/editor-prosemirror/state");
22
+ var _utils2 = require("@atlaskit/editor-prosemirror/utils");
22
23
  var _edit = _interopRequireDefault(require("@atlaskit/icon/core/edit"));
23
24
  var _linkBrokenEditorUnlink = _interopRequireDefault(require("@atlaskit/icon/core/migration/link-broken--editor-unlink"));
24
25
  var _linkExternalShortcut = _interopRequireDefault(require("@atlaskit/icon/core/migration/link-external--shortcut"));
26
+ var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
25
27
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
26
28
  var _commands = require("../../editor-commands/commands");
27
29
  var _main = require("../../pm-plugins/main");
@@ -128,7 +130,14 @@ var getToolbarConfig = exports.getToolbarConfig = function getToolbarConfig(opti
128
130
  }),
129
131
  // Use only the node types existing in the schema ED-6745
130
132
  align: 'left',
131
- className: activeLinkMark.type.match('INSERT|EDIT_INSERTED') ? 'hyperlink-floating-toolbar' : ''
133
+ className: activeLinkMark.type.match('INSERT|EDIT_INSERTED') ? 'hyperlink-floating-toolbar' : '',
134
+ // getDomRef by default uses view.state.selection.from to position the toolbar.
135
+ // However, when the user clicks in right after the link the view.state.selection.from references to the dom after the selection.
136
+ // So instead we want to use the activeLinkMark.pos which has been calculated as the position before the click so that would be the link node
137
+ getDomRef: activeLinkMark && (activeLinkMark.type === 'EDIT_INSERTED' || activeLinkMark.type === 'EDIT') && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1') && (0, _platformFeatureFlags.fg)('platform_editor_controls_patch_3') ? function (view) {
138
+ var domRef = (0, _utils2.findDomRefAtPos)(activeLinkMark.pos, view.domAtPos.bind(view));
139
+ return domRef instanceof HTMLElement ? domRef : undefined;
140
+ } : undefined
132
141
  };
133
142
  switch (activeLinkMark.type) {
134
143
  case 'EDIT':
@@ -1,5 +1,5 @@
1
1
  import uuid from 'uuid';
2
- import { handleNavigation, InsertStatus, LinkAction } from '@atlaskit/editor-common/link';
2
+ import { handleNavigation, InsertStatus, LinkAction, getActiveLinkMark } from '@atlaskit/editor-common/link';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { canLinkBeCreatedInRange, shallowEqual } from '@atlaskit/editor-common/utils';
5
5
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
@@ -7,15 +7,6 @@ import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
7
7
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
8
8
  import { fg } from '@atlaskit/platform-feature-flags';
9
9
  import { ButtonWrapper } from './decorations';
10
- const isSelectionInsideLink = state => !!state.doc.type.schema.marks.link.isInSet(state.selection.$from.marks());
11
- const isSelectionAroundLink = state => {
12
- const {
13
- $from,
14
- $to
15
- } = state.selection;
16
- const node = $from.nodeAfter;
17
- return !!node && $from.textOffset === 0 && $to.pos - $from.pos === node.nodeSize && !!state.doc.type.schema.marks.link.isInSet(node.marks);
18
- };
19
10
  const mapTransactionToState = (state, tr) => {
20
11
  if (!state) {
21
12
  return undefined;
@@ -132,22 +123,6 @@ const toState = (state, action, editorState) => {
132
123
  }
133
124
  return;
134
125
  };
135
- const getActiveLinkMark = state => {
136
- const {
137
- selection: {
138
- $from
139
- }
140
- } = state;
141
- if (isSelectionInsideLink(state) || isSelectionAroundLink(state)) {
142
- const pos = $from.pos - $from.textOffset;
143
- const node = state.doc.nodeAt(pos);
144
- return node && node.isText ? {
145
- node,
146
- pos
147
- } : undefined;
148
- }
149
- return undefined;
150
- };
151
126
  const getActiveText = selection => {
152
127
  const currentSlice = selection.content();
153
128
  if (currentSlice.size === 0) {
@@ -8,9 +8,11 @@ import { linkMessages, linkToolbarMessages as linkToolbarCommonMessages } from '
8
8
  import { LINKPICKER_HEIGHT_IN_PX, RECENT_SEARCH_HEIGHT_IN_PX, RECENT_SEARCH_WIDTH_IN_PX } from '@atlaskit/editor-common/ui';
9
9
  import { normalizeUrl } from '@atlaskit/editor-common/utils';
10
10
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
11
+ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
11
12
  import EditIcon from '@atlaskit/icon/core/edit';
12
13
  import LinkBrokenIcon from '@atlaskit/icon/core/migration/link-broken--editor-unlink';
13
14
  import LinkExternalIcon from '@atlaskit/icon/core/migration/link-external--shortcut';
15
+ import { fg } from '@atlaskit/platform-feature-flags';
14
16
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
15
17
  import { editInsertedLink, insertLinkWithAnalytics, onClickAwayCallback, onEscapeCallback, removeLink, updateLink } from '../../editor-commands/commands';
16
18
  import { stateKey } from '../../pm-plugins/main';
@@ -112,7 +114,14 @@ export const getToolbarConfig = (options, pluginInjectionApi) => (state, intl, p
112
114
  nodeType: [state.schema.nodes.text, state.schema.nodes.paragraph, state.schema.nodes.heading, state.schema.nodes.taskItem, state.schema.nodes.decisionItem, state.schema.nodes.caption].filter(nodeType => !!nodeType),
113
115
  // Use only the node types existing in the schema ED-6745
114
116
  align: 'left',
115
- className: activeLinkMark.type.match('INSERT|EDIT_INSERTED') ? 'hyperlink-floating-toolbar' : ''
117
+ className: activeLinkMark.type.match('INSERT|EDIT_INSERTED') ? 'hyperlink-floating-toolbar' : '',
118
+ // getDomRef by default uses view.state.selection.from to position the toolbar.
119
+ // However, when the user clicks in right after the link the view.state.selection.from references to the dom after the selection.
120
+ // So instead we want to use the activeLinkMark.pos which has been calculated as the position before the click so that would be the link node
121
+ getDomRef: activeLinkMark && (activeLinkMark.type === 'EDIT_INSERTED' || activeLinkMark.type === 'EDIT') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_3') ? view => {
122
+ const domRef = findDomRefAtPos(activeLinkMark.pos, view.domAtPos.bind(view));
123
+ return domRef instanceof HTMLElement ? domRef : undefined;
124
+ } : undefined
116
125
  };
117
126
  switch (activeLinkMark.type) {
118
127
  case 'EDIT':
@@ -2,7 +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 { handleNavigation, InsertStatus, LinkAction } from '@atlaskit/editor-common/link';
5
+ import { handleNavigation, InsertStatus, LinkAction, getActiveLinkMark } from '@atlaskit/editor-common/link';
6
6
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
7
7
  import { canLinkBeCreatedInRange, shallowEqual } from '@atlaskit/editor-common/utils';
8
8
  import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
@@ -10,16 +10,6 @@ import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
10
10
  import { Decoration, DecorationSet } from '@atlaskit/editor-prosemirror/view';
11
11
  import { fg } from '@atlaskit/platform-feature-flags';
12
12
  import { ButtonWrapper } from './decorations';
13
- var isSelectionInsideLink = function isSelectionInsideLink(state) {
14
- return !!state.doc.type.schema.marks.link.isInSet(state.selection.$from.marks());
15
- };
16
- var isSelectionAroundLink = function isSelectionAroundLink(state) {
17
- var _state$selection = state.selection,
18
- $from = _state$selection.$from,
19
- $to = _state$selection.$to;
20
- var node = $from.nodeAfter;
21
- return !!node && $from.textOffset === 0 && $to.pos - $from.pos === node.nodeSize && !!state.doc.type.schema.marks.link.isInSet(node.marks);
22
- };
23
13
  var mapTransactionToState = function mapTransactionToState(state, tr) {
24
14
  if (!state) {
25
15
  return undefined;
@@ -128,18 +118,6 @@ var toState = function toState(state, action, editorState) {
128
118
  }
129
119
  return;
130
120
  };
131
- var getActiveLinkMark = function getActiveLinkMark(state) {
132
- var $from = state.selection.$from;
133
- if (isSelectionInsideLink(state) || isSelectionAroundLink(state)) {
134
- var pos = $from.pos - $from.textOffset;
135
- var node = state.doc.nodeAt(pos);
136
- return node && node.isText ? {
137
- node: node,
138
- pos: pos
139
- } : undefined;
140
- }
141
- return undefined;
142
- };
143
121
  var getActiveText = function getActiveText(selection) {
144
122
  var currentSlice = selection.content();
145
123
  if (currentSlice.size === 0) {
@@ -12,9 +12,11 @@ import { linkMessages, linkToolbarMessages as linkToolbarCommonMessages } from '
12
12
  import { LINKPICKER_HEIGHT_IN_PX, RECENT_SEARCH_HEIGHT_IN_PX, RECENT_SEARCH_WIDTH_IN_PX } from '@atlaskit/editor-common/ui';
13
13
  import { normalizeUrl } from '@atlaskit/editor-common/utils';
14
14
  import { TextSelection } from '@atlaskit/editor-prosemirror/state';
15
+ import { findDomRefAtPos } from '@atlaskit/editor-prosemirror/utils';
15
16
  import EditIcon from '@atlaskit/icon/core/edit';
16
17
  import LinkBrokenIcon from '@atlaskit/icon/core/migration/link-broken--editor-unlink';
17
18
  import LinkExternalIcon from '@atlaskit/icon/core/migration/link-external--shortcut';
19
+ import { fg } from '@atlaskit/platform-feature-flags';
18
20
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
19
21
  import { editInsertedLink, insertLinkWithAnalytics, onClickAwayCallback, onEscapeCallback, removeLink, updateLink } from '../../editor-commands/commands';
20
22
  import { stateKey } from '../../pm-plugins/main';
@@ -118,7 +120,14 @@ export var getToolbarConfig = function getToolbarConfig(options, pluginInjection
118
120
  }),
119
121
  // Use only the node types existing in the schema ED-6745
120
122
  align: 'left',
121
- className: activeLinkMark.type.match('INSERT|EDIT_INSERTED') ? 'hyperlink-floating-toolbar' : ''
123
+ className: activeLinkMark.type.match('INSERT|EDIT_INSERTED') ? 'hyperlink-floating-toolbar' : '',
124
+ // getDomRef by default uses view.state.selection.from to position the toolbar.
125
+ // However, when the user clicks in right after the link the view.state.selection.from references to the dom after the selection.
126
+ // So instead we want to use the activeLinkMark.pos which has been calculated as the position before the click so that would be the link node
127
+ getDomRef: activeLinkMark && (activeLinkMark.type === 'EDIT_INSERTED' || activeLinkMark.type === 'EDIT') && editorExperiment('platform_editor_controls', 'variant1') && fg('platform_editor_controls_patch_3') ? function (view) {
128
+ var domRef = findDomRefAtPos(activeLinkMark.pos, view.domAtPos.bind(view));
129
+ return domRef instanceof HTMLElement ? domRef : undefined;
130
+ } : undefined
122
131
  };
123
132
  switch (activeLinkMark.type) {
124
133
  case 'EDIT':
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-hyperlink",
3
- "version": "4.3.1",
3
+ "version": "4.3.3",
4
4
  "description": "Hyperlink plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -35,18 +35,18 @@
35
35
  "dependencies": {
36
36
  "@atlaskit/adf-schema": "^47.6.0",
37
37
  "@atlaskit/analytics-next": "^11.0.0",
38
- "@atlaskit/editor-common": "^102.13.0",
38
+ "@atlaskit/editor-common": "^102.19.0",
39
39
  "@atlaskit/editor-plugin-analytics": "^2.2.0",
40
40
  "@atlaskit/editor-plugin-card": "^5.4.0",
41
41
  "@atlaskit/editor-plugin-connectivity": "^2.0.0",
42
42
  "@atlaskit/editor-plugin-editor-viewmode": "^3.0.0",
43
43
  "@atlaskit/editor-plugin-primary-toolbar": "^3.1.0",
44
- "@atlaskit/editor-plugin-selection-toolbar": "^2.2.0",
44
+ "@atlaskit/editor-plugin-selection-toolbar": "^3.1.0",
45
45
  "@atlaskit/editor-prosemirror": "7.0.0",
46
- "@atlaskit/icon": "^25.0.0",
46
+ "@atlaskit/icon": "^25.5.0",
47
47
  "@atlaskit/platform-feature-flags": "^1.1.0",
48
48
  "@atlaskit/prosemirror-input-rules": "^3.3.0",
49
- "@atlaskit/tmp-editor-statsig": "^4.3.0",
49
+ "@atlaskit/tmp-editor-statsig": "^4.6.0",
50
50
  "@babel/runtime": "^7.0.0",
51
51
  "@emotion/react": "^11.7.1",
52
52
  "uuid": "^3.1.0"
@@ -107,6 +107,9 @@
107
107
  },
108
108
  "linking_platform_smart_links_in_live_pages": {
109
109
  "type": "boolean"
110
+ },
111
+ "platform_editor_controls_patch_3": {
112
+ "type": "boolean"
110
113
  }
111
114
  }
112
115
  }