Skip to content

Commit

Permalink
feat: Hidden partials and partial priority. (#233)
Browse files Browse the repository at this point in the history
Allows the partial to be hidden from the partial list (ex: when adding a new partial to a page).

Also adds a priority option to be able to give priority to specific partials. For example, making the spacer partial appear first in the list.

Fixes #222
  • Loading branch information
Zoramite committed Aug 13, 2021
1 parent 5a00242 commit ab539bb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
25 changes: 25 additions & 0 deletions src/ts/editor/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -510,8 +510,33 @@ export interface FileData {
}

export interface PartialData {
/**
* Partial identifier.
*
* This is the same value used in the partial definition of partials
* in content files.
*/
partial: string;
/**
* Is the partial hidden?
*
* Partials can opt to not show the partial in the listing of partials.
* This is helpful for partials that are part of the design such as
* header and footer partials.
*/
isHidden?: boolean;
/**
* Configuration for how the editor should present the partial in the
* editor.
*/
editor?: PartialEditorConfig;
/**
* When displaying lists of paritals the priority will affect the
* sort order of the partials.
*
* Default priority is 1000
*/
priority?: number;
}

/**
Expand Down
13 changes: 13 additions & 0 deletions src/ts/example/exampleApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2076,6 +2076,19 @@ export class ExampleAmagakiApi implements AmagakiProjectTypeApi {
],
},
} as PartialData,
hidden: {
editor: {
label: 'Hidden partial',
fields: [
{
type: 'text',
key: 'title',
label: 'title',
} as TextFieldConfig,
],
},
isHidden: true,
} as PartialData,
},
this.options
);
Expand Down
7 changes: 6 additions & 1 deletion src/ts/projectType/generic/field/partials.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,16 +155,21 @@ export class GenericPartialsField
const options = [];
for (const [partialKey, partial] of Object.entries(this.partials || {})) {
// Without the editor config there are no fields to add for a partial.
if (!partial.editor) {
// Also don't show the hidden partials.
if (!partial.editor || partial.isHidden) {
continue;
}

options.push({
label: partial.editor.label || partialKey,
value: partialKey,
priority: partial.priority ?? 1000,
});
}

// Sort the options by priority.
options.sort((a, b) => a.priority - b.priority);

const selectiveConfig = merge(
{},
// Clone to prevent shared values if editor changes config.
Expand Down

0 comments on commit ab539bb

Please sign in to comment.