Skip to content

Commit f7c3990

Browse files
committed
Merge branch 'dev'
2 parents 0768e69 + 3f73a35 commit f7c3990

9 files changed

+279
-145
lines changed

package.json

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
11
{
22
"name": "sy-docs-flow",
3-
"version": "0.12.3",
3+
"version": "0.13.0",
44
"type": "module",
55
"description": "",
66
"repository": "",
77
"homepage": "",
88
"author": "",
99
"license": "MIT",
1010
"scripts": {
11-
"make-link": "node --no-warnings ./scripts/make_dev_link.js",
12-
"dev": "vite build --watch",
13-
"build": "vite build"
11+
"dev": "cross-env NODE_ENV=development VITE_SOURCEMAP=inline vite build --watch",
12+
"build": "cross-env NODE_ENV=production vite build",
13+
"make-install": "vite build && npx make-install"
1414
},
1515
"devDependencies": {
1616
"@sveltejs/vite-plugin-svelte": "^2.5.3",
1717
"@tsconfig/svelte": "^5.0.4",
1818
"@types/node": "^20.2.0",
19+
"cross-env": "^7.0.3",
1920
"eslint": "^8.42.0",
2021
"fast-glob": "^3.2.12",
2122
"glob": "^10.4.5",
2223
"js-yaml": "^4.1.0",
2324
"minimist": "^1.2.8",
2425
"rollup-plugin-livereload": "^2.0.5",
2526
"sass": "^1.62.1",
26-
"siyuan": "^1.0.3",
27+
"siyuan": "^1.0.8",
2728
"svelte": "^4.2.19",
2829
"ts-node": "^10.9.1",
2930
"typescript": "^5.0.4",

plugin.json

+1-1
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.3",
5+
"version": "0.13.0",
66
"minAppVersion": "3.1.10",
77
"backends": [
88
"all"

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

+87-17
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,7 +169,35 @@
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);
173201
174202
const { close } = svelteDialog({
175203
title: "Outline",
@@ -178,11 +206,11 @@
178206
target: container,
179207
props: {
180208
allDocIds: getAllDocIds(),
181-
loadedDocIds: getLoadedDocIds(),
209+
hightlightIds: ids || [],
182210
jumpToDoc: (id: BlockId) => {
183211
jumpToDoc(id);
184212
close();
185-
}
213+
},
186214
},
187215
});
188216
},
@@ -205,7 +233,7 @@
205233
</script>
206234

