@figma/code-connect 1.4.8 → 1.5.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.
Files changed (60) hide show
  1. package/README.md +3 -0
  2. package/dist/commands/connect.d.ts +5 -0
  3. package/dist/commands/connect.d.ts.map +1 -1
  4. package/dist/commands/connect.js +94 -26
  5. package/dist/commands/connect.js.map +1 -1
  6. package/dist/commands/connect_template.d.ts.map +1 -1
  7. package/dist/commands/connect_template.js +2 -2
  8. package/dist/commands/connect_template.js.map +1 -1
  9. package/dist/commands/preview_utils.d.ts +103 -5
  10. package/dist/commands/preview_utils.d.ts.map +1 -1
  11. package/dist/commands/preview_utils.js +453 -76
  12. package/dist/commands/preview_utils.js.map +1 -1
  13. package/dist/commands/property_list_table.d.ts +11 -0
  14. package/dist/commands/property_list_table.d.ts.map +1 -0
  15. package/dist/commands/property_list_table.js +67 -0
  16. package/dist/commands/property_list_table.js.map +1 -0
  17. package/dist/common/updates.d.ts +4 -1
  18. package/dist/common/updates.d.ts.map +1 -1
  19. package/dist/common/updates.js +26 -5
  20. package/dist/common/updates.js.map +1 -1
  21. package/dist/connect/api.d.ts +34 -1
  22. package/dist/connect/api.d.ts.map +1 -1
  23. package/dist/connect/api.js.map +1 -1
  24. package/dist/connect/batch_templates.d.ts +1 -1
  25. package/dist/connect/batch_templates.d.ts.map +1 -1
  26. package/dist/connect/batch_templates.js +2 -2
  27. package/dist/connect/batch_templates.js.map +1 -1
  28. package/dist/connect/intrinsics.d.ts +1 -0
  29. package/dist/connect/intrinsics.d.ts.map +1 -1
  30. package/dist/connect/intrinsics.js +29 -0
  31. package/dist/connect/intrinsics.js.map +1 -1
  32. package/dist/connect/migration_batch_helpers.d.ts.map +1 -1
  33. package/dist/connect/migration_batch_helpers.js +1 -15
  34. package/dist/connect/migration_batch_helpers.js.map +1 -1
  35. package/dist/connect/migration_helpers.d.ts +6 -0
  36. package/dist/connect/migration_helpers.d.ts.map +1 -1
  37. package/dist/connect/migration_helpers.js +66 -0
  38. package/dist/connect/migration_helpers.js.map +1 -1
  39. package/dist/connect/parser_executables.d.ts.map +1 -1
  40. package/dist/connect/parser_executables.js +25 -13
  41. package/dist/connect/parser_executables.js.map +1 -1
  42. package/dist/connect/property_combinations.d.ts +69 -0
  43. package/dist/connect/property_combinations.d.ts.map +1 -0
  44. package/dist/connect/property_combinations.js +172 -0
  45. package/dist/connect/property_combinations.js.map +1 -0
  46. package/dist/connect/raw_template_bundler.d.ts +13 -0
  47. package/dist/connect/raw_template_bundler.d.ts.map +1 -0
  48. package/dist/connect/raw_template_bundler.js +178 -0
  49. package/dist/connect/raw_template_bundler.js.map +1 -0
  50. package/dist/connect/raw_templates.d.ts +1 -1
  51. package/dist/connect/raw_templates.d.ts.map +1 -1
  52. package/dist/connect/raw_templates.js +85 -24
  53. package/dist/connect/raw_templates.js.map +1 -1
  54. package/dist/parser_scripts/get_swift_parser_dir.js +5 -5
  55. package/dist/parser_scripts/get_swift_parser_dir.js.map +1 -1
  56. package/dist/react/parser.d.ts.map +1 -1
  57. package/dist/react/parser.js.map +1 -1
  58. package/figma-types-no-require.d.ts +231 -0
  59. package/figma-types.d.ts +19 -8
  60. package/package.json +8 -4
