@sankhyalabs/sankhyablocks 3.6.1 → 4.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (172) hide show
  1. package/dist/cjs/ConfigStorage-967176bb.js +190 -0
  2. package/dist/cjs/{ConfigStorage-cfac5a0b.js → DataFetcher-bceeaf2d.js} +0 -383
  3. package/dist/cjs/SnkFormConfigManager-0010f570.js +133 -0
  4. package/dist/cjs/{SnkMessageBuilder-5854eedd.js → SnkMessageBuilder-196c6528.js} +11 -10
  5. package/dist/cjs/{constants-8f3504ec.js → constants-450c0bb7.js} +5 -11
  6. package/dist/cjs/form-config-fetcher-f57babd9.js +244 -0
  7. package/dist/cjs/loader.cjs.js +1 -1
  8. package/dist/cjs/sankhyablocks.cjs.js +1 -1
  9. package/dist/cjs/snk-application.cjs.entry.js +77 -110
  10. package/dist/cjs/snk-config-options.cjs.entry.js +1 -1
  11. package/dist/cjs/snk-configurator_6.cjs.entry.js +1033 -0
  12. package/dist/cjs/snk-crud.cjs.entry.js +15 -25
  13. package/dist/cjs/{snk-data-exporter_8.cjs.entry.js → snk-data-exporter_11.cjs.entry.js} +319 -10
  14. package/dist/cjs/snk-form-config.cjs.entry.js +75 -48
  15. package/dist/cjs/snk-form.cjs.entry.js +10 -174
  16. package/dist/cjs/snk-guides-viewer-14a11f80.js +363 -0
  17. package/dist/cjs/snk-guides-viewer.cjs.entry.js +20 -0
  18. package/dist/cjs/snk-tab-config.cjs.entry.js +1 -1
  19. package/dist/cjs/{index-fc7ca86c.js → taskbar-elements-d444d6a5.js} +110 -0
  20. package/dist/collection/collection-manifest.json +4 -0
  21. package/dist/collection/components/snk-application/snk-application.js +61 -217
  22. package/dist/collection/components/snk-configurator/snk-configurator.js +32 -19
  23. package/dist/collection/components/snk-crud/snk-crud.js +16 -27
  24. package/dist/collection/components/snk-crud/subcomponents/CardFormResizeObserver.js +26 -0
  25. package/dist/collection/components/snk-crud/subcomponents/snk-detail-view.css +20 -0
  26. package/dist/collection/components/snk-crud/subcomponents/snk-detail-view.js +472 -0
  27. package/dist/collection/components/snk-crud/subcomponents/snk-form-summary.css +37 -0
  28. package/dist/collection/components/snk-crud/subcomponents/snk-form-summary.js +91 -0
  29. package/dist/collection/components/snk-crud/subcomponents/snk-form-view.css +52 -0
  30. package/dist/collection/components/snk-crud/subcomponents/snk-form-view.js +336 -0
  31. package/dist/collection/components/snk-crud/subcomponents/snk-guides-viewer.css +91 -0
  32. package/dist/collection/components/snk-crud/subcomponents/snk-guides-viewer.js +591 -0
  33. package/dist/collection/components/snk-data-unit/snk-data-unit.css +1 -0
  34. package/dist/collection/components/snk-data-unit/snk-data-unit.js +35 -23
  35. package/dist/collection/components/snk-filter-bar/snk-filter-bar.js +1 -1
  36. package/dist/collection/components/snk-form/SnkFormConfigManager.js +128 -0
  37. package/dist/collection/components/snk-form/snk-form.css +4 -31
  38. package/dist/collection/components/snk-form/snk-form.js +10 -244
  39. package/dist/collection/components/snk-form/subcomponents/snk-config-options/snk-config-options.js +1 -1
  40. package/dist/collection/components/snk-form/subcomponents/snk-field-config/snk-field-config.js +1 -1
  41. package/dist/collection/components/snk-form/subcomponents/snk-form-config/snk-form-config.js +78 -71
  42. package/dist/collection/components/snk-grid/snk-grid.css +8 -0
  43. package/dist/collection/components/snk-grid/snk-grid.js +18 -13
  44. package/dist/collection/components/snk-grid/subcomponents/snk-grid-config/snk-grid-config.js +4 -2
  45. package/dist/collection/lib/configs/ConfigStorage.js +3 -0
  46. package/dist/collection/lib/http/data-fetcher/fetchers/dataunit-fetcher.js +38 -10
  47. package/dist/collection/lib/http/data-fetcher/fetchers/form-config-fetcher.js +48 -10
  48. package/dist/collection/lib/index.js +1 -0
  49. package/dist/collection/lib/message/SnkMessageBuilder.js +3 -2
  50. package/dist/collection/lib/message/resources/snk-crud.msg.js +10 -0
  51. package/dist/collection/lib/message/resources/snk-form.msg.js +0 -9
  52. package/dist/collection/lib/utils/constants.js +6 -10
  53. package/dist/components/ConfigStorage.js +6 -202
  54. package/dist/components/SnkFormConfigManager.js +131 -0
  55. package/dist/components/SnkMessageBuilder.js +11 -10
  56. package/dist/components/constants.js +5 -10
  57. package/dist/components/form-config-fetcher.js +241 -0
  58. package/dist/components/index.d.ts +4 -0
  59. package/dist/components/index.js +4 -0
  60. package/dist/components/snk-application2.js +54 -94
  61. package/dist/components/snk-configurator2.js +7 -9
  62. package/dist/components/snk-crud.js +65 -52
  63. package/dist/components/snk-data-unit.js +1 -375
  64. package/dist/{esm/snk-data-unit.entry.js → components/snk-data-unit2.js} +69 -33
  65. package/dist/components/snk-detail-view.d.ts +11 -0
  66. package/dist/components/snk-detail-view.js +6 -0
  67. package/dist/components/snk-detail-view2.js +736 -0
  68. package/dist/components/snk-filter-bar2.js +1 -1
  69. package/dist/components/snk-form-config2.js +72 -47
  70. package/dist/components/snk-form-summary.d.ts +11 -0
  71. package/dist/components/snk-form-summary.js +6 -0
  72. package/dist/components/snk-form-summary2.js +75 -0
  73. package/dist/components/snk-form-view.d.ts +11 -0
  74. package/dist/components/snk-form-view.js +6 -0
  75. package/dist/components/snk-form-view2.js +123 -0
  76. package/dist/components/snk-form.js +119 -1
  77. package/dist/components/snk-grid-config2.js +4 -2
  78. package/dist/components/snk-grid2.js +66 -16
  79. package/dist/components/snk-guides-viewer.d.ts +11 -0
  80. package/dist/components/snk-guides-viewer.js +6 -0
  81. package/dist/esm/ConfigStorage-13b5af9f.js +187 -0
  82. package/dist/esm/{ConfigStorage-77bd9902.js → DataFetcher-8700a770.js} +2 -381
  83. package/dist/esm/SnkFormConfigManager-183dcdcb.js +131 -0
  84. package/dist/esm/{SnkMessageBuilder-a266565d.js → SnkMessageBuilder-acb1109f.js} +11 -10
  85. package/dist/esm/{constants-965d7a7f.js → constants-e12d550a.js} +5 -10
  86. package/dist/esm/form-config-fetcher-73f3c594.js +241 -0
  87. package/dist/esm/loader.js +1 -1
  88. package/dist/esm/sankhyablocks.js +1 -1
  89. package/dist/esm/snk-application.entry.js +55 -88
  90. package/dist/esm/snk-config-options.entry.js +1 -1
  91. package/dist/esm/snk-configurator_6.entry.js +1024 -0
  92. package/dist/esm/snk-crud.entry.js +15 -25
  93. package/dist/esm/{snk-data-exporter_8.entry.js → snk-data-exporter_11.entry.js} +315 -9
  94. package/dist/esm/snk-form-config.entry.js +73 -46
  95. package/dist/esm/snk-form.entry.js +11 -175
  96. package/dist/esm/snk-guides-viewer-6e136f09.js +360 -0
  97. package/dist/esm/snk-guides-viewer.entry.js +12 -0
  98. package/dist/esm/snk-tab-config.entry.js +1 -1
  99. package/dist/esm/{index-e467ade5.js → taskbar-elements-d055c168.js} +110 -2
  100. package/dist/sankhyablocks/p-0ac99531.js +1 -0
  101. package/dist/sankhyablocks/p-0f7295d0.entry.js +1 -0
  102. package/dist/sankhyablocks/p-1fe0bb83.entry.js +1 -0
  103. package/dist/sankhyablocks/{p-93c92b97.entry.js → p-36263907.entry.js} +1 -1
  104. package/dist/sankhyablocks/p-498e6ec1.entry.js +1 -0
  105. package/dist/sankhyablocks/p-4a35cce8.js +1 -0
  106. package/dist/sankhyablocks/p-511fceba.js +26 -0
  107. package/dist/sankhyablocks/p-a57173c2.js +1 -0
  108. package/dist/sankhyablocks/p-b368e34b.entry.js +1 -0
  109. package/dist/sankhyablocks/p-c311e56b.js +1 -0
  110. package/dist/sankhyablocks/p-ca2049dd.js +1 -0
  111. package/dist/sankhyablocks/p-d3ad5545.entry.js +88 -0
  112. package/dist/sankhyablocks/{p-41f61cc3.entry.js → p-d4e7dcdf.entry.js} +1 -1
  113. package/dist/sankhyablocks/p-e8a1a8e3.entry.js +1 -0
  114. package/dist/sankhyablocks/{p-583bd288.js → p-eaafcafb.js} +1 -1
  115. package/dist/sankhyablocks/p-ebca169e.js +1 -0
  116. package/dist/sankhyablocks/p-f39608a9.entry.js +1 -0
  117. package/dist/sankhyablocks/sankhyablocks.esm.js +1 -1
  118. package/dist/types/components/snk-application/snk-application.d.ts +8 -37
  119. package/dist/types/components/snk-configurator/snk-configurator.d.ts +4 -3
  120. package/dist/types/components/snk-crud/snk-crud.d.ts +6 -7
  121. package/dist/types/components/snk-crud/subcomponents/CardFormResizeObserver.d.ts +1 -0
  122. package/dist/types/components/snk-crud/subcomponents/snk-detail-view.d.ts +90 -0
  123. package/dist/types/components/snk-crud/subcomponents/snk-form-summary.d.ts +22 -0
  124. package/dist/types/components/snk-crud/subcomponents/snk-form-view.d.ts +68 -0
  125. package/dist/types/components/snk-crud/subcomponents/snk-guides-viewer.d.ts +113 -0
  126. package/dist/types/components/snk-data-unit/snk-data-unit.d.ts +2 -0
  127. package/dist/types/components/snk-form/SnkFormConfigManager.d.ts +23 -0
  128. package/dist/types/components/snk-form/snk-form.d.ts +3 -42
  129. package/dist/types/components/snk-form/subcomponents/snk-config-options/snk-config-options.d.ts +1 -1
  130. package/dist/types/components/snk-form/subcomponents/snk-field-config/snk-field-config.d.ts +1 -1
  131. package/dist/types/components/snk-form/subcomponents/snk-form-config/snk-form-config.d.ts +6 -7
  132. package/dist/types/components/snk-grid/snk-grid.d.ts +3 -2
  133. package/dist/types/components.d.ts +368 -73
  134. package/dist/types/lib/configs/ConfigStorage.d.ts +2 -1
  135. package/dist/types/lib/http/data-fetcher/fetchers/form-config-fetcher.d.ts +2 -1
  136. package/dist/types/lib/index.d.ts +1 -0
  137. package/dist/types/lib/message/resources/snk-crud.msg.d.ts +2 -0
  138. package/dist/types/lib/message/resources/snk-form.msg.d.ts +0 -1
  139. package/dist/types/lib/utils/constants.d.ts +4 -10
  140. package/package.json +5 -5
  141. package/react/components.d.ts +4 -0
  142. package/react/components.js +4 -0
  143. package/react/components.js.map +1 -1
  144. package/dist/cjs/snk-configurator_3.cjs.entry.js +0 -400
  145. package/dist/cjs/snk-data-unit.cjs.entry.js +0 -357
  146. package/dist/cjs/snk-exporter-email-sender.cjs.entry.js +0 -132
  147. package/dist/cjs/snk-filter-detail.cjs.entry.js +0 -137
  148. package/dist/cjs/taskbar-elements-5e87cf44.js +0 -115
  149. package/dist/cjs/taskbar-processor-6f3d2a75.js +0 -49
  150. package/dist/collection/lib/http/data-fetcher/fetchers/default-values-fetcher.js +0 -17
  151. package/dist/components/snk-form2.js +0 -310
  152. package/dist/components/taskbar-processor.js +0 -47
  153. package/dist/esm/snk-configurator_3.entry.js +0 -394
  154. package/dist/esm/snk-exporter-email-sender.entry.js +0 -128
  155. package/dist/esm/snk-filter-detail.entry.js +0 -133
  156. package/dist/esm/taskbar-elements-8400dbe7.js +0 -112
  157. package/dist/esm/taskbar-processor-c2a99aba.js +0 -47
  158. package/dist/sankhyablocks/p-013bb019.entry.js +0 -1
  159. package/dist/sankhyablocks/p-032e1308.entry.js +0 -1
  160. package/dist/sankhyablocks/p-0981d63d.entry.js +0 -83
  161. package/dist/sankhyablocks/p-22e44b9d.entry.js +0 -1
  162. package/dist/sankhyablocks/p-43c135c4.entry.js +0 -1
  163. package/dist/sankhyablocks/p-5a3e0eb6.js +0 -1
  164. package/dist/sankhyablocks/p-705b7671.entry.js +0 -1
  165. package/dist/sankhyablocks/p-7f195b37.entry.js +0 -1
  166. package/dist/sankhyablocks/p-93c271e2.js +0 -1
  167. package/dist/sankhyablocks/p-98f7f796.js +0 -1
  168. package/dist/sankhyablocks/p-afba9bbe.entry.js +0 -1
  169. package/dist/sankhyablocks/p-b4093344.js +0 -1
  170. package/dist/sankhyablocks/p-bbd0cf7a.js +0 -26
  171. package/dist/sankhyablocks/p-db6d6b59.entry.js +0 -1
  172. package/dist/types/lib/http/data-fetcher/fetchers/default-values-fetcher.d.ts +0 -4
