Skip to content

Commit

Permalink
- Don't suggest tags allready on image
Browse files Browse the repository at this point in the history
- Don't resize for small resize increases
- Don't redraw for resizes unless there is column shifting
- New optional setting for max image height
- Fix for meta file not immediately being available for edit after inital creation
  • Loading branch information
TomNCatz committed Sep 13, 2023
1 parent 35ea774 commit 8850653
Show file tree
Hide file tree
Showing 8 changed files with 152 additions and 53 deletions.
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@


# Release Notes
## 1.0.0 RC1
- Fuzzy search auto completer field added to tag block
- tag block has Xs to delete tags
- Fixed refresh bug in main gallery view
- some CICD work to make builds run smoother that was not smooth to set up

## 0.8.1
- Added button to copy current main gallery filter in a format that can be pasted in a note to generate a block gallery
- Added another button to paste the same information back in as a filter to use in the gallery
Expand All @@ -48,10 +54,4 @@
## v0.7.1
- Fixing critical bug with meta file templates
- Improves display of gallery filter on mobile
- Image info blocks now try to resolve the image if the path has changed, and provides some info if it fails

## v0.7.0
- Total image count now only count file the gallery thinks it can display in the first place
- More large gallery optimization
- Added a setting for default hidden info
- Added the option to set your own template file for the meta files
- Image info blocks now try to resolve the image if the path has changed, and provides some info if it fails
3 changes: 2 additions & 1 deletion src/DisplayObjects/GalleryInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ export class GalleryInfo
const newTagEl = currentVal.createEl("input", {cls: "new-tag-input"});
newTagEl.name = "new-tag";
newTagEl.placeholder = "New Tag";
new SuggestionDropdown(newTagEl, () =>{
const suggetions = new SuggestionDropdown(newTagEl, () =>{
const files = this.plugin.app.vault.getMarkdownFiles();
const allTags: string[] = []
for(let i = 0; i < files.length; i++)
Expand Down Expand Up @@ -192,6 +192,7 @@ export class GalleryInfo
(document.querySelector("input[name='new-tag']") as HTMLInputElement).focus();
});
});
suggetions.ignoreList = this.tagList;
}

if(!this.infoList.contains("backlinks"))
Expand Down
78 changes: 64 additions & 14 deletions src/DisplayObjects/ImageGrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,40 @@ export class ImageGrid
exclusive: boolean = false
reverse : boolean = false
maxWidth : number
maxHeight : number
imgResources!: ImageResources
imgList: string[] = []
totalCount: number = 0

#tempImg: string
#columnCount: number
#redraw: boolean
#oldWidth: number = 0
#columnEls: HTMLDivElement[] = []

constructor(parent: HTMLElement, plugin: GalleryTagsPlugin)
{
this.plugin = plugin;
this.parent = parent;
this.path = this.plugin.settings.galleryLoadPath;
this.maxWidth = this.plugin.settings.width;
if(this.plugin.settings.useMaxHeight)
{
this.maxHeight = this.plugin.settings.maxHeight;
}
this.#tempImg = "data:image/gif;base64,R0lGODlhQABAAPeUMQAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAD/ACQkJCUlJSYmJicnJygoKCkpKSoqKisrKywsLC0tLS4uLi8vLzAwMDExMTIyMjMzMzQ0NDU1NTY2Njc3Nzg4ODk5OT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860t4xopUvJuCHtqZSkP3WwnJIah28qVaX5qnUkSkye168/4eFymilcv7M8SZ6Ml88fP3OknMZiB5dnPHUZn1VEx+sSUUza8vWFmdFXQ1IJfZlyqmrc4pgOC25yWkmZvcuLc3IC52/qJ2HsSoOm1BIVNq+YVGFzx+/t6k7Epra8RCrXs3O0Va/umRMTJlG/xNG9N5wnZ06paC2L9qt5SM4uDYvaZB0kdqLdP2r/ApXpe8vwE2MpM0YL1Wan6D+m66fum61UmsDHB6kPHrdlu4ByHnr/EFQgQaQ8E09J/tiFjjOjcNddLeGM9FM8z0BW4U/9rCPMJ+EluOBP+YSTkDpVqeNLfL6gqJSKLYJlYnwUWkgTjC7ShGFmISr4okI5zrRjfCL+GCOJM6JHy4Y/4ZjiiujNUk4/P9ao1JDdVSKKMerUo48/JplY5EyU/FNiLeFVYsknr8iyjTpf/oPlfg8RNYot1bgjzzl0RsQZJp+koks0uPRZp3migGKoQebptKhmApr3KEGi9BJNMa9ggt2kBskDDjCujGKYS5waZFc+52zTSyqWDFjqQf68q6PNLKPsNFUo1vljzzateGWOL/m9GpE8vGjqqrAEuTOLU7YiiOai+WSTH1Gp4PJYQoIt6k88tji1iTXoBFYRXYv2481QROWCjpnx0FWTofUY4xQn1VCplKH+pOOKU6aYA+a9feITTXlEKVPPvz8ZCg4tTnniVlUH7kdLLu/lhAs8EEe8H8HFbaNPxo+22molp1wjkI0mocRpq4IKVNFFFmWE7ECRLeQYj14FBAA7"
}

