vanjs-jsf 0.6.0 → 0.6.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.
- package/README.md +1 -0
- package/dist/VanJsfField.d.ts +2 -2
- package/dist/VanJsfField.js +2 -2
- package/dist/VanJsfField.js.map +1 -1
- package/dist/VanJsfForm.d.ts +4 -4
- package/dist/VanJsfForm.js +12 -7
- package/dist/VanJsfForm.js.map +1 -1
- package/dist/index.d.ts +6 -6
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.js.map +1 -1
- package/dist/util.d.ts +1 -1
- package/dist/util.js.map +1 -1
- package/dist/widgets/array.d.ts +1 -1
- package/dist/widgets/array.js +2 -2
- package/dist/widgets/array.js.map +1 -1
- package/dist/widgets/basic.d.ts +1 -1
- package/dist/widgets/basic.js +3 -3
- package/dist/widgets/basic.js.map +1 -1
- package/dist/widgets/choice.d.ts +1 -1
- package/dist/widgets/choice.js +2 -2
- package/dist/widgets/choice.js.map +1 -1
- package/dist/widgets/code.d.ts +1 -1
- package/dist/widgets/code.js.map +1 -1
- package/dist/widgets/date.d.ts +1 -1
- package/dist/widgets/date.js +3 -3
- package/dist/widgets/date.js.map +1 -1
- package/dist/widgets/file.d.ts +1 -1
- package/dist/widgets/file.js +1 -1
- package/dist/widgets/file.js.map +1 -1
- package/dist/widgets/index.d.ts +1 -1
- package/dist/widgets/index.js +7 -7
- package/dist/widgets/index.js.map +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -435,6 +435,7 @@ npm run dev # Start Vite dev server (port 3030)
|
|
|
435
435
|
npm run build # Compile lib/ → dist/ (tsc, ESM + .d.ts) + copy CSS
|
|
436
436
|
npm run lint # Run ESLint
|
|
437
437
|
npm test # Run the tests (vitest + happy-dom)
|
|
438
|
+
npm run test:pack # Pack and import the package with plain Node ESM
|
|
438
439
|
npm run lint:fix # Run ESLint with auto-fix
|
|
439
440
|
```
|
|
440
441
|
|
package/dist/VanJsfField.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { JsfField, Widget } from "./types";
|
|
2
|
-
import { JsfTheme, JsfTexts } from "./theme";
|
|
1
|
+
import type { JsfField, Widget } from "./types.js";
|
|
2
|
+
import { JsfTheme, JsfTexts } from "./theme.js";
|
|
3
3
|
/** What a field needs from the form that owns it. */
|
|
4
4
|
export interface FieldHost {
|
|
5
5
|
theme: JsfTheme;
|
package/dist/VanJsfField.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
|
-
import { resolve } from "./theme";
|
|
3
|
-
import { compact } from "./util";
|
|
2
|
+
import { resolve } from "./theme.js";
|
|
3
|
+
import { compact } from "./util.js";
|
|
4
4
|
const { div, label, p, span } = van.tags;
|
|
5
5
|
/** Container types that never hold a value of their own. */
|
|
6
6
|
const NON_ARRAY_TYPES = new Set(["file", "code", "group-array"]);
|
package/dist/VanJsfField.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VanJsfField.js","sourceRoot":"","sources":["../lib/VanJsfField.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAsB,OAAO,EAAE,MAAM,SAAS,CAAC;AACtD,OAAO,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAEjC,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAiBzC,4DAA4D;AAC5D,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC,CAAC,MAAM,EAAE,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;AAEjE,MAAM,OAAO,WAAW;IACb,GAAG,CAAW;IACd,IAAI,CAAW;IACf,EAAE,CAAS;IACX,OAAO,CAAC;IACjB,oFAAoF;IAC3E,KAAK,GAAG,GAAG,CAAC,KAAK,CAAC,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CAAC,CAAC;aACpG,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,YAAY,GAAG,GAAG,KAAK,QAAQ,CAAC;QACtC,OAAO,GAAG,CACR,OAAO,CAAC;YACN,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW;YACxB,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACtF,CAAC,EACF,MAAM;YACJ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACxB,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,EAChC,UAAU,IAAI,CAAC,IAAI,4BAA4B,GAAG,kCAAkC,CAAC,CAC1F,CAAC;IACJ,CAAC;CACF","sourcesContent":["import van from \"vanjs-core\";\nimport type { JsfField, Widget, WidgetContext } from \"./types\";\nimport { JsfTheme, JsfTexts, resolve } from \"./theme\";\nimport { compact } from \"./util\";\n\nconst { div, label, p, span } = van.tags;\n\n/** What a field needs from the form that owns it. */\nexport interface FieldHost {\n theme: JsfTheme;\n texts: JsfTexts;\n idPrefix: string;\n layoutClass(field: VanJsfField): string;\n widget(key: string): Widget | undefined;\n getValue(path: readonly string[]): unknown;\n setValue(field: VanJsfField, value: unknown): void;\n setMeta(field: VanJsfField, key: string, value: unknown): void;\n buildFields(defs: JsfField[], parentPath: string[]): VanJsfField[];\n /** Re-applies validation to every field without changing values. */\n refresh(): void;\n}\n\n/** Container types that never hold a value of their own. */\nconst NON_ARRAY_TYPES = new Set([\"file\", \"code\", \"group-array\"]);\n\nexport class VanJsfField {\n readonly def: JsfField;\n readonly path: string[];\n readonly id: string;\n readonly visible;\n /** Message on screen: the validation or widget error, once touched or submitted. */\n readonly error = van.state(\"\");\n /** Fieldset sub-fields. */\n children: VanJsfField[] = [];\n /** group-array: sub-fields of each item, rebuilt whenever items are added or removed. */\n items: VanJsfField[][] = [];\n touched = false;\n validationError = \"\";\n widgetError = \"\";\n private readonly host: FieldHost;\n\n constructor(def: JsfField, path: string[], host: FieldHost) {\n this.def = def;\n this.path = path;\n this.host = host;\n this.id = `${host.idPrefix}-${path.join(\"-\")}`;\n this.visible = van.state(def.isVisible ?? true);\n }\n\n get name(): string {\n return this.def.name;\n }\n\n get inputType(): string {\n return this.def.inputType;\n }\n\n /** Key used to pick the widget: `x-jsf-presentation.widget`, else derived from the field. */\n get widgetKey(): string {\n const d = this.def;\n if (typeof d.widget === \"string\") return d.widget;\n if (d.inputType === \"group-array\") return \"group-array\";\n // json-schema-form reports arrays as a \"select\"; with options that is a multi-select,\n // without them a repeatable list of scalars.\n if (d.jsonType === \"array\" && !NON_ARRAY_TYPES.has(d.inputType)) {\n return d.options?.length ? \"multiselect\" : \"array\";\n }\n return d.inputType;\n }\n\n /** This field and every field below it, in document order. */\n *walk(): Generator<VanJsfField> {\n yield this;\n for (const c of this.children) yield* c.walk();\n for (const item of this.items) for (const f of item) yield* f.walk();\n }\n\n showError(showAll: boolean): void {\n const msg = this.validationError || this.widgetError;\n this.error.val = this.touched || showAll ? msg : \"\";\n }\n\n attrs(): Record<string, unknown> {\n const d = this.def;\n return compact({\n id: this.id,\n name: this.path.join(\".\"),\n placeholder: d.placeholder,\n readOnly: d.readOnly || undefined,\n disabled: d.disabled || undefined,\n autocomplete: d.autocomplete,\n \"aria-required\": d.required ? \"true\" : undefined,\n \"aria-describedby\": [d.description ? `${this.id}-description` : \"\", `${this.id}-error`]\n .filter(Boolean).join(\" \"),\n \"aria-invalid\": () => (this.error.val ? \"true\" : \"false\"),\n });\n }\n\n private requiredMark(): HTMLElement | null {\n return this.def.required ? span({ class: this.host.theme.requiredIndicator || \"\" }, \" *\") : null;\n }\n\n private context(): WidgetContext {\n const { host, def } = this;\n const theme = host.theme;\n return {\n field: def,\n name: this.name,\n path: this.path,\n id: this.id,\n theme,\n texts: host.texts,\n getValue: () => host.getValue(this.path),\n setValue: (value) => {\n this.touched = true;\n host.setValue(this, value);\n },\n setMeta: (key, value) => host.setMeta(this, key, value),\n setWidgetError: (message) => {\n if (message === this.widgetError) return;\n this.widgetError = message;\n if (message) this.touched = true;\n host.refresh();\n },\n error: this.error,\n visible: this.visible,\n attrs: () => this.attrs(),\n label: () => label(\n { for: this.id, id: `${this.id}-label`, class: resolve(def.titleClass, theme.label) },\n def.label ?? \"\",\n this.requiredMark(),\n ),\n description: () => def.description\n ? div({ id: `${this.id}-description`, class: resolve(def.descriptionClass, theme.description) }, def.description)\n : null,\n errorMessage: () => p(\n { id: `${this.id}-error`, class: resolve(def.errorClass, theme.error), \"aria-live\": \"polite\" },\n () => this.error.val,\n ),\n renderChildren: () => this.children.map((c) => c.render()),\n renderItems: () => {\n const value = host.getValue(this.path);\n const count = Array.isArray(value) ? value.length : 0;\n const templates = () => (typeof def.fields === \"function\" ? def.fields() : def.fields ?? []);\n this.items = Array.from({ length: count }, (_, i) =>\n host.buildFields(templates(), [...this.path, String(i)]));\n host.refresh();\n return this.items.map((fields) => fields.map((f) => f.render()));\n },\n };\n }\n\n render(): Element {\n const key = this.widgetKey;\n const widget = this.host.widget(key);\n const base = [resolve(this.def.containerClass, this.host.theme.container), this.host.layoutClass(this)]\n .filter(Boolean).join(\" \");\n const alwaysHidden = key === \"hidden\";\n return div(\n compact({\n id: this.def.containerId,\n class: () => (alwaysHidden || !this.visible.val ? `${base} jsf-hidden`.trim() : base),\n }),\n widget\n ? widget(this.context())\n : div({ class: \"jsf-unsupported\" },\n `Field \"${this.name}\" unsupported: the type \"${key}\" has no UI component built yet.`),\n );\n }\n}\n"]}
|
|
1
|
+
{"version":3,"file":"VanJsfField.js","sourceRoot":"","sources":["../lib/VanJsfField.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAs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AAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;YACnE,CAAC;SACF,CAAC;IACJ,CAAC;IAED,MAAM;QACJ,MAAM,GAAG,GAAG,IAAI,CAAC,SAAS,CAAC;QAC3B,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QACrC,MAAM,IAAI,GAAG,CAAC,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,cAAc,EAAE,IAAI,CAAC,IAAI,CAAC,KAAK,CAAC,SAAS,CAAC,EAAE,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;aACpG,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QAC7B,MAAM,YAAY,GAAG,GAAG,KAAK,QAAQ,CAAC;QACtC,OAAO,GAAG,CACR,OAAO,CAAC;YACN,EAAE,EAAE,IAAI,CAAC,GAAG,CAAC,WAAW;YACxB,KAAK,EAAE,GAAG,EAAE,CAAC,CAAC,YAAY,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,aAAa,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,IAAI,CAAC;SACtF,CAAC,EACF,MAAM;YACJ,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,EAAE,CAAC;YACxB,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,iBAAiB,EAAE,EAChC,UAAU,IAAI,CAAC,IAAI,4BAA4B,GAAG,kCAAkC,CAAC,CAC1F,CAAC;IACJ,CAAC;CACF","sourcesContent":["import van from \"vanjs-core\";\nimport type { JsfField, Widget, WidgetContext } from \"./types.js\";\nimport { JsfTheme, JsfTexts, resolve } from \"./theme.js\";\nimport { compact } from \"./util.js\";\n\nconst { div, label, p, span } = van.tags;\n\n/** What a field needs from the form that owns it. */\nexport interface FieldHost {\n theme: JsfTheme;\n texts: JsfTexts;\n idPrefix: string;\n layoutClass(field: VanJsfField): string;\n widget(key: string): Widget | undefined;\n getValue(path: readonly string[]): unknown;\n setValue(field: VanJsfField, value: unknown): void;\n setMeta(field: VanJsfField, key: string, value: unknown): void;\n buildFields(defs: JsfField[], parentPath: string[]): VanJsfField[];\n /** Re-applies validation to every field without changing values. */\n refresh(): void;\n}\n\n/** Container types that never hold a value of their own. */\nconst NON_ARRAY_TYPES = new Set([\"file\", \"code\", \"group-array\"]);\n\nexport class VanJsfField {\n readonly def: JsfField;\n readonly path: string[];\n readonly id: string;\n readonly visible;\n /** Message on screen: the validation or widget error, once touched or submitted. */\n readonly error = van.state(\"\");\n /** Fieldset sub-fields. */\n children: VanJsfField[] = [];\n /** group-array: sub-fields of each item, rebuilt whenever items are added or removed. */\n items: VanJsfField[][] = [];\n touched = false;\n validationError = \"\";\n widgetError = \"\";\n private readonly host: FieldHost;\n\n constructor(def: JsfField, path: string[], host: FieldHost) {\n this.def = def;\n this.path = path;\n this.host = host;\n this.id = `${host.idPrefix}-${path.join(\"-\")}`;\n this.visible = van.state(def.isVisible ?? true);\n }\n\n get name(): string {\n return this.def.name;\n }\n\n get inputType(): string {\n return this.def.inputType;\n }\n\n /** Key used to pick the widget: `x-jsf-presentation.widget`, else derived from the field. */\n get widgetKey(): string {\n const d = this.def;\n if (typeof d.widget === \"string\") return d.widget;\n if (d.inputType === \"group-array\") return \"group-array\";\n // json-schema-form reports arrays as a \"select\"; with options that is a multi-select,\n // without them a repeatable list of scalars.\n if (d.jsonType === \"array\" && !NON_ARRAY_TYPES.has(d.inputType)) {\n return d.options?.length ? \"multiselect\" : \"array\";\n }\n return d.inputType;\n }\n\n /** This field and every field below it, in document order. */\n *walk(): Generator<VanJsfField> {\n yield this;\n for (const c of this.children) yield* c.walk();\n for (const item of this.items) for (const f of item) yield* f.walk();\n }\n\n showError(showAll: boolean): void {\n const msg = this.validationError || this.widgetError;\n this.error.val = this.touched || showAll ? msg : \"\";\n }\n\n attrs(): Record<string, unknown> {\n const d = this.def;\n return compact({\n id: this.id,\n name: this.path.join(\".\"),\n placeholder: d.placeholder,\n readOnly: d.readOnly || undefined,\n disabled: d.disabled || undefined,\n autocomplete: d.autocomplete,\n \"aria-required\": d.required ? \"true\" : undefined,\n \"aria-describedby\": [d.description ? `${this.id}-description` : \"\", `${this.id}-error`]\n .filter(Boolean).join(\" \"),\n \"aria-invalid\": () => (this.error.val ? \"true\" : \"false\"),\n });\n }\n\n private requiredMark(): HTMLElement | null {\n return this.def.required ? span({ class: this.host.theme.requiredIndicator || \"\" }, \" *\") : null;\n }\n\n private context(): WidgetContext {\n const { host, def } = this;\n const theme = host.theme;\n return {\n field: def,\n name: this.name,\n path: this.path,\n id: this.id,\n theme,\n texts: host.texts,\n getValue: () => host.getValue(this.path),\n setValue: (value) => {\n this.touched = true;\n host.setValue(this, value);\n },\n setMeta: (key, value) => host.setMeta(this, key, value),\n setWidgetError: (message) => {\n if (message === this.widgetError) return;\n this.widgetError = message;\n if (message) this.touched = true;\n host.refresh();\n },\n error: this.error,\n visible: this.visible,\n attrs: () => this.attrs(),\n label: () => label(\n { for: this.id, id: `${this.id}-label`, class: resolve(def.titleClass, theme.label) },\n def.label ?? \"\",\n this.requiredMark(),\n ),\n description: () => def.description\n ? div({ id: `${this.id}-description`, class: resolve(def.descriptionClass, theme.description) }, def.description)\n : null,\n errorMessage: () => p(\n { id: `${this.id}-error`, class: resolve(def.errorClass, theme.error), \"aria-live\": \"polite\" },\n () => this.error.val,\n ),\n renderChildren: () => this.children.map((c) => c.render()),\n renderItems: () => {\n const value = host.getValue(this.path);\n const count = Array.isArray(value) ? value.length : 0;\n const templates = () => (typeof def.fields === \"function\" ? def.fields() : def.fields ?? []);\n this.items = Array.from({ length: count }, (_, i) =>\n host.buildFields(templates(), [...this.path, String(i)]));\n host.refresh();\n return this.items.map((fields) => fields.map((f) => f.render()));\n },\n };\n }\n\n render(): Element {\n const key = this.widgetKey;\n const widget = this.host.widget(key);\n const base = [resolve(this.def.containerClass, this.host.theme.container), this.host.layoutClass(this)]\n .filter(Boolean).join(\" \");\n const alwaysHidden = key === \"hidden\";\n return div(\n compact({\n id: this.def.containerId,\n class: () => (alwaysHidden || !this.visible.val ? `${base} jsf-hidden`.trim() : base),\n }),\n widget\n ? widget(this.context())\n : div({ class: \"jsf-unsupported\" },\n `Field \"${this.name}\" unsupported: the type \"${key}\" has no UI component built yet.`),\n );\n }\n}\n"]}
|
package/dist/VanJsfForm.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { ChildDom, State } from "vanjs-core";
|
|
2
|
-
import { HeadlessFormOutput } from "@remoteoss/json-schema-form";
|
|
3
|
-
import { VanJsfField, FieldHost } from "./VanJsfField";
|
|
4
|
-
import type { JsfField, JsfFormElement, JsfFormHandle, JsfWidgets, Widget } from "./types";
|
|
5
|
-
import { JsfTheme, JsfLayout, JsfTexts } from "./theme";
|
|
2
|
+
import type { HeadlessFormOutput } from "@remoteoss/json-schema-form";
|
|
3
|
+
import { VanJsfField, FieldHost } from "./VanJsfField.js";
|
|
4
|
+
import type { JsfField, JsfFormElement, JsfFormHandle, JsfWidgets, Widget } from "./types.js";
|
|
5
|
+
import { JsfTheme, JsfLayout, JsfTexts } from "./theme.js";
|
|
6
6
|
/** The config object shared with the caller: `formValues` is reassigned on every change. */
|
|
7
7
|
export type JsfConfig = Record<string, any> & {
|
|
8
8
|
initialValues?: Record<string, unknown>;
|
package/dist/VanJsfForm.js
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import {
|
|
2
|
+
import * as jsfModule from "@remoteoss/json-schema-form";
|
|
3
|
+
// json-schema-form declares no `exports`: bundlers take its ESM build (named exports), Node takes
|
|
4
|
+
// its CommonJS build, whose names Node cannot detect, so they only arrive under `default`. The
|
|
5
|
+
// lookup goes through a function so bundlers see no static `.default` access to warn about.
|
|
6
|
+
const interop = (mod) => mod.default ?? mod;
|
|
7
|
+
const { createHeadlessForm } = interop(jsfModule);
|
|
8
|
+
import { VanJsfField } from "./VanJsfField.js";
|
|
9
|
+
import { defaultTexts } from "./theme.js";
|
|
10
|
+
import { builtinWidgets } from "./widgets/index.js";
|
|
11
|
+
import { arrayBounds, blankGroupItem, blankItem, itemTypeOf } from "./widgets/array.js";
|
|
12
|
+
import { clone, getIn, setIn } from "./values.js";
|
|
13
|
+
import { normalizeSchema } from "./schema.js";
|
|
9
14
|
const { form } = van.tags;
|
|
10
15
|
const FILE_META = ["fileName", "fileSize", "fileType"];
|
|
11
16
|
let formSeq = 0;
|
package/dist/VanJsfForm.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"VanJsfForm.js","sourceRoot":"","sources":["../lib/VanJsfForm.ts"],"names":[],"mappings":"AAAA,OAAO,GAAwB,MAAM,YAAY,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAA4C,MAAM,6BAA6B,CAAC;AAE3G,OAAO,EAAE,WAAW,EAAa,MAAM,eAAe,CAAC;AAEvD,OAAO,EAAiC,YAAY,EAAE,MAAM,SAAS,CAAC;AACtE,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAC3C,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AACrF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,UAAU,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAE3C,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAE1B,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAEvD,IAAI,OAAO,GAAG,CAAC,CAAC;A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;IACD,MAAM,GAAG,GAAc,MAAM,IAAI,EAAE,CAAC;IACpC,GAAG,CAAC,aAAa,KAAK,EAAE,CAAC;IACzB,MAAM,UAAU,GAAG,IAAI,UAAU,CAAC,MAAM,EAAE,GAAG,EAAE;QAC7C,OAAO;QACP,KAAK,EAAE,KAAK,IAAI,EAAE;QAClB,MAAM,EAAE,MAAM,IAAI,EAAE;QACpB,OAAO,EAAE,OAAO,IAAI,EAAE;QACtB,KAAK,EAAE,EAAE,GAAG,YAAY,EAAE,GAAG,KAAK,EAAE;QACpC,QAAQ,EAAE,QAAQ,IAAI,MAAM,EAAE,OAAO,EAAE;KACxC,CAAC,CAAC;IACH,MAAM,EAAE,GAAG,IAAI,CACb;QACE,2FAA2F;QAC3F,2DAA2D;QAC3D,UAAU,EAAE,IAAI;QAChB,GAAI,SAAmC;QACvC,QAAQ,EAAE,CAAC,CAAc,EAAE,EAAE;YAC3B,CAAC,CAAC,cAAc,EAAE,CAAC;YACnB,UAAU,CAAC,MAAM,EAAE,CAAC;YACpB,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;QACD,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzE,EACD,GAAG,UAAU,CAAC,MAAM,EAAE,EACtB,GAAG,QAAQ,CACM,CAAC;IACpB,EAAE,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;IAC7B,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import van, { ChildDom, State } from \"vanjs-core\";\nimport { createHeadlessForm, HeadlessFormOutput, JSONSchemaObjectType } from \"@remoteoss/json-schema-form\";\n\nimport { VanJsfField, FieldHost } from \"./VanJsfField\";\nimport type { JsfField, JsfFormElement, JsfFormHandle, JsfWidgets, Widget } from \"./types\";\nimport { JsfTheme, JsfLayout, JsfTexts, defaultTexts } from \"./theme\";\nimport { builtinWidgets } from \"./widgets\";\nimport { arrayBounds, blankGroupItem, blankItem, itemTypeOf } from \"./widgets/array\";\nimport { clone, getIn, setIn } from \"./values\";\nimport { normalizeSchema } from \"./schema\";\n\nconst { form } = van.tags;\n\nconst FILE_META = [\"fileName\", \"fileSize\", \"fileType\"];\n\nlet formSeq = 0;\n\n/** The config object shared with the caller: `formValues` is reassigned on every change. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type JsfConfig = Record<string, any> & {\n initialValues?: Record<string, unknown>;\n formValues?: Record<string, unknown>;\n};\n\nexport interface JsformAttributes {\n schema: object;\n config?: JsfConfig;\n /** Set to the form's validity after every change, and once when the form is built. */\n isValid?: State<boolean>;\n theme?: JsfTheme;\n layout?: JsfLayout;\n /** Extra or replacement widgets, keyed by input type or by `x-jsf-presentation.widget`. */\n widgets?: JsfWidgets;\n texts?: Partial<JsfTexts>;\n /** Prefix of every DOM id in the form. Defaults to a per-form unique value. */\n idPrefix?: string;\n onsubmit?: (e: SubmitEvent) => void;\n onchange?: (form: VanJsfForm, e: Event) => void;\n [attribute: string]: unknown;\n}\n\ninterface FormOptions {\n isValid?: State<boolean>;\n theme: JsfTheme;\n layout: JsfLayout;\n widgets: JsfWidgets;\n texts: JsfTexts;\n idPrefix: string;\n}\n\nexport class VanJsfForm implements FieldHost {\n readonly headlessForm: HeadlessFormOutput;\n readonly config: JsfConfig;\n readonly theme: JsfTheme;\n readonly texts: JsfTexts;\n readonly idPrefix: string;\n private readonly layout: JsfLayout;\n private readonly widgets: JsfWidgets;\n private readonly isValid?: State<boolean>;\n private readonly initialValues: Record<string, unknown>;\n /** All values, hidden fields included: json-schema-form evaluates conditions on them. */\n private values: Record<string, unknown> = {};\n fields: VanJsfField[] = [];\n private nodes: Element[] = [];\n private submitted = false;\n\n constructor(schema: object, config: JsfConfig, opts: FormOptions) {\n this.config = config;\n this.theme = opts.theme;\n this.texts = opts.texts;\n this.layout = opts.layout;\n this.widgets = opts.widgets;\n this.idPrefix = opts.idPrefix;\n this.isValid = opts.isValid;\n this.initialValues = clone(config.initialValues ?? {});\n const headless = createHeadlessForm(normalizeSchema(schema) as JSONSchemaObjectType, {\n // Infer the input type from the schema (boolean → checkbox, format email → email...)\n // unless the caller asks json-schema-form to insist on x-jsf-presentation.inputType.\n strictInputType: false,\n ...config,\n initialValues: clone(this.initialValues),\n }) as HeadlessFormOutput & { isError?: boolean; error?: unknown };\n // json-schema-form only logs a broken schema and returns an empty form: fail loudly instead.\n if (headless.isError) {\n throw new Error(`vanjs-jsf: invalid JSON Schema: ${String(headless.error)}`, { cause: headless.error });\n }\n this.headlessForm = headless;\n this.load(this.initialValues);\n }\n\n /** Values of the visible fields, nested as the schema is. */\n get formValues(): Record<string, unknown> {\n return this.getValues();\n }\n\n // --- FieldHost -----------------------------------------------------------\n\n layoutClass(field: VanJsfField): string {\n return this.layout[field.path.join(\".\")] || this.layout[field.name] || \"\";\n }\n\n widget(key: string): Widget | undefined {\n return this.widgets[key] ?? builtinWidgets[key];\n }\n\n getValue(path: readonly string[]): unknown {\n return getIn(this.values, path);\n }\n\n setValue(field: VanJsfField, value: unknown): void {\n setIn(this.values, field.path, value);\n this.refresh();\n }\n\n setMeta(field: VanJsfField, key: string, value: unknown): void {\n setIn(this.values, [...field.path.slice(0, -1), `${field.name}__${key}`], value);\n }\n\n buildFields(defs: JsfField[], parentPath: string[]): VanJsfField[] {\n return defs.map((def) => {\n const field = new VanJsfField(def, [...parentPath, def.name], this);\n if (def.inputType === \"fieldset\" && Array.isArray(def.fields)) {\n field.children = this.buildFields(def.fields, field.path);\n }\n return field;\n });\n }\n\n /**\n * Validates the current values and pushes the outcome to every field (visibility, error) and\n * to the caller (`isValid`, `config.formValues`). Reads no reactive state, so it is safe to\n * call from inside a VanJS binding.\n */\n refresh(): boolean {\n // handleValidation writes null over hidden fields of the object it gets: give it a copy, so\n // a field that is hidden and shown again keeps what the user typed.\n const { formErrors } = this.headlessForm.handleValidation(clone(this.values));\n let valid = !formErrors;\n this.visit((field, shown) => {\n field.visible.val = field.def.isVisible ?? true;\n const err = getIn(formErrors, field.path);\n field.validationError = typeof err === \"string\" ? err : \"\";\n if (shown && field.widgetError) valid = false;\n field.showError(this.submitted);\n });\n if (this.isValid) this.isValid.val = valid;\n this.config.formValues = this.getValues();\n return valid;\n }\n\n // --- values --------------------------------------------------------------\n\n getValues(): Record<string, unknown> {\n const out = clone(this.values);\n this.visit((field, shown) => {\n if (shown) return;\n setIn(out, field.path, undefined);\n if (field.inputType === \"file\") {\n for (const key of FILE_META) setIn(out, [...field.path.slice(0, -1), `${field.name}__${key}`], undefined);\n }\n });\n return out;\n }\n\n /** Calls `fn` on every field with whether it and all its ancestors are visible. */\n private visit(fn: (field: VanJsfField, shown: boolean) => void): void {\n const walk = (fields: VanJsfField[], parentShown: boolean) => {\n for (const f of fields) {\n const shown = parentShown && (f.def.isVisible ?? true);\n fn(f, shown);\n walk(f.children, shown);\n for (const item of f.items) walk(item, shown);\n }\n };\n walk(this.fields, true);\n }\n\n private load(initial: Record<string, unknown>): void {\n this.values = {};\n this.submitted = false;\n this.fields = this.buildFields(this.headlessForm.fields as JsfField[], []);\n this.initValues(this.fields, initial);\n this.refresh();\n }\n\n private initValues(fields: VanJsfField[], initial: Record<string, unknown>): void {\n for (const f of fields) {\n if (f.inputType === \"fieldset\") {\n this.initValues(f.children, initial);\n continue;\n }\n const v = this.initialValueOf(f, initial);\n if (v !== undefined) setIn(this.values, f.path, v);\n }\n }\n\n /**\n * Initial value of a field: `initialValues` (nested, or by dotted path), else the schema\n * default. Falsy values (0, false, \"\") are kept. Controls that always display a value\n * (checkbox, slider, colour) start with the value they display.\n */\n private initialValueOf(f: VanJsfField, initial: Record<string, unknown>): unknown {\n const d = f.def;\n let v = getIn(initial, f.path);\n if (v === undefined || v === null) v = initial[f.path.join(\".\")];\n if (v === undefined || v === null) v = d.default;\n const key = f.widgetKey;\n if (key === \"array\" || key === \"group-array\" || key === \"multiselect\") {\n const items = Array.isArray(v) ? clone(v) : [];\n if (key !== \"multiselect\") {\n const { min } = arrayBounds(d);\n while (items.length < min) items.push(key === \"array\" ? blankItem(itemTypeOf(d)) : blankGroupItem(d));\n }\n return items;\n }\n if (v !== undefined && v !== null) return v;\n if (key === \"checkbox\" && d.jsonType === \"boolean\") return false;\n if (key === \"range\") return typeof d.minimum === \"number\" ? d.minimum : 0;\n if (key === \"color\") return \"#000000\";\n return undefined;\n }\n\n // --- rendering & public handle -------------------------------------------\n\n render(): Element[] {\n this.nodes = this.fields.map((f) => f.render());\n return this.nodes;\n }\n\n submit(): boolean {\n this.submitted = true;\n return this.refresh();\n }\n\n private reload(initial: Record<string, unknown>): void {\n const old = this.nodes;\n this.load(clone(initial));\n const fresh = this.render();\n if (old.length) {\n old[0].before(...fresh);\n old.forEach((n) => n.remove());\n }\n }\n\n handle(): JsfFormHandle {\n return {\n getValues: () => this.getValues(),\n setValues: (values) => this.reload(values),\n reset: () => this.reload(this.initialValues),\n validate: () => this.submit(),\n };\n }\n}\n\nexport function jsform(attributes: JsformAttributes, ...children: ChildDom[]): JsfFormElement {\n const { schema, config, isValid, theme, layout, widgets, texts, idPrefix, onsubmit, onchange, ...formAttrs } =\n attributes;\n if (!schema) {\n throw new Error(\"JSON Schema is required\");\n }\n const cfg: JsfConfig = config ?? {};\n cfg.initialValues ??= {};\n const vanJsfForm = new VanJsfForm(schema, cfg, {\n isValid,\n theme: theme ?? {},\n layout: layout ?? {},\n widgets: widgets ?? {},\n texts: { ...defaultTexts, ...texts },\n idPrefix: idPrefix ?? `jsf${++formSeq}`,\n });\n const el = form(\n {\n // Validation is json-schema-form's; native constraints (min, maxLength...) are only hints,\n // and a hidden required control must not block the submit.\n noValidate: true,\n ...(formAttrs as Record<string, never>),\n onsubmit: (e: SubmitEvent) => {\n e.preventDefault();\n vanJsfForm.submit();\n onsubmit?.(e);\n },\n ...(onchange ? { onchange: (e: Event) => onchange(vanJsfForm, e) } : {}),\n },\n ...vanJsfForm.render(),\n ...children,\n ) as JsfFormElement;\n el.jsf = vanJsfForm.handle();\n return el;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"VanJsfForm.js","sourceRoot":"","sources":["../lib/VanJsfForm.ts"],"names":[],"mappings":"AAAA,OAAO,GAAwB,MAAM,YAAY,CAAC;AAClD,OAAO,KAAK,SAAS,MAAM,6BAA6B,CAAC;AAGzD,kGAAkG;AAClG,+FAA+F;AAC/F,4FAA4F;AAC5F,MAAM,OAAO,GAAG,CAAI,GAAM,EAAK,EAAE,CAAE,GAAuB,CAAC,OAAO,IAAI,GAAG,CAAC;AAC1E,MAAM,EAAE,kBAAkB,EAAE,GAAG,OAAO,CAAC,SAAS,CAAC,CAAC;AAElD,OAAO,EAAE,WAAW,EAAa,MAAM,kBAAkB,CAAC;AAE1D,OAAO,EAAiC,YAAY,EAAE,MAAM,YAAY,CAAC;AACzE,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,WAAW,EAAE,cAAc,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AACxF,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C,MAAM,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAE1B,MAAM,SAAS,GAAG,CAAC,UAAU,EAAE,UAAU,EAAE,UAAU,CAAC,CAAC;AAEvD,IAAI,OAAO,GAAG,CAAC,CAAC;AAmChB,MAAM,OAAO,UAAU;IACZ,YAAY,CAAqB;IACjC,MAAM,CAAY;IAClB,KAAK,CAAW;IAChB,KAAK,CAAW;IAChB,QAAQ,CAAS;IACT,MAAM,CAAY;IAClB,OAAO,CAAa;IACpB,OAAO,CAAkB;IACzB,aAAa,CAA0B;IACxD,yFAAyF;IACjF,MAAM,GAA4B,EAAE,C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AI,EAAE;QACpB,OAAO,EAAE,OAAO,IAAI,EAAE;QACtB,KAAK,EAAE,EAAE,GAAG,YAAY,EAAE,GAAG,KAAK,EAAE;QACpC,QAAQ,EAAE,QAAQ,IAAI,MAAM,EAAE,OAAO,EAAE;KACxC,CAAC,CAAC;IACH,MAAM,EAAE,GAAG,IAAI,CACb;QACE,2FAA2F;QAC3F,2DAA2D;QAC3D,UAAU,EAAE,IAAI;QAChB,GAAI,SAAmC;QACvC,QAAQ,EAAE,CAAC,CAAc,EAAE,EAAE;YAC3B,CAAC,CAAC,cAAc,EAAE,CAAC;YACnB,UAAU,CAAC,MAAM,EAAE,CAAC;YACpB,QAAQ,EAAE,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;QACD,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,CAAQ,EAAE,EAAE,CAAC,QAAQ,CAAC,UAAU,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KACzE,EACD,GAAG,UAAU,CAAC,MAAM,EAAE,EACtB,GAAG,QAAQ,CACM,CAAC;IACpB,EAAE,CAAC,GAAG,GAAG,UAAU,CAAC,MAAM,EAAE,CAAC;IAC7B,OAAO,EAAE,CAAC;AACZ,CAAC","sourcesContent":["import van, { ChildDom, State } from \"vanjs-core\";\nimport * as jsfModule from \"@remoteoss/json-schema-form\";\nimport type { HeadlessFormOutput, JSONSchemaObjectType } from \"@remoteoss/json-schema-form\";\n\n// json-schema-form declares no `exports`: bundlers take its ESM build (named exports), Node takes\n// its CommonJS build, whose names Node cannot detect, so they only arrive under `default`. The\n// lookup goes through a function so bundlers see no static `.default` access to warn about.\nconst interop = <T>(mod: T): T => (mod as { default?: T }).default ?? mod;\nconst { createHeadlessForm } = interop(jsfModule);\n\nimport { VanJsfField, FieldHost } from \"./VanJsfField.js\";\nimport type { JsfField, JsfFormElement, JsfFormHandle, JsfWidgets, Widget } from \"./types.js\";\nimport { JsfTheme, JsfLayout, JsfTexts, defaultTexts } from \"./theme.js\";\nimport { builtinWidgets } from \"./widgets/index.js\";\nimport { arrayBounds, blankGroupItem, blankItem, itemTypeOf } from \"./widgets/array.js\";\nimport { clone, getIn, setIn } from \"./values.js\";\nimport { normalizeSchema } from \"./schema.js\";\n\nconst { form } = van.tags;\n\nconst FILE_META = [\"fileName\", \"fileSize\", \"fileType\"];\n\nlet formSeq = 0;\n\n/** The config object shared with the caller: `formValues` is reassigned on every change. */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type JsfConfig = Record<string, any> & {\n initialValues?: Record<string, unknown>;\n formValues?: Record<string, unknown>;\n};\n\nexport interface JsformAttributes {\n schema: object;\n config?: JsfConfig;\n /** Set to the form's validity after every change, and once when the form is built. */\n isValid?: State<boolean>;\n theme?: JsfTheme;\n layout?: JsfLayout;\n /** Extra or replacement widgets, keyed by input type or by `x-jsf-presentation.widget`. */\n widgets?: JsfWidgets;\n texts?: Partial<JsfTexts>;\n /** Prefix of every DOM id in the form. Defaults to a per-form unique value. */\n idPrefix?: string;\n onsubmit?: (e: SubmitEvent) => void;\n onchange?: (form: VanJsfForm, e: Event) => void;\n [attribute: string]: unknown;\n}\n\ninterface FormOptions {\n isValid?: State<boolean>;\n theme: JsfTheme;\n layout: JsfLayout;\n widgets: JsfWidgets;\n texts: JsfTexts;\n idPrefix: string;\n}\n\nexport class VanJsfForm implements FieldHost {\n readonly headlessForm: HeadlessFormOutput;\n readonly config: JsfConfig;\n readonly theme: JsfTheme;\n readonly texts: JsfTexts;\n readonly idPrefix: string;\n private readonly layout: JsfLayout;\n private readonly widgets: JsfWidgets;\n private readonly isValid?: State<boolean>;\n private readonly initialValues: Record<string, unknown>;\n /** All values, hidden fields included: json-schema-form evaluates conditions on them. */\n private values: Record<string, unknown> = {};\n fields: VanJsfField[] = [];\n private nodes: Element[] = [];\n private submitted = false;\n\n constructor(schema: object, config: JsfConfig, opts: FormOptions) {\n this.config = config;\n this.theme = opts.theme;\n this.texts = opts.texts;\n this.layout = opts.layout;\n this.widgets = opts.widgets;\n this.idPrefix = opts.idPrefix;\n this.isValid = opts.isValid;\n this.initialValues = clone(config.initialValues ?? {});\n const headless = createHeadlessForm(normalizeSchema(schema) as JSONSchemaObjectType, {\n // Infer the input type from the schema (boolean → checkbox, format email → email...)\n // unless the caller asks json-schema-form to insist on x-jsf-presentation.inputType.\n strictInputType: false,\n ...config,\n initialValues: clone(this.initialValues),\n }) as HeadlessFormOutput & { isError?: boolean; error?: unknown };\n // json-schema-form only logs a broken schema and returns an empty form: fail loudly instead.\n if (headless.isError) {\n throw new Error(`vanjs-jsf: invalid JSON Schema: ${String(headless.error)}`, { cause: headless.error });\n }\n this.headlessForm = headless;\n this.load(this.initialValues);\n }\n\n /** Values of the visible fields, nested as the schema is. */\n get formValues(): Record<string, unknown> {\n return this.getValues();\n }\n\n // --- FieldHost -----------------------------------------------------------\n\n layoutClass(field: VanJsfField): string {\n return this.layout[field.path.join(\".\")] || this.layout[field.name] || \"\";\n }\n\n widget(key: string): Widget | undefined {\n return this.widgets[key] ?? builtinWidgets[key];\n }\n\n getValue(path: readonly string[]): unknown {\n return getIn(this.values, path);\n }\n\n setValue(field: VanJsfField, value: unknown): void {\n setIn(this.values, field.path, value);\n this.refresh();\n }\n\n setMeta(field: VanJsfField, key: string, value: unknown): void {\n setIn(this.values, [...field.path.slice(0, -1), `${field.name}__${key}`], value);\n }\n\n buildFields(defs: JsfField[], parentPath: string[]): VanJsfField[] {\n return defs.map((def) => {\n const field = new VanJsfField(def, [...parentPath, def.name], this);\n if (def.inputType === \"fieldset\" && Array.isArray(def.fields)) {\n field.children = this.buildFields(def.fields, field.path);\n }\n return field;\n });\n }\n\n /**\n * Validates the current values and pushes the outcome to every field (visibility, error) and\n * to the caller (`isValid`, `config.formValues`). Reads no reactive state, so it is safe to\n * call from inside a VanJS binding.\n */\n refresh(): boolean {\n // handleValidation writes null over hidden fields of the object it gets: give it a copy, so\n // a field that is hidden and shown again keeps what the user typed.\n const { formErrors } = this.headlessForm.handleValidation(clone(this.values));\n let valid = !formErrors;\n this.visit((field, shown) => {\n field.visible.val = field.def.isVisible ?? true;\n const err = getIn(formErrors, field.path);\n field.validationError = typeof err === \"string\" ? err : \"\";\n if (shown && field.widgetError) valid = false;\n field.showError(this.submitted);\n });\n if (this.isValid) this.isValid.val = valid;\n this.config.formValues = this.getValues();\n return valid;\n }\n\n // --- values --------------------------------------------------------------\n\n getValues(): Record<string, unknown> {\n const out = clone(this.values);\n this.visit((field, shown) => {\n if (shown) return;\n setIn(out, field.path, undefined);\n if (field.inputType === \"file\") {\n for (const key of FILE_META) setIn(out, [...field.path.slice(0, -1), `${field.name}__${key}`], undefined);\n }\n });\n return out;\n }\n\n /** Calls `fn` on every field with whether it and all its ancestors are visible. */\n private visit(fn: (field: VanJsfField, shown: boolean) => void): void {\n const walk = (fields: VanJsfField[], parentShown: boolean) => {\n for (const f of fields) {\n const shown = parentShown && (f.def.isVisible ?? true);\n fn(f, shown);\n walk(f.children, shown);\n for (const item of f.items) walk(item, shown);\n }\n };\n walk(this.fields, true);\n }\n\n private load(initial: Record<string, unknown>): void {\n this.values = {};\n this.submitted = false;\n this.fields = this.buildFields(this.headlessForm.fields as JsfField[], []);\n this.initValues(this.fields, initial);\n this.refresh();\n }\n\n private initValues(fields: VanJsfField[], initial: Record<string, unknown>): void {\n for (const f of fields) {\n if (f.inputType === \"fieldset\") {\n this.initValues(f.children, initial);\n continue;\n }\n const v = this.initialValueOf(f, initial);\n if (v !== undefined) setIn(this.values, f.path, v);\n }\n }\n\n /**\n * Initial value of a field: `initialValues` (nested, or by dotted path), else the schema\n * default. Falsy values (0, false, \"\") are kept. Controls that always display a value\n * (checkbox, slider, colour) start with the value they display.\n */\n private initialValueOf(f: VanJsfField, initial: Record<string, unknown>): unknown {\n const d = f.def;\n let v = getIn(initial, f.path);\n if (v === undefined || v === null) v = initial[f.path.join(\".\")];\n if (v === undefined || v === null) v = d.default;\n const key = f.widgetKey;\n if (key === \"array\" || key === \"group-array\" || key === \"multiselect\") {\n const items = Array.isArray(v) ? clone(v) : [];\n if (key !== \"multiselect\") {\n const { min } = arrayBounds(d);\n while (items.length < min) items.push(key === \"array\" ? blankItem(itemTypeOf(d)) : blankGroupItem(d));\n }\n return items;\n }\n if (v !== undefined && v !== null) return v;\n if (key === \"checkbox\" && d.jsonType === \"boolean\") return false;\n if (key === \"range\") return typeof d.minimum === \"number\" ? d.minimum : 0;\n if (key === \"color\") return \"#000000\";\n return undefined;\n }\n\n // --- rendering & public handle -------------------------------------------\n\n render(): Element[] {\n this.nodes = this.fields.map((f) => f.render());\n return this.nodes;\n }\n\n submit(): boolean {\n this.submitted = true;\n return this.refresh();\n }\n\n private reload(initial: Record<string, unknown>): void {\n const old = this.nodes;\n this.load(clone(initial));\n const fresh = this.render();\n if (old.length) {\n old[0].before(...fresh);\n old.forEach((n) => n.remove());\n }\n }\n\n handle(): JsfFormHandle {\n return {\n getValues: () => this.getValues(),\n setValues: (values) => this.reload(values),\n reset: () => this.reload(this.initialValues),\n validate: () => this.submit(),\n };\n }\n}\n\nexport function jsform(attributes: JsformAttributes, ...children: ChildDom[]): JsfFormElement {\n const { schema, config, isValid, theme, layout, widgets, texts, idPrefix, onsubmit, onchange, ...formAttrs } =\n attributes;\n if (!schema) {\n throw new Error(\"JSON Schema is required\");\n }\n const cfg: JsfConfig = config ?? {};\n cfg.initialValues ??= {};\n const vanJsfForm = new VanJsfForm(schema, cfg, {\n isValid,\n theme: theme ?? {},\n layout: layout ?? {},\n widgets: widgets ?? {},\n texts: { ...defaultTexts, ...texts },\n idPrefix: idPrefix ?? `jsf${++formSeq}`,\n });\n const el = form(\n {\n // Validation is json-schema-form's; native constraints (min, maxLength...) are only hints,\n // and a hidden required control must not block the submit.\n noValidate: true,\n ...(formAttrs as Record<string, never>),\n onsubmit: (e: SubmitEvent) => {\n e.preventDefault();\n vanJsfForm.submit();\n onsubmit?.(e);\n },\n ...(onchange ? { onchange: (e: Event) => onchange(vanJsfForm, e) } : {}),\n },\n ...vanJsfForm.render(),\n ...children,\n ) as JsfFormElement;\n el.jsf = vanJsfForm.handle();\n return el;\n}\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { jsform } from "./VanJsfForm";
|
|
2
|
-
export type { JsformAttributes, JsfConfig, VanJsfForm } from "./VanJsfForm";
|
|
3
|
-
export { builtinWidgets } from "./widgets";
|
|
4
|
-
export { defaultTexts } from "./theme";
|
|
5
|
-
export type { JsfTheme, JsfLayout, JsfTexts } from "./theme";
|
|
6
|
-
export type { JsfField, JsfFormElement, JsfFormHandle, JsfWidgets, Option, Widget, WidgetContext, } from "./types";
|
|
1
|
+
export { jsform } from "./VanJsfForm.js";
|
|
2
|
+
export type { JsformAttributes, JsfConfig, VanJsfForm } from "./VanJsfForm.js";
|
|
3
|
+
export { builtinWidgets } from "./widgets/index.js";
|
|
4
|
+
export { defaultTexts } from "./theme.js";
|
|
5
|
+
export type { JsfTheme, JsfLayout, JsfTexts } from "./theme.js";
|
|
6
|
+
export type { JsfField, JsfFormElement, JsfFormHandle, JsfWidgets, Option, Widget, WidgetContext, } from "./types.js";
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { jsform } from "./VanJsfForm";
|
|
2
|
-
export { builtinWidgets } from "./widgets";
|
|
3
|
-
export { defaultTexts } from "./theme";
|
|
1
|
+
export { jsform } from "./VanJsfForm.js";
|
|
2
|
+
export { builtinWidgets } from "./widgets/index.js";
|
|
3
|
+
export { defaultTexts } from "./theme.js";
|
|
4
4
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../lib/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAEzC,OAAO,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC","sourcesContent":["export { jsform } from \"./VanJsfForm.js\";\nexport type { JsformAttributes, JsfConfig, VanJsfForm } from \"./VanJsfForm.js\";\nexport { builtinWidgets } from \"./widgets/index.js\";\nexport { defaultTexts } from \"./theme.js\";\nexport type { JsfTheme, JsfLayout, JsfTexts } from \"./theme.js\";\nexport type {\n JsfField,\n JsfFormElement,\n JsfFormHandle,\n JsfWidgets,\n Option,\n Widget,\n WidgetContext,\n} from \"./types.js\";\n"]}
|
package/dist/types.d.ts
CHANGED
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ChildDom, State } from \"vanjs-core\";\nimport type { JsfTheme, JsfTexts } from \"./theme\";\n\nexport interface Option {\n label: string;\n value: unknown;\n description?: string;\n disabled?: boolean;\n [key: string]: unknown;\n}\n\n/**\n * A field as json-schema-form describes it: the schema keywords it extracts plus every key of\n * `x-jsf-presentation`, flattened onto the same object.\n */\nexport interface JsfField {\n name: string;\n inputType: string;\n label?: string;\n description?: string;\n jsonType?: string;\n required?: boolean;\n isVisible?: boolean;\n readOnly?: boolean;\n default?: unknown;\n options?: Option[] | null;\n multiple?: boolean;\n checkboxValue?: unknown;\n fields?: JsfField[] | (() => JsfField[]);\n [key: string]: unknown;\n}\n\n/** Everything a widget needs to render one field and report its value. */\nexport interface WidgetContext {\n /** The field as json-schema-form describes it, presentation keys included. */\n field: JsfField;\n name: string;\n /** Path of the value inside the form values, e.g. `[\"address\", \"street\"]`. */\n path: string[];\n /** DOM id for the control, unique on the page. */\n id: string;\n theme: JsfTheme;\n texts: JsfTexts;\n /** Current value of the field. */\n getValue(): unknown;\n /** Sets the value and revalidates the form. `undefined` removes it from the values. */\n setValue(value: unknown): void;\n /** Stores `<name>__<key>` next to the value, e.g. file metadata. Does not revalidate. */\n setMeta(key: string, value: unknown): void;\n /**\n * An error the widget itself detects (lint error, file too large). It is shown like a\n * validation error and keeps the form invalid until cleared with \"\".\n */\n setWidgetError(message: string): void;\n /** Message to display, already gated by \"touched or submitted\". */\n error: State<string>;\n visible: State<boolean>;\n /**\n * Native attributes every control should carry: id, name, placeholder, readOnly, disabled,\n * autocomplete and the aria wiring to the description and error.\n */\n attrs(): Record<string, unknown>;\n label(): HTMLElement;\n description(): HTMLElement | null;\n errorMessage(): HTMLElement;\n /** Rendered child fields (fieldset). */\n renderChildren(): Element[];\n /** group-array: rebuilds the sub-fields of every item from the current value and renders them. */\n renderItems(): Element[][];\n}\n\n/** Renders the content of a field container: label, control, description, error. */\nexport type Widget = (ctx: WidgetContext) => ChildDom;\n\nexport type JsfWidgets = Record<string, Widget>;\n\nexport interface JsfFormHandle {\n /** Values of the visible fields, nested as the schema is. */\n getValues(): Record<string, unknown>;\n /** Replaces the values and re-renders the fields. */\n setValues(values: Record<string, unknown>): void;\n /** Back to the initial values; touched state and errors are cleared. */\n reset(): void;\n /** Validates, shows every error and returns whether the form is valid. */\n validate(): boolean;\n}\n\nexport type JsfFormElement = HTMLFormElement & { jsf: JsfFormHandle };\n"]}
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../lib/types.ts"],"names":[],"mappings":"","sourcesContent":["import type { ChildDom, State } from \"vanjs-core\";\nimport type { JsfTheme, JsfTexts } from \"./theme.js\";\n\nexport interface Option {\n label: string;\n value: unknown;\n description?: string;\n disabled?: boolean;\n [key: string]: unknown;\n}\n\n/**\n * A field as json-schema-form describes it: the schema keywords it extracts plus every key of\n * `x-jsf-presentation`, flattened onto the same object.\n */\nexport interface JsfField {\n name: string;\n inputType: string;\n label?: string;\n description?: string;\n jsonType?: string;\n required?: boolean;\n isVisible?: boolean;\n readOnly?: boolean;\n default?: unknown;\n options?: Option[] | null;\n multiple?: boolean;\n checkboxValue?: unknown;\n fields?: JsfField[] | (() => JsfField[]);\n [key: string]: unknown;\n}\n\n/** Everything a widget needs to render one field and report its value. */\nexport interface WidgetContext {\n /** The field as json-schema-form describes it, presentation keys included. */\n field: JsfField;\n name: string;\n /** Path of the value inside the form values, e.g. `[\"address\", \"street\"]`. */\n path: string[];\n /** DOM id for the control, unique on the page. */\n id: string;\n theme: JsfTheme;\n texts: JsfTexts;\n /** Current value of the field. */\n getValue(): unknown;\n /** Sets the value and revalidates the form. `undefined` removes it from the values. */\n setValue(value: unknown): void;\n /** Stores `<name>__<key>` next to the value, e.g. file metadata. Does not revalidate. */\n setMeta(key: string, value: unknown): void;\n /**\n * An error the widget itself detects (lint error, file too large). It is shown like a\n * validation error and keeps the form invalid until cleared with \"\".\n */\n setWidgetError(message: string): void;\n /** Message to display, already gated by \"touched or submitted\". */\n error: State<string>;\n visible: State<boolean>;\n /**\n * Native attributes every control should carry: id, name, placeholder, readOnly, disabled,\n * autocomplete and the aria wiring to the description and error.\n */\n attrs(): Record<string, unknown>;\n label(): HTMLElement;\n description(): HTMLElement | null;\n errorMessage(): HTMLElement;\n /** Rendered child fields (fieldset). */\n renderChildren(): Element[];\n /** group-array: rebuilds the sub-fields of every item from the current value and renders them. */\n renderItems(): Element[][];\n}\n\n/** Renders the content of a field container: label, control, description, error. */\nexport type Widget = (ctx: WidgetContext) => ChildDom;\n\nexport type JsfWidgets = Record<string, Widget>;\n\nexport interface JsfFormHandle {\n /** Values of the visible fields, nested as the schema is. */\n getValues(): Record<string, unknown>;\n /** Replaces the values and re-renders the fields. */\n setValues(values: Record<string, unknown>): void;\n /** Back to the initial values; touched state and errors are cleared. */\n reset(): void;\n /** Validates, shows every error and returns whether the form is valid. */\n validate(): boolean;\n}\n\nexport type JsfFormElement = HTMLFormElement & { jsf: JsfFormHandle };\n"]}
|
package/dist/util.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { JsfField, Option } from "./types";
|
|
1
|
+
import type { JsfField, Option } from "./types.js";
|
|
2
2
|
/** Drops `undefined`/`null` entries: VanJS would otherwise render them as the string "undefined". */
|
|
3
3
|
export declare const compact: (props: Record<string, unknown>) => Record<string, any>;
|
|
4
4
|
/** The JSON Schema node of the field, as declared under its parent. */
|
package/dist/util.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"util.js","sourceRoot":"","sources":["../lib/util.ts"],"names":[],"mappings":"AAEA,qGAAqG;AACrG,8DAA8D;AAC9D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAA8B,EAAuB,EAAE,CAC7E,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;AAE7F,uEAAuE;AACvE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAe,EAA2B,EAAE;IACnE,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAwF,CAAC;IAC9G,OAAO,MAAM,EAAE,UAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;AAChD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/F,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAU,EAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAE/F,qGAAqG;AACrG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAiB,EAAE,EAAE;IAChD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtE,OAAO,CAAC,GAAW,EAAW,EAAE,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACpG,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,IAAqC,EAAU,EAAE,CACnF,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC","sourcesContent":["import type { JsfField, Option } from \"./types\";\n\n/** Drops `undefined`/`null` entries: VanJS would otherwise render them as the string \"undefined\". */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const compact = (props: Record<string, unknown>): Record<string, any> =>\n Object.fromEntries(Object.entries(props).filter(([, v]) => v !== undefined && v !== null));\n\n/** The JSON Schema node of the field, as declared under its parent. */\nexport const schemaOf = (field: JsfField): Record<string, unknown> => {\n const scoped = field.scopedJsonSchema as { properties?: Record<string, Record<string, unknown>> } | undefined;\n return scoped?.properties?.[field.name] ?? {};\n};\n\nexport const toText = (v: unknown): string => (v === undefined || v === null ? \"\" : String(v));\n\nexport const num = (v: unknown): number | undefined => (typeof v === \"number\" ? v : undefined);\n\n/** Maps the string a DOM control reports back to the option's real value (keeps numbers numbers). */\nexport const optionLookup = (options: Option[]) => {\n const byKey = new Map(options.map((o) => [String(o.value), o.value]));\n return (raw: string): unknown => (raw === \"\" ? undefined : byKey.has(raw) ? byKey.get(raw) : raw);\n};\n\nexport const template = (s: string, vars: Record<string, string | number>): string =>\n s.replace(/\\{(\\w+)\\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m));\n"]}
|
|
1
|
+
{"version":3,"file":"util.js","sourceRoot":"","sources":["../lib/util.ts"],"names":[],"mappings":"AAEA,qGAAqG;AACrG,8DAA8D;AAC9D,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,KAA8B,EAAuB,EAAE,CAC7E,MAAM,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC;AAE7F,uEAAuE;AACvE,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,KAAe,EAA2B,EAAE;IACnE,MAAM,MAAM,GAAG,KAAK,CAAC,gBAAwF,CAAC;IAC9G,OAAO,MAAM,EAAE,UAAU,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;AAChD,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,CAAU,EAAU,EAAE,CAAC,CAAC,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/F,MAAM,CAAC,MAAM,GAAG,GAAG,CAAC,CAAU,EAAsB,EAAE,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;AAE/F,qGAAqG;AACrG,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,OAAiB,EAAE,EAAE;IAChD,MAAM,KAAK,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IACtE,OAAO,CAAC,GAAW,EAAW,EAAE,CAAC,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;AACpG,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,QAAQ,GAAG,CAAC,CAAS,EAAE,IAAqC,EAAU,EAAE,CACnF,CAAC,CAAC,OAAO,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,CAAS,EAAE,EAAE,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC","sourcesContent":["import type { JsfField, Option } from \"./types.js\";\n\n/** Drops `undefined`/`null` entries: VanJS would otherwise render them as the string \"undefined\". */\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport const compact = (props: Record<string, unknown>): Record<string, any> =>\n Object.fromEntries(Object.entries(props).filter(([, v]) => v !== undefined && v !== null));\n\n/** The JSON Schema node of the field, as declared under its parent. */\nexport const schemaOf = (field: JsfField): Record<string, unknown> => {\n const scoped = field.scopedJsonSchema as { properties?: Record<string, Record<string, unknown>> } | undefined;\n return scoped?.properties?.[field.name] ?? {};\n};\n\nexport const toText = (v: unknown): string => (v === undefined || v === null ? \"\" : String(v));\n\nexport const num = (v: unknown): number | undefined => (typeof v === \"number\" ? v : undefined);\n\n/** Maps the string a DOM control reports back to the option's real value (keeps numbers numbers). */\nexport const optionLookup = (options: Option[]) => {\n const byKey = new Map(options.map((o) => [String(o.value), o.value]));\n return (raw: string): unknown => (raw === \"\" ? undefined : byKey.has(raw) ? byKey.get(raw) : raw);\n};\n\nexport const template = (s: string, vars: Record<string, string | number>): string =>\n s.replace(/\\{(\\w+)\\}/g, (m, k: string) => (k in vars ? String(vars[k]) : m));\n"]}
|
package/dist/widgets/array.d.ts
CHANGED
package/dist/widgets/array.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
|
-
import { resolve } from "../theme";
|
|
3
|
-
import { schemaOf } from "../util";
|
|
2
|
+
import { resolve } from "../theme.js";
|
|
3
|
+
import { schemaOf } from "../util.js";
|
|
4
4
|
const { button, div, fieldset, input, span } = van.tags;
|
|
5
5
|
export const arrayBounds = (field) => {
|
|
6
6
|
const schema = schemaOf(field);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../lib/widgets/array.ts"],"names":[],"mappings":"AAAA,OAAO,GAAiB,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAIxD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAe,EAAgC,EAAE;IAC3E,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,CAAC,CAA0B,EAAE,EAAE,CAC1C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAE,KAAK,CAAC,CAAC,CAAY,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,KAA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,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC;YAC/D,CAAC;SACF,CAAC,CAAC;IAEL,OAAO,UAAU,CACf,GAAG,EACH,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACvC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,eAAe,EAAE,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EACpG,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAC1B,CAAC;AACJ,CAAC,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,gBAAgB,GAAW,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CACzD,GAAG,EACH,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAC3C,QAAQ,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,cAAc,IAAI,sBAAsB,EAAE,EAAE,GAAG,KAAK,EAAE,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAChH,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAChC,CAAC","sourcesContent":["import van, { ChildDom } from \"vanjs-core\";\nimport type { JsfField, Widget, WidgetContext } from \"../types\";\nimport { resolve } from \"../theme\";\nimport { schemaOf } from \"../util\";\n\nconst { button, div, fieldset, input, span } = van.tags;\n\ntype ItemSchema = { type?: string };\n\nexport const arrayBounds = (field: JsfField): { min: number; max: number } => {\n const schema = schemaOf(field);\n const pick = (k: \"minItems\" | \"maxItems\") =>\n typeof field[k] === \"number\" ? (field[k] as number) : typeof schema[k] === \"number\" ? (schema[k] as number) : undefined;\n return { min: pick(\"minItems\") ?? 0, max: pick(\"maxItems\") ?? Infinity };\n};\n\nexport const itemTypeOf = (field: JsfField): string => {\n const items = (field.items ?? schemaOf(field).items ?? {}) as ItemSchema;\n return items.type ?? \"string\";\n};\n\n/** Value of a new scalar item. */\nexport const blankItem = (itemType: string): unknown =>\n itemType === \"number\" || itemType === \"integer\" ? 0 : itemType === \"boolean\" ? false : \"\";\n\n/** Templates of a group-array item, fresh objects on every call. */\nexport const itemTemplates = (field: JsfField): JsfField[] =>\n typeof field.fields === \"function\" ? field.fields() : field.fields ?? [];\n\n/** A new group-array item, with the defaults its sub-fields declare. */\nexport const blankGroupItem = (field: JsfField): Record<string, unknown> =>\n Object.fromEntries(itemTemplates(field).filter((t) => t.default !== undefined).map((t) => [t.name, t.default]));\n\nconst groupTitle = (ctx: WidgetContext) =>\n div(\n { id: `${ctx.id}-label`, class: resolve(ctx.field.titleClass, ctx.theme.legend || ctx.theme.label) },\n ctx.field.label ?? \"\",\n ctx.field.required ? span({ class: ctx.theme.requiredIndicator || \"\" }, \" *\") : null,\n );\n\nconst currentItems = (ctx: WidgetContext): unknown[] => {\n const v = ctx.getValue();\n return Array.isArray(v) ? v : [];\n};\n\nconst addLabel = (ctx: WidgetContext) =>\n typeof ctx.field.addFieldText === \"string\" ? ctx.field.addFieldText : ctx.texts.add;\n\n/**\n * Shared shell of both list widgets. Rows re-render only when an item is added or removed,\n * never while typing, so an input keeps its focus. `rows` receives `bump` to re-render after\n * a removal.\n */\nfunction listWidget(ctx: WidgetContext, rows: (bump: () => void) => Element[], blank: () => unknown): ChildDom[] {\n const { max } = arrayBounds(ctx.field);\n const version = van.state(0);\n const bump = () => { version.val++; };\n const add = () => {\n const items = currentItems(ctx);\n if (items.length >= max) return;\n ctx.setValue([...items, blank()]);\n bump();\n };\n return [\n groupTitle(ctx),\n ctx.description(),\n () => {\n void version.val;\n return div(\n { class: ctx.theme.arrayItems || \"jsf-array-items\", role: \"group\", \"aria-labelledby\": `${ctx.id}-label` },\n rows(bump),\n );\n },\n button({\n type: \"button\",\n class: ctx.theme.arrayAddButton || \"jsf-array-add\",\n disabled: () => { void version.val; return isLocked(ctx) || currentItems(ctx).length >= max; },\n onclick: add,\n }, addLabel(ctx)),\n ctx.errorMessage(),\n ];\n}\n\nconst isLocked = (ctx: WidgetContext) => Boolean(ctx.field.readOnly || ctx.field.disabled);\n\nconst removeButton = (ctx: WidgetContext, index: number, bump: () => void) => button({\n type: \"button\",\n class: ctx.theme.arrayRemoveButton || \"jsf-array-remove\",\n disabled: isLocked(ctx) || currentItems(ctx).length <= arrayBounds(ctx.field).min,\n \"aria-label\": `${ctx.texts.remove} ${index + 1}`,\n onclick: () => {\n const next = currentItems(ctx).slice();\n next.splice(index, 1);\n ctx.setValue(next);\n bump();\n },\n}, ctx.texts.remove);\n\n/** Repeatable list of scalars (string, number, integer, boolean); the value is a real array. */\nexport const arrayWidget: Widget = (ctx) => {\n const itemType = itemTypeOf(ctx.field);\n const isNumeric = itemType === \"number\" || itemType === \"integer\";\n const isBoolean = itemType === \"boolean\";\n const itemClass = resolve(ctx.field.class, ctx.theme.input);\n\n const update = (i: number, v: unknown) => {\n const next = currentItems(ctx).slice();\n next[i] = v;\n ctx.setValue(next);\n };\n\n const rowInput = (i: number, v: unknown): Element => isBoolean\n ? input({\n type: \"checkbox\",\n id: `${ctx.id}-${i}`,\n name: `${ctx.path.join(\".\")}.${i}`,\n class: itemClass,\n checked: Boolean(v),\n disabled: isLocked(ctx),\n onchange: (e: Event) => update(i, (e.target as HTMLInputElement).checked),\n })\n : input({\n type: isNumeric ? \"number\" : \"text\",\n id: `${ctx.id}-${i}`,\n name: `${ctx.path.join(\".\")}.${i}`,\n class: itemClass,\n value: v === undefined || v === null ? \"\" : String(v),\n readOnly: isLocked(ctx),\n oninput: (e: Event) => {\n const raw = (e.target as HTMLInputElement).value;\n update(i, isNumeric ? (raw === \"\" ? \"\" : Number(raw)) : raw);\n },\n });\n\n return listWidget(\n ctx,\n (bump) => currentItems(ctx).map((v, i) =>\n div({ class: ctx.theme.arrayRow || \"jsf-array-row\" }, rowInput(i, v), removeButton(ctx, i, bump))),\n () => blankItem(itemType),\n );\n};\n\n/** Repeatable list of objects: each item renders its sub-fields as a fieldset. */\nexport const groupArrayWidget: Widget = (ctx) => listWidget(\n ctx,\n (bump) => ctx.renderItems().map((nodes, i) =>\n fieldset({ class: ctx.theme.arrayGroupItem || \"jsf-array-group-item\" }, ...nodes, removeButton(ctx, i, bump))),\n () => blankGroupItem(ctx.field),\n);\n"]}
|
|
1
|
+
{"version":3,"file":"array.js","sourceRoot":"","sources":["../../lib/widgets/array.ts"],"names":[],"mappings":"AAAA,OAAO,GAAiB,MAAM,YAAY,CAAC;AAE3C,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,QAAQ,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAIxD,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,KAAe,EAAgC,EAAE;IAC3E,MAAM,MAAM,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,CAAC,CAA0B,EAAE,EAAE,CAC1C,OAAO,KAAK,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAE,KAAK,CAAC,CAAC,CAAY,CAAC,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,CAAC,KAAK,QAAQ,CAAC,CAAC,CAAE,MAAM,CAAC,CAAC,CAAY,CAAC,CAAC,CAAC,SAAS,CAAC;IAC1H,OAAO,EAAE,GAAG,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,EAAE,GAAG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G,EACH,CAAC,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACvC,GAAG,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,eAAe,EAAE,EAAE,QAAQ,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EACpG,GAAG,EAAE,CAAC,SAAS,CAAC,QAAQ,CAAC,CAC1B,CAAC;AACJ,CAAC,CAAC;AAEF,kFAAkF;AAClF,MAAM,CAAC,MAAM,gBAAgB,GAAW,CAAC,GAAG,EAAE,EAAE,CAAC,UAAU,CACzD,GAAG,EACH,CAAC,IAAI,EAAE,EAAE,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC,EAAE,EAAE,CAC3C,QAAQ,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,cAAc,IAAI,sBAAsB,EAAE,EAAE,GAAG,KAAK,EAAE,YAAY,CAAC,GAAG,EAAE,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC,EAChH,GAAG,EAAE,CAAC,cAAc,CAAC,GAAG,CAAC,KAAK,CAAC,CAChC,CAAC","sourcesContent":["import van, { ChildDom } from \"vanjs-core\";\nimport type { JsfField, Widget, WidgetContext } from \"../types.js\";\nimport { resolve } from \"../theme.js\";\nimport { schemaOf } from \"../util.js\";\n\nconst { button, div, fieldset, input, span } = van.tags;\n\ntype ItemSchema = { type?: string };\n\nexport const arrayBounds = (field: JsfField): { min: number; max: number } => {\n const schema = schemaOf(field);\n const pick = (k: \"minItems\" | \"maxItems\") =>\n typeof field[k] === \"number\" ? (field[k] as number) : typeof schema[k] === \"number\" ? (schema[k] as number) : undefined;\n return { min: pick(\"minItems\") ?? 0, max: pick(\"maxItems\") ?? Infinity };\n};\n\nexport const itemTypeOf = (field: JsfField): string => {\n const items = (field.items ?? schemaOf(field).items ?? {}) as ItemSchema;\n return items.type ?? \"string\";\n};\n\n/** Value of a new scalar item. */\nexport const blankItem = (itemType: string): unknown =>\n itemType === \"number\" || itemType === \"integer\" ? 0 : itemType === \"boolean\" ? false : \"\";\n\n/** Templates of a group-array item, fresh objects on every call. */\nexport const itemTemplates = (field: JsfField): JsfField[] =>\n typeof field.fields === \"function\" ? field.fields() : field.fields ?? [];\n\n/** A new group-array item, with the defaults its sub-fields declare. */\nexport const blankGroupItem = (field: JsfField): Record<string, unknown> =>\n Object.fromEntries(itemTemplates(field).filter((t) => t.default !== undefined).map((t) => [t.name, t.default]));\n\nconst groupTitle = (ctx: WidgetContext) =>\n div(\n { id: `${ctx.id}-label`, class: resolve(ctx.field.titleClass, ctx.theme.legend || ctx.theme.label) },\n ctx.field.label ?? \"\",\n ctx.field.required ? span({ class: ctx.theme.requiredIndicator || \"\" }, \" *\") : null,\n );\n\nconst currentItems = (ctx: WidgetContext): unknown[] => {\n const v = ctx.getValue();\n return Array.isArray(v) ? v : [];\n};\n\nconst addLabel = (ctx: WidgetContext) =>\n typeof ctx.field.addFieldText === \"string\" ? ctx.field.addFieldText : ctx.texts.add;\n\n/**\n * Shared shell of both list widgets. Rows re-render only when an item is added or removed,\n * never while typing, so an input keeps its focus. `rows` receives `bump` to re-render after\n * a removal.\n */\nfunction listWidget(ctx: WidgetContext, rows: (bump: () => void) => Element[], blank: () => unknown): ChildDom[] {\n const { max } = arrayBounds(ctx.field);\n const version = van.state(0);\n const bump = () => { version.val++; };\n const add = () => {\n const items = currentItems(ctx);\n if (items.length >= max) return;\n ctx.setValue([...items, blank()]);\n bump();\n };\n return [\n groupTitle(ctx),\n ctx.description(),\n () => {\n void version.val;\n return div(\n { class: ctx.theme.arrayItems || \"jsf-array-items\", role: \"group\", \"aria-labelledby\": `${ctx.id}-label` },\n rows(bump),\n );\n },\n button({\n type: \"button\",\n class: ctx.theme.arrayAddButton || \"jsf-array-add\",\n disabled: () => { void version.val; return isLocked(ctx) || currentItems(ctx).length >= max; },\n onclick: add,\n }, addLabel(ctx)),\n ctx.errorMessage(),\n ];\n}\n\nconst isLocked = (ctx: WidgetContext) => Boolean(ctx.field.readOnly || ctx.field.disabled);\n\nconst removeButton = (ctx: WidgetContext, index: number, bump: () => void) => button({\n type: \"button\",\n class: ctx.theme.arrayRemoveButton || \"jsf-array-remove\",\n disabled: isLocked(ctx) || currentItems(ctx).length <= arrayBounds(ctx.field).min,\n \"aria-label\": `${ctx.texts.remove} ${index + 1}`,\n onclick: () => {\n const next = currentItems(ctx).slice();\n next.splice(index, 1);\n ctx.setValue(next);\n bump();\n },\n}, ctx.texts.remove);\n\n/** Repeatable list of scalars (string, number, integer, boolean); the value is a real array. */\nexport const arrayWidget: Widget = (ctx) => {\n const itemType = itemTypeOf(ctx.field);\n const isNumeric = itemType === \"number\" || itemType === \"integer\";\n const isBoolean = itemType === \"boolean\";\n const itemClass = resolve(ctx.field.class, ctx.theme.input);\n\n const update = (i: number, v: unknown) => {\n const next = currentItems(ctx).slice();\n next[i] = v;\n ctx.setValue(next);\n };\n\n const rowInput = (i: number, v: unknown): Element => isBoolean\n ? input({\n type: \"checkbox\",\n id: `${ctx.id}-${i}`,\n name: `${ctx.path.join(\".\")}.${i}`,\n class: itemClass,\n checked: Boolean(v),\n disabled: isLocked(ctx),\n onchange: (e: Event) => update(i, (e.target as HTMLInputElement).checked),\n })\n : input({\n type: isNumeric ? \"number\" : \"text\",\n id: `${ctx.id}-${i}`,\n name: `${ctx.path.join(\".\")}.${i}`,\n class: itemClass,\n value: v === undefined || v === null ? \"\" : String(v),\n readOnly: isLocked(ctx),\n oninput: (e: Event) => {\n const raw = (e.target as HTMLInputElement).value;\n update(i, isNumeric ? (raw === \"\" ? \"\" : Number(raw)) : raw);\n },\n });\n\n return listWidget(\n ctx,\n (bump) => currentItems(ctx).map((v, i) =>\n div({ class: ctx.theme.arrayRow || \"jsf-array-row\" }, rowInput(i, v), removeButton(ctx, i, bump))),\n () => blankItem(itemType),\n );\n};\n\n/** Repeatable list of objects: each item renders its sub-fields as a fieldset. */\nexport const groupArrayWidget: Widget = (ctx) => listWidget(\n ctx,\n (bump) => ctx.renderItems().map((nodes, i) =>\n fieldset({ class: ctx.theme.arrayGroupItem || \"jsf-array-group-item\" }, ...nodes, removeButton(ctx, i, bump))),\n () => blankGroupItem(ctx.field),\n);\n"]}
|
package/dist/widgets/basic.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Widget } from "../types";
|
|
1
|
+
import type { Widget } from "../types.js";
|
|
2
2
|
export declare const basicWidgets: Record<string, Widget>;
|
package/dist/widgets/basic.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
|
-
import { resolve } from "../theme";
|
|
3
|
-
import { emptyToUndefined } from "../values";
|
|
4
|
-
import { compact, num, toText } from "../util";
|
|
2
|
+
import { resolve } from "../theme.js";
|
|
3
|
+
import { emptyToUndefined } from "../values.js";
|
|
4
|
+
import { compact, num, toText } from "../util.js";
|
|
5
5
|
const { input, textarea, output, div } = van.tags;
|
|
6
6
|
const target = (e) => e.target;
|
|
7
7
|
const textInput = (type, extra = () => ({})) => (ctx) => [
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"basic.js","sourceRoot":"","sources":["../../lib/widgets/basic.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"basic.js","sourceRoot":"","sources":["../../lib/widgets/basic.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,GAAG,EA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K,EAAE,UAAU;IACjB,QAAQ,EAAE,aAAa;IACvB,MAAM,EAAE,WAAW;CACpB,CAAC","sourcesContent":["import van from \"vanjs-core\";\nimport type { Widget, WidgetContext } from \"../types.js\";\nimport { resolve } from \"../theme.js\";\nimport { emptyToUndefined } from \"../values.js\";\nimport { compact, num, toText } from \"../util.js\";\n\nconst { input, textarea, output, div } = van.tags;\n\nconst target = (e: Event) => e.target as HTMLInputElement;\n\nconst textInput = (type: string, extra: (ctx: WidgetContext) => Record<string, unknown> = () => ({})): Widget =>\n (ctx) => [\n ctx.label(),\n ctx.description(),\n input(compact({\n ...ctx.attrs(),\n type,\n class: resolve(ctx.field.class, ctx.theme.input),\n value: toText(ctx.getValue()),\n maxLength: num(ctx.field.maxLength),\n ...extra(ctx),\n oninput: (e: Event) => ctx.setValue(emptyToUndefined(target(e).value)),\n })),\n ctx.errorMessage(),\n ];\n\nconst numberInput: Widget = (ctx) => {\n const f = ctx.field;\n return [\n ctx.label(),\n ctx.description(),\n input(compact({\n ...ctx.attrs(),\n type: \"number\",\n class: resolve(f.class, ctx.theme.input),\n value: toText(ctx.getValue()),\n min: num(f.minimum),\n max: num(f.maximum),\n step: f.step ?? (f.jsonType === \"integer\" ? 1 : \"any\"),\n oninput: (e: Event) => {\n const raw = target(e).value;\n ctx.setValue(raw === \"\" ? undefined : Number(raw));\n },\n })),\n ctx.errorMessage(),\n ];\n};\n\n/** A slider always shows a position, so the form starts with a value (see initialValue). */\nconst rangeInput: Widget = (ctx) => {\n const f = ctx.field;\n const current = van.state(toText(ctx.getValue()));\n return [\n ctx.label(),\n ctx.description(),\n div({ class: \"jsf-range\" },\n input(compact({\n ...ctx.attrs(),\n type: \"range\",\n class: resolve(f.class, ctx.theme.input),\n value: current.rawVal,\n min: num(f.minimum),\n max: num(f.maximum),\n step: f.step ?? (f.jsonType === \"integer\" ? 1 : \"any\"),\n oninput: (e: Event) => {\n current.val = target(e).value;\n ctx.setValue(Number(current.rawVal));\n },\n })),\n output({ for: ctx.id, class: ctx.theme.rangeOutput || \"jsf-range-output\" }, current),\n ),\n ctx.errorMessage(),\n ];\n};\n\nconst textareaInput: Widget = (ctx) => [\n ctx.label(),\n ctx.description(),\n textarea(compact({\n ...ctx.attrs(),\n class: resolve(ctx.field.class, ctx.theme.textarea),\n rows: num(ctx.field.rows),\n cols: num(ctx.field.columns),\n maxLength: num(ctx.field.maxLength),\n value: toText(ctx.getValue()),\n oninput: (e: Event) => ctx.setValue(emptyToUndefined((e.target as HTMLTextAreaElement).value)),\n })),\n ctx.errorMessage(),\n];\n\nconst hiddenInput: Widget = (ctx) =>\n input({ type: \"hidden\", id: ctx.id, name: ctx.path.join(\".\"), value: toText(ctx.getValue()) });\n\nexport const basicWidgets: Record<string, Widget> = {\n text: textInput(\"text\"),\n password: textInput(\"password\", (ctx) => ({ autocomplete: ctx.field.autocomplete ?? \"new-password\" })),\n email: textInput(\"email\", (ctx) => ({ autocomplete: ctx.field.autocomplete ?? \"email\" })),\n url: textInput(\"url\"),\n tel: textInput(\"tel\"),\n search: textInput(\"search\"),\n color: textInput(\"color\"),\n time: textInput(\"time\"),\n \"datetime-local\": textInput(\"datetime-local\"),\n month: textInput(\"month\"),\n week: textInput(\"week\"),\n number: numberInput,\n range: rangeInput,\n textarea: textareaInput,\n hidden: hiddenInput,\n};\n"]}
|
package/dist/widgets/choice.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Widget } from "../types";
|
|
1
|
+
import type { Widget } from "../types.js";
|
|
2
2
|
export declare const choiceWidgets: Record<string, Widget>;
|
package/dist/widgets/choice.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
|
-
import { resolve } from "../theme";
|
|
3
|
-
import { compact, optionLookup } from "../util";
|
|
2
|
+
import { resolve } from "../theme.js";
|
|
3
|
+
import { compact, optionLookup } from "../util.js";
|
|
4
4
|
const { div, input, label, option, select, small, span } = van.tags;
|
|
5
5
|
const optionsOf = (ctx) => ctx.field.options ?? [];
|
|
6
6
|
/** readOnly has no effect on selects, radios or checkboxes: they are disabled instead. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"choice.js","sourceRoot":"","sources":["../../lib/widgets/choice.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,UAAU,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AAEhD,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAEpE,MAAM,SAAS,GAAG,CAAC,GAAkB,EAAY,EAAE,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO,IAAI,EAAE,CAAC;AAE5E,0FAA0F;AAC1F,MAAM,QAAQ,GAAG,CAAC,GAAkB,EAAE,EAAE,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC;AAE3F,MAAM,YAAY,GAAG,CAAC,GAAkB,EAAE,EAAE,CAC1C,GAAG,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,IAAI,CAAC,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,iBAAiB,IAAI,EAAE,EAAE,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC;AAEvF,0GAA0G;AAC1G,MAAM,UAAU,GAAG,CAAC,GAAkB,EAAE,EAAE,CACxC,GAAG,CACD,EAAE,EAAE,EAAE,GAAG,GAAG,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC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C;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAA2B;IACnD,MAAM,EAAE,YAAY;IACpB,KAAK,EAAE,WAAW;IAClB,QAAQ,EAAE,cAAc;IACxB,WAAW,EAAE,iBAAiB;CAC/B,CAAC","sourcesContent":["import van from \"vanjs-core\";\nimport type { Option, Widget, WidgetContext } from \"../types\";\nimport { resolve } from \"../theme\";\nimport { compact, optionLookup } from \"../util\";\n\nconst { div, input, label, option, select, small, span } = van.tags;\n\nconst optionsOf = (ctx: WidgetContext): Option[] => ctx.field.options ?? [];\n\n/** readOnly has no effect on selects, radios or checkboxes: they are disabled instead. */\nconst isLocked = (ctx: WidgetContext) => Boolean(ctx.field.readOnly || ctx.field.disabled);\n\nconst requiredMark = (ctx: WidgetContext) =>\n ctx.field.required ? span({ class: ctx.theme.requiredIndicator || \"\" }, \" *\") : null;\n\n/** Title of a group of controls (radios, checkboxes): a label element would point at only one of them. */\nconst groupTitle = (ctx: WidgetContext) =>\n div(\n { id: `${ctx.id}-label`, class: resolve(ctx.field.titleClass, ctx.theme.legend || ctx.theme.label) },\n ctx.field.label ?? \"\",\n requiredMark(ctx),\n );\n\nconst groupAria = (ctx: WidgetContext, role: string) => compact({\n role,\n \"aria-labelledby\": `${ctx.id}-label`,\n \"aria-describedby\": ctx.attrs()[\"aria-describedby\"],\n \"aria-required\": ctx.field.required ? \"true\" : undefined,\n});\n\nconst optionDescription = (o: Option) =>\n o.description ? small({ class: \"jsf-option-description\" }, ` ${o.description}`) : null;\n\nconst selectWidget: Widget = (ctx) => {\n const opts = optionsOf(ctx);\n const lookup = optionLookup(opts);\n const current = ctx.getValue();\n const placeholder = typeof ctx.field.placeholder === \"string\" ? ctx.field.placeholder : ctx.texts.selectPlaceholder;\n const el = select(\n compact({\n ...ctx.attrs(),\n placeholder: undefined,\n readOnly: undefined,\n disabled: isLocked(ctx) || undefined,\n class: resolve(ctx.field.class, ctx.theme.select),\n onchange: (e: Event) => ctx.setValue(lookup((e.target as HTMLSelectElement).value)),\n }),\n // Without an empty option the browser shows the first one as chosen while the value is unset.\n option({ class: ctx.theme.option || \"\", value: \"\", selected: current === undefined }, placeholder),\n opts.map((o) =>\n option(compact({\n class: ctx.theme.option || \"\",\n value: String(o.value),\n selected: current !== undefined && String(o.value) === String(current),\n disabled: o.disabled || undefined,\n title: o.description,\n }), o.label),\n ),\n ) as HTMLSelectElement;\n // `selected` on a detached option is not honoured everywhere; set the value once mounted in the select.\n el.value = current === undefined ? \"\" : String(current);\n return [ctx.label(), ctx.description(), el, ctx.errorMessage()];\n};\n\nconst radioWidget: Widget = (ctx) => {\n const current = ctx.getValue();\n return [\n groupTitle(ctx),\n ctx.description(),\n div(\n { ...groupAria(ctx, \"radiogroup\"), class: ctx.theme.radioGroup || \"\" },\n optionsOf(ctx).map((o, i) =>\n label(\n { class: ctx.theme.radioLabel || \"\" },\n input(compact({\n type: \"radio\",\n id: i === 0 ? ctx.id : `${ctx.id}-${i}`,\n name: ctx.path.join(\".\"),\n class: resolve(ctx.field.class, ctx.theme.radioInput),\n value: String(o.value),\n checked: current !== undefined && String(o.value) === String(current),\n disabled: isLocked(ctx) || o.disabled || undefined,\n \"aria-invalid\": () => (ctx.error.val ? \"true\" : \"false\"),\n onchange: () => ctx.setValue(o.value),\n })),\n o.label,\n optionDescription(o),\n ),\n ),\n ),\n ctx.errorMessage(),\n ];\n};\n\n/**\n * A single checkbox. A boolean field stores true/false; a checkbox over a `const` stores that\n * value when checked and nothing when not. `variant: \"switch\"` renders it as a toggle.\n */\nconst checkboxWidget: Widget = (ctx) => {\n const f = ctx.field;\n const isBoolean = f.jsonType === \"boolean\" || f.checkboxValue === true || f.checkboxValue === undefined;\n const onValue = isBoolean ? true : f.checkboxValue;\n const isSwitch = f.variant === \"switch\";\n const inputClass = [resolve(f.class, ctx.theme.checkboxInput), isSwitch ? \"jsf-switch\" : \"\"]\n .filter(Boolean).join(\" \");\n return [\n label(\n { class: resolve(f.titleClass, ctx.theme.checkboxLabel || \"jsf-checkbox-label\") },\n input(compact({\n ...ctx.attrs(),\n placeholder: undefined,\n readOnly: undefined,\n disabled: isLocked(ctx) || undefined,\n type: \"checkbox\",\n role: isSwitch ? \"switch\" : undefined,\n class: inputClass,\n checked: ctx.getValue() === onValue,\n onchange: (e: Event) => {\n const checked = (e.target as HTMLInputElement).checked;\n ctx.setValue(checked ? onValue : isBoolean ? false : undefined);\n },\n })),\n span(f.label ?? \"\"),\n requiredMark(ctx),\n ),\n ctx.description(),\n ctx.errorMessage(),\n ];\n};\n\n/** An array whose items come from a fixed list: one checkbox per option, the value is the chosen values in option order. */\nconst multiselectWidget: Widget = (ctx) => {\n const opts = optionsOf(ctx);\n const current = ctx.getValue();\n const chosen = new Set((Array.isArray(current) ? current : []).map(String));\n const emit = () => ctx.setValue(opts.filter((o) => chosen.has(String(o.value))).map((o) => o.value));\n return [\n groupTitle(ctx),\n ctx.description(),\n div(\n { ...groupAria(ctx, \"group\"), class: ctx.theme.checkboxGroup || \"jsf-checkbox-group\" },\n opts.map((o, i) =>\n label(\n { class: ctx.theme.checkboxLabel || \"jsf-checkbox-label\" },\n input(compact({\n type: \"checkbox\",\n id: i === 0 ? ctx.id : `${ctx.id}-${i}`,\n name: ctx.path.join(\".\"),\n class: resolve(ctx.field.class, ctx.theme.checkboxInput),\n value: String(o.value),\n checked: chosen.has(String(o.value)),\n disabled: isLocked(ctx) || o.disabled || undefined,\n onchange: (e: Event) => {\n const key = String(o.value);\n if ((e.target as HTMLInputElement).checked) chosen.add(key);\n else chosen.delete(key);\n emit();\n },\n })),\n span(o.label),\n optionDescription(o),\n ),\n ),\n ),\n ctx.errorMessage(),\n ];\n};\n\nexport const choiceWidgets: Record<string, Widget> = {\n select: selectWidget,\n radio: radioWidget,\n checkbox: checkboxWidget,\n multiselect: multiselectWidget,\n};\n"]}
|
|
1
|
+
{"version":3,"file":"choice.js","sourceRoot":"","sources":["../../lib/widgets/choice.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,M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\nimport type { Option, Widget, WidgetContext } from \"../types.js\";\nimport { resolve } from \"../theme.js\";\nimport { compact, optionLookup } from \"../util.js\";\n\nconst { div, input, label, option, select, small, span } = van.tags;\n\nconst optionsOf = (ctx: WidgetContext): Option[] => ctx.field.options ?? [];\n\n/** readOnly has no effect on selects, radios or checkboxes: they are disabled instead. */\nconst isLocked = (ctx: WidgetContext) => Boolean(ctx.field.readOnly || ctx.field.disabled);\n\nconst requiredMark = (ctx: WidgetContext) =>\n ctx.field.required ? span({ class: ctx.theme.requiredIndicator || \"\" }, \" *\") : null;\n\n/** Title of a group of controls (radios, checkboxes): a label element would point at only one of them. */\nconst groupTitle = (ctx: WidgetContext) =>\n div(\n { id: `${ctx.id}-label`, class: resolve(ctx.field.titleClass, ctx.theme.legend || ctx.theme.label) },\n ctx.field.label ?? \"\",\n requiredMark(ctx),\n );\n\nconst groupAria = (ctx: WidgetContext, role: string) => compact({\n role,\n \"aria-labelledby\": `${ctx.id}-label`,\n \"aria-describedby\": ctx.attrs()[\"aria-describedby\"],\n \"aria-required\": ctx.field.required ? \"true\" : undefined,\n});\n\nconst optionDescription = (o: Option) =>\n o.description ? small({ class: \"jsf-option-description\" }, ` ${o.description}`) : null;\n\nconst selectWidget: Widget = (ctx) => {\n const opts = optionsOf(ctx);\n const lookup = optionLookup(opts);\n const current = ctx.getValue();\n const placeholder = typeof ctx.field.placeholder === \"string\" ? ctx.field.placeholder : ctx.texts.selectPlaceholder;\n const el = select(\n compact({\n ...ctx.attrs(),\n placeholder: undefined,\n readOnly: undefined,\n disabled: isLocked(ctx) || undefined,\n class: resolve(ctx.field.class, ctx.theme.select),\n onchange: (e: Event) => ctx.setValue(lookup((e.target as HTMLSelectElement).value)),\n }),\n // Without an empty option the browser shows the first one as chosen while the value is unset.\n option({ class: ctx.theme.option || \"\", value: \"\", selected: current === undefined }, placeholder),\n opts.map((o) =>\n option(compact({\n class: ctx.theme.option || \"\",\n value: String(o.value),\n selected: current !== undefined && String(o.value) === String(current),\n disabled: o.disabled || undefined,\n title: o.description,\n }), o.label),\n ),\n ) as HTMLSelectElement;\n // `selected` on a detached option is not honoured everywhere; set the value once mounted in the select.\n el.value = current === undefined ? \"\" : String(current);\n return [ctx.label(), ctx.description(), el, ctx.errorMessage()];\n};\n\nconst radioWidget: Widget = (ctx) => {\n const current = ctx.getValue();\n return [\n groupTitle(ctx),\n ctx.description(),\n div(\n { ...groupAria(ctx, \"radiogroup\"), class: ctx.theme.radioGroup || \"\" },\n optionsOf(ctx).map((o, i) =>\n label(\n { class: ctx.theme.radioLabel || \"\" },\n input(compact({\n type: \"radio\",\n id: i === 0 ? ctx.id : `${ctx.id}-${i}`,\n name: ctx.path.join(\".\"),\n class: resolve(ctx.field.class, ctx.theme.radioInput),\n value: String(o.value),\n checked: current !== undefined && String(o.value) === String(current),\n disabled: isLocked(ctx) || o.disabled || undefined,\n \"aria-invalid\": () => (ctx.error.val ? \"true\" : \"false\"),\n onchange: () => ctx.setValue(o.value),\n })),\n o.label,\n optionDescription(o),\n ),\n ),\n ),\n ctx.errorMessage(),\n ];\n};\n\n/**\n * A single checkbox. A boolean field stores true/false; a checkbox over a `const` stores that\n * value when checked and nothing when not. `variant: \"switch\"` renders it as a toggle.\n */\nconst checkboxWidget: Widget = (ctx) => {\n const f = ctx.field;\n const isBoolean = f.jsonType === \"boolean\" || f.checkboxValue === true || f.checkboxValue === undefined;\n const onValue = isBoolean ? true : f.checkboxValue;\n const isSwitch = f.variant === \"switch\";\n const inputClass = [resolve(f.class, ctx.theme.checkboxInput), isSwitch ? \"jsf-switch\" : \"\"]\n .filter(Boolean).join(\" \");\n return [\n label(\n { class: resolve(f.titleClass, ctx.theme.checkboxLabel || \"jsf-checkbox-label\") },\n input(compact({\n ...ctx.attrs(),\n placeholder: undefined,\n readOnly: undefined,\n disabled: isLocked(ctx) || undefined,\n type: \"checkbox\",\n role: isSwitch ? \"switch\" : undefined,\n class: inputClass,\n checked: ctx.getValue() === onValue,\n onchange: (e: Event) => {\n const checked = (e.target as HTMLInputElement).checked;\n ctx.setValue(checked ? onValue : isBoolean ? false : undefined);\n },\n })),\n span(f.label ?? \"\"),\n requiredMark(ctx),\n ),\n ctx.description(),\n ctx.errorMessage(),\n ];\n};\n\n/** An array whose items come from a fixed list: one checkbox per option, the value is the chosen values in option order. */\nconst multiselectWidget: Widget = (ctx) => {\n const opts = optionsOf(ctx);\n const current = ctx.getValue();\n const chosen = new Set((Array.isArray(current) ? current : []).map(String));\n const emit = () => ctx.setValue(opts.filter((o) => chosen.has(String(o.value))).map((o) => o.value));\n return [\n groupTitle(ctx),\n ctx.description(),\n div(\n { ...groupAria(ctx, \"group\"), class: ctx.theme.checkboxGroup || \"jsf-checkbox-group\" },\n opts.map((o, i) =>\n label(\n { class: ctx.theme.checkboxLabel || \"jsf-checkbox-label\" },\n input(compact({\n type: \"checkbox\",\n id: i === 0 ? ctx.id : `${ctx.id}-${i}`,\n name: ctx.path.join(\".\"),\n class: resolve(ctx.field.class, ctx.theme.checkboxInput),\n value: String(o.value),\n checked: chosen.has(String(o.value)),\n disabled: isLocked(ctx) || o.disabled || undefined,\n onchange: (e: Event) => {\n const key = String(o.value);\n if ((e.target as HTMLInputElement).checked) chosen.add(key);\n else chosen.delete(key);\n emit();\n },\n })),\n span(o.label),\n optionDescription(o),\n ),\n ),\n ),\n ctx.errorMessage(),\n ];\n};\n\nexport const choiceWidgets: Record<string, Widget> = {\n select: selectWidget,\n radio: radioWidget,\n checkbox: checkboxWidget,\n multiselect: multiselectWidget,\n};\n"]}
|
package/dist/widgets/code.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { Widget } from "../types";
|
|
1
|
+
import type { Widget } from "../types.js";
|
|
2
2
|
export declare const codeWidget: Widget;
|
package/dist/widgets/code.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../lib/widgets/code.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM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AAC,CAAC,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,CAAC;YACnD,wFAAwF;YACxF,iEAAiE;YACjE,UAAU,CAAC,cAAc,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,EAAE;gBACjC,IAAI,SAAS,GAAG,EAAE,CAAC;gBACnB,iBAAiB,CAAC,CAAC,CAAC,KAAK,EAAE,CAAC,CAAC,EAAE,EAAE;oBAC/B,IAAI,CAAC,SAAS,IAAI,CAAC,CAAC,QAAQ,KAAK,OAAO;wBAAE,SAAS,GAAG,CAAC,CAAC,OAAO,CAAC;gBAClE,CAAC,CAAC,CAAC;gBACH,IAAI,CAAC,CAAC,UAAU;oBAAE,GAAG,CAAC,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,QAAQ,EAAE,IAAI,SAAS,CAAC,CAAC;gBACpE,GAAG,CAAC,cAAc,CAAC,SAAS,CAAC,CAAC;YAChC,CAAC,CAAC;SACH;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAW,CAAC,GAAG,EAAE,EAAE;IACxC,MAAM,UAAU,GAAG,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;IAC1D,KAAK,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAC","sourcesContent":["import van from \"vanjs-core\";\nimport type { Widget, WidgetContext } from \"../types\";\n\nconst { div } = van.tags;\n\n/**\n * Rules the `code` field lints with. These are ESLint's own `eslint:recommended` set, spelled\n * out because `eslint-linter-browserify` ships no config resolver — a bare `Linter` with no\n * `rules` reports parse errors and nothing else, which looks like a working editor while\n * catching none of the mistakes people actually make.\n *\n * Stylistic rules are deliberately absent. A host embedding this editor has no say in the\n * code style of whoever types into it, and flagging every semicolon as an error is worse than\n * flagging nothing: the real diagnostics drown.\n */\nconst ESLINT_RULES: Record<string, \"error\"> = {\n \"constructor-super\": \"error\",\n \"for-direction\": \"error\",\n \"getter-return\": \"error\",\n \"no-async-promise-executor\": \"error\",\n \"no-case-declarations\": \"error\",\n \"no-class-assign\": \"error\",\n \"no-compare-neg-zero\": \"error\",\n \"no-cond-assign\": \"error\",\n \"no-const-assign\": \"error\",\n \"no-constant-binary-expression\": \"error\",\n \"no-constant-condition\": \"error\",\n \"no-control-regex\": \"error\",\n \"no-debugger\": \"error\",\n \"no-delete-var\": \"error\",\n \"no-dupe-args\": \"error\",\n \"no-dupe-class-members\": \"error\",\n \"no-dupe-else-if\": \"error\",\n \"no-dupe-keys\": \"error\",\n \"no-duplicate-case\": \"error\",\n \"no-empty\": \"error\",\n \"no-empty-character-class\": \"error\",\n \"no-empty-pattern\": \"error\",\n \"no-empty-static-block\": \"error\",\n \"no-ex-assign\": \"error\",\n \"no-extra-boolean-cast\": \"error\",\n \"no-fallthrough\": \"error\",\n \"no-func-assign\": \"error\",\n \"no-global-assign\": \"error\",\n \"no-import-assign\": \"error\",\n \"no-invalid-regexp\": \"error\",\n \"no-irregular-whitespace\": \"error\",\n \"no-loss-of-precision\": \"error\",\n \"no-misleading-character-class\": \"error\",\n \"no-new-native-nonconstructor\": \"error\",\n \"no-nonoctal-decimal-escape\": \"error\",\n \"no-obj-calls\": \"error\",\n \"no-octal\": \"error\",\n \"no-prototype-builtins\": \"error\",\n \"no-redeclare\": \"error\",\n \"no-regex-spaces\": \"error\",\n \"no-self-assign\": \"error\",\n \"no-setter-return\": \"error\",\n \"no-shadow-restricted-names\": \"error\",\n \"no-sparse-arrays\": \"error\",\n \"no-this-before-super\": \"error\",\n \"no-undef\": \"error\",\n \"no-unexpected-multiline\": \"error\",\n \"no-unreachable\": \"error\",\n \"no-unsafe-finally\": \"error\",\n \"no-unsafe-negation\": \"error\",\n \"no-unsafe-optional-chaining\": \"error\",\n \"no-unused-labels\": \"error\",\n \"no-unused-private-class-members\": \"error\",\n \"no-unused-vars\": \"error\",\n \"no-useless-backreference\": \"error\",\n \"no-useless-catch\": \"error\",\n \"no-useless-escape\": \"error\",\n \"no-with\": \"error\",\n \"require-yield\": \"error\",\n \"use-isnan\": \"error\",\n \"valid-typeof\": \"error\",\n};\n\n/**\n * Loads CodeMirror + ESLint on demand and mounts the editor into `parent`. These are the\n * heaviest dependencies in the library; importing them here keeps them out of the bundle of\n * forms that have no `code` field.\n */\nasync function mountCodeEditor(ctx: WidgetContext, parent: HTMLElement): Promise<void> {\n const [\n { basicSetup, EditorView },\n { javascript, esLint },\n { json, jsonParseLinter },\n { lintGutter, linter, forEachDiagnostic },\n eslint,\n globalsModule,\n { dracula },\n ] = await Promise.all([\n import(\"codemirror\"),\n import(\"@codemirror/lang-javascript\"),\n import(\"@codemirror/lang-json\"),\n import(\"@codemirror/lint\"),\n import(\"eslint-linter-browserify\"),\n import(\"globals\"),\n import(\"thememirror\"),\n ]);\n const f = ctx.field;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const globals: any = (globalsModule as any).default ?? globalsModule;\n // A `code` field may declare the globals its host injects at runtime. Those names are in\n // no environment preset, so without this every single one of them reads as `no-undef`.\n const fieldGlobals = f.globals && typeof f.globals === \"object\" ? f.globals : {};\n const eslintConfig = {\n languageOptions: {\n globals: { ...fieldGlobals, ...globals.node },\n parserOptions: { ecmaVersion: 2022, sourceType: \"module\" },\n },\n rules: ESLINT_RULES,\n };\n const cmTheme = EditorView.theme({\n \".cm-content, .cm-gutter\": { \"min-height\": \"150px\" },\n \".cm-gutters\": { margin: \"1px\" },\n \".cm-scroller\": { overflow: \"auto\" },\n });\n const lang = f.codemirrorType === \"json\"\n ? [json(), linter(jsonParseLinter())]\n : [\n javascript({ typescript: f.codemirrorType === \"typescript\" }),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n linter(esLint(new eslint.Linter(), eslintConfig as any)),\n ];\n new EditorView({\n doc: typeof ctx.getValue() === \"string\" ? (ctx.getValue() as string) : \"\",\n parent,\n extensions: [\n dracula,\n cmTheme,\n basicSetup,\n lintGutter(),\n ...lang,\n EditorView.editable.of(!(f.readOnly || f.disabled)),\n // Diagnostics arrive in their own transaction after the linter runs, not with the edit,\n // so every update re-reads them and only edits emit a new value.\n EditorView.updateListener.of((u) => {\n let lintError = \"\";\n forEachDiagnostic(u.state, (d) => {\n if (!lintError && d.severity === \"error\") lintError = d.message;\n });\n if (u.docChanged) ctx.setValue(u.state.doc.toString() || undefined);\n ctx.setWidgetError(lintError);\n }),\n ],\n });\n}\n\nexport const codeWidget: Widget = (ctx) => {\n const editorHost = div({ id: ctx.id, class: \"jsf-code\" });\n void mountCodeEditor(ctx, editorHost);\n return [ctx.label(), ctx.description(), editorHost, ctx.errorMessage()];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"code.js","sourceRoot":"","sources":["../../lib/widgets/code.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAG7B,MAAM,EAAE,GAAG,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAEzB;;;;;;;;;GASG;AACH,MAAM,YAAY,GAA4B;IAC5C,mBAAmB,EAAE,OAAO;IAC5B,eAAe,EAAE,OAAO;IACxB,eAAe,EAAE,OAAO;IACxB,2BAA2B,EAAE,OAAO;IACpC,sBAAsB,EAAE,OAAO;IAC/B,iBAAiB,EAAE,OAAO;IAC1B,qBAAqB,EAAE,OAAO;IAC9B,gBAAgB,EAAE,OAAO;IACzB,iBAAiB,EAAE,OAAO;IAC1B,+BAA+B,EAAE,OAAO;IACxC,uBAAuB,EAAE,OAAO;IAChC,kBAAkB,EAAE,OAAO;IAC3B,aAAa,EAAE,OAAO;IACtB,eAAe,EAAE,OAAO;IACxB,cAAc,EAAE,OAAO;IACvB,uBAAuB,EAAE,OAAO;IAChC,iBAAiB,EAAE,OAAO;IAC1B,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;YAChC,CAAC,CAAC;SACH;KACF,CAAC,CAAC;AACL,CAAC;AAED,MAAM,CAAC,MAAM,UAAU,GAAW,CAAC,GAAG,EAAE,EAAE;IACxC,MAAM,UAAU,GAAG,GAAG,CAAC,EAAE,EAAE,EAAE,GAAG,CAAC,EAAE,EAAE,KAAK,EAAE,UAAU,EAAE,CAAC,CAAC;IAC1D,KAAK,eAAe,CAAC,GAAG,EAAE,UAAU,CAAC,CAAC;IACtC,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,UAAU,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC;AAC1E,CAAC,CAAC","sourcesContent":["import van from \"vanjs-core\";\nimport type { Widget, WidgetContext } from \"../types.js\";\n\nconst { div } = van.tags;\n\n/**\n * Rules the `code` field lints with. These are ESLint's own `eslint:recommended` set, spelled\n * out because `eslint-linter-browserify` ships no config resolver — a bare `Linter` with no\n * `rules` reports parse errors and nothing else, which looks like a working editor while\n * catching none of the mistakes people actually make.\n *\n * Stylistic rules are deliberately absent. A host embedding this editor has no say in the\n * code style of whoever types into it, and flagging every semicolon as an error is worse than\n * flagging nothing: the real diagnostics drown.\n */\nconst ESLINT_RULES: Record<string, \"error\"> = {\n \"constructor-super\": \"error\",\n \"for-direction\": \"error\",\n \"getter-return\": \"error\",\n \"no-async-promise-executor\": \"error\",\n \"no-case-declarations\": \"error\",\n \"no-class-assign\": \"error\",\n \"no-compare-neg-zero\": \"error\",\n \"no-cond-assign\": \"error\",\n \"no-const-assign\": \"error\",\n \"no-constant-binary-expression\": \"error\",\n \"no-constant-condition\": \"error\",\n \"no-control-regex\": \"error\",\n \"no-debugger\": \"error\",\n \"no-delete-var\": \"error\",\n \"no-dupe-args\": \"error\",\n \"no-dupe-class-members\": \"error\",\n \"no-dupe-else-if\": \"error\",\n \"no-dupe-keys\": \"error\",\n \"no-duplicate-case\": \"error\",\n \"no-empty\": \"error\",\n \"no-empty-character-class\": \"error\",\n \"no-empty-pattern\": \"error\",\n \"no-empty-static-block\": \"error\",\n \"no-ex-assign\": \"error\",\n \"no-extra-boolean-cast\": \"error\",\n \"no-fallthrough\": \"error\",\n \"no-func-assign\": \"error\",\n \"no-global-assign\": \"error\",\n \"no-import-assign\": \"error\",\n \"no-invalid-regexp\": \"error\",\n \"no-irregular-whitespace\": \"error\",\n \"no-loss-of-precision\": \"error\",\n \"no-misleading-character-class\": \"error\",\n \"no-new-native-nonconstructor\": \"error\",\n \"no-nonoctal-decimal-escape\": \"error\",\n \"no-obj-calls\": \"error\",\n \"no-octal\": \"error\",\n \"no-prototype-builtins\": \"error\",\n \"no-redeclare\": \"error\",\n \"no-regex-spaces\": \"error\",\n \"no-self-assign\": \"error\",\n \"no-setter-return\": \"error\",\n \"no-shadow-restricted-names\": \"error\",\n \"no-sparse-arrays\": \"error\",\n \"no-this-before-super\": \"error\",\n \"no-undef\": \"error\",\n \"no-unexpected-multiline\": \"error\",\n \"no-unreachable\": \"error\",\n \"no-unsafe-finally\": \"error\",\n \"no-unsafe-negation\": \"error\",\n \"no-unsafe-optional-chaining\": \"error\",\n \"no-unused-labels\": \"error\",\n \"no-unused-private-class-members\": \"error\",\n \"no-unused-vars\": \"error\",\n \"no-useless-backreference\": \"error\",\n \"no-useless-catch\": \"error\",\n \"no-useless-escape\": \"error\",\n \"no-with\": \"error\",\n \"require-yield\": \"error\",\n \"use-isnan\": \"error\",\n \"valid-typeof\": \"error\",\n};\n\n/**\n * Loads CodeMirror + ESLint on demand and mounts the editor into `parent`. These are the\n * heaviest dependencies in the library; importing them here keeps them out of the bundle of\n * forms that have no `code` field.\n */\nasync function mountCodeEditor(ctx: WidgetContext, parent: HTMLElement): Promise<void> {\n const [\n { basicSetup, EditorView },\n { javascript, esLint },\n { json, jsonParseLinter },\n { lintGutter, linter, forEachDiagnostic },\n eslint,\n globalsModule,\n { dracula },\n ] = await Promise.all([\n import(\"codemirror\"),\n import(\"@codemirror/lang-javascript\"),\n import(\"@codemirror/lang-json\"),\n import(\"@codemirror/lint\"),\n import(\"eslint-linter-browserify\"),\n import(\"globals\"),\n import(\"thememirror\"),\n ]);\n const f = ctx.field;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const globals: any = (globalsModule as any).default ?? globalsModule;\n // A `code` field may declare the globals its host injects at runtime. Those names are in\n // no environment preset, so without this every single one of them reads as `no-undef`.\n const fieldGlobals = f.globals && typeof f.globals === \"object\" ? f.globals : {};\n const eslintConfig = {\n languageOptions: {\n globals: { ...fieldGlobals, ...globals.node },\n parserOptions: { ecmaVersion: 2022, sourceType: \"module\" },\n },\n rules: ESLINT_RULES,\n };\n const cmTheme = EditorView.theme({\n \".cm-content, .cm-gutter\": { \"min-height\": \"150px\" },\n \".cm-gutters\": { margin: \"1px\" },\n \".cm-scroller\": { overflow: \"auto\" },\n });\n const lang = f.codemirrorType === \"json\"\n ? [json(), linter(jsonParseLinter())]\n : [\n javascript({ typescript: f.codemirrorType === \"typescript\" }),\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n linter(esLint(new eslint.Linter(), eslintConfig as any)),\n ];\n new EditorView({\n doc: typeof ctx.getValue() === \"string\" ? (ctx.getValue() as string) : \"\",\n parent,\n extensions: [\n dracula,\n cmTheme,\n basicSetup,\n lintGutter(),\n ...lang,\n EditorView.editable.of(!(f.readOnly || f.disabled)),\n // Diagnostics arrive in their own transaction after the linter runs, not with the edit,\n // so every update re-reads them and only edits emit a new value.\n EditorView.updateListener.of((u) => {\n let lintError = \"\";\n forEachDiagnostic(u.state, (d) => {\n if (!lintError && d.severity === \"error\") lintError = d.message;\n });\n if (u.docChanged) ctx.setValue(u.state.doc.toString() || undefined);\n ctx.setWidgetError(lintError);\n }),\n ],\n });\n}\n\nexport const codeWidget: Widget = (ctx) => {\n const editorHost = div({ id: ctx.id, class: \"jsf-code\" });\n void mountCodeEditor(ctx, editorHost);\n return [ctx.label(), ctx.description(), editorHost, ctx.errorMessage()];\n};\n"]}
|
package/dist/widgets/date.d.ts
CHANGED
package/dist/widgets/date.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
|
-
import { resolve } from "../theme";
|
|
3
|
-
import { emptyToUndefined } from "../values";
|
|
4
|
-
import { compact, toText } from "../util";
|
|
2
|
+
import { resolve } from "../theme.js";
|
|
3
|
+
import { emptyToUndefined } from "../values.js";
|
|
4
|
+
import { compact, toText } from "../util.js";
|
|
5
5
|
const { input } = van.tags;
|
|
6
6
|
const pad = (n) => String(n).padStart(2, "0");
|
|
7
7
|
/**
|
package/dist/widgets/date.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../lib/widgets/date.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"date.js","sourceRoot":"","sources":["../../lib/widgets/date.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAC;AAChD,OAAO,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AAE7C,MAAM,EAAE,KAAK,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAE3B,MAAM,GAAG,GAAG,CAAC,CAAS,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,CAAC;AAEtD;;;;GAIG;AACH,KAAK,UAAU,YAAY,CAAC,GAAkB,EAAE,KAAuB;IACrE,MAAM,OAAO,GAAG,CAAC,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,CAAC;IAClD,IAAI,OAAO,CAAC;QACV,KAAK;QACL,SAAS,EAAE,KAAK,CAAC,aAA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AAK,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC;QAChD,KAAK,EAAE,MAAM,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;QAC7B,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO;QAC/C,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,OAAO;QAC/C,QAAQ,EAAE,CAAC,CAAQ,EAAE,EAAE,CAAC,GAAG,CAAC,QAAQ,CAAC,gBAAgB,CAAE,CAAC,CAAC,MAA2B,CAAC,KAAK,CAAC,CAAC;KAC7F,CAAC,CAAqB,CAAC;IACxB,IAAI,UAAU;QAAE,cAAc,CAAC,GAAG,EAAE,CAAC,KAAK,YAAY,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC;IACjE,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,EAAE,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC;AAClE,CAAC,CAAC","sourcesContent":["import van from \"vanjs-core\";\nimport type { Widget, WidgetContext } from \"../types.js\";\nimport { resolve } from \"../theme.js\";\nimport { emptyToUndefined } from \"../values.js\";\nimport { compact, toText } from \"../util.js\";\n\nconst { input } = van.tags;\n\nconst pad = (n: number) => String(n).padStart(2, \"0\");\n\n/**\n * Pikaday is loaded only when a field asks for it (`picker: \"pikaday\"`). Its stylesheet is the\n * host's to include (`import \"pikaday/css/pikaday.css\"`): loading it from a CDN at runtime\n * breaks under a strict CSP and depends on a third party being up.\n */\nasync function mountPikaday(ctx: WidgetContext, field: HTMLInputElement): Promise<void> {\n const Pikaday = (await import(\"pikaday\")).default;\n new Pikaday({\n field,\n container: field.parentElement ?? undefined,\n firstDay: 1,\n minDate: ctx.field.minDate ? new Date(String(ctx.field.minDate)) : undefined,\n maxDate: ctx.field.maxDate ? new Date(String(ctx.field.maxDate)) : undefined,\n toString: (d: Date) => `${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())}`,\n parse: (s: string) => {\n const [y, m, d] = s.split(\"-\").map((p) => parseInt(p, 10));\n return new Date(y, m - 1, d);\n },\n });\n}\n\n/** Native `<input type=\"date\">` by default; the value is always `YYYY-MM-DD`. */\nexport const dateWidget: Widget = (ctx) => {\n const usePikaday = ctx.field.picker === \"pikaday\";\n const el = input(compact({\n ...ctx.attrs(),\n type: usePikaday ? \"text\" : \"date\",\n class: resolve(ctx.field.class, ctx.theme.input),\n value: toText(ctx.getValue()),\n min: usePikaday ? undefined : ctx.field.minDate,\n max: usePikaday ? undefined : ctx.field.maxDate,\n onchange: (e: Event) => ctx.setValue(emptyToUndefined((e.target as HTMLInputElement).value)),\n })) as HTMLInputElement;\n if (usePikaday) queueMicrotask(() => void mountPikaday(ctx, el));\n return [ctx.label(), ctx.description(), el, ctx.errorMessage()];\n};\n"]}
|
package/dist/widgets/file.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Widget } from "../types";
|
|
1
|
+
import type { Widget } from "../types.js";
|
|
2
2
|
/**
|
|
3
3
|
* Drag & drop zone that reads the file in the browser. The content becomes the value; name,
|
|
4
4
|
* size and MIME type go next to it as `<name>__fileName`, `__fileSize` and `__fileType`.
|
package/dist/widgets/file.js
CHANGED
package/dist/widgets/file.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../lib/widgets/file.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAEnC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAA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AY,EAAE,CAAC,CAAC;AAC9G,CAAC,CAAC","sourcesContent":["import van from \"vanjs-core\";\nimport type { Widget } from \"../types\";\nimport { template } from \"../util\";\n\nconst { button, div, input, p, small, strong } = van.tags;\n\nconst TEXT_EXTENSIONS = new Set([\n \"json\", \"csv\", \"tsv\", \"txt\", \"xml\", \"yaml\", \"yml\",\n \"log\", \"md\", \"html\", \"css\", \"js\", \"ts\", \"sql\", \"env\",\n]);\n\nconst formatSize = (bytes: number): string => {\n if (bytes < 1024) return `${bytes} B`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n};\n\n/** Base64 of a buffer, in chunks: one char at a time is quadratic on large files. */\nconst toBase64 = (buf: ArrayBuffer): string => {\n const bytes = new Uint8Array(buf);\n let binary = \"\";\n for (let i = 0; i < bytes.length; i += 0x8000) {\n binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));\n }\n return btoa(binary);\n};\n\n/**\n * Drag & drop zone that reads the file in the browser. The content becomes the value; name,\n * size and MIME type go next to it as `<name>__fileName`, `__fileSize` and `__fileType`.\n */\nexport const fileWidget: Widget = (ctx) => {\n const f = ctx.field;\n const { theme, texts } = ctx;\n const accept = typeof f.accept === \"string\" ? f.accept : \"\";\n const maxSizeMB = typeof f.maxSizeMB === \"number\" ? f.maxSizeMB : undefined;\n const readAs = typeof f.readAs === \"string\" ? f.readAs : \"auto\";\n const locked = Boolean(f.readOnly || f.disabled);\n\n const fileName = van.state(\"\");\n const fileSize = van.state(\"\");\n const dragOver = van.state(false);\n const reading = van.state(false);\n\n const setMeta = (name?: string, size?: number, type?: string) => {\n ctx.setMeta(\"fileName\", name);\n ctx.setMeta(\"fileSize\", size === undefined ? undefined : String(size));\n ctx.setMeta(\"fileType\", type);\n };\n\n const readFile = (file: File) => {\n if (maxSizeMB && file.size > maxSizeMB * 1024 * 1024) {\n ctx.setWidgetError(template(texts.fileTooLarge, { max: maxSizeMB }));\n return;\n }\n ctx.setWidgetError(\"\");\n fileName.val = file.name;\n fileSize.val = formatSize(file.size);\n reading.val = true;\n\n const reader = new FileReader();\n reader.onload = () => {\n reading.val = false;\n const result = reader.result instanceof ArrayBuffer ? toBase64(reader.result) : String(reader.result ?? \"\");\n setMeta(file.name, file.size, file.type);\n ctx.setValue(result);\n };\n reader.onerror = () => {\n reading.val = false;\n ctx.setWidgetError(texts.fileReadError);\n };\n\n const ext = file.name.split(\".\").pop()?.toLowerCase() ?? \"\";\n if (readAs === \"dataURL\") reader.readAsDataURL(file);\n else if (readAs === \"arrayBuffer\" || (readAs === \"auto\" && !TEXT_EXTENSIONS.has(ext))) reader.readAsArrayBuffer(file);\n else reader.readAsText(file);\n };\n\n const fileInput = input({\n type: \"file\",\n id: ctx.id,\n name: ctx.path.join(\".\"),\n accept,\n disabled: locked,\n style: \"display: none;\",\n onchange: (e: Event) => {\n const files = (e.target as HTMLInputElement).files;\n if (files?.[0]) readFile(files[0]);\n },\n }) as HTMLInputElement;\n\n const clear = (e: Event) => {\n e.stopPropagation();\n fileName.val = \"\";\n fileSize.val = \"\";\n reading.val = false;\n fileInput.value = \"\";\n ctx.setWidgetError(\"\");\n setMeta();\n ctx.setValue(undefined);\n };\n\n const dzBase = theme.dropZone || \"jsf-dropzone\";\n const dzActive = theme.dropZoneActive || \"jsf-dropzone-active\";\n const browse = () => { if (!locked) fileInput.click(); };\n\n const dropZone = div(\n {\n class: () => (dragOver.val ? `${dzBase} ${dzActive}` : dzBase),\n role: \"button\",\n tabindex: locked ? \"-1\" : \"0\",\n \"aria-labelledby\": `${ctx.id}-label`,\n \"aria-describedby\": ctx.attrs()[\"aria-describedby\"] as string,\n ondragover: (e: DragEvent) => { e.preventDefault(); dragOver.val = !locked; },\n ondragleave: () => { dragOver.val = false; },\n ondrop: (e: DragEvent) => {\n e.preventDefault();\n dragOver.val = false;\n const files = e.dataTransfer?.files;\n if (!locked && files?.[0]) readFile(files[0]);\n },\n onclick: browse,\n onkeydown: (e: KeyboardEvent) => {\n if (e.key === \"Enter\" || e.key === \" \") { e.preventDefault(); browse(); }\n },\n },\n p(\n { class: theme.dropZoneText || \"jsf-dropzone-text\" },\n accept ? template(texts.dropFileAccept, { accept }) : texts.dropFile,\n ),\n );\n\n const infoBar = () => fileName.val\n ? div(\n { class: theme.fileInfoBar || \"jsf-file-info\" },\n strong({ class: theme.fileName || \"\" }, fileName.val),\n small({ class: theme.fileSize || \"jsf-file-size\" }, `(${fileSize.val})`),\n button({ type: \"button\", class: theme.fileClearButton || \"jsf-file-clear\", onclick: clear }, texts.clearFile),\n )\n : div();\n\n const readingIndicator = () => reading.val\n ? div({ class: theme.fileReading || \"jsf-file-reading\" }, texts.readingFile)\n : div();\n\n return [ctx.label(), ctx.description(), fileInput, dropZone, infoBar, readingIndicator, ctx.errorMessage()];\n};\n"]}
|
|
1
|
+
{"version":3,"file":"file.js","sourceRoot":"","sources":["../../lib/widgets/file.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAEtC,MAAM,EAAE,MAAM,EAAE,GAAG,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAE1D,MAAM,eAAe,GAAG,IAAI,GAAG,CAAC;IAC9B,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK;IACjD,KAAK,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,KAAK;CACrD,CAAC,CAAC;AAEH,MAAM,UAAU,GAAG,CAAC,KAAa,EAAU,EAAE;IAC3C,IAAI,KAAK,GAAG,IAAI;QAAE,OAAO,GAAG,KAAK,IAAI,CAAC;IACtC,IAAI,KAAK,GAAG,IAAI,GAAG,IAAI;QAAE,OAAO,GAAG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I,eAAe,EAAE,EAC/C,MAAM,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,IAAI,EAAE,EAAE,EAAE,QAAQ,CAAC,GAAG,CAAC,EACrD,KAAK,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,QAAQ,IAAI,eAAe,EAAE,EAAE,IAAI,QAAQ,CAAC,GAAG,GAAG,CAAC,EACxE,MAAM,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,KAAK,EAAE,KAAK,CAAC,eAAe,IAAI,gBAAgB,EAAE,OAAO,EAAE,KAAK,EAAE,EAAE,KAAK,CAAC,SAAS,CAAC,CAC9G;QACD,CAAC,CAAC,GAAG,EAAE,CAAC;IAEV,MAAM,gBAAgB,GAAG,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG;QACxC,CAAC,CAAC,GAAG,CAAC,EAAE,KAAK,EAAE,KAAK,CAAC,WAAW,IAAI,kBAAkB,EAAE,EAAE,KAAK,CAAC,WAAW,CAAC;QAC5E,CAAC,CAAC,GAAG,EAAE,CAAC;IAEV,OAAO,CAAC,GAAG,CAAC,KAAK,EAAE,EAAE,GAAG,CAAC,WAAW,EAAE,EAAE,SAAS,EAAE,QAAQ,EAAE,OAAO,EAAE,gBAAgB,EAAE,GAAG,CAAC,YAAY,EAAE,CAAC,CAAC;AAC9G,CAAC,CAAC","sourcesContent":["import van from \"vanjs-core\";\nimport type { Widget } from \"../types.js\";\nimport { template } from \"../util.js\";\n\nconst { button, div, input, p, small, strong } = van.tags;\n\nconst TEXT_EXTENSIONS = new Set([\n \"json\", \"csv\", \"tsv\", \"txt\", \"xml\", \"yaml\", \"yml\",\n \"log\", \"md\", \"html\", \"css\", \"js\", \"ts\", \"sql\", \"env\",\n]);\n\nconst formatSize = (bytes: number): string => {\n if (bytes < 1024) return `${bytes} B`;\n if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;\n return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;\n};\n\n/** Base64 of a buffer, in chunks: one char at a time is quadratic on large files. */\nconst toBase64 = (buf: ArrayBuffer): string => {\n const bytes = new Uint8Array(buf);\n let binary = \"\";\n for (let i = 0; i < bytes.length; i += 0x8000) {\n binary += String.fromCharCode(...bytes.subarray(i, i + 0x8000));\n }\n return btoa(binary);\n};\n\n/**\n * Drag & drop zone that reads the file in the browser. The content becomes the value; name,\n * size and MIME type go next to it as `<name>__fileName`, `__fileSize` and `__fileType`.\n */\nexport const fileWidget: Widget = (ctx) => {\n const f = ctx.field;\n const { theme, texts } = ctx;\n const accept = typeof f.accept === \"string\" ? f.accept : \"\";\n const maxSizeMB = typeof f.maxSizeMB === \"number\" ? f.maxSizeMB : undefined;\n const readAs = typeof f.readAs === \"string\" ? f.readAs : \"auto\";\n const locked = Boolean(f.readOnly || f.disabled);\n\n const fileName = van.state(\"\");\n const fileSize = van.state(\"\");\n const dragOver = van.state(false);\n const reading = van.state(false);\n\n const setMeta = (name?: string, size?: number, type?: string) => {\n ctx.setMeta(\"fileName\", name);\n ctx.setMeta(\"fileSize\", size === undefined ? undefined : String(size));\n ctx.setMeta(\"fileType\", type);\n };\n\n const readFile = (file: File) => {\n if (maxSizeMB && file.size > maxSizeMB * 1024 * 1024) {\n ctx.setWidgetError(template(texts.fileTooLarge, { max: maxSizeMB }));\n return;\n }\n ctx.setWidgetError(\"\");\n fileName.val = file.name;\n fileSize.val = formatSize(file.size);\n reading.val = true;\n\n const reader = new FileReader();\n reader.onload = () => {\n reading.val = false;\n const result = reader.result instanceof ArrayBuffer ? toBase64(reader.result) : String(reader.result ?? \"\");\n setMeta(file.name, file.size, file.type);\n ctx.setValue(result);\n };\n reader.onerror = () => {\n reading.val = false;\n ctx.setWidgetError(texts.fileReadError);\n };\n\n const ext = file.name.split(\".\").pop()?.toLowerCase() ?? \"\";\n if (readAs === \"dataURL\") reader.readAsDataURL(file);\n else if (readAs === \"arrayBuffer\" || (readAs === \"auto\" && !TEXT_EXTENSIONS.has(ext))) reader.readAsArrayBuffer(file);\n else reader.readAsText(file);\n };\n\n const fileInput = input({\n type: \"file\",\n id: ctx.id,\n name: ctx.path.join(\".\"),\n accept,\n disabled: locked,\n style: \"display: none;\",\n onchange: (e: Event) => {\n const files = (e.target as HTMLInputElement).files;\n if (files?.[0]) readFile(files[0]);\n },\n }) as HTMLInputElement;\n\n const clear = (e: Event) => {\n e.stopPropagation();\n fileName.val = \"\";\n fileSize.val = \"\";\n reading.val = false;\n fileInput.value = \"\";\n ctx.setWidgetError(\"\");\n setMeta();\n ctx.setValue(undefined);\n };\n\n const dzBase = theme.dropZone || \"jsf-dropzone\";\n const dzActive = theme.dropZoneActive || \"jsf-dropzone-active\";\n const browse = () => { if (!locked) fileInput.click(); };\n\n const dropZone = div(\n {\n class: () => (dragOver.val ? `${dzBase} ${dzActive}` : dzBase),\n role: \"button\",\n tabindex: locked ? \"-1\" : \"0\",\n \"aria-labelledby\": `${ctx.id}-label`,\n \"aria-describedby\": ctx.attrs()[\"aria-describedby\"] as string,\n ondragover: (e: DragEvent) => { e.preventDefault(); dragOver.val = !locked; },\n ondragleave: () => { dragOver.val = false; },\n ondrop: (e: DragEvent) => {\n e.preventDefault();\n dragOver.val = false;\n const files = e.dataTransfer?.files;\n if (!locked && files?.[0]) readFile(files[0]);\n },\n onclick: browse,\n onkeydown: (e: KeyboardEvent) => {\n if (e.key === \"Enter\" || e.key === \" \") { e.preventDefault(); browse(); }\n },\n },\n p(\n { class: theme.dropZoneText || \"jsf-dropzone-text\" },\n accept ? template(texts.dropFileAccept, { accept }) : texts.dropFile,\n ),\n );\n\n const infoBar = () => fileName.val\n ? div(\n { class: theme.fileInfoBar || \"jsf-file-info\" },\n strong({ class: theme.fileName || \"\" }, fileName.val),\n small({ class: theme.fileSize || \"jsf-file-size\" }, `(${fileSize.val})`),\n button({ type: \"button\", class: theme.fileClearButton || \"jsf-file-clear\", onclick: clear }, texts.clearFile),\n )\n : div();\n\n const readingIndicator = () => reading.val\n ? div({ class: theme.fileReading || \"jsf-file-reading\" }, texts.readingFile)\n : div();\n\n return [ctx.label(), ctx.description(), fileInput, dropZone, infoBar, readingIndicator, ctx.errorMessage()];\n};\n"]}
|
package/dist/widgets/index.d.ts
CHANGED
package/dist/widgets/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import van from "vanjs-core";
|
|
2
|
-
import { resolve } from "../theme";
|
|
3
|
-
import { basicWidgets } from "./basic";
|
|
4
|
-
import { choiceWidgets } from "./choice";
|
|
5
|
-
import { dateWidget } from "./date";
|
|
6
|
-
import { codeWidget } from "./code";
|
|
7
|
-
import { fileWidget } from "./file";
|
|
8
|
-
import { arrayWidget, groupArrayWidget } from "./array";
|
|
2
|
+
import { resolve } from "../theme.js";
|
|
3
|
+
import { basicWidgets } from "./basic.js";
|
|
4
|
+
import { choiceWidgets } from "./choice.js";
|
|
5
|
+
import { dateWidget } from "./date.js";
|
|
6
|
+
import { codeWidget } from "./code.js";
|
|
7
|
+
import { fileWidget } from "./file.js";
|
|
8
|
+
import { arrayWidget, groupArrayWidget } from "./array.js";
|
|
9
9
|
const { fieldset, legend } = van.tags;
|
|
10
10
|
const fieldsetWidget = (ctx) => fieldset({ class: ctx.theme.fieldset || "" }, legend({ class: resolve(ctx.field.titleClass, ctx.theme.legend || ctx.theme.label) }, ctx.field.label ?? ""), ctx.description(), ...ctx.renderChildren(), ctx.errorMessage());
|
|
11
11
|
/** Built-in widgets, keyed by input type. A `widgets` entry passed to `jsform()` overrides any of them. */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/widgets/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../lib/widgets/index.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,YAAY,CAAC;AAE7B,OAAO,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACvC,OAAO,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAE3D,MAAM,EAAE,QAAQ,EAAE,MAAM,EAAE,GAAG,GAAG,CAAC,IAAI,CAAC;AAEtC,MAAM,cAAc,GAAW,CAAC,GAAG,EAAE,EAAE,CACrC,QAAQ,CACN,EAAE,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,EAAE,EACnC,MAAM,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,GAAG,CAAC,KAAK,CAAC,UAAU,EAAE,GAAG,CAAC,KAAK,CAAC,MAAM,IAAI,GAAG,CAAC,KAAK,CAAC,KAAK,CAAC,EAAE,EAAE,GAAG,CAAC,KAAK,CAAC,KAAK,IAAI,EAAE,CAAC,EAC5G,GAAG,CAAC,WAAW,EAAE,EACjB,GAAG,GAAG,CAAC,cAAc,EAAE,EACvB,GAAG,CAAC,YAAY,EAAE,CACnB,CAAC;AAEJ,2GAA2G;AAC3G,MAAM,CAAC,MAAM,cAAc,GAA2B;IACpD,GAAG,YAAY;IACf,GAAG,aAAa;IAChB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,IAAI,EAAE,UAAU;IAChB,QAAQ,EAAE,cAAc;IACxB,KAAK,EAAE,WAAW;IAClB,aAAa,EAAE,gBAAgB;CAChC,CAAC","sourcesContent":["import van from \"vanjs-core\";\nimport type { Widget } from \"../types.js\";\nimport { resolve } from \"../theme.js\";\nimport { basicWidgets } from \"./basic.js\";\nimport { choiceWidgets } from \"./choice.js\";\nimport { dateWidget } from \"./date.js\";\nimport { codeWidget } from \"./code.js\";\nimport { fileWidget } from \"./file.js\";\nimport { arrayWidget, groupArrayWidget } from \"./array.js\";\n\nconst { fieldset, legend } = van.tags;\n\nconst fieldsetWidget: Widget = (ctx) =>\n fieldset(\n { class: ctx.theme.fieldset || \"\" },\n legend({ class: resolve(ctx.field.titleClass, ctx.theme.legend || ctx.theme.label) }, ctx.field.label ?? \"\"),\n ctx.description(),\n ...ctx.renderChildren(),\n ctx.errorMessage(),\n );\n\n/** Built-in widgets, keyed by input type. A `widgets` entry passed to `jsform()` overrides any of them. */\nexport const builtinWidgets: Record<string, Widget> = {\n ...basicWidgets,\n ...choiceWidgets,\n date: dateWidget,\n code: codeWidget,\n file: fileWidget,\n fieldset: fieldsetWidget,\n array: arrayWidget,\n \"group-array\": groupArrayWidget,\n};\n"]}
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"form",
|
|
9
9
|
"ui-library"
|
|
10
10
|
],
|
|
11
|
-
"version": "0.6.
|
|
11
|
+
"version": "0.6.1",
|
|
12
12
|
"author": {
|
|
13
13
|
"name": "Carlos Prados",
|
|
14
14
|
"email": "carlos.prados@gmail.com"
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"lint": "eslint lib/",
|
|
29
29
|
"lint:fix": "eslint lib/ --fix",
|
|
30
30
|
"test": "vitest run",
|
|
31
|
-
"test:watch": "vitest"
|
|
31
|
+
"test:watch": "vitest",
|
|
32
|
+
"test:pack": "scripts/pack-smoke.sh"
|
|
32
33
|
},
|
|
33
34
|
"dependencies": {
|
|
34
35
|
"@codemirror/lang-javascript": "^6.2.5",
|