@sap-ux/fiori-mcp-server 0.0.1

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 (181) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +99 -0
  3. package/dist/constant.d.ts +5 -0
  4. package/dist/constant.js +8 -0
  5. package/dist/index.d.ts +3 -0
  6. package/dist/index.js +7 -0
  7. package/dist/page-editor-api/api.d.ts +48 -0
  8. package/dist/page-editor-api/api.js +93 -0
  9. package/dist/page-editor-api/index.d.ts +5 -0
  10. package/dist/page-editor-api/index.js +24 -0
  11. package/dist/page-editor-api/json-helper.d.ts +11 -0
  12. package/dist/page-editor-api/json-helper.js +64 -0
  13. package/dist/page-editor-api/parser/annotations.d.ts +9 -0
  14. package/dist/page-editor-api/parser/annotations.js +13 -0
  15. package/dist/page-editor-api/parser/index.d.ts +3 -0
  16. package/dist/page-editor-api/parser/index.js +19 -0
  17. package/dist/page-editor-api/parser/model/AggregationValidator.d.ts +64 -0
  18. package/dist/page-editor-api/parser/model/AggregationValidator.js +209 -0
  19. package/dist/page-editor-api/parser/model/ArrayAggregation.d.ts +49 -0
  20. package/dist/page-editor-api/parser/model/ArrayAggregation.js +122 -0
  21. package/dist/page-editor-api/parser/model/ObjectAggregation.d.ts +374 -0
  22. package/dist/page-editor-api/parser/model/ObjectAggregation.js +802 -0
  23. package/dist/page-editor-api/parser/model/PageEditModel.d.ts +223 -0
  24. package/dist/page-editor-api/parser/model/PageEditModel.js +954 -0
  25. package/dist/page-editor-api/parser/model/PageEditProperty.d.ts +38 -0
  26. package/dist/page-editor-api/parser/model/PageEditProperty.js +49 -0
  27. package/dist/page-editor-api/parser/model/RootAggregation.d.ts +24 -0
  28. package/dist/page-editor-api/parser/model/RootAggregation.js +54 -0
  29. package/dist/page-editor-api/parser/model/actions/ActionAggregation.d.ts +34 -0
  30. package/dist/page-editor-api/parser/model/actions/ActionAggregation.js +92 -0
  31. package/dist/page-editor-api/parser/model/actions/ActionsAggregation.d.ts +96 -0
  32. package/dist/page-editor-api/parser/model/actions/ActionsAggregation.js +252 -0
  33. package/dist/page-editor-api/parser/model/actions/index.d.ts +3 -0
  34. package/dist/page-editor-api/parser/model/actions/index.js +19 -0
  35. package/dist/page-editor-api/parser/model/additionalObjects/AdditionalObjectAggregation.d.ts +17 -0
  36. package/dist/page-editor-api/parser/model/additionalObjects/AdditionalObjectAggregation.js +26 -0
  37. package/dist/page-editor-api/parser/model/additionalObjects/AdditionalObjectsAggregation.d.ts +46 -0
  38. package/dist/page-editor-api/parser/model/additionalObjects/AdditionalObjectsAggregation.js +66 -0
  39. package/dist/page-editor-api/parser/model/additionalObjects/index.d.ts +3 -0
  40. package/dist/page-editor-api/parser/model/additionalObjects/index.js +19 -0
  41. package/dist/page-editor-api/parser/model/chart/ChartAggregation.d.ts +41 -0
  42. package/dist/page-editor-api/parser/model/chart/ChartAggregation.js +94 -0
  43. package/dist/page-editor-api/parser/model/chart/index.d.ts +2 -0
  44. package/dist/page-editor-api/parser/model/chart/index.js +18 -0
  45. package/dist/page-editor-api/parser/model/fields/ConnectedFieldsAggregation.d.ts +9 -0
  46. package/dist/page-editor-api/parser/model/fields/ConnectedFieldsAggregation.js +13 -0
  47. package/dist/page-editor-api/parser/model/fields/FieldAggregation.d.ts +25 -0
  48. package/dist/page-editor-api/parser/model/fields/FieldAggregation.js +42 -0
  49. package/dist/page-editor-api/parser/model/fields/FieldsAggregation.d.ts +22 -0
  50. package/dist/page-editor-api/parser/model/fields/FieldsAggregation.js +34 -0
  51. package/dist/page-editor-api/parser/model/fields/index.d.ts +4 -0
  52. package/dist/page-editor-api/parser/model/fields/index.js +20 -0
  53. package/dist/page-editor-api/parser/model/filter-fields/FilterFieldAggregation.d.ts +39 -0
  54. package/dist/page-editor-api/parser/model/filter-fields/FilterFieldAggregation.js +94 -0
  55. package/dist/page-editor-api/parser/model/filter-fields/FilterFieldsAggregation.d.ts +36 -0
  56. package/dist/page-editor-api/parser/model/filter-fields/FilterFieldsAggregation.js +59 -0
  57. package/dist/page-editor-api/parser/model/filter-fields/index.d.ts +3 -0
  58. package/dist/page-editor-api/parser/model/filter-fields/index.js +19 -0
  59. package/dist/page-editor-api/parser/model/index.d.ts +19 -0
  60. package/dist/page-editor-api/parser/model/index.js +35 -0
  61. package/dist/page-editor-api/parser/model/macros/MacrosRoot.d.ts +48 -0
  62. package/dist/page-editor-api/parser/model/macros/MacrosRoot.js +114 -0
  63. package/dist/page-editor-api/parser/model/macros/index.d.ts +2 -0
  64. package/dist/page-editor-api/parser/model/macros/index.js +18 -0
  65. package/dist/page-editor-api/parser/model/sections/HeaderSectionsAggregation.d.ts +31 -0
  66. package/dist/page-editor-api/parser/model/sections/HeaderSectionsAggregation.js +82 -0
  67. package/dist/page-editor-api/parser/model/sections/SectionAggregation.d.ts +78 -0
  68. package/dist/page-editor-api/parser/model/sections/SectionAggregation.js +131 -0
  69. package/dist/page-editor-api/parser/model/sections/SectionsAggregation.d.ts +135 -0
  70. package/dist/page-editor-api/parser/model/sections/SectionsAggregation.js +402 -0
  71. package/dist/page-editor-api/parser/model/sections/SectionsObjectAggregation.d.ts +50 -0
  72. package/dist/page-editor-api/parser/model/sections/SectionsObjectAggregation.js +119 -0
  73. package/dist/page-editor-api/parser/model/sections/SubSectionsAggregation.d.ts +39 -0
  74. package/dist/page-editor-api/parser/model/sections/SubSectionsAggregation.js +70 -0
  75. package/dist/page-editor-api/parser/model/sections/index.d.ts +6 -0
  76. package/dist/page-editor-api/parser/model/sections/index.js +22 -0
  77. package/dist/page-editor-api/parser/model/table/ColumnAggregation.d.ts +89 -0
  78. package/dist/page-editor-api/parser/model/table/ColumnAggregation.js +175 -0
  79. package/dist/page-editor-api/parser/model/table/ColumnsAggregation.d.ts +113 -0
  80. package/dist/page-editor-api/parser/model/table/ColumnsAggregation.js +293 -0
  81. package/dist/page-editor-api/parser/model/table/TableAggregation.d.ts +13 -0
  82. package/dist/page-editor-api/parser/model/table/TableAggregation.js +21 -0
  83. package/dist/page-editor-api/parser/model/table/ToolbarAggregation.d.ts +15 -0
  84. package/dist/page-editor-api/parser/model/table/ToolbarAggregation.js +22 -0
  85. package/dist/page-editor-api/parser/model/table/index.d.ts +5 -0
  86. package/dist/page-editor-api/parser/model/table/index.js +21 -0
  87. package/dist/page-editor-api/parser/model/table/utils.d.ts +12 -0
  88. package/dist/page-editor-api/parser/model/table/utils.js +44 -0
  89. package/dist/page-editor-api/parser/model/types/annotations.d.ts +63 -0
  90. package/dist/page-editor-api/parser/model/types/annotations.js +29 -0
  91. package/dist/page-editor-api/parser/model/types/common.d.ts +13 -0
  92. package/dist/page-editor-api/parser/model/types/common.js +3 -0
  93. package/dist/page-editor-api/parser/model/types/index.d.ts +220 -0
  94. package/dist/page-editor-api/parser/model/types/index.js +149 -0
  95. package/dist/page-editor-api/parser/model/utils/annotations.d.ts +38 -0
  96. package/dist/page-editor-api/parser/model/utils/annotations.js +120 -0
  97. package/dist/page-editor-api/parser/model/utils/i18n.d.ts +33 -0
  98. package/dist/page-editor-api/parser/model/utils/i18n.js +69 -0
  99. package/dist/page-editor-api/parser/model/utils/index.d.ts +6 -0
  100. package/dist/page-editor-api/parser/model/utils/index.js +22 -0
  101. package/dist/page-editor-api/parser/model/utils/object.d.ts +25 -0
  102. package/dist/page-editor-api/parser/model/utils/object.js +68 -0
  103. package/dist/page-editor-api/parser/model/utils/sort.d.ts +31 -0
  104. package/dist/page-editor-api/parser/model/utils/sort.js +18 -0
  105. package/dist/page-editor-api/parser/model/utils/utils.d.ts +94 -0
  106. package/dist/page-editor-api/parser/model/utils/utils.js +267 -0
  107. package/dist/page-editor-api/parser/model/views/ViewAggregation.d.ts +62 -0
  108. package/dist/page-editor-api/parser/model/views/ViewAggregation.js +112 -0
  109. package/dist/page-editor-api/parser/model/views/ViewsAggregation.d.ts +54 -0
  110. package/dist/page-editor-api/parser/model/views/ViewsAggregation.js +141 -0
  111. package/dist/page-editor-api/parser/model/views/index.d.ts +3 -0
  112. package/dist/page-editor-api/parser/model/views/index.js +19 -0
  113. package/dist/page-editor-api/parser/model/visual-filters/VisualFilterAggregation.d.ts +11 -0
  114. package/dist/page-editor-api/parser/model/visual-filters/VisualFilterAggregation.js +15 -0
  115. package/dist/page-editor-api/parser/model/visual-filters/VisualFiltersAggregation.d.ts +11 -0
  116. package/dist/page-editor-api/parser/model/visual-filters/VisualFiltersAggregation.js +15 -0
  117. package/dist/page-editor-api/parser/model/visual-filters/index.d.ts +3 -0
  118. package/dist/page-editor-api/parser/model/visual-filters/index.js +19 -0
  119. package/dist/page-editor-api/parser/tree.d.ts +135 -0
  120. package/dist/page-editor-api/parser/tree.js +464 -0
  121. package/dist/page-editor-api/project.d.ts +40 -0
  122. package/dist/page-editor-api/project.js +124 -0
  123. package/dist/page-editor-api/sapuxFtfsFileIO.d.ts +84 -0
  124. package/dist/page-editor-api/sapuxFtfsFileIO.js +195 -0
  125. package/dist/server.d.ts +35 -0
  126. package/dist/server.js +120 -0
  127. package/dist/tools/execute-functionality.d.ts +19 -0
  128. package/dist/tools/execute-functionality.js +175 -0
  129. package/dist/tools/functionalities/controller-extension/index.d.ts +4 -0
  130. package/dist/tools/functionalities/controller-extension/index.js +136 -0
  131. package/dist/tools/functionalities/functionalities.d.ts +4 -0
  132. package/dist/tools/functionalities/functionalities.js +19 -0
  133. package/dist/tools/functionalities/generate-fiori-ui-app/command.d.ts +9 -0
  134. package/dist/tools/functionalities/generate-fiori-ui-app/command.js +158 -0
  135. package/dist/tools/functionalities/generate-fiori-ui-app/generate-fiori-ui-app.d.ts +4 -0
  136. package/dist/tools/functionalities/generate-fiori-ui-app/generate-fiori-ui-app.js +240 -0
  137. package/dist/tools/functionalities/generate-fiori-ui-app/index.d.ts +2 -0
  138. package/dist/tools/functionalities/generate-fiori-ui-app/index.js +7 -0
  139. package/dist/tools/functionalities/index.d.ts +2 -0
  140. package/dist/tools/functionalities/index.js +18 -0
  141. package/dist/tools/functionalities/page/add-page.d.ts +5 -0
  142. package/dist/tools/functionalities/page/add-page.js +89 -0
  143. package/dist/tools/functionalities/page/application.d.ts +212 -0
  144. package/dist/tools/functionalities/page/application.js +616 -0
  145. package/dist/tools/functionalities/page/delete-page.d.ts +4 -0
  146. package/dist/tools/functionalities/page/delete-page.js +71 -0
  147. package/dist/tools/functionalities/page/index.d.ts +3 -0
  148. package/dist/tools/functionalities/page/index.js +10 -0
  149. package/dist/tools/functionalities/page/service.d.ts +82 -0
  150. package/dist/tools/functionalities/page/service.js +114 -0
  151. package/dist/tools/functionalities/page/serviceStore.d.ts +17 -0
  152. package/dist/tools/functionalities/page/serviceStore.js +34 -0
  153. package/dist/tools/functionalities/page/types.d.ts +42 -0
  154. package/dist/tools/functionalities/page/types.js +11 -0
  155. package/dist/tools/functionalities/page/utils.d.ts +12 -0
  156. package/dist/tools/functionalities/page/utils.js +63 -0
  157. package/dist/tools/get-functionality-details.d.ts +24 -0
  158. package/dist/tools/get-functionality-details.js +142 -0
  159. package/dist/tools/index.d.ts +7 -0
  160. package/dist/tools/index.js +55 -0
  161. package/dist/tools/input-schema/execute-functionality.json +28 -0
  162. package/dist/tools/input-schema/get-functionality-details.json +24 -0
  163. package/dist/tools/input-schema/index.d.ts +5 -0
  164. package/dist/tools/input-schema/index.js +15 -0
  165. package/dist/tools/input-schema/list-fiori-apps.json +12 -0
  166. package/dist/tools/input-schema/list-functionality.json +10 -0
  167. package/dist/tools/list-fiori-apps.d.ts +10 -0
  168. package/dist/tools/list-fiori-apps.js +33 -0
  169. package/dist/tools/list-functionalities.d.ts +10 -0
  170. package/dist/tools/list-functionalities.js +145 -0
  171. package/dist/tools/output-schema/execute-functionality.json +39 -0
  172. package/dist/tools/output-schema/get-functionality-details.json +142 -0
  173. package/dist/tools/output-schema/index.d.ts +5 -0
  174. package/dist/tools/output-schema/index.js +15 -0
  175. package/dist/tools/output-schema/list-fiori-apps.json +41 -0
  176. package/dist/tools/output-schema/list-functionality.json +37 -0
  177. package/dist/tools/utils.d.ts +16 -0
  178. package/dist/tools/utils.js +74 -0
  179. package/dist/types.d.ts +170 -0
  180. package/dist/types.js +3 -0
  181. package/package.json +63 -0
