@case-framework/survey-core 0.2.0 → 0.3.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.
@@ -1 +0,0 @@
1
- {"version":3,"file":"survey-DQmpzihl.mjs","names":[],"sources":["../src/utils.ts","../src/survey/utils/value-reference.ts","../src/expressions/expression.ts","../src/expressions/template-value.ts","../src/survey/items/utils.ts","../src/survey/items/survey-item.ts","../src/survey/items/types.ts","../src/survey/item-key.ts","../src/survey/utils/group-utils.ts","../src/survey/registry/built-in-items.ts","../src/survey/registry/item-registry.ts","../src/survey/survey-file-schema.ts","../src/survey/utils/translations.ts","../src/survey/survey.ts"],"sourcesContent":["\n/**\n * Shuffles an array of indices using the Fisher-Yates shuffle algorithm\n * @param length - The length of the array to create indices for\n * @returns A shuffled array of indices from 0 to length-1\n */\nexport function shuffleIndices(length: number): number[] {\n const shuffledIndices = Array.from({ length }, (_, i) => i);\n\n for (let i = shuffledIndices.length - 1; i > 0; i--) {\n const j = Math.floor(Math.random() * (i + 1));\n [shuffledIndices[i], shuffledIndices[j]] = [shuffledIndices[j], shuffledIndices[i]];\n }\n\n return shuffledIndices;\n}\n\nexport function structuredCloneMethod<T>(obj: T): T {\n if (typeof structuredClone !== 'undefined') {\n return structuredClone(obj);\n }\n // Fallback to JSON method\n return JSON.parse(JSON.stringify(obj));\n}\n\nconst ALPHABET = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz';\n\nexport function generateId(): string {\n const length = 10;\n const timestamp = Date.now();\n let encodedTimestamp = '';\n let t = timestamp;\n const base = ALPHABET.length;\n\n while (t > 0) {\n encodedTimestamp = ALPHABET.charAt(t % base) + encodedTimestamp;\n t = Math.floor(t / base);\n }\n\n let randomPart = '';\n for (let i = 0; i < length; i++) {\n randomPart += ALPHABET.charAt(Math.floor(Math.random() * base));\n }\n return randomPart + encodedTimestamp;\n}\n\n\n/** Alphanumeric chars without ambiguous ones (0/O, 1/I) for human-readable coding keys. */\nconst CODING_KEY_ALPHABET = '23456789ABCDEFGHJKLMNPQRSTUVWXYZ';\n\n/**\n * Generates a short random coding key suitable for item keys in exports/codebooks.\n * @param length - Key length (default 4)\n * @returns A random string of the specified length.\n */\nexport function generateCodingKey(length: number = 4): string {\n const base = CODING_KEY_ALPHABET.length;\n let key = '';\n for (let i = 0; i < length; i++) {\n key += CODING_KEY_ALPHABET.charAt(Math.floor(Math.random() * base));\n }\n return key;\n}\n","const SEPARATOR = '...';\n\nexport enum ValueReferenceMethod {\n get = 'get',\n isDefined = 'isDefined',\n}\n\n\n\nexport class ValueReference {\n _itemId: string;\n _name: ValueReferenceMethod;\n _slotId: string;\n\n constructor(str: string) {\n const parts = str.split(SEPARATOR);\n if (parts.length !== 3) {\n throw new Error('Invalid value reference: ' + str);\n }\n this._itemId = parts[0];\n this._name = parts[1] as ValueReferenceMethod;\n this._slotId = parts[2];\n }\n\n get itemId(): string {\n return this._itemId;\n }\n\n get name(): ValueReferenceMethod {\n return this._name;\n }\n\n get slotId(): string {\n return this._slotId;\n }\n\n set itemId(itemId: string) {\n this._itemId = itemId;\n }\n\n toString(): string {\n return `${this._itemId}${SEPARATOR}${this._name}${this._slotId ? SEPARATOR + this._slotId : ''}`;\n }\n\n static fromParts(itemId: string, name: ValueReferenceMethod, slotId: string): ValueReference {\n return new ValueReference(`${itemId}${SEPARATOR}${name}${SEPARATOR}${slotId}`);\n }\n}\n\n\nexport enum ReferenceUsageType {\n displayConditions = 'displayConditions',\n templateValues = 'templateValues',\n validations = 'validations',\n disabledConditions = 'disabledConditions',\n}\n\nexport interface ReferenceUsage {\n itemId: string;\n fullComponentKey?: string;\n usageType?: ReferenceUsageType;\n valueReference: ValueReference;\n}\n","import { ResponseValue, ValueType, } from \"../survey/responses\";\nimport { ValueReference } from \"../survey/utils/value-reference\";\n\n\nexport const ExpressionType = {\n Const: 'const',\n ResponseVariable: 'responseVariable',\n ContextVariable: 'contextVariable',\n Function: 'function',\n} as const;\n\nexport type ExpressionType = (typeof ExpressionType)[keyof typeof ExpressionType];\n\nexport const ContextVariableType = {\n Locale: 'locale',\n ParticipantFlag: 'participantFlag',\n CustomValue: 'customValue',\n CustomExpression: 'customExpression'\n} as const;\n\nexport type ContextVariableType = (typeof ContextVariableType)[keyof typeof ContextVariableType];\n\nexport interface ExpressionEditorConfig {\n usedTemplate?: string;\n}\n\nexport interface JsonConstExpression {\n type: typeof ExpressionType.Const;\n value?: ResponseValue;\n\n editorConfig?: ExpressionEditorConfig;\n}\n\nexport interface JsonResponseVariableExpression {\n type: typeof ExpressionType.ResponseVariable;\n variableRef: string;\n\n editorConfig?: ExpressionEditorConfig;\n}\n\nexport interface JsonContextVariableExpression {\n type: typeof ExpressionType.ContextVariable;\n\n contextType: ContextVariableType;\n key?: JsonExpression;\n arguments?: Array<JsonExpression | undefined>;\n asType?: ValueType;\n\n editorConfig?: ExpressionEditorConfig;\n}\n\nexport interface JsonFunctionExpression {\n type: typeof ExpressionType.Function;\n functionName: string;\n arguments: Array<JsonExpression | undefined>;\n\n editorConfig?: ExpressionEditorConfig;\n}\n\nexport type JsonExpression = JsonConstExpression | JsonResponseVariableExpression | JsonContextVariableExpression | JsonFunctionExpression;\n\n\n\n/**\n * Base class for all expressions.\n */\nexport abstract class Expression {\n type: ExpressionType;\n editorConfig?: ExpressionEditorConfig;\n\n constructor(type: ExpressionType, editorConfig?: ExpressionEditorConfig) {\n this.type = type;\n this.editorConfig = editorConfig;\n }\n\n static deserialize(json: JsonExpression | undefined): Expression | undefined {\n if (!json) {\n return undefined;\n }\n\n switch (json.type) {\n case ExpressionType.Const:\n return ConstExpression.deserialize(json);\n case ExpressionType.ResponseVariable:\n return ResponseVariableExpression.deserialize(json);\n case ExpressionType.ContextVariable:\n return ContextVariableExpression.deserialize(json);\n case ExpressionType.Function:\n return FunctionExpression.deserialize(json);\n }\n }\n\n /**\n * Returns all unique response variable references in the expression.\n * @returns A list of ValueReference objects.\n */\n abstract get responseVariableRefs(): ValueReference[]\n abstract serialize(): JsonExpression | undefined;\n\n clone(): Expression {\n return Expression.deserialize(this.serialize()) ?? (() => {\n throw new Error('Failed to clone expression');\n })();\n }\n}\n\nexport class ConstExpression extends Expression {\n declare type: typeof ExpressionType.Const;\n value?: ResponseValue;\n\n constructor(value?: ResponseValue, editorConfig?: ExpressionEditorConfig) {\n super(ExpressionType.Const, editorConfig);\n this.value = value;\n this.type = ExpressionType.Const;\n }\n\n static deserialize(json: JsonExpression): ConstExpression {\n if (json.type !== ExpressionType.Const) {\n throw new Error('Invalid expression type: ' + json.type);\n }\n\n return new ConstExpression(json.value, json.editorConfig);\n }\n\n get responseVariableRefs(): ValueReference[] {\n return [];\n }\n\n serialize(): JsonExpression {\n return {\n type: this.type,\n value: this.value,\n editorConfig: this.editorConfig\n }\n }\n\n updateItemKeyReferences(_oldItemKey: string, _newItemKey: string): boolean {\n // Const expressions don't have item references\n return false;\n }\n}\n\nexport class ResponseVariableExpression extends Expression {\n declare type: typeof ExpressionType.ResponseVariable;\n variableRef: string;\n\n constructor(variableRef: string, editorConfig?: ExpressionEditorConfig) {\n super(ExpressionType.ResponseVariable, editorConfig);\n this.variableRef = variableRef;\n this.type = ExpressionType.ResponseVariable;\n }\n\n static deserialize(json: JsonExpression): ResponseVariableExpression {\n if (json.type !== ExpressionType.ResponseVariable) {\n throw new Error('Invalid expression type: ' + json.type);\n }\n\n return new ResponseVariableExpression(json.variableRef, json.editorConfig);\n }\n\n get responseVariableRefs(): ValueReference[] {\n return [new ValueReference(this.variableRef)];\n }\n\n get responseVariableRef(): ValueReference {\n return new ValueReference(this.variableRef);\n }\n\n serialize(): JsonExpression {\n return {\n type: this.type,\n variableRef: this.variableRef,\n editorConfig: this.editorConfig\n }\n }\n}\n\nexport class ContextVariableExpression extends Expression {\n declare type: typeof ExpressionType.ContextVariable;\n\n contextType: ContextVariableType;\n key?: Expression;\n arguments?: Array<Expression | undefined>;\n asType?: ValueType;\n\n constructor(contextType: ContextVariableType, key?: Expression, args?: Array<Expression | undefined>, asType?: ValueType, editorConfig?: ExpressionEditorConfig) {\n super(ExpressionType.ContextVariable, editorConfig);\n this.type = ExpressionType.ContextVariable;\n this.contextType = contextType;\n this.key = key;\n this.arguments = args;\n this.asType = asType;\n }\n\n static deserialize(json: JsonExpression): ContextVariableExpression {\n if (json.type !== ExpressionType.ContextVariable) {\n throw new Error('Invalid expression type: ' + json.type);\n }\n\n return new ContextVariableExpression(json.contextType, Expression.deserialize(json.key), json.arguments?.map(arg => Expression.deserialize(arg)), json.asType, json.editorConfig);\n }\n\n get responseVariableRefs(): ValueReference[] {\n return this.arguments?.flatMap(arg => arg?.responseVariableRefs).filter(ref => ref !== undefined) ?? [];\n }\n\n serialize(): JsonExpression {\n return {\n type: this.type,\n contextType: this.contextType,\n key: this.key?.serialize(),\n arguments: this.arguments?.map(arg => arg?.serialize()),\n asType: this.asType,\n editorConfig: this.editorConfig\n }\n }\n}\n\n\nexport enum FunctionExpressionNames {\n and = 'and',\n or = 'or',\n not = 'not',\n\n list_contains = 'list_contains',\n\n // numeric functions\n eq = 'eq',\n gt = 'gt',\n gte = 'gte',\n lt = 'lt',\n lte = 'lte',\n in_range = 'in_range',\n\n sum = 'sum',\n min = 'min',\n max = 'max',\n\n\n\n\n // string functions\n str_eq = 'str_eq',\n\n // date functions\n date_eq = 'date_eq',\n}\n\nexport class FunctionExpression extends Expression {\n declare type: typeof ExpressionType.Function;\n functionName: FunctionExpressionNames;\n arguments: Array<Expression | undefined>;\n\n constructor(functionName: FunctionExpressionNames, args: Array<Expression | undefined>, editorConfig?: ExpressionEditorConfig) {\n super(ExpressionType.Function);\n this.type = ExpressionType.Function;\n this.functionName = functionName;\n this.arguments = args;\n this.editorConfig = editorConfig;\n }\n\n static deserialize(json: JsonExpression): FunctionExpression {\n if (json.type !== ExpressionType.Function) {\n throw new Error('Invalid expression type: ' + json.type);\n }\n\n const functionName = json.functionName as FunctionExpressionNames;\n if (!Object.values(FunctionExpressionNames).includes(functionName)) {\n throw new Error('Invalid function name: ' + functionName);\n }\n\n const expr = new FunctionExpression(functionName, json.arguments.map(arg => Expression.deserialize(arg)));\n expr.editorConfig = json.editorConfig;\n return expr;\n }\n\n get responseVariableRefs(): ValueReference[] {\n const refs = this.arguments.flatMap(arg => arg?.responseVariableRefs).filter(ref => ref !== undefined);\n const refStrings = refs.map(ref => ref.toString());\n return [...new Set(refStrings)].map(ref => new ValueReference(ref));\n }\n\n serialize(): JsonExpression | undefined {\n return {\n type: this.type,\n functionName: this.functionName,\n arguments: this.arguments.map(arg => arg?.serialize()),\n editorConfig: this.editorConfig\n }\n }\n}\n","import { ValueType } from \"../survey/responses\";\nimport { Expression, JsonExpression } from \"./expression\";\n\n\nexport enum TemplateDefTypes {\n Default = 'default',\n Date2String = 'date2string'\n}\n\nexport type TemplateValueBase = {\n type: TemplateDefTypes;\n returnType: ValueType;\n expression?: Expression;\n}\n\n\nexport type TemplateValueFormatDate = TemplateValueBase & {\n type: TemplateDefTypes.Date2String;\n returnType: typeof ValueType.string;\n dateFormat: string;\n}\n\nexport type TemplateValueDefinition = TemplateValueBase | TemplateValueFormatDate;\n\n\n\nexport const serializeTemplateValue = (templateValue: TemplateValueDefinition): JsonTemplateValue => {\n const json: JsonTemplateValue = {\n type: templateValue.type,\n returnType: templateValue.returnType,\n expression: templateValue.expression?.serialize(),\n }\n if (templateValue.type === TemplateDefTypes.Date2String) {\n json.dateFormat = (templateValue as TemplateValueFormatDate).dateFormat;\n }\n return json;\n}\n\nexport const serializeTemplateValues = (templateValues: Map<string, TemplateValueDefinition>): { [templateValueKey: string]: JsonTemplateValue } => {\n const json: { [templateValueKey: string]: JsonTemplateValue } = {};\n for (const [key, value] of templateValues.entries()) {\n json[key] = serializeTemplateValue(value);\n }\n return json;\n}\n\nexport const deserializeTemplateValue = (json: JsonTemplateValue): TemplateValueDefinition => {\n return {\n type: json.type,\n expression: json.expression ? Expression.deserialize(json.expression) : undefined,\n returnType: json.returnType,\n dateFormat: json.dateFormat\n }\n}\n\nexport const deserializeTemplateValues = (json: { [templateValueKey: string]: JsonTemplateValue }): Map<string, TemplateValueDefinition> => {\n return new Map(Object.entries(json).map(([key, value]) => [key, deserializeTemplateValue(value)]));\n}\n\nexport interface JsonTemplateValue {\n type: TemplateDefTypes;\n expression?: JsonExpression;\n returnType: ValueType;\n dateFormat?: string;\n}\n\n","import { Expression, JsonExpression } from \"../../expressions\";\n\nexport interface DisplayConditions {\n root?: Expression;\n components?: {\n [componentKey: string]: Expression | undefined;\n }\n}\n\nexport interface JsonDisplayConditions {\n root?: JsonExpression;\n components?: {\n [componentKey: string]: JsonExpression | undefined;\n }\n}\n\nexport interface JsonDisabledConditions {\n components?: {\n [componentKey: string]: JsonExpression | undefined;\n }\n}\n\nexport interface DisabledConditions {\n components?: {\n [componentKey: string]: Expression | undefined;\n }\n}\n\nexport const displayConditionsFromJson = (json: JsonDisplayConditions): DisplayConditions => {\n return {\n root: json.root ? Expression.deserialize(json.root) : undefined,\n components: json.components ? Object.fromEntries(Object.entries(json.components).map(([key, value]) => [key, Expression.deserialize(value)])) : undefined\n }\n}\n\nexport const displayConditionsToJson = (displayConditions: DisplayConditions): JsonDisplayConditions => {\n return {\n root: displayConditions.root ? displayConditions.root.serialize() : undefined,\n components: displayConditions.components ? Object.fromEntries(Object.entries(displayConditions.components).map(([key, value]) => [key, value?.serialize()])) : undefined\n }\n}\n\nexport const disabledConditionsFromJson = (json: JsonDisabledConditions): DisabledConditions => {\n return {\n components: json.components ? Object.fromEntries(Object.entries(json.components).map(([key, value]) => [key, Expression.deserialize(value)])) : undefined\n }\n}\n\nexport const disabledConditionsToJson = (disabledConditions: DisabledConditions): JsonDisabledConditions => {\n return {\n components: disabledConditions.components ? Object.fromEntries(Object.entries(disabledConditions.components).map(([key, value]) => [key, value?.serialize()])) : undefined\n }\n}\n","import { Expression } from \"../../expressions\";\nimport { RawSurveyItem } from \"../items\";\nimport { ValueRefTypeLookup, ValueType } from \"../responses/value-types\";\nimport { ReferenceUsage, ReferenceUsageType } from \"../utils/value-reference\";\nimport { DisabledConditions, disabledConditionsFromJson, DisplayConditions, displayConditionsFromJson } from \"./utils\";\n\n/**\n * Core contract for survey item handlers.\n * Every item type (built-in and plugin) is represented by a handler class implementing this interface.\n * The core uses these methods without any casting.\n */\nexport interface SurveyItemCoreType<TConfig = unknown> {\n readonly type: string;\n readonly id: string;\n readonly key: string;\n readonly config: TConfig;\n\n isInteractive(): boolean;\n getAvailableResponseValueSlots(): ValueRefTypeLookup;\n}\n\n/**\n * Base class for survey item handlers.\n * Each handler holds type, id, key, and config (properly typed) and implements core methods.\n * Subclass for each item type; the core works with SurveyItemHandler only—no casting needed.\n */\nexport abstract class SurveyItemCore<\n TType extends string = string,\n TConfig = unknown\n> implements SurveyItemCoreType<TConfig> {\n abstract readonly type: TType;\n readonly id: string;\n key: string;\n config: TConfig;\n\n private _rawItem: RawSurveyItem;\n\n displayConditions?: DisplayConditions;\n disabledConditions?: DisabledConditions;\n validations?: {\n [validationKey: string]: Expression | undefined;\n }\n prefillRules?: Array<Expression | undefined>;\n\n\n constructor(rawItem: RawSurveyItem) {\n this._rawItem = rawItem;\n this.updateExpressions();\n this.id = this._rawItem.id;\n this.key = this._rawItem.key;\n this.config = this.parseConfig(this._rawItem.config);\n }\n\n /** Parse raw config from JSON into typed config. Override in subclasses. */\n abstract parseConfig(rawConfig: unknown): TConfig;\n abstract isInteractive(): boolean;\n abstract getAvailableResponseValueSlots(byType?: ValueType): ValueRefTypeLookup;\n\n get rawItem(): RawSurveyItem {\n return this._rawItem;\n }\n\n get metadata(): { [key: string]: string } {\n return this._rawItem.metadata ?? {};\n }\n\n set metadata(metadata: { [key: string]: string }) {\n this.updateRawItem({\n ...this._rawItem,\n metadata: metadata,\n });\n }\n\n updateRawItem(rawItem: RawSurveyItem) {\n if (rawItem.id !== this.id) {\n throw new Error('Cannot update raw item with a different id');\n }\n this._rawItem = rawItem;\n this.updateExpressions();\n this.key = rawItem.key;\n this.config = this.parseConfig(rawItem.config);\n }\n\n private updateExpressions() {\n this.displayConditions = this._rawItem.displayConditions ? displayConditionsFromJson(this._rawItem.displayConditions) : undefined;\n this.disabledConditions = this._rawItem.disabledConditions ? disabledConditionsFromJson(this._rawItem.disabledConditions) : undefined;\n this.validations = this._rawItem.validations ? Object.fromEntries(Object.entries(this._rawItem.validations).map(([key, value]) => [key, Expression.deserialize(value)])) : undefined;\n this.prefillRules = this._rawItem.prefillRules ? this._rawItem.prefillRules.map(rule => rule ? Expression.deserialize(rule) : undefined) : undefined;\n }\n\n getReferenceUsages(): ReferenceUsage[] {\n const usages: ReferenceUsage[] = [];\n\n if (this.displayConditions) {\n // root\n for (const ref of this.displayConditions.root?.responseVariableRefs || []) {\n usages.push({\n itemId: this.id,\n usageType: ReferenceUsageType.displayConditions,\n valueReference: ref,\n });\n }\n\n // components\n for (const [componentKey, expression] of Object.entries(this.displayConditions.components || {})) {\n for (const ref of expression?.responseVariableRefs || []) {\n usages.push({\n itemId: this.id,\n fullComponentKey: componentKey,\n usageType: ReferenceUsageType.displayConditions,\n valueReference: ref,\n });\n }\n }\n }\n\n if (this.disabledConditions) {\n for (const [componentKey, expression] of Object.entries(this.disabledConditions.components || {})) {\n for (const ref of expression?.responseVariableRefs || []) {\n usages.push({\n itemId: this.id,\n fullComponentKey: componentKey,\n usageType: ReferenceUsageType.disabledConditions,\n valueReference: ref,\n });\n }\n }\n }\n\n if (this.validations) {\n for (const [validationKey, expression] of Object.entries(this.validations)) {\n for (const ref of expression?.responseVariableRefs || []) {\n usages.push({\n itemId: this.id,\n fullComponentKey: validationKey,\n usageType: ReferenceUsageType.validations,\n valueReference: ref,\n });\n }\n }\n }\n\n return usages;\n }\n}\n\n\n/**\n * Constructor type for handler classes. Used by the registry to instantiate handlers.\n */\nexport type ItemCoreConstructor<TType extends string = string, TConfig = unknown> = new (\n rawItem: RawSurveyItem\n) => SurveyItemCore<TType, TConfig>;\n","export enum ReservedSurveyItemTypes {\n Group = 'group',\n PageBreak = 'page-break',\n}\n\n","\n/**\n * SurveyItemKey stores the key of the item and the path to the item.\n */\n\nexport class SurveyItemKey {\n private _itemKey: string;\n private _path: Array<string>;\n private _keySeparator: string;\n\n constructor(itemKey: string, path: string[] | undefined, keySeparator: string = '.') {\n this._itemKey = itemKey;\n this._path = path ?? [];\n this._keySeparator = keySeparator;\n }\n\n get itemKey(): string {\n return this._itemKey;\n }\n\n get path(): Array<string> {\n return this._path;\n }\n\n get parentFullKey(): string {\n return this._path.join(this._keySeparator);\n }\n\n get fullKey(): string {\n return [...this._path, this._itemKey].join(this._keySeparator);\n }\n\n get isRoot(): boolean {\n return this._path.length === 0;\n }\n\n get keySeparator(): string {\n return this._keySeparator;\n }\n\n set keySeparator(keySeparator: string) {\n this._keySeparator = keySeparator;\n }\n}\n\n","/**\n * Shared utilities for array operations.\n */\n\n/**\n * Swap two elements in an array by index.\n * @returns A new array with the elements swapped\n */\nexport function swapArrayElements<T>(arr: T[], fromIndex: number, toIndex: number): T[] {\n const result = [...arr];\n [result[fromIndex], result[toIndex]] = [result[toIndex], result[fromIndex]];\n return result;\n}\n\n/**\n * Move an element from one index to another.\n * @returns A new array with the element moved\n */\nexport function moveArrayElement<T>(arr: T[], fromIndex: number, toIndex: number): T[] {\n const result = [...arr];\n const [moved] = result.splice(fromIndex, 1);\n result.splice(toIndex, 0, moved);\n return result;\n}\n","import { ReservedSurveyItemTypes } from \"../items/types\";\nimport { ItemCoreConstructor, SurveyItemCore } from \"../items/survey-item\";\nimport { moveArrayElement, swapArrayElements } from \"../utils/group-utils\";\n\n\n/**\n * Group item core.\n */\nexport type GroupConfig = {\n items?: string[];\n shuffleItems?: boolean;\n isRoot?: boolean;\n};\n\nexport class GroupItemCore extends SurveyItemCore<\n typeof ReservedSurveyItemTypes.Group,\n GroupConfig\n> {\n readonly type = ReservedSurveyItemTypes.Group;\n\n parseConfig(rawConfig: unknown): GroupConfig {\n const cfg = (rawConfig ?? {}) as Partial<GroupConfig>;\n return {\n items: cfg.items,\n shuffleItems: cfg.shuffleItems,\n isRoot: cfg.isRoot,\n };\n }\n\n serializeConfig(): unknown {\n return this.config;\n }\n\n isInteractive(): boolean {\n return false;\n }\n\n getAvailableResponseValueSlots() {\n return {};\n }\n\n isRoot(): boolean {\n return this.config.isRoot ?? false;\n }\n\n get items(): string[] {\n return this.config.items ?? [];\n }\n\n /**\n * Add a child item id to this group at the given index.\n * @param itemId The id of the item to add to this group.\n * @param index The index at which to add the item. If not provided, the item is added to the end of the group.\n */\n addChild(itemId: string, index?: number): void {\n const items = this.config.items ??= [];\n const insertIndex = index !== undefined ? Math.min(index, items.length) : items.length;\n items.splice(insertIndex, 0, itemId);\n this.updateRawItem({\n ...this.rawItem,\n config: { ...this.config },\n });\n }\n\n /**\n * Remove a child item id from this group.\n * @param itemId The id of the item to remove from this group.\n */\n removeChild(itemId: string): void {\n const items = this.config.items ??= [];\n const index = items.indexOf(itemId);\n if (index !== -1) {\n items.splice(index, 1);\n this.updateRawItem({\n ...this.rawItem,\n config: { ...this.config },\n });\n }\n }\n\n /**\n * Check if an item is a direct child of this group.\n */\n hasChild(itemId: string): boolean {\n return this.items.includes(itemId);\n }\n\n /** Whether items in this group should be shuffled. */\n get shuffleItems(): boolean {\n return this.config.shuffleItems ?? false;\n }\n\n set shuffleItems(value: boolean) {\n this.config.shuffleItems = value;\n this.updateRawItem({\n ...this.rawItem,\n config: { ...this.config },\n });\n }\n\n /**\n * Get the ordered list of child item ids.\n */\n getChildrenIds(): string[] {\n return [...this.items];\n }\n\n /**\n * Swap two items by their positions in the group.\n * @throws Error if indices are out of bounds\n */\n swapItemsByIndex(from: number, to: number): void {\n const items = this.items;\n if (from < 0 || from >= items.length || to < 0 || to >= items.length) {\n throw new Error(`Index out of bounds. Valid range is 0-${items.length - 1}`);\n }\n if (from === to) return;\n this.config.items = swapArrayElements(items, from, to);\n this.updateRawItem({\n ...this.rawItem,\n config: { ...this.config },\n });\n }\n\n /**\n * Swap two items by their ids.\n * @throws Error if either id is not found in this group\n */\n swapItemsById(id: string, withId: string): void {\n const items = this.items;\n const index1 = items.indexOf(id);\n const index2 = items.indexOf(withId);\n if (index1 === -1) {\n throw new Error(`Item '${id}' not found in group '${this.key}'`);\n }\n if (index2 === -1) {\n throw new Error(`Item '${withId}' not found in group '${this.key}'`);\n }\n this.swapItemsByIndex(index1, index2);\n }\n\n /**\n * Move an item by id to a specific index.\n * @throws Error if the item is not found or index is out of bounds\n */\n moveItemToIndex(id: string, index: number): void {\n const items = this.items;\n const fromIndex = items.indexOf(id);\n if (fromIndex === -1) {\n throw new Error(`Item '${id}' not found in group '${this.key}'`);\n }\n if (index < 0 || index >= items.length) {\n throw new Error(`Index out of bounds. Valid range is 0-${items.length - 1}`);\n }\n if (fromIndex === index) return;\n this.config.items = moveArrayElement(items, fromIndex, index);\n this.updateRawItem({\n ...this.rawItem,\n config: { ...this.config },\n });\n }\n}\n\n/**\n * Page break item core.\n */\nexport type PageBreakConfig = Record<string, never>;\n\nexport class PageBreakItemCore extends SurveyItemCore<\n typeof ReservedSurveyItemTypes.PageBreak,\n PageBreakConfig\n> {\n readonly type = ReservedSurveyItemTypes.PageBreak;\n\n parseConfig(_rawConfig: unknown): PageBreakConfig {\n return {};\n }\n\n serializeConfig(): unknown {\n return undefined;\n }\n\n isInteractive(): boolean {\n return false;\n }\n\n getAvailableResponseValueSlots() {\n return {};\n }\n}\n\n/**\n * Built-in item type.\n */\nexport type BuiltInItemType = typeof ReservedSurveyItemTypes.Group | typeof ReservedSurveyItemTypes.PageBreak;\n\nexport const builtInItemCoreRegistry: Record<BuiltInItemType, ItemCoreConstructor> = {\n [ReservedSurveyItemTypes.Group]: GroupItemCore,\n [ReservedSurveyItemTypes.PageBreak]: PageBreakItemCore,\n};\n\nexport const isBuiltInItemType = (itemType: string): itemType is BuiltInItemType =>\n itemType in builtInItemCoreRegistry;\n\n","import { ItemCoreConstructor, SurveyItemCore } from \"../items/survey-item\";\nimport { RawSurveyItem } from \"../items/survey-item-json\";\nimport { builtInItemCoreRegistry, isBuiltInItemType } from \"./built-in-items\";\n\n/**\n * Registry maps item type name → handler constructor.\n * Plugins extend this with their own handler classes.\n */\nexport type ItemTypeRegistry = Record<string, new (rawItem: RawSurveyItem) => SurveyItemCore>;\n\n/** Item type identifier (e.g. \"singleChoiceQuestion\", \"display\"). */\nexport type ItemTypeName = string;\n\n/** Capabilities of an item type (interactive, supports children). */\nexport interface ItemTypeCapabilities {\n interactive?: boolean;\n supportsChildren?: boolean;\n}\n\n/**\n * Definition of an item type: its name, constructor, and optional capabilities.\n * Used by editor/UI layers to compose registries.\n */\nexport interface ItemTypeDefinition {\n itemType: ItemTypeName;\n constructor: ItemCoreConstructor;\n capabilities?: ItemTypeCapabilities;\n}\n\n/** Registry mapping item type name → definition. */\nexport type ItemTypeDefinitionRegistry = Record<ItemTypeName, ItemTypeDefinition>;\n\n/** Convert constructor registry to explicit definitions for higher-layer composition. */\nexport function toItemTypeDefinitionRegistry(registry: ItemTypeRegistry): ItemTypeDefinitionRegistry {\n return Object.fromEntries(\n Object.entries(registry).map(([itemType, constructor]) => [\n itemType,\n { itemType, constructor },\n ])\n );\n}\n\n\n/**\n * Creates a handler instance for a raw survey item.\n * Uses built-in registry for group/page-break, otherwise the provided plugin registry.\n */\nexport function createItemCore(\n rawItem: RawSurveyItem,\n pluginRegistry?: ItemTypeRegistry\n): SurveyItemCore {\n if (isBuiltInItemType(rawItem.itemType)) {\n const HandlerClass = builtInItemCoreRegistry[rawItem.itemType];\n return new HandlerClass(rawItem);\n }\n\n if (pluginRegistry && rawItem.itemType in pluginRegistry) {\n const HandlerClass = pluginRegistry[rawItem.itemType];\n return new HandlerClass(rawItem);\n }\n\n throw new Error(`Unknown item type: ${rawItem.itemType}`);\n}\n\n/**\n * Merge built-in handlers with plugin registry for a complete registry.\n */\nexport function createFullRegistry(pluginRegistry?: ItemTypeRegistry): ItemTypeRegistry {\n return {\n ...builtInItemCoreRegistry,\n ...pluginRegistry,\n };\n}\n\n/** Build full registry as explicit definitions for editor/ui composition. */\nexport function createItemTypeDefinitionRegistry(pluginRegistry?: ItemTypeRegistry): ItemTypeDefinitionRegistry {\n return toItemTypeDefinitionRegistry(createFullRegistry(pluginRegistry));\n}\n","import { JsonTemplateValue } from \"../expressions/template-value\";\nimport { RawSurveyItem } from \"./items\";\nimport { JsonSurveyTranslations } from \"./utils/translations\";\n\nexport const CURRENT_SURVEY_SCHEMA = 'https://github.com/case-framework/case-survey-toolkit/packages/survey-core/schemas/survey-schema.json';\n// TODO: generate schema from survey-core.ts\n\n\nexport interface SurveyVersion {\n id?: string;\n surveyKey: string;\n published?: number;\n unpublished?: number;\n versionId?: string;\n survey: RawSurvey;\n}\n\nexport type RawSurvey = {\n $schema: string;\n maxItemsPerPage?: { large: number, small: number };\n\n surveyItems: Array<RawSurveyItem>;\n\n metadata?: {\n [key: string]: string\n }\n templateValues?: {\n [templateValueKey: string]: JsonTemplateValue;\n };\n translations?: JsonSurveyTranslations;\n}\n","import { structuredCloneMethod } from \"../../utils\";\nimport { Content } from \"./content\";\n\n\nexport const validateLocale = (locale: string): void => {\n if (locale.trim() === '') {\n throw new Error('Locale cannot be empty');\n }\n}\n\nexport class SurveyItemTranslations {\n private _translations?: {\n [locale: string]: JsonComponentContent;\n };\n\n constructor() {\n this._translations = {};\n }\n\n setContent(locale: string, contentKey: string, content?: Content): void {\n validateLocale(locale);\n if (!this._translations?.[locale]) {\n if (!content) {\n // No need to do anything if content is undefined\n return\n }\n this._translations![locale] = {};\n }\n if (!content) {\n delete this._translations![locale][contentKey];\n } else {\n this._translations![locale][contentKey] = content;\n }\n }\n\n setAllForLocale(locale: string, content?: JsonComponentContent): void {\n validateLocale(locale);\n if (!this._translations?.[locale]) {\n if (!content) {\n // No need to do anything if content is undefined\n return\n }\n this._translations![locale] = {};\n }\n this._translations![locale] = content || {};\n }\n\n get locales(): string[] {\n return Object.keys(this._translations || {});\n }\n\n getAllForLocale(locale: string): JsonComponentContent | undefined {\n return this._translations?.[locale];\n }\n\n getContent(locale: string, contentKey: string, fallbackLocale?: string): Content | undefined {\n const content = this._translations?.[locale]?.[contentKey];\n if (content) {\n return content;\n }\n if (fallbackLocale) {\n return this._translations?.[fallbackLocale]?.[contentKey];\n }\n return undefined;\n }\n}\n\nexport interface SurveyCardTranslations {\n [locale: string]: SurveyCardContent;\n}\n\n\nexport class SurveyTranslations {\n private _translations: JsonSurveyTranslations;\n\n constructor(translations?: JsonSurveyTranslations) {\n this._translations = translations || {};\n }\n\n\n serialize(): JsonSurveyTranslations | undefined {\n if (this.locales.length === 0) {\n return undefined;\n }\n return this._translations;\n }\n\n get locales(): string[] {\n return Object.keys(this._translations);\n }\n\n removeLocale(locale: string): void {\n validateLocale(locale);\n delete this._translations[locale];\n }\n\n renameLocale(oldLocale: string, newLocale: string): void {\n validateLocale(oldLocale);\n validateLocale(newLocale);\n if (this._translations[oldLocale]) {\n this._translations[newLocale] = this._translations[oldLocale];\n delete this._translations[oldLocale];\n }\n }\n\n cloneLocaleAs(locale: string, newLocale: string): void {\n validateLocale(locale);\n validateLocale(newLocale);\n if (this._translations[locale]) {\n this._translations[newLocale] = structuredCloneMethod(this._translations[locale]);\n }\n }\n\n get surveyCardContent(): SurveyCardTranslations | undefined {\n const translations: SurveyCardTranslations = {};\n for (const locale of this.locales) {\n const contentForLocale = this._translations?.[locale]?.surveyCardContent;\n if (contentForLocale) {\n translations[locale] = contentForLocale as SurveyCardContent;\n }\n }\n return translations;\n }\n\n get navigationContent(): { [locale: string]: NavigationContent } | undefined {\n const translations: { [locale: string]: NavigationContent } = {};\n for (const locale of this.locales) {\n const contentForLocale = this._translations?.[locale]?.navigationContent;\n if (contentForLocale) {\n translations[locale] = contentForLocale as NavigationContent;\n }\n }\n return translations;\n }\n\n get validationMessages(): { [locale: string]: { invalidResponse?: Content } } | undefined {\n const translations: { [locale: string]: { invalidResponse?: Content } } = {};\n for (const locale of this.locales) {\n const contentForLocale = this._translations?.[locale]?.validationMessages;\n if (contentForLocale) {\n translations[locale] = contentForLocale as { invalidResponse?: Content };\n }\n }\n return translations;\n }\n\n setSurveyCardContent(locale: string, content?: SurveyCardContent): void {\n validateLocale(locale);\n if (!this._translations[locale]) {\n if (!content) {\n // No need to do anything if content is undefined\n return\n }\n this._translations[locale] = {};\n }\n this._translations[locale].surveyCardContent = content;\n }\n\n setNavigationContent(locale: string, content?: NavigationContent): void {\n validateLocale(locale);\n if (!this._translations[locale]) {\n if (!content) {\n // No need to do anything if content is undefined\n return\n }\n this._translations[locale] = {};\n }\n this._translations[locale].navigationContent = content;\n }\n\n setValidationMessages(locale: string, content?: { invalidResponse?: Content }): void {\n validateLocale(locale);\n if (!this._translations[locale]) {\n if (!content) {\n // No need to do anything if content is undefined\n return\n }\n this._translations[locale] = {};\n }\n this._translations[locale].validationMessages = content;\n }\n\n getItemTranslations(itemId: string): SurveyItemTranslations | undefined {\n const itemTranslations: SurveyItemTranslations = new SurveyItemTranslations();\n for (const locale of this.locales) {\n const contentForLocale = this._translations?.[locale].itemTranslations?.[itemId];\n itemTranslations.setAllForLocale(locale, contentForLocale as JsonComponentContent);\n }\n return itemTranslations;\n }\n\n setItemTranslations(itemId: string, itemContent?: SurveyItemTranslations): void {\n itemContent?.locales.forEach(locale => validateLocale(locale));\n if (!itemContent) {\n for (const locale of this.locales) {\n if (this._translations[locale].itemTranslations?.[itemId]) {\n delete this._translations[locale].itemTranslations?.[itemId];\n }\n }\n } else {\n const localesInUpdate = itemContent.locales;\n // Add new locales to the translations\n for (const locale of localesInUpdate) {\n if (!this.locales.includes(locale)) {\n this._translations[locale] = {};\n }\n }\n for (const locale of this.locales) {\n if (localesInUpdate.includes(locale)) {\n if (!this._translations[locale]) {\n this._translations[locale] = {};\n }\n if (!this._translations[locale].itemTranslations) {\n this._translations[locale].itemTranslations = {};\n }\n this._translations[locale].itemTranslations![itemId] = itemContent.getAllForLocale(locale) ?? {};\n } else {\n delete this._translations[locale].itemTranslations![itemId];\n }\n }\n }\n }\n\n /**\n * Rename a component key (within an item) - update key in all translations and remove old key\n * @param itemKey - The key of the item\n * @param oldKey - The old key of the component\n * @param newKey - The new key of the component\n */\n onComponentKeyChanged(itemKey: string, oldKey: string, newKey: string): void {\n for (const locale of this.locales) {\n const itemTranslations = this._translations?.[locale].itemTranslations?.[itemKey] as JsonComponentContent;\n if (itemTranslations) {\n for (const key of Object.keys(itemTranslations)) {\n if (key.startsWith(oldKey + '.') || key === oldKey) {\n itemTranslations[key.replace(oldKey, newKey)] = { ...itemTranslations[key] };\n delete itemTranslations[key];\n }\n }\n }\n }\n }\n\n /**\n * Remove all translations for a component\n * @param itemId - The id of the item\n * @param componentKey - The key of the component\n */\n onComponentDeleted(itemId: string, componentKey: string): void {\n for (const locale of this.locales) {\n const itemTranslations = this._translations?.[locale].itemTranslations?.[itemId];\n if (itemTranslations) {\n for (const key of Object.keys(itemTranslations)) {\n if (key.startsWith(componentKey + '.') || key === componentKey) {\n delete itemTranslations[key as keyof typeof itemTranslations];\n }\n }\n }\n }\n }\n\n /**\n * Remove all translations for an item\n * @param id - The id of the item\n */\n onItemDeleted(id: string): void {\n for (const locale of this.locales) {\n delete this._translations![locale].itemTranslations?.[id];\n }\n }\n}\n\n\n/**\n * Json Schemas for translations\n */\nexport type JsonComponentContent = {\n [contentKey: string]: Content;\n}\n\n\nexport interface SurveyCardContent {\n name?: Content;\n description?: Content;\n typicalDuration?: Content;\n}\n\nexport interface NavigationContent {\n previousButtonText?: Content;\n nextButtonText?: Content;\n submitButtonText?: Content;\n submitBoxMessage?: Content;\n}\n\nexport interface JsonSurveyTranslations {\n [locale: string]: {\n surveyCardContent?: SurveyCardContent;\n navigationContent?: NavigationContent;\n validationMessages?: {\n invalidResponse?: Content;\n }\n itemTranslations?: {\n [itemId: string]: JsonComponentContent;\n }\n }\n}\n","import { CURRENT_SURVEY_SCHEMA, RawSurvey, } from \"./survey-file-schema\";\nimport { SurveyItemTranslations, SurveyTranslations } from \"./utils/translations\";\nimport { SurveyItemCore, RawSurveyItem, ReservedSurveyItemTypes } from \"./items\";\nimport { ReferenceUsage, ReferenceUsageType } from \"./utils/value-reference\";\nimport { SurveyItemKey } from \"./item-key\";\nimport { deserializeTemplateValues, serializeTemplateValues, TemplateValueDefinition } from \"../expressions/template-value\";\nimport { ValueRefTypeLookup, ValueType } from \"./responses/value-types\";\nimport { createItemCore, ItemTypeRegistry } from \"./registry/item-registry\";\nimport { GroupItemCore } from \"./registry/built-in-items\";\nimport { generateCodingKey, generateId } from \"../utils\";\n\n\nexport class Survey {\n maxItemsPerPage?: { large: number, small: number };\n metadata?: {\n [key: string]: string\n }\n surveyItems: Map<string, SurveyItemCore> = new Map();\n private _templateValues?: Map<string, TemplateValueDefinition> = new Map();\n\n private _translations?: SurveyTranslations;\n\n constructor(\n private readonly pluginRegistry?: ItemTypeRegistry\n ) {\n this._translations = new SurveyTranslations();\n }\n\n /** Plugin registry used when parsing items. Exposed for editors that re-parse without their own registry. */\n getPluginRegistry(): ItemTypeRegistry | undefined {\n return this.pluginRegistry;\n }\n\n /**\n * Create a survey item from raw JSON data.\n * Uses the survey's plugin registry when available.\n */\n createItemFromRaw(rawItem: RawSurveyItem): SurveyItemCore {\n return createItemCore(rawItem, this.pluginRegistry);\n }\n\n /**\n * Create a minimal blank survey with a root group and one empty page.\n */\n static createBlankSurvey(\n pluginRegistry?: ItemTypeRegistry,\n surveyKey?: string,\n ): Survey {\n const newKey = surveyKey ?? generateCodingKey();\n const rawSurvey: RawSurvey = {\n $schema: CURRENT_SURVEY_SCHEMA,\n surveyItems: [\n {\n id: generateId(),\n key: newKey,\n itemType: ReservedSurveyItemTypes.Group,\n config: { isRoot: true, items: [], shuffleItems: false },\n },\n ],\n };\n\n return Survey.fromJson(rawSurvey, pluginRegistry);\n }\n\n static fromJson(json: RawSurvey, pluginRegistry?: ItemTypeRegistry): Survey {\n const survey = new Survey(pluginRegistry);\n const rawSurvey = json as RawSurvey;\n if (rawSurvey.$schema !== CURRENT_SURVEY_SCHEMA) {\n throw new Error(`Unsupported survey schema: ${rawSurvey.$schema}`);\n }\n\n survey.surveyItems = new Map();\n if (!rawSurvey.surveyItems || rawSurvey.surveyItems.length === 0) {\n throw new Error('surveyItems is required');\n }\n rawSurvey.surveyItems.forEach(item => {\n const surveyItem = createItemCore(item, pluginRegistry);\n survey.surveyItems.set(surveyItem.id, surveyItem);\n });\n\n // Parse other fields\n if (rawSurvey.templateValues) {\n survey._templateValues = deserializeTemplateValues(rawSurvey.templateValues);\n }\n\n survey._translations = new SurveyTranslations(rawSurvey.translations);\n\n if (rawSurvey.maxItemsPerPage) {\n survey.maxItemsPerPage = rawSurvey.maxItemsPerPage;\n }\n\n if (rawSurvey.metadata) {\n survey.metadata = rawSurvey.metadata;\n }\n\n return survey;\n }\n\n serialize(): RawSurvey {\n const json: RawSurvey = {\n $schema: CURRENT_SURVEY_SCHEMA,\n surveyItems: Array.from(this.surveyItems.values()).map(item => item.rawItem),\n };\n\n // Export other fields\n json.translations = this._translations?.serialize();\n\n if (this._templateValues) {\n json.templateValues = serializeTemplateValues(this._templateValues);\n }\n\n if (this.maxItemsPerPage) {\n json.maxItemsPerPage = this.maxItemsPerPage;\n }\n if (this.metadata) {\n json.metadata = this.metadata;\n }\n\n return json;\n }\n\n get surveyKey(): string | undefined {\n const rootItem = this.rootItem;\n if (!rootItem) {\n return undefined;\n }\n return this.rootItem.key;\n }\n\n get locales(): string[] {\n return this._translations?.locales || [];\n }\n\n get rootItem(): GroupItemCore | undefined {\n const rootItem = Array.from(this.surveyItems.values()).find(item => item instanceof GroupItemCore && item.isRoot) as GroupItemCore | undefined;\n return rootItem;\n }\n\n\n get keyIndex(): Array<{ itemId: string, key: string, keyPath: string[], path: string[] }> {\n const index: Array<{ itemId: string, key: string, keyPath: string[], path: string[] }> = [];\n for (const item of this.surveyItems.values()) {\n const path = this.getItemPath(item.id);\n index.push({\n itemId: item.id, key: item.key,\n keyPath: path.map(id => this.surveyItems.get(id)?.key ?? ''),\n path: path\n });\n }\n return index;\n }\n\n getItemPath(itemId: string): string[] {\n const item = this.surveyItems.get(itemId);\n if (!item) {\n throw new Error(`Item ${itemId} not found`);\n }\n\n if (item instanceof GroupItemCore && item.isRoot()) {\n return [];\n }\n\n // find parent item for the given item id\n const parentItem = this.getParentItem(itemId);\n if (!parentItem) {\n throw new Error(`Parent item for ${itemId} not found`);\n }\n return [...this.getItemPath(parentItem.id), parentItem.id];\n }\n\n getItemKey(itemId: string): SurveyItemKey | undefined {\n const item = this.surveyItems.get(itemId);\n if (!item) {\n return undefined;\n }\n const idPath = this.getItemPath(itemId);\n const keyPath = idPath.map(id => this.surveyItems.get(id)?.key ?? '');\n return new SurveyItemKey(item.key, keyPath);\n }\n\n getParentItem(itemId: string): GroupItemCore | undefined {\n const item = this.surveyItems.get(itemId);\n if (!item) {\n throw new Error(`Item ${itemId} not found`);\n }\n if (item instanceof GroupItemCore && item.isRoot()) {\n return undefined;\n }\n const parentItem = Array.from(this.surveyItems.values()).find(item => item instanceof GroupItemCore && item.config.items?.includes(itemId)) as GroupItemCore | undefined;\n if (!parentItem) {\n return undefined;\n }\n return parentItem;\n }\n\n getChildrenItems(parentId: string): SurveyItemCore[] {\n const parentItem = this.surveyItems.get(parentId);\n if (!parentItem || !(parentItem instanceof GroupItemCore)) {\n return [];\n }\n return (parentItem as GroupItemCore).config.items?.map(id => this.surveyItems.get(id))?.filter(item => item !== undefined) as SurveyItemCore[] || [];\n }\n\n getSiblings(itemId: string): SurveyItemCore[] {\n const item = this.surveyItems.get(itemId);\n if (!item) {\n return [];\n }\n const parentItem = this.getParentItem(itemId);\n return parentItem?.items?.map(id => this.surveyItems.get(id))?.filter(item => item !== undefined) as SurveyItemCore[] || [];\n }\n\n get translations(): SurveyTranslations {\n if (!this._translations) {\n this._translations = new SurveyTranslations();\n }\n return this._translations;\n }\n\n getItemTranslations(id: string): SurveyItemTranslations | undefined {\n const item = this.surveyItems.get(id);\n if (!item) {\n throw new Error(`Item ${id} not found`);\n }\n\n return this._translations?.getItemTranslations(id);\n }\n\n getTemplateValue(templateValueKey: string): TemplateValueDefinition | undefined {\n return this._templateValues?.get(templateValueKey);\n }\n\n setTemplateValue(templateValueKey: string, templateValue: TemplateValueDefinition) {\n if (!this._templateValues) {\n this._templateValues = new Map();\n }\n this._templateValues?.set(templateValueKey, templateValue);\n }\n\n deleteTemplateValue(templateValueKey: string) {\n this._templateValues?.delete(templateValueKey);\n }\n\n getTemplateValueKeys(): string[] {\n return Array.from(this._templateValues?.keys() || []);\n }\n\n getAvailableResponseValueSlots(byType?: ValueType): ValueRefTypeLookup {\n let valueRefs: ValueRefTypeLookup = {};\n for (const item of this.surveyItems.values()) {\n valueRefs = { ...valueRefs, ...item.getAvailableResponseValueSlots(byType) };\n }\n return valueRefs;\n }\n\n /**\n * Get all reference usages for the survey\n * @param forItemId - optional item id to filter usages for a specific item and its children (if not provided, all usages are returned)\n * @returns all reference usages for the survey (or for a specific item and its children)\n */\n getReferenceUsages(forItemId?: string): ReferenceUsage[] {\n const usages: ReferenceUsage[] = [];\n for (const item of this.surveyItems.values()) {\n if (forItemId && item.id !== forItemId && !this.isDescendantOf(item.id, forItemId)) {\n continue;\n }\n usages.push(...item.getReferenceUsages());\n }\n\n if (this._templateValues) {\n for (const [templateValueKey, templateValue] of this._templateValues.entries()) {\n for (const ref of templateValue.expression?.responseVariableRefs || []) {\n usages.push({\n itemId: templateValueKey,\n usageType: ReferenceUsageType.templateValues,\n valueReference: ref,\n });\n }\n }\n }\n\n return usages;\n }\n\n // Helper method to check if targetId is a descendant of ancestorId\n isDescendantOf(targetId: string, ancestorId: string): boolean {\n if (targetId === ancestorId) {\n return true;\n }\n const targetPath = this.getItemPath(targetId);\n return targetPath.includes(ancestorId);\n }\n}\n"],"mappings":";;;;;;AAMA,SAAgB,eAAe,QAA0B;CACvD,MAAM,kBAAkB,MAAM,KAAK,EAAE,QAAQ,GAAG,GAAG,MAAM,EAAE;AAE3D,MAAK,IAAI,IAAI,gBAAgB,SAAS,GAAG,IAAI,GAAG,KAAK;EACnD,MAA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