+ callback: F
- cbFuncName = 'onSubmit'
- props: Partial = {}
+ cbFuncName = 'onSubmit'
+ props: Partial
= {}
- abstract title: string
- abstract component: C
+ abstract title: string
+ abstract component: C
- constructor(app: App, cb: F, props: Partial
= {}) {
- super(app)
+ constructor(app: App, cb: F, props: Partial
= {}) {
+ super(app)
- this.callback = cb
- this.props = { ...this.props, ...props }
- }
+ this.callback = cb
+ this.props = { ...this.props, ...props }
+ }
- onOpen(): void {
- this.setTitle(this.title)
- this.shouldRestoreSelection = true
+ onOpen(): void {
+ this.setTitle(this.title)
+ this.shouldRestoreSelection = true
- this.svelteContent = mount(this.component, {
- target: this.contentEl,
- props: {
- ...this.props,
- [this.cbFuncName]: (...args: unknown[]) => {
- this.callback(...args)
- this.close()
- }
- }
- })
- }
+ this.svelteContent = mount(this.component, {
+ target: this.contentEl,
+ props: {
+ ...this.props,
+ [this.cbFuncName]: (...args: unknown[]) => {
+ this.callback(...args)
+ this.close()
+ }
+ }
+ })
+ }
- async onClose() {
- unmount(this.svelteContent, { outro: true })
- }
+ async onClose() {
+ unmount(this.svelteContent, { outro: true })
+ }
}
export type NewLayoutCallback = (name: string, paths: string, platformMode: PlatformMode) => void
export class NewLayoutModal extends genericSvelteModal {
- title = 'New Layout...'
- component = NewLayout
+ title = 'New Layout...'
+ component = NewLayout
}
export type OverrideLayoutCallback = (name: string) => void
export class OverrideLayoutModal extends genericSvelteModal<
- OverrideLayoutCallback,
- typeof OverrideLayout
+ OverrideLayoutCallback,
+ typeof OverrideLayout
> {
- title = 'Override Layout...'
- component = OverrideLayout
+ title = 'Override Layout...'
+ component = OverrideLayout
}
export type ConfirmationModalCallback = (confirmed: boolean) => void
export class ConfirmModal extends genericSvelteModal<
ConfirmationModalCallback,
- typeof Confirmation
+ typeof Confirmation
> {
- title = 'Are you sure?'
- component = Confirmation
+ title = 'Are you sure?'
+ component = Confirmation
}
diff --git a/src/obsidianLayout.ts b/src/obsidianLayout.ts
index d20275a..2476e77 100644
--- a/src/obsidianLayout.ts
+++ b/src/obsidianLayout.ts
@@ -3,38 +3,38 @@
import { type ViewState } from 'obsidian'
export type KnownContainers = {
- split: { direction: string }
- tabs: Record
- leaf: { state: ViewState & ViewStateFile; group?: string }
+ split: { direction: string }
+ tabs: Record
+ leaf: { state: ViewState & ViewStateFile; group?: string }
}
// I hate typescript
export type AnyContainer =
- | GenericContainer<'leaf'>
- | GenericContainer<'split'>
- | GenericContainer<'tabs'>
+ | GenericContainer<'leaf'>
+ | GenericContainer<'split'>
+ | GenericContainer<'tabs'>
export type GenericContainer = {
- id?: string
- active?: boolean
- type: N
- children?: AnyContainer[]
+ id?: string
+ active?: boolean
+ type: N
+ children?: AnyContainer[]
} & KnownContainers[N]
export interface ViewStateFile {
- type: 'markdown'
- state: {
- file: string
- mode: 'preview' | 'source'
- source: boolean
- }
+ type: 'markdown'
+ state: {
+ file: string
+ mode: 'preview' | 'source'
+ source: boolean
+ }
}
export type LayoutData = {
- // We don't care about layout data for anything other than the user content
- // Though... future release maybe? If someone asks ig
- main: AnyContainer
- active: string
+ // We don't care about layout data for anything other than the user content
+ // Though... future release maybe? If someone asks ig
+ main: AnyContainer
+ active: string
}
/**
@@ -42,33 +42,33 @@ export type LayoutData = {
* @param setActive When an active leaf is found, it will call this cb
*/
export function targetedLayout(
- l: AnyContainer,
- f: string,
- setActive: (id: string) => void,
- ogSet: Set
+ l: AnyContainer,
+ f: string,
+ setActive: (id: string) => void,
+ ogSet: Set
): AnyContainer {
- if (l.active) {
- delete l.active
- l.id = randomId(16)
- setActive(l.id)
- }
+ if (l.active) {
+ delete l.active
+ l.id = randomId(16)
+ setActive(l.id)
+ }
- if (l.type != 'leaf') {
- l.children?.forEach((c) => targetedLayout(c, f, setActive, ogSet))
- return l
- }
+ if (l.type != 'leaf') {
+ l.children?.forEach((c) => targetedLayout(c, f, setActive, ogSet))
+ return l
+ }
- if (!l.active) {
- l.id = randomId(16)
- }
+ if (!l.active) {
+ l.id = randomId(16)
+ }
- ogSet.add(l.id as string)
+ ogSet.add(l.id as string)
- if (l.state.type == 'markdown') {
- l.state.state.file = f
- }
+ if (l.state.type == 'markdown') {
+ l.state.state.file = f
+ }
- return l
+ return l
}
/**
@@ -76,43 +76,43 @@ export function targetedLayout(
* l becomes dirty after this, do not use it again.
*/
export function savableLayout(
- l: AnyContainer,
- fileSet: Set,
- activeID: string
+ l: AnyContainer,
+ fileSet: Set,
+ activeID: string
): AnyContainer {
- // This is basically js referance abuse, which is always fun & reliable & easy to debug :3
+ // This is basically js referance abuse, which is always fun & reliable & easy to debug :3
- if (l.id == activeID) {
- l.active = true
- }
+ if (l.id == activeID) {
+ l.active = true
+ }
- delete l.id
+ delete l.id
- if (l.type == 'leaf') {
- if (l.state.type == 'markdown') {
- fileSet.add(l.state.state.file)
+ if (l.type == 'leaf') {
+ if (l.state.type == 'markdown') {
+ fileSet.add(l.state.state.file)
- // @ts-expect-error Title causes issues
- delete l.state.title
+ // @ts-expect-error Title causes issues
+ delete l.state.title
- // Avoid saving extra metadata, set bare minimums
- l.state.state = {
- file: '',
- mode: l.state.state.mode,
- source: l.state.state.source
- }
- }
- } else {
- l.children?.forEach((c) => savableLayout(c, fileSet, activeID))
- }
+ // Avoid saving extra metadata, set bare minimums
+ l.state.state = {
+ file: '',
+ mode: l.state.state.mode,
+ source: l.state.state.source
+ }
+ }
+ } else {
+ l.children?.forEach((c) => savableLayout(c, fileSet, activeID))
+ }
- return l
+ return l
}
const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
function randomId(l: number) {
- return Array.from(
- { length: l },
- () => possible[Math.floor(Math.random() * possible.length)]
- ).join('')
+ return Array.from(
+ { length: l },
+ () => possible[Math.floor(Math.random() * possible.length)]
+ ).join('')
}
diff --git a/src/settings.ts b/src/settings.ts
index 5c8a941..0f35bda 100644
--- a/src/settings.ts
+++ b/src/settings.ts
@@ -1,4 +1,5 @@
-import { App, PluginSettingTab } from 'obsidian'
+import type { App } from 'obsidian'
+import { PluginSettingTab } from 'obsidian'
import type { AnyContainer } from './obsidianLayout'
import { mount, unmount } from 'svelte'
import Settings from './components/settings/Settings.svelte'
@@ -6,22 +7,22 @@ import { writable } from 'svelte/store'
import type LayoutManager from './main'
export enum PlatformMode {
- BOTH = 'both',
- COMPUTER = 'computer',
- MOBILE = 'mobile'
+ BOTH = 'both',
+ COMPUTER = 'computer',
+ MOBILE = 'mobile'
}
export interface SavedLayout {
- platformMode: PlatformMode
- container: AnyContainer
- name: string
- patterns: string
+ platformMode: PlatformMode
+ container: AnyContainer
+ name: string
+ patterns: string
}
export type SettingData = SavedLayout[]
export class LayoutMgrSettings extends PluginSettingTab {
- svelteContent: Settings
+ svelteContent: Settings
plugin: LayoutManager
constructor(app: App, plugin: LayoutManager) {
@@ -30,8 +31,8 @@ export class LayoutMgrSettings extends PluginSettingTab {
this.plugin = plugin
}
- display(): void {
- this.containerEl.addClass("lm-settings")
+ display(): void {
+ this.containerEl.addClass('lm-settings')
const settingProxy = writable(this.plugin.settings)
settingProxy.subscribe((v) => {
@@ -39,14 +40,14 @@ export class LayoutMgrSettings extends PluginSettingTab {
this.plugin.saveSettings()
})
- this.svelteContent = mount(Settings, {
- target: this.containerEl,
- props: {
+ this.svelteContent = mount(Settings, {
+ target: this.containerEl,
+ props: {
settings: settingProxy,
- app: this.app,
- }
- })
- }
+ app: this.app
+ }
+ })
+ }
hide() {
unmount(this.svelteContent, { outro: true })