@shwfed/config 2.1.1 → 2.2.0

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.
Files changed (41) hide show
  1. package/dist/module.json +1 -1
  2. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.form/config.d.vue.ts +8 -2
  3. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.form/config.vue.d.ts +8 -2
  4. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.form/runtime.d.vue.ts +8 -2
  5. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.form/runtime.vue.d.ts +8 -2
  6. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.form/schema.d.ts +8 -2
  7. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.table/config.d.vue.ts +8 -2
  8. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.table/config.vue.d.ts +8 -2
  9. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.table/runtime.d.vue.ts +8 -2
  10. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.table/runtime.vue.d.ts +8 -2
  11. package/dist/runtime/components/config/blocks/2026-05-06/com.shwfed.block.table/schema.d.ts +12 -3
  12. package/dist/runtime/components/form/config.vue +36 -5
  13. package/dist/runtime/components/form/fields/2026-05-12/com.shwfed.form.field.upload/config.d.vue.ts +8 -2
  14. package/dist/runtime/components/form/fields/2026-05-12/com.shwfed.form.field.upload/config.vue +51 -15
  15. package/dist/runtime/components/form/fields/2026-05-12/com.shwfed.form.field.upload/config.vue.d.ts +8 -2
  16. package/dist/runtime/components/form/fields/2026-05-12/com.shwfed.form.field.upload/runtime.vue +16 -5
  17. package/dist/runtime/components/form/fields/2026-05-12/com.shwfed.form.field.upload/schema.d.ts +9 -1
  18. package/dist/runtime/components/form/fields/2026-05-12/com.shwfed.form.field.upload/schema.js +25 -4
  19. package/dist/runtime/components/form/fields/2026-05-13/com.shwfed.form.field.combobox.single.remote/config.d.vue.ts +2 -2
  20. package/dist/runtime/components/form/fields/2026-05-13/com.shwfed.form.field.combobox.single.remote/config.vue.d.ts +2 -2
  21. package/dist/runtime/components/form/fields/2026-05-13/com.shwfed.form.field.list/config.d.vue.ts +14 -0
  22. package/dist/runtime/components/form/fields/2026-05-13/com.shwfed.form.field.list/config.vue +22 -0
  23. package/dist/runtime/components/form/fields/2026-05-13/com.shwfed.form.field.list/config.vue.d.ts +14 -0
  24. package/dist/runtime/components/form/fields/2026-05-13/com.shwfed.form.field.list/runtime.vue +110 -22
  25. package/dist/runtime/components/form/fields/2026-05-13/com.shwfed.form.field.list/schema.d.ts +14 -0
  26. package/dist/runtime/components/form/fields/2026-05-13/com.shwfed.form.field.list/schema.js +4 -0
  27. package/dist/runtime/components/form/index.vue +4 -1
  28. package/dist/runtime/components/form/schema.d.ts +14 -4
  29. package/dist/runtime/components/form/schema.js +30 -10
  30. package/dist/runtime/components/form/utils/initial.d.ts +26 -0
  31. package/dist/runtime/components/form/utils/initial.js +11 -0
  32. package/dist/runtime/components/table/index.vue +3 -1
  33. package/dist/runtime/components/table/schema.d.ts +16 -4
  34. package/dist/runtime/utils/interpolate.d.ts +1 -0
  35. package/dist/runtime/utils/interpolate.js +7 -0
  36. package/dist/runtime/vendor/cel-js/CLAUDE.md +1 -1
  37. package/dist/runtime/vendor/cel-js/PROMPT.md +3 -7
  38. package/dist/runtime/vendor/cel-js/lib/http-builder.d.ts +4 -3
  39. package/dist/runtime/vendor/cel-js/lib/http-builtins.d.ts +3 -3
  40. package/dist/runtime/vendor/cel-js/lib/http-builtins.js +0 -4
  41. package/package.json +1 -1
@@ -33,12 +33,12 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {},
33
33
  readonly message: string;
34
34
  }[]] | undefined;
35
35
  readonly readonly?: string | undefined;
36
+ readonly request: string;
36
37
  readonly binding?: string | undefined;
37
38
  readonly derived?: {
38
39
  readonly mode: "formula" | "prefill";
39
40
  readonly expression: string;
40
41
  } | undefined;
41
- readonly request: string;
42
42
  readonly options: string;
43
43
  readonly optionValue: string;
44
44
  readonly optionLabel: readonly [{
@@ -80,12 +80,12 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {},
80
80
  readonly message: string;
81
81
  }[]] | undefined;
82
82
  readonly readonly?: string | undefined;
83
+ readonly request: string;
83
84
  readonly binding?: string | undefined;
84
85
  readonly derived?: {
85
86
  readonly mode: "formula" | "prefill";
86
87
  readonly expression: string;
87
88
  } | undefined;
