-
-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(editor): refactor plug kit and events (#613)
- Loading branch information
Showing
21 changed files
with
431 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,8 @@ | ||
import Editor from '../editor' | ||
import EditorPlug from '../editor-plug' | ||
import PlugKit from '../plug-kit' | ||
|
||
export default class SamplePlug extends EditorPlug { | ||
constructor(editor: Editor) { | ||
super(editor) | ||
constructor(kit: PlugKit) { | ||
super(kit) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
import User from '@/lib/user' | ||
import * as Utils from '@/lib/utils' | ||
import Editor from '../editor' | ||
import $t from '@/i18n' | ||
import EditorPlug from '../editor-plug' | ||
import PlugKit from '../plug-kit' | ||
|
||
export default class ClosablePlug extends EditorPlug { | ||
constructor(editor: Editor) { | ||
super(editor) | ||
constructor(kit: PlugKit) { | ||
super(kit) | ||
} | ||
|
||
close() { | ||
if (!this.editor.getUI().$textareaWrap.querySelector('.atk-comment-closed')) | ||
this.editor.getUI().$textareaWrap.prepend(Utils.createElement(`<div class="atk-comment-closed">${this.editor.$t('onlyAdminCanReply')}</div>`)) | ||
if (!this.kit.useUI().$textareaWrap.querySelector('.atk-comment-closed')) | ||
this.kit.useUI().$textareaWrap.prepend(Utils.createElement(`<div class="atk-comment-closed">${$t('onlyAdminCanReply')}</div>`)) | ||
|
||
if (!User.data.isAdmin) { | ||
this.editor.getUI().$textarea.style.display = 'none' | ||
this.editor.getPlugs()?.closePlugPanel() | ||
this.editor.getUI().$bottom.style.display = 'none' | ||
this.kit.useUI().$textarea.style.display = 'none' | ||
this.kit.useEvents().trigger('panel-close') | ||
this.kit.useUI().$bottom.style.display = 'none' | ||
} else { | ||
// 管理员一直打开评论 | ||
this.editor.getUI().$textarea.style.display = '' | ||
this.editor.getUI().$bottom.style.display = '' | ||
this.kit.useUI().$textarea.style.display = '' | ||
this.kit.useUI().$bottom.style.display = '' | ||
} | ||
} | ||
|
||
open() { | ||
this.editor.getUI().$textareaWrap.querySelector('.atk-comment-closed')?.remove() | ||
this.editor.getUI().$textarea.style.display = '' | ||
this.editor.getUI().$bottom.style.display = '' | ||
this.kit.useUI().$textareaWrap.querySelector('.atk-comment-closed')?.remove() | ||
this.kit.useUI().$textarea.style.display = '' | ||
this.kit.useUI().$bottom.style.display = '' | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,32 @@ | ||
import Editor from '../editor' | ||
import $t from '@/i18n' | ||
import EditorPlug from '../editor-plug' | ||
import PlugKit from '../plug-kit' | ||
|
||
const LocalStorageKey = 'ArtalkContent' | ||
|
||
export default class LocalStoragePlug extends EditorPlug { | ||
constructor(editor: Editor) { | ||
super(editor) | ||
constructor(kit: PlugKit) { | ||
super(kit) | ||
|
||
this.kit.useMounted(() => { | ||
// load editor content from localStorage when init | ||
const localContent = window.localStorage.getItem(LocalStorageKey) || '' | ||
if (localContent.trim() !== '') { | ||
editor.showNotify(editor.$t('restoredMsg'), 'i') | ||
editor.setContent(localContent) | ||
this.kit.useEditor().showNotify($t('restoredMsg'), 'i') | ||
this.kit.useEditor().setContent(localContent) | ||
} | ||
}) | ||
|
||
this.kit.useUnmounted(() => { | ||
}) | ||
|
||
this.kit.useContentUpdated(() => { | ||
this.kit.useEvents().on('content-updated', () => { | ||
this.save() | ||
}) | ||
} | ||
|
||
// Save editor content to localStorage | ||
public save() { | ||
window.localStorage.setItem(LocalStorageKey, this.editor.getContentRaw().trim()) | ||
window.localStorage.setItem(LocalStorageKey, this.kit.useEditor().getContentRaw().trim()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.