@pisell/materials 6.12.39 → 6.12.41

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/meta.js +1 -1
  5. package/build/lowcode/render/default/view.js +32 -32
  6. package/build/lowcode/view.js +32 -32
  7. package/es/components/PisellSelectionFlow/PisellSelectionFlow.d.ts +7 -0
  8. package/es/components/PisellSelectionFlow/PisellSelectionFlow.js +392 -0
  9. package/es/components/PisellSelectionFlow/compiler.d.ts +12 -0
  10. package/es/components/PisellSelectionFlow/compiler.js +174 -0
  11. package/es/components/PisellSelectionFlow/context.d.ts +9 -0
  12. package/es/components/PisellSelectionFlow/context.js +12 -0
  13. package/es/components/PisellSelectionFlow/hooks/useFlowDraft.js +35 -0
  14. package/es/components/PisellSelectionFlow/hooks/useFlowModuleLifecycle.js +236 -0
  15. package/es/components/PisellSelectionFlow/hooks/useFlowNavigation.js +320 -0
  16. package/es/components/PisellSelectionFlow/index.d.ts +4 -0
  17. package/es/components/PisellSelectionFlow/types.d.ts +179 -0
  18. package/es/components/PisellSelectionFlow/types.js +10 -0
  19. package/es/components/PisellSelectionFlow/utils.js +15 -0
  20. package/es/index.d.ts +13 -9
  21. package/es/index.js +5 -1
  22. package/lib/components/PisellSelectionFlow/PisellSelectionFlow.d.ts +7 -0
  23. package/lib/components/PisellSelectionFlow/PisellSelectionFlow.js +394 -0
  24. package/lib/components/PisellSelectionFlow/compiler.d.ts +12 -0
  25. package/lib/components/PisellSelectionFlow/compiler.js +178 -0
  26. package/lib/components/PisellSelectionFlow/context.d.ts +9 -0
  27. package/lib/components/PisellSelectionFlow/context.js +16 -0
  28. package/lib/components/PisellSelectionFlow/hooks/useFlowDraft.js +36 -0
  29. package/lib/components/PisellSelectionFlow/hooks/useFlowModuleLifecycle.js +237 -0
  30. package/lib/components/PisellSelectionFlow/hooks/useFlowNavigation.js +321 -0
  31. package/lib/components/PisellSelectionFlow/index.d.ts +4 -0
  32. package/lib/components/PisellSelectionFlow/types.d.ts +179 -0
  33. package/lib/components/PisellSelectionFlow/types.js +10 -0
  34. package/lib/components/PisellSelectionFlow/utils.js +18 -0
  35. package/lib/index.d.ts +13 -9
  36. package/lib/index.js +15 -2
  37. package/package.json +1 -1
