@easy-editor/materials-dashboard-text 0.0.15 → 0.0.17
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/CHANGELOG.md +12 -0
- package/dist/component.min.js +1 -2
- package/dist/index.min.js +1 -2
- package/dist/meta.min.js +1 -2
- package/easypack.config.ts +10 -0
- package/package.json +6 -10
- package/src/assets/plain.png +0 -0
- package/src/component.module.css +58 -0
- package/src/component.tsx +286 -0
- package/src/configure.ts +388 -0
- package/{dist/src/constants.d.ts → src/constants.ts} +17 -16
- package/src/index.tsx +7 -0
- package/src/meta.ts +26 -0
- package/src/snippets.ts +151 -0
- package/src/type.d.ts +8 -0
- package/tsconfig.json +20 -9
- package/.vite/plugins/vite-plugin-external-deps.ts +0 -224
- package/.vite/plugins/vite-plugin-material-dev.ts +0 -218
- package/dist/component.esm.js +0 -134
- package/dist/component.esm.js.map +0 -1
- package/dist/component.js +0 -143
- package/dist/component.js.map +0 -1
- package/dist/component.min.js.map +0 -1
- package/dist/index.cjs +0 -513
- package/dist/index.cjs.map +0 -1
- package/dist/index.esm.js +0 -510
- package/dist/index.esm.js.map +0 -1
- package/dist/index.js +0 -518
- package/dist/index.js.map +0 -1
- package/dist/index.min.js.map +0 -1
- package/dist/meta.esm.js +0 -380
- package/dist/meta.esm.js.map +0 -1
- package/dist/meta.js +0 -388
- package/dist/meta.js.map +0 -1
- package/dist/meta.min.js.map +0 -1
- package/dist/src/component.d.ts +0 -48
- package/dist/src/configure.d.ts +0 -6
- package/dist/src/index.d.ts +0 -6
- package/dist/src/meta.d.ts +0 -6
- package/dist/src/snippets.d.ts +0 -6
- package/vite.config.ts +0 -54
|
@@ -1,224 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vite Plugin: External Dependencies
|
|
3
|
-
* 外部依赖插件 - 在开发模式下将 React/ReactDOM 外部化
|
|
4
|
-
*
|
|
5
|
-
* 用途:
|
|
6
|
-
* - 防止 Vite 将 React/ReactDOM 打包进开发服务器的模块
|
|
7
|
-
* - 强制使用父应用(dashboard)提供的 React 实例
|
|
8
|
-
* - 解决双 React 实例导致的 "Invalid hook call" 错误
|
|
9
|
-
*/
|
|
10
|
-
|
|
11
|
-
import type { Plugin } from 'vite'
|
|
12
|
-
|
|
13
|
-
interface ExternalDepsOptions {
|
|
14
|
-
/** 需要外部化的依赖列表 */
|
|
15
|
-
externals?: string[]
|
|
16
|
-
/** 全局变量映射 */
|
|
17
|
-
globals?: Record<string, string>
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
const DEFAULT_EXTERNALS = ['react', 'react-dom', 'react/jsx-runtime']
|
|
21
|
-
|
|
22
|
-
const DEFAULT_GLOBALS: Record<string, string> = {
|
|
23
|
-
react: 'React',
|
|
24
|
-
'react-dom': 'ReactDOM',
|
|
25
|
-
'react/jsx-runtime': 'jsxRuntime',
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* 创建外部依赖插件
|
|
30
|
-
*/
|
|
31
|
-
export function externalDeps(options: ExternalDepsOptions = {}): Plugin {
|
|
32
|
-
const externals = options.externals || DEFAULT_EXTERNALS
|
|
33
|
-
const globals = { ...DEFAULT_GLOBALS, ...options.globals }
|
|
34
|
-
|
|
35
|
-
// 虚拟模块前缀
|
|
36
|
-
const VIRTUAL_PREFIX = '\0virtual:external:'
|
|
37
|
-
|
|
38
|
-
return {
|
|
39
|
-
name: 'vite-plugin-external-deps',
|
|
40
|
-
enforce: 'pre',
|
|
41
|
-
|
|
42
|
-
// 在开发模式下拦截模块解析
|
|
43
|
-
resolveId(id) {
|
|
44
|
-
// 检查是否是需要外部化的依赖
|
|
45
|
-
if (externals.includes(id)) {
|
|
46
|
-
// 返回虚拟模块 ID(\0 前缀告诉 Vite 这是虚拟模块)
|
|
47
|
-
return VIRTUAL_PREFIX + id
|
|
48
|
-
}
|
|
49
|
-
return null
|
|
50
|
-
},
|
|
51
|
-
|
|
52
|
-
// 加载外部模块的代理代码
|
|
53
|
-
load(id) {
|
|
54
|
-
// 检查是否是虚拟外部模块
|
|
55
|
-
if (!id.startsWith(VIRTUAL_PREFIX)) {
|
|
56
|
-
return null
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const moduleName = id.slice(VIRTUAL_PREFIX.length)
|
|
60
|
-
const globalName = globals[moduleName]
|
|
61
|
-
|
|
62
|
-
if (!globalName) {
|
|
63
|
-
throw new Error(
|
|
64
|
-
`[vite-plugin-external-deps] No global mapping found for "${moduleName}". ` +
|
|
65
|
-
`Please add it to the globals option.`
|
|
66
|
-
)
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
// 对于 react,导出常用的命名导出
|
|
70
|
-
if (moduleName === 'react') {
|
|
71
|
-
return `
|
|
72
|
-
// External module: react -> window.${globalName}
|
|
73
|
-
const React = window.${globalName};
|
|
74
|
-
if (!React) {
|
|
75
|
-
throw new Error(
|
|
76
|
-
'External dependency "react" (window.${globalName}) is not available. ' +
|
|
77
|
-
'Make sure the parent application has loaded it globally.'
|
|
78
|
-
);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// 导出默认导出
|
|
82
|
-
export default React;
|
|
83
|
-
|
|
84
|
-
// 导出常用的命名导出
|
|
85
|
-
export const {
|
|
86
|
-
useState,
|
|
87
|
-
useEffect,
|
|
88
|
-
useContext,
|
|
89
|
-
useReducer,
|
|
90
|
-
useCallback,
|
|
91
|
-
useMemo,
|
|
92
|
-
useRef,
|
|
93
|
-
useImperativeHandle,
|
|
94
|
-
useLayoutEffect,
|
|
95
|
-
useDebugValue,
|
|
96
|
-
useDeferredValue,
|
|
97
|
-
useTransition,
|
|
98
|
-
useId,
|
|
99
|
-
useSyncExternalStore,
|
|
100
|
-
Fragment,
|
|
101
|
-
StrictMode,
|
|
102
|
-
Suspense,
|
|
103
|
-
createElement,
|
|
104
|
-
createContext,
|
|
105
|
-
forwardRef,
|
|
106
|
-
lazy,
|
|
107
|
-
memo,
|
|
108
|
-
startTransition,
|
|
109
|
-
Component,
|
|
110
|
-
PureComponent,
|
|
111
|
-
Children,
|
|
112
|
-
cloneElement,
|
|
113
|
-
isValidElement,
|
|
114
|
-
} = React;
|
|
115
|
-
`
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
// 对于 react-dom,导出常用的命名导出
|
|
119
|
-
if (moduleName === 'react-dom') {
|
|
120
|
-
return `
|
|
121
|
-
// External module: react-dom -> window.${globalName}
|
|
122
|
-
const ReactDOM = window.${globalName};
|
|
123
|
-
if (!ReactDOM) {
|
|
124
|
-
throw new Error(
|
|
125
|
-
'External dependency "react-dom" (window.${globalName}) is not available. ' +
|
|
126
|
-
'Make sure the parent application has loaded it globally.'
|
|
127
|
-
);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// 导出默认导出
|
|
131
|
-
export default ReactDOM;
|
|
132
|
-
|
|
133
|
-
// 导出常用的命名导出
|
|
134
|
-
export const {
|
|
135
|
-
createRoot,
|
|
136
|
-
hydrateRoot,
|
|
137
|
-
render,
|
|
138
|
-
hydrate,
|
|
139
|
-
unmountComponentAtNode,
|
|
140
|
-
findDOMNode,
|
|
141
|
-
flushSync,
|
|
142
|
-
} = ReactDOM;
|
|
143
|
-
`
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
// 对于 react/jsx-runtime
|
|
147
|
-
if (moduleName === 'react/jsx-runtime') {
|
|
148
|
-
return `
|
|
149
|
-
// External module: react/jsx-runtime -> window.${globalName}
|
|
150
|
-
const jsxRuntime = window.${globalName};
|
|
151
|
-
if (!jsxRuntime) {
|
|
152
|
-
throw new Error(
|
|
153
|
-
'External dependency "react/jsx-runtime" (window.${globalName}) is not available. ' +
|
|
154
|
-
'Make sure the parent application has loaded it globally.'
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
// 导出 JSX 运行时函数
|
|
159
|
-
export const { jsx, jsxs, Fragment } = jsxRuntime;
|
|
160
|
-
export default jsxRuntime;
|
|
161
|
-
`
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
// 对于 @easy-editor/core
|
|
165
|
-
if (moduleName === '@easy-editor/core') {
|
|
166
|
-
return `
|
|
167
|
-
// External module: @easy-editor/core -> window.${globalName}
|
|
168
|
-
const EasyEditorCore = window.${globalName};
|
|
169
|
-
if (!EasyEditorCore) {
|
|
170
|
-
throw new Error(
|
|
171
|
-
'External dependency "@easy-editor/core" (window.${globalName}) is not available. ' +
|
|
172
|
-
'Make sure the parent application has loaded it globally.'
|
|
173
|
-
);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
// 导出整个模块
|
|
177
|
-
export default EasyEditorCore;
|
|
178
|
-
export * from '\0virtual:external:@easy-editor/core:named';
|
|
179
|
-
`
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
// 处理 @easy-editor/core 的命名导出
|
|
183
|
-
if (id === '\0virtual:external:@easy-editor/core:named') {
|
|
184
|
-
return `
|
|
185
|
-
const EasyEditorCore = window.${globals['@easy-editor/core']};
|
|
186
|
-
// 尝试导出所有属性
|
|
187
|
-
const keys = Object.keys(EasyEditorCore || {});
|
|
188
|
-
const exports = {};
|
|
189
|
-
keys.forEach(key => {
|
|
190
|
-
exports[key] = EasyEditorCore[key];
|
|
191
|
-
});
|
|
192
|
-
export default exports;
|
|
193
|
-
`
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
// 默认情况:简单的全局变量代理
|
|
197
|
-
return `
|
|
198
|
-
// External module: ${moduleName} -> window.${globalName}
|
|
199
|
-
const mod = window.${globalName};
|
|
200
|
-
if (!mod) {
|
|
201
|
-
throw new Error(
|
|
202
|
-
'External dependency "${moduleName}" (window.${globalName}) is not available. ' +
|
|
203
|
-
'Make sure the parent application has loaded it globally.'
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
export default mod;
|
|
207
|
-
`
|
|
208
|
-
},
|
|
209
|
-
|
|
210
|
-
// 配置 Rollup 外部化(用于构建)
|
|
211
|
-
config(config) {
|
|
212
|
-
return {
|
|
213
|
-
build: {
|
|
214
|
-
rollupOptions: {
|
|
215
|
-
external: externals,
|
|
216
|
-
output: {
|
|
217
|
-
globals,
|
|
218
|
-
},
|
|
219
|
-
},
|
|
220
|
-
},
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
}
|
|
224
|
-
}
|
|
@@ -1,218 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Vite Plugin for Material Development
|
|
3
|
-
* 物料开发 Vite 插件 - 提供物料调试所需的 API 和 WebSocket 通知
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Plugin, ViteDevServer } from 'vite'
|
|
7
|
-
import type { IncomingMessage, ServerResponse } from 'node:http'
|
|
8
|
-
import { WebSocketServer, WebSocket } from 'ws'
|
|
9
|
-
|
|
10
|
-
interface MaterialDevPluginOptions {
|
|
11
|
-
/** 物料入口文件路径 */
|
|
12
|
-
entry?: string
|
|
13
|
-
/** WebSocket 端口(默认与 HTTP 端口相同) */
|
|
14
|
-
wsPort?: number
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* 物料开发插件
|
|
19
|
-
* 提供:
|
|
20
|
-
* - /api/health - 健康检查
|
|
21
|
-
* - /api/material - 物料信息
|
|
22
|
-
* - WebSocket 通知 - 文件变更时通知连接的客户端
|
|
23
|
-
*/
|
|
24
|
-
export function materialDevPlugin(options: MaterialDevPluginOptions = {}): Plugin {
|
|
25
|
-
const { entry = '/src/index.tsx' } = options
|
|
26
|
-
|
|
27
|
-
let server: ViteDevServer
|
|
28
|
-
let wss: WebSocketServer | null = null
|
|
29
|
-
const clients = new Set<WebSocket>()
|
|
30
|
-
|
|
31
|
-
// 广播消息给所有连接的客户端
|
|
32
|
-
function broadcast(message: object) {
|
|
33
|
-
const data = JSON.stringify(message)
|
|
34
|
-
for (const client of clients) {
|
|
35
|
-
if (client.readyState === WebSocket.OPEN) {
|
|
36
|
-
client.send(data)
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
return {
|
|
42
|
-
name: 'vite-plugin-material-dev',
|
|
43
|
-
|
|
44
|
-
configureServer(_server) {
|
|
45
|
-
server = _server
|
|
46
|
-
|
|
47
|
-
// 创建 WebSocket 服务器,复用 Vite 的 HTTP 服务器
|
|
48
|
-
wss = new WebSocketServer({ noServer: true })
|
|
49
|
-
|
|
50
|
-
// 处理 WebSocket 升级请求
|
|
51
|
-
server.httpServer?.on('upgrade', (request, socket, head) => {
|
|
52
|
-
// 只处理 /ws 路径的 WebSocket 请求,避免与 Vite HMR 冲突
|
|
53
|
-
if (request.url === '/ws' || request.url === '/__material_ws__') {
|
|
54
|
-
wss?.handleUpgrade(request, socket, head, ws => {
|
|
55
|
-
wss?.emit('connection', ws, request)
|
|
56
|
-
})
|
|
57
|
-
}
|
|
58
|
-
})
|
|
59
|
-
|
|
60
|
-
wss.on('connection', ws => {
|
|
61
|
-
console.log('[MaterialDevPlugin] Client connected')
|
|
62
|
-
clients.add(ws)
|
|
63
|
-
|
|
64
|
-
// 发送连接成功消息
|
|
65
|
-
ws.send(
|
|
66
|
-
JSON.stringify({
|
|
67
|
-
type: 'connected',
|
|
68
|
-
message: 'Material dev server connected',
|
|
69
|
-
timestamp: Date.now(),
|
|
70
|
-
}),
|
|
71
|
-
)
|
|
72
|
-
|
|
73
|
-
ws.on('close', () => {
|
|
74
|
-
console.log('[MaterialDevPlugin] Client disconnected')
|
|
75
|
-
clients.delete(ws)
|
|
76
|
-
})
|
|
77
|
-
|
|
78
|
-
ws.on('error', error => {
|
|
79
|
-
console.error('[MaterialDevPlugin] WebSocket error:', error)
|
|
80
|
-
clients.delete(ws)
|
|
81
|
-
})
|
|
82
|
-
})
|
|
83
|
-
|
|
84
|
-
// 处理 CORS 预检请求(需要在其他中间件之前)
|
|
85
|
-
server.middlewares.use((req: IncomingMessage, res: ServerResponse, next: () => void) => {
|
|
86
|
-
if (req.method === 'OPTIONS') {
|
|
87
|
-
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
88
|
-
res.setHeader('Access-Control-Allow-Methods', 'GET, POST, OPTIONS')
|
|
89
|
-
res.setHeader('Access-Control-Allow-Headers', 'Content-Type')
|
|
90
|
-
res.statusCode = 204
|
|
91
|
-
res.end()
|
|
92
|
-
return
|
|
93
|
-
}
|
|
94
|
-
next()
|
|
95
|
-
})
|
|
96
|
-
|
|
97
|
-
// 健康检查 API
|
|
98
|
-
server.middlewares.use('/api/health', (_req: IncomingMessage, res: ServerResponse) => {
|
|
99
|
-
res.setHeader('Content-Type', 'application/json')
|
|
100
|
-
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
101
|
-
res.end(
|
|
102
|
-
JSON.stringify({
|
|
103
|
-
status: 'ok',
|
|
104
|
-
timestamp: Date.now(),
|
|
105
|
-
server: 'vite',
|
|
106
|
-
wsPath: '/ws',
|
|
107
|
-
}),
|
|
108
|
-
)
|
|
109
|
-
})
|
|
110
|
-
|
|
111
|
-
// 物料信息 API
|
|
112
|
-
server.middlewares.use('/api/material', async (_req: IncomingMessage, res: ServerResponse) => {
|
|
113
|
-
res.setHeader('Content-Type', 'application/json')
|
|
114
|
-
res.setHeader('Access-Control-Allow-Origin', '*')
|
|
115
|
-
|
|
116
|
-
try {
|
|
117
|
-
// 使用 Vite 的 SSR 模块加载能力加载物料模块
|
|
118
|
-
const module = await server.ssrLoadModule(entry)
|
|
119
|
-
|
|
120
|
-
const meta = module.meta || module.default?.meta
|
|
121
|
-
const component = module.component || module.default
|
|
122
|
-
|
|
123
|
-
if (!meta) {
|
|
124
|
-
res.statusCode = 400
|
|
125
|
-
res.end(
|
|
126
|
-
JSON.stringify({
|
|
127
|
-
error: 'Material meta not found. Make sure to export "meta" from the entry file.',
|
|
128
|
-
}),
|
|
129
|
-
)
|
|
130
|
-
return
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
// 返回物料信息
|
|
134
|
-
const materialInfo = {
|
|
135
|
-
// 基本信息
|
|
136
|
-
name: meta.componentName,
|
|
137
|
-
title: meta.title,
|
|
138
|
-
version: meta.npm?.version || '0.0.0-dev',
|
|
139
|
-
group: meta.group,
|
|
140
|
-
category: meta.category,
|
|
141
|
-
|
|
142
|
-
// 入口信息
|
|
143
|
-
entry,
|
|
144
|
-
|
|
145
|
-
// 模块状态
|
|
146
|
-
hasComponent: !!component,
|
|
147
|
-
hasMeta: !!meta,
|
|
148
|
-
hasConfigure: !!meta.configure,
|
|
149
|
-
hasSnippets: Array.isArray(meta.snippets) && meta.snippets.length > 0,
|
|
150
|
-
|
|
151
|
-
// WebSocket 路径
|
|
152
|
-
wsPath: '/ws',
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
res.end(JSON.stringify(materialInfo))
|
|
156
|
-
} catch (error) {
|
|
157
|
-
console.error('[MaterialDevPlugin] Failed to load material:', error)
|
|
158
|
-
res.statusCode = 500
|
|
159
|
-
res.end(
|
|
160
|
-
JSON.stringify({
|
|
161
|
-
error: error instanceof Error ? error.message : String(error),
|
|
162
|
-
}),
|
|
163
|
-
)
|
|
164
|
-
}
|
|
165
|
-
})
|
|
166
|
-
|
|
167
|
-
// 在服务器启动时打印信息
|
|
168
|
-
server.httpServer?.once('listening', () => {
|
|
169
|
-
const address = server.httpServer?.address()
|
|
170
|
-
const port = typeof address === 'object' && address ? address.port : 5001
|
|
171
|
-
const host = server.config.server.host || 'localhost'
|
|
172
|
-
|
|
173
|
-
setTimeout(() => {
|
|
174
|
-
console.log('')
|
|
175
|
-
console.log('\x1b[36m%s\x1b[0m', ' Material Dev Server Ready')
|
|
176
|
-
console.log('')
|
|
177
|
-
console.log(` Health Check: http://${host}:${port}/api/health`)
|
|
178
|
-
console.log(` Material Info: http://${host}:${port}/api/material`)
|
|
179
|
-
console.log(` Module Entry: http://${host}:${port}${entry}`)
|
|
180
|
-
console.log(` WebSocket: ws://${host}:${port}/ws`)
|
|
181
|
-
console.log('')
|
|
182
|
-
console.log('\x1b[33m%s\x1b[0m', ' Connect this URL in EasyEditor to start debugging')
|
|
183
|
-
console.log('')
|
|
184
|
-
}, 100)
|
|
185
|
-
})
|
|
186
|
-
},
|
|
187
|
-
|
|
188
|
-
// 监听 Vite 的 HMR 事件,转发给我们的 WebSocket 客户端
|
|
189
|
-
handleHotUpdate({ file, modules }) {
|
|
190
|
-
console.log(`[MaterialDevPlugin] File changed: ${file}`)
|
|
191
|
-
|
|
192
|
-
// 通知所有连接的客户端
|
|
193
|
-
broadcast({
|
|
194
|
-
type: 'update',
|
|
195
|
-
file,
|
|
196
|
-
timestamp: Date.now(),
|
|
197
|
-
modules: modules.map(m => m.id),
|
|
198
|
-
})
|
|
199
|
-
|
|
200
|
-
// 返回 undefined 让 Vite 继续处理 HMR
|
|
201
|
-
return
|
|
202
|
-
},
|
|
203
|
-
|
|
204
|
-
// 插件关闭时清理
|
|
205
|
-
closeBundle() {
|
|
206
|
-
if (wss) {
|
|
207
|
-
for (const client of clients) {
|
|
208
|
-
client.close()
|
|
209
|
-
}
|
|
210
|
-
clients.clear()
|
|
211
|
-
wss.close()
|
|
212
|
-
wss = null
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
}
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
export default materialDevPlugin
|
package/dist/component.esm.js
DELETED
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
/* @easy-editor/materials-dashboard-text v0.0.15 (component, esm) */
|
|
2
|
-
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
3
|
-
|
|
4
|
-
function r(e){var t,f,n="";if("string"==typeof e||"number"==typeof e)n+=e;else if("object"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=" "),n+=f);}else for(f in e)e[f]&&(n&&(n+=" "),n+=f);return n}function clsx(){for(var e,t,f=0,n="",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=" "),n+=t);return n}
|
|
5
|
-
|
|
6
|
-
function cn(...inputs) {
|
|
7
|
-
return clsx(inputs);
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
function styleInject(css, ref) {
|
|
11
|
-
if (ref === void 0) ref = {};
|
|
12
|
-
var insertAt = ref.insertAt;
|
|
13
|
-
if (typeof document === 'undefined') {
|
|
14
|
-
return;
|
|
15
|
-
}
|
|
16
|
-
var head = document.head || document.getElementsByTagName('head')[0];
|
|
17
|
-
var style = document.createElement('style');
|
|
18
|
-
style.type = 'text/css';
|
|
19
|
-
if (insertAt === 'top') {
|
|
20
|
-
if (head.firstChild) {
|
|
21
|
-
head.insertBefore(style, head.firstChild);
|
|
22
|
-
} else {
|
|
23
|
-
head.appendChild(style);
|
|
24
|
-
}
|
|
25
|
-
} else {
|
|
26
|
-
head.appendChild(style);
|
|
27
|
-
}
|
|
28
|
-
if (style.styleSheet) {
|
|
29
|
-
style.styleSheet.cssText = css;
|
|
30
|
-
} else {
|
|
31
|
-
style.appendChild(document.createTextNode(css));
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
var css_248z = ".component-module__container___VbZSk{display:flex;height:100%;width:100%}.component-module__text___nFUOn{display:inline-block;word-break:break-word}.component-module__link___20asF{cursor:pointer;text-decoration:none;transition:opacity .2s ease}.component-module__link___20asF:hover{opacity:.8}.component-module__underline___0oAJz{text-decoration:underline}.component-module__alignLeft___IOvpO{justify-content:flex-start;text-align:left}.component-module__alignCenter___EIwIC{justify-content:center;text-align:center}.component-module__alignRight___p3ReL{justify-content:flex-end;text-align:right}.component-module__valignTop___-5DmK{align-items:flex-start}.component-module__valignMiddle___i0are{align-items:center}.component-module__valignBottom___97zzw{align-items:flex-end}";
|
|
36
|
-
var styles = {"container":"component-module__container___VbZSk","text":"component-module__text___nFUOn","link":"component-module__link___20asF","underline":"component-module__underline___0oAJz","alignLeft":"component-module__alignLeft___IOvpO","alignCenter":"component-module__alignCenter___EIwIC","alignRight":"component-module__alignRight___p3ReL","valignTop":"component-module__valignTop___-5DmK","valignMiddle":"component-module__valignMiddle___i0are","valignBottom":"component-module__valignBottom___97zzw"};
|
|
37
|
-
styleInject(css_248z);
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Text Component
|
|
41
|
-
* 文本组件 - 支持普通文本、链接、标题、发光效果
|
|
42
|
-
*/
|
|
43
|
-
|
|
44
|
-
const getAlignClass = align => {
|
|
45
|
-
switch (align) {
|
|
46
|
-
case 'left':
|
|
47
|
-
return styles.alignLeft;
|
|
48
|
-
case 'center':
|
|
49
|
-
return styles.alignCenter;
|
|
50
|
-
case 'right':
|
|
51
|
-
return styles.alignRight;
|
|
52
|
-
default:
|
|
53
|
-
return styles.alignLeft;
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
const getValignClass = align => {
|
|
57
|
-
switch (align) {
|
|
58
|
-
case 'top':
|
|
59
|
-
return styles.valignTop;
|
|
60
|
-
case 'middle':
|
|
61
|
-
return styles.valignMiddle;
|
|
62
|
-
case 'bottom':
|
|
63
|
-
return styles.valignBottom;
|
|
64
|
-
default:
|
|
65
|
-
return styles.valignMiddle;
|
|
66
|
-
}
|
|
67
|
-
};
|
|
68
|
-
const Text = ({
|
|
69
|
-
ref,
|
|
70
|
-
content = '文本内容',
|
|
71
|
-
fontSize = 16,
|
|
72
|
-
fontWeight = 'normal',
|
|
73
|
-
fontFamily = 'inherit',
|
|
74
|
-
color = '#ffffff',
|
|
75
|
-
textAlign = 'left',
|
|
76
|
-
verticalAlign = 'middle',
|
|
77
|
-
lineHeight = 1.5,
|
|
78
|
-
letterSpacing = 0,
|
|
79
|
-
isLink = false,
|
|
80
|
-
href = '',
|
|
81
|
-
target = '_blank',
|
|
82
|
-
underline = false,
|
|
83
|
-
glowEnable = false,
|
|
84
|
-
glowColor = '#00d4ff',
|
|
85
|
-
glowIntensity = 1,
|
|
86
|
-
style: externalStyle
|
|
87
|
-
}) => {
|
|
88
|
-
// 计算发光效果
|
|
89
|
-
const textShadow = glowEnable ? `0 0 ${10 * glowIntensity}px ${glowColor}, 0 0 ${20 * glowIntensity}px ${glowColor}, 0 0 ${30 * glowIntensity}px ${glowColor}` : undefined;
|
|
90
|
-
const textStyle = {
|
|
91
|
-
fontSize,
|
|
92
|
-
fontWeight,
|
|
93
|
-
fontFamily,
|
|
94
|
-
color,
|
|
95
|
-
lineHeight,
|
|
96
|
-
letterSpacing,
|
|
97
|
-
textShadow
|
|
98
|
-
};
|
|
99
|
-
const containerClass = cn(styles.container, getAlignClass(textAlign), getValignClass(verticalAlign));
|
|
100
|
-
const textClass = cn(styles.text, isLink && styles.link, underline && styles.underline);
|
|
101
|
-
|
|
102
|
-
// 链接模式
|
|
103
|
-
if (isLink && href) {
|
|
104
|
-
const relValue = target === '_blank' ? 'noopener noreferrer' : '';
|
|
105
|
-
return /*#__PURE__*/jsx("div", {
|
|
106
|
-
className: containerClass,
|
|
107
|
-
ref: ref,
|
|
108
|
-
style: externalStyle,
|
|
109
|
-
children: /*#__PURE__*/jsx("a", {
|
|
110
|
-
className: textClass,
|
|
111
|
-
href: href,
|
|
112
|
-
rel: relValue,
|
|
113
|
-
style: textStyle,
|
|
114
|
-
target: target,
|
|
115
|
-
children: content
|
|
116
|
-
})
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
// 普通文本
|
|
121
|
-
return /*#__PURE__*/jsx("div", {
|
|
122
|
-
className: containerClass,
|
|
123
|
-
ref: ref,
|
|
124
|
-
style: externalStyle,
|
|
125
|
-
children: /*#__PURE__*/jsxs("span", {
|
|
126
|
-
className: textClass,
|
|
127
|
-
style: textStyle,
|
|
128
|
-
children: [content, " \u65B0\u7248\u672C!"]
|
|
129
|
-
})
|
|
130
|
-
});
|
|
131
|
-
};
|
|
132
|
-
|
|
133
|
-
export { Text, Text as default };
|
|
134
|
-
//# sourceMappingURL=component.esm.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"component.esm.js","sources":["../../../../../node_modules/.pnpm/clsx@2.1.1/node_modules/clsx/dist/clsx.mjs","../../../../shared/src/lib/utils.ts","../../../../../node_modules/.pnpm/style-inject@0.3.0/node_modules/style-inject/dist/style-inject.es.js","../src/component.tsx"],"sourcesContent":["function r(e){var t,f,n=\"\";if(\"string\"==typeof e||\"number\"==typeof e)n+=e;else if(\"object\"==typeof e)if(Array.isArray(e)){var o=e.length;for(t=0;t<o;t++)e[t]&&(f=r(e[t]))&&(n&&(n+=\" \"),n+=f)}else for(f in e)e[f]&&(n&&(n+=\" \"),n+=f);return n}export function clsx(){for(var e,t,f=0,n=\"\",o=arguments.length;f<o;f++)(e=arguments[f])&&(t=r(e))&&(n&&(n+=\" \"),n+=t);return n}export default clsx;","import { clsx, type ClassValue } from 'clsx'\n\nexport function cn(...inputs: ClassValue[]) {\n return clsx(inputs)\n}\n","function styleInject(css, ref) {\n if ( ref === void 0 ) ref = {};\n var insertAt = ref.insertAt;\n\n if (!css || typeof document === 'undefined') { return; }\n\n var head = document.head || document.getElementsByTagName('head')[0];\n var style = document.createElement('style');\n style.type = 'text/css';\n\n if (insertAt === 'top') {\n if (head.firstChild) {\n head.insertBefore(style, head.firstChild);\n } else {\n head.appendChild(style);\n }\n } else {\n head.appendChild(style);\n }\n\n if (style.styleSheet) {\n style.styleSheet.cssText = css;\n } else {\n style.appendChild(document.createTextNode(css));\n }\n}\n\nexport default styleInject;\n","/**\n * Text Component\n * 文本组件 - 支持普通文本、链接、标题、发光效果\n */\n\nimport type { CSSProperties, Ref } from 'react'\nimport { cn } from '@easy-editor/materials-shared'\nimport styles from './component.module.css'\n\nexport type TextAlign = 'left' | 'center' | 'right'\nexport type VerticalAlign = 'top' | 'middle' | 'bottom'\n\nexport interface TextProps {\n ref?: Ref<HTMLDivElement>\n /** 文本内容 */\n content?: string\n /** 字体大小 */\n fontSize?: number\n /** 字体粗细 */\n fontWeight?: number | 'normal' | 'bold'\n /** 字体家族 */\n fontFamily?: string\n /** 颜色 */\n color?: string\n /** 水平对齐 */\n textAlign?: TextAlign\n /** 垂直对齐 */\n verticalAlign?: VerticalAlign\n /** 行高 */\n lineHeight?: number\n /** 字间距 */\n letterSpacing?: number\n /** 是否为链接 */\n isLink?: boolean\n /** 链接地址 */\n href?: string\n /** 链接打开方式 */\n target?: '_self' | '_blank'\n /** 下划线 */\n underline?: boolean\n /** 发光效果 */\n glowEnable?: boolean\n /** 发光颜色 */\n glowColor?: string\n /** 发光强度 */\n glowIntensity?: number\n /** 显隐控制 */\n condition?: boolean\n /** 外部样式 */\n style?: CSSProperties\n}\n\nconst getAlignClass = (align: TextAlign): string => {\n switch (align) {\n case 'left':\n return styles.alignLeft\n case 'center':\n return styles.alignCenter\n case 'right':\n return styles.alignRight\n default:\n return styles.alignLeft\n }\n}\n\nconst getValignClass = (align: VerticalAlign): string => {\n switch (align) {\n case 'top':\n return styles.valignTop\n case 'middle':\n return styles.valignMiddle\n case 'bottom':\n return styles.valignBottom\n default:\n return styles.valignMiddle\n }\n}\n\nexport const Text: React.FC<TextProps> = ({\n ref,\n content = '文本内容',\n fontSize = 16,\n fontWeight = 'normal',\n fontFamily = 'inherit',\n color = '#ffffff',\n textAlign = 'left',\n verticalAlign = 'middle',\n lineHeight = 1.5,\n letterSpacing = 0,\n isLink = false,\n href = '',\n target = '_blank',\n underline = false,\n glowEnable = false,\n glowColor = '#00d4ff',\n glowIntensity = 1,\n style: externalStyle,\n}) => {\n // 计算发光效果\n const textShadow = glowEnable\n ? `0 0 ${10 * glowIntensity}px ${glowColor}, 0 0 ${20 * glowIntensity}px ${glowColor}, 0 0 ${30 * glowIntensity}px ${glowColor}`\n : undefined\n\n const textStyle: CSSProperties = {\n fontSize,\n fontWeight,\n fontFamily,\n color,\n lineHeight,\n letterSpacing,\n textShadow,\n }\n\n const containerClass = cn(styles.container, getAlignClass(textAlign), getValignClass(verticalAlign))\n\n const textClass = cn(styles.text, isLink && styles.link, underline && styles.underline)\n\n // 链接模式\n if (isLink && href) {\n const relValue = target === '_blank' ? 'noopener noreferrer' : ''\n return (\n <div className={containerClass} ref={ref} style={externalStyle}>\n <a className={textClass} href={href} rel={relValue} style={textStyle} target={target}>\n {content}\n </a>\n </div>\n )\n }\n\n // 普通文本\n return (\n <div className={containerClass} ref={ref} style={externalStyle}>\n <span className={textClass} style={textStyle}>\n {content} 新版本!\n </span>\n </div>\n )\n}\n\nexport default Text\n"],"names":["cn","inputs","clsx","styleInject","css","ref","insertAt","document","head","getElementsByTagName","style","createElement","type","firstChild","insertBefore","appendChild","styleSheet","cssText","createTextNode","getAlignClass","align","styles","alignLeft","alignCenter","alignRight","getValignClass","valignTop","valignMiddle","valignBottom","Text","content","fontSize","fontWeight","fontFamily","color","textAlign","verticalAlign","lineHeight","letterSpacing","isLink","href","target","underline","glowEnable","glowColor","glowIntensity","externalStyle","textShadow","undefined","textStyle","containerClass","container","textClass","text","link","relValue","_jsx","className","children","rel","_jsxs"],"mappings":";;;AAAA,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,QAAQ,EAAE,OAAO,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,KAAK,GAAG,QAAQ,EAAE,OAAO,CAAC,CAAC,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,EAAC,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,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