@contember/react-binding 2.0.0-alpha.23 → 2.0.0-alpha.25

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 (76) hide show
  1. package/dist/development/index.cjs +5 -0
  2. package/dist/development/index.cjs.map +1 -1
  3. package/dist/development/index.js +5 -0
  4. package/dist/development/index.js.map +1 -1
  5. package/dist/development/src/accessorPropagation/EntityKeyContext.cjs.map +1 -1
  6. package/dist/development/src/accessorPropagation/EntityKeyContext.js.map +1 -1
  7. package/dist/development/src/accessorPropagation/EnvironmentContext.cjs +12 -8
  8. package/dist/development/src/accessorPropagation/EnvironmentContext.cjs.map +1 -1
  9. package/dist/development/src/accessorPropagation/EnvironmentContext.js +12 -8
  10. package/dist/development/src/accessorPropagation/EnvironmentContext.js.map +1 -1
  11. package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.cjs +27 -12
  12. package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.cjs.map +1 -1
  13. package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.js +27 -12
  14. package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.js.map +1 -1
  15. package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.cjs +33 -15
  16. package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.cjs.map +1 -1
  17. package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.js +33 -15
  18. package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.js.map +1 -1
  19. package/dist/development/src/helperComponents/RecursionTerminator.cjs +55 -0
  20. package/dist/development/src/helperComponents/RecursionTerminator.cjs.map +1 -0
  21. package/dist/development/src/helperComponents/RecursionTerminator.js +55 -0
  22. package/dist/development/src/helperComponents/RecursionTerminator.js.map +1 -0
  23. package/dist/development/src/helperComponents/RecursionTerminatorPortal.cjs +39 -0
  24. package/dist/development/src/helperComponents/RecursionTerminatorPortal.cjs.map +1 -0
  25. package/dist/development/src/helperComponents/RecursionTerminatorPortal.js +39 -0
  26. package/dist/development/src/helperComponents/RecursionTerminatorPortal.js.map +1 -0
  27. package/dist/production/index.cjs +5 -0
  28. package/dist/production/index.cjs.map +1 -1
  29. package/dist/production/index.js +5 -0
  30. package/dist/production/index.js.map +1 -1
  31. package/dist/production/src/accessorPropagation/EntityKeyContext.cjs.map +1 -1
  32. package/dist/production/src/accessorPropagation/EntityKeyContext.js.map +1 -1
  33. package/dist/production/src/accessorPropagation/EnvironmentContext.cjs +8 -4
  34. package/dist/production/src/accessorPropagation/EnvironmentContext.cjs.map +1 -1
  35. package/dist/production/src/accessorPropagation/EnvironmentContext.js +8 -4
  36. package/dist/production/src/accessorPropagation/EnvironmentContext.js.map +1 -1
  37. package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.cjs +27 -12
  38. package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.cjs.map +1 -1
  39. package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.js +27 -12
  40. package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.js.map +1 -1
  41. package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.cjs +33 -15
  42. package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.cjs.map +1 -1
  43. package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.js +33 -15
  44. package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.js.map +1 -1
  45. package/dist/production/src/helperComponents/RecursionTerminator.cjs +55 -0
  46. package/dist/production/src/helperComponents/RecursionTerminator.cjs.map +1 -0
  47. package/dist/production/src/helperComponents/RecursionTerminator.js +55 -0
  48. package/dist/production/src/helperComponents/RecursionTerminator.js.map +1 -0
  49. package/dist/production/src/helperComponents/RecursionTerminatorPortal.cjs +35 -0
  50. package/dist/production/src/helperComponents/RecursionTerminatorPortal.cjs.map +1 -0
  51. package/dist/production/src/helperComponents/RecursionTerminatorPortal.js +35 -0
  52. package/dist/production/src/helperComponents/RecursionTerminatorPortal.js.map +1 -0
  53. package/dist/types/accessorPropagation/EntityKeyContext.d.ts +1 -1
  54. package/dist/types/accessorPropagation/EntityKeyContext.d.ts.map +1 -1
  55. package/dist/types/accessorPropagation/EnvironmentContext.d.ts +4 -3
  56. package/dist/types/accessorPropagation/EnvironmentContext.d.ts.map +1 -1
  57. package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts +9 -1
  58. package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts.map +1 -1
  59. package/dist/types/accessorPropagation/useEntitySubTreeLoader.d.ts +9 -1
  60. package/dist/types/accessorPropagation/useEntitySubTreeLoader.d.ts.map +1 -1
  61. package/dist/types/helperComponents/RecursionTerminator.d.ts +22 -0
  62. package/dist/types/helperComponents/RecursionTerminator.d.ts.map +1 -0
  63. package/dist/types/helperComponents/RecursionTerminatorPortal.d.ts +3 -0
  64. package/dist/types/helperComponents/RecursionTerminatorPortal.d.ts.map +1 -0
  65. package/dist/types/helperComponents/index.d.ts +2 -0
  66. package/dist/types/helperComponents/index.d.ts.map +1 -1
  67. package/dist/types/tsconfig.tsbuildinfo +1 -1
  68. package/package.json +7 -8
  69. package/src/accessorPropagation/EntityKeyContext.ts +1 -1
  70. package/src/accessorPropagation/EnvironmentContext.tsx +14 -9
  71. package/src/accessorPropagation/useEntityListSubTreeLoader.ts +41 -12
  72. package/src/accessorPropagation/useEntitySubTreeLoader.ts +49 -16
  73. package/src/helperComponents/RecursionTerminator.tsx +73 -0
  74. package/src/helperComponents/RecursionTerminatorPortal.tsx +35 -0
  75. package/src/helperComponents/index.ts +2 -0
  76. package/src/tsconfig.json +0 -1
@@ -1,6 +1,8 @@
1
1
  import { useState, useRef, useEffect, createElement, useCallback } from "react";
2
2
  import { useExtendTree } from "./useExtendTree.js";
3
+ import { useObjectMemo } from "@contember/react-utils";
3
4
  import { EntityListSubTree } from "../coreComponents/EntityListSubTree.js";
