@webiny/react-properties 0.0.0-unstable.99666aeb00 → 0.0.0-unstable.a9593f74dd

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/Properties.d.ts CHANGED
@@ -20,8 +20,9 @@ interface PropertiesContext {
20
20
  declare const PropertiesContext: React.Context<PropertiesContext | undefined>;
21
21
  interface PropertiesProps {
22
22
  onChange?(properties: Property[]): void;
23
+ children: React.ReactNode;
23
24
  }
24
- export declare const Properties: React.FC<PropertiesProps>;
25
+ export declare const Properties: ({ onChange, children }: PropertiesProps) => JSX.Element;
25
26
  export declare function useProperties(): PropertiesContext;
26
27
  interface PropertyProps {
27
28
  id?: string;
@@ -34,11 +35,12 @@ interface PropertyProps {
34
35
  remove?: boolean;
35
36
  parent?: string;
36
37
  root?: boolean;
38
+ children?: React.ReactNode;
37
39
  }
38
40
  export declare function useParentProperty(): Property | undefined;
39
41
  interface AncestorMatch {
40
42
  [key: string]: string | boolean | number | null | undefined;
41
43
  }
42
44
  export declare function useAncestor(params: AncestorMatch): Property | undefined;
43
- export declare const Property: React.FC<PropertyProps>;
45
+ export declare const Property: ({ id, name, value, children, after, before, replace, remove, array, root, parent }: PropertyProps) => JSX.Element | null;
44
46
  export {};
package/Properties.js CHANGED
@@ -200,7 +200,7 @@ var Property = function Property(_ref2) {
200
200
  var addProperty = properties.addProperty,
201
201
  removeProperty = properties.removeProperty,
202
202
  replaceProperty = properties.replaceProperty;
203
- var parentId = parent ? parent : root ? "" : (parentProperty === null || parentProperty === void 0 ? void 0 : parentProperty.id) || "";
203
+ var parentId = parent ? parent : root ? "" : parentProperty?.id || "";
204
204
  var property = {
205
205
  id: uniqueId,
206
206
  name: name,
@@ -232,4 +232,6 @@ var Property = function Property(_ref2) {
232
232
  }
233
233
  return null;
234
234
  };
235
- exports.Property = Property;
235
+ exports.Property = Property;
236
+
237
+ //# sourceMappingURL=Properties.js.map
package/Properties.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["removeByParent","id","properties","filter","prop","parent","reduce","acc","item","putPropertyBefore","property","before","existingIndex","findIndex","existingProperty","newProperties","p","targetIndex","slice","putPropertyAfter","after","splice","removedProperty","mergeProperty","index","PropertiesContext","createContext","undefined","Properties","onChange","children","useState","setProperties","useEffect","context","useMemo","getObject","toObject","addProperty","options","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\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 = 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 = 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 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 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\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,SAASO,iBAAiB,CAACP,UAAsB,EAAEQ,QAAkB,EAAEC,MAAc,EAAE;EACnF,IAAMC,aAAa,GAAGV,UAAU,CAACW,SAAS,CAAC,UAAAT,IAAI;IAAA,OAAIA,IAAI,CAACH,EAAE,KAAKS,QAAQ,CAACT,EAAE;EAAA,EAAC;EAC3E,IAAIW,aAAa,GAAG,CAAC,CAAC,EAAE;IACpB,IAAME,gBAAgB,GAAGZ,UAAU,CAACU,aAAa,CAAC;IAClD,IAAMG,aAAa,GAAGb,UAAU,CAACC,MAAM,CAAC,UAAAa,CAAC;MAAA,OAAIA,CAAC,CAACf,EAAE,KAAKS,QAAQ,CAACT,EAAE;IAAA,EAAC;IAClE,IAAMgB,YAAW,GAAGF,aAAa,CAACF,SAAS,CAAC,UAAAT,IAAI;MAAA,OAAIA,IAAI,CAACH,EAAE,KAAKU,MAAM;IAAA,EAAC;IACvE,kDACOI,aAAa,CAACG,KAAK,CAAC,CAAC,EAAED,YAAW,CAAC,IACtCH,gBAAgB,oCACbC,aAAa,CAACG,KAAK,CAACD,YAAW,CAAC;EAE3C;EAE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oC,WAAW;IAAEE,cAAc,GAAsBtC,UAAU,CAA9CsC,cAAc;IAAEC,eAAe,GAAKvC,UAAU,CAA9BuC,eAAe;EACpD,IAAM0B,QAAQ,GAAG9D,MAAM,GAAGA,MAAM,GAAG0D,IAAI,GAAG,EAAE,GAAG,CAAAG,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAEjE,EAAE,KAAI,EAAE;EACvE,IAAMS,QAAQ,GAAG;IAAET,EAAE,EAAE+D,QAAQ;IAAEZ,IAAI,EAAJA,IAAI;IAAEC,KAAK,EAALA,KAAK;IAAEhD,MAAM,EAAE8D,QAAQ;IAAEL,KAAK,EAALA;EAAM,CAAC;EAEvE,IAAA7B,gBAAS,EAAC,YAAM;IACZ,IAAI4B,MAAM,EAAE;MACRrB,cAAc,CAACwB,QAAQ,CAAC;MACxB;IACJ;IAEA,IAAIJ,OAAO,EAAE;MACTnB,eAAe,CAACmB,OAAO,EAAElD,QAAQ,CAAC;MAClC;IACJ;IAEA4B,WAAW,CAAC5B,QAAQ,EAAE;MAAEU,KAAK,EAALA,KAAK;MAAET,MAAM,EAANA;IAAO,CAAC,CAAC;IAExC,OAAO,YAAM;MACT6B,cAAc,CAACwB,QAAQ,CAAC;IAC5B,CAAC;EACL,CAAC,EAAE,EAAE,CAAC;EAEN,IAAIlC,QAAQ,EAAE;IACV,oBAAO,6BAAC,eAAe,CAAC,QAAQ;MAAC,KAAK,EAAEpB;IAAS,GAAEoB,QAAQ,CAA4B;EAC3F;EAEA,OAAO,IAAI;AACf,CAAC;AAAC"}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_utils","removeByParent","id","properties","filter","prop","parent","reduce","acc","item","putPropertyBefore","property","before","existingIndex","findIndex","existingProperty","newProperties","p","targetIndex","concat","_toConsumableArray2","default","slice","putPropertyAfter","after","_properties$splice","splice","_properties$splice2","_slicedToArray2","removedProperty","mergeProperty","index","_objectSpread2","PropertiesContext","createContext","undefined","Properties","_ref","onChange","children","_useState","useState","_useState2","setProperties","useEffect","context","useMemo","getObject","toObject","addProperty","options","arguments","length","removeProperty","replaceProperty","toReplace","createElement","Provider","value","exports","useProperties","useContext","Error","PropertyContext","useParentProperty","useAncestor","params","_useProperties","matchOrGetAncestor","matchedProps","name","Object","keys","newParent","find","Property","_ref2","_ref2$after","_ref2$before","_ref2$replace","replace","_ref2$remove","remove","_ref2$array","array","_ref2$root","root","_ref2$parent","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\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 = 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 = 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 onChange?(properties: Property[]): void;\n children: React.ReactNode;\n}\n\nexport const Properties = ({ onChange, children }: PropertiesProps) => {\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 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\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 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}</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
+
82
+ //# sourceMappingURL=createConfigurableComponent.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["createHOC","newChildren","BaseComponent","ConfigHOC","children","createConfigurableComponent","name","ConfigApply","makeComposable","Config","defaultContext","properties","ViewContext","React","createContext","WithConfig","onProperties","useState","setProperties","context","useEffect","stateUpdater","useConfig","useContext","useMemo","toObject"],"sources":["createConfigurableComponent.tsx"],"sourcesContent":["import React, { useContext, useEffect, useMemo, useState } from \"react\";\nimport { Compose, HigherOrderComponent, makeComposable } from \"@webiny/react-composition\";\nimport { Property, Properties, toObject } from \"~/index\";\n\nconst createHOC =\n (newChildren: React.ReactNode): HigherOrderComponent =>\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\nexport function createConfigurableComponent<TConfig>(name: string) {\n /**\n * This component is used when we want to mount all composed configs.\n */\n const ConfigApply = makeComposable(`${name}ConfigApply`, ({ children }) => {\n return <>{children}</>;\n });\n\n /**\n * This component is used to configure the component (it can be mounted many times).\n */\n const Config = ({ children }: { children: React.ReactNode }) => {\n return <Compose component={ConfigApply} 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 const WithConfig = ({ onProperties, children }: WithConfigProps) => {\n const [properties, setProperties] = useState<Property[]>([]);\n const context = { properties };\n\n useEffect(() => {\n if (typeof onProperties === \"function\") {\n onProperties(properties);\n }\n }, [properties]);\n\n const stateUpdater = (properties: Property[]) => {\n setProperties(properties);\n };\n\n return (\n <ViewContext.Provider value={context}>\n <Properties onChange={stateUpdater}>\n <ConfigApply />\n {children}\n </Properties>\n </ViewContext.Provider>\n );\n };\n\n function useConfig<TExtra extends object>(): TConfig & TExtra {\n const { properties } = useContext(ViewContext);\n return useMemo(() => toObject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C;MAC5B;IACJ,CAAC,EAAE,CAACA,UAAU,CAAC,CAAC;IAEhB,IAAMU,YAAY,GAAG,SAAfA,YAAY,CAAIV,UAAsB,EAAK;MAC7CO,aAAa,CAACP,UAAU,CAAC;IAC7B,CAAC;IAED,oBACI,6BAAC,WAAW,CAAC,QAAQ;MAAC,KAAK,EAAEQ;IAAQ,gBACjC,6BAAC,iBAAU;MAAC,QAAQ,EAAEE;IAAa,gBAC/B,6BAAC,WAAW,OAAG,EACdjB,QAAQ,CACA,CACM;EAE/B,CAAC;EAED,SAASkB,SAAS,GAA4C;IAC1D,kBAAuB,IAAAC,iBAAU,EAACX,WAAW,CAAC;MAAtCD,UAAU,eAAVA,UAAU;IAClB,OAAO,IAAAa,cAAO,EAAC;MAAA,OAAM,IAAAC,eAAQ,EAAmBd,UAAU,CAAC;IAAA,GAAE,CAACA,UAAU,CAAC,CAAC;EAC9E;EAEA,OAAO;IACHI,UAAU,EAAVA,UAAU;IACVN,MAAM,EAANA,MAAM;IACNa,SAAS,EAATA;EACJ,CAAC;AACL"}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_reactComposition","_index","createHOC","newChildren","BaseComponent","ConfigHOC","_ref","children","default","createElement","createConfigurableComponent","name","ConfigApply","makeComposable","concat","_ref2","Fragment","Config","_ref3","Compose","component","with","defaultContext","properties","ViewContext","React","createContext","WithConfig","_ref4","onProperties","_useState","useState","_useState2","_slicedToArray2","setProperties","context","useEffect","stateUpdater","Provider","value","Properties","onChange","useConfig","_useContext","useContext","useMemo","toObject"],"sources":["createConfigurableComponent.tsx"],"sourcesContent":["import React, { useContext, useEffect, useMemo, useState } from \"react\";\nimport { Compose, HigherOrderComponent, makeComposable } from \"@webiny/react-composition\";\nimport { Property, Properties, toObject } from \"~/index\";\n\nconst createHOC =\n (newChildren: React.ReactNode): HigherOrderComponent =>\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\nexport function createConfigurableComponent<TConfig>(name: string) {\n /**\n * This component is used when we want to mount all composed configs.\n */\n const ConfigApply = makeComposable(`${name}ConfigApply`, ({ children }) => {\n return <>{children}</>;\n });\n\n /**\n * This component is used to configure the component (it can be mounted many times).\n */\n const Config = ({ children }: { children: React.ReactNode }) => {\n return <Compose component={ConfigApply} 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 const WithConfig = ({ onProperties, children }: WithConfigProps) => {\n const [properties, setProperties] = useState<Property[]>([]);\n const context = { properties };\n\n useEffect(() => {\n if (typeof onProperties === \"function\") {\n onProperties(properties);\n }\n }, [properties]);\n\n const stateUpdater = (properties: Property[]) => {\n setProperties(properties);\n };\n\n return (\n <ViewContext.Provider value={context}>\n <Properties onChange={stateUpdater}>\n <ConfigApply />\n {children}\n </Properties>\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,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,iBAAA,GAAAD,OAAA;AACA,IAAAE,MAAA,GAAAF,OAAA;AAEA,IAAMG,SAAS,GACX,SADEA,SAASA,CACVC,WAA4B;EAAA,OAC7B,UAAAC,aAAa,EAAI;IACb,OAAO,SAASC,SAASA,CAAAC,IAAA,EAAe;MAAA,IAAZC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;MAChC,oBACIV,MAAA,CAAAW,OAAA,CAAAC,aAAA,CAACL,aAAa,QACTD,WAAW,EACXI,QACU,CAAC;IAExB,CAAC;EACL,CAAC;AAAA;AAOE,SAASG,2BAA2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,EAAE,CAACA,UAAU,CAAC,CAAC;IAEhB,IAAMc,YAAY,GAAG,SAAfA,YAAYA,CAAId,UAAsB,EAAK;MAC7CW,aAAa,CAACX,UAAU,CAAC;IAC7B,CAAC;IAED,oBACI1B,MAAA,CAAAW,OAAA,CAAAC,aAAA,CAACe,WAAW,CAACc,QAAQ;MAACC,KAAK,EAAEJ;IAAQ,gBACjCtC,MAAA,CAAAW,OAAA,CAAAC,aAAA,CAACR,MAAA,CAAAuC,UAAU;MAACC,QAAQ,EAAEJ;IAAa,gBAC/BxC,MAAA,CAAAW,OAAA,CAAAC,aAAA,CAACG,WAAW,MAAE,CAAC,EACdL,QACO,CACM,CAAC;EAE/B,CAAC;EAED,SAASmC,SAASA,CAAA,EAA4C;IAC1D,IAAAC,WAAA,GAAuB,IAAAC,iBAAU,EAACpB,WAAW,CAAC;MAAtCD,UAAU,GAAAoB,WAAA,CAAVpB,UAAU;IAClB,OAAO,IAAAsB,cAAO,EAAC;MAAA,OAAM,IAAAC,eAAQ,EAAmBvB,UAAU,CAAC;IAAA,GAAE,CAACA,UAAU,CAAC,CAAC;EAC9E;EAEA,OAAO;IACHI,UAAU,EAAVA,UAAU;IACVV,MAAM,EAANA,MAAM;IACNyB,SAAS,EAATA;EACJ,CAAC;AACL"}
package/index.js CHANGED
@@ -46,4 +46,6 @@ Object.keys(_createConfigurableComponent).forEach(function (key) {
46
46
  return _createConfigurableComponent[key];
47
47
  }
48
48
  });
49
- });
49
+ });
50
+
51
+ //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["index.ts"],"sourcesContent":["export * from \"./utils\";\nexport * from \"./Properties\";\nexport * from \"./useIdGenerator\";\nexport * from \"./createConfigurableComponent\";\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;AACA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":["_utils","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_Properties","_useIdGenerator","_createConfigurableComponent"],"sources":["index.ts"],"sourcesContent":["export * from \"./utils\";\nexport * from \"./Properties\";\nexport * from \"./useIdGenerator\";\nexport * from \"./createConfigurableComponent\";\n"],"mappings":";;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,MAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,MAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,MAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,WAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,WAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,WAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,WAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAAM,eAAA,GAAAV,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAQ,eAAA,EAAAP,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAM,eAAA,CAAAN,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAE,eAAA,CAAAN,GAAA;IAAA;EAAA;AAAA;AACA,IAAAO,4BAAA,GAAAX,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAS,4BAAA,EAAAR,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,4BAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAG,4BAAA,CAAAP,GAAA;IAAA;EAAA;AAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/react-properties",
3
- "version": "0.0.0-unstable.99666aeb00",
3
+ "version": "0.0.0-unstable.a9593f74dd",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -10,17 +10,17 @@
10
10
  "author": "Webiny Ltd",
