dinocollab-core 2.1.27 → 2.1.29

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 (195) hide show
  1. package/dist/_virtual/_rollupPluginBabelHelpers.js +2 -2
  2. package/dist/src/api-context/alert-global.js +1 -1
  3. package/dist/src/api-context/alert-global.js.map +1 -1
  4. package/dist/src/api-context/drawer-global.js +1 -1
  5. package/dist/src/api-context/drawer-global.js.map +1 -1
  6. package/dist/src/api-context/global-modal.js +1 -1
  7. package/dist/src/api-context/global-modal.js.map +1 -1
  8. package/dist/src/api-context/popover-global.js +1 -1
  9. package/dist/src/api-context/popover-global.js.map +1 -1
  10. package/dist/src/api-context/popover.js +1 -1
  11. package/dist/src/api-context/popover.js.map +1 -1
  12. package/dist/src/components/breadcrumbs.js +1 -1
  13. package/dist/src/components/breadcrumbs.js.map +1 -1
  14. package/dist/src/components/copy-to-clipboard.js +1 -1
  15. package/dist/src/components/copy-to-clipboard.js.map +1 -1
  16. package/dist/src/components/create.multi-select-dropdown.js +1 -1
  17. package/dist/src/components/create.multi-select-dropdown.js.map +1 -1
  18. package/dist/src/components/help-tooltip.js +1 -1
  19. package/dist/src/components/help-tooltip.js.map +1 -1
  20. package/dist/src/components/image-with-fallback.js +1 -1
  21. package/dist/src/components/image-with-fallback.js.map +1 -1
  22. package/dist/src/components/rich-tooltip.js +1 -1
  23. package/dist/src/components/rich-tooltip.js.map +1 -1
  24. package/dist/src/components/text-editor.js +1 -1
  25. package/dist/src/components/text-editor.js.map +1 -1
  26. package/dist/src/components/text-editor.preview.js +1 -1
  27. package/dist/src/components/text-editor.preview.js.map +1 -1
  28. package/dist/src/data-view/animation-switch.js +1 -1
  29. package/dist/src/data-view/animation-switch.js.map +1 -1
  30. package/dist/src/data-view/convert-filter-to-graphql.js +1 -1
  31. package/dist/src/data-view/convert-filter-to-graphql.js.map +1 -1
  32. package/dist/src/data-view/create.active-filters-panel.js +1 -1
  33. package/dist/src/data-view/create.active-filters-panel.js.map +1 -1
  34. package/dist/src/data-view/create.data-view.js +1 -1
  35. package/dist/src/data-view/create.data-view.js.map +1 -1
  36. package/dist/src/data-view/create.filter-bar.js +1 -1
  37. package/dist/src/data-view/create.filter-bar.js.map +1 -1
  38. package/dist/src/data-view/create.filter-menu.js +1 -1
  39. package/dist/src/data-view/create.filter-menu.js.map +1 -1
  40. package/dist/src/data-view/create.pagination-bar.js +1 -1
  41. package/dist/src/data-view/create.pagination-bar.js.map +1 -1
  42. package/dist/src/data-view/create.popper-panel.js +1 -1
  43. package/dist/src/data-view/create.popper-panel.js.map +1 -1
  44. package/dist/src/data-view/create.search-match.js +1 -1
  45. package/dist/src/data-view/create.search-match.js.map +1 -1
  46. package/dist/src/data-view/create.sort-menu.js +1 -1
  47. package/dist/src/data-view/create.sort-menu.js.map +1 -1
  48. package/dist/src/data-view/create.view-mode.js +1 -1
  49. package/dist/src/data-view/create.view-mode.js.map +1 -1
  50. package/dist/src/data-view/dino.js +1 -1
  51. package/dist/src/data-view/dino.js.map +1 -1
  52. package/dist/src/data-view/filter-store.js +1 -1
  53. package/dist/src/data-view/filter-store.js.map +1 -1
  54. package/dist/src/data-view/helpers.js +1 -1
  55. package/dist/src/data-view/helpers.js.map +1 -1
  56. package/dist/src/data-view/scroll-tracking.js +1 -1
  57. package/dist/src/data-view/scroll-tracking.js.map +1 -1
  58. package/dist/src/data-view/ui.units.js +1 -1
  59. package/dist/src/data-view/ui.units.js.map +1 -1
  60. package/dist/src/data-view/view-mode.content.js +1 -1
  61. package/dist/src/data-view/view-mode.content.js.map +1 -1
  62. package/dist/src/data-view/view-mode.units.js +1 -1
  63. package/dist/src/data-view/view-mode.units.js.map +1 -1
  64. package/dist/src/form/create.autocomplete.chips.js +1 -1
  65. package/dist/src/form/create.autocomplete.chips.js.map +1 -1
  66. package/dist/src/form/create.color-picker.js +1 -1
  67. package/dist/src/form/create.color-picker.js.map +1 -1
  68. package/dist/src/form/create.date-expired.js +1 -1
  69. package/dist/src/form/create.date-expired.js.map +1 -1
  70. package/dist/src/form/create.date-picker.js +1 -1
  71. package/dist/src/form/create.date-picker.js.map +1 -1
  72. package/dist/src/form/create.form-base.js +1 -1
  73. package/dist/src/form/create.form-base.js.map +1 -1
  74. package/dist/src/form/create.form-comfirm.js +1 -1
  75. package/dist/src/form/create.form-comfirm.js.map +1 -1
  76. package/dist/src/form/create.form-grid-layout.js +1 -1
  77. package/dist/src/form/create.form-grid-layout.js.map +1 -1
  78. package/dist/src/form/create.input-file.csv-local-parser.js +1 -1
  79. package/dist/src/form/create.input-file.csv-local-parser.js.map +1 -1
  80. package/dist/src/form/create.input.file.js +1 -1
  81. package/dist/src/form/create.input.file.js.map +1 -1
  82. package/dist/src/form/create.input.image-file.js +1 -1
  83. package/dist/src/form/create.input.image-file.js.map +1 -1
  84. package/dist/src/form/create.input.js +1 -1
  85. package/dist/src/form/create.input.js.map +1 -1
  86. package/dist/src/form/create.select-simple.js +1 -1
  87. package/dist/src/form/create.select-simple.js.map +1 -1
  88. package/dist/src/form/create.select-with-api.js +1 -1
  89. package/dist/src/form/create.select-with-api.js.map +1 -1
  90. package/dist/src/form/create.text-editor.js +1 -1
  91. package/dist/src/form/create.text-editor.js.map +1 -1
  92. package/dist/src/form/decorator.form.js +1 -1
  93. package/dist/src/form/decorator.form.js.map +1 -1
  94. package/dist/src/form/decorator.js +1 -1
  95. package/dist/src/form/decorator.js.map +1 -1
  96. package/dist/src/form/dino-form.js +1 -1
  97. package/dist/src/form/dino-form.js.map +1 -1
  98. package/dist/src/form/helpers.js +1 -1
  99. package/dist/src/form/helpers.js.map +1 -1
  100. package/dist/src/form/modal-wrapper.js +1 -1
  101. package/dist/src/form/modal-wrapper.js.map +1 -1
  102. package/dist/src/form/validator.js +1 -1
  103. package/dist/src/form/validator.js.map +1 -1
  104. package/dist/src/hooks/check-scrolled.js +1 -1
  105. package/dist/src/hooks/check-scrolled.js.map +1 -1
  106. package/dist/src/hooks/debounce.js +1 -1
  107. package/dist/src/hooks/debounce.js.map +1 -1
  108. package/dist/src/hooks/use-fetch-data.js +1 -1
  109. package/dist/src/hooks/use-fetch-data.js.map +1 -1
  110. package/dist/src/http-service/base/crud-service-base.js +1 -1
  111. package/dist/src/http-service/base/crud-service-base.js.map +1 -1
  112. package/dist/src/http-service/base/helpers.js +1 -1
  113. package/dist/src/http-service/base/helpers.js.map +1 -1
  114. package/dist/src/http-service/base/service-base.js +1 -1
  115. package/dist/src/http-service/base/service-base.js.map +1 -1
  116. package/dist/src/http-service/graphql/app-profile.js +1 -1
  117. package/dist/src/http-service/graphql/app-profile.js.map +1 -1
  118. package/dist/src/http-service/graphql/graphql-request.js +1 -1
  119. package/dist/src/http-service/graphql/graphql-request.js.map +1 -1
  120. package/dist/src/http-service/graphql/request-param.js +1 -1
  121. package/dist/src/http-service/graphql/request-param.js.map +1 -1
  122. package/dist/src/lab/attach-widget/helpers.js +1 -1
  123. package/dist/src/lab/attach-widget/helpers.js.map +1 -1
  124. package/dist/src/lab/attach-widget/modal.js +1 -1
  125. package/dist/src/lab/attach-widget/modal.js.map +1 -1
  126. package/dist/src/lab/attach-widget/styled.js +1 -1
  127. package/dist/src/lab/attach-widget/styled.js.map +1 -1
  128. package/dist/src/lab/attach-widget/widget.js +1 -1
  129. package/dist/src/lab/attach-widget/widget.js.map +1 -1
  130. package/dist/src/lab/input.social-links/create.js +1 -1
  131. package/dist/src/lab/input.social-links/create.js.map +1 -1
  132. package/dist/src/lab/input.social-links/units.js +1 -1
  133. package/dist/src/lab/input.social-links/units.js.map +1 -1
  134. package/dist/src/mfe-shared/navigation.js +1 -1
  135. package/dist/src/mfe-shared/navigation.js.map +1 -1
  136. package/dist/src/redux/create.hoc-lazy.js +1 -1
  137. package/dist/src/redux/create.hoc-lazy.js.map +1 -1
  138. package/dist/src/redux/dino.js +1 -1
  139. package/dist/src/redux/dino.js.map +1 -1
  140. package/dist/src/redux/ui.error-page.js +1 -1
  141. package/dist/src/redux/ui.error-page.js.map +1 -1
  142. package/dist/src/table/create.action-row.js +1 -1
  143. package/dist/src/table/create.action-row.js.map +1 -1
  144. package/dist/src/table/create.table.js +1 -1
  145. package/dist/src/table/create.table.js.map +1 -1
  146. package/dist/src/table/custom.filter-operators.js +1 -1
  147. package/dist/src/table/custom.filter-operators.js.map +1 -1
  148. package/dist/src/table/dino.js +1 -1
  149. package/dist/src/table/dino.js.map +1 -1
  150. package/dist/src/table/helpers.js +1 -1
  151. package/dist/src/table/helpers.js.map +1 -1
  152. package/dist/src/table/toolbar-pannel.js +1 -1
  153. package/dist/src/table/toolbar-pannel.js.map +1 -1
  154. package/dist/src/table/ui.buttons.js +1 -1
  155. package/dist/src/table/ui.buttons.js.map +1 -1
  156. package/dist/src/table/ui.units.js +1 -1
  157. package/dist/src/table/ui.units.js.map +1 -1
  158. package/dist/src/table-grid/create.table-grid.js +1 -1
  159. package/dist/src/table-grid/create.table-grid.js.map +1 -1
  160. package/dist/src/table-grid/dino.js +1 -1
  161. package/dist/src/table-grid/dino.js.map +1 -1
  162. package/dist/src/table-grid/filter-bar/base.js +1 -1
  163. package/dist/src/table-grid/filter-bar/base.js.map +1 -1
  164. package/dist/src/table-grid/filter-bar/create.filter-bar.js +1 -1
  165. package/dist/src/table-grid/filter-bar/create.filter-bar.js.map +1 -1
  166. package/dist/src/table-grid/filter-bar/create.filter-menu.js +1 -1
  167. package/dist/src/table-grid/filter-bar/create.filter-menu.js.map +1 -1
  168. package/dist/src/table-grid/filter-bar/create.filter-panel.js +1 -1
  169. package/dist/src/table-grid/filter-bar/create.filter-panel.js.map +1 -1
  170. package/dist/src/table-grid/filter-bar/create.filtered.js +1 -1
  171. package/dist/src/table-grid/filter-bar/create.filtered.js.map +1 -1
  172. package/dist/src/table-grid/filter-bar/ui.units.js +1 -1
  173. package/dist/src/table-grid/filter-bar/ui.units.js.map +1 -1
  174. package/dist/src/table-grid/helpers.js +1 -1
  175. package/dist/src/table-grid/helpers.js.map +1 -1
  176. package/dist/src/table-grid/item-actions.js +1 -1
  177. package/dist/src/table-grid/item-actions.js.map +1 -1
  178. package/dist/src/table-grid/styled.js +2 -0
  179. package/dist/src/table-grid/styled.js.map +1 -0
  180. package/dist/src/table-grid/toolbar-pannel.js +1 -1
  181. package/dist/src/table-grid/toolbar-pannel.js.map +1 -1
  182. package/dist/src/table-grid/url-query-param.js +1 -1
  183. package/dist/src/table-grid/url-query-param.js.map +1 -1
  184. package/dist/src/utils/helpers.js +1 -1
  185. package/dist/src/utils/helpers.js.map +1 -1
  186. package/dist/src/utils/json-object.js +1 -1
  187. package/dist/src/utils/json-object.js.map +1 -1
  188. package/dist/src/utils/query-param.js +1 -1
  189. package/dist/src/utils/query-param.js.map +1 -1
  190. package/dist/types/mfe-shared/navigation.d.ts +5 -2
  191. package/dist/types/table-grid/create.table-grid.d.ts +2 -2
  192. package/dist/types/table-grid/helpers.d.ts +0 -11
  193. package/dist/types/table-grid/styled.d.ts +19 -0
  194. package/dist/types/table-grid/types.d.ts +6 -1
  195. package/package.json +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"service-base.js","sources":["../../../../src/http-service/base/service-base.ts"],"sourcesContent":["import { authService } from 'partner-oidc-auth'\r\nimport type { AxiosError, AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios'\r\nimport axios from 'axios'\r\nimport { HttpService } from './gateway'\r\nimport { handleResponseError, ApiAlertContext } from './helpers'\r\n\r\n/**\r\n * Base service class for HTTP operations with authentication and error handling\r\n * Provides common CRUD operations with automatic token management and retry logic\r\n */\r\nexport default class ServiceBase {\r\n private _http: AxiosInstance\r\n constructor(http?: AxiosInstance) {\r\n if (http) {\r\n this._http = http\r\n } else {\r\n this._http = HttpService\r\n }\r\n this.mapResponse()\r\n }\r\n /**\r\n * Maps response and request interceptors for handling authentication and errors\r\n * Automatically adds authorization headers and retries requests on 401 errors\r\n */\r\n mapResponse = () => {\r\n this._http.interceptors.response.use(\r\n (res) => res,\r\n (err) => this.tryFetchToken(err, handleResponseError)\r\n )\r\n this._http.interceptors.request.use((req) => {\r\n return this.interuptHeader(req)\r\n })\r\n }\r\n /**\r\n * Tries to fetch a new token if the current one is expired\r\n * @param error - The axios error containing response data\r\n * @param next - The next middleware function to call\r\n * @returns A promise resolving to the response data or an error\r\n */\r\n tryFetchToken = async (error: AxiosError, next: (error: AxiosError) => Promise<any>): Promise<any> => {\r\n const originalRequest = error.config\r\n if (error?.response?.status === 401 && originalRequest) {\r\n await authService.signIn({})\r\n await this.interuptHeader(originalRequest)\r\n return axios(originalRequest)\r\n }\r\n return next(error)\r\n }\r\n private _token?: string\r\n /**\r\n * Sets the token to be used for authentication\r\n * @param token - The token string to set\r\n */\r\n setToken(token?: string) {\r\n this._token = token\r\n }\r\n /**\r\n * Gets the current token, fetching a new one if not set\r\n * @returns A promise resolving to the token string\r\n */\r\n getToken = async () => {\r\n return this._token === undefined ? await authService.getAccessToken() : this._token\r\n }\r\n /**\r\n * Adds custom headers to the request configuration\r\n * @param config - The Axios request configuration object\r\n * @returns A promise resolving to the updated configuration object\r\n */\r\n async addCustomHeader(config?: AxiosRequestConfig) {\r\n if (!config) {\r\n config = { headers: {} }\r\n }\r\n if (!config.headers) {\r\n config.headers = {}\r\n }\r\n return config\r\n }\r\n /**\r\n * Intercepts the request to add the authorization token\r\n * @param config - The Axios request configuration object\r\n * @returns The updated configuration object with the token added\r\n */\r\n private async interuptHeader(config: InternalAxiosRequestConfig) {\r\n await this.addtoken(config)\r\n return config\r\n }\r\n /**\r\n * Adds the authorization token to the request headers\r\n * @param config - The Axios request configuration object\r\n * @returns The updated configuration object with the token added\r\n */\r\n private addtoken = async (config?: AxiosRequestConfig) => {\r\n const _token = await this.getToken()\r\n if (_token && config?.headers) {\r\n config.headers.Authorization = 'Bearer ' + _token\r\n }\r\n return config\r\n }\r\n /**\r\n * HTTP GET request with automatic authentication\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async get<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.get<TModel>(url, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP GET request with error handling\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryGet<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return this.get<TModel>(url, config)\r\n } catch {\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP POST request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async post<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.post<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PUT request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async put<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.put<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PUT request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPut<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n await this.addCustomHeader(config)\r\n return await this.put<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP PATCH request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async patch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.patch<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PATCH request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPatch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n await this.addCustomHeader(config)\r\n return await this.patch<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP POST request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPost<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return await this.post<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP DELETE request with automatic authentication\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async delete<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.delete<TModel>(url, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP DELETE request with error handling\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryDelete<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return await this.delete<TModel>(url, await this.addCustomHeader(config))\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * Push notification with error handling\r\n * @param action - The function to execute\r\n * @param p - Parameters to pass to the function\r\n * @returns Promise with the result of the function execution\r\n */\r\n async tryPushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>) {\r\n try {\r\n return await this.pushNotify(action, ...p)\r\n } catch (err) {}\r\n }\r\n /**\r\n * Push notification with error handling\r\n * @param action - The function to execute\r\n * @param p - Parameters to pass to the function\r\n * @returns Promise with the result of the function execution\r\n */\r\n async pushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>): Promise<ReturnType<TFunc>> {\r\n try {\r\n return await action.bind(this)(...p)\r\n } catch (err) {\r\n const error = err as AxiosError\r\n const data = error.response?.data as any\r\n if (data) {\r\n const keys = Object.keys(data)\r\n keys.forEach((key) => {\r\n const errors = data[key] as string[]\r\n if (Array.isArray(errors)) {\r\n errors.forEach((message) => {\r\n ApiAlertContext?.ApiAlert?.PushError(message)\r\n })\r\n }\r\n })\r\n }\r\n throw error\r\n }\r\n }\r\n}\r\n/**\r\n * CancelAction class extends AbortController to provide a cancel method\r\n * This class can be used to cancel ongoing HTTP requests\r\n */\r\nexport class CancelAction extends AbortController {\r\n cancel = () => {\r\n this.trigger && this.trigger()\r\n super.abort()\r\n }\r\n trigger?: () => void\r\n}\r\n"],"names":["ServiceBase","_createClass","http","_this","this","_classCallCheck","_defineProperty","_http","interceptors","response","use","res","err","tryFetchToken","handleResponseError","request","req","interuptHeader","_ref","_asyncToGenerator","_regenerator","m","_callee","error","next","_error$response","originalRequest","w","_context","n","config","status","authService","signIn","a","axios","_x","_x2","apply","arguments","_callee2","_t","_context2","undefined","_token","getAccessToken","v","_ref3","_callee3","_context3","getToken","headers","Authorization","_x3","HttpService","mapResponse","key","value","token","_addCustomHeader","_callee4","_context4","_x4","_interuptHeader","_callee5","_context5","addtoken","_x5","_get","_callee6","url","_t2","_t3","_t4","_context6","addCustomHeader","get","call","data","_x6","_x7","_tryGet","_callee7","_context7","p","_x8","_x9","_post","_callee8","_t6","_t7","_t8","_t9","_context8","post","_x0","_x1","_x10","_put","_callee9","_t0","_t1","_t10","_t11","_context9","put","_x11","_x12","_x13","_tryPut","_callee0","_context0","_x14","_x15","_x16","_patch","_callee1","_t13","_t14","_t15","_t16","_context1","patch","_x17","_x18","_x19","_tryPatch","_callee10","_context10","_x20","_x21","_x22","_tryPost","_callee11","_context11","_x23","_x24","_x25","_delete2","_callee12","_t19","_t20","_t21","_context12","_x26","_x27","_tryDelete","_callee13","_t22","_t23","_t24","_context13","_x28","_x29","_tryPushNotify","_callee14","action","_len","_key","_args14","_context14","length","Array","pushNotify","concat","_x30","_pushNotify","_callee15","_len2","_key2","_error$response2","_t27","_args15","_context15","bind","Object","keys","forEach","errors","isArray","message","_ApiAlertContext$ApiA","ApiAlertContext","ApiAlert","PushError","_x31","CancelAction","_AbortController","_this2","_len3","args","_key3","_callSuper","trigger","_superPropGet","_inherits","_wrapNativeSuper","AbortController"],"mappings":"wZAMA,IAIqBA,EAAW,WAS7B,OAAAC,GAPD,SAAAD,EAAYE,GAAoB,IAAAC,EAAAC,KAAAC,OAAAL,GAQhCM,sBAIc,WACZH,EAAKI,MAAMC,aAAaC,SAASC,KAC/B,SAACC,GAAG,OAAKA,CAAG,IACZ,SAACC,GAAG,OAAKT,EAAKU,cAAcD,EAAKE,MAEnCX,EAAKI,MAAMC,aAAaO,QAAQL,KAAI,SAACM,GACnC,OAAOb,EAAKc,eAAeD,EAC7B,OAEFV,EAAAF,KAAA,gBAAA,WAAA,IAAAc,EAAAC,EAAAC,IAAAC,GAMgB,SAAAC,EAAOC,EAAmBC,GAAyC,IAAAC,EAAAC,EAAA,OAAAN,IAAAO,GAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA,KAAA,EAC7C,GAA9BH,EAAkBH,EAAMO,OACE,OAA5BP,SAAeE,QAAVA,EAALF,EAAOd,oBAAQgB,SAAfA,EAAiBM,UAAkBL,EAAe,CAAAE,EAAAC,EAAA,EAAA,KAAA,CAAA,OAAAD,EAAAC,EAAA,EAC9CG,EAAYC,OAAO,IAAG,KAAA,EAAA,OAAAL,EAAAC,EAAA,EACtB1B,EAAKc,eAAeS,GAAgB,KAAA,EAAA,OAAAE,EAAAM,IACnCC,EAAMT,IAAgB,KAAA,EAAA,OAAAE,EAAAM,IAExBV,EAAKD,IAAM,GAAAD,OACnB,OAAAc,SAAAA,EAAAC,GAAA,OAAAnB,EAAAoB,MAAAlC,KAAAmC,UAAA,CAA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AA1L,EAAAyL,EAAA,EAAAU,EAJ+BC"}
