@contember/react-binding 1.3.0-alpha.24 → 1.3.0-alpha.26

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/development/helperComponents/DimensionRenderer.cjs +29 -0
  2. package/dist/development/helperComponents/DimensionRenderer.cjs.map +1 -0
  3. package/dist/development/helperComponents/DimensionRenderer.js +29 -0
  4. package/dist/development/helperComponents/DimensionRenderer.js.map +1 -0
  5. package/dist/development/helperComponents/If.cjs +22 -19
  6. package/dist/development/helperComponents/If.cjs.map +1 -1
  7. package/dist/development/helperComponents/If.js +22 -19
  8. package/dist/development/helperComponents/If.js.map +1 -1
  9. package/dist/development/helperComponents/Variable.cjs +18 -0
  10. package/dist/development/helperComponents/Variable.cjs.map +1 -0
  11. package/dist/development/helperComponents/Variable.js +18 -0
  12. package/dist/development/helperComponents/Variable.js.map +1 -0
  13. package/dist/development/index.cjs +4 -0
  14. package/dist/development/index.cjs.map +1 -1
  15. package/dist/development/index.js +4 -0
  16. package/dist/development/index.js.map +1 -1
  17. package/dist/production/helperComponents/DimensionRenderer.cjs +18 -0
  18. package/dist/production/helperComponents/DimensionRenderer.cjs.map +1 -0
  19. package/dist/production/helperComponents/DimensionRenderer.js +18 -0
  20. package/dist/production/helperComponents/DimensionRenderer.js.map +1 -0
  21. package/dist/production/helperComponents/If.cjs +9 -6
  22. package/dist/production/helperComponents/If.cjs.map +1 -1
  23. package/dist/production/helperComponents/If.js +9 -6
  24. package/dist/production/helperComponents/If.js.map +1 -1
  25. package/dist/production/helperComponents/Variable.cjs +14 -0
  26. package/dist/production/helperComponents/Variable.cjs.map +1 -0
  27. package/dist/production/helperComponents/Variable.js +14 -0
  28. package/dist/production/helperComponents/Variable.js.map +1 -0
  29. package/dist/production/index.cjs +4 -0
  30. package/dist/production/index.cjs.map +1 -1
  31. package/dist/production/index.js +4 -0
  32. package/dist/production/index.js.map +1 -1
  33. package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts +1 -1
  34. package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts.map +1 -1
  35. package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts +2 -2
  36. package/dist/types/accessorPropagation/useGetEntityListSubTree.d.ts.map +1 -1
  37. package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts +2 -2
  38. package/dist/types/accessorPropagation/useGetEntitySubTree.d.ts.map +1 -1
  39. package/dist/types/coreComponents/DataBindingProvider.d.ts.map +1 -1
  40. package/dist/types/coreComponents/EntityList.d.ts.map +1 -1
  41. package/dist/types/coreComponents/EntityListSubTree.d.ts.map +1 -1
  42. package/dist/types/coreComponents/EntitySubTree.d.ts.map +1 -1
  43. package/dist/types/coreComponents/Field.d.ts.map +1 -1
  44. package/dist/types/coreComponents/HasMany.d.ts.map +1 -1
  45. package/dist/types/coreComponents/HasOne.d.ts.map +1 -1
  46. package/dist/types/entityEvents/useDerivedField.d.ts.map +1 -1
  47. package/dist/types/helperComponents/DimensionRenderer.d.ts +9 -0
  48. package/dist/types/helperComponents/DimensionRenderer.d.ts.map +1 -0
  49. package/dist/types/helperComponents/If.d.ts +4 -0
  50. package/dist/types/helperComponents/If.d.ts.map +1 -1
  51. package/dist/types/helperComponents/LabelMiddleware.d.ts.map +1 -1
  52. package/dist/types/helperComponents/SugaredField.d.ts.map +1 -1
  53. package/dist/types/helperComponents/Variable.d.ts +8 -0
  54. package/dist/types/helperComponents/Variable.d.ts.map +1 -0
  55. package/dist/types/helperComponents/index.d.ts +2 -0
  56. package/dist/types/helperComponents/index.d.ts.map +1 -1
  57. package/dist/types/tsconfig.tsbuildinfo +1 -1
  58. package/package.json +11 -11
  59. package/src/helperComponents/DimensionRenderer.tsx +25 -0
  60. package/src/helperComponents/If.tsx +15 -10
  61. package/src/helperComponents/Variable.tsx +18 -0
  62. package/src/helperComponents/index.ts +2 -0
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxDevRuntime = require("react/jsx-dev-runtime");
4
+ const EnvironmentContext = require("../accessorPropagation/EnvironmentContext.cjs");
5
+ const Component = require("../coreComponents/Component.cjs");
6
+ const DimensionRenderer = Component.Component(({ dimension, as, children }, env) => {
7
+ const dimensions = env.getDimensionOrElse(dimension, []);
8
+ return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: dimensions.map((value) => /* @__PURE__ */ jsxDevRuntime.jsxDEV(
9
+ EnvironmentContext.EnvironmentMiddleware,
10
+ {
11
+ create: (it) => it.withVariables({ [as]: value }),
12
+ children
13
+ },
14
+ value,
15
+ false,
16
+ {
17
+ fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/DimensionRenderer.tsx",
18
+ lineNumber: 17,
19
+ columnNumber: 4
20
+ },
21
+ void 0
22
+ )) }, void 0, false, {
23
+ fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/DimensionRenderer.tsx",
24
+ lineNumber: 15,
25
+ columnNumber: 9
26
+ }, void 0);
27
+ });
28
+ exports.DimensionRenderer = DimensionRenderer;
29
+ //# sourceMappingURL=DimensionRenderer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DimensionRenderer.cjs","sources":["../../../src/helperComponents/DimensionRenderer.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ReactNode } from 'react'\nimport { EnvironmentMiddleware } from '../accessorPropagation'\nimport { Component } from '../coreComponents'\n\nexport type DimensionRendererProps = {\n\tdimension: string\n\tas: string\n\tchildren: ReactNode\n}\n\nexport const DimensionRenderer = Component<DimensionRendererProps>(({ dimension, as, children }, env) => {\n\tconst dimensions = env.getDimensionOrElse(dimension, [])\n\n\treturn <>\n\t\t{dimensions.map(value => (\n\t\t\t<EnvironmentMiddleware\n\t\t\t\tcreate={it => it.withVariables({ [as]: value })}\n\t\t\t\tkey={value}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</EnvironmentMiddleware>\n\t\t))}\n\t</>\n})\n"],"names":["Component","jsxDEV","Fragment","EnvironmentMiddleware","this"],"mappings":";;;;;AAWa,MAAA,oBAAoBA,oBAAkC,CAAC,EAAE,WAAW,IAAI,YAAY,QAAQ;AACxG,QAAM,aAAa,IAAI,mBAAmB,WAAW,CAAE,CAAA;AAEhD,SAAAC,8BAAAA,OAAAC,cAAAA,UAAA,EACL,UAAW,WAAA,IAAI,CACf,UAAAD,8BAAA;AAAA,IAACE,mBAAA;AAAA,IAAA;AAAA,MACA,QAAQ,QAAM,GAAG,cAAc,EAAE,CAAC,EAAE,GAAG,OAAO;AAAA,MAG7C;AAAA,IAAA;AAAA,IAFI;AAAA,IAFN;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAC;AAAAA,EAAA,CAMA,EARK,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EASP,GAAAA,MAAA;AACD,CAAC;;"}
@@ -0,0 +1,29 @@
1
+ import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
2
+ import { EnvironmentMiddleware } from "../accessorPropagation/EnvironmentContext.js";
3
+ import { Component } from "../coreComponents/Component.js";
4
+ const DimensionRenderer = Component(({ dimension, as, children }, env) => {
5
+ const dimensions = env.getDimensionOrElse(dimension, []);
6
+ return /* @__PURE__ */ jsxDEV(Fragment, { children: dimensions.map((value) => /* @__PURE__ */ jsxDEV(
7
+ EnvironmentMiddleware,
8
+ {
9
+ create: (it) => it.withVariables({ [as]: value }),
10
+ children
11
+ },
12
+ value,
13
+ false,
14
+ {
15
+ fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/DimensionRenderer.tsx",
16
+ lineNumber: 17,
17
+ columnNumber: 4
18
+ },
19
+ void 0
20
+ )) }, void 0, false, {
21
+ fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/DimensionRenderer.tsx",
22
+ lineNumber: 15,
23
+ columnNumber: 9
24
+ }, void 0);
25
+ });
26
+ export {
27
+ DimensionRenderer
28
+ };
29
+ //# sourceMappingURL=DimensionRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DimensionRenderer.js","sources":["../../../src/helperComponents/DimensionRenderer.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ReactNode } from 'react'\nimport { EnvironmentMiddleware } from '../accessorPropagation'\nimport { Component } from '../coreComponents'\n\nexport type DimensionRendererProps = {\n\tdimension: string\n\tas: string\n\tchildren: ReactNode\n}\n\nexport const DimensionRenderer = Component<DimensionRendererProps>(({ dimension, as, children }, env) => {\n\tconst dimensions = env.getDimensionOrElse(dimension, [])\n\n\treturn <>\n\t\t{dimensions.map(value => (\n\t\t\t<EnvironmentMiddleware\n\t\t\t\tcreate={it => it.withVariables({ [as]: value })}\n\t\t\t\tkey={value}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</EnvironmentMiddleware>\n\t\t))}\n\t</>\n})\n"],"names":["this"],"mappings":";;;AAWa,MAAA,oBAAoB,UAAkC,CAAC,EAAE,WAAW,IAAI,YAAY,QAAQ;AACxG,QAAM,aAAa,IAAI,mBAAmB,WAAW,CAAE,CAAA;AAEhD,SAAA,uBAAA,UAAA,EACL,UAAW,WAAA,IAAI,CACf,UAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,QAAM,GAAG,cAAc,EAAE,CAAC,EAAE,GAAG,OAAO;AAAA,MAG7C;AAAA,IAAA;AAAA,IAFI;AAAA,IAFN;AAAA,IAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA;AAAA,IAAAA;AAAAA,EAAA,CAMA,EARK,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EASP,GAAAA,MAAA;AACD,CAAC;"}
@@ -10,40 +10,43 @@ const Component = require("../coreComponents/Component.cjs");
10
10
  const useEntity = require("../accessorPropagation/useEntity.cjs");
