@case-framework/survey-core 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/editor.d.mts +52 -12
- package/build/editor.d.mts.map +1 -1
- package/build/editor.mjs +223 -48
- package/build/editor.mjs.map +1 -1
- package/build/index.d.mts +80 -50
- package/build/index.d.mts.map +1 -1
- package/build/index.mjs +235 -169
- package/build/index.mjs.map +1 -1
- package/build/package.json +8 -8
- package/build/{survey-D3sMutUV.d.mts → survey-DShEOjyz.d.mts} +389 -82
- package/build/survey-DShEOjyz.d.mts.map +1 -0
- package/build/{survey-DQmpzihl.mjs → survey-yXdl8xkf.mjs} +479 -48
- package/build/survey-yXdl8xkf.mjs.map +1 -0
- package/package.json +8 -8
- package/build/survey-D3sMutUV.d.mts.map +0 -1
- package/build/survey-DQmpzihl.mjs.map +0 -1
package/build/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@case-framework/survey-core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.0",
|
|
4
4
|
"description": "Implementation of the survey core to use in typescript/javascript projects.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
@@ -18,14 +18,14 @@
|
|
|
18
18
|
"author": "phev8",
|
|
19
19
|
"license": "ISC",
|
|
20
20
|
"devDependencies": {
|
|
21
|
-
"@eslint/js": "^9.39.
|
|
21
|
+
"@eslint/js": "^9.39.4",
|
|
22
22
|
"@types/jest": "^30.0.0",
|
|
23
|
-
"eslint": "^9.39.
|
|
24
|
-
"jest": "^30.0
|
|
25
|
-
"ts-jest": "^29.4.
|
|
26
|
-
"tsdown": "^0.
|
|
27
|
-
"typescript": "^
|
|
28
|
-
"typescript-eslint": "^8.
|
|
23
|
+
"eslint": "^9.39.4",
|
|
24
|
+
"jest": "^30.3.0",
|
|
25
|
+
"ts-jest": "^29.4.9",
|
|
26
|
+
"tsdown": "^0.21.10",
|
|
27
|
+
"typescript": "^6.0.3",
|
|
28
|
+
"typescript-eslint": "^8.59.1"
|
|
29
29
|
},
|
|
30
30
|
"dependencies": {
|
|
31
31
|
"date-fns": "^4.1.0"
|
|
@@ -74,6 +74,8 @@ type ResponseValue = StringResponse | DurationResponse | ReferenceResponse | Num
|
|
|
74
74
|
type ValueRefTypeLookup = {
|
|
75
75
|
[valueRefString: string]: ValueType;
|
|
76
76
|
};
|
|
77
|
+
declare function isResponseValue(value: unknown): value is ResponseValue;
|
|
78
|
+
declare function assertResponseValue(value: unknown, path: string): asserts value is ResponseValue;
|
|
77
79
|
//#endregion
|
|
78
80
|
//#region src/survey/utils/value-reference.d.ts
|
|
79
81
|
declare enum ValueReferenceMethod {
|
|
@@ -96,7 +98,8 @@ declare enum ReferenceUsageType {
|
|
|
96
98
|
displayConditions = "displayConditions",
|
|
97
99
|
templateValues = "templateValues",
|
|
98
100
|
validations = "validations",
|
|
99
|
-
disabledConditions = "disabledConditions"
|
|
101
|
+
disabledConditions = "disabledConditions",
|
|
102
|
+
prefills = "prefills"
|
|
100
103
|
}
|
|
101
104
|
interface ReferenceUsage {
|
|
102
105
|
itemId: string;
|
|
@@ -122,6 +125,8 @@ declare const ContextVariableType: {
|
|
|
122
125
|
type ContextVariableType = (typeof ContextVariableType)[keyof typeof ContextVariableType];
|
|
123
126
|
interface ExpressionEditorConfig {
|
|
124
127
|
usedTemplate?: string;
|
|
128
|
+
label?: string;
|
|
129
|
+
description?: string;
|
|
125
130
|
}
|
|
126
131
|
interface JsonConstExpression {
|
|
127
132
|
type: typeof ExpressionType.Const;
|
|
@@ -220,35 +225,36 @@ declare class FunctionExpression extends Expression {
|
|
|
220
225
|
serialize(): JsonExpression | undefined;
|
|
221
226
|
}
|
|
222
227
|
//#endregion
|
|
223
|
-
//#region src/
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
228
|
+
//#region src/survey/items/survey-item-json.d.ts
|
|
229
|
+
interface RawSurveyItem {
|
|
230
|
+
id: string;
|
|
231
|
+
key: string;
|
|
232
|
+
itemType: string;
|
|
233
|
+
metadata?: {
|
|
234
|
+
[key: string]: string;
|
|
235
|
+
};
|
|
236
|
+
config?: unknown;
|
|
237
|
+
validations?: {
|
|
238
|
+
[validationKey: string]: JsonExpression | undefined;
|
|
239
|
+
};
|
|
240
|
+
displayConditions?: {
|
|
241
|
+
root?: JsonExpression;
|
|
242
|
+
components?: {
|
|
243
|
+
[componentId: string]: JsonExpression | undefined;
|
|
244
|
+
};
|
|
245
|
+
};
|
|
246
|
+
disabledConditions?: {
|
|
247
|
+
components?: {
|
|
248
|
+
[componentId: string]: JsonExpression | undefined;
|
|
249
|
+
};
|
|
250
|
+
};
|
|
251
|
+
prefills?: JsonSurveyItemPrefill[];
|
|
227
252
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
type TemplateValueFormatDate = TemplateValueBase & {
|
|
234
|
-
type: TemplateDefTypes.Date2String;
|
|
235
|
-
returnType: typeof ValueType.string;
|
|
236
|
-
dateFormat: string;
|
|
237
|
-
};
|
|
238
|
-
type TemplateValueDefinition = TemplateValueBase | TemplateValueFormatDate;
|
|
239
|
-
declare const serializeTemplateValue: (templateValue: TemplateValueDefinition) => JsonTemplateValue;
|
|
240
|
-
declare const serializeTemplateValues: (templateValues: Map<string, TemplateValueDefinition>) => {
|
|
241
|
-
[templateValueKey: string]: JsonTemplateValue;
|
|
242
|
-
};
|
|
243
|
-
declare const deserializeTemplateValue: (json: JsonTemplateValue) => TemplateValueDefinition;
|
|
244
|
-
declare const deserializeTemplateValues: (json: {
|
|
245
|
-
[templateValueKey: string]: JsonTemplateValue;
|
|
246
|
-
}) => Map<string, TemplateValueDefinition>;
|
|
247
|
-
interface JsonTemplateValue {
|
|
248
|
-
type: TemplateDefTypes;
|
|
249
|
-
expression?: JsonExpression;
|
|
250
|
-
returnType: ValueType;
|
|
251
|
-
dateFormat?: string;
|
|
253
|
+
//#endregion
|
|
254
|
+
//#region src/survey/items/types.d.ts
|
|
255
|
+
declare enum ReservedSurveyItemTypes {
|
|
256
|
+
Group = "group",
|
|
257
|
+
PageBreak = "page-break"
|
|
252
258
|
}
|
|
253
259
|
//#endregion
|
|
254
260
|
//#region src/survey/items/utils.d.ts
|
|
@@ -276,7 +282,8 @@ interface SurveyItemCoreType<TConfig = unknown> {
|
|
|
276
282
|
readonly key: string;
|
|
277
283
|
readonly config: TConfig;
|
|
278
284
|
isInteractive(): boolean;
|
|
279
|
-
|
|
285
|
+
getResponseSlotDefinitions(): ResponseSlotDefinition[];
|
|
286
|
+
getAvailableResponseValueSlots(byType?: ValueType): ValueRefTypeLookup;
|
|
280
287
|
}
|
|
281
288
|
/**
|
|
282
289
|
* Base class for survey item handlers.
|
|
@@ -294,12 +301,14 @@ declare abstract class SurveyItemCore<TType extends string = string, TConfig = u
|
|
|
294
301
|
validations?: {
|
|
295
302
|
[validationKey: string]: Expression | undefined;
|
|
296
303
|
};
|
|
297
|
-
|
|
304
|
+
prefills?: SurveyItemPrefill[];
|
|
298
305
|
constructor(rawItem: RawSurveyItem);
|
|
299
306
|
/** Parse raw config from JSON into typed config. Override in subclasses. */
|
|
300
307
|
abstract parseConfig(rawConfig: unknown): TConfig;
|
|
301
308
|
abstract isInteractive(): boolean;
|
|
302
|
-
abstract
|
|
309
|
+
abstract getResponseSlotDefinitions(): ResponseSlotDefinition[];
|
|
310
|
+
protected getAdditionalResponseValueSlots(): ValueRefTypeLookup;
|
|
311
|
+
getAvailableResponseValueSlots(byType?: ValueType): ValueRefTypeLookup;
|
|
303
312
|
get rawItem(): RawSurveyItem;
|
|
304
313
|
get metadata(): {
|
|
305
314
|
[key: string]: string;
|
|
@@ -310,75 +319,301 @@ declare abstract class SurveyItemCore<TType extends string = string, TConfig = u
|
|
|
310
319
|
updateRawItem(rawItem: RawSurveyItem): void;
|
|
311
320
|
private updateExpressions;
|
|
312
321
|
getReferenceUsages(): ReferenceUsage[];
|
|
322
|
+
resolvePrefillTarget(target: SurveyItemPrefillTarget): ResponseSlotDefinition | undefined;
|
|
323
|
+
normalizePrefillValue(_prefill: SurveyItemPrefill, targetSlot: ResponseSlotDefinition, value: ResponseValue): ResponseValue | undefined;
|
|
313
324
|
}
|
|
314
325
|
/**
|
|
315
326
|
* Constructor type for handler classes. Used by the registry to instantiate handlers.
|
|
316
327
|
*/
|
|
317
328
|
type ItemCoreConstructor<TType extends string = string, TConfig = unknown> = new (rawItem: RawSurveyItem) => SurveyItemCore<TType, TConfig>;
|
|
318
329
|
//#endregion
|
|
319
|
-
//#region src/
|
|
320
|
-
|
|
330
|
+
//#region src/expressions/item-expression-registry.d.ts
|
|
331
|
+
type ItemExpressionParameterInput = "string" | "number" | "boolean" | "singleSelect" | "multiSelect";
|
|
332
|
+
interface ItemExpressionParameterOption {
|
|
333
|
+
value: string;
|
|
334
|
+
label: string;
|
|
335
|
+
description?: string;
|
|
336
|
+
}
|
|
337
|
+
interface ItemExpressionParameterDefinition<TItem extends SurveyItemCore = SurveyItemCore> {
|
|
338
|
+
key: string;
|
|
339
|
+
label: string;
|
|
340
|
+
description?: string;
|
|
341
|
+
input: ItemExpressionParameterInput;
|
|
342
|
+
required?: boolean;
|
|
343
|
+
defaultValue?: unknown;
|
|
344
|
+
getOptions?: (item: TItem) => ItemExpressionParameterOption[];
|
|
345
|
+
}
|
|
346
|
+
interface ItemExpressionDefinition<TItem extends SurveyItemCore = SurveyItemCore> {
|
|
321
347
|
id: string;
|
|
348
|
+
label: string;
|
|
349
|
+
description?: string;
|
|
350
|
+
returnType: ValueType;
|
|
351
|
+
parameters?: Array<ItemExpressionParameterDefinition<TItem>>;
|
|
352
|
+
buildExpression: (item: TItem, params?: Record<string, unknown>) => Expression;
|
|
353
|
+
}
|
|
354
|
+
type AnyItemExpressionDefinition = ItemExpressionDefinition<any>;
|
|
355
|
+
declare function getItemExpressionDefinition<TItem extends SurveyItemCore>(definitions: ReadonlyArray<ItemExpressionDefinition<TItem>> | undefined, expressionId: string): ItemExpressionDefinition<TItem> | undefined;
|
|
356
|
+
declare function buildItemExpression<TItem extends SurveyItemCore>(item: TItem, definitions: ReadonlyArray<ItemExpressionDefinition<TItem>> | undefined, expressionId: string, params?: Record<string, unknown>): Expression;
|
|
357
|
+
//#endregion
|
|
358
|
+
//#region src/survey/items/prefill.d.ts
|
|
359
|
+
declare const SurveyItemPrefillApplyMode: {
|
|
360
|
+
readonly ifEmpty: "ifEmpty";
|
|
361
|
+
};
|
|
362
|
+
type SurveyItemPrefillApplyMode = (typeof SurveyItemPrefillApplyMode)[keyof typeof SurveyItemPrefillApplyMode];
|
|
363
|
+
declare const SurveyItemPrefillTargetType: {
|
|
364
|
+
readonly itemResponse: "itemResponse";
|
|
365
|
+
readonly field: "field";
|
|
366
|
+
readonly embeddedField: "embeddedField";
|
|
367
|
+
};
|
|
368
|
+
type SurveyItemPrefillTargetType = (typeof SurveyItemPrefillTargetType)[keyof typeof SurveyItemPrefillTargetType];
|
|
369
|
+
type JsonSurveyItemPrefillTarget = {
|
|
370
|
+
type: typeof SurveyItemPrefillTargetType.itemResponse;
|
|
371
|
+
} | {
|
|
372
|
+
type: typeof SurveyItemPrefillTargetType.field;
|
|
373
|
+
fieldId: string;
|
|
374
|
+
} | {
|
|
375
|
+
type: typeof SurveyItemPrefillTargetType.embeddedField;
|
|
376
|
+
optionId: string;
|
|
377
|
+
fieldId: string;
|
|
378
|
+
};
|
|
379
|
+
type SurveyItemPrefillTarget = JsonSurveyItemPrefillTarget;
|
|
380
|
+
interface SurveyItemPreviousResponseRef {
|
|
381
|
+
surveyKey?: string;
|
|
382
|
+
itemId: string;
|
|
383
|
+
target?: SurveyItemPrefillTarget;
|
|
384
|
+
}
|
|
385
|
+
type JsonSurveyItemPrefillSource = {
|
|
386
|
+
type: "static";
|
|
387
|
+
value: ResponseValue;
|
|
388
|
+
} | {
|
|
389
|
+
type: "expression";
|
|
390
|
+
expression: JsonExpression;
|
|
391
|
+
} | {
|
|
392
|
+
type: "templateValue";
|
|
322
393
|
key: string;
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
394
|
+
} | {
|
|
395
|
+
type: "previousResponse";
|
|
396
|
+
ref: SurveyItemPreviousResponseRef;
|
|
397
|
+
ifUnsupported?: "skip";
|
|
398
|
+
};
|
|
399
|
+
type SurveyItemPrefillSource = {
|
|
400
|
+
type: "static";
|
|
401
|
+
value: ResponseValue;
|
|
402
|
+
} | {
|
|
403
|
+
type: "expression";
|
|
404
|
+
expression: Expression;
|
|
405
|
+
} | {
|
|
406
|
+
type: "templateValue";
|
|
407
|
+
key: string;
|
|
408
|
+
} | {
|
|
409
|
+
type: "previousResponse";
|
|
410
|
+
ref: SurveyItemPreviousResponseRef;
|
|
411
|
+
ifUnsupported?: "skip";
|
|
412
|
+
};
|
|
413
|
+
interface JsonSurveyItemPrefill {
|
|
414
|
+
id: string;
|
|
415
|
+
target: JsonSurveyItemPrefillTarget;
|
|
416
|
+
when?: JsonExpression;
|
|
417
|
+
apply?: SurveyItemPrefillApplyMode;
|
|
418
|
+
source: JsonSurveyItemPrefillSource;
|
|
343
419
|
}
|
|
420
|
+
interface SurveyItemPrefill {
|
|
421
|
+
id: string;
|
|
422
|
+
target: SurveyItemPrefillTarget;
|
|
423
|
+
when?: Expression;
|
|
424
|
+
apply?: SurveyItemPrefillApplyMode;
|
|
425
|
+
source: SurveyItemPrefillSource;
|
|
426
|
+
}
|
|
427
|
+
declare function deserializeSurveyItemPrefill(json: JsonSurveyItemPrefill): SurveyItemPrefill;
|
|
428
|
+
declare function serializeSurveyItemPrefill(prefill: SurveyItemPrefill): JsonSurveyItemPrefill;
|
|
429
|
+
declare function prefillTargetsEqual(left: SurveyItemPrefillTarget, right: SurveyItemPrefillTarget): boolean;
|
|
344
430
|
//#endregion
|
|
345
|
-
//#region src/survey/
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
431
|
+
//#region src/survey/responses/slot-definition.d.ts
|
|
432
|
+
interface ResponseSlotDefinition {
|
|
433
|
+
slotId: string;
|
|
434
|
+
key: string;
|
|
435
|
+
keyPath: string[];
|
|
436
|
+
valueType: ValueType;
|
|
437
|
+
prefillTarget?: SurveyItemPrefillTarget;
|
|
438
|
+
}
|
|
439
|
+
//#endregion
|
|
440
|
+
//#region src/expressions/template-value.d.ts
|
|
441
|
+
declare enum TemplateDefTypes {
|
|
442
|
+
Default = "default",
|
|
443
|
+
Date2String = "date2string"
|
|
444
|
+
}
|
|
445
|
+
type TemplateValueBase = {
|
|
446
|
+
type: TemplateDefTypes;
|
|
447
|
+
returnType: ValueType;
|
|
448
|
+
expression?: Expression;
|
|
449
|
+
};
|
|
450
|
+
type TemplateValueFormatDate = TemplateValueBase & {
|
|
451
|
+
type: TemplateDefTypes.Date2String;
|
|
452
|
+
returnType: typeof ValueType.string;
|
|
453
|
+
dateFormat: string;
|
|
454
|
+
};
|
|
455
|
+
type TemplateValueDefinition = TemplateValueBase | TemplateValueFormatDate;
|
|
456
|
+
declare const serializeTemplateValue: (templateValue: TemplateValueDefinition) => JsonTemplateValue;
|
|
457
|
+
declare const serializeTemplateValues: (templateValues: Map<string, TemplateValueDefinition>) => {
|
|
458
|
+
[templateValueKey: string]: JsonTemplateValue;
|
|
459
|
+
};
|
|
460
|
+
declare const deserializeTemplateValue: (json: JsonTemplateValue) => TemplateValueDefinition;
|
|
461
|
+
declare const deserializeTemplateValues: (json: {
|
|
462
|
+
[templateValueKey: string]: JsonTemplateValue;
|
|
463
|
+
}) => Map<string, TemplateValueDefinition>;
|
|
464
|
+
interface JsonTemplateValue {
|
|
465
|
+
type: TemplateDefTypes;
|
|
466
|
+
expression?: JsonExpression;
|
|
467
|
+
returnType: ValueType;
|
|
468
|
+
dateFormat?: string;
|
|
349
469
|
}
|
|
350
470
|
//#endregion
|
|
351
471
|
//#region src/survey/utils/content.d.ts
|
|
352
472
|
declare enum ContentType {
|
|
353
|
-
|
|
473
|
+
richText = "richText",
|
|
474
|
+
plain = "plain",
|
|
354
475
|
md = "md"
|
|
355
476
|
}
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
start: number;
|
|
364
|
-
end: number;
|
|
477
|
+
type ContentAttributes = Record<string, unknown>;
|
|
478
|
+
type TextAlignment = 'left' | 'center' | 'right' | 'justify';
|
|
479
|
+
type RichTextStyle = {
|
|
480
|
+
weight?: 'strong' | 'normal';
|
|
481
|
+
italic?: 'italic' | 'normal';
|
|
482
|
+
underline?: 'underline' | 'none';
|
|
483
|
+
color?: 'primary' | 'accent' | 'default';
|
|
365
484
|
};
|
|
366
|
-
type
|
|
367
|
-
type:
|
|
368
|
-
|
|
369
|
-
|
|
485
|
+
type RichTextTextInline = {
|
|
486
|
+
type: 'text';
|
|
487
|
+
text: string;
|
|
488
|
+
style?: RichTextStyle;
|
|
489
|
+
attrs?: ContentAttributes;
|
|
370
490
|
};
|
|
371
|
-
type
|
|
372
|
-
type
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
491
|
+
type RichTextTemplateInline = {
|
|
492
|
+
type: 'template';
|
|
493
|
+
key: string;
|
|
494
|
+
style?: RichTextStyle;
|
|
495
|
+
attrs?: ContentAttributes;
|
|
496
|
+
};
|
|
497
|
+
type RichTextLineBreakInline = {
|
|
498
|
+
type: 'lineBreak';
|
|
499
|
+
attrs?: ContentAttributes;
|
|
500
|
+
};
|
|
501
|
+
/** Inline nodes allowed inside a {@link RichTextLinkInline} (no nested links). */
|
|
502
|
+
type RichTextLinkChildInline = RichTextTextInline | RichTextTemplateInline | RichTextLineBreakInline;
|
|
503
|
+
type RichTextLinkInline = {
|
|
504
|
+
type: 'link';
|
|
505
|
+
href: string;
|
|
506
|
+
target?: string | null;
|
|
507
|
+
rel?: string | null;
|
|
508
|
+
title?: string | null;
|
|
509
|
+
attrs?: ContentAttributes;
|
|
510
|
+
children: RichTextLinkChildInline[];
|
|
511
|
+
};
|
|
512
|
+
type RichTextInlineExtension = {
|
|
513
|
+
type: 'inlineExtension';
|
|
514
|
+
name: string;
|
|
515
|
+
attrs?: ContentAttributes;
|
|
516
|
+
};
|
|
517
|
+
type RichTextInlineNode = RichTextTextInline | RichTextTemplateInline | RichTextLinkInline | RichTextLineBreakInline | RichTextInlineExtension;
|
|
518
|
+
type RichTextParagraphBlock = {
|
|
519
|
+
type: 'paragraph';
|
|
520
|
+
children: RichTextInlineNode[];
|
|
521
|
+
alignment?: TextAlignment;
|
|
522
|
+
attrs?: ContentAttributes;
|
|
523
|
+
};
|
|
524
|
+
type RichTextHeadingBlock = {
|
|
525
|
+
type: 'heading';
|
|
526
|
+
level: 1 | 2 | 3 | 4 | 5 | 6;
|
|
527
|
+
children: RichTextInlineNode[];
|
|
528
|
+
alignment?: TextAlignment;
|
|
529
|
+
attrs?: ContentAttributes;
|
|
530
|
+
};
|
|
531
|
+
type RichTextListItemBlock = {
|
|
532
|
+
type: 'listItem';
|
|
533
|
+
children: RichTextParagraphBlock[];
|
|
534
|
+
attrs?: ContentAttributes;
|
|
535
|
+
};
|
|
536
|
+
type RichTextBulletListBlock = {
|
|
537
|
+
type: 'bulletList';
|
|
538
|
+
items: RichTextListItemBlock[];
|
|
539
|
+
attrs?: ContentAttributes;
|
|
540
|
+
};
|
|
541
|
+
type SurveyContentImageSource = {
|
|
542
|
+
type: 'external';
|
|
543
|
+
url: string;
|
|
544
|
+
} | {
|
|
545
|
+
type: 'asset';
|
|
546
|
+
assetId: string;
|
|
547
|
+
};
|
|
548
|
+
type RichTextImageDimension = {
|
|
549
|
+
unit: 'px';
|
|
550
|
+
value: number;
|
|
551
|
+
} | {
|
|
552
|
+
unit: '%';
|
|
553
|
+
value: number;
|
|
554
|
+
};
|
|
555
|
+
type RichTextImageSize = {
|
|
556
|
+
width?: RichTextImageDimension;
|
|
557
|
+
maxWidth?: RichTextImageDimension;
|
|
558
|
+
};
|
|
559
|
+
type RichTextImageBlock = {
|
|
560
|
+
type: 'image';
|
|
561
|
+
source: SurveyContentImageSource;
|
|
562
|
+
alt?: string;
|
|
563
|
+
caption?: RichTextParagraphBlock[];
|
|
564
|
+
size?: RichTextImageSize;
|
|
565
|
+
alignment?: TextAlignment;
|
|
566
|
+
attrs?: ContentAttributes;
|
|
567
|
+
};
|
|
568
|
+
type RichTextInfoBoxBlock = {
|
|
569
|
+
type: 'infoBox';
|
|
570
|
+
tone?: 'info' | 'warning';
|
|
571
|
+
title?: RichTextInlineNode[];
|
|
572
|
+
collapsible?: boolean;
|
|
573
|
+
defaultOpen?: boolean;
|
|
574
|
+
children: RichTextParagraphBlock[];
|
|
575
|
+
attrs?: ContentAttributes;
|
|
576
|
+
};
|
|
577
|
+
type RichTextSeparatorBlock = {
|
|
578
|
+
type: 'separator';
|
|
579
|
+
attrs?: ContentAttributes;
|
|
580
|
+
};
|
|
581
|
+
type RichTextBlockExtension = {
|
|
582
|
+
type: 'blockExtension';
|
|
583
|
+
name: string;
|
|
584
|
+
attrs?: ContentAttributes;
|
|
585
|
+
};
|
|
586
|
+
type RichTextBlockNode = RichTextParagraphBlock | RichTextHeadingBlock | RichTextBulletListBlock | RichTextImageBlock | RichTextInfoBoxBlock | RichTextSeparatorBlock | RichTextBlockExtension;
|
|
587
|
+
type RichTextDocument = {
|
|
588
|
+
type: 'doc';
|
|
589
|
+
blocks: RichTextBlockNode[];
|
|
590
|
+
};
|
|
591
|
+
type RichTextContent = {
|
|
592
|
+
type: ContentType.richText;
|
|
593
|
+
version: 1;
|
|
594
|
+
doc: RichTextDocument;
|
|
376
595
|
};
|
|
377
596
|
type MDContent = {
|
|
378
597
|
type: ContentType.md;
|
|
379
598
|
content: string;
|
|
380
599
|
};
|
|
381
|
-
type
|
|
600
|
+
type PlainTextContent = {
|
|
601
|
+
type: ContentType.plain;
|
|
602
|
+
content: string;
|
|
603
|
+
};
|
|
604
|
+
type Content = RichTextContent | MDContent | PlainTextContent;
|
|
605
|
+
type RichTextInline = RichTextInlineNode;
|
|
606
|
+
interface ContentAssetUsage {
|
|
607
|
+
assetId: string;
|
|
608
|
+
blockIndex: number;
|
|
609
|
+
}
|
|
610
|
+
declare function hasRenderableRichTextBlock(block: RichTextBlockNode): boolean;
|
|
611
|
+
declare function hasRenderableRichTextContent(content: RichTextContent): boolean;
|
|
612
|
+
declare function createRichTextContent(text?: string): RichTextContent;
|
|
613
|
+
declare function getPlainTextFromRichTextContent(content: RichTextContent): string;
|
|
614
|
+
declare function getContentPlainText(content?: Content): string;
|
|
615
|
+
declare function isContentEmpty(content?: Content): boolean;
|
|
616
|
+
declare function getAssetUsagesFromContent(content?: Content): ContentAssetUsage[];
|
|
382
617
|
//#endregion
|
|
383
618
|
//#region src/survey/utils/translations.d.ts
|
|
384
619
|
declare const validateLocale: (locale: string) => void;
|
|
@@ -390,6 +625,25 @@ declare class SurveyItemTranslations {
|
|
|
390
625
|
get locales(): string[];
|
|
391
626
|
getAllForLocale(locale: string): JsonComponentContent | undefined;
|
|
392
627
|
getContent(locale: string, contentKey: string, fallbackLocale?: string): Content | undefined;
|
|
628
|
+
/**
|
|
629
|
+
* Create a deep clone that can be safely mutated before persisting with
|
|
630
|
+
* `setItemTranslations` or `updateItemTranslations`.
|
|
631
|
+
*/
|
|
632
|
+
clone(): SurveyItemTranslations;
|
|
633
|
+
/**
|
|
634
|
+
* Remove a single content key from every locale in this translation set.
|
|
635
|
+
*/
|
|
636
|
+
removeContentKey(contentKey: string): void;
|
|
637
|
+
/**
|
|
638
|
+
* Remove every content key that is exactly the prefix or nested beneath it.
|
|
639
|
+
*/
|
|
640
|
+
removeContentKeysWithPrefix(prefix: string): void;
|
|
641
|
+
/**
|
|
642
|
+
* Remove empty locales in place.
|
|
643
|
+
* Returns `undefined` when no translations remain so callers can pass the
|
|
644
|
+
* result directly into `setItemTranslations` / `updateItemTranslations`.
|
|
645
|
+
*/
|
|
646
|
+
compact(): SurveyItemTranslations | undefined;
|
|
393
647
|
}
|
|
394
648
|
interface SurveyCardTranslations {
|
|
395
649
|
[locale: string]: SurveyCardContent;
|
|
@@ -417,6 +671,11 @@ declare class SurveyTranslations {
|
|
|
417
671
|
invalidResponse?: Content;
|
|
418
672
|
}): void;
|
|
419
673
|
getItemTranslations(itemId: string): SurveyItemTranslations | undefined;
|
|
674
|
+
/**
|
|
675
|
+
* Persist item translations after normalizing them:
|
|
676
|
+
* empty keys/locales are removed automatically, and an empty translation set
|
|
677
|
+
* clears the item's stored translations entirely.
|
|
678
|
+
*/
|
|
420
679
|
setItemTranslations(itemId: string, itemContent?: SurveyItemTranslations): void;
|
|
421
680
|
/**
|
|
422
681
|
* Rename a component key (within an item) - update key in all translations and remove old key
|
|
@@ -452,6 +711,7 @@ interface NavigationContent {
|
|
|
452
711
|
previousButtonText?: Content;
|
|
453
712
|
nextButtonText?: Content;
|
|
454
713
|
submitButtonText?: Content;
|
|
714
|
+
pageIndicatorText?: Content;
|
|
455
715
|
submitBoxMessage?: Content;
|
|
456
716
|
}
|
|
457
717
|
interface JsonSurveyTranslations {
|
|
@@ -468,6 +728,31 @@ interface JsonSurveyTranslations {
|
|
|
468
728
|
}
|
|
469
729
|
//#endregion
|
|
470
730
|
//#region src/survey/survey-file-schema.d.ts
|
|
731
|
+
declare const CURRENT_SURVEY_SCHEMA = "https://github.com/case-framework/case-survey-toolkit/packages/survey-core/schemas/survey-schema.json";
|
|
732
|
+
interface SurveyVersion {
|
|
733
|
+
id?: string;
|
|
734
|
+
surveyKey: string;
|
|
735
|
+
published?: number;
|
|
736
|
+
unpublished?: number;
|
|
737
|
+
versionId?: string;
|
|
738
|
+
survey: RawSurvey;
|
|
739
|
+
}
|
|
740
|
+
type RawSurveyAsset = {
|
|
741
|
+
kind: 'image';
|
|
742
|
+
source: {
|
|
743
|
+
type: 'embedded';
|
|
744
|
+
mediaType: string;
|
|
745
|
+
encoding: 'base64';
|
|
746
|
+
data: string;
|
|
747
|
+
};
|
|
748
|
+
metadata?: {
|
|
749
|
+
name?: string;
|
|
750
|
+
filename?: string;
|
|
751
|
+
alt?: string;
|
|
752
|
+
width?: number;
|
|
753
|
+
height?: number;
|
|
754
|
+
};
|
|
755
|
+
};
|
|
471
756
|
type RawSurvey = {
|
|
472
757
|
$schema: string;
|
|
473
758
|
maxItemsPerPage?: {
|
|
@@ -475,6 +760,7 @@ type RawSurvey = {
|
|
|
475
760
|
small: number;
|
|
476
761
|
};
|
|
477
762
|
surveyItems: Array<RawSurveyItem>;
|
|
763
|
+
assets?: Record<string, RawSurveyAsset>;
|
|
478
764
|
metadata?: {
|
|
479
765
|
[key: string]: string;
|
|
480
766
|
};
|
|
@@ -523,6 +809,7 @@ interface ItemTypeDefinition {
|
|
|
523
809
|
itemType: ItemTypeName;
|
|
524
810
|
constructor: ItemCoreConstructor;
|
|
525
811
|
capabilities?: ItemTypeCapabilities;
|
|
812
|
+
expressions?: AnyItemExpressionDefinition[];
|
|
526
813
|
}
|
|
527
814
|
/** Registry mapping item type name → definition. */
|
|
528
815
|
type ItemTypeDefinitionRegistry = Record<ItemTypeName, ItemTypeDefinition>;
|
|
@@ -554,7 +841,7 @@ declare class GroupItemCore extends SurveyItemCore<typeof ReservedSurveyItemType
|
|
|
554
841
|
parseConfig(rawConfig: unknown): GroupConfig;
|
|
555
842
|
serializeConfig(): unknown;
|
|
556
843
|
isInteractive(): boolean;
|
|
557
|
-
|
|
844
|
+
getResponseSlotDefinitions(): never[];
|
|
558
845
|
isRoot(): boolean;
|
|
559
846
|
get items(): string[];
|
|
560
847
|
/**
|
|
@@ -604,7 +891,7 @@ declare class PageBreakItemCore extends SurveyItemCore<typeof ReservedSurveyItem
|
|
|
604
891
|
parseConfig(_rawConfig: unknown): PageBreakConfig;
|
|
605
892
|
serializeConfig(): unknown;
|
|
606
893
|
isInteractive(): boolean;
|
|
607
|
-
|
|
894
|
+
getResponseSlotDefinitions(): never[];
|
|
608
895
|
}
|
|
609
896
|
/**
|
|
610
897
|
* Built-in item type.
|
|
@@ -614,6 +901,14 @@ declare const builtInItemCoreRegistry: Record<BuiltInItemType, ItemCoreConstruct
|
|
|
614
901
|
declare const isBuiltInItemType: (itemType: string) => itemType is BuiltInItemType;
|
|
615
902
|
//#endregion
|
|
616
903
|
//#region src/survey/survey.d.ts
|
|
904
|
+
interface SurveyAssetUsage {
|
|
905
|
+
assetId: string;
|
|
906
|
+
itemId?: string;
|
|
907
|
+
locale?: string;
|
|
908
|
+
contentKey: string;
|
|
909
|
+
usageScope: 'itemTranslation' | 'surveyCard' | 'navigation' | 'validationMessages';
|
|
910
|
+
blockIndex: number;
|
|
911
|
+
}
|
|
617
912
|
declare class Survey {
|
|
618
913
|
private readonly pluginRegistry?;
|
|
619
914
|
maxItemsPerPage?: {
|
|
@@ -625,6 +920,7 @@ declare class Survey {
|
|
|
625
920
|
};
|
|
626
921
|
surveyItems: Map<string, SurveyItemCore>;
|
|
627
922
|
private _templateValues?;
|
|
923
|
+
private _assets?;
|
|
628
924
|
private _translations?;
|
|
629
925
|
constructor(pluginRegistry?: ItemTypeRegistry | undefined);
|
|
630
926
|
/** Plugin registry used when parsing items. Exposed for editors that re-parse without their own registry. */
|
|
@@ -660,7 +956,18 @@ declare class Survey {
|
|
|
660
956
|
setTemplateValue(templateValueKey: string, templateValue: TemplateValueDefinition): void;
|
|
661
957
|
deleteTemplateValue(templateValueKey: string): void;
|
|
662
958
|
getTemplateValueKeys(): string[];
|
|
959
|
+
getAsset(assetId: string): RawSurveyAsset | undefined;
|
|
960
|
+
setAsset(assetId: string, asset: RawSurveyAsset): void;
|
|
961
|
+
deleteAsset(assetId: string): void;
|
|
962
|
+
hasAsset(assetId: string): boolean;
|
|
963
|
+
getAssetIds(): string[];
|
|
964
|
+
getAssets(): Map<string, RawSurveyAsset>;
|
|
965
|
+
getAssetUsages(filterAssetId?: string): SurveyAssetUsage[];
|
|
663
966
|
getAvailableResponseValueSlots(byType?: ValueType): ValueRefTypeLookup;
|
|
967
|
+
getResponseSlotDefinitions(): Array<{
|
|
968
|
+
itemId: string;
|
|
969
|
+
slots: ResponseSlotDefinition[];
|
|
970
|
+
}>;
|
|
664
971
|
/**
|
|
665
972
|
* Get all reference usages for the survey
|
|
666
973
|
* @param forItemId - optional item id to filter usages for a specific item and its children (if not provided, all usages are returned)
|
|
@@ -670,5 +977,5 @@ declare class Survey {
|
|
|
670
977
|
isDescendantOf(targetId: string, ancestorId: string): boolean;
|
|
671
978
|
}
|
|
672
979
|
//#endregion
|
|
673
|
-
export {
|
|
674
|
-
//# sourceMappingURL=survey-
|
|
980
|
+
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 };
|
|
981
|
+
//# sourceMappingURL=survey-DShEOjyz.d.mts.map
|