Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 64 additions & 9 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import type {
Cascade,
FileInput,
Input,
InputType,
RichTextInput,
SnippetConfig,
Structure,
StructureValue,
UrlInput,
} from '@cloudcannon/configuration-types';

Expand Down Expand Up @@ -210,7 +214,7 @@ export interface EditOptions {
/** Optional style information */
style?: string | null;
/** The mouse event that triggered the edit */
e: MouseEvent;
e?: MouseEvent;
}

/**
Expand All @@ -235,7 +239,7 @@ export interface AddArrayItemOptions extends ArrayOptions {
/** The value to insert */
value: any;
/** The mouse event that triggered the addition */
e: MouseEvent;
e?: MouseEvent;
}

/**
Expand All @@ -256,6 +260,10 @@ export interface RemoveArrayItemOptions extends ArrayOptions {
index: number;
}

export interface GetInputConfigOptions {
slug: string;
}

/**
* Options for getting the current value in the v2 API
*/
Expand Down Expand Up @@ -495,15 +503,17 @@ export interface CloudCannonJavaScriptV1APIFile {
releaseLock(): Promise<{ readOnly: boolean }>;

addEventListener(
event: 'change' | 'delete' | 'create',
event: 'change' | 'delete',
listener: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;
removeEventListener(
event: 'change' | 'delete' | 'create',
event: 'change' | 'delete',
listener: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;

getInputConfig(options: GetInputConfigOptions): Promise<Input | undefined>;
}

export interface CloudCannonJavaScriptV1APICollection {
Expand All @@ -528,17 +538,45 @@ export interface CloudCannonJavaScriptV1APICollection {
// add(options: any): Promise<CloudCannonJavaScriptV1APIFile>;

addEventListener(
event: 'change' | 'delete' | 'create',
event: 'change' | 'delete',
listener: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;
removeEventListener(
event: 'change' | 'delete' | 'create',
event: 'change' | 'delete',
listener: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;
}

export interface CloudCannonJavaScriptV1APIDataset {
/**
* The key of the dataset
*/
datasetKey: string;

/**
* Gets the items in a dataset
* @returns Promise that resolves with the items in the collection
*/
items(): Promise<CloudCannonJavaScriptV1APIFile[] | CloudCannonJavaScriptV1APIFile>;

addEventListener(
event: 'change' | 'delete',
listener: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;
removeEventListener(
event: 'change' | 'delete',
listener: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;
}

export interface CloudCannonJavaScriptV1APITextEditableRegion {
setContent: (content?: string | null) => void;
}

export interface CloudCannonJavaScriptV1API {
/**
* Gets prefetched files
Expand Down Expand Up @@ -573,27 +611,44 @@ export interface CloudCannonJavaScriptV1API {
* @param inputConfig - Optional configuration for the input
* @returns Promise that resolves with the path of the uploaded file
*/
upload(
uploadFile(
file: File,
inputConfig: RichTextInput | UrlInput | FileInput | undefined
): Promise<string | undefined>;

currentFile(): CloudCannonJavaScriptV1APIFile;
file(path: string): CloudCannonJavaScriptV1APIFile;
collection(key: string): CloudCannonJavaScriptV1APICollection;
dataset(key: string): CloudCannonJavaScriptV1APIDataset;
files(): Promise<CloudCannonJavaScriptV1APIFile[]>;
collections(): Promise<CloudCannonJavaScriptV1APICollection[]>;

addEventListener(
event: 'change' | 'delete' | 'create',
event: 'change' | 'delete',
listener: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;
removeEventListener(
event: 'change' | 'delete' | 'create',
event: 'change' | 'delete',
listener: EventListenerOrEventListenerObject | null,
options?: EventListenerOptions | boolean
): void;

isAPIFile(obj: unknown): obj is CloudCannonJavaScriptV1APIFile;
isAPICollection(obj: unknown): obj is CloudCannonJavaScriptV1APICollection;
isAPIDataset(obj: unknown): obj is CloudCannonJavaScriptV1APIDataset;
findStructure(structure: Structure, value: any): StructureValue | undefined;
getInputType(key: string | undefined, value?: unknown, inputConfig?: Input): InputType;

createTextEditableRegion(
element: HTMLElement,
onChange: (content?: string | null) => void,
options?: {
elementType?: string;
editableType?: string;
inputConfig?: RichTextInput;
}
): Promise<CloudCannonJavaScriptV1APITextEditableRegion>;
}

export type CloudCannonJavaScriptAPIVersions = 'v0' | 'v1';
Expand Down