Importing Node Packages in Vue without Composition API? - vue.js

I've been trying for a while to learn how to use external Node Packages, but I keep getting frustrated.
I am currently trying to implement TinyMCE. I've installed the required packages and the example instructs me to do the following:
<script>
import Editor from '#tinymce/tinymce-vue'
export default {
name: 'app',
components: {
'editor': Editor
}
}
</script>
This is a pretty common pattern that I can never get to work, I'm guessing because I don't use the composition API. When I try to do something like this:
import Editor from '#tinymce/tinymce-vue'
const messageForm = workdesk.component('message-form', {
template: "#message-form",
delimiters: ["[[", "]]"],
props: ['project'],
components: {
'editor': Editor
},
data() {
return {
contacts: baseData.contacts,
proposed: {},
}
},
methods: {
}
})
it tells me Uncaught SyntaxError: Cannot use import statement outside a module
Does this mean that I need to learn Composition API to start using these external packages? Or am I doing something else wrong?

You do not need the Composition API in order to use TinyMCE. You can try something like this:
<template>
<Editor v-model="text" :init="editorConfig" />
</template>
<script>
// we must import TinyMCE locally, or tinymce-vue will try to load it from TinyCloud and complain about a missing API key
import 'tinymce/tinymce';
// Default icons are required for TinyMCE 5.3 or above
import 'tinymce/icons/default';
// A theme is also required
import 'tinymce/themes/silver';
// Any plugins you want to use has to be imported
import 'tinymce/plugins/advlist';
import 'tinymce/plugins/autolink';
import 'tinymce/plugins/lists';
import 'tinymce/plugins/link';
import 'tinymce/plugins/image';
import 'tinymce/plugins/charmap';
import 'tinymce/plugins/anchor';
import 'tinymce/plugins/searchreplace';
import 'tinymce/plugins/visualblocks';
import 'tinymce/plugins/code';
import 'tinymce/plugins/insertdatetime';
import 'tinymce/plugins/imagetools';
import 'tinymce/plugins/media';
import 'tinymce/plugins/table';
import 'tinymce/plugins/paste';
import 'tinymce/plugins/help';
import 'tinymce/plugins/wordcount';
import 'tinymce/plugins/spellchecker';
import 'tinymce/plugins/hr';
import 'tinymce/plugins/contextmenu';
import Editor from '#tinymce/tinymce-vue';
export default
{
name: 'RichEditor',
components:
{
Editor,
},
props:
{
value:
{
type: String,
default: ''
},
height:
{
type: [String, Number],
default: 400
}
},
data()
{
return {
text: this.value,
};
},
computed:
{
editorConfig()
{
return {
height: this.height,
content_css: process.env.BASE_URL + 'tinymce_skin/content/default/content.css',
skin_url: process.env.BASE_URL + 'tinymce_skin/ui/oxide',
menubar: 'file edit view insert format tools table tc help',
toolbar: 'undo redo | bold italic underline strikethrough | fontselect fontsizeselect formatselect | alignleft aligncenter alignright alignjustify | outdent indent | numlist bullist checklist | forecolor backcolor casechange formatpainter removeformat | pagebreak | charmap emoticons | insertfile image media pageembed template link anchor codesample',
quickbars_selection_toolbar: 'bold italic | quicklink h2 h3 blockquote quickimage quicktable',
toolbar_mode: 'sliding',
contextmenu: 'link image imagetools table',
plugins:
[
'advlist autolink lists link image charmap anchor',
'searchreplace visualblocks code imagetools hr',
'insertdatetime media table paste code help wordcount'
],
image_advtab: true,
};
},
},
watch:
{
text(newVal)
{
this.$emit('input', newVal);
}
}
};
</script>
and also in vue.config.js
module.exports =
{
chainWebpack: config =>
{
// TinyMCE - copy skins from node_modules/tinymce to the /public folder
config.plugins.has('copy') && config.plugin('copy')
.tap(([pathConfigs]) =>
{
//const to = pathConfigs[0].to;
pathConfigs[0].force = true; // so the original `/public` folder keeps priority
// add other locations.
pathConfigs.unshift({
context: './node_modules/tinymce/skins',
from: './**/*',
to: './tinymce_skin',
});
return [pathConfigs];
});
return config;
},
}

Related

How can i add google auto complete seach input in nuxt3?

I am working on a project in nuxt3 and I wanna add google places auto-complete on search input. I've been search for last 4 hours but can't got a way to set it up.
After long research I found the below solution working for me in the nuxt3 stable version.
Install the following version (0.9.72) of #fawmi/vue-google-maps
your package.json file:
"dependencies": {
"#fawmi/vue-google-maps": "0.9.72",
}
in nuxt.config.ts add following lines
build: {
transpile: ["#fawmi/vue-google-maps"],
},
Then create folder named plugins and make a file inside it named vueGoogleMaps.ts
📦plugins
┗ 📜vueGoogleMaps.ts
Your vueGoogleMaps.ts file:
import { defineNuxtPlugin } from "#app";
import VueGoogleMaps from "#fawmi/vue-google-maps";
export default defineNuxtPlugin((nuxtApp) => {
nuxtApp.vueApp.use(VueGoogleMaps, {
load: {
key: "Your-key",
libraries: "places", // This is required if you use the Autocomplete plugin
},
autobindAllEvents: true,
});
});
then in example.vue:
<template>
<GMapAutocomplete
placeholder="This is a placeholder"
#place_changed="setPlace"
>
</GMapAutocomplete>
</template>
<script>
export default {
name: 'App',
data() {
return {
}
},
methods: {
setPlace() {
}
}
}
</script>

