Skip to content

Commit 8db81cc

Browse files
committed
⚡️ enhance: 优化 doc-list:
- scroll to - hover 显示
1 parent 24a70f0 commit 8db81cc

File tree

4 files changed

+29
-17
lines changed

4 files changed

+29
-17
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "sy-docs-flow",
3-
"version": "0.12.1",
3+
"version": "0.12.2",
44
"type": "module",
55
"description": "",
66
"repository": "",

plugin.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "sy-docs-flow",
33
"author": "frostime",
44
"url": "https://github.com/frostime/sy-docs-flow",
5-
"version": "0.12.1",
5+
"version": "0.12.2",
66
"minAppVersion": "3.0.12",
77
"backends": [
88
"all"

src/components/docs-flow/docs-flow.svelte

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Author : Yp Z
44
Date : 2023-07-28 20:49:27
55
FilePath : /src/components/docs-flow/docs-flow.svelte
6-
LastEditTime : 2024-10-01 22:10:11
6+
LastEditTime : 2024-10-03 14:10:48
77
Description :
88
-->
99
<script lang="ts">
@@ -67,9 +67,10 @@
6767
}
6868
//然后再滚动到指定文档
6969
const queryAndScroll = () => {
70-
const ele = document.querySelector(`.docs-flow__doc[data-node-id="${id}"]`);
70+
const ele = document.querySelector(`.docs-flow__doc[data-node-id="${id}"] > .protyle-breadcrumb__item`);
7171
if (ele) {
72-
ele.scrollIntoView({ behavior: "smooth" });
72+
// ele.scrollIntoView({ behavior: "smooth", block: "start" });
73+
ele.scrollIntoView(true);
7374
return true;
7475
}
7576
return false;

src/components/docs-flow/docs-list.svelte

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Author : frostime
44
Date : 2024-10-01 20:33:19
55
FilePath : /src/components/docs-flow/docs-list.svelte
6-
LastEditTime : 2024-10-01 21:20:02
6+
LastEditTime : 2024-10-03 14:26:17
77
Description :
88
99
显示所有的文档
@@ -29,7 +29,8 @@
2929
const blocks: Block[] = await getBlocksByIds(...allDocIds);
3030
blocks.forEach((block: Block) => {
3131
docInfo[block.id] = {
32-
title: truncateString(block.fcontent || block.content, 30),
32+
// title: truncateString(block.fcontent || block.content, 40),
33+
title: block.fcontent || block.content,
3334
hpath: block.hpath,
3435
box: notebooks?.[block.box] || ""
3536
};
@@ -39,11 +40,11 @@
3940
scrollToFirstLoadedItem();
4041
});
4142
42-
function truncateString(str: string, maxLength: number): string {
43-
return str.length > maxLength
44-
? str.substring(0, maxLength) + "..."
45-
: str;
46-
}
43+
// function truncateString(str: string, maxLength: number): string {
44+
// return str.length > maxLength
45+
// ? str.substring(0, maxLength) + "..."
46+
// : str;
47+
// }
4748
4849
function isLoaded(id: BlockId): boolean {
4950
return loadedDocIds.includes(id);
@@ -65,13 +66,13 @@
6566
<h3>Documents List</h3>
6667
<ul>
6768
{#each allDocIds as docId, index}
68-
<li class:loaded={isLoaded(docId)}>
69+
<li class:loaded={isLoaded(docId)} data-node-id={docId}>
6970
<span class="doc-number">{index + 1}.</span>
70-
<span class="doc-title"
71-
>{docInfo[docId]?.title || `Document ${index + 1}`}</span
72-
>
71+
<span class="doc-title">
72+
{docInfo[docId]?.title || `Document ${index + 1}`}
73+
</span>
7374
<span class="doc-hpath">{docInfo[docId]?.box}{docInfo[docId]?.hpath || ""}</span>
74-
<button class="jump-button" on:click={() => scrollToDoc(docId)}>
75+
<button class="jump-button popover__block" data-id={docId} on:click={() => scrollToDoc(docId)}>
7576
<svg
7677
xmlns="http://www.w3.org/2000/svg"
7778
width="16"
@@ -123,6 +124,11 @@
123124
/* border-radius: 4px; */
124125
border-radius: 0px;
125126
transition: background-color 0.3s ease;
127+
cursor: default;
128+
129+
&:hover {
130+
color: var(--b3-theme-primary);
131+
}
126132
}
127133
128134
li.loaded {
@@ -147,12 +153,17 @@
147153
.doc-title {
148154
flex-grow: 1;
149155
margin-right: 10px;
156+
/* 隐藏超过限度的文字 */
157+
overflow: hidden;
158+
text-overflow: ellipsis;
159+
white-space: nowrap;
150160
}
151161
152162
.doc-hpath {
153163
font-size: 12px;
154164
color: var(--b3-theme-on-surface-light);
155165
margin-right: 10px;
166+
white-space: nowrap;
156167
}
157168
158169
.jump-button {

0 commit comments

Comments
 (0)