@rxdrag/website-studio 0.0.4 → 0.0.6

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.
@@ -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
  }
@@ -1,6 +1,7 @@
1
1
  export declare const FRAME_CONTENT = "#frameContent#";
2
2
  export declare const FRAME_IMPORTS = "#frameImports#";
3
3
  export declare const FRAME_404 = "#frame404#";
4
+ export declare const CSS_CONTENT = "#cssContent#";
4
5
  export declare const PAGE_CONTENT = "#content#";
5
6
  export declare const PAGE_IMPORTS = "#imports#";
6
7
  export declare const APP_NAME = "#appName#";
package/dist/index.mjs CHANGED
@@ -15415,6 +15415,7 @@ const MenuContent = memo((props) => {
15415
15415
  const FRAME_CONTENT = "#frameContent#";
15416
15416
  const FRAME_IMPORTS = "#frameImports#";
15417
15417
  const FRAME_404 = "#frame404#";
15418
+ const CSS_CONTENT = "#cssContent#";
15418
15419
  const APP_NAME = "#appName#";
15419
15420
  const APP_VERSION = "#appVersion#";
15420
15421
  const APP_PPACKAGES = "#appPackages#";
@@ -15853,126 +15854,95 @@ const tailwindCssTemplate = {
15853
15854
  @tailwind components;
15854
15855
  @tailwind utilities;
15855
15856
 
15857
+ ${CSS_CONTENT}
15856
15858
  `
15857
15859
  };
15858
15860
  const slugTemplate = {
15859
15861
  name: "$slug.tsx",
15860
- content: `import type { LoaderFunction, MetaFunction } from "@remix-run/node";
15861
- import { useLoaderData } from "@remix-run/react";
15862
- import { EntifyClient } from "@rxdrag/entify-hooks";
15863
- import { MediaFields, Post, PostCategoryFields, PostFields, ProductCategoryFields, ProductFields, Slug, SlugBoolExp, SlugDistinctExp, SlugEntityName, SlugFields, SlugOrderBy, UserFields } from "@rxdrag/rxcms-models";
15864
- import { Datas } from "@rxdrag/website-components";
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
- };
15862
+ content: `import { redirect, type LoaderFunction, type LoaderFunctionArgs } from "~/deploy/remix-run-node";
15863
+ import type { WebsiteSettings, WebsiteSettingsBoolExp, WebsiteSettingsOrderBy, WebsiteSettingsDistinctExp, Product, ProductBoolExp, ProductDistinctExp, ProductOrderBy, Post, PostBoolExp, PostDistinctExp, PostOrderBy } from "@rxdrag/rxcms-models";
15864
+ import { WebsiteSettingsQueryOptions, WebsiteSettingsFields, ProductFields, ProductQueryOptions, PostQueryOptions } from "@rxdrag/rxcms-models";
15865
+ import { queryOneEntity } from "@rxdrag/model-remix-lib";
15866
+ import { getEnvVariables } from "~/deploy/get-env";
15879
15867
 
15880
15868
  // 定义 loader 函数
15881
- export const loader: LoaderFunction = async ({ params }) => {
15869
+ export const loader: LoaderFunction = async (args: LoaderFunctionArgs) => {
15870
+ const { params } = args
15882
15871
  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
15872
 
15891
- const entifyClient = new EntifyClient(process.env.VITE_SERVER_URL);
15892
- const slugObj = await entifyClient.oneEntity<Slug, SlugBoolExp, SlugOrderBy, SlugDistinctExp>(SlugEntityName, {
15893
- queryArgs: {
15894
- where: {
15895
- [SlugFields.websiteId]: {
15896
- "_eq": websiteId
15897
- },
15873
+ if (!slug) {
15874
+ throw new Response(null, { status: 404 });
15875
+ }
15876
+ const envVariables = getEnvVariables(args)
15898
15877
 
15878
+ const webisteSettings = await queryOneEntity<WebsiteSettings, WebsiteSettingsBoolExp, WebsiteSettingsOrderBy, WebsiteSettingsDistinctExp>(
15879
+ new WebsiteSettingsQueryOptions(
15880
+ [
15881
+ WebsiteSettingsFields.id,
15882
+ WebsiteSettingsFields.map301,
15883
+ ],
15884
+ ),
15885
+ envVariables
15886
+ )
15887
+ if (webisteSettings?.map301) {
15888
+ for (const line of webisteSettings.map301?.split('\\n')) {
15889
+ const [from, to] = line.split(',');
15890
+ if (slug === from) {
15891
+ return redirect(to, 301);
15899
15892
  }
15900
- },
15901
- fields: [
15893
+ }
15894
+ }
15895
+
15896
+ const product = await queryOneEntity<Product, ProductBoolExp, ProductOrderBy, ProductDistinctExp>(
15897
+ new ProductQueryOptions(
15898
+ [
15899
+ ProductFields.id,
15900
+ ProductFields.slug,
15901
+ ],
15902
15902
  {
15903
- [SlugFields.post]: [
15904
- PostFields.id,
15905
- PostFields.title,
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
- ]
15903
+ where: {
15904
+ slug: {
15905
+ _eq: slug
15947
15906
  }
15948
- ]
15907
+ }
15949
15908
  }
15950
- ],
15951
- });
15952
- return {
15953
- datas: {
15954
- post: slugObj?.post,
15955
- product: slugObj?.product
15956
- }
15957
- };
15958
- };
15909
+ ),
15910
+ envVariables
15911
+ )
15912
+ if (product) {
15913
+ return redirect(\`/product/\${product.slug}\`, 301);
15914
+ }
15959
15915
 
15916
+ const post = await queryOneEntity<Post, PostBoolExp, PostOrderBy, PostDistinctExp>(
15917
+ new PostQueryOptions(
15918
+ [
15919
+ ProductFields.id,
15920
+ ProductFields.slug,
15921
+ ],
15922
+ {
15923
+ where: {
15924
+ slug: {
15925
+ _eq: slug
15926
+ }
15927
+ }
15928
+ }
15929
+ ),
15930
+ envVariables
15931
+ )
15960
15932
 
15961
- export default function SlugPage() {
15962
- const { datas } = useLoaderData<{ datas: Datas | undefined }>();
15963
- if (datas?.post) {
15964
- return <PostPage datas={datas as Datas} />
15965
- } else if (datas?.product) {
15966
- return <ProductPage datas={datas as Datas} />
15933
+ if (post) {
15934
+ return redirect(\`/post/\${post.slug}\`, 301);
15967
15935
  }
15968
- return <>404 can find slug</>
15969
- }
15936
+
15937
+ return redirect("/404", 404);
15938
+ };
15970
15939
  `
15971
15940
  };
15972
15941
  class Coder {
15973
15942
  constructor(comsStore, elements) {
15974
15943
  __publicField(this, "imports", {});
15975
15944
  __publicField(this, "typeImports", {});
15945
+ __publicField(this, "defaultImports", {});
15976
15946
  this.comsStore = comsStore;
15977
15947
  this.elements = elements;
15978
15948
  const customizedComponents = this.getCustomizedComponents();
@@ -16051,9 +16021,10 @@ class Coder {
16051
16021
  }
16052
16022
  }
16053
16023
  getImportsCode() {
16024
+ const defaultImportsCode = Object.keys(this.defaultImports).map((key) => `import ${this.defaultImports[key].join(", ")} from "${key}"`).join("\n");
16054
16025
  const importsCode = Object.keys(this.imports).map((key) => `import { ${this.imports[key].join(", ")} } from "${key}"`).join("\n");
16055
16026
  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);
16027
+ const codes = [defaultImportsCode, importsCode, typeImportsCode].filter((code) => code);
16057
16028
  return codes.join("\n") + "\n";
16058
16029
  }
16059
16030
  getUseLoaderDataCode(spaces = 2) {
@@ -16073,7 +16044,7 @@ class Coder {
16073
16044
  }
16074
16045
  }
16075
16046
  jsonToTsx(node, spaces = 0, hasRootClassName) {
16076
- var _a2, _b2;
16047
+ var _a2, _b2, _c2, _d2, _e2, _f2;
16077
16048
  const spacesStr = " ".repeat(spaces);
16078
16049
  if (node.componentName === TextNodeName) {
16079
16050
  return spacesStr + (node.text || "");
@@ -16120,9 +16091,18 @@ class Coder {
16120
16091
  spaceAddon = 2;
16121
16092
  str += ` ${spacesStr}{(datas) => (
16122
16093
  `;
16094
+ if (((_b2 = node.children) == null ? void 0 : _b2.length) && ((_c2 = node.children) == null ? void 0 : _c2.length) > 1) {
16095
+ str += ` ${spacesStr}<>
16096
+ `;
16097
+ spaceAddon = 4;
16098
+ }
16123
16099
  }
16124
- str += ((_b2 = node.children) == null ? void 0 : _b2.map((child) => this.jsonToTsx(child, spaces + 2 + spaceAddon)).join("\n")) + "\n";
16100
+ str += ((_d2 = node.children) == null ? void 0 : _d2.map((child) => this.jsonToTsx(child, spaces + 2 + spaceAddon)).join("\n")) + "\n";
16125
16101
  if (this.needAddDatas(xdata)) {
16102
+ if (((_e2 = node.children) == null ? void 0 : _e2.length) && ((_f2 = node.children) == null ? void 0 : _f2.length) > 1) {
16103
+ str += ` ${spacesStr}</>
16104
+ `;
16105
+ }
16126
16106
  str += ` ${spacesStr})}`;
16127
16107
  }
16128
16108
  str += `
@@ -16249,6 +16229,14 @@ ${spacesStr}}`).join("\n" + spacesStr);
16249
16229
  this.imports[packagePath].push(componentName);
16250
16230
  }
16251
16231
  }
