@builder.io/mitosis
Version:
Write components once, run everywhere. Compiles to Vue, React, Solid, and Liquid. Import code from Figma and Builder.io
41 lines (40 loc) • 2.14 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getDomRefs = void 0;
const hooks_1 = require("../../../generators/angular/helpers/hooks");
const dash_case_1 = require("../../../helpers/dash-case");
const get_refs_1 = require("../../../helpers/get-refs");
const map_refs_1 = require("../../../helpers/map-refs");
const types_1 = require("@babel/types");
const getDomRefs = ({ json, options, withAttributePassing, rootRef, }) => {
const domRefs = (0, get_refs_1.getRefs)(json);
const nativeElement = options.api === 'signals' ? `()?.nativeElement` : '?.nativeElement';
if (withAttributePassing) {
if (!domRefs.has(rootRef)) {
domRefs.add(rootRef);
}
(0, hooks_1.addCodeNgAfterViewInit)(json, `
const element: HTMLElement | null = this.${rootRef}${nativeElement};
this.enableAttributePassing(element, "${(0, dash_case_1.dashCase)(json.name)}");
`);
}
(0, map_refs_1.mapRefs)(json, (refName, extra) => {
const isDomRef = domRefs.has(refName);
let additional = nativeElement;
if ((extra === null || extra === void 0 ? void 0 : extra.type) === 'bindings' && options.api === 'signals') {
// we don't need nativeElement and this. for bindings in signals
return refName;
}
else if ((extra === null || extra === void 0 ? void 0 : extra.type) === 'hooks-deps-array' && options.api === 'signals') {
// we don't need nativeElement for deps-array in hooks
additional = '()';
}
else if ((extra === null || extra === void 0 ? void 0 : extra.path.parentPath) && (0, types_1.isAssignmentExpression)(extra === null || extra === void 0 ? void 0 : extra.path.parentPath.container)) {
// we cannot use conditionals for assignments, it has to be checked before
additional = options.api === 'signals' ? `()!.nativeElement` : '!.nativeElement';
}
return `this.${isDomRef ? '' : '_'}${refName}${isDomRef ? additional : ''}`;
});
return domRefs;
};
exports.getDomRefs = getDomRefs;
;