Skip to content

Commit

Permalink
Added json-stable-stringify to main branch
Browse files Browse the repository at this point in the history
  • Loading branch information
Developer-Mike committed Jan 15, 2025
1 parent 11d1f08 commit 50302c3
Show file tree
Hide file tree
Showing 4 changed files with 263 additions and 15 deletions.
239 changes: 236 additions & 3 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
},
"dependencies": {
"esbuild-sass-plugin": "^2.6.0",
"json-stable-stringify": "^1.2.1",
"monkey-around": "^2.3.0",
"sass": "^1.70.0",
"tiny-jsonc": "^1.0.1"
Expand Down
17 changes: 15 additions & 2 deletions src/core/canvas-patcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { requireApiVersion, WorkspaceLeaf, editorInfoField } from "obsidian"
import { EditorView, ViewUpdate } from "@codemirror/view"
import { around } from "monkey-around"
import JSONC from "tiny-jsonc"
import JSONSS from "json-stable-stringify"

export default class CanvasPatcher {
plugin: AdvancedCanvasPlugin
Expand Down Expand Up @@ -48,9 +49,21 @@ export default class CanvasPatcher {

// Patch canvas view
PatchHelper.patchObjectPrototype(this.plugin, canvasView, {
getViewData: (_next: any) => function (..._args: any) {
getViewData: (next: any) => function (...args: any) {
const canvasData = this.canvas.getData()
return JSON.stringify(canvasData, null, 2)

try {
return JSONSS(canvasData, { space: 2 })
} catch (e) {
console.error('Failed to stringify canvas data using json-stable-stringify:', e)

try {
return JSON.stringify(canvasData, null, 2)
} catch (e) {
console.error('Failed to stringify canvas data using JSON.stringify:', e)
return next.call(this, ...args)
}
}
},
setViewData: (next: any) => function (json: string, ...args: any) {
json = json !== '' ? json : '{}'
Expand Down
Loading

0 comments on commit 50302c3

Please sign in to comment.