@sap-ux/ui-prompting 0.1.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.
Files changed (86) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +20 -0
  3. package/dist/components/Inputs/Input/Input.d.ts +10 -0
  4. package/dist/components/Inputs/Input/Input.d.ts.map +1 -0
  5. package/dist/components/Inputs/Input/Input.js +21 -0
  6. package/dist/components/Inputs/Input/Input.js.map +1 -0
  7. package/dist/components/Inputs/Input/index.d.ts +2 -0
  8. package/dist/components/Inputs/Input/index.d.ts.map +1 -0
  9. package/dist/components/Inputs/Input/index.js +18 -0
  10. package/dist/components/Inputs/Input/index.js.map +1 -0
  11. package/dist/components/Inputs/MultiSelect/MultiSelect.d.ts +12 -0
  12. package/dist/components/Inputs/MultiSelect/MultiSelect.d.ts.map +1 -0
  13. package/dist/components/Inputs/MultiSelect/MultiSelect.js +30 -0
  14. package/dist/components/Inputs/MultiSelect/MultiSelect.js.map +1 -0
  15. package/dist/components/Inputs/MultiSelect/index.d.ts +2 -0
  16. package/dist/components/Inputs/MultiSelect/index.d.ts.map +1 -0
  17. package/dist/components/Inputs/MultiSelect/index.js +18 -0
  18. package/dist/components/Inputs/MultiSelect/index.js.map +1 -0
  19. package/dist/components/Inputs/Select/Select.d.ts +12 -0
  20. package/dist/components/Inputs/Select/Select.d.ts.map +1 -0
  21. package/dist/components/Inputs/Select/Select.js +46 -0
  22. package/dist/components/Inputs/Select/Select.js.map +1 -0
  23. package/dist/components/Inputs/Select/index.d.ts +2 -0
  24. package/dist/components/Inputs/Select/index.d.ts.map +1 -0
  25. package/dist/components/Inputs/Select/index.js +18 -0
  26. package/dist/components/Inputs/Select/index.js.map +1 -0
  27. package/dist/components/Inputs/index.d.ts +4 -0
  28. package/dist/components/Inputs/index.d.ts.map +1 -0
  29. package/dist/components/Inputs/index.js +20 -0
  30. package/dist/components/Inputs/index.js.map +1 -0
  31. package/dist/components/Question/Question.d.ts +15 -0
  32. package/dist/components/Question/Question.d.ts.map +1 -0
  33. package/dist/components/Question/Question.js +49 -0
  34. package/dist/components/Question/Question.js.map +1 -0
  35. package/dist/components/Question/Question.scss +47 -0
  36. package/dist/components/Question/index.d.ts +2 -0
  37. package/dist/components/Question/index.d.ts.map +1 -0
  38. package/dist/components/Question/index.js +18 -0
  39. package/dist/components/Question/index.js.map +1 -0
  40. package/dist/components/QuestionGroup/QuestionGroup.d.ts +11 -0
  41. package/dist/components/QuestionGroup/QuestionGroup.d.ts.map +1 -0
  42. package/dist/components/QuestionGroup/QuestionGroup.js +22 -0
  43. package/dist/components/QuestionGroup/QuestionGroup.js.map +1 -0
  44. package/dist/components/QuestionGroup/QuestionGroup.scss +31 -0
  45. package/dist/components/QuestionGroup/index.d.ts +2 -0
  46. package/dist/components/QuestionGroup/index.d.ts.map +1 -0
  47. package/dist/components/QuestionGroup/index.js +18 -0
  48. package/dist/components/QuestionGroup/index.js.map +1 -0
  49. package/dist/components/Questions/Questions.d.ts +19 -0
  50. package/dist/components/Questions/Questions.d.ts.map +1 -0
  51. package/dist/components/Questions/Questions.js +107 -0
  52. package/dist/components/Questions/Questions.js.map +1 -0
  53. package/dist/components/Questions/Questions.scss +23 -0
  54. package/dist/components/Questions/index.d.ts +2 -0
  55. package/dist/components/Questions/index.d.ts.map +1 -0
  56. package/dist/components/Questions/index.js +18 -0
  57. package/dist/components/Questions/index.js.map +1 -0
  58. package/dist/components/index.d.ts +4 -0
  59. package/dist/components/index.d.ts.map +1 -0
  60. package/dist/components/index.js +20 -0
  61. package/dist/components/index.js.map +1 -0
  62. package/dist/index.d.ts +4 -0
  63. package/dist/index.d.ts.map +1 -0
  64. package/dist/index.js +23 -0
  65. package/dist/index.js.map +1 -0
  66. package/dist/types.d.ts +115 -0
  67. package/dist/types.d.ts.map +1 -0
  68. package/dist/types.js +9 -0
  69. package/dist/types.js.map +1 -0
  70. package/dist/utilities/hooks.d.ts +61 -0
  71. package/dist/utilities/hooks.d.ts.map +1 -0
  72. package/dist/utilities/hooks.js +210 -0
  73. package/dist/utilities/hooks.js.map +1 -0
  74. package/dist/utilities/index.d.ts +4 -0
  75. package/dist/utilities/index.d.ts.map +1 -0
  76. package/dist/utilities/index.js +20 -0
  77. package/dist/utilities/index.js.map +1 -0
  78. package/dist/utilities/renderUtils.d.ts +6 -0
  79. package/dist/utilities/renderUtils.d.ts.map +1 -0
  80. package/dist/utilities/renderUtils.js +23 -0
  81. package/dist/utilities/renderUtils.js.map +1 -0
  82. package/dist/utilities/utils.d.ts +63 -0
  83. package/dist/utilities/utils.d.ts.map +1 -0
  84. package/dist/utilities/utils.js +169 -0
  85. package/dist/utilities/utils.js.map +1 -0
  86. package/package.json +79 -0