11
11
  "license": "MIT",
12
12
  "dependencies": {
13
- "@babel/runtime": "7.20.13",
13
+ "@babel/runtime": "7.22.6",
14
14
  "@types/react": "17.0.39",
15
+ "@webiny/react-composition": "0.0.0-unstable.a9593f74dd",
15
16
  "nanoid": "3.3.4",
16
17
  "react": "17.0.2"
17
18
  },
18
19
  "devDependencies": {
19
20
  "@testing-library/react": "12.1.5",
20
- "@webiny/cli": "0.0.0-unstable.99666aeb00",
21
- "@webiny/project-utils": "0.0.0-unstable.99666aeb00",
22
- "@webiny/react-composition": "0.0.0-unstable.99666aeb00",
23
- "prettier": "2.8.3"
21
+ "@webiny/cli": "0.0.0-unstable.a9593f74dd",
22
+ "@webiny/project-utils": "0.0.0-unstable.a9593f74dd",
23
+ "prettier": "2.8.8"
24
24
  },
25
25
  "publishConfig": {
26
26
  "access": "public",
@@ -30,5 +30,5 @@
30
30
  "build": "yarn webiny run build",
31
31
  "watch": "yarn webiny run watch"
32
32
  },
33
- "gitHead": "99666aeb00056c56292eeb5dbb6aba7fda2439e2"
33
+ "gitHead": "a9593f74ddf9ce93263eadb0ddc0807ed343f5ee"
34
34
  }
