palistor 0.0.25 → 0.0.27
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/README.md +609 -542
- package/README.ru.md +1015 -0
- package/dist/index.d.ts +16 -27
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +17 -28
- package/dist/index.js.map +1 -1
- package/dist/react/createTrackingProxy.d.ts +27 -27
- package/dist/react/createTrackingProxy.d.ts.map +1 -1
- package/dist/react/createTrackingProxy.js +54 -53
- package/dist/react/createTrackingProxy.js.map +1 -1
- package/dist/react/useForm.d.ts +42 -43
- package/dist/react/useForm.d.ts.map +1 -1
- package/dist/react/useForm.js +38 -38
- package/dist/react/useForm.js.map +1 -1
- package/dist/react/usePersist.d.ts +14 -14
- package/dist/react/usePersist.js +18 -18
- package/dist/react/usePersist.js.map +1 -1
- package/dist/react/useStoreContext.d.ts +11 -11
- package/dist/react/useStoreContext.js +11 -11
- package/dist/react/useTranslator.d.ts +12 -12
- package/dist/react/useTranslator.js +12 -12
- package/dist/store/applyPatch/applyPatch.d.ts +8 -8
- package/dist/store/applyPatch/applyPatch.js +12 -12
- package/dist/store/applyPatch/applyPatch.js.map +1 -1
- package/dist/store/buildProxy/buildEntityProjectionProxy.js +6 -6
- package/dist/store/buildProxy/buildEntityProjectionProxy.js.map +1 -1
- package/dist/store/buildProxy/buildListProxy.d.ts +8 -8
- package/dist/store/buildProxy/buildListProxy.js +30 -30
- package/dist/store/buildProxy/buildListProxy.js.map +1 -1
- package/dist/store/buildProxy/buildProxy.d.ts +8 -8
- package/dist/store/buildProxy/buildProxy.js +39 -39
- package/dist/store/buildProxy/buildProxy.js.map +1 -1
- package/dist/store/buildProxy/computeProxyKeys.d.ts +8 -8
- package/dist/store/buildProxy/computeProxyKeys.js +9 -9
- package/dist/store/buildProxy/computeProxyKeys.js.map +1 -1
- package/dist/store/buildProxy/handleLazyResolve.d.ts +3 -3
- package/dist/store/buildProxy/handleLazyResolve.js +3 -3
- package/dist/store/buildProxy/initProxyCaches.d.ts +5 -5
- package/dist/store/buildProxy/initProxyCaches.js +5 -5
- package/dist/store/compute/computeFieldState.d.ts +3 -3
- package/dist/store/compute/computeFieldState.js +8 -8
- package/dist/store/compute/computeFieldState.js.map +1 -1
- package/dist/store/compute/fieldStateChanged.d.ts +1 -1
- package/dist/store/compute/fieldStateChanged.js +1 -1
- package/dist/store/compute/recompute/collectGroupComputeNodes.d.ts +4 -4
- package/dist/store/compute/recompute/collectGroupComputeNodes.js +7 -7
- package/dist/store/compute/recompute/collectGroupComputeNodes.js.map +1 -1
- package/dist/store/compute/recompute/recomputeAndNotify.d.ts +3 -3
- package/dist/store/compute/recompute/recomputeAndNotify.js +3 -3
- package/dist/store/compute/recompute/recomputeLeaves.d.ts +11 -10
- package/dist/store/compute/recompute/recomputeLeaves.d.ts.map +1 -1
- package/dist/store/compute/recompute/recomputeLeaves.js +26 -27
- package/dist/store/compute/recompute/recomputeLeaves.js.map +1 -1
- package/dist/store/compute/recompute/recomputeTargeted.d.ts +7 -7
- package/dist/store/compute/recompute/recomputeTargeted.js +12 -12
- package/dist/store/compute/recompute/recomputeTargeted.js.map +1 -1
- package/dist/store/compute/recompute/topologicalSortComputed.d.ts +4 -4
- package/dist/store/compute/recompute/topologicalSortComputed.d.ts.map +1 -1
- package/dist/store/compute/recompute/topologicalSortComputed.js +11 -13
- package/dist/store/compute/recompute/topologicalSortComputed.js.map +1 -1
- package/dist/store/compute/recompute/types.d.ts +4 -4
- package/dist/store/compute/resolveFlag.d.ts +2 -2
- package/dist/store/compute/resolveFlag.js +2 -2
- package/dist/store/compute/resolveString.d.ts +5 -5
- package/dist/store/compute/resolveString.js +6 -6
- package/dist/store/compute/resolveString.js.map +1 -1
- package/dist/store/compute/types.d.ts +3 -3
- package/dist/store/constants.d.ts +48 -48
- package/dist/store/constants.d.ts.map +1 -1
- package/dist/store/constants.js +45 -45
- package/dist/store/defineFieldMapping.d.ts +21 -19
- package/dist/store/defineFieldMapping.d.ts.map +1 -1
- package/dist/store/defineFieldMapping.js +21 -19
- package/dist/store/defineFieldMapping.js.map +1 -1
- package/dist/store/dirtyTracking/collectInitialSnapshot.js +1 -1
- package/dist/store/dirtyTracking/collectInitialSnapshot.js.map +1 -1
- package/dist/store/dirtyTracking/recomputeDirtyTargeted.d.ts +3 -3
- package/dist/store/dirtyTracking/recomputeDirtyTargeted.js +11 -11
- package/dist/store/dirtyTracking/recomputeDirtyTargeted.js.map +1 -1
- package/dist/store/dirtyTracking/setGroupRevalidate.d.ts +6 -6
- package/dist/store/dirtyTracking/setGroupRevalidate.js +7 -7
- package/dist/store/dirtyTracking/setGroupRevalidate.js.map +1 -1
- package/dist/store/entityRegistry/entityRegistry.d.ts +72 -72
- package/dist/store/entityRegistry/entityRegistry.d.ts.map +1 -1
- package/dist/store/entityRegistry/entityRegistry.js +91 -91
- package/dist/store/entityRegistry/entityRegistry.js.map +1 -1
- package/dist/store/entityRegistry/generateId.d.ts +3 -3
- package/dist/store/entityRegistry/generateId.js +3 -3
- package/dist/store/entityRegistry/types.d.ts +17 -17
- package/dist/store/entityRegistry/types.d.ts.map +1 -1
- package/dist/store/flow/buildFlowStepsProxy.d.ts +9 -9
- package/dist/store/flow/buildFlowStepsProxy.js +13 -13
- package/dist/store/flow/buildFlowStepsProxy.js.map +1 -1
- package/dist/store/flow/defineFlow.d.ts +27 -25
- package/dist/store/flow/defineFlow.d.ts.map +1 -1
- package/dist/store/flow/defineFlow.js +15 -13
- package/dist/store/flow/defineFlow.js.map +1 -1
- package/dist/store/flow/flowApi.d.ts +3 -2
- package/dist/store/flow/flowApi.d.ts.map +1 -1
- package/dist/store/flow/flowApi.js +1 -1
- package/dist/store/flow/flowApi.js.map +1 -1
- package/dist/store/flow/flowNavigation.d.ts +65 -63
- package/dist/store/flow/flowNavigation.d.ts.map +1 -1
- package/dist/store/flow/flowNavigation.js +74 -72
- package/dist/store/flow/flowNavigation.js.map +1 -1
- package/dist/store/flow/flowState.d.ts +16 -16
- package/dist/store/flow/flowState.d.ts.map +1 -1
- package/dist/store/flow/flowState.js +5 -5
- package/dist/store/flow/flowState.js.map +1 -1
- package/dist/store/groupDeps/createGroupDeps.d.ts +3 -3
- package/dist/store/groupDeps/createGroupDeps.js +6 -6
- package/dist/store/groupDeps/createGroupDeps.js.map +1 -1
- package/dist/store/groupDeps/createTrackingValues.d.ts +9 -9
- package/dist/store/groupDeps/createTrackingValues.js +11 -11
- package/dist/store/groupDeps/createTrackingValues.js.map +1 -1
- package/dist/store/groupDeps/getNodeGroupPath.d.ts +3 -3
- package/dist/store/groupDeps/getNodeGroupPath.js +5 -5
- package/dist/store/groupDeps/getNodeGroupPath.js.map +1 -1
- package/dist/store/groupDeps/getRecipientGroups.d.ts +1 -1
- package/dist/store/groupDeps/getRecipientGroups.js +1 -1
- package/dist/store/groupDeps/groupDeps.d.ts +7 -7
- package/dist/store/groupDeps/groupDeps.js +7 -7
- package/dist/store/groupDeps/pairKey.d.ts +3 -3
- package/dist/store/groupDeps/pairKey.d.ts.map +1 -1
- package/dist/store/groupDeps/pairKey.js +4 -4
- package/dist/store/groupDeps/pairKey.js.map +1 -1
- package/dist/store/groupDeps/resolveGroupByPath.d.ts +3 -3
- package/dist/store/groupDeps/resolveGroupByPath.js +3 -3
- package/dist/store/init/createNotificationHub.d.ts +31 -31
- package/dist/store/init/createNotificationHub.d.ts.map +1 -1
- package/dist/store/init/createNotificationHub.js +36 -37
- package/dist/store/init/createNotificationHub.js.map +1 -1
- package/dist/store/init/createResolveManager.d.ts +72 -69
- package/dist/store/init/createResolveManager.d.ts.map +1 -1
- package/dist/store/init/createResolveManager.js +101 -98
- package/dist/store/init/createResolveManager.js.map +1 -1
- package/dist/store/init/initGroupSubmitting.d.ts +2 -2
- package/dist/store/init/initGroupSubmitting.js +4 -4
- package/dist/store/init/initGroupSubmitting.js.map +1 -1
- package/dist/store/normalizeConfig.d.ts +20 -18
- package/dist/store/normalizeConfig.d.ts.map +1 -1
- package/dist/store/normalizeConfig.js +31 -29
- package/dist/store/normalizeConfig.js.map +1 -1
- package/dist/store/onChangePipeline/computeFieldKey.d.ts +2 -2
- package/dist/store/onChangePipeline/computeFieldKey.js +2 -2
- package/dist/store/onChangePipeline/findOnChangeAncestors.d.ts +2 -2
- package/dist/store/onChangePipeline/findOnChangeAncestors.js +4 -4
- package/dist/store/onChangePipeline/findOnChangeAncestors.js.map +1 -1
- package/dist/store/onChangePipeline/onChangePipeline.d.ts +13 -12
- package/dist/store/onChangePipeline/onChangePipeline.d.ts.map +1 -1
- package/dist/store/onChangePipeline/onChangePipeline.js +14 -13
- package/dist/store/onChangePipeline/onChangePipeline.js.map +1 -1
- package/dist/store/persist/drivers.d.ts +7 -7
- package/dist/store/persist/drivers.js +8 -8
- package/dist/store/persist/drivers.js.map +1 -1
- package/dist/store/persist/index.d.ts +1 -1
- package/dist/store/persist/persistManager.d.ts +23 -23
- package/dist/store/persist/persistManager.d.ts.map +1 -1
- package/dist/store/persist/persistManager.js +51 -51
- package/dist/store/persist/persistManager.js.map +1 -1
- package/dist/store/persist/types.d.ts +23 -23
- package/dist/store/persist/types.d.ts.map +1 -1
- package/dist/store/persist/types.js +4 -4
- package/dist/store/resetPipeline/buildResetPatch.d.ts +5 -5
- package/dist/store/resetPipeline/buildResetPatch.js +5 -5
- package/dist/store/resetPipeline/collectDefaults.d.ts +5 -5
- package/dist/store/resetPipeline/collectDefaults.js +6 -6
- package/dist/store/resetPipeline/collectDefaults.js.map +1 -1
- package/dist/store/resetPipeline/resetPipeline.d.ts +7 -7
- package/dist/store/resetPipeline/resetPipeline.js +15 -15
- package/dist/store/resetPipeline/resetPipeline.js.map +1 -1
- package/dist/store/resolvePipeline/applyPendingWrites.d.ts +10 -10
- package/dist/store/resolvePipeline/applyPendingWrites.d.ts.map +1 -1
- package/dist/store/resolvePipeline/applyPendingWrites.js +35 -38
- package/dist/store/resolvePipeline/applyPendingWrites.js.map +1 -1
- package/dist/store/resolvePipeline/createContextTrackingProxy.d.ts +8 -7
- package/dist/store/resolvePipeline/createContextTrackingProxy.d.ts.map +1 -1
- package/dist/store/resolvePipeline/createContextTrackingProxy.js +6 -5
- package/dist/store/resolvePipeline/createContextTrackingProxy.js.map +1 -1
- package/dist/store/resolvePipeline/createValuesTrackingProxy.d.ts +43 -43
- package/dist/store/resolvePipeline/createValuesTrackingProxy.d.ts.map +1 -1
- package/dist/store/resolvePipeline/createValuesTrackingProxy.js +70 -70
- package/dist/store/resolvePipeline/createValuesTrackingProxy.js.map +1 -1
- package/dist/store/resolvePipeline/executeListResolve.d.ts +14 -14
- package/dist/store/resolvePipeline/executeListResolve.js +27 -27
- package/dist/store/resolvePipeline/executeListResolve.js.map +1 -1
- package/dist/store/resolvePipeline/executeResolve.d.ts +15 -15
- package/dist/store/resolvePipeline/executeResolve.js +46 -46
- package/dist/store/resolvePipeline/executeResolve.js.map +1 -1
- package/dist/store/store/NodeRegistry/nodeRegistry.d.ts +61 -61
- package/dist/store/store/NodeRegistry/nodeRegistry.d.ts.map +1 -1
- package/dist/store/store/NodeRegistry/nodeRegistry.js +85 -86
- package/dist/store/store/NodeRegistry/nodeRegistry.js.map +1 -1
- package/dist/store/store/NodeRegistry/nodeUtils.d.ts +5 -5
- package/dist/store/store/NodeRegistry/nodeUtils.d.ts.map +1 -1
- package/dist/store/store/NodeRegistry/nodeUtils.js +5 -5
- package/dist/store/store/NodeRegistry/nodeUtils.js.map +1 -1
- package/dist/store/store/groupDepsMap.d.ts +23 -23
- package/dist/store/store/groupDepsMap.d.ts.map +1 -1
- package/dist/store/store/groupDepsMap.js +35 -34
- package/dist/store/store/groupDepsMap.js.map +1 -1
- package/dist/store/store/hasComputedProps.d.ts +2 -2
- package/dist/store/store/hasComputedProps.js +2 -2
- package/dist/store/store/nodeMap.d.ts +5 -5
- package/dist/store/store/nodeMap.js +7 -7
- package/dist/store/store/nodeMap.js.map +1 -1
- package/dist/store/store/palistor.d.ts +80 -80
- package/dist/store/store/palistor.d.ts.map +1 -1
- package/dist/store/store/palistor.js +149 -169
- package/dist/store/store/palistor.js.map +1 -1
- package/dist/store/store/registerNodes.d.ts +10 -10
- package/dist/store/store/registerNodes.js +15 -15
- package/dist/store/store/registerNodes.js.map +1 -1
- package/dist/store/store/serviceRegistry.d.ts +8 -8
- package/dist/store/store/serviceRegistry.d.ts.map +1 -1
- package/dist/store/store/serviceRegistry.js +8 -8
- package/dist/store/store/serviceRegistry.js.map +1 -1
- package/dist/store/store/types.d.ts +236 -234
- package/dist/store/store/types.d.ts.map +1 -1
- package/dist/store/submitPipeline/applyLeafBeforeSubmit.d.ts +2 -2
- package/dist/store/submitPipeline/applyLeafBeforeSubmit.js +2 -2
- package/dist/store/submitPipeline/collectLeafStates.d.ts +2 -2
- package/dist/store/submitPipeline/collectLeafStates.js +2 -2
- package/dist/store/submitPipeline/submitPipeline.d.ts +8 -8
- package/dist/store/submitPipeline/submitPipeline.js +12 -12
- package/dist/store/submitPipeline/submitPipeline.js.map +1 -1
- package/dist/store/submitPipeline/types.d.ts +1 -1
- package/dist/store/submitPipeline/types.d.ts.map +1 -1
- package/dist/store/traversal/nodeClassifier.d.ts +9 -9
- package/dist/store/traversal/nodeClassifier.d.ts.map +1 -1
- package/dist/store/traversal/nodeClassifier.js +11 -11
- package/dist/store/traversal/nodeClassifier.js.map +1 -1
- package/dist/store/traversal/walkFull.d.ts +14 -14
- package/dist/store/traversal/walkFull.js +2 -2
- package/dist/store/valuesCache/valuesCache.d.ts +9 -9
- package/dist/store/valuesCache/valuesCache.d.ts.map +1 -1
- package/dist/store/valuesCache/valuesCache.js +6 -6
- package/dist/store/writePipeline/formatPatch.d.ts +5 -5
- package/dist/store/writePipeline/formatPatch.js +7 -7
- package/dist/store/writePipeline/formatPatch.js.map +1 -1
- package/dist/store/writePipeline/formatValue.d.ts +5 -5
- package/dist/store/writePipeline/formatValue.js +5 -5
- package/dist/store/writePipeline/mergeChanged.d.ts +4 -4
- package/dist/store/writePipeline/mergeChanged.js +4 -4
- package/dist/store/writePipeline/runSetter.d.ts +6 -6
- package/dist/store/writePipeline/runSetter.js +8 -8
- package/dist/store/writePipeline/storeValue.d.ts +3 -3
- package/dist/store/writePipeline/storeValue.js +3 -3
- package/dist/store/writePipeline/types.d.ts +4 -4
- package/dist/store/writePipeline/types.d.ts.map +1 -1
- package/dist/store/writePipeline/writePipeline.d.ts +7 -7
- package/dist/store/writePipeline/writePipeline.d.ts.map +1 -1
- package/dist/store/writePipeline/writePipeline.js +15 -15
- package/dist/store/writePipeline/writePipeline.js.map +1 -1
- package/package.json +11 -4
package/dist/react/useForm.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useForm — React
|
|
2
|
+
* useForm — the React hook that connects a component to a ProxyStore.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Returns a reactive proxy. Dot access to fields IS the subscription: the
|
|
5
|
+
* component re-renders only when a field it actually read changes.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```tsx
|
|
@@ -22,54 +22,53 @@
|
|
|
22
22
|
* );
|
|
23
23
|
* }
|
|
24
24
|
*
|
|
25
|
-
* //
|
|
25
|
+
* // Child component with its own useForm for an independent subscription:
|
|
26
26
|
* function PassportSection({ passport }) {
|
|
27
|
-
* const p = useForm(passport); // ←
|
|
27
|
+
* const p = useForm(passport); // ← accepts a subtree!
|
|
28
28
|
* if (!p.isVisible) return null;
|
|
29
29
|
* return <NumberField field={p.number} />;
|
|
30
30
|
* }
|
|
31
31
|
* ```
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
* 1. useSyncExternalStore
|
|
35
|
-
* 2. getSnapshot
|
|
36
|
-
* re-render
|
|
37
|
-
* 3. store.proxy
|
|
38
|
-
* config
|
|
39
|
-
* 4.
|
|
33
|
+
* How it works:
|
|
34
|
+
* 1. useSyncExternalStore subscribes to global store changes.
|
|
35
|
+
* 2. getSnapshot compares versions of only the nodes that were read →
|
|
36
|
+
* a re-render happens only when something that was read changed.
|
|
37
|
+
* 3. store.proxy is wrapped in a tracking proxy. Every GET records the
|
|
38
|
+
* config node into a tracked set. getSnapshot checks only those nodes.
|
|
39
|
+
* 4. A write `form.email.value = "X"` → store.proxy.email.value = "X" →
|
|
40
40
|
* SET trap → formatter → validate → recompute → notify → re-render
|
|
41
|
-
* (
|
|
41
|
+
* (only of components that read the changed nodes).
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
* - useForm(store) —
|
|
45
|
-
* - useForm(proxySubtree) —
|
|
46
|
-
*
|
|
47
|
-
* - useForm(entityProxy, templateSelector) —
|
|
48
|
-
* entityProxy
|
|
49
|
-
*
|
|
43
|
+
* Overloads:
|
|
44
|
+
* - useForm(store) — the main form, pass the ProxyStore
|
|
45
|
+
* - useForm(proxySubtree) — accepts a tracking-proxy subtree (from a prop),
|
|
46
|
+
* creating an **independent** tracking scope for this component
|
|
47
|
+
* - useForm(entityProxy, templateSelector) — binds an entity to a template.
|
|
48
|
+
* entityProxy comes from list.items/list.getById. templateSelector = (s) => s.editForm.
|
|
49
|
+
* Calls entityRegistry.bind on mount, unbind on unmount.
|
|
50
50
|
*/
|
|
51
51
|
import type { ProxyStore, ConfigProxy, GroupProxyNode, RawStoreProxyMarker } from "../store/store";
|
|
52
52
|
import type { PalistorRef, PalistorList, Palistor, PalistorEntityProxy, FieldMapping } from "../store/store/types";
|
|
53
53
|
/**
|
|
54
|
-
*
|
|
54
|
+
* Connects a React component to a ProxyStore.
|
|
55
55
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
*
|
|
56
|
+
* The component re-renders only when fields it read during the previous
|
|
57
|
+
* render change. The tracking proxy automatically records accesses to
|
|
58
|
+
* FIELD_STATE_PROPS (value, label, isVisible, error…) and getSnapshot
|
|
59
|
+
* checks the versions of only those nodes.
|
|
60
60
|
*
|
|
61
|
-
*
|
|
62
|
-
* (fallback).
|
|
61
|
+
* On the first render the tracked set is empty → the global version is used
|
|
62
|
+
* (fallback). After the first render tracking is fully targeted.
|
|
63
63
|
*
|
|
64
|
-
* @param input — ProxyStore
|
|
65
|
-
*
|
|
66
|
-
* @returns tracking proxy —
|
|
64
|
+
* @param input — a ProxyStore created via new Palistor(), OR a tracking-proxy
|
|
65
|
+
* subtree (from another useForm's prop)
|
|
66
|
+
* @returns a tracking proxy — typed by the config (or subtree)
|
|
67
67
|
*/
|
|
68
68
|
/**
|
|
69
|
-
*
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
* подскажет, что делать.
|
|
69
|
+
* An "error" type TypeScript surfaces in diagnostics when a raw `store.proxy`
|
|
70
|
+
* or its subtree is passed into `useForm`. The interface name is deliberately
|
|
71
|
+
* long and descriptive — it appears in the error text and explains the fix.
|
|
73
72
|
*
|
|
74
73
|
* @see {@link RawStoreProxyMarker}
|
|
75
74
|
*/
|
|
@@ -77,9 +76,9 @@ export interface _PALISTOR_ERROR__do_not_pass_store_proxy_subtree_to_useForm__ca
|
|
|
77
76
|
readonly _palistorError: "useForm received a raw store.proxy subtree. Use: const form = useForm(store); then drill into form.subtree (a tracking proxy). See useForm-raw-proxy-pitfall.md.";
|
|
78
77
|
}
|
|
79
78
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
* `useForm(store.proxy.subtree)`
|
|
79
|
+
* Turns T into the error type when T carries {@link RawStoreProxyMarker}.
|
|
80
|
+
* Applied to the subtree overload's parameter to make
|
|
81
|
+
* `useForm(store.proxy.subtree)` a compile-time error.
|
|
83
82
|
*/
|
|
84
83
|
type ForbidRawStoreProxy<T> = T extends RawStoreProxyMarker ? _PALISTOR_ERROR__do_not_pass_store_proxy_subtree_to_useForm__call_useForm_store_first : T;
|
|
85
84
|
export declare function useForm<T extends Record<string, any>>(input: PalistorRef<T>): PalistorEntityProxy<T>;
|
|
@@ -90,18 +89,18 @@ export declare function useForm<T extends Record<string, any> & {
|
|
|
90
89
|
export declare function useForm<T extends GroupProxyNode>(input: ForbidRawStoreProxy<T>): T;
|
|
91
90
|
export declare function useForm<TConfig extends Record<string, any>, TMapping extends FieldMapping = {}>(input: ProxyStore<TConfig, TMapping>): ConfigProxy<TConfig, TMapping>;
|
|
92
91
|
/**
|
|
93
|
-
*
|
|
92
|
+
* Overload: bind an entity to a template for display/editing.
|
|
94
93
|
*
|
|
95
|
-
* @param entity — EntityProjectionProxy
|
|
96
|
-
* @param templateSelector —
|
|
97
|
-
* @returns tracking proxy entity
|
|
94
|
+
* @param entity — an EntityProjectionProxy from list.items or list.getById
|
|
95
|
+
* @param templateSelector — template selector function: (store) => store.editUserForm
|
|
96
|
+
* @returns a tracking proxy of the entity through the template (template fields + entity values)
|
|
98
97
|
*
|
|
99
98
|
* Lifecycle:
|
|
100
99
|
* - mount: entityRegistry.bind(entityId, templateNode)
|
|
101
100
|
* - unmount: entityRegistry.unbind(entityId, templateNode)
|
|
102
101
|
*
|
|
103
|
-
* Resolved cache
|
|
104
|
-
* `isResolved`
|
|
102
|
+
* Resolved cache: when the same entity+template is opened again,
|
|
103
|
+
* `isResolved` returns true → the resolve is skipped.
|
|
105
104
|
*/
|
|
106
105
|
export declare function useForm(entity: object, templateSelector: (store: any) => any): any;
|
|
107
106
|
export {};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../react/useForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAGH,OAAO,KAAK,EAAE,UAAU,EAAE,WAAW,EAAE,cAAc,EAAE,mBAAmB,EAAE,MAAM,gBAAgB,CAAC;AACnG,OAAO,KAAK,EAAE,WAAW,EAAE,YAAY,EAAE,QAAQ,EAAE,mBAAmB,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AA2CnH;;;;;;;;;;;;;;GAcG;AACH
|
|
1
|
+
{"version":3,"file":"useForm.d.ts","sourceRoot":"","sources":["../../react/useForm.ts"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S,YAAY,GAAG,EAAE,EAElC,KAAK,EAAE,UAAU,CAAC,OAAO,EAAE,QAAQ,CAAC,GACnC,WAAW,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC;AAElC;;;;;;;;;;;;;GAaG;AACH,wBAAgB,OAAO,CACrB,MAAM,EAAE,MAAM,EACd,gBAAgB,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,GAAG,GACpC,GAAG,CAAC"}
|
package/dist/react/useForm.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useForm — React
|
|
2
|
+
* useForm — the React hook that connects a component to a ProxyStore.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* Returns a reactive proxy. Dot access to fields IS the subscription: the
|
|
5
|
+
* component re-renders only when a field it actually read changes.
|
|
6
6
|
*
|
|
7
7
|
* @example
|
|
8
8
|
* ```tsx
|
|
@@ -22,60 +22,60 @@
|
|
|
22
22
|
* );
|
|
23
23
|
* }
|
|
24
24
|
*
|
|
25
|
-
* //
|
|
25
|
+
* // Child component with its own useForm for an independent subscription:
|
|
26
26
|
* function PassportSection({ passport }) {
|
|
27
|
-
* const p = useForm(passport); // ←
|
|
27
|
+
* const p = useForm(passport); // ← accepts a subtree!
|
|
28
28
|
* if (!p.isVisible) return null;
|
|
29
29
|
* return <NumberField field={p.number} />;
|
|
30
30
|
* }
|
|
31
31
|
* ```
|
|
32
32
|
*
|
|
33
|
-
*
|
|
34
|
-
* 1. useSyncExternalStore
|
|
35
|
-
* 2. getSnapshot
|
|
36
|
-
* re-render
|
|
37
|
-
* 3. store.proxy
|
|
38
|
-
* config
|
|
39
|
-
* 4.
|
|
33
|
+
* How it works:
|
|
34
|
+
* 1. useSyncExternalStore subscribes to global store changes.
|
|
35
|
+
* 2. getSnapshot compares versions of only the nodes that were read →
|
|
36
|
+
* a re-render happens only when something that was read changed.
|
|
37
|
+
* 3. store.proxy is wrapped in a tracking proxy. Every GET records the
|
|
38
|
+
* config node into a tracked set. getSnapshot checks only those nodes.
|
|
39
|
+
* 4. A write `form.email.value = "X"` → store.proxy.email.value = "X" →
|
|
40
40
|
* SET trap → formatter → validate → recompute → notify → re-render
|
|
41
|
-
* (
|
|
41
|
+
* (only of components that read the changed nodes).
|
|
42
42
|
*
|
|
43
|
-
*
|
|
44
|
-
* - useForm(store) —
|
|
45
|
-
* - useForm(proxySubtree) —
|
|
46
|
-
*
|
|
47
|
-
* - useForm(entityProxy, templateSelector) —
|
|
48
|
-
* entityProxy
|
|
49
|
-
*
|
|
43
|
+
* Overloads:
|
|
44
|
+
* - useForm(store) — the main form, pass the ProxyStore
|
|
45
|
+
* - useForm(proxySubtree) — accepts a tracking-proxy subtree (from a prop),
|
|
46
|
+
* creating an **independent** tracking scope for this component
|
|
47
|
+
* - useForm(entityProxy, templateSelector) — binds an entity to a template.
|
|
48
|
+
* entityProxy comes from list.items/list.getById. templateSelector = (s) => s.editForm.
|
|
49
|
+
* Calls entityRegistry.bind on mount, unbind on unmount.
|
|
50
50
|
*/
|
|
51
51
|
import { useSyncExternalStore, useCallback, useRef, useMemo, useEffect } from "react";
|
|
52
52
|
import { createTrackingProxy, unwrapTrackingProxy, } from "./createTrackingProxy";
|
|
53
53
|
import { ENTITY_ID, STORE_REF, CONFIG_NODE } from "../store/constants";
|
|
54
54
|
import { buildEntityProjectionProxy } from "../store/buildProxy/buildEntityProjectionProxy";
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
57
|
-
*
|
|
56
|
+
* Extract the store and sourceProxy from the useForm argument.
|
|
57
|
+
* Supports a ProxyStore directly and tracking-proxy subtrees.
|
|
58
58
|
*/
|
|
59
59
|
function resolveInput(input) {
|
|
60
|
-
//
|
|
60
|
+
// A tracking proxy (a subtree passed as a prop)
|
|
61
61
|
const unwrapped = unwrapTrackingProxy(input);
|
|
62
62
|
if (unwrapped)
|
|
63
63
|
return unwrapped;
|
|
64
|
-
//
|
|
65
|
-
//
|
|
66
|
-
//
|
|
64
|
+
// A raw GroupProxyNode from store.proxy.someGroup is NOT acceptable.
|
|
65
|
+
// The user must pass either a ProxyStore (new Palistor()) or a tracking
|
|
66
|
+
// proxy (from a parent useForm's prop).
|
|
67
67
|
if (input != null && typeof input === "object" && input[CONFIG_NODE]) {
|
|
68
|
-
throw new Error("useForm:
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
" 1.
|
|
68
|
+
throw new Error("useForm: received a raw store proxy node (store.proxy.someGroup). " +
|
|
69
|
+
"This is not allowed.\n\n" +
|
|
70
|
+
"The correct way:\n" +
|
|
71
|
+
" 1. Get a tracking proxy via useForm(store):\n" +
|
|
72
72
|
" const form = useForm(store);\n" +
|
|
73
|
-
" 2.
|
|
73
|
+
" 2. Pass the subtree as a prop to the child component:\n" +
|
|
74
74
|
" <Child section={form.someGroup} />\n" +
|
|
75
|
-
" 3.
|
|
76
|
-
"
|
|
75
|
+
" 3. In the child component call useForm(props.section).\n\n" +
|
|
76
|
+
"Never pass store.proxy or its child nodes directly into useForm.");
|
|
77
77
|
}
|
|
78
|
-
//
|
|
78
|
+
// Otherwise it's a ProxyStore — use store.proxy as the sourceProxy
|
|
79
79
|
return { store: input, sourceProxy: input.proxy };
|
|
80
80
|
}
|
|
81
81
|
export function useForm(input, templateSelector) {
|
|
@@ -114,7 +114,7 @@ export function useForm(input, templateSelector) {
|
|
|
114
114
|
const sourceProxy = isEntityMode
|
|
115
115
|
? entityMetaRef.current.entityProxy
|
|
116
116
|
: stdSourceProxy;
|
|
117
|
-
// ─── Tracking state (per-component,
|
|
117
|
+
// ─── Tracking state (per-component, stable refs) ─────────────────────────
|
|
118
118
|
const refsRef = useRef(null);
|
|
119
119
|
if (!refsRef.current) {
|
|
120
120
|
refsRef.current = {
|
|
@@ -138,16 +138,16 @@ export function useForm(input, templateSelector) {
|
|
|
138
138
|
const meta = entityMetaRef.current;
|
|
139
139
|
if (!meta)
|
|
140
140
|
return;
|
|
141
|
-
//
|
|
141
|
+
// Bind the entity to the template — register that this template is currently displaying it
|
|
142
142
|
meta.entityStore.entityRegistry.bind(meta.entityId, meta.templateNode);
|
|
143
|
-
//
|
|
143
|
+
// Run the template-level resolve unless it already ran for this entity+template pair
|
|
144
144
|
if (!meta.entityStore.entityRegistry.isResolved(meta.entityId, meta.templateNode)) {
|
|
145
145
|
meta.entityStore.resolveManager.triggerEntityTemplateResolve(meta.entityId, meta.templateNode, meta.entityProxy);
|
|
146
146
|
}
|
|
147
147
|
// Per-field resolves are now triggered lazily from the entity leaf proxy GET trap
|
|
148
148
|
// (on first access to .value or .loading) — no eager loop needed here.
|
|
149
149
|
return () => {
|
|
150
|
-
//
|
|
150
|
+
// On unmount unbind the entity from the template — it no longer displays this entity
|
|
151
151
|
meta.entityStore.entityRegistry.unbind(meta.entityId, meta.templateNode);
|
|
152
152
|
};
|
|
153
153
|
}, []); // bind once on mount, unbind on unmount
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useForm.js","sourceRoot":"","sources":["../../react/useForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAGtF,OAAO,EACL,mBAAmB,EACnB,mBAAmB,GAEpB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,0BAA0B,EAAE,MAAM,gDAAgD,CAAC;AAI5F;;;GAGG;AACH,SAAS,YAAY,CACnB,KAAgC;IAEhC,
|
|
1
|
+
{"version":3,"file":"useForm.js","sourceRoot":"","sources":["../../react/useForm.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AAEH,OAAO,EAAE,o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AE,CAAC;YACzC,KAAK,MAAM,IAAI,IAAI,QAAQ,EAAE,CAAC;gBAC5B,YAAY,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,CAAC,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC;YACrD,CAAC;QACH,CAAC;QAED,OAAO,WAAW,CAAC,OAAO,CAAC;IAC7B,CAAC,EAAE,CAAC,KAAK,EAAE,IAAI,CAAC,CAAC,CAAC;IAElB,oBAAoB,CAAC,SAAS,EAAE,WAAW,EAAE,WAAW,CAAC,CAAC;IAE1D,OAAO,aAAa,CAAC;AACvB,CAAC"}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* usePersist — React
|
|
2
|
+
* usePersist — React hook wiring persistence into a ProxyStore.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* (
|
|
4
|
+
* Registers the driver and key on mount, disconnects on unmount.
|
|
5
|
+
* Lets you provide a key that is only known in the React context
|
|
6
|
+
* (e.g. from the router or props).
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```tsx
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* import { paymentStore } from "./config/appConfig";
|
|
13
13
|
*
|
|
14
14
|
* function PaymentPage({ orderId }: { orderId: string }) {
|
|
15
|
-
* //
|
|
15
|
+
* // The key depends on orderId — known only inside React
|
|
16
16
|
* usePersist(paymentStore, {
|
|
17
17
|
* key: `payment-${orderId}`,
|
|
18
18
|
* driver: localStorageDriver,
|
|
@@ -27,19 +27,19 @@
|
|
|
27
27
|
import type { ProxyStore } from "../store/store";
|
|
28
28
|
import type { PersistOptions } from "../store/persist/types";
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
30
|
+
* Wires persistence into a ProxyStore from a React component.
|
|
31
31
|
*
|
|
32
|
-
*
|
|
33
|
-
* -
|
|
32
|
+
* On mount:
|
|
33
|
+
* - Calls `store.persist.enable(options)` — hydration + auto-save.
|
|
34
34
|
*
|
|
35
|
-
*
|
|
36
|
-
* -
|
|
37
|
-
* -
|
|
35
|
+
* On unmount:
|
|
36
|
+
* - Calls `store.persist.flush()` (final save).
|
|
37
|
+
* - Calls `store.persist.disable()` — unsubscribes.
|
|
38
38
|
*
|
|
39
|
-
*
|
|
39
|
+
* Reconnects when the key changes.
|
|
40
40
|
*
|
|
41
|
-
* @param store — ProxyStore
|
|
42
|
-
* @param options —
|
|
41
|
+
* @param store — a ProxyStore created via new Palistor()
|
|
42
|
+
* @param options — persistence options (key, driver, debounce, …)
|
|
43
43
|
*/
|
|
44
44
|
export declare function usePersist<TConfig extends Record<string, any>>(store: ProxyStore<TConfig>, options: PersistOptions): void;
|
|
45
45
|
//# sourceMappingURL=usePersist.d.ts.map
|
package/dist/react/usePersist.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* usePersist — React
|
|
2
|
+
* usePersist — React hook wiring persistence into a ProxyStore.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* (
|
|
4
|
+
* Registers the driver and key on mount, disconnects on unmount.
|
|
5
|
+
* Lets you provide a key that is only known in the React context
|
|
6
|
+
* (e.g. from the router or props).
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```tsx
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
* import { paymentStore } from "./config/appConfig";
|
|
13
13
|
*
|
|
14
14
|
* function PaymentPage({ orderId }: { orderId: string }) {
|
|
15
|
-
* //
|
|
15
|
+
* // The key depends on orderId — known only inside React
|
|
16
16
|
* usePersist(paymentStore, {
|
|
17
17
|
* key: `payment-${orderId}`,
|
|
18
18
|
* driver: localStorageDriver,
|
|
@@ -26,34 +26,34 @@
|
|
|
26
26
|
*/
|
|
27
27
|
import { useEffect, useRef } from "react";
|
|
28
28
|
/**
|
|
29
|
-
*
|
|
29
|
+
* Wires persistence into a ProxyStore from a React component.
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
* -
|
|
31
|
+
* On mount:
|
|
32
|
+
* - Calls `store.persist.enable(options)` — hydration + auto-save.
|
|
33
33
|
*
|
|
34
|
-
*
|
|
35
|
-
* -
|
|
36
|
-
* -
|
|
34
|
+
* On unmount:
|
|
35
|
+
* - Calls `store.persist.flush()` (final save).
|
|
36
|
+
* - Calls `store.persist.disable()` — unsubscribes.
|
|
37
37
|
*
|
|
38
|
-
*
|
|
38
|
+
* Reconnects when the key changes.
|
|
39
39
|
*
|
|
40
|
-
* @param store — ProxyStore
|
|
41
|
-
* @param options —
|
|
40
|
+
* @param store — a ProxyStore created via new Palistor()
|
|
41
|
+
* @param options — persistence options (key, driver, debounce, …)
|
|
42
42
|
*/
|
|
43
43
|
export function usePersist(store, options) {
|
|
44
|
-
//
|
|
44
|
+
// Keep options in a ref so the effect isn't recreated on every render
|
|
45
45
|
const optionsRef = useRef(options);
|
|
46
46
|
optionsRef.current = options;
|
|
47
47
|
useEffect(() => {
|
|
48
48
|
const opts = optionsRef.current;
|
|
49
|
-
//
|
|
49
|
+
// Enable persist (hydrate + auto-save)
|
|
50
50
|
store.persist.enable(opts);
|
|
51
51
|
return () => {
|
|
52
|
-
//
|
|
52
|
+
// Final save before unmount
|
|
53
53
|
store.persist.flush();
|
|
54
54
|
store.persist.disable();
|
|
55
55
|
};
|
|
56
|
-
//
|
|
56
|
+
// Reconnect when the store or key changes
|
|
57
57
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
58
58
|
}, [store, options.key, options.driver]);
|
|
59
59
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePersist.js","sourceRoot":"","sources":["../../react/usePersist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAI1C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,UAAU,CACxB,KAA0B,EAC1B,OAAuB;IAEvB,
|
|
1
|
+
{"version":3,"file":"usePersist.js","sourceRoot":"","sources":["../../react/usePersist.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;GAyBG;AAEH,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAI1C;;;;;;;;;;;;;;GAcG;AACH,MAAM,UAAU,UAAU,CACxB,KAA0B,EAC1B,OAAuB;IAEvB,sEAAsE;IACtE,MAAM,UAAU,GAAG,MAAM,CAAC,OAAO,CAAC,CAAC;IACnC,UAAU,CAAC,OAAO,GAAG,OAAO,CAAC;IAE7B,SAAS,CAAC,GAAG,EAAE;QACb,MAAM,IAAI,GAAG,UAAU,CAAC,OAAO,CAAC;QAEhC,uCAAuC;QACvC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC;QAE3B,OAAO,GAAG,EAAE;YACV,4BAA4B;YAC5B,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,CAAC;YACtB,KAAK,CAAC,OAAO,CAAC,OAAO,EAAE,CAAC;QAC1B,CAAC,CAAC;QACF,0CAA0C;QAC1C,uDAAuD;IACzD,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC;AAC3C,CAAC"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useStoreContext —
|
|
2
|
+
* useStoreContext — registers non-reactive context with a ProxyStore.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The context is available in all callbacks (resolve.resolver, onSubmit,
|
|
5
|
+
* onChange, …) via `store.context`. Not part of the form — excluded from
|
|
6
6
|
* getValues(), submit, persist.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Used for global variables (accountId, tenant, …) that requests need but
|
|
9
|
+
* that are not form fields.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```tsx
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
* import { paymentStore } from './config/appConfig';
|
|
15
15
|
*
|
|
16
16
|
* function Layout({ children }: { children: React.ReactNode }) {
|
|
17
|
-
* const accountId = useAccountId(); //
|
|
17
|
+
* const accountId = useAccountId(); // from the auth provider
|
|
18
18
|
* useStoreContext(paymentStore, { accountId });
|
|
19
19
|
* return <>{children}</>;
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
|
-
*
|
|
23
|
+
* In the config:
|
|
24
24
|
* ```ts
|
|
25
25
|
* resolve: {
|
|
26
26
|
* resolver: async (values, store) => {
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import type { ProxyStore } from "../store/store";
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Registers non-reactive context with a ProxyStore.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
36
|
+
* When `ctx` changes — merges the new keys into the existing context.
|
|
37
37
|
*
|
|
38
|
-
* @param store — ProxyStore
|
|
39
|
-
* @param ctx —
|
|
38
|
+
* @param store — a ProxyStore created via new Palistor()
|
|
39
|
+
* @param ctx — an object with arbitrary data (accountId, tenant, …)
|
|
40
40
|
*/
|
|
41
41
|
export declare function useStoreContext<TConfig extends Record<string, any>>(store: ProxyStore<TConfig>, ctx: Record<string, unknown>): void;
|
|
42
42
|
//# sourceMappingURL=useStoreContext.d.ts.map
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useStoreContext —
|
|
2
|
+
* useStoreContext — registers non-reactive context with a ProxyStore.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
4
|
+
* The context is available in all callbacks (resolve.resolver, onSubmit,
|
|
5
|
+
* onChange, …) via `store.context`. Not part of the form — excluded from
|
|
6
6
|
* getValues(), submit, persist.
|
|
7
7
|
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
8
|
+
* Used for global variables (accountId, tenant, …) that requests need but
|
|
9
|
+
* that are not form fields.
|
|
10
10
|
*
|
|
11
11
|
* @example
|
|
12
12
|
* ```tsx
|
|
@@ -14,13 +14,13 @@
|
|
|
14
14
|
* import { paymentStore } from './config/appConfig';
|
|
15
15
|
*
|
|
16
16
|
* function Layout({ children }: { children: React.ReactNode }) {
|
|
17
|
-
* const accountId = useAccountId(); //
|
|
17
|
+
* const accountId = useAccountId(); // from the auth provider
|
|
18
18
|
* useStoreContext(paymentStore, { accountId });
|
|
19
19
|
* return <>{children}</>;
|
|
20
20
|
* }
|
|
21
21
|
* ```
|
|
22
22
|
*
|
|
23
|
-
*
|
|
23
|
+
* In the config:
|
|
24
24
|
* ```ts
|
|
25
25
|
* resolve: {
|
|
26
26
|
* resolver: async (values, store) => {
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
*/
|
|
32
32
|
import { useEffect } from "react";
|
|
33
33
|
/**
|
|
34
|
-
*
|
|
34
|
+
* Registers non-reactive context with a ProxyStore.
|
|
35
35
|
*
|
|
36
|
-
*
|
|
36
|
+
* When `ctx` changes — merges the new keys into the existing context.
|
|
37
37
|
*
|
|
38
|
-
* @param store — ProxyStore
|
|
39
|
-
* @param ctx —
|
|
38
|
+
* @param store — a ProxyStore created via new Palistor()
|
|
39
|
+
* @param ctx — an object with arbitrary data (accountId, tenant, …)
|
|
40
40
|
*/
|
|
41
41
|
export function useStoreContext(store, ctx) {
|
|
42
42
|
useEffect(() => {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* useTranslator —
|
|
2
|
+
* useTranslator — registers a translation function with a ProxyStore.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
4
|
+
* Call it once in a layout/provider. Once registered, every component using
|
|
5
|
+
* useForm automatically receives translated label / placeholder / description
|
|
6
|
+
* (when the config defines them as functions).
|
|
7
7
|
*
|
|
8
8
|
* @example
|
|
9
9
|
* ```tsx
|
|
@@ -18,20 +18,20 @@
|
|
|
18
18
|
* }
|
|
19
19
|
* ```
|
|
20
20
|
*
|
|
21
|
-
*
|
|
22
|
-
* (fallback,
|
|
21
|
+
* Without a translator — label/placeholder return the translation keys as-is
|
|
22
|
+
* (a fallback, convenient for tests and SSR without i18n).
|
|
23
23
|
*/
|
|
24
24
|
import type { ProxyStore } from "../store/store";
|
|
25
25
|
import type { TranslateFn } from "../store/store/types";
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Registers a translation function with a ProxyStore.
|
|
28
28
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
*
|
|
29
|
+
* When `translator` changes (e.g. on a locale switch) —
|
|
30
|
+
* all components subscribed via useForm re-render with
|
|
31
|
+
* up-to-date translations.
|
|
32
32
|
*
|
|
33
|
-
* @param store — ProxyStore
|
|
34
|
-
* @param translator —
|
|
33
|
+
* @param store — a ProxyStore created via new Palistor()
|
|
34
|
+
* @param translator — translation function (next-intl `t`, i18next `t`, …)
|
|
35
35
|
*/
|
|
36
36
|
export declare function useTranslator<TConfig extends Record<string, any>>(store: ProxyStore<TConfig>, translator: TranslateFn): void;
|
|
37
37
|
//# sourceMappingURL=useTranslator.d.ts.map
|