UNPKG

@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

34 lines 1.45 kB
import { DataAttribute, DisableableFeature, MetadataAttribute } from './attributes'; export var HighlightType; (function (HighlightType) { HighlightType["None"] = ""; HighlightType["Element"] = "element"; HighlightType["ContentComponent"] = "content-component"; HighlightType["ContentItem"] = "content-item"; })(HighlightType || (HighlightType = {})); /** * Get HighlightType based on the HTML element data-attributes. */ export function getHighlightTypeForElement(element) { if (!element || isFeatureDisabledForElement(element, DisableableFeature.Highlight)) { return HighlightType.None; } // treat node as element if it has element codename attribute if (element.hasAttribute(DataAttribute.ElementCodename)) { return HighlightType.Element; } // else treat node as content component if it has component id attribute else if (element.hasAttribute(DataAttribute.ComponentId)) { return HighlightType.ContentComponent; } // else treat node as content item if it has item id attribute else if (element.hasAttribute(DataAttribute.ItemId)) { return HighlightType.ContentItem; } return HighlightType.None; } function isFeatureDisabledForElement(element, feature) { const attribute = element.getAttribute(MetadataAttribute.DisableFeatures); return attribute?.toLowerCase().includes(feature) ?? false; } //# sourceMappingURL=elementHighlight.js.map