@modusoperandi/licit 1.3.1 → 1.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/LinkSetURLCommand.js +1 -1
- package/LinkSetURLCommand.js.flow +1 -1
- package/LinkTooltipPlugin.js +140 -188
- package/LinkTooltipPlugin.js.flow +139 -195
- package/bom.xml +333 -332
- package/package.json +1 -1
- package/ui/LinkTooltip.js +4 -85
- package/ui/LinkTooltip.js.flow +3 -77
package/LinkSetURLCommand.js
CHANGED
|
@@ -114,7 +114,7 @@ var LinkSetURLCommand = /*#__PURE__*/function (_UICommand) {
|
|
|
114
114
|
return _context2.abrupt("return", Promise.resolve(undefined));
|
|
115
115
|
case 5:
|
|
116
116
|
from = selection.from, to = selection.to;
|
|
117
|
-
result = findNodesWithSameMark(doc, from, to, markType);
|
|
117
|
+
result = findNodesWithSameMark(doc, from, to - 1, markType);
|
|
118
118
|
href = result ? result.mark.attrs.href : null;
|
|
119
119
|
_context2.next = 10;
|
|
120
120
|
return _this.showTocList(view);
|
|
@@ -86,7 +86,7 @@ class LinkSetURLCommand extends UICommand {
|
|
|
86
86
|
return Promise.resolve(undefined);
|
|
87
87
|
}
|
|
88
88
|
const { from, to } = selection;
|
|
89
|
-
const result = findNodesWithSameMark(doc, from, to, markType);
|
|
89
|
+
const result = findNodesWithSameMark(doc, from, to - 1, markType);
|
|
90
90
|
const href = result ? result.mark.attrs.href : null;
|
|
91
91
|
const tocItemsNode = await this.showTocList(view);
|
|
92
92
|
const viewPops = {
|
package/LinkTooltipPlugin.js
CHANGED
|
@@ -15,23 +15,38 @@ function _isNativeReflectConstruct() { try { var t = !Boolean.prototype.valueOf.
|
|
|
15
15
|
function _getPrototypeOf(t) { return _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function (t) { return t.__proto__ || Object.getPrototypeOf(t); }, _getPrototypeOf(t); }
|
|
16
16
|
function _inherits(t, e) { if ("function" != typeof e && null !== e) throw new TypeError("Super expression must either be null or a function"); t.prototype = Object.create(e && e.prototype, { constructor: { value: t, writable: !0, configurable: !0 } }), Object.defineProperty(t, "prototype", { writable: !1 }), e && _setPrototypeOf(t, e); }
|
|
17
17
|
function _setPrototypeOf(t, e) { return _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function (t, e) { return t.__proto__ = e, t; }, _setPrototypeOf(t, e); }
|
|
18
|
-
import {
|
|
18
|
+
import { Plugin, PluginKey, TextSelection } from 'prosemirror-state';
|
|
19
19
|
import { EditorView } from 'prosemirror-view';
|
|
20
20
|
import { MARK_LINK } from './MarkNames.js';
|
|
21
|
-
import {
|
|
22
|
-
import { applyMark, findNodesWithSameMark, atAnchorTopCenter, createPopUp } from '@modusoperandi/licit-ui-commands';
|
|
21
|
+
import { atAnchorTopCenter, createPopUp, findNodesWithSameMark } from '@modusoperandi/licit-ui-commands';
|
|
23
22
|
import lookUpElement from './lookUpElement.js';
|
|
24
23
|
import LinkTooltip from './ui/LinkTooltip.js';
|
|
25
|
-
import
|
|
26
|
-
import
|
|
27
|
-
|
|
28
|
-
// https://prosemirror.net/examples/tooltip/
|
|
24
|
+
import scrollIntoView from 'smooth-scroll-into-view-if-needed';
|
|
25
|
+
import sanitizeURL from './sanitizeURL.js';
|
|
29
26
|
var SPEC = {
|
|
30
|
-
// [FS] IRAD-1005 2020-07-07
|
|
31
|
-
// Upgrade outdated packages.
|
|
32
27
|
key: new PluginKey('LinkTooltipPlugin'),
|
|
28
|
+
props: {
|
|
29
|
+
handleDOMEvents: {
|
|
30
|
+
mouseover: function mouseover(view, event) {
|
|
31
|
+
var _pluginView$_handleMo;
|
|
32
|
+
var pluginView = view.dom._linkTooltipView;
|
|
33
|
+
return (_pluginView$_handleMo = pluginView === null || pluginView === void 0 ? void 0 : pluginView._handleMouseOver(event)) !== null && _pluginView$_handleMo !== void 0 ? _pluginView$_handleMo : false;
|
|
34
|
+
},
|
|
35
|
+
mouseout: function mouseout(view, event) {
|
|
36
|
+
var pluginView = view.dom._linkTooltipView;
|
|
37
|
+
return pluginView === null || pluginView === void 0 ? void 0 : pluginView._handleMouseOut.call(view, event);
|
|
38
|
+
},
|
|
39
|
+
click: function click(view, event) {
|
|
40
|
+
var pluginView = view.dom._linkTooltipView;
|
|
41
|
+
return pluginView === null || pluginView === void 0 ? void 0 : pluginView._handleClick.call(view, event);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
33
45
|
view: function view(editorView) {
|
|
34
|
-
|
|
46
|
+
var pluginView = new LinkTooltipView(editorView);
|
|
47
|
+
// Store the instance for use in DOM handlers
|
|
48
|
+
editorView.dom._linkTooltipView = pluginView;
|
|
49
|
+
return pluginView;
|
|
35
50
|
}
|
|
36
51
|
};
|
|
37
52
|
var LinkTooltipPlugin = /*#__PURE__*/function (_Plugin) {
|
|
@@ -43,153 +58,78 @@ var LinkTooltipPlugin = /*#__PURE__*/function (_Plugin) {
|
|
|
43
58
|
return _createClass(LinkTooltipPlugin);
|
|
44
59
|
}(Plugin);
|
|
45
60
|
var LinkTooltipView = /*#__PURE__*/function () {
|
|
46
|
-
function LinkTooltipView(
|
|
61
|
+
function LinkTooltipView(_view) {
|
|
47
62
|
var _this = this;
|
|
48
63
|
_classCallCheck(this, LinkTooltipView);
|
|
49
|
-
_defineProperty(this, "_anchorEl", null);
|
|
50
64
|
_defineProperty(this, "_popup", null);
|
|
51
|
-
_defineProperty(this, "
|
|
52
|
-
_defineProperty(this, "
|
|
53
|
-
|
|
54
|
-
|
|
65
|
+
_defineProperty(this, "_anchorEl", null);
|
|
66
|
+
_defineProperty(this, "_view", null);
|
|
67
|
+
_defineProperty(this, "jumpLink", function (view, tocItemPos, href, selectionId) {
|
|
68
|
+
if (selectionId || selectionId === 0 && tocItemPos) {
|
|
69
|
+
_this.jumpInnerLink(view, tocItemPos);
|
|
70
|
+
} else {
|
|
71
|
+
_this._openLink(href);
|
|
72
|
+
}
|
|
55
73
|
});
|
|
56
|
-
_defineProperty(this, "
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
74
|
+
_defineProperty(this, "jumpInnerLink", function (view, tocItemPos) {
|
|
75
|
+
var transaction = view.state.tr;
|
|
76
|
+
var tr = transaction.setSelection(TextSelection.create(transaction.doc, tocItemPos.position + 1));
|
|
77
|
+
view.dispatch(tr.scrollIntoView(true));
|
|
78
|
+
var dom = view.domAtPos((tocItemPos === null || tocItemPos === void 0 ? void 0 : tocItemPos.position) + 1).node;
|
|
79
|
+
if (dom !== null && dom !== void 0 && dom.scrollIntoView) {
|
|
80
|
+
dom.scrollIntoView({
|
|
81
|
+
behavior: 'smooth',
|
|
82
|
+
block: 'start'
|
|
83
|
+
});
|
|
84
|
+
}
|
|
60
85
|
});
|
|
61
|
-
_defineProperty(this, "
|
|
62
|
-
|
|
63
|
-
var
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
86
|
+
_defineProperty(this, "_openLink", function (href) {
|
|
87
|
+
if (_this.isBookMarkHref(href)) {
|
|
88
|
+
var id = href.substr(1);
|
|
89
|
+
var el = document.getElementById(id);
|
|
90
|
+
if (el) {
|
|
91
|
+
var _this$props = _this.props,
|
|
92
|
+
onCancel = _this$props.onCancel,
|
|
93
|
+
editorView = _this$props.editorView;
|
|
94
|
+
onCancel(editorView);
|
|
95
|
+
_asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
96
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
97
|
+
while (1) switch (_context.prev = _context.next) {
|
|
98
|
+
case 0:
|
|
99
|
+
_context.next = 2;
|
|
100
|
+
return scrollIntoView(el, {
|
|
101
|
+
scrollMode: 'if-needed',
|
|
102
|
+
behavior: 'smooth'
|
|
103
|
+
});
|
|
104
|
+
case 2:
|
|
105
|
+
case "end":
|
|
106
|
+
return _context.stop();
|
|
73
107
|
}
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
return stylePromise.fetchStyles();
|
|
78
|
-
case 9:
|
|
79
|
-
styles = _context.sent;
|
|
80
|
-
storeTOCvalue = styles.filter(function (style // Added TOT/TOF selected styles to be listed as well
|
|
81
|
-
) {
|
|
82
|
-
var _style$styles, _style$styles2, _style$styles3;
|
|
83
|
-
return (style === null || style === void 0 || (_style$styles = style.styles) === null || _style$styles === void 0 ? void 0 : _style$styles.toc) === true || (style === null || style === void 0 || (_style$styles2 = style.styles) === null || _style$styles2 === void 0 ? void 0 : _style$styles2.tot) === true || (style === null || style === void 0 || (_style$styles3 = style.styles) === null || _style$styles3 === void 0 ? void 0 : _style$styles3.tof) === true;
|
|
84
|
-
}).map(function (style) {
|
|
85
|
-
return style === null || style === void 0 ? void 0 : style.styleName;
|
|
86
|
-
});
|
|
87
|
-
view.state.tr.doc.descendants(function (node, pos) {
|
|
88
|
-
if (node.attrs.styleName) {
|
|
89
|
-
for (var i = 0; i <= storeTOCvalue.length; i++) {
|
|
90
|
-
if (storeTOCvalue[i] === node.attrs.styleName) {
|
|
91
|
-
TOCselectedNode.push({
|
|
92
|
-
node_: node,
|
|
93
|
-
pos_: pos
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
return _context.abrupt("return", TOCselectedNode);
|
|
100
|
-
case 13:
|
|
101
|
-
case "end":
|
|
102
|
-
return _context.stop();
|
|
103
|
-
}
|
|
104
|
-
}, _callee);
|
|
105
|
-
}));
|
|
106
|
-
return function (_x) {
|
|
107
|
-
return _ref.apply(this, arguments);
|
|
108
|
-
};
|
|
109
|
-
}());
|
|
110
|
-
_defineProperty(this, "_onEdit", function (view) {
|
|
111
|
-
_this._popup.close();
|
|
112
|
-
if (_this._editor) {
|
|
113
|
-
return;
|
|
114
|
-
}
|
|
115
|
-
var state = view.state;
|
|
116
|
-
var schema = state.schema,
|
|
117
|
-
doc = state.doc,
|
|
118
|
-
selection = state.selection;
|
|
119
|
-
var from = selection.from,
|
|
120
|
-
to = selection.to;
|
|
121
|
-
var markType = schema.marks[MARK_LINK];
|
|
122
|
-
var result = findNodesWithSameMark(doc, from, to, markType);
|
|
123
|
-
if (!result) {
|
|
108
|
+
}, _callee);
|
|
109
|
+
}))();
|
|
110
|
+
}
|
|
124
111
|
return;
|
|
125
112
|
}
|
|
126
|
-
|
|
127
|
-
var
|
|
128
|
-
var
|
|
129
|
-
var
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
_this
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
}
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
});
|
|
143
|
-
_defineProperty(this, "_onRemove", function (view) {
|
|
144
|
-
_this._popup.close();
|
|
145
|
-
_this._onEditEnd(view, view.state.selection, null);
|
|
146
|
-
});
|
|
147
|
-
_defineProperty(this, "_onEditEnd", function (view, initialSelection, url) {
|
|
148
|
-
var state = view.state,
|
|
149
|
-
dispatch = view.dispatch;
|
|
150
|
-
var tr = hideSelectionPlaceholder(state);
|
|
151
|
-
if (url !== undefined) {
|
|
152
|
-
var schema = state.schema;
|
|
153
|
-
var markType = schema.marks[MARK_LINK];
|
|
154
|
-
if (markType) {
|
|
155
|
-
var result = findNodesWithSameMark(tr.doc, initialSelection.from, initialSelection.to, markType);
|
|
156
|
-
if (result) {
|
|
157
|
-
var linkSelection = TextSelection.create(tr.doc, result.from.pos, result.to.pos + 1);
|
|
158
|
-
tr = tr.setSelection(linkSelection);
|
|
159
|
-
var selectionId;
|
|
160
|
-
var href;
|
|
161
|
-
if (url === null) {
|
|
162
|
-
selectionId = null;
|
|
163
|
-
href = null;
|
|
164
|
-
} else if (url.includes(INNER_LINK)) {
|
|
165
|
-
selectionId = url.split(INNER_LINK)[0];
|
|
166
|
-
href = url.split(INNER_LINK)[1];
|
|
167
|
-
} else {
|
|
168
|
-
selectionId = null;
|
|
169
|
-
href = url;
|
|
170
|
-
}
|
|
171
|
-
var attrs = href ? {
|
|
172
|
-
href: href,
|
|
173
|
-
selectionId: selectionId
|
|
174
|
-
} : null;
|
|
175
|
-
tr = applyMark(tr, schema, markType, attrs);
|
|
176
|
-
|
|
177
|
-
// [FS] IRAD-1005 2020-07-09
|
|
178
|
-
// Upgrade outdated packages.
|
|
179
|
-
// reset selection to original using the latest doc.
|
|
180
|
-
var origSelection = TextSelection.create(tr.doc, initialSelection.from, initialSelection.to);
|
|
181
|
-
tr = tr.setSelection(origSelection);
|
|
182
|
-
}
|
|
113
|
+
if (href) {
|
|
114
|
+
var _this$_view;
|
|
115
|
+
var url = sanitizeURL(href);
|
|
116
|
+
var popupString;
|
|
117
|
+
if (_this._view.editable) {
|
|
118
|
+
popupString = 'Any unsaved changes will be lost';
|
|
119
|
+
} else {
|
|
120
|
+
popupString = '';
|
|
121
|
+
}
|
|
122
|
+
if ((_this$_view = _this._view) !== null && _this$_view !== void 0 && (_this$_view = _this$_view.runtime) !== null && _this$_view !== void 0 && _this$_view.openLinkDialog) {
|
|
123
|
+
_this._view.runtime.openLinkDialog(url, popupString);
|
|
124
|
+
} else {
|
|
125
|
+
window.open(url);
|
|
183
126
|
}
|
|
184
127
|
}
|
|
185
|
-
dispatch(tr);
|
|
186
|
-
view.focus();
|
|
187
128
|
});
|
|
188
|
-
this
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
value: function getInnerlinkSelected_position(view, selectionId) {
|
|
129
|
+
_defineProperty(this, "isBookMarkHref", function (href) {
|
|
130
|
+
return !!href && href.startsWith('#') && href.length >= 2;
|
|
131
|
+
});
|
|
132
|
+
_defineProperty(this, "getInnerlinkSelected_position", function (view, selectionId) {
|
|
193
133
|
var tocItemPos = null;
|
|
194
134
|
if (selectionId) {
|
|
195
135
|
view.state.tr.doc.descendants(function (node, pos) {
|
|
@@ -202,68 +142,80 @@ var LinkTooltipView = /*#__PURE__*/function () {
|
|
|
202
142
|
});
|
|
203
143
|
}
|
|
204
144
|
return tocItemPos;
|
|
145
|
+
});
|
|
146
|
+
this._view = _view;
|
|
147
|
+
}
|
|
148
|
+
return _createClass(LinkTooltipView, [{
|
|
149
|
+
key: "_handleMouseOver",
|
|
150
|
+
value: function _handleMouseOver(event) {
|
|
151
|
+
var _event$target,
|
|
152
|
+
_this$_popup,
|
|
153
|
+
_this2 = this;
|
|
154
|
+
var anchor = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.closest('a');
|
|
155
|
+
if (!anchor || anchor === this._anchorEl) return;
|
|
156
|
+
this._anchorEl = anchor;
|
|
157
|
+
var href = anchor.getAttribute('href');
|
|
158
|
+
(_this$_popup = this._popup) === null || _this$_popup === void 0 || _this$_popup.close();
|
|
159
|
+
this._popup = createPopUp(LinkTooltip, {
|
|
160
|
+
href: href,
|
|
161
|
+
selectionId: null,
|
|
162
|
+
editorView: this._view
|
|
163
|
+
}, {
|
|
164
|
+
anchor: anchor,
|
|
165
|
+
autoDismiss: true,
|
|
166
|
+
onClose: function onClose() {
|
|
167
|
+
_this2._popup = null;
|
|
168
|
+
_this2._anchorEl = null;
|
|
169
|
+
},
|
|
170
|
+
position: atAnchorTopCenter
|
|
171
|
+
});
|
|
205
172
|
}
|
|
206
173
|
}, {
|
|
207
|
-
key: "
|
|
208
|
-
value: function
|
|
209
|
-
var state =
|
|
174
|
+
key: "_handleClick",
|
|
175
|
+
value: function _handleClick(event) {
|
|
176
|
+
var state = this.dom._linkTooltipView._view.state;
|
|
210
177
|
var doc = state.doc,
|
|
211
178
|
selection = state.selection,
|
|
212
179
|
schema = state.schema;
|
|
213
|
-
var markType = schema.marks[MARK_LINK];
|
|
214
|
-
if (!markType) {
|
|
215
|
-
return;
|
|
216
|
-
}
|
|
217
180
|
var from = selection.from,
|
|
218
181
|
to = selection.to;
|
|
182
|
+
var markType = schema.marks[MARK_LINK];
|
|
219
183
|
var result = findNodesWithSameMark(doc, from, to, markType);
|
|
220
184
|
if (!result) {
|
|
221
|
-
|
|
222
|
-
return;
|
|
185
|
+
return false;
|
|
223
186
|
}
|
|
224
|
-
var domFound =
|
|
187
|
+
var domFound = this.dom._linkTooltipView._view.domAtPos(from);
|
|
225
188
|
if (!domFound) {
|
|
226
|
-
|
|
227
|
-
return;
|
|
189
|
+
return false;
|
|
228
190
|
}
|
|
229
|
-
var
|
|
191
|
+
var anchor = lookUpElement(domFound.node, function (el) {
|
|
230
192
|
return el.nodeName === 'A';
|
|
231
193
|
});
|
|
232
|
-
if (!
|
|
233
|
-
|
|
234
|
-
return;
|
|
194
|
+
if (!anchor) {
|
|
195
|
+
return false;
|
|
235
196
|
}
|
|
236
|
-
var
|
|
237
|
-
var
|
|
238
|
-
var
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
popup === null || popup === void 0 || popup.close();
|
|
252
|
-
this._anchorEl = anchorEl;
|
|
253
|
-
this._popup = createPopUp(LinkTooltip, viewPops, {
|
|
254
|
-
anchor: anchorEl,
|
|
255
|
-
autoDismiss: false,
|
|
256
|
-
onClose: this._onClose,
|
|
257
|
-
position: atAnchorTopCenter
|
|
258
|
-
});
|
|
197
|
+
var href = anchor.getAttribute('href');
|
|
198
|
+
var selectionId = anchor.getAttribute('selectionid');
|
|
199
|
+
var tocItemPos = this.dom._linkTooltipView.getInnerlinkSelected_position(this.dom._linkTooltipView._view, result.mark.attrs.selectionId);
|
|
200
|
+
this.dom._linkTooltipView.jumpLink(this.dom._linkTooltipView._view, tocItemPos, href, selectionId);
|
|
201
|
+
event.preventDefault(); // prevent default browser navigation
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
}, {
|
|
205
|
+
key: "_handleMouseOut",
|
|
206
|
+
value: function _handleMouseOut(event) {
|
|
207
|
+
if (this._anchorEl && !this._anchorEl.contains(event.relatedTarget)) {
|
|
208
|
+
var _this$_popup2;
|
|
209
|
+
(_this$_popup2 = this._popup) === null || _this$_popup2 === void 0 || _this$_popup2.close();
|
|
210
|
+
this._popup = null;
|
|
211
|
+
this._anchorEl = null;
|
|
259
212
|
}
|
|
260
213
|
}
|
|
261
214
|
}, {
|
|
262
215
|
key: "destroy",
|
|
263
216
|
value: function destroy() {
|
|
264
|
-
var _this$
|
|
265
|
-
(_this$
|
|
266
|
-
(_this$_editor = this._editor) === null || _this$_editor === void 0 || _this$_editor.close();
|
|
217
|
+
var _this$_popup3;
|
|
218
|
+
(_this$_popup3 = this._popup) === null || _this$_popup3 === void 0 || _this$_popup3.close();
|
|
267
219
|
}
|
|
268
220
|
}]);
|
|
269
221
|
}();
|