Skip to content

Commit fe9768d

Browse files
Merge pull request #36 from CloudCannon/feat/file-based-url-options
Add new options to File and URL inputs
2 parents 17c8f7a + 8dea740 commit fe9768d

2 files changed

Lines changed: 93 additions & 63 deletions

File tree

src/inputs.d.ts

Lines changed: 59 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -154,14 +154,14 @@ export interface TextInput extends BaseInput {
154154
* Sets an input type, which controls how this input appears and behaves.
155155
*/
156156
type:
157-
| 'text'
158-
| 'email'
159-
| 'disabled'
160-
| 'pinterest'
161-
| 'facebook'
162-
| 'twitter'
163-
| 'github'
164-
| 'instagram';
157+
| 'text'
158+
| 'email'
159+
| 'disabled'
160+
| 'pinterest'
161+
| 'facebook'
162+
| 'twitter'
163+
| 'github'
164+
| 'instagram';
165165

166166
/**
167167
* Options that are specific to this `type` of input.
@@ -314,40 +314,6 @@ export interface RangeInput extends BaseInput {
314314
options?: RangeInputOptions;
315315
}
316316

317-
export interface UrlInputOptions extends WithEmptyTypeText, WithPaths {
318-
/**
319-
* Hides the option to link to a file. This does not prevent typing a file path in the input.
320-
*
321-
* @default false
322-
*/
323-
hide_link_to_file?: boolean;
324-
/**
325-
* Hides the option to link to a page. This does not prevent typing a file's output URL in the
326-
* input.
327-
*
328-
* @default false
329-
*/
330-
hide_link_to_page?: boolean;
331-
/**
332-
* Hides the option to link to an email address. This does not prevent typing a `mailto:` link in
333-
* the input.
334-
*
335-
* @default false
336-
*/
337-
hide_link_to_email_address?: boolean;
338-
}
339-
340-
export interface UrlInput extends BaseInput {
341-
/**
342-
* Sets an input type, which controls how this input appears and behaves.
343-
*/
344-
type: 'url';
345-
/**
346-
* Options that are specific to this `type` of input.
347-
*/
348-
options?: UrlInputOptions;
349-
}
350-
351317
export interface RichTextInputOptions extends WithEmptyTypeText, ImageResizeable, BlockEditable {
352318
/**
353319
* Shows or hides the resize handler to vertically resize the input.
@@ -406,7 +372,7 @@ export interface TimeInput extends BaseInput {
406372
options?: WithEmptyTypeText;
407373
}
408374

409-
export interface FileInputOptions extends WithEmptyTypeText, WithPaths {
375+
export interface FileInputOptions extends WithEmptyTypeText, WithPaths, ImageResizeable {
410376
/**
411377
* Restricts which file types are available to select or upload to this input. Accepted format is
412378
* an array or comma-separated string of MIME types. The special value '*' means any type is
@@ -418,30 +384,71 @@ export interface FileInputOptions extends WithEmptyTypeText, WithPaths {
418384
* sources can be uploaded to and selected from.
419385
*/
420386
allowed_sources?: string[];
387+
/**
388+
* Disables the context menu option and the drop area for uploading files.
389+
*
390+
* @default false
391+
*/
392+
disable_upload_file?: boolean;
393+
/**
394+
* Prevents typing into the text input, while still allowing context menu options to change the
395+
* value.
396+
*
397+
* @default false
398+
*/
399+
disable_direct_input?: boolean;
400+
/**
401+
* Prevents file uploads inside the "Select existing file/image" file browser modal window.
402+
*
403+
* @default false
404+
*/
405+
disable_upload_file_in_file_browser?: boolean;
421406
}
422407

423408
export interface FileInput extends BaseInput {
424409
/**
425410
* Sets an input type, which controls how this input appears and behaves.
426411
*/
427-
type: 'file' | 'document';
412+
type: 'file' | 'document' | 'image';
428413
/**
429-
* Options that are specific to File inputs.
414+
* Options that are specific to File, Image and Document inputs.
430415
*/
431416
options?: FileInputOptions;
432417
}
433418

