@webiny/react-properties 0.0.0-unstable.06b2ede40f → 0.0.0-unstable.0d717d18dd

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/index.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- export * from "./utils";
2
- export * from "./Properties";
3
- export * from "./useDebugConfig";
4
- export * from "./useIdGenerator";
5
- export * from "./createConfigurableComponent";
1
+ export * from "./utils.js";
2
+ export * from "./Properties.js";
3
+ export * from "./AsyncProperties.js";
4
+ export * from "./Await.js";
5
+ export * from "./useDebugConfig.js";
6
+ export * from "./useIdGenerator.js";
7
+ export * from "./createConfigurableComponent.js";
8
+ export * from "./domain/index.js";
9
+ export { DevToolsSection } from "./DevToolsSection.js";
package/index.js CHANGED
@@ -1,7 +1,9 @@
1
- export * from "./utils";
2
- export * from "./Properties";
3
- export * from "./useDebugConfig";
4
- export * from "./useIdGenerator";
5
- export * from "./createConfigurableComponent";
6
-
7
- //# sourceMappingURL=index.js.map
1
+ export * from "./utils.js";
2
+ export * from "./Properties.js";
3
+ export * from "./AsyncProperties.js";
4
+ export * from "./Await.js";
5
+ export * from "./useDebugConfig.js";
6
+ export * from "./useIdGenerator.js";
7
+ export * from "./createConfigurableComponent.js";
8
+ export * from "./domain/index.js";
9
+ export { DevToolsSection } from "./DevToolsSection.js";
package/package.json CHANGED
@@ -1,7 +1,11 @@
1
1
  {
2
2
  "name": "@webiny/react-properties",
3
- "version": "0.0.0-unstable.06b2ede40f",
4
- "main": "index.js",
3
+ "version": "0.0.0-unstable.0d717d18dd",
4
+ "type": "module",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./*": "./*"
8
+ },
5
9
  "repository": {
6
10
  "type": "git",
7
11
  "url": "https://github.com/webiny/webiny-js.git"
@@ -10,23 +14,22 @@
10
14
  "author": "Webiny Ltd",
11
15
  "license": "MIT",
12
16
  "dependencies": {
13
- "@types/react": "18.2.79",
14
- "@webiny/react-composition": "0.0.0-unstable.06b2ede40f",
15
- "nanoid": "3.3.8",
16
- "react": "18.2.0"
17
+ "@types/react": "18.3.31",
18
+ "@webiny/react-composition": "0.0.0-unstable.0d717d18dd",
19
+ "lodash": "4.18.1",
20
+ "nanoid": "6.0.0",
21
+ "react": "18.3.1"
17
22
  },
18
23
  "devDependencies": {
19
- "@testing-library/react": "15.0.7",
20
- "@webiny/project-utils": "0.0.0-unstable.06b2ede40f",
21
- "prettier": "2.8.8"
24
+ "@testing-library/react": "16.3.2",
25
+ "@webiny/build-tools": "0.0.0-unstable.0d717d18dd",
26
+ "oxfmt": "0.61.0",
27
+ "vitest": "4.1.10"
22
28
  },
23
29
  "publishConfig": {
24
- "access": "public",
25
- "directory": "dist"
26
- },
27
- "scripts": {
28
- "build": "node ../cli/bin.js run build",
29
- "watch": "node ../cli/bin.js run watch"
30
+ "access": "public"
30
31
  },
31
- "gitHead": "06b2ede40fc2212a70eeafd74afd50b56fb0ce82"
32
+ "webiny": {
33
+ "publishFrom": "dist"
34
+ }
32
35
  }
@@ -1,7 +1,32 @@
1
- import type { Property } from "./Properties";
1
+ import type { Property } from "./Properties.js";
2
+ interface WebinyDevtoolsConfig {
3
+ properties: Array<{
4
+ id: string;
5
+ parent: string;
6
+ name: string;
7
+ value?: unknown;
8
+ array?: boolean;
9
+ }>;
10
+ config: unknown;
11
+ updatedAt: number;
12
+ }
13
+ interface WebinyDevtoolsSection {
14
+ data: unknown;
15
+ group: string;
16
+ views: string[];
17
+ updatedAt: number;
18
+ }
19
+ interface WebinyDevtoolsHook {
20
+ revision: number;
21
+ configs: Record<string, WebinyDevtoolsConfig>;
22
+ sections: Record<string, WebinyDevtoolsSection>;
23
+ }
2
24
  declare global {
3
25
  interface Window {
4
26
  __debugConfigs: Record<string, () => void>;
27
+ __WEBINY_DEVTOOLS_HOOK__?: WebinyDevtoolsHook;
5
28
  }
6
29
  }
30
+ export declare function getHook(): WebinyDevtoolsHook;
7
31
  export declare function useDebugConfig(name: string, properties: Property[]): void;
32
+ export {};
package/useDebugConfig.js CHANGED
@@ -1,19 +1,45 @@
1
1
  import { useEffect } from "react";
2
- import { toObject } from "./utils";
3
- export function useDebugConfig(name, properties) {
4
- useEffect(() => {
5
- if (process.env.NODE_ENV !== "development") {
6
- return;
7
- }
8
- const configs = window.__debugConfigs ?? {};
9
- configs[name] = () => console.log(toObject(properties));
10
- window.__debugConfigs = configs;
11
- return () => {
12
- const configs = window.__debugConfigs ?? {};
13
- delete configs[name];
14
- window.__debugConfigs = configs;
2
+ import { toObject } from "./utils.js";
3
+ function getHook() {
4
+ if (!window.__WEBINY_DEVTOOLS_HOOK__) window.__WEBINY_DEVTOOLS_HOOK__ = {
5
+ revision: 0,
6
+ configs: {},
7
+ sections: {}
15
8
  };
16
- }, [properties]);
9
+ return window.__WEBINY_DEVTOOLS_HOOK__;
17
10
  }
11
+ function useDebugConfig(name, properties) {
12
+ useEffect(()=>{
13
+ if ("development" !== process.env.NODE_ENV) return;
14
+ const configs = window.__debugConfigs ?? {};
15
+ configs[name] = ()=>console.log(toObject(properties));
16
+ window.__debugConfigs = configs;
17
+ const hook = getHook();
18
+ hook.configs[name] = {
19
+ properties: properties.map((p)=>({
20
+ id: p.id,
21
+ parent: p.parent,
22
+ name: p.name,
23
+ value: p.value,
24
+ array: p.array
25
+ })),
26
+ config: toObject(properties),
27
+ updatedAt: Date.now()
28
+ };
29
+ hook.revision++;
30
+ return ()=>{
31
+ const configs = window.__debugConfigs ?? {};
32
+ delete configs[name];
33
+ window.__debugConfigs = configs;
34
+ if (window.__WEBINY_DEVTOOLS_HOOK__) {
35
+ delete window.__WEBINY_DEVTOOLS_HOOK__.configs[name];
36
+ window.__WEBINY_DEVTOOLS_HOOK__.revision++;
37
+ }
38
+ };
39
+ }, [
40
+ properties
41
+ ]);
42
+ }
43
+ export { getHook, useDebugConfig };
18
44
 
19
45
  //# sourceMappingURL=useDebugConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","toObject","useDebugConfig","name","properties","process","env","NODE_ENV","configs","window","__debugConfigs","console","log"],"sources":["useDebugConfig.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport type { Property } from \"./Properties\";\nimport { toObject } from \"./utils\";\n\ndeclare global {\n interface Window {\n __debugConfigs: Record<string, () => void>;\n }\n}\n\nexport function useDebugConfig(name: string, properties: Property[]) {\n useEffect(() => {\n if (process.env.NODE_ENV !== \"development\") {\n return;\n }\n\n const configs = window.__debugConfigs ?? {};\n configs[name] = () => console.log(toObject(properties));\n window.__debugConfigs = configs;\n\n return () => {\n const configs = window.__debugConfigs ?? {};\n delete configs[name];\n window.__debugConfigs = configs;\n };\n }, [properties]);\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,QAAQ;AAQjB,OAAO,SAASC,cAAcA,CAACC,IAAY,EAAEC,UAAsB,EAAE;EACjEJ,SAAS,CAAC,MAAM;IACZ,IAAIK,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,aAAa,EAAE;MACxC;IACJ;IAEA,MAAMC,OAAO,GAAGC,MAAM,CAACC,cAAc,IAAI,CAAC,CAAC;IAC3CF,OAAO,CAACL,IAAI,CAAC,GAAG,MAAMQ,OAAO,CAACC,GAAG,CAACX,QAAQ,CAACG,UAAU,CAAC,CAAC;IACvDK,MAAM,CAACC,cAAc,GAAGF,OAAO;IAE/B,OAAO,MAAM;MACT,MAAMA,OAAO,GAAGC,MAAM,CAACC,cAAc,IAAI,CAAC,CAAC;MAC3C,OAAOF,OAAO,CAACL,IAAI,CAAC;MACpBM,MAAM,CAACC,cAAc,GAAGF,OAAO;IACnC,CAAC;EACL,CAAC,EAAE,CAACJ,UAAU,CAAC,CAAC;AACpB","ignoreList":[]}
1
+ {"version":3,"file":"useDebugConfig.js","sources":["../src/useDebugConfig.ts"],"sourcesContent":["import { useEffect } from \"react\";\nimport type { Property } from \"./Properties.js\";\nimport { toObject } from \"./utils.js\";\n\ninterface WebinyDevtoolsConfig {\n properties: Array<{\n id: string;\n parent: string;\n name: string;\n value?: unknown;\n array?: boolean;\n }>;\n config: unknown;\n updatedAt: number;\n}\n\ninterface WebinyDevtoolsSection {\n data: unknown;\n group: string;\n views: string[];\n updatedAt: number;\n}\n\ninterface WebinyDevtoolsHook {\n revision: number;\n configs: Record<string, WebinyDevtoolsConfig>;\n sections: Record<string, WebinyDevtoolsSection>;\n}\n\ndeclare global {\n interface Window {\n __debugConfigs: Record<string, () => void>;\n __WEBINY_DEVTOOLS_HOOK__?: WebinyDevtoolsHook;\n }\n}\n\nexport function getHook(): WebinyDevtoolsHook {\n if (!window.__WEBINY_DEVTOOLS_HOOK__) {\n window.__WEBINY_DEVTOOLS_HOOK__ = { revision: 0, configs: {}, sections: {} };\n }\n return window.__WEBINY_DEVTOOLS_HOOK__;\n}\n\nexport function useDebugConfig(name: string, properties: Property[]) {\n useEffect(() => {\n if (process.env.NODE_ENV !== \"development\") {\n return;\n }\n\n // Legacy console.log support\n const configs = window.__debugConfigs ?? {};\n configs[name] = () => console.log(toObject(properties));\n window.__debugConfigs = configs;\n\n // DevTools hook: structured data for the Chrome extension\n const hook = getHook();\n hook.configs[name] = {\n properties: properties.map(p => ({\n id: p.id,\n parent: p.parent,\n name: p.name,\n value: p.value,\n array: p.array\n })),\n config: toObject(properties),\n updatedAt: Date.now()\n };\n hook.revision++;\n\n return () => {\n // Legacy cleanup\n const configs = window.__debugConfigs ?? {};\n delete configs[name];\n window.__debugConfigs = configs;\n\n // DevTools hook cleanup\n if (window.__WEBINY_DEVTOOLS_HOOK__) {\n delete window.__WEBINY_DEVTOOLS_HOOK__.configs[name];\n window.__WEBINY_DEVTOOLS_HOOK__.revision++;\n }\n };\n }, [properties]);\n}\n"],"names":["getHook","window","useDebugConfig","name","properties","useEffect","process","configs","console","toObject","hook","p","Date"],"mappings":";;AAoCO,SAASA;IACZ,IAAI,CAACC,OAAO,wBAAwB,EAChCA,OAAO,wBAAwB,GAAG;QAAE,UAAU;QAAG,SAAS,CAAC;QAAG,UAAU,CAAC;IAAE;IAE/E,OAAOA,OAAO,wBAAwB;AAC1C;AAEO,SAASC,eAAeC,IAAY,EAAEC,UAAsB;IAC/DC,UAAU;QACN,IAAIC,AAAyB,kBAAzBA,QAAQ,GAAG,CAAC,QAAQ,EACpB;QAIJ,MAAMC,UAAUN,OAAO,cAAc,IAAI,CAAC;QAC1CM,OAAO,CAACJ,KAAK,GAAG,IAAMK,QAAQ,GAAG,CAACC,SAASL;QAC3CH,OAAO,cAAc,GAAGM;QAGxB,MAAMG,OAAOV;QACbU,KAAK,OAAO,CAACP,KAAK,GAAG;YACjB,YAAYC,WAAW,GAAG,CAACO,CAAAA,IAAM;oBAC7B,IAAIA,EAAE,EAAE;oBACR,QAAQA,EAAE,MAAM;oBAChB,MAAMA,EAAE,IAAI;oBACZ,OAAOA,EAAE,KAAK;oBACd,OAAOA,EAAE,KAAK;gBAClB;YACA,QAAQF,SAASL;YACjB,WAAWQ,KAAK,GAAG;QACvB;QACAF,KAAK,QAAQ;QAEb,OAAO;YAEH,MAAMH,UAAUN,OAAO,cAAc,IAAI,CAAC;YAC1C,OAAOM,OAAO,CAACJ,KAAK;YACpBF,OAAO,cAAc,GAAGM;YAGxB,IAAIN,OAAO,wBAAwB,EAAE;gBACjC,OAAOA,OAAO,wBAAwB,CAAC,OAAO,CAACE,KAAK;gBACpDF,OAAO,wBAAwB,CAAC,QAAQ;YAC5C;QACJ;IACJ,GAAG;QAACG;KAAW;AACnB"}
package/useIdGenerator.js CHANGED
@@ -1,14 +1,23 @@
1
1
  import { useCallback } from "react";
2
- import { useParentProperty } from "./Properties";
3
- const keywords = ["$first", "$last"];
4
- export function useIdGenerator(name) {
5
- const parentProperty = useParentProperty();
6
- return useCallback((...parts) => {
7
- if (keywords.includes(parts[0])) {
8
- return parts[0];
9
- }
10
- return [parentProperty?.id, name, ...parts].filter(Boolean).join(":");
11
- }, [name, parentProperty]);
2
+ import { useParentProperty } from "./Properties.js";
3
+ const keywords = [
4
+ "$first",
5
+ "$last"
6
+ ];
7
+ function useIdGenerator(name) {
8
+ const parentProperty = useParentProperty();
9
+ return useCallback((...parts)=>{
10
+ if (keywords.includes(parts[0])) return parts[0];
11
+ return [
12
+ parentProperty?.id,
13
+ name,
14
+ ...parts
15
+ ].filter(Boolean).join(":");
16
+ }, [
17
+ name,
18
+ parentProperty
19
+ ]);
12
20
  }
21
+ export { useIdGenerator };
13
22
 
14
23
  //# sourceMappingURL=useIdGenerator.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useParentProperty","keywords","useIdGenerator","name","parentProperty","parts","includes","id","filter","Boolean","join"],"sources":["useIdGenerator.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useParentProperty } from \"~/Properties\";\n\nconst keywords = [\"$first\", \"$last\"];\n\nexport function useIdGenerator(name: string) {\n const parentProperty = useParentProperty();\n\n return useCallback(\n (...parts: string[]) => {\n if (keywords.includes(parts[0])) {\n return parts[0];\n }\n return [parentProperty?.id, name, ...parts].filter(Boolean).join(\":\");\n },\n [name, parentProperty]\n );\n}\n"],"mappings":"AAAA,SAASA,WAAW,QAAQ,OAAO;AACnC,SAASC,iBAAiB;AAE1B,MAAMC,QAAQ,GAAG,CAAC,QAAQ,EAAE,OAAO,CAAC;AAEpC,OAAO,SAASC,cAAcA,CAACC,IAAY,EAAE;EACzC,MAAMC,cAAc,GAAGJ,iBAAiB,CAAC,CAAC;EAE1C,OAAOD,WAAW,CACd,CAAC,GAAGM,KAAe,KAAK;IACpB,IAAIJ,QAAQ,CAACK,QAAQ,CAACD,KAAK,CAAC,CAAC,CAAC,CAAC,EAAE;MAC7B,OAAOA,KAAK,CAAC,CAAC,CAAC;IACnB;IACA,OAAO,CAACD,cAAc,EAAEG,EAAE,EAAEJ,IAAI,EAAE,GAAGE,KAAK,CAAC,CAACG,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EACzE,CAAC,EACD,CAACP,IAAI,EAAEC,cAAc,CACzB,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"file":"useIdGenerator.js","sources":["../src/useIdGenerator.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useParentProperty } from \"~/Properties.js\";\n\nconst keywords = [\"$first\", \"$last\"];\n\nexport function useIdGenerator(name: string) {\n const parentProperty = useParentProperty();\n\n return useCallback(\n (...parts: string[]) => {\n if (keywords.includes(parts[0])) {\n return parts[0];\n }\n return [parentProperty?.id, name, ...parts].filter(Boolean).join(\":\");\n },\n [name, parentProperty]\n );\n}\n"],"names":["keywords","useIdGenerator","name","parentProperty","useParentProperty","useCallback","parts","Boolean"],"mappings":";;AAGA,MAAMA,WAAW;IAAC;IAAU;CAAQ;AAE7B,SAASC,eAAeC,IAAY;IACvC,MAAMC,iBAAiBC;IAEvB,OAAOC,YACH,CAAC,GAAGC;QACA,IAAIN,SAAS,QAAQ,CAACM,KAAK,CAAC,EAAE,GAC1B,OAAOA,KAAK,CAAC,EAAE;QAEnB,OAAO;YAACH,gBAAgB;YAAID;eAASI;SAAM,CAAC,MAAM,CAACC,SAAS,IAAI,CAAC;IACrE,GACA;QAACL;QAAMC;KAAe;AAE9B"}
package/utils.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- import type { Property } from "./Properties";
1
+ import type { Property } from "./Properties.js";
2
2
  export declare function toObject<T = unknown>(properties: Property[]): T;
3
3
  export declare function getUniqueId(length?: number): string;
package/utils.js CHANGED
@@ -1,47 +1,48 @@
1
1
  import { customAlphabet } from "nanoid";
2
2
  const nanoid = customAlphabet("1234567890abcdef");
3
- const sortPropertiesToTheTop = (a, b) => {
4
- if (a.$isFirst && b.$isFirst) {
5
- return -1;
6
- }
7
- return Number(b.$isFirst) - Number(a.$isFirst);
3
+ const sortPropertiesToTheTop = (a, b)=>{
4
+ if (a.$isFirst && b.$isFirst) return -1;
5
+ return Number(b.$isFirst) - Number(a.$isFirst);
8
6
  };
9
- const sortPropertiesToTheBottom = (a, b) => {
10
- if (a.$isLast && b.$isLast) {
11
- return 1;
12
- }
13
- return Number(a.$isLast) - Number(b.$isLast);
14
- };
15
- const sortProperties = properties => {
16
- return properties.sort(sortPropertiesToTheTop).sort(sortPropertiesToTheBottom);
7
+ const sortPropertiesToTheBottom = (a, b)=>{
8
+ if (a.$isLast && b.$isLast) return 1;
9
+ return Number(a.$isLast) - Number(b.$isLast);
17
10
  };
11
+ const sortProperties = (properties)=>properties.sort(sortPropertiesToTheTop).sort(sortPropertiesToTheBottom);
18
12
  function buildRoots(roots, properties) {
19
- const sortedRoots = sortProperties(roots);
20
- const obj = sortedRoots.reduce((acc, item) => {
21
- const isArray = item.array === true || sortedRoots.filter(r => r.name === item.name).length > 1;
22
- return {
23
- ...acc,
24
- [item.name]: isArray ? [] : {}
25
- };
26
- }, {});
27
- sortedRoots.forEach(root => {
28
- const isArray = root.array === true || Array.isArray(obj[root.name]);
29
- if (root.value !== undefined) {
30
- obj[root.name] = isArray ? [...obj[root.name], root.value] : root.value;
31
- return;
32
- }
33
- const nextRoots = properties.filter(p => p.parent === root.id);
34
- const value = buildRoots(nextRoots, properties);
35
- obj[root.name] = isArray ? [...obj[root.name], value] : value;
36
- });
37
- return obj;
13
+ const sortedRoots = sortProperties(roots);
14
+ const obj = sortedRoots.reduce((acc, item)=>{
15
+ const isArray = true === item.array || sortedRoots.filter((r)=>r.name === item.name).length > 1;
16
+ return {
17
+ ...acc,
18
+ [item.name]: isArray ? [] : {}
19
+ };
20
+ }, {});
21
+ sortedRoots.forEach((root)=>{
22
+ const isArray = true === root.array || Array.isArray(obj[root.name]);
23
+ if (void 0 !== root.value) {
24
+ obj[root.name] = isArray ? [
25
+ ...obj[root.name],
26
+ root.value
27
+ ] : root.value;
28
+ return;
29
+ }
30
+ const nextRoots = properties.filter((p)=>p.parent === root.id);
31
+ const value = buildRoots(nextRoots, properties);
32
+ obj[root.name] = isArray ? [
33
+ ...obj[root.name],
34
+ value
35
+ ] : value;
36
+ });
37
+ return obj;
38
38
  }
39
- export function toObject(properties) {
40
- const roots = properties.filter(prop => prop.parent === "");
41
- return buildRoots(roots, properties);
39
+ function toObject(properties) {
40
+ const roots = properties.filter((prop)=>"" === prop.parent);
41
+ return buildRoots(roots, properties);
42
42
  }
43
- export function getUniqueId(length = 12) {
44
- return nanoid(length);
43
+ function getUniqueId(length = 12) {
44
+ return nanoid(length);
45
45
  }
46
+ export { getUniqueId, toObject };
46
47
 
47
48
  //# sourceMappingURL=utils.js.map
package/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["customAlphabet","nanoid","sortPropertiesToTheTop","a","b","$isFirst","Number","sortPropertiesToTheBottom","$isLast","sortProperties","properties","sort","buildRoots","roots","sortedRoots","obj","reduce","acc","item","isArray","array","filter","r","name","length","forEach","root","Array","value","undefined","nextRoots","p","parent","id","toObject","prop","getUniqueId"],"sources":["utils.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\nconst nanoid = customAlphabet(\"1234567890abcdef\");\nimport type { Property } from \"./Properties\";\n\nconst sortPropertiesToTheTop = (a: Property, b: Property) => {\n if (a.$isFirst && b.$isFirst) {\n return -1;\n }\n\n return Number(b.$isFirst) - Number(a.$isFirst);\n};\n\nconst sortPropertiesToTheBottom = (a: Property, b: Property) => {\n if (a.$isLast && b.$isLast) {\n return 1;\n }\n\n return Number(a.$isLast) - Number(b.$isLast);\n};\n\nconst sortProperties = (properties: Property[]) => {\n return properties.sort(sortPropertiesToTheTop).sort(sortPropertiesToTheBottom);\n};\n\nfunction buildRoots(roots: Property[], properties: Property[]) {\n const sortedRoots = sortProperties(roots);\n const obj: Record<string, unknown> = sortedRoots.reduce((acc, item) => {\n const isArray =\n item.array === true || sortedRoots.filter(r => r.name === item.name).length > 1;\n return { ...acc, [item.name]: isArray ? [] : {} };\n }, {});\n\n sortedRoots.forEach(root => {\n const isArray = root.array === true || Array.isArray(obj[root.name]);\n if (root.value !== undefined) {\n obj[root.name] = isArray ? [...(obj[root.name] as Array<any>), root.value] : root.value;\n return;\n }\n\n const nextRoots = properties.filter(p => p.parent === root.id);\n const value = buildRoots(nextRoots, properties);\n obj[root.name] = isArray ? [...(obj[root.name] as Property[]), value] : value;\n });\n\n return obj;\n}\n\nexport function toObject<T = unknown>(properties: Property[]): T {\n const roots = properties.filter(prop => prop.parent === \"\");\n return buildRoots(roots, properties) as T;\n}\n\nexport function getUniqueId(length = 12) {\n return nanoid(length);\n}\n"],"mappings":"AAAA,SAASA,cAAc,QAAQ,QAAQ;AACvC,MAAMC,MAAM,GAAGD,cAAc,CAAC,kBAAkB,CAAC;AAGjD,MAAME,sBAAsB,GAAGA,CAACC,CAAW,EAAEC,CAAW,KAAK;EACzD,IAAID,CAAC,CAACE,QAAQ,IAAID,CAAC,CAACC,QAAQ,EAAE;IAC1B,OAAO,CAAC,CAAC;EACb;EAEA,OAAOC,MAAM,CAACF,CAAC,CAACC,QAAQ,CAAC,GAAGC,MAAM,CAACH,CAAC,CAACE,QAAQ,CAAC;AAClD,CAAC;AAED,MAAME,yBAAyB,GAAGA,CAACJ,CAAW,EAAEC,CAAW,KAAK;EAC5D,IAAID,CAAC,CAACK,OAAO,IAAIJ,CAAC,CAACI,OAAO,EAAE;IACxB,OAAO,CAAC;EACZ;EAEA,OAAOF,MAAM,CAACH,CAAC,CAACK,OAAO,CAAC,GAAGF,MAAM,CAACF,CAAC,CAACI,OAAO,CAAC;AAChD,CAAC;AAED,MAAMC,cAAc,GAAIC,UAAsB,IAAK;EAC/C,OAAOA,UAAU,CAACC,IAAI,CAACT,sBAAsB,CAAC,CAACS,IAAI,CAACJ,yBAAyB,CAAC;AAClF,CAAC;AAED,SAASK,UAAUA,CAACC,KAAiB,EAAEH,UAAsB,EAAE;EAC3D,MAAMI,WAAW,GAAGL,cAAc,CAACI,KAAK,CAAC;EACzC,MAAME,GAA4B,GAAGD,WAAW,CAACE,MAAM,CAAC,CAACC,GAAG,EAAEC,IAAI,KAAK;IACnE,MAAMC,OAAO,GACTD,IAAI,CAACE,KAAK,KAAK,IAAI,IAAIN,WAAW,CAACO,MA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C;AAEA,OAAO,SAAS0B,WAAWA,CAACZ,MAAM,GAAG,EAAE,EAAE;EACrC,OAAOvB,MAAM,CAACuB,MAAM,CAAC;AACzB","ignoreList":[]}
1
+ {"version":3,"file":"utils.js","sources":["../src/utils.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\nconst nanoid = customAlphabet(\"1234567890abcdef\");\nimport type { Property } from \"./Properties.js\";\n\nconst sortPropertiesToTheTop = (a: Property, b: Property) => {\n if (a.$isFirst && b.$isFirst) {\n return -1;\n }\n\n return Number(b.$isFirst) - Number(a.$isFirst);\n};\n\nconst sortPropertiesToTheBottom = (a: Property, b: Property) => {\n if (a.$isLast && b.$isLast) {\n return 1;\n }\n\n return Number(a.$isLast) - Number(b.$isLast);\n};\n\nconst sortProperties = (properties: Property[]) => {\n return properties.sort(sortPropertiesToTheTop).sort(sortPropertiesToTheBottom);\n};\n\nfunction buildRoots(roots: Property[], properties: Property[]) {\n const sortedRoots = sortProperties(roots);\n const obj: Record<string, unknown> = sortedRoots.reduce((acc, item) => {\n const isArray =\n item.array === true || sortedRoots.filter(r => r.name === item.name).length > 1;\n return { ...acc, [item.name]: isArray ? [] : {} };\n }, {});\n\n sortedRoots.forEach(root => {\n const isArray = root.array === true || Array.isArray(obj[root.name]);\n if (root.value !== undefined) {\n obj[root.name] = isArray ? [...(obj[root.name] as Array<any>), root.value] : root.value;\n return;\n }\n\n const nextRoots = properties.filter(p => p.parent === root.id);\n const value = buildRoots(nextRoots, properties);\n obj[root.name] = isArray ? [...(obj[root.name] as Property[]), value] : value;\n });\n\n return obj;\n}\n\nexport function toObject<T = unknown>(properties: Property[]): T {\n const roots = properties.filter(prop => prop.parent === \"\");\n return buildRoots(roots, properties) as T;\n}\n\nexport function getUniqueId(length = 12) {\n return nanoid(length);\n}\n"],"names":["nanoid","customAlphabet","sortPropertiesToTheTop","a","b","Number","sortPropertiesToTheBottom","sortProperties","properties","buildRoots","roots","sortedRoots","obj","acc","item","isArray","r","root","Array","undefined","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,KAAK,EAAE;QAC7D,MAAMK,QAAQb,WAAWW,WAAWZ;QACpCI,GAAG,CAACK,KAAK,IAAI,CAAC,GAAGF,UAAU;eAAKH,GAAG,CAACK,KAAK,IAAI,CAAC;YAAiBK;SAAM,GAAGA;IAC5E;IAEA,OAAOV;AACX;AAEO,SAASW,SAAsBf,UAAsB;IACxD,MAAME,QAAQF,WAAW,MAAM,CAACgB,CAAAA,OAAQA,AAAgB,OAAhBA,KAAK,MAAM;IACnD,OAAOf,WAAWC,OAAOF;AAC7B;AAEO,SAASiB,YAAYC,SAAS,EAAE;IACnC,OAAO1B,OAAO0B;AAClB"}
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./utils\";\nexport * from \"./Properties\";\nexport * from \"./useDebugConfig\";\nexport * from \"./useIdGenerator\";\nexport * from \"./createConfigurableComponent\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA","ignoreList":[]}