ag-common 0.0.901 → 0.0.902

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.
Files changed (35) hide show
  1. package/dist/api/helpers/cosmos/get.js +1 -1
  2. package/dist/api/helpers/cosmos/utils.js +0 -3
  3. package/dist/api/helpers/dynamo/set.js +3 -3
  4. package/dist/api/helpers/google/gemini.js +3 -3
  5. package/dist/api/helpers/retryOnError.js +1 -1
  6. package/dist/api/helpers/validations.js +3 -3
  7. package/dist/common/helpers/array.js +1 -5
  8. package/dist/common/helpers/async.d.ts +1 -1
  9. package/dist/common/helpers/async.js +1 -1
  10. package/dist/common/helpers/groupBy.js +2 -2
  11. package/dist/common/helpers/i18n.js +1 -1
  12. package/dist/common/helpers/object.js +2 -5
  13. package/dist/common/helpers/stream.js +1 -1
  14. package/dist/common/helpers/withRetry.js +2 -2
  15. package/dist/common/helpers/xml.js +9 -7
  16. package/dist/ui/components/DarkMode/Base.js +1 -1
  17. package/dist/ui/components/DarkMode/types.d.ts +5 -5
  18. package/dist/ui/components/Markdown/index.js +1 -1
  19. package/dist/ui/components/shadcn/dropdown-list.js +1 -1
  20. package/dist/ui/components/shadcn/dropdown-menu.js +2 -2
  21. package/dist/ui/components/shadcn/scroll-area.js +1 -1
  22. package/dist/ui/components/shadcn/select.js +2 -2
  23. package/dist/ui/components/shadcn/textarea.js +1 -1
  24. package/dist/ui/components/shadcn/toast.js +1 -1
  25. package/dist/ui/helpers/cookie/get.js +1 -1
  26. package/dist/ui/helpers/cookie/raw.js +1 -1
  27. package/dist/ui/helpers/cookie/set.js +2 -3
  28. package/dist/ui/helpers/useGranularHook.js +4 -4
  29. package/dist/ui/helpers/useIsInViewport.d.ts +1 -1
  30. package/dist/ui/helpers/useLocalStorage.js +1 -1
  31. package/dist/ui/helpers/useOnScroll.js +5 -12
  32. package/dist/ui/helpers/useQueryString.js +2 -6
  33. package/dist/ui/helpers/useTooltip.d.ts +1 -1
  34. package/dist/ui/styles/common.js +1 -1
  35. package/package.json +3 -3
@@ -101,7 +101,7 @@ async function queryItemsByText(container, searchFields, operator = "AND") {
101
101
  case "not_equals":
102
102
  return `c.${field.fieldName} != @value${index}`;
103
103
  default:
104
- throw new Error(`Unsupported field type: ${field.type}`);
104
+ throw new Error("Unsupported field type");
105
105
  }
106
106
  });
107
107
  const query = `SELECT * FROM c WHERE ${conditions.join(` ${operator} `)}`;
@@ -11,8 +11,5 @@ function createContainer(settings) {
11
11
  const client = new cosmos_1.CosmosClient(settings);
12
12
  const database = client.database(settings.database_name);
13
13
  const container = database.container(settings.container_name);
14
- if (!container) {
15
- throw new Error("error, cosmos container undefined!!");
16
- }
17
14
  return container;
18
15
  }
@@ -17,7 +17,7 @@ const putDynamo = async (item, tableName, opt) => {
17
17
  try {
18
18
  const res = await (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.PutCommand(putParams)), "putDynamo");
19
19
  if (res.$metadata.httpStatusCode !== 200) {
20
- return { error: res.toString() };
20
+ return { error: JSON.stringify(res) };
21
21
  }
22
22
  return { data: undefined };
23
23
  }
@@ -49,7 +49,7 @@ const batchWrite = async (tableName, items, opt) => {
49
49
  }
50
50
  };
51
51
  exports.batchWrite = batchWrite;
