mirror of
https://github.com/gra0007/obsidian-css-inlay-colors.git
synced 2026-07-22 05:18:59 +00:00
feat: migrate settings to Obsidian 1.13 API
This commit is contained in:
parent
10090e7d7a
commit
be8d9a2da4
3 changed files with 159 additions and 21 deletions
|
|
@ -36,7 +36,7 @@
|
|||
"builtin-modules": "5.0.0",
|
||||
"covector": "^0.12.4",
|
||||
"esbuild": "0.27.1",
|
||||
"obsidian": "latest",
|
||||
"obsidian": "^1.13.1",
|
||||
"tslib": "2.8.1",
|
||||
"typescript": "5.9.3"
|
||||
},
|
||||
|
|
|
|||
|
|
@ -40,8 +40,8 @@ importers:
|
|||
specifier: 0.27.1
|
||||
version: 0.27.1
|
||||
obsidian:
|
||||
specifier: latest
|
||||
version: 1.10.3(@codemirror/state@6.5.2)(@codemirror/view@6.39.2)
|
||||
specifier: ^1.13.1
|
||||
version: 1.13.1(@codemirror/state@6.5.2)(@codemirror/view@6.39.2)
|
||||
tslib:
|
||||
specifier: 2.8.1
|
||||
version: 2.8.1
|
||||
|
|
@ -601,7 +601,7 @@ packages:
|
|||
glob@8.1.0:
|
||||
resolution: {integrity: sha512-r8hpEjiQEYlF2QU0df3dS+nxxSIreXQS1qRhMJM0Q5NDdR386C7jb7Hwwod8Fgiuex+k0GFjgft18yvxm5XoCQ==}
|
||||
engines: {node: '>=12'}
|
||||
deprecated: Glob versions prior to v9 are no longer supported
|
||||
deprecated: Old versions of glob are not supported, and contain widely publicized security vulnerabilities, which have been fixed in the current version. Please update. Support for old versions may be purchased (at exorbitant rates) by contacting i@izs.me
|
||||
|
||||
globby@11.1.0:
|
||||
resolution: {integrity: sha512-jhIXaOzy1sb8IyocaruWSn1TjmnBVs8Ayhcy83rmxNJ8q2uWKCAj3CnJY+KpGSXCueAPc0i05kVvVKtP1t9S3g==}
|
||||
|
|
@ -752,8 +752,8 @@ packages:
|
|||
resolution: {integrity: sha512-6eZs5Ls3WtCisHWp9S2GUy8dqkpGi4BVSz3GaqiE6ezub0512ESztXUwUB6C6IKbQkY2Pnb/mD4WYojCRwcwLA==}
|
||||
engines: {node: '>=0.10.0'}
|
||||
|
||||
obsidian@1.10.3:
|
||||
resolution: {integrity: sha512-VP+ZSxNMG7y6Z+sU9WqLvJAskCfkFrTz2kFHWmmzis+C+4+ELjk/sazwcTHrHXNZlgCeo8YOlM6SOrAFCynNew==}
|
||||
obsidian@1.13.1:
|
||||
resolution: {integrity: sha512-qtTEA2pmhJzhuhJqzbBFRYhpIOqvW+krDYjtFynv66KbxBbumHBlsJfWw3I4jtnK/6fZwbQhCrmmDdRwXmX56w==}
|
||||
peerDependencies:
|
||||
'@codemirror/state': 6.5.0
|
||||
'@codemirror/view': 6.38.6
|
||||
|
|
@ -1109,18 +1109,17 @@ snapshots:
|
|||
style-mod: 4.1.3
|
||||
w3c-keyname: 2.2.8
|
||||
|
||||
'@covector/apply@0.10.0(mocha@10.8.2)':
|
||||
'@covector/apply@0.10.0':
|
||||
dependencies:
|
||||
'@covector/files': 0.8.0
|
||||
effection: 2.0.8(mocha@10.8.2)
|
||||
semver: 7.7.2
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
- mocha
|
||||
|
||||
'@covector/assemble@0.12.0(mocha@10.8.2)':
|
||||
'@covector/assemble@0.12.0':
|
||||
dependencies:
|
||||
'@covector/command': 0.8.0(mocha@10.8.2)
|
||||
'@covector/command': 0.8.0
|
||||
'@covector/files': 0.8.0
|
||||
effection: 2.0.8(mocha@10.8.2)
|
||||
js-yaml: 4.1.0
|
||||
|
|
@ -1131,7 +1130,6 @@ snapshots:
|
|||
unified: 9.2.2
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
- mocha
|
||||
- supports-color
|
||||
|
||||
'@covector/changelog@0.12.0(mocha@10.8.2)':
|
||||
|
|
@ -1147,13 +1145,12 @@ snapshots:
|
|||
- mocha
|
||||
- supports-color
|
||||
|
||||
'@covector/command@0.8.0(mocha@10.8.2)':
|
||||
'@covector/command@0.8.0':
|
||||
dependencies:
|
||||
'@effection/process': 2.1.4(mocha@10.8.2)
|
||||
'@effection/process': 2.1.4
|
||||
effection: 2.0.8(mocha@10.8.2)
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
- mocha
|
||||
|
||||
'@covector/files@0.8.0':
|
||||
dependencies:
|
||||
|
|
@ -1200,8 +1197,10 @@ snapshots:
|
|||
dependencies:
|
||||
effection: 2.0.8(mocha@10.8.2)
|
||||
mocha: 10.8.2
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
|
||||
'@effection/process@2.1.4(mocha@10.8.2)':
|
||||
'@effection/process@2.1.4':
|
||||
dependencies:
|
||||
cross-spawn: 7.0.6
|
||||
ctrlc-windows: 2.2.0
|
||||
|
|
@ -1209,7 +1208,6 @@ snapshots:
|
|||
shellwords: 0.1.1
|
||||
transitivePeerDependencies:
|
||||
- encoding
|
||||
- mocha
|
||||
|
||||
'@effection/stream@2.0.6':
|
||||
dependencies:
|
||||
|
|
@ -1438,10 +1436,10 @@ snapshots:
|
|||
covector@0.12.4(mocha@10.8.2):
|
||||
dependencies:
|
||||
'@clack/prompts': 0.7.0
|
||||
'@covector/apply': 0.10.0(mocha@10.8.2)
|
||||
'@covector/assemble': 0.12.0(mocha@10.8.2)
|
||||
'@covector/apply': 0.10.0
|
||||
'@covector/assemble': 0.12.0
|
||||
'@covector/changelog': 0.12.0(mocha@10.8.2)
|
||||
'@covector/command': 0.8.0(mocha@10.8.2)
|
||||
'@covector/command': 0.8.0
|
||||
'@covector/files': 0.8.0
|
||||
effection: 2.0.8(mocha@10.8.2)
|
||||
globby: 11.1.0
|
||||
|
|
@ -1754,7 +1752,7 @@ snapshots:
|
|||
|
||||
normalize-path@3.0.0: {}
|
||||
|
||||
obsidian@1.10.3(@codemirror/state@6.5.2)(@codemirror/view@6.39.2):
|
||||
obsidian@1.13.1(@codemirror/state@6.5.2)(@codemirror/view@6.39.2):
|
||||
dependencies:
|
||||
'@codemirror/state': 6.5.2
|
||||
'@codemirror/view': 6.39.2
|
||||
|
|
|
|||
142
src/settings.ts
142
src/settings.ts
|
|
@ -1,4 +1,10 @@
|
|||
import { type App, PluginSettingTab, Setting } from 'obsidian'
|
||||
import {
|
||||
type App,
|
||||
PluginSettingTab,
|
||||
requireApiVersion,
|
||||
Setting,
|
||||
type SettingDefinitionItem,
|
||||
} from 'obsidian'
|
||||
import type CssColorsPlugin from './main'
|
||||
import { downloadPredefinedPalettes } from './palettes'
|
||||
|
||||
|
|
@ -26,6 +32,140 @@ export class CssColorsSettingsTab extends PluginSettingTab {
|
|||
this.plugin = plugin
|
||||
}
|
||||
|
||||
getSettingDefinitions(): SettingDefinitionItem<
|
||||
keyof CssColorsPluginSettings
|
||||
>[] {
|
||||
if (!requireApiVersion('1.13.0')) return []
|
||||
|
||||
return [
|
||||
{
|
||||
name: 'Show in live preview mode',
|
||||
desc: 'Enable color inlays in the live preview (requires reload).',
|
||||
control: { type: 'toggle', key: 'showInLiveEditor' },
|
||||
},
|
||||
{
|
||||
name: 'Enable the color picker',
|
||||
desc: createFragment((desc) => {
|
||||
desc.appendText(
|
||||
'Allows you to edit a color by clicking on the inlay.',
|
||||
)
|
||||
desc.createDiv({
|
||||
text: 'Opacity and colors outside of the sRGB color space are not supported.',
|
||||
cls: 'mod-warning',
|
||||
})
|
||||
}),
|
||||
control: { type: 'toggle', key: 'colorPickerEnabled' },
|
||||
},
|
||||
{
|
||||
name: 'Hide all color names',
|
||||
desc: 'Hides the inline code block in live preview and reading mode for all colors so only the color inlay is visible. You can also do this on a case-by-case basis by surrounding the color with square brackets.',
|
||||
control: { type: 'toggle', key: 'hideNames' },
|
||||
},
|
||||
{
|
||||
name: 'Copy on click',
|
||||
desc: 'Allows clicking on a color in reading mode to copy it to your clipboard.',
|
||||
control: { type: 'toggle', key: 'copyOnClick' },
|
||||
},
|
||||
{
|
||||
type: 'group',
|
||||
heading: 'Custom Palettes',
|
||||
items: [
|
||||
{
|
||||
name: 'Enable palette support',
|
||||
desc: createFragment((desc) => {
|
||||
desc.appendText(
|
||||
'Enable custom color palette support. This will generate classes for every inline code block surrounded in parentheses so they can be targeted with a CSS snippet file.',
|
||||
)
|
||||
desc.createEl('br')
|
||||
desc.createEl('a', {
|
||||
text: 'Learn more',
|
||||
href: 'https://github.com/GRA0007/obsidian-css-inlay-colors?tab=readme-ov-file#custom-palettes',
|
||||
})
|
||||
}),
|
||||
control: { type: 'toggle', key: 'palettesEnabled' },
|
||||
},
|
||||
{
|
||||
name: 'Download predefined palettes',
|
||||
desc: createFragment((desc) => {
|
||||
desc.appendText('You can download a ')
|
||||
desc.createEl('a', {
|
||||
text: 'snippet file',
|
||||
href: 'https://github.com/GRA0007/obsidian-css-inlay-colors/blob/main/palettes.css',
|
||||
})
|
||||
desc.appendText(
|
||||
' with some predefined palettes. It comes with the following:',
|
||||
)
|
||||
}),
|
||||
render: (setting) => {
|
||||
setting
|
||||
.addButton((button) => {
|
||||
button
|
||||
.setButtonText('Download')
|
||||
.onClick(() => downloadPredefinedPalettes(this.app))
|
||||
})
|
||||
.infoEl.createDiv({ cls: 'setting-item-description' })
|
||||
.createEl('ul', {
|
||||
text: createFragment((el) => {
|
||||
el.createEl('li', {
|
||||
text: createFragment((li) => {
|
||||
li.createEl('strong', { text: 'AutoCAD Color Index' })
|
||||
li.createDiv({ text: 'Example: (aci 91)' })
|
||||
}),
|
||||
})
|
||||
el.createEl('li', {
|
||||
text: createFragment((li) => {
|
||||
li.createEl('strong', {
|
||||
text: 'Australian Color Standard (AS 2700)',
|
||||
})
|
||||
li.createDiv({ text: 'Example: (as N45)' })
|
||||
}),
|
||||
})
|
||||
el.createEl('li', {
|
||||
text: createFragment((li) => {
|
||||
li.createEl('strong', {
|
||||
text: 'British Standard Colors (BS 381, BS 4800)',
|
||||
})
|
||||
li.createDiv({
|
||||
text: 'Example: (bs 381 593) or (bs 14-E-51)',
|
||||
})
|
||||
}),
|
||||
})
|
||||
el.createEl('li', {
|
||||
text: createFragment((li) => {
|
||||
li.createEl('strong', {
|
||||
text: 'Federal Standard (FS 595C, ANA)',
|
||||
})
|
||||
li.createDiv({
|
||||
text: 'Example: (fs 11086) or (fs w3-ana-609)',
|
||||
})
|
||||
}),
|
||||
})
|
||||
el.createEl('li', {
|
||||
text: createFragment((li) => {
|
||||
li.createEl('strong', {
|
||||
text: 'RAL Colors (Classic, Design, Effect, Plastics)',
|
||||
})
|
||||
li.createDiv({
|
||||
text: 'Example: (ral 170 50 10) or (ral 6010)',
|
||||
})
|
||||
}),
|
||||
})
|
||||
}),
|
||||
})
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
]
|
||||
}
|
||||
|
||||
async setControlValue(key: string, value: unknown): Promise<void> {
|
||||
if (!(key in this.plugin.settings)) return
|
||||
|
||||
Reflect.set(this.plugin.settings, key, value)
|
||||
await this.plugin.saveSettings()
|
||||
}
|
||||
|
||||
display(): void {
|
||||
const { containerEl } = this
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue