@figma/code-connect 1.0.5 → 1.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.
Files changed (155) hide show
  1. package/README.md +2 -595
  2. package/dist/cli.js +2 -0
  3. package/dist/cli.js.map +1 -1
  4. package/dist/client/figma_client.d.ts +1 -1
  5. package/dist/client/figma_client.js +9 -7
  6. package/dist/client/figma_client.js.map +1 -1
  7. package/dist/commands/connect.d.ts +4 -2
  8. package/dist/commands/connect.d.ts.map +1 -1
  9. package/dist/commands/connect.js +97 -49
  10. package/dist/commands/connect.js.map +1 -1
  11. package/dist/connect/api.d.ts +143 -0
  12. package/dist/connect/api.d.ts.map +1 -0
  13. package/dist/connect/api.js +3 -0
  14. package/dist/connect/api.js.map +1 -0
  15. package/dist/connect/create.d.ts.map +1 -1
  16. package/dist/connect/create.js +4 -0
  17. package/dist/connect/create.js.map +1 -1
  18. package/dist/connect/create_common.d.ts +7 -0
  19. package/dist/connect/create_common.d.ts.map +1 -0
  20. package/dist/connect/create_common.js +19 -0
  21. package/dist/connect/create_common.js.map +1 -0
  22. package/dist/connect/external_types.d.ts +8 -0
  23. package/dist/connect/external_types.d.ts.map +1 -0
  24. package/dist/connect/external_types.js +31 -0
  25. package/dist/connect/external_types.js.map +1 -0
  26. package/dist/connect/figma_connect.d.ts +26 -0
  27. package/dist/connect/figma_connect.d.ts.map +1 -0
  28. package/dist/connect/figma_connect.js +3 -0
  29. package/dist/connect/figma_connect.js.map +1 -0
  30. package/dist/connect/figma_rest_api.d.ts +7 -0
  31. package/dist/connect/figma_rest_api.d.ts.map +1 -1
  32. package/dist/connect/figma_rest_api.js.map +1 -1
  33. package/dist/connect/index_common.d.ts +3 -0
  34. package/dist/connect/index_common.d.ts.map +1 -0
  35. package/dist/connect/index_common.js +23 -0
  36. package/dist/connect/index_common.js.map +1 -0
  37. package/dist/connect/intrinsics.d.ts +94 -0
  38. package/dist/connect/intrinsics.d.ts.map +1 -0
  39. package/dist/connect/intrinsics.js +401 -0
  40. package/dist/connect/intrinsics.js.map +1 -0
  41. package/dist/connect/parser_common.d.ts +144 -0
  42. package/dist/connect/parser_common.d.ts.map +1 -0
  43. package/dist/connect/parser_common.js +297 -0
  44. package/dist/connect/parser_common.js.map +1 -0
  45. package/dist/connect/parser_executable_types.d.ts +20 -23
  46. package/dist/connect/parser_executable_types.d.ts.map +1 -1
  47. package/dist/connect/parser_executable_types.js.map +1 -1
  48. package/dist/connect/parser_executables.js +1 -1
  49. package/dist/connect/parser_executables.js.map +1 -1
  50. package/dist/connect/project.d.ts +20 -5
  51. package/dist/connect/project.d.ts.map +1 -1
  52. package/dist/connect/project.js +79 -16
  53. package/dist/connect/project.js.map +1 -1
  54. package/dist/connect/upload.d.ts +1 -1
  55. package/dist/connect/upload.d.ts.map +1 -1
  56. package/dist/connect/validation.d.ts +1 -1
  57. package/dist/connect/validation.d.ts.map +1 -1
  58. package/dist/connect/wizard/helpers.d.ts +1 -0
  59. package/dist/connect/wizard/helpers.d.ts.map +1 -1
  60. package/dist/connect/wizard/helpers.js +27 -15
  61. package/dist/connect/wizard/helpers.js.map +1 -1
  62. package/dist/connect/wizard/prop_mapping.d.ts +12 -7
  63. package/dist/connect/wizard/prop_mapping.d.ts.map +1 -1
  64. package/dist/connect/wizard/prop_mapping.js +88 -89
  65. package/dist/connect/wizard/prop_mapping.js.map +1 -1
  66. package/dist/connect/wizard/run_wizard.d.ts.map +1 -1
  67. package/dist/connect/wizard/run_wizard.js +8 -3
  68. package/dist/connect/wizard/run_wizard.js.map +1 -1
  69. package/dist/connect/wizard/signature_extraction.d.ts +7 -0
  70. package/dist/connect/wizard/signature_extraction.d.ts.map +1 -0
  71. package/dist/connect/wizard/signature_extraction.js +46 -0
  72. package/dist/connect/wizard/signature_extraction.js.map +1 -0
  73. package/dist/html/__test__/parser/examples/NoConfigObject.figma.d.ts +2 -0
  74. package/dist/html/__test__/parser/examples/NoConfigObject.figma.d.ts.map +1 -0
  75. package/dist/html/__test__/parser/examples/NoConfigObject.figma.js +9 -0
  76. package/dist/html/__test__/parser/examples/NoConfigObject.figma.js.map +1 -0
  77. package/dist/html/__test__/parser/examples/NoExample.figma.d.ts +2 -0
  78. package/dist/html/__test__/parser/examples/NoExample.figma.d.ts.map +1 -0
  79. package/dist/html/__test__/parser/examples/NoExample.figma.js +9 -0
  80. package/dist/html/__test__/parser/examples/NoExample.figma.js.map +1 -0
  81. package/dist/html/__test__/parser/examples/RegularFunctionExampleWithExtraCode.figma.d.ts +2 -0
  82. package/dist/html/__test__/parser/examples/RegularFunctionExampleWithExtraCode.figma.d.ts.map +1 -0
  83. package/dist/html/__test__/parser/examples/RegularFunctionExampleWithExtraCode.figma.js +33 -0
  84. package/dist/html/__test__/parser/examples/RegularFunctionExampleWithExtraCode.figma.js.map +1 -0
  85. package/dist/html/__test__/parser/examples/WrongSignatureJsx.figma.d.ts +2 -0
  86. package/dist/html/__test__/parser/examples/WrongSignatureJsx.figma.d.ts.map +1 -0
  87. package/dist/html/__test__/parser/examples/WrongSignatureJsx.figma.js +15 -0
  88. package/dist/html/__test__/parser/examples/WrongSignatureJsx.figma.js.map +1 -0
  89. package/dist/html/__test__/parser/examples/WrongSignatureNoHtmlTag.figma.d.ts +2 -0
  90. package/dist/html/__test__/parser/examples/WrongSignatureNoHtmlTag.figma.d.ts.map +1 -0
  91. package/dist/html/__test__/parser/examples/WrongSignatureNoHtmlTag.figma.js +15 -0
  92. package/dist/html/__test__/parser/examples/WrongSignatureNoHtmlTag.figma.js.map +1 -0
  93. package/dist/html/__test__/parser/parser.test.d.ts +2 -0
  94. package/dist/html/__test__/parser/parser.test.d.ts.map +1 -0
  95. package/dist/html/__test__/parser/parser.test.js +50 -0
  96. package/dist/html/__test__/parser/parser.test.js.map +1 -0
  97. package/dist/html/create.d.ts +4 -0
  98. package/dist/html/create.d.ts.map +1 -0
  99. package/dist/html/create.js +81 -0
  100. package/dist/html/create.js.map +1 -0
  101. package/dist/html/external.d.ts +8 -0
  102. package/dist/html/external.d.ts.map +1 -0
  103. package/dist/html/external.js +25 -0
  104. package/dist/html/external.js.map +1 -0
  105. package/dist/html/index_html.d.ts +77 -0
  106. package/dist/html/index_html.d.ts.map +1 -0
  107. package/dist/html/index_html.js +42 -0
  108. package/dist/html/index_html.js.map +1 -0
  109. package/dist/html/parser.d.ts +19 -0
  110. package/dist/html/parser.d.ts.map +1 -0
  111. package/dist/html/parser.js +487 -0
  112. package/dist/html/parser.js.map +1 -0
  113. package/dist/html/parser_template_helpers.d.ts +2 -0
  114. package/dist/html/parser_template_helpers.d.ts.map +1 -0
  115. package/dist/html/parser_template_helpers.js +68 -0
  116. package/dist/html/parser_template_helpers.js.map +1 -0
  117. package/dist/html/template_literal.d.ts +5 -0
  118. package/dist/html/template_literal.d.ts.map +1 -0
  119. package/dist/html/template_literal.js +8 -0
  120. package/dist/html/template_literal.js.map +1 -0
  121. package/dist/parser_scripts/get_swift_parser_dir.d.ts +1 -1
  122. package/dist/parser_scripts/get_swift_parser_dir.d.ts.map +1 -1
  123. package/dist/parser_scripts/get_swift_parser_dir.js +38 -10
  124. package/dist/parser_scripts/get_swift_parser_dir.js.map +1 -1
  125. package/dist/react/create.d.ts +5 -0
  126. package/dist/react/create.d.ts.map +1 -1
  127. package/dist/react/create.js +144 -42
  128. package/dist/react/create.js.map +1 -1
  129. package/dist/react/external.d.ts +9 -0
  130. package/dist/react/external.d.ts.map +1 -0
  131. package/dist/react/external.js +45 -0
  132. package/dist/react/external.js.map +1 -0
  133. package/dist/react/index_react.d.ts +94 -0
  134. package/dist/react/index_react.d.ts.map +1 -0
  135. package/dist/react/index_react.js +39 -0
  136. package/dist/react/index_react.js.map +1 -0
  137. package/dist/react/parser.d.ts +6 -38
  138. package/dist/react/parser.d.ts.map +1 -1
  139. package/dist/react/parser.js +141 -298
  140. package/dist/react/parser.js.map +1 -1
  141. package/dist/react/parser_template_helpers.d.ts +15 -15
  142. package/dist/react/parser_template_helpers.d.ts.map +1 -1
  143. package/dist/react/parser_template_helpers.js +51 -35
  144. package/dist/react/parser_template_helpers.js.map +1 -1
  145. package/dist/storybook/convert.d.ts +1 -1
  146. package/dist/storybook/convert.d.ts.map +1 -1
  147. package/dist/storybook/convert.js +6 -4
  148. package/dist/storybook/convert.js.map +1 -1
  149. package/dist/storybook/external.d.ts +1 -1
  150. package/dist/storybook/external.d.ts.map +1 -1
  151. package/dist/typescript/compiler.d.ts +2 -2
  152. package/dist/typescript/compiler.d.ts.map +1 -1
  153. package/dist/typescript/compiler.js +51 -24
  154. package/dist/typescript/compiler.js.map +1 -1
  155. package/package.json +28 -8
