Skip to content

Commit

Permalink
feat: v3.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
surmon-china committed Jan 2, 2022
1 parent 790f9c9 commit 9bec5b6
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 21 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Expand Up @@ -2,6 +2,16 @@

All notable changes to this project will be documented in this file.

### v3.3.6 (2022-01-02)

**Feature**

- Improve copyrighter when focus comment publisher

**Fix**

- Fix comment reply preview

### v3.3.4 (2022-01-01)

**Feature**
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "surmon.me",
"version": "3.3.5",
"version": "3.3.6",
"description": "Surmon.me blog",
"author": {
"name": "Surmon",
Expand Down
20 changes: 11 additions & 9 deletions src/components/comment/publisher/pen.vue
Expand Up @@ -6,6 +6,8 @@
class="markdown-input"
:contenteditable="!disabled"
:placeholder="t(LANGUAGE_KEYS.COMMENT_POST_PLACEHOLDER)"
@focus="disableCopyrighter"
@blur="enableCopyrighter"
/>
<transition name="list-fade">
<div
Expand Down Expand Up @@ -91,12 +93,13 @@

<script lang="ts">
import { defineComponent, ref, computed, watch, onMounted, onBeforeUnmount, nextTick } from 'vue'
import { useEnhancer } from '/@/app/enhancer'
import { useUniversalStore, UserType } from '/@/store/universal'
import { useEnhancer } from '/@/app/enhancer'
import { LANGUAGE_KEYS } from '/@/language/key'
import { enableCopyrighter, disableCopyrighter } from '/@/services/copyright'
import { focusPosition } from '/@/utils/editable'
import { insertContent } from '/@/utils/editable'
import { markdownToHTML } from '/@/transforms/markdown'
import { focusPosition } from '/@/utils/editable'
import { VALUABLE_LINKS } from '/@/config/app.config'
import { CommentEvents, EMOJIS } from '../helper'

Expand Down Expand Up @@ -146,7 +149,7 @@
const inputElement = ref<HTMLElement>()
let inputElementObserver: MutationObserver | null = null
const previewContent = computed(() => {
return props.previewed ? markdownToHTML(content.value, { sanitize: true }) : null
return isPreviewed.value ? markdownToHTML(content.value, { sanitize: true }) : null
})

const handleTogglePreview = () => {
Expand Down Expand Up @@ -218,22 +221,19 @@
}
})
}

// watch element
inputElementObserver = new MutationObserver((mutations) => {
handleInputChange()
})
inputElementObserver = new MutationObserver(() => handleInputChange())
inputElementObserver.observe(inputElement.value!, {
attributes: true,
characterData: true,
childList: true,
subtree: true
})
})

onBeforeUnmount(() => {
inputElementObserver?.disconnect()
})

return {
t: i18n.t,
user: universalStore.user,
Expand All @@ -250,7 +250,9 @@
insertCode,
handleInputChange,
handleTogglePreview,
handleSubmit
handleSubmit,
enableCopyrighter,
disableCopyrighter
}
}
})
Expand Down
4 changes: 2 additions & 2 deletions src/csr.ts
Expand Up @@ -23,7 +23,7 @@ import { createMusic } from '/@/services/music'
import { createPopup } from '/@/services/popup'
import { createLoading } from '/@/services/loading'
import { consoleSlogan } from '/@/services/slogan'
import { enableCopyrighter } from '/@/services/copyright'
import { initCopyrighter } from '/@/services/copyright'
import { enableBaiduSEOer } from '/@/services/baidu-seo-push'
import { runTitler, resetTitler } from '/@/services/titler'
import { exportEmojiRainToGlobal } from '/@/services/emoji-23333'
Expand Down Expand Up @@ -76,6 +76,7 @@ exportLozadToGlobal()
exportEmojiRainToGlobal()
exportStickyEventsToGlobal()
exportAppToGlobal(app)
initCopyrighter()

// init: router loading middleware client only
router.beforeEach((_, __, next) => {
Expand Down Expand Up @@ -126,7 +127,6 @@ router.isReady().finally(() => {

// production only
if (isProd) {
enableCopyrighter()
enableBaiduSEOer(router)
consoleSlogan(i18n, store.stores.meta.appOptions.data?.site_email)
}
Expand Down
18 changes: 17 additions & 1 deletion src/services/copyright.ts
Expand Up @@ -6,7 +6,23 @@

import { META } from '/@/config/app.config'

declare global {
interface Window {
__isEnabledCopyrighter: boolean
}
}

export const enableCopyrighter = () => {
window.__isEnabledCopyrighter = true
}

export const disableCopyrighter = () => {
window.__isEnabledCopyrighter = false
}

export const initCopyrighter = () => {
enableCopyrighter()

const copyText = () => {
return [
'',
Expand All @@ -24,7 +40,7 @@ export const enableCopyrighter = () => {

document.addEventListener('copy', (event) => {
if (!window.getSelection) return
if (!window.$isCopyFromApp) {
if (window.__isEnabledCopyrighter) {
const content = window.getSelection()?.toString()
event.clipboardData?.setData('text/plain', buildText(content))
event.clipboardData?.setData('text/html', buildHtml(content))
Expand Down
12 changes: 4 additions & 8 deletions src/utils/clipboard.ts
Expand Up @@ -4,19 +4,15 @@
* @author Surmon <https://github.com/surmon-china>
*/

declare global {
interface Window {
$isCopyFromApp: boolean
}
}
import { enableCopyrighter, disableCopyrighter } from '/@/services/copyright'

export const read = () => navigator.clipboard.readText()
export const copy = (text: string) => {
window.$isCopyFromApp = true
disableCopyrighter()
// https://www.w3.org/TR/clipboard-apis/#async-clipboard-api
// MARK: only https site
window.navigator.clipboard?.writeText(text).finally(() => {
window.$isCopyFromApp = false
return window.navigator.clipboard?.writeText(text).finally(() => {
enableCopyrighter()
})
}

Expand Down

0 comments on commit 9bec5b6

Please sign in to comment.