@trackunit/react-components 2.1.28 → 2.1.30

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/index.cjs.js CHANGED
@@ -10533,6 +10533,58 @@ const b64urlDecode = (s) => {
10533
10533
  }
10534
10534
  return out;
10535
10535
  };
10536
+ /**
10537
+ * Encode a value with the same gzip + base64url format used by useCustomEncoding.
10538
+ *
10539
+ * @param input - The value to encode.
10540
+ * @returns {string} The compressed URL-safe encoded value, or an empty string on failure.
10541
+ */
10542
+ const encodeCustomValue = (input) => {
10543
+ try {
10544
+ const json = typeof input === "string" ? input : JSON.stringify(input);
10545
+ const textInput = new TextEncoder().encode(json);
10546
+ const compressed = fflate.gzipSync(textInput, { mtime: 0 });
10547
+ return b64urlEncode(compressed);
10548
+ }
10549
+ catch (_) {
10550
+ return "";
10551
+ }
10552
+ };
10553
+ /**
10554
+ * Decode a value produced by encodeCustomValue.
10555
+ *
10556
+ * @param str - The compressed URL-safe encoded value.
10557
+ * @returns {object | Array<object> | string} The decoded object/string value, or an empty string on failure.
10558
+ */
10559
+ const decodeCustomValue = (str) => {
10560
+ try {
10561
+ try {
10562
+ const bytes = b64urlDecode(str);
10563
+ const decompressed = fflate.gunzipSync(bytes);
10564
+ const json = new TextDecoder().decode(decompressed);
10565
+ try {
10566
+ return JSON.parse(json);
10567
+ }
10568
+ catch (_) {
10569
+ return json;
10570
+ }
10571
+ }
10572
+ catch (_) {
10573
+ // If compression decoding fails, fall back to regular decoding.
10574
+ }
10575
+ const decoded = decodeURIComponent(escape(atob(str)));
10576
+ try {
10577
+ return JSON.parse(decoded);
10578
+ }
10579
+ catch (_) {
10580
+ return decoded;
10581
+ }
10582
+ }
10583
+ catch (_) {
10584
+ return "";
10585
+ }
10586
+ };
10587
+
10536
10588
  /**
10537
10589
  * React hook for safe base64 encoding/decoding with UTF-8 support and compression
10538
10590
  *
@@ -10552,22 +10604,7 @@ const useCustomEncoding = () => {
10552
10604
  * @param input - The object or string to encode
10553
10605
  * @returns The compressed and encoded string
10554
10606
  */
10555
- const encode = react.useCallback((input) => {
10556
- try {
10557
- // If it's already a string, use it directly; otherwise stringify the object
10558
- const json = typeof input === "string" ? input : JSON.stringify(input);
10559
- const textInput = new TextEncoder().encode(json);
10560
- // Use fflate for synchronous gzip compression.
10561
- // mtime: 0 ensures deterministic output — without it the gzip header
10562
- // includes the current timestamp, making the same input produce a
10563
- // different encoded string on every call.
10564
- const compressed = fflate.gzipSync(textInput, { mtime: 0 });
10565
- return b64urlEncode(compressed);
10566
- }
10567
- catch (_) {
10568
- return "";
10569
- }
10570
- }, []);
10607
+ const encode = react.useCallback((input) => encodeCustomValue(input), []);
10571
10608
  /**
10572
10609
  * Safely decode a compressed and encoded string back to its original form
10573
10610
  *
@@ -10575,41 +10612,9 @@ const useCustomEncoding = () => {
10575
10612
  * and returning the original object or string.
10576
10613
  *
10577
10614
  * @param str - The compressed and encoded string to decode
10578
- * @returns The decoded object or string, or null if decoding fails
10615
+ * @returns The decoded object or string, or an empty string if decoding fails
10579
10616
  */