11
11
  const useEnvironment = require("../accessorPropagation/useEnvironment.cjs");
12
12
  const If = Component.Component(
13
- (props) => {
14
- return typeof props.condition !== "function" ? /* @__PURE__ */ jsxDevRuntime.jsxDEV(IfFilter, { condition: props.condition, children: props.children }, void 0, false, {
13
+ ({ condition, ...props }) => {
14
+ if (props.children && props.then) {
15
+ throw new Error("If component cannot have both children and then prop");
16
+ }
17
+ return typeof condition !== "function" ? /* @__PURE__ */ jsxDevRuntime.jsxDEV(IfFilter, { condition, ...props }, void 0, false, {
15
18
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
16
- lineNumber: 30,
19
+ lineNumber: 37,
17
20
  columnNumber: 6
18
- }, void 0) : /* @__PURE__ */ jsxDevRuntime.jsxDEV(IfCallback, { condition: props.condition, children: props.children }, void 0, false, {
21
+ }, void 0) : /* @__PURE__ */ jsxDevRuntime.jsxDEV(IfCallback, { condition, ...props }, void 0, false, {
19
22
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
20
- lineNumber: 31,
23
+ lineNumber: 38,
21
24
  columnNumber: 6
22
25
  }, void 0);
23
26
  },
24
27
  "If"
25
28
  );
26
29
  const IfCallback = Component.Component(
27
- ({ children, condition }) => {
30
+ ({ children, condition, then, else: elseIn }) => {
28
31
  const entity = useEntity.useEntity();
29
32
  const evaluated = react.useMemo(() => condition(entity), [condition, entity]);
30
- return evaluated ? /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children }, void 0, false, {
33
+ return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: evaluated ? children ?? then : elseIn }, void 0, false, {
31
34
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
32
- lineNumber: 41,
33
- columnNumber: 22
34
- }, void 0) : null;
35
+ lineNumber: 48,
36
+ columnNumber: 10
37
+ }, void 0);
35
38
  },
36
39
  ({ children }) => {
37
40
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children }, void 0, false, {
38
41
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
39
- lineNumber: 44,
42
+ lineNumber: 51,
40
43
  columnNumber: 10
41
44
  }, void 0);
42
45
  },
43
46
  "IfCallback"
44
47
  );
45
48
  const IfFilter = Component.Component(
46
- ({ children, condition }) => {
49
+ ({ children, condition, then, else: elseIn }) => {
47
50
  const env = useEnvironment.useEnvironment();
48
51
  const entity = useEntity.useEntity();
49
52
  const schema = env.getSchema();
@@ -51,22 +54,22 @@ const IfFilter = Component.Component(
51
54
  () => new FilterEvaluator.FilterEvaluator(schema).evaluateFilter(entity, binding.QueryLanguage.desugarFilter(condition, env)),
52
55
  [condition, entity, env, schema]
53
56
  );
54
- return evaluated ? /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children }, void 0, false, {
57
+ return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: evaluated ? children ?? then : elseIn }, void 0, false, {
55
58
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
56
- lineNumber: 60,
57
- columnNumber: 22
58
- }, void 0) : null;
59
+ lineNumber: 66,
60
+ columnNumber: 10
61
+ }, void 0);
59
62
  },
60
63
  ({ children, condition }, env) => {
61
64
  const desugaredFilter = binding.QueryLanguage.desugarFilter(condition, env);
62
65
  const collectedFields = new FilterFieldsCollector.FilterFieldsCollector(env.getSchema(), desugaredFilter).collectFields(env.getSubTreeNode().entity);
63
66
  const additionalFields = /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: Array.from(collectedFields).map((it) => /* @__PURE__ */ jsxDevRuntime.jsxDEV(Field.Field, { field: it }, it, false, {
64
67
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
65
- lineNumber: 65,
68
+ lineNumber: 71,
66
69
  columnNumber: 69
67
70
  }, void 0)) }, void 0, false, {
68
71
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
69
- lineNumber: 65,
72
+ lineNumber: 71,
70
73
  columnNumber: 28
71
74
  }, void 0);
72
75
  return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: [
@@ -74,7 +77,7 @@ const IfFilter = Component.Component(
74
77
  children
75
78
  ] }, void 0, true, {
76
79
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
77
- lineNumber: 67,
80
+ lineNumber: 73,
78
81
  columnNumber: 10
79
82
  }, void 0);
80
83
  },
