-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtypescript-utils.ts
263 lines (252 loc) · 6.2 KB
/
typescript-utils.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import { config } from '@sho-ai-org/pattern-library'
import Stitches from '@stitches/react'
// import { MutationTuple } from '@apollo/client'
import React from 'react'
import { Block, BlockCategory, BlockConnection, BlockTemplate, GetSitePageQuery, Maybe, PublishState } from '../graphql/operations'
import { UpdateBlockMutationFn } from './../graphql/operations'
export type CSS = Stitches.CSS<typeof config>
interface ScaleCategory {
scaleCategoryId: string
name: string
typefaceId: string
typefaceVariantId: string
case: React.CSSProperties['textTransform']
fontSize: number
lineHeight: number
letterSpacing: number
spaceAfter: number
}
interface Button {
id: string
borderStyle: React.CSSProperties['borderStyle']
borderWidth: number
borderRadius: number
}
interface Logo {
imageAssetKey: string
clearspace: number
backgroundColorId: string
preferredLockup: boolean
}
interface AppIcon {
imageAssetKey: string
backgroundColorId: string
}
enum ColorIdProps {
pri = 'pri',
sec = 'sec',
lin = 'lin',
ale = 'ale',
suc = 'suc',
war = 'war',
gs1 = 'gs1',
gs2 = 'gs2',
gs3 = 'gs3',
gs4 = 'gs4',
gs5 = 'gs5',
gs6 = 'gs6',
gs7 = 'gs7',
gs8 = 'gs8',
gs9 = 'gs9',
gs10 = 'gs10',
gs11 = 'gs11',
gs12 = 'gs12',
w1 = 'w1',
w2 = 'w2',
w3 = 'w3',
w4 = 'w4',
w5 = 'w5',
w6 = 'w6',
w7 = 'w7',
w8 = 'w8',
w9 = 'w9',
w10 = 'w10',
w11 = 'w11',
w12 = 'w12',
b1 = 'b1',
b2 = 'b2',
b3 = 'b3',
b4 = 'b4',
b5 = 'b5',
b6 = 'b6',
b7 = 'b7',
b8 = 'b8',
b9 = 'b9',
b10 = 'b10',
b11 = 'b11',
b12 = 'b12',
btnPriBg = 'btnPriBg',
btnPriBo = 'btnPriBo',
btnSecBg = 'btnSecBg',
btnSecBo = 'btnSecBo',
btnTerBg = 'btnTerBg',
btnTerBo = 'btnTerBo',
btnGhoBg = 'btnGhoBg',
btnGhoBo = 'btnGhoBo',
}
export interface Theme {
schemaVersion: number
colors: {
colorId: ColorIdProps
name: string
palette: 'primary' | 'secondary' | 'grayscale' | 'black' | 'white' | 'button'
value: {
r: number
g: number
b: number
a: number
}
}[]
typefaces: {
[key: string]: {
typefaceId: string
fontFamily: string
category: 'sans-serif' | 'serif'
variants: {
typefaceVariantId: string
typefaceId: string
fontWeight: string
fontStyle: 'normal' | 'italic'
format: 'woff2'
fontURL: string
}[]
}
}
scaleCategories: {
h1: ScaleCategory
h2: ScaleCategory
h3: ScaleCategory
h4: ScaleCategory
h5: ScaleCategory
h6: ScaleCategory
subtitle1: ScaleCategory
subtitle2: ScaleCategory
body1: ScaleCategory
body2: ScaleCategory
button: ScaleCategory
caption: ScaleCategory
overline: ScaleCategory
blockquote: ScaleCategory
}
button: {
primary: Button
secondary: Button
tertiary: Button
fab: Button
}
logos: {
name: string
id: string
favicon: {
imageAssetKey: string
}
appicon: AppIcon
logomark: Logo
horizontallockup: Logo
verticallockup: Logo
}[]
}
export enum ScaleCategories {
h1 = 'h1',
h2 = 'h2',
h3 = 'h3',
h4 = 'h4',
h5 = 'h5',
h6 = 'h6',
subtitle1 = 'subtitle1',
subtitle2 = 'subtitle2',
body1 = 'body1',
body2 = 'body2',
button = 'button',
caption = 'caption',
overline = 'overline',
blockquote = 'blockquote',
}
export interface SiteConfigProps {
pageTemplateObjectList: {
[key: string]: PageTemplateProps
}
blockObjectList: {
[key: string]: BlockProps | BlockTemplateProps
}
app: 'identity' | 'website' | 'publication'
toolbarConfig: {
showEdit: boolean
showDrag: boolean
showDelete: boolean
showDrafted: boolean
showStarred: boolean
showCreate: boolean
showName: boolean
}
}
export interface PageTemplateProps {
id: string
name: string
viewComponent: React.FunctionComponent<any>
editComponent: React.FunctionComponent<any>
IconComponent: React.ReactNode
description: string
blockVariationToolbarDefaultOption: string
blockVariationToolbarOptions: { label: string; value: string }[]
tags: string[]
}
type ListPageAddditionalBlocks = NonNullable<
GetSitePageQuery['getSite']['getPageBySlug']
>['items'][0]['listPageAdditionalBlocks']
type ListPageLocalBlocks = NonNullable<GetSitePageQuery['getSite']['getPageBySlug']>['items'][0]['listPageLocalBlocks']
export interface BlockViewProps<DataProps = Record<string, any>> {
theme: Theme
variant: any
data: DataProps
block: Block
brandId: string
brandStyleId: string
listPageAdditionalBlocks: ListPageAddditionalBlocks
listExternalBlocks: Maybe<BlockConnection>
listPageLocalBlocks: ListPageLocalBlocks
pageId: string
siteId: string
}
export interface BlockEditProps<DataProps = Record<string, any>> extends BlockViewProps<DataProps> {
onUpdateBlock: UpdateBlockMutationFn
}
export interface BlockProps<DataProps = Record<string, any>> {
id: string
name: string
viewComponent: React.FunctionComponent<BlockViewProps<DataProps>>
editComponent: React.FunctionComponent<BlockEditProps<DataProps>>
IconComponent: React.ReactNode
description: string
blockVariationToolbarDefaultOption: string
blockVariationToolbarOptions: { label: string; value: string }[]
tags: string[]
}
// eslint-disable-next-line @typescript-eslint/no-empty-interface
export interface BlockTemplateViewProps<DataProps = Record<string, any>> {
theme: Theme
variant: any
data: DataProps
block: BlockTemplate
brandId: string
brandStyleId: string
listPageAdditionalBlocks: ListPageAddditionalBlocks
listPageLocalBlocks: ListPageLocalBlocks
pageId: string
siteId: string
}
export interface BlockTemplateEditProps<DataProps = Record<string, any>> extends BlockTemplateViewProps<DataProps> {
onUpdateBlock: UpdateBlockMutationFn
}
export interface BlockTemplateProps<DataProps = Record<string, any>> {
id: string
name: string
viewComponent: React.FunctionComponent<BlockTemplateViewProps<DataProps>>
editComponent: React.FunctionComponent<BlockTemplateEditProps<DataProps>>
IconComponent: React.ReactNode
description: string
blockVariationToolbarDefaultOption: string
blockVariationToolbarOptions: { label: string; value: string }[]
tags: string[]
}
export type ValidationFunction<Input> = (input: Input) => string