Skip to content

Commit

Permalink
Keep expander state when editor remains open
Browse files Browse the repository at this point in the history
Fix #275
  • Loading branch information
kyoshino committed Dec 13, 2024
1 parent a66da50 commit 5453ae1
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/lib/components/contents/details/toolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
originalValues = {},
currentValues = {},
validities = {},
expanderStates,
} = $entryDraft ?? /** @type {EntryDraft} */ ({}));
$: ({
Expand Down Expand Up @@ -101,7 +102,7 @@
}
// Reset the draft
createDraft({ collection, collectionFile, originalEntry: savedEntry });
createDraft({ collection, collectionFile, originalEntry: savedEntry, expanderStates });
}
} catch (/** @type {any} */ ex) {
if (ex.message === 'validation_failed') {
Expand Down
12 changes: 10 additions & 2 deletions src/lib/services/contents/draft/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -311,8 +311,16 @@ export const createProxy = ({
* @param {any} [args.originalEntry] - Entry to be edited, or a partial {@link Entry} object.
* @param {Record<string, string>} [args.dynamicValues] - Dynamic default values for a new entry
* passed through URL parameters.
* @param {Record<string, FlattenedEntryExpanderState>} [args.expanderStates] - Expander UI state.
* Can be set when resetting an entry draft.
*/
export const createDraft = ({ collection, collectionFile, originalEntry = {}, dynamicValues }) => {
export const createDraft = ({
collection,
collectionFile,
originalEntry = {},
dynamicValues,
expanderStates,
}) => {
const collectionName = collection.name;
const fileName = collectionFile?.name;
const { id, slug, locales } = originalEntry;
Expand Down Expand Up @@ -360,7 +368,7 @@ export const createDraft = ({ collection, collectionFile, originalEntry = {}, dy
files: {},
validities: Object.fromEntries(allLocales.map((locale) => [locale, {}])),
// Any locale-agnostic view states will be put under the `_` key
expanderStates: { _: {} },
expanderStates: expanderStates ?? { _: {} },
});

restoreBackupIfNeeded(collectionName, slug);
Expand Down

0 comments on commit 5453ae1

Please sign in to comment.