52
- const incrementDynamo = async ({ tableName, pkName, pkValue, fieldName, incrementValue = 1, }) => {
52
+ const incrementDynamo = async ({ tableName, pkName, pkValue, fieldName, incrementValue, }) => {
53
53
  const updateParams = {
54
54
  TableName: tableName,
55
55
  Key: { [pkName]: pkValue },
@@ -65,7 +65,7 @@ const incrementDynamo = async ({ tableName, pkName, pkValue, fieldName, incremen
65
65
  try {
66
66
  const res = await (0, withRetry_1.withRetry)(() => _1.dynamoDb.send(new lib_dynamodb_1.UpdateCommand(updateParams)), "incrementDynamo");
67
67
  if (res.$metadata.httpStatusCode !== 200) {
68
- return { error: res.toString() };
68
+ return { error: JSON.stringify(res) };
69
69
  }
70
70
  // Extract the updated value from the response
71
71
  const updatedValue = res.Attributes?.[fieldName];
@@ -9,7 +9,7 @@ const log_1 = require("../../../common/helpers/log");
9
9
  const node_cache_1 = require("../../../common/helpers/node-cache");
10
10
  const retryOnError_1 = require("../retryOnError");
11
11
  const apikey_1 = require("./apikey");
12
- let genAIs;
12
+ let genAIs = [];
13
13
  const geminiModelsCache = new node_cache_1.TypedNodeCache({ stdTTL: 86400 });
14
14
  const geminiModelsCacheKey = "gemini-models-v1";
15
15
  const FALLBACK_GEMINI_MODELS = [
@@ -87,7 +87,7 @@ const getAvailableGeminiModels = async () => {
87
87
  };
88
88
  // Helper to get available key+model combinations
89
89
  const getAvailableGeminiCombinations = async (prefer) => {
90
- if (!genAIs || genAIs.length === 0) {
90
+ if (genAIs.length === 0) {
91
91
  const keyServiceCombinations = (0, apikey_1.getAvailableCombinations)("gemini");
92
92
  const keys = keyServiceCombinations.map((combo) => combo.key);
93
93
  genAIs = keys.map((k) => [k, new genai_1.GoogleGenAI({ apiKey: k })]);
@@ -111,7 +111,7 @@ const geminiPromptImage = async ({ prompt, urls, ident, prefer, }) => {
111
111
  if (urls && urls.length > 0) {
112
112
  images = await (0, async_1.asyncMap)(urls, (i) => (0, fetch_1.fetchToMemory)(i));
113
113
  }
114
- if (images.find((a) => !a)) {
114
+ if (images.some((image) => image === undefined)) {
115
115
  throw new Error("image not downloaded correctly");
116
116
  }
117
117
  const r = await (0, exports.geminiPromptDirect)({
@@ -24,7 +24,7 @@ async function retryOnError(
24
24
  /** so we can log retries with useful info */
25
25
  debugIdent, fn, retries = 1, errorDelay = 2000, errorCheck = exports.isRetryableApiError) {
26
26
  try {
27
- return await fn();
27
+ return fn();
28
28
  }
29
29
  catch (error) {
30
30
  const e = error;
@@ -107,10 +107,10 @@ const getAndValidateToken = async ({ tokenRaw, jwksRegion = "ap-southeast-2", CO
107
107
  return { token, userProfile };
108
108
  }
109
109
  catch (e) {
110
- const ex = e;
110
+ const errorMessage = e instanceof Error ? e.message : String(e);
111
111
  // expiry is too common to log
112
- if (ex.toString().indexOf("jwt expired") !== -1) {
113
- (0, log_1.info)(`jwt fail:${e}`);
112
+ if (errorMessage.includes("jwt expired")) {
113
+ (0, log_1.info)(`jwt fail:${errorMessage}`);
114
114
  }
115
115
  throw e;
116
116
  }
@@ -17,9 +17,6 @@ keyF,
17
17
  */
18
18
  valueF) => {
19
19
  const ret = {};
20
- if (!arr || !keyF) {
21
- return ret;
22
- }
23
20
  arr.forEach((v) => {
24
21
  const k = keyF(v);
25
22
  ret[k] = valueF(v);
@@ -42,8 +39,7 @@ exports.take = take;
42
39
  const chunk = (array, max) => {
43
40
  const rows = [];
44
41
  let row = [];
45
- for (const k in array) {
46
- const item = array[k];
42
+ for (const item of array) {
47
43
  row.push(item);
48
44
  if (row.length >= max) {
49
45
  rows.push(row);
@@ -3,7 +3,7 @@
3
3
  * @param array
4
4
  * @param callback
5
5
  */
6
- export declare function asyncForEach<T>(array: T[], callback: (i: T, index: number, array: T[]) => void, opt?: {
6
+ export declare function asyncForEach<T>(array: T[], callback: (i: T, index: number, array: T[]) => void | PromiseLike<unknown>, opt?: {
7
7
  /** default 1 */
8
8
  maxConcurrency?: number;
9
9
  }): Promise<void>;
@@ -15,7 +15,7 @@ async function asyncForEach(array, callback, opt) {
15
15
  while (rem.length > 0) {
16
16
  const { rest, part } = (0, array_1.take)(rem, maxConcurrency);
17
17
  rem = rest;
18
- const proms = part.map((p, i) => callback(p, start + i, array));
18
+ const proms = part.map((p, i) => Promise.resolve(callback(p, start + i, array)));
19
19
  start += part.length;
20
20
  // oxlint-disable-next-line no-await-in-loop -- concurrency is intentionally bounded per batch
21
21
  await Promise.all(proms);
@@ -12,7 +12,7 @@ function groupBy(arr, getKey) {
12
12
  const ret = {};
13
13
  arr.forEach((item) => {
14
14
  const key = getKey(item);
15
- if (!ret[key]) {
15
+ if (!Object.prototype.hasOwnProperty.call(ret, key)) {
16
16
  ret[key] = [];
17
17
  }
18
18
  ret[key].push(item);
@@ -43,7 +43,7 @@ function groupByTwice(arr, getKey, getSubKey) {
43
43
  arr.forEach((item) => {
44
44
  const key = getKey(item);
45
45
  const subkey = getSubKey(item);
46
- if (!ret[key]) {
46
+ if (!Object.prototype.hasOwnProperty.call(ret, key)) {
47
47
  ret[key] = {};
48
48
  }
49
49
  ret[key][subkey] = item;
@@ -23,7 +23,7 @@ const useTranslation = (texts, lang) => {
23
23
  if (v1 || v1 === null) {
24
24
  return v1 ?? "";
25
25
  }
26
- return texts[lineText].en ?? "???";
26
+ return texts[lineText].en;
27
27
  };
28
28
  return ret;
29
29
  };
@@ -27,7 +27,7 @@ function isJson(str) {
27
27
  return true;
28
28
  }
29
29
  const objectKeysToLowerCase = (origObj) => {
30
- if (!origObj || Object.keys(origObj).length === 0) {
30
+ if (Object.keys(origObj).length === 0) {
31
31
  return {};
32
32
  }
33
33
  return Object.keys(origObj).reduce((newObj, key) => {
@@ -43,9 +43,6 @@ exports.objectKeysToLowerCase = objectKeysToLowerCase;
43
43
  const getObjectKeysAsNumber = (o) => Object.keys(o).map((o2) => parseInt(o2, 10));
44
44
  exports.getObjectKeysAsNumber = getObjectKeysAsNumber;
45
45
  function objectToArray(obj) {
46
- if (!obj) {
47
- return [];
48
- }
49
46
  const ret = [];
50
47
  Object.keys(obj).forEach((ok) => {
51
48
  ret.push({ key: ok, value: obj[ok] });
@@ -101,7 +98,7 @@ function objectToString(obj,
101
98
  joinKeyValue,
102
99
  /** eg '&' */
103
100
  joinKeys) {
104
- if (!obj || Object.keys(obj).length === 0) {
101
+ if (Object.keys(obj).length === 0) {
105
102
  return "";
106
103
  }
107
104
  const raw = Object.entries(obj).map(([key, value]) => key + joinKeyValue + value);
@@ -7,7 +7,7 @@ async function getStringFromStream(stream) {
7
7
  const reader = stream.getReader();
8
8
  let result = "";
9
9
  try {
10
- while (true) {
10
+ for (;;) {
11
11
  // oxlint-disable-next-line no-await-in-loop -- stream chunks must be read sequentially
12
12
  const { done, value } = await reader.read();
13
13
  if (done)
@@ -7,10 +7,10 @@ const withRetry = async (operation, operationName, opt) => {
7
7
  let retryCount = 0;
8
8
  const baseDelay = 2000;
9
9
  const { maxRetries = 3 } = opt ?? {};
10
- while (true) {
10
+ for (;;) {
11
11
  try {
12
12
  // oxlint-disable-next-line no-await-in-loop -- retries are intentionally sequential
13
- return await operation();
13
+ return operation();
14
14
  }
15
15
  catch (e) {
16
16
  const error = e;
@@ -21,15 +21,17 @@ class XMLParser {
21
21
  const newObject = { ...attributes };
22
22
  this.stack.push(this.currentObject);
23
23
  const parent = this.stack[this.stack.length - 1];
24
- const existingValue = parent[name];
25
- if (existingValue === undefined) {
24
+ if (!Object.prototype.hasOwnProperty.call(parent, name)) {
26
25
  parent[name] = newObject;
27
26
  }
28
- else if (Array.isArray(existingValue)) {
29
- existingValue.push(newObject);
30
- }
31
27
  else {
32
- parent[name] = [existingValue, newObject];
28
+ const existingValue = parent[name];
29
+ if (Array.isArray(existingValue)) {
30
+ existingValue.push(newObject);
31
+ }
32
+ else {
33
+ parent[name] = [existingValue, newObject];
34
+ }
33
35
  }
34
36
  this.currentObject = newObject;
35
37
  }
@@ -78,7 +80,7 @@ class XMLReader {
78
80
  let match;
79
81
  while ((match = attributePattern.exec(attributes))) {
80
82
  const [, key, doubleQuotedValue, singleQuotedValue] = match;
81
- parsedAttributes[key] = doubleQuotedValue ?? singleQuotedValue;
83
+ parsedAttributes[key] = doubleQuotedValue || singleQuotedValue;
82
84
  }
83
85
  return parsedAttributes;
84
86
  }
@@ -118,7 +118,7 @@ const DarkModeAux = ({ iconSize = "2.5rem", className, mode, onSubmit, style, dm
118
118
  dm.setDarkmode(newDarkMode);
119
119
  onSubmit?.(newDarkMode);
120
120
  };
121
- return (react_1.default.createElement("div", { className: (0, utils_1.cn)("flex flex-row overflow-hidden justify-between items-center rounded-4xl", "border-2 border-solid p-[2px] box-border", "data-[mode=vert]:flex-col", className), "data-mode": mode ?? "horiz", style: {
121
+ return (react_1.default.createElement("div", { className: (0, utils_1.cn)("flex flex-row overflow-hidden justify-between items-center rounded-4xl", "border-2 border-solid p-0.5 box-border", "data-[mode=vert]:flex-col", className), "data-mode": mode ?? "horiz", style: {
122
122
  ...style,
123
123
  background,
124
124
  borderColor: fill,
@@ -1,9 +1,9 @@
1
1
  export declare enum TDarkMode {
2
- "dark" = 0,
3
- "light" = 1,
4
- "system" = 2
2
+ dark = 0,
3
+ light = 1,
4
+ system = 2
5
5
  }
6
6
  export declare enum TDarkModeCalc {
7
- "dark" = 0,
8
- "light" = 1
7
+ dark = 0,
8
+ light = 1
9
9
  }
@@ -24,7 +24,7 @@ const injectGroup = ({ output, pos, wrap, }) => {
24
24
  const sum = [];
25
25
  for (let a = pos.outputIndex; a <= outputEndIndex; a += 1) {
26
26
  sum.push(output[a]);
27
- delete output[a];
27
+ output.splice(a, 1);
28
28
  }
29
29
  output = (0, array_1.insertElementAtIndex)(output, wrap(sum), pos.outputIndex);
30
30
  return output;
@@ -47,7 +47,7 @@ const DropdownList = ({ options, renderF, onChange, children, className, }) => {
47
47
  return (React.createElement(DropdownMenuPrimitive.Root, { open: open, onOpenChange: setOpen },
48
48
  React.createElement(DropdownMenuPrimitive.Trigger, { asChild: true, className: className }, children),
49
49
  React.createElement(DropdownMenuPrimitive.Portal, null,
50
- React.createElement(DropdownMenuPrimitive.Content, { className: (0, utils_1.cn)("z-[1200] min-w-[8rem] overflow-hidden rounded-md border border-main-fg-mid bg-main-bg text-main-fg shadow-md", "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2"), align: "end" }, options.map((option, index) => {
50
+ React.createElement(DropdownMenuPrimitive.Content, { className: (0, utils_1.cn)("z-1200 min-w-32 overflow-hidden rounded-md border border-main-fg-mid bg-main-bg text-main-fg shadow-md", "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2"), align: "end" }, options.map((option, index) => {
51
51
  const value = typeof option === "string" ? option : option.value;
52
52
  const label = typeof option === "string" ? option : option.label;
53
53
  const isLast = index === options.length - 1;
@@ -55,10 +55,10 @@ const DropdownMenuSubTrigger = ({ className, inset, children, ...props }) => (Re
55
55
  children,
56
56
  React.createElement(react_icons_1.ChevronRightIcon, { className: "ml-auto" })));
57
57
  exports.DropdownMenuSubTrigger = DropdownMenuSubTrigger;
58
- const DropdownMenuSubContent = ({ className, ...props }) => (React.createElement(DropdownMenuPrimitive.SubContent, { className: (0, utils_1.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props }));
58
+ const DropdownMenuSubContent = ({ className, ...props }) => (React.createElement(DropdownMenuPrimitive.SubContent, { className: (0, utils_1.cn)("z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props }));
59
59
  exports.DropdownMenuSubContent = DropdownMenuSubContent;
60
60
  const DropdownMenuContent = ({ className, sideOffset = 4, ...props }) => (React.createElement(DropdownMenuPrimitive.Portal, null,
61
- React.createElement(DropdownMenuPrimitive.Content, { sideOffset: sideOffset, className: (0, utils_1.cn)("z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md", "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props })));
61
+ React.createElement(DropdownMenuPrimitive.Content, { sideOffset: sideOffset, className: (0, utils_1.cn)("z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md", "data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", className), ...props })));
62
62
  exports.DropdownMenuContent = DropdownMenuContent;
63
63
  const DropdownMenuItem = ({ className, inset, ...props }) => (React.createElement(DropdownMenuPrimitive.Item, { className: (0, utils_1.cn)("relative flex cursor-default select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm outline-hidden transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50 [&>svg]:size-4 [&>svg]:shrink-0", inset && "pl-8", className), ...props }));
64
64
  exports.DropdownMenuItem = DropdownMenuItem;
@@ -43,6 +43,6 @@ const ScrollArea = ({ className, children, ...props }) => (React.createElement(S
43
43
  React.createElement(ScrollBar, null),
44
44
  React.createElement(ScrollAreaPrimitive.Corner, null)));
45
45
  exports.ScrollArea = ScrollArea;
46
- const ScrollBar = ({ className, orientation = "vertical", ...props }) => (React.createElement(ScrollAreaPrimitive.ScrollAreaScrollbar, { orientation: orientation, className: (0, utils_1.cn)("flex touch-none select-none transition-colors", orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-[1px]", orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent p-[1px]", className), ...props },
46
+ const ScrollBar = ({ className, orientation = "vertical", ...props }) => (React.createElement(ScrollAreaPrimitive.ScrollAreaScrollbar, { orientation: orientation, className: (0, utils_1.cn)("flex touch-none select-none transition-colors", orientation === "vertical" && "h-full w-2.5 border-l border-l-transparent p-px", orientation === "horizontal" && "h-2.5 flex-col border-t border-t-transparent p-px", className), ...props },
47
47
  React.createElement(ScrollAreaPrimitive.ScrollAreaThumb, { className: "relative flex-1 bg-border" })));
48
48
  exports.ScrollBar = ScrollBar;
@@ -61,11 +61,11 @@ const SelectScrollDownButton = ({ className, ...props }) => (React.createElement
61
61
  React.createElement(react_icons_1.ChevronDownIcon, { className: "h-4 w-4" })));
62
62
  exports.SelectScrollDownButton = SelectScrollDownButton;
63
63
  const SelectContent = ({ className, children, position = "popper", ...props }) => (React.createElement(SelectPrimitive.Portal, null,
64
- React.createElement(SelectPrimitive.Content, { className: (0, utils_1.cn)("relative z-50 max-h-96 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", position === "popper" &&
64
+ React.createElement(SelectPrimitive.Content, { className: (0, utils_1.cn)("relative z-50 max-h-96 min-w-32 overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2", position === "popper" &&
65
65
  "data-[side=bottom]:translate-y-1 data-[side=left]:-translate-x-1 data-[side=right]:translate-x-1 data-[side=top]:-translate-y-1", className), position: position, ...props },
66
66
  React.createElement(SelectScrollUpButton, null),
67
67
  React.createElement(SelectPrimitive.Viewport, { className: (0, utils_1.cn)("p-1", position === "popper" &&
68
- "h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]") }, children),
68
+ "h-(--radix-select-trigger-height) w-full min-w-(--radix-select-trigger-width)") }, children),
69
69
  React.createElement(SelectScrollDownButton, null))));
70
70
  exports.SelectContent = SelectContent;
71
71
  const SelectLabel = ({ className, ...props }) => (React.createElement(SelectPrimitive.Label, { className: (0, utils_1.cn)("px-2 py-1.5 text-sm font-semibold", className), ...props }));
@@ -37,6 +37,6 @@ exports.Textarea = void 0;
37
37
  const React = __importStar(require("react"));
38
38
  const utils_1 = require("../../helpers/utils");
39
39
  const Textarea = ({ className, ...props }) => {
40
- return (React.createElement("textarea", { className: (0, utils_1.cn)("flex min-h-[60px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm", className), ...props }));
40
+ return (React.createElement("textarea", { className: (0, utils_1.cn)("flex min-h-15 w-full rounded-md border border-input bg-transparent px-3 py-2 text-base shadow-xs placeholder:text-muted-foreground focus-visible:outline-hidden focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50 md:text-sm", className), ...props }));
41
41
  };
42
42
  exports.Textarea = Textarea;
@@ -116,7 +116,7 @@ const ToastItem = ({ toast }) => {
116
116
  progressColor = "bg-yellow-100/80";
117
117
  borderColor = "bg-yellow-500";
118
118
  }
119
- return (react_1.default.createElement("div", { className: "group flex flex-col relative overflow-hidden bg-white rounded-md shadow-md min-w-[320px] max-w-sm animate-in slide-in-from-right-full pointer-events-auto", onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave },
119
+ return (react_1.default.createElement("div", { className: "group flex flex-col relative overflow-hidden bg-white rounded-md shadow-md min-w-xs max-w-sm animate-in slide-in-from-right-full pointer-events-auto", onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave },
120
120
  toast.options.duration && toast.options.duration > 0 && (react_1.default.createElement("div", { className: `absolute inset-0 z-0 ${progressColor}`, style: {
121
121
  animation: `toast-progress ${toast.options.duration}ms linear forwards`,
122
122
  animationPlayState: isPaused ? "paused" : "running",
@@ -23,7 +23,7 @@ function getCookieRawWrapper({ name, cookieDocument, defaultValue, parse: parseR
23
23
  };
24
24
  let raw = "";
25
25
  let currentCount = 0;
26
- while (true) {
26
+ for (;;) {
27
27
  const newv = (0, raw_1.getCookie)({
28
28
  name: name + currentCount,
29
29
  cookieDocument,
@@ -47,7 +47,7 @@ function wipeCookies(name) {
47
47
  return;
48
48
  }
49
49
  let currentCount = 0;
50
- while (true) {
50
+ for (;;) {
51
51
  if ((0, exports.getCookie)({
52
52
  name: name + currentCount,
53
53
  cookieDocument: document.cookie,
@@ -24,9 +24,8 @@ function setCookieRawWrapper(p) {
24
24
  }
25
25
  const str = (0, base64_1.toBase64)(stringify(p.value));
26
26
  const chunks = (0, chunk_1.chunkString)(str, const_1.maxCookieLen);
27
- for (const index1 in chunks) {
28
- const chunk = chunks[index1];
29
- (0, raw_1.setCookie)({ ...p, name: p.name + index1, value: chunk });
27
+ for (const [index, chunk] of chunks.entries()) {
28
+ (0, raw_1.setCookie)({ ...p, name: p.name + index, value: chunk });
30
29
  }
31
30
  }
32
31
  const setCookieString = (p) => setCookieRawWrapper({ ...p, stringify: (s) => s });
@@ -4,10 +4,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
4
4
  exports.useGranularEffect = exports.useGranularHook = void 0;
5
5
  const react_1 = require("react");
6
6
  const useGranularHook = (hook, callback, primaryDeps, secondaryDeps) => {
7
- const ref = (0, react_1.useRef)(null);
8
- if (!ref.current || !primaryDeps.every((w, i) => Object.is(w, ref.current?.[i])))
9
- ref.current = [...primaryDeps, ...secondaryDeps];
10
- return hook(callback, ref.current);
7
+ // The dependency list is intentionally dynamic: only primary values control memoization.
8
+ // oxlint-disable-next-line react/use-memo, react-hooks/exhaustive-deps -- granular dependencies are the hook's purpose
9
+ const deps = (0, react_1.useMemo)(() => [...primaryDeps, ...secondaryDeps], [...primaryDeps]);
10
+ return hook(callback, deps);
11
11
  };
12
12
  exports.useGranularHook = useGranularHook;
13
13
  const useGranularEffect = (effect, primaryDeps, secondaryDeps) => (0, exports.useGranularHook)(react_1.useEffect, effect, primaryDeps, secondaryDeps);
@@ -1,2 +1,2 @@
1
1
  import type { RefObject } from "react";
2
- export declare function useIsInViewport(ref: RefObject<HTMLElement>): boolean;
2
+ export declare function useIsInViewport(ref: RefObject<HTMLElement | null>): boolean;
@@ -48,7 +48,7 @@ const setLocalStorageItem = (key, value, ttl) => {
48
48
  window.localStorage.setItem(key, JSON.stringify(set));
49
49
  }
50
50
  catch (e) {
51
- (0, log_1.error)(`set LS error:${key}-${e}`);
51
+ (0, log_1.error)(`set LS error:${key}-${String(e)}`);
52
52
  (0, exports.clearLocalStorageItem)(key);
53
53
  }
54
54
  };
@@ -14,7 +14,7 @@ function useOnScroll({ onScroll, element, } = {}) {
14
14
  scrollTopX: 0,
15
15
  scrollTopY: 0,
16
16
  });
17
- const [startScrollTopY, setStartScrollTopY] = (0, react_1.useState)(-1);
17
+ const startScrollTopY = (0, react_1.useRef)(undefined);
18
18
  (0, useGranularHook_1.useGranularEffect)(() => {
19
19
  const listener = (e) => {
20
20
  if (!element?.current) {
@@ -26,20 +26,18 @@ function useOnScroll({ onScroll, element, } = {}) {
26
26
  y,
27
27
  x,
28
28
  scrolled: !!y || !!x,
29
- isDown: startScrollTopY < y,
29
+ isDown: startScrollTopY.current !== undefined && startScrollTopY.current < y,
30
30
  scrollTopX: x,
31
31
  scrollTopY: y,
32
32
  };
33
+ startScrollTopY.current ??= y;
33
34
  setState(r);
34
35
  onScroll?.(e, r);
35
36
  return { y, x };
36
37
  };
37
38
  const listenDebounce = (e) => {
38
39
  (0, debounce_1.debounce)(() => {
39
- const l = listener(e);
40
- if (l) {
41
- setStartScrollTopY(l.y);
42
- }
40
+ listener(e);
43
41
  }, { key: "onscroll", time: 20 });
44
42
  };
45
43
  (element?.current ?? document).addEventListener(`scroll`, listenDebounce, {
@@ -53,11 +51,6 @@ function useOnScroll({ onScroll, element, } = {}) {
53
51
  //
54
52
  }
55
53
  };
56
- }, [element], [element, onScroll, startScrollTopY]);
57
- (0, react_1.useEffect)(() => {
58
- if (startScrollTopY === -1 && !!element?.current) {
59
- setStartScrollTopY(element.current.scrollTop);
60
- }
61
- }, [element, startScrollTopY]);
54
+ }, [element], [element, onScroll]);
62
55
  return state;
63
56
  }
@@ -34,12 +34,8 @@ const useQueryStringRaw = ({ name, queryValues, defaultValue, stringify, parse,
34
34
  setStateRaw(v);
35
35
  };
36
36
  //
37
- (0, react_1.useEffect)(() => {
38
- if (JSON.stringify(state) !== JSON.stringify(qsv)) {
39
- setStateRaw(qsv);
40
- }
41
- }, [name, parse, qsv, state]);
42
- return [state, setState];
37
+ const currentState = JSON.stringify(state) === JSON.stringify(qsv) ? state : qsv;
38
+ return [currentState, setState];
43
39
  };
44
40
  exports.useQueryStringRaw = useQueryStringRaw;
45
41
  /**
@@ -26,7 +26,7 @@ export interface IUseTooltip<T> {
26
26
  element: MouseEvent;
27
27
  parent: Element | null;
28
28
  data: T;
29
- } | undefined) => void;
29
+ }) => void;
30
30
  pos: IPos<T> | undefined;
31
31
  }
32
32
  export declare const useTooltip: <T>(p?: ITooltipProps) => IUseTooltip<T>;
@@ -60,7 +60,7 @@ const bounce = (isActive = false) => ({
60
60
  },
61
61
  });
62
62
  exports.bounce = bounce;
63
- const Card = ({ children, className = "", ...props }) => (react_1.default.createElement("div", { className: `bg-white m-2 relative rounded-lg max-w-[40rem] p-4 border-2 border-lighter ${className}`, ...props }, children));
63
+ const Card = ({ children, className = "", ...props }) => (react_1.default.createElement("div", { className: `bg-white m-2 relative rounded-lg max-w-160 p-4 border-2 border-lighter ${className}`, ...props }, children));
64
64
  exports.Card = Card;
65
65
  const getVarStyles = (raw) => ({
66
66
  ...raw,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ag-common",
3
- "version": "0.0.901",
3
+ "version": "0.0.902",
4
4
  "license": "ISC",
5
5
  "author": "admin@gec.dev",
6
6
  "repository": {
@@ -63,7 +63,7 @@
63
63
  "aws-cdk-lib": "^2.265.0",
64
64
  "constructs": "^10.8.1",
65
65
  "cross-env": "^10.1.0",
66
- "eslint-config-e7npm": "0.1.56",
66
+ "eslint-config-e7npm": "0.1.62",
67
67
  "globstar": "^1.0.0",
68
68
  "jiti": "^2.7.0",
69
69
  "oxfmt": "^0.60.0",
@@ -80,7 +80,7 @@
80
80
  },
81
81
  "scripts": {
82
82
  "preinstall": "npx only-allow pnpm",
83
- "format": "e7-oxfmt --config .oxfmtrc.json --disable-nested-config .",
83
+ "format": "e7-oxfmt --no-lint --config .oxfmtrc.json --disable-nested-config .",
84
84
  "lint": "e7-oxlint --config .oxlintrc.json --deny-warnings . && pnpm run typecheck",
85
85
  "typecheck": "tsc --noEmit",
86
86
  "build": "rimraf dist && tsc -p tsconfig.build.json",