haveColumnsChanged(): boolean
{
const newColumnCount = Math.ceil(this.parent.innerWidth/this.maxWidth);
const columnCount = Math.ceil(this.parent.offsetWidth/this.maxWidth);
const result = columnCount != this.#columnEls.length;

if(result)
{
this.#redraw = true;
}

return this.#columnCount != newColumnCount;
return result;
}

async updateData()
Expand All @@ -56,28 +69,48 @@ export class ImageGrid
{
this.imgList = this.imgList.reverse()
}

this.#redraw = true;
}

updateDisplay()
{
if(this.parent.innerWidth <= 0)
if(this.parent.offsetWidth <= 0)
{
return;
}

if(!this.#redraw
&& this.parent.offsetWidth >= this.#oldWidth
&& this.parent.offsetWidth - this.#oldWidth < 20)
{
return;
}

this.#oldWidth = this.parent.offsetWidth;

if(!this.#redraw && !this.haveColumnsChanged())
{
this.#resize();
return;
}

this.parent.empty();
this.#columnEls = [];

this.#columnCount = Math.ceil(this.parent.innerWidth/this.maxWidth);
const columnWidth = (this.parent.innerWidth-15)/this.#columnCount;
const columnEls: HTMLDivElement[] = [];
const columnCount = Math.ceil(this.parent.offsetWidth/this.maxWidth);
const columnWidth = (this.parent.offsetWidth-55)/columnCount;

for(let col = 0; col < this.#columnCount; col++)
for(let col = 0; col < columnCount; col++)
{
columnEls.push(this.parent.createDiv({ cls: 'gallery-grid-column' }));
this.#columnEls.push(this.parent.createDiv({ cls: 'gallery-grid-column' }));
this.#columnEls[col].style.width = columnWidth+"px";
}

let index = 0;
while(index < this.imgList.length)
{
for(let col = 0; col < this.#columnCount; col++)
for(let col = 0; col < this.#columnEls.length; col++)
{
if(index >= this.imgList.length)
{
Expand All @@ -89,26 +122,43 @@ export class ImageGrid

if(source.match(VIDEO_REGEX))
{
const vid = columnEls[col].createEl("video");
const vid = this.#columnEls[col].createEl("video");
vid.src = source;
vid.classList.add("gallery-grid-vid");
vid.controls = true;
vid.width = columnWidth;
if(this.maxHeight > 10)
{
vid.style.maxHeight = this.maxHeight+"px";
}
}
else
{
const img = columnEls[col].createEl("img");
const img = this.#columnEls[col].createEl("img");
img.src = this.#tempImg;
img.classList.add("gallery-grid-img");
img.classList.add("lazy");
img.loading = "lazy";
img.alt = "testing alt text";
img.dataset.src = source;
img.width = columnWidth;
if(this.maxHeight > 10)
{
img.style.maxHeight = this.maxHeight+"px";
}
}
}
}

this.#redraw = false;
setLazyLoading();
}

#resize()
{
const columnWidth = (this.parent.offsetWidth-55)/this.#columnEls.length;

for(let col = 0; col < this.#columnEls.length; col++)
{
this.#columnEls[col].style.width = columnWidth+"px";
}
}
}
6 changes: 6 additions & 0 deletions src/DisplayObjects/SuggestionDropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export class SuggestionDropdown
{
target: HTMLInputElement
showOnClick: boolean = true
ignoreList: string[]
onGetItems: () => string[]
onSubmit: (submission: string) => void
onEmptyBackspace: () => void
Expand Down Expand Up @@ -167,6 +168,11 @@ export class SuggestionDropdown
const matches: [string,number][] = []
for (let i = 1; i < items.length; i++)
{
if(this.ignoreList.contains(items[i]))
{
continue;
}

const result = fuzzySearch({fuzzy: input.split(""), query: input, tokens: input.split(" ") }, items[i]);
if(result)
{
Expand Down
6 changes: 5 additions & 1 deletion src/block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export class GalleryProcessor
exclusive: 'false',
matchCase: 'false',
imgWidth: 200,
imgHeight: 0,
divWidth: 100,
divAlign: 'left',
reverseOrder: 'false',
Expand Down Expand Up @@ -60,6 +61,10 @@ export class GalleryProcessor
imageGrid.tag = args.tags;
imageGrid.reverse = args.reverseOrder === 'true';
imageGrid.maxWidth = args.imgWidth;
if(args.imgHeight > 10)
{
imageGrid.maxHeight = args.imgHeight;
}
imageGrid.exclusive = args.exclusive === 'true';
imageGrid.matchCase = args.matchCase === 'true';
imageGrid.reverse = args.reverseOrder === 'true';
Expand All @@ -75,7 +80,6 @@ export class GalleryProcessor
imageGrid.updateDisplay();
plugin.onResize = () =>
{
imagesContainer.empty();
imageGrid.updateDisplay();
}

Expand Down
57 changes: 47 additions & 10 deletions src/settings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,17 @@ export class GallerySettingTab extends PluginSettingTab

// Gallery search bar
new Setting(containerEl)
.setName('Filter starts open in main gallery')
.setDesc('Toggle this option to have the filter header start open.')
.addToggle((toggle) =>
{
toggle.setValue(this.plugin.settings.filterStartOpen)
toggle.onChange(async (value) =>
.setName('Filter starts open in main gallery')
.setDesc('Toggle this option to have the filter header start open.')
.addToggle((toggle) =>
{
this.plugin.settings.filterStartOpen = value
await this.plugin.saveSettings()
});
})
toggle.setValue(this.plugin.settings.filterStartOpen)
toggle.onChange(async (value) =>
{
this.plugin.settings.filterStartOpen = value
await this.plugin.saveSettings()
});
})

// Default image width
new Setting(containerEl)
Expand All @@ -74,6 +74,43 @@ export class GallerySettingTab extends PluginSettingTab
this.plugin.settings.width = Math.abs(numValue)
await this.plugin.saveSettings()
}))


// Use max height?
new Setting(containerEl)
.setName('Use max image height')
.setDesc('Toggle this option to set a max image height for images to display in collumns.')
.addToggle((toggle) =>
{
toggle.setValue(this.plugin.settings.useMaxHeight)
toggle.onChange(async (value) =>
{
this.plugin.settings.useMaxHeight = value;
await this.plugin.saveSettings();
this.display();
});
})

// Max image height
if(this.plugin.settings.useMaxHeight)
{
new Setting(containerEl)
.setName('Max image height')
.setDesc('Max image height in `pixels` for images to display in collumns.')
.addText(text => text
.setPlaceholder(`${this.plugin.settings.maxHeight}`)
.onChange(async (value) =>
{
const numValue = parseInt(value)
if (isNaN(numValue))
{
return;
}

this.plugin.settings.maxHeight = Math.abs(numValue)
await this.plugin.saveSettings()
}))
}

// Hidden meta fields
new Setting(containerEl)
Expand Down
13 changes: 11 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ export interface GallerySettings
galleryLoadPath: string
imgmetaTemplatePath: string | null
width: number
useMaxHeight: boolean
maxHeight: number
hiddenInfo: string | null
filterStartOpen: boolean
}
Expand All @@ -29,6 +31,7 @@ export interface GalleryBlockArgs
exclusive: string
matchCase: string
imgWidth: number
imgHeight: number
divWidth: number
divAlign: string
reverseOrder: string
Expand All @@ -46,6 +49,8 @@ export const SETTINGS: GallerySettings = {
galleryLoadPath: '/',
imgmetaTemplatePath: null,
width: 400,
useMaxHeight: false,
maxHeight: 400,
hiddenInfo: "tags;palette",
filterStartOpen: false
}
Expand Down Expand Up @@ -214,9 +219,13 @@ export const getImgInfo = async (imgPath: string, vault: Vault, metadata: Metada
template = await plugin.app.vault.read(templateTFile);
}

infoFile = await vault.create(normalizePath(`${plugin.settings.imgDataFolder}/${fileName}.md`), initializeInfo(template, imgPath, imgName));
const filepath = normalizePath(`${plugin.settings.imgDataFolder}/${fileName}.md`);
await vault.create(filepath, initializeInfo(template, imgPath, imgName));
// TODO: this waits a moment for the metadatacache to catch up with the new backlinks, but boy does it feel gross. Need to find out if there's another way to do this
await new Promise(f => setTimeout(f, 50));
infoFile = plugin.app.vault.getAbstractFileByPath(filepath) as TFile
}
return infoFile
return infoFile
}

// Specified Resources folder does not exist
Expand Down
Loading

0 comments on commit 8850653

Please sign in to comment.