@cripty2001/utils 0.0.260 → 0.0.262

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/index.js CHANGED
@@ -1,37 +1,7 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.CURRENT_TS_MS = exports.GetenvHandledError = void 0;
4
- exports.randomBelow = randomBelow;
5
- exports.getRandom = getRandom;
6
- exports.getRandomId = getRandomId;
7
- exports.getRandomOtp = getRandomOtp;
8
- exports.sleep = sleep;
9
- exports.parseHash = parseHash;
10
- exports.loop = loop;
11
- exports.isEqual = isEqual;
12
- exports.arrayStep = arrayStep;
13
- exports.copyToClipboard = copyToClipboard;
14
- exports.download = download;
15
- exports.stableLog = stableLog;
16
- exports.parseQuery = parseQuery;
17
- exports.randBetween = randBetween;
18
- exports.getEnv = getEnv;
19
- exports.getEnvString = getEnvString;
20
- exports.getEnvInt = getEnvInt;
21
- exports.getEnvJson = getEnvJson;
22
- exports.getClock = getClock;
23
- exports.timediff2HumanReadable = timediff2HumanReadable;
24
- exports.fn2promise = fn2promise;
25
- exports.safeApply = safeApply;
26
- exports.timesafeEqual = timesafeEqual;
27
- exports.buildDigest = buildDigest;
28
- exports.checkDigest = checkDigest;
29
- exports.enforceDigest = enforceDigest;
30
- exports.isDigest = isDigest;
31
- const whispr_1 = require("@cripty2001/whispr");
32
- const value_1 = require("@sinclair/typebox/value");
33
- const crypto_1 = require("crypto");
34
- const lodash_1 = require("lodash");
1
+ import { Whispr } from "@cripty2001/whispr";
2
+ import { Value } from "@sinclair/typebox/value";
3
+ import { timingSafeEqual } from "crypto";
4
+ import isEqualWith from "lodash/isEqualWith.js";
35
5
  const U32_LIMIT = 0x1_0000_0000;
