@airalogy/aimd-recorder 1.14.1
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 +240 -0
- package/README.zh-CN.md +224 -0
- package/dist/AimdCodeField-DC3DPvgc.js +172 -0
- package/dist/AimdDnaSequenceField-__jdnFS9.js +59466 -0
- package/dist/AimdEditor.vue_vue_type_style_index_0_lang-Bq79rKNw.js +28370 -0
- package/dist/AimdMarkdownField-98ImHGbc.js +66 -0
- package/dist/AimdMarkdownNoteField-CuUJZkgT.js +185 -0
- package/dist/_.contribution-IP0cDNhs.js +38 -0
- package/dist/_commonjsHelpers-CZXJ37nu.js +40 -0
- package/dist/abap-Bs8kvjsq.js +1398 -0
- package/dist/aimd-recorder.css +1 -0
- package/dist/apex-Dspwrl5m.js +326 -0
- package/dist/assets/css.worker-Dmf38jDD.js +79 -0
- package/dist/assets/editor.worker-CpuX8TSY.js +12 -0
- package/dist/assets/html.worker-DotaEs7v.js +456 -0
- package/dist/assets/json.worker-B4VHhH6h.js +44 -0
- package/dist/assets/ts.worker-sl17zBDo.js +51316 -0
- package/dist/azcli-k1BiOau1.js +68 -0
- package/dist/bat-BIP72KWc.js +100 -0
- package/dist/bicep-VhQeYhS3.js +102 -0
- package/dist/cameligo-DnuAXtHg.js +174 -0
- package/dist/clojure-BAuDPsal.js +761 -0
- package/dist/coffee-BV06qSnj.js +232 -0
- package/dist/components.js +3595 -0
- package/dist/composables.js +72 -0
- package/dist/cpp-Cz8Jeyrf.js +389 -0
- package/dist/csharp-F6hhlXFb.js +326 -0
- package/dist/csp-KzlEHCyI.js +53 -0
- package/dist/css-e4FKntZ3.js +187 -0
- package/dist/cssMode-uz9U6SUU.js +1571 -0
- package/dist/cypher-CpvDGKRr.js +263 -0
- package/dist/dart-DdHeFWR0.js +281 -0
- package/dist/dockerfile-aoNXDcio.js +130 -0
- package/dist/ecl-C4Q0DYuA.js +456 -0
- package/dist/editor.api-CgD9w0gG.js +77091 -0
- package/dist/editor.main-Du02abDl.js +33783 -0
- package/dist/elixir-C9X42b0T.js +569 -0
- package/dist/flow9-Bff42pfB.js +142 -0
- package/dist/freemarker2-DFLX4iQ-.js +989 -0
- package/dist/fsharp-C6vPAsHG.js +217 -0
- package/dist/go-DEr8zx9f.js +218 -0
- package/dist/graphql-BiNBBRFh.js +151 -0
- package/dist/handlebars-aiZbIuWY.js +419 -0
- package/dist/hcl-2T9lKuFg.js +183 -0
- package/dist/html-phzTMObN.js +308 -0
- package/dist/htmlMode-BF7wMi3N.js +1581 -0
- package/dist/index.js +89 -0
- package/dist/ini-CZGtssYM.js +71 -0
- package/dist/ini.contribution-DyWtiacL.js +8 -0
- package/dist/java-B260NeH3.js +232 -0
- package/dist/javascript-BKKOItMi.js +70 -0
- package/dist/jsonMode-CDYK4B5l.js +1996 -0
- package/dist/julia-kuNLM9c5.js +511 -0
- package/dist/kotlin-Bz6kAefA.js +253 -0
- package/dist/less-AZUtS89I.js +162 -0
- package/dist/lexon-BcmgnyRb.js +157 -0
- package/dist/liquid-B2eRz5SA.js +240 -0
- package/dist/lua-Dz1RbATg.js +162 -0
- package/dist/m3-CIMooLFn.js +210 -0
- package/dist/markdown-C1BsCK9P.js +229 -0
- package/dist/markdown.contribution-DYYk6zUU.js +7 -0
- package/dist/mdx-BfV1HDRG.js +165 -0
- package/dist/mips-BovsnfLQ.js +198 -0
- package/dist/monaco.contribution-C-bQhUTI.js +114 -0
- package/dist/monaco.contribution-CCVvl3Jx.js +72 -0
- package/dist/monaco.contribution-Col-f0XR.js +164 -0
- package/dist/monaco.contribution-b5xkgQ-s.js +112 -0
- package/dist/msdax-CiRB2ZB-.js +375 -0
- package/dist/mysql-BwdpPE19.js +878 -0
- package/dist/objective-c-D4nfHfso.js +183 -0
- package/dist/pascal--j5-PYtz.js +251 -0
- package/dist/pascaligo-C7TcJxNL.js +164 -0
- package/dist/perl-BzEWqUb5.js +626 -0
- package/dist/pgsql-B_KZ0mGX.js +851 -0
- package/dist/php-A19QHzQV.js +500 -0
- package/dist/pla-COeKY1hA.js +137 -0
- package/dist/postiats-BfMp7zJL.js +907 -0
- package/dist/powerquery-B0TS_5Gb.js +890 -0
- package/dist/powershell-5jSbKdYB.js +239 -0
- package/dist/protobuf-YgnOutn3.js +420 -0
- package/dist/pug-DLej6kn5.js +402 -0
- package/dist/python-CQrZx9mR.js +301 -0
- package/dist/python.contribution-CcKs2Ktm.js +8 -0
- package/dist/qsharp-AhjqtSHB.js +301 -0
- package/dist/r-D-F4P80w.js +243 -0
- package/dist/razor-DWmpHMcx.js +550 -0
- package/dist/redis-hwwIlMnV.js +302 -0
- package/dist/redshift-Bcm_kjEG.js +809 -0
- package/dist/restructuredtext-CrdzfPP-.js +174 -0
- package/dist/ruby-QC2UNm1s.js +511 -0
- package/dist/rust-5aqiQ3L5.js +343 -0
- package/dist/sb-B1g1ZfLJ.js +115 -0
- package/dist/scala-C2U4R5Gb.js +370 -0
- package/dist/scheme-DeFRbslr.js +108 -0
- package/dist/scss-RSTCiCmI.js +262 -0
- package/dist/shell-BpF-iNu8.js +221 -0
- package/dist/shell.contribution-B80NZ3iO.js +7 -0
- package/dist/solidity-C00r2mbQ.js +1367 -0
- package/dist/sophia-DVW5ZKDB.js +199 -0
- package/dist/sparql-B0nmpxeX.js +201 -0
- package/dist/sql-CJwKPERn.js +853 -0
- package/dist/sql.contribution-DQy36aE5.js +7 -0
- package/dist/st-DPlKG5DT.js +416 -0
- package/dist/swift-YZBAbVHV.js +309 -0
- package/dist/systemverilog-CDQSaH63.js +576 -0
- package/dist/tcl-Dlu8sp6Q.js +232 -0
- package/dist/tsMode-Bh-v12OL.js +887 -0
- package/dist/twig-C5TO7-kw.js +392 -0
- package/dist/typescript-c7y6IZVP.js +343 -0
- package/dist/typespec-BsmjDEu7.js +117 -0
- package/dist/useFieldRendering-BIqeE3qo.js +6083 -0
- package/dist/vb-ChHvIDrk.js +372 -0
- package/dist/wgsl-XEp1ju8c.js +439 -0
- package/dist/xml-MAEprTnF.js +95 -0
- package/dist/xml.contribution-XMOaon8i.js +27 -0
- package/dist/yaml-C1p8rXG7.js +206 -0
- package/dist/yaml.contribution-DRRVhJmJ.js +8 -0
- package/package.json +88 -0
- package/src/__tests__/client-assigner.test.ts +341 -0
- package/src/__tests__/code-types.test.ts +30 -0
- package/src/__tests__/markdown-field.test.ts +34 -0
- package/src/__tests__/markdown-note-field.test.ts +135 -0
- package/src/__tests__/quiz-recorder.test.ts +195 -0
- package/src/__tests__/recorder-editor-content-sync.test.ts +172 -0
- package/src/__tests__/recorder-editor.test.ts +143 -0
- package/src/__tests__/recorder-render.test.ts +57 -0
- package/src/__tests__/recorder-wysiwyg-field-host.test.ts +33 -0
- package/src/__tests__/step-field.test.ts +270 -0
- package/src/__tests__/type-plugins.test.ts +59 -0
- package/src/__tests__/var-field-render.test.ts +26 -0
- package/src/client-assigner.ts +269 -0
- package/src/code-types.ts +94 -0
- package/src/components/AimdCodeField.vue +228 -0
- package/src/components/AimdDnaSequenceField.vue +983 -0
- package/src/components/AimdMarkdownField.vue +168 -0
- package/src/components/AimdMarkdownNoteField.vue +457 -0
- package/src/components/AimdQuizRecorder.vue +792 -0
- package/src/components/AimdRecorder.vue +1959 -0
- package/src/components/AimdRecorderEditor.vue +2281 -0
- package/src/components/AimdRecorderWysiwygFieldHost.vue +93 -0
- package/src/components/AimdRecorderWysiwygSurface.vue +487 -0
- package/src/components/AimdSeqVizViewer.vue +122 -0
- package/src/components/AimdStepCheckField.vue +453 -0
- package/src/components/AimdVarField.vue +213 -0
- package/src/components/AimdVarTableField.vue +516 -0
- package/src/components/DnaAnnotationEditor.vue +477 -0
- package/src/components/DnaSequenceEditor.vue +44 -0
- package/src/components/DnaSequenceToolbar.vue +98 -0
- package/src/components/DnaSequenceViewer.vue +162 -0
- package/src/components/index.ts +21 -0
- package/src/components/recorderMilkdownPlugin.ts +632 -0
- package/src/composables/__tests__/useDnaSequence.test.ts +467 -0
- package/src/composables/__tests__/useFieldAdapters.test.ts +115 -0
- package/src/composables/__tests__/useFocusManagement.test.ts +66 -0
- package/src/composables/__tests__/useRecordState.test.ts +586 -0
- package/src/composables/__tests__/useStepTimers.test.ts +64 -0
- package/src/composables/__tests__/useVarHelpers.test.ts +424 -0
- package/src/composables/__tests__/workbenchFieldEditing.test.ts +97 -0
- package/src/composables/index.ts +94 -0
- package/src/composables/useClientAssignerRunner.ts +74 -0
- package/src/composables/useDnaSequence.ts +400 -0
- package/src/composables/useDnaSequenceField.ts +316 -0
- package/src/composables/useFieldAdapters.ts +61 -0
- package/src/composables/useFieldRendering.ts +269 -0
- package/src/composables/useFocusManagement.ts +144 -0
- package/src/composables/useRecordState.ts +429 -0
- package/src/composables/useStepTimers.ts +243 -0
- package/src/composables/useVarHelpers.ts +545 -0
- package/src/composables/useVarTableDragDrop.ts +236 -0
- package/src/composables/workbenchFieldEditing.ts +705 -0
- package/src/css.d.ts +9 -0
- package/src/index.ts +65 -0
- package/src/locales.ts +559 -0
- package/src/monaco-code.ts +75 -0
- package/src/styles/aimd.css +994 -0
- package/src/type-plugins.ts +132 -0
- package/src/type-utils.ts +3 -0
- package/src/types.ts +191 -0
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import type { VNode } from "vue"
|
|
2
|
+
import type { AimdRecorderMessages } from "../locales"
|
|
3
|
+
import type {
|
|
4
|
+
AimdFieldMeta,
|
|
5
|
+
AimdFieldState,
|
|
6
|
+
AimdProtocolRecordData,
|
|
7
|
+
AimdRecorderFieldAdapterContext,
|
|
8
|
+
AimdRecorderFieldAdapters,
|
|
9
|
+
AimdRecorderFieldNodeMap,
|
|
10
|
+
AimdRecorderFieldType,
|
|
11
|
+
} from "../types"
|
|
12
|
+
|
|
13
|
+
export interface RecorderFieldAdapterResolverOptions {
|
|
14
|
+
fieldAdapters?: AimdRecorderFieldAdapters
|
|
15
|
+
wrapField?: ((fieldKey: string, fieldType: string, defaultVNode: VNode) => VNode) | undefined
|
|
16
|
+
readonly: boolean
|
|
17
|
+
locale: string
|
|
18
|
+
messages: AimdRecorderMessages
|
|
19
|
+
record: AimdProtocolRecordData
|
|
20
|
+
fieldMeta?: Record<string, AimdFieldMeta>
|
|
21
|
+
fieldState?: Record<string, AimdFieldState>
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function buildAimdRecorderFieldAdapterContext<TFieldType extends AimdRecorderFieldType>(
|
|
25
|
+
fieldType: TFieldType,
|
|
26
|
+
fieldKey: string,
|
|
27
|
+
node: AimdRecorderFieldNodeMap[TFieldType],
|
|
28
|
+
value: unknown,
|
|
29
|
+
defaultVNode: VNode,
|
|
30
|
+
options: RecorderFieldAdapterResolverOptions,
|
|
31
|
+
): AimdRecorderFieldAdapterContext<TFieldType> {
|
|
32
|
+
return {
|
|
33
|
+
fieldType,
|
|
34
|
+
fieldKey,
|
|
35
|
+
node,
|
|
36
|
+
value,
|
|
37
|
+
defaultVNode,
|
|
38
|
+
readonly: options.readonly,
|
|
39
|
+
locale: options.locale,
|
|
40
|
+
messages: options.messages,
|
|
41
|
+
record: options.record,
|
|
42
|
+
fieldMeta: options.fieldMeta,
|
|
43
|
+
fieldState: options.fieldState,
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function resolveAimdRecorderFieldVNode<TFieldType extends AimdRecorderFieldType>(
|
|
48
|
+
fieldType: TFieldType,
|
|
49
|
+
fieldKey: string,
|
|
50
|
+
node: AimdRecorderFieldNodeMap[TFieldType],
|
|
51
|
+
value: unknown,
|
|
52
|
+
defaultVNode: VNode,
|
|
53
|
+
options: RecorderFieldAdapterResolverOptions,
|
|
54
|
+
): VNode {
|
|
55
|
+
const context = buildAimdRecorderFieldAdapterContext(fieldType, fieldKey, node, value, defaultVNode, options)
|
|
56
|
+
const adapter = options.fieldAdapters?.[fieldType]
|
|
57
|
+
const adaptedVNode = adapter ? adapter(context as never) : undefined
|
|
58
|
+
const finalVNode = adaptedVNode ?? defaultVNode
|
|
59
|
+
|
|
60
|
+
return options.wrapField ? options.wrapField(fieldKey, fieldType, finalVNode) : finalVNode
|
|
61
|
+
}
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
import { reactive, type VNode } from "vue"
|
|
2
|
+
import type { AimdVarNode } from "@airalogy/aimd-core/types"
|
|
3
|
+
import type { AimdFieldMeta, AimdFieldState, AimdTypePlugin, AimdTypePluginInitContext, AimdTypePluginValueContext } from "../types"
|
|
4
|
+
import {
|
|
5
|
+
normalizeVarTypeName,
|
|
6
|
+
getVarInputKind,
|
|
7
|
+
getVarInputDisplayValue,
|
|
8
|
+
unwrapStructuredValue,
|
|
9
|
+
formatDateTimeWithTimezone,
|
|
10
|
+
type VarInputKind,
|
|
11
|
+
} from "./useVarHelpers"
|
|
12
|
+
import { normalizeDnaSequenceValue } from "./useDnaSequence"
|
|
13
|
+
import { resolveAimdTypePlugin } from "../type-plugins"
|
|
14
|
+
|
|
15
|
+
// ---------------------------------------------------------------------------
|
|
16
|
+
// Types
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
|
|
19
|
+
export interface VarInputDisplayOverride {
|
|
20
|
+
display: string
|
|
21
|
+
expectedValue: unknown
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export interface FieldRenderingOptions {
|
|
25
|
+
readonly: () => boolean
|
|
26
|
+
currentUserName: () => string | undefined
|
|
27
|
+
now: () => Date | string | number | undefined
|
|
28
|
+
fieldMeta: () => Record<string, AimdFieldMeta> | undefined
|
|
29
|
+
fieldState: () => Record<string, AimdFieldState> | undefined
|
|
30
|
+
typePlugins: () => AimdTypePlugin[] | undefined
|
|
31
|
+
wrapField: () => ((fieldKey: string, fieldType: string, defaultVNode: VNode) => VNode) | undefined
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// ---------------------------------------------------------------------------
|
|
35
|
+
// Composable
|
|
36
|
+
// ---------------------------------------------------------------------------
|
|
37
|
+
|
|
38
|
+
export function useFieldRendering(options: FieldRenderingOptions) {
|
|
39
|
+
const varInputDisplayOverrides = reactive<Record<string, VarInputDisplayOverride>>({})
|
|
40
|
+
|
|
41
|
+
// ── Extension helpers ───────────────────────────────────────────────────
|
|
42
|
+
|
|
43
|
+
function maybeWrap(fieldKey: string, fieldType: string, vnode: VNode): VNode {
|
|
44
|
+
const wrapper = options.wrapField()
|
|
45
|
+
return wrapper ? wrapper(fieldKey, fieldType, vnode) : vnode
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function fieldStateClasses(fieldKey: string): string[] {
|
|
49
|
+
const state = options.fieldState()?.[fieldKey]
|
|
50
|
+
const cls: string[] = []
|
|
51
|
+
if (state?.validationError) cls.push("aimd-rec-inline--error")
|
|
52
|
+
if (state?.loading) cls.push("aimd-rec-inline--loading")
|
|
53
|
+
return cls
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
function isFieldDisabled(fieldKey: string): boolean {
|
|
57
|
+
if (options.readonly()) return true
|
|
58
|
+
const meta = options.fieldMeta()?.[fieldKey]
|
|
59
|
+
const state = options.fieldState()?.[fieldKey]
|
|
60
|
+
return !!(meta?.disabled || state?.disabled || meta?.assigner?.mode === "auto_force")
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
// ── resolveNowDate ─────────────────────────────────────────────────────
|
|
64
|
+
|
|
65
|
+
function resolveNowDate(): Date {
|
|
66
|
+
const now = options.now()
|
|
67
|
+
if (now instanceof Date) return Number.isNaN(now.getTime()) ? new Date() : now
|
|
68
|
+
if (typeof now === "string" || typeof now === "number") {
|
|
69
|
+
const d = new Date(now)
|
|
70
|
+
if (!Number.isNaN(d.getTime())) return d
|
|
71
|
+
}
|
|
72
|
+
return new Date()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function getTypePlugin(fieldKey: string, type: string | undefined): AimdTypePlugin | undefined {
|
|
76
|
+
return resolveAimdTypePlugin(type, options.typePlugins())
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function buildTypePluginInitContext(
|
|
80
|
+
node: AimdVarNode,
|
|
81
|
+
type: string | undefined,
|
|
82
|
+
fieldKey: string,
|
|
83
|
+
): AimdTypePluginInitContext {
|
|
84
|
+
return {
|
|
85
|
+
type: type || "str",
|
|
86
|
+
normalizedType: normalizeVarTypeName(type),
|
|
87
|
+
fieldKey,
|
|
88
|
+
node,
|
|
89
|
+
fieldMeta: options.fieldMeta()?.[fieldKey],
|
|
90
|
+
currentUserName: options.currentUserName(),
|
|
91
|
+
now: options.now(),
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function buildTypePluginValueContext(
|
|
96
|
+
node: AimdVarNode,
|
|
97
|
+
type: string | undefined,
|
|
98
|
+
fieldKey: string,
|
|
99
|
+
value: unknown,
|
|
100
|
+
inputKind: VarInputKind,
|
|
101
|
+
): AimdTypePluginValueContext {
|
|
102
|
+
return {
|
|
103
|
+
...buildTypePluginInitContext(node, type, fieldKey),
|
|
104
|
+
value,
|
|
105
|
+
inputKind,
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// ── Var display value ──────────────────────────────────────────────────
|
|
110
|
+
|
|
111
|
+
function getVarInitialDisplayOverride(node: AimdVarNode, type: string | undefined, fieldKey: string): VarInputDisplayOverride | null {
|
|
112
|
+
const raw = node.definition?.defaultRaw?.trim()
|
|
113
|
+
if (!raw) {
|
|
114
|
+
return null
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const normalizedType = normalizeVarTypeName(type)
|
|
118
|
+
if (normalizedType === "int" || normalizedType === "integer") {
|
|
119
|
+
return null
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
if (
|
|
123
|
+
getVarInputKind(type, {
|
|
124
|
+
inputType: options.fieldMeta()?.[fieldKey]?.inputType,
|
|
125
|
+
codeLanguage: options.fieldMeta()?.[fieldKey]?.codeLanguage,
|
|
126
|
+
typePlugin: getTypePlugin(fieldKey, type),
|
|
127
|
+
}) !== "number"
|
|
128
|
+
|| typeof node.definition?.default !== "number"
|
|
129
|
+
) {
|
|
130
|
+
return null
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (!raw.includes(".") || String(node.definition.default) === raw) {
|
|
134
|
+
return null
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
return {
|
|
138
|
+
display: raw,
|
|
139
|
+
expectedValue: node.definition.default,
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function getVarDisplayValue(
|
|
144
|
+
id: string,
|
|
145
|
+
node: AimdVarNode,
|
|
146
|
+
type: string | undefined,
|
|
147
|
+
value: unknown,
|
|
148
|
+
kind: VarInputKind,
|
|
149
|
+
fieldKey: string,
|
|
150
|
+
): string | number {
|
|
151
|
+
const override = varInputDisplayOverrides[id]
|
|
152
|
+
const normalized = unwrapStructuredValue(value)
|
|
153
|
+
const typePlugin = getTypePlugin(fieldKey, type)
|
|
154
|
+
|
|
155
|
+
if (override) {
|
|
156
|
+
if (kind === "number" && Object.is(normalized, override.expectedValue)) {
|
|
157
|
+
return override.display
|
|
158
|
+
}
|
|
159
|
+
delete varInputDisplayOverrides[id]
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
if (typePlugin?.getDisplayValue) {
|
|
163
|
+
return typePlugin.getDisplayValue(
|
|
164
|
+
buildTypePluginValueContext(node, type, fieldKey, value, kind),
|
|
165
|
+
)
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
return getVarInputDisplayValue(value, kind, { type, typePlugin })
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
function clearVarInputDisplayOverride(id: string) {
|
|
172
|
+
if (id in varInputDisplayOverrides) {
|
|
173
|
+
delete varInputDisplayOverrides[id]
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
function setVarInputDisplayOverride(id: string, override: VarInputDisplayOverride) {
|
|
178
|
+
varInputDisplayOverrides[id] = override
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
// ── Var initial value ──────────────────────────────────────────────────
|
|
182
|
+
|
|
183
|
+
function getVarInitialValue(node: AimdVarNode, type: string | undefined, fieldKey: string): unknown {
|
|
184
|
+
const typePlugin = getTypePlugin(fieldKey, type)
|
|
185
|
+
if (typePlugin?.getInitialValue) {
|
|
186
|
+
return typePlugin.getInitialValue(buildTypePluginInitContext(node, type, fieldKey))
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
const normalizedType = normalizeVarTypeName(type)
|
|
190
|
+
if (node.definition && Object.prototype.hasOwnProperty.call(node.definition, "default")) {
|
|
191
|
+
if (normalizedType === "dnasequence") {
|
|
192
|
+
return normalizeDnaSequenceValue(node.definition.default)
|
|
193
|
+
}
|
|
194
|
+
return node.definition.default
|
|
195
|
+
}
|
|
196
|
+
const inputKind = getVarInputKind(type, {
|
|
197
|
+
inputType: options.fieldMeta()?.[fieldKey]?.inputType,
|
|
198
|
+
codeLanguage: options.fieldMeta()?.[fieldKey]?.codeLanguage,
|
|
199
|
+
typePlugin,
|
|
200
|
+
})
|
|
201
|
+
if (inputKind === "checkbox") return false
|
|
202
|
+
if (inputKind === "dna") return normalizeDnaSequenceValue(undefined)
|
|
203
|
+
if (normalizedType === "currenttime") return formatDateTimeWithTimezone(resolveNowDate())
|
|
204
|
+
if (normalizedType === "username" && typeof options.currentUserName() === "string") return options.currentUserName()
|
|
205
|
+
return ""
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
function normalizeVarValue(
|
|
209
|
+
node: AimdVarNode,
|
|
210
|
+
type: string | undefined,
|
|
211
|
+
fieldKey: string,
|
|
212
|
+
value: unknown,
|
|
213
|
+
inputKind: VarInputKind,
|
|
214
|
+
): unknown {
|
|
215
|
+
const typePlugin = getTypePlugin(fieldKey, type)
|
|
216
|
+
if (typePlugin?.normalizeValue) {
|
|
217
|
+
return typePlugin.normalizeValue(
|
|
218
|
+
buildTypePluginValueContext(node, type, fieldKey, value, inputKind),
|
|
219
|
+
)
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
const normalizedType = normalizeVarTypeName(type)
|
|
223
|
+
if (inputKind === "dna" || normalizedType === "dnasequence") {
|
|
224
|
+
return normalizeDnaSequenceValue(value)
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
return value
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
function getVarPlaceholder(node: AimdVarNode): string | undefined {
|
|
231
|
+
const title = node.definition?.kwargs?.title
|
|
232
|
+
return typeof title === "string" && title.trim() ? title.trim() : undefined
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
// ── ID helpers ─────────────────────────────────────────────────────────
|
|
236
|
+
|
|
237
|
+
function getAimdId(value: unknown): string | null {
|
|
238
|
+
if (typeof value === "string" && value.trim()) {
|
|
239
|
+
return value.trim()
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
243
|
+
return null
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
const obj = value as Record<string, unknown>
|
|
247
|
+
if (typeof obj.id === "string" && obj.id.trim()) {
|
|
248
|
+
return obj.id
|
|
249
|
+
}
|
|
250
|
+
return null
|
|
251
|
+
}
|
|
252
|
+
|
|
253
|
+
return {
|
|
254
|
+
varInputDisplayOverrides,
|
|
255
|
+
maybeWrap,
|
|
256
|
+
fieldStateClasses,
|
|
257
|
+
isFieldDisabled,
|
|
258
|
+
resolveNowDate,
|
|
259
|
+
getTypePlugin,
|
|
260
|
+
getVarInitialDisplayOverride,
|
|
261
|
+
getVarDisplayValue,
|
|
262
|
+
clearVarInputDisplayOverride,
|
|
263
|
+
setVarInputDisplayOverride,
|
|
264
|
+
getVarInitialValue,
|
|
265
|
+
normalizeVarValue,
|
|
266
|
+
getVarPlaceholder,
|
|
267
|
+
getAimdId,
|
|
268
|
+
}
|
|
269
|
+
}
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Focus snapshot / restore utilities for AIMD inline editing.
|
|
3
|
+
*
|
|
4
|
+
* When the VNode tree is rebuilt (e.g. after a content change),
|
|
5
|
+
* we capture the currently focused element's key and selection state,
|
|
6
|
+
* then restore it after the new tree is mounted.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
export interface FocusSnapshot {
|
|
10
|
+
key: string
|
|
11
|
+
selectionStart?: number | null
|
|
12
|
+
selectionEnd?: number | null
|
|
13
|
+
selectionDirection?: HTMLInputElement["selectionDirection"]
|
|
14
|
+
scrollTargets?: Array<{
|
|
15
|
+
element: HTMLElement
|
|
16
|
+
top: number
|
|
17
|
+
left: number
|
|
18
|
+
}>
|
|
19
|
+
windowScrollX?: number
|
|
20
|
+
windowScrollY?: number
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
function isScrollableElement(element: HTMLElement): boolean {
|
|
24
|
+
if (typeof window === "undefined") {
|
|
25
|
+
return false
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const style = window.getComputedStyle(element)
|
|
29
|
+
const overflowY = style.overflowY || style.overflow
|
|
30
|
+
const overflowX = style.overflowX || style.overflow
|
|
31
|
+
const canScrollY = /(auto|scroll|overlay)/.test(overflowY) && element.scrollHeight > element.clientHeight
|
|
32
|
+
const canScrollX = /(auto|scroll|overlay)/.test(overflowX) && element.scrollWidth > element.clientWidth
|
|
33
|
+
return canScrollY || canScrollX
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function collectScrollTargets(contentRoot: HTMLElement, activeElement: HTMLElement): FocusSnapshot["scrollTargets"] {
|
|
37
|
+
const targets: FocusSnapshot["scrollTargets"] = []
|
|
38
|
+
const seen = new Set<HTMLElement>()
|
|
39
|
+
|
|
40
|
+
const collectFrom = (start: HTMLElement | null) => {
|
|
41
|
+
let current = start
|
|
42
|
+
while (current && current !== document.body) {
|
|
43
|
+
if (!seen.has(current) && isScrollableElement(current)) {
|
|
44
|
+
seen.add(current)
|
|
45
|
+
targets.push({
|
|
46
|
+
element: current,
|
|
47
|
+
top: current.scrollTop,
|
|
48
|
+
left: current.scrollLeft,
|
|
49
|
+
})
|
|
50
|
+
}
|
|
51
|
+
current = current.parentElement
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
collectFrom(activeElement)
|
|
56
|
+
collectFrom(contentRoot)
|
|
57
|
+
|
|
58
|
+
return targets.length ? targets : undefined
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Capture the focus state of the currently active element inside `contentRoot`.
|
|
63
|
+
* Returns `null` if nothing relevant is focused.
|
|
64
|
+
*/
|
|
65
|
+
export function captureFocusSnapshot(contentRoot: HTMLElement | null): FocusSnapshot | null {
|
|
66
|
+
if (typeof document === "undefined" || !contentRoot) {
|
|
67
|
+
return null
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const activeElement = document.activeElement
|
|
71
|
+
if (!(activeElement instanceof HTMLElement) || !contentRoot.contains(activeElement)) {
|
|
72
|
+
return null
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const key = activeElement.dataset.recFocusKey
|
|
76
|
+
if (!key) {
|
|
77
|
+
return null
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const snapshot: FocusSnapshot = { key }
|
|
81
|
+
if (activeElement instanceof HTMLInputElement || activeElement instanceof HTMLTextAreaElement) {
|
|
82
|
+
snapshot.selectionStart = activeElement.selectionStart
|
|
83
|
+
snapshot.selectionEnd = activeElement.selectionEnd
|
|
84
|
+
snapshot.selectionDirection = activeElement.selectionDirection
|
|
85
|
+
}
|
|
86
|
+
snapshot.scrollTargets = collectScrollTargets(contentRoot, activeElement)
|
|
87
|
+
snapshot.windowScrollX = window.scrollX
|
|
88
|
+
snapshot.windowScrollY = window.scrollY
|
|
89
|
+
|
|
90
|
+
return snapshot
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Restore focus (and optionally selection) to the element matching the snapshot key.
|
|
95
|
+
*/
|
|
96
|
+
export function restoreFocusSnapshot(contentRoot: HTMLElement | null, snapshot: FocusSnapshot | null) {
|
|
97
|
+
if (!snapshot || !contentRoot) {
|
|
98
|
+
return
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const candidates = contentRoot.querySelectorAll<HTMLElement>("[data-rec-focus-key]")
|
|
102
|
+
let target: HTMLElement | null = null
|
|
103
|
+
for (let index = 0; index < candidates.length; index += 1) {
|
|
104
|
+
if (candidates[index].dataset.recFocusKey === snapshot.key) {
|
|
105
|
+
target = candidates[index]
|
|
106
|
+
break
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
if (!target) {
|
|
111
|
+
return
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
try {
|
|
115
|
+
target.focus({ preventScroll: true })
|
|
116
|
+
} catch {
|
|
117
|
+
target.focus()
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
if (
|
|
121
|
+
(target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) &&
|
|
122
|
+
snapshot.selectionStart != null &&
|
|
123
|
+
snapshot.selectionEnd != null
|
|
124
|
+
) {
|
|
125
|
+
try {
|
|
126
|
+
target.setSelectionRange(
|
|
127
|
+
snapshot.selectionStart,
|
|
128
|
+
snapshot.selectionEnd,
|
|
129
|
+
snapshot.selectionDirection ?? undefined,
|
|
130
|
+
)
|
|
131
|
+
} catch {
|
|
132
|
+
// Some input types (e.g. number, date) don't support setSelectionRange
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
for (const scrollTarget of snapshot.scrollTargets ?? []) {
|
|
137
|
+
scrollTarget.element.scrollTop = scrollTarget.top
|
|
138
|
+
scrollTarget.element.scrollLeft = scrollTarget.left
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (typeof window !== "undefined") {
|
|
142
|
+
window.scrollTo(snapshot.windowScrollX ?? window.scrollX, snapshot.windowScrollY ?? window.scrollY)
|
|
143
|
+
}
|
|
144
|
+
}
|