daisy-tiptap-test 0.0.13 → 0.0.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1 +1 @@
|
|
|
1
|
-
import{Node as
|
|
1
|
+
import{Node as i,mergeAttributes as s,nodeInputRule as a}from"@tiptap/core";import{VueNodeViewRenderer as u}from"@tiptap/vue-3";import{DEFAULT_IMAGE_URL_REGEX as d,DEFAULT_IMAGE_DISPLAY as m,IMAGE_DISPLAY_PRESETS as r}from"../utils";import{InsertImageDropdown as c,ImageView as f}from"../components";const p=/(?:^|\s)(!\[(.+|:?)]\((\S+)(?:(?:\s+)["'](\S+)["'])?\))$/,h=i.create({name:"image-block",addOptions(){return{allowBase64:!1,HTMLAttributes:{},urlPattern:d,btn({editor:e,i18n:t}){return{component:c,componentProps:{editor:e,tooltip:t("editor.extensions.Image.buttons.insert_image.tooltip"),isActive:e.isActive("block-image"),isDisabled:!1}}}}},inline:!1,group:"block",draggable:!0,addAttributes(){return{src:{default:null,parseHTML:e=>e.children[0].src||""},alt:{default:null},title:{default:null},width:{default:null,parseHTML:e=>{const t=e.style.width||e.getAttribute("width")||null;return t==null?null:parseInt(t,10)},renderHTML:e=>({width:e.width})},display:{default:m,parseHTML:e=>{const t=e.className;return t.indexOf("float-left")!==-1?r.FLOAT_LEFT:t.indexOf("float-right")!==-1?r.FLOAT_RIGHT:t.indexOf("mr-auto")!==-1?r.BLOCK_LEFT:t.indexOf("ml-auto")!==-1?r.BLOCK_RIGHT:r.BLOCK_CENTER},renderHTML:e=>{if(e.display===r.FLOAT_LEFT)return{class:"my-3 block float-left ml-0"};if(e.display===r.FLOAT_RIGHT)return{class:"my-3 block float-right mr-0"};if(e.display===r.BLOCK_LEFT)return{class:"my-3 block ml-0 mr-auto"};if(e.display===r.BLOCK_RIGHT)return{class:"my-3 block ml-auto mr-0"};if(e.display===r.BLOCK_CENTER)return{class:"my-3 block mx-auto"}}}}},parseHTML(){return[{tag:'figure[data-image="block"]'}]},renderHTML({HTMLAttributes:e}){const t={...e};return t.src=null,t.width&&(t.style=`width: ${t.width}px`,t.width=null),e.class=null,["figure",s({class:"align-baseline relative","data-image":"block"},t),["img",s(this.options.HTMLAttributes,e)]]},addCommands(){return{setBlockImage:e=>({state:t,view:l,chain:n})=>{if(l.endOfTextblock("left")){const o=t.selection.from;return n().insertContentAt(o,{type:this.name,attrs:e}).setNodeSelection(o+1).run()}else{const o=t.selection.from;return n().insertContent({type:this.name,attrs:e}).setNodeSelection(o+1).run()}},toggleBlockImage:e=>({state:t,chain:l})=>{if(t.selection.$anchor.parent.childCount===1){const n=t.selection.from;return l().deleteNode("paragraph").insertContentAt(n-1,{type:this.name,attrs:e}).setNodeSelection(n-1).run()}else return l().setBlockImage(e).run()}}},addInputRules(){return[a({find:p,type:this.type,getAttributes:e=>{const[,,t,l,n]=e;return{src:l,alt:t,title:n}}})]},addNodeView(){return u(f)}});export{h as ImageBlock,p as inputRegex};
|