@pisell/materials 6.12.82 → 6.12.84

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.
@@ -59,6 +59,7 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
59
59
  const moduleInitializationRef = useRef(/* @__PURE__ */ new Map());
60
60
  const moduleDependencyLifecycleRef = useRef(/* @__PURE__ */ new Map());
61
61
  const pendingModuleChangeRef = useRef(/* @__PURE__ */ new Map());
62
+ const moduleInvalidationRef = useRef(/* @__PURE__ */ new Map());
62
63
  const compiledStepsRef = useRef([]);
63
64
  const configurationErrorRef = useRef(null);
64
65
  const contextRef = useRef(null);
@@ -86,11 +87,13 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
86
87
  moduleInitializationRef.current.clear();
87
88
  moduleDependencyLifecycleRef.current.clear();
88
89
  pendingModuleChangeRef.current.clear();
90
+ moduleInvalidationRef.current.clear();
89
91
  moduleHandlesRef.current.clear();
90
92
  };
91
93
  }, []);
92
94
  const commitModuleState = useCallback((moduleKey, nextState) => {
93
95
  if (!mountedRef.current) return;
96
+ if (nextState.status === "ready") moduleInvalidationRef.current.delete(moduleKey);
94
97
  const previous = moduleStateRef.current[moduleKey];
95
98
  if ((previous === null || previous === void 0 ? void 0 : previous.status) === nextState.status && (previous === null || previous === void 0 ? void 0 : previous.message) === nextState.message && (previous === null || previous === void 0 ? void 0 : previous.reason) === nextState.reason && (previous === null || previous === void 0 ? void 0 : previous.error) === nextState.error) return;
96
99
  const nextMap = _objectSpread2(_objectSpread2({}, moduleStateRef.current), {}, { [moduleKey]: nextState });
@@ -254,6 +257,7 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
254
257
  moduleInitializationRef.current.delete(moduleKey);
255
258
  moduleDependencyLifecycleRef.current.delete(moduleKey);
256
259
  pendingModuleChangeRef.current.delete(moduleKey);
260
+ moduleInvalidationRef.current.delete(moduleKey);
257
261
  moduleHandlesRef.current.delete(moduleKey);
258
262
  if (moduleKey in nextMap) {
259
263
  delete nextMap[moduleKey];
@@ -286,6 +290,7 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
286
290
  moduleInitializationRef,
287
291
  moduleDependencyLifecycleRef,
288
292
  pendingModuleChangeRef,
293
+ moduleInvalidationRef,
289
294
  compiledStepsRef,
290
295
  moduleStateRef,
291
296
  processDraftChangeRef,
@@ -298,13 +303,14 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
298
303
  draft,
299
304
  moduleState
300
305
  });
301
- const { validateCurrentStep, prepareSteps, complete, next, back } = useFlowNavigation({
306
+ const { validateCurrentStep, prepareSteps, complete, next, back, isStepSkippable, navigationDirectionRef } = useFlowNavigation({
302
307
  registry,
303
308
  draftAdapter,
304
309
  createRuntimeIssue,
305
310
  mountedRef,
306
311
  moduleStateRef,
307
312
  moduleRevisionRef,
313
+ moduleInvalidationRef,
308
314
  draftRevisionRef,
309
315
  flowGenerationRef,
310
316
  moduleHandlesRef,
@@ -330,6 +336,27 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
330
336
  setCompletionReason,
331
337
  setIsCompleting
332
338
  });
339
+ const autoAdvanceAttemptRef = useRef();
340
+ useEffect(() => {
341
+ if (configurationError || completedRef.current || transitionPendingRef.current || !currentStep || !isStepSkippable(resolvedCurrentStepIndex)) return;
342
+ const direction = navigationDirectionRef.current;
343
+ const key = `${direction}:${currentStep.key}:${draftRevisionRef.current}:${currentStep.modules.map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|")}`;
344
+ if (autoAdvanceAttemptRef.current === key) return;
345
+ autoAdvanceAttemptRef.current = key;
346
+ if (direction === "backward") back();
347
+ else next();
348
+ }, [
349
+ configurationError,
350
+ currentStep,
351
+ resolvedCurrentStepIndex,
352
+ moduleState,
353
+ moduleData,
354
+ draft,
355
+ isStepSkippable,
356
+ navigationDirectionRef,
357
+ back,
358
+ next
359
+ ]);
333
360
  const getState = useCallback(() => {
334
361
  const stepIndex = currentStepIndexRef.current;
335
362
  return {
@@ -387,7 +414,8 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
387
414
  back,
388
415
  getState,
389
416
  registerModuleHandle,
390
- getModuleHandle
417
+ getModuleHandle,
418
+ isStepSkippable
391
419
  };
392
420
  return /* @__PURE__ */ React.createElement(SelectionFlowProvider, { value: contextValue }, children(controller));
393
421
  };
@@ -5,12 +5,13 @@ import { getSelectionFlowErrorMessage } from "../utils.js";
5
5
  import { useCallback, useEffect } from "react";
6
6
  //#region src/components/PisellSelectionFlow/hooks/useFlowModuleLifecycle.ts
7
7
  /** 负责依赖失效、清理、校正、刷新和异步 latest-wins。 */
8
- const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mountedRef, flowGenerationRef, draftRevisionRef, draftRef, moduleRevisionRef, moduleInitializationRef, moduleDependencyLifecycleRef, pendingModuleChangeRef, compiledStepsRef, moduleStateRef, processDraftChangeRef, commitModuleState, getFreshContext, currentStep, configurationError, compiledSteps, resolvedCurrentStepIndex, draft, moduleState }) => {
8
+ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mountedRef, flowGenerationRef, draftRevisionRef, draftRef, moduleRevisionRef, moduleInitializationRef, moduleDependencyLifecycleRef, pendingModuleChangeRef, moduleInvalidationRef, compiledStepsRef, moduleStateRef, processDraftChangeRef, commitModuleState, getFreshContext, currentStep, configurationError, compiledSteps, resolvedCurrentStepIndex, draft, moduleState }) => {
9
9
  processDraftChangeRef.current = useCallback((change) => {
10
10
  const changedFields = new Set(change.changedFields);
11
11
  const flowGeneration = flowGenerationRef.current;
12
12
  if (!mountedRef.current) return;
13
13
  for (const step of compiledStepsRef.current) for (const module of step.modules) {
14
+ var _previousInvalidation, _moduleStateRef$curre;
14
15
  if (module.key === change.sourceModuleKey) continue;
15
16
  const adapter = resolveFlowModuleAdapter(registry, module.type);
16
17
  if (!adapter) continue;
@@ -24,6 +25,14 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
24
25
  moduleRevisionRef.current.set(module.key, revision);
25
26
  moduleInitializationRef.current.delete(module.key);
26
27
  moduleDependencyLifecycleRef.current.delete(module.key);
28
+ const previousInvalidation = moduleInvalidationRef.current.get(module.key);
29
+ moduleInvalidationRef.current.set(module.key, {
30
+ wasReady: false,
31
+ change: previousInvalidation ? _objectSpread2(_objectSpread2({}, change), {}, {
32
+ previousDraft: previousInvalidation.change.previousDraft,
33
+ changedFields: Array.from(new Set([...previousInvalidation.change.changedFields, ...change.changedFields]))
34
+ }) : change
35
+ });
27
36
  commitModuleState(module.key, {
28
37
  status: "error",
29
38
  message: getSelectionFlowErrorMessage(error),
@@ -32,6 +41,14 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
32
41
  continue;
33
42
  }
34
43
  if (!shouldRefresh) continue;
44
+ const previousInvalidation = moduleInvalidationRef.current.get(module.key);
45
+ moduleInvalidationRef.current.set(module.key, {
46
+ wasReady: (_previousInvalidation = previousInvalidation === null || previousInvalidation === void 0 ? void 0 : previousInvalidation.wasReady) !== null && _previousInvalidation !== void 0 ? _previousInvalidation : ((_moduleStateRef$curre = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre === void 0 ? void 0 : _moduleStateRef$curre.status) === "ready",
47
+ change: previousInvalidation ? _objectSpread2(_objectSpread2({}, change), {}, {
48
+ previousDraft: previousInvalidation.change.previousDraft,
49
+ changedFields: Array.from(new Set([...previousInvalidation.change.changedFields, ...change.changedFields]))
50
+ }) : change
51
+ });
35
52
  const previousPendingChange = pendingModuleChangeRef.current.get(module.key);
36
53
  const lifecycleChange = previousPendingChange ? _objectSpread2(_objectSpread2({}, change), {}, {
37
54
  previousDraft: previousPendingChange.previousDraft,
@@ -163,7 +180,7 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
163
180
  return false;
164
181
  }
165
182
  try {
166
- var _await$adapter$canIni, _adapter$canInitializ, _moduleStateRef$curre2;
183
+ var _await$adapter$canIni, _adapter$canInitializ, _moduleStateRef$curre3;
167
184
  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;
168
185
  if (!isCurrentRun()) return false;
169
186
  if (!canInitialize) {
@@ -174,14 +191,14 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
174
191
  return false;
175
192
  }
176
193
  do {
177
- var _adapter$refresh, _moduleStateRef$curre;
194
+ var _adapter$refresh, _moduleStateRef$curre2;
178
195
  commitModuleState(module.key, { status: "loading" });
179
196
  context = getRunContext();
180
197
  if (!context || !isCurrentRun()) return false;
181
198
  yield (_adapter$refresh = adapter.refresh) === null || _adapter$refresh === void 0 ? void 0 : _adapter$refresh.call(adapter, context, module);
182
199
  if (!isCurrentRun()) return false;
183
- if (((_moduleStateRef$curre = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre === void 0 ? void 0 : _moduleStateRef$curre.status) === "error") return false;
184
- } while (((_moduleStateRef$curre2 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre2 === void 0 ? void 0 : _moduleStateRef$curre2.status) === "stale");
200
+ if (((_moduleStateRef$curre2 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre2 === void 0 ? void 0 : _moduleStateRef$curre2.status) === "error") return false;
201
+ } while (((_moduleStateRef$curre3 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre3 === void 0 ? void 0 : _moduleStateRef$curre3.status) === "stale");
185
202
  commitModuleState(module.key, { status: "ready" });
186
203
  return true;
187
204
  } catch (error) {
@@ -216,8 +233,8 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
216
233
  return (adapter === null || adapter === void 0 ? void 0 : adapter.initializeWhileInactive) && module.stepIndex < resolvedCurrentStepIndex;
217
234
  });
218
235
  for (const module of [...currentStep.modules, ...backgroundModules]) {
219
- var _moduleStateRef$curre3;
220
- const status = ((_moduleStateRef$curre3 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre3 === void 0 ? void 0 : _moduleStateRef$curre3.status) || "idle";
236
+ var _moduleStateRef$curre4;
237
+ const status = ((_moduleStateRef$curre4 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre4 === void 0 ? void 0 : _moduleStateRef$curre4.status) || "idle";
221
238
  if (status === "idle" || status === "stale") ensureModuleReady(module);
222
239
  }
223
240
  }, [
@@ -2,10 +2,26 @@ import { _objectSpread2 } from "../../../_virtual/_@oxc-project_runtime@0.122.0/
2
2
  import { _asyncToGenerator } from "../../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js";
3
3
  import { resolveFlowModuleAdapter } from "../compiler.js";
4
4
  import { getCompiledStepsFingerprint, getSelectionFlowErrorMessage, normalizeFlowBeforeLeaveResult, normalizeFlowValidationResult } from "../utils.js";
5
- import { useCallback } from "react";
5
+ import { useCallback, useRef } from "react";
6
6
  //#region src/components/PisellSelectionFlow/hooks/useFlowNavigation.ts
7
7
  /** 导航、校验与提交门禁独立于模块加载生命周期。 */
8
- const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mountedRef, moduleStateRef, moduleRevisionRef, draftRevisionRef, flowGenerationRef, moduleHandlesRef, configurationErrorRef, compiledStepsRef, currentStepIndexRef, currentStepKeyRef, validatedCompletionRef, navigationRevisionRef, preparationRevisionRef, transitionPendingRef, completedRef, completionPromiseRef, isCompletingRef, draftRef, onCompleteRef, ensureModuleReady, commitModuleState, getFreshContext, onValidationFailed, setCurrentStepIndex, setCompletionError, setCompletionReason, setIsCompleting }) => {
8
+ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mountedRef, moduleStateRef, moduleRevisionRef, moduleInvalidationRef, draftRevisionRef, flowGenerationRef, moduleHandlesRef, configurationErrorRef, compiledStepsRef, currentStepIndexRef, currentStepKeyRef, validatedCompletionRef, navigationRevisionRef, preparationRevisionRef, transitionPendingRef, completedRef, completionPromiseRef, isCompletingRef, draftRef, onCompleteRef, ensureModuleReady, commitModuleState, getFreshContext, onValidationFailed, setCurrentStepIndex, setCompletionError, setCompletionReason, setIsCompleting }) => {
9
+ const navigationDirectionRef = useRef("forward");
10
+ const isStepSkippable = useCallback((stepIndex) => {
11
+ const step = compiledStepsRef.current[stepIndex];
12
+ const context = getFreshContext();
13
+ if (!(step === null || step === void 0 ? void 0 : step.modules.length) || !context) return false;
14
+ return step.modules.every((module) => {
15
+ var _moduleStateRef$curre;
16
+ if (((_moduleStateRef$curre = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre === void 0 ? void 0 : _moduleStateRef$curre.status) !== "ready") return false;
17
+ try {
18
+ var _resolveFlowModuleAda, _resolveFlowModuleAda2;
19
+ return ((_resolveFlowModuleAda = resolveFlowModuleAdapter(registry, module.type)) === null || _resolveFlowModuleAda === void 0 || (_resolveFlowModuleAda2 = _resolveFlowModuleAda.isSkippable) === null || _resolveFlowModuleAda2 === void 0 ? void 0 : _resolveFlowModuleAda2.call(_resolveFlowModuleAda, context, module)) === true;
20
+ } catch (_unused) {
21
+ return false;
22
+ }
23
+ });
24
+ }, [getFreshContext, registry]);
9
25
  const validateModule = useCallback(function() {
10
26
  var _ref = _asyncToGenerator(function* (module) {
11
27
  const adapter = resolveFlowModuleAdapter(registry, module.type);
@@ -180,16 +196,16 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
180
196
  }
181
197
  }
182
198
  if (!targetModules.find(({ module }) => {
183
- var _moduleStateRef$curre;
184
- return ((_moduleStateRef$curre = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre === void 0 ? void 0 : _moduleStateRef$curre.status) !== "ready";
199
+ var _moduleStateRef$curre2;
200
+ return ((_moduleStateRef$curre2 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre2 === void 0 ? void 0 : _moduleStateRef$curre2.status) !== "ready";
185
201
  })) return isCurrentPreparation() ? { prepared: true } : {
186
202
  prepared: false,
187
203
  cancelled: true
188
204
  };
189
205
  }
190
206
  const unresolved = targetModules.find(({ module }) => {
191
- var _moduleStateRef$curre2;
192
- return ((_moduleStateRef$curre2 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre2 === void 0 ? void 0 : _moduleStateRef$curre2.status) !== "ready";
207
+ var _moduleStateRef$curre3;
208
+ return ((_moduleStateRef$curre3 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre3 === void 0 ? void 0 : _moduleStateRef$curre3.status) !== "ready";
193
209
  });
194
210
  return unresolved ? {
195
211
  prepared: false,
@@ -257,19 +273,109 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
257
273
  onValidationFailed,
258
274
  registry
259
275
  ]);
276
+ const revalidateModuleBeforeComplete = useCallback(function() {
277
+ var _ref2 = _asyncToGenerator(function* (module, expectedDraftRevision) {
278
+ const invalidation = moduleInvalidationRef.current.get(module.key);
279
+ const adapter = resolveFlowModuleAdapter(registry, module.type);
280
+ if (!(invalidation === null || invalidation === void 0 ? void 0 : invalidation.wasReady) || !(adapter === null || adapter === void 0 ? void 0 : adapter.canRevalidateBeforeComplete) || !adapter.validateAutoResolution) return false;
281
+ const moduleRevision = moduleRevisionRef.current.get(module.key) || 0;
282
+ const flowGeneration = flowGenerationRef.current;
283
+ const navigationRevision = navigationRevisionRef.current;
284
+ const compiledFingerprint = getCompiledStepsFingerprint(compiledStepsRef.current);
285
+ const isCurrentRun = () => mountedRef.current && !configurationErrorRef.current && flowGenerationRef.current === flowGeneration && navigationRevisionRef.current === navigationRevision && (moduleRevisionRef.current.get(module.key) || 0) === moduleRevision && getCompiledStepsFingerprint(compiledStepsRef.current) === compiledFingerprint;
286
+ const isCurrentSelection = () => isCurrentRun() && draftRevisionRef.current === expectedDraftRevision;
287
+ const requireReviewIfCurrent = () => {
288
+ if (isCurrentRun()) commitModuleState(module.key, {
289
+ status: "stale",
290
+ reason: createRuntimeIssue("selection-changed-validation")
291
+ });
292
+ };
293
+ try {
294
+ const initialContext = getFreshContext();
295
+ if (!initialContext || !isCurrentSelection() || !adapter.canRevalidateBeforeComplete(initialContext, invalidation.change, module)) return false;
296
+ if (!(yield ensureModuleReady(module))) return false;
297
+ if (!isCurrentSelection()) {
298
+ requireReviewIfCurrent();
299
+ return false;
300
+ }
301
+ const context = getFreshContext();
302
+ if (!context) return false;
303
+ const validationContext = _objectSpread2(_objectSpread2({}, context), {}, {
304
+ updateDraft: (update, meta) => {
305
+ if (isCurrentSelection()) context.updateDraft(update, meta);
306
+ },
307
+ setModuleState: (moduleKey, state) => {
308
+ if (isCurrentSelection()) context.setModuleState(moduleKey, state);
309
+ },
310
+ setModuleStatus: (moduleKey, status, message, error) => {
311
+ if (isCurrentSelection()) context.setModuleStatus(moduleKey, status, message, error);
312
+ },
313
+ setModuleData: (moduleKey, value) => {
314
+ if (isCurrentSelection()) context.setModuleData(moduleKey, value);
315
+ },
316
+ clearModuleData: (moduleKey) => {
317
+ if (isCurrentSelection()) context.clearModuleData(moduleKey);
318
+ }
319
+ });
320
+ const result = normalizeFlowValidationResult(yield adapter.validateAutoResolution(validationContext, module));
321
+ if (!isCurrentSelection()) {
322
+ requireReviewIfCurrent();
323
+ return false;
324
+ }
325
+ if (!result.valid) {
326
+ commitModuleState(module.key, {
327
+ status: "error",
328
+ message: result.message,
329
+ reason: result.message ? void 0 : createRuntimeIssue("module-validation-failed")
330
+ });
331
+ return false;
332
+ }
333
+ commitModuleState(module.key, { status: "ready" });
334
+ return true;
335
+ } catch (error) {
336
+ if (isCurrentSelection()) commitModuleState(module.key, {
337
+ status: "error",
338
+ message: getSelectionFlowErrorMessage(error),
339
+ error
340
+ });
341
+ else requireReviewIfCurrent();
342
+ return false;
343
+ }
344
+ });
345
+ return function(_x2, _x3) {
346
+ return _ref2.apply(this, arguments);
347
+ };
348
+ }(), [
349
+ commitModuleState,
350
+ createRuntimeIssue,
351
+ ensureModuleReady,
352
+ getFreshContext,
353
+ registry
354
+ ]);
260
355
  const validateFlowForCompletion = useCallback(_asyncToGenerator(function* () {
261
356
  validatedCompletionRef.current = null;
262
357
  if (configurationErrorRef.current) return false;
263
358
  const currentIndex = currentStepIndexRef.current;
264
359
  const allSteps = compiledStepsRef.current;
265
- const compiledFingerprint = getCompiledStepsFingerprint(allSteps);
266
- const revisionFingerprint = allSteps.flatMap((step) => step.modules).map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|");
267
- const draftRevision = draftRevisionRef.current;
360
+ const preparationFingerprint = getCompiledStepsFingerprint(allSteps);
361
+ const preparationGeneration = flowGenerationRef.current;
362
+ const preparationNavigation = navigationRevisionRef.current;
363
+ const preparationDraftRevision = draftRevisionRef.current;
364
+ const isCurrentPreparation = () => mountedRef.current && !configurationErrorRef.current && flowGenerationRef.current === preparationGeneration && navigationRevisionRef.current === preparationNavigation && currentStepIndexRef.current === currentIndex && getCompiledStepsFingerprint(compiledStepsRef.current) === preparationFingerprint;
268
365
  for (const step of allSteps) {
269
366
  if (step.index >= currentIndex) break;
270
367
  for (const module of step.modules) {
271
- const state = moduleStateRef.current[module.key];
368
+ let state = moduleStateRef.current[module.key];
272
369
  if ((state === null || state === void 0 ? void 0 : state.status) !== "ready") {
370
+ const revalidationModuleRevision = moduleRevisionRef.current.get(module.key) || 0;
371
+ const revalidated = yield revalidateModuleBeforeComplete(module, preparationDraftRevision);
372
+ if (!isCurrentPreparation()) return false;
373
+ if (revalidated && draftRevisionRef.current === preparationDraftRevision) continue;
374
+ if (revalidated && (moduleRevisionRef.current.get(module.key) || 0) === revalidationModuleRevision) commitModuleState(module.key, {
375
+ status: "stale",
376
+ reason: createRuntimeIssue("selection-changed-validation")
377
+ });
378
+ state = moduleStateRef.current[module.key];
273
379
  currentStepIndexRef.current = step.index;
274
380
  currentStepKeyRef.current = step.key;
275
381
  setCurrentStepIndex(step.index);
@@ -281,6 +387,9 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
281
387
  }
282
388
  }
283
389
  }
390
+ const compiledFingerprint = getCompiledStepsFingerprint(allSteps);
391
+ const revisionFingerprint = allSteps.flatMap((step) => step.modules).map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|");
392
+ const draftRevision = draftRevisionRef.current;
284
393
  if (!(yield validateCurrentStep())) return false;
285
394
  if (configurationErrorRef.current) return false;
286
395
  const latestSteps = compiledStepsRef.current;
@@ -288,8 +397,8 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
288
397
  const latestRevisionFingerprint = latestSteps.flatMap((step) => step.modules).map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|");
289
398
  if (compiledFingerprint !== latestCompiledFingerprint || revisionFingerprint !== latestRevisionFingerprint || draftRevision !== draftRevisionRef.current) {
290
399
  const targetStep = latestSteps.find((step) => step.modules.some((module) => {
291
- var _moduleStateRef$curre3;
292
- return ((_moduleStateRef$curre3 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre3 === void 0 ? void 0 : _moduleStateRef$curre3.status) !== "ready";
400
+ var _moduleStateRef$curre4;
401
+ return ((_moduleStateRef$curre4 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre4 === void 0 ? void 0 : _moduleStateRef$curre4.status) !== "ready";
293
402
  })) || latestSteps[0];
294
403
  const targetModule = targetStep === null || targetStep === void 0 ? void 0 : targetStep.modules[0];
295
404
  if (targetStep && targetModule) {
@@ -319,8 +428,10 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
319
428
  };
320
429
  return true;
321
430
  }), [
431
+ commitModuleState,
322
432
  createRuntimeIssue,
323
433
  onValidationFailed,
434
+ revalidateModuleBeforeComplete,
324
435
  validateCurrentStep
325
436
  ]);
326
437
  const complete = useCallback(() => {
@@ -328,6 +439,7 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
328
439
  if (completedRef.current) return Promise.resolve(true);
329
440
  if (completionPromiseRef.current) return completionPromiseRef.current;
330
441
  if (transitionPendingRef.current) return Promise.resolve(false);
442
+ navigationDirectionRef.current = "forward";
331
443
  transitionPendingRef.current = true;
332
444
  const navigationRevision = navigationRevisionRef.current + 1;
333
445
  navigationRevisionRef.current = navigationRevision;
@@ -382,6 +494,7 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
382
494
  const currentIndex = currentStepIndexRef.current;
383
495
  const allSteps = compiledStepsRef.current;
384
496
  if (!allSteps[currentIndex]) return false;
497
+ navigationDirectionRef.current = "forward";
385
498
  if (currentIndex >= allSteps.length - 1) return complete();
386
499
  const currentStepKey = allSteps[currentIndex].key;
387
500
  const navigationRevision = navigationRevisionRef.current + 1;
@@ -408,13 +521,18 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
408
521
  back: useCallback(() => {
409
522
  var _compiledStepsRef$cur3;
410
523
  if (!mountedRef.current || transitionPendingRef.current || currentStepIndexRef.current <= 0) return false;
524
+ let nextIndex = currentStepIndexRef.current - 1;
525
+ while (nextIndex >= 0 && isStepSkippable(nextIndex)) nextIndex -= 1;
526
+ if (nextIndex < 0) return false;
527
+ navigationDirectionRef.current = "backward";
411
528
  navigationRevisionRef.current += 1;
412
- const nextIndex = currentStepIndexRef.current - 1;
413
529
  currentStepIndexRef.current = nextIndex;
414
530
  currentStepKeyRef.current = (_compiledStepsRef$cur3 = compiledStepsRef.current[nextIndex]) === null || _compiledStepsRef$cur3 === void 0 ? void 0 : _compiledStepsRef$cur3.key;
415
531
  setCurrentStepIndex(nextIndex);
416
532
  return true;
417
- }, [])
533
+ }, [isStepSkippable]),
534
+ isStepSkippable,
535
+ navigationDirectionRef
418
536
  };
419
537
  };
420
538
  //#endregion
@@ -100,10 +100,19 @@ interface SelectionFlowModuleAdapter<TDraft, TDraftUpdate, TField extends string
100
100
  type: TModuleType;
101
101
  /** 离开所在步骤后仍需随 Draft 变化保持就绪的无界面门禁模块。 */
102
102
  initializeWhileInactive?: boolean;
103
+ /** Ready modules may omit their navigation stop; validation and beforeLeave still run. */
104
+ isSkippable?: (context: SelectionFlowContextValue<TDraft, TDraftUpdate, TField, TModuleType, TServices, THostContext>, module: CompiledSelectionFlowModuleConfig<TModuleType>) => boolean;
103
105
  provides?: readonly TField[];
104
106
  hardRequires?: readonly TField[];
105
107
  refreshOn?: readonly TField[];
106
108
  shouldRefresh?: (context: SelectionFlowContextValue<TDraft, TDraftUpdate, TField, TModuleType, TServices, THostContext>, change: SelectionFlowDraftChange<TDraft, TField, TModuleType>, module: CompiledSelectionFlowModuleConfig<TModuleType>) => boolean;
109
+ /**
110
+ * Explicitly permits completion to refresh a previously ready, invalidated
111
+ * module without revisiting its UI. The accumulated change starts at its last
112
+ * ready state. Completion still requires validateAutoResolution to succeed
113
+ * without any Draft revision changing; beforeLeave is not run here.
114
+ */
115
+ canRevalidateBeforeComplete?: (context: SelectionFlowContextValue<TDraft, TDraftUpdate, TField, TModuleType, TServices, THostContext>, change: SelectionFlowDraftChange<TDraft, TField, TModuleType>, module: CompiledSelectionFlowModuleConfig<TModuleType>) => boolean;
107
116
  isApplicable?: (context: SelectionFlowContextValue<TDraft, TDraftUpdate, TField, TModuleType, TServices, THostContext>, module: CompiledSelectionFlowModuleConfig<TModuleType>) => boolean;
108
117
  canInitialize?: (context: SelectionFlowContextValue<TDraft, TDraftUpdate, TField, TModuleType, TServices, THostContext>, module: CompiledSelectionFlowModuleConfig<TModuleType>) => boolean | Promise<boolean>;
109
118
  refresh?: (context: SelectionFlowContextValue<TDraft, TDraftUpdate, TField, TModuleType, TServices, THostContext>, module: CompiledSelectionFlowModuleConfig<TModuleType>) => void | Promise<void>;
@@ -164,6 +173,8 @@ interface PisellSelectionFlowController<TDraft, TDraftUpdate, TField extends str
164
173
  getState: () => SelectionFlowSnapshot<TDraft, TModuleType>;
165
174
  registerModuleHandle: (moduleKey: string, handle: FlowModuleHandle | null) => void;
166
175
  getModuleHandle: (moduleKey: string) => FlowModuleHandle | undefined;
176
+ /** True only when every module in the step is ready and explicitly permits skipping. */
177
+ isStepSkippable: (stepIndex: number) => boolean;
167
178
  }
168
179
  interface PisellSelectionFlowProps<TDraft, TDraftUpdate, TField extends string, TModuleType extends string, TServices = unknown, THostContext = unknown> {
169
180
  registry: SelectionFlowModuleRegistry<TDraft, TDraftUpdate, TField, TModuleType, TServices, THostContext>;
@@ -61,6 +61,7 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
61
61
  const moduleInitializationRef = (0, react.useRef)(/* @__PURE__ */ new Map());
62
62
  const moduleDependencyLifecycleRef = (0, react.useRef)(/* @__PURE__ */ new Map());
63
63
  const pendingModuleChangeRef = (0, react.useRef)(/* @__PURE__ */ new Map());
64
+ const moduleInvalidationRef = (0, react.useRef)(/* @__PURE__ */ new Map());
64
65
  const compiledStepsRef = (0, react.useRef)([]);
65
66
  const configurationErrorRef = (0, react.useRef)(null);
66
67
  const contextRef = (0, react.useRef)(null);
@@ -88,11 +89,13 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
88
89
  moduleInitializationRef.current.clear();
89
90
  moduleDependencyLifecycleRef.current.clear();
90
91
  pendingModuleChangeRef.current.clear();
92
+ moduleInvalidationRef.current.clear();
91
93
  moduleHandlesRef.current.clear();
92
94
  };
93
95
  }, []);
94
96
  const commitModuleState = (0, react.useCallback)((moduleKey, nextState) => {
95
97
  if (!mountedRef.current) return;
98
+ if (nextState.status === "ready") moduleInvalidationRef.current.delete(moduleKey);
96
99
  const previous = moduleStateRef.current[moduleKey];
97
100
  if ((previous === null || previous === void 0 ? void 0 : previous.status) === nextState.status && (previous === null || previous === void 0 ? void 0 : previous.message) === nextState.message && (previous === null || previous === void 0 ? void 0 : previous.reason) === nextState.reason && (previous === null || previous === void 0 ? void 0 : previous.error) === nextState.error) return;
98
101
  const nextMap = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, moduleStateRef.current), {}, { [moduleKey]: nextState });
@@ -256,6 +259,7 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
256
259
  moduleInitializationRef.current.delete(moduleKey);
257
260
  moduleDependencyLifecycleRef.current.delete(moduleKey);
258
261
  pendingModuleChangeRef.current.delete(moduleKey);
262
+ moduleInvalidationRef.current.delete(moduleKey);
259
263
  moduleHandlesRef.current.delete(moduleKey);
260
264
  if (moduleKey in nextMap) {
261
265
  delete nextMap[moduleKey];
@@ -288,6 +292,7 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
288
292
  moduleInitializationRef,
289
293
  moduleDependencyLifecycleRef,
290
294
  pendingModuleChangeRef,
295
+ moduleInvalidationRef,
291
296
  compiledStepsRef,
292
297
  moduleStateRef,
293
298
  processDraftChangeRef,
@@ -300,13 +305,14 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
300
305
  draft,
301
306
  moduleState
302
307
  });
303
- const { validateCurrentStep, prepareSteps, complete, next, back } = require_useFlowNavigation.useFlowNavigation({
308
+ const { validateCurrentStep, prepareSteps, complete, next, back, isStepSkippable, navigationDirectionRef } = require_useFlowNavigation.useFlowNavigation({
304
309
  registry,
305
310
  draftAdapter,
306
311
  createRuntimeIssue,
307
312
  mountedRef,
308
313
  moduleStateRef,
309
314
  moduleRevisionRef,
315
+ moduleInvalidationRef,
310
316
  draftRevisionRef,
311
317
  flowGenerationRef,
312
318
  moduleHandlesRef,
@@ -332,6 +338,27 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
332
338
  setCompletionReason,
333
339
  setIsCompleting
334
340
  });
341
+ const autoAdvanceAttemptRef = (0, react.useRef)();
342
+ (0, react.useEffect)(() => {
343
+ if (configurationError || completedRef.current || transitionPendingRef.current || !currentStep || !isStepSkippable(resolvedCurrentStepIndex)) return;
344
+ const direction = navigationDirectionRef.current;
345
+ const key = `${direction}:${currentStep.key}:${draftRevisionRef.current}:${currentStep.modules.map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|")}`;
346
+ if (autoAdvanceAttemptRef.current === key) return;
347
+ autoAdvanceAttemptRef.current = key;
348
+ if (direction === "backward") back();
349
+ else next();
350
+ }, [
351
+ configurationError,
352
+ currentStep,
353
+ resolvedCurrentStepIndex,
354
+ moduleState,
355
+ moduleData,
356
+ draft,
357
+ isStepSkippable,
358
+ navigationDirectionRef,
359
+ back,
360
+ next
361
+ ]);
335
362
  const getState = (0, react.useCallback)(() => {
336
363
  const stepIndex = currentStepIndexRef.current;
337
364
  return {
@@ -389,7 +416,8 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
389
416
  back,
390
417
  getState,
391
418
  registerModuleHandle,
392
- getModuleHandle
419
+ getModuleHandle,
420
+ isStepSkippable
393
421
  };
394
422
  return /* @__PURE__ */ react.default.createElement(require_context.SelectionFlowProvider, { value: contextValue }, children(controller));
395
423
  };
@@ -6,12 +6,13 @@ const require_utils = require("../utils.js");
6
6
  let react = require("react");
7
7
  //#region src/components/PisellSelectionFlow/hooks/useFlowModuleLifecycle.ts
8
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 }) => {
9
+ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mountedRef, flowGenerationRef, draftRevisionRef, draftRef, moduleRevisionRef, moduleInitializationRef, moduleDependencyLifecycleRef, pendingModuleChangeRef, moduleInvalidationRef, compiledStepsRef, moduleStateRef, processDraftChangeRef, commitModuleState, getFreshContext, currentStep, configurationError, compiledSteps, resolvedCurrentStepIndex, draft, moduleState }) => {
10
10
  processDraftChangeRef.current = (0, react.useCallback)((change) => {
11
11
  const changedFields = new Set(change.changedFields);
12
12
  const flowGeneration = flowGenerationRef.current;
13
13
  if (!mountedRef.current) return;
14
14
  for (const step of compiledStepsRef.current) for (const module of step.modules) {
15
+ var _previousInvalidation, _moduleStateRef$curre;
15
16
  if (module.key === change.sourceModuleKey) continue;
16
17
  const adapter = require_compiler.resolveFlowModuleAdapter(registry, module.type);
17
18
  if (!adapter) continue;
@@ -25,6 +26,14 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
25
26
  moduleRevisionRef.current.set(module.key, revision);
26
27
  moduleInitializationRef.current.delete(module.key);
27
28
  moduleDependencyLifecycleRef.current.delete(module.key);
29
+ const previousInvalidation = moduleInvalidationRef.current.get(module.key);
30
+ moduleInvalidationRef.current.set(module.key, {
31
+ wasReady: false,
32
+ change: previousInvalidation ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, change), {}, {
33
+ previousDraft: previousInvalidation.change.previousDraft,
34
+ changedFields: Array.from(new Set([...previousInvalidation.change.changedFields, ...change.changedFields]))
35
+ }) : change
36
+ });
28
37
  commitModuleState(module.key, {
29
38
  status: "error",
30
39
  message: require_utils.getSelectionFlowErrorMessage(error),
@@ -33,6 +42,14 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
33
42
  continue;
34
43
  }
35
44
  if (!shouldRefresh) continue;
45
+ const previousInvalidation = moduleInvalidationRef.current.get(module.key);
46
+ moduleInvalidationRef.current.set(module.key, {
47
+ wasReady: (_previousInvalidation = previousInvalidation === null || previousInvalidation === void 0 ? void 0 : previousInvalidation.wasReady) !== null && _previousInvalidation !== void 0 ? _previousInvalidation : ((_moduleStateRef$curre = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre === void 0 ? void 0 : _moduleStateRef$curre.status) === "ready",
48
+ change: previousInvalidation ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, change), {}, {
49
+ previousDraft: previousInvalidation.change.previousDraft,
50
+ changedFields: Array.from(new Set([...previousInvalidation.change.changedFields, ...change.changedFields]))
51
+ }) : change
52
+ });
36
53
  const previousPendingChange = pendingModuleChangeRef.current.get(module.key);
37
54
  const lifecycleChange = previousPendingChange ? require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, change), {}, {
38
55
  previousDraft: previousPendingChange.previousDraft,
@@ -164,7 +181,7 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
164
181
  return false;
165
182
  }
166
183
  try {
167
- var _await$adapter$canIni, _adapter$canInitializ, _moduleStateRef$curre2;
184
+ var _await$adapter$canIni, _adapter$canInitializ, _moduleStateRef$curre3;
168
185
  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
186
  if (!isCurrentRun()) return false;
170
187
  if (!canInitialize) {
@@ -175,14 +192,14 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
175
192
  return false;
176
193
  }
177
194
  do {
178
- var _adapter$refresh, _moduleStateRef$curre;
195
+ var _adapter$refresh, _moduleStateRef$curre2;
179
196
  commitModuleState(module.key, { status: "loading" });
180
197
  context = getRunContext();
181
198
  if (!context || !isCurrentRun()) return false;
182
199
  yield (_adapter$refresh = adapter.refresh) === null || _adapter$refresh === void 0 ? void 0 : _adapter$refresh.call(adapter, context, module);
183
200
  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");
201
+ if (((_moduleStateRef$curre2 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre2 === void 0 ? void 0 : _moduleStateRef$curre2.status) === "error") return false;
202
+ } while (((_moduleStateRef$curre3 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre3 === void 0 ? void 0 : _moduleStateRef$curre3.status) === "stale");
186
203
  commitModuleState(module.key, { status: "ready" });
187
204
  return true;
188
205
  } catch (error) {
@@ -217,8 +234,8 @@ const useFlowModuleLifecycle = ({ registry, draftAdapter, createRuntimeIssue, mo
217
234
  return (adapter === null || adapter === void 0 ? void 0 : adapter.initializeWhileInactive) && module.stepIndex < resolvedCurrentStepIndex;
218
235
  });
219
236
  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";
237
+ var _moduleStateRef$curre4;
238
+ const status = ((_moduleStateRef$curre4 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre4 === void 0 ? void 0 : _moduleStateRef$curre4.status) || "idle";
222
239
  if (status === "idle" || status === "stale") ensureModuleReady(module);
223
240
  }
224
241
  }, [