@headless-adminapp/app 0.0.17-alpha.8 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (243) hide show
  1. package/app/AppProvider.d.ts +0 -3
  2. package/app/AppProvider.js +10 -33
  3. package/app/AuthWrapper.d.ts +1 -1
  4. package/app/AuthWrapper.js +4 -1
  5. package/app/LayoutProvider.d.ts +8 -7
  6. package/app/LayoutProvider.js +28 -2
  7. package/app/context.d.ts +1 -1
  8. package/auth/AuthProvider.d.ts +1 -1
  9. package/auth/AuthProvider.js +30 -23
  10. package/auth/context.d.ts +2 -0
  11. package/auth/hooks/useIsSkipAuthCheck.d.ts +1 -0
  12. package/auth/hooks/useIsSkipAuthCheck.js +8 -0
  13. package/auth/hooks/useLogout.js +1 -1
  14. package/board/BoardColumnDataResolver.d.ts +1 -0
  15. package/board/BoardColumnDataResolver.js +64 -0
  16. package/board/BoardColumnProvider.d.ts +7 -0
  17. package/board/BoardColumnProvider.js +36 -0
  18. package/board/context.d.ts +19 -0
  19. package/board/context.js +6 -0
  20. package/board/hooks/index.d.ts +6 -0
  21. package/board/hooks/index.js +15 -0
  22. package/board/hooks/useBoardColumnConfig.d.ts +2 -0
  23. package/board/hooks/useBoardColumnConfig.js +8 -0
  24. package/board/hooks/useBoardColumnData.d.ts +3 -0
  25. package/board/hooks/useBoardColumnData.js +9 -0
  26. package/board/hooks/useBoardColumnDataState.d.ts +5 -0
  27. package/board/hooks/useBoardColumnDataState.js +9 -0
  28. package/board/hooks/useBoardConfig.d.ts +3 -0
  29. package/board/hooks/useBoardConfig.js +8 -0
  30. package/board/hooks/useBoardSchema.d.ts +2 -0
  31. package/board/hooks/useBoardSchema.js +7 -0
  32. package/board/hooks/useSearchText.d.ts +1 -0
  33. package/board/hooks/useSearchText.js +14 -0
  34. package/board/types.d.ts +47 -0
  35. package/board/utils.d.ts +3 -0
  36. package/board/utils.js +6 -0
  37. package/builders/CommandBuilder/DefaultCommandBuilder.d.ts +15 -6
  38. package/builders/CommandBuilder/DefaultCommandBuilder.js +42 -20
  39. package/builders/CommandBuilder/FormCommandBuilder.d.ts +14 -13
  40. package/builders/CommandBuilder/FormCommandBuilder.js +66 -52
  41. package/builders/CommandBuilder/SubgridCommandBuilder.d.ts +8 -27
  42. package/builders/CommandBuilder/SubgridCommandBuilder.js +115 -57
  43. package/builders/CommandBuilder/ViewCommandBuilder.js +32 -52
  44. package/builders/CommandBuilder/utils.js +1 -1
  45. package/builders/DefineFormExperience.d.ts +27 -0
  46. package/builders/DefineFormExperience.js +99 -0
  47. package/builders/DefineViewExperience.d.ts +13 -0
  48. package/builders/DefineViewExperience.js +33 -0
  49. package/builders/SchemaExperienceBuilder.d.ts +9 -7
  50. package/builders/SchemaExperienceBuilder.js +62 -40
  51. package/builders/utils.js +30 -44
  52. package/calendar/baseEventAttributes.d.ts +35 -0
  53. package/calendar/baseEventAttributes.js +38 -0
  54. package/calendar/context.d.ts +6 -0
  55. package/calendar/context.js +5 -0
  56. package/calendar/hooks/index.d.ts +1 -0
  57. package/{appearance → calendar}/hooks/index.js +1 -1
  58. package/calendar/hooks/useConfig.d.ts +3 -0
  59. package/calendar/hooks/useConfig.js +8 -0
  60. package/calendar/types.d.ts +41 -0
  61. package/calendar/types.js +2 -0
  62. package/calendar/utils.d.ts +3 -0
  63. package/calendar/utils.js +6 -0
  64. package/command/hooks/useBaseCommandHandlerContext.js +15 -6
  65. package/command/hooks/useCommands.js +1 -1
  66. package/command/utils/index.js +34 -9
  67. package/components/ScrollView/index.d.ts +1 -1
  68. package/components/ScrollView/index.js +2 -2
  69. package/components/ScrollbarWithMoreDataRequest/index.d.ts +9 -0
  70. package/components/ScrollbarWithMoreDataRequest/index.js +32 -0
  71. package/dataform/DataFormProvider/CustomHookExecuter.d.ts +5 -0
  72. package/dataform/DataFormProvider/CustomHookExecuter.js +14 -0
  73. package/dataform/DataFormProvider/DataResolver.d.ts +6 -4
  74. package/dataform/DataFormProvider/DataResolver.js +11 -94
  75. package/dataform/DataFormProvider/InitialValueResolver.js +3 -2
  76. package/dataform/DataFormProvider/ReadonlyInfoResolver.js +2 -3
  77. package/dataform/DataFormProvider/getRecord.d.ts +3 -0
  78. package/dataform/DataFormProvider/getRecord.js +56 -0
  79. package/dataform/DataFormProvider/index.d.ts +4 -0
  80. package/dataform/DataFormProvider/index.js +34 -12
  81. package/dataform/DataFormProvider/types.d.ts +13 -0
  82. package/dataform/DataFormProvider/types.js +2 -0
  83. package/dataform/DataFormProvider/utils.d.ts +23 -0
  84. package/dataform/DataFormProvider/utils.js +105 -0
  85. package/dataform/FormManager.d.ts +57 -0
  86. package/dataform/FormManager.js +247 -0
  87. package/dataform/constants.d.ts +1 -0
  88. package/dataform/constants.js +4 -0
  89. package/dataform/context.d.ts +26 -1
  90. package/dataform/hooks/index.d.ts +11 -0
  91. package/dataform/hooks/index.js +11 -0
  92. package/dataform/hooks/useContextKey.d.ts +1 -0
  93. package/dataform/hooks/useContextKey.js +8 -0
  94. package/dataform/hooks/useDisabledControlsManager.d.ts +6 -0
  95. package/dataform/hooks/useDisabledControlsManager.js +46 -0
  96. package/dataform/hooks/useEventManager.d.ts +1 -0
  97. package/dataform/hooks/useEventManager.js +8 -0
  98. package/dataform/hooks/useFormManager.d.ts +2 -0
  99. package/dataform/hooks/useFormManager.js +13 -0
  100. package/dataform/hooks/useFormNotifications.js +2 -2
  101. package/dataform/hooks/useFormSave.js +28 -31
  102. package/dataform/hooks/useHiddenControlsManager.d.ts +7 -0
  103. package/dataform/hooks/useHiddenControlsManager.js +50 -0
  104. package/dataform/hooks/useIsControlDisabled.d.ts +1 -0
  105. package/dataform/hooks/useIsControlDisabled.js +27 -0
  106. package/dataform/hooks/useIsControlHiddenByAttributeName.d.ts +1 -0
  107. package/dataform/hooks/useIsControlHiddenByAttributeName.js +17 -0
  108. package/dataform/hooks/useIsControlHiddenByKey.d.ts +1 -0
  109. package/dataform/hooks/useIsControlHiddenByKey.js +17 -0
  110. package/dataform/hooks/useIsFieldRequired.d.ts +1 -0
  111. package/dataform/hooks/useIsFieldRequired.js +25 -0
  112. package/dataform/hooks/useLoadFormGridPage.js +8 -17
  113. package/dataform/hooks/useMainFormCommands.d.ts +1 -12
  114. package/dataform/hooks/useMainFormCommands.js +13 -3
  115. package/dataform/hooks/useOnFieldValueChangeListener.d.ts +1 -0
  116. package/dataform/hooks/useOnFieldValueChangeListener.js +30 -0
  117. package/dataform/hooks/useProcessFlowSteps.d.ts +1 -0
  118. package/dataform/hooks/useProcessFlowSteps.js +45 -0
  119. package/dataform/hooks/useRecordTitle.d.ts +3 -1
  120. package/dataform/hooks/useRecordTitle.js +12 -5
  121. package/dataform/hooks/useRequiredFieldManager.d.ts +6 -0
  122. package/dataform/hooks/useRequiredFieldManager.js +49 -0
  123. package/dataform/test.d.ts +57 -0
  124. package/dataform/test.js +247 -0
  125. package/dataform/utils/defaultParameters.d.ts +6 -0
  126. package/dataform/utils/defaultParameters.js +54 -0
  127. package/dataform/utils/index.d.ts +6 -24
  128. package/dataform/utils/index.js +164 -190
  129. package/dataform/utils/saveRecord.d.ts +27 -0
  130. package/dataform/utils/saveRecord.js +163 -0
  131. package/datagrid/DataGridProvider/DataResolver.js +38 -109
  132. package/datagrid/DataGridProvider/index.d.ts +6 -0
  133. package/datagrid/DataGridProvider/index.js +18 -8
  134. package/datagrid/DataGridProvider/transformViewColumns.js +10 -2
  135. package/datagrid/DataGridProvider/utils.js +8 -8
  136. package/datagrid/column-filter/constants.js +38 -3
  137. package/datagrid/column-filter/utils.js +7 -1
  138. package/datagrid/context.d.ts +6 -0
  139. package/datagrid/hooks/useChangeView.js +1 -1
  140. package/datagrid/hooks/useGridColumnFilter.js +4 -1
  141. package/datagrid/hooks/useGridDisabled.d.ts +1 -0
  142. package/datagrid/hooks/useGridDisabled.js +8 -0
  143. package/datagrid/hooks/useLoadMainGridPage.js +1 -1
  144. package/datagrid/hooks/useMainGridCommands.js +23 -9
  145. package/datagrid/hooks/useOpenRecord.js +2 -2
  146. package/datagrid/hooks/useSubGridCommands.js +23 -45
  147. package/defaults.d.ts +2 -0
  148. package/defaults.js +5 -0
  149. package/dialog/hooks/useCloseDialog.js +17 -15
  150. package/dialog/hooks/useOpenAlertDialog.js +8 -3
  151. package/dialog/hooks/useOpenConfirmDialog.js +10 -4
  152. package/dialog/hooks/useOpenDialog.js +7 -5
  153. package/dialog/hooks/useOpenErrorDialog.js +8 -3
  154. package/dialog/hooks/useOpenPromptDialog.js +10 -4
  155. package/form/FormValidationStringContext.d.ts +1 -0
  156. package/form/FormValidationStringContext.js +1 -0
  157. package/hooks/index.d.ts +1 -0
  158. package/hooks/index.js +3 -0
  159. package/hooks/useDebouncedValue.js +0 -1
  160. package/hooks/useElementLayout.js +1 -1
  161. package/hooks/useIsMobile.js +0 -1
  162. package/hooks/useItemsWithKey.d.ts +7 -0
  163. package/hooks/useItemsWithKey.js +13 -0
  164. package/hooks/useStorageState.js +1 -2
  165. package/hooks/useSystemColorScheme.d.ts +1 -1
  166. package/hooks/useSystemColorScheme.js +0 -1
  167. package/insights/InsightsProvider.d.ts +8 -0
  168. package/insights/InsightsProvider.js +27 -0
  169. package/locale/LocaleProvider.d.ts +2 -1
  170. package/locale/LocaleProvider.js +3 -3
  171. package/locale/index.d.ts +1 -0
  172. package/locale/index.js +1 -0
  173. package/locale/useCurrencySymbol.d.ts +1 -0
  174. package/locale/useCurrencySymbol.js +12 -0
  175. package/locale/utils.js +4 -2
  176. package/metadata/MetadataProvider.d.ts +8 -4
  177. package/metadata/MetadataProvider.js +23 -17
  178. package/metadata/context.d.ts +3 -2
  179. package/metadata/hooks/index.d.ts +1 -1
  180. package/metadata/hooks/index.js +1 -1
  181. package/metadata/hooks/useAppExperience.d.ts +1 -0
  182. package/metadata/hooks/useAppExperience.js +8 -0
  183. package/metadata/hooks/useAppStore.d.ts +1 -1
  184. package/metadata/hooks/useAppStore.js +3 -3
  185. package/metadata/hooks/useExperienceView.js +2 -11
  186. package/metadata/hooks/useExperienceViewCommands.d.ts +1 -1
  187. package/metadata/hooks/useExperienceViewCommands.js +5 -14
  188. package/metadata/hooks/useExperienceViewLookup.js +2 -11
  189. package/metadata/hooks/useExperienceViewSubgridCommands.d.ts +1 -1
  190. package/metadata/hooks/useExperienceViewSubgridCommands.js +5 -14
  191. package/metadata/hooks/useMetadata.d.ts +11 -10
  192. package/metadata/hooks/useMetadata.js +4 -16
  193. package/metadata/hooks/useSchema.d.ts +1 -1
  194. package/metadata/hooks/useSchema.js +3 -0
  195. package/mutable/context.d.ts +3 -0
  196. package/mutable/context.js +8 -0
  197. package/mutable/utils.js +5 -12
  198. package/navigation/hooks/useOpenForm.js +4 -0
  199. package/package.json +6 -10
  200. package/providers/PageEntityFormProvider/index.d.ts +5 -1
  201. package/providers/PageEntityFormProvider/index.js +2 -2
  202. package/recordset/hooks/useRecordSetResult.js +4 -14
  203. package/route/RouteProvider.d.ts +2 -2
  204. package/route/RouteProvider.js +4 -1
  205. package/store/ClientAppStore.js +7 -20
  206. package/store/ComponentStore.d.ts +1 -1
  207. package/store/ComponentStore.js +6 -12
  208. package/store/EventManager.d.ts +2 -2
  209. package/store/EventManager.js +13 -29
  210. package/store/SchemaExperienceStore.js +179 -215
  211. package/store/index.d.ts +0 -1
  212. package/store/index.js +0 -1
  213. package/toast-notification/hooks/useCloseToastNotification.js +17 -15
  214. package/toast-notification/hooks/useOpenToastNotification.js +7 -5
  215. package/transport/InMemoryDataService/index.js +54 -77
  216. package/transport/RestDataService/index.d.ts +3 -3
  217. package/transport/RestDataService/index.js +68 -91
  218. package/transport/context.d.ts +2 -1
  219. package/transport/context.js +7 -1
  220. package/transport/hooks/index.d.ts +1 -0
  221. package/transport/hooks/index.js +1 -0
  222. package/transport/hooks/useFileService.d.ts +1 -0
  223. package/transport/hooks/useFileService.js +9 -0
  224. package/transport/hooks/useRetriveRecords.d.ts +33 -0
  225. package/transport/hooks/useRetriveRecords.js +110 -0
  226. package/utils/calculateColumnWidths.js +1 -1
  227. package/utils/color.d.ts +1 -0
  228. package/utils/color.js +14 -0
  229. package/utils/getAttributeFormattedValue.d.ts +4 -1
  230. package/utils/getAttributeFormattedValue.js +109 -54
  231. package/utils/phone.d.ts +13 -0
  232. package/utils/phone.js +33 -0
  233. package/appearance/context.d.ts +0 -7
  234. package/appearance/context.js +0 -5
  235. package/appearance/hooks/index.d.ts +0 -1
  236. package/appearance/hooks/useAppearanceContext.d.ts +0 -1
  237. package/appearance/hooks/useAppearanceContext.js +0 -12
  238. package/appearance/index.d.ts +0 -2
  239. package/appearance/index.js +0 -20
  240. package/builders/CommandBuilder.d.ts +0 -176
  241. package/builders/CommandBuilder.js +0 -567
  242. package/locale/types.d.ts +0 -2
  243. /package/{locale → board}/types.js +0 -0
