@ai-matrx/media 0.4.0 → 0.4.2

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/viewers.js CHANGED
@@ -1,5 +1,8 @@
1
1
  "use client";
2
2
 
3
+ // src/viewers/media-file-viewer.tsx
4
+ import { createElement as createElement3 } from "react";
5
+
3
6
  // src/viewers/registry.ts
4
7
  var VIEWER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.media.viewer-registry");
5
8
  var HIGHLIGHTER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.media.code-highlighter");
@@ -42,7 +45,7 @@ function getMediaCodeHighlighter() {
42
45
  }
43
46
 
44
47
  // src/viewers/code-viewer.tsx
45
- import { useMemo as useMemo2, useState as useState4 } from "react";
48
+ import { createElement as createElement2, useMemo as useMemo2, useState as useState4 } from "react";
46
49
 
47
50
  // src/react/cn.ts
48
51
  import { twMerge } from "tailwind-merge";
@@ -642,7 +645,7 @@ function useViewerDisplayUrl(source) {
642
645
  }
643
646
 
644
647
  // src/viewers/code-viewer.tsx
645
- import { Fragment, jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
648
+ import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
646
649
  var EXT_TO_LANGUAGE = {
647
650
  js: "javascript",
648
651
  jsx: "jsx",
@@ -752,7 +755,15 @@ function CodeViewer({
752
755
  /* @__PURE__ */ jsx3(ViewerCopyButton, { text })
753
756
  ] })
754
757
  ] }),
755
- /* @__PURE__ */ jsx3("div", { className: "min-h-0 flex-1 overflow-auto", children: highlighter ? /* @__PURE__ */ jsx3(Fragment, { children: highlighter({ code: text, language }) }) : /* @__PURE__ */ jsxs3("pre", { className: "m-0 flex p-3 font-mono text-xs leading-5", children: [
758
+ /* @__PURE__ */ jsx3("div", { className: "min-h-0 flex-1 overflow-auto", children: highlighter ? (
759
+ // Mounted as an element, never called — a real highlighter reads the
760
+ // host's theme with a hook, and calling it would put that hook in
761
+ // THIS component's list (see the note in media-file-viewer.tsx).
762
+ createElement2(
763
+ highlighter,
764
+ { code: text, language }
765
+ )
766
+ ) : /* @__PURE__ */ jsxs3("pre", { className: "m-0 flex p-3 font-mono text-xs leading-5", children: [
756
767
  /* @__PURE__ */ jsx3(
757
768
  "code",
758
769
  {
@@ -1381,7 +1392,7 @@ function HtmlSourceView({ source, maxBytes = 1024 * 1024 }) {
1381
1392
  }
1382
1393
 
1383
1394
  // src/core/use-media-load-recovery.ts
1384
- import { useEffect as useEffect6, useRef as useRef3, useState as useState8 } from "react";
1395
+ import { useEffect as useEffect6, useLayoutEffect, useRef as useRef3, useState as useState8 } from "react";
1385
1396
 
1386
1397
  // src/types.ts
1387
1398
  function mintDurableSrc(url) {
@@ -1401,11 +1412,17 @@ function useMediaLoadRecovery(src, options) {
1401
1412
  const failureRef = options?.failureRef;
1402
1413
  const [result, setResult] = useState8({ source: src, retryKey: 0, failed: false });
1403
1414
  const attemptRef = useRef3(0);
1415
+ const recoveryInFlightRef = useRef3(false);
1404
1416
  useEffect6(() => {
1405
1417
  attemptRef.current = 0;
1418
+ recoveryInFlightRef.current = false;
1406
1419
  }, [src]);
1420
+ useLayoutEffect(() => {
1421
+ recoveryInFlightRef.current = false;
1422
+ }, [result.retryKey]);
1407
1423
  const identity = () => failureMediaIdentity(failureRef ?? null, src);
1408
1424
  const onLoadError = (event) => {
1425
+ if (recoveryInFlightRef.current) return;
1409
1426
  if (!src || !recoverable) {
1410
1427
  setResult({ source: src, retryKey: 0, failed: true });
1411
1428
  if (src) {
@@ -1420,6 +1437,7 @@ function useMediaLoadRecovery(src, options) {
1420
1437
  onTerminal?.(event);
1421
1438
  return;
1422
1439
  }
1440
+ recoveryInFlightRef.current = true;
1423
1441
  attemptRef.current += 1;
1424
1442
  const attempt = attemptRef.current;
1425
1443
  client.recoverLoadError(mintDurableSrc(src), attempt).then(
@@ -1683,7 +1701,7 @@ function getPreviewKind(fileName, mimeType) {
1683
1701
  }
1684
1702
 
1685
1703
  // src/viewers/media-file-viewer.tsx
1686
- import { Fragment as Fragment2, jsx as jsx12 } from "react/jsx-runtime";
1704
+ import { jsx as jsx12 } from "react/jsx-runtime";
1687
1705
  var BUILT_IN = {
1688
1706
  text: TextViewer,
1689
1707
  code: CodeViewer,
@@ -1696,10 +1714,8 @@ function MediaFileViewer({
1696
1714
  ...props
1697
1715
  }) {
1698
1716
  const kind = previewKind ?? getPreviewKind(props.fileName, props.mimeType ?? null);
1699
- const registered = getMediaViewer(kind);
1700
- if (registered) return /* @__PURE__ */ jsx12(Fragment2, { children: registered(props) });
1701
- const builtIn = BUILT_IN[kind];
1702
- if (builtIn) return /* @__PURE__ */ jsx12(Fragment2, { children: builtIn(props) });
1717
+ const viewer = getMediaViewer(kind) ?? BUILT_IN[kind];
1718
+ if (viewer) return createElement3(viewer, props);
1703
1719
  return /* @__PURE__ */ jsx12(MediaViewerUnavailable, { ...props, kind });
1704
1720
  }
1705
1721
  export {