argous 1.2.218 → 1.2.219
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/Carousel/Carousel.js +2 -2
- package/dist/components/Editor/skins/content/dark/content.min.css +1 -0
- package/dist/components/Editor/skins/content/default/content.min.css +1 -0
- package/dist/components/Editor/skins/content/document/content.min.css +1 -0
- package/dist/components/Editor/skins/content/tinymce-5/content.min.css +1 -0
- package/dist/components/Editor/skins/content/tinymce-5-dark/content.min.css +1 -0
- package/dist/components/Editor/skins/content/writer/content.min.css +1 -0
- package/dist/components/Editor/skins/ui/oxide/content.inline.min.css +1 -0
- package/dist/components/Editor/skins/ui/oxide/content.min.css +1 -0
- package/dist/components/Editor/skins/ui/oxide/skin.min.css +1 -0
- package/dist/components/Editor/skins/ui/oxide/skin.shadowdom.min.css +1 -0
- package/dist/components/Editor/skins/ui/oxide-dark/content.inline.min.css +1 -0
- package/dist/components/Editor/skins/ui/oxide-dark/content.min.css +1 -0
- package/dist/components/Editor/skins/ui/oxide-dark/skin.min.css +1 -0
- package/dist/components/Editor/skins/ui/oxide-dark/skin.shadowdom.min.css +1 -0
- package/dist/components/Editor/skins/ui/tinymce-5/content.inline.min.css +1 -0
- package/dist/components/Editor/skins/ui/tinymce-5/content.min.css +1 -0
- package/dist/components/Editor/skins/ui/tinymce-5/skin.min.css +1 -0
- package/dist/components/Editor/skins/ui/tinymce-5/skin.shadowdom.min.css +1 -0
- package/dist/components/Editor/skins/ui/tinymce-5-dark/content.inline.min.css +1 -0
- package/dist/components/Editor/skins/ui/tinymce-5-dark/content.min.css +1 -0
- package/dist/components/Editor/skins/ui/tinymce-5-dark/skin.min.css +1 -0
- package/dist/components/Editor/skins/ui/tinymce-5-dark/skin.shadowdom.min.css +1 -0
- package/dist/components/Editor/tinymce/icons/default/icons.js +194 -0
- package/dist/components/Editor/tinymce/icons/default/icons.min.js +1 -0
- package/dist/components/Editor/tinymce/skins/content/dark/content.css +66 -0
- package/dist/components/Editor/tinymce/skins/content/dark/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/content/default/content.css +61 -0
- package/dist/components/Editor/tinymce/skins/content/default/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/content/document/content.css +66 -0
- package/dist/components/Editor/tinymce/skins/content/document/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/content/tinymce-5/content.css +61 -0
- package/dist/components/Editor/tinymce/skins/content/tinymce-5/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/content/tinymce-5-dark/content.css +66 -0
- package/dist/components/Editor/tinymce/skins/content/tinymce-5-dark/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/content/writer/content.css +62 -0
- package/dist/components/Editor/tinymce/skins/content/writer/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide/content.css +785 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide/content.inline.css +779 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide/content.inline.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide/skin.css +3763 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide/skin.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide/skin.shadowdom.css +30 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide/skin.shadowdom.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide-dark/content.css +766 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide-dark/content.inline.css +779 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide-dark/content.inline.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide-dark/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide-dark/skin.css +3766 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide-dark/skin.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide-dark/skin.shadowdom.css +30 -0
- package/dist/components/Editor/tinymce/skins/ui/oxide-dark/skin.shadowdom.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5/content.css +785 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5/content.inline.css +779 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5/content.inline.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5/skin.css +3857 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5/skin.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5/skin.shadowdom.css +30 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5/skin.shadowdom.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5-dark/content.css +766 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5-dark/content.inline.css +779 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5-dark/content.inline.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5-dark/content.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5-dark/skin.css +3857 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5-dark/skin.min.css +2 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5-dark/skin.shadowdom.css +30 -0
- package/dist/components/Editor/tinymce/skins/ui/tinymce-5-dark/skin.shadowdom.min.css +2 -0
- package/dist/components/TextToHtml/TextToHtml.js +5 -16
- package/dist/components/TextToHtml/icons/resize_area.svg +2 -0
- package/dist/components/TextToHtml/style.css +40 -0
- package/dist/components/Zoom/style.css +25 -0
- package/dist/components/index.d.ts +10 -1
- package/dist/components/index.js +11 -1
- package/lib/components/Carousel/Carousel.d.ts +71 -0
- package/lib/components/Carousel/Carousel.js +218 -0
- package/lib/components/Carousel/index.d.ts +2 -0
- package/lib/components/Carousel/index.js +1 -0
- package/lib/components/TextToHtml/Cursor.js +24 -0
- package/lib/components/TextToHtml/TextStyles.js +111 -0
- package/lib/components/TextToHtml/TextToHtml.d.ts +38 -0
- package/lib/components/TextToHtml/TextToHtml.js +450 -0
- package/lib/components/TextToHtml/icons/resize_area.svg +2 -0
- package/lib/components/TextToHtml/index.d.ts +2 -0
- package/lib/components/TextToHtml/index.js +1 -0
- package/lib/components/TextToHtml/style.css +40 -0
- package/lib/components/TextToHtml/utils.js +848 -0
- package/lib/components/Zoom/Zoom.d.ts +11 -0
- package/lib/components/Zoom/Zoom.js +56 -0
- package/lib/components/Zoom/index.d.ts +2 -0
- package/lib/components/Zoom/index.js +1 -0
- package/lib/components/Zoom/style.css +25 -0
- package/lib/components/index.d.ts +10 -1
- package/lib/components/index.js +11 -1
- package/package.json +2 -1
- package/dist/components/CodeReader/CodeReader.d.ts +0 -29
- package/dist/components/CodeReader/CodeReader.js +0 -487
- package/dist/components/CodeReader/index.d.ts +0 -1
- package/dist/components/CodeReader/index.js +0 -8
- package/dist/components/Editor/ScriptLoader.d.ts +0 -20
- package/dist/components/Editor/ScriptLoader.js +0 -70
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
import Cursor from './Cursor';
|
|
2
|
+
import TextStyles from './TextStyles';
|
|
3
|
+
import { translateKey } from './utils';
|
|
4
|
+
import { ClickAwayListener } from '@material-ui/core';
|
|
5
|
+
import { isEqual } from 'lodash';
|
|
6
|
+
import React, { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
7
|
+
import './style.css';
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
const resizeStyle = {
|
|
11
|
+
resize: 'both',
|
|
12
|
+
overflow: 'auto'
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
export const TEXT_TO_HTML_ID = 'text-to-html';
|
|
17
|
+
const TEXT_TO_HTML_CURSOR_ID = 'text-to-html-cursor';
|
|
18
|
+
const TEXT_TO_HTML_TEXT_CONTAINER_ID = 'text-to-html-text-container';
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
export const initialStateCharacter = {
|
|
22
|
+
key: undefined,
|
|
23
|
+
keyCode: undefined,
|
|
24
|
+
code: undefined,
|
|
25
|
+
string: '',
|
|
26
|
+
dead: false,
|
|
27
|
+
shift: false,
|
|
28
|
+
mark: []
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
export const initialStateCursor = { ...initialStateCharacter, string: 'cursor' };
|
|
32
|
+
|
|
33
|
+
export const textToHtmlInitialValue = { text: '', cssText: '', markedPeople: [], characters: [] };
|
|
34
|
+
|
|
35
|
+
const initialStateMove = {
|
|
36
|
+
isDown: false,
|
|
37
|
+
offset: []
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
const initialStateKeyboardRef = { altGraph: false };
|
|
41
|
+
|
|
42
|
+
const initialStateTextStyle = {
|
|
43
|
+
color: { r: 255, g: 255, b: 255, a: 1 },
|
|
44
|
+
textAlign: 'center',
|
|
45
|
+
fontSize: 2,
|
|
46
|
+
fontFamily: 'Roboto, Helvetica, Arial, sans-serif',
|
|
47
|
+
letterSpacing: '0.01em'
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const initialState = {
|
|
51
|
+
textStyle: initialStateTextStyle,
|
|
52
|
+
createCursorClick: false,
|
|
53
|
+
clickAway: undefined,
|
|
54
|
+
tap: 0,
|
|
55
|
+
resize: false,
|
|
56
|
+
move: initialStateMove,
|
|
57
|
+
characters: []
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
const TextToHtml = ({ initialValue = textToHtmlInitialValue, onChange, onDelete, defaultSpacing, setExternalValues }, ref) => {
|
|
62
|
+
|
|
63
|
+
const keyboardRef = useRef(initialStateKeyboardRef);
|
|
64
|
+
const [state, setState] = useState(initialState);
|
|
65
|
+
const { createCursorClick, characters, move, resize, tap, textStyle } = state;
|
|
66
|
+
const { color, fontSize, fontFamily, textAlign, letterSpacing } = textStyle;
|
|
67
|
+
const propsRef = useRef({
|
|
68
|
+
onChange
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
const cursor = characters.findIndex(({ string }) => (string === 'cursor'));
|
|
72
|
+
const canWrite = (cursor > -1);
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
const logicSetState = ({ type, field, value }) => setState(values => ({
|
|
76
|
+
...values,
|
|
77
|
+
[type]: (type && field) ? { ...values[type], [field]: value } : value
|
|
78
|
+
}));
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
const setCharacters = useCallback(value => logicSetState({ type: 'characters', value: value }), []);
|
|
82
|
+
|
|
83
|
+
const focusToWrite = () => {
|
|
84
|
+
const element = document.getElementById(TEXT_TO_HTML_ID);
|
|
85
|
+
if (element) element.focus();
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
const toggleResize = () => logicSetState({ type: 'resize', value: !resize });
|
|
89
|
+
const toggleClickAway = () => logicSetState({ type: 'clickAway', value: (state.clickAway === undefined) ? false : undefined });
|
|
90
|
+
const disableResize = useCallback(() => logicSetState({ type: 'resize', value: false }), []);
|
|
91
|
+
const handleCreateCursorClick = useCallback((boolean) => logicSetState({ type: 'createCursorClick', value: boolean }), []);
|
|
92
|
+
const deleteCursor = useCallback(() => logicSetState({ type: 'characters', value: characters.filter(({ string }) => string !== 'cursor') }), [characters]);
|
|
93
|
+
|
|
94
|
+
const createCursor = useCallback((e) => {
|
|
95
|
+
let newCharacters = [...characters];
|
|
96
|
+
newCharacters.push(initialStateCursor);
|
|
97
|
+
focusToWrite();
|
|
98
|
+
logicSetState({ type: 'characters', value: newCharacters });
|
|
99
|
+
}, [characters]);
|
|
100
|
+
|
|
101
|
+
const clickAway = useCallback((e) => {
|
|
102
|
+
if (createCursorClick) {
|
|
103
|
+
handleCreateCursorClick(false);
|
|
104
|
+
return;
|
|
105
|
+
}
|
|
106
|
+
disableResize();
|
|
107
|
+
deleteCursor();
|
|
108
|
+
}, [createCursorClick, deleteCursor, disableResize, handleCreateCursorClick]);
|
|
109
|
+
|
|
110
|
+
const handleClickAway = (e) => {
|
|
111
|
+
if (state.clickAway === false) return;
|
|
112
|
+
clickAway(e);
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
const handleContainerClick = (e) => {
|
|
116
|
+
if (canWrite) {
|
|
117
|
+
clickAway(e);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
createCursor(e);
|
|
121
|
+
handleCreateCursorClick(true);
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const handleClick = (e) => {
|
|
125
|
+
e.stopPropagation();
|
|
126
|
+
if (canWrite) return;
|
|
127
|
+
if (createCursorClick) handleCreateCursorClick(false);
|
|
128
|
+
createCursor(e);
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const pasteTextFromClipboard = async (e) => {
|
|
132
|
+
const text = await navigator.clipboard?.readText();
|
|
133
|
+
if (text?.length) {
|
|
134
|
+
let newCharacters = [...characters];
|
|
135
|
+
|
|
136
|
+
for (let index = 0; (index < text.length); index++) {
|
|
137
|
+
const string = text[index];
|
|
138
|
+
let newCharacter = { ...initialStateCharacter, string };
|
|
139
|
+
newCharacters.push(newCharacter);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const cursorIndex = newCharacters.findIndex(({ string }) => (string === 'cursor'));
|
|
143
|
+
if (cursorIndex > -1) {
|
|
144
|
+
const [cursor] = newCharacters.splice(cursorIndex, 1);
|
|
145
|
+
(cursor) && newCharacters.push(cursor);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
(!isEqual(characters, newCharacters)) && setCharacters(newCharacters);
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
const setStyleFromInitialValue = (cssText) => {
|
|
153
|
+
const element = document.getElementById(TEXT_TO_HTML_ID);
|
|
154
|
+
(element) && (element.style.cssText = cssText);
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const loadInitialValue = useCallback((initialValue) => {
|
|
158
|
+
(initialValue.cssText) && setStyleFromInitialValue(initialValue.cssText);
|
|
159
|
+
(initialValue.characters) && setCharacters(initialValue.characters);
|
|
160
|
+
}, [setCharacters]);
|
|
161
|
+
useEffect(() => loadInitialValue(initialValue), [initialValue, loadInitialValue]);
|
|
162
|
+
|
|
163
|
+
const handleKeyDown = (e) => {
|
|
164
|
+
|
|
165
|
+
e.preventDefault();
|
|
166
|
+
e.stopPropagation();
|
|
167
|
+
|
|
168
|
+
if (!canWrite) return;
|
|
169
|
+
|
|
170
|
+
const key = e.key;
|
|
171
|
+
const keyCode = e.keyCode;
|
|
172
|
+
const code = e.code;
|
|
173
|
+
const shift = e.shiftKey;
|
|
174
|
+
const ctrlKey = e.ctrlKey;
|
|
175
|
+
const shiftKey = e.shiftKey;
|
|
176
|
+
const capsLock = e.getModifierState('CapsLock');
|
|
177
|
+
|
|
178
|
+
let deleted = undefined;
|
|
179
|
+
let newCharacter = { string: null };
|
|
180
|
+
let newCharacters = [...characters];
|
|
181
|
+
|
|
182
|
+
const paste = (((key === 'v') || (key === 'V')) && (keyCode === 86) && (code === 'KeyV') && ctrlKey && !shiftKey);
|
|
183
|
+
const characterBeforeCursorIndex = (cursor - 1);
|
|
184
|
+
let characterBeforeCursor = newCharacters[characterBeforeCursorIndex];
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
function moveCursor(direction) {
|
|
188
|
+
const start = (direction === 'start');
|
|
189
|
+
const end = (direction === 'end');
|
|
190
|
+
const left = (direction === 'left');
|
|
191
|
+
const right = (direction === 'right');
|
|
192
|
+
if (!start && !end && !left && !right) return;
|
|
193
|
+
|
|
194
|
+
const cursorIndex = cursor;
|
|
195
|
+
if ((left || start) && (cursorIndex === 0)) return;
|
|
196
|
+
const cursorObject = newCharacters.splice(cursorIndex, 1)[0];
|
|
197
|
+
newCharacters.splice((start) ? 0 : (end) ? (newCharacters.length) : (left) ? (cursorIndex - 1) : (cursorIndex + 1), 0, cursorObject);
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
function deleteText(direction) {
|
|
201
|
+
const left = (direction === 'left');
|
|
202
|
+
const targetIndex = (left) ? (cursor === 0) ? 0 : (cursor - 1) : (cursor + 1);
|
|
203
|
+
const nextObjectToDelete = newCharacters[targetIndex];
|
|
204
|
+
if (nextObjectToDelete?.string === 'cursor') return;
|
|
205
|
+
deleted = newCharacters.splice(targetIndex, 1)?.[0];
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
if (paste) pasteTextFromClipboard(e);
|
|
209
|
+
else if (key === 'Home') moveCursor('start');
|
|
210
|
+
else if (key === 'End') moveCursor('end');
|
|
211
|
+
else if (key === 'ArrowLeft') moveCursor('left');
|
|
212
|
+
else if (key === 'ArrowRight') moveCursor('right');
|
|
213
|
+
else if (key === 'AltGraph') keyboardRef.current.altGraph = true;
|
|
214
|
+
else if (key === 'Backspace') deleteText('left');
|
|
215
|
+
else if (key === 'Delete') deleteText('right');
|
|
216
|
+
else {
|
|
217
|
+
const { string, before } = translateKey({ key, keyCode, code, shift, altGraph: keyboardRef.current.altGraph, capsLock, before: characterBeforeCursor });
|
|
218
|
+
if (string) {
|
|
219
|
+
newCharacter = {
|
|
220
|
+
...initialStateCharacter,
|
|
221
|
+
key,
|
|
222
|
+
keyCode,
|
|
223
|
+
code,
|
|
224
|
+
string,
|
|
225
|
+
dead: before.dead,
|
|
226
|
+
shift
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
newCharacters.splice(cursor, 0, newCharacter);
|
|
230
|
+
if (characterBeforeCursor) {
|
|
231
|
+
if (before.delete) newCharacters.splice(characterBeforeCursorIndex, 1);
|
|
232
|
+
else if (characterBeforeCursor.dead) {
|
|
233
|
+
characterBeforeCursor.dead = false;
|
|
234
|
+
newCharacters.splice(characterBeforeCursorIndex, 1, characterBeforeCursor);
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
(!isEqual(newCharacters, characters)) && setCharacters(newCharacters);
|
|
241
|
+
if (deleted) onDelete && onDelete(e, deleted, newCharacters);
|
|
242
|
+
};
|
|
243
|
+
|
|
244
|
+
const handleKeyUp = (e) => {
|
|
245
|
+
const key = e.key;
|
|
246
|
+
if (key === 'AltGraph') keyboardRef.current.altGraph = false;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const handleDoubleClick = (e) => {
|
|
250
|
+
toggleResize();
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const handleTap = () => {
|
|
254
|
+
let newTap = tap;
|
|
255
|
+
newTap += 1;
|
|
256
|
+
if (newTap > 1) toggleResize();
|
|
257
|
+
logicSetState({ type: 'tap', value: newTap });
|
|
258
|
+
setTimeout(() => logicSetState({ type: 'tap', value: 0 }), 300);
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const handleMouseDownTouchStart = (e) => {
|
|
262
|
+
if (e.type === 'touchstart') handleTap();
|
|
263
|
+
if (resize) return;
|
|
264
|
+
const element = document.getElementById(TEXT_TO_HTML_ID);
|
|
265
|
+
if (!element) return;
|
|
266
|
+
const clientX = (e.clientX || e.touches[0].clientX);
|
|
267
|
+
const clientY = (e.clientY || e.touches[0].clientY);
|
|
268
|
+
logicSetState({
|
|
269
|
+
type: 'move',
|
|
270
|
+
value: {
|
|
271
|
+
...move,
|
|
272
|
+
isDown: true,
|
|
273
|
+
offset: [
|
|
274
|
+
element.offsetLeft - clientX,
|
|
275
|
+
element.offsetTop - clientY
|
|
276
|
+
]
|
|
277
|
+
}
|
|
278
|
+
});
|
|
279
|
+
};
|
|
280
|
+
|
|
281
|
+
const handleMouseUpTouchEnd = (e) => {
|
|
282
|
+
logicSetState({ type: 'move', field: 'isDown', value: false });
|
|
283
|
+
const element = document.getElementById(TEXT_TO_HTML_ID);
|
|
284
|
+
if (element) {
|
|
285
|
+
element.style.cursor = 'pointer';
|
|
286
|
+
}
|
|
287
|
+
};
|
|
288
|
+
|
|
289
|
+
const handleMouseTouchMove = (e) => {
|
|
290
|
+
const { isDown, offset } = move;
|
|
291
|
+
const containerElement = document.getElementById(TEXT_TO_HTML_TEXT_CONTAINER_ID);
|
|
292
|
+
const textElement = document.getElementById(TEXT_TO_HTML_ID);
|
|
293
|
+
if (containerElement && textElement && isDown) {
|
|
294
|
+
const containerHeight = containerElement.clientHeight;
|
|
295
|
+
const containerWidth = containerElement.clientWidth;
|
|
296
|
+
const clientX = (e.clientX || e.touches[0].clientX);
|
|
297
|
+
const clientY = (e.clientY || e.touches[0].clientY);
|
|
298
|
+
const top = (clientY + offset[1]);
|
|
299
|
+
const left = (clientX + offset[0]);
|
|
300
|
+
const textTop = ((top / containerHeight) * 100);
|
|
301
|
+
const textLeft = ((left / containerWidth) * 100);
|
|
302
|
+
textElement.style.top = textTop + '%';
|
|
303
|
+
textElement.style.left = textLeft + '%';
|
|
304
|
+
textElement.style.cursor = 'grabbing';
|
|
305
|
+
}
|
|
306
|
+
};
|
|
307
|
+
|
|
308
|
+
const handleFontSizeChange = (e) => {
|
|
309
|
+
logicSetState({ type: 'clickAway', value: false });
|
|
310
|
+
let newFontSize = fontSize;
|
|
311
|
+
if (newFontSize > 2) newFontSize = 1;
|
|
312
|
+
else newFontSize += 1;
|
|
313
|
+
logicSetState({ type: 'textStyle', field: 'fontSize', value: newFontSize });
|
|
314
|
+
focusToWrite();
|
|
315
|
+
setTimeout(() => logicSetState({ type: 'clickAway', value: undefined }), 0);
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const handleTextAlignChange = (e) => {
|
|
319
|
+
logicSetState({ type: 'clickAway', value: false });
|
|
320
|
+
let newTextAlign = textAlign;
|
|
321
|
+
switch (textAlign) {
|
|
322
|
+
case 'start':
|
|
323
|
+
newTextAlign = 'end';
|
|
324
|
+
break;
|
|
325
|
+
case 'end':
|
|
326
|
+
newTextAlign = 'center';
|
|
327
|
+
break;
|
|
328
|
+
case 'center':
|
|
329
|
+
newTextAlign = 'justify';
|
|
330
|
+
break;
|
|
331
|
+
case 'justify':
|
|
332
|
+
newTextAlign = 'start';
|
|
333
|
+
break;
|
|
334
|
+
default:
|
|
335
|
+
return null;
|
|
336
|
+
}
|
|
337
|
+
logicSetState({ type: 'textStyle', field: 'textAlign', value: newTextAlign });
|
|
338
|
+
focusToWrite();
|
|
339
|
+
setTimeout(() => logicSetState({ type: 'clickAway', value: undefined }), 0);
|
|
340
|
+
};
|
|
341
|
+
|
|
342
|
+
const changeStyles = useCallback(({ resize }) => {
|
|
343
|
+
const element = document.getElementById(TEXT_TO_HTML_ID);
|
|
344
|
+
if (element) {
|
|
345
|
+
if (resize) {
|
|
346
|
+
element.style.resize = resizeStyle.resize;
|
|
347
|
+
element.style.overflow = resizeStyle.overflow;
|
|
348
|
+
} else {
|
|
349
|
+
element.style.resize = '';
|
|
350
|
+
element.style.overflow = '';
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}, []);
|
|
354
|
+
useEffect(() => changeStyles({ resize }), [resize, changeStyles]);
|
|
355
|
+
|
|
356
|
+
const createHtmlString = useCallback(() => {
|
|
357
|
+
const element = document.getElementById(TEXT_TO_HTML_ID);
|
|
358
|
+
if (element) {
|
|
359
|
+
let htmlDataString = '';
|
|
360
|
+
characters.forEach(({ string }) => (string === 'cursor') ? null : htmlDataString += string);
|
|
361
|
+
element.setAttribute('data-string', htmlDataString);
|
|
362
|
+
|
|
363
|
+
let newElement = element.cloneNode(true);
|
|
364
|
+
newElement.id = `${Math.floor(Math.random() * 1000001)}-${element.id}`;
|
|
365
|
+
newElement.style.cursor = 'inherit';
|
|
366
|
+
const htmlString = newElement.outerHTML;
|
|
367
|
+
|
|
368
|
+
(propsRef.current?.onChange) && propsRef.current.onChange(htmlString);
|
|
369
|
+
if (ref.current) ref.current.htmlString = htmlString;
|
|
370
|
+
return { htmlString };
|
|
371
|
+
}
|
|
372
|
+
}, [characters, ref]);
|
|
373
|
+
useEffect(() => createHtmlString(), [characters, createHtmlString]);
|
|
374
|
+
|
|
375
|
+
|
|
376
|
+
useEffect(() => ref.current = {
|
|
377
|
+
...ref.current,
|
|
378
|
+
...state,
|
|
379
|
+
clickAway,
|
|
380
|
+
focusToWrite,
|
|
381
|
+
createCursor,
|
|
382
|
+
setCharacters,
|
|
383
|
+
createHtmlString,
|
|
384
|
+
setExternalValues
|
|
385
|
+
}, [ref, state, setCharacters, createCursor, createHtmlString, clickAway, setExternalValues]);
|
|
386
|
+
|
|
387
|
+
const updateExternalValues = ({ state, setExternalValues }) => {
|
|
388
|
+
setExternalValues && setExternalValues(state);
|
|
389
|
+
};
|
|
390
|
+
useEffect(() => updateExternalValues({ state, setExternalValues }), [state, setExternalValues]);
|
|
391
|
+
|
|
392
|
+
|
|
393
|
+
return <div className='text-to-html-container'>
|
|
394
|
+
{(canWrite) && (
|
|
395
|
+
<TextStyles
|
|
396
|
+
setColor={value => logicSetState({ type: 'textStyle', field: 'color', value })}
|
|
397
|
+
{...{ color, defaultSpacing, toggleClickAway, handleFontSizeChange, textAlign, handleTextAlignChange }}
|
|
398
|
+
/>
|
|
399
|
+
)}
|
|
400
|
+
<div id={TEXT_TO_HTML_TEXT_CONTAINER_ID} onClick={handleContainerClick} className='text-to-html-text-container'>
|
|
401
|
+
<ClickAwayListener mouseEvent={state.clickAway} touchEvent={state.clickAway} disableReactTree onClickAway={handleClickAway}>
|
|
402
|
+
<div
|
|
403
|
+
id={TEXT_TO_HTML_ID}
|
|
404
|
+
tabIndex={0}
|
|
405
|
+
onKeyDown={handleKeyDown}
|
|
406
|
+
onKeyUp={handleKeyUp}
|
|
407
|
+
onMouseDown={handleMouseDownTouchStart}
|
|
408
|
+
onMouseUp={handleMouseUpTouchEnd}
|
|
409
|
+
onMouseMove={handleMouseTouchMove}
|
|
410
|
+
onTouchStart={handleMouseDownTouchStart}
|
|
411
|
+
onTouchEnd={handleMouseUpTouchEnd}
|
|
412
|
+
onTouchMove={handleMouseTouchMove}
|
|
413
|
+
onClick={handleClick}
|
|
414
|
+
onDoubleClick={handleDoubleClick}
|
|
415
|
+
style={{
|
|
416
|
+
color: (color) ? `rgba(${color.r}, ${color.g}, ${color.b}, ${color.a})` : 'inherit',
|
|
417
|
+
textAlign: (textAlign) ? textAlign : 'inherit',
|
|
418
|
+
fontSize: (fontSize) ? `${fontSize}rem` : '1rem',
|
|
419
|
+
fontFamily: (fontFamily) ? fontFamily : 'inherit',
|
|
420
|
+
letterSpacing: (letterSpacing) ? letterSpacing : 'inherit'
|
|
421
|
+
}}
|
|
422
|
+
className='text-to-html'
|
|
423
|
+
>
|
|
424
|
+
<p>
|
|
425
|
+
{characters.map(({ code, string, dead, mark }, stringIndex) => {
|
|
426
|
+
switch (string) {
|
|
427
|
+
case 'cursor':
|
|
428
|
+
return <Cursor key={`${stringIndex}-${string}`} id={TEXT_TO_HTML_CURSOR_ID} className='text-to-html-cursor' />;
|
|
429
|
+
default:
|
|
430
|
+
return (string) ? (
|
|
431
|
+
<span
|
|
432
|
+
key={`${stringIndex}-${string}`}
|
|
433
|
+
style={{
|
|
434
|
+
textDecoration: (dead || mark?.length) ? 'underline' : ''
|
|
435
|
+
}}
|
|
436
|
+
>
|
|
437
|
+
{string}
|
|
438
|
+
</span>
|
|
439
|
+
) : null;
|
|
440
|
+
}
|
|
441
|
+
})}
|
|
442
|
+
</p>
|
|
443
|
+
</div>
|
|
444
|
+
</ClickAwayListener>
|
|
445
|
+
</div>
|
|
446
|
+
</div>;
|
|
447
|
+
};
|
|
448
|
+
|
|
449
|
+
|
|
450
|
+
export default forwardRef(TextToHtml);
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
|
|
2
|
+
<svg width="800px" height="800px" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg"><path d="M22.354 9.354l-.707-.707-13 13 .707.707zm0 7l-.707-.707-6 6 .707.707z"/><path fill="none" d="M0 0h24v24H0z"/></svg>
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { default } from './TextToHtml';
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
.text-to-html-container {
|
|
2
|
+
width: 100%;
|
|
3
|
+
}
|
|
4
|
+
|
|
5
|
+
.text-to-html-text-container {
|
|
6
|
+
position: absolute;
|
|
7
|
+
width: 100%;
|
|
8
|
+
height: 100%;
|
|
9
|
+
overflow: hidden;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
.text-to-html {
|
|
13
|
+
touch-action: none;
|
|
14
|
+
position: absolute;
|
|
15
|
+
top: 45%;
|
|
16
|
+
left: 13%;
|
|
17
|
+
width: 80%;
|
|
18
|
+
display: flex;
|
|
19
|
+
flex-wrap: wrap;
|
|
20
|
+
align-items: center;
|
|
21
|
+
justify-content: center;
|
|
22
|
+
outline: 0;
|
|
23
|
+
cursor: pointer;
|
|
24
|
+
color: inherit;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.text-to-html > p {
|
|
28
|
+
margin: 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.text-to-html::-webkit-resizer {
|
|
32
|
+
background-color: #fff;
|
|
33
|
+
background-image: url('./icons/resize_area.svg');
|
|
34
|
+
background-repeat: no-repeat;
|
|
35
|
+
background-size: cover;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.text-to-html-cursor {
|
|
39
|
+
opacity: 0;
|
|
40
|
+
}
|