@figma/code-connect 0.1.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/README.md +449 -0
- package/bin/figma +5 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +41 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/connect.d.ts +3 -0
- package/dist/commands/connect.d.ts.map +1 -0
- package/dist/commands/connect.js +214 -0
- package/dist/commands/connect.js.map +1 -0
- package/dist/common/api.d.ts +146 -0
- package/dist/common/api.d.ts.map +1 -0
- package/dist/common/api.js +3 -0
- package/dist/common/api.js.map +1 -0
- package/dist/common/compiler.d.ts +96 -0
- package/dist/common/compiler.d.ts.map +1 -0
- package/dist/common/compiler.js +281 -0
- package/dist/common/compiler.js.map +1 -0
- package/dist/common/external.d.ts +10 -0
- package/dist/common/external.d.ts.map +1 -0
- package/dist/common/external.js +53 -0
- package/dist/common/external.js.map +1 -0
- package/dist/common/figma_connect.d.ts +24 -0
- package/dist/common/figma_connect.d.ts.map +1 -0
- package/dist/common/figma_connect.js +3 -0
- package/dist/common/figma_connect.js.map +1 -0
- package/dist/common/intrinsics.d.ts +61 -0
- package/dist/common/intrinsics.d.ts.map +1 -0
- package/dist/common/intrinsics.js +239 -0
- package/dist/common/intrinsics.js.map +1 -0
- package/dist/common/logging.d.ts +25 -0
- package/dist/common/logging.d.ts.map +1 -0
- package/dist/common/logging.js +47 -0
- package/dist/common/logging.js.map +1 -0
- package/dist/common/parser.d.ts +77 -0
- package/dist/common/parser.d.ts.map +1 -0
- package/dist/common/parser.js +736 -0
- package/dist/common/parser.js.map +1 -0
- package/dist/common/parser_template_helpers.d.ts +2 -0
- package/dist/common/parser_template_helpers.d.ts.map +1 -0
- package/dist/common/parser_template_helpers.js +53 -0
- package/dist/common/parser_template_helpers.js.map +1 -0
- package/dist/common/project.d.ts +79 -0
- package/dist/common/project.d.ts.map +1 -0
- package/dist/common/project.js +171 -0
- package/dist/common/project.js.map +1 -0
- package/dist/connect/create.d.ts +8 -0
- package/dist/connect/create.d.ts.map +1 -0
- package/dist/connect/create.js +162 -0
- package/dist/connect/create.js.map +1 -0
- package/dist/connect/delete_docs.d.ts +11 -0
- package/dist/connect/delete_docs.d.ts.map +1 -0
- package/dist/connect/delete_docs.js +60 -0
- package/dist/connect/delete_docs.js.map +1 -0
- package/dist/connect/figma_rest_api.d.ts +28 -0
- package/dist/connect/figma_rest_api.d.ts.map +1 -0
- package/dist/connect/figma_rest_api.js +19 -0
- package/dist/connect/figma_rest_api.js.map +1 -0
- package/dist/connect/helpers.d.ts +13 -0
- package/dist/connect/helpers.d.ts.map +1 -0
- package/dist/connect/helpers.js +87 -0
- package/dist/connect/helpers.js.map +1 -0
- package/dist/connect/upload.d.ts +8 -0
- package/dist/connect/upload.d.ts.map +1 -0
- package/dist/connect/upload.js +62 -0
- package/dist/connect/upload.js.map +1 -0
- package/dist/connect/validation.d.ts +3 -0
- package/dist/connect/validation.d.ts.map +1 -0
- package/dist/connect/validation.js +241 -0
- package/dist/connect/validation.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/storybook/convert.d.ts +24 -0
- package/dist/storybook/convert.d.ts.map +1 -0
- package/dist/storybook/convert.js +280 -0
- package/dist/storybook/convert.js.map +1 -0
- package/dist/storybook/external.d.ts +32 -0
- package/dist/storybook/external.d.ts.map +1 -0
- package/dist/storybook/external.js +3 -0
- package/dist/storybook/external.js.map +1 -0
- package/package.json +56 -0
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.addConnectCommandToProgram = void 0;
|
|
7
|
+
const parser_1 = require("../common/parser");
|
|
8
|
+
const fs_1 = __importDefault(require("fs"));
|
|
9
|
+
const upload_1 = require("../connect/upload");
|
|
10
|
+
const validation_1 = require("../connect/validation");
|
|
11
|
+
const create_1 = require("../connect/create");
|
|
12
|
+
const project_1 = require("../common/project");
|
|
13
|
+
const logging_1 = require("../common/logging");
|
|
14
|
+
const convert_1 = require("../storybook/convert");
|
|
15
|
+
const delete_docs_1 = require("../connect/delete_docs");
|
|
16
|
+
function addBaseCommand(command, name, description) {
|
|
17
|
+
return command
|
|
18
|
+
.command(name)
|
|
19
|
+
.description(description)
|
|
20
|
+
.usage('[options]')
|
|
21
|
+
.option('-r --dir <dir>', 'directory to parse')
|
|
22
|
+
.option('-t --token <token>', 'figma access token')
|
|
23
|
+
.option('-d --debug', 'output debug logs')
|
|
24
|
+
.option('-o --outfile <file>', 'output to JSON file')
|
|
25
|
+
.option('-c --config <path>', 'path to a figma config file')
|
|
26
|
+
.option('--dry-run', 'tests publishing without actually publishing');
|
|
27
|
+
}
|
|
28
|
+
function addConnectCommandToProgram(program) {
|
|
29
|
+
// Main command, invoked with `figma connect`
|
|
30
|
+
const connectCommand = addBaseCommand(program, 'connect', 'Start the Code Connect Wizard (not implemented yet)');
|
|
31
|
+
// Sub-commands, invoked with e.g. `figma connect publish`
|
|
32
|
+
addBaseCommand(connectCommand, 'publish', 'Run Code Connect locally to find any files that include calls to `figma.connect()` and publishes those to Figma. ' +
|
|
33
|
+
'By default this looks for a config file named "figma.config.json", and uses the `include` and `exclude` fields to determine which files to parse. ' +
|
|
34
|
+
'If no config file is found, this parses the current directory. An optional `--dir` flag can be used to specify a directory to parse.')
|
|
35
|
+
.option('--skip-validation', 'skip validation of Code Connect docs')
|
|
36
|
+
.action(handlePublish);
|
|
37
|
+
addBaseCommand(connectCommand, 'unpublish', 'Run to find any files that include calls to `figma.connect()` and unpublish them from Figma. ' +
|
|
38
|
+
'By default this looks for a config file named "figma.config.json", and uses the `include` and `exclude` fields to determine which files to parse. ' +
|
|
39
|
+
'If no config file is found, this parses the current directory. An optional `--dir` flag can be used to specify a directory to parse.')
|
|
40
|
+
.option('--node <link_to_node>', 'specify the node to unpublish. This will unpublish for both React and Storybook.')
|
|
41
|
+
.action(handleUnpublish);
|
|
42
|
+
addBaseCommand(connectCommand, 'parse', 'Run Code Connect locally to find any files that include calls to `figma.connect()`, then converts to JSON and outputs to stdout.').action(handleParse);
|
|
43
|
+
addBaseCommand(connectCommand, 'create', 'Generate a Code Connect file with boilerplate in the current directory for a Figma node URL')
|
|
44
|
+
.argument('<figma-node-url>', 'Figma node URL to create the Code Connect file from')
|
|
45
|
+
.action(handleCreate);
|
|
46
|
+
}
|
|
47
|
+
exports.addConnectCommandToProgram = addConnectCommandToProgram;
|
|
48
|
+
function getAccessToken(cmd) {
|
|
49
|
+
return cmd.token ?? process.env.FIGMA_ACCESS_TOKEN;
|
|
50
|
+
}
|
|
51
|
+
function setupHandler(cmd) {
|
|
52
|
+
if (cmd.debug) {
|
|
53
|
+
logging_1.logger.setLogLevel(logging_1.LogLevel.Debug);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async function getFigmadocs(dir, cmd, projectInfo) {
|
|
57
|
+
const figmadocs = [];
|
|
58
|
+
const { files, remoteUrl, config, tsProgram } = projectInfo;
|
|
59
|
+
const figmaNodeToFile = new Map();
|
|
60
|
+
for (const file of files.filter((f) => (0, parser_1.isFigmaConnectFile)(tsProgram, f))) {
|
|
61
|
+
try {
|
|
62
|
+
const docs = await (0, parser_1.parse)(tsProgram, file, remoteUrl, config, cmd.debug);
|
|
63
|
+
for (const doc of docs) {
|
|
64
|
+
figmaNodeToFile.set(doc.figmaNode, file);
|
|
65
|
+
}
|
|
66
|
+
figmadocs.push(...docs);
|
|
67
|
+
logging_1.logger.info((0, logging_1.success)(file));
|
|
68
|
+
}
|
|
69
|
+
catch (e) {
|
|
70
|
+
logging_1.logger.error(`❌ ${file}`);
|
|
71
|
+
if (e instanceof parser_1.ParserError) {
|
|
72
|
+
if (cmd.debug) {
|
|
73
|
+
console.trace(e);
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
logging_1.logger.error(e.toString());
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
if (cmd.debug) {
|
|
81
|
+
console.trace(e);
|
|
82
|
+
}
|
|
83
|
+
else {
|
|
84
|
+
logging_1.logger.error(new parser_1.InternalError(String(e)).toString());
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return figmadocs;
|
|
90
|
+
}
|
|
91
|
+
async function handlePublish(cmd) {
|
|
92
|
+
setupHandler(cmd);
|
|
93
|
+
let dir = cmd.dir ?? process.cwd();
|
|
94
|
+
const projectInfo = (0, project_1.getProjectInfo)(dir, cmd.config);
|
|
95
|
+
if (cmd.dryRun) {
|
|
96
|
+
logging_1.logger.info(`Files that would be published:`);
|
|
97
|
+
}
|
|
98
|
+
const figmadocs = await getFigmadocs(dir, cmd, projectInfo);
|
|
99
|
+
const storybookFigmadocs = await (0, convert_1.convertStorybookFiles)({
|
|
100
|
+
projectInfo,
|
|
101
|
+
});
|
|
102
|
+
const allCodeConnectFiles = figmadocs.concat(storybookFigmadocs);
|
|
103
|
+
if (allCodeConnectFiles.length === 0) {
|
|
104
|
+
logging_1.logger.warn(`No Code Connect files found in ${dir} - Make sure you have configured \`include\` and \`exclude\` in your figma.config.json file correctly, or that you are running in a directory that contains Code Connect files.`);
|
|
105
|
+
process.exit(0);
|
|
106
|
+
}
|
|
107
|
+
const accessToken = getAccessToken(cmd);
|
|
108
|
+
if (!accessToken) {
|
|
109
|
+
logging_1.logger.error(`Couldn't find a Figma access token. Please provide one with \`--token <access_token>\` or set the FIGMA_ACCESS_TOKEN environment variable`);
|
|
110
|
+
process.exit(1);
|
|
111
|
+
}
|
|
112
|
+
if (cmd.skipValidation) {
|
|
113
|
+
logging_1.logger.info('Validation skipped');
|
|
114
|
+
}
|
|
115
|
+
else {
|
|
116
|
+
logging_1.logger.info('Validating Code Connect files...');
|
|
117
|
+
var start = new Date().getTime();
|
|
118
|
+
const valid = await (0, validation_1.validateDocs)(accessToken, allCodeConnectFiles);
|
|
119
|
+
if (!valid) {
|
|
120
|
+
process.exit(1);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
var end = new Date().getTime();
|
|
124
|
+
var time = end - start;
|
|
125
|
+
logging_1.logger.info(`All Code Connect files are valid (${time}ms)`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
if (cmd.dryRun) {
|
|
129
|
+
logging_1.logger.info(`Dry run complete`);
|
|
130
|
+
process.exit(0);
|
|
131
|
+
}
|
|
132
|
+
(0, upload_1.upload)({ accessToken, docs: allCodeConnectFiles });
|
|
133
|
+
}
|
|
134
|
+
async function handleUnpublish(cmd) {
|
|
135
|
+
setupHandler(cmd);
|
|
136
|
+
let dir = cmd.dir ?? process.cwd();
|
|
137
|
+
if (cmd.dryRun) {
|
|
138
|
+
logging_1.logger.info(`Files that would be unpublished:`);
|
|
139
|
+
}
|
|
140
|
+
let nodesToDeleteRelevantInfo;
|
|
141
|
+
if (cmd.node) {
|
|
142
|
+
nodesToDeleteRelevantInfo = [
|
|
143
|
+
{ figmaNode: cmd.node, label: 'React' },
|
|
144
|
+
{ figmaNode: cmd.node, label: 'Storybook' },
|
|
145
|
+
];
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const projectInfo = (0, project_1.getProjectInfo)(dir, cmd.config);
|
|
149
|
+
const figmadocs = await getFigmadocs(dir, cmd, projectInfo);
|
|
150
|
+
const storybookFigmadocs = await (0, convert_1.convertStorybookFiles)({
|
|
151
|
+
projectInfo,
|
|
152
|
+
});
|
|
153
|
+
const allCodeConnectFiles = figmadocs.concat(storybookFigmadocs);
|
|
154
|
+
nodesToDeleteRelevantInfo = allCodeConnectFiles.map((doc) => ({
|
|
155
|
+
figmaNode: doc.figmaNode,
|
|
156
|
+
label: doc.label,
|
|
157
|
+
}));
|
|
158
|
+
if (cmd.dryRun) {
|
|
159
|
+
logging_1.logger.info(`Dry run complete`);
|
|
160
|
+
process.exit(0);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const accessToken = getAccessToken(cmd);
|
|
164
|
+
(0, delete_docs_1.delete_docs)({
|
|
165
|
+
accessToken,
|
|
166
|
+
docs: nodesToDeleteRelevantInfo,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
async function handleParse(cmd) {
|
|
170
|
+
setupHandler(cmd);
|
|
171
|
+
// if we're not doing a dry run, we don't want to output logs
|
|
172
|
+
if (!cmd.dryRun) {
|
|
173
|
+
logging_1.logger.setLogLevel(logging_1.LogLevel.Error);
|
|
174
|
+
}
|
|
175
|
+
let dir = cmd.dir ?? process.cwd();
|
|
176
|
+
const projectInfo = (0, project_1.getProjectInfo)(dir, cmd.config);
|
|
177
|
+
const figmadocs = await getFigmadocs(dir, cmd, projectInfo);
|
|
178
|
+
const storybookFigmadocs = await (0, convert_1.convertStorybookFiles)({
|
|
179
|
+
projectInfo,
|
|
180
|
+
});
|
|
181
|
+
const allCodeConnectFiles = figmadocs.concat(storybookFigmadocs);
|
|
182
|
+
if (cmd.dryRun) {
|
|
183
|
+
logging_1.logger.info(`Dry run complete`);
|
|
184
|
+
process.exit(0);
|
|
185
|
+
}
|
|
186
|
+
if (cmd.outfile) {
|
|
187
|
+
fs_1.default.writeFileSync(cmd.outfile, JSON.stringify(figmadocs, null, 2));
|
|
188
|
+
logging_1.logger.info(`Wrote Code Connect JSON to ${(0, logging_1.highlight)(cmd.outfile)}`);
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
// don't format the output, so it can be piped to other commands
|
|
192
|
+
console.log(JSON.stringify(allCodeConnectFiles, undefined, 2));
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function handleCreate(nodeUrl, cmd) {
|
|
196
|
+
setupHandler(cmd);
|
|
197
|
+
if (cmd.dryRun) {
|
|
198
|
+
process.exit(0);
|
|
199
|
+
}
|
|
200
|
+
const accessToken = getAccessToken(cmd);
|
|
201
|
+
if (!accessToken) {
|
|
202
|
+
logging_1.logger.error(`Couldn't find a Figma access token. Please provide one with \`--token <access_token>\` or set the FIGMA_ACCESS_TOKEN environment variable`);
|
|
203
|
+
process.exit(1);
|
|
204
|
+
}
|
|
205
|
+
return (0, create_1.createFigmadocFromUrl)({
|
|
206
|
+
accessToken,
|
|
207
|
+
// We remove \s to allow users to paste URLs inside quotes - the terminal
|
|
208
|
+
// paste will add backslashes, which the quotes preserve, but expected user
|
|
209
|
+
// behaviour would be to strip the quotes
|
|
210
|
+
figmaNodeUrl: nodeUrl.replace(/\\/g, ''),
|
|
211
|
+
outFile: cmd.outfile,
|
|
212
|
+
});
|
|
213
|
+
}
|
|
214
|
+
//# sourceMappingURL=connect.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"connect.js","sourceRoot":"","sources":["../../src/commands/connect.ts"],"names":[],"mappings":";;;;;;AACA,6CAAwF;AACxF,4CAAmB;AACnB,8CAA0C;AAC1C,sDAAoD;AACpD,8CAAyD;AACzD,+CAA+D;AAC/D,+CAA+E;AAE/E,kDAA4D;AAC5D,wDAAoD;AAWpD,SAAS,cAAc,CAAC,OAA0B,EAAE,IAAY,EAAE,WAAmB;IACnF,OAAO,OAAO;SACX,OAAO,CAAC,IAAI,CAAC;SACb,WAAW,CAAC,WAAW,CAAC;SACxB,KAAK,CAAC,WAAW,CAAC;SAClB,MAAM,CAAC,gBAAgB,EAAE,oBAAoB,CAAC;SAC9C,MAAM,CAAC,oBAAoB,EAAE,oBAAoB,CAAC;SAClD,MAAM,CAAC,YAAY,EAAE,mBAAmB,CAAC;SACzC,MAAM,CAAC,qBAAqB,EAAE,qBAAqB,CAAC;SACpD,MAAM,CAAC,oBAAoB,EAAE,6BAA6B,CAAC;SAC3D,MAAM,CAAC,WAAW,EAAE,8CAA8C,CAAC,CAAA;AACxE,CAA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ACxC,OAAO,EAAE,GAAG,CAAC,OAAO;KACrB,CAAC,CAAA;AACJ,CAAC"}
|
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/// <reference types="react" />
|
|
2
|
+
export interface FigmaConnectAPI {
|
|
3
|
+
/**
|
|
4
|
+
* Creates Figma documentation for a React component and a Figma component. This function is used to
|
|
5
|
+
* define a code example that displays in Figma when that component is selected. The function must be
|
|
6
|
+
* called with a link to the figmaNode and a reference to the React component.
|
|
7
|
+
*
|
|
8
|
+
* @param component A reference to the React component
|
|
9
|
+
* @param figmaNodeUrl A link to the node in Figma, for example:`https://www.figma.com/file/123abc/My-Component?node-id=123:456`
|
|
10
|
+
* @param meta {@link FigmaConnectMeta}
|
|
11
|
+
*/
|
|
12
|
+
connect<P = {}>(component: any, figmaNodeUrl: string, meta?: FigmaConnectMeta<P>): void;
|
|
13
|
+
/**
|
|
14
|
+
* Maps a Figma property to a boolean value for the connected component. This prop is replaced
|
|
15
|
+
* with values from the Figma instance when viewed in Dev Mode. For example:
|
|
16
|
+
* ```ts
|
|
17
|
+
* props: {
|
|
18
|
+
* disabled: figma.boolean('Disabled'),
|
|
19
|
+
* }
|
|
20
|
+
* ```
|
|
21
|
+
* Would show the `disabled` property if the Figma property "Disabled" is true.
|
|
22
|
+
*
|
|
23
|
+
* @param figmaPropName The name of the property on the Figma component
|
|
24
|
+
*/
|
|
25
|
+
boolean(figmaPropName: string): boolean;
|
|
26
|
+
/**
|
|
27
|
+
* Maps a Figma boolean property to a set of values for the connected component, providing
|
|
28
|
+
* a value mapping for `true` and `false`. This prop is replaced with values from the
|
|
29
|
+
* Figma instance when viewed in Dev Mode. Example:
|
|
30
|
+
* ```ts
|
|
31
|
+
* props: {
|
|
32
|
+
* label: figma.boolean('Disabled', {
|
|
33
|
+
* true: <Label />,
|
|
34
|
+
* false: <HiddenLabel />
|
|
35
|
+
* }),
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
* Would replace `label` with `<Label />` if the Figma property "Disabled" is true.
|
|
39
|
+
*
|
|
40
|
+
* @param figmaPropName The name of the property on the Figma component
|
|
41
|
+
* @param valueMapping A mapping of values for `true` and `false`
|
|
42
|
+
*/
|
|
43
|
+
boolean<V extends string | boolean | number | symbol | undefined | JSX.Element>(figmaPropName: string, valueMapping?: Record<'true' | 'false', V>): ValueOf<Record<'true' | 'false', V>>;
|
|
44
|
+
/**
|
|
45
|
+
* Maps a Figma Variant property to a set if values for the connected component. This prop is replaced
|
|
46
|
+
* with values from the Figma instance when viewed in Dev Mode. For example:
|
|
47
|
+
* ```ts
|
|
48
|
+
* props: {
|
|
49
|
+
* type: figma.enum('Type', {
|
|
50
|
+
* Primary: 'primary',
|
|
51
|
+
* Secondary: 'secondary',
|
|
52
|
+
* }),
|
|
53
|
+
* }
|
|
54
|
+
* ```
|
|
55
|
+
* Would output "primary" if the Type Variant in Figma is set to "Primary".
|
|
56
|
+
*
|
|
57
|
+
* @param figmaPropName The name of the property on the Figma component
|
|
58
|
+
* @param valueMapping A mapping of values for the Figma Variant
|
|
59
|
+
*/
|
|
60
|
+
enum<V extends string | boolean | number | symbol | undefined | JSX.Element>(figmaPropName: string, valueMapping: PropMapping<Record<string, V>>): ValueOf<Record<string, V>>;
|
|
61
|
+
/**
|
|
62
|
+
* Maps a Figma property to a string value for the connected component. This prop is replaced
|
|
63
|
+
* with values from the Figma instance when viewed in Dev Mode. For example:
|
|
64
|
+
* ```ts
|
|
65
|
+
* props: {
|
|
66
|
+
* text: figma.string('Text'),
|
|
67
|
+
* }
|
|
68
|
+
* ```
|
|
69
|
+
* Would replace `text` with the text content from the Figma property "Text".
|
|
70
|
+
*
|
|
71
|
+
* @param figmaPropName The name of the property on the Figma component
|
|
72
|
+
*/
|
|
73
|
+
string(figmaPropName: string): string;
|
|
74
|
+
/**
|
|
75
|
+
* Maps a Figma instance property for the connected component. This prop is replaced
|
|
76
|
+
* with values from the Figma instance when viewed in Dev Mode. For example:
|
|
77
|
+
* ```ts
|
|
78
|
+
* props: {
|
|
79
|
+
* icon: figma.instance('Icon'),
|
|
80
|
+
* }
|
|
81
|
+
* ```
|
|
82
|
+
* Would show the nested examples for the component passed to the "Icon" property in Figma.
|
|
83
|
+
*
|
|
84
|
+
* @param figmaPropName The name of the property on the Figma component
|
|
85
|
+
*/
|
|
86
|
+
instance(figmaPropName: string): JSX.Element;
|
|
87
|
+
/**
|
|
88
|
+
* Maps a Figma instance layer to a nested code example. For example:
|
|
89
|
+
* ```ts
|
|
90
|
+
* props: {
|
|
91
|
+
* icon: figma.children('Icon')
|
|
92
|
+
* }
|
|
93
|
+
* ```
|
|
94
|
+
* Would show the nested code example for the child instance named 'Icon'. This also supports
|
|
95
|
+
* an array: `tabs: figma.children(['Tab 1', 'Tab 2'])` to map multiple nested examples.
|
|
96
|
+
*
|
|
97
|
+
* @param figmaPropName The name of the property on the Figma component
|
|
98
|
+
*/
|
|
99
|
+
children(layerNames: string | string[]): JSX.Element;
|
|
100
|
+
}
|
|
101
|
+
export type ValueOf<T> = T[keyof T];
|
|
102
|
+
export type PropMapping<T> = {
|
|
103
|
+
[key in keyof T]: T[key];
|
|
104
|
+
};
|
|
105
|
+
export interface FigmaConnectLink {
|
|
106
|
+
name: string;
|
|
107
|
+
url: string;
|
|
108
|
+
}
|
|
109
|
+
export interface FigmaConnectMeta<T = {}, ExtraExampleT = never> {
|
|
110
|
+
/**
|
|
111
|
+
* Restricts this figma connect to any variants that fullfill the given filter.
|
|
112
|
+
* The filter is a map of Figma variant names to values. Example:
|
|
113
|
+
* ```ts
|
|
114
|
+
* {
|
|
115
|
+
* variant: { "Has Icon": true }
|
|
116
|
+
* }
|
|
117
|
+
*/
|
|
118
|
+
variant?: Record<string, string | boolean | number>;
|
|
119
|
+
/**
|
|
120
|
+
* Prop mappings for the connected component. This is used to map the values of the component's props
|
|
121
|
+
* to the values that are used in Figma, using helper functions like `Figma.boolean`. For example:
|
|
122
|
+
* ```ts
|
|
123
|
+
* props: {
|
|
124
|
+
* disabled: figma.boolean('Disabled'),
|
|
125
|
+
* text: figma.string('Text'),
|
|
126
|
+
* size: figma.enum('Size', {
|
|
127
|
+
* slim: 'slim',
|
|
128
|
+
* medium: 'medium',
|
|
129
|
+
* large: 'large',
|
|
130
|
+
* }),
|
|
131
|
+
* }
|
|
132
|
+
*/
|
|
133
|
+
props?: T;
|
|
134
|
+
/**
|
|
135
|
+
* The code example to display in Figma. Any mapped `props` is passed to the component,
|
|
136
|
+
* where those values will be replaced with the mapped value when inspecting that instance in Figma.
|
|
137
|
+
* @param props
|
|
138
|
+
* @returns
|
|
139
|
+
*/
|
|
140
|
+
example?: ((props: T) => React.Component | JSX.Element) | ExtraExampleT;
|
|
141
|
+
/**
|
|
142
|
+
* A list of links that will display in Figma along with the examples
|
|
143
|
+
*/
|
|
144
|
+
links?: FigmaConnectLink[];
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=api.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.d.ts","sourceRoot":"","sources":["../../src/common/api.ts"],"names":[],"mappings":";AAAA,MAAM,WAAW,eAAe;IAC9B;;;;;;;;OAQG;IACH,OAAO,CAAC,CAAC,GAAG,EAAE,EAAE,SAAS,EAAE,GAAG,EAAE,YAAY,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE,gBAAgB,CAAC,CAAC,CAAC,GAAG,IAAI,CAAA;IAEvF;;;;;;;;;;;OAWG;IACH,OAAO,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO,CAAA;IAEvC;;;;;;;;;;;;;;;;OAgBG;IACH,OAAO,CAAC,CAAC,SAAS,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,GAAG,CAAC,OAAO,EAC5E,aAAa,EAAE,MAAM,EACrB,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,CAAC,CAAC,GACzC,OAAO,CAAC,MAAM,CAAC,MAAM,GAAG,OAAO,EAAE,CAA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AG,GAAG,CAAC,OAAO,CAAC,GAAG,aAAa,CAAA;IAEvE;;OAEG;IACH,KAAK,CAAC,EAAE,gBAAgB,EAAE,CAAA;CAC3B"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"api.js","sourceRoot":"","sources":["../../src/common/api.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import ts from 'typescript';
|
|
2
|
+
import { ParserContext } from './parser';
|
|
3
|
+
/**
|
|
4
|
+
* Get the default export from a TypeScript source file
|
|
5
|
+
*
|
|
6
|
+
* @param sourceFile TypeScript source file
|
|
7
|
+
* @returns The default export Expression, or undefined if there is no default export
|
|
8
|
+
*/
|
|
9
|
+
export declare function getDefaultExport(sourceFile: ts.SourceFile): ts.Expression | undefined;
|
|
10
|
+
/**
|
|
11
|
+
* Perform a breadth-first search to find the first node matching a predicate
|
|
12
|
+
*
|
|
13
|
+
* @param node Node to start the search from
|
|
14
|
+
* @param tsSourceFile SourceFile associated with the node
|
|
15
|
+
* @param predicate Predicate to match
|
|
16
|
+
* @returns The first node matching the predicate, or undefined if no node is found
|
|
17
|
+
*/
|
|
18
|
+
export declare function bfsFindNode(node: ts.Node, tsSourceFile: ts.SourceFile, predicate: (node: ts.Node) => boolean): ts.Node | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Gets a property with the specified name and type (via predicate) from an object literal node
|
|
21
|
+
*
|
|
22
|
+
* @param objectLiteralNode The object literal node potentially containing the property
|
|
23
|
+
* @param propertyName The name of the property to get
|
|
24
|
+
* @param predicate Optional predicate to match
|
|
25
|
+
* @param required Whether the property is required. Defaults to false.
|
|
26
|
+
* If true, an error will be thrown if the property is not found
|
|
27
|
+
* @param errorMessage Optional error message to throw if the property is not found
|
|
28
|
+
* @returns The property, or undefined if the property is not found
|
|
29
|
+
*/
|
|
30
|
+
export declare function parsePropertyOfType<T extends ts.Node>(params: {
|
|
31
|
+
objectLiteralNode: ts.ObjectLiteralExpression;
|
|
32
|
+
propertyName: string;
|
|
33
|
+
predicate: (node: ts.Node) => node is T;
|
|
34
|
+
parserContext: ParserContext;
|
|
35
|
+
required?: true;
|
|
36
|
+
errorMessage?: string;
|
|
37
|
+
}): T;
|
|
38
|
+
export declare function parsePropertyOfType<T extends ts.Node>(params: {
|
|
39
|
+
objectLiteralNode: ts.ObjectLiteralExpression;
|
|
40
|
+
propertyName: string;
|
|
41
|
+
predicate: (node: ts.Node) => node is T;
|
|
42
|
+
parserContext: ParserContext;
|
|
43
|
+
required?: false;
|
|
44
|
+
errorMessage?: string;
|
|
45
|
+
}): T | undefined;
|
|
46
|
+
export declare function parsePropertyOfType<T extends ts.Node>(params: {
|
|
47
|
+
objectLiteralNode: ts.ObjectLiteralExpression;
|
|
48
|
+
propertyName: string;
|
|
49
|
+
predicate: (node: ts.Node) => node is T;
|
|
50
|
+
parserContext: ParserContext;
|
|
51
|
+
required?: boolean;
|
|
52
|
+
errorMessage?: string;
|
|
53
|
+
}): T | undefined;
|
|
54
|
+
type TypeGuard<A, B extends A> = (a: A) => a is B;
|
|
55
|
+
type GuardType<T> = T extends (o: any) => o is infer U ? U : never;
|
|
56
|
+
/**
|
|
57
|
+
* Combines several type guards into one.
|
|
58
|
+
*
|
|
59
|
+
* The returned function checks if any of the type guards in the list matches the argument,
|
|
60
|
+
* and infers the type based on the matching type guard.
|
|
61
|
+
*
|
|
62
|
+
* @param guards A list of type guards
|
|
63
|
+
*/
|
|
64
|
+
export declare function isOneOf<T extends TypeGuard<any, any>>(guards: T[]): [T] extends [TypeGuard<infer A, any>] ? (a: A) => a is GuardType<T> : never;
|
|
65
|
+
/**
|
|
66
|
+
* Gets a function argument with the specified index from a call expression node
|
|
67
|
+
*
|
|
68
|
+
* @param fn The call expression node potentially containing the argument
|
|
69
|
+
* @param parserContext The parser context
|
|
70
|
+
* @param index The index of the argument to get
|
|
71
|
+
* @param predicate Predicate to match
|
|
72
|
+
* @param required Whether the argument is required. Defaults to false.
|
|
73
|
+
* @param errorMessage Optional error message to throw if the argument is not found
|
|
74
|
+
* @returns
|
|
75
|
+
*/
|
|
76
|
+
export declare function parseFunctionArgument<T extends ts.Node>(fn: ts.CallExpression, parserContext: ParserContext, index: number, predicate: (node: ts.Node) => node is T, required?: boolean, errorMessage?: string): T | undefined;
|
|
77
|
+
export declare function assertIsPropertyAssignment(node: ts.Node, sourceFile: ts.SourceFile): asserts node is ts.PropertyAssignment;
|
|
78
|
+
export declare function assertIsStringLiteral(node: ts.Node, sourceFile: ts.SourceFile, msg?: string): asserts node is ts.StringLiteral;
|
|
79
|
+
export declare function assertIsArrayLiteralExpression(node: ts.Node, sourceFile: ts.SourceFile, msg?: string): asserts node is ts.ArrayLiteralExpression;
|
|
80
|
+
export declare function assertIsObjectLiteralExpression(node: ts.Node, sourceFile: ts.SourceFile, msg?: string): asserts node is ts.ObjectLiteralExpression;
|
|
81
|
+
export declare function assertIsIdentifier(node: ts.Node, sourceFile: ts.SourceFile, msg?: string): asserts node is ts.Identifier;
|
|
82
|
+
/**
|
|
83
|
+
* Convert an object literal node to a JavaScript object
|
|
84
|
+
*
|
|
85
|
+
* @param objectLiteral The object literal node to convert
|
|
86
|
+
* @param sourceFile The source file containing the object literal
|
|
87
|
+
* @param extraConversionFn Optional function to convert a node to a value. This
|
|
88
|
+
* runs before the default conversion. If this returns undefined, the default
|
|
89
|
+
* conversion will be used. (This does mean there's no way to return undefined)
|
|
90
|
+
* @returns The JavaScript object version of the object literal
|
|
91
|
+
*/
|
|
92
|
+
export declare function convertObjectLiteralToJs(objectLiteral: ts.ObjectLiteralExpression, sourceFile: ts.SourceFile, checker: ts.TypeChecker, extraConversionFn?: (node: ts.Expression) => any): Record<string, any>;
|
|
93
|
+
export declare function getTagName(element: ts.JsxElement | ts.JsxSelfClosingElement): string;
|
|
94
|
+
export declare function stripQuotes(node: ts.StringLiteral): string;
|
|
95
|
+
export {};
|
|
96
|
+
//# sourceMappingURL=compiler.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
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