@fctc/widget-logic 2.3.5 → 2.3.6

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.d.mts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _tanstack_react_query from '@tanstack/react-query';
2
2
  import * as _tanstack_query_core from '@tanstack/query-core';
3
3
  import * as react from 'react';
4
- import react__default, { RefObject } from 'react';
4
+ import { RefObject } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  export * from '@fctc/interface-logic/hooks';
7
7
 
@@ -966,11 +966,6 @@ declare const useMenuItem: (props: any) => {
966
966
  queryActionDetail: TActionDetailType;
967
967
  };
968
968
 
969
- declare const useGetRowIds: (tableRef: react__default.RefObject<HTMLTableElement | null>) => {
970
- rowIds: string[];
971
- refresh: () => void;
972
- };
973
-
974
969
  declare const DEFAULT_EVENTS: readonly ["mousedown", "touchstart"];
975
970
  type EventType = (typeof DEFAULT_EVENTS)[number];
976
971
  interface UseClickOutsideOptions {
@@ -983,4 +978,4 @@ declare const useClickOutside: ({ handler, events, nodes, refs, }: UseClickOutsi
983
978
 
984
979
  declare function useDebounce<T>(value: T, delay: number): [T];
985
980
 
986
- export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useConfig, type useConfigType, useDebounce, useDetail, useGetRowIds, useListData, type useListDataType, useMenu, useMenuItem, type useMenuType, useProfile, useUser, type useUserType, useViewV2, type useViewV2Type };
981
+ export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useConfig, type useConfigType, useDebounce, useDetail, useListData, type useListDataType, useMenu, useMenuItem, type useMenuType, useProfile, useUser, type useUserType, useViewV2, type useViewV2Type };
package/dist/hooks.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as _tanstack_react_query from '@tanstack/react-query';
2
2
  import * as _tanstack_query_core from '@tanstack/query-core';
3
3
  import * as react from 'react';
4
- import react__default, { RefObject } from 'react';
4
+ import { RefObject } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  export * from '@fctc/interface-logic/hooks';
7
7
 
@@ -966,11 +966,6 @@ declare const useMenuItem: (props: any) => {
966
966
  queryActionDetail: TActionDetailType;
967
967
  };
968
968
 
969
- declare const useGetRowIds: (tableRef: react__default.RefObject<HTMLTableElement | null>) => {
970
- rowIds: string[];
971
- refresh: () => void;
972
- };
973
-
974
969
  declare const DEFAULT_EVENTS: readonly ["mousedown", "touchstart"];
975
970
  type EventType = (typeof DEFAULT_EVENTS)[number];
