@fctc/widget-logic 2.3.6 → 2.3.7

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.
package/dist/utils.d.mts CHANGED
@@ -1,4 +1,3 @@
1
- import * as react from 'react';
2
1
  export * from '@fctc/interface-logic/utils';
3
2
 
4
3
  declare const languages: {
@@ -16,18 +15,6 @@ declare const API_APP_URL: {
16
15
 
17
16
  declare const countSum: (data: any[], field: string) => number;
18
17
  declare function mergeButtons(fields: any): any;
19
- declare function useGetRowIds(tableRef: React.RefObject<HTMLTableElement | null>): {
20
- rowIds: string[];
21
- refresh: () => void;
22
- };
23
- declare const useSelectionState: ({ typeTable, tableRef, rows, }: {
24
- typeTable?: string;
25
- tableRef: any;
26
- rows?: any[];
27
- }) => {
28
- checkedAll: boolean;
29
- selectedRowKeysRef: react.MutableRefObject<any[]>;
30
- };
31
18
  declare const getDateRange: (currentDate: any, unit: string) => string[][];
32
19
  declare const convertFieldsToArray: (fields: any[] | undefined | null) => any[];
33
20
  declare function combineContexts(contexts: ({
@@ -44,4 +31,4 @@ type StorageKey = keyof typeof STORAGES;
44
31
  declare function setStorageItemAsync(key: StorageKey, value: string | null): Promise<void>;
45
32
  declare function useStorageState(key: StorageKey): UseStateHook<string>;
46
33
 
47
- export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useGetRowIds, useSelectionState, useStorageState };
34
+ export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useStorageState };
package/dist/utils.d.ts CHANGED
@@ -1,4 +1,3 @@
1
- import * as react from 'react';
2
1
  export * from '@fctc/interface-logic/utils';
3
2
 
4
3
  declare const languages: {
@@ -16,18 +15,6 @@ declare const API_APP_URL: {
16
15
 
17
16
  declare const countSum: (data: any[], field: string) => number;
18
17
  declare function mergeButtons(fields: any): any;
19
- declare function useGetRowIds(tableRef: React.RefObject<HTMLTableElement | null>): {
20
- rowIds: string[];
21
- refresh: () => void;
22
- };
23
- declare const useSelectionState: ({ typeTable, tableRef, rows, }: {
24
- typeTable?: string;
25
- tableRef: any;
26
- rows?: any[];
27
- }) => {
28
- checkedAll: boolean;
29
- selectedRowKeysRef: react.MutableRefObject<any[]>;
30
- };
31
18
  declare const getDateRange: (currentDate: any, unit: string) => string[][];
32
19
  declare const convertFieldsToArray: (fields: any[] | undefined | null) => any[];
33
20
  declare function combineContexts(contexts: ({
@@ -44,4 +31,4 @@ type StorageKey = keyof typeof STORAGES;
44
31
  declare function setStorageItemAsync(key: StorageKey, value: string | null): Promise<void>;
45
32
  declare function useStorageState(key: StorageKey): UseStateHook<string>;
46
33
 
47
- export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useGetRowIds, useSelectionState, useStorageState };
34
+ export { API_APP_URL, API_PRESCHOOL_URL, STORAGES, combineContexts, convertFieldsToArray, countSum, getDateRange, languages, mergeButtons, setStorageItemAsync, useStorageState };
package/dist/utils.js CHANGED
@@ -31,8 +31,6 @@ __export(utils_exports, {
31
31
  languages: () => languages,
32
32
  mergeButtons: () => mergeButtons,
33
33
  setStorageItemAsync: () => setStorageItemAsync,
34
- useGetRowIds: () => useGetRowIds,
35
- useSelectionState: () => useSelectionState,
36
34
  useStorageState: () => useStorageState
37
35
  });
38
36
  module.exports = __toCommonJS(utils_exports);
@@ -53,12 +51,6 @@ var API_APP_URL = {
53
51
 
54
52
  // src/utils/function.ts
55
53
  var import_react = require("react");
56
-
57
- // src/store.ts
58
- var store_exports = {};
59
- __reExport(store_exports, require("@fctc/interface-logic/store"));
60
-
61
- // src/utils/function.ts
62
54
  var countSum = (data, field) => {
63
55
  if (!data || !field) return 0;
64
56
  return data.reduce(
@@ -77,91 +69,6 @@ function mergeButtons(fields) {
77
69
  }
78
70
  return others;
79
71
  }
80
- function isElementVisible(el) {
81
- const style = window.getComputedStyle(el);
82
- return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
83
- }
84
- function arraysAreEqual(a, b) {
85
- if (a.length !== b.length) return false;
86
- const setA = new Set(a);
87
- const setB = new Set(b);
88
- if (setA.size !== setB.size) return false;
89
- for (const val of setA) {
90
- if (!setB.has(val)) return false;
91
- }
92
- return true;
93
- }
94
- function useGetRowIds(tableRef) {
95
- const [rowIds, setRowIds] = (0, import_react.useState)([]);
96
- const lastRowIdsRef = (0, import_react.useRef)([]);
97
- const updateVisibleRowIds = (0, import_react.useCallback)(() => {
98
- const table = tableRef?.current;
99
- if (!table) return;
100
- const rows = table.querySelectorAll("tr[data-row-id]");
101
- const ids = [];
102
- rows.forEach((row) => {
103
- const el = row;
104
- if (isElementVisible(el)) {
105
- const id = el.getAttribute("data-row-id");
106
- if (id) ids.push(id);
107
- }
108
- });
109
- const uniqueIds = Array.from(new Set(ids));
110
- if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
111
- lastRowIdsRef.current = uniqueIds;
112
- setRowIds(uniqueIds);
113
- }
114
- }, [tableRef]);
115
- (0, import_react.useEffect)(() => {
116
- const table = tableRef?.current;
117
- if (!table) return;
118
- const observer = new MutationObserver(() => {
119
- updateVisibleRowIds();
120
- });
121
- observer.observe(table, {
122
- childList: true,
123
- subtree: true,
124
- attributes: true,
125
- attributeFilter: ["style", "class"]
126
- });
127
- updateVisibleRowIds();
128
- return () => {
129
- observer.disconnect();
130
- };
131
- }, [updateVisibleRowIds, tableRef]);
132
- return { rowIds, refresh: updateVisibleRowIds };
133
- }
134
- var useSelectionState = ({
135
- typeTable,
136
- tableRef,
137
- rows
138
- }) => {
139
- const { groupByDomain } = (0, store_exports.useAppSelector)(store_exports.selectSearch);
140
- const { selectedRowKeys } = (0, store_exports.useAppSelector)(store_exports.selectList);
141
- const { rowIds: recordIds } = useGetRowIds(tableRef);
142
- const selectedRowKeysRef = (0, import_react.useRef)(recordIds);
143
- const isGroupTable = typeTable === "group";
144
- const recordsCheckedGroup = (0, import_react.useMemo)(() => {
145
- if (!rows || !groupByDomain) return 0;
146
- const groupBy = typeof groupByDomain === "object" ? groupByDomain?.contexts?.[0]?.group_by : void 0;
147
- return countSum(rows, groupBy);
148
- }, [rows, groupByDomain]);
149
- const isAllGroupChecked = (0, import_react.useMemo)(() => {
150
- if (!isGroupTable || !selectedRowKeys?.length) return false;
151
- const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
152
- const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
153
- const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
154
- return allGroupsSelected || allRecordsSelected;
155
- }, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
156
- const isAllNormalChecked = (0, import_react.useMemo)(() => {
157
- if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
158
- return selectedRowKeys.length === rows.length && selectedRowKeys.every(
159
- (id) => rows.some((record) => record.id === id)
160
- );
161
- }, [isGroupTable, selectedRowKeys, rows]);
162
- const checkedAll = isAllGroupChecked || isAllNormalChecked;
163
- return { checkedAll, selectedRowKeysRef };
164
- };
165
72
  var getDateRange = (currentDate, unit) => {
166
73
  const date = new Date(currentDate);
167
74
  let dateStart, dateEnd;
@@ -314,8 +221,6 @@ __reExport(utils_exports, require("@fctc/interface-logic/utils"), module.exports
314
221
  languages,
315
222
  mergeButtons,
316
223
  setStorageItemAsync,
317
- useGetRowIds,
318
- useSelectionState,
319
224
  useStorageState,
320
225
  ...require("@fctc/interface-logic/utils")
321
226
  });
package/dist/utils.mjs CHANGED
@@ -1,17 +1,3 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __copyProps = (to, from, except, desc) => {
6
- if (from && typeof from === "object" || typeof from === "function") {
7
- for (let key of __getOwnPropNames(from))
8
- if (!__hasOwnProp.call(to, key) && key !== except)
9
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
- }
11
- return to;
12
- };
13
- var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
-
15
1
  // src/utils/constants.ts
16
2
  var languages = [
17
3
  { id: "vi_VN", name: "VIE" },
@@ -27,21 +13,7 @@ var API_APP_URL = {
27
13
  };
28
14
 
29
15
  // src/utils/function.ts
30
- import {
31
- useCallback,
32
- useEffect,
33
- useMemo,
34
- useReducer,
35
- useRef,
36
- useState
37
- } from "react";
38
-
39
- // src/store.ts
40
- var store_exports = {};
41
- __reExport(store_exports, store_star);
42
- import * as store_star from "@fctc/interface-logic/store";
43
-
44
- // src/utils/function.ts
16
+ import { useCallback, useEffect, useReducer } from "react";
45
17
  var countSum = (data, field) => {
46
18
  if (!data || !field) return 0;
47
19
  return data.reduce(
@@ -60,91 +32,6 @@ function mergeButtons(fields) {
60
32
  }
61
33
  return others;
62
34
  }
63
- function isElementVisible(el) {
64
- const style = window.getComputedStyle(el);
65
- return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
66
- }
67
- function arraysAreEqual(a, b) {
68
- if (a.length !== b.length) return false;
69
- const setA = new Set(a);
70
- const setB = new Set(b);
71
- if (setA.size !== setB.size) return false;
72
- for (const val of setA) {
73
- if (!setB.has(val)) return false;
74
- }
75
- return true;
76
- }
77
- function useGetRowIds(tableRef) {
78
- const [rowIds, setRowIds] = useState([]);
79
- const lastRowIdsRef = useRef([]);
80
- const updateVisibleRowIds = useCallback(() => {
81
- const table = tableRef?.current;
82
- if (!table) return;
83
- const rows = table.querySelectorAll("tr[data-row-id]");
84
- const ids = [];
85
- rows.forEach((row) => {
86
- const el = row;
87
- if (isElementVisible(el)) {
88
- const id = el.getAttribute("data-row-id");
89
- if (id) ids.push(id);
90
- }
91
- });
92
- const uniqueIds = Array.from(new Set(ids));
93
- if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
94
- lastRowIdsRef.current = uniqueIds;
95
- setRowIds(uniqueIds);
96
- }
97
- }, [tableRef]);
98
- useEffect(() => {
99
- const table = tableRef?.current;
100
- if (!table) return;
101
- const observer = new MutationObserver(() => {
102
- updateVisibleRowIds();
103
- });
104
- observer.observe(table, {
105
- childList: true,
106
- subtree: true,
107
- attributes: true,
108
- attributeFilter: ["style", "class"]
109
- });
110
- updateVisibleRowIds();
111
- return () => {
112
- observer.disconnect();
113
- };
114
- }, [updateVisibleRowIds, tableRef]);
115
- return { rowIds, refresh: updateVisibleRowIds };
116
- }
117
- var useSelectionState = ({
118
- typeTable,
119
- tableRef,
120
- rows
121
- }) => {
122
- const { groupByDomain } = (0, store_exports.useAppSelector)(store_exports.selectSearch);
123
- const { selectedRowKeys } = (0, store_exports.useAppSelector)(store_exports.selectList);
124
- const { rowIds: recordIds } = useGetRowIds(tableRef);
125
- const selectedRowKeysRef = useRef(recordIds);
126
- const isGroupTable = typeTable === "group";
127
- const recordsCheckedGroup = useMemo(() => {
128
- if (!rows || !groupByDomain) return 0;
129
- const groupBy = typeof groupByDomain === "object" ? groupByDomain?.contexts?.[0]?.group_by : void 0;
130
- return countSum(rows, groupBy);
131
- }, [rows, groupByDomain]);
132
- const isAllGroupChecked = useMemo(() => {
133
- if (!isGroupTable || !selectedRowKeys?.length) return false;
134
- const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
135
- const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
136
- const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
137
- return allGroupsSelected || allRecordsSelected;
138
- }, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
139
- const isAllNormalChecked = useMemo(() => {
140
- if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
141
- return selectedRowKeys.length === rows.length && selectedRowKeys.every(
142
- (id) => rows.some((record) => record.id === id)
143
- );
144
- }, [isGroupTable, selectedRowKeys, rows]);
145
- const checkedAll = isAllGroupChecked || isAllNormalChecked;
146
- return { checkedAll, selectedRowKeysRef };
147
- };
148
35
  var getDateRange = (currentDate, unit) => {
149
36
  const date = new Date(currentDate);
150
37
  let dateStart, dateEnd;
@@ -296,7 +183,5 @@ export {
296
183
  languages,
297
184
  mergeButtons,
298
185
  setStorageItemAsync,
299
- useGetRowIds,
300
- useSelectionState,
301
186
  useStorageState
302
187
  };
package/dist/widget.d.mts CHANGED
@@ -72,10 +72,10 @@ declare const many2manyFieldController: (props: IMany2ManyControllerProps) => {
72
72
  handleCreateNewOnPage: () => Promise<void>;
73
73
  optionsObject: any;
74
74
  totalRows: any;
75
- rows: any[];
75
+ rows: any;
76
76
  columns: any;
77
77
  onToggleColumnOptional: (item: any) => void;
78
- typeTable: "list" | "group" | "calendar" | undefined;
78
+ typeTable: "list" | "calendar" | "group" | undefined;
79
79
  isLoading: boolean;
80
80
  isFetched: boolean;
81
81
  isPlaceholderData: boolean;
@@ -203,11 +203,15 @@ declare const binaryFieldController: (props: IInputFieldProps) => {
203
203
  interface ITableHeadProps {
204
204
  typeTable: string;
205
205
  rows: any[];
206
- selectedRowKeysRef: any;
206
+ tableRef: React.RefObject<HTMLTableElement | null>;
207
+ groupByList: any;
208
+ selectedRowKeys: any;
207
209
  }
208
210
 
209
211
  declare const tableHeadController: (props: ITableHeadProps) => {
210
212
  handleCheckBoxAll: (event: React.ChangeEvent<HTMLInputElement>) => void;
213
+ checkedAll: any;
214
+ selectedRowKeysRef: react.MutableRefObject<any[]>;
211
215
  };
212
216
 
213
217
  interface ITableProps {
@@ -231,45 +235,28 @@ interface ISelctionStateProps {
231
235
  }
232
236
 
233
237
  declare const tableController: ({ data }: ITableProps) => {
234
- rows: any[];
238
+ rows: any;
235
239
  columns: any;
236
240
  onToggleColumnOptional: (item: any) => void;
237
- typeTable: "list" | "group" | "calendar" | undefined;
241
+ typeTable: "list" | "calendar" | "group" | undefined;
238
242
  };
239
243
 
240
244
  declare const tableGroupController: (props: any) => {
241
- handleExpandChildGroup: () => void;
245
+ onExpandChildGroup: () => void;
242
246
  colEmptyGroup: {
243
247
  fromStart: number;
244
248
  fromEnd: number;
245
249
  };
246
- leftPadding: string;
247
250
  isShowGroup: boolean;
248
- isQueryFetched: boolean;
251
+ isDataGroupFetched: boolean;
252
+ isDataPlaceHolder: boolean;
249
253
  nameGroupWithCount: string;
250
- columns: any;
251
- row: any;
252
- isPlaceholderData: boolean;
253
254
  columnsGroup: any;
254
- indexRow: any;
255
- rowsGroup: any[];
256
- model: any;
257
- viewData: any;
258
- renderField: any;
259
- level: any;
260
- specification: any;
261
- context: any;
262
- checkedAll: any;
263
- isDisplayCheckbox: any;
264
- isAutoSelect: any;
265
- setIsAutoSelect: any;
266
- selectedRowKeysRef: any;
267
- initVal: {
268
- [x: string]: any;
269
- };
270
- dataResponse: any;
255
+ rowsGroup: any;
256
+ dataGroup: any;
271
257
  pageGroup: any;
272
258
  setPageGroup: react.Dispatch<any>;
259
+ typeTableGroup: "list" | "calendar" | "group" | undefined;
273
260
  };
274
261
 
275
262
  declare const searchController: ({ viewData, model, domain, context, fieldsList, }: {
package/dist/widget.d.ts CHANGED
@@ -72,10 +72,10 @@ declare const many2manyFieldController: (props: IMany2ManyControllerProps) => {
72
72
  handleCreateNewOnPage: () => Promise<void>;
73
73
  optionsObject: any;
74
74
  totalRows: any;
75
- rows: any[];
75
+ rows: any;
76
76
  columns: any;
77
77
  onToggleColumnOptional: (item: any) => void;
78
- typeTable: "list" | "group" | "calendar" | undefined;
78
+ typeTable: "list" | "calendar" | "group" | undefined;
79
79
  isLoading: boolean;
80
80
  isFetched: boolean;
81
81
  isPlaceholderData: boolean;
@@ -203,11 +203,15 @@ declare const binaryFieldController: (props: IInputFieldProps) => {
203
203
  interface ITableHeadProps {
204
204
  typeTable: string;
205
205
  rows: any[];
206
- selectedRowKeysRef: any;
206
+ tableRef: React.RefObject<HTMLTableElement | null>;
207
+ groupByList: any;
208
+ selectedRowKeys: any;
207
209
  }
208
210
 
209
211
  declare const tableHeadController: (props: ITableHeadProps) => {
210
212
  handleCheckBoxAll: (event: React.ChangeEvent<HTMLInputElement>) => void;
213
+ checkedAll: any;
214
+ selectedRowKeysRef: react.MutableRefObject<any[]>;
211
215
  };
212
216
 
213
217
  interface ITableProps {
@@ -231,45 +235,28 @@ interface ISelctionStateProps {
231
235
  }
232
236
 
233
237
  declare const tableController: ({ data }: ITableProps) => {
234
- rows: any[];
238
+ rows: any;
235
239
  columns: any;
236
240
  onToggleColumnOptional: (item: any) => void;
237
- typeTable: "list" | "group" | "calendar" | undefined;
241
+ typeTable: "list" | "calendar" | "group" | undefined;
238
242
  };
239
243
 
240
244
  declare const tableGroupController: (props: any) => {
241
- handleExpandChildGroup: () => void;
245
+ onExpandChildGroup: () => void;
242
246
  colEmptyGroup: {
243
247
  fromStart: number;
244
248
  fromEnd: number;
245
249
  };
246
- leftPadding: string;
247
250
  isShowGroup: boolean;
248
- isQueryFetched: boolean;
251
+ isDataGroupFetched: boolean;
252
+ isDataPlaceHolder: boolean;
249
253
  nameGroupWithCount: string;
250
- columns: any;
251
- row: any;
252
- isPlaceholderData: boolean;
253
254
  columnsGroup: any;
254
- indexRow: any;
255
- rowsGroup: any[];
256
- model: any;
257
- viewData: any;
258
- renderField: any;
259
- level: any;
260
- specification: any;
261
- context: any;
262
- checkedAll: any;
263
- isDisplayCheckbox: any;
264
- isAutoSelect: any;
265
- setIsAutoSelect: any;
266
- selectedRowKeysRef: any;
267
- initVal: {
268
- [x: string]: any;
269
- };
270
- dataResponse: any;
255
+ rowsGroup: any;
256
+ dataGroup: any;
271
257
  pageGroup: any;
272
258
  setPageGroup: react.Dispatch<any>;
259
+ typeTableGroup: "list" | "calendar" | "group" | undefined;
273
260
  };
274
261
 
275
262
  declare const searchController: ({ viewData, model, domain, context, fieldsList, }: {