@pisell/materials 1.10.32 → 1.10.33

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.
@@ -298,7 +298,7 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
298
298
  draft,
299
299
  moduleState
300
300
  });
301
- const { validateCurrentStep, prepareSteps, complete, next, back } = useFlowNavigation({
301
+ const { validateCurrentStep, prepareSteps, complete, next, back, isStepSkippable, navigationDirectionRef } = useFlowNavigation({
302
302
  registry,
303
303
  draftAdapter,
304
304
  createRuntimeIssue,
@@ -330,6 +330,27 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
330
330
  setCompletionReason,
331
331
  setIsCompleting
332
332
  });
333
+ const autoAdvanceAttemptRef = useRef();
334
+ useEffect(() => {
335
+ if (configurationError || completedRef.current || transitionPendingRef.current || !currentStep || !isStepSkippable(resolvedCurrentStepIndex)) return;
336
+ const direction = navigationDirectionRef.current;
337
+ const key = `${direction}:${currentStep.key}:${draftRevisionRef.current}:${currentStep.modules.map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|")}`;
338
+ if (autoAdvanceAttemptRef.current === key) return;
339
+ autoAdvanceAttemptRef.current = key;
340
+ if (direction === "backward") back();
341
+ else next();
342
+ }, [
343
+ configurationError,
344
+ currentStep,
345
+ resolvedCurrentStepIndex,
346
+ moduleState,
347
+ moduleData,
348
+ draft,
349
+ isStepSkippable,
350
+ navigationDirectionRef,
351
+ back,
352
+ next
353
+ ]);
333
354
  const getState = useCallback(() => {
334
355
  const stepIndex = currentStepIndexRef.current;
335
356
  return {
@@ -387,7 +408,8 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
387
408
  back,
388
409
  getState,
389
410
  registerModuleHandle,
390
- getModuleHandle
411
+ getModuleHandle,
412
+ isStepSkippable
391
413
  };
392
414
  return /* @__PURE__ */ React.createElement(SelectionFlowProvider, { value: contextValue }, children(controller));
393
415
  };
@@ -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
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 }) => {
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,
@@ -288,8 +304,8 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
288
304
  const latestRevisionFingerprint = latestSteps.flatMap((step) => step.modules).map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|");
289
305
  if (compiledFingerprint !== latestCompiledFingerprint || revisionFingerprint !== latestRevisionFingerprint || draftRevision !== draftRevisionRef.current) {
290
306
  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";
307
+ var _moduleStateRef$curre4;
308
+ return ((_moduleStateRef$curre4 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre4 === void 0 ? void 0 : _moduleStateRef$curre4.status) !== "ready";
293
309
  })) || latestSteps[0];
294
310
  const targetModule = targetStep === null || targetStep === void 0 ? void 0 : targetStep.modules[0];
295
311
  if (targetStep && targetModule) {
@@ -328,6 +344,7 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
328
344
  if (completedRef.current) return Promise.resolve(true);
329
345
  if (completionPromiseRef.current) return completionPromiseRef.current;
330
346
  if (transitionPendingRef.current) return Promise.resolve(false);
347
+ navigationDirectionRef.current = "forward";
331
348
  transitionPendingRef.current = true;
332
349
  const navigationRevision = navigationRevisionRef.current + 1;
333
350
  navigationRevisionRef.current = navigationRevision;
@@ -382,6 +399,7 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
382
399
  const currentIndex = currentStepIndexRef.current;
383
400
  const allSteps = compiledStepsRef.current;
384
401
  if (!allSteps[currentIndex]) return false;
402
+ navigationDirectionRef.current = "forward";
385
403
  if (currentIndex >= allSteps.length - 1) return complete();
386
404
  const currentStepKey = allSteps[currentIndex].key;
387
405
  const navigationRevision = navigationRevisionRef.current + 1;
@@ -408,13 +426,18 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
408
426
  back: useCallback(() => {
409
427
  var _compiledStepsRef$cur3;
410
428
  if (!mountedRef.current || transitionPendingRef.current || currentStepIndexRef.current <= 0) return false;
429
+ let nextIndex = currentStepIndexRef.current - 1;
430
+ while (nextIndex >= 0 && isStepSkippable(nextIndex)) nextIndex -= 1;
431
+ if (nextIndex < 0) return false;
432
+ navigationDirectionRef.current = "backward";
411
433
  navigationRevisionRef.current += 1;
412
- const nextIndex = currentStepIndexRef.current - 1;
413
434
  currentStepIndexRef.current = nextIndex;
414
435
  currentStepKeyRef.current = (_compiledStepsRef$cur3 = compiledStepsRef.current[nextIndex]) === null || _compiledStepsRef$cur3 === void 0 ? void 0 : _compiledStepsRef$cur3.key;
415
436
  setCurrentStepIndex(nextIndex);
416
437
  return true;
417
- }, [])
438
+ }, [isStepSkippable]),
439
+ isStepSkippable,
440
+ navigationDirectionRef
418
441
  };
