@taiga-ui/cdk
Version:
Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance
34 lines • 2.93 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.migrateExpandable = void 0;
const elements_1 = require("../../../../utils/templates/elements");
const inputs_1 = require("../../../../utils/templates/inputs");
const template_resource_1 = require("../../../../utils/templates/template-resource");
function migrateExpandable({ resource, recorder, fileSystem, }) {
const template = (0, template_resource_1.getTemplateFromTemplateResource)(resource, fileSystem);
const templateOffset = (0, template_resource_1.getTemplateOffset)(resource);
const elements = (0, elements_1.findElementsWithAttributeOnTag)(template, ['[expandable]'], ['tui-input-tag', 'tui-multi-select', 'tui-input-date']);
elements.forEach(({ attrs, sourceCodeLocation }) => {
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
const expandableAttr = (0, inputs_1.findAttr)(attrs, 'expandable');
if (!expandableAttr) {
return;
}
const expandableValue = expandableAttr === null || expandableAttr === void 0 ? void 0 : expandableAttr.value;
const expandableStart = (_c = (_b = (_a = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.attrs) === null || _a === void 0 ? void 0 : _a[expandableAttr.name]) === null || _b === void 0 ? void 0 : _b.startOffset) !== null && _c !== void 0 ? _c : 0;
const expandableEnd = (_f = (_e = (_d = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.attrs) === null || _d === void 0 ? void 0 : _d[expandableAttr.name]) === null || _e === void 0 ? void 0 : _e.endOffset) !== null && _f !== void 0 ? _f : 0;
if (expandableValue === 'false') {
const rowsAttr = (0, inputs_1.findAttr)(attrs, 'rows');
const insertTo = ((_h = (_g = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.startTag) === null || _g === void 0 ? void 0 : _g.endOffset) !== null && _h !== void 0 ? _h : 0) - 1;
const insertOffset = templateOffset + insertTo;
const selfClosing = template[insertOffset - 1] === '/';
recorder.insertRight(selfClosing ? insertOffset - 1 : insertOffset, rowsAttr ? '' : '[rows]="1"');
}
if (expandableValue !== 'false' && expandableValue !== 'true') {
recorder.insertRight(templateOffset + ((_k = (_j = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.startTag) === null || _j === void 0 ? void 0 : _j.startOffset) !== null && _k !== void 0 ? _k : 0), '<!-- TODO: (Taiga UI migration) "expandable" property has been removed. Use "rows" property instead -->\n');
}
recorder.remove(templateOffset + expandableStart, expandableEnd - expandableStart);
});
}
exports.migrateExpandable = migrateExpandable;
//# sourceMappingURL=migrate-expandable.js.map