@@ -1 +1 @@
1
- {"version":3,"file":"If.cjs","sources":["../../../src/helperComponents/If.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { useMemo } from 'react'\nimport { Component, Field } from '../coreComponents'\nimport { EntityAccessor } from '@contember/binding'\nimport { QueryLanguage } from '@contember/binding'\nimport { useEntity, useEnvironment } from '../accessorPropagation'\nimport { Filter } from '@contember/binding'\nimport { FilterFieldsCollector } from './helpers/FilterFieldsCollector'\nimport { FilterEvaluator } from './helpers/FilterEvaluator'\n\nexport type IfProps =\n\t| IfFilterProps\n\t| IfCallbackProps\n\nexport interface IfFilterProps {\n\tcondition: string | Filter\n\tchildren?: ReactNode\n}\n\nexport interface IfCallbackProps {\n\tcondition: (accessor: EntityAccessor) => boolean\n\tchildren?: ReactNode\n}\n\n/**\n * @group Logic Components\n */\nexport const If = Component<IfProps>(props => {\n\t\treturn typeof props.condition !== 'function'\n\t\t\t? <IfFilter condition={props.condition}>{props.children}</IfFilter>\n\t\t\t: <IfCallback condition={props.condition}>{props.children}</IfCallback>\n\t},\n\t'If',\n)\n\nconst IfCallback = Component<IfCallbackProps>(\n\t({ children, condition }) => {\n\t\tconst entity = useEntity()\n\t\tconst evaluated = useMemo(() => condition(entity), [condition, entity])\n\n\t\treturn evaluated ? <>{children}</> : null\n\t},\n\t({ children }) => {\n\t\treturn <>{children}</>\n\t},\n\t'IfCallback',\n)\n\nconst IfFilter = Component<IfFilterProps>(\n\t({ children, condition }) => {\n\t\tconst env = useEnvironment()\n\t\tconst entity = useEntity()\n\n\t\tconst schema = env.getSchema()\n\t\tconst evaluated = useMemo(\n\t\t\t() => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),\n\t\t\t[condition, entity, env, schema],\n\t\t)\n\n\t\treturn evaluated ? <>{children}</> : null\n\t},\n\t({ children, condition }, env) => {\n\t\tconst desugaredFilter = QueryLanguage.desugarFilter(condition, env)\n\t\tconst collectedFields = new FilterFieldsCollector(env.getSchema(), desugaredFilter).collectFields(env.getSubTreeNode().entity)\n\t\tconst additionalFields = <>{Array.from(collectedFields).map(it => <Field field={it} key={it} />)}</>\n\n\t\treturn <>\n\t\t\t{additionalFields}\n\t\t\t{children}\n\t\t</>\n\t},\n\t'IfFilter',\n)\n\n"],"names":["Component","jsxDEV","this","useEntity","useMemo","useEnvironment","FilterEvaluator","QueryLanguage","FilterFieldsCollector","Fragment","Field"],"mappings":";;;;;;;;;;;AA2BO,MAAM,KAAKA,UAAA;AAAA,EAAmB,CAAS,UAAA;AACrC,WAAA,OAAO,MAAM,cAAc,aAC/BC,8BAAA,OAAC,YAAS,WAAW,MAAM,WAAY,UAAA,MAAM,SAA7C,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA,GAAAC,MAAsD,IACrDD,8BAAAA,OAAA,YAAA,EAAW,WAAW,MAAM,WAAY,gBAAM,SAA/C,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAwD,GAAAC,MAAA;AAAA,EAC5D;AAAA,EACA;AACD;AAEA,MAAM,aAAaF,UAAA;AAAA,EAClB,CAAC,EAAE,UAAU,gBAAgB;AAC5B,UAAM,SAASG,UAAAA;AACT,UAAA,YAAYC,cAAQ,MAAM,UAAU,MAAM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AR,MAA2B,CAAE,EAAtE,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAwE,GAAAA,MAAA;AAEjG,WACED,8BAAA,OAAAQ,wBAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA;AAAA,IAAA,KAFK,QAAA,MAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAGP,GAAAP,MAAA;AAAA,EACD;AAAA,EACA;AACD;;"}
1
+ {"version":3,"file":"If.cjs","sources":["../../../src/helperComponents/If.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { useMemo } from 'react'\nimport { Component, Field } from '../coreComponents'\nimport { EntityAccessor } from '@contember/binding'\nimport { QueryLanguage } from '@contember/binding'\nimport { useEntity, useEnvironment } from '../accessorPropagation'\nimport { Filter } from '@contember/binding'\nimport { FilterFieldsCollector } from './helpers/FilterFieldsCollector'\nimport { FilterEvaluator } from './helpers/FilterEvaluator'\n\nexport type IfProps =\n\t| IfFilterProps\n\t| IfCallbackProps\n\nexport interface IfFilterProps {\n\tcondition: string | Filter\n\tchildren?: ReactNode\n\tthen?: ReactNode\n\telse?: ReactNode\n}\n\nexport interface IfCallbackProps {\n\tcondition: (accessor: EntityAccessor) => boolean\n\tchildren?: ReactNode\n\tthen?: ReactNode\n\telse?: ReactNode\n}\n\n/**\n * @group Logic Components\n */\nexport const If = Component<IfProps>(({ condition, ...props }) => {\n\t\tif (props.children && props.then) {\n\t\t\tthrow new Error('If component cannot have both children and then prop')\n\t\t}\n\t\treturn typeof condition !== 'function'\n\t\t\t? <IfFilter condition={condition} {...props} />\n\t\t\t: <IfCallback condition={condition} {...props} />\n\t},\n\t'If',\n)\n\nconst IfCallback = Component<IfCallbackProps>(\n\t({ children, condition, then, else: elseIn }) => {\n\t\tconst entity = useEntity()\n\t\tconst evaluated = useMemo(() => condition(entity), [condition, entity])\n\n\t\treturn <>{evaluated ? (children ?? then) : elseIn}</>\n\t},\n\t({ children }) => {\n\t\treturn <>{children}</>\n\t},\n\t'IfCallback',\n)\n\nconst IfFilter = Component<IfFilterProps>(\n\t({ children, condition, then, else: elseIn }) => {\n\t\tconst env = useEnvironment()\n\t\tconst entity = useEntity()\n\n\t\tconst schema = env.getSchema()\n\t\tconst evaluated = useMemo(\n\t\t\t() => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),\n\t\t\t[condition, entity, env, schema],\n\t\t)\n\t\treturn <>{evaluated ? (children ?? then) : elseIn}</>\n\t},\n\t({ children, condition }, env) => {\n\t\tconst desugaredFilter = QueryLanguage.desugarFilter(condition, env)\n\t\tconst collectedFields = new FilterFieldsCollector(env.getSchema(), desugaredFilter).collectFields(env.getSubTreeNode().entity)\n\t\tconst additionalFields = <>{Array.from(collectedFields).map(it => <Field field={it} key={it} />)}</>\n\n\t\treturn <>\n\t\t\t{additionalFields}\n\t\t\t{children}\n\t\t</>\n\t},\n\t'IfFilter',\n)\n"],"names":["Component","this","jsxDEV","useEntity","useMemo","Fragment","useEnvironment","FilterEvaluator","QueryLanguage","FilterFieldsCollector","Field"],"mappings":";;;;;;;;;;;AA+BO,MAAM,KAAKA,UAAA;AAAA,EAAmB,CAAC,EAAE,WAAW,GAAG,YAAY;AAC5D,QAAA,MAAM,YAAY,MAAM,MAAM;AAC3B,YAAA,IAAI,MAAM,sDAAsD;AAAA,IACvE;AACA,WAAO,OAAO,cAAc,kDACxB,UAAS,EAAA,WAAuB,GAAG,MAApC,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA,GAAAC,MAA2C,IAC3CC,8BAAA,OAAC,YAAW,EAAA,WAAuB,GAAG,MAAtC,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAA6C,GAAAD,MAAA;AAAA,EACjD;AAAA,EACA;AAC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Ac,IAAI,eAAe,EAAE,MAAM;AAC7H,UAAM,mBAAmBP,8BAAAA,OAAAG,cAAA,UAAA,EAAG,UAAM,MAAA,KAAK,eAAe,EAAE,IAAI,CAAA,OAAOH,8BAAA,OAAAQ,aAAA,EAAM,OAAO,GAAA,GAAS,IAAvB,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA,GAAAT,MAA2B,CAAE,EAAtE,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAwE,GAAAA,MAAA;AAEjG,WACEC,8BAAA,OAAAG,wBAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA;AAAA,IAAA,KAFK,QAAA,MAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAGP,GAAAJ,MAAA;AAAA,EACD;AAAA,EACA;AACD;;"}
@@ -8,40 +8,43 @@ import { Component } from "../coreComponents/Component.js";
8
8
  import { useEntity } from "../accessorPropagation/useEntity.js";
9
9
  import { useEnvironment } from "../accessorPropagation/useEnvironment.js";
