@coorax/render-react 0.0.0-canary.1
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/index.d.ts +3 -0
- package/dist/index.js +693 -0
- package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +14 -0
- package/dist/lifecycle/index.d.ts +1 -0
- package/dist/registry/errors.registry.d.ts +8 -0
- package/dist/registry/fallbacks.registry.d.ts +9 -0
- package/dist/registry/fields.registry.d.ts +12 -0
- package/dist/registry/index.d.ts +5 -0
- package/dist/registry/primitives.registry.d.ts +22 -0
- package/dist/registry/registry.d.ts +15 -0
- package/dist/renderer/code-content.d.ts +3 -0
- package/dist/renderer/default-fields.d.ts +12 -0
- package/dist/renderer/index.d.ts +5 -0
- package/dist/renderer/renderer.d.ts +23 -0
- package/dist/renderer/renderer.document.d.ts +12 -0
- package/dist/renderer/renderer.test.d.ts +1 -0
- package/dist/renderer/renderer.types.d.ts +18 -0
- package/dist/renderer/renderer.utils.d.ts +14 -0
- package/dist/renderer/text-content.d.ts +3 -0
- package/dist/renderer/utils/blockquote.renderer.utils.d.ts +8 -0
- package/dist/renderer/utils/caption.renderer.utils.d.ts +8 -0
- package/dist/renderer/utils/code.renderer.utils.d.ts +8 -0
- package/dist/renderer/utils/divider.renderer.utils.d.ts +6 -0
- package/dist/renderer/utils/document.renderer.utils.d.ts +6 -0
- package/dist/renderer/utils/iframe.renderer.utils.d.ts +6 -0
- package/dist/renderer/utils/link.renderer.utils.d.ts +6 -0
- package/package.json +57 -0
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,693 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/renderer/renderer.tsx
|
|
4
|
+
import React3 from "react";
|
|
5
|
+
|
|
6
|
+
// src/registry/primitives.registry.tsx
|
|
7
|
+
class PrimitivesComponentsRegistry {
|
|
8
|
+
components = new Map;
|
|
9
|
+
get(name) {
|
|
10
|
+
const sid = Symbol.for(name);
|
|
11
|
+
const foundCOmp = this.components.get(sid);
|
|
12
|
+
if (foundCOmp) {
|
|
13
|
+
return foundCOmp;
|
|
14
|
+
}
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
getAll(names) {
|
|
18
|
+
return names.map((name) => this.get(name));
|
|
19
|
+
}
|
|
20
|
+
post(name, comp) {
|
|
21
|
+
if (comp.length < 1) {
|
|
22
|
+
throw new Error("Components arguments must be greater than 1");
|
|
23
|
+
}
|
|
24
|
+
const sid = Symbol.for(name);
|
|
25
|
+
this.components.set(sid, comp);
|
|
26
|
+
}
|
|
27
|
+
delete(name) {
|
|
28
|
+
const sid = Symbol.for(name);
|
|
29
|
+
this.components.delete(sid);
|
|
30
|
+
}
|
|
31
|
+
batch(comps) {
|
|
32
|
+
for (const [key, value] of Object.entries(comps)) {
|
|
33
|
+
const sid = Symbol.for(key);
|
|
34
|
+
this.components.set(sid, value);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// src/registry/registry.ts
|
|
40
|
+
class GenericRegistry {
|
|
41
|
+
items = new Map;
|
|
42
|
+
listeners = new Map;
|
|
43
|
+
notify(key) {
|
|
44
|
+
this.listeners.get(key)?.forEach((l) => l());
|
|
45
|
+
}
|
|
46
|
+
get(key) {
|
|
47
|
+
return this.items.get(key);
|
|
48
|
+
}
|
|
49
|
+
register(key, value) {
|
|
50
|
+
this.items.set(key, value);
|
|
51
|
+
this.notify(key);
|
|
52
|
+
return () => {
|
|
53
|
+
this.items.delete(key);
|
|
54
|
+
this.notify(key);
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
subscribe(key, fn) {
|
|
58
|
+
const set = this.listeners.get(key) ?? new Set;
|
|
59
|
+
set.add(fn);
|
|
60
|
+
this.listeners.set(key, set);
|
|
61
|
+
return () => {
|
|
62
|
+
set.delete(fn);
|
|
63
|
+
if (set.size === 0) {
|
|
64
|
+
this.listeners.delete(key);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// src/registry/fallbacks.registry.tsx
|
|
71
|
+
var FallbackComponentsRegistry = new GenericRegistry;
|
|
72
|
+
// src/registry/errors.registry.tsx
|
|
73
|
+
var ErrorComponentsRegistry = new GenericRegistry;
|
|
74
|
+
// src/registry/fields.registry.ts
|
|
75
|
+
class FieldRenderersRegistry extends GenericRegistry {
|
|
76
|
+
}
|
|
77
|
+
// src/renderer/default-fields.tsx
|
|
78
|
+
import React2 from "react";
|
|
79
|
+
import {
|
|
80
|
+
DEFAULT_IMAGE_PREVIEW
|
|
81
|
+
} from "@coorax/schema";
|
|
82
|
+
import { QuoteIcon } from "lucide-react";
|
|
83
|
+
|
|
84
|
+
// src/renderer/renderer.utils.tsx
|
|
85
|
+
import {
|
|
86
|
+
UTILS,
|
|
87
|
+
collectCoraxPseudoStyle
|
|
88
|
+
} from "@coorax/schema";
|
|
89
|
+
import { cn } from "cn";
|
|
90
|
+
function getTextFieldProps(block, ctx) {
|
|
91
|
+
const {
|
|
92
|
+
style,
|
|
93
|
+
pseudoStyle,
|
|
94
|
+
className,
|
|
95
|
+
children: _,
|
|
96
|
+
placeholder,
|
|
97
|
+
contentEditable,
|
|
98
|
+
"data-text-path": textPath,
|
|
99
|
+
...rest
|
|
100
|
+
} = block.props;
|
|
101
|
+
const uiStyles = ctx.styles(block.type);
|
|
102
|
+
const _pseudoStyle = {
|
|
103
|
+
...uiStyles.pseudoStyle,
|
|
104
|
+
...pseudoStyle
|
|
105
|
+
};
|
|
106
|
+
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
107
|
+
const baseProps = {
|
|
108
|
+
id: block.id,
|
|
109
|
+
key: block.id,
|
|
110
|
+
"data-block-type": block.type,
|
|
111
|
+
style: {
|
|
112
|
+
...uiStyles.style,
|
|
113
|
+
...style,
|
|
114
|
+
...contentEditable ? { cursor: "auto", userSelect: "auto" } : null
|
|
115
|
+
},
|
|
116
|
+
className: cn(uiStyles.className, className, pseudoClassName)
|
|
117
|
+
};
|
|
118
|
+
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
119
|
+
const isEdit = ctx.mode === "edit";
|
|
120
|
+
const editableProps = {
|
|
121
|
+
...rest,
|
|
122
|
+
...isEdit ? {
|
|
123
|
+
spellCheck: false,
|
|
124
|
+
suppressContentEditableWarning: true,
|
|
125
|
+
"data-placeholder": placeholder || "Tell the news here",
|
|
126
|
+
"data-text-path": textPath,
|
|
127
|
+
contentEditable: !!contentEditable,
|
|
128
|
+
autoFocus: true
|
|
129
|
+
} : {}
|
|
130
|
+
};
|
|
131
|
+
const handlers = isEdit ? ctx.events?.(block) ?? {} : {};
|
|
132
|
+
return {
|
|
133
|
+
...baseProps,
|
|
134
|
+
...containerProps,
|
|
135
|
+
...editableProps,
|
|
136
|
+
...handlers
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
function getMediaFieldProps(block, ctx) {
|
|
140
|
+
const { style, pseudoStyle, className, isLoaded: _, isError: __, ...rest } = block.props;
|
|
141
|
+
const uiStyles = ctx.styles(block.type);
|
|
142
|
+
const _pseudoStyle = {
|
|
143
|
+
...uiStyles.pseudoStyle,
|
|
144
|
+
...pseudoStyle
|
|
145
|
+
};
|
|
146
|
+
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
147
|
+
const isEdit = ctx.mode === "edit";
|
|
148
|
+
const baseProps = {
|
|
149
|
+
id: block.id,
|
|
150
|
+
key: block.id,
|
|
151
|
+
"data-block-type": block.type,
|
|
152
|
+
style: {
|
|
153
|
+
...uiStyles.style,
|
|
154
|
+
...style
|
|
155
|
+
},
|
|
156
|
+
className: cn(uiStyles.className, className, pseudoClassName),
|
|
157
|
+
...isEdit ? { tabIndex: 0 } : {}
|
|
158
|
+
};
|
|
159
|
+
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
160
|
+
const handlers = isEdit ? ctx.events?.(block) ?? {} : {};
|
|
161
|
+
return {
|
|
162
|
+
...baseProps,
|
|
163
|
+
...containerProps,
|
|
164
|
+
...rest,
|
|
165
|
+
...handlers
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function resolveCoraxPseudoStyle(style) {
|
|
169
|
+
if (!style || Object.keys(style).length === 0)
|
|
170
|
+
return;
|
|
171
|
+
return collectCoraxPseudoStyle(style);
|
|
172
|
+
}
|
|
173
|
+
function normalizeCoraxPseudoStyles(style) {
|
|
174
|
+
return UTILS.ObjectEntries(style).reduce((_style, [key, value]) => {
|
|
175
|
+
_style[key] = typeof value === "string" ? value : typeof value === "object" ? normalizeCoraxPseudoStyles(value) : String(value);
|
|
176
|
+
return _style;
|
|
177
|
+
}, {});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// src/renderer/utils/link.renderer.utils.tsx
|
|
181
|
+
import { cn as cn2 } from "cn";
|
|
182
|
+
function getLinkFieldProps(block, ctx) {
|
|
183
|
+
const { style, pseudoStyle, className, isLoaded: _, isError: __, children: _c, contentEditable, placeholder, ...rest } = block.props;
|
|
184
|
+
const uiStyles = ctx.styles(block.type);
|
|
185
|
+
const _pseudoStyle = {
|
|
186
|
+
...uiStyles.pseudoStyle,
|
|
187
|
+
...pseudoStyle
|
|
188
|
+
};
|
|
189
|
+
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
190
|
+
const isEdit = ctx.mode === "edit";
|
|
191
|
+
const textPath = block.props["data-text-path"] || "";
|
|
192
|
+
const editableProps = {
|
|
193
|
+
...rest,
|
|
194
|
+
...isEdit ? {
|
|
195
|
+
spellCheck: false,
|
|
196
|
+
suppressContentEditableWarning: true,
|
|
197
|
+
"data-placeholder": placeholder || "Tell the news here",
|
|
198
|
+
"data-text-path": textPath,
|
|
199
|
+
contentEditable: !!contentEditable,
|
|
200
|
+
autoFocus: true
|
|
201
|
+
} : {}
|
|
202
|
+
};
|
|
203
|
+
const baseProps = {
|
|
204
|
+
id: block.id,
|
|
205
|
+
key: block.id,
|
|
206
|
+
"data-block-type": block.type,
|
|
207
|
+
style: {
|
|
208
|
+
...uiStyles.style,
|
|
209
|
+
...style,
|
|
210
|
+
...contentEditable ? { cursor: "auto", userSelect: "auto", display: "block" } : null
|
|
211
|
+
},
|
|
212
|
+
className: cn2(uiStyles.className, className, pseudoClassName),
|
|
213
|
+
...isEdit ? { tabIndex: 0 } : {},
|
|
214
|
+
title: block.props?.alt || block.props.href
|
|
215
|
+
};
|
|
216
|
+
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
217
|
+
const handlers = isEdit ? ctx.events?.(block) ?? {} : {};
|
|
218
|
+
return {
|
|
219
|
+
...baseProps,
|
|
220
|
+
...containerProps,
|
|
221
|
+
...editableProps,
|
|
222
|
+
...handlers
|
|
223
|
+
};
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// src/renderer/utils/blockquote.renderer.utils.tsx
|
|
227
|
+
import { cn as cn3 } from "cn";
|
|
228
|
+
function getBlockquoteFieldProps(block, ctx) {
|
|
229
|
+
const {
|
|
230
|
+
style,
|
|
231
|
+
pseudoStyle,
|
|
232
|
+
className,
|
|
233
|
+
children: _,
|
|
234
|
+
placeholder,
|
|
235
|
+
contentEditable,
|
|
236
|
+
cite: __,
|
|
237
|
+
"data-text-path": textPath,
|
|
238
|
+
...rest
|
|
239
|
+
} = block.props;
|
|
240
|
+
const uiStyles = ctx.styles(block.type);
|
|
241
|
+
const _pseudoStyle = {
|
|
242
|
+
...uiStyles.pseudoStyle,
|
|
243
|
+
...pseudoStyle
|
|
244
|
+
};
|
|
245
|
+
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
246
|
+
const baseProps = {
|
|
247
|
+
id: block.id,
|
|
248
|
+
key: block.id,
|
|
249
|
+
"data-block-type": block.type,
|
|
250
|
+
style: {
|
|
251
|
+
...uiStyles.style,
|
|
252
|
+
...style,
|
|
253
|
+
...contentEditable ? { cursor: "auto", userSelect: "auto" } : null
|
|
254
|
+
},
|
|
255
|
+
className: cn3(uiStyles.className, className, pseudoClassName)
|
|
256
|
+
};
|
|
257
|
+
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
258
|
+
const isEdit = ctx.mode === "edit";
|
|
259
|
+
const editableProps = {
|
|
260
|
+
...rest,
|
|
261
|
+
...isEdit ? {
|
|
262
|
+
spellCheck: false,
|
|
263
|
+
suppressContentEditableWarning: true,
|
|
264
|
+
"data-placeholder": placeholder || "Write citation here...",
|
|
265
|
+
"data-text-path": textPath,
|
|
266
|
+
contentEditable: !!contentEditable,
|
|
267
|
+
autoFocus: true
|
|
268
|
+
} : {}
|
|
269
|
+
};
|
|
270
|
+
const handlers = isEdit ? ctx.events?.(block) ?? {} : {};
|
|
271
|
+
return {
|
|
272
|
+
...baseProps,
|
|
273
|
+
...containerProps,
|
|
274
|
+
...editableProps,
|
|
275
|
+
...handlers
|
|
276
|
+
};
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
// src/renderer/utils/caption.renderer.utils.tsx
|
|
280
|
+
import { cn as cn4 } from "cn";
|
|
281
|
+
function getCaptionFieldProps(block, ctx) {
|
|
282
|
+
const {
|
|
283
|
+
style,
|
|
284
|
+
pseudoStyle,
|
|
285
|
+
className,
|
|
286
|
+
children: _,
|
|
287
|
+
placeholder,
|
|
288
|
+
contentEditable,
|
|
289
|
+
mediaId: _mediaId,
|
|
290
|
+
"data-text-path": textPath,
|
|
291
|
+
...rest
|
|
292
|
+
} = block.props;
|
|
293
|
+
const uiStyles = ctx.styles(block.type);
|
|
294
|
+
const _pseudoStyle = {
|
|
295
|
+
...uiStyles.pseudoStyle,
|
|
296
|
+
...pseudoStyle
|
|
297
|
+
};
|
|
298
|
+
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
299
|
+
const baseProps = {
|
|
300
|
+
id: block.id,
|
|
301
|
+
key: block.id,
|
|
302
|
+
"data-block-type": block.type,
|
|
303
|
+
style: {
|
|
304
|
+
...uiStyles.style,
|
|
305
|
+
...style,
|
|
306
|
+
...contentEditable ? { cursor: "auto", userSelect: "auto" } : null
|
|
307
|
+
},
|
|
308
|
+
className: cn4(uiStyles.className, className, pseudoClassName)
|
|
309
|
+
};
|
|
310
|
+
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
311
|
+
const isEdit = ctx.mode === "edit";
|
|
312
|
+
const editableProps = {
|
|
313
|
+
...rest,
|
|
314
|
+
...isEdit ? {
|
|
315
|
+
spellCheck: false,
|
|
316
|
+
suppressContentEditableWarning: true,
|
|
317
|
+
"data-placeholder": placeholder || "Write a caption...",
|
|
318
|
+
"data-text-path": textPath,
|
|
319
|
+
contentEditable: !!contentEditable,
|
|
320
|
+
autoFocus: true
|
|
321
|
+
} : {}
|
|
322
|
+
};
|
|
323
|
+
const handlers = isEdit ? ctx.events?.(block) ?? {} : {};
|
|
324
|
+
return {
|
|
325
|
+
...baseProps,
|
|
326
|
+
...containerProps,
|
|
327
|
+
...editableProps,
|
|
328
|
+
...handlers
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
// src/renderer/utils/divider.renderer.utils.tsx
|
|
333
|
+
import { cn as cn5 } from "cn";
|
|
334
|
+
function getDividerFieldProps(block, ctx) {
|
|
335
|
+
const { style, pseudoStyle, className, ...rest } = block.props;
|
|
336
|
+
const uiStyles = ctx.styles(block.type);
|
|
337
|
+
const _pseudoStyle = {
|
|
338
|
+
...uiStyles.pseudoStyle,
|
|
339
|
+
...pseudoStyle
|
|
340
|
+
};
|
|
341
|
+
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
342
|
+
const isEdit = ctx.mode === "edit";
|
|
343
|
+
const baseProps = {
|
|
344
|
+
id: block.id,
|
|
345
|
+
key: block.id,
|
|
346
|
+
"data-block-type": block.type,
|
|
347
|
+
style: {
|
|
348
|
+
...uiStyles.style,
|
|
349
|
+
...style
|
|
350
|
+
},
|
|
351
|
+
className: cn5(uiStyles.className, className, pseudoClassName),
|
|
352
|
+
...isEdit ? { tabIndex: 0 } : {}
|
|
353
|
+
};
|
|
354
|
+
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
355
|
+
const handlers = isEdit ? ctx.events?.(block) ?? {} : {};
|
|
356
|
+
return {
|
|
357
|
+
...baseProps,
|
|
358
|
+
...containerProps,
|
|
359
|
+
...rest,
|
|
360
|
+
...handlers
|
|
361
|
+
};
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
// src/renderer/utils/iframe.renderer.utils.tsx
|
|
365
|
+
import { cn as cn6 } from "cn";
|
|
366
|
+
function getIFrameFieldProps(block, ctx) {
|
|
367
|
+
const { style, pseudoStyle, className, isLoaded: _, isError: __, ...rest } = block.props;
|
|
368
|
+
const uiStyles = ctx.styles(block.type);
|
|
369
|
+
const _pseudoStyle = {
|
|
370
|
+
...uiStyles.pseudoStyle,
|
|
371
|
+
...pseudoStyle
|
|
372
|
+
};
|
|
373
|
+
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
374
|
+
const isEdit = ctx.mode === "edit";
|
|
375
|
+
const baseProps = {
|
|
376
|
+
id: block.id,
|
|
377
|
+
key: block.id,
|
|
378
|
+
"data-block-type": block.type,
|
|
379
|
+
style: {
|
|
380
|
+
...uiStyles.style,
|
|
381
|
+
...style
|
|
382
|
+
},
|
|
383
|
+
className: cn6(uiStyles.className, className, pseudoClassName),
|
|
384
|
+
...isEdit ? { tabIndex: 0 } : {}
|
|
385
|
+
};
|
|
386
|
+
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
387
|
+
const handlers = isEdit ? ctx.events?.(block) ?? {} : {};
|
|
388
|
+
return {
|
|
389
|
+
...baseProps,
|
|
390
|
+
...containerProps,
|
|
391
|
+
...rest,
|
|
392
|
+
...handlers
|
|
393
|
+
};
|
|
394
|
+
}
|
|
395
|
+
|
|
396
|
+
// src/renderer/text-content.tsx
|
|
397
|
+
import React from "react";
|
|
398
|
+
import { segments } from "@coorax/schema";
|
|
399
|
+
import { jsxDEV } from "react/jsx-dev-runtime";
|
|
400
|
+
var defaults = {
|
|
401
|
+
bold: "strong",
|
|
402
|
+
italic: "em",
|
|
403
|
+
underline: "u",
|
|
404
|
+
code: "code",
|
|
405
|
+
link: "span",
|
|
406
|
+
initial: "span"
|
|
407
|
+
};
|
|
408
|
+
var RANK = {
|
|
409
|
+
link: 0,
|
|
410
|
+
bold: 1,
|
|
411
|
+
italic: 2,
|
|
412
|
+
underline: 3,
|
|
413
|
+
code: 4,
|
|
414
|
+
initial: 5
|
|
415
|
+
};
|
|
416
|
+
function formatText(text) {
|
|
417
|
+
return text;
|
|
418
|
+
}
|
|
419
|
+
function renderSegment(seg, key) {
|
|
420
|
+
const marks = [...seg.marks].sort((a, b) => (RANK[a.type] ?? 9) - (RANK[b.type] ?? 9));
|
|
421
|
+
const node = marks.reduceRight((child, mark) => {
|
|
422
|
+
const Comp = defaults[mark.type];
|
|
423
|
+
return Comp ? /* @__PURE__ */ jsxDEV(Comp, {
|
|
424
|
+
...mark.attrs,
|
|
425
|
+
children: child
|
|
426
|
+
}, undefined, false, undefined, this) : child;
|
|
427
|
+
}, formatText(seg.text));
|
|
428
|
+
return /* @__PURE__ */ jsxDEV(React.Fragment, {
|
|
429
|
+
children: node
|
|
430
|
+
}, key, false, undefined, this);
|
|
431
|
+
}
|
|
432
|
+
function renderTextContent(text) {
|
|
433
|
+
if (!text?.text)
|
|
434
|
+
return "";
|
|
435
|
+
return segments(text).map(renderSegment);
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
// src/renderer/code-content.tsx
|
|
439
|
+
import {
|
|
440
|
+
CODE_THEMES,
|
|
441
|
+
tokenizeCode
|
|
442
|
+
} from "@coorax/schema";
|
|
443
|
+
import { jsxDEV as jsxDEV2 } from "react/jsx-dev-runtime";
|
|
444
|
+
function renderCodeContent(text, theme = "dark") {
|
|
445
|
+
if (!text?.text)
|
|
446
|
+
return "";
|
|
447
|
+
const palette = CODE_THEMES[theme] ?? CODE_THEMES.dark;
|
|
448
|
+
const tokens = tokenizeCode(text.text);
|
|
449
|
+
return tokens.map((token, i) => /* @__PURE__ */ jsxDEV2("span", {
|
|
450
|
+
style: { color: palette[token.type] },
|
|
451
|
+
children: token.value
|
|
452
|
+
}, i, false, undefined, this));
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// src/renderer/utils/code.renderer.utils.tsx
|
|
456
|
+
import { cn as cn7 } from "cn";
|
|
457
|
+
function getCodeFieldProps(block, ctx) {
|
|
458
|
+
const {
|
|
459
|
+
style,
|
|
460
|
+
pseudoStyle,
|
|
461
|
+
className,
|
|
462
|
+
children: _,
|
|
463
|
+
placeholder,
|
|
464
|
+
contentEditable,
|
|
465
|
+
"data-text-path": textPath,
|
|
466
|
+
theme: _theme,
|
|
467
|
+
...rest
|
|
468
|
+
} = block.props;
|
|
469
|
+
const uiStyles = ctx.styles(block.type);
|
|
470
|
+
const _pseudoStyle = {
|
|
471
|
+
...uiStyles.pseudoStyle,
|
|
472
|
+
...pseudoStyle
|
|
473
|
+
};
|
|
474
|
+
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
475
|
+
const baseProps = {
|
|
476
|
+
id: block.id,
|
|
477
|
+
key: block.id,
|
|
478
|
+
"data-block-type": block.type,
|
|
479
|
+
style: {
|
|
480
|
+
...uiStyles.style,
|
|
481
|
+
...style,
|
|
482
|
+
...contentEditable ? { cursor: "auto", userSelect: "auto" } : null
|
|
483
|
+
},
|
|
484
|
+
className: cn7(uiStyles.className, className, pseudoClassName)
|
|
485
|
+
};
|
|
486
|
+
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
487
|
+
const isEdit = ctx.mode === "edit";
|
|
488
|
+
const editableProps = {
|
|
489
|
+
...rest,
|
|
490
|
+
...isEdit ? {
|
|
491
|
+
spellCheck: false,
|
|
492
|
+
suppressContentEditableWarning: true,
|
|
493
|
+
"data-placeholder": placeholder || "Write code here...",
|
|
494
|
+
"data-text-path": textPath,
|
|
495
|
+
contentEditable: !!contentEditable,
|
|
496
|
+
autoFocus: true
|
|
497
|
+
} : {}
|
|
498
|
+
};
|
|
499
|
+
const handlers = isEdit ? ctx.events?.(block) ?? {} : {};
|
|
500
|
+
return {
|
|
501
|
+
...baseProps,
|
|
502
|
+
...containerProps,
|
|
503
|
+
...editableProps,
|
|
504
|
+
...handlers
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
|
|
508
|
+
// src/renderer/default-fields.tsx
|
|
509
|
+
import { jsxDEV as jsxDEV3 } from "react/jsx-dev-runtime";
|
|
510
|
+
var renderTextField = (block, ctx) => {
|
|
511
|
+
const field = block;
|
|
512
|
+
return React2.createElement(field.tag, {
|
|
513
|
+
...getTextFieldProps(field, ctx),
|
|
514
|
+
key: field.id
|
|
515
|
+
}, renderTextContent(field.props.children));
|
|
516
|
+
};
|
|
517
|
+
var renderBlockquoteField = (block, ctx) => {
|
|
518
|
+
const field = block;
|
|
519
|
+
return /* @__PURE__ */ jsxDEV3(field.tag, {
|
|
520
|
+
cite: field.props.cite,
|
|
521
|
+
className: "w-full flex relative gap-1",
|
|
522
|
+
children: [
|
|
523
|
+
/* @__PURE__ */ jsxDEV3(QuoteIcon, {
|
|
524
|
+
className: "rotate-180 text-muted-foreground size-4"
|
|
525
|
+
}, undefined, false, undefined, this),
|
|
526
|
+
React2.createElement("p", {
|
|
527
|
+
...getBlockquoteFieldProps(field, ctx),
|
|
528
|
+
key: field.id
|
|
529
|
+
}, renderTextContent(field.props.children)),
|
|
530
|
+
/* @__PURE__ */ jsxDEV3(QuoteIcon, {
|
|
531
|
+
className: "ml-auto mt-auto text-muted-foreground size-4"
|
|
532
|
+
}, undefined, false, undefined, this)
|
|
533
|
+
]
|
|
534
|
+
}, undefined, true, undefined, this);
|
|
535
|
+
};
|
|
536
|
+
var renderMediaField = (block, ctx) => {
|
|
537
|
+
const field = block;
|
|
538
|
+
const shouldUseDefault = !field.props?.src?.trim();
|
|
539
|
+
return React2.createElement(field.tag, {
|
|
540
|
+
...getMediaFieldProps(field, ctx),
|
|
541
|
+
...shouldUseDefault ? { src: DEFAULT_IMAGE_PREVIEW } : {},
|
|
542
|
+
key: field.id
|
|
543
|
+
});
|
|
544
|
+
};
|
|
545
|
+
var renderIFrameField = (block, ctx) => {
|
|
546
|
+
const field = block;
|
|
547
|
+
const shouldUseDefault = !field.props?.src?.trim();
|
|
548
|
+
return React2.createElement(field.tag, {
|
|
549
|
+
...getIFrameFieldProps(field, ctx),
|
|
550
|
+
...shouldUseDefault ? { src: DEFAULT_IMAGE_PREVIEW } : {},
|
|
551
|
+
key: field.id
|
|
552
|
+
});
|
|
553
|
+
};
|
|
554
|
+
var renderDividerField = (block, ctx) => {
|
|
555
|
+
const field = block;
|
|
556
|
+
return React2.createElement(field.tag, {
|
|
557
|
+
...getDividerFieldProps(field, ctx),
|
|
558
|
+
key: field.id
|
|
559
|
+
});
|
|
560
|
+
};
|
|
561
|
+
var renderLinkField = (block, ctx) => {
|
|
562
|
+
const field = block;
|
|
563
|
+
const shouldUseDefault = !field.props?.href?.trim();
|
|
564
|
+
const isEdit = ctx.mode === "edit";
|
|
565
|
+
if (isEdit) {
|
|
566
|
+
return React2.createElement("p", {
|
|
567
|
+
...getLinkFieldProps(field, ctx),
|
|
568
|
+
...shouldUseDefault ? { href: "#" } : {},
|
|
569
|
+
key: field.id
|
|
570
|
+
}, renderTextContent(field.props.children));
|
|
571
|
+
}
|
|
572
|
+
return React2.createElement(field.tag, {
|
|
573
|
+
...getLinkFieldProps(field, ctx),
|
|
574
|
+
key: field.id
|
|
575
|
+
}, renderTextContent(field.props.children));
|
|
576
|
+
};
|
|
577
|
+
var renderCodeField = (block, ctx) => {
|
|
578
|
+
const field = block;
|
|
579
|
+
return React2.createElement(field.tag, {
|
|
580
|
+
...getCodeFieldProps(field, ctx),
|
|
581
|
+
key: field.id
|
|
582
|
+
}, renderCodeContent(field.props.children, field.props.theme));
|
|
583
|
+
};
|
|
584
|
+
var renderCaptionField = (block, ctx) => {
|
|
585
|
+
const field = block;
|
|
586
|
+
return React2.createElement(field.tag, {
|
|
587
|
+
...getCaptionFieldProps(field, ctx),
|
|
588
|
+
key: field.id
|
|
589
|
+
}, renderTextContent(field.props.children));
|
|
590
|
+
};
|
|
591
|
+
var defaultFieldRenderers = {
|
|
592
|
+
text: renderTextField,
|
|
593
|
+
heading: renderTextField,
|
|
594
|
+
video: renderMediaField,
|
|
595
|
+
image: renderMediaField,
|
|
596
|
+
iframe: renderIFrameField,
|
|
597
|
+
divider: renderDividerField,
|
|
598
|
+
link: renderLinkField,
|
|
599
|
+
blockquote: renderBlockquoteField,
|
|
600
|
+
code: renderCodeField,
|
|
601
|
+
caption: renderCaptionField
|
|
602
|
+
};
|
|
603
|
+
|
|
604
|
+
// src/renderer/renderer.tsx
|
|
605
|
+
import { jsxDEV as jsxDEV4, Fragment } from "react/jsx-dev-runtime";
|
|
606
|
+
|
|
607
|
+
class ReactRenderer {
|
|
608
|
+
ctx;
|
|
609
|
+
document;
|
|
610
|
+
primitives = new PrimitivesComponentsRegistry;
|
|
611
|
+
fields = new FieldRenderersRegistry;
|
|
612
|
+
constructor(ctx, document) {
|
|
613
|
+
this.ctx = ctx;
|
|
614
|
+
this.document = document;
|
|
615
|
+
for (const [type, renderer] of Object.entries(defaultFieldRenderers)) {
|
|
616
|
+
if (renderer)
|
|
617
|
+
this.fields.register(type, renderer);
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
renderContainer(contanier) {
|
|
621
|
+
throw new Error("Method not implemented." + contanier.name);
|
|
622
|
+
}
|
|
623
|
+
renderTree(key = 0) {
|
|
624
|
+
const children = Array.from(this.document.get().order).map((id) => {
|
|
625
|
+
const block = this.document.getBlock(id);
|
|
626
|
+
if (!block)
|
|
627
|
+
return /* @__PURE__ */ jsxDEV4(Fragment, {}, undefined, false, undefined, this);
|
|
628
|
+
const Comp = this.primitives.get(block.variant);
|
|
629
|
+
if (!Comp)
|
|
630
|
+
return /* @__PURE__ */ jsxDEV4(Fragment, {}, undefined, false, undefined, this);
|
|
631
|
+
return /* @__PURE__ */ jsxDEV4(Comp, {
|
|
632
|
+
blockId: id
|
|
633
|
+
}, id, false, undefined, this);
|
|
634
|
+
});
|
|
635
|
+
return React3.createElement(React3.Fragment, { key }, ...children);
|
|
636
|
+
}
|
|
637
|
+
renderField(_field) {
|
|
638
|
+
const field = typeof _field === "string" ? this.document.getBlock(_field) : _field;
|
|
639
|
+
if (!field || field.variant !== "field")
|
|
640
|
+
return /* @__PURE__ */ jsxDEV4(Fragment, {}, undefined, false, undefined, this);
|
|
641
|
+
const isFieldReady = !!field.props?.isLoaded;
|
|
642
|
+
const isError = !!field.props?.isError;
|
|
643
|
+
const renderer = this.fields.get(field.type);
|
|
644
|
+
const child = renderer ? renderer(field, this.ctx) : /* @__PURE__ */ jsxDEV4(Fragment, {}, undefined, false, undefined, this);
|
|
645
|
+
if (isError) {
|
|
646
|
+
const Error2 = ErrorComponentsRegistry.get(field.type);
|
|
647
|
+
if (Error2)
|
|
648
|
+
return /* @__PURE__ */ jsxDEV4(Error2, {
|
|
649
|
+
...field,
|
|
650
|
+
children: child
|
|
651
|
+
}, undefined, false, undefined, this);
|
|
652
|
+
}
|
|
653
|
+
if (!isFieldReady) {
|
|
654
|
+
const Fallback = FallbackComponentsRegistry.get(field.type);
|
|
655
|
+
if (Fallback)
|
|
656
|
+
return /* @__PURE__ */ jsxDEV4(Fallback, {
|
|
657
|
+
...field,
|
|
658
|
+
children: child
|
|
659
|
+
}, undefined, false, undefined, this);
|
|
660
|
+
}
|
|
661
|
+
return child;
|
|
662
|
+
}
|
|
663
|
+
renderNode(node, key = null) {
|
|
664
|
+
return React3.createElement(node.tag, {
|
|
665
|
+
style: node.props.style,
|
|
666
|
+
className: node.props.className,
|
|
667
|
+
key: key ?? node.id
|
|
668
|
+
}, node.props.text);
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
// src/index.ts
|
|
672
|
+
"use client";
|
|
673
|
+
export {
|
|
674
|
+
resolveCoraxPseudoStyle,
|
|
675
|
+
renderTextField,
|
|
676
|
+
renderMediaField,
|
|
677
|
+
renderLinkField,
|
|
678
|
+
renderIFrameField,
|
|
679
|
+
renderDividerField,
|
|
680
|
+
renderCodeField,
|
|
681
|
+
renderCaptionField,
|
|
682
|
+
renderBlockquoteField,
|
|
683
|
+
normalizeCoraxPseudoStyles,
|
|
684
|
+
getTextFieldProps,
|
|
685
|
+
getMediaFieldProps,
|
|
686
|
+
defaultFieldRenderers,
|
|
687
|
+
ReactRenderer,
|
|
688
|
+
PrimitivesComponentsRegistry,
|
|
689
|
+
GenericRegistry,
|
|
690
|
+
FieldRenderersRegistry,
|
|
691
|
+
FallbackComponentsRegistry,
|
|
692
|
+
ErrorComponentsRegistry
|
|
693
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { BlockId, BlockTag, BlockType } from "@coorax/schema";
|
|
2
|
+
import type { DOMAttributes } from "react";
|
|
3
|
+
export type FieldElementOf<T extends BlockTag> = HTMLElementTagNameMap[T];
|
|
4
|
+
export interface FieldLifeCycleEvents<T extends BlockTag = BlockTag> extends Omit<DOMAttributes<FieldElementOf<T>>, "dangerouslySetInnerHTML" | "children"> {
|
|
5
|
+
}
|
|
6
|
+
export type FieldLifeCycleLiterals<T extends BlockTag = BlockTag> = keyof FieldLifeCycleEvents<T>;
|
|
7
|
+
export type NativeCallback<T extends BlockTag = BlockTag, K extends FieldLifeCycleLiterals<T> = FieldLifeCycleLiterals<T>> = FieldLifeCycleEvents<T>[K];
|
|
8
|
+
export type FnParams<T extends ((event: never) => void) | undefined> = T extends (event: infer R) => void ? R : never;
|
|
9
|
+
export type FieldLifeCycleEvProps<T extends BlockTag = BlockTag> = {
|
|
10
|
+
target: BlockId;
|
|
11
|
+
fieldType: BlockType;
|
|
12
|
+
type: FieldLifeCycleLiterals<T>;
|
|
13
|
+
cycleEvent: FnParams<NativeCallback<T, FieldLifeCycleLiterals<T>>>;
|
|
14
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from "./fields/lifecycle.fields.types";
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { JSXElementConstructor } from "react";
|
|
2
|
+
import { GenericRegistry } from "./registry";
|
|
3
|
+
import type { Block, BlockType } from "@coorax/schema";
|
|
4
|
+
export interface ErrorComponentMap extends Record<BlockType, any> {
|
|
5
|
+
}
|
|
6
|
+
export type ErrorComponentKey = keyof ErrorComponentMap;
|
|
7
|
+
export type ErrorComponent = JSXElementConstructor<Block & React.PropsWithChildren>;
|
|
8
|
+
export declare const ErrorComponentsRegistry: GenericRegistry<keyof ErrorComponentMap, ErrorComponent>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { JSXElementConstructor } from "react";
|
|
2
|
+
import { GenericRegistry } from "./registry";
|
|
3
|
+
import type { Block, BlockType } from "@coorax/schema";
|
|
4
|
+
import type React from "react";
|
|
5
|
+
export interface FallbackComponentMap extends Record<BlockType, any> {
|
|
6
|
+
}
|
|
7
|
+
export type FallbackKey = keyof FallbackComponentMap;
|
|
8
|
+
export type FallbackComponent = JSXElementConstructor<Block & React.PropsWithChildren>;
|
|
9
|
+
export declare const FallbackComponentsRegistry: GenericRegistry<keyof FallbackComponentMap, FallbackComponent>;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Field, FieldType } from "@coorax/schema";
|
|
2
|
+
import type React from "react";
|
|
3
|
+
import { GenericRegistry } from "./registry";
|
|
4
|
+
import type { RenderContext } from "../renderer/renderer.types";
|
|
5
|
+
export type FieldRenderer = (block: Field, ctx: RenderContext) => React.ReactElement;
|
|
6
|
+
/**
|
|
7
|
+
* Registre type de champ → renderer de vue.
|
|
8
|
+
* Remplace le `switch (field.type)` historique : un tiers peut brancher son propre
|
|
9
|
+
* renderer sans forker (declaration merging sur `FieldTMap` + `fields.register`).
|
|
10
|
+
*/
|
|
11
|
+
export declare class FieldRenderersRegistry extends GenericRegistry<FieldType, FieldRenderer> {
|
|
12
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { BlockTag, BlockId, BlockVariant } from "@coorax/schema";
|
|
2
|
+
import type { FieldLifeCycleEvents } from "../lifecycle/fields/lifecycle.fields.types";
|
|
3
|
+
export type RComponentProps<T extends BlockTag = BlockTag> = FieldLifeCycleEvents<T> & {
|
|
4
|
+
blockId: BlockId;
|
|
5
|
+
};
|
|
6
|
+
export type RComponent<T extends BlockTag = BlockTag> = (props: RComponentProps<T>) => React.ReactNode;
|
|
7
|
+
interface CR {
|
|
8
|
+
get<T extends BlockTag = BlockTag>(name: BlockVariant): RComponent<T> | null;
|
|
9
|
+
post<T extends BlockTag = BlockTag>(name: BlockVariant, comp: RComponent<T>): void;
|
|
10
|
+
getAll(names: BlockVariant[]): (RComponent | null)[];
|
|
11
|
+
batch(comps: Record<BlockVariant, RComponent>): void;
|
|
12
|
+
delete(name: BlockVariant): void;
|
|
13
|
+
}
|
|
14
|
+
export declare class PrimitivesComponentsRegistry implements CR {
|
|
15
|
+
private components;
|
|
16
|
+
get<T extends BlockTag = BlockTag>(name: BlockVariant): RComponent<T> | null;
|
|
17
|
+
getAll(names: BlockVariant[]): (RComponent | null)[];
|
|
18
|
+
post<T extends BlockTag = BlockTag>(name: BlockVariant, comp: RComponent<T>): void;
|
|
19
|
+
delete(name: BlockVariant): void;
|
|
20
|
+
batch(comps: Record<BlockVariant, RComponent>): void;
|
|
21
|
+
}
|
|
22
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type RegistryListener = () => void;
|
|
2
|
+
export type RegistryDisposer = () => void;
|
|
3
|
+
export interface GenericRegistryInterface<K, V> {
|
|
4
|
+
get(key: K): V | undefined;
|
|
5
|
+
register(key: K, value: V): RegistryDisposer;
|
|
6
|
+
subscribe(key: K, fn: RegistryListener): RegistryDisposer;
|
|
7
|
+
}
|
|
8
|
+
export declare class GenericRegistry<K, V> implements GenericRegistryInterface<K, V> {
|
|
9
|
+
private items;
|
|
10
|
+
private listeners;
|
|
11
|
+
private notify;
|
|
12
|
+
get(key: K): V | undefined;
|
|
13
|
+
register(key: K, value: V): RegistryDisposer;
|
|
14
|
+
subscribe(key: K, fn: RegistryListener): RegistryDisposer;
|
|
15
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type FieldType } from "@coorax/schema";
|
|
2
|
+
import type { FieldRenderer } from "../registry/fields.registry";
|
|
3
|
+
export declare const renderTextField: FieldRenderer;
|
|
4
|
+
export declare const renderBlockquoteField: FieldRenderer;
|
|
5
|
+
export declare const renderMediaField: FieldRenderer;
|
|
6
|
+
export declare const renderIFrameField: FieldRenderer;
|
|
7
|
+
export declare const renderDividerField: FieldRenderer;
|
|
8
|
+
export declare const renderLinkField: FieldRenderer;
|
|
9
|
+
export declare const renderCodeField: FieldRenderer;
|
|
10
|
+
export declare const renderCaptionField: FieldRenderer;
|
|
11
|
+
/** Renderers par défaut, par type de champ (surchargeables via `renderer.fields`). */
|
|
12
|
+
export declare const defaultFieldRenderers: Partial<Record<FieldType, FieldRenderer>>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { type Container, type Field, type FieldId, type FieldType, type TNode, type TNodeType } from "@coorax/schema";
|
|
3
|
+
import { PrimitivesComponentsRegistry } from "../registry/primitives.registry";
|
|
4
|
+
import { FieldRenderersRegistry } from "../registry/fields.registry";
|
|
5
|
+
import type { RenderContext } from "./renderer.types";
|
|
6
|
+
import type { RendererDocument } from "./renderer.document";
|
|
7
|
+
interface RendererInterface {
|
|
8
|
+
renderField(field: Field | FieldId): React.ReactElement;
|
|
9
|
+
renderContainer(contanier: Container): React.ReactElement;
|
|
10
|
+
renderTree(key?: number): React.ReactElement;
|
|
11
|
+
}
|
|
12
|
+
export declare class ReactRenderer implements RendererInterface {
|
|
13
|
+
private ctx;
|
|
14
|
+
private document;
|
|
15
|
+
readonly primitives: PrimitivesComponentsRegistry;
|
|
16
|
+
readonly fields: FieldRenderersRegistry;
|
|
17
|
+
constructor(ctx: RenderContext, document: RendererDocument);
|
|
18
|
+
renderContainer(contanier: Container): React.ReactElement;
|
|
19
|
+
renderTree(key?: number): React.ReactElement;
|
|
20
|
+
renderField<T extends FieldType = FieldType>(_field: Field<T> | FieldId): React.ReactElement;
|
|
21
|
+
renderNode<T extends TNodeType = TNodeType>(node: TNode<T>, key?: null): React.ReactElement;
|
|
22
|
+
}
|
|
23
|
+
export {};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Block, BlockId, CoraxTree } from "@coorax/schema";
|
|
2
|
+
/**
|
|
3
|
+
* Sous-ensemble du service document dont la vue a besoin.
|
|
4
|
+
*
|
|
5
|
+
* Le driver d'édition (`@coorax/react`) passe `engine.document`, qui satisfait
|
|
6
|
+
* structurellement cette interface. `@coorax/render-react` reste ainsi
|
|
7
|
+
* indépendant de `@coorax/core`.
|
|
8
|
+
*/
|
|
9
|
+
export interface RendererDocument {
|
|
10
|
+
get(): CoraxTree;
|
|
11
|
+
getBlock(id: BlockId): Block | undefined;
|
|
12
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Field, FieldType, NodeCommonProps } from "@coorax/schema";
|
|
2
|
+
import type { FieldLifeCycleEvents } from "../lifecycle/fields/lifecycle.fields.types";
|
|
3
|
+
type ReactComponent = keyof React.JSX.IntrinsicElements;
|
|
4
|
+
export type ReactFieldProps<T extends ReactComponent> = React.ComponentProps<T>;
|
|
5
|
+
export type RenderMode = "preview" | "edit";
|
|
6
|
+
/**
|
|
7
|
+
* Contexte de rendu injecté dans la vue.
|
|
8
|
+
*
|
|
9
|
+
* - `mode` : `"edit"` conserve les props et handlers d'édition, `"preview"` les retire.
|
|
10
|
+
* - `styles` : remplace `engine.ui.getStyle()` (en preview, alimenté par `DEFAULT_STYLES`).
|
|
11
|
+
* - `events` : absent en preview (aucun comportement d'édition).
|
|
12
|
+
*/
|
|
13
|
+
export interface RenderContext {
|
|
14
|
+
mode: RenderMode;
|
|
15
|
+
styles: (type: FieldType) => NodeCommonProps;
|
|
16
|
+
events?: <T extends Field>(block: T) => FieldLifeCycleEvents<T["tag"]>;
|
|
17
|
+
}
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type FieldType, type ContainerId, type MediaField, type TextField, type CoraxCSSPseudos } from "@coorax/schema";
|
|
2
|
+
import type { ReactFieldProps, RenderContext } from "./renderer.types";
|
|
3
|
+
export declare function getTextFieldProps<T extends TextField = TextField>(block: T, ctx: RenderContext): ReactFieldProps<T["tag"]> & {
|
|
4
|
+
"data-block-type": FieldType;
|
|
5
|
+
"data-containerId"?: ContainerId;
|
|
6
|
+
"data-placeholder"?: string;
|
|
7
|
+
"data-text-path"?: string;
|
|
8
|
+
};
|
|
9
|
+
export declare function getMediaFieldProps<T extends MediaField = MediaField>(block: T, ctx: RenderContext): ReactFieldProps<T["tag"]> & {
|
|
10
|
+
"data-block-type": FieldType;
|
|
11
|
+
"data-containerId"?: ContainerId;
|
|
12
|
+
};
|
|
13
|
+
export declare function resolveCoraxPseudoStyle(style?: CoraxCSSPseudos): string | undefined;
|
|
14
|
+
export declare function normalizeCoraxPseudoStyles<T extends CoraxCSSPseudos = CoraxCSSPseudos>(style: T): T;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { BlockquoteField, ContainerId, FieldType } from "@coorax/schema";
|
|
2
|
+
import type { ReactFieldProps, RenderContext } from "../renderer.types";
|
|
3
|
+
export declare function getBlockquoteFieldProps<T extends BlockquoteField = BlockquoteField>(block: T, ctx: RenderContext): ReactFieldProps<T["tag"]> & {
|
|
4
|
+
"data-block-type": FieldType;
|
|
5
|
+
"data-containerId"?: ContainerId;
|
|
6
|
+
"data-placeholder"?: string;
|
|
7
|
+
"data-text-path"?: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CaptionField, ContainerId, FieldType } from "@coorax/schema";
|
|
2
|
+
import type { ReactFieldProps, RenderContext } from "../renderer.types";
|
|
3
|
+
export declare function getCaptionFieldProps<T extends CaptionField = CaptionField>(block: T, ctx: RenderContext): ReactFieldProps<T["tag"]> & {
|
|
4
|
+
"data-block-type": FieldType;
|
|
5
|
+
"data-containerId"?: ContainerId;
|
|
6
|
+
"data-placeholder"?: string;
|
|
7
|
+
"data-text-path"?: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { CodeField, ContainerId, FieldType } from "@coorax/schema";
|
|
2
|
+
import type { ReactFieldProps, RenderContext } from "../renderer.types";
|
|
3
|
+
export declare function getCodeFieldProps<T extends CodeField = CodeField>(block: T, ctx: RenderContext): ReactFieldProps<"pre"> & {
|
|
4
|
+
"data-block-type": FieldType;
|
|
5
|
+
"data-containerId"?: ContainerId;
|
|
6
|
+
"data-placeholder"?: string;
|
|
7
|
+
"data-text-path"?: string;
|
|
8
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContainerId, DividerField, FieldType } from "@coorax/schema";
|
|
2
|
+
import type { ReactFieldProps, RenderContext } from "../renderer.types";
|
|
3
|
+
export declare function getDividerFieldProps<T extends DividerField = DividerField>(block: T, ctx: RenderContext): ReactFieldProps<T["tag"]> & {
|
|
4
|
+
"data-block-type": FieldType;
|
|
5
|
+
"data-containerId"?: ContainerId;
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContainerId, FieldType, DocumentField } from "@coorax/schema";
|
|
2
|
+
import type { ReactFieldProps, RenderContext } from "../renderer.types";
|
|
3
|
+
export declare function getDocumentFieldProps<T extends DocumentField = DocumentField>(block: T, ctx: RenderContext): ReactFieldProps<"iframe"> & {
|
|
4
|
+
"data-block-type": FieldType;
|
|
5
|
+
"data-containerId"?: ContainerId;
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContainerId, FieldType, IFrameField } from "@coorax/schema";
|
|
2
|
+
import type { ReactFieldProps, RenderContext } from "../renderer.types";
|
|
3
|
+
export declare function getIFrameFieldProps<T extends IFrameField = IFrameField>(block: T, ctx: RenderContext): ReactFieldProps<T["tag"]> & {
|
|
4
|
+
"data-block-type": FieldType;
|
|
5
|
+
"data-containerId"?: ContainerId;
|
|
6
|
+
};
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { ContainerId, FieldType, LinkField } from "@coorax/schema";
|
|
2
|
+
import type { ReactFieldProps, RenderContext } from "../renderer.types";
|
|
3
|
+
export declare function getLinkFieldProps<T extends LinkField = LinkField>(block: T, ctx: RenderContext): ReactFieldProps<"a"> & {
|
|
4
|
+
"data-block-type": FieldType;
|
|
5
|
+
"data-containerId"?: ContainerId;
|
|
6
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@coorax/render-react",
|
|
3
|
+
"version": "0.0.0-canary.1",
|
|
4
|
+
"private": false,
|
|
5
|
+
"files": [
|
|
6
|
+
"dist"
|
|
7
|
+
],
|
|
8
|
+
"type": "module",
|
|
9
|
+
"main": "./dist/index.js",
|
|
10
|
+
"module": "./dist/index.js",
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"exports": {
|
|
13
|
+
".": {
|
|
14
|
+
"source": "./src/index.ts",
|
|
15
|
+
"types": "./dist/index.d.ts",
|
|
16
|
+
"import": "./dist/index.js",
|
|
17
|
+
"default": "./dist/index.js"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"scripts": {
|
|
24
|
+
"lint": "oxlint",
|
|
25
|
+
"lint:fix": "oxlint --fix --max-warnings=0",
|
|
26
|
+
"fmt": "oxfmt",
|
|
27
|
+
"fmt:check": "oxfmt --check",
|
|
28
|
+
"typecheck": "tsc --noEmit",
|
|
29
|
+
"vitest": "vitest",
|
|
30
|
+
"build:types": "tsc --emitDeclarationOnly",
|
|
31
|
+
"build:js": "bun build ./src/index.ts --outdir ./dist --target browser --banner '\"use client\";' --external react --external react-dom --external @coorax/schema --external lucide-react --external cn",
|
|
32
|
+
"build": "bun run build:types && bun run build:js",
|
|
33
|
+
"prepublishOnly": "bun run build"
|
|
34
|
+
},
|
|
35
|
+
"dependencies": {
|
|
36
|
+
"@coorax/schema": "0.0.0-canary.1",
|
|
37
|
+
"cn": "^0.4.0"
|
|
38
|
+
},
|
|
39
|
+
"devDependencies": {
|
|
40
|
+
"@types/react": "^19.2.18",
|
|
41
|
+
"@types/react-dom": "^19.2.7",
|
|
42
|
+
"lucide-react": "^1.55.0",
|
|
43
|
+
"oxfmt": "^0.71.0",
|
|
44
|
+
"oxlint": "^1.86.0",
|
|
45
|
+
"react": "^19.2.8",
|
|
46
|
+
"react-dom": "^19.2.8",
|
|
47
|
+
"typescript": "~6.0.2",
|
|
48
|
+
"vite": "^8.3.0",
|
|
49
|
+
"vitest": "^5.0.3"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"lucide-react": ">=1.55.0",
|
|
53
|
+
"react": ">=18.0.0",
|
|
54
|
+
"react-dom": ">=18.0.0"
|
|
55
|
+
},
|
|
56
|
+
"packageManager": "bun@1.3.9"
|
|
57
|
+
}
|