1
+ {"version":3,"file":"service-base.js","sources":["../../../../src/http-service/base/service-base.ts"],"sourcesContent":["import { authService } from 'partner-oidc-auth'\r\nimport type { AxiosError, AxiosInstance, AxiosRequestConfig, InternalAxiosRequestConfig } from 'axios'\r\nimport axios from 'axios'\r\nimport { HttpService } from './gateway'\r\nimport { handleResponseError, ApiAlertContext } from './helpers'\r\n\r\n/**\r\n * Base service class for HTTP operations with authentication and error handling\r\n * Provides common CRUD operations with automatic token management and retry logic\r\n */\r\nexport default class ServiceBase {\r\n private _http: AxiosInstance\r\n constructor(http?: AxiosInstance) {\r\n if (http) {\r\n this._http = http\r\n } else {\r\n this._http = HttpService\r\n }\r\n this.mapResponse()\r\n }\r\n /**\r\n * Maps response and request interceptors for handling authentication and errors\r\n * Automatically adds authorization headers and retries requests on 401 errors\r\n */\r\n mapResponse = () => {\r\n this._http.interceptors.response.use(\r\n (res) => res,\r\n (err) => this.tryFetchToken(err, handleResponseError)\r\n )\r\n this._http.interceptors.request.use((req) => {\r\n return this.interuptHeader(req)\r\n })\r\n }\r\n /**\r\n * Tries to fetch a new token if the current one is expired\r\n * @param error - The axios error containing response data\r\n * @param next - The next middleware function to call\r\n * @returns A promise resolving to the response data or an error\r\n */\r\n tryFetchToken = async (error: AxiosError, next: (error: AxiosError) => Promise<any>): Promise<any> => {\r\n const originalRequest = error.config\r\n if (error?.response?.status === 401 && originalRequest) {\r\n await authService.signIn({})\r\n await this.interuptHeader(originalRequest)\r\n return axios(originalRequest)\r\n }\r\n return next(error)\r\n }\r\n private _token?: string\r\n /**\r\n * Sets the token to be used for authentication\r\n * @param token - The token string to set\r\n */\r\n setToken(token?: string) {\r\n this._token = token\r\n }\r\n /**\r\n * Gets the current token, fetching a new one if not set\r\n * @returns A promise resolving to the token string\r\n */\r\n getToken = async () => {\r\n return this._token === undefined ? await authService.getAccessToken() : this._token\r\n }\r\n /**\r\n * Adds custom headers to the request configuration\r\n * @param config - The Axios request configuration object\r\n * @returns A promise resolving to the updated configuration object\r\n */\r\n async addCustomHeader(config?: AxiosRequestConfig) {\r\n if (!config) {\r\n config = { headers: {} }\r\n }\r\n if (!config.headers) {\r\n config.headers = {}\r\n }\r\n return config\r\n }\r\n /**\r\n * Intercepts the request to add the authorization token\r\n * @param config - The Axios request configuration object\r\n * @returns The updated configuration object with the token added\r\n */\r\n private async interuptHeader(config: InternalAxiosRequestConfig) {\r\n await this.addtoken(config)\r\n return config\r\n }\r\n /**\r\n * Adds the authorization token to the request headers\r\n * @param config - The Axios request configuration object\r\n * @returns The updated configuration object with the token added\r\n */\r\n private addtoken = async (config?: AxiosRequestConfig) => {\r\n const _token = await this.getToken()\r\n if (_token && config?.headers) {\r\n config.headers.Authorization = 'Bearer ' + _token\r\n }\r\n return config\r\n }\r\n /**\r\n * HTTP GET request with automatic authentication\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async get<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.get<TModel>(url, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP GET request with error handling\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryGet<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return this.get<TModel>(url, config)\r\n } catch {\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP POST request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async post<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.post<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PUT request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async put<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.put<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PUT request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPut<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n await this.addCustomHeader(config)\r\n return await this.put<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP PATCH request with automatic authentication\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async patch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.patch<TModel>(url, data, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP PATCH request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPatch<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n await this.addCustomHeader(config)\r\n return await this.patch<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP POST request with error handling\r\n * @param url - The request URL\r\n * @param data - Optional data to send in the request body\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryPost<TModel>(url: string, data?: any, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return await this.post<TModel>(url, data, config)\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * HTTP DELETE request with automatic authentication\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data\r\n */\r\n async delete<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n const response = await this._http.delete<TModel>(url, await this.addCustomHeader(config))\r\n return response.data\r\n }\r\n /**\r\n * HTTP DELETE request with error handling\r\n * @param url - The request URL\r\n * @param config - Optional axios configuration\r\n * @returns Promise with the response data or null if an error occurs\r\n */\r\n async tryDelete<TModel>(url: string, config?: AxiosRequestConfig | undefined) {\r\n try {\r\n return await this.delete<TModel>(url, await this.addCustomHeader(config))\r\n } catch (error) {\r\n // processError(error as any)\r\n return null\r\n }\r\n }\r\n /**\r\n * Push notification with error handling\r\n * @param action - The function to execute\r\n * @param p - Parameters to pass to the function\r\n * @returns Promise with the result of the function execution\r\n */\r\n async tryPushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>) {\r\n try {\r\n return await this.pushNotify(action, ...p)\r\n } catch (err) {}\r\n }\r\n /**\r\n * Push notification with error handling\r\n * @param action - The function to execute\r\n * @param p - Parameters to pass to the function\r\n * @returns Promise with the result of the function execution\r\n */\r\n async pushNotify<TFunc extends (...param: any[]) => any>(action: TFunc, ...p: Parameters<TFunc>): Promise<ReturnType<TFunc>> {\r\n try {\r\n return await action.bind(this)(...p)\r\n } catch (err) {\r\n const error = err as AxiosError\r\n const data = error.response?.data as any\r\n if (data) {\r\n const keys = Object.keys(data)\r\n keys.forEach((key) => {\r\n const errors = data[key] as string[]\r\n if (Array.isArray(errors)) {\r\n errors.forEach((message) => {\r\n ApiAlertContext?.ApiAlert?.PushError(message)\r\n })\r\n }\r\n })\r\n }\r\n throw error\r\n }\r\n }\r\n}\r\n/**\r\n * CancelAction class extends AbortController to provide a cancel method\r\n * This class can be used to cancel ongoing HTTP requests\r\n */\r\nexport class CancelAction extends AbortController {\r\n cancel = () => {\r\n this.trigger && this.trigger()\r\n super.abort()\r\n }\r\n trigger?: () => void\r\n}\r\n"],"names":["ServiceBase","_createClass","http","_this","this","_classCallCheck","_defineProperty","_http","interceptors","response","use","res","err","tryFetchToken","handleResponseError","request","req","interuptHeader","_ref","_asyncToGenerator","_regenerator","m","_callee","error","next","_error$response","originalRequest","w","_context","n","config","status","authService","signIn","a","axios","_x","_x2","apply","arguments","_callee2","_t","_context2","undefined","_token","getAccessToken","v","_ref3","_callee3","_context3","getToken","headers","Authorization","_x3","HttpService","mapResponse","key","value","token","_addCustomHeader","_callee4","_context4","_x4","_interuptHeader","_callee5","_context5","addtoken","_x5","_get","_callee6","url","_t2","_t3","_context6","addCustomHeader","get","call","data","_x6","_x7","_tryGet","_callee7","_context7","p","_x8","_x9","_post","_callee8","_t5","_t6","_t7","_context8","post","_x0","_x1","_x10","_put","_callee9","_t8","_t9","_t0","_context9","put","_x11","_x12","_x13","_tryPut","_callee0","_context0","_x14","_x15","_x16","_patch","_callee1","_t10","_t11","_t12","_context1","patch","_x17","_x18","_x19","_tryPatch","_callee10","_context10","_x20","_x21","_x22","_tryPost","_callee11","_context11","_x23","_x24","_x25","_delete2","_callee12","_t15","_t16","_context12","_x26","_x27","_tryDelete","_callee13","_t17","_t18","_context13","_x28","_x29","_tryPushNotify","_callee14","action","_len","_key","_args14","_context14","length","Array","pushNotify","concat","_x30","_pushNotify","_callee15","_len2","_key2","_error$response2","_t21","_args15","_context15","bind","Object","keys","forEach","errors","isArray","message","_ApiAlertContext$ApiA","ApiAlertContext","ApiAlert","PushError","_x31","CancelAction","_AbortController","_this2","_len3","args","_key3","_callSuper","trigger","_superPropGet","_inherits","_wrapNativeSuper","AbortController"],"mappings":"wZAMA,IAIqBA,EAAW,WAS7B,OAAAC,EAPD,SAAAD,EAAYE,GAAoB,IAAAC,EAAAC,KAAAC,OAAAL,GAQhCM,qBAIc,WACZH,EAAKI,MAAMC,aAAaC,SAASC,IAC/B,SAACC,GAAG,OAAKA,CAAG,EACZ,SAACC,GAAG,OAAKT,EAAKU,cAAcD,EAAKE,KAEnCX,EAAKI,MAAMC,aAAaO,QAAQL,IAAI,SAACM,GACnC,OAAOb,EAAKc,eAAeD,EAC7B,KAEFV,EAAAF,KA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OAAAnB,EAAA1H,MAAAlC,KAAAmC,UAAA,MANhB,IAAAyH,EAXAZ,EAdAP,EAVAP,EAfAN,EAhBAN,EAXAV,EAhBAN,EAXAV,EAXAV,EAbAN,EAVAZ,EArBAL,EAdAJ,CAmLgB,CAxOc,GAiQnByH,WAAaC,GAAA,SAAAD,IAAA,IAAAE,EAAAjL,OAAA+K,GAAA,IAAA,IAAAG,EAAAhJ,UAAAoH,OAAA6B,EAAA5B,IAAAA,MAAA2B,GAAAE,EAAA,EAAAA,EAAAF,EAAAE,IAAAD,EAAAC,GAAAlJ,UAAAkJ,GAIvB,OAJuBH,EAAAI,EAAAtL,KAAAgL,EAAAtB,GAAAA,OAAA0B,IAAAlL,EAAAgL,EAAA,SACf,WACPA,EAAKK,SAAWL,EAAKK,UACrBC,EAAAR,UAAAE,EAAAM,CAAA,MACDN,CAAA,CAAA,OAAAO,EAAAT,EAAAC,GAAApL,EAAAmL,EAAA,EAAAU,EAJ+BC"}
@@ -1,2 +1,2 @@
1
- import{createClass as e,classCallCheck as n,defineProperty as r,asyncToGenerator as t,regenerator as a}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{authService as i}from"partner-oidc-auth";import{EAppName as s}from"./types.js";var o;!function(e){e.Admin="Admin",e.User="User",e.Manage="Manage"}(o||(o={}));var u=new(e((function e(){var u=this;n(this,e),r(this,"getAppName",(function(){return u.window.env.REACT_APP_NAME})),r(this,"isAdmin",(function(e){return(null!=e?e:[]).some((function(e){return e===o.Admin}))&&u.getAppName()===s.ClientAdmin})),r(this,"getGraphqlSite",t(a().m((function e(){var n,r,t;return a().w((function(e){for(;;)switch(e.n){case 0:return e.n=1,i.getRoles();case 1:n=e.v,r=u.getAppName(),t=r,e.n=t===s.ClientAdmin?2:(s.ClientApp,3);break;case 2:return e.a(2,u.isAdmin(n)?o.Admin:o.Manage);case 3:return e.a(2,o.User);case 4:return e.a(2)}}),e)})))),this.window=global.window})));export{u as AppProfile};
1
+ import{createClass as e,classCallCheck as n,defineProperty as r,asyncToGenerator as t,regenerator as a}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{authService as i}from"partner-oidc-auth";import{EAppName as s}from"./types.js";var o;!function(e){e.Admin="Admin",e.User="User",e.Manage="Manage"}(o||(o={}));var u=new(e(function e(){var u=this;n(this,e),r(this,"getAppName",function(){return u.window.env.REACT_APP_NAME}),r(this,"isAdmin",function(e){return(null!=e?e:[]).some(function(e){return e===o.Admin})&&u.getAppName()===s.ClientAdmin}),r(this,"getGraphqlSite",t(a().m(function e(){var n,r,t;return a().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,i.getRoles();case 1:n=e.v,r=u.getAppName(),t=r,e.n=t===s.ClientAdmin?2:(s.ClientApp,3);break;case 2:return e.a(2,u.isAdmin(n)?o.Admin:o.Manage);case 3:return e.a(2,o.User);case 4:return e.a(2)}},e)}))),this.window=global.window}));export{u as AppProfile};
2
2
  //# sourceMappingURL=app-profile.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"app-profile.js","sources":["../../../../src/http-service/graphql/app-profile.ts"],"sourcesContent":["import { authService } from 'partner-oidc-auth'\r\nimport { EAppName } from './types'\r\n\r\nenum RoleKeyInternalSite {\r\n Admin = 'Admin',\r\n User = 'User',\r\n Manage = 'Manage'\r\n}\r\n\r\nclass AppProfileBase {\r\n window: Window & { [key: string]: any }\r\n constructor() {\r\n this.window = global.window\r\n }\r\n\r\n getAppName = () => this.window.env.REACT_APP_NAME as EAppName\r\n\r\n isAdmin = (roles?: string[]) => {\r\n return (roles ?? []).some((e) => e === RoleKeyInternalSite.Admin) && this.getAppName() === EAppName.ClientAdmin\r\n }\r\n\r\n getGraphqlSite = async () => {\r\n const roles = await authService.getRoles()\r\n const appName = this.getAppName()\r\n switch (appName) {\r\n case EAppName.ClientAdmin:\r\n return this.isAdmin(roles) ? RoleKeyInternalSite.Admin : RoleKeyInternalSite.Manage\r\n case EAppName.ClientApp:\r\n default:\r\n return RoleKeyInternalSite.User\r\n }\r\n }\r\n}\r\n\r\nexport const AppProfile = new AppProfileBase()\r\n"],"names":["RoleKeyInternalSite","AppProfile","_createClass","AppProfileBase","_this","this","_classCallCheck","_defineProperty","window","env","REACT_APP_NAME","roles","some","e","Admin","getAppName","EAppName","ClientAdmin","_asyncToGenerator","_regenerator","m","_callee","appName","_t","w","_context","n","authService","getRoles","v","ClientApp","a","isAdmin","Manage","User","global"],"mappings":"kPAGA,IAAKA,GAAL,SAAKA,GACHA,EAAA,MAAA,QACAA,EAAA,KAAA,OACAA,EAAA,OAAA,QACD,CAJD,CAAKA,IAAAA,EAIJ,CAAA,IAAA,IA2BYC,EAAa,IAzBNC,GAElB,SAAAC,IAAA,IAAAC,EAAAC,KAAAC,OAAAH,GAAAI,EAIaF,KAAA,cAAA,WAAA,OAAMD,EAAKI,OAAOC,IAAIC,cAA0B,IAAAH,EAAAF,KAAA,WAEnD,SAACM,GACT,OAAQA,QAAAA,EAAS,IAAIC,MAAK,SAACC,GAAC,OAAKA,IAAMb,EAAoBc,KAAM,KAAIV,EAAKW,eAAiBC,EAASC,eACrGV,EAAAF,KAAA,iBAAAa,EAAAC,IAAAC,GAEgB,SAAAC,IAAA,IAAAV,EAAAW,EAAAC,EAAA,OAAAJ,IAAAK,GAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA,KAAA,EAAA,OAAAD,EAAAC,EAAA,EACKC,EAAYC,WAAU,KAAA,EAApCjB,EAAKc,EAAAI,EACLP,EAAUlB,EAAKW,aAAYQ,EACzBD,EAAOG,EAAAC,EAAAH,IACRP,EAASC,YAAWM,GAEpBP,EAASc,UAAS,GAAA,MAAA,KAAA,EAAA,OAAAL,EAAAM,EADd3B,EAAAA,EAAK4B,QAAQrB,GAASX,EAAoBc,MAAQd,EAAoBiC,QAAM,KAAA,EAAA,OAAAR,EAAAM,EAG5E/B,EAAAA,EAAoBkC,MAAI,KAAA,EAAA,OAAAT,EAAAM,EAAA,GAAA,GAAAV,EAEpC,MAnBChB,KAAKG,OAAS2B,OAAO3B,MACvB"}
