hypothesis 1.980.0 → 1.981.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/boot.js +1 -1
- package/build/manifest.json +8 -8
- package/build/scripts/annotator.bundle.js +94 -94
- package/build/scripts/annotator.bundle.js.map +1 -1
- package/build/scripts/sidebar.bundle.js +59 -59
- package/build/scripts/sidebar.bundle.js.map +1 -1
- package/build/styles/annotator.css.map +1 -1
- package/build/styles/sidebar.css.map +1 -1
- package/build/styles/ui-playground.css.map +1 -1
- package/package.json +1 -1
|
@@ -557,7 +557,7 @@ t.addEventListener("touchstart",i,c),t.addEventListener("wheel",i,c)),a&&Lp(t),i
|
|
|
557
557
|
},s=t>0?`${o} (${t} available)`:o;return po(bo,{classes:qr("text-color-text","SelectionTab",{"is-selected":r}),onClick:a,onMouseDown:a,pressed:!!r,role:"tab",tabIndex:0,title:s,children:po(m,{children:[e,t>0&&!n&&po("span",{className:"text-tiny",style:"position:relative;bottom:3px;left:2px",children:t})]})})}var Fp=ri((function({annotationsService:e,isLoading:t,settings:n}){const r=ii(),o=r.selectedTab(),i=r.noteCount(),a=r.annotationCount(),s=r.orphanCount(),l=r.isWaitingToAnchorAnnotations(),c=e=>{r.clearSelection(),r.selectTab(e)},u="annotation"===o&&0===a&&!l,h="note"===o&&0===i;return po("div",{className:"hyp-u-vertical-spacing--4 SelectionTabs__container",children:[po("div",{className:"hyp-u-layout-row hyp-u-horizontal-spacing--6 SelectionTabs",role:"tablist",children:[po(Bp,{count:a,isWaitingToAnchor:l,isSelected:"annotation"===o,label:"Annotations",onSelect:()=>c("annotation"),children:"Annotations"}),po(Bp,{count:i,isWaitingToAnchor:l,isSelected:"note"===o,label:"Page notes",onSelect:()=>c("note"),
|
|
558
558
|
children:"Page Notes"}),s>0&&po(Bp,{count:s,isWaitingToAnchor:l,isSelected:"orphan"===o,label:"Orphans",onSelect:()=>c("orphan"),children:"Orphans"})]}),"note"===o&&n.enableExperimentalNewNoteButton&&po("div",{className:"hyp-u-layout-row--justify-right",children:po(bo,{"data-testid":"new-note-button",icon:"add",onClick:()=>e.createPageNote(),variant:"primary",style:ti(["ctaBackgroundColor"],n),children:"New note"})}),!t&&h&&po(ko,{classes:"text-center",children:po("span",{"data-testid":"notes-unavailable-message",children:"There are no page notes in this group."})}),!t&&u&&po(ko,{classes:"text-center",children:po("span",{"data-testid":"annotations-unavailable-message",children:["There are no annotations in this group.",po("br",{}),"Create one by selecting some text and clicking the"," ",po(Mo,{classes:"m-0.5 inline -mt-0.5",name:"annotate",title:"Annotate"})," ","button."]})})]})}),["annotationsService","settings"]);var jp=ri((function({frameSync:e,onLogin:t,onSignUp:n,loadAnnotationsService:r,streamer:o}){
|
|
559
559
|
const i=Ki(),a=ii(),s=a.focusedGroupId(),l=a.hasAppliedFilter()||a.hasSelectedAnnotations(),c=a.isLoading(),u=a.isLoggedIn(),h=a.directLinkedAnnotationId(),d=h?a.findAnnotationByID(h):void 0,p=d?ji(d):"annotation",m=a.searchUris(),f=a.hasSidebarOpened(),g=a.profile().userid,v=d&&!1===d.$orphan?d.$tag:null,y=!(c||!h)&&!d,_=a.directLinkedGroupFetchFailed(),b=y||_,w=!b,x=!b&&!l,k=h&&!u&&!y&&!c,S=to(s);Qr((()=>{if(!S.current||S.current!==s){if(S.current){let e=a.focusState().active;a.clearSelection(),e&&a.toggleFocusMode(!0)}S.current=s}s&&m.length&&r.load({groupId:s,uris:m})}),[a,r,s,g,m]),Qr((()=>{v?(e.focusAnnotations([v]),e.scrollToAnnotation(v),a.selectTab(p)):d&&a.selectTab(p)}),[p,e,d,v,a]);const C=a.hasFetchedProfile();return Qr((()=>{C&&(f||u)&&o.connect({applyUpdatesImmediately:!1})}),[C,u,f,o]),po("div",{children:[po("h2",{className:"sr-only",children:"Annotations"}),w&&po(Ep,{}),po(Dp,{onLogin:t,onSignUp:n}),y&&po(wp,{errorType:"annotation",onLoginRequest:t,showClearSelection:!0}),_&&po(wp,{
|
|
560
|
-
errorType:"group",onLoginRequest:t}),x&&po(Fp,{isLoading:c}),po(bp,{threads:i.children}),k&&po(Tp,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var Hp=ri((function({api:e,toastMessenger:t}){const n=ii(),r=n.routeParams().q,o=ro((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...yi(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return Qr((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),po(bp,{threads:Ki().children})}),["api","toastMessenger"]);class qp{constructor(e,t,n=window){var r,o,i;const a="N/A";let s=a;e.userid&&(s=e.userid,e.displayName&&(s=`${e.displayName} (${s})`)),this.version="1.
|
|
560
|
+
errorType:"group",onLoginRequest:t}),x&&po(Fp,{isLoading:c}),po(bp,{threads:i.children}),k&&po(Tp,{onLogin:t})]})}),["frameSync","loadAnnotationsService","streamer"]);var Hp=ri((function({api:e,toastMessenger:t}){const n=ii(),r=n.routeParams().q,o=ro((async t=>{const r={_separate_replies:!0,offset:0,limit:20,...yi(t)};try{n.annotationFetchStarted();const t=await e.search(r);n.addAnnotations([...t.rows,...t.replies])}finally{n.annotationFetchFinished()}}),[e,n]);return Qr((()=>{n.setSortKey("Newest"),n.clearAnnotations(),o(r).catch((e=>{t.error(`Unable to fetch annotations: ${e.message}`)}))}),[r,o,n,t]),po(bp,{threads:Ki().children})}),["api","toastMessenger"]);class qp{constructor(e,t,n=window){var r,o,i;const a="N/A";let s=a;e.userid&&(s=e.userid,e.displayName&&(s=`${e.displayName} (${s})`)),this.version="1.981.0",this.userAgent=n.navigator.userAgent,this.urls=t.map((e=>e.uri)).join(", ")||a,
|
|
561
561
|
this.fingerprint=null!==(r=null===(o=t[0])||void 0===o||null===(i=o.metadata)||void 0===i?void 0:i.documentFingerprint)&&void 0!==r?r:a,this.account=s,this.timestamp=(new Date).toString()}asFormattedString(){return`Version: ${this.version}\nUser Agent: ${this.userAgent}\nURL: ${this.urls}\nFingerprint: ${this.fingerprint}\nAccount: ${this.account}\nDate: ${this.timestamp}\n`}asEncodedURLString(){return encodeURIComponent(this.asFormattedString())}}function Up(e){const t=P(e);return!(null==t||!t.authority)&&t.authority!==e.authDomain}function $p({commandName:e,iconName:t}){return po("span",{className:"whitespace-nowrap",children:[po(Mo,{name:t,classes:qr("mx-1 -mt-1","text-color-text-light inline")}),po("em",{children:e})]})}var Gp=ri((function({settings:e}){const t=!Up(e);return po("ol",{className:"list-decimal pl-10 space-y-2",children:[po("li",{children:["To create an annotation, select text and then select the"," ",po($p,{iconName:"annotate",commandName:"Annotate"})," ","button."]}),po("li",{
|
|
562
562
|
children:["To create a highlight (",po(zo,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/why-are-highlights-private-by-default/",target:"_blank",children:"visible only to you"}),"), select text and then select the"," ",po($p,{iconName:"highlight",commandName:"Highlight"})," ","button."]}),t&&po("li",{children:["To annotate in a private group, select the group from the groups dropdown. Don't see your group? Ask the group creator to send a"," ",po(zo,{classes:"underline hover:underline",href:"https://web.hypothes.is/help/how-to-join-a-private-group/",target:"_blank",children:"join link"}),")."]}),po("li",{children:["To reply to an annotation, select the"," ",po($p,{iconName:"reply",commandName:"Reply"})," button."]})]})}),["settings"]);var Vp=ri((function({toastMessenger:e,versionData:t}){return po("div",{className:"hyp-u-vertical-spacing",children:[po("dl",{className:"VersionInfo",children:[po("dt",{className:"VersionInfo__key",children:"Version"}),po("dd",{
|
|
563
563
|
className:"VersionInfo__value",children:t.version}),po("dt",{className:"VersionInfo__key",children:"User Agent"}),po("dd",{className:"VersionInfo__value",children:t.userAgent}),po("dt",{className:"VersionInfo__key",children:"URL"}),po("dd",{className:"VersionInfo__value",children:t.urls}),po("dt",{className:"VersionInfo__key",children:"Fingerprint"}),po("dd",{className:"VersionInfo__value",children:t.fingerprint}),po("dt",{className:"VersionInfo__key",children:"Account"}),po("dd",{className:"VersionInfo__value",children:t.account}),po("dt",{className:"VersionInfo__key",children:"Date"}),po("dd",{className:"VersionInfo__value",children:t.timestamp})]}),po("div",{className:"hyp-u-layout-row--justify-center",children:po(bo,{onClick:()=>{try{ba(t.asFormattedString()),e.success("Copied version info to clipboard")}catch(t){e.error("Unable to copy version info")}},icon:"copy",children:"Copy version details"})})]})}),["toastMessenger"]);function Wp({children:e,onClick:t}){return po(wo,{
|
|
@@ -585,7 +585,7 @@ className:qr("HypothesisApp","js-thread-list-scroll-root",{"theme-clean":h,"Hypo
|
|
|
585
585
|
;function Sm({error:e}){return po("div",{className:"LaunchErrorPanel",children:po(Ho,{title:"Unable to start Hypothesis",children:e.message})})}class Cm{constructor(e,t){this._api=e,this._store=t}_applyDraftChanges(e){const t={},n=this._store.getDraft(e);return n&&(t.tags=n.tags,t.text=n.text,t.permissions=n.isPrivate?fa(e.user):ga(e.user,e.group)),{...e,...t}}_initialize(e,t=new Date){const n=this._store.getDefault("annotationPrivacy"),r=this._store.focusedGroupId(),o=this._store.profile();if(!r)throw new Error("Cannot create annotation without a group");const i=o.userid,a=o.user_info,s="s:"+U(8),l=Object.assign({created:t.toISOString(),group:r,permissions:va(i,r,n),tags:[],text:"",updated:t.toISOString(),user:i,user_info:a,$tag:s,hidden:!1,links:{},document:{title:""}},e);return Ni(l)&&(l.permissions=fa(i)),l}create(e,t=new Date){const n=this._initialize(e,t);this._store.addAnnotations([n]),this._store.deleteNewAndEmptyDrafts(),Ni(n)||this._store.createDraft(n,{tags:n.tags,text:n.text,isPrivate:!Ci(n)}),
|
|
586
586
|
Mi(n)?this._store.selectTab("note"):zi(n)&&this._store.selectTab("annotation"),(n.references||[]).forEach((e=>{this._store.setExpanded(e,!0)}))}createPageNote(){const e=this._store.mainFrame();if(!this._store.isLoggedIn())return void this._store.openSidebarPanel("loginPrompt");if(!e)return;const t={target:[],uri:e.uri};this.create(t)}async delete(e){await this._api.annotation.delete({id:e.id}),this._store.removeAnnotations([e])}async flag(e){await this._api.annotation.flag({id:e.id}),this._store.updateFlagStatus(e.id,!0)}reply(e,t){const n={group:e.group,permissions:Ci(e)?ga(t,e.group):fa(t),references:(e.references||[]).concat(e.id),target:[{source:e.target[0].source}],uri:e.uri};this.create(n)}async save(e){let t;const n=this._applyDraftChanges(e);let r;t=Si(e)?this._api.annotation.create({},n):this._api.annotation.update({id:e.id},n),this._store.annotationSaveStarted(e);try{r=await t}finally{this._store.annotationSaveFinished(e)}return Object.keys(e).forEach((t=>{"$"===t[0]&&(r[t]=e[t])})),
|
|
587
587
|
this._store.removeDraft(e),this._store.addAnnotations([r]),r}}Cm.$inject=["api","store"];class Am extends Error{constructor(e,t,n=""){let r="Network request failed";t&&(r+=` (${t.status})`),n&&(r+=`: ${n}`),super(r),this.url=e,this.response=t,this.reason=n}}async function Em(e,t){let n,r;try{n=await fetch(e,t)}catch(t){throw new Am(e,null,t.message)}if(204===n.status)return null;try{r=await n.json()}catch(t){throw new Am(e,n,"Failed to parse response")}var o;if(!n.ok)throw new Am(e,n,null===(o=r)||void 0===o?void 0:o.reason);return r}function Tm(e,t){const n={};for(const r in t)if(t.hasOwnProperty(r)){const o=t[r],i=":"+r;-1!==e.indexOf(i)?e=e.replace(i,encodeURIComponent(String(o))):n[r]=o}return{url:e,unusedParams:n}}function Nm(e){const t={};for(const n in e)e.hasOwnProperty(n)&&"$"!==n[0]&&(t[n]=e[n]);return t}class Lm{constructor(e,t,n){const r=e.routes();this._clientId=null;const o=()=>this._clientId,i=e=>function(e,t,{getAccessToken:n,getClientId:r,onRequestStarted:o,onRequestFinished:i}){
|
|
588
|
-
return async(a,s)=>{o();try{const[o,l]=await Promise.all([e,n()]),c=function(e,t){let n=e;return t.split(".").forEach((e=>{n=n[e]})),n}(o,t),u={"Content-Type":"application/json","Hypothesis-Client-Version":"1.
|
|
588
|
+
return async(a,s)=>{o();try{const[o,l]=await Promise.all([e,n()]),c=function(e,t){let n=e;return t.split(".").forEach((e=>{n=n[e]})),n}(o,t),u={"Content-Type":"application/json","Hypothesis-Client-Version":"1.981.0"};l&&(u.Authorization="Bearer "+l);const h=r();h&&(u["X-Client-Id"]=h);const{url:d,unusedParams:p}=Tm(c.url,a),m=new URL(d);for(let[e,t]of Object.entries(p)){Array.isArray(t)||(t=[t]);for(let n of t)null!=n&&m.searchParams.append(e,n.toString())}return await Em(m.toString(),{body:s?JSON.stringify(Nm(s)):null,headers:u,method:c.method})}finally{i()}}}(r,e,{getAccessToken:t.getAccessToken,getClientId:o,onRequestStarted:n.apiRequestStarted,onRequestFinished:n.apiRequestFinished});this.search=i("search"),this.annotation={create:i("annotation.create"),delete:i("annotation.delete"),get:i("annotation.read"),update:i("annotation.update"),flag:i("annotation.flag"),hide:i("annotation.hide"),unhide:i("annotation.unhide")},this.group={member:{delete:i("group.member.delete")},read:i("group.read")},this.groups={
|
|
589
589
|
list:i("groups.read")},this.profile={groups:{read:i("profile.groups.read")},read:i("profile.read"),update:i("profile.update")}}setClientId(e){this._clientId=e}}Lm.$inject=["apiRoutes","auth","store"];var Mm={};function zm(e,t){"boolean"==typeof t&&(t={forever:t}),this._originalTimeouts=JSON.parse(JSON.stringify(e)),this._timeouts=e,this._options=t||{},this._maxRetryTime=t&&t.maxRetryTime||1/0,this._fn=null,this._errors=[],this._attempts=1,this._operationTimeout=null,this._operationTimeoutCb=null,this._timeout=null,this._operationStart=null,this._timer=null,this._options.forever&&(this._cachedTimeouts=this._timeouts.slice(0))}var Om=zm;zm.prototype.reset=function(){this._attempts=1,this._timeouts=this._originalTimeouts.slice(0)},zm.prototype.stop=function(){this._timeout&&clearTimeout(this._timeout),this._timer&&clearTimeout(this._timer),this._timeouts=[],this._cachedTimeouts=null},zm.prototype.retry=function(e){if(this._timeout&&clearTimeout(this._timeout),!e)return!1;var t=(new Date).getTime()
|
|
590
590
|
;if(e&&t-this._operationStart>=this._maxRetryTime)return this._errors.push(e),this._errors.unshift(new Error("RetryOperation timeout occurred")),!1;this._errors.push(e);var n=this._timeouts.shift();if(void 0===n){if(!this._cachedTimeouts)return!1;this._errors.splice(0,this._errors.length-1),n=this._cachedTimeouts.slice(-1)}var r=this;return this._timer=setTimeout((function(){r._attempts++,r._operationTimeoutCb&&(r._timeout=setTimeout((function(){r._operationTimeoutCb(r._attempts)}),r._operationTimeout),r._options.unref&&r._timeout.unref()),r._fn(r._attempts)}),n),this._options.unref&&this._timer.unref(),!0},zm.prototype.attempt=function(e,t){this._fn=e,t&&(t.timeout&&(this._operationTimeout=t.timeout),t.cb&&(this._operationTimeoutCb=t.cb));var n=this;this._operationTimeoutCb&&(this._timeout=setTimeout((function(){n._operationTimeoutCb()}),n._operationTimeout)),this._operationStart=(new Date).getTime(),this._fn(this._attempts)},zm.prototype.try=function(e){
|
|
591
591
|
console.log("Using RetryOperation.try() is deprecated"),this.attempt(e)},zm.prototype.start=function(e){console.log("Using RetryOperation.start() is deprecated"),this.attempt(e)},zm.prototype.start=zm.prototype.try,zm.prototype.errors=function(){return this._errors},zm.prototype.attempts=function(){return this._attempts},zm.prototype.mainError=function(){if(0===this._errors.length)return null;for(var e={},t=null,n=0,r=0;r<this._errors.length;r++){var o=this._errors[r],i=o.message,a=(e[i]||0)+1;e[i]=a,a>=n&&(t=o,n=a)}return t},function(e){var t=Om;e.operation=function(n){var r=e.timeouts(n);return new t(r,{forever:n&&(n.forever||n.retries===1/0),unref:n&&n.unref,maxRetryTime:n&&n.maxRetryTime})},e.timeouts=function(e){if(e instanceof Array)return[].concat(e);var t={retries:10,factor:2,minTimeout:1e3,maxTimeout:1/0,randomize:!1};for(var n in e)t[n]=e[n];if(t.minTimeout>t.maxTimeout)throw new Error("minTimeout is greater than maxTimeout");for(var r=[],o=0;o<t.retries;o++)r.push(this.createTimeout(o,t))
|
|
@@ -596,61 +596,61 @@ const t=`left=${e.screen.width/2-237.5},top=${e.screen.height/2-215},width=475,h
|
|
|
596
596
|
;return d(n),n})(i),i=null):a=Promise.resolve(function(){const e=n.getObject(h());return e&&"string"==typeof e.accessToken&&"string"==typeof e.refreshToken&&"number"==typeof e.expiresAt?{accessToken:e.accessToken,refreshToken:e.refreshToken,expiresAt:e.expiresAt}:null}())}const e=a,t=await a;if(!t)return null;if(e!==a)return f();if(Date.now()>t.expiresAt){const e=m();return a=(async(e,t)=>{const n=await p();let r;try{if(r=await n.refreshToken(e),Date.now()>r.expiresAt)throw new Error("Refreshed token expired in the past")}catch{return null}return t.persist&&d(r),r})(t.refreshToken,{persist:void 0===e}),f()}return t.accessToken};(()=>{e.addEventListener("storage",(({key:e})=>{e===h()&&(a=null,this.emit("oauthTokensChanged"))}))})(),this.login=async function(){const t=Fm.openAuthPopupWindow(e),n=await p(),r=await n.authorize(e,t);i=r,a=null},this.logout=async function(){const[e,t]=await Promise.all([a,p()]);e&&await t.revokeToken(e.accessToken),a=Promise.resolve(null),n.removeItem(h())},this.getAccessToken=f}}
|
|
597
597
|
jm.$inject=["$window","apiRoutes","localStorage","settings","toastMessenger"];class Hm{constructor(e,t){this._annotationsService=e,this._store=t,this._saving=new Set,this._failed=new Set}init(){const e=e=>!this._saving.has(e)&&!this._failed.has(e);this._store.subscribe((()=>{this._store.newHighlights().forEach((t=>{const n=t.$tag;e(n)&&(this._saving.add(n),Rm((()=>this._annotationsService.save(t))).catch((()=>{this._failed.add(n)})).finally((()=>{this._saving.delete(n)})))}))}))}isSaving(){return this._saving.size>0}}Hm.$inject=["annotationsService","store"];var qm=function(e,t,n,r){var o=n?n.call(r,e,t):void 0;if(void 0!==o)return!!o;if(e===t)return!0;if("object"!=typeof e||!e||"object"!=typeof t||!t)return!1;var i=Object.keys(e),a=Object.keys(t);if(i.length!==a.length)return!1;for(var s=Object.prototype.hasOwnProperty.bind(t),l=0;l<i.length;l++){var c=i[l];if(!s(c))return!1;var u=e[c],h=t[c];if(!1===(o=n?n.call(r,u,h,c):void 0)||void 0===o&&u!==h)return!1}return!0};function Um(e,t,n){
|
|
598
598
|
const r=Array.isArray(t),o=()=>r?t.map((e=>e())):t();let i=o();return e((()=>{const e=o();if(r?qm(e,i):e===i)return;const t=i;i=e,n(e,t)}))}class $m{constructor(e,t){this._frameSync=e,this._store=t}init(){const e=()=>this._store.profile().features;Um(this._store.subscribe,[e,()=>this._store.frames()],(()=>{this._frameSync.notifyHost("featureFlagsUpdated",e()||{})}))}}function Gm(e,t){return!!function(e){if(null===e||"object"!=typeof e)return!1;for(let t of["frame1","frame2","type","requestId"])if("string"!=typeof e[t])return!1;return!0}(e)&&JSON.stringify(e,Object.keys(t).sort())===JSON.stringify(t,Object.keys(t).sort())}$m.$inject=["frameSync","store"];class Vm{constructor({hostFrame:e,source:t}){this._hostFrame=e,this._source=t,this._listeners=new ha}destroy(){this._listeners.removeAll()}async discover(e){let t=!1;if(("guest"===this._source&&"host"===e||"guest"===this._source&&"sidebar"===e||"sidebar"===this._source&&"host"===e||"notebook"===this._source&&"sidebar"===e)&&(t=!0),
|
|
599
|
-
!t)throw new Error("Invalid request of channel/port");const n=U(6);return new Promise(((t,r)=>{const o=()=>{this._hostFrame.postMessage({frame1:this._source,frame2:e,type:"request",requestId:n},"*")},i=setInterval(o,250),a=setTimeout((()=>{clearInterval(i),r(new Error(`Unable to establish ${this._source}-${e} communication channel`))}),2e4),s=this._listeners.add(window,"message",(r=>{const{data:o,ports:l}=r;Gm(o,{frame1:this._source,frame2:e,type:"offer",requestId:n})&&(clearInterval(i),clearTimeout(a),this._listeners.remove(s),t(l[0]))}));o()}))}}
|
|
600
|
-
;return
|
|
601
|
-
|
|
602
|
-
s.forEach((e=>{this._guestRPC.forEach((t=>t.call("deleteAnnotation",e.$tag))),this._inFrame.delete(e.$tag)})),n.length>0&&n.every((e=>e.isAnnotationFetchComplete))&&(0!==o&&o===e||(this._hostRPC.call("publicAnnotationCountChanged",o),e=o))}))}_connectGuest(e){const t=new
|
|
603
|
-
this._annotationsService.create(e)}));let r={};const o=ua((()=>{this._store.updateAnchorStatus(r),r={}}),10);t.on("syncAnchoringStatus",(({$tag:e,$orphan:t})=>{this._inFrame.add(e),r[e]=t?"orphan":"anchored",o()})),t.on("showAnnotations",(e=>{this._store.selectAnnotations(this._store.findIDsForTags(e)),this._store.selectTab("annotation")})),t.on("focusAnnotations",(e=>{this._store.focusAnnotations(e||[])})),t.on("toggleAnnotationSelection",(e=>{this._store.toggleSelectedAnnotations(this._store.findIDsForTags(e))})),t.on("openSidebar",(()=>{this._hostRPC.call("openSidebar")
|
|
604
|
-
;this._hostRPC.connect(e),this._hostRPC.call("ready"),this._listeners.add(e,"message",(e=>{const{data:t,ports:n}=e;Gm(t,{frame1:"guest",frame2:"sidebar",type:"offer"})&&this._connectGuest(n[0])}))}notifyHost(e,...t){this._hostRPC.call(e,...t)}focusAnnotations(e){this._store.focusAnnotations(e),this._guestRPC.forEach((t=>t.call("focusAnnotations",e)))}scrollToAnnotation(e){this._guestRPC.forEach((t=>t.call("scrollToAnnotation",e)))}destroy(){this._portFinder.destroy(),this._listeners.removeAll()}}function
|
|
605
|
-
;return null!==(e=null===(t=this._store.mainFrame())||void 0===t?void 0:t.uri)&&void 0!==e?e:null}async _filterGroups(e,t,n,r){if(r){const t=e.find((e=>e.id===r));t&&!t.isScopedToUri&&t.scopes&&t.scopes.enforced&&(e=e.filter((e=>e.id!==r)),this._store.setDirectLinkedGroupFetchFailed(),r=null)}if(t)return e;const o=e.some((e=>"__world__"!==e.id&&e.isScopedToUri));return o?"__world__"===r||"__world__"===n?e:e.filter((e=>"__world__"!==e.id)):e}_setupAutoReload(){this._reloadSetUp||(this._reloadSetUp=!0,Um(this._store.subscribe,(()=>this._mainURI()),(()=>{this.load()})),
|
|
606
|
-
_fetchGroup(e){return this._api.group.read({id:e,expand:
|
|
607
|
-
;if(d){m=d.group;const e=c.concat(u).find((e=>e.id===d.group));if(!e)try{const e=await this._fetchGroup(d.group);u.push(e)}catch(e){this._toastMessenger.error("Unable to fetch group for linked annotation")}}const f=null!==h,g=await this._filterGroups(J(c,u,n,this._settings),f,m,i),v=m||i||null;return this._addGroupsToStore(g,v),g}async _loadServiceSpecifiedGroups(e){const t=await this._api.profile.groups.read({expand:
|
|
608
|
-
return this._loadServiceSpecifiedGroups(e)}return this._loadGroupsForUserAndDocument()}focus(e){const t=this._store.focusedGroupId();this._store.focusGroup(e);const n=this._store.focusedGroupId();if(t!==n&&null!==t&&n){const e=this._store.newAnnotations().filter((e=>!ki(e))).map((e=>({...e,group:n})));e.length&&this._store.addAnnotations(e),this._store.setDefault("focusedGroup",n)}}leave(e){return this._api.group.member.delete({pubid:e,userid:"me"})}}
|
|
609
|
-
});else t&&t.length>0&&(this._streamFilter.resetFilter().addClause("/uri","one_of",t),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}));const s={incremental:!0,separateReplies:!1,maxResults:r,sortBy:o,sortOrder:i};this._searchClient=new tm(this._api.search,s),this._searchClient.on("resultCount",(e=>{this._store.setAnnotationResultCount(e)})),this._searchClient.on("results",(e=>{e.length&&this._store.addAnnotations(e)})),this._searchClient.on("error",(e=>{"function"==typeof n?n(e):console.error(e)})),
|
|
610
|
-
id:t.references[0]})),n=await this._api.search({references:t.id})}finally{this._store.annotationFetchFinished()}const r=[t,...n.rows];if(this._store.addAnnotations(r),!ki(t)){const e=t.id;this._streamFilter.addClause("/references","one_of",e,!0).addClause("/id","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}),this._streamer.connect()}return r}}
|
|
611
|
-
removeItem(e){this._storage.removeItem(e)}}
|
|
612
|
-
{const e=t.id;delete r.id,n=`/a/${e}`}break;case"notebook":n="/notebook";break;case"stream":n="/stream";break;default:throw new Error(`Cannot generate URL for route "${e}"`)}let o=!1;const i=new URLSearchParams;for(let[e,t]of Object.entries(r))o=!0,i.set(e,t);return o&&(n+="?"+i.toString()),n}sync(){const{route:e,params:t}=this.currentRoute();this._store.changeRoute(e,t),this._didRegisterPopstateListener||(this._window.addEventListener("popstate",(()=>{this.sync()})),this._didRegisterPopstateListener=!0)}navigate(e,t){
|
|
613
|
-
this._authority=null!==(i=null===(a=P(r))||void 0===a?void 0:a.authority)&&void 0!==i?i:null,this._lastLoad=null,this._lastLoadTime=null,n.on("oauthTokensChanged",(()=>this.reload()))}load(){return(!this._lastLoad||!this._lastLoadTime||Date.now()-this._lastLoadTime>3e5)&&(this._lastLoadTime=Date.now(),this._lastLoad=Rm((()=>{const e=this._authority?{authority:this._authority}:{};return this._api.profile.read(e)})).then((e=>(this.update(e),this._lastLoadTime=Date.now(),e))).catch((e=>{throw this._lastLoadTime=null,e}))),this._lastLoad}async dismissSidebarTutorial(){
|
|
614
|
-
return this._lastLoad=null,this._lastLoadTime=null,this.load()}}
|
|
615
|
-
n.onerror=e=>{this.emit("error",e)},n.onmessage=e=>{this.emit("message",e)}})()}}class
|
|
616
|
-
case"create":case"update":case"past":this._store.receiveRealTimeUpdates({updatedAnnotations:e});break;case"delete":this._store.receiveRealTimeUpdates({deletedAnnotations:e})}this._updateImmediately&&this.applyPendingUpdates()}else if("session-change"===t.type)this._session.update(t.model),this._groups.load();else if("whoyouare"===t.type){const e=this._store.profile().userid;t.userid!==e&&console.warn('WebSocket user ID "%s" does not match logged-in ID "%s"',t.userid,e)}else K("Received unsupported notification",t.type)}_sendClientConfig(e){
|
|
617
|
-
throw console.error("Failed to fetch token for WebSocket authentication",e),e}if(n){const e=new URL(t);e.searchParams.set("access_token",n),r=e.toString()}else r=t;const o=new
|
|
618
|
-
this._socket||await this._reconnect()}}
|
|
619
|
-
dismiss(e){const t=this._store.getToastMessage(e);t&&!t.isDismissed&&(this._store.updateToastMessage({...t,isDismissed:!0}),setTimeout((()=>{this._store.removeToastMessage(e)}),500))}_addMessage(e,t,{autoDismiss:n=!0,moreInfoURL:r=""}={}){if(this._store.hasToastMessage(e,t))return;const o=U(10),i={type:e,id:o,message:t,moreInfoURL:r};this._store.addToastMessage({isDismissed:!1,...i}),n&&setTimeout((()=>{this.dismiss(o)}),5e3)}error(e,t){this._addMessage("error",e,t)}success(e,t){this._addMessage("success",e,t)}notice(e,t){this._addMessage("notice",e,t)}}function
|
|
620
|
-
;t%2?
|
|
621
|
-
;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(
|
|
622
|
-
if("object"!=typeof e||null===e)throw new Error(
|
|
623
|
-
;return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce((function(e,t){return function(){return e(t.apply(void 0,arguments))}}))}function
|
|
624
|
-
return e(o)}));return r=
|
|
625
|
-
console.log("Prev State:",e.getState()),console.log("Action:",r),n(r),console.log("Next State:",e.getState()),console.groupEnd()}}}const
|
|
626
|
-
;return{...e,hasFetchedAnnotations:!0,activeAnnotationFetches:e.activeAnnotationFetches-1}},SET_ANNOTATION_RESULT_COUNT:(e,t)=>({annotationResultCount:t.resultCount})},
|
|
627
|
-
isLoading:function(e){return e.activeApiRequests>0||!e.hasFetchedAnnotations},isFetchingAnnotations:function(e){return e.activeAnnotationFetches>0},isSavingAnnotation:function(e,t){return!!t.$tag&&e.activeAnnotationSaveRequests.includes(t.$tag)},annotationResultCount:function(e){return e.annotationResultCount}}});var
|
|
628
|
-
get:r,put:function(t,o){"NOT_FOUND"===r(t)&&(n.unshift({key:t,value:o}),n.length>e&&n.pop())},getEntries:function(){return n},clear:function(){n=[]}}}(l,u);function d(){var t=h.get(arguments);if("NOT_FOUND"===t){if(t=e.apply(null,arguments),c){var n=h.getEntries(),r=n.find((function(e){return c(e.value,t)}));r&&(t=r.value)}h.put(arguments,t)}return t}return d.clearCache=function(){return h.clear()},d}function
|
|
629
|
-
"function"!=typeof l)throw new Error("createSelector expects an output function after the inputs, but received: ["+typeof l+"]");var c=s,u=c.memoizeOptions,h=void 0===u?n:u,d=Array.isArray(h)?h:[h],p=
|
|
630
|
-
selectors:{route:function(e){return e.name},routeParams:function(e){return e.params}}});function
|
|
631
|
-
highlighted:t.highlighted}},REMOVE_ANNOTATIONS:function(e,t){return{annotations:[...t.remainingAnnotations]}},UNHIDE_ANNOTATION:function(e,t){return{annotations:e.annotations.map((e=>e.id!==t.id?e:Object.assign({},e,{hidden:!1})))}},UPDATE_ANCHOR_STATUS:function(e,t){return{annotations:e.annotations.map((e=>{if(!t.statusUpdates.hasOwnProperty(e.$tag))return e;const n=t.statusUpdates[e.$tag];return"timeout"===n?Object.assign({},e,{$anchorTimeout:!0}):Object.assign({},e,{$orphan:"orphan"===n})}))}},UPDATE_FLAG_STATUS:function(e,t){return{annotations:e.annotations.map((e=>{if(e.id&&e.id===t.id){
|
|
632
|
-
e.filter((e=>!(e.id&&e.id in n||e.$tag&&e.$tag in r)))}(n().annotations.annotations,e);t({type:
|
|
633
|
-
},highlightAnnotations:function(e){return{type:
|
|
634
|
-
newHighlights:
|
|
635
|
-
directLinkedAnnotationId:null,directLinkedGroupId:null,directLinkedGroupFetchFailed:!1}}},
|
|
636
|
-
},directLinkedGroupId:function(e){return e.directLinkedGroupId}}});class
|
|
637
|
-
draft:new
|
|
638
|
-
SET_FOCUS_MODE:function(e,t){var n;return{focusActive:null!==(n=t.active)&&void 0!==n?n:!e.focusActive}},CLEAR_SELECTION:function(){return{filters:{},focusActive:!1,query:null}}},
|
|
639
|
-
setFilterQuery:function(e){return{type:
|
|
640
|
-
}(t))),[])),(e=>e)),
|
|
641
|
-
profile:function(e){return e.profile}}}),
|
|
642
|
-
return e.groups.find((e=>e.id===t))}const
|
|
643
|
-
getInScopeGroups:
|
|
644
|
-
FOCUS_GROUP:()=>({pendingUpdates:{},pendingDeletions:{}})},
|
|
645
|
-
pendingUpdates:function(e){return e.pendingUpdates},pendingUpdateCount:
|
|
646
|
-
return{forcedVisible:{},selected:{}}},SET_FILTER:function(){return{forcedVisible:{},selected:{},expanded:{}}},SET_FILTER_QUERY:function(){return{forcedVisible:{},selected:{},expanded:{}}},SET_FOCUS_MODE:function(){return{forcedVisible:{},selected:{}}},REMOVE_ANNOTATIONS:function(e,t){let n=e.selectedTab;"orphan"===n&&0===
|
|
647
|
-
;return"note"!==e&&t.push("Location"),t})),
|
|
648
|
-
CLOSE_SIDEBAR_PANEL:function(e,t){let n=e.activePanelName;return t.panelName===n&&(n=null),{activePanelName:n}},TOGGLE_SIDEBAR_PANEL:function(e,t){let n;const r=e.activePanelName===t.panelName,o=void 0!==t.panelState?t.panelState:!r;return n=o?t.panelName:r&&!o?null:e.activePanelName,{activePanelName:n}}},
|
|
649
|
-
|
|
650
|
-
get(e){if(this._instances.has(e))return this._instances.get(e);const t=this._providers.get(e);if(!t)throw new Error(`"${e}" is not registered`);if("value"in t)return this._instances.set(e,t.value),t.value;if(this._constructing.has(e))throw new Error(`Encountered a circular dependency when constructing "${e}"`);this._constructing.add(e);try{const n=[],r="class"in t&&t.class.$inject||"factory"in t&&t.factory.$inject||[];for(const t of r)try{n.push(this.get(t))}catch(n){
|
|
651
|
-
factory:e});try{return this.get(t)}finally{this._instances.delete(t),this._providers.delete(t)}}}const
|
|
652
|
-
"sidebar"===t.route()&&e.connect()}
|
|
653
|
-
document.createElement("div").dir="auto"}catch(e){t=!0}if(t){const t=e.vnode;e.vnode=e=>{"string"==typeof e.type&&"dir"in e.props&&"auto"===e.props.dir&&(e.props.dir=""),t&&t(e)}}}(),
|
|
654
|
-
|
|
655
|
-
console.error("Failed to start Hypothesis client: ",e),I(po(Sm,{error:e}),t)}(e,
|
|
599
|
+
!t)throw new Error("Invalid request of channel/port");const n=U(6);return new Promise(((t,r)=>{const o=()=>{this._hostFrame.postMessage({frame1:this._source,frame2:e,type:"request",requestId:n},"*")},i=setInterval(o,250),a=setTimeout((()=>{clearInterval(i),r(new Error(`Unable to establish ${this._source}-${e} communication channel`))}),2e4),s=this._listeners.add(window,"message",(r=>{const{data:o,ports:l}=r;Gm(o,{frame1:this._source,frame2:e,type:"offer",requestId:n})&&(clearInterval(i),clearTimeout(a),this._listeners.remove(s),t(l[0]))}));o()}))}}function Wm(e,t,n=[],r=-1){e.postMessage({protocol:"frame-rpc",version:"1.0.0",arguments:n,method:t,sequence:r})}class Ym{constructor({userAgent:e=navigator.userAgent,currentWindow:t=window}={}){this._port=null,this._methods=new Map,this._sequence=1,this._callbacks=new Map,this._listeners=new ha,this._listeners.add(t,"unload",(()=>{this._port&&(Wm(this._port,"close"),t!==t.parent&&function(e){const t=e.match(/\bAppleWebKit\/([0-9]+)\b/)
|
|
600
|
+
;return!!t&&!(parseInt(t[1])<=537)}(e)&&t.parent.postMessage({type:"hypothesisPortClosed"},"*",[this._port]))})),this._pendingCalls=[],this._receivedCloseEvent=!1}on(e,t){if(this._port)throw new Error("Cannot add a method handler after a port is connected");this._methods.set(e,t)}connect(e){this._port=e,this._listeners.add(e,"message",(e=>this._handle(e))),e.start(),Wm(e,"connect");for(let[e,t]of this._pendingCalls)this.call(e,...t);this._pendingCalls=[]}destroy(){this._port&&(Wm(this._port,"close"),this._port.close()),this._destroyed=!0,this._listeners.removeAll()}call(e,...t){if(this._port||this._pendingCalls.push([e,t]),!this._port||this._destroyed)return;const n=this._sequence++,r=t[t.length-1];"function"==typeof r&&(this._callbacks.set(n,r),t=t.slice(0,-1)),Wm(this._port,e,t,n)}_parseMessage({data:e}){return e&&"object"==typeof e?"frame-rpc"!==e.protocol||"1.0.0"!==e.version?null:Array.isArray(e.arguments)?e:null:null}_handle(e){const t=this._parseMessage(e),n=this._port;if(t&&n)if("method"in t){
|
|
601
|
+
if("close"===t.method){if(this._receivedCloseEvent)return;this._receivedCloseEvent=!0}const e=this._methods.get(t.method);if(!e)return;const r=(...e)=>{const r={arguments:e,protocol:"frame-rpc",response:t.sequence,version:"1.0.0"};n.postMessage(r)};e(...t.arguments,r)}else if("response"in t){const e=this._callbacks.get(t.response);this._callbacks.delete(t.response),e&&e(...t.arguments)}}}function Km({$tag:e,target:t,uri:n}){return{$tag:e,target:t,uri:n}}function Xm(e,t){const n=e.find((e=>e.uri===t.uri));return n||e.find((e=>null===e.id))}class Zm{constructor(e,t,n){this._window=e,this._annotationsService=t,this._store=n,this._portFinder=new Vm({hostFrame:this._window.parent,source:"sidebar"}),this._listeners=new ha,this._hostRPC=new Ym,this._guestRPC=new Map,this._nextGuestId=0,this._inFrame=new Set,this._highlightsVisible=!1,this._setupSyncToGuests(),this._setupHostEvents()}_setupSyncToGuests(){let e=0;Um(this._store.subscribe,[()=>this._store.allAnnotations(),()=>this._store.frames()],(([t,n],[r])=>{
|
|
602
|
+
let o=0;const i=new Set,a=[];t.forEach((e=>{ki(e)||(Ci(e)&&++o,i.add(e.$tag),this._inFrame.has(e.$tag)||a.push(e))}));const s=r.filter((e=>!i.has(e.$tag)));if(a.length>0){const e=new Map;for(let t of a){var l;const r=Xm(n,t);if(!r)continue;const o=null!==(l=e.get(r.id))&&void 0!==l?l:[];o.push(t),e.set(r.id,o)}for(let[t,n]of e){const e=this._guestRPC.get(t);e&&e.call("loadAnnotations",n.map(Km))}a.forEach((e=>{this._inFrame.add(e.$tag)}))}s.forEach((e=>{this._guestRPC.forEach((t=>t.call("deleteAnnotation",e.$tag))),this._inFrame.delete(e.$tag)})),n.length>0&&n.every((e=>e.isAnnotationFetchComplete))&&(0!==o&&o===e||(this._hostRPC.call("publicAnnotationCountChanged",o),e=o))}))}_connectGuest(e){const t=new Ym;++this._nextGuestId;let n=`temp-${this._nextGuestId}`;this._guestRPC.set(n,t),t.on("documentInfoChanged",(e=>{this._guestRPC.delete(n),n=e.frameIdentifier,this._guestRPC.set(n,t),this._store.connectFrame({id:e.frameIdentifier,metadata:e.metadata,uri:e.uri})})),t.on("close",(()=>{
|
|
603
|
+
const e=this._store.frames().find((e=>e.id===n));e&&this._store.destroyFrame(e),t.destroy(),this._guestRPC.delete(n)})),t.on("createAnnotation",(e=>{if(!this._store.isLoggedIn())return this._hostRPC.call("openSidebar"),this._store.openSidebarPanel("loginPrompt"),void this._guestRPC.forEach((t=>t.call("deleteAnnotation",e.$tag)));this._inFrame.add(e.$tag),e.$highlight||this._hostRPC.call("openSidebar"),this._hostRPC.call("showHighlights"),this._annotationsService.create(e)}));let r={};const o=ua((()=>{this._store.updateAnchorStatus(r),r={}}),10);t.on("syncAnchoringStatus",(({$tag:e,$orphan:t})=>{this._inFrame.add(e),r[e]=t?"orphan":"anchored",o()})),t.on("showAnnotations",(e=>{this._store.selectAnnotations(this._store.findIDsForTags(e)),this._store.selectTab("annotation")})),t.on("focusAnnotations",(e=>{this._store.focusAnnotations(e||[])})),t.on("toggleAnnotationSelection",(e=>{this._store.toggleSelectedAnnotations(this._store.findIDsForTags(e))})),t.on("openSidebar",(()=>{this._hostRPC.call("openSidebar")
|
|
604
|
+
})),t.on("closeSidebar",(()=>{this._hostRPC.call("closeSidebar")})),t.connect(e),t.call("setHighlightsVisible",this._highlightsVisible)}_setupHostEvents(){this._hostRPC.on("sidebarOpened",(()=>{this._store.setSidebarOpened(!0)})),this._hostRPC.on("setHighlightsVisible",(e=>{this._highlightsVisible=e,this._guestRPC.forEach((t=>t.call("setHighlightsVisible",e)))}))}async connect(){const e=await this._portFinder.discover("host");this._hostRPC.connect(e),this._hostRPC.call("ready"),this._listeners.add(e,"message",(e=>{const{data:t,ports:n}=e;Gm(t,{frame1:"guest",frame2:"sidebar",type:"offer"})&&this._connectGuest(n[0])}))}notifyHost(e,...t){this._hostRPC.call(e,...t)}focusAnnotations(e){this._store.focusAnnotations(e),this._guestRPC.forEach((t=>t.call("focusAnnotations",e)))}scrollToAnnotation(e){this._guestRPC.forEach((t=>t.call("scrollToAnnotation",e)))}destroy(){this._portFinder.destroy(),this._listeners.removeAll()}}function Jm(e){return Object.keys(e).reduce(((e,t)=>(e[t]=t,e)),{})}
|
|
605
|
+
Zm.$inject=["$window","annotationsService","store"];const Qm={id:"__default__",name:"__DEFAULT__",logo:"data:image/svg+xml;utf8,"+encodeURIComponent(Yo)};const ef=["organization","scopes"];class tf{constructor(e,t,n,r,o,i){this._store=e,this._api=t,this._auth=n,this._settings=o,this._toastMessenger=i,this._serviceConfig=P(o),this._reloadSetUp=!1}_mainURI(){var e,t;return null!==(e=null===(t=this._store.mainFrame())||void 0===t?void 0:t.uri)&&void 0!==e?e:null}async _filterGroups(e,t,n,r){if(r){const t=e.find((e=>e.id===r));t&&!t.isScopedToUri&&t.scopes&&t.scopes.enforced&&(e=e.filter((e=>e.id!==r)),this._store.setDirectLinkedGroupFetchFailed(),r=null)}if(t)return e;const o=e.some((e=>"__world__"!==e.id&&e.isScopedToUri));return o?"__world__"===r||"__world__"===n?e:e.filter((e=>"__world__"!==e.id)):e}_setupAutoReload(){this._reloadSetUp||(this._reloadSetUp=!0,Um(this._store.subscribe,(()=>this._mainURI()),(()=>{this.load()})),
|
|
606
|
+
Um(this._store.subscribe,[()=>this._store.hasFetchedProfile(),()=>this._store.profile().userid],((e,[t])=>{t&&this.load()})))}_addGroupsToStore(e,t){!function(e){e.forEach((e=>{e.organization&&"object"==typeof e.organization||(e.organization=Qm)}))}(e);const n=0===this._store.allGroups().length,r=this._store.getDefault("focusedGroup");this._store.loadGroups(e),n&&(t&&e.some((e=>e.id===t))?this.focus(t):r&&e.some((e=>e.id===r))&&this.focus(r))}_fetchGroup(e){return this._api.group.read({id:e,expand:ef})}async _loadGroupsForUserAndDocument(){var e;const t=()=>function(e,t){const n=t(e);return null!==n?Promise.resolve(n):new Promise((n=>{const r=e.subscribe((()=>{const o=t(e);null!==o&&(r(),n(o))}))}))}(this._store,(()=>this._mainURI()));let n=null;"sidebar"===this._store.route()&&(n=await t()),this._setupAutoReload();const r=this._store.directLinkedAnnotationId();let o=null;r&&(o=this._api.annotation.get({id:r}).catch((()=>null)));const i=this._store.directLinkedGroupId();let a=null
|
|
607
|
+
;i&&(a=this._fetchGroup(i).then((e=>(this._store.clearDirectLinkedGroupFetchFailed(),e))).catch((()=>(this._store.setDirectLinkedGroupFetchFailed(),null))));const s={expand:ef},l=null===(e=this._serviceConfig)||void 0===e?void 0:e.authority;l&&(s.authority=l),n&&(s.document_uri=n);const[c,u,h,d,p]=await Promise.all([this._api.profile.groups.read({expand:ef}),this._api.groups.list(s),this._auth.getAccessToken(),o,a]);p&&!u.some((e=>e.id===p.id))&&u.push(p);let m=null;if(d){m=d.group;const e=c.concat(u).find((e=>e.id===d.group));if(!e)try{const e=await this._fetchGroup(d.group);u.push(e)}catch(e){this._toastMessenger.error("Unable to fetch group for linked annotation")}}const f=null!==h,g=await this._filterGroups(J(c,u,n,this._settings),f,m,i),v=m||i||null;return this._addGroupsToStore(g,v),g}async _loadServiceSpecifiedGroups(e){const t=await this._api.profile.groups.read({expand:ef});let n;const r=async e=>{try{return await this._fetchGroup(e)}catch(e){return n=e,null}
|
|
608
|
+
},o=await Promise.all(e.map((e=>t.find((t=>t.id===e||t.groupid===e))||r(e)))),i=o.filter((e=>null!==e)),a=this._store.directLinkedGroupId();return this._addGroupsToStore(i,a),n&&this._toastMessenger.error(`Unable to fetch groups: ${n.message}`,{autoDismiss:!1}),i}async load(){var e;if(null!==(e=this._serviceConfig)&&void 0!==e&&e.groups){let e=[];try{e=await this._serviceConfig.groups}catch(e){this._toastMessenger.error(`Unable to fetch group configuration: ${e.message}`)}return this._loadServiceSpecifiedGroups(e)}return this._loadGroupsForUserAndDocument()}focus(e){const t=this._store.focusedGroupId();this._store.focusGroup(e);const n=this._store.focusedGroupId();if(t!==n&&null!==t&&n){const e=this._store.newAnnotations().filter((e=>!ki(e))).map((e=>({...e,group:n})));e.length&&this._store.addAnnotations(e),this._store.setDefault("focusedGroup",n)}}leave(e){return this._api.group.member.delete({pubid:e,userid:"me"})}}tf.$inject=["store","api","auth","session","settings","toastMessenger"];class nf{
|
|
609
|
+
constructor(e,t,n,r){this._api=e,this._store=t,this._streamer=n,this._streamFilter=r,this._searchClient=null}load({groupId:e,uris:t,onError:n,maxResults:r,sortBy:o,sortOrder:i,streamFilterBy:a="uri"}){if(this._store.removeAnnotations(this._store.savedAnnotations()),this._searchClient&&this._searchClient.cancel(),"group"===a)this._streamFilter.resetFilter().addClause("/group","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()});else t&&t.length>0&&(this._streamFilter.resetFilter().addClause("/uri","one_of",t),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}));const s={incremental:!0,separateReplies:!1,maxResults:r,sortBy:o,sortOrder:i};this._searchClient=new tm(this._api.search,s),this._searchClient.on("resultCount",(e=>{this._store.setAnnotationResultCount(e)})),this._searchClient.on("results",(e=>{e.length&&this._store.addAnnotations(e)})),this._searchClient.on("error",(e=>{"function"==typeof n?n(e):console.error(e)})),
|
|
610
|
+
this._searchClient.on("end",(()=>{this._searchClient=null,t&&t.length>0&&this._store.frames().forEach((e=>{t.indexOf(e.uri)>=0&&this._store.updateFrameAnnotationFetchStatus(e.uri,!0)})),this._store.annotationFetchFinished()})),this._store.annotationFetchStarted(),this._searchClient.get({group:e,uri:t})}async loadThread(e){let t,n;this._store.clearAnnotations();try{this._store.annotationFetchStarted(),t=await this._api.annotation.get({id:e}),ki(t)&&(t=await this._api.annotation.get({id:t.references[0]})),n=await this._api.search({references:t.id})}finally{this._store.annotationFetchFinished()}const r=[t,...n.rows];if(this._store.addAnnotations(r),!ki(t)){const e=t.id;this._streamFilter.addClause("/references","one_of",e,!0).addClause("/id","equals",e,!0),this._streamer.setConfig("filter",{filter:this._streamFilter.getFilter()}),this._streamer.connect()}return r}}nf.$inject=["api","store","streamer","streamFilter"];class rf{constructor(){this._store={}}getItem(e){return e in this._store?this._store[e]:null}
|
|
611
|
+
setItem(e,t){this._store[e]=t}removeItem(e){delete this._store[e]}}class of{constructor(e){let t="hypothesis.testKey";try{this._storage=e.localStorage,e.localStorage.setItem(t,t),e.localStorage.getItem(t),e.localStorage.removeItem(t)}catch(e){this._storage=new rf}}getItem(e){return this._storage.getItem(e)}getObject(e){const t=this._storage.getItem(e);return t?JSON.parse(t):null}setItem(e,t){this._storage.setItem(e,t)}setObject(e,t){const n=JSON.stringify(t);this._storage.setItem(e,n)}removeItem(e){this._storage.removeItem(e)}}of.$inject=["$window"];const af={annotationPrivacy:"hypothesis.privacy",focusedGroup:"hypothesis.groups.focus"};class sf{constructor(e,t){this._storage=e,this._store=t}init(){Object.keys(af).forEach((e=>{const t=this._storage.getItem(af[e]);this._store.setDefault(e,t)})),Um(this._store.subscribe,(()=>this._store.getDefaults()),((e,t)=>{for(let n in e)t[n]!==e[n]&&n in af&&this._storage.setItem(af[n],e[n])}))}}sf.$inject=["localStorage","store"];class lf{constructor(e,t){this._window=e,
|
|
612
|
+
this._store=t,this._didRegisterPopstateListener=!1}currentRoute(){const e=this._window.location.pathname.slice(1).split("/"),t=new URLSearchParams(this._window.location.search),n={};for(let[e,r]of t)n[e]=r;"client"===e[0]&&e.shift();let r;switch(e[0].replace(/\.html$/,"")){case"a":r="annotation",n.id=e[1]||"";break;case"notebook":r="notebook";break;case"stream":r="stream";break;default:r="sidebar"}return{route:r,params:n}}routeUrl(e,t={}){let n;const r={...t};switch(e){case"annotation":{const e=t.id;delete r.id,n=`/a/${e}`}break;case"notebook":n="/notebook";break;case"stream":n="/stream";break;default:throw new Error(`Cannot generate URL for route "${e}"`)}let o=!1;const i=new URLSearchParams;for(let[e,t]of Object.entries(r))o=!0,i.set(e,t);return o&&(n+="?"+i.toString()),n}sync(){const{route:e,params:t}=this.currentRoute();this._store.changeRoute(e,t),this._didRegisterPopstateListener||(this._window.addEventListener("popstate",(()=>{this.sync()})),this._didRegisterPopstateListener=!0)}navigate(e,t){
|
|
613
|
+
this._window.history.pushState({},"",this.routeUrl(e,t)),this.sync()}}lf.$inject=["$window","store"];class cf{constructor(e,t){this._apiRoutes=e,this._store=t}async init(){try{const e=await this._apiRoutes.links();this._store.updateLinks(e)}catch(e){console.warn(`Failed to fetch Hypothesis links: ${e.message}`)}}}cf.$inject=["apiRoutes","store"];class uf{constructor(e,t,n,r,o){var i,a;this._api=t,this._auth=n,this._store=e,this._toastMessenger=o,this._authority=null!==(i=null===(a=P(r))||void 0===a?void 0:a.authority)&&void 0!==i?i:null,this._lastLoad=null,this._lastLoadTime=null,n.on("oauthTokensChanged",(()=>this.reload()))}load(){return(!this._lastLoad||!this._lastLoadTime||Date.now()-this._lastLoadTime>3e5)&&(this._lastLoadTime=Date.now(),this._lastLoad=Rm((()=>{const e=this._authority?{authority:this._authority}:{};return this._api.profile.read(e)})).then((e=>(this.update(e),this._lastLoadTime=Date.now(),e))).catch((e=>{throw this._lastLoadTime=null,e}))),this._lastLoad}async dismissSidebarTutorial(){
|
|
614
|
+
const e=await this._api.profile.update({},{preferences:{show_sidebar_tutorial:!1}});this.update(e)}update(e){const t=this._store.profile(),n=e.userid!==t.userid;return this._store.updateProfile(e),this._lastLoad=Promise.resolve(e),this._lastLoadTime=Date.now(),n&&(e.userid?Cr({id:e.userid}):Cr(null)),e}async logout(){try{return await this._auth.logout(),this.reload()}catch(e){throw this._toastMessenger.error("Log out failed"),new Error(e)}}reload(){return this._lastLoad=null,this._lastLoadTime=null,this.load()}}uf.$inject=["store","api","auth","settings","toastMessenger"];class hf{constructor(){this._filter={match_policy:"include_any",clauses:[],actions:{create:!0,update:!0,delete:!0}}}addClause(e,t,n,r=!1){return this._filter.clauses.push({field:e,operator:t,value:n,case_sensitive:r}),this}getFilter(){return this._filter}resetFilter(){return this._filter={match_policy:"include_any",clauses:[],actions:{create:!0,update:!0,delete:!0}},this}}class df extends Jp{constructor(e){super();const t=[];let n
|
|
615
|
+
;const r=()=>{for(;t.length>0;){const e=JSON.stringify(t.shift());n.send(e)}};this.close=()=>{n.close(1e3)},this.send=e=>{t.push(e),this.isConnected()&&r()},this.isConnected=()=>n.readyState===WebSocket.OPEN,(()=>{n=new WebSocket(e),n.onopen=e=>{r(),this.emit("open",e)},n.onclose=e=>{if(1e3===e.code||1001===e.code)return void this.emit("close",e);const t=new Error(`WebSocket closed abnormally, code: ${e.code}`);console.warn(t),this.emit("disconnect")},n.onerror=e=>{this.emit("error",e)},n.onmessage=e=>{this.emit("message",e)}})()}}class pf{constructor(e,t,n,r,o){this._auth=n,this._groups=r,this._session=o,this._store=e,this._websocketURL=t.links().then((e=>e.websocket)),this.clientId=U(32),this._socket=null,this._updateImmediately=!0,this._configMessages={},this._reconnectionAttempts=0,this._reconnectSetUp=!1}applyPendingUpdates(){const e=Object.values(this._store.pendingUpdates());e.length&&this._store.addAnnotations(e);const t=Object.keys(this._store.pendingDeletions()).map((e=>({id:e})))
|
|
616
|
+
;t.length&&this._store.removeAnnotations(t),this._store.clearPendingUpdates()}_handleSocketError(e,t){K("Error connecting to H push notification service:",t);const n=new URL(e).hostname;-1!==["localhost","127.0.0.1"].indexOf(n)&&K("Check that your H service is configured to allow WebSocket connections from "+window.location.origin)}_handleSocketMessage(e){const t=JSON.parse(e.data);if(t)if("annotation-notification"===t.type){const e=t.payload;switch(t.options.action){case"create":case"update":case"past":this._store.receiveRealTimeUpdates({updatedAnnotations:e});break;case"delete":this._store.receiveRealTimeUpdates({deletedAnnotations:e})}this._updateImmediately&&this.applyPendingUpdates()}else if("session-change"===t.type)this._session.update(t.model),this._groups.load();else if("whoyouare"===t.type){const e=this._store.profile().userid;t.userid!==e&&console.warn('WebSocket user ID "%s" does not match logged-in ID "%s"',t.userid,e)}else K("Received unsupported notification",t.type)}_sendClientConfig(e){
|
|
617
|
+
Object.keys(this._configMessages).forEach((t=>{this._configMessages[t]&&e.send(this._configMessages[t])}))}setConfig(e,t){var n;this._configMessages[e]=t,null!==(n=this._socket)&&void 0!==n&&n.isConnected()&&this._socket.send(t)}async _reconnect(){var e;const t=await this._websocketURL;if(!t)return;let n,r;null===(e=this._socket)||void 0===e||e.close();try{n=await this._auth.getAccessToken()}catch(e){throw console.error("Failed to fetch token for WebSocket authentication",e),e}if(n){const e=new URL(t);e.searchParams.set("access_token",n),r=e.toString()}else r=t;const o=new df(r);o.on("open",(()=>{this._reconnectionAttempts=0,this._sendClientConfig(o)})),o.on("disconnect",(()=>{if(++this._reconnectionAttempts,this._reconnectionAttempts<10){const e=1e3*2**this._reconnectionAttempts;setTimeout((()=>this._reconnect()),e)}else console.error("Gave up trying to reconnect to Hypothesis real time update service")})),o.on("error",(e=>this._handleSocketError(t,e))),o.on("message",(e=>this._handleSocketMessage(e))),
|
|
618
|
+
this._socket=o,this.setConfig("client-id",{messageType:"client_id",value:this.clientId}),this.setConfig("auth-check",{type:"whoami",id:1})}async connect(e={}){var t;this._updateImmediately=null===(t=e.applyUpdatesImmediately)||void 0===t||t,this._reconnectSetUp||(this._reconnectSetUp=!0,Um(this._store.subscribe,(()=>this._store.profile().userid),(()=>{this._reconnect()}))),this._socket||await this._reconnect()}}pf.$inject=["store","apiRoutes","auth","groups","session"];class mf{constructor(e){this._storage=e}filter(e,t=null){const n=this._storage.getObject("hypothesis.user.tags.list")||[];let r=0;return n.filter((n=>{if(null!==t&&r>=t)return!1;const o=n.split(/\W+/),i=new RegExp(`^${Z(e)}`,"i");return!(!o.some((e=>e.match(i)))&&!n.match(i))&&(++r,!0)}))}store(e){const t=this._storage.getObject("hypothesis.user.tags.map")||{};e.forEach((e=>{t[e]?(t[e].count+=1,t[e].updated=Date.now()):t[e]={text:e,count:1,updated:Date.now()}})),this._storage.setObject("hypothesis.user.tags.map",t)
|
|
619
|
+
;const n=Object.keys(t).sort(((e,n)=>t[e].count!==t[n].count?t[n].count-t[e].count:e.localeCompare(n)));this._storage.setObject("hypothesis.user.tags.list",n)}}mf.$inject=["localStorage"];class ff{constructor(e){this._store=e}forceVisible(e){e.children.forEach((e=>{this.forceVisible(e)})),e.visible||this._store.setForcedVisible(e.id,!0)}}ff.$inject=["store"];class gf{constructor(e){this._store=e}dismiss(e){const t=this._store.getToastMessage(e);t&&!t.isDismissed&&(this._store.updateToastMessage({...t,isDismissed:!0}),setTimeout((()=>{this._store.removeToastMessage(e)}),500))}_addMessage(e,t,{autoDismiss:n=!0,moreInfoURL:r=""}={}){if(this._store.hasToastMessage(e,t))return;const o=U(10),i={type:e,id:o,message:t,moreInfoURL:r};this._store.addToastMessage({isDismissed:!1,...i}),n&&setTimeout((()=>{this.dismiss(o)}),5e3)}error(e,t){this._addMessage("error",e,t)}success(e,t){this._addMessage("success",e,t)}notice(e,t){this._addMessage("notice",e,t)}}function vf(e,t,n){return t in e?Object.defineProperty(e,t,{
|
|
620
|
+
value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function yf(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function _f(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?yf(Object(n),!0).forEach((function(t){vf(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):yf(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function bf(e){return"Minified Redux error #"+e+"; visit https://redux.js.org/Errors?code="+e+" for the full message or use the non-minified dev environment for full errors. "}gf.$inject=["store"];var wf="function"==typeof Symbol&&Symbol.observable||"@@observable",xf=function(){return Math.random().toString(36).substring(7).split("").join(".")},kf={INIT:"@@redux/INIT"+xf(),
|
|
621
|
+
REPLACE:"@@redux/REPLACE"+xf(),PROBE_UNKNOWN_ACTION:function(){return"@@redux/PROBE_UNKNOWN_ACTION"+xf()}};function Sf(e){if("object"!=typeof e||null===e)return!1;for(var t=e;null!==Object.getPrototypeOf(t);)t=Object.getPrototypeOf(t);return Object.getPrototypeOf(e)===t}function Cf(e,t,n){var r;if("function"==typeof t&&"function"==typeof n||"function"==typeof n&&"function"==typeof arguments[3])throw new Error(bf(0));if("function"==typeof t&&void 0===n&&(n=t,t=void 0),void 0!==n){if("function"!=typeof n)throw new Error(bf(1));return n(Cf)(e,t)}if("function"!=typeof e)throw new Error(bf(2));var o=e,i=t,a=[],s=a,l=!1;function c(){s===a&&(s=a.slice())}function u(){if(l)throw new Error(bf(3));return i}function h(e){if("function"!=typeof e)throw new Error(bf(4));if(l)throw new Error(bf(5));var t=!0;return c(),s.push(e),function(){if(t){if(l)throw new Error(bf(6));t=!1,c();var n=s.indexOf(e);s.splice(n,1),a=null}}}function d(e){if(!Sf(e))throw new Error(bf(7));if(void 0===e.type)throw new Error(bf(8))
|
|
622
|
+
;if(l)throw new Error(bf(9));try{l=!0,i=o(i,e)}finally{l=!1}for(var t=a=s,n=0;n<t.length;n++){(0,t[n])()}return e}function p(e){if("function"!=typeof e)throw new Error(bf(10));o=e,d({type:kf.REPLACE})}function m(){var e,t=h;return(e={subscribe:function(e){if("object"!=typeof e||null===e)throw new Error(bf(11));function n(){e.next&&e.next(u())}return n(),{unsubscribe:t(n)}}})[wf]=function(){return this},e}return d({type:kf.INIT}),(r={dispatch:d,subscribe:h,getState:u,replaceReducer:p})[wf]=m,r}function Af(e){for(var t=Object.keys(e),n={},r=0;r<t.length;r++){var o=t[r];"function"==typeof e[o]&&(n[o]=e[o])}var i,a=Object.keys(n);try{!function(e){Object.keys(e).forEach((function(t){var n=e[t];if(void 0===n(void 0,{type:kf.INIT}))throw new Error(bf(12));if(void 0===n(void 0,{type:kf.PROBE_UNKNOWN_ACTION()}))throw new Error(bf(13))}))}(n)}catch(e){i=e}return function(e,t){if(void 0===e&&(e={}),i)throw i;for(var r=!1,o={},s=0;s<a.length;s++){var l=a[s],c=n[l],u=e[l],h=c(u,t);if(void 0===h)throw t&&t.type,
|
|
623
|
+
new Error(bf(14));o[l]=h,r=r||h!==u}return(r=r||a.length!==Object.keys(e).length)?o:e}}function Ef(e,t){return function(){return t(e.apply(this,arguments))}}function Tf(){for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return 0===t.length?function(e){return e}:1===t.length?t[0]:t.reduce((function(e,t){return function(){return e(t.apply(void 0,arguments))}}))}function Nf(e){return function(t){var n=t.dispatch,r=t.getState;return function(t){return function(o){return"function"==typeof o?o(n,r,e):t(o)}}}}var Lf=Nf();Lf.withExtraArgument=Nf;var Mf=Lf;function zf(e,t=[],n=[]){const r={},o={},i={};e.forEach((e=>{e.namespace?(r[e.namespace]=e.initialState(...t),o[e.namespace]=function(e){return(t={},n)=>{const r=e[n.type];if(!r)return t;const o=r(t,n);return Array.isArray(o)?o:{...t,...o}}}(e.reducers),i[e.namespace]={selectors:e.selectors,rootSelectors:e.rootSelectors||{}}):console.warn("Store module does not specify a namespace",e)}));const a=function(){
|
|
624
|
+
for(var e=arguments.length,t=new Array(e),n=0;n<e;n++)t[n]=arguments[n];return function(e){return function(){var n=e.apply(void 0,arguments),r=function(){throw new Error(bf(15))},o={getState:n.getState,dispatch:function(){return r.apply(void 0,arguments)}},i=t.map((function(e){return e(o)}));return r=Tf.apply(void 0,i)(n.dispatch),_f(_f({},n),{},{dispatch:r})}}}(...[Mf],...n);const s=Cf(Af(o),r,a),l=Object.assign({},...e.map((e=>e.actionCreators))),c=function(e,t){if("function"==typeof e)return Ef(e,t);if("object"!=typeof e||null===e)throw new Error(bf(16));var n={};for(var r in e){var o=e[r];"function"==typeof o&&(n[r]=Ef(o,t))}return n}(l,s.dispatch),u=function(e,t){const n={};return Object.keys(e).forEach((r=>{const{selectors:o,rootSelectors:i={}}=e[r];Object.keys(o).forEach((e=>{if(n[e])throw new Error(`Duplicate selector "${e}"`);n[e]=(...n)=>o[e](t()[r],...n)})),Object.keys(i).forEach((e=>{if(n[e])throw new Error(`Duplicate selector "${e}"`);n[e]=(...n)=>i[e](t(),...n)}))})),n}(i,s.getState)
|
|
625
|
+
;return Object.assign(s,c,u),s}function Of(e,t){if(!(e instanceof Function)){const t=e;e=()=>t}return{initialState:e,...t}}function If(e){let t=0;return function(n){return function(r){if(!window.debug)return void n(r);++t;const o=r.type+" ("+t.toString()+")";console.group(o),console.log("Prev State:",e.getState()),console.log("Action:",r),n(r),console.log("Next State:",e.getState()),console.groupEnd()}}}const Rf={API_REQUEST_STARTED:e=>({...e,activeApiRequests:e.activeApiRequests+1}),API_REQUEST_FINISHED(e){if(0===e.activeApiRequests)throw new Error("API_REQUEST_FINISHED action when no requests were active");return{...e,activeApiRequests:e.activeApiRequests-1}},ANNOTATION_SAVE_STARTED(e,t){let n=[];t.annotation.$tag&&!e.activeAnnotationSaveRequests.includes(t.annotation.$tag)&&n.push(t.annotation.$tag);const r=e.activeAnnotationSaveRequests.concat(n);return{...e,activeAnnotationSaveRequests:r}},ANNOTATION_SAVE_FINISHED(e,t){const n=e.activeAnnotationSaveRequests.filter((e=>e!==t.annotation.$tag));return{...e,
|
|
626
|
+
activeAnnotationSaveRequests:n}},ANNOTATION_FETCH_STARTED:e=>({...e,activeAnnotationFetches:e.activeAnnotationFetches+1}),ANNOTATION_FETCH_FINISHED(e){if(0===e.activeAnnotationFetches)throw new Error("ANNOTATION_FETCH_FINISHED action when no annotation fetches were active");return{...e,hasFetchedAnnotations:!0,activeAnnotationFetches:e.activeAnnotationFetches-1}},SET_ANNOTATION_RESULT_COUNT:(e,t)=>({annotationResultCount:t.resultCount})},Pf=Jm(Rf);const Df=Of({activeAnnotationSaveRequests:[],activeApiRequests:0,activeAnnotationFetches:0,hasFetchedAnnotations:!1,annotationResultCount:null},{reducers:Rf,namespace:"activity",actionCreators:{annotationFetchStarted:function(){return{type:Pf.ANNOTATION_FETCH_STARTED}},annotationFetchFinished:function(){return{type:Pf.ANNOTATION_FETCH_FINISHED}},annotationSaveStarted:function(e){return{type:Pf.ANNOTATION_SAVE_STARTED,annotation:e}},annotationSaveFinished:function(e){return{type:Pf.ANNOTATION_SAVE_FINISHED,annotation:e}},apiRequestStarted:function(){return{
|
|
627
|
+
type:Pf.API_REQUEST_STARTED}},apiRequestFinished:function(){return{type:Pf.API_REQUEST_FINISHED}},setAnnotationResultCount:function(e){return{type:Pf.SET_ANNOTATION_RESULT_COUNT,resultCount:e}}},selectors:{hasFetchedAnnotations:function(e){return e.hasFetchedAnnotations},isLoading:function(e){return e.activeApiRequests>0||!e.hasFetchedAnnotations},isFetchingAnnotations:function(e){return e.activeAnnotationFetches>0},isSavingAnnotation:function(e,t){return!!t.$tag&&e.activeAnnotationSaveRequests.includes(t.$tag)},annotationResultCount:function(e){return e.annotationResultCount}}});var Bf=function(e,t){return e===t};function Ff(e,t){var n,r,o="object"==typeof t?t:{equalityCheck:t},i=o.equalityCheck,a=void 0===i?Bf:i,s=o.maxSize,l=void 0===s?1:s,c=o.resultEqualityCheck,u=function(e){return function(t,n){if(null===t||null===n||t.length!==n.length)return!1;for(var r=t.length,o=0;o<r;o++)if(!e(t[o],n[o]))return!1;return!0}}(a),h=1===l?(n=u,{get:function(e){return r&&n(r.key,e)?r.value:"NOT_FOUND"},
|
|
628
|
+
put:function(e,t){r={key:e,value:t}},getEntries:function(){return r?[r]:[]},clear:function(){r=void 0}}):function(e,t){var n=[];function r(e){var r=n.findIndex((function(n){return t(e,n.key)}));if(r>-1){var o=n[r];return r>0&&(n.splice(r,1),n.unshift(o)),o.value}return"NOT_FOUND"}return{get:r,put:function(t,o){"NOT_FOUND"===r(t)&&(n.unshift({key:t,value:o}),n.length>e&&n.pop())},getEntries:function(){return n},clear:function(){n=[]}}}(l,u);function d(){var t=h.get(arguments);if("NOT_FOUND"===t){if(t=e.apply(null,arguments),c){var n=h.getEntries(),r=n.find((function(e){return c(e.value,t)}));r&&(t=r.value)}h.put(arguments,t)}return t}return d.clearCache=function(){return h.clear()},d}function jf(e){var t=Array.isArray(e[0])?e[0]:e;if(!t.every((function(e){return"function"==typeof e}))){var n=t.map((function(e){return"function"==typeof e?"function "+(e.name||"unnamed")+"()":typeof e})).join(", ")
|
|
629
|
+
;throw new Error("createSelector expects all input-selectors to be functions, but received the following types: ["+n+"]")}return t}function Hf(e){for(var t=arguments.length,n=new Array(t>1?t-1:0),r=1;r<t;r++)n[r-1]=arguments[r];var o=function(){for(var t=arguments.length,r=new Array(t),o=0;o<t;o++)r[o]=arguments[o];var i,a=0,s={memoizeOptions:void 0},l=r.pop();if("object"==typeof l&&(s=l,l=r.pop()),"function"!=typeof l)throw new Error("createSelector expects an output function after the inputs, but received: ["+typeof l+"]");var c=s,u=c.memoizeOptions,h=void 0===u?n:u,d=Array.isArray(h)?h:[h],p=jf(r),m=e.apply(void 0,[function(){return a++,l.apply(null,arguments)}].concat(d)),f=e((function(){for(var e=[],t=p.length,n=0;n<t;n++)e.push(p[n].apply(null,arguments));return i=m.apply(null,e)}));return Object.assign(f,{resultFunc:l,memoizedResultFunc:m,dependencies:p,lastResult:function(){return i},recomputations:function(){return a},resetRecomputations:function(){return a=0}}),f};return o}var qf=Hf(Ff)
|
|
630
|
+
;function Uf(e,t){return e.reduce(((e,n)=>t(n)?e+1:e),0)}function $f(e){const t={};return e.forEach((e=>t[e]=!0)),t}function Gf(e){return Object.keys(e).filter((t=>!0===e[t]))}const Vf={CHANGE_ROUTE:(e,{name:t,params:n})=>({name:t,params:n})},Wf=Jm(Vf);const Yf=Of({name:null,params:{}},{namespace:"route",reducers:Vf,actionCreators:{changeRoute:function(e,t={}){return{type:Wf.CHANGE_ROUTE,name:e,params:t}}},selectors:{route:function(e){return e.name},routeParams:function(e){return e.params}}});function Kf(e,t){return e.find((e=>e.id===t))}function Xf(e,t){return e.find((e=>e.$tag===t))}const Zf={ADD_ANNOTATIONS:function(e,t){const n={},r={},o=[],i=[],a=[];let s=e.nextTag;return t.annotations.forEach((t=>{let i;t.id&&(i=Kf(e.annotations,t.id)),!i&&t.$tag&&(i=Xf(e.annotations,t.$tag)),i?(a.push(Object.assign({},i,t)),t.id&&(n[t.id]=!0),i.$tag&&(r[i.$tag]=!0)):(o.push(function(e,t){let n=e.$orphan;return e.id||(n=!1),Object.assign({},e,{$anchorTimeout:!1,$tag:e.$tag||t,$orphan:n})}(t,"t"+s)),++s)})),
|
|
631
|
+
e.annotations.forEach((e=>{n[e.id]||r[e.$tag]||i.push(e)})),{annotations:o.concat(a).concat(i),nextTag:s}},CLEAR_ANNOTATIONS:function(){return{annotations:[],focused:{},highlighted:{}}},FOCUS_ANNOTATIONS:function(e,t){return{focused:$f(t.focusedTags)}},HIDE_ANNOTATION:function(e,t){return{annotations:e.annotations.map((e=>e.id!==t.id?e:{...e,hidden:!0}))}},HIGHLIGHT_ANNOTATIONS:function(e,t){return{highlighted:t.highlighted}},REMOVE_ANNOTATIONS:function(e,t){return{annotations:[...t.remainingAnnotations]}},UNHIDE_ANNOTATION:function(e,t){return{annotations:e.annotations.map((e=>e.id!==t.id?e:Object.assign({},e,{hidden:!1})))}},UPDATE_ANCHOR_STATUS:function(e,t){return{annotations:e.annotations.map((e=>{if(!t.statusUpdates.hasOwnProperty(e.$tag))return e;const n=t.statusUpdates[e.$tag];return"timeout"===n?Object.assign({},e,{$anchorTimeout:!0}):Object.assign({},e,{$orphan:"orphan"===n})}))}},UPDATE_FLAG_STATUS:function(e,t){return{annotations:e.annotations.map((e=>{if(e.id&&e.id===t.id){
|
|
632
|
+
if(e.flagged===t.isFlagged)return e;const n=Object.assign({},e,{flagged:t.isFlagged});if(n.moderation){const r=t.isFlagged?1:-1;n.moderation=Object.assign({},e.moderation,{flagCount:e.moderation.flagCount+r})}return n}return e}))}}},Jf=Jm(Zf);function Qf(e){return(t,n)=>{const r=function(e,t){const n={},r={};return t.forEach((e=>{e.id&&(n[e.id]=!0),e.$tag&&(r[e.$tag]=!0)})),e.filter((e=>!(e.id&&e.id in n||e.$tag&&e.$tag in r)))}(n().annotations.annotations,e);t({type:Jf.REMOVE_ANNOTATIONS,annotationsToRemove:e,remainingAnnotations:r})}}function eg(e){return{type:Jf.UPDATE_ANCHOR_STATUS,statusUpdates:e}}const tg=Of({annotations:[],focused:{},highlighted:{},nextTag:1},{namespace:"annotations",reducers:Zf,actionCreators:{addAnnotations:function(e){return function(t,n){const r=e.filter((e=>!Kf(n().annotations.annotations,e.id)));if(t({type:Jf.ADD_ANNOTATIONS,annotations:e,currentAnnotationCount:n().annotations.annotations.length}),"sidebar"!==Yf.selectors.route(n().route))return
|
|
633
|
+
;const o=r.filter(Ei).map((e=>e.id));o.length>0&&setTimeout((()=>{const e=n().annotations.annotations,r=o.map((t=>Kf(e,t))).filter((e=>e&&Ei(e))).reduce(((e,t)=>(e[t.$tag]="timeout",e)),{});t(eg(r))}),500)}},clearAnnotations:function(){return{type:Jf.CLEAR_ANNOTATIONS}},focusAnnotations:function(e){return{type:Jf.FOCUS_ANNOTATIONS,focusedTags:e}},hideAnnotation:function(e){return{type:Jf.HIDE_ANNOTATION,id:e}},highlightAnnotations:function(e){return{type:Jf.HIGHLIGHT_ANNOTATIONS,highlighted:$f(e)}},removeAnnotations:Qf,unhideAnnotation:function(e){return{type:Jf.UNHIDE_ANNOTATION,id:e}},updateAnchorStatus:eg,updateFlagStatus:function(e,t){return{type:Jf.UPDATE_FLAG_STATUS,id:e,isFlagged:t}}},selectors:{allAnnotations:function(e){return e.annotations},annotationCount:qf((e=>e.annotations),(e=>Uf(e,zi))),annotationExists:function(e,t){return e.annotations.some((e=>e.id===t))},findAnnotationByID:function(e,t){return Kf(e.annotations,t)},findIDsForTags:function(e,t){const n=[];return t.forEach((t=>{
|
|
634
|
+
const r=Xf(e.annotations,t);r&&r.id&&n.push(r.id)})),n},focusedAnnotations:qf((e=>e.focused),(e=>Gf(e))),highlightedAnnotations:qf((e=>e.highlighted),(e=>Gf(e))),isAnnotationFocused:function(e,t){return!0===e.focused[t]},isWaitingToAnchorAnnotations:qf((e=>e.annotations),(e=>e.some(Ei))),newAnnotations:qf((e=>e.annotations),(e=>e.filter((e=>Si(e)&&!Ni(e))))),newHighlights:qf((e=>e.annotations),(e=>e.filter((e=>Si(e)&&Ni(e))))),noteCount:qf((e=>e.annotations),(e=>Uf(e,Mi))),orphanCount:qf((e=>e.annotations),(e=>Uf(e,Li))),savedAnnotations:function(e){return e.annotations.filter((e=>!Si(e)))}}}),ng={SET_DEFAULT:function(e,t){return{[t.defaultKey]:t.value}}},rg=Jm(ng);const og=Of({annotationPrivacy:null,focusedGroup:null},{namespace:"defaults",reducers:ng,actionCreators:{setDefault:function(e,t){return{type:rg.SET_DEFAULT,defaultKey:e,value:t}}},selectors:{getDefault:function(e,t){return e[t]},getDefaults:function(e){return e}}});const ig={UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED:(e,t)=>({
|
|
635
|
+
directLinkedGroupFetchFailed:t.directLinkedGroupFetchFailed}),UPDATE_DIRECT_LINKED_GROUP_ID:(e,t)=>({directLinkedGroupId:t.directLinkedGroupId}),UPDATE_DIRECT_LINKED_ANNOTATION_ID:(e,t)=>({directLinkedAnnotationId:t.directLinkedAnnotationId}),CLEAR_DIRECT_LINKED_IDS:()=>({directLinkedAnnotationId:null,directLinkedGroupId:null}),CLEAR_SELECTION:function(){return{directLinkedAnnotationId:null,directLinkedGroupId:null,directLinkedGroupFetchFailed:!1}}},ag=Jm(ig);const sg=Of((function(e){return{directLinkedGroupId:e.group||null,directLinkedAnnotationId:e.annotations||null,directLinkedGroupFetchFailed:!1}}),{namespace:"directLinked",reducers:ig,actionCreators:{setDirectLinkedGroupFetchFailed:function(){return{type:ag.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!0}},setDirectLinkedGroupId:function(e){return{type:ag.UPDATE_DIRECT_LINKED_GROUP_ID,directLinkedGroupId:e}},setDirectLinkedAnnotationId:function(e){return{type:ag.UPDATE_DIRECT_LINKED_ANNOTATION_ID,directLinkedAnnotationId:e}},
|
|
636
|
+
clearDirectLinkedGroupFetchFailed:function(){return{type:ag.UPDATE_DIRECT_LINKED_GROUP_FETCH_FAILED,directLinkedGroupFetchFailed:!1}},clearDirectLinkedIds:function(){return{type:ag.CLEAR_DIRECT_LINKED_IDS}}},selectors:{directLinkedAnnotationId:function(e){return e.directLinkedAnnotationId},directLinkedGroupFetchFailed:function(e){return e.directLinkedGroupFetchFailed},directLinkedGroupId:function(e){return e.directLinkedGroupId}}});class lg{constructor(e,t){this.annotation={id:e.id,$tag:e.$tag},this.isPrivate=t.isPrivate,this.tags=t.tags,this.text=t.text}match(e){return this.annotation.$tag&&e.$tag===this.annotation.$tag||this.annotation.id&&e.id===this.annotation.id}isEmpty(){return!this.text&&0===this.tags.length}}const cg={DISCARD_ALL_DRAFTS:function(){return[]},REMOVE_DRAFT:function(e,t){return e.filter((e=>!e.match(t.annotation)))},UPDATE_DRAFT:function(e,t){const n=e.filter((e=>!e.match(t.draft.annotation)));return n.push(t.draft),n}},ug=Jm(cg);function hg(e){return{type:ug.REMOVE_DRAFT,annotation:e}}
|
|
637
|
+
function dg(e,t){const n=e;for(let e=0;e<n.length;e++){const r=n[e];if(r.match(t))return r}return null}function pg(e,t){const n=dg(e,t);return n?n.isEmpty()?null:n:null}const mg=qf((e=>e),(e=>e.filter((e=>!e.annotation.id)).map((e=>e.annotation)))),fg=Of([],{namespace:"drafts",reducers:cg,actionCreators:{createDraft:function(e,t){return{type:ug.UPDATE_DRAFT,draft:new lg(e,t)}},deleteNewAndEmptyDrafts:function(){return(e,t)=>{const n=t().drafts.filter((e=>Si(e.annotation)&&!pg(t().drafts,e.annotation))).map((t=>(e(hg(t.annotation)),t.annotation)));e(Qf(n))}},discardAllDrafts:function(){return{type:ug.DISCARD_ALL_DRAFTS}},removeDraft:hg},selectors:{countDrafts:function(e){return e.length},getDraft:dg,getDraftIfNotEmpty:pg,unsavedAnnotations:mg}});function gg(e){var t,n;return!!(null!==(t=e.user)&&void 0!==t&&t.username||null!==(n=e.user)&&void 0!==n&&n.userid)}function vg(e){if(!gg(e))return{};const t=e.user.username||e.user.userid||"";return{user:{value:t,display:e.user.displayName||t}}}const yg={
|
|
638
|
+
CHANGE_FOCUS_MODE_USER:function(e,t){return{focusActive:gg({user:t.user}),focusFilters:vg({user:t.user})}},SET_FILTER:function(e,t){var n;const r={...e.filters,[t.filterName]:t.filterOption};return""===(null===(n=t.filterOption)||void 0===n?void 0:n.value)&&delete r[t.filterName],{filters:r}},SET_FILTER_QUERY:function(e,t){return{query:t.query}},SET_FOCUS_MODE:function(e,t){var n;return{focusActive:null!==(n=t.active)&&void 0!==n?n:!e.focusActive}},CLEAR_SELECTION:function(){return{filters:{},focusActive:!1,query:null}}},_g=Jm(yg);const bg=qf((e=>e.focusActive),(e=>e.focusFilters),((e,t)=>{var n;return{active:e,configured:!(null==t||!t.user),displayName:(null==t||null===(n=t.user)||void 0===n?void 0:n.display)||""}})),wg=qf((e=>e.filters),(e=>e.focusActive),(e=>e.focusFilters),((e,t,n)=>t?{...n,...e}:{...e}));const xg=qf((e=>wg(e)),(e=>{const t={};return Object.keys(e).forEach((n=>t[n]=e[n].value)),t}));const kg=Of((function(e){const t=e.focus||{};return{filters:{},focusActive:gg(t),focusFilters:vg(t),
|
|
639
|
+
query:e.query||null}}),{namespace:"filters",reducers:yg,actionCreators:{changeFocusModeUser:function(e){return{type:_g.CHANGE_FOCUS_MODE_USER,user:e}},setFilter:function(e,t){return(n,r)=>{var o;null!==(o=r().filters.focusFilters)&&void 0!==o&&o[e]&&n({type:_g.SET_FOCUS_MODE,active:!1}),n({type:_g.SET_FILTER,filterName:e,filterOption:t})}},setFilterQuery:function(e){return{type:_g.SET_FILTER_QUERY,query:e}},toggleFocusMode:function(e){return{type:_g.SET_FOCUS_MODE,active:e}}},selectors:{filterQuery:function(e){return e.query},focusState:bg,getFilter:function(e,t){return wg(e)[t]},getFilters:wg,getFilterValues:xg,getFocusFilters:function(e){return e.focusFilters},hasAppliedFilter:function(e){return!(!e.query&&!Object.keys(wg(e)).length)}}}),Sg={CONNECT_FRAME:function(e,t){return[...e,t.frame]},DESTROY_FRAME:function(e,t){return e.filter((e=>e!==t.frame))},UPDATE_FRAME_ANNOTATION_FETCH_STATUS:function(e,t){return e.map((e=>e.uri&&e.uri===t.uri?Object.assign({},e,{
|
|
640
|
+
isAnnotationFetchComplete:t.isAnnotationFetchComplete}):e))}},Cg=Jm(Sg);const Ag=qf((e=>e),(e=>e.find((e=>!e.id))||null));const Eg=Hf(Ff,qm)((e=>e.reduce(((e,t)=>e.concat(function(e){let t=[e.uri];return e.metadata&&e.metadata.documentFingerprint&&(t=e.metadata.link.map((e=>e.href))),e.metadata&&e.metadata.link&&e.metadata.link.forEach((e=>{e.href.startsWith("doi:")&&t.push(e.href)})),t}(t))),[])),(e=>e)),Tg=Of([],{namespace:"frames",reducers:Sg,actionCreators:{connectFrame:function(e){return{type:Cg.CONNECT_FRAME,frame:e}},destroyFrame:function(e){return{type:Cg.DESTROY_FRAME,frame:e}},updateFrameAnnotationFetchStatus:function(e,t){return{type:Cg.UPDATE_FRAME_ANNOTATION_FETCH_STATUS,isAnnotationFetchComplete:t,uri:e}}},selectors:{frames:function(e){return e},mainFrame:Ag,searchUris:Eg}}),Ng={features:{},preferences:{},userid:null};const Lg={UPDATE_PROFILE:function(e,t){return{profile:{...t.profile}}}},Mg=Jm(Lg);const zg=Of((function(e){var t;return{
|
|
641
|
+
defaultAuthority:null!==(t=null==e?void 0:e.authDomain)&&void 0!==t?t:"",profile:Ng}}),{namespace:"session",reducers:Lg,actionCreators:{updateProfile:function(e){return{type:Mg.UPDATE_PROFILE,profile:e}}},selectors:{defaultAuthority:function(e){return e.defaultAuthority},hasFetchedProfile:function(e){return e.profile!==Ng},isFeatureEnabled:function(e,t){return!!e.profile.features[t]},isLoggedIn:function(e){return null!==e.profile.userid},profile:function(e){return e.profile}}}),Og={FILTER_GROUPS(e,t){var n;if(null===(n=t.filteredGroupIds)||void 0===n||!n.length)return{filteredGroupIds:null};const r=e.groups.filter((e=>t.filteredGroupIds.includes(e.id)));if(!r.length)return{filteredGroupIds:null};let o=e.focusedGroupId;return o&&t.filteredGroupIds.includes(o)||(o=r[0].id),{filteredGroupIds:t.filteredGroupIds,focusedGroupId:o}},FOCUS_GROUP(e,t){const n=e.groups.find((e=>e.id===t.id));return n?{focusedGroupId:t.id}:(console.error(`Attempted to focus group ${t.id} which is not loaded`),{})},LOAD_GROUPS(e,t){
|
|
642
|
+
const n=t.groups;let r=e.focusedGroupId;return null!==e.focusedGroupId&&n.find((t=>t.id===e.focusedGroupId))||(r=n.length>0?n[0].id:null),{focusedGroupId:r,groups:t.groups}},CLEAR_GROUPS:()=>({filteredGroupIds:null,focusedGroupId:null,groups:[]})},Ig=Jm(Og);function Rg(e){return e.filteredGroupIds?e.groups.filter((t=>{var n;return null===(n=e.filteredGroupIds)||void 0===n?void 0:n.includes(t.id)})):e.groups}function Pg(e,t){return e.groups.find((e=>e.id===t))}const Dg=qf((e=>Rg(e)),(e=>e.filter((e=>!e.isMember&&e.isScopedToUri)))),Bg=qf((e=>Rg(e)),(e=>e.filter((e=>e.isScopedToUri)))),Fg=qf((e=>Rg(e.groups)),(e=>zg.selectors.isLoggedIn(e.session)),((e,t)=>t?e.filter((e=>e.isMember)):[])),jg=qf((e=>Rg(e.groups)),(e=>Fg(e)),(e=>Dg(e.groups)),((e,t,n)=>e.filter((e=>!t.includes(e)&&!n.includes(e))))),Hg=Of({filteredGroupIds:null,groups:[],focusedGroupId:null},{namespace:"groups",reducers:Og,actionCreators:{filterGroups:function(e){return{type:Ig.FILTER_GROUPS,filteredGroupIds:e}},focusGroup:function(e){return{
|
|
643
|
+
type:Ig.FOCUS_GROUP,id:e}},loadGroups:function(e){return{type:Ig.LOAD_GROUPS,groups:e}},clearGroups:function(){return{type:Ig.CLEAR_GROUPS}}},selectors:{allGroups:function(e){return e.groups},filteredGroups:Rg,filteredGroupIds:function(e){return e.filteredGroupIds},focusedGroup:function(e){return e.focusedGroupId?Pg(e,e.focusedGroupId):null},focusedGroupId:function(e){return e.focusedGroupId},getFeaturedGroups:Dg,getGroup:Pg,getInScopeGroups:Bg},rootSelectors:{getCurrentlyViewingGroups:jg,getMyGroups:Fg}}),qg={UPDATE_LINKS:(e,t)=>({...t.links})},Ug=Jm(qg);const $g=Of(null,{namespace:"links",reducers:qg,actionCreators:{updateLinks:function(e){return{type:Ug.UPDATE_LINKS,links:e}}},selectors:{getLink:function(e,t,n={}){if(!e)return"";const r=e[t];if(!r)throw new Error(`Unknown link "${t}"`);const{url:o,unusedParams:i}=Tm(r,n),a=Object.keys(i);if(a.length>0)throw new Error(`Unused parameters: ${a.join(", ")}`);return o}}}),Gg={RECEIVE_REAL_TIME_UPDATES:(e,t)=>({pendingUpdates:{...t.pendingUpdates},
|
|
644
|
+
pendingDeletions:{...t.pendingDeletions}}),CLEAR_PENDING_UPDATES:()=>({pendingUpdates:{},pendingDeletions:{}}),ADD_ANNOTATIONS(e,{annotations:t}){const n={...e.pendingUpdates};return t.forEach((e=>delete n[e.id])),{pendingUpdates:n}},REMOVE_ANNOTATIONS(e,{annotationsToRemove:t}){const n={...e.pendingUpdates},r={...e.pendingDeletions};return t.forEach((e=>{delete n[e.id],delete r[e.id]})),{pendingUpdates:n,pendingDeletions:r}},FOCUS_GROUP:()=>({pendingUpdates:{},pendingDeletions:{}})},Vg=Jm(Gg);const Wg=qf((e=>[e.pendingUpdates,e.pendingDeletions]),(([e,t])=>Object.keys(e).length+Object.keys(t).length));const Yg=Of({pendingUpdates:{},pendingDeletions:{}},{namespace:"realTimeUpdates",reducers:Gg,actionCreators:{receiveRealTimeUpdates:function({updatedAnnotations:e=[],deletedAnnotations:t=[]}){return(n,r)=>{const o={...r().realTimeUpdates.pendingUpdates},i={...r().realTimeUpdates.pendingDeletions};e.forEach((e=>{const t=r().groups,n=r().route
|
|
645
|
+
;e.group!==Hg.selectors.focusedGroupId(t)&&"sidebar"===Yf.selectors.route(n)||(o[e.id]=e)})),t.forEach((e=>{const t=e.id;delete o[t];const n=r().annotations;tg.selectors.annotationExists(n,t)&&(i[t]=!0)})),n({type:Vg.RECEIVE_REAL_TIME_UPDATES,pendingUpdates:o,pendingDeletions:i})}},clearPendingUpdates:function(){return{type:Vg.CLEAR_PENDING_UPDATES}}},selectors:{hasPendingDeletion:function(e,t){return e.pendingDeletions.hasOwnProperty(t)},pendingDeletions:function(e){return e.pendingDeletions},pendingUpdates:function(e){return e.pendingUpdates},pendingUpdateCount:Wg}}),Kg={annotation:"Location",note:"Oldest",orphan:"Location"};function Xg(e){const t={};return e.annotations&&!e.query&&(t[e.annotations]=!0),t}const Zg=(e,t)=>t===e?{}:{selectedTab:e,sortKey:Kg[e]},Jg={CLEAR_SELECTION:function(){return{forcedVisible:{},selected:{}}},SELECT_ANNOTATIONS:function(e,t){return{selected:t.selection}},SELECT_TAB:function(e,t){return Zg(t.tab,e.selectedTab)},SET_EXPANDED:function(e,t){const n={...e.expanded}
|
|
646
|
+
;return n[t.id]=t.expanded,{expanded:n}},SET_FORCED_VISIBLE:function(e,t){return{forcedVisible:{...e.forcedVisible,[t.id]:t.visible}}},SET_SORT_KEY:function(e,t){return{sortKey:t.key}},TOGGLE_SELECTED_ANNOTATIONS:function(e,t){const n={...e.selected};return t.toggleIds.forEach((e=>{n[e]=!n[e]})),{selected:n}},ADD_ANNOTATIONS(e,t){const n=t.annotations.filter((e=>!ki(e))),r=Uf(t.annotations,Mi)===n.length;return 0===t.currentAnnotationCount&&r?Zg("note",e.selectedTab):{}},CHANGE_FOCUS_MODE_USER:function(){return{forcedVisible:{},selected:{}}},SET_FILTER:function(){return{forcedVisible:{},selected:{},expanded:{}}},SET_FILTER_QUERY:function(){return{forcedVisible:{},selected:{},expanded:{}}},SET_FOCUS_MODE:function(){return{forcedVisible:{},selected:{}}},REMOVE_ANNOTATIONS:function(e,t){let n=e.selectedTab;"orphan"===n&&0===Uf(t.remainingAnnotations,Li)&&(n="annotation");const r=e=>(t.annotationsToRemove.forEach((t=>{t.id&&delete e[t.id],t.$tag&&delete e[t.$tag]})),e);return{...Zg(n,e.selectedTab),expanded:r({
|
|
647
|
+
...e.expanded}),forcedVisible:r({...e.forcedVisible}),selected:r({...e.selected})}}},Qg=Jm(Jg);function ev(e){return e.expanded}const tv=qf((e=>e.forcedVisible),(e=>Gf(e))),nv=qf((e=>e.selected),(e=>Gf(e).length>0)),rv=qf((e=>e.selected),(e=>Gf(e)));function ov(e){return e.selectedTab}const iv=qf((e=>e),(e=>({expanded:ev(e),forcedVisible:tv(e),selected:rv(e),sortKey:av(e),selectedTab:ov(e)})));function av(e){return e.sortKey}const sv=qf((e=>e.selectedTab),(e=>{const t=["Newest","Oldest"];return"note"!==e&&t.push("Location"),t})),lv=Of((function(e){return{selected:Xg(e),expanded:Xg(e)||{},forcedVisible:{},selectedTab:"annotation",sortKey:Kg.annotation}}),{namespace:"selection",reducers:Jg,actionCreators:{clearSelection:function(){return{type:Qg.CLEAR_SELECTION}},selectAnnotations:function(e){return t=>{t({type:Qg.CLEAR_SELECTION}),t({type:Qg.SELECT_ANNOTATIONS,selection:$f(e)})}},selectTab:function(e){return{type:Qg.SELECT_TAB,tab:e}},setExpanded:function(e,t){return{type:Qg.SET_EXPANDED,id:e,expanded:t}},
|
|
648
|
+
setForcedVisible:function(e,t){return{type:Qg.SET_FORCED_VISIBLE,id:e,visible:t}},setSortKey:function(e){return{type:Qg.SET_SORT_KEY,key:e}},toggleSelectedAnnotations:function(e){return{type:Qg.TOGGLE_SELECTED_ANNOTATIONS,toggleIds:e}}},selectors:{expandedMap:ev,forcedVisibleThreads:tv,hasSelectedAnnotations:nv,selectedAnnotations:rv,selectedTab:ov,selectionState:iv,sortKey:av,sortKeys:sv}}),cv={OPEN_SIDEBAR_PANEL:function(e,t){return{activePanelName:t.panelName}},CLOSE_SIDEBAR_PANEL:function(e,t){let n=e.activePanelName;return t.panelName===n&&(n=null),{activePanelName:n}},TOGGLE_SIDEBAR_PANEL:function(e,t){let n;const r=e.activePanelName===t.panelName,o=void 0!==t.panelState?t.panelState:!r;return n=o?t.panelName:r&&!o?null:e.activePanelName,{activePanelName:n}}},uv=Jm(cv);const hv=Of({activePanelName:null},{namespace:"sidebarPanels",reducers:cv,actionCreators:{openSidebarPanel:function(e){return{type:uv.OPEN_SIDEBAR_PANEL,panelName:e}},closeSidebarPanel:function(e){return{type:uv.CLOSE_SIDEBAR_PANEL,
|
|
649
|
+
panelName:e}},toggleSidebarPanel:function(e,t){return{type:uv.TOGGLE_SIDEBAR_PANEL,panelName:e,panelState:t}}},selectors:{isSidebarPanelOpen:function(e,t){return e.activePanelName===t}}}),dv={ADD_MESSAGE:function(e,t){return{messages:e.messages.concat({...t.message})}},REMOVE_MESSAGE:function(e,t){return{messages:e.messages.filter((e=>e.id!==t.id))}},UPDATE_MESSAGE:function(e,t){return{messages:e.messages.map((e=>e.id&&e.id===t.message.id?{...t.message}:e))}}},pv=Jm(dv);const mv=Of({messages:[]},{namespace:"toastMessages",reducers:dv,actionCreators:{addToastMessage:function(e){return{type:pv.ADD_MESSAGE,message:e}},removeToastMessage:function(e){return{type:pv.REMOVE_MESSAGE,id:e}},updateToastMessage:function(e){return{type:pv.UPDATE_MESSAGE,message:e}}},selectors:{getToastMessage:function(e,t){return e.messages.find((e=>e.id===t))},getToastMessages:function(e){return e.messages},hasToastMessage:function(e,t,n){return e.messages.some((e=>e.type===t&&e.message===n))}}}),fv={
|
|
650
|
+
SET_SIDEBAR_OPENED:(e,t)=>!0===t.opened?{sidebarHasOpened:!0}:{}},gv=Jm(fv);const vv=Of({sidebarHasOpened:!1},{namespace:"viewer",reducers:fv,actionCreators:{setSidebarOpened:function(e){return{type:gv.SET_SIDEBAR_OPENED,opened:e}}},selectors:{hasSidebarOpened:function(e){return e.sidebarHasOpened}}});function yv(e){return zf([Df,tg,og,sg,fg,kg,Tg,$g,Hg,Yg,Yf,lv,zg,hv,mv,vv],[e],[If])}yv.$inject=["settings"];class _v{constructor(){this._providers=new Map,this._instances=new Map,this._constructing=new Set}get(e){if(this._instances.has(e))return this._instances.get(e);const t=this._providers.get(e);if(!t)throw new Error(`"${e}" is not registered`);if("value"in t)return this._instances.set(e,t.value),t.value;if(this._constructing.has(e))throw new Error(`Encountered a circular dependency when constructing "${e}"`);this._constructing.add(e);try{const n=[],r="class"in t&&t.class.$inject||"factory"in t&&t.factory.$inject||[];for(const t of r)try{n.push(this.get(t))}catch(n){
|
|
651
|
+
const r=new Error(`Failed to construct dependency "${t}" of "${e}": ${n.message}`);throw r.cause=n,r}let o;if(t.class)o=new t.class(...n);else{o=(0,t.factory)(...n)}return this._instances.set(e,o),o}finally{this._constructing.delete(e)}}register(e,t){if("function"==typeof t)t={class:t};else if(!function(e){return"object"==typeof e&&null!==e&&("value"in e||"function"==typeof e.class||"function"==typeof e.factory)}(t))throw new Error(`Invalid provider for "${e}"`);return this._providers.set(e,t),this}run(e){const t="Injector.run";this.register(t,{factory:e});try{return this.get(t)}finally{this._instances.delete(t),this._providers.delete(t)}}}const bv=function(t){for(var n={},r=t.querySelectorAll("script.js-hypothesis-config"),o=0;o<r.length;o++){var i=void 0;try{i=JSON.parse(r[o].textContent||"")}catch(e){console.warn("Could not parse settings from js-hypothesis-config tags",e),i={}}e(n,i)}return n}(document),wv=function(e){const{version:t,origin:n}=R(e.location.href)
|
|
652
|
+
;return"1.981.0"!==t?(console.warn(`The Hypothesis sidebar is using a different version (1.981.0) than the host page (${t}). It may not work.`),!1):"null"===e.origin?(console.warn("Hypothesis has been loaded in a sandboxed frame. This is not supported."),!1):e.origin===n||(console.warn(`The Hypothesis sidebar is running in a different origin (${e.origin}) than expected (${n}). It may not work.`),!1)}(window);function xv(e,t){e.setClientId(t.clientId)}function kv(e,t,n){e.load(),t.load(),n.sync()}function Sv(e,t,n,r){e.init(),t.init(),n.init(),r.init()}function Cv(e,t){"sidebar"===t.route()&&e.connect()}bv.sentry&&wv&&function(e){const t=function(){let e=import.meta.url;return e?new URL(e).origin:null}(),n=t?[t]:void 0;wr({dsn:e.dsn,environment:e.environment,allowUrls:n,ignoreErrors:["Network request failed","Object Not Found Matching Id"],release:"1.981.0",beforeSend:(e,t)=>{if(Sr>=5)return K("Client-side Sentry quota reached. No further Sentry events will be sent"),null;++Sr;try{
|
|
653
|
+
const n=t&&t.originalException;n instanceof Event&&Object.assign(e.extra,{type:n.type,detail:n.detail,isTrusted:n.isTrusted})}catch(e){}return e}});try{Yt("host_config",R(window.location.href))}catch(e){}Yt("loaded_scripts",Array.from(document.querySelectorAll("script")).filter((e=>!e.type||e.type.match(/javascript|module/))).map((e=>e.src||"<inline>"))),kr(((e,t)=>{Wt(e,{tags:{context:t}})}))}(bv.sentry),function(e){e.addEventListener("click",(e=>{const t=e.target;if("A"===t.tagName){const e=t;"_blank"===e.target&&(e.rel="noopener")}}))}(document.body),function(e=n){let t=!1;try{document.createElement("div").dir="auto"}catch(e){t=!0}if(t){const t=e.vnode;e.vnode=e=>{"string"==typeof e.type&&"dir"in e.props&&"auto"===e.props.dir&&(e.props.dir=""),t&&t(e)}}}(),xv.$inject=["api","streamer"],kv.$inject=["groups","session","router"],Sv.$inject=["autosaveService","features","persistedDefaults","serviceURL"],Cv.$inject=["frameSync","store"],function(e,{reset:t=!1}={}){t&&mo.clear()
|
|
654
|
+
;for(let[t,n]of Object.entries(e))mo.set(t,n)}(Ko);const Av=document.querySelector("hypothesis-app");!function(e=window){e.addEventListener("message",te)}(),async function(e,t=window){const n=H(window),r=n.requestConfigFromFrame;if(!r)return V(e,n);if("string"==typeof r)return await G(e,t);if("number"==typeof r.ancestorLevel&&"string"==typeof r.origin){const o=function(e,t=window){let n=t;for(let t=0;t<e;t++){if(n===n.top)throw new Error("The target parent frame has exceeded the ancestor tree. Try reducing the `requestConfigFromFrame.ancestorLevel` value in the `hypothesisConfig`");n=n.parent}return n}(r.ancestorLevel,t);return{...await W(e,o,r.origin),...n.group?{group:n.group}:{}}}throw new Error("Improper `requestConfigFromFrame` object. Both `ancestorLevel` and `origin` need to be specified")}(bv).then((e=>{!function(e,t){const n=new _v
|
|
655
|
+
;n.register("annotationsService",Cm).register("api",Lm).register("apiRoutes",Dm).register("auth",jm).register("autosaveService",Hm).register("features",$m).register("frameSync",Zm).register("groups",tf).register("loadAnnotationsService",nf).register("localStorage",of).register("persistedDefaults",sf).register("router",lf).register("serviceURL",cf).register("session",uf).register("streamer",pf).register("streamFilter",hf).register("tags",mf).register("threadsService",ff).register("toastMessenger",gf).register("store",{factory:yv}),n.register("$window",{value:window}).register("settings",{value:e}),n.run(Sv),n.run(xv),n.run(kv),n.run(ee),n.run(Cv),I(po(ni.Provider,{value:n,children:po(km,{})}),t)}(e,Av)})).catch((e=>function(e,t){console.error("Failed to start Hypothesis client: ",e),I(po(Sm,{error:e}),t)}(e,Av)));
|
|
656
656
|
//# sourceMappingURL=sidebar.bundle.js.map
|