@rxdrag/website-studio 0.0.16 → 0.0.17

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.mjs CHANGED
@@ -6,7 +6,7 @@ var __publicField = (obj, key, value) => {
6
6
  };
7
7
  import * as React from "react";
8
8
  import React__default, { createContext, useContext, useMemo, memo, useEffect, useCallback, useState, useRef, forwardRef as forwardRef$1, useImperativeHandle, isValidElement, cloneElement, Component } from "react";
9
- import { ThemeQueryOptions, ThemeFields, PageQueryOptions, PageFields, PageAssciations, FrontComponentQueryOptions, FrontComponentFields, ComponentCategoryFields, ProductCategoryEntityName, ProductCategoryQueryOptions, ProductCategoryFields, ProductQueryOptions, ProductFields, PublishableStatus, ComponentType, FrontComponentEntityName, pageToInputCascade, frontComponentToInput, ComponentCategoryQueryOptions, ExtendFieldType, ThemeConfigQueryOptions, ThemeConfigFields, ThemeConfigAssciations, MediaQueryOptions, themeConfigToInput, ThemeConfigEntityName, themeConfigToInputCascade, MediaType, PageEntityName, PageType, pageToInput, ComponentCategoryEntityName, componentCategoryToInput, PageMetaFields, themeToInput, ThemeEntityName } from "@rxdrag/rxcms-models";
9
+ import { ThemeQueryOptions, ThemeFields, LangFields, PageQueryOptions, PageFields, PageAssciations, FrontComponentQueryOptions, FrontComponentFields, ComponentCategoryFields, ProductCategoryEntityName, ProductCategoryQueryOptions, ProductCategoryFields, ProductQueryOptions, ProductFields, PublishableStatus, ComponentType, PageType, FrontComponentEntityName, pageToInputCascade, frontComponentToInput, ComponentCategoryQueryOptions, ExtendFieldType, ThemeConfigQueryOptions, ThemeConfigFields, ThemeConfigAssciations, MediaQueryOptions, themeConfigToInput, ThemeConfigEntityName, themeConfigToInputCascade, MediaType, PageEntityName, pageToInput, ComponentCategoryEntityName, componentCategoryToInput, PageMetaFields, themeToInput, ThemeEntityName } from "@rxdrag/rxcms-models";
10
10
  import { GlobalLoading, EntityEditModal, EntitySelectField, EditingPopoverScope, EntityForm, SubmitButton, useRemoveRow, useEditRow, EntityListScope, EntityRowScope, useListData, QueryListScope, useNewRow, useIsLoading, NewButton } from "@rxdrag/rxcms-models-ui";
11
11
  import { useOneTheme, usePageList, useFrontComponentList, useUpsertOnePage, useUpsertOneTheme, useOneThemeConfig, useUpsertOneThemeConfig, useDeletePageById, useComponentCategoryList, useUpsertOneFrontComponent } from "@rxdrag/rxcms-model-hooks";
12
12
  import { newPageMetaOptions, useWebsite, useCurrentLang, MediaSingleSelectField, TitleAndSlug, TitleViewField, DescriptionViewField, currentLangState } from "@rxdrag/biz-components";
@@ -17,17 +17,18 @@ import { NodeMountedEvent, RXID_ATTR_NAME, MARGIN_DECORATOR_NAME, LINE_DECORTOR_
17
17
  import { useVariables, useExecuteExpression, VariableProvider, expressionAndName, expressionTernaryName, expressionLoopName, useViewKey, createSchema, staticMaterials, slotContentName, expressionName, ViewKeyProvider } from "@rxdrag/website-materials";
18
18
  import { isHTMLElement } from "@rxdrag/shared";
19
19
  import { isFunction, keys, debounce, uniqueId } from "lodash-es";
20
- import { useEntifyEndpoint, useEntifyToken, emitEntityChange, useLazyQueryEntityList } from "@rxdrag/entify-hooks";
20
+ import { useEntifyEndpoint, useEntifyToken, useLazyQueryEntityList, emitEntityChange } from "@rxdrag/entify-hooks";
21
21
  import dayjs from "dayjs";
22
- import { ErrorBoundary, ColorPicker, StyledTooltip, Modal, ModalContent, ModalHeader, ModalBody, WarningIcon, ModalFooter, SettingsIcon, AddIcon, Drawer, ModalClose, PinIcon, CloseIcon, LeafNode, AstroIcon, GroupNode, SearchIcon, TreeView, PredefinedColorPicker, LightIcon, DarkIcon, HomeIcon, RemoveIcon, saveFile, getTheFile, ConfirmDialog, ChevronDownIcon, BackArrowIcon, MenuIcon } from "@rxdrag/rxcms-common";
22
+ import { ErrorBoundary, ColorPicker, saveFile, StyledTooltip, Modal, ModalContent, ModalHeader, ModalBody, WarningIcon, ModalFooter, SettingsIcon, AddIcon, Drawer, ModalClose, PinIcon, CloseIcon, LeafNode, AstroIcon, GroupNode, SearchIcon, TreeView, PredefinedColorPicker, LightIcon, DarkIcon, HomeIcon, RemoveIcon, getTheFile, ConfirmDialog, ChevronDownIcon, BackArrowIcon, MenuIcon } from "@rxdrag/rxcms-common";
23
23
  import { PageLoader, PopoverController, ModalController, AnimateController, TabsController, NumberController, FlipController, AosController } from "@rxdrag/website-lib-core";
24
24
  import gsap from "gsap";
25
25
  import { Input, Textarea, ImageSelect, TargetSetter, propSetters, DeviceBreakpoints, DeviceContext } from "@rxdrag/schema-setters";
26
26
  import { Switch, cn, Button as Button$1, Divider, Tabs, Tab, Accordion, AccordionItem, Input as Input$1, Select, SelectItem, Card, CardHeader, CardBody, Dropdown, DropdownTrigger, DropdownMenu, DropdownItem, CircularProgress, Popover, PopoverTrigger, PopoverContent, useDisclosure, Link } from "@heroui/react";
27
+ import { globalErrorState, useUpsertEntityWithIndicator, globalSuccessState } from "@rxdrag/rxcms-entify-wrapper";
28
+ import { useSetRecoilState, atom, atomFamily, selectorFamily, useRecoilValue, useRecoilState } from "recoil";
29
+ import JSZip from "jszip";
27
30
  import { LazyMotion, AnimatePresence, m } from "framer-motion";
28
31
  import { Icon } from "@iconify/react";
29
- import { atom, atomFamily, selectorFamily, useRecoilValue, useRecoilState, useSetRecoilState } from "recoil";
30
- import { useUpsertEntityWithIndicator, globalErrorState, globalSuccessState } from "@rxdrag/rxcms-entify-wrapper";
31
32
  import { InputField, TextareaField, Form } from "@rxdrag/fieldy-heroui";
32
33
  import ReactDOM, { createPortal } from "react-dom";
33
34
  import Editor, { loader } from "@monaco-editor/react";
@@ -38,7 +39,6 @@ import * as monaco from "monaco-editor";
38
39
  import { ObjectField, VirtualForm } from "@rxdrag/react-fieldy-pro";
39
40
  import { ComponentRender } from "@rxdrag/react-runner-pro";
40
41
  import tinycolor from "tinycolor2";
41
- import JSZip from "jszip";
42
42
  import { useParams } from "react-router-dom";
43
43
  var jsxRuntime = { exports: {} };
44
44
  var reactJsxRuntime_production_min = {};
@@ -1036,7 +1036,7 @@ function newThemeQueryOptions(websiteId, langId) {
1036
1036
  }
1037
1037
  }
1038
1038
  }
1039
- ).setNoQuery(!websiteId || !langId);
1039
+ ).website().lang([LangFields.id, LangFields.abbr]).setNoQuery(!websiteId || !langId);
1040
1040
  }
1041
1041
  function StudioRoot(props) {
1042
1042
  const { websiteId, langId, previewUrl, aiUrl, backUrl, children } = props;
@@ -2634,523 +2634,1482 @@ function useCustomizedMaterials() {
2634
2634
  }, [components]);
2635
2635
  return materials;
2636
2636
  }
