@atlaskit/editor-plugin-hyperlink 5.2.2 → 5.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,28 @@
1
1
  # @atlaskit/editor-plugin-hyperlink
2
2
 
3
+ ## 5.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`f681ff4b37a3d`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/f681ff4b37a3d) -
8
+ [ux] ED-28752 register link button to new toolbar behind platform_editor_toolbar_aifc
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies
13
+
14
+ ## 5.3.0
15
+
16
+ ### Minor Changes
17
+
18
+ - [#196046](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/196046)
19
+ [`b0dad85aa7c35`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/b0dad85aa7c35) -
20
+ [ux] [ED-27974] Allow hyperlink plugin to change text to link on blur
21
+
22
+ ### Patch Changes
23
+
24
+ - Updated dependencies
25
+
3
26
  ## 5.2.2
4
27
 
5
28
  ### Patch Changes
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.hyperlinkPlugin = void 0;
8
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
8
9
  var _react = _interopRequireDefault(require("react"));
9
10
  var _adfSchema = require("@atlaskit/adf-schema");
10
11
  var _analytics = require("@atlaskit/editor-common/analytics");
@@ -16,6 +17,7 @@ var _quickInsert = require("@atlaskit/editor-common/quick-insert");
16
17
  var _utils = require("@atlaskit/editor-common/utils");
17
18
  var _linkEditorLink = _interopRequireDefault(require("@atlaskit/icon/core/migration/link--editor-link"));
18
19
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
20
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
19
21
  var _experiments = require("@atlaskit/tmp-editor-statsig/experiments");
20
22
  var _commands = require("./editor-commands/commands");
21
23
  var _fakeCursorForToolbar = _interopRequireDefault(require("./pm-plugins/fake-cursor-for-toolbar"));
@@ -24,6 +26,9 @@ var _keymap = require("./pm-plugins/keymap");
24
26
  var _main = require("./pm-plugins/main");
25
27
  var _toolbarButtons = require("./pm-plugins/toolbar-buttons");
26
28
  var _Toolbar = require("./ui/toolbar/Toolbar");
29
+ var _ToolbarComponents = require("./ui/ToolbarComponents");
30
+ 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; }
31
+ 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; }
27
32
  var getPosFromActiveLinkMark = function getPosFromActiveLinkMark(state) {
28
33
  if (state === undefined) {
29
34
  return undefined;
@@ -47,6 +52,10 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
47
52
  options = _ref$config === void 0 ? {} : _ref$config,
48
53
  api = _ref.api;
49
54
  var primaryToolbarComponent;
55
+ if ((0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc', 'isEnabled', true)) {
56
+ var _api$toolbar;
57
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents((0, _ToolbarComponents.getToolbarComponents)(api));
58
+ }
50
59
  return {
51
60
  name: 'hyperlink',
52
61
  marks: function marks() {
@@ -121,7 +130,7 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
121
130
  plugin: function plugin(_ref3) {
122
131
  var _api$analytics4;
123
132
  var schema = _ref3.schema;
124
- return (0, _inputRule.createInputRulePlugin)(schema, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
133
+ return (0, _inputRule.createInputRulePlugin)(schema, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, options.autoLinkOnBlur);
125
134
  }
126
135
  }, {
127
136
  name: 'hyperlinkKeymap',
@@ -140,7 +149,7 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
140
149
  }
141
150
  }];
142
151
  },
143
- pluginsOptions: {
152
+ pluginsOptions: _objectSpread(_objectSpread({
144
153
  quickInsert: function quickInsert(_ref4) {
145
154
  var formatMessage = _ref4.formatMessage;
146
155
  return [{
@@ -173,7 +182,8 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
173
182
  }
174
183
  }];
175
184
  },
176
- floatingToolbar: (0, _Toolbar.getToolbarConfig)(options, api),
185
+ floatingToolbar: (0, _Toolbar.getToolbarConfig)(options, api)
186
+ }, !(0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc', 'isEnabled', true) && {
177
187
  selectionToolbar: function selectionToolbar(state, _ref5) {
178
188
  var _api$userPreferences, _api$selectionToolbar;
179
189
  var formatMessage = _ref5.formatMessage;
@@ -209,10 +219,11 @@ var hyperlinkPlugin = exports.hyperlinkPlugin = function hyperlinkPlugin(_ref) {
209
219
  } else {
210
220
  return undefined;
211
221
  }
212
- },
222
+ }
223
+ }), !(0, _expValEquals.expValEquals)('platform_editor_toolbar_aifc', 'isEnabled', true) && {
213
224
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && (0, _experiments.editorExperiment)('platform_editor_controls', 'variant1', {
214
225
  exposure: true
215
226
  }) ? primaryToolbarComponent : undefined
216
- }
227
+ })
217
228
  };
218
229
  };
@@ -13,6 +13,7 @@ var _card = require("@atlaskit/editor-common/card");
13
13
  var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
14
14
  var _utils = require("@atlaskit/editor-common/utils");
15
15
  var _prosemirrorInputRules = require("@atlaskit/prosemirror-input-rules");
16
+ var _expValEquals = require("@atlaskit/tmp-editor-statsig/exp-val-equals");
16
17
  var _toolbarButtons = require("./toolbar-buttons");
