@blankdotpage/cake 0.1.68 → 0.1.69

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 (57) hide show
  1. package/dist/cake/core/mapping/cursor-source-map.d.ts +11 -0
  2. package/dist/cake/core/mapping/cursor-source-map.d.ts.map +1 -1
  3. package/dist/cake/core/mapping/cursor-source-map.js +159 -21
  4. package/dist/cake/core/runtime.d.ts +4 -0
  5. package/dist/cake/core/runtime.d.ts.map +1 -1
  6. package/dist/cake/core/runtime.js +332 -215
  7. package/dist/cake/dom/render.d.ts +32 -2
  8. package/dist/cake/dom/render.d.ts.map +1 -1
  9. package/dist/cake/dom/render.js +401 -118
  10. package/dist/cake/editor/cake-editor.d.ts +8 -1
  11. package/dist/cake/editor/cake-editor.d.ts.map +1 -1
  12. package/dist/cake/editor/cake-editor.js +172 -100
  13. package/dist/cake/editor/internal/editor-text-model.d.ts +49 -0
  14. package/dist/cake/editor/internal/editor-text-model.d.ts.map +1 -0
  15. package/dist/cake/editor/internal/editor-text-model.js +284 -0
  16. package/dist/cake/editor/selection/selection-geometry-dom.d.ts +5 -1
  17. package/dist/cake/editor/selection/selection-geometry-dom.d.ts.map +1 -1
  18. package/dist/cake/editor/selection/selection-geometry-dom.js +4 -5
  19. package/dist/cake/editor/selection/selection-layout-dom.d.ts.map +1 -1
  20. package/dist/cake/editor/selection/selection-layout-dom.js +2 -5
  21. package/dist/cake/editor/selection/selection-layout.d.ts +2 -15
  22. package/dist/cake/editor/selection/selection-layout.d.ts.map +1 -1
  23. package/dist/cake/editor/selection/selection-layout.js +1 -99
  24. package/dist/cake/editor/selection/selection-navigation.d.ts +4 -0
  25. package/dist/cake/editor/selection/selection-navigation.d.ts.map +1 -1
  26. package/dist/cake/editor/selection/selection-navigation.js +1 -2
  27. package/dist/cake/extensions/link/link.d.ts.map +1 -1
  28. package/dist/cake/extensions/link/link.js +1 -7
  29. package/dist/cake/extensions/shared/structural-reparse-policy.js +2 -2
  30. package/package.json +5 -2
  31. package/dist/cake/editor/selection/visible-text.d.ts +0 -5
  32. package/dist/cake/editor/selection/visible-text.d.ts.map +0 -1
  33. package/dist/cake/editor/selection/visible-text.js +0 -66
  34. package/dist/cake/engine/cake-engine.d.ts +0 -230
  35. package/dist/cake/engine/cake-engine.d.ts.map +0 -1
  36. package/dist/cake/engine/cake-engine.js +0 -3589
  37. package/dist/cake/engine/selection/selection-geometry-dom.d.ts +0 -24
  38. package/dist/cake/engine/selection/selection-geometry-dom.d.ts.map +0 -1
  39. package/dist/cake/engine/selection/selection-geometry-dom.js +0 -302
  40. package/dist/cake/engine/selection/selection-geometry.d.ts +0 -22
  41. package/dist/cake/engine/selection/selection-geometry.d.ts.map +0 -1
  42. package/dist/cake/engine/selection/selection-geometry.js +0 -158
  43. package/dist/cake/engine/selection/selection-layout-dom.d.ts +0 -50
  44. package/dist/cake/engine/selection/selection-layout-dom.d.ts.map +0 -1
  45. package/dist/cake/engine/selection/selection-layout-dom.js +0 -781
  46. package/dist/cake/engine/selection/selection-layout.d.ts +0 -55
  47. package/dist/cake/engine/selection/selection-layout.d.ts.map +0 -1
  48. package/dist/cake/engine/selection/selection-layout.js +0 -128
  49. package/dist/cake/engine/selection/selection-navigation.d.ts +0 -22
  50. package/dist/cake/engine/selection/selection-navigation.d.ts.map +0 -1
  51. package/dist/cake/engine/selection/selection-navigation.js +0 -229
  52. package/dist/cake/engine/selection/visible-text.d.ts +0 -5
  53. package/dist/cake/engine/selection/visible-text.d.ts.map +0 -1
  54. package/dist/cake/engine/selection/visible-text.js +0 -66
  55. package/dist/cake/react/CakeEditor.d.ts +0 -58
  56. package/dist/cake/react/CakeEditor.d.ts.map +0 -1
  57. package/dist/cake/react/CakeEditor.js +0 -225
