@stackbit/annotations
Version:
Stackbit annotations utils
56 lines • 1.85 kB
TypeScript
export declare const StackbitObjectIdAttrName = "data-sb-object-id";
export declare const StackbitFieldPathAttrName = "data-sb-field-path";
export type StackbitObjectId = {
[StackbitObjectIdAttrName]?: string;
};
export type StackbitFieldPath = {
[StackbitFieldPathAttrName]?: string;
};
export type StackbitAnnotations = StackbitObjectId & StackbitFieldPath;
export declare function getObjectId(props?: StackbitObjectId): string | undefined;
export declare function getFieldPath(props?: StackbitFieldPath): string | undefined;
/**
* Takes a string and returns an object with that string wrapped into the
* `data-sb-object-id` attribute.
*
* @example
* toObjectId('xyz')
* => { 'data-sb-object-id': 'xyz' }
*
* @param objectId
*/
export declare function toObjectId(objectId?: string): StackbitObjectId;
export type FieldPathDescriptor = ({
fieldPath: string;
} | {
fp: string;
}) & ({
objectId?: string;
} | {
oid?: string;
}) & {
xpath?: string;
};
/**
* Takes field-path and returns an object with all field-paths concatenated into
* the `data-sb-field-path` attribute. Each field-path can be a string or a
* FieldPathDescriptor.
*
* @example
* toFieldPath('.button', { objectId: 'xyz', fieldPath: 'link', xpath: '@href' })
* => { 'data-sb-field-path': '.button xyz:link#@href' }
*
* toFieldPath({ oid: 'abc', fp: 'image', xpath: 'img[1]/@src' })
* => { 'data-sb-field-path': 'abc:image#img[1]/@src' }
*
* @param fieldPaths
*/
export declare function toFieldPath(...fieldPaths: (undefined | null | string | FieldPathDescriptor)[]): StackbitFieldPath;
/**
* Takes an object and returns a new object with only the properties that start
* with `data-`
*
* @param props
*/
export declare function pickDataAttrs(props?: Record<string, any>): Record<string, any>;
//# sourceMappingURL=index.d.ts.map