@pie-lib/editable-html-tip-tap 3.0.1-next.20261002233132 → 3.0.1-next.20261003061051
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/extensions/responseArea.js +37 -34
- package/package.json +1 -1
|
@@ -8,11 +8,20 @@ import { Extension as o } from "@tiptap/core";
|
|
|
8
8
|
import { NodeSelection as s, Plugin as c, PluginKey as l, TextSelection as u } from "prosemirror-state";
|
|
9
9
|
import { jsx as d } from "react/jsx-runtime";
|
|
10
10
|
//#region src/extensions/responseArea.tsx
|
|
11
|
-
var f =
|
|
11
|
+
var f = (e) => String(e || "").replace(/-/g, "_"), p = (e) => e && e.attrs && e.attrs.index != null ? String(e.attrs.index) : null, m = (e, t) => {
|
|
12
|
+
let n = 0;
|
|
13
|
+
return e.descendants((e) => {
|
|
14
|
+
if (e.type && e.type.name === t) {
|
|
15
|
+
let t = parseInt(p(e), 10);
|
|
16
|
+
!Number.isNaN(t) && t > n && (n = t);
|
|
17
|
+
}
|
|
18
|
+
return !0;
|
|
19
|
+
}), n;
|
|
20
|
+
}, h = (e, t) => {
|
|
12
21
|
let n = [];
|
|
13
22
|
return e.descendants((e, r) => {
|
|
14
23
|
if (e.type && e.type.name === t) {
|
|
15
|
-
let t =
|
|
24
|
+
let t = p(e);
|
|
16
25
|
t != null && n.push({
|
|
17
26
|
index: t,
|
|
18
27
|
pos: r,
|
|
@@ -45,59 +54,53 @@ var f = {}, p = (e) => String(e || "").replace(/-/g, "_"), m = (e) => e && e.att
|
|
|
45
54
|
onHandleAreaChange: null
|
|
46
55
|
};
|
|
47
56
|
},
|
|
57
|
+
addStorage() {
|
|
58
|
+
return { lastIndexMap: {} };
|
|
59
|
+
},
|
|
48
60
|
addProseMirrorPlugins() {
|
|
49
61
|
if (!this.options.type) return [];
|
|
50
|
-
let e =
|
|
62
|
+
let e = f(this.options.type);
|
|
51
63
|
return [new c({
|
|
52
64
|
key: new l(`response-area-watcher:${e}`),
|
|
53
|
-
view: (t) =>
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
65
|
+
view: (t) => {
|
|
66
|
+
let { lastIndexMap: n } = this.storage;
|
|
67
|
+
return n[e] = Math.max(n[e] ?? 0, m(t.state.doc, e)), { update: (t, n) => {
|
|
68
|
+
let r = t.state;
|
|
69
|
+
if (n.doc.eq(r.doc)) return;
|
|
70
|
+
let i = h(r.doc, e), a = h(n.doc, e);
|
|
71
|
+
if (this.options.toolbar && (this.options.toolbar.disabled = i.length >= this.options.maxResponseAreas), a.length > i.length) {
|
|
72
|
+
let e = new Set(i.map((e) => e.index)), t = a.filter((t) => !e.has(t.index));
|
|
73
|
+
t.length && typeof this.options.onHandleAreaChange == "function" && this.options.onHandleAreaChange(t);
|
|
59
74
|
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
})), { update: (t, n) => {
|
|
63
|
-
let r = t.state;
|
|
64
|
-
if (n.doc.eq(r.doc)) return;
|
|
65
|
-
let i = h(r.doc, e), a = h(n.doc, e);
|
|
66
|
-
if (this.options.toolbar && (this.options.toolbar.disabled = i.length >= this.options.maxResponseAreas), a.length > i.length) {
|
|
67
|
-
let e = new Set(i.map((e) => e.index)), t = a.filter((t) => !e.has(t.index));
|
|
68
|
-
t.length && typeof this.options.onHandleAreaChange == "function" && this.options.onHandleAreaChange(t);
|
|
69
|
-
}
|
|
70
|
-
} })
|
|
75
|
+
} };
|
|
76
|
+
}
|
|
71
77
|
})];
|
|
72
78
|
},
|
|
73
79
|
addCommands() {
|
|
74
80
|
return {
|
|
75
81
|
insertResponseArea: (e) => ({ tr: t, state: n, dispatch: r, commands: i }) => {
|
|
76
|
-
let a =
|
|
82
|
+
let a = f(e);
|
|
77
83
|
if (g(n.doc, a) >= this.options.maxResponseAreas) return !1;
|
|
78
|
-
|
|
79
|
-
let o = f[a] + 1;
|
|
80
|
-
f[a] += 1;
|
|
81
|
-
let c = _({
|
|
84
|
+
let { lastIndexMap: o } = this.storage, c = Math.max(o[a] ?? 0, m(n.doc, a)) + 1, l = _({
|
|
82
85
|
schema: n.schema,
|
|
83
86
|
typeName: a,
|
|
84
|
-
index:
|
|
87
|
+
index: c
|
|
85
88
|
});
|
|
86
|
-
if (!
|
|
87
|
-
let { selection:
|
|
89
|
+
if (!l) return !1;
|
|
90
|
+
let { selection: u } = n, d = u.from, p = (e) => {
|
|
88
91
|
try {
|
|
89
|
-
return t.insert(e,
|
|
92
|
+
return t.insert(e, l), e;
|
|
90
93
|
} catch {
|
|
91
94
|
return null;
|
|
92
95
|
}
|
|
93
|
-
},
|
|
94
|
-
if (
|
|
95
|
-
if (["inline_dropdown", "explicit_constructed_response"].includes(a)) t.setSelection(s.create(t.doc,
|
|
96
|
+
}, h = p(d);
|
|
97
|
+
if (h ??= p(t.doc.content.size), h == null) return !1;
|
|
98
|
+
if (["inline_dropdown", "explicit_constructed_response"].includes(a)) t.setSelection(s.create(t.doc, h));
|
|
96
99
|
else {
|
|
97
|
-
let e =
|
|
100
|
+
let e = h + l.nodeSize;
|
|
98
101
|
t.setSelection(v(t.doc, e));
|
|
99
102
|
}
|
|
100
|
-
return r && (i.focus(), r(t)), !0;
|
|
103
|
+
return r && (o[a] = c, i.focus(), r(t)), !0;
|
|
101
104
|
},
|
|
102
105
|
refreshResponseArea: () => ({ tr: e, state: t, commands: n, dispatch: r }) => {
|
|
103
106
|
let { selection: i } = t, a = i.$from.nodeAfter, o = i.from;
|