17
18
  /**
18
19
  * Called when space after link, but not on enter
@@ -80,6 +81,7 @@ function createLinkInputRule(regexp, editorAnalyticsApi) {
80
81
  });
81
82
  }
82
83
  function createInputRulePlugin(schema, editorAnalyticsApi) {
84
+ var autoLinkOnBlur = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
83
85
  if (!schema.marks.link) {
84
86
  return;
85
87
  }
@@ -113,6 +115,9 @@ function createInputRulePlugin(schema, editorAnalyticsApi) {
113
115
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent((0, _utils.getLinkCreationAnalyticsEvent)(_analytics.INPUT_METHOD.FORMATTING, url))(tr);
114
116
  return tr;
115
117
  });
116
- return new _safePlugin.SafePlugin((0, _prosemirrorInputRules.createPlugin)('hyperlink', [urlWithASpaceRule, markdownLinkRule]));
118
+ return new _safePlugin.SafePlugin((0, _prosemirrorInputRules.createPlugin)('hyperlink', [urlWithASpaceRule, markdownLinkRule], autoLinkOnBlur && (0, _expValEquals.expValEquals)('platform_editor_create_link_on_blur', 'isEnabled', true) ? {
119
+ checkOnBlur: true,
120
+ appendTextOnBlur: ' '
121
+ } : undefined));
117
122
  }
118
123
  var _default = exports.default = createInputRulePlugin;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.getToolbarComponents = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
10
+ var _LinkButton = require("./toolbar/LinkButton");
11
+ var getToolbarComponents = exports.getToolbarComponents = function getToolbarComponents(api) {
12
+ var toolbarComponents = [{
13
+ type: _toolbar.LINKING_SECTION.type,
14
+ key: _toolbar.LINKING_SECTION.key,
15
+ parents: [{
16
+ type: 'toolbar',
17
+ key: _toolbar.TOOLBARS.INLINE_TEXT_TOOLBAR,
18
+ rank: _toolbar.TOOLBAR_RANK[_toolbar.LINKING_SECTION.key]
19
+ }]
20
+ }, {
21
+ type: _toolbar.LINKING_GROUP.type,
22
+ key: _toolbar.LINKING_GROUP.key,
23
+ parents: [{
24
+ type: _toolbar.LINKING_SECTION.type,
25
+ key: _toolbar.LINKING_SECTION.key,
26
+ rank: _toolbar.LINKING_SECTION_RANK[_toolbar.LINKING_GROUP.key]
27
+ }]
28
+ }, {
29
+ type: _toolbar.LINKING_BUTTON.type,
30
+ key: _toolbar.LINKING_BUTTON.key,
31
+ parents: [{
32
+ type: _toolbar.LINKING_GROUP.type,
33
+ key: _toolbar.LINKING_GROUP.key,
34
+ rank: _toolbar.LINKING_GROUP_RANK[_toolbar.LINKING_BUTTON.key]
35
+ }],
36
+ component: function component() {
37
+ return /*#__PURE__*/_react.default.createElement(_LinkButton.LinkButton, {
38
+ api: api
39
+ });
40
+ }
41
+ }];
42
+ return toolbarComponents;
43
+ };
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.LinkButton = void 0;
8
+ var _react = _interopRequireDefault(require("react"));
9
+ var _reactIntlNext = require("react-intl-next");
10
+ var _analytics = require("@atlaskit/editor-common/analytics");
11
+ var _messages = require("@atlaskit/editor-common/messages");
12
+ var _toolbar = require("@atlaskit/editor-common/toolbar");
13
+ var _utils = require("@atlaskit/editor-common/utils");
14
+ var _editorToolbar = require("@atlaskit/editor-toolbar");
15
+ var LinkButton = exports.LinkButton = function LinkButton(_ref) {
16
+ var api = _ref.api;
17
+ var _useIntl = (0, _reactIntlNext.useIntl)(),
18
+ formatMessage = _useIntl.formatMessage;
19
+ var _useEditorToolbar = (0, _toolbar.useEditorToolbar)(),
20
+ editorView = _useEditorToolbar.editorView;
21
+ var _ref2 = editorView !== null && editorView !== void 0 ? editorView : {
22
+ state: null,
23
+ dispatch: null
24
+ },
25
+ state = _ref2.state;
26
+ var onClick = function onClick() {
27
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.hyperlink.commands.showLinkToolbar(_analytics.INPUT_METHOD.FLOATING_TB));
28
+ };
29
+ var isEnabled = state !== null && state !== void 0 && state.selection ? (0, _utils.canLinkBeCreatedInRange)(state === null || state === void 0 ? void 0 : state.selection.from, state === null || state === void 0 ? void 0 : state.selection.to)(state) : false;
30
+ return (
31
+ /*#__PURE__*/
32
+ // TODO: ED-28743 - add keyboard shortcut here
33
+ _react.default.createElement(_editorToolbar.ToolbarTooltip, {
34
+ content: formatMessage(_messages.toolbarInsertBlockMessages.link)
35
+ }, /*#__PURE__*/_react.default.createElement(_editorToolbar.ToolbarButton, {
36
+ iconBefore: /*#__PURE__*/_react.default.createElement(_editorToolbar.LinkIcon, {
37
+ label: formatMessage(_messages.toolbarInsertBlockMessages.link)
38
+ }),
39
+ onClick: onClick,
40
+ testId: "editor-toolbar__link-button",
41
+ isDisabled: !isEnabled
42
+ }))
43
+ );
44
+ };
@@ -9,6 +9,7 @@ import { IconLink } from '@atlaskit/editor-common/quick-insert';
9
9
  import { canLinkBeCreatedInRange } from '@atlaskit/editor-common/utils';
