diff --git a/dist/index.js b/dist/index.js index 4c06c2dc..d65b6828 100644 --- a/dist/index.js +++ b/dist/index.js @@ -500,18 +500,6 @@ this.initializeTree(); } }; - removeRecursively = (pathComponents) => { - loop_over_files: for (const key of Object.keys(localStorage)) { - const pathComponentsOfCurrentEntity = _StorageModel.stringToPathComponents(key); - loop_over_path_components: for (let i = 0; i < pathComponents.length; i++) { - if (!pathComponentsOfCurrentEntity[i]) continue loop_over_files; - if (pathComponentsOfCurrentEntity[i] != pathComponents[i]) - continue loop_over_files; - } - this.remove(pathComponentsOfCurrentEntity, false); - } - this.initializeTree(); - }; rename = (sourcePathComponents, destinationPathComponents, shouldInitialize = true) => { const content = this.read(sourcePathComponents); if (content == null) return false; @@ -522,27 +510,34 @@ } return true; }; - renameRecursively = (sourcePathComponents, destinationPathComponents) => { + // recursion + recurse = (pathComponents, fn) => { loop_over_files: for (const key of Object.keys(localStorage)) { - const originalPathComponentsOfCurrentEntity = _StorageModel.stringToPathComponents(key); - loop_over_path_components: for (let i = 0; i < sourcePathComponents.length; i++) { - if (!originalPathComponentsOfCurrentEntity[i]) continue loop_over_files; - if (originalPathComponentsOfCurrentEntity[i] != sourcePathComponents[i]) + const pathComponentsOfCurrentEntity = _StorageModel.stringToPathComponents(key); + loop_over_path_components: for (let i = 0; i < pathComponents.length; i++) { + if (!pathComponentsOfCurrentEntity[i]) continue loop_over_files; + if (pathComponentsOfCurrentEntity[i] != pathComponents[i]) continue loop_over_files; } - const relativePathOfCurrentEntity = originalPathComponentsOfCurrentEntity.slice( + fn(pathComponentsOfCurrentEntity); + } + this.initializeTree(); + }; + removeRecursively = (pathComponents) => { + this.recurse(pathComponents, (path) => this.remove(path, false)); + this.initializeTree(); + }; + renameRecursively = (sourcePathComponents, destinationPathComponents) => { + this.recurse(sourcePathComponents, (path) => { + const relativePathOfCurrentEntity = path.slice( sourcePathComponents.length ); const destinationPathComponentsOfCurrentEntity = [ ...destinationPathComponents, ...relativePathOfCurrentEntity ]; - this.rename( - originalPathComponentsOfCurrentEntity, - destinationPathComponentsOfCurrentEntity, - false - ); - } + this.rename(path, destinationPathComponentsOfCurrentEntity, false); + }); this.initializeTree(); }; // stringifiable @@ -3689,20 +3684,20 @@ function close() { isOpen.value = false; } - const id = v4_default(); + const suggestionId = v4_default(); return /* @__PURE__ */ createElement("div", { class: "modal", "toggle:open": isOpen }, /* @__PURE__ */ createElement("div", { style: "max-width: 64rem" }, /* @__PURE__ */ createElement("main", null, /* @__PURE__ */ createElement("h2", null, headline), /* @__PURE__ */ createElement("div", { class: "flex-row width-input" }, /* @__PURE__ */ createElement( "input", { placeholder: translations.general.searchLabel, "bind:value": searchViewModel.searchInput, "on:enter": searchViewModel.applySearch, - list: id + list: suggestionId } ), /* @__PURE__ */ createElement( "datalist", { hidden: true, - id, + id: suggestionId, "children:append": [searchViewModel.suggestions, StringToOption] } ), /* @__PURE__ */ createElement( diff --git a/src/Model/Global/storageModel.ts b/src/Model/Global/storageModel.ts index 0d2dada5..de9b3d4d 100644 --- a/src/Model/Global/storageModel.ts +++ b/src/Model/Global/storageModel.ts @@ -50,29 +50,6 @@ export default class StorageModel { } }; - removeRecursively = (pathComponents: string[]): void => { - loop_over_files: for (const key of Object.keys(localStorage)) { - // get path of current entity - const pathComponentsOfCurrentEntity: string[] = - StorageModel.stringToPathComponents(key); - - // exit if entity does not match - loop_over_path_components: for ( - let i = 0; - i < pathComponents.length; - i++ - ) { - if (!pathComponentsOfCurrentEntity[i]) continue loop_over_files; - if (pathComponentsOfCurrentEntity[i] != pathComponents[i]) - continue loop_over_files; - } - - // remove - this.remove(pathComponentsOfCurrentEntity, false); - } - this.initializeTree(); - }; - rename = ( sourcePathComponents: string[], destinationPathComponents: string[], @@ -90,43 +67,52 @@ export default class StorageModel { return true; }; - renameRecursively = ( - sourcePathComponents: string[], - destinationPathComponents: string[] - ): void => { + // recursion + recurse = (pathComponents: string[], fn: (path: string[]) => void): void => { loop_over_files: for (const key of Object.keys(localStorage)) { // get path of current entity - const originalPathComponentsOfCurrentEntity: string[] = + const pathComponentsOfCurrentEntity: string[] = StorageModel.stringToPathComponents(key); // exit if entity does not match loop_over_path_components: for ( let i = 0; - i < sourcePathComponents.length; + i < pathComponents.length; i++ ) { - if (!originalPathComponentsOfCurrentEntity[i]) continue loop_over_files; - if (originalPathComponentsOfCurrentEntity[i] != sourcePathComponents[i]) + if (!pathComponentsOfCurrentEntity[i]) continue loop_over_files; + if (pathComponentsOfCurrentEntity[i] != pathComponents[i]) continue loop_over_files; } + // execute + fn(pathComponentsOfCurrentEntity); + } + this.initializeTree(); + }; + + removeRecursively = (pathComponents: string[]): void => { + this.recurse(pathComponents, (path: string[]) => this.remove(path, false)); + this.initializeTree(); + }; + + renameRecursively = ( + sourcePathComponents: string[], + destinationPathComponents: string[] + ): void => { + this.recurse(sourcePathComponents, (path: string[]) => { // assemble destinationPath - const relativePathOfCurrentEntity = - originalPathComponentsOfCurrentEntity.slice( - sourcePathComponents.length - ); + const relativePathOfCurrentEntity = path.slice( + sourcePathComponents.length + ); const destinationPathComponentsOfCurrentEntity = [ ...destinationPathComponents, ...relativePathOfCurrentEntity, ]; // rename - this.rename( - originalPathComponentsOfCurrentEntity, - destinationPathComponentsOfCurrentEntity, - false - ); - } + this.rename(path, destinationPathComponentsOfCurrentEntity, false); + }); this.initializeTree(); }; @@ -221,7 +207,7 @@ export type StorageEntry = { [key: string]: StorageEntry }; // locations export enum StorageModelSubPath { Chat = "chat", - + ConnectionModel = "connection", SettingsModel = "settings", }