Skip to content

Commit

Permalink
0.6.3
Browse files Browse the repository at this point in the history
Fix bug with intermittent missing line length
  • Loading branch information
alangrainger committed Oct 22, 2023
2 parents f7ff88f + 6e891ab commit e94c76a
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 21 deletions.
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"id": "share-note",
"name": "Share Note",
"version": "0.6.2",
"version": "0.6.3",
"minAppVersion": "0.15.0",
"description": "Instantly share a note, with the full theme and content exactly like you see in Reading View. Data is shared encrypted by default, and only you and the person you send it to have the key.",
"author": "Alan Grainger",
Expand Down
59 changes: 57 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "share-note",
"version": "0.6.2",
"version": "0.6.3",
"description": "Instantly share a note, with the full theme and content exactly like you see in Reading View. Data is shared encrypted by default, and only you and the person you send it to have the key.",
"main": "main.js",
"scripts": {
Expand All @@ -12,6 +12,7 @@
"author": "Alan Grainger",
"license": "MIT",
"devDependencies": {
"@types/csso": "^5.0.2",
"@types/node": "^16.11.6",
"@typescript-eslint/eslint-plugin": "5.29.0",
"@typescript-eslint/parser": "5.29.0",
Expand All @@ -24,6 +25,7 @@
"typescript": "4.7.4"
},
"dependencies": {
"csso": "^5.0.5",
"data-uri-to-buffer": "^6.0.1"
}
}
14 changes: 7 additions & 7 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ export default class SharePlugin extends Plugin {
}
})

// Add share icons to properties panel
this.registerEvent(this.app.workspace.on('active-leaf-change', () => {
this.addShareIcons()
}))

// Add command - Share note
this.addCommand({
id: 'share-note',
Expand Down Expand Up @@ -120,6 +115,11 @@ export default class SharePlugin extends Plugin {
}
})
)

// Add share icons to properties panel
this.registerEvent(this.app.workspace.on('active-leaf-change', () => {
this.addShareIcons()
}))
}

onunload () {
Expand Down Expand Up @@ -220,7 +220,7 @@ export default class SharePlugin extends Plugin {
let count = 0
const timer = setInterval(() => {
count++
if (count > 5) {
if (count > 8) {
clearInterval(timer)
return
}
Expand Down Expand Up @@ -259,7 +259,7 @@ export default class SharePlugin extends Plugin {
valueEl.prepend(iconsEl)
}
})
}, 100)
}, 50)
}

/**
Expand Down
22 changes: 13 additions & 9 deletions src/note.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { ThemeMode, TitleSource, YamlField } from './settings'
import { dataUriToBuffer } from 'data-uri-to-buffer'
import FileTypes from './libraries/FileTypes'
import { parseExistingShareUrl } from './api'
import { minify } from 'csso'

const cssAttachmentWhitelist: { [key: string]: string[] } = {
ttf: ['font/ttf', 'application/x-font-ttf', 'application/x-font-truetype', 'font/truetype'],
Expand Down Expand Up @@ -71,18 +72,19 @@ export default class Note {
const previewMode = this.leaf.getViewState()
previewMode.state.mode = 'preview'
await this.leaf.setViewState(previewMode)
await new Promise(resolve => setTimeout(resolve, 40))
// Scroll the view to the top to ensure we get the default margins for .markdown-preview-pusher
// @ts-ignore // 'view.previewMode'
this.leaf.view.previewMode.applyScroll(0)
this.status.setStatus('Processing note...')
await new Promise(resolve => setTimeout(resolve, 40))
try {
// @ts-ignore - view.modes
const renderer = this.leaf.view.modes.preview.renderer
// Copy classes and styles
this.elements.push(getElementStyle('html', document.documentElement))
this.elements.push(getElementStyle('body', document.body))
const previewEl = this.leaf.view.containerEl.querySelector('.markdown-preview-view.markdown-rendered')
if (previewEl) this.elements.push(getElementStyle('preview', previewEl as HTMLElement))
const pusherEl = this.leaf.view.containerEl.querySelector('.markdown-preview-pusher')
if (pusherEl) this.elements.push(getElementStyle('pusher', pusherEl as HTMLElement))
this.elements.push(getElementStyle('preview', renderer.previewEl))
this.elements.push(getElementStyle('pusher', renderer.pusherEl))
this.contentDom = new DOMParser().parseFromString(await this.querySelectorAll(this.leaf.view), 'text/html')
this.cssRules = []
Array.from(document.styleSheets)
Expand All @@ -100,8 +102,9 @@ export default class Note {

// Reset the view to the original mode
// The timeout is required, even though we 'await' the preview mode setting earlier
setTimeout(() => { this.leaf.setViewState(startMode) }, 400)
setTimeout(() => { this.leaf.setViewState(startMode) }, 200)

this.status.setStatus('Processing note...')
const file = this.plugin.app.workspace.getActiveFile()
if (!(file instanceof TFile)) {
// No active file
Expand Down Expand Up @@ -381,13 +384,14 @@ export default class Note {
this.status.setStatus('Uploading CSS attachments...')
await this.plugin.api.processQueue(this.status, 'CSS attachment')
this.status.setStatus('Uploading CSS...')
const cssHash = await sha1(this.css)
const minified = minify(this.css).css
const cssHash = await sha1(minified)
try {
await this.plugin.api.upload({
filetype: 'css',
hash: cssHash,
content: this.css,
byteLength: this.css.length
content: minified,
byteLength: minified.length
})

// Store the CSS theme in the settings
Expand Down
3 changes: 2 additions & 1 deletion versions.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,6 @@
"0.5.24": "0.15.0",
"0.6.0": "0.15.0",
"0.6.1": "0.15.0",
"0.6.2": "0.15.0"
"0.6.2": "0.15.0",
"0.6.3": "0.15.0"
}

0 comments on commit e94c76a

Please sign in to comment.