10
10
  import LinkIcon from '@atlaskit/icon/core/migration/link--editor-link';
11
11
  import { fg } from '@atlaskit/platform-feature-flags';
12
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
13
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
13
14
  import { hideLinkToolbarSetMeta, insertLinkWithAnalytics, removeLinkEditorCommand, showLinkToolbar, updateLink, updateLinkEditorCommand } from './editor-commands/commands';
14
15
  import fakeCursorToolbarPlugin from './pm-plugins/fake-cursor-for-toolbar';
@@ -17,6 +18,7 @@ import { createKeymapPlugin } from './pm-plugins/keymap';
17
18
  import { plugin, stateKey } from './pm-plugins/main';
18
19
  import { toolbarButtonsPlugin } from './pm-plugins/toolbar-buttons';
19
20
  import { getToolbarConfig } from './ui/toolbar/Toolbar';
21
+ import { getToolbarComponents } from './ui/ToolbarComponents';
20
22
  const getPosFromActiveLinkMark = state => {
21
23
  if (state === undefined) {
22
24
  return undefined;
@@ -40,6 +42,10 @@ export const hyperlinkPlugin = ({
40
42
  api
41
43
  }) => {
42
44
  let primaryToolbarComponent;
45
+ if (expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true)) {
46
+ var _api$toolbar;
47
+ api === null || api === void 0 ? void 0 : (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 ? void 0 : _api$toolbar.actions.registerComponents(getToolbarComponents(api));
48
+ }
43
49
  return {
44
50
  name: 'hyperlink',
45
51
  marks() {
@@ -104,7 +110,7 @@ export const hyperlinkPlugin = ({
104
110
  schema
105
111
  }) => {
106
112
  var _api$analytics4;
107
- return createInputRulePlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
113
+ return createInputRulePlugin(schema, api === null || api === void 0 ? void 0 : (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, options.autoLinkOnBlur);
108
114
  }
109
115
  }, {
110
116
  name: 'hyperlinkKeymap',
@@ -154,47 +160,51 @@ export const hyperlinkPlugin = ({
154
160
  }
155
161
  }],
156
162
  floatingToolbar: getToolbarConfig(options, api),
157
- selectionToolbar: (state, {
158
- formatMessage
159
- }) => {
160
- var _api$userPreferences, _api$userPreferences$, _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3;
161
- const toolbarDocking = fg('platform_editor_use_preferences_plugin') ? api === null || api === void 0 ? void 0 : (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 ? void 0 : (_api$userPreferences$ = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences$ === void 0 ? void 0 : _api$userPreferences$.preferences.toolbarDockingPosition : api === null || api === void 0 ? void 0 : (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 ? void 0 : (_api$selectionToolbar2 = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar2 === void 0 ? void 0 : (_api$selectionToolbar3 = _api$selectionToolbar2.currentState()) === null || _api$selectionToolbar3 === void 0 ? void 0 : _api$selectionToolbar3.toolbarDocking;
162
- if (toolbarDocking === 'none' && editorExperiment('platform_editor_controls', 'variant1', {
163
- exposure: true
164
- })) {
165
- const toolbarButton = () => {
166
- const {
167
- from,
168
- to
169
- } = state.selection;
170
- const isEnabled = canLinkBeCreatedInRange(from, to)(state);
171
- const title = formatMessage(messages.link);
163
+ ...(!expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true) && {
164
+ selectionToolbar: (state, {
165
+ formatMessage
166
+ }) => {
167
+ var _api$userPreferences, _api$userPreferences$, _api$selectionToolbar, _api$selectionToolbar2, _api$selectionToolbar3;
168
+ const toolbarDocking = fg('platform_editor_use_preferences_plugin') ? api === null || api === void 0 ? void 0 : (_api$userPreferences = api.userPreferences) === null || _api$userPreferences === void 0 ? void 0 : (_api$userPreferences$ = _api$userPreferences.sharedState.currentState()) === null || _api$userPreferences$ === void 0 ? void 0 : _api$userPreferences$.preferences.toolbarDockingPosition : api === null || api === void 0 ? void 0 : (_api$selectionToolbar = api.selectionToolbar) === null || _api$selectionToolbar === void 0 ? void 0 : (_api$selectionToolbar2 = _api$selectionToolbar.sharedState) === null || _api$selectionToolbar2 === void 0 ? void 0 : (_api$selectionToolbar3 = _api$selectionToolbar2.currentState()) === null || _api$selectionToolbar3 === void 0 ? void 0 : _api$selectionToolbar3.toolbarDocking;
169
+ if (toolbarDocking === 'none' && editorExperiment('platform_editor_controls', 'variant1', {
170
+ exposure: true
171
+ })) {
172
+ const toolbarButton = () => {
173
+ const {
174
+ from,
175
+ to
176
+ } = state.selection;
177
+ const isEnabled = canLinkBeCreatedInRange(from, to)(state);
178
+ const title = formatMessage(messages.link);
179
+ return {
180
+ type: 'button',
181
+ disabled: !isEnabled,
182
+ testId: `${selectionToolbarLinkButtonTestId}`,
183
+ icon: LinkIcon,
184
+ title: title,
185
+ tooltipContent: tooltip(addLink, title),
186
+ showTitle: false,
187
+ onClick: (state, dispatch) => {
188
+ var _api$analytics7;
189
+ return editorCommandToPMCommand(showLinkToolbar(INPUT_METHOD.FLOATING_TB, api === null || api === void 0 ? void 0 : (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions))(state, dispatch);
190
+ }
191
+ };
192
+ };
172
193
  return {
173
- type: 'button',
174
- disabled: !isEnabled,
175
- testId: `${selectionToolbarLinkButtonTestId}`,
176
- icon: LinkIcon,
177
- title: title,
178
- tooltipContent: tooltip(addLink, title),
179
- showTitle: false,
180
- onClick: (state, dispatch) => {
181
- var _api$analytics7;
182
- return editorCommandToPMCommand(showLinkToolbar(INPUT_METHOD.FLOATING_TB, api === null || api === void 0 ? void 0 : (_api$analytics7 = api.analytics) === null || _api$analytics7 === void 0 ? void 0 : _api$analytics7.actions))(state, dispatch);
183
- }
194
+ isToolbarAbove: true,
195
+ items: [toolbarButton()],
196
+ rank: 2
184
197
  };
185
- };
186
- return {
187
- isToolbarAbove: true,
188
- items: [toolbarButton()],
189
- rank: 2
190
- };
191
- } else {
192
- return undefined;
198
+ } else {
199
+ return undefined;
200
+ }
193
201
  }
194
- },
195
- primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && editorExperiment('platform_editor_controls', 'variant1', {
196
- exposure: true
197
- }) ? primaryToolbarComponent : undefined
202
+ }),
203
+ ...(!expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true) && {
204
+ primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && editorExperiment('platform_editor_controls', 'variant1', {
205
+ exposure: true
206
+ }) ? primaryToolbarComponent : undefined
207
+ })
198
208
  }
199
209
  };
200
210
  };
@@ -3,6 +3,7 @@ import { addLinkMetadata } from '@atlaskit/editor-common/card';
3
3
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
4
4
  import { createRule, findFilepaths, getLinkCreationAnalyticsEvent, isLinkInMatches, LinkMatcher, normalizeUrl, shouldAutoLinkifyMatch } from '@atlaskit/editor-common/utils';
5
5
  import { createPlugin } from '@atlaskit/prosemirror-input-rules';
6
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
6
7
  import { toolbarKey } from './toolbar-buttons';
7
8
 
8
9
  /**
@@ -72,7 +73,7 @@ export function createLinkInputRule(regexp, editorAnalyticsApi) {
72
73
  return tr;
73
74
  });
74
75
  }
75
- export function createInputRulePlugin(schema, editorAnalyticsApi) {
76
+ export function createInputRulePlugin(schema, editorAnalyticsApi, autoLinkOnBlur = false) {
76
77
  if (!schema.marks.link) {
77
78
  return;
78
79
  }
@@ -105,6 +106,9 @@ export function createInputRulePlugin(schema, editorAnalyticsApi) {
105
106
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 ? void 0 : editorAnalyticsApi.attachAnalyticsEvent(getLinkCreationAnalyticsEvent(INPUT_METHOD.FORMATTING, url))(tr);
106
107
  return tr;
107
108
  });
108
- return new SafePlugin(createPlugin('hyperlink', [urlWithASpaceRule, markdownLinkRule]));
109
+ return new SafePlugin(createPlugin('hyperlink', [urlWithASpaceRule, markdownLinkRule], autoLinkOnBlur && expValEquals('platform_editor_create_link_on_blur', 'isEnabled', true) ? {
110
+ checkOnBlur: true,
111
+ appendTextOnBlur: ' '
112
+ } : undefined));
109
113
  }
110
114
  export default createInputRulePlugin;
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { LINKING_BUTTON, LINKING_GROUP, LINKING_GROUP_RANK, LINKING_SECTION, LINKING_SECTION_RANK, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
+ import { LinkButton } from './toolbar/LinkButton';
4
+ export const getToolbarComponents = api => {
5
+ const toolbarComponents = [{
6
+ type: LINKING_SECTION.type,
7
+ key: LINKING_SECTION.key,
8
+ parents: [{
9
+ type: 'toolbar',
10
+ key: TOOLBARS.INLINE_TEXT_TOOLBAR,
11
+ rank: TOOLBAR_RANK[LINKING_SECTION.key]
12
+ }]
13
+ }, {
14
+ type: LINKING_GROUP.type,
15
+ key: LINKING_GROUP.key,
16
+ parents: [{
17
+ type: LINKING_SECTION.type,
18
+ key: LINKING_SECTION.key,
19
+ rank: LINKING_SECTION_RANK[LINKING_GROUP.key]
20
+ }]
21
+ }, {
22
+ type: LINKING_BUTTON.type,
23
+ key: LINKING_BUTTON.key,
24
+ parents: [{
25
+ type: LINKING_GROUP.type,
26
+ key: LINKING_GROUP.key,
27
+ rank: LINKING_GROUP_RANK[LINKING_BUTTON.key]
28
+ }],
29
+ component: () => {
30
+ return /*#__PURE__*/React.createElement(LinkButton, {
31
+ api: api
32
+ });
33
+ }
34
+ }];
35
+ return toolbarComponents;
36
+ };
@@ -0,0 +1,41 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
6
+ import { canLinkBeCreatedInRange } from '@atlaskit/editor-common/utils';
7
+ import { LinkIcon, ToolbarButton, ToolbarTooltip } from '@atlaskit/editor-toolbar';
8
+ export const LinkButton = ({
9
+ api
10
+ }) => {
11
+ const {
12
+ formatMessage
13
+ } = useIntl();
14
+ const {
15
+ editorView
16
+ } = useEditorToolbar();
17
+ const {
18
+ state
19
+ } = editorView !== null && editorView !== void 0 ? editorView : {
20
+ state: null,
21
+ dispatch: null
22
+ };
23
+ const onClick = () => {
24
+ api === null || api === void 0 ? void 0 : api.core.actions.execute(api === null || api === void 0 ? void 0 : api.hyperlink.commands.showLinkToolbar(INPUT_METHOD.FLOATING_TB));
25
+ };
26
+ const isEnabled = state !== null && state !== void 0 && state.selection ? canLinkBeCreatedInRange(state === null || state === void 0 ? void 0 : state.selection.from, state === null || state === void 0 ? void 0 : state.selection.to)(state) : false;
27
+ return (
28
+ /*#__PURE__*/
29
+ // TODO: ED-28743 - add keyboard shortcut here
30
+ React.createElement(ToolbarTooltip, {
31
+ content: formatMessage(messages.link)
32
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
33
+ iconBefore: /*#__PURE__*/React.createElement(LinkIcon, {
34
+ label: formatMessage(messages.link)
35
+ }),
36
+ onClick: onClick,
37
+ testId: "editor-toolbar__link-button",
38
+ isDisabled: !isEnabled
39
+ }))
40
+ );
41
+ };
@@ -1,3 +1,6 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
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
+ 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; }
1
4
  import React from 'react';
