case-editor-tools 1.0.0-beta.7 → 1.0.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/constants/key-definitions.d.ts +16 -0
- package/constants/key-definitions.js +38 -0
- package/constants/key-definitions.js.map +1 -0
- package/exporter/index.d.ts +2 -0
- package/exporter/index.js +128 -0
- package/exporter/index.js.map +1 -0
- package/expression-utils/expressionGen.d.ts +2 -0
- package/expression-utils/expressionGen.js +31 -0
- package/expression-utils/expressionGen.js.map +1 -0
- package/expression-utils/studyEngineExpressions.d.ts +195 -0
- package/expression-utils/studyEngineExpressions.js +479 -0
- package/expression-utils/studyEngineExpressions.js.map +1 -0
- package/index.d.ts +0 -0
- package/index.js +3 -0
- package/index.js.map +1 -0
- package/item-editor-59f51ecc.js +542 -0
- package/item-editor-59f51ecc.js.map +1 -0
- package/logger/index.d.ts +1 -0
- package/logger/index.js +10 -0
- package/logger/index.js.map +1 -0
- package/logger/logger.d.ts +9 -0
- package/logger/logger.js +31 -0
- package/logger/logger.js.map +1 -0
- package/package.json +5 -5
- package/surveys/index.d.ts +3 -0
- package/surveys/index.js +29 -0
- package/surveys/index.js.map +1 -0
- package/surveys/responseTypeGenerators/likertGroupComponents.d.ts +27 -0
- package/surveys/responseTypeGenerators/likertGroupComponents.js +350 -0
- package/surveys/responseTypeGenerators/likertGroupComponents.js.map +1 -0
- package/surveys/responseTypeGenerators/matrixGroupComponent.d.ts +49 -0
- package/surveys/responseTypeGenerators/matrixGroupComponent.js +100 -0
- package/surveys/responseTypeGenerators/matrixGroupComponent.js.map +1 -0
- package/surveys/responseTypeGenerators/optionGroupComponents.d.ts +7 -0
- package/surveys/responseTypeGenerators/optionGroupComponents.js +129 -0
- package/surveys/responseTypeGenerators/optionGroupComponents.js.map +1 -0
- package/surveys/survey-editor/component-editor.d.ts +84 -0
- package/surveys/survey-editor/component-editor.js +112 -0
- package/surveys/survey-editor/component-editor.js.map +1 -0
- package/surveys/survey-editor/data-types.d.ts +13 -0
- package/surveys/survey-editor/data-types.js +3 -0
- package/surveys/survey-editor/data-types.js.map +1 -0
- package/surveys/survey-editor/item-editor.d.ts +66 -0
- package/surveys/survey-editor/item-editor.js +13 -0
- package/surveys/survey-editor/item-editor.js.map +1 -0
- package/surveys/survey-editor/survey-editor.d.ts +48 -0
- package/surveys/survey-editor/survey-editor.js +237 -0
- package/surveys/survey-editor/survey-editor.js.map +1 -0
- package/surveys/survey-engine-expressions.d.ts +130 -0
- package/surveys/survey-engine-expressions.js +448 -0
- package/surveys/survey-engine-expressions.js.map +1 -0
- package/surveys/survey-items.d.ts +72 -0
- package/surveys/survey-items.js +384 -0
- package/surveys/survey-items.js.map +1 -0
- package/surveys/types/group.d.ts +23 -0
- package/surveys/types/group.js +72 -0
- package/surveys/types/group.js.map +1 -0
- package/surveys/types/index.d.ts +4 -0
- package/surveys/types/index.js +22 -0
- package/surveys/types/index.js.map +1 -0
- package/surveys/types/item-properties.d.ts +223 -0
- package/surveys/types/item-properties.js +10 -0
- package/surveys/types/item-properties.js.map +1 -0
- package/surveys/types/item.d.ts +22 -0
- package/surveys/types/item.js +34 -0
- package/surveys/types/item.js.map +1 -0
- package/surveys/types/survey-definition.d.ts +23 -0
- package/surveys/types/survey-definition.js +69 -0
- package/surveys/types/survey-definition.js.map +1 -0
- package/surveys/utils/componentGenerators.d.ts +24 -0
- package/surveys/utils/componentGenerators.js +59 -0
- package/surveys/utils/componentGenerators.js.map +1 -0
- package/surveys/utils/optionDefGenerators.d.ts +84 -0
- package/surveys/utils/optionDefGenerators.js +211 -0
- package/surveys/utils/optionDefGenerators.js.map +1 -0
- package/surveys/utils/randomKeyGenerator.d.ts +1 -0
- package/surveys/utils/randomKeyGenerator.js +16 -0
- package/surveys/utils/randomKeyGenerator.js.map +1 -0
- package/surveys/utils/simple-generators.d.ts +14 -0
- package/surveys/utils/simple-generators.js +131 -0
- package/surveys/utils/simple-generators.js.map +1 -0
- package/surveys/utils/simple-question-editor.d.ts +14 -0
- package/surveys/utils/simple-question-editor.js +47 -0
- package/surveys/utils/simple-question-editor.js.map +1 -0
- package/types/duration.d.ts +9 -0
- package/types/duration.js +29 -0
- package/types/duration.js.map +1 -0
- package/types/expression.d.ts +4 -0
- package/types/expression.js +23 -0
- package/types/expression.js.map +1 -0
- package/types/messageConfig.d.ts +49 -0
- package/types/messageConfig.js +23 -0
- package/types/messageConfig.js.map +1 -0
- package/types/study.d.ts +15 -0
- package/types/study.js +3 -0
- package/types/study.js.map +1 -0
- package/types/studyRules.d.ts +9 -0
- package/types/studyRules.js +36 -0
- package/types/studyRules.js.map +1 -0
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import { ItemComponent, Expression, LocalizedObject, ComponentProperties } from "survey-engine/data_types";
|
|
2
|
+
import { NewComponentProps } from "./data-types";
|
|
3
|
+
interface ComponentEditorInt {
|
|
4
|
+
getComponent: () => ItemComponent;
|
|
5
|
+
getComponentJSON: (pretty?: boolean) => string;
|
|
6
|
+
setKey: (key: string | undefined) => void;
|
|
7
|
+
setRole: (role: string) => void;
|
|
8
|
+
setDisplayCondition: (expression: Expression | undefined) => void;
|
|
9
|
+
setDisabled: (expression: Expression | undefined) => void;
|
|
10
|
+
setContent: (translations: LocalizedObject[] | undefined) => void;
|
|
11
|
+
setDescription: (translations: LocalizedObject[] | undefined) => void;
|
|
12
|
+
setStyles: (styles: Array<{
|
|
13
|
+
key: string;
|
|
14
|
+
value: string;
|
|
15
|
+
}> | undefined) => void;
|
|
16
|
+
setDType: (dtype: 'string' | 'number' | 'date') => void;
|
|
17
|
+
setProperties: (props: ComponentProperties | undefined) => void;
|
|
18
|
+
setOrder: (orderExp: Expression | undefined) => void;
|
|
19
|
+
addItemComponent: (item: ItemComponent, atPosition?: number) => void;
|
|
20
|
+
updateItemComponent: (selector: string | number, updatedItem: ItemComponent) => void;
|
|
21
|
+
removeItem: (index: number) => void;
|
|
22
|
+
}
|
|
23
|
+
export declare class ComponentEditor implements ComponentEditorInt {
|
|
24
|
+
component: ItemComponent;
|
|
25
|
+
constructor(existingComponent?: ItemComponent, newComponent?: NewComponentProps);
|
|
26
|
+
getComponent(): {
|
|
27
|
+
role: string;
|
|
28
|
+
key?: string | undefined;
|
|
29
|
+
content?: LocalizedObject[] | undefined;
|
|
30
|
+
displayCondition?: boolean | Expression | undefined;
|
|
31
|
+
disabled?: boolean | Expression | undefined;
|
|
32
|
+
style?: {
|
|
33
|
+
key: string;
|
|
34
|
+
value: string;
|
|
35
|
+
}[] | undefined;
|
|
36
|
+
description?: LocalizedObject[] | undefined;
|
|
37
|
+
properties?: ComponentProperties | undefined;
|
|
38
|
+
} | {
|
|
39
|
+
items: ItemComponent[];
|
|
40
|
+
order?: Expression | undefined;
|
|
41
|
+
role: string;
|
|
42
|
+
key?: string | undefined;
|
|
43
|
+
content?: LocalizedObject[] | undefined;
|
|
44
|
+
displayCondition?: boolean | Expression | undefined;
|
|
45
|
+
disabled?: boolean | Expression | undefined;
|
|
46
|
+
style?: {
|
|
47
|
+
key: string;
|
|
48
|
+
value: string;
|
|
49
|
+
}[] | undefined;
|
|
50
|
+
description?: LocalizedObject[] | undefined;
|
|
51
|
+
properties?: ComponentProperties | undefined;
|
|
52
|
+
} | {
|
|
53
|
+
key: string;
|
|
54
|
+
dtype?: string | undefined;
|
|
55
|
+
role: string;
|
|
56
|
+
content?: LocalizedObject[] | undefined;
|
|
57
|
+
displayCondition?: boolean | Expression | undefined;
|
|
58
|
+
disabled?: boolean | Expression | undefined;
|
|
59
|
+
style?: {
|
|
60
|
+
key: string;
|
|
61
|
+
value: string;
|
|
62
|
+
}[] | undefined;
|
|
63
|
+
description?: LocalizedObject[] | undefined;
|
|
64
|
+
properties?: ComponentProperties | undefined;
|
|
65
|
+
};
|
|
66
|
+
getComponentJSON(pretty?: boolean): string;
|
|
67
|
+
setKey(key: string | undefined): void;
|
|
68
|
+
setRole(role: string): void;
|
|
69
|
+
setDisplayCondition(expression: Expression | undefined): void;
|
|
70
|
+
setDisabled(expression: Expression | undefined): void;
|
|
71
|
+
setContent(translations: LocalizedObject[] | undefined): void;
|
|
72
|
+
setDescription(translations: LocalizedObject[] | undefined): void;
|
|
73
|
+
setStyles(styles: Array<{
|
|
74
|
+
key: string;
|
|
75
|
+
value: string;
|
|
76
|
+
}> | undefined): void;
|
|
77
|
+
setDType(dtype: 'string' | 'number' | 'date'): void;
|
|
78
|
+
setProperties(props: ComponentProperties | undefined): void;
|
|
79
|
+
setOrder(orderExp: Expression | undefined): void;
|
|
80
|
+
addItemComponent(item: ItemComponent, atPosition?: number): void;
|
|
81
|
+
updateItemComponent(selector: string | number, updatedItem: ItemComponent): void;
|
|
82
|
+
removeItem(index: number): void;
|
|
83
|
+
}
|
|
84
|
+
export {};
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
class ComponentEditor {
|
|
6
|
+
constructor(existingComponent, newComponent) {
|
|
7
|
+
if (existingComponent) {
|
|
8
|
+
this.component = Object.assign({}, existingComponent);
|
|
9
|
+
}
|
|
10
|
+
else if (newComponent) {
|
|
11
|
+
this.component = {
|
|
12
|
+
key: newComponent.key ? newComponent.key : undefined,
|
|
13
|
+
role: newComponent.role ? newComponent === null || newComponent === void 0 ? void 0 : newComponent.role : 'none',
|
|
14
|
+
};
|
|
15
|
+
if (newComponent.isGroup) {
|
|
16
|
+
this.component.items = [];
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
this.component = { role: 'undefined' };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
getComponent() {
|
|
24
|
+
return Object.assign({}, this.component);
|
|
25
|
+
}
|
|
26
|
+
;
|
|
27
|
+
getComponentJSON(pretty) {
|
|
28
|
+
return JSON.stringify(this.component, undefined, pretty ? ' ' : undefined);
|
|
29
|
+
}
|
|
30
|
+
;
|
|
31
|
+
setKey(key) {
|
|
32
|
+
this.component.key = key;
|
|
33
|
+
}
|
|
34
|
+
;
|
|
35
|
+
setRole(role) {
|
|
36
|
+
this.component.role = role;
|
|
37
|
+
}
|
|
38
|
+
;
|
|
39
|
+
setDisplayCondition(expression) {
|
|
40
|
+
this.component.displayCondition = expression;
|
|
41
|
+
}
|
|
42
|
+
;
|
|
43
|
+
setDisabled(expression) {
|
|
44
|
+
this.component.disabled = expression;
|
|
45
|
+
}
|
|
46
|
+
;
|
|
47
|
+
setContent(translations) {
|
|
48
|
+
this.component.content = translations ? [...translations] : undefined;
|
|
49
|
+
}
|
|
50
|
+
;
|
|
51
|
+
setDescription(translations) {
|
|
52
|
+
this.component.description = translations ? [...translations] : undefined;
|
|
53
|
+
}
|
|
54
|
+
;
|
|
55
|
+
setStyles(styles) {
|
|
56
|
+
this.component.style = styles ? [...styles] : undefined;
|
|
57
|
+
}
|
|
58
|
+
;
|
|
59
|
+
// response components:
|
|
60
|
+
setDType(dtype) {
|
|
61
|
+
this.component.dtype = dtype;
|
|
62
|
+
}
|
|
63
|
+
;
|
|
64
|
+
setProperties(props) {
|
|
65
|
+
this.component.properties = Object.assign({}, props);
|
|
66
|
+
}
|
|
67
|
+
;
|
|
68
|
+
// item group component:
|
|
69
|
+
setOrder(orderExp) {
|
|
70
|
+
this.component.order = orderExp;
|
|
71
|
+
}
|
|
72
|
+
;
|
|
73
|
+
addItemComponent(item, atPosition) {
|
|
74
|
+
if (!this.component.items) {
|
|
75
|
+
this.component.items = [];
|
|
76
|
+
}
|
|
77
|
+
if (atPosition !== undefined) {
|
|
78
|
+
this.component.items.splice(atPosition, 0, Object.assign({}, item));
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.component.items.push(Object.assign({}, item));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
;
|
|
85
|
+
updateItemComponent(selector, updatedItem) {
|
|
86
|
+
if (!this.component.items) {
|
|
87
|
+
console.warn('items array missing on the component');
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
if (typeof (selector) === 'string') {
|
|
91
|
+
// find by key:
|
|
92
|
+
const ind = this.component.items.findIndex(c => c.key === selector);
|
|
93
|
+
if (ind < 0) {
|
|
94
|
+
console.warn('could not find component with given key: ', selector);
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
this.component.items[ind] = Object.assign({}, updatedItem);
|
|
98
|
+
}
|
|
99
|
+
else if (typeof (selector) === 'number') {
|
|
100
|
+
// find by index:
|
|
101
|
+
this.component.items[selector] = Object.assign({}, updatedItem);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
;
|
|
105
|
+
removeItem(index) {
|
|
106
|
+
this.component.items.splice(index, 1);
|
|
107
|
+
}
|
|
108
|
+
;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
exports.ComponentEditor = ComponentEditor;
|
|
112
|
+
//# sourceMappingURL=component-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"component-editor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { SurveyItemTypes } from "survey-engine/data_types";
|
|
2
|
+
export interface NewItemProps {
|
|
3
|
+
itemKey?: string;
|
|
4
|
+
isGroup?: boolean;
|
|
5
|
+
type?: SurveyItemTypes;
|
|
6
|
+
}
|
|
7
|
+
export interface NewComponentProps {
|
|
8
|
+
key?: string;
|
|
9
|
+
isGroup?: boolean;
|
|
10
|
+
role?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface SurveyProperties {
|
|
13
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"data-types.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;"}
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { SurveyItem, SurveyItemTypes, Expression, Validation, ItemComponent, ItemGroupComponent, ConfidentialMode } from "survey-engine/data_types";
|
|
2
|
+
import { NewItemProps, NewComponentProps } from "./data-types";
|
|
3
|
+
interface ItemEditorInt {
|
|
4
|
+
getItem: () => SurveyItem;
|
|
5
|
+
getItemJSON: (pretty?: boolean) => string;
|
|
6
|
+
setKey: (newKey: string) => void;
|
|
7
|
+
addToFollows: (key: string) => void;
|
|
8
|
+
removeFromFollows: (key: string) => void;
|
|
9
|
+
clearFollows: () => void;
|
|
10
|
+
setCondition: (exp: Expression | undefined) => void;
|
|
11
|
+
setPriority: (prio: number | undefined) => void;
|
|
12
|
+
setVersion: (version: number) => void;
|
|
13
|
+
setVersionTags: (tags: string[]) => void;
|
|
14
|
+
addSurveyItem: (item: SurveyItem, atPosition?: number) => void;
|
|
15
|
+
updateSurveyItem: (item: SurveyItem) => void;
|
|
16
|
+
removeItem: (key: string) => void;
|
|
17
|
+
changeItemPosition: (key: string, newPosition: number) => void;
|
|
18
|
+
setSelectionMethod: (exp: Expression | undefined) => void;
|
|
19
|
+
setItemType: (type: SurveyItemTypes) => void;
|
|
20
|
+
setTitleComponent: (title: ItemComponent) => void;
|
|
21
|
+
setHelpGroupComponent: (helpGroup: ItemGroupComponent) => void;
|
|
22
|
+
addDisplayComponent: (comp: ItemComponent, atPosition?: number) => void;
|
|
23
|
+
updateDisplayComponent: (at: number, comp: ItemComponent) => void;
|
|
24
|
+
removeDisplayComponent: (at: number) => void;
|
|
25
|
+
addNewResponseComponent: (props: NewComponentProps, parentKey?: string, atPosition?: number) => ItemComponent | undefined;
|
|
26
|
+
addExistingResponseComponent: (newComp: ItemComponent, parentKey?: string, atPosition?: number) => ItemComponent | undefined;
|
|
27
|
+
updateResponseComponent: (path: string, item: ItemComponent) => void;
|
|
28
|
+
removeResponseComponent: (key: string) => void;
|
|
29
|
+
findResponseComponent: (key: string) => ItemComponent | undefined;
|
|
30
|
+
addValidation: (v: Validation) => void;
|
|
31
|
+
removeValidation: (vKey: string) => void;
|
|
32
|
+
}
|
|
33
|
+
export declare class ItemEditor implements ItemEditorInt {
|
|
34
|
+
private surveyItem;
|
|
35
|
+
constructor(existingItem?: SurveyItem, newItem?: NewItemProps);
|
|
36
|
+
getItem(): SurveyItem;
|
|
37
|
+
getItemJSON(pretty?: boolean): string;
|
|
38
|
+
setKey(newKey: string): void;
|
|
39
|
+
setConfidentialMode(confidentialMode?: ConfidentialMode): void;
|
|
40
|
+
addToFollows(key: string): void;
|
|
41
|
+
removeFromFollows(key: string): void;
|
|
42
|
+
clearFollows(): void;
|
|
43
|
+
setCondition(exp: Expression | undefined): void;
|
|
44
|
+
setPriority(prio: number | undefined): void;
|
|
45
|
+
setVersion(version: number): void;
|
|
46
|
+
setVersionTags(tags: string[]): void;
|
|
47
|
+
addSurveyItem(item: SurveyItem, atPosition?: number): void;
|
|
48
|
+
updateSurveyItem(item: SurveyItem): void;
|
|
49
|
+
removeItem(key: string): void;
|
|
50
|
+
changeItemPosition(key: string, newPosition: number): void;
|
|
51
|
+
setSelectionMethod(exp: Expression | undefined): void;
|
|
52
|
+
setItemType(type: SurveyItemTypes): void;
|
|
53
|
+
setTitleComponent(title: ItemComponent): void;
|
|
54
|
+
setHelpGroupComponent(helpGroup: ItemGroupComponent): void;
|
|
55
|
+
addDisplayComponent(comp: ItemComponent, atPosition?: number): void;
|
|
56
|
+
updateDisplayComponent(at: number, comp: ItemComponent): void;
|
|
57
|
+
removeDisplayComponent(at: number): void;
|
|
58
|
+
addNewResponseComponent(props: NewComponentProps, parentKey?: string, atPosition?: number): ItemComponent | undefined;
|
|
59
|
+
addExistingResponseComponent(newComp: ItemComponent, parentKey?: string, atPosition?: number): ItemComponent | undefined;
|
|
60
|
+
updateResponseComponent(path: string, item: ItemComponent): void;
|
|
61
|
+
removeResponseComponent(keyPath: string): void;
|
|
62
|
+
findResponseComponent(key: string): ItemComponent | undefined;
|
|
63
|
+
addValidation(v: Validation): void;
|
|
64
|
+
removeValidation(vKey: string): void;
|
|
65
|
+
}
|
|
66
|
+
export {};
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var surveys_surveyEditor_itemEditor = require('../../item-editor-59f51ecc.js');
|
|
6
|
+
require('./component-editor.js');
|
|
7
|
+
require('../utils/randomKeyGenerator.js');
|
|
8
|
+
require('../../logger/logger.js');
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
exports.ItemEditor = surveys_surveyEditor_itemEditor.ItemEditor;
|
|
13
|
+
//# sourceMappingURL=item-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"item-editor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;"}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { Survey, LocalizedString, SurveyItem, SurveyContextDef, Expression } from "survey-engine/data_types";
|
|
2
|
+
import { SurveyAvailableFor } from "../types";
|
|
3
|
+
import { NewItemProps } from "./data-types";
|
|
4
|
+
interface SurveyEditorInt {
|
|
5
|
+
setSurveyName: (name: Array<LocalizedString>) => void;
|
|
6
|
+
setSurveyDescription: (description: Array<LocalizedString>) => void;
|
|
7
|
+
setSurveyDuration: (duration: Array<LocalizedString>) => void;
|
|
8
|
+
setSurveyContextRules: (contextRules: SurveyContextDef) => void;
|
|
9
|
+
setPrefillRules: (rules: Expression[]) => void;
|
|
10
|
+
setAvailableFor: (value?: SurveyAvailableFor) => void;
|
|
11
|
+
setRequireLoginBeforeSubmission: (value?: boolean) => void;
|
|
12
|
+
changeItemKey: (oldKey: string, newKey: string) => void;
|
|
13
|
+
addNewSurveyItem: (itemProps: NewItemProps, parentKey?: string, atPosition?: number) => SurveyItem | undefined;
|
|
14
|
+
updateSurveyItem: (item: SurveyItem) => void;
|
|
15
|
+
removeItem: (key: string) => void;
|
|
16
|
+
findSurveyItem: (itemKey: string) => SurveyItem | undefined;
|
|
17
|
+
moveSurveyItem: (item: SurveyItem, destination: string) => void;
|
|
18
|
+
getSurvey: () => Survey;
|
|
19
|
+
getSurveyJSON: (pretty?: boolean) => string;
|
|
20
|
+
}
|
|
21
|
+
export declare class SurveyEditor implements SurveyEditorInt {
|
|
22
|
+
private survey;
|
|
23
|
+
private surveyKey;
|
|
24
|
+
constructor(survey?: Survey);
|
|
25
|
+
setSurveyName(name: Array<LocalizedString>): void;
|
|
26
|
+
setSurveyDescription(description: Array<LocalizedString>): void;
|
|
27
|
+
setSurveyDuration(duration: Array<LocalizedString>): void;
|
|
28
|
+
setMaxItemPerPage(itemLimits: {
|
|
29
|
+
small: number;
|
|
30
|
+
large: number;
|
|
31
|
+
}): void;
|
|
32
|
+
setAvailableFor(value?: SurveyAvailableFor | undefined): void;
|
|
33
|
+
setRequireLoginBeforeSubmission(value?: boolean | undefined): void;
|
|
34
|
+
setSurveyContextRules(contextRules: SurveyContextDef): void;
|
|
35
|
+
setPrefillRules(rules: Expression[]): void;
|
|
36
|
+
addNewSurveyItem(newItem: NewItemProps, parentKey?: string, atPosition?: number): SurveyItem | undefined;
|
|
37
|
+
addExistingSurveyItem(surveyItem: SurveyItem, parentKey: string, atPosition?: number): SurveyItem | undefined;
|
|
38
|
+
changeItemKey(oldKey: string, newKey: string, ignoreReferences?: boolean): void;
|
|
39
|
+
updateSurveyItem(item: SurveyItem): void;
|
|
40
|
+
removeItem(key: string): void;
|
|
41
|
+
moveSurveyItem(item: SurveyItem, destination: string): void;
|
|
42
|
+
findSurveyItem(itemKey: string): SurveyItem | undefined;
|
|
43
|
+
getSurvey(): Survey;
|
|
44
|
+
getSurveyJSON(pretty?: boolean): string;
|
|
45
|
+
private getKeyListForPath;
|
|
46
|
+
private changeItemKeyForSubtree;
|
|
47
|
+
}
|
|
48
|
+
export {};
|
|
@@ -0,0 +1,237 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var surveys_surveyEditor_itemEditor = require('../../item-editor-59f51ecc.js');
|
|
6
|
+
var logger_logger = require('../../logger/logger.js');
|
|
7
|
+
require('./component-editor.js');
|
|
8
|
+
require('../utils/randomKeyGenerator.js');
|
|
9
|
+
|
|
10
|
+
class SurveyEditor {
|
|
11
|
+
constructor(survey) {
|
|
12
|
+
if (survey) {
|
|
13
|
+
this.survey = Object.assign({}, survey);
|
|
14
|
+
this.surveyKey = this.survey.current.surveyDefinition.key;
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
this.surveyKey = 'survey';
|
|
18
|
+
this.survey = {
|
|
19
|
+
props: {},
|
|
20
|
+
current: {
|
|
21
|
+
versionId: '',
|
|
22
|
+
surveyDefinition: {
|
|
23
|
+
key: this.surveyKey,
|
|
24
|
+
version: 1,
|
|
25
|
+
items: []
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
setSurveyName(name) {
|
|
32
|
+
if (!this.survey.props) {
|
|
33
|
+
this.survey.props = {};
|
|
34
|
+
}
|
|
35
|
+
this.survey.props.name = name;
|
|
36
|
+
}
|
|
37
|
+
;
|
|
38
|
+
setSurveyDescription(description) {
|
|
39
|
+
if (!this.survey.props) {
|
|
40
|
+
this.survey.props = {};
|
|
41
|
+
}
|
|
42
|
+
this.survey.props.description = description;
|
|
43
|
+
}
|
|
44
|
+
;
|
|
45
|
+
setSurveyDuration(duration) {
|
|
46
|
+
if (!this.survey.props) {
|
|
47
|
+
this.survey.props = {};
|
|
48
|
+
}
|
|
49
|
+
this.survey.props.typicalDuration = duration;
|
|
50
|
+
}
|
|
51
|
+
;
|
|
52
|
+
setMaxItemPerPage(itemLimits) {
|
|
53
|
+
this.survey.maxItemsPerPage = itemLimits;
|
|
54
|
+
}
|
|
55
|
+
setAvailableFor(value) {
|
|
56
|
+
this.survey.availableFor = value;
|
|
57
|
+
}
|
|
58
|
+
setRequireLoginBeforeSubmission(value) {
|
|
59
|
+
this.survey.requireLoginBeforeSubmission = value;
|
|
60
|
+
}
|
|
61
|
+
setSurveyContextRules(contextRules) {
|
|
62
|
+
this.survey.contextRules = Object.assign({}, contextRules);
|
|
63
|
+
}
|
|
64
|
+
;
|
|
65
|
+
setPrefillRules(rules) {
|
|
66
|
+
this.survey.prefillRules = [...rules];
|
|
67
|
+
}
|
|
68
|
+
;
|
|
69
|
+
addNewSurveyItem(newItem, parentKey, atPosition) {
|
|
70
|
+
if (!parentKey) {
|
|
71
|
+
newItem.itemKey = this.surveyKey + '.' + newItem.itemKey;
|
|
72
|
+
if (this.survey.current.surveyDefinition.items.find(it => newItem.itemKey === it.key)) {
|
|
73
|
+
logger_logger.Logger.criticalError('Duplicate key in survey: ' + newItem.itemKey);
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
const item = (new surveys_surveyEditor_itemEditor.ItemEditor(undefined, newItem)).getItem();
|
|
77
|
+
if (atPosition !== undefined) {
|
|
78
|
+
this.survey.current.surveyDefinition.items.splice(atPosition, 0, item);
|
|
79
|
+
}
|
|
80
|
+
else {
|
|
81
|
+
this.survey.current.surveyDefinition.items.push(item);
|
|
82
|
+
}
|
|
83
|
+
return item;
|
|
84
|
+
}
|
|
85
|
+
const obj = this.findSurveyItem(parentKey);
|
|
86
|
+
if (!obj) {
|
|
87
|
+
console.warn('parent survey item cannot be found: ', parentKey);
|
|
88
|
+
return;
|
|
89
|
+
}
|
|
90
|
+
newItem.itemKey = parentKey + '.' + newItem.itemKey;
|
|
91
|
+
if (obj.items.find(it => newItem.itemKey === it.key)) {
|
|
92
|
+
logger_logger.Logger.criticalError('Duplicate key in survey: ' + newItem.itemKey);
|
|
93
|
+
return undefined;
|
|
94
|
+
}
|
|
95
|
+
const item = (new surveys_surveyEditor_itemEditor.ItemEditor(undefined, newItem)).getItem();
|
|
96
|
+
if (atPosition !== undefined) {
|
|
97
|
+
obj.items.splice(atPosition, 0, item);
|
|
98
|
+
}
|
|
99
|
+
else {
|
|
100
|
+
obj.items.push(item);
|
|
101
|
+
}
|
|
102
|
+
return item;
|
|
103
|
+
}
|
|
104
|
+
addExistingSurveyItem(surveyItem, parentKey, atPosition) {
|
|
105
|
+
const parent = this.findSurveyItem(parentKey);
|
|
106
|
+
if (!parent) {
|
|
107
|
+
console.warn('parent survey item cannot be found: ', parentKey);
|
|
108
|
+
return;
|
|
109
|
+
}
|
|
110
|
+
if (parent.items.find(it => surveyItem.key === it.key)) {
|
|
111
|
+
logger_logger.Logger.criticalError('Duplicate key in survey: ' + surveyItem.key);
|
|
112
|
+
return undefined;
|
|
113
|
+
}
|
|
114
|
+
if (atPosition !== undefined) {
|
|
115
|
+
parent.items.splice(atPosition, 0, surveyItem);
|
|
116
|
+
}
|
|
117
|
+
else {
|
|
118
|
+
parent.items.push(surveyItem);
|
|
119
|
+
}
|
|
120
|
+
return surveyItem;
|
|
121
|
+
}
|
|
122
|
+
changeItemKey(oldKey, newKey, ignoreReferences) {
|
|
123
|
+
if (oldKey === this.surveyKey) {
|
|
124
|
+
this.surveyKey = newKey;
|
|
125
|
+
this.survey.current.surveyDefinition = this.changeItemKeyForSubtree(this.survey.current.surveyDefinition, newKey);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
let obj = this.findSurveyItem(oldKey);
|
|
129
|
+
if (!obj) {
|
|
130
|
+
console.warn('survey item cannot be found: ', oldKey);
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
obj = Object.assign(obj, this.changeItemKeyForSubtree(obj, newKey));
|
|
134
|
+
if (!ignoreReferences) {
|
|
135
|
+
// replace key in every expression of the survey
|
|
136
|
+
// replace key in every follows
|
|
137
|
+
console.warn('unimplemented UPDATING KEY REFERENCES');
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
;
|
|
141
|
+
updateSurveyItem(item) {
|
|
142
|
+
if (item.key === this.surveyKey) {
|
|
143
|
+
this.survey.current.surveyDefinition = Object.assign(Object.assign({}, this.survey.current.surveyDefinition), item);
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const ids = item.key.split('.');
|
|
147
|
+
const parentIds = ids.slice(0, ids.length - 1);
|
|
148
|
+
const parentKey = parentIds.join('.');
|
|
149
|
+
const obj = this.findSurveyItem(parentKey);
|
|
150
|
+
if (!obj) {
|
|
151
|
+
console.warn('parent survey item cannot be found: ', parentKey);
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
const index = obj.items.findIndex(it => it.key === item.key);
|
|
155
|
+
if (index < 0) {
|
|
156
|
+
console.warn('survey item cannot be found: ', item.key);
|
|
157
|
+
return;
|
|
158
|
+
}
|
|
159
|
+
obj.items[index] = Object.assign(Object.assign({}, obj.items[index]), item);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
;
|
|
163
|
+
removeItem(key) {
|
|
164
|
+
// <- error if item is not found
|
|
165
|
+
console.warn('removeItem unimplemented');
|
|
166
|
+
return;
|
|
167
|
+
}
|
|
168
|
+
;
|
|
169
|
+
moveSurveyItem(item, destination) {
|
|
170
|
+
console.warn('moveSurveyItem unimplemented');
|
|
171
|
+
// error if destination not exists
|
|
172
|
+
// change item key
|
|
173
|
+
// change key for all children recursivly
|
|
174
|
+
}
|
|
175
|
+
;
|
|
176
|
+
findSurveyItem(itemKey) {
|
|
177
|
+
const ids = itemKey.split('.');
|
|
178
|
+
const paths = this.getKeyListForPath(ids);
|
|
179
|
+
let obj = undefined;
|
|
180
|
+
for (const currentKey of paths) {
|
|
181
|
+
if (!obj) {
|
|
182
|
+
obj = this.survey.current.surveyDefinition;
|
|
183
|
+
continue;
|
|
184
|
+
}
|
|
185
|
+
if (!surveys_surveyEditor_itemEditor.isSurveyGroupItem(obj)) {
|
|
186
|
+
console.warn('survey item is not a group: ', obj.key);
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
const index = obj.items.findIndex(it => it.key === currentKey);
|
|
190
|
+
if (index < 0) {
|
|
191
|
+
console.warn('survey item cannot be found: ', currentKey);
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
obj = obj.items[index];
|
|
195
|
+
}
|
|
196
|
+
return obj;
|
|
197
|
+
}
|
|
198
|
+
;
|
|
199
|
+
getSurvey() {
|
|
200
|
+
return Object.assign({}, this.survey);
|
|
201
|
+
}
|
|
202
|
+
;
|
|
203
|
+
getSurveyJSON(pretty) {
|
|
204
|
+
return JSON.stringify(this.survey, undefined, pretty ? ' ' : undefined);
|
|
205
|
+
}
|
|
206
|
+
;
|
|
207
|
+
// Private methods:
|
|
208
|
+
getKeyListForPath(ids) {
|
|
209
|
+
const paths = [];
|
|
210
|
+
let compID = '';
|
|
211
|
+
for (let i = 0; i < ids.length; i++) {
|
|
212
|
+
const id = ids[i];
|
|
213
|
+
if (compID.length < 1) {
|
|
214
|
+
compID = id;
|
|
215
|
+
}
|
|
216
|
+
else {
|
|
217
|
+
compID += '.' + id;
|
|
218
|
+
}
|
|
219
|
+
paths.push(compID);
|
|
220
|
+
}
|
|
221
|
+
return paths;
|
|
222
|
+
}
|
|
223
|
+
changeItemKeyForSubtree(currentItem, newKey) {
|
|
224
|
+
currentItem = Object.assign({}, currentItem);
|
|
225
|
+
if (surveys_surveyEditor_itemEditor.isSurveyGroupItem(currentItem)) {
|
|
226
|
+
currentItem.items = currentItem.items.map(item => {
|
|
227
|
+
const newSubkey = newKey + '.' + item.key.slice(item.key.lastIndexOf('.') + 1);
|
|
228
|
+
return this.changeItemKeyForSubtree(item, newSubkey);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
currentItem.key = newKey;
|
|
232
|
+
return currentItem;
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
exports.SurveyEditor = SurveyEditor;
|
|
237
|
+
//# sourceMappingURL=survey-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"survey-editor.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|