@marktiderman/genesis-core 2.14.0 → 2.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 (101) hide show
  1. package/dist/aggregate-Y5IJ5aPn.d.ts +34 -0
  2. package/dist/{chunk-7PUFVNPB.js → chunk-2IGAUXYH.js} +5 -3
  3. package/dist/chunk-2IGAUXYH.js.map +1 -0
  4. package/dist/{chunk-KA3BUJ4H.js → chunk-42NVJJTT.js} +3 -3
  5. package/dist/{chunk-KA3BUJ4H.js.map → chunk-42NVJJTT.js.map} +1 -1
  6. package/dist/{chunk-JN47G4UE.js → chunk-7EFTWOMA.js} +56 -2
  7. package/dist/chunk-7EFTWOMA.js.map +1 -0
  8. package/dist/{chunk-P3FHXRS2.js → chunk-ALLWIK62.js} +6 -6
  9. package/dist/{chunk-P3FHXRS2.js.map → chunk-ALLWIK62.js.map} +1 -1
  10. package/dist/chunk-APFXV6FZ.js +130 -0
  11. package/dist/chunk-APFXV6FZ.js.map +1 -0
  12. package/dist/chunk-BDPRWVFW.js +17 -0
  13. package/dist/chunk-BDPRWVFW.js.map +1 -0
  14. package/dist/{chunk-S2VYJWB4.js → chunk-E3K2A3PK.js} +3 -3
  15. package/dist/{chunk-S2VYJWB4.js.map → chunk-E3K2A3PK.js.map} +1 -1
  16. package/dist/{chunk-OYDJGPDY.js → chunk-FXPODKCK.js} +5 -5
  17. package/dist/{chunk-OYDJGPDY.js.map → chunk-FXPODKCK.js.map} +1 -1
  18. package/dist/{chunk-SDAJSJNN.js → chunk-IYGVJFCV.js} +3 -3
  19. package/dist/{chunk-SDAJSJNN.js.map → chunk-IYGVJFCV.js.map} +1 -1
  20. package/dist/chunk-J54XXKQD.js +104 -0
  21. package/dist/chunk-J54XXKQD.js.map +1 -0
  22. package/dist/{chunk-KV2HW4G4.js → chunk-LB6FMQQM.js} +11 -3
  23. package/dist/chunk-LB6FMQQM.js.map +1 -0
  24. package/dist/{chunk-G6GQPXQS.js → chunk-M5IX7C6U.js} +5 -5
  25. package/dist/{chunk-G6GQPXQS.js.map → chunk-M5IX7C6U.js.map} +1 -1
  26. package/dist/{chunk-DFABPMEQ.js → chunk-POUI7GAI.js} +5 -5
  27. package/dist/{chunk-DFABPMEQ.js.map → chunk-POUI7GAI.js.map} +1 -1
  28. package/dist/{chunk-NE2D74BP.js → chunk-QGWQ6LK3.js} +5 -5
  29. package/dist/{chunk-NE2D74BP.js.map → chunk-QGWQ6LK3.js.map} +1 -1
  30. package/dist/{chunk-2K4747KX.js → chunk-R3YXYVWF.js} +7 -2
  31. package/dist/chunk-R3YXYVWF.js.map +1 -0
  32. package/dist/{chunk-RFHUOXZC.js → chunk-SOO54YYY.js} +4 -4
  33. package/dist/{chunk-RFHUOXZC.js.map → chunk-SOO54YYY.js.map} +1 -1
  34. package/dist/{chunk-YZV3Z6ZA.js → chunk-SQLM5CIJ.js} +3 -3
  35. package/dist/{chunk-YZV3Z6ZA.js.map → chunk-SQLM5CIJ.js.map} +1 -1
  36. package/dist/{chunk-WDPM5TBO.js → chunk-UDSTWXXZ.js} +3 -3
  37. package/dist/{chunk-WDPM5TBO.js.map → chunk-UDSTWXXZ.js.map} +1 -1
  38. package/dist/chunk-XPBS5YE4.js +24 -0
  39. package/dist/chunk-XPBS5YE4.js.map +1 -0
  40. package/dist/{chunk-AHFIS42U.js → chunk-ZYOJWU62.js} +5 -5
  41. package/dist/{chunk-AHFIS42U.js.map → chunk-ZYOJWU62.js.map} +1 -1
  42. package/dist/csv.d.ts +1 -1
  43. package/dist/form-types.d.ts +1 -1
  44. package/dist/headless/index.d.ts +334 -0
  45. package/dist/headless/index.js +490 -0
  46. package/dist/headless/index.js.map +1 -0
  47. package/dist/hooks/index.d.ts +4 -2
  48. package/dist/hooks/index.js +20 -17
  49. package/dist/hooks/mutation-mode.d.ts +1 -1
  50. package/dist/hooks/mutation-mode.js +5 -4
  51. package/dist/hooks/related-keys.d.ts +1 -1
  52. package/dist/hooks/use-aggregate.d.ts +25 -0
  53. package/dist/hooks/use-aggregate.js +10 -0
  54. package/dist/hooks/use-aggregate.js.map +1 -0
  55. package/dist/hooks/use-capabilities.d.ts +1 -1
  56. package/dist/hooks/use-capabilities.js +4 -2
  57. package/dist/hooks/use-draft.js +2 -2
  58. package/dist/hooks/use-infinite-resource.d.ts +1 -1
  59. package/dist/hooks/use-infinite-resource.js +6 -4
  60. package/dist/hooks/use-link-options.d.ts +1 -1
  61. package/dist/hooks/use-link-options.js +8 -6
  62. package/dist/hooks/use-live.d.ts +1 -1
  63. package/dist/hooks/use-live.js +4 -2
  64. package/dist/hooks/use-one.d.ts +1 -1
  65. package/dist/hooks/use-one.js +6 -4
  66. package/dist/hooks/use-persisted-ui-state.js +4 -2
  67. package/dist/hooks/use-relation-label.d.ts +1 -1
  68. package/dist/hooks/use-relation-label.js +4 -2
  69. package/dist/hooks/use-resource-form.d.ts +1 -1
  70. package/dist/hooks/use-resource-form.js +8 -7
  71. package/dist/hooks/use-resource.d.ts +1 -1
  72. package/dist/hooks/use-resource.js +7 -6
  73. package/dist/hooks/use-write.d.ts +1 -1
  74. package/dist/index.d.ts +110 -6
  75. package/dist/index.js +129 -20
  76. package/dist/index.js.map +1 -1
  77. package/dist/navigation.d.ts +77 -1
  78. package/dist/navigation.js +32 -2
  79. package/dist/navigation.js.map +1 -1
  80. package/dist/provider/index.d.ts +12 -4
  81. package/dist/provider/index.js +3 -2
  82. package/dist/resource-view/index.d.ts +456 -166
  83. package/dist/resource-view/index.js +251 -5
  84. package/dist/resource-view/index.js.map +1 -1
  85. package/dist/schema/index.d.ts +3 -3
  86. package/dist/schema/index.js +1 -2
  87. package/dist/testing/index.d.ts +2 -2
  88. package/dist/{types-CtJxwoyv.d.ts → types-BriIV4e_.d.ts} +78 -3
  89. package/dist/workspaces-CxpiFu2-.d.ts +263 -0
  90. package/dist/workspaces.d.ts +2 -160
  91. package/dist/workspaces.js +2 -1
  92. package/dist/{write-outcome-Goy1v39G.d.ts → write-outcome-CkQXgtJq.d.ts} +1 -1
  93. package/package.json +14 -4
  94. package/dist/chunk-2K4747KX.js.map +0 -1
  95. package/dist/chunk-7PUFVNPB.js.map +0 -1
  96. package/dist/chunk-JN47G4UE.js.map +0 -1
  97. package/dist/chunk-KV2HW4G4.js.map +0 -1
  98. package/dist/chunk-UHOMTFBD.js +0 -72
  99. package/dist/chunk-UHOMTFBD.js.map +0 -1
  100. package/dist/chunk-YDMKMNDS.js +0 -8
  101. package/dist/chunk-YDMKMNDS.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/hooks/viewer-scope.tsx","../src/hooks/workspace-scope.tsx"],"names":["Fragment","createContext","useContext","useMemo","useEffect","jsx"],"mappings":";;;;;;;;;;;AAWA,IAAI,cAAA,GAAiB,KAAA;AAOrB,SAAS,WAAW,KAAA,EAA+C;AACjE,EAAA,IAAI,QAAA,GAAW,KAAA;AACf,EAAA,MAAM,KAAA,GAAQ,CAAC,CAAA,KAAwB;AACrC,IAAA,IAAI,MAAM,OAAA,CAAQ,CAAC,GAAG,OAAO,CAAA,CAAE,IAAI,KAAK,CAAA,CAAE,GAAA,CAAI,CAAC,MAAM,CAAC,UAAA,CAAW,CAAC,CAAA,EAAG,CAAC,CAAU,CAAA,CAAE,IAAA,CAAK,CAAC,CAAC,CAAC,CAAA,EAAG,CAAC,CAAC,CAAA,KAAO,CAAA,GAAI,IAAI,EAAA,GAAK,CAAA,GAAI,IAAI,CAAA,GAAI,CAAE,EAAE,GAAA,CAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAA;AACnJ,IAAA,IAAI,CAAA,IAAK,OAAO,CAAA,KAAM,QAAA,EAAU;AAC9B,MAAA,MAAM,KAAA,GAAQ,MAAA,CAAO,cAAA,CAAe,CAAC,CAAA;AACrC,MAAA,IAAI,KAAA,KAAU,MAAA,CAAO,SAAA,IAAa,KAAA,KAAU,IAAA,EAAM;AAChD,QAAA,IAAI,QAAQ,GAAA,CAAI,QAAA,KAAa,cAAc,MAA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EAAU,OAAO,IAAA,EAAM,QAAA,EAAU,GAAG,WAAA,EAAY,EAA2B;AAC3I,EAAA,MAAM,OAAA,GAAU,WAAA,CAAY,UAAA,EAAY,QAAQ,CAAA;AAChD,EAAA,MAAM,KAAA,GAAQC,OAAAA;AAAA,IACZ,OAAO;AAAA,MACL,OAAA;AAAA,MACA,UAAA;AAAA,MACA,OAAA,EAAS,CAAC,EAAA,KAAO,aAAA,CAAc,UAAA,EAAY,EAAA,EAAI,QAAA,EAAU,IAAA,GAAO,EAAE,IAAA,EAAK,GAAI,EAAE;AAAA,KAC/E,CAAA;AAAA,IACA,CAAC,OAAA,EAAS,UAAA,EAAY,QAAA,EAAU,IAAI;AAAA,GACtC;AACA,EAAA,MAAM,SAAS,WAAA,CAAY,MAAA;AAC3B,EAAAC,UAAU,MAAM;AACd,IAAA,IAAI,MAAA,IAAU,OAAA,EAAS,QAAA,CAAS,MAAA,EAAQ,QAAQ,EAAE,CAAA;AAAA,EACpD,CAAA,EAAG,CAAC,MAAA,EAAQ,OAAO,CAAC,CAAA;AACpB,EAAA,uBACEC,GAAAA,CAAC,qBAAA,CAAsB,QAAA,EAAtB,EAA+B,OAC9B,QAAA,kBAAAA,GAAAA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACE,GAAG,WAAA;AAAA,MACJ,OAAO,EAAE,GAAG,KAAA,EAAO,GAAG,SAAS,KAAA,EAAM;AAAA,MACpC,GAAI,SAAS,KAAA,KAAU,MAAA,GAAY,EAAE,KAAA,EAAO,OAAA,CAAQ,KAAA,EAAM,GAAI,EAAC;AAAA,MAC/D,GAAI,SAAS,QAAA,KAAa,MAAA,GAAY,EAAE,aAAA,EAAe,OAAA,CAAQ,QAAA,EAAS,GAAI,EAAC;AAAA,MAE7E;AAAA;AAAA,GACH,EACF,CAAA;AAEJ","file":"chunk-AHFIS42U.js","sourcesContent":["import { useQueryClient, type QueryClient } from \"@tanstack/react-query\";\nimport { createContext, Fragment, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\nimport { dayIn, isTimeZone, personTimeZone, type Day } from \"../dates\";\nimport { reportError } from \"../errors\";\nimport { stableJson } from \"./draft-controller\";\nimport { NO_VIEWER, type GenesisViewerRoles, type Viewer } from \"../viewer\";\nimport { dropPendingWrites, flushPendingWrites } from \"./mutation-mode\";\nimport { PersistedViewerContext } from \"../provider/context\";\n\nexport { NO_VIEWER, type GenesisViewerRoles, type Viewer };\n\nlet warnedNotPlain = false;\n\n/**\n * Roles as a value: object keys and lists sorted, so `[\"editor\", \"owner\"]` equals\n * `[\"owner\", \"editor\"]`. A Set, Map or class would stringify as `{}` and hide a change: in\n * development that throws; in production it warns once and the roles count as unknown (undefined).\n */\nfunction rolesKeyOf(roles: GenesisViewerRoles): string | undefined {\n let notPlain = false;\n const plain = (v: unknown): unknown => {\n if (Array.isArray(v)) return v.map(plain).map((x) => [stableJson(x), x] as const).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([, x]) => x);\n if (v && typeof v === \"object\") {\n const proto = Object.getPrototypeOf(v);\n if (proto !== Object.prototype && proto !== null) {\n if (process.env.NODE_ENV !== \"production\") throw new TypeError(\"[genesis-core] ViewerScope roles must be plain JSON (no Set, Map or class)\");\n notPlain = true;\n return null;\n }\n return Object.fromEntries(Object.entries(v as Record<string, unknown>).map(([k, x]) => [k, plain(x)]));\n }\n return v;\n };\n const key = stableJson(plain(roles));\n if (!notPlain) return key;\n if (!warnedNotPlain) {\n warnedNotPlain = true;\n reportError(new TypeError(\"ViewerScope roles must be plain JSON (no Set, Map or class); treating them as unknown, so guards that need them refuse\"), \"core:viewer-scope\");\n }\n return undefined;\n}\n\n/** Today in `zone`, rechecked when the page comes back into view and at the next minute boundary while it's open. */\nfunction useToday(zone: string): Day {\n const [day, setDay] = useState(() => dayIn(zone));\n useEffect(() => {\n const check = () => setDay(dayIn(zone));\n check();\n const onVisible = () => {\n if (typeof document === \"undefined\" || document.visibilityState === \"visible\") check();\n };\n if (typeof document !== \"undefined\") document.addEventListener(\"visibilitychange\", onVisible);\n // A page left open over midnight rolls over within a minute.\n const timer = setInterval(check, 60_000);\n return () => {\n if (typeof document !== \"undefined\") document.removeEventListener(\"visibilitychange\", onVisible);\n clearInterval(timer);\n };\n }, [zone]);\n return day;\n}\n\n/**\n * Empties the query cache for a new viewer: sends the old viewer's waiting\n * undoable writes (the session is still theirs), cancels reads in flight,\n * then removes every query. Call it in the sign-in and sign-out actions,\n * before the session changes.\n */\nexport async function clearViewerCache(queryClient: QueryClient): Promise<void> {\n await flushPendingWrites(queryClient);\n await queryClient.cancelQueries();\n queryClient.clear();\n}\n\n/**\n * Where the viewer is working: the person, space or set of people Genesis knows by name, plus\n * whatever the app scopes to under its own key (`{ orgId }`, `{ leagueId }`, `{ locationId }`).\n * Screens turn it into server filters and create defaults (a view's `scope: [\"league_id\"]` reads\n * `league_id`, then `leagueId`); it never decides access (row-level security does).\n */\nexport interface ResourceScope {\n personId?: string;\n spaceId?: string;\n /** Several people at once (a coach's client list, a group). */\n personIds?: readonly string[];\n /** The app's own scope keys: `orgId`, `leagueId`, `locationId`, … */\n [key: string]: unknown;\n}\n\nexport interface ViewerContext {\n viewer: string | null;\n scope: ResourceScope;\n /** The viewer's roles (see `GenesisViewerRoles`), when ViewerScope was given them. */\n roles?: GenesisViewerRoles;\n /** The zone the viewer's days are counted in: theirs if known, else the device's. */\n timeZone: string;\n /**\n * The zone of whatever the viewer is scoped to (a location, a league), for columns with\n * `timeZone: \"scope\"`: ViewerScope's `scopeTimeZone` when valid, else {@link timeZone}.\n */\n scopeTimeZone?: string;\n /**\n * Today on the viewer's clock (YYYY-MM-DD), kept current when the page comes back into view.\n * Use it for every \"today\" read and as query keys' `day`: `keys.for(useViewerScope())`.\n */\n day: Day;\n}\n\nconst ViewerContextValue = createContext<ViewerContext | null>(null);\n\n/** The viewer and scope from the nearest `ViewerScope`. Throws without one: screens that cache per viewer need it. */\nexport function useViewerScope(): ViewerContext {\n const value = useContext(ViewerContextValue);\n if (!value) throw new Error(\"[genesis-core] useViewerScope needs a <ViewerScope> above it\");\n return value;\n}\n\n/** Like useViewerScope, or null outside a ViewerScope. */\nexport function useOptionalViewerScope(): ViewerContext | null {\n return useContext(ViewerContextValue);\n}\n\n/**\n * The viewer for guards: `{ id, scope, roles }` from the nearest ViewerScope, or\n * {@link NO_VIEWER} without one. The object is stable while those are equal by value, so it can\n * sit in a memo's dependencies.\n */\nexport function useViewer(): Viewer {\n const context = useContext(ViewerContextValue);\n return useMemo<Viewer>(\n () =>\n context\n ? Object.freeze({ id: context.viewer, scope: context.scope, ...(context.roles !== undefined ? { roles: context.roles } : {}) })\n : NO_VIEWER,\n [context],\n );\n}\n\nexport interface ViewerScopeProps {\n /** The signed-in viewer's id, null when signed out, undefined while the session loads. */\n viewer: string | null | undefined;\n /**\n * The viewer a persisted cache was saved for. When the first known viewer\n * is this one, the restored cache is kept; otherwise it's emptied. Inside a\n * `GenesisProvider` with `persist`, it defaults to its `persistScope`'s user.\n */\n persistedViewer?: string | null;\n /** Where the viewer is working (see `ResourceScope`). Changing it doesn't remount or clear anything. */\n scope?: ResourceScope;\n /**\n * What the viewer may do there (see `GenesisViewerRoles`), for view guards. Compared by value,\n * so a new object with the same roles changes nothing. Undefined while they load: guards that\n * need them refuse. Arriving (undefined → roles) or going back to undefined changes nothing;\n * different roles send the person's waiting writes, then reread every query, with nothing\n * remounted. Plain JSON values only (lists are compared as sets, in any order): a Set, Map or\n * class instance throws in development; in production it warns once and the roles count as\n * unknown (as if undefined), so guards that need them refuse.\n */\n roles?: GenesisViewerRoles;\n /**\n * The viewer's saved time zone (IANA), when known; else the device's is used. Pass it when\n * rendering on a server, whose own zone is rarely the viewer's.\n */\n timeZone?: string | null;\n /**\n * The IANA zone of whatever the viewer is scoped to (a location, a league), when it has one.\n * Columns with `timeZone: \"scope\"` read on it; without it they read on the viewer's clock.\n */\n scopeTimeZone?: string | null;\n /** Shown while the session loads (and for the one render a change takes). */\n fallback?: ReactNode;\n children: ReactNode;\n}\n\n/**\n * The scope's clock: `scopeTimeZone` when the runtime knows it, else the viewer's. A zone it\n * doesn't know is never a quiet fallback: it throws in development, and in production it is\n * reported (`reportError`, once per zone) before the viewer's clock is used, so a misspelt zone can't show\n * times on the wrong clock unnoticed.\n */\nexport function scopeClock(scopeTimeZone: string | null | undefined, viewerZone: string): string {\n if (scopeTimeZone === undefined || scopeTimeZone === null || scopeTimeZone === \"\") return viewerZone;\n if (isTimeZone(scopeTimeZone)) return scopeTimeZone;\n const error = new RangeError(`[genesis-core] scopeTimeZone \"${scopeTimeZone}\" isn't a time zone this runtime knows (an IANA name such as \"Europe/Berlin\")`);\n if (process.env.NODE_ENV !== \"production\") throw error;\n // Once per zone: a bad zone in a long-lived screen must not flood the error reporter.\n if (!reportedScopeZones.has(scopeTimeZone)) {\n reportedScopeZones.add(scopeTimeZone);\n reportError(error, \"core:viewer-scope\");\n }\n return viewerZone;\n}\n\n/** The unknown scope zones already reported, so each is reported once per page load. */\nconst reportedScopeZones = new Set<string>();\n\n/**\n * Keeps one viewer's cached data from ever showing to the next. Children\n * render only once the viewer is known, under a key of that viewer, so a\n * sign-out or a new person signing in unmounts every screen and its queries\n * before the cache is emptied and the new viewer's screens mount fresh. The\n * first known viewer empties a restored cache too, unless it's the\n * `persistedViewer` it was saved for.\n *\n * ```tsx\n * <ViewerScope viewer={session === undefined ? undefined : (session?.user.id ?? null)}>\n * <App />\n * </ViewerScope>\n * ```\n */\nexport function ViewerScope({ viewer, persistedViewer: persistedViewerProp, scope, roles, timeZone, scopeTimeZone, fallback = null, children }: ViewerScopeProps) {\n const queryClient = useQueryClient();\n const restoredFor = useContext(PersistedViewerContext);\n const persistedViewer = persistedViewerProp !== undefined ? persistedViewerProp : restoredFor;\n const zone = personTimeZone({ timeZone });\n // Memoised, and scopeClock reports a zone once, so a bad zone isn't reported on every render.\n const scopeZone = useMemo(() => scopeClock(scopeTimeZone, zone), [scopeTimeZone, zone]);\n const day = useToday(zone);\n // A new scope object each render shouldn't re-render every reader: compare by value.\n const scopeKey = stableJson(scope ?? {});\n // Roles by value too: undefined stays undefined, so \"not known yet\" never equals \"none\".\n // Roles that aren't plain JSON count as unknown in production (rolesKeyOf warns; development throws).\n const rolesKey = roles === undefined ? undefined : rolesKeyOf(roles);\n const value = useMemo<ViewerContext>(\n () => ({ viewer: viewer ?? null, scope: scope ?? {}, ...(rolesKey !== undefined ? { roles } : {}), timeZone: zone, scopeTimeZone: scopeZone, day }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [viewer, scopeKey, rolesKey, zone, scopeZone, day],\n );\n // The last roles known for this viewer. Arriving (undefined → roles) or going back to undefined\n // changes nothing; different roles for the same person send their waiting writes, then reread\n // everything under the new roles. Nothing remounts: the person, their drafts and their\n // navigation are the same.\n const known = useRef<{ viewer: string | null | undefined; roles: string | undefined }>({ viewer, roles: undefined });\n useEffect(() => {\n if (known.current.viewer !== viewer) known.current = { viewer, roles: undefined };\n if (rolesKey === undefined) return;\n const previous = known.current.roles;\n known.current.roles = rolesKey;\n if (previous === undefined || previous === rolesKey) return;\n // The session is still theirs: their writes go out, and the database decides each one with the\n // roles as they are when it arrives (a refused one fails as any refused write does).\n void flushPendingWrites(queryClient).then(() => queryClient.invalidateQueries());\n }, [viewer, rolesKey, queryClient]);\n // Who the children were last mounted for, and how many times they were reset. Undefined before\n // the first mount.\n const [mounted, setMounted] = useState<{ viewer: string | null; epoch: number } | undefined>(undefined);\n if (viewer === undefined) return <>{fallback}</>;\n if (mounted === undefined || mounted.viewer !== viewer) {\n const keep = mounted === undefined && persistedViewer !== undefined && persistedViewer === viewer;\n // Nothing for the new viewer is mounted yet, so emptying now can't strand\n // a fetch; the old viewer's screens unmount with this render.\n if (!keep) {\n // The session already belongs to the new viewer: the old one's unsent\n // writes must never go out under it. (clearViewerCache, run before the\n // session changes, sends them instead.)\n dropPendingWrites(queryClient);\n void queryClient.cancelQueries();\n queryClient.clear();\n }\n setMounted({ viewer, epoch: (mounted?.epoch ?? 0) + 1 });\n return <>{fallback}</>;\n }\n return (\n <ViewerContextValue.Provider value={value}>\n <Fragment key={`${viewer ?? \"signed-out\"}#${mounted.epoch}`}>{children}</Fragment>\n </ViewerContextValue.Provider>\n );\n}\n","import { createContext, useContext, useEffect, useMemo } from \"react\";\nimport { ViewerScope, type ViewerScopeProps } from \"./viewer-scope\";\nimport { workspaceAt, workspaceHref, type Workspace, type WorkspaceHrefOptions } from \"../workspaces\";\n\n/**\n * The workspace the viewer is in, and where each of their others is from here.\n *\n * @stability Beta\n */\nexport interface WorkspaceContext<W extends Workspace = Workspace> {\n /** Undefined when the URL is in no workspace (the app's front door, a sign-in page). */\n current: W | undefined;\n workspaces: readonly W[];\n /** Where switching to `to` goes from the current URL, keeping the viewer's place when it can. */\n hrefFor: (to: W) => string;\n}\n\nconst WorkspaceContextValue = createContext<WorkspaceContext | null>(null);\n\n/**\n * The nearest `WorkspaceScope`'s workspaces, or null outside one.\n *\n * @stability Beta\n */\nexport function useWorkspace<W extends Workspace = Workspace>(): WorkspaceContext<W> | null {\n return useContext(WorkspaceContextValue) as WorkspaceContext<W> | null;\n}\n\nconst STORAGE_PREFIX = \"genesis:workspace:\";\n\n/**\n * The workspace this viewer was last in on this device, for the app's front door\n * (`defaultWorkspace(workspaces, rememberedWorkspaceId(viewer))`). Null when unknown.\n *\n * @stability Beta\n */\nexport function rememberedWorkspaceId(viewer: string | null | undefined): string | null {\n if (!viewer || typeof window === \"undefined\") return null;\n try {\n return window.localStorage.getItem(STORAGE_PREFIX + viewer);\n } catch {\n return null;\n }\n}\n\nfunction remember(viewer: string, id: string) {\n try {\n window.localStorage.setItem(STORAGE_PREFIX + viewer, id);\n } catch {\n // private mode or full: the front door falls back to the first tenant.\n }\n}\n\n/** @stability Beta */\nexport interface WorkspaceScopeProps<W extends Workspace = Workspace> extends Omit<ViewerScopeProps, \"scope\" | \"roles\" | \"scopeTimeZone\"> {\n /** Every workspace this viewer has. */\n workspaces: readonly W[];\n /** The current URL's path (`useLocation().pathname`): the workspace is read from it. */\n pathname: string;\n /** Scope keys every workspace adds to its own (rarely needed). */\n scope?: ViewerScopeProps[\"scope\"];\n /** How switching keeps the viewer's place (see `workspaceHref`). */\n keep?: WorkspaceHrefOptions[\"keep\"];\n}\n\n/**\n * `ViewerScope` for an app with workspaces: use it in place of `ViewerScope`. It reads the current\n * workspace from the URL and scopes everything under it to that workspace (its `scope`, `roles` and\n * `timeZone`), so every view with `scope: [\"org_id\"]` follows the switcher with no screen code. It\n * remembers the workspace per viewer on this device, and gives `WorkspaceSwitcher` its list.\n *\n * ```tsx\n * <WorkspaceScope viewer={userId} workspaces={workspaces} pathname={location.pathname}>\n * <AppShell headerSlot={<WorkspaceSwitcher linkComponent={Link} />} …>\n * </WorkspaceScope>\n * ```\n *\n * @stability Beta\n */\nexport function WorkspaceScope<W extends Workspace>({ workspaces, pathname, scope, keep, children, ...viewerProps }: WorkspaceScopeProps<W>) {\n const current = workspaceAt(workspaces, pathname);\n const value = useMemo<WorkspaceContext<W>>(\n () => ({\n current,\n workspaces,\n hrefFor: (to) => workspaceHref(workspaces, to, pathname, keep ? { keep } : {}),\n }),\n [current, workspaces, pathname, keep],\n );\n const viewer = viewerProps.viewer;\n useEffect(() => {\n if (viewer && current) remember(viewer, current.id);\n }, [viewer, current]);\n return (\n <WorkspaceContextValue.Provider value={value as unknown as WorkspaceContext}>\n <ViewerScope\n {...viewerProps}\n scope={{ ...scope, ...current?.scope }}\n {...(current?.roles !== undefined ? { roles: current.roles } : {})}\n {...(current?.timeZone !== undefined ? { scopeTimeZone: current.timeZone } : {})}\n >\n {children}\n </ViewerScope>\n </WorkspaceContextValue.Provider>\n );\n}\n\n"]}