1
+ {"version":3,"file":"app-profile.js","sources":["../../../../src/http-service/graphql/app-profile.ts"],"sourcesContent":["import { authService } from 'partner-oidc-auth'\r\nimport { EAppName } from './types'\r\n\r\nenum RoleKeyInternalSite {\r\n Admin = 'Admin',\r\n User = 'User',\r\n Manage = 'Manage'\r\n}\r\n\r\nclass AppProfileBase {\r\n window: Window & { [key: string]: any }\r\n constructor() {\r\n this.window = global.window\r\n }\r\n\r\n getAppName = () => this.window.env.REACT_APP_NAME as EAppName\r\n\r\n isAdmin = (roles?: string[]) => {\r\n return (roles ?? []).some((e) => e === RoleKeyInternalSite.Admin) && this.getAppName() === EAppName.ClientAdmin\r\n }\r\n\r\n getGraphqlSite = async () => {\r\n const roles = await authService.getRoles()\r\n const appName = this.getAppName()\r\n switch (appName) {\r\n case EAppName.ClientAdmin:\r\n return this.isAdmin(roles) ? RoleKeyInternalSite.Admin : RoleKeyInternalSite.Manage\r\n case EAppName.ClientApp:\r\n default:\r\n return RoleKeyInternalSite.User\r\n }\r\n }\r\n}\r\n\r\nexport const AppProfile = new AppProfileBase()\r\n"],"names":["RoleKeyInternalSite","AppProfile","_createClass","AppProfileBase","_this","this","_classCallCheck","_defineProperty","window","env","REACT_APP_NAME","roles","some","e","Admin","getAppName","EAppName","ClientAdmin","_asyncToGenerator","_regenerator","m","_callee","appName","_t","w","_context","n","authService","getRoles","v","ClientApp","a","isAdmin","Manage","User","global"],"mappings":"kPAGA,IAAKA,GAAL,SAAKA,GACHA,EAAA,MAAA,QACAA,EAAA,KAAA,OACAA,EAAA,OAAA,QACD,CAJD,CAAKA,IAAAA,EAIJ,CAAA,IAAA,IA2BYC,EAAa,IAzBNC,EAElB,SAAAC,IAAA,IAAAC,EAAAC,KAAAC,OAAAH,GAAAI,EAIaF,KAAA,aAAA,WAAA,OAAMD,EAAKI,OAAOC,IAAIC,cAA0B,GAAAH,EAAAF,KAAA,UAEnD,SAACM,GACT,OAAQA,QAAAA,EAAS,IAAIC,KAAK,SAACC,GAAC,OAAKA,IAAMb,EAAoBc,KAAM,IAAIV,EAAKW,eAAiBC,EAASC,cACrGV,EAAAF,KAAA,iBAAAa,EAAAC,IAAAC,EAEgB,SAAAC,IAAA,IAAAV,EAAAW,EAAAC,EAAA,OAAAJ,IAAAK,EAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA,KAAA,EAAA,OAAAD,EAAAC,EAAA,EACKC,EAAYC,WAAU,KAAA,EAApCjB,EAAKc,EAAAI,EACLP,EAAUlB,EAAKW,aAAYQ,EACzBD,EAAOG,EAAAC,EAAAH,IACRP,EAASC,YAAWM,GAEpBP,EAASc,UAAS,GAAA,MAAA,KAAA,EAAA,OAAAL,EAAAM,EADd3B,EAAAA,EAAK4B,QAAQrB,GAASX,EAAoBc,MAAQd,EAAoBiC,QAAM,KAAA,EAAA,OAAAR,EAAAM,EAG5E/B,EAAAA,EAAoBkC,MAAI,KAAA,EAAA,OAAAT,EAAAM,EAAA,GAAA,EAAAV,EAEpC,KAnBChB,KAAKG,OAAS2B,OAAO3B,MACvB"}
@@ -1,2 +1,2 @@
1
- import{inherits as e,createClass as t,asyncToGenerator as r,objectSpread2 as n,classCallCheck as i,callSuper as a,defineProperty as s,regenerator as o,typeof as u,superPropGet as l,toConsumableArray as c}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{AppProfile as f}from"./app-profile.js";import{fetchDelay as p,ApiAlertContext as h}from"../base/helpers.js";import{createHttpService as v}from"../base/gateway.js";import d from"../base/service-base.js";var w=function(){function w(e){var t,n,l,c;(i(this,w),l=a(this,w,[v(e.baseUrl)]),s(l,"setSite",(function(e){l.site=e})),s(l,"setGraphQLExecutor",function(){var e=r(o().m((function e(t,r,n,i){var a,s;return o().w((function(e){for(;;)switch(e.n){case 0:return a={signal:n},e.n=1,l.addCustomHeader(a,i);case 1:return s=e.v,e.a(2,l.post("",{query:t,variables:r},s))}}),e)})));return function(t,r,n,i){return e.apply(this,arguments)}}()),s(l,"_getSite",r(o().m((function e(){var t;return o().w((function(e){for(;;)switch(e.n){case 0:if(t=global.window,"object"!==u(t.wwfd)&&(t.wwfd={}),t.wwfd.GraphqlSite){e.n=2;break}return e.n=1,f.getGraphqlSite();case 1:t.wwfd.GraphqlSite=e.v;case 2:return e.a(2,t.wwfd.GraphqlSite)}}),e)})))),s(l,"autoDetectSite",r(o().m((function e(){var t;return o().w((function(e){for(;;)switch(e.n){case 0:return e.n=1,l.getSite();case 1:t=e.v,l.setSite(t);case 2:return e.a(2)}}),e)})))),s(l,"getParamExecutor",(function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=t[0],i=t[1],a=t[2],s=t[3];if("string"!=typeof n||0===n.length)throw new Error("Request must be a non-empty string");if("object"!==u(i))throw new Error("Variables must be an object");if(a&&!(a instanceof AbortSignal))throw new Error("Signal must be an instance of AbortSignal");return[n,i,a,s]})),l._options=null!==(t=e.options)&&void 0!==t?t:{},l._execute=e.execute,l.getSite=l._getSite,null!==(n=e.options)&&void 0!==n&&n.site&&"function"==typeof e.options.site)?l.getSite=e.options.site:l.site=null===(c=e.options)||void 0===c?void 0:c.site;return l}return e(w,d),t(w,[{key:"addSite",value:function(e,t){return this.site&&null!=e&&e.headers&&!t&&(e.headers["graphql-site"]=this.site),null!=e?e:{}}},{key:"addCustomHeader",value:(m=r(o().m((function e(t,r){var n;return o().w((function(e){for(;;)switch(e.n){case 0:return e.n=1,l(w,"addCustomHeader",this)([t]);case 1:return n=e.v,e.a(2,this.addSite(n,r))}}),e,this)}))),function(e,t){return m.apply(this,arguments)})},{key:"query",value:(y=r(o().m((function e(t,r){var i,a,s,u,l=this;return o().w((function(e){for(;;)switch(e.n){case 0:if(i=this._options.autoDetectSite,a=this._options.ignoreSite,void 0!==(null==r?void 0:r.autoDetectSite)&&(i=r.autoDetectSite),void 0!==(null==r?void 0:r.ignoreSite)&&(a=r.ignoreSite),a||!1===i){e.n=2;break}return e.n=1,this.autoDetectSite();case 1:e.n=3;break;case 2:!a&&null!=r&&r.site&&this.setSite(null!==(s=r.site)&&void 0!==s?s:this._options.site);case 3:return e.n=4,this._execute(t,n({executor:function(){for(var e,t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return(null==r?void 0:r.signal)&&n.push(null==r?void 0:r.signal),n.push(a),p((function(){return l.setGraphQLExecutor.apply(l,c(l.getParamExecutor.apply(l,n)))}),null!==(e=null==r?void 0:r.delay)&&void 0!==e?e:500)}},r||{}));case 4:return u=e.v,e.a(2,u)}}),e,this)}))),function(e,t){return y.apply(this,arguments)})},{key:"queryPushNotify",value:(g=r(o().m((function e(t,r){var n,i,a,s;return o().w((function(e){for(;;)switch(e.n){case 0:return e.p=0,e.n=1,this.query(t,r);case 1:return e.a(2,e.v);case 2:throw e.p=2,s=e.v,(a=null===(n=(i=s).response)||void 0===n?void 0:n.data)&&Object.keys(a).forEach((function(e){var t=a[e];if(Array.isArray(t))t.forEach((function(e){var t;null==h||null===(t=h.ApiAlert)||void 0===t||t.PushError(e)}));else if("string"==typeof t.message){var r;null==h||null===(r=h.ApiAlert)||void 0===r||r.PushError(t.message)}})),i;case 3:return e.a(2)}}),e,this,[[0,2]])}))),function(e,t){return g.apply(this,arguments)})}]);var g,y,m}(),g=function(e){return new w(n({},e))};export{g as createGraphqlRequest,w as default};
1
+ import{inherits as e,createClass as t,asyncToGenerator as r,objectSpread2 as n,classCallCheck as i,callSuper as a,defineProperty as s,regenerator as o,typeof as u,superPropGet as l,toConsumableArray as c}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{AppProfile as f}from"./app-profile.js";import{fetchDelay as p,ApiAlertContext as h}from"../base/helpers.js";import{createHttpService as v}from"../base/gateway.js";import d from"../base/service-base.js";var w=function(){function w(e){var t,n,l,c;(i(this,w),l=a(this,w,[v(e.baseUrl)]),s(l,"setSite",function(e){l.site=e}),s(l,"setGraphQLExecutor",function(){var e=r(o().m(function e(t,r,n,i){var a,s;return o().w(function(e){for(;;)switch(e.n){case 0:return a={signal:n},e.n=1,l.addCustomHeader(a,i);case 1:return s=e.v,e.a(2,l.post("",{query:t,variables:r},s))}},e)}));return function(t,r,n,i){return e.apply(this,arguments)}}()),s(l,"_getSite",r(o().m(function e(){var t;return o().w(function(e){for(;;)switch(e.n){case 0:if(t=global.window,"object"!==u(t.wwfd)&&(t.wwfd={}),t.wwfd.GraphqlSite){e.n=2;break}return e.n=1,f.getGraphqlSite();case 1:t.wwfd.GraphqlSite=e.v;case 2:return e.a(2,t.wwfd.GraphqlSite)}},e)}))),s(l,"autoDetectSite",r(o().m(function e(){var t;return o().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,l.getSite();case 1:t=e.v,l.setSite(t);case 2:return e.a(2)}},e)}))),s(l,"getParamExecutor",function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];var n=t[0],i=t[1],a=t[2],s=t[3];if("string"!=typeof n||0===n.length)throw new Error("Request must be a non-empty string");if("object"!==u(i))throw new Error("Variables must be an object");if(a&&!(a instanceof AbortSignal))throw new Error("Signal must be an instance of AbortSignal");return[n,i,a,s]}),l._options=null!==(t=e.options)&&void 0!==t?t:{},l._execute=e.execute,l.getSite=l._getSite,null!==(n=e.options)&&void 0!==n&&n.site&&"function"==typeof e.options.site)?l.getSite=e.options.site:l.site=null===(c=e.options)||void 0===c?void 0:c.site;return l}return e(w,d),t(w,[{key:"addSite",value:function(e,t){return this.site&&null!=e&&e.headers&&!t&&(e.headers["graphql-site"]=this.site),null!=e?e:{}}},{key:"addCustomHeader",value:(m=r(o().m(function e(t,r){var n;return o().w(function(e){for(;;)switch(e.n){case 0:return e.n=1,l(w,"addCustomHeader",this)([t]);case 1:return n=e.v,e.a(2,this.addSite(n,r))}},e,this)})),function(e,t){return m.apply(this,arguments)})},{key:"query",value:(y=r(o().m(function e(t,r){var i,a,s,u,l=this;return o().w(function(e){for(;;)switch(e.n){case 0:if(i=this._options.autoDetectSite,a=this._options.ignoreSite,void 0!==(null==r?void 0:r.autoDetectSite)&&(i=r.autoDetectSite),void 0!==(null==r?void 0:r.ignoreSite)&&(a=r.ignoreSite),a||!1===i){e.n=2;break}return e.n=1,this.autoDetectSite();case 1:e.n=3;break;case 2:!a&&null!=r&&r.site&&this.setSite(null!==(s=r.site)&&void 0!==s?s:this._options.site);case 3:return e.n=4,this._execute(t,n({executor:function(){for(var e,t=arguments.length,n=new Array(t),i=0;i<t;i++)n[i]=arguments[i];return(null==r?void 0:r.signal)&&n.push(null==r?void 0:r.signal),n.push(a),p(function(){return l.setGraphQLExecutor.apply(l,c(l.getParamExecutor.apply(l,n)))},null!==(e=null==r?void 0:r.delay)&&void 0!==e?e:500)}},r||{}));case 4:return u=e.v,e.a(2,u)}},e,this)})),function(e,t){return y.apply(this,arguments)})},{key:"queryPushNotify",value:(g=r(o().m(function e(t,r){var n,i,a,s;return o().w(function(e){for(;;)switch(e.p=e.n){case 0:return e.p=0,e.n=1,this.query(t,r);case 1:return e.a(2,e.v);case 2:throw e.p=2,s=e.v,(a=null===(n=(i=s).response)||void 0===n?void 0:n.data)&&Object.keys(a).forEach(function(e){var t=a[e];if(Array.isArray(t))t.forEach(function(e){var t;null==h||null===(t=h.ApiAlert)||void 0===t||t.PushError(e)});else if("string"==typeof t.message){var r;null==h||null===(r=h.ApiAlert)||void 0===r||r.PushError(t.message)}}),i;case 3:return e.a(2)}},e,this,[[0,2]])})),function(e,t){return g.apply(this,arguments)})}]);var g,y,m}(),g=function(e){return new w(n({},e))};export{g as createGraphqlRequest,w as default};
2
2
  //# sourceMappingURL=graphql-request.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"graphql-request.js","sources":["../../../../src/http-service/graphql/graphql-request.ts"],"sourcesContent":["import { AxiosError, AxiosRequestConfig } from 'axios'\r\nimport type { Fetcher } from 'graphql-ts-client-api'\r\nimport { AppProfile } from './app-profile'\r\nimport { fetchDelay } from '../base/helpers'\r\nimport { ApiAlertContext } from '../base/helpers'\r\nimport { createHttpService } from '../base/gateway'\r\nimport type { IGraphqlQueryOptions, IGraphqlRequestOptions } from './types'\r\nimport ServiceBase from '../base/service-base'\r\n\r\nexport interface IGraphqlRequestParams {\r\n baseUrl: string\r\n execute: (...p: any[]) => Promise<any>\r\n options?: IGraphqlRequestOptions\r\n}\r\n\r\nclass GraphqlRequest extends ServiceBase {\r\n private _execute: (...p: any[]) => Promise<any>\r\n private _options: IGraphqlRequestOptions\r\n /**\r\n * Constructor for GraphqlRequest.\r\n * @param url The GraphQL endpoint URL.\r\n * @param executor Custom executor function for GraphQL requests.\r\n * @param options Additional options for the request.\r\n */\r\n constructor(params: IGraphqlRequestParams) {\r\n super(createHttpService(params.baseUrl))\r\n // const { autoDetectSite, site } = options ?? {}\r\n this._options = params.options ?? {}\r\n\r\n this._execute = params.execute\r\n\r\n // Initialize autoDetectSite and site getter\r\n this.getSite = this._getSite\r\n if (params.options?.site && typeof params.options.site === 'function') {\r\n this.getSite = params.options.site\r\n } else {\r\n this.site = params.options?.site as string | undefined\r\n }\r\n }\r\n private site?: string\r\n /**\r\n * Adds the site to the request configuration headers.\r\n * @param config Optional AxiosRequestConfig to modify.\r\n * @param ignoreSite If true, skips adding the site header.\r\n * @returns Modified AxiosRequestConfig with the site header.\r\n */\r\n addSite(config?: AxiosRequestConfig, ignoreSite?: boolean) {\r\n if (this.site && config?.headers && !ignoreSite) {\r\n config.headers['graphql-site'] = this.site\r\n }\r\n return config ?? {}\r\n }\r\n /**\r\n * Sets the current site for GraphQL requests.\r\n * @param site The site string to set.\r\n */\r\n setSite = (site: string) => {\r\n this.site = site\r\n }\r\n /**\r\n * Default executor for GraphQL requests using POST.\r\n * @param request GraphQL query string.\r\n * @param variables Variables for the query.\r\n * @param signal Optional AbortSignal for cancellation.\r\n * @param ignoreSite If true, skips adding the site header.\r\n * @returns Promise with the server response.\r\n */\r\n private setGraphQLExecutor = async (request: string, variables: object, signal?: AbortSignal, ignoreSite?: boolean) => {\r\n const config = { signal }\r\n const finalConfig = await this.addCustomHeader(config, ignoreSite)\r\n return this.post('', { query: request, variables }, finalConfig)\r\n }\r\n /**\r\n * Default implementation to get the current site.\r\n * Stores the site in global.window.wwfd.GraphqlSite for reuse.\r\n * @returns Promise resolving to the current site string.\r\n */\r\n getSite: () => Promise<string>\r\n private _getSite = async () => {\r\n const windowTemp = global.window as any\r\n if (typeof windowTemp['wwfd'] !== 'object') {\r\n windowTemp['wwfd'] = {}\r\n }\r\n if (!windowTemp['wwfd'].GraphqlSite) {\r\n windowTemp['wwfd'].GraphqlSite = await AppProfile.getGraphqlSite()\r\n }\r\n return windowTemp['wwfd'].GraphqlSite\r\n }\r\n /**\r\n * Automatically detects the site by calling getSite.\r\n * Sets the detected site using setSite.\r\n */\r\n private autoDetectSite = async () => {\r\n const site = await this.getSite()\r\n this.setSite(site)\r\n }\r\n /**\r\n * Adds a custom header to the request configuration.\r\n * @param config Optional AxiosRequestConfig to modify.\r\n * @param ignoreSite If true, skips adding the site header.\r\n * @returns Modified AxiosRequestConfig with the custom header.\r\n */\r\n async addCustomHeader(config?: AxiosRequestConfig, ignoreSite?: boolean) {\r\n const cfg = await super.addCustomHeader(config)\r\n return this.addSite(cfg, ignoreSite)\r\n }\r\n /**\r\n * Gets the current site for GraphQL requests.\r\n * @returns The current site string.\r\n */\r\n private getParamExecutor = (...p: any[]): Parameters<typeof this.setGraphQLExecutor> => {\r\n const [request, variables, signal, ignoreSite] = p\r\n if (typeof request !== 'string' || request.length === 0) {\r\n throw new Error('Request must be a non-empty string')\r\n }\r\n if (typeof variables !== 'object') {\r\n throw new Error('Variables must be an object')\r\n }\r\n if (signal && !(signal instanceof AbortSignal)) {\r\n throw new Error('Signal must be an instance of AbortSignal')\r\n }\r\n return [request, variables, signal, ignoreSite]\r\n }\r\n\r\n /**\r\n * Executes a GraphQL query or mutation with the provided fetcher.\r\n * Automatically detects the site if autoDetectSite is true.\r\n * @param fetcher The fetcher function for the query or mutation.\r\n * @param options Optional IGraphqlQueryOptions for the request.\r\n * @returns Promise with the result of the query or mutation.\r\n */\r\n async query<TData extends object, TVariables extends object>(\r\n fetcher: Fetcher<'Query' | 'Mutation', TData, TVariables>,\r\n options?: IGraphqlQueryOptions\r\n ): Promise<TData> {\r\n let autoDetectSite = this._options.autoDetectSite\r\n let ignoreSite = this._options.ignoreSite\r\n\r\n if (options?.autoDetectSite !== undefined) {\r\n autoDetectSite = options.autoDetectSite\r\n }\r\n if (options?.ignoreSite !== undefined) {\r\n ignoreSite = options.ignoreSite\r\n }\r\n\r\n if (!ignoreSite && autoDetectSite !== false) {\r\n await this.autoDetectSite()\r\n } else if (!ignoreSite && options?.site) {\r\n this.setSite(options.site ?? (this._options.site as string))\r\n }\r\n\r\n const res = await this._execute(fetcher, {\r\n executor: (...params: any[]) => {\r\n options?.signal && params.push(options?.signal)\r\n params.push(ignoreSite) // Thêm ignoreSite parameter\r\n return fetchDelay(() => this.setGraphQLExecutor(...this.getParamExecutor(...params)), options?.delay ?? 500)\r\n },\r\n ...(options ? options : {})\r\n })\r\n return res\r\n }\r\n /**\r\n * Executes a GraphQL query or mutation and handles errors by pushing them to ApiAlertContext.\r\n * @param fetcher The fetcher function for the query or mutation.\r\n * @param options Optional IGraphqlQueryOptions for the request.\r\n * @returns Promise with the result of the query or mutation.\r\n */\r\n async queryPushNotify<TData extends object, TVariables extends object>(\r\n fetcher: Fetcher<'Query' | 'Mutation', TData, TVariables>,\r\n options?: IGraphqlQueryOptions\r\n ) {\r\n try {\r\n return await this.query(fetcher, options)\r\n } catch (err) {\r\n const error = err as AxiosError\r\n const data = error.response?.data as any\r\n if (data) {\r\n const keys = Object.keys(data)\r\n keys.forEach((key) => {\r\n const errors = data[key] as any\r\n if (Array.isArray(errors)) {\r\n errors.forEach((message) => {\r\n ApiAlertContext?.ApiAlert?.PushError(message)\r\n })\r\n } else if (typeof errors.message === 'string') {\r\n ApiAlertContext?.ApiAlert?.PushError(errors.message)\r\n }\r\n })\r\n }\r\n throw error\r\n }\r\n }\r\n}\r\nexport default GraphqlRequest\r\n/*\r\n * Factory function to create a new GraphqlRequest instance.\r\n * @param args Arguments to pass to the GraphqlRequest constructor.\r\n * @returns A new instance of GraphqlRequest.\r\n */\r\nexport const createGraphqlRequest = (params: IGraphqlRequestParams) => {\r\n return new GraphqlRequest({ ...params })\r\n}\r\n"],"names":["GraphqlRequest","params","_params$options","_params$options2","_this","_params$options3","_classCallCheck","_callSuper","this","createHttpService","baseUrl","_defineProperty","site","_ref","_asyncToGenerator","_regenerator","m","_callee","request","variables","signal","ignoreSite","config","finalConfig","w","_context","n","addCustomHeader","v","a","post","query","_x","_x2","_x3","_x4","apply","arguments","_callee2","windowTemp","_context2","global","window","_typeof","GraphqlSite","AppProfile","getGraphqlSite","_callee3","_context3","getSite","setSite","_len","length","p","Array","_key","Error","AbortSignal","_options","options","_execute","execute","_getSite","_inherits","ServiceBase","_createClass","key","value","headers","_addCustomHeader","_callee4","cfg","_context4","_superPropGet","addSite","_x5","_x6","_query","_callee5","fetcher","autoDetectSite","_options$site","res","_this2","_context5","undefined","_objectSpread","executor","_options$delay","_len2","_key2","push","fetchDelay","setGraphQLExecutor","_toConsumableArray","getParamExecutor","delay","_x7","_x8","_queryPushNotify","_callee6","_error$response","error","data","_t","_context6","response","Object","keys","forEach","errors","isArray","message","_ApiAlertContext$ApiA","ApiAlertContext","ApiAlert","PushError","_ApiAlertContext$ApiA2","_x9","_x0","createGraphqlRequest"],"mappings":"kdAeMA,IAAAA,aASJ,SAAAA,EAAYC,GAA6B,IAAAC,EAAAC,EAAAC,EAWhCC,GAXgCC,OAAAN,GACvCI,EAAAG,EAAAC,KAAAR,EAAA,CAAMS,EAAkBR,EAAOS,WA2BjCC,EAAAP,EAIU,WAAA,SAACQ,GACTR,EAAKQ,KAAOA,KAEdD,EAAAP,EAAA,qBAAA,WAAA,IAAAS,EAAAC,EAAAC,IAAAC,GAQ6B,SAAAC,EAAOC,EAAiBC,EAAmBC,EAAsBC,GAAoB,IAAAC,EAAAC,EAAA,OAAAR,IAAAS,GAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA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E,QAC7C,CACH,IAEIV,EAAK,KAAA,EAAA,OAAAG,EAAA5E,EAAA,GAAA,GAAAuE,EAAA5F,KAAA,CAAA,CAAA,EAAA,SAEd,SAxBoB8G,EAAAC,GAAA,OAAApB,EAAA/D,MAAA5B,KAAA6B,UAAA,MANrB,IAAA8D,EArCAtB,EA5BAR,CAuEqB,IAgCVmD,EAAuB,SAACvH,GACnC,OAAO,IAAID,EAAcsF,EAAMrF,CAAAA,EAAAA,GACjC"}