Unknown custom element: <ckeditor> - did you register the component correctly?

I'm following the documentation for setting up a custom Vue ckeditor5 build in a Nuxt app. I created a custom build using the online builder (https://ckeditor.com/ckeditor-5/online-builder/), then downloaded it to my project.
Here is my CKEditorNuxt.vue file:
<template>
<div id="app">
<ckeditor :editor="editor" v-model="editorData" :config="editorConfig"></ckeditor>
</div>
</template>
<script>
import Editor from '../ckeditor5-custom-editor/build/ckeditor.js';
export default {
name: 'CkeditorNuxt',
data() {
return {
editor: Editor,
editorData: '<p>Default text</p>',
editorConfig: {
}
};
}
}
</script>
And inside where I'd like to place my template:
<CkeditorNuxt v-model="subsection.content"></CkeditorNuxt>
My custom build ckeditor.js file:
import ClassicEditor from '#ckeditor/ckeditor5-editor-classic/src/classiceditor.js';
import Autoformat from '#ckeditor/ckeditor5-autoformat/src/autoformat.js';
import Base64UploadAdapter from '#ckeditor/ckeditor5-upload/src/adapters/base64uploadadapter.js';
import BlockQuote from '#ckeditor/ckeditor5-block-quote/src/blockquote.js';
import Bold from '#ckeditor/ckeditor5-basic-styles/src/bold.js';
import CloudServices from '#ckeditor/ckeditor5-cloud-services/src/cloudservices.js';
import Essentials from '#ckeditor/ckeditor5-essentials/src/essentials.js';
import Heading from '#ckeditor/ckeditor5-heading/src/heading.js';
import Image from '#ckeditor/ckeditor5-image/src/image.js';
import ImageCaption from '#ckeditor/ckeditor5-image/src/imagecaption.js';
import ImageStyle from '#ckeditor/ckeditor5-image/src/imagestyle.js';
import ImageToolbar from '#ckeditor/ckeditor5-image/src/imagetoolbar.js';
import ImageUpload from '#ckeditor/ckeditor5-image/src/imageupload.js';
import Indent from '#ckeditor/ckeditor5-indent/src/indent.js';
import Italic from '#ckeditor/ckeditor5-basic-styles/src/italic.js';
import Link from '#ckeditor/ckeditor5-link/src/link.js';
import List from '#ckeditor/ckeditor5-list/src/list.js';
import MediaEmbed from '#ckeditor/ckeditor5-media-embed/src/mediaembed.js';
import Paragraph from '#ckeditor/ckeditor5-paragraph/src/paragraph.js';
import PasteFromOffice from '#ckeditor/ckeditor5-paste-from-office/src/pastefromoffice.js';
import Table from '#ckeditor/ckeditor5-table/src/table.js';
import TableToolbar from '#ckeditor/ckeditor5-table/src/tabletoolbar.js';
import TextTransformation from '#ckeditor/ckeditor5-typing/src/texttransformation.js';
class Editor extends ClassicEditor {}
Editor.builtinPlugins = [
Autoformat,
Base64UploadAdapter,
BlockQuote,
Bold,
CloudServices,
Essentials,
Heading,
Image,
ImageCaption,
ImageStyle,
ImageToolbar,
ImageUpload,
Indent,
Italic,
Link,
List,
MediaEmbed,
Paragraph,
PasteFromOffice,
Table,
TableToolbar,
TextTransformation
];
// Editor configuration.
Editor.defaultConfig = {
toolbar: {
items: [
'heading',
'|',
'bold',
'italic',
'link',
'bulletedList',
'numberedList',
'|',
'outdent',
'indent',
'|',
'imageUpload',
'blockQuote',
'insertTable',
'mediaEmbed',
'undo',
'redo'
]
},
language: 'en',
image: {
toolbar: [
'imageTextAlternative',
'imageStyle:inline',
'imageStyle:block',
'imageStyle:side'
]
},
table: {
contentToolbar: [
'tableColumn',
'tableRow',
'mergeTableCells'
]
}
};
export default Editor;
When I load the page, I get this error:
Why might this error be occurring? From other similar posts (Vue.js unknown custom element), I believe I should add an item to the components section, e.g.
components: {
ckeditor: Editor.component,
}
as this works when I use the default CKEditor, but not for my custom build. I think this is the source of my error, but I'm not sure what the correct format is. How should I go about fixing this error? Thanks!

Highmaps(HighCharts) loads same map when drilling down

