Skip to content

Commit 126c9da

Browse files
authored
types: add types to usePage and useMaterial (#1263)
1 parent 00926c0 commit 126c9da

3 files changed

Lines changed: 481 additions & 105 deletions

File tree

Lines changed: 338 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,338 @@
1+
export interface Material {
2+
components: Component[]
3+
snippets?: Snippet[]
4+
blocks?: Block[]
5+
packages?: Package[]
6+
}
7+
8+
export interface Block {
9+
id: number | string
10+
label: string
11+
framework: string
12+
content: BlockResource
13+
created_by?: unknown
14+
updated_by?: unknown
15+
created_at: Date
16+
updated_at: Date
17+
assets: Assets
18+
createdBy: CreatedBy
19+
updatedBy: number
20+
last_build_info: BuildInfo
21+
description?: unknown
22+
tags: any[]
23+
current_history: number
24+
screenshot: string
25+
path: string
26+
occupier?: CreatedBy
27+
isOfficial?: boolean
28+
public: number
29+
isDefault?: boolean
30+
tiny_reserved?: boolean
31+
author?: unknown
32+
name_cn?: string
33+
npm_name: string
34+
created_app?: unknown
35+
content_blocks?: unknown
36+
histories: History[]
37+
categories: any[]
38+
public_scope_tenants: any[]
39+
histories_length: number
40+
state?: unknown
41+
}
42+
43+
export interface Assets {
44+
material: string[]
45+
scripts: string[]
46+
styles: string[]
47+
}
48+
49+
export type Resource = Omit<Component, 'component'> & { type: string; component?: string; item?: string }
50+
51+
export interface BlockResource {
52+
componentName: string
53+
fileName: string
54+
css?: string
55+
props: Record<string, any>
56+
dataSource?: Record<string, any>
57+
schema: Schema
58+
children: Schema[]
59+
state?: Record<string, any>
60+
methods: {
61+
[key: string]: TypeValuePair
62+
}
63+
lifeCycles?: {
64+
[key: string]: TypeValuePair
65+
}
66+
id?: string | number
67+
type?: string
68+
component?: string
69+
label?: string
70+
configure?: Configure
71+
actions?: unknown
72+
blockName?: string
73+
properties?: Property[]
74+
}
75+
76+
export interface TypeValuePair {
77+
type: DataTypeEnum
78+
value: string
79+
}
80+
81+
export type DataTypeEnum = 'JSExpression' | 'JSFunction' | 'JSResource' | 'JSResouce'
82+
83+
export interface Locale {
84+
zh_CN?: string
85+
}
86+
87+
export interface Collapse {
88+
number: number
89+
text: Locale
90+
}
91+
92+
export interface Linked {
93+
componentName: string
94+
property: string
95+
id: string
96+
blockProperty: any
97+
}
98+
99+
export interface CreatedBy {
100+
id: number
101+
username: string
102+
resetPasswordToken: string
103+
}
104+
105+
export interface History {
106+
id: number
107+
message: string
108+
content: unknown
109+
assets?: Assets
110+
build_info?: BuildInfo
111+
created_by?: unknown
112+
updated_by?: unknown
113+
created_at: Date | string
114+
updated_at: Date | string
115+
screenshot?: string
116+
path?: string
117+
label?: string
118+
description?: unknown
119+
mode?: string | null
120+
block_id: number
121+
version?: string | null
122+
npm_name?: string
123+
i18n?: unknown
124+
created_app?: unknown
125+
content_blocks?: unknown
126+
}
127+
128+
export interface BuildInfo {
129+
result: boolean
130+
versions: string[]
131+
endTime: string
132+
}
133+
134+
export interface Component {
135+
id?: number | string
136+
version?: string
137+
name: {
138+
zh_CN?: string
139+
}
140+
component: string
141+
icon: string
142+
description?: string
143+
doc_url?: string
144+
screenshot?: string
145+
tags?: string
146+
keywords?: string
147+
dev_mode?: string
148+
npm?: Npm
149+
group?: string
150+
configure?: Configure
151+
content?: { configure?: Configure; schema?: Schema }
152+
createdBy?: number
153+
created_at?: Date | string
154+
updated_at?: Date | string
155+
public?: number
156+
framework?: string
157+
isOfficial?: boolean
158+
isDefault?: boolean
159+
tiny_reserved?: boolean
160+
component_metadata?: {
161+
events?: unknown[]
162+
attrs?: unknown[]
163+
slots?: unknown
164+
}
165+
library?: number
166+
schema: Schema
167+
}
168+
169+
export interface Configure {
170+
loop?: boolean
171+
condition?: boolean
172+
styles?: boolean
173+
isContainer?: boolean
174+
isModal?: boolean
175+
nestingRule?: NestingRule
176+
isNullNode?: boolean
177+
isLayout?: boolean
178+
string?: string
179+
shortcuts?: {
180+
properties: string[]
181+
}
182+
contextMenu?: ContextMenu
183+
slots?: string[]
184+
framework?: string
185+
isPopper?: boolean
186+
invalidity?: string[]
187+
clickCapture?: boolean
188+
}
189+
190+
export interface ContextMenu {
191+
actions: string[]
192+
disable: string[]
193+
}
194+
195+
export interface Property {
196+
label: Locale
197+
description?: Locale
198+
collapse?: Collapse
199+
content: {
200+
[x: string]: unknown
201+
property: string
202+
label?: {
203+
text: Locale
204+
}
205+
required?: boolean
206+
readOnly?: boolean
207+
disabled?: boolean
208+
cols?: number
209+
widget: {
210+
component: string
211+
props?: Record<string, any>
212+
}
213+
description?: Locale
214+
labelPosition?: string
215+
type?: string
216+
defaultValue?: unknown
217+
rules?: any[]
218+
hidden?: boolean
219+
device?: any[]
220+
onChange?: string
221+
properties?: ContentProperty[]
222+
linked?: Linked | null
223+
handle?: Record<string, any>
224+
}[]
225+
name?: string
226+
group?: string
227+
defaultValue?: unknown
228+
}
229+
230+
export interface ContentProperty {
231+
label: Locale
232+
content: {
233+
property: string
234+
type?: string
235+
defaultValue?: boolean | string
236+
label: {
237+
text: Locale
238+
}
239+
widget: {
240+
component: string
241+
props: Record<string, any>
242+
}
243+
labelPosition?: string
244+
required?: boolean
245+
readOnly?: boolean
246+
disabled?: boolean
247+
cols?: number
248+
description?: Locale
249+
}[]
250+
}
251+
252+
export interface Package {
253+
name: string
254+
packageName: string
255+
package?: string
256+
version: string
257+
script: string
258+
css: string
259+
others?: unknown
260+
}
261+
262+
export interface Snippet {
263+
group: string
264+
children: SnippetChild[]
265+
}
266+
267+
export interface SnippetChild {
268+
icon?: string
269+
name?: Locale
270+
schema?: Schema
271+
screenshot?: string
272+
snippetName?: string
273+
configure?: Configure
274+
group?: boolean
275+
component?: string
276+
description?: string
277+
docUrl?: string
278+
tags?: string
279+
keywords?: string
280+
devMode?: string
281+
npm?: Dependency
282+
priority?: number
283+
}
284+
285+
export interface Npm {
286+
package: string
287+
exportName: string
288+
version?: string
289+
destructuring?: boolean
290+
script?: string
291+
css?: string
292+
dependencies?: unknown
293+
}
294+
295+
export type Dependency = Omit<Npm, 'exportName'> & {
296+
components?: any
297+
}
298+
299+
export interface NestingRule {
300+
string?: string[] | string
301+
parentWhitelist?: string[]
302+
descendantBlacklist?: string[]
303+
ancestorWhitelist?: string[]
304+
}
305+
306+
export interface Schema {
307+
props?: Record<string, any>
308+
children?: Schema[]
309+
componentName?: string
310+
componentType?: string
311+
properties?: Property[]
312+
events?: Record<string, any>
313+
slots?: Record<string, any>
314+
lifeCycles?: Record<string, TypeValuePair>
315+
id?: string
316+
condition?: boolean
317+
fileName?: string
318+
}
319+
320+
export interface MaterialState {
321+
components: Snippet[]
322+
blocks: { groupId: string; groupName: string; children: Block[] }[]
323+
componentsDepsMap: {
324+
scripts: Dependency[]
325+
styles: Set<unknown>
326+
}
327+
packages: never[]
328+
}
329+
330+
export type ComponentMap = Dependency & { componentName: string }
331+
332+
export interface InitMaterialOptions {
333+
isInit?: boolean
334+
appData?: {
335+
[x: string]: any
336+
componentsMap?: Array<ComponentMap>
337+
}
338+
}

0 commit comments

Comments
 (0)