Skip to content

Commit

Permalink
feat: install plugin (lang, etc.)
Browse files Browse the repository at this point in the history
  • Loading branch information
mekery committed Apr 17, 2020
1 parent b0b28a0 commit ab22477
Show file tree
Hide file tree
Showing 9 changed files with 43 additions and 39 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quasar-tiptap",
"version": "1.0.1",
"version": "1.0.2",
"description": "A modern WYSIWYG rich-text editor built on top of tiptap and Quasar for Vue.js",
"productName": "Quasar Tiptap",
"scripts": {
Expand Down
7 changes: 0 additions & 7 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@
</template>

<script>
import Vue from 'vue'
import { QuasarTiptapPlugin } from './index'
Vue.use(QuasarTiptapPlugin, {
language: 'zh-hans',
spellcheck: true
})
export default {
name: 'App'
Expand Down
10 changes: 0 additions & 10 deletions src/components/QuasarTiptap.vue
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ import DynamicClass from 'src/extentions/dynamic'
import OEditorMenuBar from 'src/components/menubars/OEditorMenuBar'
import OEditorMenuBubble from 'src/components/menubars/OEditorMenuBubble'
import Lang from 'src/lang'
export default {
name: 'quasar-tiptap',
Expand Down Expand Up @@ -244,15 +243,6 @@ export default {
showSidePanel () {},
onSlideShow () {}
},
beforeCreate () {
if (!this.$o) {
let $o = {}
Lang.install($o, '')
Vue.prototype.$o = $o
} else {
console.log('Lang installed')
}
},
mounted: function () {
this.html = this.content
this.initEditor()
Expand Down
21 changes: 8 additions & 13 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,23 @@
import Lang from 'src/lang'
import Vue from 'vue'

import install from 'src/install'
import QuasarTiptap from 'src/components/QuasarTiptap'

export const $o = {
config: {}
}
Vue.use({ install }, {})

const QuasarTiptapPlugin = {
installed: false,
spellcheck: true,

install (Vue, options = {}) {
$o.config = Object.freeze(options)

this.spellcheck = options.spellcheck == null
install (Vue, opts = {}) {
this.spellcheck = opts.spellcheck == null
? true
: options.spellcheck

// required plugins
Lang.install($o, options.language)
: opts.spellcheck
Vue.prototype.$o.lang.set(opts.language)

// quasar-tiptap
Vue.component('quasar-tiptap', QuasarTiptap)
Vue.prototype.$quasarTiptapPlugin = this
Vue.prototype.$o = $o

this.installed = true
},
Expand Down
14 changes: 14 additions & 0 deletions src/install.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import Lang from 'src/lang'

export const $o = {
config: {}
}

export default function (Vue, opts = {}) {
const cfg = $o.config = Object.freeze(opts.config || {})

// required plugins
Lang.install($o, opts.language)

Vue.prototype.$o = $o
}
9 changes: 7 additions & 2 deletions src/lang.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@ export default {
lang.set = this.set
lang.getLocale = this.getLocale

Vue.util.defineReactive($o, 'lang', lang)
if ($o !== undefined && $o.lang !== undefined) {
$o.lang = lang
} else {
Vue.util.defineReactive($o, 'lang', lang)
}

this.isoName = lang.isoName
this.nativeName = lang.nativeName
this.props = lang
console.log('install lang, $o', language, lang, $o)
}

this.set(language)
Expand All @@ -26,7 +32,6 @@ export default {
navigator.userLanguage ||
navigator.systemLanguage

console.log('lang', val)
if (val) {
return val.toLowerCase()
}
Expand Down
12 changes: 9 additions & 3 deletions src/pages/examples/all.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@
</template>

<script>
import { QuasarTiptap, OMenubarBtn } from 'src/index'
import Vue from 'vue'
import { QuasarTiptapPlugin, OMenubarBtn } from 'src/index'
Vue.use(QuasarTiptapPlugin, {
language: 'en-us',
spellcheck: true
})
import {
Placeholder,
} from 'tiptap-extensions'
Expand Down Expand Up @@ -87,13 +93,13 @@ export default {
}
},
components: {
QuasarTiptap,
OMenubarBtn,
},
methods: {
onSlideShow () {}
},
mounted: function () {
mounted () {
this.$o.lang.set('en-us')
},
deactivated () {
},
Expand Down
5 changes: 3 additions & 2 deletions src/pages/examples/basic.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</template>

<script>
import QuasarTiptap from 'src/components/QuasarTiptap'
import { QuasarTiptap } from 'src/index'
import {
Placeholder,
} from 'tiptap-extensions'
Expand Down Expand Up @@ -90,7 +90,8 @@ export default {
console.log('html', this.html)
}
},
mounted: function () {
mounted () {
this.$o.lang.set('zh-hans')
},
deactivated () {
},
Expand Down
2 changes: 1 addition & 1 deletion src/pages/examples/readonly.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
</template>

<script>
import QuasarTiptap from 'src/components/QuasarTiptap'
import { QuasarTiptap } from 'src/index'
import { BasicFeaturesArticle } from 'src/data/article'
import { RecommendedExtensions } from 'src/extentions'
Expand Down

0 comments on commit ab22477

Please sign in to comment.