@fctc/widget-logic 1.9.6 → 1.10.1
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 +140 -6
- package/dist/hooks.mjs +141 -2
- package/dist/index.js +154 -153
- package/dist/index.mjs +72 -71
- package/dist/widget.d.mts +0 -1
- package/dist/widget.d.ts +0 -1
- package/dist/widget.js +146 -145
- package/dist/widget.mjs +68 -67
- package/package.json +96 -96
package/dist/hooks.js
CHANGED
|
@@ -162,6 +162,109 @@ 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
|
+
};
|
|
165
268
|
var getDateRange = (currentDate, unit) => {
|
|
166
269
|
const date = new Date(currentDate);
|
|
167
270
|
let dateStart, dateEnd;
|
|
@@ -259,6 +362,10 @@ function combineContexts(contexts) {
|
|
|
259
362
|
return res;
|
|
260
363
|
}
|
|
261
364
|
}
|
|
365
|
+
var STORAGES = {
|
|
366
|
+
TOKEN: "accessToken",
|
|
367
|
+
USER_INFO: "USER_INFO"
|
|
368
|
+
};
|
|
262
369
|
function useAsyncState(initialValue = [true, null]) {
|
|
263
370
|
return (0, import_react4.useReducer)(
|
|
264
371
|
(_state, action = null) => [false, action],
|
|
@@ -379,6 +486,9 @@ var languages = [
|
|
|
379
486
|
{ id: "vi_VN", name: "VIE" },
|
|
380
487
|
{ id: "en_US", name: "ENG" }
|
|
381
488
|
];
|
|
489
|
+
var API_PRESCHOOL_URL = {
|
|
490
|
+
baseURL: "https://preschool.vitrust.app"
|
|
491
|
+
};
|
|
382
492
|
var API_APP_URL = {
|
|
383
493
|
baseUrl: "https://api.vitrust.app",
|
|
384
494
|
c2: "https://api.vitrust.app/c2",
|
|
@@ -681,8 +791,32 @@ var useAppProvider = () => {
|
|
|
681
791
|
return context;
|
|
682
792
|
};
|
|
683
793
|
|
|
684
|
-
// src/hooks/
|
|
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");
|
|
685
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
|
+
// src/hooks/utils/use-click-outside.ts
|
|
819
|
+
var import_react12 = require("react");
|
|
686
820
|
var DEFAULT_EVENTS = ["mousedown", "touchstart"];
|
|
687
821
|
var useClickOutside = ({
|
|
688
822
|
handler,
|
|
@@ -690,8 +824,8 @@ var useClickOutside = ({
|
|
|
690
824
|
nodes = [],
|
|
691
825
|
refs
|
|
692
826
|
}) => {
|
|
693
|
-
const ref = (0,
|
|
694
|
-
(0,
|
|
827
|
+
const ref = (0, import_react12.useRef)(null);
|
|
828
|
+
(0, import_react12.useEffect)(() => {
|
|
695
829
|
const listener = (event) => {
|
|
696
830
|
const { target } = event;
|
|
697
831
|
if (refs && refs?.length > 0 && refs?.some((r) => r.current?.contains(target))) {
|
|
@@ -713,10 +847,10 @@ var useClickOutside = ({
|
|
|
713
847
|
};
|
|
714
848
|
|
|
715
849
|
// src/hooks/utils/use-debounce.ts
|
|
716
|
-
var
|
|
850
|
+
var import_react13 = require("react");
|
|
717
851
|
function useDebounce(value, delay) {
|
|
718
|
-
const [debouncedValue, setDebouncedValue] = (0,
|
|
719
|
-
(0,
|
|
852
|
+
const [debouncedValue, setDebouncedValue] = (0, import_react13.useState)(value);
|
|
853
|
+
(0, import_react13.useEffect)(() => {
|
|
720
854
|
const handler = setTimeout(() => {
|
|
721
855
|
setDebouncedValue(value);
|
|
722
856
|
}, delay);
|
package/dist/hooks.mjs
CHANGED
|
@@ -2,6 +2,10 @@ 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
|
+
};
|
|
5
9
|
var __copyProps = (to, from, except, desc) => {
|
|
6
10
|
if (from && typeof from === "object" || typeof from === "function") {
|
|
7
11
|
for (let key of __getOwnPropNames(from))
|
|
@@ -145,6 +149,109 @@ __reExport(store_exports, store_star);
|
|
|
145
149
|
import * as store_star from "@fctc/interface-logic/store";
|
|
146
150
|
|
|
147
151
|
// 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
|
+
};
|
|
148
255
|
var getDateRange = (currentDate, unit) => {
|
|
149
256
|
const date = new Date(currentDate);
|
|
150
257
|
let dateStart, dateEnd;
|
|
@@ -242,6 +349,10 @@ function combineContexts(contexts) {
|
|
|
242
349
|
return res;
|
|
243
350
|
}
|
|
244
351
|
}
|
|
352
|
+
var STORAGES = {
|
|
353
|
+
TOKEN: "accessToken",
|
|
354
|
+
USER_INFO: "USER_INFO"
|
|
355
|
+
};
|
|
245
356
|
function useAsyncState(initialValue = [true, null]) {
|
|
246
357
|
return useReducer(
|
|
247
358
|
(_state, action = null) => [false, action],
|
|
@@ -369,6 +480,9 @@ var languages = [
|
|
|
369
480
|
{ id: "vi_VN", name: "VIE" },
|
|
370
481
|
{ id: "en_US", name: "ENG" }
|
|
371
482
|
];
|
|
483
|
+
var API_PRESCHOOL_URL = {
|
|
484
|
+
baseURL: "https://preschool.vitrust.app"
|
|
485
|
+
};
|
|
372
486
|
var API_APP_URL = {
|
|
373
487
|
baseUrl: "https://api.vitrust.app",
|
|
374
488
|
c2: "https://api.vitrust.app/c2",
|
|
@@ -679,6 +793,31 @@ var useAppProvider = () => {
|
|
|
679
793
|
return context;
|
|
680
794
|
};
|
|
681
795
|
|
|
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
|
+
|
|
682
821
|
// src/hooks/utils/use-click-outside.ts
|
|
683
822
|
import { useEffect as useEffect7, useRef as useRef2 } from "react";
|
|
684
823
|
var DEFAULT_EVENTS = ["mousedown", "touchstart"];
|
|
@@ -711,9 +850,9 @@ var useClickOutside = ({
|
|
|
711
850
|
};
|
|
712
851
|
|
|
713
852
|
// src/hooks/utils/use-debounce.ts
|
|
714
|
-
import { useEffect as useEffect8, useState as
|
|
853
|
+
import { useEffect as useEffect8, useState as useState6 } from "react";
|
|
715
854
|
function useDebounce(value, delay) {
|
|
716
|
-
const [debouncedValue, setDebouncedValue] =
|
|
855
|
+
const [debouncedValue, setDebouncedValue] = useState6(value);
|
|
717
856
|
useEffect8(() => {
|
|
718
857
|
const handler = setTimeout(() => {
|
|
719
858
|
setDebouncedValue(value);
|