@smartos-lib/components 1.7.0-beta.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (128) hide show
  1. package/.eslintrc +12 -0
  2. package/.eslintrc-auto-import.json +332 -0
  3. package/Components.code-workspace +143 -0
  4. package/LICENSE +21 -0
  5. package/dist/smart-docx-editor/index.d.ts +2 -0
  6. package/dist/smart-docx-editor/index.js +68 -0
  7. package/dist/smart-file-preview/index.d.ts +18 -0
  8. package/dist/smart-file-preview/index.js +37 -0
  9. package/dist/smart-upload/index.d.ts +2 -0
  10. package/dist/smart-upload/index.js +800 -0
  11. package/index.html +16 -0
  12. package/package.json +23 -0
  13. package/public/favicon.svg +6 -0
  14. package/scripts/components.vite.config.ts +96 -0
  15. package/scripts/shared.ts +9 -0
  16. package/src/App.vue +28 -0
  17. package/src/components/Logo/index.vue +15 -0
  18. package/src/components-private/.gitkeep +0 -0
  19. package/src/composables/useElementStyle.ts +23 -0
  20. package/src/composables/useNaiveStyle.ts +43 -0
  21. package/src/composables/useNaiveTheme.ts +71 -0
  22. package/src/composables/useSmart.ts +36 -0
  23. package/src/layouts/default.vue +3 -0
  24. package/src/main.ts +33 -0
  25. package/src/modules/pinia/index.ts +8 -0
  26. package/src/modules/progress/index.ts +12 -0
  27. package/src/modules/router/install.ts +9 -0
  28. package/src/modules/router/routes.ts +40 -0
  29. package/src/pages/[...all].vue +21 -0
  30. package/src/pages/frame/component/[name].vue +14 -0
  31. package/src/pages/frame/index.vue +81 -0
  32. package/src/pages/index/composables/useTabsManage.ts +46 -0
  33. package/src/pages/index/index.vue +111 -0
  34. package/src/pages/index/type.ts +13 -0
  35. package/src/pages/index/utils/index.ts +41 -0
  36. package/src/settings.ts +9 -0
  37. package/src/shared/components.ts +52 -0
  38. package/src/shared/env.ts +11 -0
  39. package/src/shared/unocss.theme.ts +1600 -0
  40. package/src/stores/theme.ts +29 -0
  41. package/src/styles/element.scss +3 -0
  42. package/src/styles/styles.scss +21 -0
  43. package/src/types.ts +20 -0
  44. package/src/utils/callCustomElementExposed.ts +6 -0
  45. package/src/utils/deepCloneESModule.ts +10 -0
  46. package/src/utils/defineCustomElements.ts +18 -0
  47. package/src/utils/formatComponentsGlob.ts +16 -0
  48. package/src/utils/getFileMD5.ts +31 -0
  49. package/src/utils/getFileNameAndExt.ts +11 -0
  50. package/src/utils/isFileEqual.ts +13 -0
  51. package/src/utils/jsonToFormData.ts +8 -0
  52. package/src/web-components/smart-docx-drive-page/App.vue +37 -0
  53. package/src/web-components/smart-docx-drive-page/apis/doc.ts +85 -0
  54. package/src/web-components/smart-docx-drive-page/apis/file.ts +278 -0
  55. package/src/web-components/smart-docx-drive-page/apis/folder.ts +72 -0
  56. package/src/web-components/smart-docx-drive-page/children/Home.vue +8 -0
  57. package/src/web-components/smart-docx-drive-page/children/Me.vue +47 -0
  58. package/src/web-components/smart-docx-drive-page/components/CustomImage.vue +26 -0
  59. package/src/web-components/smart-docx-drive-page/components/CustomPopover.vue +62 -0
  60. package/src/web-components/smart-docx-drive-page/components/DocxDir.vue +99 -0
  61. package/src/web-components/smart-docx-drive-page/components/DocxDoc.vue +132 -0
  62. package/src/web-components/smart-docx-drive-page/components/DocxDownloadPopoverItem.vue +41 -0
  63. package/src/web-components/smart-docx-drive-page/components/DocxFileList.vue +156 -0
  64. package/src/web-components/smart-docx-drive-page/components/DocxPreview.vue +33 -0
  65. package/src/web-components/smart-docx-drive-page/components/DocxUpload.vue +164 -0
  66. package/src/web-components/smart-docx-drive-page/components/FileIcon.vue +62 -0
  67. package/src/web-components/smart-docx-drive-page/components-private/Header.vue +65 -0
  68. package/src/web-components/smart-docx-drive-page/components-private/Logo.vue +15 -0
  69. package/src/web-components/smart-docx-drive-page/components-private/Menu.vue +34 -0
  70. package/src/web-components/smart-docx-drive-page/components-private/Navbar.vue +36 -0
  71. package/src/web-components/smart-docx-drive-page/composables/useFullscreenElDialog.ts +41 -0
  72. package/src/web-components/smart-docx-drive-page/composables/usePrompt.ts +73 -0
  73. package/src/web-components/smart-docx-drive-page/data.ts +10 -0
  74. package/src/web-components/smart-docx-drive-page/external-style/custom-popover.sass +8 -0
  75. package/src/web-components/smart-docx-drive-page/external-style/index.sass +1 -0
  76. package/src/web-components/smart-docx-drive-page/index.ts +20 -0
  77. package/src/web-components/smart-docx-drive-page/index.vue +39 -0
  78. package/src/web-components/smart-docx-drive-page/info.ts +2 -0
  79. package/src/web-components/smart-docx-drive-page/stores/menu.ts +60 -0
  80. package/src/web-components/smart-docx-drive-page/types.ts +51 -0
  81. package/src/web-components/smart-docx-drive-page/utils/file-actions.ts +63 -0
  82. package/src/web-components/smart-docx-drive-page/utils/file.ts +31 -0
  83. package/src/web-components/smart-docx-editor/App.vue +32 -0
  84. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components/Markdown.vue +202 -0
  85. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components/Menu.vue +100 -0
  86. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components/types.ts +6 -0
  87. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components-react/Markdown.tsx +71 -0
  88. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components-react/MarkdownElement.tsx +81 -0
  89. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components-react/elements/Blockquote/index.sass +6 -0
  90. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components-react/elements/Blockquote/index.tsx +12 -0
  91. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components-react/elements/Heading/index.sass +14 -0
  92. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components-react/elements/Heading/index.tsx +17 -0
  93. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components-react/elements/List/index.scss +16 -0
  94. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components-react/elements/List/index.tsx +39 -0
  95. package/src/web-components/smart-docx-editor/MarkdownShortcuts/components-react/types/custom-types.d.ts +69 -0
  96. package/src/web-components/smart-docx-editor/MarkdownShortcuts/composables/useTextSelection.ts +50 -0
  97. package/src/web-components/smart-docx-editor/MarkdownShortcuts/index.sass +19 -0
  98. package/src/web-components/smart-docx-editor/MarkdownShortcuts/index.vue +21 -0
  99. package/src/web-components/smart-docx-editor/MarkdownShortcuts/shared/const.ts +23 -0
  100. package/src/web-components/smart-docx-editor/MarkdownShortcuts/utils/slateHelpers.ts +23 -0
  101. package/src/web-components/smart-docx-editor/data.ts +38 -0
  102. package/src/web-components/smart-docx-editor/demo.vue +11 -0
  103. package/src/web-components/smart-docx-editor/index.md +3 -0
  104. package/src/web-components/smart-docx-editor/index.ts +5 -0
  105. package/src/web-components/smart-docx-editor/index.vue +12 -0
  106. package/src/web-components/smart-docx-editor/info.ts +2 -0
  107. package/src/web-components/smart-file-preview/category/Code.vue +171 -0
  108. package/src/web-components/smart-file-preview/category/Image.vue +49 -0
  109. package/src/web-components/smart-file-preview/category/Pdf.vue +14 -0
  110. package/src/web-components/smart-file-preview/category/Video.vue +27 -0
  111. package/src/web-components/smart-file-preview/demo.vue +34 -0
  112. package/src/web-components/smart-file-preview/index.md +5 -0
  113. package/src/web-components/smart-file-preview/index.ts +29 -0
  114. package/src/web-components/smart-file-preview/index.vue +56 -0
  115. package/src/web-components/smart-file-preview/info.ts +2 -0
  116. package/src/web-components/smart-file-preview/shared/const.ts +4 -0
  117. package/src/web-components/smart-file-preview/types.ts +38 -0
  118. package/src/web-components/smart-upload/index.ts +5 -0
  119. package/src/web-components/smart-upload/index.vue +101 -0
  120. package/src/web-components/smart-upload/info.ts +2 -0
  121. package/src/web-components/smart-upload/types.ts +28 -0
  122. package/tsconfig.json +15 -0
  123. package/types/auto-imports.d.ts +975 -0
  124. package/types/components.d.ts +14 -0
  125. package/types/env.d.ts +8 -0
  126. package/types/shims.d.ts +6 -0
  127. package/unocss.config.ts +23 -0
  128. package/vite.config.ts +60 -0
