@usefillo/dom 0.30.3 → 1.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 +3 -28
- package/dist/index.d.ts +8 -2
- package/dist/index.js +47 -8
- package/dist/standalone.global.js +1 -1
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -32,43 +32,18 @@ renderForm("#fillo-form", {
|
|
|
32
32
|
});
|
|
33
33
|
```
|
|
34
34
|
|
|
35
|
-
|
|
35
|
+
Get the actual ID from Share on a published form. Mount the renderer after the element exists and call the returned instance’s `destroy()` method on unmount. Set `context` to attach scalar app values to a submission, or `initialData` to prefill a declared answer. Native placements load the published Fillo definition.
|
|
36
36
|
|
|
37
|
-
|
|
38
|
-
import { createClient, defineForm, renderForm } from "@usefillo/dom";
|
|
39
|
-
|
|
40
|
-
const client = createClient({ key: "pk_…" }); // Settings → Code-defined forms
|
|
41
|
-
const form = defineForm({
|
|
42
|
-
id: "cust-feedback",
|
|
43
|
-
pages: [{ id: "p1", blocks: [
|
|
44
|
-
{ id: "email", kind: "email", label: "Work email", required: true },
|
|
45
|
-
{ id: "msg", kind: "long_text", label: "What should we know?" },
|
|
46
|
-
] }],
|
|
47
|
-
});
|
|
48
|
-
|
|
49
|
-
renderForm("#fillo-form", {
|
|
50
|
-
form,
|
|
51
|
-
client,
|
|
52
|
-
onSubmitted: (id) => console.log("response", id),
|
|
53
|
-
});
|
|
54
|
-
```
|
|
55
|
-
|
|
56
|
-
Or drop it in with a single script tag — the bundle exposes a global `Fillo`:
|
|
37
|
+
For a page without a build step:
|
|
57
38
|
|
|
58
39
|
```html
|
|
59
40
|
<div id="fillo-form"></div>
|
|
60
41
|
<script src="https://unpkg.com/@usefillo/dom/dist/standalone.global.js"></script>
|
|
61
42
|
<script>
|
|
62
|
-
|
|
63
|
-
const form = Fillo.defineForm({ id: "cust-feedback", pages: [/* … */] });
|
|
64
|
-
Fillo.renderForm("#fillo-form", { form, client });
|
|
43
|
+
Fillo.renderForm("#fillo-form", { formId: "your-published-form-id" });
|
|
65
44
|
</script>
|
|
66
45
|
```
|
|
67
46
|
|
|
68
|
-
The default stylesheet inherits the host page's CSS `color-scheme` and font. If your theme switch only toggles a class or data attribute, pass its resolved mode as `theme: { colorScheme: "light" | "dark" }`. Use `"auto"` only for a deliberately system-driven page. A fixed hex `background` automatically selects a readable palette unless you explicitly choose one.
|
|
69
|
-
|
|
70
|
-
Every rendered part carries `data-*` state attributes (`data-selected`, `data-invalid`, …) for utility CSS, and the default stylesheet is cascade-layered so your own styles win. On Tailwind v3 or reset-heavy sites import `@usefillo/dom/styles.unlayered.css` instead. Styling contract: [fillo.so/docs/styling](https://fillo.so/docs/styling).
|
|
71
|
-
|
|
72
47
|
## Links
|
|
73
48
|
|
|
74
49
|
- **Docs:** [fillo.so/docs](https://fillo.so/docs)
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Field, FieldValue, FormSchema, FilloClient, ResponseData, FormStatus as FormStatus$1, FormPage, Block, FilloRespondent, CodeForm, FormTheme, ChallengeConfig, ChallengeTheme, FieldKind, FilloError, FormControllerOptions, FormController } from '@usefillo/core';
|
|
2
|
-
export { CodeForm, Field, FieldKind, FieldValue, FileValue, FilloClient, FilloClientOptions, FilloError, FormController, FormControllerOptions, FormControllerState, FormSchema, FormTheme, ProvisionWorkspaceResult, ResponseData, createClient, defineForm, provisionWorkspace } from '@usefillo/core';
|
|
1
|
+
import { Field, FieldValue, FormSchema, FilloClient, ResponseData, FormStatus as FormStatus$1, FormPage, Block, FilloRespondent, SubmissionContext, CodeForm, FormTheme, ChallengeConfig, ChallengeTheme, FieldKind, FilloError, FormControllerOptions, FormController } from '@usefillo/core';
|
|
2
|
+
export { CodeForm, Field, FieldKind, FieldValue, FileValue, FilloClient, FilloClientOptions, FilloError, FormController, FormControllerOptions, FormControllerState, FormSchema, FormTheme, ProvisionWorkspaceResult, ResponseData, SubmissionContext, createClient, defineForm, provisionWorkspace } from '@usefillo/core';
|
|
3
3
|
|
|
4
4
|
type FormStatus = FormStatus$1 | "loading" | "closed";
|
|
5
5
|
interface FilloDomApi {
|
|
@@ -44,6 +44,8 @@ interface FilloDomFieldIds {
|
|
|
44
44
|
}
|
|
45
45
|
type FieldRenderer = (context: FieldRenderContext) => HTMLElement | null;
|
|
46
46
|
interface RenderFormBaseOptions {
|
|
47
|
+
context?: SubmissionContext;
|
|
48
|
+
definitionRevision?: string;
|
|
47
49
|
theme?: FormTheme;
|
|
48
50
|
initialData?: ResponseData;
|
|
49
51
|
/**
|
|
@@ -132,6 +134,7 @@ interface FilloDomForm {
|
|
|
132
134
|
submit(): Promise<void>;
|
|
133
135
|
/** Late-bind identify() context once the host session loads. */
|
|
134
136
|
setRespondent(respondent: FilloRespondent | undefined): void;
|
|
137
|
+
setContext(context: SubmissionContext | undefined): void;
|
|
135
138
|
/** Persist unsaved saved-progress answers now (settings.saveProgress forms).
|
|
136
139
|
* The renderer already flushes on pagehide/visibility-hidden. */
|
|
137
140
|
flushDraft(): void;
|
|
@@ -147,6 +150,7 @@ declare const HTMLElementBase: {
|
|
|
147
150
|
};
|
|
148
151
|
declare class FilloFormElement extends HTMLElementBase {
|
|
149
152
|
private instance;
|
|
153
|
+
private assignedContext;
|
|
150
154
|
private assignedForm;
|
|
151
155
|
private assignedClient;
|
|
152
156
|
private assignedTheme;
|
|
@@ -161,6 +165,8 @@ declare class FilloFormElement extends HTMLElementBase {
|
|
|
161
165
|
get form(): FormSchema | CodeForm | undefined;
|
|
162
166
|
set client(value: FilloClient | undefined);
|
|
163
167
|
set theme(value: FormTheme | undefined);
|
|
168
|
+
set context(value: SubmissionContext | undefined);
|
|
169
|
+
get context(): SubmissionContext | undefined;
|
|
164
170
|
set initialData(value: ResponseData | undefined);
|
|
165
171
|
private scheduleMount;
|
|
166
172
|
/** data-preview is on when present UNLESS its value says off ("false"/"0"):
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
reachablePageSequence,
|
|
38
38
|
REQUIRED_FIELD_MESSAGE,
|
|
39
39
|
requiredFieldMessage,
|
|
40
|
+
requiredCustomRendererError,
|
|
40
41
|
resolveThemeDom,
|
|
41
42
|
shouldAutoSubmit,
|
|
42
43
|
syncCodeForm,
|
|
@@ -1963,6 +1964,7 @@ var DomFormController = class {
|
|
|
1963
1964
|
submit: () => this.submit()
|
|
1964
1965
|
};
|
|
1965
1966
|
}
|
|
1967
|
+
resolvesCanonical = false;
|
|
1966
1968
|
resolveFormIdFn;
|
|
1967
1969
|
/** The server refuses submissions right now — render a not-open state backed
|
|
1968
1970
|
* by the real form in display-only mode ("notOpen" for a draft /
|
|
@@ -2117,15 +2119,17 @@ var DomFormController = class {
|
|
|
2117
2119
|
this.syncFormUrl = result.manageUrl;
|
|
2118
2120
|
this.uploadsAvailable = result.uploadsAvailable;
|
|
2119
2121
|
this.uploadFileSizeLimitMb = result.uploadFileSizeLimitMb;
|
|
2120
|
-
this.challenge = this.options.challenge ?? result.challenge;
|
|
2122
|
+
this.challenge = result.canonical ? result.challenge : this.options.challenge ?? result.challenge;
|
|
2121
2123
|
if (result.branding) {
|
|
2122
2124
|
this.fetchedPoweredBy = result.branding.poweredBy;
|
|
2123
2125
|
this.fetchedBrandLabel = result.branding.label;
|
|
2124
2126
|
this.fetchedBrandHref = result.branding.href;
|
|
2125
2127
|
}
|
|
2126
|
-
|
|
2128
|
+
this.resolvesCanonical = result.canonical === true;
|
|
2129
|
+
this.options.definitionRevision = result.definitionRevision;
|
|
2130
|
+
if (development && result.resolvedSchema && !result.canonical) {
|
|
2127
2131
|
this.formId = result.formId;
|
|
2128
|
-
this.engine?.setContext({ formId: result.formId });
|
|
2132
|
+
this.engine?.setContext({ formId: result.formId, definitionRevision: result.definitionRevision });
|
|
2129
2133
|
this.render();
|
|
2130
2134
|
} else {
|
|
2131
2135
|
const safeSchema = result.resolvedSchema ?? codeForm.schema;
|
|
@@ -2232,6 +2236,11 @@ var DomFormController = class {
|
|
|
2232
2236
|
this.render();
|
|
2233
2237
|
const published = await client.getForm(formId);
|
|
2234
2238
|
if (this.destroyed) return;
|
|
2239
|
+
this.options.definitionRevision = published.definitionRevision;
|
|
2240
|
+
const origin = client.baseUrl || globalThis.location?.origin;
|
|
2241
|
+
if (this.devChrome() && published.uploadsAvailable === false && origin) {
|
|
2242
|
+
this.syncWarningUrl = `${origin}/forms/${encodeURIComponent(published.id)}/settings#file-storage`;
|
|
2243
|
+
}
|
|
2235
2244
|
if (published.accepting === false) {
|
|
2236
2245
|
this.notOpenVariant = overlayVariant(published.acceptingReason);
|
|
2237
2246
|
} else {
|
|
@@ -2242,7 +2251,9 @@ var DomFormController = class {
|
|
|
2242
2251
|
this.fetchedPoweredBy = published.branding?.poweredBy ?? null;
|
|
2243
2252
|
this.fetchedBrandLabel = published.branding?.label;
|
|
2244
2253
|
this.fetchedBrandHref = published.branding?.href;
|
|
2245
|
-
|
|
2254
|
+
const challenge = published.definitionRevision ? published.challenge : this.options.challenge ?? published.challenge;
|
|
2255
|
+
if (this.challenge?.siteKey !== challenge?.siteKey) this.teardownTurnstileWidget();
|
|
2256
|
+
this.challenge = challenge;
|
|
2246
2257
|
if (published.accepting === false && this.options.renderError) {
|
|
2247
2258
|
const message = this.notOpenVariant === "closed" ? "This form is no longer accepting responses." : "This form isn't accepting responses yet.";
|
|
2248
2259
|
this.fatalError = new FilloError(message, 403, void 0, published.acceptingReason);
|
|
@@ -2250,12 +2261,19 @@ var DomFormController = class {
|
|
|
2250
2261
|
this.render(this.fatalError);
|
|
2251
2262
|
return;
|
|
2252
2263
|
}
|
|
2253
|
-
this.
|
|
2264
|
+
this.applyCanonicalSchema(
|
|
2254
2265
|
published.schema,
|
|
2255
2266
|
this.options.theme ?? published.theme ?? void 0,
|
|
2256
2267
|
published.id
|
|
2257
2268
|
);
|
|
2258
2269
|
}
|
|
2270
|
+
canRenderSchema(schema) {
|
|
2271
|
+
const error = requiredCustomRendererError(schema, this.options.customComponents, this.options.components?.custom);
|
|
2272
|
+
if (!error) return true;
|
|
2273
|
+
this.genericUnavailable = !this.devChrome() && !this.options.renderOnly;
|
|
2274
|
+
this.handleError(error);
|
|
2275
|
+
return false;
|
|
2276
|
+
}
|
|
2259
2277
|
/** Bind the resolved schema, create the engine, and render. */
|
|
2260
2278
|
setSchema(schema, theme, formId) {
|
|
2261
2279
|
if (this.destroyed) return;
|
|
@@ -2269,6 +2287,7 @@ var DomFormController = class {
|
|
|
2269
2287
|
);
|
|
2270
2288
|
}
|
|
2271
2289
|
const normalizedSchema = normalized.schema;
|
|
2290
|
+
if (!this.canRenderSchema(normalizedSchema)) return;
|
|
2272
2291
|
this.schema = normalizedSchema;
|
|
2273
2292
|
this.theme = theme;
|
|
2274
2293
|
const renderOnly = this.options.renderOnly === true;
|
|
@@ -2281,6 +2300,12 @@ var DomFormController = class {
|
|
|
2281
2300
|
formId: transportDisabled ? void 0 : formId,
|
|
2282
2301
|
client: transportDisabled ? void 0 : this.options.client,
|
|
2283
2302
|
initialData: this.options.initialData,
|
|
2303
|
+
context: this.options.context,
|
|
2304
|
+
definitionRevision: this.options.definitionRevision,
|
|
2305
|
+
get onDefinitionChanged() {
|
|
2306
|
+
const target = renderer.formId;
|
|
2307
|
+
return target && (renderer.resolvesCanonical || renderer.options.formId) ? () => renderer.loadPublished(target) : void 0;
|
|
2308
|
+
},
|
|
2284
2309
|
onChange: displayOnly ? void 0 : this.options.onChange,
|
|
2285
2310
|
onSubmitted: transportDisabled ? void 0 : this.options.onSubmitted,
|
|
2286
2311
|
getHoneypot: () => this.element.querySelector('input[name="fillo_hp_field"]')?.value ?? this.hpValue,
|
|
@@ -2341,10 +2366,11 @@ var DomFormController = class {
|
|
|
2341
2366
|
);
|
|
2342
2367
|
}
|
|
2343
2368
|
const normalizedSchema = normalized.schema;
|
|
2369
|
+
if (!this.canRenderSchema(normalizedSchema)) return;
|
|
2344
2370
|
this.schema = normalizedSchema;
|
|
2345
2371
|
this.theme = theme;
|
|
2346
2372
|
this.formId = formId;
|
|
2347
|
-
this.engine.setContext({ form: normalizedSchema, formId });
|
|
2373
|
+
this.engine.setContext({ form: normalizedSchema, formId, definitionRevision: this.options.definitionRevision });
|
|
2348
2374
|
if (this.notOpenVariant === null) this.configureDraftFlush(normalizedSchema);
|
|
2349
2375
|
this.phase = this.closed ? "closed" : "ready";
|
|
2350
2376
|
this.render();
|
|
@@ -2437,6 +2463,10 @@ var DomFormController = class {
|
|
|
2437
2463
|
this.options.respondent = respondent;
|
|
2438
2464
|
this.engine?.setContext({ respondent });
|
|
2439
2465
|
}
|
|
2466
|
+
setContext(context) {
|
|
2467
|
+
this.options.context = context;
|
|
2468
|
+
this.engine?.setContext({ context });
|
|
2469
|
+
}
|
|
2440
2470
|
/** This field's active (non-failed) in-flight count — room math and the
|
|
2441
2471
|
* setUploading(field, …) flip both key off it. A failed row holds no slot
|
|
2442
2472
|
* (it must not strand the field at permanently-full). */
|
|
@@ -3335,7 +3365,7 @@ var DomFormController = class {
|
|
|
3335
3365
|
content.appendChild(alert);
|
|
3336
3366
|
}
|
|
3337
3367
|
const autoSubmit = api.form.settings.submitMode === "auto";
|
|
3338
|
-
const showPrimaryButton = !autoSubmit || !api.isLastPage || needsExplicitSubmit(visibleFields(api.form, api.data)) || // A challenge needs an explicit Submit even on an otherwise button-less
|
|
3368
|
+
const showPrimaryButton = this.engine?.getState().definitionReviewRequired || !autoSubmit || !api.isLastPage || needsExplicitSubmit(visibleFields(api.form, api.data)) || // A challenge needs an explicit Submit even on an otherwise button-less
|
|
3339
3369
|
// auto-submit form — you can't one-tap past a human check.
|
|
3340
3370
|
showChallenge;
|
|
3341
3371
|
const showFooter = showPrimaryButton || api.pageCount > 1 && !api.isFirstPage;
|
|
@@ -3407,7 +3437,7 @@ var DomFormController = class {
|
|
|
3407
3437
|
isLastPage: api.isLastPage,
|
|
3408
3438
|
uploading: this.engine?.getState().uploading === true
|
|
3409
3439
|
};
|
|
3410
|
-
if (shouldAutoSubmit(block, value, autoCtx)) void this.submit();
|
|
3440
|
+
if (!this.engine?.getState().definitionReviewRequired && shouldAutoSubmit(block, value, autoCtx)) void this.submit();
|
|
3411
3441
|
};
|
|
3412
3442
|
const context = {
|
|
3413
3443
|
field: block,
|
|
@@ -3598,6 +3628,7 @@ var HTMLElementBase = typeof HTMLElement !== "undefined" ? HTMLElement : class {
|
|
|
3598
3628
|
};
|
|
3599
3629
|
var FilloFormElement = class extends HTMLElementBase {
|
|
3600
3630
|
instance = null;
|
|
3631
|
+
assignedContext;
|
|
3601
3632
|
assignedForm;
|
|
3602
3633
|
assignedClient;
|
|
3603
3634
|
assignedTheme;
|
|
@@ -3640,6 +3671,13 @@ var FilloFormElement = class extends HTMLElementBase {
|
|
|
3640
3671
|
this.assignedTheme = value;
|
|
3641
3672
|
if (this.mounted && this.instance instanceof DomFormController) this.instance.setTheme(value);
|
|
3642
3673
|
}
|
|
3674
|
+
set context(value) {
|
|
3675
|
+
this.assignedContext = value;
|
|
3676
|
+
this.instance?.setContext(value);
|
|
3677
|
+
}
|
|
3678
|
+
get context() {
|
|
3679
|
+
return this.assignedContext;
|
|
3680
|
+
}
|
|
3643
3681
|
set initialData(value) {
|
|
3644
3682
|
this.assignedInitialData = value;
|
|
3645
3683
|
if (this.mounted) this.scheduleMount();
|
|
@@ -3677,6 +3715,7 @@ var FilloFormElement = class extends HTMLElementBase {
|
|
|
3677
3715
|
client,
|
|
3678
3716
|
formId,
|
|
3679
3717
|
theme: this.assignedTheme,
|
|
3718
|
+
context: this.assignedContext,
|
|
3680
3719
|
initialData: this.assignedInitialData,
|
|
3681
3720
|
// Same cosmetic-only contract as renderForm's `preview` option: forces
|
|
3682
3721
|
// the dev chrome + a visible Preview badge on off-localhost surfaces,
|