@@ -0,0 +1,190 @@
1
+ 'use strict';
2
+
3
+ const core = require('@sankhyalabs/core');
4
+ const formConfigFetcher = require('./form-config-fetcher-f57babd9.js');
5
+
6
+ class GridConfigFetcher extends formConfigFetcher.ResourceFetcher {
7
+ constructor() {
8
+ super(...arguments);
9
+ this.GRID_CONFIG_VERSION = "V3:";
10
+ }
11
+ getConfig(gridName, resourceID) {
12
+ const completePath = this.getPath(resourceID, gridName);
13
+ return new Promise((resolve, reject) => {
14
+ this.loadResource(completePath)
15
+ .then(loadedResource => {
16
+ let config = undefined;
17
+ if (loadedResource) {
18
+ config = JSON.parse(loadedResource);
19
+ }
20
+ resolve(config);
21
+ }).catch((error) => {
22
+ reject(error);
23
+ });
24
+ });
25
+ }
26
+ saveConfig(config, gridName, resourceID) {
27
+ const completePath = this.getPath(resourceID, gridName);
28
+ return new Promise((resolve, reject) => {
29
+ this.saveResource(config, completePath)
30
+ .then((resp) => {
31
+ resolve(JSON.parse(resp.resource));
32
+ })
33
+ .catch((error) => {
34
+ reject(error);
35
+ });
36
+ });
37
+ }
38
+ getPath(resourceID, name) {
39
+ if (name) {
40
+ return `cfg://grid/${this.GRID_CONFIG_VERSION}${resourceID}/${name}`;
41
+ }
42
+ return `cfg://grid/${this.GRID_CONFIG_VERSION}${resourceID}`;
43
+ }
44
+ }
45
+
46
+ function normalizeValue(value) {
47
+ if (value == undefined) {
48
+ return value;
49
+ }
50
+ if (value instanceof Date) {
51
+ return value.toISOString();
52
+ }
53
+ if (typeof value === "object") {
54
+ if (value instanceof Array) {
55
+ return value.map(item => normalizeValue(item));
56
+ }
57
+ else {
58
+ const normalized = Object.assign({}, value);
59
+ Object.keys(value).forEach(prop => {
60
+ if (value[prop]) {
61
+ normalized[prop] = normalizeValue(value[prop]);
62
+ }
63
+ else {
64
+ delete normalized[prop];
65
+ }
66
+ });
67
+ return normalized;
68
+ }
69
+ }
70
+ return value;
71
+ }
72
+ class FilterBarConfigFetcher extends formConfigFetcher.ResourceFetcher {
73
+ saveConfig(items, resourceID, configName) {
74
+ const state = items.map(item => {
75
+ const { id, value, fixed, visible } = item;
76
+ const stateItem = { id };
77
+ if (value) {
78
+ stateItem["value"] = normalizeValue(value);
79
+ }
80
+ if (fixed) {
81
+ stateItem["fixed"] = fixed;
82
+ }
83
+ if (visible) {
84
+ stateItem["visible"] = true;
85
+ }
86
+ return stateItem;
87
+ });
88
+ return this.saveResource(state, this.getPath(resourceID, configName));
89
+ }
90
+ getConfig(resourceID, configName) {
91
+ return new Promise((accept, reject) => {
92
+ this.loadResource(this.getPath(resourceID, configName))
93
+ .then((configAsString) => {
94
+ let fieldsList;
95
+ if (configAsString) {
96
+ const filterBarConfig = JSON.parse(configAsString);
97
+ fieldsList = filterBarConfig.items;
98
+ }
99
+ accept(fieldsList || []);
100
+ })
101
+ .catch((error) => {
102
+ reject(error);
103
+ });
104
+ });
105
+ }
106
+ getPath(resourceID, name) {
107
+ if (name) {
108
+ return `cfg://filter/FilterBarState:${resourceID}/${name}`;
109
+ }
110
+ return `cfg://filter/FilterBarState:${resourceID}`;
111
+ }
112
+ }
113
+
114
+ const CONFIG_SOURCE = {
115
+ form: "form",
116
+ grid: "grid",
117
+ filterBar: "filterBar"
118
+ };
119
+ class ConfigStorage {
120
+ static async get() {
121
+ if (!ConfigStorage.instance) {
122
+ const application = core.ApplicationContext.getContextValue("__SNK__APPLICATION__");
123
+ if (application != undefined) {
124
+ const configName = application.configName;
125
+ const resourceID = await application.getResourceID();
126
+ ConfigStorage.instance = new ConfigStorage();
127
+ ConfigStorage.resourceID = resourceID;
128
+ ConfigStorage.instance.loadFilterBarConfig(configName);
129
+ ConfigStorage.instance.loadFormConfig(configName);
130
+ ConfigStorage.instance.loadGridConfig(configName);
131
+ }
132
+ }
133
+ return this.instance;
134
+ }
135
+ async loadFilterBarConfig(name) {
136
+ const cacheID = ConfigStorage.buildCacheID(name, CONFIG_SOURCE.filterBar);
137
+ if (!ConfigStorage.configById.has(cacheID)) {
138
+ ConfigStorage.configById.set(cacheID, ConfigStorage.filterBarConfigFetcher.getConfig(ConfigStorage.resourceID, name));
139
+ }
140
+ return ConfigStorage.configById.get(cacheID);
141
+ }
142
+ async loadFormConfig(name) {
143
+ const cacheID = ConfigStorage.buildCacheID(name, CONFIG_SOURCE.form);
144
+ if (!ConfigStorage.configById.has(cacheID)) {
145
+ ConfigStorage.configById.set(cacheID, ConfigStorage.formConfigFetcher.loadFormConfig(name, ConfigStorage.resourceID));
146
+ }
147
+ return ConfigStorage.configById.get(cacheID);
148
+ }
149
+ async loadGridConfig(name) {
150
+ const cacheID = ConfigStorage.buildCacheID(name, CONFIG_SOURCE.grid);
151
+ if (!ConfigStorage.configById.has(cacheID)) {
152
+ ConfigStorage.configById.set(cacheID, ConfigStorage.gridConfigFetcher.getConfig(name, ConfigStorage.resourceID));
153
+ }
154
+ return ConfigStorage.configById.get(cacheID);
155
+ }
156
+ static async saveFilterBarConfig(config, name) {
157
+ const cacheID = this.buildCacheID(name, CONFIG_SOURCE.filterBar);
158
+ this.configById.delete(cacheID);
159
+ return this.filterBarConfigFetcher.saveConfig(config, this.resourceID, name);
160
+ }
161
+ static async saveFormConfig(config, name) {
162
+ const cacheID = this.buildCacheID(name, CONFIG_SOURCE.form);
163
+ this.configById.delete(cacheID);
164
+ return this.formConfigFetcher.saveConfig(config, name, this.resourceID);
165
+ }
166
+ static async saveCardState(config, name) {
167
+ return this.formConfigFetcher.saveCardState(config, name, this.resourceID);
168
+ }
169
+ static async saveGridConfig(config, name) {
170
+ if (config == undefined) {
171
+ return;
172
+ }
173
+ const cacheID = this.buildCacheID(name, CONFIG_SOURCE.grid);
174
+ this.configById.delete(cacheID);
175
+ return this.gridConfigFetcher.saveConfig(config, name, this.resourceID);
176
+ }
177
+ static buildCacheID(name, source) {
178
+ if (name == undefined) {
179
+ return `req_${source}_${this.resourceID}`;
180
+ }
181
+ return `req_${source}_${name}_${this.resourceID}`;
182
+ }
183
+ }
184
+ ConfigStorage.configById = new Map();
185
+ ConfigStorage.filterBarConfigFetcher = new FilterBarConfigFetcher();
186
+ ConfigStorage.formConfigFetcher = new formConfigFetcher.FormConfigFetcher();
187
+ ConfigStorage.gridConfigFetcher = new GridConfigFetcher();
188
+
189
+ exports.ConfigStorage = ConfigStorage;
190
+ exports.GridConfigFetcher = GridConfigFetcher;
@@ -6754,389 +6754,6 @@ class WaitingRequest {
6754
6754
  }