2637
- const studioSetters = {
2638
- ...propSetters,
2639
- Fragment: React__default.Fragment
2640
- // TabList,
2641
- // Tab,
2642
- // TabPanel,
2643
- // Stack,
2644
- // FormControl,
2645
- // FormLabel: FormLabel,
2646
- // Autocomplete: Autocomplete,
2647
- // Input: toControlled(Input, 'value', ''),
2648
- // Textarea: toControlled(Textarea, 'value', ''),
2649
- //Select,
2650
- //Option: Option,
2651
- //Switch: Switch,
2652
- //IconPicker,
2653
- //ToggleButtonGroup,
2654
- // Button,
2655
- // IconButton,
2656
- // SlotSwitch,
2657
- };
2658
- function useAllMaterials() {
2659
- const customMaterials = useCustomizedMaterials();
2660
- const materials = useMemo(() => {
2661
- return staticMaterials.concat(customMaterials || []);
2662
- }, [customMaterials]);
2663
- return materials;
2664
- }
2665
- function EditorScope(props) {
2666
- const { children, resources, ...rest } = props;
2667
- const materials = useAllMaterials();
2668
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
2669
- Designer,
2670
- {
2671
- resources,
2672
- materials,
2673
- setters: studioSetters,
2674
- ...rest,
2675
- children
2676
- }
2637
+ function useGetFrontComponents() {
2638
+ const query = useLazyQueryEntityList();
2639
+ const getFrontCompoents = useCallback(
2640
+ async (themeId) => {
2641
+ return await query(
2642
+ new FrontComponentQueryOptions(
2643
+ [
2644
+ FrontComponentFields.id,
2645
+ FrontComponentFields.name,
2646
+ FrontComponentFields.title,
2647
+ FrontComponentFields.seqValue,
2648
+ FrontComponentFields.updatedAt,
2649
+ FrontComponentFields.code,
2650
+ FrontComponentFields.testConfig,
2651
+ FrontComponentFields.props,
2652
+ FrontComponentFields.slots,
2653
+ FrontComponentFields.droppable
2654
+ ],
2655
+ {
2656
+ where: {
2657
+ theme: {
2658
+ id: {
2659
+ _eq: themeId
2660
+ }
2661
+ }
2662
+ },
2663
+ orderBy: [
2664
+ {
2665
+ [FrontComponentFields.seqValue]: "asc"
2666
+ },
2667
+ {
2668
+ [FrontComponentFields.createdAt]: "asc"
2669
+ }
2670
+ ]
2671
+ }
2672
+ ).category([ComponentCategoryFields.id, ComponentCategoryFields.name]).theme().setNoQuery(!themeId).toGqlOptions()
2673
+ );
2674
+ },
2675
+ [query]
2677
2676
  );
2677
+ return getFrontCompoents;
2678
2678
  }
2679
- var ContentType = /* @__PURE__ */ ((ContentType2) => {
2680
- ContentType2["Page"] = "page";
2681
- ContentType2["Component"] = "component";
2682
- ContentType2["PredefinedPage"] = "PredefinedPage";
2683
- return ContentType2;
2684
- })(ContentType || {});
2685
- var DrawerConentType = /* @__PURE__ */ ((DrawerConentType2) => {
2686
- DrawerConentType2["Insert"] = "insert";
2687
- DrawerConentType2["Layers"] = "layers";
2688
- DrawerConentType2["SEO"] = "seo";
2689
- DrawerConentType2["SEM"] = "sem";
2690
- DrawerConentType2["SNS"] = "sns";
2691
- DrawerConentType2["ComponentSchema"] = "componentSchema";
2692
- DrawerConentType2["ComponentTest"] = "componentTest";
2693
- return DrawerConentType2;
2694
- })(DrawerConentType || {});
2695
- var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
2696
- DeviceType2["Mobile"] = "mobile";
2697
- DeviceType2["Tablet"] = "tablet";
2698
- DeviceType2["Desktop"] = "desktop";
2699
- return DeviceType2;
2700
- })(DeviceType || {});
2701
- var ViewMode = /* @__PURE__ */ ((ViewMode2) => {
2702
- ViewMode2["Design"] = "design";
2703
- ViewMode2["Preview"] = "preview";
2704
- ViewMode2["Code"] = "code";
2705
- return ViewMode2;
2706
- })(ViewMode || {});
2707
- const Sheet = forwardRef$1((props, ref) => {
2708
- const { className, children, ...rest } = props;
2709
- return /* @__PURE__ */ jsxRuntimeExports.jsx(
2710
- "div",
2711
- {
2712
- ref,
2713
- className: cn(className, "border-divider bg-black"),
2714
- ...rest,
2715
- children
2716
- }
2679
+ function useGetPages() {
2680
+ const query = useLazyQueryEntityList();
2681
+ const getPages = useCallback(
2682
+ async (themeId) => {
2683
+ return await query(
2684
+ new PageQueryOptions(
2685
+ [
2686
+ PageFields.id,
2687
+ PageFields.title,
2688
+ PageFields.createdAt,
2689
+ PageFields.updatedAt,
2690
+ PageFields.slug,
2691
+ PageFields.code,
2692
+ PageFields.pageType,
2693
+ PageFields.dataSource
2694
+ ],
2695
+ {
2696
+ where: {
2697
+ [PageAssciations.theme]: {
2698
+ id: { _eq: themeId }
2699
+ }
2700
+ },
2701
+ orderBy: [
2702
+ {
2703
+ createdAt: "desc"
2704
+ }
2705
+ ]
2706
+ }
2707
+ ).meta(newPageMetaOptions()).setNoQuery(!themeId).toGqlOptions()
2708
+ );
2709
+ },
2710
+ [query]
2717
2711
  );
2712
+ return getPages;
2713
+ }
2714
+ const packageCode = `{
2715
+ "name": "astro-project",
2716
+ "type": "module",
2717
+ "version": "0.0.1",
2718
+ "scripts": {
2719
+ "dev": "astro dev",
2720
+ "start": "astro dev",
2721
+ "build": "astro build",
2722
+ "preview": "astro preview",
2723
+ "astro": "astro"
2724
+ },
2725
+ "dependencies": {
2726
+ "@astrojs/react": "^4.2.0",
2727
+ "@iconify/react": "^5.0.2",
2728
+ "@rxdrag/website-lib": "^0.0.10",
2729
+ "@rxdrag/website-lib-core": "^0.0.8",
2730
+ "@rxdrag/slate-preview": "^1.2.55",
2731
+ "@rxdrag/rxcms-models": "^0.3.46",
2732
+ "astro": "^5.3.0",
2733
+ "dayjs": "^1.11.7",
2734
+ "gsap": "^3.12.7",
2735
+ "react": "^18.2.0",
2736
+ "react-dom": "^18.2.0"
2737
+ },
2738
+ "devDependencies": {
2739
+ "@astrojs/node": "^9.1.3",
2740
+ "@astrojs/tailwind": "^6.0.0",
2741
+ "@astrojs/vercel": "^8.1.2",
2742
+ "@tailwindcss/forms": "^0.5.7",
2743
+ "@tailwindcss/typography": "^0.5.13",
2744
+ "@types/react": "^18.2.20",
2745
+ "@types/react-dom": "^18.2.7",
2746
+ "tailwindcss": "^3.4.1"
2747
+ }
2748
+ }`;
2749
+ const astroConfig = `import { defineConfig } from "astro/config";
2750
+ import tailwind from "@astrojs/tailwind";
2751
+ import react from "@astrojs/react";
2752
+ import node from "@astrojs/node";
2753
+
2754
+ export default defineConfig({
2755
+ integrations: [tailwind(), react()],
2756
+ output: "server", // 使用服务端渲染模式
2757
+ adapter: node({
2758
+ mode: "standalone", // 使用独立模式
2759
+ }), // 使用 Node.js 适配器
2718
2760
  });
2719
- var solid = {
2720
- default: "bg-default text-default-foreground",
2721
- primary: "bg-primary text-primary-foreground",
2722
- secondary: "bg-secondary text-secondary-foreground",
2723
- success: "bg-success text-success-foreground",
2724
- warning: "bg-warning text-warning-foreground",
2725
- danger: "bg-danger text-danger-foreground",
2726
- foreground: "bg-foreground text-background"
2727
- };
2728
- var shadow = {
2729
- default: "shadow-lg shadow-default/50 bg-default text-default-foreground",
2730
- primary: "shadow-lg shadow-primary/40 bg-primary text-primary-foreground",
2731
- secondary: "shadow-lg shadow-secondary/40 bg-secondary text-secondary-foreground",
2732
- success: "shadow-lg shadow-success/40 bg-success text-success-foreground",
2733
- warning: "shadow-lg shadow-warning/40 bg-warning text-warning-foreground",
2734
- danger: "shadow-lg shadow-danger/40 bg-danger text-danger-foreground",
2735
- foreground: "shadow-lg shadow-foreground/40 bg-foreground text-background"
2736
- };
2737
- var bordered = {
2738
- default: "bg-transparent border-default text-foreground",
2739
- primary: "bg-transparent border-primary text-primary",
2740
- secondary: "bg-transparent border-secondary text-secondary",
2741
- success: "bg-transparent border-success text-success",
2742
- warning: "bg-transparent border-warning text-warning",
2743
- danger: "bg-transparent border-danger text-danger",
2744
- foreground: "bg-transparent border-foreground text-foreground"
2745
- };
2746
- var flat = {
2747
- default: "bg-default/40 text-default-700",
2748
- primary: "bg-primary/20 text-primary-600",
2749
- secondary: "bg-secondary/20 text-secondary-600",
2750
- success: "bg-success/20 text-success-700 dark:text-success",
2751
- warning: "bg-warning/20 text-warning-700 dark:text-warning",
2752
- danger: "bg-danger/20 text-danger-600 dark:text-danger-500",
2753
- foreground: "bg-foreground/10 text-foreground"
2754
- };
2755
- var faded = {
2756
- default: "border-default bg-default-100 text-default-foreground",
2757
- primary: "border-default bg-default-100 text-primary",
2758
- secondary: "border-default bg-default-100 text-secondary",
2759
- success: "border-default bg-default-100 text-success",
2760
- warning: "border-default bg-default-100 text-warning",
2761
- danger: "border-default bg-default-100 text-danger",
2762
- foreground: "border-default bg-default-100 text-foreground"
2763
- };
2764
- var light = {
2765
- default: "bg-transparent text-default-foreground",
2766
- primary: "bg-transparent text-primary",
2767
- secondary: "bg-transparent text-secondary",
2768
- success: "bg-transparent text-success",
2769
- warning: "bg-transparent text-warning",
2770
- danger: "bg-transparent text-danger",
2771
- foreground: "bg-transparent text-foreground"
2772
- };
2773
- var ghost = {
2774
- default: "border-default text-default-foreground",
2775
- primary: "border-primary text-primary",
2776
- secondary: "border-secondary text-secondary",
2777
- success: "border-success text-success",
2778
- warning: "border-warning text-warning",
2779
- danger: "border-danger text-danger",
2780
- foreground: "border-foreground text-foreground hover:!bg-foreground"
2761
+ `;
2762
+ const tsconfigCode = `{
2763
+ "extends": "astro/tsconfigs/strict",
2764
+ "compilerOptions": {
2765
+ "jsx": "react-jsx",
2766
+ "jsxImportSource": "react"
2767
+ },
2768
+ "include": [".astro/types.d.ts", "**/*"],
2769
+ "exclude": ["dist"]
2770
+ }
2771
+ `;
2772
+ const createEnv = (theme) => {
2773
+ var _a, _b;
2774
+ return `#PUBLIC_ENTIFY_SERVER_URL = https://api.yizhanfei.com/graphql
2775
+ #PUBLIC_ENTIFY_SERVER_URL = http://localhost:3000/graphql
2776
+ PUBLIC_ENTIFY_SERVER_URL =http://localhost:4000/graphql
2777
+ #PUBLIC_ENTIFY_SERVER_URL =https://api-test2.liaoker.com/graphql
2778
+ #测试服务器跟生产服务器
2779
+ PUBLIC_WEBSITE_ID = ${(_a = theme == null ? void 0 : theme.website) == null ? void 0 : _a.id}
2780
+ #语言
2781
+ PUBLIC_LANGUAGE = ${(_b = theme == null ? void 0 : theme.lang) == null ? void 0 : _b.abbr}
2782
+ #nodejs服务地址
2783
+ #PUBLIC_WEBSITE_ID = 4299262263296
2784
+ PUBLIC_ENTIFY_GUEST_TOKEN = "17bD#4!fG8^2wS*0z"
2785
+ #表单加密盐
2786
+ PUBLIC_FORM_SALT = "yizhanfeinb"
2787
+ `;
2781
2788
  };
2782
- var colorVariants = {
2783
- solid,
2784
- shadow,
2785
- bordered,
2786
- flat,
2787
- faded,
2788
- light,
2789
- ghost
2789
+ const gitignoreCode = `# build output
2790
+ dist/
2791
+
2792
+ # generated types
2793
+ .astro/
2794
+
2795
+ # dependencies
2796
+ node_modules/
2797
+
2798
+ # logs
2799
+ npm-debug.log*
2800
+ yarn-debug.log*
2801
+ yarn-error.log*
2802
+ pnpm-debug.log*
2803
+
2804
+ # environment variables
2805
+ .env
2806
+ .env.production
2807
+
2808
+ # macOS-specific files
2809
+ .DS_Store
2810
+
2811
+ # jetbrains setting folder
2812
+ .idea/
2813
+
2814
+ `;
2815
+ const faviconCode = `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 36 36">
2816
+ <path fill="#000" d="M22.25 4h-8.5a1 1 0 0 0-.96.73l-5.54 19.4a.5.5 0 0 0 .62.62l5.05-1.44a2 2 0 0 0 1.38-1.4l3.22-11.66a.5.5 0 0 1 .96 0l3.22 11.67a2 2 0 0 0 1.38 1.39l5.05 1.44a.5.5 0 0 0 .62-.62l-5.54-19.4a1 1 0 0 0-.96-.73Z"/>
2817
+ <path fill="url(#gradient)" d="M18 28a7.63 7.63 0 0 1-3-.61v.61a3 3 0 0 0 6 0v-.61c-.94.4-1.95.61-3 .61Z"/>
2818
+ <defs>
2819
+ <linearGradient id="gradient" x1="18" x2="18" y1="28" y2="31" gradientUnits="userSpaceOnUse">
2820
+ <stop stop-color="#FF1639"/>
2821
+ <stop offset="1" stop-color="#FF1639" stop-opacity="0"/>
2822
+ </linearGradient>
2823
+ </defs>
2824
+ </svg>`;
2825
+ const createBaseCssCode = (theme) => {
2826
+ return `@tailwind base;
2827
+ @tailwind components;
2828
+ @tailwind utilities;
2829
+
2830
+ ${theme.css || ""}
2831
+
2832
+ `;
2790
2833
  };
2791
- var COMMON_UNITS = ["small", "medium", "large"];
2792
- var twMergeConfig = {
2834
+ const tailwindConfigCode = `import plugin from "tailwindcss/plugin";
2835
+
2836
+ export default {
2837
+ darkMode: "class", // 使用class策略来控制暗色模式
2838
+ content: [
2839
+ "./src/**/*.{astro,html,js,jsx,md,mdx,svelte,ts,tsx,vue}",
2840
+ "node_modules/@rxdrag/website-lib/src/**/*.{js,ts,jsx,tsx}",
2841
+ "node_modules/@rxdrag/website-lib-core/src/**/*.{js,ts,jsx,tsx}",
2842
+ ],
2793
2843
  theme: {
2794
- opacity: ["disabled"],
2795
- spacing: ["divider"],
2796
- borderWidth: COMMON_UNITS,
2797
- borderRadius: COMMON_UNITS
2844
+ extend: {},
2798
2845
  },
2799
- classGroups: {
2800
- shadow: [{ shadow: COMMON_UNITS }],
2801
- "font-size": [{ text: ["tiny", ...COMMON_UNITS] }],
2802
- "bg-image": [
2803
- "bg-stripe-gradient-default",
2804
- "bg-stripe-gradient-primary",
2805
- "bg-stripe-gradient-secondary",
2806
- "bg-stripe-gradient-success",
2807
- "bg-stripe-gradient-warning",
2808
- "bg-stripe-gradient-danger"
2809
- ]
2810
- }
2811
- };
2812
- var l = (e) => typeof e == "boolean" ? `${e}` : e === 0 ? "0" : e, u = (e) => !e || typeof e != "object" || Object.keys(e).length === 0, x$1 = (e, o) => JSON.stringify(e) === JSON.stringify(o);
2813
- function i(e, o) {
2814
- e.forEach(function(r2) {
2815
- Array.isArray(r2) ? i(r2, o) : o.push(r2);
2816
- });
2817
- }
2818
- function y(e) {
2819
- let o = [];
2820
- return i(e, o), o;
2821
- }
2822
- var a = (...e) => y(e).filter(Boolean), p = (e, o) => {
2823
- let r2 = {}, c = Object.keys(e), f = Object.keys(o);
2824
- for (let t of c)
2825
- if (f.includes(t)) {
2826
- let s = e[t], n = o[t];
2827
- Array.isArray(s) || Array.isArray(n) ? r2[t] = a(n, s) : typeof s == "object" && typeof n == "object" ? r2[t] = p(s, n) : r2[t] = n + " " + s;
2828
- } else
2829
- r2[t] = e[t];
2830
- for (let t of f)
2831
- c.includes(t) || (r2[t] = o[t]);
2832
- return r2;
2833
- }, g = (e) => !e || typeof e != "string" ? e : e.replace(/\s+/g, " ").trim();
2834
- const CLASS_PART_SEPARATOR = "-";
2835
- const createClassGroupUtils = (config) => {
2836
- const classMap = createClassMap(config);
2837
- const {
2838
- conflictingClassGroups,
2839
- conflictingClassGroupModifiers
2840
- } = config;
2841
- const getClassGroupId = (className) => {
2842
- const classParts = className.split(CLASS_PART_SEPARATOR);
2843
- if (classParts[0] === "" && classParts.length !== 1) {
2844
- classParts.shift();
2845
- }
2846
- return getGroupRecursive(classParts, classMap) || getGroupIdForArbitraryProperty(className);
2847
- };
2848
- const getConflictingClassGroupIds = (classGroupId, hasPostfixModifier) => {
2849
- const conflicts = conflictingClassGroups[classGroupId] || [];
2850
- if (hasPostfixModifier && conflictingClassGroupModifiers[classGroupId]) {
2851
- return [...conflicts, ...conflictingClassGroupModifiers[classGroupId]];
2852
- }
2853
- return conflicts;
2854
- };
2855
- return {
2856
- getClassGroupId,
2857
- getConflictingClassGroupIds
2858
- };
2859
- };
2860
- const getGroupRecursive = (classParts, classPartObject) => {
2861
- var _a;
2862
- if (classParts.length === 0) {
2863
- return classPartObject.classGroupId;
2864
- }
2865
- const currentClassPart = classParts[0];
2866
- const nextClassPartObject = classPartObject.nextPart.get(currentClassPart);
2867
- const classGroupFromNextClassPart = nextClassPartObject ? getGroupRecursive(classParts.slice(1), nextClassPartObject) : void 0;
2868
- if (classGroupFromNextClassPart) {
2869
- return classGroupFromNextClassPart;
2870
- }
2871
- if (classPartObject.validators.length === 0) {
2872
- return void 0;
2873
- }
2874
- const classRest = classParts.join(CLASS_PART_SEPARATOR);
2875
- return (_a = classPartObject.validators.find(({
2876
- validator
2877
- }) => validator(classRest))) == null ? void 0 : _a.classGroupId;
2846
+ plugins: [
2847
+ require("@tailwindcss/forms"),
2848
+ require("@tailwindcss/typography"),
2849
+ plugin(function ({ addVariant }) {
2850
+ addVariant("scrolling", ".scrolling &");
2851
+ addVariant("open", [".open&", ".open &"]);
2852
+ addVariant("actived", [".actived&", ".actived &"]);
2853
+ addVariant("disabled", [".disabled&", ".disabled &"]);
2854
+ addVariant("selected", [".selected&", ".selected &"]);
2855
+ }),
2856
+ ],
2878
2857
  };
2879
- const arbitraryPropertyRegex = /^\[(.+)\]$/;
2880
- const getGroupIdForArbitraryProperty = (className) => {
2881
- if (arbitraryPropertyRegex.test(className)) {
2882
- const arbitraryPropertyClassName = arbitraryPropertyRegex.exec(className)[1];
2883
- const property = arbitraryPropertyClassName == null ? void 0 : arbitraryPropertyClassName.substring(0, arbitraryPropertyClassName.indexOf(":"));
2884
- if (property) {
2885
- return "arbitrary.." + property;
2886
- }
2858
+
2859
+ `;
2860
+ const libCode = `import {
2861
+ Entify,
2862
+ type EnvVariables,
2863
+ type IEntify,
2864
+ } from "@rxdrag/website-lib-core";
2865
+
2866
+ export function getEnvVariables(): EnvVariables {
2867
+ return {
2868
+ websiteId: ({}).PUBLIC_WEBSITE_ID,
2869
+ entifyServerUrl: ({}).PUBLIC_ENTIFY_SERVER_URL,
2870
+ entifyGuestToken: ({}).PUBLIC_ENTIFY_GUEST_TOKEN,
2871
+ language: ({}).PUBLIC_LANGUAGE,
2872
+ formSalt: ({}).PUBLIC_FORM_SALT || "yizhanfei",
2873
+ };
2887
2874
  }
2888
- };
2889
- const createClassMap = (config) => {
2890
- const {
2891
- theme,
2892
- prefix
2893
- } = config;
2894
- const classMap = {
2895
- nextPart: /* @__PURE__ */ new Map(),
2896
- validators: []
2897
- };
2898
- const prefixedClassGroupEntries = getPrefixedClassGroupEntries(Object.entries(config.classGroups), prefix);
2899
- prefixedClassGroupEntries.forEach(([classGroupId, classGroup]) => {
2900
- processClassesRecursively(classGroup, classMap, classGroupId, theme);
2901
- });
2902
- return classMap;
2903
- };
2904
- const processClassesRecursively = (classGroup, classPartObject, classGroupId, theme) => {
2905
- classGroup.forEach((classDefinition) => {
2906
- if (typeof classDefinition === "string") {
2907
- const classPartObjectToEdit = classDefinition === "" ? classPartObject : getPart(classPartObject, classDefinition);
2908
- classPartObjectToEdit.classGroupId = classGroupId;
2909
- return;
2910
- }
2911
- if (typeof classDefinition === "function") {
2912
- if (isThemeGetter(classDefinition)) {
2913
- processClassesRecursively(classDefinition(theme), classPartObject, classGroupId, theme);
2914
- return;
2875
+
2876
+ export const rx = Entify.getInstance(getEnvVariables()) as IEntify;
2877
+ `;
2878
+ const layoutCode = `---
2879
+ import "../base.css";
2880
+ import { ClientRouter } from "astro:transitions";
2881
+ ---
2882
+
2883
+ <!doctype html>
2884
+ <html lang="zh-CN">
2885
+ <head>
2886
+ <meta charset="UTF-8" />
2887
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
2888
+ <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
2889
+ <meta name="generator" content={Astro.generator} />
2890
+ <ClientRouter />
2891
+ <slot name="meta" />
2892
+ </head>
2893
+ <body>
2894
+ <slot />
2895
+ </body>
2896
+ </html>
2897
+
2898
+ <style>
2899
+ html,
2900
+ body {
2901
+ margin: 0;
2902
+ width: 100%;
2903
+ height: 100%;
2904
+ }
2905
+ </style>
2906
+ `;
2907
+ const askForQuoteCode = `import type { APIRoute } from "astro";
2908
+ import type {
2909
+ SpamFilterRule,
2910
+ SpamFilterRuleBoolExp,
2911
+ SpamFilterRuleDistinctExp,
2912
+ SpamFilterRuleOrderBy,
2913
+ } from "@rxdrag/rxcms-models";
2914
+ import {
2915
+ EnquiryAssciations,
2916
+ EnquiryEntityName,
2917
+ EnquiryFields,
2918
+ SpamFilterRuleFields,
2919
+ SpamFilterRuleQueryOptions,
2920
+ } from "@rxdrag/rxcms-models";
2921
+ import { getEnvVariables, rx } from "../../lib";
2922
+ import {
2923
+ queryWebSiteSettings,
2924
+ sendEmail,
2925
+ upsertEntity,
2926
+ verifyEncryption,
2927
+ type QuoteRequest,
2928
+ } from "@rxdrag/website-lib-core";
2929
+
2930
+ // 标记此页面为服务器渲染,而不是静态生成
2931
+ export const prerender = false;
2932
+
2933
+ export const POST: APIRoute = async ({ request }) => {
2934
+ try {
2935
+ const envVariables = getEnvVariables();
2936
+
2937
+ // 从请求中获取JSON数据
2938
+ let requestData: QuoteRequest;
2939
+ try {
2940
+ requestData = await request.json();
2941
+ } catch (error) {
2942
+ console.error("JSON parsing error:", error);
2943
+ return new Response(
2944
+ JSON.stringify({
2945
+ success: false,
2946
+ message: "Invalid request format",
2947
+ }),
2948
+ {
2949
+ status: 400,
2950
+ headers: {
2951
+ "Content-Type": "application/json",
2952
+ },
2953
+ }
2954
+ );
2915
2955
  }
2916
- classPartObject.validators.push({
2917
- validator: classDefinition,
2918
- classGroupId
2919
- });
2920
- return;
2921
- }
2922
- Object.entries(classDefinition).forEach(([key, classGroup2]) => {
2923
- processClassesRecursively(classGroup2, getPart(classPartObject, key), classGroupId, theme);
2924
- });
2925
- });
2926
- };
2927
- const getPart = (classPartObject, path) => {
2928
- let currentClassPartObject = classPartObject;
2929
- path.split(CLASS_PART_SEPARATOR).forEach((pathPart) => {
2930
- if (!currentClassPartObject.nextPart.has(pathPart)) {
2931
- currentClassPartObject.nextPart.set(pathPart, {
2932
- nextPart: /* @__PURE__ */ new Map(),
2933
- validators: []
2934
- });
2935
- }
2936
- currentClassPartObject = currentClassPartObject.nextPart.get(pathPart);
2937
- });
2938
- return currentClassPartObject;
2939
- };
2940
- const isThemeGetter = (func) => func.isThemeGetter;
2941
- const getPrefixedClassGroupEntries = (classGroupEntries, prefix) => {
2942
- if (!prefix) {
2943
- return classGroupEntries;
2944
- }
2945
- return classGroupEntries.map(([classGroupId, classGroup]) => {
2946
- const prefixedClassGroup = classGroup.map((classDefinition) => {
2947
- if (typeof classDefinition === "string") {
2948
- return prefix + classDefinition;
2956
+
2957
+ // 验证蜜罐字段
2958
+ if (requestData.phone) {
2959
+ console.log("Honeypot triggered - spam submission detected");
2960
+ // 悄悄失败,返回成功但不处理
2961
+ return new Response(
2962
+ JSON.stringify({
2963
+ success: true,
2964
+ message:
2965
+ "Your enquiry has been submitted successfully, we will contact you soon",
2966
+ }),
2967
+ {
2968
+ status: 200,
2969
+ headers: {
2970
+ "Content-Type": "application/json",
2971
+ },
2972
+ }
2973
+ );
2949
2974
  }
2950
- if (typeof classDefinition === "object") {
2951
- return Object.fromEntries(Object.entries(classDefinition).map(([key, value]) => [prefix + key, value]));
2975
+
2976
+ // 创建实体对象 - 移除不在数据库模型中的字段
2977
+ const { phone, encryptedField, ...entityData } = requestData;
2978
+ const entity: Record<string, unknown> = { ...entityData };
2979
+
2980
+ // 检查蜜罐字段
2981
+ if (phone) {
2982
+ // 蜜罐被触发,拒绝请求
2983
+ return new Response(
2984
+ JSON.stringify({
2985
+ success: false,
2986
+ message: "Form submission rejected",
2987
+ }),
2988
+ {
2989
+ status: 400,
2990
+ headers: {
2991
+ "Content-Type": "application/json",
2992
+ },
2993
+ }
2994
+ );
2952
2995
  }
2953
- return classDefinition;
2954
- });
2955
- return [classGroupId, prefixedClassGroup];
2956
- });
2957
- };
2958
- const createLruCache = (maxCacheSize) => {
2959
- if (maxCacheSize < 1) {
2960
- return {
2961
- get: () => void 0,
2962
- set: () => {
2996
+
2997
+ // 验证加密字段
2998
+ const isValid = verifyEncryption(
2999
+ //加密盐
3000
+ envVariables.formSalt,
3001
+ encryptedField,
3002
+ phone || "",
3003
+ 30 // 30分钟有效期
3004
+ );
3005
+
3006
+ if (!isValid) {
3007
+ // 加密验证失败,拒绝请求
3008
+ return new Response(
3009
+ JSON.stringify({
3010
+ success: false,
3011
+ message: "Invalid form submission",
3012
+ }),
3013
+ {
3014
+ status: 400,
3015
+ headers: {
3016
+ "Content-Type": "application/json",
3017
+ },
3018
+ }
3019
+ );
2963
3020
  }
2964
- };
2965
- }
2966
- let cacheSize = 0;
2967
- let cache = /* @__PURE__ */ new Map();
2968
- let previousCache = /* @__PURE__ */ new Map();
2969
- const update = (key, value) => {
2970
- cache.set(key, value);
2971
- cacheSize++;
2972
- if (cacheSize > maxCacheSize) {
2973
- cacheSize = 0;
2974
- previousCache = cache;
2975
- cache = /* @__PURE__ */ new Map();
3021
+
3022
+ // 获取请求头信息
3023
+ const url =
3024
+ request.headers.get("X-Request-URL") || request.headers.get("referer");
3025
+ const ip =
3026
+ request.headers.get("X-Forwarded-For") ||
3027
+ request.headers.get("X-Real-IP");
3028
+ const userAgent = request.headers.get("user-agent");
3029
+
3030
+ // 设置额外字段
3031
+ entity[EnquiryFields.formIp] = ip;
3032
+ entity[EnquiryFields.fromUrl] = url;
3033
+ entity[EnquiryFields.userAgent] = userAgent;
3034
+ entity[EnquiryFields.read] = false;
3035
+ entity[EnquiryFields.spam] = false;
3036
+ entity[EnquiryAssciations.website] = {
3037
+ sync: { id: envVariables.websiteId },
3038
+ };
3039
+
3040
+ // 验证必填字段
3041
+ if (
3042
+ !entity[EnquiryFields.name] ||
3043
+ !entity[EnquiryFields.email] ||
3044
+ !entity[EnquiryFields.message]
3045
+ ) {
3046
+ return new Response(
3047
+ JSON.stringify({
3048
+ success: false,
3049
+ message: "Please fill in all required fields",
3050
+ }),
3051
+ {
3052
+ status: 400,
3053
+ headers: {
3054
+ "Content-Type": "application/json",
3055
+ },
3056
+ }
3057
+ );
3058
+ }
3059
+
3060
+ // 垃圾信息过滤
3061
+ const spamRules = (
3062
+ await rx.queryEntityList<
3063
+ SpamFilterRule,
3064
+ SpamFilterRuleBoolExp,
3065
+ SpamFilterRuleOrderBy,
3066
+ SpamFilterRuleDistinctExp
3067
+ >(
3068
+ new SpamFilterRuleQueryOptions([
3069
+ SpamFilterRuleFields.emails,
3070
+ SpamFilterRuleFields.ips,
3071
+ SpamFilterRuleFields.keywords,
3072
+ ])
3073
+ )
3074
+ )?.items as SpamFilterRule[] | undefined;
3075
+
3076
+ for (const rule of spamRules || []) {
3077
+ const email = (entity[EnquiryFields.email] as string)?.trim();
3078
+ if (
3079
+ !email ||
3080
+ rule.emails
3081
+ ?.replace(",", ",")
3082
+ .split(",")
3083
+ .map((em) => em.trim())
3084
+ .includes(email) ||
3085
+ (ip &&
3086
+ rule.ips
3087
+ ?.replace(",", ",")
3088
+ .split(",")
3089
+ .map((ipAddr) => ipAddr.trim())
3090
+ .includes(ip)) ||
3091
+ rule.keywords
3092
+ ?.split(",")
3093
+ .some(
3094
+ (keyword: string) =>
3095
+ keyword &&
3096
+ (entity[EnquiryFields.message] as string).includes(keyword)
3097
+ )
3098
+ ) {
3099
+ // 标记为垃圾信息并保存
3100
+ await upsertEntity(
3101
+ EnquiryEntityName,
3102
+ { ...entity, spam: true, read: false },
3103
+ envVariables
3104
+ );
3105
+
3106
+ // 返回404响应,模拟原始行为
3107
+ return new Response(null, { status: 404 });
3108
+ }
3109
+ }
3110
+
3111
+ // 保存询价信息
3112
+ await upsertEntity(EnquiryEntityName, entity, envVariables);
3113
+
3114
+ // 获取网站设置并发送邮件通知
3115
+ const websettins = await queryWebSiteSettings(envVariables);
3116
+ const name = entity?.[EnquiryFields.name] as string;
3117
+
3118
+ if (websettins?.noticeEmail) {
3119
+ const content = \`
3120
+ Company: \${entity[EnquiryFields.company]}
3121
+ Name: \${name}
3122
+ Email: \${entity[EnquiryFields.email]}
3123
+ Message: \${entity[EnquiryFields.message]}
3124
+ IP: \${ip}
3125
+ URL: \${url}
3126
+ CTA: \${entity[EnquiryFields.fromCta]}
3127
+ userAgent: \${userAgent}
3128
+ \`;
3129
+
3130
+ const employeeEmail = {
3131
+ to: websettins?.noticeEmail,
3132
+ subject: "New Enquiry Received",
3133
+ message: content,
3134
+ };
3135
+
3136
+ await sendEmail(employeeEmail, envVariables);
3137
+ }
3138
+
3139
+ // 返回JSON响应
3140
+ return new Response(
3141
+ JSON.stringify({
3142
+ success: true,
3143
+ message:
3144
+ "Your enquiry has been submitted successfully, we will contact you soon",
3145
+ }),
3146
+ {
3147
+ status: 200,
3148
+ headers: {
3149
+ "Content-Type": "application/json",
3150
+ },
3151
+ }
3152
+ );
3153
+ } catch (error) {
3154
+ console.error("Error processing enquiry request:", error);
3155
+
3156
+ // 返回错误响应
3157
+ return new Response(
3158
+ JSON.stringify({
3159
+ success: false,
3160
+ message: "Submission failed, please try again later",
3161
+ }),
3162
+ {
3163
+ status: 500,
3164
+ headers: {
3165
+ "Content-Type": "application/json",
3166
+ },
3167
+ }
3168
+ );
2976
3169
  }
2977
3170
  };
3171
+ `;
3172
+ const settingsCode = `{
3173
+ "css.validate": true,
3174
+ "less.validate": true,
3175
+ "scss.validate": true,
3176
+ "stylelint.validate": ["css", "scss"],
3177
+ "editor.quickSuggestions": {
3178
+ "strings": true
3179
+ },
3180
+ "css.lint.unknownAtRules": "ignore"
3181
+ }
3182
+ `;
3183
+ const extensionsCode = `{
3184
+ "recommendations": ["astro-build.astro-vscode"],
3185
+ "unwantedRecommendations": []
3186
+ }
3187
+ `;
3188
+ const launchCode = `{
3189
+ "version": "0.2.0",
3190
+ "configurations": [
3191
+ {
3192
+ "command": "./node_modules/.bin/astro dev",
3193
+ "name": "Development server",
3194
+ "request": "launch",
3195
+ "type": "node-terminal"
3196
+ }
3197
+ ]
3198
+ }
3199
+ `;
3200
+ const createBaseFiles = (theme) => {
2978
3201
  return {
2979
- get(key) {
2980
- let value = cache.get(key);
2981
- if (value !== void 0) {
2982
- return value;
3202
+ "package.json": {
3203
+ file: {
3204
+ contents: packageCode
2983
3205
  }
2984
- if ((value = previousCache.get(key)) !== void 0) {
2985
- update(key, value);
2986
- return value;
3206
+ },
3207
+ ".gitignore": {
3208
+ file: {
3209
+ contents: gitignoreCode
2987
3210
  }
2988
3211
  },
2989
- set(key, value) {
2990
- if (cache.has(key)) {
2991
- cache.set(key, value);
2992
- } else {
2993
- update(key, value);
3212
+ "astro.config.mjs": {
3213
+ file: {
3214
+ contents: astroConfig
2994
3215
  }
2995
- }
2996
- };
2997
- };
2998
- const IMPORTANT_MODIFIER = "!";
2999
- const createParseClassName = (config) => {
3000
- const {
3001
- separator,
3002
- experimentalParseClassName
3003
- } = config;
3004
- const isSeparatorSingleCharacter = separator.length === 1;
3005
- const firstSeparatorCharacter = separator[0];
3006
- const separatorLength = separator.length;
3007
- const parseClassName = (className) => {
3008
- const modifiers = [];
3009
- let bracketDepth = 0;
3010
- let modifierStart = 0;
3011
- let postfixModifierPosition;
3012
- for (let index = 0; index < className.length; index++) {
3013
- let currentCharacter = className[index];
3014
- if (bracketDepth === 0) {
3015
- if (currentCharacter === firstSeparatorCharacter && (isSeparatorSingleCharacter || className.slice(index, index + separatorLength) === separator)) {
3016
- modifiers.push(className.slice(modifierStart, index));
3017
- modifierStart = index + separatorLength;
3018
- continue;
3216
+ },
3217
+ "tsconfig.json": {
3218
+ file: {
3219
+ contents: tsconfigCode
3220
+ }
3221
+ },
3222
+ ".env": {
3223
+ file: {
3224
+ contents: createEnv(theme)
3225
+ }
3226
+ },
3227
+ "tailwind.config.mjs": {
3228
+ file: {
3229
+ contents: tailwindConfigCode
3230
+ }
3231
+ },
3232
+ ".vscode": {
3233
+ directory: {
3234
+ "settings.json": {
3235
+ file: {
3236
+ contents: settingsCode
3237
+ }
3238
+ },
3239
+ "extensions.json": {
3240
+ file: {
3241
+ contents: extensionsCode
3242
+ }
3243
+ },
3244
+ "launch.json": {
3245
+ file: {
3246
+ contents: launchCode
3247
+ }
3019
3248
  }
3020
- if (currentCharacter === "/") {
3021
- postfixModifierPosition = index;
3022
- continue;
3249
+ }
3250
+ },
3251
+ src: {
3252
+ directory: {
3253
+ layouts: {
3254
+ directory: {
3255
+ "Layout.astro": {
3256
+ file: {
3257
+ contents: layoutCode
3258
+ }
3259
+ }
3260
+ }
3261
+ },
3262
+ pages: {
3263
+ directory: {
3264
+ api: {
3265
+ directory: {
3266
+ "ask-for-quote.ts": {
3267
+ file: {
3268
+ contents: askForQuoteCode
3269
+ }
3270
+ }
3271
+ }
3272
+ }
3273
+ }
3274
+ },
3275
+ components: {
3276
+ directory: {}
3277
+ },
3278
+ lib: {
3279
+ directory: {
3280
+ "index.ts": {
3281
+ file: {
3282
+ contents: libCode
3283
+ }
3284
+ }
3285
+ }
3286
+ },
3287
+ "base.css": {
3288
+ file: {
3289
+ contents: createBaseCssCode(theme)
3290
+ }
3291
+ },
3292
+ "env.d.ts": {
3293
+ file: {
3294
+ contents: `/// <reference types="astro/client" />`
3295
+ }
3023
3296
  }
3024
3297
  }
3025
- if (currentCharacter === "[") {
3026
- bracketDepth++;
3027
- } else if (currentCharacter === "]") {
3028
- bracketDepth--;
3298
+ },
3299
+ public: {
3300
+ directory: {
3301
+ "favicon.svg": {
3302
+ file: {
3303
+ contents: faviconCode
3304
+ }
3305
+ }
3029
3306
  }
3030
3307
  }
3031
- const baseClassNameWithImportantModifier = modifiers.length === 0 ? className : className.substring(modifierStart);
3032
- const hasImportantModifier = baseClassNameWithImportantModifier.startsWith(IMPORTANT_MODIFIER);
3033
- const baseClassName = hasImportantModifier ? baseClassNameWithImportantModifier.substring(1) : baseClassNameWithImportantModifier;
3034
- const maybePostfixModifierPosition = postfixModifierPosition && postfixModifierPosition > modifierStart ? postfixModifierPosition - modifierStart : void 0;
3035
- return {
3036
- modifiers,
3037
- hasImportantModifier,
3038
- baseClassName,
3039
- maybePostfixModifierPosition
3040
- };
3041
3308
  };
3042
- if (experimentalParseClassName) {
3043
- return (className) => experimentalParseClassName({
3044
- className,
3045
- parseClassName
3046
- });
3047
- }
3048
- return parseClassName;
3049
3309
  };
3050
- const sortModifiers = (modifiers) => {
3051
- if (modifiers.length <= 1) {
3052
- return modifiers;
3053
- }
3054
- const sortedModifiers = [];
3055
- let unsortedModifiers = [];
3056
- modifiers.forEach((modifier) => {
3057
- const isArbitraryVariant = modifier[0] === "[";
3058
- if (isArbitraryVariant) {
3059
- sortedModifiers.push(...unsortedModifiers.sort(), modifier);
3060
- unsortedModifiers = [];
3061
- } else {
3062
- unsortedModifiers.push(modifier);
3063
- }
3064
- });
3065
- sortedModifiers.push(...unsortedModifiers.sort());
3066
- return sortedModifiers;
3310
+ const PAGE_TYPE_PATHS = {
3311
+ [PageType.Home]: "index.astro",
3312
+ [PageType.Page404]: "404.astro",
3313
+ [PageType.PageError]: "500.astro",
3314
+ [PageType.Thanks]: "thanks.astro",
3315
+ [PageType.SearchList]: "search.astro",
3316
+ [PageType.Post]: "posts/[slug].astro",
3317
+ [PageType.PostList]: "posts/page/[page].astro",
3318
+ [PageType.PostCategory]: "posts/categories/[slug]/[page].astro",
3319
+ [PageType.Product]: "products/[slug].astro",
3320
+ [PageType.ProductList]: "products/page/[page].astro",
3321
+ [PageType.ProductCategory]: "products/categories/[slug]/[page].astro",
3322
+ [PageType.Profile]: "profiles/[id].astro"
3323
+ // 其他页面类型可以根据需要添加
3067
3324
  };
3068
- const createConfigUtils = (config) => ({
3069
- cache: createLruCache(config.cacheSize),
3070
- parseClassName: createParseClassName(config),
3071
- ...createClassGroupUtils(config)
3325
+ const createFileEntry = (contents) => ({
3326
+ file: { contents }
3072
3327
  });
3073
- const SPLIT_CLASSES_REGEX = /\s+/;
3074
- const mergeClassList = (classList, configUtils) => {
3075
- const {
3076
- parseClassName,
3077
- getClassGroupId,
3078
- getConflictingClassGroupIds
3079
- } = configUtils;
3080
- const classGroupsInConflict = [];
3081
- const classNames = classList.trim().split(SPLIT_CLASSES_REGEX);
3082
- let result = "";
3083
- for (let index = classNames.length - 1; index >= 0; index -= 1) {
3084
- const originalClassName = classNames[index];
3085
- const {
3086
- modifiers,
3087
- hasImportantModifier,
3088
- baseClassName,
3089
- maybePostfixModifierPosition
3090
- } = parseClassName(originalClassName);
3091
- let hasPostfixModifier = Boolean(maybePostfixModifierPosition);
3092
- let classGroupId = getClassGroupId(hasPostfixModifier ? baseClassName.substring(0, maybePostfixModifierPosition) : baseClassName);
3093
- if (!classGroupId) {
3094
- if (!hasPostfixModifier) {
3095
- result = originalClassName + (result.length > 0 ? " " + result : result);
3096
- continue;
3097
- }
3098
- classGroupId = getClassGroupId(baseClassName);
3099
- if (!classGroupId) {
3100
- result = originalClassName + (result.length > 0 ? " " + result : result);
3101
- continue;
3328
+ const createDirectoryEntry = (content = {}) => ({
3329
+ directory: content
3330
+ });
3331
+ function useGetPageFiles() {
3332
+ const getPages = useGetPages();
3333
+ const getPageFiles = useCallback(
3334
+ async (themeId) => {
3335
+ var _a;
3336
+ const pages = (_a = await getPages(themeId)) == null ? void 0 : _a.items;
3337
+ const defaultHomeContent = `---
3338
+ import Layout from '../layouts/Layout.astro';
3339
+ ---
3340
+
3341
+ <Layout>
3342
+ <main class="p-4 max-w-screen-lg mx-auto">
3343
+ <h1 class="text-3xl font-bold mb-4">欢迎访问</h1>
3344
+ <p class="text-lg">没有找到首页...</p>
3345
+ </main>
3346
+ </Layout>
3347
+ `;
3348
+ const initialPageFiles = {
3349
+ "index.astro": createFileEntry(defaultHomeContent)
3350
+ };
3351
+ const createNestedDir = (basePath, structure) => {
3352
+ let current = structure;
3353
+ for (const segment of basePath) {
3354
+ if (!current[segment]) {
3355
+ current[segment] = createDirectoryEntry();
3356
+ }
3357
+ current = current[segment].directory;
3358
+ }
3359
+ return current;
3360
+ };
3361
+ const createFileAtPath = (path, content, structure) => {
3362
+ const segments = path.split("/");
3363
+ const fileName = segments.pop() || "";
3364
+ if (segments.length === 0) {
3365
+ structure[fileName] = createFileEntry(content);
3366
+ } else {
3367
+ const dirContent = createNestedDir(segments, structure);
3368
+ dirContent[fileName] = createFileEntry(content);
3369
+ }
3370
+ };
3371
+ createNestedDir(["posts"], initialPageFiles);
3372
+ createNestedDir(["posts", "categories"], initialPageFiles);
3373
+ createNestedDir(["posts", "page"], initialPageFiles);
3374
+ createNestedDir(["products"], initialPageFiles);
3375
+ createNestedDir(["products", "categories"], initialPageFiles);
3376
+ createNestedDir(["products", "page"], initialPageFiles);
3377
+ createNestedDir(["profiles"], initialPageFiles);
3378
+ createNestedDir(["api"], initialPageFiles);
3379
+ const processedPaths = /* @__PURE__ */ new Set();
3380
+ if (pages && pages.length > 0) {
3381
+ pages.forEach((page) => {
3382
+ const pageContent = page.code || "";
3383
+ const pageType = page.pageType;
3384
+ const path = PAGE_TYPE_PATHS[pageType];
3385
+ if (path) {
3386
+ createFileAtPath(path, pageContent, initialPageFiles);
3387
+ processedPaths.add(path);
3388
+ } else if (page.pageType === PageType.Customized && page.slug) {
3389
+ const fileName = `${page.slug}.astro`;
3390
+ initialPageFiles[fileName] = createFileEntry(pageContent);
3391
+ processedPaths.add(fileName);
3392
+ } else {
3393
+ const fileName = "page.astro";
3394
+ initialPageFiles[fileName] = createFileEntry(pageContent);
3395
+ processedPaths.add(fileName);
3396
+ }
3397
+ });
3102
3398
  }
3103
- hasPostfixModifier = false;
3104
- }
3105
- const variantModifier = sortModifiers(modifiers).join(":");
3106
- const modifierId = hasImportantModifier ? variantModifier + IMPORTANT_MODIFIER : variantModifier;
3107
- const classId = modifierId + classGroupId;
3108
- if (classGroupsInConflict.includes(classId)) {
3109
- continue;
3110
- }
3111
- classGroupsInConflict.push(classId);
3112
- const conflictGroups = getConflictingClassGroupIds(classGroupId, hasPostfixModifier);
3113
- for (let i2 = 0; i2 < conflictGroups.length; ++i2) {
3114
- const group = conflictGroups[i2];
3115
- classGroupsInConflict.push(modifierId + group);
3116
- }
3117
- result = originalClassName + (result.length > 0 ? " " + result : result);
3118
- }
3119
- return result;
3120
- };
3121
- function twJoin() {
3122
- let index = 0;
3123
- let argument;
3124
- let resolvedValue;
3125
- let string = "";
3126
- while (index < arguments.length) {
3127
- if (argument = arguments[index++]) {
3128
- if (resolvedValue = toValue(argument)) {
3129
- string && (string += " ");
3130
- string += resolvedValue;
3399
+ return initialPageFiles;
3400
+ },
3401
+ [getPages]
3402
+ );
3403
+ return getPageFiles;
3404
+ }
3405
+ function useGetComponentFiles() {
3406
+ const getComponents = useGetFrontComponents();
3407
+ const getFiles = useCallback(
3408
+ async (themeId) => {
3409
+ var _a;
3410
+ const components = (_a = await getComponents(themeId)) == null ? void 0 : _a.items;
3411
+ const files = {};
3412
+ if (components && components.length > 0) {
3413
+ components.forEach((component) => {
3414
+ if (component.name && component.code) {
3415
+ files[`${component.name}.astro`] = {
3416
+ file: {
3417
+ contents: component.code
3418
+ }
3419
+ };
3420
+ }
3421
+ });
3131
3422
  }
3132
- }
3133
- }
3134
- return string;
3423
+ return files;
3424
+ },
3425
+ [getComponents]
3426
+ );
3427
+ return getFiles;
3135
3428
  }
3136
- const toValue = (mix) => {
3137
- if (typeof mix === "string") {
3138
- return mix;
3139
- }
3140
- let resolvedValue;
3141
- let string = "";
3142
- for (let k = 0; k < mix.length; k++) {
3143
- if (mix[k]) {
3144
- if (resolvedValue = toValue(mix[k])) {
3145
- string && (string += " ");
3146
- string += resolvedValue;
3429
+ function useGetFiles() {
3430
+ const getPageFiles = useGetPageFiles();
3431
+ const getComponentFiles = useGetComponentFiles();
3432
+ const getFiles = useCallback(
3433
+ async (theme) => {
3434
+ if (!(theme == null ? void 0 : theme.id)) {
3435
+ console.error("theme is not defined");
3436
+ return;
3147
3437
  }
3148
- }
3149
- }
3150
- return string;
3151
- };
3152
- function createTailwindMerge(createConfigFirst, ...createConfigRest) {
3153
- let configUtils;
3438
+ const pageFiles = await getPageFiles((theme == null ? void 0 : theme.id) || void 0);
3439
+ const componentFiles = await getComponentFiles((theme == null ? void 0 : theme.id) || void 0);
3440
+ const baseFiles = createBaseFiles(theme);
3441
+ return {
3442
+ ...baseFiles,
3443
+ src: {
3444
+ ...baseFiles.src,
3445
+ directory: {
3446
+ ...baseFiles.src.directory,
3447
+ components: {
3448
+ ...baseFiles.src.directory.components,
3449
+ directory: {
3450
+ ...baseFiles.src.directory.components.directory,
3451
+ ...componentFiles
3452
+ }
3453
+ },
3454
+ pages: {
3455
+ ...baseFiles.src.directory.pages,
3456
+ directory: {
3457
+ ...baseFiles.src.directory.pages.directory,
3458
+ ...pageFiles
3459
+ }
3460
+ }
3461
+ }
3462
+ }
3463
+ };
3464
+ },
3465
+ [getComponentFiles, getPageFiles]
3466
+ );
3467
+ return getFiles;
3468
+ }
3469
+ function useSave(onSaved) {
3470
+ const save = useCallback(
3471
+ (name, content) => {
3472
+ saveFile(name, content).then(
3473
+ (savedName) => {
3474
+ if (savedName) {
3475
+ onSaved && onSaved();
3476
+ }
3477
+ }
3478
+ );
3479
+ },
3480
+ [onSaved]
3481
+ );
3482
+ return save;
3483
+ }
3484
+ var ContentType = /* @__PURE__ */ ((ContentType2) => {
3485
+ ContentType2["Page"] = "page";
3486
+ ContentType2["Component"] = "component";
3487
+ ContentType2["PredefinedPage"] = "PredefinedPage";
3488
+ return ContentType2;
3489
+ })(ContentType || {});
3490
+ var DrawerConentType = /* @__PURE__ */ ((DrawerConentType2) => {
3491
+ DrawerConentType2["Insert"] = "insert";
3492
+ DrawerConentType2["Layers"] = "layers";
3493
+ DrawerConentType2["SEO"] = "seo";
3494
+ DrawerConentType2["SEM"] = "sem";
3495
+ DrawerConentType2["SNS"] = "sns";
3496
+ DrawerConentType2["ComponentSchema"] = "componentSchema";
3497
+ DrawerConentType2["ComponentTest"] = "componentTest";
3498
+ return DrawerConentType2;
3499
+ })(DrawerConentType || {});
3500
+ var DeviceType = /* @__PURE__ */ ((DeviceType2) => {
3501
+ DeviceType2["Mobile"] = "mobile";
3502
+ DeviceType2["Tablet"] = "tablet";
3503
+ DeviceType2["Desktop"] = "desktop";
3504
+ return DeviceType2;
3505
+ })(DeviceType || {});
3506
+ var ViewMode = /* @__PURE__ */ ((ViewMode2) => {
3507
+ ViewMode2["Design"] = "design";
3508
+ ViewMode2["Preview"] = "preview";
3509
+ ViewMode2["Code"] = "code";
3510
+ return ViewMode2;
3511
+ })(ViewMode || {});
3512
+ const defaultSchema = {
3513
+ componentName: "Root"
3514
+ };
3515
+ const emptyValue = { schema: void 0, config: void 0 };
3516
+ function useSchema(selectedContent) {
3517
+ const [schema, setSchema] = useState(emptyValue);
3518
+ const components = useFrontComponents();
3519
+ const pages = usePages();
3520
+ const componentsRef = useRef(components);
3521
+ const pagesRef = useRef(pages);
3522
+ componentsRef.current = components;
3523
+ pagesRef.current = pages;
3524
+ useEffect(() => {
3525
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
3526
+ let code;
3527
+ let hasContent = false;
3528
+ let defaultConfig;
3529
+ if ((selectedContent == null ? void 0 : selectedContent.type) === ContentType.Component) {
3530
+ const component = (_a = componentsRef.current) == null ? void 0 : _a.find(
3531
+ (component2) => component2.id === selectedContent.id
3532
+ );
3533
+ if (component) {
3534
+ code = component.code;
3535
+ hasContent = true;
3536
+ }
3537
+ } else if ((selectedContent == null ? void 0 : selectedContent.type) === ContentType.PredefinedPage || (selectedContent == null ? void 0 : selectedContent.type) === ContentType.Page) {
3538
+ const page = (_c = (_b = pagesRef.current) == null ? void 0 : _b.items) == null ? void 0 : _c.find(
3539
+ (item) => item.id === selectedContent.id
3540
+ );
3541
+ defaultConfig = {
3542
+ pageMeta: {
3543
+ seoTitle: (_d = page == null ? void 0 : page.meta) == null ? void 0 : _d.seoTitle,
3544
+ seoDescription: (_e = page == null ? void 0 : page.meta) == null ? void 0 : _e.seoDescription,
3545
+ seoKeywords: (_f = page == null ? void 0 : page.meta) == null ? void 0 : _f.seoKeywords,
3546
+ ogTitle: (_g = page == null ? void 0 : page.meta) == null ? void 0 : _g.ogTitle,
3547
+ ogDescription: (_h = page == null ? void 0 : page.meta) == null ? void 0 : _h.ogDescription,
3548
+ ogType: (_i = page == null ? void 0 : page.meta) == null ? void 0 : _i.ogType,
3549
+ ogImage: (_j = page == null ? void 0 : page.meta) == null ? void 0 : _j.ogImage
3550
+ }
3551
+ };
3552
+ if (page) {
3553
+ code = page.code;
3554
+ hasContent = true;
3555
+ }
3556
+ }
3557
+ if (code) {
3558
+ transformCodeToSchema(code).then((value) => {
3559
+ setSchema({
3560
+ schema: { ...defaultSchema, children: (value == null ? void 0 : value.template) || [] },
3561
+ config: { ...defaultConfig, ...value.resources }
3562
+ });
3563
+ });
3564
+ } else if (hasContent) {
3565
+ setSchema({
3566
+ schema: { ...defaultSchema, children: [] }
3567
+ });
3568
+ }
3569
+ }, [selectedContent == null ? void 0 : selectedContent.id, selectedContent == null ? void 0 : selectedContent.type]);
3570
+ return schema;
3571
+ }
3572
+ function useExportWebsite() {
3573
+ const [isExporting, setIsExporting] = useState(false);
3574
+ const setError = useSetRecoilState(globalErrorState);
3575
+ const theme = useWebsiteTheme();
3576
+ const save = useSave();
3577
+ const getFiles = useGetFiles();
3578
+ const addFilesToZip = useCallback(
3579
+ (zip, files, currentPath = "") => {
3580
+ for (const [name, content] of Object.entries(files)) {
3581
+ const path = currentPath ? `${currentPath}/${name}` : name;
3582
+ if (content.file && content.file.contents) {
3583
+ zip.file(path, content.file.contents);
3584
+ } else if (content.directory) {
3585
+ const folder = zip.folder(path);
3586
+ if (folder) {
3587
+ addFilesToZip(folder, content.directory, "");
3588
+ }
3589
+ } else if (typeof content === "object" && content !== null) {
3590
+ if (name === "src" || name === "public" || name === "components" || name === "pages") {
3591
+ const folder = zip.folder(path);
3592
+ if (folder) {
3593
+ addFilesToZip(folder, content, "");
3594
+ }
3595
+ } else {
3596
+ addFilesToZip(zip, content, path);
3597
+ }
3598
+ }
3599
+ }
3600
+ },
3601
+ []
3602
+ );
3603
+ const exportWebsite = useCallback(async () => {
3604
+ try {
3605
+ if (theme == null ? void 0 : theme.id) {
3606
+ setIsExporting(true);
3607
+ const files = await getFiles(theme);
3608
+ const zip = new JSZip();
3609
+ console.log("开始导出文件...");
3610
+ addFilesToZip(zip, files);
3611
+ const content = await zip.generateAsync({ type: "blob" });
3612
+ const fileName = `website-${theme.name || theme.id}-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}`;
3613
+ save(fileName, content);
3614
+ }
3615
+ } catch (e) {
3616
+ console.error(e);
3617
+ setError(e == null ? void 0 : e.message);
3618
+ } finally {
3619
+ setIsExporting(false);
3620
+ }
3621
+ }, [getFiles, save, setError, theme, addFilesToZip]);
3622
+ return { exportWebsite, isExporting };
3623
+ }
3624
+ const studioSetters = {
3625
+ ...propSetters,
3626
+ Fragment: React__default.Fragment
3627
+ // TabList,
3628
+ // Tab,
3629
+ // TabPanel,
3630
+ // Stack,
3631
+ // FormControl,
3632
+ // FormLabel: FormLabel,
3633
+ // Autocomplete: Autocomplete,
3634
+ // Input: toControlled(Input, 'value', ''),
3635
+ // Textarea: toControlled(Textarea, 'value', ''),
3636
+ //Select,
3637
+ //Option: Option,
3638
+ //Switch: Switch,
3639
+ //IconPicker,
3640
+ //ToggleButtonGroup,
3641
+ // Button,
3642
+ // IconButton,
3643
+ // SlotSwitch,
3644
+ };
3645
+ function useAllMaterials() {
3646
+ const customMaterials = useCustomizedMaterials();
3647
+ const materials = useMemo(() => {
3648
+ return staticMaterials.concat(customMaterials || []);
3649
+ }, [customMaterials]);
3650
+ return materials;
3651
+ }
3652
+ function EditorScope(props) {
3653
+ const { children, resources, ...rest } = props;
3654
+ const materials = useAllMaterials();
3655
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
3656
+ Designer,
3657
+ {
3658
+ resources,
3659
+ materials,
3660
+ setters: studioSetters,
3661
+ ...rest,
3662
+ children
3663
+ }
3664
+ );
3665
+ }
3666
+ const Sheet = forwardRef$1((props, ref) => {
3667
+ const { className, children, ...rest } = props;
3668
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(
3669
+ "div",
3670
+ {
3671
+ ref,
3672
+ className: cn(className, "border-divider bg-black"),
3673
+ ...rest,
3674
+ children
3675
+ }
3676
+ );
3677
+ });
3678
+ var solid = {
3679
+ default: "bg-default text-default-foreground",
3680
+ primary: "bg-primary text-primary-foreground",
3681
+ secondary: "bg-secondary text-secondary-foreground",
3682
+ success: "bg-success text-success-foreground",
3683
+ warning: "bg-warning text-warning-foreground",
3684
+ danger: "bg-danger text-danger-foreground",
3685
+ foreground: "bg-foreground text-background"
3686
+ };
3687
+ var shadow = {
3688
+ default: "shadow-lg shadow-default/50 bg-default text-default-foreground",
3689
+ primary: "shadow-lg shadow-primary/40 bg-primary text-primary-foreground",
3690
+ secondary: "shadow-lg shadow-secondary/40 bg-secondary text-secondary-foreground",
3691
+ success: "shadow-lg shadow-success/40 bg-success text-success-foreground",
3692
+ warning: "shadow-lg shadow-warning/40 bg-warning text-warning-foreground",
3693
+ danger: "shadow-lg shadow-danger/40 bg-danger text-danger-foreground",
3694
+ foreground: "shadow-lg shadow-foreground/40 bg-foreground text-background"
3695
+ };
3696
+ var bordered = {
3697
+ default: "bg-transparent border-default text-foreground",
3698
+ primary: "bg-transparent border-primary text-primary",
3699
+ secondary: "bg-transparent border-secondary text-secondary",
3700
+ success: "bg-transparent border-success text-success",
3701
+ warning: "bg-transparent border-warning text-warning",
3702
+ danger: "bg-transparent border-danger text-danger",
3703
+ foreground: "bg-transparent border-foreground text-foreground"
3704
+ };
3705
+ var flat = {
3706
+ default: "bg-default/40 text-default-700",
3707
+ primary: "bg-primary/20 text-primary-600",
3708
+ secondary: "bg-secondary/20 text-secondary-600",
3709
+ success: "bg-success/20 text-success-700 dark:text-success",
3710
+ warning: "bg-warning/20 text-warning-700 dark:text-warning",
3711
+ danger: "bg-danger/20 text-danger-600 dark:text-danger-500",
3712
+ foreground: "bg-foreground/10 text-foreground"
3713
+ };
3714
+ var faded = {
3715
+ default: "border-default bg-default-100 text-default-foreground",
3716
+ primary: "border-default bg-default-100 text-primary",
3717
+ secondary: "border-default bg-default-100 text-secondary",
3718
+ success: "border-default bg-default-100 text-success",
3719
+ warning: "border-default bg-default-100 text-warning",
3720
+ danger: "border-default bg-default-100 text-danger",
3721
+ foreground: "border-default bg-default-100 text-foreground"
3722
+ };
3723
+ var light = {
3724
+ default: "bg-transparent text-default-foreground",
3725
+ primary: "bg-transparent text-primary",
3726
+ secondary: "bg-transparent text-secondary",
3727
+ success: "bg-transparent text-success",
3728
+ warning: "bg-transparent text-warning",
3729
+ danger: "bg-transparent text-danger",
3730
+ foreground: "bg-transparent text-foreground"
3731
+ };
3732
+ var ghost = {
3733
+ default: "border-default text-default-foreground",
3734
+ primary: "border-primary text-primary",
3735
+ secondary: "border-secondary text-secondary",
3736
+ success: "border-success text-success",
3737
+ warning: "border-warning text-warning",
3738
+ danger: "border-danger text-danger",
3739
+ foreground: "border-foreground text-foreground hover:!bg-foreground"
3740
+ };
3741
+ var colorVariants = {
3742
+ solid,
3743
+ shadow,
3744
+ bordered,
3745
+ flat,
3746
+ faded,
3747
+ light,
3748
+ ghost
3749
+ };
3750
+ var COMMON_UNITS = ["small", "medium", "large"];
3751
+ var twMergeConfig = {
3752
+ theme: {
3753
+ opacity: ["disabled"],
3754
+ spacing: ["divider"],
3755
+ borderWidth: COMMON_UNITS,
3756
+ borderRadius: COMMON_UNITS
3757
+ },
3758
+ classGroups: {
3759
+ shadow: [{ shadow: COMMON_UNITS }],
3760
+ "font-size": [{ text: ["tiny", ...COMMON_UNITS] }],
3761
+ "bg-image": [
3762
+ "bg-stripe-gradient-default",
3763
+ "bg-stripe-gradient-primary",
3764
+ "bg-stripe-gradient-secondary",
3765
+ "bg-stripe-gradient-success",
3766
+ "bg-stripe-gradient-warning",
3767
+ "bg-stripe-gradient-danger"
3768
+ ]
3769
+ }
3770
+ };
3771
+ var l = (e) => typeof e == "boolean" ? `${e}` : e === 0 ? "0" : e, u = (e) => !e || typeof e != "object" || Object.keys(e).length === 0, x$1 = (e, o) => JSON.stringify(e) === JSON.stringify(o);
3772
+ function i(e, o) {
3773
+ e.forEach(function(r2) {
3774
+ Array.isArray(r2) ? i(r2, o) : o.push(r2);
3775
+ });
3776
+ }
3777
+ function y(e) {
3778
+ let o = [];
3779
+ return i(e, o), o;
3780
+ }
3781
+ var a = (...e) => y(e).filter(Boolean), p = (e, o) => {
3782
+ let r2 = {}, c = Object.keys(e), f = Object.keys(o);
3783
+ for (let t of c)
3784
+ if (f.includes(t)) {
3785
+ let s = e[t], n = o[t];
3786
+ Array.isArray(s) || Array.isArray(n) ? r2[t] = a(n, s) : typeof s == "object" && typeof n == "object" ? r2[t] = p(s, n) : r2[t] = n + " " + s;
3787
+ } else
3788
+ r2[t] = e[t];
3789
+ for (let t of f)
3790
+ c.includes(t) || (r2[t] = o[t]);
3791
+ return r2;
3792
+ }, g = (e) => !e || typeof e != "string" ? e : e.replace(/\s+/g, " ").trim();
3793
+ const CLASS_PART_SEPARATOR = "-";
3794
+ const createClassGroupUtils = (config) => {
3795
+ const classMap = createClassMap(config);
3796
+ const {
3797
+ conflictingClassGroups,
3798
+ conflictingClassGroupModifiers
3799
+ } = config;
3800
+ const getClassGroupId = (className) => {
3801
+ const classParts = className.split(CLASS_PART_SEPARATOR);
3802
+ if (classParts[0] === "" && classParts.length !== 1) {
3803
+ classParts.shift();
3804
+ }
3805
+ return getGroupRecursive(classParts, classMap) || getGroupIdForArbitraryProperty(className);
3806
+ };
3807
+ const getConflictingClassGroupIds = (classGroupId, hasPostfixModifier) => {
3808
+ const conflicts = conflictingClassGroups[classGroupId] || [];
3809
+ if (hasPostfixModifier && conflictingClassGroupModifiers[classGroupId]) {
3810
+ return [...conflicts, ...conflictingClassGroupModifiers[classGroupId]];
3811
+ }
3812
+ return conflicts;
3813
+ };
3814
+ return {
3815
+ getClassGroupId,
3816
+ getConflictingClassGroupIds
3817
+ };
3818
+ };
3819
+ const getGroupRecursive = (classParts, classPartObject) => {
3820
+ var _a;
3821
+ if (classParts.length === 0) {
3822
+ return classPartObject.classGroupId;
3823
+ }
3824
+ const currentClassPart = classParts[0];
3825
+ const nextClassPartObject = classPartObject.nextPart.get(currentClassPart);
3826
+ const classGroupFromNextClassPart = nextClassPartObject ? getGroupRecursive(classParts.slice(1), nextClassPartObject) : void 0;
3827
+ if (classGroupFromNextClassPart) {
3828
+ return classGroupFromNextClassPart;
3829
+ }
3830
+ if (classPartObject.validators.length === 0) {
3831
+ return void 0;
3832
+ }
3833
+ const classRest = classParts.join(CLASS_PART_SEPARATOR);
3834
+ return (_a = classPartObject.validators.find(({
3835
+ validator
3836
+ }) => validator(classRest))) == null ? void 0 : _a.classGroupId;
3837
+ };
3838
+ const arbitraryPropertyRegex = /^\[(.+)\]$/;
3839
+ const getGroupIdForArbitraryProperty = (className) => {
3840
+ if (arbitraryPropertyRegex.test(className)) {
3841
+ const arbitraryPropertyClassName = arbitraryPropertyRegex.exec(className)[1];
3842
+ const property = arbitraryPropertyClassName == null ? void 0 : arbitraryPropertyClassName.substring(0, arbitraryPropertyClassName.indexOf(":"));
3843
+ if (property) {
3844
+ return "arbitrary.." + property;
3845
+ }
3846
+ }
3847
+ };
3848
+ const createClassMap = (config) => {
3849
+ const {
3850
+ theme,
3851
+ prefix
3852
+ } = config;
3853
+ const classMap = {
3854
+ nextPart: /* @__PURE__ */ new Map(),
3855
+ validators: []
3856
+ };
3857
+ const prefixedClassGroupEntries = getPrefixedClassGroupEntries(Object.entries(config.classGroups), prefix);
3858
+ prefixedClassGroupEntries.forEach(([classGroupId, classGroup]) => {
3859
+ processClassesRecursively(classGroup, classMap, classGroupId, theme);
3860
+ });
3861
+ return classMap;
3862
+ };
3863
+ const processClassesRecursively = (classGroup, classPartObject, classGroupId, theme) => {
3864
+ classGroup.forEach((classDefinition) => {
3865
+ if (typeof classDefinition === "string") {
3866
+ const classPartObjectToEdit = classDefinition === "" ? classPartObject : getPart(classPartObject, classDefinition);
3867
+ classPartObjectToEdit.classGroupId = classGroupId;
3868
+ return;
3869
+ }
3870
+ if (typeof classDefinition === "function") {
3871
+ if (isThemeGetter(classDefinition)) {
3872
+ processClassesRecursively(classDefinition(theme), classPartObject, classGroupId, theme);
3873
+ return;
3874
+ }
3875
+ classPartObject.validators.push({
3876
+ validator: classDefinition,
3877
+ classGroupId
3878
+ });
3879
+ return;
3880
+ }
3881
+ Object.entries(classDefinition).forEach(([key, classGroup2]) => {
3882
+ processClassesRecursively(classGroup2, getPart(classPartObject, key), classGroupId, theme);
3883
+ });
3884
+ });
3885
+ };
3886
+ const getPart = (classPartObject, path) => {
3887
+ let currentClassPartObject = classPartObject;
3888
+ path.split(CLASS_PART_SEPARATOR).forEach((pathPart) => {
3889
+ if (!currentClassPartObject.nextPart.has(pathPart)) {
3890
+ currentClassPartObject.nextPart.set(pathPart, {
3891
+ nextPart: /* @__PURE__ */ new Map(),
3892
+ validators: []
3893
+ });
3894
+ }
3895
+ currentClassPartObject = currentClassPartObject.nextPart.get(pathPart);
3896
+ });
3897
+ return currentClassPartObject;
3898
+ };
3899
+ const isThemeGetter = (func) => func.isThemeGetter;
3900
+ const getPrefixedClassGroupEntries = (classGroupEntries, prefix) => {
3901
+ if (!prefix) {
3902
+ return classGroupEntries;
3903
+ }
3904
+ return classGroupEntries.map(([classGroupId, classGroup]) => {
3905
+ const prefixedClassGroup = classGroup.map((classDefinition) => {
3906
+ if (typeof classDefinition === "string") {
3907
+ return prefix + classDefinition;
3908
+ }
3909
+ if (typeof classDefinition === "object") {
3910
+ return Object.fromEntries(Object.entries(classDefinition).map(([key, value]) => [prefix + key, value]));
3911
+ }
3912
+ return classDefinition;
3913
+ });
3914
+ return [classGroupId, prefixedClassGroup];
3915
+ });
3916
+ };
3917
+ const createLruCache = (maxCacheSize) => {
3918
+ if (maxCacheSize < 1) {
3919
+ return {
3920
+ get: () => void 0,
3921
+ set: () => {
3922
+ }
3923
+ };
3924
+ }
3925
+ let cacheSize = 0;
3926
+ let cache = /* @__PURE__ */ new Map();
3927
+ let previousCache = /* @__PURE__ */ new Map();
3928
+ const update = (key, value) => {
3929
+ cache.set(key, value);
3930
+ cacheSize++;
3931
+ if (cacheSize > maxCacheSize) {
3932
+ cacheSize = 0;
3933
+ previousCache = cache;
3934
+ cache = /* @__PURE__ */ new Map();
3935
+ }
3936
+ };
3937
+ return {
3938
+ get(key) {
3939
+ let value = cache.get(key);
3940
+ if (value !== void 0) {
3941
+ return value;
3942
+ }
3943
+ if ((value = previousCache.get(key)) !== void 0) {
3944
+ update(key, value);
3945
+ return value;
3946
+ }
3947
+ },
3948
+ set(key, value) {
3949
+ if (cache.has(key)) {
3950
+ cache.set(key, value);
3951
+ } else {
3952
+ update(key, value);
3953
+ }
3954
+ }
3955
+ };
3956
+ };
3957
+ const IMPORTANT_MODIFIER = "!";
3958
+ const createParseClassName = (config) => {
3959
+ const {
3960
+ separator,
3961
+ experimentalParseClassName
3962
+ } = config;
3963
+ const isSeparatorSingleCharacter = separator.length === 1;
3964
+ const firstSeparatorCharacter = separator[0];
3965
+ const separatorLength = separator.length;
3966
+ const parseClassName = (className) => {
3967
+ const modifiers = [];
3968
+ let bracketDepth = 0;
3969
+ let modifierStart = 0;
3970
+ let postfixModifierPosition;
3971
+ for (let index = 0; index < className.length; index++) {
3972
+ let currentCharacter = className[index];
3973
+ if (bracketDepth === 0) {
3974
+ if (currentCharacter === firstSeparatorCharacter && (isSeparatorSingleCharacter || className.slice(index, index + separatorLength) === separator)) {
3975
+ modifiers.push(className.slice(modifierStart, index));
3976
+ modifierStart = index + separatorLength;
3977
+ continue;
3978
+ }
3979
+ if (currentCharacter === "/") {
3980
+ postfixModifierPosition = index;
3981
+ continue;
3982
+ }
3983
+ }
3984
+ if (currentCharacter === "[") {
3985
+ bracketDepth++;
3986
+ } else if (currentCharacter === "]") {
3987
+ bracketDepth--;
3988
+ }
3989
+ }
3990
+ const baseClassNameWithImportantModifier = modifiers.length === 0 ? className : className.substring(modifierStart);
3991
+ const hasImportantModifier = baseClassNameWithImportantModifier.startsWith(IMPORTANT_MODIFIER);
3992
+ const baseClassName = hasImportantModifier ? baseClassNameWithImportantModifier.substring(1) : baseClassNameWithImportantModifier;
3993
+ const maybePostfixModifierPosition = postfixModifierPosition && postfixModifierPosition > modifierStart ? postfixModifierPosition - modifierStart : void 0;
3994
+ return {
3995
+ modifiers,
3996
+ hasImportantModifier,
3997
+ baseClassName,
3998
+ maybePostfixModifierPosition
3999
+ };
4000
+ };
4001
+ if (experimentalParseClassName) {
4002
+ return (className) => experimentalParseClassName({
4003
+ className,
4004
+ parseClassName
4005
+ });
4006
+ }
4007
+ return parseClassName;
4008
+ };
4009
+ const sortModifiers = (modifiers) => {
4010
+ if (modifiers.length <= 1) {
4011
+ return modifiers;
4012
+ }
4013
+ const sortedModifiers = [];
4014
+ let unsortedModifiers = [];
4015
+ modifiers.forEach((modifier) => {
4016
+ const isArbitraryVariant = modifier[0] === "[";
4017
+ if (isArbitraryVariant) {
4018
+ sortedModifiers.push(...unsortedModifiers.sort(), modifier);
4019
+ unsortedModifiers = [];
4020
+ } else {
4021
+ unsortedModifiers.push(modifier);
4022
+ }
4023
+ });
4024
+ sortedModifiers.push(...unsortedModifiers.sort());
4025
+ return sortedModifiers;
4026
+ };
4027
+ const createConfigUtils = (config) => ({
4028
+ cache: createLruCache(config.cacheSize),
4029
+ parseClassName: createParseClassName(config),
4030
+ ...createClassGroupUtils(config)
4031
+ });
4032
+ const SPLIT_CLASSES_REGEX = /\s+/;
4033
+ const mergeClassList = (classList, configUtils) => {
4034
+ const {
4035
+ parseClassName,
4036
+ getClassGroupId,
4037
+ getConflictingClassGroupIds
4038
+ } = configUtils;
4039
+ const classGroupsInConflict = [];
4040
+ const classNames = classList.trim().split(SPLIT_CLASSES_REGEX);
4041
+ let result = "";
4042
+ for (let index = classNames.length - 1; index >= 0; index -= 1) {
4043
+ const originalClassName = classNames[index];
4044
+ const {
4045
+ modifiers,
4046
+ hasImportantModifier,
4047
+ baseClassName,
4048
+ maybePostfixModifierPosition
4049
+ } = parseClassName(originalClassName);
4050
+ let hasPostfixModifier = Boolean(maybePostfixModifierPosition);
4051
+ let classGroupId = getClassGroupId(hasPostfixModifier ? baseClassName.substring(0, maybePostfixModifierPosition) : baseClassName);
4052
+ if (!classGroupId) {
4053
+ if (!hasPostfixModifier) {
4054
+ result = originalClassName + (result.length > 0 ? " " + result : result);
4055
+ continue;
4056
+ }
4057
+ classGroupId = getClassGroupId(baseClassName);
4058
+ if (!classGroupId) {
4059
+ result = originalClassName + (result.length > 0 ? " " + result : result);
4060
+ continue;
4061
+ }
4062
+ hasPostfixModifier = false;
4063
+ }
4064
+ const variantModifier = sortModifiers(modifiers).join(":");
4065
+ const modifierId = hasImportantModifier ? variantModifier + IMPORTANT_MODIFIER : variantModifier;
4066
+ const classId = modifierId + classGroupId;
4067
+ if (classGroupsInConflict.includes(classId)) {
4068
+ continue;
4069
+ }
4070
+ classGroupsInConflict.push(classId);
4071
+ const conflictGroups = getConflictingClassGroupIds(classGroupId, hasPostfixModifier);
4072
+ for (let i2 = 0; i2 < conflictGroups.length; ++i2) {
4073
+ const group = conflictGroups[i2];
4074
+ classGroupsInConflict.push(modifierId + group);
4075
+ }
4076
+ result = originalClassName + (result.length > 0 ? " " + result : result);
4077
+ }
4078
+ return result;
4079
+ };
4080
+ function twJoin() {
4081
+ let index = 0;
4082
+ let argument;
4083
+ let resolvedValue;
4084
+ let string = "";
4085
+ while (index < arguments.length) {
4086
+ if (argument = arguments[index++]) {
4087
+ if (resolvedValue = toValue(argument)) {
4088
+ string && (string += " ");
4089
+ string += resolvedValue;
4090
+ }
4091
+ }
4092
+ }
4093
+ return string;
4094
+ }
4095
+ const toValue = (mix) => {
4096
+ if (typeof mix === "string") {
4097
+ return mix;
4098
+ }
4099
+ let resolvedValue;
4100
+ let string = "";
4101
+ for (let k = 0; k < mix.length; k++) {
4102
+ if (mix[k]) {
4103
+ if (resolvedValue = toValue(mix[k])) {
4104
+ string && (string += " ");
4105
+ string += resolvedValue;
4106
+ }
4107
+ }
4108
+ }
4109
+ return string;
4110
+ };
4111
+ function createTailwindMerge(createConfigFirst, ...createConfigRest) {
4112
+ let configUtils;
3154
4113
  let cacheGet;
3155
4114
  let cacheSet;
3156
4115
  let functionToCall = initTailwindMerge;
@@ -13938,502 +14897,55 @@ function PredefinedPages(props) {
13938
14897
  icon: null,
13939
14898
  classNames: {
13940
14899
  title: "text-sm font-semibold"
13941
- },
13942
- defaultExpanded: (selectedContent == null ? void 0 : selectedContent.type) === ContentType.PredefinedPage,
13943
- children: predefinedTypes.map((item) => /* @__PURE__ */ jsxRuntimeExports.jsx(
13944
- PredefinedPageNode,
13945
- {
13946
- themeId,
13947
- title: item.title,
13948
- selectedContent,
13949
- onSelect: handleSelect,
13950
- pageType: item.pageType
13951
- },
13952
- item.pageType
13953
- ))
13954
- }
13955
- );
13956
- }
13957
- const MenuContent = memo(
13958
- (props) => {
13959
- const { selectedContent, onSelectContent } = props;
13960
- const theme = useWebsiteTheme();
13961
- const pages = usePages();
13962
- const customizedPages = useMemo(() => {
13963
- var _a;
13964
- return {
13965
- items: (_a = pages == null ? void 0 : pages.items) == null ? void 0 : _a.filter(
13966
- (item) => item.pageType === PageType.Customized
13967
- )
13968
- };
13969
- }, [pages == null ? void 0 : pages.items]);
13970
- return /* @__PURE__ */ jsxRuntimeExports.jsxs(TreeView, { children: [
13971
- (theme == null ? void 0 : theme.id) && /* @__PURE__ */ jsxRuntimeExports.jsx(EntityListScope, { entityName: PageEntityName, data: customizedPages, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
13972
- PagesNode,
13973
- {
13974
- themeId: theme.id,
13975
- selectedContent,
13976
- onSelectContent
13977
- }
13978
- ) }),
13979
- (theme == null ? void 0 : theme.id) && /* @__PURE__ */ jsxRuntimeExports.jsx(
13980
- PredefinedPages,
13981
- {
13982
- themeId: theme.id,
13983
- selectedContent,
13984
- onSelectContent
13985
- }
13986
- )
13987
- ] });
13988
- }
13989
- );
13990
- function useGetFrontComponents() {
13991
- const query = useLazyQueryEntityList();
13992
- const getFrontCompoents = useCallback(
13993
- async (themeId) => {
13994
- return await query(
13995
- new FrontComponentQueryOptions(
13996
- [
13997
- FrontComponentFields.id,
13998
- FrontComponentFields.name,
13999
- FrontComponentFields.title,
14000
- FrontComponentFields.seqValue,
14001
- FrontComponentFields.updatedAt,
14002
- FrontComponentFields.code,
14003
- FrontComponentFields.testConfig,
14004
- FrontComponentFields.props,
14005
- FrontComponentFields.slots,
14006
- FrontComponentFields.droppable
14007
- ],
14008
- {
14009
- where: {
14010
- theme: {
14011
- id: {
14012
- _eq: themeId
14013
- }
14014
- }
14015
- },
14016
- orderBy: [
14017
- {
14018
- [FrontComponentFields.seqValue]: "asc"
14019
- },
14020
- {
14021
- [FrontComponentFields.createdAt]: "asc"
14022
- }
14023
- ]
14024
- }
14025
- ).category([ComponentCategoryFields.id, ComponentCategoryFields.name]).theme().setNoQuery(!themeId).toGqlOptions()
14026
- );
14027
- },
14028
- [query]
14029
- );
14030
- return getFrontCompoents;
14031
- }
14032
- function useGetPages() {
14033
- const query = useLazyQueryEntityList();
14034
- const getPages = useCallback(
14035
- async (themeId) => {
14036
- return await query(
14037
- new PageQueryOptions(
14038
- [
14039
- PageFields.id,
14040
- PageFields.title,
14041
- PageFields.createdAt,
14042
- PageFields.updatedAt,
14043
- PageFields.slug,
14044
- PageFields.code,
14045
- PageFields.pageType,
14046
- PageFields.dataSource
14047
- ],
14048
- {
14049
- where: {
14050
- [PageAssciations.theme]: {
14051
- id: { _eq: themeId }
14052
- }
14053
- },
14054
- orderBy: [
14055
- {
14056
- createdAt: "desc"
14057
- }
14058
- ]
14059
- }
14060
- ).meta(newPageMetaOptions()).setNoQuery(!themeId).toGqlOptions()
14061
- );
14062
- },
14063
- [query]
14064
- );
14065
- return getPages;
14066
- }
14067
- const baseFiles = {
14068
- "package.json": {
14069
- file: {
14070
- contents: `{
14071
- "name": "astro-project",
14072
- "type": "module",
14073
- "version": "0.0.1",
14074
- "scripts": {
14075
- "dev": "astro dev",
14076
- "start": "astro dev",
14077
- "build": "astro build",
14078
- "preview": "astro preview",
14079
- "astro": "astro"
14080
- },
14081
- "dependencies": {
14082
- "@astrojs/react": "^4.2.0",
14083
- "@rxdrag/website-lib": "^0.0.9",
14084
- "@rxdrag/website-lib-core": "^0.0.7",
14085
- "@rxdrag/slate-preview": "^1.2.54",
14086
- "astro": "^5.3.0",
14087
- "dayjs": "^1.11.7",
14088
- "gsap": "^3.12.7",
14089
- "react": "^18.2.0",
14090
- "react-dom": "^18.2.0"
14091
- }
14092
- }`
14093
- }
14094
- },
14095
- "astro.config.mjs": {
14096
- file: {
14097
- contents: `import { defineConfig } from 'astro/config';
14098
- import react from '@astrojs/react';
14099
-
14100
- // https://astro.build/config
14101
- export default defineConfig({
14102
- integrations: [react()],
14103
- server: {
14104
- host: true
14105
- },
14106
- devToolbar: {
14107
- enabled: false // 禁用开发工具栏
14108
- }
14109
- });`
14110
- }
14111
- },
14112
- "tsconfig.json": {
14113
- file: {
14114
- contents: `{
14115
- "extends": "astro/tsconfigs/strict",
14116
- "compilerOptions": {
14117
- "jsx": "react-jsx",
14118
- "jsxImportSource": "react"
14119
- }
14120
- }`
14121
- }
14122
- },
14123
- src: {
14124
- directory: {
14125
- layouts: {
14126
- directory: {
14127
- "Layout.astro": {
14128
- file: {
14129
- contents: `---
14130
- ---
14131
-
14132
- <!DOCTYPE html>
14133
- <html lang="en">
14134
- <head>
14135
- <meta charset="UTF-8" />
14136
- <meta name="description" content="Astro description">
14137
- <meta name="viewport" content="width=device-width" />
14138
- <link rel="icon" type="image/svg+xml" href="/favicon.svg" />
14139
- <meta name="generator" content={Astro.generator} />
14140
- </head>
14141
- <body>
14142
- <slot />
14143
- </body>
14144
- </html>
14145
- `
14146
- }
14147
- }
14148
- }
14149
- },
14150
- pages: {
14151
- directory: {}
14152
- },
14153
- components: {
14154
- directory: {}
14155
- },
14156
- lib: {
14157
- directory: {
14158
- "index.ts": {
14159
- file: {
14160
- contents: `import {
14161
- Entify,
14162
- type EnvVariables,
14163
- type IEntify,
14164
- } from "@rxdrag/website-lib-core";
14165
-
14166
- export function getEnvVariables(): EnvVariables {
14167
- return {
14168
- websiteId: ({}).PUBLIC_WEBSITE_ID,
14169
- entifyServerUrl: ({}).PUBLIC_ENTIFY_SERVER_URL,
14170
- entifyGuestToken: ({}).PUBLIC_ENTIFY_GUEST_TOKEN,
14171
- language: ({}).PUBLIC_LANGUAGE,
14172
- formSalt: ({}).PUBLIC_FORM_SALT || "yizhanfei",
14173
- };
14174
- }
14175
-
14176
- export const rx = Entify.getInstance(getEnvVariables()) as IEntify;
14177
- `
14178
- }
14179
- }
14180
- }
14181
- },
14182
- "env.d.ts": {
14183
- file: {
14184
- contents: `/// <reference types="astro/client" />`
14185
- }
14186
- }
14187
- }
14188
- },
14189
- public: {
14190
- directory: {
14191
- "favicon.svg": {
14192
- file: {
14193
- contents: `<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 36 36">
14194
- <path fill="#000" d="M22.25 4h-8.5a1 1 0 0 0-.96.73l-5.54 19.4a.5.5 0 0 0 .62.62l5.05-1.44a2 2 0 0 0 1.38-1.4l3.22-11.66a.5.5 0 0 1 .96 0l3.22 11.67a2 2 0 0 0 1.38 1.39l5.05 1.44a.5.5 0 0 0 .62-.62l-5.54-19.4a1 1 0 0 0-.96-.73Z"/>
14195
- <path fill="url(#gradient)" d="M18 28a7.63 7.63 0 0 1-3-.61v.61a3 3 0 0 0 6 0v-.61c-.94.4-1.95.61-3 .61Z"/>
14196
- <defs>
14197
- <linearGradient id="gradient" x1="18" x2="18" y1="28" y2="31" gradientUnits="userSpaceOnUse">
14198
- <stop stop-color="#FF1639"/>
14199
- <stop offset="1" stop-color="#FF1639" stop-opacity="0"/>
14200
- </linearGradient>
14201
- </defs>
14202
- </svg>`
14203
- }
14204
- }
14900
+ },
14901
+ defaultExpanded: (selectedContent == null ? void 0 : selectedContent.type) === ContentType.PredefinedPage,
14902
+ children: predefinedTypes.map((item) => /* @__PURE__ */ jsxRuntimeExports.jsx(
14903
+ PredefinedPageNode,
14904
+ {
14905
+ themeId,
14906
+ title: item.title,
14907
+ selectedContent,
14908
+ onSelect: handleSelect,
14909
+ pageType: item.pageType
14910
+ },
14911
+ item.pageType
14912
+ ))
14205
14913
  }
14206
- }
14207
- };
14208
- function useGetPageFiles() {
14209
- const getPages = useGetPages();
14210
- const getPageFiles = useCallback(
14211
- async (themeId) => {
14212
- var _a;
14213
- const pages = (_a = await getPages(themeId)) == null ? void 0 : _a.items;
14214
- const initialPageFiles = {
14215
- // 添加默认的 index.astro 文件,确保始终有一个可访问的首页
14216
- "index.astro": {
14217
- file: {
14218
- contents: `---
14219
- import Layout from '../layouts/Layout.astro';
14220
- ---
14221
-
14222
- <Layout>
14223
- <main class="p-4 max-w-screen-lg mx-auto">
14224
- <h1 class="text-3xl font-bold mb-4">欢迎访问</h1>
14225
- <p class="text-lg">没有找到首页...</p>
14226
- </main>
14227
- </Layout>
14228
- `
14229
- }
14230
- }
14231
- };
14232
- if (pages && pages.length > 0) {
14233
- pages.forEach((page) => {
14234
- let fileName = `${page.slug}.astro`;
14235
- if (page.pageType === PageType.Home) {
14236
- fileName = "index.astro";
14237
- }
14238
- initialPageFiles[fileName] = {
14239
- file: {
14240
- contents: page.code || ""
14241
- }
14242
- };
14243
- });
14244
- }
14245
- return initialPageFiles;
14246
- },
14247
- [getPages]
14248
14914
  );
14249
- return getPageFiles;
14250
14915
  }
14251
- function useGetComponentFiles() {
14252
- const getComponents = useGetFrontComponents();
14253
- const getFiles = useCallback(
14254
- async (themeId) => {
14916
+ const MenuContent = memo(
14917
+ (props) => {
14918
+ const { selectedContent, onSelectContent } = props;
14919
+ const theme = useWebsiteTheme();
14920
+ const pages = usePages();
14921
+ const customizedPages = useMemo(() => {
14255
14922
  var _a;
14256
- const components = (_a = await getComponents(themeId)) == null ? void 0 : _a.items;
14257
- const files = {};
14258
- if (components && components.length > 0) {
14259
- components.forEach((component) => {
14260
- if (component.name && component.code) {
14261
- files[`${component.name}.astro`] = {
14262
- file: {
14263
- contents: component.code
14264
- }
14265
- };
14266
- }
14267
- });
14268
- }
14269
- return files;
14270
- },
14271
- [getComponents]
14272
- );
14273
- return getFiles;
14274
- }
14275
- function useGetFiles() {
14276
- const getPageFiles = useGetPageFiles();
14277
- const getComponentFiles = useGetComponentFiles();
14278
- const getFiles = useCallback(
14279
- async (theme) => {
14280
- const pageFiles = await getPageFiles((theme == null ? void 0 : theme.id) || void 0);
14281
- const componentFiles = await getComponentFiles((theme == null ? void 0 : theme.id) || void 0);
14282
14923
  return {
14283
- ...baseFiles,
14284
- src: {
14285
- ...baseFiles.src,
14286
- directory: {
14287
- ...baseFiles.src.directory,
14288
- components: {
14289
- ...baseFiles.src.directory.components,
14290
- directory: {
14291
- ...baseFiles.src.directory.components.directory,
14292
- ...componentFiles
14293
- }
14294
- },
14295
- pages: {
14296
- ...baseFiles.src.directory.pages,
14297
- directory: {
14298
- ...baseFiles.src.directory.pages.directory,
14299
- ...pageFiles
14300
- }
14301
- }
14302
- }
14303
- }
14924
+ items: (_a = pages == null ? void 0 : pages.items) == null ? void 0 : _a.filter(
14925
+ (item) => item.pageType === PageType.Customized
14926
+ )
14304
14927
  };
14305
- },
14306
- [getComponentFiles, getPageFiles]
14307
- );
14308
- return getFiles;
14309
- }
14310
- function useSave(onSaved) {
14311
- const save = useCallback(
14312
- (name, content) => {
14313
- saveFile(name, content).then(
14314
- (savedName) => {
14315
- if (savedName) {
14316
- onSaved && onSaved();
14317
- }
14318
- }
14319
- );
14320
- },
14321
- [onSaved]
14322
- );
14323
- return save;
14324
- }
14325
- const defaultSchema = {
14326
- componentName: "Root"
14327
- };
14328
- const emptyValue = { schema: void 0, config: void 0 };
14329
- function useSchema(selectedContent) {
14330
- const [schema, setSchema] = useState(emptyValue);
14331
- const components = useFrontComponents();
14332
- const pages = usePages();
14333
- const componentsRef = useRef(components);
14334
- const pagesRef = useRef(pages);
14335
- componentsRef.current = components;
14336
- pagesRef.current = pages;
14337
- useEffect(() => {
14338
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
14339
- let code;
14340
- let hasContent = false;
14341
- let defaultConfig;
14342
- if ((selectedContent == null ? void 0 : selectedContent.type) === ContentType.Component) {
14343
- const component = (_a = componentsRef.current) == null ? void 0 : _a.find(
14344
- (component2) => component2.id === selectedContent.id
14345
- );
14346
- if (component) {
14347
- code = component.code;
14348
- hasContent = true;
14349
- }
14350
- } else if ((selectedContent == null ? void 0 : selectedContent.type) === ContentType.PredefinedPage || (selectedContent == null ? void 0 : selectedContent.type) === ContentType.Page) {
14351
- const page = (_c = (_b = pagesRef.current) == null ? void 0 : _b.items) == null ? void 0 : _c.find(
14352
- (item) => item.id === selectedContent.id
14353
- );
14354
- defaultConfig = {
14355
- pageMeta: {
14356
- seoTitle: (_d = page == null ? void 0 : page.meta) == null ? void 0 : _d.seoTitle,
14357
- seoDescription: (_e = page == null ? void 0 : page.meta) == null ? void 0 : _e.seoDescription,
14358
- seoKeywords: (_f = page == null ? void 0 : page.meta) == null ? void 0 : _f.seoKeywords,
14359
- ogTitle: (_g = page == null ? void 0 : page.meta) == null ? void 0 : _g.ogTitle,
14360
- ogDescription: (_h = page == null ? void 0 : page.meta) == null ? void 0 : _h.ogDescription,
14361
- ogType: (_i = page == null ? void 0 : page.meta) == null ? void 0 : _i.ogType,
14362
- ogImage: (_j = page == null ? void 0 : page.meta) == null ? void 0 : _j.ogImage
14928
+ }, [pages == null ? void 0 : pages.items]);
14929
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(TreeView, { children: [
14930
+ (theme == null ? void 0 : theme.id) && /* @__PURE__ */ jsxRuntimeExports.jsx(EntityListScope, { entityName: PageEntityName, data: customizedPages, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
14931
+ PagesNode,
14932
+ {
14933
+ themeId: theme.id,
14934
+ selectedContent,
14935
+ onSelectContent
14363
14936
  }
14364
- };
14365
- if (page) {
14366
- code = page.code;
14367
- hasContent = true;
14368
- }
14369
- }
14370
- if (code) {
14371
- transformCodeToSchema(code).then((value) => {
14372
- setSchema({
14373
- schema: { ...defaultSchema, children: (value == null ? void 0 : value.template) || [] },
14374
- config: { ...defaultConfig, ...value.resources }
14375
- });
14376
- });
14377
- } else if (hasContent) {
14378
- setSchema({
14379
- schema: { ...defaultSchema, children: [] }
14380
- });
14381
- }
14382
- }, [selectedContent == null ? void 0 : selectedContent.id, selectedContent == null ? void 0 : selectedContent.type]);
14383
- return schema;
14384
- }
14385
- function useExportWebsite() {
14386
- const [isExporting, setIsExporting] = useState(false);
14387
- const setError = useSetRecoilState(globalErrorState);
14388
- const theme = useWebsiteTheme();
14389
- const save = useSave();
14390
- const getFiles = useGetFiles();
14391
- const addFilesToZip = useCallback(
14392
- (zip, files, currentPath = "") => {
14393
- for (const [name, content] of Object.entries(files)) {
14394
- const path = currentPath ? `${currentPath}/${name}` : name;
14395
- if (content.file && content.file.contents) {
14396
- zip.file(path, content.file.contents);
14397
- } else if (content.directory) {
14398
- const folder = zip.folder(path);
14399
- if (folder) {
14400
- addFilesToZip(folder, content.directory, "");
14401
- }
14402
- } else if (typeof content === "object" && content !== null) {
14403
- if (name === "src" || name === "public" || name === "components" || name === "pages") {
14404
- const folder = zip.folder(path);
14405
- if (folder) {
14406
- addFilesToZip(folder, content, "");
14407
- }
14408
- } else {
14409
- addFilesToZip(zip, content, path);
14410
- }
14937
+ ) }),
14938
+ (theme == null ? void 0 : theme.id) && /* @__PURE__ */ jsxRuntimeExports.jsx(
14939
+ PredefinedPages,
14940
+ {
14941
+ themeId: theme.id,
14942
+ selectedContent,
14943
+ onSelectContent
14411
14944
  }
14412
- }
14413
- },
14414
- []
14415
- );
14416
- const exportWebsite = useCallback(async () => {
14417
- try {
14418
- if (theme == null ? void 0 : theme.id) {
14419
- setIsExporting(true);
14420
- const files = await getFiles(theme);
14421
- const zip = new JSZip();
14422
- console.log("开始导出文件...");
14423
- addFilesToZip(zip, files);
14424
- const content = await zip.generateAsync({ type: "blob" });
14425
- const fileName = `website-${theme.name || theme.id}-${(/* @__PURE__ */ new Date()).toISOString().slice(0, 10)}`;
14426
- save(fileName, content);
14427
- }
14428
- } catch (e) {
14429
- console.error(e);
14430
- setError(e == null ? void 0 : e.message);
14431
- } finally {
14432
- setIsExporting(false);
14433
- }
14434
- }, [getFiles, save, setError, theme, addFilesToZip]);
14435
- return { exportWebsite, isExporting };
14436
- }
14945
+ )
14946
+ ] });
14947
+ }
14948
+ );
14437
14949
  function useDownloadWebsite() {
14438
14950
  const [isDownloading, setIsDownloading] = useState(false);
14439
14951
  const contextValue = useStudioContext();
@@ -15157,6 +15669,10 @@ function WebsiteStudioInner() {
15157
15669
  export {
15158
15670
  WebsiteStudio,
15159
15671
  useCustomizedMaterials,
15160
- useFrontComponent
15672
+ useExportWebsite,
15673
+ useFrontComponent,
15674
+ useGetFiles,
15675
+ useGetFrontComponents,
15676
+ useGetPages
15161
15677
  };
15162
15678
  //# sourceMappingURL=index.mjs.map