@case-framework/survey-core 0.7.0 → 0.9.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,997 +0,0 @@
1
- //#region src/survey/responses/value-types.d.ts
2
- declare const ValueType: {
3
- readonly string: "string";
4
- readonly duration: "duration";
5
- readonly reference: "reference";
6
- readonly number: "number";
7
- readonly boolean: "boolean";
8
- readonly date: "date";
9
- readonly stringArray: "string[]";
10
- readonly durationArray: "duration[]";
11
- readonly referenceArray: "reference[]";
12
- readonly numberArray: "number[]";
13
- readonly dateArray: "date[]";
14
- };
15
- type ValueType = (typeof ValueType)[keyof typeof ValueType];
16
- declare const DurationUnits: {
17
- readonly seconds: "seconds";
18
- readonly minutes: "minutes";
19
- readonly hours: "hours";
20
- readonly days: "days";
21
- readonly weeks: "weeks";
22
- readonly months: "months";
23
- readonly years: "years";
24
- };
25
- type DurationUnit = (typeof DurationUnits)[keyof typeof DurationUnits];
26
- declare const NumberPrecision: {
27
- readonly int: "int";
28
- readonly float: "float";
29
- };
30
- type NumberPrecision = (typeof NumberPrecision)[keyof typeof NumberPrecision];
31
- interface SlotResponseBase<TValueType extends ValueType> {
32
- type: TValueType;
33
- }
34
- interface StringResponse extends SlotResponseBase<typeof ValueType.string> {
35
- value: string;
36
- }
37
- interface DurationResponse extends SlotResponseBase<typeof ValueType.duration> {
38
- value: number;
39
- unit: DurationUnit;
40
- precision?: NumberPrecision;
41
- }
42
- interface NumberResponse extends SlotResponseBase<typeof ValueType.number> {
43
- value: number;
44
- precision?: NumberPrecision;
45
- }
46
- interface BooleanResponse extends SlotResponseBase<typeof ValueType.boolean> {
47
- value: boolean;
48
- }
49
- interface ReferenceResponse extends SlotResponseBase<typeof ValueType.reference> {
50
- value: string;
51
- }
52
- interface DateResponse extends SlotResponseBase<typeof ValueType.date> {
53
- value: number;
54
- }
55
- interface StringArrayResponse extends SlotResponseBase<typeof ValueType.stringArray> {
56
- value: string[];
57
- }
58
- interface DurationArrayResponse extends SlotResponseBase<typeof ValueType.durationArray> {
59
- value: number[];
60
- unit: DurationUnit;
61
- precision?: NumberPrecision;
62
- }
63
- interface NumberArrayResponse extends SlotResponseBase<typeof ValueType.numberArray> {
64
- value: number[];
65
- precision?: NumberPrecision;
66
- }
67
- interface DateArrayResponse extends SlotResponseBase<typeof ValueType.dateArray> {
68
- value: number[];
69
- }
70
- interface ReferenceArrayResponse extends SlotResponseBase<typeof ValueType.referenceArray> {
71
- value: string[];
72
- }
73
- type ResponseValue = StringResponse | DurationResponse | ReferenceResponse | NumberResponse | BooleanResponse | DateResponse | StringArrayResponse | DurationArrayResponse | NumberArrayResponse | DateArrayResponse | ReferenceArrayResponse;
74
- type ValueRefTypeLookup = {
75
- [valueRefString: string]: ValueType;
76
- };
77
- declare function isResponseValue(value: unknown): value is ResponseValue;
78
- declare function assertResponseValue(value: unknown, path: string): asserts value is ResponseValue;
79
- //#endregion
80
- //#region src/survey/utils/value-reference.d.ts
81
- declare enum ValueReferenceMethod {
82
- get = "get",
83
- isDefined = "isDefined"
84
- }
85
- declare class ValueReference {
86
- _itemId: string;
87
- _name: ValueReferenceMethod;
88
- _slotId: string;
89
- constructor(str: string);
90
- get itemId(): string;
91
- get name(): ValueReferenceMethod;
92
- get slotId(): string;
93
- set itemId(itemId: string);
94
- toString(): string;
95
- static fromParts(itemId: string, name: ValueReferenceMethod, slotId: string): ValueReference;
96
- }
97
- declare enum ReferenceUsageType {
98
- displayConditions = "displayConditions",
99
- templateValues = "templateValues",
100
- validations = "validations",
101
- disabledConditions = "disabledConditions",
102
- prefills = "prefills"
103
- }
104
- interface ReferenceUsage {
105
- itemId: string;
106
- fullComponentKey?: string;
107
- usageType?: ReferenceUsageType;
108
- valueReference: ValueReference;
109
- }
110
- //#endregion
111
- //#region src/expressions/expression.d.ts
112
- declare const ExpressionType: {
113
- readonly Const: "const";
114
- readonly ResponseVariable: "responseVariable";
115
- readonly ContextVariable: "contextVariable";
116
- readonly Function: "function";
117
- };
118
- type ExpressionType = (typeof ExpressionType)[keyof typeof ExpressionType];
119
- declare const ContextVariableType: {
120
- readonly Locale: "locale";
121
- readonly ParticipantFlag: "participantFlag";
122
- readonly CustomValue: "customValue";
123
- readonly CustomExpression: "customExpression";
124
- };
125
- type ContextVariableType = (typeof ContextVariableType)[keyof typeof ContextVariableType];
126
- interface ExpressionEditorConfig {
127
- usedTemplate?: string;
128
- label?: string;
129
- description?: string;
130
- }
131
- interface JsonConstExpression {
132
- type: typeof ExpressionType.Const;
133
- value?: ResponseValue;
134
- editorConfig?: ExpressionEditorConfig;
135
- }
136
- interface JsonResponseVariableExpression {
137
- type: typeof ExpressionType.ResponseVariable;
138
- variableRef: string;
139
- editorConfig?: ExpressionEditorConfig;
140
- }
141
- interface JsonContextVariableExpression {
142
- type: typeof ExpressionType.ContextVariable;
143
- contextType: ContextVariableType;
144
- key?: JsonExpression;
145
- arguments?: Array<JsonExpression | undefined>;
146
- asType?: ValueType;
147
- editorConfig?: ExpressionEditorConfig;
148
- }
149
- interface JsonFunctionExpression {
150
- type: typeof ExpressionType.Function;
151
- functionName: string;
152
- arguments: Array<JsonExpression | undefined>;
153
- editorConfig?: ExpressionEditorConfig;
154
- }
155
- type JsonExpression = JsonConstExpression | JsonResponseVariableExpression | JsonContextVariableExpression | JsonFunctionExpression;
156
- /**
157
- * Base class for all expressions.
158
- */
159
- declare abstract class Expression {
160
- type: ExpressionType;
161
- editorConfig?: ExpressionEditorConfig;
162
- constructor(type: ExpressionType, editorConfig?: ExpressionEditorConfig);
163
- static deserialize(json: JsonExpression | undefined): Expression | undefined;
164
- /**
165
- * Returns all unique response variable references in the expression.
166
- * @returns A list of ValueReference objects.
167
- */
168
- abstract get responseVariableRefs(): ValueReference[];
169
- abstract serialize(): JsonExpression | undefined;
170
- clone(): Expression;
171
- }
172
- declare class ConstExpression extends Expression {
173
- type: typeof ExpressionType.Const;
174
- value?: ResponseValue;
175
- constructor(value?: ResponseValue, editorConfig?: ExpressionEditorConfig);
176
- static deserialize(json: JsonExpression): ConstExpression;
177
- get responseVariableRefs(): ValueReference[];
178
- serialize(): JsonExpression;
179
- updateItemKeyReferences(_oldItemKey: string, _newItemKey: string): boolean;
180
- }
181
- declare class ResponseVariableExpression extends Expression {
182
- type: typeof ExpressionType.ResponseVariable;
183
- variableRef: string;
184
- constructor(variableRef: string, editorConfig?: ExpressionEditorConfig);
185
- static deserialize(json: JsonExpression): ResponseVariableExpression;
186
- get responseVariableRefs(): ValueReference[];
187
- get responseVariableRef(): ValueReference;
188
- serialize(): JsonExpression;
189
- }
190
- declare class ContextVariableExpression extends Expression {
191
- type: typeof ExpressionType.ContextVariable;
192
- contextType: ContextVariableType;
193
- key?: Expression;
194
- arguments?: Array<Expression | undefined>;
195
- asType?: ValueType;
196
- constructor(contextType: ContextVariableType, key?: Expression, args?: Array<Expression | undefined>, asType?: ValueType, editorConfig?: ExpressionEditorConfig);
197
- static deserialize(json: JsonExpression): ContextVariableExpression;
198
- get responseVariableRefs(): ValueReference[];
199
- serialize(): JsonExpression;
200
- }
201
- declare enum FunctionExpressionNames {
202
- and = "and",
203
- or = "or",
204
- not = "not",
205
- list_contains = "list_contains",
206
- eq = "eq",
207
- gt = "gt",
208
- gte = "gte",
209
- lt = "lt",
210
- lte = "lte",
211
- in_range = "in_range",
212
- sum = "sum",
213
- min = "min",
214
- max = "max",
215
- str_eq = "str_eq",
216
- date_eq = "date_eq"
217
- }
218
- declare class FunctionExpression extends Expression {
219
- type: typeof ExpressionType.Function;
220
- functionName: FunctionExpressionNames;
221
- arguments: Array<Expression | undefined>;
222
- constructor(functionName: FunctionExpressionNames, args: Array<Expression | undefined>, editorConfig?: ExpressionEditorConfig);
223
- static deserialize(json: JsonExpression): FunctionExpression;
224
- get responseVariableRefs(): ValueReference[];
225
- serialize(): JsonExpression | undefined;
226
- }
227
- //#endregion
228
- //#region src/survey/items/survey-item-json.d.ts
229
- interface RawSurveyItem {
230
- id: string;
231
- key: string;
232
- itemType: string;
233
- editorMetadata?: {
234
- createdAt?: string;
235
- updatedAt?: string;
236
- };
237
- metadata?: {
238
- [key: string]: string;
239
- };
240
- config?: unknown;
241
- validations?: {
242
- [validationKey: string]: JsonExpression | undefined;
243
- };
244
- displayConditions?: {
245
- root?: JsonExpression;
246
- components?: {
247
- [componentId: string]: JsonExpression | undefined;
248
- };
249
- };
250
- disabledConditions?: {
251
- components?: {
252
- [componentId: string]: JsonExpression | undefined;
253
- };
254
- };
255
- prefills?: JsonSurveyItemPrefill[];
256
- }
257
- //#endregion
258
- //#region src/survey/items/types.d.ts
259
- declare enum ReservedSurveyItemTypes {
260
- Group = "group",
261
- PageBreak = "page-break"
262
- }
263
- //#endregion
264
- //#region src/survey/items/utils.d.ts
265
- interface DisplayConditions {
266
- root?: Expression;
267
- components?: {
268
- [componentKey: string]: Expression | undefined;
269
- };
270
- }
271
- interface DisabledConditions {
272
- components?: {
273
- [componentKey: string]: Expression | undefined;
274
- };
275
- }
276
- //#endregion
277
- //#region src/survey/items/survey-item.d.ts
278
- /**
279
- * Core contract for survey item handlers.
280
- * Every item type (built-in and plugin) is represented by a handler class implementing this interface.
281
- * The core uses these methods without any casting.
282
- */
283
- interface SurveyItemCoreType<TConfig = unknown> {
284
- readonly type: string;
285
- readonly id: string;
286
- readonly key: string;
287
- readonly config: TConfig;
288
- isInteractive(): boolean;
289
- getResponseSlotDefinitions(): ResponseSlotDefinition[];
290
- getAvailableResponseValueSlots(byType?: ValueType): ValueRefTypeLookup;
291
- }
292
- /**
293
- * Base class for survey item handlers.
294
- * Each handler holds type, id, key, and config (properly typed) and implements core methods.
295
- * Subclass for each item type; the core works with SurveyItemHandler only—no casting needed.
296
- */
297
- declare abstract class SurveyItemCore<TType extends string = string, TConfig = unknown> implements SurveyItemCoreType<TConfig> {
298
- abstract readonly type: TType;
299
- readonly id: string;
300
- key: string;
301
- config: TConfig;
302
- private _rawItem;
303
- displayConditions?: DisplayConditions;
304
- disabledConditions?: DisabledConditions;
305
- validations?: {
306
- [validationKey: string]: Expression | undefined;
307
- };
308
- prefills?: SurveyItemPrefill[];
309
- constructor(rawItem: RawSurveyItem);
310
- /** Parse raw config from JSON into typed config. Override in subclasses. */
311
- abstract parseConfig(rawConfig: unknown): TConfig;
312
- abstract isInteractive(): boolean;
313
- abstract getResponseSlotDefinitions(): ResponseSlotDefinition[];
314
- protected getAdditionalResponseValueSlots(): ValueRefTypeLookup;
315
- getAvailableResponseValueSlots(byType?: ValueType): ValueRefTypeLookup;
316
- get rawItem(): RawSurveyItem;
317
- get metadata(): {
318
- [key: string]: string;
319
- };
320
- set metadata(metadata: {
321
- [key: string]: string;
322
- });
323
- get editorMetadata(): NonNullable<RawSurveyItem["editorMetadata"]>;
324
- setCreatedAt(timestamp: string): void;
325
- setModifiedAt(timestamp: string): void;
326
- updateRawItem(rawItem: RawSurveyItem): void;
327
- private updateExpressions;
328
- getReferenceUsages(): ReferenceUsage[];
329
- resolvePrefillTarget(target: SurveyItemPrefillTarget): ResponseSlotDefinition | undefined;
330
- normalizePrefillValue(_prefill: SurveyItemPrefill, targetSlot: ResponseSlotDefinition, value: ResponseValue): ResponseValue | undefined;
331
- }
332
- /**
333
- * Constructor type for handler classes. Used by the registry to instantiate handlers.
334
- */
335
- type ItemCoreConstructor<TType extends string = string, TConfig = unknown> = new (rawItem: RawSurveyItem) => SurveyItemCore<TType, TConfig>;
336
- //#endregion
337
- //#region src/expressions/item-expression-registry.d.ts
338
- type ItemExpressionParameterInput = "string" | "number" | "boolean" | "singleSelect" | "multiSelect";
339
- interface ItemExpressionParameterOption {
340
- value: string;
341
- label: string;
342
- description?: string;
343
- }
344
- interface ItemExpressionParameterDefinition<TItem extends SurveyItemCore = SurveyItemCore> {
345
- key: string;
346
- label: string;
347
- description?: string;
348
- input: ItemExpressionParameterInput;
349
- required?: boolean;
350
- defaultValue?: unknown;
351
- getOptions?: (item: TItem) => ItemExpressionParameterOption[];
352
- }
353
- interface ItemExpressionDefinition<TItem extends SurveyItemCore = SurveyItemCore> {
354
- id: string;
355
- label: string;
356
- description?: string;
357
- returnType: ValueType;
358
- parameters?: Array<ItemExpressionParameterDefinition<TItem>>;
359
- buildExpression: (item: TItem, params?: Record<string, unknown>) => Expression;
360
- }
361
- type AnyItemExpressionDefinition = ItemExpressionDefinition<any>;
362
- declare function getItemExpressionDefinition<TItem extends SurveyItemCore>(definitions: ReadonlyArray<ItemExpressionDefinition<TItem>> | undefined, expressionId: string): ItemExpressionDefinition<TItem> | undefined;
363
- declare function buildItemExpression<TItem extends SurveyItemCore>(item: TItem, definitions: ReadonlyArray<ItemExpressionDefinition<TItem>> | undefined, expressionId: string, params?: Record<string, unknown>): Expression;
364
- //#endregion
365
- //#region src/survey/items/prefill.d.ts
366
- declare const SurveyItemPrefillApplyMode: {
367
- readonly ifEmpty: "ifEmpty";
368
- };
369
- type SurveyItemPrefillApplyMode = (typeof SurveyItemPrefillApplyMode)[keyof typeof SurveyItemPrefillApplyMode];
370
- declare const SurveyItemPrefillTargetType: {
371
- readonly itemResponse: "itemResponse";
372
- readonly field: "field";
373
- readonly embeddedField: "embeddedField";
374
- };
375
- type SurveyItemPrefillTargetType = (typeof SurveyItemPrefillTargetType)[keyof typeof SurveyItemPrefillTargetType];
376
- type JsonSurveyItemPrefillTarget = {
377
- type: typeof SurveyItemPrefillTargetType.itemResponse;
378
- } | {
379
- type: typeof SurveyItemPrefillTargetType.field;
380
- fieldId: string;
381
- } | {
382
- type: typeof SurveyItemPrefillTargetType.embeddedField;
383
- optionId: string;
384
- fieldId: string;
385
- };
386
- type SurveyItemPrefillTarget = JsonSurveyItemPrefillTarget;
387
- interface SurveyItemPreviousResponseRef {
388
- surveyKey?: string;
389
- itemId: string;
390
- target?: SurveyItemPrefillTarget;
391
- }
392
- type JsonSurveyItemPrefillSource = {
393
- type: "static";
394
- value: ResponseValue;
395
- } | {
396
- type: "expression";
397
- expression: JsonExpression;
398
- } | {
399
- type: "templateValue";
400
- key: string;
401
- } | {
402
- type: "previousResponse";
403
- ref: SurveyItemPreviousResponseRef;
404
- ifUnsupported?: "skip";
405
- };
406
- type SurveyItemPrefillSource = {
407
- type: "static";
408
- value: ResponseValue;
409
- } | {
410
- type: "expression";
411
- expression: Expression;
412
- } | {
413
- type: "templateValue";
414
- key: string;
415
- } | {
416
- type: "previousResponse";
417
- ref: SurveyItemPreviousResponseRef;
418
- ifUnsupported?: "skip";
419
- };
420
- interface JsonSurveyItemPrefill {
421
- id: string;
422
- target: JsonSurveyItemPrefillTarget;
423
- when?: JsonExpression;
424
- apply?: SurveyItemPrefillApplyMode;
425
- source: JsonSurveyItemPrefillSource;
426
- }
427
- interface SurveyItemPrefill {
428
- id: string;
429
- target: SurveyItemPrefillTarget;
430
- when?: Expression;
431
- apply?: SurveyItemPrefillApplyMode;
432
- source: SurveyItemPrefillSource;
433
- }
434
- declare function deserializeSurveyItemPrefill(json: JsonSurveyItemPrefill): SurveyItemPrefill;
435
- declare function serializeSurveyItemPrefill(prefill: SurveyItemPrefill): JsonSurveyItemPrefill;
436
- declare function prefillTargetsEqual(left: SurveyItemPrefillTarget, right: SurveyItemPrefillTarget): boolean;
437
- //#endregion
438
- //#region src/survey/responses/slot-definition.d.ts
439
- interface ResponseSlotDefinition {
440
- slotId: string;
441
- key: string;
442
- keyPath: string[];
443
- valueType: ValueType;
444
- /** Optional finite value domain used to validate expression constants. */
445
- allowedValues?: ResponseValue[];
446
- prefillTarget?: SurveyItemPrefillTarget;
447
- }
448
- //#endregion
449
- //#region src/expressions/template-value.d.ts
450
- declare enum TemplateDefTypes {
451
- Default = "default",
452
- Date2String = "date2string"
453
- }
454
- type TemplateValueBase = {
455
- type: TemplateDefTypes;
456
- returnType: ValueType;
457
- expression?: Expression;
458
- };
459
- type TemplateValueFormatDate = TemplateValueBase & {
460
- type: TemplateDefTypes.Date2String;
461
- returnType: typeof ValueType.string;
462
- dateFormat: string;
463
- };
464
- type TemplateValueDefinition = TemplateValueBase | TemplateValueFormatDate;
465
- declare const serializeTemplateValue: (templateValue: TemplateValueDefinition) => JsonTemplateValue;
466
- declare const serializeTemplateValues: (templateValues: Map<string, TemplateValueDefinition>) => {
467
- [templateValueKey: string]: JsonTemplateValue;
468
- };
469
- declare const deserializeTemplateValue: (json: JsonTemplateValue) => TemplateValueDefinition;
470
- declare const deserializeTemplateValues: (json: {
471
- [templateValueKey: string]: JsonTemplateValue;
472
- }) => Map<string, TemplateValueDefinition>;
473
- interface JsonTemplateValue {
474
- type: TemplateDefTypes;
475
- expression?: JsonExpression;
476
- returnType: ValueType;
477
- dateFormat?: string;
478
- }
479
- //#endregion
480
- //#region src/survey/utils/content.d.ts
481
- declare enum ContentType {
482
- richText = "richText",
483
- plain = "plain",
484
- md = "md"
485
- }
486
- type ContentAttributes = Record<string, unknown>;
487
- type TextAlignment = "left" | "center" | "right" | "justify";
488
- type RichTextStyle = {
489
- weight?: "strong" | "normal";
490
- italic?: "italic" | "normal";
491
- underline?: "underline" | "none";
492
- color?: "primary" | "accent" | "default";
493
- };
494
- type RichTextTextInline = {
495
- type: "text";
496
- text: string;
497
- style?: RichTextStyle;
498
- attrs?: ContentAttributes;
499
- };
500
- type RichTextTemplateInline = {
501
- type: "template";
502
- key: string;
503
- style?: RichTextStyle;
504
- attrs?: ContentAttributes;
505
- };
506
- type RichTextLineBreakInline = {
507
- type: "lineBreak";
508
- attrs?: ContentAttributes;
509
- };
510
- /** Inline nodes allowed inside a {@link RichTextLinkInline} (no nested links). */
511
- type RichTextLinkChildInline = RichTextTextInline | RichTextTemplateInline | RichTextLineBreakInline;
512
- type RichTextLinkInline = {
513
- type: "link";
514
- href: string;
515
- target?: string | null;
516
- rel?: string | null;
517
- title?: string | null;
518
- attrs?: ContentAttributes;
519
- children: RichTextLinkChildInline[];
520
- };
521
- type RichTextInlineExtension = {
522
- type: "inlineExtension";
523
- name: string;
524
- attrs?: ContentAttributes;
525
- };
526
- type RichTextInlineNode = RichTextTextInline | RichTextTemplateInline | RichTextLinkInline | RichTextLineBreakInline | RichTextInlineExtension;
527
- type RichTextParagraphBlock = {
528
- type: "paragraph";
529
- children: RichTextInlineNode[];
530
- alignment?: TextAlignment;
531
- attrs?: ContentAttributes;
532
- };
533
- type RichTextHeadingBlock = {
534
- type: "heading";
535
- level: 1 | 2 | 3 | 4 | 5 | 6;
536
- children: RichTextInlineNode[];
537
- alignment?: TextAlignment;
538
- attrs?: ContentAttributes;
539
- };
540
- type RichTextListItemBlock = {
541
- type: "listItem";
542
- children: RichTextParagraphBlock[];
543
- attrs?: ContentAttributes;
544
- };
545
- type RichTextBulletListBlock = {
546
- type: "bulletList";
547
- items: RichTextListItemBlock[];
548
- attrs?: ContentAttributes;
549
- };
550
- type SurveyContentImageSource = {
551
- type: "external";
552
- url: string;
553
- } | {
554
- type: "asset";
555
- assetId: string;
556
- };
557
- type RichTextImageDimension = {
558
- unit: "px";
559
- value: number;
560
- } | {
561
- unit: "%";
562
- value: number;
563
- };
564
- type RichTextImageSize = {
565
- width?: RichTextImageDimension;
566
- height?: RichTextImageDimension;
567
- maxWidth?: RichTextImageDimension;
568
- maxHeight?: RichTextImageDimension;
569
- };
570
- type RichTextImageBlock = {
571
- type: "image";
572
- source: SurveyContentImageSource;
573
- alt?: string;
574
- caption?: RichTextParagraphBlock[];
575
- size?: RichTextImageSize;
576
- alignment?: TextAlignment;
577
- attrs?: ContentAttributes;
578
- };
579
- type RichTextInfoBoxBlock = {
580
- type: "infoBox";
581
- tone?: "info" | "warning";
582
- title?: RichTextInlineNode[];
583
- collapsible?: boolean;
584
- defaultOpen?: boolean;
585
- children: RichTextParagraphBlock[];
586
- attrs?: ContentAttributes;
587
- };
588
- type RichTextSeparatorBlock = {
589
- type: "separator";
590
- attrs?: ContentAttributes;
591
- };
592
- type RichTextBlockExtension = {
593
- type: "blockExtension";
594
- name: string;
595
- attrs?: ContentAttributes;
596
- };
597
- type RichTextBlockNode = RichTextParagraphBlock | RichTextHeadingBlock | RichTextBulletListBlock | RichTextImageBlock | RichTextInfoBoxBlock | RichTextSeparatorBlock | RichTextBlockExtension;
598
- type RichTextDocument = {
599
- type: "doc";
600
- blocks: RichTextBlockNode[];
601
- };
602
- type RichTextContent = {
603
- type: ContentType.richText;
604
- version: 1;
605
- doc: RichTextDocument;
606
- };
607
- type MDContent = {
608
- type: ContentType.md;
609
- content: string;
610
- };
611
- type PlainTextContent = {
612
- type: ContentType.plain;
613
- content: string;
614
- };
615
- type Content = RichTextContent | MDContent | PlainTextContent;
616
- type RichTextInline = RichTextInlineNode;
617
- interface ContentAssetUsage {
618
- assetId: string;
619
- blockIndex: number;
620
- }
621
- declare function hasRenderableRichTextBlock(block: RichTextBlockNode): boolean;
622
- declare function hasRenderableRichTextContent(content: RichTextContent): boolean;
623
- declare function createRichTextContent(text?: string): RichTextContent;
624
- declare function getPlainTextFromRichTextContent(content: RichTextContent): string;
625
- declare function getContentPlainText(content?: Content): string;
626
- declare function isContentEmpty(content?: Content): boolean;
627
- declare function getAssetUsagesFromContent(content?: Content): ContentAssetUsage[];
628
- //#endregion
629
- //#region src/survey/utils/translations.d.ts
630
- declare const validateLocale: (locale: string) => void;
631
- declare class SurveyItemTranslations {
632
- private _translations?;
633
- constructor();
634
- setContent(locale: string, contentKey: string, content?: Content): void;
635
- setAllForLocale(locale: string, content?: JsonComponentContent): void;
636
- get locales(): string[];
637
- getAllForLocale(locale: string): JsonComponentContent | undefined;
638
- getContent(locale: string, contentKey: string, fallbackLocale?: string): Content | undefined;
639
- /**
640
- * Create a deep clone that can be safely mutated before persisting with
641
- * `setItemTranslations` or `updateItemTranslations`.
642
- */
643
- clone(): SurveyItemTranslations;
644
- /**
645
- * Remove a single content key from every locale in this translation set.
646
- */
647
- removeContentKey(contentKey: string): void;
648
- /**
649
- * Remove every content key that is exactly the prefix or nested beneath it.
650
- */
651
- removeContentKeysWithPrefix(prefix: string): void;
652
- /**
653
- * Remove empty locales in place.
654
- * Returns `undefined` when no translations remain so callers can pass the
655
- * result directly into `setItemTranslations` / `updateItemTranslations`.
656
- */
657
- compact(): SurveyItemTranslations | undefined;
658
- }
659
- interface SurveyCardTranslations {
660
- [locale: string]: SurveyCardContent;
661
- }
662
- declare class SurveyTranslations {
663
- private _translations;
664
- constructor(translations?: JsonSurveyTranslations);
665
- serialize(): JsonSurveyTranslations | undefined;
666
- get locales(): string[];
667
- /**
668
- * Register a locale even when it has no translated content yet.
669
- * Returns false when the locale is already present.
670
- */
671
- addLocale(locale: string): boolean;
672
- removeLocale(locale: string): void;
673
- renameLocale(oldLocale: string, newLocale: string): void;
674
- cloneLocaleAs(locale: string, newLocale: string): void;
675
- get surveyCardContent(): SurveyCardTranslations | undefined;
676
- get navigationContent(): {
677
- [locale: string]: NavigationContent;
678
- } | undefined;
679
- get validationMessages(): {
680
- [locale: string]: {
681
- invalidResponse?: Content;
682
- };
683
- } | undefined;
684
- setSurveyCardContent(locale: string, content?: SurveyCardContent): void;
685
- setNavigationContent(locale: string, content?: NavigationContent): void;
686
- setValidationMessages(locale: string, content?: {
687
- invalidResponse?: Content;
688
- }): void;
689
- getItemTranslations(itemId: string): SurveyItemTranslations | undefined;
690
- /**
691
- * Persist item translations after normalizing them:
692
- * empty keys/locales are removed automatically, and an empty translation set
693
- * clears the item's stored translations entirely.
694
- */
695
- setItemTranslations(itemId: string, itemContent?: SurveyItemTranslations): void;
696
- /**
697
- * Rename a component key (within an item) - update key in all translations and remove old key
698
- * @param itemKey - The key of the item
699
- * @param oldKey - The old key of the component
700
- * @param newKey - The new key of the component
701
- */
702
- onComponentKeyChanged(itemKey: string, oldKey: string, newKey: string): void;
703
- /**
704
- * Remove all translations for a component
705
- * @param itemId - The id of the item
706
- * @param componentKey - The key of the component
707
- */
708
- onComponentDeleted(itemId: string, componentKey: string): void;
709
- /**
710
- * Remove all translations for an item
711
- * @param id - The id of the item
712
- */
713
- onItemDeleted(id: string): void;
714
- }
715
- /**
716
- * Json Schemas for translations
717
- */
718
- type JsonComponentContent = {
719
- [contentKey: string]: Content;
720
- };
721
- interface SurveyCardContent {
722
- name?: Content;
723
- description?: Content;
724
- typicalDuration?: Content;
725
- }
726
- interface NavigationContent {
727
- previousButtonText?: Content;
728
- nextButtonText?: Content;
729
- submitButtonText?: Content;
730
- pageIndicatorText?: Content;
731
- submitBoxMessage?: Content;
732
- }
733
- interface JsonSurveyTranslations {
734
- [locale: string]: {
735
- surveyCardContent?: SurveyCardContent;
736
- navigationContent?: NavigationContent;
737
- validationMessages?: {
738
- invalidResponse?: Content;
739
- };
740
- itemTranslations?: {
741
- [itemId: string]: JsonComponentContent;
742
- };
743
- };
744
- }
745
- //#endregion
746
- //#region src/survey/survey-file-schema.d.ts
747
- declare const CURRENT_SURVEY_SCHEMA = "https://github.com/case-framework/case-survey-toolkit/packages/survey-core/schemas/survey-schema.json";
748
- interface SurveyVersion {
749
- id?: string;
750
- surveyKey: string;
751
- published?: number;
752
- unpublished?: number;
753
- versionId?: string;
754
- survey: RawSurvey;
755
- }
756
- type RawSurveyAsset = {
757
- kind: "image";
758
- source: {
759
- type: "embedded";
760
- mediaType: string;
761
- encoding: "base64";
762
- data: string;
763
- };
764
- metadata?: {
765
- name?: string;
766
- filename?: string;
767
- alt?: string;
768
- width?: number;
769
- height?: number;
770
- };
771
- };
772
- type RawSurvey = {
773
- $schema: string;
774
- maxItemsPerPage?: {
775
- large: number;
776
- small: number;
777
- };
778
- surveyItems: Array<RawSurveyItem>;
779
- assets?: Record<string, RawSurveyAsset>;
780
- metadata?: {
781
- [key: string]: string;
782
- };
783
- templateValues?: {
784
- [templateValueKey: string]: JsonTemplateValue;
785
- };
786
- translations?: JsonSurveyTranslations;
787
- };
788
- //#endregion
789
- //#region src/survey/item-key.d.ts
790
- /**
791
- * SurveyItemKey stores the key of the item and the path to the item.
792
- */
793
- declare class SurveyItemKey {
794
- private _itemKey;
795
- private _path;
796
- private _keySeparator;
797
- constructor(itemKey: string, path: string[] | undefined, keySeparator?: string);
798
- get itemKey(): string;
799
- get path(): Array<string>;
800
- get parentFullKey(): string;
801
- get fullKey(): string;
802
- get isRoot(): boolean;
803
- get keySeparator(): string;
804
- set keySeparator(keySeparator: string);
805
- }
806
- //#endregion
807
- //#region src/survey/registry/item-registry.d.ts
808
- /**
809
- * Registry maps item type name → handler constructor.
810
- * Plugins extend this with their own handler classes.
811
- */
812
- type ItemTypeRegistry = Record<string, new (rawItem: RawSurveyItem) => SurveyItemCore>;
813
- /** Item type identifier (e.g. "singleChoiceQuestion", "display"). */
814
- type ItemTypeName = string;
815
- /** Capabilities of an item type (interactive, supports children). */
816
- interface ItemTypeCapabilities {
817
- interactive?: boolean;
818
- supportsChildren?: boolean;
819
- }
820
- /**
821
- * Definition of an item type: its name, constructor, and optional capabilities.
822
- * Used by editor/UI layers to compose registries.
823
- */
824
- interface ItemTypeDefinition {
825
- itemType: ItemTypeName;
826
- constructor: ItemCoreConstructor;
827
- capabilities?: ItemTypeCapabilities;
828
- expressions?: AnyItemExpressionDefinition[];
829
- }
830
- /** Registry mapping item type name → definition. */
831
- type ItemTypeDefinitionRegistry = Record<ItemTypeName, ItemTypeDefinition>;
832
- /** Convert constructor registry to explicit definitions for higher-layer composition. */
833
- declare function toItemTypeDefinitionRegistry(registry: ItemTypeRegistry): ItemTypeDefinitionRegistry;
834
- /**
835
- * Creates a handler instance for a raw survey item.
836
- * Uses built-in registry for group/page-break, otherwise the provided plugin registry.
837
- */
838
- declare function createItemCore(rawItem: RawSurveyItem, pluginRegistry?: ItemTypeRegistry): SurveyItemCore;
839
- /**
840
- * Merge built-in handlers with plugin registry for a complete registry.
841
- */
842
- declare function createFullRegistry(pluginRegistry?: ItemTypeRegistry): ItemTypeRegistry;
843
- /** Build full registry as explicit definitions for editor/ui composition. */
844
- declare function createItemTypeDefinitionRegistry(pluginRegistry?: ItemTypeRegistry): ItemTypeDefinitionRegistry;
845
- //#endregion
846
- //#region src/survey/registry/built-in-items.d.ts
847
- /**
848
- * Group item core.
849
- */
850
- type GroupConfig = {
851
- items?: string[];
852
- shuffleItems?: boolean;
853
- isRoot?: boolean;
854
- };
855
- declare class GroupItemCore extends SurveyItemCore<typeof ReservedSurveyItemTypes.Group, GroupConfig> {
856
- readonly type = ReservedSurveyItemTypes.Group;
857
- parseConfig(rawConfig: unknown): GroupConfig;
858
- serializeConfig(): unknown;
859
- isInteractive(): boolean;
860
- getResponseSlotDefinitions(): never[];
861
- isRoot(): boolean;
862
- get items(): string[];
863
- /**
864
- * Add a child item id to this group at the given index.
865
- * @param itemId The id of the item to add to this group.
866
- * @param index The index at which to add the item. If not provided, the item is added to the end of the group.
867
- */
868
- addChild(itemId: string, index?: number): void;
869
- /**
870
- * Remove a child item id from this group.
871
- * @param itemId The id of the item to remove from this group.
872
- */
873
- removeChild(itemId: string): void;
874
- /**
875
- * Check if an item is a direct child of this group.
876
- */
877
- hasChild(itemId: string): boolean;
878
- /** Whether items in this group should be shuffled. */
879
- get shuffleItems(): boolean;
880
- set shuffleItems(value: boolean);
881
- /**
882
- * Get the ordered list of child item ids.
883
- */
884
- getChildrenIds(): string[];
885
- /**
886
- * Swap two items by their positions in the group.
887
- * @throws Error if indices are out of bounds
888
- */
889
- swapItemsByIndex(from: number, to: number): void;
890
- /**
891
- * Swap two items by their ids.
892
- * @throws Error if either id is not found in this group
893
- */
894
- swapItemsById(id: string, withId: string): void;
895
- /**
896
- * Move an item by id to a specific index.
897
- * @throws Error if the item is not found or index is out of bounds
898
- */
899
- moveItemToIndex(id: string, index: number): void;
900
- }
901
- /**
902
- * Page break item core.
903
- */
904
- type PageBreakConfig = Record<string, never>;
905
- declare class PageBreakItemCore extends SurveyItemCore<typeof ReservedSurveyItemTypes.PageBreak, PageBreakConfig> {
906
- readonly type = ReservedSurveyItemTypes.PageBreak;
907
- parseConfig(_rawConfig: unknown): PageBreakConfig;
908
- serializeConfig(): unknown;
909
- isInteractive(): boolean;
910
- getResponseSlotDefinitions(): never[];
911
- }
912
- /**
913
- * Built-in item type.
914
- */
915
- type BuiltInItemType = typeof ReservedSurveyItemTypes.Group | typeof ReservedSurveyItemTypes.PageBreak;
916
- declare const builtInItemCoreRegistry: Record<BuiltInItemType, ItemCoreConstructor>;
917
- declare const isBuiltInItemType: (itemType: string) => itemType is BuiltInItemType;
918
- //#endregion
919
- //#region src/survey/survey.d.ts
920
- interface SurveyAssetUsage {
921
- assetId: string;
922
- itemId?: string;
923
- locale?: string;
924
- contentKey: string;
925
- usageScope: "itemTranslation" | "surveyCard" | "navigation" | "validationMessages";
926
- blockIndex: number;
927
- }
928
- declare class Survey {
929
- private readonly pluginRegistry?;
930
- maxItemsPerPage?: {
931
- large: number;
932
- small: number;
933
- };
934
- metadata?: {
935
- [key: string]: string;
936
- };
937
- surveyItems: Map<string, SurveyItemCore>;
938
- private _templateValues?;
939
- private _assets?;
940
- private _translations?;
941
- constructor(pluginRegistry?: ItemTypeRegistry | undefined);
942
- /** Plugin registry used when parsing items. Exposed for editors that re-parse without their own registry. */
943
- getPluginRegistry(): ItemTypeRegistry | undefined;
944
- /**
945
- * Create a survey item from raw JSON data.
946
- * Uses the survey's plugin registry when available.
947
- */
948
- createItemFromRaw(rawItem: RawSurveyItem): SurveyItemCore;
949
- /**
950
- * Create a minimal blank survey with a root group and one empty page.
951
- */
952
- static createBlankSurvey(pluginRegistry?: ItemTypeRegistry, surveyKey?: string): Survey;
953
- static fromJson(json: RawSurvey, pluginRegistry?: ItemTypeRegistry): Survey;
954
- serialize(): RawSurvey;
955
- get surveyKey(): string | undefined;
956
- get locales(): string[];
957
- get rootItem(): GroupItemCore | undefined;
958
- get keyIndex(): Array<{
959
- itemId: string;
960
- key: string;
961
- keyPath: string[];
962
- path: string[];
963
- }>;
964
- getItemPath(itemId: string): string[];
965
- getItemKey(itemId: string): SurveyItemKey | undefined;
966
- getParentItem(itemId: string): GroupItemCore | undefined;
967
- getChildrenItems(parentId: string): SurveyItemCore[];
968
- getSiblings(itemId: string): SurveyItemCore[];
969
- get translations(): SurveyTranslations;
970
- getItemTranslations(id: string): SurveyItemTranslations | undefined;
971
- getTemplateValue(templateValueKey: string): TemplateValueDefinition | undefined;
972
- setTemplateValue(templateValueKey: string, templateValue: TemplateValueDefinition): void;
973
- deleteTemplateValue(templateValueKey: string): void;
974
- getTemplateValueKeys(): string[];
975
- getAsset(assetId: string): RawSurveyAsset | undefined;
976
- setAsset(assetId: string, asset: RawSurveyAsset): void;
977
- deleteAsset(assetId: string): void;
978
- hasAsset(assetId: string): boolean;
979
- getAssetIds(): string[];
980
- getAssets(): Map<string, RawSurveyAsset>;
981
- getAssetUsages(filterAssetId?: string): SurveyAssetUsage[];
982
- getAvailableResponseValueSlots(byType?: ValueType): ValueRefTypeLookup;
983
- getResponseSlotDefinitions(): Array<{
984
- itemId: string;
985
- slots: ResponseSlotDefinition[];
986
- }>;
987
- /**
988
- * Get all reference usages for the survey
989
- * @param forItemId - optional item id to filter usages for a specific item and its children (if not provided, all usages are returned)
990
- * @returns all reference usages for the survey (or for a specific item and its children)
991
- */
992
- getReferenceUsages(forItemId?: string): ReferenceUsage[];
993
- isDescendantOf(targetId: string, ancestorId: string): boolean;
994
- }
995
- //#endregion
996
- export { RichTextLinkInline as $, ExpressionEditorConfig as $t, SurveyTranslations as A, ValueType as An, SurveyItemPrefillSource as At, RichTextBulletListBlock as B, ItemExpressionParameterInput as Bt, SurveyVersion as C, ReferenceArrayResponse as Cn, serializeTemplateValues as Ct, SurveyCardContent as D, StringArrayResponse as Dn, JsonSurveyItemPrefillTarget as Dt, NavigationContent as E, SlotResponseBase as En, JsonSurveyItemPrefillSource as Et, ContentType as F, prefillTargetsEqual as Ft, RichTextImageDimension as G, SurveyItemCore as Gt, RichTextDocument as H, buildItemExpression as Ht, MDContent as I, serializeSurveyItemPrefill as It, RichTextInline as J, RawSurveyItem as Jt, RichTextImageSize as K, SurveyItemCoreType as Kt, PlainTextContent as L, AnyItemExpressionDefinition as Lt, Content as M, isResponseValue as Mn, SurveyItemPrefillTargetType as Mt, ContentAssetUsage as N, SurveyItemPreviousResponseRef as Nt, SurveyCardTranslations as O, StringResponse as On, SurveyItemPrefill as Ot, ContentAttributes as P, deserializeSurveyItemPrefill as Pt, RichTextLinkChildInline as Q, Expression as Qt, RichTextBlockExtension as R, ItemExpressionDefinition as Rt, RawSurveyAsset as S, NumberResponse as Sn, serializeTemplateValue as St, JsonSurveyTranslations as T, ResponseValue as Tn, JsonSurveyItemPrefill as Tt, RichTextHeadingBlock as U, getItemExpressionDefinition as Ut, RichTextContent as V, ItemExpressionParameterOption as Vt, RichTextImageBlock as W, ItemCoreConstructor as Wt, RichTextInlineNode as X, ContextVariableExpression as Xt, RichTextInlineExtension as Y, ConstExpression as Yt, RichTextLineBreakInline as Z, ContextVariableType as Zt, createItemTypeDefinitionRegistry as _, DurationResponse as _n, TemplateValueBase as _t, GroupItemCore as a, JsonExpression as an, RichTextTextInline as at, CURRENT_SURVEY_SCHEMA as b, NumberArrayResponse as bn, deserializeTemplateValue as bt, builtInItemCoreRegistry as c, ResponseVariableExpression as cn, createRichTextContent as ct, ItemTypeDefinition as d, ValueReference as dn, getPlainTextFromRichTextContent as dt, ExpressionType as en, RichTextListItemBlock as et, ItemTypeDefinitionRegistry as f, ValueReferenceMethod as fn, hasRenderableRichTextBlock as ft, createItemCore as g, DurationArrayResponse as gn, TemplateDefTypes as gt, createFullRegistry as h, DateResponse as hn, JsonTemplateValue as ht, GroupConfig as i, JsonContextVariableExpression as in, RichTextTemplateInline as it, validateLocale as j, assertResponseValue as jn, SurveyItemPrefillTarget as jt, SurveyItemTranslations as k, ValueRefTypeLookup as kn, SurveyItemPrefillApplyMode as kt, isBuiltInItemType as l, ReferenceUsage as ln, getAssetUsagesFromContent as lt, ItemTypeRegistry as m, DateArrayResponse as mn, isContentEmpty as mt, SurveyAssetUsage as n, FunctionExpressionNames as nn, RichTextSeparatorBlock as nt, PageBreakConfig as o, JsonFunctionExpression as on, SurveyContentImageSource as ot, ItemTypeName as p, BooleanResponse as pn, hasRenderableRichTextContent as pt, RichTextInfoBoxBlock as q, ReservedSurveyItemTypes as qt, BuiltInItemType as r, JsonConstExpression as rn, RichTextStyle as rt, PageBreakItemCore as s, JsonResponseVariableExpression as sn, TextAlignment as st, Survey as t, FunctionExpression as tn, RichTextParagraphBlock as tt, ItemTypeCapabilities as u, ReferenceUsageType as un, getContentPlainText as ut, toItemTypeDefinitionRegistry as v, DurationUnit as vn, TemplateValueDefinition as vt, JsonComponentContent as w, ReferenceResponse as wn, ResponseSlotDefinition as wt, RawSurvey as x, NumberPrecision as xn, deserializeTemplateValues as xt, SurveyItemKey as y, DurationUnits as yn, TemplateValueFormatDate as yt, RichTextBlockNode as z, ItemExpressionParameterDefinition as zt };
997
- //# sourceMappingURL=survey-DedDemSc.d.mts.map