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.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,
|
|
@@ -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");
|
|
@@ -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,
|