I'm faced with a problem while implementing Highmaps.
In my vue project with Webpack, I followed each step explained https://github.com/highcharts/highcharts-vue to use Highmaps.
Here's my main.js file
//highchart
import HighchartsVue from 'highcharts-vue'
import Highcharts from 'highcharts'
import WorldMap from '#highcharts/map-collection/custom/world.geo.json'
import USMap from '#highcharts/map-collection/countries/us/us-all.geo.json'
import mapInit from 'highcharts/modules/map.js'
import DrillDown from 'highcharts/modules/drilldown.js'
mapInit(Highcharts);
DrillDown(Highcharts);
Highcharts.maps['world'] = WorldMap;
Highcharts.maps['us'] = USMap;
And, here's my vue file
<template>
<div>
<mymap :mapOptions="mapOptions.options"></mymap>
</div>
</template>
<script>
export default{
data(){
return {
mapOptions: {
options: {
chart: {
map: 'us',
events: {
drilldown: function(e){
var chart = this;
this.addSeriesAsDrilldown(e.point, {
data: 'world',
dataLabels: {
enabled: true,
format: '{point.name}'
}
})
},
drillup: function(){
}
}
},
series: [{
data: data,
joinBy: ['postal-code', 'code'],
dataLabels: {
enabled:true,
color: '#FFFFFF',
format: '{point.name}'
}
}],
}
}
}
},
}
</script>
Because the chart has 'chart': 'us' option, it renders US map first. Then, when I click any state (just for a test) it switches US map to world map.
It renders world map. However, it also render US map too. That is, it renders both two maps. How can I fix it??

HighCharts Vue JS - CSV key

I'm using csv-loader from webpack to load my CSV file and it loads fine on my Vue JS app.
The data.csv key is populated but the chart is not displayed.
App is being served locally.
<template>
<div id="app">
<img src="./assets/logo.png">
<highcharts :options="chartOptions"></highcharts>
</div>
</template>
<script>
import {Chart} from 'highcharts-vue'
import csvPath from './assets/test.csv'
import Papa from 'papaparse'
export default {
name: 'app',
components: {
highcharts: Chart
},
data () {
return {
chartOptions: {
chart: {
type: 'column'
},
data: {
csv: csvPath
},
title: {
text: 'Fruit Consumption'
},
yAxis: {
title: {
text: 'Units'
}
}
}
}
},
CSV File
Categories,Apples,Pears,Oranges,Bananas
John,8,4,6,5
I expect to see a fully plotted graph (barchart).
Try to import and initialize the data Highcharts module like that:
import Highcharts from "highcharts";
import dataModule from "highcharts/modules/data";
dataModule(Highcharts);

Integration CKFinder in CKEditor on Vue.js

I'm new to vue.js. Integrated CKEditor successfully but having trouble to integrate CKFinder in it. I'm trying to Import CKFinder in CKEditor component but I'm getting an error.
CKEditor-Vue Component:
<template>
<ckeditor :editor="editor" :value="defaultValue"
#input="editorInput" :disabled="disabled" :config="editorConfig"></ckeditor>
</template>
<script>
import DecoupledEditor from '#ckeditor/ckeditor5-build-decoupled-document';
import CKFinder from '#ckeditor/ckeditor5-ckfinder/src/ckfinder'
export default {
name: "Editor",
props: {
defaultValue: String,
disabled: Boolean
},
data() {
return {
editor: DecoupledEditor,
editorConfig: {
plugins: [
CKFinder
]
}
}
},
methods: {
editorInput(e) {
this.$emit('getEditorData', e);
}
}
}
</script>
<style scoped>
</style>
When I try to import CKFinder it's showing ckeditor-duplicated-modules: Some CKEditor 5 modules are duplicated.. Screenshot:
Am I doing anything wrong? Do you have any integration guide or correction on my component?
Thanks in advance for helping me.
You don't have to import
import CKFinder from '#ckeditor/ckeditor5-ckfinder/src/ckfinder'
because it is already included in the build of your choice. You only need to configure it and the error should disappear.
To make it clear like what oleq mean, just make a config under the editorConfig like this. You don't need to import it.
<script>
import DecoupledEditor from '#ckeditor/ckeditor5-build-decoupled-document';
import CKFinder from '#ckeditor/ckeditor5-ckfinder/src/ckfinder'
export default {
name: "Editor",
props: {
defaultValue: String,
disabled: Boolean
},
data() {
return {
editor: DecoupledEditor,
editorConfig: {
plugins: [
ckfinder: {
uploadUrl:
'/ckfinder/connector?command=QuickUpload&type=Files&responseType=json',
filebrowserBrowseUrl: '/ckfinder/browser',
filebrowserImageBrowseUrl: '/ckfinder/browser?type=Images',
filebrowserUploadUrl:'/ckfinder/connector?command=QuickUpload&type=Files',
filebrowserImageUploadUrl: '/ckfinder/connector?command=QuickUpload&type=Images'
}
]
}
}
},
methods: {
editorInput(e) {
this.$emit('getEditorData', e);
}
}
}
</script>