Skip to content

Commit f87970b

Browse files
committed
🎨 style: 优化响应式布局
1 parent 11a5e8f commit f87970b

File tree

4 files changed

+113
-52
lines changed

4 files changed

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

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

Lines changed: 64 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,6 @@
170170
};
171171
172172
const showDocsFlowOutline = () => {
173-
174173
const { close } = svelteDialog({
175174
title: "Outline",
176175
constructor: (container: HTMLElement) => {
@@ -182,7 +181,7 @@
182181
jumpToDoc: (id: BlockId) => {
183182
jumpToDoc(id);
184183
close();
185-
}
184+
},
186185
},
187186
});
188187
},
@@ -205,7 +204,7 @@
205204
</script>
206205

207206
<div
208-
class="docs-flow__toolbar {classNamePin}"
207+
class="docs-flow__toolbar {classNamePin} {isMobile() ? 'is-mobile' : ''}"
209208
on:mouseenter={() => {
210209
if (pinToolbar) return;
211210
showToolbar = true;
@@ -248,7 +247,7 @@
248247
</svg>
249248

250249
<svg
251-
class="svg-button ariaLabel"
250+
class="svg-button ariaLabel hide-if-very-narrow"
252251
aria-label={i18n.button.reverse}
253252
on:click={() => {
254253
listDocumentIds = listDocumentIds.reverse();
@@ -260,7 +259,7 @@
260259
</svg>
261260

262261
<svg
263-
class="svg-button ariaLabel"
262+
class="svg-button ariaLabel hide-if-very-narrow"
264263
aria-label={i18n.button.edit}
265264
on:click={editRuleValue}
266265
on:keypress={() => {}}
@@ -294,14 +293,16 @@
294293

295294
<input
296295
id="displayBreadcrumb"
297-
class="b3-switch fn__flex-center"
296+
class="b3-switch fn__flex-center hide-if-very-narrow"
298297
type="checkbox"
299298
bind:checked={config.breadcrumb}
300299
on:change={onConfigChanged}
301300
/>
302301

303302
<button
304-
class="b3-button {isMobile() ? 'b3-button--text' : ''}"
303+
class="b3-button {isMobile()
304+
? 'b3-button--text'
305+
: ''}"
305306
on:click={onOpenConfig}
306307
>
307308
{i18n.button.moreConfig}
@@ -312,13 +313,16 @@
312313
class="fn__flex {isMobile() ? 'fn__none' : ''}"
313314
style="gap: 5px;"
314315
>
315-
<button class="b3-button hide-if-need" on:click={onRenameThis}
316+
<button class="b3-button hide-if-narrow" on:click={onRenameThis}
316317
>{i18n.nameTab}</button
317318
>
318-
<button class="b3-button" on:click={onSaveThis}>
319+
<button
320+
class="b3-button hide-if-very-narrow"
321+
on:click={onSaveThis}
322+
>
319323
{i18n.saveRule}
320324
</button>
321-
<button class="b3-button hide-if-need" on:click={onCopyLink}>
325+
<button class="b3-button hide-if-narrow" on:click={onCopyLink}>
322326
{i18n.copyLink}
323327
</button>
324328
</div>
@@ -330,41 +334,84 @@
330334
.docs-flow__toolbar {
331335
height: 3rem;
332336
padding: 0;
333-
334337
position: absolute;
338+
339+
--width: 70%;
340+
--left: calc(calc(100% - var(--width)) / 2);
341+
335342
width: var(--width);
336343
left: var(--left);
337344
338345
top: 15px;
339346
z-index: 10;
340-
341347
display: flex;
342348
justify-content: center;
343349
align-items: center;
350+
351+
container-type: inline-size;
352+
container-name: docs-flow-toolbar;
344353
}
345354
346355
.docs-flow__toolbar section.docs-flow__toolbar-body {
347356
display: flex;
348357
flex-wrap: wrap;
349358
align-items: center;
350359
gap: 5px;
351-
352360
padding: 4px 5px;
353-
width: 600px;
354-
height: 30px;
355361
362+
height: 30px;
356363
background-color: var(--b3-theme-surface);
357364
opacity: 1;
358365
border-radius: 10px;
359366
box-shadow:
360367
0 0.5em 1em -0.125em var(--b3-theme-primary-light),
361368
0 0 0 1px var(--b3-theme-primary-light);
362369
363-
overflow: hidden; /* 添加这行以隐藏溢出的内容 */
364-
365370
#space {
366371
flex: 1;
367372
}
373+
374+
flex-wrap: nowrap;
375+
376+
@container docs-flow-toolbar (max-width: 600px) {
377+
.b3-label__text {
378+
display: none;
379+
}
380+
.hide-if-narrow {
381+
display: none;
382+
}
383+
}
384+
385+
@container docs-flow-toolbar (max-width: 400px) {
386+
.hide-if-very-narrow {
387+
display: none;
388+
}
389+
}
390+
}
391+
392+
.docs-flow__toolbar.is-mobile {
393+
--width: 95%;
394+
}
395+
.docs-flow__toolbar:not(.is-mobile) {
396+
@container docs-flow (min-width: 1000px) {
397+
--width: 72%;
398+
}
399+
400+
@container docs-flow (max-width: 800px) {
401+
--width: 90%;
402+
}
403+
404+
section.docs-flow__toolbar-body {
405+
@container docs-flow-toolbar (min-width: 720px) {
406+
width: 720px;
407+
}
408+
@container docs-flow-toolbar (max-width: 720px) {
409+
max-width: 100%;
410+
}
411+
@container docs-flow-toolbar (max-width: 400px) {
412+
width: 100%;
413+
}
414+
}
368415
}
369416
370417
.docs-flow__toolbar svg.svg-button {

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

Lines changed: 47 additions & 33 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-03 14:10:48
6+
LastEditTime : 2025-01-18 17:31:07
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) {
@@ -206,30 +210,40 @@
206210
let hideGutterClass: "" | "hide-gutter" = "";
207211
</script>
208212

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>
213+
<main class="docs-flow-container">
214+
<Toolbar
215+
bind:rule
216+
bind:config
217+
bind:listDocumentIds
218+
{updateLoadIdList}
219+
{dispatch}
220+
{reInit}
221+
/>
222+
223+
<div
224+
class="docs-flow fn__flex-1 {hideGutterClass}"
225+
style="--display-breadcrumb: {isMobile() ? 'none' : 'flex'}"
226+
>
227+
{#each loadIdList as did, i (did)}
228+
<Protyle
229+
{app}
230+
index={i + loadOffset}
231+
blockId={did}
232+
{config}
233+
displayCollapseBar={config.breadcrumb}
234+
/>
235+
{/each}
236+
</div>
237+
</main>
231238

232239
<style lang="scss">
240+
.docs-flow-container {
241+
container-type: inline-size;
242+
container-name: docs-flow;
243+
width: 100%;
244+
position: relative;
245+
}
246+
233247
.docs-flow {
234248
:global(div.docs-flow__protyle .protyle-breadcrumb) {
235249
display: var(--display-breadcrumb);

0 commit comments

Comments
 (0)