Vue and TinyMCE Issue - vue.js

I am trying to integrate a TinyMCE editor into my Vue application. From the Developer Tools Console I am able to access the tinymce object and manipulate it. For example:
tinymce.activeEditor.selection.setContent('I am a replacement')
The above code will replace the selected text within the TinyMCE editor. I want to work with the tinymce object from within Vue (in multiple components) but I am not sure how to access it. The exact error I get when I enter the above code into a function is: error 'tinymce' is not defined no-undef.
Any help would be much appreciated. Thank you.

Without seeing any code at all it is hard to say exactly why this is happening. Documenting how you are instantiating TinyMCE would help.
Based on the error message I would assume that you are using the TinyMCE Vue component/wrapper to inject TinyMCE into your Vue component. By default that does not actually load the core TinyMCE editor until run-time - and at that time it loads thing via the TinyMCE Cloud server.
The error you are seeing is your linting tool (eslint?) complaining that you are trying to call a variable tinymce but that variable is not defined anywhere.
There are a few ways you could choose to "fix" eslint complaining:
1 - Access tinymce through the global window object:
window.tinymce
2 - Wrap your code with a directive for eslint to not check for undefined variables:
/*eslint-disable no-undef*/
...
/*eslint-enable no-undef*/
https://eslint.org/docs/user-guide/configuring#disabling-rules-with-inline-comments
3 - Define a global in your .eslintrc file
{
"globals": {
"tinymce": true
}
}
https://eslint.org/docs/user-guide/configuring#specifying-globals

Related

VsCode Intellisense does not work for "this" keyword in Vue Script

VsCode doesn't recognise "this" keyword in methods (or anywhere in script tag) in my vue file.
Therefore it doesn't help when I hover or click a variable that starts with "this" keyword. On the other hand in template tag there isn't any problem with variables and functions.
You can see in the screenshots, like this;
IntelliSense for "this" keyword in script
IntelliSense in template
I am using VsCode for frontend development with Vue 2. I have Volar extensions, typescript setups. I don't know what exactly this problem is about. Can you help me solve it?

CSS-less vue component fails when copied from vue2/vuetify project to vue2/tailwind

I have written a very simple, learning "hello world" type component, in the vue 2/typescript 4 project at:
https://github.com/sldev2/vr-vtsv-timeline
This project was made with vue ui. I've added #vue/composition-api 1.0.3 and vuetify 2.4.0
The component is called CompositionApiEg.vue. It doesn't use any explicit vuetify styles. When you browse to http://localhost:8080/, It displays 3 names, and allows you to increase "capacity" by clicking the button with text "Increase Capacity". (The button border does not show. I know not why; I assume I need a vuetify button style) There are no runtime errors in the browser.
The CompositionApiEg.vue file is here.
I've tried transplanting this component into another vue2/typescript 4 project also made with vue ui, with the composition-api added, but that has tailwind instead of vuetify. The component was not modified in any way. In particular, no tailwind styles were added.
This project is at: https://github.com/sldev2/v23tstw
Now, however, this component is throwing a bunch of runtime errors, such as:
warning eg:
vue.runtime.esm.js?d04a:619 [Vue warn]: Property or method "spacesLeft" is not defined on the instance but referenced during render. Make sure that this property is reactive, either in the data option, or for class-based components, by initializing the property. See: https://v2.vuejs.org/v2/guide/reactivity.html#Declaring-Reactive-Properties.
error eg:
vue.runtime.esm.js?d04a:1897 TypeError: _vm.increaseCapacity is not a function
at click (CompositionApiEg.vue?c6d9:27)
at invokeWithErrorHandling (vue.runtime.esm.js?d04a:1863)
at HTMLButtonElement.invoker (vue.runtime.esm.js?d04a:2188)
at HTMLButtonElement.original._wrapper (vue.runtime.esm.js?d04a:6961)
Why does the exact same, very simple component succeed in one vue2 project, but not in another?

Is it possible to use ag-grid with vue without a builder?

In particular, can the typescript source of the ag-grid-vue component be compiled then included in a regular html file?
I found a way to do this without modifying the source. Near the top of ag-grid-vue.umd.js, you can see that the module does this:
root["ag-grid-vue"] = factory(root["Vue"], root["agGrid"]);
Here, "root" is the window, and the result of the factory call is what you'll want. But due to the dashes, you can't access it directly. But you can use the dictionary syntax (or whatever it's called):
let agVueObj = window["ag-grid-vue"];
//The component is a field on this object:
let AgGridVue = agVueObj.AgGridVue;
//Then register it as a component in your Vue instance:
//components: { AgGridVue }
And you should be able to use <ag-grid-vue> tags.
I figured it out:
Download the ag-grid source code, go into the packages/ag-grid-vue directory and do npm install and npm run build. That will put compiled javascript modules in the dist directory that can be used without a build system.
I did have to modify the built javascript slightly to get the AgGridVue object into the global namespace, since I'm not using a module loader.
EDIT:
To get the AgGridVue into the global namespace, add window.AgGridVue = AgGridVue; to the end of the function that returns AgGridVue in ag-grid-vue.umd.js

source.vue doesn't work in my vue snippet in sublime text3?

I have a very annoying problem with my sublime snippet about .vue type flie.
Say I want to add a vue snippet in sublime on my own, and I want the vue tabtrigger below works in vue type file only.
I add these codes into my vue.sublime-snippet:
<snippet>
<content><![CDATA[
Some text
]]></content>
<tabTrigger>vue</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.vue</scope>
</snippet>
After saving this file in my sublime folder, I create a test.vue file and type vue and then press Tab.
But nothing happened. What I expected is Some text could appear after tabbing in test.vue file.
Why doesn't my snippet work on vue file?
PS: I changed source.vue into source.js source.php,etc in my snippet and tested in corresponding js, php file, they all work fine. Only vue didn't work out. Is there anything wrong with sublime identifying vue type file? How to solve this problem?
The correct scope selector to use for Vue.js is text.html.vue, which can be seen by creating a new, empty tab in ST, setting the syntax to Vue.js and then going to the Tools menu -> Developer -> Show Scope Name or by checking the syntax definition: https://github.com/vuejs/vue-syntax-highlight/blob/f87459fc1bf26a4b8e50e232757d4682892c971d/vue.tmLanguage#L1465-L1466
I recently faced the same issue and I used source.js as the scope selector.
<snippet>
<content><![CDATA[
your snippet here
]]></content>
<tabTrigger>vue</tabTrigger>
<!-- Optional: Set a scope to limit where the snippet will trigger -->
<scope>source.js</scope>
</snippet>

Rangy injection module issue

I'm trying to inject the rangy javascript core and serializer code base (https://code.google.com/p/rangy/) into an html page. However when I inject it, the rangy object isn't created properly. The modules are added at rangy.modules.* however the functions created within the module are not added to the rangy object. Also the modules all have the following variables 'initialized' and 'supported' as false. Has anyone been able to inject the Rangy code base into their web page properly or can provide any assistance?
To inject - open up Chrome javascript console and insert code as minified (very important or it will not work - http://jscompress.com/):
javascript: insert code here
You can call rangy.init() to initialize Rangy after the page has loaded.