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.mjs CHANGED
@@ -2272,15 +2272,19 @@ var ModalComponent = forwardRef7(function Modal({
2272
2272
  }
2273
2273
  onOpen?.();
2274
2274
  }, [onOpen, urlQuery, name]);
2275
- const onClickClose = useCallback4(() => {
2276
- setIsOpened.setFalse();
2277
- onClose?.();
2278
- if (urlQuery && name) urlQuery.removeQuery(`${name}-modal`, false);
2279
- setTimeout(() => {
2280
- dialogRef.current?.close();
2281
- setIsOpenedLate.setFalse();
2282
- }, 0.2 * 1e3);
2283
- }, [onClose, urlQuery, name]);
2275
+ const onClickClose = useCallback4(
2276
+ (event) => {
2277
+ event?.stopPropagation();
2278
+ setIsOpened.setFalse();
2279
+ onClose?.();
2280
+ if (urlQuery && name) urlQuery.removeQuery(`${name}-modal`, false);
2281
+ setTimeout(() => {
2282
+ dialogRef.current?.close();
2283
+ setIsOpenedLate.setFalse();
2284
+ }, 0.2 * 1e3);
2285
+ },
2286
+ [onClose, urlQuery, name]
2287
+ );
2284
2288
  const onKeyDown = useCallback4(
2285
2289
  (event) => {
2286
2290
  if (event.key === "Escape") {
@@ -2294,17 +2298,13 @@ var ModalComponent = forwardRef7(function Modal({
2294
2298
  if (!defaultIsOpened) return;
2295
2299
  onClickOpen();
2296
2300
  }, []);
2297
- useImperativeHandle(
2298
- ref,
2299
- () => {
2300
- return {
2301
- open: onClickOpen,
2302
- close: onClickClose,
2303
- isOpened
2304
- };
2305
- },
2306
- [onClickOpen, onClickClose, isOpened]
2307
- );
2301
+ useImperativeHandle(ref, () => {
2302
+ return {
2303
+ open: onClickOpen,
2304
+ close: onClickClose,
2305
+ isOpened
2306
+ };
2307
+ }, [onClickOpen, onClickClose, isOpened]);
2308
2308
  const headerVertical = headerTextAlign === "center";
2309
2309
  return createPortal(
2310
2310
  /* @__PURE__ */ jsx9(
@@ -3001,7 +3001,8 @@ function BetterHtmlProviderInternal({ config, plugins, children }) {
3001
3001
  tabsWithDots,
3002
3002
  setTabsWithDots
3003
3003
  }
3004
- }
3004
+ },
3005
+ devMode: config?.devMode
3005
3006
  }),
3006
3007
  [config, alerts, sideMenuIsCollapsed, sideMenuIsOpenMobile, plugins, tabGroups, tabsWithDots]
3007
3008
  );
@@ -3040,7 +3041,8 @@ function BetterHtmlProvider({ config, ...props }) {
3040
3041
  app: config?.app,
3041
3042
  sideMenuIsCollapsed: config?.sideMenuIsCollapsed,
3042
3043
  sideMenuIsOpenMobile: config?.sideMenuIsOpenMobile,
3043
- components: config?.components
3044
+ components: config?.components,
3045
+ devMode: config?.devMode
3044
3046
  }),
3045
3047
  [config]
3046
3048
  );
@@ -3200,6 +3202,12 @@ function findClosestNumber(numbers, target) {
3200
3202
  }
3201
3203
  return closest;
3202
3204
  }
3205
+ var constructQuery = (query) => {
3206
+ if (!query) return "";
3207
+ return Object.entries(query).filter(([_, queryVale]) => queryVale !== void 0 && queryVale !== null).map(
3208
+ ([queryName, queryVale]) => typeof queryVale === "object" ? queryVale.map((value) => `${queryName}=${value}`) : [`${queryName}=${queryVale}`]
3209
+ ).flat().join("&");
3210
+ };
3203
3211
 
3204
3212
  // src/utils/localStorage.ts
3205
3213
  function generateLocalStorage() {
@@ -3266,6 +3274,180 @@ function generateLocalStorage() {
3266
3274
  };
3267
3275
  }
3268
3276
 