88
- readonly request: string;
89
89
  readonly options: string;
90
90
  readonly optionValue: string;
91
91
  readonly optionLabel: readonly [{
@@ -22,6 +22,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {},
22
22
  readonly locale: "en" | "ja" | "ko";
23
23
  readonly message: string;
24
24
  }[]] | undefined;
25
+ readonly locale?: readonly [{
26
+ readonly locale: "zh";
27
+ readonly message: string;
28
+ }, ...{
29
+ readonly locale: "en" | "ja" | "ko";
30
+ readonly message: string;
31
+ }[]] | undefined;
25
32
  readonly displayName?: string | undefined;
26
33
  readonly compatibilityDate: "2026-05-13";
27
34
  readonly min?: number | undefined;
@@ -71,6 +78,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {},
71
78
  readonly locale: "en" | "ja" | "ko";
72
79
  readonly message: string;
73
80
  }[]] | undefined;
81
+ readonly locale?: readonly [{
82
+ readonly locale: "zh";
83
+ readonly message: string;
84
+ }, ...{
85
+ readonly locale: "en" | "ja" | "ko";
86
+ readonly message: string;
87
+ }[]] | undefined;
74
88
  readonly displayName?: string | undefined;
75
89
  readonly compatibilityDate: "2026-05-13";
76
90
  readonly min?: number | undefined;
@@ -233,6 +233,28 @@ const reorderable = computed({
233
233
  </Field>
234
234
  </div>
235
235
 
236
+ <Field orientation="vertical">
237
+ <FieldLabel class="text-xs text-zinc-500">
238
+ <template
239
+ v-if="fieldDescription('locale')"
240
+ #tooltip
241
+ >
242
+ <Markdown
243
+ :source="fieldDescription('locale')"
244
+ block
245
+ class="prose prose-sm prose-zinc"
246
+ />
247
+ </template>
248
+ {{ fieldTitle("locale") }}
249
+ </FieldLabel>
250
+ <LocaleField
251
+ markdown
252
+ translate-hint="列表项折叠摘要,Markdown 文本,保留表达式插值占位符不要翻译"
253
+ :model-value="value.locale"
254
+ @update:model-value="(v) => value = { ...value, locale: v }"
255
+ />
256
+ </Field>
257
+
236
258
  <div class="grid grid-cols-3 gap-3">
237
259
  <Field orientation="vertical">
238
260
  <FieldLabel class="text-xs text-zinc-500">
@@ -22,6 +22,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {},
22
22
  readonly locale: "en" | "ja" | "ko";
23
23
  readonly message: string;
24
24
  }[]] | undefined;
25
+ readonly locale?: readonly [{
26
+ readonly locale: "zh";
27
+ readonly message: string;
28
+ }, ...{
29
+ readonly locale: "en" | "ja" | "ko";
30
+ readonly message: string;
31
+ }[]] | undefined;
25
32
  readonly displayName?: string | undefined;
26
33
  readonly compatibilityDate: "2026-05-13";
27
34
  readonly min?: number | undefined;
@@ -71,6 +78,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_ModelProps, {},
71
78
  readonly locale: "en" | "ja" | "ko";
72
79
  readonly message: string;
73
80
  }[]] | undefined;
81
+ readonly locale?: readonly [{
82
+ readonly locale: "zh";
83
+ readonly message: string;
84
+ }, ...{
85
+ readonly locale: "en" | "ja" | "ko";
86
+ readonly message: string;
87
+ }[]] | undefined;
74
88
  readonly displayName?: string | undefined;
75
89
  readonly compatibilityDate: "2026-05-13";
76
90
  readonly min?: number | undefined;
@@ -5,6 +5,7 @@ import { computed, ref, watch } from "vue";
5
5
  import { useI18n } from "vue-i18n";
6
6
  import { cel as _rawCel } from "../../../../../utils/cel";
7
7
  import { celBindings, injectCELContext } from "../../../../../utils/cel-context";
8
+ import { interpolate } from "../../../../../utils/interpolate";
8
9
  import { getLocalizedText } from "../../../../../share/locale";