1
+ {"version":3,"file":"graphql-request.js","sources":["../../../../src/http-service/graphql/graphql-request.ts"],"sourcesContent":["import { AxiosError, AxiosRequestConfig } from 'axios'\r\nimport type { Fetcher } from 'graphql-ts-client-api'\r\nimport { AppProfile } from './app-profile'\r\nimport { fetchDelay } from '../base/helpers'\r\nimport { ApiAlertContext } from '../base/helpers'\r\nimport { createHttpService } from '../base/gateway'\r\nimport type { IGraphqlQueryOptions, IGraphqlRequestOptions } from './types'\r\nimport ServiceBase from '../base/service-base'\r\n\r\nexport interface IGraphqlRequestParams {\r\n baseUrl: string\r\n execute: (...p: any[]) => Promise<any>\r\n options?: IGraphqlRequestOptions\r\n}\r\n\r\nclass GraphqlRequest extends ServiceBase {\r\n private _execute: (...p: any[]) => Promise<any>\r\n private _options: IGraphqlRequestOptions\r\n /**\r\n * Constructor for GraphqlRequest.\r\n * @param url The GraphQL endpoint URL.\r\n * @param executor Custom executor function for GraphQL requests.\r\n * @param options Additional options for the request.\r\n */\r\n constructor(params: IGraphqlRequestParams) {\r\n super(createHttpService(params.baseUrl))\r\n // const { autoDetectSite, site } = options ?? {}\r\n this._options = params.options ?? {}\r\n\r\n this._execute = params.execute\r\n\r\n // Initialize autoDetectSite and site getter\r\n this.getSite = this._getSite\r\n if (params.options?.site && typeof params.options.site === 'function') {\r\n this.getSite = params.options.site\r\n } else {\r\n this.site = params.options?.site as string | undefined\r\n }\r\n }\r\n private site?: string\r\n /**\r\n * Adds the site to the request configuration headers.\r\n * @param config Optional AxiosRequestConfig to modify.\r\n * @param ignoreSite If true, skips adding the site header.\r\n * @returns Modified AxiosRequestConfig with the site header.\r\n */\r\n addSite(config?: AxiosRequestConfig, ignoreSite?: boolean) {\r\n if (this.site && config?.headers && !ignoreSite) {\r\n config.headers['graphql-site'] = this.site\r\n }\r\n return config ?? {}\r\n }\r\n /**\r\n * Sets the current site for GraphQL requests.\r\n * @param site The site string to set.\r\n */\r\n setSite = (site: string) => {\r\n this.site = site\r\n }\r\n /**\r\n * Default executor for GraphQL requests using POST.\r\n * @param request GraphQL query string.\r\n * @param variables Variables for the query.\r\n * @param signal Optional AbortSignal for cancellation.\r\n * @param ignoreSite If true, skips adding the site header.\r\n * @returns Promise with the server response.\r\n */\r\n private setGraphQLExecutor = async (request: string, variables: object, signal?: AbortSignal, ignoreSite?: boolean) => {\r\n const config = { signal }\r\n const finalConfig = await this.addCustomHeader(config, ignoreSite)\r\n return this.post('', { query: request, variables }, finalConfig)\r\n }\r\n /**\r\n * Default implementation to get the current site.\r\n * Stores the site in global.window.wwfd.GraphqlSite for reuse.\r\n * @returns Promise resolving to the current site string.\r\n */\r\n getSite: () => Promise<string>\r\n private _getSite = async () => {\r\n const windowTemp = global.window as any\r\n if (typeof windowTemp['wwfd'] !== 'object') {\r\n windowTemp['wwfd'] = {}\r\n }\r\n if (!windowTemp['wwfd'].GraphqlSite) {\r\n windowTemp['wwfd'].GraphqlSite = await AppProfile.getGraphqlSite()\r\n }\r\n return windowTemp['wwfd'].GraphqlSite\r\n }\r\n /**\r\n * Automatically detects the site by calling getSite.\r\n * Sets the detected site using setSite.\r\n */\r\n private autoDetectSite = async () => {\r\n const site = await this.getSite()\r\n this.setSite(site)\r\n }\r\n /**\r\n * Adds a custom header to the request configuration.\r\n * @param config Optional AxiosRequestConfig to modify.\r\n * @param ignoreSite If true, skips adding the site header.\r\n * @returns Modified AxiosRequestConfig with the custom header.\r\n */\r\n async addCustomHeader(config?: AxiosRequestConfig, ignoreSite?: boolean) {\r\n const cfg = await super.addCustomHeader(config)\r\n return this.addSite(cfg, ignoreSite)\r\n }\r\n /**\r\n * Gets the current site for GraphQL requests.\r\n * @returns The current site string.\r\n */\r\n private getParamExecutor = (...p: any[]): Parameters<typeof this.setGraphQLExecutor> => {\r\n const [request, variables, signal, ignoreSite] = p\r\n if (typeof request !== 'string' || request.length === 0) {\r\n throw new Error('Request must be a non-empty string')\r\n }\r\n if (typeof variables !== 'object') {\r\n throw new Error('Variables must be an object')\r\n }\r\n if (signal && !(signal instanceof AbortSignal)) {\r\n throw new Error('Signal must be an instance of AbortSignal')\r\n }\r\n return [request, variables, signal, ignoreSite]\r\n }\r\n\r\n /**\r\n * Executes a GraphQL query or mutation with the provided fetcher.\r\n * Automatically detects the site if autoDetectSite is true.\r\n * @param fetcher The fetcher function for the query or mutation.\r\n * @param options Optional IGraphqlQueryOptions for the request.\r\n * @returns Promise with the result of the query or mutation.\r\n */\r\n async query<TData extends object, TVariables extends object>(\r\n fetcher: Fetcher<'Query' | 'Mutation', TData, TVariables>,\r\n options?: IGraphqlQueryOptions\r\n ): Promise<TData> {\r\n let autoDetectSite = this._options.autoDetectSite\r\n let ignoreSite = this._options.ignoreSite\r\n\r\n if (options?.autoDetectSite !== undefined) {\r\n autoDetectSite = options.autoDetectSite\r\n }\r\n if (options?.ignoreSite !== undefined) {\r\n ignoreSite = options.ignoreSite\r\n }\r\n\r\n if (!ignoreSite && autoDetectSite !== false) {\r\n await this.autoDetectSite()\r\n } else if (!ignoreSite && options?.site) {\r\n this.setSite(options.site ?? (this._options.site as string))\r\n }\r\n\r\n const res = await this._execute(fetcher, {\r\n executor: (...params: any[]) => {\r\n options?.signal && params.push(options?.signal)\r\n params.push(ignoreSite) // Thêm ignoreSite parameter\r\n return fetchDelay(() => this.setGraphQLExecutor(...this.getParamExecutor(...params)), options?.delay ?? 500)\r\n },\r\n ...(options ? options : {})\r\n })\r\n return res\r\n }\r\n /**\r\n * Executes a GraphQL query or mutation and handles errors by pushing them to ApiAlertContext.\r\n * @param fetcher The fetcher function for the query or mutation.\r\n * @param options Optional IGraphqlQueryOptions for the request.\r\n * @returns Promise with the result of the query or mutation.\r\n */\r\n async queryPushNotify<TData extends object, TVariables extends object>(\r\n fetcher: Fetcher<'Query' | 'Mutation', TData, TVariables>,\r\n options?: IGraphqlQueryOptions\r\n ) {\r\n try {\r\n return await this.query(fetcher, options)\r\n } catch (err) {\r\n const error = err as AxiosError\r\n const data = error.response?.data as any\r\n if (data) {\r\n const keys = Object.keys(data)\r\n keys.forEach((key) => {\r\n const errors = data[key] as any\r\n if (Array.isArray(errors)) {\r\n errors.forEach((message) => {\r\n ApiAlertContext?.ApiAlert?.PushError(message)\r\n })\r\n } else if (typeof errors.message === 'string') {\r\n ApiAlertContext?.ApiAlert?.PushError(errors.message)\r\n }\r\n })\r\n }\r\n throw error\r\n }\r\n }\r\n}\r\nexport default GraphqlRequest\r\n/*\r\n * Factory function to create a new GraphqlRequest instance.\r\n * @param args Arguments to pass to the GraphqlRequest constructor.\r\n * @returns A new instance of GraphqlRequest.\r\n */\r\nexport const createGraphqlRequest = (params: IGraphqlRequestParams) => {\r\n return new GraphqlRequest({ ...params })\r\n}\r\n"],"names":["GraphqlRequest","params","_params$options","_params$options2","_this","_params$options3","_classCallCheck","_callSuper","this","createHttpService","baseUrl","_defineProperty","site","_ref","_asyncToGenerator","_regenerator","m","_callee","request","variables","signal","ignoreSite","config","finalConfig","w","_context","n","addCustomHeader","v","a","post","query","_x","_x2","_x3","_x4","apply","arguments","_callee2","windowTemp","_context2","global","window","_typeof","GraphqlSite","AppProfile","getGraphqlSite","_callee3","_context3","getSite","setSite","_len","length","p","Array","_key","Error","AbortSignal","_options","options","_execute","execute","_getSite","_inherits","ServiceBase","_createClass","key","value","headers","_addCustomHeader","_callee4","cfg","_context4","_superPropGet","addSite","_x5","_x6","_query","_callee5","fetcher","autoDetectSite","_options$site","res","_this2","_context5","undefined","_objectSpread","executor","_options$delay","_len2","_key2","push","fetchDelay","setGraphQLExecutor","_toConsumableArray","getParamExecutor","delay","_x7","_x8","_queryPushNotify","_callee6","_error$response","error","data","_t","_context6","response","Object","keys","forEach","errors","isArray","message","_ApiAlertContext$ApiA","ApiAlertContext","ApiAlert","PushError","_ApiAlertContext$ApiA2","_x9","_x0","createGraphqlRequest"],"mappings":"kdAeMA,IAAAA,aASJ,SAAAA,EAAYC,GAA6B,IAAAC,EAAAC,EAAAC,EAWhCC,GAXgCC,OAAAN,GACvCI,EAAAG,EAAAC,KAAAR,EAAA,CAAMS,EAAkBR,EAAOS,WA2BjCC,EAAAP,EAIU,UAAA,SAACQ,GACTR,EAAKQ,KAAOA,IAEdD,EAAAP,EAAA,qBAAA,WAAA,IAAAS,EAAAC,EAAAC,IAAAC,EAQ6B,SAAAC,EAAOC,EAAiBC,EAAmBC,EAAsBC,GAAoB,IAAAC,EAAAC,EAAA,OAAAR,IAAAS,EAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA,KAAA,EACvF,OAAnBJ,EAAS,CAAEF,OAAAA,GAAQK,EAAAC,EAAA,EACCtB,EAAKuB,gBAAgBL,EAAQD,GAAW,KAAA,EAAjD,OAAXE,EAAWE,EAAAG,EAAAH,EAAAI,EAAA,EACVzB,EAAK0B,KAAK,GAAI,CAAEC,MAAOb,EAASC,UAAAA,GAAaI,IAAY,EAAAN,MACjE,OAAA,SAAAe,EAAAC,EAAAC,EAAAC,GAAA,OAAAtB,EAAAuB,MAAA5B,KAAA6B,UAAA,CAAA,CAZD,IAYC1B,EAAAP,EAAA,WAAAU,EAAAC,IAAAC,EAOkB,SAAAsB,IAAA,IAAAC,EAAA,OAAAxB,IAAAS,EAAA,SAAAgB,GAAA,cAAAA,EAAAd,GAAA,KAAA,EAIhB,GAHKa,EAAaE,OAAOC,OACQ,WAA9BC,EAAOJ,EAAiB,QAC1BA,EAAiB,KAAI,CAAE,GAEpBA,EAAiB,KAAEK,YAAW,CAAAJ,EAAAd,EAAA,EAAA,KAAA,CAAA,OAAAc,EAAAd,EAAA,EACMmB,EA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KAAKuB,MAAMgD,EAASpB,GAAQ,KAAA,EAAA,OAAA8C,EAAA5E,EAAA4E,EAAAA,EAAA7E,GAAA,KAAA,EAgBxC,MAhBwC6E,EAAApD,EAAA,EAAAmD,EAAAC,EAAA7E,GAGnC2E,EAAqB,QAAjBF,GADJC,EAAKE,GACQE,gBAAQ,IAAAL,OAAA,EAAdA,EAAgBE,OAEdI,OAAOC,KAAKL,GACpBM,QAAQ,SAAC3C,GACZ,IAAM4C,EAASP,EAAKrC,GACpB,GAAIZ,MAAMyD,QAAQD,GAChBA,EAAOD,QAAQ,SAACG,GAAW,IAAAC,EACzBC,SAAyBD,QAAVA,EAAfC,EAAiBC,oBAAQF,GAAzBA,EAA2BG,UAAUJ,EACvC,QACK,GAA8B,iBAAnBF,EAAOE,QAAsB,CAAA,IAAAK,EAC7CH,SAAyB,QAAVG,EAAfH,EAAiBC,gBAAQ,IAAAE,GAAzBA,EAA2BD,UAAUN,EAAOE,QAC7C,CACH,GAEIV,EAAK,KAAA,EAAA,OAAAG,EAAA5E,EAAA,GAAA,EAAAuE,EAAA5F,KAAA,CAAA,CAAA,EAAA,QAEd,SAxBoB8G,EAAAC,GAAA,OAAApB,EAAA/D,MAAA5B,KAAA6B,UAAA,MANrB,IAAA8D,EArCAtB,EA5BAR,CAuEqB,IAgCVmD,EAAuB,SAACvH,GACnC,OAAO,IAAID,EAAcsF,EAAMrF,CAAAA,EAAAA,GACjC"}
@@ -1,2 +1,2 @@
1
- import{createClass as t,classCallCheck as e,defineProperty as i,objectSpread2 as n}from"../../../_virtual/_rollupPluginBabelHelpers.js";var r=t((function t(r){var o=this;e(this,t),i(this,"mergeOptions",(function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return e.reduce((function(t,e){return Object.assign(t,null!=e?e:{})}),{})})),i(this,"ignoreEmpty",(function(t,e){var i=o.mergeOptions(o._option,e);return!t&&!0===(null==i?void 0:i.ignoreEmpty)})),i(this,"_filter",[]),i(this,"_filterBase",(function(t,e,i,n){var r=o._filter.length?" "+("And"===(null==n?void 0:n.logic)?"&&":"||")+" ":"";return o._filter.push("".concat(r).concat(t).concat(e).concat(i)),o})),i(this,"filter",(function(t,e,i){return"string"==typeof e&&o.ignoreEmpty(e,i)?o:o._filterBase(t,"==","string"==typeof e?'"'.concat(e,'"'):e.toString(),i)})),i(this,"filterNotEquals",(function(t,e,i){return"string"==typeof e&&o.ignoreEmpty(e,i)?o:o._filterBase(t,"!=","string"==typeof e?'"'.concat(e,'"'):e.toString(),i)})),i(this,"filterEnum",(function(t,e,i){return"string"==typeof e&&o.ignoreEmpty(e,i)?o:o._filterBase(t,"==","string"==typeof e?e:e.toString(),i)})),i(this,"filterStartsWith",(function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t,'.startsWith("'+e+'")',"",i)})),i(this,"filterContains",(function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t,'.Contains("'+e+'")',"",i)})),i(this,"filterLast",(function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t,'.endsWith("'+e+'")',"",i)})),i(this,"filterNumber",(function(t,e,i,n){return o.ignoreEmpty(i,n)?o:o._filterBase(t," ".concat(e," ")+i,"",n)})),i(this,"filterGreater",(function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t," > '"+e+"'","",i)})),i(this,"filterLess",(function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t," < '"+e+"'","",i)})),i(this,"filterCustom",(function(t,e){var i=o._filter.length?" "+("And"===(null==e?void 0:e.logic)?"&&":"||")+" ":"";return o._filter.push("".concat(i).concat(t)),o})),i(this,"scope",(function(e,i){var n=e(new t(o._option));if(n.buildFilter()){var r=o._filter.length?" "+("And"===(null==i?void 0:i.logic)?"&&":"||")+" ":"";o._filter.push("".concat(r,"(").concat(n.buildFilter(),")"))}return o})),i(this,"seed",(function(t,e){return o.seedStore={field:t,key:e},o})),i(this,"skip",(function(t){return o._skip=t,o})),i(this,"take",(function(t){return o._take=t,o})),i(this,"sortStore",[]),i(this,"sortBase",(function(t,e,i){var n={};return n[t]=e,o.sortStore.some((function(t){return Object.keys(t)[0]===Object.keys(n)[0]}))||o.sortStore.push(n),o})),i(this,"sort",(function(t,e){return o.sortBase(t,null!=e&&e.direction?e.direction:"ASC"),o})),i(this,"noTotal",(function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return o._noTotal=t,o})),i(this,"buildFilter",(function(){return o._filter.join("")})),i(this,"buildPage",(function(){var t={};return o._skip&&(t.skip=o._skip),o._take&&(t.take=o._take),t})),i(this,"buildRandomWithSeedKey",(function(){var t,e,i,n,r,s;return null===(t=o.seedStore)||void 0===t||!t.field||null!==(e=o.seedStore)&&void 0!==e&&e.key||console.warn("RandomWithSeedKey missing seedKey."),null===(i=o.seedStore)||void 0===i||!i.key||null!==(n=o.seedStore)&&void 0!==n&&n.field||console.warn("RandomWithSeedKey missing seedField."),null!==(r=o.seedStore)&&void 0!==r&&r.key||null!==(s=o.seedStore)&&void 0!==s&&s.field?o.seedStore:{}})),i(this,"build",(function(){var t=n({},o.buildPage());o.sortStore.length>0&&(t.sort=o.sortStore);var e=o.buildFilter();e&&(t.filter=e),o._noTotal&&(t.noTotal=o._noTotal);var i=o.buildRandomWithSeedKey();return i.key&&i.field&&(t.seedField=i.field.toString(),t.seedKey=i.key),t})),this._option=r})),o=function(t){return new r(t)};export{r as RequestParam,o as createRequestBuilder};
1
+ import{createClass as t,classCallCheck as e,defineProperty as i,objectSpread2 as n}from"../../../_virtual/_rollupPluginBabelHelpers.js";var r=t(function t(r){var o=this;e(this,t),i(this,"mergeOptions",function(){for(var t=arguments.length,e=new Array(t),i=0;i<t;i++)e[i]=arguments[i];return e.reduce(function(t,e){return Object.assign(t,null!=e?e:{})},{})}),i(this,"ignoreEmpty",function(t,e){var i=o.mergeOptions(o._option,e);return!t&&!0===(null==i?void 0:i.ignoreEmpty)}),i(this,"_filter",[]),i(this,"_filterBase",function(t,e,i,n){var r=o._filter.length?" "+("And"===(null==n?void 0:n.logic)?"&&":"||")+" ":"";return o._filter.push("".concat(r).concat(t).concat(e).concat(i)),o}),i(this,"filter",function(t,e,i){return"string"==typeof e&&o.ignoreEmpty(e,i)?o:o._filterBase(t,"==","string"==typeof e?'"'.concat(e,'"'):e.toString(),i)}),i(this,"filterNotEquals",function(t,e,i){return"string"==typeof e&&o.ignoreEmpty(e,i)?o:o._filterBase(t,"!=","string"==typeof e?'"'.concat(e,'"'):e.toString(),i)}),i(this,"filterEnum",function(t,e,i){return"string"==typeof e&&o.ignoreEmpty(e,i)?o:o._filterBase(t,"==","string"==typeof e?e:e.toString(),i)}),i(this,"filterStartsWith",function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t,'.startsWith("'+e+'")',"",i)}),i(this,"filterContains",function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t,'.Contains("'+e+'")',"",i)}),i(this,"filterLast",function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t,'.endsWith("'+e+'")',"",i)}),i(this,"filterNumber",function(t,e,i,n){return o.ignoreEmpty(i,n)?o:o._filterBase(t," ".concat(e," ")+i,"",n)}),i(this,"filterGreater",function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t," > '"+e+"'","",i)}),i(this,"filterLess",function(t,e,i){return o.ignoreEmpty(e,i)?o:o._filterBase(t," < '"+e+"'","",i)}),i(this,"filterCustom",function(t,e){var i=o._filter.length?" "+("And"===(null==e?void 0:e.logic)?"&&":"||")+" ":"";return o._filter.push("".concat(i).concat(t)),o}),i(this,"scope",function(e,i){var n=e(new t(o._option));if(n.buildFilter()){var r=o._filter.length?" "+("And"===(null==i?void 0:i.logic)?"&&":"||")+" ":"";o._filter.push("".concat(r,"(").concat(n.buildFilter(),")"))}return o}),i(this,"seed",function(t,e){return o.seedStore={field:t,key:e},o}),i(this,"skip",function(t){return o._skip=t,o}),i(this,"take",function(t){return o._take=t,o}),i(this,"sortStore",[]),i(this,"sortBase",function(t,e,i){var n={};return n[t]=e,o.sortStore.some(function(t){return Object.keys(t)[0]===Object.keys(n)[0]})||o.sortStore.push(n),o}),i(this,"sort",function(t,e){return o.sortBase(t,null!=e&&e.direction?e.direction:"ASC"),o}),i(this,"noTotal",function(){var t=!(arguments.length>0&&void 0!==arguments[0])||arguments[0];return o._noTotal=t,o}),i(this,"buildFilter",function(){return o._filter.join("")}),i(this,"buildPage",function(){var t={};return o._skip&&(t.skip=o._skip),o._take&&(t.take=o._take),t}),i(this,"buildRandomWithSeedKey",function(){var t,e,i,n,r,s;return null===(t=o.seedStore)||void 0===t||!t.field||null!==(e=o.seedStore)&&void 0!==e&&e.key||console.warn("RandomWithSeedKey missing seedKey."),null===(i=o.seedStore)||void 0===i||!i.key||null!==(n=o.seedStore)&&void 0!==n&&n.field||console.warn("RandomWithSeedKey missing seedField."),null!==(r=o.seedStore)&&void 0!==r&&r.key||null!==(s=o.seedStore)&&void 0!==s&&s.field?o.seedStore:{}}),i(this,"build",function(){var t=n({},o.buildPage());o.sortStore.length>0&&(t.sort=o.sortStore);var e=o.buildFilter();e&&(t.filter=e),o._noTotal&&(t.noTotal=o._noTotal);var i=o.buildRandomWithSeedKey();return i.key&&i.field&&(t.seedField=i.field.toString(),t.seedKey=i.key),t}),this._option=r}),o=function(t){return new r(t)};export{r as RequestParam,o as createRequestBuilder};
2
2
  //# sourceMappingURL=request-param.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"request-param.js","sources":["../../../../src/http-service/graphql/request-param.ts"],"sourcesContent":["export type IVariable<T extends object> = keyof T\r\n\r\nexport type ILogic = 'Or' | 'And'\r\n\r\nexport type ISortDirection = 'ASC' | 'DESC'\r\n\r\nexport interface ISeedModel<T> {\r\n key: string\r\n field: keyof T\r\n}\r\n\r\nexport interface IFilterOption {\r\n logic: ILogic\r\n ignoreEmpty: boolean\r\n}\r\n\r\nexport interface IRequestParamOption {\r\n ignoreEmpty: boolean\r\n}\r\n\r\nexport interface ISortOption {\r\n direction: ISortDirection\r\n}\r\n\r\nexport type ISortStore<T extends object> = { [key in keyof T]?: ISortDirection }\r\n\r\nexport type IAllOptions = IFilterOption & IRequestParamOption & ISortOption\r\n\r\nexport type IRequestParamResult<T extends object> = {\r\n sort?: ISortStore<T>[]\r\n skip: number\r\n take: number\r\n filter?: string\r\n noTotal?: boolean\r\n seedKey?: string\r\n seedField?: string\r\n}\r\n\r\nexport class RequestParam<T extends object = any> {\r\n private readonly _option?: Partial<IRequestParamOption>\r\n constructor(option?: Partial<IRequestParamOption>) {\r\n this._option = option\r\n }\r\n\r\n private mergeOptions = (...p: any[]): Partial<IAllOptions> => {\r\n return p.reduce((a, b) => {\r\n return Object.assign(a, b ?? {})\r\n }, {})\r\n }\r\n\r\n private ignoreEmpty = (field2: string, option?: Partial<IFilterOption>) => {\r\n const mOption = this.mergeOptions(this._option, option)\r\n return !field2 && mOption?.ignoreEmpty === true\r\n }\r\n\r\n private _filter: string[] = []\r\n private _filterBase = (field1: IVariable<T>, operation: string, field2: string, option?: Partial<IFilterOption>) => {\r\n const logicStr = this._filter.length ? ' ' + (option?.logic === 'And' ? '&&' : '||') + ' ' : ''\r\n this._filter.push(`${logicStr}${field1 as string}${operation}${field2 as string}`)\r\n return this\r\n }\r\n filter = (field1: IVariable<T>, field2: string | number, option?: Partial<IFilterOption>) => {\r\n if (typeof field2 === 'string' && this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '==', typeof field2 === 'string' ? `\"${field2}\"` : field2.toString(), option)\r\n }\r\n filterNotEquals = (field1: IVariable<T>, field2: string | number, option?: Partial<IFilterOption>) => {\r\n if (typeof field2 === 'string' && this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '!=', typeof field2 === 'string' ? `\"${field2}\"` : field2.toString(), option)\r\n }\r\n filterEnum = (field1: IVariable<T>, field2: string | number, option?: Partial<IFilterOption>) => {\r\n if (typeof field2 === 'string' && this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '==', typeof field2 === 'string' ? field2 : field2.toString(), option)\r\n }\r\n filterStartsWith = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '.startsWith(\"' + (field2 as string) + '\")', '', option)\r\n }\r\n filterContains = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '.Contains(\"' + (field2 as string) + '\")', '', option)\r\n }\r\n filterLast = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '.endsWith(\"' + (field2 as string) + '\")', '', option)\r\n }\r\n filterNumber = (field1: IVariable<T>, operator: string, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, ` ${operator} ` + (field2 as string), '', option)\r\n }\r\n filterGreater = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, \" > '\" + (field2 as string) + \"'\", '', option)\r\n }\r\n filterLess = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, \" < '\" + (field2 as string) + \"'\", '', option)\r\n }\r\n filterCustom = (field1: string, option?: Partial<IFilterOption>) => {\r\n const logicStr = this._filter.length ? ' ' + (option?.logic === 'And' ? '&&' : '||') + ' ' : ''\r\n this._filter.push(`${logicStr}${field1 as string}`)\r\n return this\r\n }\r\n\r\n scope = (action: (crd: RequestParam<T>) => RequestParam<T>, option?: Partial<IFilterOption>) => {\r\n const crd = action(new RequestParam(this._option))\r\n const temp = crd.buildFilter()\r\n if (temp) {\r\n const logicStr = this._filter.length ? ' ' + (option?.logic === 'And' ? '&&' : '||') + ' ' : ''\r\n this._filter.push(`${logicStr}(${crd.buildFilter()})`)\r\n }\r\n return this\r\n }\r\n\r\n private seedStore?: ISeedModel<T>\r\n seed = (field: keyof T, key: string) => {\r\n this.seedStore = { field, key }\r\n return this\r\n }\r\n\r\n private _skip?: number\r\n skip = (skip: number) => {\r\n this._skip = skip\r\n return this\r\n }\r\n\r\n private _take?: number\r\n take = (take: number) => {\r\n this._take = take\r\n return this\r\n }\r\n\r\n private sortStore: ISortStore<T>[] = []\r\n private sortBase = (field1: IVariable<T>, direction: ISortDirection, option?: Partial<ISortOption>) => {\r\n const temp = {} as ISortStore<T>\r\n temp[field1] = direction\r\n if (!this.sortStore.some((item) => Object.keys(item)[0] === Object.keys(temp)[0])) {\r\n this.sortStore.push(temp)\r\n }\r\n return this\r\n }\r\n sort = (field1: IVariable<T>, option?: Partial<ISortOption>) => {\r\n this.sortBase(field1, option?.direction ? option.direction : 'ASC')\r\n return this\r\n }\r\n\r\n private _noTotal?: boolean\r\n noTotal = (value: boolean = true) => {\r\n this._noTotal = value\r\n return this\r\n }\r\n\r\n private buildFilter = () => {\r\n return this._filter.join('')\r\n }\r\n\r\n private buildPage = () => {\r\n const temp = {} as any\r\n if (this._skip) {\r\n temp.skip = this._skip\r\n }\r\n if (this._take) {\r\n temp.take = this._take\r\n }\r\n return temp as { skip: number; take: number }\r\n }\r\n\r\n private buildRandomWithSeedKey = (): Partial<ISeedModel<T>> => {\r\n if (this.seedStore?.field && !this.seedStore?.key) {\r\n console.warn('RandomWithSeedKey missing seedKey.')\r\n }\r\n if (this.seedStore?.key && !this.seedStore?.field) {\r\n console.warn('RandomWithSeedKey missing seedField.')\r\n }\r\n if (!this.seedStore?.key && !this.seedStore?.field) {\r\n return {}\r\n }\r\n return this.seedStore\r\n }\r\n\r\n build = (): IRequestParamResult<T> => {\r\n const obj: IRequestParamResult<T> = { ...this.buildPage() }\r\n if (this.sortStore.length > 0) obj.sort = this.sortStore\r\n const filter = this.buildFilter()\r\n if (filter) obj.filter = filter\r\n if (this._noTotal) obj.noTotal = this._noTotal\r\n const seedInfo = this.buildRandomWithSeedKey()\r\n if (!!seedInfo.key && !!seedInfo.field) {\r\n obj.seedField = seedInfo.field.toString()\r\n obj.seedKey = seedInfo.key\r\n }\r\n return obj\r\n }\r\n}\r\n\r\nexport const createRequestBuilder = <T extends object>(option?: Partial<IRequestParamOption>) => {\r\n return new RequestParam<T>(option)\r\n}\r\n"],"names":["RequestParam","_createClass","option","_this","this","_classCallCheck","_defineProperty","_len","arguments","length","p","Array","_key","reduce","a","b","Object","assign","field2","mOption","mergeOptions","_option","ignoreEmpty","field1","operation","logicStr","_filter","logic","push","concat","_filterBase","toString","operator","action","crd","buildFilter","field","key","seedStore","skip","_skip","take","_take","direction","temp","sortStore","some","item","keys","sortBase","value","undefined","_noTotal","join","_this$seedStore","_this$seedStore2","_this$seedStore3","_this$seedStore4","_this$seedStore5","_this$seedStore6","console","warn","obj","_objectSpread","buildPage","sort","filter","noTotal","seedInfo","buildRandomWithSeedKey","seedField","seedKey","createRequestBuilder"],"mappings":"wIAsCA,IAAaA,EAAYC,GAEvB,SAAAD,EAAYE,GAAqC,IAAAC,EAAAC,KAAAC,OAAAL,GAAAM,uBAI1B,WAAsC,IAAA,IAAAC,EAAAC,UAAAC,OAAlCC,EAAQC,IAAAA,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAARF,EAAQE,GAAAJ,UAAAI,GACjC,OAAOF,EAAEG,QAAO,SAACC,EAAGC,GAClB,OAAOC,OAAOC,OAAOH,EAAGC,QAAAA,EAAK,GAC9B,GAAE,OACJT,EAEqBF,KAAA,eAAA,SAACc,EAAgBhB,GACrC,IAAMiB,EAAUhB,EAAKiB,aAAajB,EAAKkB,QAASnB,GAChD,OAAQgB,IAAmC,KAAzBC,aAAO,EAAPA,EAASG,gBAC5BhB,iBAE2B,IAAEA,EAAAF,KAAA,eACR,SAACmB,EAAsBC,EAAmBN,EAAgBhB,GAC9E,IAAMuB,EAAWtB,EAAKuB,QAAQjB,OAAS,KAAyB,SAAlBP,aAAAA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D,EAAGC,EAAA,CAAA,EAAgC5D,EAAK6D,aAC1C7D,EAAK0C,UAAUpC,OAAS,IAAGqD,EAAIG,KAAO9D,EAAK0C,WAC/C,IAAMqB,EAAS/D,EAAKgC,cAChB+B,IAAQJ,EAAII,OAASA,GACrB/D,EAAKiD,WAAUU,EAAIK,QAAUhE,EAAKiD,UACtC,IAAMgB,EAAWjE,EAAKkE,yBAKtB,OAJMD,EAAS/B,KAAS+B,EAAShC,QAC/B0B,EAAIQ,UAAYF,EAAShC,MAAML,WAC/B+B,EAAIS,QAAUH,EAAS/B,KAElByB,KArJP1D,KAAKiB,QAAUnB,CACjB,IAwJWsE,EAAuB,SAAmBtE,GACrD,OAAO,IAAIF,EAAgBE,EAC7B"}
