@factorialco/rjsf-f0 2.5.0 → 3.0.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/README.md CHANGED
@@ -10,7 +10,7 @@ Use it inside an app that already runs f0 (the Factorial Code dashboard, the Fac
10
10
  pnpm add @factorialco/rjsf-f0
11
11
  ```
12
12
 
13
- Peers you must already have: `react`, `react-dom`, `@rjsf/core` 6, `@rjsf/utils` 6 and `@factorialco/f0-react` 4.39+ or 6.
13
+ Peers you must already have: `react`, `react-dom`, `@rjsf/core` 6, `@rjsf/utils` 6 and `@factorialco/f0-react` 11.3.1 or later, up to 14 (the pairing table needs f0's `F0FormEditableTable`).
14
14
 
15
15
  ## Usage
16
16
 
@@ -50,20 +50,21 @@ The host app must render f0's `F0Provider` above the form and import `@factorial
50
50
 
51
51
  ## How the mapping works
52
52
 
53
- | RJSF | f0 |
54
- | --- | --- |
55
- | text / email / url / password | `F0FormField` `text` |
56
- | number / integer / `updown` / `range` | `F0FormField` `number` |
57
- | `date` / `datetime-local` / `time` | `F0FormField` `date` / `datetime` / `time` |
58
- | `textarea` | `F0FormField` `textarea` |
59
- | enum select, multi-select | `F0FormField` `select` |
60
- | boolean checkbox, `checkboxes` | `F0Checkbox` |
61
- | `radio` | `F0FormField` `cardSelect` (f0 has no radio control) |
62
- | `file` / `data-url` | f0-styled dropzone + file chips (see below) |
63
- | submit, add/move/copy/remove | `F0Button` |
64
- | `oauth` connect control | `F0Button` (see below) |
65
- | error summary | `F0Alert` |
66
- | section title | `F0Heading` |
53
+ | RJSF | f0 |
54
+ | ------------------------------------- | ---------------------------------------------------- |
55
+ | text / email / url / password | `F0FormField` `text` |
56
+ | number / integer / `updown` / `range` | `F0FormField` `number` |
57
+ | `date` / `datetime-local` / `time` | `F0FormField` `date` / `datetime` / `time` |
58
+ | `textarea` | `F0FormField` `textarea` |
59
+ | enum select, multi-select | `F0FormField` `select` |
60
+ | boolean checkbox, `checkboxes` | `F0Checkbox` |
61
+ | `radio` | `F0FormField` `cardSelect` (f0 has no radio control) |
62
+ | `file` / `data-url` | f0-styled dropzone + file chips (see below) |
63
+ | submit, add/move/copy/remove | `F0Button` |
64
+ | `oauth` connect control | `F0Button` (see below) |
65
+ | `pairing` table | `F0FormEditableTable` (see below) |
66
+ | error summary | `F0Alert` |
67
+ | section title | `F0Heading` |
67
68
 
68
69
  Two deliberate consequences of that mapping:
69
70
 
@@ -72,22 +73,24 @@ Two deliberate consequences of that mapping:
72
73
 
73
74
  ### File fields
74
75
 
75
- `FileWidget` replaces core's, which renders a bare `<input type="file">`. That input gives away a non-native dialog in two ways CSS cannot reach: its "No file chosen" text, and a browse button the *browser* labels in the *browser's* locale — English chrome inside a Spanish form, which no locale propagation on our side can fix.
76
+ `FileWidget` replaces core's, which renders a bare `<input type="file">`. That input gives away a non-native dialog in two ways CSS cannot reach: its "No file chosen" text, and a browse button the _browser_ labels in the _browser's_ locale — English chrome inside a Spanish form, which no locale propagation on our side can fix.
76
77
 
77
78
  The theme draws its own dropzone and one chip per picked file (name, human-readable size, remove button). The value is unchanged: core's own `useFileWidgetProps` still owns the `File` -> `data:` URL exchange, so what RJSF stores is byte-identical.
78
79
 
80
+ One exception, opt-in: when the form provides `formContext.fcode.keptFiles` (`FcodeForm` from `@factorialco/fcode-react-forms` does), a single file larger than 50 MiB (`LARGE_FILE_BYTES`) in a root field is not read at all. Base64 of a file near 1 GB is longer than the longest string a browser can hold, so encoding it fails before the form is submitted; a file that size can only travel through an upload grant anyway, which sends the `File` as it is. The widget hands the `File` to `keptFiles.keep(file)` and stores the string it returns: a `data:` URL with no content and a `fcode-kept` parameter, so validation, conditional schemas and JSON copies of the form data treat it like any other file value. `keptFiles.get(value)` returns the `File` behind it, and the host swaps it back in at submit. Multiple-file and nested fields always encode. A host rendering this theme on its own provides no `keptFiles` and keeps getting `data:` URLs with their content. If the browser cannot read a picked file, the widget shows an error and keeps the previous value.
81
+
79
82
  It does **not** bridge to f0's `F0FormField` `file`. That field is driven by an upload hook returning an opaque id, and — the blocker — its `accept` is a closed `MimeType` allowlist with no file extensions. `ui:options.accept` is a raw HTML accept string, so a schema asking for `.msj` (or any extension without a registered MIME type) would silently lose its filter. The dropzone keeps the string verbatim.
80
83
 
81
84
  `ui:options`:
82
85
 
83
- | Option | Effect |
84
- | --- | --- |
85
- | `accept` | Passed to the input verbatim. Also shown as a hint under the dropzone text. |
86
+ | Option | Effect |
87
+ | -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
88
+ | `accept` | Passed to the input verbatim. Also shown as a hint under the dropzone text. |
86
89
  | `dropzoneText` | Replaces the dropzone copy, before any translation. For a marketplace app this is the path that works: schema strings go through the platform's i18n token substitution and need no cooperation from the embedder. |
87
90
 
88
91
  ### Localising the chrome
89
92
 
90
- Every string this theme renders that the schema did not author goes through RJSF's `translateString` — `Add Item`, `Remove`, `Move up`, `Move down`, `Copy`, `Errors`, and the dropzone copy. **All of them are English until a host supplies a translator**, because RJSF's default translator is the identity function and its `TranslatableString` values *are* the English text (`RemoveButton` is the literal `'Remove'`). Nothing in this package translates on its own.
93
+ Every string this theme renders that the schema did not author goes through RJSF's `translateString` — `Add Item`, `Remove`, `Move up`, `Move down`, `Copy`, `Errors`, and the dropzone copy. **All of them are English until a host supplies a translator**, because RJSF's default translator is the identity function and its `TranslatableString` values _are_ the English text (`RemoveButton` is the literal `'Remove'`). Nothing in this package translates on its own.
91
94
 
92
95
  One prop on the form localises the lot:
93
96
 
@@ -114,19 +117,19 @@ A form rendered inside a localised product without this prop shows English butto
114
117
  > **Nothing is written yet.** You will see a preview first.
115
118
  ```
116
119
 
117
- | Marker | f0 variant |
118
- | --- | --- |
119
- | `[!NOTE]` | `info` |
120
- | `[!TIP]` | `positive` |
121
- | `[!IMPORTANT]` | `info` |
122
- | `[!WARNING]` | `warning` |
123
- | `[!CAUTION]` | `critical` |
120
+ | Marker | f0 variant |
121
+ | -------------- | ---------- |
122
+ | `[!NOTE]` | `info` |
123
+ | `[!TIP]` | `positive` |
124
+ | `[!IMPORTANT]` | `info` |
125
+ | `[!WARNING]` | `warning` |
126
+ | `[!CAUTION]` | `critical` |
124
127
 
125
128
  Any other blockquote still renders as f0's blockquote, and an unrecognised marker is left as the text it is.
126
129
 
127
130
  Two things worth knowing:
128
131
 
129
- - **These are not GFM.** The GFM spec covers tables, task lists, strikethrough, autolinks and footnotes; alerts are a GitHub.com convention and `remark-gfm` does not parse them. The marker survives parsing as ordinary text at the start of the quote, which is what this renderer keys off — so no remark plugin and no new dependency is involved, and the shared `markdown-content.tsx` (and with it the hosted bundle) is untouched. It also means that *without* this renderer a literal `[!NOTE]` is printed to the user.
132
+ - **These are not GFM.** The GFM spec covers tables, task lists, strikethrough, autolinks and footnotes; alerts are a GitHub.com convention and `remark-gfm` does not parse them. The marker survives parsing as ordinary text at the start of the quote, which is what this renderer keys off — so no remark plugin and no new dependency is involved, and the shared `markdown-content.tsx` (and with it the hosted bundle) is untouched. It also means that _without_ this renderer a literal `[!NOTE]` is printed to the user.
130
133
  - **The callout is not `F0Alert`.** That component's `title` and `description` are plain `string`s, so routing a blockquote through it would flatten the body and drop the bold, links, lists and code an author may legitimately put in a markdown block. The callout keeps the real markdown children and borrows f0's semantic colour scale, so it still flips in dark mode.
131
134
 
132
135
  ### Markdown heading levels
@@ -135,17 +138,17 @@ A schema author choosing `#` or `###` inside `markdown.before` / `markdown.after
135
138
 
136
139
  f0's type scale is **not** Tailwind's default — `f0/packages/core/src/tokens/typography.ts` puts `base` at 14px, `lg` at 16px and `2xl` at 22px. So:
137
140
 
138
- | | Source | Renders at |
139
- | --- | --- | --- |
140
- | **The form's own title** (schema `title`) | `F0Heading variant="heading"` | **16px / 600** |
141
- | `#` | f0 `text-2xl font-medium` | **22px / 500** |
142
- | `##` | f0 `text-lg font-medium` | 16px / 500 |
143
- | `###` | f0 `text-base font-semibold` | 14px / 600 |
144
- | `####` | this package's stylesheet | 14px / 600 |
145
- | `#####` | this package's stylesheet | 14px / 500 |
146
- | `######` | this package's stylesheet | 14px / 500, secondary |
147
- | body text | f0 `text-base font-normal` | 14px / 400 |
148
- | `**bold**` | f0 `font-semibold` | 14px / 600 |
141
+ | | Source | Renders at |
142
+ | ----------------------------------------- | ----------------------------- | --------------------- |
143
+ | **The form's own title** (schema `title`) | `F0Heading variant="heading"` | **16px / 600** |
144
+ | `#` | f0 `text-2xl font-medium` | **22px / 500** |
145
+ | `##` | f0 `text-lg font-medium` | 16px / 500 |
146
+ | `###` | f0 `text-base font-semibold` | 14px / 600 |
147
+ | `####` | this package's stylesheet | 14px / 600 |
148
+ | `#####` | this package's stylesheet | 14px / 500 |
149
+ | `######` | this package's stylesheet | 14px / 500, secondary |
150
+ | body text | f0 `text-base font-normal` | 14px / 400 |
151
+ | `**bold**` | f0 `font-semibold` | 14px / 600 |
149
152
 
150
153
  **There is no rule relating these to the form's title.** Read the table before picking a level, because three of the rows collide:
151
154
 
@@ -157,9 +160,9 @@ The compression is f0's, not this package's: between the title (16/600) and body
157
160
 
158
161
  **Which level reads as a section depends on what sits directly below it**, which is the part the table cannot tell you. A `markdown.before` heading is almost always followed by one of two things, and they are not the same weight:
159
162
 
160
- | Directly below | Renders at | So the heading above it |
161
- | --- | --- | --- |
162
- | A plain field's label | 16px / 500, dimmed | `###` (14/600, full strength) reads clearly as a heading — smaller, but bolder and darker |
163
+ | Directly below | Renders at | So the heading above it |
164
+ | ----------------------------------------------------------------- | ------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
165
+ | A plain field's label | 16px / 500, dimmed | `###` (14/600, full strength) reads clearly as a heading — smaller, but bolder and darker |
163
166
  | An object's or array's title (`TitleFieldTemplate` → `F0Heading`) | 16px / 600, full strength | `###` reads as subordinate to the field it introduces; nothing available outranks it, since `##` is 16/500 and `#` would outrank the form itself |
164
167
 
165
168
  So `###` is the right default above an ordinary field and the wrong one above an array — and `##` is not a fix for the second case, because it only matches the title's size while staying a weight lighter. `dev/main.tsx` renders both levels above a field so the difference can be seen rather than reasoned about.
@@ -194,6 +197,16 @@ The toolbar is RJSF's, so it is the schema that decides what a row can do:
194
197
 
195
198
  The Forms SDK's `"ui:widget": "oauth"` field opens the provider in a popup and reacts when the flow finishes; the widget logic ships in `@factorialco/fcode-react-forms`. This theme only contributes the control it draws, as `Theme.oauth.ConnectControl`: an `F0Button` (`default` while idle or waiting, `outline` with a check icon once connected) plus the flow's error message underneath. `FcodeJsonSchemaForm` finds it through `rjsfTheme.oauth`, the same way it finds `rjsfTheme.multistep`.
196
199
 
200
+ ### Pairing tables
201
+
202
+ The Forms SDK's `"ui:field": "pairing"` turns an object whose properties pair Factorial records with another system's (accounts, tax codes, wage types…) into one reviewable table. The rows, their suggestions, the in-use filter and the submitted values are all handled in `@factorialco/fcode-react-forms`. This theme contributes only the drawing, as `Theme.pairing.Table`, which `FcodeJsonSchemaForm` finds through `rjsfTheme.pairing`. The table has:
203
+
204
+ - a header with the counts, an **Accept N suggestions** `F0Button` shown while any suggestion is pending, and the **Needs a choice (N)** filter (an `F0Button`, outlined while off and filled while on);
205
+ - an `F0FormEditableTable` with three columns: the Factorial record, a searchable select of the other system's records (a suggested row shows the suggestion as its value, marked by a blue lightbulb hint carrying the app's reason; clearing it dismisses the suggestion), and a status tag: _Confirmed_, _Suggested_ (the reason as its tooltip), _No longer available_ or _Needs a choice_. An explicit "not mapped" (`""` in the form) is a real option in the select. The record and status columns have fixed widths so the select keeps the rest. Each suggested row also gets an **Accept** action, and a row's validation error marks its select;
206
+ - a footer with an `F0Select` to add rows the in-use list left out, beside the app's in-use note.
207
+
208
+ f0's editable table re-renders every row on each edit. With a few hundred rows listed, an edit takes about a third of a second, so keep the default list short by marking the rows in use.
209
+
197
210
  ### Not yet f0
198
211
 
199
212
  - **`range`** renders as a number input rather than `F0Slider`.