@mohasinac/appkit 4.21.0 → 4.22.0

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 (38) hide show
  1. package/dist/client.d.ts +5 -0
  2. package/dist/client.js +3 -0
  3. package/dist/features/account/components/AddressForm.js +45 -29
  4. package/dist/features/admin/components/AdminBundleEditorView.js +3 -0
  5. package/dist/features/auctions/components/PlaceBidFormClient.js +3 -1
  6. package/dist/features/catalogue/components/CatalogueItemEditorView.js +3 -1
  7. package/dist/features/layout/BottomActions.js +18 -1
  8. package/dist/features/layout/BottomActionsContext.d.ts +19 -0
  9. package/dist/features/layout/BottomActionsContext.js +37 -0
  10. package/dist/features/layout/hooks/useBottomActions.d.ts +10 -0
  11. package/dist/features/layout/hooks/useBottomActions.js +48 -11
  12. package/dist/features/layout/hooks/useFormBottomActions.d.ts +57 -0
  13. package/dist/features/layout/hooks/useFormBottomActions.js +89 -0
  14. package/dist/features/layout/index.d.ts +2 -0
  15. package/dist/features/layout/index.js +1 -0
  16. package/dist/features/products/components/MakeOfferButton.js +5 -3
  17. package/dist/features/shell/QuickFormDrawer.js +15 -1
  18. package/dist/features/shell/SectionForm.d.ts +16 -2
  19. package/dist/features/shell/SectionForm.js +28 -2
  20. package/dist/features/shipments/components/AdminShipmentEditorView.js +3 -1
  21. package/dist/features/tester/seed-data/tester-checklist-seed-data.js +36 -0
  22. package/dist/index.d.ts +3 -0
  23. package/dist/index.js +4 -0
  24. package/dist/ui/components/Form.d.ts +22 -1
  25. package/dist/ui/components/Form.js +30 -2
  26. package/dist/ui/components/Modal.js +4 -3
  27. package/dist/ui/components/SideDrawer.js +5 -4
  28. package/dist/ui/components/overlay-context.d.ts +21 -0
  29. package/dist/ui/components/overlay-context.js +25 -0
  30. package/dist/ui/forms/FormErrorList.d.ts +29 -0
  31. package/dist/ui/forms/FormErrorList.js +36 -0
  32. package/dist/ui/forms/FormErrorSummary.d.ts +8 -0
  33. package/dist/ui/forms/FormErrorSummary.js +15 -8
  34. package/dist/ui/forms/FormShell.d.ts +25 -1
  35. package/dist/ui/forms/FormShell.js +39 -4
  36. package/dist/ui/forms/index.d.ts +2 -0
  37. package/dist/ui/forms/index.js +1 -0
  38. package/package.json +1 -1
