@webiny/react-properties 0.0.0-unstable.78f581c1d2 → 0.0.0-unstable.7be00a75a9

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 (42) hide show
  1. package/DevToolsSection.d.ts +40 -0
  2. package/DevToolsSection.js +54 -0
  3. package/DevToolsSection.js.map +1 -0
  4. package/Properties.d.ts +60 -0
  5. package/Properties.js +130 -191
  6. package/Properties.js.map +1 -1
  7. package/PropertyPriority.d.ts +8 -0
  8. package/PropertyPriority.js +11 -0
  9. package/PropertyPriority.js.map +1 -0
  10. package/README.md +7 -61
  11. package/createConfigurableComponent.d.ts +15 -0
  12. package/createConfigurableComponent.js +67 -0
  13. package/createConfigurableComponent.js.map +1 -0
  14. package/domain/PropertyStore.d.ts +51 -0
  15. package/domain/PropertyStore.js +154 -0
  16. package/domain/PropertyStore.js.map +1 -0
  17. package/domain/index.d.ts +1 -0
  18. package/domain/index.js +1 -0
  19. package/index.d.ts +7 -0
  20. package/index.js +7 -31
  21. package/package.json +19 -17
  22. package/useDebugConfig.d.ts +32 -0
  23. package/useDebugConfig.js +45 -0
  24. package/useDebugConfig.js.map +1 -0
  25. package/useIdGenerator.d.ts +1 -0
  26. package/useIdGenerator.js +23 -0
  27. package/useIdGenerator.js.map +1 -0
  28. package/utils.d.ts +3 -0
  29. package/utils.js +42 -48
  30. package/utils.js.map +1 -1
  31. package/__tests__/cases/dashboard/App.d.ts +0 -23
  32. package/__tests__/cases/dashboard/dashboard.test.d.ts +0 -1
  33. package/__tests__/cases/pbEditorSettings/PbEditorSettingsView.d.ts +0 -21
  34. package/__tests__/cases/pbEditorSettings/createConfigurableView.d.ts +0 -9
  35. package/__tests__/cases/pbEditorSettings/pbEditorSettings.test.d.ts +0 -1
  36. package/__tests__/properties.test.d.ts +0 -1
  37. package/__tests__/setupEnv.d.ts +0 -1
  38. package/__tests__/utils.d.ts +0 -2
  39. package/index.js.map +0 -1
  40. package/src/Properties.d.ts +0 -38
  41. package/src/index.d.ts +0 -2
  42. package/src/utils.d.ts +0 -3