976
971
  interface UseClickOutsideOptions {
@@ -983,4 +978,4 @@ declare const useClickOutside: ({ handler, events, nodes, refs, }: UseClickOutsi
983
978
 
984
979
  declare function useDebounce<T>(value: T, delay: number): [T];
985
980
 
986
- export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useConfig, type useConfigType, useDebounce, useDetail, useGetRowIds, useListData, type useListDataType, useMenu, useMenuItem, type useMenuType, useProfile, useUser, type useUserType, useViewV2, type useViewV2Type };
981
+ export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useConfig, type useConfigType, useDebounce, useDetail, useListData, type useListDataType, useMenu, useMenuItem, type useMenuType, useProfile, useUser, type useUserType, useViewV2, type useViewV2Type };
package/dist/hooks.js CHANGED
@@ -29,7 +29,6 @@ __export(hooks_exports, {
29
29
  useConfig: () => useConfig,
30
30
  useDebounce: () => useDebounce,
31
31
  useDetail: () => useDetail,
32
- useGetRowIds: () => useGetRowIds,
33
32
  useListData: () => useListData,
34
33
  useMenu: () => useMenu,
35
34
  useMenuItem: () => useMenuItem,
@@ -158,6 +157,12 @@ var import_react5 = require("react");
158
157
 
159
158
  // src/utils/function.ts
160
159
  var import_react4 = require("react");
160
+
161
+ // src/store.ts
162
+ var store_exports = {};
163
+ __reExport(store_exports, require("@fctc/interface-logic/store"));
164
+
165
+ // src/utils/function.ts
161
166
  var countSum = (data, field) => {
162
167
  if (!data || !field) return 0;
163
168
  return data.reduce(
@@ -176,6 +181,91 @@ function mergeButtons(fields) {
176
181
  }
177
182
  return others;
178
183
  }
184
+ function isElementVisible(el) {
185
+ const style = window.getComputedStyle(el);
186
+ return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
187
+ }
188
+ function arraysAreEqual(a, b) {
189
+ if (a.length !== b.length) return false;
190
+ const setA = new Set(a);
191
+ const setB = new Set(b);
192
+ if (setA.size !== setB.size) return false;
193
+ for (const val of setA) {
194
+ if (!setB.has(val)) return false;
195
+ }
196
+ return true;
197
+ }
198
+ function useGetRowIds(tableRef) {
199
+ const [rowIds, setRowIds] = (0, import_react4.useState)([]);
200
+ const lastRowIdsRef = (0, import_react4.useRef)([]);
201
+ const updateVisibleRowIds = (0, import_react4.useCallback)(() => {
202
+ const table = tableRef?.current;
203
+ if (!table) return;
204
+ const rows = table.querySelectorAll("tr[data-row-id]");
205
+ const ids = [];
206
+ rows.forEach((row) => {
207
+ const el = row;
208
+ if (isElementVisible(el)) {
209
+ const id = el.getAttribute("data-row-id");
210
+ if (id) ids.push(id);
211
+ }
212
+ });
213
+ const uniqueIds = Array.from(new Set(ids));
214
+ if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
215
+ lastRowIdsRef.current = uniqueIds;
216
+ setRowIds(uniqueIds);
217
+ }
218
+ }, [tableRef]);
219
+ (0, import_react4.useEffect)(() => {
220
+ const table = tableRef?.current;
221
+ if (!table) return;
222
+ const observer = new MutationObserver(() => {
223
+ updateVisibleRowIds();
224
+ });
225
+ observer.observe(table, {
226
+ childList: true,
227
+ subtree: true,
228
+ attributes: true,
229
+ attributeFilter: ["style", "class"]
230
+ });
231
+ updateVisibleRowIds();
232
+ return () => {
233
+ observer.disconnect();
234
+ };
235
+ }, [updateVisibleRowIds, tableRef]);
236
+ return { rowIds, refresh: updateVisibleRowIds };
237
+ }
238
+ var useSelectionState = ({
239
+ typeTable,
240
+ tableRef,
241
+ rows
242
+ }) => {
243
+ const { groupByDomain } = (0, store_exports.useAppSelector)(store_exports.selectSearch);
244
+ const { selectedRowKeys } = (0, store_exports.useAppSelector)(store_exports.selectList);
245
+ const { rowIds: recordIds } = useGetRowIds(tableRef);
246
+ const selectedRowKeysRef = (0, import_react4.useRef)(recordIds);
247
+ const isGroupTable = typeTable === "group";
248
+ const recordsCheckedGroup = (0, import_react4.useMemo)(() => {
249
+ if (!rows || !groupByDomain) return 0;
250
+ const groupBy = typeof groupByDomain === "object" ? groupByDomain?.contexts?.[0]?.group_by : void 0;
251
+ return countSum(rows, groupBy);
252
+ }, [rows, groupByDomain]);
253
+ const isAllGroupChecked = (0, import_react4.useMemo)(() => {
254
+ if (!isGroupTable || !selectedRowKeys?.length) return false;
255
+ const selectedLength = selectedRowKeys.filter((id) => id !== -1).length;
256
+ const allRecordsSelected = recordIds.length === selectedRowKeys.length ? recordIds.length === selectedLength : false;
257
+ const allGroupsSelected = recordsCheckedGroup === selectedRowKeys.length;
258
+ return allGroupsSelected || allRecordsSelected;
259
+ }, [isGroupTable, selectedRowKeys, recordIds, recordsCheckedGroup]);
260
+ const isAllNormalChecked = (0, import_react4.useMemo)(() => {
261
+ if (isGroupTable || !selectedRowKeys?.length || !rows?.length) return false;
262
+ return selectedRowKeys.length === rows.length && selectedRowKeys.every(
263
+ (id) => rows.some((record) => record.id === id)
264
+ );
265
+ }, [isGroupTable, selectedRowKeys, rows]);
266
+ const checkedAll = isAllGroupChecked || isAllNormalChecked;
267
+ return { checkedAll, selectedRowKeysRef };
268
+ };
179
269
  var getDateRange = (currentDate, unit) => {
180
270
  const date = new Date(currentDate);
181
271
  let dateStart, dateEnd;
@@ -316,19 +406,19 @@ function useStorageState(key) {
316
406
 
317
407
  // src/hooks/core/use-list-data.ts
318
408
  var import_hooks3 = require("@fctc/interface-logic/hooks");
319
- var import_store3 = require("@fctc/interface-logic/store");
409
+ var import_store4 = require("@fctc/interface-logic/store");
320
410
  var import_utils = require("@fctc/interface-logic/utils");
321
411
  var useListData = ({
322
412
  action,
323
413
  context,
324
414
  viewResponse
325
415
  }) => {
326
- const { groupByDomain } = (0, import_store3.useAppSelector)(import_store3.selectSearch);
416
+ const { groupByDomain } = (0, import_store4.useAppSelector)(import_store4.selectSearch);
327
417
  const initModel = (0, import_hooks3.useModel)();
328
418
  const [type, setType] = (0, import_react5.useState)("list");
329
419
  const [mode, setMode] = (0, import_react5.useState)("month");
330
420
  const [currentDate, setCurrentDate] = (0, import_react5.useState)(/* @__PURE__ */ new Date());
331
- const { pageLimit, page, order } = (0, import_store3.useAppSelector)(import_store3.selectList);
421
+ const { pageLimit, page, order } = (0, import_store4.useAppSelector)(import_store4.selectList);
332
422
  const listDataProps = (0, import_react5.useMemo)(() => {
333
423
  const actData = action?.result;
334
424
  if (!viewResponse || !actData || !context) {
@@ -463,10 +553,10 @@ var import_react7 = require("react");
463
553
  var import_react_i18next = require("react-i18next");
464
554
  var import_environment3 = require("@fctc/interface-logic/environment");
465
555
  var import_hooks5 = require("@fctc/interface-logic/hooks");
466
- var import_store4 = require("@fctc/interface-logic/store");
556
+ var import_store5 = require("@fctc/interface-logic/store");
467
557
  var useProfile = (accessToken) => {
468
558
  const getProfile = (0, import_hooks5.useGetProfile)();
469
- const dispatch = (0, import_store4.useAppDispatch)();
559
+ const dispatch = (0, import_store5.useAppDispatch)();
470
560
  const { i18n } = (0, import_react_i18next.useTranslation)();
471
561
  const fetchUserProfile = async () => {
472
562
  return await getProfile.mutateAsync();
@@ -481,7 +571,7 @@ var useProfile = (accessToken) => {
481
571
  const userInfo = userInfoQuery.data;
482
572
  const env = (0, import_environment3.getEnv)();
483
573
  env.setUid(userInfo?.sub);
484
- dispatch((0, import_store4.setDataUser)(userInfo));
574
+ dispatch((0, import_store5.setDataUser)(userInfo));
485
575
  const userLocale = languages.find((lang) => lang?.id === userInfo?.locale);
486
576
  env.setLang(userLocale?.id);
487
577
  i18n.changeLanguage(userLocale?.id.split("_")[0]);
@@ -546,11 +636,11 @@ var useViewV2 = ({
546
636
 
547
637
  // src/hooks/core/use-auth.ts
548
638
  var import_hooks7 = require("@fctc/interface-logic/hooks");
549
- var import_store5 = require("@fctc/interface-logic/store");
639
+ var import_store6 = require("@fctc/interface-logic/store");
550
640
  var useAuth = () => {
551
641
  const [[isLoading, accessToken], setAccessToken] = useStorageState("TOKEN");
552
642
  const loginMutate = (0, import_hooks7.useLoginCredential)();
553
- const dispatch = (0, import_store5.useAppDispatch)();
643
+ const dispatch = (0, import_store6.useAppDispatch)();
554
644
  const signIn = async (email, password) => {
555
645
  try {
556
646
  loginMutate.mutate(
@@ -571,9 +661,9 @@ var useAuth = () => {
571
661
  }
572
662
  };
573
663
  const signOut = async () => {
574
- dispatch((0, import_store5.setMenuList)([]));
575
- dispatch((0, import_store5.setDataUser)({}));
576
- dispatch((0, import_store5.setProfile)({}));
664
+ dispatch((0, import_store6.setMenuList)([]));
665
+ dispatch((0, import_store6.setDataUser)({}));
666
+ dispatch((0, import_store6.setProfile)({}));
577
667
  setAccessToken(null);
578
668
  };
579
669
  return {
@@ -720,6 +810,8 @@ __export(utils_exports, {
720
810
  languages: () => languages,
721
811
  mergeButtons: () => mergeButtons,
722
812
  setStorageItemAsync: () => setStorageItemAsync,
813
+ useGetRowIds: () => useGetRowIds,
814
+ useSelectionState: () => useSelectionState,
723
815
  useStorageState: () => useStorageState
724
816
  });
725
817
  __reExport(utils_exports, require("@fctc/interface-logic/utils"));
@@ -761,74 +853,8 @@ var useMenuItem = (props) => {
761
853
  return { handleClick, path, queryActionDetail };
762
854
  };
763
855
 
764
- // src/hooks/core/use-get-rowids.ts
765
- var import_react12 = require("react");
766
- var useGetRowIds = (tableRef) => {
767
- function isElementVisible(el) {
768
- const style = window.getComputedStyle(el);
769
- return style.display !== "none" && style.visibility !== "hidden" && style.opacity !== "0";
770
- }
771
- function arraysAreEqual(a, b) {
772
- if (a.length !== b.length) return false;
773
- if (a.length === 0 && b.length === 0) return true;
774
- const setA = new Set(a);
775
- const setB = new Set(b);
776
- if (setA.size !== setB.size) return false;
777
- for (const val of setA) {
778
- if (!setB.has(val)) return false;
779
- }
780
- return true;
781
- }
782
- const [rowIds, setRowIds] = (0, import_react12.useState)([]);
783
- const lastRowIdsRef = (0, import_react12.useRef)([]);
784
- const updateVisibleRowIds = (0, import_react12.useCallback)(() => {
785
- const table = tableRef.current;
786
- if (!table) return;
787
- const rows = table.querySelectorAll("tr[data-row-id]");
788
- const ids = [];
789
- rows.forEach((row) => {
790
- const el = row;
791
- if (isElementVisible(el)) {
792
- const id = el.getAttribute("data-row-id");
793
- if (id) ids.push(id);
794
- }
795
- });
796
- const uniqueIds = Array.from(new Set(ids));
797
- if (!arraysAreEqual(lastRowIdsRef.current, uniqueIds)) {
798
- lastRowIdsRef.current = uniqueIds;
799
- setRowIds(uniqueIds);
800
- }
801
- }, [tableRef]);
802
- (0, import_react12.useEffect)(() => {
803
- const table = tableRef.current;
804
- if (!table) return;
805
- const mutationObserver = new MutationObserver(() => {
806
- updateVisibleRowIds();
807
- });
808
- mutationObserver.observe(table, {
809
- childList: true,
810
- subtree: true,
811
- attributes: true,
812
- attributeFilter: ["style", "class"]
813
- });
814
- const resizeObserver = new ResizeObserver(() => {
815
- updateVisibleRowIds();
816
- });
817
- resizeObserver.observe(table);
818
- const handleScroll = () => updateVisibleRowIds();
819
- table.addEventListener("scroll", handleScroll, true);
820
- updateVisibleRowIds();
821
- return () => {
822
- mutationObserver.disconnect();
823
- resizeObserver.disconnect();
824
- table.removeEventListener("scroll", handleScroll, true);
825
- };
826
- }, [updateVisibleRowIds, tableRef?.current]);
827
- return { rowIds, refresh: updateVisibleRowIds };
828
- };
829
-
830
856
  // src/hooks/utils/use-click-outside.ts
831
- var import_react13 = require("react");
857
+ var import_react12 = require("react");
832
858
  var DEFAULT_EVENTS = ["mousedown", "touchstart"];
833
859
  var useClickOutside = ({
834
860
  handler,
@@ -836,8 +862,8 @@ var useClickOutside = ({
836
862
  nodes = [],
837
863
  refs
838
864
  }) => {
839
- const ref = (0, import_react13.useRef)(null);
840
- (0, import_react13.useEffect)(() => {
865
+ const ref = (0, import_react12.useRef)(null);
866
+ (0, import_react12.useEffect)(() => {
841
867
  const listener = (event) => {
842
868
  const { target } = event;
843
869
  if (refs && refs?.length > 0 && refs?.some((r) => r.current?.contains(target))) {
@@ -859,10 +885,10 @@ var useClickOutside = ({
859
885
  };
860
886
 
861
887
  // src/hooks/utils/use-debounce.ts
862
- var import_react14 = require("react");
888
+ var import_react13 = require("react");
863
889
  function useDebounce(value, delay) {
864
- const [debouncedValue, setDebouncedValue] = (0, import_react14.useState)(value);
865
- (0, import_react14.useEffect)(() => {
890
+ const [debouncedValue, setDebouncedValue] = (0, import_react13.useState)(value);
891
+ (0, import_react13.useEffect)(() => {
866
892
  const handler = setTimeout(() => {
867
893
  setDebouncedValue(value);
868
894
  }, delay);
@@ -885,7 +911,6 @@ __reExport(hooks_exports, require("@fctc/interface-logic/hooks"), module.exports
885
911
  useConfig,
886
912
  useDebounce,
887
913
  useDetail,
888
- useGetRowIds,
889
914
  useListData,
890
915
  useMenu,
891
916
  useMenuItem,