3277
+ // src/utils/logger.ts
3278
+ var textColors = {
3279
+ black: "#111111",
3280
+ red: "#f83e4b",
3281
+ green: "#5ac53a",
3282
+ yellow: "#f8d770",
3283
+ blue: "#3d6fdf",
3284
+ magenta: "#9648eb",
3285
+ cyan: "#53b2c8",
3286
+ white: "#f8f8f8"
3287
+ };
3288
+ var backgroundColors = {
3289
+ black: "#111111",
3290
+ red: "#f83e4b",
3291
+ green: "#5ac53a",
3292
+ yellow: "#f8d770",
3293
+ blue: "#3d6fdf",
3294
+ magenta: "#9648eb",
3295
+ cyan: "#53b2c8",
3296
+ white: "#f8f8f8"
3297
+ };
3298
+ var logTypes = {
3299
+ info: "cyan",
3300
+ success: "green",
3301
+ warn: "yellow",
3302
+ error: "red"
3303
+ };
3304
+ function getCssString(options) {
3305
+ const color = options.color ? textColors[options.color] : void 0;
3306
+ const backgroundColor = options.backgroundColor ? backgroundColors[options.backgroundColor] : void 0;
3307
+ const fontWeight = options.bold ? "bold" : "normal";
3308
+ return `${color ? `color: ${color};` : ""}${backgroundColor ? `background-color: ${backgroundColor};` : ""}${fontWeight ? `font-weight: ${fontWeight};` : ""}`;
3309
+ }
3310
+ function logText(text, options) {
3311
+ if (externalBetterHtmlContextValue?.devMode !== true) return;
3312
+ console.log(`%c${text}`, getCssString(options ?? {}));
3313
+ }
3314
+ var log = {
3315
+ ...Object.entries(logTypes).reduce(
3316
+ (previousValue, [logType, color]) => {
3317
+ previousValue[logType] = (text = "", bold) => {
3318
+ logText(text, {
3319
+ color,
3320
+ bold
3321
+ });
3322
+ };
3323
+ return previousValue;
3324
+ },
3325
+ {}
3326
+ ),
3327
+ /** @description Default log function */
3328
+ log: (text, options) => {
3329
+ logText(text, options);
3330
+ },
3331
+ /** @description Logs the value in pretty json format */
3332
+ json: (jsonObject, options) => {
3333
+ logText(JSON.stringify(jsonObject, null, 4), options);
3334
+ },
3335
+ /** @description Logs a -=-= pattern */
3336
+ divider: (color) => {
3337
+ logText("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-", {
3338
+ color
3339
+ });
3340
+ },
3341
+ trace: () => {
3342
+ if (externalBetterHtmlContextValue?.devMode !== true) return;
3343
+ console.trace();
3344
+ }
3345
+ };
3346
+
3347
+ // src/utils/api.ts
3348
+ var methodInitiateToString = {
3349
+ GET: "GET request to ",
3350
+ PUT: "PUT request to ",
3351
+ POST: "POST request to ",
3352
+ PATCH: "PATCH request to ",
3353
+ DELETE: "DELETE request to ",
3354
+ HEAD: "HEAD request to ",
3355
+ OPTIONS: "OPTIONS request to ",
3356
+ TRACE: "TRACE request to ",
3357
+ CONNECT: "CONNECT request to "
3358
+ };
3359
+ var methodResponseToString = {
3360
+ GET: "GET request from ",
3361
+ PUT: "PUT request from ",
3362
+ POST: "POST request from ",
3363
+ PATCH: "PATCH request from ",
3364
+ DELETE: "DELETE request from ",
3365
+ HEAD: "HEAD request from ",
3366
+ OPTIONS: "OPTIONS request from",
3367
+ TRACE: "TRACE request from ",
3368
+ CONNECT: "CONNECT request from"
3369
+ };
3370
+ function generateApi(config, apiConfig, getHeaders) {
3371
+ return async function apiCall(name, payload = {}) {
3372
+ if (!apiConfig[name]) {
3373
+ return Promise.reject(
3374
+ new Error(`Endpoint ${name.toString()} is not defined in the \`generateApi\` function.`, {
3375
+ cause: "generateApi.apiConfig.missingEndpoint"
3376
+ })
3377
+ );
3378
+ }
3379
+ const baseURL = config.baseUrl;
3380
+ const path = `${apiConfig[name].path}${payload.path?.length ? `/${payload.path.join("/")}` : ""}`;
3381
+ const query = constructQuery(payload.query);
3382
+ const url = `${baseURL}${path}${query ? `?${query}` : ""}`;
3383
+ const requestHeaders = {
3384
+ "Content-Type": apiConfig[name].bodyWithFormData ? "multipart/form-data" : "application/json",
3385
+ ...getHeaders ? Object.entries(getHeaders).reduce((previousValue, [key, value]) => {
3386
+ if (apiConfig[name].includeHeaders?.includes(key)) {
3387
+ previousValue[key] = value?.();
3388
+ }
3389
+ return previousValue;
3390
+ }, {}) : {}
3391
+ };
3392
+ const body = payload.body;
3393
+ const bodyAsFormData = new FormData();
3394
+ if (body && apiConfig[name].bodyWithFormData) {
3395
+ Object.entries(body).forEach(([key, value]) => {
3396
+ bodyAsFormData.append(key, value);
3397
+ });
3398
+ }
3399
+ const readyBody = JSON.stringify((apiConfig[name].bodyWithFormData ? bodyAsFormData : body) ?? {});
3400
+ log.log(`Initiate ${methodInitiateToString[apiConfig[name].method]} ${url} - ${name.toString()}`, {
3401
+ color: "magenta"
3402
+ });
3403
+ return await call(
3404
+ () => fetch(url, {
3405
+ method: apiConfig[name].method,
3406
+ body: apiConfig[name].method !== "GET" ? readyBody : void 0,
3407
+ headers: requestHeaders
3408
+ })
3409
+ );
3410
+ async function call(callAction) {
3411
+ const response = await callAction();
3412
+ const responseJson = await response.json();
3413
+ log.log(`Response ${methodResponseToString[apiConfig[name].method]} ${url} - ${name.toString()}`, {
3414
+ color: "blue"
3415
+ });
3416
+ return {
3417
+ data: responseJson,
3418
+ headers: response.headers,
3419
+ statusCode: response.status,
3420
+ statusText: response.statusText,
3421
+ url: response.url,
3422
+ ok: response.ok,
3423
+ redirected: response.redirected
3424
+ };
3425
+ }
3426
+ };
3427
+ }
3428
+
3429
+ // src/utils/eventEmitter.ts
3430
+ function generateEventEmitter() {
3431
+ const eventEmitter = new EventTarget();
3432
+ return {
3433
+ emit: (name, data) => {
3434
+ const event = new CustomEvent(name.toString(), {
3435
+ detail: data
3436
+ });
3437
+ eventEmitter.dispatchEvent(event);
3438
+ },
3439
+ listen: (name, callback) => {
3440
+ const listener = (event) => {
3441
+ callback?.(event.detail);
3442
+ };
3443
+ eventEmitter.addEventListener(name.toString(), listener);
3444
+ return () => {
3445
+ eventEmitter.removeEventListener(name.toString(), listener);
3446
+ };
3447
+ }
3448
+ };
3449
+ }
3450
+
3269
3451
  // src/components/PageHolder.tsx
