|
| 1 | +import { Form, JsonSchemaFormElement, WidgetTree } from '@jsfe/generics/form'; |
| 2 | +import { html } from '@lit-labs/signals'; |
| 3 | +import { css, unsafeCSS } from 'lit'; |
| 4 | + |
| 5 | +// import { styles } from './styles.js'; |
| 6 | +import * as widgets from './widgets/index.js'; |
| 7 | + |
| 8 | +// import styles from '@jsfe/webawesome/css?inline'; |
| 9 | + |
| 10 | +export class JsonSchemaFormWebawesome extends JsonSchemaFormElement { |
| 11 | + // static styles = [ |
| 12 | + // // unsafeCSS(styles), |
| 13 | + // // To be populated by user |
| 14 | + // /* styles */ |
| 15 | + // css` |
| 16 | + // * { |
| 17 | + // display: none; |
| 18 | + // /* */ |
| 19 | + // } |
| 20 | + // `, |
| 21 | + // ]; |
| 22 | + |
| 23 | + static readonly tagName = 'jsf-webawesome'; |
| 24 | + |
| 25 | + widgets = widgets; |
| 26 | + |
| 27 | + render() { |
| 28 | + // return html`hello`; |
| 29 | + |
| 30 | + // console.log(this.schema); |
| 31 | + |
| 32 | + if (!this.form) return html`No form`; |
| 33 | + |
| 34 | + return html` |
| 35 | + FORM WA |
| 36 | + <details> |
| 37 | + <pre>${JSON.stringify(this.schema, null, 2)}</pre> |
| 38 | + <pre>${JSON.stringify(this.form.rootField, null, 2)}</pre> |
| 39 | + </details> |
| 40 | +
|
| 41 | + ${Form({ |
| 42 | + children: html` |
| 43 | + <!-- --> |
| 44 | + ${WidgetTree({ |
| 45 | + rootField: this.form.rootField, |
| 46 | + widgets: this.widgets, |
| 47 | + })} |
| 48 | +
|
| 49 | + <!-- --> |
| 50 | + ${this.widgets.Submit({})} |
| 51 | +
|
| 52 | + <!-- --> |
| 53 | + `, |
| 54 | + form: this.form, |
| 55 | + })} |
| 56 | +
|
| 57 | + <!-- --> |
| 58 | + `; |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +// /* eslint-disable max-classes-per-file */ |
| 63 | +// // import { Jsf } from '@jsfe/engine'; |
| 64 | +// import * as widgets from './widgets/index.js'; |
| 65 | +// import { styles } from './styles.js'; |
| 66 | +// import { customElement, property } from 'lit/decorators.js'; |
| 67 | +// import { html, LitElement, type TemplateResult } from 'lit'; |
| 68 | +// import { JSONSchemaForm } from '@jsfe/engine'; |
| 69 | +// import type { Field } from '@jsfe/engine/core/src/exp-types.js'; |
| 70 | + |
| 71 | +// // export class JsfFormWa extends Jsf { |
| 72 | +// // public widgets = widgets; |
| 73 | + |
| 74 | +// // public styleSheets = [styles]; |
| 75 | +// // } |
| 76 | + |
| 77 | +// // @customElement('jsfe-form-wa') |
| 78 | +// export class JsfeFormWa extends LitElement { |
| 79 | +// @property({ type: Object }) form: JSONSchemaForm = new JSONSchemaForm({}); |
| 80 | + |
| 81 | +// public static Field(field: Field): TemplateResult | TemplateResult[] { |
| 82 | +// const widgetType = field.widget; |
| 83 | +// console.log({ widgetType }); |
| 84 | + |
| 85 | +// if (widgetType && widgetType in widgets) { |
| 86 | +// let children = undefined; |
| 87 | +// if (field.children) |
| 88 | +// children = |
| 89 | +// field.children?.map((child) => JsfeFormWa.Field(child)) ?? []; |
| 90 | +// const fieldContent = |
| 91 | +// widgetType && widgets[widgetType]?.({ ...field, children }); |
| 92 | + |
| 93 | +// return html` |
| 94 | +// <slot name=${field.html?.name || '_'}>${fieldContent} </slot> |
| 95 | +// `; |
| 96 | +// } |
| 97 | + |
| 98 | +// return html`Missing ${widgetType}`; |
| 99 | +// } |
| 100 | + |
| 101 | +// render() { |
| 102 | +// // ${JSON.stringify(this.form.fields)} |
| 103 | +// return html` |
| 104 | +// FORM WA |
| 105 | +// <form |
| 106 | +// @submit=${(event: SubmitEvent) => { |
| 107 | +// console.log(event); |
| 108 | + |
| 109 | +// const { json } = this.form.handleFormSubmit(event); |
| 110 | +// console.log({ json }); |
| 111 | +// }} |
| 112 | +// @input=${(event: InputEvent) => this.form.handleFormEvent(event)} |
| 113 | +// @change=${(event: InputEvent) => this.form.handleFormEvent(event)} |
| 114 | +// > |
| 115 | +// ${JsfeFormWa.Field(this.form.root)} |
| 116 | + |
| 117 | +// <button type="submit">OK</button> |
| 118 | +// </form> |
| 119 | +// <!-- --> |
| 120 | +// `; |
| 121 | +// // ${this.form.field['CustomWidgets.MyCustomWidgetBigButton'].type} |
| 122 | +// } |
| 123 | + |
| 124 | +// static styles = []; |
| 125 | +// } |
| 126 | + |
| 127 | +declare global { |
| 128 | + interface HTMLElementTagNameMap { |
| 129 | + 'jsf-webawesome': JsonSchemaFormWebawesome; |
| 130 | + } |
| 131 | +} |
0 commit comments