notion-utils
Advanced tools
Comparing version 6.9.4 to 6.10.0
@@ -1,3 +0,3 @@ | ||
import { Block } from 'notion-types'; | ||
export declare function getBlockCollectionId(block: Block): string | null; | ||
import { Block, ExtendedRecordMap } from 'notion-types'; | ||
export declare function getBlockCollectionId(block: Block, recordMap: ExtendedRecordMap): string | null; | ||
//# sourceMappingURL=get-block-collection-id.d.ts.map |
@@ -1,2 +0,2 @@ | ||
var z=Object.defineProperty;var C=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var D=(e,t,o)=>t in e?z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,d=(e,t)=>{for(var o in t||(t={}))S.call(t,o)&&D(e,o,t[o]);if(C)for(var o of C(t))q.call(t,o)&&D(e,o,t[o]);return e};var B=(e,t,o)=>new Promise((r,s)=>{var n=l=>{try{p(o.next(l))}catch(c){s(c)}},i=l=>{try{p(o.throw(l))}catch(c){s(c)}},p=l=>l.done?r(l.value):Promise.resolve(l.value).then(n,i);p((o=o.apply(e,t)).next())});var h=e=>{var t;return e?Array.isArray(e)?(t=e==null?void 0:e.reduce((o,r)=>o+(r[0]!=="\u204D"&&r[0]!=="\u2023"?r[0]:""),""))!=null?t:"":e:""};function P(e){var t,o;return e.collection_id||((o=(t=e.format)==null?void 0:t.collection_pointer)==null?void 0:o.id)||null}function w(e,t){var o,r;if((o=e.properties)!=null&&o.title)return h(e.properties.title);if(e.type==="collection_view_page"||e.type==="collection_view"){let s=(r=t.collection[P(e)])==null?void 0:r.value;if(s)return h(s.name)}return""}function E(e,t){var o,r,s;if((o=e.format)!=null&&o.page_icon)return(r=e.format)==null?void 0:r.page_icon;if(e.type==="collection_view_page"||e.type==="collection_view"){let n=P(e);if(n){let i=(s=t.collection[n])==null?void 0:s.value;if(i)return i.icon}}return null}function ne(e){var o;let t=(o=e.block[Object.keys(e.block)[0]])==null?void 0:o.value;return t?w(t,e):null}function R(e,t,o){var r;try{if(!t.properties||!Object.keys(o.collection))return null;let s=(r=o.collection[t.parent_id])==null?void 0:r.value;if(s){let n=e.toLowerCase(),i=Object.keys(s.schema).find(c=>{var a,u;return((u=(a=s.schema[c])==null?void 0:a.name)==null?void 0:u.toLowerCase())===n});if(!i)return null;let{type:p}=s.schema[i],l=h(t.properties[i]);switch(p){case"created_time":return t.created_time;case"multi_select":return l.split(",");case"date":{let a=t.properties[i][0][1][0][1];if(a.type=="datetime")return new Date(`${a.start_date} ${a.start_time}`).getTime();if(a.type=="date")return new Date(a.start_date).getTime();if(a.type=="datetimerange"){let{start_date:u,start_time:y,end_date:f,end_time:_}=a,g=new Date(`${u} ${y}`).getTime(),m=new Date(`${f} ${_}`).getTime();return[g,m]}else{let u=new Date(a.start_date).getTime(),y=new Date(a.end_date).getTime();return[u,y]}}case"checkbox":return l=="Yes";case"last_edited_time":return t.last_edited_time;default:return l}}}catch(s){}return null}var F=e=>{if(e&&Array.isArray(e)){if(e[0]==="d")return e[1];for(let t of e){let o=F(t);if(o)return o}}return null};var $=(e,t,{inclusive:o=!1}={})=>{var s,n;let r=e;for(;r!=null;){if(o&&(r==null?void 0:r.type)==="page")return r;let i=r.parent_id,p=r.parent_table;if(!i)break;if(p==="collection")r=(s=t.collection[i])==null?void 0:s.value;else if(r=(n=t.block[i])==null?void 0:n.value,(r==null?void 0:r.type)==="page")return r}return null};var M={header:0,sub_header:1,sub_sub_header:2},me=(e,t)=>{var s;let o=((s=e.content)!=null?s:[]).map(n=>{var p,l;let i=(p=t.block[n])==null?void 0:p.value;if(i){let{type:c}=i;if(c==="header"||c==="sub_header"||c==="sub_sub_header")return{id:n,type:c,text:h((l=i.properties)==null?void 0:l.title),indentLevel:M[c]}}return null}).filter(Boolean),r=[{actual:-1,effective:-1}];for(let n of o){let{indentLevel:i}=n,p=i;do{let l=r[r.length-1],{actual:c,effective:a}=l;if(p>c)n.indentLevel=a+1,r.push({actual:p,effective:n.indentLevel});else if(p===c){n.indentLevel=a;break}else r.pop()}while(!0)}return o};var ue=(e,t)=>{let o=t||Object.keys(e.block)[0],r=new Set;function s(n){var u,y,f,_;if(r.has(n))return;r.add(n);let i=(u=e.block[n])==null?void 0:u.value;if(!i)return;let{content:p,type:l,properties:c,format:a}=i;if(c)for(let g of Object.keys(c)){let m=c[g];m.map(b=>{var v,T;let k=(T=(v=b==null?void 0:b[0])==null?void 0:v[1])==null?void 0:T[0];(k==null?void 0:k[0])==="p"&&k[1]&&s(k[1])});let x=(f=(y=m==null?void 0:m[0])==null?void 0:y[1])==null?void 0:f[0];(x==null?void 0:x[0])==="p"&&x[1]&&s(x[1])}if(a){let g=(_=a.transclusion_reference_pointer)==null?void 0:_.id;g&&s(g)}if(!(!p||!Array.isArray(p))&&!(n!==o&&(l==="page"||l==="collection_view_page")))for(let g of p)s(g)}return s(o),Array.from(r)};var U=(e="")=>`${e.substr(0,8)}-${e.substr(8,4)}-${e.substr(12,4)}-${e.substr(16,4)}-${e.substr(20)}`;var N=/\b([a-f0-9]{32})\b/,W=/\b([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\b/,I=(e="",{uuid:t=!0}={})=>{if(!e)return null;e=e.split("?")[0];let o=e.match(N);if(o)return t?U(o[1]):o[1];let r=e.match(W);return r?t?r[1]:r[1].replace(/-/g,""):null};var L=e=>e.replace(/-/g,"");import Q from"p-queue";function ve(i,p,l){return B(this,arguments,function*(e,t,o,{concurrency:r=4,traverseCollections:s=!0,targetPageId:n=null}={}){let c={},a=new Set,u=new Q({concurrency:r});function y(f){return B(this,null,function*(){n&&a.has(n)||(f=I(f),f&&!c[f]&&!a.has(f)&&(a.add(f),u.add(()=>B(this,null,function*(){var _,g;try{if(n&&a.has(n)&&f!==n)return;let m=yield o(f);if(!m)return;let x=(g=(_=m.block[f])==null?void 0:_.value)==null?void 0:g.space_id;if(x){if(!t)t=x;else if(t!==x)return}if(Object.keys(m.block).filter(b=>{var v;let k=(v=m.block[b])==null?void 0:v.value;return!(!k||k.type!=="page"&&k.type!=="collection_view_page"||t&&k.space_id&&k.space_id!==t)}).forEach(b=>y(b)),s)for(let b of Object.values(m.collection_query))for(let k of Object.values(b)){let{blockIds:v}=k;if(v)for(let T of v)y(T)}c[f]=m}catch(m){console.warn("page load error",{pageId:f,spaceId:t},m.statusCode,m.message),c[f]=null}a.delete(f)}))))})}return yield y(e),yield u.onIdle(),c})}var O=e=>(e||"").replace(/ /g,"-").replace(/[^a-zA-Z0-9-\u4e00-\u9fa5]/g,"").replace(/--/g,"-").replace(/-$/,"").replace(/^-/,"").trim().toLowerCase();var Re=(e,t,{uuid:o=!0}={})=>{var n;if(!e||!t)return null;let r=L(e),s=(n=t.block[e])==null?void 0:n.value;if(s){let i=R("slug",s,t)||R("Slug",s,t)||O(w(s,t));if(i)return o?`${i}-${r}`:i}return r};var Ie=(e,t)=>{var n;let o=e.block,r=[],s=t;do{let i=(n=o[s])==null?void 0:n.value;if(!i)break;let p=w(i,e),l=E(i,e);if(!(p||l))break;r.push({block:i,active:s===t,pageId:s,title:p,icon:l});let c=$(i,e),a=c==null?void 0:c.id;if(!a)break;s=a}while(!0);return r.reverse(),r};import j from"is-url-superb";var Se=(e,{mapImageUrl:t})=>{let r=Object.keys(e.block).flatMap(s=>{var p,l,c,a,u,y,f,_;let n=(p=e.block[s])==null?void 0:p.value,i=[];if(n){if(n.type==="image"){let x=((l=e.signed_urls)==null?void 0:l[n.id])||((u=(a=(c=n.properties)==null?void 0:c.source)==null?void 0:a[0])==null?void 0:u[0]);x&&i.push({block:n,url:x})}if((y=n.format)!=null&&y.page_cover){let m=n.format.page_cover;i.push({block:n,url:m})}if((f=n.format)!=null&&f.bookmark_cover){let m=n.format.bookmark_cover;i.push({block:n,url:m})}if((_=n.format)!=null&&_.bookmark_icon){let m=n.format.bookmark_icon;i.push({block:n,url:m})}let g=E(n,e);g&&j(g)&&i.push({block:n,url:g})}return i}).filter(Boolean).map(({block:s,url:n})=>t(n,s)).filter(Boolean);return Array.from(new Set(r))};import V from"normalize-url";import Y from"mem";var H=Y(e=>{if(!e)return"";try{if(e.startsWith("https://www.notion.so/image/")){let t=new URL(e),o=decodeURIComponent(t.pathname.substr(7)),r=H(o);t.pathname=`/image/${encodeURIComponent(r)}`,e=t.toString()}return V(e,{stripProtocol:!0,stripWWW:!0,stripHash:!0,stripTextFragment:!0,removeQueryParameters:!0})}catch(t){return""}});function We(e,t){return{block:d(d({},e.block),t.block),collection:d(d({},e.collection),t.collection),collection_view:d(d({},e.collection_view),t.collection_view),notion_user:d(d({},e.notion_user),t.notion_user),collection_query:d(d({},e.collection_query),t.collection_query),signed_urls:d(d({},e.signed_urls),t.signed_urls),preview_images:d(d({},e.preview_images),t.preview_images)}}var A=(e,{month:t="short"}={})=>{let o=new Date(e);return`${o.toLocaleString("en-US",{month:t})} ${o.getUTCDate()}, ${o.getUTCFullYear()}`};var He=e=>{let t=`${e.start_time||""} ${e.start_date} ${e.time_zone||""}`;return A(t)};export{A as formatDate,He as formatNotionDateTime,ve as getAllPagesInSpace,P as getBlockCollectionId,E as getBlockIcon,$ as getBlockParentPage,w as getBlockTitle,Re as getCanonicalPageId,F as getDateValue,Ie as getPageBreadcrumbs,ue as getPageContentBlockIds,Se as getPageImageUrls,R as getPageProperty,me as getPageTableOfContents,ne as getPageTitle,h as getTextContent,U as idToUuid,j as isUrl,We as mergeRecordMaps,O as normalizeTitle,H as normalizeUrl,I as parsePageId,L as uuidToId}; | ||
var z=Object.defineProperty;var C=Object.getOwnPropertySymbols;var S=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable;var I=(e,t,o)=>t in e?z(e,t,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[t]=o,g=(e,t)=>{for(var o in t||(t={}))S.call(t,o)&&I(e,o,t[o]);if(C)for(var o of C(t))q.call(t,o)&&I(e,o,t[o]);return e};var B=(e,t,o)=>new Promise((n,s)=>{var r=l=>{try{p(o.next(l))}catch(c){s(c)}},i=l=>{try{p(o.throw(l))}catch(c){s(c)}},p=l=>l.done?n(l.value):Promise.resolve(l.value).then(r,i);p((o=o.apply(e,t)).next())});var h=e=>{var t;return e?Array.isArray(e)?(t=e==null?void 0:e.reduce((o,n)=>o+(n[0]!=="\u204D"&&n[0]!=="\u2023"?n[0]:""),""))!=null?t:"":e:""};function P(e,t){var s,r,i,p,l,c,a;let o=e.collection_id||((r=(s=e.format)==null?void 0:s.collection_pointer)==null?void 0:r.id);if(o)return o;let n=(i=e==null?void 0:e.view_ids)==null?void 0:i[0];if(n){let u=(l=(p=t.collection_view)==null?void 0:p[n])==null?void 0:l.value;if(u)return(a=(c=u.format)==null?void 0:c.collection_pointer)==null?void 0:a.id}return null}function w(e,t){var o,n;if((o=e.properties)!=null&&o.title)return h(e.properties.title);if(e.type==="collection_view_page"||e.type==="collection_view"){let s=P(e,t);if(s){let r=(n=t.collection[s])==null?void 0:n.value;if(r)return h(r.name)}}return""}function E(e,t){var o,n,s;if((o=e.format)!=null&&o.page_icon)return(n=e.format)==null?void 0:n.page_icon;if(e.type==="collection_view_page"||e.type==="collection_view"){let r=P(e,t);if(r){let i=(s=t.collection[r])==null?void 0:s.value;if(i)return i.icon}}return null}function ne(e){var o;let t=(o=e.block[Object.keys(e.block)[0]])==null?void 0:o.value;return t?w(t,e):null}function R(e,t,o){var n;try{if(!t.properties||!Object.keys(o.collection))return null;let s=(n=o.collection[t.parent_id])==null?void 0:n.value;if(s){let r=e.toLowerCase(),i=Object.keys(s.schema).find(c=>{var a,u;return((u=(a=s.schema[c])==null?void 0:a.name)==null?void 0:u.toLowerCase())===r});if(!i)return null;let{type:p}=s.schema[i],l=h(t.properties[i]);switch(p){case"created_time":return t.created_time;case"multi_select":return l.split(",");case"date":{let a=t.properties[i][0][1][0][1];if(a.type=="datetime")return new Date(`${a.start_date} ${a.start_time}`).getTime();if(a.type=="date")return new Date(a.start_date).getTime();if(a.type=="datetimerange"){let{start_date:u,start_time:y,end_date:m,end_time:k}=a,d=new Date(`${u} ${y}`).getTime(),f=new Date(`${m} ${k}`).getTime();return[d,f]}else{let u=new Date(a.start_date).getTime(),y=new Date(a.end_date).getTime();return[u,y]}}case"checkbox":return l=="Yes";case"last_edited_time":return t.last_edited_time;default:return l}}}catch(s){}return null}var F=e=>{if(e&&Array.isArray(e)){if(e[0]==="d")return e[1];for(let t of e){let o=F(t);if(o)return o}}return null};var D=(e,t,{inclusive:o=!1}={})=>{var s,r;let n=e;for(;n!=null;){if(o&&(n==null?void 0:n.type)==="page")return n;let i=n.parent_id,p=n.parent_table;if(!i)break;if(p==="collection")n=(s=t.collection[i])==null?void 0:s.value;else if(n=(r=t.block[i])==null?void 0:r.value,(n==null?void 0:n.type)==="page")return n}return null};var M={header:0,sub_header:1,sub_sub_header:2},fe=(e,t)=>{var s;let o=((s=e.content)!=null?s:[]).map(r=>{var p,l;let i=(p=t.block[r])==null?void 0:p.value;if(i){let{type:c}=i;if(c==="header"||c==="sub_header"||c==="sub_sub_header")return{id:r,type:c,text:h((l=i.properties)==null?void 0:l.title),indentLevel:M[c]}}return null}).filter(Boolean),n=[{actual:-1,effective:-1}];for(let r of o){let{indentLevel:i}=r,p=i;do{let l=n[n.length-1],{actual:c,effective:a}=l;if(p>c)r.indentLevel=a+1,n.push({actual:p,effective:r.indentLevel});else if(p===c){r.indentLevel=a;break}else n.pop()}while(!0)}return o};var ue=(e,t)=>{let o=t||Object.keys(e.block)[0],n=new Set;function s(r){var u,y,m,k;if(n.has(r))return;n.add(r);let i=(u=e.block[r])==null?void 0:u.value;if(!i)return;let{content:p,type:l,properties:c,format:a}=i;if(c)for(let d of Object.keys(c)){let f=c[d];f.map(b=>{var v,T;let _=(T=(v=b==null?void 0:b[0])==null?void 0:v[1])==null?void 0:T[0];(_==null?void 0:_[0])==="p"&&_[1]&&s(_[1])});let x=(m=(y=f==null?void 0:f[0])==null?void 0:y[1])==null?void 0:m[0];(x==null?void 0:x[0])==="p"&&x[1]&&s(x[1])}if(a){let d=(k=a.transclusion_reference_pointer)==null?void 0:k.id;d&&s(d)}if(!(!p||!Array.isArray(p))&&!(r!==o&&(l==="page"||l==="collection_view_page")))for(let d of p)s(d)}return s(o),Array.from(n)};var $=(e="")=>`${e.substr(0,8)}-${e.substr(8,4)}-${e.substr(12,4)}-${e.substr(16,4)}-${e.substr(20)}`;var N=/\b([a-f0-9]{32})\b/,V=/\b([a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12})\b/,U=(e="",{uuid:t=!0}={})=>{if(!e)return null;e=e.split("?")[0];let o=e.match(N);if(o)return t?$(o[1]):o[1];let n=e.match(V);return n?t?n[1]:n[1].replace(/-/g,""):null};var L=e=>e.replace(/-/g,"");import W from"p-queue";function ve(i,p,l){return B(this,arguments,function*(e,t,o,{concurrency:n=4,traverseCollections:s=!0,targetPageId:r=null}={}){let c={},a=new Set,u=new W({concurrency:n});function y(m){return B(this,null,function*(){r&&a.has(r)||(m=U(m),m&&!c[m]&&!a.has(m)&&(a.add(m),u.add(()=>B(this,null,function*(){var k,d;try{if(r&&a.has(r)&&m!==r)return;let f=yield o(m);if(!f)return;let x=(d=(k=f.block[m])==null?void 0:k.value)==null?void 0:d.space_id;if(x){if(!t)t=x;else if(t!==x)return}if(Object.keys(f.block).filter(b=>{var v;let _=(v=f.block[b])==null?void 0:v.value;return!(!_||_.type!=="page"&&_.type!=="collection_view_page"||t&&_.space_id&&_.space_id!==t)}).forEach(b=>y(b)),s)for(let b of Object.values(f.collection_query))for(let _ of Object.values(b)){let{blockIds:v}=_;if(v)for(let T of v)y(T)}c[m]=f}catch(f){console.warn("page load error",{pageId:m,spaceId:t},f.statusCode,f.message),c[m]=null}a.delete(m)}))))})}return yield y(e),yield u.onIdle(),c})}var O=e=>(e||"").replace(/ /g,"-").replace(/[^a-zA-Z0-9-\u4e00-\u9fa5]/g,"").replace(/--/g,"-").replace(/-$/,"").replace(/^-/,"").trim().toLowerCase();var Re=(e,t,{uuid:o=!0}={})=>{var r;if(!e||!t)return null;let n=L(e),s=(r=t.block[e])==null?void 0:r.value;if(s){let i=R("slug",s,t)||R("Slug",s,t)||O(w(s,t));if(i)return o?`${i}-${n}`:i}return n};var Ue=(e,t)=>{var r;let o=e.block,n=[],s=t;do{let i=(r=o[s])==null?void 0:r.value;if(!i)break;let p=w(i,e),l=E(i,e);if(!(p||l))break;n.push({block:i,active:s===t,pageId:s,title:p,icon:l});let c=D(i,e),a=c==null?void 0:c.id;if(!a)break;s=a}while(!0);return n.reverse(),n};import j from"is-url-superb";var Se=(e,{mapImageUrl:t})=>{let n=Object.keys(e.block).flatMap(s=>{var p,l,c,a,u,y,m,k;let r=(p=e.block[s])==null?void 0:p.value,i=[];if(r){if(r.type==="image"){let x=((l=e.signed_urls)==null?void 0:l[r.id])||((u=(a=(c=r.properties)==null?void 0:c.source)==null?void 0:a[0])==null?void 0:u[0]);x&&i.push({block:r,url:x})}if((y=r.format)!=null&&y.page_cover){let f=r.format.page_cover;i.push({block:r,url:f})}if((m=r.format)!=null&&m.bookmark_cover){let f=r.format.bookmark_cover;i.push({block:r,url:f})}if((k=r.format)!=null&&k.bookmark_icon){let f=r.format.bookmark_icon;i.push({block:r,url:f})}let d=E(r,e);d&&j(d)&&i.push({block:r,url:d})}return i}).filter(Boolean).map(({block:s,url:r})=>t(r,s)).filter(Boolean);return Array.from(new Set(n))};import Q from"normalize-url";import Y from"mem";var H=Y(e=>{if(!e)return"";try{if(e.startsWith("https://www.notion.so/image/")){let t=new URL(e),o=decodeURIComponent(t.pathname.substr(7)),n=H(o);t.pathname=`/image/${encodeURIComponent(n)}`,e=t.toString()}return Q(e,{stripProtocol:!0,stripWWW:!0,stripHash:!0,stripTextFragment:!0,removeQueryParameters:!0})}catch(t){return""}});function Ve(e,t){return{block:g(g({},e.block),t.block),collection:g(g({},e.collection),t.collection),collection_view:g(g({},e.collection_view),t.collection_view),notion_user:g(g({},e.notion_user),t.notion_user),collection_query:g(g({},e.collection_query),t.collection_query),signed_urls:g(g({},e.signed_urls),t.signed_urls),preview_images:g(g({},e.preview_images),t.preview_images)}}var A=(e,{month:t="short"}={})=>{let o=new Date(e);return`${o.toLocaleString("en-US",{month:t})} ${o.getUTCDate()}, ${o.getUTCFullYear()}`};var He=e=>{let t=`${e.start_time||""} ${e.start_date} ${e.time_zone||""}`;return A(t)};export{A as formatDate,He as formatNotionDateTime,ve as getAllPagesInSpace,P as getBlockCollectionId,E as getBlockIcon,D as getBlockParentPage,w as getBlockTitle,Re as getCanonicalPageId,F as getDateValue,Ue as getPageBreadcrumbs,ue as getPageContentBlockIds,Se as getPageImageUrls,R as getPageProperty,fe as getPageTableOfContents,ne as getPageTitle,h as getTextContent,$ as idToUuid,j as isUrl,Ve as mergeRecordMaps,O as normalizeTitle,H as normalizeUrl,U as parsePageId,L as uuidToId}; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "notion-utils", | ||
"version": "6.9.4", | ||
"version": "6.10.0", | ||
"type": "module", | ||
@@ -48,3 +48,3 @@ "description": "Useful utilities for working with Notion data. Isomorphic.", | ||
}, | ||
"gitHead": "f4fd22c0b0771d750af350e6d03d7c968e5e2ca3" | ||
"gitHead": "d0f9b251fb9c09c8e9e7f8f63ebe3b227abfa772" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
96608
184