@airalogy/aimd-recorder 1.14.1 → 1.16.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/LICENSE +201 -0
- package/README.md +9 -1
- package/README.zh-CN.md +9 -1
- package/dist/{AimdDnaSequenceField-__jdnFS9.js → AimdDnaSequenceField-CPyMqIVh.js} +1 -1
- package/dist/{AimdEditor.vue_vue_type_style_index_0_lang-Bq79rKNw.js → AimdEditor.vue_vue_type_style_index_0_lang-lyHIpch9.js} +6344 -6073
- package/dist/{AimdMarkdownField-98ImHGbc.js → AimdMarkdownField-CX71bOdX.js} +4 -3
- package/dist/{AimdMarkdownNoteField-CuUJZkgT.js → AimdMarkdownNoteField--ssNIQfG.js} +11 -10
- package/dist/aimd-recorder.css +1 -1
- package/dist/components.js +2128 -1891
- package/dist/composables.js +1 -1
- package/dist/index.js +2 -2
- package/dist/{useFieldRendering-BIqeE3qo.js → useFieldRendering-Dh6Kib_0.js} +1303 -1207
- package/package.json +13 -13
- package/src/__tests__/client-assigner.test.ts +59 -0
- package/src/__tests__/quiz-recorder.test.ts +112 -0
- package/src/__tests__/recorder-quiz-followups.test.ts +97 -0
- package/src/__tests__/step-field.test.ts +47 -3
- package/src/__tests__/var-field-render.test.ts +7 -1
- package/src/client-assigner.ts +47 -3
- package/src/components/AimdQuizRecorder.vue +404 -45
- package/src/components/AimdRecorder.vue +14 -1
- package/src/components/AimdRecorderEditor.vue +3 -2
- package/src/components/AimdVarField.vue +43 -5
- package/src/composables/__tests__/useRecordState.test.ts +41 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +44 -0
- package/src/composables/useClientAssignerRunner.ts +7 -1
- package/src/composables/useRecordState.ts +57 -4
- package/src/composables/useVarHelpers.ts +113 -0
- package/src/composables/workbenchFieldEditing.ts +8 -5
- package/src/locales.ts +3 -0
|
@@ -9,8 +9,11 @@ import {
|
|
|
9
9
|
normalizeVarTypeName,
|
|
10
10
|
parseVarInputValue,
|
|
11
11
|
applyVarStackWidth,
|
|
12
|
+
getNumericConstraintViolation,
|
|
13
|
+
getNumericInputAttributes,
|
|
12
14
|
syncAutoWrapTextareaHeight,
|
|
13
15
|
toBooleanValue,
|
|
16
|
+
type NumericInputAttributes,
|
|
14
17
|
} from "../composables/useVarHelpers"
|
|
15
18
|
|
|
16
19
|
const AimdCodeField = defineAsyncComponent(() => import("./AimdCodeField.vue"))
|
|
@@ -45,6 +48,12 @@ export default defineComponent({
|
|
|
45
48
|
const placeholder = meta?.placeholder ?? getVarPlaceholder(node)
|
|
46
49
|
const displayValue = props.displayValue
|
|
47
50
|
const codeLanguage = resolveAimdCodeEditorLanguage(type, meta) ?? "plaintext"
|
|
51
|
+
const numericInputAttributes: NumericInputAttributes = inputKind === "number"
|
|
52
|
+
? getNumericInputAttributes(type, node.definition?.kwargs)
|
|
53
|
+
: {}
|
|
54
|
+
const numericConstraintViolation = inputKind === "number"
|
|
55
|
+
? getNumericConstraintViolation(displayValue, type, node.definition?.kwargs)
|
|
56
|
+
: null
|
|
48
57
|
|
|
49
58
|
function onVarChange(rawValue: string) {
|
|
50
59
|
const parsed = parseVarInputValue(rawValue, type, inputKind, {
|
|
@@ -86,9 +95,14 @@ export default defineComponent({
|
|
|
86
95
|
}
|
|
87
96
|
|
|
88
97
|
// Default stacked widget
|
|
89
|
-
const renderStackedVar = (control: VNode, variantClass?: string): VNode =>
|
|
98
|
+
const renderStackedVar = (control: VNode, variantClass?: string | string[]): VNode =>
|
|
90
99
|
h("span", {
|
|
91
|
-
class: [
|
|
100
|
+
class: [
|
|
101
|
+
"aimd-rec-inline aimd-rec-inline--var-stacked aimd-field-wrapper aimd-field-wrapper--inline",
|
|
102
|
+
variantClass,
|
|
103
|
+
numericConstraintViolation ? "aimd-rec-inline--error" : undefined,
|
|
104
|
+
...extraClasses,
|
|
105
|
+
],
|
|
92
106
|
}, [
|
|
93
107
|
h("span", { class: "aimd-field aimd-field--no-style aimd-field__label" }, [
|
|
94
108
|
h("span", { class: "aimd-field__scope aimd-field__scope--var" }, getAimdRecorderScopeLabel("var", props.messages)),
|
|
@@ -179,6 +193,17 @@ export default defineComponent({
|
|
|
179
193
|
const htmlInputType = inputKind === "datetime"
|
|
180
194
|
? "datetime-local"
|
|
181
195
|
: (usesDecimalTextInput ? "text" : inputKind)
|
|
196
|
+
const nativeNumericAttrs: NumericInputAttributes = inputKind === "number" && htmlInputType === "number"
|
|
197
|
+
? numericInputAttributes
|
|
198
|
+
: {}
|
|
199
|
+
|
|
200
|
+
function syncNumberValidity(control: HTMLInputElement) {
|
|
201
|
+
if (inputKind !== "number") {
|
|
202
|
+
return
|
|
203
|
+
}
|
|
204
|
+
const violation = getNumericConstraintViolation(control.value, type, node.definition?.kwargs)
|
|
205
|
+
control.setCustomValidity(violation ?? "")
|
|
206
|
+
}
|
|
182
207
|
|
|
183
208
|
return renderStackedVar(
|
|
184
209
|
h("input", {
|
|
@@ -186,17 +211,30 @@ export default defineComponent({
|
|
|
186
211
|
class: "aimd-rec-inline__input aimd-rec-inline__input--stacked",
|
|
187
212
|
type: htmlInputType,
|
|
188
213
|
inputmode: inputKind === "number" ? (isIntegerInput ? "numeric" : "decimal") : undefined,
|
|
214
|
+
min: nativeNumericAttrs.min,
|
|
215
|
+
max: nativeNumericAttrs.max,
|
|
189
216
|
disabled,
|
|
190
217
|
placeholder,
|
|
191
218
|
step: inputKind === "number"
|
|
192
|
-
? (isIntegerInput ? "1" : undefined)
|
|
219
|
+
? (nativeNumericAttrs.step ?? (isIntegerInput ? "1" : undefined))
|
|
193
220
|
: (inputKind === "time" ? "1" : undefined),
|
|
221
|
+
title: numericConstraintViolation ?? undefined,
|
|
222
|
+
"aria-invalid": numericConstraintViolation ? "true" : undefined,
|
|
194
223
|
value: displayValue,
|
|
195
|
-
onVnodeMounted: (vnode: any) =>
|
|
196
|
-
|
|
224
|
+
onVnodeMounted: (vnode: any) => {
|
|
225
|
+
const el = vnode.el as HTMLInputElement
|
|
226
|
+
syncCompactControlLayout(el)
|
|
227
|
+
syncNumberValidity(el)
|
|
228
|
+
},
|
|
229
|
+
onVnodeUpdated: (vnode: any) => {
|
|
230
|
+
const el = vnode.el as HTMLInputElement
|
|
231
|
+
syncCompactControlLayout(el)
|
|
232
|
+
syncNumberValidity(el)
|
|
233
|
+
},
|
|
197
234
|
onInput: (event: Event) => {
|
|
198
235
|
const el = event.target as HTMLInputElement
|
|
199
236
|
syncCompactControlLayout(el)
|
|
237
|
+
syncNumberValidity(el)
|
|
200
238
|
onVarChange(el.value)
|
|
201
239
|
},
|
|
202
240
|
onBlur: onVarBlur,
|
|
@@ -395,6 +395,47 @@ describe('getQuizDefaultValue', () => {
|
|
|
395
395
|
expect(getQuizDefaultValue(quiz as any)).toEqual([])
|
|
396
396
|
})
|
|
397
397
|
|
|
398
|
+
it('returns structured defaults for choice quiz with followups', () => {
|
|
399
|
+
const quiz = {
|
|
400
|
+
id: 'q1', type: 'choice', stem: 'Q?',
|
|
401
|
+
options: [
|
|
402
|
+
{
|
|
403
|
+
key: 'yes',
|
|
404
|
+
text: 'Yes',
|
|
405
|
+
followups: [
|
|
406
|
+
{ key: 'years', type: 'int', required: true, default: 5 },
|
|
407
|
+
{ key: 'unit', type: 'str', required: false },
|
|
408
|
+
],
|
|
409
|
+
},
|
|
410
|
+
{ key: 'no', text: 'No' },
|
|
411
|
+
],
|
|
412
|
+
default: 'yes',
|
|
413
|
+
}
|
|
414
|
+
expect(getQuizDefaultValue(quiz as any)).toEqual({
|
|
415
|
+
selected: 'yes',
|
|
416
|
+
followups: {
|
|
417
|
+
yes: {
|
|
418
|
+
years: 5,
|
|
419
|
+
},
|
|
420
|
+
},
|
|
421
|
+
})
|
|
422
|
+
})
|
|
423
|
+
|
|
424
|
+
it('returns nullable boolean default for true/false quiz', () => {
|
|
425
|
+
expect(getQuizDefaultValue({
|
|
426
|
+
id: 'q1',
|
|
427
|
+
type: 'true_false',
|
|
428
|
+
stem: 'Q?',
|
|
429
|
+
} as any)).toBeNull()
|
|
430
|
+
|
|
431
|
+
expect(getQuizDefaultValue({
|
|
432
|
+
id: 'q2',
|
|
433
|
+
type: 'true_false',
|
|
434
|
+
stem: 'Q?',
|
|
435
|
+
default: false,
|
|
436
|
+
} as any)).toBe(false)
|
|
437
|
+
})
|
|
438
|
+
|
|
398
439
|
it('returns blank map for blank quiz', () => {
|
|
399
440
|
const quiz = {
|
|
400
441
|
id: 'q1', type: 'blank', stem: 'Fill ____',
|
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
formatDateForInput,
|
|
12
12
|
getVarInputDisplayValue,
|
|
13
13
|
parseVarInputValue,
|
|
14
|
+
getNumericConstraintViolation,
|
|
15
|
+
getNumericFieldConstraints,
|
|
16
|
+
getNumericInputAttributes,
|
|
14
17
|
calculateVarStackWidth,
|
|
15
18
|
syncAutoWrapTextareaHeight,
|
|
16
19
|
} from '../useVarHelpers'
|
|
@@ -110,6 +113,47 @@ describe('getVarInputKind', () => {
|
|
|
110
113
|
})
|
|
111
114
|
})
|
|
112
115
|
|
|
116
|
+
// ---------------------------------------------------------------------------
|
|
117
|
+
// Numeric Pydantic-style constraints
|
|
118
|
+
// ---------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
describe('numeric field constraints', () => {
|
|
121
|
+
it('reads Pydantic-style numeric constraints only for numeric var types', () => {
|
|
122
|
+
expect(getNumericFieldConstraints('float', { gt: 0, le: 100, multiple_of: 0.5 })).toEqual({
|
|
123
|
+
gt: 0,
|
|
124
|
+
le: 100,
|
|
125
|
+
multiple_of: 0.5,
|
|
126
|
+
})
|
|
127
|
+
expect(getNumericFieldConstraints('str', { gt: 0 })).toEqual({})
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('maps inclusive native input attributes from numeric constraints', () => {
|
|
131
|
+
expect(getNumericInputAttributes('int', { ge: 0, le: 10, multiple_of: 2 })).toEqual({
|
|
132
|
+
min: 0,
|
|
133
|
+
max: 10,
|
|
134
|
+
step: 2,
|
|
135
|
+
})
|
|
136
|
+
expect(getNumericInputAttributes('float', { gt: 0, lt: 1 })).toEqual({
|
|
137
|
+
min: 0,
|
|
138
|
+
max: 1,
|
|
139
|
+
step: undefined,
|
|
140
|
+
})
|
|
141
|
+
})
|
|
142
|
+
|
|
143
|
+
it('validates strict and inclusive numeric bounds without treating empty values as violations', () => {
|
|
144
|
+
expect(getNumericConstraintViolation('', 'float', { gt: 0 })).toBeNull()
|
|
145
|
+
expect(getNumericConstraintViolation(0, 'float', { gt: 0 })).toBe('Must be > 0')
|
|
146
|
+
expect(getNumericConstraintViolation(0, 'float', { ge: 0 })).toBeNull()
|
|
147
|
+
expect(getNumericConstraintViolation(10, 'float', { lt: 10 })).toBe('Must be < 10')
|
|
148
|
+
expect(getNumericConstraintViolation(10, 'float', { le: 10 })).toBeNull()
|
|
149
|
+
})
|
|
150
|
+
|
|
151
|
+
it('validates numeric multiples', () => {
|
|
152
|
+
expect(getNumericConstraintViolation(4, 'int', { multiple_of: 2 })).toBeNull()
|
|
153
|
+
expect(getNumericConstraintViolation(5, 'int', { multiple_of: 2 })).toBe('Must be a multiple of 2')
|
|
154
|
+
})
|
|
155
|
+
})
|
|
156
|
+
|
|
113
157
|
// ---------------------------------------------------------------------------
|
|
114
158
|
// unwrapStructuredValue
|
|
115
159
|
// ---------------------------------------------------------------------------
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
import { type Ref } from "vue"
|
|
2
2
|
import type { AimdClientAssignerField } from "@airalogy/aimd-core/types"
|
|
3
3
|
import { applyClientAssigners } from "../client-assigner"
|
|
4
|
+
import type { ClientAssignerFieldDefinitions } from "../client-assigner"
|
|
4
5
|
import type { AimdProtocolRecordData } from "../types"
|
|
5
6
|
|
|
6
7
|
export interface ClientAssignerRunnerOptions {
|
|
7
8
|
readonly: () => boolean
|
|
8
9
|
clientAssigners: Ref<AimdClientAssignerField[]>
|
|
10
|
+
fieldDefinitions?: () => ClientAssignerFieldDefinitions
|
|
9
11
|
localRecord: AimdProtocolRecordData
|
|
10
12
|
onError: (message: string) => void
|
|
11
13
|
emitRecordUpdate: () => void
|
|
@@ -16,6 +18,7 @@ export function useClientAssignerRunner(options: ClientAssignerRunnerOptions) {
|
|
|
16
18
|
const {
|
|
17
19
|
readonly: isReadonly,
|
|
18
20
|
clientAssigners,
|
|
21
|
+
fieldDefinitions,
|
|
19
22
|
localRecord,
|
|
20
23
|
onError,
|
|
21
24
|
emitRecordUpdate,
|
|
@@ -28,7 +31,10 @@ export function useClientAssignerRunner(options: ClientAssignerRunnerOptions) {
|
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
try {
|
|
31
|
-
return applyClientAssigners(clientAssigners.value, localRecord.var,
|
|
34
|
+
return applyClientAssigners(clientAssigners.value, localRecord.var, {
|
|
35
|
+
...opts,
|
|
36
|
+
fieldDefinitions: fieldDefinitions?.(),
|
|
37
|
+
}).changed
|
|
32
38
|
}
|
|
33
39
|
catch (error) {
|
|
34
40
|
const message = error instanceof Error ? error.message : String(error)
|
|
@@ -205,20 +205,73 @@ export function normalizeVarTableFields(raw: unknown): AimdVarTableField[] {
|
|
|
205
205
|
// Quiz default values
|
|
206
206
|
// ---------------------------------------------------------------------------
|
|
207
207
|
|
|
208
|
+
type ChoiceFollowupPrimitive = string | number | boolean
|
|
209
|
+
|
|
210
|
+
function quizHasChoiceFollowups(quiz: AimdQuizField): boolean {
|
|
211
|
+
return quiz.type === "choice"
|
|
212
|
+
&& Array.isArray(quiz.options)
|
|
213
|
+
&& quiz.options.some(option => Array.isArray(option.followups) && option.followups.length > 0)
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
function buildChoiceFollowupDefaultMap(
|
|
217
|
+
quiz: AimdQuizField,
|
|
218
|
+
selectedKeys: string[],
|
|
219
|
+
): Record<string, Record<string, ChoiceFollowupPrimitive>> {
|
|
220
|
+
const selectedKeySet = new Set(selectedKeys)
|
|
221
|
+
const followups: Record<string, Record<string, ChoiceFollowupPrimitive>> = {}
|
|
222
|
+
|
|
223
|
+
for (const option of quiz.options || []) {
|
|
224
|
+
if (!selectedKeySet.has(option.key) || !Array.isArray(option.followups)) {
|
|
225
|
+
continue
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
const fieldDefaults: Record<string, ChoiceFollowupPrimitive> = {}
|
|
229
|
+
for (const followup of option.followups) {
|
|
230
|
+
if (followup.default !== undefined) {
|
|
231
|
+
fieldDefaults[followup.key] = followup.default
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (Object.keys(fieldDefaults).length > 0) {
|
|
235
|
+
followups[option.key] = fieldDefaults
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
|
|
239
|
+
return followups
|
|
240
|
+
}
|
|
241
|
+
|
|
208
242
|
export function getQuizDefaultValue(quiz: AimdQuizField): unknown {
|
|
209
243
|
if (quiz.type === "choice") {
|
|
210
244
|
const optionKeys = new Set((quiz.options || []).map(option => option.key))
|
|
245
|
+
const hasFollowups = quizHasChoiceFollowups(quiz)
|
|
211
246
|
if (quiz.mode === "multiple") {
|
|
247
|
+
let selected: string[] = []
|
|
212
248
|
if (Array.isArray(quiz.default)) {
|
|
213
|
-
|
|
249
|
+
selected = quiz.default.filter((item): item is string => typeof item === "string" && optionKeys.has(item))
|
|
250
|
+
}
|
|
251
|
+
if (hasFollowups) {
|
|
252
|
+
return {
|
|
253
|
+
selected,
|
|
254
|
+
followups: buildChoiceFollowupDefaultMap(quiz, selected),
|
|
255
|
+
}
|
|
214
256
|
}
|
|
215
|
-
return
|
|
257
|
+
return selected
|
|
216
258
|
}
|
|
217
259
|
|
|
260
|
+
let selected = ""
|
|
218
261
|
if (typeof quiz.default === "string" && optionKeys.has(quiz.default)) {
|
|
219
|
-
|
|
262
|
+
selected = quiz.default
|
|
220
263
|
}
|
|
221
|
-
|
|
264
|
+
if (hasFollowups) {
|
|
265
|
+
return {
|
|
266
|
+
selected,
|
|
267
|
+
followups: buildChoiceFollowupDefaultMap(quiz, selected ? [selected] : []),
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
return selected
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
if (quiz.type === "true_false") {
|
|
274
|
+
return typeof quiz.default === "boolean" ? quiz.default : null
|
|
222
275
|
}
|
|
223
276
|
|
|
224
277
|
if (quiz.type === "blank") {
|
|
@@ -29,6 +29,20 @@ export interface VarInputValueOptions extends VarInputKindOptions {
|
|
|
29
29
|
fieldMeta?: Record<string, unknown>
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
export interface AimdNumericFieldConstraints {
|
|
33
|
+
gt?: number
|
|
34
|
+
ge?: number
|
|
35
|
+
lt?: number
|
|
36
|
+
le?: number
|
|
37
|
+
multiple_of?: number
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export interface NumericInputAttributes {
|
|
41
|
+
min?: number
|
|
42
|
+
max?: number
|
|
43
|
+
step?: number
|
|
44
|
+
}
|
|
45
|
+
|
|
32
46
|
function resolveOverrideInputKind(inputType: string | undefined, codeLanguage: string | undefined): VarInputKind | undefined {
|
|
33
47
|
if (isAimdCodeEditorType(undefined, { inputType, codeLanguage })) {
|
|
34
48
|
return 'code'
|
|
@@ -87,6 +101,11 @@ export function normalizeVarTypeName(type: string | undefined): string {
|
|
|
87
101
|
return normalizeAimdTypeName(type)
|
|
88
102
|
}
|
|
89
103
|
|
|
104
|
+
export function isNumericVarType(type: string | undefined): boolean {
|
|
105
|
+
const normalized = normalizeVarTypeName(type)
|
|
106
|
+
return normalized === "float" || normalized === "int" || normalized === "integer" || normalized === "number"
|
|
107
|
+
}
|
|
108
|
+
|
|
90
109
|
export function getVarInputKind(type: string | undefined, options: VarInputKindOptions = {}): VarInputKind {
|
|
91
110
|
const override = resolveOverrideInputKind(options.inputType, options.codeLanguage)
|
|
92
111
|
if (override) {
|
|
@@ -135,6 +154,100 @@ export function getVarInputKind(type: string | undefined, options: VarInputKindO
|
|
|
135
154
|
return "text"
|
|
136
155
|
}
|
|
137
156
|
|
|
157
|
+
function toFiniteNumber(value: unknown): number | undefined {
|
|
158
|
+
if (typeof value === "number") {
|
|
159
|
+
return Number.isFinite(value) ? value : undefined
|
|
160
|
+
}
|
|
161
|
+
if (typeof value === "string" && value.trim()) {
|
|
162
|
+
const parsed = Number(value)
|
|
163
|
+
return Number.isFinite(parsed) ? parsed : undefined
|
|
164
|
+
}
|
|
165
|
+
return undefined
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
export function getNumericFieldConstraints(
|
|
169
|
+
type: string | undefined,
|
|
170
|
+
kwargs?: Record<string, unknown>,
|
|
171
|
+
): AimdNumericFieldConstraints {
|
|
172
|
+
if (!isNumericVarType(type) || !kwargs) {
|
|
173
|
+
return {}
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const constraints: AimdNumericFieldConstraints = {}
|
|
177
|
+
const gt = toFiniteNumber(kwargs.gt)
|
|
178
|
+
const ge = toFiniteNumber(kwargs.ge)
|
|
179
|
+
const lt = toFiniteNumber(kwargs.lt)
|
|
180
|
+
const le = toFiniteNumber(kwargs.le)
|
|
181
|
+
const multipleOf = toFiniteNumber(kwargs.multiple_of)
|
|
182
|
+
|
|
183
|
+
if (gt !== undefined) constraints.gt = gt
|
|
184
|
+
if (ge !== undefined) constraints.ge = ge
|
|
185
|
+
if (lt !== undefined) constraints.lt = lt
|
|
186
|
+
if (le !== undefined) constraints.le = le
|
|
187
|
+
if (multipleOf !== undefined && multipleOf > 0) constraints.multiple_of = multipleOf
|
|
188
|
+
|
|
189
|
+
return constraints
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
export function getNumericInputAttributes(
|
|
193
|
+
type: string | undefined,
|
|
194
|
+
kwargs?: Record<string, unknown>,
|
|
195
|
+
): NumericInputAttributes {
|
|
196
|
+
const constraints = getNumericFieldConstraints(type, kwargs)
|
|
197
|
+
const lowerBounds = [constraints.gt, constraints.ge].filter((value): value is number => value !== undefined)
|
|
198
|
+
const upperBounds = [constraints.lt, constraints.le].filter((value): value is number => value !== undefined)
|
|
199
|
+
|
|
200
|
+
return {
|
|
201
|
+
min: lowerBounds.length ? Math.max(...lowerBounds) : undefined,
|
|
202
|
+
max: upperBounds.length ? Math.min(...upperBounds) : undefined,
|
|
203
|
+
step: constraints.multiple_of,
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
export function getNumericConstraintViolation(
|
|
208
|
+
value: unknown,
|
|
209
|
+
type: string | undefined,
|
|
210
|
+
kwargs?: Record<string, unknown>,
|
|
211
|
+
): string | null {
|
|
212
|
+
const constraints = getNumericFieldConstraints(type, kwargs)
|
|
213
|
+
if (Object.keys(constraints).length === 0) {
|
|
214
|
+
return null
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
if (value === null || typeof value === "undefined") {
|
|
218
|
+
return null
|
|
219
|
+
}
|
|
220
|
+
if (typeof value === "string" && value.trim() === "") {
|
|
221
|
+
return null
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const numericValue = toFiniteNumber(value)
|
|
225
|
+
if (numericValue === undefined) {
|
|
226
|
+
return null
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (constraints.gt !== undefined && !(numericValue > constraints.gt)) {
|
|
230
|
+
return `Must be > ${constraints.gt}`
|
|
231
|
+
}
|
|
232
|
+
if (constraints.ge !== undefined && !(numericValue >= constraints.ge)) {
|
|
233
|
+
return `Must be >= ${constraints.ge}`
|
|
234
|
+
}
|
|
235
|
+
if (constraints.lt !== undefined && !(numericValue < constraints.lt)) {
|
|
236
|
+
return `Must be < ${constraints.lt}`
|
|
237
|
+
}
|
|
238
|
+
if (constraints.le !== undefined && !(numericValue <= constraints.le)) {
|
|
239
|
+
return `Must be <= ${constraints.le}`
|
|
240
|
+
}
|
|
241
|
+
if (constraints.multiple_of !== undefined) {
|
|
242
|
+
const quotient = numericValue / constraints.multiple_of
|
|
243
|
+
if (Math.abs(quotient - Math.round(quotient)) > 1e-9) {
|
|
244
|
+
return `Must be a multiple of ${constraints.multiple_of}`
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
return null
|
|
249
|
+
}
|
|
250
|
+
|
|
138
251
|
// ---------------------------------------------------------------------------
|
|
139
252
|
// Structured-value helpers
|
|
140
253
|
// ---------------------------------------------------------------------------
|
|
@@ -304,8 +304,8 @@ function buildWorkbenchSyntax(
|
|
|
304
304
|
case 'check':
|
|
305
305
|
return `{{check|${(fields.name || '').trim() || 'my_check'}}}`
|
|
306
306
|
case 'quiz': {
|
|
307
|
-
const id = (fields.id || '').trim() || 'quiz_choice_1'
|
|
308
307
|
const quizType = (fields.quizType || '').trim() || 'choice'
|
|
308
|
+
const id = (fields.id || '').trim() || `quiz_${quizType}_1`
|
|
309
309
|
const stem = fields.stem || 'Fill the question stem'
|
|
310
310
|
if (quizType === 'open') {
|
|
311
311
|
return [
|
|
@@ -391,11 +391,13 @@ function buildFieldSyntax(
|
|
|
391
391
|
return buildWorkbenchSyntax('check', {
|
|
392
392
|
name: id || 'my_check',
|
|
393
393
|
})
|
|
394
|
-
case 'quiz':
|
|
394
|
+
case 'quiz': {
|
|
395
|
+
const quizType = options?.quizType?.trim() || 'choice'
|
|
395
396
|
return buildWorkbenchSyntax('quiz', {
|
|
396
|
-
id: id ||
|
|
397
|
-
quizType
|
|
397
|
+
id: id || `quiz_${quizType}_1`,
|
|
398
|
+
quizType,
|
|
398
399
|
})
|
|
400
|
+
}
|
|
399
401
|
}
|
|
400
402
|
}
|
|
401
403
|
|
|
@@ -524,6 +526,7 @@ export function scanWorkbenchFields(content: string): AimdWorkbenchFieldDescript
|
|
|
524
526
|
export function generateNextWorkbenchFieldId(
|
|
525
527
|
fields: AimdWorkbenchFieldDescriptor[],
|
|
526
528
|
fieldType: AimdWorkbenchFieldType,
|
|
529
|
+
quizType?: string,
|
|
527
530
|
): string {
|
|
528
531
|
const existingIds = new Set(fields.map(field => field.id))
|
|
529
532
|
const base = fieldType === 'var'
|
|
@@ -534,7 +537,7 @@ export function generateNextWorkbenchFieldId(
|
|
|
534
537
|
? 'new_step'
|
|
535
538
|
: fieldType === 'check'
|
|
536
539
|
? 'new_check'
|
|
537
|
-
: '
|
|
540
|
+
: `quiz_${quizType || 'choice'}`
|
|
538
541
|
|
|
539
542
|
if (!existingIds.has(base)) {
|
|
540
543
|
return base
|
package/src/locales.ts
CHANGED
|
@@ -27,6 +27,7 @@ export interface AimdRecorderMessages {
|
|
|
27
27
|
choice: string
|
|
28
28
|
singleChoice: string
|
|
29
29
|
multipleChoice: string
|
|
30
|
+
trueFalse: string
|
|
30
31
|
blank: string
|
|
31
32
|
open: string
|
|
32
33
|
scale: string
|
|
@@ -195,6 +196,7 @@ const EN_US_MESSAGES: AimdRecorderMessages = {
|
|
|
195
196
|
choice: "choice",
|
|
196
197
|
singleChoice: "Single choice",
|
|
197
198
|
multipleChoice: "Multiple choice",
|
|
199
|
+
trueFalse: "True/false",
|
|
198
200
|
blank: "blank",
|
|
199
201
|
open: "open",
|
|
200
202
|
scale: "scale",
|
|
@@ -336,6 +338,7 @@ const ZH_CN_MESSAGES: AimdRecorderMessages = {
|
|
|
336
338
|
choice: "选择",
|
|
337
339
|
singleChoice: "单选",
|
|
338
340
|
multipleChoice: "多选",
|
|
341
|
+
trueFalse: "判断",
|
|
339
342
|
blank: "填空",
|
|
340
343
|
open: "开放",
|
|
341
344
|
scale: "量表",
|