6755
6755
  }
6756
6756
 
6757
- class ResourceFetcher {
6758
- constructor() {
6759
- this.templateByQuery = new Map();
6760
- this.buldTemplates();
6761
- }
6762
- buldTemplates() {
6763
- this.templateByQuery.set("fetchResource", dist.gql `query($name: String!) {
6764
- $queryAlias$: fetchResource(name: $name){
6765
- resource
6766
- }
6767
- }`);
6768
- this.templateByQuery.set("saveResource", dist.gql `mutation($resource: InputResource!) {
6769
- $queryAlias$: saveResource(resource: $resource){
6770
- name
6771
- resource
6772
- }
6773
- }`);
6774
- }
6775
- loadResource(name) {
6776
- if (ResourceFetcher._loadingResource.has(name)) {
6777
- return ResourceFetcher._loadingResource.get(name);
6778
- }
6779
- const promiseLoadResource = new Promise((resolve, reject) => {
6780
- DataFetcher.get()
6781
- .callGraphQL({
6782
- values: { name },
6783
- query: this.templateByQuery.get("fetchResource"),
6784
- })
6785
- .then((result) => {
6786
- resolve(result === null || result === void 0 ? void 0 : result.resource);
6787
- ResourceFetcher._loadingResource.delete(name);
6788
- })
6789
- .catch((error) => {
6790
- reject(error);
6791
- ResourceFetcher._loadingResource.delete(name);
6792
- });
6793
- });
6794
- ResourceFetcher._loadingResource.set(name, promiseLoadResource);
6795
- return promiseLoadResource;
6796
- }
6797
- saveResource(resource, name) {
6798
- return new Promise((resolve, reject) => {
6799
- DataFetcher.get()
6800
- .callGraphQL({
6801
- values: {
6802
- resource: {
6803
- name: name,
6804
- resource: JSON.stringify(resource)
6805
- }
6806
- },
6807
- query: this.templateByQuery.get("saveResource")
6808
- })
6809
- .then((resp) => {
6810
- resolve(resp);
6811
- })
6812
- .catch((error) => {
6813
- reject(error);
6814
- });
6815
- });
6816
- }
6817
- }
6818
- ResourceFetcher._loadingResource = new Map();
6819
-
6820
- class FormConfigFetcher extends ResourceFetcher {
6821
- constructor() {
6822
- super();
6823
- this.queryConfig = new Map();
6824
- this.buildTemplatesConfig();
6825
- }
6826
- buildTemplatesConfig() {
6827
- this.queryConfig.set("fetchUserAvailableConfigs", dist.gql `query($name: String!) {
6828
- $queryAlias$: fetchUserAvailableConfigs(name: $name){
6829
- name
6830
- origin
6831
- key
6832
- }
6833
- }`);
6834
- this.queryConfig.set("fetchLegacyConfig", dist.gql `query($name: String!) {
6835
- $queryAlias$: fetchLegacyConfig(name: $name){
6836
- name
6837
- resource
6838
- }
6839
- }`);
6840
- this.queryConfig.set("fetchDefaultConfig", dist.gql `query($name: String!) {
6841
- $queryAlias$: fetchDefaultConfig(name: $name){
6842
- name
6843
- resource
6844
- }
6845
- }`);
6846
- }
6847
- loadFormConfig(formName, resourceID) {
6848
- return new Promise((accept, reject) => {
6849
- Promise.all([
6850
- this.loadResource(this.getPath(resourceID, formName))
6851
- ])
6852
- .then(([configAsString]) => {
6853
- const config = configAsString ? JSON.parse(configAsString) : {};
6854
- const { tabs, fields } = config;
6855
- if (tabs) {
6856
- const allTabs = new Map(tabs.map(t => [t.label, t]));
6857
- fields === null || fields === void 0 ? void 0 : fields.forEach(f => { var _a; return f.tab = ((_a = allTabs.get(this.getTabName(f.tab))) === null || _a === void 0 ? void 0 : _a.label) || allTabs.get(this.getTabName(f.tab)); });
6858
- }
6859
- if (fields) {
6860
- config.fields = fields === null || fields === void 0 ? void 0 : fields.map((field) => {
6861
- if ("readonly" in field) {
6862
- const readOnly = field['readonly'] === true;
6863
- delete field['readonly'];
6864
- field.readOnly = readOnly;
6865
- }
6866
- return field;
6867
- });
6868
- }
6869
- accept(config);
6870
- })
6871
- .catch((error) => {
6872
- reject(error);
6873
- });
6874
- });
6875
- }
6876
- getTabName(tab) {
6877
- if (typeof tab === 'object') { // ITabConfig type
6878
- return tab.label;
6879
- }
6880
- return tab; //string type
6881
- }
6882
- saveConfig(config, formName, resourceID) {
6883
- const completePath = this.getPath(resourceID, formName);
6884
- return new Promise((resolve, reject) => {
6885
- this.saveResource(config, completePath)
6886
- .then((resp) => {
6887
- resolve(JSON.parse(resp.resource));
6888
- })
6889
- .catch((error) => {
6890
- reject(error);
6891
- });
6892
- });
6893
- }
6894
- fetchUserAvailableConfigs(formName, resourceID) {
6895
- const name = this.getPath(resourceID, formName);
6896
- return new Promise((resolve, reject) => {
6897
- DataFetcher.get()
6898
- .callGraphQL({
6899
- values: { name },
6900
- query: this.queryConfig.get("fetchUserAvailableConfigs"),
6901
- })
6902
- .then((result) => {
6903
- resolve(result);
6904
- })
6905
- .catch((error) => {
6906
- reject(error);
6907
- });
6908
- });
6909
- }
6910
- fetchLegacyConfig(formName, resourceID) {
6911
- const name = this.getPath(resourceID, formName);
6912
- return new Promise((resolve, reject) => {
6913
- DataFetcher.get()
6914
- .callGraphQL({
6915
- values: { name },
6916
- query: this.queryConfig.get("fetchLegacyConfig"),
6917
- })
6918
- .then((result) => {
6919
- resolve(core.ObjectUtils.stringToObject((result === null || result === void 0 ? void 0 : result.resource) || ''));
6920
- })
6921
- .catch((error) => {
6922
- reject(error);
6923
- });
6924
- });
6925
- }
6926
- fetchDefaultConfig(formName, resourceID) {
6927
- const name = this.getPath(resourceID, formName);
6928
- return new Promise((resolve, reject) => {
6929
- DataFetcher.get()
6930
- .callGraphQL({
6931
- values: { name },
6932
- query: this.queryConfig.get("fetchDefaultConfig"),
6933
- })
6934
- .then((result) => {
6935
- resolve(core.ObjectUtils.stringToObject((result === null || result === void 0 ? void 0 : result.resource) || ''));
6936
- })
6937
- .catch((error) => {
6938
- reject(error);
6939
- });
6940
- });
6941
- }
6942
- getPath(resourceID, name, authority = "form") {
6943
- if (name) {
6944
- return `cfg://${authority}/${resourceID}/${name}`;
6945
- }
6946
- return `cfg://${authority}/${resourceID}`;
6947
- }
6948
- }
6949
- exports.UserConfigType = void 0;
6950
- (function (UserConfigType) {
6951
- UserConfigType["USER"] = "USER";
6952
- UserConfigType["DEFAULT"] = "DEFAULT";
6953
- UserConfigType["SHARED"] = "SHARED";
6954
- })(exports.UserConfigType || (exports.UserConfigType = {}));
6955
-
6956
- class GridConfigFetcher extends ResourceFetcher {
6957
- constructor() {
6958
- super(...arguments);
6959
- this.GRID_CONFIG_VERSION = "V3:";
6960
- }
6961
- getConfig(gridName, resourceID) {
6962
- const completePath = this.getPath(resourceID, gridName);
6963
- return new Promise((resolve, reject) => {
6964
- this.loadResource(completePath)
6965
- .then(loadedResource => {
6966
- let config = undefined;
6967
- if (loadedResource) {
6968
- config = JSON.parse(loadedResource);
6969
- }
6970
- resolve(config);
6971
- }).catch((error) => {
6972
- reject(error);
6973
- });
6974
- });
6975
- }
6976
- saveConfig(config, gridName, resourceID) {
6977
- const completePath = this.getPath(resourceID, gridName);
6978
- return new Promise((resolve, reject) => {
6979
- this.saveResource(config, completePath)
6980
- .then((resp) => {
6981
- resolve(JSON.parse(resp.resource));
6982
- })
6983
- .catch((error) => {
6984
- reject(error);
6985
- });
6986
- });
6987
- }
6988
- getPath(resourceID, name) {
6989
- if (name) {
6990
- return `cfg://grid/${this.GRID_CONFIG_VERSION}${resourceID}/${name}`;
6991
- }
6992
- return `cfg://grid/${this.GRID_CONFIG_VERSION}${resourceID}`;
6993
- }
6994
- }
6995
-
6996
- function normalizeValue(value) {
6997
- if (value == undefined) {
6998
- return value;
6999
- }
7000
- if (value instanceof Date) {
7001
- return value.toISOString();
7002
- }
7003
- if (typeof value === "object") {
7004
- if (value instanceof Array) {
7005
- return value.map(item => normalizeValue(item));
7006
- }
7007
- else {
7008
- const normalized = Object.assign({}, value);
7009
- Object.keys(value).forEach(prop => {
7010
- if (value[prop]) {
7011
- normalized[prop] = normalizeValue(value[prop]);
7012
- }
7013
- else {
7014
- delete normalized[prop];
7015
- }
7016
- });
7017
- return normalized;
7018
- }
7019
- }
7020
- return value;
7021
- }
7022
- class FilterBarConfigFetcher extends ResourceFetcher {
7023
- saveConfig(items, resourceID, configName) {
7024
- const state = items.map(item => {
7025
- const { id, value, fixed, visible } = item;
7026
- const stateItem = { id };
7027
- if (value) {
7028
- stateItem["value"] = normalizeValue(value);
7029
- }
7030
- if (fixed) {
7031
- stateItem["fixed"] = fixed;
7032
- }
7033
- if (visible) {
7034
- stateItem["visible"] = true;
7035
- }
7036
- return stateItem;
7037
- });
7038
- return this.saveResource(state, this.getPath(resourceID, configName));
7039
- }
7040
- getConfig(resourceID, configName) {
7041
- return new Promise((accept, reject) => {
7042
- this.loadResource(this.getPath(resourceID, configName))
7043
- .then((configAsString) => {
7044
- let fieldsList;
7045
- if (configAsString) {
7046
- const filterBarConfig = JSON.parse(configAsString);
7047
- fieldsList = filterBarConfig.items;
7048
- }
7049
- accept(fieldsList || []);
7050
- })
7051
- .catch((error) => {
7052
- reject(error);
7053
- });
7054
- });
7055
- }
7056
- getPath(resourceID, name) {
7057
- if (name) {
7058
- return `cfg://filter/FilterBarState:${resourceID}/${name}`;
7059
- }
7060
- return `cfg://filter/FilterBarState:${resourceID}`;
7061
- }
7062
- }
7063
-
7064
- const CONFIG_SOURCE = {
7065
- form: "form",
7066
- grid: "grid",
7067
- filterBar: "filterBar"
7068
- };
7069
- class ConfigStorage {
7070
- static async get() {
7071
- if (!ConfigStorage.instance) {
7072
- const application = core.ApplicationContext.getContextValue("__SNK__APPLICATION__");
7073
- if (application != undefined) {
7074
- const configName = application.configName;
7075
- const resourceID = await application.getResourceID();
7076
- ConfigStorage.instance = new ConfigStorage();
7077
- ConfigStorage.resourceID = resourceID;
7078
- ConfigStorage.instance.loadFilterBarConfig(configName);
7079
- ConfigStorage.instance.loadFormConfig(configName);
7080
- ConfigStorage.instance.loadGridConfig(configName);
7081
- }
7082
- }
7083
- return this.instance;
7084
- }
7085
- async loadFilterBarConfig(name) {
7086
- const cacheID = ConfigStorage.buildCacheID(name, CONFIG_SOURCE.filterBar);
7087
- if (!ConfigStorage.configById.has(cacheID)) {
7088
- ConfigStorage.configById.set(cacheID, ConfigStorage.filterBarConfigFetcher.getConfig(ConfigStorage.resourceID, name));
7089
- }
7090
- return ConfigStorage.configById.get(cacheID);
7091
- }
7092
- async loadFormConfig(name) {
7093
- const cacheID = ConfigStorage.buildCacheID(name, CONFIG_SOURCE.form);
7094
- if (!ConfigStorage.configById.has(cacheID)) {
7095
- ConfigStorage.configById.set(cacheID, ConfigStorage.formConfigFetcher.loadFormConfig(name, ConfigStorage.resourceID));
7096
- }
7097
- return ConfigStorage.configById.get(cacheID);
7098
- }
7099
- async loadGridConfig(name) {
7100
- const cacheID = ConfigStorage.buildCacheID(name, CONFIG_SOURCE.grid);
7101
- if (!ConfigStorage.configById.has(cacheID)) {
7102
- ConfigStorage.configById.set(cacheID, ConfigStorage.gridConfigFetcher.getConfig(name, ConfigStorage.resourceID));
7103
- }
7104
- return ConfigStorage.configById.get(cacheID);
7105
- }
7106
- static async saveFilterBarConfig(config, name) {
7107
- const cacheID = this.buildCacheID(name, CONFIG_SOURCE.filterBar);
7108
- this.configById.delete(cacheID);
7109
- return this.filterBarConfigFetcher.saveConfig(config, this.resourceID, name);
7110
- }
7111
- static async saveFormConfig(config, name) {
7112
- const cacheID = this.buildCacheID(name, CONFIG_SOURCE.form);
7113
- this.configById.delete(cacheID);
7114
- return this.formConfigFetcher.saveConfig(config, name, this.resourceID);
7115
- }
7116
- static async saveGridConfig(config, name) {
7117
- if (config == undefined) {
7118
- return;
7119
- }
7120
- const cacheID = this.buildCacheID(name, CONFIG_SOURCE.grid);
7121
- this.configById.delete(cacheID);
7122
- return this.gridConfigFetcher.saveConfig(config, name, this.resourceID);
7123
- }
7124
- static buildCacheID(name, source) {
7125
- if (name == undefined) {
7126
- return `req_${source}_${this.resourceID}`;
7127
- }
7128
- return `req_${source}_${name}_${this.resourceID}`;
7129
- }
7130
- }
7131
- ConfigStorage.configById = new Map();
7132
- ConfigStorage.filterBarConfigFetcher = new FilterBarConfigFetcher();
7133
- ConfigStorage.formConfigFetcher = new FormConfigFetcher();
7134
- ConfigStorage.gridConfigFetcher = new GridConfigFetcher();
7135
-
7136
- exports.ConfigStorage = ConfigStorage;
7137
6757
  exports.DataFetcher = DataFetcher;
