@fctc/widget-logic 2.3.8 → 2.3.10

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 { RefObject } from 'react';
4
+ import react__default, { RefObject } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  export * from '@fctc/interface-logic/hooks';
7
7
 
@@ -927,7 +927,6 @@ declare const useCompany: (accessToken: string | null) => {
927
927
  allowed_company_ids: (number | undefined)[];
928
928
  };
929
929
  };
930
-
931
930
  interface CompanyTuple extends Array<number | string> {
932
931
  0: number;
933
932
  1: string;
@@ -966,6 +965,11 @@ declare const useMenuItem: (props: any) => {
966
965
  queryActionDetail: TActionDetailType;
967
966
  };
968
967
 
968
+ declare const useGetRowIds: (tableRef: react__default.RefObject<HTMLTableElement | null>) => {
969
+ rowIds: string[];
970
+ refresh: () => void;
971
+ };
972
+
969
973
  declare const DEFAULT_EVENTS: readonly ["mousedown", "touchstart"];
970
974
  type EventType = (typeof DEFAULT_EVENTS)[number];
971
975
  interface UseClickOutsideOptions {
@@ -978,4 +982,4 @@ declare const useClickOutside: ({ handler, events, nodes, refs, }: UseClickOutsi
978
982
 
979
983
  declare function useDebounce<T>(value: T, delay: number): [T];
980
984
 
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 };
985
+ export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useCompany, type useCompanyType, useConfig, type useConfigType, useDebounce, useDetail, useGetRowIds, 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 { RefObject } from 'react';
4
+ import react__default, { RefObject } from 'react';
5
5
  import * as react_jsx_runtime from 'react/jsx-runtime';
6
6
  export * from '@fctc/interface-logic/hooks';
7
7
 
@@ -927,7 +927,6 @@ declare const useCompany: (accessToken: string | null) => {
927
927
  allowed_company_ids: (number | undefined)[];
928
928
  };
929
929
  };
930
-
931
930
  interface CompanyTuple extends Array<number | string> {
932
931
  0: number;
933
932
  1: string;
@@ -966,6 +965,11 @@ declare const useMenuItem: (props: any) => {
966
965
  queryActionDetail: TActionDetailType;
967
966
  };
968
967
 
968
+ declare const useGetRowIds: (tableRef: react__default.RefObject<HTMLTableElement | null>) => {
969
+ rowIds: string[];
970
+ refresh: () => void;
971
+ };
972
+
969
973
  declare const DEFAULT_EVENTS: readonly ["mousedown", "touchstart"];
970
974
  type EventType = (typeof DEFAULT_EVENTS)[number];
971
975
  interface UseClickOutsideOptions {
@@ -978,4 +982,4 @@ declare const useClickOutside: ({ handler, events, nodes, refs, }: UseClickOutsi
978
982
 
979
983
  declare function useDebounce<T>(value: T, delay: number): [T];
980
984
 
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 };
985
+ export { type ActionResultType, AppProvider, type ContextProfile, type Record, type ViewResponse, useAppProvider, useAuth, type useAuthType, useCallAction, type useCallActionType, useClickOutside, useCompany, type useCompanyType, useConfig, type useConfigType, useDebounce, useDetail, useGetRowIds, useListData, type useListDataType, useMenu, useMenuItem, type useMenuType, useProfile, useUser, type useUserType, useViewV2, type useViewV2Type };
package/dist/hooks.js CHANGED
@@ -26,9 +26,11 @@ __export(hooks_exports, {
26
26
  useAuth: () => useAuth,
27
27
  useCallAction: () => useCallAction,
28
28
  useClickOutside: () => useClickOutside,
29
+ useCompany: () => useCompany,
29
30
  useConfig: () => useConfig,
30
31
  useDebounce: () => useDebounce,
31
32
  useDetail: () => useDetail,
33
+ useGetRowIds: () => useGetRowIds,
32
34
  useListData: () => useListData,
33
35
  useMenu: () => useMenu,
34
36
  useMenuItem: () => useMenuItem,
@@ -157,12 +159,6 @@ var import_react5 = require("react");
157
159
 
158
160
  // src/utils/function.ts
159
161
  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
166
162
  var countSum = (data, field) => {
167
163
  if (!data || !field) return 0;
168
164
  return data.reduce(
@@ -181,91 +177,6 @@ function mergeButtons(fields) {
181
177
  }
182
178
  return others;
183
179
  }
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
- };
269
180
  var getDateRange = (currentDate, unit) => {
270
181
  const date = new Date(currentDate);
271
182
  let dateStart, dateEnd;
@@ -406,19 +317,19 @@ function useStorageState(key) {
406
317
 
407
318
  // src/hooks/core/use-list-data.ts
408
319
  var import_hooks3 = require("@fctc/interface-logic/hooks");
409
- var import_store4 = require("@fctc/interface-logic/store");
320
+ var import_store3 = require("@fctc/interface-logic/store");
410
321
  var import_utils = require("@fctc/interface-logic/utils");
411
322
  var useListData = ({
412
323
  action,
413
324
  context,
414
325
  viewResponse
415
326
  }) => {
416
- const { groupByDomain } = (0, import_store4.useAppSelector)(import_store4.selectSearch);
327
+ const { groupByDomain } = (0, import_store3.useAppSelector)(import_store3.selectSearch);
417
328
  const initModel = (0, import_hooks3.useModel)();
418
329
  const [type, setType] = (0, import_react5.useState)("list");
419
330
  const [mode, setMode] = (0, import_react5.useState)("month");
420
331
  const [currentDate, setCurrentDate] = (0, import_react5.useState)(/* @__PURE__ */ new Date());
421
- const { pageLimit, page, order } = (0, import_store4.useAppSelector)(import_store4.selectList);
332
+ const { pageLimit, page, order } = (0, import_store3.useAppSelector)(import_store3.selectList);
422
333
  const listDataProps = (0, import_react5.useMemo)(() => {
423
334
  const actData = action?.result;
424
335
  if (!viewResponse || !actData || !context) {
@@ -553,10 +464,10 @@ var import_react7 = require("react");
553
464
  var import_react_i18next = require("react-i18next");
554
465
  var import_environment3 = require("@fctc/interface-logic/environment");
555
466
  var import_hooks5 = require("@fctc/interface-logic/hooks");
556
- var import_store5 = require("@fctc/interface-logic/store");
467
+ var import_store4 = require("@fctc/interface-logic/store");
557
468
  var useProfile = (accessToken) => {
558
469
  const getProfile = (0, import_hooks5.useGetProfile)();
559
- const dispatch = (0, import_store5.useAppDispatch)();
470
+ const dispatch = (0, import_store4.useAppDispatch)();
560
471
  const { i18n } = (0, import_react_i18next.useTranslation)();
561
472
  const fetchUserProfile = async () => {
562
473
  return await getProfile.mutateAsync();
@@ -571,7 +482,7 @@ var useProfile = (accessToken) => {
571
482
  const userInfo = userInfoQuery.data;
572
483
  const env = (0, import_environment3.getEnv)();
573
484
  env.setUid(userInfo?.sub);
574
- dispatch((0, import_store5.setDataUser)(userInfo));
485
+ dispatch((0, import_store4.setDataUser)(userInfo));
575
486
  const userLocale = languages.find((lang) => lang?.id === userInfo?.locale);
576
487
  env.setLang(userLocale?.id);
577
488
  i18n.changeLanguage(userLocale?.id.split("_")[0]);
@@ -636,11 +547,11 @@ var useViewV2 = ({
636
547
 
637
548
  // src/hooks/core/use-auth.ts
638
549
  var import_hooks7 = require("@fctc/interface-logic/hooks");
639
- var import_store6 = require("@fctc/interface-logic/store");
550
+ var import_store5 = require("@fctc/interface-logic/store");
640
551
  var useAuth = () => {
641
552
  const [[isLoading, accessToken], setAccessToken] = useStorageState("TOKEN");
642
553
  const loginMutate = (0, import_hooks7.useLoginCredential)();
643
- const dispatch = (0, import_store6.useAppDispatch)();
554
+ const dispatch = (0, import_store5.useAppDispatch)();
644
555
  const signIn = async (email, password) => {
645
556
  try {
646
557
  loginMutate.mutate(
@@ -661,9 +572,9 @@ var useAuth = () => {
661
572
  }
662
573
  };
663
574
  const signOut = async () => {
664
- dispatch((0, import_store6.setMenuList)([]));
665
- dispatch((0, import_store6.setDataUser)({}));
666
- dispatch((0, import_store6.setProfile)({}));
575
+ dispatch((0, import_store5.setMenuList)([]));
576
+ dispatch((0, import_store5.setDataUser)({}));
577
+ dispatch((0, import_store5.setProfile)({}));
667
578
  setAccessToken(null);
668
579
  };
669
580
  return {
@@ -676,6 +587,7 @@ var useAuth = () => {
676
587
 
677
588
  // src/hooks/core/use-app-provider.tsx
678
589
  var import_react10 = require("react");
590
+ var import_utils2 = require("@fctc/interface-logic/utils");
679
591
 
680
592
  // src/hooks/core/use-company.ts
681
593
  var import_react_query3 = require("@tanstack/react-query");
@@ -724,10 +636,8 @@ var useCompany = (accessToken) => {
724
636
  context: { allowed_company_ids: [current_company_id] }
725
637
  };
726
638
  };
727
- var use_company_default = useCompany;
728
639
 
729
640
  // src/hooks/core/use-app-provider.tsx
730
- var import_utils2 = require("@fctc/interface-logic/utils");
731
641
  var import_jsx_runtime = require("react/jsx-runtime");
732
642
  var AppProviderInitialValue = {
733
643
  config: {},
@@ -744,7 +654,7 @@ var AppProvider = ({ children }) => {
744
654
  const config = useConfig({});
745
655
  const auth = useAuth();
746
656
  const user = useUser(auth.accessToken);
747
- const company = use_company_default(auth.accessToken);
657
+ const company = useCompany(auth.accessToken);
748
658
  const menuContext = (0, import_react10.useMemo)(() => {
749
659
  return combineContexts([user.context, company.context]);
750
660
  }, [user.context, company.context]);
@@ -810,8 +720,6 @@ __export(utils_exports, {
810
720
  languages: () => languages,
811
721
  mergeButtons: () => mergeButtons,
812
722
  setStorageItemAsync: () => setStorageItemAsync,
813
- useGetRowIds: () => useGetRowIds,
814
- useSelectionState: () => useSelectionState,
815
723
  useStorageState: () => useStorageState
816
724
  });
817
725
  __reExport(utils_exports, require("@fctc/interface-logic/utils"));
@@ -853,8 +761,74 @@ var useMenuItem = (props) => {
853
761
  return { handleClick, path, queryActionDetail };
854
762
  };
855
763
 
856
- // src/hooks/utils/use-click-outside.ts
764
+ // src/hooks/core/use-get-rowids.ts
857
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
+ // src/hooks/utils/use-click-outside.ts
831
+ var import_react13 = require("react");
858
832
  var DEFAULT_EVENTS = ["mousedown", "touchstart"];
859
833
  var useClickOutside = ({
860
834
  handler,
@@ -862,8 +836,8 @@ var useClickOutside = ({
862
836
  nodes = [],
863
837
  refs
864
838
  }) => {
865
- const ref = (0, import_react12.useRef)(null);
866
- (0, import_react12.useEffect)(() => {
839
+ const ref = (0, import_react13.useRef)(null);
840
+ (0, import_react13.useEffect)(() => {
867
841
  const listener = (event) => {
868
842
  const { target } = event;
869
843
  if (refs && refs?.length > 0 && refs?.some((r) => r.current?.contains(target))) {
@@ -885,10 +859,10 @@ var useClickOutside = ({
885
859
  };
886
860
 
887
861
  // src/hooks/utils/use-debounce.ts
888
- var import_react13 = require("react");
862
+ var import_react14 = require("react");
889
863
  function useDebounce(value, delay) {
890
- const [debouncedValue, setDebouncedValue] = (0, import_react13.useState)(value);
891
- (0, import_react13.useEffect)(() => {
864
+ const [debouncedValue, setDebouncedValue] = (0, import_react14.useState)(value);
865
+ (0, import_react14.useEffect)(() => {
892
866
  const handler = setTimeout(() => {
893
867
  setDebouncedValue(value);
894
868
  }, delay);
@@ -908,9 +882,11 @@ __reExport(hooks_exports, require("@fctc/interface-logic/hooks"), module.exports
908
882
  useAuth,
909
883
  useCallAction,
910
884
  useClickOutside,
885
+ useCompany,
911
886
  useConfig,
912
887
  useDebounce,
913
888
  useDetail,
889
+ useGetRowIds,
914
890
  useListData,
915
891
  useMenu,
916
892
  useMenuItem,