New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@salesforcedevs/docs-components

Package Overview
Dependencies
Maintainers
0
Versions
673
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@salesforcedevs/docs-components - npm Package Compare versions

Comparing version

to
0.7.59-sppage-alpha1

src/modules/doc/amfModelParser/amfModelParser.ts

20

lwc.config.json
{
"modules": [
{ "dir": "src/modules" },
{ "npm": "@salesforcedevs/dx-components" }
{ "npm": "@salesforcedevs/dx-components" },
{ "npm": "@salesforcedevs/dw-components" }
],
"expose": [
"doc/amfReference",
"doc/breadcrumbs",
"doc/content",
"doc/contentCallout",
"doc/doDont",
"doc/contentLayout",
"doc/contentMedia",
"doc/content",
"doc/header"
"doc/docXmlContent",
"doc/header",
"doc/heading",
"doc/headingAnchor",
"doc/overview",
"doc/phase",
"doc/specificationContent",
"doc/versionPicker",
"doc/xmlContent",
"docUtils/utils"
]
}

22

package.json
{
"name": "@salesforcedevs/docs-components",
"version": "0.7.0",
"version": "0.7.59-sppage-alpha1",
"description": "Docs Lightning web components for DSC",

@@ -10,10 +10,20 @@ "license": "MIT",

},
"files": [
"src/modules",
"lwc.config.json"
],
"publishConfig": {
"access": "public"
},
"gitHead": "924c919f0e9214fffb628926b1ac0ad73f9304b7"
"dependencies": {
"@api-components/amf-helper-mixin": "4.5.24",
"classnames": "2.5.1",
"kagekiri": "1.4.2",
"lodash.orderby": "4.6.0",
"lodash.uniqby": "4.7.0",
"query-string": "7.1.3",
"sentence-case": "3.0.4"
},
"devDependencies": {
"@types/classnames": "2.3.1",
"@types/lodash.orderby": "4.6.9",
"@types/lodash.uniqby": "4.7.9"
},
"gitHead": "4629fdd9ca18a13480044ad43515b91945d16aad"
}
/* eslint-disable @lwc/lwc/no-inner-html */
import { createElement, LightningElement, api, track } from "lwc";
import { DocContent, PageReference } from "../../../../../../../typings/custom";
import { DocContent, PageReference } from "typings/custom";
import CodeBlock from "dx/codeBlock";
import Button from "dx/button";
import { highlightTerms } from "dxUtils/highlight";
import ContentCallout from "doc/contentCallout";
import CodeBlock from "dx/codeBlock";
import ContentMedia from "doc/contentMedia";
import Button from "dx/button";
const HIGHLIGHTABLE_SELECTOR = [
"p",
".p",
".shortdesc",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"li",
"dl",
"th",
"td"
].join(",");
const LANGUAGE_MAP: { [key: string]: string } = {
xml: "plain",
html: "plain",
js: "javascript"

@@ -20,11 +35,13 @@ };

@api showPaginationButtons: boolean = false;
@api
set docsData(value) {
this._docRendered = false;
this.docContent = value;
this.docContent = (value && value.trim()) || "";
}
get docsData() {
return this.docContent;
}
_codeBlockTheme: string = "dark";
@api

