Skip to content

Commit 7bc1787

Browse files
committed
docs: better TypeScript
1 parent 785cc0e commit 7bc1787

File tree

1 file changed

+63
-15
lines changed

1 file changed

+63
-15
lines changed

README.md

Lines changed: 63 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 📝  JSON Schema Form Element
22

3-
_Effortless forms_, with **standards**.
3+
Effortless forms, with standards.
44

55
**Features**:
66

@@ -26,7 +26,8 @@ See also the [inspirations](#acknowledgements) for this project.
2626
<div align="center">
2727

2828
Jump to **implementations**:
29-
[Vanilla JS / Astro (SSR)](#vanilla-js--astro-ssr)
29+
[TypeScript](#typescript-no-framework)
30+
[Astro (SSR)](#astro-ssr)
3031
[Lit](#lit)
3132
[Solid](#solid)
3233
[Vue](#vue)
@@ -69,7 +70,8 @@ Jump to **implementations**:
6970
- [Usage](#usage)
7071
- [Installation](#installation)
7172
- [Implementation](#implementation)
72-
- [Vanilla JS / Astro (SSR)](#vanilla-js--astro-ssr)
73+
- [TypeScript (no framework)](#typescript-no-framework)
74+
- [Astro (SSR)](#astro-ssr)
7375
- [Lit](#lit)
7476
- [Extended example](#extended-example)
7577
- [Solid](#solid)
@@ -82,6 +84,8 @@ Jump to **implementations**:
8284
- [Custom widgets](#custom-widgets)
8385
- [Validation](#validation)
8486
- [Schema massaging](#schema-massaging)
87+
- [Custom Elements Manifests](#custom-elements-manifests)
88+
- [Experimental features](#experimental-features)
8589
- [Improvements](#improvements)
8690
- [Acknowledgements](#acknowledgements)
8791

@@ -488,7 +492,11 @@ items:
488492
### Installation
489493
490494
```sh
495+
npm i @jsfe/core
496+
# or
491497
pnpm i @jsfe/core
498+
# or
499+
yarn add @jsfe/core
492500
```
493501

494502
```ts
@@ -500,6 +508,8 @@ import '@shoelace-style/shoelace/dist/themes/light.css';
500508
import '@shoelace-style/shoelace/dist/themes/dark.css';
501509
```
502510

511+
See also the [CSS section](#CSS).
512+
503513
### Implementation
504514

505515
> **Note**
@@ -516,17 +526,27 @@ npm i
516526
npm run dev
517527
```
518528

519-
#### Vanilla JS / Astro (SSR)
529+
#### TypeScript (no framework)
530+
531+
See [examples/src/components/TypeScriptOnly.ts](https://github.com/json-schema-form-element/examples/blob/main/src/components/TypeScriptOnly.ts)
532+
533+
**TypeScript** inference: YES.
520534

521-
See [examples/src/components/VanillaJs.ts](https://github.com/json-schema-form-element/examples/blob/main/src/components/VanillaJs.astro)
535+
#### Astro (SSR)
522536

523-
TypeScript inference: YES for client side, not for SSR (Astro JSX-y template).
537+
See [examples/src/components/AstroJs.astro](https://github.com/json-schema-form-element/examples/blob/main/src/components/AstroJs.astro)
538+
539+
**TypeScript** inference: NO.
524540

525541
#### Lit
526542

527543
See [examples/src/components/LitJs.ts](https://github.com/json-schema-form-element/examples/blob/main/src/components/LitJs.ts)
528544

529-
TypeScript inference: YES.
545+
**TypeScript** inference: YES.
546+
547+
> **Note**
548+
> Inside template literals, **methods are type-checked** correctly,
549+
> but **arguments are not inferred** automatically.
530550
531551
##### Extended example
532552

@@ -560,12 +580,12 @@ class MyApp extends LitElement {
560580
.schema=${this.schema}
561581
.uiSchema=${this.uiSchema}
562582
.data=${this.data}
563-
.onSubmit=${(data, errors) => {
564-
console.info(data, errors);
565-
}}
566-
.onDataChange=${(data) => {
583+
.onDataChange=${(newData: Pet) => {
567584
this.data = data;
568585
}}
586+
.onFormSubmit=${(newData: Pet, valid: boolean) => {
587+
console.info(data, errors);
588+
}}
569589
></json-schema-form>`;
570590

571591
render() {
@@ -592,13 +612,13 @@ class MyApp extends LitElement {
592612

593613
See [examples/src/components/SolidJs.tsx](https://github.com/json-schema-form-element/examples/blob/main/src/components/SolidJs.tsx)
594614

595-
TypeScript inference: YES.
615+
**TypeScript** inference: YES.
596616

597617
#### Vue
598618

599619
See [examples/src/components/VueJs.vue](https://github.com/json-schema-form-element/examples/blob/main/src/components/VueJs.vue)
600620

601-
TypeScript inference: NO.
621+
**TypeScript** inference: NO.
602622

603623
#### Svelte
604624

@@ -645,8 +665,8 @@ Main benefit could be to add some “missing” components in Shoelace, like
645665
combobox, complex date-time ranges, or whatever fancy widget your dreaming of.
646666

647667
For example, _React JSON Schema Form_ does support a handful of different UI libraries maintained by the community,
648-
but AFAIK, in the Web Component space only Shoelace is on par, while beeing totally FLOSS.
649-
Things are changing fast though, thanks to a growing WC ecosystem, with big names backing it up (Adobe, MS, Google, SpaceX… basically everyone).
668+
but AFAIK, in the Web Component space only Shoelace is on par, thanks its Lit backbone, all while beeing totally FLOSS.
669+
Things are changing fast though, thanks to a growing WC ecosystem, with big names backing it up (Adobe, MS, Google, IBM, SpaceX… basically everyone).
650670

651671
For now, the _JSFE_ component is one Lit Element monolith. All sub-parts are “partials“,
652672
not individual Web Components. Those snippets are wrapping the Shoelace
@@ -676,6 +696,31 @@ Only thing it does is resolving [JSON references](https://datatracker.ietf.org/d
676696
Implementation is quite simple, and because this is a much needed feature for DRY-ness, recursivity…
677697
Hopefully it's easy to bring in an advanced parser along, like the [`json-schema-ref-parser`](https://github.com/APIDevTools/json-schema-ref-parser).
678698

699+
## Custom Elements Manifests
700+
701+
See [./custom-elements.json](./custom-elements.json) & [./custom-elements.md](./custom-elements.md)
702+
703+
## Experimental features
704+
705+
To activate experimental features preview flags, just pass the `experimental` property.
706+
707+
E.g. with Lit:
708+
709+
```ts
710+
html`<json-schema-form
711+
otherProps="..."
712+
.experimental=${{
713+
'<flag>': true,
714+
// ...
715+
}}
716+
></json-schema-form>`;
717+
```
718+
719+
Actual **features flags** list:
720+
721+
- `allOf`
722+
- `oneOf`
723+
679724
## Improvements
680725

681726
- BYOC (bring your own components).
@@ -684,6 +729,9 @@ Hopefully it's easy to bring in an advanced parser along, like the [`json-schema
684729
- Layout customizations
685730
- Tests, browser based (due to the WC nature).
686731
- Tests, tests, even more tests in the field to reveal shortcomings.
732+
- Support for other UI library (MWC? FAST?)
733+
-
734+
- Have an idea? [Discussions are open](https://github.com/json-schema-form-element/core/discussions)!
687735

688736
## Acknowledgements
689737

0 commit comments

Comments
 (0)