@webiny/react-properties 0.0.0-unstable.b14eaecf38 → 0.0.0-unstable.b6d7105cee
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/AsyncProperties.d.ts +14 -0
- package/AsyncProperties.js +43 -0
- package/AsyncProperties.js.map +1 -0
- package/Await.d.ts +7 -0
- package/Await.js +44 -0
- package/Await.js.map +1 -0
- package/DevToolsSection.d.ts +40 -0
- package/DevToolsSection.js +54 -0
- package/DevToolsSection.js.map +1 -0
- package/Properties.d.ts +19 -3
- package/Properties.js +129 -182
- package/Properties.js.map +1 -1
- package/PropertyPriority.d.ts +8 -0
- package/PropertyPriority.js +11 -0
- package/PropertyPriority.js.map +1 -0
- package/README.md +7 -61
- package/createConfigurableComponent.d.ts +15 -0
- package/createConfigurableComponent.js +67 -0
- package/createConfigurableComponent.js.map +1 -0
- package/domain/PropertyStore.d.ts +52 -0
- package/domain/PropertyStore.js +162 -0
- package/domain/PropertyStore.js.map +1 -0
- package/domain/index.d.ts +1 -0
- package/domain/index.js +1 -0
- package/index.d.ts +9 -2
- package/index.js +9 -27
- package/package.json +19 -18
- package/useDebugConfig.d.ts +32 -0
- package/useDebugConfig.js +45 -0
- package/useDebugConfig.js.map +1 -0
- package/useIdGenerator.d.ts +1 -0
- package/useIdGenerator.js +23 -0
- package/useIdGenerator.js.map +1 -0
- package/utils.d.ts +1 -1
- package/utils.js +43 -39
- package/utils.js.map +1 -1
- package/index.js.map +0 -1
package/Properties.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"names":["removeByParent","id","properties","filter","prop","parent","reduce","acc","item","PropertiesContext","createContext","undefined","Properties","onChange","children","useState","setProperties","useEffect","context","useMemo","getObject","toObject","addProperty","property","options","index","findIndex","slice","after","before","removeProperty","replaceProperty","toReplace","useProperties","useContext","Error","PropertyContext","useParentProperty","useAncestor","params","matchOrGetAncestor","matchedProps","name","value","length","Object","keys","newParent","find","Property","replace","remove","array","root","uniqueId","getUniqueId","parentProperty","parentId"],"sources":["Properties.tsx"],"sourcesContent":["import React, { createContext, useContext, useEffect, useMemo, useState } from \"react\";\nimport { getUniqueId, toObject } from \"./utils\";\n\nexport interface Property {\n id: string;\n parent: string;\n name: string;\n value?: unknown;\n array?: 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 properties: Property[];\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 onChange?(properties: Property[]): void;\n}\n\nexport const Properties: React.FC<PropertiesProps> = ({ onChange, children }) => {\n const [properties, setProperties] = useState<Property[]>([]);\n\n useEffect(() => {\n if (onChange) {\n onChange(properties);\n }\n }, [properties]);\n\n const context: PropertiesContext = useMemo(\n () => ({\n properties,\n getObject<T>() {\n return toObject(properties) as T;\n },\n addProperty(property, options = {}) {\n setProperties(properties => {\n // If a property with this ID already exists, merge the two properties.\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\n if (options.after) {\n const index = properties.findIndex(prop => prop.id === options.after);\n if (index > -1) {\n return [\n ...properties.slice(0, index + 1),\n property,\n ...properties.slice(index + 1)\n ];\n }\n }\n\n if (options.before) {\n const index = properties.findIndex(prop => prop.id === options.before);\n if (index > -1) {\n return [\n ...properties.slice(0, index),\n property,\n ...properties.slice(index)\n ];\n }\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\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}\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: React.FC<PropertyProps> = ({\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}) => {\n const uniqueId = useMemo(() => id || getUniqueId(), []);\n const parentProperty = useParentProperty();\n const properties = useProperties();\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 addProperty(property, { after, before });\n\n return () => {\n removeProperty(uniqueId);\n };\n }, []);\n\n if (children) {\n return <PropertyContext.Provider value={property}>{children}</PropertyContext.Provider>;\n }\n\n return null;\n};\n"],"mappings":";;;;;;;;;;;;;;AAAA;AACA;AAUA,SAASA,cAAc,CAACC,EAAU,EAAEC,UAAsB,EAAc;EACpE,OAAOA,UAAU,CACZC,MAAM,CAAC,UAAAC,IAAI;IAAA,OAAIA,IAAI,CAACC,MAAM,KAAKJ,EAAE;EAAA,EAAC,CAClCK,MAAM,CAAC,UAACC,GAAG,EAAEC,IAAI,EAAK;IACnB,OAAOR,cAAc,CACjBQ,IAAI,CAACP,EAAE,EACPM,GAAG,CAACJ,MAAM,CAAC,UAAAC,IAAI;MAAA,OAAIA,IAAI,CAACH,EAAE,KAAKO,IAAI,CAACP,EAAE;IAAA,EAAC,CAC1C;EACL,CAAC,EAAEC,UAAU,CAAC;AACtB;AAeA,IAAMO,iBAAiB,gBAAG,IAAAC,oBAAa,EAAgCC,SAAS,CAAC;AAM1E,IAAMC,UAAqC,GAAG,SAAxCA,UAAqC,OAA+B;EAAA,IAAzBC,QAAQ,QAARA,QAAQ;IAAEC,QAAQ,QAARA,QAAQ;EACtE,gBAAoC,IAAAC,eAAQ,EAAa,EAAE,CAAC;IAAA;IAArDb,UAAU;IAAEc,aAAa;EAEhC,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAIJ,QAAQ,EAAE;MACVA,QAAQ,CAACX,UAAU,CAAC;IACxB;EACJ,CAAC,EAAE,CAACA,UAAU,CAAC,CAAC;EAEhB,IAAMgB,OAA0B,GAAG,IAAAC,cAAO,EACtC;IAAA,OAAO;MACHjB,UAAU,EAAVA,UAAU;MACV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xB;IACJ;IAEA,IAAIJ,OAAO,EAAE;MACTnB,eAAe,CAACmB,OAAO,EAAE3B,QAAQ,CAAC;MAClC;IACJ;IAEAD,WAAW,CAACC,QAAQ,EAAE;MAAEK,KAAK,EAALA,KAAK;MAAEC,MAAM,EAANA;IAAO,CAAC,CAAC;IAExC,OAAO,YAAM;MACTC,cAAc,CAACwB,QAAQ,CAAC;IAC5B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,IAAIxC,QAAQ,EAAE;IACV,oBAAO,6BAAC,eAAe,CAAC,QAAQ;MAAC,KAAK,EAAES;IAAS,GAAET,QAAQ,CAA4B;EAC3F;EAEA,OAAO,IAAI;AACf,CAAC;AAAC"}
|
|
1
|
+
{"version":3,"file":"Properties.js","sources":["../src/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"],"names":["PropertiesTargetContext","createContext","undefined","ConnectToProperties","name","children","PropertiesContext","Properties","onChange","storeRef","useRef","PropertyStore","store","parent","useProperties","useEffect","properties","context","useMemo","ancestorName","toObject","property","options","id","useContext","Error","useMaybeProperties","useAncestorByName","PropertyContext","useParentProperty","useAncestor","params","matchOrGetAncestor","matchedProps","prop","Object","newParent","Property","value","after","before","replace","remove","array","root","targetName","uniqueId","getUniqueId","parentProperty","immediateProperties","ancestorByName","previousValue","priority","usePropertyPriority","addProperty","removeProperty","replaceProperty","propertyStore","parentId","$isFirst","$isLast"],"mappings":";;;;AAKA,MAAMA,0BAA0B,WAAHA,GAAGC,cAAkCC;AAO3D,MAAMC,sBAAsB,CAAC,EAAEC,IAAI,EAAEC,QAAQ,EAA4B,GACrE,WAAP,GACI,oBAACL,wBAAwB,QAAQ;QAAC,OAAOI;OAAOC;AA8BxD,MAAMC,oBAAoB,WAAHA,GAAGL,cAA6CC;AAQhE,MAAMK,aAAa,CAAC,EAAEH,IAAI,EAAEI,QAAQ,EAAEH,QAAQ,EAAmB;IACpE,MAAMI,WAAWC,OAA6B;IAC9C,IAAI,CAACD,SAAS,OAAO,EACjBA,SAAS,OAAO,GAAG,IAAIE;IAE3B,MAAMC,QAAQH,SAAS,OAAO;IAE9B,IAAII;IAEJ,IAAI;QACAA,SAASC;IACb,EAAE,OAAM,CAER;IAEAC,UAAU;QACN,IAAI,CAACP,UACD;QAGJ,OAAOI,MAAM,SAAS,CAACI,CAAAA;YACnBR,SAASQ;QACb;IACJ,GAAG;QAACJ;QAAOJ;KAAS;IAIpB,MAAMS,UAA6BC,QAC/B,IAAO;YACHd;YACAQ;YACA,aAAYO,YAAoB;gBAC5B,IAAI,CAACN,QACD;gBAGJ,OAAOA,UAAUA,OAAO,IAAI,KAAKM,eAC3BN,SACAA,OAAO,WAAW,CAACM;YAC7B;YACA;gBACI,OAAOC,SAASR,MAAM,aAAa;YACvC;YACA,aAAYS,QAAQ,EAAEC,UAA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,OAAO,GAAGb;YACxB,IAAI,CAACI,UAAU,CAACD,SACZe,gBAAgBV,UAAUzB;QAElC;IACJ,GAAG;QAACiB;KAAM;IAEV,IAAIjC,UACA,OAAO,WAAP,GAAO,oBAACuB,gBAAgB,QAAQ;QAAC,OAAOP;OAAWhB;IAGvD,OAAO;AACX"}
|
|
@@ -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,11 @@
|
|
|
1
|
+
import react, { createContext, useContext } from "react";
|
|
2
|
+
const PropertyPriorityContext = /*#__PURE__*/ createContext(0);
|
|
3
|
+
const PropertyPriorityProvider = ({ priority, children })=>/*#__PURE__*/ react.createElement(PropertyPriorityContext.Provider, {
|
|
4
|
+
value: priority
|
|
5
|
+
}, children);
|
|
6
|
+
function usePropertyPriority() {
|
|
7
|
+
return useContext(PropertyPriorityContext);
|
|
8
|
+
}
|
|
9
|
+
export { PropertyPriorityProvider, usePropertyPriority };
|
|
10
|
+
|
|
11
|
+
//# sourceMappingURL=PropertyPriority.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"PropertyPriority.js","sources":["../src/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"],"names":["PropertyPriorityContext","createContext","PropertyPriorityProvider","priority","children","usePropertyPriority","useContext"],"mappings":";AAEA,MAAMA,0BAA0B,WAAHA,GAAGC,cAAc;AAOvC,MAAMC,2BAA2B,CAAC,EAAEC,QAAQ,EAAEC,QAAQ,EAAiC,GACnF,WAAP,GACI,oBAACJ,wBAAwB,QAAQ;QAAC,OAAOG;OACpCC;AAKN,SAASC;IACZ,OAAOC,WAAWN;AACtB"}
|
package/README.md
CHANGED
|
@@ -1,65 +1,11 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @webiny/react-properties
|
|
2
2
|
|
|
3
|
-
[!
|
|
4
|
-
[
|
|
5
|
-
|
|
6
|
-
[](http://makeapullrequest.com)
|
|
3
|
+
> [!NOTE]
|
|
4
|
+
> This package is part of the [Webiny](https://www.webiny.com) monorepo.
|
|
5
|
+
> It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
|
|
7
6
|
|
|
8
|
-
|
|
7
|
+
📘 **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
|
|
9
8
|
|
|
10
|
-
|
|
9
|
+
---
|
|
11
10
|
|
|
12
|
-
|
|
13
|
-
import React, { useCallback } from "react";
|
|
14
|
-
import { Properties, Property, toObject } from "@webiny/react-properties";
|
|
15
|
-
|
|
16
|
-
const View = () => {
|
|
17
|
-
const onChange = useCallback(properties => {
|
|
18
|
-
console.log(toObject(properties));
|
|
19
|
-
}, []);
|
|
20
|
-
|
|
21
|
-
return (
|
|
22
|
-
<Properties onChange={onChange}>
|
|
23
|
-
<Property name={"group"}>
|
|
24
|
-
<Property name={"name"} value={"layout"} />
|
|
25
|
-
<Property name={"label"} value={"Layout"} />
|
|
26
|
-
<Property name={"toolbar"}>
|
|
27
|
-
<Property name={"name"} value={"basic"} />
|
|
28
|
-
</Property>
|
|
29
|
-
</Property>
|
|
30
|
-
<Property name={"group"}>
|
|
31
|
-
<Property name={"name"} value={"heroes"} />
|
|
32
|
-
<Property name={"label"} value={"Heroes"} />
|
|
33
|
-
<Property name={"toolbar"}>
|
|
34
|
-
<Property name={"name"} value={"heroes"} />
|
|
35
|
-
</Property>
|
|
36
|
-
</Property>
|
|
37
|
-
</Properties>
|
|
38
|
-
);
|
|
39
|
-
};
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
Output:
|
|
43
|
-
|
|
44
|
-
```json
|
|
45
|
-
{
|
|
46
|
-
"group": [
|
|
47
|
-
{
|
|
48
|
-
"name": "layout",
|
|
49
|
-
"label": "Layout",
|
|
50
|
-
"toolbar": {
|
|
51
|
-
"name": "basic"
|
|
52
|
-
}
|
|
53
|
-
},
|
|
54
|
-
{
|
|
55
|
-
"name": "heroes",
|
|
56
|
-
"label": "Heroes",
|
|
57
|
-
"toolbar": {
|
|
58
|
-
"name": "heroes"
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
]
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
For more examples, check out the test files.
|
|
11
|
+
_This README file is automatically generated during the publish process._
|
|
@@ -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,SAASC,4BAAqCC,IAAY;IAC7D,MAAMC,qBAAqBC,g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AUqB;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,52 @@
|
|
|
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
|
+
notify(): void;
|
|
23
|
+
get allProperties(): Property[];
|
|
24
|
+
subscribe(listener: Listener): () => void;
|
|
25
|
+
/**
|
|
26
|
+
* Returns properties that are children of the given parent ID.
|
|
27
|
+
* Reads from the synchronous lookup map, so it works during render
|
|
28
|
+
* before the debounced queue has flushed.
|
|
29
|
+
*/
|
|
30
|
+
getChildrenOf(parentId: string): Property[];
|
|
31
|
+
/**
|
|
32
|
+
* Find a property by ID from the synchronous lookup map.
|
|
33
|
+
*/
|
|
34
|
+
getById(id: string): Property | undefined;
|
|
35
|
+
/**
|
|
36
|
+
* Register a property in the synchronous lookup map during render,
|
|
37
|
+
* so useAncestor can find it before the debounced queue flushes.
|
|
38
|
+
*/
|
|
39
|
+
registerLookup(property: Property): void;
|
|
40
|
+
addProperty(property: Property, options?: AddPropertyOptions): void;
|
|
41
|
+
removeProperty(id: string): void;
|
|
42
|
+
replaceProperty(oldId: string, newProperty: Property): void;
|
|
43
|
+
private processQueue;
|
|
44
|
+
private executeAdd;
|
|
45
|
+
private executeRemove;
|
|
46
|
+
private executeReplace;
|
|
47
|
+
private insertBefore;
|
|
48
|
+
private insertAfter;
|
|
49
|
+
private reposition;
|
|
50
|
+
private removeDescendants;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import debounce from "lodash/debounce.js";
|
|
2
|
+
class PropertyStore {
|
|
3
|
+
notify() {
|
|
4
|
+
this.scheduleFlush.cancel();
|
|
5
|
+
if (this.queue.length > 0) this.processQueue();
|
|
6
|
+
else {
|
|
7
|
+
const properties = this.allProperties;
|
|
8
|
+
for (const listener of this.listeners)listener(properties);
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
get allProperties() {
|
|
12
|
+
return this.order.filter((id)=>this.map.has(id)).map((id)=>this.map.get(id));
|
|
13
|
+
}
|
|
14
|
+
subscribe(listener) {
|
|
15
|
+
this.listeners.add(listener);
|
|
16
|
+
return ()=>{
|
|
17
|
+
this.listeners.delete(listener);
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
getChildrenOf(parentId) {
|
|
21
|
+
return Array.from(this.lookup.values()).filter((p)=>p.parent === parentId);
|
|
22
|
+
}
|
|
23
|
+
getById(id) {
|
|
24
|
+
return this.lookup.get(id);
|
|
25
|
+
}
|
|
26
|
+
registerLookup(property) {
|
|
27
|
+
if (this.lookup.has(property.id)) {
|
|
28
|
+
const existing = this.lookup.get(property.id);
|
|
29
|
+
this.lookup.set(property.id, {
|
|
30
|
+
...existing,
|
|
31
|
+
...property
|
|
32
|
+
});
|
|
33
|
+
} else this.lookup.set(property.id, property);
|
|
34
|
+
}
|
|
35
|
+
addProperty(property, options = {}) {
|
|
36
|
+
this.registerLookup(property);
|
|
37
|
+
this.queue.push({
|
|
38
|
+
type: "add",
|
|
39
|
+
property,
|
|
40
|
+
options
|
|
41
|
+
});
|
|
42
|
+
this.scheduleFlush();
|
|
43
|
+
}
|
|
44
|
+
removeProperty(id) {
|
|
45
|
+
this.lookup.delete(id);
|
|
46
|
+
this.queue.push({
|
|
47
|
+
type: "remove",
|
|
48
|
+
id
|
|
49
|
+
});
|
|
50
|
+
this.scheduleFlush();
|
|
51
|
+
}
|
|
52
|
+
replaceProperty(oldId, newProperty) {
|
|
53
|
+
this.lookup.delete(oldId);
|
|
54
|
+
this.lookup.set(newProperty.id, newProperty);
|
|
55
|
+
this.queue.push({
|
|
56
|
+
type: "replace",
|
|
57
|
+
oldId,
|
|
58
|
+
newProperty
|
|
59
|
+
});
|
|
60
|
+
this.scheduleFlush();
|
|
61
|
+
}
|
|
62
|
+
processQueue() {
|
|
63
|
+
if (0 === this.queue.length) return;
|
|
64
|
+
const ops = this.queue.splice(0);
|
|
65
|
+
ops.sort((a, b)=>{
|
|
66
|
+
const pa = "add" === a.type ? a.options.priority ?? 0 : 0;
|
|
67
|
+
const pb = "add" === b.type ? b.options.priority ?? 0 : 0;
|
|
68
|
+
return pa - pb;
|
|
69
|
+
});
|
|
70
|
+
for (const op of ops)switch(op.type){
|
|
71
|
+
case "add":
|
|
72
|
+
this.executeAdd(op.property, op.options);
|
|
73
|
+
break;
|
|
74
|
+
case "remove":
|
|
75
|
+
this.executeRemove(op.id);
|
|
76
|
+
break;
|
|
77
|
+
case "replace":
|
|
78
|
+
this.executeReplace(op.oldId, op.newProperty);
|
|
79
|
+
break;
|
|
80
|
+
}
|
|
81
|
+
this.order.sort((a, b)=>{
|
|
82
|
+
if (this.positioned.has(a) || this.positioned.has(b)) return 0;
|
|
83
|
+
return (this.priorities.get(a) ?? 0) - (this.priorities.get(b) ?? 0);
|
|
84
|
+
});
|
|
85
|
+
const properties = this.allProperties;
|
|
86
|
+
for (const listener of this.listeners)listener(properties);
|
|
87
|
+
}
|
|
88
|
+
executeAdd(property, options) {
|
|
89
|
+
if (options.after || options.before) this.positioned.add(property.id);
|
|
90
|
+
const exists = this.map.has(property.id);
|
|
91
|
+
if (exists) {
|
|
92
|
+
const existing = this.map.get(property.id);
|
|
93
|
+
this.map.set(property.id, {
|
|
94
|
+
...existing,
|
|
95
|
+
...property
|
|
96
|
+
});
|
|
97
|
+
if (options.after) this.reposition(property.id, options.after, "after");
|
|
98
|
+
else if (options.before) this.reposition(property.id, options.before, "before");
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
this.map.set(property.id, property);
|
|
102
|
+
this.priorities.set(property.id, options.priority ?? 0);
|
|
103
|
+
if (options.after) this.insertAfter(property.id, options.after);
|
|
104
|
+
else if (options.before) this.insertBefore(property.id, options.before);
|
|
105
|
+
else this.order.push(property.id);
|
|
106
|
+
}
|
|
107
|
+
executeRemove(id) {
|
|
108
|
+
if (!this.map.has(id)) return;
|
|
109
|
+
this.map.delete(id);
|
|
110
|
+
this.priorities.delete(id);
|
|
111
|
+
this.positioned.delete(id);
|
|
112
|
+
this.order = this.order.filter((oid)=>oid !== id);
|
|
113
|
+
}
|
|
114
|
+
executeReplace(oldId, newProperty) {
|
|
115
|
+
const idx = this.order.indexOf(oldId);
|
|
116
|
+
if (-1 === idx) return;
|
|
117
|
+
this.map.delete(oldId);
|
|
118
|
+
this.map.set(newProperty.id, newProperty);
|
|
119
|
+
this.order[idx] = newProperty.id;
|
|
120
|
+
this.removeDescendants(oldId);
|
|
121
|
+
}
|
|
122
|
+
insertBefore(id, before) {
|
|
123
|
+
if (before.endsWith("$first")) return void this.order.unshift(id);
|
|
124
|
+
const targetIdx = this.order.indexOf(before);
|
|
125
|
+
if (-1 === targetIdx) return void this.order.push(id);
|
|
126
|
+
this.order.splice(targetIdx, 0, id);
|
|
127
|
+
}
|
|
128
|
+
insertAfter(id, after) {
|
|
129
|
+
if (after.endsWith("$last")) return void this.order.push(id);
|
|
130
|
+
const targetIdx = this.order.indexOf(after);
|
|
131
|
+
if (-1 === targetIdx) return void this.order.push(id);
|
|
132
|
+
this.order.splice(targetIdx + 1, 0, id);
|
|
133
|
+
}
|
|
134
|
+
reposition(id, targetId, position) {
|
|
135
|
+
this.order = this.order.filter((oid)=>oid !== id);
|
|
136
|
+
if ("before" === position) this.insertBefore(id, targetId);
|
|
137
|
+
else this.insertAfter(id, targetId);
|
|
138
|
+
}
|
|
139
|
+
removeDescendants(parentId) {
|
|
140
|
+
const children = Array.from(this.map.values()).filter((p)=>p.parent === parentId);
|
|
141
|
+
for (const child of children){
|
|
142
|
+
this.map.delete(child.id);
|
|
143
|
+
this.order = this.order.filter((oid)=>oid !== child.id);
|
|
144
|
+
this.removeDescendants(child.id);
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
constructor(){
|
|
148
|
+
this.map = new Map();
|
|
149
|
+
this.order = [];
|
|
150
|
+
this.queue = [];
|
|
151
|
+
this.listeners = new Set();
|
|
152
|
+
this.priorities = new Map();
|
|
153
|
+
this.positioned = new Set();
|
|
154
|
+
this.lookup = new Map();
|
|
155
|
+
this.scheduleFlush = debounce(()=>{
|
|
156
|
+
this.processQueue();
|
|
157
|
+
}, 0);
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
export { PropertyStore };
|
|
161
|
+
|
|
162
|
+
//# 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 notify(): void {\n this.scheduleFlush.cancel();\n if (this.queue.length > 0) {\n this.processQueue();\n } else {\n const properties = this.allProperties;\n for (const listener of this.listeners) {\n listener(properties);\n }\n }\n }\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","properties","listener","id","parentId","Array","p","property","existing","options","oldId","newProperty","ops","a","b","pa","pb","op","exists","oid","idx","before","targetIdx","after","targetId","position","children","child","Map","Set","debounce"],"mappings":";AAgBO,MAAMA;IAmBT,SAAe;QACX,IAAI,CAAC,aAAa,CAAC,MAAM;QACzB,IAAI,IAAI,CAAC,KAAK,CAAC,MAAM,GAAG,GACpB,IAAI,CAAC,YAAY;aACd;YACH,MAAMC,aAAa,IAAI,CAAC,aAAa;YACrC,KAAK,MAAMC,YAAY,IAAI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B,EAAQ;QACjF,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAACN,CAAAA,MAAOA,QAAQhB;QAE9C,IAAIsB,AAAa,aAAbA,UACA,IAAI,CAAC,YAAY,CAACtB,IAAIqB;aAEtB,IAAI,CAAC,WAAW,CAACrB,IAAIqB;IAE7B;IAEQ,kBAAkBpB,QAAgB,EAAQ;QAC9C,MAAMsB,WAAWrB,MAAM,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,IAAI,MAAM,CAACC,CAAAA,IAAKA,EAAE,MAAM,KAAKF;QACxE,KAAK,MAAMuB,SAASD,SAAU;YAC1B,IAAI,CAAC,GAAG,CAAC,MAAM,CAACC,MAAM,EAAE;YACxB,IAAI,CAAC,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAACR,CAAAA,MAAOA,QAAQQ,MAAM,EAAE;YACtD,IAAI,CAAC,iBAAiB,CAACA,MAAM,EAAE;QACnC;IACJ;;aAlPQ,GAAG,GAAG,IAAIC;aACV,KAAK,GAAa,EAAE;aACpB,KAAK,GAAgB,EAAE;aACvB,SAAS,GAAG,IAAIC;aAChB,UAAU,GAAG,IAAID;QACwC,KACzD,UAAU,GAAG,IAAIC;QAKxB,KACO,MAAM,GAAG,IAAID;aAEb,aAAa,GAAGE,SAAS;YAC7B,IAAI,CAAC,YAAY;QACrB,GAAG;;AAmOP"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PropertyStore } from "./PropertyStore.js";
|
package/domain/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { PropertyStore } from "./PropertyStore.js";
|
package/index.d.ts
CHANGED
|
@@ -1,2 +1,9 @@
|
|
|
1
|
-
export * from "./utils";
|
|
2
|
-
export * from "./Properties";
|
|
1
|
+
export * from "./utils.js";
|
|
2
|
+
export * from "./Properties.js";
|
|
3
|
+
export * from "./AsyncProperties.js";
|
|
4
|
+
export * from "./Await.js";
|
|
5
|
+
export * from "./useDebugConfig.js";
|
|
6
|
+
export * from "./useIdGenerator.js";
|
|
7
|
+
export * from "./createConfigurableComponent.js";
|
|
8
|
+
export * from "./domain/index.js";
|
|
9
|
+
export { DevToolsSection } from "./DevToolsSection.js";
|
package/index.js
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
Object.defineProperty(exports, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
get: function get() {
|
|
13
|
-
return _utils[key];
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
});
|
|
17
|
-
var _Properties = require("./Properties");
|
|
18
|
-
Object.keys(_Properties).forEach(function (key) {
|
|
19
|
-
if (key === "default" || key === "__esModule") return;
|
|
20
|
-
if (key in exports && exports[key] === _Properties[key]) return;
|
|
21
|
-
Object.defineProperty(exports, key, {
|
|
22
|
-
enumerable: true,
|
|
23
|
-
get: function get() {
|
|
24
|
-
return _Properties[key];
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
});
|
|
1
|
+
export * from "./utils.js";
|
|
2
|
+
export * from "./Properties.js";
|
|
3
|
+
export * from "./AsyncProperties.js";
|
|
4
|
+
export * from "./Await.js";
|
|
5
|
+
export * from "./useDebugConfig.js";
|
|
6
|
+
export * from "./useIdGenerator.js";
|
|
7
|
+
export * from "./createConfigurableComponent.js";
|
|
8
|
+
export * from "./domain/index.js";
|
|
9
|
+
export { DevToolsSection } from "./DevToolsSection.js";
|
package/package.json
CHANGED
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@webiny/react-properties",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
4
|
-
"
|
|
3
|
+
"version": "0.0.0-unstable.b6d7105cee",
|
|
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,25 +14,22 @@
|
|
|
10
14
|
"author": "Webiny Ltd",
|
|
11
15
|
"license": "MIT",
|
|
12
16
|
"dependencies": {
|
|
13
|
-
"@
|
|
14
|
-
"@
|
|
15
|
-
"
|
|
16
|
-
"
|
|
17
|
+
"@types/react": "18.3.31",
|
|
18
|
+
"@webiny/react-composition": "0.0.0-unstable.b6d7105cee",
|
|
19
|
+
"lodash": "4.18.1",
|
|
20
|
+
"nanoid": "6.0.0",
|
|
21
|
+
"react": "18.3.1"
|
|
17
22
|
},
|
|
18
23
|
"devDependencies": {
|
|
19
|
-
"@testing-library/react": "
|
|
20
|
-
"@webiny/
|
|
21
|
-
"
|
|
22
|
-
"
|
|
23
|
-
"prettier": "^2.3.2"
|
|
24
|
+
"@testing-library/react": "16.3.2",
|
|
25
|
+
"@webiny/build-tools": "0.0.0-unstable.b6d7105cee",
|
|
26
|
+
"oxfmt": "0.59.0",
|
|
27
|
+
"vitest": "4.1.10"
|
|
24
28
|
},
|
|
25
29
|
"publishConfig": {
|
|
26
|
-
"access": "public"
|
|
27
|
-
"directory": "dist"
|
|
28
|
-
},
|
|
29
|
-
"scripts": {
|
|
30
|
-
"build": "yarn webiny run build",
|
|
31
|
-
"watch": "yarn webiny run watch"
|
|
30
|
+
"access": "public"
|
|
32
31
|
},
|
|
33
|
-
"
|
|
32
|
+
"webiny": {
|
|
33
|
+
"publishFrom": "dist"
|
|
34
|
+
}
|
|
34
35
|
}
|