UNPKG

@taiga-ui/cdk

Version:

Base library for creating Angular components and applications using Taiga UI principles regarding of actual visual appearance

48 lines (47 loc) 2.49 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.migrateThumbnailCard = 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 migrateThumbnailCard({ 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.findElementsByTagNames)(template, ['tui-thumbnail-card', 'tui-card']); elements.forEach(({ attrs, sourceCodeLocation }) => { if (!sourceCodeLocation) { return; } const valueAttr = (0, inputs_1.findAttr)(attrs, 'cardNumber'); if (!valueAttr) { return; } migrateValue({ valueAttr, sourceCodeLocation, recorder, templateOffset, }); }); } exports.migrateThumbnailCard = migrateThumbnailCard; function migrateValue({ valueAttr, sourceCodeLocation, recorder, templateOffset, }) { var _a, _b, _c, _d, _e; const attrValue = valueAttr === null || valueAttr === void 0 ? void 0 : valueAttr.value; const insertTo = (_b = (_a = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.startTag) === null || _a === void 0 ? void 0 : _a.endOffset) !== null && _b !== void 0 ? _b : 0; const selfClosing = !(sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.endTag); if (!attrValue || !insertTo) { return; } recorder.insertRight(insertTo + templateOffset, valueAttr.name === 'cardnumber' ? attrValue : `{{ ${attrValue} }}${selfClosing ? '</tui-thumbnail-card>' : ''}`); const attrOffset = (_c = sourceCodeLocation === null || sourceCodeLocation === void 0 ? void 0 : sourceCodeLocation.attrs) === null || _c === void 0 ? void 0 : _c[valueAttr.name]; if (attrOffset) { const { startOffset, endOffset } = attrOffset; recorder.remove(templateOffset + startOffset - 1, endOffset - startOffset + 1); } if (selfClosing) { recorder.remove(((_e = (_d = sourceCodeLocation.startTag) === null || _d === void 0 ? void 0 : _d.endOffset) !== null && _e !== void 0 ? _e : 2) - 2, 1); } }