10580
- const decode = react.useCallback((str) => {
10581
- try {
10582
- // Try to decode as compressed data first
10583
- try {
10584
- const bytes = b64urlDecode(str);
10585
- const decompressed = fflate.gunzipSync(bytes);
10586
- const json = new TextDecoder().decode(decompressed);
10587
- // Try to parse as JSON first (for objects)
10588
- try {
10589
- return JSON.parse(json);
10590
- }
10591
- catch (_) {
10592
- // If JSON parsing fails, return the string as-is
10593
- return json;
10594
- }
10595
- }
10596
- catch (_) {
10597
- // If compression decoding fails, fall back to regular decoding
10598
- }
10599
- // Fallback: use regular base64 decoding
10600
- const decoded = decodeURIComponent(escape(atob(str)));
10601
- try {
10602
- return JSON.parse(decoded);
10603
- }
10604
- catch (_) {
10605
- // If JSON parsing fails, return the string as-is
10606
- return decoded;
10607
- }
10608
- }
10609
- catch (_) {
10610
- return "";
10611
- }
10612
- }, []);
10617
+ const decode = react.useCallback((str) => decodeCustomValue(str), []);
10613
10618
  return react.useMemo(() => ({ encode, decode }), [encode, decode]);
10614
10619
  };
10615
10620
 
package/index.esm.js CHANGED
@@ -10531,6 +10531,58 @@ const b64urlDecode = (s) => {
10531
10531
  }
10532
10532
  return out;
10533
10533
  };
10534
+ /**
10535
+ * Encode a value with the same gzip + base64url format used by useCustomEncoding.
10536
+ *
10537
+ * @param input - The value to encode.
10538
+ * @returns {string} The compressed URL-safe encoded value, or an empty string on failure.
10539
+ */
10540
+ const encodeCustomValue = (input) => {
10541
+ try {
10542
+ const json = typeof input === "string" ? input : JSON.stringify(input);
10543
+ const textInput = new TextEncoder().encode(json);
10544
+ const compressed = gzipSync(textInput, { mtime: 0 });
10545
+ return b64urlEncode(compressed);
10546
+ }
10547
+ catch (_) {
10548
+ return "";
10549
+ }
10550
+ };
10551
+ /**
10552
+ * Decode a value produced by encodeCustomValue.
10553
+ *
10554
+ * @param str - The compressed URL-safe encoded value.
10555
+ * @returns {object | Array<object> | string} The decoded object/string value, or an empty string on failure.
10556
+ */
10557
+ const decodeCustomValue = (str) => {
10558
+ try {
10559
+ try {
10560
+ const bytes = b64urlDecode(str);
10561
+ const decompressed = gunzipSync(bytes);
10562
+ const json = new TextDecoder().decode(decompressed);
10563
+ try {
10564
+ return JSON.parse(json);
10565
+ }
10566
+ catch (_) {
10567
+ return json;
10568
+ }
10569
+ }
10570
+ catch (_) {
10571
+ // If compression decoding fails, fall back to regular decoding.
10572
+ }
10573
+ const decoded = decodeURIComponent(escape(atob(str)));
10574
+ try {
10575
+ return JSON.parse(decoded);
10576
+ }
10577
+ catch (_) {
10578
+ return decoded;
10579
+ }
10580
+ }
10581
+ catch (_) {
10582
+ return "";
10583
+ }
10584
+ };
10585
+
10534
10586
  /**
10535
10587
  * React hook for safe base64 encoding/decoding with UTF-8 support and compression
10536
10588
  *
@@ -10550,22 +10602,7 @@ const useCustomEncoding = () => {
10550
10602
  * @param input - The object or string to encode
10551
10603
  * @returns The compressed and encoded string
10552
10604
  */
10553
- const encode = useCallback((input) => {
10554
- try {
10555
- // If it's already a string, use it directly; otherwise stringify the object
10556
- const json = typeof input === "string" ? input : JSON.stringify(input);
10557
- const textInput = new TextEncoder().encode(json);
10558
- // Use fflate for synchronous gzip compression.
10559
- // mtime: 0 ensures deterministic output — without it the gzip header
10560
- // includes the current timestamp, making the same input produce a
10561
- // different encoded string on every call.
10562
- const compressed = gzipSync(textInput, { mtime: 0 });
10563
- return b64urlEncode(compressed);
10564
- }
10565
- catch (_) {
10566
- return "";
10567
- }
10568
- }, []);
10605
+ const encode = useCallback((input) => encodeCustomValue(input), []);
10569
10606
  /**
10570
10607
  * Safely decode a compressed and encoded string back to its original form
10571
10608
  *
@@ -10573,41 +10610,9 @@ const useCustomEncoding = () => {
10573
10610
  * and returning the original object or string.
10574
10611
  *
10575
10612
  * @param str - The compressed and encoded string to decode
10576
- * @returns The decoded object or string, or null if decoding fails
10613
+ * @returns The decoded object or string, or an empty string if decoding fails
10577
10614
  */
