@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.
- package/dist/components/CharacterPicker.d.ts +31 -0
- package/dist/components/CharacterPicker.d.ts.map +1 -0
- package/dist/components/CharacterPicker.js +129 -0
- package/dist/components/EditableHtml.d.ts +11 -0
- package/dist/components/EditableHtml.d.ts.map +1 -0
- package/dist/components/EditableHtml.js +270 -0
- package/dist/components/MenuBar.d.ts +11 -0
- package/dist/components/MenuBar.d.ts.map +1 -0
- package/dist/components/MenuBar.js +460 -0
- package/dist/components/TiptapContainer.d.ts +11 -0
- package/dist/components/TiptapContainer.d.ts.map +1 -0
- package/dist/components/TiptapContainer.js +157 -0
- package/dist/components/characters/characterUtils.d.ts +36 -0
- package/dist/components/characters/characterUtils.d.ts.map +1 -0
- package/dist/components/characters/characterUtils.js +465 -0
- package/dist/components/characters/custom-popper.d.ts +14 -0
- package/dist/components/characters/custom-popper.d.ts.map +1 -0
- package/dist/components/characters/custom-popper.js +32 -0
- package/dist/components/common/done-button.d.ts +30 -0
- package/dist/components/common/done-button.d.ts.map +1 -0
- package/dist/components/common/done-button.js +26 -0
- package/dist/components/common/toolbar-buttons.d.ts +39 -0
- package/dist/components/common/toolbar-buttons.d.ts.map +1 -0
- package/dist/components/common/toolbar-buttons.js +91 -0
- package/dist/components/icons/CssIcon.d.ts +11 -0
- package/dist/components/icons/CssIcon.d.ts.map +1 -0
- package/dist/components/icons/CssIcon.js +14 -0
- package/dist/components/icons/RespArea.d.ts +26 -0
- package/dist/components/icons/RespArea.d.ts.map +1 -0
- package/dist/components/icons/RespArea.js +42 -0
- package/dist/components/icons/TableIcons.d.ts +14 -0
- package/dist/components/icons/TableIcons.d.ts.map +1 -0
- package/dist/components/icons/TableIcons.js +32 -0
- package/dist/components/icons/TextAlign.d.ts +18 -0
- package/dist/components/icons/TextAlign.d.ts.map +1 -0
- package/dist/components/icons/TextAlign.js +134 -0
- package/dist/components/image/AltDialog.d.ts +23 -0
- package/dist/components/image/AltDialog.d.ts.map +1 -0
- package/dist/components/image/AltDialog.js +61 -0
- package/dist/components/image/ImageToolbar.d.ts +25 -0
- package/dist/components/image/ImageToolbar.d.ts.map +1 -0
- package/dist/components/image/ImageToolbar.js +80 -0
- package/dist/components/image/InsertImageHandler.d.ts +33 -0
- package/dist/components/image/InsertImageHandler.d.ts.map +1 -0
- package/dist/components/image/InsertImageHandler.js +55 -0
- package/dist/components/media/MediaDialog.d.ts +44 -0
- package/dist/components/media/MediaDialog.d.ts.map +1 -0
- package/dist/components/media/MediaDialog.js +389 -0
- package/dist/components/media/MediaToolbar.d.ts +20 -0
- package/dist/components/media/MediaToolbar.d.ts.map +1 -0
- package/dist/components/media/MediaToolbar.js +41 -0
- package/dist/components/media/MediaWrapper.d.ts +20 -0
- package/dist/components/media/MediaWrapper.d.ts.map +1 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts +23 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.d.ts.map +1 -0
- package/dist/components/respArea/DragInTheBlank/DragInTheBlank.js +58 -0
- package/dist/components/respArea/DragInTheBlank/choice.d.ts +56 -0
- package/dist/components/respArea/DragInTheBlank/choice.d.ts.map +1 -0
- package/dist/components/respArea/DragInTheBlank/choice.js +156 -0
- package/dist/components/respArea/ExplicitConstructedResponse.d.ts +20 -0
- package/dist/components/respArea/ExplicitConstructedResponse.d.ts.map +1 -0
- package/dist/components/respArea/ExplicitConstructedResponse.js +67 -0
- package/dist/components/respArea/InlineDropdown.d.ts +18 -0
- package/dist/components/respArea/InlineDropdown.d.ts.map +1 -0
- package/dist/components/respArea/InlineDropdown.js +91 -0
- package/dist/components/respArea/MathTemplated.d.ts +19 -0
- package/dist/components/respArea/MathTemplated.d.ts.map +1 -0
- package/dist/components/respArea/MathTemplated.js +97 -0
- package/dist/components/respArea/ToolbarIcon.d.ts +14 -0
- package/dist/components/respArea/ToolbarIcon.d.ts.map +1 -0
- package/dist/components/respArea/ToolbarIcon.js +17 -0
- package/dist/constants.d.ts +14 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +4 -0
- package/dist/extensions/css.d.ts +12 -0
- package/dist/extensions/css.d.ts.map +1 -0
- package/dist/extensions/css.js +115 -0
- package/dist/extensions/custom-toolbar-wrapper.d.ts +11 -0
- package/dist/extensions/custom-toolbar-wrapper.d.ts.map +1 -0
- package/dist/extensions/custom-toolbar-wrapper.js +58 -0
- package/dist/extensions/div-node.d.ts +11 -0
- package/dist/extensions/div-node.d.ts.map +1 -0
- package/dist/extensions/div-node.js +25 -0
- package/dist/extensions/extended-table.d.ts +11 -0
- package/dist/extensions/extended-table.d.ts.map +1 -0
- package/dist/extensions/extended-table.js +15 -0
- package/dist/extensions/image-component.d.ts +22 -0
- package/dist/extensions/image-component.d.ts.map +1 -0
- package/dist/extensions/image-component.js +200 -0
- package/dist/extensions/image.d.ts +11 -0
- package/dist/extensions/image.d.ts.map +1 -0
- package/dist/extensions/image.js +42 -0
- package/dist/extensions/index.d.ts +17 -0
- package/dist/extensions/index.d.ts.map +1 -0
- package/dist/extensions/index.js +65 -0
- package/dist/extensions/math.d.ts +15 -0
- package/dist/extensions/math.d.ts.map +1 -0
- package/dist/extensions/math.js +150 -0
- package/dist/extensions/media.d.ts +19 -0
- package/dist/extensions/media.d.ts.map +1 -0
- package/dist/extensions/media.js +147 -0
- package/dist/extensions/responseArea.d.ts +28 -0
- package/dist/extensions/responseArea.d.ts.map +1 -0
- package/dist/extensions/responseArea.js +259 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +6 -0
- package/dist/styles/editorContainerStyles.d.ts +135 -0
- package/dist/styles/editorContainerStyles.d.ts.map +1 -0
- package/dist/theme.d.ts +10 -0
- package/dist/theme.d.ts.map +1 -0
- package/dist/utils/helper.d.ts +10 -0
- package/dist/utils/helper.d.ts.map +1 -0
- package/dist/utils/helper.js +7 -0
- package/dist/utils/size.d.ts +10 -0
- package/dist/utils/size.d.ts.map +1 -0
- package/dist/utils/size.js +14 -0
- package/package.json +71 -0
- package/src/components/CharacterPicker.tsx +210 -0
- package/src/components/EditableHtml.tsx +416 -0
- package/src/components/MenuBar.tsx +558 -0
- package/src/components/TiptapContainer.tsx +228 -0
- package/src/components/characters/characterUtils.ts +457 -0
- package/src/components/characters/custom-popper.tsx +48 -0
- package/src/components/common/done-button.tsx +37 -0
- package/src/components/common/toolbar-buttons.tsx +132 -0
- package/src/components/icons/CssIcon.tsx +25 -0
- package/src/components/icons/RespArea.tsx +81 -0
- package/src/components/icons/TableIcons.tsx +62 -0
- package/src/components/icons/TextAlign.tsx +124 -0
- package/src/components/image/AltDialog.tsx +92 -0
- package/src/components/image/ImageToolbar.tsx +109 -0
- package/src/components/image/InsertImageHandler.ts +121 -0
- package/src/components/media/MediaDialog.tsx +606 -0
- package/src/components/media/MediaToolbar.tsx +59 -0
- package/src/components/media/MediaWrapper.tsx +49 -0
- package/src/components/respArea/DragInTheBlank/DragInTheBlank.tsx +86 -0
- package/src/components/respArea/DragInTheBlank/choice.tsx +266 -0
- package/src/components/respArea/ExplicitConstructedResponse.tsx +122 -0
- package/src/components/respArea/InlineDropdown.tsx +152 -0
- package/src/components/respArea/MathTemplated.tsx +134 -0
- package/src/components/respArea/ToolbarIcon.tsx +76 -0
- package/src/constants.ts +15 -0
- package/src/extensions/css.tsx +230 -0
- package/src/extensions/custom-toolbar-wrapper.tsx +88 -0
- package/src/extensions/div-node.tsx +46 -0
- package/src/extensions/extended-table.ts +34 -0
- package/src/extensions/image-component.tsx +303 -0
- package/src/extensions/image.tsx +64 -0
- package/src/extensions/index.tsx +91 -0
- package/src/extensions/math.tsx +285 -0
- package/src/extensions/media.tsx +198 -0
- package/src/extensions/responseArea.tsx +404 -0
- package/src/index.tsx +15 -0
- package/src/styles/editorContainerStyles.ts +155 -0
- package/src/theme.ts +11 -0
- package/src/utils/helper.tsx +27 -0
- package/src/utils/size.ts +42 -0
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/styles/editorContainerStyles.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
|
+
declare const styles: (theme: any) => {
|
|
10
|
+
root: {
|
|
11
|
+
position: string;
|
|
12
|
+
padding: string;
|
|
13
|
+
border: string;
|
|
14
|
+
borderRadius: string;
|
|
15
|
+
cursor: string;
|
|
16
|
+
'& [data-slate-editor="true"]': {
|
|
17
|
+
wordBreak: string;
|
|
18
|
+
overflow: string;
|
|
19
|
+
maxHeight: string;
|
|
20
|
+
padding: string;
|
|
21
|
+
};
|
|
22
|
+
'&:first-child': {
|
|
23
|
+
marginTop: number;
|
|
24
|
+
};
|
|
25
|
+
'& ul, & ol': {
|
|
26
|
+
padding: string;
|
|
27
|
+
margin: string;
|
|
28
|
+
};
|
|
29
|
+
'& ul li p, & ol li p': {
|
|
30
|
+
marginTop: string;
|
|
31
|
+
marginBottom: string;
|
|
32
|
+
};
|
|
33
|
+
'& h1, & h2, & h3, & h4, & h5, & h6': {
|
|
34
|
+
lineHeight: number;
|
|
35
|
+
marginTop: string;
|
|
36
|
+
textWrap: string;
|
|
37
|
+
};
|
|
38
|
+
'& h1, & h2': {
|
|
39
|
+
marginTop: string;
|
|
40
|
+
marginBottom: string;
|
|
41
|
+
};
|
|
42
|
+
'& h1': {
|
|
43
|
+
fontSize: string;
|
|
44
|
+
};
|
|
45
|
+
'& h2': {
|
|
46
|
+
fontSize: string;
|
|
47
|
+
};
|
|
48
|
+
'& h3': {
|
|
49
|
+
fontSize: string;
|
|
50
|
+
};
|
|
51
|
+
'& h4, & h5, & h6': {
|
|
52
|
+
fontSize: string;
|
|
53
|
+
};
|
|
54
|
+
'& code': {
|
|
55
|
+
backgroundColor: string;
|
|
56
|
+
borderRadius: string;
|
|
57
|
+
color: string;
|
|
58
|
+
fontSize: string;
|
|
59
|
+
padding: string;
|
|
60
|
+
};
|
|
61
|
+
'& pre': {
|
|
62
|
+
background: string;
|
|
63
|
+
borderRadius: string;
|
|
64
|
+
color: string;
|
|
65
|
+
fontFamily: string;
|
|
66
|
+
margin: string;
|
|
67
|
+
padding: string;
|
|
68
|
+
'& code': {
|
|
69
|
+
background: string;
|
|
70
|
+
color: string;
|
|
71
|
+
fontSize: string;
|
|
72
|
+
padding: number;
|
|
73
|
+
};
|
|
74
|
+
};
|
|
75
|
+
'& blockquote': {
|
|
76
|
+
background: string;
|
|
77
|
+
borderLeft: string;
|
|
78
|
+
margin: string;
|
|
79
|
+
padding: string;
|
|
80
|
+
};
|
|
81
|
+
'& hr': {
|
|
82
|
+
border: string;
|
|
83
|
+
borderTop: string;
|
|
84
|
+
margin: string;
|
|
85
|
+
};
|
|
86
|
+
'& table': {
|
|
87
|
+
tableLayout: string;
|
|
88
|
+
width: string;
|
|
89
|
+
borderCollapse: string;
|
|
90
|
+
color: any;
|
|
91
|
+
backgroundColor: any;
|
|
92
|
+
};
|
|
93
|
+
'& table:not([border="1"]) tr': {
|
|
94
|
+
borderTop: string;
|
|
95
|
+
};
|
|
96
|
+
'& td, th': {
|
|
97
|
+
padding: string;
|
|
98
|
+
textAlign: string;
|
|
99
|
+
};
|
|
100
|
+
'& table:not([border="1"]) td, th': {
|
|
101
|
+
border: string;
|
|
102
|
+
};
|
|
103
|
+
};
|
|
104
|
+
children: {
|
|
105
|
+
padding: string;
|
|
106
|
+
};
|
|
107
|
+
editorHolder: {
|
|
108
|
+
position: string;
|
|
109
|
+
padding: string;
|
|
110
|
+
overflowY: string;
|
|
111
|
+
color: any;
|
|
112
|
+
backgroundColor: any;
|
|
113
|
+
};
|
|
114
|
+
disabledScrollbar: {
|
|
115
|
+
'&::-webkit-scrollbar': {
|
|
116
|
+
display: string;
|
|
117
|
+
};
|
|
118
|
+
scrollbarWidth: string;
|
|
119
|
+
'-ms-overflow-style': string;
|
|
120
|
+
};
|
|
121
|
+
error: {
|
|
122
|
+
border: string;
|
|
123
|
+
};
|
|
124
|
+
noBorder: {
|
|
125
|
+
border: string;
|
|
126
|
+
};
|
|
127
|
+
noPadding: {
|
|
128
|
+
padding: number;
|
|
129
|
+
};
|
|
130
|
+
toolbarOnTop: {
|
|
131
|
+
marginTop: string;
|
|
132
|
+
};
|
|
133
|
+
};
|
|
134
|
+
export default styles;
|
|
135
|
+
//# sourceMappingURL=editorContainerStyles.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"editorContainerStyles.d.ts","sourceRoot":"","sources":["../../src/styles/editorContainerStyles.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAIH,QAAA,MAAM,MAAM,GAAI,UAAK;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4InB,CAAC;AAEH,eAAe,MAAM,CAAC"}
|
package/dist/theme.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/theme.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 primary = "#304ffe";
|
|
10
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../src/theme.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,eAAO,MAAM,OAAO,YAAY,CAAC"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/utils/helper.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 normalizeInitialMarkup: (markup: any) => string;
|
|
10
|
+
//# sourceMappingURL=helper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"helper.d.ts","sourceRoot":"","sources":["../../src/utils/helper.tsx"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAUH,eAAO,MAAM,sBAAsB,GAAI,WAAM,WAQ5C,CAAC"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
//#region src/utils/helper.tsx
|
|
2
|
+
var e = (e) => String(e).replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'"), t = (t) => {
|
|
3
|
+
let n = String(t ?? "").trim();
|
|
4
|
+
return n ? /<[^>]+>/.test(n) ? n : `<div>${e(n)}</div>` : "<div></div>";
|
|
5
|
+
};
|
|
6
|
+
//#endregion
|
|
7
|
+
export { t as normalizeInitialMarkup };
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/utils/size.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 valueToSize: (v: any) => string | number | undefined;
|
|
10
|
+
//# sourceMappingURL=size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../src/utils/size.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,eAAO,MAAM,WAAW,GAAI,MAAC,gCA+B5B,CAAC"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/utils/size.ts
|
|
2
|
+
var e = (e) => {
|
|
3
|
+
if (!e) return;
|
|
4
|
+
let t = /^calc\((.*)\)$/;
|
|
5
|
+
if (typeof e == "string") {
|
|
6
|
+
if (e.endsWith("%")) return;
|
|
7
|
+
if (e.endsWith("px") || e.endsWith("vh") || e.endsWith("vw") || e.endsWith("ch") || e.endsWith("em") || e.match(t)) return e;
|
|
8
|
+
let n = parseInt(e, 10);
|
|
9
|
+
return Number.isNaN(n) ? n : `${n}px`;
|
|
10
|
+
}
|
|
11
|
+
if (typeof e == "number") return `${e}px`;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { e as valueToSize };
|
package/package.json
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pie-lib/editable-html-tip-tap",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"@dnd-kit/core": "6.3.1",
|
|
7
|
+
"@dnd-kit/modifiers": "9.0.0",
|
|
8
|
+
"@dnd-kit/utilities": "3.2.2",
|
|
9
|
+
"@mui/icons-material": "^7.3.4",
|
|
10
|
+
"@mui/material": "^7.3.4",
|
|
11
|
+
"@pie-lib/drag": "0.1.0",
|
|
12
|
+
"@pie-lib/math-input": "0.1.0",
|
|
13
|
+
"@pie-lib/math-rendering": "0.1.0",
|
|
14
|
+
"@pie-lib/math-toolbar": "0.1.0",
|
|
15
|
+
"@pie-lib/render-ui": "0.1.0",
|
|
16
|
+
"@tiptap/core": "3.0.9",
|
|
17
|
+
"@tiptap/extension-character-count": "3.0.9",
|
|
18
|
+
"@tiptap/extension-color": "3.0.9",
|
|
19
|
+
"@tiptap/extension-image": "3.0.9",
|
|
20
|
+
"@tiptap/extension-list-item": "3.0.9",
|
|
21
|
+
"@tiptap/extension-placeholder": "3.20.0",
|
|
22
|
+
"@tiptap/extension-subscript": "3.0.9",
|
|
23
|
+
"@tiptap/extension-superscript": "3.0.9",
|
|
24
|
+
"@tiptap/extension-table": "3.0.9",
|
|
25
|
+
"@tiptap/extension-table-cell": "3.0.9",
|
|
26
|
+
"@tiptap/extension-table-header": "3.0.9",
|
|
27
|
+
"@tiptap/extension-table-row": "3.0.9",
|
|
28
|
+
"@tiptap/extension-text-align": "3.0.9",
|
|
29
|
+
"@tiptap/extension-text-style": "3.0.9",
|
|
30
|
+
"@tiptap/pm": "3.0.9",
|
|
31
|
+
"@tiptap/react": "3.0.9",
|
|
32
|
+
"@tiptap/starter-kit": "3.0.9",
|
|
33
|
+
"change-case": "^3.0.2",
|
|
34
|
+
"classnames": "^2.2.6",
|
|
35
|
+
"debug": "^4.1.1",
|
|
36
|
+
"immutable": "^4.0.0-rc.12",
|
|
37
|
+
"keycode": "^2.2.0",
|
|
38
|
+
"lodash-es": "^4.17.23",
|
|
39
|
+
"prop-types": "^15.6.2",
|
|
40
|
+
"react-attr-converter": "^0.3.1",
|
|
41
|
+
"react-jss": "^8.6.1",
|
|
42
|
+
"react-portal": "^4.2.0",
|
|
43
|
+
"tippy.js": "latest",
|
|
44
|
+
"to-style": "^1.3.3",
|
|
45
|
+
"@pie-element/shared-math-rendering-mathjax": "0.1.0",
|
|
46
|
+
"@tiptap/extensions": "^3.20.0",
|
|
47
|
+
"@tiptap/extension-list": "3.0.9",
|
|
48
|
+
"prosemirror-state": "^1.4.4",
|
|
49
|
+
"react": "^18.2.0",
|
|
50
|
+
"react-dom": "^18.2.0"
|
|
51
|
+
},
|
|
52
|
+
"type": "module",
|
|
53
|
+
"main": "./dist/index.js",
|
|
54
|
+
"types": "./dist/index.d.ts",
|
|
55
|
+
"exports": {
|
|
56
|
+
".": {
|
|
57
|
+
"types": "./dist/index.d.ts",
|
|
58
|
+
"default": "./dist/index.js"
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
"files": [
|
|
62
|
+
"dist",
|
|
63
|
+
"src"
|
|
64
|
+
],
|
|
65
|
+
"sideEffects": false,
|
|
66
|
+
"scripts": {
|
|
67
|
+
"build": "bun x vite build && bun x tsc --emitDeclarationOnly",
|
|
68
|
+
"dev": "bun x vite",
|
|
69
|
+
"test": "bun x vitest run"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
@@ -0,0 +1,210 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/components/CharacterPicker.jsx
|
|
4
|
+
* @auto-generated
|
|
5
|
+
*
|
|
6
|
+
* This file is automatically synced from pie-elements and converted to TypeScript.
|
|
7
|
+
* Manual edits will be overwritten on next sync.
|
|
8
|
+
* To make changes, edit the upstream JavaScript file and run sync again.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
import React, { useEffect, useMemo, useRef, useState } from 'react';
|
|
12
|
+
import ReactDOM from 'react-dom';
|
|
13
|
+
import PropTypes from 'prop-types';
|
|
14
|
+
import get from 'lodash-es/get.js';
|
|
15
|
+
|
|
16
|
+
import { PureToolbar } from '@pie-lib/math-toolbar';
|
|
17
|
+
|
|
18
|
+
import CustomPopper from './characters/custom-popper.js';
|
|
19
|
+
import { spanishConfig, specialConfig } from './characters/characterUtils.js';
|
|
20
|
+
|
|
21
|
+
const CharacterIcon = ({ letter }) => (
|
|
22
|
+
<div
|
|
23
|
+
style={{
|
|
24
|
+
fontSize: '24px',
|
|
25
|
+
lineHeight: '24px',
|
|
26
|
+
}}
|
|
27
|
+
>
|
|
28
|
+
{letter}
|
|
29
|
+
</div>
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
CharacterIcon.propTypes = {
|
|
33
|
+
letter: PropTypes.string,
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
export function CharacterPicker({ editor, opts, onClose }) {
|
|
37
|
+
if (!opts?.characters?.length) {
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const containerRef = useRef(null);
|
|
42
|
+
const [position, setPosition] = useState({ top: 0, left: 0 });
|
|
43
|
+
const [popover, setPopover] = useState(null);
|
|
44
|
+
|
|
45
|
+
const configToUse = useMemo(() => {
|
|
46
|
+
if (!opts) return spanishConfig;
|
|
47
|
+
|
|
48
|
+
switch (true) {
|
|
49
|
+
case opts.language === 'spanish':
|
|
50
|
+
return spanishConfig;
|
|
51
|
+
case opts.language === 'special':
|
|
52
|
+
return specialConfig;
|
|
53
|
+
default:
|
|
54
|
+
return opts;
|
|
55
|
+
}
|
|
56
|
+
}, [opts]);
|
|
57
|
+
|
|
58
|
+
const layoutForCharacters = useMemo(
|
|
59
|
+
() =>
|
|
60
|
+
configToUse.characters.reduce(
|
|
61
|
+
(obj, arr) => {
|
|
62
|
+
if (arr.length >= obj.columns) {
|
|
63
|
+
obj.columns = arr.length;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return obj;
|
|
67
|
+
},
|
|
68
|
+
{ rows: configToUse.characters.length, columns: 0 },
|
|
69
|
+
),
|
|
70
|
+
[configToUse],
|
|
71
|
+
);
|
|
72
|
+
|
|
73
|
+
const closePopOver = () => setPopover(null);
|
|
74
|
+
|
|
75
|
+
useEffect(
|
|
76
|
+
() => () => {
|
|
77
|
+
closePopOver();
|
|
78
|
+
},
|
|
79
|
+
[],
|
|
80
|
+
);
|
|
81
|
+
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
if (!editor) return;
|
|
84
|
+
|
|
85
|
+
// Calculate position relative to selection
|
|
86
|
+
const editorDOM = editor.options.element;
|
|
87
|
+
const editorRect = editorDOM.getBoundingClientRect();
|
|
88
|
+
const bodyRect = document.body.getBoundingClientRect();
|
|
89
|
+
const { from } = editor.state.selection;
|
|
90
|
+
const start = editor.view.coordsAtPos(from);
|
|
91
|
+
|
|
92
|
+
let top = editorRect.top + Math.abs(bodyRect.top) + editorRect.height + 60;
|
|
93
|
+
|
|
94
|
+
if (editorRect.y > containerRef.current.offsetHeight) {
|
|
95
|
+
top = top - (containerRef.current.offsetHeight + editorRect.height) - 80;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
setPosition({
|
|
99
|
+
// top: start.top + Math.abs(bodyRect.top) - containerRef.current.offsetHeight - 10 + additionalTopOffset, // shift above
|
|
100
|
+
top: top,
|
|
101
|
+
left: start.left,
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
const handleClickOutside = (e) => {
|
|
105
|
+
if (containerRef.current && !containerRef.current.contains(e.target) && !editor.view.dom.contains(e.target)) {
|
|
106
|
+
onClose();
|
|
107
|
+
}
|
|
108
|
+
};
|
|
109
|
+
|
|
110
|
+
const timeoutId = setTimeout(() => {
|
|
111
|
+
document.addEventListener('click', handleClickOutside);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
return () => {
|
|
115
|
+
clearTimeout(timeoutId);
|
|
116
|
+
document.removeEventListener('click', handleClickOutside);
|
|
117
|
+
};
|
|
118
|
+
}, [editor, onClose]);
|
|
119
|
+
|
|
120
|
+
const renderPopOver = (event, el) => setPopover({ anchorEl: event.currentTarget, el });
|
|
121
|
+
|
|
122
|
+
const handleChange = (val) => {
|
|
123
|
+
if (typeof val === 'string') {
|
|
124
|
+
editor.chain().focus().insertContent(val).run();
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<>
|
|
130
|
+
{ReactDOM.createPortal(
|
|
131
|
+
<div
|
|
132
|
+
ref={containerRef}
|
|
133
|
+
className="insert-character-dialog"
|
|
134
|
+
data-toolbar-for={editor.instanceId}
|
|
135
|
+
style={{
|
|
136
|
+
visibility: position.top === 0 && position.left === 0 ? 'hidden' : 'initial',
|
|
137
|
+
position: 'absolute',
|
|
138
|
+
top: `${position.top}px`,
|
|
139
|
+
left: `${position.left}px`,
|
|
140
|
+
maxWidth: '500px',
|
|
141
|
+
zIndex: 99,
|
|
142
|
+
}}
|
|
143
|
+
>
|
|
144
|
+
<div>
|
|
145
|
+
<PureToolbar
|
|
146
|
+
keyPadCharacterRef={opts.keyPadCharacterRef}
|
|
147
|
+
setKeypadInteraction={opts.setKeypadInteraction}
|
|
148
|
+
autoFocus
|
|
149
|
+
noDecimal
|
|
150
|
+
hideInput
|
|
151
|
+
noLatexHandling
|
|
152
|
+
hideDoneButtonBackground
|
|
153
|
+
layoutForKeyPad={layoutForCharacters}
|
|
154
|
+
additionalKeys={configToUse.characters.reduce((arr, n) => {
|
|
155
|
+
arr = [
|
|
156
|
+
...arr,
|
|
157
|
+
...n.map((k) => ({
|
|
158
|
+
name: get(k, 'name') || k,
|
|
159
|
+
write: get(k, 'write') || k,
|
|
160
|
+
label: get(k, 'label') || k,
|
|
161
|
+
category: 'character',
|
|
162
|
+
extraClass: 'character',
|
|
163
|
+
extraProps: {
|
|
164
|
+
...(k.extraProps || {}),
|
|
165
|
+
style: {
|
|
166
|
+
...(k.extraProps || {}).style,
|
|
167
|
+
border: '1px solid #000',
|
|
168
|
+
},
|
|
169
|
+
},
|
|
170
|
+
...(configToUse.hasPreview
|
|
171
|
+
? {
|
|
172
|
+
actions: {
|
|
173
|
+
onMouseEnter: (ev) => renderPopOver(ev, k),
|
|
174
|
+
onMouseLeave: closePopOver,
|
|
175
|
+
},
|
|
176
|
+
}
|
|
177
|
+
: {}),
|
|
178
|
+
})),
|
|
179
|
+
];
|
|
180
|
+
|
|
181
|
+
return arr;
|
|
182
|
+
}, [])}
|
|
183
|
+
keypadMode="language"
|
|
184
|
+
onChange={handleChange}
|
|
185
|
+
onDone={onClose}
|
|
186
|
+
/>
|
|
187
|
+
</div>
|
|
188
|
+
</div>,
|
|
189
|
+
document.body,
|
|
190
|
+
)}
|
|
191
|
+
{popover &&
|
|
192
|
+
ReactDOM.createPortal(
|
|
193
|
+
<CustomPopper onClose={closePopOver} anchorEl={popover.anchorEl}>
|
|
194
|
+
<div>{popover.el.label}</div>
|
|
195
|
+
<div style={{ fontSize: 20, lineHeight: '20px' }}>{popover.el.description}</div>
|
|
196
|
+
<div style={{ fontSize: 20, lineHeight: '20px' }}>{popover.el.unicode}</div>
|
|
197
|
+
</CustomPopper>,
|
|
198
|
+
document.body,
|
|
199
|
+
)}
|
|
200
|
+
</>
|
|
201
|
+
);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
CharacterPicker.propTypes = {
|
|
205
|
+
editor: PropTypes.object,
|
|
206
|
+
opts: PropTypes.object,
|
|
207
|
+
onClose: PropTypes.func.isRequired,
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
export { CharacterIcon };
|