@webstudio-is/react-sdk 0.21.0 → 0.23.0

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.
Files changed (47) hide show
  1. package/lib/app/custom-components/image.js +3 -3
  2. package/lib/cjs/app/custom-components/image.cjs +3 -3
  3. package/lib/cjs/components/index.cjs +15 -9
  4. package/lib/cjs/index.cjs +3 -3
  5. package/lib/cjs/props.cjs +80 -0
  6. package/lib/cjs/tree/root.cjs +3 -2
  7. package/lib/cjs/tree/wrapper-component.cjs +7 -4
  8. package/lib/components/index.js +15 -9
  9. package/lib/index.js +3 -3
  10. package/lib/props.js +60 -0
  11. package/lib/tree/root.js +3 -2
  12. package/lib/tree/wrapper-component.js +10 -7
  13. package/package.json +11 -11
  14. package/src/app/custom-components/image.tsx +3 -3
  15. package/src/components/index.ts +26 -17
  16. package/src/index.ts +2 -3
  17. package/src/props.ts +69 -0
  18. package/src/tree/create-elements-tree.tsx +2 -2
  19. package/src/tree/root.ts +9 -9
  20. package/src/tree/wrapper-component.tsx +8 -5
  21. package/lib/cjs/db/index.cjs +0 -20
  22. package/lib/cjs/db/instance.cjs +0 -59
  23. package/lib/cjs/db/style.cjs +0 -67
  24. package/lib/cjs/db/types.cjs +0 -16
  25. package/lib/cjs/user-props/all-user-props.cjs +0 -40
  26. package/lib/cjs/user-props/index.cjs +0 -20
  27. package/lib/cjs/user-props/schema.cjs +0 -54
  28. package/lib/cjs/user-props/use-user-props-asset.cjs +0 -43
  29. package/lib/cjs/user-props/use-user-props.cjs +0 -42
  30. package/lib/db/index.js +0 -3
  31. package/lib/db/instance.js +0 -39
  32. package/lib/db/style.js +0 -50
  33. package/lib/db/types.js +0 -0
  34. package/lib/user-props/all-user-props.js +0 -20
  35. package/lib/user-props/index.js +0 -3
  36. package/lib/user-props/schema.js +0 -34
  37. package/lib/user-props/use-user-props-asset.js +0 -23
  38. package/lib/user-props/use-user-props.js +0 -22
  39. package/src/db/index.ts +0 -3
  40. package/src/db/instance.ts +0 -56
  41. package/src/db/style.ts +0 -63
  42. package/src/db/types.ts +0 -22
  43. package/src/user-props/all-user-props.ts +0 -26
  44. package/src/user-props/index.ts +0 -3
  45. package/src/user-props/schema.ts +0 -35
  46. package/src/user-props/use-user-props-asset.ts +0 -35
  47. package/src/user-props/use-user-props.ts +0 -32
@@ -1,7 +1,7 @@
1
1
  import { type ComponentProps, Fragment } from "react";
2
- import type { Instance } from "../db";
3
- import { WrapperComponent } from "./wrapper-component";
4
2
  import { Scripts, ScrollRestoration } from "@remix-run/react";
3
+ import type { Instance } from "@webstudio-is/project-build";
4
+ import { WrapperComponent } from "./wrapper-component";
5
5
  import { SessionStoragePolyfill } from "./session-storage-polyfill";
6
6
 
7
7
  export type ChildrenUpdates = Array<
package/src/tree/root.ts CHANGED
@@ -1,20 +1,18 @@
1
- import { useAllUserProps } from "../user-props/";
2
- import type { Tree, InstanceProps } from "../db";
1
+ import type { ComponentProps } from "react";
2
+ import { atom } from "nanostores";
3
+ import type { Breakpoint } from "@webstudio-is/css-data";
4
+ import type { Tree } from "@webstudio-is/project-build";
5
+ import type { Asset } from "@webstudio-is/asset-uploader";
3
6
  import { createElementsTree } from "./create-elements-tree";
4
7
  import { WrapperComponent } from "./wrapper-component";
5
- import type { Asset } from "@webstudio-is/asset-uploader";
6
- import { type ComponentProps } from "react";
7
- import type { Breakpoint } from "@webstudio-is/css-data";
8
8
  import { registerComponents } from "../components";
9
9
  import { customComponents as defaultCustomComponents } from "../app/custom-components";
10
10
  import { setParams, type Params } from "../app/params";
