8000 refactor: cleanup solid-js builders for module support · gridaco/code@fd72126 · GitHub
[go: up one dir, main page]

Skip to content

Commit fd72126

Browse files
refactor: cleanup solid-js builders for module support
1 parent 2b11f67 commit fd72126

File tree

7 files changed

+78
-79
lines changed

7 files changed

+78
-79
lines changed

packages/builder-web-react/react-inline-css-widget/from-static-widget-tree.ts

Whitespace-only changes.

packages/builder-web-solid/index.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
export * from "./solid-import-specifications";
2-
export * from "./solid-inline-css-widget";
3-
export * from "./solid-styled-component-widget";
2+
import with_inline_css from "./solid-inline-css-widget";
3+
import with_styled_components from "./solid-styled-component-widget";
4+
5+
const finilize = {
6+
with_inline_css,
7+
with_styled_components,
8+
} as const;
9+
10+
export default finilize;

packages/builder-web-solid/solid-inline-css-widget/from-static-widget-tree.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,22 @@
1-
export { finalizeSolidWidget_InlineCSS } from "./from-static-widget-tree";
1+
import type { JsxWidget } from "@web-builder/core";
2+
import { solid as solid_config } from "@designto/config";
3+
import {
4+
SolidInlineCssBuilder,
5+
SolidInlineCssWidgetModuleExportable,
6+
} from "./solid-inline-css-module-builder";
7+
8+
export default function finalizeSolidWidget_InlineCSS(
9+
entry: JsxWidget,
10+
{
11+
styling,
12+
exporting,
13+
}: {
14+
styling: solid_config.SolidInlineCssConfig;
15+
exporting: solid_config.SolidComponentExportingCofnig;
16+
}
17+
) {
18+
const builder = new SolidInlineCssBuilder({ entry, config: styling });
19+
return builder.asExportableModule().finalize(exporting);
20+
}
21+
22+
export { SolidInlineCssBuilder, SolidInlineCssWidgetModuleExportable };

packages/builder-web-solid/solid-styled-component-widget/from-static-widget-tree.ts

Lines changed: 0 additions & 17 deletions
This file was deleted.
Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
1-
export * from "./from-static-widget-tree";
2-
export * from "./solid-styled-components-module-builder";
1+
import { JsxWidget } from "@web-builder/core";
2+
import { solid as solid_config } from "@designto/config";
3+
import {
4+
SolidStyledComponentsBuilder,
5+
SolidStyledComponentWidgetModuleExportable,
6+
} from "./solid-styled-components-module-builder";
7+
8+
export default function finalizeSolidWidget_StyledComponents(
9+
entry: JsxWidget,
10+
{
11+
styling,
12+
exporting,
13+
}: {
14+
styling: solid_config.SolidStyledComponentsConfig;
15+
exporting: solid_config.SolidComponentExportingCofnig;
16+
}
17+
) {
18+
const builder = new SolidStyledComponentsBuilder({ entry, config: styling });
19+
return builder.asExportableModule().finalize(exporting);
20+
}
21+
22+
export {
23+
SolidStyledComponentsBuilder,
24+
SolidStyledComponentWidgetModuleExportable,
25+
};
Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,29 @@
11
import { JsxWidget } from "@web-builder/core";
22
import { solid as config } from "@designto/config";
3-
import {
4-
finalizeSolidWidget_StyledComponents,
5-
finalizeSolidWidget_InlineCSS,
6-
} from "@web-builder/solid-js";
3+
import build from "@web-builder/solid-js";
4+
5+
const builders = {
6+
"inline-css": build.with_inline_css,
7+
"styled-components": build.with_styled_components,
8+
} as const;
9+
710
export function buildSolidApp(
811
entry: JsxWidget,
912
config: config.SolidFrameworkConfig
1013
): config.SolidComponentOutput {
11-
switch (config.styling.type) {
12-
// TODO:
13-
case "inline-css": {
14-
const res = finalizeSolidWidget_InlineCSS(entry, {
15-
styling: config.styling,
16-
exporting: config.component_declaration_style.exporting_style,
17-
});
18-
return {
19-
id: entry.key.id,
20-
name: entry.key.name,
21-
code: { raw: res.code },
22-
scaffold: { raw: res.code },
23-
};
24-
break;
25-
}
26-
case "styled-components": {
27-
const res = finalizeSolidWidget_StyledComponents(entry, {
28-
styling: config.styling,
29-
exporting: config.component_declaration_style.exporting_style,
30-
});
31-
return {
32-
id: entry.key.id,
33-
name: entry.key.name,
34-
code: { raw: res.code },
35-
scaffold: { raw: res.code },
36-
};
37-
}
38-
default: {
39-
throw (
40-
"Unexpected styling type for solid-js framework: " +
41-
// @ts-ignore
42-
config.styling.type
43-
);
44-
}
45-
}
46-
// return;
14+
if (!builders[config.styling.type])
15+
throw "Unexpected styling type for solid-js: " + config.styling.type;
16+
17+
const res = builders[config.styling.type](entry, {
18+
// @ts-ignore
19+
styling: config.styling,
20+
exporting: config.component_declaration_style.exporting_style,
21+
});
22+
23+
return {
24+
id: entry.key.id,
25+
name: entry.key.name,
26+
code: { raw: res.code },
27+
scaffold: { raw: res.code },
28+
};
4729
}

0 commit comments

Comments
 (0)
0