1// [email protected] downloaded from https://ga.jspm.io/npm:[email protected]/dist/index.mjs 2 3import e from"@tiptap/extension-ordered-list";import{Plugin as t,PluginKey as n,NodeSelection as r}from"@tiptap/pm/state";import{ReplaceStep as o}from"@tiptap/pm/transform";import{Extension as a,Node as s,mergeAttributes as i}from"@tiptap/core";import{Fragment as f,Slice as d}from"@tiptap/pm/model";import c from"@tiptap/extension-list-item";function u(e){let t=1;const n=[];e.doc.descendants(((r,o)=>{if(r.type.name=="footnoteReference"){e.setNodeAttribute(o,"referenceNumber",`${t}`);n.push(r);t+=1}}));return n}function l(e){let t;const n=[];e.doc.descendants(((e,r)=>{if(e.type.name=="footnote")n.push(e);else{if(e.type.name!="footnotes")return false;t={from:r,to:r+e.nodeSize}}}));return{footnotesRange:t,footnotes:n}}function m(e,t){const n=u(e);const r=t.schema.nodes.footnote;const o=t.schema.nodes.footnotes;const a=t.schema.nodeFromJSON({type:"paragraph",content:[]});const{footnotesRange:s,footnotes:i}=l(e);const d=i.reduce(((e,t)=>{e[t.attrs["data-id"]]=t;return e}),{});const c=[];let m=new Set(n.map((e=>e.attrs["data-id"])));const p=new Set;for(let e of i){const t=e.attrs["data-id"];if(!m.has(t)||p.has(t)){p.add(t);e.content.descendants((e=>{e.type.name=="footnoteReference"&&p.add(e.attrs["data-id"])}))}}for(let e=0;e<n.length;e++){let t=n[e].attrs["data-id"];if(!p.has(t))if(t in d){let n=d[t];c.push(r.create({...n.attrs,id:`fn:${e+1}`},n.content))}else{let n=r.create({"data-id":t,id:`fn:${e+1}`},[a]);c.push(n)}}c.length==0?s&&e.delete(s.from,s.to):s?e.replaceWith(s.from+1,s.to-1,f.from(c)):e.insert(e.doc.content.size,o.create(void 0,f.from(c)))}var p=a.create({name:"footnoteRules",priority:1e3,addProseMirrorPlugins(){return[new t({key:new n("footnoteRules"),filterTransaction(e){const{from:t,to:n}=e.selection;if(t===0&&n===e.doc.content.size)return true;let r=false;let o=false;let a=0;e.doc.nodesBetween(t,n,((e,t,n)=>{n?.type.name=="doc"&&e.type.name!="footnotes"?o=true:e.type.name=="footnote"?a+=1:e.type.name=="footnotes"&&(r=true)}));const s=o&&r;return!s&&a<=1},appendTransaction(e,t,n){let r=n.tr;let a=false;for(let t of e)if(t.docChanged){if(a)break;for(let e of t.steps){if(!(e instanceof o))continue;if(a)break;const n=e.from!=e.to;const r=e.slice.size>0;r&&e.slice.content.descendants((e=>{if(e?.type.name=="footnoteReference"){a=true;return false}}));n&&!a&&t.before.nodesBetween(e.from,Math.min(t.before.content.size,e.to),(e=>{if(e.type.name=="footnoteReference"){a=true;return false}}))}}if(a){m(r,n);return r}return null}})]}});var h=p;var y=e.extend({name:"footnotes",group:"",isolating:true,defining:true,draggable:false,content(){return"footnote*"},addAttributes(){return{class:{default:"footnotes"}}},parseHTML(){return[{tag:"ol.footnotes",priority:1e3}]},addKeyboardShortcuts(){return{}},addCommands(){return{}},addInputRules(){return[]},addExtensions(){return[h]}});var b=y;var g="data-reference-number";var T="footnote-ref";var R=s.create({name:"footnoteReference",inline:true,content:"text*",group:"inline",atom:true,draggable:true,parseHTML(){return[{tag:"sup",priority:1e3,getAttrs(e){const t=e.querySelector(`a.${T}:first-child`);if(!t)return false;const n=t.getAttribute("data-id");const r=t.getAttribute(g);return{"data-id":n??crypto.randomUUID(),referenceNumber:r??t.innerText}},contentElement(e){return e.firstChild}}]},addAttributes(){return{class:{default:T},"data-id":{renderHTML(e){return{"data-id":e["data-id"]||crypto.randomUUID()}}},referenceNumber:{},href:{renderHTML(e){return{href:`#fn:${e.referenceNumber}`}}}}},renderHTML({HTMLAttributes:e}){const{referenceNumber:t,...n}=e;const r=i(this.options.HTMLAttributes,n);r[g]=t;return["sup",{id:`fnref:${t}`},["a",r,e.referenceNumber]]},addProseMirrorPlugins(){const{editor:e}=this;const o=e=>{if(e.type.name===this.name){const t={...e.attrs,"data-id":crypto.randomUUID()};return e.type.create(t,e.content,e.marks)}if(e.content&&e.content.size>0){const t=[];let n=false;e.content.forEach((e=>{const r=o(e);r!==e&&(n=true);t.push(r)}));if(n)return e.copy(f.from(t))}return e};return[new t({key:new n("footnotePasteHandler"),props:{transformPasted(e){const t=[];let n=false;e.content.forEach((e=>{const r=o(e);r!==e&&(n=true);t.push(r)}));return n?new d(f.from(t),e.openStart,e.openEnd):e}}}),new t({key:new n("footnoteRefClick"),props:{handleDoubleClickOn(t,n,r,o,a){if(r.type.name!="footnoteReference")return false;a.preventDefault();const s=r.attrs["data-id"];return e.commands.focusFootnote(s)}
3,handleClickOn(t,n,o,a,s){if(o.type.name!="footnoteReference")return false;s.preventDefault();const{selection:i}=e.state.tr;if(i instanceof r&&i.node.eq(o)){const t=o.attrs["data-id"];return e.commands.focusFootnote(t)}e.chain().setNodeSelection(a).run();return true}}})]},addCommands(){return{addFootnote:()=>({state:e,tr:t})=>{const n=this.type.create({"data-id":crypto.randomUUID()});t.insert(e.selection.anchor,n);return true}}},addInputRules(){return[{find:/\[\^(.*?)\]/,type:this.type,undoable:true,handler({range:e,match:t,chain:n}){const r=e.from;let o=e.to;t[1]&&n().deleteRange({from:r,to:o}).addFootnote().run()}}]}});var N=R;var L=c.extend({name:"footnote",content(){return this.options.content},isolating:true,defining:true,draggable:false,addOptions(){return{HTMLAttributes:{},bulletListTypeName:"bulletList",orderedListTypeName:"orderedList",...this.parent?.(),content:"paragraph+"}},addAttributes(){return{id:{isRequired:true},"data-id":{isRequired:true}}},parseHTML(){return[{tag:"li",getAttrs(e){const t=e.getAttribute("data-id");return!!t&&{"data-id":e.getAttribute("data-id")}},priority:1e3}]},renderHTML({HTMLAttributes:e}){return["li",i(this.options.HTMLAttributes,e),0]},addCommands(){return{focusFootnote:e=>({editor:t,chain:n})=>{const r=t.$node("footnote",{"data-id":e});if(r){n().focus().setTextSelection(r.from+r.content.size).run();r.element.scrollIntoView();return true}return false}}},addKeyboardShortcuts(){return{"Mod-a":({editor:e})=>{try{const{selection:t}=e.state;const{$from:n}=t;for(let t=n.depth;t>=0;t--){const r=n.node(t);if(r.type.name==="footnote"){const r=n.start(t);const o=n.end(t);e.commands.setTextSelection({from:r+1,to:o-1});return true}}return false}catch(e){return false}},Tab:({editor:e})=>{try{const{selection:t}=e.state;const n=e.$pos(t.anchor);if(!n.after)return false;if(n.after.node.type.name=="footnotes"){const t=n.after.node.child(0);e.chain().setTextSelection(n.after.from+t.content.size).scrollIntoView().run();return true}{const n=t.$from.start(2);if(Number.isNaN(n))return false;const r=e.$pos(n);if(r.node.type.name!="footnote"||!r.after)return false;e.chain().setTextSelection(r.after.to-1).scrollIntoView().run();return true}}catch{return false}},"Shift-Tab":({editor:e})=>{const{selection:t}=e.state;const n=t.$from.start(2);if(Number.isNaN(n))return false;const r=e.$pos(n);if(r.node.type.name!="footnote"||!r.before)return false;e.chain().setTextSelection(r.before.to-1).scrollIntoView().run();return true}}}});var M=L;export{M as Footnote,N as FootnoteReference,b as Footnotes}; 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.