@webiny/react-properties 0.0.0-unstable.e622468070 → 0.0.0-unstable.e6f0dc8ca7
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/DevToolsSection.d.ts +40 -0
- package/DevToolsSection.js +70 -0
- package/DevToolsSection.js.map +1 -0
- package/Properties.d.ts +3 -1
- package/Properties.js +41 -88
- package/Properties.js.map +1 -1
- package/PropertyPriority.d.ts +8 -0
- package/PropertyPriority.js +15 -0
- package/PropertyPriority.js.map +1 -0
- package/createConfigurableComponent.js +43 -38
- package/createConfigurableComponent.js.map +1 -1
- package/domain/PropertyStore.d.ts +51 -0
- package/domain/PropertyStore.js +229 -0
- package/domain/PropertyStore.js.map +1 -0
- package/domain/index.d.ts +1 -0
- package/domain/index.js +3 -0
- package/domain/index.js.map +1 -0
- package/index.d.ts +2 -0
- package/index.js +2 -0
- package/index.js.map +1 -1
- package/package.json +15 -12
- package/useDebugConfig.d.ts +25 -0
- package/useDebugConfig.js +34 -0
- package/useDebugConfig.js.map +1 -1
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
type DevToolsView = "browse" | "raw";
|
|
2
|
+
interface DevToolsSectionProps {
|
|
3
|
+
name: string;
|
|
4
|
+
data: unknown;
|
|
5
|
+
/**
|
|
6
|
+
* Group name for the sidebar. Items with the same group appear
|
|
7
|
+
* under the same header. Defaults to "Sections".
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* <DevToolsSection name="Article" group="CMS" data={model} />
|
|
12
|
+
* <DevToolsSection name="Author" group="CMS" data={author} />
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
15
|
+
group?: string;
|
|
16
|
+
/**
|
|
17
|
+
* Which views to show in the detail panel.
|
|
18
|
+
* - `"browse"` — split view with root keys on the left, value tree on the right
|
|
19
|
+
* - `"raw"` — full JSON tree view
|
|
20
|
+
*
|
|
21
|
+
* Accepts a single view or an array. First item is the default tab.
|
|
22
|
+
* @default ["browse", "raw"]
|
|
23
|
+
*/
|
|
24
|
+
views?: DevToolsView | DevToolsView[];
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Registers a named section in the Webiny DevTools extension.
|
|
28
|
+
* Renders nothing — purely a data registration side-effect.
|
|
29
|
+
*
|
|
30
|
+
* When the component unmounts (e.g., route change), the section
|
|
31
|
+
* is automatically removed from DevTools.
|
|
32
|
+
*
|
|
33
|
+
* @example
|
|
34
|
+
* ```tsx
|
|
35
|
+
* <DevToolsSection name="CMS Model" data={model} />
|
|
36
|
+
* <DevToolsSection name="Article" group="CMS" data={model} views="raw" />
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
export declare function DevToolsSection({ name, data, group, views }: DevToolsSectionProps): null;
|
|
40
|
+
export {};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { useEffect } from "react";
|
|
2
|
+
import { getHook } from "./useDebugConfig.js";
|
|
3
|
+
/**
|
|
4
|
+
* Registers a named section in the Webiny DevTools extension.
|
|
5
|
+
* Renders nothing — purely a data registration side-effect.
|
|
6
|
+
*
|
|
7
|
+
* When the component unmounts (e.g., route change), the section
|
|
8
|
+
* is automatically removed from DevTools.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```tsx
|
|
12
|
+
* <DevToolsSection name="CMS Model" data={model} />
|
|
13
|
+
* <DevToolsSection name="Article" group="CMS" data={model} views="raw" />
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export function DevToolsSection({
|
|
17
|
+
name,
|
|
18
|
+
data,
|
|
19
|
+
group,
|
|
20
|
+
views
|
|
21
|
+
}) {
|
|
22
|
+
// Snapshot the data on every render to get a stable, plain value.
|
|
23
|
+
// This also ensures that if data is a MobX observable, we capture
|
|
24
|
+
// the current state as a plain object (no proxies on the hook).
|
|
25
|
+
const dataKey = safeStringify(data);
|
|
26
|
+
useEffect(() => {
|
|
27
|
+
if (process.env.NODE_ENV !== "development") {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const normalizedViews = views ? Array.isArray(views) ? views : [views] : ["browse", "raw"];
|
|
31
|
+
let plainData;
|
|
32
|
+
try {
|
|
33
|
+
plainData = JSON.parse(dataKey);
|
|
34
|
+
} catch {
|
|
35
|
+
plainData = data;
|
|
36
|
+
}
|
|
37
|
+
const hook = getHook();
|
|
38
|
+
hook.sections[name] = {
|
|
39
|
+
data: plainData,
|
|
40
|
+
group: group || "Sections",
|
|
41
|
+
views: normalizedViews,
|
|
42
|
+
updatedAt: Date.now()
|
|
43
|
+
};
|
|
44
|
+
hook.revision++;
|
|
45
|
+
return () => {
|
|
46
|
+
if (window.__WEBINY_DEVTOOLS_HOOK__) {
|
|
47
|
+
delete window.__WEBINY_DEVTOOLS_HOOK__.sections[name];
|
|
48
|
+
window.__WEBINY_DEVTOOLS_HOOK__.revision++;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
}, [name, dataKey, group, Array.isArray(views) ? views.join(",") : views]);
|
|
52
|
+
return null;
|
|
53
|
+
}
|
|
54
|
+
function safeStringify(value) {
|
|
55
|
+
try {
|
|
56
|
+
return JSON.stringify(value, (_key, v) => {
|
|
57
|
+
if (typeof v === "function") {
|
|
58
|
+
return `[Function: ${v.name || "anonymous"}]`;
|
|
59
|
+
}
|
|
60
|
+
if (typeof v === "undefined") {
|
|
61
|
+
return "[undefined]";
|
|
62
|
+
}
|
|
63
|
+
return v;
|
|
64
|
+
});
|
|
65
|
+
} catch {
|
|
66
|
+
return String(value);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=DevToolsSection.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["useEffect","getHook","DevToolsSection","name","data","group","views","dataKey","safeStringify","process","env","NODE_ENV","normalizedViews","Array","isArray","plainData","JSON","parse","hook","sections","updatedAt","Date","now","revision","window","__WEBINY_DEVTOOLS_HOOK__","join","value","stringify","_key","v","String"],"sources":["DevToolsSection.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { getHook } from \"./useDebugConfig.js\";\n\ntype DevToolsView = \"browse\" | \"raw\";\n\ninterface DevToolsSectionProps {\n name: string;\n data: unknown;\n /**\n * Group name for the sidebar. Items with the same group appear\n * under the same header. Defaults to \"Sections\".\n *\n * @example\n * ```tsx\n * <DevToolsSection name=\"Article\" group=\"CMS\" data={model} />\n * <DevToolsSection name=\"Author\" group=\"CMS\" data={author} />\n * ```\n */\n group?: string;\n /**\n * Which views to show in the detail panel.\n * - `\"browse\"` — split view with root keys on the left, value tree on the right\n * - `\"raw\"` — full JSON tree view\n *\n * Accepts a single view or an array. First item is the default tab.\n * @default [\"browse\", \"raw\"]\n */\n views?: DevToolsView | DevToolsView[];\n}\n\n/**\n * Registers a named section in the Webiny DevTools extension.\n * Renders nothing — purely a data registration side-effect.\n *\n * When the component unmounts (e.g., route change), the section\n * is automatically removed from DevTools.\n *\n * @example\n * ```tsx\n * <DevToolsSection name=\"CMS Model\" data={model} />\n * <DevToolsSection name=\"Article\" group=\"CMS\" data={model} views=\"raw\" />\n * ```\n */\nexport function DevToolsSection({ name, data, group, views }: DevToolsSectionProps) {\n // Snapshot the data on every render to get a stable, plain value.\n // This also ensures that if data is a MobX observable, we capture\n // the current state as a plain object (no proxies on the hook).\n const dataKey = safeStringify(data);\n\n useEffect(() => {\n if (process.env.NODE_ENV !== \"development\") {\n return;\n }\n\n const normalizedViews: DevToolsView[] = views\n ? Array.isArray(views)\n ? views\n : [views]\n : [\"browse\", \"raw\"];\n\n let plainData: unknown;\n try {\n plainData = JSON.parse(dataKey);\n } catch {\n plainData = data;\n }\n\n const hook = getHook();\n hook.sections[name] = {\n data: plainData,\n group: group || \"Sections\",\n views: normalizedViews,\n updatedAt: Date.now()\n };\n hook.revision++;\n\n return () => {\n if (window.__WEBINY_DEVTOOLS_HOOK__) {\n delete window.__WEBINY_DEVTOOLS_HOOK__.sections[name];\n window.__WEBINY_DEVTOOLS_HOOK__.revision++;\n }\n };\n }, [name, dataKey, group, Array.isArray(views) ? views.join(\",\") : views]);\n\n return null;\n}\n\nfunction safeStringify(value: unknown): string {\n try {\n return JSON.stringify(value, (_key, v) => {\n if (typeof v === \"function\") {\n return `[Function: ${v.name || \"anonymous\"}]`;\n }\n if (typeof v === \"undefined\") {\n return \"[undefined]\";\n }\n return v;\n });\n } catch {\n return String(value);\n }\n}\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AACjC,SAASC,OAAO;AA6BhB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,eAAeA,CAAC;EAAEC,IAAI;EAAEC,IAAI;EAAEC,KAAK;EAAEC;AAA4B,CAAC,EAAE;EAChF;EACA;EACA;EACA,MAAMC,OAAO,GAAGC,aAAa,CAACJ,IAAI,CAAC;EAEnCJ,SAAS,CAAC,MAAM;IACZ,IAAIS,OAAO,CAACC,GAAG,CAACC,QAAQ,KAAK,aAAa,EAAE;MACxC;IACJ;IAEA,MAAMC,eAA+B,GAAGN,KAAK,GACvCO,KAAK,CAACC,OAAO,CAACR,KAAK,CAAC,GAChBA,KAAK,GACL,CAACA,KAAK,CAAC,GACX,CAAC,QAAQ,EAAE,KAAK,CAAC;IAEvB,IAAIS,SAAkB;IACtB,IAAI;MACAA,SAAS,GAAGC,IAAI,CAACC,KAAK,CAACV,OAAO,CAAC;IACnC,CAAC,CAAC,MAAM;MACJQ,SAAS,GAAGX,IAAI;IACpB;IAEA,MAAMc,IAAI,GAAGjB,OAAO,CAAC,CAAC;IACtBiB,IAAI,CAACC,QAAQ,CAAChB,IAAI,CAAC,GAAG;MAClBC,IAAI,EAAEW,SAAS;MACfV,KAAK,EAAEA,KAAK,IAAI,UAAU;MAC1BC,KAAK,EAAEM,eAAe;MACtBQ,SAAS,EAAEC,IAAI,CAACC,GAAG,CAAC;IACxB,CAAC;IACDJ,IAAI,CAACK,QAAQ,EAAE;IAEf,OAAO,MAAM;MACT,IAAIC,MAAM,CAACC,wBAAwB,EAAE;QACjC,OAAOD,MAAM,CAACC,wBAAwB,CAACN,QAAQ,CAAChB,IAAI,CAAC;QACrDqB,MAAM,CAACC,wBAAwB,CAACF,QAAQ,EAAE;MAC9C;IACJ,CAAC;EACL,CAAC,EAAE,CAACpB,IAAI,EAAEI,OAAO,EAAEF,KAAK,EAAEQ,KAAK,CAACC,OAAO,CAACR,KAAK,CAAC,GAAGA,KAAK,CAACoB,IAAI,CAAC,GAAG,CAAC,GAAGpB,KAAK,CAAC,CAAC;EAE1E,OAAO,IAAI;AACf;AAEA,SAASE,aAAaA,CAACmB,KAAc,EAAU;EAC3C,IAAI;IACA,OAAOX,IAAI,CAACY,SAAS,CAACD,KAAK,EAAE,CAACE,IAAI,EAAEC,CAAC,KAAK;MACtC,IAAI,OAAOA,CAAC,KAAK,UAAU,EAAE;QACzB,OAAO,cAAcA,CAAC,CAAC3B,IAAI,IAAI,WAAW,GAAG;MACjD;MACA,IAAI,OAAO2B,CAAC,KAAK,WAAW,EAAE;QAC1B,OAAO,aAAa;MACxB;MACA,OAAOA,CAAC;IACZ,CAAC,CAAC;EACN,CAAC,CAAC,MAAM;IACJ,OAAOC,MAAM,CAACJ,KAAK,CAAC;EACxB;AACJ","ignoreList":[]}
|
package/Properties.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { PropertyStore } from "./domain/index.js";
|
|
2
3
|
export interface ConnectToPropertiesProps {
|
|
3
4
|
name: string;
|
|
4
5
|
children: React.ReactNode;
|
|
@@ -16,10 +17,11 @@ export interface Property {
|
|
|
16
17
|
interface AddPropertyOptions {
|
|
17
18
|
after?: string;
|
|
18
19
|
before?: string;
|
|
20
|
+
priority?: number;
|
|
19
21
|
}
|
|
20
22
|
interface PropertiesContext {
|
|
21
23
|
name?: string;
|
|
22
|
-
|
|
24
|
+
store: PropertyStore;
|
|
23
25
|
getAncestor(name: string): PropertiesContext | undefined;
|
|
24
26
|
getObject<T = unknown>(): T;
|
|
25
27
|
addProperty(property: Property, options?: AddPropertyOptions): void;
|
package/Properties.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import React, { createContext, useContext, useEffect, useMemo, useRef
|
|
1
|
+
import React, { createContext, useContext, useEffect, useMemo, useRef } from "react";
|
|
2
2
|
import { getUniqueId, toObject } from "./utils.js";
|
|
3
|
+
import { PropertyStore } from "./domain/index.js";
|
|
4
|
+
import { usePropertyPriority } from "./PropertyPriority.js";
|
|
3
5
|
const PropertiesTargetContext = /*#__PURE__*/createContext(undefined);
|
|
4
6
|
export const ConnectToProperties = ({
|
|
5
7
|
name,
|
|
@@ -9,49 +11,17 @@ export const ConnectToProperties = ({
|
|
|
9
11
|
value: name
|
|
10
12
|
}, children);
|
|
11
13
|
};
|
|
12
|
-
function removeByParent(id, properties) {
|
|
13
|
-
return properties.filter(prop => prop.parent === id).reduce((acc, item) => {
|
|
14
|
-
return removeByParent(item.id, acc.filter(prop => prop.id !== item.id));
|
|
15
|
-
}, properties);
|
|
16
|
-
}
|
|
17
|
-
function putPropertyBefore(properties, property, before) {
|
|
18
|
-
const existingIndex = properties.findIndex(prop => prop.id === property.id);
|
|
19
|
-
if (existingIndex > -1) {
|
|
20
|
-
const existingProperty = properties[existingIndex];
|
|
21
|
-
const newProperties = properties.filter(p => p.id !== property.id);
|
|
22
|
-
const targetIndex = before.endsWith("$first") ? 0 : newProperties.findIndex(prop => prop.id === before);
|
|
23
|
-
return [...newProperties.slice(0, targetIndex), existingProperty, ...newProperties.slice(targetIndex)];
|
|
24
|
-
}
|
|
25
|
-
const targetIndex = properties.findIndex(prop => prop.id === before);
|
|
26
|
-
return [...properties.slice(0, targetIndex), property, ...properties.slice(targetIndex)];
|
|
27
|
-
}
|
|
28
|
-
function putPropertyAfter(properties, property, after) {
|
|
29
|
-
const existingIndex = properties.findIndex(prop => prop.id === property.id);
|
|
30
|
-
if (existingIndex > -1) {
|
|
31
|
-
const [removedProperty] = properties.splice(existingIndex, 1);
|
|
32
|
-
const targetIndex = after.endsWith("$last") ? properties.length - 1 : properties.findIndex(prop => prop.id === after);
|
|
33
|
-
return [...properties.slice(0, targetIndex + 1), removedProperty, ...properties.slice(targetIndex + 1)];
|
|
34
|
-
}
|
|
35
|
-
const targetIndex = properties.findIndex(prop => prop.id === after);
|
|
36
|
-
return [...properties.slice(0, targetIndex + 1), property, ...properties.slice(targetIndex + 1)];
|
|
37
|
-
}
|
|
38
|
-
function mergeProperty(properties, property) {
|
|
39
|
-
const index = properties.findIndex(prop => prop.id === property.id);
|
|
40
|
-
if (index > -1) {
|
|
41
|
-
return [...properties.slice(0, index), {
|
|
42
|
-
...properties[index],
|
|
43
|
-
...property
|
|
44
|
-
}, ...properties.slice(index + 1)];
|
|
45
|
-
}
|
|
46
|
-
return properties;
|
|
47
|
-
}
|
|
48
14
|
const PropertiesContext = /*#__PURE__*/createContext(undefined);
|
|
49
15
|
export const Properties = ({
|
|
50
16
|
name,
|
|
51
17
|
onChange,
|
|
52
18
|
children
|
|
53
19
|
}) => {
|
|
54
|
-
const
|
|
20
|
+
const storeRef = useRef(null);
|
|
21
|
+
if (!storeRef.current) {
|
|
22
|
+
storeRef.current = new PropertyStore();
|
|
23
|
+
}
|
|
24
|
+
const store = storeRef.current;
|
|
55
25
|
let parent;
|
|
56
26
|
try {
|
|
57
27
|
parent = useProperties();
|
|
@@ -59,13 +29,19 @@ export const Properties = ({
|
|
|
59
29
|
// Do nothing, if there's no parent.
|
|
60
30
|
}
|
|
61
31
|
useEffect(() => {
|
|
62
|
-
if (onChange) {
|
|
63
|
-
|
|
32
|
+
if (!onChange) {
|
|
33
|
+
return;
|
|
64
34
|
}
|
|
65
|
-
|
|
35
|
+
return store.subscribe(properties => {
|
|
36
|
+
onChange(properties);
|
|
37
|
+
});
|
|
38
|
+
}, [store, onChange]);
|
|
39
|
+
|
|
40
|
+
// Context value is stable — it never changes after mount.
|
|
41
|
+
// Children never re-render due to context changes.
|
|
66
42
|
const context = useMemo(() => ({
|
|
67
43
|
name,
|
|
68
|
-
|
|
44
|
+
store,
|
|
69
45
|
getAncestor(ancestorName) {
|
|
70
46
|
if (!parent) {
|
|
71
47
|
return undefined;
|
|
@@ -73,63 +49,31 @@ export const Properties = ({
|
|
|
73
49
|
return parent && parent.name === ancestorName ? parent : parent.getAncestor(ancestorName);
|
|
74
50
|
},
|
|
75
51
|
getObject() {
|
|
76
|
-
return toObject(
|
|
52
|
+
return toObject(store.allProperties);
|
|
77
53
|
},
|
|
78
54
|
addProperty(property, options = {}) {
|
|
79
|
-
|
|
80
|
-
const index = properties.findIndex(prop => prop.id === property.id);
|
|
81
|
-
if (index > -1) {
|
|
82
|
-
const newProperties = mergeProperty(properties, property);
|
|
83
|
-
if (options.after) {
|
|
84
|
-
return putPropertyAfter(newProperties, property, options.after);
|
|
85
|
-
}
|
|
86
|
-
if (options.before) {
|
|
87
|
-
return putPropertyBefore(newProperties, property, options.before);
|
|
88
|
-
}
|
|
89
|
-
return newProperties;
|
|
90
|
-
}
|
|
91
|
-
if (options.after) {
|
|
92
|
-
return putPropertyAfter(properties, property, options.after);
|
|
93
|
-
}
|
|
94
|
-
if (options.before) {
|
|
95
|
-
return putPropertyBefore(properties, property, options.before);
|
|
96
|
-
}
|
|
97
|
-
return [...properties, property];
|
|
98
|
-
});
|
|
55
|
+
store.addProperty(property, options);
|
|
99
56
|
},
|
|
100
57
|
removeProperty(id) {
|
|
101
|
-
|
|
102
|
-
return removeByParent(id, properties.filter(prop => prop.id !== id));
|
|
103
|
-
});
|
|
58
|
+
store.removeProperty(id);
|
|
104
59
|
},
|
|
105
60
|
replaceProperty(id, property) {
|
|
106
|
-
|
|
107
|
-
const toReplace = properties.findIndex(prop => prop.id === id);
|
|
108
|
-
if (toReplace > -1) {
|
|
109
|
-
// Replace the property and remove all remaining child properties.
|
|
110
|
-
return removeByParent(id, [...properties.slice(0, toReplace), property, ...properties.slice(toReplace + 1)]);
|
|
111
|
-
}
|
|
112
|
-
return properties;
|
|
113
|
-
});
|
|
61
|
+
store.replaceProperty(id, property);
|
|
114
62
|
}
|
|
115
|
-
}), [
|
|
63
|
+
}), [store]);
|
|
116
64
|
return /*#__PURE__*/React.createElement(PropertiesContext.Provider, {
|
|
117
65
|
value: context
|
|
118
66
|
}, children);
|
|
119
67
|
};
|
|
120
68
|
export function useProperties() {
|
|
121
|
-
const
|
|
122
|
-
if (!
|
|
69
|
+
const context = useContext(PropertiesContext);
|
|
70
|
+
if (!context) {
|
|
123
71
|
throw Error("Properties context provider is missing!");
|
|
124
72
|
}
|
|
125
|
-
return
|
|
73
|
+
return context;
|
|
126
74
|
}
|
|
127
75
|
export function useMaybeProperties() {
|
|
128
|
-
|
|
129
|
-
if (!properties) {
|
|
130
|
-
return undefined;
|
|
131
|
-
}
|
|
132
|
-
return properties;
|
|
76
|
+
return useContext(PropertiesContext);
|
|
133
77
|
}
|
|
134
78
|
export function useAncestorByName(name) {
|
|
135
79
|
const parent = useMaybeProperties();
|
|
@@ -150,14 +94,15 @@ export function useParentProperty() {
|
|
|
150
94
|
export function useAncestor(params) {
|
|
151
95
|
const property = useParentProperty();
|
|
152
96
|
const {
|
|
153
|
-
|
|
97
|
+
store
|
|
154
98
|
} = useProperties();
|
|
155
99
|
const matchOrGetAncestor = (property, params) => {
|
|
156
|
-
const
|
|
100
|
+
const children = store.getChildrenOf(property.id);
|
|
101
|
+
const matchedProps = children.filter(prop => prop.name in params && prop.value === params[prop.name]);
|
|
157
102
|
if (matchedProps.length === Object.keys(params).length) {
|
|
158
103
|
return property;
|
|
159
104
|
}
|
|
160
|
-
const newParent = property.parent ?
|
|
105
|
+
const newParent = property.parent ? store.getById(property.parent) : undefined;
|
|
161
106
|
return newParent ? matchOrGetAncestor(newParent, params) : undefined;
|
|
162
107
|
};
|
|
163
108
|
return property ? matchOrGetAncestor(property, params) : undefined;
|
|
@@ -181,6 +126,7 @@ export const Property = ({
|
|
|
181
126
|
const immediateProperties = useProperties();
|
|
182
127
|
const ancestorByName = useAncestorByName(targetName);
|
|
183
128
|
const previousValue = useRef(value);
|
|
129
|
+
const priority = usePropertyPriority();
|
|
184
130
|
const properties = targetName && ancestorByName ? ancestorByName : immediateProperties;
|
|
185
131
|
if (!properties) {
|
|
186
132
|
throw Error("<Properties> provider is missing higher in the hierarchy!");
|
|
@@ -188,7 +134,8 @@ export const Property = ({
|
|
|
188
134
|
const {
|
|
189
135
|
addProperty,
|
|
190
136
|
removeProperty,
|
|
191
|
-
replaceProperty
|
|
137
|
+
replaceProperty,
|
|
138
|
+
store: propertyStore
|
|
192
139
|
} = properties;
|
|
193
140
|
const parentId = parent ? parent : root ? "" : parentProperty?.id || "";
|
|
194
141
|
const property = {
|
|
@@ -198,6 +145,11 @@ export const Property = ({
|
|
|
198
145
|
parent: parentId,
|
|
199
146
|
array
|
|
200
147
|
};
|
|
148
|
+
|
|
149
|
+
// Register in the synchronous lookup during render so useAncestor can find this property.
|
|
150
|
+
if (!remove) {
|
|
151
|
+
propertyStore.registerLookup(property);
|
|
152
|
+
}
|
|
201
153
|
useEffect(() => {
|
|
202
154
|
if (remove) {
|
|
203
155
|
removeProperty(uniqueId);
|
|
@@ -215,7 +167,8 @@ export const Property = ({
|
|
|
215
167
|
$isLast
|
|
216
168
|
}, {
|
|
217
169
|
after,
|
|
218
|
-
before
|
|
170
|
+
before,
|
|
171
|
+
priority
|
|
219
172
|
});
|
|
220
173
|
return () => {
|
|
221
174
|
removeProperty(uniqueId);
|
package/Properties.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","createContext","useContext","useEffect","useMemo","useRef","useState","getUniqueId","toObject","PropertiesTargetContext","undefined","ConnectToProperties","name","children","createElement","Provider","value","removeByParent","id","properties","filter","prop","parent","reduce","acc","item","putPropertyBefore","property","before","existingIndex","findIndex","existingProperty","newProperties","p","targetIndex","endsWith","slice","putPropertyAfter","after","removedProperty","splice","length","mergeProperty","index","PropertiesContext","Properties","onChange","setProperties","useProperties","context","getAncestor","ancestorName","getObject","addProperty","options","removeProperty","replaceProperty","toReplace","Error","useMaybeProperties","useAncestorByName","PropertyContext","useParentProperty","useAncestor","params","matchOrGetAncestor","matchedProps","Object","keys","newParent","find","Property","replace","remove","array","root","targetName","uniqueId","parentProperty","immediateProperties","ancestorByName","previousValue","parentId","$isFirst","$isLast","current"],"sources":["Properties.tsx"],"sourcesContent":["import React, { createContext, useContext, useEffect, useMemo, useRef, useState } from \"react\";\nimport { getUniqueId, toObject } from \"./utils.js\";\n\nconst PropertiesTargetContext = createContext<string | undefined>(undefined);\n\nexport interface ConnectToPropertiesProps {\n name: string;\n children: React.ReactNode;\n}\n\nexport const ConnectToProperties = ({ name, children }: ConnectToPropertiesProps) => {\n return (\n <PropertiesTargetContext.Provider value={name}>{children}</PropertiesTargetContext.Provider>\n );\n};\n\nexport interface Property {\n id: string;\n parent: string;\n name: string;\n value?: unknown;\n array?: boolean;\n $isFirst?: boolean;\n $isLast?: boolean;\n}\n\nfunction removeByParent(id: string, properties: Property[]): Property[] {\n return properties\n .filter(prop => prop.parent === id)\n .reduce((acc, item) => {\n return removeByParent(\n item.id,\n acc.filter(prop => prop.id !== item.id)\n );\n }, properties);\n}\n\ninterface AddPropertyOptions {\n after?: string;\n before?: string;\n}\n\ninterface PropertiesContext {\n name?: string;\n properties: Property[];\n getAncestor(name: string): PropertiesContext | undefined;\n getObject<T = unknown>(): T;\n addProperty(property: Property, options?: AddPropertyOptions): void;\n removeProperty(id: string): void;\n replaceProperty(id: string, property: Property): void;\n}\n\nfunction putPropertyBefore(properties: Property[], property: Property, before: string) {\n const existingIndex = properties.findIndex(prop => prop.id === property.id);\n if (existingIndex > -1) {\n const existingProperty = properties[existingIndex];\n const newProperties = properties.filter(p => p.id !== property.id);\n const targetIndex = before.endsWith(\"$first\")\n ? 0\n : newProperties.findIndex(prop => prop.id === before);\n return [\n ...newProperties.slice(0, targetIndex),\n existingProperty,\n ...newProperties.slice(targetIndex)\n ];\n }\n\n const targetIndex = properties.findIndex(prop => prop.id === before);\n\n return [...properties.slice(0, targetIndex), property, ...properties.slice(targetIndex)];\n}\n\nfunction putPropertyAfter(properties: Property[], property: Property, after: string) {\n const existingIndex = properties.findIndex(prop => prop.id === property.id);\n\n if (existingIndex > -1) {\n const [removedProperty] = properties.splice(existingIndex, 1);\n const targetIndex = after.endsWith(\"$last\")\n ? properties.length - 1\n : properties.findIndex(prop => prop.id === after);\n return [\n ...properties.slice(0, targetIndex + 1),\n removedProperty,\n ...properties.slice(targetIndex + 1)\n ];\n }\n\n const targetIndex = properties.findIndex(prop => prop.id === after);\n\n return [\n ...properties.slice(0, targetIndex + 1),\n property,\n ...properties.slice(targetIndex + 1)\n ];\n}\n\nfunction mergeProperty(properties: Property[], property: Property) {\n const index = properties.findIndex(prop => prop.id === property.id);\n if (index > -1) {\n return [\n ...properties.slice(0, index),\n { ...properties[index], ...property },\n ...properties.slice(index + 1)\n ];\n }\n return properties;\n}\n\nconst PropertiesContext = createContext<PropertiesContext | undefined>(undefined);\n\ninterface PropertiesProps {\n name?: string;\n onChange?(properties: Property[]): void;\n children: React.ReactNode;\n}\n\nexport const Properties = ({ name, onChange, children }: PropertiesProps) => {\n const [properties, setProperties] = useState<Property[]>([]);\n let parent: PropertiesContext;\n\n try {\n parent = useProperties();\n } catch {\n // Do nothing, if there's no parent.\n }\n\n useEffect(() => {\n if (onChange) {\n onChange(properties);\n }\n }, [properties]);\n\n const context: PropertiesContext = useMemo(\n () => ({\n name,\n properties,\n getAncestor(ancestorName: string) {\n if (!parent) {\n return undefined;\n }\n\n return parent && parent.name === ancestorName\n ? parent\n : parent.getAncestor(ancestorName);\n },\n getObject<T>() {\n return toObject(properties) as T;\n },\n addProperty(property, options = {}) {\n setProperties(properties => {\n const index = properties.findIndex(prop => prop.id === property.id);\n\n if (index > -1) {\n const newProperties = mergeProperty(properties, property);\n if (options.after) {\n return putPropertyAfter(newProperties, property, options.after);\n }\n if (options.before) {\n return putPropertyBefore(newProperties, property, options.before);\n }\n\n return newProperties;\n }\n\n if (options.after) {\n return putPropertyAfter(properties, property, options.after);\n }\n\n if (options.before) {\n return putPropertyBefore(properties, property, options.before);\n }\n\n return [...properties, property];\n });\n },\n removeProperty(id) {\n setProperties(properties => {\n return removeByParent(\n id,\n properties.filter(prop => prop.id !== id)\n );\n });\n },\n replaceProperty(id, property) {\n setProperties(properties => {\n const toReplace = properties.findIndex(prop => prop.id === id);\n\n if (toReplace > -1) {\n // Replace the property and remove all remaining child properties.\n return removeByParent(id, [\n ...properties.slice(0, toReplace),\n property,\n ...properties.slice(toReplace + 1)\n ]);\n }\n return properties;\n });\n }\n }),\n [properties]\n );\n\n return <PropertiesContext.Provider value={context}>{children}</PropertiesContext.Provider>;\n};\n\nexport function useProperties() {\n const properties = useContext(PropertiesContext);\n if (!properties) {\n throw Error(\"Properties context provider is missing!\");\n }\n\n return properties;\n}\n\nexport function useMaybeProperties() {\n const properties = useContext(PropertiesContext);\n if (!properties) {\n return undefined;\n }\n\n return properties;\n}\n\nexport function useAncestorByName(name: string | undefined) {\n const parent = useMaybeProperties();\n\n return useMemo(() => {\n if (!name || !parent) {\n return undefined;\n }\n\n if (parent.name === name) {\n return parent;\n }\n\n return parent.getAncestor(name);\n }, [name]);\n}\n\ninterface PropertyProps {\n id?: string;\n name: string;\n value?: unknown;\n array?: boolean;\n after?: string;\n before?: string;\n replace?: string;\n remove?: boolean;\n parent?: string;\n root?: boolean;\n children?: React.ReactNode;\n}\n\nconst PropertyContext = createContext<Property | undefined>(undefined);\n\nexport function useParentProperty() {\n return useContext(PropertyContext);\n}\n\ninterface AncestorMatch {\n [key: string]: string | boolean | number | null | undefined;\n}\n\nexport function useAncestor(params: AncestorMatch) {\n const property = useParentProperty();\n const { properties } = useProperties();\n\n const matchOrGetAncestor = (\n property: Property,\n params: AncestorMatch\n ): Property | undefined => {\n const matchedProps = properties\n .filter(prop => prop.parent === property.id)\n .filter(prop => prop.name in params && prop.value === params[prop.name]);\n\n if (matchedProps.length === Object.keys(params).length) {\n return property;\n }\n\n const newParent = property.parent\n ? properties.find(prop => prop.id === property.parent)\n : undefined;\n\n return newParent ? matchOrGetAncestor(newParent, params) : undefined;\n };\n\n return property ? matchOrGetAncestor(property, params) : undefined;\n}\n\nexport const Property = ({\n id,\n name,\n value,\n children,\n after = undefined,\n before = undefined,\n replace = undefined,\n remove = false,\n array = false,\n root = false,\n parent = undefined\n}: PropertyProps) => {\n const targetName = useContext(PropertiesTargetContext);\n const uniqueId = useMemo(() => id || getUniqueId(), []);\n const parentProperty = useParentProperty();\n const immediateProperties = useProperties();\n const ancestorByName = useAncestorByName(targetName);\n const previousValue = useRef(value);\n\n const properties = targetName && ancestorByName ? ancestorByName : immediateProperties;\n\n if (!properties) {\n throw Error(\"<Properties> provider is missing higher in the hierarchy!\");\n }\n\n const { addProperty, removeProperty, replaceProperty } = properties;\n const parentId = parent ? parent : root ? \"\" : parentProperty?.id || \"\";\n const property = { id: uniqueId, name, value, parent: parentId, array };\n\n useEffect(() => {\n if (remove) {\n removeProperty(uniqueId);\n return;\n }\n\n if (replace) {\n replaceProperty(replace, property);\n return;\n }\n\n const $isFirst = before === \"$first\";\n const $isLast = after === \"$last\";\n\n addProperty({ ...property, $isFirst, $isLast }, { after, before });\n\n return () => {\n removeProperty(uniqueId);\n };\n }, []);\n\n useEffect(() => {\n if (previousValue.current !== value) {\n previousValue.current = value;\n if (!remove && !replace) {\n replaceProperty(uniqueId, property);\n }\n }\n }, [value]);\n\n if (children) {\n return <PropertyContext.Provider value={property}>{children}</PropertyContext.Provider>;\n }\n\n return null;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,OAAO;AAC9F,SAASC,WAAW,EAAEC,QAAQ;AAE9B,MAAMC,uBAAuB,gBAAGR,aAAa,CAAqBS,SAAS,CAAC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IAAER;EAAM,CAAC;EAEvEvE,SAAS,CAAC,MAAM;IACZ,IAAIsE,MAAM,EAAE;MACRlB,cAAc,CAACsB,QAAQ,CAAC;MACxB;IACJ;IAEA,IAAIL,OAAO,EAAE;MACThB,eAAe,CAACgB,OAAO,EAAE7C,QAAQ,CAAC;MAClC;IACJ;IAEA,MAAMwD,QAAQ,GAAGvD,MAAM,KAAK,QAAQ;IACpC,MAAMwD,OAAO,GAAG9C,KAAK,KAAK,OAAO;IAEjCe,WAAW,CAAC;MAAE,GAAG1B,QAAQ;MAAEwD,QAAQ;MAAEC;IAAQ,CAAC,EAAE;MAAE9C,KAAK;MAAEV;IAAO,CAAC,CAAC;IAElE,OAAO,MAAM;MACT2B,cAAc,CAACsB,QAAQ,CAAC;IAC5B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN1E,SAAS,CAAC,MAAM;IACZ,IAAI8E,aAAa,CAACI,OAAO,KAAKrE,KAAK,EAAE;MACjCiE,aAAa,CAACI,OAAO,GAAGrE,KAAK;MAC7B,IAAI,CAACyD,MAAM,IAAI,CAACD,OAAO,EAAE;QACrBhB,eAAe,CAACqB,QAAQ,EAAElD,QAAQ,CAAC;MACvC;IACJ;EACJ,CAAC,EAAE,CAACX,KAAK,CAAC,CAAC;EAEX,IAAIH,QAAQ,EAAE;IACV,oBAAOb,KAAA,CAAAc,aAAA,CAAC+C,eAAe,CAAC9C,QAAQ;MAACC,KAAK,EAAEW;IAAS,GAAEd,QAAmC,CAAC;EAC3F;EAEA,OAAO,IAAI;AACf,CAAC","ignoreList":[]}
|
|
1
|
+
{"version":3,"names":["React","createContext","useContext","useEffect","useMemo","useRef","getUniqueId","toObject","PropertyStore","usePropertyPriority","PropertiesTargetContext","undefined","ConnectToProperties","name","children","createElement","Provider","value","PropertiesContext","Properties","onChange","storeRef","current","store","parent","useProperties","subscribe","properties","context","getAncestor","ancestorName","getObject","allProperties","addProperty","property","options","removeProperty","id","replaceProperty","Error","useMaybeProperties","useAncestorByName","PropertyContext","useParentProperty","useAncestor","params","matchOrGetAncestor","getChildrenOf","matchedProps","filter","prop","length","Object","keys","newParent","getById","Property","after","before","replace","remove","array","root","targetName","uniqueId","parentProperty","immediateProperties","ancestorByName","previousValue","priority","propertyStore","parentId","registerLookup","$isFirst","$isLast"],"sources":["Properties.tsx"],"sourcesContent":["import React, { createContext, useContext, useEffect, useMemo, useRef } from \"react\";\nimport { getUniqueId, toObject } from \"./utils.js\";\nimport { PropertyStore } from \"./domain/index.js\";\nimport { usePropertyPriority } from \"./PropertyPriority.js\";\n\nconst PropertiesTargetContext = createContext<string | undefined>(undefined);\n\nexport interface ConnectToPropertiesProps {\n name: string;\n children: React.ReactNode;\n}\n\nexport const ConnectToProperties = ({ name, children }: ConnectToPropertiesProps) => {\n return (\n <PropertiesTargetContext.Provider value={name}>{children}</PropertiesTargetContext.Provider>\n );\n};\n\nexport interface Property {\n id: string;\n parent: string;\n name: string;\n value?: unknown;\n array?: boolean;\n $isFirst?: boolean;\n $isLast?: boolean;\n}\n\ninterface AddPropertyOptions {\n after?: string;\n before?: string;\n priority?: number;\n}\n\ninterface PropertiesContext {\n name?: string;\n store: PropertyStore;\n getAncestor(name: string): PropertiesContext | undefined;\n getObject<T = unknown>(): T;\n addProperty(property: Property, options?: AddPropertyOptions): void;\n removeProperty(id: string): void;\n replaceProperty(id: string, property: Property): void;\n}\n\nconst PropertiesContext = createContext<PropertiesContext | undefined>(undefined);\n\ninterface PropertiesProps {\n name?: string;\n onChange?(properties: Property[]): void;\n children: React.ReactNode;\n}\n\nexport const Properties = ({ name, onChange, children }: PropertiesProps) => {\n const storeRef = useRef<PropertyStore | null>(null);\n if (!storeRef.current) {\n storeRef.current = new PropertyStore();\n }\n const store = storeRef.current;\n\n let parent: PropertiesContext;\n\n try {\n parent = useProperties();\n } catch {\n // Do nothing, if there's no parent.\n }\n\n useEffect(() => {\n if (!onChange) {\n return;\n }\n\n return store.subscribe(properties => {\n onChange(properties);\n });\n }, [store, onChange]);\n\n // Context value is stable — it never changes after mount.\n // Children never re-render due to context changes.\n const context: PropertiesContext = useMemo(\n () => ({\n name,\n store,\n getAncestor(ancestorName: string) {\n if (!parent) {\n return undefined;\n }\n\n return parent && parent.name === ancestorName\n ? parent\n : parent.getAncestor(ancestorName);\n },\n getObject<T>() {\n return toObject(store.allProperties) as T;\n },\n addProperty(property, options = {}) {\n store.addProperty(property, options);\n },\n removeProperty(id) {\n store.removeProperty(id);\n },\n replaceProperty(id, property) {\n store.replaceProperty(id, property);\n }\n }),\n [store]\n );\n\n return <PropertiesContext.Provider value={context}>{children}</PropertiesContext.Provider>;\n};\n\nexport function useProperties() {\n const context = useContext(PropertiesContext);\n if (!context) {\n throw Error(\"Properties context provider is missing!\");\n }\n\n return context;\n}\n\nexport function useMaybeProperties() {\n return useContext(PropertiesContext);\n}\n\nexport function useAncestorByName(name: string | undefined) {\n const parent = useMaybeProperties();\n\n return useMemo(() => {\n if (!name || !parent) {\n return undefined;\n }\n\n if (parent.name === name) {\n return parent;\n }\n\n return parent.getAncestor(name);\n }, [name]);\n}\n\ninterface PropertyProps {\n id?: string;\n name: string;\n value?: unknown;\n array?: boolean;\n after?: string;\n before?: string;\n replace?: string;\n remove?: boolean;\n parent?: string;\n root?: boolean;\n children?: React.ReactNode;\n}\n\nconst PropertyContext = createContext<Property | undefined>(undefined);\n\nexport function useParentProperty() {\n return useContext(PropertyContext);\n}\n\ninterface AncestorMatch {\n [key: string]: string | boolean | number | null | undefined;\n}\n\nexport function useAncestor(params: AncestorMatch) {\n const property = useParentProperty();\n const { store } = useProperties();\n\n const matchOrGetAncestor = (\n property: Property,\n params: AncestorMatch\n ): Property | undefined => {\n const children = store.getChildrenOf(property.id);\n const matchedProps = children.filter(\n prop => prop.name in params && prop.value === params[prop.name]\n );\n\n if (matchedProps.length === Object.keys(params).length) {\n return property;\n }\n\n const newParent = property.parent ? store.getById(property.parent) : undefined;\n\n return newParent ? matchOrGetAncestor(newParent, params) : undefined;\n };\n\n return property ? matchOrGetAncestor(property, params) : undefined;\n}\n\nexport const Property = ({\n id,\n name,\n value,\n children,\n after = undefined,\n before = undefined,\n replace = undefined,\n remove = false,\n array = false,\n root = false,\n parent = undefined\n}: PropertyProps) => {\n const targetName = useContext(PropertiesTargetContext);\n const uniqueId = useMemo(() => id || getUniqueId(), []);\n const parentProperty = useParentProperty();\n const immediateProperties = useProperties();\n const ancestorByName = useAncestorByName(targetName);\n const previousValue = useRef(value);\n const priority = usePropertyPriority();\n\n const properties = targetName && ancestorByName ? ancestorByName : immediateProperties;\n\n if (!properties) {\n throw Error(\"<Properties> provider is missing higher in the hierarchy!\");\n }\n\n const { addProperty, removeProperty, replaceProperty, store: propertyStore } = properties;\n const parentId = parent ? parent : root ? \"\" : parentProperty?.id || \"\";\n const property = { id: uniqueId, name, value, parent: parentId, array };\n\n // Register in the synchronous lookup during render so useAncestor can find this property.\n if (!remove) {\n propertyStore.registerLookup(property);\n }\n\n useEffect(() => {\n if (remove) {\n removeProperty(uniqueId);\n return;\n }\n\n if (replace) {\n replaceProperty(replace, property);\n return;\n }\n\n const $isFirst = before === \"$first\";\n const $isLast = after === \"$last\";\n\n addProperty({ ...property, $isFirst, $isLast }, { after, before, priority });\n\n return () => {\n removeProperty(uniqueId);\n };\n }, []);\n\n useEffect(() => {\n if (previousValue.current !== value) {\n previousValue.current = value;\n if (!remove && !replace) {\n replaceProperty(uniqueId, property);\n }\n }\n }, [value]);\n\n if (children) {\n return <PropertyContext.Provider value={property}>{children}</PropertyContext.Provider>;\n }\n\n return null;\n};\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,MAAM,QAAQ,OAAO;AACpF,SAASC,WAAW,EAAEC,QAAQ;AAC9B,SAASC,aAAa;AACtB,SAASC,mBAAmB;AAE5B,MAAMC,uBAAuB,gBAAGT,aAAa,CAAqBU,SAAS,CAAC;AAO5E,OAAO,MAAMC,mBAAmB,GAAGA,CA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AClC;IACJ;IAEA,MAAMuC,QAAQ,GAAGf,MAAM,KAAK,QAAQ;IACpC,MAAMgB,OAAO,GAAGjB,KAAK,KAAK,OAAO;IAEjCxB,WAAW,CAAC;MAAE,GAAGC,QAAQ;MAAEuC,QAAQ;MAAEC;IAAQ,CAAC,EAAE;MAAEjB,KAAK;MAAEC,MAAM;MAAEW;IAAS,CAAC,CAAC;IAE5E,OAAO,MAAM;MACTjC,cAAc,CAAC4B,QAAQ,CAAC;IAC5B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN7D,SAAS,CAAC,MAAM;IACZ,IAAIiE,aAAa,CAAC9C,OAAO,KAAKL,KAAK,EAAE;MACjCmD,aAAa,CAAC9C,OAAO,GAAGL,KAAK;MAC7B,IAAI,CAAC2C,MAAM,IAAI,CAACD,OAAO,EAAE;QACrBrB,eAAe,CAAC0B,QAAQ,EAAE9B,QAAQ,CAAC;MACvC;IACJ;EACJ,CAAC,EAAE,CAACjB,KAAK,CAAC,CAAC;EAEX,IAAIH,QAAQ,EAAE;IACV,oBAAOd,KAAA,CAAAe,aAAA,CAAC2B,eAAe,CAAC1B,QAAQ;MAACC,KAAK,EAAEiB;IAAS,GAAEpB,QAAmC,CAAC;EAC3F;EAEA,OAAO,IAAI;AACf,CAAC","ignoreList":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
interface PropertyPriorityProviderProps {
|
|
3
|
+
priority: number;
|
|
4
|
+
children: React.ReactNode;
|
|
5
|
+
}
|
|
6
|
+
export declare const PropertyPriorityProvider: ({ priority, children }: PropertyPriorityProviderProps) => React.JSX.Element;
|
|
7
|
+
export declare function usePropertyPriority(): number;
|
|
8
|
+
export {};
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import React, { createContext, useContext } from "react";
|
|
2
|
+
const PropertyPriorityContext = /*#__PURE__*/createContext(0);
|
|
3
|
+
export const PropertyPriorityProvider = ({
|
|
4
|
+
priority,
|
|
5
|
+
children
|
|
6
|
+
}) => {
|
|
7
|
+
return /*#__PURE__*/React.createElement(PropertyPriorityContext.Provider, {
|
|
8
|
+
value: priority
|
|
9
|
+
}, children);
|
|
10
|
+
};
|
|
11
|
+
export function usePropertyPriority() {
|
|
12
|
+
return useContext(PropertyPriorityContext);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
//# sourceMappingURL=PropertyPriority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["React","createContext","useContext","PropertyPriorityContext","PropertyPriorityProvider","priority","children","createElement","Provider","value","usePropertyPriority"],"sources":["PropertyPriority.tsx"],"sourcesContent":["import React, { createContext, useContext } from \"react\";\n\nconst PropertyPriorityContext = createContext(0);\n\ninterface PropertyPriorityProviderProps {\n priority: number;\n children: React.ReactNode;\n}\n\nexport const PropertyPriorityProvider = ({ priority, children }: PropertyPriorityProviderProps) => {\n return (\n <PropertyPriorityContext.Provider value={priority}>\n {children}\n </PropertyPriorityContext.Provider>\n );\n};\n\nexport function usePropertyPriority(): number {\n return useContext(PropertyPriorityContext);\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,QAAQ,OAAO;AAExD,MAAMC,uBAAuB,gBAAGF,aAAa,CAAC,CAAC,CAAC;AAOhD,OAAO,MAAMG,wBAAwB,GAAGA,CAAC;EAAEC,QAAQ;EAAEC;AAAwC,CAAC,KAAK;EAC/F,oBACIN,KAAA,CAAAO,aAAA,CAACJ,uBAAuB,CAACK,QAAQ;IAACC,KAAK,EAAEJ;EAAS,GAC7CC,QAC6B,CAAC;AAE3C,CAAC;AAED,OAAO,SAASI,mBAAmBA,CAAA,EAAW;EAC1C,OAAOR,UAAU,CAACC,uBAAuB,CAAC;AAC9C","ignoreList":[]}
|
|
@@ -1,19 +1,30 @@
|
|
|
1
|
-
import React, { useContext, useEffect, useMemo, useState } from "react";
|
|
1
|
+
import React, { useCallback, useContext, useEffect, useMemo, useState } from "react";
|
|
2
2
|
import { Compose, makeDecoratable } from "@webiny/react-composition";
|
|
3
3
|
import { Properties, toObject } from "./index.js";
|
|
4
4
|
import { useDebugConfig } from "./useDebugConfig.js";
|
|
5
|
-
import
|
|
5
|
+
import { PropertyPriorityProvider } from "./PropertyPriority.js";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Each `<Config>` call composes a new HOC around the previous one via `Compose`.
|
|
9
|
+
* The last composed HOC is the outermost wrapper. By placing `{newChildren}`
|
|
10
|
+
* (this HOC's addition) before `{children}` (all previously composed configs),
|
|
11
|
+
* the final render order matches declaration order:
|
|
12
|
+
*
|
|
13
|
+
* <Config>A</Config> → renders first (outermost HOC, its newChildren rendered first)
|
|
14
|
+
* <Config>B</Config> → renders second
|
|
15
|
+
* <Config>C</Config> → renders third (innermost, rendered last via children chain)
|
|
16
|
+
*
|
|
17
|
+
* This is important because Property components register in mount order,
|
|
18
|
+
* so declaration order = mount order = predictable config resolution.
|
|
19
|
+
*/
|
|
6
20
|
const createHOC = newChildren => BaseComponent => {
|
|
7
21
|
return function ConfigHOC({
|
|
8
22
|
children
|
|
9
23
|
}) {
|
|
10
|
-
return /*#__PURE__*/React.createElement(BaseComponent, null,
|
|
24
|
+
return /*#__PURE__*/React.createElement(BaseComponent, null, newChildren, children);
|
|
11
25
|
};
|
|
12
26
|
};
|
|
13
27
|
export function createConfigurableComponent(name) {
|
|
14
|
-
/**
|
|
15
|
-
* This component is used when we want to mount all composed configs.
|
|
16
|
-
*/
|
|
17
28
|
const ConfigApplyPrimary = makeDecoratable(`${name}ConfigApply<Primary>`, ({
|
|
18
29
|
children
|
|
19
30
|
}) => {
|
|
@@ -24,10 +35,6 @@ export function createConfigurableComponent(name) {
|
|
|
24
35
|
}) => {
|
|
25
36
|
return /*#__PURE__*/React.createElement(React.Fragment, null, children);
|
|
26
37
|
});
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* This component is used to configure the component (it can be mounted many times).
|
|
30
|
-
*/
|
|
31
38
|
const Config = ({
|
|
32
39
|
priority = "primary",
|
|
33
40
|
children
|
|
@@ -47,28 +54,47 @@ export function createConfigurableComponent(name) {
|
|
|
47
54
|
properties: []
|
|
48
55
|
};
|
|
49
56
|
const ViewContext = /*#__PURE__*/React.createContext(defaultContext);
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Memoized config subtree — ConfigApply components don't depend on WithConfig
|
|
60
|
+
* props, so they must not remount when the parent re-renders. Without this,
|
|
61
|
+
* every parent re-render causes Property components inside HOCs to unmount
|
|
62
|
+
* and remount, corrupting the config object.
|
|
63
|
+
*/
|
|
64
|
+
const ConfigApplyTree = /*#__PURE__*/React.memo(function ConfigApplyTree() {
|
|
65
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ConfigApplyPrimary, null), /*#__PURE__*/React.createElement(PropertyPriorityProvider, {
|
|
66
|
+
priority: 1
|
|
67
|
+
}, /*#__PURE__*/React.createElement(ConfigApplySecondary, null)));
|
|
68
|
+
});
|
|
50
69
|
const WithConfig = ({
|
|
51
70
|
onProperties,
|
|
52
71
|
children
|
|
53
72
|
}) => {
|
|
54
|
-
|
|
55
|
-
|
|
73
|
+
// `null` = config not yet collected; `[]` = collected but empty.
|
|
74
|
+
// This distinction is critical: children must NOT render until the
|
|
75
|
+
// PropertyStore debounce has flushed and delivered the initial config.
|
|
76
|
+
// Rendering children with partial/empty config causes errors in
|
|
77
|
+
// consumers like LexicalEditor that require a complete config on mount.
|
|
78
|
+
const [properties, setProperties] = useState(null);
|
|
79
|
+
const resolvedProperties = properties ?? [];
|
|
80
|
+
useDebugConfig(name, resolvedProperties);
|
|
56
81
|
const context = {
|
|
57
|
-
properties
|
|
82
|
+
properties: resolvedProperties
|
|
58
83
|
};
|
|
59
84
|
useEffect(() => {
|
|
60
|
-
if (typeof onProperties === "function") {
|
|
85
|
+
if (properties !== null && typeof onProperties === "function") {
|
|
61
86
|
onProperties(properties);
|
|
62
87
|
}
|
|
63
88
|
}, [properties]);
|
|
64
|
-
const stateUpdater = properties => {
|
|
89
|
+
const stateUpdater = useCallback(properties => {
|
|
65
90
|
setProperties(properties);
|
|
66
|
-
};
|
|
91
|
+
}, []);
|
|
67
92
|
return /*#__PURE__*/React.createElement(ViewContext.Provider, {
|
|
68
93
|
value: context
|
|
69
94
|
}, /*#__PURE__*/React.createElement(Properties, {
|
|
95
|
+
name: name,
|
|
70
96
|
onChange: stateUpdater
|
|
71
|
-
}, /*#__PURE__*/React.createElement(
|
|
97
|
+
}, /*#__PURE__*/React.createElement(ConfigApplyTree, null)), properties !== null ? children : null);
|
|
72
98
|
};
|
|
73
99
|
function useConfig() {
|
|
74
100
|
const {
|
|
@@ -76,27 +102,6 @@ export function createConfigurableComponent(name) {
|
|
|
76
102
|
} = useContext(ViewContext);
|
|
77
103
|
return useMemo(() => toObject(properties), [properties]);
|
|
78
104
|
}
|
|
79
|
-
const DebounceRenderer = ({
|
|
80
|
-
children
|
|
81
|
-
}) => {
|
|
82
|
-
const [render, setRender] = useState(false);
|
|
83
|
-
const editorConfig = useConfig();
|
|
84
|
-
const debouncedRender = useMemo(() => {
|
|
85
|
-
return debounce(() => {
|
|
86
|
-
setRender(true);
|
|
87
|
-
}, 10);
|
|
88
|
-
}, [setRender]);
|
|
89
|
-
useEffect(() => {
|
|
90
|
-
if (render) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
debouncedRender();
|
|
94
|
-
return () => {
|
|
95
|
-
debouncedRender.cancel();
|
|
96
|
-
};
|
|
97
|
-
}, [editorConfig]);
|
|
98
|
-
return /*#__PURE__*/React.createElement(React.Fragment, null, render ? children : null);
|
|
99
|
-
};
|
|
100
105
|
return {
|
|
101
106
|
WithConfig,
|
|
102
107
|
Config,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["React","useContext","useEffect","useMemo","useState","Compose","makeDecoratable","Properties","toObject","useDebugConfig","
|
|
1
|
+
{"version":3,"names":["React","useCallback","useContext","useEffect","useMemo","useState","Compose","makeDecoratable","Properties","toObject","useDebugConfig","PropertyPriorityProvider","createHOC","newChildren","BaseComponent","ConfigHOC","children","createElement","createConfigurableComponent","name","ConfigApplyPrimary","Fragment","ConfigApplySecondary","Config","priority","component","with","defaultContext","properties","ViewContext","createContext","ConfigApplyTree","memo","WithConfig","onProperties","setProperties","resolvedProperties","context","stateUpdater","Provider","value","onChange","useConfig"],"sources":["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"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,WAAW,EAAEC,UAAU,EAAEC,SAAS,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AAEpF,SAASC,OAAO,EAAEC,eAAe,QAAQ,2BAA2B;AAGpE,SAASC,UAAU,EAAEC,QAAQ;AAC7B,SAASC,cAAc;AACvB,SAASC,wBAAwB;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,SAAS,GACVC,WAA4B,IAC7BC,aAAa,IAAI;EACb,OAAO,SAASC,SAASA,CAAC;IAAEC;EAAS,CAAC,EAAE;IACpC,oBACIhB,KAAA,CAAAiB,aAAA,CAACH,aAAa,QACTD,WAAW,EACXG,QACU,CAAC;EAExB,CAAC;AACL,CAAC;AAgBL,OAAO,SAASE,2BAA2BA,CAAUC,IAAY,EAAE;EAC/D,MAAMC,kBAAkB,GAAGb,eAAe,CACtC,GAAGY,IAAI,sBAAsB,EAC7B,CAAC;IAAEH;EAA2B,CAAC,KAAK;IAChC,oBAAOhB,KAAA,CAAAiB,aAAA,CAAAjB,KAAA,CAAAqB,QAAA,QAAGL,QAAW,CAAC;EAC1B,CACJ,CAAC;EAED,MAAMM,oBAAoB,GAAGf,eAAe,CACxC,GAAGY,IAAI,wBAAwB,EAC/B,CAAC;IAAEH;EAA2B,CAAC,KAAK;IAChC,oBAAOhB,KAAA,CAAAiB,aAAA,CAAAjB,KAAA,CAAAqB,QAAA,QAAGL,QAAW,CAAC;EAC1B,CACJ,CAAC;EAED,MAAMO,MAAM,GAAGA,CAAC;IAAEC,QAAQ,GAAG,SAAS;IAAER;EAAsB,CAAC,KAAK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AI,OAAOM,YAAY,KAAK,UAAU,EAAE;QAC3DA,YAAY,CAACN,UAAU,CAAC;MAC5B;IACJ,CAAC,EAAE,CAACA,UAAU,CAAC,CAAC;IAEhB,MAAMU,YAAY,GAAGrC,WAAW,CAAE2B,UAAsB,IAAK;MACzDO,aAAa,CAACP,UAAU,CAAC;IAC7B,CAAC,EAAE,EAAE,CAAC;IAEN,oBACI5B,KAAA,CAAAiB,aAAA,CAACY,WAAW,CAACU,QAAQ;MAACC,KAAK,EAAEH;IAAQ,gBAIjCrC,KAAA,CAAAiB,aAAA,CAACT,UAAU;MAACW,IAAI,EAAEA,IAAK;MAACsB,QAAQ,EAAEH;IAAa,gBAC3CtC,KAAA,CAAAiB,aAAA,CAACc,eAAe,MAAE,CACV,CAAC,EAIZH,UAAU,KAAK,IAAI,GAAGZ,QAAQ,GAAG,IAChB,CAAC;EAE/B,CAAC;EAED,SAAS0B,SAASA,CAAA,EAA4C;IAC1D,MAAM;MAAEd;IAAW,CAAC,GAAG1B,UAAU,CAAC2B,WAAW,CAAC;IAC9C,OAAOzB,OAAO,CAAC,MAAMK,QAAQ,CAAmBmB,UAAU,CAAC,EAAE,CAACA,UAAU,CAAC,CAAC;EAC9E;EAEA,OAAO;IACHK,UAAU;IACVV,MAAM;IACNmB;EACJ,CAAC;AACL","ignoreList":[]}
|
|
@@ -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,229 @@
|
|
|
1
|
+
import debounce from "lodash/debounce.js";
|
|
2
|
+
export class PropertyStore {
|
|
3
|
+
map = new Map();
|
|
4
|
+
order = [];
|
|
5
|
+
queue = [];
|
|
6
|
+
listeners = new Set();
|
|
7
|
+
priorities = new Map();
|
|
8
|
+
/** Properties that were explicitly positioned via before/after. */
|
|
9
|
+
positioned = new Set();
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Synchronous lookup map — written immediately on addProperty (before debounce),
|
|
13
|
+
* so useAncestor can find properties during render.
|
|
14
|
+
*/
|
|
15
|
+
lookup = new Map();
|
|
16
|
+
scheduleFlush = debounce(() => {
|
|
17
|
+
this.processQueue();
|
|
18
|
+
}, 0);
|
|
19
|
+
get allProperties() {
|
|
20
|
+
return this.order.filter(id => this.map.has(id)).map(id => this.map.get(id));
|
|
21
|
+
}
|
|
22
|
+
subscribe(listener) {
|
|
23
|
+
this.listeners.add(listener);
|
|
24
|
+
return () => {
|
|
25
|
+
this.listeners.delete(listener);
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* Returns properties that are children of the given parent ID.
|
|
31
|
+
* Reads from the synchronous lookup map, so it works during render
|
|
32
|
+
* before the debounced queue has flushed.
|
|
33
|
+
*/
|
|
34
|
+
getChildrenOf(parentId) {
|
|
35
|
+
return Array.from(this.lookup.values()).filter(p => p.parent === parentId);
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* Find a property by ID from the synchronous lookup map.
|
|
40
|
+
*/
|
|
41
|
+
getById(id) {
|
|
42
|
+
return this.lookup.get(id);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Register a property in the synchronous lookup map during render,
|
|
47
|
+
* so useAncestor can find it before the debounced queue flushes.
|
|
48
|
+
*/
|
|
49
|
+
registerLookup(property) {
|
|
50
|
+
if (this.lookup.has(property.id)) {
|
|
51
|
+
const existing = this.lookup.get(property.id);
|
|
52
|
+
this.lookup.set(property.id, {
|
|
53
|
+
...existing,
|
|
54
|
+
...property
|
|
55
|
+
});
|
|
56
|
+
} else {
|
|
57
|
+
this.lookup.set(property.id, property);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
addProperty(property, options = {}) {
|
|
61
|
+
this.registerLookup(property);
|
|
62
|
+
this.queue.push({
|
|
63
|
+
type: "add",
|
|
64
|
+
property,
|
|
65
|
+
options
|
|
66
|
+
});
|
|
67
|
+
this.scheduleFlush();
|
|
68
|
+
}
|
|
69
|
+
removeProperty(id) {
|
|
70
|
+
this.lookup.delete(id);
|
|
71
|
+
this.queue.push({
|
|
72
|
+
type: "remove",
|
|
73
|
+
id
|
|
74
|
+
});
|
|
75
|
+
this.scheduleFlush();
|
|
76
|
+
}
|
|
77
|
+
replaceProperty(oldId, newProperty) {
|
|
78
|
+
this.lookup.delete(oldId);
|
|
79
|
+
this.lookup.set(newProperty.id, newProperty);
|
|
80
|
+
this.queue.push({
|
|
81
|
+
type: "replace",
|
|
82
|
+
oldId,
|
|
83
|
+
newProperty
|
|
84
|
+
});
|
|
85
|
+
this.scheduleFlush();
|
|
86
|
+
}
|
|
87
|
+
processQueue() {
|
|
88
|
+
if (this.queue.length === 0) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
const ops = this.queue.splice(0);
|
|
92
|
+
|
|
93
|
+
// Stable-sort operations so that "add" ops with lower priority numbers
|
|
94
|
+
// are processed first. Non-add operations and adds with default priority (0)
|
|
95
|
+
// keep their original order.
|
|
96
|
+
ops.sort((a, b) => {
|
|
97
|
+
const pa = a.type === "add" ? a.options.priority ?? 0 : 0;
|
|
98
|
+
const pb = b.type === "add" ? b.options.priority ?? 0 : 0;
|
|
99
|
+
return pa - pb;
|
|
100
|
+
});
|
|
101
|
+
for (const op of ops) {
|
|
102
|
+
switch (op.type) {
|
|
103
|
+
case "add":
|
|
104
|
+
this.executeAdd(op.property, op.options);
|
|
105
|
+
break;
|
|
106
|
+
case "remove":
|
|
107
|
+
this.executeRemove(op.id);
|
|
108
|
+
break;
|
|
109
|
+
case "replace":
|
|
110
|
+
this.executeReplace(op.oldId, op.newProperty);
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
// Stable-sort the order array by priority, but only for properties
|
|
116
|
+
// that were NOT explicitly positioned via before/after. Explicitly
|
|
117
|
+
// positioned properties keep their placement.
|
|
118
|
+
this.order.sort((a, b) => {
|
|
119
|
+
if (this.positioned.has(a) || this.positioned.has(b)) {
|
|
120
|
+
return 0;
|
|
121
|
+
}
|
|
122
|
+
return (this.priorities.get(a) ?? 0) - (this.priorities.get(b) ?? 0);
|
|
123
|
+
});
|
|
124
|
+
const properties = this.allProperties;
|
|
125
|
+
for (const listener of this.listeners) {
|
|
126
|
+
listener(properties);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
executeAdd(property, options) {
|
|
130
|
+
if (options.after || options.before) {
|
|
131
|
+
this.positioned.add(property.id);
|
|
132
|
+
}
|
|
133
|
+
const exists = this.map.has(property.id);
|
|
134
|
+
if (exists) {
|
|
135
|
+
// Merge into existing property. Keep the original priority so
|
|
136
|
+
// that a secondary config overriding a primary property doesn't
|
|
137
|
+
// cause the re-sort to move it after all primary properties.
|
|
138
|
+
const existing = this.map.get(property.id);
|
|
139
|
+
this.map.set(property.id, {
|
|
140
|
+
...existing,
|
|
141
|
+
...property
|
|
142
|
+
});
|
|
143
|
+
if (options.after) {
|
|
144
|
+
this.reposition(property.id, options.after, "after");
|
|
145
|
+
} else if (options.before) {
|
|
146
|
+
this.reposition(property.id, options.before, "before");
|
|
147
|
+
}
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
this.map.set(property.id, property);
|
|
151
|
+
// Set priority only for new properties — not merges (handled above).
|
|
152
|
+
this.priorities.set(property.id, options.priority ?? 0);
|
|
153
|
+
if (options.after) {
|
|
154
|
+
this.insertAfter(property.id, options.after);
|
|
155
|
+
} else if (options.before) {
|
|
156
|
+
this.insertBefore(property.id, options.before);
|
|
157
|
+
} else {
|
|
158
|
+
this.order.push(property.id);
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
executeRemove(id) {
|
|
162
|
+
if (!this.map.has(id)) {
|
|
163
|
+
return;
|
|
164
|
+
}
|
|
165
|
+
this.map.delete(id);
|
|
166
|
+
this.priorities.delete(id);
|
|
167
|
+
this.positioned.delete(id);
|
|
168
|
+
this.order = this.order.filter(oid => oid !== id);
|
|
169
|
+
// Note: we intentionally do NOT call removeDescendants here.
|
|
170
|
+
// React's component lifecycle ensures that when a parent Property
|
|
171
|
+
// unmounts, all child Properties unmount too — each triggering its
|
|
172
|
+
// own removeProperty call. Calling removeDescendants would wipe
|
|
173
|
+
// children that belong to OTHER still-mounted configs sharing the
|
|
174
|
+
// same parent ID (e.g., id="pageSettings" used by both primary
|
|
175
|
+
// and secondary configs).
|
|
176
|
+
}
|
|
177
|
+
executeReplace(oldId, newProperty) {
|
|
178
|
+
const idx = this.order.indexOf(oldId);
|
|
179
|
+
if (idx === -1) {
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
this.map.delete(oldId);
|
|
183
|
+
this.map.set(newProperty.id, newProperty);
|
|
184
|
+
this.order[idx] = newProperty.id;
|
|
185
|
+
this.removeDescendants(oldId);
|
|
186
|
+
}
|
|
187
|
+
insertBefore(id, before) {
|
|
188
|
+
if (before.endsWith("$first")) {
|
|
189
|
+
this.order.unshift(id);
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
const targetIdx = this.order.indexOf(before);
|
|
193
|
+
if (targetIdx === -1) {
|
|
194
|
+
this.order.push(id);
|
|
195
|
+
return;
|
|
196
|
+
}
|
|
197
|
+
this.order.splice(targetIdx, 0, id);
|
|
198
|
+
}
|
|
199
|
+
insertAfter(id, after) {
|
|
200
|
+
if (after.endsWith("$last")) {
|
|
201
|
+
this.order.push(id);
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
204
|
+
const targetIdx = this.order.indexOf(after);
|
|
205
|
+
if (targetIdx === -1) {
|
|
206
|
+
this.order.push(id);
|
|
207
|
+
return;
|
|
208
|
+
}
|
|
209
|
+
this.order.splice(targetIdx + 1, 0, id);
|
|
210
|
+
}
|
|
211
|
+
reposition(id, targetId, position) {
|
|
212
|
+
this.order = this.order.filter(oid => oid !== id);
|
|
213
|
+
if (position === "before") {
|
|
214
|
+
this.insertBefore(id, targetId);
|
|
215
|
+
} else {
|
|
216
|
+
this.insertAfter(id, targetId);
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
removeDescendants(parentId) {
|
|
220
|
+
const children = Array.from(this.map.values()).filter(p => p.parent === parentId);
|
|
221
|
+
for (const child of children) {
|
|
222
|
+
this.map.delete(child.id);
|
|
223
|
+
this.order = this.order.filter(oid => oid !== child.id);
|
|
224
|
+
this.removeDescendants(child.id);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
//# sourceMappingURL=PropertyStore.js.map
|
|
@@ -0,0 +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,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,CAACgD,GAAG,IAAIA,GAAG,KAAKU,KAAK,CAACzD,EAAE,CAAC;MACvD,IAAI,CAACkD,iBAAiB,CAACO,KAAK,CAACzD,EAAE,CAAC;IACpC;EACJ;AACJ","ignoreList":[]}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PropertyStore } from "./PropertyStore.js";
|
package/domain/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["PropertyStore"],"sources":["index.ts"],"sourcesContent":["export { PropertyStore } from \"./PropertyStore.js\";\n"],"mappings":"AAAA,SAASA,aAAa","ignoreList":[]}
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -3,5 +3,7 @@ export * from "./Properties.js";
|
|
|
3
3
|
export * from "./useDebugConfig.js";
|
|
4
4
|
export * from "./useIdGenerator.js";
|
|
5
5
|
export * from "./createConfigurableComponent.js";
|
|
6
|
+
export * from "./domain/index.js";
|
|
7
|
+
export { DevToolsSection } from "./DevToolsSection.js";
|
|
6
8
|
|
|
7
9
|
//# sourceMappingURL=index.js.map
|
package/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./utils.js\";\nexport * from \"./Properties.js\";\nexport * from \"./useDebugConfig.js\";\nexport * from \"./useIdGenerator.js\";\nexport * from \"./createConfigurableComponent.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA","ignoreList":[]}
|
|
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":[]}
|
package/package.json
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/react-properties",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.e6f0dc8ca7",
|
|
4
4
|
"type": "module",
|
|
5
|
-
"
|
|
5
|
+
"exports": {
|
|
6
|
+
".": "./index.js",
|
|
7
|
+
"./*": "./*"
|
|
8
|
+
},
|
|
6
9
|
"repository": {
|
|
7
10
|
"type": "git",
|
|
8
11
|
"url": "https://github.com/webiny/webiny-js.git"
|
|
@@ -11,21 +14,21 @@
|
|
|
11
14
|
"author": "Webiny Ltd",
|
|
12
15
|
"license": "MIT",
|
|
13
16
|
"dependencies": {
|
|
14
|
-
"@types/react": "18.
|
|
15
|
-
"@webiny/react-composition": "0.0.0-unstable.
|
|
16
|
-
"lodash": "4.
|
|
17
|
-
"nanoid": "
|
|
18
|
-
"react": "18.
|
|
17
|
+
"@types/react": "18.3.28",
|
|
18
|
+
"@webiny/react-composition": "0.0.0-unstable.e6f0dc8ca7",
|
|
19
|
+
"lodash": "4.18.1",
|
|
20
|
+
"nanoid": "5.1.11",
|
|
21
|
+
"react": "18.3.1"
|
|
19
22
|
},
|
|
20
23
|
"devDependencies": {
|
|
21
|
-
"@testing-library/react": "
|
|
22
|
-
"@webiny/build-tools": "0.0.0-unstable.
|
|
23
|
-
"
|
|
24
|
-
"vitest": "
|
|
24
|
+
"@testing-library/react": "16.3.2",
|
|
25
|
+
"@webiny/build-tools": "0.0.0-unstable.e6f0dc8ca7",
|
|
26
|
+
"oxfmt": "0.48.0",
|
|
27
|
+
"vitest": "4.1.5"
|
|
25
28
|
},
|
|
26
29
|
"publishConfig": {
|
|
27
30
|
"access": "public",
|
|
28
31
|
"directory": "dist"
|
|
29
32
|
},
|
|
30
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "e6f0dc8ca741c1fcc3fec9a5b9e86fdd49544641"
|
|
31
34
|
}
|
package/useDebugConfig.d.ts
CHANGED
|
@@ -1,7 +1,32 @@
|
|
|
1
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,17 +1,51 @@
|
|
|
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: {}
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
return window.__WEBINY_DEVTOOLS_HOOK__;
|
|
12
|
+
}
|
|
3
13
|
export function useDebugConfig(name, properties) {
|
|
4
14
|
useEffect(() => {
|
|
5
15
|
if (process.env.NODE_ENV !== "development") {
|
|
6
16
|
return;
|
|
7
17
|
}
|
|
18
|
+
|
|
19
|
+
// Legacy console.log support
|
|
8
20
|
const configs = window.__debugConfigs ?? {};
|
|
9
21
|
configs[name] = () => console.log(toObject(properties));
|
|
10
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++;
|
|
11
38
|
return () => {
|
|
39
|
+
// Legacy cleanup
|
|
12
40
|
const configs = window.__debugConfigs ?? {};
|
|
13
41
|
delete configs[name];
|
|
14
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
|
+
}
|
|
15
49
|
};
|
|
16
50
|
}, [properties]);
|
|
17
51
|
}
|
package/useDebugConfig.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["useEffect","toObject","useDebugConfig","name","properties","process","env","NODE_ENV","
|
|
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,OAAO,SAASC,OAAOA,CAAA,EAAuB;EAC1C,IAAI,CAAC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