2
5
  import { link } from '@atlaskit/adf-schema';
3
6
  import { ACTION, ACTION_SUBJECT, ACTION_SUBJECT_ID, EVENT_TYPE, INPUT_METHOD } from '@atlaskit/editor-common/analytics';
@@ -9,6 +12,7 @@ import { IconLink } from '@atlaskit/editor-common/quick-insert';
9
12
  import { canLinkBeCreatedInRange } from '@atlaskit/editor-common/utils';
10
13
  import LinkIcon from '@atlaskit/icon/core/migration/link--editor-link';
11
14
  import { fg } from '@atlaskit/platform-feature-flags';
15
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
12
16
  import { editorExperiment } from '@atlaskit/tmp-editor-statsig/experiments';
13
17
  import { hideLinkToolbarSetMeta, insertLinkWithAnalytics, removeLinkEditorCommand, showLinkToolbar as _showLinkToolbar, updateLink, updateLinkEditorCommand } from './editor-commands/commands';
14
18
  import fakeCursorToolbarPlugin from './pm-plugins/fake-cursor-for-toolbar';
@@ -17,6 +21,7 @@ import { createKeymapPlugin } from './pm-plugins/keymap';
17
21
  import { plugin as _plugin, stateKey } from './pm-plugins/main';
18
22
  import { toolbarButtonsPlugin } from './pm-plugins/toolbar-buttons';