@@ -0,0 +1,15 @@
1
+ import React from "react";
2
+ import type { Property } from "./index.js";
3
+ export interface WithConfigProps {
4
+ children: React.ReactNode;
5
+ onProperties?(properties: Property[]): void;
6
+ }
7
+ export interface ConfigProps {
8
+ children: React.ReactNode;
9
+ priority?: "primary" | "secondary";
10
+ }
11
+ export declare function createConfigurableComponent<TConfig>(name: string): {
12
+ WithConfig: ({ onProperties, children }: WithConfigProps) => React.JSX.Element;
13
+ Config: ({ priority, children }: ConfigProps) => React.JSX.Element;
14
+ useConfig: <TExtra extends object>() => TConfig & TExtra;
15
+ };
@@ -0,0 +1,67 @@
1
+ import react, { useCallback, useContext, useEffect, useMemo, useState } from "react";
2
+ import { Compose, makeDecoratable } from "@webiny/react-composition";
3
+ import { Properties, toObject } from "./index.js";
4
+ import { useDebugConfig } from "./useDebugConfig.js";
5
+ import { PropertyPriorityProvider } from "./PropertyPriority.js";
6
+ const createHOC = (newChildren)=>(BaseComponent)=>function({ children }) {
7
+ return /*#__PURE__*/ react.createElement(BaseComponent, null, newChildren, children);
8
+ };
9
+ function createConfigurableComponent(name) {
10
+ const ConfigApplyPrimary = makeDecoratable(`${name}ConfigApply<Primary>`, ({ children })=>/*#__PURE__*/ react.createElement(react.Fragment, null, children));
11
+ const ConfigApplySecondary = makeDecoratable(`${name}ConfigApply<Secondary>`, ({ children })=>/*#__PURE__*/ react.createElement(react.Fragment, null, children));
12
+ const Config = ({ priority = "primary", children })=>{
13
+ if ("primary" === priority) return /*#__PURE__*/ react.createElement(Compose, {
14
+ component: ConfigApplyPrimary,
15
+ with: createHOC(children)
16
+ });
17
+ return /*#__PURE__*/ react.createElement(Compose, {
18
+ component: ConfigApplySecondary,
19
+ with: createHOC(children)
20
+ });
21
+ };
22
+ const defaultContext = {
23
+ properties: []
24
+ };
25
+ const ViewContext = /*#__PURE__*/ react.createContext(defaultContext);
26
+ const ConfigApplyTree = /*#__PURE__*/ react.memo(function() {
27
+ return /*#__PURE__*/ react.createElement(react.Fragment, null, /*#__PURE__*/ react.createElement(ConfigApplyPrimary, null), /*#__PURE__*/ react.createElement(PropertyPriorityProvider, {
28
+ priority: 1
29
+ }, /*#__PURE__*/ react.createElement(ConfigApplySecondary, null)));
30
+ });
31
+ const WithConfig = ({ onProperties, children })=>{
32
+ const [properties, setProperties] = useState(null);
33
+ const resolvedProperties = properties ?? [];
34
+ useDebugConfig(name, resolvedProperties);
35
+ const context = {
36
+ properties: resolvedProperties
37
+ };
38
+ useEffect(()=>{
39
+ if (null !== properties && "function" == typeof onProperties) onProperties(properties);
40
+ }, [
41
+ properties
42
+ ]);
43
+ const stateUpdater = useCallback((properties)=>{
44
+ setProperties(properties);
45
+ }, []);
46
+ return /*#__PURE__*/ react.createElement(ViewContext.Provider, {
47
+ value: context
48
+ }, /*#__PURE__*/ react.createElement(Properties, {
49
+ name: name,
50
+ onChange: stateUpdater
51
+ }, /*#__PURE__*/ react.createElement(ConfigApplyTree, null)), null !== properties ? children : null);
52
+ };
53
+ function useConfig() {
54
+ const { properties } = useContext(ViewContext);
55
+ return useMemo(()=>toObject(properties), [
56
+ properties
57
+ ]);
58
+ }
59
+ return {
60
+ WithConfig,
61
+ Config,
62
+ useConfig
63
+ };
64
+ }
65
+ export { createConfigurableComponent };
66
+
67
+ //# sourceMappingURL=createConfigurableComponent.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createConfigurableComponent.js","sources":["../src/createConfigurableComponent.tsx"],"sourcesContent":["import React, { useCallback, useContext, useEffect, useMemo, useState } from \"react\";\nimport type { Decorator } from \"@webiny/react-composition\";\nimport { Compose, makeDecoratable } from \"@webiny/react-composition\";\nimport type { GenericComponent } from \"@webiny/react-composition/types.js\";\nimport type { Property } from \"~/index.js\";\nimport { Properties, toObject } from \"~/index.js\";\nimport { useDebugConfig } from \"./useDebugConfig.js\";\nimport { PropertyPriorityProvider } from \"./PropertyPriority.js\";\n\n/**\n * Each `<Config>` call composes a new HOC around the previous one via `Compose`.\n * The last composed HOC is the outermost wrapper. By placing `{newChildren}`\n * (this HOC's addition) before `{children}` (all previously composed configs),\n * the final render order matches declaration order:\n *\n * <Config>A</Config> → renders first (outermost HOC, its newChildren rendered first)\n * <Config>B</Config> → renders second\n * <Config>C</Config> → renders third (innermost, rendered last via children chain)\n *\n * This is important because Property components register in mount order,\n * so declaration order = mount order = predictable config resolution.\n */\nconst createHOC =\n (newChildren: React.ReactNode): Decorator<GenericComponent<{ children?: React.ReactNode }>> =>\n BaseComponent => {\n return function ConfigHOC({ children }) {\n return (\n <BaseComponent>\n {newChildren}\n {children}\n </BaseComponent>\n );\n };\n };\n\nexport interface WithConfigProps {\n children: React.ReactNode;\n onProperties?(properties: Property[]): void;\n}\n\ninterface ConfigApplyProps {\n children?: React.ReactNode;\n}\n\nexport interface ConfigProps {\n children: React.ReactNode;\n priority?: \"primary\" | \"secondary\";\n}\n\nexport function createConfigurableComponent<TConfig>(name: string) {\n const ConfigApplyPrimary = makeDecoratable(\n `${name}ConfigApply<Primary>`,\n ({ children }: ConfigApplyProps) => {\n return <>{children}</>;\n }\n );\n\n const ConfigApplySecondary = makeDecoratable(\n `${name}ConfigApply<Secondary>`,\n ({ children }: ConfigApplyProps) => {\n return <>{children}</>;\n }\n );\n\n const Config = ({ priority = \"primary\", children }: ConfigProps) => {\n if (priority === \"primary\") {\n return <Compose component={ConfigApplyPrimary} with={createHOC(children)} />;\n }\n return <Compose component={ConfigApplySecondary} with={createHOC(children)} />;\n };\n\n interface ViewContext {\n properties: Property[];\n }\n\n const defaultContext = { properties: [] };\n\n const ViewContext = React.createContext<ViewContext>(defaultContext);\n\n /**\n * Memoized config subtree — ConfigApply components don't depend on WithConfig\n * props, so they must not remount when the parent re-renders. Without this,\n * every parent re-render causes Property components inside HOCs to unmount\n * and remount, corrupting the config object.\n */\n const ConfigApplyTree = React.memo(function ConfigApplyTree() {\n return (\n <>\n <ConfigApplyPrimary />\n <PropertyPriorityProvider priority={1}>\n <ConfigApplySecondary />\n </PropertyPriorityProvider>\n </>\n );\n });\n\n const WithConfig = ({ onProperties, children }: WithConfigProps) => {\n // `null` = config not yet collected; `[]` = collected but empty.\n // This distinction is critical: children must NOT render until the\n // PropertyStore debounce has flushed and delivered the initial config.\n // Rendering children with partial/empty config causes errors in\n // consumers like LexicalEditor that require a complete config on mount.\n const [properties, setProperties] = useState<Property[] | null>(null);\n const resolvedProperties = properties ?? [];\n useDebugConfig(name, resolvedProperties);\n const context = { properties: resolvedProperties };\n\n useEffect(() => {\n if (properties !== null && typeof onProperties === \"function\") {\n onProperties(properties);\n }\n }, [properties]);\n\n const stateUpdater = useCallback((properties: Property[]) => {\n setProperties(properties);\n }, []);\n\n return (\n <ViewContext.Provider value={context}>\n {/* ConfigApplyTree always renders so Property components inside\n composed HOCs can mount and register with the PropertyStore.\n It lives outside the children gate below. */}\n <Properties name={name} onChange={stateUpdater}>\n <ConfigApplyTree />\n </Properties>\n {/* Gate: only render children once the PropertyStore has flushed\n its first batch (properties !== null). This guarantees that\n useConfig() returns a complete config object on first render. */}\n {properties !== null ? children : null}\n </ViewContext.Provider>\n );\n };\n\n function useConfig<TExtra extends object>(): TConfig & TExtra {\n const { properties } = useContext(ViewContext);\n return useMemo(() => toObject<TConfig & TExtra>(properties), [properties]);\n }\n\n return {\n WithConfig,\n Config,\n useConfig\n };\n}\n"],"names":["createHOC","newChildren","BaseComponent","children","createConfigurableComponent","name","ConfigApplyPrimary","makeDecoratable","ConfigApplySecondary","Config","priority","Compose","defaultContext","ViewContext","React","ConfigApplyTree","PropertyPriorityProvider","WithConfig","onProperties","properties","setProperties","useState","resolvedProperties","useDebugConfig","context","useEffect","stateUpdater","useCallback","Properties","useConfig","useContext","useMemo","toObject"],"mappings":";;;;;AAsBA,MAAMA,YACF,CAACC,cACDC,CAAAA,gBACW,SAAmB,EAAEC,QAAQ,EAAE;YAClC,OAAO,WAAP,GACI,oBAACD,eAAAA,MACID,aACAE;QAGb;AAiBD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W;yBAIzB,oBAACI,YAAUA;YAAC,MAAMvB;YAAM,UAAUqB;yBAC9B,oBAACX,iBAAAA,QAKJI,AAAe,SAAfA,aAAsBhB,WAAW;IAG9C;IAEA,SAAS0B;QACL,MAAM,EAAEV,UAAU,EAAE,GAAGW,WAAWjB;QAClC,OAAOkB,QAAQ,IAAMC,SAA2Bb,aAAa;YAACA;SAAW;IAC7E;IAEA,OAAO;QACHF;QACAR;QACAoB;IACJ;AACJ"}
@@ -0,0 +1,51 @@
1
+ import type { Property } from "../Properties.js";
2
+ interface AddPropertyOptions {
3
+ after?: string;
4
+ before?: string;
5
+ priority?: number;
6
+ }
7
+ type Listener = (properties: Property[]) => void;
8
+ export declare class PropertyStore {
9
+ private map;
10
+ private order;
11
+ private queue;
12
+ private listeners;
13
+ private priorities;
14
+ /** Properties that were explicitly positioned via before/after. */
15
+ private positioned;
16
+ /**
17
+ * Synchronous lookup map — written immediately on addProperty (before debounce),
18
+ * so useAncestor can find properties during render.
19
+ */
20
+ private lookup;
21
+ private scheduleFlush;
22
+ get allProperties(): Property[];
23
+ subscribe(listener: Listener): () => void;
24
+ /**
25
+ * Returns properties that are children of the given parent ID.
26
+ * Reads from the synchronous lookup map, so it works during render
27
+ * before the debounced queue has flushed.
28
+ */
29
+ getChildrenOf(parentId: string): Property[];
30
+ /**
31
+ * Find a property by ID from the synchronous lookup map.
32
+ */
33
+ getById(id: string): Property | undefined;
34
+ /**
35
+ * Register a property in the synchronous lookup map during render,
36
+ * so useAncestor can find it before the debounced queue flushes.
37
+ */
38
+ registerLookup(property: Property): void;
39
+ addProperty(property: Property, options?: AddPropertyOptions): void;
40
+ removeProperty(id: string): void;
41
+ replaceProperty(oldId: string, newProperty: Property): void;
42
+ private processQueue;
43
+ private executeAdd;
44
+ private executeRemove;
45
+ private executeReplace;
46
+ private insertBefore;
47
+ private insertAfter;
48
+ private reposition;
49
+ private removeDescendants;
50
+ }
51
+ export {};
@@ -0,0 +1,154 @@
1
+ import debounce from "lodash/debounce.js";
2
+ class PropertyStore {
3
+ get allProperties() {
4
+ return this.order.filter((id)=>this.map.has(id)).map((id)=>this.map.get(id));
5
+ }
6
+ subscribe(listener) {
7
+ this.listeners.add(listener);
8
+ return ()=>{
9
+ this.listeners.delete(listener);
10
+ };
11
+ }
12
+ getChildrenOf(parentId) {
13
+ return Array.from(this.lookup.values()).filter((p)=>p.parent === parentId);
14
+ }
15
+ getById(id) {
16
+ return this.lookup.get(id);
17
+ }
18
+ registerLookup(property) {
19
+ if (this.lookup.has(property.id)) {
20
+ const existing = this.lookup.get(property.id);
21
+ this.lookup.set(property.id, {
22
+ ...existing,
23
+ ...property
24
+ });
25
+ } else this.lookup.set(property.id, property);
26
+ }
27
+ addProperty(property, options = {}) {
28
+ this.registerLookup(property);
29
+ this.queue.push({
30
+ type: "add",
31
+ property,
32
+ options
33
+ });
34
+ this.scheduleFlush();
35
+ }
36
+ removeProperty(id) {
37
+ this.lookup.delete(id);
38
+ this.queue.push({
39
+ type: "remove",
40
+ id
41
+ });
42
+ this.scheduleFlush();
43
+ }
44
+ replaceProperty(oldId, newProperty) {
45
+ this.lookup.delete(oldId);
46
+ this.lookup.set(newProperty.id, newProperty);
47
+ this.queue.push({
48
+ type: "replace",
49
+ oldId,
50
+ newProperty
51
+ });
52
+ this.scheduleFlush();
53
+ }
54
+ processQueue() {
55
+ if (0 === this.queue.length) return;
56
+ const ops = this.queue.splice(0);
57
+ ops.sort((a, b)=>{
58
+ const pa = "add" === a.type ? a.options.priority ?? 0 : 0;
59
+ const pb = "add" === b.type ? b.options.priority ?? 0 : 0;
60
+ return pa - pb;
61
+ });
62
+ for (const op of ops)switch(op.type){
63
+ case "add":
64
+ this.executeAdd(op.property, op.options);
65
+ break;
66
+ case "remove":
67
+ this.executeRemove(op.id);
68
+ break;
69
+ case "replace":
70
+ this.executeReplace(op.oldId, op.newProperty);
71
+ break;
72
+ }
73
+ this.order.sort((a, b)=>{
74
+ if (this.positioned.has(a) || this.positioned.has(b)) return 0;
75
+ return (this.priorities.get(a) ?? 0) - (this.priorities.get(b) ?? 0);
76
+ });
77
+ const properties = this.allProperties;
78
+ for (const listener of this.listeners)listener(properties);
79
+ }
80
+ executeAdd(property, options) {
81
+ if (options.after || options.before) this.positioned.add(property.id);
82
+ const exists = this.map.has(property.id);
83
+ if (exists) {
84
+ const existing = this.map.get(property.id);
85
+ this.map.set(property.id, {
86
+ ...existing,
87
+ ...property
88
+ });
89
+ if (options.after) this.reposition(property.id, options.after, "after");
90
+ else if (options.before) this.reposition(property.id, options.before, "before");
91
+ return;
92
+ }
93
+ this.map.set(property.id, property);
94
+ this.priorities.set(property.id, options.priority ?? 0);
95
+ if (options.after) this.insertAfter(property.id, options.after);
96
+ else if (options.before) this.insertBefore(property.id, options.before);
97
+ else this.order.push(property.id);
98
+ }
99
+ executeRemove(id) {
100
+ if (!this.map.has(id)) return;
101
+ this.map.delete(id);
102
+ this.priorities.delete(id);
103
+ this.positioned.delete(id);
104
+ this.order = this.order.filter((oid)=>oid !== id);
105
+ }
106
+ executeReplace(oldId, newProperty) {
107
+ const idx = this.order.indexOf(oldId);
108
+ if (-1 === idx) return;
109
+ this.map.delete(oldId);
110
+ this.map.set(newProperty.id, newProperty);
111
+ this.order[idx] = newProperty.id;
112
+ this.removeDescendants(oldId);
113
+ }
114
+ insertBefore(id, before) {
115
+ if (before.endsWith("$first")) return void this.order.unshift(id);
116
+ const targetIdx = this.order.indexOf(before);
117
+ if (-1 === targetIdx) return void this.order.push(id);
118
+ this.order.splice(targetIdx, 0, id);
119
+ }
120
+ insertAfter(id, after) {
121
+ if (after.endsWith("$last")) return void this.order.push(id);
122
+ const targetIdx = this.order.indexOf(after);
123
+ if (-1 === targetIdx) return void this.order.push(id);
124
+ this.order.splice(targetIdx + 1, 0, id);
125
+ }
126
+ reposition(id, targetId, position) {
127
+ this.order = this.order.filter((oid)=>oid !== id);
128
+ if ("before" === position) this.insertBefore(id, targetId);
129
+ else this.insertAfter(id, targetId);
130
+ }
131
+ removeDescendants(parentId) {
132
+ const children = Array.from(this.map.values()).filter((p)=>p.parent === parentId);
133
+ for (const child of children){
134
+ this.map.delete(child.id);
135
+ this.order = this.order.filter((oid)=>oid !== child.id);
136
+ this.removeDescendants(child.id);
137
+ }
138
+ }
139
+ constructor(){
140
+ this.map = new Map();
141
+ this.order = [];
142
+ this.queue = [];
143
+ this.listeners = new Set();
144
+ this.priorities = new Map();
145
+ this.positioned = new Set();
146
+ this.lookup = new Map();
147
+ this.scheduleFlush = debounce(()=>{
148
+ this.processQueue();
149
+ }, 0);
150
+ }
151
+ }
152
+ export { PropertyStore };
153
+
154
+ //# sourceMappingURL=PropertyStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"domain/PropertyStore.js","sources":["../../src/domain/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"],"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,gBAA4B;QAC5B,OAAO,IAAI,CAAC,KAAK,CAAC,MAAM,CAACC,CAAAA,KAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAACA,KAAK,GAAG,CAACA,CAAAA,KAAM,IAAI,CAAC,GAAG,CAAC,GAAG,CAACA;IAC5E;IAEA,UAAUC,QAAkB,EAAc;QACtC,IAAI,CAAC,SAAS,CAAC,GAAG,CAACA;QACnB,OAAO;YACH,IAAI,CAAC,SAAS,CAAC,MAAM,CAACA;QAC1B;IACJ;IAOA,cAAcC,QAAgB,EAAc;QACxC,OAAOC,MAAM,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,MAAM,IAAI,MAAM,CAACC,CAAAA,IAAKA,EAAE,MAAM,KAAKF;IACrE;IAKA,QAAQF,EAAU,EAAwB;QACtC,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA;IAC3B;IAMA,eAAeK,QAAkB,EAAQ;QACrC,IAAI,IAAI,CAAC,MAAM,CAAC,GAAG,CAACA,SAAS,EAAE,GAAG;YAC9B,MAAMC,WAAW,IAAI,CAAC,MAAM,CAAC,GAAG,CAACD,SAAS,EAAE;YAC5C,IAAI,CAAC,MAAM,CAAC,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AAM,GAAG,IAAID;aAEb,aAAa,GAAGE,SAAS;YAC7B,IAAI,CAAC,YAAY;QACrB,GAAG;;AAuNP"}
@@ -0,0 +1 @@
1
+ export { PropertyStore } from "./PropertyStore.js";
@@ -0,0 +1 @@
1
+ export { PropertyStore } from "./PropertyStore.js";
package/index.d.ts ADDED
@@ -0,0 +1,7 @@
1
+ export * from "./utils.js";
2
+ export * from "./Properties.js";
3
+ export * from "./useDebugConfig.js";
4
+ export * from "./useIdGenerator.js";
5
+ export * from "./createConfigurableComponent.js";
6
+ export * from "./domain/index.js";
7
+ export { DevToolsSection } from "./DevToolsSection.js";
package/index.js CHANGED
@@ -1,31 +1,7 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
-
7
- var _utils = require("./utils");
8
-
9
- Object.keys(_utils).forEach(function (key) {
10
- if (key === "default" || key === "__esModule") return;
11
- if (key in exports && exports[key] === _utils[key]) return;
12
- Object.defineProperty(exports, key, {
13
- enumerable: true,
14
- get: function get() {
15
- return _utils[key];
16
- }
17
- });
18
- });
19
-
20
- var _Properties = require("./Properties");
21
-
22
- Object.keys(_Properties).forEach(function (key) {
23
- if (key === "default" || key === "__esModule") return;
24
- if (key in exports && exports[key] === _Properties[key]) return;
25
- Object.defineProperty(exports, key, {
26
- enumerable: true,
27
- get: function get() {
28
- return _Properties[key];
29
- }
30
- });
31
- });
1
+ export * from "./utils.js";
2
+ export * from "./Properties.js";
3
+ export * from "./useDebugConfig.js";
4
+ export * from "./useIdGenerator.js";
5
+ export * from "./createConfigurableComponent.js";
6
+ export * from "./domain/index.js";
7
+ 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.78f581c1d2",
4
- "main": "index.js",
3
+ "version": "0.0.0-unstable.7be00a75a9",
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,24 +14,22 @@
10
14
  "author": "Webiny Ltd",
