@mohasinac/appkit 4.14.0 → 4.16.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 (206) hide show
  1. package/dist/_internal/server/features/auctions/actions.js +2 -2
  2. package/dist/_internal/server/features/cart/service.d.ts +3 -3
  3. package/dist/_internal/server/features/checkout/actions.js +19 -0
  4. package/dist/_internal/server/features/checkout/source-context.d.ts +5 -0
  5. package/dist/_internal/server/features/checkout/source-context.js +157 -0
  6. package/dist/_internal/server/features/offers/adapters.d.ts +103 -0
  7. package/dist/_internal/server/features/offers/adapters.js +88 -0
  8. package/dist/_internal/server/features/offers/index.d.ts +2 -0
  9. package/dist/_internal/server/features/offers/index.js +1 -0
  10. package/dist/_internal/server/features/orders/adapters.js +24 -0
  11. package/dist/_internal/server/jobs/core/offerExpiry.js +10 -10
  12. package/dist/_internal/shared/actions/action-registry.d.ts +9 -2
  13. package/dist/_internal/shared/actions/action-registry.js +458 -7
  14. package/dist/_internal/shared/features/auctions/schema.d.ts +14 -2
  15. package/dist/_internal/shared/features/auctions/schema.js +13 -1
  16. package/dist/_internal/shared/features/blog/schema.d.ts +4 -4
  17. package/dist/_internal/shared/features/cart/schema.d.ts +25 -20
  18. package/dist/_internal/shared/features/cart/schema.js +15 -0
  19. package/dist/_internal/shared/features/categories/bundle-schemas.d.ts +22 -22
  20. package/dist/_internal/shared/features/orders/schema.d.ts +4 -4
  21. package/dist/_internal/shared/features/products/schema.d.ts +27 -27
  22. package/dist/_internal/shared/features/promotions/schema.d.ts +4 -4
  23. package/dist/_internal/shared/features/reviews/schema.d.ts +2 -2
  24. package/dist/_internal/shared/history/history.d.ts +22 -0
  25. package/dist/_internal/shared/history/history.js +41 -1
  26. package/dist/client.d.ts +13 -2
  27. package/dist/client.js +20 -2
  28. package/dist/constants/field-names.d.ts +8 -6
  29. package/dist/constants/field-names.js +48 -6
  30. package/dist/contracts/extend.d.ts +29 -0
  31. package/dist/contracts/extend.js +20 -0
  32. package/dist/contracts/index.d.ts +2 -1
  33. package/dist/contracts/index.js +2 -0
  34. package/dist/features/account/components/UserBidsView.js +12 -4
  35. package/dist/features/account/components/UserReturnsView.d.ts +3 -0
  36. package/dist/features/account/components/UserReturnsView.js +17 -1
  37. package/dist/features/admin/components/AdminAuditLogView.js +1 -0
  38. package/dist/features/admin/components/AdminBidsView.js +15 -2
  39. package/dist/features/admin/components/AdminBlogEditorView.js +65 -33
  40. package/dist/features/admin/components/AdminFeatureEditorView.js +35 -6
  41. package/dist/features/admin/components/AdminNavEditorView.js +15 -5
  42. package/dist/features/admin/components/AdminNewsletterView.js +18 -2
  43. package/dist/features/admin/components/AdminOffersView.js +62 -18
  44. package/dist/features/admin/components/AdminPaymentMethodsView.js +24 -4
  45. package/dist/features/admin/components/AdminScammerEditorView.d.ts +2 -1
  46. package/dist/features/admin/components/AdminScammerEditorView.js +3 -13
  47. package/dist/features/admin/components/AdminScammersView.js +3 -8
  48. package/dist/features/admin/components/AdminSectionsView.js +32 -23
  49. package/dist/features/admin/components/AdminSessionsView.js +17 -2
  50. package/dist/features/admin/components/AdminViewCards.js +24 -17
  51. package/dist/features/admin/components/DataListingView.js +15 -1
  52. package/dist/features/admin/components/DataTable.js +7 -17
  53. package/dist/features/admin/components/ViewAuditLogEntryModal.js +1 -0
  54. package/dist/features/admin/components/sections/adminSectionsTypes.d.ts +4 -2
  55. package/dist/features/admin/components/sections/adminSectionsTypes.js +45 -27
  56. package/dist/features/admin/constants/filter-tabs.d.ts +3 -0
  57. package/dist/features/admin/constants/filter-tabs.js +1 -0
  58. package/dist/features/admin/schemas/homepage-section-form.d.ts +22 -0
  59. package/dist/features/admin/schemas/homepage-section-form.js +68 -0
  60. package/dist/features/admin/schemas/nav-item-form.d.ts +74 -0
  61. package/dist/features/admin/schemas/nav-item-form.js +72 -0
  62. package/dist/features/auctions/components/AuctionBidsTable.d.ts +10 -1
  63. package/dist/features/auctions/components/AuctionBidsTable.js +22 -4
  64. package/dist/features/auctions/components/bid-detail-fields.d.ts +29 -0
  65. package/dist/features/auctions/components/bid-detail-fields.js +103 -0
  66. package/dist/features/auctions/schemas/index.d.ts +14 -14
  67. package/dist/features/audit-log/schemas/firestore.d.ts +14 -0
  68. package/dist/features/audit-log/schemas/firestore.js +7 -0
  69. package/dist/features/auth/schemas/index.d.ts +2 -2
  70. package/dist/features/blog/actions/blog-actions.d.ts +7 -7
  71. package/dist/features/blog/schemas/blog-form.d.ts +80 -0
  72. package/dist/features/blog/schemas/blog-form.js +100 -0
  73. package/dist/features/blog/schemas/index.d.ts +10 -10
  74. package/dist/features/cart/schemas/index.d.ts +3 -3
  75. package/dist/features/catalogue/schemas/validation.d.ts +12 -12
  76. package/dist/features/categories/schemas/index.d.ts +16 -16
  77. package/dist/features/collections/schemas/index.d.ts +8 -8
  78. package/dist/features/events/components/AdminEventEditorView.js +32 -54
  79. package/dist/features/events/components/AdminEventEntriesView.js +22 -3
  80. package/dist/features/events/schemas/event-form.d.ts +113 -0
  81. package/dist/features/events/schemas/event-form.js +82 -0
  82. package/dist/features/events/schemas/index.d.ts +2 -2
  83. package/dist/features/faq/actions/faq-actions.d.ts +6 -6
  84. package/dist/features/faq/schemas/index.d.ts +6 -6
  85. package/dist/features/grouped/schemas/grouped-listing-form.d.ts +101 -0
  86. package/dist/features/grouped/schemas/grouped-listing-form.js +89 -0
  87. package/dist/features/grouped/schemas/index.d.ts +4 -4
  88. package/dist/features/homepage/actions/homepage-section-actions.d.ts +11 -3
  89. package/dist/features/homepage/actions/homepage-section-actions.js +33 -1
  90. package/dist/features/homepage/schemas/index.d.ts +71 -40
  91. package/dist/features/homepage/schemas/index.js +24 -0
  92. package/dist/features/messages/schemas/index.d.ts +2 -2
  93. package/dist/features/orders/components/OrderStatusTimeline.d.ts +5 -1
  94. package/dist/features/orders/components/OrderStatusTimeline.js +39 -20
  95. package/dist/features/orders/repository/orders.repository.js +5 -0
  96. package/dist/features/orders/schemas/firestore.d.ts +36 -1
  97. package/dist/features/orders/schemas/index.d.ts +24 -24
  98. package/dist/features/orders/types/index.d.ts +35 -7
  99. package/dist/features/pre-orders/schemas/index.d.ts +4 -4
  100. package/dist/features/products/components/GroupSettingsPanel.js +5 -1
  101. package/dist/features/products/schemas/index.d.ts +38 -38
  102. package/dist/features/products/schemas/product-features.validators.d.ts +75 -2
  103. package/dist/features/products/schemas/product-features.validators.js +63 -0
  104. package/dist/features/promotions/schemas/index.d.ts +14 -14
  105. package/dist/features/reviews/schemas/index.d.ts +14 -14
  106. package/dist/features/scams/constants/scammer-status-display.d.ts +28 -0
  107. package/dist/features/scams/constants/scammer-status-display.js +79 -0
  108. package/dist/features/scams/schemas/index.d.ts +2 -2
  109. package/dist/features/search/schemas/index.d.ts +2 -2
  110. package/dist/features/seller/actions/offer-actions.js +32 -2
  111. package/dist/features/seller/components/OfferPhaseTimeline.d.ts +59 -0
  112. package/dist/features/seller/components/OfferPhaseTimeline.js +107 -0
  113. package/dist/features/seller/components/SellerBidsView.js +11 -4
  114. package/dist/features/seller/components/SellerCouponEditorView.js +17 -17
  115. package/dist/features/seller/components/SellerOffersView.js +2 -1
  116. package/dist/features/seller/components/SellerPayoutSettingsView.js +38 -14
  117. package/dist/features/seller/repository/offer.repository.d.ts +69 -8
  118. package/dist/features/seller/repository/offer.repository.js +127 -23
  119. package/dist/features/seller/schemas/coupon-form.d.ts +72 -0
  120. package/dist/features/seller/schemas/coupon-form.js +116 -0
  121. package/dist/features/seller/schemas/firestore.d.ts +56 -2
  122. package/dist/features/seller/schemas/firestore.js +27 -0
  123. package/dist/features/seller/schemas/index.d.ts +2 -2
  124. package/dist/features/seller/schemas/offer-forms.d.ts +21 -0
  125. package/dist/features/seller/schemas/offer-forms.js +21 -0
  126. package/dist/features/shell/build-sections.d.ts +63 -0
  127. package/dist/features/shell/build-sections.js +207 -0
  128. package/dist/features/shell/field-ui-meta.d.ts +115 -0
  129. package/dist/features/shell/field-ui-meta.js +324 -0
  130. package/dist/features/shell/index.d.ts +4 -0
  131. package/dist/features/shell/index.js +2 -0
  132. package/dist/features/shipments/schemas/validation.d.ts +22 -22
  133. package/dist/features/status-history/components/StatusTimeline.d.ts +74 -0
  134. package/dist/features/status-history/components/StatusTimeline.js +46 -0
  135. package/dist/features/status-history/index.d.ts +11 -0
  136. package/dist/features/status-history/index.js +10 -0
  137. package/dist/features/store-extensions/components/ReviewDecisionModal.d.ts +27 -0
  138. package/dist/features/store-extensions/components/ReviewDecisionModal.js +82 -0
  139. package/dist/features/store-extensions/index.d.ts +12 -0
  140. package/dist/features/store-extensions/index.js +12 -0
  141. package/dist/features/store-extensions/schemas/admin-notification-form.d.ts +36 -0
  142. package/dist/features/store-extensions/schemas/admin-notification-form.js +114 -0
  143. package/dist/features/store-extensions/schemas/analytics-forms.d.ts +57 -0
  144. package/dist/features/store-extensions/schemas/analytics-forms.js +158 -0
  145. package/dist/features/store-extensions/schemas/custom-role-form.d.ts +85 -0
  146. package/dist/features/store-extensions/schemas/custom-role-form.js +118 -0
  147. package/dist/features/store-extensions/schemas/firestore.d.ts +21 -1
  148. package/dist/features/store-extensions/schemas/firestore.js +60 -0
  149. package/dist/features/store-extensions/schemas/google-config-form.d.ts +53 -0
  150. package/dist/features/store-extensions/schemas/google-config-form.js +105 -0
  151. package/dist/features/store-extensions/schemas/item-request-create-form.d.ts +28 -0
  152. package/dist/features/store-extensions/schemas/item-request-create-form.js +80 -0
  153. package/dist/features/store-extensions/schemas/listing-template-form.d.ts +78 -0
  154. package/dist/features/store-extensions/schemas/listing-template-form.js +87 -0
  155. package/dist/features/store-extensions/schemas/moderation-review-form.d.ts +49 -0
  156. package/dist/features/store-extensions/schemas/moderation-review-form.js +101 -0
  157. package/dist/features/store-extensions/schemas/payout-method-form.d.ts +153 -0
  158. package/dist/features/store-extensions/schemas/payout-method-form.js +155 -0
  159. package/dist/features/store-extensions/schemas/report-create-form.d.ts +25 -0
  160. package/dist/features/store-extensions/schemas/report-create-form.js +79 -0
  161. package/dist/features/store-extensions/schemas/report-review-form.d.ts +47 -0
  162. package/dist/features/store-extensions/schemas/report-review-form.js +111 -0
  163. package/dist/features/store-extensions/schemas/shipping-config-form.d.ts +148 -0
  164. package/dist/features/store-extensions/schemas/shipping-config-form.js +104 -0
  165. package/dist/features/store-extensions/schemas/store-category-form.d.ts +54 -0
  166. package/dist/features/store-extensions/schemas/store-category-form.js +73 -0
  167. package/dist/features/stores/schemas/index.d.ts +4 -4
  168. package/dist/features/support/schemas/index.d.ts +4 -4
  169. package/dist/features/tester/seed-data/tester-checklist-seed-data.js +350 -0
  170. package/dist/features/wishlist/hooks/useWishlistWithGuest.d.ts +1 -1
  171. package/dist/index.d.ts +12 -2
  172. package/dist/index.js +12 -2
  173. package/dist/next/routing/route-map.d.ts +16 -2
  174. package/dist/next/routing/route-map.js +9 -2
  175. package/dist/schemas/firestore-value.d.ts +8 -0
  176. package/dist/schemas/firestore-value.js +44 -0
  177. package/dist/schemas/index.d.ts +1 -1
  178. package/dist/schemas/index.js +1 -1
  179. package/dist/schemas/registry.d.ts +734 -101
  180. package/dist/schemas/registry.js +64 -1
  181. package/dist/seed/bids-seed-data.js +30 -0
  182. package/dist/seed/offers-seed-data.js +212 -7
  183. package/dist/seed/orders-seed-data.js +336 -1
  184. package/dist/seed/products-auctions-seed-data.js +41 -0
  185. package/dist/server.d.ts +2 -0
  186. package/dist/server.js +5 -0
  187. package/dist/styles.css +1 -1
  188. package/dist/tailwind-utilities.css +1 -1
  189. package/dist/ui/DataTable.js +4 -2
  190. package/dist/ui/columns/build-columns.d.ts +6 -1
  191. package/dist/ui/columns/build-columns.js +53 -0
  192. package/dist/ui/columns/cell-renderers.d.ts +68 -0
  193. package/dist/ui/columns/cell-renderers.js +111 -0
  194. package/dist/ui/columns/column-renderers.d.ts +6 -1
  195. package/dist/ui/columns/column-renderers.js +6 -1
  196. package/dist/ui/columns/index.d.ts +2 -1
  197. package/dist/ui/columns/index.js +5 -1
  198. package/dist/ui/components/Button.js +27 -2
  199. package/dist/ui/components/RecordDetailModal.d.ts +10 -1
  200. package/dist/ui/components/RecordDetailModal.js +2 -2
  201. package/dist/ui/icons/icon-registry.d.ts +65 -0
  202. package/dist/ui/icons/icon-registry.js +115 -0
  203. package/package.json +2 -1
  204. package/scripts/node-esm-loader.mjs +65 -0
  205. package/scripts/seed-cli-loader.mjs +6 -49
  206. package/scripts/seed-cli.mjs +1 -1
