@cherrystudio/file-preview 0.2.2 → 0.2.3
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/README.md
CHANGED
|
@@ -64,6 +64,11 @@ without splitting a surrogate pair; an empty normalized excerpt produces `null`.
|
|
|
64
64
|
Callback references are stabilized inside `Preview`, so inline callbacks do not
|
|
65
65
|
reopen documents or repeat a selection notification merely because the host rendered.
|
|
66
66
|
|
|
67
|
+
DOCX text supports native selection and copying with Ctrl+C (Cmd+C on macOS),
|
|
68
|
+
including across paragraphs. Copying uses the browser selection, not the normalized
|
|
69
|
+
or length-limited reference excerpt. While paragraph picking is enabled, ending a
|
|
70
|
+
text drag preserves the existing paragraph pick; a plain click still picks or clears it.
|
|
71
|
+
|
|
67
72
|
Recognized `source.mediaType` values take precedence over the filename extension;
|
|
68
73
|
missing or unrecognized media types fall back to the extension. `supportsPreview`
|
|
69
74
|
and `canSelectPreview` accept the same optional media type as their second argument.
|
|
@@ -3841,6 +3841,7 @@ function WordFilePreview({ sourceId, fileName, document: previewDocument, onSele
|
|
|
3841
3841
|
const docxClassName = `docx-preview-${useId().replace(/[^a-zA-Z0-9_-]/g, "")}`;
|
|
3842
3842
|
const containerRef = useRef(null);
|
|
3843
3843
|
const bodyRef = useRef(null);
|
|
3844
|
+
const pressPositionRef = useRef(null);
|
|
3844
3845
|
const styleRef = useRef(null);
|
|
3845
3846
|
const renderTokenRef = useRef(0);
|
|
3846
3847
|
const fitScrollTopRef = useRef(null);
|
|
@@ -4027,9 +4028,14 @@ function WordFilePreview({ sourceId, fileName, document: previewDocument, onSele
|
|
|
4027
4028
|
return () => observer.disconnect();
|
|
4028
4029
|
}, [pageCount, loading]);
|
|
4029
4030
|
const handlePick = useCallback((event) => {
|
|
4031
|
+
const pressPosition = pressPositionRef.current;
|
|
4032
|
+
pressPositionRef.current = null;
|
|
4030
4033
|
if (!onSelection || !(event.target instanceof Element)) return;
|
|
4031
4034
|
if (event.target.closest("a[href]")) event.preventDefault();
|
|
4032
|
-
const
|
|
4035
|
+
const bodyContainer = bodyRef.current;
|
|
4036
|
+
const selection = bodyContainer?.ownerDocument.getSelection();
|
|
4037
|
+
if (pressPosition && (event.clientX !== pressPosition.x || event.clientY !== pressPosition.y) && bodyContainer && selection && !selection.isCollapsed && selection.rangeCount > 0 && selection.getRangeAt(0).intersectsNode(bodyContainer)) return;
|
|
4038
|
+
const previous = bodyContainer?.querySelector("[data-docx-picked=\"true\"]") ?? null;
|
|
4033
4039
|
const resolved = paragraphToDocxAnchor(event.target);
|
|
4034
4040
|
previous?.removeAttribute("data-docx-picked");
|
|
4035
4041
|
if (!resolved || resolved.element === previous) {
|
|
@@ -4106,9 +4112,15 @@ function WordFilePreview({ sourceId, fileName, document: previewDocument, onSele
|
|
|
4106
4112
|
"data-testid": "docx-preview-content",
|
|
4107
4113
|
"data-zoom": zoom,
|
|
4108
4114
|
"data-picker": onSelection ? "true" : void 0,
|
|
4115
|
+
onMouseDown: (event) => {
|
|
4116
|
+
pressPositionRef.current = {
|
|
4117
|
+
x: event.clientX,
|
|
4118
|
+
y: event.clientY
|
|
4119
|
+
};
|
|
4120
|
+
},
|
|
4109
4121
|
onClick: handlePick,
|
|
4110
4122
|
style: contentStyle,
|
|
4111
|
-
className: "mx-auto w-fit min-w-0 [&_.docx-preview]:box-border [&_.docx-preview]:max-w-full [&_.docx-preview-wrapper]:mx-auto [&_p[data-docx-picked=true]]:bg-primary/15 [&_p[data-docx-picked=true]]:outline [&_p[data-docx-picked=true]]:outline-1 [&_p[data-docx-picked=true]]:outline-primary/60 [&_section]:overflow-hidden [&_section]:rounded-sm [&_section]:shadow-md [&[data-picker=true]_p[data-docx-part=body]]:cursor-pointer [&[data-picker=true]_p[data-docx-part=body]:not([data-docx-picked=true]):hover]:bg-primary/10"
|
|
4123
|
+
className: "selectable mx-auto w-fit min-w-0 [&_.docx-preview]:box-border [&_.docx-preview]:max-w-full [&_.docx-preview-wrapper]:mx-auto [&_p[data-docx-picked=true]]:bg-primary/15 [&_p[data-docx-picked=true]]:outline [&_p[data-docx-picked=true]]:outline-1 [&_p[data-docx-picked=true]]:outline-primary/60 [&_section]:overflow-hidden [&_section]:rounded-sm [&_section]:shadow-md [&[data-picker=true]_p[data-docx-part=body]]:cursor-pointer [&[data-picker=true]_p[data-docx-part=body]:not([data-docx-picked=true]):hover]:bg-primary/10"
|
|
4112
4124
|
})]
|
|
4113
4125
|
}),
|
|
4114
4126
|
loading ? /* @__PURE__ */ jsxs("div", {
|
package/dist/react.js
CHANGED
|
@@ -63,7 +63,7 @@ var plugins = [
|
|
|
63
63
|
id: "word",
|
|
64
64
|
extensions: ["docx"],
|
|
65
65
|
mediaTypes: ["application/vnd.openxmlformats-officedocument.wordprocessingml.document"],
|
|
66
|
-
load: () => import("./WordFilePreview-
|
|
66
|
+
load: () => import("./WordFilePreview-Do062CDe.js"),
|
|
67
67
|
supportsSelectionReference: true
|
|
68
68
|
}
|
|
69
69
|
];
|