10578
- const decode = useCallback((str) => {
10579
- try {
10580
- // Try to decode as compressed data first
10581
- try {
10582
- const bytes = b64urlDecode(str);
10583
- const decompressed = gunzipSync(bytes);
10584
- const json = new TextDecoder().decode(decompressed);
10585
- // Try to parse as JSON first (for objects)
10586
- try {
10587
- return JSON.parse(json);
10588
- }
10589
- catch (_) {
10590
- // If JSON parsing fails, return the string as-is
10591
- return json;
10592
- }
10593
- }
10594
- catch (_) {
10595
- // If compression decoding fails, fall back to regular decoding
10596
- }
10597
- // Fallback: use regular base64 decoding
10598
- const decoded = decodeURIComponent(escape(atob(str)));
10599
- try {
10600
- return JSON.parse(decoded);
10601
- }
10602
- catch (_) {
10603
- // If JSON parsing fails, return the string as-is
10604
- return decoded;
10605
- }
10606
- }
10607
- catch (_) {
10608
- return "";
10609
- }
10610
- }, []);
10615
+ const decode = useCallback((str) => decodeCustomValue(str), []);
10611
10616
  return useMemo(() => ({ encode, decode }), [encode, decode]);
10612
10617
  };
10613
10618
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trackunit/react-components",
3
- "version": "2.1.28",
3
+ "version": "2.1.30",
4
4
  "repository": "https://github.com/Trackunit/manager",
5
5
  "license": "SEE LICENSE IN LICENSE.txt",
6
6
  "migrations": "./migrations.json",
@@ -14,17 +14,17 @@
14
14
  "@floating-ui/react": "^0.26.25",
15
15
  "string-ts": "^2.0.0",
16
16
  "tailwind-merge": "^2.0.0",
17
- "@trackunit/ui-design-tokens": "1.13.32",
18
- "@trackunit/css-class-variance-utilities": "1.13.32",
19
- "@trackunit/shared-utils": "1.15.32",
20
- "@trackunit/ui-icons": "1.13.34",
17
+ "@trackunit/ui-design-tokens": "1.13.34",
18
+ "@trackunit/css-class-variance-utilities": "1.13.34",
19
+ "@trackunit/shared-utils": "1.15.34",
20
+ "@trackunit/ui-icons": "1.13.36",
21
21
  "es-toolkit": "^1.39.10",
22
22
  "@tanstack/react-virtual": "3.13.12",
23
23
  "dequal": "^2.0.3",
24
24
  "fflate": "^0.8.2",
25
25
  "superjson": "^2.2.6",
26
26
  "zod": "^3.25.76",
27
- "@trackunit/i18n-library-translation": "2.0.29"
27
+ "@trackunit/i18n-library-translation": "2.0.31"
28
28
  },
29
29
  "peerDependencies": {
30
30
  "react": "^19.0.0",
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Encode a value with the same gzip + base64url format used by useCustomEncoding.
3
+ *
4
+ * @param input - The value to encode.
5
+ * @returns {string} The compressed URL-safe encoded value, or an empty string on failure.
6
+ */
7
+ export declare const encodeCustomValue: (input: string | object | Array<object>) => string;
8
+ /**
9
+ * Decode a value produced by encodeCustomValue.
10
+ *
11
+ * @param str - The compressed URL-safe encoded value.
12
+ * @returns {object | Array<object> | string} The decoded object/string value, or an empty string on failure.
13
+ */
14
+ export declare const decodeCustomValue: (str: string) => object | Array<object> | string;