Skip to content

Commit

Permalink
Merge pull request #25 from CloudCannon/fix/add-option-intersection
Browse files Browse the repository at this point in the history
fix: use union instead of megatype for add options
  • Loading branch information
Tate-CC authored Nov 29, 2024
2 parents ecd631c + 643650a commit dd4435c
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 53 deletions.
11 changes: 9 additions & 2 deletions src/build-coupled.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,18 +88,25 @@ export interface ReaderConfiguration extends Configuration {
output?: string;
}

export interface BuildCoupledCollectionConfig extends Omit<CollectionConfig, 'url'>, Filterable {
export interface BuildCoupledCollectionConfig
extends Omit<CollectionConfig, 'url' | 'path'>,
Filterable {
/**
* Overrides the default singular input key of the collection. This is used for naming conventions
* for select and multiselect inputs.
*/
singular_key?: string;
/**
* The top-most folder where the files in this collection are stored. It is relative to `source`.
*/
path?: string;
}

interface BuildCoupledConfiguration
extends Omit<Configuration, 'data_config'>,
extends Omit<Configuration, 'data_config' | 'collections_config'>,
WithCollectionsConfigOverride {
paths?: BuildCoupledPaths;
collections_config?: BuildCoupledCollectionConfig;
}

/**
Expand Down
109 changes: 58 additions & 51 deletions src/configuration.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1269,56 +1269,63 @@ export interface Preview
gallery?: PreviewGallery;
}

export type AddOption =
| {
/**
* The text displayed for the menu item. Defaults to using name from the matching schema if
* set.
*/
name?: string;
/**
* The icon next to the text in the menu item. Defaults to using icon from the matching schema
* if set, then falls back to add.
*/
icon?: Icon;
/**
* The editor to open the new file in. Defaults to an appropriate editor for new file's type
* if possible. If no default editor can be calculated, or the editor does not support the new
* file type, a warning is shown in place of the editor.
*/
editor?: EditorKey;
/**
* Enforces a path for new files to be created in, regardless of path the user is currently
* navigated to within the collection file list. Relative to the path of the collection
* defined in collection. Defaults to the path within the collection the user is currently
* navigated to.
*/
base_path?: string;
/**
* Sets which collection this action is creating a file in. This is used when matching the
* value for schema. Defaults to the containing collection these `add_options` are configured
* in.
*/
collection?: string;
/**
* The schema that new files are created from with this action. This schema is not restricted
* to the containing collection, and is instead relative to the collection specified with
* collection. Defaults to default if schemas are configured for the collection.
*/
schema?: string;
/**
* The path to a file used to populate the initial contents of a new file if no schemas are
* configured. We recommend using schemas, and this is ignored if a schema is available.
*/
default_content_file?: string;
}
| {
/**
* The link that opens when the option is clicked. Can either be an external or internal link.
* If internal, the link is relative to the current site.
*/
href: string;
};
export type HrefAddOption = {
/**
* The text displayed for the menu item.
*/
name?: string;
/**
* The icon next to the text in the menu item.
*
* @default add
*/
icon?: Icon;
/**
* The link that opens when the option is clicked. Can either be an external or internal link. If
* internal, the link is relative to the current site.
*/
href: string;
};

export type AddOption = {
/**
* The text displayed for the menu item. Defaults to using name from the matching schema if set.
*/
name?: string;
/**
* The icon next to the text in the menu item. Defaults to using icon from the matching schema if
* set, then falls back to add.
*/
icon?: Icon;
/**
* The editor to open the new file in. Defaults to an appropriate editor for new file's type if
* possible. If no default editor can be calculated, or the editor does not support the new file
* type, a warning is shown in place of the editor.
*/
editor?: EditorKey;
/**
* Enforces a path for new files to be created in, regardless of path the user is currently
* navigated to within the collection file list. Relative to the path of the collection defined in
* collection. Defaults to the path within the collection the user is currently navigated to.
*/
base_path?: string;
/**
* Sets which collection this action is creating a file in. This is used when matching the value
* for schema. Defaults to the containing collection these `add_options` are configured in.
*/
collection?: string;
/**
* The schema that new files are created from with this action. This schema is not restricted to
* the containing collection, and is instead relative to the collection specified with collection.
* Defaults to default if schemas are configured for the collection.
*/
schema?: string;
/**
* The path to a file used to populate the initial contents of a new file if no schemas are
* configured. We recommend using schemas, and this is ignored if a schema is available.
*/
default_content_file?: string;
};

interface WithPreview {
/**
Expand Down Expand Up @@ -1488,7 +1495,7 @@ export interface CollectionConfig extends Cascade, WithPreview {
* automatically generated list from _Schemas_, or uses the first file in the collection if no
* schemas are configured.
*/
add_options?: AddOption[];
add_options?: (AddOption | HrefAddOption)[];
/**
* The create path definition to control where new files are saved to inside this collection.
* Defaults to [relative_base_path]/{title|slugify}.md.
Expand Down

0 comments on commit dd4435c

Please sign in to comment.