rimelight-components 1.9.0 → 1.10.0
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/dist/runtime/components/app/ScrollToTop.d.vue.ts +1 -1
- package/dist/runtime/components/app/ScrollToTop.vue.d.ts +1 -1
- package/dist/runtime/components/renderers/TOC.d.vue.ts +26 -0
- package/dist/runtime/components/renderers/TOC.vue +94 -0
- package/dist/runtime/components/renderers/TOC.vue.d.ts +26 -0
- package/dist/runtime/types/blocks.d.ts +5 -1
- package/package.json +1 -1
|
@@ -3,8 +3,8 @@ interface Props {
|
|
|
3
3
|
duration?: number;
|
|
4
4
|
}
|
|
5
5
|
declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
6
|
-
circleStrokeWidth: number;
|
|
7
6
|
duration: number;
|
|
7
|
+
circleStrokeWidth: number;
|
|
8
8
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
9
|
declare const _default: typeof __VLS_export;
|
|
10
10
|
export default _default;
|
|
@@ -3,8 +3,8 @@ interface Props {
|
|
|
3
3
|
duration?: number;
|
|
4
4
|
}
|
|
5
5
|
declare const __VLS_export: import("vue").DefineComponent<Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<Props> & Readonly<{}>, {
|
|
6
|
-
circleStrokeWidth: number;
|
|
7
6
|
duration: number;
|
|
7
|
+
circleStrokeWidth: number;
|
|
8
8
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
9
9
|
declare const _default: typeof __VLS_export;
|
|
10
10
|
export default _default;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Block } from "../../types/blocks.js";
|
|
2
|
+
import type { HeadingLevel } from "../../types/blocks.js";
|
|
3
|
+
export interface TOCItem {
|
|
4
|
+
id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
level: HeadingLevel;
|
|
7
|
+
children?: TOCItem[];
|
|
8
|
+
}
|
|
9
|
+
type __VLS_Props = {
|
|
10
|
+
pageBlocks: Block[];
|
|
11
|
+
title?: string;
|
|
12
|
+
levels?: HeadingLevel[];
|
|
13
|
+
};
|
|
14
|
+
declare var __VLS_6: {};
|
|
15
|
+
type __VLS_Slots = {} & {
|
|
16
|
+
bottom?: (props: typeof __VLS_6) => any;
|
|
17
|
+
};
|
|
18
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
19
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
20
|
+
declare const _default: typeof __VLS_export;
|
|
21
|
+
export default _default;
|
|
22
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
23
|
+
new (): {
|
|
24
|
+
$slots: S;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
<script setup>
|
|
2
|
+
import { computed } from "vue";
|
|
3
|
+
import { slugify } from "../../utils/slugify";
|
|
4
|
+
const {
|
|
5
|
+
pageBlocks,
|
|
6
|
+
title = "table_of_contents",
|
|
7
|
+
levels = [2, 3, 4]
|
|
8
|
+
} = defineProps({
|
|
9
|
+
pageBlocks: { type: Array, required: true },
|
|
10
|
+
title: { type: String, required: false },
|
|
11
|
+
levels: { type: Array, required: false }
|
|
12
|
+
});
|
|
13
|
+
const extractHeadings = (blocks) => {
|
|
14
|
+
const headings = [];
|
|
15
|
+
if (!blocks || blocks.length === 0) {
|
|
16
|
+
return headings;
|
|
17
|
+
}
|
|
18
|
+
for (const block of blocks) {
|
|
19
|
+
if (block.type === "SectionBlock") {
|
|
20
|
+
const props = block.props;
|
|
21
|
+
const title2 = props.title;
|
|
22
|
+
const level = props.level;
|
|
23
|
+
if (title2 && level) {
|
|
24
|
+
headings.push({
|
|
25
|
+
id: slugify(title2),
|
|
26
|
+
title: title2,
|
|
27
|
+
level
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
if (props.children && props.children.length > 0) {
|
|
31
|
+
headings.push(...extractHeadings(props.children));
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return headings;
|
|
36
|
+
};
|
|
37
|
+
const tocItems = computed(() => {
|
|
38
|
+
if (!pageBlocks || pageBlocks.length === 0) {
|
|
39
|
+
return [];
|
|
40
|
+
}
|
|
41
|
+
if (levels.length === 0) {
|
|
42
|
+
return [];
|
|
43
|
+
}
|
|
44
|
+
const allHeadings = extractHeadings(pageBlocks);
|
|
45
|
+
const filteredHeadings = allHeadings.filter(
|
|
46
|
+
(item) => levels.includes(item.level)
|
|
47
|
+
);
|
|
48
|
+
return Array.from(new Set(filteredHeadings.map((h) => h.id))).map(
|
|
49
|
+
(id) => filteredHeadings.find((h) => h.id === id)
|
|
50
|
+
);
|
|
51
|
+
});
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<template>
|
|
55
|
+
<div class="z-10 flex flex-col gap-md">
|
|
56
|
+
<nav
|
|
57
|
+
class="sticky top-(--ui-header-height) z-50 flex flex-col gap-md pt-lg"
|
|
58
|
+
aria-label="Table of Contents"
|
|
59
|
+
>
|
|
60
|
+
<h5 class="text-highlighted">
|
|
61
|
+
{{ $t(title) }}
|
|
62
|
+
</h5>
|
|
63
|
+
|
|
64
|
+
<ul
|
|
65
|
+
v-if="tocItems.length > 0"
|
|
66
|
+
class="flex flex-col gap-0 border-s border-default"
|
|
67
|
+
>
|
|
68
|
+
<li
|
|
69
|
+
v-for="item in tocItems"
|
|
70
|
+
:key="item.id"
|
|
71
|
+
class="relative flex min-w-0"
|
|
72
|
+
:class="{
|
|
73
|
+
'ms-2': item.level === 2,
|
|
74
|
+
'ms-4': item.level === 3,
|
|
75
|
+
'ms-6': item.level === 4,
|
|
76
|
+
'ms-8': item.level === 5,
|
|
77
|
+
'ms-10': item.level === 6
|
|
78
|
+
}"
|
|
79
|
+
>
|
|
80
|
+
<NuxtLink
|
|
81
|
+
:href="`#${item.id}`"
|
|
82
|
+
class="group relative flex size-full items-center px-1.5 py-1.5 text-start text-sm font-medium before:absolute before:inset-x-0 before:inset-y-px before:z-[-1] before:rounded-md focus:outline-none focus-visible:outline-none focus-visible:before:ring-2 focus-visible:before:ring-inset dark:focus-visible:outline-none"
|
|
83
|
+
>
|
|
84
|
+
<span class="truncate">
|
|
85
|
+
{{ item.title }}
|
|
86
|
+
</span>
|
|
87
|
+
</NuxtLink>
|
|
88
|
+
</li>
|
|
89
|
+
</ul>
|
|
90
|
+
|
|
91
|
+
<slot name="bottom" />
|
|
92
|
+
</nav>
|
|
93
|
+
</div>
|
|
94
|
+
</template>
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { Block } from "../../types/blocks.js";
|
|
2
|
+
import type { HeadingLevel } from "../../types/blocks.js";
|
|
3
|
+
export interface TOCItem {
|
|
4
|
+
id: string;
|
|
5
|
+
title: string;
|
|
6
|
+
level: HeadingLevel;
|
|
7
|
+
children?: TOCItem[];
|
|
8
|
+
}
|
|
9
|
+
type __VLS_Props = {
|
|
10
|
+
pageBlocks: Block[];
|
|
11
|
+
title?: string;
|
|
12
|
+
levels?: HeadingLevel[];
|
|
13
|
+
};
|
|
14
|
+
declare var __VLS_6: {};
|
|
15
|
+
type __VLS_Slots = {} & {
|
|
16
|
+
bottom?: (props: typeof __VLS_6) => any;
|
|
17
|
+
};
|
|
18
|
+
declare const __VLS_base: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
19
|
+
declare const __VLS_export: __VLS_WithSlots<typeof __VLS_base, __VLS_Slots>;
|
|
20
|
+
declare const _default: typeof __VLS_export;
|
|
21
|
+
export default _default;
|
|
22
|
+
type __VLS_WithSlots<T, S> = T & {
|
|
23
|
+
new (): {
|
|
24
|
+
$slots: S;
|
|
25
|
+
};
|
|
26
|
+
};
|
|
@@ -1,3 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Defines the allowed heading levels (h2 through h6) for the Table of Contents.
|
|
3
|
+
*/
|
|
4
|
+
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
1
5
|
/**
|
|
2
6
|
* All valid block types the application can render.
|
|
3
7
|
* This union type is the single source of truth for component names.
|
|
@@ -13,7 +17,7 @@ export interface BaseContentBlock {
|
|
|
13
17
|
props: Record<string, any>;
|
|
14
18
|
}
|
|
15
19
|
export interface SectionBlockProps {
|
|
16
|
-
level:
|
|
20
|
+
level: HeadingLevel;
|
|
17
21
|
title: string;
|
|
18
22
|
description?: string;
|
|
19
23
|
children: Block[];
|
package/package.json
CHANGED