@@ -0,0 +1,802 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ObjectAggregation = exports.CUSTOM_EXTENSION_ANCHOR_PROPERTIES = void 0;
4
+ const types_1 = require("./types");
5
+ const PageEditProperty_1 = require("./PageEditProperty");
6
+ const utils_1 = require("./utils");
7
+ const annotations_1 = require("../annotations");
8
+ const ROOT_SORTING_NAMES = {
9
+ top: ['header', 'filterBar']
10
+ };
11
+ exports.CUSTOM_EXTENSION_ANCHOR_PROPERTIES = ['anchor', 'relatedFacet'];
12
+ /**
13
+ * Represents an aggregation for objects.
14
+ */
15
+ class ObjectAggregation {
16
+ // Path
17
+ path = [];
18
+ // Standard properties for aggregation and properties
19
+ aggregations = {};
20
+ properties = {};
21
+ additionalProperties;
22
+ // Properties variants - multiple variation of properties and aggregations. Depending on values - other properties or aggregation may be hidden/disabled.
23
+ variants = [];
24
+ // Class for child aggregations
25
+ childClass;
26
+ // Additional information text
27
+ additionalText;
28
+ // Aggregation actions
29
+ locations;
30
+ actions;
31
+ // Inactive
32
+ inactive;
33
+ // Original schema data
34
+ schema;
35
+ // Public creation form - (+) button would appear on UI and form will be opened
36
+ annotationCreationForms = [];
37
+ allowedAnnotationCreationForms = [];
38
+ schemaCreationForms = [];
39
+ formSchema;
40
+ sortableList;
41
+ sortableItem;
42
+ sortableReadonlyTooltip;
43
+ sortableConfigOnly;
44
+ order;
45
+ // Property description
46
+ description;
47
+ // Aggregation i18n key
48
+ i18nKey;
49
+ // Validation state
50
+ state = types_1.ValidationState.Valid;
51
+ messages;
52
+ value;
53
+ // Aggregation type - currently object or array
54
+ type = types_1.AggregationType.Object;
55
+ // Reference to parent aggregation
56
+ parent;
57
+ // Custom
58
+ custom = false;
59
+ isViewNode;
60
+ isTable = false;
61
+ pattern;
62
+ name;
63
+ union;
64
+ sortableCollection;
65
+ annotationNodeId;
66
+ dropUINodes;
67
+ // Is aggregation pending and not fully ready for edit
68
+ pending;
69
+ hidden;
70
+ // Aggregation's artifact type
71
+ artifactType;
72
+ // Is virtual node - means that node is not presented in source code and visible only on UI
73
+ virtual;
74
+ // Visualisation icon for aggregation
75
+ icon;
76
+ // Is aggregation atomic - it means that value is number/string/boolean
77
+ isAtomic;
78
+ /**
79
+ * Creates an instance of `ObjectAggregation`.
80
+ *
81
+ * @param data Optional aggregation data object used to initialize properties.
82
+ * @param schema Optional JSON schema fragment associated with this aggregation.
83
+ */
84
+ constructor(data, schema) {
85
+ if (data) {
86
+ this.aggregations = data.aggregations;
87
+ this.properties = data.properties;
88
+ }
89
+ if (schema) {
90
+ this.schema = schema;
91
+ }
92
+ }
93
+ /**
94
+ * Method adds aggregation object.
95
+ *
96
+ * @param name Name of aggregation.
97
+ * @param aggregation Aggregation to add.
98
+ * @param path Array of path to aggregation.
99
+ * @param order Order index.
100
+ * @param overwrite Overwrite existing aggregation.
101
+ * @returns Added aggregation.
102
+ */
103
+ addAggregation(name, aggregation, path, order, overwrite) {
104
+ if (this.aggregations[name] && !overwrite) {
105
+ return this.aggregations[name];
106
+ }
107
+ // Append new
108
+ aggregation.name = name;
109
+ if (order !== undefined && !isNaN(order)) {
110
+ // Looks like we need place aggregation in certain place - recalculate other aggregations
111
+ for (const key in this.aggregations) {
112
+ const existingOrder = this.aggregations[key].order;
113
+ if (existingOrder !== undefined && !isNaN(existingOrder) && existingOrder >= order) {
114
+ this.aggregations[key].order = existingOrder + 1;
115
+ }
116
+ }
117
+ aggregation.order = order;
118
+ }
119
+ else {
120
+ aggregation.order = Object.keys(this.aggregations).length;
121
+ }
122
+ // Define parent, but as not writable
123
+ Object.defineProperty(aggregation, 'parent', {
124
+ value: this,
125
+ writable: false
126
+ });
127
+ this.aggregations[name] = aggregation;
128
+ // Update path and apply path to childs
129
+ this.updatePath(this.aggregations[name], path);
130
+ return aggregation;
131
+ }
132
+ /**
133
+ * Method adds property object.
134
+ *
135
+ * @param name Name of property.
136
+ * @param schema Schema object of property.
137
+ * @returns Instance of new property.
138
+ */
139
+ addProperty(name, schema) {
140
+ if (exports.CUSTOM_EXTENSION_ANCHOR_PROPERTIES.includes(name)) {
141
+ schema = (0, utils_1.updateAnchorSchema)(this, schema);
142
+ }
143
+ const displayName = schema.displayName || (0, utils_1.startCase)(name);
144
+ const property = new PageEditProperty_1.PageEditProperty(schema, displayName);
145
+ this.properties[name] = property;
146
+ return property;
147
+ }
148
+ /**
149
+ * Public method returns display name of aggregation.
150
+ * Is used as display name in outline.
151
+ *
152
+ * @param i18nBundle I18n translation entries which should be looked up if display value persists.
153
+ * @returns Display name of aggregation with applied i18n.
154
+ */
155
+ getDisplayName(i18nBundle = {}) {
156
+ const nameResolutionMethods = [
157
+ // Read translatable value
158
+ () => {
159
+ const name = this.getRawDisplayName();
160
+ const i18nValue = (0, utils_1.resolveI18nValue)(name, i18nBundle);
161
+ if (i18nValue) {
162
+ return i18nValue;
163
+ }
164
+ return name;
165
+ },
166
+ // Use technical name resolution method - not every aggregations support it
167
+ this.getTechnicalName.bind(this),
168
+ // Use name property based on property key in schema path
169
+ () => {
170
+ const name = this.getFormattedName();
171
+ return name ? (0, utils_1.startCase)(name) : undefined;
172
+ }
173
+ ];
174
+ let displayName = '';
175
+ for (const resolutionMethod of nameResolutionMethods) {
176
+ displayName = resolutionMethod() || '';
177
+ if (displayName) {
178
+ break;
179
+ }
180
+ }
181
+ return displayName;
182
+ }
183
+ /**
184
+ * Retrieves the supported aggregation actions for this instance.
185
+ *
186
+ * @returns A list of supported aggregation actions.
187
+ */
188
+ getSupportedActions() {
189
+ const actions = [...(this.actions ?? [])];
190
+ if (this.locations?.length) {
191
+ actions.push(types_1.AggregationActions.OpenSource);
192
+ }
193
+ return actions;
194
+ }
195
+ /**
196
+ * Public method that returns keys from schema for an aggregation object.
197
+ *
198
+ * @returns Array of keys.
199
+ */
200
+ getKeys() {
201
+ if (this.schema?.keys) {
202
+ return this.schema.keys;
203
+ }
204
+ else {
205
+ return undefined;
206
+ }
207
+ }
208
+ /**
209
+ * Method returns value of passed schema key.
210
+ *
211
+ * @param name Name to search.
212
+ * @returns Value for passed key's name.
213
+ */
214
+ getValueOfSchemaKey(name) {
215
+ const keyObject = this.getKeys()?.find((schemaKey) => schemaKey.name === name);
216
+ return keyObject?.value;
217
+ }
218
+ /**
219
+ * Public method that returns technical name for an aggregation object.
220
+ * Currently it is used to display in tooltip.
221
+ *
222
+ * @returns technical name.
223
+ */
224
+ getTechnicalName() {
225
+ return undefined;
226
+ }
227
+ /**
228
+ * Protected method returns display name of aggregation without applying i18n translation.
229
+ *
230
+ * @returns Display name of aggregation.
231
+ */
232
+ getRawDisplayName() {
233
+ if (this.isViewNode) {
234
+ const description = this.formatTextForDisplay(this.description);
235
+ if (description) {
236
+ return description;
237
+ }
238
+ }
239
+ return this.formatTextForDisplay(this.schema?.title);
240
+ }
241
+ /**
242
+ * Method formats text for display.
243
+ * Trim is used to avoid whitespaces.
244
+ *
245
+ * @param text Text to format.
246
+ * @returns Formatted text.
247
+ */
248
+ formatTextForDisplay(text = '') {
249
+ return text.trim();
250
+ }
251
+ /**
252
+ * Method updates value of aggregatipn properties and child aggregations.
253
+ *
254
+ * @param data Data which should be used for value population.
255
+ */
256
+ updateValues(data) {
257
+ const propertyKeys = Object.keys(this.properties);
258
+ const aggregationKeys = Object.keys(this.aggregations);
259
+ if (data) {
260
+ for (const name in data) {
261
+ if (propertyKeys.includes(name)) {
262
+ this.properties[name].value = data[name];
263
+ }
264
+ if (aggregationKeys.includes(name)) {
265
+ this.aggregations[name].value = data[name];
266
+ }
267
+ }
268
+ }
269
+ }
270
+ /**
271
+ * Public method which recursively updates aggregation's properties with values from passed data object.
272
+ *
273
+ * @param data Data which should be used for value population.
274
+ * @param page Page config data.
275
+ * @param pageType Page type.
276
+ * @param path Aggregation path.
277
+ * @param annotations Page annotations.
278
+ * @param parser Model parser parameters.
279
+ */
280
+ updatePropertiesValues(data, page, pageType, path, annotations, parser) {
281
+ this.updateValues(data);
282
+ this.updateAnnotationData(annotations);
283
+ this.annotationCreationForms = this.getNativeNodeCreationForms(annotations);
284
+ // Go with recursion
285
+ for (const rootName in this.aggregations) {
286
+ const pathPart = this.type === types_1.AggregationType.Array ? parseInt(rootName, 10) : rootName;
287
+ const names = this.aggregations[rootName].union?.originalNames || [rootName];
288
+ for (const name of names) {
289
+ this.aggregations[rootName].updatePropertiesValues(data?.[name], page, pageType, path.concat([pathPart]), annotations, parser);
290
+ }
291
+ this.aggregations[rootName].onPropertiesUpdated();
292
+ }
293
+ if (this.isAtomic) {
294
+ this.handleAtomicObject(data, path);
295
+ }
296
+ }
297
+ /**
298
+ * Method which called when properties and aggregation data was applied and updated.
299
+ */
300
+ onPropertiesUpdated() {
301
+ // no-op
302
+ }
303
+ /**
304
+ * Refreshes internal data based on annotation node data.
305
+ *
306
+ * @param annotations
307
+ */
308
+ /**
309
+ * Refreshes internal data based on latest annotation node data.
310
+ *
311
+ * @param annotations
312
+ */
313
+ updateAnnotationData(annotations) {
314
+ const currentUINode = this.getCurrentUINode(annotations);
315
+ const directNode = currentUINode?.direct ? currentUINode.node : undefined;
316
+ this.setAllowedParents(annotations, directNode);
317
+ this.updateLocations(annotations, directNode);
318
+ // Handle readonly node
319
+ if (currentUINode?.node && !(0, annotations_1.isTooComplex)(currentUINode.node) && currentUINode.node.readonly) {
320
+ this.applyReadonlyAnnotationNode(currentUINode.node.readonlyTooltip);
321
+ }
322
+ // Check if annotation node resolution failed and we should disable sorting and deletion
323
+ if (!this.custom && this.sortableItem === types_1.SortingOptions.Enabled && !this.annotationNodeId) {
324
+ // Disable sorting - it is not custom extension node and annotation id resolution failed
325
+ this.sortableItem = types_1.SortingOptions.Readonly;
326
+ this.removeAction(types_1.AggregationActions.Delete);
327
+ }
328
+ }
329
+ /**
330
+ * Method checks if annotation contains allowedSubnodeTypes
331
+ * and sets disabled param for add action button.
332
+ *
333
+ * @param annotations Page annotations.
334
+ * @param uiNode Annotation node.
335
+ */
336
+ setAllowedParents(annotations, uiNode) {
337
+ if (uiNode) {
338
+ this.dropUINodes = uiNode?.allowedParentNodes;
339
+ }
340
+ }
341
+ /**
342
+ * Refreshes node locations based on the annotation node data.
343
+ *
344
+ * @param annotations All page annotation nodes.
345
+ * @param currentUINode Current annotation node.
346
+ */
347
+ updateLocations(annotations, currentUINode) {
348
+ this.locations = this.locations || [];
349
+ const currentLocationsCount = this.locations.length;
350
+ // Do not append annotation locations to macros nodes if macro node has location assigned
351
+ if (!currentUINode || (currentLocationsCount && this.isMacrosNode())) {
352
+ return;
353
+ }
354
+ const locations = (0, utils_1.getNodeLocations)(currentUINode);
355
+ if (locations.length > 0) {
356
+ if (currentLocationsCount) {
357
+ // Locations exists merge locations
358
+ for (const location of this.locations) {
359
+ if (locations.some((_location) => _location.fileUri !== location.fileUri)) {
360
+ locations.push(location);
361
+ }
362
+ }
363
+ }
364
+ this.locations = locations;
365
+ }
366
+ }
367
+ /**
368
+ * Method provides creation options based on its related annotation node.
369
+ *
370
+ * @param annotations Page annotations.
371
+ * @returns Array of creation forms.
372
+ */
373
+ getNativeNodeCreationForms(annotations) {
374
+ if (!this.name || !annotations) {
375
+ return [];
376
+ }
377
+ const annotationNodeId = this.annotationNodeId || this.getParentAnnotationNodeId();
378
+ if (!annotationNodeId) {
379
+ return this.getDefaultNativeCreationForms(annotations);
380
+ }
381
+ return [];
382
+ }
383
+ /**
384
+ * Method provides default creation options, when no matching annotation node exists.
385
+ *
386
+ * @param annotations Page annotations.
387
+ * @returns Array of creation forms.
388
+ */
389
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
390
+ getDefaultNativeCreationForms(annotations) {
391
+ return [];
392
+ }
393
+ /**
394
+ * Method recursively searches for parent with 'annotationNodeId' and returns 'annotationNodeId' as current context.
395
+ *
396
+ * @returns Annotation node id.
397
+ */
398
+ getParentAnnotationNodeId() {
399
+ let parent = this.parent;
400
+ while (parent) {
401
+ if (parent.annotationNodeId) {
402
+ return parent.annotationNodeId;
403
+ }
404
+ parent = parent ? parent.parent : undefined;
405
+ }
406
+ }
407
+ /**
408
+ * Method get valid object of properties.
409
+ * There can be case when aggregation can have several variants of property combination - we are returning currently valid, depending on entered values.
410
+ *
411
+ * @returns Object of properties.
412
+ */
413
+ getProperties() {
414
+ return this.properties;
415
+ }
416
+ /**
417
+ * Method returns copy of ObjectAggregation object.
418
+ *
419
+ * @param type Type of aggregation.
420
+ * @returns Copy of ObjectAggregation.
421
+ */
422
+ getCopy(type = ObjectAggregation) {
423
+ const cloneData = JSON.parse(JSON.stringify(this, (key, value) => {
424
+ if (key === 'parent') {
425
+ return undefined;
426
+ }
427
+ return value;
428
+ }));
429
+ const cloneObject = new type(cloneData);
430
+ this.createAggregations(cloneObject, type);
431
+ return new type(cloneObject);
432
+ }
433
+ /**
434
+ * Recursive method to use for copying aggregations objects.
435
+ *
436
+ * @param aggregation Original aggregation for copy.
437
+ * @param type Type of aggregation.
438
+ */
439
+ createAggregations(aggregation, type = ObjectAggregation) {
440
+ if (!aggregation.aggregations) {
441
+ return;
442
+ }
443
+ for (const name in aggregation.aggregations) {
444
+ aggregation.aggregations[name] = new type(aggregation.aggregations[name]);
445
+ this.createAggregations(aggregation.aggregations[name]);
446
+ }
447
+ if (aggregation.additionalProperties?.aggregations) {
448
+ aggregation.additionalProperties = new type(aggregation.additionalProperties);
449
+ }
450
+ }
451
+ /**
452
+ * Method sorts aggregation by 'order' property.
453
+ *
454
+ * @param name1 Aggregation name.
455
+ * @param name2 Aggregation name.
456
+ * @returns Sort result.
457
+ */
458
+ aggregationOrderSorter(name1, name2) {
459
+ // Ordering when order is represented in aggregation
460
+ const order1 = this.aggregations[name1] ? this.aggregations[name1].order || -1 : -1;
461
+ const order2 = this.aggregations[name2] ? this.aggregations[name2].order || -1 : -1;
462
+ if (order1 === order2) {
463
+ return 0;
464
+ }
465
+ return order1 > order2 ? 1 : -1;
466
+ }
467
+ /**
468
+ * Method returns array of ordered aggregation keys/names.
469
+ *
470
+ * @param viewNodesOnly Return only aggregations for view.
471
+ * @param sortBy Sorting type. Currently aggregations can be sorted by 'ViewNode' to move visible nodes to top.
472
+ * @returns Array of aggregations keys/names.
473
+ */
474
+ getAggregationKeys(viewNodesOnly = false, sortBy) {
475
+ let aggregationKeys = Object.keys(this.aggregations).sort(this.aggregationOrderSorter.bind(this));
476
+ if (!this.sortableList) {
477
+ // Like 'header', 'filter' - render on top if aggregations are not sortable in UI.
478
+ aggregationKeys = aggregationKeys.sort((obj1, obj2) => {
479
+ // index of first priority prop
480
+ const indexOfFirstRoot = ROOT_SORTING_NAMES.top.indexOf(obj1);
481
+ // index of second priority prop
482
+ const indexOfSecondRoot = ROOT_SORTING_NAMES.top.indexOf(obj2);
483
+ if (indexOfFirstRoot !== -1 && indexOfSecondRoot !== -1 && indexOfFirstRoot > indexOfSecondRoot) {
484
+ return 1;
485
+ }
486
+ if (indexOfFirstRoot !== -1) {
487
+ return -1;
488
+ }
489
+ return indexOfSecondRoot !== -1 ? 1 : 0;
490
+ });
491
+ }
492
+ if (viewNodesOnly) {
493
+ aggregationKeys = aggregationKeys.filter((key) => this.aggregations[key].isViewNode && !this.aggregations[key].hidden);
494
+ }
495
+ if (sortBy === types_1.AggregationSortBy.ViewNode) {
496
+ aggregationKeys = aggregationKeys.sort(this.getViewNodeSorter.bind(this));
497
+ }
498
+ return aggregationKeys;
499
+ }
500
+ /**
501
+ * Aggregation key sorter by view node.
502
+ * Sorter also sorts by aggregation key in scope of save view node group.
503
+ *
504
+ * @param key1 First aggregation key.
505
+ * @param key2 Second aggregation key.
506
+ * @returns Sorter result.
507
+ */
508
+ getViewNodeSorter(key1, key2) {
509
+ const isViewNode1 = this.aggregations[key1].isViewNode;
510
+ const isViewNode2 = this.aggregations[key2].isViewNode;
511
+ if (isViewNode1 === isViewNode2 && !isViewNode1) {
512
+ // If view node is same, then sort by key
513
+ if (key1 === key2) {
514
+ return 0;
515
+ }
516
+ else if (key1 > key2) {
517
+ return 1;
518
+ }
519
+ else {
520
+ return -1;
521
+ }
522
+ }
523
+ // sort by view node
524
+ if (this.aggregations[key1].isViewNode === this.aggregations[key2].isViewNode) {
525
+ return 0;
526
+ }
527
+ else if (this.aggregations[key1].isViewNode) {
528
+ return 1;
529
+ }
530
+ else {
531
+ return -1;
532
+ }
533
+ }
534
+ /**
535
+ * Method updates path recursively.
536
+ *
537
+ * @param aggregation Aggregation to update.
538
+ * @param path Current path.
539
+ */
540
+ updatePath(aggregation, path) {
541
+ aggregation.setPath(path);
542
+ if (aggregation.aggregations) {
543
+ for (const key in aggregation.aggregations) {
544
+ this.updatePath(aggregation.aggregations[key], path.concat([key]));
545
+ }
546
+ }
547
+ }
548
+ /**
549
+ * Set method to store path of aggregation.
550
+ *
551
+ * @param path Path array.
552
+ */
553
+ setPath(path) {
554
+ this.path = path;
555
+ }
556
+ /**
557
+ * Method returns maximal order by looping through all properties.
558
+ *
559
+ * @returns Maximal property order index.
560
+ */
561
+ getMaxOrder() {
562
+ let maxOrder = 0;
563
+ for (const key in this.aggregations) {
564
+ const order = this.aggregations[key].order || 0;
565
+ if (maxOrder < order) {
566
+ maxOrder = order;
567
+ }
568
+ }
569
+ return maxOrder;
570
+ }
571
+ /**
572
+ * Traverses up the parent hierarchy to find the first matching parent of the specified aggregation type.
573
+ *
574
+ * @param matchType The constructor of the aggregation type to match against.
575
+ * @returns The first matching parent if found.
576
+ */
577
+ findMatchingParent(matchType = ObjectAggregation) {
578
+ let parent = this.parent;
579
+ while (parent) {
580
+ if (parent instanceof matchType) {
581
+ return parent;
582
+ }
583
+ parent = parent ? parent.parent : undefined;
584
+ }
585
+ }
586
+ /**
587
+ * Method enables union handling by adding setting union name and passing original name of aggregation.
588
+ *
589
+ * @param name Union name for aggregation.
590
+ * @param originalName Original name of aggregation.
591
+ */
592
+ addUnionName(name, originalName) {
593
+ const originalNames = this.union?.originalNames || [];
594
+ if (!originalNames.includes(originalName)) {
595
+ originalNames.push(originalName);
596
+ }
597
+ this.union = {
598
+ name,
599
+ originalNames
600
+ };
601
+ }
602
+ /**
603
+ * Protected method which returns name with additional formatting if it is unnecessary.
604
+ * Default logic does not apply any additional formatting, but it allows to overwrite such method and provide additional logic specific to each aggregation.
605
+ *
606
+ * @returns Name of aggregation.
607
+ */
608
+ getFormattedName() {
609
+ return this.name;
610
+ }
611
+ /**
612
+ * Method returns associated annotation UI Node for aggregation.
613
+ *
614
+ * @param annotations Annotations data.
615
+ * @returns Associated annotation UI Node.
616
+ */
617
+ getCurrentUINode(annotations) {
618
+ if (this.name && annotations) {
619
+ const annotationNodeId = this.annotationNodeId || this.getParentAnnotationNodeId();
620
+ if (annotationNodeId) {
621
+ const currentUINode = (0, utils_1.getAnnotationNodeById)(annotations, annotationNodeId);
622
+ if (currentUINode) {
623
+ return {
624
+ node: currentUINode,
625
+ // If it resolved directly or by first non-virtual parent
626
+ direct: !!this.annotationNodeId
627
+ };
628
+ }
629
+ }
630
+ }
631
+ }
632
+ /**
633
+ * Method handles readonly annotation node by disabling actions and DnD.
634
+ *
635
+ * @param readonlyTooltip Tooltip text for readonly mode.
636
+ */
637
+ applyReadonlyAnnotationNode(readonlyTooltip) {
638
+ // Method to disable actions
639
+ const disableActions = (actions) => {
640
+ for (let i = 0; i < actions.length; i++) {
641
+ let action = actions[i];
642
+ if (typeof action === 'string') {
643
+ // Simple string - make object which allow to disable action
644
+ actions[i] = action = {
645
+ type: action
646
+ };
647
+ }
648
+ action.disabled = true;
649
+ action.title = readonlyTooltip;
650
+ }
651
+ };
652
+ // Method to disable reordering
653
+ const disableReordering = (aggregation) => {
654
+ aggregation.sortableItem = types_1.SortingOptions.Readonly;
655
+ if (readonlyTooltip) {
656
+ aggregation.sortableReadonlyTooltip = readonlyTooltip;
657
+ }
658
+ };
659
+ for (const key in this.aggregations) {
660
+ const aggregation = this.aggregations[key];
661
+ if (aggregation.actions && !aggregation.custom) {
662
+ disableActions(aggregation.actions);
663
+ }
664
+ if (aggregation.sortableItem === types_1.SortingOptions.Enabled) {
665
+ disableReordering(aggregation);
666
+ }
667
+ }
668
+ if (this.actions) {
669
+ disableActions(this.actions);
670
+ }
671
+ if (this.sortableItem === types_1.SortingOptions.Enabled) {
672
+ disableReordering(this);
673
+ }
674
+ }
675
+ /**
676
+ * Method removes passed action from visible actions.
677
+ *
678
+ * @param action Action to remove.
679
+ */
680
+ removeAction(action) {
681
+ if (this.actions) {
682
+ const actionIndex = this.actions.indexOf(action);
683
+ if (actionIndex !== -1) {
684
+ this.actions.splice(actionIndex, 1);
685
+ }
686
+ }
687
+ }
688
+ /**
689
+ * Method to stringify node id to string to match 'allowedParents' properties format.
690
+ *
691
+ * @param annotationNodeId - Annotation node id.
692
+ * @returns Formatted node id.
693
+ */
694
+ nodeIdToString(annotationNodeId) {
695
+ return `[${annotationNodeId.join(',')}]`;
696
+ }
697
+ /**
698
+ * Method to find all droppable collections inside aggregation by passed collection name.
699
+ *
700
+ * @param aggregation Current aggregation to check.
701
+ * @param collectionName Collection name to check.
702
+ * @returns Found droppable collections.
703
+ */
704
+ findDropableCollectionsByCollection(aggregation, collectionName) {
705
+ const result = [];
706
+ if (aggregation.sortableList && aggregation.sortableCollection === collectionName) {
707
+ result.push(aggregation);
708
+ }
709
+ else {
710
+ // Continue looking inside
711
+ for (const id in aggregation.aggregations) {
712
+ const childAggregation = aggregation.aggregations[id];
713
+ const foundAggregations = this.findDropableCollectionsByCollection(childAggregation, collectionName);
714
+ result.push(...foundAggregations);
715
+ }
716
+ }
717
+ return result;
718
+ }
719
+ /**
720
+ * Method returns allowed drop ranges for passed source aggregation.
721
+ *
722
+ * @param source Source aggregation.
723
+ * @returns Allowed drop ranges for passed source aggregation.
724
+ */
725
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
726
+ getAllowedDropRange(source) {
727
+ return undefined;
728
+ }
729
+ /**
730
+ * Method to find allowed drop parents for aggregation.
731
+ *
732
+ * @param source Source aggregation.
733
+ * @param aggregation Aggregation to search in.
734
+ * @returns Found allowed drop parents.
735
+ */
736
+ findAllowedDropAggregations(source, aggregation = this) {
737
+ const { dropUINodes = {}, sortableCollection } = source;
738
+ const result = [];
739
+ if (aggregation.annotationNodeId && dropUINodes[this.nodeIdToString(aggregation.annotationNodeId)]) {
740
+ const droppableAggregations = this.findDropableCollectionsByCollection(aggregation, sortableCollection);
741
+ // Root aggregation found - find dropable containers
742
+ result.push(...droppableAggregations.map((droppableAggregation) => {
743
+ const range = droppableAggregation.getAllowedDropRange(source);
744
+ return { path: droppableAggregation.path, range };
745
+ }));
746
+ }
747
+ for (const id in aggregation.aggregations) {
748
+ const childAggregation = aggregation.aggregations[id];
749
+ const foundAggregations = this.findAllowedDropAggregations(source, childAggregation);
750
+ result.push(...foundAggregations);
751
+ }
752
+ return result;
753
+ }
754
+ /**
755
+ * Method returns whether aggregation node has macros metadata.
756
+ *
757
+ * @returns Whether aggregation node is macros node.
758
+ */
759
+ isMacrosNode() {
760
+ return !!this.schema?.metadata;
761
+ }
762
+ /**
763
+ * Method converts property to aggregation.
764
+ *
765
+ * @param key Property key/index in object.
766
+ * @param path Aggregation path.
767
+ */
768
+ convertAtomicPropertyToAggregation(key, path) {
769
+ const aggregation = new ObjectAggregation();
770
+ const property = key.toString();
771
+ if (this.properties[key]) {
772
+ aggregation.properties[property] = this.properties[key];
773
+ aggregation.properties[property].isAtomic = true;
774
+ }
775
+ this.addAggregation(key.toString(), aggregation, path.concat(key));
776
+ }
777
+ /**
778
+ * Method handles atomic aggregation by converting properties to aggregation.
779
+ *
780
+ * @param data Aggregation source data.
781
+ * @param path Aggregation path.
782
+ */
783
+ handleAtomicObject(data, path) {
784
+ if (typeof data !== 'object') {
785
+ return;
786
+ }
787
+ // Special handling for atomic arrays and objects - swap properties with aggregation
788
+ if (Array.isArray(data)) {
789
+ for (let i = 0; i < data.length; i++) {
790
+ this.convertAtomicPropertyToAggregation(i, path);
791
+ }
792
+ }
793
+ else {
794
+ for (const property in data) {
795
+ this.convertAtomicPropertyToAggregation(property, path);
796
+ }
797
+ }
798
+ this.properties = {};
799
+ }
800
+ }
801
+ exports.ObjectAggregation = ObjectAggregation;
802
+ //# sourceMappingURL=ObjectAggregation.js.map