@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.
@@ -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 = {}, p = (e) => String(e || "").replace(/-/g, "_"), m = (e) => e && e.attrs && e.attrs.index != null ? String(e.attrs.index) : null, h = (e, t) => {
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 = m(e);
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 = p(this.options.type);
62
+ let e = f(this.options.type);
51
63
  return [new c({
52
64
  key: new l(`response-area-watcher:${e}`),
53
- view: (t) => (f[e] === void 0 && (f[e] = 0, t.state.doc.descendants((t) => {
54
- if (t.type && t.type.name === e) {
55
- let n = m(t);
56
- if (n != null) {
57
- let t = parseInt(n, 10);
58
- !Number.isNaN(t) && t > f[e] && (f[e] = t);
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
- return !0;
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 = p(e);
82
+ let a = f(e);
77
83
  if (g(n.doc, a) >= this.options.maxResponseAreas) return !1;
78
- f[a] === void 0 && (f[a] = 0);
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: o
87
+ index: c
85
88
  });
86
- if (!c) return !1;
87
- let { selection: l } = n, u = l.from, d = (e) => {
89
+ if (!l) return !1;
90
+ let { selection: u } = n, d = u.from, p = (e) => {
88
91
  try {
89
- return t.insert(e, c), e;
92
+ return t.insert(e, l), e;
90
93
  } catch {
91
94
  return null;
92
95
  }
93
- }, m = d(u);
94
- if (m ??= d(t.doc.content.size), m == null) return !1;
95
- if (["inline_dropdown", "explicit_constructed_response"].includes(a)) t.setSelection(s.create(t.doc, m));
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 = m + c.nodeSize;
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.20261002233132",
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.20261002233132",
17
- "@pie-lib/math-input": "9.0.1-next.20261002233132",
18
- "@pie-lib/math-toolbar": "4.0.1-next.20261002233132",
19
- "@pie-lib/render-ui": "8.0.1-next.20261002233132",
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.20261002233132",
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",