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

48 lines (47 loc) 2.25 kB
import { type IContentComponentClickedMessageData, type IContentItemClickedMessageData, type IElementClickedMessageData } from "../../lib/IFrameCommunicatorTypes"; import { DataAttribute } from "./attributes"; export type EditButtonClickedData = IContentItemClickedMessageData | IContentComponentClickedMessageData | IElementClickedMessageData; export type ParserTokenKey = "environmentId" | "languageCodename" | "itemId" | "contentComponentId" | "elementCodename" | "placement" | "targetId"; type IDataAttributesParserToken = Readonly<{ key: ParserTokenKey; dataAttributes: DataAttribute[]; optional?: boolean; }>; /** * Represents a pattern of tokens to parse data attributes. * Tokens have precedence in the hierarchy - tokens appearing later in the array * can appear in upper elements than earlier ones. * * EXAMPLE: projectId can be specified in higher element than itemId */ type DataAttributesParserPattern = ReadonlyArray<IDataAttributesParserToken>; /** * Parses data attributes from an HTML element to extract edit button information. * The function determines the type of element being edited (element, component, or item) * and extracts relevant data attributes based on that type. */ export declare function parseEditButtonDataAttributes(target: HTMLElement): ParseResult; /** * Parses data attributes from an HTML element to extract add button information. * The function determines the insert position type (fixed or relative) and extracts * relevant data attributes based on that type. */ export declare function parseAddButtonDataAttributes(target: HTMLElement): ParseResult; export type ParseTokenResult = Partial<Record<ParserTokenKey, string | null>>; export type ParseResult = { parsed: ParseTokenResult; debugData: ReadonlyArray<{ element: HTMLElement; parsedAttributes: ReadonlyArray<{ token: ParserTokenKey; dataAttribute: DataAttribute; value: string; }>; skippedAttributes: ReadonlyArray<{ dataAttribute: DataAttribute; value: string | null; }>; }>; }; export declare const parseDataAttributes: (pattern: DataAttributesParserPattern, element: HTMLElement | null) => ParseResult; export {};