207235
<div
208-
class="docs-flow__toolbar {classNamePin}"
236+
class="docs-flow__toolbar {classNamePin} {isMobile() ? 'is-mobile' : ''}"
209237
on:mouseenter={() => {
210238
if (pinToolbar) return;
211239
showToolbar = true;
@@ -248,7 +276,7 @@
248276
</svg>
249277

250278
<svg
251-
class="svg-button ariaLabel"
279+
class="svg-button ariaLabel hide-if-very-narrow"
252280
aria-label={i18n.button.reverse}
253281
on:click={() => {
254282
listDocumentIds = listDocumentIds.reverse();
@@ -260,7 +288,7 @@
260288
</svg>
261289

262290
<svg
263-
class="svg-button ariaLabel"
291+
class="svg-button ariaLabel hide-if-very-narrow"
264292
aria-label={i18n.button.edit}
265293
on:click={editRuleValue}
266294
on:keypress={() => {}}
@@ -294,7 +322,7 @@
294322

295323
<input
296324
id="displayBreadcrumb"
297-
class="b3-switch fn__flex-center"
325+
class="b3-switch fn__flex-center hide-if-very-narrow"
298326
type="checkbox"
299327
bind:checked={config.breadcrumb}
300328
on:change={onConfigChanged}
@@ -312,13 +340,16 @@
312340
class="fn__flex {isMobile() ? 'fn__none' : ''}"
313341
style="gap: 5px;"
314342
>
315-
<button class="b3-button hide-if-need" on:click={onRenameThis}
343+
<button class="b3-button hide-if-narrow" on:click={onRenameThis}
316344
>{i18n.nameTab}</button
317345
>
318-
<button class="b3-button" on:click={onSaveThis}>
346+
<button
347+
class="b3-button hide-if-very-narrow"
348+
on:click={onSaveThis}
349+
>
319350
{i18n.saveRule}
320351
</button>
321-
<button class="b3-button hide-if-need" on:click={onCopyLink}>
352+
<button class="b3-button hide-if-narrow" on:click={onCopyLink}>
322353
{i18n.copyLink}
323354
</button>
324355
</div>
@@ -330,41 +361,80 @@
330361
.docs-flow__toolbar {
331362
height: 3rem;
332363
padding: 0;
333-
334364
position: absolute;
365+
366+
--width: 70%;
367+
--left: calc(calc(100% - var(--width)) / 2);
368+
335369
width: var(--width);
336370
left: var(--left);
337371
338372
top: 15px;
339373
z-index: 10;
340-
341374
display: flex;
342375
justify-content: center;
343376
align-items: center;
377+
378+
container-type: inline-size;
379+
container-name: docs-flow-toolbar;
344380
}
345381
346382
.docs-flow__toolbar section.docs-flow__toolbar-body {
347383
display: flex;
348384
flex-wrap: wrap;
349385
align-items: center;
350386
gap: 5px;
351-
352387
padding: 4px 5px;
353-
width: 600px;
354-
height: 30px;
355388
389+
height: 30px;
356390
background-color: var(--b3-theme-surface);
357391
opacity: 1;
358392
border-radius: 10px;
359393
box-shadow:
360394
0 0.5em 1em -0.125em var(--b3-theme-primary-light),
361395
0 0 0 1px var(--b3-theme-primary-light);
362396
363-
overflow: hidden; /* 添加这行以隐藏溢出的内容 */
364-
365397
#space {
366398
flex: 1;
367399
}
400+
401+
flex-wrap: nowrap;
402+
403+
@container docs-flow-toolbar (max-width: 600px) {
404+
.b3-label__text {
405+
display: none;
406+
}
407+
.hide-if-narrow {
408+
display: none;
409+
}
410+
}
411+
412+
@container docs-flow-toolbar (max-width: 400px) {
413+
.hide-if-very-narrow {
414+
display: none;
415+
}
416+
}
417+
}
418+
419+
.docs-flow__toolbar.is-mobile {
420+
--width: 90%;
421+
top: 25px;
422+
section.docs-flow__toolbar-body {
423+
width: 70%;
424+
min-width: max-content;
425+
}
426+
}
427+
.docs-flow__toolbar:not(.is-mobile) {
428+
--width: 80%;
429+
430+
section.docs-flow__toolbar-body {
431+
@container docs-flow-toolbar (min-width: 720px) {
432+
width: 720px;
433+
}
434+
@container docs-flow-toolbar (max-width: 720px) {
435+
width: 100%;
436+
}
437+
}
368438
}
369439
370440
.docs-flow__toolbar svg.svg-button {

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

+46-33
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-03 14:10:48
6+
LastEditTime : 2025-01-18 19:03:34
77
Description :
88
-->
99
<script lang="ts">
@@ -18,21 +18,21 @@
1818
1919
export let app: any;
2020
export let rule: MatchRule;
21-
export let listDocumentIds: DocumentId[] = []; //所有文档列表
21+
export let listDocumentIds: DocumentId[] = []; //所有文档列表
2222
2323
// const ruleHash: string = rule.hash;
2424
let config: IConfig = rule.config;
2525
2626
let loadOffset: number = 0; //当前动态加载的文档偏移量
2727
let loadLength: number = config.dynamicLoading.capacity; //每次动态加载的文档数量
2828
let shiftLength: number = config.dynamicLoading.shift; //每次动态加载时的偏移量
29-
let loadIdList: DocumentId[] = []; //当前动态加载的文档列表
29+
let loadIdList: DocumentId[] = []; //当前动态加载的文档列表
3030
31-
setContext('getAllDocIds', () => {
31+
setContext("getAllDocIds", () => {
3232
return listDocumentIds;
3333
});
3434
35-
setContext('getLoadedDocIds', () => {
35+
setContext("getLoadedDocIds", () => {
3636
return loadIdList;
3737
});
3838
@@ -67,14 +67,16 @@
6767
}
6868
//然后再滚动到指定文档
6969
const queryAndScroll = () => {
70-
const ele = document.querySelector(`.docs-flow__doc[data-node-id="${id}"] > .protyle-breadcrumb__item`);
70+
const ele = document.querySelector(
71+
`.docs-flow__doc[data-node-id="${id}"] > .protyle-breadcrumb__item`,
72+
);
7173
if (ele) {
7274
// ele.scrollIntoView({ behavior: "smooth", block: "start" });
7375
ele.scrollIntoView(true);
7476
return true;
7577
}
7678
return false;
77-
}
79+
};
7880
7981
const MAX_ATTEMPTS = 5;
8082
const TRY_INTERVAL = 500;
@@ -84,19 +86,21 @@
8486
if (queryAndScroll()) {
8587
console.debug("滚动成功");
8688
} else if (attempts < MAX_ATTEMPTS) {
87-
console.debug(`滚动失败,${TRY_INTERVAL * (attempts + 1)}ms 后重试`);
89+
console.debug(
90+
`滚动失败,${TRY_INTERVAL * (attempts + 1)}ms 后重试`,
91+
);
8892
attempts++;
8993
setTimeout(attemptScroll, TRY_INTERVAL);
9094
} else {
9195
console.debug("滚动失败,已达到最大尝试次数");
9296
}
93-
}
97+
};
9498
9599
// 立即尝试第一次滚动
96100
attemptScroll();
97-
}
101+
};
98102
99-
setContext('jumpToDoc', jumpToDoc);
103+
setContext("jumpToDoc", jumpToDoc);
100104
101105
const updateLoadIdList = () => {
102106
if (config.dynamicLoading.enabled !== true) {
@@ -204,32 +208,41 @@
204208
205209
//全局 css,用于隐藏gutter
206210
let hideGutterClass: "" | "hide-gutter" = "";
211+
let docsFlow: HTMLElement;
212+
213+
setContext("docsFlow", () => docsFlow);
214+
207215
</script>
208216

209-
<Toolbar
210-
bind:rule
211-
bind:config
212-
bind:listDocumentIds
213-
{updateLoadIdList}
214-
{dispatch}
215-
{reInit}
216-
--width="{isMobile() ? '80%' : '60%'}"
217-
--left="calc(calc(100% - var(--width)) / 2)"
218-
/>
219-
220-
<div class="docs-flow fn__flex-1 {hideGutterClass}" style="--display-breadcrumb: {isMobile() ? "none" : "flex"}">
221-
{#each loadIdList as did, i (did)}
222-
<Protyle
223-
{app}
224-
index={i + loadOffset}
225-
blockId={did}
226-
{config}
227-
displayCollapseBar={config.breadcrumb}
228-
/>
229-
{/each}
230-
</div>
217+
<main class="docs-flow-container">
218+
<Toolbar
219+
bind:rule
220+
bind:config
221+
bind:listDocumentIds
222+
{updateLoadIdList}
223+
{dispatch}
224+
{reInit}
225+
/>
226+
227+
<div
228+
class="docs-flow fn__flex-1 {hideGutterClass}"
229+
style="--display-breadcrumb: {isMobile() ? 'none' : 'flex'}"
230+
bind:this={docsFlow}
231+
>
232+
{#each loadIdList as did, i (did)}
233+
<Protyle
234+
{app}
235+
index={i + loadOffset}
236+
blockId={did}
237+
{config}
238+
displayCollapseBar={config.breadcrumb}
239+
/>
240+
{/each}
241+
</div>
242+
</main>
231243

232244
<style lang="scss">
245+
233246
.docs-flow {
234247
:global(div.docs-flow__protyle .protyle-breadcrumb) {
235248
display: var(--display-breadcrumb);

0 commit comments

Comments
 (0)