10
10
  const If = Component(
11
- (props) => {
12
- return typeof props.condition !== "function" ? /* @__PURE__ */ jsxDEV(IfFilter, { condition: props.condition, children: props.children }, void 0, false, {
11
+ ({ condition, ...props }) => {
12
+ if (props.children && props.then) {
13
+ throw new Error("If component cannot have both children and then prop");
14
+ }
15
+ return typeof condition !== "function" ? /* @__PURE__ */ jsxDEV(IfFilter, { condition, ...props }, void 0, false, {
13
16
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
14
- lineNumber: 30,
17
+ lineNumber: 37,
15
18
  columnNumber: 6
16
- }, void 0) : /* @__PURE__ */ jsxDEV(IfCallback, { condition: props.condition, children: props.children }, void 0, false, {
19
+ }, void 0) : /* @__PURE__ */ jsxDEV(IfCallback, { condition, ...props }, void 0, false, {
17
20
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
18
- lineNumber: 31,
21
+ lineNumber: 38,
19
22
  columnNumber: 6
20
23
  }, void 0);
21
24
  },
22
25
  "If"
23
26
  );
24
27
  const IfCallback = Component(
25
- ({ children, condition }) => {
28
+ ({ children, condition, then, else: elseIn }) => {
26
29
  const entity = useEntity();
27
30
  const evaluated = useMemo(() => condition(entity), [condition, entity]);
28
- return evaluated ? /* @__PURE__ */ jsxDEV(Fragment, { children }, void 0, false, {
31
+ return /* @__PURE__ */ jsxDEV(Fragment, { children: evaluated ? children ?? then : elseIn }, void 0, false, {
29
32
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
30
- lineNumber: 41,
31
- columnNumber: 22
32
- }, void 0) : null;
33
+ lineNumber: 48,
34
+ columnNumber: 10
35
+ }, void 0);
33
36
  },
34
37
  ({ children }) => {
35
38
  return /* @__PURE__ */ jsxDEV(Fragment, { children }, void 0, false, {
36
39
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
37
- lineNumber: 44,
40
+ lineNumber: 51,
38
41
  columnNumber: 10
39
42
  }, void 0);
40
43
  },
41
44
  "IfCallback"
42
45
  );
43
46
  const IfFilter = Component(
44
- ({ children, condition }) => {
47
+ ({ children, condition, then, else: elseIn }) => {
45
48
  const env = useEnvironment();
46
49
  const entity = useEntity();
47
50
  const schema = env.getSchema();
@@ -49,22 +52,22 @@ const IfFilter = Component(
49
52
  () => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),
50
53
  [condition, entity, env, schema]
51
54
  );
52
- return evaluated ? /* @__PURE__ */ jsxDEV(Fragment, { children }, void 0, false, {
55
+ return /* @__PURE__ */ jsxDEV(Fragment, { children: evaluated ? children ?? then : elseIn }, void 0, false, {
53
56
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
54
- lineNumber: 60,
55
- columnNumber: 22
56
- }, void 0) : null;
57
+ lineNumber: 66,
58
+ columnNumber: 10
59
+ }, void 0);
57
60
  },
58
61
  ({ children, condition }, env) => {
59
62
  const desugaredFilter = QueryLanguage.desugarFilter(condition, env);
60
63
  const collectedFields = new FilterFieldsCollector(env.getSchema(), desugaredFilter).collectFields(env.getSubTreeNode().entity);
61
64
  const additionalFields = /* @__PURE__ */ jsxDEV(Fragment, { children: Array.from(collectedFields).map((it) => /* @__PURE__ */ jsxDEV(Field, { field: it }, it, false, {
62
65
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
63
- lineNumber: 65,
66
+ lineNumber: 71,
64
67
  columnNumber: 69
65
68
  }, void 0)) }, void 0, false, {
66
69
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
67
- lineNumber: 65,
70
+ lineNumber: 71,
68
71
  columnNumber: 28
69
72
  }, void 0);
70
73
  return /* @__PURE__ */ jsxDEV(Fragment, { children: [
@@ -72,7 +75,7 @@ const IfFilter = Component(
72
75
  children
73
76
  ] }, void 0, true, {
74
77
  fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/If.tsx",
75
- lineNumber: 67,
78
+ lineNumber: 73,
76
79
  columnNumber: 10
77
80
  }, void 0);
78
81
  },
@@ -1 +1 @@
1
- {"version":3,"file":"If.js","sources":["../../../src/helperComponents/If.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { useMemo } from 'react'\nimport { Component, Field } from '../coreComponents'\nimport { EntityAccessor } from '@contember/binding'\nimport { QueryLanguage } from '@contember/binding'\nimport { useEntity, useEnvironment } from '../accessorPropagation'\nimport { Filter } from '@contember/binding'\nimport { FilterFieldsCollector } from './helpers/FilterFieldsCollector'\nimport { FilterEvaluator } from './helpers/FilterEvaluator'\n\nexport type IfProps =\n\t| IfFilterProps\n\t| IfCallbackProps\n\nexport interface IfFilterProps {\n\tcondition: string | Filter\n\tchildren?: ReactNode\n}\n\nexport interface IfCallbackProps {\n\tcondition: (accessor: EntityAccessor) => boolean\n\tchildren?: ReactNode\n}\n\n/**\n * @group Logic Components\n */\nexport const If = Component<IfProps>(props => {\n\t\treturn typeof props.condition !== 'function'\n\t\t\t? <IfFilter condition={props.condition}>{props.children}</IfFilter>\n\t\t\t: <IfCallback condition={props.condition}>{props.children}</IfCallback>\n\t},\n\t'If',\n)\n\nconst IfCallback = Component<IfCallbackProps>(\n\t({ children, condition }) => {\n\t\tconst entity = useEntity()\n\t\tconst evaluated = useMemo(() => condition(entity), [condition, entity])\n\n\t\treturn evaluated ? <>{children}</> : null\n\t},\n\t({ children }) => {\n\t\treturn <>{children}</>\n\t},\n\t'IfCallback',\n)\n\nconst IfFilter = Component<IfFilterProps>(\n\t({ children, condition }) => {\n\t\tconst env = useEnvironment()\n\t\tconst entity = useEntity()\n\n\t\tconst schema = env.getSchema()\n\t\tconst evaluated = useMemo(\n\t\t\t() => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),\n\t\t\t[condition, entity, env, schema],\n\t\t)\n\n\t\treturn evaluated ? <>{children}</> : null\n\t},\n\t({ children, condition }, env) => {\n\t\tconst desugaredFilter = QueryLanguage.desugarFilter(condition, env)\n\t\tconst collectedFields = new FilterFieldsCollector(env.getSchema(), desugaredFilter).collectFields(env.getSubTreeNode().entity)\n\t\tconst additionalFields = <>{Array.from(collectedFields).map(it => <Field field={it} key={it} />)}</>\n\n\t\treturn <>\n\t\t\t{additionalFields}\n\t\t\t{children}\n\t\t</>\n\t},\n\t'IfFilter',\n)\n\n"],"names":["this"],"mappings":";;;;;;;;;AA2BO,MAAM,KAAK;AAAA,EAAmB,CAAS,UAAA;AACrC,WAAA,OAAO,MAAM,cAAc,aAC/B,uBAAC,YAAS,WAAW,MAAM,WAAY,UAAA,MAAM,SAA7C,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA,GAAAA,MAAsD,IACrD,uBAAA,YAAA,EAAW,WAAW,MAAM,WAAY,gBAAM,SAA/C,GAAA,QAAA,OA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AAe,EAAE,IAAI,CAAA,OAAO,uBAAA,OAAA,EAAM,OAAO,GAAA,GAAS,IAAvB,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA,GAAAA,MAA2B,CAAE,EAAtE,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAwE,GAAAA,MAAA;AAEjG,WACE,uBAAA,UAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA;AAAA,IAAA,KAFK,QAAA,MAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAGP,GAAAA,MAAA;AAAA,EACD;AAAA,EACA;AACD;"}
1
+ {"version":3,"file":"If.js","sources":["../../../src/helperComponents/If.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { useMemo } from 'react'\nimport { Component, Field } from '../coreComponents'\nimport { EntityAccessor } from '@contember/binding'\nimport { QueryLanguage } from '@contember/binding'\nimport { useEntity, useEnvironment } from '../accessorPropagation'\nimport { Filter } from '@contember/binding'\nimport { FilterFieldsCollector } from './helpers/FilterFieldsCollector'\nimport { FilterEvaluator } from './helpers/FilterEvaluator'\n\nexport type IfProps =\n\t| IfFilterProps\n\t| IfCallbackProps\n\nexport interface IfFilterProps {\n\tcondition: string | Filter\n\tchildren?: ReactNode\n\tthen?: ReactNode\n\telse?: ReactNode\n}\n\nexport interface IfCallbackProps {\n\tcondition: (accessor: EntityAccessor) => boolean\n\tchildren?: ReactNode\n\tthen?: ReactNode\n\telse?: ReactNode\n}\n\n/**\n * @group Logic Components\n */\nexport const If = Component<IfProps>(({ condition, ...props }) => {\n\t\tif (props.children && props.then) {\n\t\t\tthrow new Error('If component cannot have both children and then prop')\n\t\t}\n\t\treturn typeof condition !== 'function'\n\t\t\t? <IfFilter condition={condition} {...props} />\n\t\t\t: <IfCallback condition={condition} {...props} />\n\t},\n\t'If',\n)\n\nconst IfCallback = Component<IfCallbackProps>(\n\t({ children, condition, then, else: elseIn }) => {\n\t\tconst entity = useEntity()\n\t\tconst evaluated = useMemo(() => condition(entity), [condition, entity])\n\n\t\treturn <>{evaluated ? (children ?? then) : elseIn}</>\n\t},\n\t({ children }) => {\n\t\treturn <>{children}</>\n\t},\n\t'IfCallback',\n)\n\nconst IfFilter = Component<IfFilterProps>(\n\t({ children, condition, then, else: elseIn }) => {\n\t\tconst env = useEnvironment()\n\t\tconst entity = useEntity()\n\n\t\tconst schema = env.getSchema()\n\t\tconst evaluated = useMemo(\n\t\t\t() => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),\n\t\t\t[condition, entity, env, schema],\n\t\t)\n\t\treturn <>{evaluated ? (children ?? then) : elseIn}</>\n\t},\n\t({ children, condition }, env) => {\n\t\tconst desugaredFilter = QueryLanguage.desugarFilter(condition, env)\n\t\tconst collectedFields = new FilterFieldsCollector(env.getSchema(), desugaredFilter).collectFields(env.getSubTreeNode().entity)\n\t\tconst additionalFields = <>{Array.from(collectedFields).map(it => <Field field={it} key={it} />)}</>\n\n\t\treturn <>\n\t\t\t{additionalFields}\n\t\t\t{children}\n\t\t</>\n\t},\n\t'IfFilter',\n)\n"],"names":["this"],"mappings":";;;;;;;;;AA+BO,MAAM,KAAK;AAAA,EAAmB,CAAC,EAAE,WAAW,GAAG,YAAY;AAC5D,QAAA,MAAM,YAAY,MAAM,MAAM;AAC3B,YAAA,IAAI,MAAM,sDAAsD;AAAA,IACvE;AACA,WAAO,OAAO,cAAc,oCACxB,UAAS,EAAA,WAAuB,GAAG,MAApC,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA,GAAAA,MAA2C,IAC3C,uBAAC,YAAW,EAAA,WAAuB,GAAG,MAAtC,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IA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uBAAA,UAAA,EAAG,UAAM,MAAA,KAAK,eAAe,EAAE,IAAI,CAAA,OAAO,uBAAA,OAAA,EAAM,OAAO,GAAA,GAAS,IAAvB,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAA,GAAAA,MAA2B,CAAE,EAAtE,GAAA,QAAA,OAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAAwE,GAAAA,MAAA;AAEjG,WACE,uBAAA,UAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA;AAAA,IAAA,KAFK,QAAA,MAAA;AAAA,MAAA,UAAA;AAAA,MAAA,YAAA;AAAA,MAAA,cAAA;AAAA,IAGP,GAAAA,MAAA;AAAA,EACD;AAAA,EACA;AACD;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxDevRuntime = require("react/jsx-dev-runtime");
4
+ const react = require("react");
5
+ const useEnvironment = require("../accessorPropagation/useEnvironment.cjs");
6
+ const Variable = react.memo(({ name, format }) => {
7
+ const environment = useEnvironment.useEnvironment();
8
+ const value = environment.getVariableOrElse(name, void 0) ?? environment.getParameter(name);
9
+ const formatted = react.useMemo(() => format ? format(value) : value, [format, value]);
10
+ return /* @__PURE__ */ jsxDevRuntime.jsxDEV(jsxDevRuntime.Fragment, { children: formatted }, void 0, false, {
11
+ fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/Variable.tsx",
12
+ lineNumber: 16,
13
+ columnNumber: 9
14
+ }, void 0);
15
+ });
16
+ Variable.displayName = "Variable";
17
+ exports.Variable = Variable;
18
+ //# sourceMappingURL=Variable.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Variable.cjs","sources":["../../../src/helperComponents/Variable.tsx"],"sourcesContent":["import { Environment } from '@contember/binding'\nimport { memo, ReactElement, ReactNode, useMemo } from 'react'\nimport { useEnvironment } from '../accessorPropagation'\n\nexport interface VariableProps {\n\tname: Environment.Name\n\tformat?: (value: ReactNode) => ReactNode\n}\n\nexport const Variable = memo(({ name, format }: VariableProps): ReactElement => {\n\tconst environment = useEnvironment()\n\tconst value = environment.getVariableOrElse<undefined, ReactNode & Environment.Value>(name, undefined) ?? environment.getParameter(name)\n\n\tconst formatted = useMemo(() => (format ? format(value) : value), [format, value])\n\n\treturn <>{formatted}</>\n})\nVariable.displayName = 'Variable'\n"],"names":["memo","useEnvironment","useMemo","this"],"mappings":";;;;;AASO,MAAM,WAAWA,MAAAA,KAAK,CAAC,EAAE,MAAM,aAA0C;AAC/E,QAAM,cAAcC,eAAAA;AACd,QAAA,QAAQ,YAAY,kBAA4D,MAAM,MAAS,KAAK,YAAY,aAAa,IAAI;AAEjI,QAAA,YAAYC,MAAAA,QAAQ,MAAO,SAAS,OAAO,KAAK,IAAI,OAAQ,CAAC,QAAQ,KAAK,CAAC;AAEjF,wEAAU,UAAH,aAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAa,GAAAC,MAAA;AACrB,CAAC;AACD,SAAS,cAAc;;"}
@@ -0,0 +1,18 @@
1
+ import { jsxDEV, Fragment } from "react/jsx-dev-runtime";
2
+ import { memo, useMemo } from "react";
3
+ import { useEnvironment } from "../accessorPropagation/useEnvironment.js";
4
+ const Variable = memo(({ name, format }) => {
5
+ const environment = useEnvironment();
6
+ const value = environment.getVariableOrElse(name, void 0) ?? environment.getParameter(name);
7
+ const formatted = useMemo(() => format ? format(value) : value, [format, value]);
8
+ return /* @__PURE__ */ jsxDEV(Fragment, { children: formatted }, void 0, false, {
9
+ fileName: "/__w/interface/interface/packages/react-binding/src/helperComponents/Variable.tsx",
10
+ lineNumber: 16,
11
+ columnNumber: 9
12
+ }, void 0);
13
+ });
14
+ Variable.displayName = "Variable";
15
+ export {
16
+ Variable
17
+ };
18
+ //# sourceMappingURL=Variable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Variable.js","sources":["../../../src/helperComponents/Variable.tsx"],"sourcesContent":["import { Environment } from '@contember/binding'\nimport { memo, ReactElement, ReactNode, useMemo } from 'react'\nimport { useEnvironment } from '../accessorPropagation'\n\nexport interface VariableProps {\n\tname: Environment.Name\n\tformat?: (value: ReactNode) => ReactNode\n}\n\nexport const Variable = memo(({ name, format }: VariableProps): ReactElement => {\n\tconst environment = useEnvironment()\n\tconst value = environment.getVariableOrElse<undefined, ReactNode & Environment.Value>(name, undefined) ?? environment.getParameter(name)\n\n\tconst formatted = useMemo(() => (format ? format(value) : value), [format, value])\n\n\treturn <>{formatted}</>\n})\nVariable.displayName = 'Variable'\n"],"names":["this"],"mappings":";;;AASO,MAAM,WAAW,KAAK,CAAC,EAAE,MAAM,aAA0C;AAC/E,QAAM,cAAc;AACd,QAAA,QAAQ,YAAY,kBAA4D,MAAM,MAAS,KAAK,YAAY,aAAa,IAAI;AAEjI,QAAA,YAAY,QAAQ,MAAO,SAAS,OAAO,KAAK,IAAI,OAAQ,CAAC,QAAQ,KAAK,CAAC;AAEjF,4CAAU,UAAH,aAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAa,GAAAA,MAAA;AACrB,CAAC;AACD,SAAS,cAAc;"}
@@ -62,12 +62,14 @@ const useEntityPersistError = require("./entityEvents/useEntityPersistError.cjs"
62
62
  const useEntityPersistSuccess = require("./entityEvents/useEntityPersistSuccess.cjs");
63
63
  const useOnConnectionUpdate = require("./entityEvents/useOnConnectionUpdate.cjs");
64
64
  const DeferredSubTrees = require("./helperComponents/DeferredSubTrees.cjs");
65
+ const DimensionRenderer = require("./helperComponents/DimensionRenderer.cjs");
65
66
  const EntityView = require("./helperComponents/EntityView.cjs");
66
67
  const If = require("./helperComponents/If.cjs");
67
68
  const FieldView = require("./helperComponents/FieldView.cjs");
68
69
  const LabelMiddleware = require("./helperComponents/LabelMiddleware.cjs");
69
70
  const StaticRender = require("./helperComponents/StaticRender.cjs");
70
71
  const SugaredField = require("./helperComponents/SugaredField.cjs");
72
+ const Variable = require("./helperComponents/Variable.cjs");
71
73
  exports.MarkerTreeGenerator = MarkerTreeGenerator.MarkerTreeGenerator;
72
74
  exports.AccessorTree = AccessorTree.AccessorTree;
73
75
  exports.accessorTreeStateReducer = accessorTreeStateReducer.accessorTreeStateReducer;
@@ -132,6 +134,7 @@ exports.useEntityPersistError = useEntityPersistError.useEntityPersistError;
132
134
  exports.useEntityPersistSuccess = useEntityPersistSuccess.useEntityPersistSuccess;
133
135
  exports.useOnConnectionUpdate = useOnConnectionUpdate.useOnConnectionUpdate;
134
136
  exports.DeferredSubTrees = DeferredSubTrees.DeferredSubTrees;
137
+ exports.DimensionRenderer = DimensionRenderer.DimensionRenderer;
135
138
  exports.EntityView = EntityView.EntityView;
136
139
  exports.If = If.If;
137
140
  exports.FieldView = FieldView.FieldView;
@@ -140,6 +143,7 @@ exports.LabelMiddlewareProvider = LabelMiddleware.LabelMiddlewareProvider;
140
143
  exports.useLabelMiddleware = LabelMiddleware.useLabelMiddleware;
141
144
  exports.StaticRender = StaticRender.StaticRender;
142
145
  exports.SugaredField = SugaredField.SugaredField;
146
+ exports.Variable = Variable.Variable;
143
147
  Object.keys(binding).forEach((k) => {
144
148
  if (k !== "default" && !Object.prototype.hasOwnProperty.call(exports, k))
145
149
  Object.defineProperty(exports, k, {
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -60,12 +60,14 @@ import { useEntityPersistError } from "./entityEvents/useEntityPersistError.js";
60
60
  import { useEntityPersistSuccess } from "./entityEvents/useEntityPersistSuccess.js";
61
61
  import { useOnConnectionUpdate } from "./entityEvents/useOnConnectionUpdate.js";
62
62
  import { DeferredSubTrees } from "./helperComponents/DeferredSubTrees.js";
63
+ import { DimensionRenderer } from "./helperComponents/DimensionRenderer.js";
63
64
  import { EntityView } from "./helperComponents/EntityView.js";
64
65
  import { If } from "./helperComponents/If.js";
65
66
  import { FieldView } from "./helperComponents/FieldView.js";
66
67
  import { LabelMiddlewareContext, LabelMiddlewareProvider, useLabelMiddleware } from "./helperComponents/LabelMiddleware.js";
67
68
  import { StaticRender } from "./helperComponents/StaticRender.js";
68
69
  import { SugaredField } from "./helperComponents/SugaredField.js";
70
+ import { Variable } from "./helperComponents/Variable.js";
69
71
  export {
70
72
  AccessorProvider,
71
73
  AccessorTree,
@@ -73,6 +75,7 @@ export {
73
75
  Component,
74
76
  DataBindingProvider,
75
77
  DeferredSubTrees,
78
+ DimensionRenderer,
76
79
  DirtinessContext,
77
80
  Entity,
78
81
  EntityKeyProvider,
@@ -97,6 +100,7 @@ export {
97
100
  StaticRender,
98
101
  SugaredField,
99
102
  TreeRootIdProvider,
103
+ Variable,
100
104
  accessorTreeStateReducer,
101
105
  addEntityAtIndex,
102
106
  moveEntity,
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const EnvironmentContext = require("../accessorPropagation/EnvironmentContext.cjs");
5
+ const Component = require("../coreComponents/Component.cjs");
6
+ const DimensionRenderer = Component.Component(({ dimension, as, children }, env) => {
7
+ const dimensions = env.getDimensionOrElse(dimension, []);
8
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: dimensions.map((value) => /* @__PURE__ */ jsxRuntime.jsx(
9
+ EnvironmentContext.EnvironmentMiddleware,
10
+ {
11
+ create: (it) => it.withVariables({ [as]: value }),
12
+ children
13
+ },
14
+ value
15
+ )) });
16
+ });
17
+ exports.DimensionRenderer = DimensionRenderer;
18
+ //# sourceMappingURL=DimensionRenderer.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DimensionRenderer.cjs","sources":["../../../src/helperComponents/DimensionRenderer.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ReactNode } from 'react'\nimport { EnvironmentMiddleware } from '../accessorPropagation'\nimport { Component } from '../coreComponents'\n\nexport type DimensionRendererProps = {\n\tdimension: string\n\tas: string\n\tchildren: ReactNode\n}\n\nexport const DimensionRenderer = Component<DimensionRendererProps>(({ dimension, as, children }, env) => {\n\tconst dimensions = env.getDimensionOrElse(dimension, [])\n\n\treturn <>\n\t\t{dimensions.map(value => (\n\t\t\t<EnvironmentMiddleware\n\t\t\t\tcreate={it => it.withVariables({ [as]: value })}\n\t\t\t\tkey={value}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</EnvironmentMiddleware>\n\t\t))}\n\t</>\n})\n"],"names":["Component","jsx","Fragment","EnvironmentMiddleware"],"mappings":";;;;;AAWa,MAAA,oBAAoBA,oBAAkC,CAAC,EAAE,WAAW,IAAI,YAAY,QAAQ;AACxG,QAAM,aAAa,IAAI,mBAAmB,WAAW,CAAE,CAAA;AAEhD,SAAAC,2BAAAA,IAAAC,WAAAA,UAAA,EACL,UAAW,WAAA,IAAI,CACf,UAAAD,2BAAA;AAAA,IAACE,mBAAA;AAAA,IAAA;AAAA,MACA,QAAQ,QAAM,GAAG,cAAc,EAAE,CAAC,EAAE,GAAG,OAAO;AAAA,MAG7C;AAAA,IAAA;AAAA,IAFI;AAAA,EAIN,CAAA,EACF,CAAA;AACD,CAAC;;"}
@@ -0,0 +1,18 @@
1
+ import { jsx, Fragment } from "react/jsx-runtime";
2
+ import { EnvironmentMiddleware } from "../accessorPropagation/EnvironmentContext.js";
3
+ import { Component } from "../coreComponents/Component.js";
4
+ const DimensionRenderer = Component(({ dimension, as, children }, env) => {
5
+ const dimensions = env.getDimensionOrElse(dimension, []);
6
+ return /* @__PURE__ */ jsx(Fragment, { children: dimensions.map((value) => /* @__PURE__ */ jsx(
7
+ EnvironmentMiddleware,
8
+ {
9
+ create: (it) => it.withVariables({ [as]: value }),
10
+ children
11
+ },
12
+ value
13
+ )) });
14
+ });
15
+ export {
16
+ DimensionRenderer
17
+ };
18
+ //# sourceMappingURL=DimensionRenderer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"DimensionRenderer.js","sources":["../../../src/helperComponents/DimensionRenderer.tsx"],"sourcesContent":["import * as React from 'react'\nimport { ReactNode } from 'react'\nimport { EnvironmentMiddleware } from '../accessorPropagation'\nimport { Component } from '../coreComponents'\n\nexport type DimensionRendererProps = {\n\tdimension: string\n\tas: string\n\tchildren: ReactNode\n}\n\nexport const DimensionRenderer = Component<DimensionRendererProps>(({ dimension, as, children }, env) => {\n\tconst dimensions = env.getDimensionOrElse(dimension, [])\n\n\treturn <>\n\t\t{dimensions.map(value => (\n\t\t\t<EnvironmentMiddleware\n\t\t\t\tcreate={it => it.withVariables({ [as]: value })}\n\t\t\t\tkey={value}\n\t\t\t>\n\t\t\t\t{children}\n\t\t\t</EnvironmentMiddleware>\n\t\t))}\n\t</>\n})\n"],"names":[],"mappings":";;;AAWa,MAAA,oBAAoB,UAAkC,CAAC,EAAE,WAAW,IAAI,YAAY,QAAQ;AACxG,QAAM,aAAa,IAAI,mBAAmB,WAAW,CAAE,CAAA;AAEhD,SAAA,oBAAA,UAAA,EACL,UAAW,WAAA,IAAI,CACf,UAAA;AAAA,IAAC;AAAA,IAAA;AAAA,MACA,QAAQ,QAAM,GAAG,cAAc,EAAE,CAAC,EAAE,GAAG,OAAO;AAAA,MAG7C;AAAA,IAAA;AAAA,IAFI;AAAA,EAIN,CAAA,EACF,CAAA;AACD,CAAC;"}
@@ -10,16 +10,19 @@ const Component = require("../coreComponents/Component.cjs");
10
10
  const useEntity = require("../accessorPropagation/useEntity.cjs");
11
11
  const useEnvironment = require("../accessorPropagation/useEnvironment.cjs");
12
12
  const If = Component.Component(
13
- (props) => {
14
- return typeof props.condition !== "function" ? /* @__PURE__ */ jsxRuntime.jsx(IfFilter, { condition: props.condition, children: props.children }) : /* @__PURE__ */ jsxRuntime.jsx(IfCallback, { condition: props.condition, children: props.children });
13
+ ({ condition, ...props }) => {
14
+ if (props.children && props.then) {
15
+ throw new Error("If component cannot have both children and then prop");
16
+ }
17
+ return typeof condition !== "function" ? /* @__PURE__ */ jsxRuntime.jsx(IfFilter, { condition, ...props }) : /* @__PURE__ */ jsxRuntime.jsx(IfCallback, { condition, ...props });
15
18
  },
16
19
  "If"
17
20
  );
18
21
  const IfCallback = Component.Component(
19
- ({ children, condition }) => {
22
+ ({ children, condition, then, else: elseIn }) => {
20
23
  const entity = useEntity.useEntity();
21
24
  const evaluated = react.useMemo(() => condition(entity), [condition, entity]);
22
- return evaluated ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }) : null;
25
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: evaluated ? children ?? then : elseIn });
23
26
  },
24
27
  ({ children }) => {
25
28
  return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
@@ -27,7 +30,7 @@ const IfCallback = Component.Component(
27
30
  "IfCallback"
28
31
  );
29
32
  const IfFilter = Component.Component(
30
- ({ children, condition }) => {
33
+ ({ children, condition, then, else: elseIn }) => {
31
34
  const env = useEnvironment.useEnvironment();
32
35
  const entity = useEntity.useEntity();
33
36
  const schema = env.getSchema();
@@ -35,7 +38,7 @@ const IfFilter = Component.Component(
35
38
  () => new FilterEvaluator.FilterEvaluator(schema).evaluateFilter(entity, binding.QueryLanguage.desugarFilter(condition, env)),
36
39
  [condition, entity, env, schema]
37
40
  );
38
- return evaluated ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children }) : null;
41
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: evaluated ? children ?? then : elseIn });
39
42
  },
40
43
  ({ children, condition }, env) => {
41
44
  const desugaredFilter = binding.QueryLanguage.desugarFilter(condition, env);
@@ -1 +1 @@
1
- {"version":3,"file":"If.cjs","sources":["../../../src/helperComponents/If.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { useMemo } from 'react'\nimport { Component, Field } from '../coreComponents'\nimport { EntityAccessor } from '@contember/binding'\nimport { QueryLanguage } from '@contember/binding'\nimport { useEntity, useEnvironment } from '../accessorPropagation'\nimport { Filter } from '@contember/binding'\nimport { FilterFieldsCollector } from './helpers/FilterFieldsCollector'\nimport { FilterEvaluator } from './helpers/FilterEvaluator'\n\nexport type IfProps =\n\t| IfFilterProps\n\t| IfCallbackProps\n\nexport interface IfFilterProps {\n\tcondition: string | Filter\n\tchildren?: ReactNode\n}\n\nexport interface IfCallbackProps {\n\tcondition: (accessor: EntityAccessor) => boolean\n\tchildren?: ReactNode\n}\n\n/**\n * @group Logic Components\n */\nexport const If = Component<IfProps>(props => {\n\t\treturn typeof props.condition !== 'function'\n\t\t\t? <IfFilter condition={props.condition}>{props.children}</IfFilter>\n\t\t\t: <IfCallback condition={props.condition}>{props.children}</IfCallback>\n\t},\n\t'If',\n)\n\nconst IfCallback = Component<IfCallbackProps>(\n\t({ children, condition }) => {\n\t\tconst entity = useEntity()\n\t\tconst evaluated = useMemo(() => condition(entity), [condition, entity])\n\n\t\treturn evaluated ? <>{children}</> : null\n\t},\n\t({ children }) => {\n\t\treturn <>{children}</>\n\t},\n\t'IfCallback',\n)\n\nconst IfFilter = Component<IfFilterProps>(\n\t({ children, condition }) => {\n\t\tconst env = useEnvironment()\n\t\tconst entity = useEntity()\n\n\t\tconst schema = env.getSchema()\n\t\tconst evaluated = useMemo(\n\t\t\t() => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),\n\t\t\t[condition, entity, env, schema],\n\t\t)\n\n\t\treturn evaluated ? <>{children}</> : null\n\t},\n\t({ children, condition }, env) => {\n\t\tconst desugaredFilter = QueryLanguage.desugarFilter(condition, env)\n\t\tconst collectedFields = new FilterFieldsCollector(env.getSchema(), desugaredFilter).collectFields(env.getSubTreeNode().entity)\n\t\tconst additionalFields = <>{Array.from(collectedFields).map(it => <Field field={it} key={it} />)}</>\n\n\t\treturn <>\n\t\t\t{additionalFields}\n\t\t\t{children}\n\t\t</>\n\t},\n\t'IfFilter',\n)\n\n"],"names":["Component","jsx","useEntity","useMemo","Fragment","useEnvironment","FilterEvaluator","QueryLanguage","FilterFieldsCollector","Field","jsxs"],"mappings":";;;;;;;;;;;AA2BO,MAAM,KAAKA,UAAA;AAAA,EAAmB,CAAS,UAAA;AAC5C,WAAO,OAAO,MAAM,cAAc,aAC9BC,2BAAA,IAAA,UAAA,EAAS,WAAW,MAAM,WAAY,UAAM,MAAA,SAAA,CAAS,IACrDA,2BAAAA,IAAA,YAAA,EAAW,WAAW,MAAM,WAAY,gBAAM,SAAS,CAAA;AAAA,EAC5D;AAAA,EACA;AACD;AAEA,MAAM,aAAaD,UAAA;AAAA,EAClB,CAAC,EAAE,UAAU,gBAAgB;AAC5B,UAAM,SAASE,UAAAA;AACT,UAAA,YAAYC,cAAQ,MAAM,UAAU,MAAM,GAAG,CAAC,WAAW,MAAM,CAAC;AAE/D,WAAA,YAAeF,2BAAAA,IAAAG,WAAAA,UAAA,EAAA,SAAA,CAAS,IAAM;AAAA,EACtC;AAAA,EACA,CAAC,EAAE,SAAA,MAAe;AACjB,iEAAU,SAAS,CAAA;AAAA,EACpB;AAAA,EACA;AACD;AAEA,MAAM,WAAWJ,UAAA;AAAA,EAChB,CAAC,EAAE,UAAU,gBAAgB;AAC5B,UAAM,MAAMK,eAAAA;AACZ,UAAM,SAASH,UAAAA;AAET,UAAA,SAAS,IAAI;AACnB,UAAM,YAAYC,MAAA;AAAA,MACjB,MAAM,IAAIG,gBAAAA,gBAAgB,MAAM,EAAE,eAAe,QAAQC,QAAAA,cAAc,cAAc,WAAW,GAAG,CAAC;AAAA,MACpG,CAAC,WAAW,QAAQ,KAAK,MAAM;AAAA,IAAA;AAGzB,WAAA,YAAeN,2BAAAA,IAAAG,WAAAA,UAAA,EAAA,SAAA,CAAS,IAAM;AAAA,EACtC;AAAA,EACA,CAAC,EAAE,UAAU,aAAa,QAAQ;AACjC,UAAM,kBAAkBG,QAAA,cAAc,cAAc,WAAW,GAAG;AAClE,UAAM,kBAAkB,IAAIC,4CAAsB,IAAI,UAAU,GAAG,eAAe,EAAE,cAAc,IAAI,eAAe,EAAE,MAAM;AAC7H,UAAM,mBAAmBP,2BAAA,IAAAG,qBAAA,EAAG,UAAM,MAAA,KAAK,eAAe,EAAE,IAAI,CAAM,OAAAH,2BAAAA,IAACQ,MAAAA,OAAM,EAAA,OAAO,MAAS,EAAI,CAAE,EAAE,CAAA;AAEjG,WACEC,2BAAA,KAAAN,qBAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA;AAAA,IACF,EAAA,CAAA;AAAA,EACD;AAAA,EACA;AACD;;"}
1
+ {"version":3,"file":"If.cjs","sources":["../../../src/helperComponents/If.tsx"],"sourcesContent":["import type { ReactNode } from 'react'\nimport { useMemo } from 'react'\nimport { Component, Field } from '../coreComponents'\nimport { EntityAccessor } from '@contember/binding'\nimport { QueryLanguage } from '@contember/binding'\nimport { useEntity, useEnvironment } from '../accessorPropagation'\nimport { Filter } from '@contember/binding'\nimport { FilterFieldsCollector } from './helpers/FilterFieldsCollector'\nimport { FilterEvaluator } from './helpers/FilterEvaluator'\n\nexport type IfProps =\n\t| IfFilterProps\n\t| IfCallbackProps\n\nexport interface IfFilterProps {\n\tcondition: string | Filter\n\tchildren?: ReactNode\n\tthen?: ReactNode\n\telse?: ReactNode\n}\n\nexport interface IfCallbackProps {\n\tcondition: (accessor: EntityAccessor) => boolean\n\tchildren?: ReactNode\n\tthen?: ReactNode\n\telse?: ReactNode\n}\n\n/**\n * @group Logic Components\n */\nexport const If = Component<IfProps>(({ condition, ...props }) => {\n\t\tif (props.children && props.then) {\n\t\t\tthrow new Error('If component cannot have both children and then prop')\n\t\t}\n\t\treturn typeof condition !== 'function'\n\t\t\t? <IfFilter condition={condition} {...props} />\n\t\t\t: <IfCallback condition={condition} {...props} />\n\t},\n\t'If',\n)\n\nconst IfCallback = Component<IfCallbackProps>(\n\t({ children, condition, then, else: elseIn }) => {\n\t\tconst entity = useEntity()\n\t\tconst evaluated = useMemo(() => condition(entity), [condition, entity])\n\n\t\treturn <>{evaluated ? (children ?? then) : elseIn}</>\n\t},\n\t({ children }) => {\n\t\treturn <>{children}</>\n\t},\n\t'IfCallback',\n)\n\nconst IfFilter = Component<IfFilterProps>(\n\t({ children, condition, then, else: elseIn }) => {\n\t\tconst env = useEnvironment()\n\t\tconst entity = useEntity()\n\n\t\tconst schema = env.getSchema()\n\t\tconst evaluated = useMemo(\n\t\t\t() => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),\n\t\t\t[condition, entity, env, schema],\n\t\t)\n\t\treturn <>{evaluated ? (children ?? then) : elseIn}</>\n\t},\n\t({ children, condition }, env) => {\n\t\tconst desugaredFilter = QueryLanguage.desugarFilter(condition, env)\n\t\tconst collectedFields = new FilterFieldsCollector(env.getSchema(), desugaredFilter).collectFields(env.getSubTreeNode().entity)\n\t\tconst additionalFields = <>{Array.from(collectedFields).map(it => <Field field={it} key={it} />)}</>\n\n\t\treturn <>\n\t\t\t{additionalFields}\n\t\t\t{children}\n\t\t</>\n\t},\n\t'IfFilter',\n)\n"],"names":["Component","jsx","useEntity","useMemo","Fragment","useEnvironment","FilterEvaluator","QueryLanguage","FilterFieldsCollector","Field","jsxs"],"mappings":";;;;;;;;;;;AA+BO,MAAM,KAAKA,UAAA;AAAA,EAAmB,CAAC,EAAE,WAAW,GAAG,YAAY;AAC5D,QAAA,MAAM,YAAY,MAAM,MAAM;AAC3B,YAAA,IAAI,MAAM,sDAAsD;AAAA,IACvE;AACA,WAAO,OAAO,cAAc,aACzBC,2BAAA,IAAC,UAAS,EAAA,WAAuB,GAAG,MAAA,CAAO,IAC3CA,2BAAA,IAAC,YAAW,EAAA,WAAuB,GAAG,MAAO,CAAA;AAAA,EACjD;AAAA,EACA;AACD;AAEA,MAAM,aAAaD,UAAA;AAAA,EAClB,CAAC,EAAE,UAAU,WAAW,MAAM,MAAM,aAAa;AAChD,UAAM,SAASE,UAAAA;AACT,UAAA,YAAYC,cAAQ,MAAM,UAAU,MAAM,GAAG,CAAC,WAAW,MAAM,CAAC;AAEtE,WAAUF,2BAAA,IAAAG,WAAA,UAAA,EAAA,UAAA,YAAa,YAAY,OAAQ,OAAO,CAAA;AAAA,EACnD;AAAA,EACA,CAAC,EAAE,SAAA,MAAe;AACjB,iEAAU,SAAS,CAAA;AAAA,EACpB;AAAA,EACA;AACD;AAEA,MAAM,WAAWJ,UAAA;AAAA,EAChB,CAAC,EAAE,UAAU,WAAW,MAAM,MAAM,aAAa;AAChD,UAAM,MAAMK,eAAAA;AACZ,UAAM,SAASH,UAAAA;AAET,UAAA,SAAS,IAAI;AACnB,UAAM,YAAYC,MAAA;AAAA,MACjB,MAAM,IAAIG,gBAAAA,gBAAgB,MAAM,EAAE,eAAe,QAAQC,QAAAA,cAAc,cAAc,WAAW,GAAG,CAAC;AAAA,MACpG,CAAC,WAAW,QAAQ,KAAK,MAAM;AAAA,IAAA;AAEhC,WAAUN,2BAAA,IAAAG,WAAA,UAAA,EAAA,UAAA,YAAa,YAAY,OAAQ,OAAO,CAAA;AAAA,EACnD;AAAA,EACA,CAAC,EAAE,UAAU,aAAa,QAAQ;AACjC,UAAM,kBAAkBG,QAAA,cAAc,cAAc,WAAW,GAAG;AAClE,UAAM,kBAAkB,IAAIC,4CAAsB,IAAI,UAAU,GAAG,eAAe,EAAE,cAAc,IAAI,eAAe,EAAE,MAAM;AAC7H,UAAM,mBAAmBP,2BAAA,IAAAG,qBAAA,EAAG,UAAM,MAAA,KAAK,eAAe,EAAE,IAAI,CAAM,OAAAH,2BAAAA,IAACQ,MAAAA,OAAM,EAAA,OAAO,MAAS,EAAI,CAAE,EAAE,CAAA;AAEjG,WACEC,2BAAA,KAAAN,qBAAA,EAAA,UAAA;AAAA,MAAA;AAAA,MACA;AAAA,IACF,EAAA,CAAA;AAAA,EACD;AAAA,EACA;AACD;;"}
@@ -8,16 +8,19 @@ import { Component } from "../coreComponents/Component.js";
8
8
  import { useEntity } from "../accessorPropagation/useEntity.js";
9
9
  import { useEnvironment } from "../accessorPropagation/useEnvironment.js";
10
10
  const If = Component(
11
- (props) => {
12
- return typeof props.condition !== "function" ? /* @__PURE__ */ jsx(IfFilter, { condition: props.condition, children: props.children }) : /* @__PURE__ */ jsx(IfCallback, { condition: props.condition, children: props.children });
11
+ ({ condition, ...props }) => {
12
+ if (props.children && props.then) {
13
+ throw new Error("If component cannot have both children and then prop");
14
+ }
15
+ return typeof condition !== "function" ? /* @__PURE__ */ jsx(IfFilter, { condition, ...props }) : /* @__PURE__ */ jsx(IfCallback, { condition, ...props });
13
16
  },
14
17
  "If"
15
18
  );
16
19
  const IfCallback = Component(
17
- ({ children, condition }) => {
20
+ ({ children, condition, then, else: elseIn }) => {
18
21
  const entity = useEntity();
19
22
  const evaluated = useMemo(() => condition(entity), [condition, entity]);
20
- return evaluated ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
23
+ return /* @__PURE__ */ jsx(Fragment, { children: evaluated ? children ?? then : elseIn });
21
24
  },
22
25
  ({ children }) => {
23
26
  return /* @__PURE__ */ jsx(Fragment, { children });
@@ -25,7 +28,7 @@ const IfCallback = Component(
25
28
  "IfCallback"
26
29
  );
27
30
  const IfFilter = Component(
28
- ({ children, condition }) => {
31
+ ({ children, condition, then, else: elseIn }) => {
29
32
  const env = useEnvironment();
30
33
  const entity = useEntity();
31
34
  const schema = env.getSchema();
@@ -33,7 +36,7 @@ const IfFilter = Component(
33
36
  () => new FilterEvaluator(schema).evaluateFilter(entity, QueryLanguage.desugarFilter(condition, env)),
34
37
  [condition, entity, env, schema]
35
38
  );
36
- return evaluated ? /* @__PURE__ */ jsx(Fragment, { children }) : null;
39
+ return /* @__PURE__ */ jsx(Fragment, { children: evaluated ? children ?? then : elseIn });
37
40
  },
38
41
  ({ children, condition }, env) => {
39
42
  const desugaredFilter = QueryLanguage.desugarFilter(condition, env);