@atlaskit/editor-plugin-hyperlink 5.1.0 → 5.2.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 +12 -0
- package/dist/cjs/pm-plugins/main.js +5 -139
- package/dist/es2019/pm-plugins/main.js +5 -145
- package/dist/esm/pm-plugins/main.js +7 -141
- package/package.json +5 -8
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/editor-plugin-hyperlink
|
|
2
2
|
|
|
3
|
+
## 5.2.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#189119](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/pull-requests/189119)
|
|
8
|
+
[`3422f57cf2b75`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/3422f57cf2b75) -
|
|
9
|
+
Removing linking_platform_smart_links_in_live_pages FF
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
|
|
3
15
|
## 5.1.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
|
@@ -10,11 +10,8 @@ var _uuid = _interopRequireDefault(require("uuid"));
|
|
|
10
10
|
var _link3 = require("@atlaskit/editor-common/link");
|
|
11
11
|
var _safePlugin = require("@atlaskit/editor-common/safe-plugin");
|
|
12
12
|
var _utils = require("@atlaskit/editor-common/utils");
|
|
13
|
-
var _model = require("@atlaskit/editor-prosemirror/model");
|
|
14
13
|
var _state = require("@atlaskit/editor-prosemirror/state");
|
|
15
14
|
var _view = require("@atlaskit/editor-prosemirror/view");
|
|
16
|
-
var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
|
|
17
|
-
var _decorations2 = require("./decorations");
|
|
18
15
|
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
16
|
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
17
|
var mapTransactionToState = function mapTransactionToState(state, tr) {
|
|
@@ -171,75 +168,13 @@ var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance,
|
|
|
171
168
|
timesViewed: state.timesViewed,
|
|
172
169
|
searchSessionId: state.searchSessionId
|
|
173
170
|
};
|
|
174
|
-
state = _objectSpread(
|
|
171
|
+
state = _objectSpread({
|
|
175
172
|
activeText: state.activeText,
|
|
176
173
|
canInsertLink: state.canInsertLink,
|
|
177
174
|
inputMethod: inputMethod,
|
|
178
175
|
activeLinkMark: toState(state.activeLinkMark, action, newState),
|
|
179
176
|
editorAppearance: editorAppearance
|
|
180
177
|
}, stateForAnalytics);
|
|
181
|
-
if ((0, _platformFeatureFlags.fg)('linking_platform_smart_links_in_live_pages')) {
|
|
182
|
-
var _pluginInjectionApi$e;
|
|
183
|
-
var isViewMode = (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 || (_pluginInjectionApi$e = _pluginInjectionApi$e.sharedState.currentState()) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.mode) === 'view';
|
|
184
|
-
if (__livePage && !isViewMode) {
|
|
185
|
-
if (action === _link3.LinkAction.SET_CONFIGURE_DROPDOWN_OPEN) {
|
|
186
|
-
var configureDropdownOpen = tr.getMeta(stateKey).isOpen;
|
|
187
|
-
// Hide overlay when the dropdown is closed (state is updated to false)
|
|
188
|
-
var decorations = configureDropdownOpen ? {} : {
|
|
189
|
-
decorations: _view.DecorationSet.empty
|
|
190
|
-
};
|
|
191
|
-
state = _objectSpread(_objectSpread(_objectSpread({}, state), decorations), {}, {
|
|
192
|
-
configureDropdownOpen: configureDropdownOpen
|
|
193
|
-
});
|
|
194
|
-
}
|
|
195
|
-
if (action === _link3.LinkAction.SET_CONFIGURE_BUTTON_TARGET_POS) {
|
|
196
|
-
var configureButtonTargetPos = tr.getMeta(stateKey).pos;
|
|
197
|
-
var targetPosHasChanged = pluginState.configureButtonTargetPos !== configureButtonTargetPos;
|
|
198
|
-
var _decorations = pluginState.decorations;
|
|
199
|
-
if (targetPosHasChanged && state.configureDropdownOpen !== true) {
|
|
200
|
-
if (configureButtonTargetPos === undefined) {
|
|
201
|
-
_decorations = _view.DecorationSet.empty;
|
|
202
|
-
} else {
|
|
203
|
-
var decoration = _view.Decoration.widget(configureButtonTargetPos, function (view) {
|
|
204
|
-
return (0, _decorations2.ButtonWrapper)({
|
|
205
|
-
editorView: view,
|
|
206
|
-
pos: configureButtonTargetPos,
|
|
207
|
-
stateKey: stateKey,
|
|
208
|
-
intl: intl,
|
|
209
|
-
onOpenLinkClick: function onOpenLinkClick(event) {
|
|
210
|
-
var _node$marks$find, _pluginInjectionApi$a;
|
|
211
|
-
if (configureButtonTargetPos === undefined || typeof configureButtonTargetPos !== 'number') {
|
|
212
|
-
return;
|
|
213
|
-
}
|
|
214
|
-
var node = view.state.tr.doc.nodeAt(configureButtonTargetPos);
|
|
215
|
-
if (node === null) {
|
|
216
|
-
return;
|
|
217
|
-
}
|
|
218
|
-
var url = (_node$marks$find = node.marks.find(function (mark) {
|
|
219
|
-
return mark.type.name === 'link';
|
|
220
|
-
})) === null || _node$marks$find === void 0 ? void 0 : _node$marks$find.attrs.href;
|
|
221
|
-
if (!url) {
|
|
222
|
-
return;
|
|
223
|
-
}
|
|
224
|
-
(0, _link3.handleNavigation)({
|
|
225
|
-
fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.fireAnalyticsEvent,
|
|
226
|
-
onClickCallback: onClickCallback,
|
|
227
|
-
url: url,
|
|
228
|
-
event: event
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
});
|
|
232
|
-
});
|
|
233
|
-
_decorations = _view.DecorationSet.create(newState.doc, [decoration]);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
state = _objectSpread(_objectSpread({}, state), {}, {
|
|
237
|
-
configureButtonTargetPos: configureButtonTargetPos,
|
|
238
|
-
decorations: _decorations
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
178
|
}
|
|
244
179
|
var hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
|
|
245
180
|
if (tr.selectionSet && hasPositionChanged) {
|
|
@@ -260,16 +195,9 @@ var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance,
|
|
|
260
195
|
}
|
|
261
196
|
},
|
|
262
197
|
key: stateKey,
|
|
263
|
-
props:
|
|
264
|
-
decorations: function decorations(
|
|
265
|
-
|
|
266
|
-
var _stateKey$getState;
|
|
267
|
-
var _ref = (_stateKey$getState = stateKey.getState(state)) !== null && _stateKey$getState !== void 0 ? _stateKey$getState : {},
|
|
268
|
-
decorations = _ref.decorations;
|
|
269
|
-
return decorations;
|
|
270
|
-
} else {
|
|
271
|
-
return _view.DecorationSet.empty;
|
|
272
|
-
}
|
|
198
|
+
props: {
|
|
199
|
+
decorations: function decorations() {
|
|
200
|
+
return _view.DecorationSet.empty;
|
|
273
201
|
},
|
|
274
202
|
handleDOMEvents: {
|
|
275
203
|
// Ignored via go/ees005
|
|
@@ -305,71 +233,9 @@ var plugin = exports.plugin = function plugin(dispatch, intl, editorAppearance,
|
|
|
305
233
|
return false;
|
|
306
234
|
}
|
|
307
235
|
}
|
|
308
|
-
}
|
|
309
|
-
markViews: {
|
|
310
|
-
link: function link(mark, view, inline) {
|
|
311
|
-
var toDOM = mark.type.spec.toDOM;
|
|
312
|
-
if (!toDOM) {
|
|
313
|
-
throw new Error('toDom method missing');
|
|
314
|
-
}
|
|
315
|
-
var dom = _model.DOMSerializer.renderSpec(document, toDOM(mark, inline)).dom;
|
|
316
|
-
if (!(dom instanceof HTMLElement)) {
|
|
317
|
-
throw new Error('Error rendering hyperlink spec to dom');
|
|
318
|
-
}
|
|
319
|
-
var setTargetElementPos = function setTargetElementPos(val) {
|
|
320
|
-
var tr = view.state.tr;
|
|
321
|
-
tr.setMeta(stateKey, {
|
|
322
|
-
type: _link3.LinkAction.SET_CONFIGURE_BUTTON_TARGET_POS,
|
|
323
|
-
pos: val
|
|
324
|
-
});
|
|
325
|
-
view.dispatch(tr);
|
|
326
|
-
};
|
|
327
|
-
dom.onmouseenter = function () {
|
|
328
|
-
var _stateKey$getState2;
|
|
329
|
-
var _ref2 = (_stateKey$getState2 = stateKey.getState(view.state)) !== null && _stateKey$getState2 !== void 0 ? _stateKey$getState2 : {},
|
|
330
|
-
activeLinkMark = _ref2.activeLinkMark,
|
|
331
|
-
configureButtonTargetPos = _ref2.configureButtonTargetPos;
|
|
332
|
-
if (!activeLinkMark) {
|
|
333
|
-
var nodePos = view.posAtDOM(dom, -1);
|
|
334
|
-
if (nodePos !== configureButtonTargetPos) {
|
|
335
|
-
setTargetElementPos(nodePos);
|
|
336
|
-
}
|
|
337
|
-
}
|
|
338
|
-
};
|
|
339
|
-
dom.onmouseleave = function () {
|
|
340
|
-
var _stateKey$getState3;
|
|
341
|
-
var _ref3 = (_stateKey$getState3 = stateKey.getState(view.state)) !== null && _stateKey$getState3 !== void 0 ? _stateKey$getState3 : {},
|
|
342
|
-
configureButtonTargetPos = _ref3.configureButtonTargetPos;
|
|
343
|
-
if (configureButtonTargetPos !== undefined) {
|
|
344
|
-
setTargetElementPos(undefined);
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
dom.onclick = function (event) {
|
|
348
|
-
if (isDirectTarget(event, dom)) {
|
|
349
|
-
var _pluginInjectionApi$a2;
|
|
350
|
-
var url = mark.attrs.href;
|
|
351
|
-
// event is globalThis.MouseEvent, while handleNavigation
|
|
352
|
-
// (and editor-common OnClickCallback) require React.MouseEvent
|
|
353
|
-
var reactMouseEvent = event;
|
|
354
|
-
(0, _link3.handleNavigation)({
|
|
355
|
-
fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions.fireAnalyticsEvent,
|
|
356
|
-
onClickCallback: onClickCallback,
|
|
357
|
-
url: url,
|
|
358
|
-
event: reactMouseEvent
|
|
359
|
-
});
|
|
360
|
-
}
|
|
361
|
-
};
|
|
362
|
-
return {
|
|
363
|
-
dom: dom
|
|
364
|
-
};
|
|
365
|
-
}
|
|
366
|
-
}
|
|
367
|
-
})
|
|
236
|
+
}
|
|
368
237
|
});
|
|
369
238
|
};
|
|
370
239
|
function isLinkDirectTarget(event) {
|
|
371
240
|
return (event === null || event === void 0 ? void 0 : event.target) instanceof HTMLElement && event.target.tagName === 'A';
|
|
372
|
-
}
|
|
373
|
-
function isDirectTarget(event, element) {
|
|
374
|
-
return (event === null || event === void 0 ? void 0 : event.target) instanceof HTMLElement && event.target === element;
|
|
375
241
|
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
import uuid from 'uuid';
|
|
2
|
-
import {
|
|
2
|
+
import { 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
|
-
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
6
5
|
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
7
|
-
import {
|
|
8
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
9
|
-
import { ButtonWrapper } from './decorations';
|
|
6
|
+
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
10
7
|
const mapTransactionToState = (state, tr) => {
|
|
11
8
|
if (!state) {
|
|
12
9
|
return undefined;
|
|
@@ -169,7 +166,6 @@ export const plugin = (dispatch, intl, editorAppearance, pluginInjectionApi, onC
|
|
|
169
166
|
searchSessionId: state.searchSessionId
|
|
170
167
|
};
|
|
171
168
|
state = {
|
|
172
|
-
...(__livePage && fg('linking_platform_smart_links_in_live_pages') && state),
|
|
173
169
|
activeText: state.activeText,
|
|
174
170
|
canInsertLink: state.canInsertLink,
|
|
175
171
|
inputMethod,
|
|
@@ -177,69 +173,6 @@ export const plugin = (dispatch, intl, editorAppearance, pluginInjectionApi, onC
|
|
|
177
173
|
editorAppearance,
|
|
178
174
|
...stateForAnalytics
|
|
179
175
|
};
|
|
180
|
-
if (fg('linking_platform_smart_links_in_live_pages')) {
|
|
181
|
-
var _pluginInjectionApi$e, _pluginInjectionApi$e2;
|
|
182
|
-
const isViewMode = (pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 ? void 0 : (_pluginInjectionApi$e2 = _pluginInjectionApi$e.sharedState.currentState()) === null || _pluginInjectionApi$e2 === void 0 ? void 0 : _pluginInjectionApi$e2.mode) === 'view';
|
|
183
|
-
if (__livePage && !isViewMode) {
|
|
184
|
-
if (action === LinkAction.SET_CONFIGURE_DROPDOWN_OPEN) {
|
|
185
|
-
const configureDropdownOpen = tr.getMeta(stateKey).isOpen;
|
|
186
|
-
// Hide overlay when the dropdown is closed (state is updated to false)
|
|
187
|
-
const decorations = configureDropdownOpen ? {} : {
|
|
188
|
-
decorations: DecorationSet.empty
|
|
189
|
-
};
|
|
190
|
-
state = {
|
|
191
|
-
...state,
|
|
192
|
-
...decorations,
|
|
193
|
-
configureDropdownOpen
|
|
194
|
-
};
|
|
195
|
-
}
|
|
196
|
-
if (action === LinkAction.SET_CONFIGURE_BUTTON_TARGET_POS) {
|
|
197
|
-
const configureButtonTargetPos = tr.getMeta(stateKey).pos;
|
|
198
|
-
const targetPosHasChanged = pluginState.configureButtonTargetPos !== configureButtonTargetPos;
|
|
199
|
-
let decorations = pluginState.decorations;
|
|
200
|
-
if (targetPosHasChanged && state.configureDropdownOpen !== true) {
|
|
201
|
-
if (configureButtonTargetPos === undefined) {
|
|
202
|
-
decorations = DecorationSet.empty;
|
|
203
|
-
} else {
|
|
204
|
-
const decoration = Decoration.widget(configureButtonTargetPos, view => {
|
|
205
|
-
return ButtonWrapper({
|
|
206
|
-
editorView: view,
|
|
207
|
-
pos: configureButtonTargetPos,
|
|
208
|
-
stateKey,
|
|
209
|
-
intl,
|
|
210
|
-
onOpenLinkClick: event => {
|
|
211
|
-
var _node$marks$find, _pluginInjectionApi$a;
|
|
212
|
-
if (configureButtonTargetPos === undefined || typeof configureButtonTargetPos !== 'number') {
|
|
213
|
-
return;
|
|
214
|
-
}
|
|
215
|
-
const node = view.state.tr.doc.nodeAt(configureButtonTargetPos);
|
|
216
|
-
if (node === null) {
|
|
217
|
-
return;
|
|
218
|
-
}
|
|
219
|
-
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;
|
|
220
|
-
if (!url) {
|
|
221
|
-
return;
|
|
222
|
-
}
|
|
223
|
-
handleNavigation({
|
|
224
|
-
fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.fireAnalyticsEvent,
|
|
225
|
-
onClickCallback,
|
|
226
|
-
url,
|
|
227
|
-
event
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
});
|
|
231
|
-
});
|
|
232
|
-
decorations = DecorationSet.create(newState.doc, [decoration]);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
state = {
|
|
236
|
-
...state,
|
|
237
|
-
configureButtonTargetPos,
|
|
238
|
-
decorations
|
|
239
|
-
};
|
|
240
|
-
}
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
176
|
}
|
|
244
177
|
const hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
|
|
245
178
|
if (tr.selectionSet && hasPositionChanged) {
|
|
@@ -261,16 +194,8 @@ export const plugin = (dispatch, intl, editorAppearance, pluginInjectionApi, onC
|
|
|
261
194
|
},
|
|
262
195
|
key: stateKey,
|
|
263
196
|
props: {
|
|
264
|
-
decorations:
|
|
265
|
-
|
|
266
|
-
var _stateKey$getState;
|
|
267
|
-
const {
|
|
268
|
-
decorations
|
|
269
|
-
} = (_stateKey$getState = stateKey.getState(state)) !== null && _stateKey$getState !== void 0 ? _stateKey$getState : {};
|
|
270
|
-
return decorations;
|
|
271
|
-
} else {
|
|
272
|
-
return DecorationSet.empty;
|
|
273
|
-
}
|
|
197
|
+
decorations: () => {
|
|
198
|
+
return DecorationSet.empty;
|
|
274
199
|
},
|
|
275
200
|
handleDOMEvents: {
|
|
276
201
|
// Ignored via go/ees005
|
|
@@ -311,74 +236,9 @@ export const plugin = (dispatch, intl, editorAppearance, pluginInjectionApi, onC
|
|
|
311
236
|
}
|
|
312
237
|
return false;
|
|
313
238
|
}
|
|
314
|
-
}
|
|
315
|
-
...(__livePage && fg('linking_platform_smart_links_in_live_pages') && {
|
|
316
|
-
markViews: {
|
|
317
|
-
link: (mark, view, inline) => {
|
|
318
|
-
const toDOM = mark.type.spec.toDOM;
|
|
319
|
-
if (!toDOM) {
|
|
320
|
-
throw new Error('toDom method missing');
|
|
321
|
-
}
|
|
322
|
-
const dom = DOMSerializer.renderSpec(document, toDOM(mark, inline)).dom;
|
|
323
|
-
if (!(dom instanceof HTMLElement)) {
|
|
324
|
-
throw new Error('Error rendering hyperlink spec to dom');
|
|
325
|
-
}
|
|
326
|
-
const setTargetElementPos = val => {
|
|
327
|
-
const tr = view.state.tr;
|
|
328
|
-
tr.setMeta(stateKey, {
|
|
329
|
-
type: LinkAction.SET_CONFIGURE_BUTTON_TARGET_POS,
|
|
330
|
-
pos: val
|
|
331
|
-
});
|
|
332
|
-
view.dispatch(tr);
|
|
333
|
-
};
|
|
334
|
-
dom.onmouseenter = () => {
|
|
335
|
-
var _stateKey$getState2;
|
|
336
|
-
const {
|
|
337
|
-
activeLinkMark,
|
|
338
|
-
configureButtonTargetPos
|
|
339
|
-
} = (_stateKey$getState2 = stateKey.getState(view.state)) !== null && _stateKey$getState2 !== void 0 ? _stateKey$getState2 : {};
|
|
340
|
-
if (!activeLinkMark) {
|
|
341
|
-
const nodePos = view.posAtDOM(dom, -1);
|
|
342
|
-
if (nodePos !== configureButtonTargetPos) {
|
|
343
|
-
setTargetElementPos(nodePos);
|
|
344
|
-
}
|
|
345
|
-
}
|
|
346
|
-
};
|
|
347
|
-
dom.onmouseleave = () => {
|
|
348
|
-
var _stateKey$getState3;
|
|
349
|
-
const {
|
|
350
|
-
configureButtonTargetPos
|
|
351
|
-
} = (_stateKey$getState3 = stateKey.getState(view.state)) !== null && _stateKey$getState3 !== void 0 ? _stateKey$getState3 : {};
|
|
352
|
-
if (configureButtonTargetPos !== undefined) {
|
|
353
|
-
setTargetElementPos(undefined);
|
|
354
|
-
}
|
|
355
|
-
};
|
|
356
|
-
dom.onclick = event => {
|
|
357
|
-
if (isDirectTarget(event, dom)) {
|
|
358
|
-
var _pluginInjectionApi$a2;
|
|
359
|
-
const url = mark.attrs.href;
|
|
360
|
-
// event is globalThis.MouseEvent, while handleNavigation
|
|
361
|
-
// (and editor-common OnClickCallback) require React.MouseEvent
|
|
362
|
-
const reactMouseEvent = event;
|
|
363
|
-
handleNavigation({
|
|
364
|
-
fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 ? void 0 : (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions.fireAnalyticsEvent,
|
|
365
|
-
onClickCallback,
|
|
366
|
-
url,
|
|
367
|
-
event: reactMouseEvent
|
|
368
|
-
});
|
|
369
|
-
}
|
|
370
|
-
};
|
|
371
|
-
return {
|
|
372
|
-
dom: dom
|
|
373
|
-
};
|
|
374
|
-
}
|
|
375
|
-
}
|
|
376
|
-
})
|
|
239
|
+
}
|
|
377
240
|
}
|
|
378
241
|
});
|
|
379
242
|
function isLinkDirectTarget(event) {
|
|
380
243
|
return (event === null || event === void 0 ? void 0 : event.target) instanceof HTMLElement && event.target.tagName === 'A';
|
|
381
|
-
}
|
|
382
|
-
function isDirectTarget(event, element) {
|
|
383
|
-
return (event === null || event === void 0 ? void 0 : event.target) instanceof HTMLElement && event.target === element;
|
|
384
244
|
}
|
|
@@ -2,14 +2,11 @@ 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 {
|
|
5
|
+
import { 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
|
-
import { DOMSerializer } from '@atlaskit/editor-prosemirror/model';
|
|
9
8
|
import { PluginKey, TextSelection } from '@atlaskit/editor-prosemirror/state';
|
|
10
|
-
import {
|
|
11
|
-
import { fg } from '@atlaskit/platform-feature-flags';
|
|
12
|
-
import { ButtonWrapper } from './decorations';
|
|
9
|
+
import { DecorationSet } from '@atlaskit/editor-prosemirror/view';
|
|
13
10
|
var mapTransactionToState = function mapTransactionToState(state, tr) {
|
|
14
11
|
if (!state) {
|
|
15
12
|
return undefined;
|
|
@@ -164,75 +161,13 @@ export var plugin = function plugin(dispatch, intl, editorAppearance, pluginInje
|
|
|
164
161
|
timesViewed: state.timesViewed,
|
|
165
162
|
searchSessionId: state.searchSessionId
|
|
166
163
|
};
|
|
167
|
-
state = _objectSpread(
|
|
164
|
+
state = _objectSpread({
|
|
168
165
|
activeText: state.activeText,
|
|
169
166
|
canInsertLink: state.canInsertLink,
|
|
170
167
|
inputMethod: inputMethod,
|
|
171
168
|
activeLinkMark: toState(state.activeLinkMark, action, newState),
|
|
172
169
|
editorAppearance: editorAppearance
|
|
173
170
|
}, stateForAnalytics);
|
|
174
|
-
if (fg('linking_platform_smart_links_in_live_pages')) {
|
|
175
|
-
var _pluginInjectionApi$e;
|
|
176
|
-
var isViewMode = (pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$e = pluginInjectionApi.editorViewMode) === null || _pluginInjectionApi$e === void 0 || (_pluginInjectionApi$e = _pluginInjectionApi$e.sharedState.currentState()) === null || _pluginInjectionApi$e === void 0 ? void 0 : _pluginInjectionApi$e.mode) === 'view';
|
|
177
|
-
if (__livePage && !isViewMode) {
|
|
178
|
-
if (action === LinkAction.SET_CONFIGURE_DROPDOWN_OPEN) {
|
|
179
|
-
var configureDropdownOpen = tr.getMeta(stateKey).isOpen;
|
|
180
|
-
// Hide overlay when the dropdown is closed (state is updated to false)
|
|
181
|
-
var decorations = configureDropdownOpen ? {} : {
|
|
182
|
-
decorations: DecorationSet.empty
|
|
183
|
-
};
|
|
184
|
-
state = _objectSpread(_objectSpread(_objectSpread({}, state), decorations), {}, {
|
|
185
|
-
configureDropdownOpen: configureDropdownOpen
|
|
186
|
-
});
|
|
187
|
-
}
|
|
188
|
-
if (action === LinkAction.SET_CONFIGURE_BUTTON_TARGET_POS) {
|
|
189
|
-
var configureButtonTargetPos = tr.getMeta(stateKey).pos;
|
|
190
|
-
var targetPosHasChanged = pluginState.configureButtonTargetPos !== configureButtonTargetPos;
|
|
191
|
-
var _decorations = pluginState.decorations;
|
|
192
|
-
if (targetPosHasChanged && state.configureDropdownOpen !== true) {
|
|
193
|
-
if (configureButtonTargetPos === undefined) {
|
|
194
|
-
_decorations = DecorationSet.empty;
|
|
195
|
-
} else {
|
|
196
|
-
var decoration = Decoration.widget(configureButtonTargetPos, function (view) {
|
|
197
|
-
return ButtonWrapper({
|
|
198
|
-
editorView: view,
|
|
199
|
-
pos: configureButtonTargetPos,
|
|
200
|
-
stateKey: stateKey,
|
|
201
|
-
intl: intl,
|
|
202
|
-
onOpenLinkClick: function onOpenLinkClick(event) {
|
|
203
|
-
var _node$marks$find, _pluginInjectionApi$a;
|
|
204
|
-
if (configureButtonTargetPos === undefined || typeof configureButtonTargetPos !== 'number') {
|
|
205
|
-
return;
|
|
206
|
-
}
|
|
207
|
-
var node = view.state.tr.doc.nodeAt(configureButtonTargetPos);
|
|
208
|
-
if (node === null) {
|
|
209
|
-
return;
|
|
210
|
-
}
|
|
211
|
-
var url = (_node$marks$find = node.marks.find(function (mark) {
|
|
212
|
-
return mark.type.name === 'link';
|
|
213
|
-
})) === null || _node$marks$find === void 0 ? void 0 : _node$marks$find.attrs.href;
|
|
214
|
-
if (!url) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
|
-
handleNavigation({
|
|
218
|
-
fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a === void 0 ? void 0 : _pluginInjectionApi$a.actions.fireAnalyticsEvent,
|
|
219
|
-
onClickCallback: onClickCallback,
|
|
220
|
-
url: url,
|
|
221
|
-
event: event
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
});
|
|
225
|
-
});
|
|
226
|
-
_decorations = DecorationSet.create(newState.doc, [decoration]);
|
|
227
|
-
}
|
|
228
|
-
}
|
|
229
|
-
state = _objectSpread(_objectSpread({}, state), {}, {
|
|
230
|
-
configureButtonTargetPos: configureButtonTargetPos,
|
|
231
|
-
decorations: _decorations
|
|
232
|
-
});
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
171
|
}
|
|
237
172
|
var hasPositionChanged = oldState.selection.from !== newState.selection.from || oldState.selection.to !== newState.selection.to;
|
|
238
173
|
if (tr.selectionSet && hasPositionChanged) {
|
|
@@ -253,16 +188,9 @@ export var plugin = function plugin(dispatch, intl, editorAppearance, pluginInje
|
|
|
253
188
|
}
|
|
254
189
|
},
|
|
255
190
|
key: stateKey,
|
|
256
|
-
props:
|
|
257
|
-
decorations: function decorations(
|
|
258
|
-
|
|
259
|
-
var _stateKey$getState;
|
|
260
|
-
var _ref = (_stateKey$getState = stateKey.getState(state)) !== null && _stateKey$getState !== void 0 ? _stateKey$getState : {},
|
|
261
|
-
decorations = _ref.decorations;
|
|
262
|
-
return decorations;
|
|
263
|
-
} else {
|
|
264
|
-
return DecorationSet.empty;
|
|
265
|
-
}
|
|
191
|
+
props: {
|
|
192
|
+
decorations: function decorations() {
|
|
193
|
+
return DecorationSet.empty;
|
|
266
194
|
},
|
|
267
195
|
handleDOMEvents: {
|
|
268
196
|
// Ignored via go/ees005
|
|
@@ -298,71 +226,9 @@ export var plugin = function plugin(dispatch, intl, editorAppearance, pluginInje
|
|
|
298
226
|
return false;
|
|
299
227
|
}
|
|
300
228
|
}
|
|
301
|
-
}
|
|
302
|
-
markViews: {
|
|
303
|
-
link: function link(mark, view, inline) {
|
|
304
|
-
var toDOM = mark.type.spec.toDOM;
|
|
305
|
-
if (!toDOM) {
|
|
306
|
-
throw new Error('toDom method missing');
|
|
307
|
-
}
|
|
308
|
-
var dom = DOMSerializer.renderSpec(document, toDOM(mark, inline)).dom;
|
|
309
|
-
if (!(dom instanceof HTMLElement)) {
|
|
310
|
-
throw new Error('Error rendering hyperlink spec to dom');
|
|
311
|
-
}
|
|
312
|
-
var setTargetElementPos = function setTargetElementPos(val) {
|
|
313
|
-
var tr = view.state.tr;
|
|
314
|
-
tr.setMeta(stateKey, {
|
|
315
|
-
type: LinkAction.SET_CONFIGURE_BUTTON_TARGET_POS,
|
|
316
|
-
pos: val
|
|
317
|
-
});
|
|
318
|
-
view.dispatch(tr);
|
|
319
|
-
};
|
|
320
|
-
dom.onmouseenter = function () {
|
|
321
|
-
var _stateKey$getState2;
|
|
322
|
-
var _ref2 = (_stateKey$getState2 = stateKey.getState(view.state)) !== null && _stateKey$getState2 !== void 0 ? _stateKey$getState2 : {},
|
|
323
|
-
activeLinkMark = _ref2.activeLinkMark,
|
|
324
|
-
configureButtonTargetPos = _ref2.configureButtonTargetPos;
|
|
325
|
-
if (!activeLinkMark) {
|
|
326
|
-
var nodePos = view.posAtDOM(dom, -1);
|
|
327
|
-
if (nodePos !== configureButtonTargetPos) {
|
|
328
|
-
setTargetElementPos(nodePos);
|
|
329
|
-
}
|
|
330
|
-
}
|
|
331
|
-
};
|
|
332
|
-
dom.onmouseleave = function () {
|
|
333
|
-
var _stateKey$getState3;
|
|
334
|
-
var _ref3 = (_stateKey$getState3 = stateKey.getState(view.state)) !== null && _stateKey$getState3 !== void 0 ? _stateKey$getState3 : {},
|
|
335
|
-
configureButtonTargetPos = _ref3.configureButtonTargetPos;
|
|
336
|
-
if (configureButtonTargetPos !== undefined) {
|
|
337
|
-
setTargetElementPos(undefined);
|
|
338
|
-
}
|
|
339
|
-
};
|
|
340
|
-
dom.onclick = function (event) {
|
|
341
|
-
if (isDirectTarget(event, dom)) {
|
|
342
|
-
var _pluginInjectionApi$a2;
|
|
343
|
-
var url = mark.attrs.href;
|
|
344
|
-
// event is globalThis.MouseEvent, while handleNavigation
|
|
345
|
-
// (and editor-common OnClickCallback) require React.MouseEvent
|
|
346
|
-
var reactMouseEvent = event;
|
|
347
|
-
handleNavigation({
|
|
348
|
-
fireAnalyticsEvent: pluginInjectionApi === null || pluginInjectionApi === void 0 || (_pluginInjectionApi$a2 = pluginInjectionApi.analytics) === null || _pluginInjectionApi$a2 === void 0 ? void 0 : _pluginInjectionApi$a2.actions.fireAnalyticsEvent,
|
|
349
|
-
onClickCallback: onClickCallback,
|
|
350
|
-
url: url,
|
|
351
|
-
event: reactMouseEvent
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
};
|
|
355
|
-
return {
|
|
356
|
-
dom: dom
|
|
357
|
-
};
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
})
|
|
229
|
+
}
|
|
361
230
|
});
|
|
362
231
|
};
|
|
363
232
|
function isLinkDirectTarget(event) {
|
|
364
233
|
return (event === null || event === void 0 ? void 0 : event.target) instanceof HTMLElement && event.target.tagName === 'A';
|
|
365
|
-
}
|
|
366
|
-
function isDirectTarget(event, element) {
|
|
367
|
-
return (event === null || event === void 0 ? void 0 : event.target) instanceof HTMLElement && event.target === element;
|
|
368
234
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/editor-plugin-hyperlink",
|
|
3
|
-
"version": "5.
|
|
3
|
+
"version": "5.2.0",
|
|
4
4
|
"description": "Hyperlink plugin for @atlaskit/editor-core",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -35,22 +35,22 @@
|
|
|
35
35
|
"@atlaskit/adf-schema": "^49.0.6",
|
|
36
36
|
"@atlaskit/analytics-next": "^11.1.0",
|
|
37
37
|
"@atlaskit/editor-plugin-analytics": "^3.0.0",
|
|
38
|
-
"@atlaskit/editor-plugin-card": "^7.
|
|
38
|
+
"@atlaskit/editor-plugin-card": "^7.2.0",
|
|
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
42
|
"@atlaskit/editor-plugin-selection-toolbar": "^4.2.0",
|
|
43
43
|
"@atlaskit/editor-prosemirror": "7.0.0",
|
|
44
|
-
"@atlaskit/icon": "^27.
|
|
44
|
+
"@atlaskit/icon": "^27.6.0",
|
|
45
45
|
"@atlaskit/platform-feature-flags": "^1.1.0",
|
|
46
46
|
"@atlaskit/prosemirror-input-rules": "^3.3.0",
|
|
47
|
-
"@atlaskit/tmp-editor-statsig": "^9.
|
|
47
|
+
"@atlaskit/tmp-editor-statsig": "^9.10.0",
|
|
48
48
|
"@babel/runtime": "^7.0.0",
|
|
49
49
|
"@emotion/react": "^11.7.1",
|
|
50
50
|
"uuid": "^3.1.0"
|
|
51
51
|
},
|
|
52
52
|
"peerDependencies": {
|
|
53
|
-
"@atlaskit/editor-common": "^107.
|
|
53
|
+
"@atlaskit/editor-common": "^107.11.0",
|
|
54
54
|
"react": "^18.2.0",
|
|
55
55
|
"react-dom": "^18.2.0",
|
|
56
56
|
"react-intl-next": "npm:react-intl@^5.18.1"
|
|
@@ -101,9 +101,6 @@
|
|
|
101
101
|
}
|
|
102
102
|
},
|
|
103
103
|
"platform-feature-flags": {
|
|
104
|
-
"linking_platform_smart_links_in_live_pages": {
|
|
105
|
-
"type": "boolean"
|
|
106
|
-
},
|
|
107
104
|
"platform_editor_use_preferences_plugin": {
|
|
108
105
|
"type": "boolean"
|
|
109
106
|
},
|