@kontent-ai/smart-link
Version:
Kontent.ai Smart Link SDK allowing to automatically inject [smart links](https://docs.kontent.ai/tutorials/develop-apps/build-strong-foundation/set-up-editing-from-preview#a-using-smart-links) to Kontent.ai according to manually specified [HTML data attri
38 lines • 1.66 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.HighlightType = void 0;
exports.getHighlightTypeForElement = getHighlightTypeForElement;
const attributes_1 = require("./attributes");
var HighlightType;
(function (HighlightType) {
HighlightType["None"] = "";
HighlightType["Element"] = "element";
HighlightType["ContentComponent"] = "content-component";
HighlightType["ContentItem"] = "content-item";
})(HighlightType || (exports.HighlightType = HighlightType = {}));
/**
* Get HighlightType based on the HTML element data-attributes.
*/
function getHighlightTypeForElement(element) {
if (!element || isFeatureDisabledForElement(element, attributes_1.DisableableFeature.Highlight)) {
return HighlightType.None;
}
// treat node as element if it has element codename attribute
if (element.hasAttribute(attributes_1.DataAttribute.ElementCodename)) {
return HighlightType.Element;
}
// else treat node as content component if it has component id attribute
else if (element.hasAttribute(attributes_1.DataAttribute.ComponentId)) {
return HighlightType.ContentComponent;
}
// else treat node as content item if it has item id attribute
else if (element.hasAttribute(attributes_1.DataAttribute.ItemId)) {
return HighlightType.ContentItem;
}
return HighlightType.None;
}
function isFeatureDisabledForElement(element, feature) {
const attribute = element.getAttribute(attributes_1.MetadataAttribute.DisableFeatures);
return attribute?.toLowerCase().includes(feature) ?? false;
}
//# sourceMappingURL=elementHighlight.js.map