@pie-lib/editable-html-tip-tap 0.1.0

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.
Files changed (158) hide show
  1. package/dist/components/CharacterPicker.d.ts +31 -0
  2. package/dist/components/CharacterPicker.d.ts.map +1 -0
  3. package/dist/components/CharacterPicker.js +129 -0
  4. package/dist/components/EditableHtml.d.ts +11 -0
  5. package/dist/components/EditableHtml.d.ts.map +1 -0
  6. package/dist/components/EditableHtml.js +270 -0
  7. package/dist/components/MenuBar.d.ts +11 -0
  8. package/dist/components/MenuBar.d.ts.map +1 -0
  9. package/dist/components/MenuBar.js +460 -0
  10. package/dist/components/TiptapContainer.d.ts +11 -0
  11. package/dist/components/TiptapContainer.d.ts.map +1 -0
  12. package/dist/components/TiptapContainer.js +157 -0
  13. package/dist/components/characters/characterUtils.d.ts +36 -0
  14. package/dist/components/characters/characterUtils.d.ts.map +1 -0
  15. package/dist/components/characters/characterUtils.js +465 -0
  16. package/dist/components/characters/custom-popper.d.ts +14 -0
  17. package/dist/components/characters/custom-popper.d.ts.map +1 -0
  18. package/dist/components/characters/custom-popper.js +32 -0
  19. package/dist/components/common/done-button.d.ts +30 -0
  20. package/dist/components/common/done-button.d.ts.map +1 -0
  21. package/dist/components/common/done-button.js +26 -0
  22. package/dist/components/common/toolbar-buttons.d.ts +39 -0
  23. package/dist/components/common/toolbar-buttons.d.ts.map +1 -0
  24. package/dist/components/common/toolbar-buttons.js +91 -0
  25. package/dist/components/icons/CssIcon.d.ts +11 -0
  26. package/dist/components/icons/CssIcon.d.ts.map +1 -0
  27. package/dist/components/icons/CssIcon.js +14 -0
  28. package/dist/components/icons/RespArea.d.ts +26 -0
  29. package/dist/components/icons/RespArea.d.ts.map +1 -0
  30. package/dist/components/icons/RespArea.js +42 -0
  31. package/dist/components/icons/TableIcons.d.ts +14 -0
  32. package/dist/components/icons/TableIcons.d.ts.map +1 -0
  33. package/dist/components/icons/TableIcons.js +32 -0
  34. package/dist/components/icons/TextAlign.d.ts +18 -0
  35. package/dist/components/icons/TextAlign.d.ts.map +1 -0
  36. package/dist/components/icons/TextAlign.js +134 -0
  37. package/dist/components/image/AltDialog.d.ts +23 -0
  38. package/dist/components/image/AltDialog.d.ts.map +1 -0
  39. package/dist/components/image/AltDialog.js +61 -0
  40. package/dist/components/image/ImageToolbar.d.ts +25 -0
  41. package/dist/components/image/ImageToolbar.d.ts.map +1 -0
  42. package/dist/components/image/ImageToolbar.js +80 -0
  43. package/dist/components/image/InsertImageHandler.d.ts +33 -0
  44. package/dist/components/image/InsertImageHandler.d.ts.map +1 -0
  45. package/dist/components/image/InsertImageHandler.js +55 -0
  46. package/dist/components/media/MediaDialog.d.ts +44 -0
  47. package/dist/components/media/MediaDialog.d.ts.map +1 -0
  48. package/dist/components/media/MediaDialog.js +389 -0
  49. package/dist/components/media/MediaToolbar.d.ts +20 -0
  50. package/dist/components/media/MediaToolbar.d.ts.map +1 -0
  51. package/dist/components/media/MediaToolbar.js +41 -0
  52. package/dist/components/media/MediaWrapper.d.ts +20 -0
  53. package/dist/components/media/MediaWrapper.d.ts.map +1 -0
  54. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
  55. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts.map +1 -0
  56. package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +58 -0
  57. package/dist/components/respArea/DragInTheBlank/choice.d.ts +56 -0
  58. package/dist/components/respArea/DragInTheBlank/choice.d.ts.map +1 -0
  59. package/dist/components/respArea/DragInTheBlank/choice.js +156 -0
  60. package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
  61. package/dist/components/respArea/ExplicitConstructedResponse.d.ts.map +1 -0
  62. package/dist/components/respArea/ExplicitConstructedResponse.js +67 -0
  63. package/dist/components/respArea/InlineDropdown.d.ts +18 -0
  64. package/dist/components/respArea/InlineDropdown.d.ts.map +1 -0
  65. package/dist/components/respArea/InlineDropdown.js +91 -0
  66. package/dist/components/respArea/MathTemplated.d.ts +19 -0
  67. package/dist/components/respArea/MathTemplated.d.ts.map +1 -0
  68. package/dist/components/respArea/MathTemplated.js +97 -0
  69. package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
  70. package/dist/components/respArea/ToolbarIcon.d.ts.map +1 -0
  71. package/dist/components/respArea/ToolbarIcon.js +17 -0
  72. package/dist/constants.d.ts +14 -0
  73. package/dist/constants.d.ts.map +1 -0
  74. package/dist/constants.js +4 -0
  75. package/dist/extensions/css.d.ts +12 -0
  76. package/dist/extensions/css.d.ts.map +1 -0
  77. package/dist/extensions/css.js +115 -0
  78. package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
  79. package/dist/extensions/custom-toolbar-wrapper.d.ts.map +1 -0
  80. package/dist/extensions/custom-toolbar-wrapper.js +58 -0
  81. package/dist/extensions/div-node.d.ts +11 -0
  82. package/dist/extensions/div-node.d.ts.map +1 -0
  83. package/dist/extensions/div-node.js +25 -0
  84. package/dist/extensions/extended-table.d.ts +11 -0
  85. package/dist/extensions/extended-table.d.ts.map +1 -0
  86. package/dist/extensions/extended-table.js +15 -0
  87. package/dist/extensions/image-component.d.ts +22 -0
  88. package/dist/extensions/image-component.d.ts.map +1 -0
  89. package/dist/extensions/image-component.js +200 -0
  90. package/dist/extensions/image.d.ts +11 -0
  91. package/dist/extensions/image.d.ts.map +1 -0
  92. package/dist/extensions/image.js +42 -0
  93. package/dist/extensions/index.d.ts +17 -0
  94. package/dist/extensions/index.d.ts.map +1 -0
  95. package/dist/extensions/index.js +65 -0
  96. package/dist/extensions/math.d.ts +15 -0
  97. package/dist/extensions/math.d.ts.map +1 -0
  98. package/dist/extensions/math.js +150 -0
  99. package/dist/extensions/media.d.ts +19 -0
  100. package/dist/extensions/media.d.ts.map +1 -0
  101. package/dist/extensions/media.js +147 -0
  102. package/dist/extensions/responseArea.d.ts +28 -0
  103. package/dist/extensions/responseArea.d.ts.map +1 -0
  104. package/dist/extensions/responseArea.js +259 -0
  105. package/dist/index.d.ts +13 -0
  106. package/dist/index.d.ts.map +1 -0
  107. package/dist/index.js +6 -0
  108. package/dist/styles/editorContainerStyles.d.ts +135 -0
  109. package/dist/styles/editorContainerStyles.d.ts.map +1 -0
  110. package/dist/theme.d.ts +10 -0
  111. package/dist/theme.d.ts.map +1 -0
  112. package/dist/utils/helper.d.ts +10 -0
  113. package/dist/utils/helper.d.ts.map +1 -0
  114. package/dist/utils/helper.js +7 -0
  115. package/dist/utils/size.d.ts +10 -0
  116. package/dist/utils/size.d.ts.map +1 -0
  117. package/dist/utils/size.js +14 -0
  118. package/package.json +71 -0
  119. package/src/components/CharacterPicker.tsx +210 -0
  120. package/src/components/EditableHtml.tsx +416 -0
  121. package/src/components/MenuBar.tsx +558 -0
  122. package/src/components/TiptapContainer.tsx +228 -0
  123. package/src/components/characters/characterUtils.ts +457 -0
  124. package/src/components/characters/custom-popper.tsx +48 -0
  125. package/src/components/common/done-button.tsx +37 -0
  126. package/src/components/common/toolbar-buttons.tsx +132 -0
  127. package/src/components/icons/CssIcon.tsx +25 -0
  128. package/src/components/icons/RespArea.tsx +81 -0
  129. package/src/components/icons/TableIcons.tsx +62 -0
  130. package/src/components/icons/TextAlign.tsx +124 -0
  131. package/src/components/image/AltDialog.tsx +92 -0
  132. package/src/components/image/ImageToolbar.tsx +109 -0
  133. package/src/components/image/InsertImageHandler.ts +121 -0
  134. package/src/components/media/MediaDialog.tsx +606 -0
  135. package/src/components/media/MediaToolbar.tsx +59 -0
  136. package/src/components/media/MediaWrapper.tsx +49 -0
  137. package/src/components/respArea/DragInTheBlank/DragInTheBlank.tsx +86 -0
  138. package/src/components/respArea/DragInTheBlank/choice.tsx +266 -0
  139. package/src/components/respArea/ExplicitConstructedResponse.tsx +122 -0
  140. package/src/components/respArea/InlineDropdown.tsx +152 -0
  141. package/src/components/respArea/MathTemplated.tsx +134 -0
  142. package/src/components/respArea/ToolbarIcon.tsx +76 -0
  143. package/src/constants.ts +15 -0
  144. package/src/extensions/css.tsx +230 -0
  145. package/src/extensions/custom-toolbar-wrapper.tsx +88 -0
  146. package/src/extensions/div-node.tsx +46 -0
  147. package/src/extensions/extended-table.ts +34 -0
  148. package/src/extensions/image-component.tsx +303 -0
  149. package/src/extensions/image.tsx +64 -0
  150. package/src/extensions/index.tsx +91 -0
  151. package/src/extensions/math.tsx +285 -0
  152. package/src/extensions/media.tsx +198 -0
  153. package/src/extensions/responseArea.tsx +404 -0
  154. package/src/index.tsx +15 -0
  155. package/src/styles/editorContainerStyles.ts +155 -0
  156. package/src/theme.ts +11 -0
  157. package/src/utils/helper.tsx +27 -0
  158. package/src/utils/size.ts +42 -0
