@coffic/cosy-ui 0.6.6 → 0.6.10

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.
@@ -0,0 +1,105 @@
1
+ import Feature from './Feature';
2
+ import type { Component } from 'vue';
3
+
4
+ class Banner {
5
+ private translations: Map<string, {
6
+ title: string,
7
+ description: string
8
+ }>;
9
+ private features: Feature[];
10
+ private component: Component | null;
11
+ private componentProps: Record<string, unknown>;
12
+
13
+ constructor() {
14
+ this.translations = new Map();
15
+ this.features = [];
16
+ this.component = null;
17
+ this.componentProps = {};
18
+ // Initialize empty entries for both languages
19
+ this.translations.set('zh-cn', { title: '', description: '' });
20
+ this.translations.set('en', { title: '', description: '' });
21
+ }
22
+
23
+ static create(): Banner {
24
+ return new Banner();
25
+ }
26
+
27
+ public setZhTitle(title: string): Banner {
28
+ const current = this.translations.get('zh-cn') || { title: '', description: '' };
29
+ this.translations.set('zh-cn', { ...current, title });
30
+ return this;
31
+ }
32
+
33
+ public setEnTitle(title: string): Banner {
34
+ const current = this.translations.get('en') || { title: '', description: '' };
35
+ this.translations.set('en', { ...current, title });
36
+ return this;
37
+ }
38
+
39
+ public setZhDescription(description: string): Banner {
40
+ const current = this.translations.get('zh-cn') || { title: '', description: '' };
41
+ this.translations.set('zh-cn', { ...current, description });
42
+ return this;
43
+ }
44
+
45
+ public setEnDescription(description: string): Banner {
46
+ const current = this.translations.get('en') || { title: '', description: '' };
47
+ this.translations.set('en', { ...current, description });
48
+ return this;
49
+ }
50
+
51
+ public appendFeature(feature: Feature): Banner {
52
+ this.features.push(feature);
53
+ return this;
54
+ }
55
+
56
+ public withFeatures(features: Feature[]): Banner {
57
+ this.features.push(...features);
58
+ return this;
59
+ }
60
+
61
+ // 获取指定语言的标题
62
+ public getTitle(lang: string): string {
63
+ return this.translations.get(lang)?.title || '';
64
+ }
65
+
66
+ // 获取指定语言的描述
67
+ public getDescription(lang: string): string {
68
+ return this.translations.get(lang)?.description || '';
69
+ }
70
+
71
+ // 获取指定语言的特性列表
72
+ public getFeatures(): Feature[] {
73
+ return this.features;
74
+ }
75
+
76
+ // 检查是否支持某种语言
77
+ public hasLanguage(lang: string): boolean {
78
+ return this.translations.has(lang);
79
+ }
80
+
81
+ // 获取所有支持的语言
82
+ public getSupportedLanguages(): string[] {
83
+ return Array.from(this.translations.keys());
84
+ }
85
+
86
+ public setComponent(component: Component): Banner {
87
+ this.component = component;
88
+ return this;
89
+ }
90
+
91
+ public getComponent(): Component | null {
92
+ return this.component;
93
+ }
94
+
95
+ public setComponentProps(props: Record<string, unknown>): Banner {
96
+ this.componentProps = props;
97
+ return this;
98
+ }
99
+
100
+ public getComponentProps(): Record<string, unknown> {
101
+ return this.componentProps;
102
+ }
103
+ }
104
+
105
+ export default Banner;
@@ -43,7 +43,7 @@ export abstract class BaseDoc<
43
43
  */
44
44
  getAncestorIds(): string[] {
45
45
  const parts = this.entry.id.split('/');
46
- return parts.slice(0, -1).map((part, index) => parts.slice(0, index + 1).join('/'));
46
+ return parts.slice(0, -1).map((_part, index) => parts.slice(0, index + 1).join('/'));
47
47
  }
48
48
 