7138
- exports.FormConfigFetcher = FormConfigFetcher;
7139
- exports.GridConfigFetcher = GridConfigFetcher;
7140
- exports.ResourceFetcher = ResourceFetcher;
7141
6758
  exports.UrlUtils = UrlUtils;
7142
6759
  exports.dist = dist;
@@ -0,0 +1,133 @@
1
+ 'use strict';
2
+
3
+ const ConfigStorage = require('./ConfigStorage-967176bb.js');
4
+ const core = require('@sankhyalabs/core');
5
+ const formConfigFetcher = require('./form-config-fetcher-f57babd9.js');
6
+
7
+ class SnkFormConfigManager {
8
+ constructor(configName, onConfigChange) {
9
+ this._configName = configName;
10
+ this._onConfigChange = onConfigChange;
11
+ }
12
+ async loadConfig() {
13
+ return new Promise(resolve => {
14
+ ConfigStorage.ConfigStorage.get()
15
+ .then((configStorage) => {
16
+ configStorage.loadFormConfig(this._configName)
17
+ .then((config) => {
18
+ this.setConfig(config);
19
+ resolve(config);
20
+ })
21
+ .catch((error) => {
22
+ console.warn(error);
23
+ });
24
+ });
25
+ });
26
+ }
27
+ saveConfig(config) {
28
+ const configToSave = core.ObjectUtils.copy(config);
29
+ return new Promise(accept => {
30
+ ConfigStorage.ConfigStorage.saveFormConfig(config, this._configName)
31
+ .then((response) => {
32
+ this.setConfig(Object.assign(Object.assign({}, configToSave), response));
33
+ accept(Object.assign(Object.assign({}, configToSave), response));
34
+ });
35
+ });
36
+ }
37
+ saveCardState(cardId, cardConfig, propertyChanged) {
38
+ return new Promise(resolve => {
39
+ var _a;
40
+ const cardsState = ((_a = this._config) === null || _a === void 0 ? void 0 : _a.cardsState) || new Map;
41
+ this.updateFixSequence(cardConfig, cardsState);
42
+ const currentConfig = cardsState.get(cardId);
43
+ cardsState.set(cardId, Object.assign(Object.assign({}, currentConfig), { [propertyChanged]: cardConfig[propertyChanged] }));
44
+ ConfigStorage.ConfigStorage.saveCardState(cardsState, this._configName)
45
+ .then(savedCardConfig => {
46
+ this._config = Object.assign(Object.assign({}, this._config), { cardsState });
47
+ resolve(savedCardConfig);
48
+ });
49
+ });
50
+ }
51
+ updateFixSequence(cardConfig, cardsState) {
52
+ if (!cardConfig.fixed) {
53
+ delete cardConfig.fixSequence;
54
+ return;
55
+ }
56
+ if (cardConfig.fixSequence != undefined) {
57
+ return;
58
+ }
59
+ let maxSequence = -1;
60
+ Array.from(cardsState.values()).forEach(cardConfig => {
61
+ if (cardConfig.fixSequence != undefined) {
62
+ maxSequence = Math.max(maxSequence, cardConfig.fixSequence);
63
+ }
64
+ });
65
+ cardConfig.fixSequence = maxSequence + 1;
66
+ }
67
+ getFieldsList(dataUnit) {
68
+ var _a;
69
+ const fields = (_a = this._config) === null || _a === void 0 ? void 0 : _a.fields;
70
+ if (fields != undefined && fields.length > 0) {
71
+ return [...fields];
72
+ }
73
+ if (dataUnit != undefined) {
74
+ return dataUnit.metadata.fields
75
+ .filter(field => field.visible !== false)
76
+ .map(({ name }) => { return { name }; });
77
+ }
78
+ return [];
79
+ }
80
+ getInsertionConfig(dataUnit) {
81
+ const fields = this.getFieldsList(dataUnit).filter(field => {
82
+ if (dataUnit) {
83
+ const def = dataUnit.getField(field.name);
84
+ if (def && def.readOnly) {
85
+ return false;
86
+ }
87
+ }
88
+ return !field.readOnly;
89
+ });
90
+ return Object.assign(Object.assign({}, this._config), { fields });
91
+ }
92
+ setConfig(config) {
93
+ this.isLoaded = true;
94
+ const { cardsState, summary, defaultVars } = this._config || {};
95
+ this._config = Object.assign({}, config);
96
+ if (cardsState) {
97
+ this._config.cardsState = cardsState;
98
+ }
99
+ if (summary) {
100
+ this._config.summary = summary;
101
+ }
102
+ if (defaultVars) {
103
+ this._config.defaultVars = defaultVars;
104
+ }
105
+ if (this._onConfigChange) {
106
+ this._onConfigChange(Object.assign({}, this._config));
107
+ }
108
+ }
109
+ getConfig(insertionMode, dataUnit) {
110
+ return insertionMode ? this.getInsertionConfig(dataUnit) : Object.assign({}, this._config);
111
+ }
112
+ getFormConfigFetcher() {
113
+ if (this._formConfigFetcher == undefined) {
114
+ this._formConfigFetcher = new formConfigFetcher.FormConfigFetcher();
115
+ }
116
+ return this._formConfigFetcher;
117
+ }
118
+ async fetchUserAvailableConfigs(resourceID) {
119
+ if (this._configName != undefined) {
120
+ //FIXME: Precisamos preparar o backend para retornar as configurações disponíveis para details;
121
+ return Promise.resolve(undefined);
122
+ }
123
+ return this.getFormConfigFetcher().fetchUserAvailableConfigs(this._configName, resourceID);
124
+ }
125
+ async fetchLegacyConfig(resourceID) {
126
+ return this.getFormConfigFetcher().fetchLegacyConfig(this._configName, resourceID);
127
+ }
128
+ async fetchDefaultConfig(resourceID) {
129
+ return this.getFormConfigFetcher().fetchDefaultConfig(this._configName, resourceID);
130
+ }
131
+ }
132
+
133
+ exports.SnkFormConfigManager = SnkFormConfigManager;