@coorax/react 0.0.0-canary.1 → 0.0.0-canary.10

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 (198) hide show
  1. package/dist/components/commons/button.d.ts +8 -0
  2. package/dist/components/commons/youtube.d.ts +2 -0
  3. package/dist/components/corax-context-provider.d.ts +11 -0
  4. package/dist/components/corax-flow.d.ts +6 -0
  5. package/dist/components/errors/iframe.error.d.ts +2 -0
  6. package/dist/components/errors/image.error.d.ts +2 -0
  7. package/dist/components/errors/video.errors.d.ts +2 -0
  8. package/dist/components/fallbacks/iframe.fallback.d.ts +2 -0
  9. package/dist/components/fallbacks/image.fallback.d.ts +2 -0
  10. package/dist/components/fallbacks/link.fallback.d.ts +2 -0
  11. package/dist/components/fallbacks/video.fallback.d.ts +2 -0
  12. package/dist/components/slots/buttons/block-actions-button.d.ts +3 -0
  13. package/dist/components/slots/buttons/caption-button.d.ts +3 -0
  14. package/dist/components/slots/buttons/code-theme-button.d.ts +3 -0
  15. package/dist/components/slots/buttons/delete-button.d.ts +3 -0
  16. package/dist/components/slots/buttons/divider-style-button.d.ts +3 -0
  17. package/dist/components/slots/buttons/divider-width-button.d.ts +3 -0
  18. package/dist/components/slots/buttons/iframe-playback-button.d.ts +3 -0
  19. package/dist/components/slots/buttons/image-width-button.d.ts +3 -0
  20. package/dist/components/slots/buttons/paragraph-theme-button.d.ts +3 -0
  21. package/dist/components/slots/buttons/toolbar-button.d.ts +3 -0
  22. package/dist/components/slots/maps/block-actions.d.ts +1 -0
  23. package/dist/components/slots/maps/overlays.d.ts +1 -0
  24. package/dist/components/slots/maps/text-inspector.d.ts +2 -0
  25. package/dist/components/slots/maps/toolbar.d.ts +1 -0
  26. package/dist/components/slots/overlays/focus-overlay.d.ts +3 -0
  27. package/dist/components/slots/overlays/hover-overlay.d.ts +3 -0
  28. package/dist/components/slots/overlays/selection-overlay.d.ts +3 -0
  29. package/dist/components/slots/slot-button.d.ts +6 -0
  30. package/dist/components/slots/slot-component.d.ts +5 -0
  31. package/dist/components/slots/slots.d.ts +4 -0
  32. package/dist/constants/field.constants.d.ts +2 -0
  33. package/dist/hooks/custom/use-custom-ref.d.ts +1 -0
  34. package/dist/hooks/custom/use-isomorphic-layout-effect.d.ts +2 -0
  35. package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -0
  36. package/dist/hooks/use-block-entry.d.ts +2 -0
  37. package/dist/hooks/use-block.d.ts +2 -0
  38. package/dist/hooks/use-flow.d.ts +17 -0
  39. package/dist/hooks/use-is-selected.d.ts +2 -0
  40. package/dist/hooks/use-keyboard.d.ts +10 -0
  41. package/dist/hooks/use-registry.d.ts +3 -0
  42. package/dist/hooks/use-renderer.d.ts +2 -0
  43. package/dist/hooks/use-slice.d.ts +2 -0
  44. package/dist/hooks/use-slots.d.ts +2 -0
  45. package/dist/hooks/use-tasks.d.ts +7 -0
  46. package/dist/hooks/use-text-input.d.ts +2 -0
  47. package/dist/hooks/use-ui-context.d.ts +2 -0
  48. package/dist/hooks/useSelection.d.ts +2 -0
  49. package/{src/index.ts → dist/index.d.ts} +8 -4
  50. package/dist/index.js +3575 -0
  51. package/dist/lib/comp.utils.d.ts +8 -0
  52. package/dist/lib/func.utils.d.ts +3 -0
  53. package/dist/lib/index.d.ts +4 -0
  54. package/dist/lib/selection.utils.d.ts +5 -0
  55. package/dist/lib/slots.utils.d.ts +4 -0
  56. package/dist/lifecycle/fields/common/focus.events/onblur.d.ts +3 -0
  57. package/dist/lifecycle/fields/common/focus.events/onfocus.d.ts +3 -0
  58. package/dist/lifecycle/fields/common/handlers.d.ts +13 -0
  59. package/dist/lifecycle/fields/common/mouse.events/onclick.d.ts +3 -0
  60. package/dist/lifecycle/fields/common/mouse.events/onmouseenter.d.ts +3 -0
  61. package/dist/lifecycle/fields/common/mouse.events/onmouseleave.d.ts +3 -0
  62. package/dist/lifecycle/fields/divider/handlers.d.ts +7 -0
  63. package/dist/lifecycle/fields/divider/keyboard.events/onkeydown.d.ts +3 -0
  64. package/dist/lifecycle/fields/editable/focus.events/onbeforeinput.d.ts +3 -0
  65. package/dist/lifecycle/fields/editable/handlers.d.ts +7 -0
  66. package/dist/lifecycle/fields/editable/keyboard.events/onkeydown.d.ts +3 -0
  67. package/dist/lifecycle/fields/editable/mouse.events/ondoubleclick.d.ts +4 -0
  68. package/dist/lifecycle/fields/editable/synthetic.events/onselect.d.ts +3 -0
  69. package/dist/lifecycle/fields/handlers.registry.d.ts +12 -0
  70. package/dist/lifecycle/fields/lifecycle.fields.d.ts +10 -0
  71. package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +4 -0
  72. package/dist/lifecycle/fields/lifecycle.utils.d.ts +8 -0
  73. package/dist/lifecycle/fields/media/common/handlers.d.ts +7 -0
  74. package/dist/lifecycle/fields/media/common/keyboard.events/onkeydown.d.ts +3 -0
  75. package/dist/lifecycle/fields/media/common/synthetic.events/onerror.d.ts +3 -0
  76. package/dist/lifecycle/fields/media/iframe/handlers.d.ts +7 -0
  77. package/dist/lifecycle/fields/media/iframe/synthetic.events/onload.d.ts +3 -0
  78. package/dist/lifecycle/fields/media/image/handlers.d.ts +7 -0
  79. package/dist/lifecycle/fields/media/image/synthetic.events/onload.d.ts +3 -0
  80. package/dist/lifecycle/fields/media/video/handlers.d.ts +7 -0
  81. package/dist/lifecycle/fields/media/video/mouse.events/ondoubleclick.d.ts +4 -0
  82. package/dist/lifecycle/fields/media/video/synthetic.events/oncanplaythrough.d.ts +3 -0
  83. package/dist/lifecycle/index.d.ts +3 -0
  84. package/dist/modules/autosave.module.d.ts +41 -0
  85. package/dist/modules/errors.module.d.ts +7 -0
  86. package/dist/modules/fallbacks.module.d.ts +7 -0
  87. package/dist/modules/slots.module.d.ts +7 -0
  88. package/dist/modules/ui-primitives.module.d.ts +7 -0
  89. package/dist/primitives/fields/field.primitives.d.ts +2 -0
  90. package/dist/primitives/index.d.ts +3 -0
  91. package/dist/registry/index.d.ts +4 -0
  92. package/dist/registry/slots.registry.d.ts +4 -0
  93. package/{src/registry/ui.primitives.registry.tsx → dist/registry/ui.primitives.registry.d.ts} +4 -5
  94. package/dist/services/index.d.ts +2 -0
  95. package/dist/services/localdb/db/db.d.ts +78 -0
  96. package/dist/services/localdb/db/db.test.d.ts +1 -0
  97. package/dist/services/localdb/dbtest.d.ts +1 -0
  98. package/dist/services/localdb/lexer/lexer.d.ts +14 -0
  99. package/dist/services/localdb/lexer/lexer.test.d.ts +1 -0
  100. package/dist/services/localdb/lexer/lexer.types.d.ts +5 -0
  101. package/dist/services/localdb/operator/operator.d.ts +10 -0
  102. package/dist/services/localdb/parser/parser.constants.d.ts +3 -0
  103. package/dist/services/localdb/parser/parser.d.ts +15 -0
  104. package/dist/services/localdb/parser/parser.test.d.ts +1 -0
  105. package/dist/services/localdb/parser/parser.types.d.ts +49 -0
  106. package/dist/services/localdb/sheet/sheet.constants.d.ts +3 -0
  107. package/dist/services/localdb/sheet/sheet.d.ts +14 -0
  108. package/dist/services/localdb/sheet/sheet.types.d.ts +13 -0
  109. package/dist/styles.css +2 -0
  110. package/package.json +38 -15
  111. package/styles.css +2 -1
  112. package/.oxlintrc.json +0 -8
  113. package/src/components/commons/button.tsx +0 -59
  114. package/src/components/corax-context-provider.tsx +0 -47
  115. package/src/components/corax-flow.tsx +0 -44
  116. package/src/components/fallbacks/image.fallback.tsx +0 -23
  117. package/src/components/slots/buttons/block-actions-button.tsx +0 -85
  118. package/src/components/slots/buttons/toolbar-button.tsx +0 -40
  119. package/src/components/slots/maps/block-actions.tsx +0 -84
  120. package/src/components/slots/maps/overlays.tsx +0 -9
  121. package/src/components/slots/maps/text-inspector.tsx +0 -5
  122. package/src/components/slots/maps/toolbar.tsx +0 -79
  123. package/src/components/slots/overlays/focus-overlay.tsx +0 -30
  124. package/src/components/slots/overlays/hover-overlay.tsx +0 -18
  125. package/src/components/slots/overlays/selection-overlay.tsx +0 -20
  126. package/src/components/slots/slot-button.tsx +0 -20
  127. package/src/components/slots/slot-component.tsx +0 -17
  128. package/src/components/slots/slots.tsx +0 -29
  129. package/src/constants/field.constants.ts +0 -3
  130. package/src/hooks/custom/use-custom-ref.ts +0 -11
  131. package/src/hooks/use-block-entry.ts +0 -44
  132. package/src/hooks/use-block.ts +0 -11
  133. package/src/hooks/use-flow.ts +0 -83
  134. package/src/hooks/use-keyboard.ts +0 -66
  135. package/src/hooks/use-registry.ts +0 -18
  136. package/src/hooks/use-renderer.ts +0 -8
  137. package/src/hooks/use-slice.ts +0 -13
  138. package/src/hooks/use-slots.ts +0 -13
  139. package/src/hooks/use-tasks.ts +0 -33
  140. package/src/hooks/use-text-input.ts +0 -83
  141. package/src/hooks/use-ui-context.ts +0 -16
  142. package/src/hooks/useSelection.ts +0 -27
  143. package/src/lib/comp.utils.tsx +0 -44
  144. package/src/lib/func.utils.ts +0 -15
  145. package/src/lib/selection.utils.ts +0 -33
  146. package/src/lib/slots.utils.tsx +0 -23
  147. package/src/lifecycle/fields/focus.events/onbeforeinput.ts +0 -21
  148. package/src/lifecycle/fields/focus.events/onblur.ts +0 -19
  149. package/src/lifecycle/fields/focus.events/onfocus.ts +0 -16
  150. package/src/lifecycle/fields/keyboard.events/onkeydown.ts +0 -128
  151. package/src/lifecycle/fields/lifecycle.fields.ts +0 -116
  152. package/src/lifecycle/fields/lifecycle.fields.types.ts +0 -33
  153. package/src/lifecycle/fields/lifecycle.utils.ts +0 -26
  154. package/src/lifecycle/fields/mouse.events/onclick.ts +0 -79
  155. package/src/lifecycle/fields/mouse.events/ondoubleclick.ts +0 -27
  156. package/src/lifecycle/fields/mouse.events/onmouseenter.ts +0 -27
  157. package/src/lifecycle/fields/mouse.events/onmouseleave.ts +0 -21
  158. package/src/lifecycle/fields/synthetic.events/onload.ts +0 -16
  159. package/src/lifecycle/fields/synthetic.events/onselect.ts +0 -57
  160. package/src/lifecycle/index.ts +0 -1
  161. package/src/modules/autosave.module.ts +0 -238
  162. package/src/modules/fallbacks.module.tsx +0 -19
  163. package/src/modules/slots.module.tsx +0 -28
  164. package/src/modules/ui-primitives.module.tsx +0 -20
  165. package/src/primitives/fields/field.primitives.tsx +0 -86
  166. package/src/primitives/index.ts +0 -8
  167. package/src/registry/fallbacks.registry.tsx +0 -9
  168. package/src/registry/index.ts +0 -5
  169. package/src/registry/primitives.registry.tsx +0 -57
  170. package/src/registry/registry.ts +0 -44
  171. package/src/registry/slots.registry.tsx +0 -6
  172. package/src/renderer/renderer.test.ts +0 -34
  173. package/src/renderer/renderer.tsx +0 -164
  174. package/src/renderer/renderer.types.ts +0 -3
  175. package/src/renderer/renderer.utils.tsx +0 -139
  176. package/src/renderer/utils/divider.renderer.utils.tsx +0 -53
  177. package/src/services/localdb/db/db.test.ts +0 -351
  178. package/src/services/localdb/db/db.ts +0 -628
  179. package/src/services/localdb/lexer/lexer.test.ts +0 -123
  180. package/src/services/localdb/lexer/lexer.ts +0 -173
  181. package/src/services/localdb/lexer/lexer.types.ts +0 -34
  182. package/src/services/localdb/operator/operator.ts +0 -16
  183. package/src/services/localdb/parser/parser.constants.ts +0 -23
  184. package/src/services/localdb/parser/parser.test.ts +0 -172
  185. package/src/services/localdb/parser/parser.ts +0 -427
  186. package/src/services/localdb/parser/parser.types.ts +0 -56
  187. package/src/services/localdb/sheet/sheet.constants.ts +0 -32
  188. package/src/services/localdb/sheet/sheet.ts +0 -47
  189. package/src/services/localdb/sheet/sheet.types.ts +0 -38
  190. package/tsconfig.app.json +0 -26
  191. package/tsconfig.json +0 -9
  192. package/tsconfig.node.json +0 -9
  193. package/tsconfig.tsbuildinfo +0 -1
  194. package/vite.config.ts +0 -9
  195. /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
  196. /package/{src/components/slots/index.ts → dist/components/slots/index.d.ts} +0 -0
  197. /package/{src/components/slots/maps/index.ts → dist/components/slots/maps/index.d.ts} +0 -0
  198. /package/{src/modules/index.ts → dist/modules/index.d.ts} +0 -0
