@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
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@airalogy/aimd-recorder",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.
|
|
5
|
-
"description": "AIMD
|
|
4
|
+
"version": "1.16.0",
|
|
5
|
+
"description": "AIMD (Airalogy Markdown) recorder Vue components and UI",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -47,26 +47,20 @@
|
|
|
47
47
|
"dist",
|
|
48
48
|
"src"
|
|
49
49
|
],
|
|
50
|
-
"scripts": {
|
|
51
|
-
"type-check": "vue-tsc --noEmit",
|
|
52
|
-
"build": "vite build",
|
|
53
|
-
"dev": "vite build --watch",
|
|
54
|
-
"test": "vitest run --config vitest.config.ts"
|
|
55
|
-
},
|
|
56
50
|
"peerDependencies": {
|
|
57
51
|
"@vueuse/core": "^13.5.0",
|
|
58
52
|
"naive-ui": "2.41.0",
|
|
59
53
|
"vue": "^3.5.17"
|
|
60
54
|
},
|
|
61
55
|
"dependencies": {
|
|
62
|
-
"@airalogy/aimd-editor": "workspace:^",
|
|
63
|
-
"@airalogy/aimd-core": "workspace:^",
|
|
64
|
-
"@airalogy/aimd-renderer": "workspace:^",
|
|
65
56
|
"@milkdown/kit": "^7.18.0",
|
|
66
57
|
"monaco-editor": "^0.52.2",
|
|
67
58
|
"react": "^19.2.4",
|
|
68
59
|
"react-dom": "^19.2.4",
|
|
69
|
-
"seqviz": "^3.10.18"
|
|
60
|
+
"seqviz": "^3.10.18",
|
|
61
|
+
"@airalogy/aimd-core": "^2.6.0",
|
|
62
|
+
"@airalogy/aimd-renderer": "^2.5.0",
|
|
63
|
+
"@airalogy/aimd-editor": "^1.9.0"
|
|
70
64
|
},
|
|
71
65
|
"devDependencies": {
|
|
72
66
|
"@types/node": "^24.3.0",
|
|
@@ -84,5 +78,11 @@
|
|
|
84
78
|
"vite-tsconfig-paths": "^5.1.4",
|
|
85
79
|
"vue": "^3.5.17",
|
|
86
80
|
"vue-tsc": "^3.0.6"
|
|
81
|
+
},
|
|
82
|
+
"scripts": {
|
|
83
|
+
"type-check": "vue-tsc --noEmit",
|
|
84
|
+
"build": "vite build",
|
|
85
|
+
"dev": "vite build --watch",
|
|
86
|
+
"test": "vitest run --config vitest.config.ts"
|
|
87
87
|
}
|
|
88
|
-
}
|
|
88
|
+
}
|
|
@@ -176,6 +176,65 @@ describe('client-assigner: dependency ordering', () => {
|
|
|
176
176
|
expect(result.changed).toBe(false)
|
|
177
177
|
expect(values.y).toBe(0)
|
|
178
178
|
})
|
|
179
|
+
|
|
180
|
+
it('skips assigners when a numeric dependency violates field constraints', () => {
|
|
181
|
+
const assigners = [makeAssigner({
|
|
182
|
+
id: 'bmi',
|
|
183
|
+
function_source: 'function assign(fields) { var h = Number(fields.height_cm) / 100; return { bmi: Math.round((Number(fields.weight_kg) / (h * h)) * 10) / 10 }; }',
|
|
184
|
+
dependent_fields: ['height_cm', 'weight_kg'],
|
|
185
|
+
assigned_fields: ['bmi'],
|
|
186
|
+
})]
|
|
187
|
+
|
|
188
|
+
const values: Record<string, unknown> = { height_cm: -170, weight_kg: 70, bmi: '' }
|
|
189
|
+
const result = applyClientAssigners(assigners, values, {
|
|
190
|
+
fieldDefinitions: {
|
|
191
|
+
height_cm: { type: 'float', kwargs: { gt: 0 } },
|
|
192
|
+
weight_kg: { type: 'float', kwargs: { gt: 0 } },
|
|
193
|
+
},
|
|
194
|
+
})
|
|
195
|
+
|
|
196
|
+
expect(result.changed).toBe(false)
|
|
197
|
+
expect(values.bmi).toBe('')
|
|
198
|
+
})
|
|
199
|
+
|
|
200
|
+
it('runs assigners when constrained numeric dependencies are valid', () => {
|
|
201
|
+
const assigners = [makeAssigner({
|
|
202
|
+
id: 'bmi',
|
|
203
|
+
function_source: 'function assign(fields) { var h = Number(fields.height_cm) / 100; return { bmi: Math.round((Number(fields.weight_kg) / (h * h)) * 10) / 10 }; }',
|
|
204
|
+
dependent_fields: ['height_cm', 'weight_kg'],
|
|
205
|
+
assigned_fields: ['bmi'],
|
|
206
|
+
})]
|
|
207
|
+
|
|
208
|
+
const values: Record<string, unknown> = { height_cm: 170, weight_kg: 70, bmi: '' }
|
|
209
|
+
const result = applyClientAssigners(assigners, values, {
|
|
210
|
+
fieldDefinitions: {
|
|
211
|
+
height_cm: { type: 'float', kwargs: { gt: 0 } },
|
|
212
|
+
weight_kg: { type: 'float', kwargs: { gt: 0 } },
|
|
213
|
+
},
|
|
214
|
+
})
|
|
215
|
+
|
|
216
|
+
expect(result.changed).toBe(true)
|
|
217
|
+
expect(values.bmi).toBe(24.2)
|
|
218
|
+
})
|
|
219
|
+
|
|
220
|
+
it('skips assigners when a numeric dependency is not finite', () => {
|
|
221
|
+
const assigners = [makeAssigner({
|
|
222
|
+
id: 'calc',
|
|
223
|
+
function_source: 'function assign(fields) { return { y: Number(fields.x) + 1 }; }',
|
|
224
|
+
dependent_fields: ['x'],
|
|
225
|
+
assigned_fields: ['y'],
|
|
226
|
+
})]
|
|
227
|
+
|
|
228
|
+
const values: Record<string, unknown> = { x: 'abc', y: 0 }
|
|
229
|
+
const result = applyClientAssigners(assigners, values, {
|
|
230
|
+
fieldDefinitions: {
|
|
231
|
+
x: { type: 'float' },
|
|
232
|
+
},
|
|
233
|
+
})
|
|
234
|
+
|
|
235
|
+
expect(result.changed).toBe(false)
|
|
236
|
+
expect(values.y).toBe(0)
|
|
237
|
+
})
|
|
179
238
|
})
|
|
180
239
|
|
|
181
240
|
// ---------------------------------------------------------------------------
|
|
@@ -146,6 +146,118 @@ describe('AimdQuizRecorder', () => {
|
|
|
146
146
|
expect(wrapper.text()).not.toContain('Not the best answer.')
|
|
147
147
|
})
|
|
148
148
|
|
|
149
|
+
it('renders true/false quizzes and emits boolean answers', async () => {
|
|
150
|
+
const wrapper = mount(AimdQuizRecorder, {
|
|
151
|
+
props: {
|
|
152
|
+
locale: 'en-US',
|
|
153
|
+
quiz: {
|
|
154
|
+
id: 'quiz_true_false',
|
|
155
|
+
type: 'true_false',
|
|
156
|
+
stem: 'The sample stayed cold.',
|
|
157
|
+
options: [
|
|
158
|
+
{ key: 'true', text: 'True', explanation: 'Correct.' },
|
|
159
|
+
{ key: 'false', text: 'False', explanation: 'Incorrect.' },
|
|
160
|
+
],
|
|
161
|
+
},
|
|
162
|
+
modelValue: null,
|
|
163
|
+
choiceOptionExplanationMode: 'selected',
|
|
164
|
+
},
|
|
165
|
+
})
|
|
166
|
+
|
|
167
|
+
const trueInput = wrapper.find('input[data-rec-focus-key="quiz:quiz_true_false:true_false:true"]')
|
|
168
|
+
expect(trueInput.exists()).toBe(true)
|
|
169
|
+
|
|
170
|
+
await trueInput.setValue()
|
|
171
|
+
|
|
172
|
+
const emitted = wrapper.emitted('update:modelValue') || []
|
|
173
|
+
expect(emitted[emitted.length - 1]?.[0]).toBe(true)
|
|
174
|
+
|
|
175
|
+
await wrapper.setProps({ modelValue: true })
|
|
176
|
+
|
|
177
|
+
expect(wrapper.text()).toContain('Correct.')
|
|
178
|
+
expect(wrapper.text()).not.toContain('Incorrect.')
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
it('renders selected choice followups and emits structured updates', async () => {
|
|
182
|
+
const wrapper = mount(AimdQuizRecorder, {
|
|
183
|
+
props: {
|
|
184
|
+
locale: 'en-US',
|
|
185
|
+
quiz: {
|
|
186
|
+
id: 'quiz_smoking',
|
|
187
|
+
type: 'choice',
|
|
188
|
+
stem: 'Do you smoke?',
|
|
189
|
+
mode: 'single',
|
|
190
|
+
options: [
|
|
191
|
+
{
|
|
192
|
+
key: 'yes',
|
|
193
|
+
text: 'Yes',
|
|
194
|
+
followups: [
|
|
195
|
+
{ key: 'years', type: 'int', required: true, title: 'Years' },
|
|
196
|
+
{ key: 'cigarettes_per_day', type: 'float', required: true, title: 'Cigarettes per day', unit: 'sticks/day' },
|
|
197
|
+
],
|
|
198
|
+
},
|
|
199
|
+
{ key: 'no', text: 'No' },
|
|
200
|
+
],
|
|
201
|
+
},
|
|
202
|
+
modelValue: {
|
|
203
|
+
selected: 'yes',
|
|
204
|
+
followups: {
|
|
205
|
+
yes: {
|
|
206
|
+
years: 3,
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
})
|
|
212
|
+
|
|
213
|
+
expect(wrapper.text()).toContain('Years')
|
|
214
|
+
expect(wrapper.text()).toContain('Cigarettes per day')
|
|
215
|
+
expect(wrapper.text()).toContain('sticks/day')
|
|
216
|
+
|
|
217
|
+
await wrapper
|
|
218
|
+
.find('input[data-rec-focus-key="quiz:quiz_smoking:single:yes:followup:cigarettes_per_day"]')
|
|
219
|
+
.setValue('12.5')
|
|
220
|
+
|
|
221
|
+
const emitted = wrapper.emitted('update:modelValue') || []
|
|
222
|
+
expect(emitted[emitted.length - 1]?.[0]).toEqual({
|
|
223
|
+
selected: 'yes',
|
|
224
|
+
followups: {
|
|
225
|
+
yes: {
|
|
226
|
+
years: 3,
|
|
227
|
+
cigarettes_per_day: 12.5,
|
|
228
|
+
},
|
|
229
|
+
},
|
|
230
|
+
})
|
|
231
|
+
})
|
|
232
|
+
|
|
233
|
+
it('keeps legacy selected choice values readable for followup-enabled quizzes', () => {
|
|
234
|
+
const wrapper = mount(AimdQuizRecorder, {
|
|
235
|
+
props: {
|
|
236
|
+
locale: 'en-US',
|
|
237
|
+
quiz: {
|
|
238
|
+
id: 'quiz_legacy_smoking',
|
|
239
|
+
type: 'choice',
|
|
240
|
+
stem: 'Do you smoke?',
|
|
241
|
+
mode: 'single',
|
|
242
|
+
options: [
|
|
243
|
+
{
|
|
244
|
+
key: 'yes',
|
|
245
|
+
text: 'Yes',
|
|
246
|
+
followups: [
|
|
247
|
+
{ key: 'years', type: 'int', required: true, title: 'Years' },
|
|
248
|
+
],
|
|
249
|
+
},
|
|
250
|
+
{ key: 'no', text: 'No' },
|
|
251
|
+
],
|
|
252
|
+
},
|
|
253
|
+
modelValue: 'yes',
|
|
254
|
+
},
|
|
255
|
+
})
|
|
256
|
+
|
|
257
|
+
expect((wrapper.find('input[type="radio"][value="yes"]').element as HTMLInputElement).checked).toBe(true)
|
|
258
|
+
expect(wrapper.text()).toContain('Years')
|
|
259
|
+
})
|
|
260
|
+
|
|
149
261
|
it('shows local scale grading only after submission when configured', async () => {
|
|
150
262
|
const wrapper = mount(AimdQuizRecorder, {
|
|
151
263
|
props: {
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import { flushPromises, mount } from '@vue/test-utils'
|
|
2
|
+
import { describe, expect, it, vi } from 'vitest'
|
|
3
|
+
|
|
4
|
+
const mocks = vi.hoisted(() => {
|
|
5
|
+
const quizNode = {
|
|
6
|
+
type: 'aimd',
|
|
7
|
+
fieldType: 'quiz',
|
|
8
|
+
id: 'quiz_followup',
|
|
9
|
+
raw: '',
|
|
10
|
+
quizType: 'choice',
|
|
11
|
+
stem: 'Do you smoke?',
|
|
12
|
+
mode: 'single',
|
|
13
|
+
options: [
|
|
14
|
+
{
|
|
15
|
+
key: 'yes',
|
|
16
|
+
text: 'Yes',
|
|
17
|
+
followups: [
|
|
18
|
+
{ key: 'years', type: 'int', required: true, title: 'Years' },
|
|
19
|
+
],
|
|
20
|
+
},
|
|
21
|
+
{ key: 'no', text: 'No' },
|
|
22
|
+
],
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const fields = {
|
|
26
|
+
var: [],
|
|
27
|
+
var_definitions: [],
|
|
28
|
+
var_table: [],
|
|
29
|
+
client_assigner: [],
|
|
30
|
+
quiz: [
|
|
31
|
+
{
|
|
32
|
+
id: 'quiz_followup',
|
|
33
|
+
type: 'choice',
|
|
34
|
+
stem: 'Do you smoke?',
|
|
35
|
+
mode: 'single',
|
|
36
|
+
options: quizNode.options,
|
|
37
|
+
},
|
|
38
|
+
],
|
|
39
|
+
step: [],
|
|
40
|
+
check: [],
|
|
41
|
+
ref_step: [],
|
|
42
|
+
ref_var: [],
|
|
43
|
+
ref_fig: [],
|
|
44
|
+
cite: [],
|
|
45
|
+
fig: [],
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
return {
|
|
49
|
+
parseAndExtract: vi.fn(() => fields),
|
|
50
|
+
renderToVue: vi.fn(async (
|
|
51
|
+
_content: string,
|
|
52
|
+
options: { aimdRenderers: { quiz: (node: unknown) => unknown } },
|
|
53
|
+
) => ({
|
|
54
|
+
fields,
|
|
55
|
+
nodes: [options.aimdRenderers.quiz(quizNode)],
|
|
56
|
+
})),
|
|
57
|
+
}
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
vi.mock('@airalogy/aimd-renderer', async (importOriginal) => {
|
|
61
|
+
const actual = await importOriginal<typeof import('@airalogy/aimd-renderer')>()
|
|
62
|
+
return {
|
|
63
|
+
...actual,
|
|
64
|
+
parseAndExtract: mocks.parseAndExtract,
|
|
65
|
+
renderToVue: mocks.renderToVue,
|
|
66
|
+
}
|
|
67
|
+
})
|
|
68
|
+
|
|
69
|
+
import AimdRecorder from '../components/AimdRecorder.vue'
|
|
70
|
+
|
|
71
|
+
describe('AimdRecorder quiz followups', () => {
|
|
72
|
+
it('rebuilds inline quiz widgets so followups appear after selecting an option', async () => {
|
|
73
|
+
const wrapper = mount(AimdRecorder, {
|
|
74
|
+
props: {
|
|
75
|
+
content: 'mock content',
|
|
76
|
+
locale: 'en-US',
|
|
77
|
+
modelValue: { var: {}, step: {}, check: {}, quiz: {} },
|
|
78
|
+
},
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
await flushPromises()
|
|
82
|
+
await wrapper.vm.$nextTick()
|
|
83
|
+
|
|
84
|
+
expect(wrapper.text()).not.toContain('Years')
|
|
85
|
+
|
|
86
|
+
const yesInput = wrapper.find('input[type="radio"][value="yes"]')
|
|
87
|
+
expect(yesInput.exists()).toBe(true)
|
|
88
|
+
|
|
89
|
+
await yesInput.setValue()
|
|
90
|
+
await flushPromises()
|
|
91
|
+
await wrapper.vm.$nextTick()
|
|
92
|
+
|
|
93
|
+
expect(wrapper.text()).toContain('Years')
|
|
94
|
+
expect(wrapper.find('input[data-rec-focus-key="quiz:quiz_followup:single:yes:followup:years"]').exists()).toBe(true)
|
|
95
|
+
expect(mocks.renderToVue).toHaveBeenCalledTimes(2)
|
|
96
|
+
})
|
|
97
|
+
})
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { mount } from '@vue/test-utils'
|
|
1
|
+
import { flushPromises, mount } from '@vue/test-utils'
|
|
2
2
|
import { h, nextTick, reactive } from 'vue'
|
|
3
3
|
import { afterEach, describe, expect, it, vi } from 'vitest'
|
|
4
4
|
import type { AimdCheckNode, AimdStepNode } from '@airalogy/aimd-core/types'
|
|
@@ -7,6 +7,46 @@ import { createAimdRecorderMessages } from '../locales'
|
|
|
7
7
|
import { AimdCheckField, AimdStepField } from '../components/AimdStepCheckField.vue'
|
|
8
8
|
import { createEmptyStepRecordItem, startStepTimer } from '../composables/useStepTimers'
|
|
9
9
|
|
|
10
|
+
vi.mock('@airalogy/aimd-editor/vue', async () => {
|
|
11
|
+
const { defineComponent, h } = await import('vue')
|
|
12
|
+
|
|
13
|
+
return {
|
|
14
|
+
AimdEditor: defineComponent({
|
|
15
|
+
name: 'AimdEditorMock',
|
|
16
|
+
props: {
|
|
17
|
+
modelValue: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: '',
|
|
20
|
+
},
|
|
21
|
+
},
|
|
22
|
+
emits: ['update:modelValue'],
|
|
23
|
+
setup(props, { emit }) {
|
|
24
|
+
return () => h('textarea', {
|
|
25
|
+
class: 'aimd-editor-mock',
|
|
26
|
+
value: props.modelValue,
|
|
27
|
+
onInput: (event: Event) => emit('update:modelValue', (event.target as HTMLTextAreaElement).value),
|
|
28
|
+
})
|
|
29
|
+
},
|
|
30
|
+
}),
|
|
31
|
+
}
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
vi.mock('@airalogy/aimd-renderer', async () => {
|
|
35
|
+
const { h } = await import('vue')
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
renderToVue: async (content: string) => ({
|
|
39
|
+
nodes: [h('div', { class: 'aimd-rendered-note' }, content)],
|
|
40
|
+
fields: {},
|
|
41
|
+
}),
|
|
42
|
+
}
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
async function flushStepFieldAsync() {
|
|
46
|
+
await flushPromises()
|
|
47
|
+
await nextTick()
|
|
48
|
+
}
|
|
49
|
+
|
|
10
50
|
describe('AimdStepField', () => {
|
|
11
51
|
afterEach(() => {
|
|
12
52
|
vi.useRealTimers()
|
|
@@ -68,7 +108,7 @@ describe('AimdStepField', () => {
|
|
|
68
108
|
expect(wrapper.find('input[type="checkbox"]').exists()).toBe(true)
|
|
69
109
|
})
|
|
70
110
|
|
|
71
|
-
it('shows the annotation detail when a note already exists in auto mode', () => {
|
|
111
|
+
it('shows the annotation detail when a note already exists in auto mode', async () => {
|
|
72
112
|
const state = reactive({
|
|
73
113
|
...createEmptyStepRecordItem(),
|
|
74
114
|
annotation: 'Keep on ice',
|
|
@@ -80,6 +120,8 @@ describe('AimdStepField', () => {
|
|
|
80
120
|
},
|
|
81
121
|
})
|
|
82
122
|
|
|
123
|
+
await flushStepFieldAsync()
|
|
124
|
+
|
|
83
125
|
expect(wrapper.find('.aimd-step-field__details').exists()).toBe(true)
|
|
84
126
|
expect(wrapper.find('.aimd-step-field__detail--annotation').exists()).toBe(true)
|
|
85
127
|
expect(wrapper.text()).toContain('Timer')
|
|
@@ -96,7 +138,7 @@ describe('AimdStepField', () => {
|
|
|
96
138
|
})
|
|
97
139
|
|
|
98
140
|
await wrapper.find('.aimd-step-field__toggle--annotation').trigger('click')
|
|
99
|
-
await
|
|
141
|
+
await flushStepFieldAsync()
|
|
100
142
|
|
|
101
143
|
expect(wrapper.find('.aimd-step-field__details').exists()).toBe(true)
|
|
102
144
|
expect(wrapper.find('.aimd-step-field__detail--annotation').exists()).toBe(true)
|
|
@@ -135,6 +177,8 @@ describe('AimdStepField', () => {
|
|
|
135
177
|
},
|
|
136
178
|
})
|
|
137
179
|
|
|
180
|
+
await flushStepFieldAsync()
|
|
181
|
+
|
|
138
182
|
expect(wrapper.text()).toContain('ETA 1m 30s')
|
|
139
183
|
expect(wrapper.text()).toContain('Timer 0s')
|
|
140
184
|
expect(wrapper.find('.aimd-step-timer__controls .aimd-step-timer__btn').text()).toBe('Start')
|
|
@@ -14,7 +14,13 @@ describe('AimdVarField render behavior', () => {
|
|
|
14
14
|
})
|
|
15
15
|
|
|
16
16
|
it('resizes single-line inputs while the user types', () => {
|
|
17
|
-
expect(source).toMatch(/onInput: \(event: Event\) => \{\s*const el = event\.target as HTMLInputElement\s*syncCompactControlLayout\(el\)\s*onVarChange\(el\.value\)\s*\}/)
|
|
17
|
+
expect(source).toMatch(/onInput: \(event: Event\) => \{\s*const el = event\.target as HTMLInputElement\s*syncCompactControlLayout\(el\)\s*syncNumberValidity\(el\)\s*onVarChange\(el\.value\)\s*\}/)
|
|
18
|
+
})
|
|
19
|
+
|
|
20
|
+
it('applies Pydantic-style numeric constraints from AIMD kwargs', () => {
|
|
21
|
+
expect(source).toMatch(/getNumericInputAttributes\(type, node\.definition\?\.kwargs\)/)
|
|
22
|
+
expect(source).toMatch(/getNumericConstraintViolation\(displayValue, type, node\.definition\?\.kwargs\)/)
|
|
23
|
+
expect(source).toMatch(/control\.setCustomValidity\(violation \?\? ""\)/)
|
|
18
24
|
})
|
|
19
25
|
|
|
20
26
|
it('renders code-like vars with the dedicated code editor field', () => {
|
package/src/client-assigner.ts
CHANGED
|
@@ -1,8 +1,16 @@
|
|
|
1
1
|
import { validateClientAssignerFunctionSource } from "@airalogy/aimd-core/parser"
|
|
2
2
|
import type { AimdClientAssignerField } from "@airalogy/aimd-core/types"
|
|
3
|
+
import { getNumericConstraintViolation, isNumericVarType } from "./composables/useVarHelpers"
|
|
3
4
|
|
|
4
5
|
type ClientAssignerExecutor = (dependentFields: Record<string, unknown>) => unknown
|
|
5
6
|
|
|
7
|
+
export interface ClientAssignerFieldDefinition {
|
|
8
|
+
type?: string
|
|
9
|
+
kwargs?: Record<string, unknown>
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export type ClientAssignerFieldDefinitions = Record<string, ClientAssignerFieldDefinition | undefined>
|
|
13
|
+
|
|
6
14
|
const executorCache = new Map<string, ClientAssignerExecutor>()
|
|
7
15
|
|
|
8
16
|
const SAFE_MATH = Object.freeze({
|
|
@@ -82,6 +90,37 @@ function isReadyValue(value: unknown): boolean {
|
|
|
82
90
|
return true
|
|
83
91
|
}
|
|
84
92
|
|
|
93
|
+
function toFiniteNumber(value: unknown): number | undefined {
|
|
94
|
+
if (typeof value === "number") {
|
|
95
|
+
return Number.isFinite(value) ? value : undefined
|
|
96
|
+
}
|
|
97
|
+
if (typeof value === "string" && value.trim()) {
|
|
98
|
+
const parsed = Number(value)
|
|
99
|
+
return Number.isFinite(parsed) ? parsed : undefined
|
|
100
|
+
}
|
|
101
|
+
return undefined
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
function isValidFieldValue(value: unknown, definition: ClientAssignerFieldDefinition | undefined): boolean {
|
|
105
|
+
if (!definition) {
|
|
106
|
+
return true
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
if (isNumericVarType(definition.type) && toFiniteNumber(value) === undefined) {
|
|
110
|
+
return false
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
return getNumericConstraintViolation(value, definition.type, definition.kwargs) === null
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function isReadyFieldValue(
|
|
117
|
+
field: string,
|
|
118
|
+
value: unknown,
|
|
119
|
+
fieldDefinitions: ClientAssignerFieldDefinitions | undefined,
|
|
120
|
+
): boolean {
|
|
121
|
+
return isReadyValue(value) && isValidFieldValue(value, fieldDefinitions?.[field])
|
|
122
|
+
}
|
|
123
|
+
|
|
85
124
|
function getAssignerDependencies(assigner: AimdClientAssignerField, fieldOwners: Map<string, string>): Set<string> {
|
|
86
125
|
const dependencies = new Set<string>()
|
|
87
126
|
for (const field of assigner.dependent_fields) {
|
|
@@ -131,8 +170,12 @@ function shouldRunAutoFirst(assigner: AimdClientAssignerField, values: Record<st
|
|
|
131
170
|
return assigner.assigned_fields.every(field => !isReadyValue(values[field]))
|
|
132
171
|
}
|
|
133
172
|
|
|
134
|
-
function areDependenciesReady(
|
|
135
|
-
|
|
173
|
+
function areDependenciesReady(
|
|
174
|
+
assigner: AimdClientAssignerField,
|
|
175
|
+
values: Record<string, unknown>,
|
|
176
|
+
options: ClientAssignerApplyOptions | undefined,
|
|
177
|
+
): boolean {
|
|
178
|
+
return assigner.dependent_fields.every(field => isReadyFieldValue(field, values[field], options?.fieldDefinitions))
|
|
136
179
|
}
|
|
137
180
|
|
|
138
181
|
function compileClientAssigner(assigner: AimdClientAssignerField): ClientAssignerExecutor {
|
|
@@ -214,6 +257,7 @@ function executeClientAssigner(
|
|
|
214
257
|
|
|
215
258
|
export interface ClientAssignerApplyOptions {
|
|
216
259
|
triggerIds?: string[]
|
|
260
|
+
fieldDefinitions?: ClientAssignerFieldDefinitions
|
|
217
261
|
}
|
|
218
262
|
|
|
219
263
|
export interface ClientAssignerApplyResult {
|
|
@@ -237,7 +281,7 @@ export function applyClientAssigners(
|
|
|
237
281
|
const changedFields = new Set<string>()
|
|
238
282
|
|
|
239
283
|
for (const assigner of sortClientAssigners(assigners)) {
|
|
240
|
-
if (!areDependenciesReady(assigner, values)) {
|
|
284
|
+
if (!areDependenciesReady(assigner, values, options)) {
|
|
241
285
|
continue
|
|
242
286
|
}
|
|
243
287
|
|