react-better-html 1.1.218 → 1.1.219

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
@@ -1853,6 +1853,7 @@ var defaultAlertsPluginOptions = {
1853
1853
  position: "bottom",
1854
1854
  align: "right",
1855
1855
  defaultDuration: "auto",
1856
+ defaultDisplay: {},
1856
1857
  maxWidth: 460,
1857
1858
  withLoaderBar: true,
1858
1859
  withCloseButton: true
@@ -2291,6 +2292,7 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2291
2292
  name,
2292
2293
  overflow,
2293
2294
  withoutCloseButton,
2295
+ defaultIsOpened = false,
2294
2296
  onOpen,
2295
2297
  onClose,
2296
2298
  children
@@ -2301,12 +2303,12 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2301
2303
  const { app } = useBetterHtmlContextInternal();
2302
2304
  const { colorTheme } = (0, import_react_better_core10.useBetterCoreContext)();
2303
2305
  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);
2306
+ const [isOpened, setIsOpened] = (0, import_react_better_core10.useBooleanState)(false);
2307
+ const [isOpenedLate, setIsOpenedLate] = (0, import_react_better_core10.useBooleanState)(false);
2306
2308
  const onClickOpen = (0, import_react11.useCallback)(() => {
2307
2309
  dialogRef.current?.showModal();
2308
- setIsOpened(true);
2309
- setIsOpenedLate(true);
2310
+ setIsOpened.setTrue();
2311
+ setIsOpenedLate.setTrue();
2310
2312
  if (urlQuery && name) {
2311
2313
  urlQuery.setQuery(
2312
2314
  {
@@ -2318,12 +2320,12 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2318
2320
  onOpen?.();
2319
2321
  }, [onOpen, urlQuery, name]);
2320
2322
  const onClickClose = (0, import_react11.useCallback)(() => {
2321
- setIsOpened(false);
2323
+ setIsOpened.setFalse();
2322
2324
  onClose?.();
2323
2325
  if (urlQuery && name) urlQuery.removeQuery(`${name}-modal`, false);
2324
2326
  setTimeout(() => {
2325
2327
  dialogRef.current?.close();
2326
- setIsOpenedLate(false);
2328
+ setIsOpenedLate.setFalse();
2327
2329
  }, 0.2 * 1e3);
2328
2330
  }, [onClose, urlQuery, name]);
2329
2331
  const onKeyDown = (0, import_react11.useCallback)(
@@ -2335,6 +2337,10 @@ var ModalComponent = (0, import_react11.forwardRef)(function Modal({
2335
2337
  },
2336
2338
  [withoutCloseButton]
2337
2339
  );
2340
+ (0, import_react11.useEffect)(() => {
2341
+ if (!defaultIsOpened) return;
2342
+ onClickOpen();
2343
+ }, []);
2338
2344
  (0, import_react11.useImperativeHandle)(
2339
2345
  ref,
2340
2346
  () => {
@@ -2684,6 +2690,7 @@ function Alert2({ alert }) {
2684
2690
  alert.duration ?? pluginConfig.defaultDuration ?? defaultAlertsPluginOptions.defaultDuration,
2685
2691
  alert
2686
2692
  );
2693
+ const defaultAlertDisplay = alert.display ?? pluginConfig.defaultDisplay?.[alert.type] ?? defaultAlertsPluginOptions.defaultDisplay[alert.type] ?? "default";
2687
2694
  const intervalRef = (0, import_react12.useRef)(void 0);
2688
2695
  const startTimeRef = (0, import_react12.useRef)(Date.now());
2689
2696
  const remainingTimeRef = (0, import_react12.useRef)(defaultAlertDurationNumber);
@@ -2703,7 +2710,7 @@ function Alert2({ alert }) {
2703
2710
  setProgress(newProgress);
2704
2711
  if (newProgress <= 0) {
2705
2712
  if (intervalRef.current) clearInterval(intervalRef.current);
2706
- if (alert.display === "prominent") return;
2713
+ if (defaultAlertDisplay === "prominent") return;
2707
2714
  setIsRemoved(true);
2708
2715
  setTimeout(() => {
2709
2716
  alertControls2.removeAlert(alert.id);
@@ -2714,7 +2721,7 @@ function Alert2({ alert }) {
2714
2721
  }, 0.2 * 1e3 - 10);
2715
2722
  }
2716
2723
  }, updateInterval);
2717
- }, [alert, progress]);
2724
+ }, [alert, progress, defaultAlertDisplay]);
2718
2725
  const onClickCloseAlert = (0, import_react12.useCallback)(() => {
2719
2726
  setIsRemoved(true);
2720
2727
  setTimeout(() => {
@@ -2773,13 +2780,6 @@ function Alert2({ alert }) {
2773
2780
  }),
2774
2781
  [theme2]
2775
2782
  );
2776
- (0, import_react12.useEffect)(() => {
2777
- if (alert.display === "prominent") {
2778
- setTimeout(() => {
2779
- modalRef.current?.open();
2780
- }, 0.1 * 1e3);
2781
- }
2782
- }, []);
2783
2783
  (0, import_react12.useEffect)(() => {
2784
2784
  startTimeRef.current = Date.now();
2785
2785
  remainingTimeRef.current = defaultAlertDurationNumber;
@@ -2790,9 +2790,10 @@ function Alert2({ alert }) {
2790
2790
  }, [defaultAlertDurationNumber, startProgressTimer]);
2791
2791
  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
2792
  const alertTitle = alert.title ?? alertData[alert.type].title;
2793
- return alert.display === "prominent" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2793
+ return defaultAlertDisplay === "prominent" ? /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(
2794
2794
  Modal_default,
2795
2795
  {
2796
+ defaultIsOpened: true,
2796
2797
  icon: alertData[alert.type].icon,
2797
2798
  title: alertTitle,
2798
2799
  description: alert.message,