16232
+ addDefaultImport(componentName, packagePath) {
16233
+ if (!this.defaultImports[packagePath]) {
16234
+ this.defaultImports[packagePath] = [];
16235
+ }
16236
+ if (!this.defaultImports[packagePath].find((name) => name === componentName)) {
16237
+ this.defaultImports[packagePath].push(componentName);
16238
+ }
16239
+ }
16252
16240
  addTypeImport(componentName, packagePath) {
16253
16241
  if (!this.typeImports[packagePath]) {
16254
16242
  this.typeImports[packagePath] = [];
@@ -16264,7 +16252,6 @@ const rootTemplate = {
16264
16252
  import { entify } from "@rxdrag/model-remix-lib";
16265
16253
  import { useAppInit, XDataScope, HtmlDocument } from "@rxdrag/website-components";
16266
16254
  import "./tailwind.css";
16267
- import './frontend.css'
16268
16255
  ${FRAME_IMPORTS}
16269
16256
 
16270
16257
  ${LOADER_FUNCTION}
@@ -16368,7 +16355,7 @@ class ComponentCoder extends Coder {
16368
16355
  this.comsStore = comsStore;
16369
16356
  this.component = component;
16370
16357
  if (this.component.droppable) {
16371
- this.addImport("React", "react");
16358
+ this.addDefaultImport("React", "react");
16372
16359
  }
16373
16360
  if (this.getXDataSchemas().length) {
16374
16361
  this.addTypeImport("TDatas", "@rxdrag/website-components");
@@ -16382,7 +16369,7 @@ class ComponentCoder extends Coder {
16382
16369
  let code = "\n";
16383
16370
  code += this.getPropsTypeCode();
16384
16371
  const xdatas = this.getXDataSchemas();
16385
- code += `export default function ${this.component.name}(props: ${this.component.name}Props) {
16372
+ code += `export function ${this.component.name}(props: ${this.component.name}Props) {
16386
16373
  `;
16387
16374
  const childrenCode = this.component.droppable ? `, children` : "";
16388
16375
  const propsStr = (_b2 = (_a2 = this.component.props) == null ? void 0 : _a2.items) == null ? void 0 : _b2.map((field) => field.name).join(", ");
@@ -16412,18 +16399,23 @@ class ComponentCoder extends Coder {
16412
16399
  return code;
16413
16400
  }
16414
16401
  getPropsTypeCode() {
16415
- var _a2;
16402
+ var _a2, _b2;
16416
16403
  let code = `export type ${this.component.name}Props = {
16417
16404
  `;
16418
16405
  code += ` className?: string
16419
16406
  `;
16420
16407
  if (this.getXDataSchemas().length) {
16421
- code += ` datas: TDatas
16408
+ code += ` datas?: TDatas
16422
16409
  `;
16423
16410
  }
16424
16411
  for (const field of ((_a2 = this.component.props) == null ? void 0 : _a2.items) || []) {
16425
- code += ` ${field.name}: ${field.type}
16412
+ if (field.type === ExtendFieldType.Json) {
16413
+ code += ` ${field.name}?: any
16426
16414
  `;
16415
+ } else {
16416
+ code += ` ${field.name}: ${(_b2 = field.type) == null ? void 0 : _b2.toLowerCase()}
16417
+ `;
16418
+ }
16427
16419
  }
16428
16420
  if (this.component.droppable) {
16429
16421
  code += ` children: React.ReactNode
@@ -16738,6 +16730,7 @@ class WebsiteGenerator {
16738
16730
  return this.studioProps.frame;
16739
16731
  }
16740
16732
  async generate() {
16733
+ var _a2, _b2, _c2;
16741
16734
  const zip = new JSZip();
16742
16735
  const pages = this.getPages();
16743
16736
  const frame = this.getFrame();
@@ -16764,7 +16757,7 @@ class WebsiteGenerator {
16764
16757
  );
16765
16758
  usedMaterials.push(...frameCoder.getUsedMaterials());
16766
16759
  appFolder.file(frameCoder.getFileName(), frameCoder.getFileCode());
16767
- appFolder.file(tailwindCssTemplate.name, tailwindCssTemplate.content);
16760
+ appFolder.file(tailwindCssTemplate.name, tailwindCssTemplate.content.replace(CSS_CONTENT, ((_a2 = this.studioProps.theme) == null ? void 0 : _a2.css) || ""));
16768
16761
  const deplyFolder = appFolder.folder("deploy");
16769
16762
  if (deplyFolder) {
16770
16763
  deplyFolder.file(deployEnvTemplate.name, deployEnvTemplate.content);
@@ -16775,9 +16768,11 @@ class WebsiteGenerator {
16775
16768
  if (routesFolder) {
16776
16769
  routesFolder.file(slugTemplate.name, slugTemplate.content);
16777
16770
  for (const page of pages || []) {
16778
- const pageCoder = new PageCoder(comsStore, page);
16779
- routesFolder.file(pageCoder.getFileName(), pageCoder.getFileCode());
16780
- usedMaterials.push(...pageCoder.getUsedMaterials());
16771
+ if ((_c2 = (_b2 = page.content) == null ? void 0 : _b2.elements) == null ? void 0 : _c2.length) {
16772
+ const pageCoder = new PageCoder(comsStore, page);
16773
+ routesFolder.file(pageCoder.getFileName(), pageCoder.getFileCode());
16774
+ usedMaterials.push(...pageCoder.getUsedMaterials());
16775
+ }
16781
16776
  }
16782
16777
  }
16783
16778
  const componentsFolder = appFolder == null ? void 0 : appFolder.folder("components");
@@ -16787,7 +16782,7 @@ class WebsiteGenerator {
16787
16782
  componentsFolder.file(comCoder.getFileName(), comCoder.getFileCode());
16788
16783
  usedMaterials.push(...comCoder.getUsedMaterials());
16789
16784
  }
16790
- componentsFolder.file("index.ts", coders.map((coder) => `export { ${coder.getComponent().name} } from "./components/${coder.getComponent().name}"`).join("\n"));
16785
+ componentsFolder.file("index.ts", coders.map((coder) => `export { ${coder.getComponent().name} } from "./${coder.getComponent().name}"`).join("\n"));
16791
16786
  }
16792
16787
  }
16793
16788
  const packages = {};