@@ -0,0 +1,150 @@
1
+ import { useEffect as e, useRef as t, useState as n } from "react";
2
+ import { NodeViewWrapper as r, ReactNodeViewRenderer as i } from "@tiptap/react";
3
+ import { Node as a } from "@tiptap/core";
4
+ import { NodeSelection as o, Plugin as s, PluginKey as c, TextSelection as l } from "prosemirror-state";
5
+ import { jsx as u, jsxs as d } from "react/jsx-runtime";
6
+ import { wrapMath as f } from "@pie-element/shared-math-rendering-mathjax";
7
+ import p from "react-dom";
8
+ import { MathPreview as m, MathToolbar as h } from "@pie-lib/math-toolbar";
9
+ //#region src/extensions/math.tsx
10
+ var g = new c("ensureTextAfterMath"), _ = (e) => new s({
11
+ key: g,
12
+ appendTransaction: (t, n, r) => {
13
+ if (!t.some((e) => e.docChanged)) return null;
14
+ let i = r.tr, a = !1;
15
+ return r.doc.descendants((t, n) => {
16
+ if (t.type.name === e) {
17
+ let e = n + t.nodeSize, o = r.doc.nodeAt(e);
18
+ (!o || o.type.name !== "text") && (i.insert(e, r.schema.text("​")), a = !0);
19
+ }
20
+ }), a ? i : null;
21
+ }
22
+ }), v = new s({
23
+ key: new c("zeroWidthSpaceHandling"),
24
+ props: { handleKeyDown(e, t) {
25
+ let { state: n, dispatch: r } = e, { selection: i, doc: a } = n, { from: s, empty: c } = i;
26
+ if (c && t.key === "Backspace" && s > 0 && a.textBetween(s - 1, s, "", "") === "​") return r(n.tr.delete(s - 2, s)), !0;
27
+ if (c && t.key === "ArrowLeft" && s > 0 && a.textBetween(s - 1, s, "", "") === "​") {
28
+ let e = s - 1, t = n.doc.resolve(e - 1), i = t.nodeAfter || t.nodeBefore;
29
+ if (i) {
30
+ let t = e - i.nodeSize, a = n.doc.resolve(t);
31
+ return r(n.tr.setSelection(o.create(n.doc, a.pos))), !0;
32
+ } else return r(n.tr.setSelection(l.create(n.doc, s - 2))), !0;
33
+ }
34
+ return !1;
35
+ } }
36
+ }), y = a.create({
37
+ name: "math",
38
+ group: "inline",
39
+ inline: !0,
40
+ atom: !0,
41
+ addAttributes() {
42
+ return {
43
+ latex: { default: "" },
44
+ wrapper: { default: null },
45
+ html: { default: null }
46
+ };
47
+ },
48
+ addProseMirrorPlugins() {
49
+ return [_(this.name), v];
50
+ },
51
+ parseHTML() {
52
+ return [{
53
+ tag: "span[data-latex]",
54
+ getAttrs: (e) => ({ latex: e.getAttribute("data-raw") || e.textContent })
55
+ }, {
56
+ tag: "span[data-type=\"mathml\"]",
57
+ getAttrs: (e) => ({ html: e.innerHTML })
58
+ }];
59
+ },
60
+ addCommands() {
61
+ return { insertMath: (e = "") => ({ tr: t, editor: n, dispatch: r }) => {
62
+ let { state: i } = n.view, a = i.schema.nodes.math.create({ latex: e }), { selection: s } = i, c = s.$from.pos;
63
+ if (t.insert(c, a), a?.type?.name === this.name) {
64
+ let e = o.create(t.doc, s.$from.pos);
65
+ t.setSelection(e);
66
+ }
67
+ return r(t), !0;
68
+ } };
69
+ },
70
+ renderHTML({ HTMLAttributes: e }) {
71
+ return e.html ? ["span", {
72
+ "data-type": "mathml",
73
+ dangerouslySetInnerHTML: { __html: e.html }
74
+ }] : [
75
+ "span",
76
+ {
77
+ "data-latex": "",
78
+ "data-raw": e.latex
79
+ },
80
+ f(e.latex, e.wrapper)
81
+ ];
82
+ },
83
+ addNodeView() {
84
+ return i((e) => /* @__PURE__ */ u(b, {
85
+ ...e,
86
+ options: this.options
87
+ }));
88
+ }
89
+ }), b = (i) => {
90
+ let { node: a, updateAttributes: o, editor: s, selected: c, options: f } = i, [g, _] = n(c), v = t(null), [y, b] = n({
91
+ top: 0,
92
+ left: 0
93
+ }), x = a.attrs.latex || "";
94
+ e(() => {
95
+ c && _(!0);
96
+ }, [c]), e(() => {
97
+ s._toolbarOpened = !!g;
98
+ }, [g]), e(() => {
99
+ let e = document.body.getBoundingClientRect(), { from: t } = s.state.selection, n = s.view.coordsAtPos(t);
100
+ b({
101
+ top: n.top + Math.abs(e.top) + 40,
102
+ left: n.left
103
+ });
104
+ let r = (e) => {
105
+ v.current && !v.current.contains(e.target) && !e.target.closest("[data-inline-node]") && _(!1);
106
+ };
107
+ return g ? document.addEventListener("click", r) : document.removeEventListener("click", r), () => document.removeEventListener("click", r);
108
+ }, [s, g]);
109
+ let S = (e) => {
110
+ o({ latex: e });
111
+ }, C = (e) => {
112
+ o({ latex: e }), _(!1), s._toolbarOpened = !1;
113
+ let { selection: t, tr: n, doc: r } = s.state, i = l.create(r, t.from + 1);
114
+ n.setSelection(i), s.view.dispatch(n), s.commands.focus();
115
+ };
116
+ return /* @__PURE__ */ d(r, {
117
+ className: "math-node",
118
+ style: {
119
+ display: "inline-flex",
120
+ cursor: "pointer",
121
+ margin: "0 4px"
122
+ },
123
+ "data-selected": c,
124
+ children: [/* @__PURE__ */ u("div", {
125
+ onClick: () => _(!0),
126
+ contentEditable: !1,
127
+ children: /* @__PURE__ */ u(m, { latex: x })
128
+ }), g && p.createPortal(/* @__PURE__ */ u("div", {
129
+ ref: v,
130
+ "data-toolbar-for": s.instanceId,
131
+ style: {
132
+ position: "absolute",
133
+ top: `${y.top}px`,
134
+ left: `${y.left}px`,
135
+ zIndex: 20,
136
+ background: "var(--editable-html-toolbar-bg, #efefef)",
137
+ 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)"
138
+ },
139
+ children: /* @__PURE__ */ u(h, {
140
+ latex: x,
141
+ autoFocus: !0,
142
+ onChange: S,
143
+ onDone: C,
144
+ keypadMode: "basic"
145
+ })
146
+ }), document.body)]
147
+ });
148
+ };
149
+ //#endregion
150
+ export { y as MathNode };
@@ -0,0 +1,19 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/media.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
+ import { Node } from '@tiptap/core';
10
+ export declare const Media: Node<any, any>;
11
+ export declare const insertDialog: (props: any) => void;
12
+ export default function MediaNodeView({ editor, node, updateAttributes, deleteNode, options }: {
13
+ editor: any;
14
+ node: any;
15
+ updateAttributes: any;
16
+ deleteNode: any;
17
+ options: any;
18
+ }): JSX.Element;
19
+ //# sourceMappingURL=media.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"media.d.ts","sourceRoot":"","sources":["../../src/extensions/media.tsx"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAIH,OAAO,EAAmB,IAAI,EAAE,MAAM,cAAc,CAAC;AAKrD,eAAO,MAAM,KAAK,gBAyFhB,CAAC;AAQH,eAAO,MAAM,YAAY,GAAI,UAAK,SA8BjC,CAAC;AAEF,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,gBAAgB,EAAE,UAAU,EAAE,OAAO,EAAE;;;;;;CAAA,eAmD5F"}
@@ -0,0 +1,147 @@
1
+ import e from "../components/media/MediaDialog.js";
2
+ import t from "../components/media/MediaToolbar.js";
3
+ import { useEffect as n } from "react";
4
+ import { NodeViewWrapper as r, ReactNodeViewRenderer as i } from "@tiptap/react";
5
+ import { Node as a, mergeAttributes as o } from "@tiptap/core";
6
+ import { jsx as s, jsxs as c } from "react/jsx-runtime";
7
+ import l from "react-dom";
8
+ //#region src/extensions/media.tsx
9
+ var u = a.create({
10
+ name: "media",
11
+ group: "inline",
12
+ inline: !0,
13
+ atom: !0,
14
+ addAttributes() {
15
+ return {
16
+ type: { default: "video" },
17
+ src: { default: null },
18
+ width: { default: null },
19
+ height: { default: null },
20
+ title: { default: null },
21
+ starts: { default: null },
22
+ ends: { default: null },
23
+ editing: { default: !1 },
24
+ tag: { default: "iframe" },
25
+ url: { default: null }
26
+ };
27
+ },
28
+ parseHTML() {
29
+ return [{
30
+ tag: "iframe[data-type=\"video\"]",
31
+ getAttrs: (e) => ({
32
+ type: "video",
33
+ tag: "iframe",
34
+ src: e.getAttribute("src"),
35
+ width: e.getAttribute("width"),
36
+ height: e.getAttribute("height"),
37
+ title: e.dataset.title,
38
+ starts: e.dataset.starts,
39
+ ends: e.dataset.ends,
40
+ url: e.dataset.url
41
+ })
42
+ }, {
43
+ tag: "audio",
44
+ getAttrs: (e) => ({
45
+ type: "audio",
46
+ tag: "audio",
47
+ src: e.querySelector("source")?.getAttribute("src")
48
+ })
49
+ }];
50
+ },
51
+ renderHTML({ HTMLAttributes: e }) {
52
+ let { tag: t, src: n, width: r, height: i } = e;
53
+ return t === "audio" ? [
54
+ "audio",
55
+ {
56
+ controls: "controls",
57
+ controlsList: "nodownload"
58
+ },
59
+ ["source", {
60
+ src: n,
61
+ type: "audio/mp3"
62
+ }]
63
+ ] : ["iframe", o({
64
+ "data-type": "video",
65
+ frameborder: "0",
66
+ allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture",
67
+ allowfullscreen: "",
68
+ src: n
69
+ }, r ? { width: r } : {}, i ? { height: i } : {})];
70
+ },
71
+ addCommands() {
72
+ return {
73
+ insertMedia: (e) => ({ commands: t }) => t.insertContent({
74
+ type: this.name,
75
+ attrs: e
76
+ }),
77
+ updateMedia: (e) => ({ commands: t }) => t.updateAttributes(this.name, e)
78
+ };
79
+ },
80
+ addNodeView() {
81
+ return i((e) => /* @__PURE__ */ s(p, {
82
+ ...e,
83
+ options: this.options
84
+ }));
85
+ }
86
+ }), d = () => {
87
+ document.querySelectorAll(".insert-media-dialog").forEach((e) => e.remove());
88
+ }, f = (t) => {
89
+ let n = document.createElement("div"), { type: r, callback: i, options: a, ...o } = t, c = document.body.style.overflow;
90
+ d(), n.className = "insert-media-dialog", document.body.style.overflow = "hidden";
91
+ let u = (e, t) => {
92
+ i(e, t), n.remove(), document.body.style.overflow = c;
93
+ }, f = /* @__PURE__ */ s(e, {
94
+ ...o,
95
+ uploadSoundSupport: a.uploadSoundSupport,
96
+ type: r,
97
+ disablePortal: !0,
98
+ open: !0,
99
+ handleClose: u
100
+ });
101
+ l.render(f, n), document.body.appendChild(n);
102
+ };
103
+ function p({ editor: e, node: i, updateAttributes: a, deleteNode: o, options: l }) {
104
+ let { type: u, src: d, width: p, height: m, tag: h } = i.attrs, g = () => {
105
+ f({
106
+ ...i.attrs,
107
+ options: l,
108
+ edit: !0,
109
+ callback: (t, n) => {
110
+ t && a(n), e.chain().focus().run();
111
+ }
112
+ });
113
+ };
114
+ return n(() => {
115
+ d || f({
116
+ ...i.attrs,
117
+ options: l,
118
+ edit: !0,
119
+ callback: (t, n) => {
120
+ t ? a(n) : o(), e.chain().focus().run();
121
+ }
122
+ });
123
+ }, []), /* @__PURE__ */ c(r, {
124
+ "data-type": u,
125
+ style: {
126
+ width: p,
127
+ height: m
128
+ },
129
+ children: [h === "audio" ? /* @__PURE__ */ s("audio", {
130
+ controls: !0,
131
+ controlsList: "nodownload",
132
+ children: /* @__PURE__ */ s("source", {
133
+ type: "audio/mp3",
134
+ src: d
135
+ })
136
+ }) : /* @__PURE__ */ s("iframe", {
137
+ src: d,
138
+ allowFullScreen: !0,
139
+ frameBorder: "0"
140
+ }), /* @__PURE__ */ s(t, {
141
+ onEdit: g,
142
+ onRemove: o
143
+ })]
144
+ });
145
+ }
146
+ //#endregion
147
+ export { u as Media };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/responseArea.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
+ import { Extension } from '@tiptap/core';
10
+ import { Node } from '@tiptap/react';
11
+ export declare const ResponseAreaExtension: Extension<any, any>;
12
+ /**
13
+ * ExplicitConstructedResponse Node
14
+ */
15
+ export declare const ExplicitConstructedResponseNode: Node<any, any>;
16
+ /**
17
+ * MathTemplated Node
18
+ */
19
+ export declare const MathTemplatedNode: Node<any, any>;
20
+ /**
21
+ * DragInTheBlank Node
22
+ */
23
+ export declare const DragInTheBlankNode: Node<any, any>;
24
+ /**
25
+ * InlineDropdown Node
26
+ */
27
+ export declare const InlineDropdownNode: Node<any, any>;
28
+ //# sourceMappingURL=responseArea.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"responseArea.d.ts","sourceRoot":"","sources":["../../src/extensions/responseArea.tsx"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAIH,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,IAAI,EAAyB,MAAM,eAAe,CAAC;AAsD5D,eAAO,MAAM,qBAAqB,qBAsKhC,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,+BAA+B,gBAoC1C,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,iBAAiB,gBAoC5B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,gBA0C7B,CAAC;AAEH;;GAEG;AACH,eAAO,MAAM,kBAAkB,gBAoC7B,CAAC"}
@@ -0,0 +1,259 @@
1
+ import e from "../components/respArea/ExplicitConstructedResponse.js";
2
+ import t from "../components/respArea/DragInTheBlank/DragInTheBlank.js";
3
+ import n from "../components/respArea/InlineDropdown.js";
4
+ import r from "../components/respArea/MathTemplated.js";
5
+ import "react";
6
+ import { Node as i, ReactNodeViewRenderer as a } from "@tiptap/react";
7
+ import { Extension as o } from "@tiptap/core";
8
+ import { NodeSelection as s, Plugin as c, PluginKey as l, TextSelection as u } from "prosemirror-state";
9
+ import { jsx as d } from "react/jsx-runtime";
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) => {
12
+ let n = [];
13
+ return e.descendants((e, r) => {
14
+ if (e.type && e.type.name === t) {
15
+ let t = m(e);
16
+ t != null && n.push({
17
+ index: t,
18
+ pos: r,
19
+ node: e
20
+ });
21
+ }
22
+ return !0;
23
+ }), n;
24
+ }, g = (e, t) => {
25
+ let n = 0;
26
+ return e.descendants((e) => (e.type && e.type.name === t && (n += 1), !0)), n;
27
+ }, _ = ({ schema: e, typeName: t, index: n }) => {
28
+ let r = e.nodes[t];
29
+ return r ? r.create({
30
+ index: String(n),
31
+ id: String(n),
32
+ value: ""
33
+ }) : null;
34
+ }, v = (e, t) => {
35
+ let n = e.resolve(Math.min(t, e.content.size));
36
+ return u.near(n, 1);
37
+ }, y = o.create({
38
+ name: "responseArea",
39
+ addOptions() {
40
+ return {
41
+ maxResponseAreas: null,
42
+ error: null,
43
+ options: null,
44
+ respAreaToolbar: null,
45
+ onHandleAreaChange: null
46
+ };
47
+ },
48
+ addProseMirrorPlugins() {
49
+ if (!this.options.type) return [];
50
+ let e = p(this.options.type);
51
+ return [new c({
52
+ 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);
59
+ }
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
+ } })
71
+ })];
72
+ },
73
+ addCommands() {
74
+ return {
75
+ insertResponseArea: (e) => ({ tr: t, state: n, dispatch: r, commands: i }) => {
76
+ let a = p(e);
77
+ if (g(n.doc, a) >= this.options.maxResponseAreas) return !1;
78
+ f[a] === void 0 && (f[a] = 0);
79
+ let o = f[a], c = o === 0 ? o : o + 1;
80
+ f[a] += 1;
81
+ let l = _({
82
+ schema: n.schema,
83
+ typeName: a,
84
+ index: c
85
+ });
86
+ if (!l) return !1;
87
+ let { selection: u } = n, d = u.from, m = (e) => {
88
+ try {
89
+ return t.insert(e, l), e;
90
+ } catch {
91
+ return null;
92
+ }
93
+ }, h = m(d);
94
+ if (h ??= m(t.doc.content.size), h == null) return !1;
95
+ if ([
96
+ "math_templated",
97
+ "inline_dropdown",
98
+ "explicit_constructed_response"
99
+ ].includes(a)) t.setSelection(s.create(t.doc, h));
100
+ else {
101
+ let e = h + l.nodeSize;
102
+ t.setSelection(v(t.doc, e));
103
+ }
104
+ return r && (i.focus(), r(t)), !0;
105
+ },
106
+ refreshResponseArea: () => ({ tr: e, state: t, commands: n, dispatch: r }) => {
107
+ let { selection: i } = t, a = i.$from.nodeAfter, o = i.from;
108
+ return e.setNodeMarkup(o, void 0, {
109
+ ...a?.attrs,
110
+ updated: `${Date.now()}`
111
+ }), e.setSelection(s.create(e.doc, o)), r && (n.focus(), r(e)), !0;
112
+ }
113
+ };
114
+ }
115
+ }), b = i.create({
116
+ name: "explicit_constructed_response",
117
+ group: "inline",
118
+ inline: !0,
119
+ atom: !0,
120
+ addAttributes() {
121
+ return {
122
+ index: { default: null },
123
+ value: { default: "" },
124
+ updated: { default: "" }
125
+ };
126
+ },
127
+ parseHTML() {
128
+ return [{
129
+ tag: "span[data-type=\"explicit_constructed_response\"]",
130
+ getAttrs: (e) => ({
131
+ index: e.dataset.index,
132
+ value: e.dataset.value
133
+ })
134
+ }];
135
+ },
136
+ renderHTML({ HTMLAttributes: e }) {
137
+ return ["span", {
138
+ "data-type": "explicit_constructed_response",
139
+ "data-index": e.index,
140
+ "data-value": e.value
141
+ }];
142
+ },
143
+ addNodeView() {
144
+ return a((t) => /* @__PURE__ */ d(e, {
145
+ ...t,
146
+ options: this.options
147
+ }));
148
+ }
149
+ }), x = i.create({
150
+ name: "math_templated",
151
+ group: "inline",
152
+ inline: !0,
153
+ atom: !0,
154
+ addAttributes() {
155
+ return {
156
+ index: { default: null },
157
+ value: { default: "" },
158
+ updated: { default: "" }
159
+ };
160
+ },
161
+ parseHTML() {
162
+ return [{
163
+ tag: "span[data-type=\"math_templated\"]",
164
+ getAttrs: (e) => ({
165
+ index: e.dataset.index,
166
+ value: e.dataset.value
167
+ })
168
+ }];
169
+ },
170
+ renderHTML({ HTMLAttributes: e }) {
171
+ return ["span", {
172
+ "data-type": "math_templated",
173
+ "data-index": e.index,
174
+ "data-value": e.value
175
+ }];
176
+ },
177
+ addNodeView() {
178
+ return a((e) => /* @__PURE__ */ d(r, {
179
+ ...e,
180
+ options: this.options
181
+ }));
182
+ }
183
+ }), S = i.create({
184
+ name: "drag_in_the_blank",
185
+ group: "inline",
186
+ inline: !0,
187
+ atom: !0,
188
+ addAttributes() {
189
+ return {
190
+ index: { default: null },
191
+ id: { default: null },
192
+ value: { default: "" },
193
+ inTable: { default: null },
194
+ updated: { default: "" }
195
+ };
196
+ },
197
+ parseHTML() {
198
+ return [{
199
+ tag: "span[data-type=\"drag_in_the_blank\"]",
200
+ getAttrs: (e) => ({
201
+ index: e.dataset.index,
202
+ id: e.dataset.id,
203
+ value: e.dataset.value,
204
+ inTable: e.dataset.inTable
205
+ })
206
+ }];
207
+ },
208
+ renderHTML({ HTMLAttributes: e }) {
209
+ return ["span", {
210
+ "data-type": "drag_in_the_blank",
211
+ "data-index": e.index,
212
+ "data-id": e.id,
213
+ "data-value": e.value,
214
+ "data-in-table": e.inTable
215
+ }];
216
+ },
217
+ addNodeView() {
218
+ return a((e) => /* @__PURE__ */ d(t, {
219
+ ...e,
220
+ options: this.options
221
+ }));
222
+ }
223
+ }), C = i.create({
224
+ name: "inline_dropdown",
225
+ group: "inline",
226
+ inline: !0,
227
+ atom: !0,
228
+ addAttributes() {
229
+ return {
230
+ index: { default: null },
231
+ value: { default: "" },
232
+ updated: { default: "" }
233
+ };
234
+ },
235
+ parseHTML() {
236
+ return [{
237
+ tag: "span[data-type=\"inline_dropdown\"]",
238
+ getAttrs: (e) => ({
239
+ index: e.dataset.index,
240
+ value: e.dataset.value
241
+ })
242
+ }];
243
+ },
244
+ renderHTML({ HTMLAttributes: e }) {
245
+ return ["span", {
246
+ "data-type": "inline_dropdown",
247
+ "data-index": e.index,
248
+ "data-value": e.value
249
+ }];
250
+ },
251
+ addNodeView() {
252
+ return a((e) => /* @__PURE__ */ d(n, {
253
+ ...e,
254
+ options: this.options
255
+ }));
256
+ }
257
+ });
258
+ //#endregion
259
+ export { S as DragInTheBlankNode, b as ExplicitConstructedResponseNode, C as InlineDropdownNode, x as MathTemplatedNode, y as ResponseAreaExtension };
@@ -0,0 +1,13 @@
1
+ /**
2
+ * @synced-from pie-lib/packages/editable-html-tip-tap/src/index.jsx
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
+ import StyledEditor, { EditableHtml } from './components/EditableHtml.js';
10
+ import { ALL_PLUGINS, DEFAULT_PLUGINS } from './extensions/index.js';
11
+ export { EditableHtml, ALL_PLUGINS, DEFAULT_PLUGINS };
12
+ export default StyledEditor;
13
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.tsx"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,YAAY,EAAE,EAAE,YAAY,EAAE,MAAM,8BAA8B,CAAC;AAC1E,OAAO,EAAE,WAAW,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,WAAW,EAAE,eAAe,EAAE,CAAC;AACtD,eAAe,YAAY,CAAC"}
package/dist/index.js ADDED
@@ -0,0 +1,6 @@
1
+ import { ALL_PLUGINS as e, DEFAULT_PLUGINS as t } from "./extensions/index.js";
2
+ import n from "./components/EditableHtml.js";
3
+ //#region src/index.tsx
4
+ var r = n;
5
+ //#endregion
6
+ export { e as ALL_PLUGINS, t as DEFAULT_PLUGINS, n as EditableHtml, r as default };