@webiny/react-properties 6.3.0 → 6.4.0-beta.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.
@@ -1 +1 @@
1
- {"version":3,"names":["debounce","PropertyStore","map","Map","order","queue","listeners","Set","priorities","positioned","lookup","scheduleFlush","processQueue","allProperties","filter","id","has","get","subscribe","listener","add","delete","getChildrenOf","parentId","Array","from","values","p","parent","getById","registerLookup","property","existing","set","addProperty","options","push","type","removeProperty","replaceProperty","oldId","newProperty","length","ops","splice","sort","a","b","pa","priority","pb","op","executeAdd","executeRemove","executeReplace","properties","after","before","exists","reposition","insertAfter","insertBefore","oid","idx","indexOf","removeDescendants","endsWith","unshift","targetIdx","targetId","position","children","child"],"sources":["PropertyStore.ts"],"sourcesContent":["import debounce from \"lodash/debounce.js\";\nimport type { Property } from \"../Properties.js\";\n\ninterface AddPropertyOptions {\n after?: string;\n before?: string;\n priority?: number;\n}\n\ntype Operation =\n | { type: \"add\"; property: Property; options: AddPropertyOptions }\n | { type: \"remove\"; id: string }\n | { type: \"replace\"; oldId: string; newProperty: Property };\n\ntype Listener = (properties: Property[]) => void;\n\nexport class PropertyStore {\n private map = new Map<string, Property>();\n private order: string[] = [];\n private queue: Operation[] = [];\n private listeners = new Set<Listener>();\n private priorities = new Map<string, number>();\n /** Properties that were explicitly positioned via before/after. */\n private positioned = new Set<string>();\n\n /**\n * Synchronous lookup map — written immediately on addProperty (before debounce),\n * so useAncestor can find properties during render.\n */\n private lookup = new Map<string, Property>();\n\n private scheduleFlush = debounce(() => {\n this.processQueue();\n }, 0);\n\n get allProperties(): Property[] {\n return this.order.filter(id => this.map.has(id)).map(id => this.map.get(id)!);\n }\n\n subscribe(listener: Listener): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n /**\n * Returns properties that are children of the given parent ID.\n * Reads from the synchronous lookup map, so it works during render\n * before the debounced queue has flushed.\n */\n getChildrenOf(parentId: string): Property[] {\n return Array.from(this.lookup.values()).filter(p => p.parent === parentId);\n }\n\n /**\n * Find a property by ID from the synchronous lookup map.\n */\n getById(id: string): Property | undefined {\n return this.lookup.get(id);\n }\n\n /**\n * Register a property in the synchronous lookup map during render,\n * so useAncestor can find it before the debounced queue flushes.\n */\n registerLookup(property: Property): void {\n if (this.lookup.has(property.id)) {\n const existing = this.lookup.get(property.id)!;\n this.lookup.set(property.id, { ...existing, ...property });\n } else {\n this.lookup.set(property.id, property);\n }\n }\n\n addProperty(property: Property, options: AddPropertyOptions = {}): void {\n this.registerLookup(property);\n this.queue.push({ type: \"add\", property, options });\n this.scheduleFlush();\n }\n\n removeProperty(id: string): void {\n this.lookup.delete(id);\n this.queue.push({ type: \"remove\", id });\n this.scheduleFlush();\n }\n\n replaceProperty(oldId: string, newProperty: Property): void {\n this.lookup.delete(oldId);\n this.lookup.set(newProperty.id, newProperty);\n this.queue.push({ type: \"replace\", oldId, newProperty });\n this.scheduleFlush();\n }\n\n private processQueue(): void {\n if (this.queue.length === 0) {\n return;\n }\n\n const ops = this.queue.splice(0);\n\n // Stable-sort operations so that \"add\" ops with lower priority numbers\n // are processed first. Non-add operations and adds with default priority (0)\n // keep their original order.\n ops.sort((a, b) => {\n const pa = a.type === \"add\" ? (a.options.priority ?? 0) : 0;\n const pb = b.type === \"add\" ? (b.options.priority ?? 0) : 0;\n return pa - pb;\n });\n\n for (const op of ops) {\n switch (op.type) {\n case \"add\":\n this.executeAdd(op.property, op.options);\n break;\n case \"remove\":\n this.executeRemove(op.id);\n break;\n case \"replace\":\n this.executeReplace(op.oldId, op.newProperty);\n break;\n }\n }\n\n // Stable-sort the order array by priority, but only for properties\n // that were NOT explicitly positioned via before/after. Explicitly\n // positioned properties keep their placement.\n this.order.sort((a, b) => {\n if (this.positioned.has(a) || this.positioned.has(b)) {\n return 0;\n }\n return (this.priorities.get(a) ?? 0) - (this.priorities.get(b) ?? 0);\n });\n\n const properties = this.allProperties;\n for (const listener of this.listeners) {\n listener(properties);\n }\n }\n\n private executeAdd(property: Property, options: AddPropertyOptions): void {\n if (options.after || options.before) {\n this.positioned.add(property.id);\n }\n\n const exists = this.map.has(property.id);\n\n if (exists) {\n // Merge into existing property. Keep the original priority so\n // that a secondary config overriding a primary property doesn't\n // cause the re-sort to move it after all primary properties.\n const existing = this.map.get(property.id)!;\n this.map.set(property.id, { ...existing, ...property });\n\n if (options.after) {\n this.reposition(property.id, options.after, \"after\");\n } else if (options.before) {\n this.reposition(property.id, options.before, \"before\");\n }\n return;\n }\n\n this.map.set(property.id, property);\n // Set priority only for new properties — not merges (handled above).\n this.priorities.set(property.id, options.priority ?? 0);\n\n if (options.after) {\n this.insertAfter(property.id, options.after);\n } else if (options.before) {\n this.insertBefore(property.id, options.before);\n } else {\n this.order.push(property.id);\n }\n }\n\n private executeRemove(id: string): void {\n if (!this.map.has(id)) {\n return;\n }\n this.map.delete(id);\n this.priorities.delete(id);\n this.positioned.delete(id);\n this.order = this.order.filter(oid => oid !== id);\n // Note: we intentionally do NOT call removeDescendants here.\n // React's component lifecycle ensures that when a parent Property\n // unmounts, all child Properties unmount too — each triggering its\n // own removeProperty call. Calling removeDescendants would wipe\n // children that belong to OTHER still-mounted configs sharing the\n // same parent ID (e.g., id=\"pageSettings\" used by both primary\n // and secondary configs).\n }\n\n private executeReplace(oldId: string, newProperty: Property): void {\n const idx = this.order.indexOf(oldId);\n if (idx === -1) {\n return;\n }\n\n this.map.delete(oldId);\n this.map.set(newProperty.id, newProperty);\n this.order[idx] = newProperty.id;\n this.removeDescendants(oldId);\n }\n\n private insertBefore(id: string, before: string): void {\n if (before.endsWith(\"$first\")) {\n this.order.unshift(id);\n return;\n }\n const targetIdx = this.order.indexOf(before);\n if (targetIdx === -1) {\n this.order.push(id);\n return;\n }\n this.order.splice(targetIdx, 0, id);\n }\n\n private insertAfter(id: string, after: string): void {\n if (after.endsWith(\"$last\")) {\n this.order.push(id);\n return;\n }\n const targetIdx = this.order.indexOf(after);\n if (targetIdx === -1) {\n this.order.push(id);\n return;\n }\n this.order.splice(targetIdx + 1, 0, id);\n }\n\n private reposition(id: string, targetId: string, position: \"before\" | \"after\"): void {\n this.order = this.order.filter(oid => oid !== id);\n\n if (position === \"before\") {\n this.insertBefore(id, targetId);\n } else {\n this.insertAfter(id, targetId);\n }\n }\n\n private removeDescendants(parentId: string): void {\n const children = Array.from(this.map.values()).filter(p => p.parent === parentId);\n for (const child of children) {\n this.map.delete(child.id);\n this.order = this.order.filter(oid => oid !== child.id);\n this.removeDescendants(child.id);\n }\n }\n}\n"],"mappings":"AAAA,OAAOA,QAAQ,MAAM,oBAAoB;AAgBzC,OAAO,MAAMC,aAAa,CAAC;EACfC,GAAG,GAAG,IAAIC,GAAG,CAAmB,CAAC;EACjCC,KAAK,GAAa,EAAE;EACpBC,KAAK,GAAgB,EAAE;EACvBC,SAAS,GAAG,IAAIC,GAAG,CAAW,CAAC;EAC/BC,UAAU,GAAG,IAAIL,GAAG,CAAiB,CAAC;EAC9C;EACQM,UAAU,GAAG,IAAIF,GAAG,CAAS,CAAC;;EAEtC;AACJ;AACA;AACA;EACYG,MAAM,GAAG,IAAIP,GAAG,CAAmB,CAAC;EAEpCQ,aAAa,GAAGX,QAAQ,CAAC,MAAM;IACnC,IAAI,CAACY,YAAY,CAAC,CAAC;EACvB,CAAC,EAAE,CAAC,CAAC;EAEL,IAAIC,aAAaA,CAAA,EAAe;IAC5B,OAAO,IAAI,CAACT,KAAK,CAACU,MAAM,CAACC,EAAE,IAAI,IAAI,CAACb,GAAG,CAACc,GAAG,CAACD,EAAE,CAAC,CAAC,CAACb,GAAG,CAACa,EAAE,IAAI,IAAI,CAACb,GAAG,CAACe,GAAG,CAACF,EAAE,CAAE,CAAC;EACjF;EAEAG,SAASA,CAACC,QAAkB,EAAc;IACtC,IAAI,CAACb,SAAS,CAACc,GAAG,CAACD,QAAQ,CAAC;IAC5B,OAAO,MAAM;MACT,IAAI,CAACb,SAAS,CAACe,MAAM,CAACF,QAAQ,CAAC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ent":["import debounce from \"lodash/debounce.js\";\nimport type { Property } from \"../Properties.js\";\n\ninterface AddPropertyOptions {\n after?: string;\n before?: string;\n priority?: number;\n}\n\ntype Operation =\n | { type: \"add\"; property: Property; options: AddPropertyOptions }\n | { type: \"remove\"; id: string }\n | { type: \"replace\"; oldId: string; newProperty: Property };\n\ntype Listener = (properties: Property[]) => void;\n\nexport class PropertyStore {\n private map = new Map<string, Property>();\n private order: string[] = [];\n private queue: Operation[] = [];\n private listeners = new Set<Listener>();\n private priorities = new Map<string, number>();\n /** Properties that were explicitly positioned via before/after. */\n private positioned = new Set<string>();\n\n /**\n * Synchronous lookup map — written immediately on addProperty (before debounce),\n * so useAncestor can find properties during render.\n */\n private lookup = new Map<string, Property>();\n\n private scheduleFlush = debounce(() => {\n this.processQueue();\n }, 0);\n\n get allProperties(): Property[] {\n return this.order.filter(id => this.map.has(id)).map(id => this.map.get(id)!);\n }\n\n subscribe(listener: Listener): () => void {\n this.listeners.add(listener);\n return () => {\n this.listeners.delete(listener);\n };\n }\n\n /**\n * Returns properties that are children of the given parent ID.\n * Reads from the synchronous lookup map, so it works during render\n * before the debounced queue has flushed.\n */\n getChildrenOf(parentId: string): Property[] {\n return Array.from(this.lookup.values()).filter(p => p.parent === parentId);\n }\n\n /**\n * Find a property by ID from the synchronous lookup map.\n */\n getById(id: string): Property | undefined {\n return this.lookup.get(id);\n }\n\n /**\n * Register a property in the synchronous lookup map during render,\n * so useAncestor can find it before the debounced queue flushes.\n */\n registerLookup(property: Property): void {\n if (this.lookup.has(property.id)) {\n const existing = this.lookup.get(property.id)!;\n this.lookup.set(property.id, { ...existing, ...property });\n } else {\n this.lookup.set(property.id, property);\n }\n }\n\n addProperty(property: Property, options: AddPropertyOptions = {}): void {\n this.registerLookup(property);\n this.queue.push({ type: \"add\", property, options });\n this.scheduleFlush();\n }\n\n removeProperty(id: string): void {\n this.lookup.delete(id);\n this.queue.push({ type: \"remove\", id });\n this.scheduleFlush();\n }\n\n replaceProperty(oldId: string, newProperty: Property): void {\n this.lookup.delete(oldId);\n this.lookup.set(newProperty.id, newProperty);\n this.queue.push({ type: \"replace\", oldId, newProperty });\n this.scheduleFlush();\n }\n\n private processQueue(): void {\n if (this.queue.length === 0) {\n return;\n }\n\n const ops = this.queue.splice(0);\n\n // Stable-sort operations so that \"add\" ops with lower priority numbers\n // are processed first. Non-add operations and adds with default priority (0)\n // keep their original order.\n ops.sort((a, b) => {\n const pa = a.type === \"add\" ? (a.options.priority ?? 0) : 0;\n const pb = b.type === \"add\" ? (b.options.priority ?? 0) : 0;\n return pa - pb;\n });\n\n for (const op of ops) {\n switch (op.type) {\n case \"add\":\n this.executeAdd(op.property, op.options);\n break;\n case \"remove\":\n this.executeRemove(op.id);\n break;\n case \"replace\":\n this.executeReplace(op.oldId, op.newProperty);\n break;\n }\n }\n\n // Stable-sort the order array by priority, but only for properties\n // that were NOT explicitly positioned via before/after. Explicitly\n // positioned properties keep their placement.\n this.order.sort((a, b) => {\n if (this.positioned.has(a) || this.positioned.has(b)) {\n return 0;\n }\n return (this.priorities.get(a) ?? 0) - (this.priorities.get(b) ?? 0);\n });\n\n const properties = this.allProperties;\n for (const listener of this.listeners) {\n listener(properties);\n }\n }\n\n private executeAdd(property: Property, options: AddPropertyOptions): void {\n if (options.after || options.before) {\n this.positioned.add(property.id);\n }\n\n const exists = this.map.has(property.id);\n\n if (exists) {\n // Merge into existing property. Keep the original priority so\n // that a secondary config overriding a primary property doesn't\n // cause the re-sort to move it after all primary properties.\n const existing = this.map.get(property.id)!;\n this.map.set(property.id, { ...existing, ...property });\n\n if (options.after) {\n this.reposition(property.id, options.after, \"after\");\n } else if (options.before) {\n this.reposition(property.id, options.before, \"before\");\n }\n return;\n }\n\n this.map.set(property.id, property);\n // Set priority only for new properties — not merges (handled above).\n this.priorities.set(property.id, options.priority ?? 0);\n\n if (options.after) {\n this.insertAfter(property.id, options.after);\n } else if (options.before) {\n this.insertBefore(property.id, options.before);\n } else {\n this.order.push(property.id);\n }\n }\n\n private executeRemove(id: string): void {\n if (!this.map.has(id)) {\n return;\n }\n this.map.delete(id);\n this.priorities.delete(id);\n this.positioned.delete(id);\n this.order = this.order.filter(oid => oid !== id);\n // Note: we intentionally do NOT call removeDescendants here.\n // React's component lifecycle ensures that when a parent Property\n // unmounts, all child Properties unmount too — each triggering its\n // own removeProperty call. Calling removeDescendants would wipe\n // children that belong to OTHER still-mounted configs sharing the\n // same parent ID (e.g., id=\"pageSettings\" used by both primary\n // and secondary configs).\n }\n\n private executeReplace(oldId: string, newProperty: Property): void {\n const idx = this.order.indexOf(oldId);\n if (idx === -1) {\n return;\n }\n\n this.map.delete(oldId);\n this.map.set(newProperty.id, newProperty);\n this.order[idx] = newProperty.id;\n this.removeDescendants(oldId);\n }\n\n private insertBefore(id: string, before: string): void {\n if (before.endsWith(\"$first\")) {\n this.order.unshift(id);\n return;\n }\n const targetIdx = this.order.indexOf(before);\n if (targetIdx === -1) {\n this.order.push(id);\n return;\n }\n this.order.splice(targetIdx, 0, id);\n }\n\n private insertAfter(id: string, after: string): void {\n if (after.endsWith(\"$last\")) {\n this.order.push(id);\n return;\n }\n const targetIdx = this.order.indexOf(after);\n if (targetIdx === -1) {\n this.order.push(id);\n return;\n }\n this.order.splice(targetIdx + 1, 0, id);\n }\n\n private reposition(id: string, targetId: string, position: \"before\" | \"after\"): void {\n this.order = this.order.filter(oid => oid !== id);\n\n if (position === \"before\") {\n this.insertBefore(id, targetId);\n } else {\n this.insertAfter(id, targetId);\n }\n }\n\n private removeDescendants(parentId: string): void {\n const children = Array.from(this.map.values()).filter(p => p.parent === parentId);\n for (const child of children) {\n this.map.delete(child.id);\n this.order = this.order.filter(oid => oid !== child.id);\n this.removeDescendants(child.id);\n }\n }\n}\n"],"names":["PropertyStore","id","listener","parentId","Array","p","property","existing","options","oldId","newProperty","ops","a","b","pa","pb","op","properties","exists","oid","idx","before","targetIdx","after","targetId","position","children","child","Map","Set","debounce"],"mappings":";AAgBO,MAAMA;IAmBT,IAAI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AC,KAAK,CAAC,MAAM,CAACN,CAAAA,MAAOA,QAAQlB;QAE9C,IAAIwB,AAAa,aAAbA,UACA,IAAI,CAAC,YAAY,CAACxB,IAAIuB;aAEtB,IAAI,CAAC,WAAW,CAACvB,IAAIuB;IAE7B;IAEQ,kBAAkBrB,QAAgB,EAAQ;QAC9C,MAAMuB,WAAWtB,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,MAAM,CAACC,CAAAA,IAAKA,EAAE,MAAM,KAAKF;QACxE,KAAK,MAAMwB,SAASD,SAAU;YAC1B,IAAI,CAAC,GAAG,CAAC,MAAM,CAACC,MAAM,EAAE;YACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAACR,CAAAA,MAAOA,QAAQQ,MAAM,EAAE;YACtD,IAAI,CAAC,iBAAiB,CAACA,MAAM,EAAE;QACnC;IACJ;;aAtOQ,GAAG,GAAG,IAAIC;aACV,KAAK,GAAa,EAAE;aACpB,KAAK,GAAgB,EAAE;aACvB,SAAS,GAAG,IAAIC;aAChB,UAAU,GAAG,IAAID;QACwC,KACzD,UAAU,GAAG,IAAIC;QAKxB,KACO,MAAM,GAAG,IAAID;aAEb,aAAa,GAAGE,SAAS;YAC7B,IAAI,CAAC,YAAY;QACrB,GAAG;;AAuNP"}
package/domain/index.js CHANGED
@@ -1,3 +1 @@
1
1
  export { PropertyStore } from "./PropertyStore.js";