1
+ {"version":3,"file":"request-param.js","sources":["../../../../src/http-service/graphql/request-param.ts"],"sourcesContent":["export type IVariable<T extends object> = keyof T\r\n\r\nexport type ILogic = 'Or' | 'And'\r\n\r\nexport type ISortDirection = 'ASC' | 'DESC'\r\n\r\nexport interface ISeedModel<T> {\r\n key: string\r\n field: keyof T\r\n}\r\n\r\nexport interface IFilterOption {\r\n logic: ILogic\r\n ignoreEmpty: boolean\r\n}\r\n\r\nexport interface IRequestParamOption {\r\n ignoreEmpty: boolean\r\n}\r\n\r\nexport interface ISortOption {\r\n direction: ISortDirection\r\n}\r\n\r\nexport type ISortStore<T extends object> = { [key in keyof T]?: ISortDirection }\r\n\r\nexport type IAllOptions = IFilterOption & IRequestParamOption & ISortOption\r\n\r\nexport type IRequestParamResult<T extends object> = {\r\n sort?: ISortStore<T>[]\r\n skip: number\r\n take: number\r\n filter?: string\r\n noTotal?: boolean\r\n seedKey?: string\r\n seedField?: string\r\n}\r\n\r\nexport class RequestParam<T extends object = any> {\r\n private readonly _option?: Partial<IRequestParamOption>\r\n constructor(option?: Partial<IRequestParamOption>) {\r\n this._option = option\r\n }\r\n\r\n private mergeOptions = (...p: any[]): Partial<IAllOptions> => {\r\n return p.reduce((a, b) => {\r\n return Object.assign(a, b ?? {})\r\n }, {})\r\n }\r\n\r\n private ignoreEmpty = (field2: string, option?: Partial<IFilterOption>) => {\r\n const mOption = this.mergeOptions(this._option, option)\r\n return !field2 && mOption?.ignoreEmpty === true\r\n }\r\n\r\n private _filter: string[] = []\r\n private _filterBase = (field1: IVariable<T>, operation: string, field2: string, option?: Partial<IFilterOption>) => {\r\n const logicStr = this._filter.length ? ' ' + (option?.logic === 'And' ? '&&' : '||') + ' ' : ''\r\n this._filter.push(`${logicStr}${field1 as string}${operation}${field2 as string}`)\r\n return this\r\n }\r\n filter = (field1: IVariable<T>, field2: string | number, option?: Partial<IFilterOption>) => {\r\n if (typeof field2 === 'string' && this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '==', typeof field2 === 'string' ? `\"${field2}\"` : field2.toString(), option)\r\n }\r\n filterNotEquals = (field1: IVariable<T>, field2: string | number, option?: Partial<IFilterOption>) => {\r\n if (typeof field2 === 'string' && this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '!=', typeof field2 === 'string' ? `\"${field2}\"` : field2.toString(), option)\r\n }\r\n filterEnum = (field1: IVariable<T>, field2: string | number, option?: Partial<IFilterOption>) => {\r\n if (typeof field2 === 'string' && this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '==', typeof field2 === 'string' ? field2 : field2.toString(), option)\r\n }\r\n filterStartsWith = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '.startsWith(\"' + (field2 as string) + '\")', '', option)\r\n }\r\n filterContains = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '.Contains(\"' + (field2 as string) + '\")', '', option)\r\n }\r\n filterLast = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, '.endsWith(\"' + (field2 as string) + '\")', '', option)\r\n }\r\n filterNumber = (field1: IVariable<T>, operator: string, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, ` ${operator} ` + (field2 as string), '', option)\r\n }\r\n filterGreater = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, \" > '\" + (field2 as string) + \"'\", '', option)\r\n }\r\n filterLess = (field1: IVariable<T>, field2: string, option?: Partial<IFilterOption>) => {\r\n if (this.ignoreEmpty(field2, option)) return this\r\n return this._filterBase(field1, \" < '\" + (field2 as string) + \"'\", '', option)\r\n }\r\n filterCustom = (field1: string, option?: Partial<IFilterOption>) => {\r\n const logicStr = this._filter.length ? ' ' + (option?.logic === 'And' ? '&&' : '||') + ' ' : ''\r\n this._filter.push(`${logicStr}${field1 as string}`)\r\n return this\r\n }\r\n\r\n scope = (action: (crd: RequestParam<T>) => RequestParam<T>, option?: Partial<IFilterOption>) => {\r\n const crd = action(new RequestParam(this._option))\r\n const temp = crd.buildFilter()\r\n if (temp) {\r\n const logicStr = this._filter.length ? ' ' + (option?.logic === 'And' ? '&&' : '||') + ' ' : ''\r\n this._filter.push(`${logicStr}(${crd.buildFilter()})`)\r\n }\r\n return this\r\n }\r\n\r\n private seedStore?: ISeedModel<T>\r\n seed = (field: keyof T, key: string) => {\r\n this.seedStore = { field, key }\r\n return this\r\n }\r\n\r\n private _skip?: number\r\n skip = (skip: number) => {\r\n this._skip = skip\r\n return this\r\n }\r\n\r\n private _take?: number\r\n take = (take: number) => {\r\n this._take = take\r\n return this\r\n }\r\n\r\n private sortStore: ISortStore<T>[] = []\r\n private sortBase = (field1: IVariable<T>, direction: ISortDirection, option?: Partial<ISortOption>) => {\r\n const temp = {} as ISortStore<T>\r\n temp[field1] = direction\r\n if (!this.sortStore.some((item) => Object.keys(item)[0] === Object.keys(temp)[0])) {\r\n this.sortStore.push(temp)\r\n }\r\n return this\r\n }\r\n sort = (field1: IVariable<T>, option?: Partial<ISortOption>) => {\r\n this.sortBase(field1, option?.direction ? option.direction : 'ASC')\r\n return this\r\n }\r\n\r\n private _noTotal?: boolean\r\n noTotal = (value: boolean = true) => {\r\n this._noTotal = value\r\n return this\r\n }\r\n\r\n private buildFilter = () => {\r\n return this._filter.join('')\r\n }\r\n\r\n private buildPage = () => {\r\n const temp = {} as any\r\n if (this._skip) {\r\n temp.skip = this._skip\r\n }\r\n if (this._take) {\r\n temp.take = this._take\r\n }\r\n return temp as { skip: number; take: number }\r\n }\r\n\r\n private buildRandomWithSeedKey = (): Partial<ISeedModel<T>> => {\r\n if (this.seedStore?.field && !this.seedStore?.key) {\r\n console.warn('RandomWithSeedKey missing seedKey.')\r\n }\r\n if (this.seedStore?.key && !this.seedStore?.field) {\r\n console.warn('RandomWithSeedKey missing seedField.')\r\n }\r\n if (!this.seedStore?.key && !this.seedStore?.field) {\r\n return {}\r\n }\r\n return this.seedStore\r\n }\r\n\r\n build = (): IRequestParamResult<T> => {\r\n const obj: IRequestParamResult<T> = { ...this.buildPage() }\r\n if (this.sortStore.length > 0) obj.sort = this.sortStore\r\n const filter = this.buildFilter()\r\n if (filter) obj.filter = filter\r\n if (this._noTotal) obj.noTotal = this._noTotal\r\n const seedInfo = this.buildRandomWithSeedKey()\r\n if (!!seedInfo.key && !!seedInfo.field) {\r\n obj.seedField = seedInfo.field.toString()\r\n obj.seedKey = seedInfo.key\r\n }\r\n return obj\r\n }\r\n}\r\n\r\nexport const createRequestBuilder = <T extends object>(option?: Partial<IRequestParamOption>) => {\r\n return new RequestParam<T>(option)\r\n}\r\n"],"names":["RequestParam","_createClass","option","_this","this","_classCallCheck","_defineProperty","_len","arguments","length","p","Array","_key","reduce","a","b","Object","assign","field2","mOption","mergeOptions","_option","ignoreEmpty","field1","operation","logicStr","_filter","logic","push","concat","_filterBase","toString","operator","action","crd","buildFilter","field","key","seedStore","skip","_skip","take","_take","direction","temp","sortStore","some","item","keys","sortBase","value","undefined","_noTotal","join","_this$seedStore","_this$seedStore2","_this$seedStore3","_this$seedStore4","_this$seedStore5","_this$seedStore6","console","warn","obj","_objectSpread","buildPage","sort","filter","noTotal","seedInfo","buildRandomWithSeedKey","seedField","seedKey","createRequestBuilder"],"mappings":"wIAsCA,IAAaA,EAAYC,EAEvB,SAAAD,EAAYE,GAAqC,IAAAC,EAAAC,KAAAC,OAAAL,GAAAM,sBAI1B,WAAsC,IAAA,IAAAC,EAAAC,UAAAC,OAAlCC,EAAQC,IAAAA,MAAAJ,GAAAK,EAAA,EAAAA,EAAAL,EAAAK,IAARF,EAAQE,GAAAJ,UAAAI,GACjC,OAAOF,EAAEG,OAAO,SAACC,EAAGC,GAClB,OAAOC,OAAOC,OAAOH,EAAGC,QAAAA,EAAK,GAC9B,EAAE,MACJT,EAEqBF,KAAA,cAAA,SAACc,EAAgBhB,GACrC,IAAMiB,EAAUhB,EAAKiB,aAAajB,EAAKkB,QAASnB,GAChD,OAAQgB,IAAmC,KAAzBC,aAAO,EAAPA,EAASG,eAC5BhB,iBAE2B,IAAEA,EAAAF,KAAA,cACR,SAACmB,EAAsBC,EAAmBN,EAAgBhB,GAC9E,IAAMuB,EAAWtB,EAAKuB,QAAQjB,OAAS,KAAyB,SAAlBP,aAAAA,EAAAA,EAAQyB,OAAkB,KAAO,MAAQ,IAAM,GAE7F,OADAxB,EAAKuB,QAAQE,QAAIC,OAAIJ,GAAQI,OAAGN,GAAgBM,OAAGL,GAASK,OAAGX,IACxDf,IACRG,gBACQ,SAACiB,EAAsBL,EAAyBhB,GACvD,MAAsB,iBAAXgB,GAAuBf,EAAKmB,YAAYJ,EAAQhB,GAAgBC,EACpEA,EAAK2B,YAAYP,EAAQ,KAAwB,iBAAXL,MAAmBW,OAAOX,EAAM,KAAMA,EAAOa,WAAY7B,KACvGI,yBACiB,SAACiB,EAAsBL,EAAyBhB,GAChE,MAAsB,iBAAXgB,GAAuBf,EAAKmB,YAAYJ,EAAQ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AO,IAAIF,EAAgBE,EAC7B"}
@@ -1,2 +1,2 @@
1
- import{objectSpread2 as e,asyncToGenerator as r,regenerator as n,createForOfIteratorHelper as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{colors as a}from"@mui/material";var u=["image/jpeg","image/png","image/svg+xml"],o=["application/pdf"],i=[].concat(u,o),c=function(e){return i.some((function(r){return r===e}))},l=function(e){return u.some((function(r){return r===e}))},s=function(e){return o.some((function(r){return r===e}))},f={old:{color:a.grey[500],label:"Current",count:0},new:{color:a.green[500],label:"New",count:0},deleted:{color:a.red[500],label:"Delete",count:0}},p=function(e){return e.reduce((function(e,r){var n=r.status||"old";return e[n]=(e[n]||0)+1,e}),{old:0,new:0,deleted:0})},m=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-zA-Z0-9\s]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"-").toLowerCase()+"-"+(new Date).getTime().toString(36)},g=function(r,n){return e({id:m(r.name),name:r.name,type:l(r.type)?"image":s(r.type)?"pdf":"unknown",thumbnail:s(r.type)?"/images/pdf-default.webp":URL.createObjectURL(r),file:r},n)},b=function(e,r){var n=p(e),t=p(r);return JSON.stringify(n)!==JSON.stringify(t)},d=function(){var a=r(n().m((function r(a,u){var o,i,c,l,s,f;return n().w((function(r){for(;;)switch(r.n){case 0:if(u){r.n=1;break}return r.a(2,a);case 1:o=[],i=t(a),r.p=2,i.s();case 3:if((c=i.n()).done){r.n=10;break}if("new"!==(l=c.value).status||!l.file){r.n=8;break}return r.p=4,r.n=5,u(l.file);case 5:(s=r.v)&&s.url&&o.push(e(e({},l),{},{url:s.url,thumbnail:s.thumbnail,status:"old"})),r.n=7;break;case 6:r.p=6,r.v;case 7:r.n=9;break;case 8:o.push(l);case 9:r.n=3;break;case 10:r.n=12;break;case 11:r.p=11,f=r.v,i.e(f);case 12:return r.p=12,i.f(),r.f(12);case 13:return r.a(2,o)}}),r,null,[[4,6],[2,11,12,13]])})));return function(e,r){return a.apply(this,arguments)}}();export{i as allowFileTypes,u as allowImageTypes,o as allowPdfTypes,b as checkEqualQuality,d as fetchUploadNewFiles,g as fileToAttachItem,p as getAttachQuality,l as isImageFile,s as isPdfFile,c as isValidFileType,f as mapItemConfigs,m as toEnglishSlug};
1
+ import{objectSpread2 as e,asyncToGenerator as r,regenerator as n,createForOfIteratorHelper as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{colors as a}from"@mui/material";var u=["image/jpeg","image/png","image/svg+xml"],o=["application/pdf"],i=[].concat(u,o),c=function(e){return i.some(function(r){return r===e})},l=function(e){return u.some(function(r){return r===e})},s=function(e){return o.some(function(r){return r===e})},f={old:{color:a.grey[500],label:"Current",count:0},new:{color:a.green[500],label:"New",count:0},deleted:{color:a.red[500],label:"Delete",count:0}},p=function(e){return e.reduce(function(e,r){var n=r.status||"old";return e[n]=(e[n]||0)+1,e},{old:0,new:0,deleted:0})},m=function(e){return e.normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-zA-Z0-9\s]/g,"").replace(/\s+/g," ").trim().replace(/\s/g,"-").toLowerCase()+"-"+(new Date).getTime().toString(36)},g=function(r,n){return e({id:m(r.name),name:r.name,type:l(r.type)?"image":s(r.type)?"pdf":"unknown",thumbnail:s(r.type)?"/images/pdf-default.webp":URL.createObjectURL(r),file:r},n)},b=function(e,r){var n=p(e),t=p(r);return JSON.stringify(n)!==JSON.stringify(t)},d=function(){var a=r(n().m(function r(a,u){var o,i,c,l,s,f;return n().w(function(r){for(;;)switch(r.p=r.n){case 0:if(u){r.n=1;break}return r.a(2,a);case 1:o=[],i=t(a),r.p=2,i.s();case 3:if((c=i.n()).done){r.n=10;break}if("new"!==(l=c.value).status||!l.file){r.n=8;break}return r.p=4,r.n=5,u(l.file);case 5:(s=r.v)&&s.url&&o.push(e(e({},l),{},{url:s.url,thumbnail:s.thumbnail,status:"old"})),r.n=7;break;case 6:r.p=6,r.v;case 7:r.n=9;break;case 8:o.push(l);case 9:r.n=3;break;case 10:r.n=12;break;case 11:r.p=11,f=r.v,i.e(f);case 12:return r.p=12,i.f(),r.f(12);case 13:return r.a(2,o)}},r,null,[[4,6],[2,11,12,13]])}));return function(e,r){return a.apply(this,arguments)}}();export{i as allowFileTypes,u as allowImageTypes,o as allowPdfTypes,b as checkEqualQuality,d as fetchUploadNewFiles,g as fileToAttachItem,p as getAttachQuality,l as isImageFile,s as isPdfFile,c as isValidFileType,f as mapItemConfigs,m as toEnglishSlug};
2
2
  //# sourceMappingURL=helpers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sources":["../../../../src/lab/attach-widget/helpers.ts"],"sourcesContent":["import { colors } from '@mui/material'\r\nimport { AttachUploadFunction, IAttachItem, IAttachItemConfigs, IAttachItemStatus } from './types'\r\n\r\nexport const allowImageTypes = ['image/jpeg', 'image/png', 'image/svg+xml']\r\n\r\nexport const allowPdfTypes = ['application/pdf']\r\n\r\nexport const allowFileTypes = [...allowImageTypes, ...allowPdfTypes]\r\n\r\nexport const isValidFileType = (value?: string) => allowFileTypes.some((e) => e === value)\r\n\r\nexport const isImageFile = (value?: string) => allowImageTypes.some((e) => e === value)\r\n\r\nexport const isPdfFile = (value?: string) => allowPdfTypes.some((e) => e === value)\r\n\r\nexport const mapItemConfigs: IAttachItemConfigs = {\r\n old: { color: colors.grey[500], label: 'Current', count: 0 },\r\n new: { color: colors.green[500], label: 'New', count: 0 },\r\n deleted: { color: colors.red[500], label: 'Delete', count: 0 }\r\n}\r\n\r\nexport const getAttachQuality = (items: IAttachItem[]) => {\r\n return items.reduce<Record<IAttachItemStatus, number>>(\r\n (acc, item) => {\r\n const status = item.status || 'old'\r\n acc[status] = (acc[status] || 0) + 1\r\n return acc\r\n },\r\n { old: 0, new: 0, deleted: 0 }\r\n )\r\n}\r\n\r\nexport const toEnglishSlug = (str: string): string => {\r\n const temp = str\r\n .normalize('NFD') // split Vietnamese accents\r\n .replace(/[\\u0300-\\u036f]/g, '') // remove accents\r\n .replace(/[^a-zA-Z0-9\\s]/g, '') // remove special characters\r\n .replace(/\\s+/g, ' ') // replace multiple spaces with a single space\r\n .trim() // remove leading/trailing spaces\r\n .replace(/\\s/g, '-') // replace spaces with hyphens\r\n .toLowerCase()\r\n return temp + '-' + new Date().getTime().toString(36) // append timestamp to ensure uniqueness\r\n}\r\n\r\nexport const fileToAttachItem = (file: File, options?: Partial<IAttachItem>): IAttachItem => ({\r\n id: toEnglishSlug(file.name),\r\n name: file.name,\r\n type: isImageFile(file.type) ? 'image' : isPdfFile(file.type) ? 'pdf' : 'unknown',\r\n thumbnail: isPdfFile(file.type) ? '/images/pdf-default.webp' : URL.createObjectURL(file),\r\n file,\r\n ...options\r\n})\r\n\r\nexport const checkEqualQuality = (items1: IAttachItem[], items2: IAttachItem[]): boolean => {\r\n const quality = getAttachQuality(items1)\r\n const qualityCache = getAttachQuality(items2)\r\n return JSON.stringify(quality) !== JSON.stringify(qualityCache)\r\n}\r\n\r\n// Upload new items and return updated items with url, skip items if upload fails or returns empty\r\nexport const fetchUploadNewFiles = async (items: IAttachItem[], fetchUpload?: AttachUploadFunction): Promise<IAttachItem[]> => {\r\n if (!fetchUpload) return items\r\n\r\n const updated: IAttachItem[] = []\r\n for (const item of items) {\r\n if (item.status === 'new' && item.file) {\r\n try {\r\n const result = await fetchUpload(item.file)\r\n if (result && result.url) {\r\n updated.push({ ...item, url: result.url, thumbnail: result.thumbnail, status: 'old' })\r\n }\r\n // If result is empty or no url, skip this item\r\n } catch {\r\n // If upload fails, skip this item\r\n }\r\n } else {\r\n updated.push(item)\r\n }\r\n }\r\n return updated\r\n}\r\n"],"names":["allowImageTypes","allowPdfTypes","allowFileTypes","concat","isValidFileType","value","some","e","isImageFile","isPdfFile","mapItemConfigs","old","color","colors","grey","label","count","new","green","deleted","red","getAttachQuality","items","reduce","acc","item","status","toEnglishSlug","str","normalize","replace","trim","toLowerCase","Date","getTime","toString","fileToAttachItem","file","options","_objectSpread","id","name","type","thumbnail","URL","createObjectURL","checkEqualQuality","items1","items2","quality","qualityCache","JSON","stringify","fetchUploadNewFiles","_ref","_asyncToGenerator","_regenerator","m","_callee","fetchUpload","updated","_iterator","_step","result","_t2","w","_context","n","a","_createForOfIteratorHelper","p","s","done","v","url","push","f","_x","_x2","apply","this","arguments"],"mappings":"4LAGO,IAAMA,EAAkB,CAAC,aAAc,YAAa,iBAE9CC,EAAgB,CAAC,mBAEjBC,EAAcC,GAAAA,OAAOH,EAAoBC,GAEzCG,EAAkB,SAACC,GAAc,OAAKH,EAAeI,MAAK,SAACC,GAAC,OAAKA,IAAMF,IAAM,EAE7EG,EAAc,SAACH,GAAc,OAAKL,EAAgBM,MAAK,SAACC,GAAC,OAAKA,IAAMF,IAAM,EAE1EI,EAAY,SAACJ,GAAc,OAAKJ,EAAcK,MAAK,SAACC,GAAC,OAAKA,IAAMF,IAAM,EAEtEK,EAAqC,CAChDC,IAAK,CAAEC,MAAOC,EAAOC,KAAK,KAAMC,MAAO,UAAWC,MAAO,GACzDC,IAAK,CAAEL,MAAOC,EAAOK,MAAM,KAAMH,MAAO,MAAOC,MAAO,GACtDG,QAAS,CAAEP,MAAOC,EAAOO,IAAI,KAAML,MAAO,SAAUC,MAAO,IAGhDK,EAAmB,SAACC,GAC/B,OAAOA,EAAMC,QACX,SAACC,EAAKC,GACJ,IAAMC,EAASD,EAAKC,QAAU,MAE9B,OADAF,EAAIE,IAAWF,EAAIE,IAAW,GAAK,EAC5BF,CACT,GACA,CAAEb,IAAK,EAAGM,IAAK,EAAGE,QAAS,GAE/B,EAEaQ,EAAgB,SAACC,GAS5B,OARaA,EACVC,UAAU,OACVC,QAAQ,mBAAoB,IAC5BA,QAAQ,kBAAmB,IAC3BA,QAAQ,OAAQ,KAChBC,OACAD,QAAQ,MAAO,KACfE,cACW,KAAM,IAAIC,MAAOC,UAAUC,SAAS,GACpD,EAEaC,EAAmB,SAACC,EAAYC,GAA8B,OAAAC,EAAA,CACzEC,GAAIb,EAAcU,EAAKI,MACvBA,KAAMJ,E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EAKFP,EAAQe,KAAKlD,GAAK,KAAA,EAAAyC,EAAAC,EAAA,EAAA,MAAA,KAAA,GAAAD,EAAAC,EAAA,GAAA,MAAA,KAAA,GAAAD,EAAAI,EAAA,GAAAN,EAAAE,EAAAO,EAAAZ,EAAAtD,EAAAyD,GAAA,KAAA,GAAA,OAAAE,EAAAI,EAAA,GAAAT,EAAAe,IAAAV,EAAAU,EAAA,IAAA,KAAA,GAAA,OAAAV,EAAAE,EAAA,EAGfR,GAAO,GAAAF,EAAA,KAAA,CAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,GAAA,UACf,OAAA,SApB+BmB,EAAAC,GAAA,OAAAxB,EAAAyB,MAAAC,KAAAC,UAAA,CAAA,CAAA"}
