react-better-html 1.1.218 → 1.1.220

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 CHANGED
@@ -520,6 +520,8 @@ type ModalProps = {
520
520
  name?: string;
521
521
  overflow?: React.CSSProperties["overflow"];
522
522
  withoutCloseButton?: boolean;
523
+ /** @default false */
524
+ defaultIsOpened?: boolean;
523
525
  onOpen?: () => void;
524
526
  onClose?: () => void;
525
527
  children?: React.ReactNode;
@@ -1055,6 +1057,7 @@ type AlertsPluginOptions = {
1055
1057
  align?: "left" | "center" | "right";
1056
1058
  /** @default "auto" */
1057
1059
  defaultDuration?: AlertDuration;
1060
+ defaultDisplay?: PartialRecord<AlertType, AlertDisplay>;
1058
1061
  /** @default 460 */
1059
1062
  maxWidth?: number;
1060
1063
  /** @default true */
package/dist/index.d.ts CHANGED
@@ -520,6 +520,8 @@ type ModalProps = {
520
520
  name?: string;
521
521
  overflow?: React.CSSProperties["overflow"];
522
522
  withoutCloseButton?: boolean;
523
+ /** @default false */
524
+ defaultIsOpened?: boolean;
523
525
  onOpen?: () => void;
524
526
  onClose?: () => void;
525
527
  children?: React.ReactNode;
@@ -1055,6 +1057,7 @@ type AlertsPluginOptions = {
1055
1057
  align?: "left" | "center" | "right";
1056
1058
  /** @default "auto" */
1057
1059
  defaultDuration?: AlertDuration;
1060
+ defaultDisplay?: PartialRecord<AlertType, AlertDisplay>;
1058
1061
  /** @default 460 */
1059
1062
  maxWidth?: number;
1060
1063
  /** @default true */
package/dist/index.js CHANGED
@@ -1296,12 +1296,6 @@ function useUrlQuery() {
1296
1296
  );
1297
1297
  }
1298
1298
  const reactRouterDomPluginConfig = reactRouterDomPlugin2.getConfig();
1299
- const isInRouterContext = reactRouterDomPluginConfig.useInRouterContext();
1300
- if (!isInRouterContext) {
1301
- throw new Error(
1302
- "`useUrlQuery` hook must be used inside a React Router context. Make sure your component is wrapped in a `<BrowserRouter>`, or another Router component."
1303
- );
1304
- }
1305
1299
  const navigate = reactRouterDomPluginConfig.useNavigate();
1306
1300
  const [searchParams] = reactRouterDomPluginConfig.useSearchParams();
1307
1301
  const createSearchParams2 = reactRouterDomPluginConfig.createSearchParams;
@@ -1853,6 +1847,7 @@ var defaultAlertsPluginOptions = {
1853
1847
  position: "bottom",
1854
1848
  align: "right",
1855
1849
  defaultDuration: "auto",
1850
+ defaultDisplay: {},
1856
1851
  maxWidth: 460,
1857
1852
  withLoaderBar: true,
1858
1853
  withCloseButton: true
@@ -2291,6 +2286,7 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2291
2286
  name,
2292
2287
  overflow,
2293
2288
  withoutCloseButton,
2289
+ defaultIsOpened = false,
2294
2290
  onOpen,
2295
2291
  onClose,
2296
2292
  children
@@ -2301,12 +2297,12 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2301
2297
  const { app } = useBetterHtmlContextInternal();
2302
2298
  const { colorTheme } = (0, import_react_better_core10.useBetterCoreContext)();
2303
2299
  const dialogRef = (0, import_react11.useRef)(null);
2304
- const [isOpened, setIsOpened] = (0, import_react11.useState)(false);
2305
- const [isOpenedLate, setIsOpenedLate] = (0, import_react11.useState)(false);
2300
+ const [isOpened, setIsOpened] = (0, import_react_better_core10.useBooleanState)(false);
2301
+ const [isOpenedLate, setIsOpenedLate] = (0, import_react_better_core10.useBooleanState)(false);
2306
2302
  const onClickOpen = (0, import_react11.useCallback)(() => {
2307
2303
  dialogRef.current?.showModal();
2308
- setIsOpened(true);
2309
- setIsOpenedLate(true);
2304
+ setIsOpened.setTrue();
2305
+ setIsOpenedLate.setTrue();
2310
2306
  if (urlQuery && name) {
2311
2307
  urlQuery.setQuery(
2312
2308
  {
@@ -2318,12 +2314,12 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2318
2314
  onOpen?.();
2319
2315
  }, [onOpen, urlQuery, name]);
2320
2316
  const onClickClose = (0, import_react11.useCallback)(() => {
2321
- setIsOpened(false);
2317
+ setIsOpened.setFalse();
2322
2318
  onClose?.();
2323
2319
  if (urlQuery && name) urlQuery.removeQuery(`${name}-modal`, false);
2324
2320
  setTimeout(() => {
2325
2321
  dialogRef.current?.close();
2326
- setIsOpenedLate(false);
2322
+ setIsOpenedLate.setFalse();
2327
2323
  }, 0.2 * 1e3);
2328
2324
  }, [onClose, urlQuery, name]);
2329
2325
  const onKeyDown = (0, import_react11.useCallback)(
@@ -2335,6 +2331,10 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2335
2331
  },
2336
2332
  [withoutCloseButton]
2337
2333
  );
2334
+ (0, import_react11.useEffect)(() => {
2335
+ if (!defaultIsOpened) return;
2336
+ onClickOpen();
2337
+ }, []);
2338
2338
  (0, import_react11.useImperativeHandle)(
2339
2339
  ref,
2340
2340
  () => {
@@ -2684,6 +2684,7 @@ function Alert2({ alert }) {
2684
2684
  alert.duration ?? pluginConfig.defaultDuration ?? defaultAlertsPluginOptions.defaultDuration,
2685
2685
  alert
2686
2686
  );
2687
+ const defaultAlertDisplay = alert.display ?? pluginConfig.defaultDisplay?.[alert.type] ?? defaultAlertsPluginOptions.defaultDisplay[alert.type] ?? "default";
2687
2688
  const intervalRef = (0, import_react12.useRef)(void 0);
2688
2689
  const startTimeRef = (0, import_react12.useRef)(Date.now());
2689
2690
  const remainingTimeRef = (0, import_react12.useRef)(defaultAlertDurationNumber);
@@ -2703,7 +2704,7 @@ function Alert2({ alert }) {
2703
2704
  setProgress(newProgress);
2704
2705
  if (newProgress <= 0) {
2705
2706
  if (intervalRef.current) clearInterval(intervalRef.current);
2706
- if (alert.display === "prominent") return;
2707
+ if (defaultAlertDisplay === "prominent") return;
2707
2708
  setIsRemoved(true);
2708
2709
  setTimeout(() => {
2709
2710
  alertControls2.removeAlert(alert.id);
@@ -2714,7 +2715,7 @@ function Alert2({ alert }) {
2714
2715
  }, 0.2 * 1e3 - 10);
2715
2716
  }
2716
2717
  }, updateInterval);
2717
- }, [alert, progress]);
2718
+ }, [alert, progress, defaultAlertDisplay]);
2718
2719
  const onClickCloseAlert = (0, import_react12.useCallback)(() => {
2719
2720
  setIsRemoved(true);
2720
2721
  setTimeout(() => {
@@ -2773,13 +2774,6 @@ function Alert2({ alert }) {
2773
2774
  }),
2774
2775
  [theme2]
2775
2776
  );
2776
- (0, import_react12.useEffect)(() => {
2777
- if (alert.display === "prominent") {
2778
- setTimeout(() => {
2779
- modalRef.current?.open();
2780
- }, 0.1 * 1e3);
2781
- }
2782
- }, []);
2783
2777
  (0, import_react12.useEffect)(() => {
2784
2778
  startTimeRef.current = Date.now();
2785
2779
  remainingTimeRef.current = defaultAlertDurationNumber;
@@ -2790,9 +2784,10 @@ function Alert2({ alert }) {
2790
2784
  }, [defaultAlertDurationNumber, startProgressTimer]);
2791
2785
  const animation = `${isRemoved ? getAnimationOutName(pluginConfig.position ?? defaultAlertsPluginOptions.position)[pluginConfig.align ?? defaultAlertsPluginOptions.align] : getAnimationInName(pluginConfig.position ?? defaultAlertsPluginOptions.position)[pluginConfig.align ?? defaultAlertsPluginOptions.align]} ${theme2.styles.transition}`;
2792
2786
  const alertTitle = alert.title ?? alertData[alert.type].title;
2793
- return alert.display === "prominent" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2787
+ return defaultAlertDisplay === "prominent" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2794
2788
  Modal_default,
2795
2789
  {
2790
+ defaultIsOpened: true,
2796
2791
  icon: alertData[alert.type].icon,
2797
2792
  title: alertTitle,
2798
2793
  description: alert.message,