11
- import type { DesignToken } from "@webstudio-is/design-tokens";
11
+ import { getPropsByInstanceId, setPropsByInstanceIdStore } from "../props";
12
12
 
13
13
  export type Data = {
14
14
  tree: Tree | null;
15
15
  breakpoints: Array<Breakpoint>;
16
- designTokens: Array<DesignToken>;
17
- props: Array<InstanceProps>;
18
16
  assets: Array<Asset>;
19
17
  params?: Params;
20
18
  };
@@ -33,7 +31,9 @@ export const InstanceRoot = ({
33
31
  if (data.tree === null) {
34
32
  throw new Error("Tree is null");
35
33
  }
36
- useAllUserProps(data.props);
34
+
35
+ setPropsByInstanceIdStore(atom(getPropsByInstanceId(data.tree.props)));
36
+
37
37
  setParams(data.params ?? null);
38
38
 
39
39
  registerComponents(customComponents);
@@ -1,7 +1,7 @@
1
1
  import { Fragment } from "react";
2
- import type { Instance } from "../db";
2
+ import type { Instance } from "@webstudio-is/project-build";
3
3
  import { getComponent } from "../components";
4
- import { useUserProps } from "../user-props/use-user-props";
4
+ import { useInstanceProps } from "../props";
5
5
  import type { OnChangeChildren } from "./create-elements-tree";
6
6
 
7
7
  const renderText = (text: string): Array<JSX.Element> => {
@@ -39,14 +39,17 @@ export const WrapperComponent = ({
39
39
  children,
40
40
  ...rest
41
41
  }: WrapperComponentProps) => {
42
- const Component = getComponent(instance.component);
43
- const userProps = useUserProps(instance.id);
42
+ const instanceProps = useInstanceProps(instance.id);
44
43
  const props = {
45
- ...userProps,
44
+ ...instanceProps,
46
45
  ...rest,
47
46
  [idAttribute]: instance.id,
48
47
  [componentAttribute]: instance.component,
49
48
  };
49
+ const Component = getComponent(instance.component);
50
+ if (Component === undefined) {
51
+ return <></>;
52
+ }
50
53
  return (
51
54
  <Component {...props}>{renderWrapperComponentChildren(children)}</Component>
52
55
  );
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var db_exports = {};
17
- module.exports = __toCommonJS(db_exports);
18
- __reExport(db_exports, require("./types"), module.exports);
19
- __reExport(db_exports, require("./instance"), module.exports);
20
- __reExport(db_exports, require("./style"), module.exports);
@@ -1,59 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var instance_exports = {};
20
- __export(instance_exports, {
21
- Id: () => Id,
22
- Instance: () => Instance,
23
- Instances: () => Instances,
24
- InstancesItem: () => InstancesItem,
25
- Text: () => Text,
26
- toBaseInstance: () => toBaseInstance
27
- });
28
- module.exports = __toCommonJS(instance_exports);
29
- var import_zod = require("zod");
30
- var import_components = require("../components");
31
- const toBaseInstance = (instance) => {
32
- return {
33
- id: instance.id,
34
- component: instance.component
35
- };
36
- };
37
- const Text = import_zod.z.object({
38
- type: import_zod.z.literal("text"),
39
- value: import_zod.z.string()
40
- });
41
- const Id = import_zod.z.object({
42
- type: import_zod.z.literal("id"),
43
- value: import_zod.z.string()
44
- });
45
- const InstancesItem = import_zod.z.object({
46
- type: import_zod.z.literal("instance"),
47
- id: import_zod.z.string(),
48
- component: import_zod.z.enum((0, import_components.getComponentNames)()),
49
- children: import_zod.z.array(import_zod.z.union([Id, Text]))
50
- });
51
- const Instances = import_zod.z.array(InstancesItem);
52
- const Instance = import_zod.z.lazy(
53
- () => import_zod.z.object({
54
- type: import_zod.z.literal("instance"),
55
- id: import_zod.z.string(),
56
- component: import_zod.z.enum((0, import_components.getComponentNames)()),
57
- children: import_zod.z.array(import_zod.z.union([Instance, Text]))
58
- })
59
- );
@@ -1,67 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var style_exports = {};
20
- __export(style_exports, {
21
- PresetStyles: () => PresetStyles,
22
- PresetStylesItem: () => PresetStylesItem,
23
- Styles: () => Styles,
24
- StylesItem: () => StylesItem,
25
- findMissingPresetStyles: () => findMissingPresetStyles
26
- });
27
- module.exports = __toCommonJS(style_exports);
28
- var import_zod = require("zod");
29
- var import_css_data = require("@webstudio-is/css-data");
30
- var import_components = require("../components");
31
- const PresetStylesItem = import_zod.z.object({
32
- component: import_zod.z.enum((0, import_components.getComponentNames)()),
33
- property: import_zod.z.string(),
34
- value: import_css_data.SharedStyleValue
35
- });
36
- const PresetStyles = import_zod.z.array(PresetStylesItem);
37
- const findMissingPresetStyles = (presetStyles, components) => {
38
- const populatedComponents = /* @__PURE__ */ new Set();
39
- for (const style of presetStyles) {
40
- populatedComponents.add(style.component);
41
- }
42
- const missingPresetStyles = [];
43
- for (const component of components) {
44
- if (populatedComponents.has(component)) {
45
- continue;
46
- }
47
- const meta = (0, import_components.getComponentMeta)(component);
48
- if (meta.presetStyle === void 0) {
49
- continue;
50
- }
51
- for (const [property, value] of Object.entries(meta.presetStyle)) {
52
- missingPresetStyles.push({
53
- component,
54
- property,
55
- value
56
- });
57
- }
58
- }
59
- return missingPresetStyles;
60
- };
61
- const StylesItem = import_zod.z.object({
62
- breakpointId: import_zod.z.string(),
63
- instanceId: import_zod.z.string(),
64
- property: import_zod.z.string(),
65
- value: import_css_data.SharedStyleValue
66
- });
67
- const Styles = import_zod.z.array(StylesItem);
@@ -1,16 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
- var types_exports = {};
16
- module.exports = __toCommonJS(types_exports);
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var all_user_props_exports = {};
20
- __export(all_user_props_exports, {
21
- allUserPropsContainer: () => allUserPropsContainer,
22
- useAllUserProps: () => useAllUserProps
23
- });
24
- module.exports = __toCommonJS(all_user_props_exports);
25
- var import_react = require("react");
26
- var import_nanostores = require("nanostores");
27
- var import_react2 = require("@nanostores/react");
28
- const allUserPropsContainer = (0, import_nanostores.atom)({});
29
- const useAllUserProps = (initialUserProps) => {
30
- const ref = (0, import_react.useRef)(false);
31
- if (ref.current === false && initialUserProps !== void 0) {
32
- const propsMap = {};
33
- for (const item of initialUserProps) {
34
- propsMap[item.instanceId] = item.props;
35
- }
36
- allUserPropsContainer.set(propsMap);
37
- ref.current = true;
38
- }
39
- return (0, import_react2.useStore)(allUserPropsContainer);
40
- };
@@ -1,20 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __copyProps = (to, from, except, desc) => {
7
- if (from && typeof from === "object" || typeof from === "function") {
8
- for (let key of __getOwnPropNames(from))
9
- if (!__hasOwnProp.call(to, key) && key !== except)
10
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
11
- }
12
- return to;
13
- };
14
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
15
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
16
- var user_props_exports = {};
17
- module.exports = __toCommonJS(user_props_exports);
18
- __reExport(user_props_exports, require("./all-user-props"), module.exports);
19
- __reExport(user_props_exports, require("./use-user-props"), module.exports);
20
- __reExport(user_props_exports, require("./schema"), module.exports);
@@ -1,54 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var schema_exports = {};
20
- __export(schema_exports, {
21
- UserProp: () => UserProp,
22
- UserProps: () => UserProps
23
- });
24
- module.exports = __toCommonJS(schema_exports);
25
- var import_zod = require("zod");
26
- var import_asset_uploader = require("@webstudio-is/asset-uploader");
27
- const baseUserProps = {
28
- id: import_zod.z.string(),
29
- prop: import_zod.z.string(),
30
- required: import_zod.z.optional(import_zod.z.boolean())
31
- };
32
- const UserProp = import_zod.z.discriminatedUnion("type", [
33
- import_zod.z.object({
34
- ...baseUserProps,
35
- type: import_zod.z.literal("number"),
36
- value: import_zod.z.number()
37
- }),
38
- import_zod.z.object({
39
- ...baseUserProps,
40
- type: import_zod.z.literal("string"),
41
- value: import_zod.z.string()
42
- }),
43
- import_zod.z.object({
44
- ...baseUserProps,
45
- type: import_zod.z.literal("boolean"),
46
- value: import_zod.z.boolean()
47
- }),
48
- import_zod.z.object({
49
- ...baseUserProps,
50
- type: import_zod.z.literal("asset"),
51
- value: import_asset_uploader.Asset
52
- })
53
- ]);
54
- const UserProps = import_zod.z.array(UserProp);
@@ -1,43 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var use_user_props_asset_exports = {};
20
- __export(use_user_props_asset_exports, {
21
- useUserPropsAsset: () => useUserPropsAsset
22
- });
23
- module.exports = __toCommonJS(use_user_props_asset_exports);
24
- var import_react = require("react");
25
- var import_all_user_props = require("./all-user-props");
26
- const useUserPropsAsset = (instanceId, propName) => {
27
- const allUserProps = (0, import_all_user_props.useAllUserProps)();
28
- const propsData = allUserProps[instanceId];
29
- const asset = (0, import_react.useMemo)(() => {
30
- if (propsData == null) {
31
- return void 0;
32
- }
33
- const prop = propsData.find((prop2) => prop2.prop === propName);
34
- if (prop == null) {
35
- return void 0;
36
- }
37
- if (prop.type === "asset") {
38
- return prop.value;
39
- }
40
- return void 0;
41
- }, [propName, propsData]);
42
- return asset;
43
- };
@@ -1,42 +0,0 @@
1
- "use strict";
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __export = (target, all) => {
7
- for (var name in all)
8
- __defProp(target, name, { get: all[name], enumerable: true });
9
- };
10
- var __copyProps = (to, from, except, desc) => {
11
- if (from && typeof from === "object" || typeof from === "function") {
12
- for (let key of __getOwnPropNames(from))
13
- if (!__hasOwnProp.call(to, key) && key !== except)
14
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
- }
16
- return to;
17
- };
18
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
- var use_user_props_exports = {};
20
- __export(use_user_props_exports, {
21
- useUserProps: () => useUserProps
22
- });
23
- module.exports = __toCommonJS(use_user_props_exports);
24
- var import_react = require("react");
25
- var import_all_user_props = require("./all-user-props");
26
- const useUserProps = (instanceId) => {
27
- const allUserProps = (0, import_all_user_props.useAllUserProps)();
28
- const propsData = allUserProps[instanceId];
29
- const props = (0, import_react.useMemo)(() => {
30
- if (propsData == null) {
31
- return {};
32
- }
33
- const result = {};
34
- for (const userProp of propsData) {
35
- if (userProp.type !== "asset") {
36
- result[userProp.prop] = userProp.value;
37
- }
38
- }
39
- return result;
40
- }, [propsData]);
41
- return props;
42
- };
package/lib/db/index.js DELETED
@@ -1,3 +0,0 @@
1
- export * from "./types";
2
- export * from "./instance";
3
- export * from "./style";
@@ -1,39 +0,0 @@
1
- import { z } from "zod";
2
- import { getComponentNames } from "../components";
3
- const toBaseInstance = (instance) => {
4
- return {
5
- id: instance.id,
6
- component: instance.component
7
- };
8
- };
9
- const Text = z.object({
10
- type: z.literal("text"),
11
- value: z.string()
12
- });
13
- const Id = z.object({
14
- type: z.literal("id"),
15
- value: z.string()
16
- });
17
- const InstancesItem = z.object({
18
- type: z.literal("instance"),
19
- id: z.string(),
20
- component: z.enum(getComponentNames()),
21
- children: z.array(z.union([Id, Text]))
22
- });
23
- const Instances = z.array(InstancesItem);
24
- const Instance = z.lazy(
25
- () => z.object({
26
- type: z.literal("instance"),
27
- id: z.string(),
28
- component: z.enum(getComponentNames()),
29
- children: z.array(z.union([Instance, Text]))
30
- })
31
- );
32
- export {
33
- Id,
34
- Instance,
35
- Instances,
36
- InstancesItem,
37
- Text,
38
- toBaseInstance
39
- };
package/lib/db/style.js DELETED
@@ -1,50 +0,0 @@
1
- import { z } from "zod";
2
- import { SharedStyleValue } from "@webstudio-is/css-data";
3
- import {
4
- getComponentMeta,
5
- getComponentNames
6
- } from "../components";
7
- const PresetStylesItem = z.object({
8
- component: z.enum(getComponentNames()),
9
- property: z.string(),
10
- value: SharedStyleValue
11
- });
12
- const PresetStyles = z.array(PresetStylesItem);
13
- const findMissingPresetStyles = (presetStyles, components) => {
14
- const populatedComponents = /* @__PURE__ */ new Set();
15
- for (const style of presetStyles) {
16
- populatedComponents.add(style.component);
17
- }
18
- const missingPresetStyles = [];
19
- for (const component of components) {
20
- if (populatedComponents.has(component)) {
21
- continue;
22
- }
23
- const meta = getComponentMeta(component);
24
- if (meta.presetStyle === void 0) {
25
- continue;
26
- }
27
- for (const [property, value] of Object.entries(meta.presetStyle)) {
28
- missingPresetStyles.push({
29
- component,
30
- property,
31
- value
32
- });
33
- }
34
- }
35
- return missingPresetStyles;
36
- };
37
- const StylesItem = z.object({
38
- breakpointId: z.string(),
39
- instanceId: z.string(),
40
- property: z.string(),
41
- value: SharedStyleValue
42
- });
43
- const Styles = z.array(StylesItem);
44
- export {
45
- PresetStyles,
46
- PresetStylesItem,
47
- Styles,
48
- StylesItem,
49
- findMissingPresetStyles
50
- };
package/lib/db/types.js DELETED
File without changes
@@ -1,20 +0,0 @@
1
- import { useRef } from "react";
2
- import { atom } from "nanostores";
3
- import { useStore } from "@nanostores/react";
4
- const allUserPropsContainer = atom({});
5
- const useAllUserProps = (initialUserProps) => {
6
- const ref = useRef(false);
7
- if (ref.current === false && initialUserProps !== void 0) {
8
- const propsMap = {};
9
- for (const item of initialUserProps) {
10
- propsMap[item.instanceId] = item.props;
11
- }
12
- allUserPropsContainer.set(propsMap);
13
- ref.current = true;
14
- }
15
- return useStore(allUserPropsContainer);
16
- };
17
- export {
18
- allUserPropsContainer,
19
- useAllUserProps
20
- };
@@ -1,3 +0,0 @@
1
- export * from "./all-user-props";
2
- export * from "./use-user-props";
3
- export * from "./schema";
@@ -1,34 +0,0 @@
1
- import { z } from "zod";
2
- import { Asset } from "@webstudio-is/asset-uploader";
3
- const baseUserProps = {
4
- id: z.string(),
5
- prop: z.string(),
6
- required: z.optional(z.boolean())
7
- };
8
- const UserProp = z.discriminatedUnion("type", [
9
- z.object({
10
- ...baseUserProps,
11
- type: z.literal("number"),
12
- value: z.number()
13
- }),
14
- z.object({
15
- ...baseUserProps,
16
- type: z.literal("string"),
17
- value: z.string()
18
- }),
19
- z.object({
20
- ...baseUserProps,
21
- type: z.literal("boolean"),
22
- value: z.boolean()
23
- }),
24
- z.object({
25
- ...baseUserProps,
26
- type: z.literal("asset"),
27
- value: Asset
28
- })
29
- ]);
30
- const UserProps = z.array(UserProp);
31
- export {
32
- UserProp,
33
- UserProps
34
- };
@@ -1,23 +0,0 @@
1
- import { useMemo } from "react";
2
- import { useAllUserProps } from "./all-user-props";
3
- const useUserPropsAsset = (instanceId, propName) => {
4
- const allUserProps = useAllUserProps();
5
- const propsData = allUserProps[instanceId];
6
- const asset = useMemo(() => {
7
- if (propsData == null) {
8
- return void 0;
9
- }
10
- const prop = propsData.find((prop2) => prop2.prop === propName);
11
- if (prop == null) {
12
- return void 0;
13
- }
14
- if (prop.type === "asset") {
15
- return prop.value;
16
- }
17
- return void 0;
18
- }, [propName, propsData]);
19
- return asset;
20
- };
21
- export {
22
- useUserPropsAsset
23
- };
@@ -1,22 +0,0 @@
1
- import { useMemo } from "react";
2
- import { useAllUserProps } from "./all-user-props";
3
- const useUserProps = (instanceId) => {
4
- const allUserProps = useAllUserProps();
5
- const propsData = allUserProps[instanceId];
6
- const props = useMemo(() => {
7
- if (propsData == null) {
8
- return {};
9
- }
10
- const result = {};
11
- for (const userProp of propsData) {
12
- if (userProp.type !== "asset") {
13
- result[userProp.prop] = userProp.value;
14
- }
15
- }
16
- return result;
17
- }, [propsData]);
18
- return props;
19
- };
20
- export {
21
- useUserProps
22
- };
package/src/db/index.ts DELETED
@@ -1,3 +0,0 @@
1
- export * from "./types";
2
- export * from "./instance";
3
- export * from "./style";