@@ -35,3 +35,24 @@ export declare function makeOfferFormSchema(opts: {
35
35
  buyerNote?: string | undefined;
36
36
  }>;
37
37
  export type MakeOfferFormValues = z.infer<ReturnType<typeof makeOfferFormSchema>>;
38
+ /**
39
+ * Admin cancel-offer form.
40
+ *
41
+ * A bare confirm dialog was the wrong control here. Admin cancel is an
42
+ * escalation over the store's own authority, and it lands in three permanent
43
+ * places at once — the buyer's notification, the offer's own status history,
44
+ * and `adminAuditLog`. All three are useless without a reason, and the route
45
+ * used to accept an optional one and never read it.
46
+ *
47
+ * The 10-character floor mirrors the server schema exactly. Stating it in both
48
+ * places is deliberate: the client bound exists so the admin is told before
49
+ * submitting, not so the server can trust it.
50
+ */
51
+ export declare const cancelOfferFormSchema: z.ZodObject<{
52
+ reason: z.ZodString;
53
+ }, "strip", z.ZodTypeAny, {
54
+ reason: string;
55
+ }, {
56
+ reason: string;
57
+ }>;
58
+ export type CancelOfferFormValues = z.infer<typeof cancelOfferFormSchema>;
@@ -11,6 +11,8 @@
11
11
  *
12
12
  * EXPORTS:
13
13
  * counterOfferFormSchema, type CounterOfferFormValues
14
+ * makeOfferFormSchema, type MakeOfferFormValues
15
+ * cancelOfferFormSchema, type CancelOfferFormValues
14
16
  *
15
17
  * @tag domain:seller,offers
16
18
  * @tag layer:schema
@@ -47,3 +49,22 @@ export function makeOfferFormSchema(opts) {
47
49
  buyerNote: z.string().max(300, "Keep your note under 300 characters.").optional(),
48
50
  });
