-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(core): поддрежка вывода редактора без свойств битрикса
- Loading branch information
Showing
9 changed files
with
575 additions
and
1,068 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
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,34 +1,8 @@ | ||
import Vue from 'vue'; | ||
import ElementUI from 'element-ui'; | ||
import VueYoutube from 'vue-youtube' | ||
import 'element-ui/lib/theme-chalk/index.css'; | ||
import hello from './hello.vue'; | ||
import baseField from "./baseField"; | ||
import locale from 'element-ui/lib/locale/lang/ru-RU' | ||
import BlockEditor from './blockEditor.ts'; | ||
|
||
Vue.use(ElementUI, { locale }); | ||
Vue.mixin(baseField); | ||
Vue.use(VueYoutube); | ||
|
||
document.gtdEditor = ($value, input_name, app_id, allowBlocks = [], propId=0) => { | ||
let value = JSON.parse($value) || []; | ||
let block = allowBlocks.length > 0 ? JSON.parse(allowBlocks) : [] | ||
new Vue({ | ||
data(){ | ||
return { | ||
val: value, | ||
inputName: input_name, | ||
allowBlocks: block | ||
} | ||
}, | ||
render: (h) => h(hello), | ||
mounted() { | ||
let appTr = document.getElementById('tr_PROPERTY_'+propId); | ||
if(appTr){ | ||
appTr.childNodes[3].colSpan = "2"; | ||
appTr.childNodes[3].width = "100%"; | ||
appTr.childNodes[1].remove(); | ||
} | ||
} | ||
}).$mount('#' + app_id) // Если должен быть найден один элемент | ||
} | ||
// backward compatibility | ||
var blockEditor = BlockEditor; | ||
document.gtdEditor = BlockEditor; | ||
|
||
export default blockEditor; |
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 |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import Vue from 'vue'; | ||
import ElementUI from 'element-ui'; | ||
// @ts-ignore | ||
import VueYoutube from 'vue-youtube' | ||
import 'element-ui/lib/theme-chalk/index.css'; | ||
// @ts-ignore | ||
import hello from './hello.vue'; | ||
import baseField from "./baseField"; | ||
// @ts-ignore | ||
import locale from 'element-ui/lib/locale/lang/ru-RU' | ||
|
||
Vue.use(ElementUI, { locale }); | ||
Vue.mixin(baseField); | ||
Vue.use(VueYoutube); | ||
|
||
|
||
|
||
export default class BlockEditor{ | ||
|
||
private _inputName:String = ""; | ||
private _value:Array<any> = []; | ||
private _allowBlock:Array<string> = []; | ||
private _appId: string = ""; | ||
private _onValueChange:valueChangeCallback; | ||
private _onRendered:any; | ||
|
||
constructor(value: string, inputName: string = "", allowBlock: string = "", appId: string = "") { | ||
this.setValue(value); | ||
this.setAllowBlocks(allowBlock); | ||
this._appId = appId.length > 0 ? appId : this.makeId(10); | ||
this._inputName = inputName !== "" ? inputName : this.makeId(10); | ||
} | ||
|
||
initEditor(){ | ||
document.addEventListener('DOMContentLoaded', () => { // Аналог $(document).ready(function(){ | ||
new Vue({ | ||
data:() => { | ||
return { | ||
val: this._value, | ||
inputName: this._inputName, | ||
allowBlocks: this._allowBlock, | ||
callback: this._onValueChange | ||
} | ||
}, | ||
render: (h) => h(hello), | ||
mounted: () => { | ||
if(typeof this._onRendered === 'function'){ | ||
this._onRendered(); | ||
} | ||
} | ||
}).$mount('#' + this._appId) | ||
}); | ||
} | ||
|
||
|
||
setValue(value:string) { | ||
this._value = JSON.parse(value) || []; | ||
} | ||
|
||
setAllowBlocks(value:string){ | ||
this._allowBlock = value.length > 0 ? JSON.parse(value) : [] | ||
} | ||
|
||
setInputName(inputName:string) { | ||
this._inputName = inputName; | ||
} | ||
|
||
onValueChange(callBack:valueChangeCallback) { | ||
if(typeof callBack === "function"){ | ||
this._onValueChange = callBack; | ||
} | ||
} | ||
|
||
onRendered(callBack:any) { | ||
if(typeof callBack === 'function'){ | ||
this._onRendered = callBack; | ||
} | ||
} | ||
|
||
makeId(length:number = 10) :string | ||
{ | ||
let result = ''; | ||
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'; | ||
const charactersLength = characters.length; | ||
for ( var i = 0; i < length; i++ ) { | ||
result += characters.charAt(Math.floor(Math.random() * | ||
charactersLength)); | ||
} | ||
return result; | ||
} | ||
} | ||
|
||
type valueChangeCallback = (value: any) => void |
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"compilerOptions": { | ||
"outDir": "./dist/", | ||
"noImplicitAny": true, | ||
"module": "es6", | ||
"target": "es5", | ||
"jsx": "react", | ||
"allowJs": true, | ||
"moduleResolution": "node" | ||
} | ||
} |
Oops, something went wrong.