react-better-html 1.1.158 → 1.1.160

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
@@ -1526,19 +1526,6 @@ import { memo as memo7 } from "react";
1526
1526
  import { memo as memo6, useCallback as useCallback2, useEffect as useEffect3, useMemo, useRef, useState } from "react";
1527
1527
  import styled6 from "styled-components";
1528
1528
 
1529
- // src/plugins/react-router-dom.ts
1530
- import { Link as RouterLink, NavLink as RouterNavLink } from "react-router-dom";
1531
- var reactRouterDomPlugin = () => ({
1532
- name: "react-router-dom",
1533
- components: {
1534
- Link: RouterLink,
1535
- NavLink: RouterNavLink
1536
- },
1537
- initialize: () => {
1538
- console.log("react-router-dom plugin initialized");
1539
- }
1540
- });
1541
-
1542
1529
  // src/plugins/alerts.ts
1543
1530
  var defaultAlertsPluginOptions = {
1544
1531
  position: "bottom",
@@ -1559,6 +1546,39 @@ var alertsPlugin = (options) => ({
1559
1546
  })
1560
1547
  });
1561
1548
 
1549
+ // src/plugins/reactRouterDom.ts
1550
+ import { Link as RouterLink, NavLink as RouterNavLink } from "react-router-dom";
1551
+ var defaultReactRouterDomPluginOptions = {};
1552
+ var reactRouterDomPlugin = (options) => ({
1553
+ name: "react-router-dom",
1554
+ components: {
1555
+ Link: RouterLink,
1556
+ NavLink: RouterNavLink
1557
+ },
1558
+ initialize: () => {
1559
+ console.log("react-router-dom plugin initialized");
1560
+ },
1561
+ getConfig: () => ({
1562
+ ...defaultReactRouterDomPluginOptions,
1563
+ ...options
1564
+ })
1565
+ });
1566
+
1567
+ // src/plugins/localStorage.ts
1568
+ var defaultLocalStoragePluginOptions = {
1569
+ encryption: {}
1570
+ };
1571
+ var localStoragePlugin = (options) => ({
1572
+ name: "localStorage",
1573
+ initialize: () => {
1574
+ console.log("localStorage plugin initialized");
1575
+ },
1576
+ getConfig: () => ({
1577
+ ...defaultLocalStoragePluginOptions,
1578
+ ...options
1579
+ })
1580
+ });
1581
+
1562
1582
  // src/components/Icon.tsx
1563
1583
  import { forwardRef, memo, useEffect } from "react";
1564
1584
  import styled from "styled-components";
@@ -3232,11 +3252,11 @@ var Divider_default = {
3232
3252
  })
3233
3253
  ),
