@theoremjs/react 0.3.5-next.949.gac4d2f6 → 0.3.5-next.951.gc40a24e
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/package.json +3 -3
- package/ui/SchemaFields.js +56 -3
- package/ui/labels.d.ts +8 -0
- package/ui/labels.js +8 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@theoremjs/react",
|
|
3
|
-
"version": "0.3.5-next.
|
|
3
|
+
"version": "0.3.5-next.951.gc40a24e",
|
|
4
4
|
"description": "React bindings for Theorem: headless hooks + transport, an Astryx chat UI, and a Web-standard server handler.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -60,8 +60,8 @@
|
|
|
60
60
|
"@stylexjs/stylex": "0.19.0",
|
|
61
61
|
"react": "^19.0.0",
|
|
62
62
|
"react-dom": "^19.0.0",
|
|
63
|
-
"@theoremjs/agents": "^0.3.5-next.
|
|
64
|
-
"@theoremjs/web": "^0.3.5-next.
|
|
63
|
+
"@theoremjs/agents": "^0.3.5-next.951.gc40a24e",
|
|
64
|
+
"@theoremjs/web": "^0.3.5-next.951.gc40a24e"
|
|
65
65
|
},
|
|
66
66
|
"peerDependenciesMeta": {
|
|
67
67
|
"@astryxdesign/core": {
|
package/ui/SchemaFields.js
CHANGED
|
@@ -14,7 +14,7 @@ import { TextArea } from '@astryxdesign/core/TextArea';
|
|
|
14
14
|
import { TextInput } from '@astryxdesign/core/TextInput';
|
|
15
15
|
import { Tokenizer } from '@astryxdesign/core/Tokenizer';
|
|
16
16
|
import { VStack } from '@astryxdesign/core/VStack';
|
|
17
|
-
import { blankRow, isRow, json, schemaFields, withField, } from '@theoremjs/web/client';
|
|
17
|
+
import { blankRow, branchField, branchSample, branchValue, chosenBranch, inBranch, isRow, json, schemaControl, schemaFields, withField, } from '@theoremjs/web/client';
|
|
18
18
|
import { useState } from 'react';
|
|
19
19
|
import { useLabels } from "./labels-provider.js";
|
|
20
20
|
import { useKeyedRows } from "./row-keys.js";
|
|
@@ -90,6 +90,33 @@ function WordsField({ field, value, onChange }) {
|
|
|
90
90
|
? Number(item.label)
|
|
91
91
|
: item.label)) }));
|
|
92
92
|
}
|
|
93
|
+
/** The shapes to pick from: segments when they are few and short, else a menu. */
|
|
94
|
+
function BranchPicker({ label, labels, isMenu, value, onPick, }) {
|
|
95
|
+
if (isMenu) {
|
|
96
|
+
return _jsx(Selector, { label: label, size: "sm", options: labels, value: value, onChange: onPick });
|
|
97
|
+
}
|
|
98
|
+
return (_jsx(HStack, { children: _jsx(SegmentedControl, { label: label, size: "sm", value: value ?? '', onChange: onPick, children: labels.map((each) => (_jsx(SegmentedControlItem, { value: each, label: each }, each))) }) }));
|
|
99
|
+
}
|
|
100
|
+
/** A field that holds other fields, under its label and description. */
|
|
101
|
+
function FieldGroup({ field, children }) {
|
|
102
|
+
return (_jsx(Group, { label: field.label, isRequired: field.isRequired, description: field.description && _jsx(Description, { text: field.description }), children: children }));
|
|
103
|
+
}
|
|
104
|
+
/** Which shape a value takes, then what that shape asks for. Picking one starts it at its sample. */
|
|
105
|
+
function BranchFields({ label, branches, isMenu, value, onChange, }) {
|
|
106
|
+
const chosen = chosenBranch(branches, value);
|
|
107
|
+
const pick = (next) => {
|
|
108
|
+
const branch = branches.find((each) => each.label === next);
|
|
109
|
+
if (branch && branch !== chosen)
|
|
110
|
+
onChange(branchSample(branch));
|
|
111
|
+
};
|
|
112
|
+
const picker = (_jsx(BranchPicker, { label: label, labels: branches.map((branch) => branch.label), isMenu: isMenu, value: chosen?.label, onPick: pick }));
|
|
113
|
+
if (!chosen)
|
|
114
|
+
return picker;
|
|
115
|
+
const body = branchField(chosen);
|
|
116
|
+
const edit = (next) => onChange(inBranch(chosen, next));
|
|
117
|
+
const current = branchValue(chosen, value);
|
|
118
|
+
return (_jsxs(VStack, { gap: 3, children: [picker, body.control.kind === 'group' ? (_jsx(ObjectFields, { schema: body.control.schema, value: isRow(current) ? current : {}, onChange: edit })) : (_jsx(Field, { field: body, value: current, onChange: edit }))] }));
|
|
119
|
+
}
|
|
93
120
|
/** Each control's input, as the schema asks for it. */
|
|
94
121
|
const CONTROLS = {
|
|
95
122
|
choice: ({ field, control, value, onChange }) => (_jsx(ChoiceField, { field: field, options: control.options, isMenu: control.isMenu, value: value, onChange: onChange })),
|
|
@@ -103,18 +130,39 @@ const CONTROLS = {
|
|
|
103
130
|
: [], onChange: onChange, children: control.options.map((option) => (_jsx(CheckboxListItem, { label: option, value: option }, option))) })),
|
|
104
131
|
words: ({ field, value, onChange }) => (_jsx(WordsField, { field: field, value: value, onChange: onChange })),
|
|
105
132
|
rows: ({ field, control, value, onChange }) => (_jsx(RowsField, { field: field, item: control.item, value: value, onChange: onChange })),
|
|
106
|
-
group: ({ field, control, value, onChange }) => (_jsx(
|
|
133
|
+
group: ({ field, control, value, onChange }) => (_jsx(FieldGroup, { field: field, children: _jsx(ObjectFields, { schema: control.schema, value: isRow(value) ? value : {}, onChange: onChange }) })),
|
|
134
|
+
branches: ({ field, control, value, onChange }) => (_jsx(FieldGroup, { field: field, children: _jsx(BranchFields, { label: field.label, branches: control.branches, isMenu: control.isMenu, value: value, onChange: onChange }) })),
|
|
107
135
|
json: ({ field, value, onChange }) => (_jsx(JsonField, { field: field, value: value, onChange: onChange })),
|
|
108
136
|
};
|
|
109
137
|
function Field({ field, value, onChange }) {
|
|
138
|
+
if (field.isNullable)
|
|
139
|
+
return _jsx(NullableField, { field: field, value: value, onChange: onChange });
|
|
140
|
+
return _jsx(FieldInput, { field: field, value: value, onChange: onChange });
|
|
141
|
+
}
|
|
142
|
+
function FieldInput({ field, value, onChange }) {
|
|
110
143
|
const control = CONTROLS[field.control.kind];
|
|
111
144
|
const input = control({ field, control: field.control, value, onChange });
|
|
112
145
|
// why: A group already says its description under its name.
|
|
113
|
-
const isGroup = field.control.kind === 'rows' ||
|
|
146
|
+
const isGroup = field.control.kind === 'rows' ||
|
|
147
|
+
field.control.kind === 'group' ||
|
|
148
|
+
field.control.kind === 'branches';
|
|
114
149
|
if (!field.description || isGroup)
|
|
115
150
|
return input;
|
|
116
151
|
return (_jsxs(VStack, { gap: 1, children: [input, _jsx(Description, { text: field.description })] }));
|
|
117
152
|
}
|
|
153
|
+
/**
|
|
154
|
+
* A field that also takes null: its own input, and a switch that sends null instead. Turning the
|
|
155
|
+
* switch off leaves the field out, so null is sent only when asked for.
|
|
156
|
+
*/
|
|
157
|
+
function NullableField({ field, value, onChange }) {
|
|
158
|
+
const t = useLabels();
|
|
159
|
+
const isNull = value === null;
|
|
160
|
+
const toggle = (_jsx(Switch, { label: t('@theorem.decision.send_null'), value: isNull, onChange: (on) => onChange(on ? null : undefined) }));
|
|
161
|
+
if (isNull) {
|
|
162
|
+
return (_jsx(Labelled, { label: field.label, isRequired: field.isRequired, children: toggle }));
|
|
163
|
+
}
|
|
164
|
+
return (_jsxs(VStack, { gap: 1, children: [_jsx(FieldInput, { field: field, value: value, onChange: onChange }), toggle] }));
|
|
165
|
+
}
|
|
118
166
|
/** Room a short field takes: numbers, dates, menus, and one-line text sit side by side. */
|
|
119
167
|
const SHORT_FIELD_PX = 200;
|
|
120
168
|
/** Segments whose labels run this long in all still fit a short field's width. */
|
|
@@ -145,5 +193,10 @@ function ObjectFields({ schema, value, onChange, }) {
|
|
|
145
193
|
* description. Optional fields left empty aren't sent.
|
|
146
194
|
*/
|
|
147
195
|
export function SchemaFields({ schema, value, onChange, }) {
|
|
196
|
+
const t = useLabels();
|
|
197
|
+
const control = schemaControl(schema);
|
|
198
|
+
if (control.kind === 'branches') {
|
|
199
|
+
return (_jsx(BranchFields, { label: t('@theorem.decision.shape'), branches: control.branches, isMenu: control.isMenu, value: value, onChange: (next) => onChange(isRow(next) ? next : {}) }));
|
|
200
|
+
}
|
|
148
201
|
return _jsx(ObjectFields, { schema: schema, value: value, onChange: onChange });
|
|
149
202
|
}
|
package/ui/labels.d.ts
CHANGED
|
@@ -482,6 +482,14 @@ export declare const THEOREM_UI_CATALOG: {
|
|
|
482
482
|
readonly defaultMessage: "Add a value";
|
|
483
483
|
readonly description: "A list of words in the state, while it is empty.";
|
|
484
484
|
};
|
|
485
|
+
readonly '@theorem.decision.send_null': {
|
|
486
|
+
readonly defaultMessage: "Send null";
|
|
487
|
+
readonly description: "Sends the JSON null for a field that takes it, instead of leaving the field out.";
|
|
488
|
+
};
|
|
489
|
+
readonly '@theorem.decision.shape': {
|
|
490
|
+
readonly defaultMessage: "Kind";
|
|
491
|
+
readonly description: "Picks which of its shapes a request takes, for a tool whose input is one of several.";
|
|
492
|
+
};
|
|
485
493
|
readonly '@theorem.decision.invalid_json': {
|
|
486
494
|
readonly defaultMessage: "Not valid JSON yet";
|
|
487
495
|
readonly description: "The state doesn't parse.";
|
package/ui/labels.js
CHANGED
|
@@ -445,6 +445,14 @@ export const THEOREM_UI_CATALOG = {
|
|
|
445
445
|
defaultMessage: 'Add a value',
|
|
446
446
|
description: 'A list of words in the state, while it is empty.',
|
|
447
447
|
},
|
|
448
|
+
'@theorem.decision.send_null': {
|
|
449
|
+
defaultMessage: 'Send null',
|
|
450
|
+
description: 'Sends the JSON null for a field that takes it, instead of leaving the field out.',
|
|
451
|
+
},
|
|
452
|
+
'@theorem.decision.shape': {
|
|
453
|
+
defaultMessage: 'Kind',
|
|
454
|
+
description: 'Picks which of its shapes a request takes, for a tool whose input is one of several.',
|
|
455
|
+
},
|
|
448
456
|
'@theorem.decision.invalid_json': {
|
|
449
457
|
defaultMessage: 'Not valid JSON yet',
|
|
450
458
|
description: "The state doesn't parse.",
|