@mapples/render 1.0.2 → 1.0.4

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.
@@ -44,6 +44,6 @@ import { RenderProps } from '../types';
44
44
  * />
45
45
  * ```
46
46
  */
47
- declare const Render: ({ root, CustomRenderComponent }: RenderProps) => import("react").JSX.Element;
47
+ declare const Render: ({ root, state, CustomRenderComponent }: RenderProps) => import("react").JSX.Element;
48
48
  export default Render;
49
49
  //# sourceMappingURL=Render.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"Render.d.ts","sourceRoot":"","sources":["../../src/components/Render.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,QAAA,MAAM,MAAM,GAAI,iCAAiC,WAAW,gCAM3D,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Render.d.ts","sourceRoot":"","sources":["../../src/components/Render.tsx"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIvC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,QAAA,MAAM,MAAM,GAAI,wCAAwC,WAAW,gCAQlE,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1,3 +1,4 @@
1
+ import { RenderStateContextProvider } from '../context/RenderStateContext';
1
2
  import RenderComponent from './RenderComponent';
2
3
  /**
3
4
  * Main render component that renders a component tree from a root component definition.
@@ -44,8 +45,10 @@ import RenderComponent from './RenderComponent';
44
45
  * />
45
46
  * ```
46
47
  */
47
- const Render = ({ root, CustomRenderComponent }) => {
48
- return CustomRenderComponent ? (<CustomRenderComponent {...root}/>) : (<RenderComponent {...root}/>);
48
+ const Render = ({ root, state, CustomRenderComponent }) => {
49
+ return CustomRenderComponent ? (<CustomRenderComponent {...root}/>) : (<RenderStateContextProvider value={state}>
50
+ <RenderComponent {...root}/>
51
+ </RenderStateContextProvider>);
49
52
  };
50
53
  export default Render;
51
54
  //# sourceMappingURL=Render.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"Render.js","sourceRoot":"","sources":["../../src/components/Render.tsx"],"names":[],"mappings":"AAEA,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,qBAAqB,EAAe,EAAE,EAAE;IAC9D,OAAO,qBAAqB,CAAC,CAAC,CAAC,CAC7B,CAAC,qBAAqB,CAAC,IAAI,IAAI,CAAC,EAAG,CACpC,CAAC,CAAC,CAAC,CACF,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,EAAG,CAC9B,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC"}
1
+ {"version":3,"file":"Render.js","sourceRoot":"","sources":["../../src/components/Render.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAG3E,OAAO,eAAe,MAAM,mBAAmB,CAAC;AAEhD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,MAAM,GAAG,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,qBAAqB,EAAe,EAAE,EAAE;IACrE,OAAO,qBAAqB,CAAC,CAAC,CAAC,CAC7B,CAAC,qBAAqB,CAAC,IAAI,IAAI,CAAC,EAAG,CACpC,CAAC,CAAC,CAAC,CACF,CAAC,0BAA0B,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CACvC;MAAA,CAAC,eAAe,CAAC,IAAI,IAAI,CAAC,EAC5B;IAAA,EAAE,0BAA0B,CAAC,CAC9B,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,MAAM,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"RenderComponent.d.ts","sourceRoot":"","sources":["../../src/components/RenderComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAQ,MAAM,OAAO,CAAC;AAMjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,QAAA,MAAM,eAAe,EAAE,EAAE,CAAC,mBAAmB,CA+B5C,CAAC;AAQF,eAAe,eAAe,CAAC"}
1
+ {"version":3,"file":"RenderComponent.d.ts","sourceRoot":"","sources":["../../src/components/RenderComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAQ,MAAM,OAAO,CAAC;AAQjC,OAAO,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAC;AAE/C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,QAAA,MAAM,eAAe,EAAE,EAAE,CAAC,mBAAmB,CAsC5C,CAAC;AAQF,eAAe,eAAe,CAAC"}
@@ -2,6 +2,8 @@ import { memo } from 'react';
2
2
  import { useDataProps } from '@mapples/state';
3
3
  import { map } from 'lodash';
4
4
  import { useRender } from '../hooks';
5
+ import useConditionalStyled from '../hooks/useConditionalStyled';
6
+ import useRefProps from '../hooks/useRefProps';
5
7
  /**
6
8
  * Default implementation of a renderable component.
7
9
  *
@@ -37,9 +39,11 @@ import { useRender } from '../hooks';
37
39
  *
38
40
  * @throws {Error} If the component type is not registered in the render context
39
41
  */
40
- const RenderComponent = ({ type, props, dataProps, children, childComponents, }) => {
42
+ const RenderComponent = ({ type, props, dataProps, children, refProps, childComponents, }) => {
41
43
  const { components } = useRender();
42
44
  const propsWithData = useDataProps(dataProps);
45
+ const resolvedRefProps = useRefProps(refProps);
46
+ const propsWithConditional = useConditionalStyled(props);
43
47
  const Component = components[type].Component;
44
48
  if (!Component) {
45
49
  return null;
@@ -48,7 +52,7 @@ const RenderComponent = ({ type, props, dataProps, children, childComponents, })
48
52
  const renderComponentProps = childComponents[child];
49
53
  return (<RenderComponentMemorized {...renderComponentProps} key={renderComponentProps.id}/>);
50
54
  };
51
- return (<Component {...props} {...propsWithData}>
55
+ return (<Component {...propsWithConditional} {...propsWithData} {...resolvedRefProps}>
52
56
  {map(children, renderChildren)}
53
57
  </Component>);
54
58
  };
@@ -1 +1 @@
1
- {"version":3,"file":"RenderComponent.js","sourceRoot":"","sources":["../../src/components/RenderComponent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAM,IAAI,EAAE,MAAM,OAAO,CAAC;AAEjC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,GAAG,EAAE,MAAM,QAAQ,CAAC;AAE7B,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAGrC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,eAAe,GAA4B,CAAC,EAChD,IAAI,EACJ,KAAK,EACL,SAAS,EACT,QAAQ,EACR,eAAe,GAChB,EAAE,EAAE;IACH,MAAM,EAAE,UAAU,EAAE,GAAG,SAAS,EAAE,CAAC;IACnC,MAAM,aAAa,GAAG,YAAY,CAAC,SAAS,CAAC,CAAC;IAE9C,MAAM,SAAS,GAAG,UAAU,CAAC,IAA+B,CAAC,CAAC,SAAS,CAAC;IAExE,IAAI,CAAC,SAAS,EAAE,CAAC;QACf,OAAO,IAAI,CAAC;IACd,CAAC;IAED,MAAM,cAAc,GAAG,CAAC,KAAa,EAAE,EAAE;QACvC,MAAM,oBAAoB,GAAG,eAAe,CAAC,KAAK,CAAC,CAAC;QACpD,OAAO,CACL,CAAC,wBAAwB,CACvB,IAAI,oBAAoB,CAAC,CACzB,GAAG,CAAC,CAAC,oBAAoB,CAAC,EAAE,CAAC,EAC7B,CACH,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CACL,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,CAAC,IA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AAO,CACL,CAAC,wBAAwB,CACvB,IAAI,oBAAoB,CAAC,CACzB,GAAG,CAAC,CAAC,oBAAoB,CAAC,EAAE,CAAC,EAC7B,CACH,CAAC;IACJ,CAAC,CAAC;IAEF,OAAO,CACL,CAAC,SAAS,CACR,IAAI,oBAAoB,CAAC,CACzB,IAAI,aAAa,CAAC,CAClB,IAAI,gBAAgB,CAAC,CAErB;MAAA,CAAC,GAAG,CAAC,QAAQ,EAAE,cAAc,CAAC,CAChC;IAAA,EAAE,SAAS,CAAC,CACb,CAAC;AACJ,CAAC,CAAC;AAEF;;;GAGG;AACH,MAAM,wBAAwB,GAAG,IAAI,CAAC,eAAe,CAAC,CAAC;AAEvD,eAAe,eAAe,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"RenderProvider.d.ts","sourceRoot":"","sources":["../../src/components/RenderProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,QAAA,MAAM,cAAc,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAS5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"RenderProvider.d.ts","sourceRoot":"","sources":["../../src/components/RenderProvider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,iBAAiB,EAAE,MAAM,OAAO,CAAC;AAG9C,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,QAAA,MAAM,cAAc,EAAE,EAAE,CAAC,iBAAiB,CAAC,iBAAiB,CAAC,CAU5D,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -25,8 +25,8 @@ import { RenderContextProvider } from '../context';
25
25
  * );
26
26
  * ```
27
27
  */
28
- const RenderProvider = ({ components, children, }) => {
29
- return (<RenderContextProvider value={{ components }}>
28
+ const RenderProvider = ({ components, children, assets, }) => {
29
+ return (<RenderContextProvider value={{ components, assets }}>
30
30
  {children}
31
31
  </RenderContextProvider>);
32
32
  };
@@ -1 +1 @@
1
- {"version":3,"file":"RenderProvider.js","sourceRoot":"","sources":["../../src/components/RenderProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,cAAc,GAA6C,CAAC,EAChE,UAAU,EACV,QAAQ,GACT,EAAE,EAAE;IACH,OAAO,CACL,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,CAAC,CAC3C;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,qBAAqB,CAAC,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"RenderProvider.js","sourceRoot":"","sources":["../../src/components/RenderProvider.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AACH,MAAM,cAAc,GAA6C,CAAC,EAChE,UAAU,EACV,QAAQ,EACR,MAAM,GACP,EAAE,EAAE;IACH,OAAO,CACL,CAAC,qBAAqB,CAAC,KAAK,CAAC,CAAC,EAAE,UAAU,EAAE,MAAM,EAAE,CAAC,CACnD;MAAA,CAAC,QAAQ,CACX;IAAA,EAAE,qBAAqB,CAAC,CACzB,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"RenderContext.d.ts","sourceRoot":"","sources":["../../src/context/RenderContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,aAAa,4CAEjB,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,6CAAyB,CAAC;AAE5D,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"RenderContext.d.ts","sourceRoot":"","sources":["../../src/context/RenderContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAE7C;;;;;;;;;;;;GAYG;AACH,QAAA,MAAM,aAAa,4CAGjB,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,qBAAqB,6CAAyB,CAAC;AAE5D,eAAe,aAAa,CAAC"}
@@ -14,6 +14,7 @@ import { createContext } from 'react';
14
14
  */
15
15
  const RenderContext = createContext({
16
16
  components: {},
17
+ assets: {},
17
18
  });
18
19
  /**
19
20
  * Provider component for the RenderContext.
@@ -1 +1 @@
1
- {"version":3,"file":"RenderContext.js","sourceRoot":"","sources":["../../src/context/RenderContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItC;;;;;;;;;;;;GAYG;AACH,MAAM,aAAa,GAAG,aAAa,CAAoB;IACrD,UAAU,EAAE,EAAE;CACf,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC,QAAQ,CAAC;AAE5D,eAAe,aAAa,CAAC"}
1
+ {"version":3,"file":"RenderContext.js","sourceRoot":"","sources":["../../src/context/RenderContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItC;;;;;;;;;;;;GAYG;AACH,MAAM,aAAa,GAAG,aAAa,CAAoB;IACrD,UAAU,EAAE,EAAE;IACd,MAAM,EAAE,EAAE;CACX,CAAC,CAAC;AAEH;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,MAAM,qBAAqB,GAAG,aAAa,CAAC,QAAQ,CAAC;AAE5D,eAAe,aAAa,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { StateCondition } from '../types';
2
+ declare const RenderStateContext: import("react").Context<Record<string, StateCondition> | undefined>;
3
+ export declare const RenderStateContextProvider: import("react").Provider<Record<string, StateCondition> | undefined>;
4
+ export default RenderStateContext;
5
+ //# sourceMappingURL=RenderStateContext.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RenderStateContext.d.ts","sourceRoot":"","sources":["../../src/context/RenderStateContext.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,cAAc,EAAE,MAAM,UAAU,CAAC;AAE1C,QAAA,MAAM,kBAAkB,qEAEZ,CAAC;AAEb,eAAO,MAAM,0BAA0B,sEAA8B,CAAC;AAEtE,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,5 @@
1
+ import { createContext } from 'react';
2
+ const RenderStateContext = createContext(undefined);
3
+ export const RenderStateContextProvider = RenderStateContext.Provider;
4
+ export default RenderStateContext;
5
+ //# sourceMappingURL=RenderStateContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RenderStateContext.js","sourceRoot":"","sources":["../../src/context/RenderStateContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAItC,MAAM,kBAAkB,GAAG,aAAa,CAEtC,SAAS,CAAC,CAAC;AAEb,MAAM,CAAC,MAAM,0BAA0B,GAAG,kBAAkB,CAAC,QAAQ,CAAC;AAEtE,eAAe,kBAAkB,CAAC"}
@@ -0,0 +1,29 @@
1
+ import { AnyObject } from '../types';
2
+ /**
3
+ * Hook that processes component props to apply conditional styling based on state conditions.
4
+ *
5
+ * This hook evaluates conditions defined in the `styled` prop and applies conditional styles
6
+ * based on the current render state. Style keys can include condition suffixes (e.g., "backgroundColor::conditionName")
7
+ * that are evaluated against the render state.
8
+ *
9
+ * @param props - Component props that may contain a `styled` object with conditional styles
10
+ * @returns Props with processed conditional styles applied
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const props = {
15
+ * styled: {
16
+ * backgroundColor: '#fff',
17
+ * 'backgroundColor::isActive': '#000',
18
+ * }
19
+ * };
20
+ *
21
+ * const processedProps = useConditionalStyled(props);
22
+ * // If isActive condition is true, backgroundColor will be '#000', otherwise '#fff'
23
+ * ```
24
+ *
25
+ * @internal
26
+ */
27
+ declare const useConditionalStyled: (props: AnyObject) => AnyObject;
28
+ export default useConditionalStyled;
29
+ //# sourceMappingURL=useConditionalStyled.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConditionalStyled.d.ts","sourceRoot":"","sources":["../../src/hooks/useConditionalStyled.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,SAAS,EAAE,MAAM,UAAU,CAAC;AAErC;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,QAAA,MAAM,oBAAoB,GAAI,OAAO,SAAS,cAoC7C,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,57 @@
1
+ import { useContext, useMemo } from 'react';
2
+ import { useDataState } from '@mapples/state';
3
+ import { keys, reduce } from 'lodash';
4
+ import RenderStateContext from '../context/RenderStateContext';
5
+ /**
6
+ * Hook that processes component props to apply conditional styling based on state conditions.
7
+ *
8
+ * This hook evaluates conditions defined in the `styled` prop and applies conditional styles
9
+ * based on the current render state. Style keys can include condition suffixes (e.g., "backgroundColor::conditionName")
10
+ * that are evaluated against the render state.
11
+ *
12
+ * @param props - Component props that may contain a `styled` object with conditional styles
13
+ * @returns Props with processed conditional styles applied
14
+ *
15
+ * @example
16
+ * ```tsx
17
+ * const props = {
18
+ * styled: {
19
+ * backgroundColor: '#fff',
20
+ * 'backgroundColor::isActive': '#000',
21
+ * }
22
+ * };
23
+ *
24
+ * const processedProps = useConditionalStyled(props);
25
+ * // If isActive condition is true, backgroundColor will be '#000', otherwise '#fff'
26
+ * ```
27
+ *
28
+ * @internal
29
+ */
30
+ const useConditionalStyled = (props) => {
31
+ const { getConditionResult } = useDataState();
32
+ const state = useContext(RenderStateContext);
33
+ const propsWithConditional = useMemo(() => {
34
+ const styled = props?.styled;
35
+ if (!styled)
36
+ return props;
37
+ const activeKeys = reduce(keys(styled), (acc, next) => {
38
+ const [styleKey, styleCondition] = next.split('::');
39
+ let conditionActive = false;
40
+ const condition = state?.[styleCondition];
41
+ if (condition) {
42
+ conditionActive = getConditionResult(condition?.condition);
43
+ }
44
+ return {
45
+ ...acc,
46
+ [styleKey]: [styled[styleKey], conditionActive && styled[next]],
47
+ };
48
+ }, {});
49
+ return {
50
+ ...props,
51
+ styled: activeKeys,
52
+ };
53
+ }, [props, state, getConditionResult]);
54
+ return propsWithConditional;
55
+ };
56
+ export default useConditionalStyled;
57
+ //# sourceMappingURL=useConditionalStyled.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useConditionalStyled.js","sourceRoot":"","sources":["../../src/hooks/useConditionalStyled.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAE5C,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,kBAAkB,MAAM,+BAA+B,CAAC;AAG/D;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,oBAAoB,GAAG,CAAC,KAAgB,EAAE,EAAE;IAChD,MAAM,EAAE,kBAAkB,EAAE,GAAG,YAAY,EAAE,CAAC;IAC9C,MAAM,KAAK,GAAG,UAAU,CAAC,kBAAkB,CAAC,CAAC;IAE7C,MAAM,oBAAoB,GAAG,OAAO,CAAC,GAAG,EAAE;QACxC,MAAM,MAAM,GAAc,KAAK,EAAE,MAAM,CAAC;QAExC,IAAI,CAAC,MAAM;YAAE,OAAO,KAAK,CAAC;QAE1B,MAAM,UAAU,GAAG,MAAM,CACvB,IAAI,CAAC,MAAM,CAAC,EACZ,CAAC,GAAG,EAAE,IAAI,EAAE,EAAE;YACZ,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;YAEpD,IAAI,eAAe,GAAG,KAAK,CAAC;YAE5B,MAAM,SAAS,GAAG,KAAK,EAAE,CAAC,cAAc,CAAC,CAAC;YAC1C,IAAI,SAAS,EAAE,CAAC;gBACd,eAAe,GAAG,kBAAkB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;YAC7D,CAAC;YAED,OAAO;gBACL,GAAG,GAAG;gBACN,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,CAAC,QAAQ,CAAC,EAAE,eAAe,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;aAChE,CAAC;QACJ,CAAC,EACD,EAAE,CACH,CAAC;QAEF,OAAO;YACL,GAAG,KAAK;YACR,MAAM,EAAE,UAAU;SACnB,CAAC;IACJ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,EAAE,kBAAkB,CAAC,CAAC,CAAC;IAEvC,OAAO,oBAAoB,CAAC;AAC9B,CAAC,CAAC;AAEF,eAAe,oBAAoB,CAAC"}
@@ -0,0 +1,28 @@
1
+ import { RefPropsMap } from '../types';
2
+ /**
3
+ * Hook that resolves ref properties by looking up assets from the render context.
4
+ *
5
+ * Ref properties are strings that reference assets in the format `ref(assetType:uuid:name)`.
6
+ * This hook resolves these references to their actual asset values from the render context.
7
+ *
8
+ * @param refProps - Optional map of ref property names to ref strings
9
+ * @returns Map of resolved asset values, with undefined values filtered out
10
+ *
11
+ * @example
12
+ * ```tsx
13
+ * const refProps = {
14
+ * image: 'ref(image:123:logo)',
15
+ * icon: 'ref(icon:456:home)',
16
+ * };
17
+ *
18
+ * const resolved = useRefProps(refProps);
19
+ * // Returns: { image: <ImageAsset>, icon: <IconAsset> }
20
+ * ```
21
+ *
22
+ * @internal
23
+ */
24
+ declare const useRefProps: (refProps?: RefPropsMap) => {
25
+ [x: string]: any;
26
+ };
27
+ export default useRefProps;
28
+ //# sourceMappingURL=useRefProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRefProps.d.ts","sourceRoot":"","sources":["../../src/hooks/useRefProps.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,UAAU,CAAC;AAIvC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,QAAA,MAAM,WAAW,GAAI,WAAW,WAAW;;CAQ1C,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -0,0 +1,34 @@
1
+ import { mapValues } from 'lodash';
2
+ import useRender from './useRender';
3
+ /**
4
+ * Hook that resolves ref properties by looking up assets from the render context.
5
+ *
6
+ * Ref properties are strings that reference assets in the format `ref(assetType:uuid:name)`.
7
+ * This hook resolves these references to their actual asset values from the render context.
8
+ *
9
+ * @param refProps - Optional map of ref property names to ref strings
10
+ * @returns Map of resolved asset values, with undefined values filtered out
11
+ *
12
+ * @example
13
+ * ```tsx
14
+ * const refProps = {
15
+ * image: 'ref(image:123:logo)',
16
+ * icon: 'ref(icon:456:home)',
17
+ * };
18
+ *
19
+ * const resolved = useRefProps(refProps);
20
+ * // Returns: { image: <ImageAsset>, icon: <IconAsset> }
21
+ * ```
22
+ *
23
+ * @internal
24
+ */
25
+ const useRefProps = (refProps) => {
26
+ const { assets } = useRender();
27
+ return mapValues(refProps, (value) => {
28
+ if (!value)
29
+ return;
30
+ return assets[value];
31
+ });
32
+ };
33
+ export default useRefProps;
34
+ //# sourceMappingURL=useRefProps.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useRefProps.js","sourceRoot":"","sources":["../../src/hooks/useRefProps.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAC;AAInC,OAAO,SAAS,MAAM,aAAa,CAAC;AAEpC;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,WAAW,GAAG,CAAC,QAAsB,EAAE,EAAE;IAC7C,MAAM,EAAE,MAAM,EAAE,GAAG,SAAS,EAAE,CAAC;IAE/B,OAAO,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;QACnC,IAAI,CAAC,KAAK;YAAE,OAAO;QAEnB,OAAO,MAAM,CAAC,KAAK,CAAC,CAAC;IACvB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
@@ -26,6 +26,11 @@ export interface ActionProps {
26
26
  * Each entry contains configuration for component interactions.
27
27
  */
28
28
  export type ActionPropsMap = Partial<Record<string, ActionProps>>;
29
+ /**
30
+ * A map of ref properties indexed by their names.
31
+ * Each entry has ref link in format ref(assetType:uuid:name)
32
+ */
33
+ export type RefPropsMap = Partial<Record<string, string>>;
29
34
  /**
30
35
  * Represents a renderable component with all its configuration and children.
31
36
  * This is the core type used throughout the render system.
@@ -51,6 +56,25 @@ export interface RenderComponentType {
51
56
  childComponents: ChildComponents;
52
57
  dataProps?: DataProps;
53
58
  actionProps?: ActionPropsMap;
59
+ refProps?: RefPropsMap;
60
+ }
61
+ /**
62
+ * Represents a state condition used for conditional styling and rendering.
63
+ *
64
+ * State conditions allow components to apply different styles or behaviors
65
+ * based on dynamic state values. The condition string follows the format
66
+ * used by the state package's condition system.
67
+ *
68
+ * @interface StateCondition
69
+ * @property {string} name - The name identifier for this condition
70
+ * @property {string} condition - The condition string (e.g., "user.age::eq::18")
71
+ * @property {string} id - Unique identifier for this condition instance
72
+ * @public
73
+ */
74
+ export interface StateCondition {
75
+ name: string;
76
+ condition: string;
77
+ id: string;
54
78
  }
55
79
  /**
56
80
  * Represents the complete render DOM structure.
@@ -59,8 +83,9 @@ export interface RenderComponentType {
59
83
  * @interface RenderDom
60
84
  * @property {RenderComponentType} root - The root component of the render tree
61
85
  */
62
- export interface RenderDom extends ChildComponents {
86
+ export interface RenderDom {
63
87
  root: RenderComponentType;
88
+ state?: Record<string, StateCondition>;
64
89
  }
65
90
  /**
66
91
  * Props for the main Render component.
@@ -69,7 +94,7 @@ export interface RenderDom extends ChildComponents {
69
94
  * @property {RenderComponentType} root - The root component to render
70
95
  * @property {FC<RenderComponentType>} [CustomRenderComponent] - Optional custom render component to override default rendering
71
96
  */
72
- export type RenderProps = Pick<RenderDom, 'root'> & {
97
+ export type RenderProps = Pick<RenderDom, 'root' | 'state'> & {
73
98
  CustomRenderComponent?: FC<RenderComponentType>;
74
99
  };
75
100
  /**
@@ -81,5 +106,6 @@ export type RenderProps = Pick<RenderDom, 'root'> & {
81
106
  */
82
107
  export interface RenderContextType {
83
108
  components: RegisteredComponents;
109
+ assets: AnyObject;
84
110
  }
85
111
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC;AAE3B,OAAO,EAAE,SAAS,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AAEjE;;;GAGG;AAEH,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;AAE5C;;;GAGG;AACH,MAAM,MAAM,eAAe,GAAG,MAAM,CAAC,MAAM,EAAE,mBAAmB,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;;GAGG;AACH,MAAM,MAAM,cAAc,GAAG,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC,CAAC;AAElE;;;;;;;;;;;;;GAaG;AACH,MAAM,WAAW,mBAAmB;IAClC,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,QAAQ,EAA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;IACX,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,SAAS,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACvC,YAAY,CAAC,EAAE,SAAS,CAAC;IACzB,QAAQ,EAAE,MAAM,EAAE,CAAC;IACnB,eAAe,EAAE,eAAe,CAAC;IACjC,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,WAAW,CAAC,EAAE,cAAc,CAAC;IAC7B,QAAQ,CAAC,EAAE,WAAW,CAAC;CACxB;AAED;;;;;;;;;;;;GAYG;AACH,MAAM,WAAW,cAAc;IAC7B,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,EAAE,EAAE,MAAM,CAAC;CACZ;AAED;;;;;;GAMG;AACH,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,mBAAmB,CAAC;IAC1B,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;CACxC;AAED;;;;;;GAMG;AACH,MAAM,MAAM,WAAW,GAAG,IAAI,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG;IAC5D,qBAAqB,CAAC,EAAE,EAAE,CAAC,mBAAmB,CAAC,CAAC;CACjD,CAAC;AAEF;;;;;;GAMG;AACH,MAAM,WAAW,iBAAiB;IAChC,UAAU,EAAE,oBAAoB,CAAC;IACjC,MAAM,EAAE,SAAS,CAAC;CACnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mapples/render",
3
- "version": "1.0.2",
3
+ "version": "1.0.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "scripts": {