@embeddables/cli 0.7.13 → 0.7.15

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 (236) hide show
  1. package/.prompts/custom/build-funnel.md +1 -1
  2. package/.prompts/embeddables-cli.md +9 -2
  3. package/package.json +1 -1
  4. package/dist/auth/index.d.ts +0 -43
  5. package/dist/auth/index.d.ts.map +0 -1
  6. package/dist/auth/index.js +0 -102
  7. package/dist/cli.d.ts +0 -2
  8. package/dist/cli.d.ts.map +0 -1
  9. package/dist/cli.js +0 -174
  10. package/dist/commands/branch.d.ts +0 -4
  11. package/dist/commands/branch.d.ts.map +0 -1
  12. package/dist/commands/branch.js +0 -68
  13. package/dist/commands/build-workbench.d.ts +0 -5
  14. package/dist/commands/build-workbench.d.ts.map +0 -1
  15. package/dist/commands/build-workbench.js +0 -128
  16. package/dist/commands/build.d.ts +0 -8
  17. package/dist/commands/build.d.ts.map +0 -1
  18. package/dist/commands/build.js +0 -55
  19. package/dist/commands/dev.d.ts +0 -12
  20. package/dist/commands/dev.d.ts.map +0 -1
  21. package/dist/commands/dev.js +0 -221
  22. package/dist/commands/experiments-connect.d.ts +0 -6
  23. package/dist/commands/experiments-connect.d.ts.map +0 -1
  24. package/dist/commands/experiments-connect.js +0 -140
  25. package/dist/commands/init.d.ts +0 -5
  26. package/dist/commands/init.d.ts.map +0 -1
  27. package/dist/commands/init.js +0 -327
  28. package/dist/commands/login.d.ts +0 -2
  29. package/dist/commands/login.d.ts.map +0 -1
  30. package/dist/commands/login.js +0 -122
  31. package/dist/commands/logout.d.ts +0 -2
  32. package/dist/commands/logout.d.ts.map +0 -1
  33. package/dist/commands/logout.js +0 -22
  34. package/dist/commands/pull.d.ts +0 -14
  35. package/dist/commands/pull.d.ts.map +0 -1
  36. package/dist/commands/pull.js +0 -383
  37. package/dist/commands/save.d.ts +0 -30
  38. package/dist/commands/save.d.ts.map +0 -1
  39. package/dist/commands/save.js +0 -591
  40. package/dist/commands/upgrade.d.ts +0 -2
  41. package/dist/commands/upgrade.d.ts.map +0 -1
  42. package/dist/commands/upgrade.js +0 -51
  43. package/dist/compiler/errors.d.ts +0 -20
  44. package/dist/compiler/errors.d.ts.map +0 -1
  45. package/dist/compiler/errors.js +0 -35
  46. package/dist/compiler/evalStatic.d.ts +0 -3
  47. package/dist/compiler/evalStatic.d.ts.map +0 -1
  48. package/dist/compiler/evalStatic.js +0 -57
  49. package/dist/compiler/flatten.js +0 -1
  50. package/dist/compiler/helpers/duplicateIds.d.ts +0 -9
  51. package/dist/compiler/helpers/duplicateIds.d.ts.map +0 -1
  52. package/dist/compiler/helpers/duplicateIds.js +0 -71
  53. package/dist/compiler/helpers/numericLeadingKeys.d.ts +0 -8
  54. package/dist/compiler/helpers/numericLeadingKeys.d.ts.map +0 -1
  55. package/dist/compiler/helpers/numericLeadingKeys.js +0 -17
  56. package/dist/compiler/index.d.ts +0 -18
  57. package/dist/compiler/index.d.ts.map +0 -1
  58. package/dist/compiler/index.js +0 -1245
  59. package/dist/compiler/parsePage.d.ts +0 -15
  60. package/dist/compiler/parsePage.d.ts.map +0 -1
  61. package/dist/compiler/parsePage.js +0 -631
  62. package/dist/compiler/registry.d.ts +0 -4
  63. package/dist/compiler/registry.d.ts.map +0 -1
  64. package/dist/compiler/registry.js +0 -44
  65. package/dist/compiler/reverse.d.ts +0 -23
  66. package/dist/compiler/reverse.d.ts.map +0 -1
  67. package/dist/compiler/reverse.js +0 -1875
  68. package/dist/compiler/types.d.ts +0 -21
  69. package/dist/compiler/types.d.ts.map +0 -1
  70. package/dist/compiler/types.js +0 -1
  71. package/dist/components/index.d.ts +0 -21
  72. package/dist/components/index.d.ts.map +0 -1
  73. package/dist/components/index.js +0 -21
  74. package/dist/components/primitives/BaseComponent.d.ts +0 -32
  75. package/dist/components/primitives/BaseComponent.d.ts.map +0 -1
  76. package/dist/components/primitives/BaseComponent.js +0 -26
  77. package/dist/components/primitives/BookMeeting.d.ts +0 -18
  78. package/dist/components/primitives/BookMeeting.d.ts.map +0 -1
  79. package/dist/components/primitives/BookMeeting.js +0 -5
  80. package/dist/components/primitives/Chart.d.ts +0 -41
  81. package/dist/components/primitives/Chart.d.ts.map +0 -1
  82. package/dist/components/primitives/Chart.js +0 -5
  83. package/dist/components/primitives/Container.d.ts +0 -8
  84. package/dist/components/primitives/Container.d.ts.map +0 -1
  85. package/dist/components/primitives/Container.js +0 -5
  86. package/dist/components/primitives/CustomButton.d.ts +0 -37
  87. package/dist/components/primitives/CustomButton.d.ts.map +0 -1
  88. package/dist/components/primitives/CustomButton.js +0 -10
  89. package/dist/components/primitives/CustomHTML.d.ts +0 -8
  90. package/dist/components/primitives/CustomHTML.d.ts.map +0 -1
  91. package/dist/components/primitives/CustomHTML.js +0 -5
  92. package/dist/components/primitives/FileUpload.d.ts +0 -18
  93. package/dist/components/primitives/FileUpload.d.ts.map +0 -1
  94. package/dist/components/primitives/FileUpload.js +0 -16
  95. package/dist/components/primitives/InputBox.d.ts +0 -34
  96. package/dist/components/primitives/InputBox.d.ts.map +0 -1
  97. package/dist/components/primitives/InputBox.js +0 -25
  98. package/dist/components/primitives/Lottie.d.ts +0 -11
  99. package/dist/components/primitives/Lottie.d.ts.map +0 -1
  100. package/dist/components/primitives/Lottie.js +0 -5
  101. package/dist/components/primitives/MediaEmbed.d.ts +0 -13
  102. package/dist/components/primitives/MediaEmbed.d.ts.map +0 -1
  103. package/dist/components/primitives/MediaEmbed.js +0 -6
  104. package/dist/components/primitives/MediaImage.d.ts +0 -8
  105. package/dist/components/primitives/MediaImage.d.ts.map +0 -1
  106. package/dist/components/primitives/MediaImage.js +0 -5
  107. package/dist/components/primitives/OptionSelector.d.ts +0 -35
  108. package/dist/components/primitives/OptionSelector.d.ts.map +0 -1
  109. package/dist/components/primitives/OptionSelector.js +0 -8
  110. package/dist/components/primitives/PaypalCheckout.d.ts +0 -25
  111. package/dist/components/primitives/PaypalCheckout.d.ts.map +0 -1
  112. package/dist/components/primitives/PaypalCheckout.js +0 -5
  113. package/dist/components/primitives/PlainText.d.ts +0 -6
  114. package/dist/components/primitives/PlainText.d.ts.map +0 -1
  115. package/dist/components/primitives/PlainText.js +0 -5
  116. package/dist/components/primitives/ProgressBar.d.ts +0 -15
  117. package/dist/components/primitives/ProgressBar.d.ts.map +0 -1
  118. package/dist/components/primitives/ProgressBar.js +0 -5
  119. package/dist/components/primitives/RichText.d.ts +0 -6
  120. package/dist/components/primitives/RichText.d.ts.map +0 -1
  121. package/dist/components/primitives/RichText.js +0 -5
  122. package/dist/components/primitives/RichTextMarkdown.d.ts +0 -6
  123. package/dist/components/primitives/RichTextMarkdown.d.ts.map +0 -1
  124. package/dist/components/primitives/RichTextMarkdown.js +0 -5
  125. package/dist/components/primitives/Rive.d.ts +0 -16
  126. package/dist/components/primitives/Rive.d.ts.map +0 -1
  127. package/dist/components/primitives/Rive.js +0 -8
  128. package/dist/components/primitives/StripeCheckout.d.ts +0 -52
  129. package/dist/components/primitives/StripeCheckout.d.ts.map +0 -1
  130. package/dist/components/primitives/StripeCheckout.js +0 -5
  131. package/dist/components/primitives/StripeCheckout2.d.ts +0 -30
  132. package/dist/components/primitives/StripeCheckout2.d.ts.map +0 -1
  133. package/dist/components/primitives/StripeCheckout2.js +0 -7
  134. package/dist/config/index.d.ts +0 -23
  135. package/dist/config/index.d.ts.map +0 -1
  136. package/dist/config/index.js +0 -42
  137. package/dist/constants.d.ts +0 -9
  138. package/dist/constants.d.ts.map +0 -1
  139. package/dist/constants.js +0 -9
  140. package/dist/helpers/TEMP helpers file.d.ts +0 -1
  141. package/dist/helpers/TEMP helpers file.d.ts.map +0 -1
  142. package/dist/helpers/TEMP helpers file.js +0 -1
  143. package/dist/helpers/dates.d.ts +0 -5
  144. package/dist/helpers/dates.d.ts.map +0 -1
  145. package/dist/helpers/dates.js +0 -7
  146. package/dist/helpers/json.d.ts +0 -47
  147. package/dist/helpers/json.d.ts.map +0 -1
  148. package/dist/helpers/json.js +0 -622
  149. package/dist/helpers/utils.d.ts +0 -13
  150. package/dist/helpers/utils.d.ts.map +0 -1
  151. package/dist/helpers/utils.js +0 -28
  152. package/dist/logger.d.ts +0 -11
  153. package/dist/logger.d.ts.map +0 -1
  154. package/dist/logger.js +0 -21
  155. package/dist/prompts/branches.d.ts +0 -20
  156. package/dist/prompts/branches.d.ts.map +0 -1
  157. package/dist/prompts/branches.js +0 -90
  158. package/dist/prompts/embeddables.d.ts +0 -43
  159. package/dist/prompts/embeddables.d.ts.map +0 -1
  160. package/dist/prompts/embeddables.js +0 -198
  161. package/dist/prompts/experiments.d.ts +0 -28
  162. package/dist/prompts/experiments.d.ts.map +0 -1
  163. package/dist/prompts/experiments.js +0 -87
  164. package/dist/prompts/index.d.ts +0 -11
  165. package/dist/prompts/index.d.ts.map +0 -1
  166. package/dist/prompts/index.js +0 -6
  167. package/dist/prompts/projects.d.ts +0 -22
  168. package/dist/prompts/projects.d.ts.map +0 -1
  169. package/dist/prompts/projects.js +0 -86
  170. package/dist/prompts/versions.d.ts +0 -18
  171. package/dist/prompts/versions.d.ts.map +0 -1
  172. package/dist/prompts/versions.js +0 -99
  173. package/dist/proxy/injectApiInterceptor.d.ts +0 -6
  174. package/dist/proxy/injectApiInterceptor.d.ts.map +0 -1
  175. package/dist/proxy/injectApiInterceptor.js +0 -66
  176. package/dist/proxy/injectReload.d.ts +0 -2
  177. package/dist/proxy/injectReload.d.ts.map +0 -1
  178. package/dist/proxy/injectReload.js +0 -14
  179. package/dist/proxy/injectWorkbench.d.ts +0 -5
  180. package/dist/proxy/injectWorkbench.d.ts.map +0 -1
  181. package/dist/proxy/injectWorkbench.js +0 -22
  182. package/dist/proxy/server.d.ts +0 -11
  183. package/dist/proxy/server.d.ts.map +0 -1
  184. package/dist/proxy/server.js +0 -316
  185. package/dist/proxy/sse.d.ts +0 -5
  186. package/dist/proxy/sse.d.ts.map +0 -1
  187. package/dist/proxy/sse.js +0 -17
  188. package/dist/sentry-context.d.ts +0 -48
  189. package/dist/sentry-context.d.ts.map +0 -1
  190. package/dist/sentry-context.js +0 -156
  191. package/dist/stdout.d.ts +0 -17
  192. package/dist/stdout.d.ts.map +0 -1
  193. package/dist/stdout.js +0 -23
  194. package/dist/types-builder.d.ts +0 -800
  195. package/dist/types-builder.d.ts.map +0 -1
  196. package/dist/types-builder.js +0 -20
  197. package/dist/workbench/ActionsPanel.d.ts +0 -6
  198. package/dist/workbench/ActionsPanel.d.ts.map +0 -1
  199. package/dist/workbench/ActionsPanel.js +0 -47
  200. package/dist/workbench/AutofillPanel.d.ts +0 -6
  201. package/dist/workbench/AutofillPanel.d.ts.map +0 -1
  202. package/dist/workbench/AutofillPanel.js +0 -543
  203. package/dist/workbench/ComputedFieldsPanel.d.ts +0 -6
  204. package/dist/workbench/ComputedFieldsPanel.d.ts.map +0 -1
  205. package/dist/workbench/ComputedFieldsPanel.js +0 -31
  206. package/dist/workbench/ExperimentsPanel.d.ts +0 -6
  207. package/dist/workbench/ExperimentsPanel.d.ts.map +0 -1
  208. package/dist/workbench/ExperimentsPanel.js +0 -182
  209. package/dist/workbench/FieldEditorPanel.d.ts +0 -9
  210. package/dist/workbench/FieldEditorPanel.d.ts.map +0 -1
  211. package/dist/workbench/FieldEditorPanel.js +0 -650
  212. package/dist/workbench/InspectorPanel.d.ts +0 -6
  213. package/dist/workbench/InspectorPanel.d.ts.map +0 -1
  214. package/dist/workbench/InspectorPanel.js +0 -341
  215. package/dist/workbench/PageNavigator.d.ts +0 -6
  216. package/dist/workbench/PageNavigator.d.ts.map +0 -1
  217. package/dist/workbench/PageNavigator.js +0 -123
  218. package/dist/workbench/SchemaPanel.d.ts +0 -6
  219. package/dist/workbench/SchemaPanel.d.ts.map +0 -1
  220. package/dist/workbench/SchemaPanel.js +0 -222
  221. package/dist/workbench/UserDataPanel.d.ts +0 -6
  222. package/dist/workbench/UserDataPanel.d.ts.map +0 -1
  223. package/dist/workbench/UserDataPanel.js +0 -350
  224. package/dist/workbench/WorkbenchApp.d.ts +0 -7
  225. package/dist/workbench/WorkbenchApp.d.ts.map +0 -1
  226. package/dist/workbench/WorkbenchApp.js +0 -193
  227. package/dist/workbench/cloudflare-worker/README.md +0 -31
  228. package/dist/workbench/cloudflare-worker/public/workbench.css +0 -1614
  229. package/dist/workbench/cloudflare-worker/public/workbench.js +0 -77
  230. package/dist/workbench/cloudflare-worker/worker.js +0 -40
  231. package/dist/workbench/cloudflare-worker/wrangler.toml +0 -10
  232. package/dist/workbench/index.d.ts +0 -10
  233. package/dist/workbench/index.d.ts.map +0 -1
  234. package/dist/workbench/index.js +0 -44
  235. package/dist/workbench/workbench.css +0 -1614
  236. package/dist/workbench/workbench.js +0 -77
@@ -1,15 +0,0 @@
1
- import type { ComponentJson, PageJson } from './types.js';
2
- export declare function parsePageFromFile(args: {
3
- code: string;
4
- filePath: string;
5
- pageKey: string;
6
- }): PageJson;
7
- /**
8
- * Parses a global component file and returns the components.
9
- * Similar to parsePageFromFile but simpler - no pageKey needed, just returns components.
10
- */
11
- export declare function parseGlobalComponentsFromFile(args: {
12
- code: string;
13
- filePath: string;
14
- }): ComponentJson[];
15
- //# sourceMappingURL=parsePage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"parsePage.d.ts","sourceRoot":"","sources":["../../src/compiler/parsePage.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAA;AAezD,wBAAgB,iBAAiB,CAAC,IAAI,EAAE;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;IAChB,OAAO,EAAE,MAAM,CAAA;CAChB,GAAG,QAAQ,CAuHX;AAED;;;GAGG;AACH,wBAAgB,6BAA6B,CAAC,IAAI,EAAE;IAClD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,MAAM,CAAA;CACjB,GAAG,aAAa,EAAE,CAqGlB"}
@@ -1,631 +0,0 @@
1
- import { parse } from '@babel/parser';
2
- import traverseImport from '@babel/traverse';
3
- import { ALLOWED_PRIMITIVES, TYPE_MAP, DEFAULTS_BY_TYPE } from './registry.js';
4
- import { CompileError } from './errors.js';
5
- import { evalStatic } from './evalStatic.js';
6
- const traverse = (traverseImport.default ?? traverseImport);
7
- export function parsePageFromFile(args) {
8
- let ast;
9
- try {
10
- ast = parse(args.code, {
11
- sourceType: 'module',
12
- plugins: ['typescript', 'jsx'],
13
- sourceFilename: args.filePath,
14
- });
15
- }
16
- catch (error) {
17
- // Babel parser errors have loc property with line/column
18
- const line = error.loc?.line ?? error.loc?.start?.line;
19
- const column = error.loc?.column ?? error.loc?.start?.column;
20
- throw new CompileError(error.message || 'Syntax error', {
21
- file: args.filePath,
22
- line,
23
- column,
24
- pageKey: args.pageKey,
25
- });
26
- }
27
- // collect static consts in module scope + inside page function (v1: module scope only is fine)
28
- const constEnv = new Map();
29
- traverse(ast, {
30
- VariableDeclarator(path) {
31
- const id = path.node.id;
32
- const init = path.node.init;
33
- if (id.type === 'Identifier' && init) {
34
- // only accept if init is statically evaluable
35
- try {
36
- const v = evalStatic(init, constEnv, args.filePath);
37
- constEnv.set(id.name, v);
38
- }
39
- catch {
40
- // ignore non-static consts
41
- }
42
- }
43
- },
44
- });
45
- // find exported function and its return JSX + collect function declarations for custom_validation_function
46
- // Supports both default exports (preferred) and named exports
47
- let rootJsx = null;
48
- let rootFragment = null;
49
- const validationFunctionSource = new Map();
50
- // Helper to extract JSX from a function body and collect inner function declarations
51
- const extractJsxAndFunctions = (fnBody, code) => {
52
- const ret = fnBody.body.find((s) => s.type === 'ReturnStatement');
53
- const arg = ret?.argument;
54
- if (arg) {
55
- if (arg.type === 'JSXElement') {
56
- rootJsx = arg;
57
- }
58
- else if (arg.type === 'JSXFragment') {
59
- rootFragment = arg;
60
- }
61
- }
62
- for (const stmt of fnBody.body) {
63
- if (stmt.type === 'FunctionDeclaration' && stmt.id?.name) {
64
- const start = stmt.start ?? 0;
65
- const end = stmt.end ?? code.length;
66
- validationFunctionSource.set(stmt.id.name, code.slice(start, end));
67
- }
68
- }
69
- };
70
- traverse(ast, {
71
- // Handle: export default function PageName() { ... }
72
- ExportDefaultDeclaration(path) {
73
- const decl = path.node.declaration;
74
- if (decl.type === 'FunctionDeclaration') {
75
- extractJsxAndFunctions(decl.body, args.code);
76
- }
77
- },
78
- // Handle: export function PageName() { ... } (legacy support)
79
- ExportNamedDeclaration(path) {
80
- const decl = path.node.declaration;
81
- if (!decl)
82
- return;
83
- if (decl.type === 'FunctionDeclaration' && decl.id?.name) {
84
- extractJsxAndFunctions(decl.body, args.code);
85
- }
86
- },
87
- });
88
- const components = [];
89
- if (rootJsx) {
90
- // Single root element
91
- const tree = jsxToTree(rootJsx, constEnv, args.filePath, validationFunctionSource);
92
- flatten(tree, null, components, args.pageKey, args.filePath);
93
- }
94
- else if (rootFragment) {
95
- // Multiple root elements (fragment) - allow empty fragments for blank pages
96
- const fragmentChildren = [];
97
- const fragment = rootFragment;
98
- for (const c of fragment.children) {
99
- if (c.type === 'JSXElement') {
100
- fragmentChildren.push(c);
101
- }
102
- }
103
- // Allow blank pages - if fragment has no JSXElement children, components array stays empty
104
- for (const child of fragmentChildren) {
105
- const tree = jsxToTree(child, constEnv, args.filePath, validationFunctionSource);
106
- flatten(tree, null, components, args.pageKey, args.filePath);
107
- }
108
- }
109
- else {
110
- // Allow blank pages - if no JSX found, components array stays empty
111
- // This handles pages that return null, undefined, or have no return statement
112
- }
113
- return {
114
- key: args.pageKey,
115
- showNav: true,
116
- tags: [],
117
- id: `page_${args.pageKey}`,
118
- components,
119
- };
120
- }
121
- /**
122
- * Parses a global component file and returns the components.
123
- * Similar to parsePageFromFile but simpler - no pageKey needed, just returns components.
124
- */
125
- export function parseGlobalComponentsFromFile(args) {
126
- let ast;
127
- try {
128
- ast = parse(args.code, {
129
- sourceType: 'module',
130
- plugins: ['typescript', 'jsx'],
131
- sourceFilename: args.filePath,
132
- });
133
- }
134
- catch (error) {
135
- // Babel parser errors have loc property with line/column
136
- const line = error.loc?.line ?? error.loc?.start?.line;
137
- const column = error.loc?.column ?? error.loc?.start?.column;
138
- throw new CompileError(error.message || 'Syntax error', {
139
- file: args.filePath,
140
- line,
141
- column,
142
- });
143
- }
144
- // collect static consts in module scope
145
- const constEnv = new Map();
146
- traverse(ast, {
147
- VariableDeclarator(path) {
148
- const id = path.node.id;
149
- const init = path.node.init;
150
- if (id.type === 'Identifier' && init) {
151
- try {
152
- const v = evalStatic(init, constEnv, args.filePath);
153
- constEnv.set(id.name, v);
154
- }
155
- catch {
156
- // ignore non-static consts
157
- }
158
- }
159
- },
160
- });
161
- // find exported function and its return JSX + collect function declarations for custom_validation_function
162
- let rootJsx = null;
163
- let rootFragment = null;
164
- const validationFunctionSource = new Map();
165
- const extractJsxAndFunctions = (fnBody, code) => {
166
- const ret = fnBody.body.find((s) => s.type === 'ReturnStatement');
167
- const arg = ret?.argument;
168
- if (arg) {
169
- if (arg.type === 'JSXElement') {
170
- rootJsx = arg;
171
- }
172
- else if (arg.type === 'JSXFragment') {
173
- rootFragment = arg;
174
- }
175
- }
176
- for (const stmt of fnBody.body) {
177
- if (stmt.type === 'FunctionDeclaration' && stmt.id?.name) {
178
- const start = stmt.start ?? 0;
179
- const end = stmt.end ?? code.length;
180
- validationFunctionSource.set(stmt.id.name, code.slice(start, end));
181
- }
182
- }
183
- };
184
- traverse(ast, {
185
- ExportDefaultDeclaration(path) {
186
- const decl = path.node.declaration;
187
- if (decl.type === 'FunctionDeclaration') {
188
- extractJsxAndFunctions(decl.body, args.code);
189
- }
190
- },
191
- ExportNamedDeclaration(path) {
192
- const decl = path.node.declaration;
193
- if (!decl)
194
- return;
195
- if (decl.type === 'FunctionDeclaration' && decl.id?.name) {
196
- extractJsxAndFunctions(decl.body, args.code);
197
- }
198
- },
199
- });
200
- const components = [];
201
- if (rootJsx) {
202
- const tree = jsxToTree(rootJsx, constEnv, args.filePath, validationFunctionSource);
203
- flatten(tree, null, components, '', args.filePath);
204
- }
205
- else if (rootFragment) {
206
- const fragmentChildren = [];
207
- const fragment = rootFragment;
208
- for (const c of fragment.children) {
209
- if (c.type === 'JSXElement') {
210
- fragmentChildren.push(c);
211
- }
212
- }
213
- for (const child of fragmentChildren) {
214
- const tree = jsxToTree(child, constEnv, args.filePath, validationFunctionSource);
215
- flatten(tree, null, components, '', args.filePath);
216
- }
217
- }
218
- return components;
219
- }
220
- function jsxToTree(el, constEnv, filePath, validationFunctionSource) {
221
- const opening = el.openingElement;
222
- const tagName = getJsxTagName(opening.name);
223
- if (!ALLOWED_PRIMITIVES.has(tagName)) {
224
- throw new CompileError(`Unknown/unsupported primitive <${tagName}>.`, loc(filePath, opening));
225
- }
226
- const jsonType = TYPE_MAP[tagName];
227
- const attrs = attrsToProps(opening.attributes, constEnv, filePath, validationFunctionSource);
228
- const id = requireString(attrs, 'id', filePath, opening);
229
- const key = requireString(attrs, 'key', filePath, opening);
230
- const tags = (attrs.tags ?? []);
231
- if (!Array.isArray(tags) || tags.some((t) => typeof t !== 'string')) {
232
- throw new CompileError(`Prop "tags" must be an array of strings.`, loc(filePath, opening));
233
- }
234
- delete attrs.id;
235
- delete attrs.key;
236
- delete attrs.tags;
237
- // For CustomHTML, convert all children (including text) to HTML string
238
- if (tagName === 'CustomHTML') {
239
- // Check if there are any children (including text nodes and fragments)
240
- const hasChildren = el.children.some((c) => c.type === 'JSXElement' ||
241
- c.type === 'JSXFragment' ||
242
- (c.type === 'JSXText' && c.value.trim().length > 0) ||
243
- c.type === 'JSXExpressionContainer');
244
- if (hasChildren) {
245
- // Convert JSX children to HTML string
246
- const htmlString = jsxChildrenToHTML(el.children, constEnv, filePath);
247
- attrs.text = htmlString;
248
- }
249
- // Return with empty children array since we've converted them to HTML
250
- return {
251
- tag: tagName,
252
- type: jsonType,
253
- id,
254
- key,
255
- tags,
256
- props: attrs,
257
- children: [],
258
- loc: loc(filePath, opening),
259
- };
260
- }
261
- // children JSXElements only (ignore whitespace text nodes)
262
- const children = el.children
263
- .filter((c) => c.type === 'JSXElement')
264
- .map((c) => jsxToTree(c, constEnv, filePath, validationFunctionSource));
265
- // v1 rule: only Container can have children (CustomHTML handled above)
266
- if (children.length > 0 && tagName !== 'Container') {
267
- throw new CompileError(`<${tagName}> cannot have children. Only <Container> and <CustomHTML> may contain children.`, loc(filePath, opening));
268
- }
269
- // enforce OptionSelector uses buttons
270
- if (tagName === 'OptionSelector' && 'options' in attrs) {
271
- throw new CompileError(`OptionSelector does not support prop "options". Use "buttons".`, loc(filePath, opening));
272
- }
273
- return {
274
- tag: tagName,
275
- type: jsonType,
276
- id,
277
- key,
278
- tags,
279
- props: attrs,
280
- children,
281
- loc: loc(filePath, opening),
282
- };
283
- }
284
- function flatten(node, parentId, out, pageKey, filePath) {
285
- const base = {
286
- type: node.type,
287
- id: node.id,
288
- key: node.key,
289
- tags: node.tags,
290
- };
291
- if (parentId)
292
- base.parent_id = parentId;
293
- const defaults = DEFAULTS_BY_TYPE[node.type] ?? {};
294
- // Extract extra props from props={...} (round-trip from reverse compiler) and merge into component
295
- const { props: extraProps, ...restProps } = node.props;
296
- const mergedExtra = extraProps != null && typeof extraProps === 'object' && !Array.isArray(extraProps)
297
- ? extraProps
298
- : {};
299
- const json = {
300
- ...base,
301
- ...defaults,
302
- ...restProps,
303
- ...mergedExtra,
304
- };
305
- // Helper to create errors with component context
306
- const createError = (message, loc) => {
307
- return new CompileError(message, {
308
- ...loc,
309
- pageKey,
310
- componentId: node.id,
311
- componentKey: node.key,
312
- });
313
- };
314
- // Normalize OptionSelector buttons: generate IDs + defaults
315
- if (json.type === 'OptionSelector') {
316
- const buttons = json.buttons;
317
- if (buttons != null) {
318
- if (!Array.isArray(buttons)) {
319
- throw createError(`OptionSelector requires "buttons" as an array. Got: ${typeof buttons}`, node.loc);
320
- }
321
- json.buttons = buttons.map((b) => {
322
- if (!b || typeof b !== 'object') {
323
- throw createError(`Each button must be an object.`, node.loc);
324
- }
325
- // key can be string or null, text is optional
326
- if (b.key !== null && typeof b.key !== 'string') {
327
- throw createError(`Each button requires "key" to be a string or null. Got: ${typeof b.key}`, node.loc);
328
- }
329
- if (b.text != null && typeof b.text !== 'string') {
330
- throw createError(`Button "text" must be a string if provided. Got: ${typeof b.text}`, node.loc);
331
- }
332
- // Preserve all OptionSelectorButton properties from the input
333
- // Required properties
334
- const result = {
335
- id: typeof b.id === 'string' ? b.id : `option_${b.key}`,
336
- key: b.key,
337
- };
338
- // Optional properties - only include if present
339
- if (b.text != null)
340
- result.text = b.text;
341
- if (b.description != null)
342
- result.description = b.description;
343
- // triggerEvent defaults to 'no-action' if not provided
344
- result.triggerEvent = typeof b.triggerEvent === 'string' ? b.triggerEvent : 'no-action';
345
- if (b.conditions != null)
346
- result.conditions = b.conditions;
347
- if (b.openUrlInNewTab != null)
348
- result.openUrlInNewTab = b.openUrlInNewTab;
349
- if (b.url != null)
350
- result.url = b.url;
351
- if (b.single_select != null)
352
- result.single_select = b.single_select;
353
- if (b.icon != null)
354
- result.icon = b.icon;
355
- if (b.emojiIcon != null)
356
- result.emojiIcon = b.emojiIcon;
357
- if (b.imageUrl != null)
358
- result.imageUrl = b.imageUrl;
359
- if (b.imageAltText != null)
360
- result.imageAltText = b.imageAltText;
361
- if (b.hide != null)
362
- result.hide = b.hide;
363
- if (b.is_repeatable_button != null)
364
- result.is_repeatable_button = b.is_repeatable_button;
365
- return result;
366
- });
367
- }
368
- // If buttons is null/undefined, leave it as is (optional prop)
369
- }
370
- out.push(json);
371
- for (const child of node.children) {
372
- flatten(child, node.id, out, pageKey, filePath);
373
- }
374
- }
375
- /**
376
- * Normalize validation function source for embeddable.json: use name "validate" and strip TS (param types).
377
- */
378
- function normalizeValidationFunctionSource(source) {
379
- // 1. Rename function to "validate"
380
- let out = source.replace(/function\s+\w+\s*\(/, 'function validate(');
381
- // 2. Strip parameter type annotations in the first parameter list (e.g. value: string -> value)
382
- const openParen = out.indexOf('(', out.indexOf('function'));
383
- if (openParen !== -1) {
384
- let depth = 1;
385
- let i = openParen + 1;
386
- while (depth > 0 && i < out.length) {
387
- if (out[i] === '(')
388
- depth++;
389
- else if (out[i] === ')')
390
- depth--;
391
- i++;
392
- }
393
- const params = out.slice(openParen, i);
394
- const paramsNoTypes = params.replace(/:\s*[^,)]+/g, '');
395
- out = out.slice(0, openParen) + paramsNoTypes + out.slice(i);
396
- }
397
- return out;
398
- }
399
- function attrsToProps(attrs, constEnv, filePath, validationFunctionSource) {
400
- const out = {};
401
- for (const a of attrs) {
402
- if (a.type === 'JSXSpreadAttribute') {
403
- throw new CompileError('JSX spread props are not supported.', loc(filePath, a));
404
- }
405
- const name = a.name.type === 'JSXIdentifier' ? a.name.name : `${a.name.namespace.name}:${a.name.name.name}`;
406
- if (!a.value) {
407
- // <X disabled />
408
- out[name] = true;
409
- continue;
410
- }
411
- if (a.value.type === 'StringLiteral') {
412
- out[name] = a.value.value;
413
- continue;
414
- }
415
- if (a.value.type === 'JSXExpressionContainer') {
416
- const expr = a.value.expression;
417
- // custom_validation_function: resolve to source and normalize to "validate" + JS for embeddable.json
418
- if (name === 'custom_validation_function' &&
419
- expr.type === 'Identifier' &&
420
- validationFunctionSource?.has(expr.name)) {
421
- out[name] = normalizeValidationFunctionSource(validationFunctionSource.get(expr.name));
422
- continue;
423
- }
424
- out[name] = evalStatic(expr, constEnv, filePath);
425
- continue;
426
- }
427
- throw new CompileError(`Unsupported JSX attribute value for "${name}".`, loc(filePath, a));
428
- }
429
- // When validation_formula is not "custom", custom_validation_function is ignored and omitted (removed on save).
430
- if (out.validation_formula != null && out.validation_formula !== 'custom' && 'custom_validation_function' in out) {
431
- delete out.custom_validation_function;
432
- }
433
- return out;
434
- }
435
- function getJsxTagName(n) {
436
- if (n.type === 'JSXIdentifier')
437
- return n.name;
438
- throw new CompileError('Only simple JSX identifiers are supported (no member expressions).');
439
- }
440
- function requireString(obj, prop, filePath, node) {
441
- const v = obj[prop];
442
- if (typeof v !== 'string' || v.length === 0) {
443
- throw new CompileError(`Missing required string prop "${prop}".`, loc(filePath, node));
444
- }
445
- return v;
446
- }
447
- function loc(file, node) {
448
- return { file, line: node.loc?.start?.line, column: node.loc?.start?.column };
449
- }
450
- /**
451
- * Converts JSX children to HTML string.
452
- * Handles JSXElements, JSXText, JSXExpressions, and JSXFragments.
453
- * @param preserveWhitespace If true, preserves all whitespace (for <style> and <script> tags)
454
- */
455
- function jsxChildrenToHTML(children, constEnv, filePath, preserveWhitespace = false) {
456
- let html = '';
457
- for (const child of children) {
458
- if (child.type === 'JSXElement') {
459
- html += jsxElementToHTML(child, constEnv, filePath);
460
- }
461
- else if (child.type === 'JSXText') {
462
- const text = child.value;
463
- // For <style> and <script> tags, preserve all whitespace
464
- // For other tags, skip whitespace-only text (it's likely indentation)
465
- if (preserveWhitespace || text.trim().length > 0) {
466
- html += escapeHTML(text);
467
- }
468
- }
469
- else if (child.type === 'JSXExpressionContainer') {
470
- // Try to evaluate static expressions
471
- try {
472
- const value = evalStatic(child.expression, constEnv, filePath);
473
- if (typeof value === 'string') {
474
- html += escapeHTML(value);
475
- }
476
- else if (value != null) {
477
- html += escapeHTML(String(value));
478
- }
479
- }
480
- catch {
481
- throw new CompileError('CustomHTML children must be static. Dynamic expressions are not supported.', loc(filePath, child));
482
- }
483
- }
484
- else if (child.type === 'JSXFragment') {
485
- // Handle fragments by recursively processing their children
486
- html += jsxChildrenToHTML(child.children, constEnv, filePath, preserveWhitespace);
487
- }
488
- // Ignore JSXSpreadChild and other unsupported types
489
- }
490
- return html;
491
- }
492
- /**
493
- * HTML5 void elements - these are the only elements that can be self-closing in HTML.
494
- * For all other elements, we must emit explicit closing tags even if they're self-closing in JSX.
495
- * See: https://html.spec.whatwg.org/multipage/syntax.html#void-elements
496
- */
497
- const HTML_VOID_ELEMENTS = new Set([
498
- 'area',
499
- 'base',
500
- 'br',
501
- 'col',
502
- 'embed',
503
- 'hr',
504
- 'img',
505
- 'input',
506
- 'link',
507
- 'meta',
508
- 'param',
509
- 'source',
510
- 'track',
511
- 'wbr',
512
- ]);
513
- /**
514
- * Map React/JSX attribute names to HTML attribute names so serialized HTML
515
- * uses valid attributes (e.g. class for CSS, not className).
516
- */
517
- function jsxAttrNameToHTMLAttrName(jsxName) {
518
- switch (jsxName) {
519
- case 'className':
520
- return 'class';
521
- case 'htmlFor':
522
- return 'for';
523
- case 'tabIndex':
524
- return 'tabindex';
525
- default:
526
- return jsxName;
527
- }
528
- }
529
- /**
530
- * Converts a JSX element to HTML string.
531
- */
532
- function jsxElementToHTML(el, constEnv, filePath) {
533
- const opening = el.openingElement;
534
- const tagName = getJsxTagName(opening.name);
535
- // Build attributes string (use HTML attribute names so class selectors work)
536
- const attrs = [];
537
- for (const attr of opening.attributes) {
538
- if (attr.type === 'JSXAttribute') {
539
- const name = attr.name.type === 'JSXIdentifier'
540
- ? attr.name.name
541
- : `${attr.name.namespace.name}:${attr.name.name.name}`;
542
- const htmlName = jsxAttrNameToHTMLAttrName(name);
543
- if (!attr.value) {
544
- // Boolean attribute
545
- attrs.push(htmlName);
546
- }
547
- else if (attr.value.type === 'StringLiteral') {
548
- attrs.push(`${htmlName}="${escapeHTMLAttribute(attr.value.value)}"`);
549
- }
550
- else if (attr.value.type === 'JSXExpressionContainer') {
551
- try {
552
- const value = evalStatic(attr.value.expression, constEnv, filePath);
553
- if (name === 'style' && typeof value === 'object' && value !== null) {
554
- // Convert style object to CSS string
555
- const cssString = styleObjectToCSS(value);
556
- attrs.push(`${htmlName}="${escapeHTMLAttribute(cssString)}"`);
557
- }
558
- else if (typeof value === 'string') {
559
- attrs.push(`${htmlName}="${escapeHTMLAttribute(value)}"`);
560
- }
561
- else if (typeof value === 'number' || typeof value === 'boolean') {
562
- attrs.push(`${htmlName}="${String(value)}"`);
563
- }
564
- }
565
- catch {
566
- throw new CompileError('CustomHTML attribute values must be static. Dynamic expressions are not supported.', loc(filePath, attr));
567
- }
568
- }
569
- }
570
- }
571
- const attrsStr = attrs.length > 0 ? ' ' + attrs.join(' ') : '';
572
- // For <style> and <script> tags, preserve all whitespace to maintain CSS/JS formatting
573
- const isRawTextTag = tagName.toLowerCase() === 'style' || tagName.toLowerCase() === 'script';
574
- const childrenHTML = jsxChildrenToHTML(el.children, constEnv, filePath, isRawTextTag);
575
- if (el.closingElement) {
576
- return `<${tagName}${attrsStr}>${childrenHTML}</${tagName}>`;
577
- }
578
- else {
579
- // Self-closing in JSX - check if it's an HTML void element
580
- const isVoidElement = HTML_VOID_ELEMENTS.has(tagName.toLowerCase());
581
- if (isVoidElement) {
582
- // Void elements can be self-closing in HTML
583
- return `<${tagName}${attrsStr} />`;
584
- }
585
- else {
586
- // Non-void elements MUST have explicit closing tags in HTML
587
- // Otherwise browsers interpret <div /> as <div> (unclosed)
588
- return `<${tagName}${attrsStr}></${tagName}>`;
589
- }
590
- }
591
- }
592
- /**
593
- * Escapes HTML entities in text content.
594
- */
595
- function escapeHTML(text) {
596
- return text
597
- .replace(/&/g, '&amp;')
598
- .replace(/</g, '&lt;')
599
- .replace(/>/g, '&gt;')
600
- .replace(/"/g, '&quot;')
601
- .replace(/'/g, '&#39;');
602
- }
603
- /**
604
- * Escapes HTML entities in attribute values.
605
- */
606
- function escapeHTMLAttribute(text) {
607
- return text
608
- .replace(/&/g, '&amp;')
609
- .replace(/</g, '&lt;')
610
- .replace(/>/g, '&gt;')
611
- .replace(/"/g, '&quot;');
612
- }
613
- /**
614
- * Converts a JSX style object to CSS string.
615
- * Example: { margin: 0, padding: 0, color: "#171717" } -> "margin: 0; padding: 0; color: #171717;"
616
- */
617
- function styleObjectToCSS(styleObj) {
618
- const cssParts = [];
619
- for (const [key, value] of Object.entries(styleObj)) {
620
- // Preserve CSS custom properties (e.g., --ta, --my-variable) as-is
621
- if (key.startsWith('--')) {
622
- cssParts.push(`${key}: ${value};`);
623
- }
624
- else {
625
- // Convert camelCase to kebab-case (e.g., lineHeight -> line-height)
626
- const cssKey = key.replace(/([A-Z])/g, '-$1').toLowerCase();
627
- cssParts.push(`${cssKey}: ${value};`);
628
- }
629
- }
630
- return cssParts.join(' ');
631
- }
@@ -1,4 +0,0 @@
1
- export declare const ALLOWED_PRIMITIVES: Set<string>;
2
- export declare const TYPE_MAP: Record<string, string>;
3
- export declare const DEFAULTS_BY_TYPE: Record<string, Record<string, any>>;
4
- //# sourceMappingURL=registry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/compiler/registry.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,kBAAkB,aAoB7B,CAAA;AAGF,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAoB3C,CAAA;AAED,eAAO,MAAM,gBAAgB,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAM,CAAA"}