@harbour-enterprises/superdoc 0.13.2-rev1 → 0.13.2-rev11
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/chunks/{eventemitter3-DfVviFzP.cjs → eventemitter3-CHxWXmuK.cjs} +1 -1
- package/dist/chunks/{eventemitter3-BrspJk8q.es.js → eventemitter3-KKY27oz-.es.js} +1 -1
- package/dist/chunks/{index-KzH9VKHh.es.js → index-BqLFjUHn.es.js} +2 -2
- package/dist/chunks/{index-B0t3i_io.cjs → index-CweAXNfB.cjs} +2 -2
- package/dist/chunks/{index-D_HUrFWV.es.js → index-DS3W0eVB.es.js} +4 -4
- package/dist/chunks/{index-Bk160jQ2.cjs → index-kOMfCfBT.cjs} +4 -4
- package/dist/chunks/{jszip-BTAcmbVg.cjs → jszip-9bCX1h2W.cjs} +1 -1
- package/dist/chunks/{jszip-DckFs3A7.es.js → jszip-Cl3s9njw.es.js} +1 -1
- package/dist/chunks/{super-editor.es-DyTkLKR1.es.js → super-editor.es-C0XuFRew.es.js} +1501 -1191
- package/dist/chunks/{super-editor.es--NMYzIh3.cjs → super-editor.es-DNcda5wa.cjs} +1501 -1191
- package/dist/chunks/{url-CWyTQ-Xy.cjs → url-B8LY3nwf.cjs} +2 -2
- package/dist/chunks/{url-DsBQArCl.es.js → url-Bq00tGvm.es.js} +2 -2
- package/dist/chunks/{vue-Bi1uWinj.es.js → vue-BBJVqxjL.es.js} +10 -3
- package/dist/chunks/{vue-HIY1g7dm.cjs → vue-BBjMeYfo.cjs} +10 -3
- package/dist/chunks/{xml-js-CdiD26MJ.es.js → xml-js-1F0lia4t.es.js} +2 -2
- package/dist/chunks/{xml-js-Bu1ZZzmb.cjs → xml-js-BuAdLsHD.cjs} +2 -2
- package/dist/core/SuperDoc.d.ts +5 -0
- package/dist/core/SuperDoc.d.ts.map +1 -1
- package/dist/style.css +2 -2
- package/dist/super-editor/ai-writer.es.js +2 -2
- package/dist/super-editor/chunks/{converter-CJ9kHtZx.js → converter-g7XDS8H8.js} +632 -52
- package/dist/super-editor/chunks/{docx-zipper-scQqOWXA.js → docx-zipper-VpCXV0uV.js} +1 -1
- package/dist/super-editor/chunks/{editor-DM6yaxu_.js → editor-B3V2UfZk.js} +444 -707
- package/dist/super-editor/chunks/{toolbar-CIHbdcnv.js → toolbar-DbwzVBvd.js} +2 -3
- package/dist/super-editor/converter.es.js +2 -2
- package/dist/super-editor/core/Editor.d.ts +17 -3
- package/dist/super-editor/core/Editor.d.ts.map +1 -1
- package/dist/super-editor/core/InputRule.d.ts +7 -0
- package/dist/super-editor/core/InputRule.d.ts.map +1 -1
- package/dist/super-editor/core/helpers/annotator.d.ts +4 -0
- package/dist/super-editor/core/helpers/annotator.d.ts.map +1 -1
- package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts +2 -0
- package/dist/super-editor/core/helpers/setImageNodeSelection.d.ts.map +1 -0
- package/dist/super-editor/core/super-converter/exporter.d.ts.map +1 -1
- package/dist/super-editor/docx-zipper.es.js +2 -2
- package/dist/super-editor/editor.es.js +3 -3
- package/dist/super-editor/extensions/field-annotation/field-annotation.d.ts.map +1 -1
- package/dist/super-editor/extensions/field-annotation/fieldAnnotationHelpers/findRemovedFieldAnnotations.d.ts.map +1 -1
- package/dist/super-editor/extensions/image/imageHelpers/startImageUpload.d.ts.map +1 -1
- package/dist/super-editor/extensions/line-break/line-break.d.ts.map +1 -1
- package/dist/super-editor/extensions/noderesizer/noderesizer.d.ts.map +1 -1
- package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts +6 -1
- package/dist/super-editor/extensions/pagination/pagination-helpers.d.ts.map +1 -1
- package/dist/super-editor/extensions/pagination/pagination.d.ts.map +1 -1
- package/dist/super-editor/extensions/paragraph/paragraph.d.ts.map +1 -1
- package/dist/super-editor/file-zipper.es.js +1 -1
- package/dist/super-editor/style.css +2 -2
- package/dist/super-editor/super-editor.es.js +7 -7
- package/dist/super-editor/toolbar.es.js +2 -2
- package/dist/super-editor.cjs +2 -2
- package/dist/super-editor.es.js +2 -2
- package/dist/superdoc.cjs +21 -9
- package/dist/superdoc.es.js +22 -10
- package/dist/superdoc.umd.js +1184 -855
- package/dist/superdoc.umd.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as global$2, r as ref$1, c as createApp, a as computed, b as createElementBlock, o as openBlock, F as Fragment$1, d as renderList, n as normalizeClass, w as withModifiers, e as createCommentVNode, t as toDisplayString, f as createBaseVNode, i as inject, h as onBeforeMount, j as onMounted, k as onBeforeUnmount, l as watch, m as defineComponent, q as getCurrentInstance, s as onDeactivated, u as nextTick, v as createBlock, x as createVNode, y as unref, z as withCtx, A as createTextVNode, B as normalizeStyle, C as h, D as toRef, E as provide, G as mergeProps, H as cloneVNode, T as Text$2, I as withDirectives, J as watchEffect, K as shallowRef, L as vModelText, M as withKeys, N as reactive, O as readonly, P as Transition, Q as vShow, R as Comment, S as renderSlot, U as onActivated, V as Teleport, W as isVNode, X as onUnmounted } from "./vue-
|
|
1
|
+
import { g as global$2, r as ref$1, c as createApp, a as computed, b as createElementBlock, o as openBlock, F as Fragment$1, d as renderList, n as normalizeClass, w as withModifiers, e as createCommentVNode, t as toDisplayString, f as createBaseVNode, i as inject, h as onBeforeMount, j as onMounted, k as onBeforeUnmount, l as watch, m as defineComponent, q as getCurrentInstance, s as onDeactivated, u as nextTick, v as createBlock, x as createVNode, y as unref, z as withCtx, A as createTextVNode, B as normalizeStyle, C as h, D as toRef, E as provide, G as mergeProps, H as cloneVNode, T as Text$2, I as withDirectives, J as watchEffect, K as shallowRef, L as vModelText, M as withKeys, N as reactive, O as readonly, P as Transition, Q as vShow, R as Comment, S as renderSlot, U as onActivated, V as Teleport, W as isVNode, X as onUnmounted } from "./vue-BBJVqxjL.es.js";
|
|
2
2
|
import * as Y from "yjs";
|
|
3
3
|
import { UndoManager, Item as Item$2, ContentType, Text as Text$1, XmlElement, encodeStateAsUpdate } from "yjs";
|
|
4
4
|
var __defProp$2 = Object.defineProperty;
|
|
@@ -10941,7 +10941,7 @@ class NodeRange {
|
|
|
10941
10941
|
}
|
|
10942
10942
|
}
|
|
10943
10943
|
const emptyAttrs = /* @__PURE__ */ Object.create(null);
|
|
10944
|
-
let Node$
|
|
10944
|
+
let Node$1$1 = class Node2 {
|
|
10945
10945
|
/**
|
|
10946
10946
|
@internal
|
|
10947
10947
|
*/
|
|
@@ -11342,8 +11342,8 @@ let Node$2 = class Node2 {
|
|
|
11342
11342
|
return node2;
|
|
11343
11343
|
}
|
|
11344
11344
|
};
|
|
11345
|
-
Node$
|
|
11346
|
-
class TextNode extends Node$
|
|
11345
|
+
Node$1$1.prototype.text = void 0;
|
|
11346
|
+
class TextNode extends Node$1$1 {
|
|
11347
11347
|
/**
|
|
11348
11348
|
@internal
|
|
11349
11349
|
*/
|
|
@@ -11930,7 +11930,7 @@ let NodeType$1 = class NodeType {
|
|
|
11930
11930
|
create(attrs = null, content, marks) {
|
|
11931
11931
|
if (this.isText)
|
|
11932
11932
|
throw new Error("NodeType.create can't construct text nodes");
|
|
11933
|
-
return new Node$
|
|
11933
|
+
return new Node$1$1(this, this.computeAttrs(attrs), Fragment.from(content), Mark$1.setFrom(marks));
|
|
11934
11934
|
}
|
|
11935
11935
|
/**
|
|
11936
11936
|
Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but check the given content
|
|
@@ -11940,7 +11940,7 @@ let NodeType$1 = class NodeType {
|
|
|
11940
11940
|
createChecked(attrs = null, content, marks) {
|
|
11941
11941
|
content = Fragment.from(content);
|
|
11942
11942
|
this.checkContent(content);
|
|
11943
|
-
return new Node$
|
|
11943
|
+
return new Node$1$1(this, this.computeAttrs(attrs), content, Mark$1.setFrom(marks));
|
|
11944
11944
|
}
|
|
11945
11945
|
/**
|
|
11946
11946
|
Like [`create`](https://prosemirror.net/docs/ref/#model.NodeType.create), but see if it is
|
|
@@ -11963,7 +11963,7 @@ let NodeType$1 = class NodeType {
|
|
|
11963
11963
|
let after = matched && matched.fillBefore(Fragment.empty, true);
|
|
11964
11964
|
if (!after)
|
|
11965
11965
|
return null;
|
|
11966
|
-
return new Node$
|
|
11966
|
+
return new Node$1$1(this, attrs, content.append(after), Mark$1.setFrom(marks));
|
|
11967
11967
|
}
|
|
11968
11968
|
/**
|
|
11969
11969
|
Returns true if the given fragment is valid content for this node
|
|
@@ -12200,7 +12200,7 @@ let Schema$1 = class Schema {
|
|
|
12200
12200
|
bound.
|
|
12201
12201
|
*/
|
|
12202
12202
|
nodeFromJSON(json) {
|
|
12203
|
-
return Node$
|
|
12203
|
+
return Node$1$1.fromJSON(this, json);
|
|
12204
12204
|
}
|
|
12205
12205
|
/**
|
|
12206
12206
|
Deserialize a mark from its JSON representation. This method is
|
|
@@ -13726,7 +13726,7 @@ class ReplaceStep extends Step {
|
|
|
13726
13726
|
}
|
|
13727
13727
|
}
|
|
13728
13728
|
Step.jsonID("replace", ReplaceStep);
|
|
13729
|
-
|
|
13729
|
+
let ReplaceAroundStep$1 = class ReplaceAroundStep2 extends Step {
|
|
13730
13730
|
/**
|
|
13731
13731
|
Create a replace-around step with the given range and gap.
|
|
13732
13732
|
`insert` should be the point in the slice into which the content
|
|
@@ -13766,7 +13766,7 @@ class ReplaceAroundStep extends Step {
|
|
|
13766
13766
|
}
|
|
13767
13767
|
invert(doc2) {
|
|
13768
13768
|
let gap = this.gapTo - this.gapFrom;
|
|
13769
|
-
return new
|
|
13769
|
+
return new ReplaceAroundStep2(this.from, this.from + this.slice.size + gap, this.from + this.insert, this.from + this.insert + gap, doc2.slice(this.from, this.to).removeBetween(this.gapFrom - this.from, this.gapTo - this.from), this.gapFrom - this.from, this.structure);
|
|
13770
13770
|
}
|
|
13771
13771
|
map(mapping) {
|
|
13772
13772
|
let from2 = mapping.mapResult(this.from, 1), to = mapping.mapResult(this.to, -1);
|
|
@@ -13774,7 +13774,7 @@ class ReplaceAroundStep extends Step {
|
|
|
13774
13774
|
let gapTo = this.to == this.gapTo ? to.pos : mapping.map(this.gapTo, 1);
|
|
13775
13775
|
if (from2.deletedAcross && to.deletedAcross || gapFrom < from2.pos || gapTo > to.pos)
|
|
13776
13776
|
return null;
|
|
13777
|
-
return new
|
|
13777
|
+
return new ReplaceAroundStep2(from2.pos, to.pos, gapFrom, gapTo, this.slice, this.insert, this.structure);
|
|
13778
13778
|
}
|
|
13779
13779
|
toJSON() {
|
|
13780
13780
|
let json = {
|
|
@@ -13797,10 +13797,10 @@ class ReplaceAroundStep extends Step {
|
|
|
13797
13797
|
static fromJSON(schema, json) {
|
|
13798
13798
|
if (typeof json.from != "number" || typeof json.to != "number" || typeof json.gapFrom != "number" || typeof json.gapTo != "number" || typeof json.insert != "number")
|
|
13799
13799
|
throw new RangeError("Invalid input for ReplaceAroundStep.fromJSON");
|
|
13800
|
-
return new
|
|
13800
|
+
return new ReplaceAroundStep2(json.from, json.to, json.gapFrom, json.gapTo, Slice.fromJSON(schema, json.slice), json.insert, !!json.structure);
|
|
13801
13801
|
}
|
|
13802
|
-
}
|
|
13803
|
-
Step.jsonID("replaceAround", ReplaceAroundStep);
|
|
13802
|
+
};
|
|
13803
|
+
Step.jsonID("replaceAround", ReplaceAroundStep$1);
|
|
13804
13804
|
function contentBetween(doc2, from2, to) {
|
|
13805
13805
|
let $from = doc2.resolve(from2), dist2 = to - from2, depth = $from.depth;
|
|
13806
13806
|
while (dist2 > 0 && depth > 0 && $from.indexAfter(depth) == $from.node(depth).childCount) {
|
|
@@ -13953,7 +13953,7 @@ function lift(tr, range2, target) {
|
|
|
13953
13953
|
} else {
|
|
13954
13954
|
end2++;
|
|
13955
13955
|
}
|
|
13956
|
-
tr.step(new ReplaceAroundStep(start2, end2, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
|
|
13956
|
+
tr.step(new ReplaceAroundStep$1(start2, end2, gapStart, gapEnd, new Slice(before.append(after), openStart, openEnd), before.size - openStart, true));
|
|
13957
13957
|
}
|
|
13958
13958
|
function findWrapping(range2, nodeType, attrs = null, innerRange = range2) {
|
|
13959
13959
|
let around = findWrappingOutside(range2, nodeType);
|
|
@@ -13998,7 +13998,7 @@ function wrap(tr, range2, wrappers) {
|
|
|
13998
13998
|
content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
|
|
13999
13999
|
}
|
|
14000
14000
|
let start2 = range2.start, end2 = range2.end;
|
|
14001
|
-
tr.step(new ReplaceAroundStep(start2, end2, start2, end2, new Slice(content, 0, 0), wrappers.length, true));
|
|
14001
|
+
tr.step(new ReplaceAroundStep$1(start2, end2, start2, end2, new Slice(content, 0, 0), wrappers.length, true));
|
|
14002
14002
|
}
|
|
14003
14003
|
function setBlockType$1(tr, from2, to, type2, attrs) {
|
|
14004
14004
|
if (!type2.isTextblock)
|
|
@@ -14020,7 +14020,7 @@ function setBlockType$1(tr, from2, to, type2, attrs) {
|
|
|
14020
14020
|
clearIncompatible(tr, tr.mapping.slice(mapFrom).map(pos, 1), type2, void 0, convertNewlines === null);
|
|
14021
14021
|
let mapping = tr.mapping.slice(mapFrom);
|
|
14022
14022
|
let startM = mapping.map(pos, 1), endM = mapping.map(pos + node2.nodeSize, 1);
|
|
14023
|
-
tr.step(new ReplaceAroundStep(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type2.create(attrsHere, null, node2.marks)), 0, 0), 1, true));
|
|
14023
|
+
tr.step(new ReplaceAroundStep$1(startM, endM, startM + 1, endM - 1, new Slice(Fragment.from(type2.create(attrsHere, null, node2.marks)), 0, 0), 1, true));
|
|
14024
14024
|
if (convertNewlines === true)
|
|
14025
14025
|
replaceNewlines(tr, node2, pos, mapFrom);
|
|
14026
14026
|
return false;
|
|
@@ -14061,7 +14061,7 @@ function setNodeMarkup(tr, pos, type2, attrs, marks) {
|
|
|
14061
14061
|
return tr.replaceWith(pos, pos + node2.nodeSize, newNode);
|
|
14062
14062
|
if (!type2.validContent(node2.content))
|
|
14063
14063
|
throw new RangeError("Invalid content for node type " + type2.name);
|
|
14064
|
-
tr.step(new ReplaceAroundStep(pos, pos + node2.nodeSize, pos + 1, pos + node2.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));
|
|
14064
|
+
tr.step(new ReplaceAroundStep$1(pos, pos + node2.nodeSize, pos + 1, pos + node2.nodeSize - 1, new Slice(Fragment.from(newNode), 0, 0), 1, true));
|
|
14065
14065
|
}
|
|
14066
14066
|
function canSplit(doc2, pos, depth = 1, typesAfter) {
|
|
14067
14067
|
let $pos = doc2.resolve(pos), base2 = $pos.depth - depth;
|
|
@@ -14262,7 +14262,7 @@ class Fitter {
|
|
|
14262
14262
|
}
|
|
14263
14263
|
let slice2 = new Slice(content, openStart, openEnd);
|
|
14264
14264
|
if (moveInline > -1)
|
|
14265
|
-
return new ReplaceAroundStep($from.pos, moveInline, this.$to.pos, this.$to.end(), slice2, placedSize);
|
|
14265
|
+
return new ReplaceAroundStep$1($from.pos, moveInline, this.$to.pos, this.$to.end(), slice2, placedSize);
|
|
14266
14266
|
if (slice2.size || $from.pos != this.$to.pos)
|
|
14267
14267
|
return new ReplaceStep($from.pos, $to.pos, slice2);
|
|
14268
14268
|
return null;
|
|
@@ -15345,7 +15345,7 @@ function selectionToInsertionEnd$1(tr, startLen, bias) {
|
|
|
15345
15345
|
if (last < startLen)
|
|
15346
15346
|
return;
|
|
15347
15347
|
let step = tr.steps[last];
|
|
15348
|
-
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep))
|
|
15348
|
+
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep$1))
|
|
15349
15349
|
return;
|
|
15350
15350
|
let map3 = tr.mapping.maps[last], end2;
|
|
15351
15351
|
map3.forEach((_from, _to, _newFrom, newTo) => {
|
|
@@ -15760,7 +15760,7 @@ class EditorState {
|
|
|
15760
15760
|
let instance = new EditorState($config);
|
|
15761
15761
|
$config.fields.forEach((field) => {
|
|
15762
15762
|
if (field.name == "doc") {
|
|
15763
|
-
instance.doc = Node$
|
|
15763
|
+
instance.doc = Node$1$1.fromJSON(config.schema, json.doc);
|
|
15764
15764
|
} else if (field.name == "selection") {
|
|
15765
15765
|
instance.selection = Selection.fromJSON(instance.doc, json.selection);
|
|
15766
15766
|
} else if (field.name == "storedMarks") {
|
|
@@ -18821,210 +18821,787 @@ const createColGroup = (node2, cellMinWidth, overrideCol, overrideValue) => {
|
|
|
18821
18821
|
colgroupValues
|
|
18822
18822
|
};
|
|
18823
18823
|
};
|
|
18824
|
-
function
|
|
18825
|
-
|
|
18826
|
-
|
|
18827
|
-
|
|
18828
|
-
|
|
18829
|
-
|
|
18830
|
-
|
|
18831
|
-
|
|
18832
|
-
|
|
18833
|
-
|
|
18834
|
-
|
|
18835
|
-
|
|
18836
|
-
|
|
18837
|
-
|
|
18838
|
-
|
|
18839
|
-
|
|
18840
|
-
|
|
18841
|
-
|
|
18842
|
-
|
|
18843
|
-
|
|
18844
|
-
|
|
18845
|
-
|
|
18846
|
-
|
|
18847
|
-
|
|
18848
|
-
|
|
18849
|
-
"page-number": translatePageNumberNode,
|
|
18850
|
-
"total-page-number": translateTotalPageNumberNode
|
|
18824
|
+
function chainableEditorState(transaction, state2) {
|
|
18825
|
+
let { selection, doc: doc2, storedMarks } = transaction;
|
|
18826
|
+
return {
|
|
18827
|
+
...state2,
|
|
18828
|
+
apply: state2.apply.bind(state2),
|
|
18829
|
+
applyTransaction: state2.applyTransaction.bind(state2),
|
|
18830
|
+
plugins: state2.plugins,
|
|
18831
|
+
schema: state2.schema,
|
|
18832
|
+
reconfigure: state2.reconfigure.bind(state2),
|
|
18833
|
+
toJSON: state2.toJSON.bind(state2),
|
|
18834
|
+
get storedMarks() {
|
|
18835
|
+
return storedMarks;
|
|
18836
|
+
},
|
|
18837
|
+
get selection() {
|
|
18838
|
+
return selection;
|
|
18839
|
+
},
|
|
18840
|
+
get doc() {
|
|
18841
|
+
return doc2;
|
|
18842
|
+
},
|
|
18843
|
+
get tr() {
|
|
18844
|
+
selection = transaction.selection;
|
|
18845
|
+
doc2 = transaction.doc;
|
|
18846
|
+
storedMarks = transaction.storedMarks;
|
|
18847
|
+
return transaction;
|
|
18848
|
+
}
|
|
18851
18849
|
};
|
|
18852
|
-
if (!router[type2]) {
|
|
18853
|
-
console.error("No translation function found for node type:", type2);
|
|
18854
|
-
return null;
|
|
18855
|
-
}
|
|
18856
|
-
return router[type2](params2);
|
|
18857
18850
|
}
|
|
18858
|
-
|
|
18859
|
-
|
|
18860
|
-
|
|
18861
|
-
|
|
18862
|
-
|
|
18863
|
-
|
|
18864
|
-
const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
|
|
18865
|
-
sectPr.elements.push(defaultHeader);
|
|
18866
|
-
}
|
|
18867
|
-
const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
|
|
18868
|
-
const hasDefaultFooter = params2.converter.footerIds?.default;
|
|
18869
|
-
if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
|
|
18870
|
-
const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
|
|
18871
|
-
sectPr.elements.push(defaultFooter);
|
|
18872
|
-
}
|
|
18873
|
-
const newMargins = params2.converter.pageStyles.pageMargins;
|
|
18874
|
-
const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
|
|
18875
|
-
const { attributes } = sectPrMargins;
|
|
18876
|
-
Object.entries(newMargins).forEach(([key, value]) => {
|
|
18877
|
-
const convertedValue = inchesToTwips(value);
|
|
18878
|
-
attributes[`w:${key}`] = convertedValue;
|
|
18879
|
-
});
|
|
18880
|
-
sectPrMargins.attributes = attributes;
|
|
18851
|
+
class CommandService {
|
|
18852
|
+
constructor(props) {
|
|
18853
|
+
__publicField$2(this, "editor");
|
|
18854
|
+
__publicField$2(this, "rawCommands");
|
|
18855
|
+
this.editor = props.editor;
|
|
18856
|
+
this.rawCommands = this.editor.extensionService.commands;
|
|
18881
18857
|
}
|
|
18882
|
-
|
|
18883
|
-
|
|
18884
|
-
|
|
18885
|
-
|
|
18886
|
-
|
|
18887
|
-
|
|
18858
|
+
/**
|
|
18859
|
+
* Static method for creating a service.
|
|
18860
|
+
* @param args Arguments for the constructor.
|
|
18861
|
+
*/
|
|
18862
|
+
static create(...args) {
|
|
18863
|
+
return new CommandService(...args);
|
|
18888
18864
|
}
|
|
18889
|
-
|
|
18890
|
-
|
|
18891
|
-
|
|
18892
|
-
|
|
18893
|
-
|
|
18894
|
-
const generateDefaultHeaderFooter = (type2, id) => {
|
|
18895
|
-
return {
|
|
18896
|
-
"type": "element",
|
|
18897
|
-
"name": `w:${type2}Reference`,
|
|
18898
|
-
"attributes": {
|
|
18899
|
-
"w:type": "default",
|
|
18900
|
-
"r:id": id
|
|
18901
|
-
}
|
|
18902
|
-
};
|
|
18903
|
-
};
|
|
18904
|
-
function translateParagraphNode(params2) {
|
|
18905
|
-
const elements = translateChildNodes(params2);
|
|
18906
|
-
const htmlAnnotationChild = elements.find((element) => element.name === "htmlAnnotation");
|
|
18907
|
-
if (htmlAnnotationChild) {
|
|
18908
|
-
return htmlAnnotationChild.elements;
|
|
18865
|
+
/**
|
|
18866
|
+
* Get editor state.
|
|
18867
|
+
*/
|
|
18868
|
+
get state() {
|
|
18869
|
+
return this.editor.state;
|
|
18909
18870
|
}
|
|
18910
|
-
|
|
18911
|
-
|
|
18912
|
-
|
|
18913
|
-
|
|
18914
|
-
|
|
18871
|
+
/**
|
|
18872
|
+
* Get all commands with wrapped command method.
|
|
18873
|
+
*/
|
|
18874
|
+
get commands() {
|
|
18875
|
+
const { editor, state: state2 } = this;
|
|
18876
|
+
const { view } = editor;
|
|
18877
|
+
const { tr } = state2;
|
|
18878
|
+
const props = this.createProps(tr);
|
|
18879
|
+
const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
|
|
18880
|
+
const method = (...args) => {
|
|
18881
|
+
const fn2 = command2(...args)(props);
|
|
18882
|
+
if (!tr.getMeta("preventDispatch")) {
|
|
18883
|
+
view.dispatch(tr);
|
|
18884
|
+
}
|
|
18885
|
+
return fn2;
|
|
18886
|
+
};
|
|
18887
|
+
return [name, method];
|
|
18888
|
+
});
|
|
18889
|
+
return Object.fromEntries(entries);
|
|
18915
18890
|
}
|
|
18916
|
-
|
|
18917
|
-
|
|
18918
|
-
|
|
18919
|
-
|
|
18920
|
-
|
|
18921
|
-
}
|
|
18922
|
-
function generateParagraphProperties(node2) {
|
|
18923
|
-
const { attrs = {} } = node2;
|
|
18924
|
-
const pPrElements = [];
|
|
18925
|
-
const { styleId } = attrs;
|
|
18926
|
-
if (styleId) pPrElements.push({ name: "w:pStyle", attributes: { "w:val": styleId } });
|
|
18927
|
-
const { spacing, indent, textAlign, textIndent, lineHeight: lineHeight2, marksAttrs, keepLines, keepNext, dropcap } = attrs;
|
|
18928
|
-
if (spacing) {
|
|
18929
|
-
const { lineSpaceBefore, lineSpaceAfter, line, lineRule } = spacing;
|
|
18930
|
-
const attributes = {};
|
|
18931
|
-
if (lineSpaceBefore >= 0) attributes["w:before"] = pixelsToTwips(lineSpaceBefore);
|
|
18932
|
-
if (lineSpaceAfter >= 0) attributes["w:after"] = pixelsToTwips(lineSpaceAfter);
|
|
18933
|
-
if (lineRule === "exact") {
|
|
18934
|
-
if (lineHeight2) attributes["w:line"] = ptToTwips(parseFloat(lineHeight2));
|
|
18935
|
-
} else {
|
|
18936
|
-
if (lineHeight2) attributes["w:line"] = linesToTwips(lineHeight2);
|
|
18937
|
-
}
|
|
18938
|
-
attributes["w:lineRule"] = lineRule || "auto";
|
|
18939
|
-
const spacingElement = {
|
|
18940
|
-
name: "w:spacing",
|
|
18941
|
-
attributes
|
|
18942
|
-
};
|
|
18943
|
-
pPrElements.push(spacingElement);
|
|
18891
|
+
/**
|
|
18892
|
+
* Create a chain of commands to call multiple commands at once.
|
|
18893
|
+
*/
|
|
18894
|
+
get chain() {
|
|
18895
|
+
return () => this.createChain();
|
|
18944
18896
|
}
|
|
18945
|
-
|
|
18946
|
-
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
|
|
18897
|
+
/**
|
|
18898
|
+
* Check if a command or a chain of commands can be executed. Without executing it.
|
|
18899
|
+
*/
|
|
18900
|
+
get can() {
|
|
18901
|
+
return () => this.createCan();
|
|
18902
|
+
}
|
|
18903
|
+
/**
|
|
18904
|
+
* Creates a chain of commands.
|
|
18905
|
+
* @param startTr Start transaction.
|
|
18906
|
+
* @param shouldDispatch Should dispatch or not.
|
|
18907
|
+
*/
|
|
18908
|
+
createChain(startTr, shouldDispatch = true) {
|
|
18909
|
+
const { editor, state: state2, rawCommands } = this;
|
|
18910
|
+
const { view } = editor;
|
|
18911
|
+
const callbacks2 = [];
|
|
18912
|
+
const hasStartTr = !!startTr;
|
|
18913
|
+
const tr = startTr || state2.tr;
|
|
18914
|
+
const run2 = () => {
|
|
18915
|
+
if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
|
|
18916
|
+
view.dispatch(tr);
|
|
18950
18917
|
}
|
|
18918
|
+
return callbacks2.every((cb) => cb === true);
|
|
18951
18919
|
};
|
|
18952
|
-
|
|
18953
|
-
|
|
18954
|
-
|
|
18955
|
-
|
|
18956
|
-
|
|
18957
|
-
|
|
18958
|
-
|
|
18959
|
-
|
|
18960
|
-
|
|
18961
|
-
|
|
18962
|
-
|
|
18963
|
-
|
|
18964
|
-
const indentElement = {
|
|
18965
|
-
name: "w:ind",
|
|
18966
|
-
attributes
|
|
18920
|
+
const entries = Object.entries(rawCommands).map(([name, command2]) => {
|
|
18921
|
+
const chainedCommand = (...args) => {
|
|
18922
|
+
const props = this.createProps(tr, shouldDispatch);
|
|
18923
|
+
const callback = command2(...args)(props);
|
|
18924
|
+
callbacks2.push(callback);
|
|
18925
|
+
return chain;
|
|
18926
|
+
};
|
|
18927
|
+
return [name, chainedCommand];
|
|
18928
|
+
});
|
|
18929
|
+
const chain = {
|
|
18930
|
+
...Object.fromEntries(entries),
|
|
18931
|
+
run: run2
|
|
18967
18932
|
};
|
|
18968
|
-
|
|
18969
|
-
}
|
|
18970
|
-
|
|
18971
|
-
|
|
18972
|
-
|
|
18973
|
-
|
|
18974
|
-
|
|
18933
|
+
return chain;
|
|
18934
|
+
}
|
|
18935
|
+
/**
|
|
18936
|
+
* Creates a can check for commands.
|
|
18937
|
+
* @param startTr Start transaction.
|
|
18938
|
+
*/
|
|
18939
|
+
createCan(startTr) {
|
|
18940
|
+
const { rawCommands, state: state2 } = this;
|
|
18941
|
+
const dispatch = false;
|
|
18942
|
+
const tr = startTr || state2.tr;
|
|
18943
|
+
const props = this.createProps(tr, dispatch);
|
|
18944
|
+
const commands2 = Object.fromEntries(
|
|
18945
|
+
Object.entries(rawCommands).map(([name, command2]) => {
|
|
18946
|
+
return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
|
|
18947
|
+
})
|
|
18948
|
+
);
|
|
18949
|
+
return {
|
|
18950
|
+
...commands2,
|
|
18951
|
+
chain: () => this.createChain(tr, dispatch)
|
|
18975
18952
|
};
|
|
18976
|
-
pPrElements.push(indentElement);
|
|
18977
18953
|
}
|
|
18978
|
-
|
|
18979
|
-
|
|
18980
|
-
|
|
18981
|
-
|
|
18954
|
+
/**
|
|
18955
|
+
* Creates default props for the command method.
|
|
18956
|
+
* @param {*} tr Transaction.
|
|
18957
|
+
* @param {*} shouldDispatch Check if should dispatch.
|
|
18958
|
+
* @returns Object with props.
|
|
18959
|
+
*/
|
|
18960
|
+
createProps(tr, shouldDispatch = true) {
|
|
18961
|
+
const { editor, state: state2, rawCommands } = this;
|
|
18962
|
+
const { view } = editor;
|
|
18963
|
+
const props = {
|
|
18964
|
+
tr,
|
|
18965
|
+
editor,
|
|
18966
|
+
view,
|
|
18967
|
+
state: chainableEditorState(tr, state2),
|
|
18968
|
+
dispatch: shouldDispatch ? () => void 0 : void 0,
|
|
18969
|
+
chain: () => this.createChain(tr, shouldDispatch),
|
|
18970
|
+
can: () => this.createCan(tr),
|
|
18971
|
+
get commands() {
|
|
18972
|
+
return Object.fromEntries(
|
|
18973
|
+
Object.entries(rawCommands).map(([name, command2]) => {
|
|
18974
|
+
return [name, (...args) => command2(...args)(props)];
|
|
18975
|
+
})
|
|
18976
|
+
);
|
|
18977
|
+
}
|
|
18982
18978
|
};
|
|
18983
|
-
|
|
18979
|
+
return props;
|
|
18984
18980
|
}
|
|
18985
|
-
|
|
18986
|
-
|
|
18987
|
-
|
|
18988
|
-
|
|
18981
|
+
}
|
|
18982
|
+
function getHTMLFromFragment(fragment, schema) {
|
|
18983
|
+
const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
|
|
18984
|
+
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
18985
|
+
const container = temporaryDocument.createElement("div");
|
|
18986
|
+
container.appendChild(documentFragment);
|
|
18987
|
+
return container.innerHTML;
|
|
18988
|
+
}
|
|
18989
|
+
const getTextContentFromNodes = ($from, maxMatch = 500) => {
|
|
18990
|
+
let textBefore = "";
|
|
18991
|
+
const sliceEndPos = $from.parentOffset;
|
|
18992
|
+
$from.parent.nodesBetween(
|
|
18993
|
+
Math.max(0, sliceEndPos - maxMatch),
|
|
18994
|
+
sliceEndPos,
|
|
18995
|
+
(node2, pos, parent, index2) => {
|
|
18996
|
+
const chunk = node2.type.spec.toText?.({
|
|
18997
|
+
node: node2,
|
|
18998
|
+
pos,
|
|
18999
|
+
parent,
|
|
19000
|
+
index: index2
|
|
19001
|
+
}) || node2.textContent || "%leaf%";
|
|
19002
|
+
textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
|
|
19003
|
+
}
|
|
19004
|
+
);
|
|
19005
|
+
return textBefore;
|
|
19006
|
+
};
|
|
19007
|
+
const handleDocxPaste = (html, editor, view, plugin2) => {
|
|
19008
|
+
const { converter } = editor;
|
|
19009
|
+
if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
|
|
19010
|
+
let cleanedHtml = convertEmToPt(html);
|
|
19011
|
+
cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
|
|
19012
|
+
const tempDiv = document.createElement("div");
|
|
19013
|
+
tempDiv.innerHTML = cleanedHtml;
|
|
19014
|
+
const paragraphs = tempDiv.querySelectorAll("p");
|
|
19015
|
+
paragraphs.forEach((p) => {
|
|
19016
|
+
const innerHTML3 = p.innerHTML;
|
|
19017
|
+
if (!innerHTML3.includes("<!--[if !supportLists]")) return;
|
|
19018
|
+
const styleAttr = p.getAttribute("style") || "";
|
|
19019
|
+
const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
|
|
19020
|
+
if (msoListMatch) {
|
|
19021
|
+
const [, abstractId, level] = msoListMatch;
|
|
19022
|
+
const listNumId = getListNumIdFromAbstract(abstractId, editor);
|
|
19023
|
+
if (!listNumId) return;
|
|
19024
|
+
const abstractDefinition = getListAbstractDefinition(abstractId, editor);
|
|
19025
|
+
const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
|
|
19026
|
+
p.setAttribute("data-num-id", listNumId);
|
|
19027
|
+
p.setAttribute("data-list-level", level - 1);
|
|
19028
|
+
p.setAttribute("data-start", start2);
|
|
19029
|
+
p.setAttribute("data-lvl-text", lvlText);
|
|
19030
|
+
p.setAttribute("data-num-fmt", numFmt);
|
|
19031
|
+
}
|
|
19032
|
+
extractAndRemoveConditionalPrefix(p);
|
|
19033
|
+
});
|
|
19034
|
+
transformWordLists(tempDiv);
|
|
19035
|
+
const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
|
|
19036
|
+
tempDiv.remove();
|
|
19037
|
+
const { dispatch } = editor.view;
|
|
19038
|
+
if (!dispatch) return false;
|
|
19039
|
+
dispatch(view.state.tr.replaceSelectionWith(doc2, true));
|
|
19040
|
+
return true;
|
|
19041
|
+
};
|
|
19042
|
+
const getLevelDefinition = (abstractDefinition, level) => {
|
|
19043
|
+
if (!abstractDefinition || !abstractDefinition.elements) return null;
|
|
19044
|
+
const levelElement = abstractDefinition.elements.find((el) => {
|
|
19045
|
+
return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
|
|
19046
|
+
});
|
|
19047
|
+
if (!levelElement) return null;
|
|
19048
|
+
const { elements } = levelElement;
|
|
19049
|
+
const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
|
|
19050
|
+
const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
|
|
19051
|
+
const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
|
|
19052
|
+
return { lvlText, start: start2, numFmt, elements };
|
|
19053
|
+
};
|
|
19054
|
+
const getListNumIdFromAbstract = (abstractId, editor) => {
|
|
19055
|
+
const { definitions } = editor?.converter?.numbering;
|
|
19056
|
+
if (!definitions) return null;
|
|
19057
|
+
const matchedDefinition = Object.values(definitions).find((def) => {
|
|
19058
|
+
return def.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
|
|
19059
|
+
});
|
|
19060
|
+
return matchedDefinition?.attributes?.["w:numId"];
|
|
19061
|
+
};
|
|
19062
|
+
const getListAbstractDefinition = (abstractId, editor) => {
|
|
19063
|
+
const { abstracts = {} } = editor?.converter?.numbering;
|
|
19064
|
+
return abstracts[abstractId] || null;
|
|
19065
|
+
};
|
|
19066
|
+
const transformWordLists = (container) => {
|
|
19067
|
+
const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
|
|
19068
|
+
const listMap = /* @__PURE__ */ new Map();
|
|
19069
|
+
const listLevels = {};
|
|
19070
|
+
for (const p of paragraphs) {
|
|
19071
|
+
const listId = p.getAttribute("data-num-id");
|
|
19072
|
+
const level = parseInt(p.getAttribute("data-list-level"));
|
|
19073
|
+
const numFmt = p.getAttribute("data-num-fmt");
|
|
19074
|
+
const start2 = p.getAttribute("data-start");
|
|
19075
|
+
const lvlText = p.getAttribute("data-lvl-text");
|
|
19076
|
+
if (!listMap.has(listId)) listMap.set(listId, []);
|
|
19077
|
+
listMap.get(listId).push({ p, level, numFmt, start: start2, lvlText });
|
|
18989
19078
|
}
|
|
18990
|
-
|
|
18991
|
-
|
|
18992
|
-
|
|
18993
|
-
|
|
19079
|
+
for (const [id, items] of listMap.entries()) {
|
|
19080
|
+
if (!listLevels[id]) {
|
|
19081
|
+
listLevels[id] = {
|
|
19082
|
+
stack: [],
|
|
19083
|
+
counts: {},
|
|
19084
|
+
prevLevel: null
|
|
19085
|
+
};
|
|
19086
|
+
}
|
|
19087
|
+
const parentStack = [];
|
|
19088
|
+
items.forEach(({ p, level, numFmt, start: start2, lvlText }, index2) => {
|
|
19089
|
+
const listLevel = generateListNestingPath(listLevels, id, level);
|
|
19090
|
+
const li = document.createElement("li");
|
|
19091
|
+
li.innerHTML = p.innerHTML;
|
|
19092
|
+
li.setAttribute("data-list-level", JSON.stringify(listLevel));
|
|
19093
|
+
li.setAttribute("data-num-id", id);
|
|
19094
|
+
li.setAttribute("data-lvl-text", lvlText);
|
|
19095
|
+
li.setAttribute("data-num-fmt", numFmt);
|
|
19096
|
+
if (p.hasAttribute("data-font-family")) {
|
|
19097
|
+
li.setAttribute("data-font-family", p.getAttribute("data-font-family"));
|
|
19098
|
+
}
|
|
19099
|
+
if (p.hasAttribute("data-font-size")) {
|
|
19100
|
+
li.setAttribute("data-font-size", p.getAttribute("data-font-size"));
|
|
19101
|
+
}
|
|
19102
|
+
const parentNode2 = p.parentNode;
|
|
19103
|
+
let listForLevel = parentStack[level];
|
|
19104
|
+
if (!listForLevel) {
|
|
19105
|
+
const newList = document.createElement("ol");
|
|
19106
|
+
newList.setAttribute("data-list-id", id);
|
|
19107
|
+
newList.level = level;
|
|
19108
|
+
if (level > 0) {
|
|
19109
|
+
const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
|
|
19110
|
+
if (parentLi) parentLi.appendChild(newList);
|
|
19111
|
+
} else {
|
|
19112
|
+
parentNode2.insertBefore(newList, p);
|
|
19113
|
+
}
|
|
19114
|
+
parentStack[level] = newList;
|
|
19115
|
+
parentStack.length = level + 1;
|
|
19116
|
+
listForLevel = newList;
|
|
19117
|
+
}
|
|
19118
|
+
listForLevel.appendChild(li);
|
|
19119
|
+
p.remove();
|
|
18994
19120
|
});
|
|
18995
19121
|
}
|
|
18996
|
-
|
|
18997
|
-
|
|
18998
|
-
|
|
18999
|
-
|
|
19000
|
-
|
|
19122
|
+
};
|
|
19123
|
+
function generateListNestingPath(listLevels, listId, currentLevel) {
|
|
19124
|
+
const levelState = listLevels[listId];
|
|
19125
|
+
if (!levelState.stack) levelState.stack = [];
|
|
19126
|
+
if (levelState.prevLevel === void 0) levelState.prevLevel = null;
|
|
19127
|
+
if (levelState.prevLevel === null) {
|
|
19128
|
+
levelState.stack = Array(currentLevel).fill(1).concat(1);
|
|
19129
|
+
} else {
|
|
19130
|
+
if (currentLevel > levelState.prevLevel) {
|
|
19131
|
+
levelState.stack.push(1);
|
|
19132
|
+
} else if (currentLevel === levelState.prevLevel) {
|
|
19133
|
+
levelState.stack[levelState.stack.length - 1]++;
|
|
19134
|
+
} else {
|
|
19135
|
+
levelState.stack = levelState.stack.slice(0, currentLevel + 1);
|
|
19136
|
+
levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
|
|
19137
|
+
}
|
|
19001
19138
|
}
|
|
19002
|
-
|
|
19003
|
-
|
|
19004
|
-
|
|
19005
|
-
|
|
19006
|
-
|
|
19007
|
-
|
|
19008
|
-
|
|
19009
|
-
|
|
19010
|
-
|
|
19139
|
+
levelState.prevLevel = currentLevel;
|
|
19140
|
+
return [...levelState.stack];
|
|
19141
|
+
}
|
|
19142
|
+
function extractAndRemoveConditionalPrefix(p) {
|
|
19143
|
+
const nodes = Array.from(p.childNodes);
|
|
19144
|
+
let fontFamily2 = null;
|
|
19145
|
+
let fontSize2 = null;
|
|
19146
|
+
let start2 = -1, end2 = -1;
|
|
19147
|
+
nodes.forEach((node2, index2) => {
|
|
19148
|
+
if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
|
|
19149
|
+
start2 = index2;
|
|
19150
|
+
}
|
|
19151
|
+
if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
|
|
19152
|
+
end2 = index2;
|
|
19153
|
+
}
|
|
19154
|
+
});
|
|
19155
|
+
if (start2 !== -1 && end2 !== -1) {
|
|
19156
|
+
for (let i = start2 + 1; i < end2; i++) {
|
|
19157
|
+
const node2 = nodes[i];
|
|
19158
|
+
if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
|
|
19159
|
+
fontFamily2 = fontFamily2 || node2.style.fontFamily;
|
|
19160
|
+
fontSize2 = fontSize2 || node2.style.fontSize;
|
|
19011
19161
|
}
|
|
19012
|
-
}
|
|
19162
|
+
}
|
|
19163
|
+
for (let i = end2; i >= start2; i--) {
|
|
19164
|
+
p.removeChild(p.childNodes[i]);
|
|
19165
|
+
}
|
|
19166
|
+
if (fontFamily2) p.setAttribute("data-font-family", fontFamily2);
|
|
19167
|
+
if (fontSize2) p.setAttribute("data-font-size", fontSize2);
|
|
19013
19168
|
}
|
|
19014
|
-
|
|
19015
|
-
|
|
19016
|
-
|
|
19169
|
+
}
|
|
19170
|
+
class InputRule {
|
|
19171
|
+
constructor(config) {
|
|
19172
|
+
__publicField$2(this, "match");
|
|
19173
|
+
__publicField$2(this, "handler");
|
|
19174
|
+
this.match = config.match;
|
|
19175
|
+
this.handler = config.handler;
|
|
19017
19176
|
}
|
|
19018
|
-
if (!pPrElements.length) return null;
|
|
19019
|
-
return {
|
|
19020
|
-
name: "w:pPr",
|
|
19021
|
-
elements: pPrElements
|
|
19022
|
-
};
|
|
19023
19177
|
}
|
|
19024
|
-
|
|
19025
|
-
|
|
19026
|
-
|
|
19027
|
-
|
|
19178
|
+
const inputRuleMatcherHandler = (text, match) => {
|
|
19179
|
+
if (isRegExp(match)) {
|
|
19180
|
+
return match.exec(text);
|
|
19181
|
+
}
|
|
19182
|
+
const inputRuleMatch = match(text);
|
|
19183
|
+
if (!inputRuleMatch) {
|
|
19184
|
+
return null;
|
|
19185
|
+
}
|
|
19186
|
+
const result = [inputRuleMatch.text];
|
|
19187
|
+
result.index = inputRuleMatch.index;
|
|
19188
|
+
result.input = text;
|
|
19189
|
+
result.data = inputRuleMatch.data;
|
|
19190
|
+
if (inputRuleMatch.replaceWith) {
|
|
19191
|
+
if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
|
|
19192
|
+
console.warn(
|
|
19193
|
+
'[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
|
|
19194
|
+
);
|
|
19195
|
+
}
|
|
19196
|
+
result.push(inputRuleMatch.replaceWith);
|
|
19197
|
+
}
|
|
19198
|
+
return result;
|
|
19199
|
+
};
|
|
19200
|
+
const run = (config) => {
|
|
19201
|
+
const {
|
|
19202
|
+
editor,
|
|
19203
|
+
from: from2,
|
|
19204
|
+
to,
|
|
19205
|
+
text,
|
|
19206
|
+
rules,
|
|
19207
|
+
plugin: plugin2
|
|
19208
|
+
} = config;
|
|
19209
|
+
const { view } = editor;
|
|
19210
|
+
if (view.composing) {
|
|
19211
|
+
return false;
|
|
19212
|
+
}
|
|
19213
|
+
const $from = view.state.doc.resolve(from2);
|
|
19214
|
+
if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
|
|
19215
|
+
return false;
|
|
19216
|
+
}
|
|
19217
|
+
let matched = false;
|
|
19218
|
+
const textBefore = getTextContentFromNodes($from) + text;
|
|
19219
|
+
rules.forEach((rule) => {
|
|
19220
|
+
if (matched) {
|
|
19221
|
+
return;
|
|
19222
|
+
}
|
|
19223
|
+
const match = inputRuleMatcherHandler(textBefore, rule.match);
|
|
19224
|
+
if (!match) {
|
|
19225
|
+
return;
|
|
19226
|
+
}
|
|
19227
|
+
const tr = view.state.tr;
|
|
19228
|
+
const state2 = chainableEditorState(tr, view.state);
|
|
19229
|
+
const range2 = {
|
|
19230
|
+
from: from2 - (match[0].length - text.length),
|
|
19231
|
+
to
|
|
19232
|
+
};
|
|
19233
|
+
const { commands: commands2, chain, can } = new CommandService({
|
|
19234
|
+
editor,
|
|
19235
|
+
state: state2
|
|
19236
|
+
});
|
|
19237
|
+
const handler = rule.handler({
|
|
19238
|
+
state: state2,
|
|
19239
|
+
range: range2,
|
|
19240
|
+
match,
|
|
19241
|
+
commands: commands2,
|
|
19242
|
+
chain,
|
|
19243
|
+
can
|
|
19244
|
+
});
|
|
19245
|
+
if (handler === null || !tr.steps.length) {
|
|
19246
|
+
return;
|
|
19247
|
+
}
|
|
19248
|
+
tr.setMeta(plugin2, {
|
|
19249
|
+
transform: tr,
|
|
19250
|
+
from: from2,
|
|
19251
|
+
to,
|
|
19252
|
+
text
|
|
19253
|
+
});
|
|
19254
|
+
view.dispatch(tr);
|
|
19255
|
+
matched = true;
|
|
19256
|
+
});
|
|
19257
|
+
return matched;
|
|
19258
|
+
};
|
|
19259
|
+
const inputRulesPlugin = ({ editor, rules }) => {
|
|
19260
|
+
const plugin2 = new Plugin({
|
|
19261
|
+
key: new PluginKey("inputRulesPlugin"),
|
|
19262
|
+
state: {
|
|
19263
|
+
init() {
|
|
19264
|
+
return null;
|
|
19265
|
+
},
|
|
19266
|
+
apply(tr, prev, state2) {
|
|
19267
|
+
const stored = tr.getMeta(plugin2);
|
|
19268
|
+
if (stored) {
|
|
19269
|
+
return stored;
|
|
19270
|
+
}
|
|
19271
|
+
const simulatedInputMeta = tr.getMeta("applyInputRules");
|
|
19272
|
+
const isSimulatedInput = !!simulatedInputMeta;
|
|
19273
|
+
if (isSimulatedInput) {
|
|
19274
|
+
setTimeout(() => {
|
|
19275
|
+
let { text } = simulatedInputMeta;
|
|
19276
|
+
if (typeof text !== "string") {
|
|
19277
|
+
text = getHTMLFromFragment(Fragment.from(text), state2.schema);
|
|
19278
|
+
}
|
|
19279
|
+
const { from: from2 } = simulatedInputMeta;
|
|
19280
|
+
const to = from2 + text.length;
|
|
19281
|
+
run({
|
|
19282
|
+
editor,
|
|
19283
|
+
from: from2,
|
|
19284
|
+
to,
|
|
19285
|
+
text,
|
|
19286
|
+
rules,
|
|
19287
|
+
plugin: plugin2
|
|
19288
|
+
});
|
|
19289
|
+
});
|
|
19290
|
+
}
|
|
19291
|
+
return tr.selectionSet || tr.docChanged ? null : prev;
|
|
19292
|
+
}
|
|
19293
|
+
},
|
|
19294
|
+
props: {
|
|
19295
|
+
handleTextInput(view, from2, to, text) {
|
|
19296
|
+
return run({
|
|
19297
|
+
editor,
|
|
19298
|
+
from: from2,
|
|
19299
|
+
to,
|
|
19300
|
+
text,
|
|
19301
|
+
rules,
|
|
19302
|
+
plugin: plugin2
|
|
19303
|
+
});
|
|
19304
|
+
},
|
|
19305
|
+
// add support for input rules to trigger on enter
|
|
19306
|
+
// this is useful for example for code blocks
|
|
19307
|
+
handleKeyDown(view, event) {
|
|
19308
|
+
if (event.key !== "Enter") {
|
|
19309
|
+
return false;
|
|
19310
|
+
}
|
|
19311
|
+
const { $cursor } = view.state.selection;
|
|
19312
|
+
if ($cursor) {
|
|
19313
|
+
return run({
|
|
19314
|
+
editor,
|
|
19315
|
+
from: $cursor.pos,
|
|
19316
|
+
to: $cursor.pos,
|
|
19317
|
+
text: "\n",
|
|
19318
|
+
rules,
|
|
19319
|
+
plugin: plugin2
|
|
19320
|
+
});
|
|
19321
|
+
}
|
|
19322
|
+
return false;
|
|
19323
|
+
},
|
|
19324
|
+
// Paste handler
|
|
19325
|
+
handlePaste(view, event, slice2) {
|
|
19326
|
+
const clipboard = event.clipboardData;
|
|
19327
|
+
const html = clipboard.getData("text/html");
|
|
19328
|
+
clipboard.getData("text/plain");
|
|
19329
|
+
const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
|
|
19330
|
+
if (fieldAnnotationContent.length) {
|
|
19331
|
+
return false;
|
|
19332
|
+
}
|
|
19333
|
+
let source;
|
|
19334
|
+
if (!html) {
|
|
19335
|
+
source = "plain-text";
|
|
19336
|
+
} else if (isWordHtml(html)) {
|
|
19337
|
+
source = "word-html";
|
|
19338
|
+
} else {
|
|
19339
|
+
source = "browser-html";
|
|
19340
|
+
}
|
|
19341
|
+
switch (source) {
|
|
19342
|
+
case "plain-text":
|
|
19343
|
+
break;
|
|
19344
|
+
case "word-html":
|
|
19345
|
+
if (editor.options.mode === "docx") {
|
|
19346
|
+
return handleDocxPaste(html, editor, view, plugin2);
|
|
19347
|
+
}
|
|
19348
|
+
case "browser-html":
|
|
19349
|
+
return handleHtmlPaste$1(html, editor);
|
|
19350
|
+
}
|
|
19351
|
+
return false;
|
|
19352
|
+
}
|
|
19353
|
+
},
|
|
19354
|
+
isInputRules: true
|
|
19355
|
+
});
|
|
19356
|
+
return plugin2;
|
|
19357
|
+
};
|
|
19358
|
+
function isWordHtml(html) {
|
|
19359
|
+
return /class=["']?Mso|xmlns:o=["']?urn:schemas-microsoft-com|<!--\[if gte mso|<meta[^>]+name=["']?Generator["']?[^>]+Word/i.test(html);
|
|
19360
|
+
}
|
|
19361
|
+
const handleHtmlPaste$1 = (html, editor, plugin2) => {
|
|
19362
|
+
const htmlWithPtSizing = convertEmToPt(html);
|
|
19363
|
+
const cleanedHtml = sanitizeHtml(htmlWithPtSizing);
|
|
19364
|
+
const doc2 = DOMParser$1.fromSchema(editor.schema).parse(cleanedHtml);
|
|
19365
|
+
const { dispatch } = editor.view;
|
|
19366
|
+
if (!dispatch) return false;
|
|
19367
|
+
dispatch(editor.view.state.tr.replaceSelectionWith(doc2, true));
|
|
19368
|
+
return true;
|
|
19369
|
+
};
|
|
19370
|
+
const convertEmToPt = (html) => {
|
|
19371
|
+
return html.replace(
|
|
19372
|
+
/font-size\s*:\s*([\d.]+)em/gi,
|
|
19373
|
+
(_, emValue) => {
|
|
19374
|
+
const em = parseFloat(emValue);
|
|
19375
|
+
const pt = Math.round(em * 12 * 100) / 100;
|
|
19376
|
+
return `font-size: ${pt}pt`;
|
|
19377
|
+
}
|
|
19378
|
+
);
|
|
19379
|
+
};
|
|
19380
|
+
function cleanHtmlUnnecessaryTags(html) {
|
|
19381
|
+
return html.replace(/<o:p>.*?<\/o:p>/gi, "").replace(/ /gi, " ").replace(/<span[^>]*>\s*<\/span>/gi, "").replace(/<p[^>]*>\s*<\/p>/gi, "").trim();
|
|
19382
|
+
}
|
|
19383
|
+
function sanitizeHtml(html, forbiddenTags = ["meta", "svg", "script", "style", "button"]) {
|
|
19384
|
+
const container = document.createElement("div");
|
|
19385
|
+
container.innerHTML = html;
|
|
19386
|
+
const walkAndClean = (node2) => {
|
|
19387
|
+
for (const child of [...node2.children]) {
|
|
19388
|
+
if (forbiddenTags.includes(child.tagName.toLowerCase())) {
|
|
19389
|
+
child.remove();
|
|
19390
|
+
continue;
|
|
19391
|
+
}
|
|
19392
|
+
if (child.hasAttribute("linebreaktype")) {
|
|
19393
|
+
child.removeAttribute("linebreaktype");
|
|
19394
|
+
}
|
|
19395
|
+
walkAndClean(child);
|
|
19396
|
+
}
|
|
19397
|
+
};
|
|
19398
|
+
walkAndClean(container);
|
|
19399
|
+
return container;
|
|
19400
|
+
}
|
|
19401
|
+
function exportSchemaToJson(params2) {
|
|
19402
|
+
const { type: type2 } = params2.node || {};
|
|
19403
|
+
const router = {
|
|
19404
|
+
doc: translateDocumentNode,
|
|
19405
|
+
body: translateBodyNode,
|
|
19406
|
+
paragraph: translateParagraphNode,
|
|
19407
|
+
text: translateTextNode,
|
|
19408
|
+
bulletList: translateList,
|
|
19409
|
+
orderedList: translateList,
|
|
19410
|
+
lineBreak: translateLineBreak,
|
|
19411
|
+
table: translateTable,
|
|
19412
|
+
tableRow: translateTableRow,
|
|
19413
|
+
tableCell: translateTableCell,
|
|
19414
|
+
bookmarkStart: translateBookmarkStart,
|
|
19415
|
+
fieldAnnotation: translateFieldAnnotation,
|
|
19416
|
+
tab: translateTab,
|
|
19417
|
+
image: translateImageNode,
|
|
19418
|
+
hardBreak: translateHardBreak,
|
|
19419
|
+
commentRangeStart: () => translateCommentNode(params2, "Start"),
|
|
19420
|
+
commentRangeEnd: () => translateCommentNode(params2, "End"),
|
|
19421
|
+
commentReference: () => null,
|
|
19422
|
+
shapeContainer: translateShapeContainer,
|
|
19423
|
+
shapeTextbox: translateShapeTextbox,
|
|
19424
|
+
contentBlock: translateContentBlock,
|
|
19425
|
+
structuredContent: translateStructuredContent,
|
|
19426
|
+
"page-number": translatePageNumberNode,
|
|
19427
|
+
"total-page-number": translateTotalPageNumberNode
|
|
19428
|
+
};
|
|
19429
|
+
if (!router[type2]) {
|
|
19430
|
+
console.error("No translation function found for node type:", type2);
|
|
19431
|
+
return null;
|
|
19432
|
+
}
|
|
19433
|
+
return router[type2](params2);
|
|
19434
|
+
}
|
|
19435
|
+
function translateBodyNode(params2) {
|
|
19436
|
+
let sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
|
|
19437
|
+
if (params2.converter) {
|
|
19438
|
+
const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
|
|
19439
|
+
const hasDefaultHeader = params2.converter.headerIds?.default;
|
|
19440
|
+
if (!hasHeader && hasDefaultHeader && !params2.editor.options.isHeaderOrFooter) {
|
|
19441
|
+
const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
|
|
19442
|
+
sectPr.elements.push(defaultHeader);
|
|
19443
|
+
}
|
|
19444
|
+
const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
|
|
19445
|
+
const hasDefaultFooter = params2.converter.footerIds?.default;
|
|
19446
|
+
if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
|
|
19447
|
+
const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
|
|
19448
|
+
sectPr.elements.push(defaultFooter);
|
|
19449
|
+
}
|
|
19450
|
+
const newMargins = params2.converter.pageStyles.pageMargins;
|
|
19451
|
+
const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
|
|
19452
|
+
const { attributes } = sectPrMargins;
|
|
19453
|
+
Object.entries(newMargins).forEach(([key, value]) => {
|
|
19454
|
+
const convertedValue = inchesToTwips(value);
|
|
19455
|
+
attributes[`w:${key}`] = convertedValue;
|
|
19456
|
+
});
|
|
19457
|
+
sectPrMargins.attributes = attributes;
|
|
19458
|
+
}
|
|
19459
|
+
const elements = translateChildNodes(params2);
|
|
19460
|
+
if (params2.isHeaderFooter) {
|
|
19461
|
+
return {
|
|
19462
|
+
name: "w:body",
|
|
19463
|
+
elements: [...elements]
|
|
19464
|
+
};
|
|
19465
|
+
}
|
|
19466
|
+
return {
|
|
19467
|
+
name: "w:body",
|
|
19468
|
+
elements: [...elements, sectPr]
|
|
19469
|
+
};
|
|
19470
|
+
}
|
|
19471
|
+
const generateDefaultHeaderFooter = (type2, id) => {
|
|
19472
|
+
return {
|
|
19473
|
+
"type": "element",
|
|
19474
|
+
"name": `w:${type2}Reference`,
|
|
19475
|
+
"attributes": {
|
|
19476
|
+
"w:type": "default",
|
|
19477
|
+
"r:id": id
|
|
19478
|
+
}
|
|
19479
|
+
};
|
|
19480
|
+
};
|
|
19481
|
+
function translateParagraphNode(params2) {
|
|
19482
|
+
const elements = translateChildNodes(params2);
|
|
19483
|
+
const htmlAnnotationChild = elements.find((element) => element.name === "htmlAnnotation");
|
|
19484
|
+
if (htmlAnnotationChild) {
|
|
19485
|
+
return htmlAnnotationChild.elements;
|
|
19486
|
+
}
|
|
19487
|
+
const pPr = generateParagraphProperties(params2.node);
|
|
19488
|
+
if (pPr) elements.unshift(pPr);
|
|
19489
|
+
let attributes = {};
|
|
19490
|
+
if (params2.node.attrs?.rsidRDefault) {
|
|
19491
|
+
attributes["w:rsidRDefault"] = params2.node.attrs.rsidRDefault;
|
|
19492
|
+
}
|
|
19493
|
+
return {
|
|
19494
|
+
name: "w:p",
|
|
19495
|
+
elements,
|
|
19496
|
+
attributes
|
|
19497
|
+
};
|
|
19498
|
+
}
|
|
19499
|
+
function generateParagraphProperties(node2) {
|
|
19500
|
+
const { attrs = {} } = node2;
|
|
19501
|
+
const pPrElements = [];
|
|
19502
|
+
const { styleId } = attrs;
|
|
19503
|
+
if (styleId) pPrElements.push({ name: "w:pStyle", attributes: { "w:val": styleId } });
|
|
19504
|
+
const { spacing, indent, textAlign, textIndent, lineHeight: lineHeight2, marksAttrs, keepLines, keepNext, dropcap } = attrs;
|
|
19505
|
+
if (spacing) {
|
|
19506
|
+
const { lineSpaceBefore, lineSpaceAfter, line, lineRule } = spacing;
|
|
19507
|
+
const attributes = {};
|
|
19508
|
+
if (lineSpaceBefore >= 0) attributes["w:before"] = pixelsToTwips(lineSpaceBefore);
|
|
19509
|
+
if (lineSpaceAfter >= 0) attributes["w:after"] = pixelsToTwips(lineSpaceAfter);
|
|
19510
|
+
if (lineRule === "exact") {
|
|
19511
|
+
if (lineHeight2) attributes["w:line"] = ptToTwips(parseFloat(lineHeight2));
|
|
19512
|
+
} else {
|
|
19513
|
+
if (lineHeight2) attributes["w:line"] = linesToTwips(lineHeight2);
|
|
19514
|
+
}
|
|
19515
|
+
attributes["w:lineRule"] = lineRule || "auto";
|
|
19516
|
+
const spacingElement = {
|
|
19517
|
+
name: "w:spacing",
|
|
19518
|
+
attributes
|
|
19519
|
+
};
|
|
19520
|
+
pPrElements.push(spacingElement);
|
|
19521
|
+
}
|
|
19522
|
+
if (lineHeight2 && !spacing) {
|
|
19523
|
+
const spacingElement = {
|
|
19524
|
+
name: "w:spacing",
|
|
19525
|
+
attributes: {
|
|
19526
|
+
"w:line": linesToTwips(lineHeight2)
|
|
19527
|
+
}
|
|
19528
|
+
};
|
|
19529
|
+
pPrElements.push(spacingElement);
|
|
19530
|
+
}
|
|
19531
|
+
if (indent) {
|
|
19532
|
+
const { left: left2, right: right2, firstLine, hanging } = indent;
|
|
19533
|
+
const attributes = {};
|
|
19534
|
+
if (left2 || left2 === 0) attributes["w:left"] = pixelsToTwips(left2);
|
|
19535
|
+
if (right2 || right2 === 0) attributes["w:right"] = pixelsToTwips(right2);
|
|
19536
|
+
if (firstLine || firstLine === 0) attributes["w:firstLine"] = pixelsToTwips(firstLine);
|
|
19537
|
+
if (hanging || hanging === 0) attributes["w:hanging"] = pixelsToTwips(hanging);
|
|
19538
|
+
if (textIndent && !attributes["w:left"]) {
|
|
19539
|
+
attributes["w:left"] = inchesToTwips(textIndent);
|
|
19540
|
+
}
|
|
19541
|
+
const indentElement = {
|
|
19542
|
+
name: "w:ind",
|
|
19543
|
+
attributes
|
|
19544
|
+
};
|
|
19545
|
+
pPrElements.push(indentElement);
|
|
19546
|
+
} else if (textIndent) {
|
|
19547
|
+
const indentElement = {
|
|
19548
|
+
name: "w:ind",
|
|
19549
|
+
attributes: {
|
|
19550
|
+
"w:left": inchesToTwips(textIndent)
|
|
19551
|
+
}
|
|
19552
|
+
};
|
|
19553
|
+
pPrElements.push(indentElement);
|
|
19554
|
+
}
|
|
19555
|
+
if (textAlign) {
|
|
19556
|
+
const textAlignElement = {
|
|
19557
|
+
name: "w:jc",
|
|
19558
|
+
attributes: { "w:val": textAlign === "justify" ? "both" : textAlign }
|
|
19559
|
+
};
|
|
19560
|
+
pPrElements.push(textAlignElement);
|
|
19561
|
+
}
|
|
19562
|
+
if (marksAttrs) {
|
|
19563
|
+
const outputMarks = processOutputMarks(marksAttrs);
|
|
19564
|
+
const rPrElement = generateRunProps(outputMarks);
|
|
19565
|
+
pPrElements.push(rPrElement);
|
|
19566
|
+
}
|
|
19567
|
+
if (keepLines) {
|
|
19568
|
+
pPrElements.push({
|
|
19569
|
+
name: "w:keepLines",
|
|
19570
|
+
attributes: { "w:val": keepLines }
|
|
19571
|
+
});
|
|
19572
|
+
}
|
|
19573
|
+
if (keepNext) {
|
|
19574
|
+
pPrElements.push({
|
|
19575
|
+
name: "w:keepNext",
|
|
19576
|
+
attributes: { "w:val": keepNext }
|
|
19577
|
+
});
|
|
19578
|
+
}
|
|
19579
|
+
if (dropcap) {
|
|
19580
|
+
pPrElements.push({
|
|
19581
|
+
name: "w:framePr",
|
|
19582
|
+
attributes: {
|
|
19583
|
+
"w:dropCap": dropcap.type,
|
|
19584
|
+
"w:lines": dropcap.lines,
|
|
19585
|
+
"w:wrap": dropcap.wrap,
|
|
19586
|
+
"w:vAnchor": dropcap.vAnchor,
|
|
19587
|
+
"w:hAnchor": dropcap.hAnchor
|
|
19588
|
+
}
|
|
19589
|
+
});
|
|
19590
|
+
}
|
|
19591
|
+
const sectPr = node2.attrs?.paragraphProperties?.sectPr;
|
|
19592
|
+
if (sectPr) {
|
|
19593
|
+
pPrElements.push(sectPr);
|
|
19594
|
+
}
|
|
19595
|
+
if (!pPrElements.length) return null;
|
|
19596
|
+
return {
|
|
19597
|
+
name: "w:pPr",
|
|
19598
|
+
elements: pPrElements
|
|
19599
|
+
};
|
|
19600
|
+
}
|
|
19601
|
+
function translateDocumentNode(params2) {
|
|
19602
|
+
const bodyNode = {
|
|
19603
|
+
type: "body",
|
|
19604
|
+
content: params2.node.content
|
|
19028
19605
|
};
|
|
19029
19606
|
const translatedBodyNode = exportSchemaToJson({ ...params2, node: bodyNode });
|
|
19030
19607
|
const node2 = {
|
|
@@ -20164,12 +20741,11 @@ function prepareHtmlAnnotation(params2) {
|
|
|
20164
20741
|
node: { attrs = {}, marks = [] },
|
|
20165
20742
|
editorSchema
|
|
20166
20743
|
} = params2;
|
|
20167
|
-
const
|
|
20168
|
-
const paragraphHtml = parser.parseFromString(attrs.rawHtml || attrs.displayLabel, "text/html");
|
|
20744
|
+
const paragraphHtmlContainer = sanitizeHtml(attrs.rawHtml);
|
|
20169
20745
|
const marksFromAttrs = translateFieldAttrsToMarks(attrs);
|
|
20170
20746
|
const allMarks = [...marks, ...marksFromAttrs];
|
|
20171
20747
|
let state2 = EditorState.create({
|
|
20172
|
-
doc: DOMParser$1.fromSchema(editorSchema).parse(
|
|
20748
|
+
doc: DOMParser$1.fromSchema(editorSchema).parse(paragraphHtmlContainer)
|
|
20173
20749
|
});
|
|
20174
20750
|
if (allMarks.length) {
|
|
20175
20751
|
state2 = applyMarksToHtmlAnnotation(state2, allMarks);
|
|
@@ -23234,6 +23810,7 @@ const importHeadersFooters = (docx, converter, mainEditor) => {
|
|
|
23234
23810
|
const footers = elements.filter((el) => el.attributes["Type"] === footerType);
|
|
23235
23811
|
const sectPr = findSectPr(docx["word/document.xml"]) || [];
|
|
23236
23812
|
const allSectPrElements = sectPr.flatMap((el) => el.elements);
|
|
23813
|
+
if (!mainEditor) return;
|
|
23237
23814
|
const editor = { ...mainEditor };
|
|
23238
23815
|
editor.options.annotations = true;
|
|
23239
23816
|
headers.forEach((header) => {
|
|
@@ -23395,7 +23972,7 @@ const _SuperConverter = class _SuperConverter2 {
|
|
|
23395
23972
|
return;
|
|
23396
23973
|
}
|
|
23397
23974
|
}
|
|
23398
|
-
static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.2-
|
|
23975
|
+
static updateDocumentVersion(docx = this.convertedXml, version2 = "0.13.2-rev11") {
|
|
23399
23976
|
const customLocation = "docProps/custom.xml";
|
|
23400
23977
|
if (!docx[customLocation]) {
|
|
23401
23978
|
docx[customLocation] = generateCustomXml();
|
|
@@ -23862,7 +24439,7 @@ function storeSuperdocVersion(docx) {
|
|
|
23862
24439
|
function generateCustomXml() {
|
|
23863
24440
|
return DEFAULT_CUSTOM_XML;
|
|
23864
24441
|
}
|
|
23865
|
-
function generateSuperdocVersion(pid = 2, version2 = "0.13.2-
|
|
24442
|
+
function generateSuperdocVersion(pid = 2, version2 = "0.13.2-rev11") {
|
|
23866
24443
|
return {
|
|
23867
24444
|
type: "element",
|
|
23868
24445
|
name: "property",
|
|
@@ -26395,7 +26972,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
|
|
|
26395
26972
|
var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
26396
26973
|
var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
|
|
26397
26974
|
var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
|
|
26398
|
-
var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn,
|
|
26975
|
+
var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _commandService, _css, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, createSchema_fn, generatePmData_fn, createDocFromHTML_fn, createView_fn, onCollaborationReady_fn, initComments_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
|
|
26399
26976
|
function getMarksFromSelection(state2) {
|
|
26400
26977
|
const { from: from2, to, empty: empty2 } = state2.selection;
|
|
26401
26978
|
const marks = [];
|
|
@@ -27584,164 +28161,6 @@ createMarksSchema_fn = function(markExtensions, attributes, editor) {
|
|
|
27584
28161
|
};
|
|
27585
28162
|
__privateAdd$1(_Schema, _Schema_static);
|
|
27586
28163
|
let Schema2 = _Schema;
|
|
27587
|
-
function chainableEditorState(transaction, state2) {
|
|
27588
|
-
let { selection, doc: doc2, storedMarks } = transaction;
|
|
27589
|
-
return {
|
|
27590
|
-
...state2,
|
|
27591
|
-
apply: state2.apply.bind(state2),
|
|
27592
|
-
applyTransaction: state2.applyTransaction.bind(state2),
|
|
27593
|
-
plugins: state2.plugins,
|
|
27594
|
-
schema: state2.schema,
|
|
27595
|
-
reconfigure: state2.reconfigure.bind(state2),
|
|
27596
|
-
toJSON: state2.toJSON.bind(state2),
|
|
27597
|
-
get storedMarks() {
|
|
27598
|
-
return storedMarks;
|
|
27599
|
-
},
|
|
27600
|
-
get selection() {
|
|
27601
|
-
return selection;
|
|
27602
|
-
},
|
|
27603
|
-
get doc() {
|
|
27604
|
-
return doc2;
|
|
27605
|
-
},
|
|
27606
|
-
get tr() {
|
|
27607
|
-
selection = transaction.selection;
|
|
27608
|
-
doc2 = transaction.doc;
|
|
27609
|
-
storedMarks = transaction.storedMarks;
|
|
27610
|
-
return transaction;
|
|
27611
|
-
}
|
|
27612
|
-
};
|
|
27613
|
-
}
|
|
27614
|
-
class CommandService {
|
|
27615
|
-
constructor(props) {
|
|
27616
|
-
__publicField$1(this, "editor");
|
|
27617
|
-
__publicField$1(this, "rawCommands");
|
|
27618
|
-
this.editor = props.editor;
|
|
27619
|
-
this.rawCommands = this.editor.extensionService.commands;
|
|
27620
|
-
}
|
|
27621
|
-
/**
|
|
27622
|
-
* Static method for creating a service.
|
|
27623
|
-
* @param args Arguments for the constructor.
|
|
27624
|
-
*/
|
|
27625
|
-
static create(...args) {
|
|
27626
|
-
return new CommandService(...args);
|
|
27627
|
-
}
|
|
27628
|
-
/**
|
|
27629
|
-
* Get editor state.
|
|
27630
|
-
*/
|
|
27631
|
-
get state() {
|
|
27632
|
-
return this.editor.state;
|
|
27633
|
-
}
|
|
27634
|
-
/**
|
|
27635
|
-
* Get all commands with wrapped command method.
|
|
27636
|
-
*/
|
|
27637
|
-
get commands() {
|
|
27638
|
-
const { editor, state: state2 } = this;
|
|
27639
|
-
const { view } = editor;
|
|
27640
|
-
const { tr } = state2;
|
|
27641
|
-
const props = this.createProps(tr);
|
|
27642
|
-
const entries = Object.entries(this.rawCommands).map(([name, command2]) => {
|
|
27643
|
-
const method = (...args) => {
|
|
27644
|
-
const fn2 = command2(...args)(props);
|
|
27645
|
-
if (!tr.getMeta("preventDispatch")) {
|
|
27646
|
-
view.dispatch(tr);
|
|
27647
|
-
}
|
|
27648
|
-
return fn2;
|
|
27649
|
-
};
|
|
27650
|
-
return [name, method];
|
|
27651
|
-
});
|
|
27652
|
-
return Object.fromEntries(entries);
|
|
27653
|
-
}
|
|
27654
|
-
/**
|
|
27655
|
-
* Create a chain of commands to call multiple commands at once.
|
|
27656
|
-
*/
|
|
27657
|
-
get chain() {
|
|
27658
|
-
return () => this.createChain();
|
|
27659
|
-
}
|
|
27660
|
-
/**
|
|
27661
|
-
* Check if a command or a chain of commands can be executed. Without executing it.
|
|
27662
|
-
*/
|
|
27663
|
-
get can() {
|
|
27664
|
-
return () => this.createCan();
|
|
27665
|
-
}
|
|
27666
|
-
/**
|
|
27667
|
-
* Creates a chain of commands.
|
|
27668
|
-
* @param startTr Start transaction.
|
|
27669
|
-
* @param shouldDispatch Should dispatch or not.
|
|
27670
|
-
*/
|
|
27671
|
-
createChain(startTr, shouldDispatch = true) {
|
|
27672
|
-
const { editor, state: state2, rawCommands } = this;
|
|
27673
|
-
const { view } = editor;
|
|
27674
|
-
const callbacks2 = [];
|
|
27675
|
-
const hasStartTr = !!startTr;
|
|
27676
|
-
const tr = startTr || state2.tr;
|
|
27677
|
-
const run2 = () => {
|
|
27678
|
-
if (!hasStartTr && shouldDispatch && !tr.getMeta("preventDispatch")) {
|
|
27679
|
-
view.dispatch(tr);
|
|
27680
|
-
}
|
|
27681
|
-
return callbacks2.every((cb) => cb === true);
|
|
27682
|
-
};
|
|
27683
|
-
const entries = Object.entries(rawCommands).map(([name, command2]) => {
|
|
27684
|
-
const chainedCommand = (...args) => {
|
|
27685
|
-
const props = this.createProps(tr, shouldDispatch);
|
|
27686
|
-
const callback = command2(...args)(props);
|
|
27687
|
-
callbacks2.push(callback);
|
|
27688
|
-
return chain;
|
|
27689
|
-
};
|
|
27690
|
-
return [name, chainedCommand];
|
|
27691
|
-
});
|
|
27692
|
-
const chain = {
|
|
27693
|
-
...Object.fromEntries(entries),
|
|
27694
|
-
run: run2
|
|
27695
|
-
};
|
|
27696
|
-
return chain;
|
|
27697
|
-
}
|
|
27698
|
-
/**
|
|
27699
|
-
* Creates a can check for commands.
|
|
27700
|
-
* @param startTr Start transaction.
|
|
27701
|
-
*/
|
|
27702
|
-
createCan(startTr) {
|
|
27703
|
-
const { rawCommands, state: state2 } = this;
|
|
27704
|
-
const dispatch = false;
|
|
27705
|
-
const tr = startTr || state2.tr;
|
|
27706
|
-
const props = this.createProps(tr, dispatch);
|
|
27707
|
-
const commands2 = Object.fromEntries(
|
|
27708
|
-
Object.entries(rawCommands).map(([name, command2]) => {
|
|
27709
|
-
return [name, (...args) => command2(...args)({ ...props, dispatch: void 0 })];
|
|
27710
|
-
})
|
|
27711
|
-
);
|
|
27712
|
-
return {
|
|
27713
|
-
...commands2,
|
|
27714
|
-
chain: () => this.createChain(tr, dispatch)
|
|
27715
|
-
};
|
|
27716
|
-
}
|
|
27717
|
-
/**
|
|
27718
|
-
* Creates default props for the command method.
|
|
27719
|
-
* @param {*} tr Transaction.
|
|
27720
|
-
* @param {*} shouldDispatch Check if should dispatch.
|
|
27721
|
-
* @returns Object with props.
|
|
27722
|
-
*/
|
|
27723
|
-
createProps(tr, shouldDispatch = true) {
|
|
27724
|
-
const { editor, state: state2, rawCommands } = this;
|
|
27725
|
-
const { view } = editor;
|
|
27726
|
-
const props = {
|
|
27727
|
-
tr,
|
|
27728
|
-
editor,
|
|
27729
|
-
view,
|
|
27730
|
-
state: chainableEditorState(tr, state2),
|
|
27731
|
-
dispatch: shouldDispatch ? () => void 0 : void 0,
|
|
27732
|
-
chain: () => this.createChain(tr, shouldDispatch),
|
|
27733
|
-
can: () => this.createCan(tr),
|
|
27734
|
-
get commands() {
|
|
27735
|
-
return Object.fromEntries(
|
|
27736
|
-
Object.entries(rawCommands).map(([name, command2]) => {
|
|
27737
|
-
return [name, (...args) => command2(...args)(props)];
|
|
27738
|
-
})
|
|
27739
|
-
);
|
|
27740
|
-
}
|
|
27741
|
-
};
|
|
27742
|
-
return props;
|
|
27743
|
-
}
|
|
27744
|
-
}
|
|
27745
28164
|
const first = (commands2) => (props) => {
|
|
27746
28165
|
const items = typeof commands2 === "function" ? commands2(props) : commands2;
|
|
27747
28166
|
for (let i = 0; i < items.length; i += 1) {
|
|
@@ -28103,7 +28522,7 @@ function deleteBarrier(state2, $cut, dispatch, dir) {
|
|
|
28103
28522
|
for (let i = conn.length - 1; i >= 0; i--)
|
|
28104
28523
|
wrap2 = Fragment.from(conn[i].create(null, wrap2));
|
|
28105
28524
|
wrap2 = Fragment.from(before.copy(wrap2));
|
|
28106
|
-
let tr = state2.tr.step(new ReplaceAroundStep($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap2, 1, 0), conn.length, true));
|
|
28525
|
+
let tr = state2.tr.step(new ReplaceAroundStep$1($cut.pos - 1, end2, $cut.pos, end2, new Slice(wrap2, 1, 0), conn.length, true));
|
|
28107
28526
|
let $joinAt = tr.doc.resolve(end2 + 2 * conn.length);
|
|
28108
28527
|
if ($joinAt.nodeAfter && $joinAt.nodeAfter.type == before.type && canJoin(tr.doc, $joinAt.pos))
|
|
28109
28528
|
tr.join($joinAt.pos);
|
|
@@ -28134,7 +28553,7 @@ function deleteBarrier(state2, $cut, dispatch, dir) {
|
|
|
28134
28553
|
let end2 = Fragment.empty;
|
|
28135
28554
|
for (let i = wrap2.length - 1; i >= 0; i--)
|
|
28136
28555
|
end2 = Fragment.from(wrap2[i].copy(end2));
|
|
28137
|
-
let tr = state2.tr.step(new ReplaceAroundStep($cut.pos - wrap2.length, $cut.pos + after.nodeSize, $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, new Slice(end2, wrap2.length, 0), 0, true));
|
|
28556
|
+
let tr = state2.tr.step(new ReplaceAroundStep$1($cut.pos - wrap2.length, $cut.pos + after.nodeSize, $cut.pos + afterDepth, $cut.pos + after.nodeSize - afterDepth, new Slice(end2, wrap2.length, 0), 0, true));
|
|
28138
28557
|
dispatch(tr.scrollIntoView());
|
|
28139
28558
|
}
|
|
28140
28559
|
return true;
|
|
@@ -28707,7 +29126,7 @@ function selectionToInsertionEnd(tr, startLen, bias) {
|
|
|
28707
29126
|
return;
|
|
28708
29127
|
}
|
|
28709
29128
|
const step = tr.steps[last];
|
|
28710
|
-
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep)) {
|
|
29129
|
+
if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep$1)) {
|
|
28711
29130
|
return;
|
|
28712
29131
|
}
|
|
28713
29132
|
const map22 = tr.mapping.maps[last];
|
|
@@ -28853,7 +29272,7 @@ function doWrapInList(tr, range2, wrappers, joinBefore, listType) {
|
|
|
28853
29272
|
let content = Fragment.empty;
|
|
28854
29273
|
for (let i = wrappers.length - 1; i >= 0; i--)
|
|
28855
29274
|
content = Fragment.from(wrappers[i].type.create(wrappers[i].attrs, content));
|
|
28856
|
-
tr.step(new ReplaceAroundStep(range2.start - (joinBefore ? 2 : 0), range2.end, range2.start, range2.end, new Slice(content, 0, 0), wrappers.length, true));
|
|
29275
|
+
tr.step(new ReplaceAroundStep$1(range2.start - (joinBefore ? 2 : 0), range2.end, range2.start, range2.end, new Slice(content, 0, 0), wrappers.length, true));
|
|
28857
29276
|
let found2 = 0;
|
|
28858
29277
|
for (let i = 0; i < wrappers.length; i++)
|
|
28859
29278
|
if (wrappers[i].type == listType)
|
|
@@ -28886,7 +29305,7 @@ function liftListItem$1(itemType) {
|
|
|
28886
29305
|
function liftToOuterList(state2, dispatch, itemType, range2) {
|
|
28887
29306
|
let tr = state2.tr, end2 = range2.end, endOfList = range2.$to.end(range2.depth);
|
|
28888
29307
|
if (end2 < endOfList) {
|
|
28889
|
-
tr.step(new ReplaceAroundStep(end2 - 1, endOfList, end2, endOfList, new Slice(Fragment.from(itemType.create(null, range2.parent.copy())), 1, 0), 1, true));
|
|
29308
|
+
tr.step(new ReplaceAroundStep$1(end2 - 1, endOfList, end2, endOfList, new Slice(Fragment.from(itemType.create(null, range2.parent.copy())), 1, 0), 1, true));
|
|
28890
29309
|
range2 = new NodeRange(tr.doc.resolve(range2.$from.pos), tr.doc.resolve(endOfList), range2.depth);
|
|
28891
29310
|
}
|
|
28892
29311
|
const target = liftTarget(range2);
|
|
@@ -28913,7 +29332,7 @@ function liftOutOfList(state2, dispatch, range2) {
|
|
|
28913
29332
|
if (!parent.canReplace(indexBefore + (atStart ? 0 : 1), indexBefore + 1, item.content.append(atEnd ? Fragment.empty : Fragment.from(list))))
|
|
28914
29333
|
return false;
|
|
28915
29334
|
let start2 = $start.pos, end2 = start2 + item.nodeSize;
|
|
28916
|
-
tr.step(new ReplaceAroundStep(start2 - (atStart ? 1 : 0), end2 + (atEnd ? 1 : 0), start2 + 1, end2 - 1, new Slice((atStart ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))).append(atEnd ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1));
|
|
29335
|
+
tr.step(new ReplaceAroundStep$1(start2 - (atStart ? 1 : 0), end2 + (atEnd ? 1 : 0), start2 + 1, end2 - 1, new Slice((atStart ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))).append(atEnd ? Fragment.empty : Fragment.from(list.copy(Fragment.empty))), atStart ? 0 : 1, atEnd ? 0 : 1), atStart ? 0 : 1));
|
|
28917
29336
|
dispatch(tr.scrollIntoView());
|
|
28918
29337
|
return true;
|
|
28919
29338
|
}
|
|
@@ -28934,7 +29353,7 @@ function sinkListItem$1(itemType) {
|
|
|
28934
29353
|
let inner = Fragment.from(nestedBefore ? itemType.create() : null);
|
|
28935
29354
|
let slice2 = new Slice(Fragment.from(itemType.create(null, Fragment.from(parent.type.create(null, inner)))), nestedBefore ? 3 : 1, 0);
|
|
28936
29355
|
let before = range2.start, after = range2.end;
|
|
28937
|
-
dispatch(state2.tr.step(new ReplaceAroundStep(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
|
|
29356
|
+
dispatch(state2.tr.step(new ReplaceAroundStep$1(before - (nestedBefore ? 3 : 1), after, before, after, slice2, 1, true)).scrollIntoView());
|
|
28938
29357
|
}
|
|
28939
29358
|
return true;
|
|
28940
29359
|
};
|
|
@@ -36527,7 +36946,8 @@ const restoreRelativeSelection = (tr, relSel, binding) => {
|
|
|
36527
36946
|
binding.mapping
|
|
36528
36947
|
);
|
|
36529
36948
|
if (anchor !== null && head !== null) {
|
|
36530
|
-
|
|
36949
|
+
const sel = TextSelection.between(tr.doc.resolve(anchor), tr.doc.resolve(head));
|
|
36950
|
+
tr.setSelection(sel);
|
|
36531
36951
|
}
|
|
36532
36952
|
}
|
|
36533
36953
|
}
|
|
@@ -37308,7 +37728,7 @@ const setMeta = (view, key, value) => {
|
|
|
37308
37728
|
};
|
|
37309
37729
|
const absolutePositionToRelativePosition = (pos, type2, mapping) => {
|
|
37310
37730
|
if (pos === 0) {
|
|
37311
|
-
return Y.createRelativePositionFromTypeIndex(type2, 0, -1);
|
|
37731
|
+
return Y.createRelativePositionFromTypeIndex(type2, 0, type2.length === 0 ? -1 : 0);
|
|
37312
37732
|
}
|
|
37313
37733
|
let n = type2._first === null ? null : (
|
|
37314
37734
|
/** @type {Y.ContentType} */
|
|
@@ -37317,7 +37737,7 @@ const absolutePositionToRelativePosition = (pos, type2, mapping) => {
|
|
|
37317
37737
|
while (n !== null && type2 !== n) {
|
|
37318
37738
|
if (n instanceof Y.XmlText) {
|
|
37319
37739
|
if (n._length >= pos) {
|
|
37320
|
-
return Y.createRelativePositionFromTypeIndex(n, pos, -1);
|
|
37740
|
+
return Y.createRelativePositionFromTypeIndex(n, pos, type2.length === 0 ? -1 : 0);
|
|
37321
37741
|
} else {
|
|
37322
37742
|
pos -= n._length;
|
|
37323
37743
|
}
|
|
@@ -37381,7 +37801,7 @@ const absolutePositionToRelativePosition = (pos, type2, mapping) => {
|
|
|
37381
37801
|
return createRelativePosition(n._item.parent, n._item);
|
|
37382
37802
|
}
|
|
37383
37803
|
}
|
|
37384
|
-
return Y.createRelativePositionFromTypeIndex(type2, type2._length, -1);
|
|
37804
|
+
return Y.createRelativePositionFromTypeIndex(type2, type2._length, type2.length === 0 ? -1 : 0);
|
|
37385
37805
|
};
|
|
37386
37806
|
const createRelativePosition = (type2, item) => {
|
|
37387
37807
|
let typeid = null;
|
|
@@ -37693,693 +38113,290 @@ const yUndoPlugin = ({ protectedNodes = defaultProtectedNodes, trackedOrigins =
|
|
|
37693
38113
|
} else {
|
|
37694
38114
|
if (hasUndoOps !== val.hasUndoOps || hasRedoOps !== val.hasRedoOps) {
|
|
37695
38115
|
return Object.assign({}, val, {
|
|
37696
|
-
hasUndoOps: undoManager2.undoStack.length > 0,
|
|
37697
|
-
hasRedoOps: undoManager2.redoStack.length > 0
|
|
37698
|
-
});
|
|
37699
|
-
} else {
|
|
37700
|
-
return val;
|
|
37701
|
-
}
|
|
37702
|
-
}
|
|
37703
|
-
}
|
|
37704
|
-
},
|
|
37705
|
-
view: (view) => {
|
|
37706
|
-
const ystate = ySyncPluginKey.getState(view.state);
|
|
37707
|
-
const undoManager2 = yUndoPluginKey.getState(view.state).undoManager;
|
|
37708
|
-
undoManager2.on("stack-item-added", ({ stackItem }) => {
|
|
37709
|
-
const binding = ystate.binding;
|
|
37710
|
-
if (binding) {
|
|
37711
|
-
stackItem.meta.set(binding, yUndoPluginKey.getState(view.state).prevSel);
|
|
37712
|
-
}
|
|
37713
|
-
});
|
|
37714
|
-
undoManager2.on("stack-item-popped", ({ stackItem }) => {
|
|
37715
|
-
const binding = ystate.binding;
|
|
37716
|
-
if (binding) {
|
|
37717
|
-
binding.beforeTransactionSelection = stackItem.meta.get(binding) || binding.beforeTransactionSelection;
|
|
37718
|
-
}
|
|
37719
|
-
});
|
|
37720
|
-
return {
|
|
37721
|
-
destroy: () => {
|
|
37722
|
-
undoManager2.destroy();
|
|
37723
|
-
}
|
|
37724
|
-
};
|
|
37725
|
-
}
|
|
37726
|
-
});
|
|
37727
|
-
let EventEmitter$1 = class EventEmitter {
|
|
37728
|
-
constructor() {
|
|
37729
|
-
__privateAdd$1(this, _events, /* @__PURE__ */ new Map());
|
|
37730
|
-
}
|
|
37731
|
-
/**
|
|
37732
|
-
* Subscribe to the event.
|
|
37733
|
-
* @param {string} name Event name.
|
|
37734
|
-
* @param {(...args: any[]) => void} fn Callback.
|
|
37735
|
-
* @returns {void}
|
|
37736
|
-
*/
|
|
37737
|
-
on(name, fn2) {
|
|
37738
|
-
const callbacks2 = __privateGet$1(this, _events).get(name);
|
|
37739
|
-
if (callbacks2) callbacks2.push(fn2);
|
|
37740
|
-
else __privateGet$1(this, _events).set(name, [fn2]);
|
|
37741
|
-
}
|
|
37742
|
-
/**
|
|
37743
|
-
* Emit event.
|
|
37744
|
-
* @param {string} name Event name.
|
|
37745
|
-
* @param {...any} args – Arguments to pass to each listener.
|
|
37746
|
-
* @returns {void}
|
|
37747
|
-
*/
|
|
37748
|
-
emit(name, ...args) {
|
|
37749
|
-
const callbacks2 = __privateGet$1(this, _events).get(name);
|
|
37750
|
-
if (!callbacks2) return;
|
|
37751
|
-
for (const fn2 of callbacks2) {
|
|
37752
|
-
fn2.apply(this, args);
|
|
37753
|
-
}
|
|
37754
|
-
}
|
|
37755
|
-
/**
|
|
37756
|
-
* Remove a specific callback from event
|
|
37757
|
-
* or all event subscriptions.
|
|
37758
|
-
* @param {string} name Event name.
|
|
37759
|
-
* @param {(...args: any[]) => void} fn Callback.
|
|
37760
|
-
* @returns {void}
|
|
37761
|
-
*/
|
|
37762
|
-
off(name, fn2) {
|
|
37763
|
-
const callbacks2 = __privateGet$1(this, _events).get(name);
|
|
37764
|
-
if (!callbacks2) return;
|
|
37765
|
-
if (fn2) {
|
|
37766
|
-
__privateGet$1(this, _events).set(
|
|
37767
|
-
name,
|
|
37768
|
-
callbacks2.filter((cb) => cb !== fn2)
|
|
37769
|
-
);
|
|
37770
|
-
} else {
|
|
37771
|
-
__privateGet$1(this, _events).delete(name);
|
|
37772
|
-
}
|
|
37773
|
-
}
|
|
37774
|
-
/**
|
|
37775
|
-
* Subscribe to an event that will be called only once.
|
|
37776
|
-
* @param {string} name Event name.
|
|
37777
|
-
* @param {(...args: any[]) => void} fn Callback.
|
|
37778
|
-
* @returns {void}
|
|
37779
|
-
*/
|
|
37780
|
-
once(name, fn2) {
|
|
37781
|
-
const wrapper = (...args) => {
|
|
37782
|
-
this.off(name, wrapper);
|
|
37783
|
-
fn2.apply(this, args);
|
|
37784
|
-
};
|
|
37785
|
-
this.on(name, wrapper);
|
|
37786
|
-
}
|
|
37787
|
-
/**
|
|
37788
|
-
* Remove all registered events and subscriptions.
|
|
37789
|
-
*/
|
|
37790
|
-
removeAllListeners() {
|
|
37791
|
-
__privateSet(this, _events, /* @__PURE__ */ new Map());
|
|
37792
|
-
}
|
|
37793
|
-
};
|
|
37794
|
-
_events = /* @__PURE__ */ new WeakMap();
|
|
37795
|
-
var base$1 = {
|
|
37796
|
-
8: "Backspace",
|
|
37797
|
-
9: "Tab",
|
|
37798
|
-
10: "Enter",
|
|
37799
|
-
12: "NumLock",
|
|
37800
|
-
13: "Enter",
|
|
37801
|
-
16: "Shift",
|
|
37802
|
-
17: "Control",
|
|
37803
|
-
18: "Alt",
|
|
37804
|
-
20: "CapsLock",
|
|
37805
|
-
27: "Escape",
|
|
37806
|
-
32: " ",
|
|
37807
|
-
33: "PageUp",
|
|
37808
|
-
34: "PageDown",
|
|
37809
|
-
35: "End",
|
|
37810
|
-
36: "Home",
|
|
37811
|
-
37: "ArrowLeft",
|
|
37812
|
-
38: "ArrowUp",
|
|
37813
|
-
39: "ArrowRight",
|
|
37814
|
-
40: "ArrowDown",
|
|
37815
|
-
44: "PrintScreen",
|
|
37816
|
-
45: "Insert",
|
|
37817
|
-
46: "Delete",
|
|
37818
|
-
59: ";",
|
|
37819
|
-
61: "=",
|
|
37820
|
-
91: "Meta",
|
|
37821
|
-
92: "Meta",
|
|
37822
|
-
106: "*",
|
|
37823
|
-
107: "+",
|
|
37824
|
-
108: ",",
|
|
37825
|
-
109: "-",
|
|
37826
|
-
110: ".",
|
|
37827
|
-
111: "/",
|
|
37828
|
-
144: "NumLock",
|
|
37829
|
-
145: "ScrollLock",
|
|
37830
|
-
160: "Shift",
|
|
37831
|
-
161: "Shift",
|
|
37832
|
-
162: "Control",
|
|
37833
|
-
163: "Control",
|
|
37834
|
-
164: "Alt",
|
|
37835
|
-
165: "Alt",
|
|
37836
|
-
173: "-",
|
|
37837
|
-
186: ";",
|
|
37838
|
-
187: "=",
|
|
37839
|
-
188: ",",
|
|
37840
|
-
189: "-",
|
|
37841
|
-
190: ".",
|
|
37842
|
-
191: "/",
|
|
37843
|
-
192: "`",
|
|
37844
|
-
219: "[",
|
|
37845
|
-
220: "\\",
|
|
37846
|
-
221: "]",
|
|
37847
|
-
222: "'"
|
|
37848
|
-
};
|
|
37849
|
-
var shift = {
|
|
37850
|
-
48: ")",
|
|
37851
|
-
49: "!",
|
|
37852
|
-
50: "@",
|
|
37853
|
-
51: "#",
|
|
37854
|
-
52: "$",
|
|
37855
|
-
53: "%",
|
|
37856
|
-
54: "^",
|
|
37857
|
-
55: "&",
|
|
37858
|
-
56: "*",
|
|
37859
|
-
57: "(",
|
|
37860
|
-
59: ":",
|
|
37861
|
-
61: "+",
|
|
37862
|
-
173: "_",
|
|
37863
|
-
186: ":",
|
|
37864
|
-
187: "+",
|
|
37865
|
-
188: "<",
|
|
37866
|
-
189: "_",
|
|
37867
|
-
190: ">",
|
|
37868
|
-
191: "?",
|
|
37869
|
-
192: "~",
|
|
37870
|
-
219: "{",
|
|
37871
|
-
220: "|",
|
|
37872
|
-
221: "}",
|
|
37873
|
-
222: '"'
|
|
37874
|
-
};
|
|
37875
|
-
var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
|
|
37876
|
-
var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
|
|
37877
|
-
for (var i = 0; i < 10; i++) base$1[48 + i] = base$1[96 + i] = String(i);
|
|
37878
|
-
for (var i = 1; i <= 24; i++) base$1[i + 111] = "F" + i;
|
|
37879
|
-
for (var i = 65; i <= 90; i++) {
|
|
37880
|
-
base$1[i] = String.fromCharCode(i + 32);
|
|
37881
|
-
shift[i] = String.fromCharCode(i);
|
|
37882
|
-
}
|
|
37883
|
-
for (var code in base$1) if (!shift.hasOwnProperty(code)) shift[code] = base$1[code];
|
|
37884
|
-
function keyName(event) {
|
|
37885
|
-
var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
|
|
37886
|
-
var name = !ignoreKey && event.key || (event.shiftKey ? shift : base$1)[event.keyCode] || event.key || "Unidentified";
|
|
37887
|
-
if (name == "Esc") name = "Escape";
|
|
37888
|
-
if (name == "Del") name = "Delete";
|
|
37889
|
-
if (name == "Left") name = "ArrowLeft";
|
|
37890
|
-
if (name == "Up") name = "ArrowUp";
|
|
37891
|
-
if (name == "Right") name = "ArrowRight";
|
|
37892
|
-
if (name == "Down") name = "ArrowDown";
|
|
37893
|
-
return name;
|
|
37894
|
-
}
|
|
37895
|
-
const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
|
|
37896
|
-
const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
|
|
37897
|
-
function normalizeKeyName(name) {
|
|
37898
|
-
let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
|
|
37899
|
-
if (result == "Space")
|
|
37900
|
-
result = " ";
|
|
37901
|
-
let alt, ctrl, shift2, meta;
|
|
37902
|
-
for (let i = 0; i < parts.length - 1; i++) {
|
|
37903
|
-
let mod = parts[i];
|
|
37904
|
-
if (/^(cmd|meta|m)$/i.test(mod))
|
|
37905
|
-
meta = true;
|
|
37906
|
-
else if (/^a(lt)?$/i.test(mod))
|
|
37907
|
-
alt = true;
|
|
37908
|
-
else if (/^(c|ctrl|control)$/i.test(mod))
|
|
37909
|
-
ctrl = true;
|
|
37910
|
-
else if (/^s(hift)?$/i.test(mod))
|
|
37911
|
-
shift2 = true;
|
|
37912
|
-
else if (/^mod$/i.test(mod)) {
|
|
37913
|
-
if (mac)
|
|
37914
|
-
meta = true;
|
|
37915
|
-
else
|
|
37916
|
-
ctrl = true;
|
|
37917
|
-
} else
|
|
37918
|
-
throw new Error("Unrecognized modifier name: " + mod);
|
|
37919
|
-
}
|
|
37920
|
-
if (alt)
|
|
37921
|
-
result = "Alt-" + result;
|
|
37922
|
-
if (ctrl)
|
|
37923
|
-
result = "Ctrl-" + result;
|
|
37924
|
-
if (meta)
|
|
37925
|
-
result = "Meta-" + result;
|
|
37926
|
-
if (shift2)
|
|
37927
|
-
result = "Shift-" + result;
|
|
37928
|
-
return result;
|
|
37929
|
-
}
|
|
37930
|
-
function normalize(map22) {
|
|
37931
|
-
let copy2 = /* @__PURE__ */ Object.create(null);
|
|
37932
|
-
for (let prop in map22)
|
|
37933
|
-
copy2[normalizeKeyName(prop)] = map22[prop];
|
|
37934
|
-
return copy2;
|
|
37935
|
-
}
|
|
37936
|
-
function modifiers(name, event, shift2 = true) {
|
|
37937
|
-
if (event.altKey)
|
|
37938
|
-
name = "Alt-" + name;
|
|
37939
|
-
if (event.ctrlKey)
|
|
37940
|
-
name = "Ctrl-" + name;
|
|
37941
|
-
if (event.metaKey)
|
|
37942
|
-
name = "Meta-" + name;
|
|
37943
|
-
if (shift2 && event.shiftKey)
|
|
37944
|
-
name = "Shift-" + name;
|
|
37945
|
-
return name;
|
|
37946
|
-
}
|
|
37947
|
-
function keymap(bindings) {
|
|
37948
|
-
return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
|
|
37949
|
-
}
|
|
37950
|
-
function keydownHandler(bindings) {
|
|
37951
|
-
let map22 = normalize(bindings);
|
|
37952
|
-
return function(view, event) {
|
|
37953
|
-
let name = keyName(event), baseName, direct = map22[modifiers(name, event)];
|
|
37954
|
-
if (direct && direct(view.state, view.dispatch, view))
|
|
37955
|
-
return true;
|
|
37956
|
-
if (name.length == 1 && name != " ") {
|
|
37957
|
-
if (event.shiftKey) {
|
|
37958
|
-
let noShift = map22[modifiers(name, event, false)];
|
|
37959
|
-
if (noShift && noShift(view.state, view.dispatch, view))
|
|
37960
|
-
return true;
|
|
37961
|
-
}
|
|
37962
|
-
if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
|
|
37963
|
-
!(windows && event.ctrlKey && event.altKey) && (baseName = base$1[event.keyCode]) && baseName != name) {
|
|
37964
|
-
let fromCode = map22[modifiers(baseName, event)];
|
|
37965
|
-
if (fromCode && fromCode(view.state, view.dispatch, view))
|
|
37966
|
-
return true;
|
|
37967
|
-
}
|
|
37968
|
-
}
|
|
37969
|
-
return false;
|
|
37970
|
-
};
|
|
37971
|
-
}
|
|
37972
|
-
function isExtensionRulesEnabled(extension, enabled) {
|
|
37973
|
-
if (Array.isArray(enabled)) {
|
|
37974
|
-
return enabled.some((enabledExtension) => {
|
|
37975
|
-
const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
|
|
37976
|
-
return name === extension.name;
|
|
37977
|
-
});
|
|
37978
|
-
}
|
|
37979
|
-
return enabled;
|
|
37980
|
-
}
|
|
37981
|
-
function getHTMLFromFragment(fragment, schema) {
|
|
37982
|
-
const documentFragment = DOMSerializer.fromSchema(schema).serializeFragment(fragment);
|
|
37983
|
-
const temporaryDocument = document.implementation.createHTMLDocument();
|
|
37984
|
-
const container = temporaryDocument.createElement("div");
|
|
37985
|
-
container.appendChild(documentFragment);
|
|
37986
|
-
return container.innerHTML;
|
|
37987
|
-
}
|
|
37988
|
-
const getTextContentFromNodes = ($from, maxMatch = 500) => {
|
|
37989
|
-
let textBefore = "";
|
|
37990
|
-
const sliceEndPos = $from.parentOffset;
|
|
37991
|
-
$from.parent.nodesBetween(
|
|
37992
|
-
Math.max(0, sliceEndPos - maxMatch),
|
|
37993
|
-
sliceEndPos,
|
|
37994
|
-
(node2, pos, parent, index2) => {
|
|
37995
|
-
const chunk = node2.type.spec.toText?.({
|
|
37996
|
-
node: node2,
|
|
37997
|
-
pos,
|
|
37998
|
-
parent,
|
|
37999
|
-
index: index2
|
|
38000
|
-
}) || node2.textContent || "%leaf%";
|
|
38001
|
-
textBefore += node2.isAtom && !node2.isText ? chunk : chunk.slice(0, Math.max(0, sliceEndPos - pos));
|
|
38002
|
-
}
|
|
38003
|
-
);
|
|
38004
|
-
return textBefore;
|
|
38005
|
-
};
|
|
38006
|
-
const handleDocxPaste = (html, editor, view, plugin2) => {
|
|
38007
|
-
const { converter } = editor;
|
|
38008
|
-
if (!converter || !converter.convertedXml) return handleHtmlPaste(html, editor, view, plugin2);
|
|
38009
|
-
let cleanedHtml = convertEmToPt(html);
|
|
38010
|
-
cleanedHtml = cleanHtmlUnnecessaryTags(cleanedHtml);
|
|
38011
|
-
const tempDiv = document.createElement("div");
|
|
38012
|
-
tempDiv.innerHTML = cleanedHtml;
|
|
38013
|
-
const paragraphs = tempDiv.querySelectorAll("p");
|
|
38014
|
-
paragraphs.forEach((p) => {
|
|
38015
|
-
const innerHTML3 = p.innerHTML;
|
|
38016
|
-
if (!innerHTML3.includes("<!--[if !supportLists]")) return;
|
|
38017
|
-
const styleAttr = p.getAttribute("style") || "";
|
|
38018
|
-
const msoListMatch = styleAttr.match(/mso-list:\s*l(\d+)\s+level(\d+)/);
|
|
38019
|
-
if (msoListMatch) {
|
|
38020
|
-
const [, abstractId, level] = msoListMatch;
|
|
38021
|
-
const listNumId = getListNumIdFromAbstract(abstractId, editor);
|
|
38022
|
-
if (!listNumId) return;
|
|
38023
|
-
const abstractDefinition = getListAbstractDefinition(abstractId, editor);
|
|
38024
|
-
const { lvlText, start: start2, numFmt } = getLevelDefinition(abstractDefinition, level - 1);
|
|
38025
|
-
p.setAttribute("data-num-id", listNumId);
|
|
38026
|
-
p.setAttribute("data-list-level", level - 1);
|
|
38027
|
-
p.setAttribute("data-start", start2);
|
|
38028
|
-
p.setAttribute("data-lvl-text", lvlText);
|
|
38029
|
-
p.setAttribute("data-num-fmt", numFmt);
|
|
38030
|
-
}
|
|
38031
|
-
extractAndRemoveConditionalPrefix(p);
|
|
38032
|
-
});
|
|
38033
|
-
transformWordLists(tempDiv);
|
|
38034
|
-
const doc2 = DOMParser$1.fromSchema(editor.schema).parse(tempDiv);
|
|
38035
|
-
tempDiv.remove();
|
|
38036
|
-
const { dispatch } = editor.view;
|
|
38037
|
-
if (!dispatch) return false;
|
|
38038
|
-
dispatch(view.state.tr.replaceSelectionWith(doc2, true));
|
|
38039
|
-
return true;
|
|
38040
|
-
};
|
|
38041
|
-
const getLevelDefinition = (abstractDefinition, level) => {
|
|
38042
|
-
if (!abstractDefinition || !abstractDefinition.elements) return null;
|
|
38043
|
-
const levelElement = abstractDefinition.elements.find((el) => {
|
|
38044
|
-
return el.name === "w:lvl" && el.attributes?.["w:ilvl"] == level;
|
|
38045
|
-
});
|
|
38046
|
-
if (!levelElement) return null;
|
|
38047
|
-
const { elements } = levelElement;
|
|
38048
|
-
const lvlText = elements.find((el) => el.name === "w:lvlText")?.attributes?.["w:val"];
|
|
38049
|
-
const start2 = elements.find((el) => el.name === "w:start")?.attributes?.["w:val"];
|
|
38050
|
-
const numFmt = elements.find((el) => el.name === "w:numFmt")?.attributes?.["w:val"];
|
|
38051
|
-
return { lvlText, start: start2, numFmt, elements };
|
|
38052
|
-
};
|
|
38053
|
-
const getListNumIdFromAbstract = (abstractId, editor) => {
|
|
38054
|
-
const { definitions } = editor?.converter?.numbering;
|
|
38055
|
-
if (!definitions) return null;
|
|
38056
|
-
const matchedDefinition = Object.values(definitions).find((def) => {
|
|
38057
|
-
return def.elements.some((el) => el.name === "w:abstractNumId" && el.attributes?.["w:val"] == abstractId);
|
|
38058
|
-
});
|
|
38059
|
-
return matchedDefinition?.attributes?.["w:numId"];
|
|
38060
|
-
};
|
|
38061
|
-
const getListAbstractDefinition = (abstractId, editor) => {
|
|
38062
|
-
const { abstracts = {} } = editor?.converter?.numbering;
|
|
38063
|
-
return abstracts[abstractId] || null;
|
|
38064
|
-
};
|
|
38065
|
-
const transformWordLists = (container) => {
|
|
38066
|
-
const paragraphs = Array.from(container.querySelectorAll("p[data-num-id]"));
|
|
38067
|
-
const listMap = /* @__PURE__ */ new Map();
|
|
38068
|
-
const listLevels = {};
|
|
38069
|
-
for (const p of paragraphs) {
|
|
38070
|
-
const listId = p.getAttribute("data-num-id");
|
|
38071
|
-
const level = parseInt(p.getAttribute("data-list-level"));
|
|
38072
|
-
const numFmt = p.getAttribute("data-num-fmt");
|
|
38073
|
-
const start2 = p.getAttribute("data-start");
|
|
38074
|
-
const lvlText = p.getAttribute("data-lvl-text");
|
|
38075
|
-
if (!listMap.has(listId)) listMap.set(listId, []);
|
|
38076
|
-
listMap.get(listId).push({ p, level, numFmt, start: start2, lvlText });
|
|
38077
|
-
}
|
|
38078
|
-
for (const [id, items] of listMap.entries()) {
|
|
38079
|
-
if (!listLevels[id]) {
|
|
38080
|
-
listLevels[id] = {
|
|
38081
|
-
stack: [],
|
|
38082
|
-
counts: {},
|
|
38083
|
-
prevLevel: null
|
|
38084
|
-
};
|
|
38085
|
-
}
|
|
38086
|
-
const parentStack = [];
|
|
38087
|
-
items.forEach(({ p, level, numFmt, start: start2, lvlText }, index2) => {
|
|
38088
|
-
const listLevel = generateListNestingPath(listLevels, id, level);
|
|
38089
|
-
const li = document.createElement("li");
|
|
38090
|
-
li.innerHTML = p.innerHTML;
|
|
38091
|
-
li.setAttribute("data-list-level", JSON.stringify(listLevel));
|
|
38092
|
-
li.setAttribute("data-num-id", id);
|
|
38093
|
-
li.setAttribute("data-lvl-text", lvlText);
|
|
38094
|
-
li.setAttribute("data-num-fmt", numFmt);
|
|
38095
|
-
if (p.hasAttribute("data-font-family")) {
|
|
38096
|
-
li.setAttribute("data-font-family", p.getAttribute("data-font-family"));
|
|
38097
|
-
}
|
|
38098
|
-
if (p.hasAttribute("data-font-size")) {
|
|
38099
|
-
li.setAttribute("data-font-size", p.getAttribute("data-font-size"));
|
|
38100
|
-
}
|
|
38101
|
-
const parentNode2 = p.parentNode;
|
|
38102
|
-
let listForLevel = parentStack[level];
|
|
38103
|
-
if (!listForLevel) {
|
|
38104
|
-
const newList = document.createElement("ol");
|
|
38105
|
-
newList.setAttribute("data-list-id", id);
|
|
38106
|
-
newList.level = level;
|
|
38107
|
-
if (level > 0) {
|
|
38108
|
-
const parentLi = parentStack[level - 1]?.querySelector("li:last-child");
|
|
38109
|
-
if (parentLi) parentLi.appendChild(newList);
|
|
38110
|
-
} else {
|
|
38111
|
-
parentNode2.insertBefore(newList, p);
|
|
38112
|
-
}
|
|
38113
|
-
parentStack[level] = newList;
|
|
38114
|
-
parentStack.length = level + 1;
|
|
38115
|
-
listForLevel = newList;
|
|
38116
|
-
}
|
|
38117
|
-
listForLevel.appendChild(li);
|
|
38118
|
-
p.remove();
|
|
38119
|
-
});
|
|
38120
|
-
}
|
|
38121
|
-
};
|
|
38122
|
-
function generateListNestingPath(listLevels, listId, currentLevel) {
|
|
38123
|
-
const levelState = listLevels[listId];
|
|
38124
|
-
if (!levelState.stack) levelState.stack = [];
|
|
38125
|
-
if (levelState.prevLevel === void 0) levelState.prevLevel = null;
|
|
38126
|
-
if (levelState.prevLevel === null) {
|
|
38127
|
-
levelState.stack = Array(currentLevel).fill(1).concat(1);
|
|
38128
|
-
} else {
|
|
38129
|
-
if (currentLevel > levelState.prevLevel) {
|
|
38130
|
-
levelState.stack.push(1);
|
|
38131
|
-
} else if (currentLevel === levelState.prevLevel) {
|
|
38132
|
-
levelState.stack[levelState.stack.length - 1]++;
|
|
38133
|
-
} else {
|
|
38134
|
-
levelState.stack = levelState.stack.slice(0, currentLevel + 1);
|
|
38135
|
-
levelState.stack[currentLevel] = (levelState.stack[currentLevel] || 1) + 1;
|
|
38136
|
-
}
|
|
38137
|
-
}
|
|
38138
|
-
levelState.prevLevel = currentLevel;
|
|
38139
|
-
return [...levelState.stack];
|
|
38140
|
-
}
|
|
38141
|
-
function extractAndRemoveConditionalPrefix(p) {
|
|
38142
|
-
const nodes = Array.from(p.childNodes);
|
|
38143
|
-
let fontFamily2 = null;
|
|
38144
|
-
let fontSize2 = null;
|
|
38145
|
-
let start2 = -1, end2 = -1;
|
|
38146
|
-
nodes.forEach((node2, index2) => {
|
|
38147
|
-
if (node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[if !supportLists]")) {
|
|
38148
|
-
start2 = index2;
|
|
38149
|
-
}
|
|
38150
|
-
if (start2 !== -1 && node2.nodeType === Node.COMMENT_NODE && node2.nodeValue.includes("[endif]")) {
|
|
38151
|
-
end2 = index2;
|
|
38152
|
-
}
|
|
38153
|
-
});
|
|
38154
|
-
if (start2 !== -1 && end2 !== -1) {
|
|
38155
|
-
for (let i = start2 + 1; i < end2; i++) {
|
|
38156
|
-
const node2 = nodes[i];
|
|
38157
|
-
if (node2.nodeType === Node.ELEMENT_NODE && node2.style) {
|
|
38158
|
-
fontFamily2 = fontFamily2 || node2.style.fontFamily;
|
|
38159
|
-
fontSize2 = fontSize2 || node2.style.fontSize;
|
|
38160
|
-
}
|
|
38161
|
-
}
|
|
38162
|
-
for (let i = end2; i >= start2; i--) {
|
|
38163
|
-
p.removeChild(p.childNodes[i]);
|
|
38164
|
-
}
|
|
38165
|
-
if (fontFamily2) p.setAttribute("data-font-family", fontFamily2);
|
|
38166
|
-
if (fontSize2) p.setAttribute("data-font-size", fontSize2);
|
|
38167
|
-
}
|
|
38168
|
-
}
|
|
38169
|
-
class InputRule {
|
|
38170
|
-
constructor(config) {
|
|
38171
|
-
__publicField$1(this, "match");
|
|
38172
|
-
__publicField$1(this, "handler");
|
|
38173
|
-
this.match = config.match;
|
|
38174
|
-
this.handler = config.handler;
|
|
38175
|
-
}
|
|
38176
|
-
}
|
|
38177
|
-
const inputRuleMatcherHandler = (text, match) => {
|
|
38178
|
-
if (isRegExp(match)) {
|
|
38179
|
-
return match.exec(text);
|
|
38180
|
-
}
|
|
38181
|
-
const inputRuleMatch = match(text);
|
|
38182
|
-
if (!inputRuleMatch) {
|
|
38183
|
-
return null;
|
|
38184
|
-
}
|
|
38185
|
-
const result = [inputRuleMatch.text];
|
|
38186
|
-
result.index = inputRuleMatch.index;
|
|
38187
|
-
result.input = text;
|
|
38188
|
-
result.data = inputRuleMatch.data;
|
|
38189
|
-
if (inputRuleMatch.replaceWith) {
|
|
38190
|
-
if (!inputRuleMatch.text.includes(inputRuleMatch.replaceWith)) {
|
|
38191
|
-
console.warn(
|
|
38192
|
-
'[super-editor warn]: "inputRuleMatch.replaceWith" must be part of "inputRuleMatch.text".'
|
|
38193
|
-
);
|
|
38194
|
-
}
|
|
38195
|
-
result.push(inputRuleMatch.replaceWith);
|
|
38196
|
-
}
|
|
38197
|
-
return result;
|
|
38198
|
-
};
|
|
38199
|
-
const run = (config) => {
|
|
38200
|
-
const {
|
|
38201
|
-
editor,
|
|
38202
|
-
from: from2,
|
|
38203
|
-
to,
|
|
38204
|
-
text,
|
|
38205
|
-
rules,
|
|
38206
|
-
plugin: plugin2
|
|
38207
|
-
} = config;
|
|
38208
|
-
const { view } = editor;
|
|
38209
|
-
if (view.composing) {
|
|
38210
|
-
return false;
|
|
38211
|
-
}
|
|
38212
|
-
const $from = view.state.doc.resolve(from2);
|
|
38213
|
-
if ($from.parent.type.spec.code || !!($from.nodeBefore || $from.nodeAfter)?.marks.find((mark) => mark.type.spec.code)) {
|
|
38214
|
-
return false;
|
|
38215
|
-
}
|
|
38216
|
-
let matched = false;
|
|
38217
|
-
const textBefore = getTextContentFromNodes($from) + text;
|
|
38218
|
-
rules.forEach((rule) => {
|
|
38219
|
-
if (matched) {
|
|
38220
|
-
return;
|
|
38221
|
-
}
|
|
38222
|
-
const match = inputRuleMatcherHandler(textBefore, rule.match);
|
|
38223
|
-
if (!match) {
|
|
38224
|
-
return;
|
|
38225
|
-
}
|
|
38226
|
-
const tr = view.state.tr;
|
|
38227
|
-
const state2 = chainableEditorState(tr, view.state);
|
|
38228
|
-
const range2 = {
|
|
38229
|
-
from: from2 - (match[0].length - text.length),
|
|
38230
|
-
to
|
|
38231
|
-
};
|
|
38232
|
-
const { commands: commands2, chain, can } = new CommandService({
|
|
38233
|
-
editor,
|
|
38234
|
-
state: state2
|
|
38235
|
-
});
|
|
38236
|
-
const handler = rule.handler({
|
|
38237
|
-
state: state2,
|
|
38238
|
-
range: range2,
|
|
38239
|
-
match,
|
|
38240
|
-
commands: commands2,
|
|
38241
|
-
chain,
|
|
38242
|
-
can
|
|
38243
|
-
});
|
|
38244
|
-
if (handler === null || !tr.steps.length) {
|
|
38245
|
-
return;
|
|
38246
|
-
}
|
|
38247
|
-
tr.setMeta(plugin2, {
|
|
38248
|
-
transform: tr,
|
|
38249
|
-
from: from2,
|
|
38250
|
-
to,
|
|
38251
|
-
text
|
|
38252
|
-
});
|
|
38253
|
-
view.dispatch(tr);
|
|
38254
|
-
matched = true;
|
|
38255
|
-
});
|
|
38256
|
-
return matched;
|
|
38257
|
-
};
|
|
38258
|
-
const inputRulesPlugin = ({ editor, rules }) => {
|
|
38259
|
-
const plugin2 = new Plugin({
|
|
38260
|
-
key: new PluginKey("inputRulesPlugin"),
|
|
38261
|
-
state: {
|
|
38262
|
-
init() {
|
|
38263
|
-
return null;
|
|
38264
|
-
},
|
|
38265
|
-
apply(tr, prev, state2) {
|
|
38266
|
-
const stored = tr.getMeta(plugin2);
|
|
38267
|
-
if (stored) {
|
|
38268
|
-
return stored;
|
|
38269
|
-
}
|
|
38270
|
-
const simulatedInputMeta = tr.getMeta("applyInputRules");
|
|
38271
|
-
const isSimulatedInput = !!simulatedInputMeta;
|
|
38272
|
-
if (isSimulatedInput) {
|
|
38273
|
-
setTimeout(() => {
|
|
38274
|
-
let { text } = simulatedInputMeta;
|
|
38275
|
-
if (typeof text !== "string") {
|
|
38276
|
-
text = getHTMLFromFragment(Fragment.from(text), state2.schema);
|
|
38277
|
-
}
|
|
38278
|
-
const { from: from2 } = simulatedInputMeta;
|
|
38279
|
-
const to = from2 + text.length;
|
|
38280
|
-
run({
|
|
38281
|
-
editor,
|
|
38282
|
-
from: from2,
|
|
38283
|
-
to,
|
|
38284
|
-
text,
|
|
38285
|
-
rules,
|
|
38286
|
-
plugin: plugin2
|
|
38287
|
-
});
|
|
38288
|
-
});
|
|
38289
|
-
}
|
|
38290
|
-
return tr.selectionSet || tr.docChanged ? null : prev;
|
|
38291
|
-
}
|
|
38292
|
-
},
|
|
38293
|
-
props: {
|
|
38294
|
-
handleTextInput(view, from2, to, text) {
|
|
38295
|
-
return run({
|
|
38296
|
-
editor,
|
|
38297
|
-
from: from2,
|
|
38298
|
-
to,
|
|
38299
|
-
text,
|
|
38300
|
-
rules,
|
|
38301
|
-
plugin: plugin2
|
|
38302
|
-
});
|
|
38303
|
-
},
|
|
38304
|
-
// add support for input rules to trigger on enter
|
|
38305
|
-
// this is useful for example for code blocks
|
|
38306
|
-
handleKeyDown(view, event) {
|
|
38307
|
-
if (event.key !== "Enter") {
|
|
38308
|
-
return false;
|
|
38309
|
-
}
|
|
38310
|
-
const { $cursor } = view.state.selection;
|
|
38311
|
-
if ($cursor) {
|
|
38312
|
-
return run({
|
|
38313
|
-
editor,
|
|
38314
|
-
from: $cursor.pos,
|
|
38315
|
-
to: $cursor.pos,
|
|
38316
|
-
text: "\n",
|
|
38317
|
-
rules,
|
|
38318
|
-
plugin: plugin2
|
|
38116
|
+
hasUndoOps: undoManager2.undoStack.length > 0,
|
|
38117
|
+
hasRedoOps: undoManager2.redoStack.length > 0
|
|
38319
38118
|
});
|
|
38320
|
-
}
|
|
38321
|
-
return false;
|
|
38322
|
-
},
|
|
38323
|
-
// Paste handler
|
|
38324
|
-
handlePaste(view, event, slice2) {
|
|
38325
|
-
const clipboard = event.clipboardData;
|
|
38326
|
-
const html = clipboard.getData("text/html");
|
|
38327
|
-
clipboard.getData("text/plain");
|
|
38328
|
-
const fieldAnnotationContent = slice2.content.content.filter((item) => item.type.name === "fieldAnnotation");
|
|
38329
|
-
if (fieldAnnotationContent.length) {
|
|
38330
|
-
return false;
|
|
38331
|
-
}
|
|
38332
|
-
let source;
|
|
38333
|
-
if (!html) {
|
|
38334
|
-
source = "plain-text";
|
|
38335
|
-
} else if (isWordHtml(html)) {
|
|
38336
|
-
source = "word-html";
|
|
38337
38119
|
} else {
|
|
38338
|
-
|
|
38339
|
-
}
|
|
38340
|
-
switch (source) {
|
|
38341
|
-
case "plain-text":
|
|
38342
|
-
break;
|
|
38343
|
-
case "word-html":
|
|
38344
|
-
if (editor.options.mode === "docx") {
|
|
38345
|
-
return handleDocxPaste(html, editor, view, plugin2);
|
|
38346
|
-
}
|
|
38347
|
-
case "browser-html":
|
|
38348
|
-
return handleHtmlPaste$1(html, editor);
|
|
38120
|
+
return val;
|
|
38349
38121
|
}
|
|
38350
|
-
return false;
|
|
38351
38122
|
}
|
|
38352
|
-
}
|
|
38353
|
-
|
|
38354
|
-
|
|
38355
|
-
|
|
38123
|
+
}
|
|
38124
|
+
},
|
|
38125
|
+
view: (view) => {
|
|
38126
|
+
const ystate = ySyncPluginKey.getState(view.state);
|
|
38127
|
+
const undoManager2 = yUndoPluginKey.getState(view.state).undoManager;
|
|
38128
|
+
undoManager2.on("stack-item-added", ({ stackItem }) => {
|
|
38129
|
+
const binding = ystate.binding;
|
|
38130
|
+
if (binding) {
|
|
38131
|
+
stackItem.meta.set(binding, yUndoPluginKey.getState(view.state).prevSel);
|
|
38132
|
+
}
|
|
38133
|
+
});
|
|
38134
|
+
undoManager2.on("stack-item-popped", ({ stackItem }) => {
|
|
38135
|
+
const binding = ystate.binding;
|
|
38136
|
+
if (binding) {
|
|
38137
|
+
binding.beforeTransactionSelection = stackItem.meta.get(binding) || binding.beforeTransactionSelection;
|
|
38138
|
+
}
|
|
38139
|
+
});
|
|
38140
|
+
return {
|
|
38141
|
+
destroy: () => {
|
|
38142
|
+
undoManager2.destroy();
|
|
38143
|
+
}
|
|
38144
|
+
};
|
|
38145
|
+
}
|
|
38146
|
+
});
|
|
38147
|
+
let EventEmitter$1 = class EventEmitter {
|
|
38148
|
+
constructor() {
|
|
38149
|
+
__privateAdd$1(this, _events, /* @__PURE__ */ new Map());
|
|
38150
|
+
}
|
|
38151
|
+
/**
|
|
38152
|
+
* Subscribe to the event.
|
|
38153
|
+
* @param {string} name Event name.
|
|
38154
|
+
* @param {(...args: any[]) => void} fn Callback.
|
|
38155
|
+
* @returns {void}
|
|
38156
|
+
*/
|
|
38157
|
+
on(name, fn2) {
|
|
38158
|
+
const callbacks2 = __privateGet$1(this, _events).get(name);
|
|
38159
|
+
if (callbacks2) callbacks2.push(fn2);
|
|
38160
|
+
else __privateGet$1(this, _events).set(name, [fn2]);
|
|
38161
|
+
}
|
|
38162
|
+
/**
|
|
38163
|
+
* Emit event.
|
|
38164
|
+
* @param {string} name Event name.
|
|
38165
|
+
* @param {...any} args – Arguments to pass to each listener.
|
|
38166
|
+
* @returns {void}
|
|
38167
|
+
*/
|
|
38168
|
+
emit(name, ...args) {
|
|
38169
|
+
const callbacks2 = __privateGet$1(this, _events).get(name);
|
|
38170
|
+
if (!callbacks2) return;
|
|
38171
|
+
for (const fn2 of callbacks2) {
|
|
38172
|
+
fn2.apply(this, args);
|
|
38173
|
+
}
|
|
38174
|
+
}
|
|
38175
|
+
/**
|
|
38176
|
+
* Remove a specific callback from event
|
|
38177
|
+
* or all event subscriptions.
|
|
38178
|
+
* @param {string} name Event name.
|
|
38179
|
+
* @param {(...args: any[]) => void} fn Callback.
|
|
38180
|
+
* @returns {void}
|
|
38181
|
+
*/
|
|
38182
|
+
off(name, fn2) {
|
|
38183
|
+
const callbacks2 = __privateGet$1(this, _events).get(name);
|
|
38184
|
+
if (!callbacks2) return;
|
|
38185
|
+
if (fn2) {
|
|
38186
|
+
__privateGet$1(this, _events).set(
|
|
38187
|
+
name,
|
|
38188
|
+
callbacks2.filter((cb) => cb !== fn2)
|
|
38189
|
+
);
|
|
38190
|
+
} else {
|
|
38191
|
+
__privateGet$1(this, _events).delete(name);
|
|
38192
|
+
}
|
|
38193
|
+
}
|
|
38194
|
+
/**
|
|
38195
|
+
* Subscribe to an event that will be called only once.
|
|
38196
|
+
* @param {string} name Event name.
|
|
38197
|
+
* @param {(...args: any[]) => void} fn Callback.
|
|
38198
|
+
* @returns {void}
|
|
38199
|
+
*/
|
|
38200
|
+
once(name, fn2) {
|
|
38201
|
+
const wrapper = (...args) => {
|
|
38202
|
+
this.off(name, wrapper);
|
|
38203
|
+
fn2.apply(this, args);
|
|
38204
|
+
};
|
|
38205
|
+
this.on(name, wrapper);
|
|
38206
|
+
}
|
|
38207
|
+
/**
|
|
38208
|
+
* Remove all registered events and subscriptions.
|
|
38209
|
+
*/
|
|
38210
|
+
removeAllListeners() {
|
|
38211
|
+
__privateSet(this, _events, /* @__PURE__ */ new Map());
|
|
38212
|
+
}
|
|
38356
38213
|
};
|
|
38357
|
-
|
|
38358
|
-
|
|
38359
|
-
|
|
38360
|
-
|
|
38361
|
-
|
|
38362
|
-
|
|
38363
|
-
|
|
38364
|
-
|
|
38365
|
-
|
|
38366
|
-
|
|
38367
|
-
|
|
38368
|
-
|
|
38369
|
-
|
|
38214
|
+
_events = /* @__PURE__ */ new WeakMap();
|
|
38215
|
+
var base$1 = {
|
|
38216
|
+
8: "Backspace",
|
|
38217
|
+
9: "Tab",
|
|
38218
|
+
10: "Enter",
|
|
38219
|
+
12: "NumLock",
|
|
38220
|
+
13: "Enter",
|
|
38221
|
+
16: "Shift",
|
|
38222
|
+
17: "Control",
|
|
38223
|
+
18: "Alt",
|
|
38224
|
+
20: "CapsLock",
|
|
38225
|
+
27: "Escape",
|
|
38226
|
+
32: " ",
|
|
38227
|
+
33: "PageUp",
|
|
38228
|
+
34: "PageDown",
|
|
38229
|
+
35: "End",
|
|
38230
|
+
36: "Home",
|
|
38231
|
+
37: "ArrowLeft",
|
|
38232
|
+
38: "ArrowUp",
|
|
38233
|
+
39: "ArrowRight",
|
|
38234
|
+
40: "ArrowDown",
|
|
38235
|
+
44: "PrintScreen",
|
|
38236
|
+
45: "Insert",
|
|
38237
|
+
46: "Delete",
|
|
38238
|
+
59: ";",
|
|
38239
|
+
61: "=",
|
|
38240
|
+
91: "Meta",
|
|
38241
|
+
92: "Meta",
|
|
38242
|
+
106: "*",
|
|
38243
|
+
107: "+",
|
|
38244
|
+
108: ",",
|
|
38245
|
+
109: "-",
|
|
38246
|
+
110: ".",
|
|
38247
|
+
111: "/",
|
|
38248
|
+
144: "NumLock",
|
|
38249
|
+
145: "ScrollLock",
|
|
38250
|
+
160: "Shift",
|
|
38251
|
+
161: "Shift",
|
|
38252
|
+
162: "Control",
|
|
38253
|
+
163: "Control",
|
|
38254
|
+
164: "Alt",
|
|
38255
|
+
165: "Alt",
|
|
38256
|
+
173: "-",
|
|
38257
|
+
186: ";",
|
|
38258
|
+
187: "=",
|
|
38259
|
+
188: ",",
|
|
38260
|
+
189: "-",
|
|
38261
|
+
190: ".",
|
|
38262
|
+
191: "/",
|
|
38263
|
+
192: "`",
|
|
38264
|
+
219: "[",
|
|
38265
|
+
220: "\\",
|
|
38266
|
+
221: "]",
|
|
38267
|
+
222: "'"
|
|
38370
38268
|
};
|
|
38371
|
-
|
|
38372
|
-
|
|
38373
|
-
|
|
38374
|
-
|
|
38375
|
-
|
|
38376
|
-
|
|
38377
|
-
|
|
38378
|
-
|
|
38379
|
-
|
|
38269
|
+
var shift = {
|
|
38270
|
+
48: ")",
|
|
38271
|
+
49: "!",
|
|
38272
|
+
50: "@",
|
|
38273
|
+
51: "#",
|
|
38274
|
+
52: "$",
|
|
38275
|
+
53: "%",
|
|
38276
|
+
54: "^",
|
|
38277
|
+
55: "&",
|
|
38278
|
+
56: "*",
|
|
38279
|
+
57: "(",
|
|
38280
|
+
59: ":",
|
|
38281
|
+
61: "+",
|
|
38282
|
+
173: "_",
|
|
38283
|
+
186: ":",
|
|
38284
|
+
187: "+",
|
|
38285
|
+
188: "<",
|
|
38286
|
+
189: "_",
|
|
38287
|
+
190: ">",
|
|
38288
|
+
191: "?",
|
|
38289
|
+
192: "~",
|
|
38290
|
+
219: "{",
|
|
38291
|
+
220: "|",
|
|
38292
|
+
221: "}",
|
|
38293
|
+
222: '"'
|
|
38380
38294
|
};
|
|
38381
|
-
|
|
38382
|
-
|
|
38295
|
+
var mac$1 = typeof navigator != "undefined" && /Mac/.test(navigator.platform);
|
|
38296
|
+
var ie = typeof navigator != "undefined" && /MSIE \d|Trident\/(?:[7-9]|\d{2,})\..*rv:(\d+)/.exec(navigator.userAgent);
|
|
38297
|
+
for (var i = 0; i < 10; i++) base$1[48 + i] = base$1[96 + i] = String(i);
|
|
38298
|
+
for (var i = 1; i <= 24; i++) base$1[i + 111] = "F" + i;
|
|
38299
|
+
for (var i = 65; i <= 90; i++) {
|
|
38300
|
+
base$1[i] = String.fromCharCode(i + 32);
|
|
38301
|
+
shift[i] = String.fromCharCode(i);
|
|
38302
|
+
}
|
|
38303
|
+
for (var code in base$1) if (!shift.hasOwnProperty(code)) shift[code] = base$1[code];
|
|
38304
|
+
function keyName(event) {
|
|
38305
|
+
var ignoreKey = mac$1 && event.metaKey && event.shiftKey && !event.ctrlKey && !event.altKey || ie && event.shiftKey && event.key && event.key.length == 1 || event.key == "Unidentified";
|
|
38306
|
+
var name = !ignoreKey && event.key || (event.shiftKey ? shift : base$1)[event.keyCode] || event.key || "Unidentified";
|
|
38307
|
+
if (name == "Esc") name = "Escape";
|
|
38308
|
+
if (name == "Del") name = "Delete";
|
|
38309
|
+
if (name == "Left") name = "ArrowLeft";
|
|
38310
|
+
if (name == "Up") name = "ArrowUp";
|
|
38311
|
+
if (name == "Right") name = "ArrowRight";
|
|
38312
|
+
if (name == "Down") name = "ArrowDown";
|
|
38313
|
+
return name;
|
|
38314
|
+
}
|
|
38315
|
+
const mac = typeof navigator != "undefined" && /Mac|iP(hone|[oa]d)/.test(navigator.platform);
|
|
38316
|
+
const windows = typeof navigator != "undefined" && /Win/.test(navigator.platform);
|
|
38317
|
+
function normalizeKeyName(name) {
|
|
38318
|
+
let parts = name.split(/-(?!$)/), result = parts[parts.length - 1];
|
|
38319
|
+
if (result == "Space")
|
|
38320
|
+
result = " ";
|
|
38321
|
+
let alt, ctrl, shift2, meta;
|
|
38322
|
+
for (let i = 0; i < parts.length - 1; i++) {
|
|
38323
|
+
let mod = parts[i];
|
|
38324
|
+
if (/^(cmd|meta|m)$/i.test(mod))
|
|
38325
|
+
meta = true;
|
|
38326
|
+
else if (/^a(lt)?$/i.test(mod))
|
|
38327
|
+
alt = true;
|
|
38328
|
+
else if (/^(c|ctrl|control)$/i.test(mod))
|
|
38329
|
+
ctrl = true;
|
|
38330
|
+
else if (/^s(hift)?$/i.test(mod))
|
|
38331
|
+
shift2 = true;
|
|
38332
|
+
else if (/^mod$/i.test(mod)) {
|
|
38333
|
+
if (mac)
|
|
38334
|
+
meta = true;
|
|
38335
|
+
else
|
|
38336
|
+
ctrl = true;
|
|
38337
|
+
} else
|
|
38338
|
+
throw new Error("Unrecognized modifier name: " + mod);
|
|
38339
|
+
}
|
|
38340
|
+
if (alt)
|
|
38341
|
+
result = "Alt-" + result;
|
|
38342
|
+
if (ctrl)
|
|
38343
|
+
result = "Ctrl-" + result;
|
|
38344
|
+
if (meta)
|
|
38345
|
+
result = "Meta-" + result;
|
|
38346
|
+
if (shift2)
|
|
38347
|
+
result = "Shift-" + result;
|
|
38348
|
+
return result;
|
|
38349
|
+
}
|
|
38350
|
+
function normalize(map22) {
|
|
38351
|
+
let copy2 = /* @__PURE__ */ Object.create(null);
|
|
38352
|
+
for (let prop in map22)
|
|
38353
|
+
copy2[normalizeKeyName(prop)] = map22[prop];
|
|
38354
|
+
return copy2;
|
|
38355
|
+
}
|
|
38356
|
+
function modifiers(name, event, shift2 = true) {
|
|
38357
|
+
if (event.altKey)
|
|
38358
|
+
name = "Alt-" + name;
|
|
38359
|
+
if (event.ctrlKey)
|
|
38360
|
+
name = "Ctrl-" + name;
|
|
38361
|
+
if (event.metaKey)
|
|
38362
|
+
name = "Meta-" + name;
|
|
38363
|
+
if (shift2 && event.shiftKey)
|
|
38364
|
+
name = "Shift-" + name;
|
|
38365
|
+
return name;
|
|
38366
|
+
}
|
|
38367
|
+
function keymap(bindings) {
|
|
38368
|
+
return new Plugin({ props: { handleKeyDown: keydownHandler(bindings) } });
|
|
38369
|
+
}
|
|
38370
|
+
function keydownHandler(bindings) {
|
|
38371
|
+
let map22 = normalize(bindings);
|
|
38372
|
+
return function(view, event) {
|
|
38373
|
+
let name = keyName(event), baseName, direct = map22[modifiers(name, event)];
|
|
38374
|
+
if (direct && direct(view.state, view.dispatch, view))
|
|
38375
|
+
return true;
|
|
38376
|
+
if (name.length == 1 && name != " ") {
|
|
38377
|
+
if (event.shiftKey) {
|
|
38378
|
+
let noShift = map22[modifiers(name, event, false)];
|
|
38379
|
+
if (noShift && noShift(view.state, view.dispatch, view))
|
|
38380
|
+
return true;
|
|
38381
|
+
}
|
|
38382
|
+
if ((event.altKey || event.metaKey || event.ctrlKey) && // Ctrl-Alt may be used for AltGr on Windows
|
|
38383
|
+
!(windows && event.ctrlKey && event.altKey) && (baseName = base$1[event.keyCode]) && baseName != name) {
|
|
38384
|
+
let fromCode = map22[modifiers(baseName, event)];
|
|
38385
|
+
if (fromCode && fromCode(view.state, view.dispatch, view))
|
|
38386
|
+
return true;
|
|
38387
|
+
}
|
|
38388
|
+
}
|
|
38389
|
+
return false;
|
|
38390
|
+
};
|
|
38391
|
+
}
|
|
38392
|
+
function isExtensionRulesEnabled(extension, enabled) {
|
|
38393
|
+
if (Array.isArray(enabled)) {
|
|
38394
|
+
return enabled.some((enabledExtension) => {
|
|
38395
|
+
const name = typeof enabledExtension === "string" ? enabledExtension : enabledExtension.name;
|
|
38396
|
+
return name === extension.name;
|
|
38397
|
+
});
|
|
38398
|
+
}
|
|
38399
|
+
return enabled;
|
|
38383
38400
|
}
|
|
38384
38401
|
const _ExtensionService = class _ExtensionService2 {
|
|
38385
38402
|
constructor(extensions, userExtensions, editor) {
|
|
@@ -39209,6 +39226,8 @@ const createHeaderFooterEditor = ({
|
|
|
39209
39226
|
});
|
|
39210
39227
|
if (appendToBody) document.body.appendChild(editorContainer);
|
|
39211
39228
|
const headerFooterEditor = new Editor({
|
|
39229
|
+
documentMode: editor.options.documentMode,
|
|
39230
|
+
role: editor.options.role,
|
|
39212
39231
|
loadFromSchema: true,
|
|
39213
39232
|
mode: "docx",
|
|
39214
39233
|
element: editorContainer,
|
|
@@ -39219,6 +39238,7 @@ const createHeaderFooterEditor = ({
|
|
|
39219
39238
|
mediaFiles: editor.storage.image.media,
|
|
39220
39239
|
fonts: editor.options.fonts,
|
|
39221
39240
|
isHeaderOrFooter: true,
|
|
39241
|
+
isHeadless: editor.options.isHeadless,
|
|
39222
39242
|
annotations: true,
|
|
39223
39243
|
currentPageNumber,
|
|
39224
39244
|
parentEditor: editor,
|
|
@@ -39226,13 +39246,15 @@ const createHeaderFooterEditor = ({
|
|
|
39226
39246
|
onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, sectionId, type2)
|
|
39227
39247
|
});
|
|
39228
39248
|
const pm = editorContainer.querySelector(".ProseMirror");
|
|
39229
|
-
pm
|
|
39230
|
-
|
|
39231
|
-
|
|
39232
|
-
|
|
39233
|
-
|
|
39234
|
-
|
|
39235
|
-
|
|
39249
|
+
if (pm) {
|
|
39250
|
+
pm.style.maxHeight = "100%";
|
|
39251
|
+
pm.style.minHeight = "100%";
|
|
39252
|
+
pm.style.outline = "none";
|
|
39253
|
+
pm.style.border = "none";
|
|
39254
|
+
pm.setAttribute("role", "textbox");
|
|
39255
|
+
pm.setAttribute("aria-multiline", true);
|
|
39256
|
+
pm.setAttribute("aria-label", `${type2} content area. Double click to start typing.`);
|
|
39257
|
+
}
|
|
39236
39258
|
return headerFooterEditor;
|
|
39237
39259
|
};
|
|
39238
39260
|
const broadcastEditorEvents = (editor, sectionEditor) => {
|
|
@@ -39251,14 +39273,16 @@ const broadcastEditorEvents = (editor, sectionEditor) => {
|
|
|
39251
39273
|
});
|
|
39252
39274
|
});
|
|
39253
39275
|
};
|
|
39254
|
-
const toggleHeaderFooterEditMode = (editor, focusedSectionEditor, isEditMode) => {
|
|
39276
|
+
const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode, documentMode }) => {
|
|
39255
39277
|
editor.converter.headerEditors.forEach((item) => {
|
|
39256
39278
|
item.editor.setEditable(isEditMode, false);
|
|
39257
39279
|
item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
|
|
39280
|
+
item.editor.view.dom.setAttribute("documentmode", documentMode);
|
|
39258
39281
|
});
|
|
39259
39282
|
editor.converter.footerEditors.forEach((item) => {
|
|
39260
39283
|
item.editor.setEditable(isEditMode, false);
|
|
39261
39284
|
item.editor.view.dom.setAttribute("aria-readonly", !isEditMode);
|
|
39285
|
+
item.editor.view.dom.setAttribute("documentmode", documentMode);
|
|
39262
39286
|
});
|
|
39263
39287
|
if (isEditMode) {
|
|
39264
39288
|
const pm = document.querySelector(".ProseMirror");
|
|
@@ -40339,6 +40363,19 @@ const deleteHeaderFooterFieldAnnotations = ({ editor, fieldIdOrArray }) => {
|
|
|
40339
40363
|
);
|
|
40340
40364
|
});
|
|
40341
40365
|
};
|
|
40366
|
+
const resetHeaderFooterFieldAnnotations = ({ editor }) => {
|
|
40367
|
+
if (!editor) return;
|
|
40368
|
+
const sectionEditors = getAllHeaderFooterEditors(editor);
|
|
40369
|
+
sectionEditors.forEach(({ editor: sectionEditor, sectionId, type: type2 }) => {
|
|
40370
|
+
sectionEditor.commands.resetFieldAnnotations();
|
|
40371
|
+
onHeaderFooterDataUpdate(
|
|
40372
|
+
{ editor: sectionEditor },
|
|
40373
|
+
editor,
|
|
40374
|
+
sectionId,
|
|
40375
|
+
type2
|
|
40376
|
+
);
|
|
40377
|
+
});
|
|
40378
|
+
};
|
|
40342
40379
|
const cleanUpListsWithAnnotations = (fieldsToDelete = [], editor) => {
|
|
40343
40380
|
if (!Array.isArray(fieldsToDelete)) fieldsToDelete = [fieldsToDelete];
|
|
40344
40381
|
const { doc: doc2 } = editor.state;
|
|
@@ -40409,6 +40446,7 @@ const AnnotatorHelpers = {
|
|
|
40409
40446
|
getAllHeaderFooterEditors,
|
|
40410
40447
|
updateHeaderFooterFieldAnnotations,
|
|
40411
40448
|
deleteHeaderFooterFieldAnnotations,
|
|
40449
|
+
resetHeaderFooterFieldAnnotations,
|
|
40412
40450
|
cleanUpListsWithAnnotations
|
|
40413
40451
|
};
|
|
40414
40452
|
const CollaborationPluginKey = new PluginKey("collaboration");
|
|
@@ -40588,6 +40626,16 @@ const setWordSelection = (view, pos) => {
|
|
|
40588
40626
|
const tr = state2.tr.setSelection(TextSelection.create(state2.doc, word.from, word.to));
|
|
40589
40627
|
dispatch(tr);
|
|
40590
40628
|
};
|
|
40629
|
+
const setImageNodeSelection = (view, pos) => {
|
|
40630
|
+
const { doc: doc2 } = view.state;
|
|
40631
|
+
const node2 = doc2.nodeAt(pos);
|
|
40632
|
+
if (node2 && node2.type.name === "image") {
|
|
40633
|
+
const tr = view.state.tr.setSelection(NodeSelection.create(doc2, pos));
|
|
40634
|
+
view.dispatch(tr);
|
|
40635
|
+
return true;
|
|
40636
|
+
}
|
|
40637
|
+
return false;
|
|
40638
|
+
};
|
|
40591
40639
|
const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
40592
40640
|
/**
|
|
40593
40641
|
* Create a new Editor instance
|
|
@@ -40686,6 +40734,19 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40686
40734
|
this.setHighContrastMode = setHighContrastMode;
|
|
40687
40735
|
initMode();
|
|
40688
40736
|
}
|
|
40737
|
+
mount(el) {
|
|
40738
|
+
__privateMethod$1(this, _Editor_instances, createView_fn).call(this, el);
|
|
40739
|
+
window.setTimeout(() => {
|
|
40740
|
+
if (this.isDestroyed) return;
|
|
40741
|
+
this.emit("create", { editor: this });
|
|
40742
|
+
}, 0);
|
|
40743
|
+
}
|
|
40744
|
+
unmount() {
|
|
40745
|
+
if (this.view) {
|
|
40746
|
+
this.view.destroy();
|
|
40747
|
+
}
|
|
40748
|
+
this.view = null;
|
|
40749
|
+
}
|
|
40689
40750
|
/**
|
|
40690
40751
|
* Set the toolbar for this editor
|
|
40691
40752
|
* @param {Object} toolbar - The toolbar instance
|
|
@@ -40734,7 +40795,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40734
40795
|
* @returns {boolean}
|
|
40735
40796
|
*/
|
|
40736
40797
|
get isDestroyed() {
|
|
40737
|
-
return this.view
|
|
40798
|
+
return this.view?.isDestroyed ?? true;
|
|
40738
40799
|
}
|
|
40739
40800
|
/**
|
|
40740
40801
|
* Get the editor element
|
|
@@ -40777,7 +40838,12 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40777
40838
|
this.commands.toggleTrackChangesShowOriginal();
|
|
40778
40839
|
this.setEditable(false, false);
|
|
40779
40840
|
this.setOptions({ documentMode: "viewing" });
|
|
40780
|
-
toggleHeaderFooterEditMode(
|
|
40841
|
+
toggleHeaderFooterEditMode({
|
|
40842
|
+
editor: this,
|
|
40843
|
+
focusedSectionEditor: null,
|
|
40844
|
+
isEditMode: false,
|
|
40845
|
+
documentMode: cleanedMode
|
|
40846
|
+
});
|
|
40781
40847
|
} else if (cleanedMode === "suggesting") {
|
|
40782
40848
|
__privateMethod$1(this, _Editor_instances, registerPluginByNameIfNotExists_fn).call(this, "TrackChangesBase");
|
|
40783
40849
|
this.commands.disableTrackChangesShowOriginal();
|
|
@@ -40790,7 +40856,12 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40790
40856
|
this.commands.disableTrackChanges();
|
|
40791
40857
|
this.setEditable(true, false);
|
|
40792
40858
|
this.setOptions({ documentMode: "editing" });
|
|
40793
|
-
toggleHeaderFooterEditMode(
|
|
40859
|
+
toggleHeaderFooterEditMode({
|
|
40860
|
+
editor: this,
|
|
40861
|
+
focusedSectionEditor: null,
|
|
40862
|
+
isEditMode: false,
|
|
40863
|
+
documentMode: cleanedMode
|
|
40864
|
+
});
|
|
40794
40865
|
}
|
|
40795
40866
|
}
|
|
40796
40867
|
/**
|
|
@@ -40888,10 +40959,10 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40888
40959
|
}
|
|
40889
40960
|
/**
|
|
40890
40961
|
* Unregister a PM plugin
|
|
40891
|
-
* @param {string|Object}
|
|
40962
|
+
* @param {string|Object} nameOrPluginKey - Plugin name or plugin instance
|
|
40892
40963
|
* @returns {void}
|
|
40893
40964
|
*/
|
|
40894
|
-
unregisterPlugin(
|
|
40965
|
+
unregisterPlugin(nameOrPluginKey) {
|
|
40895
40966
|
if (this.isDestroyed) return;
|
|
40896
40967
|
const name = typeof nameOrPluginKey === "string" ? `${nameOrPluginKey}$` : nameOrPluginKey.key;
|
|
40897
40968
|
const state2 = this.state.reconfigure({
|
|
@@ -40967,29 +41038,26 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
40967
41038
|
};
|
|
40968
41039
|
}
|
|
40969
41040
|
/**
|
|
40970
|
-
|
|
40971
|
-
|
|
40972
|
-
|
|
40973
|
-
*
|
|
40974
|
-
* @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
|
|
40975
|
-
* @returns {void}
|
|
40976
|
-
*/
|
|
40977
|
-
initDefaultStyles(element = this.element) {
|
|
40978
|
-
if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
|
|
40979
|
-
const proseMirror = element?.querySelector(".ProseMirror");
|
|
41041
|
+
* Attach styles and attributes to the editor element
|
|
41042
|
+
*/
|
|
41043
|
+
updateEditorStyles(element, proseMirror, hasPaginationEnabled = true) {
|
|
40980
41044
|
const { pageSize, pageMargins } = this.converter.pageStyles ?? {};
|
|
40981
|
-
if (!proseMirror || !
|
|
41045
|
+
if (!proseMirror || !element) {
|
|
40982
41046
|
return;
|
|
40983
41047
|
}
|
|
40984
41048
|
proseMirror.setAttribute("role", "document");
|
|
40985
41049
|
proseMirror.setAttribute("aria-multiline", true);
|
|
40986
41050
|
proseMirror.setAttribute("aria-label", "Main content area, start typing to enter text.");
|
|
40987
41051
|
proseMirror.setAttribute("aria-description", "");
|
|
40988
|
-
|
|
40989
|
-
|
|
40990
|
-
|
|
40991
|
-
|
|
40992
|
-
|
|
41052
|
+
if (pageSize) {
|
|
41053
|
+
element.style.width = pageSize.width + "in";
|
|
41054
|
+
element.style.minWidth = pageSize.width + "in";
|
|
41055
|
+
element.style.minHeight = pageSize.height + "in";
|
|
41056
|
+
}
|
|
41057
|
+
if (pageMargins) {
|
|
41058
|
+
element.style.paddingLeft = pageMargins.left + "in";
|
|
41059
|
+
element.style.paddingRight = pageMargins.right + "in";
|
|
41060
|
+
}
|
|
40993
41061
|
element.style.boxSizing = "border-box";
|
|
40994
41062
|
element.style.isolation = "isolate";
|
|
40995
41063
|
proseMirror.style.outline = "none";
|
|
@@ -41006,10 +41074,26 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
41006
41074
|
element.style.webkitOverflowScrolling = "touch";
|
|
41007
41075
|
const defaultLineHeight = 1.2;
|
|
41008
41076
|
proseMirror.style.lineHeight = defaultLineHeight;
|
|
41009
|
-
if (!
|
|
41077
|
+
if (!hasPaginationEnabled) {
|
|
41010
41078
|
proseMirror.style.paddingTop = "1in";
|
|
41011
41079
|
proseMirror.style.paddingBottom = "1in";
|
|
41080
|
+
} else {
|
|
41081
|
+
proseMirror.style.paddingTop = "0";
|
|
41082
|
+
proseMirror.style.paddingBottom = "0";
|
|
41012
41083
|
}
|
|
41084
|
+
}
|
|
41085
|
+
/**
|
|
41086
|
+
* Initialize default styles for the editor container and ProseMirror.
|
|
41087
|
+
* Get page size and margins from the converter.
|
|
41088
|
+
* Set document default font and font size.
|
|
41089
|
+
*
|
|
41090
|
+
* @param {HTMLElement} [element=this.element] - The DOM element to apply styles to
|
|
41091
|
+
* @returns {void}
|
|
41092
|
+
*/
|
|
41093
|
+
initDefaultStyles(element = this.element, isPaginationEnabled = true) {
|
|
41094
|
+
if (this.options.isHeadless || this.options.suppressDefaultDocxStyles) return;
|
|
41095
|
+
const proseMirror = element?.querySelector(".ProseMirror");
|
|
41096
|
+
this.updateEditorStyles(element, proseMirror, isPaginationEnabled);
|
|
41013
41097
|
this.initMobileStyles(element);
|
|
41014
41098
|
}
|
|
41015
41099
|
/**
|
|
@@ -41057,6 +41141,26 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
41057
41141
|
}
|
|
41058
41142
|
window.addEventListener("resize", () => handleResize);
|
|
41059
41143
|
}
|
|
41144
|
+
/**
|
|
41145
|
+
* Initialize pagination, if the pagination extension is enabled.
|
|
41146
|
+
* @private
|
|
41147
|
+
* @async
|
|
41148
|
+
* @returns {Promise<void>}
|
|
41149
|
+
*/
|
|
41150
|
+
async initPagination() {
|
|
41151
|
+
if (this.options.isHeadless || !this.extensionService || this.options.isHeaderOrFooter) {
|
|
41152
|
+
return;
|
|
41153
|
+
}
|
|
41154
|
+
const pagination = this.options.extensions.find((e) => e.name === "pagination");
|
|
41155
|
+
if (pagination && this.options.pagination) {
|
|
41156
|
+
console.debug("🔗 [super-editor] Initializing pagination");
|
|
41157
|
+
const sectionData = await initPaginationData(this);
|
|
41158
|
+
this.storage.pagination.sectionData = sectionData;
|
|
41159
|
+
const { state: state2, dispatch } = this.view;
|
|
41160
|
+
const tr = state2.tr.setMeta(PaginationPluginKey, { isReadyToInit: true });
|
|
41161
|
+
dispatch(tr);
|
|
41162
|
+
}
|
|
41163
|
+
}
|
|
41060
41164
|
/**
|
|
41061
41165
|
* Get attrs of the currently selected node or mark.
|
|
41062
41166
|
* @param {String} nameOrType
|
|
@@ -41221,10 +41325,25 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
41221
41325
|
*/
|
|
41222
41326
|
destroy() {
|
|
41223
41327
|
this.emit("destroy");
|
|
41224
|
-
|
|
41328
|
+
this.unmount();
|
|
41329
|
+
this.destroyHeaderFooterEditors();
|
|
41225
41330
|
__privateMethod$1(this, _Editor_instances, endCollaboration_fn).call(this);
|
|
41226
41331
|
this.removeAllListeners();
|
|
41227
41332
|
}
|
|
41333
|
+
destroyHeaderFooterEditors() {
|
|
41334
|
+
try {
|
|
41335
|
+
const editors = [
|
|
41336
|
+
...this.converter.headerEditors,
|
|
41337
|
+
...this.converter.footerEditors
|
|
41338
|
+
];
|
|
41339
|
+
for (let editorData of editors) {
|
|
41340
|
+
editorData.editor.destroy();
|
|
41341
|
+
}
|
|
41342
|
+
this.converter.headerEditors.length = 0;
|
|
41343
|
+
this.converter.footerEditors.length = 0;
|
|
41344
|
+
} catch (error) {
|
|
41345
|
+
}
|
|
41346
|
+
}
|
|
41228
41347
|
/**
|
|
41229
41348
|
* Check if migrations are needed for the data
|
|
41230
41349
|
* @static
|
|
@@ -41242,7 +41361,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
41242
41361
|
* @returns {Object | void} Migration results
|
|
41243
41362
|
*/
|
|
41244
41363
|
processCollaborationMigrations() {
|
|
41245
|
-
console.debug("[checkVersionMigrations] Current editor version", "0.13.2-
|
|
41364
|
+
console.debug("[checkVersionMigrations] Current editor version", "0.13.2-rev11");
|
|
41246
41365
|
if (!this.options.ydoc) return;
|
|
41247
41366
|
const metaMap = this.options.ydoc.getMap("meta");
|
|
41248
41367
|
let docVersion = metaMap.get("version");
|
|
@@ -41292,7 +41411,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
|
|
|
41292
41411
|
__privateMethod$1(this, _Editor_instances, insertNewFileData_fn).call(this);
|
|
41293
41412
|
}
|
|
41294
41413
|
if (!this.options.ydoc) {
|
|
41295
|
-
|
|
41414
|
+
this.initPagination();
|
|
41296
41415
|
__privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
|
|
41297
41416
|
}
|
|
41298
41417
|
}
|
|
@@ -41438,9 +41557,7 @@ init_fn = function(options2) {
|
|
|
41438
41557
|
this.emit("beforeCreate", { editor: this });
|
|
41439
41558
|
this.on("contentError", this.options.onContentError);
|
|
41440
41559
|
this.on("exception", this.options.onException);
|
|
41441
|
-
|
|
41442
|
-
this.initDefaultStyles();
|
|
41443
|
-
this.setDocumentMode(options2.documentMode);
|
|
41560
|
+
this.mount(this.options.element);
|
|
41444
41561
|
if (this.options.isHeadless) return;
|
|
41445
41562
|
this.on("create", this.options.onCreate);
|
|
41446
41563
|
this.on("update", this.options.onUpdate);
|
|
@@ -41458,14 +41575,12 @@ init_fn = function(options2) {
|
|
|
41458
41575
|
this.on("paginationUpdate", this.options.onPaginationUpdate);
|
|
41459
41576
|
this.on("comment-positions", this.options.onCommentLocationsUpdate);
|
|
41460
41577
|
this.initializeCollaborationData();
|
|
41578
|
+
this.initDefaultStyles();
|
|
41579
|
+
this.setDocumentMode(this.options.documentMode);
|
|
41461
41580
|
if (!this.options.ydoc) {
|
|
41462
|
-
|
|
41581
|
+
this.initPagination();
|
|
41463
41582
|
__privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
|
|
41464
41583
|
}
|
|
41465
|
-
window.setTimeout(() => {
|
|
41466
|
-
if (this.isDestroyed) return;
|
|
41467
|
-
this.emit("create", { editor: this });
|
|
41468
|
-
}, 0);
|
|
41469
41584
|
};
|
|
41470
41585
|
initRichText_fn = function(options2) {
|
|
41471
41586
|
if (!options2.extensions || !options2.extensions.length) {
|
|
@@ -41477,7 +41592,7 @@ initRichText_fn = function(options2) {
|
|
|
41477
41592
|
this.on("beforeCreate", this.options.onBeforeCreate);
|
|
41478
41593
|
this.emit("beforeCreate", { editor: this });
|
|
41479
41594
|
this.on("contentError", this.options.onContentError);
|
|
41480
|
-
|
|
41595
|
+
this.mount(this.options.element);
|
|
41481
41596
|
this.on("create", this.options.onCreate);
|
|
41482
41597
|
this.on("update", this.options.onUpdate);
|
|
41483
41598
|
this.on("selectionUpdate", this.options.onSelectionUpdate);
|
|
@@ -41488,10 +41603,6 @@ initRichText_fn = function(options2) {
|
|
|
41488
41603
|
this.on("commentsLoaded", this.options.onCommentsLoaded);
|
|
41489
41604
|
this.on("commentClick", this.options.onCommentClicked);
|
|
41490
41605
|
this.on("locked", this.options.onDocumentLocked);
|
|
41491
|
-
window.setTimeout(() => {
|
|
41492
|
-
if (this.isDestroyed) return;
|
|
41493
|
-
this.emit("create", { editor: this });
|
|
41494
|
-
}, 0);
|
|
41495
41606
|
};
|
|
41496
41607
|
onFocus_fn = function({ editor, event }) {
|
|
41497
41608
|
this.toolbar?.setActiveEditor(editor);
|
|
@@ -41514,7 +41625,7 @@ insertNewFileData_fn = function() {
|
|
|
41514
41625
|
const tr = this.state.tr.replaceWith(0, this.state.doc.content.size, doc2);
|
|
41515
41626
|
this.view.dispatch(tr);
|
|
41516
41627
|
setTimeout(() => {
|
|
41517
|
-
|
|
41628
|
+
this.initPagination();
|
|
41518
41629
|
__privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
|
|
41519
41630
|
}, 50);
|
|
41520
41631
|
};
|
|
@@ -41612,14 +41723,15 @@ createDocFromHTML_fn = function(content) {
|
|
|
41612
41723
|
}
|
|
41613
41724
|
return DOMParser$1.fromSchema(this.schema).parse(parsedContent);
|
|
41614
41725
|
};
|
|
41615
|
-
createView_fn = function() {
|
|
41726
|
+
createView_fn = function(element) {
|
|
41616
41727
|
let doc2 = __privateMethod$1(this, _Editor_instances, generatePmData_fn).call(this);
|
|
41617
41728
|
const state2 = { schema: this.schema };
|
|
41618
41729
|
if (!this.options.ydoc) state2.doc = doc2;
|
|
41619
|
-
this.view = new EditorView(
|
|
41730
|
+
this.view = new EditorView(element, {
|
|
41620
41731
|
...this.options.editorProps,
|
|
41621
41732
|
dispatchTransaction: __privateMethod$1(this, _Editor_instances, dispatchTransaction_fn).bind(this),
|
|
41622
41733
|
state: EditorState.create(state2),
|
|
41734
|
+
handleClick: __privateMethod$1(this, _Editor_instances, handleNodeSelection_fn).bind(this),
|
|
41623
41735
|
handleDoubleClick: async (view, pos, event) => {
|
|
41624
41736
|
if (this.options.documentMode !== "editing") return;
|
|
41625
41737
|
const isHeader = hasSomeParentWithClass(event.target, "pagination-section-header");
|
|
@@ -41633,7 +41745,12 @@ createView_fn = function() {
|
|
|
41633
41745
|
event.stopPropagation();
|
|
41634
41746
|
if (!this.options.editable) {
|
|
41635
41747
|
this.setEditable(true, false);
|
|
41636
|
-
toggleHeaderFooterEditMode(
|
|
41748
|
+
toggleHeaderFooterEditMode({
|
|
41749
|
+
editor: this,
|
|
41750
|
+
focusedSectionEditor: null,
|
|
41751
|
+
isEditMode: false,
|
|
41752
|
+
documentMode: this.options.documentMode
|
|
41753
|
+
});
|
|
41637
41754
|
const pm = document.querySelector(".ProseMirror");
|
|
41638
41755
|
pm.classList.remove("header-footer-edit");
|
|
41639
41756
|
pm.setAttribute("aria-readonly", false);
|
|
@@ -41646,8 +41763,6 @@ createView_fn = function() {
|
|
|
41646
41763
|
});
|
|
41647
41764
|
this.view.updateState(newState);
|
|
41648
41765
|
this.createNodeViews();
|
|
41649
|
-
const dom = this.view.dom;
|
|
41650
|
-
dom.editor = this;
|
|
41651
41766
|
this.options.telemetry?.sendReport();
|
|
41652
41767
|
};
|
|
41653
41768
|
onCollaborationReady_fn = function({ editor, ydoc }) {
|
|
@@ -41656,7 +41771,7 @@ onCollaborationReady_fn = function({ editor, ydoc }) {
|
|
|
41656
41771
|
this.options.onCollaborationReady({ editor, ydoc });
|
|
41657
41772
|
this.options.collaborationIsReady = true;
|
|
41658
41773
|
if (!this.options.isNewFile) {
|
|
41659
|
-
|
|
41774
|
+
this.initPagination();
|
|
41660
41775
|
__privateMethod$1(this, _Editor_instances, initComments_fn).call(this);
|
|
41661
41776
|
}
|
|
41662
41777
|
};
|
|
@@ -41673,20 +41788,8 @@ initComments_fn = function() {
|
|
|
41673
41788
|
dispatch(tr);
|
|
41674
41789
|
}, 50);
|
|
41675
41790
|
};
|
|
41676
|
-
initPagination_fn = async function() {
|
|
41677
|
-
if (this.options.isHeadless || !this.extensionService) return;
|
|
41678
|
-
const pagination = this.options.extensions.find((e) => e.name === "pagination");
|
|
41679
|
-
if (pagination && this.options.pagination) {
|
|
41680
|
-
console.debug("🔗 [super-editor] Initializing pagination");
|
|
41681
|
-
const sectionData = await initPaginationData(this);
|
|
41682
|
-
this.storage.pagination.sectionData = sectionData;
|
|
41683
|
-
const { state: state2, dispatch } = this.view;
|
|
41684
|
-
const tr = state2.tr.setMeta(PaginationPluginKey, { isReadyToInit: true });
|
|
41685
|
-
dispatch(tr);
|
|
41686
|
-
}
|
|
41687
|
-
};
|
|
41688
41791
|
dispatchTransaction_fn = function(transaction) {
|
|
41689
|
-
if (this.
|
|
41792
|
+
if (this.isDestroyed) return;
|
|
41690
41793
|
let state2;
|
|
41691
41794
|
try {
|
|
41692
41795
|
const trackChangesState = TrackChangesBasePluginKey.getState(this.view.state);
|
|
@@ -41738,6 +41841,11 @@ dispatchTransaction_fn = function(transaction) {
|
|
|
41738
41841
|
transaction
|
|
41739
41842
|
});
|
|
41740
41843
|
};
|
|
41844
|
+
handleNodeSelection_fn = function(view, pos) {
|
|
41845
|
+
if (this.options.isHeaderOrFooter) {
|
|
41846
|
+
return setImageNodeSelection(view, pos);
|
|
41847
|
+
}
|
|
41848
|
+
};
|
|
41741
41849
|
prepareDocumentForImport_fn = function(doc2) {
|
|
41742
41850
|
const newState = EditorState.create({
|
|
41743
41851
|
schema: this.schema,
|
|
@@ -44080,7 +44188,7 @@ const Paragraph = Node$1.create({
|
|
|
44080
44188
|
},
|
|
44081
44189
|
addPmPlugins() {
|
|
44082
44190
|
const { view } = this.editor;
|
|
44083
|
-
|
|
44191
|
+
new Plugin({
|
|
44084
44192
|
name: "dropcapPlugin",
|
|
44085
44193
|
key: new PluginKey("dropcapPlugin"),
|
|
44086
44194
|
state: {
|
|
@@ -44100,7 +44208,7 @@ const Paragraph = Node$1.create({
|
|
|
44100
44208
|
}
|
|
44101
44209
|
}
|
|
44102
44210
|
});
|
|
44103
|
-
return [
|
|
44211
|
+
return [];
|
|
44104
44212
|
}
|
|
44105
44213
|
});
|
|
44106
44214
|
const getDropcapDecorations = (state2, view) => {
|
|
@@ -44453,7 +44561,16 @@ const HardBreak = Node$1.create({
|
|
|
44453
44561
|
};
|
|
44454
44562
|
},
|
|
44455
44563
|
parseDOM() {
|
|
44456
|
-
return [{
|
|
44564
|
+
return [{
|
|
44565
|
+
tag: 'span[linebreaktype="page"]',
|
|
44566
|
+
getAttrs: (dom) => {
|
|
44567
|
+
if (!(dom instanceof HTMLElement)) return false;
|
|
44568
|
+
return {
|
|
44569
|
+
pageBreakSource: dom.getAttribute("pagebreaksource") || null,
|
|
44570
|
+
pageBreakType: dom.getAttribute("linebreaktype") || null
|
|
44571
|
+
};
|
|
44572
|
+
}
|
|
44573
|
+
}];
|
|
44457
44574
|
},
|
|
44458
44575
|
renderDOM({ htmlAttributes }) {
|
|
44459
44576
|
return ["span", Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes)];
|
|
@@ -47450,6 +47567,8 @@ function findRemovedFieldAnnotations(tr) {
|
|
|
47450
47567
|
if (!tr.steps.length || tr.meta && !Object.keys(tr.meta).every((meta) => ["inputType", "uiEvent", "paste"].includes(meta)) || ["historyUndo", "historyRedo"].includes(tr.getMeta("inputType")) || ["drop"].includes(tr.getMeta("uiEvent")) || tr.getMeta("fieldAnnotationUpdate") === true) {
|
|
47451
47568
|
return removedNodes;
|
|
47452
47569
|
}
|
|
47570
|
+
const hasDeletion = transactionDeletedAnything(tr);
|
|
47571
|
+
if (!hasDeletion) return removedNodes;
|
|
47453
47572
|
tr.steps.forEach((step, stepIndex) => {
|
|
47454
47573
|
if (step instanceof ReplaceStep && step.from !== step.to) {
|
|
47455
47574
|
let mapping = tr.mapping.maps[stepIndex];
|
|
@@ -47466,6 +47585,14 @@ function findRemovedFieldAnnotations(tr) {
|
|
|
47466
47585
|
});
|
|
47467
47586
|
return removedNodes;
|
|
47468
47587
|
}
|
|
47588
|
+
function transactionDeletedAnything(tr) {
|
|
47589
|
+
return tr.steps.some((step) => {
|
|
47590
|
+
if (step instanceof ReplaceStep || step instanceof ReplaceAroundStep) {
|
|
47591
|
+
return step.from !== step.to;
|
|
47592
|
+
}
|
|
47593
|
+
return false;
|
|
47594
|
+
});
|
|
47595
|
+
}
|
|
47469
47596
|
function trackFieldAnnotationsDeletion(editor, tr) {
|
|
47470
47597
|
let removedAnnotations = [];
|
|
47471
47598
|
try {
|
|
@@ -47861,8 +47988,18 @@ const FieldAnnotation = Node$1.create({
|
|
|
47861
47988
|
};
|
|
47862
47989
|
}
|
|
47863
47990
|
},
|
|
47991
|
+
defaultDisplayLabel: {
|
|
47992
|
+
default: "",
|
|
47993
|
+
parseDOM: (elem) => elem.getAttribute("data-default-display-label"),
|
|
47994
|
+
renderDOM: (attrs) => {
|
|
47995
|
+
if (!attrs.defaultDisplayLabel) return {};
|
|
47996
|
+
return {
|
|
47997
|
+
"data-default-display-label": attrs.defaultDisplayLabel
|
|
47998
|
+
};
|
|
47999
|
+
}
|
|
48000
|
+
},
|
|
47864
48001
|
displayLabel: {
|
|
47865
|
-
default: "
|
|
48002
|
+
default: "",
|
|
47866
48003
|
parseDOM: (elem) => elem.getAttribute("data-display-label"),
|
|
47867
48004
|
renderDOM: (attrs) => {
|
|
47868
48005
|
if (!attrs.displayLabel) return {};
|
|
@@ -48178,6 +48315,7 @@ const FieldAnnotation = Node$1.create({
|
|
|
48178
48315
|
return renderer();
|
|
48179
48316
|
},
|
|
48180
48317
|
addCommands() {
|
|
48318
|
+
const annotationTypes = this.options.types;
|
|
48181
48319
|
return {
|
|
48182
48320
|
/**
|
|
48183
48321
|
* Add field annotation.
|
|
@@ -48199,7 +48337,12 @@ const FieldAnnotation = Node$1.create({
|
|
|
48199
48337
|
let currentMarks = $pos.marks();
|
|
48200
48338
|
currentMarks = currentMarks.length ? [...currentMarks] : null;
|
|
48201
48339
|
let formatAttrs = getFormatAttrsFromMarks(currentMarks);
|
|
48202
|
-
let
|
|
48340
|
+
let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
|
|
48341
|
+
let node2 = schema.nodes[this.name].create({
|
|
48342
|
+
...attrs,
|
|
48343
|
+
...formatAttrs,
|
|
48344
|
+
defaultDisplayLabel
|
|
48345
|
+
}, null, null);
|
|
48203
48346
|
state2.tr.insert(newPos, node2).setSelection(Selection.near(tr.doc.resolve(newPos + node2.nodeSize)));
|
|
48204
48347
|
if (editorFocus) {
|
|
48205
48348
|
this.editor.view.focus();
|
|
@@ -48207,9 +48350,9 @@ const FieldAnnotation = Node$1.create({
|
|
|
48207
48350
|
}
|
|
48208
48351
|
return true;
|
|
48209
48352
|
},
|
|
48210
|
-
addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({
|
|
48353
|
+
addFieldAnnotationAtSelection: (attrs = {}, editorFocus = false) => ({ state: state2, commands: commands2 }) => {
|
|
48211
48354
|
const { from: from2 } = state2.selection;
|
|
48212
|
-
commands2.addFieldAnnotation(from2, attrs, editorFocus);
|
|
48355
|
+
return commands2.addFieldAnnotation(from2, attrs, editorFocus);
|
|
48213
48356
|
},
|
|
48214
48357
|
/**
|
|
48215
48358
|
* Replace field annotation.
|
|
@@ -48219,24 +48362,113 @@ const FieldAnnotation = Node$1.create({
|
|
|
48219
48362
|
* from: 20,
|
|
48220
48363
|
* to: 45,
|
|
48221
48364
|
* attrs: {
|
|
48222
|
-
*
|
|
48223
|
-
*
|
|
48365
|
+
* fieldType: 'TEXTINPUT'
|
|
48366
|
+
* fieldColor: '#980043'
|
|
48224
48367
|
* }
|
|
48225
48368
|
* ])
|
|
48226
48369
|
*/
|
|
48227
|
-
replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch,
|
|
48370
|
+
replaceWithFieldAnnotation: (fieldsArray) => ({ editor, dispatch, tr }) => {
|
|
48228
48371
|
if (!dispatch) return true;
|
|
48229
|
-
tr.setMeta("fieldAnnotationReplace", true);
|
|
48230
48372
|
fieldsArray.forEach((annotation) => {
|
|
48231
48373
|
let { from: from2, to, attrs } = annotation;
|
|
48232
48374
|
let { schema } = editor;
|
|
48233
48375
|
let newPosFrom = tr.mapping.map(from2);
|
|
48234
48376
|
let newPosTo = tr.mapping.map(to);
|
|
48235
|
-
let
|
|
48377
|
+
let defaultDisplayLabel = attrs.defaultDisplayLabel ? attrs.defaultDisplayLabel : attrs.displayLabel || "";
|
|
48378
|
+
let node2 = schema.nodes[this.name].create({
|
|
48379
|
+
...attrs,
|
|
48380
|
+
defaultDisplayLabel
|
|
48381
|
+
}, null, null);
|
|
48236
48382
|
tr.replaceWith(newPosFrom, newPosTo, node2);
|
|
48237
48383
|
});
|
|
48238
48384
|
return true;
|
|
48239
48385
|
},
|
|
48386
|
+
/**
|
|
48387
|
+
* Replace annotations with a label (as text node) in selection.
|
|
48388
|
+
* @param options Additional options.
|
|
48389
|
+
* @example
|
|
48390
|
+
* editor.commands.replaceFieldAnnotationsWithLabelInSelection()
|
|
48391
|
+
*/
|
|
48392
|
+
replaceFieldAnnotationsWithLabelInSelection: (options2 = {}) => ({ commands: commands2 }) => {
|
|
48393
|
+
return commands2.replaceFieldAnnotationsWithLabel(null, {
|
|
48394
|
+
...options2,
|
|
48395
|
+
isInSelection: true
|
|
48396
|
+
});
|
|
48397
|
+
},
|
|
48398
|
+
/**
|
|
48399
|
+
* Replace annotations with a label (as text node).
|
|
48400
|
+
* @param fieldIdOrArray The field ID or array of field IDs.
|
|
48401
|
+
* @param options.isInSelection Find in selection instead of field IDs.
|
|
48402
|
+
* @param options.addToHistory Add to history or not.
|
|
48403
|
+
* @param options.types Annotation types to replace.
|
|
48404
|
+
* @example
|
|
48405
|
+
* editor.commands.replaceFieldAnnotationsWithLabel(['1', '2'])
|
|
48406
|
+
*/
|
|
48407
|
+
replaceFieldAnnotationsWithLabel: (fieldIdOrArray, {
|
|
48408
|
+
isInSelection = false,
|
|
48409
|
+
addToHistory = false,
|
|
48410
|
+
types: types2 = annotationTypes
|
|
48411
|
+
} = {}) => ({ dispatch, state: state2, tr }) => {
|
|
48412
|
+
let { from: from2, to } = state2.selection;
|
|
48413
|
+
let annotations = isInSelection ? findFieldAnnotationsBetween(from2, to, state2.doc) : findFieldAnnotationsByFieldId(fieldIdOrArray, state2);
|
|
48414
|
+
annotations = types2.length ? annotations.filter(({ node: node2 }) => types2.includes(node2.attrs.type)) : annotations;
|
|
48415
|
+
if (!annotations.length) {
|
|
48416
|
+
return true;
|
|
48417
|
+
}
|
|
48418
|
+
if (!addToHistory) {
|
|
48419
|
+
tr.setMeta("addToHistory", false);
|
|
48420
|
+
}
|
|
48421
|
+
if (dispatch) {
|
|
48422
|
+
annotations.forEach((annotation) => {
|
|
48423
|
+
let { pos, node: node2 } = annotation;
|
|
48424
|
+
let newPosFrom = tr.mapping.map(pos);
|
|
48425
|
+
let newPosTo = tr.mapping.map(pos + node2.nodeSize);
|
|
48426
|
+
let currentNode = tr.doc.nodeAt(newPosFrom);
|
|
48427
|
+
let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
|
|
48428
|
+
let $newPosFrom = tr.doc.resolve(newPosFrom);
|
|
48429
|
+
let currentMarks = $newPosFrom.marks();
|
|
48430
|
+
currentMarks = currentMarks.length ? [...currentMarks] : null;
|
|
48431
|
+
if (nodeEqual) {
|
|
48432
|
+
let label = node2.attrs.displayLabel || " ";
|
|
48433
|
+
let textNode = state2.schema.text(label, currentMarks);
|
|
48434
|
+
tr.replaceWith(newPosFrom, newPosTo, textNode);
|
|
48435
|
+
}
|
|
48436
|
+
});
|
|
48437
|
+
}
|
|
48438
|
+
return true;
|
|
48439
|
+
},
|
|
48440
|
+
/**
|
|
48441
|
+
* Resets all annotations to default values.
|
|
48442
|
+
* @example
|
|
48443
|
+
* editor.commands.resetFieldAnnotations()
|
|
48444
|
+
*/
|
|
48445
|
+
resetFieldAnnotations: () => ({ dispatch, state: state2, tr }) => {
|
|
48446
|
+
let annotations = getAllFieldAnnotations(state2);
|
|
48447
|
+
if (!annotations.length) {
|
|
48448
|
+
return true;
|
|
48449
|
+
}
|
|
48450
|
+
tr.setMeta("fieldAnnotationUpdate", true);
|
|
48451
|
+
if (dispatch) {
|
|
48452
|
+
annotations.forEach(({ pos, node: node2 }) => {
|
|
48453
|
+
let newPos = tr.mapping.map(pos);
|
|
48454
|
+
let currentNode = tr.doc.nodeAt(newPos);
|
|
48455
|
+
let nodeEqual = node2.attrs.fieldId === currentNode?.attrs?.fieldId;
|
|
48456
|
+
if (nodeEqual) {
|
|
48457
|
+
let displayLabel = node2.attrs.defaultDisplayLabel || node2.attrs.displayLabel || "";
|
|
48458
|
+
tr.setNodeMarkup(newPos, void 0, {
|
|
48459
|
+
...node2.attrs,
|
|
48460
|
+
// reset displayLabel to default.
|
|
48461
|
+
displayLabel,
|
|
48462
|
+
// reset attrs for specific types.
|
|
48463
|
+
imageSrc: null,
|
|
48464
|
+
rawHtml: null,
|
|
48465
|
+
linkUrl: null
|
|
48466
|
+
});
|
|
48467
|
+
}
|
|
48468
|
+
});
|
|
48469
|
+
}
|
|
48470
|
+
return true;
|
|
48471
|
+
},
|
|
48240
48472
|
/**
|
|
48241
48473
|
* Update annotations associated with a field.
|
|
48242
48474
|
* @param fieldIdOrArray The field ID or array of field IDs.
|
|
@@ -48991,12 +49223,16 @@ const startImageUpload = async ({ editor, view, file }) => {
|
|
|
48991
49223
|
}
|
|
48992
49224
|
let id = {};
|
|
48993
49225
|
let { tr, schema } = view.state;
|
|
48994
|
-
|
|
49226
|
+
let { selection } = tr;
|
|
49227
|
+
if (editor.options.isHeaderOrFooter) {
|
|
49228
|
+
selection = editor.options.lastSelection;
|
|
49229
|
+
}
|
|
49230
|
+
if (!selection.empty && !editor.options.isHeaderOrFooter) {
|
|
48995
49231
|
tr.deleteSelection();
|
|
48996
49232
|
}
|
|
48997
49233
|
let imageMeta = {
|
|
48998
49234
|
type: "add",
|
|
48999
|
-
pos:
|
|
49235
|
+
pos: selection.from,
|
|
49000
49236
|
id
|
|
49001
49237
|
};
|
|
49002
49238
|
tr.setMeta(ImagePlaceholderPluginKey, imageMeta);
|
|
@@ -54245,7 +54481,8 @@ const Pagination = Extension.create({
|
|
|
54245
54481
|
addStorage() {
|
|
54246
54482
|
return {
|
|
54247
54483
|
height: 0,
|
|
54248
|
-
sectionData: null
|
|
54484
|
+
sectionData: null,
|
|
54485
|
+
headerFooterEditors: /* @__PURE__ */ new Map()
|
|
54249
54486
|
};
|
|
54250
54487
|
},
|
|
54251
54488
|
addCommands() {
|
|
@@ -54254,6 +54491,19 @@ const Pagination = Extension.create({
|
|
|
54254
54491
|
return commands2.insertContent({
|
|
54255
54492
|
type: "hardBreak"
|
|
54256
54493
|
});
|
|
54494
|
+
},
|
|
54495
|
+
/**
|
|
54496
|
+
* Toggle pagination on/off
|
|
54497
|
+
* @returns {void}
|
|
54498
|
+
*/
|
|
54499
|
+
togglePagination: () => ({ tr, state: state2, dispatch, editor }) => {
|
|
54500
|
+
const isEnabled = PaginationPluginKey.getState(state2)?.isEnabled;
|
|
54501
|
+
tr.setMeta(PaginationPluginKey, { isEnabled: !isEnabled });
|
|
54502
|
+
if (dispatch) {
|
|
54503
|
+
dispatch(tr);
|
|
54504
|
+
editor.initDefaultStyles(editor.element, !isEnabled);
|
|
54505
|
+
return true;
|
|
54506
|
+
}
|
|
54257
54507
|
}
|
|
54258
54508
|
};
|
|
54259
54509
|
},
|
|
@@ -54279,22 +54529,33 @@ const Pagination = Extension.create({
|
|
|
54279
54529
|
return {
|
|
54280
54530
|
isReadyToInit: false,
|
|
54281
54531
|
decorations: DecorationSet.empty,
|
|
54282
|
-
isDebugging
|
|
54532
|
+
isDebugging,
|
|
54533
|
+
isEnabled: editor.options.pagination
|
|
54283
54534
|
};
|
|
54284
54535
|
},
|
|
54285
54536
|
apply(tr, oldState, prevEditorState, newEditorState) {
|
|
54286
54537
|
const meta = tr.getMeta(PaginationPluginKey);
|
|
54538
|
+
if (meta && "isEnabled" in meta) {
|
|
54539
|
+
const newEnabled = meta.isEnabled;
|
|
54540
|
+
if (newEnabled) shouldUpdate = true;
|
|
54541
|
+
return {
|
|
54542
|
+
...oldState,
|
|
54543
|
+
decorations: newEnabled ? oldState.decorations : DecorationSet.empty,
|
|
54544
|
+
isEnabled: newEnabled
|
|
54545
|
+
};
|
|
54546
|
+
}
|
|
54287
54547
|
if (meta && meta.isReadyToInit) {
|
|
54288
54548
|
shouldUpdate = true;
|
|
54289
54549
|
shouldInitialize = meta.isReadyToInit;
|
|
54290
54550
|
}
|
|
54551
|
+
const syncMeta = tr.getMeta("y-sync$");
|
|
54552
|
+
if (syncMeta && syncMeta.isChangeOrigin) {
|
|
54553
|
+
return { ...oldState };
|
|
54554
|
+
}
|
|
54291
54555
|
const imagePluginTransaction = tr.getMeta(ImagePlaceholderPluginKey);
|
|
54292
54556
|
if (imagePluginTransaction) {
|
|
54293
54557
|
if (imagePluginTransaction.type === "remove") {
|
|
54294
|
-
|
|
54295
|
-
const domImage = editor.view.domAtPos(imagePos).node.querySelector("img");
|
|
54296
|
-
if (domImage.complete) onImageLoad(editor);
|
|
54297
|
-
else domImage.onload = () => onImageLoad(editor);
|
|
54558
|
+
onImageLoad(editor);
|
|
54298
54559
|
}
|
|
54299
54560
|
return { ...oldState };
|
|
54300
54561
|
}
|
|
@@ -54321,6 +54582,7 @@ const Pagination = Extension.create({
|
|
|
54321
54582
|
if (isForceUpdate) shouldUpdate = true;
|
|
54322
54583
|
return {
|
|
54323
54584
|
...oldState,
|
|
54585
|
+
decorations: meta?.decorations?.map(tr.mapping, tr.doc) || DecorationSet.empty,
|
|
54324
54586
|
isReadyToInit: shouldInitialize
|
|
54325
54587
|
};
|
|
54326
54588
|
}
|
|
@@ -54330,6 +54592,7 @@ const Pagination = Extension.create({
|
|
|
54330
54592
|
let previousDecorations = DecorationSet.empty;
|
|
54331
54593
|
return {
|
|
54332
54594
|
update: (view2, prevState) => {
|
|
54595
|
+
if (!PaginationPluginKey.getState(view2.state)?.isEnabled) return;
|
|
54333
54596
|
if (!shouldUpdate || isUpdating) return;
|
|
54334
54597
|
isUpdating = true;
|
|
54335
54598
|
hasInitialized = true;
|
|
@@ -54341,7 +54604,8 @@ const Pagination = Extension.create({
|
|
|
54341
54604
|
},
|
|
54342
54605
|
props: {
|
|
54343
54606
|
decorations(state2) {
|
|
54344
|
-
|
|
54607
|
+
const pluginState = PaginationPluginKey.getState(state2);
|
|
54608
|
+
return pluginState.isEnabled ? pluginState.decorations : DecorationSet.empty;
|
|
54345
54609
|
}
|
|
54346
54610
|
}
|
|
54347
54611
|
});
|
|
@@ -54349,6 +54613,10 @@ const Pagination = Extension.create({
|
|
|
54349
54613
|
},
|
|
54350
54614
|
onDestroy() {
|
|
54351
54615
|
cleanupFloatingSeparators();
|
|
54616
|
+
const { headerFooterEditors } = this.editor.storage.pagination;
|
|
54617
|
+
if (headerFooterEditors) {
|
|
54618
|
+
headerFooterEditors.clear();
|
|
54619
|
+
}
|
|
54352
54620
|
}
|
|
54353
54621
|
});
|
|
54354
54622
|
const getHeaderFooterId = (currentPageNumber, sectionType, editor, node2 = null) => {
|
|
@@ -54409,6 +54677,7 @@ const performUpdate = (editor, view, previousDecorations) => {
|
|
|
54409
54677
|
const calculatePageBreaks = (view, editor, sectionData) => {
|
|
54410
54678
|
if (!editor.converter) return DecorationSet.empty;
|
|
54411
54679
|
const pageSize = editor.converter.pageStyles?.pageSize;
|
|
54680
|
+
if (!pageSize) return DecorationSet.empty;
|
|
54412
54681
|
const { width, height } = pageSize;
|
|
54413
54682
|
if (!width || !height) return DecorationSet.empty;
|
|
54414
54683
|
const ignorePlugins = [CollaborationPluginKey, PaginationPluginKey];
|
|
@@ -54447,11 +54716,13 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
|
|
|
54447
54716
|
let pageHeightThreshold = pageHeight;
|
|
54448
54717
|
let footer = null, header = null;
|
|
54449
54718
|
const firstHeaderId = getHeaderFooterId(currentPageNumber, "headerIds", editor);
|
|
54450
|
-
const
|
|
54719
|
+
const isFirstHeader = true;
|
|
54720
|
+
const firstHeader = createHeader(pageMargins, pageSize, sectionData, firstHeaderId, editor, currentPageNumber, isFirstHeader);
|
|
54451
54721
|
const pageBreak = createPageBreak({ editor, header: firstHeader, isFirstHeader: true });
|
|
54452
54722
|
decorations.push(Decoration.widget(0, pageBreak, { key: "stable-key" }));
|
|
54453
54723
|
const lastFooterId = getHeaderFooterId(currentPageNumber, "footerIds", editor);
|
|
54454
|
-
const
|
|
54724
|
+
const isLastFooter = true;
|
|
54725
|
+
const lastFooter = createFooter(pageMargins, pageSize, sectionData, lastFooterId, editor, currentPageNumber, isLastFooter);
|
|
54455
54726
|
pageHeightThreshold -= firstHeader.headerHeight + lastFooter.footerHeight;
|
|
54456
54727
|
let coords = view?.coordsAtPos(doc2.content.size);
|
|
54457
54728
|
if (!coords) return [];
|
|
@@ -54470,7 +54741,8 @@ function generateInternalPageBreaks(doc2, view, editor, sectionData) {
|
|
|
54470
54741
|
if (currentPageNumber === 1) {
|
|
54471
54742
|
const headerId2 = getHeaderFooterId(currentPageNumber, "headerIds", editor, currentNode);
|
|
54472
54743
|
decorations.pop();
|
|
54473
|
-
const
|
|
54744
|
+
const isFirstHeader2 = true;
|
|
54745
|
+
const newFirstHeader = createHeader(pageMargins, pageSize, sectionData, headerId2, editor, currentPageNumber, isFirstHeader2);
|
|
54474
54746
|
const pageBreak2 = createPageBreak({ editor, header: newFirstHeader, isFirstHeader: true });
|
|
54475
54747
|
decorations.push(Decoration.widget(0, pageBreak2, { key: "stable-key" }));
|
|
54476
54748
|
}
|
|
@@ -54544,15 +54816,15 @@ function createFinalPagePadding(bufferHeight) {
|
|
|
54544
54816
|
div2.style.height = bufferHeight + "px";
|
|
54545
54817
|
return { nodeHeight: bufferHeight, node: div2 };
|
|
54546
54818
|
}
|
|
54547
|
-
function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber) {
|
|
54548
|
-
const headerDef = sectionData
|
|
54819
|
+
function createHeader(pageMargins, pageSize, sectionData, headerId, editor, currentPageNumber, isFirstHeader = false) {
|
|
54820
|
+
const headerDef = sectionData?.headers?.[headerId];
|
|
54549
54821
|
const minHeaderHeight = pageMargins.top * 96;
|
|
54550
54822
|
const headerMargin = pageMargins.header * 96;
|
|
54551
54823
|
const hasHeaderOffset = headerDef?.height > minHeaderHeight - headerMargin;
|
|
54552
54824
|
const headerOffset = hasHeaderOffset ? headerMargin : 0;
|
|
54553
54825
|
const headerHeight = Math.max(headerDef?.height || 0, minHeaderHeight) + headerOffset;
|
|
54554
54826
|
const availableHeight = headerHeight - headerMargin;
|
|
54555
|
-
|
|
54827
|
+
let editorContainer = document.createElement("div");
|
|
54556
54828
|
if (!headerId && !editor?.converter?.headerIds?.["default"]) {
|
|
54557
54829
|
headerId = "rId" + generateDocxRandomId();
|
|
54558
54830
|
editor.converter.headerIds["default"] = headerId;
|
|
@@ -54564,23 +54836,31 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
|
|
|
54564
54836
|
};
|
|
54565
54837
|
}
|
|
54566
54838
|
const data = editor.converter.headers[headerId];
|
|
54567
|
-
const
|
|
54568
|
-
|
|
54569
|
-
|
|
54570
|
-
|
|
54571
|
-
|
|
54572
|
-
|
|
54573
|
-
|
|
54574
|
-
|
|
54575
|
-
|
|
54576
|
-
|
|
54577
|
-
|
|
54578
|
-
|
|
54579
|
-
|
|
54580
|
-
|
|
54839
|
+
const pageNumberIndex = currentPageNumber - 1;
|
|
54840
|
+
const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isHeader: true, isFirstHeader });
|
|
54841
|
+
let editorSection = null;
|
|
54842
|
+
const { headerFooterEditors } = editor.storage.pagination;
|
|
54843
|
+
if (headerFooterEditors.has(editorKey) && editor.converter.headerEditors[pageNumberIndex]) {
|
|
54844
|
+
const editorData = headerFooterEditors.get(editorKey);
|
|
54845
|
+
editorSection = editorData.editor;
|
|
54846
|
+
editorContainer = editorSection.element;
|
|
54847
|
+
} else {
|
|
54848
|
+
editorSection = createHeaderFooterEditor({
|
|
54849
|
+
editor,
|
|
54850
|
+
data,
|
|
54851
|
+
editorContainer,
|
|
54852
|
+
appendToBody: false,
|
|
54853
|
+
sectionId: headerId,
|
|
54854
|
+
type: "header",
|
|
54855
|
+
availableHeight,
|
|
54856
|
+
currentPageNumber
|
|
54857
|
+
});
|
|
54858
|
+
editor.converter.headerEditors.push({ id: headerId, editor: editorSection });
|
|
54859
|
+
headerFooterEditors.set(editorKey, { editor: editorSection });
|
|
54860
|
+
broadcastEditorEvents(editor, editorSection);
|
|
54861
|
+
}
|
|
54581
54862
|
editorSection.setEditable(false, false);
|
|
54582
|
-
|
|
54583
|
-
editorContainer.className = "pagination-section-header";
|
|
54863
|
+
editorContainer.classList.add("pagination-section-header");
|
|
54584
54864
|
editorContainer.style.paddingTop = headerMargin + "px";
|
|
54585
54865
|
editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
|
|
54586
54866
|
editorContainer.style.paddingRight = pageMargins.right * 96 + "px";
|
|
@@ -54593,12 +54873,12 @@ function createHeader(pageMargins, pageSize, sectionData, headerId, editor, curr
|
|
|
54593
54873
|
headerHeight
|
|
54594
54874
|
};
|
|
54595
54875
|
}
|
|
54596
|
-
function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber) {
|
|
54597
|
-
const footerDef = sectionData
|
|
54876
|
+
function createFooter(pageMargins, pageSize, sectionData, footerId, editor, currentPageNumber, isLastFooter = false) {
|
|
54877
|
+
const footerDef = sectionData?.footers?.[footerId];
|
|
54598
54878
|
const minFooterHeight = pageMargins.bottom * 96;
|
|
54599
54879
|
const footerPaddingFromEdge = pageMargins.footer * 96;
|
|
54600
54880
|
const footerHeight = Math.max(footerDef?.height || 0, minFooterHeight - footerPaddingFromEdge);
|
|
54601
|
-
|
|
54881
|
+
let editorContainer = document.createElement("div");
|
|
54602
54882
|
if (!footerId && !editor.converter.footerIds["default"]) {
|
|
54603
54883
|
footerId = "rId" + generateDocxRandomId();
|
|
54604
54884
|
editor.converter.footerIds["default"] = footerId;
|
|
@@ -54610,23 +54890,31 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
|
|
|
54610
54890
|
};
|
|
54611
54891
|
}
|
|
54612
54892
|
const data = editor.converter.footers[footerId];
|
|
54613
|
-
const
|
|
54614
|
-
|
|
54615
|
-
|
|
54616
|
-
|
|
54617
|
-
|
|
54618
|
-
|
|
54619
|
-
|
|
54620
|
-
|
|
54621
|
-
|
|
54622
|
-
|
|
54623
|
-
|
|
54624
|
-
|
|
54625
|
-
|
|
54626
|
-
|
|
54893
|
+
const pageNumberIndex = currentPageNumber - 1;
|
|
54894
|
+
const editorKey = getHeaderFooterEditorKey({ pageNumber: pageNumberIndex, isFooter: true, isLastFooter });
|
|
54895
|
+
let editorSection = null;
|
|
54896
|
+
const { headerFooterEditors } = editor.storage.pagination;
|
|
54897
|
+
if (headerFooterEditors.has(editorKey) && editor.converter.footerEditors[pageNumberIndex]) {
|
|
54898
|
+
const editorData = headerFooterEditors.get(editorKey);
|
|
54899
|
+
editorSection = editorData.editor;
|
|
54900
|
+
editorContainer = editorSection.element;
|
|
54901
|
+
} else {
|
|
54902
|
+
editorSection = createHeaderFooterEditor({
|
|
54903
|
+
editor,
|
|
54904
|
+
data,
|
|
54905
|
+
editorContainer,
|
|
54906
|
+
appendToBody: false,
|
|
54907
|
+
sectionId: footerId,
|
|
54908
|
+
type: "footer",
|
|
54909
|
+
availableHeight: footerHeight,
|
|
54910
|
+
currentPageNumber
|
|
54911
|
+
});
|
|
54912
|
+
editor.converter.footerEditors.push({ id: footerId, editor: editorSection });
|
|
54913
|
+
headerFooterEditors.set(editorKey, { editor: editorSection });
|
|
54914
|
+
broadcastEditorEvents(editor, editorSection);
|
|
54915
|
+
}
|
|
54627
54916
|
editorSection.setEditable(false, false);
|
|
54628
|
-
|
|
54629
|
-
editorContainer.className = "pagination-section-footer";
|
|
54917
|
+
editorContainer.classList.add("pagination-section-footer");
|
|
54630
54918
|
editorContainer.style.height = footerHeight + "px";
|
|
54631
54919
|
editorContainer.style.marginBottom = footerPaddingFromEdge + "px";
|
|
54632
54920
|
editorContainer.style.paddingLeft = pageMargins.left * 96 + "px";
|
|
@@ -54639,10 +54927,28 @@ function createFooter(pageMargins, pageSize, sectionData, footerId, editor, curr
|
|
|
54639
54927
|
footerHeight: footerHeight + footerPaddingFromEdge
|
|
54640
54928
|
};
|
|
54641
54929
|
}
|
|
54930
|
+
const getHeaderFooterEditorKey = ({
|
|
54931
|
+
pageNumber,
|
|
54932
|
+
isHeader,
|
|
54933
|
+
isFooter,
|
|
54934
|
+
isFirstHeader = false,
|
|
54935
|
+
isLastFooter = false
|
|
54936
|
+
}) => {
|
|
54937
|
+
if (isFirstHeader) return `first-header-${pageNumber}`;
|
|
54938
|
+
if (isLastFooter) return `last-footer-${pageNumber}`;
|
|
54939
|
+
if (isHeader) return `header-${pageNumber}`;
|
|
54940
|
+
if (isFooter) return `footer-${pageNumber}`;
|
|
54941
|
+
return void 0;
|
|
54942
|
+
};
|
|
54642
54943
|
const onHeaderFooterDblClick = (editor, currentFocusedSectionEditor) => {
|
|
54643
54944
|
if (editor.options.documentMode !== "editing") return;
|
|
54644
54945
|
editor.setEditable(false, false);
|
|
54645
|
-
toggleHeaderFooterEditMode(
|
|
54946
|
+
toggleHeaderFooterEditMode({
|
|
54947
|
+
editor,
|
|
54948
|
+
focusedSectionEditor: currentFocusedSectionEditor,
|
|
54949
|
+
isEditMode: true,
|
|
54950
|
+
documentMode: editor.options.documentMode
|
|
54951
|
+
});
|
|
54646
54952
|
};
|
|
54647
54953
|
function createPageBreak({ editor, header, footer, footerBottom = null, isFirstHeader, isLastFooter, isInTable: isInTable2 = false }) {
|
|
54648
54954
|
const { pageSize, pageMargins } = editor.converter.pageStyles;
|
|
@@ -55197,7 +55503,7 @@ const Search = Extension.create({
|
|
|
55197
55503
|
}
|
|
55198
55504
|
});
|
|
55199
55505
|
const NodeResizerKey = new PluginKey("node-resizer");
|
|
55200
|
-
const nodeResizer = (nodeNames = ["image"]) => {
|
|
55506
|
+
const nodeResizer = (nodeNames = ["image"], editor) => {
|
|
55201
55507
|
let resizeState = {
|
|
55202
55508
|
dragging: false,
|
|
55203
55509
|
startX: 0,
|
|
@@ -55222,8 +55528,13 @@ const nodeResizer = (nodeNames = ["image"]) => {
|
|
|
55222
55528
|
if (tr.getMeta(NodeResizerKey)) {
|
|
55223
55529
|
return oldState;
|
|
55224
55530
|
}
|
|
55225
|
-
|
|
55531
|
+
if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
|
|
55226
55532
|
const { selection } = newState;
|
|
55533
|
+
const node2 = selection.node;
|
|
55534
|
+
if (!node2 || !nodeNames.includes(node2.type.name)) {
|
|
55535
|
+
return DecorationSet.empty;
|
|
55536
|
+
}
|
|
55537
|
+
const decorations = [];
|
|
55227
55538
|
if (nodeNames.includes(selection.node?.type.name)) {
|
|
55228
55539
|
decorations.push(
|
|
55229
55540
|
Decoration.node(selection.from, selection.to, {
|
|
@@ -55426,7 +55737,7 @@ const nodeResizer = (nodeNames = ["image"]) => {
|
|
|
55426
55737
|
const NodeResizer = Extension.create({
|
|
55427
55738
|
name: "nodeResizer",
|
|
55428
55739
|
addPmPlugins() {
|
|
55429
|
-
return [nodeResizer(["image"])];
|
|
55740
|
+
return [nodeResizer(["image"], this.editor)];
|
|
55430
55741
|
}
|
|
55431
55742
|
});
|
|
55432
55743
|
const getRichTextExtensions = () => {
|
|
@@ -64102,7 +64413,6 @@ const style$2 = cB("icon", `
|
|
|
64102
64413
|
display: inline-block;
|
|
64103
64414
|
position: relative;
|
|
64104
64415
|
fill: currentColor;
|
|
64105
|
-
transform: translateZ(0);
|
|
64106
64416
|
`, [cM("color-transition", {
|
|
64107
64417
|
transition: "color .3s var(--n-bezier)"
|
|
64108
64418
|
}), cM("depth", {
|