11
15
  "license": "MIT",
12
16
  "dependencies": {
13
- "@babel/runtime": "7.19.0",
14
- "@types/react": "17.0.39",
15
- "nanoid": "3.3.4",
16
- "react": "17.0.2"
17
+ "@types/react": "18.3.29",
18
+ "@webiny/react-composition": "0.0.0-unstable.7be00a75a9",
19
+ "lodash": "4.18.1",
20
+ "nanoid": "5.1.11",
21
+ "react": "18.3.1"
17
22
  },
18
23
  "devDependencies": {
19
- "@testing-library/react": "^12.1.5",
20
- "@webiny/cli": "^0.0.0-unstable.78f581c1d2",
21
- "@webiny/project-utils": "^0.0.0-unstable.78f581c1d2",
22
- "@webiny/react-composition": "^0.0.0-unstable.78f581c1d2"
24
+ "@testing-library/react": "16.3.2",
25
+ "@webiny/build-tools": "0.0.0-unstable.7be00a75a9",
26
+ "oxfmt": "0.51.0",
27
+ "vitest": "4.1.7"
23
28
  },
24
29
  "publishConfig": {
25
- "access": "public",
26
- "directory": "dist"
27
- },
28
- "scripts": {
29
- "build": "yarn webiny run build",
30
- "watch": "yarn webiny run watch"
30
+ "access": "public"
31
31
  },
