PageSourceSearch

https://pika.page/assets/@tiptap--suggestion-4b69cdea97e553e4d1a2f…a6334f5a8b0257ab235d469f44d3114a79890180.js

js pika.page collected 2026-10-03 21:42:09 UTC 9,693 bytes, 5 lines download raw bytes

1// @tiptap/[email protected] downloaded from https://ga.jspm.io/npm:@tiptap/[email protected]/dist/index.js
2
3import{PluginKey as e,Plugin as t}from"@tiptap/pm/state";import{escapeForRegEx as n}from"@tiptap/core";import{DecorationSet as r,Decoration as i}from"@tiptap/pm/view";import{offset as a,flip as o,computePosition as s,autoUpdate as c}from"@floating-ui/dom";function l(e){var t;let{char:r,allowSpaces:i,allowToIncludeChar:a,allowedPrefixes:o,startOfLine:s,$position:c}=e,l=i&&!a,u=n(r),d=RegExp(`\\s${u}$`),f=s?`^`:``,p=a?``:u,m=RegExp(l?`${f}${u}.*?(?=\\s${p}|$)`:`${f}(?:^)?${u}[^\\s${p}]*`,`gm`),h=((t=c.nodeBefore)==null?void 0:t.isText)&&c.nodeBefore.text;if(!h)return null;let g=c.pos-h.length,_=Array.from(h.matchAll(m)).pop();if(!_||_.input===void 0||_.index===void 0)return null;let v=_.input.slice(Math.max(0,_.index-1),_.index),y=RegExp(`^[${o==null?void 0:o.join(``)}\0]?$`).test(v);if(o!==null&&!y)return null;let b=g+_.index,x=b+_[0].length;return l&&d.test(h.slice(x-1,x+1))&&(_[0]+=` `,x+=1),b<c.pos&&x>=c.pos?{range:{from:b,to:x},query:_[0].slice(r.length),text:_[0]}:null}function u(e){return e.docChanged?e.steps.some(e=>{let t=e.slice;if(!(t!=null&&t.content))return!1;let n=t.content.textBetween(0,t.content.size,`
4`);return/\s/.test(n)}):!1}function d(e){return()=>{let t=e.state.selection.$anchor.pos,{top:n,right:r,bottom:i,left:a}=e.view.coordsAtPos(t);try{return new DOMRect(a,n,r-a,i-n)}catch{return null}}}function f(e,t,n,r){return n?()=>{let n=r.getState(e.state),i=n==null?void 0:n.decorationId,a=t.dom.querySelector(`[data-decoration-id="${i}"]`);return(a==null?void 0:a.getBoundingClientRect())||null}:d(e)}function p({match:e,dismissedRange:t,state:n,transaction:r,editor:i,shouldResetDismissed:a,effectiveAllowSpaces:o}){return a!=null&&a({editor:i,state:n,range:t,match:e,transaction:r,allowSpaces:o})?!1:o?e.range.from===t.from:e.range.from===t.from&&!u(r)}function m({view:e,pluginKeyRef:t}){let n=e.state.tr.setMeta(t,{exit:!0});e.dispatch(n)}function h({pluginKey:e,decorationTag:t,decorationClass:n,decorationContent:a,decorationEmptyClass:o,renderer:s,dispatchExit:c}){return{handleKeyDown(t,n){var r;let i=e.getState(t.state);if(!i.active)return!1;if(n.key===`Escape`||n.key===`Esc`){var a;return s==null||(a=s.onKeyDown)==null||a.call(s,{view:t,event:n,range:i.range}),c(t),!0}return(s==null||(r=s.onKeyDown)==null?void 0:r.call(s,{view:t,event:n,range:i.range}))||!1},decorations(s){let{active:c,range:l,decorationId:u,query:d}=e.getState(s);if(!c)return null;let f=!(d!=null&&d.length),p=[n];return f&&p.push(o),r.create(s.doc,[i.inline(l.from,l.to,{nodeName:t,class:p.join(` `),"data-decoration-id":u||void 0,"data-decoration-content":a})])}}}function g({editor:e,char:t,effectiveAllowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,findSuggestionMatch:o,allow:s,shouldShow:c,shouldKeepDismissed:l,pluginKey:u}){return{init(){return{active:!1,range:{from:0,to:0},query:null,text:null,composing:!1,dismissedRange:null}},apply(d,f,p,m){let{isEditable:h}=e,{composing:g}=e.view,{selection:_}=d,{empty:v,from:y}=_,b={...f},x=d.getMeta(u);if(x&&x.exit)return b.active=!1,b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null,b.dismissedRange=f.active?{...f.range}:f.dismissedRange,b;if(b.composing=g,d.docChanged&&b.dismissedRange!==null&&(b.dismissedRange={from:d.mapping.map(b.dismissedRange.from),to:d.mapping.map(b.dismissedRange.to)}),h&&(v||e.view.composing)){(y<f.range.from||y>f.range.to)&&!g&&!f.composing&&(b.active=!1);let u=o({char:t,allowSpaces:n,allowToIncludeChar:r,allowedPrefixes:i,startOfLine:a,$position:_.$from}),p=`id_${Math.floor(Math.random()*4294967295)}`;u&&s({editor:e,state:m,range:u.range,isActive:f.active})&&(!c||c({editor:e,range:u.range,query:u.query,text:u.text,transaction:d}))?(b.dismissedRange!==null&&!l({match:u,dismissedRange:b.dismissedRange,state:m,transaction:d})&&(b.dismissedRange=null),b.dismissedRange===null?(b.active=!0,b.decorationId=f.decorationId||p,b.range=u.range,b.query=u.query,b.text=u.text):b.active=!1):(u||(b.dismissedRange=null),b.active=!1)}else b.active=!1;return b.active||(b.decorationId=null,b.range={from:0,to:0},b.query=null,b.text=null),b}}
4}function _({editor:e,items:t}){let n=null,r=null,i=null,a=()=>{r!==null&&(clearTimeout(r),r=null),i==null||i(),i=null},o=e=>new Promise(t=>{i=t,r=setTimeout(()=>{r=null;let e=i;i=null,e==null||e()},e)}),s=()=>{n==null||n.abort(),a(),n=null},c=async(r,i)=>{s(),n=new AbortController;let a=n;if(i>0&&await o(i),n!==a||a.signal.aborted)return{status:`aborted`};try{let i=await t({editor:e,query:r,signal:a.signal});return n!==a||a.signal.aborted?{status:`aborted`}:{status:`resolved`,items:i}}catch{return n!==a||a.signal.aborted?{status:`aborted`}:{status:`error`}}};return{abort:s,fetch:c}}function v({placement:e,offset:t,flip:n,floatingUi:r}){var i,s,c,l;let u=[a({mainAxis:(i=t.mainAxis)==null?4:i,crossAxis:(s=t.crossAxis)==null?0:s})];return n&&u.push(o()),!(r==null||(c=r.middleware)==null)&&c.length&&u.push(...r.middleware),{placement:e,strategy:(l=r==null?void 0:r.strategy)==null?`absolute`:l,middleware:u}}function y(e){if(e instanceof HTMLElement)return e;if(typeof e==`string`)try{let t=document.querySelector(e);if(t)return t}catch{return document.body}return document.body}function b({getReferenceRect:e,contextElement:t,config:n,container:r,dismissOnOutsideClick:i,dismiss:a}){return(o,l={})=>{let u={getBoundingClientRect:()=>{var t;return(t=e())==null?new DOMRect:t},contextElement:t},d=!1,f=!o.isConnected;f&&y(r).appendChild(o),l.onPosition||(o.style.visibility=`hidden`,o.style.width=`max-content`);let p=()=>{s(u,o,{placement:n.placement,strategy:n.strategy,middleware:n.middleware}).then(({x:e,y:t,placement:n,strategy:r})=>{if(l.onPosition){l.onPosition({x:e,y:t,placement:n,strategy:r});return}Object.assign(o.style,{position:r,left:`${e}px`,top:`${t}px`}),d||(d=!0,o.style.visibility=``)})},m=c(u,o,p,l.autoUpdate),h;return i&&(h=e=>{let n=e.target;!(n instanceof Node)||o.contains(n)||t.contains(n)||a()},document.addEventListener(`pointerdown`,h,!0)),()=>{m(),h&&document.removeEventListener(`pointerdown`,h,!0),f&&o.remove()}}}function x({editor:e,pluginKey:t,items:n,renderer:r,minQueryLength:i,debounce:a,initialItems:o,placement:s,offset:c,container:l,flip:u,floatingUi:d,dismissOnOutsideClick:f,command:p,clientRectFor:m,dispatchExit:h}){let g,y=_({editor:e,items:n}),x=v({placement:s,offset:c,flip:u,floatingUi:d});function S(e,t){switch(e){case`started`:var n;r==null||(n=r.onStart)==null||n.call(r,t);break;case`updated`:var i;r==null||(i=r.onUpdate)==null||i.call(r,t);break;case`stopped`:var a;r==null||(a=r.onExit)==null||a.call(r,t)}}return{update:async(n,d)=>{var _,v;let C=t.getState(d),w=t.getState(n.state);if(!C||!w)return;let T=null,E=C.query!==w.query,D=C.text!==w.text,O=C.range.from!==w.range.from||C.range.to!==w.range.to,k=E||D||O;if(!C.active&&w.active)T=`started`;else if(C.active&&!w.active)T=`stopped`;else if(w.active&&k)T=`updated`;else return;let A=T===`stopped`?C:w,j=n.dom.querySelector(`[data-decoration-id="${A.decorationId}"]`),M=m(n,j),N=i===0||(A.query?A.query.length>=i:!1),P=(T===`started`||T===`updated`)&&N;if(g={editor:e,range:A.range,query:A.query||``,text:A.text||``,items:o==null?[]:o,command:t=>p({editor:e,range:A.range,props:t}),decorationNode:j,clientRect:M,loading:P,placement:s,offset:{mainAxis:(_=c.mainAxis)==null?4:_,crossAxis:(v=c.crossAxis)==null?0:v},container:l,flip:u,floatingUi:x,mount:b({getReferenceRect:M,contextElement:n.dom,config:x,container:l,dismissOnOutsideClick:f,dismiss:()=>h(e.view)})},T===`started`){var F;r==null||(F=r.onBeforeStart)==null||F.call(r,g)}if(T===`updated`){var I;r==null||(I=r.onBeforeUpdate)==null||I.call(r,g)}if(T===`started`&&S(T,g),T===`started`||T===`updated`)if(!P)y.abort(),g={...g,items:o==null?[]:o,loading:!1};else{g={...g,items:o==null?[]:o,loading:!0},T=`updated`,S(T,g);let e=await y.fetch(A.query||``,a);if(e.status===`aborted`)return;let r=t.getState(n.state);if(!(r!=null&&r.active)){y.abort();return}g=e.status===`resolved`?{...g,items:e.items,loading:!1}:{...g,loading:!1}}
4if(T===`stopped`){y.abort(),S(T,g),g=void 0;return}T===`updated`&&S(T,g)},destroy:()=>{var e;y.abort(),g&&(r==null||(e=r.onExit)==null||e.call(r,g))}}}const S=new e(`suggestion`);function C({pluginKey:e=S,editor:n,char:r=`@`,allowSpaces:i=!1,allowToIncludeChar:a=!1,allowedPrefixes:o=[` `],startOfLine:s=!1,decorationTag:c=`span`,decorationClass:u=`suggestion`,decorationContent:d=``,decorationEmptyClass:_=`is-empty`,command:v=()=>null,items:y=()=>[],minQueryLength:b=0,debounce:C=0,initialItems:w,placement:T=`bottom-start`,offset:E={},container:D,flip:O=!0,floatingUi:k,dismissOnOutsideClick:A=!0,render:j=()=>({}),allow:M=()=>!0,findSuggestionMatch:N=l,shouldShow:P,shouldResetDismissed:F}){let I=j==null?void 0:j(),L=i&&!a,R=(t,r)=>f(n,t,r,e);function z(e){return p({...e,editor:n,shouldResetDismissed:F,effectiveAllowSpaces:L})}let B=t=>m({view:t,pluginKeyRef:e});return new t({key:e,view:()=>x({editor:n,pluginKey:e,items:y,renderer:I,minQueryLength:b,debounce:C,initialItems:w,placement:T,offset:E,container:D,flip:O,floatingUi:k,dismissOnOutsideClick:A,command:v,clientRectFor:R,dispatchExit:B}),state:g({editor:n,char:r,effectiveAllowSpaces:L,allowToIncludeChar:a,allowedPrefixes:o,startOfLine:s,findSuggestionMatch:N,allow:M,shouldShow:P,shouldKeepDismissed:z,pluginKey:e}),props:h({pluginKey:e,decorationTag:c,decorationClass:u,decorationContent:d,decorationEmptyClass:_,renderer:I,dispatchExit:B})})}function w(e,t=S){let n=e.state.tr.setMeta(t,{exit:!0});e.dispatch(n)}var T=C;export{C as Suggestion,S as SuggestionPluginKey,T as default,w as exitSuggestion,l as findSuggestionMatch};
5

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.