@@ -1,225 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { Fragment, forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react";
3
- import { CakeEngine } from "../engine/cake-engine";
4
- function toEngineSelection(selection) {
5
- if (!selection) {
6
- return { start: 0, end: 0, affinity: "forward" };
7
- }
8
- return {
9
- start: selection.start,
10
- end: selection.end,
11
- affinity: selection.affinity,
12
- };
13
- }
14
- export const CakeEditor = forwardRef(function CakeEditor(props, outerRef) {
15
- const containerRef = useRef(null);
16
- const engineRef = useRef(null);
17
- const onChangeRef = useRef(props.onChange);
18
- const onSelectionChangeRef = useRef(props.onSelectionChange);
19
- const lastEmittedValueRef = useRef(null);
20
- const lastEmittedSelectionRef = useRef(null);
21
- const [contentRoot, setContentRoot] = useState(null);
22
- const extensionsRef = useRef(props.extensions);
23
- const hasOverlayExtensions = extensionsRef.current.some((ext) => ext.renderOverlay);
24
- useEffect(() => {
25
- onChangeRef.current = props.onChange;
26
- onSelectionChangeRef.current = props.onSelectionChange;
27
- }, [props.onChange, props.onSelectionChange]);
28
- useEffect(() => {
29
- engineRef.current?.syncPlaceholder();
30
- }, [props.placeholder]);
31
- useEffect(() => {
32
- const container = containerRef.current;
33
- if (!container) {
34
- return;
35
- }
36
- const engine = new CakeEngine({
37
- container,
38
- value: props.value,
39
- selection: props.selection ?? undefined,
40
- extensions: extensionsRef.current,
41
- readOnly: props.disabled ?? false,
42
- spellCheckEnabled: props.spellCheck ?? false,
43
- onChange: (value, selection) => {
44
- lastEmittedValueRef.current = value;
45
- lastEmittedSelectionRef.current = selection;
46
- onChangeRef.current(value);
47
- onSelectionChangeRef.current?.(selection.start, selection.end, selection.affinity);
48
- },
49
- onSelectionChange: (selection) => {
50
- lastEmittedSelectionRef.current = selection;
51
- onSelectionChangeRef.current?.(selection.start, selection.end, selection.affinity);
52
- },
53
- });
54
- engineRef.current = engine;
55
- setContentRoot(engine.getContentRoot());
56
- return () => {
57
- engine.destroy();
58
- engineRef.current = null;
59
- setContentRoot(null);
60
- };
61
- }, []);
62
- useEffect(() => {
63
- const engine = engineRef.current;
64
- if (!engine) {
65
- return;
66
- }
67
- engine.setReadOnly(props.disabled ?? false);
68
- }, [props.disabled]);
69
- useEffect(() => {
70
- const engine = engineRef.current;
71
- if (!engine) {
72
- return;
73
- }
74
- engine.setSpellCheckEnabled(props.spellCheck ?? false);
75
- }, [props.spellCheck]);
76
- useEffect(() => {
77
- const engine = engineRef.current;
78
- if (!engine) {
79
- return;
80
- }
81
- const nextValue = props.value;
82
- const nextSelection = props.selection
83
- ? toEngineSelection(props.selection)
84
- : undefined;
85
- const lastEmittedValue = lastEmittedValueRef.current;
86
- // If the value matches what we emitted, don't accept selection changes from props.
87
- // This prevents stale selection props (from React batching during fast typing)
88
- // from resetting the engine's selection.
89
- if (lastEmittedValue === nextValue) {
90
- return;
91
- }
92
- engine.setValue({
93
- value: nextValue,
94
- selection: nextSelection,
95
- });
96
- }, [props.value, props.selection]);
97
- useImperativeHandle(outerRef, () => {
98
- return {
99
- element: containerRef.current,
100
- focus: (selection) => {
101
- const sel = selection ? toEngineSelection(selection) : undefined;
102
- engineRef.current?.focus(sel);
103
- },
104
- blur: () => {
105
- engineRef.current?.blur();
106
- },
107
- hasFocus: () => {
108
- return engineRef.current?.hasFocus() ?? false;
109
- },
110
- selectAll: () => {
111
- engineRef.current?.selectAll();
112
- },
113
- executeCommand: (command, options) => {
114
- if (!engineRef.current) {
115
- return false;
116
- }
117
- return engineRef.current.executeCommand(command, options);
118
- },
119
- applyUpdate: (update) => {
120
- if (!engineRef.current) {
121
- return;
122
- }
123
- const engine = engineRef.current;
124
- const selection = update.selection
125
- ? toEngineSelection(update.selection)
126
- : undefined;
127
- if (update.value !== undefined) {
128
- engine.setValue({
129
- value: update.value,
130
- selection,
131
- });
132
- if (update.focus) {
133
- engine.focus(selection);
134
- }
135
- return;
136
- }
137
- if (update.selection) {
138
- if (!selection) {
139
- return;
140
- }
141
- engine.setSelection(selection);
142
- if (update.focus) {
143
- engine.focus(selection);
144
- }
145
- return;
146
- }
147
- if (update.focus) {
148
- engine.focus();
149
- }
150
- },
151
- getValue: () => engineRef.current?.getValue() ?? props.value,
152
- getSelection: () => {
153
- const selection = engineRef.current?.getSelection();
154
- if (!selection) {
155
- return null;
156
- }
157
- return { start: selection.start, end: selection.end };
158
- },
159
- getCursorLength: () => engineRef.current?.getCursorLength() ?? 0,
160
- insertText: (text) => {
161
- engineRef.current?.insertText(text);
162
- },
163
- replaceText: (oldText, newText) => {
164
- engineRef.current?.replaceText(oldText, newText);
165
- },
166
- };
167
- }, [props.value]);
168
- const containerStyle = props.style
169
- ? { ...props.style }
170
- : {};
171
- if (!containerStyle.position) {
172
- containerStyle.position = "relative";
173
- }
174
- const containerClassName = props.className
175
- ? `cake ${props.className}`
176
- : "cake";
177
- const overlayContext = containerRef.current && contentRoot
178
- ? {
179
- container: containerRef.current,
180
- contentRoot,
181
- toOverlayRect: (rect) => {
182
- const containerRect = containerRef.current?.getBoundingClientRect();
183
- if (!containerRect) {
184
- return {
185
- top: rect.top,
186
- left: rect.left,
187
- width: rect.width,
188
- height: rect.height,
189
- };
190
- }
191
- return {
192
- top: rect.top - containerRect.top,
193
- left: rect.left - containerRect.left,
194
- width: rect.width,
195
- height: rect.height,
196
- };
197
- },
198
- insertText: (text) => {
199
- engineRef.current?.insertText(text);
200
- },
201
- replaceText: (oldText, newText) => {
202
- engineRef.current?.replaceText(oldText, newText);
203
- },
204
- getSelection: () => {
205
- const selection = engineRef.current?.getSelection();
206
- if (!selection) {
207
- return null;
208
- }
209
- const focus = selection.start === selection.end
210
- ? selection.start
211
- : Math.max(selection.start, selection.end);
212
- return { start: focus, end: focus };
213
- },
214
- executeCommand: (command) => {
215
- return engineRef.current?.executeCommand(command) ?? false;
216
- },
217
- }
218
- : null;
219
- return (_jsxs("div", { style: { position: "relative", height: "100%" }, children: [_jsx("div", { ref: containerRef, className: containerClassName, style: containerStyle, "data-placeholder": props.placeholder, onBlur: (event) => {
220
- props.onBlur?.(event.nativeEvent);
221
- } }), overlayContext && hasOverlayExtensions
222
- ? extensionsRef.current.map((extension) => extension.renderOverlay ? (_jsx(Fragment, { children: extension.renderOverlay(overlayContext) }, extension.name)) : null)
223
- : null] }));
224
- });
225
- CakeEditor.displayName = "CakeEditor";