49
51
  }
52
+ /**
53
+ * Admin cancel-offer form.
54
+ *
55
+ * A bare confirm dialog was the wrong control here. Admin cancel is an
56
+ * escalation over the store's own authority, and it lands in three permanent
57
+ * places at once — the buyer's notification, the offer's own status history,
58
+ * and `adminAuditLog`. All three are useless without a reason, and the route
59
+ * used to accept an optional one and never read it.
60
+ *
61
+ * The 10-character floor mirrors the server schema exactly. Stating it in both
62
+ * places is deliberate: the client bound exists so the admin is told before
63
+ * submitting, not so the server can trust it.
64
+ */
65
+ export const cancelOfferFormSchema = z.object({
66
+ reason: z
67
+ .string()
68
+ .min(10, "Give a reason of at least 10 characters — the buyer sees this.")
69
+ .max(300, "Keep the reason under 300 characters."),
70
+ });
@@ -0,0 +1,63 @@
1
+ import { type ReactNode } from "react";
2
+ import type { ZodTypeAny } from "zod";
3
+ import type { SectionDef } from "./SectionForm";
4
+ import { type FieldUiMeta } from "./field-ui-meta";
5
+ /** One field, resolved: its name, its schema, and its final metadata. */
6
+ export interface ResolvedField {
7
+ name: string;
8
+ schema: ZodTypeAny;
9
+ meta: FieldUiMeta;
10
+ required: boolean;
11
+ }
12
+ /** Per-field JSX override. Receives everything the derived control would get. */
13
+ export type FieldRenderer<T extends object> = (props: {
14
+ field: ResolvedField;
15
+ values: T;
16
+ onChange: (partial: Partial<T>) => void;
17
+ errors: Record<string, string>;
18
+ }) => ReactNode;
19
+ export interface BuildSectionsOptions<T extends object> {
20
+ /** Per-field JSX overrides, keyed by field name. */
21
+ renderers?: Record<string, FieldRenderer<T>>;
22
+ /** Option lists for `kind: "select"` fields that aren't Zod enums. */
23
+ options?: Record<string, {
24
+ value: string;
25
+ label: string;
26
+ }[]>;
27
+ /** Section id → label, when no field declared `sectionLabel`. */
28
+ sectionLabels?: Record<string, string>;
29
+ /**
30
+ * Section ids in the order they should appear. Sections not listed follow,
31
+ * in first-declaration order. `sectionRequired` still sorts first regardless.
32
+ */
33
+ sectionOrder?: string[];
34
+ }
35
+ /**
36
+ * Resolve every field in a schema's shape.
37
+ *
38
+ * Fields with no registration are still returned, carrying inferred metadata
39
+ * and a `section` of `""`. Dropping them silently would hide the exact defect
40
+ * `audit-field-ui-meta` is meant to report — an unregistered field, or one
41
+ * whose `.register()` was not the last call in the chain and was therefore
42
+ * discarded by a subsequent `.optional()`.
43
+ */
44
+ export declare function resolveFields(schema: ZodTypeAny): ResolvedField[];
45
+ /** Group resolved fields by section, preserving declaration order within each. */
46
+ export declare function groupFieldsBySection(fields: ResolvedField[]): Map<string, ResolvedField[]>;
47
+ /**
48
+ * Pack consecutive fields into rows by their span.
49
+ *
50
+ * A `full` field always breaks the current row — that is what stops a media
51
+ * upload or a textarea being squeezed alongside a short input. Mixed spans
52
+ * start a new row too, rather than being crammed together: two `pair` fields
53
+ * make a clean 2-up, a `pair` next to a `quarter` makes neither.
54
+ */
55
+ export declare function packRows(fields: ResolvedField[]): ResolvedField[][];
56
+ /**
57
+ * Build the `SectionDef[]` a `<SectionForm>` renders.
58
+ *
59
+ * Section order: `sectionRequired` first (there is normally exactly one — the
60
+ * fields without which the record cannot be saved), then `sectionOrder`, then
61
+ * first-declaration order.
62
+ */
63
+ export declare function buildSectionsFromSchema<T extends object>(schema: ZodTypeAny, opts?: BuildSectionsOptions<T>): SectionDef<T>[];
@@ -0,0 +1,207 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
3
+ /*
4
+ * WHY: A `SectionDef[]` written by hand is a second source of truth that has to
5
+ * stay aligned with the schema that validates it. Nothing enforces the
6
+ * alignment, so a field added to the schema renders nowhere, and a field
7
+ * removed from the schema keeps rendering into a key that is stripped on
8
+ * save. `audit-form-field-roundtrip` exists to catch exactly that — this
9
+ * file removes the opportunity instead.
10
+ * WHAT: `buildSectionsFromSchema` — walk a schema's shape, group by
11
+ * `FieldUiMeta.section`, pack consecutive fields into `<FormGroup>` rows
12
+ * by their `row` span, and pick each control from its `kind`.
13
+ *
14
+ * Sections become DERIVED, exactly as quick mode already is. Adding a field to
15
+ * the schema puts it in the right section, in the right row, in the right mode,
16
+ * with one edit rather than three.
17
+ *
18
+ * ## The escape hatch is per field, not per form
19
+ *
20
+ * `renderers` overrides a single field's JSX while everything around it stays
21
+ * derived. That matters: a form with one bespoke control should not have to
22
+ * hand-write its other twelve fields, which is what an all-or-nothing escape
23
+ * hatch would force and is how hand-written section arrays got normalised in
24
+ * the first place.
25
+ *
26
+ * EXPORTS:
27
+ * buildSectionsFromSchema, groupFieldsBySection, packRows,
28
+ * type FieldRenderer, type BuildSectionsOptions
29
+ *
30
+ * @tag domain:forms
31
+ * @tag layer:shared
32
+ * @tag pattern:slot-shell
33
+ * @tag access:client
34
+ * @tag consumers:SectionForm callsites
35
+ * @tag sideEffects:none
36
+ */
37
+ import { Fragment } from "react";
38
+ import { FormGroup } from "../../ui/components/Form";
39
+ import { FieldInput } from "../../ui/forms/FieldInput";
40
+ import { FieldSelect } from "../../ui/forms/FieldSelect";
41
+ import { FieldTextarea } from "../../ui/forms/FieldTextarea";
42
+ import { FieldCheckbox } from "../../ui/forms/FieldCheckbox";
43
+ import { humaniseFieldName } from "./entity-form";
44
+ import { ROW_COLUMNS, inferFieldUiMeta, objectShape, schemaEnumOptions, schemaIsOptional, ui, } from "./field-ui-meta";
45
+ /**
46
+ * Enum members as `<FieldSelect>` options.
47
+ *
48
+ * Both the zod-version handling and the optional/required test live in
49
+ * `field-ui-meta.ts` — this file must not grow a second copy, which is how the
50
+ * two majors' differing `_def` shapes would come to be handled inconsistently.
51
+ */
52
+ function selectOptions(schema) {
53
+ const options = schemaEnumOptions(schema);
54
+ return options ? options.map((o) => ({ value: o, label: humaniseFieldName(o) })) : null;
55
+ }
56
+ /**
57
+ * Resolve every field in a schema's shape.
58
+ *
59
+ * Fields with no registration are still returned, carrying inferred metadata
60
+ * and a `section` of `""`. Dropping them silently would hide the exact defect
61
+ * `audit-field-ui-meta` is meant to report — an unregistered field, or one
62
+ * whose `.register()` was not the last call in the chain and was therefore
63
+ * discarded by a subsequent `.optional()`.
64
+ */
65
+ export function resolveFields(schema) {
66
+ const shape = objectShape(schema);
67
+ if (!shape)
68
+ return [];
69
+ return Object.entries(shape).map(([name, fieldSchema]) => {
70
+ const explicit = ui.get(fieldSchema);
71
+ const meta = {
72
+ section: "",
73
+ ...inferFieldUiMeta(name, fieldSchema),
74
+ ...(explicit ?? {}),
75
+ };
76
+ return { name, schema: fieldSchema, meta, required: !schemaIsOptional(fieldSchema) };
77
+ });
78
+ }
79
+ /** Group resolved fields by section, preserving declaration order within each. */
80
+ export function groupFieldsBySection(fields) {
81
+ const bySection = new Map();
82
+ for (const field of fields) {
83
+ if (field.meta.derived)
84
+ continue; // server-owned — never an input
85
+ const key = field.meta.section || "advanced";
86
+ const bucket = bySection.get(key);
87
+ if (bucket)
88
+ bucket.push(field);
89
+ else
90
+ bySection.set(key, [field]);
91
+ }
92
+ for (const bucket of bySection.values()) {
93
+ bucket.sort((a, b) => (a.meta.order ?? Number.MAX_SAFE_INTEGER) - (b.meta.order ?? Number.MAX_SAFE_INTEGER));
94
+ }
95
+ return bySection;
96
+ }
97
+ /**
98
+ * Pack consecutive fields into rows by their span.
99
+ *
100
+ * A `full` field always breaks the current row — that is what stops a media
101
+ * upload or a textarea being squeezed alongside a short input. Mixed spans
102
+ * start a new row too, rather than being crammed together: two `pair` fields
103
+ * make a clean 2-up, a `pair` next to a `quarter` makes neither.
104
+ */
105
+ export function packRows(fields) {
106
+ const rows = [];
107
+ let current = [];
108
+ let currentSpan = null;
109
+ const flush = () => {
110
+ if (current.length > 0)
111
+ rows.push(current);
112
+ current = [];
113
+ currentSpan = null;
114
+ };
115
+ for (const field of fields) {
116
+ const span = field.meta.row ?? "pair";
117
+ if (span === "full") {
118
+ flush();
119
+ rows.push([field]);
120
+ continue;
121
+ }
122
+ if (currentSpan !== null && (span !== currentSpan || current.length >= ROW_COLUMNS[span])) {
123
+ flush();
124
+ }
125
+ current.push(field);
126
+ currentSpan = span;
127
+ }
128
+ flush();
129
+ return rows;
130
+ }
131
+ /**
132
+ * Build the `SectionDef[]` a `<SectionForm>` renders.
133
+ *
134
+ * Section order: `sectionRequired` first (there is normally exactly one — the
135
+ * fields without which the record cannot be saved), then `sectionOrder`, then
136
+ * first-declaration order.
137
+ */
138
+ export function buildSectionsFromSchema(schema, opts = {}) {
139
+ const fields = resolveFields(schema);
140
+ const bySection = groupFieldsBySection(fields);
141
+ const declarationOrder = [...bySection.keys()];
142
+ const explicitOrder = opts.sectionOrder ?? [];
143
+ const rank = (id) => {
144
+ const bucket = bySection.get(id) ?? [];
145
+ if (bucket.some((f) => f.meta.sectionRequired))
146
+ return -1;
147
+ const i = explicitOrder.indexOf(id);
148
+ return i === -1 ? explicitOrder.length + declarationOrder.indexOf(id) : i;
149
+ };
150
+ return declarationOrder
151
+ .slice()
152
+ .sort((a, b) => rank(a) - rank(b))
153
+ .map((sectionId) => {
154
+ const sectionFields = bySection.get(sectionId) ?? [];
155
+ const label = sectionFields.find((f) => f.meta.sectionLabel)?.meta.sectionLabel ??
156
+ opts.sectionLabels?.[sectionId] ??
157
+ humaniseFieldName(sectionId);
158
+ return {
159
+ id: sectionId,
160
+ label,
161
+ required: sectionFields.some((f) => f.meta.sectionRequired),
162
+ quick: sectionFields.some((f) => f.meta.quick),
163
+ // Any section holding uncommitted state must stay mounted while
164
+ // collapsed — `<Collapse>` unmounts children, which would discard an
165
+ // in-flight media upload. Inference sets this for every media field.
166
+ keepMounted: sectionFields.some((f) => f.meta.sectionKeepMounted),
167
+ fields: sectionFields.map((f) => f.name),
168
+ render: ({ values, onChange, errors }) => (_jsx(_Fragment, { children: packRows(sectionFields).map((row, i) => (_jsx(FormGroup, { columns: ROW_COLUMNS[row[0].meta.row ?? "pair"], children: row.map((field) => renderField(field, { values, onChange, errors }, opts)) }, `${sectionId}-row-${i}`))) })),
169
+ };
170
+ });
171
+ }
172
+ function renderField(field, ctx, opts) {
173
+ const override = opts.renderers?.[field.name];
174
+ // A keyed Fragment, not a wrapper element: an override may legitimately
175
+ // return a block-level control (a media uploader, a repeatable list editor),
176
+ // and wrapping that in a <span> would put block content inside an inline box.
177
+ if (override)
178
+ return _jsx(Fragment, { children: override({ field, ...ctx }) }, field.name);
179
+ const { name, meta, required } = field;
180
+ const label = meta.label ?? humaniseFieldName(name);
181
+ const value = ctx.values[name];
182
+ const set = (v) => ctx.onChange({ [name]: v });
183
+ switch (meta.kind) {
184
+ case "toggle":
185
+ return (_jsx(FieldCheckbox, { name: name, label: label, hint: meta.help, checked: Boolean(value), onChange: set }, name));
186
+ case "textarea":
187
+ return (_jsx(FieldTextarea, { name: name, label: label, hint: meta.help, required: required, value: typeof value === "string" ? value : "", onChange: set }, name));
188
+ case "select": {
189
+ const options = opts.options?.[name] ?? selectOptions(field.schema) ?? [];
190
+ return (_jsx(FieldSelect, { name: name, label: label, hint: meta.help === "paginated" ? undefined : meta.help, required: required, value: typeof value === "string" ? value : "", options: options, onChange: set }, name));
191
+ }
192
+ case "number":
193
+ return (_jsx(FieldInput, { name: name, type: "number", label: label, hint: meta.help, required: required, value: value == null ? "" : String(value), onChange: (v) => set(v === "" ? undefined : Number(v)) }, name));
194
+ case "date":
195
+ return (_jsx(FieldInput, { name: name, type: "date", label: label, hint: meta.help, required: required, value: typeof value === "string" ? value.slice(0, 10) : "", onChange: set }, name));
196
+ // `media` and `list` have no derived control on purpose. A MediaUploadField
197
+ // needs an upload context, a staging path and a finalize call that only the
198
+ // owning feature can supply, and a list editor needs to know what an item
199
+ // looks like. Deriving a placeholder for either would render a control that
200
+ // silently fails to save — worse than requiring an explicit renderer.
201
+ case "media":
202
+ case "list":
203
+ return (_jsx(FieldInput, { name: name, label: label, hint: meta.help ?? `Provide a renderer for "${name}" — this field needs a custom control.`, required: required, disabled: true, value: "" }, name));
204
+ default:
205
+ return (_jsx(FieldInput, { name: name, label: label, hint: meta.help, required: required, value: typeof value === "string" ? value : value == null ? "" : String(value), onChange: set }, name));
206
+ }
207
+ }
@@ -0,0 +1,115 @@
1
+ import type { ZodTypeAny } from "zod";
2
+ /** How much of a row a field claims on desktop. Everything is 1-up on mobile. */
3
+ export type FieldRow = "full" | "pair" | "third" | "quarter";
4
+ /** Which input primitive renders the field, and its default row span. */
5
+ export type FieldKind = "text" | "number" | "date" | "select" | "toggle" | "textarea" | "media" | "list";
6
+ /**
7
+ * Which tier owns a value that is not typed by the user.
8
+ * T1 client `derive()` · T2 server-on-write · T3 mirror · T4 background job.
9
+ * The tier decides the correctness rule — see the calculated-field dictionary.
10
+ */
11
+ export type CalculatedTier = "t1-derive" | "t2-server" | "t3-mirror" | "t4-aggregate";
12
+ export interface FieldUiMeta {
13
+ /**
14
+ * Section id this field belongs to — the grouping key, and the ONE key that
15
+ * cannot be inferred. Whether `gstin` belongs under "Tax" or "Business
16
+ * details" is a product decision, and a wrong section renders perfectly
17
+ * fine in the wrong place with nothing failing. Deliberately NOT inferred
18
+ * from a name prefix (`billing_city` → "billing"): that would work for a
19
+ * handful of schemas and quietly mis-group the rest.
20
+ */
21
+ section: string;
22
+ /** Human label for the section. The first field to declare it wins. */
23
+ sectionLabel?: string;
24
+ /** Marks its section required-first, open on mount, non-collapsible. */
25
+ sectionRequired?: boolean;
26
+ /**
27
+ * Section keeps its panel mounted while collapsed. Mandatory for any
28
+ * section holding uncommitted state — `<Collapse>` unmounts its children,
29
+ * which discards an in-flight media upload.
30
+ */
31
+ sectionKeepMounted?: boolean;
32
+ /** Row span. Drives the `<FormGroup columns>` packing. */
33
+ row?: FieldRow;
34
+ /** Control kind. Picks the primitive and the default row span. */
35
+ kind?: FieldKind;
36
+ /** Sort order within the section. Unset sorts after ordered fields. */
37
+ order?: number;
38
+ /** Belongs in the self-submitting quick drawer. */
39
+ quick?: boolean;
40
+ /** Produced by `derive()` or the server — never rendered as a bare input. */
41
+ derived?: boolean;
42
+ /** Which calculated-field tier owns it, when it is not user-entered. */
43
+ tier?: CalculatedTier;
44
+ label?: string;
45
+ help?: string;
46
+ }
47
+ export declare const ui: {
48
+ /** Attach metadata to a schema instance. Returns the SAME instance. */
49
+ add<S extends ZodTypeAny>(schema: S, meta: FieldUiMeta): S;
50
+ get(schema: ZodTypeAny): FieldUiMeta | undefined;
51
+ has(schema: ZodTypeAny): boolean;
52
+ };
53
+ /**
54
+ * Annotate a field. **Must be the outermost call in the chain** — see the
55
+ * ordering trap in the header.
56
+ *
57
+ * name: annotate(z.string().min(1), { section: "basics", quick: true }),
58
+ * photo: annotate(z.string().optional(), { section: "media" }),
59
+ *
60
+ * Wrapping the call rather than chaining off it (`.register()`-style) is
61
+ * deliberate: it puts the schema visually INSIDE the annotation, so appending
62
+ * `.optional()` afterwards looks as wrong as it is.
63
+ */
64
+ export declare function annotate<S extends ZodTypeAny>(schema: S, meta: FieldUiMeta): S;
65
+ /** `row` → the `<FormGroup columns>` value it packs into. */
66
+ export declare const ROW_COLUMNS: Record<FieldRow, 1 | 2 | 3 | 4>;
67
+ /**
68
+ * Strip `.optional()` / `.nullable()` / `.default()` / `.catch()` to reach the
69
+ * type that actually decides the control. Returns the innermost schema and its
70
+ * normalised type discriminator.
71
+ *
72
+ * Reads `_def` because zod exposes no public accessor for this, on either
73
+ * major. Depth-bounded rather than trusting the shape: `_def` is internal, and
74
+ * this must degrade to "text" rather than loop if a future zod reshapes it.
75
+ */
76
+ export declare function unwrapSchema(schema: ZodTypeAny): {
77
+ schema: ZodTypeAny;
78
+ type: string;
79
+ };
80
+ /** Public: the option list for a select-shaped field, or null. */
81
+ export declare function schemaEnumOptions(schema: ZodTypeAny): string[] | null;
82
+ /** Public: whether a field's type is optional-wrapped (i.e. not required). */
83
+ export declare function schemaIsOptional(schema: ZodTypeAny): boolean;
84
+ /**
85
+ * The `.shape` of an object schema, seeing through effects wrappers.
86
+ *
87
+ * `.superRefine()` / `.refine()` / `.transform()` return a wrapper that does
88
+ * NOT expose `.shape` — verified: `z.object({...}).superRefine(fn)` has
89
+ * `_def.typeName === "ZodEffects"`, `.shape === undefined`, and the real object
90
+ * on `_def.schema`. Reading `.shape` directly therefore returns nothing for any
91
+ * schema with a cross-field rule, which is most of the interesting ones (the
92
+ * payout form's UPI-vs-bank branch is exactly this shape).
93
+ *
94
+ * Failing to unwrap would not error — it would silently derive a form with
95
+ * ZERO sections, which is the quiet-wrong-answer failure mode this whole wave
96
+ * exists to eliminate.
97
+ */
98
+ export declare function objectShape(schema: ZodTypeAny): Record<string, ZodTypeAny> | null;
99
+ /**
100
+ * Everything about a field's layout that can be derived from its name and its
101
+ * Zod type. `section` is never inferred, so the return type is a Partial —
102
+ * `resolveFieldUiMeta` is what merges it with the explicit registration.
103
+ *
104
+ * This is what makes annotation cheap: a 13-field form is 13 short
105
+ * `.register(ui, { section: "…" })` calls, not 13 full metadata objects.
106
+ */
107
+ export declare function inferFieldUiMeta(name: string, schema: ZodTypeAny): Partial<FieldUiMeta>;
108
+ /**
109
+ * The field's final metadata: inference first, explicit registration on top.
110
+ *
111
+ * Returns `null` when the field has no registration at all — the caller
112
+ * decides whether that is a hard error (a registered form schema, where
113
+ * `section` is mandatory) or a fallback (an ad-hoc schema being previewed).
114
+ */
115
+ export declare function resolveFieldUiMeta(name: string, schema: ZodTypeAny): FieldUiMeta | null;