@@ -1,16 +1,8 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.InMemoryDataService = void 0;
13
4
  class InMemoryDataService {
5
+ options;
14
6
  // , IActionService, IReportService
15
7
  constructor(options) {
16
8
  this.options = options;
@@ -28,85 +20,70 @@ class InMemoryDataService {
28
20
  }
29
21
  return this.options.data[logicalName];
30
22
  }
31
- retriveRecord(logicalName, id) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- const schema = this.getSchema(logicalName);
34
- const records = this.getCollection(logicalName);
35
- const record = records.find((record) => {
36
- return record[schema.idAttribute] === id;
37
- });
38
- if (!record) {
39
- throw new Error(`Record with id ${id} not found`);
40
- }
41
- return record;
23
+ async retriveRecord(logicalName, id) {
24
+ const schema = this.getSchema(logicalName);
25
+ const records = this.getCollection(logicalName);
26
+ const record = records.find((record) => {
27
+ return record[schema.idAttribute] === id;
42
28
  });
29
+ if (!record) {
30
+ throw new Error(`Record with id ${id} not found`);
31
+ }
32
+ return record;
43
33
  }
44
- retriveRecords(_a) {
45
- return __awaiter(this, arguments, void 0, function* ({ logicalName, }) {
46
- const records = this.getCollection(logicalName);
47
- return {
48
- logicalName,
49
- records: records,
50
- count: records.length,
51
- };
52
- });
34
+ async retriveRecords({ logicalName, }) {
35
+ const records = this.getCollection(logicalName);
36
+ return {
37
+ logicalName,
38
+ records: records,
39
+ count: records.length,
40
+ };
53
41
  }
54
- createRecord(logicalName, data) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- const schema = this.getSchema(logicalName);
57
- const records = this.getCollection(logicalName);
58
- const newId = this.options.idGenerator(logicalName, records);
59
- const newRecord = Object.assign(Object.assign({}, data), { [schema.idAttribute]: newId });
60
- records.push(newRecord);
61
- return { id: newId };
62
- });
42
+ async createRecord(logicalName, data) {
43
+ const schema = this.getSchema(logicalName);
44
+ const records = this.getCollection(logicalName);
45
+ const newId = this.options.idGenerator(logicalName, records);
46
+ const newRecord = {
47
+ ...data,
48
+ [schema.idAttribute]: newId,
49
+ };
50
+ records.push(newRecord);
51
+ return { id: newId };
63
52
  }