19
23
  import { getToolbarConfig } from './ui/toolbar/Toolbar';
24
+ import { getToolbarComponents } from './ui/ToolbarComponents';
20
25
  var getPosFromActiveLinkMark = function getPosFromActiveLinkMark(state) {
21
26
  if (state === undefined) {
22
27
  return undefined;
@@ -40,6 +45,10 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
40
45
  options = _ref$config === void 0 ? {} : _ref$config,
41
46
  api = _ref.api;
42
47
  var primaryToolbarComponent;
48
+ if (expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true)) {
49
+ var _api$toolbar;
50
+ api === null || api === void 0 || (_api$toolbar = api.toolbar) === null || _api$toolbar === void 0 || _api$toolbar.actions.registerComponents(getToolbarComponents(api));
51
+ }
43
52
  return {
44
53
  name: 'hyperlink',
45
54
  marks: function marks() {
@@ -114,7 +123,7 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
114
123
  plugin: function plugin(_ref3) {
115
124
  var _api$analytics4;
116
125
  var schema = _ref3.schema;
117
- return createInputRulePlugin(schema, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions);
126
+ return createInputRulePlugin(schema, api === null || api === void 0 || (_api$analytics4 = api.analytics) === null || _api$analytics4 === void 0 ? void 0 : _api$analytics4.actions, options.autoLinkOnBlur);
118
127
  }
119
128
  }, {
120
129
  name: 'hyperlinkKeymap',
@@ -133,7 +142,7 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
133
142
  }
134
143
  }];
