@fctc/widget-logic 1.10.1 → 1.10.2

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/hooks.js CHANGED
@@ -162,109 +162,6 @@ var store_exports = {};
162
162
  __reExport(store_exports, require("@fctc/interface-logic/store"));
163
163
 
164
164
  // src/utils/function.ts
165
- var countSum = (data, field) => {
166
- if (!data || !field) return 0;
167
- return data.reduce(
168
- (total, item) => total + (item?.[`${field}_count`] || 0),
169
- 0
170
- );
171
- };
172
- function mergeButtons(fields) {
173
- const buttons = fields?.filter((f) => f.type_co === "button");
174
- const others = fields?.filter((f) => f.type_co !== "button");
175
- if (buttons?.length) {
176
- others.push({
177
- type_co: "buttons",
178
- buttons
179
- });
180
- }
181
- return others;
182
- }
183
- function isElementVisible(el) {
184
- const style = window.getComputedStyle(el);
185
- return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
186
- }
187
- function arraysAreEqual(a, b) {
188
- if (a.length !== b.length) return false;
189
- const setA = new Set(a);
190
- const setB = new Set(b);
191
- if (setA.size !== setB.size) return false;
192
- for (const val of setA) {
193
- if (!setB.has(val)) return false;
194
- }
195
- return true;
196
- }
197
- function useGetRowIds(tableRef) {
198
- const [rowIds, setRowIds] = (0, import_react4.useState)([]);
199
- const lastRowIdsRef = (0, import_react4.useRef)([]);
200
- const updateVisibleRowIds = (0, import_react4.useCallback)(() => {
201
- const table = tableRef?.current;
202
- if (!table) return;
203
- const rows = table.querySelectorAll("tr[data-row-id]");
204
- const ids = [];
205
- rows.forEach((row) => {
206
- const el = row;
207
- if (isElementVisible(el)) {
208
- const id = el.getAttribute("data-row-id");
209
- if (id) ids.push(id);
210
- }
211
- });
212
- const uniqueIds = Array.from(new Set(ids));
213
- if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
214
- lastRowIdsRef.current = uniqueIds;
215
- setRowIds(uniqueIds);
216
- }
217
- }, [tableRef]);
218
- (0, import_react4.useEffect)(() => {
219
- const table = tableRef?.current;
220
- if (!table) return;
221
- const observer = new MutationObserver(() => {
222
- updateVisibleRowIds();
223
- });
224
- observer.observe(table, {
225
- childList: true,
226
- subtree: true,
227
- attributes: true,
228
- attributeFilter: ["style", "class"]
229
- });
230
- updateVisibleRowIds();
231
- return () => {
232
- observer.disconnect();
233
- };
234
- }, [updateVisibleRowIds, tableRef]);
235
- return { rowIds, refresh: updateVisibleRowIds };
236
- }
237
- var useSelectionState = ({
238
- typeTable,
239
- tableRef,
240
- rows
241
- }) => {
242
- const { groupByDomain } = (0, store_exports.useAppSelector)(store_exports.selectSearch);
243
- const { selectedRowKeys } = (0, store_exports.useAppSelector)(store_exports.selectList);
244
- const { rowIds: recordIds } = useGetRowIds(tableRef);
245
- const selectedRowKeysRef = (0, import_react4.useRef)(recordIds);
246
- const isGroupTable = typeTable === "group";
247
- const recordsCheckedGroup = (0, import_react4.useMemo)(() => {
248
- if (!rows || !groupByDomain) return 0;
249
- const groupBy = typeof groupByDomain === "object" ? groupByDomain?.contexts?.[0]?.group_by : void 0;
250
- return countSum(rows, groupBy);
251
- }, [rows, groupByDomain]);
252
- const isAllGroupChecked = (0, import_react4.useMemo)(() => {
253
- if (!isGroupTable || !selectedRowKeys?.length) return false;
254
- const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
255
- const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
256
- const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
257
- return allGroupsSelected || allRecordsSelected;
258
- }, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
259
- const isAllNormalChecked = (0, import_react4.useMemo)(() => {
260
- if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
261
- return selectedRowKeys.length === rows.length && selectedRowKeys.every(
262
- (id) => rows.some((record) => record.id === id)
263
- );
264
- }, [isGroupTable, selectedRowKeys, rows]);
265
- const checkedAll = isAllGroupChecked || isAllNormalChecked;
266
- return { checkedAll, selectedRowKeysRef };
267
- };
268
165
  var getDateRange = (currentDate, unit) => {
269
166
  const date = new Date(currentDate);
270
167
  let dateStart, dateEnd;
@@ -362,10 +259,6 @@ function combineContexts(contexts) {
362
259
  return res;
363
260
  }
364
261
  }
365
- var STORAGES = {
366
- TOKEN: "accessToken",
367
- USER_INFO: "USER_INFO"
368
- };
369
262
  function useAsyncState(initialValue = [true, null]) {
370
263
  return (0, import_react4.useReducer)(
371
264
  (_state, action = null) => [false, action],
@@ -486,9 +379,6 @@ var languages = [
486
379
  { id: "vi_VN", name: "VIE" },
487
380
  { id: "en_US", name: "ENG" }
488
381
  ];
489
- var API_PRESCHOOL_URL = {
490
- baseURL: "https://preschool.vitrust.app"
491
- };
492
382
  var API_APP_URL = {
493
383
  baseUrl: "https://api.vitrust.app",
494
384
  c2: "https://api.vitrust.app/c2",
@@ -791,32 +681,8 @@ var useAppProvider = () => {
791
681
  return context;
792
682
  };
793
683
 
794
- // src/hooks/core/use-menu-item.tsx
795
- var import_environment5 = require("@fctc/interface-logic/environment");
796
- var import_hooks9 = require("@fctc/interface-logic/hooks");
797
- var import_react11 = require("react");
798
-
799
- // src/utils.ts
800
- var utils_exports = {};
801
- __export(utils_exports, {
802
- API_APP_URL: () => API_APP_URL,
803
- API_PRESCHOOL_URL: () => API_PRESCHOOL_URL,
804
- STORAGES: () => STORAGES,
805
- combineContexts: () => combineContexts,
806
- convertFieldsToArray: () => convertFieldsToArray,
807
- countSum: () => countSum,
808
- getDateRange: () => getDateRange,
809
- languages: () => languages,
810
- mergeButtons: () => mergeButtons,
811
- setStorageItemAsync: () => setStorageItemAsync,
812
- useGetRowIds: () => useGetRowIds,
813
- useSelectionState: () => useSelectionState,
814
- useStorageState: () => useStorageState
815
- });
816
- __reExport(utils_exports, require("@fctc/interface-logic/utils"));
817
-
818
684
  // src/hooks/utils/use-click-outside.ts
819
- var import_react12 = require("react");
685
+ var import_react11 = require("react");
820
686
  var DEFAULT_EVENTS = ["mousedown", "touchstart"];
821
687
  var useClickOutside = ({
822
688
  handler,
@@ -824,8 +690,8 @@ var useClickOutside = ({
824
690
  nodes = [],
825
691
  refs
826
692
  }) => {
827
- const ref = (0, import_react12.useRef)(null);
828
- (0, import_react12.useEffect)(() => {
693
+ const ref = (0, import_react11.useRef)(null);
694
+ (0, import_react11.useEffect)(() => {
829
695
  const listener = (event) => {
830
696
  const { target } = event;
831
697
  if (refs && refs?.length > 0 && refs?.some((r) => r.current?.contains(target))) {
@@ -847,10 +713,10 @@ var useClickOutside = ({
847
713
  };
848
714
 
849
715
  // src/hooks/utils/use-debounce.ts
850
- var import_react13 = require("react");
716
+ var import_react12 = require("react");
851
717
  function useDebounce(value, delay) {
852
- const [debouncedValue, setDebouncedValue] = (0, import_react13.useState)(value);
853
- (0, import_react13.useEffect)(() => {
718
+ const [debouncedValue, setDebouncedValue] = (0, import_react12.useState)(value);
719
+ (0, import_react12.useEffect)(() => {
854
720
  const handler = setTimeout(() => {
855
721
  setDebouncedValue(value);
856
722
  }, delay);
package/dist/hooks.mjs CHANGED
@@ -2,10 +2,6 @@ var __defProp = Object.defineProperty;
2
2
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
3
  var __getOwnPropNames = Object.getOwnPropertyNames;
4
4
  var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
5
  var __copyProps = (to, from, except, desc) => {
10
6
  if (from && typeof from === "object" || typeof from === "function") {
11
7
  for (let key of __getOwnPropNames(from))
@@ -149,109 +145,6 @@ __reExport(store_exports, store_star);
149
145
  import * as store_star from "@fctc/interface-logic/store";
150
146
 
151
147
  // src/utils/function.ts
152
- var countSum = (data, field) => {
153
- if (!data || !field) return 0;
154
- return data.reduce(
155
- (total, item) => total + (item?.[`${field}_count`] || 0),
156
- 0
157
- );
158
- };
159
- function mergeButtons(fields) {
160
- const buttons = fields?.filter((f) => f.type_co === "button");
161
- const others = fields?.filter((f) => f.type_co !== "button");
162
- if (buttons?.length) {
163
- others.push({
164
- type_co: "buttons",
165
- buttons
166
- });
167
- }
168
- return others;
169
- }
170
- function isElementVisible(el) {
171
- const style = window.getComputedStyle(el);
172
- return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
173
- }
174
- function arraysAreEqual(a, b) {
175
- if (a.length !== b.length) return false;
176
- const setA = new Set(a);
177
- const setB = new Set(b);
178
- if (setA.size !== setB.size) return false;
179
- for (const val of setA) {
180
- if (!setB.has(val)) return false;
181
- }
182
- return true;
183
- }
184
- function useGetRowIds(tableRef) {
185
- const [rowIds, setRowIds] = useState2([]);
186
- const lastRowIdsRef = useRef([]);
187
- const updateVisibleRowIds = useCallback(() => {
188
- const table = tableRef?.current;
189
- if (!table) return;
190
- const rows = table.querySelectorAll("tr[data-row-id]");
191
- const ids = [];
192
- rows.forEach((row) => {
193
- const el = row;
194
- if (isElementVisible(el)) {
195
- const id = el.getAttribute("data-row-id");
196
- if (id) ids.push(id);
197
- }
198
- });
199
- const uniqueIds = Array.from(new Set(ids));
200
- if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
201
- lastRowIdsRef.current = uniqueIds;
202
- setRowIds(uniqueIds);
203
- }
204
- }, [tableRef]);
205
- useEffect3(() => {
206
- const table = tableRef?.current;
207
- if (!table) return;
208
- const observer = new MutationObserver(() => {
209
- updateVisibleRowIds();
210
- });
211
- observer.observe(table, {
212
- childList: true,
213
- subtree: true,
214
- attributes: true,
215
- attributeFilter: ["style", "class"]
216
- });
217
- updateVisibleRowIds();
218
- return () => {
219
- observer.disconnect();
220
- };
221
- }, [updateVisibleRowIds, tableRef]);
222
- return { rowIds, refresh: updateVisibleRowIds };
223
- }
224
- var useSelectionState = ({
225
- typeTable,
226
- tableRef,
227
- rows
228
- }) => {
229
- const { groupByDomain } = (0, store_exports.useAppSelector)(store_exports.selectSearch);
230
- const { selectedRowKeys } = (0, store_exports.useAppSelector)(store_exports.selectList);
231
- const { rowIds: recordIds } = useGetRowIds(tableRef);
232
- const selectedRowKeysRef = useRef(recordIds);
233
- const isGroupTable = typeTable === "group";
234
- const recordsCheckedGroup = useMemo2(() => {
235
- if (!rows || !groupByDomain) return 0;
236
- const groupBy = typeof groupByDomain === "object" ? groupByDomain?.contexts?.[0]?.group_by : void 0;
237
- return countSum(rows, groupBy);
238
- }, [rows, groupByDomain]);
239
- const isAllGroupChecked = useMemo2(() => {
240
- if (!isGroupTable || !selectedRowKeys?.length) return false;
241
- const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
242
- const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
243
- const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
244
- return allGroupsSelected || allRecordsSelected;
245
- }, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
246
- const isAllNormalChecked = useMemo2(() => {
247
- if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
248
- return selectedRowKeys.length === rows.length && selectedRowKeys.every(
249
- (id) => rows.some((record) => record.id === id)
250
- );
251
- }, [isGroupTable, selectedRowKeys, rows]);
252
- const checkedAll = isAllGroupChecked || isAllNormalChecked;
253
- return { checkedAll, selectedRowKeysRef };
254
- };
255
148
  var getDateRange = (currentDate, unit) => {
256
149
  const date = new Date(currentDate);
257
150
  let dateStart, dateEnd;
@@ -349,10 +242,6 @@ function combineContexts(contexts) {
349
242
  return res;
350
243
  }
351
244
  }
352
- var STORAGES = {
353
- TOKEN: "accessToken",
354
- USER_INFO: "USER_INFO"
355
- };
356
245
  function useAsyncState(initialValue = [true, null]) {
357
246
  return useReducer(
358
247
  (_state, action = null) => [false, action],
@@ -480,9 +369,6 @@ var languages = [
480
369
  { id: "vi_VN", name: "VIE" },
481
370
  { id: "en_US", name: "ENG" }
482
371
  ];
483
- var API_PRESCHOOL_URL = {
484
- baseURL: "https://preschool.vitrust.app"
485
- };
486
372
  var API_APP_URL = {
487
373
  baseUrl: "https://api.vitrust.app",
488
374
  c2: "https://api.vitrust.app/c2",
@@ -793,31 +679,6 @@ var useAppProvider = () => {
793
679
  return context;
794
680
  };
795
681
 
796
- // src/hooks/core/use-menu-item.tsx
797
- import { getEnv as getEnv5 } from "@fctc/interface-logic/environment";
798
- import { useGetActionDetail } from "@fctc/interface-logic/hooks";
799
- import { useState as useState5 } from "react";
800
-
801
- // src/utils.ts
802
- var utils_exports = {};
803
- __export(utils_exports, {
804
- API_APP_URL: () => API_APP_URL,
805
- API_PRESCHOOL_URL: () => API_PRESCHOOL_URL,
806
- STORAGES: () => STORAGES,
807
- combineContexts: () => combineContexts,
808
- convertFieldsToArray: () => convertFieldsToArray,
809
- countSum: () => countSum,
810
- getDateRange: () => getDateRange,
811
- languages: () => languages,
812
- mergeButtons: () => mergeButtons,
813
- setStorageItemAsync: () => setStorageItemAsync,
814
- useGetRowIds: () => useGetRowIds,
815
- useSelectionState: () => useSelectionState,
816
- useStorageState: () => useStorageState
817
- });
818
- __reExport(utils_exports, utils_star);
819
- import * as utils_star from "@fctc/interface-logic/utils";
820
-
821
682
  // src/hooks/utils/use-click-outside.ts
822
683
  import { useEffect as useEffect7, useRef as useRef2 } from "react";
823
684
  var DEFAULT_EVENTS = ["mousedown", "touchstart"];
@@ -850,9 +711,9 @@ var useClickOutside = ({
850
711
  };
851
712
 
852
713
  // src/hooks/utils/use-debounce.ts
853
- import { useEffect as useEffect8, useState as useState6 } from "react";
714
+ import { useEffect as useEffect8, useState as useState5 } from "react";
854
715
  function useDebounce(value, delay) {
855
- const [debouncedValue, setDebouncedValue] = useState6(value);
716
+ const [debouncedValue, setDebouncedValue] = useState5(value);
856
717
  useEffect8(() => {
857
718
  const handler = setTimeout(() => {
858
719
  setDebouncedValue(value);