@lark-apaas/client-toolkit-lite 0.0.1

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/LICENSE ADDED
@@ -0,0 +1,13 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Lark Technologies Pte. Ltd. and/or its affiliates
4
+
5
+ Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted,provided that the above copyright notice and this permission notice appear in all copies.
6
+
7
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
8
+ IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE
9
+ INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO
10
+ EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
11
+ CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
12
+ DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
13
+ ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,236 @@
1
+ # @lark-apaas/client-toolkit-lite
2
+
3
+ 轻量版客户端工具包,面向 Express/Vite 技术栈。从 `@lark-apaas/client-toolkit` 精简而来,保留核心能力(AppContainer、hooks、工具函数、路由组件、DataLoom),去掉重量级依赖(antd、Observable、Auth SDK、Slardar、Sonner 等)。
4
+
5
+ ## 安装
6
+
7
+ ```bash
8
+ npm install @lark-apaas/client-toolkit-lite
9
+ ```
10
+
11
+ ### Peer Dependencies
12
+
13
+ ```bash
14
+ npm install react react-dom react-router-dom @tanstack/react-query
15
+ ```
16
+
17
+ ## 快速接入
18
+
19
+ ### 1. 引入主题样式
20
+
21
+ 在项目入口文件(如 `main.tsx`)中引入全局样式:
22
+
23
+ ```tsx
24
+ // main.tsx
25
+ import '@lark-apaas/client-toolkit-lite/styles';
26
+ import { createRoot } from 'react-dom/client';
27
+ import App from './App';
28
+
29
+ createRoot(document.getElementById('root')!).render(<App />);
30
+ ```
31
+
32
+ 样式包含:
33
+ - **theme-layer.css** — Tailwind CSS 层声明(由消费端 Vite + PostCSS 处理)
34
+ - **tailwind-theme.css** — 设计系统 CSS 变量(颜色体系)
35
+ - **override.css** — 全局基础样式(border-color、background、container)
36
+ - **font-family.css** — 字体定义
37
+
38
+ ### 2. 使用 AppContainer
39
+
40
+ `AppContainer` 是应用根容器,内部集成:
41
+ - **Safety** — 生产环境「妙搭构建」安全标识
42
+ - **QueryProvider** — React Query 数据管理
43
+ - **useAppInfo** — 自动同步 document title / favicon / OG meta
44
+ - **Runtime** — React DevTools Hook + Axios CSRF 全局注入(防重复)
45
+
46
+ ```tsx
47
+ // App.tsx
48
+ import { AppContainer } from '@lark-apaas/client-toolkit-lite';
49
+ import { BrowserRouter, Routes, Route } from 'react-router-dom';
50
+
51
+ function App() {
52
+ return (
53
+ <BrowserRouter>
54
+ <AppContainer>
55
+ <Routes>
56
+ <Route path="/" element={<Home />} />
57
+ <Route path="/about" element={<About />} />
58
+ </Routes>
59
+ </AppContainer>
60
+ </BrowserRouter>
61
+ );
62
+ }
63
+ ```
64
+
65
+ 也可以单独使用 `QueryProvider`(不需要 AppContainer 的其他功能时):
66
+
67
+ ```tsx
68
+ import { QueryProvider } from '@lark-apaas/client-toolkit-lite';
69
+
70
+ <QueryProvider>{children}</QueryProvider>
71
+ ```
72
+
73
+ ### 3. Hooks
74
+
75
+ #### useAppInfo
76
+
77
+ 获取应用元数据,自动同步到 document title / favicon / OG meta:
78
+
79
+ ```tsx
80
+ import { useAppInfo } from '@lark-apaas/client-toolkit-lite';
81
+
82
+ const { appName, appLogo, description } = useAppInfo();
83
+ ```
84
+
85
+ #### useCurrentUserProfile
86
+
87
+ 获取当前登录用户信息(通过 DataLoom 拉取):
88
+
89
+ ```tsx
90
+ import { useCurrentUserProfile } from '@lark-apaas/client-toolkit-lite';
91
+
92
+ const { user_id, name, email, avatar } = useCurrentUserProfile();
93
+ ```
94
+
95
+ #### useIsMobile
96
+
97
+ 响应式移动端检测(768px 断点):
98
+
99
+ ```tsx
100
+ import { useIsMobile } from '@lark-apaas/client-toolkit-lite';
101
+
102
+ const isMobile = useIsMobile();
103
+ ```
104
+
105
+ #### useLogout
106
+
107
+ 退出登录(通过 DataLoom session.signOut):
108
+
109
+ ```tsx
110
+ import { useLogout } from '@lark-apaas/client-toolkit-lite';
111
+
112
+ const { handlerLogout, isLoading } = useLogout();
113
+ ```
114
+
115
+ ### 4. 路由组件
116
+
117
+ 依赖 `react-router-dom`:
118
+
119
+ ```tsx
120
+ import { ActiveLink, NavLink, UniversalLink } from '@lark-apaas/client-toolkit-lite';
121
+
122
+ // 支持 hash 定位的 NavLink,自动 active 检测
123
+ <ActiveLink to="/page#section">Section</ActiveLink>
124
+
125
+ // 增强版 NavLink,支持 hash + 滚动到顶部
126
+ <NavLink to="/about">About</NavLink>
127
+
128
+ // 统一链接:内部路由用 Link,外部 URL 用 a 标签(自动识别)
129
+ <UniversalLink to="https://example.com">External</UniversalLink>
130
+ <UniversalLink to="/internal">Internal</UniversalLink>
131
+ ```
132
+
133
+ ### 5. 工具函数
134
+
135
+ ```tsx
136
+ import {
137
+ // 平台相关
138
+ getAppId, // 获取应用 ID(from window.appId)
139
+ getCsrfToken, // 从 cookie 提取 CSRF token
140
+ getEnvPath, // 预览/运行态路径
141
+ resolveAppUrl, // 解析应用相对路径,自动加 CLIENT_BASE_PATH
142
+
143
+ // HTTP
144
+ getAxiosForBackend, // 获取后端 axios 实例(带登录重定向拦截)
145
+ axiosForBackend, // 同上,预创建的单例
146
+ initAxiosConfig, // 初始化 axios 拦截器(CSRF token 注入)
147
+
148
+ // 存储
149
+ scopedStorage, // 应用隔离的 localStorage(key 加 appId 前缀)
150
+
151
+ // 样式
152
+ clsxWithTw, // Tailwind class 合并(clsx + twMerge)
153
+
154
+ // 工具
155
+ copyToClipboard, // 复制到剪贴板
156
+ safeStringify, // 安全 JSON 序列化(处理循环引用/BigInt)
157
+ isPreview, // 是否预览模式
158
+ normalizeBasePath, // 路径标准化(去尾部斜杠)
159
+ getWsPath, // WebSocket 路径
160
+
161
+ // 设备检测
162
+ isIpad, isMobile, isIOS,
163
+ } from '@lark-apaas/client-toolkit-lite';
164
+ ```
165
+
166
+ ### 6. 数据集成
167
+
168
+ ```tsx
169
+ import { getAppInfo, getCurrentUserProfile, getDataloom } from '@lark-apaas/client-toolkit-lite';
170
+
171
+ // 获取应用元数据(缓存在 window._appInfo)
172
+ const appInfo = await getAppInfo();
173
+
174
+ // 获取当前用户(from window._userInfo)
175
+ const userProfile = getCurrentUserProfile();
176
+
177
+ // 获取 DataLoom 客户端(单例,懒初始化)
178
+ const dataloom = await getDataloom();
179
+ const users = await dataloom.service.user.search({ name: '张三' });
180
+ ```
181
+
182
+ ### 7. 图片资源
183
+
184
+ ```tsx
185
+ import { avatarImages, bannerImages, coverImages } from '@lark-apaas/client-toolkit-lite';
186
+
187
+ // avatarImages.avatarImg1 ~ avatarImg11(11 张默认头像 CDN URL)
188
+ // bannerImages(24 张横幅,科技/专业/极简分类)
189
+ // coverImages(36 张封面,办公/建筑/风景/科技/3D 等分类)
190
+ ```
191
+
192
+ ### 8. 类型导出
193
+
194
+ ```tsx
195
+ import type {
196
+ AppInfoPayload, // { name, avatar, description }
197
+ IUserProfile, // { user_id, email, name, avatar, status }
198
+ IJson, // Record<string, unknown>
199
+ IFileAttachment, // { bucket_id, file_path }
200
+ } from '@lark-apaas/client-toolkit-lite';
201
+ ```
202
+
203
+ ## 完整导出清单
204
+
205
+ | 分类 | 导出 |
206
+ |------|------|
207
+ | Components | AppContainer, QueryProvider |
208
+ | Route Components | ActiveLink, NavLink, UniversalLink |
209
+ | Hooks | useAppInfo, useCurrentUserProfile, useIsMobile, useLogout |
210
+ | Utils | clsxWithTw, isPreview, normalizeBasePath, getWsPath, getAppId, getCsrfToken, scopedStorage, copyToClipboard, isIpad, isMobile, isIOS, resolveAppUrl, getEnvPath, safeStringify, getAxiosForBackend, axiosForBackend, initAxiosConfig |
211
+ | Integrations | getAppInfo, getCurrentUserProfile, getDataloom |
212
+ | Types | AppInfoPayload, IUserProfile, IJson, IFileAttachment |
213
+ | Constants | avatarImages, bannerImages, coverImages |
214
+
215
+ ## 与 client-toolkit 的区别
216
+
217
+ | 能力 | client-toolkit | lite |
218
+ |------|:-:|:-:|
219
+ | AppContainer(完整版) | ✅ | 精简版 |
220
+ | antd ConfigProvider | ✅ | ❌ |
221
+ | AuthProvider / CanRole | ✅ | ❌ |
222
+ | Observable / Slardar | ✅ | ❌ |
223
+ | Sonner toast | ✅ | ❌ |
224
+ | Logger(批量上报) | ✅ | ❌ |
225
+ | MiaodaInspector | ✅ | ❌ |
226
+ | UI 基础组件 | ✅ | ❌ |
227
+ | User 组件 | ✅ | ❌ |
228
+ | Runtime(完整版) | ✅ | 精简版 |
229
+ | DataLoom | ✅ | ✅ |
230
+ | Hooks | 6 个 | 4 个 |
231
+ | 路由组件 | ✅ | ✅ |
232
+ | 工具函数 | ✅ | ✅ |
233
+
234
+ ## License
235
+
236
+ MIT
@@ -0,0 +1,39 @@
1
+ @font-face {
2
+ font-family: LarkChineseQuote;
3
+ font-weight: 300;
4
+ src: local("PingFangSC-Light");
5
+ unicode-range: U+2018, U+2019, U+201A, U+201C, U+201D, U+201E;
6
+ }
7
+
8
+ @font-face {
9
+ font-family: LarkChineseQuote;
10
+ font-weight: 400;
11
+ src: local("PingFangSC-Regular");
12
+ unicode-range: U+2018, U+2019, U+201A, U+201C, U+201D, U+201E;
13
+ }
14
+
15
+ @font-face {
16
+ font-family: LarkChineseQuote;
17
+ font-weight: 500;
18
+ src: local("PingFangSC-Medium");
19
+ unicode-range: U+2018, U+2019, U+201A, U+201C, U+201D, U+201E;
20
+ }
21
+
22
+ @font-face {
23
+ font-family: LarkChineseQuote;
24
+ font-weight: 600;
25
+ src: local("PingFangSC-Semibold");
26
+ unicode-range: U+2018, U+2019, U+201A, U+201C, U+201D, U+201E;
27
+ }
28
+
29
+ @font-face {
30
+ font-family: LarkEmojiFont;
31
+ src: local("Apple Color Emoji"), local("Noto Color Emoji");
32
+ unicode-range: U+1F21A, U+1F250, U+1F237, U+26A0;
33
+ }
34
+
35
+ @font-face {
36
+ font-family: LarkHackSafariFont;
37
+ src: local("Helvetica Neue");
38
+ unicode-range: U+0000;
39
+ }
@@ -0,0 +1,2 @@
1
+ @import './override.css';
2
+ @import './font-family.css';
@@ -0,0 +1,18 @@
1
+ @layer base {
2
+ * {
3
+ border-color: var(--border);
4
+ outline-color: var(--ring);
5
+ @supports (color: color-mix(in lab, red, red)) {
6
+ outline-color: color-mix(in oklab, var(--ring) 50%, transparent);
7
+ }
8
+ }
9
+ body {
10
+ background-color: var(--background);
11
+ color: var(--foreground);
12
+ }
13
+
14
+ .container {
15
+ margin-left: auto;
16
+ margin-right: auto;
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ @layer base {
2
+ :root {
3
+ --color-blue-500: #5083fb;
4
+ --color-blue-600: #336df4;
5
+ --color-neutral-00: #ffffff;
6
+ --color-neutral-300: #dee0e3;
7
+ --color-neutral-500: #bbbfc4;
8
+ --color-neutral-600: #8f959e;
9
+ --color-neutral-700: #646a73;
10
+ --color-neutral-950: #1f2329;
11
+ --color-green-500: #32a645;
12
+ --color-red-500: #f54a45;
13
+ --color-orange-400: #ff811a;
14
+ --fontReverse: #fff;
15
+ --bgContentBase: #f8f9fa;
16
+ --lineDividerDefault: 31, 35, 41, 0.15;
17
+ }
18
+ }
@@ -0,0 +1,3 @@
1
+ @layer theme, base, components, utilities;
2
+ @import 'tailwindcss' source(none);
3
+ @source "../**/*.{js,jsx,ts,tsx}";