@figma/code-connect 1.4.1 → 1.4.3
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/README.md +4 -4
- package/dist/commands/connect.d.ts +6 -4
- package/dist/commands/connect.d.ts.map +1 -1
- package/dist/commands/connect.js +80 -107
- package/dist/commands/connect.js.map +1 -1
- package/dist/commands/filter_project_info.d.ts +7 -0
- package/dist/commands/filter_project_info.d.ts.map +1 -0
- package/dist/commands/filter_project_info.js +32 -0
- package/dist/commands/filter_project_info.js.map +1 -0
- package/dist/connect/helpers.d.ts +6 -0
- package/dist/connect/helpers.d.ts.map +1 -1
- package/dist/connect/helpers.js +18 -0
- package/dist/connect/helpers.js.map +1 -1
- package/dist/connect/intrinsics.d.ts +3 -3
- package/dist/connect/intrinsics.d.ts.map +1 -1
- package/dist/connect/intrinsics.js +21 -10
- package/dist/connect/intrinsics.js.map +1 -1
- package/dist/connect/migration_helpers.d.ts +15 -1
- package/dist/connect/migration_helpers.d.ts.map +1 -1
- package/dist/connect/migration_helpers.js +187 -73
- package/dist/connect/migration_helpers.js.map +1 -1
- package/dist/connect/parser_common.d.ts +3 -2
- package/dist/connect/parser_common.d.ts.map +1 -1
- package/dist/connect/parser_common.js +2 -2
- package/dist/connect/parser_common.js.map +1 -1
- package/dist/connect/project.d.ts +8 -3
- package/dist/connect/project.d.ts.map +1 -1
- package/dist/connect/project.js +25 -11
- package/dist/connect/project.js.map +1 -1
- package/dist/connect/raw_templates.d.ts +11 -0
- package/dist/connect/raw_templates.d.ts.map +1 -0
- package/dist/connect/raw_templates.js +149 -0
- package/dist/connect/raw_templates.js.map +1 -0
- package/dist/connect/upload.d.ts.map +1 -1
- package/dist/connect/upload.js +27 -6
- package/dist/connect/upload.js.map +1 -1
- package/dist/html/parser.d.ts +2 -2
- package/dist/html/parser.d.ts.map +1 -1
- package/dist/html/parser.js +9 -9
- package/dist/html/parser.js.map +1 -1
- package/dist/react/parser.d.ts +3 -3
- package/dist/react/parser.d.ts.map +1 -1
- package/dist/react/parser.js +14 -12
- package/dist/react/parser.js.map +1 -1
- package/dist/storybook/convert.d.ts +7 -1
- package/dist/storybook/convert.d.ts.map +1 -1
- package/dist/storybook/convert.js +12 -5
- package/dist/storybook/convert.js.map +1 -1
- package/figma-types.d.ts +214 -0
- package/package.json +7 -3
package/figma-types.d.ts
ADDED
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type definitions for the `figma` module available in Code Connect template files
|
|
3
|
+
* (.figma.ts).
|
|
4
|
+
* Usage: add to your tsconfig.json:
|
|
5
|
+
* { "compilerOptions": { "types": ["@figma/code-connect/figma-types"] } }
|
|
6
|
+
*/
|
|
7
|
+
// Declare require() for the 'figma' module so that template files can use
|
|
8
|
+
// `const figma = require('figma')` without needing @types/node installed.
|
|
9
|
+
declare function require(module: 'figma'): typeof import('figma')
|
|
10
|
+
declare function require(module: string): any
|
|
11
|
+
declare module 'figma' {
|
|
12
|
+
export type CodeSection = { type: 'CODE'; code: string; nestedImports?: string[] }
|
|
13
|
+
export type InstanceSection = {
|
|
14
|
+
type: 'INSTANCE'
|
|
15
|
+
guid: string
|
|
16
|
+
symbolId: string
|
|
17
|
+
resultSections?: ResultSection[]
|
|
18
|
+
nestedImports?: string[]
|
|
19
|
+
}
|
|
20
|
+
export type SlotSection = { type: 'SLOT'; guid?: string; propertyName: string }
|
|
21
|
+
export type ErrorSection = { type: 'ERROR'; message: string; errorObject?: unknown }
|
|
22
|
+
export type ResultSection = CodeSection | InstanceSection | SlotSection | ErrorSection
|
|
23
|
+
|
|
24
|
+
export interface TemplateStringResult {
|
|
25
|
+
sections: ResultSection[]
|
|
26
|
+
language: string
|
|
27
|
+
type: 'SECTIONS'
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export interface SelectorOptions {
|
|
31
|
+
path?: string[]
|
|
32
|
+
traverseInstances?: boolean
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
type ObjectValue = Record<string, FCCValue>
|
|
36
|
+
|
|
37
|
+
export type FCCValue =
|
|
38
|
+
| string
|
|
39
|
+
| number
|
|
40
|
+
| boolean
|
|
41
|
+
| undefined
|
|
42
|
+
| { $value: string; $type: 'jsx-element' }
|
|
43
|
+
| { $value: string; $type: 'function' }
|
|
44
|
+
| { $value: string; $type: 'identifier' }
|
|
45
|
+
| { $value: ObjectValue; $type: 'object' }
|
|
46
|
+
| { $value: string; $type: 'template-string' }
|
|
47
|
+
| { $value: string; $type: 'react-component' }
|
|
48
|
+
| { $value: FCCValue[]; $type: 'array' }
|
|
49
|
+
|
|
50
|
+
export interface TextHandle {
|
|
51
|
+
readonly type: 'TEXT'
|
|
52
|
+
readonly name: string
|
|
53
|
+
readonly textContent: string
|
|
54
|
+
__render__(): string
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface TemplateMetadata {
|
|
58
|
+
nestable?: boolean
|
|
59
|
+
props?: Record<string, unknown>
|
|
60
|
+
__props: Record<string, unknown>
|
|
61
|
+
[key: string]: unknown
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface ErrorHandle {
|
|
65
|
+
readonly type: 'ERROR'
|
|
66
|
+
__render__(): ResultSection[]
|
|
67
|
+
executeTemplate(): {
|
|
68
|
+
example: ResultSection[]
|
|
69
|
+
metadata?: TemplateMetadata
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export interface InstanceHandle {
|
|
74
|
+
readonly type: 'INSTANCE'
|
|
75
|
+
readonly symbolId: string
|
|
76
|
+
readonly name: string
|
|
77
|
+
readonly children: (InstanceHandle | TextHandle | ErrorHandle)[]
|
|
78
|
+
readonly properties: Record<string, { value: string | boolean }>
|
|
79
|
+
readonly path?: string[]
|
|
80
|
+
readonly slots?: Record<string, { guid: string }>
|
|
81
|
+
|
|
82
|
+
codeConnectId(): string | null
|
|
83
|
+
|
|
84
|
+
__find__(name: string): InstanceHandle | ErrorHandle | null
|
|
85
|
+
__findChildWithCriteria__(criteria: {
|
|
86
|
+
type: 'INSTANCE' | 'TEXT'
|
|
87
|
+
name: string
|
|
88
|
+
}): InstanceHandle | TextHandle | ErrorHandle | null
|
|
89
|
+
__getPropertyValue__(name: string): string | boolean | ErrorHandle
|
|
90
|
+
__render__(): ResultSection[]
|
|
91
|
+
__getProps__(): ResultSection[] | Record<string, unknown> | undefined
|
|
92
|
+
__renderWithFn__(
|
|
93
|
+
renderFn: (props: Record<string, unknown>) => TemplateStringResult,
|
|
94
|
+
): ResultSection[] | ErrorHandle | undefined
|
|
95
|
+
|
|
96
|
+
getString(propName: string): string
|
|
97
|
+
getBoolean(propName: string): boolean
|
|
98
|
+
getBoolean<O extends Record<string, unknown>>(
|
|
99
|
+
propName: string,
|
|
100
|
+
options: O,
|
|
101
|
+
): EnumOptionsValues<O>
|
|
102
|
+
getEnum<O extends Record<string, unknown>>(
|
|
103
|
+
propName: string,
|
|
104
|
+
options: O,
|
|
105
|
+
): EnumOptionsValues<O> | undefined
|
|
106
|
+
getInstanceSwap(propName: string): InstanceHandle | undefined
|
|
107
|
+
getSlot(propName: string): ResultSection[] | undefined
|
|
108
|
+
hasCodeConnect(): boolean
|
|
109
|
+
getPropertyValue(name: string): string | boolean | ErrorHandle
|
|
110
|
+
findInstance(layerName: string, opts?: SelectorOptions): InstanceHandle | ErrorHandle
|
|
111
|
+
findText(layerName: string, opts?: SelectorOptions): TextHandle | ErrorHandle
|
|
112
|
+
findConnectedInstance(
|
|
113
|
+
codeConnectId: string,
|
|
114
|
+
opts?: SelectorOptions,
|
|
115
|
+
): InstanceHandle | ErrorHandle | null
|
|
116
|
+
findConnectedInstances(
|
|
117
|
+
selectorFn: (node: InstanceHandle) => boolean,
|
|
118
|
+
opts?: SelectorOptions,
|
|
119
|
+
): (InstanceHandle | ErrorHandle)[]
|
|
120
|
+
findLayers(
|
|
121
|
+
selectorFn: (node: InstanceHandle | TextHandle) => boolean,
|
|
122
|
+
opts?: SelectorOptions,
|
|
123
|
+
): (InstanceHandle | TextHandle | ErrorHandle)[]
|
|
124
|
+
executeTemplate(): {
|
|
125
|
+
example: ResultSection[]
|
|
126
|
+
metadata?: TemplateMetadata
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
export type LayerHandle = InstanceHandle | TextHandle | ErrorHandle
|
|
131
|
+
|
|
132
|
+
export type EnumOptionsValues<O extends Record<string, unknown>> = O[keyof O]
|
|
133
|
+
|
|
134
|
+
export interface FigmaProperties {
|
|
135
|
+
string(propName: string): string
|
|
136
|
+
boolean(propName: string): boolean
|
|
137
|
+
boolean<O extends Record<string, unknown>>(propName: string, options: O): EnumOptionsValues<O>
|
|
138
|
+
enum<O extends Record<string, unknown>>(
|
|
139
|
+
propName: string,
|
|
140
|
+
options: O,
|
|
141
|
+
): EnumOptionsValues<O> | undefined
|
|
142
|
+
// In error cases the implementation may return string (from TextHandle.__render__)
|
|
143
|
+
instance(propName: string): ResultSection[] | string | undefined
|
|
144
|
+
__instance__(
|
|
145
|
+
propName: string,
|
|
146
|
+
): InstanceHandle | TextHandle | ErrorHandle | ResultSection[] | undefined
|
|
147
|
+
slot(propName: string): ResultSection[] | undefined
|
|
148
|
+
children(layerNames: string[]): ResultSection[]
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
export type TemplateLiteral = (
|
|
152
|
+
strings: TemplateStringsArray,
|
|
153
|
+
...values: unknown[]
|
|
154
|
+
) => TemplateStringResult
|
|
155
|
+
|
|
156
|
+
export interface Figma {
|
|
157
|
+
/** The currently selected component instance */
|
|
158
|
+
readonly selectedInstance: InstanceHandle & { readonly __properties__: FigmaProperties }
|
|
159
|
+
/** Alias for selectedInstance */
|
|
160
|
+
readonly currentLayer: InstanceHandle & { readonly __properties__: FigmaProperties }
|
|
161
|
+
/** Access component properties via the properties API */
|
|
162
|
+
readonly properties: FigmaProperties
|
|
163
|
+
|
|
164
|
+
/** Template literal tag for custom/plaintext code */
|
|
165
|
+
code: TemplateLiteral
|
|
166
|
+
/** Template literal tag for JSX/TSX code */
|
|
167
|
+
tsx: TemplateLiteral
|
|
168
|
+
/** Template literal tag for HTML code */
|
|
169
|
+
html: TemplateLiteral
|
|
170
|
+
/** Template literal tag for Swift code */
|
|
171
|
+
swift: TemplateLiteral
|
|
172
|
+
/** Template literal tag for Kotlin/Compose code */
|
|
173
|
+
kotlin: TemplateLiteral
|
|
174
|
+
|
|
175
|
+
/** Return a raw value (not rendered as a template string) */
|
|
176
|
+
value(raw: unknown, preview?: unknown): { type: string; value: unknown; preview: unknown }
|
|
177
|
+
|
|
178
|
+
helpers: {
|
|
179
|
+
react: {
|
|
180
|
+
renderProp(name: string, prop: FCCValue | ResultSection[]): TemplateStringResult | string
|
|
181
|
+
renderChildren(
|
|
182
|
+
prop: FCCValue | ResultSection[],
|
|
183
|
+
): ResultSection[] | string | number | boolean | TemplateStringResult
|
|
184
|
+
renderPropValue(
|
|
185
|
+
prop: FCCValue | ResultSection[],
|
|
186
|
+
): string | number | boolean | ResultSection[]
|
|
187
|
+
stringifyObject(obj: unknown): string
|
|
188
|
+
jsxElement(value: string): { $value: string; $type: 'jsx-element' }
|
|
189
|
+
function(value: string): { $value: string; $type: 'function' }
|
|
190
|
+
identifier(value: string): { $value: string; $type: 'identifier' }
|
|
191
|
+
object(value: ObjectValue): { $value: ObjectValue; $type: 'object' }
|
|
192
|
+
templateString(value: string): { $value: string; $type: 'template-string' }
|
|
193
|
+
reactComponent(value: string): { $value: string; $type: 'react-component' }
|
|
194
|
+
array(value: FCCValue[]): { $value: FCCValue[]; $type: 'array' }
|
|
195
|
+
isReactComponentArray(prop: unknown): boolean
|
|
196
|
+
}
|
|
197
|
+
swift: {
|
|
198
|
+
renderChildren(
|
|
199
|
+
children: ResultSection[] | string | undefined,
|
|
200
|
+
prefix: string,
|
|
201
|
+
): ResultSection[]
|
|
202
|
+
}
|
|
203
|
+
kotlin: {
|
|
204
|
+
renderChildren(
|
|
205
|
+
children: ResultSection[] | string | undefined,
|
|
206
|
+
prefix: string,
|
|
207
|
+
): ResultSection[]
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
const figma: Figma
|
|
213
|
+
export = figma
|
|
214
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@figma/code-connect",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.3",
|
|
4
4
|
"description": "A tool for connecting your design system components in code with your design system in Figma",
|
|
5
5
|
"keywords": [],
|
|
6
6
|
"author": "Figma",
|
|
@@ -18,6 +18,9 @@
|
|
|
18
18
|
"./react": {
|
|
19
19
|
"types": "./dist/react/index_react.d.ts",
|
|
20
20
|
"default": "./dist/react/index_react.js"
|
|
21
|
+
},
|
|
22
|
+
"./figma-types": {
|
|
23
|
+
"types": "./figma-types.d.ts"
|
|
21
24
|
}
|
|
22
25
|
},
|
|
23
26
|
"repository": {
|
|
@@ -29,7 +32,8 @@
|
|
|
29
32
|
"figma": "bin/figma"
|
|
30
33
|
},
|
|
31
34
|
"files": [
|
|
32
|
-
"dist/**/*"
|
|
35
|
+
"dist/**/*",
|
|
36
|
+
"figma-types.d.ts"
|
|
33
37
|
],
|
|
34
38
|
"engines": {
|
|
35
39
|
"node": ">=18"
|
|
@@ -83,7 +87,7 @@
|
|
|
83
87
|
"pkg": "^5.8.1",
|
|
84
88
|
"ts-jest": "^29.2.5",
|
|
85
89
|
"ts-loader": "^9.5.1",
|
|
86
|
-
"tsx": "
|
|
90
|
+
"tsx": "4.21.0",
|
|
87
91
|
"webpack": "5.91.0",
|
|
88
92
|
"webpack-cli": "5.1.4"
|
|
89
93
|
},
|