@rxdrag/website-studio 0.0.4 → 0.0.5
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/generator/classes/Coder.d.ts +2 -0
- package/dist/index.mjs +78 -100
- package/dist/index.mjs.map +1 -1
- package/package.json +19 -19
|
@@ -8,6 +8,7 @@ export declare abstract class Coder {
|
|
|
8
8
|
protected elements: INodeSchema<XData>[];
|
|
9
9
|
protected imports: Record<string, string[]>;
|
|
10
10
|
protected typeImports: Record<string, string[]>;
|
|
11
|
+
protected defaultImports: Record<string, string[]>;
|
|
11
12
|
constructor(comsStore: TemplatesStore, elements: INodeSchema<XData>[]);
|
|
12
13
|
getUsedMaterials(): IMaterial[];
|
|
13
14
|
getMaterialsFromElements(elements: INodeSchema<XData>[], usedMaterials: IMaterial[]): void;
|
|
@@ -30,6 +31,7 @@ export declare abstract class Coder {
|
|
|
30
31
|
[key: string]: INodeSchema | undefined;
|
|
31
32
|
} | undefined, spaces?: number): string;
|
|
32
33
|
addImport(componentName: string, packagePath: string): void;
|
|
34
|
+
addDefaultImport(componentName: string, packagePath: string): void;
|
|
33
35
|
addTypeImport(componentName: string, packagePath: string): void;
|
|
34
36
|
abstract getFileName(): string;
|
|
35
37
|
}
|
package/dist/index.mjs
CHANGED
|
@@ -15857,122 +15857,91 @@ const tailwindCssTemplate = {
|
|
|
15857
15857
|
};
|
|
15858
15858
|
const slugTemplate = {
|
|
15859
15859
|
name: "$slug.tsx",
|
|
15860
|
-
content: `import type
|
|
15861
|
-
import {
|
|
15862
|
-
import {
|
|
15863
|
-
import {
|
|
15864
|
-
import {
|
|
15865
|
-
import { PostPage } from "~/components/PostPage";
|
|
15866
|
-
import { ProductPage } from "~/components/ProductPage";
|
|
15867
|
-
|
|
15868
|
-
export const meta: MetaFunction = ({ data }) => {
|
|
15869
|
-
const datas = data as Datas | undefined
|
|
15870
|
-
const obj = datas?.post || datas?.product;
|
|
15871
|
-
return [
|
|
15872
|
-
{ title: obj?.seoTitle || obj?.title },
|
|
15873
|
-
{
|
|
15874
|
-
name: "description",
|
|
15875
|
-
content: obj?.seoDescription
|
|
15876
|
-
},
|
|
15877
|
-
];
|
|
15878
|
-
};
|
|
15860
|
+
content: `import { redirect, type LoaderFunction, type LoaderFunctionArgs } from "~/deploy/remix-run-node";
|
|
15861
|
+
import type { WebsiteSettings, WebsiteSettingsBoolExp, WebsiteSettingsOrderBy, WebsiteSettingsDistinctExp, Product, ProductBoolExp, ProductDistinctExp, ProductOrderBy, Post, PostBoolExp, PostDistinctExp, PostOrderBy } from "@rxdrag/rxcms-models";
|
|
15862
|
+
import { WebsiteSettingsQueryOptions, WebsiteSettingsFields, ProductFields, ProductQueryOptions, PostQueryOptions } from "@rxdrag/rxcms-models";
|
|
15863
|
+
import { queryOneEntity } from "@rxdrag/model-remix-lib";
|
|
15864
|
+
import { getEnvVariables } from "~/deploy/get-env";
|
|
15879
15865
|
|
|
15880
15866
|
// 定义 loader 函数
|
|
15881
|
-
export const loader: LoaderFunction = async (
|
|
15867
|
+
export const loader: LoaderFunction = async (args: LoaderFunctionArgs) => {
|
|
15868
|
+
const { params } = args
|
|
15882
15869
|
const { slug } = params;
|
|
15883
|
-
if (!process.env.VITE_SERVER_URL) {
|
|
15884
|
-
return { status: 404, error: new Error("VITE_SERVER_URL Not Set") };
|
|
15885
|
-
}
|
|
15886
|
-
const websiteId = process.env.VITE_WEBSITE_ID;
|
|
15887
|
-
if (!process.env.VITE_WEBSITE_ID) {
|
|
15888
|
-
return { status: 404, error: new Error("VITE_WEBSITE_ID Not Set") };
|
|
15889
|
-
}
|
|
15890
15870
|
|
|
15891
|
-
|
|
15892
|
-
|
|
15893
|
-
|
|
15894
|
-
|
|
15895
|
-
[SlugFields.websiteId]: {
|
|
15896
|
-
"_eq": websiteId
|
|
15897
|
-
},
|
|
15871
|
+
if (!slug) {
|
|
15872
|
+
throw new Response(null, { status: 404 });
|
|
15873
|
+
}
|
|
15874
|
+
const envVariables = getEnvVariables(args)
|
|
15898
15875
|
|
|
15876
|
+
const webisteSettings = await queryOneEntity<WebsiteSettings, WebsiteSettingsBoolExp, WebsiteSettingsOrderBy, WebsiteSettingsDistinctExp>(
|
|
15877
|
+
new WebsiteSettingsQueryOptions(
|
|
15878
|
+
[
|
|
15879
|
+
WebsiteSettingsFields.id,
|
|
15880
|
+
WebsiteSettingsFields.map301,
|
|
15881
|
+
],
|
|
15882
|
+
),
|
|
15883
|
+
envVariables
|
|
15884
|
+
)
|
|
15885
|
+
if (webisteSettings?.map301) {
|
|
15886
|
+
for (const line of webisteSettings.map301?.split('
|
|
15887
|
+
')) {
|
|
15888
|
+
const [from, to] = line.split(',');
|
|
15889
|
+
if (slug === from) {
|
|
15890
|
+
return redirect(to, 301);
|
|
15899
15891
|
}
|
|
15900
|
-
}
|
|
15901
|
-
|
|
15892
|
+
}
|
|
15893
|
+
}
|
|
15894
|
+
|
|
15895
|
+
const product = await queryOneEntity<Product, ProductBoolExp, ProductOrderBy, ProductDistinctExp>(
|
|
15896
|
+
new ProductQueryOptions(
|
|
15897
|
+
[
|
|
15898
|
+
ProductFields.id,
|
|
15899
|
+
ProductFields.slug,
|
|
15900
|
+
],
|
|
15902
15901
|
{
|
|
15903
|
-
|
|
15904
|
-
|
|
15905
|
-
|
|
15906
|
-
PostFields.seoTitle,
|
|
15907
|
-
PostFields.seoKeywords,
|
|
15908
|
-
PostFields.seoDescription,
|
|
15909
|
-
PostFields.content,
|
|
15910
|
-
{
|
|
15911
|
-
[PostFields.author]: [
|
|
15912
|
-
UserFields.id,
|
|
15913
|
-
UserFields.name,
|
|
15914
|
-
{
|
|
15915
|
-
[UserFields.avatar]: [
|
|
15916
|
-
MediaFields.id,
|
|
15917
|
-
{
|
|
15918
|
-
[MediaFields.file]: [
|
|
15919
|
-
'thumbnail',
|
|
15920
|
-
]
|
|
15921
|
-
}
|
|
15922
|
-
]
|
|
15923
|
-
}
|
|
15924
|
-
]
|
|
15925
|
-
},
|
|
15926
|
-
{
|
|
15927
|
-
[PostFields.category]: [
|
|
15928
|
-
PostCategoryFields.id,
|
|
15929
|
-
PostCategoryFields.name,
|
|
15930
|
-
PostCategoryFields.description
|
|
15931
|
-
]
|
|
15932
|
-
}
|
|
15933
|
-
],
|
|
15934
|
-
[SlugFields.product]: [
|
|
15935
|
-
ProductFields.id,
|
|
15936
|
-
ProductFields.title,
|
|
15937
|
-
ProductFields.seoTitle,
|
|
15938
|
-
ProductFields.seoKeywords,
|
|
15939
|
-
ProductFields.seoDescription,
|
|
15940
|
-
ProductFields.content,
|
|
15941
|
-
{
|
|
15942
|
-
[ProductFields.category]: [
|
|
15943
|
-
ProductCategoryFields.id,
|
|
15944
|
-
ProductCategoryFields.name,
|
|
15945
|
-
ProductCategoryFields.description
|
|
15946
|
-
]
|
|
15902
|
+
where: {
|
|
15903
|
+
slug: {
|
|
15904
|
+
_eq: slug
|
|
15947
15905
|
}
|
|
15948
|
-
|
|
15906
|
+
}
|
|
15949
15907
|
}
|
|
15950
|
-
|
|
15951
|
-
|
|
15952
|
-
|
|
15953
|
-
|
|
15954
|
-
|
|
15955
|
-
|
|
15956
|
-
}
|
|
15957
|
-
};
|
|
15958
|
-
};
|
|
15908
|
+
),
|
|
15909
|
+
envVariables
|
|
15910
|
+
)
|
|
15911
|
+
if (product) {
|
|
15912
|
+
return redirect(\`/product/\${product.slug}\`, 301);
|
|
15913
|
+
}
|
|
15959
15914
|
|
|
15915
|
+
const post = await queryOneEntity<Post, PostBoolExp, PostOrderBy, PostDistinctExp>(
|
|
15916
|
+
new PostQueryOptions(
|
|
15917
|
+
[
|
|
15918
|
+
ProductFields.id,
|
|
15919
|
+
ProductFields.slug,
|
|
15920
|
+
],
|
|
15921
|
+
{
|
|
15922
|
+
where: {
|
|
15923
|
+
slug: {
|
|
15924
|
+
_eq: slug
|
|
15925
|
+
}
|
|
15926
|
+
}
|
|
15927
|
+
}
|
|
15928
|
+
),
|
|
15929
|
+
envVariables
|
|
15930
|
+
)
|
|
15960
15931
|
|
|
15961
|
-
|
|
15962
|
-
|
|
15963
|
-
if (datas?.post) {
|
|
15964
|
-
return <PostPage datas={datas as Datas} />
|
|
15965
|
-
} else if (datas?.product) {
|
|
15966
|
-
return <ProductPage datas={datas as Datas} />
|
|
15932
|
+
if (post) {
|
|
15933
|
+
return redirect(\`/post/\${post.slug}\`, 301);
|
|
15967
15934
|
}
|
|
15968
|
-
|
|
15969
|
-
|
|
15935
|
+
|
|
15936
|
+
return redirect("/404", 404);
|
|
15937
|
+
};
|
|
15970
15938
|
`
|
|
15971
15939
|
};
|
|
15972
15940
|
class Coder {
|
|
15973
15941
|
constructor(comsStore, elements) {
|
|
15974
15942
|
__publicField(this, "imports", {});
|
|
15975
15943
|
__publicField(this, "typeImports", {});
|
|
15944
|
+
__publicField(this, "defaultImports", {});
|
|
15976
15945
|
this.comsStore = comsStore;
|
|
15977
15946
|
this.elements = elements;
|
|
15978
15947
|
const customizedComponents = this.getCustomizedComponents();
|
|
@@ -16051,9 +16020,10 @@ class Coder {
|
|
|
16051
16020
|
}
|
|
16052
16021
|
}
|
|
16053
16022
|
getImportsCode() {
|
|
16023
|
+
const defaultImportsCode = Object.keys(this.defaultImports).map((key) => `import ${this.defaultImports[key].join(", ")} from "${key}"`).join("\n");
|
|
16054
16024
|
const importsCode = Object.keys(this.imports).map((key) => `import { ${this.imports[key].join(", ")} } from "${key}"`).join("\n");
|
|
16055
16025
|
const typeImportsCode = Object.keys(this.typeImports).map((key) => `import type { ${this.typeImports[key].join(", ")} } from "${key}"`).join("\n");
|
|
16056
|
-
const codes = [importsCode, typeImportsCode].filter((code) => code);
|
|
16026
|
+
const codes = [defaultImportsCode, importsCode, typeImportsCode].filter((code) => code);
|
|
16057
16027
|
return codes.join("\n") + "\n";
|
|
16058
16028
|
}
|
|
16059
16029
|
getUseLoaderDataCode(spaces = 2) {
|
|
@@ -16249,6 +16219,14 @@ ${spacesStr}}`).join("\n" + spacesStr);
|
|
|
16249
16219
|
this.imports[packagePath].push(componentName);
|
|
16250
16220
|
}
|
|
16251
16221
|
}
|
|
16222
|
+
addDefaultImport(componentName, packagePath) {
|
|
16223
|
+
if (!this.defaultImports[packagePath]) {
|
|
16224
|
+
this.defaultImports[packagePath] = [];
|
|
16225
|
+
}
|
|
16226
|
+
if (!this.defaultImports[packagePath].find((name) => name === componentName)) {
|
|
16227
|
+
this.defaultImports[packagePath].push(componentName);
|
|
16228
|
+
}
|
|
16229
|
+
}
|
|
16252
16230
|
addTypeImport(componentName, packagePath) {
|
|
16253
16231
|
if (!this.typeImports[packagePath]) {
|
|
16254
16232
|
this.typeImports[packagePath] = [];
|
|
@@ -16368,7 +16346,7 @@ class ComponentCoder extends Coder {
|
|
|
16368
16346
|
this.comsStore = comsStore;
|
|
16369
16347
|
this.component = component;
|
|
16370
16348
|
if (this.component.droppable) {
|
|
16371
|
-
this.
|
|
16349
|
+
this.addDefaultImport("React", "react");
|
|
16372
16350
|
}
|
|
16373
16351
|
if (this.getXDataSchemas().length) {
|
|
16374
16352
|
this.addTypeImport("TDatas", "@rxdrag/website-components");
|