2
-
3
- //# sourceMappingURL=index.js.map
package/index.js CHANGED
@@ -5,5 +5,3 @@ export * from "./useIdGenerator.js";
5
5
  export * from "./createConfigurableComponent.js";
6
6
  export * from "./domain/index.js";
7
7
  export { DevToolsSection } from "./DevToolsSection.js";
8
-
9
- //# sourceMappingURL=index.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/react-properties",
3
- "version": "6.3.0",
3
+ "version": "6.4.0-beta.0",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -15,20 +15,20 @@
15
15
  "license": "MIT",
16
16
  "dependencies": {
17
17
  "@types/react": "18.3.28",
18
- "@webiny/react-composition": "6.3.0",
18
+ "@webiny/react-composition": "6.4.0-beta.0",
19
19
  "lodash": "4.18.1",
20
20
  "nanoid": "5.1.11",
21
21
  "react": "18.3.1"
22
22
  },
23
23
  "devDependencies": {
24
24
  "@testing-library/react": "16.3.2",
25
- "@webiny/build-tools": "6.3.0",
26
- "oxfmt": "0.47.0",
27
- "vitest": "4.1.5"
25
+ "@webiny/build-tools": "6.4.0-beta.0",
26
+ "oxfmt": "0.49.0",
27
+ "vitest": "4.1.6"
28
28
  },