@@ -0,0 +1,50 @@
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
+ const typescript_1 = __importDefault(require("typescript"));
7
+ const path_1 = __importDefault(require("path"));
8
+ const parser_common_1 = require("../../../connect/parser_common");
9
+ const parser_1 = require("../../parser");
10
+ async function testParse(file, extraFiles = [], config) {
11
+ const program = typescript_1.default.createProgram([
12
+ path_1.default.join(__dirname, 'examples', file),
13
+ ...extraFiles.map((file) => path_1.default.join(__dirname, file)),
14
+ ], {});
15
+ return await (0, parser_common_1.parseCodeConnect)({
16
+ program,
17
+ file: path_1.default.join(__dirname, 'examples', file),
18
+ config: { ...config, parser: 'html' },
19
+ parseFn: parser_1.parseHtmlDoc,
20
+ absPath: __dirname,
21
+ parseOptions: {
22
+ repoUrl: 'git@github.com:figma/code-connect.git',
23
+ debug: false,
24
+ },
25
+ });
26
+ }
27
+ describe('HTML Parser', () => {
28
+ it('throws an error if there is no config object', async () => {
29
+ expect(async () => await testParse('NoConfigObject.figma.ts')).rejects.toThrow(`The second argument to figma.connect() must be an object literal. Example usage:
30
+ \`figma.connect('https://www.figma.com/file/123?node-id=1-1', {
31
+ example: () => html\`<button />\`
32
+ })\``);
33
+ });
34
+ it('throws an error if there is no example', async () => {
35
+ expect(async () => await testParse('NoExample.figma.ts')).rejects.toThrow(`The 'example' property must be an arrow function which returns a html tagged template string. Example usage:
36
+ \`figma.connect('https://www.figma.com/file/123?node-id=1-1', {
37
+ example: (props) => html\`<my-button />\`
38
+ })\``);
39
+ });
40
+ it('throws an error if the example function returns a plain tagged template', async () => {
41
+ expect(async () => await testParse('WrongSignatureNoHtmlTag.figma.ts')).rejects.toThrow('Expected only a tagged template literal as the body of the render function');
42
+ });
43
+ it('throws an error if the example function returns JSX', async () => {
44
+ expect(async () => await testParse('WrongSignatureJsx.figma.tsx')).rejects.toThrow('Expected only a tagged template literal as the body of the render function');
45
+ });
46
+ it('throws an error if the example function is a regular function with extra code', async () => {
47
+ expect(async () => await testParse('RegularFunctionExampleWithExtraCode.figma.ts')).rejects.toThrow('Expected only a tagged template literal as the body of the render function');
48
+ });
49
+ });
50
+ //# sourceMappingURL=parser.test.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.test.js","sourceRoot":"","sources":["../../../../src/html/__test__/parser/parser.test.ts"],"names":[],"mappings":";;;;;AACA,4DAA2B;AAC3B,gDAAuB;AACvB,kEAAiE;AACjE,yCAA2C;AAE3C,KAAK,UAAU,SAAS,CACtB,IAAY,EACZ,aAAuB,EAAE,EACzB,MAA8C;IAE9C,MAAM,OAAO,GAAG,oBAAE,CAAC,aAAa,CAC9B;QACE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC;QACtC,GAAG,UAAU,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,IAAI,CAAC,CAAC;KACxD,EACD,EAAE,CACH,CAAA;IACD,OAAO,MAAM,IAAA,gCAAgB,EAAC;QAC5B,OAAO;QACP,IAAI,EAAE,cAAI,CAAC,IAAI,CAAC,SAAS,EAAE,UAAU,EAAE,IAAI,CAAC;QAC5C,MAAM,EAAE,EAAE,GAAG,MAAM,EAAE,MAA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CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -0,0 +1,4 @@
1
+ import { z } from 'zod';
2
+ import { CreateRequestPayload, CreateResponsePayload } from '../connect/parser_executable_types';
3
+ export declare function createHtmlCodeConnect(payload: CreateRequestPayload): Promise<z.infer<typeof CreateResponsePayload>>;
4
+ //# sourceMappingURL=create.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../src/html/create.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AACvB,OAAO,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,oCAAoC,CAAA;AAQhG,wBAAsB,qBAAqB,CACzC,OAAO,EAAE,oBAAoB,GAC5B,OAAO,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,CAAC,CAkDhD"}
@@ -0,0 +1,81 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.createHtmlCodeConnect = void 0;
30
+ const path_1 = __importDefault(require("path"));
31
+ const fs_1 = __importDefault(require("fs"));
32
+ const create_1 = require("../react/create");
33
+ const prettier = __importStar(require("prettier"));
34
+ const lodash_1 = require("lodash");
35
+ const create_common_1 = require("../connect/create_common");
36
+ async function createHtmlCodeConnect(payload) {
37
+ const { component, destinationFile, destinationDir, sourceFilepath, sourceExport } = payload;
38
+ const { normalizedName, figmaNodeUrl } = component;
39
+ const webComponentName = (0, lodash_1.kebabCase)(normalizedName);
40
+ const sourceFilename = sourceFilepath
41
+ ? path_1.default.parse(sourceFilepath).name.split('.')[0]
42
+ : webComponentName;
43
+ const filePath = (0, create_common_1.getOutFileName)({
44
+ outFile: destinationFile,
45
+ outDir: destinationDir,
46
+ sourceFilename,
47
+ extension: 'ts',
48
+ });
49
+ const codeConnect = `
50
+ import figma, { html } from '@figma/code-connect/html'
51
+
52
+ /**
53
+ * -- This file was auto-generated by \`figma connect create\` --
54
+ * \`props\` includes a mapping from Figma properties and variants to
55
+ * suggested values. You should update this to match the props of your
56
+ * code component, and update the \`example\` function to return the
57
+ * code example you'd like to see in Figma
58
+ */
59
+
60
+ figma.connect("${figmaNodeUrl}", {
61
+ props: ${(0, create_1.generateProps)(component)},
62
+ example: (props) => html\`<${webComponentName} />\`
63
+ })
64
+ `;
65
+ let formatted = prettier.format(codeConnect, {
66
+ parser: 'typescript',
67
+ semi: false,
68
+ trailingComma: 'all',
69
+ });
70
+ if (fs_1.default.existsSync(filePath)) {
71
+ return {
72
+ createdFiles: [],
73
+ messages: [{ message: `File ${filePath} already exists, skipping creation`, level: 'ERROR' }],
74
+ };
75
+ }
76
+ fs_1.default.mkdirSync(path_1.default.dirname(filePath), { recursive: true });
77
+ fs_1.default.writeFileSync(filePath, formatted);
78
+ return { createdFiles: [{ filePath }], messages: [] };
79
+ }
80
+ exports.createHtmlCodeConnect = createHtmlCodeConnect;
81
+ //# sourceMappingURL=create.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"create.js","sourceRoot":"","sources":["../../src/html/create.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAEA,gDAAuB;AACvB,4CAAmB;AACnB,4CAA+C;AAC/C,mDAAoC;AACpC,mCAAkC;AAClC,4DAAyD;AAElD,KAAK,UAAU,qBAAqB,CACzC,OAA6B;IAE7B,MAAM,EAAE,SAAS,EAAE,eAAe,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,GAAG,OAAO,CAAA;IAC5F,MAAM,EAAE,cAAc,EAAE,YAAY,EAAE,GAAG,SAAS,CAAA;IAElD,MAAM,gBAAgB,GAAG,IAAA,kBAAS,EAAC,cAAc,CAAC,CAAA;IAElD,MAAM,cAAc,GAAG,cAAc;QACnC,CAAC,CAAC,cAAI,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;QAC/C,CAAC,CAAC,gBAAgB,CAAA;IAEpB,MAAM,QAAQ,GAAG,IAAA,8BAAc,EAAC;QAC9B,OAAO,EAAE,eAAe;QACxB,MAAM,EAAE,cAAc;QACtB,cAAc;QACd,SAAS,EAAE,IAAI;KAChB,CAAC,CAAA;IAEF,MAAM,WAAW,GAAG;;;;;;;;;;;iBAWL,YAAY;WAClB,IAAA,sBAAa,EAAC,SAAS,CAAC;+BACJ,gBAAgB;;CAE9C,CAAA;IAEC,IAAI,SAAS,GAAG,QAAQ,CAAC,MAAM,CAAC,WAAW,EAAE;QAC3C,MAAM,EAAE,YAAY;QACpB,IAAI,EAAE,KAAK;QACX,aAAa,EAAE,KAAK;KACrB,CAAC,CAAA;IAEF,IAAI,YAAE,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,CAAC;QAC5B,OAAO;YACL,YAAY,EAAE,EAAE;YAChB,QAAQ,EAAE,CAAC,EAAE,OAAO,EAAE,QAAQ,QAAQ,oCAAoC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;SAC9F,CAAA;IACH,CAAC;IACD,YAAE,CAAC,SAAS,CAAC,cAAI,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,CAAA;IACzD,YAAE,CAAC,aAAa,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAA;IAErC,OAAO,EAAE,YAAY,EAAE,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAA;AACvD,CAAC;AApDD,sDAoDC"}
@@ -0,0 +1,8 @@
1
+ import { FigmaConnectMeta } from '../connect/api';
2
+ import { booleanType, enumType, stringType, nestedPropsType, classNameType, textContentType } from '../connect/external_types';
3
+ import { HtmlTemplateString } from './template_literal';
4
+ declare function connectType<P = {}>(_figmaNodeUrl: string, _meta?: FigmaConnectMeta<P, HtmlTemplateString>): void;
5
+ declare function instanceType(_figmaPropName: string): HtmlTemplateString;
6
+ declare function childrenType(_layers: string | string[]): HtmlTemplateString;
7
+ export { booleanType as boolean, enumType as enum, stringType as string, nestedPropsType as nestedProps, classNameType as className, textContentType as textContent, connectType as connect, instanceType as instance, childrenType as children, };
8
+ //# sourceMappingURL=external.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external.d.ts","sourceRoot":"","sources":["../../src/html/external.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAA;AACjD,OAAO,EACL,WAAW,EACX,QAAQ,EACR,UAAU,EACV,eAAe,EACf,aAAa,EACb,eAAe,EAChB,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAA;AAEvD,iBAAS,WAAW,CAAC,CAAC,GAAG,EAAE,EACzB,aAAa,EAAE,MAAM,EACrB,KAAK,CAAC,EAAE,gBAAgB,CAAC,CAAC,EAAE,kBAAkB,CAAC,GAC9C,IAAI,CAAG;AAEV,iBAAS,YAAY,CAAC,cAAc,EAAE,MAAM,GAAG,kBAAkB,CAIhE;AAED,iBAAS,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,EAAE,GAAG,kBAAkB,CAIpE;AAED,OAAO,EACL,WAAW,IAAI,OAAO,EACtB,QAAQ,IAAI,IAAI,EAChB,UAAU,IAAI,MAAM,EACpB,eAAe,IAAI,WAAW,EAC9B,aAAa,IAAI,SAAS,EAC1B,eAAe,IAAI,WAAW,EAC9B,WAAW,IAAI,OAAO,EACtB,YAAY,IAAI,QAAQ,EACxB,YAAY,IAAI,QAAQ,GACzB,CAAA"}
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.children = exports.instance = exports.connect = exports.textContent = exports.className = exports.nestedProps = exports.string = exports.enum = exports.boolean = void 0;
4
+ const external_types_1 = require("../connect/external_types");
5
+ Object.defineProperty(exports, "boolean", { enumerable: true, get: function () { return external_types_1.booleanType; } });
6
+ Object.defineProperty(exports, "enum", { enumerable: true, get: function () { return external_types_1.enumType; } });
7
+ Object.defineProperty(exports, "string", { enumerable: true, get: function () { return external_types_1.stringType; } });
8
+ Object.defineProperty(exports, "nestedProps", { enumerable: true, get: function () { return external_types_1.nestedPropsType; } });
9
+ Object.defineProperty(exports, "className", { enumerable: true, get: function () { return external_types_1.classNameType; } });
10
+ Object.defineProperty(exports, "textContent", { enumerable: true, get: function () { return external_types_1.textContentType; } });
11
+ function connectType(_figmaNodeUrl, _meta) { }
12
+ exports.connect = connectType;
13
+ function instanceType(_figmaPropName) {
14
+ return {
15
+ __tag: 'HtmlTemplateString',
16
+ };
17
+ }
18
+ exports.instance = instanceType;
19
+ function childrenType(_layers) {
20
+ return {
21
+ __tag: 'HtmlTemplateString',
22
+ };
23
+ }
24
+ exports.children = childrenType;
25
+ //# sourceMappingURL=external.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"external.js","sourceRoot":"","sources":["../../src/html/external.ts"],"names":[],"mappings":";;;AACA,8DAOkC;AAqBjB,wFA3Bf,4BAAW,OA2BW;AACV,qFA3BZ,yBAAQ,OA2BQ;AACF,uFA3Bd,2BAAU,OA2BU;AACD,4FA3BnB,gCAAe,OA2Be;AACb,0FA3BjB,8BAAa,OA2Ba;AACP,4FA3BnB,gCAAe,OA2Be;AAvBhC,SAAS,WAAW,CAClB,aAAqB,EACrB,KAA+C,IACxC,CAAC;AAqBO,8BAAO;AAnBxB,SAAS,YAAY,CAAC,cAAsB;IAC1C,OAAO;QACL,KAAK,EAAE,oBAAoB;KAC5B,CAAA;AACH,CAAC;AAgBiB,gCAAQ;AAd1B,SAAS,YAAY,CAAC,OAA0B;IAC9C,OAAO;QACL,KAAK,EAAE,oBAAoB;KAC5B,CAAA;AACH,CAAC;AAWiB,gCAAQ"}
@@ -0,0 +1,77 @@
1
+ import { EnumValue, FigmaConnectAPI, FigmaConnectMeta, ValueOf } from '../connect/api';
2
+ import { FigmaConnectClient } from '../client/figma_client';
3
+ import { html, HtmlTemplateString } from './template_literal';
4
+ declare const _client: FigmaConnectClient;
5
+ declare const _figma: FigmaConnectAPI<HtmlTemplateString> & {
6
+ /**
7
+ * Defines a code snippet that displays in Figma when a component is selected.
8
+ *
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 = {}>(figmaNodeUrl: string, meta: Required<Pick<FigmaConnectMeta<P, HtmlTemplateString>, 'example'>> & FigmaConnectMeta<P, HtmlTemplateString>): 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
28
+ * component, providing a value mapping for `true` and `false`. This prop is
29
+ * replaced with values from the Figma instance when viewed in Dev Mode.
30
+ * Example:
31
+ * ```ts
32
+ * props: {
33
+ * label: figma.boolean('Disabled', {
34
+ * true: <my-label></my-label>,
35
+ * false: <my-disabled-label></my-disabled-label>,
36
+ * }),
37
+ * }
38
+ * ```
39
+ * Would replace `label` with `<my-label></my-label>` if the Figma property
40
+ * "Disabled" is true.
41
+ *
42
+ * @param figmaPropName The name of the property on the Figma component
43
+ * @param valueMapping A mapping of values for `true` and `false`
44
+ */
45
+ boolean<TrueT extends EnumValue, FalseT extends EnumValue>(figmaPropName: string, valueMapping?: {
46
+ true?: TrueT;
47
+ false?: FalseT;
48
+ }): ValueOf<Record<'true' | 'false', TrueT | FalseT>>;
49
+ /**
50
+ * Maps nested properties from a Figma instance layer. The first argument
51
+ * should be the layer name of the nested instance. The mapping object passed
52
+ * in is in the same format as the `props` object in the `connect` function.
53
+ * For example:
54
+ * ```ts
55
+ * props: {
56
+ * nested: figma.nestedProps('Nested', {
57
+ * label: figma.string('Text'),
58
+ * icon: figma.instance('Icon'),
59
+ * }),
60
+ * }
61
+ * ```
62
+ *
63
+ * Which would then allow you to access the nested properties in the `example` function like so:
64
+ * ```ts
65
+ * (props) => html`<my-button label=${props.nested.label}>${props.nested.icon}</my-button>`
66
+ * ```
67
+ */
68
+ nestedProps<V>(layer: string, input: V): V;
69
+ /**
70
+ * A list of import statements that will render in the Code Snippet in Figma.
71
+ */
72
+ imports?: string[];
73
+ };
74
+ declare const _html: typeof html;
75
+ export { _figma as figma, _client as client, _html as html };
76
+ export default _figma;
77
+ //# sourceMappingURL=index_html.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index_html.d.ts","sourceRoot":"","sources":["../../src/html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AAK,EAAE,OAAO,IAAI,MAAM,EAAE,KAAK,IAAI,IAAI,EAAE,CAAA;AAC5D,eAAe,MAAM,CAAA"}
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ // IMPORTANT: be careful to ensure you don't accidentally add code which has a
3
+ // dependency on Node.js-only modules here, as it will break co-located
4
+ // components. We don't have a test for this yet. Any such code should be
5
+ // conditionally required - see `client` for an example. Reach out in
6
+ // #feat-code-connect if you're unsure.
7
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
8
+ if (k2 === undefined) k2 = k;
9
+ var desc = Object.getOwnPropertyDescriptor(m, k);
10
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
11
+ desc = { enumerable: true, get: function() { return m[k]; } };
12
+ }
13
+ Object.defineProperty(o, k2, desc);
14
+ }) : (function(o, m, k, k2) {
15
+ if (k2 === undefined) k2 = k;
16
+ o[k2] = m[k];
17
+ }));
18
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
19
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
20
+ }) : function(o, v) {
21
+ o["default"] = v;
22
+ });
23
+ var __importStar = (this && this.__importStar) || function (mod) {
24
+ if (mod && mod.__esModule) return mod;
25
+ var result = {};
26
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
27
+ __setModuleDefault(result, mod);
28
+ return result;
29
+ };
30
+ Object.defineProperty(exports, "__esModule", { value: true });
31
+ exports.html = exports.client = exports.figma = void 0;
32
+ const figma = __importStar(require("./external"));
33
+ const template_literal_1 = require("./template_literal");
34
+ const index_common_1 = require("../connect/index_common");
35
+ const _client = (0, index_common_1.getClient)();
36
+ exports.client = _client;
37
+ const _figma = figma;
38
+ exports.figma = _figma;
39
+ const _html = template_literal_1.html;
40
+ exports.html = _html;
41
+ exports.default = _figma;
42
+ //# sourceMappingURL=index_html.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index_html.js","sourceRoot":"","sources":["../../src/html/index_html.ts"],"names":[],"mappings":";AAAA,8EAA8E;AAC9E,uEAAuE;AACvE,yEAAyE;AACzE,qEAAqE;AACrE,uCAAuC;;;;;;;;;;;;;;;;;;;;;;;;;;AAGvC,kDAAmC;AAEnC,yDAA6D;AAC7D,0DAAmD;AAEnD,MAAM,OAAO,GAAuB,IAAA,wBAAS,GAAE,CAAA;AAmFV,yBAAM;AAlF3C,MAAM,MAAM,GA+ER,KAAK,CAAA;AAGU,uBAAK;AAFxB,MAAM,KAAK,GAAG,uBAAI,CAAA;AAEoC,qBAAI;AAC1D,kBAAe,MAAM,CAAA"}
@@ -0,0 +1,19 @@
1
+ import ts from 'typescript';
2
+ import { PropMappings } from '../connect/intrinsics';
3
+ import { CodeConnectJSON } from '../connect/figma_connect';
4
+ import { ParserContext, ParseOptions } from '../connect/parser_common';
5
+ /**
6
+ * Parses the example template string passed to `figma.connect()`.
7
+ *
8
+ * @param exp A function or arrow function expression
9
+ * @param parserContext Parser context
10
+ * @param propMappings Prop mappings object as returned by parseProps
11
+ *
12
+ * @returns The code of the render function and a list of imports
13
+ */
14
+ export declare function parseExampleTemplate(exp: ts.ArrowFunction, parserContext: ParserContext, propMappings?: PropMappings): {
15
+ code: string;
16
+ nestable: boolean;
17
+ };
18
+ export declare function parseHtmlDoc(node: ts.CallExpression, parserContext: ParserContext, { repoUrl, silent }: ParseOptions): Promise<CodeConnectJSON>;
19
+ //# sourceMappingURL=parser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"parser.d.ts","sourceRoot":"","sources":["../../src/html/parser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAwC,MAAM,YAAY,CAAA;AAOjE,OAAO,EAAsB,YAAY,EAAoB,MAAM,uBAAuB,CAAA;AAC1F,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAA;AAI1D,OAAO,EAEL,aAAa,EAOb,YAAY,EACb,MAAM,0BAA0B,CAAA;AAyKjC;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,EAAE,CAAC,aAAa,EACrB,aAAa,EAAE,aAAa,EAC5B,YAAY,CAAC,EAAE,YAAY;;;EA4L5B;AAiID,wBAAsB,YAAY,CAChC,IAAI,EAAE,EAAE,CAAC,cAAc,EACvB,aAAa,EAAE,aAAa,EAC5B,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,YAAY,GAChC,OAAO,CAAC,eAAe,CAAC,CA6D1B"}