@fajarmaulana/komerce-lp-helper 0.2.2 → 0.3.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.
@@ -1,25 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __rest = (this && this.__rest) || function (s, e) {
13
- var t = {};
14
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
15
- t[p] = s[p];
16
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
17
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
18
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
19
- t[p[i]] = s[p[i]];
20
- }
21
- return t;
22
- };
23
1
  import { jsx as _jsx } from "react/jsx-runtime";
24
2
  import { useImperativeHandle, useRef } from 'react';
25
3
  /**
@@ -37,19 +15,18 @@ import { useImperativeHandle, useRef } from 'react';
37
15
  * @property {ComponentPropsWithRef<'form'>} - All attribute of form element.
38
16
  * @property {React.ReactNode} [children] - The form’s inner content (inputs, buttons, etc.).
39
17
  */
40
- var Form = function (_a) {
41
- var action = _a.action, ref = _a.ref, children = _a.children, props = __rest(_a, ["action", "ref", "children"]);
42
- var innerRef = useRef(null);
43
- useImperativeHandle(ref, function () { return innerRef.current; });
44
- var handleSubmit = function (e) {
18
+ const Form = ({ action, ref, children, ...props }) => {
19
+ const innerRef = useRef(null);
20
+ useImperativeHandle(ref, () => innerRef.current);
21
+ const handleSubmit = (e) => {
45
22
  e.preventDefault();
46
- var activeEl = document.activeElement;
23
+ const activeEl = document.activeElement;
47
24
  activeEl.blur();
48
25
  if (!innerRef.current)
49
26
  return;
50
- var formData = new FormData(innerRef.current);
27
+ const formData = new FormData(innerRef.current);
51
28
  action(formData);
52
29
  };
53
- return (_jsx("form", __assign({}, props, { ref: innerRef, onSubmit: handleSubmit, children: children })));
30
+ return (_jsx("form", { ...props, ref: innerRef, onSubmit: handleSubmit, children: children }));
54
31
  };
55
32
  export default Form;
@@ -18,9 +18,8 @@ import { useLazyBackground } from './hooks';
18
18
  * The component renders a `<div>` with a `ref` attached for the lazy observer.
19
19
  * The `url` is passed to `useLazyBackground`, which handles loading behavior internally.
20
20
  */
21
- var LazyBackground = function (_a) {
22
- var url = _a.url, children = _a.children, className = _a.className;
23
- var ref = useLazyBackground({ url: url }).ref;
21
+ const LazyBackground = ({ url, children, className }) => {
22
+ const { ref } = useLazyBackground({ url });
24
23
  return (_jsx("div", { ref: ref, className: className || '', children: children }));
25
24
  };
26
25
  export default memo(LazyBackground);
@@ -1,19 +1,3 @@
1
- var __read = (this && this.__read) || function (o, n) {
2
- var m = typeof Symbol === "function" && o[Symbol.iterator];
3
- if (!m) return o;
4
- var i = m.call(o), r, ar = [], e;
5
- try {
6
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
- }
8
- catch (error) { e = { error: error }; }
9
- finally {
10
- try {
11
- if (r && !r.done && (m = i["return"])) m.call(i);
12
- }
13
- finally { if (e) throw e.error; }
14
- }
15
- return ar;
16
- };
17
1
  import { useEffect, useRef } from 'react';
18
2
  /**
19
3
  * `useLazyBackground` is a custom React hook that applies a background image
@@ -21,24 +5,22 @@ import { useEffect, useRef } from 'react';
21
5
  *
22
6
  * @param {TLazyBackground} props - The props object containing the image URL.
23
7
  */
24
- export var useLazyBackground = function (_a) {
25
- var url = _a.url;
26
- var ref = useRef(null);
27
- useEffect(function () {
28
- var el = ref.current;
8
+ export const useLazyBackground = ({ url }) => {
9
+ const ref = useRef(null);
10
+ useEffect(() => {
11
+ const el = ref.current;
29
12
  if (!el)
30
13
  return;
31
- var observer = new IntersectionObserver(function (_a, obs) {
32
- var _b = __read(_a, 1), entry = _b[0];
14
+ const observer = new IntersectionObserver(([entry], obs) => {
33
15
  if (entry.isIntersecting) {
34
- el.style.backgroundImage = "url(".concat(url, ")");
16
+ el.style.backgroundImage = `url(${url})`;
35
17
  obs.unobserve(el);
36
18
  }
37
19
  });
38
20
  observer.observe(el);
39
- return function () { return observer.disconnect(); };
21
+ return () => observer.disconnect();
40
22
  }, [url]);
41
23
  return {
42
- ref: ref,
24
+ ref,
43
25
  };
44
26
  };
@@ -1 +1 @@
1
- export var MOBILE_BOUND = 640;
1
+ export const MOBILE_BOUND = 640;
@@ -1,40 +1,40 @@
1
- export var VALID_EMAIL = {
1
+ export const VALID_EMAIL = {
2
2
  re: /^(?![.])[A-Za-z0-9._-]+(?<![.])@[A-Za-z0-9-]+(\.[A-Za-z0-9-]+)*\.[A-Za-z]{2,4}$/,
3
3
  text: 'masukkan email yang valid',
4
4
  };
5
- export var DOTALPHANUM = {
5
+ export const DOTALPHANUM = {
6
6
  re: /^[a-zA-Z0-9._-]+$/,
7
7
  text: " hanya boleh berisi huruf, angka, '.', '_' atau '-'",
8
8
  };
9
- export var REPEATED_DOT = {
9
+ export const REPEATED_DOT = {
10
10
  re: /(\.\.|__|--)/,
11
11
  text: ' tidak boleh berisi simbol berulang',
12
12
  };
13
- export var NUMBER_ONLY = {
13
+ export const NUMBER_ONLY = {
14
14
  re: /[^\d]/,
15
15
  text: ' hanya boleh berisi angka',
16
16
  };
17
- export var ALPHASPACE = {
17
+ export const ALPHASPACE = {
18
18
  re: /^[A-Za-z]+(?: [A-Za-z]+)*$/,
19
19
  text: ' hanya boleh berisi huruf dan spasi antar kata',
20
20
  };
21
- export var ANY_UPPERCASE = {
21
+ export const ANY_UPPERCASE = {
22
22
  re: /[A-Z]/,
23
23
  text: ' harus berisi minimal 1 huruf kapital',
24
24
  };
25
- export var ANY_LOWERCASE = {
25
+ export const ANY_LOWERCASE = {
26
26
  re: /[a-z]/,
27
27
  text: ' harus berisi minimal 1 huruf kecil',
28
28
  };
29
- export var ANY_NUMBER = {
29
+ export const ANY_NUMBER = {
30
30
  re: /\d/,
31
31
  text: ' harus berisi minimal 1 angka',
32
32
  };
33
- export var ANY_SYMBOL = {
33
+ export const ANY_SYMBOL = {
34
34
  re: /[\W+_]/,
35
35
  text: ' harus berisi minimal 1 simbol',
36
36
  };
37
- export var NO_SPACE = {
37
+ export const NO_SPACE = {
38
38
  re: /^\S+$/,
39
39
  text: ' tidak boleh berisi spasi',
40
40
  };
@@ -1,28 +1,3 @@
1
- var __read = (this && this.__read) || function (o, n) {
2
- var m = typeof Symbol === "function" && o[Symbol.iterator];
3
- if (!m) return o;
4
- var i = m.call(o), r, ar = [], e;
5
- try {
6
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
- }
8
- catch (error) { e = { error: error }; }
9
- finally {
10
- try {
11
- if (r && !r.done && (m = i["return"])) m.call(i);
12
- }
13
- finally { if (e) throw e.error; }
14
- }
15
- return ar;
16
- };
17
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
18
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
19
- if (ar || !(i in from)) {
20
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
21
- ar[i] = from[i];
22
- }
23
- }
24
- return to.concat(ar || Array.prototype.slice.call(from));
25
- };
26
1
  /* eslint-disable @typescript-eslint/no-explicit-any */
27
2
  import { useCallback, useEffect, useRef, useState } from 'react';
28
3
  /**
@@ -40,14 +15,13 @@ import { useCallback, useEffect, useRef, useState } from 'react';
40
15
  * @example
41
16
  * const debouncedSearchTerm = useDebounce(searchTerm, 500);
42
17
  */
43
- export function useDebounce(value, delay) {
44
- if (delay === void 0) { delay = 500; }
45
- var _a = __read(useState(value), 2), debouncedValue = _a[0], setDebouncedValue = _a[1];
46
- useEffect(function () {
47
- var handler = setTimeout(function () {
18
+ export function useDebounce(value, delay = 500) {
19
+ const [debouncedValue, setDebouncedValue] = useState(value);
20
+ useEffect(() => {
21
+ const handler = setTimeout(() => {
48
22
  setDebouncedValue(value);
49
23
  }, delay);
50
- return function () {
24
+ return () => {
51
25
  clearTimeout(handler);
52
26
  };
53
27
  }, [value, delay]);
@@ -68,21 +42,17 @@ export function useDebounce(value, delay) {
68
42
  * debouncedSearch('hello'); // Will wait 300ms before calling fetchResults
69
43
  */
70
44
  export function useDebounceFunc(callback, delay) {
71
- var timerRef = useRef(null);
72
- var debouncedFunction = function () {
73
- var args = [];
74
- for (var _i = 0; _i < arguments.length; _i++) {
75
- args[_i] = arguments[_i];
76
- }
45
+ const timerRef = useRef(null);
46
+ const debouncedFunction = (...args) => {
77
47
  if (timerRef.current) {
78
48
  clearTimeout(timerRef.current);
79
49
  }
80
- timerRef.current = setTimeout(function () {
81
- callback.apply(void 0, __spreadArray([], __read(args), false));
50
+ timerRef.current = setTimeout(() => {
51
+ callback(...args);
82
52
  }, delay);
83
53
  };
84
- useEffect(function () {
85
- return function () {
54
+ useEffect(() => {
55
+ return () => {
86
56
  if (timerRef.current) {
87
57
  clearTimeout(timerRef.current);
88
58
  }
@@ -98,18 +68,17 @@ export function useDebounceFunc(callback, delay) {
98
68
  *
99
69
  * @param {number} [delay=500] - The debounce delay in milliseconds before executing the callback.
100
70
  */
101
- export function useConditionalDebounce(delay) {
102
- if (delay === void 0) { delay = 500; }
103
- var timeoutRef = useRef(null);
104
- var run = useCallback(function (condition, callback) {
71
+ export function useConditionalDebounce(delay = 500) {
72
+ const timeoutRef = useRef(null);
73
+ const run = useCallback((condition, callback) => {
105
74
  if (timeoutRef.current)
106
75
  clearTimeout(timeoutRef.current);
107
76
  if (!condition)
108
77
  return;
109
78
  timeoutRef.current = window.setTimeout(callback, delay);
110
79
  }, [delay]);
111
- useEffect(function () {
112
- return function () {
80
+ useEffect(() => {
81
+ return () => {
113
82
  if (timeoutRef.current)
114
83
  clearTimeout(timeoutRef.current);
115
84
  };
@@ -1,30 +1,3 @@
1
- var __values = (this && this.__values) || function(o) {
2
- var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
- if (m) return m.call(o);
4
- if (o && typeof o.length === "number") return {
5
- next: function () {
6
- if (o && i >= o.length) o = void 0;
7
- return { value: o && o[i++], done: !o };
8
- }
9
- };
10
- throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
11
- };
12
- var __read = (this && this.__read) || function (o, n) {
13
- var m = typeof Symbol === "function" && o[Symbol.iterator];
14
- if (!m) return o;
15
- var i = m.call(o), r, ar = [], e;
16
- try {
17
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
- }
19
- catch (error) { e = { error: error }; }
20
- finally {
21
- try {
22
- if (r && !r.done && (m = i["return"])) m.call(i);
23
- }
24
- finally { if (e) throw e.error; }
25
- }
26
- return ar;
27
- };
28
1
  import { useRef } from 'react';
29
2
  import { getById } from '../utils/general';
30
3
  /**
@@ -41,54 +14,42 @@ import { getById } from '../utils/general';
41
14
  *
42
15
  * @param {string[]} [fieldsWithoutNameIds=[]] - A list of field IDs that exist outside the form element.
43
16
  */
44
- export function useForm(fieldsWithoutNameIds) {
45
- if (fieldsWithoutNameIds === void 0) { fieldsWithoutNameIds = []; }
46
- var form = useRef(null);
47
- var fields = function () {
48
- var e_1, _a;
49
- var result = {};
17
+ export function useForm(fieldsWithoutNameIds = []) {
18
+ const form = useRef(null);
19
+ const fields = () => {
20
+ const result = {};
50
21
  if (!form.current)
51
22
  return result;
52
- var formData = new FormData(form.current);
53
- try {
54
- for (var _b = __values(formData.entries()), _c = _b.next(); !_c.done; _c = _b.next()) {
55
- var _d = __read(_c.value, 2), name_1 = _d[0], value = _d[1];
56
- var key = name_1;
57
- var input = form.current.querySelector("[name=\"".concat(key, "\"]"));
58
- var fieldValue = value;
59
- if ((input === null || input === void 0 ? void 0 : input.type) === 'checkbox')
60
- fieldValue = input.checked;
61
- result[key] = {
62
- field_value: fieldValue,
63
- field_id: (input === null || input === void 0 ? void 0 : input.id) || '',
64
- field_error: form.current.querySelector("#".concat(key, "_error")),
65
- field_info: form.current.querySelector("#".concat(key, "_info")),
66
- };
67
- }
68
- }
69
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
70
- finally {
71
- try {
72
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
73
- }
74
- finally { if (e_1) throw e_1.error; }
23
+ const formData = new FormData(form.current);
24
+ for (const [name, value] of formData.entries()) {
25
+ const key = name;
26
+ const input = form.current.querySelector(`[name="${key}"]`);
27
+ let fieldValue = value;
28
+ if (input?.type === 'checkbox')
29
+ fieldValue = input.checked;
30
+ result[key] = {
31
+ field_value: fieldValue,
32
+ field_id: input?.id || '',
33
+ field_error: form.current.querySelector(`#${key}_error`),
34
+ field_info: form.current.querySelector(`#${key}_info`),
35
+ };
75
36
  }
76
37
  return result;
77
38
  };
78
- var fieldsWithoutName = function () {
79
- var result = {};
80
- fieldsWithoutNameIds.forEach(function (id) {
81
- var field = getById(id);
82
- var key = id;
83
- var value = field.type === 'radio' || field.type === 'checkbox' ? field.checked : field.value;
39
+ const fieldsWithoutName = () => {
40
+ const result = {};
41
+ fieldsWithoutNameIds.forEach(id => {
42
+ const field = getById(id);
43
+ const key = id;
44
+ const value = field.type === 'radio' || field.type === 'checkbox' ? field.checked : field.value;
84
45
  result[key] = {
85
46
  field_value: value,
86
47
  field_id: field.id,
87
- field_error: getById("".concat(key, "_error")),
88
- field_info: getById("".concat(key, "_info")),
48
+ field_error: getById(`${key}_error`),
49
+ field_info: getById(`${key}_info`),
89
50
  };
90
51
  });
91
52
  return result;
92
53
  };
93
- return { form: form, fields: fields, fieldsWithoutName: fieldsWithoutName };
54
+ return { form, fields, fieldsWithoutName };
94
55
  }
@@ -1,39 +1,3 @@
1
- var __assign = (this && this.__assign) || function () {
2
- __assign = Object.assign || function(t) {
3
- for (var s, i = 1, n = arguments.length; i < n; i++) {
4
- s = arguments[i];
5
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
- t[p] = s[p];
7
- }
8
- return t;
9
- };
10
- return __assign.apply(this, arguments);
11
- };
12
- var __read = (this && this.__read) || function (o, n) {
13
- var m = typeof Symbol === "function" && o[Symbol.iterator];
14
- if (!m) return o;
15
- var i = m.call(o), r, ar = [], e;
16
- try {
17
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
18
- }
19
- catch (error) { e = { error: error }; }
20
- finally {
21
- try {
22
- if (r && !r.done && (m = i["return"])) m.call(i);
23
- }
24
- finally { if (e) throw e.error; }
25
- }
26
- return ar;
27
- };
28
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
29
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
30
- if (ar || !(i in from)) {
31
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
32
- ar[i] = from[i];
33
- }
34
- }
35
- return to.concat(ar || Array.prototype.slice.call(from));
36
- };
37
1
  import { useCallback, useMemo } from 'react';
38
2
  import { useLocation, useNavigate, useParams, useSearchParams } from 'react-router-dom';
39
3
  /**
@@ -42,16 +6,17 @@ import { useLocation, useNavigate, useParams, useSearchParams } from 'react-rout
42
6
  * @returns An object implementing the {@link TUseRouter} interface
43
7
  */
44
8
  export function useRouter() {
45
- var navigate = useNavigate();
46
- var location = useLocation();
47
- var params = useParams();
48
- var _a = __read(useSearchParams(), 1), searchParams = _a[0];
49
- var query = useMemo(function () {
50
- var queryObj = {};
51
- searchParams.forEach(function (value, key) {
9
+ const navigate = useNavigate();
10
+ const location = useLocation();
11
+ const params = useParams();
12
+ const [searchParams] = useSearchParams();
13
+ const query = useMemo(() => {
14
+ const queryObj = {};
15
+ searchParams.forEach((value, key) => {
52
16
  if (queryObj[key]) {
53
17
  queryObj[key] = Array.isArray(queryObj[key])
54
- ? __spreadArray(__spreadArray([], __read(queryObj[key]), false), [value], false) : [queryObj[key], value];
18
+ ? [...queryObj[key], value]
19
+ : [queryObj[key], value];
55
20
  }
56
21
  else {
57
22
  queryObj[key] = value;
@@ -59,81 +24,77 @@ export function useRouter() {
59
24
  });
60
25
  return queryObj;
61
26
  }, [searchParams]);
62
- var push = useCallback(function (url, options) {
27
+ const push = useCallback((url, options) => {
63
28
  if (typeof url === 'string') {
64
29
  navigate(url, options);
65
30
  }
66
31
  else {
67
- var queryString = url.query
32
+ const queryString = url.query
68
33
  ? '?' +
69
- new URLSearchParams(Object.entries(url.query).map(function (_a) {
70
- var _b = __read(_a, 2), k = _b[0], v = _b[1];
71
- return [k, Array.isArray(v) ? v.join(',') : v];
72
- })).toString()
34
+ new URLSearchParams(Object.entries(url.query).map(([k, v]) => [k, Array.isArray(v) ? v.join(',') : v])).toString()
73
35
  : '';
74
- var hash = url.hash ? (url.hash.startsWith('#') ? url.hash : "#".concat(url.hash)) : '';
75
- navigate("".concat(url.pathname).concat(queryString).concat(hash), options);
36
+ const hash = url.hash ? (url.hash.startsWith('#') ? url.hash : `#${url.hash}`) : '';
37
+ navigate(`${url.pathname}${queryString}${hash}`, options);
76
38
  }
77
39
  }, [navigate]);
78
- var route = useCallback(function (pathname, query, options) {
79
- var searchParams = new URLSearchParams();
40
+ const route = useCallback((pathname, query, options) => {
41
+ const searchParams = new URLSearchParams();
80
42
  if (query) {
81
- Object.entries(query).forEach(function (_a) {
82
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
43
+ Object.entries(query).forEach(([key, value]) => {
83
44
  if (Array.isArray(value)) {
84
- value.forEach(function (v) { return searchParams.append(key, v); });
45
+ value.forEach(v => searchParams.append(key, v));
85
46
  }
86
47
  else {
87
48
  searchParams.set(key, value);
88
49
  }
89
50
  });
90
51
  }
91
- var search = searchParams.toString();
92
- var fullPath = search ? "".concat(pathname, "?").concat(search) : pathname;
52
+ const search = searchParams.toString();
53
+ const fullPath = search ? `${pathname}?${search}` : pathname;
93
54
  navigate(fullPath, options);
94
55
  }, [navigate]);
95
- var replace = useCallback(function (url, options) {
96
- var replaceOptions = __assign(__assign({}, options), { replace: true });
56
+ const replace = useCallback((url, options) => {
57
+ const replaceOptions = { ...options, replace: true };
97
58
  push(url, replaceOptions);
98
59
  }, [push]);
99
- var back = useCallback(function () {
60
+ const back = useCallback(() => {
100
61
  navigate(-1);
101
62
  }, [navigate]);
102
- var next = useCallback(function () {
63
+ const next = useCallback(() => {
103
64
  navigate(1);
104
65
  }, [navigate]);
105
- var go = useCallback(function (num) {
66
+ const go = useCallback((num) => {
106
67
  navigate(num);
107
68
  }, [navigate]);
108
- var refresh = useCallback(function () {
69
+ const refresh = useCallback(() => {
109
70
  window.location.reload();
110
71
  }, []);
111
- var beforePopState = useCallback(function (cb) {
112
- var handlePopState = function (event) {
72
+ const beforePopState = useCallback((cb) => {
73
+ const handlePopState = (event) => {
113
74
  if (!cb(event.state)) {
114
75
  event.preventDefault();
115
76
  window.history.pushState(location.state, '', location.pathname + location.search);
116
77
  }
117
78
  };
118
79
  window.addEventListener('popstate', handlePopState);
119
- return function () { return window.removeEventListener('popstate', handlePopState); };
80
+ return () => window.removeEventListener('popstate', handlePopState);
120
81
  }, [location]);
121
82
  return {
122
- push: push,
123
- route: route,
124
- replace: replace,
125
- back: back,
126
- next: next,
127
- go: go,
128
- refresh: refresh,
83
+ push,
84
+ route,
85
+ replace,
86
+ back,
87
+ next,
88
+ go,
89
+ refresh,
129
90
  path: location.pathname,
130
91
  hash: location.hash,
131
- fullpath: "".concat(location.pathname).concat(location.search).concat(location.hash),
92
+ fullpath: `${location.pathname}${location.search}${location.hash}`,
132
93
  origin: window.location.origin,
133
94
  href: window.location.href,
134
- query: query,
135
- params: params,
136
- beforePopState: beforePopState,
95
+ query,
96
+ params,
97
+ beforePopState,
137
98
  };
138
99
  }
139
100
  /**
@@ -147,11 +108,11 @@ export function useRouter() {
147
108
  * - `updateQuery`: A function to update query parameters
148
109
  */
149
110
  export function useQueryParams(defaultValues) {
150
- var _a = __read(useSearchParams(), 2), searchParams = _a[0], setSearchParams = _a[1];
151
- var queryObj = useMemo(function () {
152
- var result = __assign({}, defaultValues);
153
- searchParams.forEach(function (value, key) {
154
- var allValues = searchParams.getAll(key);
111
+ const [searchParams, setSearchParams] = useSearchParams();
112
+ const queryObj = useMemo(() => {
113
+ const result = { ...defaultValues };
114
+ searchParams.forEach((value, key) => {
115
+ const allValues = searchParams.getAll(key);
155
116
  if (allValues.length > 1) {
156
117
  result[key] = allValues;
157
118
  }
@@ -161,16 +122,15 @@ export function useQueryParams(defaultValues) {
161
122
  });
162
123
  return result;
163
124
  }, [searchParams, defaultValues]);
164
- var updateQuery = useCallback(function (updates) {
165
- var newParams = new URLSearchParams(searchParams);
166
- Object.entries(updates).forEach(function (_a) {
167
- var _b = __read(_a, 2), key = _b[0], value = _b[1];
125
+ const updateQuery = useCallback((updates) => {
126
+ const newParams = new URLSearchParams(searchParams);
127
+ Object.entries(updates).forEach(([key, value]) => {
168
128
  if (value === undefined || value === null) {
169
129
  newParams.delete(key);
170
130
  }
171
131
  else if (Array.isArray(value)) {
172
132
  newParams.delete(key);
173
- value.forEach(function (v) { return newParams.append(key, v); });
133
+ value.forEach(v => newParams.append(key, v));
174
134
  }
175
135
  else {
176
136
  newParams.set(key, value);
@@ -1,30 +1,12 @@
1
- var __read = (this && this.__read) || function (o, n) {
2
- var m = typeof Symbol === "function" && o[Symbol.iterator];
3
- if (!m) return o;
4
- var i = m.call(o), r, ar = [], e;
5
- try {
6
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
7
- }
8
- catch (error) { e = { error: error }; }
9
- finally {
10
- try {
11
- if (r && !r.done && (m = i["return"])) m.call(i);
12
- }
13
- finally { if (e) throw e.error; }
14
- }
15
- return ar;
16
- };
17
1
  import { useEffect } from 'react';
18
2
  import { getById } from '../utils/general';
19
- export var useSectionObserver = function (_a) {
20
- var triggerRef = _a.triggerRef, targetId = _a.targetId, _b = _a.threshold, threshold = _b === void 0 ? 0.8 : _b;
21
- useEffect(function () {
22
- var container = getById(targetId);
23
- var trigger = triggerRef.current;
3
+ export const useSectionObserver = ({ triggerRef, targetId, threshold = 0.8 }) => {
4
+ useEffect(() => {
5
+ const container = getById(targetId);
6
+ const trigger = triggerRef.current;
24
7
  if (!trigger || !container)
25
8
  return;
26
- var observer = new IntersectionObserver(function (_a) {
27
- var _b = __read(_a, 1), entry = _b[0];
9
+ const observer = new IntersectionObserver(([entry]) => {
28
10
  if (entry.isIntersecting) {
29
11
  container.setAttribute('data-visible', 'true');
30
12
  return;
@@ -32,9 +14,9 @@ export var useSectionObserver = function (_a) {
32
14
  if (entry.boundingClientRect.top > 0) {
33
15
  container.setAttribute('data-visible', 'false');
34
16
  }
35
- }, { threshold: threshold });
17
+ }, { threshold });
36
18
  observer.observe(trigger);
37
- return function () {
19
+ return () => {
38
20
  observer.disconnect();
39
21
  };
40
22
  }, [triggerRef, targetId, threshold]);