9
10
  import {
10
11
  useTreeDnd
@@ -31,6 +32,8 @@ const tooltipText = computed(
31
32
  const addLabelText = computed(
32
33
  () => getLocalizedText(props.config.addLabel, locale.value) || "\u65B0\u589E"
33
34
  );
35
+ const summaryTemplate = computed(() => getLocalizedText(props.config.locale, locale.value));
36
+ const collapsible = computed(() => !!summaryTemplate.value);
34
37
  function evalBool(expression, label) {
35
38
  if (!expression) return false;
36
39
  try {
@@ -50,6 +53,28 @@ const items = computed(() => {
50
53
  if (!Array.isArray(raw)) return [];
51
54
  return raw;
52
55
  });
56
+ const rowSummaries = computed(() => {
57
+ const template = summaryTemplate.value;
58
+ if (template == null) return [];
59
+ return items.value.map(
60
+ (item, i) => interpolate(template, (expression) => {
61
+ try {
62
+ const out = Effect.runSync($cel(expression, {
63
+ form: state.value ?? {},
64
+ item: item ?? {},
65
+ index: i
66
+ }));
67
+ return out == null ? "" : String(out);
68
+ } catch (err) {
69
+ console.error(
70
+ `[shwfed-form] list field: failed to evaluate summary expression \`${expression}\` for ${props.fieldId}[${i}]:`,
71
+ err
72
+ );
73
+ return "";
74
+ }
75
+ })
76
+ );
77
+ });
53
78
  function writeItems(next) {
54
79
  const path = props.config.binding;
55
80
  if (path == null) {
@@ -74,6 +99,16 @@ watch(
74
99
  },
75
100
  { immediate: true }
76
101
  );
102
+ const expandedKeys = ref(/* @__PURE__ */ new Set());
103
+ function isExpanded(key) {
104
+ return expandedKeys.value.has(key);
105
+ }
106
+ function toggleExpanded(key) {
107
+ const next = new Set(expandedKeys.value);
108
+ if (next.has(key)) next.delete(key);
109
+ else next.add(key);
110
+ expandedKeys.value = next;
111
+ }
77
112
  const atMax = computed(
78
113
  () => props.config.max != null && items.value.length >= props.config.max
79
114
  );
@@ -86,13 +121,23 @@ const canReorder = computed(() => !isDisabled.value && reorderable.value);
86
121
  function append() {
87
122
  if (!canAdd.value) return;
88
123
  writeItems([...items.value, {}]);
89
- rowKeys.value = [...rowKeys.value, makeId()];
124
+ const id = makeId();
125
+ rowKeys.value = [...rowKeys.value, id];
126
+ const next = new Set(expandedKeys.value);
127
+ next.add(id);
128
+ expandedKeys.value = next;
90
129
  }
91
130
  function removeAt(i) {
92
131
  if (!canRemove.value) return;
93
132
  if (i < 0 || i >= items.value.length) return;
133
+ const removedKey = rowKeys.value[i];
94
134
  writeItems(items.value.filter((_, j) => j !== i));
95
135
  rowKeys.value = rowKeys.value.filter((_, j) => j !== i);
136
+ if (removedKey != null && expandedKeys.value.has(removedKey)) {
137
+ const next = new Set(expandedKeys.value);
138
+ next.delete(removedKey);
139
+ expandedKeys.value = next;
140
+ }
96
141
  }
97
142
  function moveRow(from, to) {
98
143
  if (!canReorder.value) return;
@@ -169,19 +214,74 @@ function rowConfig(i) {
169
214
  v-for="(item, i) in items"
170
215
  :key="rowKeys[i]"
171
216
  :ref="dnd.rowRef(rowId(i), rowConfig(i))"
172
- class="relative flex items-center gap-2 rounded border border-zinc-200 bg-zinc-50/40 p-3"
217
+ class="relative rounded border border-zinc-200 bg-zinc-50/40 p-3"
173
218
  data-slot="list-row"
174
219
  :data-instruction="dnd.instructionFor(rowId(i)) ?? void 0"
175
220
  >
176
- <Icon
177
- v-if="reorderable"
178
- icon="fluent:re-order-dots-vertical-20-regular"
179
- class="drag-handle size-4 shrink-0 text-zinc-400"
180
- :class="canReorder ? 'cursor-grab' : 'cursor-not-allowed opacity-50'"
181
- data-slot="list-row-drag-handle"
182
- />
221
+ <div class="flex items-center gap-2">
222
+ <Icon
223
+ v-if="reorderable"
224
+ icon="fluent:re-order-dots-vertical-20-regular"
225
+ class="drag-handle size-4 shrink-0 text-zinc-400"
226
+ :class="canReorder ? 'cursor-grab' : 'cursor-not-allowed opacity-50'"
227
+ data-slot="list-row-drag-handle"
228
+ />
229
+
230
+ <InputGroupButton
231
+ v-if="collapsible"
232
+ size="icon-xs"
233
+ class="shrink-0"
234
+ data-slot="list-row-collapse"
235
+ :aria-expanded="isExpanded(rowId(i))"
236
+ :aria-label="isExpanded(rowId(i)) ? '\u6298\u53E0' : '\u5C55\u5F00'"
237
+ @click="toggleExpanded(rowId(i))"
238
+ >
239
+ <Icon
240
+ :icon="isExpanded(rowId(i)) ? 'fluent:chevron-down-20-regular' : 'fluent:chevron-right-20-regular'"
241
+ />
242
+ </InputGroupButton>
183
243
 
184
- <div class="min-w-0 flex-1">
244
+ <div
245
+ v-if="collapsible"
246
+ class="min-w-0 flex-1"
247
+ data-slot="list-row-summary"
248
+ >
249
+ <Markdown
250
+ :source="rowSummaries[i] ?? ''"
251
+ class="prose prose-xs prose-zinc"
252
+ />
253
+ </div>
254
+ <div
255
+ v-else
256
+ class="min-w-0 flex-1"
257
+ >
258
+ <Row
259
+ :model-value="item"
260
+ :unit="config.unit"
261
+ :index="i"
262
+ @update:model-value="(next) => updateRow(i, next)"
263
+ />
264
+ </div>
265
+
266
+ <InputGroupButton
267
+ variant="destructive"
268
+ size="icon-xs"
269
+ class="shrink-0"
270
+ :disabled="!canRemove"
271
+ data-slot="list-row-remove"
272
+ aria-label="删除"
273
+ @click="removeAt(i)"
274
+ >
275
+ <Icon icon="fluent:delete-20-regular" />
276
+ </InputGroupButton>
277
+ </div>
278
+
279
+ <div
280
+ v-if="collapsible"
281
+ v-show="isExpanded(rowId(i))"
282
+ class="mt-3 min-w-0"
283
+ data-slot="list-row-content"
284
+ >
185
285
  <Row
186
286
  :model-value="item"
187
287
  :unit="config.unit"
@@ -189,18 +289,6 @@ function rowConfig(i) {
189
289
  @update:model-value="(next) => updateRow(i, next)"
190
290
  />
191
291
  </div>
192
-
193
- <InputGroupButton
194
- variant="destructive"
195
- size="icon-xs"
196
- class="shrink-0"
197
- :disabled="!canRemove"
198
- data-slot="list-row-remove"
199
- aria-label="删除"
200
- @click="removeAt(i)"
201
- >
202
- <Icon icon="fluent:delete-20-regular" />
203
- </InputGroupButton>
204
292
  </div>
205
293
 
206
294
  <Button
@@ -36,6 +36,13 @@ export declare function schema(configure: (env: Environment) => void): Schema.re
36
36
  readonly locale: "en" | "ja" | "ko";
37
37
  readonly message: string;
38
38
  }[]] | undefined;
39
+ readonly locale?: readonly [{
40
+ readonly locale: "zh";
41
+ readonly message: string;
42
+ }, ...{
43
+ readonly locale: "en" | "ja" | "ko";
44
+ readonly message: string;
45
+ }[]] | undefined;
39
46
  readonly displayName?: string | undefined;
40
47
  readonly compatibilityDate: "2026-05-13";
41
48
  readonly min?: number | undefined;
@@ -94,6 +101,13 @@ export declare function schema(configure: (env: Environment) => void): Schema.re
94
101
  min: Schema.optional<Schema.refine<number, Schema.filter<typeof Schema.Number>>>;
95
102
  max: Schema.optional<Schema.refine<number, Schema.filter<typeof Schema.Number>>>;
96
103
  disabled: Schema.optional<Schema.Schema<string, string, never>>;
104
+ locale: Schema.optional<Schema.TupleType<readonly [Schema.Struct<{
105
+ locale: Schema.Literal<["zh"]>;
106
+ message: Schema.SchemaClass<string, string, never>;
107
+ }>], [Schema.Struct<{
108
+ locale: Schema.Literal<["ja", "en", "ko"]>;
109
+ message: Schema.SchemaClass<string, string, never>;
110
+ }>]>>;
97
111
  unit: Schema.suspend<Readonly<{
98
112
  fields: ReadonlyArray<import("../../../schema.js").FieldValue>;
99
113
  layouts: ReadonlyArray<import("../../../schema.js").LayoutSetValue>;
@@ -64,6 +64,10 @@ export function schema(configure) {
64
64
  title: "\u7981\u7528\u6761\u4EF6",
65
65
  description: "\u8FD4\u56DE `true` \u65F6\u6574\u4E2A\u5217\u8868\u53EA\u8BFB\uFF0C\u4E0D\u80FD\u65B0\u589E/\u5220\u9664/\u91CD\u6392"
66
66
  })),
67
+ locale: Schema.optional(Locale.annotations({
68
+ title: "\u5217\u8868\u9879\u6458\u8981",
69
+ description: "\u914D\u7F6E\u540E\u6BCF\u4E2A\u5217\u8868\u9879\u53EF\u6298\u53E0\uFF0C\u6298\u53E0\u65F6\u5C55\u793A\u6B64\u5904\u6587\u672C\u6E32\u67D3\u7684\u884C\u5185 Markdown \u4F5C\u4E3A\u6458\u8981\u3002\u652F\u6301 `{{ \u8868\u8FBE\u5F0F }}` \u63D2\u503C\uFF0C\u8868\u8FBE\u5F0F\u4E3A CEL\uFF0C\u53EF\u8BBF\u95EE `item`\uFF08\u5F53\u524D\u9879\uFF09\u3001`index`\uFF08\u5E8F\u53F7\uFF0C\u4ECE 0 \u5F00\u59CB\uFF09\u4E0E `form`"
70
+ })),
67
71
  unit: Unit.annotations({
68
72
  title: "\u5217\u8868\u9879\u914D\u7F6E",
69
73
  description: "\u5355\u4E2A\u5217\u8868\u9879\u7684\u5B57\u6BB5\u4E0E\u5E03\u5C40\uFF1B\u6BCF\u4E2A\u5217\u8868\u9879\u90FD\u6309\u6B64\u7ED3\u6784\u6E32\u67D3\u4E00\u4EFD"
@@ -2,6 +2,7 @@
2
2
  import { cel as _rawCel } from "../../utils/cel";
3
3
  import { TZDate } from "@date-fns/tz";
4
4
  import { Effect } from "effect";
5
+ import { Fetch } from "fx-fetch";
5
6
  import { computed, onMounted, ref, watch } from "vue";
6
7
  import {
7
8
  celBindings,
@@ -11,6 +12,7 @@ import {
11
12
  import { provideCommitBus } from "./utils/commit-bus";
12
13
  import { provideDerivedQuiescence, useDerived } from "./utils/derived";
13
14
  import { useFormHistory } from "./utils/history";
15
+ import { evaluateInitial } from "./utils/initial";
14
16
  import { provideFormReadonly } from "./utils/readonly";
15
17
  import { findField } from "./utils/resolve";
16
18
  import { provideFormState } from "./utils/state";
@@ -62,7 +64,8 @@ const seeded = (() => {
62
64
  const current = state.value ?? {};
63
65
  const initial = config.value.initial;
64
66
  if (!initial || Object.keys(current).length > 0) return Promise.resolve();
65
- return Effect.runPromise($cel(initial, { form: current })).then(
67
+ const program = evaluateInitial(initial, $cel, { form: current });
68
+ return Effect.runPromise(Effect.provide(program, Fetch.layer)).then(
66
69
  (result) => {
67
70
  if (result && typeof result === "object" && !Array.isArray(result)) {
68
71
  state.value = { ...current, ...result };
@@ -1,5 +1,6 @@
1
1
  import { Schema } from 'effect';
2
2
  import type { Environment } from '../../vendor/cel-js/lib/index.js';
3
+ import type { InitialSource } from './utils/initial.js';
3
4
  import { type LayoutSetValue } from '../../share/layout.js';
4
5
  export { commonFieldFields } from './utils/common.js';
5
6
  export { getStructFieldTitle, getStructFieldDescription } from './utils/schema-meta.js';
@@ -79,7 +80,10 @@ export declare function FormUnit(configure: (env: Environment) => void): Schema.
79
80
  */
80
81
  export declare function registerFormVariablesIfAbsent(env: Environment): void;
81
82
  export declare function FormConfig(configure: (env: Environment) => void): Schema.refine<{
82
- readonly initial?: string | undefined;
83
+ readonly initial?: {
84
+ readonly data: string;
85
+ readonly request?: string | undefined;
86
+ } | undefined;
83
87
  readonly kind: "shwfed.component.form";
84
88
  readonly fields: readonly any[];
85
89
  readonly layouts: readonly {
@@ -134,11 +138,17 @@ export declare function FormConfig(configure: (env: Environment) => void): Schem
134
138
  }>;
135
139
  }>>>;
136
140
  kind: Schema.tag<"shwfed.component.form">;
137
- initial: Schema.optional<Schema.Schema<string, string, never>>;
141
+ initial: Schema.optional<Schema.Struct<{
142
+ request: Schema.optional<Schema.Schema<string, string, never>>;
143
+ data: Schema.Schema<string, string, never>;
144
+ }>>;
138
145
  readonly: Schema.optional<Schema.Schema<string, string, never>>;
139
146
  }>>;
140
147
  export declare function createFormConfig(body: Omit<Schema.Schema.Type<ReturnType<typeof FormConfig>>, 'kind'>): {
141
- initial?: string | undefined;
148
+ initial?: {
149
+ readonly data: string;
150
+ readonly request?: string | undefined;
151
+ } | undefined;
142
152
  fields: readonly any[];
143
153
  layouts: readonly {
144
154
  readonly name: string;
@@ -173,6 +183,6 @@ export type FormUnitValue = Readonly<{
173
183
  }>;
174
184
  export type FormConfigValue = Readonly<{
175
185
  kind: typeof KIND;
176
- initial?: string;
186
+ initial?: InitialSource;
177
187
  readonly?: string;
178
188
  }> & FormUnitValue;
@@ -47,23 +47,43 @@ export function FormConfig(configure) {
47
47
  registerFormVariablesIfAbsent(env);
48
48
  configure(env);
49
49
  };
50
- const CelFormInitial = Expression({ configure: formConfigure, resultType: "dyn" });
50
+ const CelInitialRequest = Expression({ configure: formConfigure, resultType: "HttpRequest" });
51
+ const CelInitialData = Expression({
52
+ configure: (env) => {
53
+ formConfigure(env);
54
+ env.registerVariable("json", "optional<dyn>", {
55
+ description: "HTTP \u54CD\u5E94\u4F53\uFF08\u5DF2\u89E3\u6790 JSON\uFF09\uFF1B\u672A\u914D\u7F6E request \u65F6\u4E3A none\uFF0C\u7528 `json.?\u5B57\u6BB5` \u8BBF\u95EE"
56
+ });
57
+ },
58
+ resultType: "dyn"
59
+ });
51
60
  const CelFormReadonly = Expression({ configure: formConfigure, resultType: "bool" });
52
61
  return Schema.Struct({
53
62
  kind: Schema.tag(KIND),
54
- initial: Schema.optional(CelFormInitial.annotations({
55
- title: "\u521D\u59CB\u503C",
56
- description: md`
57
- 返回整个表单初始值的 CEL 表达式:
63
+ initial: Schema.optional(Schema.Struct({
64
+ request: Schema.optional(CelInitialRequest.annotations({
65
+ title: "\u8BF7\u6C42",
66
+ description: md`
67
+ 可选的 HTTP 请求表达式:返回 \`HttpRequest\`,运行时由宿主发起,并把响应体作为 \`json\` 传给「数据」表达式。
58
68
 
59
- - 可以互相依赖,但是应当避免循环引用出现
69
+ 留空时「数据」直接对 CEL 上下文求值(静态默认值,或引用 \`form\` 的表达式)。
70
+ `
71
+ })),
72
+ data: CelInitialData.annotations({
73
+ title: "\u6570\u636E",
74
+ description: md`
75
+ 返回整个表单初始值的 CEL 表达式(应为一个对象):
60
76
 
61
- 考虑一个表单,包含了用户名 & 用户角色。特别的,一个用户可能有多个角色。我们可以默认填入当前登入人的用户名,随后再以此为依据,填入其默认的角色。
77
+ - 可以互相依赖,但应避免循环引用。考虑一个含「用户名」与「用户角色」的表单:可默认填入当前登入人的用户名,再以此为依据填入其默认角色。
62
78
 
63
- - 支持异步调用(如 \`http.get(...).json()\`)。运行时会等待表达式 resolve 后再触发依赖 \`form\` 的请求
79
+ - 配置了「请求」时,可通过 \`json\` 引用响应体,例如 \`json.?data\`。
64
80
 
65
- - 如果配置了初始值,重置这个表单将**重置为其初始值,而非空**
66
- `
81
+ - 如果配置了初始值,重置这个表单将**重置为其初始值,而非空**。
82
+ `
83
+ })
84
+ }).annotations({
85
+ title: "\u521D\u59CB\u503C",
86
+ description: "\u8868\u5355\u521D\u59CB\u503C\u7684\u6765\u6E90\uFF1A\u53EF\u9009\u7684 HTTP \u8BF7\u6C42\uFF0C\u52A0\u4E00\u4E2A\u8FD4\u56DE\u521D\u59CB\u503C\u5BF9\u8C61\u7684 CEL \u8868\u8FBE\u5F0F"
67
87
  })),
68
88
  readonly: Schema.optional(CelFormReadonly.annotations({
69
89
  title: "\u53EA\u8BFB\u6761\u4EF6",
@@ -0,0 +1,26 @@
1
+ import { Effect } from 'effect';
2
+ import type { Fetch } from 'fx-fetch';
3
+ /**
4
+ * The form's initial-state source. Mirrors the table's `dataSource` shape: an
5
+ * optional HTTP `request` whose response feeds the `data` expression, which
6
+ * produces the seed object. With no `request`, `data` is evaluated directly
7
+ * against the CEL context (a static default, or one referencing `form`).
8
+ */
9
+ export type InitialSource = Readonly<{
10
+ request?: string;
11
+ data: string;
12
+ }>;
13
+ /**
14
+ * Evaluates a CEL expression against the host's context. A CEL `http.*`
15
+ * expression only *builds* a request, so this never performs IO itself —
16
+ * `evaluateInitial` issues the request separately.
17
+ */
18
+ export type CelEvaluator = <T>(expression: string, context?: Record<string, unknown>) => Effect.Effect<T, unknown, never>;
19
+ /**
20
+ * Resolve an `InitialSource` to the seed value. When `request` is set it is
21
+ * built by CEL, then issued here as `.json()` — the host owns the IO, CEL only
22
+ * describes it. The response is exposed to `data` as the `json` variable (an
23
+ * `Option`, so a missing response is `None`, never a crash). The returned
24
+ * Effect needs a `Fetch` layer.
25
+ */
26
+ export declare function evaluateInitial(initial: InitialSource, cel: CelEvaluator, context: Record<string, unknown>): Effect.Effect<unknown, unknown, Fetch.Fetch>;
@@ -0,0 +1,11 @@
1
+ import { Effect, Option } from "effect";
2
+ export function evaluateInitial(initial, cel, context) {
3
+ return Effect.gen(function* () {
4
+ let json = Option.none();
5
+ if (initial.request) {
6
+ const builder = yield* cel(initial.request, context);
7
+ json = Option.some(yield* builder.json());
8
+ }
9
+ return yield* cel(initial.data, { ...context, json });
10
+ });
11
+ }
@@ -24,6 +24,7 @@ import { NumberField, NumberFieldInput } from "../ui/number-field";
24
24
  import { Tooltip, TooltipContent, TooltipTrigger } from "../ui/tooltip";
25
25
  import ShwfedActions from "../actions/components/group.vue";
26
26
  import ShwfedForm from "../form/index.vue";
27
+ import { evaluateInitial } from "../form/utils/initial";
27
28
  import { provideTableInstanceId } from "./utils/instance";
28
29
  import { provideEventTarget } from "../../share/event-bus";
29
30
  import { findColumn } from "./utils/resolve";
@@ -294,7 +295,8 @@ async function resetQuery() {
294
295
  return;
295
296
  }
296
297
  try {
297
- const result = await Effect.runPromise($cel(initial, { query: {} }));
298
+ const program = evaluateInitial(initial, $cel, { query: {} });
299
+ const result = await Effect.runPromise(Effect.provide(program, Fetch.layer));
298
300
  queryState.value = result && typeof result === "object" && !Array.isArray(result) ? { ...result } : {};
299
301
  } catch (e) {
300
302
  console.error("[shwfed-table] resetQuery failed", e);
@@ -201,7 +201,10 @@ export declare function TableConfig(configure: (env: Environment) => void): Sche
201
201
  }[];
202
202
  } | undefined;
203
203
  readonly query?: {
204
- readonly initial?: string | undefined;
204
+ readonly initial?: {
205
+ readonly data: string;
206
+ readonly request?: string | undefined;
207
+ } | undefined;
205
208
  readonly kind: "shwfed.component.form";
206
209
  readonly fields: readonly any[];
207
210
  readonly layouts: readonly {
@@ -371,7 +374,10 @@ export declare function TableConfig(configure: (env: Environment) => void): Sche
371
374
  }>]>>;
372
375
  }>>;
373
376
  query: Schema.optional<Schema.refine<{
374
- readonly initial?: string | undefined;
377
+ readonly initial?: {
378
+ readonly data: string;
379
+ readonly request?: string | undefined;
380
+ } | undefined;
375
381
  readonly kind: "shwfed.component.form";
376
382
  readonly fields: readonly any[];
377
383
  readonly layouts: readonly {
@@ -426,7 +432,10 @@ export declare function TableConfig(configure: (env: Environment) => void): Sche
426
432
  }>;
427
433
  }>>>;
428
434
  kind: Schema.tag<"shwfed.component.form">;
429
- initial: Schema.optional<Schema.Schema<string, string, never>>;
435
+ initial: Schema.optional<Schema.Struct<{
436
+ request: Schema.optional<Schema.Schema<string, string, never>>;
437
+ data: Schema.Schema<string, string, never>;
438
+ }>>;
430
439
  readonly: Schema.optional<Schema.Schema<string, string, never>>;
431
440
  }>>>;
432
441
  cellStyle: Schema.optional<Schema.Schema<string, string, never>>;
@@ -573,7 +582,10 @@ export declare function createTableConfig(body: Omit<Schema.Schema.Type<ReturnTy
573
582
  }[];
574
583
  } | undefined;
575
584
  query?: {
576
- readonly initial?: string | undefined;
585
+ readonly initial?: {
586
+ readonly data: string;
587
+ readonly request?: string | undefined;
588
+ } | undefined;
577
589
  readonly kind: "shwfed.component.form";
578
590
  readonly fields: readonly any[];
579
591
  readonly layouts: readonly {
@@ -0,0 +1 @@
1
+ export declare function interpolate(template: string, evaluate: (expression: string) => string): string;
@@ -0,0 +1,7 @@
1
+ const TOKEN = /\{\{([\s\S]*?)\}\}/g;
2
+ export function interpolate(template, evaluate) {
3
+ return template.replace(TOKEN, (_token, raw) => {
4
+ const expression = raw.trim();
5
+ return expression.length === 0 ? "" : evaluate(expression);
6
+ });
7
+ }
@@ -20,7 +20,7 @@ The `homogeneousAggregateLiterals` and `enableOptionalTypes` environment options
20
20
 
21
21
  The custom `Optional` class has been replaced with Effect's `Option` type (`import { Option } from 'effect'`). Internal helpers `optionalOf(value)` and `optionalValue(opt)` in `optional.js` handle the CEL-specific semantics (treating `undefined` as `None`, throwing `EvaluationError` on missing value access).
22
22
 
23
- An `http` built-in has been added (`http-builtins.ts`, `http-builder.ts`) — not from upstream. It registers the `http` constant and the `http` / `HttpRequest` types on `globalRegistry`, so `http.get(url).header(...).body(...)` expressions type-check and evaluate in every `Environment`. A CEL expression builds an `HttpRequestBuilder`; the terminal `HttpRequest.file(): File` method issues the request and evaluates to the downloaded `File`, while `.json()` is dispatched by the host on the builder value (it is not a CEL method). Endpoints must be absolute URLs — there is no base-URL resolution. Depends on `fx-fetch`.
23
+ An `http` built-in has been added (`http-builtins.ts`, `http-builder.ts`) — not from upstream. It registers the `http` constant and the `http` / `HttpRequest` types on `globalRegistry`, so `http.get(url).header(...).body(...)` expressions type-check and evaluate in every `Environment`. A CEL expression only builds an `HttpRequestBuilder` a pure description of a request; it never issues one. Both terminal methods, `.json()` and `.file()`, are dispatched by the host on the returned builder (neither is a CEL method), so expression evaluation stays free of IO. Endpoints must be absolute URLs — there is no base-URL resolution. Depends on `fx-fetch`.
24
24
 
25
25
  ## Architecture
26
26
 
@@ -197,7 +197,7 @@ location.param("id") // first value when a param repeats
197
197
 
198
198
  ## HTTP
199
199
 
200
- Build HTTP requests using the `http` builder. A CEL expression *describes* a request; calling `.file()` on it issues the request and evaluates to the downloaded `File`. Any other request is handed to the host to dispatch — there is no way to read a JSON or text response from CEL.
200
+ Build HTTP requests using the `http` builder. A CEL expression only *describes* a request it always evaluates to an `HttpRequest`, never issues it. The host decides when and how to send it (downloading a file, reading a JSON response, etc.). There is no way to perform the request or read its response from CEL.
201
201
 
202
202
  **URLs must be absolute** — pass a full `https://…` URL. There is no base URL, so relative paths like `/api/users` will not resolve.
203
203
 
@@ -236,12 +236,8 @@ http.post("https://api.example.com/users")
236
236
  .header("Content-Type", "application/json")
237
237
  .body({"name": "Alice", "channel": query.?channel})
238
238
 
239
- // Download the response as a File. Unlike the chainable methods above,
240
- // .file() is terminal it issues the request and the expression evaluates
241
- // to a File (filename from the Content-Disposition header, else the URL path):
242
- http.get("https://api.example.com/files/report.pdf").file()
243
-
244
- // Full example — the expression returns an HttpRequest; the host sends it:
239
+ // The expression always evaluates to an HttpRequest the host sends it
240
+ // (downloading a File, reading a JSON response, etc.):
245
241
  http.post("https://api.example.com/users")
246
242
  .header("Content-Type", "application/json")
247
243
  .header("Authorization", "Bearer " + token)
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * `HttpRequestBuilder` — the value an `http.*` CEL expression evaluates to.
3
3
  *
4
- * A local (non-upstream) extension. A CEL expression builds and *describes* a
5
- * request; `.file()` is exposed as a CEL method and evaluates to the downloaded
6
- * `File`, while `.json()` is dispatched by the host on the returned builder.
4
+ * A local (non-upstream) extension. A CEL expression only *describes* a
5
+ * request it never issues one. Both terminal methods, `.json()` and
6
+ * `.file()`, are dispatched by the host on the returned builder, keeping
7
+ * expression evaluation free of IO.
7
8
  *
8
9
  * Endpoints are used verbatim — there is no base-URL resolution, so callers
9
10
  * must pass absolute URLs.