From c439b1641da8c62807c3a76414bfa46aacf1a750 Mon Sep 17 00:00:00 2001 From: sidmohanty11 Date: Thu, 2 Jan 2025 18:28:23 +0530 Subject: [PATCH] add --- .changeset/chatty-islands-camp.md | 5 +++++ packages/sdks/mitosis.config.cjs | 36 +++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+) create mode 100644 .changeset/chatty-islands-camp.md diff --git a/.changeset/chatty-islands-camp.md b/.changeset/chatty-islands-camp.md new file mode 100644 index 00000000000..d053da4d6ec --- /dev/null +++ b/.changeset/chatty-islands-camp.md @@ -0,0 +1,5 @@ +--- +"@builder.io/sdk-angular": patch +--- + +Fix: mark text as safe to remove the Angular stripping/warning message diff --git a/packages/sdks/mitosis.config.cjs b/packages/sdks/mitosis.config.cjs index 71bb54ebf0e..4437d32dc28 100644 --- a/packages/sdks/mitosis.config.cjs +++ b/packages/sdks/mitosis.config.cjs @@ -718,6 +718,41 @@ const ANGULAR_COMPONENT_REF_UPDATE_TEMPLATE_SSR = () => ({ }, }); +const ANGULAR_TEXT_MARK_SAFE_HTML = () => ({ + code: { + post: (code) => { + if (code.includes('selector: "builder-text"')) { + code = + `import { DomSanitizer } from "@angular/platform-browser";\n` + code; + + const constructorIndex = code.indexOf('constructor'); + + if (constructorIndex === -1) { + // not found + const ngOnInitIndex = code.indexOf('ngOnInit'); + code = + code.slice(0, ngOnInitIndex) + + `constructor(protected sanitizer: DomSanitizer) {}\n` + + code.slice(ngOnInitIndex); + } else { + throw new Error( + 'constructor found which should not be here. If you see this, please fix the ANGULAR_TEXT_MARK_SAFE_HTML Plugin.' + ); + } + + const variableName = code.match(/\[innerHTML\]="([^"]+)"/)?.[1]; + if (variableName) { + code = code.replace( + `[innerHTML]="${variableName}"`, + `[innerHTML]="sanitizer.bypassSecurityTrustHtml(${variableName})"` + ); + } + } + return code; + }, + }, +}); + /** * @type {MitosisConfig} */ @@ -746,6 +781,7 @@ module.exports = { ANGULAR_ADD_UNUSED_PROP_TYPES, ANGULAR_NOWRAP_INTERACTIVE_ELEMENT_PLUGIN, ANGULAR_COMPONENT_REF_UPDATE_TEMPLATE_SSR, + ANGULAR_TEXT_MARK_SAFE_HTML, ], }, solid: {