1/** 2 * File Manager State Model 3 * 4 * Represents the persisted state of the file manager in localStorage. 5 * This model provides a single source of truth for all file manager preferences. 6 */ /** 7 * Column visibility settings for list view 8 */ function _class_call_check(instance, Constructor) { 9 if (!(instance instanceof Constructor)) { 10 throw new TypeError("Cannot call a class as a function"); 11 } 12} 13function _defineProperties(target, props) { 14 for(var i = 0; i < props.length; i++){ 15 var descriptor = props[i]; 16 descriptor.enumerable = descriptor.enumerable || false; 17 descriptor.configurable = true; 18 if ("value" in descriptor) descriptor.writable = true; 19 Object.defineProperty(target, descriptor.key, descriptor); 20 } 21} 22function _create_class(Constructor, protoProps, staticProps) { 23 if (protoProps) _defineProperties(Constructor.prototype, protoProps); 24 if (staticProps) _defineProperties(Constructor, staticProps); 25 return Constructor; 26} 27function _define_property(obj, key, value) { 28 if (key in obj) { 29 Object.defineProperty(obj, key, { 30 value: value, 31 enumerable: true, 32 configurable: true, 33 writable: true 34 }); 35 } else { 36 obj[key] = value; 37 } 38 return obj; 39} 40function _object_spread(target) { 41 for(var i = 1; i < arguments.length; i++){ 42 var source = arguments[i] != null ? arguments[i] : {}; 43 var ownKeys = Object.keys(source); 44 if (typeof Object.getOwnPropertySymbols === "function") { 45 ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) { 46 return Object.getOwnPropertyDescriptor(source, sym).enumerable; 47 })); 48 } 49 ownKeys.forEach(function(key) { 50 _define_property(target, key, source[key]); 51 }); 52 } 53 return target; 54} 55/** 56 * Default state values 57 */ var DEFAULT_STATE = { 58 viewMode: "list", 59 columns: { 60 type: false, 61 size: true, 62 modified: true, 63 webPermission: true, 64 permissions: true, 65 owner: true 66 }, 67 sort: { 68 field: "name", 69 direction: "asc" 70 }, 71 treePaneWidth: 250, 72 infoPaneWidth: 280, 73 infoPaneVisible: true, 74 terminalPaneHeight: 300 75}; 76/** 77 * File Manager State 78 * 79 * Manages persistence of file manager preferences to localStorage. 80 * Provides a clean API for reading and writing state with validation. 81 */ export var FileManagerState = /*#__PURE__*/ function() { 82 "use strict"; 83 function FileManagerState(filesystemType, filesystemIdentifier) { 84 _class_call_check(this, FileManagerState); 85 _define_property(this, "storageKey", void 0); 86 _define_property(this, "state", void 0); 87 this.storageKey = "fileManager:".concat(filesystemType, ":").concat(filesystemIdentifier, ":state"); 88 this.state = this.load(); 89 } 90 _create_class(FileManagerState, [ 91 { 92 key: "load", 93 value: /** 94 * Load state from localStorage, falling back to defaults 95 */ function load() { 96 try { 97 var saved = localStorage.getItem(this.storageKey); 98 if (saved) { 99 var parsed = JSON.parse(saved); 100 // Merge with defaults to handle missing properties (future-proofing) 101 return this.mergeWithDefaults(parsed); 102 } 103 } catch (error) { 104 console.warn("Failed to load file manager state:", error); 105 } 106 return _object_spread({}, DEFAULT_STATE); 107 } 108 }, 109 { 110 key: "mergeWithDefaults", 111 value: /** 112 * Merge saved state with defaults to handle missing/new properties 113 */ function mergeWithDefaults(saved) { 114 var _saved_sort, _saved_sort1; 115 return { 116 viewMode: this.isValidViewMode(saved.viewMode) ? saved.viewMode : DEFAULT_STATE.viewMode, 117 columns: _object_spread({}, DEFAULT_STATE.columns, saved.columns || {}), 118 sort: { 119 field: this.isValidSortField((_saved_sort = saved.sort) === null || _saved_sort === void 0 ? void 0 : _saved_sort.field) ? saved.sort.field : DEFAULT_STATE.sort.field, 120 direction: this.isValidSortDirection((_saved_sort1 = saved.sort) === null || _saved_sort1 === void 0 ? void 0 : _saved_sort1.direction) ? saved.sort.direction : DEFAULT_STATE.sort.direction 121 }, 122 treePaneWidth: typeof saved.treePaneWidth === "number" && saved.treePaneWidth > 0 ? saved.treePaneWidth : DEFAULT_STATE.treePaneWidth, 123 infoPaneWidth: typeof saved.infoPaneWidth === "number" && saved.infoPaneWidth > 0 ? saved.infoPaneWidth : DEFAULT_STATE.infoPaneWidth, 124 infoPaneVisible: typeof saved.infoPaneVisible === "boolean" ? saved.infoPaneVisible : DEFAULT_STATE.infoPaneVisible, 125 terminalPaneHeight: typeof saved.terminalPaneHeight === "number" && saved.terminalPaneHeight > 0 ? saved.terminalPaneHeight : DEFAULT_STATE.terminalPaneHeight 126 }; 127 } 128 }, 129 { 130 key: "isValidViewMode", 131 value: /** 132 * Validate view mode value 133 */ function isValidViewMode(value) { 134 return value === "list" || value === "grid" || value === "treemap"; 135 } 136 }, 137 { 138 key: "isValidSortField", 139 value: /** 140 * Validate sort field value 141 */ function isValidSortField(value) { 142 return value === "name" || value === "size" || value === "modificationTime" || value === "type"; 143 } 144 }, 145 { 146 key: "isValidSortDirection", 147 value: /** 148 * Validate sort direction value 149 */ function isValidSortDirection(value) { 150 return value === "asc" || value === "desc"; 151 } 152 }, 153 { 154 /** 155 * Save current state to localStorage 156 */ key: "save", 157 value: function save() { 158 try { 159 localStorage.setItem(this.storageKey, JSON.stringify(this.state)); 160 } catch (error) { 161 console.warn("Failed to save file manager state:", error); 162 } 163 } 164 }, 165 { 166 key: "viewMode", 167 get: // ==================== Getters ==================== 168 function get() { 169 return this.state.viewMode; 170 }, 171 set: // ==================== Setters (auto-save on change) ==================== 172 function set(value) { 173 if (this.isValidViewMode(value)) { 174 this.state.viewMode = value; 175 this.save(); 176 } 177 } 178 }, 179 { 180 key: "columns", 181 get: function get() { 182 return _object_spread({}, this.state.columns); 183 } 184 }, 185 { 186 key: "sort", 187 get: function get() { 188 return _object_spread({}, this.state.sort); 189 } 190 }, 191 { 192 key: "treePaneWidth", 193 get: function get() { 194 return this.state.treePaneWidth; 195 }, 196 set: function set(value) { 197 if (typeof value === "number" && value > 0) { 198 this.state.treePaneWidth = value; 199 this.save(); 200 } 201 } 202 }, 203 { 204 key: "infoPaneWidth", 205 get: function get() { 206 return this.state.infoPaneWidth; 207 }, 208 set: function set(value) { 209 if (typeof value === "number" && value > 0) { 210 this.state.infoPaneWidth = value; 211 this.save(); 212 } 213 } 214 }, 215 { 216 key: "infoPaneVisible", 217 get: function get() { 218 return this.state.infoPaneVisible; 219 }, 220 set: function set(value) { 221 if (typeof value === "boolean") { 222 this.state.infoPaneVisible = value; 223 this.save(); 224 } 225 } 226 }, 227 { 228 key: "terminalPaneHeight", 229 get: function get() { 230 return this.state.terminalPaneHeight; 231 }, 232 set: function set(value) { 233 if (typeof value === "number" && value > 0) { 234 this.state.terminalPaneHeight = value; 235 this.save(); 236 } 237 } 238 }, 239 { 240 key: "setColumnVisibility", 241 value: function setColumnVisibility(column, visible) { 242 if (column in this.state.columns) { 243 this.state.columns[column] = visible; 244 this.save(); 245 } 246 } 247 }, 248 { 249 key: "setSortField", 250 value: function setSortField(field) { 251 if (this.isValidSortField(field)) { 252 this.state.sort.field = field; 253 this.save(); 254 } 255 } 256 }, 257 { 258 key: "setSortDirection", 259 value: function setSortDirection(direction) { 260 if (this.isValidSortDirection(direction)) { 261 this.state.sort.direction = direction; 262 this.save(); 263 } 264 } 265 }, 266 { 267 // ==================== Utility ==================== 268 /** 269 * Reset state to defaults 270 */ key: "reset", 271 value: function reset() { 272 this.state = _object_spread({}, DEFAULT_STATE); 273 this.save(); 274 } 275 }, 276 { 277 /** 278 * Get a snapshot of the current state (for debugging) 279 */ key: "toJSON", 280 value: function toJSON() { 281 return _object_spread({}, this.state); 282 } 283 } 284 ]); 285 return FileManagerState; 286}();
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.