@@ -0,0 +1,231 @@
1
+ /**
2
+ * Type definitions for the `figma` module available in Code Connect template files
3
+ * (.figma.ts) — variant WITHOUT the global `require('figma')` shim.
4
+ *
5
+ * Use this instead of `@figma/code-connect/figma-types` if your project has
6
+ * @types/node installed. The default entry declares a global `require`, which
7
+ * overrides Node's `NodeRequire` type and breaks `require.resolve` (and similar)
8
+ * elsewhere in your project. This variant omits that declaration so the figma
9
+ * types can be added to your main tsconfig.json without a conflict. It types the
10
+ * recommended `import figma from 'figma'` syntax; `require('figma')` is typed by
11
+ * @types/node's own `require`.
12
+ * { "compilerOptions": { "types": ["@figma/code-connect/figma-types-no-require"] } }
13
+ */
14
+ declare module 'figma' {
15
+ export type CodeSection = { type: 'CODE'; code: string; nestedImports?: string[] }
16
+ export type InstanceSection = {
17
+ type: 'INSTANCE'
18
+ guid: string
19
+ symbolId: string
20
+ resultSections?: ResultSection[]
21
+ nestedImports?: string[]
22
+ }
23
+ export type SlotSection = { type: 'SLOT'; guid?: string; propertyName: string }
24
+ export type ErrorSection = { type: 'ERROR'; message: string; errorObject?: unknown }
25
+ export type ResultSection = CodeSection | InstanceSection | SlotSection | ErrorSection
26
+ export type ResultSectionList = Array<ResultSection | ResultSectionList>
27
+
28
+ export interface TemplateStringResult {
29
+ sections: ResultSection[]
30
+ language: string
31
+ type: 'SECTIONS'
32
+ }
33
+
34
+ export interface SelectorOptions {
35
+ path?: string[]
36
+ traverseInstances?: boolean
37
+ }
38
+
39
+ export type SlotResult = ResultSection[] & {
40
+ /** Connected instances directly in the slot (shallow). */
41
+ readonly connectedInstances: InstanceHandle[]
42
+ }
43
+
44
+ type ObjectValue = Record<string, FCCValue>
45
+
46
+ export type FCCValue =
47
+ | string
48
+ | number
49
+ | boolean
50
+ | undefined
51
+ | { $value: string; $type: 'jsx-element' }
52
+ | { $value: string; $type: 'function' }
53
+ | { $value: string; $type: 'identifier' }
54
+ | { $value: ObjectValue; $type: 'object' }
55
+ | { $value: string; $type: 'template-string' }
56
+ | { $value: string; $type: 'react-component' }
57
+ | { $value: FCCValue[]; $type: 'array' }
58
+
59
+ export interface TextHandle {
60
+ readonly type: 'TEXT'
61
+ readonly name: string
62
+ readonly textContent: string
63
+ readonly __containingSlotName__?: string
64
+ __render__(): string
65
+ }
66
+
67
+ export interface TemplateMetadata {
68
+ nestable?: boolean
69
+ props?: Record<string, unknown>
70
+ __props: Record<string, unknown>
71
+ [key: string]: unknown
72
+ }
73
+
74
+ export interface ErrorHandle {
75
+ readonly type: 'ERROR'
76
+ readonly __containingSlotName__?: string
77
+ __render__(): ResultSection[]
78
+ executeTemplate(): {
79
+ example: ResultSection[]
80
+ metadata?: TemplateMetadata
81
+ }
82
+ }
83
+
84
+ export interface InstanceHandle {
85
+ readonly type: 'INSTANCE'
86
+ readonly symbolId: string
87
+ readonly name: string
88
+ readonly children: (InstanceHandle | TextHandle | ErrorHandle)[]
89
+ readonly properties: Record<string, { value: string | boolean }>
90
+ readonly path?: string[]
91
+ readonly slots?: Record<string, { guid: string }>
92
+ /** Internal: the property name of the slot this node is content of, if any. */
93
+ readonly __containingSlotName__?: string
94
+
95
+ codeConnectId(): string | null
96
+
97
+ __find__(name: string): InstanceHandle | ErrorHandle | null
98
+ __findChildWithCriteria__(criteria: {
99
+ type: 'INSTANCE' | 'TEXT'
100
+ name: string
101
+ }): InstanceHandle | TextHandle | ErrorHandle | null
102
+ __getPropertyValue__(name: string): string | boolean | ErrorHandle
103
+ __getPropertyValueByType__(name: string, type: string): string | boolean | ErrorHandle
104
+ __render__(): ResultSection[]
105
+ __getProps__(): ResultSection[] | Record<string, unknown> | undefined
106
+ __renderWithFn__(
107
+ renderFn: (props: Record<string, unknown>) => TemplateStringResult,
108
+ ): ResultSection[] | ErrorHandle | undefined
109
+
110
+ getString(propName: string): string
111
+ getBoolean(propName: string): boolean
112
+ getBoolean<O extends Record<string, unknown>>(
113
+ propName: string,
114
+ options: O,
115
+ ): EnumOptionsValues<O>
116
+ getEnum<O extends Record<string, unknown>>(
117
+ propName: string,
118
+ options: O,
119
+ ): EnumOptionsValues<O> | undefined
120
+ getInstanceSwap(propName: string): InstanceHandle | ErrorHandle | undefined
121
+ getSlot(propName: string): SlotResult | undefined
122
+ hasCodeConnect(): boolean
123
+ getPropertyValue(name: string): string | boolean | ErrorHandle
124
+ findInstance(layerName: string, opts?: SelectorOptions): InstanceHandle | ErrorHandle
125
+ findText(layerName: string, opts?: SelectorOptions): TextHandle | ErrorHandle
126
+ findConnectedInstance(
127
+ codeConnectId: string,
128
+ opts?: SelectorOptions,
129
+ ): InstanceHandle | ErrorHandle | null
130
+ findConnectedInstances(
131
+ selectorFn: (node: InstanceHandle) => boolean,
132
+ opts?: SelectorOptions,
133
+ ): (InstanceHandle | ErrorHandle)[]
134
+ findLayers(
135
+ selectorFn: (node: InstanceHandle | TextHandle) => boolean,
136
+ opts?: SelectorOptions,
137
+ ): (InstanceHandle | TextHandle | ErrorHandle)[]
138
+ executeTemplate(): {
139
+ example: ResultSection[]
140
+ metadata?: TemplateMetadata
141
+ }
142
+ }
143
+
144
+ export type LayerHandle = InstanceHandle | TextHandle | ErrorHandle
145
+
146
+ export type EnumOptionsValues<O extends Record<string, unknown>> = O[keyof O]
147
+
148
+ export interface FigmaProperties {
149
+ string(propName: string): string
150
+ boolean(propName: string): boolean
151
+ boolean<O extends Record<string, unknown>>(propName: string, options: O): EnumOptionsValues<O>
152
+ enum<O extends Record<string, unknown>>(
153
+ propName: string,
154
+ options: O,
155
+ ): EnumOptionsValues<O> | undefined
156
+ // In error cases the implementation may return string (from TextHandle.__render__)
157
+ instance(propName: string): ResultSection[] | string | undefined
158
+ __instance__(
159
+ propName: string,
160
+ ): InstanceHandle | TextHandle | ErrorHandle | ResultSection[] | undefined
161
+ slot(propName: string): SlotResult | undefined
162
+ children(layerNames: string[]): ResultSection[]
163
+ }
164
+
165
+ export type TemplateLiteral = (
166
+ strings: TemplateStringsArray,
167
+ ...values: unknown[]
168
+ ) => TemplateStringResult
169
+
170
+ export interface Figma {
171
+ /** Per-entry data from a .figma.batch.json file. Available in batch templates. */
172
+ readonly batch: Record<string, any>
173
+
174
+ /** The currently selected component instance */
175
+ readonly selectedInstance: InstanceHandle & { readonly __properties__: FigmaProperties }
176
+ /** Alias for selectedInstance */
177
+ readonly currentLayer: InstanceHandle & { readonly __properties__: FigmaProperties }
178
+ /** Access component properties via the properties API */
179
+ readonly properties: FigmaProperties
180
+
181
+ /** Template literal tag for custom/plaintext code */
182
+ code: TemplateLiteral
183
+ /** Template literal tag for JSX/TSX code */
184
+ tsx: TemplateLiteral
185
+ /** Template literal tag for HTML code */
186
+ html: TemplateLiteral
187
+ /** Template literal tag for Swift code */
188
+ swift: TemplateLiteral
189
+ /** Template literal tag for Kotlin/Compose code */
190
+ kotlin: TemplateLiteral
191
+
192
+ /** Return a raw value (not rendered as a template string) */
193
+ value(raw: unknown, preview?: unknown): { type: string; value: unknown; preview: unknown }
194
+
195
+ helpers: {
196
+ react: {
197
+ renderProp(name: string, prop: FCCValue | ResultSectionList): TemplateStringResult | string
198
+ renderChildren(
199
+ prop: FCCValue | ResultSectionList,
200
+ ): ResultSection[] | string | number | boolean | TemplateStringResult
201
+ renderPropValue(
202
+ prop: FCCValue | ResultSectionList,
203
+ ): string | number | boolean | ResultSection[]
204
+ stringifyObject(obj: unknown): string
205
+ jsxElement(value: string): { $value: string; $type: 'jsx-element' }
206
+ function(value: string): { $value: string; $type: 'function' }
207
+ identifier(value: string): { $value: string; $type: 'identifier' }
208
+ object(value: ObjectValue): { $value: ObjectValue; $type: 'object' }
209
+ templateString(value: string): { $value: string; $type: 'template-string' }
210
+ reactComponent(value: string): { $value: string; $type: 'react-component' }
211
+ array(value: FCCValue[]): { $value: FCCValue[]; $type: 'array' }
212
+ isReactComponentArray(prop: unknown): prop is ResultSectionList
213
+ }
214
+ swift: {
215
+ renderChildren(
216
+ children: ResultSectionList | string | undefined,
217
+ prefix: string,
218
+ ): ResultSection[]
219
+ }
220
+ kotlin: {
221
+ renderChildren(
222
+ children: ResultSectionList | string | undefined,
223
+ prefix: string,
224
+ ): ResultSection[]
225
+ }
226
+ }
227
+ }
228
+
229
+ const figma: Figma
230
+ export = figma
231
+ }
package/figma-types.d.ts CHANGED
@@ -20,6 +20,7 @@ declare module 'figma' {
20
20
  export type SlotSection = { type: 'SLOT'; guid?: string; propertyName: string }
21
21
  export type ErrorSection = { type: 'ERROR'; message: string; errorObject?: unknown }
22
22
  export type ResultSection = CodeSection | InstanceSection | SlotSection | ErrorSection
23
+ export type ResultSectionList = Array<ResultSection | ResultSectionList>
23
24
 
24
25
  export interface TemplateStringResult {
25
26
  sections: ResultSection[]
@@ -32,6 +33,11 @@ declare module 'figma' {
32
33
  traverseInstances?: boolean
33
34
  }
34
35
 
36
+ export type SlotResult = ResultSection[] & {
37
+ /** Connected instances directly in the slot (shallow). */
38
+ readonly connectedInstances: InstanceHandle[]
39
+ }
40
+
35
41
  type ObjectValue = Record<string, FCCValue>
36
42
 
37
43
  export type FCCValue =
@@ -51,6 +57,7 @@ declare module 'figma' {
51
57
  readonly type: 'TEXT'
52
58
  readonly name: string
53
59
  readonly textContent: string
60
+ readonly __containingSlotName__?: string
54
61
  __render__(): string
55
62
  }
56
63
 
@@ -63,6 +70,7 @@ declare module 'figma' {
63
70
 
64
71
  export interface ErrorHandle {
65
72
  readonly type: 'ERROR'
73
+ readonly __containingSlotName__?: string
66
74
  __render__(): ResultSection[]
67
75
  executeTemplate(): {
68
76
  example: ResultSection[]
@@ -78,6 +86,8 @@ declare module 'figma' {
78
86
  readonly properties: Record<string, { value: string | boolean }>
79
87
  readonly path?: string[]
80
88
  readonly slots?: Record<string, { guid: string }>
89
+ /** Internal: the property name of the slot this node is content of, if any. */
90
+ readonly __containingSlotName__?: string
81
91
 
82
92
  codeConnectId(): string | null
83
93
 
@@ -87,6 +97,7 @@ declare module 'figma' {
87
97
  name: string
88
98
  }): InstanceHandle | TextHandle | ErrorHandle | null
89
99
  __getPropertyValue__(name: string): string | boolean | ErrorHandle
100
+ __getPropertyValueByType__(name: string, type: string): string | boolean | ErrorHandle
90
101
  __render__(): ResultSection[]
91
102
  __getProps__(): ResultSection[] | Record<string, unknown> | undefined
92
103
  __renderWithFn__(
@@ -104,7 +115,7 @@ declare module 'figma' {
104
115
  options: O,
105
116
  ): EnumOptionsValues<O> | undefined
106
117
  getInstanceSwap(propName: string): InstanceHandle | ErrorHandle | undefined
107
- getSlot(propName: string): ResultSection[] | undefined
118
+ getSlot(propName: string): SlotResult | undefined
108
119
  hasCodeConnect(): boolean
109
120
  getPropertyValue(name: string): string | boolean | ErrorHandle
110
121
  findInstance(layerName: string, opts?: SelectorOptions): InstanceHandle | ErrorHandle
@@ -144,7 +155,7 @@ declare module 'figma' {
144
155
  __instance__(
145
156
  propName: string,
146
157
  ): InstanceHandle | TextHandle | ErrorHandle | ResultSection[] | undefined
147
- slot(propName: string): ResultSection[] | undefined
158
+ slot(propName: string): SlotResult | undefined
148
159
  children(layerNames: string[]): ResultSection[]
149
160
  }
150
161
 
@@ -180,12 +191,12 @@ declare module 'figma' {
180
191
 
181
192
  helpers: {
182
193
  react: {
183
- renderProp(name: string, prop: FCCValue | ResultSection[]): TemplateStringResult | string
194
+ renderProp(name: string, prop: FCCValue | ResultSectionList): TemplateStringResult | string
184
195
  renderChildren(
185
- prop: FCCValue | ResultSection[],
196
+ prop: FCCValue | ResultSectionList,
186
197
  ): ResultSection[] | string | number | boolean | TemplateStringResult
187
198
  renderPropValue(
188
- prop: FCCValue | ResultSection[],
199
+ prop: FCCValue | ResultSectionList,
189
200
  ): string | number | boolean | ResultSection[]
190
201
  stringifyObject(obj: unknown): string
191
202
  jsxElement(value: string): { $value: string; $type: 'jsx-element' }
@@ -195,17 +206,17 @@ declare module 'figma' {
195
206
  templateString(value: string): { $value: string; $type: 'template-string' }
196
207
  reactComponent(value: string): { $value: string; $type: 'react-component' }
197
208
  array(value: FCCValue[]): { $value: FCCValue[]; $type: 'array' }
198
- isReactComponentArray(prop: unknown): boolean
209
+ isReactComponentArray(prop: unknown): prop is ResultSectionList
199
210
  }
200
211
  swift: {
201
212
  renderChildren(
202
- children: ResultSection[] | string | undefined,
213
+ children: ResultSectionList | string | undefined,
203
214
  prefix: string,
204
215
  ): ResultSection[]
205
216
  }
206
217
  kotlin: {
207
218
  renderChildren(
208
- children: ResultSection[] | string | undefined,
219
+ children: ResultSectionList | string | undefined,
209
220
  prefix: string,
210
221
  ): ResultSection[]
211
222
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@figma/code-connect",
3
- "version": "1.4.8",
3
+ "version": "1.5.0",
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",
@@ -25,6 +25,9 @@
25
25
  },
26
26
  "./figma-types": {
27
27
  "types": "./figma-types.d.ts"
28
+ },
29
+ "./figma-types-no-require": {
30
+ "types": "./figma-types-no-require.d.ts"
28
31
  }
29
32
  },
30
33
  "repository": {
@@ -37,7 +40,8 @@
37
40
  },
38
41
  "files": [
39
42
  "dist/**/*",
40
- "figma-types.d.ts"
43
+ "figma-types.d.ts",
44
+ "figma-types-no-require.d.ts"
41
45
  ],
42
46
  "engines": {
43
47
  "node": ">=18"
@@ -77,13 +81,12 @@
77
81
  "@babel/types": "7.28.5",
78
82
 
79
83
 
80
-
81
84
  "@storybook/csf-tools": "8.5.1",
82
85
  "@types/cross-spawn": "^6.0.6",
83
86
  "@types/jest": "^29.5.13",
84
87
  "@types/jsdom": "^21.1.7",
85
88
  "@types/lodash": "4.17.20",
86
- "@types/node": "22.17.2",
89
+ "@types/node": "22.19.21",
87
90
  "@types/prettier": "2.7.3",
88
91
  "@types/prompts": "^2.4.9",
89
92
  "@types/react": "18.3.27",
@@ -106,6 +109,7 @@
106
109
  "compare-versions": "^6.1.0",
107
110
  "cross-spawn": "^7.0.3",
108
111
  "dotenv": "^16.3.1",
112
+ "esbuild-wasm": "0.27.3",
109
113
  "fast-fuzzy": "^1.12.0",
110
114
  "find-up": "^5.0.0",
111
115
  "glob": "^11.0.4",