feat!: publish per-component ESM entries as @timi/tdesign-mobile

This commit is contained in:
Timi
2026-11-23 20:28:05 +08:00
parent 7349bb3429
commit 3f4c98fbf3
44 changed files with 137 additions and 81 deletions
+2 -2
View File
@@ -72,8 +72,8 @@ jobs:
- name: Ensure version not published
if: ${{ steps.version.outputs.publish == 'true' }}
run: |
if npm view "timi-tdesign-mobile@${{ steps.version.outputs.version }}" version > /dev/null 2>&1; then
echo "FAIL: timi-tdesign-mobile@${{ steps.version.outputs.version }} 已存在于 nexus,请提升 package.json 版本"
if npm view "@timi/tdesign-mobile@${{ steps.version.outputs.version }}" version > /dev/null 2>&1; then
echo "FAIL: @timi/tdesign-mobile@${{ steps.version.outputs.version }} 已存在于 nexus,请提升 package.json 版本"
exit 1
fi
echo "OK: 版本未占用"
+4 -4
View File
@@ -1,12 +1,12 @@
# timi-tdesign-mobile
# @timi/tdesign-mobile
Vue 3 移动端通用组件库,依赖 `timi-web` 提供基础组件和编辑器能力。
Vue 3 移动端通用组件库,依赖 `@timi/web` 提供基础组件和编辑器能力。
本包不依赖 `timi-web-api`。业务项目可以只安装本包使用通用组件;需要业务接口、领域类型或用户状态时,再单独安装 `timi-web-api`。
本包不绑定业务 API 包。业务项目可以只安装本包使用通用组件;业务接口、领域类型和用户状态由应用层自行提供。
## 文章和通知组件
`ArticleEditor`、`ArticleView`、`NotifyEditor`、`NotifyView` 只约束对象的最小字段。`Article`、`Attachment` 和 `NotifyDetail` 支持携带业务自定义字段,不要求对象来自 `timi-web-api`。
`ArticleEditor`、`ArticleView`、`NotifyEditor`、`NotifyView` 只约束对象的最小字段。`Article`、`Attachment` 和 `NotifyDetail` 支持携带业务自定义字段,不要求对象来自特定 API 包。
上传和附件地址由业务项目通过回调注入:
+3
View File
@@ -22,8 +22,10 @@ declare module 'vue' {
BottomPopup: typeof import('./src/components/bottom-popup/index.vue')['default']
CardContainer: typeof import('./src/components/card-container/index.vue')['default']
CodeEditor: typeof import('./src/components/code-editor/index.vue')['default']
DropdownFilter: typeof import('./src/components/dropdown-filter/index.vue')['default']
DurationPicker: typeof import('./src/components/duration-picker/index.vue')['default']
EditorSearch: typeof import('./src/components/editor-search/index.vue')['default']
Item: typeof import('./src/components/timeline/item.vue')['default']
MasterDetail: typeof import('./src/components/master-detail/index.vue')['default']
MasterDetailPage: typeof import('./src/components/master-detail-page/index.vue')['default']
NotifyEditor: typeof import('./src/components/notify-editor/index.vue')['default']
@@ -44,6 +46,7 @@ declare module 'vue' {
TIcon: typeof import('tdesign-mobile-vue')['Icon']
TImage: typeof import('tdesign-mobile-vue')['Image']
TImageViewer: typeof import('tdesign-mobile-vue')['ImageViewer']
Timeline: typeof import('./src/components/timeline/index.vue')['default']
TInput: typeof import('tdesign-mobile-vue')['Input']
TiptapCodeBlockButton: typeof import('./src/components/tiptap-editor/TiptapCodeBlockButton.vue')['default']
TiptapEditor: typeof import('./src/components/tiptap-editor/index.vue')['default']
+26 -7
View File
@@ -1,11 +1,15 @@
{
"name": "timi-tdesign-mobile",
"main": "./dist/timi-tdesign-mobile.umd.js",
"name": "@timi/tdesign-mobile",
"type": "module",
"main": "./dist/index.js",
"types": "./dist/index.d.ts",
"module": "./dist/timi-tdesign-mobile.mjs",
"module": "./dist/index.js",
"style": "./dist/timi-tdesign-mobile.css",
"sideEffects": [
"**/*.css"
],
"private": false,
"version": "1.5.0",
"version": "2.0.0",
"license": "MIT",
"scripts": {
"dev": "pnpm run -C docs dev",
@@ -25,8 +29,23 @@
"exports": {
".": {
"types": "./dist/index.d.ts",
"import": "./dist/timi-tdesign-mobile.mjs",
"require": "./dist/timi-tdesign-mobile.umd.js"
"import": "./dist/index.js"
},
"./components": {
"types": "./dist/components/index.d.ts",
"import": "./dist/components/index.js"
},
"./components/*": {
"types": "./dist/components/*/index.d.ts",
"import": "./dist/components/*/index.js"
},
"./directives": {
"types": "./dist/directives/index.d.ts",
"import": "./dist/directives/index.js"
},
"./utils/message": {
"types": "./dist/utils/message.d.ts",
"import": "./dist/utils/message.js"
},
"./style.css": "./dist/timi-tdesign-mobile.css",
"./src/*": "./src/*"
@@ -36,7 +55,7 @@
},
"dependencies": {
"tdesign-mobile-vue": "^1.17.1",
"timi-web": "^1.0.2"
"@timi/web": "^2.0.0"
},
"peerDependencies": {
"vue": "^3.5.0",
+1 -1
View File
@@ -84,7 +84,7 @@
<script setup lang="ts">
import { nextTick, useTemplateRef } from "vue";
import { MarkdownView } from "timi-web";
import { MarkdownView } from "@timi/web/components/markdown-view";
import AiChatThinking from "./AiChatThinking.vue";
import type {
AiChatMessage,
+1 -1
View File
@@ -1,4 +1,4 @@
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
import AiChatComposerView from "./AiChatComposer.vue";
import AiChatMessageListView from "./AiChatMessageList.vue";
import AiChatPanelView from "./AiChatPanel.vue";
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const AppShell = WebToolkit.withInstall(view);
export default AppShell;
+1 -1
View File
@@ -3,7 +3,7 @@ import {
TEMP_FILE_ID_ATTR,
isLocalMediaId,
normalizeContent
} from "timi-web/editor";
} from "@timi/web/editor";
import type { ArticleContentType, Attachment } from "./types";
/** 文章内容中附件和临时文件的标识前缀。 */
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
import type { Article } from "./types";
export type {
+2 -2
View File
@@ -25,7 +25,7 @@
<script lang="ts" setup>
import type { Article, ArticleContentType, Attachment, UploadResult } from "./types";
import { MarkdownEditor } from "timi-web";
import { MarkdownEditor } from "@timi/web/components/markdown-editor";
import { TiptapEditor } from "../tiptap-editor";
import type { TiptapEditorExpose } from "../tiptap-editor";
import {
@@ -41,7 +41,7 @@ import {
ATTACHMENT_ID_ATTR,
TEMP_FILE_ID_ATTR,
normalizeContent
} from "timi-web/editor";
} from "@timi/web/editor";
defineOptions({
name: "ArticleEditor"
+1 -1
View File
@@ -1,4 +1,4 @@
import type { UploadResult as EditorUploadResult } from "timi-web/editor";
import type { UploadResult as EditorUploadResult } from "@timi/web/editor";
/** 文章编辑器支持的正文类型。 */
export type ArticleContentType = "TEXT" | "MARKDOWN" | "TIP_TAP";
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const ArticleView = WebToolkit.withInstall(view);
export default ArticleView;
+2 -2
View File
@@ -14,14 +14,14 @@
<script lang="ts" setup>
import type { Article, Attachment } from "../article-editor/types";
import { MarkdownView } from "timi-web";
import { MarkdownView } from "@timi/web/components/markdown-view";
import { TiptapView } from "../tiptap-view";
import {
getAttachmentIdFromSrc,
normalizeArticleContentType,
normalizeRawArticleContent
} from "../article-editor/content";
import { ATTACHMENT_ID_ATTR, normalizeContent } from "timi-web/editor";
import { ATTACHMENT_ID_ATTR, normalizeContent } from "@timi/web/editor";
defineOptions({
name: "ArticleView"
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export type {
AttachmentSelectorItem,
+1 -1
View File
@@ -63,7 +63,7 @@ import type {
AttachmentSelectorViewerItem
} from "./types";
import { getMediaKind, getMediaPreviewURL } from "./utils";
import { CenterTips } from "timi-web";
import { CenterTips } from "@timi/web/components/center-tips";
defineOptions({
name: "AttachmentSelector",
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const BottomPopup = WebToolkit.withInstall(view);
export default BottomPopup;
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const CardContainer = WebToolkit.withInstall(view);
export default CardContainer;
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
import "./style.less";
export type CodeEditorScrollState = {
+2 -2
View File
@@ -65,8 +65,8 @@ import {
replaceMatchText,
type TextSearchMatch,
type TextSearchOptions
} from "timi-web/editor";
import { highlightCode, resolveCodeEditorKeydown, resolvePrismLanguage } from "timi-web/editor";
} from "@timi/web/editor";
import { highlightCode, resolveCodeEditorKeydown, resolvePrismLanguage } from "@timi/web/editor";
defineOptions({
name: "CodeEditor"
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const DropdownFilter = WebToolkit.withInstall(view);
export default DropdownFilter;
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const DurationPicker = WebToolkit.withInstall(view);
export default DurationPicker;
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const MasterDetailPage = WebToolkit.withInstall(view);
export default MasterDetailPage;
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const MasterDetail = WebToolkit.withInstall(view);
export default MasterDetail;
+1 -1
View File
@@ -31,7 +31,7 @@
<script setup lang="ts">
import { computed, type StyleValue } from "vue";
import { CenterTips } from "timi-web";
import { CenterTips } from "@timi/web/components/center-tips";
import { useLayout } from "../../composables/use-layout";
import type { MasterDetailProps } from "./type";
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
import type { NotifyDetail } from "./types";
export type { NotifyContentType, NotifyDetail } from "./types";
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const NotifyView = WebToolkit.withInstall(view);
export default NotifyView;
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export type {
PageTransitionBackground,
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const PaneTransition = WebToolkit.withInstall(view);
export default PaneTransition;
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const RootLayout = WebToolkit.withInstall(view);
export default RootLayout;
+1 -1
View File
@@ -6,7 +6,7 @@
</template>
<script lang="ts" setup>
import { Copyright } from "timi-web";
import { Copyright } from "@timi/web/components/copyright";
defineOptions({
name: "RootLayout"
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export type {
SpaceAlign,
+1 -1
View File
@@ -1,4 +1,4 @@
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
import timeline from "./index.vue";
import item from "./item.vue";
@@ -21,8 +21,8 @@
<script lang="ts" setup>
import type { PickerValue } from "tdesign-mobile-vue";
import { supportedCodeLanguages } from "timi-web/editor";
import type { TiptapEditorInstance } from "timi-web/editor";
import { supportedCodeLanguages } from "@timi/web/editor";
import type { TiptapEditorInstance } from "@timi/web/editor";
defineOptions({
name: "TiptapCodeBlockButton"
@@ -60,7 +60,7 @@
<script lang="ts" setup>
import { showPlatformMessage } from "../message";
import type { TiptapEditorInstance } from "timi-web/editor";
import type { TiptapEditorInstance } from "@timi/web/editor";
import BottomPopup from "../bottom-popup/index.vue";
defineOptions({
@@ -35,7 +35,7 @@
</template>
<script lang="ts" setup>
import type { TiptapEditorInstance } from "timi-web/editor";
import type { TiptapEditorInstance } from "@timi/web/editor";
import BottomPopup from "../bottom-popup/index.vue";
defineOptions({
@@ -90,7 +90,7 @@
<script lang="ts" setup>
import { showPlatformMessage } from "../message";
import type { TiptapEditorInstance, UploadResult } from "timi-web/editor";
import type { TiptapEditorInstance, UploadResult } from "@timi/web/editor";
import BottomPopup from "../bottom-popup/index.vue";
defineOptions({
@@ -61,8 +61,8 @@
</template>
<script lang="ts" setup>
import { TABLE_PICKER_SIZE } from "timi-web/editor";
import type { TiptapEditorInstance } from "timi-web/editor";
import { TABLE_PICKER_SIZE } from "@timi/web/editor";
import type { TiptapEditorInstance } from "@timi/web/editor";
import BottomPopup from "../bottom-popup/index.vue";
defineOptions({
@@ -151,8 +151,8 @@
<script lang="ts" setup>
import type { ColorObject } from "tdesign-mobile-vue";
import type { AlignType, UploadResult, TiptapEditorInstance } from "timi-web/editor";
import { headingMeta } from "timi-web/editor";
import type { AlignType, UploadResult, TiptapEditorInstance } from "@timi/web/editor";
import { headingMeta } from "@timi/web/editor";
import TiptapCodeBlockButton from "./TiptapCodeBlockButton.vue";
import TiptapIframeButton from "./TiptapIframeButton.vue";
import TiptapLinkButton from "./TiptapLinkButton.vue";
+3 -3
View File
@@ -1,8 +1,8 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import type { TiptapEditorInstance } from "timi-web/editor";
import { WebToolkit } from "@timi/web/utils";
import type { TiptapEditorInstance } from "@timi/web/editor";
export * from "timi-web/editor";
export * from "@timi/web/editor";
export type TiptapEditorExpose = {
submit: () => Promise<string>;
getPendingMediaCount: () => number;
+5 -5
View File
@@ -58,18 +58,18 @@ import {
buildSearchRegex,
replaceMatchText,
type TextSearchOptions
} from "timi-web/editor";
import { Toolkit } from "timi-web";
import type { PendingMediaItem, UploadMediaType, UploadResult } from "timi-web/editor";
} from "@timi/web/editor";
import { Toolkit } from "@timi/web/utils";
import type { PendingMediaItem, UploadMediaType, UploadResult } from "@timi/web/editor";
import TiptapToolbar from "./TiptapToolbar.vue";
import { useTiptapEditor } from "timi-web/editor";
import { useTiptapEditor } from "@timi/web/editor";
import {
ATTACHMENT_ID_ATTR,
LOCAL_MEDIA_ID_PREFIX,
TEMP_FILE_ID_ATTR,
isLocalMediaId,
normalizeContent
} from "timi-web/editor";
} from "@timi/web/editor";
defineOptions({
name: "TiptapEditor"
+1 -1
View File
@@ -1,5 +1,5 @@
import view from "./index.vue";
import { WebToolkit } from "timi-web";
import { WebToolkit } from "@timi/web/utils";
export const TiptapView = WebToolkit.withInstall(view);
export default TiptapView;
+1 -1
View File
@@ -10,7 +10,7 @@
</template>
<script lang="ts" setup>
import { normalizeContent, useTiptapView } from "timi-web/editor";
import { normalizeContent, useTiptapView } from "@timi/web/editor";
defineOptions({
name: "TiptapView"
-1
View File
@@ -2,7 +2,6 @@ import "./assets/style/tdesign-custom.less";
import "./assets/style/entrance-transition.less";
import "./assets/style/page-layout.less";
import "./components/tiptap-content.less";
import "timi-web/style.css";
export * from "./components";
export * from "./directives";
+52 -17
View File
@@ -1,3 +1,4 @@
import { existsSync, readdirSync, statSync } from "fs";
import { resolve } from "path";
import { Alias, defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
@@ -8,11 +9,44 @@ import dts from "vite-plugin-dts";
const alias: Alias[] = [
{
find: /^timi-tdesign-mobile(\/(es|lib))?$/,
find: /^@timi\/tdesign-mobile(\/(es|lib))?$/,
replacement: resolve(__dirname, "./src/index.ts")
}
];
/**
* 递归收集组件入口,组件目录下存在 index.ts 时即视为一个可独立导出的组件
*/
function collectComponentEntries(
dir: string,
prefix: string,
entries: Record<string, string>
) {
for (const name of readdirSync(dir)) {
const fullPath = resolve(dir, name);
if (!statSync(fullPath).isDirectory()) {
continue;
}
const entry = resolve(fullPath, "index.ts");
if (existsSync(entry)) {
entries[`${prefix}/${name}/index`] = entry;
}
collectComponentEntries(fullPath, `${prefix}/${name}`, entries);
}
}
const entries: Record<string, string> = {
index: resolve(__dirname, "./src/index.ts"),
"components/index": resolve(__dirname, "./src/components/index.ts"),
"directives/index": resolve(__dirname, "./src/directives/index.ts"),
"utils/message": resolve(__dirname, "./src/utils/message.ts")
};
collectComponentEntries(
resolve(__dirname, "./src/components"),
"components",
entries
);
export default defineConfig({
server: {
port: 3004,
@@ -24,33 +58,34 @@ export default defineConfig({
build: {
outDir: "dist",
lib: {
entry: resolve(__dirname, "./src/index.ts"),
name: "TimiTDesignMobile",
fileName: "timi-tdesign-mobile"
entry: entries,
formats: ["es"],
fileName: (_format, entryName) => `${entryName}.js`,
cssFileName: "timi-tdesign-mobile"
},
rollupOptions: {
external: [
"vue",
"vue-router",
"timi-web",
"tdesign-mobile-vue"
],
external: (id) =>
id === "vue" ||
id === "vue-router" ||
id === "@timi/web" ||
id.startsWith("@timi/web/") ||
id === "tdesign-mobile-vue" ||
id.startsWith("tdesign-mobile-vue/"),
output: {
globals: {
vue: "Vue",
"timi-web": "TimiWeb"
}
chunkFileNames: "chunks/[name]-[hash].js"
}
},
minify: "terser"
cssCodeSplit: false,
minify: "terser",
target: "es2017"
},
plugins: [
vue({
include: [/\.vue$/, /\.md$/]
}),
dts({
pathsToAliases: false,
aliasesExclude: [/^timi-web\/editor$/]
entryRoot: "src",
pathsToAliases: false
}),
AutoImport({
imports: [