react-better-html 1.1.247 → 1.1.249
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 +18 -8
- package/dist/index.d.ts +18 -8
- package/dist/index.js +75 -36
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +75 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -1580,6 +1580,8 @@ var Icon_default = { Icon: MemoizedIcon }.Icon;
|
|
|
1580
1580
|
import { jsx as jsx5, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
1581
1581
|
var PageHeaderComponent = forwardRef5(function PageHeader({
|
|
1582
1582
|
icon,
|
|
1583
|
+
iconColor,
|
|
1584
|
+
iconSize = 20,
|
|
1583
1585
|
image,
|
|
1584
1586
|
imageUrl,
|
|
1585
1587
|
imageSize = 60,
|
|
@@ -1610,7 +1612,7 @@ var PageHeaderComponent = forwardRef5(function PageHeader({
|
|
|
1610
1612
|
marginBottom: marginBottom ?? theme2.styles.space * 2,
|
|
1611
1613
|
ref,
|
|
1612
1614
|
children: [
|
|
1613
|
-
icon && /* @__PURE__ */ jsx5(Icon_default, { name: icon, size:
|
|
1615
|
+
icon && /* @__PURE__ */ jsx5(Icon_default, { name: icon, size: iconSize, color: iconColor, flexShrink: 0 }),
|
|
1614
1616
|
(image || imageUrl) && /* @__PURE__ */ jsx5(
|
|
1615
1617
|
ImageTag,
|
|
1616
1618
|
{
|
|
@@ -3286,25 +3288,53 @@ function findClosestNumber(numbers, target) {
|
|
|
3286
3288
|
|
|
3287
3289
|
// src/utils/localStorage.ts
|
|
3288
3290
|
function generateLocalStorage() {
|
|
3289
|
-
|
|
3290
|
-
|
|
3291
|
-
|
|
3292
|
-
|
|
3293
|
-
|
|
3294
|
-
|
|
3291
|
+
const setItem = (name, value) => {
|
|
3292
|
+
if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage.setItem"))
|
|
3293
|
+
return void 0;
|
|
3294
|
+
const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
|
|
3295
|
+
(plugin) => plugin.name === "localStorage"
|
|
3296
|
+
);
|
|
3297
|
+
if (!localStoragePlugin2) {
|
|
3298
|
+
throw new Error(
|
|
3299
|
+
"`generateLocalStorage.setItem` function requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
|
|
3295
3300
|
);
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
|
|
3299
|
-
|
|
3300
|
-
|
|
3301
|
-
|
|
3302
|
-
|
|
3303
|
-
|
|
3304
|
-
|
|
3305
|
-
|
|
3306
|
-
|
|
3307
|
-
|
|
3301
|
+
}
|
|
3302
|
+
const pluginConfig = localStoragePlugin2.getConfig();
|
|
3303
|
+
const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
|
|
3304
|
+
const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
|
|
3305
|
+
const readyValue = encryptionEnabled ? encryptString(JSON.stringify(value)) : JSON.stringify(value);
|
|
3306
|
+
if (value) localStorage.setItem(readyName.toString(), readyValue);
|
|
3307
|
+
else localStorage.removeItem(readyName.toString());
|
|
3308
|
+
};
|
|
3309
|
+
const getAllItems = () => {
|
|
3310
|
+
if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage.getAllItems"))
|
|
3311
|
+
return void 0;
|
|
3312
|
+
const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
|
|
3313
|
+
(plugin) => plugin.name === "localStorage"
|
|
3314
|
+
);
|
|
3315
|
+
if (!localStoragePlugin2) {
|
|
3316
|
+
throw new Error(
|
|
3317
|
+
"`generateLocalStorage.getAllItems` function requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
|
|
3318
|
+
);
|
|
3319
|
+
}
|
|
3320
|
+
const pluginConfig = localStoragePlugin2.getConfig();
|
|
3321
|
+
const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
|
|
3322
|
+
const items = {
|
|
3323
|
+
...localStorage
|
|
3324
|
+
};
|
|
3325
|
+
try {
|
|
3326
|
+
return encryptionEnabled ? Object.entries(items).reduce((previousValue, currentValue) => {
|
|
3327
|
+
const readyName = encryptString(currentValue[0]);
|
|
3328
|
+
const item = JSON.parse(decryptString(currentValue[1]));
|
|
3329
|
+
previousValue[readyName] = item;
|
|
3330
|
+
return previousValue;
|
|
3331
|
+
}, {}) : items;
|
|
3332
|
+
} catch (error) {
|
|
3333
|
+
return void 0;
|
|
3334
|
+
}
|
|
3335
|
+
};
|
|
3336
|
+
return {
|
|
3337
|
+
setItem,
|
|
3308
3338
|
getItem: (name) => {
|
|
3309
3339
|
if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage.getItem"))
|
|
3310
3340
|
return void 0;
|
|
@@ -3327,6 +3357,7 @@ function generateLocalStorage() {
|
|
|
3327
3357
|
return void 0;
|
|
3328
3358
|
}
|
|
3329
3359
|
},
|
|
3360
|
+
getAllItems,
|
|
3330
3361
|
removeItem: (name) => {
|
|
3331
3362
|
if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage.removeItem"))
|
|
3332
3363
|
return void 0;
|
|
@@ -3343,8 +3374,14 @@ function generateLocalStorage() {
|
|
|
3343
3374
|
const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
|
|
3344
3375
|
localStorage.removeItem(readyName.toString());
|
|
3345
3376
|
},
|
|
3346
|
-
removeAllItems: () => {
|
|
3377
|
+
removeAllItems: (config) => {
|
|
3378
|
+
const allItems = getAllItems();
|
|
3347
3379
|
localStorage.clear();
|
|
3380
|
+
if (config?.keepValues) {
|
|
3381
|
+
config.keepValues.forEach((key) => {
|
|
3382
|
+
setItem(key, allItems[key]);
|
|
3383
|
+
});
|
|
3384
|
+
}
|
|
3348
3385
|
}
|
|
3349
3386
|
};
|
|
3350
3387
|
}
|
|
@@ -7365,23 +7402,23 @@ var TabsComponent = forwardRef17(function Tabs({ tabs, name, accentColor, style
|
|
|
7365
7402
|
const firstRenderPassedRef = useRef8(false);
|
|
7366
7403
|
const tabsRef = useRef8({});
|
|
7367
7404
|
const [selectedTab, setSelectedTab] = useState13(() => {
|
|
7368
|
-
const
|
|
7405
|
+
const selectedTabId = tabs[0]?.id ?? "";
|
|
7369
7406
|
if (urlQuery) {
|
|
7370
7407
|
const tabQueryValue = urlQuery.getQuery(name ?? defaultTabName);
|
|
7371
|
-
if (!tabQueryValue) return
|
|
7372
|
-
if (tabs.
|
|
7408
|
+
if (!tabQueryValue) return selectedTabId;
|
|
7409
|
+
if (tabs.some((tab) => tab.id === tabQueryValue)) return tabQueryValue;
|
|
7373
7410
|
}
|
|
7374
|
-
return
|
|
7411
|
+
return selectedTabId;
|
|
7375
7412
|
});
|
|
7376
7413
|
const [rerenderState, setRerenderState] = useState13(0);
|
|
7377
7414
|
const tabsGap = style === "box" ? theme2.styles.gap / 2 : 0;
|
|
7378
7415
|
const onClickTab = useCallback16(
|
|
7379
7416
|
(tab) => {
|
|
7380
|
-
setSelectedTab(tab);
|
|
7417
|
+
setSelectedTab(tab.id);
|
|
7381
7418
|
onChange?.(tab);
|
|
7382
7419
|
if (urlQuery) {
|
|
7383
7420
|
urlQuery.setQuery({
|
|
7384
|
-
[name ?? defaultTabName]: tab
|
|
7421
|
+
[name ?? defaultTabName]: tab.id
|
|
7385
7422
|
});
|
|
7386
7423
|
}
|
|
7387
7424
|
},
|
|
@@ -7392,7 +7429,7 @@ var TabsComponent = forwardRef17(function Tabs({ tabs, name, accentColor, style
|
|
|
7392
7429
|
[rerenderState, selectedTab]
|
|
7393
7430
|
);
|
|
7394
7431
|
const leftSpacing = useMemo11(() => {
|
|
7395
|
-
const selectedTabIndex = tabs.findIndex((tab) => tab === selectedTab);
|
|
7432
|
+
const selectedTabIndex = tabs.findIndex((tab) => tab.id === selectedTab);
|
|
7396
7433
|
let spacing = 0;
|
|
7397
7434
|
Object.values(tabsRef.current).forEach((tab, index) => {
|
|
7398
7435
|
if (index < selectedTabIndex) spacing += (tab?.getBoundingClientRect().width ?? 0) + tabsGap;
|
|
@@ -7451,7 +7488,7 @@ var TabsComponent = forwardRef17(function Tabs({ tabs, name, accentColor, style
|
|
|
7451
7488
|
return /* @__PURE__ */ jsxs22(Div_default.column, { width: "100%", gap: theme2.styles.space, ...props, children: [
|
|
7452
7489
|
/* @__PURE__ */ jsxs22(Div_default, { position: "relative", className: "react-better-html-no-scrollbar", overflowY: "auto", children: [
|
|
7453
7490
|
/* @__PURE__ */ jsx25(Div_default.row, { position: "relative", width: "fit-content", gap: tabsGap, userSelect: "none", children: tabs.map((tab) => {
|
|
7454
|
-
const selected = tab === selectedTab;
|
|
7491
|
+
const selected = tab.id === selectedTab;
|
|
7455
7492
|
return /* @__PURE__ */ jsxs22(
|
|
7456
7493
|
Div_default,
|
|
7457
7494
|
{
|
|
@@ -7470,10 +7507,10 @@ var TabsComponent = forwardRef17(function Tabs({ tabs, name, accentColor, style
|
|
|
7470
7507
|
isTabAccessed: true,
|
|
7471
7508
|
onClickWithValue: onClickTab,
|
|
7472
7509
|
ref: (ref2) => {
|
|
7473
|
-
tabsRef.current[tab] = ref2;
|
|
7510
|
+
tabsRef.current[tab.id] = ref2;
|
|
7474
7511
|
},
|
|
7475
7512
|
children: [
|
|
7476
|
-
componentsState.tabs.tabsWithDots.includes(tab) && /* @__PURE__ */ jsx25(
|
|
7513
|
+
componentsState.tabs.tabsWithDots.includes(tab.id) && /* @__PURE__ */ jsx25(
|
|
7477
7514
|
Div_default,
|
|
7478
7515
|
{
|
|
7479
7516
|
position: "absolute",
|
|
@@ -7493,12 +7530,12 @@ var TabsComponent = forwardRef17(function Tabs({ tabs, name, accentColor, style
|
|
|
7493
7530
|
color: !selected ? theme2.colors.textSecondary : style === "box" ? theme2.colors.base : void 0,
|
|
7494
7531
|
transition: theme2.styles.transition,
|
|
7495
7532
|
whiteSpace: "nowrap",
|
|
7496
|
-
children: tab
|
|
7533
|
+
children: tab.label ?? tab.id
|
|
7497
7534
|
}
|
|
7498
7535
|
)
|
|
7499
7536
|
]
|
|
7500
7537
|
},
|
|
7501
|
-
tab
|
|
7538
|
+
tab.id
|
|
7502
7539
|
);
|
|
7503
7540
|
}) }),
|
|
7504
7541
|
style !== "box" && /* @__PURE__ */ jsx25(
|
|
@@ -7517,7 +7554,7 @@ var TabsComponent = forwardRef17(function Tabs({ tabs, name, accentColor, style
|
|
|
7517
7554
|
children && /* @__PURE__ */ jsx25(Div_default, { width: "100%", children })
|
|
7518
7555
|
] });
|
|
7519
7556
|
});
|
|
7520
|
-
TabsComponent.content = function Content({
|
|
7557
|
+
TabsComponent.content = function Content({ tabId, tabWithDot, tabsGroupName, isInitialTab, children }) {
|
|
7521
7558
|
const { componentsState } = useBetterHtmlContextInternal();
|
|
7522
7559
|
const thisTabGroupData = useMemo11(
|
|
7523
7560
|
() => componentsState.tabs.tabGroups.find((item) => item.name === (tabsGroupName ?? defaultTabName)),
|
|
@@ -7525,14 +7562,16 @@ TabsComponent.content = function Content({ tab, tabWithDot, tabsGroupName, isIni
|
|
|
7525
7562
|
);
|
|
7526
7563
|
useEffect14(() => {
|
|
7527
7564
|
if (tabWithDot) {
|
|
7528
|
-
componentsState.tabs.setTabsWithDots?.(
|
|
7565
|
+
componentsState.tabs.setTabsWithDots?.(
|
|
7566
|
+
(oldValue) => oldValue.includes(tabId) ? oldValue : [...oldValue, tabId]
|
|
7567
|
+
);
|
|
7529
7568
|
} else {
|
|
7530
7569
|
componentsState.tabs.setTabsWithDots?.(
|
|
7531
|
-
(oldValue) => oldValue.includes(
|
|
7570
|
+
(oldValue) => oldValue.includes(tabId) ? oldValue.filter((tab) => tab !== tabId) : oldValue
|
|
7532
7571
|
);
|
|
7533
7572
|
}
|
|
7534
7573
|
}, [tabWithDot]);
|
|
7535
|
-
return (thisTabGroupData ? thisTabGroupData.selectedTab ===
|
|
7574
|
+
return (thisTabGroupData ? thisTabGroupData.selectedTab === tabId : isInitialTab) ? /* @__PURE__ */ jsx25(Div_default, { width: "100%", children }) : void 0;
|
|
7536
7575
|
};
|
|
7537
7576
|
var Tabs2 = memo25(TabsComponent);
|
|
7538
7577
|
Tabs2.content = TabsComponent.content;
|