@contember/react-binding 2.0.0-alpha.24 → 2.0.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.
- package/dist/development/index.cjs +5 -0
- package/dist/development/index.cjs.map +1 -1
- package/dist/development/index.js +5 -0
- package/dist/development/index.js.map +1 -1
- package/dist/development/src/accessorPropagation/EntityKeyContext.cjs.map +1 -1
- package/dist/development/src/accessorPropagation/EntityKeyContext.js.map +1 -1
- package/dist/development/src/accessorPropagation/EnvironmentContext.cjs +12 -8
- package/dist/development/src/accessorPropagation/EnvironmentContext.cjs.map +1 -1
- package/dist/development/src/accessorPropagation/EnvironmentContext.js +12 -8
- package/dist/development/src/accessorPropagation/EnvironmentContext.js.map +1 -1
- package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.cjs +27 -12
- package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.cjs.map +1 -1
- package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.js +27 -12
- package/dist/development/src/accessorPropagation/useEntityListSubTreeLoader.js.map +1 -1
- package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.cjs +33 -15
- package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.cjs.map +1 -1
- package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.js +33 -15
- package/dist/development/src/accessorPropagation/useEntitySubTreeLoader.js.map +1 -1
- package/dist/development/src/helperComponents/RecursionTerminator.cjs +55 -0
- package/dist/development/src/helperComponents/RecursionTerminator.cjs.map +1 -0
- package/dist/development/src/helperComponents/RecursionTerminator.js +55 -0
- package/dist/development/src/helperComponents/RecursionTerminator.js.map +1 -0
- package/dist/development/src/helperComponents/RecursionTerminatorPortal.cjs +39 -0
- package/dist/development/src/helperComponents/RecursionTerminatorPortal.cjs.map +1 -0
- package/dist/development/src/helperComponents/RecursionTerminatorPortal.js +39 -0
- package/dist/development/src/helperComponents/RecursionTerminatorPortal.js.map +1 -0
- package/dist/development/src/markers/MarkerStaticAnalyzer.cjs +4 -1
- package/dist/development/src/markers/MarkerStaticAnalyzer.cjs.map +1 -1
- package/dist/development/src/markers/MarkerStaticAnalyzer.js +4 -1
- package/dist/development/src/markers/MarkerStaticAnalyzer.js.map +1 -1
- package/dist/production/index.cjs +5 -0
- package/dist/production/index.cjs.map +1 -1
- package/dist/production/index.js +5 -0
- package/dist/production/index.js.map +1 -1
- package/dist/production/src/accessorPropagation/EntityKeyContext.cjs.map +1 -1
- package/dist/production/src/accessorPropagation/EntityKeyContext.js.map +1 -1
- package/dist/production/src/accessorPropagation/EnvironmentContext.cjs +8 -4
- package/dist/production/src/accessorPropagation/EnvironmentContext.cjs.map +1 -1
- package/dist/production/src/accessorPropagation/EnvironmentContext.js +8 -4
- package/dist/production/src/accessorPropagation/EnvironmentContext.js.map +1 -1
- package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.cjs +27 -12
- package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.cjs.map +1 -1
- package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.js +27 -12
- package/dist/production/src/accessorPropagation/useEntityListSubTreeLoader.js.map +1 -1
- package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.cjs +33 -15
- package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.cjs.map +1 -1
- package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.js +33 -15
- package/dist/production/src/accessorPropagation/useEntitySubTreeLoader.js.map +1 -1
- package/dist/production/src/helperComponents/RecursionTerminator.cjs +55 -0
- package/dist/production/src/helperComponents/RecursionTerminator.cjs.map +1 -0
- package/dist/production/src/helperComponents/RecursionTerminator.js +55 -0
- package/dist/production/src/helperComponents/RecursionTerminator.js.map +1 -0
- package/dist/production/src/helperComponents/RecursionTerminatorPortal.cjs +35 -0
- package/dist/production/src/helperComponents/RecursionTerminatorPortal.cjs.map +1 -0
- package/dist/production/src/helperComponents/RecursionTerminatorPortal.js +35 -0
- package/dist/production/src/helperComponents/RecursionTerminatorPortal.js.map +1 -0
- package/dist/production/src/markers/MarkerStaticAnalyzer.cjs +4 -1
- package/dist/production/src/markers/MarkerStaticAnalyzer.cjs.map +1 -1
- package/dist/production/src/markers/MarkerStaticAnalyzer.js +4 -1
- package/dist/production/src/markers/MarkerStaticAnalyzer.js.map +1 -1
- package/dist/types/accessorPropagation/EntityKeyContext.d.ts +1 -1
- package/dist/types/accessorPropagation/EntityKeyContext.d.ts.map +1 -1
- package/dist/types/accessorPropagation/EnvironmentContext.d.ts +4 -3
- package/dist/types/accessorPropagation/EnvironmentContext.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts +9 -1
- package/dist/types/accessorPropagation/useEntityListSubTreeLoader.d.ts.map +1 -1
- package/dist/types/accessorPropagation/useEntitySubTreeLoader.d.ts +9 -1
- package/dist/types/accessorPropagation/useEntitySubTreeLoader.d.ts.map +1 -1
- package/dist/types/helperComponents/RecursionTerminator.d.ts +22 -0
- package/dist/types/helperComponents/RecursionTerminator.d.ts.map +1 -0
- package/dist/types/helperComponents/RecursionTerminatorPortal.d.ts +3 -0
- package/dist/types/helperComponents/RecursionTerminatorPortal.d.ts.map +1 -0
- package/dist/types/helperComponents/index.d.ts +2 -0
- package/dist/types/helperComponents/index.d.ts.map +1 -1
- package/dist/types/markers/MarkerStaticAnalyzer.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +7 -8
- package/src/accessorPropagation/EntityKeyContext.ts +1 -1
- package/src/accessorPropagation/EnvironmentContext.tsx +14 -9
- package/src/accessorPropagation/useEntityListSubTreeLoader.ts +41 -12
- package/src/accessorPropagation/useEntitySubTreeLoader.ts +49 -16
- package/src/helperComponents/RecursionTerminator.tsx +73 -0
- package/src/helperComponents/RecursionTerminatorPortal.tsx +35 -0
- package/src/helperComponents/index.ts +2 -0
- package/src/markers/MarkerStaticAnalyzer.ts +5 -1
- 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 { 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 (!
|
|
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
|
-
...
|
|
45
|
+
...resolvedEntity,
|
|
42
46
|
children
|
|
43
47
|
}),
|
|
44
|
-
{
|
|
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,
|
|
61
|
-
return [
|
|
62
|
-
|
|
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 (!
|
|
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,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const jsxDevRuntime = require("react/jsx-dev-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__ */ jsxDevRuntime.jsxDEV(EnvironmentContext.EnvironmentMiddleware, { args: [field], create: createEnvWithExtension, children }, void 0, false, {
|
|
10
|
+
fileName: "/home/runner/work/contember/contember/packages/react-binding/src/helperComponents/RecursionTerminatorPortal.tsx",
|
|
11
|
+
lineNumber: 7,
|
|
12
|
+
columnNumber: 9
|
|
13
|
+
}, void 0);
|
|
14
|
+
});
|
|
15
|
+
const createEnvWithExtension = (env, [{ field, kind }]) => {
|
|
16
|
+
const envForField = kind === "hasOne" ? binding.TreeNodeEnvironmentFactory.createEnvironmentForEntity(env, { field }) : binding.TreeNodeEnvironmentFactory.createEnvironmentForEntityList(env, { field });
|
|
17
|
+
const parentNode = envForField.getSubTreeNode();
|
|
18
|
+
if (!(parentNode.type === "entity-list" || parentNode.type === "entity")) {
|
|
19
|
+
throw new binding.BindingError();
|
|
20
|
+
}
|
|
21
|
+
return env.withExtension(RecursionTerminator.recursionTerminatorEnvironmentExtension, {
|
|
22
|
+
shouldTerminate: (args) => {
|
|
23
|
+
if (args.environment.getParent().getSubTreeNode() !== env.getSubTreeNode()) {
|
|
24
|
+
return void 0;
|
|
25
|
+
}
|
|
26
|
+
const currentNode = args.node;
|
|
27
|
+
if (currentNode.type !== "subtree-entity" || currentNode.entity.name !== parentNode.field.targetEntity) {
|
|
28
|
+
return void 0;
|
|
29
|
+
}
|
|
30
|
+
const inverseField = parentNode.field.inversedBy ?? parentNode.field.ownedBy;
|
|
31
|
+
if (!inverseField) {
|
|
32
|
+
return false;
|
|
33
|
+
}
|
|
34
|
+
return args.field === inverseField;
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
exports.RecursionTerminatorPortal = RecursionTerminatorPortal;
|
|
39
|
+
//# 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","jsxDEV","EnvironmentMiddleware","this","TreeNodeEnvironmentFactory","BindingError","recursionTerminatorEnvironmentExtension"],"mappings":";;;;;;;AAKO,MAAM,4BAA4BA,UAAAA,UAAoC,CAAC,EAAE,OAAO,eAAe;AAC9F,SAAAC,qCAACC,mBAAAA,yBAAsB,MAAM,CAAC,KAAK,GAAG,QAAQ,wBAA0B,SAAxE,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAiF,GAAAC,MAAA;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,39 @@
|
|
|
1
|
+
import { jsxDEV } from "react/jsx-dev-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__ */ jsxDEV(EnvironmentMiddleware, { args: [field], create: createEnvWithExtension, children }, void 0, false, {
|
|
8
|
+
fileName: "/home/runner/work/contember/contember/packages/react-binding/src/helperComponents/RecursionTerminatorPortal.tsx",
|
|
9
|
+
lineNumber: 7,
|
|
10
|
+
columnNumber: 9
|
|
11
|
+
}, void 0);
|
|
12
|
+
});
|
|
13
|
+
const createEnvWithExtension = (env, [{ field, kind }]) => {
|
|
14
|
+
const envForField = kind === "hasOne" ? TreeNodeEnvironmentFactory.createEnvironmentForEntity(env, { field }) : TreeNodeEnvironmentFactory.createEnvironmentForEntityList(env, { field });
|
|
15
|
+
const parentNode = envForField.getSubTreeNode();
|
|
16
|
+
if (!(parentNode.type === "entity-list" || parentNode.type === "entity")) {
|
|
17
|
+
throw new BindingError();
|
|
18
|
+
}
|
|
19
|
+
return env.withExtension(recursionTerminatorEnvironmentExtension, {
|
|
20
|
+
shouldTerminate: (args) => {
|
|
21
|
+
if (args.environment.getParent().getSubTreeNode() !== env.getSubTreeNode()) {
|
|
22
|
+
return void 0;
|
|
23
|
+
}
|
|
24
|
+
const currentNode = args.node;
|
|
25
|
+
if (currentNode.type !== "subtree-entity" || currentNode.entity.name !== parentNode.field.targetEntity) {
|
|
26
|
+
return void 0;
|
|
27
|
+
}
|
|
28
|
+
const inverseField = parentNode.field.inversedBy ?? parentNode.field.ownedBy;
|
|
29
|
+
if (!inverseField) {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
return args.field === inverseField;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
};
|
|
36
|
+
export {
|
|
37
|
+
RecursionTerminatorPortal
|
|
38
|
+
};
|
|
39
|
+
//# 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":["this"],"mappings":";;;;;AAKO,MAAM,4BAA4B,UAAoC,CAAC,EAAE,OAAO,eAAe;AAC9F,SAAA,uBAAC,yBAAsB,MAAM,CAAC,KAAK,GAAG,QAAQ,wBAA0B,SAAxE,GAAA,QAAA,OAAA;AAAA,IAAA,UAAA;AAAA,IAAA,YAAA;AAAA,IAAA,cAAA;AAAA,EAAiF,GAAAA,MAAA;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;"}
|
|
@@ -29,8 +29,11 @@ class MarkerStaticAnalyzer {
|
|
|
29
29
|
if (typeof node.type === "symbol" || typeof node.type === "string") {
|
|
30
30
|
return this.processNode(node.props.children, env, componentPath);
|
|
31
31
|
}
|
|
32
|
-
componentPath = [...componentPath, node];
|
|
33
32
|
const nodeDisplayName = "displayName" in node.type ? node.type.displayName : "???";
|
|
33
|
+
componentPath = [...componentPath, node];
|
|
34
|
+
if (componentPath.length > 1e3) {
|
|
35
|
+
wrapError(new ChildrenAnalyzerError("Component path too long, likely a circular reference"), nodeDisplayName, "[NONE]", componentPath);
|
|
36
|
+
}
|
|
34
37
|
try {
|
|
35
38
|
if ("generateEnvironment" in node.type) {
|
|
36
39
|
env = node.type.generateEnvironment(node.props, env);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkerStaticAnalyzer.cjs","sources":["../../../../../packages/react-binding/src/markers/MarkerStaticAnalyzer.ts"],"sourcesContent":["import React, { ReactElement, ReactNode } from 'react'\nimport { BranchMarkerProvider, EnvironmentDeltaProvider, LeafMarkerProvider, StaticRenderProvider } from './MarkerProvider'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityFieldsWithHoistablesMarker,\n\tEnvironment,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '@contember/binding'\nimport { IncrementalMarkerBuilder } from './IncrementalMarkerBuilder'\n\ntype Markers = FieldMarker | HasOneRelationMarker | EntityFieldMarkersContainer | EntityFieldsWithHoistablesMarker | HasManyRelationMarker\n\nexport class MarkerStaticAnalyzer {\n\tpublic processChildren(\n\t\tchildren: ReactNode,\n\t\tenv: Environment,\n\t): EntityFieldsWithHoistablesMarker | EntityFieldMarkersContainer | undefined {\n\t\tconst markers = this.processNode(children, env, [])\n\t\tif (markers.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn IncrementalMarkerBuilder.build(markers)\n\t}\n\n\tprivate processNode(\n\t\tnode: ReactNode,\n\t\tenv: Environment,\n\t\tcomponentPath: ReactElement[],\n\t): Markers[] {\n\t\tif (node === false || node === undefined || node === null || typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean') {\n\t\t\treturn []\n\t\t}\n\t\tif (typeof node === 'function') {\n\t\t\tthrow new ChildrenAnalyzerError(`Render props (functions as React component children) are not supported within the schema. ` +\n\t\t\t\t`You have likely used a bare custom component as opposed to wrapping in with \\`Component\\` ` +\n\t\t\t\t`from the \\`@contember/admin\\` package. Please refer to the documentation.`)\n\t\t}\n\n\t\tif (Array.isArray(node)) {\n\t\t\treturn node.flatMap(subNode => this.processNode(subNode, env, componentPath))\n\t\t}\n\n\t\tif (!('type' in node)) {\n\t\t\treturn []\n\t\t}\n\n\t\tif (typeof node.type === 'symbol' || typeof node.type === 'string') {\n\t\t\t// Fragment, Portal or other non-component\n\t\t\treturn this.processNode(node.props.children, env, componentPath)\n\t\t}\n\n\t\
|
|
1
|
+
{"version":3,"file":"MarkerStaticAnalyzer.cjs","sources":["../../../../../packages/react-binding/src/markers/MarkerStaticAnalyzer.ts"],"sourcesContent":["import React, { ReactElement, ReactNode } from 'react'\nimport { BranchMarkerProvider, EnvironmentDeltaProvider, LeafMarkerProvider, StaticRenderProvider } from './MarkerProvider'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityFieldsWithHoistablesMarker,\n\tEnvironment,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '@contember/binding'\nimport { IncrementalMarkerBuilder } from './IncrementalMarkerBuilder'\n\ntype Markers = FieldMarker | HasOneRelationMarker | EntityFieldMarkersContainer | EntityFieldsWithHoistablesMarker | HasManyRelationMarker\n\nexport class MarkerStaticAnalyzer {\n\tpublic processChildren(\n\t\tchildren: ReactNode,\n\t\tenv: Environment,\n\t): EntityFieldsWithHoistablesMarker | EntityFieldMarkersContainer | undefined {\n\t\tconst markers = this.processNode(children, env, [])\n\t\tif (markers.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn IncrementalMarkerBuilder.build(markers)\n\t}\n\n\tprivate processNode(\n\t\tnode: ReactNode,\n\t\tenv: Environment,\n\t\tcomponentPath: ReactElement[],\n\t): Markers[] {\n\t\tif (node === false || node === undefined || node === null || typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean') {\n\t\t\treturn []\n\t\t}\n\t\tif (typeof node === 'function') {\n\t\t\tthrow new ChildrenAnalyzerError(`Render props (functions as React component children) are not supported within the schema. ` +\n\t\t\t\t`You have likely used a bare custom component as opposed to wrapping in with \\`Component\\` ` +\n\t\t\t\t`from the \\`@contember/admin\\` package. Please refer to the documentation.`)\n\t\t}\n\n\t\tif (Array.isArray(node)) {\n\t\t\treturn node.flatMap(subNode => this.processNode(subNode, env, componentPath))\n\t\t}\n\n\t\tif (!('type' in node)) {\n\t\t\treturn []\n\t\t}\n\n\t\tif (typeof node.type === 'symbol' || typeof node.type === 'string') {\n\t\t\t// Fragment, Portal or other non-component\n\t\t\treturn this.processNode(node.props.children, env, componentPath)\n\t\t}\n\n\t\tconst nodeDisplayName = 'displayName' in node.type ? (node.type.displayName as string) : '???'\n\n\t\tcomponentPath = [...componentPath, node]\n\t\tif (componentPath.length > 1000) {\n\t\t\twrapError(new ChildrenAnalyzerError('Component path too long, likely a circular reference'), nodeDisplayName, '[NONE]', componentPath)\n\t\t}\n\n\n\t\ttry {\n\t\t\tif ('generateEnvironment' in node.type) {\n\t\t\t\tenv = (node.type as EnvironmentDeltaProvider).generateEnvironment(node.props, env)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\twrapError(e, nodeDisplayName, 'static context factory', componentPath)\n\t\t}\n\t\tif ('generateLeafMarker' in node.type) {\n\t\t\treturn [(node.type as LeafMarkerProvider).generateLeafMarker(node.props, env)]\n\t\t}\n\t\tlet children: ReactNode = node.props.children\n\t\ttry {\n\t\t\tif ('staticRender' in node.type) {\n\t\t\t\tchildren = (node.type as StaticRenderProvider).staticRender(node.props, env)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\twrapError(e, nodeDisplayName, 'static render', componentPath)\n\t\t}\n\t\tconst processedChildren = this.processNode(children, env, componentPath)\n\t\tif ('generateBranchMarker' in node.type) {\n\t\t\tconst marker = IncrementalMarkerBuilder.build(processedChildren)\n\t\t\treturn [(node.type as BranchMarkerProvider).generateBranchMarker(node.props, marker, env)]\n\t\t}\n\t\treturn processedChildren\n\t}\n}\n\nexport class ChildrenAnalyzerError extends Error {\n\tpublic details?: string\n\n\tconstructor(message: string, options?: { cause: Error; details?: string }) {\n\t\tsuper(message, options)\n\t\tthis.details = options?.details\n\t}\n}\n\nconst wrapError = (e: unknown, currentComponentName: string, methodName: string, path: ReactElement[]): never => {\n\tif (!(e instanceof Error)) {\n\t\tthrow e\n\t}\n\n\tconst componentPath = path.map((it, index) => {\n\t\tconst { children, ...props } = it.props\n\t\tconst printProps = (props: any) => {\n\t\t\tlet result = ''\n\t\t\tfor (const [key, value] of Object.entries(props)) {\n\t\t\t\tif (value === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst valuePrinted = JSON.stringify(value, (key, value) => {\n\t\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t\treturn '(function)'\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (React.isValidElement(value)) {\n\t\t\t\t\t\t\treturn '(react element)'\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn value\n\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t\tresult += ` ${key}=${valuePrinted}`\n\t\t\t\t} catch {\n\t\t\t\t\tresult += ` ${key}=(failed to print a value)`\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result\n\t\t}\n\t\tconst componentName = typeof it.type === 'object' && 'displayName' in it.type ? (it.type as any).displayName : null\n\t\tconst propsPrinted = printProps(props)\n\t\tconst indent = ' '.repeat(index)\n\t\treturn `${indent}<${componentName ?? '???'}${propsPrinted}>`\n\t})\n\tconst errorMessage = `Error during static render of ${currentComponentName} in ${methodName}:\\n${e.message || 'unknown error'}`\n\n\tthrow new ChildrenAnalyzerError(errorMessage, {\n\t\tcause: e,\n\t\tdetails: `Component path:\\n${componentPath.join('\\n')}`,\n\t})\n}\n"],"names":["IncrementalMarkerBuilder","props","key","value"],"mappings":"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"}
|
|
@@ -27,8 +27,11 @@ class MarkerStaticAnalyzer {
|
|
|
27
27
|
if (typeof node.type === "symbol" || typeof node.type === "string") {
|
|
28
28
|
return this.processNode(node.props.children, env, componentPath);
|
|
29
29
|
}
|
|
30
|
-
componentPath = [...componentPath, node];
|
|
31
30
|
const nodeDisplayName = "displayName" in node.type ? node.type.displayName : "???";
|
|
31
|
+
componentPath = [...componentPath, node];
|
|
32
|
+
if (componentPath.length > 1e3) {
|
|
33
|
+
wrapError(new ChildrenAnalyzerError("Component path too long, likely a circular reference"), nodeDisplayName, "[NONE]", componentPath);
|
|
34
|
+
}
|
|
32
35
|
try {
|
|
33
36
|
if ("generateEnvironment" in node.type) {
|
|
34
37
|
env = node.type.generateEnvironment(node.props, env);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MarkerStaticAnalyzer.js","sources":["../../../../../packages/react-binding/src/markers/MarkerStaticAnalyzer.ts"],"sourcesContent":["import React, { ReactElement, ReactNode } from 'react'\nimport { BranchMarkerProvider, EnvironmentDeltaProvider, LeafMarkerProvider, StaticRenderProvider } from './MarkerProvider'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityFieldsWithHoistablesMarker,\n\tEnvironment,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '@contember/binding'\nimport { IncrementalMarkerBuilder } from './IncrementalMarkerBuilder'\n\ntype Markers = FieldMarker | HasOneRelationMarker | EntityFieldMarkersContainer | EntityFieldsWithHoistablesMarker | HasManyRelationMarker\n\nexport class MarkerStaticAnalyzer {\n\tpublic processChildren(\n\t\tchildren: ReactNode,\n\t\tenv: Environment,\n\t): EntityFieldsWithHoistablesMarker | EntityFieldMarkersContainer | undefined {\n\t\tconst markers = this.processNode(children, env, [])\n\t\tif (markers.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn IncrementalMarkerBuilder.build(markers)\n\t}\n\n\tprivate processNode(\n\t\tnode: ReactNode,\n\t\tenv: Environment,\n\t\tcomponentPath: ReactElement[],\n\t): Markers[] {\n\t\tif (node === false || node === undefined || node === null || typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean') {\n\t\t\treturn []\n\t\t}\n\t\tif (typeof node === 'function') {\n\t\t\tthrow new ChildrenAnalyzerError(`Render props (functions as React component children) are not supported within the schema. ` +\n\t\t\t\t`You have likely used a bare custom component as opposed to wrapping in with \\`Component\\` ` +\n\t\t\t\t`from the \\`@contember/admin\\` package. Please refer to the documentation.`)\n\t\t}\n\n\t\tif (Array.isArray(node)) {\n\t\t\treturn node.flatMap(subNode => this.processNode(subNode, env, componentPath))\n\t\t}\n\n\t\tif (!('type' in node)) {\n\t\t\treturn []\n\t\t}\n\n\t\tif (typeof node.type === 'symbol' || typeof node.type === 'string') {\n\t\t\t// Fragment, Portal or other non-component\n\t\t\treturn this.processNode(node.props.children, env, componentPath)\n\t\t}\n\n\t\
|
|
1
|
+
{"version":3,"file":"MarkerStaticAnalyzer.js","sources":["../../../../../packages/react-binding/src/markers/MarkerStaticAnalyzer.ts"],"sourcesContent":["import React, { ReactElement, ReactNode } from 'react'\nimport { BranchMarkerProvider, EnvironmentDeltaProvider, LeafMarkerProvider, StaticRenderProvider } from './MarkerProvider'\nimport {\n\tEntityFieldMarkersContainer,\n\tEntityFieldsWithHoistablesMarker,\n\tEnvironment,\n\tFieldMarker,\n\tHasManyRelationMarker,\n\tHasOneRelationMarker,\n} from '@contember/binding'\nimport { IncrementalMarkerBuilder } from './IncrementalMarkerBuilder'\n\ntype Markers = FieldMarker | HasOneRelationMarker | EntityFieldMarkersContainer | EntityFieldsWithHoistablesMarker | HasManyRelationMarker\n\nexport class MarkerStaticAnalyzer {\n\tpublic processChildren(\n\t\tchildren: ReactNode,\n\t\tenv: Environment,\n\t): EntityFieldsWithHoistablesMarker | EntityFieldMarkersContainer | undefined {\n\t\tconst markers = this.processNode(children, env, [])\n\t\tif (markers.length === 0) {\n\t\t\treturn undefined\n\t\t}\n\t\treturn IncrementalMarkerBuilder.build(markers)\n\t}\n\n\tprivate processNode(\n\t\tnode: ReactNode,\n\t\tenv: Environment,\n\t\tcomponentPath: ReactElement[],\n\t): Markers[] {\n\t\tif (node === false || node === undefined || node === null || typeof node === 'string' || typeof node === 'number' || typeof node === 'boolean') {\n\t\t\treturn []\n\t\t}\n\t\tif (typeof node === 'function') {\n\t\t\tthrow new ChildrenAnalyzerError(`Render props (functions as React component children) are not supported within the schema. ` +\n\t\t\t\t`You have likely used a bare custom component as opposed to wrapping in with \\`Component\\` ` +\n\t\t\t\t`from the \\`@contember/admin\\` package. Please refer to the documentation.`)\n\t\t}\n\n\t\tif (Array.isArray(node)) {\n\t\t\treturn node.flatMap(subNode => this.processNode(subNode, env, componentPath))\n\t\t}\n\n\t\tif (!('type' in node)) {\n\t\t\treturn []\n\t\t}\n\n\t\tif (typeof node.type === 'symbol' || typeof node.type === 'string') {\n\t\t\t// Fragment, Portal or other non-component\n\t\t\treturn this.processNode(node.props.children, env, componentPath)\n\t\t}\n\n\t\tconst nodeDisplayName = 'displayName' in node.type ? (node.type.displayName as string) : '???'\n\n\t\tcomponentPath = [...componentPath, node]\n\t\tif (componentPath.length > 1000) {\n\t\t\twrapError(new ChildrenAnalyzerError('Component path too long, likely a circular reference'), nodeDisplayName, '[NONE]', componentPath)\n\t\t}\n\n\n\t\ttry {\n\t\t\tif ('generateEnvironment' in node.type) {\n\t\t\t\tenv = (node.type as EnvironmentDeltaProvider).generateEnvironment(node.props, env)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\twrapError(e, nodeDisplayName, 'static context factory', componentPath)\n\t\t}\n\t\tif ('generateLeafMarker' in node.type) {\n\t\t\treturn [(node.type as LeafMarkerProvider).generateLeafMarker(node.props, env)]\n\t\t}\n\t\tlet children: ReactNode = node.props.children\n\t\ttry {\n\t\t\tif ('staticRender' in node.type) {\n\t\t\t\tchildren = (node.type as StaticRenderProvider).staticRender(node.props, env)\n\t\t\t}\n\t\t} catch (e) {\n\t\t\twrapError(e, nodeDisplayName, 'static render', componentPath)\n\t\t}\n\t\tconst processedChildren = this.processNode(children, env, componentPath)\n\t\tif ('generateBranchMarker' in node.type) {\n\t\t\tconst marker = IncrementalMarkerBuilder.build(processedChildren)\n\t\t\treturn [(node.type as BranchMarkerProvider).generateBranchMarker(node.props, marker, env)]\n\t\t}\n\t\treturn processedChildren\n\t}\n}\n\nexport class ChildrenAnalyzerError extends Error {\n\tpublic details?: string\n\n\tconstructor(message: string, options?: { cause: Error; details?: string }) {\n\t\tsuper(message, options)\n\t\tthis.details = options?.details\n\t}\n}\n\nconst wrapError = (e: unknown, currentComponentName: string, methodName: string, path: ReactElement[]): never => {\n\tif (!(e instanceof Error)) {\n\t\tthrow e\n\t}\n\n\tconst componentPath = path.map((it, index) => {\n\t\tconst { children, ...props } = it.props\n\t\tconst printProps = (props: any) => {\n\t\t\tlet result = ''\n\t\t\tfor (const [key, value] of Object.entries(props)) {\n\t\t\t\tif (value === undefined) {\n\t\t\t\t\tcontinue\n\t\t\t\t}\n\t\t\t\ttry {\n\t\t\t\t\tconst valuePrinted = JSON.stringify(value, (key, value) => {\n\t\t\t\t\t\tif (typeof value === 'function') {\n\t\t\t\t\t\t\treturn '(function)'\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif (React.isValidElement(value)) {\n\t\t\t\t\t\t\treturn '(react element)'\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn value\n\t\t\t\t\t},\n\t\t\t\t\t)\n\t\t\t\t\tresult += ` ${key}=${valuePrinted}`\n\t\t\t\t} catch {\n\t\t\t\t\tresult += ` ${key}=(failed to print a value)`\n\t\t\t\t}\n\t\t\t}\n\t\t\treturn result\n\t\t}\n\t\tconst componentName = typeof it.type === 'object' && 'displayName' in it.type ? (it.type as any).displayName : null\n\t\tconst propsPrinted = printProps(props)\n\t\tconst indent = ' '.repeat(index)\n\t\treturn `${indent}<${componentName ?? '???'}${propsPrinted}>`\n\t})\n\tconst errorMessage = `Error during static render of ${currentComponentName} in ${methodName}:\\n${e.message || 'unknown error'}`\n\n\tthrow new ChildrenAnalyzerError(errorMessage, {\n\t\tcause: e,\n\t\tdetails: `Component path:\\n${componentPath.join('\\n')}`,\n\t})\n}\n"],"names":["props","key","value","React"],"mappings":";;;;;AAcO,MAAM,qBAAqB;AAAA,EAC1B,gBACN,UACA,KAC6E;AAC7E,UAAM,UAAU,KAAK,YAAY,UAAU,KAAK,CAAA,CAAE;AAC9C,QAAA,QAAQ,WAAW,GAAG;AAClB,aAAA;AAAA,IACR;AACO,WAAA,yBAAyB,MAAM,OAAO;AAAA,EAC9C;AAAA,EAEQ,YACP,MACA,KACA,eACY;AACZ,QAAI,SAAS,SAAS,SAAS,UAAa,SAAS,QAAQ,OAAO,SAAS,YAAY,OAAO,SAAS,YAAY,OAAO,SAAS,WAAW;AAC/I,aAAO;IACR;AACI,QAAA,OAAO,SAAS,YAAY;AACzB,YAAA,IAAI,sBAAsB,+PAE4C;AAAA,IAC7E;AAEI,QAAA,MAAM,QAAQ,IAAI,GAAG;AACjB,aAAA,KAAK,QAAQ,CAAW,YAAA,KAAK,YAAY,SAAS,KAAK,aAAa,CAAC;AAAA,IAC7E;AAEI,QAAA,EAAE,UAAU,OAAO;AACtB,aAAO;IACR;AAEA,QAAI,OAAO,KAAK,SAAS,YAAY,OAAO,KAAK,SAAS,UAAU;AAEnE,aAAO,KAAK,YAAY,KAAK,MAAM,UAAU,KAAK,aAAa;AAAA,IAChE;AAEA,UAAM,kBAAkB,iBAAiB,KAAK,OAAQ,KAAK,KAAK,cAAyB;AAEzE,oBAAA,CAAC,GAAG,eAAe,IAAI;AACnC,QAAA,cAAc,SAAS,KAAM;AAChC,gBAAU,IAAI,sBAAsB,sDAAsD,GAAG,iBAAiB,UAAU,aAAa;AAAA,IACtI;AAGI,QAAA;AACC,UAAA,yBAAyB,KAAK,MAAM;AACvC,cAAO,KAAK,KAAkC,oBAAoB,KAAK,OAAO,GAAG;AAAA,MAClF;AAAA,aACQ,GAAG;AACD,gBAAA,GAAG,iBAAiB,0BAA0B,aAAa;AAAA,IACtE;AACI,QAAA,wBAAwB,KAAK,MAAM;AACtC,aAAO,CAAE,KAAK,KAA4B,mBAAmB,KAAK,OAAO,GAAG,CAAC;AAAA,IAC9E;AACI,QAAA,WAAsB,KAAK,MAAM;AACjC,QAAA;AACC,UAAA,kBAAkB,KAAK,MAAM;AAChC,mBAAY,KAAK,KAA8B,aAAa,KAAK,OAAO,GAAG;AAAA,MAC5E;AAAA,aACQ,GAAG;AACD,gBAAA,GAAG,iBAAiB,iBAAiB,aAAa;AAAA,IAC7D;AACA,UAAM,oBAAoB,KAAK,YAAY,UAAU,KAAK,aAAa;AACnE,QAAA,0BAA0B,KAAK,MAAM;AAClC,YAAA,SAAS,yBAAyB,MAAM,iBAAiB;AACxD,aAAA,CAAE,KAAK,KAA8B,qBAAqB,KAAK,OAAO,QAAQ,GAAG,CAAC;AAAA,IAC1F;AACO,WAAA;AAAA,EACR;AACD;AAEO,MAAM,8BAA8B,MAAM;AAAA,EAGhD,YAAY,SAAiB,SAA8C;AAC1E,UAAM,SAAS,OAAO;AAHhB,kBAAA,MAAA,SAAA;AAIN,SAAK,UAAU,SAAS;AAAA,EACzB;AACD;AAEA,MAAM,YAAY,CAAC,GAAY,sBAA8B,YAAoB,SAAgC;AAC5G,MAAA,EAAE,aAAa,QAAQ;AACpB,UAAA;AAAA,EACP;AAEA,QAAM,gBAAgB,KAAK,IAAI,CAAC,IAAI,UAAU;AAC7C,UAAM,EAAE,UAAU,GAAG,MAAA,IAAU,GAAG;AAC5B,UAAA,aAAa,CAACA,WAAe;AAClC,UAAI,SAAS;AACb,iBAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQA,MAAK,GAAG;AACjD,YAAI,UAAU,QAAW;AACxB;AAAA,QACD;AACI,YAAA;AACH,gBAAM,eAAe,KAAK;AAAA,YAAU;AAAA,YAAO,CAACC,MAAKC,WAAU;AACtD,kBAAA,OAAOA,WAAU,YAAY;AACzB,uBAAA;AAAA,cACR;AACI,kBAAAC,eAAM,eAAeD,MAAK,GAAG;AACzB,uBAAA;AAAA,cACR;AACOA,qBAAAA;AAAAA,YACR;AAAA,UAAA;AAEU,oBAAA,IAAI,GAAG,IAAI,YAAY;AAAA,QAAA,QAC1B;AACP,oBAAU,IAAI,GAAG;AAAA,QAClB;AAAA,MACD;AACO,aAAA;AAAA,IAAA;AAEF,UAAA,gBAAgB,OAAO,GAAG,SAAS,YAAY,iBAAiB,GAAG,OAAQ,GAAG,KAAa,cAAc;AACzG,UAAA,eAAe,WAAW,KAAK;AAC/B,UAAA,SAAS,KAAK,OAAO,KAAK;AAChC,WAAO,GAAG,MAAM,IAAI,iBAAiB,KAAK,GAAG,YAAY;AAAA,EAAA,CACzD;AACD,QAAM,eAAe,iCAAiC,oBAAoB,OAAO,UAAU;AAAA,EAAM,EAAE,WAAW,eAAe;AAEvH,QAAA,IAAI,sBAAsB,cAAc;AAAA,IAC7C,OAAO;AAAA,IACP,SAAS;AAAA,EAAoB,cAAc,KAAK,IAAI,CAAC;AAAA,EAAA,CACrD;AACF;"}
|
|
@@ -63,6 +63,8 @@ const EntityView = require("./src/helperComponents/EntityView.cjs");
|
|
|
63
63
|
const If = require("./src/helperComponents/If.cjs");
|
|
64
64
|
const FieldView = require("./src/helperComponents/FieldView.cjs");
|
|
65
65
|
const LabelMiddleware = require("./src/helperComponents/LabelMiddleware.cjs");
|
|
66
|
+
const RecursionTerminator = require("./src/helperComponents/RecursionTerminator.cjs");
|
|
67
|
+
const RecursionTerminatorPortal = require("./src/helperComponents/RecursionTerminatorPortal.cjs");
|
|
66
68
|
const StaticRender = require("./src/helperComponents/StaticRender.cjs");
|
|
67
69
|
const SugaredField = require("./src/helperComponents/SugaredField.cjs");
|
|
68
70
|
const Variable = require("./src/helperComponents/Variable.cjs");
|
|
@@ -133,6 +135,9 @@ exports.FieldView = FieldView.FieldView;
|
|
|
133
135
|
exports.LabelMiddlewareContext = LabelMiddleware.LabelMiddlewareContext;
|
|
134
136
|
exports.LabelMiddlewareProvider = LabelMiddleware.LabelMiddlewareProvider;
|
|
135
137
|
exports.useLabelMiddleware = LabelMiddleware.useLabelMiddleware;
|
|
138
|
+
exports.RecursionTerminator = RecursionTerminator.RecursionTerminator;
|
|
139
|
+
exports.recursionTerminatorEnvironmentExtension = RecursionTerminator.recursionTerminatorEnvironmentExtension;
|
|
140
|
+
exports.RecursionTerminatorPortal = RecursionTerminatorPortal.RecursionTerminatorPortal;
|
|
136
141
|
exports.StaticRender = StaticRender.StaticRender;
|
|
137
142
|
exports.SugaredField = SugaredField.SugaredField;
|
|
138
143
|
exports.Variable = Variable.Variable;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/production/index.js
CHANGED
|
@@ -61,6 +61,8 @@ import { EntityView } from "./src/helperComponents/EntityView.js";
|
|
|
61
61
|
import { If } from "./src/helperComponents/If.js";
|
|
62
62
|
import { FieldView } from "./src/helperComponents/FieldView.js";
|
|
63
63
|
import { LabelMiddlewareContext, LabelMiddlewareProvider, useLabelMiddleware } from "./src/helperComponents/LabelMiddleware.js";
|
|
64
|
+
import { RecursionTerminator, recursionTerminatorEnvironmentExtension } from "./src/helperComponents/RecursionTerminator.js";
|
|
65
|
+
import { RecursionTerminatorPortal } from "./src/helperComponents/RecursionTerminatorPortal.js";
|
|
64
66
|
import { StaticRender } from "./src/helperComponents/StaticRender.js";
|
|
65
67
|
import { SugaredField } from "./src/helperComponents/SugaredField.js";
|
|
66
68
|
import { Variable } from "./src/helperComponents/Variable.js";
|
|
@@ -93,12 +95,15 @@ export {
|
|
|
93
95
|
MarkerTreeGenerator,
|
|
94
96
|
MutationStateContext,
|
|
95
97
|
ParentEntity,
|
|
98
|
+
RecursionTerminator,
|
|
99
|
+
RecursionTerminatorPortal,
|
|
96
100
|
SetOrderFieldOnCreate,
|
|
97
101
|
StaticRender,
|
|
98
102
|
SugaredField,
|
|
99
103
|
TreeRootIdProvider,
|
|
100
104
|
Variable,
|
|
101
105
|
addEntityAtIndex,
|
|
106
|
+
recursionTerminatorEnvironmentExtension,
|
|
102
107
|
repairEntitiesOrder,
|
|
103
108
|
sortEntities,
|
|
104
109
|
useAccessorTreeState,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityKeyContext.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/EntityKeyContext.ts"],"sourcesContent":["import { EntityAccessor } from '@contember/binding
|
|
1
|
+
{"version":3,"file":"EntityKeyContext.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/EntityKeyContext.ts"],"sourcesContent":["import { EntityAccessor } from '@contember/binding'\nimport { createContext } from 'react'\n\nexport const EntityKeyContext = createContext<undefined | string | (() => EntityAccessor)>(undefined)\nEntityKeyContext.displayName = 'EntityKeyContext'\n"],"names":["createContext"],"mappings":";;;AAGa,MAAA,mBAAmBA,MAAAA,cAA2D,MAAS;AACpG,iBAAiB,cAAc;;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EntityKeyContext.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/EntityKeyContext.ts"],"sourcesContent":["import { EntityAccessor } from '@contember/binding
|
|
1
|
+
{"version":3,"file":"EntityKeyContext.js","sources":["../../../../../packages/react-binding/src/accessorPropagation/EntityKeyContext.ts"],"sourcesContent":["import { EntityAccessor } from '@contember/binding'\nimport { createContext } from 'react'\n\nexport const EntityKeyContext = createContext<undefined | string | (() => EntityAccessor)>(undefined)\nEntityKeyContext.displayName = 'EntityKeyContext'\n"],"names":[],"mappings":";AAGa,MAAA,mBAAmB,cAA2D,MAAS;AACpG,iBAAiB,cAAc;"}
|
|
@@ -8,17 +8,21 @@ const Component = require("../coreComponents/Component.cjs");
|
|
|
8
8
|
const EnvironmentContext = React.createContext(binding.Environment.create());
|
|
9
9
|
EnvironmentContext.displayName = "EnvironmentContext";
|
|
10
10
|
const EnvironmentMiddleware = Component.Component(
|
|
11
|
-
({ children, create }) => {
|
|
11
|
+
({ children, create, args }) => {
|
|
12
12
|
const env = useEnvironment.useEnvironment();
|
|
13
|
-
const envWithExtension = React.useMemo(
|
|
13
|
+
const envWithExtension = React.useMemo(
|
|
14
|
+
() => create(env, args ?? []),
|
|
15
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
16
|
+
[env, create, ...args ?? []]
|
|
17
|
+
);
|
|
14
18
|
return /* @__PURE__ */ jsxRuntime.jsx(EnvironmentContext.Provider, { value: envWithExtension, children });
|
|
15
19
|
},
|
|
16
20
|
{
|
|
17
21
|
staticRender: ({ children }) => {
|
|
18
22
|
return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children });
|
|
19
23
|
},
|
|
20
|
-
generateEnvironment: ({ create }, env) => {
|
|
21
|
-
return create(env);
|
|
24
|
+
generateEnvironment: ({ create, args }, env) => {
|
|
25
|
+
return create(env, args ?? []);
|
|
22
26
|
}
|
|
23
27
|
}
|
|
24
28
|
);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EnvironmentContext.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { createContext, ReactNode, useCallback, useMemo } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps {\n\tchildren: ReactNode\n\tcreate: (env: Environment) => Environment\n}\n\nexport const EnvironmentMiddleware = Component(\n\t({ children, create }
|
|
1
|
+
{"version":3,"file":"EnvironmentContext.cjs","sources":["../../../../../packages/react-binding/src/accessorPropagation/EnvironmentContext.tsx"],"sourcesContent":["import { ComponentType, createContext, ReactNode, useCallback, useMemo } from 'react'\nimport { Environment } from '@contember/binding'\nimport { useEnvironment } from './useEnvironment'\nimport { Component } from '../coreComponents'\n\nexport const EnvironmentContext = createContext<Environment>(Environment.create())\nEnvironmentContext.displayName = 'EnvironmentContext'\n\nexport interface EnvironmentMiddlewareProps<T extends unknown[]> {\n\tchildren: ReactNode\n\tcreate: (env: Environment, args: T) => Environment\n\targs?: T\n}\n\nexport const EnvironmentMiddleware = Component<EnvironmentMiddlewareProps<unknown[]>>(\n\t({ children, create, args }) => {\n\t\tconst env = useEnvironment()\n\t\tconst envWithExtension = useMemo(\n\t\t\t() => create(env, args ?? []),\n\t\t\t// eslint-disable-next-line react-hooks/exhaustive-deps\n\t\t\t[env, create, ...(args ?? [])],\n\t\t)\n\n\t\treturn <EnvironmentContext.Provider value={envWithExtension}>{children}</EnvironmentContext.Provider>\n\t},\n\t{\n\t\tstaticRender: ({ children }) => {\n\t\t\treturn <>{children}</>\n\t\t},\n\t\tgenerateEnvironment: ({ create, args }, env) => {\n\t\t\treturn create(env, args ?? [])\n\t\t},\n\t},\n) as <T extends unknown[]>(props: EnvironmentMiddlewareProps<T>) => ReactNode\n\nexport interface EnvironmentWithExtensionProps<S, R> {\n\tchildren: ReactNode\n\textension: Environment.Extension<S, R>\n\tstate: S\n}\n\nexport const EnvironmentExtensionProvider: <S, R>(props: EnvironmentWithExtensionProps<S, R>) => ReactNode = Component(\n\t({ children, extension, state }) => {\n\t\tconst create = useCallback((env: Environment) => env.withExtension(extension, state), [extension, state])\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n\t({ children, extension, state }) => {\n\t\tconst create = (env: Environment) => env.withExtension(extension, state)\n\t\treturn <EnvironmentMiddleware create={create}>{children}</EnvironmentMiddleware>\n\t},\n)\n"],"names":["createContext","Environment","Component","useEnvironment","useMemo","useCallback","jsx"],"mappings":";;;;;;;AAKO,MAAM,qBAAqBA,MAAA,cAA2BC,oBAAY,QAAQ;AACjF,mBAAmB,cAAc;AAQ1B,MAAM,wBAAwBC,UAAA;AAAA,EACpC,CAAC,EAAE,UAAU,QAAQ,WAAW;AAC/B,UAAM,MAAMC,eAAAA;AACZ,UAAM,mBAAmBC,MAAA;AAAA,MACxB,MAAM,OAAO,KAAK,QAAQ,EAAE;AAAA;AAAA,MAE5B,CAAC,KAAK,QAAQ,GAAI,QAAQ,CAAA,CAAG;AAAA,IAAA;AAG9B,0CAAQ,mBAAmB,UAAnB,EAA4B,OAAO,kBAAmB,SAAS,CAAA;AAAA,EACxE;AAAA,EACA;AAAA,IACC,cAAc,CAAC,EAAE,eAAe;AAC/B,mEAAU,SAAS,CAAA;AAAA,IACpB;AAAA,IACA,qBAAqB,CAAC,EAAE,QAAQ,KAAA,GAAQ,QAAQ;AAC/C,aAAO,OAAO,KAAK,QAAQ,CAAE,CAAA;AAAA,IAC9B;AAAA,EACD;AACD;AAQO,MAAM,+BAAgGF,UAAA;AAAA,EAC5G,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAASG,MAAAA,YAAY,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK,GAAG,CAAC,WAAW,KAAK,CAAC;AACjG,WAAAC,2BAAA,IAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AAAA,EACA,CAAC,EAAE,UAAU,WAAW,YAAY;AACnC,UAAM,SAAS,CAAC,QAAqB,IAAI,cAAc,WAAW,KAAK;AAChE,WAAAA,2BAAA,IAAC,uBAAsB,EAAA,QAAiB,SAAS,CAAA;AAAA,EACzD;AACD;;;;"}
|
|
@@ -6,17 +6,21 @@ import { Component } from "../coreComponents/Component.js";
|
|
|
6
6
|
const EnvironmentContext = createContext(Environment.create());
|
|
7
7
|
EnvironmentContext.displayName = "EnvironmentContext";
|
|
8
8
|
const EnvironmentMiddleware = Component(
|
|
9
|
-
({ children, create }) => {
|
|
9
|
+
({ children, create, args }) => {
|
|
10
10
|
const env = useEnvironment();
|
|
11
|
-
const envWithExtension = useMemo(
|
|
11
|
+
const envWithExtension = useMemo(
|
|
12
|
+
() => create(env, args ?? []),
|
|
13
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
14
|
+
[env, create, ...args ?? []]
|
|
15
|
+
);
|
|
12
16
|
return /* @__PURE__ */ jsx(EnvironmentContext.Provider, { value: envWithExtension, children });
|
|
13
17
|
},
|
|
14
18
|
{
|
|
15
19
|
staticRender: ({ children }) => {
|
|
16
20
|
return /* @__PURE__ */ jsx(Fragment, { children });
|
|
17
21
|
},
|
|
18
|
-
generateEnvironment: ({ create }, env) => {
|
|
19
|
-
return create(env);
|
|
22
|
+
generateEnvironment: ({ create, args }, env) => {
|
|
23
|
+
return create(env, args ?? []);
|
|
20
24
|
}
|
|
21
25
|
}
|
|
22
26
|
);
|