135
144
  },
136
- pluginsOptions: {
145
+ pluginsOptions: _objectSpread(_objectSpread({
137
146
  quickInsert: function quickInsert(_ref4) {
138
147
  var formatMessage = _ref4.formatMessage;
139
148
  return [{
@@ -166,7 +175,8 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
166
175
  }
167
176
  }];
168
177
  },
169
- floatingToolbar: getToolbarConfig(options, api),
178
+ floatingToolbar: getToolbarConfig(options, api)
179
+ }, !expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true) && {
170
180
  selectionToolbar: function selectionToolbar(state, _ref5) {
171
181
  var _api$userPreferences, _api$selectionToolbar;
172
182
  var formatMessage = _ref5.formatMessage;
@@ -202,10 +212,11 @@ export var hyperlinkPlugin = function hyperlinkPlugin(_ref) {
202
212
  } else {
203
213
  return undefined;
204
214
  }
205
- },
215
+ }
216
+ }), !expValEquals('platform_editor_toolbar_aifc', 'isEnabled', true) && {
206
217
  primaryToolbarComponent: !(api !== null && api !== void 0 && api.primaryToolbar) && editorExperiment('platform_editor_controls', 'variant1', {
207
218
  exposure: true
208
219
  }) ? primaryToolbarComponent : undefined
209
- }
220
+ })
210
221
  };
211
222
  };
@@ -4,6 +4,7 @@ import { addLinkMetadata } from '@atlaskit/editor-common/card';
4
4
  import { SafePlugin } from '@atlaskit/editor-common/safe-plugin';
5
5
  import { createRule, findFilepaths, getLinkCreationAnalyticsEvent, isLinkInMatches, LinkMatcher, normalizeUrl, shouldAutoLinkifyMatch } from '@atlaskit/editor-common/utils';
6
6
  import { createPlugin } from '@atlaskit/prosemirror-input-rules';
7
+ import { expValEquals } from '@atlaskit/tmp-editor-statsig/exp-val-equals';
7
8
  import { toolbarKey } from './toolbar-buttons';
8
9
 
9
10
  /**
@@ -72,6 +73,7 @@ export function createLinkInputRule(regexp, editorAnalyticsApi) {
72
73
  });
73
74
  }
74
75
  export function createInputRulePlugin(schema, editorAnalyticsApi) {
76
+ var autoLinkOnBlur = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false;
75
77
  if (!schema.marks.link) {
76
78
  return;
77
79
  }
@@ -105,6 +107,9 @@ export function createInputRulePlugin(schema, editorAnalyticsApi) {
105
107
  editorAnalyticsApi === null || editorAnalyticsApi === void 0 || editorAnalyticsApi.attachAnalyticsEvent(getLinkCreationAnalyticsEvent(INPUT_METHOD.FORMATTING, url))(tr);
106
108
  return tr;
107
109
  });
108
- return new SafePlugin(createPlugin('hyperlink', [urlWithASpaceRule, markdownLinkRule]));
110
+ return new SafePlugin(createPlugin('hyperlink', [urlWithASpaceRule, markdownLinkRule], autoLinkOnBlur && expValEquals('platform_editor_create_link_on_blur', 'isEnabled', true) ? {
111
+ checkOnBlur: true,
112
+ appendTextOnBlur: ' '
113
+ } : undefined));
109
114
  }
110
115
  export default createInputRulePlugin;
@@ -0,0 +1,36 @@
1
+ import React from 'react';
2
+ import { LINKING_BUTTON, LINKING_GROUP, LINKING_GROUP_RANK, LINKING_SECTION, LINKING_SECTION_RANK, TOOLBAR_RANK, TOOLBARS } from '@atlaskit/editor-common/toolbar';
3
+ import { LinkButton } from './toolbar/LinkButton';
4
+ export var getToolbarComponents = function getToolbarComponents(api) {
5
+ var toolbarComponents = [{
6
+ type: LINKING_SECTION.type,
7
+ key: LINKING_SECTION.key,
8
+ parents: [{
9
+ type: 'toolbar',
10
+ key: TOOLBARS.INLINE_TEXT_TOOLBAR,
11
+ rank: TOOLBAR_RANK[LINKING_SECTION.key]
12
+ }]
13
+ }, {
14
+ type: LINKING_GROUP.type,
15
+ key: LINKING_GROUP.key,
16
+ parents: [{
17
+ type: LINKING_SECTION.type,
18
+ key: LINKING_SECTION.key,
19
+ rank: LINKING_SECTION_RANK[LINKING_GROUP.key]
20
+ }]
21
+ }, {
22
+ type: LINKING_BUTTON.type,
23
+ key: LINKING_BUTTON.key,
24
+ parents: [{
25
+ type: LINKING_GROUP.type,
26
+ key: LINKING_GROUP.key,
27
+ rank: LINKING_GROUP_RANK[LINKING_BUTTON.key]
28
+ }],
29
+ component: function component() {
30
+ return /*#__PURE__*/React.createElement(LinkButton, {
31
+ api: api
32
+ });
33
+ }
34
+ }];
35
+ return toolbarComponents;
36
+ };
@@ -0,0 +1,37 @@
1
+ import React from 'react';
2
+ import { useIntl } from 'react-intl-next';
3
+ import { INPUT_METHOD } from '@atlaskit/editor-common/analytics';
4
+ import { toolbarInsertBlockMessages as messages } from '@atlaskit/editor-common/messages';
5
+ import { useEditorToolbar } from '@atlaskit/editor-common/toolbar';
6
+ import { canLinkBeCreatedInRange } from '@atlaskit/editor-common/utils';
7
+ import { LinkIcon, ToolbarButton, ToolbarTooltip } from '@atlaskit/editor-toolbar';
8
+ export var LinkButton = function LinkButton(_ref) {
9
+ var api = _ref.api;
10
+ var _useIntl = useIntl(),
11
+ formatMessage = _useIntl.formatMessage;
12
+ var _useEditorToolbar = useEditorToolbar(),
13
+ editorView = _useEditorToolbar.editorView;
14
+ var _ref2 = editorView !== null && editorView !== void 0 ? editorView : {
15
+ state: null,
16
+ dispatch: null
17
+ },
18
+ state = _ref2.state;
19
+ var onClick = function onClick() {
20
+ api === null || api === void 0 || api.core.actions.execute(api === null || api === void 0 ? void 0 : api.hyperlink.commands.showLinkToolbar(INPUT_METHOD.FLOATING_TB));
21
+ };
22
+ var isEnabled = state !== null && state !== void 0 && state.selection ? canLinkBeCreatedInRange(state === null || state === void 0 ? void 0 : state.selection.from, state === null || state === void 0 ? void 0 : state.selection.to)(state) : false;
23
+ return (
24
+ /*#__PURE__*/
25
+ // TODO: ED-28743 - add keyboard shortcut here
26
+ React.createElement(ToolbarTooltip, {
27
+ content: formatMessage(messages.link)
28
+ }, /*#__PURE__*/React.createElement(ToolbarButton, {
29
+ iconBefore: /*#__PURE__*/React.createElement(LinkIcon, {
30
+ label: formatMessage(messages.link)
31
+ }),
32
+ onClick: onClick,
33
+ testId: "editor-toolbar__link-button",
34
+ isDisabled: !isEnabled
35
+ }))
36
+ );
37
+ };
@@ -6,6 +6,7 @@ import type { ConnectivityPlugin } from '@atlaskit/editor-plugin-connectivity';
6
6
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
7
7
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
8
8
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
9
+ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
9
10
  import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
