PageSourceSearch

https://pika.page/assets/prosemirror-utils-87e8abb394b6a68d14c1e01c2909b79b1820e60018b7cf9ab9a19f5db52b40ed.js

js pika.page collected 2026-10-03 21:40:11 UTC 6,353 bytes, 4 lines download raw bytes

1// [email protected] downloaded from https://ga.jspm.io/npm:[email protected]/dist/index.js
2
3import{NodeSelection as e,Selection as r}from"prosemirror-state";import{Fragment as t,Node as o}from"prosemirror-model";var removeParentNodeOfType=e=>r=>{const t=findParentNodeOfType(e)(r.selection);return t?removeNodeAtPos(t.pos)(r):r};var replaceParentNodeOfType=(e,r)=>t=>{Array.isArray(e)||(e=[e]);for(let o=0,n=e.length;o<n;o++){const n=findParentNodeOfType(e[o])(t.selection);if(n){const e=replaceNodeAtPos(n.pos,r)(t);if(e!==t)return e}}return t};var removeSelectedNode=e=>{if(isNodeSelection(e.selection)){const r=e.selection.$from.pos;const t=e.selection.$to.pos;return cloneTr(e.delete(r,t))}return e};var replaceSelectedNode=r=>n=>{if(isNodeSelection(n.selection)){const{$from:s,$to:a}=n.selection;if(r instanceof t&&s.parent.canReplace(s.index(),s.indexAfter(),r)||r instanceof o&&s.parent.canReplaceWith(s.index(),s.indexAfter(),r.type))return cloneTr(n.replaceWith(s.pos,a.pos,r).setSelection(new e(n.doc.resolve(s.pos))))}return n};var setTextSelection=(e,t=1)=>o=>{const n=r.findFrom(o.doc.resolve(e),t,true);return n?o.setSelection(n):o};var isSelectableNode=e=>Boolean(e instanceof o&&e.type&&e.type.spec.selectable);var shouldSelectNode=e=>isSelectableNode(e)&&e.type.isLeaf;var setSelection=(r,t,o)=>shouldSelectNode(r)?o.setSelection(new e(o.doc.resolve(t))):setTextSelection(t)(o);var safeInsert=(e,r,t)=>o=>{const n=typeof r==="number";const{$from:s}=o.selection;const a=n?o.doc.resolve(r):isNodeSelection(o.selection)?o.doc.resolve(s.pos+1):s;const{parent:c}=a;if(isNodeSelection(o.selection)&&t){const r=o;o=replaceSelectedNode(e)(o);if(r!==o)return o}if(isEmptyParagraph(c)){const r=o;o=replaceParentNodeOfType(c.type,e)(o);if(r!==o){const r=isSelectableNode(e)?a.before(a.depth):a.pos;return setSelection(e,r,o)}}if(canInsert(a,e)){o.insert(a.pos,e);const r=n?a.pos:isSelectableNode(e)?o.selection.$anchor.pos-1:o.selection.$anchor.pos;return cloneTr(setSelection(e,r,o))}for(let r=a.depth;r>0;r--){const t=a.after(r);const n=o.doc.resolve(t);if(canInsert(n,e)){o.insert(t,e);return cloneTr(setSelection(e,t,o))}}return o};var setParentNodeMarkup=(e,r,t,o)=>n=>{const s=findParentNodeOfType(e)(n.selection);return s?cloneTr(n.setNodeMarkup(s.pos,r,Object.assign({},s.node.attrs,t),o)):n};var selectParentNodeOfType=r=>t=>{if(!isNodeSelection(t.selection)){const o=findParentNodeOfType(r)(t.selection);if(o)return cloneTr(t.setSelection(e.create(t.doc,o.pos)))}return t};var removeNodeBefore=e=>{const r=findPositionOfNodeBefore(e.selection);return typeof r==="number"?removeNodeAtPos(r)(e):e};var isNodeSelection=r=>r instanceof e;var equalNodeType=(e,r)=>Array.isArray(e)&&e.indexOf(r.type)>-1||r.type===e;var cloneTr=e=>Object.assign(Object.create(e),e).setTime(Date.now());var replaceNodeAtPos=(e,r)=>t=>{const o=t.doc.nodeAt(e);const n=t.doc.resolve(e);if(!o)return t;if(canReplace(n,r)){t=t.replaceWith(e,e+o.nodeSize,r);const n=t.selection.$from.pos-1;t=setTextSelection(Math.max(n,0),-1)(t);t=setTextSelection(t.selection.$from.start())(t);return cloneTr(t)}return t};var canReplace=(e,r)=>{const o=e.node(e.depth);return o&&o.type.validContent(r instanceof t?r:t.from(r))};var removeNodeAtPos=e=>r=>{const t=r.doc.nodeAt(e);return t?cloneTr(r.delete(e,e+t.nodeSize)):r};var canInsert=(e,r)=>{const n=e.index();return r instanceof t?e.parent.canReplace(n,n,r):r instanceof o&&e.parent.canReplaceWith(n,n,r.type)};var isEmptyParagraph=e=>!e||e.type.name==="paragraph"&&e.nodeSize===2;var findParentNode=e=>({$from:r,$to:t},o=false)=>{if(!o||r.sameParent(t))return findParentNodeClosestToPos(r,e);{let o=Math.min(r.depth,t.depth);while(o>=0){const n=r.node(o);const s=t.node(o);if(s===n&&e(n))return{pos:o>0?r.before(o):0,start:r.start(o),depth:o,node:n};o-=1}}};var findParentNodeClosestToPos=(e,r)=>{for(let t=e.depth;t>0;t--){const o=e.node(t);if(r(o))return{pos:t>0?e.before(t):0,start:e.start(t),depth:t,node:o}}};var findParentDomRef=(e,r)=>t=>{const o=findParentNode(e)(t);if(o)return findDomRefAtPos(o.pos,r)};var hasParentNode=e=>r=>!!findParentNode(e)(r);var findParentNodeOfType=e=>r=>findParentNode((r=>equalNodeType(e,r)))(r);var findParentNodeOfTypeClosestToPos=(e,r)=>findParentNodeClosestToPos(e,(e=>equalNodeType(r,e)));var hasParentNodeOfType=e=>r=>hasParentNode((r=>equalNodeType(e,r)))(r);var findParentDomRefOfType=(e,r)=>t=>findParentDomRef((r=>equalNodeType(e,r)),r)(t);var findSelectedNodeOfType=e=>r=>{if(isNodeSelection(r)){const{node:t,$from:o}=r;if(equalNodeType(e,t))return{node:t,start:o.start(),pos:o.pos,depth:o.depth}}};var findPositionOfNodeBefore=e=>{const{nodeBefore:t}=e.$from;const o=r.findFrom(e.$from,-1);if(o&&t){const e=findParentNodeOfType(t.type)(o);return e?e.pos:o.$from.pos}};var findDomRefAtPos=(e,r)=>{const t=r(e);const o=t.node.childNodes[t.offset];return t.node.nodeType===Node.TEXT_NODE&&t.node.parentNode?t.node.parentNode:o&&o.nodeType!==Node.TEXT_NODE?o:t.node};var flatten=(e,r=true)=>{if(!e)throw new Error('Invalid "node" parameter');const t=[];e.descendants(((e,o)=>{t.push({node:e,pos:o});if(!r)return false}));return t};
3var findChildren=(e,r,t=true)=>{if(!e)throw new Error('Invalid "node" parameter');if(!r)throw new Error('Invalid "predicate" parameter');return flatten(e,t).filter((e=>r(e.node)))};var findTextNodes=(e,r=true)=>findChildren(e,(e=>e.isText),r);var findInlineNodes=(e,r=true)=>findChildren(e,(e=>e.isInline),r);var findBlockNodes=(e,r=true)=>findChildren(e,(e=>e.isBlock),r);var findChildrenByAttr=(e,r,t=true)=>findChildren(e,(e=>!!r(e.attrs)),t);var findChildrenByType=(e,r,t=true)=>findChildren(e,(e=>e.type===r),t);var findChildrenByMark=(e,r,t=true)=>findChildren(e,(e=>Boolean(r.isInSet(e.marks))),t);var contains=(e,r)=>!!findChildrenByType(e,r).length;export{canInsert,contains,findBlockNodes,findChildren,findChildrenByAttr,findChildrenByMark,findChildrenByType,findDomRefAtPos,findInlineNodes,findParentDomRef,findParentDomRefOfType,findParentNode,findParentNodeClosestToPos,findParentNodeOfType,findParentNodeOfTypeClosestToPos,findPositionOfNodeBefore,findSelectedNodeOfType,findTextNodes,flatten,hasParentNode,hasParentNodeOfType,isNodeSelection,removeNodeBefore,removeParentNodeOfType,removeSelectedNode,replaceParentNodeOfType,replaceSelectedNode,safeInsert,selectParentNodeOfType,setParentNodeMarkup,setTextSelection};
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.