1
+ {"version":3,"file":"helpers.js","sources":["../../../../src/lab/attach-widget/helpers.ts"],"sourcesContent":["import { colors } from '@mui/material'\r\nimport { AttachUploadFunction, IAttachItem, IAttachItemConfigs, IAttachItemStatus } from './types'\r\n\r\nexport const allowImageTypes = ['image/jpeg', 'image/png', 'image/svg+xml']\r\n\r\nexport const allowPdfTypes = ['application/pdf']\r\n\r\nexport const allowFileTypes = [...allowImageTypes, ...allowPdfTypes]\r\n\r\nexport const isValidFileType = (value?: string) => allowFileTypes.some((e) => e === value)\r\n\r\nexport const isImageFile = (value?: string) => allowImageTypes.some((e) => e === value)\r\n\r\nexport const isPdfFile = (value?: string) => allowPdfTypes.some((e) => e === value)\r\n\r\nexport const mapItemConfigs: IAttachItemConfigs = {\r\n old: { color: colors.grey[500], label: 'Current', count: 0 },\r\n new: { color: colors.green[500], label: 'New', count: 0 },\r\n deleted: { color: colors.red[500], label: 'Delete', count: 0 }\r\n}\r\n\r\nexport const getAttachQuality = (items: IAttachItem[]) => {\r\n return items.reduce<Record<IAttachItemStatus, number>>(\r\n (acc, item) => {\r\n const status = item.status || 'old'\r\n acc[status] = (acc[status] || 0) + 1\r\n return acc\r\n },\r\n { old: 0, new: 0, deleted: 0 }\r\n )\r\n}\r\n\r\nexport const toEnglishSlug = (str: string): string => {\r\n const temp = str\r\n .normalize('NFD') // split Vietnamese accents\r\n .replace(/[\\u0300-\\u036f]/g, '') // remove accents\r\n .replace(/[^a-zA-Z0-9\\s]/g, '') // remove special characters\r\n .replace(/\\s+/g, ' ') // replace multiple spaces with a single space\r\n .trim() // remove leading/trailing spaces\r\n .replace(/\\s/g, '-') // replace spaces with hyphens\r\n .toLowerCase()\r\n return temp + '-' + new Date().getTime().toString(36) // append timestamp to ensure uniqueness\r\n}\r\n\r\nexport const fileToAttachItem = (file: File, options?: Partial<IAttachItem>): IAttachItem => ({\r\n id: toEnglishSlug(file.name),\r\n name: file.name,\r\n type: isImageFile(file.type) ? 'image' : isPdfFile(file.type) ? 'pdf' : 'unknown',\r\n thumbnail: isPdfFile(file.type) ? '/images/pdf-default.webp' : URL.createObjectURL(file),\r\n file,\r\n ...options\r\n})\r\n\r\nexport const checkEqualQuality = (items1: IAttachItem[], items2: IAttachItem[]): boolean => {\r\n const quality = getAttachQuality(items1)\r\n const qualityCache = getAttachQuality(items2)\r\n return JSON.stringify(quality) !== JSON.stringify(qualityCache)\r\n}\r\n\r\n// Upload new items and return updated items with url, skip items if upload fails or returns empty\r\nexport const fetchUploadNewFiles = async (items: IAttachItem[], fetchUpload?: AttachUploadFunction): Promise<IAttachItem[]> => {\r\n if (!fetchUpload) return items\r\n\r\n const updated: IAttachItem[] = []\r\n for (const item of items) {\r\n if (item.status === 'new' && item.file) {\r\n try {\r\n const result = await fetchUpload(item.file)\r\n if (result && result.url) {\r\n updated.push({ ...item, url: result.url, thumbnail: result.thumbnail, status: 'old' })\r\n }\r\n // If result is empty or no url, skip this item\r\n } catch {\r\n // If upload fails, skip this item\r\n }\r\n } else {\r\n updated.push(item)\r\n }\r\n }\r\n return updated\r\n}\r\n"],"names":["allowImageTypes","allowPdfTypes","allowFileTypes","concat","isValidFileType","value","some","e","isImageFile","isPdfFile","mapItemConfigs","old","color","colors","grey","label","count","new","green","deleted","red","getAttachQuality","items","reduce","acc","item","status","toEnglishSlug","str","normalize","replace","trim","toLowerCase","Date","getTime","toString","fileToAttachItem","file","options","_objectSpread","id","name","type","thumbnail","URL","createObjectURL","checkEqualQuality","items1","items2","quality","qualityCache","JSON","stringify","fetchUploadNewFiles","_ref","_asyncToGenerator","_regenerator","m","_callee","fetchUpload","updated","_iterator","_step","result","_t2","w","_context","p","n","a","_createForOfIteratorHelper","s","done","v","url","push","f","_x","_x2","apply","this","arguments"],"mappings":"4LAGO,IAAMA,EAAkB,CAAC,aAAc,YAAa,iBAE9CC,EAAgB,CAAC,mBAEjBC,EAAcC,GAAAA,OAAOH,EAAoBC,GAEzCG,EAAkB,SAACC,GAAc,OAAKH,EAAeI,KAAK,SAACC,GAAC,OAAKA,IAAMF,GAAM,EAE7EG,EAAc,SAACH,GAAc,OAAKL,EAAgBM,KAAK,SAACC,GAAC,OAAKA,IAAMF,GAAM,EAE1EI,EAAY,SAACJ,GAAc,OAAKJ,EAAcK,KAAK,SAACC,GAAC,OAAKA,IAAMF,GAAM,EAEtEK,EAAqC,CAChDC,IAAK,CAAEC,MAAOC,EAAOC,KAAK,KAAMC,MAAO,UAAWC,MAAO,GACzDC,IAAK,CAAEL,MAAOC,EAAOK,MAAM,KAAMH,MAAO,MAAOC,MAAO,GACtDG,QAAS,CAAEP,MAAOC,EAAOO,IAAI,KAAML,MAAO,SAAUC,MAAO,IAGhDK,EAAmB,SAACC,GAC/B,OAAOA,EAAMC,OACX,SAACC,EAAKC,GACJ,IAAMC,EAASD,EAAKC,QAAU,MAE9B,OADAF,EAAIE,IAAWF,EAAIE,IAAW,GAAK,EAC5BF,CACT,EACA,CAAEb,IAAK,EAAGM,IAAK,EAAGE,QAAS,GAE/B,EAEaQ,EAAgB,SAACC,GAS5B,OARaA,EACVC,UAAU,OACVC,QAAQ,mBAAoB,IAC5BA,QAAQ,kBAAmB,IAC3BA,QAAQ,OAAQ,KAChBC,OACAD,QAAQ,MAAO,KACfE,cACW,KAAM,IAAI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OAAQ,SAEhFwC,EAAAE,EAAA,EAAA,MAAA,KAAA,EAAAF,EAAAC,EAAA,EAAAD,EAAAO,EAAA,KAAA,EAAAP,EAAAE,EAAA,EAAA,MAAA,KAAA,EAKFR,EAAQe,KAAKlD,GAAK,KAAA,EAAAyC,EAAAE,EAAA,EAAA,MAAA,KAAA,GAAAF,EAAAE,EAAA,GAAA,MAAA,KAAA,GAAAF,EAAAC,EAAA,GAAAH,EAAAE,EAAAO,EAAAZ,EAAAtD,EAAAyD,GAAA,KAAA,GAAA,OAAAE,EAAAC,EAAA,GAAAN,EAAAe,IAAAV,EAAAU,EAAA,IAAA,KAAA,GAAA,OAAAV,EAAAG,EAAA,EAGfT,GAAO,EAAAF,EAAA,KAAA,CAAA,CAAA,EAAA,GAAA,CAAA,EAAA,GAAA,GAAA,SACf,OAAA,SApB+BmB,EAAAC,GAAA,OAAAxB,EAAAyB,MAAAC,KAAAC,UAAA,CAAA,CAAA"}
@@ -1,2 +1,2 @@
1
- import{inherits as e,createClass as t,objectSpread2 as a,classCallCheck as r,callSuper as n,defineProperty as i,asyncToGenerator as o,regenerator as s,toConsumableArray as l}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as c,jsx as d}from"react/jsx-runtime";import h,{Component as u}from"react";import{Typography as m,Stack as p,Tooltip as g,IconButton as f,Divider as v,Grid as C,CircularProgress as y}from"@mui/material";import D from"@mui/icons-material/Save";import S from"@mui/icons-material/Close";import b from"@mui/icons-material/Replay";import k from"@mui/icons-material/Square";import I from"@mui/icons-material/Remove";import w from"@mui/icons-material/AttachFile";import{attachModalClasses as N,AttachModalStyled as j}from"./styled.js";import{getAttachQuality as F,mapItemConfigs as L,checkEqualQuality as x,allowFileTypes as H,fetchUploadNewFiles as R,isValidFileType as A,fileToAttachItem as z}from"./helpers.js";var O=function(){function O(e){var t;return r(this,O),t=n(this,O,[e]),i(t,"onSaveHandler",o(s().m((function e(){var a;return s().w((function(e){for(;;)switch(e.n){case 0:if(t.props.onChange){e.n=1;break}return e.a(2);case 1:if(t.setState({isLoading:!0}),a=l(t.attachItems),!t.props.uploadFile){e.n=3;break}return e.n=2,R(a,t.props.uploadFile);case 2:a=e.v;case 3:t.setState({isLoading:!1}),t.props.onChange(a,{isSave:!0}),t.props.onClose&&t.props.onClose();case 4:return e.a(2)}}),e)})))),i(t,"onFileChangeHandler",(function(e){var a=e.filter((function(e){return A(e.type)}));if(!(a.length<1)){var r=a.map((function(e){return z(e,{status:"new"})})),n=[].concat(l(r),l(t.attachItems));t.setState({attachs:n})}})),i(t,"handleTriggerDeleteItemClick",(function(e){var r=t.attachItems.reduce((function(t,r){var n=a({},r);if(n.id===e.id){if("new"===n.status)return t;n.status="deleted"===n.status?"old":"deleted"}return t.push(n),t}),[]);t.setState({attachs:r})})),i(t,"fileInputRef",h.createRef()),i(t,"handleIconClick",(function(){var e;null===(e=t.fileInputRef.current)||void 0===e||e.click()})),i(t,"handleFileChange",(function(e){var a=e.target.files;a&&a.length>0&&t.onFileChangeHandler(Array.from(a))})),i(t,"dragCounter",0),i(t,"handleDragEnter",(function(){t.dragCounter++,t.setState({isDragging:!0})})),i(t,"handleDragLeave",(function(){t.dragCounter--,0===t.dragCounter&&t.setState({isDragging:!1})})),i(t,"handleDragOver",(function(e){e.preventDefault()})),i(t,"handleDrop",(function(e){if(e.preventDefault(),e.stopPropagation(),t.state.isDragging){t.setState({isDragging:!1});var a=Array.from(e.dataTransfer.files);a.length>0&&t.onFileChangeHandler(a)}})),t.state={attachs:l(e.value),isDragging:!1,isLoading:!1},t}return e(O,u),t(O,[{key:"attachItems",get:function(){return this.state.attachs}},{key:"attachItemConfigs",get:function(){var e=F(this.attachItems);return Object.keys(L).map((function(t){var r=a({},L[t]);return r.count=e[t],r}))}},{key:"render",value:function(){var e=this,t=this.state.isDragging,a=x(this.attachItems,this.props.value),r=[N.root];return t&&!this.state.isLoading&&r.push(N.dragging),this.state.isLoading&&r.push(N.loading),c(j,{className:r.join(" "),onDragEnter:this.handleDragEnter,onDragLeave:this.handleDragLeave,onDragOver:this.handleDragOver,onDrop:this.handleDrop,children:[c("div",{className:N.header,children:[c("div",{children:[d(m,{variant:"h6",noWrap:!0,children:"Attach File"}),d(m,{variant:"body2",noWrap:!0,color:"text.secondary",children:"Data will only be updated after you click the Save button"})]}),c(p,{direction:"row",spacing:1,children:[d("input",{ref:this.fileInputRef,type:"file",hidden:!0,multiple:!0,onChange:this.handleFileChange,accept:H.join(",")}),d(g,{title:"Add files",arrow:!0,children:d(f,{color:"primary",onClick:this.handleIconClick,children:d(w,{})})}),d(g,{title:a?"Save":"Unsaved changes",arrow:!0,children:d("span",{children:d(f,{color:"primary",onClick:this.onSaveHandler,disabled:!a,children:d(D,{})})})}),d(g,{title:"Close",arrow:!0,children:d(f,{color:"secondary",onClick:this.props.onClose,children:d(S,{})})})]})]}),d(v,{}),c("div",{className:N.content,children:[this.attachItems.length<1&&d(p,{className:N.emptyState,children:d(m,{variant:"body2",color:"text.secondary",children:"Drag and drop files here or click to browse"})}),d(C,{container:!0,spacing:1.5,children:this.attachItems.map((function(t,a){var r=[N.item];return"deleted"===t.status?r.push(N.itemDelete):"new"===t.status&&r.push(N.itemNew),d(C,{item:!0,xs:6,sm:4,md:3,lg:2,children:c("div",{className:r.join(" "),children:[c("div",{className:N.itemHeader,children:[d(m,{variant:"body1",noWrap:!0,children:t.name}),d(g,{title:"deleted"===t.status?"Restore":"Delete",arrow:!0,children:d(f,{size:"small",color:"deleted"===t.status?"primary":"secondary",onClick:function(){return e.handleTriggerDeleteItemClick(t)},children:"deleted"===t.status?d(b,{fontSize:"small"}):d(I,{fontSize:"small"})})})]}),d("div",{className:N.itemContent,children:d("img",{src:t.thumbnail||t.url,alt:t.name})})]})},t.id+a.toString())}))})]}),d(v,{}),d("div",{className:N.footer,children:this.attachItemConfigs.map((function(e){var t=e.count||0;return c(p,{direction:"row",gap:.5,alignItems:"center",children:[d(k,{fontSize:"small",sx:{color:e.color}}),c(m,{variant:"body2",children:[e.label," (",t,")s"]})]},e.label)}))}),d("div",{className:N.dragPanel,children:d("div",{children:d(m,{variant:"body2",color:"primary",sx:{fontWeight:600},children:"Drop files here to upload"})})}),d("div",{className:N.overlay,children:d(y,{size:36})})]})}}])}();export{O as default};
1
+ import{inherits as e,createClass as t,objectSpread2 as a,classCallCheck as r,callSuper as n,defineProperty as i,asyncToGenerator as o,regenerator as s,toConsumableArray as l}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{jsxs as c,jsx as d}from"react/jsx-runtime";import h,{Component as u}from"react";import{Typography as m,Stack as p,Tooltip as g,IconButton as f,Divider as v,Grid as C,CircularProgress as y}from"@mui/material";import D from"@mui/icons-material/Save";import S from"@mui/icons-material/Close";import b from"@mui/icons-material/Replay";import k from"@mui/icons-material/Square";import I from"@mui/icons-material/Remove";import w from"@mui/icons-material/AttachFile";import{attachModalClasses as N,AttachModalStyled as j}from"./styled.js";import{getAttachQuality as F,mapItemConfigs as L,checkEqualQuality as x,allowFileTypes as H,fetchUploadNewFiles as R,isValidFileType as A,fileToAttachItem as z}from"./helpers.js";var O=function(){function O(e){var t;return r(this,O),t=n(this,O,[e]),i(t,"onSaveHandler",o(s().m(function e(){var a;return s().w(function(e){for(;;)switch(e.n){case 0:if(t.props.onChange){e.n=1;break}return e.a(2);case 1:if(t.setState({isLoading:!0}),a=l(t.attachItems),!t.props.uploadFile){e.n=3;break}return e.n=2,R(a,t.props.uploadFile);case 2:a=e.v;case 3:t.setState({isLoading:!1}),t.props.onChange(a,{isSave:!0}),t.props.onClose&&t.props.onClose();case 4:return e.a(2)}},e)}))),i(t,"onFileChangeHandler",function(e){var a=e.filter(function(e){return A(e.type)});if(!(a.length<1)){var r=a.map(function(e){return z(e,{status:"new"})}),n=[].concat(l(r),l(t.attachItems));t.setState({attachs:n})}}),i(t,"handleTriggerDeleteItemClick",function(e){var r=t.attachItems.reduce(function(t,r){var n=a({},r);if(n.id===e.id){if("new"===n.status)return t;n.status="deleted"===n.status?"old":"deleted"}return t.push(n),t},[]);t.setState({attachs:r})}),i(t,"fileInputRef",h.createRef()),i(t,"handleIconClick",function(){var e;null===(e=t.fileInputRef.current)||void 0===e||e.click()}),i(t,"handleFileChange",function(e){var a=e.target.files;a&&a.length>0&&t.onFileChangeHandler(Array.from(a))}),i(t,"dragCounter",0),i(t,"handleDragEnter",function(){t.dragCounter++,t.setState({isDragging:!0})}),i(t,"handleDragLeave",function(){t.dragCounter--,0===t.dragCounter&&t.setState({isDragging:!1})}),i(t,"handleDragOver",function(e){e.preventDefault()}),i(t,"handleDrop",function(e){if(e.preventDefault(),e.stopPropagation(),t.state.isDragging){t.setState({isDragging:!1});var a=Array.from(e.dataTransfer.files);a.length>0&&t.onFileChangeHandler(a)}}),t.state={attachs:l(e.value),isDragging:!1,isLoading:!1},t}return e(O,u),t(O,[{key:"attachItems",get:function(){return this.state.attachs}},{key:"attachItemConfigs",get:function(){var e=F(this.attachItems);return Object.keys(L).map(function(t){var r=a({},L[t]);return r.count=e[t],r})}},{key:"render",value:function(){var e=this,t=this.state.isDragging,a=x(this.attachItems,this.props.value),r=[N.root];return t&&!this.state.isLoading&&r.push(N.dragging),this.state.isLoading&&r.push(N.loading),c(j,{className:r.join(" "),onDragEnter:this.handleDragEnter,onDragLeave:this.handleDragLeave,onDragOver:this.handleDragOver,onDrop:this.handleDrop,children:[c("div",{className:N.header,children:[c("div",{children:[d(m,{variant:"h6",noWrap:!0,children:"Attach File"}),d(m,{variant:"body2",noWrap:!0,color:"text.secondary",children:"Data will only be updated after you click the Save button"})]}),c(p,{direction:"row",spacing:1,children:[d("input",{ref:this.fileInputRef,type:"file",hidden:!0,multiple:!0,onChange:this.handleFileChange,accept:H.join(",")}),d(g,{title:"Add files",arrow:!0,children:d(f,{color:"primary",onClick:this.handleIconClick,children:d(w,{})})}),d(g,{title:a?"Save":"Unsaved changes",arrow:!0,children:d("span",{children:d(f,{color:"primary",onClick:this.onSaveHandler,disabled:!a,children:d(D,{})})})}),d(g,{title:"Close",arrow:!0,children:d(f,{color:"secondary",onClick:this.props.onClose,children:d(S,{})})})]})]}),d(v,{}),c("div",{className:N.content,children:[this.attachItems.length<1&&d(p,{className:N.emptyState,children:d(m,{variant:"body2",color:"text.secondary",children:"Drag and drop files here or click to browse"})}),d(C,{container:!0,spacing:1.5,children:this.attachItems.map(function(t,a){var r=[N.item];return"deleted"===t.status?r.push(N.itemDelete):"new"===t.status&&r.push(N.itemNew),d(C,{item:!0,xs:6,sm:4,md:3,lg:2,children:c("div",{className:r.join(" "),children:[c("div",{className:N.itemHeader,children:[d(m,{variant:"body1",noWrap:!0,children:t.name}),d(g,{title:"deleted"===t.status?"Restore":"Delete",arrow:!0,children:d(f,{size:"small",color:"deleted"===t.status?"primary":"secondary",onClick:function(){return e.handleTriggerDeleteItemClick(t)},children:"deleted"===t.status?d(b,{fontSize:"small"}):d(I,{fontSize:"small"})})})]}),d("div",{className:N.itemContent,children:d("img",{src:t.thumbnail||t.url,alt:t.name})})]})},t.id+a.toString())})})]}),d(v,{}),d("div",{className:N.footer,children:this.attachItemConfigs.map(function(e){var t=e.count||0;return c(p,{direction:"row",gap:.5,alignItems:"center",children:[d(k,{fontSize:"small",sx:{color:e.color}}),c(m,{variant:"body2",children:[e.label," (",t,")s"]})]},e.label)})}),d("div",{className:N.dragPanel,children:d("div",{children:d(m,{variant:"body2",color:"primary",sx:{fontWeight:600},children:"Drop files here to upload"})})}),d("div",{className:N.overlay,children:d(y,{size:36})})]})}}])}();export{O as default};
2
2
  //# sourceMappingURL=modal.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"modal.js","sources":["../../../../src/lab/attach-widget/modal.tsx"],"sourcesContent":["import React, { Component } from 'react'\r\nimport { CircularProgress, Divider, Grid, IconButton, Stack, Tooltip, Typography } from '@mui/material'\r\nimport SaveIcon from '@mui/icons-material/Save'\r\nimport CloseIcon from '@mui/icons-material/Close'\r\nimport ReplayIcon from '@mui/icons-material/Replay'\r\nimport SquareIcon from '@mui/icons-material/Square'\r\nimport RemoveIcon from '@mui/icons-material/Remove'\r\nimport AttachFileIcon from '@mui/icons-material/AttachFile'\r\nimport { attachModalClasses, AttachModalStyled } from './styled'\r\nimport { allowFileTypes, checkEqualQuality, fetchUploadNewFiles } from './helpers'\r\nimport { fileToAttachItem, getAttachQuality, isValidFileType, mapItemConfigs } from './helpers'\r\nimport { AttachChangeFunction, AttachUploadFunction, IAttachItem, IAttachItemConfig, IAttachItemStatus } from './types'\r\n\r\ninterface IAttachModalProps {\r\n value: IAttachItem[]\r\n onChange?: AttachChangeFunction\r\n uploadFile?: AttachUploadFunction\r\n onClose?: () => void\r\n}\r\n\r\ninterface IAttachModalState {\r\n attachs: IAttachItem[]\r\n isDragging: boolean\r\n isLoading: boolean\r\n}\r\n\r\nclass AttachModal extends Component<IAttachModalProps, IAttachModalState> {\r\n constructor(props: IAttachModalProps) {\r\n super(props)\r\n this.state = { attachs: [...props.value], isDragging: false, isLoading: false }\r\n }\r\n\r\n get attachItems() {\r\n return this.state.attachs\r\n }\r\n\r\n get attachItemConfigs(): IAttachItemConfig[] {\r\n const temp = getAttachQuality(this.attachItems)\r\n const list = Object.keys(mapItemConfigs) as IAttachItemStatus[]\r\n return list.map((key) => {\r\n const config = { ...mapItemConfigs[key] }\r\n config.count = temp[key]\r\n return config\r\n })\r\n }\r\n\r\n render() {\r\n const { isDragging } = this.state\r\n const isSave = checkEqualQuality(this.attachItems, this.props.value)\r\n const rootClasses = [attachModalClasses.root]\r\n if (isDragging && !this.state.isLoading) rootClasses.push(attachModalClasses.dragging)\r\n if (this.state.isLoading) rootClasses.push(attachModalClasses.loading)\r\n\r\n return (\r\n <AttachModalStyled\r\n className={rootClasses.join(' ')}\r\n onDragEnter={this.handleDragEnter}\r\n onDragLeave={this.handleDragLeave}\r\n onDragOver={this.handleDragOver}\r\n onDrop={this.handleDrop}\r\n >\r\n <div className={attachModalClasses.header}>\r\n <div>\r\n <Typography variant='h6' noWrap>\r\n Attach File\r\n </Typography>\r\n <Typography variant='body2' noWrap color='text.secondary'>\r\n Data will only be updated after you click the Save button\r\n </Typography>\r\n </div>\r\n <Stack direction='row' spacing={1}>\r\n <input ref={this.fileInputRef} type='file' hidden multiple onChange={this.handleFileChange} accept={allowFileTypes.join(',')} />\r\n <Tooltip title='Add files' arrow>\r\n <IconButton color='primary' onClick={this.handleIconClick}>\r\n <AttachFileIcon />\r\n </IconButton>\r\n </Tooltip>\r\n <Tooltip title={isSave ? 'Save' : 'Unsaved changes'} arrow>\r\n <span>\r\n <IconButton color='primary' onClick={this.onSaveHandler} disabled={!isSave}>\r\n <SaveIcon />\r\n </IconButton>\r\n </span>\r\n </Tooltip>\r\n <Tooltip title='Close' arrow>\r\n <IconButton color='secondary' onClick={this.props.onClose}>\r\n <CloseIcon />\r\n </IconButton>\r\n </Tooltip>\r\n </Stack>\r\n </div>\r\n <Divider />\r\n <div className={attachModalClasses.content}>\r\n {this.attachItems.length < 1 && (\r\n <Stack className={attachModalClasses.emptyState}>\r\n <Typography variant='body2' color='text.secondary'>\r\n Drag and drop files here or click to browse\r\n </Typography>\r\n </Stack>\r\n )}\r\n <Grid container spacing={1.5}>\r\n {this.attachItems.map((x, i) => {\r\n const itemClasses = [attachModalClasses.item]\r\n\r\n if (x.status === 'deleted') itemClasses.push(attachModalClasses.itemDelete)\r\n else if (x.status === 'new') itemClasses.push(attachModalClasses.itemNew)\r\n\r\n return (\r\n <Grid key={x.id + i.toString()} item xs={6} sm={4} md={3} lg={2}>\r\n <div className={itemClasses.join(' ')}>\r\n <div className={attachModalClasses.itemHeader}>\r\n <Typography variant='body1' noWrap>\r\n {x.name}\r\n </Typography>\r\n <Tooltip title={x.status === 'deleted' ? 'Restore' : 'Delete'} arrow>\r\n <IconButton\r\n size='small'\r\n color={x.status === 'deleted' ? 'primary' : 'secondary'}\r\n onClick={() => this.handleTriggerDeleteItemClick(x)}\r\n >\r\n {x.status === 'deleted' ? <ReplayIcon fontSize='small' /> : <RemoveIcon fontSize='small' />}\r\n </IconButton>\r\n </Tooltip>\r\n </div>\r\n <div className={attachModalClasses.itemContent}>\r\n <img src={x.thumbnail || x.url} alt={x.name} />\r\n </div>\r\n </div>\r\n </Grid>\r\n )\r\n })}\r\n </Grid>\r\n </div>\r\n <Divider />\r\n <div className={attachModalClasses.footer}>\r\n {this.attachItemConfigs.map((config) => {\r\n const count = config.count || 0\r\n return (\r\n <Stack key={config.label} direction='row' gap={0.5} alignItems='center'>\r\n <SquareIcon fontSize='small' sx={{ color: config.color }} />\r\n <Typography variant='body2'>\r\n {config.label} ({count})s\r\n </Typography>\r\n </Stack>\r\n )\r\n })}\r\n </div>\r\n <div className={attachModalClasses.dragPanel}>\r\n <div>\r\n <Typography variant='body2' color='primary' sx={{ fontWeight: 600 }}>\r\n Drop files here to upload\r\n </Typography>\r\n </div>\r\n </div>\r\n <div className={attachModalClasses.overlay}>\r\n <CircularProgress size={36} />\r\n </div>\r\n </AttachModalStyled>\r\n )\r\n }\r\n\r\n onSaveHandler = async () => {\r\n if (!this.props.onChange) return\r\n\r\n this.setState({ isLoading: true })\r\n let updatedItems = [...this.attachItems]\r\n\r\n if (this.props.uploadFile) {\r\n updatedItems = await fetchUploadNewFiles(updatedItems, this.props.uploadFile)\r\n }\r\n\r\n this.setState({ isLoading: false })\r\n this.props.onChange(updatedItems, { isSave: true })\r\n if (this.props.onClose) this.props.onClose()\r\n }\r\n\r\n onFileChangeHandler = (files: File[]) => {\r\n const validFiles = files.filter((f) => isValidFileType(f.type))\r\n if (validFiles.length < 1) return\r\n const items = validFiles.map((x) => fileToAttachItem(x, { status: 'new' }))\r\n const newItems = [...items, ...this.attachItems]\r\n this.setState({ attachs: newItems }) // Update state directly to avoid memory leaks\r\n }\r\n\r\n handleTriggerDeleteItemClick = (item: IAttachItem) => {\r\n const updatedItems = this.attachItems.reduce<IAttachItem[]>((a, b) => {\r\n const obj = { ...b }\r\n if (obj.id === item.id) {\r\n if (obj.status === 'new') return a // Do not delete new item, they are not saved yet\r\n obj.status = obj.status === 'deleted' ? 'old' : 'deleted'\r\n }\r\n a.push(obj)\r\n return a\r\n }, [])\r\n this.setState({ attachs: updatedItems }) // Update state directly to avoid memory leaks\r\n }\r\n\r\n fileInputRef = React.createRef<HTMLInputElement>()\r\n handleIconClick = () => {\r\n this.fileInputRef.current?.click()\r\n }\r\n\r\n handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {\r\n const files = e.target.files\r\n if (files && files.length > 0) {\r\n this.onFileChangeHandler(Array.from(files))\r\n }\r\n }\r\n\r\n dragCounter = 0\r\n handleDragEnter = () => {\r\n this.dragCounter++\r\n this.setState({ isDragging: true })\r\n }\r\n\r\n handleDragLeave = () => {\r\n this.dragCounter--\r\n if (this.dragCounter === 0) {\r\n this.setState({ isDragging: false })\r\n }\r\n }\r\n\r\n handleDragOver = (e: React.DragEvent) => {\r\n e.preventDefault()\r\n }\r\n\r\n handleDrop = (e: React.DragEvent) => {\r\n e.preventDefault()\r\n e.stopPropagation()\r\n if (!this.state.isDragging) return // If not dragging, do nothing\r\n this.setState({ isDragging: false })\r\n const files = Array.from(e.dataTransfer.files)\r\n if (files.length > 0) {\r\n this.onFileChangeHandler(files)\r\n }\r\n }\r\n}\r\nexport default AttachModal\r\n"],"names":["AttachModal","props","_this","_classCallCheck","_callSuper","_defineProperty","_asyncToGenerator","_regenerator","m","_callee","updatedItems","w","_context","n","onChange","a","setState","isLoading","_toConsumableArray","attachItems","uploadFile","fetchUploadNewFiles","v","isSave","onClose","files","validFiles","filter","f","isValidFileType","type","length","items","map","x","fileToAttachItem","status","newItems","concat","attachs","item","reduce","b","obj","_objectSpread","id","push","React","createRef","_this$fileInputRef$cu","fileInputRef","current","click","e","target","onFileChangeHandler","Array","from","dragCounter","isDragging","preventDefault","stopPropagation","state","dataTransfer","value","_inherits","Component","_createClass","key","get","this","temp","getAttachQuality","Object","keys","mapItemConfigs","config","count","_this2","checkEqualQuality","rootClasses","attachModalClasses","root","dragging","loading","_jsxs","AttachModalStyled","className","join","onDragEnter","handleDragEnter","onDragLeave","handleDragLeave","onDragOver","handleDragOver","onDrop","handleDrop","children","header","_jsx","Typography","variant","noWrap","color","Stack","direction","spacing","ref","hidden","multiple","handleFileChange","accept","allowFileTypes","Tooltip","title","arrow","IconButton","onClick","handleIconClick","AttachFileIcon","onSaveHandler","disabled","SaveIcon","CloseIcon","Divider","content","emptyState","Grid","container","i","itemClasses","itemDelete","itemNew","xs","sm","md","lg","itemHeader","name","size","handleTriggerDeleteItemClick","ReplayIcon","fontSize","RemoveIcon","itemContent","src","thumbnail","url","alt","toString","footer","attachItemConfigs","gap","alignItems","SquareIcon","sx","label","dragPanel","fontWeight","overlay","CircularProgress"],"mappings":"k7BA0BMA,IAAAA,aACJ,SAAAA,EAAYC,GAAwB,IAAAC,EAE6C,OAF7CC,OAAAH,GAClCE,EAAAE,EAAAJ,KAAAA,GAAMC,IAAMI,EAAAH,EAAA,gBAAAI,EAAAC,IAAAC,GAqIE,SAAAC,IAAA,IAAAC,EAAA,OAAAH,IAAAI,GAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA,KAAA,EAAA,GACTX,EAAKD,MAAMa,SAAQ,CAAAF,EAAAC,EAAA,EAAA,KAAA,CAAA,OAAAD,EAAAG,EAAA,GAAA,KAAA,EAGe,GADvCb,EAAKc,SAAS,CAAEC,WAAW,IACvBP,EAAYQ,EAAOhB,EAAKiB,cAExBjB,EAAKD,MAAMmB,WAAU,CAAAR,EAAAC,EAAA,EAAA,KAAA,CAAA,OAAAD,EAAAC,EAAA,EACFQ,EAAoBX,EAAcR,EAAKD,MAAMmB,YAAW,KAAA,EAA7EV,EAAYE,EAAAU,EAAA,KAAA,EAGdpB,EAAKc,SAAS,CAAEC,WAAW,IAC3Bf,EAAKD,MAAMa,SAASJ,EAAc,CAAEa,QAAQ,IACxCrB,EAAKD,MAAMuB,SAAStB,EAAKD,MAAMuB,UAAS,KAAA,EAAA,OAAAZ,EAAAG,EAAA,GAAA,GAAAN,EAC7C,MAAAJ,EAAAH,EAEqB,uBAAA,SAAC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dD,EAAOgF,MAOtB,MAEHzD,EAAA,MAAA,CAAKZ,UAAWN,EAAmB4E,UACjC5D,SAAAE,EAAA,MAAA,CAAAF,SACEE,EAACC,EAAU,CAACC,QAAQ,QAAQE,MAAM,UAAUoD,GAAI,CAAEG,WAAY,KAEjD7D,SAAA,kCAGjBE,EAAA,MAAA,CAAKZ,UAAWN,EAAmB8E,QACjC9D,SAAAE,EAAC6D,EAAgB,CAACrB,KAAM,SAIhC,IAAC"}
