@builder.io/mitosis 0.0.56-2 → 0.0.56-5

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 (32) hide show
  1. package/dist/src/__tests__/angular.test.js +24 -0
  2. package/dist/src/__tests__/data/basic-for.raw.d.ts +1 -0
  3. package/dist/src/__tests__/data/basic-for.raw.jsx +24 -0
  4. package/dist/src/__tests__/data/blocks/img-state.raw.d.ts +1 -0
  5. package/dist/src/__tests__/data/blocks/img-state.raw.jsx +17 -0
  6. package/dist/src/__tests__/data/blocks/onInit-onMount.raw.d.ts +1 -0
  7. package/dist/src/__tests__/data/blocks/onInit-onMount.raw.jsx +13 -0
  8. package/dist/src/__tests__/data/blocks/onInit.raw.d.ts +1 -0
  9. package/dist/src/__tests__/data/blocks/onInit.raw.jsx +10 -0
  10. package/dist/src/__tests__/data/blocks/section-state.raw.d.ts +6 -0
  11. package/dist/src/__tests__/data/blocks/section-state.raw.jsx +17 -0
  12. package/dist/src/__tests__/data/context/component-with-context.lite.d.ts +3 -1
  13. package/dist/src/__tests__/data/context/component-with-context.lite.jsx +7 -2
  14. package/dist/src/__tests__/html.test.js +126 -0
  15. package/dist/src/__tests__/react.test.js +12 -0
  16. package/dist/src/__tests__/svelte.test.js +40 -6
  17. package/dist/src/__tests__/webcomponent.test.js +144 -0
  18. package/dist/src/generators/angular.js +12 -5
  19. package/dist/src/generators/html.js +167 -67
  20. package/dist/src/generators/react.js +10 -6
  21. package/dist/src/generators/svelte.js +10 -2
  22. package/dist/src/generators/vue.js +2 -2
  23. package/dist/src/helpers/render-imports.d.ts +1 -1
  24. package/dist/src/parsers/builder.d.ts +2 -0
  25. package/dist/src/parsers/jsx.js +26 -2
  26. package/dist/src/symbols/symbol-processor.js +3 -3
  27. package/dist/src/types/config.d.ts +7 -1
  28. package/dist/src/types/mitosis-component.d.ts +1 -0
  29. package/dist/src/types/mitosis-node.d.ts +8 -8
  30. package/dist/tsconfig.build.tsbuildinfo +1 -1
  31. package/dist/tsconfig.tsbuildinfo +1 -1
  32. package/package.json +2 -2
@@ -10,6 +10,15 @@ var __assign = (this && this.__assign) || function () {
10
10
  };
11
11
  return __assign.apply(this, arguments);
12
12
  };
13
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
14
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
15
+ if (ar || !(i in from)) {
16
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
17
+ ar[i] = from[i];
18
+ }
19
+ }
20
+ return to.concat(ar || Array.prototype.slice.call(from));
21
+ };
13
22
  var __importDefault = (this && this.__importDefault) || function (mod) {
14
23
  return (mod && mod.__esModule) ? mod : { "default": mod };
15
24
  };
@@ -28,7 +37,6 @@ var get_state_object_string_1 = require("../helpers/get-state-object-string");
28
37
  var has_component_1 = require("../helpers/has-component");
29
38
  var is_component_1 = require("../helpers/is-component");
30
39
  var is_mitosis_node_1 = require("../helpers/is-mitosis-node");
31
- var replace_idenifiers_1 = require("../helpers/replace-idenifiers");
32
40
  var jsx_1 = require("../parsers/jsx");
33
41
  var strip_state_and_props_refs_1 = require("../helpers/strip-state-and-props-refs");
34
42
  var plugins_1 = require("../modules/plugins");