29
29
  "publishConfig": {
30
30
  "access": "public",
31
31
  "directory": "dist"
32
32
  },
33
- "gitHead": "7cefe15431dbd65504e1f58147dc9e55bcbfa693"
33
+ "gitHead": "a545d7529828af07d08d49c3da1bcb967483b9ce"
34
34
  }
package/useDebugConfig.js CHANGED
@@ -1,53 +1,45 @@
1
1
  import { useEffect } from "react";
2
2
  import { toObject } from "./utils.js";
3
- export function getHook() {
4
- if (!window.__WEBINY_DEVTOOLS_HOOK__) {
5
- window.__WEBINY_DEVTOOLS_HOOK__ = {
6
- revision: 0,
7
- configs: {},
8
- sections: {}
3
+ function getHook() {
4
+ if (!window.__WEBINY_DEVTOOLS_HOOK__) window.__WEBINY_DEVTOOLS_HOOK__ = {
5
+ revision: 0,
6
+ configs: {},
7
+ sections: {}
9
8
  };
10
- }
11
- return window.__WEBINY_DEVTOOLS_HOOK__;
9
+ return window.__WEBINY_DEVTOOLS_HOOK__;
12
10
  }
13
- export function useDebugConfig(name, properties) {
14
- useEffect(() => {
15
- if (process.env.NODE_ENV !== "development") {
16
- return;
17
- }
18
-
19
- // Legacy console.log support
20
- const configs = window.__debugConfigs ?? {};
21
- configs[name] = () => console.log(toObject(properties));
22
- window.__debugConfigs = configs;
23
-
24
- // DevTools hook: structured data for the Chrome extension
25
- const hook = getHook();
26
- hook.configs[name] = {
27
- properties: properties.map(p => ({
28
- id: p.id,
29
- parent: p.parent,
30
- name: p.name,
31
- value: p.value,
32
- array: p.array
33
- })),
34
- config: toObject(properties),
35
- updatedAt: Date.now()
36
- };
37
- hook.revision++;
38
- return () => {
39
- // Legacy cleanup
40
- const configs = window.__debugConfigs ?? {};
41
- delete configs[name];
42
- window.__debugConfigs = configs;
43
-
44
- // DevTools hook cleanup
45
- if (window.__WEBINY_DEVTOOLS_HOOK__) {
46
- delete window.__WEBINY_DEVTOOLS_HOOK__.configs[name];
47
- window.__WEBINY_DEVTOOLS_HOOK__.revision++;
48
- }
49
- };
50
- }, [properties]);
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
+ ]);
51
42
  }
