react-better-html 1.1.158 → 1.1.159

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";
@@ -5339,6 +5359,62 @@ var countries = [
5339
5359
  }
5340
5360
  ];
5341
5361
 
5362
+ // src/utils/functions.ts
5363
+ import CryptoJS from "crypto-js";
5364
+
5365
+ // src/utils/variableFunctions.ts
5366
+ var checkBetterHtmlContextValue = (value, functionsName) => {
5367
+ if (value === void 0) {
5368
+ throw new Error(
5369
+ `\`${functionsName}()\` must be used within a \`<BetterHtmlProvider>\`. Make sure to add one at the root of your component tree.`
5370
+ );
5371
+ }
5372
+ return value !== void 0;
5373
+ };
5374
+ var loaderControls = {
5375
+ startLoading: (loaderName) => {
5376
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.startLoading")) return;
5377
+ externalBetterHtmlContextValue.setLoaders((oldValue) => ({
5378
+ ...oldValue,
5379
+ [loaderName.toString()]: true
5380
+ }));
5381
+ },
5382
+ stopLoading: (loaderName) => {
5383
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "loaderControls.stopLoading")) return;
5384
+ externalBetterHtmlContextValue.setLoaders((oldValue) => ({
5385
+ ...oldValue,
5386
+ [loaderName.toString()]: false
5387
+ }));
5388
+ }
5389
+ };
5390
+ var alertControls = {
5391
+ createAlert: (alert) => {
5392
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.createAlert"))
5393
+ return void 0;
5394
+ const readyAlert = {
5395
+ id: crypto.randomUUID(),
5396
+ ...alert
5397
+ };
5398
+ externalBetterHtmlContextValue.setAlerts((oldValue) => [...oldValue, readyAlert]);
5399
+ return readyAlert;
5400
+ },
5401
+ removeAlert: (alertId) => {
5402
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "alertControls.removeAlert")) return;
5403
+ externalBetterHtmlContextValue.setAlerts((oldValue) => oldValue.filter((alert) => alert.id !== alertId));
5404
+ }
5405
+ };
5406
+ var colorThemeControls = {
5407
+ toggleTheme: (theme2) => {
5408
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "colorThemeControls.toggleTheme")) return;
5409
+ const currentColorTheme = externalBetterHtmlContextValue.colorTheme;
5410
+ const newColorTheme = theme2 ?? (currentColorTheme === "dark" ? "light" : "dark");
5411
+ setTimeout(() => {
5412
+ window.document.body.parentElement?.setAttribute("data-theme", newColorTheme);
5413
+ localStorage.setItem("theme", newColorTheme);
5414
+ }, 0.01 * 1e3);
5415
+ }
5416
+ };
5417
+
5342
5418
  // src/utils/functions.ts
5343
5419
  var generateRandomString = (stringLength, options) => {
5344
5420
  const capitals = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
@@ -5410,6 +5486,40 @@ var eventPreventStop = (event) => {
5410
5486
  event.preventDefault();
5411
5487
  event.stopPropagation();
5412
5488
  };
5489
+ var encryptString = (text) => {
5490
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "encryptString")) return void 0;
5491
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find((plugin) => plugin.name === "localStorage");
5492
+ if (!localStoragePlugin2) {
5493
+ throw new Error(
5494
+ "`encryptString` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
5495
+ );
5496
+ }
5497
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
5498
+ if (!pluginConfig?.encryption?.enabled) return text;
5499
+ const encrypted = CryptoJS.AES.encrypt(text, CryptoJS.enc.Hex.parse(pluginConfig.encryption.secretKey), {
5500
+ iv: CryptoJS.enc.Hex.parse(pluginConfig.encryption.iv),
5501
+ mode: CryptoJS.mode.CBC,
5502
+ padding: CryptoJS.pad.Pkcs7
5503
+ }).toString();
5504
+ return encrypted;
5505
+ };
5506
+ var decryptString = (text) => {
5507
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "decryptString")) return void 0;
5508
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find((plugin) => plugin.name === "localStorage");
5509
+ if (!localStoragePlugin2) {
5510
+ throw new Error(
5511
+ "`decryptString` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
5512
+ );
5513
+ }
5514
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
5515
+ if (!pluginConfig?.encryption?.enabled) return text;
5516
+ const decrypted = CryptoJS.AES.decrypt(text, CryptoJS.enc.Hex.parse(pluginConfig.encryption.secretKey), {
5517
+ iv: CryptoJS.enc.Hex.parse(pluginConfig.encryption.iv),
5518
+ mode: CryptoJS.mode.CBC,
5519
+ padding: CryptoJS.pad.Pkcs7
5520
+ });
5521
+ return decrypted.toString(CryptoJS.enc.Utf8);
5522
+ };
5413
5523
 
