dsh-codinput 0.3.0 → 0.3.1
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 +20 -0
- package/NOTICE +19 -0
- package/README.en.md +6 -12
- package/README.md +6 -12
- package/assets/icon.png +0 -0
- package/assets/icon.svg +1 -1
- package/assets/preview-float.webp +0 -0
- package/assets/preview-normal.webp +0 -0
- package/assets/preview-side.webp +0 -0
- package/assets/preview-split.webp +0 -0
- package/lib/client.js +39 -33
- package/package.json +1 -1
- package/src/client/components/CodinputSurface.tsx +31 -1
- package/src/client/styles.ts +8 -2
- package/assets/en/preview-ball-detail.png +0 -0
- package/assets/en/preview-float.png +0 -0
- package/assets/en/preview-normal.png +0 -0
- package/assets/en/preview-side.png +0 -0
- package/assets/en/preview-split.png +0 -0
- package/assets/preview-ball-detail.png +0 -0
- package/assets/preview-float.png +0 -0
- package/assets/preview-normal.png +0 -0
- package/assets/preview-side.png +0 -0
- package/assets/preview-split.png +0 -0
package/package.json
CHANGED
|
@@ -73,6 +73,7 @@ export function CodinputSurface(props: CodinputSurfaceProps): JSX.Element {
|
|
|
73
73
|
const cardRef = useRef<HTMLDivElement | null>(null);
|
|
74
74
|
const viewRef = useRef<EditorView | null>(null);
|
|
75
75
|
const caretRef = useRef<number | null>(null);
|
|
76
|
+
const previewRef = useRef<HTMLDivElement | null>(null);
|
|
76
77
|
|
|
77
78
|
// 高度调节:仅顶边把手,1:1 跟手(顶边上移多少、编辑区就高多少),松手持久化。
|
|
78
79
|
// 宽度不做自有调节——沿用官方聊天宽度调节器(wSkVaW_widthHandle):
|
|
@@ -245,6 +246,34 @@ export function CodinputSurface(props: CodinputSurfaceProps): JSX.Element {
|
|
|
245
246
|
[state?.draft, previewOn],
|
|
246
247
|
);
|
|
247
248
|
|
|
249
|
+
// ---- 分屏同步滚动:两侧按滚动比例互随(内容高度不同,比例映射) ----
|
|
250
|
+
// scroll 不冒泡但走捕获相位,挂在 body 上的 onScrollCapture 能收到两栏的
|
|
251
|
+
// 滚动,且 CM 视图随会话重建(scrollDOM 换新)也无需重挂监听;epsilon 防
|
|
252
|
+
// 两侧事件互馈成回环。预览栏不显示滚动条(编辑栏为主),滚轮仍可反向带动。
|
|
253
|
+
const syncSplitScroll = (event: React.SyntheticEvent<HTMLDivElement>): void => {
|
|
254
|
+
if (!editOn || !previewOn) return;
|
|
255
|
+
const src = event.target as HTMLElement;
|
|
256
|
+
const editorScroll = viewRef.current?.scrollDOM;
|
|
257
|
+
const previewScroll = previewRef.current;
|
|
258
|
+
if (!editorScroll || !previewScroll) return;
|
|
259
|
+
const dst = src === editorScroll ? previewScroll : src === previewScroll ? editorScroll : null;
|
|
260
|
+
if (!dst) return;
|
|
261
|
+
const srcMax = src.scrollHeight - src.clientHeight;
|
|
262
|
+
if (srcMax <= 0) return;
|
|
263
|
+
const top = (src.scrollTop / srcMax) * (dst.scrollHeight - dst.clientHeight);
|
|
264
|
+
if (Math.abs(dst.scrollTop - top) > 1) dst.scrollTop = top;
|
|
265
|
+
};
|
|
266
|
+
// 进入分屏 / 草稿更新 / 切会话后,预览按编辑器当前比例对齐。
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
if (!editOn || !previewOn) return;
|
|
269
|
+
const editorScroll = viewRef.current?.scrollDOM;
|
|
270
|
+
const previewScroll = previewRef.current;
|
|
271
|
+
if (!editorScroll || !previewScroll) return;
|
|
272
|
+
const editorMax = editorScroll.scrollHeight - editorScroll.clientHeight;
|
|
273
|
+
if (editorMax <= 0) return;
|
|
274
|
+
previewScroll.scrollTop = (editorScroll.scrollTop / editorMax) * (previewScroll.scrollHeight - previewScroll.clientHeight);
|
|
275
|
+
}, [editOn, previewOn, html, sessionId]);
|
|
276
|
+
|
|
248
277
|
const toggleEdit = (): void => {
|
|
249
278
|
if (!editOn && previewOn) setEditOn(true);
|
|
250
279
|
else if (editOn && previewOn) setEditOn(false);
|
|
@@ -329,6 +358,7 @@ export function CodinputSurface(props: CodinputSurfaceProps): JSX.Element {
|
|
|
329
358
|
<div
|
|
330
359
|
className="dci-body"
|
|
331
360
|
data-split={editOn && previewOn}
|
|
361
|
+
onScrollCapture={syncSplitScroll}
|
|
332
362
|
style={
|
|
333
363
|
!side && !float && bodyHeight !== null
|
|
334
364
|
? ({ '--dci-body-h': `${bodyHeight}px`, '--dci-body-max': `${bodyHeight}px` } as React.CSSProperties)
|
|
@@ -352,7 +382,7 @@ export function CodinputSurface(props: CodinputSurfaceProps): JSX.Element {
|
|
|
352
382
|
/>
|
|
353
383
|
) : null}
|
|
354
384
|
{previewOn ? (
|
|
355
|
-
<div className="dci-preview" data-solo={!editOn}>
|
|
385
|
+
<div className="dci-preview" data-solo={!editOn} ref={previewRef}>
|
|
356
386
|
{html ? <div dangerouslySetInnerHTML={{ __html: html }} /> : <span style={{ opacity: 0.4 }}>{t("preview.empty")}</span>}
|
|
357
387
|
</div>
|
|
358
388
|
) : null}
|
package/src/client/styles.ts
CHANGED
|
@@ -50,8 +50,14 @@ const CSS = `
|
|
|
50
50
|
.dci-body { position: relative; display: flex; gap: 0; min-height: 60px; max-height: var(--dci-body-max, 46vh); overflow: hidden; }
|
|
51
51
|
.dci-body[style*="--dci-body-h"] { height: var(--dci-body-h); }
|
|
52
52
|
/* 分屏:grid 等宽两栏(fr 计入 padding/border,两栏边界严格居中;flex
|
|
53
|
-
* 会把预览栏的横向 padding
|
|
54
|
-
|
|
53
|
+
* 会把预览栏的横向 padding 泄漏进空间分配,做不到对半)。行高必须
|
|
54
|
+
* minmax(0,1fr)+两栏 min-height:0:隐式 auto 行随内容撑高、不受 max-height
|
|
55
|
+
* 钳制,内容一高整行溢出被 overflow:hidden 裁掉,两栏都出不了滚动条。 */
|
|
56
|
+
.dci-body[data-split="true"] { display: grid; grid-template-columns: 1fr 1fr; grid-template-rows: minmax(0, 1fr); }
|
|
57
|
+
.dci-body[data-split="true"] > * { min-height: 0; }
|
|
58
|
+
/* 分屏同步滚动:只留编辑栏一个滚动条,预览栏藏起但滚轮仍可反向带动编辑器。 */
|
|
59
|
+
.dci-body[data-split="true"] .dci-preview { scrollbar-width: none; }
|
|
60
|
+
.dci-body[data-split="true"] .dci-preview::-webkit-scrollbar { display: none; }
|
|
55
61
|
.dci-body[data-split="true"] .dci-editor-wrap { border-right: 1px solid var(--dsw-alias-border-l2, color-mix(in srgb, currentColor 12%, transparent)); }
|
|
56
62
|
.dci-editor-wrap { position: relative; flex: 1 1 100%; min-width: 0; box-sizing: border-box; display: flex; flex-direction: column; }
|
|
57
63
|
.dci-editor-wrap[data-solo="true"] { flex-basis: 100%; }
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
package/assets/preview-float.png
DELETED
|
Binary file
|
|
Binary file
|
package/assets/preview-side.png
DELETED
|
Binary file
|
package/assets/preview-split.png
DELETED
|
Binary file
|