1
+ {"version":3,"file":"modal.js","sources":["../../../../src/lab/attach-widget/modal.tsx"],"sourcesContent":["import React, { Component } from 'react'\r\nimport { CircularProgress, Divider, Grid, IconButton, Stack, Tooltip, Typography } from '@mui/material'\r\nimport SaveIcon from '@mui/icons-material/Save'\r\nimport CloseIcon from '@mui/icons-material/Close'\r\nimport ReplayIcon from '@mui/icons-material/Replay'\r\nimport SquareIcon from '@mui/icons-material/Square'\r\nimport RemoveIcon from '@mui/icons-material/Remove'\r\nimport AttachFileIcon from '@mui/icons-material/AttachFile'\r\nimport { attachModalClasses, AttachModalStyled } from './styled'\r\nimport { allowFileTypes, checkEqualQuality, fetchUploadNewFiles } from './helpers'\r\nimport { fileToAttachItem, getAttachQuality, isValidFileType, mapItemConfigs } from './helpers'\r\nimport { AttachChangeFunction, AttachUploadFunction, IAttachItem, IAttachItemConfig, IAttachItemStatus } from './types'\r\n\r\ninterface IAttachModalProps {\r\n value: IAttachItem[]\r\n onChange?: AttachChangeFunction\r\n uploadFile?: AttachUploadFunction\r\n onClose?: () => void\r\n}\r\n\r\ninterface IAttachModalState {\r\n attachs: IAttachItem[]\r\n isDragging: boolean\r\n isLoading: boolean\r\n}\r\n\r\nclass AttachModal extends Component<IAttachModalProps, IAttachModalState> {\r\n constructor(props: IAttachModalProps) {\r\n super(props)\r\n this.state = { attachs: [...props.value], isDragging: false, isLoading: false }\r\n }\r\n\r\n get attachItems() {\r\n return this.state.attachs\r\n }\r\n\r\n get attachItemConfigs(): IAttachItemConfig[] {\r\n const temp = getAttachQuality(this.attachItems)\r\n const list = Object.keys(mapItemConfigs) as IAttachItemStatus[]\r\n return list.map((key) => {\r\n const config = { ...mapItemConfigs[key] }\r\n config.count = temp[key]\r\n return config\r\n })\r\n }\r\n\r\n render() {\r\n const { isDragging } = this.state\r\n const isSave = checkEqualQuality(this.attachItems, this.props.value)\r\n const rootClasses = [attachModalClasses.root]\r\n if (isDragging && !this.state.isLoading) rootClasses.push(attachModalClasses.dragging)\r\n if (this.state.isLoading) rootClasses.push(attachModalClasses.loading)\r\n\r\n return (\r\n <AttachModalStyled\r\n className={rootClasses.join(' ')}\r\n onDragEnter={this.handleDragEnter}\r\n onDragLeave={this.handleDragLeave}\r\n onDragOver={this.handleDragOver}\r\n onDrop={this.handleDrop}\r\n >\r\n <div className={attachModalClasses.header}>\r\n <div>\r\n <Typography variant='h6' noWrap>\r\n Attach File\r\n </Typography>\r\n <Typography variant='body2' noWrap color='text.secondary'>\r\n Data will only be updated after you click the Save button\r\n </Typography>\r\n </div>\r\n <Stack direction='row' spacing={1}>\r\n <input ref={this.fileInputRef} type='file' hidden multiple onChange={this.handleFileChange} accept={allowFileTypes.join(',')} />\r\n <Tooltip title='Add files' arrow>\r\n <IconButton color='primary' onClick={this.handleIconClick}>\r\n <AttachFileIcon />\r\n </IconButton>\r\n </Tooltip>\r\n <Tooltip title={isSave ? 'Save' : 'Unsaved changes'} arrow>\r\n <span>\r\n <IconButton color='primary' onClick={this.onSaveHandler} disabled={!isSave}>\r\n <SaveIcon />\r\n </IconButton>\r\n </span>\r\n </Tooltip>\r\n <Tooltip title='Close' arrow>\r\n <IconButton color='secondary' onClick={this.props.onClose}>\r\n <CloseIcon />\r\n </IconButton>\r\n </Tooltip>\r\n </Stack>\r\n </div>\r\n <Divider />\r\n <div className={attachModalClasses.content}>\r\n {this.attachItems.length < 1 && (\r\n <Stack className={attachModalClasses.emptyState}>\r\n <Typography variant='body2' color='text.secondary'>\r\n Drag and drop files here or click to browse\r\n </Typography>\r\n </Stack>\r\n )}\r\n <Grid container spacing={1.5}>\r\n {this.attachItems.map((x, i) => {\r\n const itemClasses = [attachModalClasses.item]\r\n\r\n if (x.status === 'deleted') itemClasses.push(attachModalClasses.itemDelete)\r\n else if (x.status === 'new') itemClasses.push(attachModalClasses.itemNew)\r\n\r\n return (\r\n <Grid key={x.id + i.toString()} item xs={6} sm={4} md={3} lg={2}>\r\n <div className={itemClasses.join(' ')}>\r\n <div className={attachModalClasses.itemHeader}>\r\n <Typography variant='body1' noWrap>\r\n {x.name}\r\n </Typography>\r\n <Tooltip title={x.status === 'deleted' ? 'Restore' : 'Delete'} arrow>\r\n <IconButton\r\n size='small'\r\n color={x.status === 'deleted' ? 'primary' : 'secondary'}\r\n onClick={() => this.handleTriggerDeleteItemClick(x)}\r\n >\r\n {x.status === 'deleted' ? <ReplayIcon fontSize='small' /> : <RemoveIcon fontSize='small' />}\r\n </IconButton>\r\n </Tooltip>\r\n </div>\r\n <div className={attachModalClasses.itemContent}>\r\n <img src={x.thumbnail || x.url} alt={x.name} />\r\n </div>\r\n </div>\r\n </Grid>\r\n )\r\n })}\r\n </Grid>\r\n </div>\r\n <Divider />\r\n <div className={attachModalClasses.footer}>\r\n {this.attachItemConfigs.map((config) => {\r\n const count = config.count || 0\r\n return (\r\n <Stack key={config.label} direction='row' gap={0.5} alignItems='center'>\r\n <SquareIcon fontSize='small' sx={{ color: config.color }} />\r\n <Typography variant='body2'>\r\n {config.label} ({count})s\r\n </Typography>\r\n </Stack>\r\n )\r\n })}\r\n </div>\r\n <div className={attachModalClasses.dragPanel}>\r\n <div>\r\n <Typography variant='body2' color='primary' sx={{ fontWeight: 600 }}>\r\n Drop files here to upload\r\n </Typography>\r\n </div>\r\n </div>\r\n <div className={attachModalClasses.overlay}>\r\n <CircularProgress size={36} />\r\n </div>\r\n </AttachModalStyled>\r\n )\r\n }\r\n\r\n onSaveHandler = async () => {\r\n if (!this.props.onChange) return\r\n\r\n this.setState({ isLoading: true })\r\n let updatedItems = [...this.attachItems]\r\n\r\n if (this.props.uploadFile) {\r\n updatedItems = await fetchUploadNewFiles(updatedItems, this.props.uploadFile)\r\n }\r\n\r\n this.setState({ isLoading: false })\r\n this.props.onChange(updatedItems, { isSave: true })\r\n if (this.props.onClose) this.props.onClose()\r\n }\r\n\r\n onFileChangeHandler = (files: File[]) => {\r\n const validFiles = files.filter((f) => isValidFileType(f.type))\r\n if (validFiles.length < 1) return\r\n const items = validFiles.map((x) => fileToAttachItem(x, { status: 'new' }))\r\n const newItems = [...items, ...this.attachItems]\r\n this.setState({ attachs: newItems }) // Update state directly to avoid memory leaks\r\n }\r\n\r\n handleTriggerDeleteItemClick = (item: IAttachItem) => {\r\n const updatedItems = this.attachItems.reduce<IAttachItem[]>((a, b) => {\r\n const obj = { ...b }\r\n if (obj.id === item.id) {\r\n if (obj.status === 'new') return a // Do not delete new item, they are not saved yet\r\n obj.status = obj.status === 'deleted' ? 'old' : 'deleted'\r\n }\r\n a.push(obj)\r\n return a\r\n }, [])\r\n this.setState({ attachs: updatedItems }) // Update state directly to avoid memory leaks\r\n }\r\n\r\n fileInputRef = React.createRef<HTMLInputElement>()\r\n handleIconClick = () => {\r\n this.fileInputRef.current?.click()\r\n }\r\n\r\n handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => {\r\n const files = e.target.files\r\n if (files && files.length > 0) {\r\n this.onFileChangeHandler(Array.from(files))\r\n }\r\n }\r\n\r\n dragCounter = 0\r\n handleDragEnter = () => {\r\n this.dragCounter++\r\n this.setState({ isDragging: true })\r\n }\r\n\r\n handleDragLeave = () => {\r\n this.dragCounter--\r\n if (this.dragCounter === 0) {\r\n this.setState({ isDragging: false })\r\n }\r\n }\r\n\r\n handleDragOver = (e: React.DragEvent) => {\r\n e.preventDefault()\r\n }\r\n\r\n handleDrop = (e: React.DragEvent) => {\r\n e.preventDefault()\r\n e.stopPropagation()\r\n if (!this.state.isDragging) return // If not dragging, do nothing\r\n this.setState({ isDragging: false })\r\n const files = Array.from(e.dataTransfer.files)\r\n if (files.length > 0) {\r\n this.onFileChangeHandler(files)\r\n }\r\n }\r\n}\r\nexport default AttachModal\r\n"],"names":["AttachModal","props","_this","_classCallCheck","_callSuper","_defineProperty","_asyncToGenerator","_regenerator","m","_callee","updatedItems","w","_context","n","onChange","a","setState","isLoading","_toConsumableArray","attachItems","uploadFile","fetchUploadNewFiles","v","isSave","onClose","files","validFiles","filter","f","isValidFileType","type","length","items","map","x","fileToAttachItem","status","newItems","concat","attachs","item","reduce","b","obj","_objectSpread","id","push","React","createRef","_this$fileInputRef$cu","fileInputRef","current","click","e","target","onFileChangeHandler","Array","from","dragCounter","isDragging","preventDefault","stopPropagation","state","dataTransfer","value","_inherits","Component","_createClass","key","get","this","temp","getAttachQuality","Object","keys","mapItemConfigs","config","count","_this2","checkEqualQuality","rootClasses","attachModalClasses","root","dragging","loading","_jsxs","AttachModalStyled","className","join","onDragEnter","handleDragEnter","onDragLeave","handleDragLeave","onDragOver","handleDragOver","onDrop","handleDrop","children","header","_jsx","Typography","variant","noWrap","color","Stack","direction","spacing","ref","hidden","multiple","handleFileChange","accept","allowFileTypes","Tooltip","title","arrow","IconButton","onClick","handleIconClick","AttachFileIcon","onSaveHandler","disabled","SaveIcon","CloseIcon","Divider","content","emptyState","Grid","container","i","itemClasses","itemDelete","itemNew","xs","sm","md","lg","itemHeader","name","size","handleTriggerDeleteItemClick","ReplayIcon","fontSize","RemoveIcon","itemContent","src","thumbnail","url","alt","toString","footer","attachItemConfigs","gap","alignItems","SquareIcon","sx","label","dragPanel","fontWeight","overlay","CircularProgress"],"mappings":"k7BA0BMA,IAAAA,aACJ,SAAAA,EAAYC,GAAwB,IAAAC,EAE6C,OAF7CC,OAAAH,GAClCE,EAAAE,EAAAJ,KAAAA,GAAMC,IAAMI,EAAAH,EAAA,gBAAAI,EAAAC,IAAAC,EAqIE,SAAAC,IAAA,IAAAC,EAAA,OAAAH,IAAAI,EAAA,SAAAC,GAAA,cAAAA,EAAAC,GAAA,KAAA,E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AAWD,SAAS,iBAIvF3C,EAAK,MAAA,CAAAZ,UAAWN,EAAmB+D,YAAW/C,SAC5CE,SAAK8C,IAAK/G,EAAEgH,WAAahH,EAAEiH,IAAKC,IAAKlH,EAAEwG,aAjBlCxG,EAAEW,GAAKoF,EAAEoB,WAsBvB,QAGLlD,EAACyB,EAAU,CAAA,GACXzB,EAAK,MAAA,CAAAZ,UAAWN,EAAmBqE,OAAMrD,SACtC3B,KAAKiF,kBAAkBtH,IAAI,SAAC2C,GAC3B,IAAMC,EAAQD,EAAOC,OAAS,EAC9B,OACEQ,EAACmB,EAAyB,CAAAC,UAAU,MAAM+C,IAAK,GAAKC,WAAW,SAC7DxD,SAAA,CAAAE,EAACuD,EAAU,CAACZ,SAAS,QAAQa,GAAI,CAAEpD,MAAO3B,EAAO2B,SACjDlB,EAACe,EAAW,CAAAC,QAAQ,kBACjBzB,EAAOgF,MAAK,KAAI/E,EAAK,UAHdD,EAAOgF,MAOtB,KAEHzD,EAAA,MAAA,CAAKZ,UAAWN,EAAmB4E,UACjC5D,SAAAE,EAAA,MAAA,CAAAF,SACEE,EAACC,EAAU,CAACC,QAAQ,QAAQE,MAAM,UAAUoD,GAAI,CAAEG,WAAY,KAEjD7D,SAAA,kCAGjBE,EAAA,MAAA,CAAKZ,UAAWN,EAAmB8E,QACjC9D,SAAAE,EAAC6D,EAAgB,CAACrB,KAAM,SAIhC,IAAC"}
@@ -1,2 +1,2 @@
1
- import{defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{styled as e,alpha as i,Box as o}from"@mui/material";import{mapItemConfigs as a}from"./helpers.js";var r={root:"AttachWidget-root",content:"AttachWidget-content",dragging:"AttachWidget-dragging",dragPanel:"AttachWidget-dragPanel",inputButton:"AttachWidget-inputButton",moreButton:"AttachWidget-moreButton",list:"AttachWidget-list",listItem:"AttachWidget-listItem",overlay:"AttachWidget-overlay",loading:"AttachWidget-loading"},n=function(t,e){return"".concat((null==e?void 0:e.prefix)||"",".").concat(r[t]).concat((null==e?void 0:e.suffix)||"")},d=e("div")((function(e){var o,a=e.theme;return t(t(t(t(t(t(t(t(t(t(o={},n("root",{prefix:"&"}),{position:"relative",width:"100%",height:"100%",backgroundColor:a.palette.common.white,borderRadius:a.shape.borderRadius}),n("content"),{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"flex-start",padding:a.spacing(1)}),n("list"),{height:"100%",flex:1,display:"flex",alignItems:"center",gap:a.spacing(.75),overflow:"hidden",minWidth:0,position:"relative","&::after":{content:'""',height:"100%",width:"30px",position:"absolute",right:0,top:0,zIndex:1,background:"linear-gradient(to right, transparent, #ffffffb0, #ffffff)"}}),n("listItem"),{width:"var(--attach-widget-list-item-width, 42px)",padding:0,aspectRatio:"5 / 7",borderRadius:a.shape.borderRadius,border:"1px solid "+a.palette.divider,boxShadow:"rgba(99, 99, 99, 0.2) 0px 2px 8px 0px",img:{width:"100%",height:"100%",objectFit:"cover"}}),n("inputButton"),{width:"var(--attach-widget-list-item-width, 42px)",aspectRatio:"5 / 7",padding:0,cursor:"pointer",color:a.palette.primary.main,borderRadius:a.shape.borderRadius,border:"1px dashed "+a.palette.primary.main,marginRight:a.spacing(1),"&:hover":{color:a.palette.primary.dark}}),n("moreButton"),{opacity:.5,transition:"opacity 0.3s ease-in-out"}),n("dragPanel"),{position:"absolute",top:0,left:0,right:0,bottom:0,padding:a.spacing(.75),backgroundColor:a.palette.common.white,pointerEvents:"none",borderRadius:a.shape.borderRadius,display:"flex",opacity:0,zIndex:1,transition:"opacity 0.3s ease-in-out","& > div":{flex:1,display:"flex",alignItems:"center",justifyContent:"center",border:"2px dashed "+a.palette.primary.main,borderRadius:a.shape.borderRadius}}),n("overlay"),{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:i(a.palette.common.white,.5),zIndex:1,opacity:0,transition:"opacity 0.3s ease-in-out",visibility:"hidden",display:"flex",alignItems:"center",justifyContent:"center"}),n("loading",{prefix:"&"}),t({},n("overlay"),{opacity:1,visibility:"visible"})),n("dragging",{prefix:"&"}),t(t({},n("dragPanel"),{opacity:1}),n("content"),{pointerEvents:"none"})),t(o,n("root",{prefix:"&",suffix:":hover"}),t({},n("moreButton"),{opacity:1}))})),l={root:"AttachModal-root",header:"AttachModal-header",footer:"AttachModal-footer",loading:"AttachModal-loading",overlay:"AttachModal-overlay",dragging:"AttachModal-dragging",dragPanel:"AttachModal-dragPanel",content:"AttachModal-content",emptyState:"AttachModal-emptyState",closeButton:"AttachModal-closeButton",item:"AttachModal-item",itemHeader:"AttachModal-itemHeader",itemContent:"AttachModal-itemContent",itemNew:"AttachModal-itemNew",itemDelete:"AttachModal-itemDelete"},p=function(t,e){return"".concat((null==e?void 0:e.prefix)||"",".").concat(l[t]).concat((null==e?void 0:e.suffix)||"")},s=e(o)((function(e){var o,r,n,d,l=e.theme;return t(t(t(t(t(t(t(t(t(t(d={},p("root",{prefix:"&"}),{backgroundColor:l.palette.background.paper,borderRadius:l.shape.borderRadius,boxShadow:l.shadows[5],width:"calc(100vw - 48px)",maxHeight:"calc(100vh - 48px)",maxWidth:l.breakpoints.values.md,position:"relative",display:"flex",flexDirection:"column"}),p("header"),{display:"flex",justifyContent:"space-between",alignItems:"center",padding:l.spacing(1,2)}),p("footer"),{padding:l.spacing(1,2),display:"flex",alignItems:"center",gap:l.spacing(3)}),p("content"),{minHeight:"200px",padding:l.spacing(1),overflowY:"auto",height:"100%"}),p("emptyState"),{display:"flex",alignItems:"center",justifyContent:"center",height:"168px"}),p("itemContent"),{width:"100%",height:"100%",padding:0,borderRadius:l.shape.borderRadius,cursor:"pointer",backgroundColor:l.palette.background.paper,img:{width:"100%",height:"100%",objectFit:"cover"}}),p("itemHeader"),{marginTop:l.spacing(-.5),padding:l.spacing(.5,0),display:"flex",alignItems:"center",justifyContent:"space-between",".MuiTypography-root":{color:l.palette.common.white},".MuiIconButton-root":{backgroundColor:i(l.palette.common.white,.5),".MuiSvgIcon-root":{fontSize:"1rem"},"&:hover":{backgroundColor:l.palette.common.white}}}),p("item"),t(t({width:"var(--attach-modal-list-item-width, 100%)",aspectRatio:"5 / 7",display:"inline-block",position:"relative",backgroundColor:null===(o=a.old)||void 0===o?void 0:o.color,borderRadius:l.shape.borderRadius,padding:l.spacing(.5),boxShadow:"rgba(99, 99, 99, 0.2) 0px 2px 8px 0px"},p("itemNew",{prefix:"&"}),{backgroundColor:null===(r=a.new)||void 0===r?void 0:r.color}),p("itemDelete",{prefix:"&"}),{backgroundColor:null===(n=a.deleted)||void 0===n?void 0:n.color})),p("dragPanel"),{position:"absolute",borderRadius:l.shape.borderRadius,cursor:"pointer","& img":{width:"100%",height:"auto",borderRadius:4}}),p("dragPanel"),{position:"absolute",top:0,left:0,right:0,bottom:0,padding:l.spacing(.75),backgroundColor:l.palette.common.white,pointerEvents:"none",borderRadius:l.shape.borderRadius,display:"flex",opacity:0,zIndex:1,transition:"opacity 0.3s ease-in-out","& > div":{flex:1,display:"flex",alignItems:"center",justifyContent:"center",border:"2px dashed "+l.palette.primary.main,borderRadius:l.shape.borderRadius}}),t(t(t(d,p("dragging",{prefix:"&"}),t(t({},p("dragPanel"),{opacity:1}),p("content"),{pointerEvents:"none"})),p("overlay"),{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:i(l.palette.common.white,.5),zIndex:1,opacity:0,transition:"opacity 0.3s ease-in-out",visibility:"hidden",display:"flex",alignItems:"center",justifyContent:"center"}),p("loading",{prefix:"&"}),t({},p("overlay"),{opacity:1,visibility:"visible"}))}));export{s as AttachModalStyled,d as AttachWidgetStyled,l as attachModalClasses,r as attachWidgetClasses};
1
+ import{defineProperty as t}from"../../../_virtual/_rollupPluginBabelHelpers.js";import{styled as e,alpha as i,Box as o}from"@mui/material";import{mapItemConfigs as a}from"./helpers.js";var r={root:"AttachWidget-root",content:"AttachWidget-content",dragging:"AttachWidget-dragging",dragPanel:"AttachWidget-dragPanel",inputButton:"AttachWidget-inputButton",moreButton:"AttachWidget-moreButton",list:"AttachWidget-list",listItem:"AttachWidget-listItem",overlay:"AttachWidget-overlay",loading:"AttachWidget-loading"},n=function(t,e){return"".concat((null==e?void 0:e.prefix)||"",".").concat(r[t]).concat((null==e?void 0:e.suffix)||"")},d=e("div")(function(e){var o,a=e.theme;return t(t(t(t(t(t(t(t(t(t(o={},n("root",{prefix:"&"}),{position:"relative",width:"100%",height:"100%",backgroundColor:a.palette.common.white,borderRadius:a.shape.borderRadius}),n("content"),{width:"100%",height:"100%",display:"flex",alignItems:"center",justifyContent:"flex-start",padding:a.spacing(1)}),n("list"),{height:"100%",flex:1,display:"flex",alignItems:"center",gap:a.spacing(.75),overflow:"hidden",minWidth:0,position:"relative","&::after":{content:'""',height:"100%",width:"30px",position:"absolute",right:0,top:0,zIndex:1,background:"linear-gradient(to right, transparent, #ffffffb0, #ffffff)"}}),n("listItem"),{width:"var(--attach-widget-list-item-width, 42px)",padding:0,aspectRatio:"5 / 7",borderRadius:a.shape.borderRadius,border:"1px solid "+a.palette.divider,boxShadow:"rgba(99, 99, 99, 0.2) 0px 2px 8px 0px",img:{width:"100%",height:"100%",objectFit:"cover"}}),n("inputButton"),{width:"var(--attach-widget-list-item-width, 42px)",aspectRatio:"5 / 7",padding:0,cursor:"pointer",color:a.palette.primary.main,borderRadius:a.shape.borderRadius,border:"1px dashed "+a.palette.primary.main,marginRight:a.spacing(1),"&:hover":{color:a.palette.primary.dark}}),n("moreButton"),{opacity:.5,transition:"opacity 0.3s ease-in-out"}),n("dragPanel"),{position:"absolute",top:0,left:0,right:0,bottom:0,padding:a.spacing(.75),backgroundColor:a.palette.common.white,pointerEvents:"none",borderRadius:a.shape.borderRadius,display:"flex",opacity:0,zIndex:1,transition:"opacity 0.3s ease-in-out","& > div":{flex:1,display:"flex",alignItems:"center",justifyContent:"center",border:"2px dashed "+a.palette.primary.main,borderRadius:a.shape.borderRadius}}),n("overlay"),{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:i(a.palette.common.white,.5),zIndex:1,opacity:0,transition:"opacity 0.3s ease-in-out",visibility:"hidden",display:"flex",alignItems:"center",justifyContent:"center"}),n("loading",{prefix:"&"}),t({},n("overlay"),{opacity:1,visibility:"visible"})),n("dragging",{prefix:"&"}),t(t({},n("dragPanel"),{opacity:1}),n("content"),{pointerEvents:"none"})),t(o,n("root",{prefix:"&",suffix:":hover"}),t({},n("moreButton"),{opacity:1}))}),l={root:"AttachModal-root",header:"AttachModal-header",footer:"AttachModal-footer",loading:"AttachModal-loading",overlay:"AttachModal-overlay",dragging:"AttachModal-dragging",dragPanel:"AttachModal-dragPanel",content:"AttachModal-content",emptyState:"AttachModal-emptyState",closeButton:"AttachModal-closeButton",item:"AttachModal-item",itemHeader:"AttachModal-itemHeader",itemContent:"AttachModal-itemContent",itemNew:"AttachModal-itemNew",itemDelete:"AttachModal-itemDelete"},p=function(t,e){return"".concat((null==e?void 0:e.prefix)||"",".").concat(l[t]).concat((null==e?void 0:e.suffix)||"")},s=e(o)(function(e){var o,r,n,d,l=e.theme;return t(t(t(t(t(t(t(t(t(t(d={},p("root",{prefix:"&"}),{backgroundColor:l.palette.background.paper,borderRadius:l.shape.borderRadius,boxShadow:l.shadows[5],width:"calc(100vw - 48px)",maxHeight:"calc(100vh - 48px)",maxWidth:l.breakpoints.values.md,position:"relative",display:"flex",flexDirection:"column"}),p("header"),{display:"flex",justifyContent:"space-between",alignItems:"center",padding:l.spacing(1,2)}),p("footer"),{padding:l.spacing(1,2),display:"flex",alignItems:"center",gap:l.spacing(3)}),p("content"),{minHeight:"200px",padding:l.spacing(1),overflowY:"auto",height:"100%"}),p("emptyState"),{display:"flex",alignItems:"center",justifyContent:"center",height:"168px"}),p("itemContent"),{width:"100%",height:"100%",padding:0,borderRadius:l.shape.borderRadius,cursor:"pointer",backgroundColor:l.palette.background.paper,img:{width:"100%",height:"100%",objectFit:"cover"}}),p("itemHeader"),{marginTop:l.spacing(-.5),padding:l.spacing(.5,0),display:"flex",alignItems:"center",justifyContent:"space-between",".MuiTypography-root":{color:l.palette.common.white},".MuiIconButton-root":{backgroundColor:i(l.palette.common.white,.5),".MuiSvgIcon-root":{fontSize:"1rem"},"&:hover":{backgroundColor:l.palette.common.white}}}),p("item"),t(t({width:"var(--attach-modal-list-item-width, 100%)",aspectRatio:"5 / 7",display:"inline-block",position:"relative",backgroundColor:null===(o=a.old)||void 0===o?void 0:o.color,borderRadius:l.shape.borderRadius,padding:l.spacing(.5),boxShadow:"rgba(99, 99, 99, 0.2) 0px 2px 8px 0px"},p("itemNew",{prefix:"&"}),{backgroundColor:null===(r=a.new)||void 0===r?void 0:r.color}),p("itemDelete",{prefix:"&"}),{backgroundColor:null===(n=a.deleted)||void 0===n?void 0:n.color})),p("dragPanel"),{position:"absolute",borderRadius:l.shape.borderRadius,cursor:"pointer","& img":{width:"100%",height:"auto",borderRadius:4}}),p("dragPanel"),{position:"absolute",top:0,left:0,right:0,bottom:0,padding:l.spacing(.75),backgroundColor:l.palette.common.white,pointerEvents:"none",borderRadius:l.shape.borderRadius,display:"flex",opacity:0,zIndex:1,transition:"opacity 0.3s ease-in-out","& > div":{flex:1,display:"flex",alignItems:"center",justifyContent:"center",border:"2px dashed "+l.palette.primary.main,borderRadius:l.shape.borderRadius}}),t(t(t(d,p("dragging",{prefix:"&"}),t(t({},p("dragPanel"),{opacity:1}),p("content"),{pointerEvents:"none"})),p("overlay"),{position:"absolute",top:0,left:0,right:0,bottom:0,backgroundColor:i(l.palette.common.white,.5),zIndex:1,opacity:0,transition:"opacity 0.3s ease-in-out",visibility:"hidden",display:"flex",alignItems:"center",justifyContent:"center"}),p("loading",{prefix:"&"}),t({},p("overlay"),{opacity:1,visibility:"visible"}))});export{s as AttachModalStyled,d as AttachWidgetStyled,l as attachModalClasses,r as attachWidgetClasses};
2
2
  //# sourceMappingURL=styled.js.map