@inspectorhub/field-ui 0.0.0-stage → 0.2.1

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.
@@ -0,0 +1,155 @@
1
+ import { F as FieldCommand, C as CommandResult, a as CommandData, b as FieldDataSource } from './data-source-B_ogNIa3.js';
2
+ export { A as AiAssistInput, c as AiAssistResult, d as AutoAdvanceMode, e as AutofillReason, B as BulkCreateUnitsBody, f as CollabConnector, g as CommandDataMap, h as CommandKey, i as CommentsLibraryEntry, j as CommentsLibraryQuery, k as CommentsLibraryRow, l as CommercialPresets, m as ComplianceCommand, n as CompliancePanelData, o as CostItemView, p as CostItemWrite, q as CostItemsListing, D as DateFormat, r as DefectCategory, s as DocumentReviewItemView, E as EditorData, t as EditorInspection, u as ExecuteOptions, v as FieldResources, w as FieldUrls, I as InspectionPrefs, x as InspectionUnit, M as MediaFileResult, y as MediaPoolListing, z as MediaUploader, N as NotifyOptions, G as NotifyVariant, O as OutboundCoolingWindow, P as PcaNarrative, H as PcaNarrativeData, J as PendingMediaRecord, K as PendingMediaStore, L as PhotoAnnotateMeta, Q as PhotoCropMeta, R as PhotoCropTransform, S as PhotoUploadMeta, T as PropertyMetaField, U as PsqView, V as RatingLevel, W as RelianceText, X as RepairItemOption, Y as ReportLinkTtl, Z as ReportSignoffView, _ as ResultMap, $ as ResultsDocHandle, a0 as RevisionStatus, a1 as SaveStructureTemplateCommand, a2 as SchemaItem, a3 as SchemaSection, a4 as SessionInfo, a5 as SettingsSheetData, a6 as StatutoryCoverage, a7 as StatutoryDetails, a8 as TagLibraryEntry, a9 as TemplateItemBody, aa as TemplateSchema, ab as TemplateSearchResult, ac as TemplateSnapshot, ad as TemplateSummary, ae as TimeFormat, af as UnitCommand, ag as UnitProgress, ah as VersionSnapshotContent, ai as VersionSnapshotEntry, aj as VideoFinalizeInput, ak as VideoUploadRef, al as VideoUploadTicket } from './data-source-B_ogNIa3.js';
3
+ import * as react from 'react';
4
+ import { ReactNode } from 'react';
5
+ import 'yjs';
6
+
7
+ /**
8
+ * Host-supplied UI, injected through `FieldDataSourceProvider` rather than read
9
+ * from the data source: the package renders the entry point, the host owns the
10
+ * implementation.
11
+ */
12
+ interface FieldHostSlots {
13
+ /** The theme switch shown in the header (the web host passes `ThemeSegmentControl`). Absent hides it. */
14
+ renderThemeControl?: (props: {
15
+ className?: string;
16
+ }) => ReactNode;
17
+ /**
18
+ * PDF export, kept in the host (it needs the host's download machinery).
19
+ * `run` starts the export for the inspection; the rest is what the header
20
+ * reads off `usePdfExport`. Absent hides the PDF entry points.
21
+ */
22
+ pdf?: {
23
+ run(inspectionId: string): void;
24
+ busy: boolean;
25
+ /** The last failure's sentence, or null. */
26
+ error: string | null;
27
+ /** Button text: the host's `pdfActionLabel`, which swaps in "Generating" / "Retry in N s". */
28
+ actionLabel(defaultLabel: string): string;
29
+ };
30
+ /**
31
+ * The human check that gates an outbound send (publish). Resolves `true` when the person may go on (the
32
+ * check passed, or none is due) and `false` when they cancelled it. Read it through `useFieldEnsureHuman`,
33
+ * which hands back a stable function.
34
+ *
35
+ * FAIL-CLOSED: a host that provides neither this nor `humanCheck: 'not-required'` gets a check that refuses
36
+ * every send and tells the person why. A forgotten slot must never turn the gate off; the client check is the
37
+ * only gate on publishing, so skipping it has to be a decision the host writes down.
38
+ */
39
+ ensureHuman?: () => Promise<boolean>;
40
+ /**
41
+ * The explicit opt-out of the human check, for a host that has none by design (a native shell with its own
42
+ * signed-in session). Only this exact value lets sends through without `ensureHuman`; it is not a default.
43
+ */
44
+ humanCheck?: 'not-required';
45
+ /**
46
+ * The unsaved-changes guard: a component the editor mounts once, which watches `atRisk` and, while it is
47
+ * true, stops the person leaving the page without asking. The host owns the mechanism (a router blocker, the
48
+ * browser's close prompt) and renders its own confirmation. Absent means leaving is never intercepted.
49
+ */
50
+ renderUnsavedGuard?: (props: {
51
+ atRisk: boolean;
52
+ }) => ReactNode;
53
+ /** Told which layout band the browser really shows (after mount, and on change); a host that remembers it returns it as `EditorData.initialLayout`. */
54
+ onLayoutObserved?: (layout: 'phone' | 'tablet' | 'desktop') => void;
55
+ }
56
+
57
+ interface FieldDataSourceProviderProps {
58
+ dataSource: FieldDataSource;
59
+ /** Host-supplied UI (theme control, PDF export). Absent slots hide their entry points. */
60
+ slots?: FieldHostSlots;
61
+ children?: ReactNode;
62
+ }
63
+ declare function FieldDataSourceProvider({ dataSource, slots, children }: FieldDataSourceProviderProps): react.JSX.Element;
64
+ /** The data source of the nearest provider. Throws outside one: a silent null would fail much later. */
65
+ declare function useFieldDataSource(): FieldDataSource;
66
+ /** The host-supplied UI slots; an empty object when the provider was given none. */
67
+ declare function useFieldSlots(): FieldHostSlots;
68
+ /**
69
+ * The host's human check as one stable function, FAIL-CLOSED.
70
+ *
71
+ * - `slots.ensureHuman` present: that function.
72
+ * - `slots.humanCheck === 'not-required'` (the host's explicit opt-out): answers `true` at once.
73
+ * - Neither: refuses (`false`) and shows the person why, because a host that forgot the slot must not
74
+ * silently lose the check. The caller treats `false` as "do not send".
75
+ *
76
+ * The function keeps its identity across renders for as long as the slot and data source do.
77
+ */
78
+ declare function useFieldEnsureHuman(): () => Promise<boolean>;
79
+ /**
80
+ * What `run` answers. `ignored: true` means the call was dropped because another
81
+ * command of this hook was still in flight; nothing was sent and the caller must
82
+ * treat it as a no-op (not as a failure to report).
83
+ */
84
+ type IgnoredRun = {
85
+ ok: false;
86
+ ignored: true;
87
+ error?: undefined;
88
+ };
89
+ type FieldRunResult<D> = CommandResult<D> | IgnoredRun;
90
+ /**
91
+ * True when `run` dropped the call because another command of this hook was in flight. Check this FIRST:
92
+ * an ignored call is neither success nor failure (the first request is still running), so a consumer that
93
+ * toasts an error or rolls back on `!ok` would undo work that is about to succeed.
94
+ */
95
+ declare function isIgnored<D>(result: FieldRunResult<D>): result is IgnoredRun;
96
+ interface FieldCommandRunner {
97
+ run<C extends FieldCommand>(cmd: C): Promise<FieldRunResult<CommandData<C>>>;
98
+ /** True from the call until the answer settles. Render state only; the guard is synchronous and separate. */
99
+ busy: boolean;
100
+ /**
101
+ * The guard itself, read synchronously: true from the moment a `run` started (in the same frame, before any
102
+ * render) until it settles. Use it to decide, BEFORE changing UI state, whether a `run` would be dropped
103
+ * (an optimistic update that a dropped call must not make). It is the same ref `run` tests, not a second
104
+ * guard: `run` stays the only thing that can start a request.
105
+ */
106
+ isBusy(): boolean;
107
+ }
108
+ /**
109
+ * The guarded write channel: the only caller of `FieldDataSource.execute` in the
110
+ * package. It reproduces `useGuardedSubmit` (app/hooks/useGuardedSubmit.ts):
111
+ *
112
+ * - Same-frame guard. `inFlight` is a ref set synchronously, so two `run` calls
113
+ * in one frame send ONE request; the second answers `{ ok: false, ignored: true }`.
114
+ * - Idempotency key. Minted on the first attempt, HELD across a retry of a failed
115
+ * attempt, ROTATED after an `ok` answer. The rotation is written into the ref
116
+ * before the guard is released, so no call can ever carry a spent key. Unlike the
117
+ * host hook (one key per hook), the held key is tied to the request (inspection
118
+ * plus the whole command): a different request mints its own, so a failed
119
+ * `unit:delete` of one row cannot make the delete of another row read as its replay.
120
+ * - `busy` mirrors the in-flight state for rendering.
121
+ * - After unmount no state is set, but the pending promise still settles.
122
+ *
123
+ * A host `execute` that rejects is reported as `{ ok: false, error }` and counts as
124
+ * a failed attempt (the key is held). Use one hook per write surface, as with
125
+ * `useGuardedSubmit`.
126
+ */
127
+ declare function useFieldCommand(inspectionId: string): FieldCommandRunner;
128
+
129
+ /**
130
+ * Pin the package to one locale, explicitly.
131
+ *
132
+ * Use this from a host that has no per-request locale scope: a native shell, a
133
+ * test, a single-user browser app. An unknown tag falls back to the base locale
134
+ * rather than throwing, because a locale the catalogue does not carry is a
135
+ * configuration gap and must not blank the editor. Calling this also detaches
136
+ * any source installed with `bindFieldLocaleSource`.
137
+ *
138
+ * On a server that renders several requests at once, do NOT use this: it writes
139
+ * a module-level variable that every in-flight render reads. Bind a
140
+ * request-scoped source instead.
141
+ */
142
+ declare function setFieldLocale(locale: string): void;
143
+ /**
144
+ * Make the package read its locale from the host on every message call.
145
+ *
146
+ * The host passes the same function its own messages use (on the web, the app
147
+ * runtime's `getLocale`, which reads the request-scoped store on the server and
148
+ * `<html lang>` or the cookie in the browser). The package then agrees with the
149
+ * app by construction, with no copy to go stale and no shared mutable variable
150
+ * between concurrent server renders. `null` restores the package's own variable.
151
+ */
152
+ declare function bindFieldLocaleSource(read: (() => string) | null): void;
153
+
154
+ export { CommandData, CommandResult, FieldCommand, FieldDataSource, FieldDataSourceProvider, bindFieldLocaleSource, isIgnored, setFieldLocale, useFieldCommand, useFieldDataSource, useFieldEnsureHuman, useFieldSlots };
155
+ export type { FieldCommandRunner, FieldDataSourceProviderProps, FieldHostSlots, FieldRunResult, IgnoredRun };