@@ -0,0 +1,237 @@
1
+ require("../../../_virtual/_rolldown/runtime.js");
2
+ const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
3
+ const require_asyncToGenerator = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
4
+ const require_compiler = require("../compiler.js");
5
+ const require_utils = require("../utils.js");
6
+ let react = require("react");
7
+ //#region src/components/PisellSelectionFlow/hooks/useFlowModuleLifecycle.ts
8
+ /** 负责依赖失效、清理、校正、刷新和异步 latest-wins。 */
9
+ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mountedRef, flowGenerationRef, draftRevisionRef, draftRef, moduleRevisionRef, moduleInitializationRef, moduleDependencyLifecycleRef, pendingModuleChangeRef, compiledStepsRef, moduleStateRef, processDraftChangeRef, commitModuleState, getFreshContext, currentStep, configurationError, compiledSteps, resolvedCurrentStepIndex, draft, moduleState }) => {
10
+ processDraftChangeRef.current = (0, react.useCallback)((change) => {
11
+ const changedFields = new Set(change.changedFields);
12
+ const flowGeneration = flowGenerationRef.current;
13
+ if (!mountedRef.current) return;
14
+ for (const step of compiledStepsRef.current) for (const module of step.modules) {
15
+ if (module.key === change.sourceModuleKey) continue;
16
+ const adapter = require_compiler.resolveFlowModuleAdapter(registry, module.type);
17
+ if (!adapter) continue;
18
+ const dependencyChanged = [...new Set([...adapter.refreshOn || [], ...adapter.hardRequires || []])].some((field) => changedFields.has(field));
19
+ let shouldRefresh = dependencyChanged;
20
+ if (dependencyChanged && adapter.shouldRefresh) try {
21
+ const refreshContext = getFreshContext();
22
+ shouldRefresh = Boolean(refreshContext && adapter.shouldRefresh(refreshContext, change, module));
23
+ } catch (error) {
24
+ const revision = (moduleRevisionRef.current.get(module.key) || 0) + 1;
25
+ moduleRevisionRef.current.set(module.key, revision);
26
+ moduleInitializationRef.current.delete(module.key);
27
+ moduleDependencyLifecycleRef.current.delete(module.key);
28
+ commitModuleState(module.key, {
29
+ status: "error",
30
+ message: require_utils.getSelectionFlowErrorMessage(error),
31
+ error
32
+ });
33
+ continue;
34
+ }
35
+ if (!shouldRefresh) continue;
36
+ const previousPendingChange = pendingModuleChangeRef.current.get(module.key);
37
+ const lifecycleChange = previousPendingChange ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, change), {}, {
38
+ previousDraft: previousPendingChange.previousDraft,
39
+ changedFields: Array.from(new Set([...previousPendingChange.changedFields, ...change.changedFields]))
40
+ }) : change;
41
+ pendingModuleChangeRef.current.set(module.key, lifecycleChange);
42
+ const revision = (moduleRevisionRef.current.get(module.key) || 0) + 1;
43
+ moduleRevisionRef.current.set(module.key, revision);
44
+ commitModuleState(module.key, {
45
+ status: "loading",
46
+ reason: createRuntimeIssue("dependencies-reconciling")
47
+ });
48
+ let dependencyLifecycle;
49
+ const runDependencyLifecycle = () => Promise.resolve().then(require_asyncToGenerator._asyncToGenerator(function* () {
50
+ var _adapter$clearDepende, _adapter$reconcile;
51
+ const buildLifecycleContext = () => {
52
+ const freshContext = getFreshContext();
53
+ const isCurrentLifecycle = () => mountedRef.current && flowGenerationRef.current === flowGeneration && moduleRevisionRef.current.get(module.key) === revision;
54
+ if (!freshContext || !isCurrentLifecycle()) return null;
55
+ return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, freshContext), {}, {
56
+ updateDraft: (update, meta) => {
57
+ if (isCurrentLifecycle()) freshContext.updateDraft(update, meta);
58
+ },
59
+ setModuleState: (moduleKey, state) => {
60
+ if (isCurrentLifecycle()) freshContext.setModuleState(moduleKey, state);
61
+ },
62
+ setModuleStatus: (moduleKey, status, message, error) => {
63
+ if (isCurrentLifecycle()) freshContext.setModuleStatus(moduleKey, status, message, error);
64
+ },
65
+ setModuleData: (moduleKey, value) => {
66
+ if (isCurrentLifecycle()) freshContext.setModuleData(moduleKey, value);
67
+ },
68
+ clearModuleData: (moduleKey) => {
69
+ if (isCurrentLifecycle()) freshContext.clearModuleData(moduleKey);
70
+ }
71
+ });
72
+ };
73
+ const clearContext = buildLifecycleContext();
74
+ if (!clearContext) return false;
75
+ yield (_adapter$clearDepende = adapter.clearDependencies) === null || _adapter$clearDepende === void 0 ? void 0 : _adapter$clearDepende.call(adapter, clearContext, lifecycleChange, module);
76
+ const reconcileContext = buildLifecycleContext();
77
+ if (!reconcileContext) return false;
78
+ yield (_adapter$reconcile = adapter.reconcile) === null || _adapter$reconcile === void 0 ? void 0 : _adapter$reconcile.call(adapter, reconcileContext, lifecycleChange, module);
79
+ if (mountedRef.current && flowGenerationRef.current === flowGeneration && moduleRevisionRef.current.get(module.key) === revision) commitModuleState(module.key, { status: "stale" });
80
+ return true;
81
+ })).catch((error) => {
82
+ if (mountedRef.current && flowGenerationRef.current === flowGeneration && moduleRevisionRef.current.get(module.key) === revision) commitModuleState(module.key, {
83
+ status: "error",
84
+ message: require_utils.getSelectionFlowErrorMessage(error),
85
+ error
86
+ });
87
+ return false;
88
+ });
89
+ const setLifecyclePromise = () => {
90
+ dependencyLifecycle.status = "pending";
91
+ const promise = runDependencyLifecycle();
92
+ dependencyLifecycle.promise = promise;
93
+ promise.then((success) => {
94
+ if (moduleDependencyLifecycleRef.current.get(module.key) !== dependencyLifecycle) return;
95
+ if (success) {
96
+ moduleDependencyLifecycleRef.current.delete(module.key);
97
+ if (pendingModuleChangeRef.current.get(module.key) === lifecycleChange) pendingModuleChangeRef.current.delete(module.key);
98
+ } else dependencyLifecycle.status = "failed";
99
+ });
100
+ return promise;
101
+ };
102
+ dependencyLifecycle = {
103
+ revision,
104
+ status: "pending",
105
+ promise: Promise.resolve(false),
106
+ retry: setLifecyclePromise
107
+ };
108
+ moduleDependencyLifecycleRef.current.set(module.key, dependencyLifecycle);
109
+ setLifecyclePromise();
110
+ }
111
+ }, [
112
+ commitModuleState,
113
+ createRuntimeIssue,
114
+ getFreshContext,
115
+ registry
116
+ ]);
117
+ const ensureModuleReady = (0, react.useCallback)((module) => {
118
+ if (!mountedRef.current) return Promise.resolve(false);
119
+ const revision = moduleRevisionRef.current.get(module.key) || 0;
120
+ const flowGeneration = flowGenerationRef.current;
121
+ const existing = moduleInitializationRef.current.get(module.key);
122
+ if ((existing === null || existing === void 0 ? void 0 : existing.revision) === revision) return existing.promise;
123
+ const currentState = moduleStateRef.current[module.key];
124
+ const pendingDependencyLifecycle = moduleDependencyLifecycleRef.current.get(module.key);
125
+ if ((currentState === null || currentState === void 0 ? void 0 : currentState.status) === "ready" && (pendingDependencyLifecycle === null || pendingDependencyLifecycle === void 0 ? void 0 : pendingDependencyLifecycle.revision) !== revision) return Promise.resolve(true);
126
+ const isCurrentRun = () => mountedRef.current && flowGenerationRef.current === flowGeneration && (moduleRevisionRef.current.get(module.key) || 0) === revision;
127
+ const getRunContext = () => {
128
+ const freshContext = getFreshContext();
129
+ if (!freshContext || !isCurrentRun()) return null;
130
+ return require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, freshContext), {}, {
131
+ updateDraft: (update, meta) => {
132
+ if (isCurrentRun()) freshContext.updateDraft(update, meta);
133
+ },
134
+ setModuleState: (moduleKey, state) => {
135
+ if (isCurrentRun()) freshContext.setModuleState(moduleKey, state);
136
+ },
137
+ setModuleStatus: (moduleKey, status, message, error) => {
138
+ if (isCurrentRun()) freshContext.setModuleStatus(moduleKey, status, message, error);
139
+ },
140
+ setModuleData: (moduleKey, value) => {
141
+ if (isCurrentRun()) freshContext.setModuleData(moduleKey, value);
142
+ },
143
+ clearModuleData: (moduleKey) => {
144
+ if (isCurrentRun()) freshContext.clearModuleData(moduleKey);
145
+ }
146
+ });
147
+ };
148
+ const run = require_asyncToGenerator._asyncToGenerator(function* () {
149
+ var _adapter$hardRequires;
150
+ const adapter = require_compiler.resolveFlowModuleAdapter(registry, module.type);
151
+ if (!adapter) return false;
152
+ const dependencyLifecycle = moduleDependencyLifecycleRef.current.get(module.key);
153
+ if ((dependencyLifecycle === null || dependencyLifecycle === void 0 ? void 0 : dependencyLifecycle.revision) === revision) {
154
+ if (!(dependencyLifecycle.status === "failed" ? yield dependencyLifecycle.retry() : yield dependencyLifecycle.promise) || !isCurrentRun()) return false;
155
+ }
156
+ let context = getRunContext();
157
+ if (!context) return false;
158
+ const missingField = (_adapter$hardRequires = adapter.hardRequires) === null || _adapter$hardRequires === void 0 ? void 0 : _adapter$hardRequires.find((field) => !require_compiler.hasSelectionDraftFieldValue(draftAdapter, draftRef.current, field));
159
+ if (missingField) {
160
+ if (isCurrentRun()) commitModuleState(module.key, {
161
+ status: "stale",
162
+ reason: createRuntimeIssue("waiting-field", { field: missingField })
163
+ });
164
+ return false;
165
+ }
166
+ try {
167
+ var _await$adapter$canIni, _adapter$canInitializ, _moduleStateRef$curre2;
168
+ const canInitialize = (_await$adapter$canIni = yield (_adapter$canInitializ = adapter.canInitialize) === null || _adapter$canInitializ === void 0 ? void 0 : _adapter$canInitializ.call(adapter, context, module)) !== null && _await$adapter$canIni !== void 0 ? _await$adapter$canIni : true;
169
+ if (!isCurrentRun()) return false;
170
+ if (!canInitialize) {
171
+ commitModuleState(module.key, {
172
+ status: "stale",
173
+ reason: createRuntimeIssue("prerequisites-not-ready")
174
+ });
175
+ return false;
176
+ }
177
+ do {
178
+ var _adapter$refresh, _moduleStateRef$curre;
179
+ commitModuleState(module.key, { status: "loading" });
180
+ context = getRunContext();
181
+ if (!context || !isCurrentRun()) return false;
182
+ yield (_adapter$refresh = adapter.refresh) === null || _adapter$refresh === void 0 ? void 0 : _adapter$refresh.call(adapter, context, module);
183
+ if (!isCurrentRun()) return false;
184
+ if (((_moduleStateRef$curre = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre === void 0 ? void 0 : _moduleStateRef$curre.status) === "error") return false;
185
+ } while (((_moduleStateRef$curre2 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre2 === void 0 ? void 0 : _moduleStateRef$curre2.status) === "stale");
186
+ commitModuleState(module.key, { status: "ready" });
187
+ return true;
188
+ } catch (error) {
189
+ if (isCurrentRun()) commitModuleState(module.key, {
190
+ status: "error",
191
+ message: require_utils.getSelectionFlowErrorMessage(error),
192
+ error
193
+ });
194
+ return false;
195
+ }
196
+ })();
197
+ const initialization = {
198
+ revision,
199
+ promise: run
200
+ };
201
+ moduleInitializationRef.current.set(module.key, initialization);
202
+ run.finally(() => {
203
+ if (moduleInitializationRef.current.get(module.key) === initialization) moduleInitializationRef.current.delete(module.key);
204
+ });
205
+ return run;
206
+ }, [
207
+ commitModuleState,
208
+ createRuntimeIssue,
209
+ draftAdapter,
210
+ getFreshContext,
211
+ registry
212
+ ]);
213
+ (0, react.useEffect)(() => {
214
+ if (!currentStep || configurationError) return;
215
+ const backgroundModules = compiledSteps.flatMap((step) => step.modules).filter((module) => {
216
+ const adapter = require_compiler.resolveFlowModuleAdapter(registry, module.type);
217
+ return (adapter === null || adapter === void 0 ? void 0 : adapter.initializeWhileInactive) && module.stepIndex < resolvedCurrentStepIndex;
218
+ });
219
+ for (const module of [...currentStep.modules, ...backgroundModules]) {
220
+ var _moduleStateRef$curre3;
221
+ const status = ((_moduleStateRef$curre3 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre3 === void 0 ? void 0 : _moduleStateRef$curre3.status) || "idle";
222
+ if (status === "idle" || status === "stale") ensureModuleReady(module);
223
+ }
224
+ }, [
225
+ compiledSteps,
226
+ configurationError,
227
+ currentStep,
228
+ draft,
229
+ ensureModuleReady,
230
+ moduleState,
231
+ registry,
232
+ resolvedCurrentStepIndex
233
+ ]);
234
+ return { ensureModuleReady };
235
+ };
236
+ //#endregion
237
+ exports.useFlowModuleLifecycle = useFlowModuleLifecycle;
@@ -0,0 +1,321 @@
1
+ require("../../../_virtual/_rolldown/runtime.js");
2
+ const require_objectSpread2 = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
3
+ const require_asyncToGenerator = require("../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
4
+ const require_compiler = require("../compiler.js");
5
+ const require_utils = require("../utils.js");
6
+ let react = require("react");
7
+ //#region src/components/PisellSelectionFlow/hooks/useFlowNavigation.ts
8
+ /** 导航、校验与提交门禁独立于模块加载生命周期。 */
9
+ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mountedRef, moduleStateRef, moduleRevisionRef, draftRevisionRef, flowGenerationRef, moduleHandlesRef, configurationErrorRef, compiledStepsRef, currentStepIndexRef, currentStepKeyRef, validatedCompletionRef, navigationRevisionRef, transitionPendingRef, completedRef, completionPromiseRef, isCompletingRef, draftRef, onCompleteRef, ensureModuleReady, commitModuleState, getFreshContext, onValidationFailed, setCurrentStepIndex, setCompletionError, setCompletionReason, setIsCompleting }) => {
10
+ const validateModule = (0, react.useCallback)(function() {
11
+ var _ref = require_asyncToGenerator._asyncToGenerator(function* (module) {
12
+ const adapter = require_compiler.resolveFlowModuleAdapter(registry, module.type);
13
+ if (!adapter || !mountedRef.current) return false;
14
+ const ready = yield ensureModuleReady(module);
15
+ if (!mountedRef.current || !ready) {
16
+ const state = moduleStateRef.current[module.key];
17
+ onValidationFailed === null || onValidationFailed === void 0 || onValidationFailed(module, {
18
+ message: state === null || state === void 0 ? void 0 : state.message,
19
+ reason: state === null || state === void 0 ? void 0 : state.reason
20
+ });
21
+ return false;
22
+ }
23
+ const validationRevision = moduleRevisionRef.current.get(module.key) || 0;
24
+ const validationDraftRevision = draftRevisionRef.current;
25
+ const validationGeneration = flowGenerationRef.current;
26
+ const isCurrentValidationRun = () => mountedRef.current && flowGenerationRef.current === validationGeneration && (moduleRevisionRef.current.get(module.key) || 0) === validationRevision;
27
+ const isCurrentValidation = () => isCurrentValidationRun() && draftRevisionRef.current === validationDraftRevision;
28
+ commitModuleState(module.key, { status: "loading" });
29
+ try {
30
+ var _handle$validate;
31
+ const context = getFreshContext();
32
+ if (!context) return false;
33
+ const validationContext = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, context), {}, {
34
+ updateDraft: (update, meta) => {
35
+ if (isCurrentValidation()) context.updateDraft(update, meta);
36
+ },
37
+ setModuleState: (moduleKey, state) => {
38
+ if (isCurrentValidation()) context.setModuleState(moduleKey, state);
39
+ },
40
+ setModuleStatus: (moduleKey, status, message, error) => {
41
+ if (isCurrentValidation()) context.setModuleStatus(moduleKey, status, message, error);
42
+ },
43
+ setModuleData: (moduleKey, value) => {
44
+ if (isCurrentValidation()) context.setModuleData(moduleKey, value);
45
+ },
46
+ clearModuleData: (moduleKey) => {
47
+ if (isCurrentValidation()) context.clearModuleData(moduleKey);
48
+ }
49
+ });
50
+ const handle = moduleHandlesRef.current.get(module.key) || null;
51
+ const result = require_utils.normalizeFlowValidationResult(adapter.validate ? yield adapter.validate(validationContext, handle, module) : yield handle === null || handle === void 0 || (_handle$validate = handle.validate) === null || _handle$validate === void 0 ? void 0 : _handle$validate.call(handle));
52
+ if (!isCurrentValidation()) {
53
+ if (isCurrentValidationRun()) commitModuleState(module.key, {
54
+ status: "stale",
55
+ reason: createRuntimeIssue("selection-changed-validation")
56
+ });
57
+ return false;
58
+ }
59
+ if (!result.valid) {
60
+ const fallbackReason = result.message ? void 0 : createRuntimeIssue("module-validation-failed");
61
+ commitModuleState(module.key, {
62
+ status: "error",
63
+ message: result.message,
64
+ reason: fallbackReason
65
+ });
66
+ onValidationFailed === null || onValidationFailed === void 0 || onValidationFailed(module, {
67
+ message: result.message,
68
+ reason: fallbackReason
69
+ });
70
+ return false;
71
+ }
72
+ commitModuleState(module.key, { status: "ready" });
73
+ return true;
74
+ } catch (error) {
75
+ const message = require_utils.getSelectionFlowErrorMessage(error);
76
+ if (isCurrentValidation()) {
77
+ commitModuleState(module.key, {
78
+ status: "error",
79
+ message,
80
+ error
81
+ });
82
+ onValidationFailed === null || onValidationFailed === void 0 || onValidationFailed(module, { message });
83
+ } else if (isCurrentValidationRun()) commitModuleState(module.key, {
84
+ status: "stale",
85
+ reason: createRuntimeIssue("selection-changed-validation")
86
+ });
87
+ return false;
88
+ }
89
+ });
90
+ return function(_x) {
91
+ return _ref.apply(this, arguments);
92
+ };
93
+ }(), [
94
+ commitModuleState,
95
+ ensureModuleReady,
96
+ createRuntimeIssue,
97
+ getFreshContext,
98
+ onValidationFailed,
99
+ registry
100
+ ]);
101
+ const validateCurrentStep = (0, react.useCallback)(require_asyncToGenerator._asyncToGenerator(function* () {
102
+ if (configurationErrorRef.current) return false;
103
+ const step = compiledStepsRef.current[currentStepIndexRef.current];
104
+ if (!step) return false;
105
+ for (const module of step.modules) if (!(yield validateModule(module))) return false;
106
+ return true;
107
+ }), [validateModule]);
108
+ const runBeforeLeaveForCurrentStep = (0, react.useCallback)(require_asyncToGenerator._asyncToGenerator(function* () {
109
+ if (configurationErrorRef.current) return false;
110
+ const stepIndex = currentStepIndexRef.current;
111
+ const step = compiledStepsRef.current[stepIndex];
112
+ if (!step) return false;
113
+ for (const module of step.modules) {
114
+ const adapter = require_compiler.resolveFlowModuleAdapter(registry, module.type);
115
+ const handle = moduleHandlesRef.current.get(module.key) || null;
116
+ if (!((adapter === null || adapter === void 0 ? void 0 : adapter.beforeLeave) || (handle === null || handle === void 0 ? void 0 : handle.beforeLeave))) continue;
117
+ const draftRevision = draftRevisionRef.current;
118
+ const moduleRevision = moduleRevisionRef.current.get(module.key) || 0;
119
+ try {
120
+ var _handle$beforeLeave, _compiledStepsRef$cur;
121
+ const context = getFreshContext();
122
+ if (!context) return false;
123
+ const result = require_utils.normalizeFlowBeforeLeaveResult((adapter === null || adapter === void 0 ? void 0 : adapter.beforeLeave) ? yield adapter.beforeLeave(context, handle, module) : yield handle === null || handle === void 0 || (_handle$beforeLeave = handle.beforeLeave) === null || _handle$beforeLeave === void 0 ? void 0 : _handle$beforeLeave.call(handle));
124
+ if (!mountedRef.current || currentStepIndexRef.current !== stepIndex || ((_compiledStepsRef$cur = compiledStepsRef.current[stepIndex]) === null || _compiledStepsRef$cur === void 0 ? void 0 : _compiledStepsRef$cur.key) !== step.key || draftRevisionRef.current !== draftRevision || (moduleRevisionRef.current.get(module.key) || 0) !== moduleRevision) {
125
+ commitModuleState(module.key, {
126
+ status: "stale",
127
+ reason: createRuntimeIssue("selection-changed-confirmation")
128
+ });
129
+ onValidationFailed === null || onValidationFailed === void 0 || onValidationFailed(module, { reason: createRuntimeIssue("selection-changed-confirmation") });
130
+ return false;
131
+ }
132
+ if (!result.allowed) {
133
+ if (result.message) {
134
+ commitModuleState(module.key, {
135
+ status: "error",
136
+ message: result.message
137
+ });
138
+ onValidationFailed === null || onValidationFailed === void 0 || onValidationFailed(module, { message: result.message });
139
+ }
140
+ return false;
141
+ }
142
+ } catch (error) {
143
+ const message = require_utils.getSelectionFlowErrorMessage(error);
144
+ commitModuleState(module.key, {
145
+ status: "error",
146
+ message,
147
+ error
148
+ });
149
+ onValidationFailed === null || onValidationFailed === void 0 || onValidationFailed(module, { message });
150
+ return false;
151
+ }
152
+ }
153
+ return true;
154
+ }), [
155
+ commitModuleState,
156
+ createRuntimeIssue,
157
+ getFreshContext,
158
+ onValidationFailed,
159
+ registry
160
+ ]);
161
+ const validateFlowForCompletion = (0, react.useCallback)(require_asyncToGenerator._asyncToGenerator(function* () {
162
+ validatedCompletionRef.current = null;
163
+ if (configurationErrorRef.current) return false;
164
+ const currentIndex = currentStepIndexRef.current;
165
+ const allSteps = compiledStepsRef.current;
166
+ const compiledFingerprint = require_utils.getCompiledStepsFingerprint(allSteps);
167
+ const revisionFingerprint = allSteps.flatMap((step) => step.modules).map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|");
168
+ const draftRevision = draftRevisionRef.current;
169
+ for (const step of allSteps) {
170
+ if (step.index >= currentIndex) break;
171
+ for (const module of step.modules) {
172
+ const state = moduleStateRef.current[module.key];
173
+ if ((state === null || state === void 0 ? void 0 : state.status) !== "ready") {
174
+ currentStepIndexRef.current = step.index;
175
+ currentStepKeyRef.current = step.key;
176
+ setCurrentStepIndex(step.index);
177
+ onValidationFailed === null || onValidationFailed === void 0 || onValidationFailed(module, {
178
+ message: state === null || state === void 0 ? void 0 : state.message,
179
+ reason: (state === null || state === void 0 ? void 0 : state.reason) || createRuntimeIssue("previous-step-review")
180
+ });
181
+ return false;
182
+ }
183
+ }
184
+ }
185
+ if (!(yield validateCurrentStep())) return false;
186
+ if (configurationErrorRef.current) return false;
187
+ const latestSteps = compiledStepsRef.current;
188
+ const latestCompiledFingerprint = require_utils.getCompiledStepsFingerprint(latestSteps);
189
+ const latestRevisionFingerprint = latestSteps.flatMap((step) => step.modules).map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|");
190
+ if (compiledFingerprint !== latestCompiledFingerprint || revisionFingerprint !== latestRevisionFingerprint || draftRevision !== draftRevisionRef.current) {
191
+ const targetStep = latestSteps.find((step) => step.modules.some((module) => {
192
+ var _moduleStateRef$curre;
193
+ return ((_moduleStateRef$curre = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre === void 0 ? void 0 : _moduleStateRef$curre.status) !== "ready";
194
+ })) || latestSteps[0];
195
+ const targetModule = targetStep === null || targetStep === void 0 ? void 0 : targetStep.modules[0];
196
+ if (targetStep && targetModule) {
197
+ currentStepIndexRef.current = targetStep.index;
198
+ currentStepKeyRef.current = targetStep.key;
199
+ setCurrentStepIndex(targetStep.index);
200
+ onValidationFailed === null || onValidationFailed === void 0 || onValidationFailed(targetModule, { reason: createRuntimeIssue("changed-review") });
201
+ }
202
+ return false;
203
+ }
204
+ for (const step of latestSteps) for (const module of step.modules) {
205
+ const state = moduleStateRef.current[module.key];
206
+ if ((state === null || state === void 0 ? void 0 : state.status) === "ready") continue;
207
+ currentStepIndexRef.current = step.index;
208
+ currentStepKeyRef.current = step.key;
209
+ setCurrentStepIndex(step.index);
210
+ onValidationFailed === null || onValidationFailed === void 0 || onValidationFailed(module, {
211
+ message: state === null || state === void 0 ? void 0 : state.message,
212
+ reason: (state === null || state === void 0 ? void 0 : state.reason) || createRuntimeIssue("current-step-review")
213
+ });
214
+ return false;
215
+ }
216
+ validatedCompletionRef.current = {
217
+ draftRevision: draftRevisionRef.current,
218
+ compiledFingerprint: require_utils.getCompiledStepsFingerprint(latestSteps),
219
+ moduleRevisionFingerprint: latestSteps.flatMap((step) => step.modules).map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|")
220
+ };
221
+ return true;
222
+ }), [
223
+ createRuntimeIssue,
224
+ onValidationFailed,
225
+ validateCurrentStep
226
+ ]);
227
+ const complete = (0, react.useCallback)(() => {
228
+ if (!mountedRef.current) return Promise.resolve(false);
229
+ if (completedRef.current) return Promise.resolve(true);
230
+ if (completionPromiseRef.current) return completionPromiseRef.current;
231
+ if (transitionPendingRef.current) return Promise.resolve(false);
232
+ transitionPendingRef.current = true;
233
+ const navigationRevision = navigationRevisionRef.current + 1;
234
+ navigationRevisionRef.current = navigationRevision;
235
+ isCompletingRef.current = true;
236
+ setIsCompleting(true);
237
+ const run = require_asyncToGenerator._asyncToGenerator(function* () {
238
+ try {
239
+ setCompletionError(void 0);
240
+ setCompletionReason(void 0);
241
+ if (!(yield validateFlowForCompletion())) return false;
242
+ if (!(yield runBeforeLeaveForCurrentStep())) return false;
243
+ const validated = validatedCompletionRef.current;
244
+ const latestSteps = compiledStepsRef.current;
245
+ if (!mountedRef.current || navigationRevisionRef.current !== navigationRevision || !validated || validated.draftRevision !== draftRevisionRef.current || validated.compiledFingerprint !== require_utils.getCompiledStepsFingerprint(latestSteps) || validated.moduleRevisionFingerprint !== latestSteps.flatMap((step) => step.modules).map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|")) {
246
+ if (mountedRef.current) setCompletionReason(createRuntimeIssue("changed-confirm-again"));
247
+ return false;
248
+ }
249
+ const snapshot = draftAdapter.createSnapshot ? draftAdapter.createSnapshot(draftRef.current) : draftRef.current;
250
+ const completionResult = yield onCompleteRef.current(snapshot);
251
+ if (!mountedRef.current || navigationRevisionRef.current !== navigationRevision) return false;
252
+ if (completionResult === false) return false;
253
+ completedRef.current = true;
254
+ return true;
255
+ } catch (error) {
256
+ if (mountedRef.current) setCompletionError(require_utils.getSelectionFlowErrorMessage(error));
257
+ return false;
258
+ } finally {
259
+ isCompletingRef.current = false;
260
+ transitionPendingRef.current = false;
261
+ if (mountedRef.current) setIsCompleting(false);
262
+ }
263
+ })();
264
+ completionPromiseRef.current = run;
265
+ run.finally(() => {
266
+ if (completionPromiseRef.current === run) completionPromiseRef.current = null;
267
+ });
268
+ return run;
269
+ }, [
270
+ draftAdapter,
271
+ createRuntimeIssue,
272
+ runBeforeLeaveForCurrentStep,
273
+ setCompletionReason,
274
+ validateFlowForCompletion
275
+ ]);
276
+ return {
277
+ validateCurrentStep,
278
+ runBeforeLeaveForCurrentStep,
279
+ complete,
280
+ next: (0, react.useCallback)(require_asyncToGenerator._asyncToGenerator(function* () {
281
+ if (!mountedRef.current || configurationErrorRef.current || transitionPendingRef.current) return false;
282
+ const currentIndex = currentStepIndexRef.current;
283
+ const allSteps = compiledStepsRef.current;
284
+ if (!allSteps[currentIndex]) return false;
285
+ if (currentIndex >= allSteps.length - 1) return complete();
286
+ const currentStepKey = allSteps[currentIndex].key;
287
+ const navigationRevision = navigationRevisionRef.current + 1;
288
+ navigationRevisionRef.current = navigationRevision;
289
+ transitionPendingRef.current = true;
290
+ try {
291
+ var _compiledStepsRef$cur2, _allSteps$nextIndex;
292
+ if (!(yield validateCurrentStep())) return false;
293
+ if (!(yield runBeforeLeaveForCurrentStep())) return false;
294
+ if (!mountedRef.current || navigationRevisionRef.current !== navigationRevision || currentStepIndexRef.current !== currentIndex || ((_compiledStepsRef$cur2 = compiledStepsRef.current[currentIndex]) === null || _compiledStepsRef$cur2 === void 0 ? void 0 : _compiledStepsRef$cur2.key) !== currentStepKey) return false;
295
+ const nextIndex = currentIndex + 1;
296
+ currentStepIndexRef.current = nextIndex;
297
+ currentStepKeyRef.current = (_allSteps$nextIndex = allSteps[nextIndex]) === null || _allSteps$nextIndex === void 0 ? void 0 : _allSteps$nextIndex.key;
298
+ setCurrentStepIndex(nextIndex);
299
+ return true;
300
+ } finally {
301
+ transitionPendingRef.current = false;
302
+ }
303
+ }), [
304
+ complete,
305
+ runBeforeLeaveForCurrentStep,
306
+ validateCurrentStep
307
+ ]),
308
+ back: (0, react.useCallback)(() => {
309
+ var _compiledStepsRef$cur3;
310
+ if (!mountedRef.current || transitionPendingRef.current || currentStepIndexRef.current <= 0) return false;
311
+ navigationRevisionRef.current += 1;
312
+ const nextIndex = currentStepIndexRef.current - 1;
313
+ currentStepIndexRef.current = nextIndex;
314
+ currentStepKeyRef.current = (_compiledStepsRef$cur3 = compiledStepsRef.current[nextIndex]) === null || _compiledStepsRef$cur3 === void 0 ? void 0 : _compiledStepsRef$cur3.key;
315
+ setCurrentStepIndex(nextIndex);
316
+ return true;
317
+ }, [])
318
+ };
319
+ };
320
+ //#endregion
321
+ exports.useFlowNavigation = useFlowNavigation;
@@ -0,0 +1,4 @@
1
+ import { CompiledSelectionFlowModuleConfig, CompiledSelectionFlowStep, FlowModuleBeforeLeaveResult, FlowModuleBeforeLeaveReturn, FlowModuleDataMap, FlowModuleHandle, FlowModuleState, FlowModuleStateMap, FlowModuleStatus, FlowModuleValidationResult, FlowModuleValidationReturn, PisellSelectionFlowController, PisellSelectionFlowProps, SelectionFlowCompileError, SelectionFlowCompileIssue, SelectionFlowCompileIssueCode, SelectionFlowContextValue, SelectionFlowDraftAdapter, SelectionFlowDraftChange, SelectionFlowDraftUpdateMeta, SelectionFlowMessageCode, SelectionFlowMetadata, SelectionFlowModuleAdapter, SelectionFlowModuleConfig, SelectionFlowModuleInput, SelectionFlowModuleRegistry, SelectionFlowRef, SelectionFlowRuntimeIssue, SelectionFlowSnapshot, SelectionFlowStepConfig, SelectionFlowValidationFeedback } from "./types.js";
2
+ import { _default } from "./PisellSelectionFlow.js";
3
+ import { useSelectionFlowContext, useTypedSelectionFlowContext } from "./context.js";
4
+ import { compileSelectionFlow, compileSelectionFlowSteps, hasSelectionDraftFieldValue, isSelectionModuleType, resolveFlowModuleAdapter } from "./compiler.js";