react-better-html 1.1.231 → 1.1.233

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
@@ -69,6 +69,8 @@ __export(index_exports, {
69
69
  eventStopPropagation: () => import_react_better_core30.eventStopPropagation,
70
70
  filterHover: () => filterHover,
71
71
  formatPhoneNumber: () => import_react_better_core30.formatPhoneNumber,
72
+ generateApi: () => generateApi,
73
+ generateEventEmitter: () => generateEventEmitter,
72
74
  generateLocalStorage: () => generateLocalStorage,
73
75
  generateRandomString: () => import_react_better_core30.generateRandomString,
74
76
  getBrowser: () => getBrowser,
@@ -2335,15 +2337,19 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2335
2337
  }
2336
2338
  onOpen?.();
2337
2339
  }, [onOpen, urlQuery, name]);
2338
- const onClickClose = (0, import_react11.useCallback)(() => {
2339
- setIsOpened.setFalse();
2340
- onClose?.();
2341
- if (urlQuery && name) urlQuery.removeQuery(`${name}-modal`, false);
2342
- setTimeout(() => {
2343
- dialogRef.current?.close();
2344
- setIsOpenedLate.setFalse();
2345
- }, 0.2 * 1e3);
2346
- }, [onClose, urlQuery, name]);
2340
+ const onClickClose = (0, import_react11.useCallback)(
2341
+ (event) => {
2342
+ event?.stopPropagation();
2343
+ setIsOpened.setFalse();
2344
+ onClose?.();
2345
+ if (urlQuery && name) urlQuery.removeQuery(`${name}-modal`, false);
2346
+ setTimeout(() => {
2347
+ dialogRef.current?.close();
2348
+ setIsOpenedLate.setFalse();
2349
+ }, 0.2 * 1e3);
2350
+ },
2351
+ [onClose, urlQuery, name]
2352
+ );
2347
2353
  const onKeyDown = (0, import_react11.useCallback)(
2348
2354
  (event) => {
2349
2355
  if (event.key === "Escape") {
@@ -2357,17 +2363,13 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2357
2363
  if (!defaultIsOpened) return;
2358
2364
  onClickOpen();
2359
2365
  }, []);
2360
- (0, import_react11.useImperativeHandle)(
2361
- ref,
2362
- () => {
2363
- return {
2364
- open: onClickOpen,
2365
- close: onClickClose,
2366
- isOpened
2367
- };
2368
- },
2369
- [onClickOpen, onClickClose, isOpened]
2370
- );
2366
+ (0, import_react11.useImperativeHandle)(ref, () => {
2367
+ return {
2368
+ open: onClickOpen,
2369
+ close: onClickClose,
2370
+ isOpened
2371
+ };
2372
+ }, [onClickOpen, onClickClose, isOpened]);
2371
2373
  const headerVertical = headerTextAlign === "center";
2372
2374
  return (0, import_react_dom.createPortal)(
2373
2375
  /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(
@@ -3064,7 +3066,8 @@ function BetterHtmlProviderInternal({ config, plugins, children }) {
3064
3066
  tabsWithDots,
3065
3067
  setTabsWithDots
3066
3068
  }
3067
- }
3069
+ },
3070
+ devMode: config?.devMode
3068
3071
  }),
3069
3072
  [config, alerts, sideMenuIsCollapsed, sideMenuIsOpenMobile, plugins, tabGroups, tabsWithDots]
3070
3073
  );
@@ -3103,7 +3106,8 @@ function BetterHtmlProvider({ config, ...props }) {
3103
3106
  app: config?.app,
3104
3107
  sideMenuIsCollapsed: config?.sideMenuIsCollapsed,
3105
3108
  sideMenuIsOpenMobile: config?.sideMenuIsOpenMobile,
3106
- components: config?.components
3109
+ components: config?.components,
3110
+ devMode: config?.devMode
3107
3111
  }),
3108
3112
  [config]
3109
3113
  );
@@ -3263,6 +3267,12 @@ function findClosestNumber(numbers, target) {
3263
3267
  }
3264
3268
  return closest;
3265
3269
  }
3270
+ var constructQuery = (query) => {
3271
+ if (!query) return "";
3272
+ return Object.entries(query).filter(([_, queryVale]) => queryVale !== void 0 && queryVale !== null).map(
3273
+ ([queryName, queryVale]) => typeof queryVale === "object" ? queryVale.map((value) => `${queryName}=${value}`) : [`${queryName}=${queryVale}`]
3274
+ ).flat().join("&");
3275
+ };
3266
3276
 
3267
3277
  // src/utils/localStorage.ts
3268
3278
  function generateLocalStorage() {
@@ -3329,6 +3339,180 @@ function generateLocalStorage() {
3329
3339
  };
3330
3340
  }
3331
3341
 
