@coorax/react 0.0.0-canary.1 → 0.0.0-canary.3
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/commons/button.d.ts +8 -0
- package/dist/components/corax-context-provider.d.ts +6 -0
- package/dist/components/corax-flow.d.ts +4 -0
- package/dist/components/fallbacks/image.fallback.d.ts +3 -0
- package/dist/components/slots/buttons/block-actions-button.d.ts +3 -0
- package/dist/components/slots/buttons/toolbar-button.d.ts +3 -0
- package/dist/components/slots/maps/block-actions.d.ts +1 -0
- package/dist/components/slots/maps/overlays.d.ts +1 -0
- package/dist/components/slots/maps/text-inspector.d.ts +2 -0
- package/dist/components/slots/maps/toolbar.d.ts +1 -0
- package/dist/components/slots/overlays/focus-overlay.d.ts +3 -0
- package/dist/components/slots/overlays/hover-overlay.d.ts +3 -0
- package/dist/components/slots/overlays/selection-overlay.d.ts +3 -0
- package/dist/components/slots/slot-button.d.ts +6 -0
- package/dist/components/slots/slot-component.d.ts +5 -0
- package/dist/components/slots/slots.d.ts +4 -0
- package/dist/constants/field.constants.d.ts +2 -0
- package/dist/hooks/custom/use-custom-ref.d.ts +1 -0
- package/dist/hooks/custom/use-isomorphic-layout-effect.d.ts +2 -0
- package/{src/hooks/index.ts → dist/hooks/index.d.ts} +1 -0
- package/dist/hooks/use-block-entry.d.ts +2 -0
- package/dist/hooks/use-block.d.ts +2 -0
- package/dist/hooks/use-flow.d.ts +17 -0
- package/dist/hooks/use-keyboard.d.ts +10 -0
- package/dist/hooks/use-registry.d.ts +3 -0
- package/dist/hooks/use-renderer.d.ts +2 -0
- package/dist/hooks/use-slice.d.ts +2 -0
- package/dist/hooks/use-slots.d.ts +2 -0
- package/dist/hooks/use-tasks.d.ts +7 -0
- package/dist/hooks/use-text-input.d.ts +2 -0
- package/dist/hooks/use-ui-context.d.ts +2 -0
- package/dist/hooks/useSelection.d.ts +2 -0
- package/{src/index.ts → dist/index.d.ts} +3 -4
- package/dist/index.js +2751 -0
- package/dist/lib/comp.utils.d.ts +4 -0
- package/dist/lib/func.utils.d.ts +3 -0
- package/dist/lib/selection.utils.d.ts +5 -0
- package/dist/lib/slots.utils.d.ts +4 -0
- package/dist/lifecycle/fields/focus.events/onbeforeinput.d.ts +3 -0
- package/dist/lifecycle/fields/focus.events/onblur.d.ts +3 -0
- package/dist/lifecycle/fields/focus.events/onfocus.d.ts +3 -0
- package/dist/lifecycle/fields/keyboard.events/onkeydown.d.ts +3 -0
- package/dist/lifecycle/fields/lifecycle.fields.d.ts +12 -0
- package/dist/lifecycle/fields/lifecycle.fields.types.d.ts +15 -0
- package/dist/lifecycle/fields/lifecycle.utils.d.ts +2 -0
- package/dist/lifecycle/fields/mouse.events/onclick.d.ts +3 -0
- package/dist/lifecycle/fields/mouse.events/ondoubleclick.d.ts +4 -0
- package/dist/lifecycle/fields/mouse.events/onmouseenter.d.ts +3 -0
- package/dist/lifecycle/fields/mouse.events/onmouseleave.d.ts +3 -0
- package/dist/lifecycle/fields/synthetic.events/onload.d.ts +3 -0
- package/dist/lifecycle/fields/synthetic.events/onselect.d.ts +3 -0
- package/dist/lifecycle/index.d.ts +1 -0
- package/dist/modules/autosave.module.d.ts +31 -0
- package/dist/modules/fallbacks.module.d.ts +7 -0
- package/dist/modules/slots.module.d.ts +7 -0
- package/dist/modules/ui-primitives.module.d.ts +7 -0
- package/dist/primitives/fields/field.primitives.d.ts +2 -0
- package/dist/primitives/index.d.ts +3 -0
- package/{src/registry/fallbacks.registry.tsx → dist/registry/fallbacks.registry.d.ts} +3 -4
- package/dist/registry/primitives.registry.d.ts +22 -0
- package/dist/registry/registry.d.ts +15 -0
- package/dist/registry/slots.registry.d.ts +4 -0
- package/{src/registry/ui.primitives.registry.tsx → dist/registry/ui.primitives.registry.d.ts} +3 -4
- package/dist/renderer/renderer.d.ts +23 -0
- package/dist/renderer/renderer.test.d.ts +1 -0
- package/{src/renderer/renderer.types.ts → dist/renderer/renderer.types.d.ts} +0 -1
- package/dist/renderer/renderer.utils.d.ts +14 -0
- package/dist/renderer/utils/divider.renderer.utils.d.ts +6 -0
- package/dist/services/localdb/db/db.d.ts +74 -0
- package/dist/services/localdb/db/db.test.d.ts +1 -0
- package/dist/services/localdb/lexer/lexer.d.ts +14 -0
- package/dist/services/localdb/lexer/lexer.test.d.ts +1 -0
- package/dist/services/localdb/lexer/lexer.types.d.ts +5 -0
- package/dist/services/localdb/operator/operator.d.ts +10 -0
- package/dist/services/localdb/parser/parser.constants.d.ts +3 -0
- package/dist/services/localdb/parser/parser.d.ts +14 -0
- package/dist/services/localdb/parser/parser.test.d.ts +1 -0
- package/dist/services/localdb/parser/parser.types.d.ts +43 -0
- package/dist/services/localdb/sheet/sheet.constants.d.ts +3 -0
- package/dist/services/localdb/sheet/sheet.d.ts +14 -0
- package/dist/services/localdb/sheet/sheet.types.d.ts +13 -0
- package/dist/styles.css +1094 -0
- package/package.json +29 -12
- package/.oxlintrc.json +0 -8
- package/src/components/commons/button.tsx +0 -59
- package/src/components/corax-context-provider.tsx +0 -47
- package/src/components/corax-flow.tsx +0 -44
- package/src/components/fallbacks/image.fallback.tsx +0 -23
- package/src/components/slots/buttons/block-actions-button.tsx +0 -85
- package/src/components/slots/buttons/toolbar-button.tsx +0 -40
- package/src/components/slots/maps/block-actions.tsx +0 -84
- package/src/components/slots/maps/overlays.tsx +0 -9
- package/src/components/slots/maps/text-inspector.tsx +0 -5
- package/src/components/slots/maps/toolbar.tsx +0 -79
- package/src/components/slots/overlays/focus-overlay.tsx +0 -30
- package/src/components/slots/overlays/hover-overlay.tsx +0 -18
- package/src/components/slots/overlays/selection-overlay.tsx +0 -20
- package/src/components/slots/slot-button.tsx +0 -20
- package/src/components/slots/slot-component.tsx +0 -17
- package/src/components/slots/slots.tsx +0 -29
- package/src/constants/field.constants.ts +0 -3
- package/src/hooks/custom/use-custom-ref.ts +0 -11
- package/src/hooks/use-block-entry.ts +0 -44
- package/src/hooks/use-block.ts +0 -11
- package/src/hooks/use-flow.ts +0 -83
- package/src/hooks/use-keyboard.ts +0 -66
- package/src/hooks/use-registry.ts +0 -18
- package/src/hooks/use-renderer.ts +0 -8
- package/src/hooks/use-slice.ts +0 -13
- package/src/hooks/use-slots.ts +0 -13
- package/src/hooks/use-tasks.ts +0 -33
- package/src/hooks/use-text-input.ts +0 -83
- package/src/hooks/use-ui-context.ts +0 -16
- package/src/hooks/useSelection.ts +0 -27
- package/src/lib/comp.utils.tsx +0 -44
- package/src/lib/func.utils.ts +0 -15
- package/src/lib/selection.utils.ts +0 -33
- package/src/lib/slots.utils.tsx +0 -23
- package/src/lifecycle/fields/focus.events/onbeforeinput.ts +0 -21
- package/src/lifecycle/fields/focus.events/onblur.ts +0 -19
- package/src/lifecycle/fields/focus.events/onfocus.ts +0 -16
- package/src/lifecycle/fields/keyboard.events/onkeydown.ts +0 -128
- package/src/lifecycle/fields/lifecycle.fields.ts +0 -116
- package/src/lifecycle/fields/lifecycle.fields.types.ts +0 -33
- package/src/lifecycle/fields/lifecycle.utils.ts +0 -26
- package/src/lifecycle/fields/mouse.events/onclick.ts +0 -79
- package/src/lifecycle/fields/mouse.events/ondoubleclick.ts +0 -27
- package/src/lifecycle/fields/mouse.events/onmouseenter.ts +0 -27
- package/src/lifecycle/fields/mouse.events/onmouseleave.ts +0 -21
- package/src/lifecycle/fields/synthetic.events/onload.ts +0 -16
- package/src/lifecycle/fields/synthetic.events/onselect.ts +0 -57
- package/src/lifecycle/index.ts +0 -1
- package/src/modules/autosave.module.ts +0 -238
- package/src/modules/fallbacks.module.tsx +0 -19
- package/src/modules/slots.module.tsx +0 -28
- package/src/modules/ui-primitives.module.tsx +0 -20
- package/src/primitives/fields/field.primitives.tsx +0 -86
- package/src/primitives/index.ts +0 -8
- package/src/registry/primitives.registry.tsx +0 -57
- package/src/registry/registry.ts +0 -44
- package/src/registry/slots.registry.tsx +0 -6
- package/src/renderer/renderer.test.ts +0 -34
- package/src/renderer/renderer.tsx +0 -164
- package/src/renderer/renderer.utils.tsx +0 -139
- package/src/renderer/utils/divider.renderer.utils.tsx +0 -53
- package/src/services/localdb/db/db.test.ts +0 -351
- package/src/services/localdb/db/db.ts +0 -628
- package/src/services/localdb/lexer/lexer.test.ts +0 -123
- package/src/services/localdb/lexer/lexer.ts +0 -173
- package/src/services/localdb/lexer/lexer.types.ts +0 -34
- package/src/services/localdb/operator/operator.ts +0 -16
- package/src/services/localdb/parser/parser.constants.ts +0 -23
- package/src/services/localdb/parser/parser.test.ts +0 -172
- package/src/services/localdb/parser/parser.ts +0 -427
- package/src/services/localdb/parser/parser.types.ts +0 -56
- package/src/services/localdb/sheet/sheet.constants.ts +0 -32
- package/src/services/localdb/sheet/sheet.ts +0 -47
- package/src/services/localdb/sheet/sheet.types.ts +0 -38
- package/tsconfig.app.json +0 -26
- package/tsconfig.json +0 -9
- package/tsconfig.node.json +0 -9
- package/tsconfig.tsbuildinfo +0 -1
- package/vite.config.ts +0 -9
- /package/{src/components/index.ts → dist/components/index.d.ts} +0 -0
- /package/{src/components/slots/index.ts → dist/components/slots/index.d.ts} +0 -0
- /package/{src/components/slots/maps/index.ts → dist/components/slots/maps/index.d.ts} +0 -0
- /package/{src/modules/index.ts → dist/modules/index.d.ts} +0 -0
- /package/{src/registry/index.ts → dist/registry/index.d.ts} +0 -0
|
@@ -1,164 +0,0 @@
|
|
|
1
|
-
import React from "react";
|
|
2
|
-
import {
|
|
3
|
-
Engine,
|
|
4
|
-
UTILS,
|
|
5
|
-
type Field,
|
|
6
|
-
type FieldId,
|
|
7
|
-
type FieldType,
|
|
8
|
-
type TNode,
|
|
9
|
-
type TNodeType,
|
|
10
|
-
type Container,
|
|
11
|
-
type Segment,
|
|
12
|
-
segments,
|
|
13
|
-
type TextField,
|
|
14
|
-
type MediaField,
|
|
15
|
-
type DividerField,
|
|
16
|
-
} from "@coorax/core";
|
|
17
|
-
import { PrimitivesComponentsRegistry, type RComponent } from "../registry/primitives.registry";
|
|
18
|
-
import { FieldsPrimitives } from "../primitives";
|
|
19
|
-
import type { MarkType, TextContent } from "../../../core/src/services/text-marks/marks.types";
|
|
20
|
-
import { getTextFieldProps, getMediaFieldProps } from "./renderer.utils";
|
|
21
|
-
import { FallbackComponentsRegistry } from "../registry/fallbacks.registry";
|
|
22
|
-
import { getDividerFieldProps } from "./utils/divider.renderer.utils";
|
|
23
|
-
|
|
24
|
-
interface RendererInterface {
|
|
25
|
-
renderField(field: Field | FieldId, key?: null | number): React.ReactElement;
|
|
26
|
-
renderContainer(contanier: Container): React.ReactElement;
|
|
27
|
-
|
|
28
|
-
renderTree(key?: number): React.ReactElement;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
const defaults: Record<MarkType, React.ElementType> = {
|
|
32
|
-
bold: "strong",
|
|
33
|
-
italic: "em",
|
|
34
|
-
underline: "u",
|
|
35
|
-
code: "code",
|
|
36
|
-
link: "span",
|
|
37
|
-
initial: "span",
|
|
38
|
-
};
|
|
39
|
-
const RANK: Record<MarkType, number> = {
|
|
40
|
-
link: 0,
|
|
41
|
-
bold: 1,
|
|
42
|
-
italic: 2,
|
|
43
|
-
underline: 3,
|
|
44
|
-
code: 4,
|
|
45
|
-
initial: 5,
|
|
46
|
-
};
|
|
47
|
-
|
|
48
|
-
function formatText(text: string): string {
|
|
49
|
-
return text; //?.replaceAll(" ", " ");
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
export class ReactRenderer implements RendererInterface {
|
|
53
|
-
private engine: Engine;
|
|
54
|
-
readonly primitives = new PrimitivesComponentsRegistry();
|
|
55
|
-
|
|
56
|
-
constructor(engine: Engine) {
|
|
57
|
-
this.engine = engine;
|
|
58
|
-
|
|
59
|
-
//Add default primitives to renderer
|
|
60
|
-
for (const [type, comp] of UTILS.ObjectEntries(FieldsPrimitives)) {
|
|
61
|
-
this.primitives.post(type, comp as RComponent);
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
renderContainer(contanier: Container): React.ReactElement {
|
|
65
|
-
throw new Error("Method not implemented." + contanier.name);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
renderTree(key = 0): React.ReactElement {
|
|
69
|
-
const children = Array.from(this.engine.document.get().order).map((id) => {
|
|
70
|
-
const block = this.engine.document.getBlock(id);
|
|
71
|
-
if (!block) return <></>;
|
|
72
|
-
|
|
73
|
-
const Comp = this.primitives.get(block.variant);
|
|
74
|
-
if (!Comp) return <></>;
|
|
75
|
-
|
|
76
|
-
return <Comp blockId={id} key={id} />;
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
return React.createElement(React.Fragment, { key }, ...children);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
renderTextField(field: TextField, key = null): React.ReactElement {
|
|
83
|
-
const children = field.props.children;
|
|
84
|
-
|
|
85
|
-
return React.createElement(
|
|
86
|
-
field.tag,
|
|
87
|
-
{
|
|
88
|
-
...getTextFieldProps(this.engine, field),
|
|
89
|
-
key: key !== null ? key : field.id,
|
|
90
|
-
},
|
|
91
|
-
this.renderTextContent(children),
|
|
92
|
-
);
|
|
93
|
-
}
|
|
94
|
-
renderMediaField(field: MediaField, key = null): React.ReactElement {
|
|
95
|
-
const isMediaReady = !!field.props.src.trim();
|
|
96
|
-
if (!isMediaReady) {
|
|
97
|
-
const Fallback = FallbackComponentsRegistry.get(field.type);
|
|
98
|
-
if (Fallback) return <Fallback {...field} />;
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
return React.createElement(field.tag, {
|
|
102
|
-
...getMediaFieldProps(this.engine, field),
|
|
103
|
-
key: key !== null ? key : field.id,
|
|
104
|
-
});
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
renderDividerField(field: DividerField, key = null): React.ReactElement {
|
|
108
|
-
return React.createElement(field.tag, {
|
|
109
|
-
...getDividerFieldProps(this.engine, field),
|
|
110
|
-
key: key !== null ? key : field.id,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
renderField<T extends FieldType = FieldType>(
|
|
115
|
-
_field: Field<T> | FieldId,
|
|
116
|
-
key = null,
|
|
117
|
-
): React.ReactElement {
|
|
118
|
-
const field =
|
|
119
|
-
typeof _field === "string" ? (this.engine.document.getBlock(_field) as Field<T>) : _field;
|
|
120
|
-
if (!field || field.variant !== "field") return <></>;
|
|
121
|
-
|
|
122
|
-
switch (field.type) {
|
|
123
|
-
case "text":
|
|
124
|
-
case "heading":
|
|
125
|
-
return this.renderTextField(field as any, key);
|
|
126
|
-
case "video":
|
|
127
|
-
case "image":
|
|
128
|
-
return this.renderMediaField(field as any, key);
|
|
129
|
-
case "divider":
|
|
130
|
-
return this.renderDividerField(field as any);
|
|
131
|
-
default:
|
|
132
|
-
return <></>;
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
private renderSegment(seg: Segment, key: number) {
|
|
137
|
-
const marks = [...seg.marks].sort((a, b) => (RANK[a.type] ?? 9) - (RANK[b.type] ?? 9));
|
|
138
|
-
|
|
139
|
-
const node = marks.reduceRight<React.ReactNode>((child, mark) => {
|
|
140
|
-
const Comp = defaults[mark.type];
|
|
141
|
-
return Comp ? <Comp {...mark.attrs}>{child}</Comp> : child; // type inconnu : ignoré
|
|
142
|
-
}, formatText(seg.text));
|
|
143
|
-
|
|
144
|
-
return <React.Fragment key={key}>{node}</React.Fragment>;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
private renderTextContent(text: TextContent | null): React.ReactNode {
|
|
148
|
-
if (!text?.text) return "";
|
|
149
|
-
|
|
150
|
-
return segments(text).map(this.renderSegment);
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
renderNode<T extends TNodeType = TNodeType>(node: TNode<T>, key = null): React.ReactElement {
|
|
154
|
-
return React.createElement(
|
|
155
|
-
node.tag,
|
|
156
|
-
{
|
|
157
|
-
style: node.props.style,
|
|
158
|
-
className: node.props.className,
|
|
159
|
-
key: key ?? node.id,
|
|
160
|
-
},
|
|
161
|
-
node.props.text,
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
}
|
|
@@ -1,139 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type FieldType,
|
|
3
|
-
type ContainerId,
|
|
4
|
-
type FieldId,
|
|
5
|
-
type Engine,
|
|
6
|
-
type MediaField,
|
|
7
|
-
type TextField,
|
|
8
|
-
type CoraxCSSPseudos,
|
|
9
|
-
UTILS,
|
|
10
|
-
} from "@coorax/core";
|
|
11
|
-
import { FLC } from "../lifecycle/fields/lifecycle.fields";
|
|
12
|
-
import type { ReactFieldProps } from "./renderer.types";
|
|
13
|
-
import { cn } from "cn";
|
|
14
|
-
import { css } from "@emotion/css";
|
|
15
|
-
|
|
16
|
-
export function getTextFieldProps<T extends TextField = TextField>(
|
|
17
|
-
engine: Engine,
|
|
18
|
-
block: T,
|
|
19
|
-
): ReactFieldProps<T["tag"]> & {
|
|
20
|
-
"data-block-type": FieldType;
|
|
21
|
-
"data-containerId"?: ContainerId;
|
|
22
|
-
"data-placeholder"?: string;
|
|
23
|
-
"data-text-path"?: string;
|
|
24
|
-
} {
|
|
25
|
-
const ui = engine.ui;
|
|
26
|
-
|
|
27
|
-
const { style, pseudoStyle, className, children: _, placeholder, ...rest } = block.props;
|
|
28
|
-
const uiStyles = ui.getStyle(block.type);
|
|
29
|
-
|
|
30
|
-
const _pseudoStyle = {
|
|
31
|
-
...uiStyles.pseudoStyle,
|
|
32
|
-
...pseudoStyle,
|
|
33
|
-
};
|
|
34
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
35
|
-
|
|
36
|
-
const baseProps = {
|
|
37
|
-
id: block.id,
|
|
38
|
-
key: block.id,
|
|
39
|
-
"data-block-type": block.type,
|
|
40
|
-
style: {
|
|
41
|
-
...uiStyles.style,
|
|
42
|
-
...style,
|
|
43
|
-
...(block.props?.contentEditable ? { cursor: "auto", userSelect: "auto" } : null),
|
|
44
|
-
},
|
|
45
|
-
className: cn(uiStyles.className, className, pseudoClassName),
|
|
46
|
-
} as ReactFieldProps<T["tag"]> & {
|
|
47
|
-
"data-block-type": FieldType;
|
|
48
|
-
id: FieldId;
|
|
49
|
-
key: FieldId;
|
|
50
|
-
};
|
|
51
|
-
|
|
52
|
-
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
53
|
-
|
|
54
|
-
const editableProps = {
|
|
55
|
-
spellCheck: false,
|
|
56
|
-
suppressContentEditableWarning: true,
|
|
57
|
-
//#TODO replace with props.placeholder
|
|
58
|
-
"data-placeholder": placeholder || "Tell the news here",
|
|
59
|
-
...rest,
|
|
60
|
-
contentEditable: !!rest?.contentEditable,
|
|
61
|
-
autoFocus: true,
|
|
62
|
-
};
|
|
63
|
-
|
|
64
|
-
return {
|
|
65
|
-
...baseProps,
|
|
66
|
-
...containerProps,
|
|
67
|
-
...editableProps,
|
|
68
|
-
...FLC.getFieldLifeCycleEvents(engine, block.tag, block),
|
|
69
|
-
} as ReactFieldProps<T["tag"]> & {
|
|
70
|
-
"data-block-type": FieldType;
|
|
71
|
-
"data-containerId"?: ContainerId;
|
|
72
|
-
"data-placeholder"?: string;
|
|
73
|
-
};
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
export function getMediaFieldProps<T extends MediaField = MediaField>(
|
|
77
|
-
engine: Engine,
|
|
78
|
-
block: T,
|
|
79
|
-
): ReactFieldProps<T["tag"]> & {
|
|
80
|
-
"data-block-type": FieldType;
|
|
81
|
-
"data-containerId"?: ContainerId;
|
|
82
|
-
} {
|
|
83
|
-
const ui = engine.ui;
|
|
84
|
-
|
|
85
|
-
const { style, pseudoStyle, className, ...rest } = block.props;
|
|
86
|
-
const uiStyles = ui.getStyle(block.type);
|
|
87
|
-
|
|
88
|
-
const _pseudoStyle = {
|
|
89
|
-
...uiStyles.pseudoStyle,
|
|
90
|
-
...pseudoStyle,
|
|
91
|
-
};
|
|
92
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
93
|
-
|
|
94
|
-
const baseProps = {
|
|
95
|
-
id: block.id,
|
|
96
|
-
key: block.id,
|
|
97
|
-
"data-block-type": block.type,
|
|
98
|
-
style: {
|
|
99
|
-
...uiStyles.style,
|
|
100
|
-
...style,
|
|
101
|
-
},
|
|
102
|
-
className: cn(uiStyles.className, className, pseudoClassName),
|
|
103
|
-
} as ReactFieldProps<T["tag"]> & {
|
|
104
|
-
"data-block-type": FieldType;
|
|
105
|
-
id: FieldId;
|
|
106
|
-
key: FieldId;
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
...baseProps,
|
|
113
|
-
...containerProps,
|
|
114
|
-
...rest,
|
|
115
|
-
...FLC.getFieldLifeCycleEvents(engine, block.tag, block),
|
|
116
|
-
} as ReactFieldProps<T["tag"]> & {
|
|
117
|
-
"data-block-type": FieldType;
|
|
118
|
-
"data-containerId"?: ContainerId;
|
|
119
|
-
};
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
export function resolveCoraxPseudoStyle(style?: CoraxCSSPseudos): string | undefined {
|
|
123
|
-
if (!style || Object.keys(style).length === 0) return undefined;
|
|
124
|
-
return css(style);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
//
|
|
128
|
-
export function normalizeCoraxPseudoStyles<T extends CoraxCSSPseudos = CoraxCSSPseudos>(style: T) {
|
|
129
|
-
return UTILS.ObjectEntries(style).reduce((_style, [key, value]) => {
|
|
130
|
-
_style[key] = (
|
|
131
|
-
typeof value === "string"
|
|
132
|
-
? value
|
|
133
|
-
: typeof value === "object"
|
|
134
|
-
? normalizeCoraxPseudoStyles(value as any)
|
|
135
|
-
: String(value)
|
|
136
|
-
) as T[keyof T];
|
|
137
|
-
return _style;
|
|
138
|
-
}, {} as T);
|
|
139
|
-
}
|
|
@@ -1,53 +0,0 @@
|
|
|
1
|
-
import type { ContainerId, DividerField, Engine, FieldId, FieldType } from "@coorax/core";
|
|
2
|
-
import type { ReactFieldProps } from "../renderer.types";
|
|
3
|
-
import { cn } from "cn";
|
|
4
|
-
import { FLC } from "../../lifecycle/fields/lifecycle.fields";
|
|
5
|
-
import { resolveCoraxPseudoStyle } from "../renderer.utils";
|
|
6
|
-
|
|
7
|
-
export function getDividerFieldProps<T extends DividerField = DividerField>(
|
|
8
|
-
engine: Engine,
|
|
9
|
-
block: T,
|
|
10
|
-
): ReactFieldProps<T["tag"]> & {
|
|
11
|
-
"data-block-type": FieldType;
|
|
12
|
-
"data-containerId"?: ContainerId;
|
|
13
|
-
} {
|
|
14
|
-
const ui = engine.ui;
|
|
15
|
-
|
|
16
|
-
const { style, pseudoStyle, className, ...rest } = block.props;
|
|
17
|
-
const uiStyles = ui.getStyle(block.type);
|
|
18
|
-
|
|
19
|
-
const _pseudoStyle = {
|
|
20
|
-
...uiStyles.pseudoStyle,
|
|
21
|
-
...pseudoStyle,
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
const pseudoClassName = resolveCoraxPseudoStyle(_pseudoStyle);
|
|
25
|
-
|
|
26
|
-
const baseProps = {
|
|
27
|
-
id: block.id,
|
|
28
|
-
key: block.id,
|
|
29
|
-
"data-block-type": block.type,
|
|
30
|
-
style: {
|
|
31
|
-
...uiStyles.style,
|
|
32
|
-
...style,
|
|
33
|
-
},
|
|
34
|
-
className: cn(uiStyles.className, className, pseudoClassName),
|
|
35
|
-
} as ReactFieldProps<T["tag"]> & {
|
|
36
|
-
"data-block-type": FieldType;
|
|
37
|
-
id: FieldId;
|
|
38
|
-
key: FieldId;
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
const containerProps = block.isContainerized() ? { "data-containerId": block.containerId } : {};
|
|
42
|
-
const handlers = FLC.getFieldLifeCycleEvents(engine, block.tag, block);
|
|
43
|
-
|
|
44
|
-
return {
|
|
45
|
-
...baseProps,
|
|
46
|
-
...containerProps,
|
|
47
|
-
...rest,
|
|
48
|
-
...handlers,
|
|
49
|
-
} as ReactFieldProps<T["tag"]> & {
|
|
50
|
-
"data-block-type": FieldType;
|
|
51
|
-
"data-containerId"?: ContainerId;
|
|
52
|
-
};
|
|
53
|
-
}
|
|
@@ -1,351 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it, beforeEach } from "vitest";
|
|
2
|
-
import { LocalDB } from "./db";
|
|
3
|
-
import { loadCompleteDocument } from "../../../modules/autosave.module";
|
|
4
|
-
|
|
5
|
-
// Lightweight in-memory IndexedDB mock for unit/integration testing
|
|
6
|
-
function setupIndexedDBMock() {
|
|
7
|
-
const databases = new Map<string, { version: number; stores: Map<string, Map<any, any>> }>();
|
|
8
|
-
|
|
9
|
-
class MockCursor {
|
|
10
|
-
private items: any[];
|
|
11
|
-
private index = 0;
|
|
12
|
-
constructor(items: any[]) {
|
|
13
|
-
this.items = items;
|
|
14
|
-
}
|
|
15
|
-
get value() {
|
|
16
|
-
return this.items[this.index];
|
|
17
|
-
}
|
|
18
|
-
continue() {
|
|
19
|
-
this.index++;
|
|
20
|
-
if (this.index < this.items.length) {
|
|
21
|
-
if (this.onsuccess) this.onsuccess({ target: { result: this } });
|
|
22
|
-
} else {
|
|
23
|
-
if (this.onsuccess) this.onsuccess({ target: { result: null } });
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
onsuccess: any = null;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
const mockIndexedDB = {
|
|
30
|
-
open(dbName: string, version?: number) {
|
|
31
|
-
const req: any = {
|
|
32
|
-
result: null,
|
|
33
|
-
error: null,
|
|
34
|
-
onsuccess: null,
|
|
35
|
-
onerror: null,
|
|
36
|
-
onupgradeneeded: null,
|
|
37
|
-
};
|
|
38
|
-
|
|
39
|
-
setTimeout(() => {
|
|
40
|
-
let dbRecord = databases.get(dbName);
|
|
41
|
-
let oldVersion = dbRecord ? dbRecord.version : 0;
|
|
42
|
-
let newVersion = version || (dbRecord ? dbRecord.version : 1);
|
|
43
|
-
|
|
44
|
-
if (!dbRecord) {
|
|
45
|
-
dbRecord = { version: newVersion, stores: new Map() };
|
|
46
|
-
databases.set(dbName, dbRecord);
|
|
47
|
-
} else {
|
|
48
|
-
dbRecord.version = newVersion;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
const dbInstance: any = {
|
|
52
|
-
name: dbName,
|
|
53
|
-
version: dbRecord.version,
|
|
54
|
-
objectStoreNames: {
|
|
55
|
-
contains: (name: string) => dbRecord!.stores.has(name),
|
|
56
|
-
},
|
|
57
|
-
createObjectStore: (name: string, _opts: any) => {
|
|
58
|
-
if (!dbRecord!.stores.has(name)) {
|
|
59
|
-
dbRecord!.stores.set(name, new Map());
|
|
60
|
-
}
|
|
61
|
-
return {};
|
|
62
|
-
},
|
|
63
|
-
transaction: (_storeNames: string[], _mode: string) => {
|
|
64
|
-
const tx: any = {
|
|
65
|
-
db: dbInstance,
|
|
66
|
-
oncomplete: null,
|
|
67
|
-
onerror: null,
|
|
68
|
-
objectStore: (storeName: string) => {
|
|
69
|
-
const store = dbRecord!.stores.get(storeName);
|
|
70
|
-
if (!store) throw new Error(`Object store ${storeName} not found`);
|
|
71
|
-
|
|
72
|
-
return {
|
|
73
|
-
put: (data: any) => {
|
|
74
|
-
const putReq: any = { onsuccess: null, onerror: null, result: data.id };
|
|
75
|
-
store.set(
|
|
76
|
-
data.id,
|
|
77
|
-
JSON.parse(
|
|
78
|
-
JSON.stringify(data, (key, value) => {
|
|
79
|
-
if (typeof Blob !== "undefined" && value instanceof Blob) return value;
|
|
80
|
-
return value;
|
|
81
|
-
}),
|
|
82
|
-
),
|
|
83
|
-
);
|
|
84
|
-
setTimeout(() => putReq.onsuccess && putReq.onsuccess({ target: putReq }), 0);
|
|
85
|
-
return putReq;
|
|
86
|
-
},
|
|
87
|
-
get: (key: any) => {
|
|
88
|
-
const getReq: any = {
|
|
89
|
-
onsuccess: null,
|
|
90
|
-
onerror: null,
|
|
91
|
-
result: store.get(key) || null,
|
|
92
|
-
};
|
|
93
|
-
setTimeout(() => getReq.onsuccess && getReq.onsuccess({ target: getReq }), 0);
|
|
94
|
-
return getReq;
|
|
95
|
-
},
|
|
96
|
-
openCursor: () => {
|
|
97
|
-
const cursorReq: any = { onsuccess: null, onerror: null, result: null };
|
|
98
|
-
const allItems = Array.from(store.values());
|
|
99
|
-
const cursor = allItems.length > 0 ? new MockCursor(allItems) : null;
|
|
100
|
-
if (cursor) {
|
|
101
|
-
cursor.onsuccess = (ev: any) =>
|
|
102
|
-
cursorReq.onsuccess && cursorReq.onsuccess(ev);
|
|
103
|
-
}
|
|
104
|
-
setTimeout(() => {
|
|
105
|
-
cursorReq.result = cursor;
|
|
106
|
-
if (cursorReq.onsuccess) cursorReq.onsuccess({ target: cursorReq });
|
|
107
|
-
}, 0);
|
|
108
|
-
return cursorReq;
|
|
109
|
-
},
|
|
110
|
-
};
|
|
111
|
-
},
|
|
112
|
-
};
|
|
113
|
-
return tx;
|
|
114
|
-
},
|
|
115
|
-
close: () => {},
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
req.result = dbInstance;
|
|
119
|
-
|
|
120
|
-
if (oldVersion < newVersion && req.onupgradeneeded) {
|
|
121
|
-
req.onupgradeneeded({ target: req });
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (req.onsuccess) {
|
|
125
|
-
req.onsuccess({ target: req });
|
|
126
|
-
}
|
|
127
|
-
}, 0);
|
|
128
|
-
|
|
129
|
-
return req;
|
|
130
|
-
},
|
|
131
|
-
deleteDatabase: (name: string) => {
|
|
132
|
-
const req: any = { onsuccess: null, onerror: null };
|
|
133
|
-
databases.delete(name);
|
|
134
|
-
setTimeout(() => req.onsuccess && req.onsuccess(), 0);
|
|
135
|
-
return req;
|
|
136
|
-
},
|
|
137
|
-
};
|
|
138
|
-
|
|
139
|
-
(globalThis as any).window = (globalThis as any).window || {};
|
|
140
|
-
(globalThis as any).window.indexedDB = mockIndexedDB;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
describe("LocalDB with JOINs and separated tables", () => {
|
|
144
|
-
beforeEach(() => {
|
|
145
|
-
setupIndexedDBMock();
|
|
146
|
-
});
|
|
147
|
-
|
|
148
|
-
it("should migrate tables including medias table", async () => {
|
|
149
|
-
const db = new LocalDB("test_corax_db");
|
|
150
|
-
const err = await db.MigrateDB(`
|
|
151
|
-
CREATE TABLE documents (
|
|
152
|
-
id TEXT,
|
|
153
|
-
version TEXT,
|
|
154
|
-
order ARRAY[STRING],
|
|
155
|
-
created_at DATETIME
|
|
156
|
-
);
|
|
157
|
-
CREATE TABLE fields (
|
|
158
|
-
id TEXT,
|
|
159
|
-
document_id TEXT,
|
|
160
|
-
name TEXT,
|
|
161
|
-
tag TEXT,
|
|
162
|
-
type TEXT,
|
|
163
|
-
variant TEXT,
|
|
164
|
-
containerId TEXT,
|
|
165
|
-
props OBJECT
|
|
166
|
-
);
|
|
167
|
-
CREATE TABLE containers (
|
|
168
|
-
id TEXT,
|
|
169
|
-
document_id TEXT,
|
|
170
|
-
name TEXT,
|
|
171
|
-
tag TEXT,
|
|
172
|
-
type TEXT,
|
|
173
|
-
variant TEXT,
|
|
174
|
-
order ARRAY[STRING],
|
|
175
|
-
props OBJECT
|
|
176
|
-
);
|
|
177
|
-
CREATE TABLE components (
|
|
178
|
-
id TEXT,
|
|
179
|
-
document_id TEXT,
|
|
180
|
-
name TEXT,
|
|
181
|
-
tag TEXT,
|
|
182
|
-
type TEXT,
|
|
183
|
-
variant TEXT,
|
|
184
|
-
order ARRAY[STRING],
|
|
185
|
-
count INTEGER,
|
|
186
|
-
updatedAt DATETIME,
|
|
187
|
-
createdAt DATETIME,
|
|
188
|
-
props OBJECT
|
|
189
|
-
);
|
|
190
|
-
CREATE TABLE medias (
|
|
191
|
-
id TEXT,
|
|
192
|
-
document_id TEXT,
|
|
193
|
-
name TEXT,
|
|
194
|
-
type TEXT,
|
|
195
|
-
size INTEGER,
|
|
196
|
-
data FILE,
|
|
197
|
-
created_at DATETIME
|
|
198
|
-
);
|
|
199
|
-
`);
|
|
200
|
-
|
|
201
|
-
expect(err).toBeNull();
|
|
202
|
-
});
|
|
203
|
-
|
|
204
|
-
it("should insert into separate tables and join them to form the complete document", async () => {
|
|
205
|
-
const db = new LocalDB("test_corax_db");
|
|
206
|
-
await db.MigrateDB(`
|
|
207
|
-
CREATE TABLE documents (
|
|
208
|
-
id TEXT,
|
|
209
|
-
version TEXT,
|
|
210
|
-
order ARRAY[STRING],
|
|
211
|
-
created_at DATETIME
|
|
212
|
-
);
|
|
213
|
-
CREATE TABLE fields (
|
|
214
|
-
id TEXT,
|
|
215
|
-
document_id TEXT,
|
|
216
|
-
name TEXT,
|
|
217
|
-
tag TEXT,
|
|
218
|
-
type TEXT,
|
|
219
|
-
variant TEXT,
|
|
220
|
-
containerId TEXT,
|
|
221
|
-
props OBJECT
|
|
222
|
-
);
|
|
223
|
-
CREATE TABLE containers (
|
|
224
|
-
id TEXT,
|
|
225
|
-
document_id TEXT,
|
|
226
|
-
name TEXT,
|
|
227
|
-
tag TEXT,
|
|
228
|
-
type TEXT,
|
|
229
|
-
variant TEXT,
|
|
230
|
-
order ARRAY[STRING],
|
|
231
|
-
props OBJECT
|
|
232
|
-
);
|
|
233
|
-
CREATE TABLE components (
|
|
234
|
-
id TEXT,
|
|
235
|
-
document_id TEXT,
|
|
236
|
-
name TEXT,
|
|
237
|
-
tag TEXT,
|
|
238
|
-
type TEXT,
|
|
239
|
-
variant TEXT,
|
|
240
|
-
order ARRAY[STRING],
|
|
241
|
-
count INTEGER,
|
|
242
|
-
updatedAt DATETIME,
|
|
243
|
-
createdAt DATETIME,
|
|
244
|
-
props OBJECT
|
|
245
|
-
);
|
|
246
|
-
CREATE TABLE medias (
|
|
247
|
-
id TEXT,
|
|
248
|
-
document_id TEXT,
|
|
249
|
-
name TEXT,
|
|
250
|
-
type TEXT,
|
|
251
|
-
size INTEGER,
|
|
252
|
-
data FILE,
|
|
253
|
-
created_at DATETIME
|
|
254
|
-
);
|
|
255
|
-
`);
|
|
256
|
-
|
|
257
|
-
const docId = "doc-root-1";
|
|
258
|
-
const now = Date.now();
|
|
259
|
-
|
|
260
|
-
// 1. Insert documents row
|
|
261
|
-
await db.QueryDB(
|
|
262
|
-
`INSERT INTO documents (id, version, order, created_at) VALUES (?, ?, ?, ?);`,
|
|
263
|
-
[docId, "1.0.0", ["field:1", "container:1"], now],
|
|
264
|
-
);
|
|
265
|
-
|
|
266
|
-
// 2. Insert fields row
|
|
267
|
-
await db.QueryDB(
|
|
268
|
-
`INSERT INTO fields (id, document_id, name, tag, type, variant, containerId, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`,
|
|
269
|
-
["field:1", docId, "Main Title", "h1", "heading", "field", "", { content: "Hello World" }],
|
|
270
|
-
);
|
|
271
|
-
|
|
272
|
-
// 3. Insert containers row
|
|
273
|
-
await db.QueryDB(
|
|
274
|
-
`INSERT INTO containers (id, document_id, name, tag, type, variant, order, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?);`,
|
|
275
|
-
[
|
|
276
|
-
"container:1",
|
|
277
|
-
docId,
|
|
278
|
-
"Section One",
|
|
279
|
-
"div",
|
|
280
|
-
"division",
|
|
281
|
-
"container",
|
|
282
|
-
["field:1"],
|
|
283
|
-
{ className: "hero" },
|
|
284
|
-
],
|
|
285
|
-
);
|
|
286
|
-
|
|
287
|
-
// 4. Insert components row
|
|
288
|
-
await db.QueryDB(
|
|
289
|
-
`INSERT INTO components (id, document_id, name, tag, type, variant, order, count, updatedAt, createdAt, props) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);`,
|
|
290
|
-
["component:1", docId, "Card", "div", "division", "component", [], 1, now, now, {}],
|
|
291
|
-
);
|
|
292
|
-
|
|
293
|
-
// 5. Insert media row (e.g. File / Blob)
|
|
294
|
-
const mockFile = new Blob(["test image content"], { type: "image/png" });
|
|
295
|
-
await db.QueryDB(
|
|
296
|
-
`INSERT INTO medias (id, document_id, name, type, size, data, created_at) VALUES (?, ?, ?, ?, ?, ?, ?);`,
|
|
297
|
-
["media:field:1", docId, "banner.png", "image/png", mockFile.size, mockFile, now],
|
|
298
|
-
);
|
|
299
|
-
|
|
300
|
-
// Query with JOINs to form the complete document
|
|
301
|
-
const completeDoc = await loadCompleteDocument(db, docId);
|
|
302
|
-
|
|
303
|
-
expect(completeDoc).toBeDefined();
|
|
304
|
-
expect(completeDoc.id).toBe(docId);
|
|
305
|
-
expect(completeDoc.version).toBe("1.0.0");
|
|
306
|
-
expect(completeDoc.order).toEqual(["field:1", "container:1"]);
|
|
307
|
-
|
|
308
|
-
// Check nested objects joined and formed
|
|
309
|
-
expect(completeDoc.fields).toBeDefined();
|
|
310
|
-
expect(completeDoc.fields["field:1"]).toEqual({
|
|
311
|
-
id: "field:1",
|
|
312
|
-
name: "Main Title",
|
|
313
|
-
tag: "h1",
|
|
314
|
-
type: "heading",
|
|
315
|
-
variant: "field",
|
|
316
|
-
containerId: "",
|
|
317
|
-
props: { content: "Hello World" },
|
|
318
|
-
});
|
|
319
|
-
|
|
320
|
-
expect(completeDoc.containers).toBeDefined();
|
|
321
|
-
expect(completeDoc.containers["container:1"]).toEqual({
|
|
322
|
-
id: "container:1",
|
|
323
|
-
name: "Section One",
|
|
324
|
-
tag: "div",
|
|
325
|
-
type: "division",
|
|
326
|
-
variant: "container",
|
|
327
|
-
order: ["field:1"],
|
|
328
|
-
props: { className: "hero" },
|
|
329
|
-
});
|
|
330
|
-
|
|
331
|
-
expect(completeDoc.components).toBeDefined();
|
|
332
|
-
expect(completeDoc.components["component:1"]).toEqual({
|
|
333
|
-
id: "component:1",
|
|
334
|
-
name: "Card",
|
|
335
|
-
tag: "div",
|
|
336
|
-
type: "division",
|
|
337
|
-
variant: "component",
|
|
338
|
-
order: [],
|
|
339
|
-
count: 1,
|
|
340
|
-
updatedAt: now,
|
|
341
|
-
createdAt: now,
|
|
342
|
-
props: {},
|
|
343
|
-
});
|
|
344
|
-
|
|
345
|
-
expect(completeDoc.medias).toBeDefined();
|
|
346
|
-
expect(completeDoc.medias["media:field:1"]).toBeDefined();
|
|
347
|
-
expect(completeDoc.medias["media:field:1"].name).toBe("banner.png");
|
|
348
|
-
expect(completeDoc.medias["media:field:1"].type).toBe("image/png");
|
|
349
|
-
expect(completeDoc.medias["media:field:1"].size).toBe(mockFile.size);
|
|
350
|
-
});
|
|
351
|
-
});
|