case-editor-tools 1.0.0-beta.16 → 1.0.0-beta.17

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