1// @tiptap/[email protected] downloaded from https://ga.jspm.io/npm:@tiptap/[email protected]/dist/index.js 2 3import{findParentNode as e,findChildren as t,Node as n,isActive as r,defaultBlockAt as i,mergeAttributes as a,createBlockMarkdownSpec as o}from"@tiptap/core";import{Plugin as s,TextSelection as c,PluginKey as l,Selection as u}from"@tiptap/pm/state";import{GapCursor as d}from"@tiptap/pm/gapcursor";const f=(e,t)=>{let n=t.view.domAtPos(e).node,r=n.nodeType===Node.ELEMENT_NODE?n:n.parentElement;return r?r.offsetParent!==null:!1},p=(e,t,n)=>{for(let r=e.depth;r>0;--r){let i=e.node(r),a=t(i),o=f(e.start(r),n);if(a&&o)return{pos:r>0?e.before(r):0,start:e.start(r),depth:r,node:i}}},m=(n,r)=>{let{state:i,view:a,extensionManager:o}=n,{schema:s,selection:c}=i,{empty:l,$anchor:u}=c,p=!!o.extensions.find(e=>e.name===`gapCursor`);if(!l||u.parent.type!==s.nodes.detailsSummary||!p||r===`right`&&u.parentOffset!==u.parent.nodeSize-2)return!1;let m=e(e=>e.type===s.nodes.details)(c);if(!m)return!1;let h=t(m.node,e=>e.type===s.nodes.detailsContent);if(!h.length||f(m.start+h[0].pos+1,n))return!1;let g=i.doc.resolve(m.pos+m.node.nodeSize),_=d.findFrom(g,1,!1);if(!_)return!1;let{tr:v}=i,y=new d(_);return v.setSelection(y),v.scrollIntoView(),a.dispatch(v),!0},h=n.create({name:`details`,content:`detailsSummary detailsContent`,group:`block`,defining:!0,isolating:!0,allowGapCursor:!1,addOptions(){return{persist:!1,openClassName:`is-open`,HTMLAttributes:{},renderToggleButton:({element:e,isOpen:t})=>{e.setAttribute(`aria-label`,t?`Collapse details content`:`Expand details content`)}}},addAttributes(){return this.options.persist?{open:{default:!1,parseHTML:e=>e.hasAttribute(`open`),renderHTML:({open:e})=>e?{open:``}:{}}}:[]},parseHTML(){return[{tag:`details`}]},renderHTML({HTMLAttributes:e}){return[`details`,a(this.options.HTMLAttributes,e),0]},...o({nodeName:`details`,content:`block`}),addNodeView(){return({editor:e,getPos:t,node:n,HTMLAttributes:r})=>{let i=document.createElement(`div`),o=a(this.options.HTMLAttributes,r,{"data-type":this.name});Object.entries(o).forEach(([e,t])=>i.setAttribute(e,t));let s=document.createElement(`button`);s.type=`button`;let c=e=>{this.options.renderToggleButton({element:s,...e})};i.append(s);let l=document.createElement(`div`);i.append(l);let u=e=>{let{setToValue:t,node:r=n}=e||{};if(t!==void 0)if(t){if(i.classList.contains(this.options.openClassName))return;i.classList.add(this.options.openClassName)}else{if(!i.classList.contains(this.options.openClassName))return;i.classList.remove(this.options.openClassName)}else i.classList.toggle(this.options.openClassName);c({isOpen:i.classList.contains(this.options.openClassName),node:r});let a=new Event(`toggleDetailsContent`),o=l.querySelector(`:scope > div[data-type="detailsContent"]`);o==null||o.dispatchEvent(a)};return c({isOpen:!!n.attrs.open,node:n}),n.attrs.open&&setTimeout(()=>u()),s.addEventListener(`click`,()=>{if(u(),!this.options.persist){e.commands.focus(void 0,{scrollIntoView:!1});return}if(e.isEditable&&typeof t==`function`){let{from:n,to:r}=e.state.selection;e.chain().command(({tr:e})=>{let n=t();if(typeof n!=`number`)return!1;let r=e.doc.nodeAt(n);return(r==null?void 0:r.type)===this.type?(e.setNodeMarkup(n,void 0,{open:!r.attrs.open}),!0):!1}).setTextSelection({from:n,to:r}).focus(void 0,{scrollIntoView:!1}).run()}}),{dom:i,contentDOM:l,ignoreMutation(e){if(e.type===`selection`)return!1;let t=e.target,n=i.contains(t);return s.contains(t)||!n||i===t},update:e=>e.type===this.type?(e.attrs.open===void 0?c({isOpen:i.classList.contains(this.options.openClassName),node:e}):u({setToValue:e.attrs.open,node:e}),!0):!1}}},addCommands(){return{setDetails:()=>({state:e,chain:t})=>{var n;let{schema:r,selection:i}=e,{$from:a,$to:o}=i,s=a.blockRange(o);if(!s)return!1;let c=e.doc.slice(s.start,s.end);if(!r.nodes.detailsContent.contentMatch.matchFragment(c.content))return!1;let l=((n=c.toJSON())==null?void 0:n.content)||[];return t().insertContentAt({from:s.start,to:s.end},{type:this.name,content:[{type:`detailsSummary`},{type:`detailsContent`,content:l}]}).setTextSelection(s.start+2).run()},unsetDetails:()=>({state:n,chain:r})=>{let{selection:i,schema:a}=n,o=e(e=>e.type===this.type)(i);if(!o)return!1;let s=t(o.node,e=>e.type===a.nodes.detailsSummary),c=t(o.node,e=>e.type===a.nodes.detailsContent);if(!s.length||!c.length)return!1;let l=s[0],u=c[0],d=o.pos,f=n.doc.resolve(d),p={from:d,to:d+o.node.nodeSize},m=u.node.content.toJSON()||[],h=f.parent.type.contentMatch.defaultType,g=[h==null?void 0:h.create(null,l.node.content).toJSON(),...m];return r().insertContentAt(p,g).setTextSelection(d+1).run()}}},addKeyboardShortcuts(){return{Backspace:()=>{let{schema:e,selection:t}=this.editor.state,{empty:n,$anchor:r}=t;return!n||r.parent.type!==e.nodes.detailsSummary?!1:r.parentOffset===0?this.editor.commands.unsetDetails():this.editor.commands.command(({tr:e})=>{let t=r.pos-1,n=r.pos;return e.delete(t,n),!0})},Enter:({editor:e})=>{let{state:t,view:n}=e,{schema:r,selection:a}=t,{$head:o}=a;if(o.parent.type!==r.nodes.detailsSummary)return!1;let s=f(o.after()+1,e),c=s?t.doc.nodeAt(o.after()):o.node(-2);if(!c)return!1;let l=s?0:o.indexAfter(-1),d=i(c.contentMatchAt(l));if(!d||!c.canReplaceWith(l,l,d))return!1;let p=d.createAndFill();if(!p)return!1;let m=s?o.after()+1:o.after(-1),h=t.tr.replaceWith(m,m,p),g=h.doc.resolve(m),_=u.near(g,1);return h.setSelection(_),h.scrollIntoView(),n.dispatch(h),!0},ArrowRight:({editor:e})=>m(e,`right`),ArrowDown:({editor:e})=>m(e,`down`)}},addProseMirrorPlugins(){return[new s({key:new l(`detailsSelection`),appendTransaction:(e,n,i)=>{let{editor:a,type:o}=this;if(a.view.composing||!e.some(e=>e.selectionSet)||!n.selection.empty||!i.selection.empty||!r(i,o.name))return;let{$from:s}=i.selection;if(f(s.pos,a))return;let l=p(s,e=>e.type===o,a);if(!l)return;let u=t(l.node,e=>e.type===i.schema.nodes.detailsSummary);if(!u.length)return;let d=u[0],m=(n.selection.from<i.selection.from?`forward`:`backward`)==`forward`?l.start+d.pos:l.pos+d.pos+d.node.nodeSize,h=c.create(i.doc,m);return i.tr.setSelection(h)}})]}}),g=n.create({name:`detailsContent`,content:`block+`,defining:!0,selectable:!1,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`div[data-type="${this.name}"]`}]},renderHTML({HTMLAttributes:e}){return[`div`,a(this.options.HTMLAttributes,e,{"data-type":this.name}),0]},addNodeView(){return({HTMLAttributes:e})=>{let t=document.createElement(`div`),n=a(this.options.HTMLAttributes,e,{"data-type":this.name,hidden:`hidden`});
3return Object.entries(n).forEach(([e,n])=>t.setAttribute(e,n)),t.addEventListener(`toggleDetailsContent`,()=>{t.toggleAttribute(`hidden`)}),{dom:t,contentDOM:t,ignoreMutation(e){return e.type===`selection`?!1:!t.contains(e.target)||t===e.target},update:e=>e.type===this.type}}},addKeyboardShortcuts(){return{Enter:({editor:t})=>{let{state:n,view:r}=t,{selection:a}=n,{$from:o,empty:s}=a,c=e(e=>e.type===this.type)(a);if(!s||!c||!c.node.childCount)return!1;let l=o.index(c.depth),{childCount:d}=c.node;if(d!==l+1)return!1;let f=c.node.type.contentMatch.defaultType,p=f==null?void 0:f.createAndFill();if(!p)return!1;let m=n.doc.resolve(c.pos+1),h=d-1,g=c.node.child(h),_=m.posAtIndex(h,c.depth);if(!g.eq(p))return!1;let v=o.node(-3);if(!v)return!1;let y=o.indexAfter(-3),b=i(v.contentMatchAt(y));if(!b||!v.canReplaceWith(y,y,b))return!1;let x=b.createAndFill();if(!x)return!1;let{tr:S}=n,C=o.after(-2);S.replaceWith(C,C,x);let w=S.doc.resolve(C),T=u.near(w,1);S.setSelection(T);let E=_,D=_+g.nodeSize;return S.delete(E,D),S.scrollIntoView(),r.dispatch(S),!0}}},...o({nodeName:`detailsContent`})}),_=n.create({name:`detailsSummary`,content:`text*`,defining:!0,selectable:!1,isolating:!0,addOptions(){return{HTMLAttributes:{}}},parseHTML(){return[{tag:`summary`}]},renderHTML({HTMLAttributes:e}){return[`summary`,a(this.options.HTMLAttributes,e),0]},...o({nodeName:`detailsSummary`,content:`inline`})});var v=h;export{h as Details,g as DetailsContent,_ as DetailsSummary,v as default}; 4
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.