Added bidi button to Squire editor

This commit is contained in:
Mohammad rezaei 2023-07-01 17:31:07 +03:30 committed by GitHub
parent 47e3fc90f2
commit b2b07ab920
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 46 additions and 11 deletions

View file

@ -110,17 +110,29 @@ class SquireUI
select: ['11px','13px','16px','20px','24px','30px'], select: ['11px','13px','16px','20px','24px','30px'],
cmd: s => squire.setStyle({ fontSize: s.value }) cmd: s => squire.setStyle({ fontSize: s.value })
}, },
// dir: {
// select: [
// [i18n('EDITOR/DIR_LTR', 'LTR'),'ltr'],
// [i18n('EDITOR/DIR_RTL', 'RTL'),'rtl'],
// [i18n('EDITOR/DIR_AUTO', 'Auto'),'auto'],
// ['',''],
// ],
// cmd: s => {
// squire.setAttribute('dir', s.value || null);
// // squire.setStyle({ 'unicode-bidi': 'plaintext' });
// }
// }
},
dir: { dir: {
select: [ ltr: {
[i18n('EDITOR/DIR_LTR', 'LTR'),'ltr'], html: '⁋',
[i18n('EDITOR/DIR_RTL', 'RTL'),'rtl'], cmd: () => squire.bidi('ltr'),
[i18n('EDITOR/DIR_AUTO', 'Auto'),'auto'], hint: 'ltr direction'
['',''], },
], rtl: {
cmd: s => { html: '¶',
squire.setAttribute('dir', s.value || null); cmd: () => squire.bidi('rtl'),
// squire.setStyle({ 'unicode-bidi': 'plaintext' }); hint: 'rtl direction'
}
} }
}, },
colors: { colors: {
@ -278,6 +290,7 @@ class SquireUI
plain.className = 'squire-plain'; plain.className = 'squire-plain';
wysiwyg.className = 'squire-wysiwyg'; wysiwyg.className = 'squire-wysiwyg';
wysiwyg.dir = 'auto';
this.mode = ''; // 'plain' | 'wysiwyg' this.mode = ''; // 'plain' | 'wysiwyg'
this.__plain = { this.__plain = {
getRawData: () => this.plain.value, getRawData: () => this.plain.value,

View file

@ -1766,6 +1766,22 @@ const
return frag; return frag;
}, },
setDirection = (self, frag, dir) => {
let walker = getBlockWalker(frag, self._root),
node;
while(node = walker.nextNode()){
if (node.nodeName === "LI") {
node.parentNode.setAttribute("dir", dir);
break;
}
node.setAttribute("dir", dir);
}
return frag;
},
linkRegExp = /\b(?:((https?:\/\/)?(?:www\d{0,3}\.|[a-z0-9][a-z0-9.-]*\.[a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:[^\s?&`!()[\]{};:'".,<>«»“”‘’]|\([^\s()<>]+\)))|([\w\-.%+]+@(?:[\w-]+\.)+[a-z]{2,}\b(?:\?[^&?\s]+=[^\s?&`!()[\]{};:'".,<>«»“”‘’]+(?:&[^&?\s]+=[^\s?&`!()[\]{};:'".,<>«»“”‘’]+)*)?))/i, linkRegExp = /\b(?:((https?:\/\/)?(?:www\d{0,3}\.|[a-z0-9][a-z0-9.-]*\.[a-z]{2,}\/)(?:[^\s()<>]+|\([^\s()<>]+\))+(?:[^\s?&`!()[\]{};:'".,<>«»“”‘’]|\([^\s()<>]+\)))|([\w\-.%+]+@(?:[\w-]+\.)+[a-z]{2,}\b(?:\?[^&?\s]+=[^\s?&`!()[\]{};:'".,<>«»“”‘’]+(?:&[^&?\s]+=[^\s?&`!()[\]{};:'".,<>«»“”‘’]+)*)?))/i,
addLinks = (frag, root) => { addLinks = (frag, root) => {
@ -3663,6 +3679,12 @@ class Squire
return this.focus(); return this.focus();
} }
bidi(dir) {
this.modifyBlocks(frag => setDirection(this, frag, dir));
return this.focus();
}
makeUnorderedList() { makeUnorderedList() {
this.modifyBlocks(frag => makeList(this, frag, 'UL')); this.modifyBlocks(frag => makeList(this, frag, 'UL'));
return this.focus(); return this.focus();