64
- updateRecord(logicalName, id, data) {
65
- return __awaiter(this, void 0, void 0, function* () {
66
- const schema = this.getSchema(logicalName);
67
- const records = this.getCollection(logicalName);
68
- const record = records.find((record) => {
69
- return record[schema.idAttribute] === id;
70
- });
71
- if (!record) {
72
- throw new Error(`Record with id ${id} not found`);
73
- }
74
- Object.assign(record, data);
75
- return { id };
53
+ async updateRecord(logicalName, id, data) {
54
+ const schema = this.getSchema(logicalName);
55
+ const records = this.getCollection(logicalName);
56
+ const record = records.find((record) => {
57
+ return record[schema.idAttribute] === id;
76
58
  });
59
+ if (!record) {
60
+ throw new Error(`Record with id ${id} not found`);
61
+ }
62
+ Object.assign(record, data);
63
+ return { id };
77
64
  }
78
- deleteRecord(logicalName, id) {
79
- return __awaiter(this, void 0, void 0, function* () {
80
- const schema = this.getSchema(logicalName);
81
- const records = this.getCollection(logicalName);
82
- const index = records.findIndex((record) => {
83
- return record[schema.idAttribute] === id;
84
- });
85
- if (index === -1) {
86
- throw new Error(`Record with id ${id} not found`);
87
- }
88
- records.splice(index, 1);
65
+ async deleteRecord(logicalName, id) {
66
+ const schema = this.getSchema(logicalName);
67
+ const records = this.getCollection(logicalName);
68
+ const index = records.findIndex((record) => {
69
+ return record[schema.idAttribute] === id;
89
70
  });
71
+ if (index === -1) {
72
+ throw new Error(`Record with id ${id} not found`);
73
+ }
74
+ records.splice(index, 1);
90
75
  }
91
- executeAction() {
92
- return __awaiter(this, void 0, void 0, function* () {
93
- return {};
94
- });
76
+ async executeAction() {
77
+ return {};
95
78
  }
96
- getReportData() {
97
- return __awaiter(this, void 0, void 0, function* () {
98
- return {};
99
- });
79
+ async getReportData() {
80
+ return {};
100
81
  }
101
- retriveAggregate() {
102
- return __awaiter(this, void 0, void 0, function* () {
103
- return [];
104
- });
82
+ async retriveAggregate() {
83
+ return [];
105
84
  }
106
- customAction() {
107
- return __awaiter(this, void 0, void 0, function* () {
108
- return {};
109
- });
85
+ async customAction() {
86
+ return {};
110
87
  }
111
88
  }
112
89
  exports.InMemoryDataService = InMemoryDataService;
@@ -3,11 +3,11 @@ import { RetriveRecordsFnOptions, RetriveRecordsResult } from '@headless-adminap
3
3
  interface RestDataServiceOptions {
4
4
  endpoint: string;
5
5
  }
6
+ export declare function handleResponseError(response: Response): Promise<void>;
6
7
  export declare class RestDataService implements IDataService {
7
8
  protected readonly options: RestDataServiceOptions;
8
9
  constructor(options: RestDataServiceOptions);
9
10
  protected readonly headers: Record<string, string>;
10
- protected handleResponseError(response: Response): Promise<void>;
11
11
  private getHeaders;
12
12
  setHeader(name: string, value: string): void;
13
13
  removeHeader(name: string): void;
@@ -16,8 +16,8 @@ export declare class RestDataService implements IDataService {
16
16
  [key in keyof T]?: string[];
17
17
  }): Promise<Data<T>>;
18
18
  retriveRecords<T = unknown>(params: RetriveRecordsFnOptions<T>): Promise<RetriveRecordsResult<T>>;
19
- createRecord<T>(logicalName: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core/attributes").Id>>;
20
- updateRecord<T>(logicalName: string, id: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core/attributes").Id>>;
19
+ createRecord<T>(logicalName: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core").Id>>;
20
+ updateRecord<T>(logicalName: string, id: string, data: Partial<T>): Promise<CreateRecordResult<import("@headless-adminapp/core").Id>>;
21
21
  deleteRecord(logicalName: string, id: string): Promise<void>;
22
22
  retriveAggregate<Q extends Record<string, AggregateAttribute> = Record<string, AggregateAttribute>>(query: AggregateQuery<Q>): Promise<InferredAggregateQueryResult<Q>[]>;
23
23
  customAction<T = unknown>(_actionName: string, _payload: unknown): Promise<T>;
@@ -1,38 +1,31 @@
1
1
  "use strict";
2
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
- return new (P || (P = Promise))(function (resolve, reject) {
5
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
- step((generator = generator.apply(thisArg, _arguments || [])).next());
9
- });
10
- };
11
2
  Object.defineProperty(exports, "__esModule", { value: true });
12
3
  exports.RestDataService = void 0;
4
+ exports.handleResponseError = handleResponseError;
13
5
  const transport_1 = require("@headless-adminapp/core/transport");
6
+ async function handleResponseError(response) {
7
+ if (response.ok) {
8
+ return;
9
+ }
10
+ if (response.headers.get('content-type')?.includes('application/json')) {
11
+ const data = await response.json();
12
+ if (data.error) {
13
+ throw new transport_1.HttpError(response.status, data.error);
14
+ }
15
+ }
16
+ throw new transport_1.HttpError(response.status, response.statusText);
17
+ }
14
18
  class RestDataService {
19
+ options;
15
20
  constructor(options) {
16
21
  this.options = options;
17
- this.headers = {};
18
- }
19
- handleResponseError(response) {
20
- return __awaiter(this, void 0, void 0, function* () {
21
- var _a;
22
- if (response.ok) {
23
- return;
24
- }
25
- if ((_a = response.headers.get('content-type')) === null || _a === void 0 ? void 0 : _a.includes('application/json')) {
26
- const data = yield response.json();
27
- if (data.error) {
28
- throw new transport_1.HttpError(response.status, data.error);
29
- }
30
- }
31
- throw new transport_1.HttpError(response.status, response.statusText);
32
- });
33
22
  }
23
+ headers = {};
34
24
  getHeaders() {
35
- return Object.assign({ 'content-type': 'application/json' }, this.headers);
25
+ return {
26
+ 'content-type': 'application/json',
27
+ ...this.headers,
28
+ };
36
29
  }
37
30
  setHeader(name, value) {
38
31
  this.headers[name] = value;
@@ -40,85 +33,69 @@ class RestDataService {
40
33
  removeHeader(name) {
41
34
  delete this.headers[name];
42
35
  }
43
- execute(data) {
44
- return __awaiter(this, void 0, void 0, function* () {
45
- const response = yield fetch(this.options.endpoint, {
46
- headers: this.getHeaders(),
47
- method: 'POST',
48
- body: JSON.stringify(data),
49
- });
50
- yield this.handleResponseError(response);
51
- return response.json();
36
+ async execute(data) {
37
+ const response = await fetch(this.options.endpoint, {
38
+ headers: this.getHeaders(),
39
+ method: 'POST',
40
+ body: JSON.stringify(data),
52
41
  });
42
+ await handleResponseError(response);
43
+ return response.json();
53
44
  }
54
- retriveRecord(logicalName, id, columns, expand) {
55
- return __awaiter(this, void 0, void 0, function* () {
56
- return this.execute({
57
- type: 'retriveRecord',
58
- payload: {
59
- logicalName,
60
- id,
61
- columns,
62
- expand,
63
- },
64
- });
45
+ async retriveRecord(logicalName, id, columns, expand) {
46
+ return this.execute({
47
+ type: 'retriveRecord',
48
+ payload: {
49
+ logicalName,
50
+ id,
51
+ columns,
52
+ expand,
53
+ },
65
54
  });
66
55
  }
67
- retriveRecords(params) {
68
- return __awaiter(this, void 0, void 0, function* () {
69
- return this.execute({
70
- type: 'retriveRecords',
71
- payload: params,
72
- });
56
+ async retriveRecords(params) {
57
+ return this.execute({
58
+ type: 'retriveRecords',
59
+ payload: params,
73
60
  });
74
61
  }
75
- createRecord(logicalName, data) {
76
- return __awaiter(this, void 0, void 0, function* () {
77
- return this.execute({
78
- type: 'createRecord',
79
- payload: {
80
- logicalName,
81
- data,
82
- },
83
- });
62
+ async createRecord(logicalName, data) {
63
+ return this.execute({
64
+ type: 'createRecord',
65
+ payload: {
66
+ logicalName,
67
+ data,
68
+ },
84
69
  });
85
70
  }
86
- updateRecord(logicalName, id, data) {
87
- return __awaiter(this, void 0, void 0, function* () {
88
- return this.execute({
89
- type: 'updateRecord',
90
- payload: {
91
- logicalName,
92
- id,
93
- data,
94
- },
95
- });
71
+ async updateRecord(logicalName, id, data) {
72
+ return this.execute({
73
+ type: 'updateRecord',
74
+ payload: {
75
+ logicalName,
76
+ id,
77
+ data,
78
+ },
96
79
  });
97
80
  }
98
- deleteRecord(logicalName, id) {
99
- return __awaiter(this, void 0, void 0, function* () {
100
- return this.execute({
101
- type: 'deleteRecord',
102
- payload: {
103
- logicalName,
104
- id,
105
- },
106
- });
81
+ async deleteRecord(logicalName, id) {
82
+ return this.execute({
83
+ type: 'deleteRecord',
84
+ payload: {
85
+ logicalName,
86
+ id,
87
+ },
107
88
  });
108
89
  }
109
- retriveAggregate(query) {
110
- return __awaiter(this, void 0, void 0, function* () {
111
- const result = yield this.execute({
112
- type: 'retriveAggregate',
113
- payload: query,
114
- });
115
- return result;
90
+ async retriveAggregate(query) {
91
+ const result = await this.execute({
92
+ type: 'retriveAggregate',
93
+ payload: query,
116
94
  });
95
+ return result;
117
96
  }
118
- customAction(_actionName, _payload) {
119
- return __awaiter(this, void 0, void 0, function* () {
120
- throw new Error('Custom action not implemented in RestDataService, to use custom actions, define a custom data service extending RestDataService');
121
- });
97
+ async customAction(_actionName, _payload) {
98
+ throw new Error('Custom action not implemented in RestDataService, to use custom actions, define a custom data service extending RestDataService');
122
99
  }
123
100
  }
124
101
  exports.RestDataService = RestDataService;
@@ -1,2 +1,3 @@
1
- import { IDataService } from '@headless-adminapp/core/transport';
1
+ import { IDataService, IFileService } from '@headless-adminapp/core/transport';
2
2
  export declare const DataServiceContext: import("react").Context<IDataService | undefined>;
3
+ export declare const FileServiceContext: import("react").Context<IFileService | null>;
@@ -1,5 +1,11 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DataServiceContext = void 0;
3
+ exports.FileServiceContext = exports.DataServiceContext = void 0;
4
4
  const react_1 = require("react");
5
5
  exports.DataServiceContext = (0, react_1.createContext)(undefined);
6
+ // export const noopFileService = {
7
+ // uploadFile: async () => {
8
+ // throw new Error('File service not implemented');
9
+ // },
10
+ // } as IFileService;
11
+ exports.FileServiceContext = (0, react_1.createContext)(null);
@@ -1 +1,2 @@
1
1
  export * from './useDataService';
2
+ export * from './useFileService';
@@ -15,3 +15,4 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
17
  __exportStar(require("./useDataService"), exports);
18
+ __exportStar(require("./useFileService"), exports);
@@ -0,0 +1 @@
1
+ export declare function useFileService(): import("@headless-adminapp/core/transport").IFileService | null;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useFileService = useFileService;
4
+ const react_1 = require("react");
5
+ const context_1 = require("../context");
6
+ function useFileService() {
7
+ const context = (0, react_1.useContext)(context_1.FileServiceContext);
8
+ return context;
9
+ }
@@ -0,0 +1,33 @@
1
+ import { SortingState } from '@headless-adminapp/core/experience/view';
2
+ import { InferredSchemaType, Schema, SchemaAttributes } from '@headless-adminapp/core/schema';
3
+ import { Filter } from '@headless-adminapp/core/transport';
4
+ import { QueryKey } from '@tanstack/react-query';
5
+ interface UseRetriveRecordProps<S extends SchemaAttributes = SchemaAttributes> {
6
+ schema: Schema<S>;
7
+ search: string;
8
+ filter: Filter | null;
9
+ sorting: SortingState<S>;
10
+ columns: string[];
11
+ expand?: Partial<Record<string, string[]>>;
12
+ maxRecords: number;
13
+ disabled?: boolean;
14
+ }
15
+ export declare function useRetrieveRecordsKey<S extends SchemaAttributes = SchemaAttributes>({ schema, search, filter, sorting, columns, expand, maxRecords, }: UseRetriveRecordProps<S>): (string | number | string[] | Filter | Partial<Record<string, string[]>> | SortingState<S> | null | undefined)[];
16
+ export declare function useClearDataExceptFirstPage(queryKey: QueryKey): void;
17
+ export declare function useRetriveRecords<S extends SchemaAttributes = SchemaAttributes>(queryKey: QueryKey, { columns, expand, filter, maxRecords, schema, search, sorting, disabled, }: UseRetriveRecordProps): {
18
+ data: {
19
+ logicalName: string;
20
+ count: number;
21
+ records: import("@headless-adminapp/core/transport").Data<InferredSchemaType<S>>[];
22
+ } | null;
23
+ isFetching: boolean;
24
+ hasNextPage: boolean;
25
+ fetchNextPage: (options?: import("@tanstack/react-query").FetchNextPageOptions) => Promise<import("@tanstack/react-query").InfiniteQueryObserverResult<import("@tanstack/react-query").InfiniteData<{
26
+ params: {
27
+ pageIndex: number;
28
+ };
29
+ data: import("@headless-adminapp/core/transport").RetriveRecordsResult<InferredSchemaType<S>>;
30
+ }, unknown>, Error>>;
31
+ isFetchingNextPage: boolean;
32
+ };
33
+ export {};
@@ -0,0 +1,110 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.useRetrieveRecordsKey = useRetrieveRecordsKey;
4
+ exports.useClearDataExceptFirstPage = useClearDataExceptFirstPage;
5
+ exports.useRetriveRecords = useRetriveRecords;
6
+ const transport_1 = require("@headless-adminapp/app/transport");
7
+ const react_query_1 = require("@tanstack/react-query");
8
+ const react_1 = require("react");
9
+ const ROWS_PER_PAGE = 100;
10
+ function useRetrieveRecordsKey({ schema, search, filter, sorting, columns, expand, maxRecords, }) {
11
+ const queryKey = (0, react_1.useMemo)(() => [
12
+ 'data',
13
+ 'retriveRecords',
14
+ schema.logicalName,
15
+ search,
16
+ filter,
17
+ sorting,
18
+ columns,
19
+ expand,
20
+ maxRecords,
21
+ ], [schema.logicalName, search, filter, sorting, columns, expand, maxRecords]);
22
+ return queryKey;
23
+ }
24
+ function useClearDataExceptFirstPage(queryKey) {
25
+ const queryClient = (0, react_query_1.useQueryClient)();
26
+ (0, react_1.useEffect)(() => {
27
+ return () => {
28
+ // Clear all pages except the first one when the component is unmounted
29
+ queryClient.setQueryData(queryKey, (oldData) => {
30
+ if (!oldData) {
31
+ return oldData;
32
+ }
33
+ if (!oldData.pageParams.length || !oldData.pages.length) {
34
+ return oldData;
35
+ }
36
+ return {
37
+ pageParams: [oldData.pageParams[0]],
38
+ pages: [oldData.pages[0]],
39
+ };
40
+ });
41
+ };
42
+ }, [queryClient, queryKey]);
43
+ }
44
+ function useRetriveRecords(queryKey, { columns, expand, filter, maxRecords, schema, search, sorting, disabled, }) {
45
+ const dataService = (0, transport_1.useDataService)();
46
+ const { data, isFetching, hasNextPage, fetchNextPage, isFetchingNextPage } = (0, react_query_1.useInfiniteQuery)({
47
+ queryKey: queryKey,
48
+ queryFn: async (queryContext) => {
49
+ const params = queryContext.pageParam ?? {
50
+ pageIndex: 0,
51
+ };
52
+ const skip = params.pageIndex * ROWS_PER_PAGE;
53
+ const limit = Math.min(ROWS_PER_PAGE, Math.max(0, maxRecords - skip));
54
+ if (limit <= 0) {
55
+ return {
56
+ params: params,
57
+ data: {
58
+ logicalName: schema.logicalName,
59
+ count: 0,
60
+ records: [],
61
+ },
62
+ };
63
+ }
64
+ const result = await dataService.retriveRecords({
65
+ logicalName: schema.logicalName,
66
+ search,
67
+ columns: columns,
68
+ expand,
69
+ filter,
70
+ skip,
71
+ limit,
72
+ sort: sorting,
73
+ });
74
+ return {
75
+ params: params,
76
+ data: result,
77
+ };
78
+ },
79
+ getNextPageParam: (lastPage) => {
80
+ if (lastPage.data.count <
81
+ ROWS_PER_PAGE * (lastPage.params.pageIndex + 1)) {
82
+ return undefined;
83
+ }
84
+ return {
85
+ pageIndex: lastPage.params.pageIndex + 1,
86
+ };
87
+ },
88
+ initialPageParam: {
89
+ pageIndex: 0,
90
+ },
91
+ enabled: !disabled,
92
+ });
93
+ const finalData = (0, react_1.useMemo)(() => {
94
+ if (!data?.pages.length) {
95
+ return null;
96
+ }
97
+ return {
98
+ logicalName: data?.pages?.[0].data.logicalName,
99
+ count: data?.pages?.[0].data.count ?? 0,
100
+ records: data?.pages.map((x) => x.data.records).flat() ?? [],
101
+ };
102
+ }, [data]);
103
+ return {
104
+ data: finalData,
105
+ isFetching,
106
+ hasNextPage,
107
+ fetchNextPage,
108
+ isFetchingNextPage,
109
+ };
110
+ }
@@ -39,7 +39,7 @@ function extendValues(values, maxValues, available) {
39
39
  if (maxValue && value >= maxValue)
40
40
  continue;
41
41
  const newValue = value + value * ratio;
42
- values[i] = Math.min(newValue, maxValue !== null && maxValue !== void 0 ? maxValue : newValue);
42
+ values[i] = Math.min(newValue, maxValue ?? newValue);
43
43
  }
44
44
  } while (true);
45
45
  return values;
@@ -0,0 +1 @@
1
+ export declare function isColorDark(color: string): boolean;
package/utils/color.js ADDED
@@ -0,0 +1,14 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isColorDark = isColorDark;
4
+ function isColorDark(color) {
5
+ if (color.startsWith('#')) {
6
+ color = color.substring(1);
7
+ }
8
+ const rgb = parseInt(color, 16);
9
+ const r = (rgb >> 16) & 0xff;
10
+ const g = (rgb >> 8) & 0xff;
11
+ const b = (rgb >> 0) & 0xff;
12
+ const luma = 0.2126 * r + 0.7152 * g + 0.0722 * b;
13
+ return luma < 128;
14
+ }
@@ -7,9 +7,12 @@ export declare function getAttributeFormattedValue<A extends Attribute = Attribu
7
7
  maxCount?: number;
8
8
  strings?: AttributeFormattedValueStringsSet;
9
9
  dateFormat?: string;
10
+ timeFormat?: string;
10
11
  locale?: string;
11
12
  currency?: string;
12
13
  currencySign?: 'accounting' | 'standard';
13
14
  currencyDisplay?: 'symbol' | 'narrowSymbol' | 'code';
14
- }): string | null | undefined;
15
+ timezone?: string;
16
+ region?: string;
17
+ }): string | null;
15
18
  export {};