TYPO3 v15 dev-main snapshot ()
This commit is contained in:
commit
1e393722e8
183 files changed
+7832
No files matched your search
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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 d from"@ckeditor/ckeditor5-ui";import*as h from"@ckeditor/ckeditor5-core";import*as U from"@ckeditor/ckeditor5-engine";import*as f from"@ckeditor/ckeditor5-typing";import*as y from"@ckeditor/ckeditor5-widget";import*as v from"@ckeditor/ckeditor5-utils";import*as b from"@ckeditor/ckeditor5-link";import{LinkUtils as k}from"@ckeditor/ckeditor5-link";import p from"@typo3/backend/modal.js";import{IconLink as I,IconUnlink as R,IconPencil as V}from"@ckeditor/ckeditor5-icons";const C=["href","title","class","target","rel","download"];function x(c){return"link"+(c.charAt(0).toUpperCase()+c.slice(1))}function A(c){return c.startsWith("link")&&c.length>=5?c.charAt(4).toLowerCase()+c.slice(5):c}class E extends h.Command{constructor(){super(...arguments),this.attrs={}}refresh(){const e=this.editor.model,n=e.document.selection,t=n.getSelectedElement()||v.first(n.getSelectedBlocks()),o=k.isLinkableElement(t,e.schema)?t:n;o===t?(this.value=t.getAttribute("linkHref"),this.isEnabled=e.schema.checkAttribute(t,"linkHref")):(this.value=n.getAttribute("linkHref"),this.isEnabled=e.schema.checkAttributeInSelection(n,"linkHref"));const s=this.editor.plugins.get("GeneralHtmlSupport").getGhsAttributeNameForElement("a"),l={};for(const a of this.getLinkAttributesAllowedOnText(e.schema))if(a!=="linkHref")if(a===s){const r=o.getAttribute(a);r?.classes&&r.classes.length!==0&&(l.class=r.classes.join(" "))}else{const r=o.getAttribute(a);r!==void 0&&(l[A(a)]=r)}this.attrs=l}execute(e,n={}){const t=this.editor.model,o=t.document.selection;t.change(i=>{if(o.isCollapsed){const s=o.getFirstPosition();if(o.hasAttribute("linkHref")){const l=f.findAttributeRange(s,"linkHref",o.getAttribute("linkHref"),t);i.setAttribute("linkHref",e,l);for(const[a,r]of Object.entries(this.composeLinkAttributes(n)))r!==null?i.setAttribute(a,r,l):i.removeAttribute(a,l);i.setSelection(i.createPositionAfter(l.end.nodeBefore))}else if(e!==""){const l=v.toMap(o.getAttributes());l.set("linkHref",e);for(const[r,m]of Object.entries(this.composeLinkAttributes(n)))m!==null&&l.set(r,m);const{end:a}=t.insertContent(i.createText(e,l),s);i.setSelection(a)}this.removeLinkAttributesFromSelection(i,this.getLinkAttributesAllowedOnText(t.schema))}else{const s=t.schema.getValidRanges(o.getRanges(),"linkHref"),l=[];for(const r of o.getSelectedBlocks())t.schema.checkAttribute(r,"linkHref")&&l.push(i.createRangeOn(r));const a=l.slice();for(const r of s)this.isRangeToUpdate(r,l)&&a.push(r);for(const r of a){i.setAttribute("linkHref",e,r);for(const[m,g]of Object.entries(this.composeLinkAttributes(n)))g!==null?i.setAttribute(m,g,r):i.removeAttribute(m,r)}}})}getLinkAttributesAllowedOnText(e){return e.getDefinition("$text").allowAttributes.filter(t=>t.startsWith("link")||t==="htmlA")}removeLinkAttributesFromSelection(e,n){e.removeSelectionAttribute("linkHref");for(const t of n)e.removeSelectionAttribute(t)}composeLinkAttributes(e){const n={};for(const[t,o]of Object.entries(e.attrs))if(t==="linkClass"){const s=this.editor.plugins.get("GeneralHtmlSupport").getGhsAttributeNameForElement("a"),l=this.editor.model.document.selection;let a;l.hasAttribute(s)?a={...l.getAttribute(s)}:a={};const r=o.replace(/\s+/g," ").trim();r!==""?a.classes=r.split(" "):"classes"in a&&delete a.classes,n[s]=Object.keys(a).length!==0?a:null}else n[t]=o!==""?o:null;return n}isRangeToUpdate(e,n){for(const t of n)if(t.containsRange(e))return!1;return!0}}class w extends h.Command{refresh(){const e=this.editor.model,n=e.document.selection,t=n.getSelectedElement();k.isLinkableElement(t,e.schema)?this.isEnabled=e.schema.checkAttribute(t,"linkHref"):this.isEnabled=e.schema.checkAttributeInSelection(n,"linkHref")}execute(){const e=this.editor.model,n=e.document.selection;e.change(t=>{const o=n.isCollapsed?[f.findAttributeRange(n.getFirstPosition(),"linkHref",n.getAttribute("linkHref"),e)]:e.schema.getValidRanges(n.getRanges(),"linkHref");for(const i of o)t.removeAttribute("linkHref",i),t.removeAttribute("linkTarget",i),t.removeAttribute("linkTitle",i),t.removeAttribute("linkRel",i),t.removeAttribute("linkDownload",i),t.removeAttribute("linkDataRteError",i)})}}class T extends h.Plugin{static{this.pluginName="Typo3LinkEditing"}init(){const e=this.editor;window.editor=e,e.model.schema.extend("$text",{allowAttributes:["linkTitle","linkTarget","linkRel","linkDownload","linkDataRteError"]}),e.plugins.get("DataFilter").loadAllowedConfig([{name:"a",classes:!0}]),e.conversion.for("downcast").attributeToElement({model:"linkDataRteError",view:(t,{writer:o})=>{const i=o.createAttributeElement("a",{"data-rte-error":t},{priority:5});return o.setCustomProperty("linkDataRteError",!0,i),i}}),e.conversion.for("upcast").elementToAttribute({view:{name:"a",attributes:{"data-rte-error":!0}},model:{key:"linkDataRteError",value:t=>t.getAttribute("data-rte-error")}}),e.conversion.for("downcast").attributeToElement({model:"linkTitle",view:(t,{writer:o})=>{const i=o.createAttributeElement("a",{title:t},{priority:5});return o.setCustomProperty("Line truncated
|
||||
@@ -0,0 +1,13 @@
|
||||
/*
|
||||
* 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 w from"@ckeditor/ckeditor5-core";import*as x from"@ckeditor/ckeditor5-ui";import*as y from"@ckeditor/ckeditor5-utils";import*as S from"@ckeditor/ckeditor5-typing";class p extends w.Plugin{static{this.pluginName="Whitespace"}static{this.requires=[S.Typing]}init(){const e=this.editor,h=e.commands.get("insertText"),a=y.env.isMac?"Alt":"Ctrl";e.ui.componentFactory.add("softhyphen",s=>{const t=new x.ButtonView(s);return t.label="Soft-Hyphen",t.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>',t.keystroke=`${a}+Shift+-`,t.tooltip=!0,t.bind("isEnabled").to(h),t.on("execute",()=>this.insertSoftHyphen()),t}),e.keystrokes.set([a,"Shift",189],(s,t)=>{this.insertSoftHyphen(),t()}),e.keystrokes.set([a,"Shift","Space"],(s,t)=>{this.insertNonBreakingSpace(),t()}),e.conversion.for("editingDowncast").add(s=>{s.on("insert:$text",(t,c,o)=>{if(!o.consumable.consume(c.item,t.name))return;const n=o.writer,m=c.item.data.split(/([\u00AD\u00A0])/).filter(i=>i!=="");let r=c.range.start;m.forEach(i=>{const d=i==="\xAD"?"-":i;if(n.insert(o.mapper.toViewPosition(r),n.createText(d)),i==="\xAD"||i==="\xA0"){const l=i==="\xAD"?"softhyphen":"nbsp",f=Math.random().toString(16).slice(2),g=n.createAttributeElement("span",{class:`ck ck-${l}`},{id:f}),u=n.createRange(o.mapper.toViewPosition(r),o.mapper.toViewPosition(r.getShiftedBy(i.length)));n.wrap(u,g)}r=r.getShiftedBy(i.length)})},{priority:"high"})})}insertNonBreakingSpace(){const e=this.editor;e.execute("insertText",{text:"\xA0"}),e.editing.view.focus()}insertSoftHyphen(){const e=this.editor;e.execute("insertText",{text:"\xAD"}),e.editing.view.focus()}}export{p as Whitespace,p as default};
|
||||
Reference in new issue
Block a user