419
442
  };
420
443
  //#endregion
@@ -100,6 +100,8 @@ 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[];
@@ -164,6 +166,8 @@ interface PisellSelectionFlowController<TDraft, TDraftUpdate, TField extends str
164
166
  getState: () => SelectionFlowSnapshot<TDraft, TModuleType>;
165
167
  registerModuleHandle: (moduleKey: string, handle: FlowModuleHandle | null) => void;
166
168
  getModuleHandle: (moduleKey: string) => FlowModuleHandle | undefined;
169
+ /** True only when every module in the step is ready and explicitly permits skipping. */
170
+ isStepSkippable: (stepIndex: number) => boolean;
167
171
  }
168
172
  interface PisellSelectionFlowProps<TDraft, TDraftUpdate, TField extends string, TModuleType extends string, TServices = unknown, THostContext = unknown> {
169
173
  registry: SelectionFlowModuleRegistry<TDraft, TDraftUpdate, TField, TModuleType, TServices, THostContext>;
@@ -300,7 +300,7 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
300
300
  draft,
301
301
  moduleState
302
302
  });
303
- const { validateCurrentStep, prepareSteps, complete, next, back } = require_useFlowNavigation.useFlowNavigation({
303
+ const { validateCurrentStep, prepareSteps, complete, next, back, isStepSkippable, navigationDirectionRef } = require_useFlowNavigation.useFlowNavigation({
304
304
  registry,
305
305
  draftAdapter,
306
306
  createRuntimeIssue,
@@ -332,6 +332,27 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
332
332
  setCompletionReason,
333
333
  setIsCompleting
334
334
  });
335
+ const autoAdvanceAttemptRef = (0, react.useRef)();
336
+ (0, react.useEffect)(() => {
337
+ if (configurationError || completedRef.current || transitionPendingRef.current || !currentStep || !isStepSkippable(resolvedCurrentStepIndex)) return;
338
+ const direction = navigationDirectionRef.current;
339
+ const key = `${direction}:${currentStep.key}:${draftRevisionRef.current}:${currentStep.modules.map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|")}`;
340
+ if (autoAdvanceAttemptRef.current === key) return;
341
+ autoAdvanceAttemptRef.current = key;
342
+ if (direction === "backward") back();
343
+ else next();
344
+ }, [
345
+ configurationError,
346
+ currentStep,
347
+ resolvedCurrentStepIndex,
348
+ moduleState,
349
+ moduleData,
350
+ draft,
351
+ isStepSkippable,
352
+ navigationDirectionRef,
353
+ back,
354
+ next
355
+ ]);
335
356
  const getState = (0, react.useCallback)(() => {
336
357
  const stepIndex = currentStepIndexRef.current;
337
358
  return {
@@ -389,7 +410,8 @@ const SelectionFlow = ({ registry, draftAdapter, steps, initialDraft, initialSte
389
410
  back,
390
411
  getState,
391
412
  registerModuleHandle,
392
- getModuleHandle
413
+ getModuleHandle,
414
+ isStepSkippable
393
415
  };
394
416
  return /* @__PURE__ */ react.default.createElement(require_context.SelectionFlowProvider, { value: contextValue }, children(controller));
395
417
  };
@@ -7,6 +7,22 @@ let react = require("react");
7
7
  //#region src/components/PisellSelectionFlow/hooks/useFlowNavigation.ts
8
8
  /** 导航、校验与提交门禁独立于模块加载生命周期。 */
9
9
  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 }) => {
10
+ const navigationDirectionRef = (0, react.useRef)("forward");
11
+ const isStepSkippable = (0, react.useCallback)((stepIndex) => {
12
+ const step = compiledStepsRef.current[stepIndex];
13
+ const context = getFreshContext();
14
+ if (!(step === null || step === void 0 ? void 0 : step.modules.length) || !context) return false;
15
+ return step.modules.every((module) => {
16
+ var _moduleStateRef$curre;
17
+ if (((_moduleStateRef$curre = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre === void 0 ? void 0 : _moduleStateRef$curre.status) !== "ready") return false;
18
+ try {
19
+ var _resolveFlowModuleAda, _resolveFlowModuleAda2;
20
+ return ((_resolveFlowModuleAda = require_compiler.resolveFlowModuleAdapter(registry, module.type)) === null || _resolveFlowModuleAda === void 0 || (_resolveFlowModuleAda2 = _resolveFlowModuleAda.isSkippable) === null || _resolveFlowModuleAda2 === void 0 ? void 0 : _resolveFlowModuleAda2.call(_resolveFlowModuleAda, context, module)) === true;
21
+ } catch (_unused) {
22
+ return false;
23
+ }
24
+ });
25
+ }, [getFreshContext, registry]);
10
26
  const validateModule = (0, react.useCallback)(function() {
11
27
  var _ref = require_asyncToGenerator._asyncToGenerator(function* (module) {
12
28
  const adapter = require_compiler.resolveFlowModuleAdapter(registry, module.type);
@@ -181,16 +197,16 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
181
197
  }
182
198
  }
183
199
  if (!targetModules.find(({ module }) => {
184
- var _moduleStateRef$curre;
185
- return ((_moduleStateRef$curre = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre === void 0 ? void 0 : _moduleStateRef$curre.status) !== "ready";
200
+ var _moduleStateRef$curre2;
201
+ return ((_moduleStateRef$curre2 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre2 === void 0 ? void 0 : _moduleStateRef$curre2.status) !== "ready";
186
202
  })) return isCurrentPreparation() ? { prepared: true } : {
187
203
  prepared: false,
188
204
  cancelled: true
189
205
  };
190
206
  }
191
207
  const unresolved = targetModules.find(({ module }) => {
192
- var _moduleStateRef$curre2;
193
- return ((_moduleStateRef$curre2 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre2 === void 0 ? void 0 : _moduleStateRef$curre2.status) !== "ready";
208
+ var _moduleStateRef$curre3;
209
+ return ((_moduleStateRef$curre3 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre3 === void 0 ? void 0 : _moduleStateRef$curre3.status) !== "ready";
194
210
  });
195
211
  return unresolved ? {
196
212
  prepared: false,
@@ -289,8 +305,8 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
289
305
  const latestRevisionFingerprint = latestSteps.flatMap((step) => step.modules).map((module) => `${module.key}:${moduleRevisionRef.current.get(module.key) || 0}`).join("|");
290
306
  if (compiledFingerprint !== latestCompiledFingerprint || revisionFingerprint !== latestRevisionFingerprint || draftRevision !== draftRevisionRef.current) {
291
307
  const targetStep = latestSteps.find((step) => step.modules.some((module) => {
292
- var _moduleStateRef$curre3;
293
- return ((_moduleStateRef$curre3 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre3 === void 0 ? void 0 : _moduleStateRef$curre3.status) !== "ready";
308
+ var _moduleStateRef$curre4;
309
+ return ((_moduleStateRef$curre4 = moduleStateRef.current[module.key]) === null || _moduleStateRef$curre4 === void 0 ? void 0 : _moduleStateRef$curre4.status) !== "ready";
294
310
  })) || latestSteps[0];
295
311
  const targetModule = targetStep === null || targetStep === void 0 ? void 0 : targetStep.modules[0];
296
312
  if (targetStep && targetModule) {
@@ -329,6 +345,7 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
329
345
  if (completedRef.current) return Promise.resolve(true);
330
346
  if (completionPromiseRef.current) return completionPromiseRef.current;
331
347
  if (transitionPendingRef.current) return Promise.resolve(false);
348
+ navigationDirectionRef.current = "forward";
332
349
  transitionPendingRef.current = true;
333
350
  const navigationRevision = navigationRevisionRef.current + 1;
334
351
  navigationRevisionRef.current = navigationRevision;
@@ -383,6 +400,7 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
383
400
  const currentIndex = currentStepIndexRef.current;
384
401
  const allSteps = compiledStepsRef.current;
385
402
  if (!allSteps[currentIndex]) return false;
403
+ navigationDirectionRef.current = "forward";
386
404
  if (currentIndex >= allSteps.length - 1) return complete();
387
405
  const currentStepKey = allSteps[currentIndex].key;
388
406
  const navigationRevision = navigationRevisionRef.current + 1;
@@ -409,13 +427,18 @@ const useFlowNavigation = ({ registry, draftAdapter, createRuntimeIssue, mounted
409
427
  back: (0, react.useCallback)(() => {
410
428
  var _compiledStepsRef$cur3;
411
429
  if (!mountedRef.current || transitionPendingRef.current || currentStepIndexRef.current <= 0) return false;
430
+ let nextIndex = currentStepIndexRef.current - 1;
431
+ while (nextIndex >= 0 && isStepSkippable(nextIndex)) nextIndex -= 1;
432
+ if (nextIndex < 0) return false;
433
+ navigationDirectionRef.current = "backward";
412
434
  navigationRevisionRef.current += 1;
413
- const nextIndex = currentStepIndexRef.current - 1;
414
435
  currentStepIndexRef.current = nextIndex;
415
436
  currentStepKeyRef.current = (_compiledStepsRef$cur3 = compiledStepsRef.current[nextIndex]) === null || _compiledStepsRef$cur3 === void 0 ? void 0 : _compiledStepsRef$cur3.key;
416
437
  setCurrentStepIndex(nextIndex);
417
438
  return true;
418
- }, [])
439
+ }, [isStepSkippable]),
440
+ isStepSkippable,
441
+ navigationDirectionRef
419
442
  };
420
443
  };
421
444
  //#endregion
@@ -100,6 +100,8 @@ 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[];
@@ -164,6 +166,8 @@ interface PisellSelectionFlowController<TDraft, TDraftUpdate, TField extends str
164
166
  getState: () => SelectionFlowSnapshot<TDraft, TModuleType>;
165
167
  registerModuleHandle: (moduleKey: string, handle: FlowModuleHandle | null) => void;
166
168
  getModuleHandle: (moduleKey: string) => FlowModuleHandle | undefined;
169
+ /** True only when every module in the step is ready and explicitly permits skipping. */
170
+ isStepSkippable: (stepIndex: number) => boolean;
167
171
  }
168
172
  interface PisellSelectionFlowProps<TDraft, TDraftUpdate, TField extends string, TModuleType extends string, TServices = unknown, THostContext = unknown> {
169
173
  registry: SelectionFlowModuleRegistry<TDraft, TDraftUpdate, TField, TModuleType, TServices, THostContext>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pisell/materials",
3
- "version": "1.10.32",
3
+ "version": "1.10.33",
4
4
  "scripts": {
5
5
  "dev:tailwind-css": "tailwindcss -c ./tailwind.materials.config.cjs --postcss ./postcss.materials-tailwind.cjs -i ./src/tailwind-input.css -o ./src/pisell-materials.tw.css --watch",
6
6
  "build:tailwind-css:once": "tailwindcss -c ./tailwind.materials.config.cjs --postcss ./postcss.materials-tailwind.cjs -i ./src/tailwind-input.css -o ./src/pisell-materials.tw.css",