diff --git a/app/templates/library.html b/app/templates/library.html index 682f8f5..4337b3d 100644 --- a/app/templates/library.html +++ b/app/templates/library.html @@ -179,7 +179,7 @@ 🌐 Published - + 🔒 Private @@ -346,10 +346,8 @@ function libraryPage() { // Selection selected: {}, - get selectedCount() { return Object.keys(this.selected).length; }, - get allSelected() { - return this.flatItems.length > 0 && this.selectedCount === this.flatItems.length; - }, + selectedCount: 0, + allSelected: false, // Tree expanded: {}, @@ -369,18 +367,21 @@ function libraryPage() { peekFavorited: false, peekMoreOpen: false, - // ── Computed flat list ── - get flatItems() { + // ── Computed flat list (NOT a getter — Alpine 3.14.9 bug) ── + flatItems: [], + + _recomputeFlatItems() { var result = []; this._flatten(this.items, result, 0); - // Apply search filter if (this.searchQuery.trim()) { var q = this.searchQuery.toLowerCase(); result = result.filter(function(r) { return (r.title || '').toLowerCase().indexOf(q) !== -1; }); } - return result; + this.flatItems = result; + this.selectedCount = Object.keys(this.selected).length; + this.allSelected = this.flatItems.length > 0 && this.selectedCount === this.flatItems.length; }, _flatten(nodes, out, depth) { @@ -396,17 +397,17 @@ function libraryPage() { }, // ── Empty states ── - get emptyIcon() { + emptyIcon: '📄', + emptyTitle: 'No items', + emptyText: '', + + _recomputeEmpty() { var icons = {recents:'🕒',favorites:'⭐',shared:'👥',published:'🌐',private:'🔒',workspace:'📁',repository:'📦'}; - return icons[this.tab] || '📄'; - }, - get emptyTitle() { + this.emptyIcon = icons[this.tab] || '📄'; var titles = {recents:'No recent pages',favorites:'No favorites',shared:'No shared pages', published:'No published pages',private:'No private pages',workspace:'No workspace pages', repository:'Empty repository'}; - return titles[this.tab] || 'No items'; - }, - get emptyText() { + this.emptyTitle = titles[this.tab] || 'No items'; var texts = {recents:'Pages you\'ve recently viewed or edited will appear here.', favorites:'Right-click a page in the sidebar and select "Add to Favorites".', shared:'Shared pages from your team will appear here.', @@ -414,7 +415,7 @@ function libraryPage() { private:'Create a new page with the + button.', workspace:'Pages inside workspaces will appear here.', repository:'Repository files and pages will appear here.'}; - return texts[this.tab] || ''; + this.emptyText = texts[this.tab] || ''; }, // ── Init ── @@ -430,6 +431,7 @@ function libraryPage() { if (t && ['recents','favorites','shared','published','private','workspace','repository'].indexOf(t) !== -1) { this.tab = t; } + this._recomputeEmpty(); this.loadTab(); }, @@ -439,9 +441,12 @@ function libraryPage() { this.tab = t; this.items = []; this.selected = {}; + this.selectedCount = 0; + this.allSelected = false; this.expanded = {}; this.searchQuery = ''; this.searchOpen = false; + this._recomputeEmpty(); this.updateUrl(); this.loadTab(); }, @@ -470,6 +475,7 @@ function libraryPage() { var d = await r.json(); this.items = d.items || []; this._markTree(this.items, 0); + this._recomputeFlatItems(); } catch(e) { console.error('Library load:', e); this.items = []; @@ -490,7 +496,7 @@ function libraryPage() { } }, - doSearch() { /* flatItems reacts to searchQuery */ }, + doSearch() { this._recomputeFlatItems(); }, doSort() { var s = this.sortBy; if (!s) return; @@ -508,7 +514,7 @@ function libraryPage() { // Collapse delete this.expanded[item.id]; this.expanded = Object.assign({}, this.expanded); - this.items = [...this.items]; // force reactivity + this._recomputeFlatItems(); return; } // Expand — load children if not loaded yet @@ -525,7 +531,7 @@ function libraryPage() { item.children = []; } } - this.items = [...this.items]; // force Alpine reactivity + this._recomputeFlatItems(); }, _markChildren(nodes, depth) { @@ -546,6 +552,7 @@ function libraryPage() { this.selected[item.id] = true; } this.selected = Object.assign({}, this.selected); + this._recomputeFlatItems(); }, toggleSelectAll() { @@ -558,11 +565,13 @@ function libraryPage() { } this.selected = s; } + this._recomputeFlatItems(); }, clearSelection() { this.selected = {}; this.moreOpen = false; + this._recomputeFlatItems(); }, // ── Multi-select actions ──