3342
+ // src/utils/logger.ts
3343
+ var textColors = {
3344
+ black: "#111111",
3345
+ red: "#f83e4b",
3346
+ green: "#5ac53a",
3347
+ yellow: "#f8d770",
3348
+ blue: "#3d6fdf",
3349
+ magenta: "#9648eb",
3350
+ cyan: "#53b2c8",
3351
+ white: "#f8f8f8"
3352
+ };
3353
+ var backgroundColors = {
3354
+ black: "#111111",
3355
+ red: "#f83e4b",
3356
+ green: "#5ac53a",
3357
+ yellow: "#f8d770",
3358
+ blue: "#3d6fdf",
3359
+ magenta: "#9648eb",
3360
+ cyan: "#53b2c8",
3361
+ white: "#f8f8f8"
3362
+ };
3363
+ var logTypes = {
3364
+ info: "cyan",
3365
+ success: "green",
3366
+ warn: "yellow",
3367
+ error: "red"
3368
+ };
3369
+ function getCssString(options) {
3370
+ const color = options.color ? textColors[options.color] : void 0;
3371
+ const backgroundColor = options.backgroundColor ? backgroundColors[options.backgroundColor] : void 0;
3372
+ const fontWeight = options.bold ? "bold" : "normal";
3373
+ return `${color ? `color: ${color};` : ""}${backgroundColor ? `background-color: ${backgroundColor};` : ""}${fontWeight ? `font-weight: ${fontWeight};` : ""}`;
3374
+ }
3375
+ function logText(text, options) {
3376
+ if (externalBetterHtmlContextValue?.devMode !== true) return;
3377
+ console.log(`%c${text}`, getCssString(options ?? {}));
3378
+ }
3379
+ var log = {
3380
+ ...Object.entries(logTypes).reduce(
3381
+ (previousValue, [logType, color]) => {
3382
+ previousValue[logType] = (text = "", bold) => {
3383
+ logText(text, {
3384
+ color,
3385
+ bold
3386
+ });
3387
+ };
3388
+ return previousValue;
3389
+ },
3390
+ {}
3391
+ ),
3392
+ /** @description Default log function */
3393
+ log: (text, options) => {
3394
+ logText(text, options);
3395
+ },
3396
+ /** @description Logs the value in pretty json format */
3397
+ json: (jsonObject, options) => {
3398
+ logText(JSON.stringify(jsonObject, null, 4), options);
3399
+ },
3400
+ /** @description Logs a -=-= pattern */
3401
+ divider: (color) => {
3402
+ logText("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-", {
3403
+ color
3404
+ });
3405
+ },
3406
+ trace: () => {
3407
+ if (externalBetterHtmlContextValue?.devMode !== true) return;
3408
+ console.trace();
3409
+ }
3410
+ };
3411
+
3412
+ // src/utils/api.ts
3413
+ var methodInitiateToString = {
3414
+ GET: "GET request to ",
3415
+ PUT: "PUT request to ",
3416
+ POST: "POST request to ",
3417
+ PATCH: "PATCH request to ",
3418
+ DELETE: "DELETE request to ",
3419
+ HEAD: "HEAD request to ",
3420
+ OPTIONS: "OPTIONS request to ",
3421
+ TRACE: "TRACE request to ",
3422
+ CONNECT: "CONNECT request to "
3423
+ };
3424
+ var methodResponseToString = {
3425
+ GET: "GET request from ",
3426
+ PUT: "PUT request from ",
3427
+ POST: "POST request from ",
3428
+ PATCH: "PATCH request from ",
3429
+ DELETE: "DELETE request from ",
3430
+ HEAD: "HEAD request from ",
3431
+ OPTIONS: "OPTIONS request from",
3432
+ TRACE: "TRACE request from ",
3433
+ CONNECT: "CONNECT request from"
3434
+ };
3435
+ function generateApi(config, apiConfig, getHeaders) {
3436
+ return async function apiCall(name, payload = {}) {
3437
+ if (!apiConfig[name]) {
3438
+ return Promise.reject(
3439
+ new Error(`Endpoint ${name.toString()} is not defined in the \`generateApi\` function.`, {
3440
+ cause: "generateApi.apiConfig.missingEndpoint"
3441
+ })
3442
+ );
3443
+ }
3444
+ const baseURL = config.baseUrl;
3445
+ const path = `${apiConfig[name].path}${payload.path?.length ? `/${payload.path.join("/")}` : ""}`;
3446
+ const query = constructQuery(payload.query);
3447
+ const url = `${baseURL}${path}${query ? `?${query}` : ""}`;
3448
+ const requestHeaders = {
3449
+ "Content-Type": apiConfig[name].bodyWithFormData ? "multipart/form-data" : "application/json",
3450
+ ...getHeaders ? Object.entries(getHeaders).reduce((previousValue, [key, value]) => {
3451
+ if (apiConfig[name].includeHeaders?.includes(key)) {
3452
+ previousValue[key] = value?.();
3453
+ }
3454
+ return previousValue;
3455
+ }, {}) : {}
3456
+ };
3457
+ const body = payload.body;
3458
+ const bodyAsFormData = new FormData();
3459
+ if (body && apiConfig[name].bodyWithFormData) {
3460
+ Object.entries(body).forEach(([key, value]) => {
3461
+ bodyAsFormData.append(key, value);
3462
+ });
3463
+ }
3464
+ const readyBody = JSON.stringify((apiConfig[name].bodyWithFormData ? bodyAsFormData : body) ?? {});
3465
+ log.log(`Initiate ${methodInitiateToString[apiConfig[name].method]} ${url} - ${name.toString()}`, {
3466
+ color: "magenta"
3467
+ });
3468
+ return await call(
3469
+ () => fetch(url, {
3470
+ method: apiConfig[name].method,
3471
+ body: apiConfig[name].method !== "GET" ? readyBody : void 0,
3472
+ headers: requestHeaders
3473
+ })
3474
+ );
3475
+ async function call(callAction) {
3476
+ const response = await callAction();
3477
+ const responseJson = await response.json();
3478
+ log.log(`Response ${methodResponseToString[apiConfig[name].method]} ${url} - ${name.toString()}`, {
3479
+ color: "blue"
3480
+ });
3481
+ return {
3482
+ data: responseJson,
3483
+ headers: response.headers,
3484
+ statusCode: response.status,
3485
+ statusText: response.statusText,
3486
+ url: response.url,
3487
+ ok: response.ok,
3488
+ redirected: response.redirected
3489
+ };
3490
+ }
3491
+ };
3492
+ }
3493
+
3494
+ // src/utils/eventEmitter.ts
3495
+ function generateEventEmitter() {
3496
+ const eventEmitter = new EventTarget();
3497
+ return {
3498
+ emit: (name, data) => {
3499
+ const event = new CustomEvent(name.toString(), {
3500
+ detail: data
3501
+ });
3502
+ eventEmitter.dispatchEvent(event);
3503
+ },
3504
+ listen: (name, callback) => {
3505
+ const listener = (event) => {
3506
+ callback?.(event.detail);
3507
+ };
3508
+ eventEmitter.addEventListener(name.toString(), listener);
3509
+ return () => {
3510
+ eventEmitter.removeEventListener(name.toString(), listener);
3511
+ };
3512
+ }
3513
+ };
3514
+ }
3515
+
3332
3516
  // src/components/PageHolder.tsx