@@ -0,0 +1,61 @@
1
+ import type { UISelectableOption } from '@sap-ux/ui-components';
2
+ import type { PromptQuestion, DynamicChoices, PromptListChoices } from '../types';
3
+ import type { Answers, ChoiceOptions } from 'inquirer';
4
+ interface RequestedChoices {
5
+ [key: string]: boolean;
6
+ }
7
+ /**
8
+ * Hook for value update for input components.
9
+ *
10
+ * @param initialValue - Initial/default value
11
+ * @param propValue - External value from component properties
12
+ * @returns Returns a stateful value, and a function to update it.
13
+ */
14
+ export declare function useValue<S>(initialValue?: S, propValue?: S): [S | undefined, (value: S | undefined) => void];
15
+ /**
16
+ * Hook for dropdown/combobox options for dropdown components.
17
+ *
18
+ * @param question - Question with choices
19
+ * @param choices - External choices(if param is passed then choices would be used on top of "question.choices")
20
+ * @returns Returns dropdown/combobox options.
21
+ */
22
+ export declare function useOptions(question: PromptQuestion, choices?: PromptListChoices): UISelectableOption<ChoiceOptions>[];
23
+ /**
24
+ * Hook for requested choices update.
25
+ *
26
+ * @param initialValue - Initial/default choices
27
+ * @param latestChoices - Latest choices from component properties
28
+ * @returns Returns a stateful value, and a function to update it.
29
+ */
30
+ export declare function useRequestedChoices(initialValue: RequestedChoices, latestChoices?: DynamicChoices): [RequestedChoices, (value: string[]) => void];
31
+ /**
32
+ * Hook as effect to detect when dynamic choices should be requested.
33
+ *
34
+ * @param effect - Effect which triggered when update/refresh for dynamic questions should be requested
35
+ * @param questions - Current questions
36
+ */
37
+ export declare function useDynamicQuestionsEffect(effect: (names: string[]) => void, questions: PromptQuestion[]): void;
38
+ /**
39
+ * Hook for question answers state object whch maintains external answers with defaul answers from questions.
40
+ *
41
+ * @param questions - Questions which can contain default answers
42
+ * @param externalAnswers - External answers to merge with default values from questions
43
+ * @param onInitialChange - Callback function which called when external or default values of questions changed
44
+ * @returns Returns a stateful answers, and a function to update it.
45
+ */
46
+ export declare function useAnswers(questions: PromptQuestion[], externalAnswers?: Answers, onInitialChange?: (value: Answers) => void): [Answers, (value: Answers) => void];
47
+ /**
48
+ * Method to generate id for prompt component.
49
+ *
50
+ * @returns Generated id for prompt component.
51
+ */
52
+ export declare function getId(): string;
53
+ /**
54
+ * Hook for unique id for component or DOM element.
55
+ *
56
+ * @param externalId - external id
57
+ * @returns Resolved id for component or DOM.
58
+ */
59
+ export declare function useId(externalId?: string): string;
60
+ export {};
61
+ //# sourceMappingURL=hooks.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/utilities/hooks.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAoB,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAElF,OAAO,KAAK,EAAE,cAAc,EAAE,cAAc,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAClF,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEvD,UAAU,gBAAgB;IACtB,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC;CAC1B;AAED;;;;;;GAMG;AACH,wBAAgB,QAAQ,CAAC,CAAC,EAAE,YAAY,CAAC,EAAE,CAAC,EAAE,SAAS,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,KAAK,EAAE,CAAC,GAAG,SAAS,KAAK,IAAI,CAAC,CAe5G;AAsBD;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,cAAc,EAAE,OAAO,CAAC,EAAE,iBAAiB,GAAG,kBAAkB,CAAC,aAAa,CAAC,EAAE,CAOrH;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAC/B,YAAY,EAAE,gBAAgB,EAC9B,aAAa,GAAE,cAAmB,GACnC,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC,CA4B/C;AAiBD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE,SAAS,EAAE,cAAc,EAAE,GAAG,IAAI,CAU9G;AAwBD;;;;;;;GAOG;AACH,wBAAgB,UAAU,CACtB,SAAS,EAAE,cAAc,EAAE,EAC3B,eAAe,CAAC,EAAE,OAAO,EACzB,eAAe,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,GAC3C,CAAC,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC,CA0BrC;AAGD;;;;GAIG;AACH,wBAAgB,KAAK,IAAI,MAAM,CAI9B;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,CASjD"}
@@ -0,0 +1,210 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useId = exports.getId = exports.useAnswers = exports.useDynamicQuestionsEffect = exports.useRequestedChoices = exports.useOptions = exports.useValue = void 0;
4
+ const react_1 = require("react");
5
+ const utils_1 = require("./utils");
6
+ /**
7
+ * Hook for value update for input components.
8
+ *
9
+ * @param initialValue - Initial/default value
10
+ * @param propValue - External value from component properties
11
+ * @returns Returns a stateful value, and a function to update it.
12
+ */
13
+ function useValue(initialValue, propValue) {
14
+ const [value, setValue] = (0, react_1.useState)(propValue ?? initialValue);
15
+ (0, react_1.useEffect)(() => {
16
+ // Update the local state value if new value from props is received
17
+ if (propValue !== value) {
18
+ setValue(propValue);
19
+ }
20
+ }, [propValue]);
21
+ const updateValue = (newValue) => {
22
+ setValue(newValue);
23
+ };
24
+ return [value, updateValue];
25
+ }
26
+ exports.useValue = useValue;
27
+ /**
28
+ * Method returns dropdown options for passed question.
29
+ *
30
+ * @param question - Question with choices
31
+ * @param choices - External choices(if param is passed then choices would be used on top of "question.choices")
32
+ * @returns Returns dropdown/combobox options.
33
+ */
34
+ function getQuestionOptions(question, choices) {
35
+ // Use external/dynamicly populated choices
36
+ let resolvedChoices = choices;
37
+ // Use static choices if dynamic choices are not available
38
+ if (!resolvedChoices && 'choices' in question && Array.isArray(question.choices)) {
39
+ resolvedChoices = question.choices;
40
+ }
41
+ return (0, utils_1.convertChoicesToOptions)(resolvedChoices ?? []);
42
+ }
43
+ /**
44
+ * Hook for dropdown/combobox options for dropdown components.
45
+ *
46
+ * @param question - Question with choices
47
+ * @param choices - External choices(if param is passed then choices would be used on top of "question.choices")
48
+ * @returns Returns dropdown/combobox options.
49
+ */
50
+ function useOptions(question, choices) {
51
+ const [options, setOptions] = (0, react_1.useState)(() => getQuestionOptions(question, choices));
52
+ (0, react_1.useEffect)(() => {
53
+ const options = getQuestionOptions(question, choices);
54
+ setOptions(options);
55
+ }, [question, choices]);
56
+ return options;
57
+ }
58
+ exports.useOptions = useOptions;
59
+ /**
60
+ * Hook for requested choices update.
61
+ *
62
+ * @param initialValue - Initial/default choices
63
+ * @param latestChoices - Latest choices from component properties
64
+ * @returns Returns a stateful value, and a function to update it.
65
+ */
66
+ function useRequestedChoices(initialValue, latestChoices = {}) {
67
+ const requests = (0, react_1.useRef)({ ...initialValue });
68
+ const [pendingRequests, setPendingRequests] = (0, react_1.useState)({ ...requests.current });
69
+ const choices = (0, react_1.useRef)({ ...latestChoices });
70
+ const setRequestedChoices = (names) => {
71
+ for (const name of names) {
72
+ requests.current[name] = true;
73
+ // Remove previous choices
74
+ delete choices.current[name];
75
+ }
76
+ setPendingRequests({ ...requests.current });
77
+ };
78
+ (0, react_1.useEffect)(() => {
79
+ let updated = false;
80
+ for (const name in latestChoices) {
81
+ if (!choices.current[name]) {
82
+ updated = true;
83
+ // Update local choices and pending requests
84
+ choices.current[name] = latestChoices[name];
85
+ delete requests.current[name];
86
+ }
87
+ }
88
+ choices.current = { ...latestChoices };
89
+ if (updated) {
90
+ setPendingRequests({ ...requests.current });
91
+ }
92
+ }, [latestChoices]);
93
+ return [pendingRequests, setRequestedChoices];
94
+ }
95
+ exports.useRequestedChoices = useRequestedChoices;
96
+ /**
97
+ * Method checks if array of dynamic questions are equal.
98
+ *
99
+ * @param values1 - First array of choices
100
+ * @param values2 - Second array of choices
101
+ * @returns Returns true if all values in both arays exists.
102
+ */
103
+ function isDynamicQuestionsEquals(values1, values2) {
104
+ return (values1.length === values2.length &&
105
+ values1.every((value) => values2.includes(value)) &&
106
+ values2.every((value) => values1.includes(value)));
107
+ }
108
+ /**
109
+ * Hook as effect to detect when dynamic choices should be requested.
110
+ *
111
+ * @param effect - Effect which triggered when update/refresh for dynamic questions should be requested
112
+ * @param questions - Current questions
113
+ */
114
+ function useDynamicQuestionsEffect(effect, questions) {
115
+ const dynamicChoices = (0, react_1.useRef)([]);
116
+ (0, react_1.useEffect)(() => {
117
+ const newDynamicChoices = (0, utils_1.getDynamicQuestions)(questions);
118
+ if (!isDynamicQuestionsEquals(dynamicChoices.current, newDynamicChoices)) {
119
+ // Dynamic questions changed - trigger effect
120
+ dynamicChoices.current = newDynamicChoices;
121
+ effect(dynamicChoices.current);
122
+ }
123
+ }, [questions]);
124
+ }
125
+ exports.useDynamicQuestionsEffect = useDynamicQuestionsEffect;
126
+ /**
127
+ * Methods merges external answers with default values with questions and returns new reference with merged answers.
128
+ *
129
+ * @param answers - External answers to merge with default values from questions
130
+ * @param questions - Questions which can contain default answers
131
+ * @returns New reference with merged answers.
132
+ */
133
+ const mergeAllAnswers = (answers, questions) => {
134
+ const newAnswers = structuredClone(answers);
135
+ let merged = false;
136
+ for (const question of questions) {
137
+ if (question.default !== undefined && (0, utils_1.getAnswer)(newAnswers, question.name) === undefined) {
138
+ (0, utils_1.setAnswer)(newAnswers, question.name, question.default);
139
+ merged = true;
140
+ }
141
+ }
142
+ return {
143
+ merged,
144
+ answers: newAnswers
145
+ };
146
+ };
147
+ /**
148
+ * Hook for question answers state object whch maintains external answers with defaul answers from questions.
149
+ *
150
+ * @param questions - Questions which can contain default answers
151
+ * @param externalAnswers - External answers to merge with default values from questions
152
+ * @param onInitialChange - Callback function which called when external or default values of questions changed
153
+ * @returns Returns a stateful answers, and a function to update it.
154
+ */
155
+ function useAnswers(questions, externalAnswers, onInitialChange) {
156
+ const currentExternalAnswers = (0, react_1.useRef)({});
157
+ const [localAnswers, setLocalAnswers] = (0, react_1.useState)(() => {
158
+ // Initial value
159
+ const merge = mergeAllAnswers(externalAnswers ?? {}, questions);
160
+ return merge.answers ?? {};
161
+ });
162
+ (0, react_1.useEffect)(() => {
163
+ let updated = false;
164
+ let answers = localAnswers;
165
+ if (externalAnswers && !(0, utils_1.isDeepEqual)(currentExternalAnswers.current, externalAnswers)) {
166
+ currentExternalAnswers.current = externalAnswers;
167
+ answers = externalAnswers;
168
+ updated = true;
169
+ }
170
+ const { merged, answers: newAnswers } = mergeAllAnswers(answers, questions);
171
+ updated = merged || updated;
172
+ if (updated && newAnswers) {
173
+ setLocalAnswers(newAnswers);
174
+ // Callback function - notify about answers change
175
+ onInitialChange?.(newAnswers);
176
+ }
177
+ }, [questions, externalAnswers]);
178
+ return [localAnswers, setLocalAnswers];
179
+ }
180
+ exports.useAnswers = useAnswers;
181
+ let GENERATED_PROMPT_ID_INDEX = 0;
182
+ /**
183
+ * Method to generate id for prompt component.
184
+ *
185
+ * @returns Generated id for prompt component.
186
+ */
187
+ function getId() {
188
+ // Update global index
189
+ const index = GENERATED_PROMPT_ID_INDEX++;
190
+ return `ui-prompt${index}`;
191
+ }
192
+ exports.getId = getId;
193
+ /**
194
+ * Hook for unique id for component or DOM element.
195
+ *
196
+ * @param externalId - external id
197
+ * @returns Resolved id for component or DOM.
198
+ */
199
+ function useId(externalId) {
200
+ const currentExternalId = (0, react_1.useRef)(externalId);
201
+ const [id, setId] = (0, react_1.useState)(() => externalId ?? getId());
202
+ (0, react_1.useEffect)(() => {
203
+ if (currentExternalId.current !== externalId) {
204
+ setId(externalId ?? getId());
205
+ }
206
+ }, [externalId]);
207
+ return id;
208
+ }
209
+ exports.useId = useId;
210
+ //# sourceMappingURL=hooks.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hooks.js","sourceRoot":"","sources":["../../src/utilities/hooks.ts"],"names":[],"mappings":";;;AAAA,iCAAoD;AAEpD,mCAA0G;AAQ1G;;;;;;GAMG;AACH,SAAgB,QAAQ,CAAI,YAAgB,EAAE,SAAa;IACvD,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAG,IAAA,gBAAQ,EAAC,SAAS,IAAI,YAAY,CAAC,CAAC;IAE9D,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,mEAAmE;QACnE,IAAI,SAAS,KAAK,KAAK,EAAE,CAAC;YACtB,QAAQ,CAAC,SAAS,CAAC,CAAC;QACxB,CAAC;IACL,CAAC,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;IAEhB,MAAM,WAAW,GAAG,CAAC,QAAuB,EAAE,EAAE;QAC5C,QAAQ,CAAC,QAAQ,CAAC,CAAC;IACvB,CAAC,CAAC;IAEF,OAAO,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC;AAChC,CAAC;AAfD,4BAeC;AAED;;;;;;GAMG;AACH,SAAS,kBAAkB,CACvB,QAAwB,EACxB,OAA2B;IAE3B,2CAA2C;IAC3C,IAAI,eAAe,GAAG,OAAO,CAAC;IAC9B,0DAA0D;IAC1D,IAAI,CAAC,eAAe,IAAI,SAAS,IAAI,QAAQ,IAAI,KAAK,CAAC,OAAO,CA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G,IAAA,gBAAQ,EAAS,GAAG,EAAE,CAAC,UAAU,IAAI,KAAK,EAAE,CAAC,CAAC;IAClE,IAAA,iBAAS,EAAC,GAAG,EAAE;QACX,IAAI,iBAAiB,CAAC,OAAO,KAAK,UAAU,EAAE,CAAC;YAC3C,KAAK,CAAC,UAAU,IAAI,KAAK,EAAE,CAAC,CAAC;QACjC,CAAC;IACL,CAAC,EAAE,CAAC,UAAU,CAAC,CAAC,CAAC;IACjB,OAAO,EAAE,CAAC;AACd,CAAC;AATD,sBASC"}
@@ -0,0 +1,4 @@
1
+ export * from './hooks';
2
+ export * from './renderUtils';
3
+ export * from './utils';
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,SAAS,CAAC"}
@@ -0,0 +1,20 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./hooks"), exports);
18
+ __exportStar(require("./renderUtils"), exports);
19
+ __exportStar(require("./utils"), exports);
20
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utilities/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,0CAAwB;AACxB,gDAA8B;AAC9B,0CAAwB"}
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ type IRenderFunction<P> = (props?: P, defaultRender?: (props?: P) => JSX.Element | null) => JSX.Element | null;
3
+ export declare const onLabelRender: <P>(tooltipText?: string, props?: P | undefined, defaultRender?: ((props?: P | undefined) => React.ReactElement | null) | undefined) => React.ReactElement | null;
4
+ export declare const getLabelRenderer: <P>(title?: string) => IRenderFunction<P> | undefined;
5
+ export {};
6
+ //# sourceMappingURL=renderUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderUtils.d.ts","sourceRoot":"","sources":["../../src/utilities/renderUtils.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,KAAK,eAAe,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,EAAE,aAAa,CAAC,EAAE,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,GAAG,CAAC,OAAO,GAAG,IAAI,KAAK,GAAG,CAAC,OAAO,GAAG,IAAI,CAAC;AAE/G,eAAO,MAAM,aAAa,oBACR,MAAM,qEAEW,MAAM,YAAY,GAAG,IAAI,kBACzD,MAAM,YAAY,GAAG,IAOvB,CAAC;AAEF,eAAO,MAAM,gBAAgB,cAAwB,MAAM,mCAM1D,CAAC"}
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.getLabelRenderer = exports.onLabelRender = void 0;
7
+ const ui_components_1 = require("@sap-ux/ui-components");
8
+ const react_1 = __importDefault(require("react"));
9
+ const onLabelRender = function (tooltipText, props, defaultRender) {
10
+ return (react_1.default.createElement("div", { className: "input__label" },
11
+ defaultRender ? defaultRender(props) : undefined,
12
+ tooltipText && react_1.default.createElement(ui_components_1.UIIcon, { iconName: ui_components_1.UiIcons.Info, title: tooltipText })));
13
+ };
14
+ exports.onLabelRender = onLabelRender;
15
+ const getLabelRenderer = function (title) {
16
+ return title
17
+ ? (props, defaultRender) => {
18
+ return (0, exports.onLabelRender)(title, props, defaultRender);
19
+ }
20
+ : undefined;
21
+ };
22
+ exports.getLabelRenderer = getLabelRenderer;
23
+ //# sourceMappingURL=renderUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"renderUtils.js","sourceRoot":"","sources":["../../src/utilities/renderUtils.tsx"],"names":[],"mappings":";;;;;;AAAA,yDAAwD;AACxD,kDAA0B;AAInB,MAAM,aAAa,GAAG,UACzB,WAAoB,EACpB,KAAS,EACT,aAAwD;IAExD,OAAO,CACH,uCAAK,SAAS,EAAC,cAAc;QACxB,aAAa,CAAC,CAAC,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS;QAChD,WAAW,IAAI,8BAAC,sBAAM,IAAC,QAAQ,EAAE,uBAAO,CAAC,IAAI,EAAE,KAAK,EAAE,WAAW,GAAI,CACpE,CACT,CAAC;AACN,CAAC,CAAC;AAXW,QAAA,aAAa,iBAWxB;AAEK,MAAM,gBAAgB,GAAG,UAAa,KAAc;IACvD,OAAO,KAAK;QACR,CAAC,CAAC,CAAC,KAAS,EAAE,aAAwD,EAAE,EAAE;YACpE,OAAO,IAAA,qBAAa,EAAC,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,CAAC;QACtD,CAAC;QACH,CAAC,CAAC,SAAS,CAAC;AACpB,CAAC,CAAC;AANW,QAAA,gBAAgB,oBAM3B"}
@@ -0,0 +1,63 @@
1
+ import type { Answers, ChoiceOptions } from 'inquirer';
2
+ import type { PromptQuestion, AnswerValue, PromptListChoices } from '../types';
3
+ import type { UISelectableOption } from '@sap-ux/ui-components';
4
+ /**
5
+ * Method finds dependant question names for passed question.
6
+ * Method goes into recursion and finds dependant questions on deeper levels.
7
+ *
8
+ * @param questions - All questions
9
+ * @param name - Question name for which dependant question names should be resolved
10
+ * @param dependantPromptNames - Existing dependant names to update
11
+ * @returns Found dependant question names for passed question.
12
+ */
13
+ export declare function getDependantQuestions(questions: PromptQuestion[], name: string, dependantPromptNames?: string[]): string[];
14
+ /**
15
+ * Method finds all dynamic questions.
16
+ *
17
+ * @param questions - All questions
18
+ * @returns Found dynamic questions.
19
+ */
20
+ export declare function getDynamicQuestions(questions: PromptQuestion[]): string[];
21
+ /**
22
+ * Method updates answer value and resets dependant questions answer.
23
+ *
24
+ * @param answers - Latest answers
25
+ * @param questions - All questions
26
+ * @param name - Answer to update
27
+ * @param value - New value of answer
28
+ * @returns New reference of updated answers.
29
+ */
30
+ export declare function updateAnswers(answers: Answers, questions: PromptQuestion[], name: string, value?: AnswerValue): Answers;
31
+ /**
32
+ * Method updates single answer in answers object.
33
+ *
34
+ * @param answers - Answers to update
35
+ * @param path - Path to answer
36
+ * @param value - Value of answer
37
+ * @returns Updated answers.
38
+ */
39
+ export declare function setAnswer(answers: Answers, path: string, value: unknown): Answers;
40
+ /**
41
+ * Method gets answer value by passed path.
42
+ *
43
+ * @param answers - All answers
44
+ * @param path - Path to answer
45
+ * @returns Answer value.
46
+ */
47
+ export declare function getAnswer(answers: Answers, path: string): unknown;
48
+ /**
49
+ * Method convert choices(inquirer) to dropdown/combobox options(ui-components).
50
+ *
51
+ * @param choices - Array of choices
52
+ * @returns Returns dropdown/combobox options.
53
+ */
54
+ export declare function convertChoicesToOptions(choices: PromptListChoices): UISelectableOption<ChoiceOptions>[];
55
+ /**
56
+ * Method deeply compares two answers objects.
57
+ *
58
+ * @param obj1 - First object with answers
59
+ * @param obj2 - Second object with answers
60
+ * @returns True if objects are same.
61
+ */
62
+ export declare function isDeepEqual(obj1: Answers, obj2: Answers): boolean;
63
+ //# sourceMappingURL=utils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../../src/utilities/utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACvD,OAAO,KAAK,EAAE,cAAc,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAC;AAC/E,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAC;AAEhE;;;;;;;;GAQG;AACH,wBAAgB,qBAAqB,CACjC,SAAS,EAAE,cAAc,EAAE,EAC3B,IAAI,EAAE,MAAM,EACZ,oBAAoB,GAAE,MAAM,EAAO,GACpC,MAAM,EAAE,CAUV;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,SAAS,EAAE,cAAc,EAAE,GAAG,MAAM,EAAE,CAMzE;AAED;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CACzB,OAAO,EAAE,OAAO,EAChB,SAAS,EAAE,cAAc,EAAE,EAC3B,IAAI,EAAE,MAAM,EACZ,KAAK,CAAC,EAAE,WAAW,GACpB,OAAO,CAQT;AAED;;;;;;;GAOG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,OAAO,CAyBjF;AAED;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAYjE;AAED;;;;;GAKG;AACH,wBAAgB,uBAAuB,CAAC,OAAO,EAAE,iBAAiB,GAAG,kBAAkB,CAAC,aAAa,CAAC,EAAE,CAsBvG;AAED;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAkBjE"}
@@ -0,0 +1,169 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isDeepEqual = exports.convertChoicesToOptions = exports.getAnswer = exports.setAnswer = exports.updateAnswers = exports.getDynamicQuestions = exports.getDependantQuestions = void 0;
4
+ /**
5
+ * Method finds dependant question names for passed question.
6
+ * Method goes into recursion and finds dependant questions on deeper levels.
7
+ *
8
+ * @param questions - All questions
9
+ * @param name - Question name for which dependant question names should be resolved
10
+ * @param dependantPromptNames - Existing dependant names to update
11
+ * @returns Found dependant question names for passed question.
12
+ */
13
+ function getDependantQuestions(questions, name, dependantPromptNames = []) {
14
+ const question = questions.find((checkQuestion) => checkQuestion.name === name);
15
+ if (question?.type === 'list') {
16
+ const questionsDependantNames = question?.guiOptions?.dependantPromptNames ?? [];
17
+ questionsDependantNames.forEach((dependantName) => {
18
+ dependantPromptNames.push(dependantName);
19
+ getDependantQuestions(questions, dependantName, dependantPromptNames);
20
+ });
21
+ }
22
+ return dependantPromptNames;
23
+ }
24
+ exports.getDependantQuestions = getDependantQuestions;
25
+ /**
26
+ * Method finds all dynamic questions.
27
+ *
28
+ * @param questions - All questions
29
+ * @returns Found dynamic questions.
30
+ */
31
+ function getDynamicQuestions(questions) {
32
+ const dynamicQuestions = questions.filter((question) => {
33
+ const { guiOptions = {} } = question;
34
+ return 'selectType' in guiOptions && guiOptions.selectType === 'dynamic' && !!question.name;
35
+ });
36
+ return dynamicQuestions.map((question) => question.name);
37
+ }
38
+ exports.getDynamicQuestions = getDynamicQuestions;
39
+ /**
40
+ * Method updates answer value and resets dependant questions answer.
41
+ *
42
+ * @param answers - Latest answers
43
+ * @param questions - All questions
44
+ * @param name - Answer to update
45
+ * @param value - New value of answer
46
+ * @returns New reference of updated answers.
47
+ */
48
+ function updateAnswers(answers, questions, name, value) {
49
+ let updatedAnswers = setAnswer(structuredClone(answers), name, value);
50
+ const dependantPromptNames = getDependantQuestions(questions, name);
51
+ dependantPromptNames?.length &&
52
+ dependantPromptNames.forEach((dependantName) => {
53
+ updatedAnswers = setAnswer(updatedAnswers, dependantName, undefined);
54
+ });
55
+ return updatedAnswers;
56
+ }
57
+ exports.updateAnswers = updateAnswers;
58
+ /**
59
+ * Method updates single answer in answers object.
60
+ *
61
+ * @param answers - Answers to update
62
+ * @param path - Path to answer
63
+ * @param value - Value of answer
64
+ * @returns Updated answers.
65
+ */
66
+ function setAnswer(answers, path, value) {
67
+ const keys = path.split('.');
68
+ let current = answers;
69
+ let validPath = true;
70
+ for (let i = 0; i < keys.length - 1; i++) {
71
+ const key = keys[i];
72
+ if (['__proto__', 'constructor', 'prototype'].includes(key)) {
73
+ // Prototype-polluting assignment restriction
74
+ validPath = false;
75
+ break;
76
+ }
77
+ if (current && typeof current === 'object' && !(key in current)) {
78
+ current[key] = {};
79
+ }
80
+ current = current[key];
81
+ }
82
+ if (validPath) {
83
+ const key = keys[keys.length - 1];
84
+ if (!['__proto__', 'constructor', 'prototype'].includes(key)) {
85
+ current[key] = value;
86
+ }
87
+ }
88
+ return answers;
89
+ }
90
+ exports.setAnswer = setAnswer;
91
+ /**
92
+ * Method gets answer value by passed path.
93
+ *
94
+ * @param answers - All answers
95
+ * @param path - Path to answer
96
+ * @returns Answer value.
97
+ */
98
+ function getAnswer(answers, path) {
99
+ const keys = path.split('.');
100
+ let current = answers;
101
+ for (const key of keys) {
102
+ if (typeof current !== 'object' || !(key in current)) {
103
+ return undefined;
104
+ }
105
+ current = current[key];
106
+ }
107
+ return current;
108
+ }
109
+ exports.getAnswer = getAnswer;
110
+ /**
111
+ * Method convert choices(inquirer) to dropdown/combobox options(ui-components).
112
+ *
113
+ * @param choices - Array of choices
114
+ * @returns Returns dropdown/combobox options.
115
+ */
116
+ function convertChoicesToOptions(choices) {
117
+ if (!choices.length) {
118
+ return [];
119
+ }
120
+ const options = [];
121
+ for (const choice of choices) {
122
+ if (typeof choice === 'object' && 'value' in choice) {
123
+ options.push({
124
+ key: choice.value.toString(),
125
+ text: choice.name ?? '',
126
+ data: choice
127
+ });
128
+ }
129
+ else {
130
+ const choiceText = choice.toString();
131
+ options.push({
132
+ key: choiceText,
133
+ text: choiceText,
134
+ data: { value: choice }
135
+ });
136
+ }
137
+ }
138
+ return options;
139
+ }
140
+ exports.convertChoicesToOptions = convertChoicesToOptions;
141
+ /**
142
+ * Method deeply compares two answers objects.
143
+ *
144
+ * @param obj1 - First object with answers
145
+ * @param obj2 - Second object with answers
146
+ * @returns True if objects are same.
147
+ */
148
+ function isDeepEqual(obj1, obj2) {
149
+ // Check if both inputs are objects
150
+ if (typeof obj1 === 'object' && obj1 !== null && typeof obj2 === 'object' && obj2 !== null) {
151
+ // Check if both objects have the same number of properties
152
+ if (Object.keys(obj1).length !== Object.keys(obj2).length) {
153
+ return false;
154
+ }
155
+ // Recursively check each property
156
+ for (const key in obj1) {
157
+ if (!obj2.hasOwnProperty(key) || !isDeepEqual(obj1[key], obj2[key])) {
158
+ return false;
159
+ }
160
+ }
161
+ return true;
162
+ }
163
+ else {
164
+ // For primitive values, use strict equality
165
+ return obj1 === obj2;
166
+ }
167
+ }
168
+ exports.isDeepEqual = isDeepEqual;
169
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/utilities/utils.ts"],"names":[],"mappings":";;;AAIA;;;;;;;;GAQG;AACH,SAAgB,qBAAqB,CACjC,SAA2B,EAC3B,IAAY,EACZ,uBAAiC,EAAE;IAEnC,MAAM,QAAQ,GAAG,SAAS,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC;IAChF,IAAI,QAAQ,EAAE,IAAI,KAAK,MAAM,EAAE,CAAC;QAC5B,MAAM,uBAAuB,GAAG,QAAQ,EAAE,UAAU,EAAE,oBAAoB,IAAI,EAAE,CAAC;QACjF,uBAAuB,CAAC,OAAO,CAAC,CAAC,aAAa,EAAE,EAAE;YAC9C,oBAAoB,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC;YACzC,qBAAqB,CAAC,SAAS,EAAE,aAAa,EAAE,oBAAoB,CAAC,CAAC;QAC1E,CAAC,CAAC,CAAC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