@pie-lib/editable-html-tip-tap 3.0.1-next.20261002233132 → 3.0.1-next.20261003064518
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 +6 -6
|
@@ -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;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/editable-html-tip-tap",
|
|
3
|
-
"version": "3.0.1-next.
|
|
3
|
+
"version": "3.0.1-next.20261003064518",
|
|
4
4
|
"description": "",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -13,10 +13,10 @@
|
|
|
13
13
|
"@dnd-kit/utilities": "3.2.2",
|
|
14
14
|
"@mui/icons-material": "^7.3.4",
|
|
15
15
|
"@mui/material": "^7.3.4",
|
|
16
|
-
"@pie-lib/drag": "5.0.1-next.
|
|
17
|
-
"@pie-lib/math-input": "9.0.1-next.
|
|
18
|
-
"@pie-lib/math-toolbar": "4.0.1-next.
|
|
19
|
-
"@pie-lib/render-ui": "8.0.1-next.
|
|
16
|
+
"@pie-lib/drag": "5.0.1-next.20261003064518",
|
|
17
|
+
"@pie-lib/math-input": "9.0.1-next.20261003064518",
|
|
18
|
+
"@pie-lib/math-toolbar": "4.0.1-next.20261003064518",
|
|
19
|
+
"@pie-lib/render-ui": "8.0.1-next.20261003064518",
|
|
20
20
|
"@tiptap/core": "3.31.3",
|
|
21
21
|
"@tiptap/extension-character-count": "3.31.3",
|
|
22
22
|
"@tiptap/extension-color": "3.31.3",
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"@pie-element/shared-lodash": "0.1.2-next.20261002215153",
|
|
47
47
|
"clsx": "^2.1.1",
|
|
48
48
|
"prosemirror-state": "^1.4.4",
|
|
49
|
-
"@pie-element/shared-math-rendering-mathjax": "0.1.2-next.
|
|
49
|
+
"@pie-element/shared-math-rendering-mathjax": "0.1.2-next.20261003064518",
|
|
50
50
|
"@tiptap/extensions": "3.31.3",
|
|
51
51
|
"@tiptap/extension-list": "3.31.3",
|
|
52
52
|
"@tiptap/extension-bubble-menu": "3.31.3",
|