@airalogy/aimd-recorder 1.27.2 → 1.28.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.
- package/README.md +1 -1
- package/README.zh-CN.md +1 -1
- package/dist/{AimdDnaSequenceField-CjcZ1fpz.js → AimdDnaSequenceField-DblYTIq0.js} +1 -1
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-4yWDudoV.js → AimdEditor.vue_vue_type_style_index_0_lang-4uL-qHII.js} +6727 -6636
- package/dist/{AimdEntityRefField-CiGP3IyQ.js → AimdEntityRefField-bRM3TRyz.js} +1 -1
- package/dist/{AimdEntityRefField.vue_vue_type_script_setup_true_lang-B-a446u5.js → AimdEntityRefField.vue_vue_type_script_setup_true_lang-BM5paTdk.js} +1 -1
- package/dist/{AimdMarkdownField-BAJ7otCw.js → AimdMarkdownField-qaWjbybB.js} +3 -3
- package/dist/{AimdMarkdownNoteField-Ca-kRvLz.js → AimdMarkdownNoteField-B8vZnU6s.js} +2 -2
- package/dist/{AimdResourceRefField-Yc3j0Pgu.js → AimdResourceRefField-Bq2ASMTK.js} +2 -2
- package/dist/aimd-recorder.css +1 -1
- package/dist/{arc-CAjOitck.js → arc-00d15h7D.js} +1 -1
- package/dist/{architectureDiagram-3BPJPVTR-Dqk9MN5z.js → architectureDiagram-3BPJPVTR-DKYLI713.js} +2 -2
- package/dist/{blockDiagram-GPEHLZMM-DQLn0TV3.js → blockDiagram-GPEHLZMM-dNWlyXPI.js} +4 -4
- package/dist/{c4Diagram-AAUBKEIU-DZZ_f9Fy.js → c4Diagram-AAUBKEIU-CAqsYcIl.js} +2 -2
- package/dist/{channel-rjOxq-6_.js → channel-4oJLrZcY.js} +1 -1
- package/dist/{chunk-2J33WTMH-tQlc96HU.js → chunk-2J33WTMH-DzoFraaP.js} +1 -1
- package/dist/{chunk-4BX2VUAB-DJYTZE2c.js → chunk-4BX2VUAB-DXRnEJXi.js} +1 -1
- package/dist/{chunk-55IACEB6-CRiTC3Ls.js → chunk-55IACEB6-BfMMJ2bK.js} +1 -1
- package/dist/{chunk-727SXJPM-BD2QhWqt.js → chunk-727SXJPM-BLnYDYYi.js} +5 -5
- package/dist/{chunk-AQP2D5EJ-B0aa98ib.js → chunk-AQP2D5EJ-gckWU-r5.js} +3 -3
- package/dist/{chunk-FMBD7UC4-ByDG3u38.js → chunk-FMBD7UC4-CQ5X8W3n.js} +1 -1
- package/dist/{chunk-ND2GUHAM-Cj1D7wW5.js → chunk-ND2GUHAM-EKUg1pFy.js} +1 -1
- package/dist/{chunk-QZHKN3VN-g2yBIr1b.js → chunk-QZHKN3VN-C7rc4zcu.js} +1 -1
- package/dist/{classDiagram-v2-Q7XG4LA2-BHrQHB1_.js → classDiagram-4FO5ZUOK-EfTWUW7K.js} +2 -2
- package/dist/{classDiagram-4FO5ZUOK-BHrQHB1_.js → classDiagram-v2-Q7XG4LA2-EfTWUW7K.js} +2 -2
- package/dist/components.js +2719 -2710
- package/dist/composables.js +2 -2
- package/dist/{cose-bilkent-S5V4N54A-DoR6eiyr.js → cose-bilkent-S5V4N54A-7OZaecIh.js} +1 -1
- package/dist/{dagre-BM42HDAG-Dojxqnuq.js → dagre-BM42HDAG-DTPFiUIQ.js} +3 -3
- package/dist/{diagram-2AECGRRQ-CXtd1KGZ.js → diagram-2AECGRRQ-BqkCMrTN.js} +2 -2
- package/dist/{diagram-5GNKFQAL-BnJ2DhKE.js → diagram-5GNKFQAL-bzujL8bv.js} +3 -3
- package/dist/{diagram-KO2AKTUF-DJZFSngn.js → diagram-KO2AKTUF-zAvqbjMt.js} +2 -2
- package/dist/{diagram-LMA3HP47-Dx6TLGwi.js → diagram-LMA3HP47-7i7fJxdU.js} +2 -2
- package/dist/{diagram-OG6HWLK6-BX5km_SS.js → diagram-OG6HWLK6-GC2rMiZ5.js} +3 -3
- package/dist/{erDiagram-TEJ5UH35-PWmJC0ho.js → erDiagram-TEJ5UH35-D2U3IvMI.js} +4 -4
- package/dist/{example-record-AHkkwdqV.js → example-record-DJYZw-ON.js} +2 -2
- package/dist/{flowDiagram-I6XJVG4X-ODu7JRxY.js → flowDiagram-I6XJVG4X-nieM9Hg0.js} +6 -6
- package/dist/{ganttDiagram-6RSMTGT7-CZY08InD.js → ganttDiagram-6RSMTGT7-zNrnW3u3.js} +2 -2
- package/dist/{gitGraphDiagram-PVQCEYII-1FOO5ySv.js → gitGraphDiagram-PVQCEYII-DA9UoINV.js} +3 -3
- package/dist/{graph-Dx1st3gR.js → graph-CyckuBF1.js} +1 -1
- package/dist/index.js +5 -5
- package/dist/{infoDiagram-5YYISTIA-Rqn1YuSl.js → infoDiagram-5YYISTIA-DUgRU8-y.js} +1 -1
- package/dist/{ishikawaDiagram-YF4QCWOH-DTqjtgII.js → ishikawaDiagram-YF4QCWOH-BaruYTNe.js} +1 -1
- package/dist/{journeyDiagram-JHISSGLW-Dfc2a9K3.js → journeyDiagram-JHISSGLW-BHlST22D.js} +4 -4
- package/dist/{kanban-definition-UN3LZRKU-DZz55ohU.js → kanban-definition-UN3LZRKU-BW6pDr5N.js} +2 -2
- package/dist/{layout-k1LKX9WI.js → layout-DhpqmwBF.js} +2 -2
- package/dist/{linear-DSz9nhkN.js → linear-BmZyP-ga.js} +1 -1
- package/dist/{mermaid.core-iwpvEomj.js → mermaid.core-SBTvkVkQ.js} +34 -34
- package/dist/{mindmap-definition-RKZ34NQL-CEz0DgQr.js → mindmap-definition-RKZ34NQL-C7mDnX8X.js} +3 -3
- package/dist/{pieDiagram-4H26LBE5-BcuSLA0L.js → pieDiagram-4H26LBE5-Dax4XYix.js} +3 -3
- package/dist/{quadrantDiagram-W4KKPZXB-D3IixvxS.js → quadrantDiagram-W4KKPZXB-tx0eF1c_.js} +2 -2
- package/dist/record.js +3 -3
- package/dist/{requirementDiagram-4Y6WPE33-Bk-lwb2t.js → requirementDiagram-4Y6WPE33-DoEeWHvY.js} +3 -3
- package/dist/{sankeyDiagram-5OEKKPKP-BmUhv9kI.js → sankeyDiagram-5OEKKPKP-qUrDMgFF.js} +1 -1
- package/dist/{sequenceDiagram-3UESZ5HK-BhAJ2Wz1.js → sequenceDiagram-3UESZ5HK-DQy8q3qc.js} +3 -3
- package/dist/{stateDiagram-AJRCARHV-DvH3mI9R.js → stateDiagram-AJRCARHV-Ctcg2io0.js} +4 -4
- package/dist/{stateDiagram-v2-BHNVJYJU-DvkU8jpH.js → stateDiagram-v2-BHNVJYJU-B0bKxEaj.js} +2 -2
- package/dist/{timeline-definition-PNZ67QCA-CQFLx2MG.js → timeline-definition-PNZ67QCA-BRvAr_Ti.js} +2 -2
- package/dist/{useFieldRendering-Bj2H9CPx.js → useFieldRendering-FDuKoylb.js} +57 -57
- package/dist/{useVarHelpers-Bf3wNHxF.js → useVarHelpers-CnOgtKri.js} +1308 -1292
- package/dist/{validation-CH6pi638.js → validation-CK747BvO.js} +1431 -1426
- package/dist/{vennDiagram-CIIHVFJN-D_qwBk9R.js → vennDiagram-CIIHVFJN-Co_TdJKN.js} +1 -1
- package/dist/{wardleyDiagram-YWT4CUSO-BezUR1jm.js → wardleyDiagram-YWT4CUSO-BFW0djMX.js} +2 -2
- package/dist/{xychartDiagram-2RQKCTM6-CTFs3FiD.js → xychartDiagram-2RQKCTM6-DgT1Tjy1.js} +2 -2
- package/package.json +3 -3
- package/src/__tests__/record-validation.test.ts +41 -3
- package/src/__tests__/var-field-render.test.ts +28 -0
- package/src/components/AimdRecorder.vue +7 -1
- package/src/components/AimdRecorderWysiwygSurface.vue +5 -0
- package/src/components/AimdVarField.vue +20 -12
- package/src/composables/__tests__/useVarHelpers.test.ts +7 -1
- package/src/composables/useFieldRendering.ts +2 -1
- package/src/locales.ts +6 -0
- package/src/record/validation.ts +18 -9
- package/src/styles/recorder.css +7 -0
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { aU as Gt, s as Wt, g as Kt, t as Ht, q as Yt, a as Xt, b as Zt, _ as w, F as wt, L as Jt, d as ot, al as Qt, ac as $t, ad as te, ae as ee, e as ne, A as se, H as ie, I as oe } from "./mermaid.core-
|
|
1
|
+
import { aU as Gt, s as Wt, g as Kt, t as Ht, q as Yt, a as Xt, b as Zt, _ as w, F as wt, L as Jt, d as ot, al as Qt, ac as $t, ad as te, ae as ee, e as ne, A as se, H as ie, I as oe } from "./mermaid.core-SBTvkVkQ.js";
|
|
2
2
|
const kt = (t, n) => Gt(t, "a", -n), _t = 1e-10;
|
|
3
3
|
function st(t, n) {
|
|
4
4
|
const s = ae(t), e = s.filter((c) => re(c, t));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { s as Mt, g as Nt, t as Lt, q as zt, a as Tt, b as At, _ as u, a1 as Xt, F as Et, H as J, l as Q, L as Yt, e as It, A as Ft, c as V } from "./mermaid.core-
|
|
2
|
-
import { p as Bt } from "./chunk-4BX2VUAB-
|
|
1
|
+
import { s as Mt, g as Nt, t as Lt, q as zt, a as Tt, b as At, _ as u, a1 as Xt, F as Et, H as J, l as Q, L as Yt, e as It, A as Ft, c as V } from "./mermaid.core-SBTvkVkQ.js";
|
|
2
|
+
import { p as Bt } from "./chunk-4BX2VUAB-DXRnEJXi.js";
|
|
3
3
|
import { p as Rt } from "./wardley-L42UT6IY-D7b2ujEZ.js";
|
|
4
4
|
var G = /* @__PURE__ */ u((o, r) => {
|
|
5
5
|
const e = o <= 1 ? o * 100 : o;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import { s as gi, g as xi, t as Xt, q as di, a as fi, b as pi, _ as a, l as Yt, L as mi, e as yi, A as bi, F as _t, i as Ai, H as Nt, I as wi, a1 as Ci, am as Si, a9 as Wt } from "./mermaid.core-
|
|
1
|
+
import { s as gi, g as xi, t as Xt, q as di, a as fi, b as pi, _ as a, l as Yt, L as mi, e as yi, A as bi, F as _t, i as Ai, H as Nt, I as wi, a1 as Ci, am as Si, a9 as Wt } from "./mermaid.core-SBTvkVkQ.js";
|
|
2
2
|
import { i as _i } from "./init-DjUOC4st.js";
|
|
3
3
|
import { o as ki } from "./ordinal-B6-f3MAq.js";
|
|
4
|
-
import { l as zt } from "./linear-
|
|
4
|
+
import { l as zt } from "./linear-BmZyP-ga.js";
|
|
5
5
|
function Ri(e, t, i) {
|
|
6
6
|
e = +e, t = +t, i = (n = arguments.length) < 2 ? (t = e, e = 0, 1) : n < 3 ? 1 : +i;
|
|
7
7
|
for (var s = -1, n = Math.max(0, Math.ceil((t - e) / i)) | 0, o = new Array(n); ++s < n; )
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airalogy/aimd-recorder",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
4
|
+
"version": "1.28.0",
|
|
5
5
|
"description": "AIMD (Airalogy Markdown) recorder Vue components and UI",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
@@ -67,8 +67,8 @@
|
|
|
67
67
|
"react": "^19.2.4",
|
|
68
68
|
"react-dom": "^19.2.4",
|
|
69
69
|
"seqviz": "^3.10.18",
|
|
70
|
-
"@airalogy/aimd-core": "^2.18.
|
|
71
|
-
"@airalogy/aimd-editor": "^1.
|
|
70
|
+
"@airalogy/aimd-core": "^2.18.1",
|
|
71
|
+
"@airalogy/aimd-editor": "^1.14.0",
|
|
72
72
|
"@airalogy/aimd-renderer": "^2.14.0"
|
|
73
73
|
},
|
|
74
74
|
"devDependencies": {
|
|
@@ -28,14 +28,14 @@ describe("AimdRecorder validation", () => {
|
|
|
28
28
|
var_definitions: [
|
|
29
29
|
{ id: "schema_name", type: "str", default: "" },
|
|
30
30
|
{ id: "aimd_name", type: "str" },
|
|
31
|
-
{ id: "optional_name", type: "str", default:
|
|
31
|
+
{ id: "optional_name", type: "str | None", default: null },
|
|
32
32
|
],
|
|
33
33
|
var_table: [{
|
|
34
34
|
id: "samples",
|
|
35
35
|
scope: "var_table",
|
|
36
36
|
subvars: [
|
|
37
37
|
{ id: "sample_id", type: "str" },
|
|
38
|
-
{ id: "note", type: "str", default:
|
|
38
|
+
{ id: "note", type: "str | None", default: null },
|
|
39
39
|
],
|
|
40
40
|
}],
|
|
41
41
|
}
|
|
@@ -54,7 +54,7 @@ describe("AimdRecorder validation", () => {
|
|
|
54
54
|
required: ["sample_id"],
|
|
55
55
|
properties: {
|
|
56
56
|
sample_id: { type: "string" },
|
|
57
|
-
note: { type: "string" },
|
|
57
|
+
note: { type: ["string", "null"] },
|
|
58
58
|
},
|
|
59
59
|
},
|
|
60
60
|
},
|
|
@@ -179,6 +179,44 @@ describe("AimdRecorder validation", () => {
|
|
|
179
179
|
])
|
|
180
180
|
})
|
|
181
181
|
|
|
182
|
+
it("distinguishes an omitted prefill, an explicitly cleared input and a valid false answer", async () => {
|
|
183
|
+
const wrapper = mount(AimdRecorder, { props: {
|
|
184
|
+
content: '{{var|unit: str = "mg"}} {{var|note: str | None = None}} {{var|flag: Literal[True, False]}}',
|
|
185
|
+
showSearch: false,
|
|
186
|
+
} })
|
|
187
|
+
await flushPromises()
|
|
188
|
+
const validate = () => (wrapper.vm as unknown as {
|
|
189
|
+
validate: (options: { focus: boolean }) => Promise<{ valid: boolean; issues: { fieldKey: string }[] }>
|
|
190
|
+
}).validate({ focus: false })
|
|
191
|
+
const unit = wrapper.get<HTMLInputElement>('[data-rec-focus-key="var:unit"]')
|
|
192
|
+
const flag = wrapper.get<HTMLSelectElement>('select[data-rec-focus-key="var:flag"]')
|
|
193
|
+
expect(unit.element.value).toBe('mg')
|
|
194
|
+
expect(flag.element.value).toBe('')
|
|
195
|
+
expect((await validate()).issues.map(issue => issue.fieldKey)).toEqual(['var:flag'])
|
|
196
|
+
expect(wrapper.get('.aimd-field__optional-marker').text()).toBe('Optional')
|
|
197
|
+
await flag.setValue('1')
|
|
198
|
+
expect((await validate()).valid).toBe(true)
|
|
199
|
+
await unit.setValue('')
|
|
200
|
+
expect((await validate()).issues.map(issue => issue.fieldKey)).toEqual(['var:unit'])
|
|
201
|
+
wrapper.unmount()
|
|
202
|
+
})
|
|
203
|
+
|
|
204
|
+
it("does not confuse a nullable list with a default-empty list", () => {
|
|
205
|
+
const fields = { ...EMPTY_FIELDS, var: ['nullable', 'omittable', 'empty'], var_definitions: [
|
|
206
|
+
{ id: 'nullable', type: 'list[str] | None' },
|
|
207
|
+
{ id: 'omittable', type: 'list[str] | None', default: null },
|
|
208
|
+
{ id: 'empty', type: 'list[str]', default: [] },
|
|
209
|
+
] }
|
|
210
|
+
const record = createEmptyProtocolRecordData()
|
|
211
|
+
const issues = () => validateAimdRecord(fields, record, { messages }).issues.map(issue => issue.fieldKey)
|
|
212
|
+
expect(issues()).toEqual(['var:nullable'])
|
|
213
|
+
record.var.nullable = null
|
|
214
|
+
record.var.empty = []
|
|
215
|
+
expect(issues()).toEqual([])
|
|
216
|
+
record.var.empty = null
|
|
217
|
+
expect(issues()).toEqual(['var:empty'])
|
|
218
|
+
})
|
|
219
|
+
|
|
182
220
|
it("accepts null for schema-required nullable fields and table columns", () => {
|
|
183
221
|
const fields: ExtractedAimdFields = {
|
|
184
222
|
...EMPTY_FIELDS,
|
|
@@ -706,6 +706,34 @@ describe('AimdVarField render behavior', () => {
|
|
|
706
706
|
expect(wrapper.findAll<HTMLInputElement>('.aimd-rec-scalar-list__input').map(input => input.element.value)).toEqual(['aaa', 'bbb'])
|
|
707
707
|
})
|
|
708
708
|
|
|
709
|
+
it('preserves the difference between an unanswered list and an explicit empty array in JSON mode', async () => {
|
|
710
|
+
const node: AimdVarNode = {
|
|
711
|
+
type: 'aimd', fieldType: 'var', scope: 'var', id: 'tags',
|
|
712
|
+
raw: '{{var|tags: list[str] | None = None}}',
|
|
713
|
+
definition: { id: 'tags', type: 'list[str] | None', default: null },
|
|
714
|
+
}
|
|
715
|
+
const wrapper = mount(AimdVarField, {
|
|
716
|
+
props: { node, value: null as any, inputKind: 'scalar-list', initialized: true, messages: createAimdRecorderMessages('en-US') },
|
|
717
|
+
})
|
|
718
|
+
const [items, json] = wrapper.findAll('.aimd-rec-scalar-list__mode-button')
|
|
719
|
+
await json.trigger('click')
|
|
720
|
+
await vi.dynamicImportSettled()
|
|
721
|
+
const editor = wrapper.findComponent({ name: 'AimdCodeField' })
|
|
722
|
+
expect(editor.props('modelValue')).toBe('null')
|
|
723
|
+
expect(wrapper.emitted('change')).toBeUndefined()
|
|
724
|
+
|
|
725
|
+
editor.vm.$emit('update:modelValue', '[]')
|
|
726
|
+
expect(wrapper.emitted('change')?.[0]?.[0]).toMatchObject({ value: [] })
|
|
727
|
+
await wrapper.setProps({ value: [] as any })
|
|
728
|
+
editor.vm.$emit('update:modelValue', 'null')
|
|
729
|
+
expect(wrapper.emitted('change')?.[1]?.[0]).toMatchObject({ value: null })
|
|
730
|
+
await wrapper.setProps({ value: null as any })
|
|
731
|
+
await items.trigger('click')
|
|
732
|
+
await json.trigger('click')
|
|
733
|
+
expect(wrapper.findComponent({ name: 'AimdCodeField' }).props('modelValue')).toBe('null')
|
|
734
|
+
expect(wrapper.emitted('change')).toHaveLength(2)
|
|
735
|
+
})
|
|
736
|
+
|
|
709
737
|
it('parses numeric scalar-list JSON according to the item type', async () => {
|
|
710
738
|
const node: AimdVarNode = {
|
|
711
739
|
type: 'aimd',
|
|
@@ -607,7 +607,7 @@ const serverAssignerByAssignedField = computed(() => (
|
|
|
607
607
|
|
|
608
608
|
function createEnumOptions(values: unknown[]): NonNullable<AimdFieldMeta["enumOptions"]> {
|
|
609
609
|
return values.map(value => ({
|
|
610
|
-
label: String(value),
|
|
610
|
+
label: typeof value === "boolean" ? resolvedMessages.value.boolean[value ? 'true' : 'false'] : String(value),
|
|
611
611
|
value,
|
|
612
612
|
}))
|
|
613
613
|
}
|
|
@@ -678,6 +678,11 @@ const requiredFieldKeys = computed(() => getAimdRequiredFieldKeys(extractedField
|
|
|
678
678
|
fieldMeta: effectiveFieldMeta.value,
|
|
679
679
|
schema: props.validationSchema,
|
|
680
680
|
}))
|
|
681
|
+
const markOptionalInputs = computed(() => {
|
|
682
|
+
const vars = extractedFields.value.var_definitions ?? []
|
|
683
|
+
const optional = vars.filter(field => !requiredFieldKeys.value.has(`var:${field.id}`)).length
|
|
684
|
+
return optional > 0 && optional < vars.length - optional
|
|
685
|
+
})
|
|
681
686
|
const effectiveFieldState = computed<Record<string, AimdFieldState>>(() => {
|
|
682
687
|
const keys = new Set([
|
|
683
688
|
...Object.keys(internalAssignerFieldState.value),
|
|
@@ -1370,6 +1375,7 @@ function renderInlineVar(node: AimdVarNode): VNode {
|
|
|
1370
1375
|
messages: resolvedMessages.value,
|
|
1371
1376
|
fieldMeta: meta,
|
|
1372
1377
|
required,
|
|
1378
|
+
markOptional: markOptionalInputs.value,
|
|
1373
1379
|
displayValue,
|
|
1374
1380
|
inputKind,
|
|
1375
1381
|
typePlugin,
|
|
@@ -782,6 +782,11 @@ defineExpose({
|
|
|
782
782
|
padding: 3px 5px;
|
|
783
783
|
}
|
|
784
784
|
|
|
785
|
+
/* The first inline field has no preceding line for its floating edit controls. */
|
|
786
|
+
.aimd-recorder-wysiwyg-surface :deep(.ProseMirror > :first-child:has(.aimd-recorder-wysiwyg-node--inline)) {
|
|
787
|
+
padding-block-start: 2rem;
|
|
788
|
+
}
|
|
789
|
+
|
|
785
790
|
.aimd-recorder-wysiwyg-surface :deep(.aimd-recorder-wysiwyg-node__chrome--block) {
|
|
786
791
|
top: 10px;
|
|
787
792
|
right: 10px;
|
|
@@ -497,6 +497,7 @@ export default defineComponent({
|
|
|
497
497
|
messages: { type: Object as PropType<AimdRecorderMessages>, required: true },
|
|
498
498
|
fieldMeta: { type: Object as PropType<AimdFieldMeta | undefined>, default: undefined },
|
|
499
499
|
required: { type: Boolean, default: false },
|
|
500
|
+
markOptional: { type: Boolean, default: false },
|
|
500
501
|
displayValue: { type: [String, Number] as PropType<string | number>, default: "" },
|
|
501
502
|
inputKind: { type: String as PropType<AimdVarInputKind>, required: true },
|
|
502
503
|
typePlugin: { type: Object as PropType<AimdTypePlugin | undefined>, default: undefined },
|
|
@@ -553,7 +554,10 @@ export default defineComponent({
|
|
|
553
554
|
}
|
|
554
555
|
if (scalarListJsonDraft.value !== null) {
|
|
555
556
|
const parsedDraft = parseScalarListJsonValue(scalarListJsonDraft.value, itemType)
|
|
556
|
-
|
|
557
|
+
const nullMismatch = isNullableVarType(props.node.definition?.type) &&
|
|
558
|
+
(parsedDraft.ok || scalarListJsonDraft.value.trim() === 'null') &&
|
|
559
|
+
(scalarListJsonDraft.value.trim() === 'null') !== (value === null)
|
|
560
|
+
if (nullMismatch || (parsedDraft.ok && !areArraysEqual(persistedItems, parsedDraft.value))) {
|
|
557
561
|
scalarListJsonDraft.value = null
|
|
558
562
|
scalarListJsonError.value = ""
|
|
559
563
|
}
|
|
@@ -766,9 +770,12 @@ export default defineComponent({
|
|
|
766
770
|
}
|
|
767
771
|
|
|
768
772
|
const renderVarLabel = (headerAction?: VNode | null): VNode | null => {
|
|
773
|
+
const optional = props.markOptional && !props.required
|
|
774
|
+
? h('span', { class: 'aimd-field__optional-marker' }, props.messages.common.optional)
|
|
775
|
+
: null
|
|
769
776
|
if (fieldDisplay.value === 'compact') {
|
|
770
777
|
const actions = renderHeaderAssignerActions(headerAction)
|
|
771
|
-
return actions ? h('span', { class: 'aimd-rec-inline__compact-actions' }, [actions]) : null
|
|
778
|
+
return actions || optional ? h('span', { class: 'aimd-rec-inline__compact-actions' }, [optional, actions]) : null
|
|
772
779
|
}
|
|
773
780
|
const metaTitle = normalizeMetaString(meta?.title)
|
|
774
781
|
const definitionTitle = getAimdFieldTitle(node.definition)
|
|
@@ -800,7 +807,7 @@ export default defineComponent({
|
|
|
800
807
|
}, [
|
|
801
808
|
h("span", { class: "aimd-field__title-row" }, [
|
|
802
809
|
h("span", { class: "aimd-field__title", title: displayTitle }, displayTitle),
|
|
803
|
-
props.required ? h(AimdRequiredMarker, { label: props.messages.common.required }) :
|
|
810
|
+
props.required && !props.markOptional ? h(AimdRequiredMarker, { label: props.messages.common.required }) : optional,
|
|
804
811
|
]),
|
|
805
812
|
hasCustomTitle ? h("span", { class: "aimd-field__key", title: id }, id) : null,
|
|
806
813
|
renderFieldMetadataPopover(help),
|
|
@@ -839,7 +846,7 @@ export default defineComponent({
|
|
|
839
846
|
const showEmptyEnumOption = emptyEnumValue === null || selectedEnumValue === ""
|
|
840
847
|
const emptyEnumLabel = emptyEnumValue === null
|
|
841
848
|
? getAimdRecorderEmptyValueLabel(props.messages)
|
|
842
|
-
: placeholder
|
|
849
|
+
: placeholder || props.messages.common.chooseValue
|
|
843
850
|
return h("span", {
|
|
844
851
|
class: [
|
|
845
852
|
"aimd-rec-inline aimd-rec-inline--var-stacked aimd-field-wrapper",
|
|
@@ -1303,10 +1310,16 @@ export default defineComponent({
|
|
|
1303
1310
|
}
|
|
1304
1311
|
const getScalarListJsonDraft = () => (
|
|
1305
1312
|
scalarListJsonDraft.value
|
|
1306
|
-
?? formatScalarListJsonValue(scalarListDraftRows.value ?? props.value, scalarListItemType)
|
|
1313
|
+
?? (props.value === null && isNullableVarType(type) ? 'null' : formatScalarListJsonValue(scalarListDraftRows.value ?? props.value, scalarListItemType))
|
|
1307
1314
|
)
|
|
1308
1315
|
const emitScalarListJsonDraft = (rawValue: string) => {
|
|
1309
1316
|
scalarListJsonDraft.value = rawValue
|
|
1317
|
+
if (rawValue.trim() === 'null' && isNullableVarType(type)) {
|
|
1318
|
+
scalarListJsonError.value = ''
|
|
1319
|
+
scalarListDraftRows.value = null
|
|
1320
|
+
emit('change', { id, value: null, type, inputKind })
|
|
1321
|
+
return
|
|
1322
|
+
}
|
|
1310
1323
|
const parsed = parseScalarListJsonValue(rawValue, scalarListItemType)
|
|
1311
1324
|
if (!parsed.ok) {
|
|
1312
1325
|
scalarListJsonError.value = getScalarListJsonErrorMessage(parsed.error)
|
|
@@ -1325,13 +1338,8 @@ export default defineComponent({
|
|
|
1325
1338
|
if (scalarListMode.value === mode) {
|
|
1326
1339
|
return
|
|
1327
1340
|
}
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
scalarListJsonError.value = ""
|
|
1331
|
-
} else {
|
|
1332
|
-
scalarListJsonDraft.value = null
|
|
1333
|
-
scalarListJsonError.value = ""
|
|
1334
|
-
}
|
|
1341
|
+
scalarListJsonDraft.value = null
|
|
1342
|
+
scalarListJsonError.value = ""
|
|
1335
1343
|
scalarListMode.value = mode
|
|
1336
1344
|
}
|
|
1337
1345
|
const modeButton = (mode: ScalarListEditMode, label: string) => h("button", {
|
|
@@ -695,7 +695,13 @@ describe('field rendering nullable defaults', () => {
|
|
|
695
695
|
expect(rendering.getVarInitialValue(node('int | None') as never, 'int | None', 'var:value')).toBeNull()
|
|
696
696
|
expect(rendering.getVarInitialValue(node('date | None') as never, 'date | None', 'var:value')).toBeNull()
|
|
697
697
|
expect(rendering.getVarInitialValue(node('str | None') as never, 'str | None', 'var:value')).toBeNull()
|
|
698
|
-
|
|
698
|
+
const type = 'list[str] | None'
|
|
699
|
+
expect(rendering.getVarInitialValue(node(type) as never, type, 'var:value')).toBeNull()
|
|
700
|
+
for (const value of [null, [], ['tag']]) {
|
|
701
|
+
const withDefault = { ...node(type), definition: { id: 'value', type, default: value } }
|
|
702
|
+
expect(rendering.getVarInitialValue(withDefault as never, type, 'var:value')).toEqual(value)
|
|
703
|
+
expect(rendering.normalizeVarValue(node(type) as never, type, 'var:value', value, 'scalar-list')).toEqual(value)
|
|
704
|
+
}
|
|
699
705
|
})
|
|
700
706
|
})
|
|
701
707
|
|
|
@@ -222,7 +222,7 @@ export function useFieldRendering(options: FieldRenderingOptions) {
|
|
|
222
222
|
typePlugin,
|
|
223
223
|
})
|
|
224
224
|
if (inputKind === "boolean-select") return null
|
|
225
|
-
if (isNullableVarType(type) && inputKind !== "
|
|
225
|
+
if (isNullableVarType(type) && inputKind !== "checkbox") return null
|
|
226
226
|
if (inputKind === "multi-select") return []
|
|
227
227
|
if (inputKind === "checkbox") return false
|
|
228
228
|
if (inputKind === "scalar-list") return []
|
|
@@ -252,6 +252,7 @@ export function useFieldRendering(options: FieldRenderingOptions) {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
if (inputKind === "scalar-list") {
|
|
255
|
+
if (value == null && isNullableVarType(type)) return null
|
|
255
256
|
return normalizeScalarListInputItems(
|
|
256
257
|
getScalarListInputItems(value),
|
|
257
258
|
getScalarListItemType(type) ?? "string",
|
package/src/locales.ts
CHANGED
|
@@ -259,6 +259,8 @@ export interface AimdRecorderMessages {
|
|
|
259
259
|
emptyValue?: string
|
|
260
260
|
emptyContent: string
|
|
261
261
|
required: string
|
|
262
|
+
optional: string
|
|
263
|
+
chooseValue: string
|
|
262
264
|
}
|
|
263
265
|
}
|
|
264
266
|
|
|
@@ -529,6 +531,8 @@ const EN_US_MESSAGES: AimdRecorderMessages = {
|
|
|
529
531
|
emptyValue: "Not set",
|
|
530
532
|
emptyContent: "No renderable protocol content.",
|
|
531
533
|
required: "Required",
|
|
534
|
+
optional: "Optional",
|
|
535
|
+
chooseValue: "Choose an option",
|
|
532
536
|
},
|
|
533
537
|
}
|
|
534
538
|
|
|
@@ -772,6 +776,8 @@ const ZH_CN_MESSAGES: AimdRecorderMessages = {
|
|
|
772
776
|
emptyValue: "未填写",
|
|
773
777
|
emptyContent: "没有可渲染的协议内容。",
|
|
774
778
|
required: "必填",
|
|
779
|
+
optional: "选填",
|
|
780
|
+
chooseValue: "请选择",
|
|
775
781
|
},
|
|
776
782
|
}
|
|
777
783
|
|
package/src/record/validation.ts
CHANGED
|
@@ -323,16 +323,17 @@ export function getAimdRequiredFieldKeys(
|
|
|
323
323
|
kwargs: Record<string, unknown> | undefined,
|
|
324
324
|
inferredRequired: boolean,
|
|
325
325
|
type?: string,
|
|
326
|
+
hasDefault = false,
|
|
326
327
|
) => {
|
|
327
328
|
const required = schemaCoveredKeys.has(fieldKey)
|
|
328
329
|
? fieldMeta[fieldKey]?.required === true
|
|
329
|
-
|| (schemaRequiredKeys.has(fieldKey) && !schemaNullableKeys.has(fieldKey))
|
|
330
|
+
|| ((schemaRequiredKeys.has(fieldKey) || hasDefault) && !schemaNullableKeys.has(fieldKey))
|
|
330
331
|
: resolveRequired(fieldMeta[fieldKey], kwargs, inferredRequired && !isNullableVarType(type))
|
|
331
332
|
if (required) keys.add(fieldKey)
|
|
332
333
|
}
|
|
333
334
|
|
|
334
335
|
for (const field of fields.var_definitions ?? []) {
|
|
335
|
-
addWhenRequired(`var:${field.id}`, field.kwargs,
|
|
336
|
+
addWhenRequired(`var:${field.id}`, field.kwargs, true, field.type, hasOwn(field, "default"))
|
|
336
337
|
}
|
|
337
338
|
|
|
338
339
|
for (const table of fields.var_table ?? []) {
|
|
@@ -343,11 +344,11 @@ export function getAimdRequiredFieldKeys(
|
|
|
343
344
|
const columnKey = `${tableKey}:${column.id}`
|
|
344
345
|
const required = schemaCovered
|
|
345
346
|
? fieldMeta[columnKey]?.required === true
|
|
346
|
-
|| (schemaRequiredKeys.has(columnKey) && !schemaNullableKeys.has(columnKey))
|
|
347
|
+
|| ((schemaRequiredKeys.has(columnKey) || hasOwn(column, "default")) && !schemaNullableKeys.has(columnKey))
|
|
347
348
|
: resolveRequired(
|
|
348
349
|
fieldMeta[columnKey],
|
|
349
350
|
column.kwargs,
|
|
350
|
-
!
|
|
351
|
+
!isNullableVarType(column.type),
|
|
351
352
|
)
|
|
352
353
|
if (required) keys.add(columnKey)
|
|
353
354
|
}
|
|
@@ -645,6 +646,8 @@ function validateValue(
|
|
|
645
646
|
rowIndex?: number
|
|
646
647
|
column?: string
|
|
647
648
|
inferredRequired?: boolean
|
|
649
|
+
hasDefault?: boolean
|
|
650
|
+
defaultValue?: unknown
|
|
648
651
|
schemaCovered?: boolean
|
|
649
652
|
schemaRequired?: boolean
|
|
650
653
|
schemaNullable?: boolean
|
|
@@ -662,6 +665,7 @@ function validateValue(
|
|
|
662
665
|
rowIndex,
|
|
663
666
|
column,
|
|
664
667
|
inferredRequired = false,
|
|
668
|
+
hasDefault = false,
|
|
665
669
|
schemaCovered = false,
|
|
666
670
|
schemaRequired = false,
|
|
667
671
|
schemaNullable = false,
|
|
@@ -672,11 +676,12 @@ function validateValue(
|
|
|
672
676
|
const explicitlyRequired = meta?.required === true || (!schemaCovered && kwargs?.required === true)
|
|
673
677
|
const nullable = schemaCovered ? schemaNullable : isNullableVarType(type)
|
|
674
678
|
const required = schemaCovered
|
|
675
|
-
? schemaRequired || meta?.required === true
|
|
676
|
-
: resolveRequired(meta, kwargs, inferredRequired && !nullable)
|
|
679
|
+
? schemaRequired || meta?.required === true || (hasDefault && !nullable && value !== undefined)
|
|
680
|
+
: resolveRequired(meta, kwargs, inferredRequired && (value === undefined ? !hasDefault : !nullable))
|
|
677
681
|
const allowedNullableEmpty = value === null && nullable && !explicitlyRequired
|
|
678
682
|
|
|
679
|
-
|
|
683
|
+
const allowedEmptyList = !schemaRequired && !explicitlyRequired && Array.isArray(value) && Array.isArray(input.defaultValue) && input.defaultValue.length === 0
|
|
684
|
+
if (required && isEmptyValue(value) && !allowedNullableEmpty && !allowedEmptyList) {
|
|
680
685
|
addIssue(issues, fieldKey, section, "required", options.messages.required(label), value, details)
|
|
681
686
|
return
|
|
682
687
|
}
|
|
@@ -854,7 +859,9 @@ export function validateAimdRecord(
|
|
|
854
859
|
kwargs: field.kwargs,
|
|
855
860
|
meta: fieldMeta[fieldKey],
|
|
856
861
|
enumValues: field.enum,
|
|
857
|
-
inferredRequired:
|
|
862
|
+
inferredRequired: true,
|
|
863
|
+
hasDefault: hasOwn(field, "default"),
|
|
864
|
+
defaultValue: field.default,
|
|
858
865
|
schemaCovered: schemaCoveredKeys.has(fieldKey),
|
|
859
866
|
schemaRequired: schemaRequiredKeys.has(fieldKey),
|
|
860
867
|
schemaNullable: schemaNullableKeys.has(fieldKey),
|
|
@@ -900,7 +907,9 @@ export function validateAimdRecord(
|
|
|
900
907
|
enumValues: column.enum,
|
|
901
908
|
rowIndex,
|
|
902
909
|
column: column.id,
|
|
903
|
-
inferredRequired:
|
|
910
|
+
inferredRequired: true,
|
|
911
|
+
hasDefault: hasOwn(column, "default"),
|
|
912
|
+
defaultValue: column.default,
|
|
904
913
|
schemaCovered,
|
|
905
914
|
schemaRequired: schemaRequiredKeys.has(columnMetaKey),
|
|
906
915
|
schemaNullable: schemaNullableKeys.has(columnMetaKey),
|
package/src/styles/recorder.css
CHANGED
|
@@ -668,3 +668,10 @@ td .field__wrapper--tagged {
|
|
|
668
668
|
.aimd-check-field__identity { display: inline-flex; flex-direction: column; min-width: 0; overflow-wrap: anywhere; }
|
|
669
669
|
.aimd-check-field__title { font-size: 14px; font-weight: 600; line-height: 1.5; }
|
|
670
670
|
.aimd-check-field__identity .aimd-check-field__key { font: 12px/1.4 monospace; color: #667085; }
|
|
671
|
+
.aimd-field__optional-marker {
|
|
672
|
+
margin-inline: 0.3rem;
|
|
673
|
+
color: #526477;
|
|
674
|
+
font-size: 0.75rem;
|
|
675
|
+
font-weight: 400;
|
|
676
|
+
white-space: nowrap;
|
|
677
|
+
}
|