UNPKG

@taiga-ui/cdk

Version:

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

45 lines 2.52 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.migrateTuiNotification = migrateTuiNotification; const elements_1 = require("../../../../utils/templates/elements"); const template_resource_1 = require("../../../../utils/templates/template-resource"); const replace_tag_1 = require("../../../utils/templates/replace-tag"); const NOTIFICATION_ATTRIBUTE = [ 'tuiNotification', '[tuiNotification]', '[(tuiNotification)]', ].map((attr) => attr.toLowerCase()); function migrateTuiNotification({ resource, recorder, fileSystem, }) { const template = (0, template_resource_1.getTemplateFromTemplateResource)(resource, fileSystem); const templateOffset = (0, template_resource_1.getTemplateOffset)(resource); const notifications = (0, elements_1.findElementsByTagName)(template, 'tui-notification'); notifications.forEach((element) => { const location = element.sourceCodeLocation; const startTag = location === null || location === void 0 ? void 0 : location.startTag; if (!startTag) { return; } const attrsToAdd = element.attrs.some(({ name }) => NOTIFICATION_ATTRIBUTE.includes(name)) ? [] : ['tuiNotification']; const raw = template.slice(startTag.startOffset, startTag.endOffset); const isSelfClosing = raw.trimEnd().endsWith('/>'); if (isSelfClosing) { const old = template.slice(startTag.startOffset, startTag.endOffset); const attrs = element.attrs .map((attr) => (NOTIFICATION_ATTRIBUTE.includes(attr.name) ? null : attr)) .filter(Boolean) .map((attr) => { var _a; return `${attr === null || attr === void 0 ? void 0 : attr.name}="${(_a = attr === null || attr === void 0 ? void 0 : attr.value) !== null && _a !== void 0 ? _a : ''}"`; }) .join(' '); const extraAttr = element.attrs.some(({ name }) => NOTIFICATION_ATTRIBUTE.includes(name)) ? '' : ' tuiNotification'; const newTag = `<div${extraAttr}${attrs ? ` ${attrs}` : ''}></div>`; recorder.remove(templateOffset + startTag.startOffset, old.length); recorder.insertRight(templateOffset + startTag.startOffset, newTag); return; } (0, replace_tag_1.replaceTag)(recorder, location, 'tui-notification', 'div', template, templateOffset, attrsToAdd); }); } //# sourceMappingURL=migrate-notification.js.map