@pie-lib/editable-html-tip-tap 2.1.2-next.30 → 2.1.2-next.32

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,37 +4,41 @@ 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";
7
+ import { DragInTheBlankNode as ee, ExplicitConstructedResponseNode as s, InlineDropdownNode as c, MathTemplatedNode as l, ResponseAreaExtension as u } from "../extensions/responseArea.js";
8
+ import { MathNode as d } from "../extensions/math.js";
9
+ import { ImageUploadNode as f } from "../extensions/image.js";
10
+ import { Media as p } from "../extensions/media.js";
11
+ import { CSSMark as m } from "../extensions/css.js";
12
+ import { ExtendedListItem as h } from "../extensions/extended-list-item.js";
13
+ import { HeadingParagraph as g } from "../extensions/heading-paragraph.js";
14
+ import { valueToSize as _ } from "../utils/size.js";
15
+ import v from "./TiptapContainer.js";
16
+ import { PLUGINS_MAP as y, buildExtensions as te } from "../extensions/index.js";
17
+ import { useCallback as b, useEffect as x, useMemo as S, useState as C } from "react";
18
+ import { debounce as w } from "@pie-element/shared-lodash";
19
+ import { EditorContent as T, useEditor as E, useEditorState as D } from "@tiptap/react";
20
+ import { styled as O } from "@mui/material/styles";
21
+ import k from "@tiptap/starter-kit";
22
+ import { TextStyleKit as A } from "@tiptap/extension-text-style";
23
+ import { CharacterCount as j } from "@tiptap/extension-character-count";
24
+ import M from "@tiptap/extension-superscript";
25
+ import N from "@tiptap/extension-subscript";
26
+ import P from "@tiptap/extension-text-align";
27
27
  import F from "@tiptap/extension-image";
28
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";
29
+ import { TableRow as ne } from "@tiptap/extension-table-row";
30
+ import { jsx as L } from "react/jsx-runtime";
31
31
  //#region src/components/EditableHtml.tsx
