lark-docs-variables 1.0.0
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/.vscode/launch.json +18 -0
- package/.vscode/settings.json +42 -0
- package/README.md +1 -0
- package/app.json +19 -0
- package/components.json +38 -0
- package/eslint.config.js +123 -0
- package/package.json +55 -0
- package/src/components/Box.tsx +10 -0
- package/src/components/Icon.module.css +3 -0
- package/src/components/Icon.tsx +26 -0
- package/src/components/ValueToggle.module.css +4 -0
- package/src/components/ValueToggle.tsx +25 -0
- package/src/components/base/Button.tsx +46 -0
- package/src/components/base/Card.tsx +74 -0
- package/src/components/base/Combobox.tsx +217 -0
- package/src/components/base/Input.tsx +17 -0
- package/src/components/base/InputGroup.tsx +123 -0
- package/src/components/base/Textarea.tsx +15 -0
- package/src/components/base/Toggle.tsx +24 -0
- package/src/entries/Panel.module.css +33 -0
- package/src/entries/Panel.tsx +67 -0
- package/src/entries/Settings.css +3 -0
- package/src/entries/Settings.module.css +4 -0
- package/src/entries/Settings.tsx +14 -0
- package/src/globals.d.ts +1 -0
- package/src/hooks/useBlockHover.ts +20 -0
- package/src/hooks/useDebounce.ts +16 -0
- package/src/hooks/useDocument.ts +8 -0
- package/src/hooks/useIsMounted.ts +15 -0
- package/src/hooks/useRecord.ts +33 -0
- package/src/hooks/useResizeObserver.ts +90 -0
- package/src/hooks/useSelection.ts +16 -0
- package/src/hooks/useTimeoutFn.ts +40 -0
- package/src/index.css +125 -0
- package/src/lib/utils.ts +6 -0
- package/src/panel.html +11 -0
- package/src/panel.tsx +14 -0
- package/src/providers/BlockProvider.context.ts +10 -0
- package/src/providers/BlockProvider.tsx +30 -0
- package/src/public/icon.png +0 -0
- package/src/settings.html +11 -0
- package/src/settings.tsx +14 -0
- package/src/util/app.ts +3 -0
- package/src/util/box.ts +27 -0
- package/tsconfig.app.json +35 -0
- package/tsconfig.json +13 -0
- package/tsconfig.node.json +26 -0
- package/vite/plugin.ts +131 -0
- package/vite.config.ts +55 -0
package/vite/plugin.ts
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
2
|
+
import opapi$1 from '@lark-opdev/cli/libs/api'
|
|
3
|
+
import { readFileSync } from 'fs'
|
|
4
|
+
import open from 'open'
|
|
5
|
+
import { basename } from 'path'
|
|
6
|
+
import colors from 'picocolors'
|
|
7
|
+
import qs from 'query-string'
|
|
8
|
+
import { Plugin } from 'vite'
|
|
9
|
+
|
|
10
|
+
const opapi = (opapi$1 as any).default as typeof opapi$1
|
|
11
|
+
|
|
12
|
+
export interface AppMeta {
|
|
13
|
+
appID: string
|
|
14
|
+
blockTypeID: string
|
|
15
|
+
appName: Record<string, string>
|
|
16
|
+
name: Record<string, string>
|
|
17
|
+
icon: string
|
|
18
|
+
filledIcon: string
|
|
19
|
+
outlinedIcon: string
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export interface AppConfig {
|
|
23
|
+
manifestVersion: 1
|
|
24
|
+
appID: string
|
|
25
|
+
appType: 'docs-addon'
|
|
26
|
+
blockTypeID: string
|
|
27
|
+
projectName: string
|
|
28
|
+
url: string
|
|
29
|
+
contributes?: {
|
|
30
|
+
addPanel?: { initialHeight: number; view: string }
|
|
31
|
+
modal?: { initialHeight: number; view: string }
|
|
32
|
+
popup?: { initialHeight: number; view: string }
|
|
33
|
+
}
|
|
34
|
+
meta: Partial<AppMeta>
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const getAppConfig = (): AppConfig => JSON.parse(readFileSync('app.json', 'utf-8'))
|
|
38
|
+
|
|
39
|
+
const getProjectConfig = (config: AppConfig) => {
|
|
40
|
+
const blocks: string[] = []
|
|
41
|
+
if (config.contributes?.addPanel) { blocks.push(basename(config.contributes.addPanel.view, '.html')) }
|
|
42
|
+
if (config.contributes?.modal) { blocks.push(basename(config.contributes.modal.view, '.html')) }
|
|
43
|
+
if (config.contributes?.popup) { blocks.push(basename(config.contributes.popup.view, '.html')) }
|
|
44
|
+
return { appid: config.appID, projectname: config.projectName, blocks }
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const getBlockConfig = (config: AppConfig) => ({
|
|
48
|
+
blockTypeID: config.blockTypeID,
|
|
49
|
+
blockRenderType: 'offlineWeb' as const,
|
|
50
|
+
offlineWebConfig: {
|
|
51
|
+
initialHeight: config.contributes?.addPanel?.initialHeight,
|
|
52
|
+
contributes: config.contributes
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
const getBlockConfigMap = (config: AppConfig) => ({
|
|
57
|
+
[config.blockTypeID]: getBlockConfig(config)
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
const getMiddlewareConfig = (config: AppConfig, devServerHost: string) => ({
|
|
61
|
+
projectConfig: getProjectConfig(config),
|
|
62
|
+
blockConfigMap: getBlockConfigMap(config),
|
|
63
|
+
devServerHost,
|
|
64
|
+
basePath: '/'
|
|
65
|
+
})
|
|
66
|
+
|
|
67
|
+
function docVerseVitePlugin(options: { open?: boolean; url?: string } = {}): Plugin {
|
|
68
|
+
const config = getAppConfig()
|
|
69
|
+
const shouldOpen = typeof options.open !== 'undefined' ? Boolean(options.open) : true
|
|
70
|
+
const url = options.url ?? config.url
|
|
71
|
+
return {
|
|
72
|
+
name: 'docverse-debug-url',
|
|
73
|
+
async configureServer(server) {
|
|
74
|
+
const port = server.config.server.port ?? 8080
|
|
75
|
+
if (process.env.NODE_ENV === 'development') {
|
|
76
|
+
const api = await opapi.init()
|
|
77
|
+
const devServerHost = `http://localhost:${port}`
|
|
78
|
+
const middleware = await api.dev.getBlockitDevMiddleware(getMiddlewareConfig(config, devServerHost))
|
|
79
|
+
server.middlewares.use((req, res, next) => {
|
|
80
|
+
res.setHeader('Access-Control-Allow-Origin', new URL(url).origin)
|
|
81
|
+
res.setHeader('Access-Control-Allow-Methods', '*')
|
|
82
|
+
res.setHeader('Access-Control-Allow-Headers', 'x-request-id')
|
|
83
|
+
res.setHeader('Access-Control-Allow-Credentials', 'true')
|
|
84
|
+
if (!req.url) { return next() }
|
|
85
|
+
const uri = new URL(req.url, devServerHost)
|
|
86
|
+
if (uri.pathname.startsWith('/api')) {
|
|
87
|
+
middleware({ url: req.url }, {
|
|
88
|
+
send: (content: any) => {
|
|
89
|
+
if (!content) { return next() }
|
|
90
|
+
if (uri.pathname === '/api/block' && config.meta) {
|
|
91
|
+
Object.assign(content.data.blocks[0], config.meta)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (uri.pathname === '/api/meta' && config.meta) {
|
|
95
|
+
Object.assign(content.data.app_metas[0].app_base_info, { filledIcon: config.meta.icon })
|
|
96
|
+
}
|
|
97
|
+
res.setHeader('Content-Type', 'application/json')
|
|
98
|
+
res.end(Buffer.from(JSON.stringify(content, null, 2)))
|
|
99
|
+
}
|
|
100
|
+
}, next)
|
|
101
|
+
} else {
|
|
102
|
+
return next()
|
|
103
|
+
}
|
|
104
|
+
})
|
|
105
|
+
server.httpServer?.once('listening', () => {
|
|
106
|
+
setTimeout(() => {
|
|
107
|
+
const documentUrl = qs.stringifyUrl({ url, query: { blockitdebug: true, debugport: port } })
|
|
108
|
+
console.info(` ${colors.green('➜')} ${colors.bold('DocVerse')}: ${documentUrl}`)
|
|
109
|
+
if (shouldOpen) { open(documentUrl) }
|
|
110
|
+
}, 0)
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
},
|
|
114
|
+
async generateBundle(this: any) {
|
|
115
|
+
if (process.env.NODE_ENV === 'production') {
|
|
116
|
+
this.emitFile({
|
|
117
|
+
type: 'asset',
|
|
118
|
+
fileName: 'project.config.json',
|
|
119
|
+
source: JSON.stringify(getProjectConfig(config), null, 2)
|
|
120
|
+
})
|
|
121
|
+
this.emitFile({
|
|
122
|
+
type: 'asset',
|
|
123
|
+
fileName: 'index.json',
|
|
124
|
+
source: JSON.stringify(getBlockConfig(config), null, 2)
|
|
125
|
+
})
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
export { docVerseVitePlugin }
|
package/vite.config.ts
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
|
|
2
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
3
|
+
import react from '@vitejs/plugin-react'
|
|
4
|
+
import path, { basename } from "path"
|
|
5
|
+
import { defineConfig } from 'vite'
|
|
6
|
+
import { docVerseVitePlugin } from './vite/plugin'
|
|
7
|
+
|
|
8
|
+
export default defineConfig({
|
|
9
|
+
root: 'src',
|
|
10
|
+
base: '',
|
|
11
|
+
server: { cors: false },
|
|
12
|
+
plugins: [
|
|
13
|
+
react(),
|
|
14
|
+
tailwindcss(),
|
|
15
|
+
docVerseVitePlugin({
|
|
16
|
+
url: 'https://atomicbi.sg.larksuite.com/wiki/Bi6Uw0I7jiWPt1kQU3ZlxivwgGg',
|
|
17
|
+
open: true
|
|
18
|
+
})
|
|
19
|
+
],
|
|
20
|
+
build: {
|
|
21
|
+
outDir: 'dist',
|
|
22
|
+
emptyOutDir: true,
|
|
23
|
+
assetsDir: '.',
|
|
24
|
+
cssCodeSplit: false,
|
|
25
|
+
rollupOptions: {
|
|
26
|
+
input: {
|
|
27
|
+
panel: 'src/panel.html',
|
|
28
|
+
settings: 'src/settings.html'
|
|
29
|
+
},
|
|
30
|
+
output: {
|
|
31
|
+
dir: 'dist',
|
|
32
|
+
entryFileNames: '[name].js',
|
|
33
|
+
assetFileNames: '[name].[ext]',
|
|
34
|
+
chunkFileNames: '[name].js',
|
|
35
|
+
manualChunks(id, meta) {
|
|
36
|
+
const name = id.split('/').at(-1)?.replace(/\?.*$/, '')
|
|
37
|
+
if (!name) { return null }
|
|
38
|
+
const info = meta.getModuleInfo(id)
|
|
39
|
+
if (info?.isEntry) {
|
|
40
|
+
return basename(name, '.html')
|
|
41
|
+
} else if (['panel.tsx', 'settings.tsx'].includes(name)) {
|
|
42
|
+
return basename(name, '.tsx')
|
|
43
|
+
}
|
|
44
|
+
return 'bundle'
|
|
45
|
+
},
|
|
46
|
+
sanitizeFileName: (name) => name === 'style.css' ? 'bundle.css' : name
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
},
|
|
50
|
+
resolve: {
|
|
51
|
+
alias: {
|
|
52
|
+
"@": path.resolve(__dirname, "./src")
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
})
|