@pie-lib/editable-html-tip-tap 2.1.2-next.31 → 2.1.2-next.33
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/components/CharacterPicker.js +22 -12
- package/dist/components/EditableHtml.js +215 -181
- package/dist/components/MenuBar.js +135 -75
- package/dist/components/TiptapContainer.js +16 -3
- package/dist/components/common/done-button.js +1 -1
- package/dist/components/common/toolbar-buttons.js +23 -18
- package/dist/components/icons/TableIcons.js +2 -0
- package/dist/components/icons/TextAlign.js +10 -1
- package/dist/components/image/AltDialog.js +1 -1
- package/dist/components/image/ImageToolbar.js +2 -2
- package/dist/components/media/MediaDialog.js +1 -1
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +1 -1
- package/dist/components/respArea/DragInTheBlank/choice.js +3 -2
- package/dist/components/respArea/ExplicitConstructedResponse.js +40 -39
- package/dist/components/respArea/InlineDropdown.js +58 -51
- package/dist/components/respArea/MathTemplated.js +15 -14
- package/dist/components/respArea/inlineDropdownUtils.js +1 -1
- package/dist/extensions/css.js +8 -3
- package/dist/extensions/extended-table.js +1 -1
- package/dist/extensions/image-component.js +17 -12
- package/dist/extensions/math.js +131 -76
- package/dist/extensions/media.js +2 -2
- package/dist/extensions/responseArea.js +1 -5
- package/dist/index.js +1 -1
- package/dist/node_modules/.bun/clsx@2.1.1/node_modules/clsx/dist/clsx.js +1 -1
- package/dist/utils/toolbar.d.ts +10 -0
- package/dist/utils/toolbar.js +7 -0
- package/package.json +13 -8
package/dist/extensions/math.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import u from "
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
1
|
+
import { setToolbarOpened as e } from "../utils/toolbar.js";
|
|
2
|
+
import { useEffect as t, useRef as n, useState as r } from "react";
|
|
3
|
+
import { NodeViewWrapper as i, ReactNodeViewRenderer as a } from "@tiptap/react";
|
|
4
|
+
import { Node as o } from "@tiptap/core";
|
|
5
|
+
import { NodeSelection as s, Plugin as c, PluginKey as l, TextSelection as u } from "prosemirror-state";
|
|
6
|
+
import d from "react-dom";
|
|
7
|
+
import { jsx as f, jsxs as p } from "react/jsx-runtime";
|
|
8
|
+
import { wrapMath as m } from "@pie-element/shared-math-rendering-mathjax";
|
|
9
|
+
import { MathPreview as h, MathToolbar as g } from "@pie-lib/math-toolbar";
|
|
9
10
|
//#region src/extensions/math.tsx
|
|
10
|
-
var
|
|
11
|
+
var _ = new l("ensureTextAfterMath"), v = (e = []) => e.map((e) => ({
|
|
11
12
|
name: e,
|
|
12
13
|
latex: e,
|
|
13
14
|
write: e,
|
|
14
15
|
label: e
|
|
15
|
-
})),
|
|
16
|
-
key:
|
|
16
|
+
})), y = (e) => new c({
|
|
17
|
+
key: _,
|
|
17
18
|
appendTransaction: (t, n, r) => {
|
|
18
19
|
if (!t.some((e) => e.docChanged)) return null;
|
|
19
20
|
let i = r.tr, a = !1;
|
|
@@ -24,21 +25,34 @@ var g = new c("ensureTextAfterMath"), _ = (e = []) => e.map((e) => ({
|
|
|
24
25
|
}
|
|
25
26
|
}), a ? i : null;
|
|
26
27
|
}
|
|
27
|
-
}),
|
|
28
|
-
|
|
28
|
+
}), b = (e, t) => {
|
|
29
|
+
let n;
|
|
30
|
+
for (n = t; n > 0; n--) {
|
|
31
|
+
let t = e.nodeAt(n);
|
|
32
|
+
if (t?.type?.name === "text" && t.textContent !== "") return -1;
|
|
33
|
+
if (t && t?.type?.name !== "text") break;
|
|
34
|
+
}
|
|
35
|
+
return n;
|
|
36
|
+
}, x = new c({
|
|
37
|
+
key: new l("zeroWidthSpaceHandling"),
|
|
29
38
|
props: { handleKeyDown(e, t) {
|
|
30
|
-
let { state: n, dispatch: r } = e, { selection: i, doc: a } = n, { from:
|
|
31
|
-
if (c && t.key === "Backspace" &&
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
39
|
+
let { state: n, dispatch: r } = e, { selection: i, doc: a } = n, { from: o, empty: c } = i;
|
|
40
|
+
if (c && t.key === "Backspace" && o > 0) {
|
|
41
|
+
let e = b(a, o);
|
|
42
|
+
return e === -1 ? !1 : (r(n.tr.delete(e, o)), !0);
|
|
43
|
+
}
|
|
44
|
+
if (c && t.key === "ArrowLeft" && o > 0) {
|
|
45
|
+
let e = b(a, o);
|
|
46
|
+
if (e === -1) return !1;
|
|
47
|
+
let t = n.doc.resolve(e);
|
|
48
|
+
if (t.nodeAfter || t.nodeBefore) {
|
|
49
|
+
let t = n.doc.resolve(e);
|
|
50
|
+
return r(n.tr.setSelection(s.create(n.doc, t.pos))), !0;
|
|
51
|
+
} else return r(n.tr.setSelection(u.create(n.doc, o - 2))), !0;
|
|
38
52
|
}
|
|
39
53
|
return !1;
|
|
40
54
|
} }
|
|
41
|
-
}),
|
|
55
|
+
}), S = o.create({
|
|
42
56
|
name: "math",
|
|
43
57
|
group: "inline",
|
|
44
58
|
inline: !0,
|
|
@@ -51,7 +65,7 @@ var g = new c("ensureTextAfterMath"), _ = (e = []) => e.map((e) => ({
|
|
|
51
65
|
};
|
|
52
66
|
},
|
|
53
67
|
addProseMirrorPlugins() {
|
|
54
|
-
return [
|
|
68
|
+
return [y(this.name), x];
|
|
55
69
|
},
|
|
56
70
|
parseHTML() {
|
|
57
71
|
return [{
|
|
@@ -63,13 +77,13 @@ var g = new c("ensureTextAfterMath"), _ = (e = []) => e.map((e) => ({
|
|
|
63
77
|
}];
|
|
64
78
|
},
|
|
65
79
|
addCommands() {
|
|
66
|
-
return { insertMath: (
|
|
67
|
-
let { state:
|
|
68
|
-
if (
|
|
69
|
-
let e =
|
|
70
|
-
|
|
80
|
+
return { insertMath: (t = "") => ({ tr: n, editor: r, dispatch: i }) => {
|
|
81
|
+
let { state: a } = r.view, o = a.schema.nodes.math.create({ latex: t }), { selection: c } = a, l = c.$from.pos;
|
|
82
|
+
if (n.insert(l, o), o?.type?.name === this.name) {
|
|
83
|
+
let e = s.create(n.doc, c.$from.pos);
|
|
84
|
+
n.setSelection(e);
|
|
71
85
|
}
|
|
72
|
-
return
|
|
86
|
+
return i(n), e(r, !0), !0;
|
|
73
87
|
} };
|
|
74
88
|
},
|
|
75
89
|
renderHTML({ HTMLAttributes: e }) {
|
|
@@ -82,77 +96,118 @@ var g = new c("ensureTextAfterMath"), _ = (e = []) => e.map((e) => ({
|
|
|
82
96
|
"data-latex": "",
|
|
83
97
|
"data-raw": e.latex
|
|
84
98
|
},
|
|
85
|
-
|
|
99
|
+
m(e.latex, e.wrapper)
|
|
86
100
|
];
|
|
87
101
|
},
|
|
88
102
|
addNodeView() {
|
|
89
|
-
return
|
|
103
|
+
return a((e) => /* @__PURE__ */ f(C, {
|
|
90
104
|
...e,
|
|
91
105
|
options: this.options
|
|
92
106
|
}));
|
|
93
107
|
}
|
|
94
|
-
}),
|
|
95
|
-
let { node:
|
|
108
|
+
}), C = (a) => {
|
|
109
|
+
let { node: o, updateAttributes: s, editor: c, selected: l, options: m, getPos: _ } = a, [y, b] = r(l), x = n(null), S = n(null), C = n(Date.now()), [w, T] = r({
|
|
96
110
|
top: 0,
|
|
97
111
|
left: 0
|
|
98
|
-
}), { math:
|
|
99
|
-
|
|
100
|
-
},
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
112
|
+
}), { math: E = {} } = m || {}, { keypadMode: D, controlledKeypadMode: O = !0, customKeys: k = [], keyPadCharacterRef: A, setKeypadInteraction: j } = E, M = o.attrs.latex || "", N = (e) => {
|
|
113
|
+
s({ latex: e });
|
|
114
|
+
}, P = (e, { moveCursorAfterNode: t = !0 } = {}) => {
|
|
115
|
+
if (s({ latex: e }), b(!1), t && typeof _ == "function") {
|
|
116
|
+
let e = _(), { doc: t } = c.state, n = u.create(t, e + o.nodeSize), r = c.state.tr.setSelection(n);
|
|
117
|
+
c.view.dispatch(r);
|
|
118
|
+
}
|
|
119
|
+
c.commands.focus();
|
|
104
120
|
};
|
|
105
|
-
return
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}, [
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
121
|
+
return t(() => {
|
|
122
|
+
if (!l) return;
|
|
123
|
+
let { selection: e } = c.state;
|
|
124
|
+
e.node?.type?.name === "math" && b(!0);
|
|
125
|
+
}, [l, c]), t(() => {
|
|
126
|
+
e(c, l || y);
|
|
127
|
+
}, [
|
|
128
|
+
c,
|
|
129
|
+
y,
|
|
130
|
+
l
|
|
131
|
+
]), t(() => {
|
|
132
|
+
if (!c || !y) {
|
|
133
|
+
T({
|
|
134
|
+
top: 0,
|
|
135
|
+
left: 0
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
let e = () => {
|
|
140
|
+
if (!x.current) return;
|
|
141
|
+
let { from: e } = c.state.selection, t = c.view.coordsAtPos(e), n = S.current?.getBoundingClientRect?.(), r = n?.height ? n.top : t.top, i = n?.width ? n.left : t.left, a = n?.height ? n.bottom : t.bottom ?? t.top, o = x.current.offsetHeight, s = x.current.offsetWidth, l = window.innerHeight - (a + 0) >= o ? a + 0 : r - o - 0, u = i;
|
|
142
|
+
l = Math.max(8, Math.min(l, window.innerHeight - o - 8)), u = Math.max(8, Math.min(u, window.innerWidth - s - 8));
|
|
143
|
+
let d = (c._tiptapContainerEl || document.body).getBoundingClientRect();
|
|
144
|
+
T({
|
|
145
|
+
top: l - d.top,
|
|
146
|
+
left: u - d.left
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
e();
|
|
150
|
+
let t = null, n = () => {
|
|
151
|
+
t === null && (t = requestAnimationFrame(() => {
|
|
152
|
+
t = null, e();
|
|
153
|
+
}));
|
|
154
|
+
};
|
|
155
|
+
return t = requestAnimationFrame(() => {
|
|
156
|
+
t = null, e();
|
|
157
|
+
}), window.addEventListener("scroll", n, !0), window.addEventListener("resize", n), () => {
|
|
158
|
+
t !== null && cancelAnimationFrame(t), window.removeEventListener("scroll", n, !0), window.removeEventListener("resize", n);
|
|
159
|
+
};
|
|
160
|
+
}, [c, y]), t(() => {
|
|
161
|
+
let e = (e) => {
|
|
162
|
+
let t = e?.target, n = (document.querySelectorAll?.("[id^=\"equation-editor-select\"][id*=\"listbox\"], [aria-labelledby=\"equation-editor-label\"][role=\"listbox\"]") || []).length > 0, r = !!(t?.id && t.id.includes("equation-editor-select")) || !!t?.closest?.("[id*=\"equation-editor-select\"]"), i = !!t?.closest?.(`.math-node-${C.current}`);
|
|
163
|
+
if (x.current && !x.current.contains(t) && !t?.closest?.("[data-inline-node]") && !n && !r && !i) {
|
|
164
|
+
b(!1);
|
|
165
|
+
let e = !!c?.view?.dom?.contains(t);
|
|
166
|
+
P(o.attrs.latex, { moveCursorAfterNode: !e });
|
|
167
|
+
}
|
|
118
168
|
};
|
|
119
|
-
return
|
|
120
|
-
}, [
|
|
121
|
-
|
|
169
|
+
return y ? document.addEventListener("click", e) : document.removeEventListener("click", e), () => document.removeEventListener("click", e);
|
|
170
|
+
}, [
|
|
171
|
+
c,
|
|
172
|
+
y,
|
|
173
|
+
o
|
|
174
|
+
]), /* @__PURE__ */ p(i, {
|
|
175
|
+
className: `math-node-${C.current}`,
|
|
122
176
|
style: {
|
|
123
177
|
display: "inline-flex",
|
|
124
178
|
cursor: "pointer",
|
|
125
179
|
margin: "0 4px"
|
|
126
180
|
},
|
|
127
|
-
"data-selected":
|
|
128
|
-
children: [/* @__PURE__ */
|
|
129
|
-
|
|
181
|
+
"data-selected": l,
|
|
182
|
+
children: [/* @__PURE__ */ f("div", {
|
|
183
|
+
ref: S,
|
|
184
|
+
onClick: () => b(!0),
|
|
130
185
|
contentEditable: !1,
|
|
131
|
-
children: /* @__PURE__ */
|
|
132
|
-
}),
|
|
133
|
-
ref:
|
|
134
|
-
"data-toolbar-for":
|
|
186
|
+
children: /* @__PURE__ */ f(h, { latex: M })
|
|
187
|
+
}), y && d.createPortal(/* @__PURE__ */ f("div", {
|
|
188
|
+
ref: x,
|
|
189
|
+
"data-toolbar-for": c.instanceId,
|
|
135
190
|
style: {
|
|
136
191
|
position: "absolute",
|
|
137
|
-
top: `${
|
|
138
|
-
left: `${
|
|
139
|
-
zIndex:
|
|
192
|
+
top: `${w.top}px`,
|
|
193
|
+
left: `${w.left}px`,
|
|
194
|
+
zIndex: 1e3,
|
|
140
195
|
background: "var(--editable-html-toolbar-bg, #efefef)",
|
|
141
196
|
boxShadow: "0px 1px 5px 0px rgba(0, 0, 0, 0.2), 0px 2px 2px 0px rgba(0, 0, 0, 0.14), 0px 3px 1px -2px rgba(0, 0, 0, 0.12)"
|
|
142
197
|
},
|
|
143
|
-
children: /* @__PURE__ */
|
|
144
|
-
latex:
|
|
198
|
+
children: /* @__PURE__ */ f(g, {
|
|
199
|
+
latex: M,
|
|
145
200
|
autoFocus: !0,
|
|
146
|
-
onChange:
|
|
147
|
-
onDone:
|
|
148
|
-
keypadMode:
|
|
149
|
-
controlledKeypadMode:
|
|
150
|
-
additionalKeys:
|
|
151
|
-
keyPadCharacterRef:
|
|
152
|
-
setKeypadInteraction:
|
|
201
|
+
onChange: N,
|
|
202
|
+
onDone: P,
|
|
203
|
+
keypadMode: D,
|
|
204
|
+
controlledKeypadMode: O,
|
|
205
|
+
additionalKeys: v(k),
|
|
206
|
+
keyPadCharacterRef: A,
|
|
207
|
+
setKeypadInteraction: j
|
|
153
208
|
})
|
|
154
|
-
}),
|
|
209
|
+
}), c?._tiptapContainerEl || document.body)]
|
|
155
210
|
});
|
|
156
211
|
};
|
|
157
212
|
//#endregion
|
|
158
|
-
export {
|
|
213
|
+
export { y as EnsureTextAfterMathPlugin, S as MathNode, C as MathNodeView, x as ZeroWidthSpaceHandlingPlugin };
|
package/dist/extensions/media.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import e from "../components/media/MediaDialog.js";
|
|
1
|
+
import { MediaDialog as e } from "../components/media/MediaDialog.js";
|
|
2
2
|
import t from "../components/media/MediaToolbar.js";
|
|
3
3
|
import { useEffect as n } from "react";
|
|
4
4
|
import { NodeViewWrapper as r, ReactNodeViewRenderer as i } from "@tiptap/react";
|
|
@@ -146,4 +146,4 @@ function p({ editor: e, node: i, updateAttributes: a, deleteNode: o, options: s
|
|
|
146
146
|
});
|
|
147
147
|
}
|
|
148
148
|
//#endregion
|
|
149
|
-
export { u as Media };
|
|
149
|
+
export { u as Media, p as default, f as insertDialog };
|
|
@@ -92,11 +92,7 @@ var f = {}, p = (e) => String(e || "").replace(/-/g, "_"), m = (e) => e && e.att
|
|
|
92
92
|
}
|
|
93
93
|
}, m = d(u);
|
|
94
94
|
if (m ??= d(t.doc.content.size), m == null) return !1;
|
|
95
|
-
if ([
|
|
96
|
-
"math_templated",
|
|
97
|
-
"inline_dropdown",
|
|
98
|
-
"explicit_constructed_response"
|
|
99
|
-
].includes(a)) t.setSelection(s.create(t.doc, m));
|
|
95
|
+
if (["inline_dropdown", "explicit_constructed_response"].includes(a)) t.setSelection(s.create(t.doc, m));
|
|
100
96
|
else {
|
|
101
97
|
let e = m + c.nodeSize;
|
|
102
98
|
t.setSelection(v(t.doc, e));
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ALL_PLUGINS as e, DEFAULT_PLUGINS as t } from "./extensions/index.js";
|
|
2
|
-
import n from "./components/EditableHtml.js";
|
|
2
|
+
import { EditableHtml as n } from "./components/EditableHtml.js";
|
|
3
3
|
import { deleteInlineDropdownByIndex as r } from "./components/respArea/inlineDropdownUtils.js";
|
|
4
4
|
//#region src/index.tsx
|
|
5
5
|
var i = n;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/utils/toolbar.js
|
|
3
|
+
* @auto-generated
|
|
4
|
+
*
|
|
5
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
6
|
+
* Manual edits will be overwritten on next sync.
|
|
7
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
8
|
+
*/
|
|
9
|
+
export declare const TOOLBAR_OPENED_META_KEY = "toolbarOpenedChanged";
|
|
10
|
+
export declare const setToolbarOpened: (editor: any, opened: any) => void;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/utils/toolbar.ts
|
|
2
|
+
var e = "toolbarOpenedChanged", t = (t, n) => {
|
|
3
|
+
let r = !!n;
|
|
4
|
+
t._toolbarOpened !== r && (t._toolbarOpened = r, t?.view && t?.state?.tr && t.view.dispatch(t.state.tr.setMeta(e, !0)));
|
|
5
|
+
};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { e as TOOLBAR_OPENED_META_KEY, t as setToolbarOpened };
|
package/package.json
CHANGED
|
@@ -1,17 +1,22 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@pie-lib/editable-html-tip-tap",
|
|
3
|
-
"version": "2.1.2-next.
|
|
3
|
+
"version": "2.1.2-next.33",
|
|
4
4
|
"description": "",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/pie-framework/pie-elements-ng.git",
|
|
8
|
+
"directory": "packages/lib-react/editable-html-tip-tap"
|
|
9
|
+
},
|
|
5
10
|
"dependencies": {
|
|
6
11
|
"@dnd-kit/core": "6.3.1",
|
|
7
12
|
"@dnd-kit/modifiers": "9.0.0",
|
|
8
13
|
"@dnd-kit/utilities": "3.2.2",
|
|
9
14
|
"@mui/icons-material": "^7.3.4",
|
|
10
15
|
"@mui/material": "^7.3.4",
|
|
11
|
-
"@pie-lib/drag": "4.0.3-next.
|
|
12
|
-
"@pie-lib/math-input": "8.1.1-next.
|
|
13
|
-
"@pie-lib/math-toolbar": "3.0.3-next.
|
|
14
|
-
"@pie-lib/render-ui": "6.1.1-next.
|
|
16
|
+
"@pie-lib/drag": "4.0.3-next.39",
|
|
17
|
+
"@pie-lib/math-input": "8.1.1-next.4",
|
|
18
|
+
"@pie-lib/math-toolbar": "3.0.3-next.39",
|
|
19
|
+
"@pie-lib/render-ui": "6.1.1-next.39",
|
|
15
20
|
"@tiptap/core": "3.20.0",
|
|
16
21
|
"@tiptap/extension-character-count": "3.20.0",
|
|
17
22
|
"@tiptap/extension-color": "3.20.0",
|
|
@@ -23,10 +28,10 @@
|
|
|
23
28
|
"@tiptap/extension-table": "3.20.0",
|
|
24
29
|
"@tiptap/extension-table-cell": "3.20.0",
|
|
25
30
|
"@tiptap/extension-table-header": "3.20.0",
|
|
26
|
-
"@tiptap/extension-table-row": "3.
|
|
31
|
+
"@tiptap/extension-table-row": "3.30.1",
|
|
27
32
|
"@tiptap/extension-text-align": "3.20.0",
|
|
28
33
|
"@tiptap/extension-text-style": "3.20.0",
|
|
29
|
-
"@tiptap/pm": "3.
|
|
34
|
+
"@tiptap/pm": "3.30.2",
|
|
30
35
|
"@tiptap/react": "3.20.0",
|
|
31
36
|
"@tiptap/starter-kit": "3.20.0",
|
|
32
37
|
"change-case": "^3.0.2",
|
|
@@ -43,7 +48,7 @@
|
|
|
43
48
|
"clsx": "^2.1.1",
|
|
44
49
|
"prosemirror-state": "^1.4.4",
|
|
45
50
|
"@pie-element/shared-math-rendering-mathjax": "0.1.1-next.0",
|
|
46
|
-
"@tiptap/extensions": "^3.
|
|
51
|
+
"@tiptap/extensions": "^3.30.3",
|
|
47
52
|
"@tiptap/extension-list": "^3.20.0",
|
|
48
53
|
"@types/react": "^18.2.0",
|
|
49
54
|
"@types/react-dom": "^18.2.0"
|