3270
3452
  import { forwardRef as forwardRef8, memo as memo13 } from "react";
3271
3453
  import { useTheme as useTheme14 } from "react-better-core";
@@ -4674,7 +4856,7 @@ InputFieldComponent.phoneNumber = forwardRef11(function PhoneNumber({ label, val
4674
4856
  return;
4675
4857
  }
4676
4858
  setDropdownValue(country.phoneNumberExtension);
4677
- setInputFieldValue(newValue.slice(country?.phoneNumberExtension.length + 1));
4859
+ setInputFieldValue(newValue.slice(country.phoneNumberExtension.length + 1));
4678
4860
  }, [value]);
4679
4861
  const readyId = id ?? internalId;
4680
4862
  return /* @__PURE__ */ jsxs14(Div_default.column, { width: "100%", gap: theme2.styles.gap / 2, children: [
@@ -4986,7 +5168,7 @@ InputFieldComponent.time = forwardRef11(function Time({ hoursToRender, minutesTo
4986
5168
  const readyHour = readyHours.includes(hours2) ? hours2 : findClosestNumber(readyHours, hours2);
4987
5169
  const readyMinute = readyMinutes.includes(minutes2) ? minutes2 : findClosestNumber(readyMinutes, minutes2);
4988
5170
  const finalHour = minHours && readyHour < minHours ? minHours : maxHours && readyHour > maxHours ? maxHours : readyHour;
4989
- 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;
5171
+ const finalMinute = !!minHours && !!minMinutes && finalHour === minHours && readyMinute < minMinutes ? minMinutes : !!maxHours && !!maxMinutes && finalHour === maxHours && readyMinute > maxMinutes ? maxMinutes : readyMinute;
4990
5172
  const newValue = `${finalHour.toString().padStart(2, "0")}:${finalMinute.toString().padStart(2, "0")}`;
4991
5173
  inputFieldProps.onChangeValue?.(newValue);
4992
5174
  }
@@ -7891,6 +8073,8 @@ export {
7891
8073
  eventStopPropagation,
7892
8074
  filterHover,
7893
8075
  formatPhoneNumber,
8076
+ generateApi,
8077
+ generateEventEmitter,
7894
8078
  generateLocalStorage,
7895
8079
  generateRandomString,
7896
8080
  getBrowser,