1
+ {"version":3,"sources":["../src/hooks/viewer-scope.tsx","../src/hooks/workspace-scope.tsx"],"names":["Fragment","createContext","useContext","useMemo","useEffect","jsx"],"mappings":";;;;;;;;;;;AAWA,IAAI,cAAA,GAAiB,KAAA;AAOrB,SAAS,WAAW,KAAA,EAA+C;AACjE,EA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MAAA,IAAU,OAAA,EAAS,QAAA,CAAS,MAAA,EAAQ,QAAQ,EAAE,CAAA;AAAA,EACpD,CAAA,EAAG,CAAC,MAAA,EAAQ,OAAO,CAAC,CAAA;AACpB,EAAA,uBACEC,GAAAA,CAAC,qBAAA,CAAsB,QAAA,EAAtB,EAA+B,OAC9B,QAAA,kBAAAA,GAAAA;AAAA,IAAC,WAAA;AAAA,IAAA;AAAA,MACE,GAAG,WAAA;AAAA,MACJ,OAAO,EAAE,GAAG,KAAA,EAAO,GAAG,SAAS,KAAA,EAAM;AAAA,MACpC,GAAI,SAAS,KAAA,KAAU,MAAA,GAAY,EAAE,KAAA,EAAO,OAAA,CAAQ,KAAA,EAAM,GAAI,EAAC;AAAA,MAC/D,GAAI,SAAS,QAAA,KAAa,MAAA,GAAY,EAAE,aAAA,EAAe,OAAA,CAAQ,QAAA,EAAS,GAAI,EAAC;AAAA,MAE7E;AAAA;AAAA,GACH,EACF,CAAA;AAEJ","file":"chunk-ZYOJWU62.js","sourcesContent":["import { useQueryClient, type QueryClient } from \"@tanstack/react-query\";\nimport { createContext, Fragment, useContext, useEffect, useMemo, useRef, useState, type ReactNode } from \"react\";\nimport { dayIn, isTimeZone, personTimeZone, type Day } from \"../dates\";\nimport { reportError } from \"../errors\";\nimport { stableJson } from \"./draft-controller\";\nimport { NO_VIEWER, type GenesisViewerRoles, type Viewer } from \"../viewer\";\nimport { dropPendingWrites, flushPendingWrites } from \"./mutation-mode\";\nimport { PersistedViewerContext } from \"../provider/context\";\n\nexport { NO_VIEWER, type GenesisViewerRoles, type Viewer };\n\nlet warnedNotPlain = false;\n\n/**\n * Roles as a value: object keys and lists sorted, so `[\"editor\", \"owner\"]` equals\n * `[\"owner\", \"editor\"]`. A Set, Map or class would stringify as `{}` and hide a change: in\n * development that throws; in production it warns once and the roles count as unknown (undefined).\n */\nfunction rolesKeyOf(roles: GenesisViewerRoles): string | undefined {\n let notPlain = false;\n const plain = (v: unknown): unknown => {\n if (Array.isArray(v)) return v.map(plain).map((x) => [stableJson(x), x] as const).sort(([a], [b]) => (a < b ? -1 : a > b ? 1 : 0)).map(([, x]) => x);\n if (v && typeof v === \"object\") {\n const proto = Object.getPrototypeOf(v);\n if (proto !== Object.prototype && proto !== null) {\n if (process.env.NODE_ENV !== \"production\") throw new TypeError(\"[genesis-core] ViewerScope roles must be plain JSON (no Set, Map or class)\");\n notPlain = true;\n return null;\n }\n return Object.fromEntries(Object.entries(v as Record<string, unknown>).map(([k, x]) => [k, plain(x)]));\n }\n return v;\n };\n const key = stableJson(plain(roles));\n if (!notPlain) return key;\n if (!warnedNotPlain) {\n warnedNotPlain = true;\n reportError(new TypeError(\"ViewerScope roles must be plain JSON (no Set, Map or class); treating them as unknown, so guards that need them refuse\"), \"core:viewer-scope\");\n }\n return undefined;\n}\n\n/** Today in `zone`, rechecked when the page comes back into view and at the next minute boundary while it's open. */\nfunction useToday(zone: string): Day {\n const [day, setDay] = useState(() => dayIn(zone));\n useEffect(() => {\n const check = () => setDay(dayIn(zone));\n check();\n const onVisible = () => {\n if (typeof document === \"undefined\" || document.visibilityState === \"visible\") check();\n };\n if (typeof document !== \"undefined\") document.addEventListener(\"visibilitychange\", onVisible);\n // A page left open over midnight rolls over within a minute.\n const timer = setInterval(check, 60_000);\n return () => {\n if (typeof document !== \"undefined\") document.removeEventListener(\"visibilitychange\", onVisible);\n clearInterval(timer);\n };\n }, [zone]);\n return day;\n}\n\n/**\n * Empties the query cache for a new viewer: sends the old viewer's waiting\n * undoable writes (the session is still theirs), cancels reads in flight,\n * then removes every query. Call it in the sign-in and sign-out actions,\n * before the session changes.\n */\nexport async function clearViewerCache(queryClient: QueryClient): Promise<void> {\n await flushPendingWrites(queryClient);\n await queryClient.cancelQueries();\n queryClient.clear();\n}\n\n/**\n * Where the viewer is working: the person, space or set of people Genesis knows by name, plus\n * whatever the app scopes to under its own key (`{ orgId }`, `{ leagueId }`, `{ locationId }`).\n * Screens turn it into server filters and create defaults (a view's `scope: [\"league_id\"]` reads\n * `league_id`, then `leagueId`); it never decides access (row-level security does).\n */\nexport interface ResourceScope {\n personId?: string;\n spaceId?: string;\n /** Several people at once (a coach's client list, a group). */\n personIds?: readonly string[];\n /** The app's own scope keys: `orgId`, `leagueId`, `locationId`, … */\n [key: string]: unknown;\n}\n\nexport interface ViewerContext {\n viewer: string | null;\n scope: ResourceScope;\n /** The viewer's roles (see `GenesisViewerRoles`), when ViewerScope was given them. */\n roles?: GenesisViewerRoles;\n /** The zone the viewer's days are counted in: theirs if known, else the device's. */\n timeZone: string;\n /**\n * The zone of whatever the viewer is scoped to (a location, a league), for columns with\n * `timeZone: \"scope\"`: ViewerScope's `scopeTimeZone` when valid, else {@link timeZone}.\n */\n scopeTimeZone?: string;\n /**\n * Today on the viewer's clock (YYYY-MM-DD), kept current when the page comes back into view.\n * Use it for every \"today\" read and as query keys' `day`: `keys.for(useViewerScope())`.\n */\n day: Day;\n}\n\nconst ViewerContextValue = createContext<ViewerContext | null>(null);\n\n/** The viewer and scope from the nearest `ViewerScope`. Throws without one: screens that cache per viewer need it. */\nexport function useViewerScope(): ViewerContext {\n const value = useContext(ViewerContextValue);\n if (!value) throw new Error(\"[genesis-core] useViewerScope needs a <ViewerScope> above it\");\n return value;\n}\n\n/** Like useViewerScope, or null outside a ViewerScope. */\nexport function useOptionalViewerScope(): ViewerContext | null {\n return useContext(ViewerContextValue);\n}\n\n/**\n * The viewer for guards: `{ id, scope, roles }` from the nearest ViewerScope, or\n * {@link NO_VIEWER} without one. The object is stable while those are equal by value, so it can\n * sit in a memo's dependencies.\n */\nexport function useViewer(): Viewer {\n const context = useContext(ViewerContextValue);\n return useMemo<Viewer>(\n () =>\n context\n ? Object.freeze({ id: context.viewer, scope: context.scope, ...(context.roles !== undefined ? { roles: context.roles } : {}) })\n : NO_VIEWER,\n [context],\n );\n}\n\nexport interface ViewerScopeProps {\n /** The signed-in viewer's id, null when signed out, undefined while the session loads. */\n viewer: string | null | undefined;\n /**\n * The viewer a persisted cache was saved for. When the first known viewer\n * is this one, the restored cache is kept; otherwise it's emptied. Inside a\n * `GenesisProvider` with `persist`, it defaults to its `persistScope`'s user.\n */\n persistedViewer?: string | null;\n /** Where the viewer is working (see `ResourceScope`). Changing it doesn't remount or clear anything. */\n scope?: ResourceScope;\n /**\n * What the viewer may do there (see `GenesisViewerRoles`), for view guards. Compared by value,\n * so a new object with the same roles changes nothing. Undefined while they load: guards that\n * need them refuse. Arriving (undefined → roles) or going back to undefined changes nothing;\n * different roles send the person's waiting writes, then reread every query, with nothing\n * remounted. Plain JSON values only (lists are compared as sets, in any order): a Set, Map or\n * class instance throws in development; in production it warns once and the roles count as\n * unknown (as if undefined), so guards that need them refuse.\n */\n roles?: GenesisViewerRoles;\n /**\n * The viewer's saved time zone (IANA), when known; else the device's is used. Pass it when\n * rendering on a server, whose own zone is rarely the viewer's.\n */\n timeZone?: string | null;\n /**\n * The IANA zone of whatever the viewer is scoped to (a location, a league), when it has one.\n * Columns with `timeZone: \"scope\"` read on it; without it they read on the viewer's clock.\n */\n scopeTimeZone?: string | null;\n /** Shown while the session loads (and for the one render a change takes). */\n fallback?: ReactNode;\n children: ReactNode;\n}\n\n/**\n * The scope's clock: `scopeTimeZone` when the runtime knows it, else the viewer's. A zone it\n * doesn't know is never a quiet fallback: it throws in development, and in production it is\n * reported (`reportError`, once per zone) before the viewer's clock is used, so a misspelt zone can't show\n * times on the wrong clock unnoticed.\n */\nexport function scopeClock(scopeTimeZone: string | null | undefined, viewerZone: string): string {\n if (scopeTimeZone === undefined || scopeTimeZone === null || scopeTimeZone === \"\") return viewerZone;\n if (isTimeZone(scopeTimeZone)) return scopeTimeZone;\n const error = new RangeError(`[genesis-core] scopeTimeZone \"${scopeTimeZone}\" isn't a time zone this runtime knows (an IANA name such as \"Europe/Berlin\")`);\n if (process.env.NODE_ENV !== \"production\") throw error;\n // Once per zone: a bad zone in a long-lived screen must not flood the error reporter.\n if (!reportedScopeZones.has(scopeTimeZone)) {\n reportedScopeZones.add(scopeTimeZone);\n reportError(error, \"core:viewer-scope\");\n }\n return viewerZone;\n}\n\n/** The unknown scope zones already reported, so each is reported once per page load. */\nconst reportedScopeZones = new Set<string>();\n\n/**\n * Keeps one viewer's cached data from ever showing to the next. Children\n * render only once the viewer is known, under a key of that viewer, so a\n * sign-out or a new person signing in unmounts every screen and its queries\n * before the cache is emptied and the new viewer's screens mount fresh. The\n * first known viewer empties a restored cache too, unless it's the\n * `persistedViewer` it was saved for.\n *\n * ```tsx\n * <ViewerScope viewer={session === undefined ? undefined : (session?.user.id ?? null)}>\n * <App />\n * </ViewerScope>\n * ```\n */\nexport function ViewerScope({ viewer, persistedViewer: persistedViewerProp, scope, roles, timeZone, scopeTimeZone, fallback = null, children }: ViewerScopeProps) {\n const queryClient = useQueryClient();\n const restoredFor = useContext(PersistedViewerContext);\n const persistedViewer = persistedViewerProp !== undefined ? persistedViewerProp : restoredFor;\n const zone = personTimeZone({ timeZone });\n // Memoised, and scopeClock reports a zone once, so a bad zone isn't reported on every render.\n const scopeZone = useMemo(() => scopeClock(scopeTimeZone, zone), [scopeTimeZone, zone]);\n const day = useToday(zone);\n // A new scope object each render shouldn't re-render every reader: compare by value.\n const scopeKey = stableJson(scope ?? {});\n // Roles by value too: undefined stays undefined, so \"not known yet\" never equals \"none\".\n // Roles that aren't plain JSON count as unknown in production (rolesKeyOf warns; development throws).\n const rolesKey = roles === undefined ? undefined : rolesKeyOf(roles);\n const value = useMemo<ViewerContext>(\n () => ({ viewer: viewer ?? null, scope: scope ?? {}, ...(rolesKey !== undefined ? { roles } : {}), timeZone: zone, scopeTimeZone: scopeZone, day }),\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [viewer, scopeKey, rolesKey, zone, scopeZone, day],\n );\n // The last roles known for this viewer. Arriving (undefined → roles) or going back to undefined\n // changes nothing; different roles for the same person send their waiting writes, then reread\n // everything under the new roles. Nothing remounts: the person, their drafts and their\n // navigation are the same.\n const known = useRef<{ viewer: string | null | undefined; roles: string | undefined }>({ viewer, roles: undefined });\n useEffect(() => {\n if (known.current.viewer !== viewer) known.current = { viewer, roles: undefined };\n if (rolesKey === undefined) return;\n const previous = known.current.roles;\n known.current.roles = rolesKey;\n if (previous === undefined || previous === rolesKey) return;\n // The session is still theirs: their writes go out, and the database decides each one with the\n // roles as they are when it arrives (a refused one fails as any refused write does).\n void flushPendingWrites(queryClient).then(() => queryClient.invalidateQueries());\n }, [viewer, rolesKey, queryClient]);\n // Who the children were last mounted for, and how many times they were reset. Undefined before\n // the first mount.\n const [mounted, setMounted] = useState<{ viewer: string | null; epoch: number } | undefined>(undefined);\n if (viewer === undefined) return <>{fallback}</>;\n if (mounted === undefined || mounted.viewer !== viewer) {\n const keep = mounted === undefined && persistedViewer !== undefined && persistedViewer === viewer;\n // Nothing for the new viewer is mounted yet, so emptying now can't strand\n // a fetch; the old viewer's screens unmount with this render.\n if (!keep) {\n // The session already belongs to the new viewer: the old one's unsent\n // writes must never go out under it. (clearViewerCache, run before the\n // session changes, sends them instead.)\n dropPendingWrites(queryClient);\n void queryClient.cancelQueries();\n queryClient.clear();\n }\n setMounted({ viewer, epoch: (mounted?.epoch ?? 0) + 1 });\n return <>{fallback}</>;\n }\n return (\n <ViewerContextValue.Provider value={value}>\n <Fragment key={`${viewer ?? \"signed-out\"}#${mounted.epoch}`}>{children}</Fragment>\n </ViewerContextValue.Provider>\n );\n}\n","import { createContext, useContext, useEffect, useMemo } from \"react\";\nimport { ViewerScope, type ViewerScopeProps } from \"./viewer-scope\";\nimport { workspaceAt, workspaceHref, type Workspace, type WorkspaceHrefOptions } from \"../workspaces\";\n\n/**\n * The workspace the viewer is in, and where each of their others is from here.\n *\n * @stability Beta\n */\nexport interface WorkspaceContext<W extends Workspace = Workspace> {\n /** Undefined when the URL is in no workspace (the app's front door, a sign-in page). */\n current: W | undefined;\n workspaces: readonly W[];\n /** Where switching to `to` goes from the current URL, keeping the viewer's place when it can. */\n hrefFor: (to: W) => string;\n}\n\nconst WorkspaceContextValue = createContext<WorkspaceContext | null>(null);\n\n/**\n * The nearest `WorkspaceScope`'s workspaces, or null outside one.\n *\n * @stability Beta\n */\nexport function useWorkspace<W extends Workspace = Workspace>(): WorkspaceContext<W> | null {\n return useContext(WorkspaceContextValue) as WorkspaceContext<W> | null;\n}\n\nconst STORAGE_PREFIX = \"genesis:workspace:\";\n\n/**\n * The workspace this viewer was last in on this device, for the app's front door\n * (`defaultWorkspace(workspaces, rememberedWorkspaceId(viewer))`). Null when unknown.\n *\n * @stability Beta\n */\nexport function rememberedWorkspaceId(viewer: string | null | undefined): string | null {\n if (!viewer || typeof window === \"undefined\") return null;\n try {\n return window.localStorage.getItem(STORAGE_PREFIX + viewer);\n } catch {\n return null;\n }\n}\n\nfunction remember(viewer: string, id: string) {\n try {\n window.localStorage.setItem(STORAGE_PREFIX + viewer, id);\n } catch {\n // private mode or full: the front door falls back to the first tenant.\n }\n}\n\n/** @stability Beta */\nexport interface WorkspaceScopeProps<W extends Workspace = Workspace> extends Omit<ViewerScopeProps, \"scope\" | \"roles\" | \"scopeTimeZone\"> {\n /** Every workspace this viewer has. */\n workspaces: readonly W[];\n /** The current URL's path (`useLocation().pathname`): the workspace is read from it. */\n pathname: string;\n /** Scope keys every workspace adds to its own (rarely needed). */\n scope?: ViewerScopeProps[\"scope\"];\n /** How switching keeps the viewer's place (see `workspaceHref`). */\n keep?: WorkspaceHrefOptions[\"keep\"];\n}\n\n/**\n * `ViewerScope` for an app with workspaces: use it in place of `ViewerScope`. It reads the current\n * workspace from the URL and scopes everything under it to that workspace (its `scope`, `roles` and\n * `timeZone`), so every view with `scope: [\"org_id\"]` follows the switcher with no screen code. It\n * remembers the workspace per viewer on this device, and gives `WorkspaceSwitcher` its list.\n *\n * ```tsx\n * <WorkspaceScope viewer={userId} workspaces={workspaces} pathname={location.pathname}>\n * <AppShell headerSlot={<WorkspaceSwitcher linkComponent={Link} />} …>\n * </WorkspaceScope>\n * ```\n *\n * @stability Beta\n */\nexport function WorkspaceScope<W extends Workspace>({ workspaces, pathname, scope, keep, children, ...viewerProps }: WorkspaceScopeProps<W>) {\n const current = workspaceAt(workspaces, pathname);\n const value = useMemo<WorkspaceContext<W>>(\n () => ({\n current,\n workspaces,\n hrefFor: (to) => workspaceHref(workspaces, to, pathname, keep ? { keep } : {}),\n }),\n [current, workspaces, pathname, keep],\n );\n const viewer = viewerProps.viewer;\n useEffect(() => {\n if (viewer && current) remember(viewer, current.id);\n }, [viewer, current]);\n return (\n <WorkspaceContextValue.Provider value={value as unknown as WorkspaceContext}>\n <ViewerScope\n {...viewerProps}\n scope={{ ...scope, ...current?.scope }}\n {...(current?.roles !== undefined ? { roles: current.roles } : {})}\n {...(current?.timeZone !== undefined ? { scopeTimeZone: current.timeZone } : {})}\n >\n {children}\n </ViewerScope>\n </WorkspaceContextValue.Provider>\n );\n}\n\n"]}
package/dist/csv.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { D as DataProvider, F as FieldSchema, S as SortParam, a as FilterParam } from './types-CtJxwoyv.js';
1
+ import { D as DataProvider, F as FieldSchema, S as SortParam, a as FilterParam } from './types-BriIV4e_.js';
2
2
 