49
49
  /**
@@ -3,7 +3,7 @@ import { LinkUtil } from '../utils/link';
3
3
  import Tag from './Tag';
4
4
  import { BaseDoc } from './BaseDoc';
5
5
  import { COLLECTION_BLOG } from '../database/BlogDB';
6
- import blogDB from '../database/BlogDB';
6
+ import { blogDB } from '../database/BlogDB';
7
7
 
8
8
  export default class BlogDoc extends BaseDoc<typeof COLLECTION_BLOG, BlogEntry> {
9
9
  private constructor(entry: BlogEntry) {
@@ -1,5 +1,5 @@
1
1
  import type { ExperimentEntry } from '../database/ExperimentDB';
2
- import experimentDB from '../database/ExperimentDB';
2
+ import { experimentDB } from '../database/ExperimentDB';
3
3
  import { logger } from '../utils/logger';
4
4
  import { SidebarItemEntity } from './SidebarItem';
5
5
  import { LinkUtil } from '../utils/link';
@@ -17,7 +17,7 @@ export default class ExperimentDoc extends BaseDoc<typeof COLLECTION_EXPERIMENT,
17
17
  }
18
18
 
19
19
  async getBookId(): Promise<string> {
20
- return await this.getTopDocId();
20
+ return this.getTopDocId();
21
21
  }
22
22
 
23
23
  async getBook(): Promise<ExperimentDoc | null> {
@@ -0,0 +1,53 @@
1
+ class Feature {
2
+ private translations: Map<string, string>;
3
+ public emoji: string = '';
4
+ public link: string = '';
5
+ public presetIcon: string = '';
6
+
7
+ private constructor() {
8
+ this.translations = new Map();
9
+ this.translations.set('zh-cn', '');
10
+ this.translations.set('en', '');
11
+ }
12
+
13
+ public static createWithIcon(emoji: string): Feature {
14
+ const feature = new Feature();
15
+ feature.emoji = emoji;
16
+ return feature;
17
+ }
18
+
19
+ public static createWithPresetIcon(presetIcon: string): Feature {
20
+ const feature = new Feature();
21
+ feature.presetIcon = presetIcon;
22
+ return feature;
23
+ }
24
+
25
+ public setTitle(title: string, lang: string): Feature {
26
+ this.translations.set(lang, title);
27
+ return this;
28
+ }
29
+
30
+ public setLink(link: string): Feature {
31
+ this.link = link;
32
+ return this;
33
+ }
34
+
35
+ public setPresetIcon(presetIcon: string): Feature {
36
+ this.presetIcon = presetIcon;
37
+ return this;
38
+ }
39
+
40
+ public setZh(title: string): Feature {
41
+ return this.setTitle(title, 'zh-cn');
42
+ }
43
+
44
+ public setEn(title: string): Feature {
45
+ return this.setTitle(title, 'en');
46
+ }
47
+
48
+ public getTitle(lang: string): string {
49
+ return this.translations.get(lang) || '';
50
+ }
51
+ }
52
+
53
+ export default Feature;
@@ -1,5 +1,5 @@
1
1
  import type { LessonEntry } from '../database/LessonDB';
2
- import lessonDB from '../database/LessonDB';
2
+ import { lessonDB } from '../database/LessonDB';
3
3
  import { logger } from '../utils/logger';
4
4
  import { SidebarItemEntity } from './SidebarItem';
5
5
  import { LinkUtil } from '../utils/link';
@@ -17,7 +17,7 @@ export default class LessonDoc extends BaseDoc<typeof COLLECTION_LESSON, LessonE
17
17
  }
18
18
 
19
19
  async getBookId(): Promise<string> {
20
- return await this.getTopDocId();
20
+ return this.getTopDocId();
21
21
  }
22
22
 
23
23
  async getBook(): Promise<LessonDoc | null> {
@@ -2,7 +2,7 @@ import { SidebarItemEntity } from './SidebarItem';
2
2
  import type { MetaEntry } from '../database/MetaDB';
3
3
  import { LinkUtil } from '../utils/link';
4
4
  import { BaseDoc } from './BaseDoc';
5
- import metaDB from '../database/MetaDB';
5
+ import { metaDB } from '../database/MetaDB';
6
6
  import { COLLECTION_META } from '../database/MetaDB';
7
7
 
8
8
  export default class MetaDoc extends BaseDoc<typeof COLLECTION_META, MetaEntry> {
@@ -14,6 +14,14 @@ export default class MetaDoc extends BaseDoc<typeof COLLECTION_META, MetaEntry>
14
14
  return new MetaDoc(entry);
15
15
  }
16
16
 
17
+ getTopDoc(): Promise<MetaDoc | null> {
18
+ return Promise.resolve(null);
19
+ }
20
+
21
+ getChildren(): Promise<MetaDoc[]> {
22
+ return Promise.resolve([]);
23
+ }
24
+
17
25
  getLink(): string {
18
26
  return LinkUtil.getMetaLink(this.getLang(), this.getSlug());
19
27
  }
@@ -1,4 +1,4 @@
1
- import blogDB from '../database/BlogDB';
1
+ import { blogDB } from '../database/BlogDB';
2
2
  import { SidebarItemEntity } from './SidebarItem';
3
3
  import { type ITagStaticPath } from '../types/static-path';
4
4
  import { LinkUtil } from '../utils/link';
package/dist/icons.ts ADDED
@@ -0,0 +1,22 @@
1
+ export { default as SocialIcon } from './components/icons/SocialIcon.astro';
2
+ export { default as TwitterIcon } from './components/icons/TwitterIcon.astro';
3
+ export { default as UserIcon } from './components/icons/UserIcon.astro';
4
+ export { default as WarningIcon } from './components/icons/WarningIcon.astro';
5
+ export { default as XCircle } from './components/icons/XCircle.astro';
6
+ export { default as InfoIcon } from './components/icons/InfoIcon.astro';
7
+ export { default as LinkIcon } from './components/icons/LinkIcon.astro';
8
+ export { default as LinkedinIcon } from './components/icons/LinkedinIcon.astro';
9
+ export { default as MenuIcon } from './components/icons/MenuIcon.astro';
10
+ export { default as SearchIcon } from './components/icons/SearchIcon.astro';
11
+ export { default as SuccessIcon } from './components/icons/SuccessIcon.astro';
12
+ export { default as SunCloudyIcon } from './components/icons/SunCloudyIcon.astro';
13
+ export { default as AlertTriangle } from './components/icons/AlertTriangle.astro';
14
+ export { default as CalendarIcon } from './components/icons/CalendarIcon.astro';
15
+ export { default as CheckCircle } from './components/icons/CheckCircle.astro';
16
+ export { default as CheckIcon } from './components/icons/CheckIcon.astro';
17
+ export { default as ClipboardIcon } from './components/icons/ClipboardIcon.astro';
18
+ export { default as CloseIcon } from './components/icons/CloseIcon.astro';
19
+ export { default as ErrorIcon } from './components/icons/ErrorIcon.astro';
20
+ export { default as GithubIcon } from './components/icons/GithubIcon.astro';
21
+ export { default as InfoCircle } from './components/icons/InfoCircle.astro';
22
+ export { default as SettingsIcon } from './components/icons/SettingsIcon.astro';
package/dist/index.ts CHANGED
@@ -46,27 +46,7 @@ export { default as Heading } from './components/typography/Heading.astro';
46
46
  export { default as ErrorPage404 } from './components/errors/404.astro';
47
47
 
48
48
  // Icons
49
- export { default as SocialIcon } from './components/icons/SocialIcon.astro';
50
- export { default as TwitterIcon } from './components/icons/TwitterIcon.astro';
51
- export { default as UserIcon } from './components/icons/UserIcon.astro';
52
- export { default as WarningIcon } from './components/icons/WarningIcon.astro';
53
- export { default as XCircle } from './components/icons/XCircle.astro';
54
- export { default as InfoIcon } from './components/icons/InfoIcon.astro';
55
- export { default as LinkIcon } from './components/icons/LinkIcon.astro';
56
- export { default as LinkedinIcon } from './components/icons/LinkedinIcon.astro';
57
- export { default as MenuIcon } from './components/icons/MenuIcon.astro';
58
- export { default as SearchIcon } from './components/icons/SearchIcon.astro';
59
- export { default as SuccessIcon } from './components/icons/SuccessIcon.astro';
60
- export { default as SunCloudyIcon } from './components/icons/SunCloudyIcon.astro';
61
- export { default as AlertTriangle } from './components/icons/AlertTriangle.astro';
62
- export { default as CalendarIcon } from './components/icons/CalendarIcon.astro';
63
- export { default as CheckCircle } from './components/icons/CheckCircle.astro';
64
- export { default as CheckIcon } from './components/icons/CheckIcon.astro';
65
- export { default as ClipboardIcon } from './components/icons/ClipboardIcon.astro';
66
- export { default as CloseIcon } from './components/icons/CloseIcon.astro';
67
- export { default as ErrorIcon } from './components/icons/ErrorIcon.astro';
68
- export { default as GithubIcon } from './components/icons/GithubIcon.astro';
69
- export { default as InfoCircle } from './components/icons/InfoCircle.astro';
49
+ export * from './icons';
70
50
 
71
51
  // Containers
72
52
  export { default as Container } from './components/containers/Container.astro';
@@ -0,0 +1,120 @@
1
+ <!--
2
+ @component AlertDialog
3
+
4
+ @description
5
+ AlertDialog 组件用于显示简单的确认对话框,支持国际化,带有淡入淡出动画效果。
6
+
7
+ @usage
8
+ 基本用法:
9
+ ```vue
10
+ <AlertDialog v-model="showDialog" message="操作已完成" />
11
+ ```
12
+
13
+ 指定语言:
14
+ ```vue
15
+ <AlertDialog v-model="showDialog" message="Operation completed" lang="en" />
16
+ ```
17
+
18
+ 组合使用:
19
+ ```vue
20
+ <template>
21
+ <button @click="showDialog = true">显示对话框</button>
22
+ <AlertDialog v-model="showDialog" message="确认要继续吗?" />
23
+ </template>
24
+
25
+ <script setup lang="ts">
26
+ import { ref } from 'vue';
27
+ import { AlertDialog } from 'cosy-ui';
28
+
29
+ const showDialog = ref(false);
30
+ </script>
31
+ ```
32
+
33
+ @props
34
+ @prop {boolean} modelValue - 控制对话框显示状态,支持v-model双向绑定
35
+ @prop {string} message - 对话框显示的消息内容
36
+ @prop {('zh-cn'|'en')} [lang='zh-cn'] - 语言设置,影响按钮文本
37
+
38
+ @emits
39
+ @emit {update:modelValue} - 当对话框关闭时触发,用于更新v-model绑定值
40
+ -->
41
+
42
+ <script lang="ts">
43
+ import '../app.css'
44
+ import { defineComponent } from 'vue'
45
+
46
+ type MessageKey = 'confirm';
47
+
48
+ interface Messages {
49
+ [key: string]: {
50
+ [key in MessageKey]: string;
51
+ };
52
+ }
53
+
54
+ export default defineComponent({
55
+ name: 'AlertDialog',
56
+ props: {
57
+ modelValue: {
58
+ type: Boolean,
59
+ required: true
60
+ },
61
+ message: {
62
+ type: String,
63
+ required: true
64
+ },
65
+ lang: {
66
+ type: String as () => 'zh-cn' | 'en',
67
+ default: 'zh-cn'
68
+ }
69
+ },
70
+ emits: ['update:modelValue'],
71
+ setup(props) {
72
+ // 多语言文本
73
+ const t = (key: MessageKey) => {
74
+ const messages: Messages = {
75
+ 'zh-cn': {
76
+ confirm: '确定'
77
+ },
78
+ 'en': {
79
+ confirm: 'OK'
80
+ }
81
+ };
82
+ return messages[props.lang][key];
83
+ };
84
+
85
+ return {
86
+ t
87
+ };
88
+ }
89
+ })
90
+ </script>
91
+
92
+ <template>
93
+ <Transition name="fade" class="cosy:transition-opacity cosy:duration-200 cosy:ease-in-out">
94
+ <div v-if="modelValue"
95
+ class="cosy:fixed cosy:inset-0 cosy:z-50 cosy:flex cosy:items-center cosy:justify-center cosy:opacity-100 cosy:enter:opacity-0 cosy:leave:opacity-0">
96
+ <!-- 背景遮罩 -->
97
+ <div class="cosy:absolute cosy:inset-0 cosy:bg-base-200/80 cosy:backdrop-blur-sm"
98
+ @click="$emit('update:modelValue', false)" />
99
+
100
+ <!-- 对话框 -->
101
+ <div
102
+ class="cosy:relative cosy:bg-base-100 cosy:rounded-xl cosy:shadow-lg cosy:w-[400px] cosy:transform cosy:transition-all">
103
+ <!-- 内容区域 -->
104
+ <div class="cosy:p-6">
105
+ <p class="cosy:text-base-content">
106
+ {{ message }}
107
+ </p>
108
+ </div>
109
+
110
+ <!-- 按钮区域 -->
111
+ <div class="cosy:flex cosy:border-t cosy:border-base-300">
112
+ <button class="cosy:btn cosy:btn-ghost cosy:flex-1 cosy:rounded-none cosy:rounded-b-xl"
113
+ @click="$emit('update:modelValue', false)">
114
+ {{ t('confirm') }}
115
+ </button>
116
+ </div>
117
+ </div>
118
+ </div>
119
+ </Transition>
120
+ </template>