mirror of
https://github.com/zoriya/v10.git
synced 2026-08-16 02:45:09 +00:00
build(react): build26 from 45504a2b
This commit is contained in:
+57
@@ -0,0 +1,57 @@
|
||||
"use client";
|
||||
import { usePlayer } from "../../player/context.js";
|
||||
import { useLatestRef } from "../../utils/use-latest-ref.js";
|
||||
import { useDestroy } from "../../utils/use-destroy.js";
|
||||
import { AlertDialogContextProvider } from "../alert-dialog/context.js";
|
||||
import { useSafeId } from "../../utils/use-safe-id.js";
|
||||
import { ErrorDialogContextProvider } from "./context.js";
|
||||
import { createAlertDialog, createTransition, selectError } from "@videojs/core/dom";
|
||||
import { useSnapshot } from "@videojs/store/react";
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { jsx } from "react/jsx-runtime";
|
||||
import { AlertDialogDataAttrs, ErrorDialogCore } from "@videojs/core";
|
||||
//#region src/ui/error-dialog/error-dialog-root.tsx
|
||||
function ErrorDialogRoot({ children }) {
|
||||
const [core] = useState(() => new ErrorDialogCore());
|
||||
const errorState = usePlayer(selectError);
|
||||
const lastError = useRef(errorState?.error ?? null);
|
||||
if (errorState?.error) lastError.current = errorState.error;
|
||||
const errorStateRef = useLatestRef(errorState);
|
||||
const [dialog] = useState(() => createAlertDialog({
|
||||
transition: createTransition(),
|
||||
onOpenChange: (nextOpen) => {
|
||||
if (!nextOpen) errorStateRef.current?.dismissError();
|
||||
}
|
||||
}));
|
||||
const titleId = useSafeId("error-dialog-title");
|
||||
const descriptionId = useSafeId("error-dialog-desc");
|
||||
core.setTitleId(titleId);
|
||||
core.setDescriptionId(descriptionId);
|
||||
useEffect(() => {
|
||||
const hasError = Boolean(errorState?.error);
|
||||
const { active: isOpen } = dialog.input.current;
|
||||
if (hasError && !isOpen) dialog.open();
|
||||
else if (!hasError && isOpen) dialog.close();
|
||||
}, [errorState?.error, dialog]);
|
||||
useDestroy(dialog);
|
||||
const input = useSnapshot(dialog.input);
|
||||
core.setInput(input);
|
||||
const state = core.getState();
|
||||
if (!errorState) return null;
|
||||
return /* @__PURE__ */ jsx(ErrorDialogContextProvider, {
|
||||
value: { lastError: lastError.current },
|
||||
children: /* @__PURE__ */ jsx(AlertDialogContextProvider, {
|
||||
value: {
|
||||
core,
|
||||
dialog,
|
||||
state,
|
||||
stateAttrMap: AlertDialogDataAttrs
|
||||
},
|
||||
children
|
||||
})
|
||||
});
|
||||
}
|
||||
//#endregion
|
||||
export { ErrorDialogRoot };
|
||||
|
||||
//# sourceMappingURL=error-dialog-root.js.map
|
||||
Reference in New Issue
Block a user