react-better-html 1.1.232 → 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.d.mts +269 -2
- package/dist/index.d.ts +269 -2
- package/dist/index.js +188 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +186 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/index.mjs
CHANGED
|
@@ -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";
|
|
@@ -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,
|