diff --git a/src/controls/IWidget.ts b/src/controls/IWidget.ts index 2ddabbcbd..5bc8adac0 100644 --- a/src/controls/IWidget.ts +++ b/src/controls/IWidget.ts @@ -31,4 +31,5 @@ export type ReqInput = X & { i18n?: { [key: string]: string } className?: string startCollapsed?: boolean + showID?: boolean } diff --git a/src/controls/Widget.ts b/src/controls/Widget.ts index 474c8122a..32977df0a 100644 --- a/src/controls/Widget.ts +++ b/src/controls/Widget.ts @@ -790,7 +790,7 @@ export class Widget_imageOpt implements IRequest<'imageOpt', Widget_imageOpt_opt // 🅿️ selectOne ============================================================================== export type BaseSelectOneEntry = { id: string, label?: string } -export type Widget_selectOne_opts = ReqInput<{ default?: T; choices: T[] | ((formRoot:Widget_group) => T[]) }> +export type Widget_selectOne_opts = ReqInput<{ default?: T; choices: T[] | ((formRoot:Maybe>) => T[]) }> export type Widget_selectOne_serial = Widget_selectOne_state export type Widget_selectOne_state = StateFields<{ type:'selectOne', query: string; val: T }> export type Widget_selectOne_output = T @@ -932,7 +932,7 @@ export class Widget_selectManyOrCustom implements IRequest<'selectManyOrCustom', // 🅿️ list ============================================================================== export type Widget_list_opts = ReqInput<{ - element: () => T, + element: (ix:number) => T, min?: number, max?:number, defaultLength?:number @@ -948,6 +948,7 @@ export class Widget_list implements IRequest<'list', Widget_li state: Widget_list_state private _reference: T + get items(): T[] { return this.state.items } constructor( public builder: FormBuilder, public schema: SchemaL, @@ -955,7 +956,7 @@ export class Widget_list implements IRequest<'list', Widget_li serial?: Widget_list_serial, ) { this.id = serial?.id ?? nanoid() - this._reference = input.element() + this._reference = input.element(0) if (serial) { const items = serial.items_.map((sub_) => builder._HYDRATE(sub_.type, this._reference.input, sub_)) // 🔴 handler filter if wrong type this.state = { type: 'list', id: this.id, active: serial.active, items } @@ -963,7 +964,7 @@ export class Widget_list implements IRequest<'list', Widget_li const clamp = (v: number, min: number, max: number) => Math.min(Math.max(v, min), max) const defaultLen = clamp(input.defaultLength ?? 0, input.min ?? 0, input.max ?? 10) const items = defaultLen - ? new Array(defaultLen).fill(0).map(() => input.element()) + ? new Array(defaultLen).fill(0).map((_,ix) => input.element(ix)) : [] this.state = { type: 'list', @@ -994,7 +995,7 @@ export class Widget_list implements IRequest<'list', Widget_li addItem() { // const _ref = this._reference // const newItem = this.builder.HYDRATE(_ref.type, _ref.input) - this.state.items.push(this.input.element()) + this.state.items.push(this.input.element(this.state.items.length)) } } @@ -1138,6 +1139,10 @@ export class Widget_group implements IReque id: string type: 'group' = 'group' state: Widget_group_state + /** all [key,value] pairs */ + get entries() { return Object.entries(this.state.values) as [keyof T, T[keyof T]][] } + /** the dict of all child widgets */ + get values() { return this.state.values } constructor( public builder: FormBuilder, public schema: SchemaL, @@ -1199,6 +1204,10 @@ export class Widget_groupOpt implements IRe id: string type: 'groupOpt' = 'groupOpt' state: Widget_groupOpt_state + /** all [key,value] pairs */ + get entries() { return Object.entries(this.state.values) as [keyof T, T[keyof T]][] } + /** the dict of all child widgets */ + get values() { return this.state.values } constructor( public builder: FormBuilder, public schema: SchemaL, @@ -1285,6 +1294,11 @@ export class Widget_choice implements } makeAutoObservable(this) } + + get pick() { return this.state.pick } + get child(){ + return this.state.values[this.state.pick] + } get serial(): Widget_choice_serial { const out: { [key: string]: any } = {} for (const key in this.state.values) out[key] = this.state.values[key].serial diff --git a/src/controls/widgets/WidgetListUI.tsx b/src/controls/widgets/WidgetListUI.tsx index 8a6d398b3..ce3a3e645 100644 --- a/src/controls/widgets/WidgetListUI.tsx +++ b/src/controls/widgets/WidgetListUI.tsx @@ -30,15 +30,15 @@ export const WidgetListUI = observer(function WidgetListUI_(p: - + ))} @@ -52,7 +52,7 @@ const ListDragHandleUI = forwardRef((props, ref) return (
-
+
menu
{props.ix}
@@ -67,7 +67,7 @@ export const ListItemCollapseBtnUI = observer(function ListItemCollapseBtnUI_(p: if (!isCollapsible) return null return (
(v.state.collapsed = !Boolean(v.state.collapsed))} >