@@ -34,2 +51,3 @@ set codeBlockTheme(value) {

}
get codeBlockTheme() {

@@ -40,4 +58,6 @@ return this._codeBlockTheme;

@track docContent: DocContent = "";
_codeBlockTheme: string = "dark";
_docRendered: boolean = false;
originalCodeBlockThemeValue: String = "";
connectedCallback() {

@@ -48,4 +68,16 @@ this.template.addEventListener(

);
window.addEventListener(
"highlightedtermchange",
this.updateHighlighted
);
}
disconnectedCallback(): void {
window.removeEventListener(
"highlightedtermchange",
this.updateHighlighted
);
}
updateTheme() {

@@ -61,3 +93,3 @@ this._codeBlockTheme =

renderPaginationButton(anchorEl: HTMLElement) {
const isNext = anchorEl.textContent.includes("Next →");
const isNext = anchorEl.textContent!.includes("Next →");
anchorEl.innerHTML = "";

@@ -82,174 +114,193 @@ const buttonEl = createElement("dx-button", { is: Button });

// field to the template. Hence we manipulate the DOM manually.
insertDocHtml() {
const divEl = this.template.querySelector("div");
insertDocHtml(docContent?: string) {
const divEl = this.getCleanContainer();
// Some simple data mutation to make Prism work on-the-fly with the existing datasource
const templateEl = document.createElement("template");
this.docContent = this.docContent.trim();
// eslint-disable-next-line no-use-before-define
templateEl.innerHTML = this.docContent;
if (divEl) {
divEl.innerHTML = docContent || this.docContent;
// Query the code blocks and create a dx-code-block component that contains the code
const codeBlockEls = templateEl.content.querySelectorAll(
".codeSection"
);
codeBlockEls.forEach((codeBlockEl) => {
codeBlockEl.setAttribute("lwc:dom", "manual");
const classList = codeBlockEl.firstChild.classList;
let language = "";
for (const key in classList) {
if (typeof classList[key] === "string") {
const className = classList[key];
if (className.startsWith("brush:")) {
language = className.split(":")[1];
// Query the code blocks and create a dx-code-block component that contains the code
const codeBlockEls = divEl.querySelectorAll(".codeSection");
codeBlockEls.forEach((codeBlockEl) => {
codeBlockEl.setAttribute("lwc:dom", "manual");
const classList = (codeBlockEl.firstChild as any).classList;
let language = "";
for (const key in classList) {
if (typeof classList[key] === "string") {
const className = classList[key];
if (className.startsWith("brush:")) {
language = className.split(":")[1];
}
}
}
}
const blockCmp = createElement("dx-code-block", { is: CodeBlock });
Object.assign(blockCmp, {
codeBlock: codeBlockEl.innerHTML,
// ! Hot fix for incoming html tags from couchdb for xml blocks, fix me soon please
language: LANGUAGE_MAP[language] || language,
theme: this.codeBlockTheme,
title: "", // Default no title.
variant: this.codeBlockType
const blockCmp = createElement("dx-code-block", {
is: CodeBlock
});
Object.assign(blockCmp, {
codeBlock: codeBlockEl.innerHTML,
// ! Hot fix for incoming html tags from couchdb for xml blocks, fix me soon please
language: LANGUAGE_MAP[language] || language,
theme: this.codeBlockTheme,
header: "", // Default no title.
variant: this.codeBlockType,
isEncoded: true
});
// eslint-disable-next-line no-use-before-define
codeBlockEl.innerHTML = "";
codeBlockEl.appendChild(blockCmp);
});
// eslint-disable-next-line no-use-before-define
codeBlockEl.innerHTML = "";
codeBlockEl.appendChild(blockCmp);
});
// Query the callouts and create a doc-content-callout component that contains the code
const calloutEls = templateEl.content.querySelectorAll(".message");
calloutEls.forEach((calloutEl) => {
const calloutCompEl = createElement("doc-content-callout", {
is: ContentCallout
});
const detailEls = calloutEl.querySelectorAll(
"p, div.data, ol, ul, .codeSection, .mediaBd > span.ph"
);
detailEls.forEach((detailEl) => {
calloutCompEl.appendChild(detailEl);
});
const type = calloutEl.querySelector("h4").textContent;
const typeLower = type.toLowerCase();
Object.assign(calloutCompEl, {
title: type,
variant: typeLower
});
// eslint-disable-next-line no-use-before-define
calloutEl.innerHTML = "";
calloutEl.appendChild(calloutCompEl);
});
// Query the callouts and create a doc-content-callout component that contains the code
const calloutEls = divEl.querySelectorAll(".message");
calloutEls.forEach((calloutEl) => {
const calloutCompEl = createElement("doc-content-callout", {
is: ContentCallout
});
const detailEls = calloutEl.querySelectorAll(
"p, .p, div.data, ol, ul, p+.codeSection, p~.codeSection, div >.codeSection, .mediaBd > span.ph"
);
detailEls.forEach((detailEl) => {
if (detailEl.innerHTML.trim() !== "") {
calloutCompEl.appendChild(detailEl);
}
});
// Modify links to work with any domain, links that start with "#" are excluded
const anchorEls = templateEl.content.querySelectorAll(
"a:not([href^='#'])"
);
anchorEls.forEach((anchorEl) => {
if (
anchorEl.textContent.includes("Next →") ||
anchorEl.textContent.includes("← Previous")
) {
if (this.showPaginationButtons) {
this.renderPaginationButton(anchorEl);
} else {
anchorEl.remove();
let flag = 1;
for (let i: number = 0; i < detailEls.length; i++) {
flag &= (detailEls[i].innerHTML.trim() === "") as any; // Dark Magic TM
}
}
const href = anchorEl.href.split("/");
if (
(href[3] === this.pageReference.docId && this.isStorybook) ||
href[4] === this.pageReference.docId ||
href[6] === this.pageReference.docId
) {
let updatedURL;
switch (href.length) {
case 8:
updatedURL = href.splice(5).join("/");
break;
case 7:
updatedURL = href.splice(4).join("/");
break;
case 6:
updatedURL = href.splice(3).join("/");
break;
default:
updatedURL = href.splice(6).join("/");
break;
if (flag) {
const codeEls = calloutEl.querySelectorAll(".codeSection");
codeEls.forEach((codeEl) => {
calloutCompEl.appendChild(codeEl);
});
}
anchorEl.addEventListener(
"click",
// eslint-disable-next-line no-use-before-define
this.handleNavClick.bind(this)
);
// anchor href event is not propagated here as we want SPA nature.
// But in prerender.io - as javascript is not executed, we want the anchor links are proper (absolute urls).
anchorEl.setAttribute("href", "/docs/" + updatedURL);
anchorEl.setAttribute("data-id", "docs/" + updatedURL);
return;
}
anchorEl.setAttribute("data-id", anchorEl.href);
});
const type = calloutEl.querySelector("h4")!.textContent!;
const typeLower = type.toLowerCase();
Object.assign(calloutCompEl, {
header: type,
variant: typeLower
});
// eslint-disable-next-line no-use-before-define
calloutEl.innerHTML = "";
calloutEl.appendChild(calloutCompEl);
});
// Modify image src to work with any domain and replace images/iframes with doc-content-media
const imgEls = templateEl.content.querySelectorAll("img, iframe");
// Modify links to work with any domain, links that start with "#" are excluded
const anchorEls = divEl.querySelectorAll("a:not([href^='#'])");
imgEls.forEach((mediaEl) => {
const isImage = mediaEl.nodeName === "IMG";
let src = mediaEl.getAttribute("src");
if (!src) {
return;
}
const alt = mediaEl.getAttribute("alt");
const title = mediaEl.getAttribute("title");
const label = mediaEl.getAttribute("label");
const width = mediaEl.getAttribute("width");
const height = mediaEl.getAttribute("height");
anchorEls.forEach((anchorEl: any) => {
if (
anchorEl.textContent!.includes("Next →") ||
anchorEl.textContent!.includes("← Previous")
) {
if (this.showPaginationButtons) {
this.renderPaginationButton(anchorEl);
} else {
anchorEl.remove();
}
}
if (isImage) {
src = src.startsWith("/")
? `https://developer.salesforce.com${src}`
: src.replace(
window.location.origin,
"https://developer.salesforce.com"
);
// ! This is a hack
// Normalize urls in case it doesn't come complete.
if (anchorEl.href.startsWith("atlas.")) {
anchorEl.href = "/docs/" + anchorEl.href;
}
const img: HTMLImageElement = document.createElement("img");
img.src = src;
if (alt) {
img.alt = alt;
const href = anchorEl.href.split("/");
if (
(href[3] === this.pageReference.docId &&
this.isStorybook) ||
href[4] === this.pageReference.docId ||
href[6] === this.pageReference.docId
) {
let updatedURL;
switch (href.length) {
case 8:
updatedURL = href.splice(5).join("/");
break;
case 7:
updatedURL = href.splice(4).join("/");
break;
case 6:
updatedURL = href.splice(3).join("/");
break;
default:
updatedURL = href.splice(6).join("/");
break;
}
anchorEl.addEventListener(
"click",
// eslint-disable-next-line no-use-before-define
this.handleNavClick.bind(this)
);
// anchor href event is not propagated here as we want SPA nature.
// But in prerender.io - as javascript is not executed, we want the anchor links are proper (absolute urls).
anchorEl.setAttribute("href", "/docs/" + updatedURL);
anchorEl.setAttribute("data-id", "docs/" + updatedURL);
return;
}
if (title) {
img.title = title;
anchorEl.setAttribute("data-id", anchorEl.href);
});
// Modify image src to work with any domain and replace images/iframes with doc-content-media
const imgEls = divEl.querySelectorAll("img, iframe");
imgEls.forEach((mediaEl) => {
const isImage = mediaEl.nodeName === "IMG";
let src = mediaEl.getAttribute("src");
if (!src) {
return;
}
if (height) {
img.height = parseFloat(height);
}
if (width) {
img.width = parseFloat(width);
}
const alt = mediaEl.getAttribute("alt");
const title = mediaEl.getAttribute("title");
const label = mediaEl.getAttribute("label");
const width = mediaEl.getAttribute("width");
const height = mediaEl.getAttribute("height");
const className = mediaEl.getAttribute("class");
img.className = "content-image";
mediaEl.parentNode!.insertBefore(img, mediaEl);
} else {
const contentMediaEl = createElement("doc-content-media", {
is: ContentMedia
});
Object.assign(contentMediaEl, {
contentType: "iframe",
contentSrc: src,
mediaTitle: alt || title || label
});
mediaEl.parentNode!.insertBefore(contentMediaEl, mediaEl);
}
mediaEl.remove();
});
if (isImage) {
src = src.startsWith("/")
? `https://developer.salesforce.com${src}`
: src.replace(
window.location.origin,
"https://developer.salesforce.com"
);
if (divEl) {
// eslint-disable-next-line no-use-before-define
divEl.innerHTML = "";
divEl.append(templateEl.content);
const img: HTMLImageElement = document.createElement("img");
img.src = src;
img.alt = "";
if (alt) {
img.alt = alt;
}
if (title) {
img.title = title;
}
if (height) {
img.height = parseFloat(height);
}
if (width) {
img.width = parseFloat(width);
}
if (className) {
img.className = className;
}
img.className = `content-image ${img.className}`;
mediaEl.parentNode!.insertBefore(img, mediaEl);
} else {
const contentMediaEl = createElement("doc-content-media", {
is: ContentMedia
});
Object.assign(contentMediaEl, {
contentType: "iframe",
contentSrc: src,
mediaTitle: alt || title || label
});
mediaEl.parentNode!.insertBefore(contentMediaEl, mediaEl);
}
mediaEl.remove();
});
}

@@ -263,2 +314,11 @@

private getCleanContainer(): HTMLElement | null {
const divEl = this.template.querySelector("div");
if (divEl?.hasChildNodes()) {
divEl.removeChild(divEl.firstChild!);
}
return divEl;
}
isSamePage(reference: PageReference): boolean {

@@ -276,7 +336,5 @@ return (

event.preventDefault();
// eslint-disable-next-line no-use-before-define
const target = event.currentTarget.dataset.id;
const [page, docId, deliverable, tempContentDocumentId] = target.split(
"/"
);
const target = (event.currentTarget! as any).dataset.id;
const [page, docId, deliverable, tempContentDocumentId] =
target.split("/");
const [contentDocumentId, hash] = tempContentDocumentId.split("#");

@@ -305,2 +363,8 @@ const newPageReference = {

updateHighlighted = (event: any) =>
highlightTerms(
this.template.querySelectorAll(HIGHLIGHTABLE_SELECTOR),
event.detail
);
@api

@@ -307,0 +371,0 @@ public navigateToHash(hash: String) {

@@ -6,3 +6,3 @@ import { LightningElement, api } from "lwc";

export default class ContentCallout extends LightningElement {
@api title!: string;
@api header!: string;
@api variant!: CalloutVariant;

@@ -15,2 +15,5 @@ cardVariant?: string;

switch (this.variant) {
case "plain":
this.cardVariant = "dx-callout-plain";
break;
case "tip":

@@ -22,4 +25,4 @@ this.cardVariant = "dx-callout-tip";

case "warning":
this.cardVariant = "dx-callout-warning";
this.iconColor = "gray-10";
this.cardVariant = "doc-status-container dx-callout-warning";
this.iconColor = "red-vibrant-50";
this.iconName = "warning";

@@ -32,2 +35,7 @@ break;

break;
case "important":
this.cardVariant = "doc-status-container dx-callout-important";
this.iconColor = "gray-10";
this.iconName = "announcement";
break;
case "note":

@@ -44,2 +52,3 @@ default:

"dx-callout",
"doc-status-base",
"dx-callout-base_section",

@@ -51,2 +60,6 @@ "dx-callout-base_column",

get hideIcon() {
return this.variant === "plain";
}
private isSlotEmpty: boolean = true;

@@ -53,0 +66,0 @@ private onSlotChange(e: LightningSlotElement) {

import { api } from "lwc";
import cx from "classnames";
import type { Option } from "typings/custom";
import { HeaderBase } from "utils/headerBase";
import { toJson } from "utils/normalizers";
import get from "lodash.get";
import type { OptionWithNested } from "typings/custom";
import { HeaderBase } from "dxBaseElements/headerBase";
import { toJson } from "dxUtils/normalizers";
const TABLET_MATCH = "980px";
const MOBILE_MATCH = "880px";
const SMALL_MOBILE_MATCH = "740px";
const MOBILE_MATCH = "768px";

@@ -26,28 +24,16 @@ export default class Header extends HeaderBase {

@api
get languages() {
return this._languages;
get devCenter() {
return this._devCenter;
}
set languages(value) {
this._languages = toJson(value);
set devCenter(value) {
this._devCenter = toJson(value);
}
@api
get language() {
return this._language;
}
set language(value) {
if (this._language !== value) {
this._language = value;
}
}
private _language: string | null = null;
private _languages!: Option[];
private _scopedNavItems!: Option[];
private smallMobile = false;
private smallMobileMatchMedia!: MediaQueryList;
private _scopedNavItems!: OptionWithNested[];
private tablet = false;
private tabletMatchMedia!: MediaQueryList;
private shouldRender: boolean = false;
private showDocDivider: boolean = false;
private _devCenter: any;

@@ -62,32 +48,2 @@ protected mobileBreakpoint(): string {

private get showDesktopNavItems(): boolean {
return !this.mobile && this.hasNavItems;
}
private get showSignup(): boolean {
return (this.tablet && !this.isSearchOpen) || !this.tablet;
}
private get hasLanguages(): boolean {
return !!(this.languages && this.languages.length);
}
private get showMobileLanguages(): boolean {
return this.smallMobile && this.hasLanguages;
}
private get languageLabel(): string {
return (
(this.language &&
this.languages.find(
(lang) => get(lang, this.langValuePath) === this.language
)?.label) ||
this.languages[0].label
);
}
private get showMenuButton(): boolean {
return this.mobile && this.hasNavItems;
}
connectedCallback(): void {

@@ -101,10 +57,19 @@ super.connectedCallback();

this.smallMobileMatchMedia = window.matchMedia(
`(max-width: ${SMALL_MOBILE_MATCH})`
);
this.onSmallMobileChange(this.smallMobileMatchMedia);
this.smallMobileMatchMedia.addEventListener(
"change",
this.onSmallMobileChange
);
if (
(window.location.pathname.includes("/docs/") &&
window.location.pathname !== "/docs/apis") ||
window.location.pathname ===
"/tableau/embedding-playground/overview" ||
window.location.host === "localhost:6006" ||
window.location.host === "dsc-components.herokuapp.com"
) {
this.shouldRender = true;
}
if (this.shouldRender && window.location.pathname.includes("/docs/")) {
if (!this.brand && !this.mobile) {
this.shouldRender = false;
this.showDocDivider = true;
}
}
}

@@ -118,7 +83,2 @@

);
this.smallMobileMatchMedia.removeEventListener(
"change",
this.onSmallMobileChange
);
}

@@ -129,5 +89,2 @@

private onSmallMobileChange = (e: MediaQueryListEvent | MediaQueryList) =>
(this.smallMobile = e.matches);
protected additionalClasses(): string {

@@ -139,8 +96,2 @@ return cx(

}
private onLangChange(event: CustomEvent<string>): void {
const { detail } = event;
this._language = detail;
this.dispatchEvent(new CustomEvent("langchange", { detail }));
}
}

@@ -14,3 +14,3 @@ import { LightningElement, api } from "lwc";

//const target = event.detail.name.split('-')
const target = event.currentTarget.dataset.id.split("-");
const target = (event.currentTarget as any).dataset.id.split("-");
newPageReference.contentDocumentId = target[0] + ".htm";

@@ -17,0 +17,0 @@ newPageReference.hash = target[1];

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet