@hazem3500/palette 0.9.119 → 0.9.121

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.
@@ -20,6 +20,8 @@ export type WebhookEvent = {
20
20
  author: string;
21
21
  body: string | null;
22
22
  snapshotStatus?: "pending" | "skipped";
23
+ /** Present and false when the reviewer chose to keep this comment in Palette. */
24
+ share?: false;
23
25
  };
24
26
 
25
27
  export type WebhookEnv = {
package/src/types.ts CHANGED
@@ -356,6 +356,13 @@ export interface CommentsOptions {
356
356
  * never captured, nor is anything inside an element with data-palette-no-snapshot (or the older data-komo-no-snapshot).
357
357
  */
358
358
  snapshots?: PaletteSnapshots;
359
+ /**
360
+ * Let reviewers keep new comments out of an integration fed by the project's
361
+ * webhooks, e.g. { label: "Post to the GitHub PR" }. Shows an account default and
362
+ * a per-comment toggle; a comment kept in Palette is delivered with `share: false`.
363
+ * Needs a server that advertises `share` in /config. Off by default.
364
+ */
365
+ share?: { label: string };
359
366
  }
360
367
 
361
368
  export interface CommentsController {
@@ -363,6 +370,8 @@ export interface CommentsController {
363
370
  comment(element: Element): void;
364
371
  destroy(): void;
365
372
  open(): void;
373
+ /** Bring back a toolbar the reviewer dismissed, without opening the sidebar. */
374
+ restore(): void;
366
375
  close(): void;
367
376
  refresh(): Promise<void>;
368
377
  }
@@ -1 +0,0 @@
1
- function e(e){return!!e&&"string"==typeof e.id&&"string"==typeof e.name&&"boolean"==typeof e.verified&&[e.avatarUrl,e.accentColor].every(e=>void 0===e||"string"==typeof e)}function t(t){return Array.isArray(t)&&t.every(t=>t&&"string"==typeof t.id&&"string"==typeof t.page&&"boolean"==typeof t.resolved&&Number.isFinite(t.createdAt)&&Number.isFinite(t.updatedAt)&&(null===t.resolvedBy||e(t.resolvedBy))&&t.anchor&&(!("context"in t.anchor)||function(e){if(void 0===e)return!0;if(!e||"object"!=typeof e||Array.isArray(e))return!1;let t={tag:32,role:80,label:160,nearby:160,classes:200,selectedText:200,styles:500,scope:2e3};return Object.entries(e).every(([e,s])=>"number"==typeof t[e]&&"string"==typeof s&&s.length<=t[e])}(t.anchor.context))&&"string"==typeof t.anchor.selector&&"string"==typeof t.anchor.text&&[t.anchor.x,t.anchor.y,t.anchor.width,t.anchor.height,t.anchor.pageX,t.anchor.pageY,t.anchor.viewportWidth].every(Number.isFinite)&&Array.isArray(t.comments)&&t.comments.every(t=>t&&"string"==typeof t.id&&"string"==typeof t.body&&e(t.author)&&Number.isFinite(t.createdAt)&&(null===t.editedAt||Number.isFinite(t.editedAt))&&t.reactions&&"object"==typeof t.reactions&&!Array.isArray(t.reactions)&&Object.values(t.reactions).every(e=>Array.isArray(e)&&e.every(e=>"string"==typeof e))))}function s(e,t){if(!t||!Array.isArray(e))return e;let s=e=>"string"==typeof e?Object.hasOwn(t,e)?t[e]:void 0:e;return e.map(e=>e&&{...e,resolvedBy:s(e.resolvedBy),comments:Array.isArray(e.comments)&&e.comments.map(e=>e&&{...e,author:s(e.author)})})}function o(){return new r(0,"Could not read comments. Try again.","invalid_response")}var r,i;import{a as n,c as a}from"./chunk-5HZI7HRR.js";r=class extends Error{constructor(e,t,s){super(t),this.status=e,this.code=s}status;code},i=class{constructor(t){this.options=t;let s=new URL(t.sessionEndpoint??t.endpoint).href.replace(/\/$/,""),o=t.sessionDomain?.replace(/^\./,"")??"";this.cookieDomain=o&&(location.hostname===o||location.hostname.endsWith(`.${o}`))?o:"",this.cookieName=`${this.cookieDomain?"__Secure-":"__Host-"}bc-session-${encodeURIComponent(JSON.stringify([s,t.project]))}`,this.key=`palette:${t.endpoint}:${t.project}`;let r=!1;try{let e=document.cookie.split("; ").find(e=>e.startsWith(`${this.cookieName}=`));r=void 0!==e,this.token=e?.slice(this.cookieName.length+1)||null}catch{}try{let t;try{t=JSON.parse(localStorage.getItem(this.userKey)??"null")}catch{}let s=localStorage.getItem(this.key)??(e(t?.user)&&"string"==typeof t.token?t.token:null);r?!this.token&&s&&this.clear():this.token=s,this.token&&t?.token===this.token&&e(t.user)&&(this.user=t.user)}catch{}try{let e=`bc-session-${encodeURIComponent(t.project)}`,s=location.hostname.match(/^[^.]+\.([^.]+\.(?:workers|pages)\.dev)$/)?.[1];for(let t of new Set(["",this.cookieDomain,s]))void 0!==t&&(document.cookie=`${e}=; Max-Age=0; Path=/${t?`; Domain=${t}`:""}`)}catch{}}options;token=null;user=null;transient=!1;revision;cachedThreads=[];reads=new AbortController;persistenceQueued=!1;persistenceBlocked=!1;key;cookieName;cookieDomain;get sessionKey(){return this.key}get userKey(){return`${this.key}:user`}rememberUser(){try{this.token&&this.user?localStorage.setItem(this.userKey,JSON.stringify({token:this.token,user:this.user})):a(localStorage,this.userKey)}catch{}}cancelReads(){this.reads.abort(),this.reads=new AbortController}async request(e,t="GET",s,i){let n=new URL(e,this.options.endpoint.replace(/\/?$/,"/"));n.searchParams.set("project",this.options.project),n.searchParams.set("repo",this.options.repo),n.searchParams.set("branch",this.options.branch);let a={},h=this.token;h&&(a.Authorization=`Bearer ${h}`),void 0!==s&&(a["Content-Type"]=i??"application/json");let c="GET"===t?this.reads.signal:void 0,l=AbortSignal.timeout(15e3),u=await fetch(n,{method:t,headers:a,body:void 0===s?void 0:i?s:JSON.stringify(s),credentials:"omit",cache:"no-store",signal:c?AbortSignal.any([c,l]):l}).catch(e=>{throw e instanceof TypeError?!1===navigator.onLine?new r(0,"You’re offline.","offline"):new r(0,"Can’t connect to comments.","unreachable"):e});c?.throwIfAborted();let d=await u.json().catch(()=>{if(c?.throwIfAborted(),u.ok)throw o();return{}});if(c?.throwIfAborted(),u.ok&&(!d||"object"!=typeof d||Array.isArray(d)))throw o();if(!u.ok)throw 401===u.status&&h&&this.token===h&&this.clear(),new r(u.status,"site_not_approved"===d?.code?"Comments aren’t turned on for this site yet.":d?.error??"Could not load comments.",d?.code);return d}get listKey(){return`${this.key}:${JSON.stringify([this.options.repo,this.options.branch])}:threads`}cached(){try{let e=JSON.parse(localStorage.getItem(this.listKey)??"null");return e&&(e.threads=s(e.threads,e.authors)),e?.token!==(this.token??"")||!t(e.threads)||void 0!==e.revision&&(!Number.isSafeInteger(e.revision)||e.revision<0)?null:(this.revision=e.revision,this.cachedThreads=e.threads,e.threads)}catch{return null}}persist(){this.persistenceQueued||this.persistenceBlocked||(this.persistenceQueued=!0,queueMicrotask(()=>{this.persistenceQueued=!1;try{let e=Object.create(null),t=[],s=0,o=!1,r=this.options.page?.()??location.pathname,i=[...this.cachedThreads].sort((e,t)=>+(t.page===r)-+(e.page===r));for(let r of i){let i=Object.create(null),n=t=>(t&&(i[t.id]={...e[t.id],...i[t.id],...t}),t?.id??null),a={...r,resolvedBy:n(r.resolvedBy),comments:r.comments.map(e=>({...e,author:n(e.author)}))},h=JSON.stringify(a).length+Object.entries(i).reduce((t,[s,o])=>t+JSON.stringify([s,o]).length-(e[s]?JSON.stringify([s,e[s]]).length:0),0)+2;s+h>25e4?o=!0:(s+=h,Object.assign(e,i),t.push(a))}if(o&&!t.length)return void a(localStorage,this.listKey);localStorage.setItem(this.listKey,JSON.stringify({token:this.token??"",revision:o?void 0:this.revision,threads:t,authors:e}))}catch{this.persistenceBlocked=!0;try{a(localStorage,this.listKey)}catch{}}}))}async list(){let e,i,n=this.token,a=this.reads.signal,h=[],c=0;for(;null!==c;){let l=await this.request(`threads?authors=1&offset=${c}${e?`&cursor=${encodeURIComponent(e)}`:""}${0===c&&void 0!==this.revision?`&revision=${this.revision}`:""}`).catch(e=>{throw e instanceof r&&403===e.status&&this.token===n&&(this.revision=void 0,this.cachedThreads=[],this.persist()),e});if(a.throwIfAborted(),l.threads=s(l.threads,l.authors),!0===l.notModified&&0===c&&void 0!==this.revision)return this.cachedThreads;if(!t(l.threads)||null!=l.nextCursor&&("string"!=typeof l.nextCursor||l.nextCursor.length>200||l.nextCursor===e)||void 0!==l.revision&&(!Number.isSafeInteger(l.revision)||l.revision<0)||null!=l.next&&(!Number.isSafeInteger(l.next)||l.next<=c))throw o();0===c&&(i=l.revision),h.push(...l.threads??[]),e=l.nextCursor??void 0,c=l.next??null}return this.revision=i,this.cachedThreads=h,this.persist(),h}save(e){e.token!==this.token&&(this.cancelReads(),this.revision=void 0,this.cachedThreads=[]),this.token=e.token,this.user=e.user,this.rememberUser();let t=!1;try{localStorage.setItem(this.key,e.token),t=!0}catch{}this.transient=!this.writeCookie(e.token,3456e4)&&!t}writeCookie(e,t){if("https:"!==location.protocol)return;let s="Path=/; SameSite=Lax; Secure";try{return this.cookieDomain&&(document.cookie=`${this.cookieName}=; Max-Age=0; ${s}`),document.cookie=`${this.cookieName}=${e}; Max-Age=${t}; ${s}${this.cookieDomain?`; Domain=${this.cookieDomain}`:""}`,document.cookie.split("; ").includes(`${this.cookieName}=${e}`)}catch{}}clear(){this.cancelReads();try{a(localStorage,this.listKey);let e=n(this.key);for(let t of Object.keys(localStorage))(t.startsWith(`${this.key}:`)||e&&t.startsWith(`${e}:`))&&localStorage.removeItem(t)}catch{}this.revision=void 0,this.cachedThreads=[],this.token=null,this.user=null,this.transient=!1,this.rememberUser(),this.writeCookie("",3456e4);try{a(localStorage,this.key)}catch{}}async restore(){if(!this.token)return;let t=this.token,s=await this.request("me");if(this.token===t){if(!e(s.user))throw o();this.save({token:t,user:s.user})}}async guest(e){this.save(await this.request("auth/guest","POST",{name:e}))}async logout(){let e=this.request("me","DELETE");this.clear(),await e}};export{r as a,i as b};