3234
3254
  horizontal: memo10(
3235
- forwardRef5(function Divider2({ width = 1, backgroundColor, text, textColor, ...props }, ref) {
3255
+ forwardRef5(function Divider2({ width = 1, backgroundColor, text, textFontSize, textColor, ...props }, ref) {
3236
3256
  const theme2 = useTheme();
3237
3257
  return /* @__PURE__ */ jsxs5(Div_default.row, { width: "100%", alignItems: "center", gap: text ? theme2.styles.space : void 0, ...props, ref, children: [
3238
3258
  /* @__PURE__ */ jsx10(Div_default, { flex: 1, height: width, flexShrink: 0, backgroundColor: backgroundColor ?? theme2.colors.border }),
3239
- text && /* @__PURE__ */ jsx10(Text_default, { color: textColor ?? theme2.colors.textSecondary, children: text }),
3259
+ text && /* @__PURE__ */ jsx10(Text_default, { fontSize: textFontSize, color: textColor ?? theme2.colors.textSecondary, children: text }),
3240
3260
  /* @__PURE__ */ jsx10(Div_default, { flex: 1, height: width, flexShrink: 0, backgroundColor: backgroundColor ?? theme2.colors.border })
3241
3261
  ] });
3242
3262
  })
@@ -3547,11 +3567,8 @@ var PageHolderComponent = forwardRef7(function PageHolder({ noMaxContentWidth, c
3547
3567
  PageHolderComponent.center = forwardRef7(function Center({
3548
3568
  pageBackgroundColor,
3549
3569
  contentMaxWidth,
3550
- sideImageSrc,
3551
- sideImageName,
3552
- sideImagePosition = "right",
3553
- sideImageAlignment = "center",
3554
- sideImageFooter,
3570
+ sideComponent,
3571
+ sideComponentPosition = "right",
3555
3572
  noMaxContentWidth,
3556
3573
  children,
3557
3574
  ...props
@@ -3560,7 +3577,7 @@ PageHolderComponent.center = forwardRef7(function Center({
3560
3577
  const mediaQuery = useMediaQuery();
3561
3578
  const { app } = useBetterHtmlContextInternal();
3562
3579
  const breakingPoint = mediaQuery.size1000;
3563
- const withSideImage = (sideImageSrc || sideImageName) && !breakingPoint;
3580
+ const withSideComponent = sideComponent && !breakingPoint;
3564
3581
  return /* @__PURE__ */ jsxs7(
3565
3582
  Div_default.row,
3566
3583
  {
@@ -3570,8 +3587,8 @@ PageHolderComponent.center = forwardRef7(function Center({
3570
3587
  justifyContent: "center",
3571
3588
  backgroundColor: pageBackgroundColor,
3572
3589
  children: [
3573
- sideImagePosition === "left" && withSideImage && /* @__PURE__ */ jsx12(Div_default, { width: "50%" }),
3574
- /* @__PURE__ */ jsx12(Div_default.column, { width: `${withSideImage ? 50 : 100}%`, alignItems: "center", children: /* @__PURE__ */ jsx12(
3590
+ sideComponentPosition === "left" && withSideComponent && /* @__PURE__ */ jsx12(Div_default, { width: "50%" }),
3591
+ /* @__PURE__ */ jsx12(Div_default.column, { width: `${withSideComponent ? 50 : 100}%`, alignItems: "center", children: /* @__PURE__ */ jsx12(
3575
3592
  Div_default.box,
3576
3593
  {
3577
3594
  width: `calc(100% - ${theme2.styles.space}px * 2)`,
@@ -3583,32 +3600,17 @@ PageHolderComponent.center = forwardRef7(function Center({
3583
3600
  children
3584
3601
  }
3585
3602
  ) }),
3586
- sideImagePosition === "right" && withSideImage && /* @__PURE__ */ jsx12(Div_default, { width: "50%" }),
3587
- withSideImage && /* @__PURE__ */ jsxs7(
3603
+ sideComponentPosition === "right" && withSideComponent && /* @__PURE__ */ jsx12(Div_default, { width: "50%" }),
3604
+ withSideComponent && /* @__PURE__ */ jsx12(
3588
3605
  Div_default,
3589
3606
  {
3590
3607
  position: "fixed",
3591
3608
  width: "50%",
3592
3609
  height: "100svh",
3593
3610
  top: 0,
3594
- left: sideImagePosition === "left" ? 0 : "auto",
3595
- right: sideImagePosition === "right" ? 0 : "auto",
3596
- children: [
3597
- /* @__PURE__ */ jsx12(
3598
- Div_default.row,
3599
- {
3600
- position: "absolute",
3601
- width: "100%",
3602
- height: "100%",
3603
- top: 0,
3604
- left: 0,
3605
- justifyContent: sideImageAlignment === "left" ? "flex-start" : sideImageAlignment === "right" ? "flex-end" : "center",
3606
- overflow: "hidden",
3607
- children: /* @__PURE__ */ jsx12(Image_default, { name: sideImageName, height: "100%", src: sideImageSrc })
3608
- }
3609
- ),
3610
- /* @__PURE__ */ jsx12(Div_default, { position: "absolute", width: "100%", bottom: theme2.styles.space, children: sideImageFooter })
3611
- ]
3611
+ left: sideComponentPosition === "left" ? 0 : "auto",
3612
+ right: sideComponentPosition === "right" ? 0 : "auto",
3613
+ children: sideComponent
3612
3614
  }
3613
3615
  )
3614
3616
  ]
@@ -5339,6 +5341,62 @@ var countries = [
5339
5341
  }
5340
5342
  ];
5341
5343
 
5344
+ // src/utils/functions.ts
5345
+ import CryptoJS from "crypto-js";
5346
+
5347
+ // src/utils/variableFunctions.ts
5348
+ var checkBetterHtmlContextValue = (value, functionsName) => {
5349
+ if (value === void 0) {
5350
+ throw new Error(
5351
+ `\`${functionsName}()\` must be used within a \`<BetterHtmlProvider>\`. Make sure to add one at the root of your component tree.`
5352
+ );
5353
+ }
5354
+ return value !== void 0;
5355
+ };
5356
+ var loaderControls = {
5357
+ startLoading: (loaderName) => {
5358
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.startLoading")) return;
5359
+ externalBetterHtmlContextValue.setLoaders((oldValue) => ({
5360
+ ...oldValue,
5361
+ [loaderName.toString()]: true
5362
+ }));
5363
+ },
5364
+ stopLoading: (loaderName) => {
5365
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.stopLoading")) return;
5366
+ externalBetterHtmlContextValue.setLoaders((oldValue) => ({
5367
+ ...oldValue,
5368
+ [loaderName.toString()]: false
5369
+ }));
5370
+ }
5371
+ };
5372
+ var alertControls = {
5373
+ createAlert: (alert) => {
5374
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.createAlert"))
5375
+ return void 0;
5376
+ const readyAlert = {
5377
+ id: crypto.randomUUID(),
5378
+ ...alert
5379
+ };
5380
+ externalBetterHtmlContextValue.setAlerts((oldValue) => [...oldValue, readyAlert]);
5381
+ return readyAlert;
5382
+ },
5383
+ removeAlert: (alertId) => {
5384
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.removeAlert")) return;
5385
+ externalBetterHtmlContextValue.setAlerts((oldValue) => oldValue.filter((alert) => alert.id !== alertId));
5386
+ }
5387
+ };
5388
+ var colorThemeControls = {
5389
+ toggleTheme: (theme2) => {
5390
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "colorThemeControls.toggleTheme")) return;
5391
+ const currentColorTheme = externalBetterHtmlContextValue.colorTheme;
5392
+ const newColorTheme = theme2 ?? (currentColorTheme === "dark" ? "light" : "dark");
5393
+ setTimeout(() => {
5394
+ window.document.body.parentElement?.setAttribute("data-theme", newColorTheme);
5395
+ localStorage.setItem("theme", newColorTheme);
5396
+ }, 0.01 * 1e3);
5397
+ }
5398
+ };
5399
+
5342
5400
  // src/utils/functions.ts
5343
5401
  var generateRandomString = (stringLength, options) => {
5344
5402
  const capitals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -5410,6 +5468,40 @@ var eventPreventStop = (event) => {
5410
5468
  event.preventDefault();
5411
5469
  event.stopPropagation();
5412
5470
  };
5471
+ var encryptString = (text) => {
5472
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "encryptString")) return void 0;
5473
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find((plugin) => plugin.name === "localStorage");
5474
+ if (!localStoragePlugin2) {
5475
+ throw new Error(
5476
+ "`encryptString` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
5477
+ );
5478
+ }
5479
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
5480
+ if (!pluginConfig?.encryption?.enabled) return text;
5481
+ const encrypted = CryptoJS.AES.encrypt(text, CryptoJS.enc.Hex.parse(pluginConfig.encryption.secretKey), {
5482
+ iv: CryptoJS.enc.Hex.parse(pluginConfig.encryption.iv),
5483
+ mode: CryptoJS.mode.CBC,
5484
+ padding: CryptoJS.pad.Pkcs7
5485
+ }).toString();
5486
+ return encrypted;
5487
+ };
5488
+ var decryptString = (text) => {
5489
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "decryptString")) return void 0;
5490
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find((plugin) => plugin.name === "localStorage");
5491
+ if (!localStoragePlugin2) {
5492
+ throw new Error(
5493
+ "`decryptString` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
5494
+ );
5495
+ }
5496
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
5497
+ if (!pluginConfig?.encryption?.enabled) return text;
5498
+ const decrypted = CryptoJS.AES.decrypt(text, CryptoJS.enc.Hex.parse(pluginConfig.encryption.secretKey), {
5499
+ iv: CryptoJS.enc.Hex.parse(pluginConfig.encryption.iv),
5500
+ mode: CryptoJS.mode.CBC,
5501
+ padding: CryptoJS.pad.Pkcs7
5502
+ });
5503
+ return decrypted.toString(CryptoJS.enc.Utf8);
5504
+ };
5413
5505
 
5414
5506
  // src/components/Label.tsx
5415
5507
  import { memo as memo15 } from "react";
@@ -7374,61 +7466,6 @@ var FormRow_default = FormRow2;
7374
7466
 
7375
7467
  // src/components/ColorThemeSwitch.tsx
7376
7468
  import { memo as memo21, useEffect as useEffect9 } from "react";
7377
-
7378
- // src/utils/variableFunctions.ts
7379
- var checkBetterHtmlContextValue = (value, functionsName) => {
7380
- if (value === void 0) {
7381
- throw new Error(
7382
- `\`${functionsName}()\` must be used within a \`<BetterHtmlProvider>\`. Make sure to add one at the root of your component tree.`
7383
- );
7384
- }
7385
- return value !== void 0;
7386
- };
7387
- var loaderControls = {
7388
- startLoading: (loaderName) => {
7389
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.startLoading")) return;
7390
- externalBetterHtmlContextValue.setLoaders((oldValue) => ({
7391
- ...oldValue,
7392
- [loaderName.toString()]: true
7393
- }));
7394
- },
7395
- stopLoading: (loaderName) => {
7396
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.stopLoading")) return;
7397
- externalBetterHtmlContextValue.setLoaders((oldValue) => ({
7398
- ...oldValue,
7399
- [loaderName.toString()]: false
7400
- }));
7401
- }
7402
- };
7403
- var alertControls = {
7404
- createAlert: (alert) => {
7405
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.createAlert"))
7406
- return void 0;
7407
- const readyAlert = {
7408
- id: crypto.randomUUID(),
7409
- ...alert
7410
- };
7411
- externalBetterHtmlContextValue.setAlerts((oldValue) => [...oldValue, readyAlert]);
7412
- return readyAlert;
7413
- },
7414
- removeAlert: (alertId) => {
7415
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.removeAlert")) return;
7416
- externalBetterHtmlContextValue.setAlerts((oldValue) => oldValue.filter((alert) => alert.id !== alertId));
7417
- }
7418
- };
7419
- var colorThemeControls = {
7420
- toggleTheme: (theme2) => {
7421
- if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "colorThemeControls.toggleTheme")) return;
7422
- const currentColorTheme = externalBetterHtmlContextValue.colorTheme;
7423
- const newColorTheme = theme2 ?? (currentColorTheme === "dark" ? "light" : "dark");
7424
- setTimeout(() => {
7425
- window.document.body.parentElement?.setAttribute("data-theme", newColorTheme);
7426
- localStorage.setItem("theme", newColorTheme);
7427
- }, 0.01 * 1e3);
7428
- }
7429
- };
7430
-
7431
- // src/components/ColorThemeSwitch.tsx
7432
7469
  import { jsx as jsx21, jsxs as jsxs16 } from "react/jsx-runtime";
7433
7470
  var ColorThemeSwitchComponent = function ColorThemeSwitch({
7434
7471
  withMoon,
@@ -9042,6 +9079,71 @@ FoldableComponent.box = forwardRef18(function Box3({ ...props }, ref) {
9042
9079
  var Foldable2 = memo25(FoldableComponent);
9043
9080
  Foldable2.box = FoldableComponent.box;
9044
9081
  var Foldable_default = Foldable2;
9082
+
9083
+ // src/utils/localStorage.ts
9084
+ function generateLocalStorage() {
9085
+ return {
9086
+ setItem: (name, value) => {
9087
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage"))
9088
+ return void 0;
9089
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
9090
+ (plugin) => plugin.name === "localStorage"
9091
+ );
9092
+ if (!localStoragePlugin2) {
9093
+ throw new Error(
9094
+ "`generateLocalStorage` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
9095
+ );
9096
+ }
9097
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
9098
+ const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
9099
+ const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
9100
+ const readyValue = encryptionEnabled ? encryptString(JSON.stringify(value)) : JSON.stringify(value);
9101
+ if (value) localStorage.setItem(readyName.toString(), readyValue);
9102
+ else localStorage.removeItem(readyName.toString());
9103
+ },
9104
+ getItem: (name) => {
9105
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage"))
9106
+ return void 0;
9107
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
9108
+ (plugin) => plugin.name === "localStorage"
9109
+ );
9110
+ if (!localStoragePlugin2) {
9111
+ throw new Error(
9112
+ "`generateLocalStorage` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
9113
+ );
9114
+ }
9115
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
9116
+ const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
9117
+ const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
9118
+ const item = localStorage.getItem(readyName.toString());
9119
+ if (item === null) return void 0;
9120
+ try {
9121
+ return encryptionEnabled ? JSON.parse(decryptString(item)) : JSON.parse(item);
9122
+ } catch (error) {
9123
+ return void 0;
9124
+ }
9125
+ },
9126
+ removeItem: (name) => {
9127
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage"))
9128
+ return void 0;
9129
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
9130
+ (plugin) => plugin.name === "localStorage"
9131
+ );
9132
+ if (!localStoragePlugin2) {
9133
+ throw new Error(
9134
+ "`generateLocalStorage` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
9135
+ );
9136
+ }
9137
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
9138
+ const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
9139
+ const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
9140
+ localStorage.removeItem(readyName.toString());
9141
+ },
9142
+ removeAllItems: () => {
9143
+ localStorage.clear();
9144
+ }
9145
+ };
9146
+ }
9045
9147
  export {
9046
9148
  BetterHtmlProvider_default as BetterHtmlProvider,
9047
9149
  Button_default as Button,
@@ -9072,17 +9174,21 @@ export {
9072
9174
  countries,
9073
9175
  darkenColor,
9074
9176
  defaultAlertsPluginOptions,
9177
+ defaultLocalStoragePluginOptions,
9178
+ defaultReactRouterDomPluginOptions,
9075
9179
  desaturateColor,
9076
9180
  eventPreventDefault,
9077
9181
  eventPreventStop,
9078
9182
  eventStopPropagation,
9079
9183
  formatPhoneNumber,
9184
+ generateLocalStorage,
9080
9185
  generateRandomString,
9081
9186
  getBrowser,
9082
9187
  getFormErrorObject,
9083
9188
  isMobileDevice,
9084
9189
  lightenColor,
9085
9190
  loaderControls,
9191
+ localStoragePlugin,
9086
9192
  reactRouterDomPlugin,
9087
9193
  saturateColor,
9088
9194
  useAlertControls,