@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.
@@ -37,18 +37,28 @@ function h({ editor: l, opts: m, onClose: h }) {
37
37
  w();
38
38
  }, []), r(() => {
39
39
  if (!l) return;
40
- let e = l.options.element.getBoundingClientRect(), t = document.body.getBoundingClientRect(), { from: n } = l.state.selection, r = l.view.coordsAtPos(n), i = e.top + Math.abs(t.top) + e.height + 60;
41
- e.y > g.current.offsetHeight && (i = i - (g.current.offsetHeight + e.height) - 80), y({
42
- top: i,
43
- left: r.left
44
- });
45
- let a = l.view.dom, o = (e) => {
46
- g.current && !g.current.contains(e.target) && !a.contains(e.target) && _.current();
47
- }, s = setTimeout(() => {
48
- document.addEventListener("click", o);
40
+ let e = l.options.element, t = l.view.dom, n = () => {
41
+ if (!g.current) return;
42
+ let t = e.getBoundingClientRect(), { from: n } = l.state.selection, r = l.view.coordsAtPos(n), i = g.current.offsetHeight, a = g.current.offsetWidth, o = window.innerHeight - (t.bottom + 60) >= i || t.top < i + 80 ? t.bottom + 60 : t.top - i - 20, s = r.left;
43
+ o = Math.max(8, Math.min(o, window.innerHeight - i - 8)), s = Math.max(8, Math.min(s, window.innerWidth - a - 8)), y({
44
+ top: o,
45
+ left: s
46
+ });
47
+ };
48
+ n();
49
+ let r = null, i = () => {
50
+ r === null && (r = requestAnimationFrame(() => {
51
+ r = null, n();
52
+ }));
53
+ };
54
+ window.addEventListener("scroll", i, !0), window.addEventListener("resize", i);
55
+ let a = (e) => {
56
+ g.current && !g.current.contains(e.target) && !t.contains(e.target) && _.current();
57
+ }, o = setTimeout(() => {
58
+ document.addEventListener("click", a);
49
59
  });
50
60
  return () => {
51
- clearTimeout(s), document.removeEventListener("click", o);
61
+ clearTimeout(o), r !== null && cancelAnimationFrame(r), window.removeEventListener("scroll", i, !0), window.removeEventListener("resize", i), document.removeEventListener("click", a);
52
62
  };
53
63
  }, [l]);
54
64
  let T = (e, t) => x({
@@ -61,11 +71,11 @@ function h({ editor: l, opts: m, onClose: h }) {
61
71
  "data-toolbar-for": l.instanceId,
62
72
  style: {
63
73
  visibility: v.top === 0 && v.left === 0 ? "hidden" : "initial",
64
- position: "absolute",
74
+ position: "fixed",
65
75
  top: `${v.top}px`,
66
76
  left: `${v.left}px`,
67
77
  maxWidth: "500px",
68
- zIndex: 99
78
+ zIndex: 1e3
69
79
  },
70
80
  children: /* @__PURE__ */ d("div", { children: /* @__PURE__ */ d(p, {
71
81
  keyPadCharacterRef: m.keyPadCharacterRef,
@@ -4,38 +4,42 @@ import { ExtendedTableCell as n, ExtendedTableHeader as r } from "../extensions/
4
4
  import { DivNode as i } from "../extensions/div-node.js";
5
5
  import { EnsureEmptyRootIsDiv as a } from "../extensions/ensure-empty-root-div.js";
6
6
  import { EnsureListItemContentIsDiv as o } from "../extensions/ensure-list-item-content-is-div.js";
7
- import { DragInTheBlankNode as s, ExplicitConstructedResponseNode as c, InlineDropdownNode as l, MathTemplatedNode as u, ResponseAreaExtension as d } from "../extensions/responseArea.js";
8
- import { MathNode as f } from "../extensions/math.js";
9
- import { ImageUploadNode as p } from "../extensions/image.js";
10
- import { Media as m } from "../extensions/media.js";
11
- import { CSSMark as h } from "../extensions/css.js";
12
- import { ExtendedListItem as g } from "../extensions/extended-list-item.js";
13
- import { HeadingParagraph as _ } from "../extensions/heading-paragraph.js";
14
- import { valueToSize as v } from "../utils/size.js";
15
- import ee from "./TiptapContainer.js";
16
- import { PLUGINS_MAP as y, buildExtensions as b } from "../extensions/index.js";
17
- import { useCallback as x, useEffect as S, useMemo as C, useState as w } from "react";
18
- import { debounce as T } from "@pie-element/shared-lodash";
19
- import { EditorContent as E, useEditor as D, useEditorState as O } from "@tiptap/react";
20
- import { styled as k } from "@mui/material/styles";
21
- import A from "@tiptap/starter-kit";
22
- import { TextStyleKit as j } from "@tiptap/extension-text-style";
23
- import { CharacterCount as M } from "@tiptap/extension-character-count";
24
- import N from "@tiptap/extension-superscript";
25
- import P from "@tiptap/extension-subscript";
26
- import te from "@tiptap/extension-text-align";
27
- import F from "@tiptap/extension-image";
28
- import I from "@tiptap/extension-placeholder";
29
- import { TableRow as L } from "@tiptap/extension-table-row";
30
- import { jsx as R } from "react/jsx-runtime";
7
+ import { DragInTheBlankNode as s, ExplicitConstructedResponseNode as c, InlineDropdownNode as l, MathTemplatedNode as u, ResponseAreaExtension as ee } from "../extensions/responseArea.js";
8
+ import { MathNode as te } from "../extensions/math.js";
9
+ import { ImageUploadNode as d } from "../extensions/image.js";
10
+ import { Media as f } from "../extensions/media.js";
11
+ import { CSSMark as ne } from "../extensions/css.js";
12
+ import { ExtendedListItem as p } from "../extensions/extended-list-item.js";
13
+ import { HeadingParagraph as re } from "../extensions/heading-paragraph.js";
14
+ import { valueToSize as m } from "../utils/size.js";
15
+ import h from "./TiptapContainer.js";
16
+ import { PLUGINS_MAP as g, buildExtensions as _ } from "../extensions/index.js";
17
+ import { useCallback as v, useEffect as y, useMemo as b, useState as x } from "react";
18
+ import { debounce as S } from "@pie-element/shared-lodash";
19
+ import { EditorContent as C, useEditor as w, useEditorState as T } from "@tiptap/react";
20
+ import { styled as E } from "@mui/material/styles";
21
+ import D from "@tiptap/starter-kit";
22
+ import { TextStyleKit as O } from "@tiptap/extension-text-style";
23
+ import { CharacterCount as k } from "@tiptap/extension-character-count";
24
+ import A from "@tiptap/extension-superscript";
25
+ import j from "@tiptap/extension-subscript";
26
+ import M from "@tiptap/extension-text-align";
27
+ import N from "@tiptap/extension-image";
28
+ import P from "@tiptap/extension-placeholder";
29
+ import { TableRow as F } from "@tiptap/extension-table-row";
30
+ import { jsx as I } from "react/jsx-runtime";
31
31
  //#region src/components/EditableHtml.tsx
32
- var z = {
32
+ var ie = {
33
33
  position: "bottom",
34
34
  alignment: "left",
35
35
  alwaysVisible: !1,
36
36
  showDone: !0,
37
37
  doneOn: "blur"
38
- }, B = [
38
+ }, L = {
39
+ options: {},
40
+ respAreaToolbar: () => {},
41
+ onHandleAreaChange: () => {}
42
+ }, R = [
39
43
  "bold",
40
44
  "italic",
41
45
  "underline",
@@ -57,7 +61,7 @@ var z = {
57
61
  "h3",
58
62
  "undo",
59
63
  "redo"
60
- ], V = {
64
+ ], z = {
61
65
  "--white": "#fff",
62
66
  "--black": "#2e2b29",
63
67
  "--black-contrast": "#110f0e",
@@ -76,189 +80,219 @@ var z = {
76
80
  "--red": "#ff5c33",
77
81
  "--red-light": "#ffebe5",
78
82
  "--shadow": "0px 12px 33px 0px rgba(0, 0, 0, .06),\n 0px 3.618px 9.949px 0px rgba(0, 0, 0, .04)"
79
- }, H = (E) => {
80
- let { showParagraphs: k, separateParagraphs: H } = E.pluginProps || {}, [ne, W] = w([]), [G, K] = w(!1), { toolbarOpts: q } = E, J = x((e) => {
81
- W((t) => {
83
+ }, B = (e) => ({
84
+ spellcheck: e ? "true" : "false",
85
+ autocorrect: e ? "on" : "off",
86
+ autocapitalize: e ? "on" : "off"
87
+ }), V = (C) => {
88
+ let { showParagraphs: E, separateParagraphs: V } = C.pluginProps || {}, [ae, U] = x([]), [W, G] = x(!1), { toolbarOpts: K } = C, q = v((e) => {
89
+ U((t) => {
82
90
  let n = t.filter((t) => t.pos !== e);
83
- return n.length === 0 && K(!1), n;
91
+ return n.length === 0 && G(!1), n;
84
92
  });
85
- }, [W]), Y = {
86
- ...z,
87
- ...q
88
- }, X = C(() => {
89
- let { customPlugins: e, ...t } = E.pluginProps || {};
93
+ }, [U]), J = {
94
+ ...ie,
95
+ ...K
96
+ }, Y = v((e) => {
97
+ let t = e.getHTML();
98
+ C.markup !== t && C.onChange?.(t), J.doneOn === "blur" && C.onDone?.(t);
99
+ }, [
100
+ C.markup,
101
+ C.onChange,
102
+ C.onDone,
103
+ J.doneOn
104
+ ]), X = b(() => ({
105
+ ...L,
106
+ ...C.responseAreaProps,
107
+ onInlineDropdownToolbarClose: Y
108
+ }), [C.responseAreaProps, Y]), oe = b(() => {
109
+ let { customPlugins: e, ...t } = C.pluginProps || {};
90
110
  e ||= [];
91
- let n = (E.activePlugins || B)?.filter((e) => {
92
- let n = t[y[e] || e] || {};
93
- return !n || !n.disabled;
111
+ let n = (C.activePlugins || R)?.filter((e) => {
112
+ let n = g[e] || e, r = t[n] || {};
113
+ return !r || !r.disabled;
94
114
  });
95
- return b(n, e, {
115
+ return _(n, e, {
96
116
  math: {},
97
- textAlign: E.textAlign,
117
+ textAlign: C.textAlign,
98
118
  html: {},
99
- extraCSSRules: E.extraCSSRules || {},
100
- image: { ...E.imageSupport },
119
+ extraCSSRules: C.extraCSSRules || {},
120
+ image: { ...C.imageSupport },
101
121
  toolbar: {},
102
122
  table: {},
103
- responseArea: { type: E.responseAreaProps?.type },
104
- languageCharacters: E.languageCharactersProps,
123
+ responseArea: { type: X.type },
124
+ languageCharacters: C.languageCharactersProps,
105
125
  keyPadCharacterRef: {},
106
126
  setKeypadInteraction: {},
107
127
  media: {}
108
128
  });
109
- }, [E]), Z = D({
110
- extensions: [
111
- te.configure({
112
- types: [
113
- "heading",
114
- "paragraph",
115
- "div",
116
- "headingParagraph",
117
- "h1",
118
- "h2",
119
- "h3",
120
- "h4",
121
- "h5",
122
- "h6",
123
- "td",
124
- "th"
125
- ],
126
- alignments: [
127
- "left",
128
- "right",
129
- "center",
130
- "justify"
131
- ]
132
- }),
133
- j,
134
- M.configure({ limit: E.charactersLimit || 1e6 }),
135
- A.configure({ trailingNode: {
129
+ }, [C, X.type]), se = [
130
+ M.configure({
131
+ types: [
132
+ "heading",
133
+ "paragraph",
134
+ "div",
135
+ "headingParagraph",
136
+ "h1",
137
+ "h2",
138
+ "h3",
139
+ "h4",
140
+ "h5",
141
+ "h6",
142
+ "td",
143
+ "th"
144
+ ],
145
+ alignments: [
146
+ "left",
147
+ "right",
148
+ "center",
149
+ "justify"
150
+ ]
151
+ }),
152
+ O,
153
+ k.configure({ limit: C.charactersLimit || 1e6 }),
154
+ D.configure({
155
+ trailingNode: {
136
156
  node: "paragraph",
137
157
  notAfter: ["paragraph", "div"]
138
- } }),
139
- g,
140
- i,
141
- _,
142
- a,
143
- o,
144
- I.configure({
145
- placeholder: E.placeholder,
146
- showOnlyWhenEditable: !0,
147
- showOnlyCurrent: !1,
148
- includeChildren: !0
149
- }),
150
- t,
151
- L,
152
- r,
153
- n,
154
- d.configure(E.responseAreaProps),
155
- c.configure(E.responseAreaProps),
156
- s.configure(E.responseAreaProps),
157
- l.configure(E.responseAreaProps),
158
- u.configure(E.responseAreaProps),
159
- f.configure({
160
- toolbarOpts: Y,
161
- math: E.pluginProps?.math || {}
162
- }),
163
- P,
164
- N,
165
- F,
166
- p.configure({
167
- toolbarOpts: Y,
168
- imageHandling: {
169
- disableImageAlignmentButtons: E.disableImageAlignmentButtons,
170
- onDone: (e) => E.onDone?.(e.getHTML()),
171
- onDelete: E.imageSupport && E.imageSupport.delete && ((e) => {
172
- let { src: t } = e.attrs;
173
- E.imageSupport.delete(t, (t) => {
174
- J(e.pos);
175
- });
176
- }),
177
- insertImageRequested: E.imageSupport && ((e, t, n) => {
178
- let [r, i] = t, a = (t) => {
179
- let n;
180
- G && t && (n = E.onChange), J(i), n?.(e.getHTML());
181
- };
182
- e._insertingImage = !0, W((e) => [...e, r]), (() => {
183
- let t = n(a), r = T(() => {
184
- let t = () => window.removeEventListener("focus", r);
185
- if (!e._insertingImage) {
186
- t();
187
- return;
188
- }
189
- J(i), e._insertingImage = !1, t();
190
- }, 500);
191
- window.addEventListener("focus", r), E.imageSupport.add(t);
192
- })();
193
- }),
194
- maxImageWidth: E.maxImageWidth,
195
- maxImageHeight: E.maxImageHeight
196
- },
197
- limit: 3
198
- }),
199
- m.configure({ uploadSoundSupport: E.uploadSoundSupport }),
200
- h.configure({ extraCSSRules: E.extraCSSRules })
201
- ],
158
+ },
159
+ link: {
160
+ autolink: !1,
161
+ linkOnPaste: !1
162
+ }
163
+ }),
164
+ p,
165
+ i,
166
+ re,
167
+ a,
168
+ o,
169
+ P.configure({
170
+ placeholder: C.placeholder,
171
+ showOnlyWhenEditable: !0,
172
+ showOnlyCurrent: !1,
173
+ includeChildren: !0
174
+ }),
175
+ t,
176
+ F,
177
+ r,
178
+ n,
179
+ ee.configure(X),
180
+ c.configure(X),
181
+ s.configure(X),
182
+ l.configure(X),
183
+ u.configure(X),
184
+ te.configure({
185
+ toolbarOpts: J,
186
+ math: C.pluginProps?.math || {}
187
+ }),
188
+ j,
189
+ A,
190
+ N,
191
+ d.configure({
192
+ toolbarOpts: J,
193
+ imageHandling: {
194
+ disableImageAlignmentButtons: C.disableImageAlignmentButtons,
195
+ onDone: (e) => C.onDone?.(e.getHTML()),
196
+ onDelete: C.imageSupport && C.imageSupport.delete && ((e) => {
197
+ let { src: t } = e.attrs;
198
+ C.imageSupport.delete(t, (t) => {
199
+ q(e.pos);
200
+ });
201
+ }),
202
+ insertImageRequested: C.imageSupport && ((e, t, n) => {
203
+ let [r, i] = t, a = (t) => {
204
+ let n;
205
+ W && t && (n = C.onChange), q(i), n?.(e.getHTML());
206
+ };
207
+ e._insertingImage = !0, U((e) => [...e, r]), (() => {
208
+ let t = n(a), r = S(() => {
209
+ let t = () => window.removeEventListener("focus", r);
210
+ if (!e._insertingImage) {
211
+ t();
212
+ return;
213
+ }
214
+ q(i), e._insertingImage = !1, t();
215
+ }, 500);
216
+ window.addEventListener("focus", r), C.imageSupport.add(t);
217
+ })();
218
+ }),
219
+ maxImageWidth: C.maxImageWidth,
220
+ maxImageHeight: C.maxImageHeight
221
+ },
222
+ limit: 3
223
+ }),
224
+ f.configure({ uploadSoundSupport: C.uploadSoundSupport }),
225
+ ne.configure({ extraCSSRules: C.extraCSSRules })
226
+ ], Z = C.spellCheck !== !1, Q = w({
227
+ extensions: se,
202
228
  immediatelyRender: !1,
203
- editorProps: { handleKeyDown(e, t) {
204
- return E.onKeyDown ? E.onKeyDown(t) : !1;
205
- } },
206
- editable: !E.disabled,
207
- content: e(E.markup),
229
+ editorProps: {
230
+ attributes: B(Z),
231
+ handleKeyDown(e, t) {
232
+ return C.onKeyDown ? C.onKeyDown(t) : !1;
233
+ }
234
+ },
235
+ editable: !C.disabled,
236
+ content: e(C.markup),
208
237
  onUpdate: ({ editor: e, transaction: t }) => {
209
- t.isDone && E.onChange?.(e.getHTML());
238
+ t.isDone && C.onChange?.(e.getHTML());
210
239
  },
211
240
  onBlur: ({ editor: e }) => {
212
- if (e._insertingImage || e._toolbarOpened || e.isActive("inline_dropdown") || e.isActive("explicit_constructed_response") || !e.schema) return;
213
- let t = e.getHTML();
214
- E.markup !== t && E.onChange?.(t), Y.doneOn === "blur" && E.onDone?.(t);
241
+ e._insertingImage || e._toolbarOpened || e.isActive("inline_dropdown") || e.isActive("explicit_constructed_response") || !e.schema || Y(e);
215
242
  }
216
- }, [E.charactersLimit]);
217
- S(() => {
218
- E.editorRef && E.editorRef(Z);
219
- }, [E.editorRef, Z]), S(() => {
220
- Z?.setEditable(!E.disabled);
221
- }, [E.disabled, Z]), S(() => {
222
- if (!Z) return;
223
- let t = e(E.markup);
224
- t !== Z.getHTML() && Z.commands.setContent(t, !1);
225
- }, [E.markup, Z]), S(() => {
226
- Object.entries(V).forEach(([e, t]) => {
243
+ }, [C.charactersLimit]);
244
+ y(() => {
245
+ C.editorRef && C.editorRef(Q);
246
+ }, [C.editorRef, Q]), y(() => {
247
+ Q?.setEditable(!C.disabled);
248
+ }, [C.disabled, Q]), y(() => {
249
+ if (!Q) return;
250
+ let e = Q.options?.editorProps, t = B(Z);
251
+ e?.attributes?.spellcheck !== t.spellcheck && Q.setOptions({ editorProps: {
252
+ ...e,
253
+ attributes: t
254
+ } });
255
+ }, [Z, Q]), y(() => {
256
+ if (!Q) return;
257
+ let t = e(C.markup);
258
+ t !== Q.getHTML() && Q.commands.setContent(t, { emitUpdate: !1 });
259
+ }, [C.markup, Q]), y(() => {
260
+ Object.entries(z).forEach(([e, t]) => {
227
261
  document.documentElement.style.setProperty(e, t);
228
262
  });
229
263
  }, []);
230
- let Q = O({
231
- editor: Z,
264
+ let ce = T({
265
+ editor: Q,
232
266
  selector: (e) => ({ isFocused: e.editor?.isFocused })
233
- }), $ = C(() => {
234
- let { minWidth: e, width: t, maxWidth: n, minHeight: r, height: i, maxHeight: a } = E;
267
+ }), $ = b(() => {
268
+ let { minWidth: e, width: t, maxWidth: n, minHeight: r, height: i, maxHeight: a } = C;
235
269
  return {
236
- width: v(t),
237
- minWidth: v(e),
238
- maxWidth: v(n),
239
- height: v(i),
240
- minHeight: v(r),
241
- maxHeight: v(a)
270
+ width: m(t),
271
+ minWidth: m(e),
272
+ maxWidth: m(n),
273
+ height: m(i),
274
+ minHeight: m(r),
275
+ maxHeight: m(a)
242
276
  };
243
- }, [E]);
244
- return /* @__PURE__ */ R(ee, {
245
- ...E,
246
- activePlugins: X,
247
- toolbarOpts: Y,
248
- editorState: Q,
249
- editor: Z,
250
- children: Z && /* @__PURE__ */ R(U, {
277
+ }, [C]);
278
+ return /* @__PURE__ */ I(h, {
279
+ ...C,
280
+ activePlugins: oe,
281
+ toolbarOpts: J,
282
+ editorState: ce,
283
+ editor: Q,
284
+ children: Q && /* @__PURE__ */ I(H, {
251
285
  style: {
252
286
  minHeight: $.minHeight,
253
287
  height: $.height,
254
288
  maxHeight: $.maxHeight
255
289
  },
256
- showParagraph: k && !k.disabled,
257
- separateParagraph: H && !H.disabled,
258
- editor: Z
290
+ showParagraph: E && !E.disabled,
291
+ separateParagraph: V && !V.disabled,
292
+ editor: Q
259
293
  })
260
294
  });
261
- }, U = k(E, { shouldForwardProp: (e) => !["showParagraph", "separateParagraph"].includes(e) })(({ showParagraph: e, separateParagraph: t }) => ({
295
+ }, H = E(C, { shouldForwardProp: (e) => !["showParagraph", "separateParagraph"].includes(e) })(({ showParagraph: e, separateParagraph: t }) => ({
262
296
  display: "flex",
263
297
  outline: "none !important",
264
298
  "& .ProseMirror": {
@@ -268,8 +302,8 @@ var z = {
268
302
  outline: "none !important",
269
303
  position: "initial",
270
304
  "& > p, & > div": { margin: "0" },
271
- "& p.is-editor-empty, & div.is-editor-empty": { position: "relative" },
272
- "& p.is-editor-empty::before, & div.is-editor-empty::before": {
305
+ "& p[data-placeholder].is-empty:only-child, & div[data-placeholder].is-empty:only-child": { position: "relative" },
306
+ "& p[data-placeholder].is-empty:only-child::before, & div[data-placeholder].is-empty:only-child::before": {
273
307
  content: "attr(data-placeholder)",
274
308
  position: "absolute",
275
309
  left: 0,
@@ -288,4 +322,4 @@ var z = {
288
322
  }
289
323
  }));
290
324
  //#endregion
291
- export { H as default };
325
+ export { V as EditableHtml, V as default };