3
3
  /** RFC 4180 field: quoted when it holds a comma, quote or line break. */
4
4
  declare function csvField(value: unknown): string;
@@ -1 +1 @@
1
- export { m as FieldType, y as ResourceFormFieldDef, T as SelectOption } from './types-CtJxwoyv.js';
1
+ export { t as FieldType, R as ResourceFormFieldDef, Z as SelectOption } from './types-BriIV4e_.js';
@@ -0,0 +1,334 @@
1
+ import { R as ResourceFormFieldDef } from '../types-BriIV4e_.js';
2
+ import { Day } from '../dates.js';
3
+
4
+ /**
5
+ * `value` kept inside `min` and `max` (either may be left out). `NaN` reads as 0 (then clamped),
6
+ * so a field never shows "NaN". A `min` above `max` is a caller's mistake and throws a RangeError
7
+ * rather than picking one end silently.
8
+ */
9
+ declare function clampNumber(value: number, min?: number, max?: number): number;
10
+ /**
11
+ * `value` on the grid of `step`s counted from `min` (min 1, step 2: 1, 3, 5…), inside `min` and
12
+ * `max`. A step of 0 or less, or one that isn't finite, only clamps.
13
+ */
14
+ declare function snapToStep(value: number, step: number, min: number, max: number): number;
15
+ interface NumberStepOptions {
16
+ min?: number | undefined;
17
+ max?: number | undefined;
18
+ /** Default 1. */
19
+ step?: number | undefined;
20
+ }
21
+ /** One press of a stepper: `value` moved by `step` up (`1`) or down (`-1`), kept inside the range. */
22
+ declare function stepNumber(value: number, direction: 1 | -1, options?: NumberStepOptions): number;
23
+ /** Whether a stepper's down (`-1`) or up (`1`) button can move `value`. */
24
+ declare function canStepNumber(value: number, direction: 1 | -1, options?: NumberStepOptions): boolean;
25
+ interface ParseNumberOptions {
26
+ /**
27
+ * The locale whose marks the text uses (`"de-DE"`: "1.234,5"). Its group and decimal marks are
28
+ * read from `Intl.NumberFormat`. Without one, the marks are worked out from the text.
29
+ */
30
+ locale?: string | undefined;
31
+ }
32
+ /**
33
+ * A number as typed: "1.5", "-3", "1,234" and "1,234.5" (commas group thousands), "1,5" and
34
+ * "1.234,5" (a comma as the decimal mark), "1 000" and "1'000". Anything else (an empty field,
35
+ * "abc", "1.2.3", "1 5") is `null`, so the field keeps its value instead of becoming NaN. Only
36
+ * ASCII digits are read ("١٢٣" is `null`).
37
+ *
38
+ * A run of spaces (no-break and narrow ones too) or apostrophes (' and ’) is a group mark, read
39
+ * like any other: only between whole groups of three in the whole part ("1 000,25", "1’234.5";
40
+ * not "1 5" or "12 34,5"), with at most one "," or "." after it as the decimal mark.
41
+ *
42
+ * Without a `locale`, the last of "." and "," is the decimal mark when both appear; a mark that
43
+ * appears more than once groups thousands; one comma followed by exactly three digits groups
44
+ * thousands ("1,234" is 1234), any other single comma is the decimal mark ("1,5", "0,125").
45
+ * Pass `locale` to read the text with that locale's marks instead, as strictly.
46
+ */
47
+ declare function parseNumberInput(text: string, options?: ParseNumberOptions): number | null;
48
+ interface NumberDraftOptions {
49
+ min?: number | undefined;
50
+ max?: number | undefined;
51
+ /** Decimal places the field keeps. A typed number with more is passed on only when it is committed, rounded. */
52
+ precision?: number | undefined;
53
+ locale?: string | undefined;
54
+ }
55
+ /**
56
+ * What a number field does with its text as it is typed. `value` is the number it reads (`null`
57
+ * while it isn't one: "", "-", "1."), and `ready` whether to pass it on now: inside `min` and
58
+ * `max`, within `precision`, and not text that may still be a thousands group ("1,2" and "1,23",
59
+ * with no `locale`, may be on the way to "1,234"). Anything not ready is passed on when the field
60
+ * is left, through `commitNumberDraft`, so typing "1" on the way to "15" with `min` 10 never
61
+ * sends 10, and typing "1,234" never sends 1.2.
62
+ */
63
+ declare function readNumberDraft(text: string, options?: NumberDraftOptions): {
64
+ value: number | null;
65
+ ready: boolean;
66
+ };
67
+ /**
68
+ * The number a field keeps when it is left: what's typed, rounded to `precision` and clamped to
69
+ * `min` and `max`, so what is stored is what the field then shows. `null` when the text isn't a number.
70
+ */
71
+ declare function commitNumberDraft(text: string, options?: NumberDraftOptions): number | null;
72
+ /**
73
+ * Where two thumbs of a range slider may go: each snapped, the low one never past the high one.
74
+ * `moving` says which thumb the person moved, so it stops at the other instead of pushing it.
75
+ */
76
+ declare function clampRange(value: readonly [number, number], options: {
77
+ min: number;
78
+ max: number;
79
+ step?: number | undefined;
80
+ moving?: 0 | 1 | undefined;
81
+ }): [number, number];
82
+
83
+ /** Whether every word of `query` appears in one of `texts` (an empty query matches everything). */
84
+ declare function matchesQuery(texts: string | readonly (string | null | undefined)[], query: string): boolean;
85
+ /** An option a combobox lists: what it stores, what it shows, and a second line. */
86
+ interface ComboboxOption<T = string> {
87
+ value: T;
88
+ label: string;
89
+ description?: string | undefined;
90
+ disabled?: boolean | undefined;
91
+ }
92
+ /** The options whose label or description matches `query`, in the order given. */
93
+ declare function filterOptions<O extends {
94
+ label: string;
95
+ description?: string | undefined;
96
+ }>(options: readonly O[], query: string): O[];
97
+
98
+ /** `items` with the one at `from` moved to `to` (both from 0, `to` counted after it is taken out). */
99
+ declare function moveItem<T>(items: readonly T[], from: number, to: number): T[];
100
+ /**
101
+ * The index a dragged item lands on: its start index plus how far it was dragged, in whole rows
102
+ * (`offset` over `rowSize`), kept inside the list.
103
+ */
104
+ declare function dropIndex(start: number, offset: number, rowSize: number, total: number): number;
105
+ /**
106
+ * A move's words for a screen reader, from a template with `{name}`, `{n}` (the new position,
107
+ * from 1) and `{total}`: "Week 1 moved to position 3 of 5."
108
+ */
109
+ declare function movedAnnouncement(name: string, to: number, total: number, template?: string): string;
110
+
111
+ /** A time of day: hours 0-23, minutes 0-59. */
112
+ interface TimeOfDay {
113
+ hours: number;
114
+ minutes: number;
115
+ }
116
+ /**
117
+ * A time as typed: "14:30", "2:30 pm", "2pm", "1430", "9.05". `null` when it isn't one, so the
118
+ * field keeps its last good value.
119
+ */
120
+ declare function parseTimeOfDay(text: string): TimeOfDay | null;
121
+ /** "14:30" (24-hour, the stored form and an `<input type="time">`'s value). */
122
+ declare function timeToValue(time: TimeOfDay): string;
123
+ /** A time shown to a person: "2:30 PM" with `hour12`, else "14:30". */
124
+ declare function formatTimeOfDay(time: TimeOfDay, options?: {
125
+ hour12?: boolean | undefined;
126
+ }): string;
127
+ /** The time of day a Date holds, on the device's clock. */
128
+ declare function timeOfDate(date: Date): TimeOfDay;
129
+ /** `date` with its time of day set (seconds cleared), on the device's clock. */
130
+ declare function withTimeOfDay(date: Date, time: TimeOfDay): Date;
131
+ /** Every time from 00:00 in steps of `minutes` (default 30), for a picker's list. */
132
+ declare function timeSlots(minutes?: number): TimeOfDay[];
133
+
134
+ /** The two colour schemes a chart's series can name a colour for. */
135
+ type ChartScheme = "light" | "dark";
136
+ /**
137
+ * One series of a chart config: its label, and a colour for both schemes (`color`) or one per
138
+ * scheme (`theme`). The web's `ChartConfig` is a record of these.
139
+ */
140
+ interface ChartSeriesConfig<Label = unknown> {
141
+ label?: Label;
142
+ color?: string | undefined;
143
+ theme?: Partial<Record<ChartScheme, string>> | undefined;
144
+ }
145
+ /** A series' colour in a scheme: its `theme` colour for the scheme, else `color`. */
146
+ declare function chartSeriesColor(series: Pick<ChartSeriesConfig, "color" | "theme"> | undefined, scheme: ChartScheme): string | undefined;
147
+ /**
148
+ * The design token a colour names, when it is one of the chart tokens: `"var(--chart-2)"`,
149
+ * `"hsl(var(--chart-2))"` and `"chart-2"` are all `"chart-2"`. A literal colour is `undefined`.
150
+ */
151
+ declare function chartTokenOf(color: string | undefined): `chart-${number}` | undefined;
152
+ /** The default token for the `index`th series: chart-1 to chart-5, then round again. */
153
+ declare function defaultChartToken(index: number): `chart-${number}`;
154
+ /**
155
+ * The value axis for `keys` over `rows`: from 0 (or the lowest value, when below 0) to the
156
+ * highest, widened to round ticks.
157
+ */
158
+ declare function chartDomain(rows: readonly Record<string, unknown>[], keys: readonly string[], options?: {
159
+ ticks?: number | undefined;
160
+ stacked?: boolean | undefined;
161
+ }): {
162
+ min: number;
163
+ max: number;
164
+ ticks: number[];
165
+ };
166
+ /** Where `value` falls on an axis `size` long (0 at `min`, `size` at `max`). */
167
+ declare function chartPosition(value: number, domain: {
168
+ min: number;
169
+ max: number;
170
+ }, size: number): number;
171
+ /**
172
+ * What a screen reader hears for a chart, since it can't see the bars: each series and its
173
+ * values, "Visitors: Jan 120, Feb 140. Signups: Jan 12, Feb 18."
174
+ */
175
+ declare function chartSummary(rows: readonly Record<string, unknown>[], xKey: string, series: readonly {
176
+ key: string;
177
+ label: string;
178
+ }[], format?: (value: number) => string): string;
179
+
180
+ /** Digits only, the usual SMS and authenticator code. */
181
+ declare const OTP_PATTERN_DIGITS = "^\\d+$";
182
+ /** A pasted or autofilled code without the spaces, dashes and dots it is often grouped with ("123-456"). */
183
+ declare function stripOtpSeparators(text: string): string;
184
+ /**
185
+ * What a code field keeps of `text`: separators stripped, cut to `length` characters, and only
186
+ * when the whole code then matches `pattern`. `null` means it doesn't, and the field keeps the
187
+ * code it had (input-otp refuses such a change the same way).
188
+ */
189
+ declare function sanitizeOtp(text: string, length: number, pattern?: string): string | null;
190
+ /** One box of a code: its character, and whether the caret is in it. */
191
+ interface OtpSlot {
192
+ char: string | null;
193
+ isActive: boolean;
194
+ }
195
+ /** The boxes for `value`: each character in its box, and the caret in the first empty one (or the last). */
196
+ declare function otpSlots(value: string, length: number, focused: boolean): OtpSlot[];
197
+ /** Whether every box is filled: the moment to submit. */
198
+ declare function otpComplete(value: string, length: number): boolean;
199
+
200
+ /** Whether a repeating group with `count` items may add one, and may remove one. */
201
+ declare function fieldArrayLimits(count: number, field: Pick<ResourceFormFieldDef, "arrayMin" | "arrayMax">): {
202
+ canAdd: boolean;
203
+ canRemove: boolean;
204
+ };
205
+ /**
206
+ * The add button's words for a group: "Add Contact" for "Contacts", "Add Address" for
207
+ * "Addresses", "Add Status" for "Status". The field's `arrayItemLabel` (its one item's name)
208
+ * wins over the guess, for a plural English doesn't make with an "s".
209
+ */
210
+ declare function fieldArrayAddLabel(label: string, itemLabel?: string | undefined): string;
211
+ /** A wizard step's fields, in the form's order, without those hidden for these values. */
212
+ declare function wizardStepFields<F extends Pick<ResourceFormFieldDef, "key" | "visible">>(fields: readonly F[], stepFields: readonly string[], values: Record<string, unknown>): F[];
213
+ /** The progress line over a wizard, from `useWizard()`'s state: "Step 2 of 4" and its `progress` as a percent. */
214
+ declare function wizardProgressLabel(wizard: {
215
+ currentStep: number;
216
+ totalSteps: number;
217
+ progress: number;
218
+ }): {
219
+ step: string;
220
+ percent: string;
221
+ };
222
+ /** Default most a file may weigh: 10 MB. */
223
+ declare const DEFAULT_MAX_FILE_SIZE: number;
224
+ /** A file's size in words: "512 B", "1.5 KB", "3.2 MB". */
225
+ declare function formatFileSize(bytes: number): string;
226
+ /** What an upload field needs to know about a picked file, on either platform. */
227
+ interface PickedFileInfo {
228
+ name: string;
229
+ /** MIME type, e.g. "image/png". Empty when unknown. */
230
+ type?: string | undefined;
231
+ /** Bytes, when known. */
232
+ size?: number | undefined;
233
+ }
234
+ /**
235
+ * Why `file` can't be added, in words, or `null` when it can: too heavy for `maxSize`, or not a
236
+ * type `accept` lists.
237
+ */
238
+ declare function fileProblem(file: PickedFileInfo, options: {
239
+ accept?: string | undefined;
240
+ maxSize?: number | undefined;
241
+ }): string | null;
242
+ /** An upload field's `accept`: the field's, else images for an image field. */
243
+ declare function fieldAccept(field: Pick<ResourceFormFieldDef, "accept" | "type">): string | undefined;
244
+
245
+ /** A stat's change: "+12% vs last week", and whether it went up. */
246
+ declare function formatTrend(trend: {
247
+ value: number;
248
+ label: string;
249
+ }): {
250
+ text: string;
251
+ positive: boolean;
252
+ };
253
+ /** The goal and task statuses StatusBadge draws. */
254
+ type StatusBadgeStatus = "onTrack" | "atRisk" | "offTrack" | "done" | "blocked" | "inProgress";
255
+ /** Each status's tone: the tint both platforms draw it in. */
256
+ declare const STATUS_BADGE_TONES: Readonly<Record<StatusBadgeStatus, "success" | "warning" | "info" | "danger">>;
257
+ /** A status in words, for a badge with no children: "On track", "In progress". */
258
+ declare function statusBadgeLabel(status: StatusBadgeStatus): string;
259
+ /** Where a step is in a stepper, from the current one. */
260
+ type StepState = "complete" | "current" | "upcoming";
261
+ /** The state of step `index` when `current` is the step the person is on. */
262
+ declare function stepState(index: number, current: number): StepState;
263
+ /**
264
+ * The day group a notification goes under: "Upcoming" for a later day (scheduled, or a clock
265
+ * that runs ahead), then "Today", "Yesterday" and "Earlier".
266
+ */
267
+ type NotificationDayBucket = "Upcoming" | "Today" | "Yesterday" | "Earlier";
268
+ /** The day groups in the order a list shows them. */
269
+ declare const NOTIFICATION_DAY_BUCKETS: readonly NotificationDayBucket[];
270
+ interface NotificationClock {
271
+ /** The moment the groups count from. Default now. */
272
+ now?: Date | undefined;
273
+ /**
274
+ * The zone whose days are counted (an IANA name, "Europe/Paris"). Default the device's. A
275
+ * server rendering the list passes the person's zone, or its days won't be theirs.
276
+ */
277
+ timeZone?: string | undefined;
278
+ }
279
+ /** Which day group `timestamp` belongs to, counted in calendar days on `timeZone`'s clock. */
280
+ declare function notificationDayBucket(timestamp: string | Date, clock?: NotificationClock): NotificationDayBucket;
281
+ /**
282
+ * Notifications under day headings (Upcoming, Today, Yesterday, Earlier), in that order, each
283
+ * keeping the order given. Empty groups are left out.
284
+ */
285
+ declare function groupNotificationsByDay<N extends {
286
+ timestamp: string | Date;
287
+ }>(items: readonly N[], clock?: NotificationClock): {
288
+ title: NotificationDayBucket;
289
+ data: N[];
290
+ }[];
291
+ /** Where a custom view is: the states Genesis draws, then `ready` for the app's own. */
292
+ type CustomViewStatus = "loading" | "error" | "empty" | "ready";
293
+ /** A custom view's state from its query: an error first, then the first load, then no rows. */
294
+ declare function customViewStatus(query: {
295
+ error: unknown;
296
+ loading: boolean;
297
+ empty: boolean;
298
+ }): CustomViewStatus;
299
+
300
+ /** The slide a scroll `offset` rests on, for slides `pageSize` wide, kept inside `count`. */
301
+ declare function carouselIndex(offset: number, pageSize: number, count: number): number;
302
+ /** The scroll offset that shows slide `index`. */
303
+ declare function carouselOffset(index: number, pageSize: number): number;
304
+
305
+ /** A Date's calendar day on the device's clock (a picker's dates are the person's own days). */
306
+ declare function dayOfDate(date: Date): Day;
307
+ /** A calendar day as a Date at local midnight. */
308
+ declare function dateOfDay(day: Day): Date;
309
+ /**
310
+ * The weeks a month's grid shows: whole weeks, from `weekStartsOn` (0 Sunday to 6 Saturday;
311
+ * default 1, Monday, as genesis-core's `startOfWeek` and `monthGridRange`). Any other
312
+ * `weekStartsOn` throws a RangeError, as `weekdayDays` does.
313
+ */
314
+ declare function monthWeeks(month: Day, weekStartsOn?: number): Day[][];
315
+ /** Whether `day` is inside a range, both ends included (an open end takes nothing past the other). */
316
+ declare function dayInRange(day: Day, range: {
317
+ from?: Day | undefined;
318
+ to?: Day | undefined;
319
+ }): boolean;
320
+ /** A range after picking `day`: a new start, or the end once the start is set (swapped if earlier). */
321
+ declare function pickRangeDay(range: {
322
+ from?: Day | undefined;
323
+ to?: Day | undefined;
324
+ } | undefined, day: Day): {
325
+ from: Day;
326
+ to?: Day;
327
+ };
328
+ /**
329
+ * The seven weekday dates of a week starting `weekStartsOn`, for the grid's header: the same
330
+ * default (1, Monday) and the same RangeError outside 0 to 6 as `monthWeeks`.
331
+ */
332
+ declare function weekdayDays(weekStartsOn?: number): Day[];
333
+
334
+ export { type ChartScheme, type ChartSeriesConfig, type ComboboxOption, type CustomViewStatus, DEFAULT_MAX_FILE_SIZE, NOTIFICATION_DAY_BUCKETS, type NotificationClock, type NotificationDayBucket, type NumberDraftOptions, type NumberStepOptions, OTP_PATTERN_DIGITS, type OtpSlot, type ParseNumberOptions, type PickedFileInfo, STATUS_BADGE_TONES, type StatusBadgeStatus, type StepState, type TimeOfDay, canStepNumber, carouselIndex, carouselOffset, chartDomain, chartPosition, chartSeriesColor, chartSummary, chartTokenOf, clampNumber, clampRange, commitNumberDraft, customViewStatus, dateOfDay, dayInRange, dayOfDate, defaultChartToken, dropIndex, fieldAccept, fieldArrayAddLabel, fieldArrayLimits, fileProblem, filterOptions, formatFileSize, formatTimeOfDay, formatTrend, groupNotificationsByDay, matchesQuery, monthWeeks, moveItem, movedAnnouncement, notificationDayBucket, otpComplete, otpSlots, parseNumberInput, parseTimeOfDay, pickRangeDay, readNumberDraft, sanitizeOtp, snapToStep, statusBadgeLabel, stepNumber, stepState, stripOtpSeparators, timeOfDate, timeSlots, timeToValue, weekdayDays, withTimeOfDay, wizardProgressLabel, wizardStepFields };