@@ -0,0 +1,29 @@
1
+ import { defineCustomElement } from 'vue';
2
+ import VueComponent from './index.vue';
3
+ import { tag } from './info';
4
+ import type { PreviewFile } from './types';
5
+ import { defineCustomElements } from '@/utils/defineCustomElements';
6
+ import { getCustomElementExposed } from '@/utils/callCustomElementExposed';
7
+
8
+ // 组件转为 Vue 自定义元素
9
+ const VueCustomElement = defineCustomElement(VueComponent);
10
+
11
+ // 暴露组件方法
12
+ Object.assign(VueCustomElement.prototype, {
13
+ previewFile(...args: any[]) {
14
+ return getCustomElementExposed(this, 'previewFile')(...args);
15
+ },
16
+ });
17
+
18
+ // 注册组件
19
+ defineCustomElements(tag, VueCustomElement);
20
+
21
+ // 暴露组件类型
22
+ export type SmartFilePreviewElement = typeof VueCustomElement & {
23
+ /**
24
+ * 预览文件
25
+ * @param fileName 文件名
26
+ * @param file 文件 Blob 对象
27
+ */
28
+ previewFile: PreviewFile
29
+ };
@@ -0,0 +1,56 @@
1
+ <template>
2
+ <ElConfigProvider namespace="smart">
3
+ <div size-full relative>
4
+ <!-- File / Blob 文件打开 -->
5
+ <component
6
+ v-if="file"
7
+ :is="components[fileCategory] || Code"
8
+ :file="file" :fileName="fileName" :fileExt="fileExt"
9
+ v-bind="attrs"
10
+ />
11
+ </div>
12
+ </ElConfigProvider>
13
+ </template>
14
+
15
+ <script lang="ts" setup>
16
+ import type { FileExt, PreviewFile } from './types';
17
+ import { fileCategoryMap } from './types';
18
+ import { shadowRoot } from './shared/const';
19
+ import Code from './category/Code.vue';
20
+ import Image from './category/Image.vue';
21
+ import Pdf from './category/Pdf.vue';
22
+ import Video from './category/Video.vue';
23
+ import { getFileNameAndExt } from '@/utils/getFileNameAndExt';
24
+
25
+ const attrs = useAttrs();
26
+
27
+ const file = shallowRef<Blob>();
28
+ const fileName = ref<string>();
29
+ const fileExt = ref<FileExt>();
30
+ const fileCategory = computed(() => fileCategoryMap[fileExt.value!]);
31
+
32
+ const components = {
33
+ image: Image,
34
+ pdf: Pdf,
35
+ video: Video,
36
+ };
37
+
38
+ const previewFile: PreviewFile = (_fileName, _file) => {
39
+ const { name, ext } = getFileNameAndExt(_fileName);
40
+
41
+ file.value = _file;
42
+ fileName.value = name;
43
+ fileExt.value = ext as FileExt;
44
+ };
45
+
46
+ useSmart();
47
+
48
+ onMounted(() => {
49
+ const el = useCurrentElement();
50
+ shadowRoot.value = el.value!.parentNode! as ShadowRoot;
51
+ });
52
+
53
+ defineExpose({
54
+ previewFile,
55
+ });
56
+ </script>
@@ -0,0 +1,2 @@
1
+ export const name = '文件预览';
2
+ export const tag = 'smart-file-preview';
@@ -0,0 +1,4 @@
1
+ /**
2
+ * 组件 ShadowRoot
3
+ */
4
+ export const shadowRoot = ref<ShadowRoot>();
@@ -0,0 +1,38 @@
1
+ export interface SmartFilePreviewProps {
2
+
3
+ }
4
+
5
+ /** 预览文件方法 */
6
+ export interface PreviewFile {
7
+ (fileName: string, file: Blob): void
8
+ }
9
+
10
+ /** 文件后缀对应的分类 */
11
+ export const fileCategoryMap = {
12
+ // 图片
13
+ jpg: 'image',
14
+ jpeg: 'image',
15
+ png: 'image',
16
+ bmp: 'image',
17
+ gif: 'image',
18
+ svg: 'image',
19
+ webp: 'image',
20
+
21
+ // 视频
22
+ mp4: 'video',
23
+ avi: 'video',
24
+ mov: 'video',
25
+ wmv: 'video',
26
+ flv: 'video',
27
+ mkv: 'video',
28
+ webm: 'video',
29
+
30
+ // PDF
31
+ pdf: 'pdf',
32
+ } as const;
33
+
34
+ /** 文件后缀 */
35
+ export type FileExt = keyof typeof fileCategoryMap;
36
+
37
+ /** 文件分类 */
38
+ export type FileCategory = typeof fileCategoryMap[FileExt];
@@ -0,0 +1,5 @@
1
+ import VueComponent from './index.vue';
2
+ import { tag } from './info';
3
+ import { defineCustomElements } from '@/utils/defineCustomElements';
4
+
5
+ defineCustomElements(tag, VueComponent);
@@ -0,0 +1,101 @@
1
+ <template>
2
+ <NConfigProvider :cls-prefix="classPrefix" :theme-overrides="commonOverrides" :locale="zhCN" abstract>
3
+ <NUpload
4
+ v-bind="props"
5
+ v-model:file-list="fileList"
6
+ :custom-request="customRequest"
7
+ @remove="onRemoved"
8
+ >
9
+ <slot>
10
+ <NButton v-if="[undefined, 'image'].includes(listType)">选择文件</NButton>
11
+ </slot>
12
+ </NUpload>
13
+ </NConfigProvider>
14
+ </template>
15
+
16
+ <script lang="ts" setup>
17
+ import type { UploadCustomRequestOptions, UploadFileInfo } from 'naive-ui';
18
+ import type { UploadFieldValueItem } from '@smartos-lib/utils';
19
+ import { NButton, NConfigProvider, NUpload, zhCN } from 'naive-ui';
20
+ import { getConfigProvider } from '@smartos-lib/core';
21
+ import type { Props } from './types';
22
+
23
+ const props = defineProps<Props>();
24
+ const list = defineModel<UploadFieldValueItem[]>('fileList', {
25
+ default: () => [],
26
+ });
27
+
28
+ const { classPrefix } = useSmart();
29
+
30
+ /** 内部维护的文件列表 */
31
+ const fileList = ref<UploadFileInfo[]>(
32
+ list.value.map(({ fileName: url }) => ({ id: url, name: url, url, status: 'finished' })),
33
+ );
34
+
35
+ /** 自定义上传 */
36
+ function customRequest({ file, onFinish, onError, onProgress }: UploadCustomRequestOptions) {
37
+ const originFile = file.file as File;
38
+
39
+ const form = new FormData();
40
+ form.set('file', originFile);
41
+
42
+ getConfigProvider('request')!({
43
+ method: 'post',
44
+ url: '/admin/sys-file/upload',
45
+ data: form,
46
+ headers: {
47
+ 'Content-Type': 'multipart/form-data',
48
+ },
49
+ onUploadProgress({ loaded, total }) {
50
+ onProgress({ percent: total ? Math.ceil((loaded / total) * 100) : 0 });
51
+ },
52
+ })
53
+ .then((res) => {
54
+ const data = res.data.data;
55
+
56
+ file.url = data.url;
57
+ onFinish();
58
+
59
+ nextTick(() => {
60
+ list.value.includes(data.url) || list.value.push({ fileName: data.url, originalFileName: originFile.name });
61
+ });
62
+ })
63
+ .catch((error) => {
64
+ onError();
65
+ console.error(error);
66
+ });
67
+ }
68
+
69
+ /** 已删除的文件, 从父组件中删除 */
70
+ function onRemoved() {
71
+ setTimeout(
72
+ () => {
73
+ for (let i = 0; i < list.value.length;) {
74
+ const url = list.value[i].fileName;
75
+
76
+ if (!fileList.value.some(file => file.url === url)) list.value.splice(i, 1);
77
+ else i++;
78
+ }
79
+ },
80
+ 10,
81
+ );
82
+ }
83
+
84
+ // 监听父组件值变化, 同步到内部维护的文件列表
85
+ watchDeep(list, (newList: UploadFieldValueItem[]) => {
86
+ // 在传入值中, 但不在内部维护的文件列表中, 则添加
87
+ newList.forEach(({ fileName: url }) => {
88
+ if (!fileList.value.some(file => file.url === url))
89
+ fileList.value.push({ id: url, name: url, url, status: 'finished' });
90
+ });
91
+ // 在内部维护的文件列表中, 但不在传入值中, 则删除
92
+ for (let i = 0; i < fileList.value.length;) {
93
+ const file = fileList.value[i];
94
+
95
+ if (file.status === 'finished' && file.url && !newList.some(({ fileName: url }) => url === file.url))
96
+ fileList.value.splice(i, 1);
97
+ else
98
+ i++;
99
+ }
100
+ });
101
+ </script>
@@ -0,0 +1,2 @@
1
+ export const name = '文件上传';
2
+ export const tag = 'smart-upload';
@@ -0,0 +1,28 @@
1
+ import type { UploadProps } from 'naive-ui';
2
+
3
+ export interface Props {
4
+ accept?: UploadProps['accept']
5
+ defaultFileList?: UploadProps['defaultFileList']
6
+ defaultUpload?: UploadProps['defaultUpload']
7
+ disabled?: UploadProps['disabled']
8
+ directory?: UploadProps['directory']
9
+ directoryDnd: UploadProps['directoryDnd']
10
+ fileListClass?: UploadProps['fileListClass']
11
+ fileListStyle?: UploadProps['fileListStyle']
12
+ imageGroupProps?: UploadProps['imageGroupProps']
13
+ inputProps?: UploadProps['inputProps']
14
+ listType?: UploadProps['listType']
15
+ max?: UploadProps['max']
16
+ multiple?: UploadProps['multiple']
17
+ renderIcon?: UploadProps['renderIcon']
18
+ shouldUseThumbnailUrl?: UploadProps['shouldUseThumbnailUrl']
19
+ showCancelButton?: UploadProps['showCancelButton']
20
+ showDownloadButton?: UploadProps['showDownloadButton']
21
+ showRemoveButton?: UploadProps['showRemoveButton']
22
+ showRetryButton?: UploadProps['showRetryButton']
23
+ showFileList?: UploadProps['showFileList']
24
+ showPreviewButton?: UploadProps['showPreviewButton']
25
+ showTrigger?: UploadProps['showTrigger']
26
+ triggerClass?: UploadProps['triggerClass']
27
+ triggerStyle?: UploadProps['triggerStyle']
28
+ };
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "../../tsconfig.json",
3
+ "compilerOptions": {
4
+ "types": [
5
+ "vitest/globals",
6
+ "vite/client",
7
+ "unplugin-icons/types/vue",
8
+ "naive-ui/volar",
9
+ "element-plus/global",
10
+
11
+ "vite-plugin-pages/client",
12
+ "vite-plugin-vue-layouts/client"
13
+ ]
14
+ }
15
+ }