Skip to content

Commit f57b8b1

Browse files
committed
chore(monorepo): handlers in plugins
1 parent 6649c5a commit f57b8b1

File tree

9 files changed

+52
-60
lines changed

9 files changed

+52
-60
lines changed

packages/better-write-app/src/use/editor.ts

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import { Calls, usePlugin } from 'better-write-plugin-core'
1515
import { computed, onBeforeUnmount, onMounted, watch } from 'vue'
1616
import { useI18n } from 'vue-i18n'
1717
import { onBeforeRouteLeave } from 'vue-router'
18-
import { useListener } from './listener'
1918
import { useStorage } from './storage/storage'
2019
import { useEditorStore } from '@/store/editor'
2120
import { useAbsoluteStore } from '@/store/absolute'
@@ -32,7 +31,6 @@ export const useEditor = () => {
3231
const entity = useEntity()
3332
const local = useLocalStorage()
3433
const plugin = usePlugin()
35-
const listener = useListener()
3634
const { t } = useI18n()
3735
const { toggle } = useFullscreen()
3836
const storage = useStorage()
@@ -86,12 +84,6 @@ export const useEditor = () => {
8684
{ deep: true }
8785
)
8886

89-
// window events
90-
listener.window().start()
91-
92-
// editor emitter and events
93-
listener.editor().start()
94-
9587
// theme loader
9688
plugin.emit('plugin-theme-set')
9789

packages/better-write-app/src/use/initializer/plugin.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { useHistoryStore } from '@/store/history'
3535
import * as VUEUSE_CORE from '@vueuse/core'
3636
import useEmitter from '../emitter'
3737
import { useSupabase } from '../storage/supabase'
38+
import { useCharacters } from '../characters'
3839

3940
export const usePluginInitializer = () => {
4041
const core = useCore()
@@ -79,6 +80,7 @@ export const usePluginInitializer = () => {
7980
toast: useToast(),
8081
breakpoints: useBreakpoint(),
8182
transformer: useTransformer(),
83+
characters: useCharacters(),
8284
vueuse: {
8385
core: VUEUSE_CORE,
8486
integration: {

packages/better-write-app/src/use/listener.ts

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

packages/better-write-plugin-characters/src/color.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
} from 'better-write-types'
88
import { ASTUtils } from 'better-write-contenteditable-ast'
99

10-
export const BackgroundColorSet = (
10+
export const PluginBackgroundColorSet = (
1111
emitter: PluginTypes.PluginEmitter,
1212
stores: PluginTypes.PluginStores,
1313
hooks: PluginTypes.PluginHooks
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { PluginTypes } from 'better-write-types'
2+
3+
export const PluginHandlerSet = (
4+
emitter: PluginTypes.PluginEmitter,
5+
stores: PluginTypes.PluginStores,
6+
hooks: PluginTypes.PluginHooks
7+
) => {
8+
emitter.on('call-editor-mounted', () => {
9+
// for set color in all entities with character exists
10+
hooks.characters.handler()
11+
12+
hooks.emitter.on(
13+
'characters-handler',
14+
({ index, inner }: { index: number; inner: string }) => {
15+
hooks.characters.handler(index, inner)
16+
}
17+
)
18+
})
19+
}
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import { PluginTypes } from 'better-write-types'
22
import { createPlugin } from 'better-write-plugin-core'
3-
import { BackgroundColorSet } from './color'
3+
import { PluginBackgroundColorSet } from './color'
4+
import { PluginHandlerSet } from './handler'
45

56
export const CharactersPlugin = (): PluginTypes.Plugin =>
6-
createPlugin({ name: 'characters' }, [BackgroundColorSet])
7+
createPlugin({ name: 'characters' }, [
8+
PluginHandlerSet,
9+
PluginBackgroundColorSet,
10+
])
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import { PluginTypes } from 'better-write-types'
2+
3+
export const PluginHandlerSet = (
4+
emitter: PluginTypes.PluginEmitter,
5+
stores: PluginTypes.PluginStores,
6+
hooks: PluginTypes.PluginHooks
7+
) => {
8+
emitter.on('call-editor-mounted', () => {
9+
hooks.vueuse.core.useEventListener('dragover', (e: DragEvent) => {
10+
e.preventDefault()
11+
e.stopPropagation()
12+
})
13+
14+
hooks.vueuse.core.useEventListener('drop', (event: DragEvent) => {
15+
event.preventDefault()
16+
event.stopPropagation()
17+
18+
hooks.plugin.emit('plugin-window-drop', event)
19+
})
20+
})
21+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { PluginTypes } from 'better-write-types'
22
import { createPlugin } from 'better-write-plugin-core'
33
import { PluginDropSet } from './drop'
4+
import { PluginHandlerSet } from './handler'
45

56
export const WindowPlugin = (): PluginTypes.Plugin =>
6-
createPlugin({ name: 'window' }, [PluginDropSet])
7+
createPlugin({ name: 'window' }, [PluginHandlerSet, PluginDropSet])

packages/better-write-types/src/plugin/core.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,7 @@ export interface PluginHooks {
136136
toast: PluginHook
137137
breakpoints: PluginHook
138138
transformer: PluginHook
139+
characters: PluginHook
139140
vueuse: {
140141
core: PluginHook
141142
integration: {

0 commit comments

Comments
 (0)