Skip to content

Commit

Permalink
feat: better types for computed content getters
Browse files Browse the repository at this point in the history
  • Loading branch information
johannschopplich committed Dec 10, 2024
1 parent 32aca52 commit 52a07b1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,6 @@ The import will provide global type augmentations for the `window.panel` object.

## API

Da der Arbeitsbereich-Index noch erstellt wird, kann die Antwort weniger genau sein.

Here's the documentation for the composables in your workspace:

### useApi

Returns Kirby's Panel API for making HTTP requests to the backend.
Expand Down
29 changes: 20 additions & 9 deletions src/composables/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,32 @@ export function useContent() {
const _isKirby5 = isKirby5();

const currentContent = _isKirby5
? computed(() => panel.view.props.content)
: computed(() => store.getters["content/values"]());
? computed<Record<string, any>>(() => panel.view.props.content)
: computed<Record<string, any>>(() => store.getters["content/values"]());
const contentChanges = _isKirby5
? computed(() => panel.content.changes())
: computed(() => store.getters["content/changes"]());
? computed<Record<string, any>>(() => panel.content.changes())
: computed<Record<string, any>>(() => store.getters["content/changes"]());
const hasChanges = _isKirby5
? computed(() => store.getters["content/hasChanges"]())
: computed(() => Object.keys(contentChanges.value).length > 0);

const content = _isKirby5 ? panel.content : ({} as PanelContent);
? computed<boolean>(() => Object.keys(contentChanges.value).length > 0)
: computed<boolean>(() => store.getters["content/hasChanges"]());
const content = _isKirby5
? panel.content
: new Proxy({} as PanelContent, {
get() {
return () => {
throw new Error(
'The "window.panel.content" API is not available in Kirby 4.',
);
};
},
});

/**
* Updates the form values of the current view without saving them.
*/
const update = (values?: Record<string, any>) => {
const update = (
values?: Record<string, any>,
): Record<string, any> | undefined => {
if (!values || Object.keys(values).length === 0) {
return;
}
Expand Down

0 comments on commit 52a07b1

Please sign in to comment.