@factorialco/rjsf-f0 2.0.0 → 2.2.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
@@ -59,6 +59,7 @@ The host app must render f0's `F0Provider` above the form and import `@factorial
59
59
  | enum select, multi-select | `F0FormField` `select` |
60
60
  | boolean checkbox, `checkboxes` | `F0Checkbox` |
61
61
  | `radio` | `F0FormField` `cardSelect` (f0 has no radio control) |
62
+ | `file` / `data-url` | f0-styled dropzone + file chips (see below) |
62
63
  | submit, add/move/copy/remove | `F0Button` |
63
64
  | error summary | `F0Alert` |
64
65
  | section title | `F0Heading` |
@@ -68,10 +69,130 @@ Two deliberate consequences of that mapping:
68
69
  - **RJSF keeps ownership of validation.** f0 fields normally validate with zod; here they are told about errors (`error`, `errorMessage`) rather than deriving them, so the schema stays the single source of truth.
69
70
  - **Labels are rendered by the theme, not by f0.** Factorial Code form labels may contain markdown, which f0 takes as a plain string. The theme renders the markdown label itself and hands f0 the plain text so the control keeps an accessible name.
70
71
 
72
+ ### File fields
73
+
74
+ `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.
75
+
76
+ 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.
77
+
78
+ 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.
79
+
80
+ `ui:options`:
81
+
82
+ | Option | Effect |
83
+ | --- | --- |
84
+ | `accept` | Passed to the input verbatim. Also shown as a hint under the dropzone text. |
85
+ | `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. |
86
+
87
+ ### Localising the chrome
88
+
89
+ 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.
90
+
91
+ One prop on the form localises the lot:
92
+
93
+ ```tsx
94
+ <FcodeForm
95
+ translateString={(key, params) => myTable[key] ?? englishStringTranslator(key, params)}
96
+ …
97
+ />
98
+ ```
99
+
100
+ The dropzone's two defaults are keyed on their English text, since RJSF has no enum member for them:
101
+
102
+ - `Drag a file here, or click to choose one`
103
+ - `Drag files here, or click to choose them` (when `multiple`)
104
+
105
+ A form rendered inside a localised product without this prop shows English buttons next to translated field labels. `ui:options.dropzoneText` fixes only the dropzone; the translator fixes everything.
106
+
107
+ ### Markdown alerts
108
+
109
+ `markdownComponents` renders a blockquote opening with a GitHub alert marker as an f0-toned callout:
110
+
111
+ ```markdown
112
+ > [!NOTE]
113
+ > **Nothing is written yet.** You will see a preview first.
114
+ ```
115
+
116
+ | Marker | f0 variant |
117
+ | --- | --- |
118
+ | `[!NOTE]` | `info` |
119
+ | `[!TIP]` | `positive` |
120
+ | `[!IMPORTANT]` | `info` |
121
+ | `[!WARNING]` | `warning` |
122
+ | `[!CAUTION]` | `critical` |
123
+
124
+ Any other blockquote still renders as f0's blockquote, and an unrecognised marker is left as the text it is.
125
+
126
+ Two things worth knowing:
127
+
128
+ - **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.
129
+ - **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.
130
+
131
+ ### Markdown heading levels
132
+
133
+ A schema author choosing `#` or `###` inside `markdown.before` / `markdown.after` (or a result `message`) cannot see what the form's own title renders at. This is that scale, measured, so the choice can be made deliberately.
134
+
135
+ 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:
136
+
137
+ | | Source | Renders at |
138
+ | --- | --- | --- |
139
+ | **The form's own title** (schema `title`) | `F0Heading variant="heading"` | **16px / 600** |
140
+ | `#` | f0 `text-2xl font-medium` | **22px / 500** |
141
+ | `##` | f0 `text-lg font-medium` | 16px / 500 |
142
+ | `###` | f0 `text-base font-semibold` | 14px / 600 |
143
+ | `####` | this package's stylesheet | 14px / 600 |
144
+ | `#####` | this package's stylesheet | 14px / 500 |
145
+ | `######` | this package's stylesheet | 14px / 500, secondary |
146
+ | body text | f0 `text-base font-normal` | 14px / 400 |
147
+ | `**bold**` | f0 `font-semibold` | 14px / 600 |
148
+
149
+ **There is no rule relating these to the form's title.** Read the table before picking a level, because three of the rows collide:
150
+
151
+ - **`#` outranks the form's title.** 22px against the title's 16px, so a heading inside the form is larger than the form it sits in. Avoid `#` in a form.
152
+ - **`###` is identical to `**bold**`** — both 14px/600. A `###` section heading is indistinguishable from a bold sentence. `####` lands on the same values, so it is indistinguishable from both.
153
+ - **`##` matches the title's size** at one weight step lighter, which reads as a peer of the title rather than a section under it.
154
+
155
+ The compression is f0's, not this package's: between the title (16/600) and body text (14/400) the scale has two slots, and markdown has six levels — so any mapping has to collapse levels rather than preserve them.
156
+
157
+ **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:
158
+
159
+ | Directly below | Renders at | So the heading above it |
160
+ | --- | --- | --- |
161
+ | A plain field's label | 16px / 500, dimmed | `###` (14/600, full strength) reads clearly as a heading — smaller, but bolder and darker |
162
+ | 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 |
163
+
164
+ 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.
165
+
166
+ A heading above an **object or array** is usually the wrong shape rather than the wrong level. Those fields already render their own title at 16/600, so a markdown heading above one is a second title for the same thing — which is what makes it read badly no matter which level it uses. Two ways out, both better than picking a different `#`:
167
+
168
+ ```markdown
169
+ ---
170
+ ```
171
+
172
+ A rule opens the group without competing for the title: it renders as a 1px hairline with 12px of clearance, and the field's own title becomes the section heading. Use this when the point of the heading was to separate the group from what came before it.
173
+
174
+ Or drop the markdown block and let the title carry the section on its own. Use this when the heading and the title were saying the same thing.
175
+
176
+ A heading earns its place when it opens a group of **several** fields, each with its own label — there it names something no single field's title can.
177
+
178
+ ### Arrays of scalars
179
+
180
+ A list of plain values — addresses, tags, ids — renders as one row per item: the control, then the item toolbar, then the array's add button.
181
+
182
+ Rows carry **no label of their own**. RJSF titles each one after the array plus its position (`Emails-1`, `Emails-2`) and marks every non-null item required, which on an optional list of two addresses produced a repeated heading and two asterisks. The array's own title already names the group, and the control keeps its accessible name through f0's `hideLabel`. Rows holding an object or a nested array are unaffected: those are blocks of several fields, and their labels are what separate one from the next.
183
+
184
+ The toolbar is RJSF's, so it is the schema that decides what a row can do:
185
+
186
+ ```json
187
+ { "ui:options": { "orderable": false } }
188
+ ```
189
+
190
+ `orderable` (default `true`) draws move up/down — turn it off when order carries no meaning, which is most scalar lists. `copyable` defaults to `false` already, `removable` and `addable` to `true`.
191
+
71
192
  ### Not yet f0
72
193
 
73
- - **File fields** keep a native `<input type="file">` (rendered by the theme's `BaseInputTemplate`, since core's `FileWidget` delegates its input to it). The SDK exchanges uploads as `data:` URLs, while f0's file field is built around an upload hook — bridging the two is not done yet.
74
194
  - **`range`** renders as a number input rather than `F0Slider`.
195
+ - **Headings** `h1`–`h3` come from f0's own renderers; `h4`–`h6` are styled by this package's stylesheet instead, since a renderer here would have to carry Tailwind utility classes that the host's Tailwind build never generates (its `content` globs do not include this package).
75
196
  - The Forms SDK's `sourceCode` field keeps its Monaco editor, which is not f0-styled.
76
197
 
77
198
  ## Development