@inspectorhub/field-ui 0.0.0-stage → 0.1.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.
package/LICENSE ADDED
@@ -0,0 +1,17 @@
1
+ GNU AFFERO GENERAL PUBLIC LICENSE
2
+ Version 3, 19 November 2007
3
+
4
+ OpenInspection
5
+ Copyright (C) 2024-present InspectorHub Contributors
6
+
7
+ This program is free software: you can redistribute it and/or modify
8
+ it under the terms of the GNU Affero General Public License as published
9
+ by the Free Software Foundation, version 3 of the License.
10
+
11
+ This program is distributed in the hope that it will be useful,
12
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ GNU Affero General Public License for more details.
15
+
16
+ The full license text is available at:
17
+ https://www.gnu.org/licenses/agpl-3.0.html
package/README.md CHANGED
@@ -1,3 +1,115 @@
1
- # Temporary Holding Version
1
+ # @inspectorhub/field-ui
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ The OpenInspection field inspection editor as an embeddable React package, so
4
+ the web app and other hosts (for example the offline-first native client) can
5
+ share one editor.
6
+
7
+ **Status: pre-1.0 and incomplete.** The package is being extracted from the
8
+ OpenInspection web app in steps. What the published build exports today is the
9
+ host contract (the data source, its types, the provider and hooks, locale
10
+ binding) and an in-memory fake for tests. The editor components themselves are
11
+ not exported yet; this README says so again where it matters, and will change
12
+ when they land.
13
+
14
+ ## What the build exports
15
+
16
+ Built with `npm run build -w @inspectorhub/field-ui` (ESM only, React and Yjs
17
+ external):
18
+
19
+ | Entry | Contents |
20
+ |---|---|
21
+ | `@inspectorhub/field-ui` | `FieldDataSourceProvider`, `useFieldDataSource`, `useFieldCommand`, `useFieldEnsureHuman`, `useFieldSlots`, `isIgnored`, `setFieldLocale`, `bindFieldLocaleSource`, and the TypeScript types of the contract |
22
+ | `@inspectorhub/field-ui/testing` | `createFakeDataSource` and fakes for each optional resource, for host test suites |
23
+ | `@inspectorhub/field-ui/theme.css` | The design-token and base-layer CSS (see Theme) |
24
+
25
+ ## The data source contract
26
+
27
+ The editor never talks to a server itself. A host implements `FieldDataSource`
28
+ and passes it to `FieldDataSourceProvider`:
29
+
30
+ ```tsx
31
+ import { FieldDataSourceProvider } from '@inspectorhub/field-ui';
32
+
33
+ <FieldDataSourceProvider dataSource={myDataSource} slots={mySlots}>
34
+ {/* editor */}
35
+ </FieldDataSourceProvider>
36
+ ```
37
+
38
+ `FieldDataSource` (see `FieldDataSource` in the published `.d.ts` for the exact
39
+ signatures):
40
+
41
+ - `load(inspectionId, scope?)` returns the `EditorData` the editor opens with
42
+ (inspection, template schema, results, rating levels, tag library, units,
43
+ and so on).
44
+ - `session()` returns `SessionInfo`: the viewer's id (null when the host cannot tell; the editor then announces no presence), role, locale, time zone,
45
+ date and clock formats, and the video backend.
46
+ - `execute(inspectionId, command, { idempotencyKey })` runs one typed
47
+ `FieldCommand` and answers a `CommandResult`.
48
+ - `notify`, `reload`, `exit`, plus optional `restartSession` and `openUrl`.
49
+ - `isOnline()` and `onOnlineChange(cb)`.
50
+ - `collab`: a `CollabConnector` that opens the results Yjs document for an
51
+ inspection (local persistence first, then network).
52
+ - `media`: a `PendingMediaStore` and a `uploader(inspectionId, doc)` factory.
53
+ - `urls`: `FieldUrls`, the address builders for photos, reports, presence and
54
+ in-app paths.
55
+ - `resources`: `FieldResources`, optional capabilities (preferences, canned
56
+ comments, cost items, repair items, media pool, settings sheet, AI assist,
57
+ publish readiness, template search, version history, video). A member the
58
+ host leaves out hides its entry point.
59
+ - `platform`: `'web' | 'ios' | 'android'`.
60
+
61
+ `FieldHostSlots` carries host-owned UI (theme switch, PDF export, human
62
+ verification). An absent slot hides its entry point.
63
+
64
+ A host that can render on a server may remember which layout band (`phone`,
65
+ `tablet`, `desktop`) a device showed last time, so the server render matches the
66
+ client's first render instead of always assuming `desktop`. It receives the band
67
+ through the optional `FieldHostSlots.onLayoutObserved(layout)` (called after mount
68
+ and when the band changes), stores it however it likes, and returns it as the
69
+ optional `EditorData.initialLayout` on the next load. The real viewport still
70
+ decides right after mount, so a wrong memory is corrected. The package never
71
+ stores the value itself.
72
+
73
+ Use `@inspectorhub/field-ui/testing` for a ready-made in-memory implementation.
74
+
75
+ ## Theme
76
+
77
+ The package ships its design tokens as plain CSS that your Tailwind v4 build
78
+ compiles (it contains `@theme` blocks), so it is a file rather than bundled
79
+ output. In your global stylesheet:
80
+
81
+ ```css
82
+ @import "tailwindcss";
83
+ @import "@inspectorhub/field-ui/theme.css";
84
+
85
+ /* Scan the package so Tailwind generates the utilities it uses. Adjust the
86
+ relative path from your stylesheet to node_modules. */
87
+ @source "../node_modules/@inspectorhub/field-ui/dist";
88
+ ```
89
+
90
+ ## Third-party stylesheets
91
+
92
+ The editor's photo gallery and lightbox use `react-photo-album` and
93
+ `yet-another-react-lightbox`. Those libraries are peers and their CSS is not
94
+ copied into `dist`. The current build does not import any of them yet (the
95
+ editor components are not exported), so nothing is required today. Once the
96
+ editor components ship, the host must import, from its own copy of each
97
+ library:
98
+
99
+ ```ts
100
+ import 'yet-another-react-lightbox/styles.css';
101
+ import 'react-photo-album/rows.css';
102
+ ```
103
+
104
+ ## Peer dependencies
105
+
106
+ Declared in `package.json` and resolved by the host so there is one copy of
107
+ each: `react` and `react-dom` ^19, `yjs`, `lib0`, `y-indexeddb`, `y-protocols`,
108
+ `konva`, `react-konva`, `react-easy-crop`, `react-photo-album`, `sortablejs`,
109
+ `yet-another-react-lightbox`. Today only `react` and `yjs` (in
110
+ `/testing`) are imported by the build; the rest are declared ahead of the
111
+ editor components.
112
+
113
+ ## Licence
114
+
115
+ Licensed under the GNU Affero General Public License v3 (AGPL-3.0-only). See LICENSE.
@@ -0,0 +1,9 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __export = (target, all) => {
3
+ for (var name in all)
4
+ __defProp(target, name, { get: all[name], enumerable: true });
5
+ };
6
+
7
+ export {
8
+ __export
9
+ };