Your IP : 216.73.217.13


Current Path : /var/www/surf/TYPO3/vendor/typo3/cms-rte-ckeditor/Resources/Public/JavaScript/plugin/
Upload File :
Current File : /var/www/surf/TYPO3/vendor/typo3/cms-rte-ckeditor/Resources/Public/JavaScript/plugin/whitespace.js

/*
 * This file is part of the TYPO3 CMS project.
 *
 * It is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License, either version 2
 * of the License, or any later version.
 *
 * For the full copyright and license information, please read the
 * LICENSE.txt file that was distributed with this source code.
 *
 * The TYPO3 project - inspiring people to share!
 */
import*as Core from"@ckeditor/ckeditor5-core";import*as UI from"@ckeditor/ckeditor5-ui";import*as Utils from"@ckeditor/ckeditor5-utils";import*as Typing from"@ckeditor/ckeditor5-typing";export class Whitespace extends Core.Plugin{init(){const t=this.editor,e=t.commands.get("insertText"),i=Utils.env.isMac?"Alt":"Ctrl";t.ui.componentFactory.add("softhyphen",(t=>{const o=new UI.ButtonView(t);return o.label="Soft-Hyphen",o.icon='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 20 20" xml:space="preserve"><path d="M4.25 3C3.082 4.683 2 6.917 2 10.026 2 13.083 3.114 15.282 4.25 17H3c-1.008-1.425-2-3.624-2-6.974.016-3.384.992-5.583 2-7.026h1.25zM17 3c1.008 1.443 1.984 3.642 2 7.026 0 3.35-.992 5.549-2 6.974h-1.25c1.136-1.718 2.25-3.917 2.25-6.974 0-3.11-1.082-5.343-2.25-7.026H17zM6 9h8v2H6z"/></svg>',o.keystroke=`${i}+Shift+-`,o.tooltip=!0,o.bind("isEnabled").to(e),o.on("execute",(()=>this.insertSoftHyphen())),o})),t.keystrokes.set([i,"Shift",189],((t,e)=>{this.insertSoftHyphen(),e()})),t.keystrokes.set([i,"Shift","Space"],((t,e)=>{this.insertNonBreakingSpace(),e()})),t.conversion.for("editingDowncast").add((t=>{t.on("insert:$text",((t,e,i)=>{if(!i.consumable.consume(e.item,t.name))return;const o=i.writer,s=e.item.data.split(/([\u00AD\u00A0])/).filter((t=>""!==t));let n=e.range.start;s.forEach((t=>{const e="­"===t?"-":t;if(o.insert(i.mapper.toViewPosition(n),o.createText(e)),"­"===t||" "===t){const e="­"===t?"softhyphen":"nbsp",s=Math.random().toString(16).slice(2),r=o.createAttributeElement("span",{class:`ck ck-${e}`},{id:s}),c=o.createRange(i.mapper.toViewPosition(n),i.mapper.toViewPosition(n.getShiftedBy(t.length)));o.wrap(c,r)}n=n.getShiftedBy(t.length)}))}),{priority:"high"})}))}insertNonBreakingSpace(){const t=this.editor;t.execute("insertText",{text:" "}),t.editing.view.focus()}insertSoftHyphen(){const t=this.editor;t.execute("insertText",{text:"­"}),t.editing.view.focus()}}Whitespace.pluginName="Whitespace",Whitespace.requires=[Typing.Typing];export default Whitespace;