package/useIdGenerator.js CHANGED
@@ -12,6 +12,8 @@ function useIdGenerator(name) {
12
12
  for (var _len = arguments.length, parts = new Array(_len), _key = 0; _key < _len; _key++) {
13
13
  parts[_key] = arguments[_key];
14
14
  }
15
- return [parentProperty === null || parentProperty === void 0 ? void 0 : parentProperty.id, name].concat(parts).filter(Boolean).join(":");
15
+ return [parentProperty?.id, name].concat(parts).filter(Boolean).join(":");
16
16
  }, [name, parentProperty]);
17
- }
17
+ }
18
+
19
+ //# sourceMappingURL=useIdGenerator.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useIdGenerator","name","parentProperty","useParentProperty","useCallback","parts","id","filter","Boolean","join"],"sources":["useIdGenerator.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useParentProperty } from \"~/Properties\";\n\nexport function useIdGenerator(name: string) {\n const parentProperty = useParentProperty();\n\n return useCallback(\n (...parts: string[]) => {\n return [parentProperty?.id, name, ...parts].filter(Boolean).join(\":\");\n },\n [name, parentProperty]\n );\n}\n"],"mappings":";;;;;;AAAA;AACA;AAEO,SAASA,cAAc,CAACC,IAAY,EAAE;EACzC,IAAMC,cAAc,GAAG,IAAAC,6BAAiB,GAAE;EAE1C,OAAO,IAAAC,kBAAW,EACd,YAAwB;IAAA,kCAApBC,KAAK;MAALA,KAAK;IAAA;IACL,OAAO,CAACH,cAAc,aAAdA,cAAc,uBAAdA,cAAc,CAAEI,EAAE,EAAEL,IAAI,SAAKI,KAAK,EAAEE,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EACzE,CAAC,EACD,CAACR,IAAI,EAAEC,cAAc,CAAC,CACzB;AACL"}
1
+ {"version":3,"names":["_react","require","_Properties","useIdGenerator","name","parentProperty","useParentProperty","useCallback","_len","arguments","length","parts","Array","_key","id","concat","filter","Boolean","join"],"sources":["useIdGenerator.ts"],"sourcesContent":["import { useCallback } from \"react\";\nimport { useParentProperty } from \"~/Properties\";\n\nexport function useIdGenerator(name: string) {\n const parentProperty = useParentProperty();\n\n return useCallback(\n (...parts: string[]) => {\n return [parentProperty?.id, name, ...parts].filter(Boolean).join(\":\");\n },\n [name, parentProperty]\n );\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAD,OAAA;AAEO,SAASE,cAAcA,CAACC,IAAY,EAAE;EACzC,IAAMC,cAAc,GAAG,IAAAC,6BAAiB,EAAC,CAAC;EAE1C,OAAO,IAAAC,kBAAW,EACd,YAAwB;IAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAApBC,KAAK,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;MAALF,KAAK,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;IAAA;IACL,OAAO,CAACR,cAAc,EAAES,EAAE,EAAEV,IAAI,EAAAW,MAAA,CAAKJ,KAAK,EAAEK,MAAM,CAACC,OAAO,CAAC,CAACC,IAAI,CAAC,GAAG,CAAC;EACzE,CAAC,EACD,CAACd,IAAI,EAAEC,cAAc,CACzB,CAAC;AACL"}
package/utils.js CHANGED
@@ -41,4 +41,6 @@ function toObject(properties) {
41
41
  function getUniqueId() {
42
42
  var length = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 12;
43
43
  return nanoid(length);
44
- }
44
+ }
45
+
46
+ //# sourceMappingURL=utils.js.map
package/utils.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["nanoid","customAlphabet","buildRoots","roots","properties","obj","reduce","acc","item","isArray","array","filter","r","name","length","forEach","root","Array","value","undefined","nextRoots","p","parent","id","toObject","prop","getUniqueId"],"sources":["utils.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\nconst nanoid = customAlphabet(\"1234567890abcdef\");\nimport { Property } from \"./Properties\";\n\nfunction buildRoots(roots: Property[], properties: Property[]) {\n const obj: Record<string, unknown> = roots.reduce((acc, item) => {\n const isArray = item.array === true || roots.filter(r => r.name === item.name).length > 1;\n return { ...acc, [item.name]: isArray ? [] : {} };\n }, {});\n\n roots.forEach(root => {\n const isArray = root.array === true || Array.isArray(obj[root.name]);\n if (root.value !== undefined) {\n obj[root.name] = isArray ? [...(obj[root.name] as Array<any>), root.value] : root.value;\n return;\n }\n\n const nextRoots = properties.filter(p => p.parent === root.id);\n const value = buildRoots(nextRoots, properties);\n obj[root.name] = isArray ? [...(obj[root.name] as Property[]), value] : value;\n });\n\n return obj;\n}\n\nexport function toObject<T = unknown>(properties: Property[]): T {\n const roots = properties.filter(prop => prop.parent === \"\");\n return buildRoots(roots, properties) as T;\n}\n\nexport function getUniqueId(length = 12) {\n return nanoid(length);\n}\n"],"mappings":";;;;;;;;;;;AAAA;AACA,IAAMA,MAAM,GAAG,IAAAC,sBAAc,EAAC,kBAAkB,CAAC;AAGjD,SAASC,UAAU,CAACC,KAAiB,EAAEC,UAAsB,EAAE;EAC3D,IAAMC,GAA4B,GAAGF,KAAK,CAACG,MAAM,CAAC,UAACC,GAAG,EAAEC,IAAI,EAAK;IAC7D,IAAMC,OAAO,GAAGD,IAAI,CAACE,KAAK,KAAK,IAAI,IAAIP,KAAK,CAACQ,MAAM,CAAC,UAAAC,CAAC;MAAA,OAAIA,CAAC,CAACC,IAAI,KAAKL,IAAI,CAACK,IAAI;IAAA,EAAC,CAACC,MAAM,GAAG,CAAC;IACzF,mEAAYP,GAAG,yCAAGC,IAAI,CAACK,IAAI,EAAGJ,OAAO,GAAG,EAAE,GAAG,CAAC,CAAC;EACnD,CAAC,EAAE,CAAC,CAAC,CAAC;EAENN,KAAK,CAACY,OAAO,CAAC,UAAAC,IAAI,EAAI;IAClB,IAAMP,OAAO,GAAGO,IAAI,CAACN,KAAK,KAAK,IAAI,IAAIO,KAAK,CAACR,OAAO,CAACJ,GAAG,CAACW,IAAI,CAACH,IAAI,CAAC,CAAC;IACpE,IAAIG,IAAI,CAACE,KAAK,KAAKC,SAAS,EAAE;MAC1Bd,GAAG,CAACW,IAAI,CAACH,IAAI,CAAC,GAAGJ,OAAO,8CAAQJ,GAAG,CAACW,IAAI,CAACH,IAAI,CAAC,IAAiBG,IAAI,CAACE,KAAK,KAAIF,IAAI,CAACE,KAAK;MACvF;IACJ;IAEA,IAAME,SAAS,GAAGhB,UAAU,CAACO,MAAM,CAAC,UAAAU,CAAC;MAAA,OAAIA,CAAC,CAACC,MAAM,KAAKN,IAAI,CAACO,EAAE;IAAA,EAAC;IAC9D,IAAML,KAAK,GAAGhB,UAAU,CAACkB,SAAS,EAAEhB,UAAU,CAAC;IAC/CC,GAAG,CAACW,IAAI,CAACH,IAAI,CAAC,GAAGJ,OAAO,8CAAQJ,GAAG,CAACW,IAAI,CAACH,IAAI,CAAC,IAAiBK,KAAK,KAAIA,KAAK;EACjF,CAAC,CAAC;EAEF,OAAOb,GAAG;AACd;AAEO,SAASmB,QAAQ,CAAcpB,UAAsB,EAAK;EAC7D,IAAMD,KAAK,GAAGC,UAAU,CAACO,MAAM,CAAC,UAAAc,IAAI;IAAA,OAAIA,IAAI,CAACH,MAAM,KAAK,EAAE;EAAA,EAAC;EAC3D,OAAOpB,UAAU,CAACC,KAAK,EAAEC,UAAU,CAAC;AACxC;AAEO,SAASsB,WAAW,GAAc;EAAA,IAAbZ,MAAM,uEAAG,EAAE;EACnC,OAAOd,MAAM,CAACc,MAAM,CAAC;AACzB"}
1
+ {"version":3,"names":["_nanoid","require","nanoid","customAlphabet","buildRoots","roots","properties","obj","reduce","acc","item","isArray","array","filter","r","name","length","_objectSpread3","default","_defineProperty2","forEach","root","Array","value","undefined","concat","_toConsumableArray2","nextRoots","p","parent","id","toObject","prop","getUniqueId","arguments"],"sources":["utils.ts"],"sourcesContent":["import { customAlphabet } from \"nanoid\";\nconst nanoid = customAlphabet(\"1234567890abcdef\");\nimport { Property } from \"./Properties\";\n\nfunction buildRoots(roots: Property[], properties: Property[]) {\n const obj: Record<string, unknown> = roots.reduce((acc, item) => {\n const isArray = item.array === true || roots.filter(r => r.name === item.name).length > 1;\n return { ...acc, [item.name]: isArray ? [] : {} };\n }, {});\n\n roots.forEach(root => {\n const isArray = root.array === true || Array.isArray(obj[root.name]);\n if (root.value !== undefined) {\n obj[root.name] = isArray ? [...(obj[root.name] as Array<any>), root.value] : root.value;\n return;\n }\n\n const nextRoots = properties.filter(p => p.parent === root.id);\n const value = buildRoots(nextRoots, properties);\n obj[root.name] = isArray ? [...(obj[root.name] as Property[]), value] : value;\n });\n\n return obj;\n}\n\nexport function toObject<T = unknown>(properties: Property[]): T {\n const roots = properties.filter(prop => prop.parent === \"\");\n return buildRoots(roots, properties) as T;\n}\n\nexport function getUniqueId(length = 12) {\n return nanoid(length);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,OAAA,GAAAC,OAAA;AACA,IAAMC,MAAM,GAAG,IAAAC,sBAAc,EAAC,kBAAkB,CAAC;AAGjD,SAASC,UAAUA,CAACC,KAAiB,EAAEC,UAAsB,EAAE;EAC3D,IAAMC,GAA4B,GAAGF,KAAK,CAACG,MAAM,CAAC,UAACC,GAAG,EAAEC,IAAI,EAAK;IAC7D,IAAMC,OAAO,GAAGD,IAAI,CAACE,KAAK,KAAK,IAAI,IAAIP,KAAK,CAACQ,MAAM,CAAC,UAAAC,CAAC;MAAA,OAAIA,CAAC,CAACC,IAAI,KAAKL,IAAI,CAACK,IAAI;IAAA,EAAC,CAACC,MAAM,GAAG,CAAC;IACzF,WAAAC,cAAA,CAAAC,OAAA,MAAAD,cAAA,CAAAC,OAAA,MAAYT,GAAG,WAAAU,gBAAA,CAAAD,OAAA,MAAGR,IA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