@salesforcedevs/docs-components
Advanced tools
Comparing version 0.13.0 to 0.13.2
{ | ||
"name": "@salesforcedevs/docs-components", | ||
"version": "0.13.0", | ||
"version": "0.13.2", | ||
"description": "Docs Lightning web components for DSC", | ||
@@ -17,3 +17,3 @@ "license": "MIT", | ||
}, | ||
"gitHead": "712b43fcdf2478ace9dd7b6b41b6850762c74314" | ||
"gitHead": "dc3c93441a0f1cde3faaf1bfafbbf7bd5c4d29ff" | ||
} |
@@ -120,25 +120,2 @@ import { createRenderComponent } from "utils/tests"; | ||
}); | ||
it("highlights text that matches search criteria", () => { | ||
const component = render({ | ||
docsData: mockContent.content, | ||
pageReference: mockPageReference, | ||
isStorybook: true | ||
}); | ||
const contentEl = component.shadowRoot.querySelector( | ||
'[data-name="content"]' | ||
); | ||
contentEl.dispatchEvent( | ||
new CustomEvent("highlightedtermchange", { | ||
detail: "apex", | ||
composed: true, | ||
bubbles: true | ||
}) | ||
); | ||
const highlightedSpanEls = contentEl.querySelectorAll(".highlight"); | ||
expect(highlightedSpanEls.length).toEqual(14); | ||
}); | ||
}); |
@@ -38,4 +38,2 @@ /* eslint-disable @lwc/lwc/no-inner-html */ | ||
originalCodeBlockThemeValue: String = ""; | ||
_ogContent: string = ""; | ||
connectedCallback() { | ||
@@ -46,15 +44,4 @@ this.template.addEventListener( | ||
); | ||
window.addEventListener("highlightedtermchange", (e: any) => | ||
this.updateHighlighted(e.detail) | ||
); | ||
} | ||
disconnectedCallback(): void { | ||
window.removeEventListener( | ||
"highlightedtermchange", | ||
this.updateHighlighted | ||
); | ||
} | ||
updateTheme() { | ||
@@ -69,28 +56,2 @@ this._codeBlockTheme = | ||
updateHighlighted(searchTerm: string) { | ||
const divEl = this.template.querySelector("div"); | ||
if (divEl) { | ||
divEl.innerHTML = this._ogContent; | ||
const divChildNodes = divEl.childNodes; | ||
divChildNodes.forEach((node) => { | ||
this.highlight(node, searchTerm); | ||
}); | ||
} | ||
} | ||
highlight(element: any, searchTerm: string) { | ||
const text = element.innerHTML; | ||
if (text) { | ||
const regexp = new RegExp(`${searchTerm}(?![^<>]*>)`, "gi"); | ||
const highlightedText = text.replace( | ||
regexp, | ||
`<span class="highlight">$&</span>` | ||
); | ||
element.innerHTML = highlightedText; | ||
} | ||
} | ||
renderPaginationButton(anchorEl: HTMLElement) { | ||
@@ -358,4 +319,3 @@ const isNext = anchorEl.textContent.includes("Next →"); | ||
this._docRendered = true; | ||
this._ogContent = this.template.querySelector("div").innerHTML; | ||
} | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
157715
3998