10
11
  import type { HideLinkToolbar, InsertLink, ShowLinkToolbar, UpdateLink } from './editor-commands/commands';
11
12
  type HyperlinkPluginCommands = {
@@ -53,7 +54,8 @@ export type HyperlinkPluginDependencies = [
53
54
  OptionalPlugin<ConnectivityPlugin>,
54
55
  OptionalPlugin<PrimaryToolbarPlugin>,
55
56
  OptionalPlugin<SelectionToolbarPlugin>,
56
- OptionalPlugin<UserPreferencesPlugin>
57
+ OptionalPlugin<UserPreferencesPlugin>,
58
+ OptionalPlugin<ToolbarPlugin>
57
59
  ];
58
60
  export type HyperlinkPluginActions = {
59
61
  hideLinkToolbar: HideLinkToolbar;
@@ -6,5 +6,5 @@ import type { Schema } from '@atlaskit/editor-prosemirror/model';
6
6
  * Called when space after link, but not on enter
7
7
  */
8
8
  export declare function createLinkInputRule(regexp: RegExp, editorAnalyticsApi: EditorAnalyticsAPI | undefined): InputRuleWrapper;
9
- export declare function createInputRulePlugin(schema: Schema, editorAnalyticsApi: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
9
+ export declare function createInputRulePlugin(schema: Schema, editorAnalyticsApi: EditorAnalyticsAPI | undefined, autoLinkOnBlur?: boolean): SafePlugin | undefined;
10
10
  export default createInputRulePlugin;
@@ -0,0 +1,4 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
3
+ import type { HyperlinkPlugin } from '../hyperlinkPluginType';
4
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<HyperlinkPlugin>) => RegisterComponent[];
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from "@atlaskit/editor-common/types";
3
+ import type { HyperlinkPlugin } from "../../hyperlinkPluginType";
4
+ type LinkButtonProps = {
5
+ api?: ExtractInjectionAPI<HyperlinkPlugin>;
6
+ };
7
+ export declare const LinkButton: ({ api }: LinkButtonProps) => React.JSX.Element;
8
+ export {};
@@ -6,6 +6,7 @@ import type { ConnectivityPlugin } from '@atlaskit/editor-plugin-connectivity';
6
6
  import type { EditorViewModePlugin } from '@atlaskit/editor-plugin-editor-viewmode';
7
7
  import type { PrimaryToolbarPlugin } from '@atlaskit/editor-plugin-primary-toolbar';
8
8
  import type { SelectionToolbarPlugin } from '@atlaskit/editor-plugin-selection-toolbar';
9
+ import type { ToolbarPlugin } from '@atlaskit/editor-plugin-toolbar';
9
10
  import type { UserPreferencesPlugin } from '@atlaskit/editor-plugin-user-preferences';
10
11
  import type { HideLinkToolbar, InsertLink, ShowLinkToolbar, UpdateLink } from './editor-commands/commands';
11
12
  type HyperlinkPluginCommands = {
@@ -53,7 +54,8 @@ export type HyperlinkPluginDependencies = [
53
54
  OptionalPlugin<ConnectivityPlugin>,
54
55
  OptionalPlugin<PrimaryToolbarPlugin>,
55
56
  OptionalPlugin<SelectionToolbarPlugin>,
56
- OptionalPlugin<UserPreferencesPlugin>
57
+ OptionalPlugin<UserPreferencesPlugin>,
58
+ OptionalPlugin<ToolbarPlugin>
57
59
  ];
58
60
  export type HyperlinkPluginActions = {
59
61
  hideLinkToolbar: HideLinkToolbar;
@@ -6,5 +6,5 @@ import type { Schema } from '@atlaskit/editor-prosemirror/model';
6
6
  * Called when space after link, but not on enter
7
7
  */
8
8
  export declare function createLinkInputRule(regexp: RegExp, editorAnalyticsApi: EditorAnalyticsAPI | undefined): InputRuleWrapper;
9
- export declare function createInputRulePlugin(schema: Schema, editorAnalyticsApi: EditorAnalyticsAPI | undefined): SafePlugin | undefined;
9
+ export declare function createInputRulePlugin(schema: Schema, editorAnalyticsApi: EditorAnalyticsAPI | undefined, autoLinkOnBlur?: boolean): SafePlugin | undefined;
10
10
  export default createInputRulePlugin;
@@ -0,0 +1,4 @@
1
+ import type { ExtractInjectionAPI } from '@atlaskit/editor-common/types';
2
+ import type { RegisterComponent } from '@atlaskit/editor-toolbar-model';
3
+ import type { HyperlinkPlugin } from '../hyperlinkPluginType';
4
+ export declare const getToolbarComponents: (api?: ExtractInjectionAPI<HyperlinkPlugin>) => RegisterComponent[];
@@ -0,0 +1,8 @@
1
+ import React from 'react';
2
+ import type { ExtractInjectionAPI } from "@atlaskit/editor-common/types";
3
+ import type { HyperlinkPlugin } from "../../hyperlinkPluginType";
4
+ type LinkButtonProps = {
5
+ api?: ExtractInjectionAPI<HyperlinkPlugin>;
6
+ };
7
+ export declare const LinkButton: ({ api }: LinkButtonProps) => React.JSX.Element;
8
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/editor-plugin-hyperlink",
3
- "version": "5.2.2",
3
+ "version": "5.4.0",
4
4
  "description": "Hyperlink plugin for @atlaskit/editor-core",
5
5
  "author": "Atlassian Pty Ltd",
6
6
  "license": "Apache-2.0",
@@ -39,18 +39,21 @@
39
39
  "@atlaskit/editor-plugin-connectivity": "^3.1.0",
40
40
  "@atlaskit/editor-plugin-editor-viewmode": "^5.0.0",
41
41
  "@atlaskit/editor-plugin-primary-toolbar": "^4.1.0",
42
- "@atlaskit/editor-plugin-selection-toolbar": "^4.2.0",
42
+ "@atlaskit/editor-plugin-selection-toolbar": "^4.3.0",
43
+ "@atlaskit/editor-plugin-toolbar": "^0.1.0",
43
44
  "@atlaskit/editor-prosemirror": "7.0.0",
44
- "@atlaskit/icon": "^27.9.0",
45
+ "@atlaskit/editor-toolbar": "^0.1.0",
46
+ "@atlaskit/editor-toolbar-model": "^0.0.4",
47
+ "@atlaskit/icon": "^27.10.0",
45
48
  "@atlaskit/platform-feature-flags": "^1.1.0",
46
- "@atlaskit/prosemirror-input-rules": "^3.3.0",
47
- "@atlaskit/tmp-editor-statsig": "^9.22.0",
49
+ "@atlaskit/prosemirror-input-rules": "^3.4.0",
50
+ "@atlaskit/tmp-editor-statsig": "^9.25.0",
48
51
  "@babel/runtime": "^7.0.0",
49
52
  "@emotion/react": "^11.7.1",
50
53
  "uuid": "^3.1.0"
51
54
  },
52
55
  "peerDependencies": {
53
- "@atlaskit/editor-common": "^107.16.0",
56
+ "@atlaskit/editor-common": "^107.19.0",
54
57
  "react": "^18.2.0",
55
58
  "react-dom": "^18.2.0",
56
59
  "react-intl-next": "npm:react-intl@^5.18.1"
@@ -64,7 +67,6 @@
64
67
  "@atlaskit/visual-regression": "workspace:^",
65
68
  "@testing-library/react": "^13.4.0",
66
69
  "raf-stub": "^2.0.1",
67
- "typescript": "~5.4.2",
68
70
  "wait-for-expect": "^1.2.0"
69
71
  },
70
72
  "techstack": {