Skip to content

Commit

Permalink
refa: use ctx.schema.component for schema extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Jun 3, 2024
1 parent 81d0d3c commit 6ffd2b7
Show file tree
Hide file tree
Showing 7 changed files with 15 additions and 10 deletions.
2 changes: 1 addition & 1 deletion packages/client/app/settings/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export default function (ctx: Context) {
component: Settings,
})

ctx.schema({
ctx.schema.component({
type: 'string',
role: 'theme',
component: Theme,
Expand Down
2 changes: 1 addition & 1 deletion packages/client/client/context.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import ThemeService from './plugins/theme'

// layout api

export interface Events<C extends Context> extends cordis.Events<C> {}
export interface Events<C extends Context = Context> extends cordis.Events<C> {}

export interface Context {
[Context.events]: Events<this>
Expand Down
3 changes: 1 addition & 2 deletions packages/client/client/plugins/router.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@ declare module '../context' {
page(options: Activity.Options): () => void
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
interface Events<C> {
interface Events {
'activity'(activity: Activity): boolean
}
}
Expand Down
12 changes: 10 additions & 2 deletions packages/client/client/plugins/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,15 @@ import { Dict, remove } from 'cosmokit'
import { Component, computed, markRaw, reactive, ref, watch } from 'vue'
import { Config } from '..'

declare module '@cordisjs/schema' {
interface SchemaService {
component(extension: SchemaBase.Extension): () => void
}
}

declare module '../context' {
interface Context {
$setting: SettingService
schema(extension: SchemaBase.Extension): () => void
settings(options: SettingOptions): () => void
}

Expand Down Expand Up @@ -73,7 +78,10 @@ export const useConfig = (useOriginal = false) => useOriginal ? original : resol
export default class SettingService extends Service {
constructor(ctx: Context) {
super(ctx, '$setting', true)
ctx.mixin('$setting', ['schema', 'settings'])
ctx.mixin('$setting', {
'schema': 'schema.component',
'settings': 'settings',
})

ctx.internal.settings = reactive({})

Expand Down
2 changes: 1 addition & 1 deletion packages/client/client/tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"incremental": true,
"skipLibCheck": true,
"esModuleInterop": true,
"moduleResolution": "node",
"moduleResolution": "bundler",
"strictBindCallApply": true,
"types": [
"@koishijs/client/global",
Expand Down
2 changes: 0 additions & 2 deletions plugins/explorer/.npmignore

This file was deleted.

2 changes: 1 addition & 1 deletion plugins/explorer/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'virtual:uno.css'
import './editor.scss'

export default (ctx: Context) => {
ctx.schema({
ctx.schema.component({
type: 'string',
role: 'path',
component: FilePicker,
Expand Down

0 comments on commit 6ffd2b7

Please sign in to comment.