@@ -46,10 +54,14 @@ var updateKeyIfException = function (key) {
46
54
  var needsSetAttribute = function (key) {
47
55
  return [key.includes('-')].some(Boolean);
48
56
  };
49
- var generateSetElementAttributeCode = function (key, useValue) {
57
+ var generateSetElementAttributeCode = function (key, useValue, options) {
58
+ var _a, _b;
59
+ if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.props) {
60
+ return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.props(key, useValue, options);
61
+ }
50
62
  return needsSetAttribute(key)
51
63
  ? ";el.setAttribute(\"".concat(key, "\", ").concat(useValue, ");")
52
- : ";el.".concat(updateKeyIfException(key), " = ").concat(useValue);
64
+ : ";el.".concat(updateKeyIfException(key), " = ").concat(useValue, ";");
53
65
  };
54
66
  var addUpdateAfterSet = function (json, options) {
55
67
  (0, traverse_1.default)(json).forEach(function (item) {
@@ -64,39 +76,21 @@ var addUpdateAfterSet = function (json, options) {
64
76
  }
65
77
  });
66
78
  };
67
- var getForNames = function (json) {
68
- var names = [];
69
- (0, traverse_1.default)(json).forEach(function (item) {
70
- if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
71
- if (item.name === 'For') {
72
- names.push(item.properties._forName);
73
- }
74
- }
75
- });
76
- return names;
77
- };
78
- var replaceForNameIdentifiers = function (json, options) {
79
- // TODO: cache this. by reference? lru?
80
- var forNames = getForNames(json);
81
- (0, traverse_1.default)(json).forEach(function (item) {
82
- if ((0, is_mitosis_node_1.isMitosisNode)(item)) {
83
- for (var key in item.bindings) {
84
- if (key === 'css' || key === '_forName') {
85
- continue;
86
- }
87
- var value = item.bindings[key];
88
- if (typeof value === 'string') {
89
- item.bindings[key] = (0, replace_idenifiers_1.replaceIdentifiers)(value, forNames, function (name) {
90
- return "".concat(options.format === 'class' ? 'this.' : '', "getContext(el, \"").concat(name, "\")");
91
- });
92
- }
93
- }
94
- }
95
- });
79
+ var addScopeVars = function (parentScopeVars, value, fn) {
80
+ return "".concat(parentScopeVars
81
+ .filter(function (scopeVar) {
82
+ return new RegExp(scopeVar).test(value);
83
+ })
84
+ .map(function (scopeVar) {
85
+ return fn(scopeVar);
86
+ })
87
+ .join('\n'));
96
88
  };
97
89
  var mappers = {
98
- Fragment: function (json, options) {
99
- return json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
90
+ Fragment: function (json, options, parentScopeVars) {
91
+ return json.children
92
+ .map(function (item) { return blockToHtml(item, options, parentScopeVars); })
93
+ .join('\n');
100
94
  },
101
95
  };
102
96
  var getId = function (json, options) {
@@ -110,6 +104,12 @@ var getId = function (json, options) {
110
104
  return "".concat(name).concat(options.prefix ? "-".concat(options.prefix) : '').concat(name !== json.name && newNameNum === 1 ? '' : "-".concat(newNameNum));
111
105
  };
112
106
  var updateReferencesInCode = function (code, options) {
107
+ var _a, _b;
108
+ if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.updateReferencesInCode) {
109
+ return (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.updateReferencesInCode(code, options, {
110
+ stripStateAndPropsRefs: strip_state_and_props_refs_1.stripStateAndPropsRefs,
111
+ });
112
+ }
113
113
  if (options.format === 'class') {
114
114
  return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(code, {
115
115
  includeProps: false,
@@ -131,15 +131,30 @@ var addOnChangeJs = function (id, options, code) {
131
131
  options.onChangeJsById[id] += code;
132
132
  };
133
133
  // TODO: spread support
134
- var blockToHtml = function (json, options) {
134
+ var blockToHtml = function (json, options, parentScopeVars) {
135
+ var _a, _b, _c, _d, _e, _f, _g;
136
+ if (parentScopeVars === void 0) { parentScopeVars = []; }
135
137
  var hasData = Object.keys(json.bindings).length;
136
138
  var elId = '';
137
139
  if (hasData) {
138
140
  elId = getId(json, options);
139
141
  json.properties['data-name'] = elId;
140
142
  }
143
+ if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.getId) {
144
+ elId = (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.getId(elId, json, options, {
145
+ hasData: hasData,
146
+ getId: getId,
147
+ });
148
+ json.properties['data-name'] = (_c = options === null || options === void 0 ? void 0 : options.experimental) === null || _c === void 0 ? void 0 : _c.dataName(elId, json, options, {
149
+ hasData: hasData,
150
+ getId: getId,
151
+ });
152
+ }
153
+ if ((_e = (_d = options === null || options === void 0 ? void 0 : options.experimental) === null || _d === void 0 ? void 0 : _d.mappers) === null || _e === void 0 ? void 0 : _e[json.name]) {
154
+ return (_g = (_f = options === null || options === void 0 ? void 0 : options.experimental) === null || _f === void 0 ? void 0 : _f.mappers) === null || _g === void 0 ? void 0 : _g[json.name](json, options, elId, parentScopeVars, blockToHtml, addScopeVars, addOnChangeJs);
155
+ }
141
156
  if (mappers[json.name]) {
142
- return mappers[json.name](json, options);
157
+ return mappers[json.name](json, options, parentScopeVars);
143
158
  }
144
159
  if ((0, is_children_1.default)(json)) {
145
160
  return "<slot></slot>";
@@ -149,28 +164,41 @@ var blockToHtml = function (json, options) {
149
164
  }
150
165
  if (json.bindings._text) {
151
166
  // TO-DO: textContent might be better performance-wise
152
- addOnChangeJs(elId, options, "el.innerText = ".concat(json.bindings._text, ";"));
153
- return "<span data-name=\"".concat(elId, "\"><!-- ").concat(json.bindings._text.replace(/getContext\(el, "([^"]+)"\)/g, '$1'), " --></span>");
167
+ addOnChangeJs(elId, options, "\n ".concat(addScopeVars(parentScopeVars, json.bindings._text, function (scopeVar) {
168
+ return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getContext(el, \"").concat(scopeVar, "\");");
169
+ }), "\n ;el.innerText = ").concat(json.bindings._text, ";"));
170
+ return "<span data-name=\"".concat(elId, "\"><!-- ").concat(json.bindings._text, " --></span>");
154
171
  }
155
172
  var str = '';
156
173
  if (json.name === 'For') {
157
174
  var itemName = json.properties._forName;
175
+ var indexName = json.properties._indexName;
176
+ var collectionName = json.properties._collectionName;
177
+ var scopedVars_1 = __spreadArray(__spreadArray([], parentScopeVars, true), [
178
+ itemName,
179
+ indexName,
180
+ collectionName,
181
+ ], false).filter(Boolean);
158
182
  addOnChangeJs(elId, options,
159
183
  // TODO: be smarter about rendering, deleting old items and adding new ones by
160
184
  // querying dom potentially
161
- "\n let array = ".concat(json.bindings.each, ";\n let template = ").concat(options.format === 'class' ? 'this._root' : 'document', ".querySelector('[data-template-for=\"").concat(elId, "\"]');\n ").concat(options.format === 'class' ? 'this.' : '', "renderLoop(el, array, template, \"").concat(itemName, "\");\n "));
185
+ "\n let array = ".concat(json.bindings.each, ";\n let template = ").concat(options.format === 'class' ? 'this._root' : 'document', ".querySelector('[data-template-for=\"").concat(elId, "\"]');\n ").concat(options.format === 'class' ? 'this.' : '', "renderLoop(el, array, template, ").concat(itemName ? "\"".concat(itemName, "\"") : 'undefined', ", ").concat(indexName ? "\"".concat(indexName, "\"") : 'undefined', ", ").concat(collectionName ? "\"".concat(collectionName, "\"") : 'undefined', ");\n "));
162
186
  // TODO: decide on how to handle this...
163
187
  str += "\n <span data-name=\"".concat(elId, "\"></span>\n <template data-template-for=\"").concat(elId, "\">");
164
188
  if (json.children) {
165
- str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
189
+ str += json.children
190
+ .map(function (item) { return blockToHtml(item, options, scopedVars_1); })
191
+ .join('\n');
166
192
  }
167
193
  str += '</template>';
168
194
  }
169
195
  else if (json.name === 'Show') {
170
- addOnChangeJs(elId, options, "\n if(".concat(json.bindings.when.replace(/;$/, ''), ") {\n \tconst clonedElement = el.content.cloneNode(true);\n const endTag = document.createElement('template');\n endTag.setAttribute('data-show', '").concat(elId, "-end');\n\t\t\t\t\n el.after(endTag);\n el.after(clonedElement)\n } else {\n if (this.querySelector(\"[data-show='").concat(elId, "-end']\") === null) {\n \treturn;\n }\n\n let sibling = el.nextSibling;\n const toBeRemoved = [];\n while (sibling) {\n toBeRemoved.push(sibling);\n if (sibling?.dataset?.show === '").concat(elId, "-end') {\n \ttoBeRemoved.forEach(sib => sib.remove());\n return;\n } \n sibling = sibling.nextSibling;\n }\n } \n "));
196
+ addOnChangeJs(elId, options, "\n const whenCondition = ".concat(json.bindings.when.replace(/;$/, ''), ";\n if (whenCondition) {\n ").concat(options.format === 'class' ? 'this.' : '', "showContent(el)\n }\n "));
171
197
  str += "<template data-name=\"".concat(elId, "\">");
172
198
  if (json.children) {
173
- str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
199
+ str += json.children
200
+ .map(function (item) { return blockToHtml(item, options, parentScopeVars); })
201
+ .join('\n');
174
202
  }
175
203
  str += '</template>';
176
204
  }
@@ -209,18 +237,26 @@ var blockToHtml = function (json, options) {
209
237
  event_1 = 'input';
210
238
  }
211
239
  var fnName = (0, lodash_1.camelCase)("on-".concat(elId, "-").concat(event_1));
240
+ var codeContent = (0, remove_surrounding_block_1.removeSurroundingBlock)(updateReferencesInCode(useValue, options));
212
241
  options.js += "\n // Event handler for '".concat(event_1, "' event on ").concat(elId, "\n ").concat(options.format === 'class'
213
242
  ? "this.".concat(fnName, " = (event) => {")
214
- : "function ".concat(fnName, " (event) {"), "\n ").concat((0, remove_surrounding_block_1.removeSurroundingBlock)(updateReferencesInCode(useValue, options)), "\n }\n ");
243
+ : "function ".concat(fnName, " (event) {"), "\n ").concat(addScopeVars(parentScopeVars, codeContent, function (scopeVar) {
244
+ return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getContext(event.currentTarget, \"").concat(scopeVar, "\");");
245
+ }), "\n ").concat(codeContent, "\n }\n ");
215
246
  var fnIdentifier = "".concat(options.format === 'class' ? 'this.' : '').concat(fnName);
216
247
  addOnChangeJs(elId, options, "\n ;el.removeEventListener('".concat(event_1, "', ").concat(fnIdentifier, ");\n ;el.addEventListener('").concat(event_1, "', ").concat(fnIdentifier, ");\n "));
217
248
  }
218
249
  else {
219
250
  if (key === 'style') {
220
- addOnChangeJs(elId, options, ";Object.assign(el.style, ".concat(useValue, ");"));
251
+ addOnChangeJs(elId, options, "\n ".concat(addScopeVars(parentScopeVars, useValue, function (scopeVar) {
252
+ return "const ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getContext(el, \"").concat(scopeVar, "\");");
253
+ }), "\n ;Object.assign(el.style, ").concat(useValue, ");"));
221
254
  }
222
255
  else {
223
- addOnChangeJs(elId, options, generateSetElementAttributeCode(key, useValue));
256
+ addOnChangeJs(elId, options, "\n ".concat(addScopeVars(parentScopeVars, useValue, function (scopeVar) {
257
+ // TODO: multiple loops may duplicate variable declarations
258
+ return ";var ".concat(scopeVar, " = ").concat(options.format === 'class' ? 'this.' : '', "getContext(el, \"").concat(scopeVar, "\");");
259
+ }), "\n ").concat(generateSetElementAttributeCode(key, useValue, options), "\n "));
224
260
  }
225
261
  }
226
262
  }
@@ -229,7 +265,9 @@ var blockToHtml = function (json, options) {
229
265
  }
230
266
  str += '>';
231
267
  if (json.children) {
232
- str += json.children.map(function (item) { return blockToHtml(item, options); }).join('\n');
268
+ str += json.children
269
+ .map(function (item) { return blockToHtml(item, options, parentScopeVars); })
270
+ .join('\n');
233
271
  }
234
272
  if (json.properties.innerHTML) {
235
273
  // Maybe put some kind of safety here for broken HTML such as no close tag
@@ -244,6 +282,7 @@ function addUpdateAfterSetInCode(code, options, useString) {
244
282
  var updates = 0;
245
283
  return (0, babel_transform_1.babelTransformExpression)(code, {
246
284
  AssignmentExpression: function (path) {
285
+ var _a, _b;
247
286
  var node = path.node;
248
287
  if (core_1.types.isMemberExpression(node.left)) {
249
288
  if (core_1.types.isIdentifier(node.left.object)) {
@@ -267,6 +306,13 @@ function addUpdateAfterSetInCode(code, options, useString) {
267
306
  // console.error('Infinite assignment detected');
268
307
  // return;
269
308
  // }
309
+ if ((_a = options === null || options === void 0 ? void 0 : options.experimental) === null || _a === void 0 ? void 0 : _a.addUpdateAfterSetInCode) {
310
+ useString = (_b = options === null || options === void 0 ? void 0 : options.experimental) === null || _b === void 0 ? void 0 : _b.addUpdateAfterSetInCode(useString, options, {
311
+ node: node,
312
+ code: code,
313
+ types: core_1.types,
314
+ });
315
+ }
270
316
  path.insertAfter(core_1.types.callExpression(core_1.types.identifier(useString), []));
271
317
  }
272
318
  }
@@ -279,17 +325,17 @@ var htmlDecode = function (html) { return html.replace(/&quot;/gi, '"'); };
279
325
  var componentToHtml = function (options) {
280
326
  if (options === void 0) { options = {}; }
281
327
  return function (_a) {
282
- var _b, _c, _d;
328
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k;
283
329
  var component = _a.component;
284
330
  var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'script' });
285
331
  var json = (0, fast_clone_1.fastClone)(component);
286
332
  if (options.plugins) {
287
333
  json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
288
334
  }
289
- replaceForNameIdentifiers(json, useOptions);
290
335
  addUpdateAfterSet(json, useOptions);
291
336
  var componentHasProps = (0, has_props_1.hasProps)(json);
292
337
  var hasLoop = (0, has_component_1.hasComponent)('For', json);
338
+ var hasShow = (0, has_component_1.hasComponent)('Show', json);
293
339
  if (options.plugins) {
294
340
  json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
295
341
  }
@@ -313,7 +359,7 @@ var componentToHtml = function (options) {
313
359
  valueMapper: function (value) {
314
360
  return addUpdateAfterSetInCode(updateReferencesInCode(value, useOptions), useOptions);
315
361
  },
316
- }), ";\n ").concat(componentHasProps ? "let props = {};" : '', "\n\n ").concat(!hasChangeListeners
362
+ }), ";\n ").concat(componentHasProps ? "let props = {};" : '', "\n let nodesToDestroy = [];\n ").concat(!((_d = (_c = json.hooks) === null || _c === void 0 ? void 0 : _c.onInit) === null || _d === void 0 ? void 0 : _d.code) ? '' : 'let onInitOnce = false;', "\n\n function destroyAnyNodes() {\n // destroy current view template refs before rendering again\n nodesToDestroy.forEach(el => el.remove());\n nodesToDestroy = [];\n }\n ").concat(!hasChangeListeners
317
363
  ? ''
318
364
  : "\n \n // Function to update data bindings and loops\n // call update() when you mutate state and need the updates to reflect\n // in the dom\n function update() {\n ".concat(Object.keys(useOptions.onChangeJsById)
319
365
  .map(function (key) {
@@ -323,16 +369,20 @@ var componentToHtml = function (options) {
323
369
  }
324
370
  return "\n document.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el, index) => {\n ").concat(value, "\n })\n ");
325
371
  })
326
- .join('\n\n'), "\n\n ").concat(!((_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.length)
372
+ .join('\n\n'), "\n\n destroyAnyNodes();\n\n ").concat(!((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)
327
373
  ? ''
328
374
  : "\n ".concat(json.hooks.onUpdate.map(function (hook) {
329
375
  return updateReferencesInCode(hook.code, useOptions);
330
- }), " \n "), "\n }\n\n ").concat(useOptions.js, "\n\n // Update with initial state on first load\n update();\n "), "\n\n ").concat(!((_d = json.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
376
+ }), " \n "), "\n }\n\n ").concat(useOptions.js, "\n\n // Update with initial state on first load\n update();\n "), "\n\n ").concat(!((_g = (_f = json.hooks) === null || _f === void 0 ? void 0 : _f.onInit) === null || _g === void 0 ? void 0 : _g.code)
377
+ ? ''
378
+ : "\n if (!onInitOnce) {\n ".concat(updateReferencesInCode((_j = (_h = json.hooks) === null || _h === void 0 ? void 0 : _h.onInit) === null || _j === void 0 ? void 0 : _j.code, useOptions), "\n onInitOnce = true;\n }\n "), "\n\n ").concat(!((_k = json.hooks.onMount) === null || _k === void 0 ? void 0 : _k.code)
331
379
  ? ''
332
380
  : // TODO: make prettier by grabbing only the function body
333
- "\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), " \n "), "\n\n ").concat(!hasLoop
381
+ "\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), " \n "), "\n\n ").concat(!hasShow
382
+ ? ''
383
+ : "\n function showContent(el) {\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content\n // grabs the content of a node that is between <template> tags\n // iterates through child nodes to register all content including text elements\n // attaches the content after the template\n \n \n const elementFragment = el.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n children.forEach(child => {\n ".concat(options.format === 'class' ? 'this.' : '', "nodesToDestroy.push(child);\n });\n el.after(elementFragment);\n }\n \n "), "\n ").concat(!hasLoop
334
384
  ? ''
335
- : "\n\n // Helper to render loops\n function renderLoop(el, array, template, itemName) {\n el.innerHTML = '';\n for (let value of array) {\n let tmp = document.createElement('span');\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach(function (child) {\n contextMap.set(child, {\n ...contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n // Helper to pass context down for loops\n let contextMap = new WeakMap();\n function getContext(el, name) {\n let parent = el;\n do {\n let context = contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode)\n }\n ", "\n })()\n </script>\n ");
385
+ : "\n // Helper to render loops\n function renderLoop(el, array, template, itemName, itemIndex, collectionName) {\n el.innerHTML = \"\";\n for (let [index, value] of array.entries()) {\n let tmp = document.createElement(\"span\");\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach((child) => {\n if (itemName !== undefined) {\n child['__' + itemName] = value;\n }\n if (itemIndex !== undefined) {\n child['__' + itemIndex] = index;\n }\n if (collectionName !== undefined) {\n child['__' + collectionName] = array;\n }\n el.appendChild(child);\n });\n }\n }\n\n function getContext(el, name) {\n do {\n let value = el['__' + name]\n if (value !== undefined) {\n return value\n }\n } while ((el = el.parentNode));\n }\n ", "\n })()\n </script>\n ");
336
386
  }
337
387
  if (options.plugins) {
338
388
  str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
@@ -365,7 +415,7 @@ exports.componentToHtml = componentToHtml;
365
415
  var componentToCustomElement = function (options) {
366
416
  if (options === void 0) { options = {}; }
367
417
  return function (_a) {
368
- var _b, _c, _d, _e;
418
+ var _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16;
369
419
  var component = _a.component;
370
420
  var useOptions = __assign(__assign({}, options), { onChangeJsById: {}, js: '', namesMap: {}, format: 'class' });
371
421
  var json = (0, fast_clone_1.fastClone)(component);
@@ -373,20 +423,37 @@ var componentToCustomElement = function (options) {
373
423
  json = (0, plugins_1.runPreJsonPlugins)(json, options.plugins);
374
424
  }
375
425
  var componentHasProps = (0, has_props_1.hasProps)(json);
376
- replaceForNameIdentifiers(json, useOptions);
377
426
  addUpdateAfterSet(json, useOptions);
378
427
  var hasLoop = (0, has_component_1.hasComponent)('For', json);
428
+ var hasShow = (0, has_component_1.hasComponent)('Show', json);
379
429
  if (options.plugins) {
380
430
  json = (0, plugins_1.runPostJsonPlugins)(json, options.plugins);
381
431
  }
382
- var css = (0, collect_styles_1.collectCss)(json, {
383
- prefix: options.prefix,
384
- });
432
+ var css = '';
433
+ if ((_b = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _b === void 0 ? void 0 : _b.css) {
434
+ css = (_c = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _c === void 0 ? void 0 : _c.css(json, useOptions, {
435
+ collectCss: collect_styles_1.collectCss,
436
+ prefix: options.prefix,
437
+ });
438
+ }
439
+ else {
440
+ css = (0, collect_styles_1.collectCss)(json, {
441
+ prefix: options.prefix,
442
+ });
443
+ }
385
444
  (0, strip_meta_properties_1.stripMetaProperties)(json);
386
445
  var html = json.children
387
446
  .map(function (item) { return blockToHtml(item, useOptions); })
388
447
  .join('\n');
389
- html += "<style>".concat(css, "</style>");
448
+ if ((_d = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _d === void 0 ? void 0 : _d.childrenHtml) {
449
+ html = (_e = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _e === void 0 ? void 0 : _e.childrenHtml(html, json, useOptions);
450
+ }
451
+ if ((_f = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _f === void 0 ? void 0 : _f.cssHtml) {
452
+ html += (_g = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _g === void 0 ? void 0 : _g.cssHtml(css);
453
+ }
454
+ else {
455
+ html += "<style>".concat(css, "</style>");
456
+ }
390
457
  if (options.prettier !== false) {
391
458
  try {
392
459
  html = (0, standalone_1.format)(html, {
@@ -409,7 +476,9 @@ var componentToCustomElement = function (options) {
409
476
  var kebabName = component.name
410
477
  .replace(/([a-z])([A-Z])/g, '$1-$2')
411
478
  .toLowerCase();
412
- var str = "\n ".concat((0, render_imports_1.renderPreComponent)(json), "\n /**\n * Usage:\n * \n * <").concat(kebabName, "></").concat(kebabName, ">\n * \n */\n class ").concat(component.name, " extends HTMLElement {\n constructor() {\n super();\n\n const self = this;\n this.state = ").concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
479
+ var str = "\n ".concat((0, render_imports_1.renderPreComponent)(json), "\n /**\n * Usage:\n * \n * <").concat(kebabName, "></").concat(kebabName, ">\n * \n */\n class ").concat(component.name, " extends ").concat(((_h = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _h === void 0 ? void 0 : _h.classExtends)
480
+ ? (_j = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _j === void 0 ? void 0 : _j.classExtends(json, useOptions)
481
+ : 'HTMLElement', " {\n constructor() {\n super();\n const self = this;\n ").concat(!((_l = (_k = json.hooks) === null || _k === void 0 ? void 0 : _k.onInit) === null || _l === void 0 ? void 0 : _l.code) ? '' : 'this.onInitOnce = false;', "\n this.state = ").concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json, {
413
482
  valueMapper: function (value) {
414
483
  return (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, strip_state_and_props_refs_1.stripStateAndPropsRefs)(addUpdateAfterSetInCode(value, useOptions, 'self.update'), {
415
484
  includeProps: false,
@@ -425,28 +494,59 @@ var componentToCustomElement = function (options) {
425
494
  },
426
495
  }), ";\n ").concat(componentHasProps /* TODO: accept these as attributes/properties on the custom element */
427
496
  ? "this.props = {};"
428
- : '', "\n\n ").concat(!hasLoop
497
+ : '', "\n\n\n // used to keep track of all nodes created by show/for\n this.nodesToDestroy = [];\n ").concat(((_m = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _m === void 0 ? void 0 : _m.componentConstructor)
498
+ ? (_o = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _o === void 0 ? void 0 : _o.componentConstructor(json, useOptions)
499
+ : '', "\n\n ").concat(useOptions.js, "\n\n if (").concat((_p = json.meta.useMetadata) === null || _p === void 0 ? void 0 : _p.isAttachedToShadowDom, ") {\n this.attachShadow({ mode: 'open' })\n }\n }\n\n\n ").concat(!((_q = json.hooks.onUnMount) === null || _q === void 0 ? void 0 : _q.code)
500
+ ? ''
501
+ : "\n disconnectedCallback() {\n ".concat(((_r = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _r === void 0 ? void 0 : _r.disconnectedCallback)
502
+ ? (_s = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _s === void 0 ? void 0 : _s.disconnectedCallback(json, useOptions)
503
+ : "\n // onUnMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onUnMount.code, useOptions), useOptions), "\n this.destroyAnyNodes(); // clean up nodes when component is destroyed\n ").concat(!((_u = (_t = json.hooks) === null || _t === void 0 ? void 0 : _t.onInit) === null || _u === void 0 ? void 0 : _u.code) ? '' : 'this.onInitOnce = false;', "\n "), "\n }\n "), "\n\n destroyAnyNodes() {\n // destroy current view template refs before rendering again\n this.nodesToDestroy.forEach(el => el.remove());\n this.nodesToDestroy = [];\n }\n\n get _root() {\n return this.shadowRoot || this;\n }\n\n connectedCallback() {\n ").concat(((_v = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _v === void 0 ? void 0 : _v.connectedCallbackUpdate)
504
+ ? (_w = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _w === void 0 ? void 0 : _w.connectedCallbackUpdate(json, html, useOptions)
505
+ : "\n this._root.innerHTML = `\n ".concat(html, "`;\n this.render();\n ").concat(!((_y = (_x = json.hooks) === null || _x === void 0 ? void 0 : _x.onInit) === null || _y === void 0 ? void 0 : _y.code) ? '' : 'this.onInit();', "\n this.onMount();\n this.onUpdate();\n "), "\n }\n ").concat(!((_0 = (_z = json.hooks) === null || _z === void 0 ? void 0 : _z.onInit) === null || _0 === void 0 ? void 0 : _0.code)
506
+ ? ''
507
+ : "\n onInit() {\n ".concat(!((_2 = (_1 = json.hooks) === null || _1 === void 0 ? void 0 : _1.onInit) === null || _2 === void 0 ? void 0 : _2.code)
508
+ ? ''
509
+ : "\n if (!this.onInitOnce) {\n ".concat(updateReferencesInCode((_4 = (_3 = json.hooks) === null || _3 === void 0 ? void 0 : _3.onInit) === null || _4 === void 0 ? void 0 : _4.code, useOptions), "\n this.onInitOnce = true;\n }"), "\n }\n "), "\n\n ").concat(!hasShow
429
510
  ? ''
430
- : "\n // Helper to pass context down for loops\n this.contextMap = new WeakMap();\n ", "\n\n ").concat(useOptions.js, "\n\n if (").concat((_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.isAttachedToShadowDom, ") {\n this.attachShadow({ mode: 'open' })\n }\n }\n\n\n ").concat(!((_c = json.hooks.onUnMount) === null || _c === void 0 ? void 0 : _c.code)
511
+ : "\n showContent(el) {\n // https://developer.mozilla.org/en-US/docs/Web/API/HTMLTemplateElement/content\n // grabs the content of a node that is between <template> tags\n // iterates through child nodes to register all content including text elements\n // attaches the content after the template\n \n \n const elementFragment = el.content.cloneNode(true);\n const children = Array.from(elementFragment.childNodes)\n children.forEach(child => {\n this.nodesToDestroy.push(child);\n });\n el.after(elementFragment);\n }", "\n ").concat(!((_5 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _5 === void 0 ? void 0 : _5.attributeChangedCallback)
431
512
  ? ''
432
- : "\n disconnectedCallback() {\n // onUnMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onUnMount.code, useOptions), useOptions), "\n }\n "), "\n\n get _root() {\n return this.shadowRoot || this;\n }\n\n connectedCallback() {\n this._root.innerHTML = `\n ").concat(html, "`;\n this.onMount();\n this.update();\n }\n\n onMount() {\n ").concat(!((_d = json.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
513
+ : "\n attributeChangedCallback(name, oldValue, newValue) {\n ".concat((_6 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _6 === void 0 ? void 0 : _6.attributeChangedCallback(['name', 'oldValue', 'newValue'], json, useOptions), "\n }\n "), "\n\n onMount() {\n ").concat(!((_7 = json.hooks.onMount) === null || _7 === void 0 ? void 0 : _7.code)
433
514
  ? ''
434
515
  : // TODO: make prettier by grabbing only the function body
435
- "\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), "\n "), "\n }\n\n onUpdate() {\n ").concat(!((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)
516
+ "\n // onMount\n ".concat(updateReferencesInCode(addUpdateAfterSetInCode(json.hooks.onMount.code, useOptions), useOptions), "\n "), "\n }\n\n onUpdate() {\n ").concat(!((_8 = json.hooks.onUpdate) === null || _8 === void 0 ? void 0 : _8.length)
436
517
  ? ''
437
518
  : "\n ".concat(json.hooks.onUpdate.map(function (hook) {
438
519
  return updateReferencesInCode(hook.code, useOptions);
439
- }), " \n "), " \n }\n\n update() {\n this.onUpdate();\n this.updateBindings();\n }\n\n updateBindings() {\n ").concat(Object.keys(useOptions.onChangeJsById)
520
+ }), " \n "), " \n }\n\n update() {\n ").concat(!((_9 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _9 === void 0 ? void 0 : _9.shouldComponentUpdateStart)
521
+ ? ''
522
+ : "\n ".concat((_10 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _10 === void 0 ? void 0 : _10.shouldComponentUpdateStart(json, useOptions), "\n "), "\n this.render();\n this.onUpdate();\n ").concat(!((_11 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _11 === void 0 ? void 0 : _11.shouldComponentUpdateEnd)
523
+ ? ''
524
+ : "\n ".concat((_12 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _12 === void 0 ? void 0 : _12.shouldComponentUpdateEnd(json, useOptions), "\n "), "\n }\n\n render() {\n // re-rendering needs to ensure that all nodes generated by for/show are refreshed\n this.destroyAnyNodes();\n ").concat(((_13 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _13 === void 0 ? void 0 : _13.updateBindings)
525
+ ? (_14 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _14 === void 0 ? void 0 : _14.updateBindings(json, useOptions)
526
+ : 'this.updateBindings();', "\n }\n\n updateBindings() {\n ").concat(Object.keys(useOptions.onChangeJsById)
440
527
  .map(function (key) {
528
+ var _a, _b, _c, _d, _e, _f, _g;
441
529
  var value = useOptions.onChangeJsById[key];
442
530
  if (!value) {
443
531
  return '';
444
532
  }
445
- return "\n this._root.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el, index) => {\n ").concat(updateReferencesInCode(value, useOptions), "\n })\n ");
533
+ var code = '';
534
+ if ((_a = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _a === void 0 ? void 0 : _a.updateBindings) {
535
+ key = (_c = (_b = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _b === void 0 ? void 0 : _b.updateBindings) === null || _c === void 0 ? void 0 : _c.key(key, value, useOptions);
536
+ code = (_e = (_d = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _d === void 0 ? void 0 : _d.updateBindings) === null || _e === void 0 ? void 0 : _e.code(key, value, useOptions);
537
+ }
538
+ else {
539
+ code = updateReferencesInCode(value, useOptions);
540
+ }
541
+ return "\n ".concat(((_f = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _f === void 0 ? void 0 : _f.generateQuerySelectorAll)
542
+ ? "\n ".concat((_g = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _g === void 0 ? void 0 : _g.generateQuerySelectorAll(key, code), "\n ")
543
+ : " \n this._root.querySelectorAll(\"[data-name='".concat(key, "']\").forEach((el) => {\n ").concat(code, "\n })\n "), "\n ");
446
544
  })
447
545
  .join('\n\n'), "\n }\n\n ").concat(!hasLoop
448
546
  ? ''
449
- : "\n\n // Helper to render loops\n renderLoop(el, array, template, itemName) {\n el.innerHTML = '';\n for (let value of array) {\n let tmp = document.createElement('span');\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach((child) => {\n this.contextMap.set(child, {\n ...this.contextMap.get(child),\n [itemName]: value\n });\n el.appendChild(child);\n });\n }\n }\n\n getContext(el, name) {\n let parent = el;\n do {\n let context = this.contextMap.get(parent);\n if (context && name in context) {\n return context[name];\n }\n } while (parent = parent.parentNode || parent.host)\n }\n ", "\n }\n\n customElements.define('").concat(kebabName, "', ").concat(component.name, ");\n ");
547
+ : "\n\n // Helper to render loops\n renderLoop(el, array, template, itemName, itemIndex, collectionName) {\n el.innerHTML = \"\";\n for (let [index, value] of array.entries()) {\n let tmp = document.createElement(\"span\");\n tmp.innerHTML = template.innerHTML;\n Array.from(tmp.children).forEach((child) => {\n if (itemName !== undefined) {\n child['__' + itemName] = value;\n }\n if (itemIndex !== undefined) {\n child['__' + itemIndex] = index;\n }\n if (collectionName !== undefined) {\n child['__' + collectionName] = array;\n }\n el.appendChild(child);\n });\n }\n }\n \n getContext(el, name) {\n do {\n let value = el['__' + name]\n if (value !== undefined) {\n return value\n }\n } while ((el = el.parentNode));\n }\n ", "\n }\n\n ").concat(((_15 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _15 === void 0 ? void 0 : _15.customElementsDefine)
548
+ ? (_16 = useOptions === null || useOptions === void 0 ? void 0 : useOptions.experimental) === null || _16 === void 0 ? void 0 : _16.customElementsDefine(kebabName, component, useOptions)
549
+ : "customElements.define('".concat(kebabName, "', ").concat(component.name, ");"), "\n ");
450
550
  if (options.plugins) {
451
551
  str = (0, plugins_1.runPreCodePlugins)(str, options.plugins);
452
552
  }
@@ -69,7 +69,9 @@ var NODE_MAPPERS = {
69
69
  },
70
70
  For: function (json, options) {
71
71
  var wrap = wrapInFragment(json);
72
- return "{".concat(processBinding(json.bindings.each, options), "?.map((").concat(json.properties._forName, ", index) => (\n ").concat(wrap ? '<>' : '').concat(json.children
72
+ return "{".concat(processBinding(json.bindings.each, options), "?.map((").concat(json.properties._forName).concat(json.properties._indexName ? ',' + json.properties._indexName : '').concat(json.properties._collectionName
73
+ ? ',' + json.properties._collectionName
74
+ : '', ") => (\n ").concat(wrap ? '<>' : '').concat(json.children
73
75
  .filter(filter_empty_text_nodes_1.filterEmptyTextNodes)
74
76
  .map(function (item) { return (0, exports.blockToReact)(item, options); })
75
77
  .join('\n')).concat(wrap ? '</>' : '', "\n ))}");
@@ -349,7 +351,7 @@ var componentToReact = function (reactOptions) {
349
351
  };
350
352
  exports.componentToReact = componentToReact;
351
353
  var _componentToReact = function (json, options, isSubComponent) {
352
- var _a, _b, _c, _d, _e, _f;
354
+ var _a, _b, _c, _d, _e, _f, _g;
353
355
  if (isSubComponent === void 0) { isSubComponent = false; }
354
356
  (0, process_http_requests_1.processHttpRequests)(json);
355
357
  (0, handle_missing_state_1.handleMissingState)(json);
@@ -401,7 +403,7 @@ var _componentToReact = function (json, options, isSubComponent) {
401
403
  var nativeStyles = stylesType === 'react-native' &&
402
404
  componentHasStyles &&
403
405
  (0, react_native_1.collectReactNativeStyles)(json);
404
- var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "function ", "(props) {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }\n\n ", "\n\n ", "\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "function ", "(props) {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }\n\n ", "\n\n ", "\n "])), options.type !== 'native'
406
+ var str = (0, dedent_1.default)(templateObject_1 || (templateObject_1 = __makeTemplateObject(["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "function ", "(props) {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }\n\n ", "\n\n ", "\n "], ["\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n ", "\n\n ", "function ", "(props) {\n ", "\n ", "\n ", "\n ", "\n\n ", "\n ", "\n\n ", "\n\n ", "\n\n return (\n ", "\n ", "\n ", "\n ", "\n );\n }\n\n ", "\n\n ", "\n "])), options.type !== 'native'
405
407
  ? ''
406
408
  : "\n import * as React from 'react';\n import { View, StyleSheet, Image, Text } from 'react-native';\n ", styledComponentsCode ? "import styled from 'styled-components';\n" : '', reactLibImports.size
407
409
  ? "import { ".concat(Array.from(reactLibImports).join(', '), " } from 'react'")
@@ -423,15 +425,17 @@ var _componentToReact = function (json, options, isSubComponent) {
423
425
  : stateType === 'builder'
424
426
  ? "var state = useBuilderState(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
425
427
  : "const state = useLocalProxy(".concat((0, get_state_object_string_1.getStateObjectStringFromComponent)(json), ");")
426
- : '', getContextString(json, options), getRefsString(json), getInitCode(json, options), ((_d = json.hooks.onMount) === null || _d === void 0 ? void 0 : _d.code)
428
+ : '', getContextString(json, options), getRefsString(json), getInitCode(json, options), ((_d = json.hooks.onInit) === null || _d === void 0 ? void 0 : _d.code)
429
+ ? "useEffect(() => {\n ".concat(processBinding(updateStateSettersInCode(json.hooks.onInit.code, options), options), "\n }, [])")
430
+ : '', ((_e = json.hooks.onMount) === null || _e === void 0 ? void 0 : _e.code)
427
431
  ? "useEffect(() => {\n ".concat(processBinding(updateStateSettersInCode(json.hooks.onMount.code, options), options), "\n }, [])")
428
- : '', ((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)
432
+ : '', ((_f = json.hooks.onUpdate) === null || _f === void 0 ? void 0 : _f.length)
429
433
  ? json.hooks.onUpdate
430
434
  .map(function (hook) { return "useEffect(() => {\n ".concat(processBinding(updateStateSettersInCode(hook.code, options), options), "\n }, \n ").concat(hook.deps
431
435
  ? processBinding(updateStateSettersInCode(hook.deps, options), options)
432
436
  : '', ")"); })
433
437
  .join(';')
434
- : '', ((_f = json.hooks.onUnMount) === null || _f === void 0 ? void 0 : _f.code)
438
+ : '', ((_g = json.hooks.onUnMount) === null || _g === void 0 ? void 0 : _g.code)
435
439
  ? "useEffect(() => {\n return () => {\n ".concat(processBinding(updateStateSettersInCode(json.hooks.onUnMount.code, options), options), "\n }\n }, [])")
436
440
  : '', wrap ? '<>' : '', json.children.map(function (item) { return (0, exports.blockToReact)(item, options); }).join('\n'), componentHasStyles && stylesType === 'styled-jsx'
437
441
  ? "<style jsx>{`".concat(css, "`}</style>")
@@ -69,7 +69,13 @@ var mappers = {
69
69
  includeState: options.stateType === 'variables',
70
70
  }), " }\n").concat(json.children
71
71
  .map(function (item) { return (0, exports.blockToSvelte)({ json: item, options: options, parentComponent: parentComponent }); })
72
- .join('\n'), "\n{/if}");
72
+ .join('\n'), "\n\n ").concat(json.meta.else
73
+ ? "\n {:else}\n ".concat((0, exports.blockToSvelte)({
74
+ json: json.meta.else,
75
+ options: options,
76
+ parentComponent: parentComponent,
77
+ }), "\n ")
78
+ : '', "\n{/if}");
73
79
  },
74
80
  };
75
81
  var getContextCode = function (json) {
@@ -83,7 +89,9 @@ var setContextCode = function (json) {
83
89
  return Object.keys(contextSetters)
84
90
  .map(function (key) {
85
91
  var _a = contextSetters[key], value = _a.value, name = _a.name;
86
- return "setContext(".concat(name, ".key, ").concat(value ? (0, get_state_object_string_1.getMemberObjectString)(value) : 'undefined', ");");
92
+ return "setContext(".concat(name, ".key, ").concat(value
93
+ ? (0, strip_state_and_props_refs_1.stripStateAndPropsRefs)((0, get_state_object_string_1.getMemberObjectString)(value))
94
+ : 'undefined', ");");
87
95
  })
88
96
  .join('\n');
89
97
  };
@@ -196,9 +196,9 @@ var blockToVue = function (node, options) {
196
196
  }
197
197
  if (node.name === 'style') {
198
198
  // Vue doesn't allow <style>...</style> in templates, but does support the synonymous
199
- // <component is="style">...</component>
199
+ // <component is="'style'">...</component>
200
200
  node.name = 'component';
201
- node.bindings.is = 'style';
201
+ node.bindings.is = "'style'";
202
202
  }
203
203
  if (node.properties._text) {
204
204
  return "".concat(node.properties._text);
@@ -1,2 +1,2 @@
1
1
  import { MitosisComponent } from '../types/mitosis-component';
2
- export declare const renderPreComponent: (component: MitosisComponent, target?: "html" | "template" | "angular" | "builder" | "customElement" | "mitosis" | "liquid" | "react" | "reactNative" | "solid" | "svelte" | "swift" | "webcomponent" | "vue" | undefined) => string;
2
+ export declare const renderPreComponent: (component: MitosisComponent, target?: "angular" | "builder" | "customElement" | "html" | "mitosis" | "liquid" | "react" | "reactNative" | "solid" | "svelte" | "swift" | "template" | "webcomponent" | "vue" | undefined) => string;
@@ -55,6 +55,7 @@ export declare const builderContentToMitosisComponent: (builderContent: BuilderC
55
55
  };
56
56
  hooks: {
57
57
  init?: import("..").extendedHook | undefined;
58
+ onInit?: import("..").extendedHook | undefined;
58
59
  onMount?: import("..").extendedHook | undefined;
59
60
  onUnMount?: import("..").extendedHook | undefined;
60
61
  preComponent?: import("..").extendedHook | undefined;
@@ -88,6 +89,7 @@ export declare const builderContentToMitosisComponent: (builderContent: BuilderC
88
89
  };
89
90
  hooks: {
90
91
  init?: import("..").extendedHook | undefined;
92
+ onInit?: import("..").extendedHook | undefined;
91
93
  onMount?: import("..").extendedHook | undefined;
92
94
  onUnMount?: import("..").extendedHook | undefined;
93
95
  preComponent?: import("..").extendedHook | undefined;