5
+ const emptyObject = {};
4
6
  const useEntityListSubTreeLoader = (entities, children, state) => {
5
7
  const [displayedState, setDisplayedState] = useState({
6
8
  state: "initial",
@@ -12,17 +14,19 @@ const useEntityListSubTreeLoader = (entities, children, state) => {
12
14
  const currentlyLoading = useRef();
13
15
  const extendTree = useExtendTree();
14
16
  const [reloadTrigger, setReloadTrigger] = useState(null);
17
+ const memoizedEntities = useObjectMemo(entities ?? emptyObject);
18
+ const resolvedEntities = entities ? memoizedEntities : void 0;
15
19
  useEffect(() => {
16
20
  (async () => {
17
- if (!entities) {
21
+ if (!resolvedEntities) {
18
22
  return;
19
23
  }
20
24
  currentlyLoading.current = {
21
- entities,
25
+ entities: resolvedEntities,
22
26
  state
23
27
  };
24
28
  setDisplayedState((it) => {
25
- if (it.state === "initial" || it.state === "loading") {
29
+ if (it.state === "initial" || it.state === "loading" || it.state === "failed") {
26
30
  return {
27
31
  ...it,
28
32
  isLoading: true,
@@ -38,26 +42,37 @@ const useEntityListSubTreeLoader = (entities, children, state) => {
38
42
  });
39
43
  const newTreeRootId = await extendTree(
40
44
  createElement(EntityListSubTree, {
41
- ...entities,
45
+ ...resolvedEntities,
42
46
  children
43
47
  }),
44
- { force: reloadTrigger !== null }
48
+ {
49
+ force: reloadTrigger !== null,
50
+ onError: (e) => {
51
+ console.error(e);
52
+ currentlyLoading.current = void 0;
53
+ setDisplayedState({
54
+ state: "failed",
55
+ error: e,
56
+ entities: void 0,
57
+ treeRootId: void 0,
58
+ customState: void 0,
59
+ isLoading: false
60
+ });
61
+ }
62
+ }
45
63
  );
46
- if (currentlyLoading.current?.entities !== entities || currentlyLoading.current?.state !== state) {
47
- return;
48
- }
49
- currentlyLoading.current = void 0;
50
64
  if (newTreeRootId) {
65
+ currentlyLoading.current = void 0;
51
66
  setDisplayedState({
52
- entities,
53
- treeRootId: newTreeRootId,
54
67
  state: "loaded",
68
+ entities: resolvedEntities,
69
+ treeRootId: newTreeRootId,
55
70
  customState: state,
56
71
  isLoading: false
57
72
  });
58
73
  }
59
74
  })();
60
- }, [extendTree, entities, children, state, reloadTrigger]);
75
+ }, [extendTree, resolvedEntities, children, state, reloadTrigger]);
61
76
  return [
62
77
  displayedState,
63
78
  {
@@ -1 +1 @@
1
- {"version":3,"file":"useEntityListSubTreeLoader.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityListSubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedEntityList, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntityListSubTree } from '../coreComponents'\nimport { useEnvironment } from './useEnvironment'\n\nexport type UseEntityListSubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentities: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntityListSubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentities: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntityListSubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentities: SugaredQualifiedEntityList\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntityListSubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentities: SugaredQualifiedEntityList\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\n\nexport type UseEntityListSubTreeLoaderState<State> =\n\t| UseEntityListSubTreeLoaderStateInitial\n\t| UseEntityListSubTreeLoaderStateLoading\n\t| UseEntityListSubTreeLoaderStateRefreshing<State>\n\t| UseEntityListSubTreeLoaderStateLoaded<State>\n\nexport type UseEntityListSubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nexport const useEntityListSubTreeLoader = <State>(entities: SugaredQualifiedEntityList | undefined, children: ReactNode, state?: State): [UseEntityListSubTreeLoaderState<State>, UseEntityListSubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntityListSubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentities: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentities: SugaredQualifiedEntityList\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!entities) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentities,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntityListSubTree, {\n\t\t\t\t\t...entities,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{ force: reloadTrigger !== null },\n\t\t\t)\n\t\t\tif (currentlyLoading.current?.entities !== entities || currentlyLoading.current?.state !== state) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentities: entities,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, entities, children, state, reloadTrigger])\n\n\treturn [\n\t\tdisplayedState,\n\t\t{\n\t\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t\t},\n\t]\n}\n"],"names":[],"mappings":";;;AAkDO,MAAM,6BAA6B,CAAQ,UAAkD,UAAqB,UAAoG;AAC5N,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAiD;AAAA,IAC5F,OAAO;AAAA,IACP,WAAW;AAAA,IACX,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmB;AAKzB,QAAM,aAAa;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAwB,IAAI;AAEtE,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,UAAU;AACd;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACvB,YAAI,GAAG,UAAU,aAAa,GAAG,UAAU,WAAW;AAC9C,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3B,cAAc,mBAAmB;AAAA,UAChC,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD,EAAE,OAAO,kBAAkB,KAAK;AAAA,MAAA;AAEjC,UAAI,iBAAiB,SAAS,aAAa,YAAY,iBAAiB,SAAS,UAAU,OAAO;AACjG;AAAA,MACD;AACA,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,UAAU,UAAU,OAAO,aAAa,CAAC;AAElD,SAAA;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQ,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,IACnD;AAAA,EAAA;AAEF;"}
1
+ {"version":3,"file":"useEntityListSubTreeLoader.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntityListSubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedEntityList, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntityListSubTree } from '../coreComponents'\nimport { useEnvironment } from './useEnvironment'\nimport { useObjectMemo } from '@contember/react-utils'\n\nexport type UseEntityListSubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentities: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntityListSubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentities: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntityListSubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentities: SugaredQualifiedEntityList\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntityListSubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentities: SugaredQualifiedEntityList\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\nexport type UseEntityListSubTreeLoaderStateFailed = {\n\tstate: 'failed'\n\terror: unknown\n\tentities: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\n\nexport type UseEntityListSubTreeLoaderState<State> =\n\t| UseEntityListSubTreeLoaderStateInitial\n\t| UseEntityListSubTreeLoaderStateLoading\n\t| UseEntityListSubTreeLoaderStateRefreshing<State>\n\t| UseEntityListSubTreeLoaderStateLoaded<State>\n\t| UseEntityListSubTreeLoaderStateFailed\n\nexport type UseEntityListSubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nconst emptyObject = {} as SugaredQualifiedEntityList\n\nexport const useEntityListSubTreeLoader = <State>(entities: SugaredQualifiedEntityList | undefined, children: ReactNode, state?: State): [UseEntityListSubTreeLoaderState<State>, UseEntityListSubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntityListSubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentities: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentities: SugaredQualifiedEntityList\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\tconst memoizedEntities = useObjectMemo(entities ?? emptyObject)\n\tconst resolvedEntities = entities ? memoizedEntities : undefined\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!resolvedEntities) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentities: resolvedEntities,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading' || it.state === 'failed') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntityListSubTree, {\n\t\t\t\t\t...resolvedEntities,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\tforce: reloadTrigger !== null,\n\t\t\t\t\tonError: e => {\n\t\t\t\t\t\tconsole.error(e)\n\n\t\t\t\t\t\tcurrentlyLoading.current = undefined\n\n\t\t\t\t\t\tsetDisplayedState({\n\t\t\t\t\t\t\tstate: 'failed',\n\t\t\t\t\t\t\terror: e,\n\t\t\t\t\t\t\tentities: undefined,\n\t\t\t\t\t\t\ttreeRootId: undefined,\n\t\t\t\t\t\t\tcustomState: undefined,\n\t\t\t\t\t\t\tisLoading: false,\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t)\n\n\t\t\tif (newTreeRootId) {\n\t\t\t\tcurrentlyLoading.current = undefined\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tentities: resolvedEntities,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, resolvedEntities, children, state, reloadTrigger])\n\n\treturn [\n\t\tdisplayedState,\n\t\t{\n\t\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t\t},\n\t]\n}\n"],"names":[],"mappings":";;;;AA6DA,MAAM,cAAc,CAAA;AAEb,MAAM,6BAA6B,CAAQ,UAAkD,UAAqB,UAAoG;AAC5N,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAAiD;AAAA,IAC5F,OAAO;AAAA,IACP,WAAW;AAAA,IACX,UAAU;AAAA,IACV,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmB;AAKzB,QAAM,aAAa;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAwB,IAAI;AAChE,QAAA,mBAAmB,cAAc,YAAY,WAAW;AACxD,QAAA,mBAAmB,WAAW,mBAAmB;AAEvD,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,kBAAkB;AACtB;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B,UAAU;AAAA,QACV;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACnB,YAAA,GAAG,UAAU,aAAa,GAAG,UAAU,aAAa,GAAG,UAAU,UAAU;AACvE,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3B,cAAc,mBAAmB;AAAA,UAChC,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD;AAAA,UACC,OAAO,kBAAkB;AAAA,UACzB,SAAS,CAAK,MAAA;AACb,oBAAQ,MAAM,CAAC;AAEf,6BAAiB,UAAU;AAET,8BAAA;AAAA,cACjB,OAAO;AAAA,cACP,OAAO;AAAA,cACP,UAAU;AAAA,cACV,YAAY;AAAA,cACZ,aAAa;AAAA,cACb,WAAW;AAAA,YAAA,CACX;AAAA,UACF;AAAA,QACD;AAAA,MAAA;AAGD,UAAI,eAAe;AAClB,yBAAiB,UAAU;AACT,0BAAA;AAAA,UACjB,OAAO;AAAA,UACP,UAAU;AAAA,UACV,YAAY;AAAA,UACZ,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,kBAAkB,UAAU,OAAO,aAAa,CAAC;AAE1D,SAAA;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQ,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,IACnD;AAAA,EAAA;AAEF;"}
@@ -2,7 +2,9 @@
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const React = require("react");
4
4
  const useExtendTree = require("./useExtendTree.cjs");
5
+ const reactUtils = require("@contember/react-utils");
5
6
  const EntitySubTree = require("../coreComponents/EntitySubTree.cjs");
7
+ const emptyObject = {};
6
8
  const useEntitySubTreeLoader = (entity, children, state) => {
7
9
  const [displayedState, setDisplayedState] = React.useState({
8
10
  state: "initial",
@@ -14,17 +16,19 @@ const useEntitySubTreeLoader = (entity, children, state) => {
14
16
  const currentlyLoading = React.useRef();
15
17
  const extendTree = useExtendTree.useExtendTree();
16
18
  const [reloadTrigger, setReloadTrigger] = React.useState(null);
19
+ const memoizedEntity = reactUtils.useObjectMemo(entity ?? emptyObject);
20
+ const resolvedEntity = entity ? memoizedEntity : void 0;
17
21
  React.useEffect(() => {
18
22
  (async () => {
19
- if (!entity) {
23
+ if (!resolvedEntity) {
20
24
  return;
21
25
  }
22
26
  currentlyLoading.current = {
23
- entity,
27
+ entity: resolvedEntity,
24
28
  state
25
29
  };
26
30
  setDisplayedState((it) => {
27
- if (it.state === "initial" || it.state === "loading") {
31
+ if (it.state === "initial" || it.state === "loading" || it.state === "failed") {
28
32
  return {
29
33
  ...it,
30
34
  isLoading: true,
@@ -40,29 +44,43 @@ const useEntitySubTreeLoader = (entity, children, state) => {
40
44
  });
41
45
  const newTreeRootId = await extendTree(
42
46
  React.createElement(EntitySubTree.EntitySubTree, {
43
- ...entity,
47
+ ...resolvedEntity,
44
48
  children
45
49
  }),
46
- { force: reloadTrigger !== null }
50
+ {
51
+ force: reloadTrigger !== null,
52
+ onError: (e) => {
53
+ console.error(e);
54
+ currentlyLoading.current = void 0;
55
+ setDisplayedState({
56
+ state: "failed",
57
+ error: e,
58
+ entity: void 0,
59
+ treeRootId: void 0,
60
+ customState: void 0,
61
+ isLoading: false
62
+ });
63
+ }
64
+ }
47
65
  );
48
- if (currentlyLoading.current?.entity !== entity || currentlyLoading.current?.state !== state) {
49
- return;
50
- }
51
- currentlyLoading.current = void 0;
52
66
  if (newTreeRootId) {
67
+ currentlyLoading.current = void 0;
53
68
  setDisplayedState({
54
- entity,
55
- treeRootId: newTreeRootId,
56
69
  state: "loaded",
70
+ entity: resolvedEntity,
71
+ treeRootId: newTreeRootId,
57
72
  customState: state,
58
73
  isLoading: false
59
74
  });
60
75
  }
61
76
  })();
62
- }, [extendTree, entity, children, state, reloadTrigger]);
63
- return [displayedState, {
64
- reload: React.useCallback(() => setReloadTrigger({}), [])
65
- }];
77
+ }, [extendTree, resolvedEntity, children, state, reloadTrigger]);
78
+ return [
79
+ displayedState,
80
+ {
81
+ reload: React.useCallback(() => setReloadTrigger({}), [])
82
+ }
83
+ ];
66
84
  };
67
85
  exports.useEntitySubTreeLoader = useEntitySubTreeLoader;
68
86
  //# sourceMappingURL=useEntitySubTreeLoader.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"useEntitySubTreeLoader.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntitySubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedSingleEntity, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntitySubTree } from '../coreComponents'\n\nexport type UseEntitySubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntitySubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntitySubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntitySubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\n\nexport type UseEntitySubTreeLoaderState<State> =\n\t| UseEntitySubTreeLoaderStateInitial\n\t| UseEntitySubTreeLoaderStateLoading\n\t| UseEntitySubTreeLoaderStateRefreshing<State>\n\t| UseEntitySubTreeLoaderStateLoaded<State>\n\nexport type EntityListSubTreeLoaderState = UseEntitySubTreeLoaderState<any>['state']\n\nexport type UseEntitySubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nexport const useEntitySubTreeLoader = <State>(entity: SugaredQualifiedSingleEntity | undefined, children: ReactNode, state?: State): [UseEntitySubTreeLoaderState<State>, UseEntitySubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntitySubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentity: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentity: SugaredQualifiedSingleEntity\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!entity) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentity,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntitySubTree, {\n\t\t\t\t\t...entity,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{ force: reloadTrigger !== null },\n\t\t\t)\n\t\t\tif (currentlyLoading.current?.entity !== entity || currentlyLoading.current?.state !== state) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentity: entity,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, entity, children, state, reloadTrigger])\n\n\treturn [displayedState, {\n\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t}]\n}\n"],"names":["useState","useRef","useExtendTree","useEffect","createElement","EntitySubTree","useCallback"],"mappings":";;;;;AAmDO,MAAM,yBAAyB,CAAQ,QAAkD,UAAqB,UAA4F;AAChN,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,eAA6C;AAAA,IACxF,OAAO;AAAA,IACP,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmBC,MAAAA;AAKzB,QAAM,aAAaC,cAAAA;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAIF,eAAwB,IAAI;AAEtEG,QAAAA,UAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,QAAQ;AACZ;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACvB,YAAI,GAAG,UAAU,aAAa,GAAG,UAAU,WAAW;AAC9C,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3BC,MAAAA,cAAcC,cAAAA,eAAe;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD,EAAE,OAAO,kBAAkB,KAAK;AAAA,MAAA;AAEjC,UAAI,iBAAiB,SAAS,WAAW,UAAU,iBAAiB,SAAS,UAAU,OAAO;AAC7F;AAAA,MACD;AACA,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,QAAQ,UAAU,OAAO,aAAa,CAAC;AAEvD,SAAO,CAAC,gBAAgB;AAAA,IACvB,QAAQC,MAAAA,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,EAAA,CAClD;AACF;;"}
1
+ {"version":3,"file":"useEntitySubTreeLoader.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntitySubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedSingleEntity, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntitySubTree } from '../coreComponents'\nimport { useObjectMemo } from '@contember/react-utils'\n\nexport type UseEntitySubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntitySubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntitySubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntitySubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\nexport type UseEntitySubTreeLoaderStateFailed = {\n\tstate: 'failed'\n\terror: unknown\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\n\nexport type UseEntitySubTreeLoaderState<State> =\n\t| UseEntitySubTreeLoaderStateInitial\n\t| UseEntitySubTreeLoaderStateLoading\n\t| UseEntitySubTreeLoaderStateRefreshing<State>\n\t| UseEntitySubTreeLoaderStateLoaded<State>\n\t| UseEntitySubTreeLoaderStateFailed\n\nexport type EntityListSubTreeLoaderState = UseEntitySubTreeLoaderState<any>['state']\n\nexport type UseEntitySubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nconst emptyObject = {} as SugaredQualifiedSingleEntity\n\nexport const useEntitySubTreeLoader = <State>(entity: SugaredQualifiedSingleEntity | undefined, children: ReactNode, state?: State): [UseEntitySubTreeLoaderState<State>, UseEntitySubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntitySubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentity: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentity: SugaredQualifiedSingleEntity\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\tconst memoizedEntity = useObjectMemo(entity ?? emptyObject)\n\tconst resolvedEntity = entity ? memoizedEntity : undefined\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!resolvedEntity) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentity: resolvedEntity,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading' || it.state === 'failed') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntitySubTree, {\n\t\t\t\t\t...resolvedEntity,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\tforce: reloadTrigger !== null,\n\t\t\t\t\tonError: e => {\n\t\t\t\t\t\tconsole.error(e)\n\n\t\t\t\t\t\tcurrentlyLoading.current = undefined\n\n\t\t\t\t\t\tsetDisplayedState({\n\t\t\t\t\t\t\tstate: 'failed',\n\t\t\t\t\t\t\terror: e,\n\t\t\t\t\t\t\tentity: undefined,\n\t\t\t\t\t\t\ttreeRootId: undefined,\n\t\t\t\t\t\t\tcustomState: undefined,\n\t\t\t\t\t\t\tisLoading: false,\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t)\n\n\n\t\t\tif (newTreeRootId) {\n\t\t\t\tcurrentlyLoading.current = undefined\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tentity: resolvedEntity,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, resolvedEntity, children, state, reloadTrigger])\n\n\treturn [\n\t\tdisplayedState,\n\t\t{\n\t\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t\t},\n\t]\n}\n"],"names":["useState","useRef","useExtendTree","useObjectMemo","useEffect","createElement","EntitySubTree","useCallback"],"mappings":";;;;;;AA8DA,MAAM,cAAc,CAAA;AAEb,MAAM,yBAAyB,CAAQ,QAAkD,UAAqB,UAA4F;AAChN,QAAM,CAAC,gBAAgB,iBAAiB,IAAIA,eAA6C;AAAA,IACxF,OAAO;AAAA,IACP,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmBC,MAAAA;AAKzB,QAAM,aAAaC,cAAAA;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAIF,eAAwB,IAAI;AAChE,QAAA,iBAAiBG,WAAAA,cAAc,UAAU,WAAW;AACpD,QAAA,iBAAiB,SAAS,iBAAiB;AAEjDC,QAAAA,UAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,gBAAgB;AACpB;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B,QAAQ;AAAA,QACR;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACnB,YAAA,GAAG,UAAU,aAAa,GAAG,UAAU,aAAa,GAAG,UAAU,UAAU;AACvE,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3BC,MAAAA,cAAcC,cAAAA,eAAe;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD;AAAA,UACC,OAAO,kBAAkB;AAAA,UACzB,SAAS,CAAK,MAAA;AACb,oBAAQ,MAAM,CAAC;AAEf,6BAAiB,UAAU;AAET,8BAAA;AAAA,cACjB,OAAO;AAAA,cACP,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,YAAY;AAAA,cACZ,aAAa;AAAA,cACb,WAAW;AAAA,YAAA,CACX;AAAA,UACF;AAAA,QACD;AAAA,MAAA;AAID,UAAI,eAAe;AAClB,yBAAiB,UAAU;AACT,0BAAA;AAAA,UACjB,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,YAAY;AAAA,UACZ,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,gBAAgB,UAAU,OAAO,aAAa,CAAC;AAExD,SAAA;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQC,MAAAA,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,IACnD;AAAA,EAAA;AAEF;;"}
@@ -1,6 +1,8 @@
1
1
  import { useState, useRef, useEffect, createElement, useCallback } from "react";
2
2
  import { useExtendTree } from "./useExtendTree.js";
3
+ import { useObjectMemo } from "@contember/react-utils";
3
4
  import { EntitySubTree } from "../coreComponents/EntitySubTree.js";
5
+ const emptyObject = {};
4
6
  const useEntitySubTreeLoader = (entity, children, state) => {
5
7
  const [displayedState, setDisplayedState] = useState({
6
8
  state: "initial",
@@ -12,17 +14,19 @@ const useEntitySubTreeLoader = (entity, children, state) => {
12
14
  const currentlyLoading = useRef();
13
15
  const extendTree = useExtendTree();
14
16
  const [reloadTrigger, setReloadTrigger] = useState(null);
17
+ const memoizedEntity = useObjectMemo(entity ?? emptyObject);
18
+ const resolvedEntity = entity ? memoizedEntity : void 0;
15
19
  useEffect(() => {
16
20
  (async () => {
17
- if (!entity) {
21
+ if (!resolvedEntity) {
18
22
  return;
19
23
  }
20
24
  currentlyLoading.current = {
21
- entity,
25
+ entity: resolvedEntity,
22
26
  state
23
27
  };
24
28
  setDisplayedState((it) => {
25
- if (it.state === "initial" || it.state === "loading") {
29
+ if (it.state === "initial" || it.state === "loading" || it.state === "failed") {
26
30
  return {
27
31
  ...it,
28
32
  isLoading: true,
@@ -38,29 +42,43 @@ const useEntitySubTreeLoader = (entity, children, state) => {
38
42
  });
39
43
  const newTreeRootId = await extendTree(
40
44
  createElement(EntitySubTree, {
41
- ...entity,
45
+ ...resolvedEntity,
42
46
  children
43
47
  }),
44
- { force: reloadTrigger !== null }
48
+ {
49
+ force: reloadTrigger !== null,
50
+ onError: (e) => {
51
+ console.error(e);
52
+ currentlyLoading.current = void 0;
53
+ setDisplayedState({
54
+ state: "failed",
55
+ error: e,
56
+ entity: void 0,
57
+ treeRootId: void 0,
58
+ customState: void 0,
59
+ isLoading: false
60
+ });
61
+ }
62
+ }
45
63
  );
46
- if (currentlyLoading.current?.entity !== entity || currentlyLoading.current?.state !== state) {
47
- return;
48
- }
49
- currentlyLoading.current = void 0;
50
64
  if (newTreeRootId) {
65
+ currentlyLoading.current = void 0;
51
66
  setDisplayedState({
52
- entity,
53
- treeRootId: newTreeRootId,
54
67
  state: "loaded",
68
+ entity: resolvedEntity,
69
+ treeRootId: newTreeRootId,
55
70
  customState: state,
56
71
  isLoading: false
57
72
  });
58
73
  }
59
74
  })();
60
- }, [extendTree, entity, children, state, reloadTrigger]);
61
- return [displayedState, {
62
- reload: useCallback(() => setReloadTrigger({}), [])
63
- }];
75
+ }, [extendTree, resolvedEntity, children, state, reloadTrigger]);
76
+ return [
77
+ displayedState,
78
+ {
79
+ reload: useCallback(() => setReloadTrigger({}), [])
80
+ }
81
+ ];
64
82
  };
65
83
  export {
66
84
  useEntitySubTreeLoader
@@ -1 +1 @@
1
- {"version":3,"file":"useEntitySubTreeLoader.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntitySubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedSingleEntity, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntitySubTree } from '../coreComponents'\n\nexport type UseEntitySubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntitySubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntitySubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntitySubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\n\nexport type UseEntitySubTreeLoaderState<State> =\n\t| UseEntitySubTreeLoaderStateInitial\n\t| UseEntitySubTreeLoaderStateLoading\n\t| UseEntitySubTreeLoaderStateRefreshing<State>\n\t| UseEntitySubTreeLoaderStateLoaded<State>\n\nexport type EntityListSubTreeLoaderState = UseEntitySubTreeLoaderState<any>['state']\n\nexport type UseEntitySubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nexport const useEntitySubTreeLoader = <State>(entity: SugaredQualifiedSingleEntity | undefined, children: ReactNode, state?: State): [UseEntitySubTreeLoaderState<State>, UseEntitySubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntitySubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentity: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentity: SugaredQualifiedSingleEntity\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!entity) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentity,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntitySubTree, {\n\t\t\t\t\t...entity,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{ force: reloadTrigger !== null },\n\t\t\t)\n\t\t\tif (currentlyLoading.current?.entity !== entity || currentlyLoading.current?.state !== state) {\n\t\t\t\treturn\n\t\t\t}\n\t\t\tcurrentlyLoading.current = undefined\n\t\t\tif (newTreeRootId) {\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tentity: entity,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, entity, children, state, reloadTrigger])\n\n\treturn [displayedState, {\n\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t}]\n}\n"],"names":[],"mappings":";;;AAmDO,MAAM,yBAAyB,CAAQ,QAAkD,UAAqB,UAA4F;AAChN,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAA6C;AAAA,IACxF,OAAO;AAAA,IACP,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmB;AAKzB,QAAM,aAAa;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAwB,IAAI;AAEtE,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,QAAQ;AACZ;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B;AAAA,QACA;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACvB,YAAI,GAAG,UAAU,aAAa,GAAG,UAAU,WAAW;AAC9C,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3B,cAAc,eAAe;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD,EAAE,OAAO,kBAAkB,KAAK;AAAA,MAAA;AAEjC,UAAI,iBAAiB,SAAS,WAAW,UAAU,iBAAiB,SAAS,UAAU,OAAO;AAC7F;AAAA,MACD;AACA,uBAAiB,UAAU;AAC3B,UAAI,eAAe;AACA,0BAAA;AAAA,UACjB;AAAA,UACA,YAAY;AAAA,UACZ,OAAO;AAAA,UACP,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,QAAQ,UAAU,OAAO,aAAa,CAAC;AAEvD,SAAO,CAAC,gBAAgB;AAAA,IACvB,QAAQ,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,EAAA,CAClD;AACF;"}
1
+ {"version":3,"file":"useEntitySubTreeLoader.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/useEntitySubTreeLoader.ts"],"sourcesContent":["import { createElement, ReactNode, useCallback, useEffect, useRef, useState } from 'react'\nimport { SugaredQualifiedSingleEntity, TreeRootId } from '@contember/binding'\nimport { useExtendTree } from './useExtendTree'\nimport { EntitySubTree } from '../coreComponents'\nimport { useObjectMemo } from '@contember/react-utils'\n\nexport type UseEntitySubTreeLoaderStateInitial = {\n\tstate: 'initial'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\nexport type UseEntitySubTreeLoaderStateLoading = {\n\tstate: 'loading'\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: true\n}\n\nexport type UseEntitySubTreeLoaderStateRefreshing<State> = {\n\tstate: 'refreshing'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: true\n}\n\n\nexport type UseEntitySubTreeLoaderStateLoaded<State> = {\n\tstate: 'loaded'\n\tentity: SugaredQualifiedSingleEntity\n\ttreeRootId: TreeRootId | undefined\n\tcustomState: State\n\tisLoading: false\n}\n\nexport type UseEntitySubTreeLoaderStateFailed = {\n\tstate: 'failed'\n\terror: unknown\n\tentity: undefined\n\ttreeRootId: undefined\n\tcustomState: undefined\n\tisLoading: false\n}\n\n\nexport type UseEntitySubTreeLoaderState<State> =\n\t| UseEntitySubTreeLoaderStateInitial\n\t| UseEntitySubTreeLoaderStateLoading\n\t| UseEntitySubTreeLoaderStateRefreshing<State>\n\t| UseEntitySubTreeLoaderStateLoaded<State>\n\t| UseEntitySubTreeLoaderStateFailed\n\nexport type EntityListSubTreeLoaderState = UseEntitySubTreeLoaderState<any>['state']\n\nexport type UseEntitySubTreeLoaderStateMethods = {\n\treload: () => void\n}\n\nconst emptyObject = {} as SugaredQualifiedSingleEntity\n\nexport const useEntitySubTreeLoader = <State>(entity: SugaredQualifiedSingleEntity | undefined, children: ReactNode, state?: State): [UseEntitySubTreeLoaderState<State>, UseEntitySubTreeLoaderStateMethods] => {\n\tconst [displayedState, setDisplayedState] = useState<UseEntitySubTreeLoaderState<State>>({\n\t\tstate: 'initial',\n\t\tisLoading: false,\n\t\tentity: undefined,\n\t\ttreeRootId: undefined,\n\t\tcustomState: undefined,\n\t})\n\tconst currentlyLoading = useRef<{\n\t\tentity: SugaredQualifiedSingleEntity\n\t\tstate?: State\n\t}>()\n\n\tconst extendTree = useExtendTree()\n\tconst [reloadTrigger, setReloadTrigger] = useState<object | null>(null)\n\tconst memoizedEntity = useObjectMemo(entity ?? emptyObject)\n\tconst resolvedEntity = entity ? memoizedEntity : undefined\n\n\tuseEffect(() => {\n\t\t(async () => {\n\t\t\tif (!resolvedEntity) {\n\t\t\t\treturn\n\t\t\t}\n\n\t\t\tcurrentlyLoading.current = {\n\t\t\t\tentity: resolvedEntity,\n\t\t\t\tstate,\n\t\t\t}\n\n\t\t\tsetDisplayedState(it => {\n\t\t\t\tif (it.state === 'initial' || it.state === 'loading' || it.state === 'failed') {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'loading',\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...it,\n\t\t\t\t\t\tisLoading: true,\n\t\t\t\t\t\tstate: 'refreshing',\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t})\n\n\t\t\tconst newTreeRootId = await extendTree(\n\t\t\t\tcreateElement(EntitySubTree, {\n\t\t\t\t\t...resolvedEntity,\n\t\t\t\t\tchildren,\n\t\t\t\t}),\n\t\t\t\t{\n\t\t\t\t\tforce: reloadTrigger !== null,\n\t\t\t\t\tonError: e => {\n\t\t\t\t\t\tconsole.error(e)\n\n\t\t\t\t\t\tcurrentlyLoading.current = undefined\n\n\t\t\t\t\t\tsetDisplayedState({\n\t\t\t\t\t\t\tstate: 'failed',\n\t\t\t\t\t\t\terror: e,\n\t\t\t\t\t\t\tentity: undefined,\n\t\t\t\t\t\t\ttreeRootId: undefined,\n\t\t\t\t\t\t\tcustomState: undefined,\n\t\t\t\t\t\t\tisLoading: false,\n\t\t\t\t\t\t})\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t)\n\n\n\t\t\tif (newTreeRootId) {\n\t\t\t\tcurrentlyLoading.current = undefined\n\t\t\t\tsetDisplayedState({\n\t\t\t\t\tstate: 'loaded',\n\t\t\t\t\tentity: resolvedEntity,\n\t\t\t\t\ttreeRootId: newTreeRootId,\n\t\t\t\t\tcustomState: state as State,\n\t\t\t\t\tisLoading: false,\n\t\t\t\t})\n\t\t\t}\n\t\t})()\n\t}, [extendTree, resolvedEntity, children, state, reloadTrigger])\n\n\treturn [\n\t\tdisplayedState,\n\t\t{\n\t\t\treload: useCallback(() => setReloadTrigger({}), []),\n\t\t},\n\t]\n}\n"],"names":[],"mappings":";;;;AA8DA,MAAM,cAAc,CAAA;AAEb,MAAM,yBAAyB,CAAQ,QAAkD,UAAqB,UAA4F;AAChN,QAAM,CAAC,gBAAgB,iBAAiB,IAAI,SAA6C;AAAA,IACxF,OAAO;AAAA,IACP,WAAW;AAAA,IACX,QAAQ;AAAA,IACR,YAAY;AAAA,IACZ,aAAa;AAAA,EAAA,CACb;AACD,QAAM,mBAAmB;AAKzB,QAAM,aAAa;AACnB,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAwB,IAAI;AAChE,QAAA,iBAAiB,cAAc,UAAU,WAAW;AACpD,QAAA,iBAAiB,SAAS,iBAAiB;AAEjD,YAAU,MAAM;AACf,KAAC,YAAY;AACZ,UAAI,CAAC,gBAAgB;AACpB;AAAA,MACD;AAEA,uBAAiB,UAAU;AAAA,QAC1B,QAAQ;AAAA,QACR;AAAA,MAAA;AAGD,wBAAkB,CAAM,OAAA;AACnB,YAAA,GAAG,UAAU,aAAa,GAAG,UAAU,aAAa,GAAG,UAAU,UAAU;AACvE,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QACR,OACM;AACC,iBAAA;AAAA,YACN,GAAG;AAAA,YACH,WAAW;AAAA,YACX,OAAO;AAAA,UAAA;AAAA,QAET;AAAA,MAAA,CACA;AAED,YAAM,gBAAgB,MAAM;AAAA,QAC3B,cAAc,eAAe;AAAA,UAC5B,GAAG;AAAA,UACH;AAAA,QAAA,CACA;AAAA,QACD;AAAA,UACC,OAAO,kBAAkB;AAAA,UACzB,SAAS,CAAK,MAAA;AACb,oBAAQ,MAAM,CAAC;AAEf,6BAAiB,UAAU;AAET,8BAAA;AAAA,cACjB,OAAO;AAAA,cACP,OAAO;AAAA,cACP,QAAQ;AAAA,cACR,YAAY;AAAA,cACZ,aAAa;AAAA,cACb,WAAW;AAAA,YAAA,CACX;AAAA,UACF;AAAA,QACD;AAAA,MAAA;AAID,UAAI,eAAe;AAClB,yBAAiB,UAAU;AACT,0BAAA;AAAA,UACjB,OAAO;AAAA,UACP,QAAQ;AAAA,UACR,YAAY;AAAA,UACZ,aAAa;AAAA,UACb,WAAW;AAAA,QAAA,CACX;AAAA,MACF;AAAA,IAAA;EACE,GACD,CAAC,YAAY,gBAAgB,UAAU,OAAO,aAAa,CAAC;AAExD,SAAA;AAAA,IACN;AAAA,IACA;AAAA,MACC,QAAQ,YAAY,MAAM,iBAAiB,CAAE,CAAA,GAAG,CAAA,CAAE;AAAA,IACnD;AAAA,EAAA;AAEF;"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const binding = require("@contember/binding");
4
+ const React = require("react");
5
+ const Component = require("../coreComponents/Component.cjs");
6
+ const recursionTerminatorEnvironmentExtension = binding.Environment.createExtension((options) => {
7
+ return options;
8
+ });
9
+ const RecursionTerminator = Component.Component(({ field, children }, env) => {
10
+ const isRecursion = React.useMemo(() => {
11
+ return recursionDetector(field, env);
12
+ }, [field, env]);
13
+ return !isRecursion ? children : null;
14
+ }, ({ field, children }, env) => {
15
+ const isRecursion = recursionDetector(field, env);
16
+ return !isRecursion ? children : null;
17
+ });
18
+ const recursionDetector = (field, env) => {
19
+ const firstPathItem = getFirstPathItem(field);
20
+ if (!firstPathItem) {
21
+ return false;
22
+ }
23
+ const shouldTerminate = env.getExtension(recursionTerminatorEnvironmentExtension)?.shouldTerminate;
24
+ const shouldTerminateResult = shouldTerminate?.({ node: env.getSubTreeNode(), field: firstPathItem, environment: env });
25
+ if (shouldTerminateResult !== void 0) {
26
+ return shouldTerminateResult;
27
+ }
28
+ const node = env.getSubTreeNode();
29
+ const otherSide = node.type === "entity-list" || node.type === "entity" ? node.field.ownedBy ?? node.field.inversedBy : void 0;
30
+ if (!otherSide) {
31
+ return false;
32
+ }
33
+ if (!firstPathItem) {
34
+ return false;
35
+ }
36
+ return otherSide === firstPathItem;
37
+ };
38
+ const getFirstPathItem = (field) => {
39
+ if (typeof field.field === "string") {
40
+ return field.field.match(binding.TokenRegExps.identifier)?.[0];
41
+ }
42
+ const getFromHasOne = (relation) => {
43
+ if (Array.isArray(relation)) {
44
+ return relation?.[0].field;
45
+ }
46
+ return relation?.field;
47
+ };
48
+ if (field.kind === "hasMany") {
49
+ return getFromHasOne(field.field.hasOneRelationPath) ?? field.field.hasManyRelation.field;
50
+ }
51
+ return getFromHasOne(field.field);
52
+ };
53
+ exports.RecursionTerminator = RecursionTerminator;
54
+ exports.recursionTerminatorEnvironmentExtension = recursionTerminatorEnvironmentExtension;
55
+ //# sourceMappingURL=RecursionTerminator.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecursionTerminator.cjs","sources":["../../../../../packages/react-binding/src/helperComponents/RecursionTerminator.tsx"],"sourcesContent":["import {\n\tEnvironment,\n\tSugarableHasOneRelation,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tTokenRegExps,\n} from '@contember/binding'\nimport { ReactNode, useMemo } from 'react'\nimport { Component } from '../coreComponents'\n\nexport interface RecursionTerminatorOptions {\n\tshouldTerminate?: (args: { node: Environment.AnyNode; field: string; environment: Environment }) => boolean | undefined\n}\n\nexport const recursionTerminatorEnvironmentExtension = Environment.createExtension((options: RecursionTerminatorOptions | undefined) => {\n\treturn options\n})\n\nexport interface RecursionTerminatorProps {\n\tfield:\n\t\t| { kind: 'hasOne'; field: SugaredRelativeSingleEntity['field'] }\n\t\t| { kind: 'hasMany'; field: SugaredRelativeEntityList['field'] }\n\tchildren: ReactNode\n}\n\nexport const RecursionTerminator = Component<RecursionTerminatorProps>(({ field, children }, env) => {\n\tconst isRecursion = useMemo(() => {\n\t\treturn recursionDetector(field, env)\n\t}, [field, env])\n\n\treturn !isRecursion ? children : null\n}, ({ field, children }, env) => {\n\tconst isRecursion = recursionDetector(field, env)\n\treturn !isRecursion ? children : null\n})\n\nconst recursionDetector = (field: RecursionTerminatorProps['field'], env: Environment) => {\n\tconst firstPathItem = getFirstPathItem(field)\n\tif (!firstPathItem) {\n\t\treturn false\n\t}\n\tconst shouldTerminate = env.getExtension(recursionTerminatorEnvironmentExtension)?.shouldTerminate\n\tconst shouldTerminateResult = shouldTerminate?.({ node: env.getSubTreeNode(), field: firstPathItem, environment: env })\n\tif (shouldTerminateResult !== undefined) {\n\t\treturn shouldTerminateResult\n\t}\n\n\tconst node = env.getSubTreeNode()\n\tconst otherSide = node.type === 'entity-list' || node.type === 'entity' ? (node.field.ownedBy ?? node.field.inversedBy) : undefined\n\tif (!otherSide) {\n\t\treturn false\n\t}\n\tif (!firstPathItem) {\n\t\treturn false\n\t}\n\treturn otherSide === firstPathItem\n}\n\nconst getFirstPathItem = (field: RecursionTerminatorProps['field']) => {\n\tif (typeof field.field === 'string') {\n\t\treturn field.field.match(TokenRegExps.identifier)?.[0]\n\t}\n\tconst getFromHasOne = (relation: SugarableHasOneRelation[] | SugarableHasOneRelation | undefined) => {\n\t\tif (Array.isArray(relation)) {\n\t\t\treturn relation?.[0].field\n\t\t}\n\t\treturn relation?.field\n\t}\n\tif (field.kind === 'hasMany') {\n\t\treturn getFromHasOne(field.field.hasOneRelationPath) ?? field.field.hasManyRelation.field\n\t}\n\treturn getFromHasOne(field.field)\n}\n"],"names":["Environment","Component","useMemo","TokenRegExps"],"mappings":";;;;;AAcO,MAAM,0CAA0CA,QAAA,YAAY,gBAAgB,CAAC,YAAoD;AAChI,SAAA;AACR,CAAC;AASM,MAAM,sBAAsBC,UAAoC,UAAA,CAAC,EAAE,OAAO,SAAA,GAAY,QAAQ;AAC9F,QAAA,cAAcC,MAAAA,QAAQ,MAAM;AAC1B,WAAA,kBAAkB,OAAO,GAAG;AAAA,EAAA,GACjC,CAAC,OAAO,GAAG,CAAC;AAER,SAAA,CAAC,cAAc,WAAW;AAClC,GAAG,CAAC,EAAE,OAAO,SAAA,GAAY,QAAQ;AAC1B,QAAA,cAAc,kBAAkB,OAAO,GAAG;AACzC,SAAA,CAAC,cAAc,WAAW;AAClC,CAAC;AAED,MAAM,oBAAoB,CAAC,OAA0C,QAAqB;AACnF,QAAA,gBAAgB,iBAAiB,KAAK;AAC5C,MAAI,CAAC,eAAe;AACZ,WAAA;AAAA,EACR;AACA,QAAM,kBAAkB,IAAI,aAAa,uCAAuC,GAAG;AAC7E,QAAA,wBAAwB,kBAAkB,EAAE,MAAM,IAAI,kBAAkB,OAAO,eAAe,aAAa,IAAK,CAAA;AACtH,MAAI,0BAA0B,QAAW;AACjC,WAAA;AAAA,EACR;AAEM,QAAA,OAAO,IAAI;AACjB,QAAM,YAAY,KAAK,SAAS,iBAAiB,KAAK,SAAS,WAAY,KAAK,MAAM,WAAW,KAAK,MAAM,aAAc;AAC1H,MAAI,CAAC,WAAW;AACR,WAAA;AAAA,EACR;AACA,MAAI,CAAC,eAAe;AACZ,WAAA;AAAA,EACR;AACA,SAAO,cAAc;AACtB;AAEA,MAAM,mBAAmB,CAAC,UAA6C;AAClE,MAAA,OAAO,MAAM,UAAU,UAAU;AACpC,WAAO,MAAM,MAAM,MAAMC,QAAa,aAAA,UAAU,IAAI,CAAC;AAAA,EACtD;AACM,QAAA,gBAAgB,CAAC,aAA8E;AAChG,QAAA,MAAM,QAAQ,QAAQ,GAAG;AACrB,aAAA,WAAW,CAAC,EAAE;AAAA,IACtB;AACA,WAAO,UAAU;AAAA,EAAA;AAEd,MAAA,MAAM,SAAS,WAAW;AAC7B,WAAO,cAAc,MAAM,MAAM,kBAAkB,KAAK,MAAM,MAAM,gBAAgB;AAAA,EACrF;AACO,SAAA,cAAc,MAAM,KAAK;AACjC;;;"}
@@ -0,0 +1,55 @@
1
+ import { Environment, TokenRegExps } from "@contember/binding";
2
+ import { useMemo } from "react";
3
+ import { Component } from "../coreComponents/Component.js";
4
+ const recursionTerminatorEnvironmentExtension = Environment.createExtension((options) => {
5
+ return options;
6
+ });
7
+ const RecursionTerminator = Component(({ field, children }, env) => {
8
+ const isRecursion = useMemo(() => {
9
+ return recursionDetector(field, env);
10
+ }, [field, env]);
11
+ return !isRecursion ? children : null;
12
+ }, ({ field, children }, env) => {
13
+ const isRecursion = recursionDetector(field, env);
14
+ return !isRecursion ? children : null;
15
+ });
16
+ const recursionDetector = (field, env) => {
17
+ const firstPathItem = getFirstPathItem(field);
18
+ if (!firstPathItem) {
19
+ return false;
20
+ }
21
+ const shouldTerminate = env.getExtension(recursionTerminatorEnvironmentExtension)?.shouldTerminate;
22
+ const shouldTerminateResult = shouldTerminate?.({ node: env.getSubTreeNode(), field: firstPathItem, environment: env });
23
+ if (shouldTerminateResult !== void 0) {
24
+ return shouldTerminateResult;
25
+ }
26
+ const node = env.getSubTreeNode();
27
+ const otherSide = node.type === "entity-list" || node.type === "entity" ? node.field.ownedBy ?? node.field.inversedBy : void 0;
28
+ if (!otherSide) {
29
+ return false;
30
+ }
31
+ if (!firstPathItem) {
32
+ return false;
33
+ }
34
+ return otherSide === firstPathItem;
35
+ };
36
+ const getFirstPathItem = (field) => {
37
+ if (typeof field.field === "string") {
38
+ return field.field.match(TokenRegExps.identifier)?.[0];
39
+ }
40
+ const getFromHasOne = (relation) => {
41
+ if (Array.isArray(relation)) {
42
+ return relation?.[0].field;
43
+ }
44
+ return relation?.field;
45
+ };
46
+ if (field.kind === "hasMany") {
47
+ return getFromHasOne(field.field.hasOneRelationPath) ?? field.field.hasManyRelation.field;
48
+ }
49
+ return getFromHasOne(field.field);
50
+ };
51
+ export {
52
+ RecursionTerminator,
53
+ recursionTerminatorEnvironmentExtension
54
+ };
55
+ //# sourceMappingURL=RecursionTerminator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecursionTerminator.js","sources":["../../../../../packages/react-binding/src/helperComponents/RecursionTerminator.tsx"],"sourcesContent":["import {\n\tEnvironment,\n\tSugarableHasOneRelation,\n\tSugaredRelativeEntityList,\n\tSugaredRelativeSingleEntity,\n\tTokenRegExps,\n} from '@contember/binding'\nimport { ReactNode, useMemo } from 'react'\nimport { Component } from '../coreComponents'\n\nexport interface RecursionTerminatorOptions {\n\tshouldTerminate?: (args: { node: Environment.AnyNode; field: string; environment: Environment }) => boolean | undefined\n}\n\nexport const recursionTerminatorEnvironmentExtension = Environment.createExtension((options: RecursionTerminatorOptions | undefined) => {\n\treturn options\n})\n\nexport interface RecursionTerminatorProps {\n\tfield:\n\t\t| { kind: 'hasOne'; field: SugaredRelativeSingleEntity['field'] }\n\t\t| { kind: 'hasMany'; field: SugaredRelativeEntityList['field'] }\n\tchildren: ReactNode\n}\n\nexport const RecursionTerminator = Component<RecursionTerminatorProps>(({ field, children }, env) => {\n\tconst isRecursion = useMemo(() => {\n\t\treturn recursionDetector(field, env)\n\t}, [field, env])\n\n\treturn !isRecursion ? children : null\n}, ({ field, children }, env) => {\n\tconst isRecursion = recursionDetector(field, env)\n\treturn !isRecursion ? children : null\n})\n\nconst recursionDetector = (field: RecursionTerminatorProps['field'], env: Environment) => {\n\tconst firstPathItem = getFirstPathItem(field)\n\tif (!firstPathItem) {\n\t\treturn false\n\t}\n\tconst shouldTerminate = env.getExtension(recursionTerminatorEnvironmentExtension)?.shouldTerminate\n\tconst shouldTerminateResult = shouldTerminate?.({ node: env.getSubTreeNode(), field: firstPathItem, environment: env })\n\tif (shouldTerminateResult !== undefined) {\n\t\treturn shouldTerminateResult\n\t}\n\n\tconst node = env.getSubTreeNode()\n\tconst otherSide = node.type === 'entity-list' || node.type === 'entity' ? (node.field.ownedBy ?? node.field.inversedBy) : undefined\n\tif (!otherSide) {\n\t\treturn false\n\t}\n\tif (!firstPathItem) {\n\t\treturn false\n\t}\n\treturn otherSide === firstPathItem\n}\n\nconst getFirstPathItem = (field: RecursionTerminatorProps['field']) => {\n\tif (typeof field.field === 'string') {\n\t\treturn field.field.match(TokenRegExps.identifier)?.[0]\n\t}\n\tconst getFromHasOne = (relation: SugarableHasOneRelation[] | SugarableHasOneRelation | undefined) => {\n\t\tif (Array.isArray(relation)) {\n\t\t\treturn relation?.[0].field\n\t\t}\n\t\treturn relation?.field\n\t}\n\tif (field.kind === 'hasMany') {\n\t\treturn getFromHasOne(field.field.hasOneRelationPath) ?? field.field.hasManyRelation.field\n\t}\n\treturn getFromHasOne(field.field)\n}\n"],"names":[],"mappings":";;;AAcO,MAAM,0CAA0C,YAAY,gBAAgB,CAAC,YAAoD;AAChI,SAAA;AACR,CAAC;AASM,MAAM,sBAAsB,UAAoC,CAAC,EAAE,OAAO,SAAA,GAAY,QAAQ;AAC9F,QAAA,cAAc,QAAQ,MAAM;AAC1B,WAAA,kBAAkB,OAAO,GAAG;AAAA,EAAA,GACjC,CAAC,OAAO,GAAG,CAAC;AAER,SAAA,CAAC,cAAc,WAAW;AAClC,GAAG,CAAC,EAAE,OAAO,SAAA,GAAY,QAAQ;AAC1B,QAAA,cAAc,kBAAkB,OAAO,GAAG;AACzC,SAAA,CAAC,cAAc,WAAW;AAClC,CAAC;AAED,MAAM,oBAAoB,CAAC,OAA0C,QAAqB;AACnF,QAAA,gBAAgB,iBAAiB,KAAK;AAC5C,MAAI,CAAC,eAAe;AACZ,WAAA;AAAA,EACR;AACA,QAAM,kBAAkB,IAAI,aAAa,uCAAuC,GAAG;AAC7E,QAAA,wBAAwB,kBAAkB,EAAE,MAAM,IAAI,kBAAkB,OAAO,eAAe,aAAa,IAAK,CAAA;AACtH,MAAI,0BAA0B,QAAW;AACjC,WAAA;AAAA,EACR;AAEM,QAAA,OAAO,IAAI;AACjB,QAAM,YAAY,KAAK,SAAS,iBAAiB,KAAK,SAAS,WAAY,KAAK,MAAM,WAAW,KAAK,MAAM,aAAc;AAC1H,MAAI,CAAC,WAAW;AACR,WAAA;AAAA,EACR;AACA,MAAI,CAAC,eAAe;AACZ,WAAA;AAAA,EACR;AACA,SAAO,cAAc;AACtB;AAEA,MAAM,mBAAmB,CAAC,UAA6C;AAClE,MAAA,OAAO,MAAM,UAAU,UAAU;AACpC,WAAO,MAAM,MAAM,MAAM,aAAa,UAAU,IAAI,CAAC;AAAA,EACtD;AACM,QAAA,gBAAgB,CAAC,aAA8E;AAChG,QAAA,MAAM,QAAQ,QAAQ,GAAG;AACrB,aAAA,WAAW,CAAC,EAAE;AAAA,IACtB;AACA,WAAO,UAAU;AAAA,EAAA;AAEd,MAAA,MAAM,SAAS,WAAW;AAC7B,WAAO,cAAc,MAAM,MAAM,kBAAkB,KAAK,MAAM,MAAM,gBAAgB;AAAA,EACrF;AACO,SAAA,cAAc,MAAM,KAAK;AACjC;"}
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
+ const jsxRuntime = require("react/jsx-runtime");
4
+ const binding = require("@contember/binding");
5
+ const RecursionTerminator = require("./RecursionTerminator.cjs");
6
+ const Component = require("../coreComponents/Component.cjs");
7
+ const EnvironmentContext = require("../accessorPropagation/EnvironmentContext.cjs");
8
+ const RecursionTerminatorPortal = Component.Component(({ field, children }) => {
9
+ return /* @__PURE__ */ jsxRuntime.jsx(EnvironmentContext.EnvironmentMiddleware, { args: [field], create: createEnvWithExtension, children });
10
+ });
11
+ const createEnvWithExtension = (env, [{ field, kind }]) => {
12
+ const envForField = kind === "hasOne" ? binding.TreeNodeEnvironmentFactory.createEnvironmentForEntity(env, { field }) : binding.TreeNodeEnvironmentFactory.createEnvironmentForEntityList(env, { field });
13
+ const parentNode = envForField.getSubTreeNode();
14
+ if (!(parentNode.type === "entity-list" || parentNode.type === "entity")) {
15
+ throw new binding.BindingError();
16
+ }
17
+ return env.withExtension(RecursionTerminator.recursionTerminatorEnvironmentExtension, {
18
+ shouldTerminate: (args) => {
19
+ if (args.environment.getParent().getSubTreeNode() !== env.getSubTreeNode()) {
20
+ return void 0;
21
+ }
22
+ const currentNode = args.node;
23
+ if (currentNode.type !== "subtree-entity" || currentNode.entity.name !== parentNode.field.targetEntity) {
24
+ return void 0;
25
+ }
26
+ const inverseField = parentNode.field.inversedBy ?? parentNode.field.ownedBy;
27
+ if (!inverseField) {
28
+ return false;
29
+ }
30
+ return args.field === inverseField;
31
+ }
32
+ });
33
+ };
34
+ exports.RecursionTerminatorPortal = RecursionTerminatorPortal;
35
+ //# sourceMappingURL=RecursionTerminatorPortal.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecursionTerminatorPortal.cjs","sources":["../../../../../packages/react-binding/src/helperComponents/RecursionTerminatorPortal.tsx"],"sourcesContent":["import { BindingError, Environment, TreeNodeEnvironmentFactory } from '@contember/binding'\nimport { Component } from '../coreComponents'\nimport { recursionTerminatorEnvironmentExtension, RecursionTerminatorProps } from './RecursionTerminator'\nimport { EnvironmentMiddleware } from '../accessorPropagation'\n\nexport const RecursionTerminatorPortal = Component<RecursionTerminatorProps>(({ field, children }) => {\n\treturn <EnvironmentMiddleware args={[field]} create={createEnvWithExtension} >{children}</EnvironmentMiddleware>\n})\n\nconst createEnvWithExtension = (env: Environment, [{ field, kind }]: [field: RecursionTerminatorProps['field']]) => {\n\tconst envForField = kind === 'hasOne'\n\t\t? TreeNodeEnvironmentFactory.createEnvironmentForEntity(env, { field })\n\t\t: TreeNodeEnvironmentFactory.createEnvironmentForEntityList(env, { field })\n\n\tconst parentNode = envForField.getSubTreeNode()\n\tif (!(parentNode.type === 'entity-list' || parentNode.type === 'entity')) {\n\t\tthrow new BindingError()\n\t}\n\treturn env.withExtension(recursionTerminatorEnvironmentExtension, {\n\t\tshouldTerminate: args => {\n\t\t\tif (args.environment.getParent().getSubTreeNode() !== env.getSubTreeNode()) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tconst currentNode = args.node\n\t\t\tif (currentNode.type !== 'subtree-entity' || currentNode.entity.name !== parentNode.field.targetEntity) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tconst inverseField = parentNode.field.inversedBy ?? parentNode.field.ownedBy\n\t\t\tif (!inverseField) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn args.field === inverseField\n\t\t},\n\t})\n}\n"],"names":["Component","jsx","EnvironmentMiddleware","TreeNodeEnvironmentFactory","BindingError","recursionTerminatorEnvironmentExtension"],"mappings":";;;;;;;AAKO,MAAM,4BAA4BA,UAAAA,UAAoC,CAAC,EAAE,OAAO,eAAe;AAC9F,SAAAC,2BAAA,IAACC,4CAAsB,MAAM,CAAC,KAAK,GAAG,QAAQ,wBAA0B,SAAS,CAAA;AACzF,CAAC;AAED,MAAM,yBAAyB,CAAC,KAAkB,CAAC,EAAE,OAAO,KAAM,CAAA,MAAkD;AACnH,QAAM,cAAc,SAAS,WAC1BC,QAAAA,2BAA2B,2BAA2B,KAAK,EAAE,MAAM,CAAC,IACpEA,QAA2B,2BAAA,+BAA+B,KAAK,EAAE,MAAO,CAAA;AAErE,QAAA,aAAa,YAAY;AAC/B,MAAI,EAAE,WAAW,SAAS,iBAAiB,WAAW,SAAS,WAAW;AACzE,UAAM,IAAIC,QAAa,aAAA;AAAA,EACxB;AACO,SAAA,IAAI,cAAcC,6DAAyC;AAAA,IACjE,iBAAiB,CAAQ,SAAA;AACpB,UAAA,KAAK,YAAY,UAAU,EAAE,qBAAqB,IAAI,kBAAkB;AACpE,eAAA;AAAA,MACR;AACA,YAAM,cAAc,KAAK;AACrB,UAAA,YAAY,SAAS,oBAAoB,YAAY,OAAO,SAAS,WAAW,MAAM,cAAc;AAChG,eAAA;AAAA,MACR;AACA,YAAM,eAAe,WAAW,MAAM,cAAc,WAAW,MAAM;AACrE,UAAI,CAAC,cAAc;AACX,eAAA;AAAA,MACR;AACA,aAAO,KAAK,UAAU;AAAA,IACvB;AAAA,EAAA,CACA;AACF;;"}
@@ -0,0 +1,35 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { TreeNodeEnvironmentFactory, BindingError } from "@contember/binding";
3
+ import { recursionTerminatorEnvironmentExtension } from "./RecursionTerminator.js";
4
+ import { Component } from "../coreComponents/Component.js";
5
+ import { EnvironmentMiddleware } from "../accessorPropagation/EnvironmentContext.js";
6
+ const RecursionTerminatorPortal = Component(({ field, children }) => {
7
+ return /* @__PURE__ */ jsx(EnvironmentMiddleware, { args: [field], create: createEnvWithExtension, children });
8
+ });
9
+ const createEnvWithExtension = (env, [{ field, kind }]) => {
10
+ const envForField = kind === "hasOne" ? TreeNodeEnvironmentFactory.createEnvironmentForEntity(env, { field }) : TreeNodeEnvironmentFactory.createEnvironmentForEntityList(env, { field });
11
+ const parentNode = envForField.getSubTreeNode();
12
+ if (!(parentNode.type === "entity-list" || parentNode.type === "entity")) {
13
+ throw new BindingError();
14
+ }
15
+ return env.withExtension(recursionTerminatorEnvironmentExtension, {
16
+ shouldTerminate: (args) => {
17
+ if (args.environment.getParent().getSubTreeNode() !== env.getSubTreeNode()) {
18
+ return void 0;
19
+ }
20
+ const currentNode = args.node;
21
+ if (currentNode.type !== "subtree-entity" || currentNode.entity.name !== parentNode.field.targetEntity) {
22
+ return void 0;
23
+ }
24
+ const inverseField = parentNode.field.inversedBy ?? parentNode.field.ownedBy;
25
+ if (!inverseField) {
26
+ return false;
27
+ }
28
+ return args.field === inverseField;
29
+ }
30
+ });
31
+ };
32
+ export {
33
+ RecursionTerminatorPortal
34
+ };
35
+ //# sourceMappingURL=RecursionTerminatorPortal.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"RecursionTerminatorPortal.js","sources":["../../../../../packages/react-binding/src/helperComponents/RecursionTerminatorPortal.tsx"],"sourcesContent":["import { BindingError, Environment, TreeNodeEnvironmentFactory } from '@contember/binding'\nimport { Component } from '../coreComponents'\nimport { recursionTerminatorEnvironmentExtension, RecursionTerminatorProps } from './RecursionTerminator'\nimport { EnvironmentMiddleware } from '../accessorPropagation'\n\nexport const RecursionTerminatorPortal = Component<RecursionTerminatorProps>(({ field, children }) => {\n\treturn <EnvironmentMiddleware args={[field]} create={createEnvWithExtension} >{children}</EnvironmentMiddleware>\n})\n\nconst createEnvWithExtension = (env: Environment, [{ field, kind }]: [field: RecursionTerminatorProps['field']]) => {\n\tconst envForField = kind === 'hasOne'\n\t\t? TreeNodeEnvironmentFactory.createEnvironmentForEntity(env, { field })\n\t\t: TreeNodeEnvironmentFactory.createEnvironmentForEntityList(env, { field })\n\n\tconst parentNode = envForField.getSubTreeNode()\n\tif (!(parentNode.type === 'entity-list' || parentNode.type === 'entity')) {\n\t\tthrow new BindingError()\n\t}\n\treturn env.withExtension(recursionTerminatorEnvironmentExtension, {\n\t\tshouldTerminate: args => {\n\t\t\tif (args.environment.getParent().getSubTreeNode() !== env.getSubTreeNode()) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tconst currentNode = args.node\n\t\t\tif (currentNode.type !== 'subtree-entity' || currentNode.entity.name !== parentNode.field.targetEntity) {\n\t\t\t\treturn undefined\n\t\t\t}\n\t\t\tconst inverseField = parentNode.field.inversedBy ?? parentNode.field.ownedBy\n\t\t\tif (!inverseField) {\n\t\t\t\treturn false\n\t\t\t}\n\t\t\treturn args.field === inverseField\n\t\t},\n\t})\n}\n"],"names":[],"mappings":";;;;;AAKO,MAAM,4BAA4B,UAAoC,CAAC,EAAE,OAAO,eAAe;AAC9F,SAAA,oBAAC,yBAAsB,MAAM,CAAC,KAAK,GAAG,QAAQ,wBAA0B,SAAS,CAAA;AACzF,CAAC;AAED,MAAM,yBAAyB,CAAC,KAAkB,CAAC,EAAE,OAAO,KAAM,CAAA,MAAkD;AACnH,QAAM,cAAc,SAAS,WAC1B,2BAA2B,2BAA2B,KAAK,EAAE,MAAM,CAAC,IACpE,2BAA2B,+BAA+B,KAAK,EAAE,MAAO,CAAA;AAErE,QAAA,aAAa,YAAY;AAC/B,MAAI,EAAE,WAAW,SAAS,iBAAiB,WAAW,SAAS,WAAW;AACzE,UAAM,IAAI,aAAa;AAAA,EACxB;AACO,SAAA,IAAI,cAAc,yCAAyC;AAAA,IACjE,iBAAiB,CAAQ,SAAA;AACpB,UAAA,KAAK,YAAY,UAAU,EAAE,qBAAqB,IAAI,kBAAkB;AACpE,eAAA;AAAA,MACR;AACA,YAAM,cAAc,KAAK;AACrB,UAAA,YAAY,SAAS,oBAAoB,YAAY,OAAO,SAAS,WAAW,MAAM,cAAc;AAChG,eAAA;AAAA,MACR;AACA,YAAM,eAAe,WAAW,MAAM,cAAc,WAAW,MAAM;AACrE,UAAI,CAAC,cAAc;AACX,eAAA;AAAA,MACR;AACA,aAAO,KAAK,UAAU;AAAA,IACvB;AAAA,EAAA,CACA;AACF;"}
@@ -1,3 +1,3 @@
1
- import { EntityAccessor } from '@contember/binding-common';
1
+ import { EntityAccessor } from '@contember/binding';
2
2
  export declare const EntityKeyContext: React.Context<string | (() => EntityAccessor) | undefined>;
3
3
  //# sourceMappingURL=EntityKeyContext.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"EntityKeyContext.d.ts","sourceRoot":"","sources":["../../../src/accessorPropagation/EntityKeyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,2BAA2B,CAAA;AAG1D,eAAO,MAAM,gBAAgB,gCAA6C,cAAc,cAAa,CAAA"}
1
+ {"version":3,"file":"EntityKeyContext.d.ts","sourceRoot":"","sources":["../../../src/accessorPropagation/EntityKeyContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAA;AAGnD,eAAO,MAAM,gBAAgB,gCAA6C,cAAc,cAAa,CAAA"}
@@ -1,11 +1,12 @@
1
1
  import { ReactNode } from 'react';
2
2
  import { Environment } from '@contember/binding';
3
3
  export declare const EnvironmentContext: React.Context<Environment<Environment.AnyNode | undefined>>;
4
- export interface EnvironmentMiddlewareProps {
4
+ export interface EnvironmentMiddlewareProps<T extends unknown[]> {
5
5
  children: ReactNode;
6
- create: (env: Environment) => Environment;
6
+ create: (env: Environment, args: T) => Environment;
7
+ args?: T;
7
8
  }
8
- export declare const EnvironmentMiddleware: React.NamedExoticComponent<EnvironmentMiddlewareProps>;
9
+ export declare const EnvironmentMiddleware: <T extends unknown[]>(props: EnvironmentMiddlewareProps<T>) => ReactNode;
9
10
  export interface EnvironmentWithExtensionProps<S, R> {
10
11
  children: ReactNode;
11
12
  extension: Environment.Extension<S, R>;
@@ -1 +1 @@
1
- {"version":3,"file":"EnvironmentContext.d.ts","sourceRoot":"","sources":["../../../src/accessorPropagation/EnvironmentContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAiB,SAAS,EAAwB,MAAM,OAAO,CAAA;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAIhD,eAAO,MAAM,kBAAkB,6DAAmD,CAAA;AAGlF,MAAM,WAAW,0BAA0B;IAC1C,QAAQ,EAAE,SAAS,CAAA;IACnB,MAAM,EAAE,CAAC,GAAG,EAAE,WAAW,KAAK,WAAW,CAAA;CACzC;AAED,eAAO,MAAM,qBAAqB,wDAejC,CAAA;AAED,MAAM,WAAW,6BAA6B,CAAC,CAAC,EAAE,CAAC;IAClD,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACtC,KAAK,EAAE,CAAC,CAAA;CACR;AAED,eAAO,MAAM,4BAA4B,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,6BAA6B,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAShG,CAAA"}
1
+ {"version":3,"file":"EnvironmentContext.d.ts","sourceRoot":"","sources":["../../../src/accessorPropagation/EnvironmentContext.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAgC,SAAS,EAAwB,MAAM,OAAO,CAAA;AACrF,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAA;AAIhD,eAAO,MAAM,kBAAkB,6DAAmD,CAAA;AAGlF,MAAM,WAAW,0BAA0B,CAAC,CAAC,SAAS,OAAO,EAAE;IAC9D,QAAQ,EAAE,SAAS,CAAA;IACnB,MAAM,EAAE,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,KAAK,WAAW,CAAA;IAClD,IAAI,CAAC,EAAE,CAAC,CAAA;CACR;AAED,eAAO,MAAM,qBAAqB,EAmB7B,CAAC,CAAmB,SAAT,OAAO,EAAE,EAAE,KAAK,EAAE,0BAA0B,CAAC,CAAC,CAAC,KAAK,SAAS,CAAA;AAE7E,MAAM,WAAW,6BAA6B,CAAC,CAAC,EAAE,CAAC;IAClD,QAAQ,EAAE,SAAS,CAAA;IACnB,SAAS,EAAE,WAAW,CAAC,SAAS,CAAC,CAAC,EAAE,CAAC,CAAC,CAAA;IACtC,KAAK,EAAE,CAAC,CAAA;CACR;AAED,eAAO,MAAM,4BAA4B,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,KAAK,EAAE,6BAA6B,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,SAShG,CAAA"}
@@ -28,7 +28,15 @@ export type UseEntityListSubTreeLoaderStateLoaded<State> = {
28
28
  customState: State;
29
29
  isLoading: false;
30
30
  };
31
- export type UseEntityListSubTreeLoaderState<State> = UseEntityListSubTreeLoaderStateInitial | UseEntityListSubTreeLoaderStateLoading | UseEntityListSubTreeLoaderStateRefreshing<State> | UseEntityListSubTreeLoaderStateLoaded<State>;
31
+ export type UseEntityListSubTreeLoaderStateFailed = {
32
+ state: 'failed';
33
+ error: unknown;
34
+ entities: undefined;
35
+ treeRootId: undefined;
36
+ customState: undefined;
37
+ isLoading: false;
38
+ };
39
+ export type UseEntityListSubTreeLoaderState<State> = UseEntityListSubTreeLoaderStateInitial | UseEntityListSubTreeLoaderStateLoading | UseEntityListSubTreeLoaderStateRefreshing<State> | UseEntityListSubTreeLoaderStateLoaded<State> | UseEntityListSubTreeLoaderStateFailed;
32
40
  export type UseEntityListSubTreeLoaderStateMethods = {
33
41
  reload: () => void;
34
42
  };