@nerd-bible/wordgard 0.6.2-beta11 → 0.6.2-beta13
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/dist/editor.d.ts +1 -1
- package/dist/editor.js +45 -42
- package/package.json +1 -1
package/dist/editor.d.ts
CHANGED
|
@@ -731,7 +731,7 @@ declare class Wordgard {
|
|
|
731
731
|
Facet that allows you to register handlers to override paste
|
|
732
732
|
behavior.
|
|
733
733
|
*/
|
|
734
|
-
static pasteHandler: GardState.Facet<(wg: Wordgard, event:
|
|
734
|
+
static pasteHandler: GardState.Facet<(wg: Wordgard, event: ClipboardEvent, slice: wordgard_doc.Slice, html: string, text: string) => boolean, readonly ((wg: Wordgard, event: ClipboardEvent, slice: wordgard_doc.Slice, html: string, text: string) => boolean)[]>;
|
|
735
735
|
/**
|
|
736
736
|
Perform a paste with the given content. This will run {@link
|
|
737
737
|
Wordgard.pasteHandler paste handlers} and, if none handles the
|
package/dist/editor.js
CHANGED
|
@@ -921,28 +921,6 @@ function logException(state, exception, context) {
|
|
|
921
921
|
console.error(exception);
|
|
922
922
|
}
|
|
923
923
|
|
|
924
|
-
let nav = typeof navigator != "undefined" ? navigator : { userAgent: "", vendor: "", platform: "" };
|
|
925
|
-
let doc = typeof document != "undefined" ? document : { documentElement: { style: {} } };
|
|
926
|
-
const edge = /*@__PURE__*/(() => /Edge\/(\d+)/.exec(nav.userAgent))();
|
|
927
|
-
const gecko = /*@__PURE__*/(() => !edge && /gecko\/(\d+)/i.test(nav.userAgent))();
|
|
928
|
-
const chrome = /*@__PURE__*/(() => !edge && /Chrome\/(\d+)/.exec(nav.userAgent))();
|
|
929
|
-
const webkit = /*@__PURE__*/(() => "webkitFontSmoothing" in doc.documentElement.style)();
|
|
930
|
-
const safari = /*@__PURE__*/(() => !edge && /Apple Computer/.test(nav.vendor))();
|
|
931
|
-
const ios = /*@__PURE__*/(() => safari && (/Mobile\/\w+/.test(nav.userAgent) || nav.maxTouchPoints > 2))();
|
|
932
|
-
var browser = /*@__PURE__*/(() => ({
|
|
933
|
-
mac: ios || /Mac/.test(nav.platform),
|
|
934
|
-
windows: /Win/.test(nav.platform),
|
|
935
|
-
linux: /Linux|X11/.test(nav.platform),
|
|
936
|
-
gecko_version: gecko ? +(/Firefox\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
|
|
937
|
-
chrome: !!chrome,
|
|
938
|
-
chrome_version: chrome ? +chrome[1] : 0,
|
|
939
|
-
ios,
|
|
940
|
-
android: /Android\b/.test(nav.userAgent),
|
|
941
|
-
webkit,
|
|
942
|
-
webkit_version: webkit ? +(/\bAppleWebKit\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
|
|
943
|
-
safari,
|
|
944
|
-
safari_version: safari ? +(/\bVersion\/(\d+(\.\d+)?)/.exec(nav.userAgent) || [0, 0])[1] : 0}))();
|
|
945
|
-
|
|
946
924
|
function getSelection(root) {
|
|
947
925
|
let target;
|
|
948
926
|
if (root.nodeType == 11) { target = root.getSelection ? root : root.ownerDocument;
|
|
@@ -952,17 +930,6 @@ function getSelection(root) {
|
|
|
952
930
|
}
|
|
953
931
|
return target.getSelection();
|
|
954
932
|
}
|
|
955
|
-
function getSelectionRange(root) {
|
|
956
|
-
let sel = getSelection(root);
|
|
957
|
-
if (!sel)
|
|
958
|
-
return null;
|
|
959
|
-
if (browser.safari && root.nodeType == 11) {
|
|
960
|
-
let range = sel.getComposedRanges(root)[0];
|
|
961
|
-
if (range)
|
|
962
|
-
return range;
|
|
963
|
-
}
|
|
964
|
-
return new StaticRange(sel.getRangeAt(0));
|
|
965
|
-
}
|
|
966
933
|
function hasSelection(dom, selection) {
|
|
967
934
|
if (!selection.focusNode)
|
|
968
935
|
return false;
|
|
@@ -2723,6 +2690,28 @@ function flattenH(rect, top) {
|
|
|
2723
2690
|
return rect.height ? new DOMRect(rect.left, top ? rect.top : rect.bottom, rect.width, 0) : rect;
|
|
2724
2691
|
}
|
|
2725
2692
|
|
|
2693
|
+
let nav = typeof navigator != "undefined" ? navigator : { userAgent: "", vendor: "", platform: "" };
|
|
2694
|
+
let doc = typeof document != "undefined" ? document : { documentElement: { style: {} } };
|
|
2695
|
+
const edge = /*@__PURE__*/(() => /Edge\/(\d+)/.exec(nav.userAgent))();
|
|
2696
|
+
const gecko = /*@__PURE__*/(() => !edge && /gecko\/(\d+)/i.test(nav.userAgent))();
|
|
2697
|
+
const chrome = /*@__PURE__*/(() => !edge && /Chrome\/(\d+)/.exec(nav.userAgent))();
|
|
2698
|
+
const webkit = /*@__PURE__*/(() => "webkitFontSmoothing" in doc.documentElement.style)();
|
|
2699
|
+
const safari = /*@__PURE__*/(() => !edge && /Apple Computer/.test(nav.vendor))();
|
|
2700
|
+
const ios = /*@__PURE__*/(() => safari && (/Mobile\/\w+/.test(nav.userAgent) || nav.maxTouchPoints > 2))();
|
|
2701
|
+
var browser = /*@__PURE__*/(() => ({
|
|
2702
|
+
mac: ios || /Mac/.test(nav.platform),
|
|
2703
|
+
windows: /Win/.test(nav.platform),
|
|
2704
|
+
linux: /Linux|X11/.test(nav.platform),
|
|
2705
|
+
gecko_version: gecko ? +(/Firefox\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
|
|
2706
|
+
chrome: !!chrome,
|
|
2707
|
+
chrome_version: chrome ? +chrome[1] : 0,
|
|
2708
|
+
ios,
|
|
2709
|
+
android: /Android\b/.test(nav.userAgent),
|
|
2710
|
+
webkit,
|
|
2711
|
+
webkit_version: webkit ? +(/\bAppleWebKit\/(\d+)/.exec(nav.userAgent) || [0, 0])[1] : 0,
|
|
2712
|
+
safari,
|
|
2713
|
+
safari_version: safari ? +(/\bVersion\/(\d+(\.\d+)?)/.exec(nav.userAgent) || [0, 0])[1] : 0}))();
|
|
2714
|
+
|
|
2726
2715
|
const clipboardOutputFilter = /*@__PURE__*/GardState.Facet.define({
|
|
2727
2716
|
name: "clipboardOutputFilter"
|
|
2728
2717
|
});
|
|
@@ -3905,6 +3894,8 @@ class InputState {
|
|
|
3905
3894
|
this.lastKeyCode = event.keyCode;
|
|
3906
3895
|
this.lastKeyTime = Date.now();
|
|
3907
3896
|
this.shiftKey = event.keyCode == 16 || event.shiftKey;
|
|
3897
|
+
if (this.composing && event.isComposing === false)
|
|
3898
|
+
compositionEnd(this.wg);
|
|
3908
3899
|
return false;
|
|
3909
3900
|
}
|
|
3910
3901
|
ignoreDuringComposition(event) {
|
|
@@ -3969,6 +3960,8 @@ class InputState {
|
|
|
3969
3960
|
return this.domMapping.mapPos(this.getDOMPos(node, offset), assoc);
|
|
3970
3961
|
}
|
|
3971
3962
|
beforeInput(event, data) {
|
|
3963
|
+
if (this.composing && event.isComposing === false)
|
|
3964
|
+
compositionEnd(this.wg);
|
|
3972
3965
|
let type = event.inputType, range;
|
|
3973
3966
|
let { wg } = this, sel = wg.state.selection;
|
|
3974
3967
|
if (data.domRange) {
|
|
@@ -3998,14 +3991,8 @@ class InputState {
|
|
|
3998
3991
|
Command.dispatch(wg, insertText, { from, to, insert, userEvent: "input.type" });
|
|
3999
3992
|
}
|
|
4000
3993
|
else if (type == "insertFromPaste") {
|
|
4001
|
-
let isSel = this.unflushedSelection;
|
|
4002
|
-
if (!isSel) {
|
|
4003
|
-
let r = data.domRange.range, domSel = getSelectionRange(wg.root);
|
|
4004
|
-
isSel = !!domSel && isEquivalentPosition(r.startContainer, r.startOffset, domSel.startContainer, domSel.startOffset) &&
|
|
4005
|
-
isEquivalentPosition(r.endContainer, r.endOffset, domSel.endContainer, domSel.endOffset);
|
|
4006
|
-
}
|
|
4007
3994
|
let transfer = event.dataTransfer;
|
|
4008
|
-
doPaste(wg, getHTML(transfer), getText(transfer),
|
|
3995
|
+
doPaste(wg, getHTML(transfer), getText(transfer), this.unflushedSelection ? wg.state.selection : range, null);
|
|
4009
3996
|
}
|
|
4010
3997
|
else if ((type == "insertReplacementText" || type == "insertFromYank")) {
|
|
4011
3998
|
let transfer = event.dataTransfer;
|
|
@@ -4110,6 +4097,8 @@ class InputState {
|
|
|
4110
4097
|
}
|
|
4111
4098
|
clearComposition() {
|
|
4112
4099
|
let comp = this.composing;
|
|
4100
|
+
if (!comp)
|
|
4101
|
+
return false;
|
|
4113
4102
|
this.composing = null;
|
|
4114
4103
|
this.compositionPendingKey = true;
|
|
4115
4104
|
this.compositionEndedAt = Date.now();
|
|
@@ -4196,8 +4185,15 @@ function computeHandlers(state) {
|
|
|
4196
4185
|
function doPaste(wg, html, text, targetRange, event) {
|
|
4197
4186
|
let { from, to } = targetRange || wg.state.selection.replacementRange;
|
|
4198
4187
|
let slice = readClipboard(wg.state, html, text, wg.state.doc.resolve(from), wg.inputState.shiftKey);
|
|
4199
|
-
if (!targetRange
|
|
4200
|
-
|
|
4188
|
+
if (!targetRange) {
|
|
4189
|
+
if (!event) {
|
|
4190
|
+
event = new ClipboardEvent("paste", { clipboardData: new DataTransfer });
|
|
4191
|
+
event.clipboardData.setData("text/html", html);
|
|
4192
|
+
event.clipboardData.setData("text/plain", text);
|
|
4193
|
+
}
|
|
4194
|
+
if (wg.state.facet(pasteHandler).some(h => h(wg, event, slice || Slice.empty, text, html)))
|
|
4195
|
+
return;
|
|
4196
|
+
}
|
|
4201
4197
|
if (slice) {
|
|
4202
4198
|
wg.dispatch({
|
|
4203
4199
|
changes: { correct: { from, to, insert: slice, fit: true }, local: true },
|
|
@@ -4548,6 +4544,13 @@ const baseHandlers = {
|
|
|
4548
4544
|
},
|
|
4549
4545
|
copy,
|
|
4550
4546
|
cut: copy,
|
|
4547
|
+
paste(wg, event) {
|
|
4548
|
+
let data = event.clipboardData;
|
|
4549
|
+
if (!data)
|
|
4550
|
+
return false;
|
|
4551
|
+
doPaste(wg, getHTML(data), getText(data), null, event);
|
|
4552
|
+
return true;
|
|
4553
|
+
},
|
|
4551
4554
|
drop(wg, event) {
|
|
4552
4555
|
let data = event.dataTransfer;
|
|
4553
4556
|
if (!data || wg.state.readOnly)
|