@@ -45,6 +45,9 @@ export function applyZodIssues(issues, setFieldError) {
45
45
  */
46
46
  export function useFormShellState(schema, nav) {
47
47
  const [errors, setErrors] = useState({});
48
+ const [submitAttemptCount, setSubmitAttemptCount] = useState(0);
49
+ const markSubmitAttempted = useCallback(() => setSubmitAttemptCount((n) => n + 1), []);
50
+ const submitAttempted = submitAttemptCount > 0;
48
51
  const setFieldError = useCallback((name, error) => {
49
52
  setErrors((prev) => {
50
53
  if (!error) {
@@ -59,6 +62,19 @@ export function useFormShellState(schema, nav) {
59
62
  }, []);
60
63
  const clearErrors = useCallback(() => setErrors({}), []);
61
64
  const validate = useCallback((values) => {
65
+ /*
66
+ * 🛑 validate() does NOT mark the submit attempt, and must not.
67
+ *
68
+ * ELEVEN views call `validate(draft)` from a MOUNT EFFECT to keep the
69
+ * summary and the submit-button state live as the user types — which
70
+ * is the behaviour worth having. Marking here would fire on first
71
+ * paint in exactly those views and defeat the gate entirely.
72
+ *
73
+ * The attempt is marked where an attempt actually happens: <Form>'s
74
+ * native submit handler, <SectionForm>'s submit button, and
75
+ * QuickFormDrawer's. A caller whose submit is an onClick on a
76
+ * type="button" calls markSubmitAttempted() itself.
77
+ */
62
78
  if (!schema)
63
79
  return values;
64
80
  const parsed = schema.safeParse(values);
@@ -90,12 +106,28 @@ export function useFormShellState(schema, nav) {
90
106
  isSubmitting: false,
91
107
  stepErrorCounts: [],
92
108
  fieldToStepIndex: navFieldMap,
93
- }), [errors, setFieldError, navSections, navGoTo, navFieldMap]);
94
- return { shellCtx, setFieldError, clearErrors, hasErrors: Object.keys(errors).length > 0, validate };
109
+ submitAttempted,
110
+ submitAttemptCount,
111
+ markSubmitAttempted,
112
+ }), [errors, setFieldError, navSections, navGoTo, navFieldMap, submitAttempted, submitAttemptCount, markSubmitAttempted]);
113
+ return {
114
+ shellCtx,
115
+ setFieldError,
116
+ clearErrors,
117
+ hasErrors: Object.keys(errors).length > 0,
118
+ validate,
119
+ submitAttempted,
120
+ submitAttemptCount,
121
+ markSubmitAttempted,
122
+ };
95
123
  }
96
- export function FormShellProvider({ children, onSaveDraft, isDirty = false, autoSaveDelayMs = 2000, values = {}, schema, fieldToStepIndex, onGoToStep, sections, }) {
124
+ export function FormShellProvider({ children, onSaveDraft, isDirty = false, autoSaveDelayMs = 2000, values = {}, schema, fieldToStepIndex, onGoToStep, sections, submitAttempted: submitAttemptedProp = false, }) {
97
125
  const [errors, setErrors] = useState({});
98
126
  const [touched, setTouched] = useState({});
127
+ const [ownAttemptCount, setOwnAttemptCount] = useState(0);
128
+ const markSubmitAttempted = useCallback(() => setOwnAttemptCount((n) => n + 1), []);
129
+ const submitAttemptCount = ownAttemptCount + (submitAttemptedProp ? 1 : 0);
130
+ const submitAttempted = submitAttemptCount > 0;
99
131
  const autoSaveTimer = useRef(null);
100
132
  const valuesRef = useRef(values);
101
133
  valuesRef.current = values;
@@ -169,6 +201,9 @@ export function FormShellProvider({ children, onSaveDraft, isDirty = false, auto
169
201
  isSubmitting: false,
170
202
  stepErrorCounts: [],
171
203
  fieldToStepIndex,
172
- }), [errors, touched, setFieldError, setFieldTouched, clearFieldError, isDirty, onGoToStep, fieldToStepIndex, sections]);
204
+ submitAttempted,
205
+ submitAttemptCount,
206
+ markSubmitAttempted,
207
+ }), [errors, touched, setFieldError, setFieldTouched, clearFieldError, isDirty, onGoToStep, fieldToStepIndex, sections, submitAttempted, submitAttemptCount, markSubmitAttempted]);
173
208
  return _jsx(FormShellContext.Provider, { value: ctx, children: children });
174
209
  }
@@ -12,3 +12,5 @@ export type { ColorPickerFieldProps } from "./ColorPickerField";
12
12
  export { ColorPickerField } from "./ColorPickerField";
13
13
  export type { FormErrorSummaryProps } from "./FormErrorSummary";
14
14
  export { FormErrorSummary } from "./FormErrorSummary";
15
+ export type { FormErrorListProps } from "./FormErrorList";
16
+ export { FormErrorList } from "./FormErrorList";
@@ -5,3 +5,4 @@ export { FieldCheckbox } from "./FieldCheckbox";
5
5
  export { FieldTextarea } from "./FieldTextarea";
6
6
  export { ColorPickerField } from "./ColorPickerField";
7
7
  export { FormErrorSummary } from "./FormErrorSummary";
8
+ export { FormErrorList } from "./FormErrorList";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mohasinac/appkit",
3
- "version": "4.21.0",
3
+ "version": "4.22.0",
4
4
  "license": "MIT",
5
5
  "publishConfig": {
6
6
  "access": "public"