434-
export type ImageInputOptions = FileInputOptions & ImageResizeable;
419+
export interface UrlInputOptions extends FileInputOptions {
420+
/**
421+
* Hides the options to link to an existing file, and upload a new file. This does not prevent
422+
* typing a file path in the input.
423+
*
424+
* @default false
425+
*/
426+
hide_link_to_file?: boolean;
427+
/**
428+
* Hides the option to link to a page. This does not prevent typing a file's output URL in the
429+
* input.
430+
*
431+
* @default false
432+
*/
433+
hide_link_to_page?: boolean;
434+
/**
435+
* Hides the option to link to an email address. This does not prevent typing a `mailto:` link in
436+
* the input.
437+
*
438+
* @default false
439+
*/
440+
hide_link_to_email_address?: boolean;
441+
}
435442

436-
export interface ImageInput extends BaseInput {
443+
export interface UrlInput extends BaseInput {
437444
/**
438445
* Sets an input type, which controls how this input appears and behaves.
439446
*/
440-
type: 'image';
447+
type: 'url';
441448
/**
442-
* Options that are specific to Image inputs.
449+
* Options that are specific to URL inputs.
443450
*/
444-
options?: ImageInputOptions;
451+
options?: UrlInputOptions;
445452
}
446453

447454
export interface SelectInputOptions extends WithPreview, WithPickerPreview {
@@ -501,7 +508,7 @@ export interface MultiselectInput extends BaseInput {
501508
options?: SelectInputOptions & WithEmptyTypeArray;
502509
}
503510

504-
export interface ChoiceInputOptions extends Omit<SelectInputOptions, 'allow_create'> {}
511+
export interface ChoiceInputOptions extends Omit<SelectInputOptions, 'allow_create'> { }
505512

506513
export interface ChoiceInput extends BaseInput {
507514
/**
@@ -667,12 +674,11 @@ export type KnownInput =
667674
| BooleanInput
668675
| NumberInput
669676
| RangeInput
670-
| UrlInput
671677
| RichTextInput
672678
| DateInput
673679
| TimeInput
674680
| FileInput
675-
| ImageInput
681+
| UrlInput
676682
| SelectInput
677683
| MultiselectInput
678684
| ChoiceInput

src/javascript-api.d.ts

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import type { Cascade } from './cascade';
22
import type { SnippetConfig } from './snippets';
3-
import type { FileInput, ImageInput, RichTextInput } from './inputs';
3+
import type { FileInput, UrlInput, RichTextInput } from './inputs';
44

55
export interface CloseCustomDataPanelOptions {
66
parentId: string;
@@ -17,12 +17,17 @@ export interface OpenCustomDataPanelOptions extends CloseCustomDataPanelOptions
1717

1818
/**
1919
* Interface defining the public JavaScript API for interacting with CloudCannon's Visual Editor.
20-
* This API provides methods for managing content, handling file operations, and controlling the editor's state.
20+
* This API provides methods for managing content, handling file operations, and controlling the
21+
* editor's state.
2122
*/
2223
export interface CloudCannonJavaScriptAPI {
23-
/** Whether event handling is currently enabled */
24+
/**
25+
* Whether event handling is currently enabled
26+
*/
2427
eventsEnabled: boolean;
25-
/** Whether the API should be installed globally */
28+
/**
29+
* Whether the API should be installed globally
30+
*/
2631
installGlobally: boolean;
2732

2833
/**
@@ -31,8 +36,7 @@ export interface CloudCannonJavaScriptAPI {
3136
disableGlobalInstall(): void;
3237

3338
/**
34-
* Enables event handling for the API
35-
* This will also ensure the commit model is created
39+
* Enables event handling for the API This will also ensure the commit model is created
3640
*/
3741
enableEvents(): void;
3842

@@ -42,26 +46,29 @@ export interface CloudCannonJavaScriptAPI {
4246
disableEvents(): void;
4347

4448
/**
45-
* Refreshes the editor interface
46-
* Note: This has been replaced with a MutationObserver in editor-overlays-view
49+
* Refreshes the editor interface Note: This has been replaced with a MutationObserver in
50+
* editor-overlays-view
4751
*/
4852
refreshInterface(): void;
4953

5054
/**
5155
* Triggers an update event for a specific file
56+
*
5257
* @param sourcePath - The path of the file to update
5358
*/
5459
triggerUpdateEvent(sourcePath: string): void;
5560

5661
/**
5762
* Sets the loading state of the editor
63+
*
5864
* @param loadingData - Optional loading state message
5965
* @returns Promise that resolves when loading state is updated
6066
*/
6167
setLoading(loadingData: string | undefined): Promise<any>;
6268

6369
/**
6470
* Sets data for a specific field
71+
*
6572
* @param slug - The identifier of the field to set
6673
* @param value - The value to set
6774
* @returns Promise that resolves when the data is set
@@ -70,6 +77,7 @@ export interface CloudCannonJavaScriptAPI {
7077

7178
/**
7279
* Initiates editing of a specific field
80+
*
7381
* @param slug - The identifier of the field to edit
7482
* @param style - Optional style information
7583
* @param e - The mouse event that triggered the edit
@@ -78,28 +86,35 @@ export interface CloudCannonJavaScriptAPI {
7886

7987
/**
8088
* Opens a custom data panel for editing
89+
*
8190
* @param options - Configuration options for the panel
8291
* @returns Promise that resolves when the panel is opened
8392
*/
8493
openCustomDataPanel(options: OpenCustomDataPanelOptions): Promise<void>;
8594

8695
/**
8796
* Closes a custom data panel
97+
*
8898
* @param options - Configuration options for the panel to close
8999
* @returns Promise that resolves when the panel is closed
90100
*/
91101
closeCustomDataPanel(options: CloseCustomDataPanelOptions): Promise<void>;
92102

93103
/**
94104
* Uploads a file to the editor
105+
*
95106
* @param file - The file to upload
96107
* @param inputConfig - Optional configuration for the input
97108
* @returns Promise that resolves with the path of the uploaded file
98109
*/
99-
uploadFile(file: File, inputConfig: RichTextInput | ImageInput | FileInput | undefined): Promise<string | undefined>;
110+
uploadFile(
111+
file: File,
112+
inputConfig: RichTextInput | UrlInput | FileInput | undefined,
113+
): Promise<string | undefined>;
100114

101115
/**
102116
* Adds an item to an array field
117+
*
103118
* @param slug - The identifier of the array field
104119
* @param index - The position to insert at (null for end)
105120
* @param value - The value to insert
@@ -110,6 +125,7 @@ export interface CloudCannonJavaScriptAPI {
110125

111126
/**
112127
* Adds an item before a specific index in an array field
128+
*
113129
* @param slug - The identifier of the array field
114130
* @param index - The index to insert before
115131
* @param value - The value to insert
@@ -120,6 +136,7 @@ export interface CloudCannonJavaScriptAPI {
120136

121137
/**
122138
* Adds an item after a specific index in an array field
139+
*
123140
* @param slug - The identifier of the array field
124141
* @param index - The index to insert after
125142
* @param value - The value to insert
@@ -130,6 +147,7 @@ export interface CloudCannonJavaScriptAPI {
130147

131148
/**
132149
* Removes an item from an array field
150+
*
133151
* @param slug - The identifier of the array field
134152
* @param index - The index of the item to remove
135153
* @returns Promise that resolves when the item is removed
@@ -138,6 +156,7 @@ export interface CloudCannonJavaScriptAPI {
138156

139157
/**
140158
* Moves an item within an array field
159+
*
141160
* @param slug - The identifier of the array field
142161
* @param index - The current index of the item
143162
* @param toIndex - The target index for the item
@@ -147,34 +166,39 @@ export interface CloudCannonJavaScriptAPI {
147166

148167
/**
149168
* Gets the current value of the editor
169+
*
150170
* @param options - Optional configuration for the value retrieval
151171
* @returns Promise that resolves with the current value
152172
*/
153173
value(options?: { keepMarkdownAsHTML?: boolean }): Promise<string>;
154174

155175
/**
156176
* Claims a lock on a file
177+
*
157178
* @param sourcePath - Optional path of the file to lock
158179
* @returns Promise that resolves with the lock status
159180
*/
160181
claimLock(sourcePath?: string): Promise<{ readOnly: boolean }>;
161182

162183
/**
163184
* Releases a lock on a file
185+
*
164186
* @param sourcePath - Optional path of the file to unlock
165187
* @returns Promise that resolves with the lock status
166188
*/
167189
releaseLock(sourcePath?: string): Promise<{ readOnly: boolean }>;
168190

169191
/**
170192
* Gets prefetched files
193+
*
171194
* @returns Promise that resolves with a record of file blobs
172195
*/
173196
prefetchedFiles(): Promise<Record<string, Blob>>;
174197

175198
/**
176199
* Loads legacy Bookshop information
200+
*
177201
* @returns Promise that resolves with the Bookshop data
178202
*/
179203
loadLegacyBookshopInfo(): Promise<any>;
180-
}
204+
}

0 commit comments

Comments
 (0)