PageSourceSearch

https://pika.page/assets/@tiptap--extension-link-c3cff4fc0f343d8d7…771e7ee86c42f11d4872478941a9465bc8652f76.js

js pika.page collected 2026-10-03 21:39:17 UTC 9,441 bytes, 4 lines download raw bytes

vendor: 1,205 bytes, lines 1-3
1// @tiptap/[email protected] downloaded from https://ga.jspm.io/npm:@tiptap/[email protected]/dist/index.js
2
3import{combineTransactionSteps as e,getChangedRanges as t,findChildrenInRange as n,getMarksBetween as r,getAttributes as i,markInputRule as a,InputRule as o,markPasteRule as s,PasteRule as c,Mark as l,mergeAttributes as u}from"@tiptap/core";import{tokenize as d,find as f,reset as p,registerCustomProtocol as m}from"linkifyjs";import{Plugin as h,PluginKey as g}from"@tiptap/pm/state";const _=`[\0- \xA0 ᠎ -\u2029  ]`,v=RegExp(_),y=RegExp(`${_}$`),b=RegExp(_,`g`);function x(e){return e.length===1?e[0].isLink:e.length===3&&e[1].isLink?[`()`,`[]`].includes(e[0].value+e[2].value):!1}function S(i){return new h({key:new g(`autolink`),appendTransaction:(a,o,s)=>{let c=a.some(e=>e.docChanged)&&!o.doc.eq(s.doc),l=a.some(e=>e.getMeta(`preventAutolink`));if(!c||l)return;let{tr:u}=s;if(t(e(o.doc,[...a])).forEach(({newRange:e})=>{let t=n(s.doc,e,e=>e.isTextblock),a,o;if(t.length>1)a=t[0],o=s.doc.textBetween(a.pos,a.pos+a.node.nodeSize,void 0,` `);else if(t.length){let n=s.doc.textBetween(e.from,e.to,` `,` `);if(!y.test(n))return;a=t[0],o=s.doc.textBetween(a.pos,e.to,void 0,` `)}
3if(a&&o){let e=o.split(v).filter(Boolean);if(e.length<=0)return!1;let t=e[e.length-1],n=a.pos+o.lastIndexOf(t);if(!t)return!1;let c=d(t).map(e=>e.toObject(i.defaultProtocol));if(!x(c))return!1;c.filter(e=>e.isLink).map(e=>({...e,from:n+e.start+1,to:n+e.end+1})).filter(e=>s.schema.marks.code?!s.doc.rangeHasMark(e.from,e.to,s.schema.marks.code):!0).filter(e=>i.validate(e.value)).filter(e=>i.shouldAutoLink(e.value)).forEach(e=>{r(e.from,e.to,s.doc).some(e=>e.mark.type===i.type)||u.addMark(e.from,e.to,i.type.create({href:e.href}))})}}),u.steps.length)return u}})}function C(e){return new h({key:new g(`handleClickLink`),props:{handleClick:(t,n,r)=>{if(r.button!==0||!t.editable)return!1;let a=null;if(r.target instanceof HTMLAnchorElement)a=r.target;else{let t=r.target;if(!t)return!1;let n=e.editor.view.dom;a=t.closest(`a`),a&&!n.contains(a)&&(a=null)}if(!a)return!1;let o=!1;if(e.enableClickSelection&&(o=e.editor.commands.extendMarkRange(e.type.name)),e.openOnClick){var s,c;let n=i(t.state,e.type.name),r=(s=a.href)==null?n.href:s,l=(c=a.target)==null?n.target:c;r&&(window.open(r,l),o=!0)}return o}}})}const w=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)$/,T=/\[([^[\]]+)\]\(((?:[^\s()]|\([^\s()]*\))+)(?:\s+(?:(["'])(.*?)\3|“(.*?)”|‘(.*?)’))?\)/g;function E(e,t){let n=0;for(let r=t-1;r>=0&&e[r]===`\\`;--r)n+=1;return n%2==1}function D(e,t){let n=0,r=0;for(;r<t;){if(e[r]!=="`"){r+=1;continue}if(n===0&&E(e,r)){r+=1;continue}let i=0;for(;r<t&&e[r]==="`";)i+=1,r+=1;n===0?n=i:i===n&&(n=0)}return n>0}function O(e,t,n){var r,i;let[,a,o]=t;return(t.index?e[t.index-1]:void 0)===`!`||E(e,(r=t.index)==null?0:r)||D(e,(i=t.index)==null?0:i)?!1:!!a.trim()&&n(o)}function k(e){var t,n;let[r,i,a,,o,s,c]=e,l=(t=o==null?s:o)==null?c:t;return{index:(n=e.index)==null?0:n,text:r,replaceWith:i,data:{href:a,title:l||null,markdown:!0}}}function A(e,t){return e.index<t.index+t.text.length&&t.index<e.index+e.text.length}function j(e){var t,n,r;return{href:(t=e.data)==null?void 0:t.href,title:(n=(r=e.data)==null?void 0:r.title)==null?null:n}}function M(e){let t=a({find:t=>{let n=w.exec(t);return!n||!O(t,n,e.isAllowedHref)?null:k(n)},type:e.type,getAttributes:j});return new o({find:t.find,handler:e=>{let n=t.handler(e);return n!==null&&e.state.tr.steps.length&&e.state.tr.setMeta(`preventAutolink`,!0),n}})}function N(e){let t=s({find:t=>{var n,r;let i=[];for(let n of t.matchAll(T))O(t,n,e.isAllowedHref)&&i.push(k(n));let a=((n=(r=e.findPlainUrls)==null?void 0:r.call(e,t))==null?[]:n).filter(e=>!i.some(t=>A(t,e)));return[...i,...a]},type:e.type,getAttributes:j});return new c({find:t.find,handler:e=>{var n;let r=t.handler(e);return r!==null&&e.state.tr.steps.length&&(n=e.match.data)!=null&&n.markdown&&e.state.tr.setMeta(`preventAutolink`,!0),r}})}function P(e){return new h({key:new g(`handlePasteLink`),props:{handlePaste:(t,n,r)=>{let{shouldAutoLink:i}=e,{state:a}=t,{selection:o}=a,{empty:s}=o;if(s)return!1;let c=``;r.content.forEach(e=>{c+=e.textContent});let l=f(c,{defaultProtocol:e.defaultProtocol}).find(e=>e.isLink&&e.value===c);return!c||!l||i!==void 0&&!i(l.value)?!1:e.editor.commands.setMark(e.type,{href:l.href})}}})}const F=/https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._+~#=]{1,256}\.[a-zA-Z]{2,}\b(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)(?:[-a-zA-Z0-9@:%._+~#=?!&/]*)/gi;function I(e,t){let n=[`http`,`https`,`ftp`,`ftps`,`mailto`,`tel`,`callto`,`sms`,`cid`,`xmpp`];return t&&t.forEach(e=>{let t=typeof e==`string`?e:e.scheme;t&&n.push(t)}),!e||e.replace(b,``).match(RegExp(`^(?:(?:${n.map(e=>e.replace(/[-/\\^$*+?.()|[\]{}]/g,`\\$&`)).join(`|`)}):|[^a-z]|[a-z0-9+.\\-]+(?:[^a-z+.\\-:]|$))`,`i`))}const L=l.create({name:`link`,priority:1e3,keepOnSplit:!1,exitable:!0,onCreate(){this.options.validate&&!this.options.shouldAutoLink&&(this.options.shouldAutoLink=this.options.validate,console.warn("The `validate` option is deprecated. Rename to the `shouldAutoLink` option instead.")),this.options.protocols.forEach(e=>{if(typeof e==`string`){m(e);return}m(e.scheme,e.optionalSlashes)})},onDestroy(){p()},inclusive(){return this.options.autolink},addOptions(){return{openOnClick:!0,enableClickSelection:!1,linkOnPaste:!0,markdownLinks:!1,autolink:!0,protocols:[],defaultProtocol:`http`,HTMLAttributes:{target:`_blank`,rel:`noopener noreferrer nofollow`,class:null},isAllowedUri:(e,t)=>
3!!I(e,t.protocols),validate:e=>!!e,shouldAutoLink:e=>{let t=/^[a-z][a-z0-9+.-]*:\/\//i.test(e),n=/^[a-z][a-z0-9+.-]*:/i.test(e);if(t||n&&!e.includes(`@`))return!0;let r=(e.includes(`@`)?e.split(`@`).pop():e).split(/[/?#:]/)[0];return!(/^\d{1,3}(\.\d{1,3}){3}$/.test(r)||!/\./.test(r))}}},addAttributes(){var e,t,n;return{href:{default:null,parseHTML(e){return e.getAttribute(`href`)}},target:{default:(e=this.options.HTMLAttributes.target)==null?null:e},rel:{default:(t=this.options.HTMLAttributes.rel)==null?null:t},class:{default:(n=this.options.HTMLAttributes.class)==null?null:n},title:{default:null}}},parseHTML(){return[{tag:`a[href]`,getAttrs:e=>{let t=e.getAttribute(`href`);return!t||!this.options.isAllowedUri(t,{defaultValidate:e=>!!I(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:null}}]},renderHTML({HTMLAttributes:e}){return this.options.isAllowedUri(e.href,{defaultValidate:e=>!!I(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?[`a`,u(this.options.HTMLAttributes,e),0]:[`a`,u(this.options.HTMLAttributes,{...e,href:``}),0]},markdownTokenName:`link`,parseMarkdown:(e,t)=>t.applyMark(`link`,t.parseInline(e.tokens||[]),{href:e.href,title:e.title||null}),renderMarkdown:(e,t)=>{var n,r,i,a;let o=(n=(r=e.attrs)==null?void 0:r.href)==null?``:n,s=(i=(a=e.attrs)==null?void 0:a.title)==null?``:i,c=t.renderChildren(e);return s?`[${c}](${o} "${s}")`:`[${c}](${o})`},addCommands(){return{setLink:e=>({chain:t})=>{let{href:n}=e;return this.options.isAllowedUri(n,{defaultValidate:e=>!!I(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?t().setMark(this.name,e).setMeta(`preventAutolink`,!0).run():!1},toggleLink:e=>({chain:t})=>{let{href:n}=e||{};return n&&!this.options.isAllowedUri(n,{defaultValidate:e=>!!I(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})?!1:t().toggleMark(this.name,e,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()},unsetLink:()=>({chain:e})=>e().unsetMark(this.name,{extendEmptyMarkRange:!0}).setMeta(`preventAutolink`,!0).run()}},addInputRules(){return this.options.markdownLinks?[M({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!I(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol})})]:[]},addPasteRules(){let e=e=>{let t=[];if(e){let{protocols:n,defaultProtocol:r}=this.options;f(e).filter(e=>e.isLink&&this.options.isAllowedUri(e.value,{defaultValidate:e=>!!I(e,n),protocols:n,defaultProtocol:r})).forEach(e=>{this.options.shouldAutoLink(e.value)&&t.push({text:e.value,data:{href:e.href},index:e.start})})}return t};return this.options.markdownLinks?[N({type:this.type,isAllowedHref:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!I(e,this.options.protocols),protocols:this.options.protocols,defaultProtocol:this.options.defaultProtocol}),findPlainUrls:e})]:[s({find:e,type:this.type,getAttributes:e=>{var t;return{href:(t=e.data)==null?void 0:t.href}}})]},addProseMirrorPlugins(){let e=[],{protocols:t,defaultProtocol:n}=this.options;return this.options.autolink&&e.push(S({type:this.type,defaultProtocol:this.options.defaultProtocol,validate:e=>this.options.isAllowedUri(e,{defaultValidate:e=>!!I(e,t),protocols:t,defaultProtocol:n}),shouldAutoLink:this.options.shouldAutoLink})),e.push(C({type:this.type,editor:this.editor,openOnClick:this.options.openOnClick===`whenNotEditable`?!0:this.options.openOnClick,enableClickSelection:this.options.enableClickSelection})),this.options.linkOnPaste&&e.push(P({editor:this.editor,defaultProtocol:this.options.defaultProtocol,type:this.type,shouldAutoLink:this.options.shouldAutoLink})),e}});var R=L;export{L as Link,R as default,I as isAllowedUri,F as pasteRegex};
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.