36
6
  function randomU32() {
37
7
  const buf = new Uint32Array(1);
@@ -44,7 +14,7 @@ function randomU32() {
44
14
  * @returns A random number between 0 and `maxExclusive - 1`
45
15
  * @throws If `maxExclusive` is less than 1 or greater than 2^32
46
16
  */
47
- function randomBelow(maxExclusive) {
17
+ export function randomBelow(maxExclusive) {
48
18
  const n = Math.floor(maxExclusive);
49
19
  if (n < 1)
50
20
  throw new RangeError(`randomBelow span must be at least 1: ${n}`);
@@ -62,7 +32,7 @@ function randomBelow(maxExclusive) {
62
32
  * @param length The length of the string to generate
63
33
  * @returns The generated string
64
34
  */
65
- function getRandom(_alphabeth, length) {
35
+ export function getRandom(_alphabeth, length) {
66
36
  const alphabeth = _alphabeth.split("");
67
37
  const toReturn = [];
68
38
  while (toReturn.length < length) {
@@ -75,7 +45,7 @@ function getRandom(_alphabeth, length) {
75
45
  * @param length The length of the id to generate
76
46
  * @returns The generated id
77
47
  */
78
- function getRandomId(length = 20) {
48
+ export function getRandomId(length = 20) {
79
49
  const ALPHABET = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-_";
80
50
  return getRandom(ALPHABET, length);
81
51
  }
@@ -85,7 +55,7 @@ function getRandomId(length = 20) {
85
55
  * @param char Allow for characters to be inserted in the otp
86
56
  * @returns The generated otp
87
57
  */
88
- function getRandomOtp(length = 6, char = false) {
58
+ export function getRandomOtp(length = 6, char = false) {
89
59
  const ALPHABET = "0123456789" + (char ? "ABCDEFGHIJKLMNOPQRSTUVWXYZ" : "");
90
60
  return getRandom(ALPHABET, length);
91
61
  }
@@ -93,10 +63,10 @@ function getRandomOtp(length = 6, char = false) {
93
63
  * Pause the execution for the given number of milliseconds.
94
64
  * @param ms The number of milliseconds to sleep
95
65
  */
96
- function sleep(ms) {
66
+ export function sleep(ms) {
97
67
  return new Promise((resolve) => setTimeout(resolve, ms));
98
68
  }
99
- function parseHash(fields, deleteFields = false) {
69
+ export function parseHash(fields, deleteFields = false) {
100
70
  // Checking empty hash
101
71
  if (window.location.hash === "")
102
72
  return new URLSearchParams();
@@ -126,7 +96,7 @@ function parseHash(fields, deleteFields = false) {
126
96
  * @param interval The minimum interval between two executions, in milliseconds. The execution may be scheduled later, but not earlier.
127
97
  * @param onError The error callback. Return true to stop the loop.
128
98
  */
129
- async function loop(cb, interval, onError = async (e) => { console.error(e); return false; }) {
99
+ export async function loop(cb, interval, onError = async (e) => { console.error(e); return false; }) {
130
100
  while (true) {
131
101
  try {
132
102
  await cb();
@@ -148,16 +118,16 @@ async function loop(cb, interval, onError = async (e) => { console.error(e); ret
148
118
  /**
149
119
  * Float aware deep equality check between two values.
150
120
  */
151
- function isEqual(a, b) {
121
+ export function isEqual(a, b) {
152
122
  const TOLERANCE = 1e-9;
153
- const toReturn = (0, lodash_1.isEqualWith)(a, b, (a, b) => {
123
+ const toReturn = isEqualWith(a, b, (a, b) => {
154
124
  if (typeof a === 'number' && typeof b === 'number')
155
125
  return Math.abs(a - b) < TOLERANCE;
156
126
  return undefined;
157
127
  });
158
128
  return toReturn;
159
129
  }
160
- function arrayStep(from, to, step) {
130
+ export function arrayStep(from, to, step) {
161
131
  const result = [];
162
132
  for (let i = from; i <= to; i += step) {
163
133
  result.push(i);
@@ -168,7 +138,7 @@ function arrayStep(from, to, step) {
168
138
  * Copy the given text to clipboard.
169
139
  * @param text The text to copy to clipboard
170
140
  */
171
- function copyToClipboard(text) {
141
+ export function copyToClipboard(text) {
172
142
  navigator.clipboard.writeText(text);
173
143
  }
174
144
  /**
@@ -177,7 +147,7 @@ function copyToClipboard(text) {
177
147
  * @param filename The filename to use
178
148
  * @param mimeType The mime type of the data
179
149
  */
180
- function download(data, filename, mimeType = 'application/octet-stream') {
150
+ export function download(data, filename, mimeType = 'application/octet-stream') {
181
151
  const blob = data instanceof Blob ? data : new Blob([data], { type: mimeType });
182
152
  const url = URL.createObjectURL(blob);
183
153
  const a = document.createElement('a');
@@ -188,10 +158,10 @@ function download(data, filename, mimeType = 'application/octet-stream') {
188
158
  document.body.removeChild(a);
189
159
  URL.revokeObjectURL(url);
190
160
  }
191
- function stableLog(obj, message = '') {
161
+ export function stableLog(obj, message = '') {
192
162
  console.log(message, JSON.parse(JSON.stringify(obj)));
193
163
  }
194
- function parseQuery(query, fields) {
164
+ export function parseQuery(query, fields) {
195
165
  const data = (() => {
196
166
  if (typeof query === 'string') {
197
167
  return new URLSearchParams(query);
@@ -228,18 +198,17 @@ function parseQuery(query, fields) {
228
198
  * @returns The generated random int
229
199
  * @throws If `max - min + 1` is greater than 2^32
230
200
  */
231
- function randBetween(min, max) {
201
+ export function randBetween(min, max) {
232
202
  const span = max - min + 1;
233
203
  if (span <= 1)
234
204
  return min;
235
205
  return min + randomBelow(span);
236
206
  }
237
- class GetenvHandledError extends Error {
207
+ export class GetenvHandledError extends Error {
238
208
  constructor(message) {
239
209
  super(message);
240
210
  }
241
211
  }
242
- exports.GetenvHandledError = GetenvHandledError;
243
212
  /**
244
213
  * Get an environment variable, convert it using the given converter function.
245
214
  * If the environment variable is not defined, the default value is used.
@@ -254,7 +223,7 @@ exports.GetenvHandledError = GetenvHandledError;
254
223
  * @throws If the environment variable is not defined and no default value is provided
255
224
  * @throws If the conversion throws an error
256
225
  */
257
- function getEnv(key, defaultValue, converter = (s) => s) {
226
+ export function getEnv(key, defaultValue, converter = (s) => s) {
258
227
  const value = process.env[key];
259
228
  if (value === undefined) {
260
229
  if (defaultValue === undefined)
@@ -278,7 +247,7 @@ function getEnv(key, defaultValue, converter = (s) => s) {
278
247
  *
279
248
  * @param allowEmpty Whether to allow empty strings
280
249
  */
281
- function getEnvString(key, allowEmpty = false, defaultValue) {
250
+ export function getEnvString(key, allowEmpty = false, defaultValue) {
282
251
  return getEnv(key, defaultValue, (s) => {
283
252
  if (s === "" && !allowEmpty)
284
253
  throw new GetenvHandledError(`Empty string.`);
@@ -292,7 +261,7 @@ function getEnvString(key, allowEmpty = false, defaultValue) {
292
261
  *
293
262
  * Note: the default value is not used instead of an invalid integer. An invalid integer therefore throws an error.
294
263
  */
295
- function getEnvInt(key, constraints = {}, defaultValue) {
264
+ export function getEnvInt(key, constraints = {}, defaultValue) {
296
265
  return getEnv(key, defaultValue, (s) => {
297
266
  if (!/^[+-]?\d+$/.test(s))
298
267
  throw new GetenvHandledError(`Invalid integer.`);
@@ -308,7 +277,7 @@ function getEnvInt(key, constraints = {}, defaultValue) {
308
277
  return parsed;
309
278
  });
310
279
  }
311
- function getEnvJson(key, defaultValue, schema) {
280
+ export function getEnvJson(key, defaultValue, schema) {
312
281
  return getEnv(key, defaultValue, (s) => {
313
282
  const parsed = (() => {
314
283
  try {
@@ -320,12 +289,12 @@ function getEnvJson(key, defaultValue, schema) {
320
289
  })();
321
290
  if (schema === undefined)
322
291
  return parsed;
323
- return value_1.Value.Parse(schema, parsed);
292
+ return Value.Parse(schema, parsed);
324
293
  });
325
294
  }
326
- const [currentTsMs, setCurrentTsMs] = whispr_1.Whispr.create(Date.now());
295
+ const [currentTsMs, setCurrentTsMs] = Whispr.create(Date.now());
327
296
  let currentTsMsInterval = null;
328
- const CURRENT_TS_MS = () => {
297
+ export const CURRENT_TS_MS = () => {
329
298
  if (currentTsMsInterval === null) {
330
299
  currentTsMsInterval = setInterval(() => {
331
300
  setCurrentTsMs(Date.now());
@@ -333,11 +302,10 @@ const CURRENT_TS_MS = () => {
333
302
  }
334
303
  return currentTsMs;
335
304
  };
336
- exports.CURRENT_TS_MS = CURRENT_TS_MS;
337
- function getClock(rate) {
338
- return (0, exports.CURRENT_TS_MS)().transform((curr) => Math.floor(curr / rate));
305
+ export function getClock(rate) {
306
+ return CURRENT_TS_MS().transform((curr) => Math.floor(curr / rate));
339
307
  }
340
- function timediff2HumanReadable(diffMs) {
308
+ export function timediff2HumanReadable(diffMs) {
341
309
  const { unit, diff } = (() => {
342
310
  let toReturn = diffMs;
343
311
  const OPTIONS = [
@@ -363,25 +331,25 @@ function timediff2HumanReadable(diffMs) {
363
331
  const rtf = new Intl.RelativeTimeFormat();
364
332
  return rtf.format(Math.round(diff), unit);
365
333
  }
366
- function fn2promise(fn) {
334
+ export function fn2promise(fn) {
367
335
  const result = fn();
368
336
  return result instanceof Promise ?
369
337
  result :
370
338
  Promise.resolve(result);
371
339
  }
372
- function safeApply(updater, incoming) {
340
+ export function safeApply(updater, incoming) {
373
341
  const cloned = structuredClone(incoming);
374
342
  const new_data = updater(cloned);
375
343
  const chosen = new_data ?? cloned;
376
344
  return structuredClone(chosen);
377
345
  }
378
- function timesafeEqual(a, b) {
346
+ export function timesafeEqual(a, b) {
379
347
  if (a.length !== b.length)
380
348
  return false;
381
- return (0, crypto_1.timingSafeEqual)(Buffer.from(a), Buffer.from(b));
349
+ return timingSafeEqual(Buffer.from(a), Buffer.from(b));
382
350
  }
383
351
  const DIGEST_PREFIX = 'sha256.base64url.';
384
- async function buildDigest(data) {
352
+ export async function buildDigest(data) {
385
353
  const encoded = typeof data === "string" ?
386
354
  new TextEncoder().encode(data) :
387
355
  data;
@@ -392,16 +360,16 @@ async function buildDigest(data) {
392
360
  });
393
361
  return `${DIGEST_PREFIX}${b64url}`;
394
362
  }
395
- async function checkDigest(data, digest) {
363
+ export async function checkDigest(data, digest) {
396
364
  if (!digest.startsWith(DIGEST_PREFIX))
397
365
  throw new Error(`The digest was not generated with digest() function.`);
398
366
  const dataDigest = await buildDigest(data);
399
367
  return timesafeEqual(dataDigest, digest);
400
368
  }
401
- async function enforceDigest(data, digest) {
369
+ export async function enforceDigest(data, digest) {
402
370
  if (!(await checkDigest(data, digest)))
403
371
  throw new Error(`The digest does not match the data.`);
404
372
  }
405
- function isDigest(digest) {
373
+ export function isDigest(digest) {
406
374
  return digest.startsWith(DIGEST_PREFIX) && digest.length === DIGEST_PREFIX.length + 43;
407
375
  }
@@ -1 +1 @@
1
- export { LoggerReactDisplay, type LoggerReactDisplayProps } from './logger-display';
1
+ export { LoggerReactDisplay, type LoggerReactDisplayProps } from './logger-display.js';
@@ -1,5 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.LoggerReactDisplay = void 0;
4
- var logger_display_1 = require("./logger-display");
5
- Object.defineProperty(exports, "LoggerReactDisplay", { enumerable: true, get: function () { return logger_display_1.LoggerReactDisplay; } });
1
+ export { LoggerReactDisplay } from './logger-display.js';
@@ -1,34 +1,28 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.LoggerReactDisplay = LoggerReactDisplay;
7
- const jsx_runtime_1 = require("react/jsx-runtime");
8
- const lucide_react_1 = require("lucide-react");
9
- const Logger_1 = __importDefault(require("../Logger/Logger"));
10
- const react_whispr_1 = require("../react-whispr");
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { AlertCircle, CheckCircle2, Info, TriangleAlert, X } from "lucide-react";
3
+ import logger from "../Logger/Logger.js";
4
+ import { useWhisprValue } from "../react-whispr.js";
11
5
  const SEVERITY_STYLES = {
12
6
  error: {
13
- icon: lucide_react_1.AlertCircle,
7
+ icon: AlertCircle,
14
8
  container: "border-red-200 bg-red-50 dark:border-red-900/50 dark:bg-red-950/40",
15
9
  iconClass: "text-red-600 dark:text-red-400",
16
10
  textClass: "text-red-800 dark:text-red-200",
17
11
  },
18
12
  warning: {
19
- icon: lucide_react_1.TriangleAlert,
13
+ icon: TriangleAlert,
20
14
  container: "border-amber-200 bg-amber-50 dark:border-amber-900/50 dark:bg-amber-950/40",
21
15
  iconClass: "text-amber-600 dark:text-amber-400",
22
16
  textClass: "text-amber-900 dark:text-amber-200",
23
17
  },
24
18
  success: {
25
- icon: lucide_react_1.CheckCircle2,
19
+ icon: CheckCircle2,
26
20
  container: "border-emerald-200 bg-emerald-50 dark:border-emerald-900/50 dark:bg-emerald-950/40",
27
21
  iconClass: "text-emerald-600 dark:text-emerald-400",
28
22
  textClass: "text-emerald-900 dark:text-emerald-200",
29
23
  },
30
24
  info: {
31
- icon: lucide_react_1.Info,
25
+ icon: Info,
32
26
  container: "border-blue-200 bg-blue-50 dark:border-blue-900/50 dark:bg-blue-950/40",
33
27
  iconClass: "text-blue-600 dark:text-blue-400",
34
28
  textClass: "text-blue-900 dark:text-blue-200",
@@ -40,12 +34,12 @@ const MESSAGE_MAX_HEIGHT_CLASS = "max-h-[6.875rem]";
40
34
  function LoggerReactDisplayItem({ message }) {
41
35
  const styles = SEVERITY_STYLES[message.severity];
42
36
  const Icon = styles.icon;
43
- return ((0, jsx_runtime_1.jsxs)("div", { role: "alert", className: `flex items-start gap-3 rounded-lg border px-3 py-2.5 shadow-lg ${styles.container}`, children: [(0, jsx_runtime_1.jsx)(Icon, { size: 16, className: `mt-0.5 shrink-0 ${styles.iconClass}` }), (0, jsx_runtime_1.jsx)("p", { className: `min-w-0 flex-1 overflow-y-auto text-sm leading-snug ${MESSAGE_MAX_HEIGHT_CLASS} ${styles.textClass}`, children: message.message }), (0, jsx_runtime_1.jsx)("button", { type: "button", onClick: message.dismiss, className: "shrink-0 rounded p-0.5 text-gray-400 hover:bg-black/5 hover:text-gray-600 dark:hover:bg-white/10 dark:hover:text-gray-200", "aria-label": "Dismiss", children: (0, jsx_runtime_1.jsx)(lucide_react_1.X, { size: 14 }) })] }));
37
+ return (_jsxs("div", { role: "alert", className: `flex items-start gap-3 rounded-lg border px-3 py-2.5 shadow-lg ${styles.container}`, children: [_jsx(Icon, { size: 16, className: `mt-0.5 shrink-0 ${styles.iconClass}` }), _jsx("p", { className: `min-w-0 flex-1 overflow-y-auto text-sm leading-snug ${MESSAGE_MAX_HEIGHT_CLASS} ${styles.textClass}`, children: message.message }), _jsx("button", { type: "button", onClick: message.dismiss, className: "shrink-0 rounded p-0.5 text-gray-400 hover:bg-black/5 hover:text-gray-600 dark:hover:bg-white/10 dark:hover:text-gray-200", "aria-label": "Dismiss", children: _jsx(X, { size: 14 }) })] }));
44
38
  }
45
- function LoggerReactDisplay({ zIndex = 5000 }) {
46
- const messages = (0, react_whispr_1.useWhisprValue)(Logger_1.default.lines);
39
+ export function LoggerReactDisplay({ zIndex = 5000 }) {
40
+ const messages = useWhisprValue(logger.lines);
47
41
  const visible = [...messages].reverse().slice(0, MAX_VISIBLE_TOASTS);
48
42
  if (visible.length === 0)
49
43
  return null;
50
- return ((0, jsx_runtime_1.jsx)("div", { className: "pointer-events-none fixed inset-x-0 bottom-4 flex justify-center px-4", style: { zIndex }, children: (0, jsx_runtime_1.jsx)("div", { className: "pointer-events-auto flex w-full max-w-sm flex-col gap-2", children: visible.map((message) => ((0, jsx_runtime_1.jsx)(LoggerReactDisplayItem, { message: message }, message.id))) }) }));
44
+ return (_jsx("div", { className: "pointer-events-none fixed inset-x-0 bottom-4 flex justify-center px-4", style: { zIndex }, children: _jsx("div", { className: "pointer-events-auto flex w-full max-w-sm flex-col gap-2", children: visible.map((message) => (_jsx(LoggerReactDisplayItem, { message: message }, message.id))) }) }));
51
45
  }
@@ -1,17 +1,14 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = Button;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const lucide_react_1 = require("lucide-react");
6
- const react_1 = require("react");
7
- function Button({ onClick, children, className, onError, loader }) {
8
- const Loader = loader ?? (0, jsx_runtime_1.jsx)(lucide_react_1.Loader2, { style: {
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Loader2 } from "lucide-react";
3
+ import { useState } from "react";
4
+ export default function Button({ onClick, children, className, onError, loader }) {
5
+ const Loader = loader ?? _jsx(Loader2, { style: {
9
6
  width: '1rem',
10
7
  height: '1rem',
11
8
  animation: 'spin 1s linear infinite',
12
9
  } });
13
- const [loading, setLoading] = (0, react_1.useState)(false);
14
- const [error, setError] = (0, react_1.useState)(null);
10
+ const [loading, setLoading] = useState(false);
11
+ const [error, setError] = useState(null);
15
12
  const handleClick = async () => {
16
13
  if (loading)
17
14
  return;
@@ -31,7 +28,7 @@ function Button({ onClick, children, className, onError, loader }) {
31
28
  })
32
29
  .finally(() => setLoading(false));
33
30
  };
34
- return ((0, jsx_runtime_1.jsx)(jsx_runtime_1.Fragment, { children: (0, jsx_runtime_1.jsxs)("div", { className: "flex flex-col h-full w-full gap-2", children: [(0, jsx_runtime_1.jsx)("div", { onClick: handleClick, className: className, style: {
31
+ return (_jsx(_Fragment, { children: _jsxs("div", { className: "flex flex-col h-full w-full gap-2", children: [_jsx("div", { onClick: handleClick, className: className, style: {
35
32
  display: 'flex',
36
33
  alignItems: 'center',
37
34
  justifyContent: 'center',
@@ -39,7 +36,7 @@ function Button({ onClick, children, className, onError, loader }) {
39
36
  cursor: 'pointer',
40
37
  }, children: loading ?
41
38
  Loader :
42
- children }), error && (0, jsx_runtime_1.jsx)("div", { style: {
39
+ children }), error && _jsx("div", { style: {
43
40
  color: '#ef4444'
44
41
  }, children: error })] }) }));
45
42
  }
@@ -1,20 +1,17 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = Copiable;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const lucide_react_1 = require("lucide-react");
6
- const react_1 = require("react");
7
- const __1 = require("../");
8
- function Copiable({ value, className }) {
9
- const [copying, setCopying] = (0, react_1.useState)(false);
10
- const copy = (0, react_1.useCallback)(() => {
11
- (0, __1.copyToClipboard)(value);
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CheckCircle2, CopyIcon } from "lucide-react";
3
+ import { useCallback, useState } from "react";
4
+ import { copyToClipboard } from "../index.js";
5
+ export default function Copiable({ value, className }) {
6
+ const [copying, setCopying] = useState(false);
7
+ const copy = useCallback(() => {
8
+ copyToClipboard(value);
12
9
  setCopying(true);
13
10
  setTimeout(() => {
14
11
  setCopying(false);
15
12
  }, 1000);
16
13
  }, [value, setCopying]);
17
- return ((0, jsx_runtime_1.jsxs)("div", { onClick: copy, className: `flex flex-row items-center justify-between gap-2 cursor-pointer ${className}`, children: [(0, jsx_runtime_1.jsx)("span", { children: value }), copying ?
18
- (0, jsx_runtime_1.jsx)(lucide_react_1.CheckCircle2, { className: "w-4 h-4" }) :
19
- (0, jsx_runtime_1.jsx)(lucide_react_1.CopyIcon, { className: "w-4 h-4" })] }));
14
+ return (_jsxs("div", { onClick: copy, className: `flex flex-row items-center justify-between gap-2 cursor-pointer ${className}`, children: [_jsx("span", { children: value }), copying ?
15
+ _jsx(CheckCircle2, { className: "w-4 h-4" }) :
16
+ _jsx(CopyIcon, { className: "w-4 h-4" })] }));
20
17
  }
@@ -1,6 +1,6 @@
1
1
  import { LucideIcon } from "lucide-react";
2
- import { TypeofRecord } from "..";
3
- import { InputComponentPropsVariants } from "./input";
2
+ import { TypeofRecord } from "../index.js";
3
+ import { InputComponentPropsVariants } from "./input.js";
4
4
  export type FormComponentPropsInput = {
5
5
  label?: string;
6
6
  required: boolean;
@@ -1,19 +1,13 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.default = FormComponent;
7
- const jsx_runtime_1 = require("react/jsx-runtime");
8
- const react_1 = require("react");
9
- const react_2 = require("react");
10
- const input_1 = __importDefault(require("./input"));
11
- const textButton_1 = __importDefault(require("./textButton"));
12
- function FormComponent(props) {
13
- const variants = (0, react_2.useMemo)(() => ({
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createElement as _createElement } from "react";
3
+ import { useMemo } from "react";
4
+ import InputComponent from "./input.js";
5
+ import TextButton from "./textButton.js";
6
+ export default function FormComponent(props) {
7
+ const variants = useMemo(() => ({
14
8
  default: props.variant
15
9
  }), [props.variant]);
16
- return ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', gap: '1rem' }, children: [props.inputs.map((input, index) => (() => {
10
+ return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '1rem' }, children: [props.inputs.map((input, index) => (() => {
17
11
  const value = props.value[input.key];
18
12
  const setValue = (v) => props.setValue({
19
13
  ...props.value,
@@ -33,15 +27,15 @@ function FormComponent(props) {
33
27
  case "email":
34
28
  case "password":
35
29
  case "tel":
36
- return (0, react_1.createElement)(input_1.default, { ...baseProps, key: index }, ({ value, setValue, className }) => ((0, jsx_runtime_1.jsx)("input", { type: input.type, value: value, onChange: (e) => setValue(e.target.value), required: input.required, className: className, placeholder: input.label })));
30
+ return _createElement(InputComponent, { ...baseProps, key: index }, ({ value, setValue, className }) => (_jsx("input", { type: input.type, value: value, onChange: (e) => setValue(e.target.value), required: input.required, className: className, placeholder: input.label })));
37
31
  case "select":
38
- return (0, react_1.createElement)(input_1.default, { ...baseProps, key: index, required: input.required, validate: (v) => {
32
+ return _createElement(InputComponent, { ...baseProps, key: index, required: input.required, validate: (v) => {
39
33
  if (!input.options.includes(v))
40
34
  throw new Error("Invalid option");
41
- } }, ({ value, setValue, className }) => ((0, jsx_runtime_1.jsx)("select", { value: value, onChange: (e) => setValue(e.target.value), required: input.required, className: className, children: input.options.map(option => ((0, jsx_runtime_1.jsx)("option", { value: option, children: option }, option))) })));
35
+ } }, ({ value, setValue, className }) => (_jsx("select", { value: value, onChange: (e) => setValue(e.target.value), required: input.required, className: className, children: input.options.map(option => (_jsx("option", { value: option, children: option }, option))) })));
42
36
  default:
43
- return (0, jsx_runtime_1.jsx)("div", { style: { color: '#ef4444', backgroundColor: 'white' }, children: "Unknown input type" });
37
+ return _jsx("div", { style: { color: '#ef4444', backgroundColor: 'white' }, children: "Unknown input type" });
44
38
  }
45
39
  })()), props.submit &&
46
- (0, jsx_runtime_1.jsx)(textButton_1.default, { className: variants.default.button, title: props.submit.label, onClick: () => props.submit?.callback(props.value) })] }));
40
+ _jsx(TextButton, { className: variants.default.button, title: props.submit.label, onClick: () => props.submit?.callback(props.value) })] }));
47
41
  }
@@ -1,9 +1,9 @@
1
- import BaseButton, { type ButtonProps as BaseButtonProps } from './button';
2
- import BaseCopiable, { type CopiableProps as BaseCopiableProps } from './copiable';
3
- import BaseForm, { type FormComponentProps as BaseFormProps } from './form';
4
- import BaseInput, { type InputComponentProps as BaseInputProps } from './input';
5
- import BaseLoader, { type LoaderProps as BaseLoaderProps } from './loader';
6
- import BaseModal, { type ModalActions as BaseModalActions, type ModalContent as BaseModalContent, type ModalComponentProps as BaseModalProps } from './modal';
7
- import BaseTable, { type TableProps as BaseTableProps } from './table';
8
- import BaseTextButton, { type TextButtonProps as BaseTextButtonProps } from './textButton';
1
+ import BaseButton, { type ButtonProps as BaseButtonProps } from './button.js';
2
+ import BaseCopiable, { type CopiableProps as BaseCopiableProps } from './copiable.js';
3
+ import BaseForm, { type FormComponentProps as BaseFormProps } from './form.js';
4
+ import BaseInput, { type InputComponentProps as BaseInputProps } from './input.js';
5
+ import BaseLoader, { type LoaderProps as BaseLoaderProps } from './loader.js';
6
+ import BaseModal, { type ModalActions as BaseModalActions, type ModalContent as BaseModalContent, type ModalComponentProps as BaseModalProps } from './modal.js';
7
+ import BaseTable, { type TableProps as BaseTableProps } from './table.js';
8
+ import BaseTextButton, { type TextButtonProps as BaseTextButtonProps } from './textButton.js';
9
9
  export { BaseButton, BaseButtonProps, BaseCopiable, BaseCopiableProps, BaseForm, BaseFormProps, BaseInput, BaseInputProps, BaseLoader, BaseLoaderProps, BaseModal, BaseModalActions, BaseModalContent, BaseModalProps, BaseTable, BaseTableProps, BaseTextButton, BaseTextButtonProps };
@@ -1,22 +1,9 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.BaseTextButton = exports.BaseTable = exports.BaseModal = exports.BaseLoader = exports.BaseInput = exports.BaseForm = exports.BaseCopiable = exports.BaseButton = void 0;
7
- const button_1 = __importDefault(require("./button"));
8
- exports.BaseButton = button_1.default;
9
- const copiable_1 = __importDefault(require("./copiable"));
10
- exports.BaseCopiable = copiable_1.default;
11
- const form_1 = __importDefault(require("./form"));
12
- exports.BaseForm = form_1.default;
13
- const input_1 = __importDefault(require("./input"));
14
- exports.BaseInput = input_1.default;
15
- const loader_1 = __importDefault(require("./loader"));
16
- exports.BaseLoader = loader_1.default;
17
- const modal_1 = __importDefault(require("./modal"));
18
- exports.BaseModal = modal_1.default;
19
- const table_1 = __importDefault(require("./table"));
20
- exports.BaseTable = table_1.default;
21
- const textButton_1 = __importDefault(require("./textButton"));
22
- exports.BaseTextButton = textButton_1.default;
1
+ import BaseButton from './button.js';
2
+ import BaseCopiable from './copiable.js';
3
+ import BaseForm from './form.js';
4
+ import BaseInput from './input.js';
5
+ import BaseLoader from './loader.js';
6
+ import BaseModal from './modal.js';
7
+ import BaseTable from './table.js';
8
+ import BaseTextButton from './textButton.js';
9
+ export { BaseButton, BaseCopiable, BaseForm, BaseInput, BaseLoader, BaseModal, BaseTable, BaseTextButton };
@@ -1,18 +1,15 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.default = InputComponent;
4
- const jsx_runtime_1 = require("react/jsx-runtime");
5
- const lucide_react_1 = require("lucide-react");
6
- const react_1 = require("react");
7
- const index_1 = require("../index");
8
- function InputComponent(props) {
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { CopyIcon } from "lucide-react";
3
+ import { useState } from "react";
4
+ import { copyToClipboard } from "../index.js";
5
+ export default function InputComponent(props) {
9
6
  const variant = props.variant;
10
7
  const baseClassName = props.variants[variant ?? "default"];
11
- const [error, setError] = (0, react_1.useState)(null);
12
- return ((0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'column', gap: '0.5rem' }, children: [(0, jsx_runtime_1.jsxs)("div", { style: { display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', gap: '0.5rem' }, children: [props.label &&
13
- (0, jsx_runtime_1.jsx)("label", { className: baseClassName.label, children: props.label }), props.copy &&
14
- (0, jsx_runtime_1.jsx)(lucide_react_1.CopyIcon, { style: { width: '1rem', height: '1rem', cursor: 'pointer' }, onClick: () => (0, index_1.copyToClipboard)(props.value) })] }), (0, jsx_runtime_1.jsxs)("div", { style: { position: 'relative' }, className: baseClassName.wrapper, children: [props.icon &&
15
- (0, jsx_runtime_1.jsx)("div", { style: { position: 'absolute', top: '0.5rem' }, children: props.icon }), (0, jsx_runtime_1.jsx)("div", { style: { paddingLeft: props.icon ? '2rem' : '0' }, children: props.children({
8
+ const [error, setError] = useState(null);
9
+ return (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '0.5rem' }, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', gap: '0.5rem' }, children: [props.label &&
10
+ _jsx("label", { className: baseClassName.label, children: props.label }), props.copy &&
11
+ _jsx(CopyIcon, { style: { width: '1rem', height: '1rem', cursor: 'pointer' }, onClick: () => copyToClipboard(props.value) })] }), _jsxs("div", { style: { position: 'relative' }, className: baseClassName.wrapper, children: [props.icon &&
12
+ _jsx("div", { style: { position: 'absolute', top: '0.5rem' }, children: props.icon }), _jsx("div", { style: { paddingLeft: props.icon ? '2rem' : '0' }, children: props.children({
16
13
  value: props.value,
17
14
  setValue: (v) => {
18
15
  try {
@@ -28,5 +25,5 @@ function InputComponent(props) {
28
25
  },
29
26
  className: baseClassName.input
30
27
  }) })] }), error &&
31
- (0, jsx_runtime_1.jsx)("div", { style: { color: '#ef4444', fontSize: '0.75rem' }, children: error })] }));
28
+ _jsx("div", { style: { color: '#ef4444', fontSize: '0.75rem' }, children: error })] }));
32
29
  }
@@ -1,5 +1,5 @@
1
1
  import type React from "react";
2
- import type { Dispatcher } from "../Dispatcher";
2
+ import type { Dispatcher } from "../Dispatcher.js";
3
3
  export type LoaderProps<I, O> = {
4
4
  data: Dispatcher<I, O>;
5
5
  children: (props: {