32
- "gitHead": "78f581c1d2e5e6936aa11b9452a66d2a3652a1b2"
32
+ "webiny": {
33
+ "publishFrom": "dist"
34
+ }
33
35
  }
@@ -0,0 +1,32 @@
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
+ }
24
+ declare global {
25
+ interface Window {
26
+ __debugConfigs: Record<string, () => void>;
27
+ __WEBINY_DEVTOOLS_HOOK__?: WebinyDevtoolsHook;
28
+ }
29
+ }
30
+ export declare function getHook(): WebinyDevtoolsHook;
31
+ export declare function useDebugConfig(name: string, properties: Property[]): void;
32
+ export {};
@@ -0,0 +1,45 @@
1
+ import { useEffect } from "react";
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: {}
8
+ };
9
+ return window.__WEBINY_DEVTOOLS_HOOK__;
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 };
44
+
45
+ //# sourceMappingURL=useDebugConfig.js.map
@@ -0,0 +1 @@
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"}
@@ -0,0 +1 @@
1
+ export declare function useIdGenerator(name: string): (...parts: string[]) => string;
@@ -0,0 +1,23 @@
1
+ import { useCallback } from "react";
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
+ ]);
20
+ }
21
+ export { useIdGenerator };
22
+
23
+ //# sourceMappingURL=useIdGenerator.js.map
@@ -0,0 +1 @@
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 ADDED
@@ -0,0 +1,3 @@
1
+ import type { Property } from "./Properties.js";
2
+ export declare function toObject<T = unknown>(properties: Property[]): T;
3
+ export declare function getUniqueId(length?: number): string;