Skip to content

Commit 3f73a35

Browse files
committed
fuck you , wasting time
1 parent 3abd01d commit 3f73a35

File tree

4 files changed

+47
-14
lines changed

4 files changed

+47
-14
lines changed

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

+31-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
let showToolbar: boolean = false;
2525
2626
const getAllDocIds = getContext("getAllDocIds") as () => BlockId[];
27-
const getLoadedDocIds = getContext("getLoadedDocIds") as () => BlockId[];
27+
// const getLoadedDocIds = getContext("getLoadedDocIds") as () => BlockId[];
2828
const jumpToDoc = getContext("jumpToDoc") as (id: BlockId) => void;
2929
3030
function onConfigChanged() {
@@ -169,15 +169,44 @@
169169
});
170170
};
171171
172+
const getDocsFlow = getContext("docsFlow") as () => HTMLElement;
173+
174+
const getCurrentProtyle = (): BlockId[] => {
175+
const docsFlow = getDocsFlow();
176+
if (!docsFlow) return [];
177+
178+
// 获取容器在视口中的实际可见位置
179+
const rect = docsFlow.getBoundingClientRect();
180+
const visibleTop = rect.top;
181+
const visibleBottom = rect.bottom;
182+
183+
const protyles = docsFlow.querySelectorAll(".docs-flow__doc");
184+
const visibleIds: BlockId[] = [];
185+
186+
protyles.forEach((protyle: HTMLElement) => {
187+
const protyleRect = protyle.getBoundingClientRect();
188+
const id = protyle.getAttribute("data-node-id");
189+
190+
if (protyleRect.bottom > visibleTop && protyleRect.top < visibleBottom && id) {
191+
visibleIds.push(id);
192+
}
193+
});
194+
195+
return visibleIds;
196+
};
197+
172198
const showDocsFlowOutline = () => {
199+
const ids = getCurrentProtyle();
200+
// console.log(visibleIds);
201+
173202
const { close } = svelteDialog({
174203
title: "Outline",
175204
constructor: (container: HTMLElement) => {
176205
return new DocsFlowOutline({
177206
target: container,
178207
props: {
179208
allDocIds: getAllDocIds(),
180-
loadedDocIds: getLoadedDocIds(),
209+
hightlightIds: ids || [],
181210
jumpToDoc: (id: BlockId) => {
182211
jumpToDoc(id);
183212
close();

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

+7-3
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 : 2025-01-18 18:40:13
6+
LastEditTime : 2025-01-18 19:03:34
77
Description :
88
-->
99
<script lang="ts">
@@ -208,10 +208,13 @@
208208
209209
//全局 css,用于隐藏gutter
210210
let hideGutterClass: "" | "hide-gutter" = "";
211-
let container: HTMLElement;
211+
let docsFlow: HTMLElement;
212+
213+
setContext("docsFlow", () => docsFlow);
214+
212215
</script>
213216

214-
<main class="docs-flow-container" bind:this={container}>
217+
<main class="docs-flow-container">
215218
<Toolbar
216219
bind:rule
217220
bind:config
@@ -224,6 +227,7 @@
224227
<div
225228
class="docs-flow fn__flex-1 {hideGutterClass}"
226229
style="--display-breadcrumb: {isMobile() ? 'none' : 'flex'}"
230+
bind:this={docsFlow}
227231
>
228232
{#each loadIdList as did, i (did)}
229233
<Protyle

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

+3-3
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-11-17 18:41:11
6+
LastEditTime : 2025-01-18 19:20:08
77
Description :
88
99
显示所有的文档
@@ -20,7 +20,7 @@
2020
import { onMount } from "svelte";
2121
2222
export let allDocIds: BlockId[];
23-
export let loadedDocIds: BlockId[];
23+
export let hightlightIds: BlockId[];
2424
export let jumpToDoc: (id: BlockId) => void;
2525
2626
let docInfo: Record<BlockId, { title: string; hpath: string; box: string }> = {};
@@ -47,7 +47,7 @@
4747
// }
4848
4949
function isLoaded(id: BlockId): boolean {
50-
return loadedDocIds.includes(id);
50+
return hightlightIds.includes(id);
5151
}
5252
5353
function scrollToDoc(id: BlockId) {

src/components/docs-flow/protyle.svelte

+6-6
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
let prefix = notebookName ? `/${notebookName}` : "";
8787
hpath = prefix + rootDoc.hpath;
8888
89-
console.debug("Mount protyle:", notebookName, hpath, blockId);
89+
// console.debug("Mount protyle:", notebookName, hpath, blockId);
9090
Flag.initialised = true;
9191
ChangeStatus.collapseBarChanged = false; //TODO 这个解决方案很不优雅,后面有空改掉
9292
// ChangeStatus.scrollingChanged = false;
@@ -126,11 +126,11 @@
126126
return;
127127
}
128128
updateProtyleMaxHeight();
129-
console.log("load protyle", {
130-
title: config.protyleTitle,
131-
mode: config.readonly ? "preview" : "wysiwyg",
132-
scroll: config.scroll,
133-
});
129+
// console.log("load protyle", {
130+
// title: config.protyleTitle,
131+
// mode: config.readonly ? "preview" : "wysiwyg",
132+
// scroll: config.scroll,
133+
// });
134134
protyle = new Protyle(app, divProtyle, {
135135
mode: config.readonly ? "preview" : "wysiwyg",
136136
action: ["cb-get-all"],

0 commit comments

Comments
 (0)