Skip to content

Commit 104a436

Browse files
committed
refactor(core)!: migrate to custom DnD engine and update patching logic
- Remove `sortablejs` dependency and implement custom drag-and-drop engine in `dnd-manager.ts` - Update patching logic to intercept `getSortedFolderItems` method and sort items in custom order - Don't save `customOrder` changes to `data.json` on file create/delete to avoid sync conflicts (only save on drag-and-drop) - Replace drag animation with Spotify-like drop indicator - Move managers to separate `managers/` folder with barrel exports - Add `infoCompact` method to `Logger` for convenient large object output - Simplify `ResetOrderModal` message - Simplify `SettingsTab` description - Add removal of third-party properties from settings file in `loadSettings` - Add barrel file exports in `utils` folder - Disable `@typescript-eslint/no-non-null-assertion` rule in ESLint config BREAKING CHANGES: - Changed settings storage format: renamed `customFileOrder` to `customOrder`, `selectedSortOrder` to `sortOrder`, and `newItemsPosition` to `newItemPlacement` - Removed `draggingEnabled` option Fixes #34, #46, #48, #49, #73
1 parent 4496135 commit 104a436

21 files changed

+651
-917
lines changed

eslint.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ export default defineConfig([
2424
'@typescript-eslint/no-confusing-void-expression': ['error', { ignoreArrowShorthand: true }],
2525
'@typescript-eslint/no-this-alias': 'off',
2626
'@typescript-eslint/prefer-nullish-coalescing': 'off',
27+
'@typescript-eslint/no-non-null-assertion': 'off',
2728
'@typescript-eslint/naming-convention': ['error', {
2829
selector: ['classProperty', 'classMethod'],
2930
format: ['camelCase'],

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,7 @@
5757
"vitest": "^4.0.6"
5858
},
5959
"dependencies": {
60-
"monkey-around": "^3.0.0",
61-
"sortablejs": "^1.15.6"
60+
"monkey-around": "^3.0.0"
6261
},
6362
"simple-git-hooks": {
6463
"pre-commit": "pnpm lint-staged"

pnpm-lock.yaml

Lines changed: 0 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/reset-order-modal.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import { App, ButtonComponent, Modal } from 'obsidian'
22

33
export class ResetOrderModal extends Modal {
4-
constructor(app: App, prevSelectedSortOrder: string, onSubmit: () => void) {
4+
constructor(app: App, onSubmit: () => void) {
55
super(app)
66
this.setTitle('Manual sorting')
77
this.modalEl.addClass('manual-sorting-modal')
88

99
const modalContent = this.contentEl.createEl('div')
10-
modalContent.createEl('p', { text: `Reset custom order to match previously selected one (${prevSelectedSortOrder})?` })
10+
modalContent.createEl('p', { text: `Reset custom order?` })
1111
const modalButtons = modalContent.createEl('div', { cls: 'modal-buttons' })
1212
new ButtonComponent(modalButtons)
1313
.setButtonText('Yep')

src/components/settings-tab.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { App, PluginSettingTab, Setting } from 'obsidian'
22
import type ManualSortingPlugin from '@/plugin'
3-
import { Logger } from '@/utils/logger'
3+
import { Logger } from '@/utils'
44

55
export class SettingsTab extends PluginSettingTab {
66
constructor(app: App, public plugin: ManualSortingPlugin) {
@@ -11,14 +11,14 @@ export class SettingsTab extends PluginSettingTab {
1111
this.containerEl.empty()
1212

1313
new Setting(this.containerEl)
14-
.setName('New items position')
15-
.setDesc('Position of newly created items in a folder.')
14+
.setName('New item placement')
15+
.setDesc('Default new item placement.')
1616
.addDropdown(dropdown => dropdown
1717
.addOption('top', 'Top')
1818
.addOption('bottom', 'Bottom')
19-
.setValue(this.plugin.settings.newItemsPosition)
19+
.setValue(this.plugin.settings.newItemPlacement)
2020
.onChange(async value => {
21-
this.plugin.settings.newItemsPosition = value as 'top' | 'bottom'
21+
this.plugin.settings.newItemPlacement = value as 'top' | 'bottom'
2222
await this.plugin.saveSettings()
2323
}),
2424
)

src/constants.ts

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,12 @@
11
import { type PluginSettings } from '@/types.d'
22

3-
export const MANUAL_SORTING_MODE_ID = 'manual-sorting'
3+
export const CUSTOM_SORTING_ID = 'customOrder'
44

5-
export const DND_MIN_SWAP_THRESHOLD = 0.3
6-
export const DND_MAX_SWAP_THRESHOLD = 2
7-
8-
export const FILE_EXPLORER_SELECTOR = '[data-type="file-explorer"] .nav-files-container'
5+
export const FILE_EXPLORER_SELECTOR = '[data-type="file-explorer"] > .nav-files-container > div'
96

107
export const DEFAULT_SETTINGS: PluginSettings = {
11-
customFileOrder: { '/': [] },
12-
draggingEnabled: true,
13-
selectedSortOrder: 'manual-sorting',
8+
customOrder: { '/': [] },
9+
sortOrder: 'customOrder',
1410
debugMode: !!process.env.DEV,
15-
newItemsPosition: 'top',
11+
newItemPlacement: 'top',
1612
}

src/dnd-manager.ts

Lines changed: 0 additions & 178 deletions
This file was deleted.

0 commit comments

Comments
 (0)