3333
3517
  var import_react15 = require("react");
3334
3518
  var import_react_better_core14 = require("react-better-core");
@@ -4723,7 +4907,7 @@ InputFieldComponent.phoneNumber = (0, import_react21.forwardRef)(function PhoneN
4723
4907
  return;
4724
4908
  }
4725
4909
  setDropdownValue(country.phoneNumberExtension);
4726
- setInputFieldValue(newValue.slice(country?.phoneNumberExtension.length + 1));
4910
+ setInputFieldValue(newValue.slice(country.phoneNumberExtension.length + 1));
4727
4911
  }, [value]);
4728
4912
  const readyId = id ?? internalId;
4729
4913
  return /* @__PURE__ */ (0, import_jsx_runtime18.jsxs)(Div_default.column, { width: "100%", gap: theme2.styles.gap / 2, children: [
@@ -5035,7 +5219,7 @@ InputFieldComponent.time = (0, import_react21.forwardRef)(function Time({ hoursT
5035
5219
  const readyHour = readyHours.includes(hours2) ? hours2 : findClosestNumber(readyHours, hours2);
5036
5220
  const readyMinute = readyMinutes.includes(minutes2) ? minutes2 : findClosestNumber(readyMinutes, minutes2);
5037
5221
  const finalHour = minHours && readyHour < minHours ? minHours : maxHours && readyHour > maxHours ? maxHours : readyHour;
5038
- const finalMinute = minHours !== void 0 && minMinutes !== void 0 && finalHour === minHours && readyMinute < minMinutes ? minMinutes : maxHours !== void 0 && maxMinutes !== void 0 && finalHour === maxHours && readyMinute > maxMinutes ? maxMinutes : readyMinute;
5222
+ const finalMinute = !!minHours && !!minMinutes && finalHour === minHours && readyMinute < minMinutes ? minMinutes : !!maxHours && !!maxMinutes && finalHour === maxHours && readyMinute > maxMinutes ? maxMinutes : readyMinute;
5039
5223
  const newValue = `${finalHour.toString().padStart(2, "0")}:${finalMinute.toString().padStart(2, "0")}`;
5040
5224
  inputFieldProps.onChangeValue?.(newValue);
5041
5225
  }
@@ -7926,6 +8110,8 @@ var SideMenu_default = SideMenu2;
7926
8110
  eventStopPropagation,
7927
8111
  filterHover,
7928
8112
  formatPhoneNumber,
8113
+ generateApi,
8114
+ generateEventEmitter,
7929
8115
  generateLocalStorage,
7930
8116
  generateRandomString,
7931
8117
  getBrowser,