@builder.io/mitosis 0.6.4 → 0.6.6

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.
@@ -22,7 +22,7 @@ const standalone_1 = require("prettier/standalone");
22
22
  const componentToStencil = (_options = {
23
23
  typescript: true, // Stencil is uses .tsx always
24
24
  }) => ({ component }) => {
25
- var _a, _b, _c, _d, _e;
25
+ var _a, _b, _c, _d, _e, _f, _g, _h;
26
26
  let json = (0, fast_clone_1.fastClone)(component);
27
27
  const options = (0, merge_options_1.initializeOptions)({
28
28
  target: 'stencil',
@@ -84,7 +84,20 @@ const componentToStencil = (_options = {
84
84
  // Deprecated option, we shouldn't use this, instead change the name of your Mitosis component
85
85
  tagName = (_b = json.meta.useMetadata) === null || _b === void 0 ? void 0 : _b.tagName;
86
86
  }
87
- const coreImports = (0, helpers_1.getStencilCoreImportsAsString)(wrap, events, props, dataString);
87
+ const noDependencyOnUpdateHooks = (_d = (_c = json.hooks.onUpdate) === null || _c === void 0 ? void 0 : _c.filter((hook) => !hook.deps)) !== null && _d !== void 0 ? _d : [];
88
+ /*
89
+ * We want to create a function for every onUpdate hook that has dependencies.
90
+ * We call the function once in "componentDidLoad"
91
+ * And we create "Watch" decorators for every dependency
92
+ */
93
+ const dependencyOnUpdateHooks = (_f = (_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.filter((hook) => hook.deps)) !== null && _f !== void 0 ? _f : [];
94
+ const coreImports = (0, helpers_1.getStencilCoreImportsAsString)({
95
+ wrap,
96
+ events,
97
+ props,
98
+ dataString,
99
+ watch: Boolean(dependencyOnUpdateHooks === null || dependencyOnUpdateHooks === void 0 ? void 0 : dependencyOnUpdateHooks.length),
100
+ });
88
101
  let str = (0, dedent_1.dedent) `
89
102
  ${(0, helpers_1.getImports)(json, options, childComponents)}
90
103
 
@@ -94,7 +107,7 @@ const componentToStencil = (_options = {
94
107
 
95
108
  @Component({
96
109
  tag: '${tagName}',
97
- ${((_c = json.meta.useMetadata) === null || _c === void 0 ? void 0 : _c.isAttachedToShadowDom) ? 'shadow: true,' : ''}
110
+ ${((_g = json.meta.useMetadata) === null || _g === void 0 ? void 0 : _g.isAttachedToShadowDom) ? 'shadow: true,' : ''}
98
111
  ${css.length
99
112
  ? `styles: \`
100
113
  ${(0, indent_1.indent)(css, 8)}\`,`
@@ -107,19 +120,41 @@ const componentToStencil = (_options = {
107
120
  ${methodsString}
108
121
 
109
122
  ${withAttributePassing ? (0, attribute_passing_1.getAttributePassingString)(true) : ''}
123
+
124
+ ${dependencyOnUpdateHooks
125
+ .map((hook, index) => {
126
+ return `
127
+ watch${index}Fn() {
128
+ ${hook.code}
129
+ }
130
+
131
+ ${(0, helpers_1.getDepsAsArray)(hook.deps)
132
+ .map((dep) => `@Watch("${dep}")`)
133
+ .join('\n')}
134
+ watch${index}(){
135
+ this.watch${index}Fn();
136
+ }
137
+ `;
138
+ })
139
+ .join('\n')}
110
140
 
111
141
  ${`componentDidLoad() {
112
142
  ${withAttributePassing
113
143
  ? `this.enableAttributePassing(this.${rootRef}, "${(0, dash_case_1.dashCase)(json.name)}");`
114
144
  : ''}
115
145
  ${json.hooks.onMount.length ? (0, on_mount_1.stringifySingleScopeOnMount)(json) : ''}
146
+ ${dependencyOnUpdateHooks
147
+ .map((_, index) => `this.watch${index}Fn();`)
148
+ .join('\n')}
116
149
  }`}
117
- ${!((_d = json.hooks.onUnMount) === null || _d === void 0 ? void 0 : _d.code)
150
+ ${!((_h = json.hooks.onUnMount) === null || _h === void 0 ? void 0 : _h.code)
118
151
  ? ''
119
152
  : `disconnectedCallback() { ${json.hooks.onUnMount.code} }`}
120
- ${!((_e = json.hooks.onUpdate) === null || _e === void 0 ? void 0 : _e.length)
121
- ? ''
122
- : `componentDidUpdate() { ${json.hooks.onUpdate.map((hook) => hook.code).join('\n')} }`}
153
+ ${noDependencyOnUpdateHooks.length
154
+ ? `componentDidUpdate() { ${noDependencyOnUpdateHooks
155
+ .map((hook) => hook.code)
156
+ .join('\n')} }`
157
+ : ''}
123
158
 
124
159
  render() {
125
160
  return (${wrap ? '<Host>' : ''}
@@ -19,6 +19,18 @@ export declare const needsWrap: (children: MitosisNode[]) => boolean;
19
19
  * @param events
20
20
  * @param props
21
21
  * @param dataString
22
+ * @param watch
22
23
  */
23
- export declare const getStencilCoreImportsAsString: (wrap: boolean, events: string[], props: string[], dataString: string) => string;
24
+ export declare const getStencilCoreImportsAsString: ({ wrap, events, props, dataString, watch, }: {
25
+ wrap: boolean;
26
+ events: string[];
27
+ props: string[];
28
+ dataString: string;
29
+ watch: boolean;
30
+ }) => string;
24
31
  export declare const getImports: (json: MitosisComponent, options: ToStencilOptions, childComponents: string[]) => string;
32
+ /**
33
+ * Converts the deps string into an array of strings
34
+ * @param deps The hook dependencies as string e.g.: "[this.a,this.b]"
35
+ */
36
+ export declare const getDepsAsArray: (deps: string) => string[];
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getImports = exports.getStencilCoreImportsAsString = exports.needsWrap = exports.getPropsAsCode = exports.getTagName = exports.processBinding = exports.isEvent = void 0;
3
+ exports.getDepsAsArray = exports.getImports = exports.getStencilCoreImportsAsString = exports.needsWrap = exports.getPropsAsCode = exports.getTagName = exports.processBinding = exports.isEvent = void 0;
4
4
  const dash_case_1 = require("../../../helpers/dash-case");
5
5
  const event_handlers_1 = require("../../../helpers/event-handlers");
6
6
  const render_imports_1 = require("../../../helpers/render-imports");
@@ -77,13 +77,15 @@ exports.needsWrap = needsWrap;
77
77
  * @param events
78
78
  * @param props
79
79
  * @param dataString
80
+ * @param watch
80
81
  */
81
- const getStencilCoreImportsAsString = (wrap, events, props, dataString) => {
82
+ const getStencilCoreImportsAsString = ({ wrap, events, props, dataString, watch, }) => {
82
83
  const stencilCoreImports = {
83
84
  Component: true,
84
85
  h: true,
85
86
  Fragment: true,
86
87
  Host: wrap,
88
+ Watch: watch,
87
89
  Event: events.length > 0,
88
90
  Prop: props.length > 0,
89
91
  State: dataString.length > 0,
@@ -109,3 +111,16 @@ const getImports = (json, options, childComponents) => {
109
111
  });
110
112
  };
111
113
  exports.getImports = getImports;
114
+ /**
115
+ * Converts the deps string into an array of strings
116
+ * @param deps The hook dependencies as string e.g.: "[this.a,this.b]"
117
+ */
118
+ const getDepsAsArray = (deps) => {
119
+ return deps
120
+ .replace('[', '')
121
+ .replace(']', '')
122
+ .replaceAll('this.', '')
123
+ .split(',')
124
+ .map((dep) => dep.trim());
125
+ };
126
+ exports.getDepsAsArray = getDepsAsArray;
@@ -1021,7 +1021,13 @@ const builderContentPartToMitosisComponent = (builderContent, options = {}) => {
1021
1021
  const voidElemRegex = /(<area|base|br|col|embed|hr|img|input|keygen|link|meta|param|source|track|wbr[^>]+)>/gm;
1022
1022
  try {
1023
1023
  if (((_a = elem.component) === null || _a === void 0 ? void 0 : _a.name) === 'Text') {
1024
- elem.component.options.text = elem.component.options.text.replace(voidElemRegex, '$1 />');
1024
+ const text = elem.component.options.text;
1025
+ elem.component.options.text = text.replace(voidElemRegex, '$1 />');
1026
+ // Remove broken emojis
1027
+ const hasUnpairedSurrogate = /[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/g;
1028
+ if (hasUnpairedSurrogate.test(text)) {
1029
+ elem.component.options.text = text.replace(hasUnpairedSurrogate, '');
1030
+ }
1025
1031
  }
1026
1032
  }
1027
1033
  catch (_error) {
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "name": "Builder.io",
23
23
  "url": "https://www.builder.io"
24
24
  },
25
- "version": "0.6.4",
25
+ "version": "0.6.6",
26
26
  "homepage": "https://github.com/BuilderIO/mitosis",
27
27
  "main": "./dist/src/index.js",
28
28
  "exports": {