5414
5524
  // src/components/Label.tsx
5415
5525
  import { memo as memo15 } from "react";
@@ -7374,61 +7484,6 @@ var FormRow_default = FormRow2;
7374
7484
 
7375
7485
  // src/components/ColorThemeSwitch.tsx
7376
7486
  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
7487
  import { jsx as jsx21, jsxs as jsxs16 } from "react/jsx-runtime";
7433
7488
  var ColorThemeSwitchComponent = function ColorThemeSwitch({
7434
7489
  withMoon,
@@ -9042,6 +9097,71 @@ FoldableComponent.box = forwardRef18(function Box3({ ...props }, ref) {
9042
9097
  var Foldable2 = memo25(FoldableComponent);
9043
9098
  Foldable2.box = FoldableComponent.box;
9044
9099
  var Foldable_default = Foldable2;
9100
+
9101
+ // src/utils/localStorage.ts
9102
+ function generateLocalStorage() {
9103
+ return {
9104
+ setItem: (name, value) => {
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 readyValue = encryptionEnabled ? encryptString(JSON.stringify(value)) : JSON.stringify(value);
9119
+ if (value) localStorage.setItem(readyName.toString(), readyValue);
9120
+ else localStorage.removeItem(readyName.toString());
9121
+ },
9122
+ getItem: (name) => {
9123
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage"))
9124
+ return void 0;
9125
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
9126
+ (plugin) => plugin.name === "localStorage"
9127
+ );
9128
+ if (!localStoragePlugin2) {
9129
+ throw new Error(
9130
+ "`generateLocalStorage` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
9131
+ );
9132
+ }
9133
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
9134
+ const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
9135
+ const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
9136
+ const item = localStorage.getItem(readyName.toString());
9137
+ if (item === null) return void 0;
9138
+ try {
9139
+ return encryptionEnabled ? JSON.parse(decryptString(item)) : JSON.parse(item);
9140
+ } catch (error) {
9141
+ return void 0;
9142
+ }
9143
+ },
9144
+ removeItem: (name) => {
9145
+ if (!checkBetterHtmlContextValue(externalBetterHtmlContextValue, "generateLocalStorage"))
9146
+ return void 0;
9147
+ const localStoragePlugin2 = externalBetterHtmlContextValue.plugins.find(
9148
+ (plugin) => plugin.name === "localStorage"
9149
+ );
9150
+ if (!localStoragePlugin2) {
9151
+ throw new Error(
9152
+ "`generateLocalStorage` hook requires the `localStorage` plugin to be added to the `plugins` prop in `<BetterHtmlProvider>`."
9153
+ );
9154
+ }
9155
+ const pluginConfig = localStoragePlugin2.getConfig?.() ?? {};
9156
+ const encryptionEnabled = pluginConfig.encryption?.enabled ?? false;
9157
+ const readyName = encryptionEnabled ? encryptString(name.toString()) : name;
9158
+ localStorage.removeItem(readyName.toString());
9159
+ },
9160
+ removeAllItems: () => {
9161
+ localStorage.clear();
9162
+ }
9163
+ };
9164
+ }
9045
9165
  export {
9046
9166
  BetterHtmlProvider_default as BetterHtmlProvider,
9047
9167
  Button_default as Button,
@@ -9072,17 +9192,21 @@ export {
9072
9192
  countries,
9073
9193
  darkenColor,
9074
9194
  defaultAlertsPluginOptions,
9195
+ defaultLocalStoragePluginOptions,
9196
+ defaultReactRouterDomPluginOptions,
9075
9197
  desaturateColor,
9076
9198
  eventPreventDefault,
9077
9199
  eventPreventStop,
9078
9200
  eventStopPropagation,
9079
9201
  formatPhoneNumber,
9202
+ generateLocalStorage,
9080
9203
  generateRandomString,
9081
9204
  getBrowser,
9082
9205
  getFormErrorObject,
9083
9206
  isMobileDevice,
9084
9207
  lightenColor,
9085
9208
  loaderControls,
9209
+ localStoragePlugin,
9086
9210
  reactRouterDomPlugin,
9087
9211
  saturateColor,
9088
9212
  useAlertControls,