This version uses Rollup instead of WebPack.

Due to that the code is smaller and has changes to prevent Circular Dependencies
This commit is contained in:
djmaze 2021-01-25 22:00:13 +01:00
parent 5e63ade9dd
commit ad8fd8879b
49 changed files with 595 additions and 577 deletions

View file

@ -1,5 +1,23 @@
import { createCKEditor } from 'External/CKEditor.js';
const
htmlre = /[&<>"']/g,
htmlmap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;'
};
/**
* @param {string} text
* @returns {string}
*/
export function encodeHtml(text) {
return (text && text.toString ? text.toString() : ''+text).replace(htmlre, m => htmlmap[m]);
}
class HtmlEditor {
editor;
blurTimer = 0;

View file

@ -1,3 +1,5 @@
import * as Knoin from 'Knoin/Knoin';
const USER_VIEW_MODELS_HOOKS = [],
ADMIN_VIEW_MODELS_HOOKS = [];
@ -45,9 +47,8 @@ export function addSettingsViewModelForAdmin(SettingsViewModelClass, template, l
* @param {boolean} admin
*/
export function runSettingsViewModelHooks(admin) {
const Knoin = require('Knoin/Knoin');
(admin ? ADMIN_VIEW_MODELS_HOOKS : USER_VIEW_MODELS_HOOKS).forEach(view => {
Knoin.addSettingsViewModel(view[0], view[1], view[2], view[3]);
Knoin.settingsAddViewModel(view[0], view[1], view[2], view[3]);
});
}

View file

@ -160,3 +160,17 @@ export function reload(admin, language) {
doc.head.append(script);
});
}
/**
*
* @param {string} language
* @param {boolean=} isEng = false
* @returns {string}
*/
export function convertLangName(language, isEng = false) {
return i18n(
'LANGS_NAMES' + (true === isEng ? '_EN' : '') + '/LANG_' + language.toUpperCase().replace(/[^a-zA-Z0-9]+/g, '_'),
null,
language
);
}

View file

@ -49,20 +49,6 @@ export const convertThemeName = theme => {
.trim();
};
/**
*
* @param {string} language
* @param {boolean=} isEng = false
* @returns {string}
*/
export function convertLangName(language, isEng = false) {
return require('Common/Translator').i18n(
'LANGS_NAMES' + (true === isEng ? '_EN' : '') + '/LANG_' + language.toUpperCase().replace(/[^a-zA-Z0-9]+/g, '_'),
null,
language
);
}
/**
* @param {object} domOption
* @param {object} item

View file

@ -1,16 +1,11 @@
import { ComposeType, FolderType } from 'Common/EnumsUser';
import { EmailModel } from 'Model/Email';
import { showScreenPopup } from 'Knoin/Knoin';
import { encodeHtml } from 'Common/Html';
const
tpl = document.createElement('template'),
isArray = Array.isArray,
htmlmap = {
'&': '&amp;',
'<': '&lt;',
'>': '&gt;',
'"': '&quot;',
"'": '&#x27;'
},
htmlspecialchars = str => (''+str).replace(/[&<>"']/g, m => htmlmap[m]);
isArray = Array.isArray;
/**
* @param {(string|number)} value
@ -21,14 +16,6 @@ export function isPosNumeric(value, includeZero = true) {
return null != value && (includeZero ? /^[0-9]*$/ : /^[1-9]+[0-9]*$/).test(value.toString());
}
/**
* @param {string} text
* @returns {string}
*/
export function encodeHtml(text) {
return null != text ? htmlspecialchars(text.toString()) : '';
}
/**
* @param {string} text
* @param {number=} len = 100
@ -101,7 +88,7 @@ export function htmlToPlain(html) {
.replace(/[\n]/gm, '<br />')
.replace(/[\r]/gm, '')
: '',
fixAttibuteValue = (...args) => (args && 1 < args.length ? '' + args[1] + htmlspecialchars(args[2]) : ''),
fixAttibuteValue = (...args) => (args && 1 < args.length ? '' + args[1] + encodeHtml(args[2]) : ''),
convertLinks = (...args) => (args && 1 < args.length ? args[1].trim() : '');
tpl.innerHTML = html
@ -470,8 +457,7 @@ export function mailToHelper(mailToUrl, PopupComposeViewModel) {
params = {};
const email = mailToUrl.replace(/\?.+$/, ''),
query = mailToUrl.replace(/^[^?]*\?/, ''),
EmailModel = require('Model/Email').default;
query = mailToUrl.replace(/^[^?]*\?/, '');
query.split('&').forEach(temp => {
temp = temp.split('=');
@ -506,7 +492,7 @@ export function mailToHelper(mailToUrl, PopupComposeViewModel) {
bcc = EmailModel.parseEmailLine(decodeURIComponent(params.bcc));
}
require('Knoin/Knoin').showScreenPopup(PopupComposeViewModel, [
showScreenPopup(PopupComposeViewModel, [
ComposeType.Empty,
null,
to,