32
- var z = {
32
+ var R = {
33
33
  position: "bottom",
34
34
  alignment: "left",
35
35
  alwaysVisible: !1,
36
36
  showDone: !0,
37
37
  doneOn: "blur"
38
+ }, z = {
39
+ options: {},
40
+ respAreaToolbar: () => {},
41
+ onHandleAreaChange: () => {}
38
42
  }, B = [
39
43
  "bold",
40
44
  "italic",
@@ -76,39 +80,51 @@ 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) => {
83
+ }, H = (T) => {
84
+ let { showParagraphs: O, separateParagraphs: H } = T.pluginProps || {}, [re, W] = C([]), [G, K] = C(!1), { toolbarOpts: q } = T, J = b((e) => {
81
85
  W((t) => {
82
86
  let n = t.filter((t) => t.pos !== e);
83
87
  return n.length === 0 && K(!1), n;
84
88
  });
85
89
  }, [W]), Y = {
86
- ...z,
90
+ ...R,
87
91
  ...q
88
- }, X = C(() => {
89
- let { customPlugins: e, ...t } = E.pluginProps || {};
92
+ }, X = b((e) => {
93
+ let t = e.getHTML();
94
+ T.markup !== t && T.onChange?.(t), Y.doneOn === "blur" && T.onDone?.(t);
95
+ }, [
96
+ T.markup,
97
+ T.onChange,
98
+ T.onDone,
99
+ Y.doneOn
100
+ ]), Z = S(() => ({
101
+ ...z,
102
+ ...T.responseAreaProps,
103
+ onInlineDropdownToolbarClose: X
104
+ }), [T.responseAreaProps, X]), ie = S(() => {
105
+ let { customPlugins: e, ...t } = T.pluginProps || {};
90
106
  e ||= [];
91
- let n = (E.activePlugins || B)?.filter((e) => {
92
- let n = t[y[e] || e] || {};
93
- return !n || !n.disabled;
107
+ let n = (T.activePlugins || B)?.filter((e) => {
108
+ let n = y[e] || e, r = t[n] || {};
109
+ return !r || !r.disabled;
94
110
  });
95
- return b(n, e, {
111
+ return te(n, e, {
96
112
  math: {},
97
- textAlign: E.textAlign,
113
+ textAlign: T.textAlign,
98
114
  html: {},
99
- extraCSSRules: E.extraCSSRules || {},
100
- image: { ...E.imageSupport },
115
+ extraCSSRules: T.extraCSSRules || {},
116
+ image: { ...T.imageSupport },
101
117
  toolbar: {},
102
118
  table: {},
103
- responseArea: { type: E.responseAreaProps?.type },
104
- languageCharacters: E.languageCharactersProps,
119
+ responseArea: { type: Z.type },
120
+ languageCharacters: T.languageCharactersProps,
105
121
  keyPadCharacterRef: {},
106
122
  setKeypadInteraction: {},
107
123
  media: {}
108
124
  });
109
- }, [E]), Z = D({
125
+ }, [T, Z.type]), Q = E({
110
126
  extensions: [
111
- te.configure({
127
+ P.configure({
112
128
  types: [
113
129
  "heading",
114
130
  "paragraph",
@@ -130,57 +146,57 @@ var z = {
130
146
  "justify"
131
147
  ]
132
148
  }),
133
- j,
134
- M.configure({ limit: E.charactersLimit || 1e6 }),
135
- A.configure({ trailingNode: {
149
+ A,
150
+ j.configure({ limit: T.charactersLimit || 1e6 }),
151
+ k.configure({ trailingNode: {
136
152
  node: "paragraph",
137
153
  notAfter: ["paragraph", "div"]
138
154
  } }),
139
- g,
155
+ h,
140
156
  i,
141
- _,
157
+ g,
142
158
  a,
143
159
  o,
144
160
  I.configure({
145
- placeholder: E.placeholder,
161
+ placeholder: T.placeholder,
146
162
  showOnlyWhenEditable: !0,
147
163
  showOnlyCurrent: !1,
148
164
  includeChildren: !0
149
165
  }),
150
166
  t,
151
- L,
167
+ ne,
152
168
  r,
153
169
  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({
170
+ u.configure(Z),
171
+ s.configure(Z),
172
+ ee.configure(Z),
173
+ c.configure(Z),
174
+ l.configure(Z),
175
+ d.configure({
160
176
  toolbarOpts: Y,
161
- math: E.pluginProps?.math || {}
177
+ math: T.pluginProps?.math || {}
162
178
  }),
163
- P,
164
179
  N,
180
+ M,
165
181
  F,
166
- p.configure({
182
+ f.configure({
167
183
  toolbarOpts: Y,
168
184
  imageHandling: {
169
- disableImageAlignmentButtons: E.disableImageAlignmentButtons,
170
- onDone: (e) => E.onDone?.(e.getHTML()),
171
- onDelete: E.imageSupport && E.imageSupport.delete && ((e) => {
185
+ disableImageAlignmentButtons: T.disableImageAlignmentButtons,
186
+ onDone: (e) => T.onDone?.(e.getHTML()),
187
+ onDelete: T.imageSupport && T.imageSupport.delete && ((e) => {
172
188
  let { src: t } = e.attrs;
173
- E.imageSupport.delete(t, (t) => {
189
+ T.imageSupport.delete(t, (t) => {
174
190
  J(e.pos);
175
191
  });
176
192
  }),
177
- insertImageRequested: E.imageSupport && ((e, t, n) => {
193
+ insertImageRequested: T.imageSupport && ((e, t, n) => {
178
194
  let [r, i] = t, a = (t) => {
179
195
  let n;
180
- G && t && (n = E.onChange), J(i), n?.(e.getHTML());
196
+ G && t && (n = T.onChange), J(i), n?.(e.getHTML());
181
197
  };
182
198
  e._insertingImage = !0, W((e) => [...e, r]), (() => {
183
- let t = n(a), r = T(() => {
199
+ let t = n(a), r = w(() => {
184
200
  let t = () => window.removeEventListener("focus", r);
185
201
  if (!e._insertingImage) {
186
202
  t();
@@ -188,77 +204,75 @@ var z = {
188
204
  }
189
205
  J(i), e._insertingImage = !1, t();
190
206
  }, 500);
191
- window.addEventListener("focus", r), E.imageSupport.add(t);
207
+ window.addEventListener("focus", r), T.imageSupport.add(t);
192
208
  })();
193
209
  }),
194
- maxImageWidth: E.maxImageWidth,
195
- maxImageHeight: E.maxImageHeight
210
+ maxImageWidth: T.maxImageWidth,
211
+ maxImageHeight: T.maxImageHeight
196
212
  },
197
213
  limit: 3
198
214
  }),
199
- m.configure({ uploadSoundSupport: E.uploadSoundSupport }),
200
- h.configure({ extraCSSRules: E.extraCSSRules })
215
+ p.configure({ uploadSoundSupport: T.uploadSoundSupport }),
216
+ m.configure({ extraCSSRules: T.extraCSSRules })
201
217
  ],
202
218
  immediatelyRender: !1,
203
219
  editorProps: { handleKeyDown(e, t) {
204
- return E.onKeyDown ? E.onKeyDown(t) : !1;
220
+ return T.onKeyDown ? T.onKeyDown(t) : !1;
205
221
  } },
206
- editable: !E.disabled,
207
- content: e(E.markup),
222
+ editable: !T.disabled,
223
+ content: e(T.markup),
208
224
  onUpdate: ({ editor: e, transaction: t }) => {
209
- t.isDone && E.onChange?.(e.getHTML());
225
+ t.isDone && T.onChange?.(e.getHTML());
210
226
  },
211
227
  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);
228
+ e._insertingImage || e._toolbarOpened || e.isActive("inline_dropdown") || e.isActive("explicit_constructed_response") || !e.schema || X(e);
215
229
  }
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(() => {
230
+ }, [T.charactersLimit]);
231
+ x(() => {
232
+ T.editorRef && T.editorRef(Q);
233
+ }, [T.editorRef, Q]), x(() => {
234
+ Q?.setEditable(!T.disabled);
235
+ }, [T.disabled, Q]), x(() => {
236
+ if (!Q) return;
237
+ let t = e(T.markup);
238
+ t !== Q.getHTML() && Q.commands.setContent(t, { emitUpdate: !1 });
239
+ }, [T.markup, Q]), x(() => {
226
240
  Object.entries(V).forEach(([e, t]) => {
227
241
  document.documentElement.style.setProperty(e, t);
228
242
  });
229
243
  }, []);
230
- let Q = O({
231
- editor: Z,
244
+ let ae = D({
245
+ editor: Q,
232
246
  selector: (e) => ({ isFocused: e.editor?.isFocused })
233
- }), $ = C(() => {
234
- let { minWidth: e, width: t, maxWidth: n, minHeight: r, height: i, maxHeight: a } = E;
247
+ }), $ = S(() => {
248
+ let { minWidth: e, width: t, maxWidth: n, minHeight: r, height: i, maxHeight: a } = T;
235
249
  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)
250
+ width: _(t),
251
+ minWidth: _(e),
252
+ maxWidth: _(n),
253
+ height: _(i),
254
+ minHeight: _(r),
255
+ maxHeight: _(a)
242
256
  };
243
- }, [E]);
244
- return /* @__PURE__ */ R(ee, {
245
- ...E,
246
- activePlugins: X,
257
+ }, [T]);
258
+ return /* @__PURE__ */ L(v, {
259
+ ...T,
260
+ activePlugins: ie,
247
261
  toolbarOpts: Y,
248
- editorState: Q,
249
- editor: Z,
250
- children: Z && /* @__PURE__ */ R(U, {
262
+ editorState: ae,
263
+ editor: Q,
264
+ children: Q && /* @__PURE__ */ L(U, {
251
265
  style: {
252
266
  minHeight: $.minHeight,
253
267
  height: $.height,
254
268
  maxHeight: $.maxHeight
255
269
  },
256
- showParagraph: k && !k.disabled,
270
+ showParagraph: O && !O.disabled,
257
271
  separateParagraph: H && !H.disabled,
258
- editor: Z
272
+ editor: Q
259
273
  })
260
274
  });
261
- }, U = k(E, { shouldForwardProp: (e) => !["showParagraph", "separateParagraph"].includes(e) })(({ showParagraph: e, separateParagraph: t }) => ({
275
+ }, U = O(T, { shouldForwardProp: (e) => !["showParagraph", "separateParagraph"].includes(e) })(({ showParagraph: e, separateParagraph: t }) => ({
262
276
  display: "flex",
263
277
  outline: "none !important",
264
278
  "& .ProseMirror": {
@@ -268,8 +282,8 @@ var z = {
268
282
  outline: "none !important",
269
283
  position: "initial",
270
284
  "& > 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": {
285
+ "& p[data-placeholder].is-empty:only-child, & div[data-placeholder].is-empty:only-child": { position: "relative" },
286
+ "& p[data-placeholder].is-empty:only-child::before, & div[data-placeholder].is-empty:only-child::before": {
273
287
  content: "attr(data-placeholder)",
274
288
  position: "absolute",
275
289
  left: 0,
@@ -288,4 +302,4 @@ var z = {
288
302
  }
289
303
  }));
290
304
  //#endregion
291
- export { H as default };
305
+ export { H as EditableHtml, H as default };