@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/CHANGELOG.md +40 -0
- package/README.md +4 -0
- package/dist/core.cjs +7 -0
- package/dist/core.cjs.map +1 -1
- package/dist/core.js +8 -1
- package/dist/core.js.map +1 -1
- package/dist/react.cjs +7 -0
- package/dist/react.cjs.map +1 -1
- package/dist/react.js +8 -1
- package/dist/react.js.map +1 -1
- package/dist/viewers.cjs +21 -5
- package/dist/viewers.cjs.map +1 -1
- package/dist/viewers.js +25 -9
- package/dist/viewers.js.map +1 -1
- package/package.json +1 -1
package/dist/viewers.cjs
CHANGED
|
@@ -46,6 +46,9 @@ __export(viewers_exports, {
|
|
|
46
46
|
});
|
|
47
47
|
module.exports = __toCommonJS(viewers_exports);
|
|
48
48
|
|
|
49
|
+
// src/viewers/media-file-viewer.tsx
|
|
50
|
+
var import_react12 = require("react");
|
|
51
|
+
|
|
49
52
|
// src/viewers/registry.ts
|
|
50
53
|
var VIEWER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.media.viewer-registry");
|
|
51
54
|
var HIGHLIGHTER_SLOT = /* @__PURE__ */ Symbol.for("ai-matrx.media.code-highlighter");
|
|
@@ -794,7 +797,15 @@ function CodeViewer({
|
|
|
794
797
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(ViewerCopyButton, { text })
|
|
795
798
|
] })
|
|
796
799
|
] }),
|
|
797
|
-
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "min-h-0 flex-1 overflow-auto", children: highlighter ?
|
|
800
|
+
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)("div", { className: "min-h-0 flex-1 overflow-auto", children: highlighter ? (
|
|
801
|
+
// Mounted as an element, never called — a real highlighter reads the
|
|
802
|
+
// host's theme with a hook, and calling it would put that hook in
|
|
803
|
+
// THIS component's list (see the note in media-file-viewer.tsx).
|
|
804
|
+
(0, import_react7.createElement)(
|
|
805
|
+
highlighter,
|
|
806
|
+
{ code: text, language }
|
|
807
|
+
)
|
|
808
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime3.jsxs)("pre", { className: "m-0 flex p-3 font-mono text-xs leading-5", children: [
|
|
798
809
|
/* @__PURE__ */ (0, import_jsx_runtime3.jsx)(
|
|
799
810
|
"code",
|
|
800
811
|
{
|
|
@@ -1443,11 +1454,17 @@ function useMediaLoadRecovery(src, options) {
|
|
|
1443
1454
|
const failureRef = options?.failureRef;
|
|
1444
1455
|
const [result, setResult] = (0, import_react11.useState)({ source: src, retryKey: 0, failed: false });
|
|
1445
1456
|
const attemptRef = (0, import_react11.useRef)(0);
|
|
1457
|
+
const recoveryInFlightRef = (0, import_react11.useRef)(false);
|
|
1446
1458
|
(0, import_react11.useEffect)(() => {
|
|
1447
1459
|
attemptRef.current = 0;
|
|
1460
|
+
recoveryInFlightRef.current = false;
|
|
1448
1461
|
}, [src]);
|
|
1462
|
+
(0, import_react11.useLayoutEffect)(() => {
|
|
1463
|
+
recoveryInFlightRef.current = false;
|
|
1464
|
+
}, [result.retryKey]);
|
|
1449
1465
|
const identity = () => failureMediaIdentity(failureRef ?? null, src);
|
|
1450
1466
|
const onLoadError = (event) => {
|
|
1467
|
+
if (recoveryInFlightRef.current) return;
|
|
1451
1468
|
if (!src || !recoverable) {
|
|
1452
1469
|
setResult({ source: src, retryKey: 0, failed: true });
|
|
1453
1470
|
if (src) {
|
|
@@ -1462,6 +1479,7 @@ function useMediaLoadRecovery(src, options) {
|
|
|
1462
1479
|
onTerminal?.(event);
|
|
1463
1480
|
return;
|
|
1464
1481
|
}
|
|
1482
|
+
recoveryInFlightRef.current = true;
|
|
1465
1483
|
attemptRef.current += 1;
|
|
1466
1484
|
const attempt = attemptRef.current;
|
|
1467
1485
|
client.recoverLoadError(mintDurableSrc(src), attempt).then(
|
|
@@ -1738,10 +1756,8 @@ function MediaFileViewer({
|
|
|
1738
1756
|
...props
|
|
1739
1757
|
}) {
|
|
1740
1758
|
const kind = previewKind ?? getPreviewKind(props.fileName, props.mimeType ?? null);
|
|
1741
|
-
const
|
|
1742
|
-
if (
|
|
1743
|
-
const builtIn = BUILT_IN[kind];
|
|
1744
|
-
if (builtIn) return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(import_jsx_runtime12.Fragment, { children: builtIn(props) });
|
|
1759
|
+
const viewer = getMediaViewer(kind) ?? BUILT_IN[kind];
|
|
1760
|
+
if (viewer) return (0, import_react12.createElement)(viewer, props);
|
|
1745
1761
|
return /* @__PURE__ */ (0, import_jsx_runtime12.jsx)(MediaViewerUnavailable, { ...props, kind });
|
|
1746
1762
|
}
|
|
1747
1763
|
//# sourceMappingURL=viewers.cjs.map
|