@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,404 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/extensions/responseArea.js
|
|
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 from 'react';
|
|
12
|
+
import { NodeSelection, Plugin, PluginKey, TextSelection } from 'prosemirror-state';
|
|
13
|
+
import { Extension } from '@tiptap/core';
|
|
14
|
+
import { Node, ReactNodeViewRenderer } from '@tiptap/react';
|
|
15
|
+
import ExplicitConstructedResponse from '../components/respArea/ExplicitConstructedResponse.js';
|
|
16
|
+
import DragInTheBlank from '../components/respArea/DragInTheBlank/DragInTheBlank.js';
|
|
17
|
+
import InlineDropdown from '../components/respArea/InlineDropdown.js';
|
|
18
|
+
import MathTemplated from '../components/respArea/MathTemplated.js';
|
|
19
|
+
|
|
20
|
+
const lastIndexMap = {};
|
|
21
|
+
|
|
22
|
+
const normalizeType = (type) => String(type || '').replace(/-/g, '_');
|
|
23
|
+
|
|
24
|
+
const getAttrIndex = (node) => (node && node.attrs && node.attrs.index != null ? String(node.attrs.index) : null);
|
|
25
|
+
|
|
26
|
+
const collectNodesOfType = (doc, typeName) => {
|
|
27
|
+
const results = [];
|
|
28
|
+
|
|
29
|
+
doc.descendants((node, pos) => {
|
|
30
|
+
if (node.type && node.type.name === typeName) {
|
|
31
|
+
const index = getAttrIndex(node);
|
|
32
|
+
if (index != null) results.push({ index, pos, node });
|
|
33
|
+
}
|
|
34
|
+
return true;
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
return results;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const countNodesOfType = (doc, typeName) => {
|
|
41
|
+
let count = 0;
|
|
42
|
+
doc.descendants((node) => {
|
|
43
|
+
if (node.type && node.type.name === typeName) count += 1;
|
|
44
|
+
return true;
|
|
45
|
+
});
|
|
46
|
+
return count;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const getDefaultNode = ({ schema, typeName, index }) => {
|
|
50
|
+
const nodeType = schema.nodes[typeName];
|
|
51
|
+
if (!nodeType) return null;
|
|
52
|
+
|
|
53
|
+
// mirror your Slate "getDefaultElement(opts, newIndex)"
|
|
54
|
+
// customize attrs as needed:
|
|
55
|
+
return nodeType.create({
|
|
56
|
+
index: String(index),
|
|
57
|
+
id: String(index),
|
|
58
|
+
value: '',
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
// Find a good cursor position *after* an inserted node.
|
|
63
|
+
const selectionAfterPos = (doc, pos) => {
|
|
64
|
+
const $pos = doc.resolve(Math.min(pos, doc.content.size));
|
|
65
|
+
return TextSelection.near($pos, 1);
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
export const ResponseAreaExtension = Extension.create({
|
|
69
|
+
name: 'responseArea',
|
|
70
|
+
|
|
71
|
+
addOptions() {
|
|
72
|
+
return {
|
|
73
|
+
maxResponseAreas: null,
|
|
74
|
+
error: null,
|
|
75
|
+
options: null,
|
|
76
|
+
respAreaToolbar: null,
|
|
77
|
+
onHandleAreaChange: null,
|
|
78
|
+
};
|
|
79
|
+
},
|
|
80
|
+
|
|
81
|
+
addProseMirrorPlugins() {
|
|
82
|
+
if (!this.options.type) {
|
|
83
|
+
return [];
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
const typeName = normalizeType(this.options.type);
|
|
87
|
+
const key = new PluginKey(`response-area-watcher:${typeName}`);
|
|
88
|
+
|
|
89
|
+
return [
|
|
90
|
+
new Plugin({
|
|
91
|
+
key,
|
|
92
|
+
|
|
93
|
+
view: (view) => {
|
|
94
|
+
// Lazy init lastIndexMap[typeName]
|
|
95
|
+
if (lastIndexMap[typeName] === undefined) {
|
|
96
|
+
lastIndexMap[typeName] = 0;
|
|
97
|
+
|
|
98
|
+
view.state.doc.descendants((node) => {
|
|
99
|
+
if (node.type && node.type.name === typeName) {
|
|
100
|
+
const idx = getAttrIndex(node);
|
|
101
|
+
if (idx != null) {
|
|
102
|
+
const n = parseInt(idx, 10);
|
|
103
|
+
if (!Number.isNaN(n) && n > lastIndexMap[typeName]) {
|
|
104
|
+
lastIndexMap[typeName] = n;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
return true;
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
return {
|
|
113
|
+
update: (view, prevState) => {
|
|
114
|
+
const state = view.state;
|
|
115
|
+
if (prevState.doc.eq(state.doc)) return;
|
|
116
|
+
|
|
117
|
+
const currentList = collectNodesOfType(state.doc, typeName);
|
|
118
|
+
const oldList = collectNodesOfType(prevState.doc, typeName);
|
|
119
|
+
|
|
120
|
+
if (this.options.toolbar) {
|
|
121
|
+
this.options.toolbar.disabled = currentList.length >= this.options.maxResponseAreas;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// Removed elements (same logic as Slate)
|
|
125
|
+
if (oldList.length > currentList.length) {
|
|
126
|
+
const currentIndexSet = new Set(currentList.map((x) => x.index));
|
|
127
|
+
|
|
128
|
+
const removed = oldList.filter((x) => !currentIndexSet.has(x.index));
|
|
129
|
+
|
|
130
|
+
if (removed.length && typeof this.options.onHandleAreaChange === 'function') {
|
|
131
|
+
this.options.onHandleAreaChange(removed);
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
};
|
|
136
|
+
},
|
|
137
|
+
}),
|
|
138
|
+
];
|
|
139
|
+
},
|
|
140
|
+
|
|
141
|
+
addCommands() {
|
|
142
|
+
return {
|
|
143
|
+
insertResponseArea:
|
|
144
|
+
(type) =>
|
|
145
|
+
({ tr, state, dispatch, commands }) => {
|
|
146
|
+
const typeName = normalizeType(type);
|
|
147
|
+
|
|
148
|
+
// --- Slate: currentRespAreaList + max check ---
|
|
149
|
+
const currentCount = countNodesOfType(state.doc, typeName);
|
|
150
|
+
if (currentCount >= this.options.maxResponseAreas) {
|
|
151
|
+
return false;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// --- Slate: indexing logic (kept identical) ---
|
|
155
|
+
if (lastIndexMap[typeName] === undefined) lastIndexMap[typeName] = 0;
|
|
156
|
+
|
|
157
|
+
const prevIndex = lastIndexMap[typeName];
|
|
158
|
+
const newIndex = prevIndex === 0 ? prevIndex : prevIndex + 1;
|
|
159
|
+
|
|
160
|
+
// Slate increments map even if newIndex === 0
|
|
161
|
+
lastIndexMap[typeName] += 1;
|
|
162
|
+
|
|
163
|
+
const newInline = getDefaultNode({
|
|
164
|
+
schema: state.schema,
|
|
165
|
+
typeName,
|
|
166
|
+
index: newIndex,
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
if (!newInline) return false;
|
|
170
|
+
|
|
171
|
+
// --- Insert logic ---
|
|
172
|
+
const { selection } = state;
|
|
173
|
+
let insertPos = selection.from;
|
|
174
|
+
|
|
175
|
+
// If we're in a NodeSelection, insert before/after is ambiguous;
|
|
176
|
+
// We'll insert at its "from" (like your current code).
|
|
177
|
+
// If insertion fails, we fallback to end of doc.
|
|
178
|
+
const tryInsertAt = (pos) => {
|
|
179
|
+
try {
|
|
180
|
+
tr.insert(pos, newInline);
|
|
181
|
+
return pos;
|
|
182
|
+
} catch (e) {
|
|
183
|
+
return null;
|
|
184
|
+
}
|
|
185
|
+
};
|
|
186
|
+
|
|
187
|
+
let usedPos = tryInsertAt(insertPos);
|
|
188
|
+
|
|
189
|
+
// Slate branch: "markup empty and there's no focus"
|
|
190
|
+
// ProseMirror doesn't expose "no focus" the same way, so the closest
|
|
191
|
+
// equivalent fallback is inserting at end of document.
|
|
192
|
+
if (usedPos == null) {
|
|
193
|
+
usedPos = tryInsertAt(tr.doc.content.size);
|
|
194
|
+
}
|
|
195
|
+
if (usedPos == null) return false;
|
|
196
|
+
|
|
197
|
+
// Optionally select the node you just inserted (like your original command)
|
|
198
|
+
// tr.setSelection(NodeSelection.create(tr.doc, usedPos))
|
|
199
|
+
|
|
200
|
+
// --- Cursor move behavior for certain types (Slate: moveFocusTo next text) ---
|
|
201
|
+
if (['math_templated', 'inline_dropdown', 'explicit_constructed_response'].includes(typeName)) {
|
|
202
|
+
tr.setSelection(NodeSelection.create(tr.doc, usedPos));
|
|
203
|
+
} else {
|
|
204
|
+
const after = usedPos + newInline.nodeSize;
|
|
205
|
+
tr.setSelection(selectionAfterPos(tr.doc, after));
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (dispatch) {
|
|
209
|
+
commands.focus();
|
|
210
|
+
dispatch(tr);
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
return true;
|
|
214
|
+
},
|
|
215
|
+
refreshResponseArea:
|
|
216
|
+
() =>
|
|
217
|
+
({ tr, state, commands, dispatch }) => {
|
|
218
|
+
const { selection } = state;
|
|
219
|
+
const node = selection.$from.nodeAfter;
|
|
220
|
+
const nodePos = selection.from;
|
|
221
|
+
|
|
222
|
+
tr.setNodeMarkup(nodePos, undefined, { ...node?.attrs, updated: `${Date.now()}` });
|
|
223
|
+
tr.setSelection(NodeSelection.create(tr.doc, nodePos));
|
|
224
|
+
|
|
225
|
+
if (dispatch) {
|
|
226
|
+
commands.focus();
|
|
227
|
+
dispatch(tr);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
return true;
|
|
231
|
+
},
|
|
232
|
+
};
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
/**
|
|
237
|
+
* ExplicitConstructedResponse Node
|
|
238
|
+
*/
|
|
239
|
+
export const ExplicitConstructedResponseNode = Node.create({
|
|
240
|
+
name: 'explicit_constructed_response',
|
|
241
|
+
group: 'inline',
|
|
242
|
+
inline: true,
|
|
243
|
+
atom: true,
|
|
244
|
+
addAttributes() {
|
|
245
|
+
return {
|
|
246
|
+
index: { default: null },
|
|
247
|
+
value: { default: '' },
|
|
248
|
+
updated: { default: '' },
|
|
249
|
+
};
|
|
250
|
+
},
|
|
251
|
+
parseHTML() {
|
|
252
|
+
return [
|
|
253
|
+
{
|
|
254
|
+
tag: 'span[data-type="explicit_constructed_response"]',
|
|
255
|
+
getAttrs: (el) => ({
|
|
256
|
+
index: el.dataset.index,
|
|
257
|
+
value: el.dataset.value,
|
|
258
|
+
}),
|
|
259
|
+
},
|
|
260
|
+
];
|
|
261
|
+
},
|
|
262
|
+
renderHTML({ HTMLAttributes }) {
|
|
263
|
+
return [
|
|
264
|
+
'span',
|
|
265
|
+
{
|
|
266
|
+
'data-type': 'explicit_constructed_response',
|
|
267
|
+
'data-index': HTMLAttributes.index,
|
|
268
|
+
'data-value': HTMLAttributes.value,
|
|
269
|
+
},
|
|
270
|
+
];
|
|
271
|
+
},
|
|
272
|
+
addNodeView() {
|
|
273
|
+
return ReactNodeViewRenderer((props) => <ExplicitConstructedResponse {...{ ...props, options: this.options }} />);
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
/**
|
|
278
|
+
* MathTemplated Node
|
|
279
|
+
*/
|
|
280
|
+
export const MathTemplatedNode = Node.create({
|
|
281
|
+
name: 'math_templated',
|
|
282
|
+
group: 'inline',
|
|
283
|
+
inline: true,
|
|
284
|
+
atom: true,
|
|
285
|
+
addAttributes() {
|
|
286
|
+
return {
|
|
287
|
+
index: { default: null },
|
|
288
|
+
value: { default: '' },
|
|
289
|
+
updated: { default: '' },
|
|
290
|
+
};
|
|
291
|
+
},
|
|
292
|
+
parseHTML() {
|
|
293
|
+
return [
|
|
294
|
+
{
|
|
295
|
+
tag: 'span[data-type="math_templated"]',
|
|
296
|
+
getAttrs: (el) => ({
|
|
297
|
+
index: el.dataset.index,
|
|
298
|
+
value: el.dataset.value,
|
|
299
|
+
}),
|
|
300
|
+
},
|
|
301
|
+
];
|
|
302
|
+
},
|
|
303
|
+
renderHTML({ HTMLAttributes }) {
|
|
304
|
+
return [
|
|
305
|
+
'span',
|
|
306
|
+
{
|
|
307
|
+
'data-type': 'math_templated',
|
|
308
|
+
'data-index': HTMLAttributes.index,
|
|
309
|
+
'data-value': HTMLAttributes.value,
|
|
310
|
+
},
|
|
311
|
+
];
|
|
312
|
+
},
|
|
313
|
+
addNodeView() {
|
|
314
|
+
return ReactNodeViewRenderer((props) => <MathTemplated {...{ ...props, options: this.options }} />);
|
|
315
|
+
},
|
|
316
|
+
});
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* DragInTheBlank Node
|
|
320
|
+
*/
|
|
321
|
+
export const DragInTheBlankNode = Node.create({
|
|
322
|
+
name: 'drag_in_the_blank',
|
|
323
|
+
group: 'inline',
|
|
324
|
+
inline: true,
|
|
325
|
+
atom: true,
|
|
326
|
+
addAttributes() {
|
|
327
|
+
return {
|
|
328
|
+
index: { default: null },
|
|
329
|
+
id: { default: null },
|
|
330
|
+
value: { default: '' },
|
|
331
|
+
inTable: { default: null },
|
|
332
|
+
updated: { default: '' },
|
|
333
|
+
};
|
|
334
|
+
},
|
|
335
|
+
parseHTML() {
|
|
336
|
+
return [
|
|
337
|
+
{
|
|
338
|
+
tag: 'span[data-type="drag_in_the_blank"]',
|
|
339
|
+
getAttrs: (el) => ({
|
|
340
|
+
index: el.dataset.index,
|
|
341
|
+
id: el.dataset.id,
|
|
342
|
+
value: el.dataset.value,
|
|
343
|
+
inTable: el.dataset.inTable,
|
|
344
|
+
}),
|
|
345
|
+
},
|
|
346
|
+
];
|
|
347
|
+
},
|
|
348
|
+
renderHTML({ HTMLAttributes }) {
|
|
349
|
+
return [
|
|
350
|
+
'span',
|
|
351
|
+
{
|
|
352
|
+
'data-type': 'drag_in_the_blank',
|
|
353
|
+
'data-index': HTMLAttributes.index,
|
|
354
|
+
'data-id': HTMLAttributes.id,
|
|
355
|
+
'data-value': HTMLAttributes.value,
|
|
356
|
+
'data-in-table': HTMLAttributes.inTable,
|
|
357
|
+
},
|
|
358
|
+
];
|
|
359
|
+
},
|
|
360
|
+
addNodeView() {
|
|
361
|
+
return ReactNodeViewRenderer((props) => <DragInTheBlank {...{ ...props, options: this.options }} />);
|
|
362
|
+
},
|
|
363
|
+
});
|
|
364
|
+
|
|
365
|
+
/**
|
|
366
|
+
* InlineDropdown Node
|
|
367
|
+
*/
|
|
368
|
+
export const InlineDropdownNode = Node.create({
|
|
369
|
+
name: 'inline_dropdown',
|
|
370
|
+
group: 'inline',
|
|
371
|
+
inline: true,
|
|
372
|
+
atom: true,
|
|
373
|
+
addAttributes() {
|
|
374
|
+
return {
|
|
375
|
+
index: { default: null },
|
|
376
|
+
value: { default: '' },
|
|
377
|
+
updated: { default: '' },
|
|
378
|
+
};
|
|
379
|
+
},
|
|
380
|
+
parseHTML() {
|
|
381
|
+
return [
|
|
382
|
+
{
|
|
383
|
+
tag: 'span[data-type="inline_dropdown"]',
|
|
384
|
+
getAttrs: (el) => ({
|
|
385
|
+
index: el.dataset.index,
|
|
386
|
+
value: el.dataset.value,
|
|
387
|
+
}),
|
|
388
|
+
},
|
|
389
|
+
];
|
|
390
|
+
},
|
|
391
|
+
renderHTML({ HTMLAttributes }) {
|
|
392
|
+
return [
|
|
393
|
+
'span',
|
|
394
|
+
{
|
|
395
|
+
'data-type': 'inline_dropdown',
|
|
396
|
+
'data-index': HTMLAttributes.index,
|
|
397
|
+
'data-value': HTMLAttributes.value,
|
|
398
|
+
},
|
|
399
|
+
];
|
|
400
|
+
},
|
|
401
|
+
addNodeView() {
|
|
402
|
+
return ReactNodeViewRenderer((props) => <InlineDropdown {...{ ...props, options: this.options }} />);
|
|
403
|
+
},
|
|
404
|
+
});
|
package/src/index.tsx
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/index.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 StyledEditor, { EditableHtml } from './components/EditableHtml.js';
|
|
12
|
+
import { ALL_PLUGINS, DEFAULT_PLUGINS } from './extensions/index.js';
|
|
13
|
+
|
|
14
|
+
export { EditableHtml, ALL_PLUGINS, DEFAULT_PLUGINS };
|
|
15
|
+
export default StyledEditor;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/styles/editorContainerStyles.js
|
|
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 { color } from '@pie-lib/render-ui';
|
|
12
|
+
|
|
13
|
+
const styles = (theme) => ({
|
|
14
|
+
root: {
|
|
15
|
+
position: 'relative',
|
|
16
|
+
padding: '0px',
|
|
17
|
+
border: '1px solid #ccc',
|
|
18
|
+
borderRadius: '4px',
|
|
19
|
+
cursor: 'text',
|
|
20
|
+
'& [data-slate-editor="true"]': {
|
|
21
|
+
wordBreak: 'break-word',
|
|
22
|
+
overflow: 'visible',
|
|
23
|
+
maxHeight: '500px',
|
|
24
|
+
// needed in order to be able to put the focus before a void element when it is the first one in the editor
|
|
25
|
+
padding: '5px',
|
|
26
|
+
},
|
|
27
|
+
|
|
28
|
+
'&:first-child': {
|
|
29
|
+
marginTop: 0,
|
|
30
|
+
},
|
|
31
|
+
|
|
32
|
+
'& ul, & ol': {
|
|
33
|
+
padding: '0 1rem',
|
|
34
|
+
margin: '1.25rem 1rem 1.25rem 0.4rem',
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
'& ul li p, & ol li p': {
|
|
38
|
+
marginTop: '0.25em',
|
|
39
|
+
marginBottom: '0.25em',
|
|
40
|
+
},
|
|
41
|
+
|
|
42
|
+
'& h1, & h2, & h3, & h4, & h5, & h6': {
|
|
43
|
+
lineHeight: 1.1,
|
|
44
|
+
marginTop: '2.5rem',
|
|
45
|
+
textWrap: 'pretty',
|
|
46
|
+
},
|
|
47
|
+
|
|
48
|
+
'& h1, & h2': {
|
|
49
|
+
marginTop: '3.5rem',
|
|
50
|
+
marginBottom: '1.5rem',
|
|
51
|
+
},
|
|
52
|
+
|
|
53
|
+
'& h1': {
|
|
54
|
+
fontSize: '1.4rem',
|
|
55
|
+
},
|
|
56
|
+
|
|
57
|
+
'& h2': {
|
|
58
|
+
fontSize: '1.2rem',
|
|
59
|
+
},
|
|
60
|
+
|
|
61
|
+
'& h3': {
|
|
62
|
+
fontSize: '1.1rem',
|
|
63
|
+
},
|
|
64
|
+
|
|
65
|
+
'& h4, & h5, & h6': {
|
|
66
|
+
fontSize: '1rem',
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
'& code': {
|
|
70
|
+
backgroundColor: 'var(--purple-light)',
|
|
71
|
+
borderRadius: '0.4rem',
|
|
72
|
+
color: 'var(--black)',
|
|
73
|
+
fontSize: '0.85rem',
|
|
74
|
+
padding: '0.25em 0.3em',
|
|
75
|
+
},
|
|
76
|
+
|
|
77
|
+
'& pre': {
|
|
78
|
+
background: 'var(--black)',
|
|
79
|
+
borderRadius: '0.5rem',
|
|
80
|
+
color: 'var(--white)',
|
|
81
|
+
fontFamily: '\'JetBrainsMono\', monospace',
|
|
82
|
+
margin: '1.5rem 0',
|
|
83
|
+
padding: '0.75rem 1rem',
|
|
84
|
+
|
|
85
|
+
'& code': {
|
|
86
|
+
background: 'none',
|
|
87
|
+
color: 'inherit',
|
|
88
|
+
fontSize: '0.8rem',
|
|
89
|
+
padding: 0,
|
|
90
|
+
},
|
|
91
|
+
},
|
|
92
|
+
|
|
93
|
+
'& blockquote': {
|
|
94
|
+
background: '#f9f9f9',
|
|
95
|
+
borderLeft: '5px solid #ccc',
|
|
96
|
+
margin: '1.5em 10px',
|
|
97
|
+
padding: '.5em 10px',
|
|
98
|
+
},
|
|
99
|
+
|
|
100
|
+
'& hr': {
|
|
101
|
+
border: 'none',
|
|
102
|
+
borderTop: '1px solid var(--gray-2)',
|
|
103
|
+
margin: '2rem 0',
|
|
104
|
+
},
|
|
105
|
+
|
|
106
|
+
'& table': {
|
|
107
|
+
tableLayout: 'fixed',
|
|
108
|
+
width: '100%',
|
|
109
|
+
borderCollapse: 'collapse',
|
|
110
|
+
color: color.text(),
|
|
111
|
+
backgroundColor: color.background(),
|
|
112
|
+
},
|
|
113
|
+
'& table:not([border="1"]) tr': {
|
|
114
|
+
borderTop: '1px solid #dfe2e5',
|
|
115
|
+
},
|
|
116
|
+
'& td, th': {
|
|
117
|
+
padding: '.6em 1em',
|
|
118
|
+
textAlign: 'center',
|
|
119
|
+
},
|
|
120
|
+
'& table:not([border="1"]) td, th': {
|
|
121
|
+
border: '1px solid #dfe2e5',
|
|
122
|
+
},
|
|
123
|
+
},
|
|
124
|
+
children: {
|
|
125
|
+
padding: '10px 16px',
|
|
126
|
+
},
|
|
127
|
+
editorHolder: {
|
|
128
|
+
position: 'relative',
|
|
129
|
+
padding: '0px',
|
|
130
|
+
overflowY: 'auto',
|
|
131
|
+
color: color.text(),
|
|
132
|
+
backgroundColor: color.background(),
|
|
133
|
+
},
|
|
134
|
+
disabledScrollbar: {
|
|
135
|
+
'&::-webkit-scrollbar': {
|
|
136
|
+
display: 'none',
|
|
137
|
+
},
|
|
138
|
+
scrollbarWidth: 'none',
|
|
139
|
+
'-ms-overflow-style': 'none',
|
|
140
|
+
},
|
|
141
|
+
error: {
|
|
142
|
+
border: `2px solid ${theme.palette.error.main} !important`,
|
|
143
|
+
},
|
|
144
|
+
noBorder: {
|
|
145
|
+
border: 'none',
|
|
146
|
+
},
|
|
147
|
+
noPadding: {
|
|
148
|
+
padding: 0,
|
|
149
|
+
},
|
|
150
|
+
toolbarOnTop: {
|
|
151
|
+
marginTop: '45px',
|
|
152
|
+
},
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
export default styles;
|
package/src/theme.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/theme.js
|
|
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
|
+
export const primary = '#304ffe';
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/utils/helper.js
|
|
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
|
+
const escapeHtml = (str) =>
|
|
12
|
+
String(str)
|
|
13
|
+
.replace(/&/g, '&')
|
|
14
|
+
.replace(/</g, '<')
|
|
15
|
+
.replace(/>/g, '>')
|
|
16
|
+
.replace(/"/g, '"')
|
|
17
|
+
.replace(/'/g, ''');
|
|
18
|
+
|
|
19
|
+
export const normalizeInitialMarkup = (markup) => {
|
|
20
|
+
const trimmed = String(markup ?? '').trim();
|
|
21
|
+
if (!trimmed) return '<div></div>';
|
|
22
|
+
|
|
23
|
+
const looksLikeHtml = /<[^>]+>/.test(trimmed);
|
|
24
|
+
if (looksLikeHtml) return trimmed;
|
|
25
|
+
|
|
26
|
+
return `<div>${escapeHtml(trimmed)}</div>`;
|
|
27
|
+
};
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
/**
|
|
3
|
+
* @synced-from pie-lib/packages/editable-html-tip-tap/src/utils/size.js
|
|
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
|
+
export const valueToSize = (v) => {
|
|
12
|
+
if (!v) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const calcRegex = /^calc\((.*)\)$/;
|
|
17
|
+
|
|
18
|
+
if (typeof v === 'string') {
|
|
19
|
+
if (v.endsWith('%')) {
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (
|
|
24
|
+
v.endsWith('px') ||
|
|
25
|
+
v.endsWith('vh') ||
|
|
26
|
+
v.endsWith('vw') ||
|
|
27
|
+
v.endsWith('ch') ||
|
|
28
|
+
v.endsWith('em') ||
|
|
29
|
+
v.match(calcRegex)
|
|
30
|
+
) {
|
|
31
|
+
return v;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
const value = parseInt(v, 10);
|
|
35
|
+
|
|
36
|
+
return Number.isNaN(value) ? value : `${value}px`;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (typeof v === 'number') {
|
|
40
|
+
return `${v}px`;
|
|
41
|
+
}
|
|
42
|
+
};
|