@@ -1,238 +0,0 @@
1
- import { SerializeTree, type TModule } from "@coorax/core";
2
- import { LocalDB } from "../services/localdb/db/db";
3
-
4
- declare module "@coorax/core" {
5
- interface ModuleMap {
6
- autosave: {
7
- loadDocument(id: string): Promise<any>;
8
- saveMedia(media: {
9
- id: string;
10
- document_id: string;
11
- name: string;
12
- type: string;
13
- size: number;
14
- data: File | Blob;
15
- }): Promise<any>;
16
- };
17
- }
18
- }
19
-
20
- declare module "@coorax/core" {
21
- interface StateMap {
22
- localdbState: { isDBReady: boolean };
23
- }
24
- }
25
-
26
- declare module "@coorax/core" {
27
- interface TaskMap {
28
- "autosave:persist": true;
29
- }
30
- }
31
-
32
- export async function loadCompleteDocument(db: LocalDB, documentId: string) {
33
- const result = await db.QueryDB<any>(`
34
- SELECT * FROM documents
35
- JOIN fields ON documents.id = fields.document_id
36
- JOIN containers ON documents.id = containers.document_id
37
- JOIN components ON documents.id = components.document_id
38
- LEFT JOIN medias ON documents.id = medias.document_id
39
- WHERE documents.id = '${documentId}';
40
- `);
41
-
42
- if (result instanceof Error) {
43
- throw result;
44
- }
45
-
46
- if (Array.isArray(result) && result.length > 0) {
47
- return result[0];
48
- }
49
-
50
- return null;
51
- }
52
-
53
- export const AutoSaveModule: TModule = {
54
- name: "autosave",
55
- version: "1.0.0",
56
- requires: [],
57
-
58
- install(ctx) {
59
- ctx.state.defineSlice("localdbState", { isDBReady: false });
60
-
61
- const db = new LocalDB("coraxdb");
62
- db.DeleteDB()
63
- .then((err) => {
64
- if (err) {
65
- console.error(err);
66
- return;
67
- }
68
-
69
- db.MigrateDB(`
70
- CREATE TABLE documents (
71
- id TEXT,
72
- version TEXT,
73
- order ARRAY[STRING],
74
- created_at DATETIME
75
- );
76
- CREATE TABLE fields (
77
- id TEXT,
78
- document_id TEXT,
79
- name TEXT,
80
- tag TEXT,
81
- type TEXT,
82
- variant TEXT,
83
- containerId TEXT,
84
- props OBJECT
85
- );
86
- CREATE TABLE containers (
87
- id TEXT,
88
- document_id TEXT,
89
- name TEXT,
90
- tag TEXT,
91
- type TEXT,
92
- variant TEXT,
93
- order ARRAY[STRING],
94
- props OBJECT
95
- );
96
- CREATE TABLE components (
97
- id TEXT,
98
- document_id TEXT,
99
- name TEXT,
100
- tag TEXT,
101
- type TEXT,
102
- variant TEXT,
103
- order ARRAY[STRING],
104
- count INTEGER,
105
- updatedAt DATETIME,
106
- createdAt DATETIME,
107
- props OBJECT
108
- );
109
- CREATE TABLE medias (
110
- id TEXT,
111
- document_id TEXT,
112
- name TEXT,
113
- type TEXT,
114
- size INTEGER,
115
- data FILE,
116
- created_at DATETIME
117
- );
118
- `)
119
- .then((error) => {
120
- if (error) {
121
- console.error("Failed to migrate database:", error);
122
- return;
123
- }
124
- ctx.state.set("localdbState", { isDBReady: true });
125
- })
126
- .catch((r) => {
127
- console.error(r);
128
- });
129
- })
130
- .catch((e) => {
131
- console.error(e);
132
- });
133
-
134
- ctx.commands.before("blocks.insert", (p) => {
135
- const dbState = ctx.state.get("localdbState");
136
- if (!dbState || !dbState.isDBReady) return null;
137
-
138
- return p;
139
- });
140
-
141
- ctx.events.on("document:changed", (sbc) => {
142
- const dbState = ctx.state.get("localdbState");
143
- if (!dbState || !dbState.isDBReady) return;
144
-
145
- const jsonDocument = SerializeTree(sbc.value.next);
146
-
147
- // Program the save with a 1s delay (reschedules and cancels if new changes occur within 1s)
148
- const saveDocument = async () => {
149
- const documentId = jsonDocument.id;
150
- const now = Date.now();
151
-
152
- // 1. Store main document row
153
- await db.QueryDB(
154
- `INSERT INTO documents (id, version, order, created_at) VALUES (?, ?, ?, ?);`,
155
- [documentId, jsonDocument.version, Array.from(jsonDocument.order ?? []), now],
156
- );
157
-
158
- // 2. Separate and store fields in their own table
159
- for (const [fieldId, field] of Object.entries(jsonDocument.fields ?? {})) {
160
- await db.QueryDB(
161
- `INSERT INTO fields (id, document_id, name, tag, type, variant, containerId, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`,
162
- [
163
- field.id || fieldId,
164
- documentId,
165
- field.name ?? "",
166
- field.tag ?? "p",
167
- field.type ?? "text",
168
- field.variant ?? "field",
169
- field.containerId ?? "",
170
- field.props ?? {},
171
- ],
172
- );
173
-
174
- // Check if field contains a File or Blob media to store in medias table
175
- const fieldProps = (field.props as any) ?? {};
176
- if (
177
- fieldProps.file &&
178
- (fieldProps.file instanceof Blob ||
179
- (typeof File !== "undefined" && fieldProps.file instanceof File))
180
- ) {
181
- const file = fieldProps.file;
182
- await db.QueryDB(
183
- `INSERT INTO medias (id, document_id, name, type, size, data, created_at) VALUES (?, ?, ?, ?, ?, ?, ?);`,
184
- [
185
- `media:${field.id || fieldId}`,
186
- documentId,
187
- file.name ?? "unnamed",
188
- file.type ?? "application/octet-stream",
189
- file.size ?? 0,
190
- file,
191
- now,
192
- ],
193
- );
194
- }
195
- }
196
-
197
- // 3. Separate and store containers in their own table
198
- for (const [containerId, container] of Object.entries(jsonDocument.containers ?? {})) {
199
- await db.QueryDB(
200
- `INSERT INTO containers (id, document_id, name, tag, type, variant, order, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`,
201
- [
202
- container.id || containerId,
203
- documentId,
204
- container.name ?? "",
205
- container.tag ?? "div",
206
- container.type ?? "division",
207
- container.variant ?? "container",
208
- Array.from(container.order ?? []),
209
- container.props ?? {},
210
- ],
211
- );
212
- }
213
-
214
- // 4. Separate and store components in their own table
215
- for (const [componentId, component] of Object.entries(jsonDocument.components ?? {})) {
216
- await db.QueryDB(
217
- `INSERT INTO components (id, document_id, name, tag, type, variant, order, count, updatedAt, createdAt, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
218
- [
219
- component.id || componentId,
220
- documentId,
221
- component.name ?? "",
222
- component.tag ?? "div",
223
- component.type ?? "division",
224
- component.variant ?? "component",
225
- Array.from(component.order ?? []),
226
- component.count ?? 0,
227
- component.updatedAt ?? now,
228
- component.createdAt ?? now,
229
- component.props ?? {},
230
- ],
231
- );
232
- }
233
- };
234
-
235
- ctx.tasks.schedule("autosave:persist", 1000, saveDocument);
236
- });
237
- },
238
- };
@@ -1,19 +0,0 @@
1
- import { type TModule } from "@coorax/core";
2
- import { FallbackComponentsRegistry, type FallbackComponent } from "../registry/fallbacks.registry";
3
- import { ImageFallback } from "../components/fallbacks/image.fallback";
4
-
5
- declare module "@coorax/core" {
6
- interface ModuleMap {
7
- fallbacks: {};
8
- }
9
- }
10
-
11
- export const FallbacksModule: TModule = {
12
- name: "fallbacks",
13
- version: "1.0.0",
14
- requires: [],
15
-
16
- install() {
17
- FallbackComponentsRegistry.register("image", ImageFallback as FallbackComponent);
18
- },
19
- };
@@ -1,28 +0,0 @@
1
- import { type TModule } from "@coorax/core";
2
- import { SlotsComponentRegistry } from "../registry/slots.registry";
3
- import { BlockActionButton } from "../components/slots/buttons/block-actions-button";
4
- import { ToolbarButton } from "../components/slots/buttons/toolbar-button";
5
- import { FocusOverlay } from "../components/slots/overlays/focus-overlay";
6
- import { HoverOverlay } from "../components/slots/overlays/hover-overlay";
7
- import { SelectionOverlay } from "../components/slots/overlays/selection-overlay";
8
-
9
- declare module "@coorax/core" {
10
- interface ModuleMap {
11
- slots: {};
12
- }
13
- }
14
-
15
- export const SlotsModule: TModule = {
16
- name: "slots",
17
- version: "1.0.0",
18
- requires: [],
19
-
20
- install() {
21
- SlotsComponentRegistry.register("BlockActionButton", BlockActionButton);
22
- SlotsComponentRegistry.register("ToolBarButton", ToolbarButton);
23
-
24
- SlotsComponentRegistry.register("SelectionOverlay", SelectionOverlay);
25
- SlotsComponentRegistry.register("FocusOverlay", FocusOverlay);
26
- SlotsComponentRegistry.register("HoverOverlay", HoverOverlay);
27
- },
28
- };
@@ -1,20 +0,0 @@
1
- import { type TModule } from "@coorax/core";
2
- import { UIPrimitivesRegistry } from "../registry/ui.primitives.registry";
3
- import { Button } from "../components/commons/button";
4
-
5
- declare module "@coorax/core" {
6
- interface ModuleMap {
7
- "ui-primitives": {};
8
- }
9
- }
10
-
11
- export const UIPrimitivesModule: TModule = {
12
- name: "ui-primitives",
13
- version: "1.0.0",
14
- requires: [],
15
-
16
- install() {
17
- UIPrimitivesRegistry.register("BlockActionButton", Button);
18
- UIPrimitivesRegistry.register("ToolBarButton", Button);
19
- },
20
- };
@@ -1,86 +0,0 @@
1
- import { type Field } from "@coorax/core";
2
- import type { RComponentProps } from "../../registry/primitives.registry";
3
- import { useRenderer } from "../../hooks/use-renderer";
4
- import { useBlock } from "../../hooks/use-block";
5
- import { useCallback, useEffect, useLayoutEffect, useRef } from "react";
6
- import { useEngine } from "../../components/corax-context-provider";
7
- import { useSlice } from "../../hooks/use-slice";
8
- import { offsetsToRange, rangeToOffsets } from "../../lib/selection.utils";
9
- import { blockRectFromBlockId } from "../../lifecycle/fields/lifecycle.utils";
10
-
11
- export function FieldPrimitive({ blockId }: RComponentProps) {
12
- const blockRef = useRef<HTMLDivElement | null>(null);
13
- const engine = useEngine();
14
- const renderer = useRenderer();
15
-
16
- const block = useBlock<Field>(blockId);
17
- const sel = useSlice("textSelection");
18
-
19
- const updateRange = useCallback(() => {
20
- if (!sel) return;
21
-
22
- const root = document.querySelector<HTMLElement>(
23
- `[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path!)}"]`,
24
- );
25
-
26
- if (!root || !root.contains(document.activeElement)) return;
27
-
28
- const domSel = document.getSelection();
29
- if (!domSel) return;
30
-
31
- if (domSel.rangeCount) {
32
- const cur = rangeToOffsets(root, domSel.getRangeAt(0));
33
- if (cur.start === sel.start && cur.end === sel.end) return; // déjà en place
34
- }
35
-
36
- const range = offsetsToRange(root, sel.start, sel.end);
37
- if (!range) return;
38
-
39
- domSel.removeAllRanges();
40
- domSel.addRange(range);
41
- }, [sel]);
42
-
43
- useLayoutEffect(() => {
44
- updateRange();
45
- }, [updateRange, engine]);
46
-
47
- useLayoutEffect(() => {
48
- if (!sel) return;
49
-
50
- const root = document.querySelector<HTMLElement>(
51
- `[id="${CSS.escape(sel.blockId)}"][data-text-path="${CSS.escape(sel.path!)}"]`,
52
- );
53
- if (!root) return;
54
-
55
- const range = offsetsToRange(root, sel.start, sel.end);
56
- if (!range) return;
57
-
58
- root.focus({ preventScroll: true });
59
- const domSel = document.getSelection()!;
60
- domSel.removeAllRanges();
61
- domSel.addRange(range);
62
- });
63
-
64
- useEffect(() => {
65
- const domEl = blockRef.current;
66
- if (!domEl) return;
67
-
68
- const observer = new ResizeObserver(() => {
69
- const rect = blockRectFromBlockId(blockId);
70
- if (!rect || !!engine.document.get().order.size) return;
71
-
72
- engine.commands.tryExecute("blocks.focus", { id: blockId, rect });
73
- });
74
-
75
- observer.observe(domEl);
76
-
77
- return () => {
78
- observer.unobserve(domEl);
79
- observer.disconnect();
80
- };
81
- }, [engine, blockId]);
82
-
83
- if (!blockId.startsWith("field") || !block) return null;
84
-
85
- return <div ref={blockRef}>{renderer.renderField(block)}</div>;
86
- }
@@ -1,8 +0,0 @@
1
- import type { BlockVariant } from "@coorax/core";
2
- import type { RComponent } from "../registry/primitives.registry";
3
- import { FieldPrimitive } from "./fields/field.primitives";
4
-
5
- //#TODO add the rest of primitives
6
- export const FieldsPrimitives: Partial<Record<BlockVariant, RComponent>> = {
7
- field: FieldPrimitive,
8
- };
@@ -1,9 +0,0 @@
1
- import type { JSXElementConstructor } from "react";
2
- import { GenericRegistry } from "./registry";
3
- import type { Block, BlockType, NodeCommonProps } from "@coorax/core";
4
-
5
- export interface FallbackComponentMap extends Record<BlockType, any> {}
6
- export type FallbackKey = keyof FallbackComponentMap;
7
- export type FallbackComponent = JSXElementConstructor<Block & NodeCommonProps>;
8
-
9
- export const FallbackComponentsRegistry = new GenericRegistry<FallbackKey, FallbackComponent>();
@@ -1,5 +0,0 @@
1
- export * from "./fallbacks.registry";
2
- export * from "./slots.registry";
3
- export * from "./primitives.registry";
4
- export * from "./ui.primitives.registry";
5
- export * from "./registry";
@@ -1,57 +0,0 @@
1
- import type { BlockTag, BlockId, BlockVariant } from "@coorax/core";
2
- import type { FieldLifeCycleEvents } from "../lifecycle/fields/lifecycle.fields.types";
3
-
4
- export type RComponentProps<T extends BlockTag = BlockTag> = FieldLifeCycleEvents<T> & {
5
- blockId: BlockId;
6
- };
7
-
8
- export type RComponent<T extends BlockTag = BlockTag> = (
9
- props: RComponentProps<T>,
10
- ) => React.ReactNode;
11
-
12
- interface CR {
13
- get<T extends BlockTag = BlockTag>(name: BlockVariant): RComponent<T> | null;
14
- post<T extends BlockTag = BlockTag>(name: BlockVariant, comp: RComponent<T>): void;
15
- // #TODO infer types correctly
16
- getAll(names: BlockVariant[]): (RComponent | null)[];
17
- batch(comps: Record<BlockVariant, RComponent>): void;
18
- delete(name: BlockVariant): void;
19
- }
20
-
21
- export class PrimitivesComponentsRegistry implements CR {
22
- private components: Map<symbol, RComponent> = new Map();
23
-
24
- get<T extends BlockTag = BlockTag>(name: BlockVariant): RComponent<T> | null {
25
- const sid = Symbol.for(name);
26
- const foundCOmp = this.components.get(sid);
27
- if (foundCOmp) {
28
- return foundCOmp;
29
- }
30
- return null;
31
- }
32
-
33
- getAll(names: BlockVariant[]): (RComponent | null)[] {
34
- return names.map((name) => this.get(name));
35
- }
36
-
37
- post<T extends BlockTag = BlockTag>(name: BlockVariant, comp: RComponent<T>) {
38
- if (comp.length < 1) {
39
- throw new Error("Components arguments must be greater than 1");
40
- }
41
-
42
- const sid = Symbol.for(name);
43
- this.components.set(sid, comp as RComponent);
44
- }
45
-
46
- delete(name: BlockVariant) {
47
- const sid = Symbol.for(name);
48
- this.components.delete(sid);
49
- }
50
-
51
- batch(comps: Record<BlockVariant, RComponent>) {
52
- for (const [key, value] of Object.entries(comps)) {
53
- const sid = Symbol.for(key);
54
- this.components.set(sid, value);
55
- }
56
- }
57
- }
@@ -1,44 +0,0 @@
1
- export type RegistryListener = () => void;
2
- export type RegistryDisposer = () => void;
3
-
4
- export interface GenericRegistryInterface<K, V> {
5
- get(key: K): V | undefined;
6
- register(key: K, value: V): RegistryDisposer;
7
- subscribe(key: K, fn: RegistryListener): RegistryDisposer;
8
- }
9
-
10
- export class GenericRegistry<K, V> implements GenericRegistryInterface<K, V> {
11
- private items = new Map<K, V>();
12
- private listeners = new Map<K, Set<RegistryListener>>();
13
-
14
- private notify(key: K) {
15
- this.listeners.get(key)?.forEach((l) => l());
16
- }
17
-
18
- get(key: K): V | undefined {
19
- return this.items.get(key);
20
- }
21
-
22
- register(key: K, value: V): RegistryDisposer {
23
- this.items.set(key, value);
24
- this.notify(key);
25
-
26
- return () => {
27
- this.items.delete(key);
28
- this.notify(key);
29
- };
30
- }
31
-
32
- subscribe(key: K, fn: RegistryListener): RegistryDisposer {
33
- const set = this.listeners.get(key) ?? new Set();
34
- set.add(fn);
35
- this.listeners.set(key, set);
36
-
37
- return () => {
38
- set.delete(fn);
39
- if (set.size === 0) {
40
- this.listeners.delete(key);
41
- }
42
- };
43
- }
44
- }
@@ -1,6 +0,0 @@
1
- import type { SlotKey } from "@coorax/core";
2
- import { GenericRegistry } from "./registry";
3
- import type { JSXElementConstructor } from "react";
4
-
5
- // Use a broad type to accept any React component with any SlotBaseProps variation
6
- export const SlotsComponentRegistry = new GenericRegistry<SlotKey, JSXElementConstructor<any>>();
@@ -1,34 +0,0 @@
1
- import { Engine, FieldsUtils } from "@coorax/core";
2
- import { describe, expect, it } from "vitest";
3
- import { ReactRenderer } from "./renderer";
4
- import React from "react";
5
-
6
- describe("ReactRenderer", () => {
7
- const engine = new Engine();
8
- const renderer = new ReactRenderer(engine);
9
-
10
- describe("RenderBlock", () => {
11
- it("should create a valid react element from field", () => {
12
- const field = FieldsUtils.NewHeadingField();
13
-
14
- const element = renderer.renderField(field);
15
- expect(React.isValidElement(element)).toBe(true);
16
- expect((element.props as any).id).toBe(field.id);
17
- expect(element.key).toBe(field.id);
18
- });
19
-
20
- it("should apply pseudoStyles as a generated CSS class", () => {
21
- const divider = FieldsUtils.NewDividerField();
22
-
23
- const element = renderer.renderField(divider);
24
- expect(React.isValidElement(element)).toBe(true);
25
- const props = element.props as any;
26
- expect(props.id).toBe(divider.id);
27
- expect(typeof props.className).toBe("string");
28
- // Should include the generated emotion class (e.g. css-...)
29
- expect(props.className).toMatch(/css-[a-z0-9]+/);
30
- // Inline style should NOT contain pseudo selectors like :before
31
- expect(props.style[":before"]).toBeUndefined();
32
- });
33
- });
34
- });