43
+ export { getHook, useDebugConfig };
52
44
 
53
45
  //# sourceMappingURL=useDebugConfig.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useEffect","toObject","getHook","window","__WEBINY_DEVTOOLS_HOOK__","revision","configs","sections","useDebugConfig","name","properties","process","env","NODE_ENV","__debugConfigs","console","log","hook","map","p","id","parent","value","array","config","updatedAt","Date","now"],"sources":["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"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,QAAQ;AAkCjB,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G,IAAI,CAAC;MACpBN,MAAM,CAACW,cAAc,GAAGR,OAAO;;MAE/B;MACA,IAAIH,MAAM,CAACC,wBAAwB,EAAE;QACjC,OAAOD,MAAM,CAACC,wBAAwB,CAACE,OAAO,CAACG,IAAI,CAAC;QACpDN,MAAM,CAACC,wBAAwB,CAACC,QAAQ,EAAE;MAC9C;IACJ,CAAC;EACL,CAAC,EAAE,CAACK,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
2
  import { useParentProperty } from "./Properties.js";
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]);
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.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"],"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.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.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"],"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,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,CAAgB,EAAEK,KAAK,CAAC,GAAGA,KAAK;EACjF,CAAC,CAAC;EAEF,OAAOb,GAAG;AACd;AAEA,OAAO,SAASmB,QAAQA,CAAcxB,UAAsB,EAAK;EAC7D,MAAMG,KAAK,GAAGH,UAAU,CAACW,MAAM,CAACc,IAAI,IAAIA,IAAI,CAACH,MAAM,KAAK,EAAE,CAAC;EAC3D,OAAOpB,UAAU,CAACC,KAAK,EAAEH,UAAU,CAAC;AACxC;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","nextRoots","p","value","toObject","prop","getUniqueId","length"],"mappings":";AACA,MAAMA,SAASC,eAAe;AAG9B,MAAMC,yBAAyB,CAACC,GAAaC;IACzC,IAAID,EAAE,QAAQ,IAAIC,EAAE,QAAQ,EACxB,OAAO;IAGX,OAAOC,OAAOD,EAAE,QAAQ,IAAIC,OAAOF,EAAE,QAAQ;AACjD;AAEA,MAAMG,4BAA4B,CAACH,GAAaC;IAC5C,IAAID,EAAE,OAAO,IAAIC,EAAE,OAAO,EACtB,OAAO;IAGX,OAAOC,OAAOF,EAAE,OAAO,IAAIE,OAAOD,EAAE,OAAO;AAC/C;AAEA,MAAMG,iBAAiB,CAACC,aACbA,WAAW,IAAI,CAACN,wBAAwB,IAAI,CAACI;AAGxD,SAASG,WAAWC,KAAiB,EAAEF,UAAsB;IACzD,MAAMG,cAAcJ,eAAeG;IACnC,MAAME,MAA+BD,YAAY,MAAM,CAAC,CAACE,KAAKC;QAC1D,MAAMC,UACFD,AAAe,SAAfA,KAAK,KAAK,IAAaH,YAAY,MAAM,CAACK,CAAAA,IAAKA,EAAE,IAAI,KAAKF,KAAK,IAAI,EAAE,MAAM,GAAG;QAClF,OAAO;YAAE,GAAGD,GAAG;YAAE,CAACC,KAAK,IAAI,CAAC,EAAEC,UAAU,EAAE,GAAG,CAAC;QAAE;IACpD,GAAG,CAAC;IAEJJ,YAAY,OAAO,CAACM,CAAAA;QAChB,MAAMF,UAAUE,AAAe,SAAfA,KAAK,KAAK,IAAaC,MAAM,OAAO,CAACN,GAAG,CAACK,KAAK,IAAI,CAAC;QACnE,IAAIA,AAAeE,WAAfF,KAAK,KAAK,EAAgB;YAC1BL,GAAG,CAACK,KAAK,IAAI,CAAC,GAAGF,UAAU;mBAAKH,GAAG,CAACK,KAAK,IAAI,CAAC;gBAAiBA,KAAK,KAAK;aAAC,GAAGA,KAAK,KAAK;YACvF;QACJ;QAEA,MAAMG,YAAYZ,WAAW,MAAM,CAACa,CAAAA,IAAKA,EAAE,MAAM,KAAKJ,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"}
@@ -1 +0,0 @@
1
- {"version":3,"names":["PropertyStore"],"sources":["index.ts"],"sourcesContent":["export { PropertyStore } from \"./PropertyStore.js\";\n"],"mappings":"AAAA,SAASA,aAAa","ignoreList":[]}
package/index.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"names":["DevToolsSection"],"sources":["index.ts"],"sourcesContent":["export * from \"./utils.js\";\nexport * from \"./Properties.js\";\nexport * from \"./useDebugConfig.js\";\nexport * from \"./useIdGenerator.js\";\nexport * from \"./createConfigurableComponent.js\";\nexport * from \"./domain/index.js\";\nexport { DevToolsSection } from \"./DevToolsSection.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,eAAe","ignoreList":[]}