@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.
- package/NODE.md +12 -0
- package/README.md +3 -2
- package/dist/{account-tokens-ZXA2HQS4.js → account-tokens-W2SBGBUW.js} +1 -1
- package/dist/api.d.ts +2 -0
- package/dist/chunk-HC3P6VXJ.js +1 -0
- package/dist/chunk-HHUTDVTM.js +1 -0
- package/dist/index.js +1 -1
- package/dist/node.mjs +35 -5
- package/dist/{onboarding-6OSADOWE.js → onboarding-WNFR5RLQ.js} +1 -1
- package/dist/postgres/009_user_share_comments.sql +2 -0
- package/dist/react.js +1 -1
- package/dist/server.js +33 -4
- package/dist/setup.js +1 -1
- package/dist/shell-mode-I5OAFZVD.js +1 -0
- package/dist/shell-mode.d.ts +4 -3
- package/dist/types.d.ts +11 -0
- package/package.json +1 -1
- package/server/index.ts +42 -3
- package/server/migrations/0023_user_share_comments.sql +3 -0
- package/server/setup-client.txt +81 -72
- package/server/webhooks.ts +2 -0
- package/src/types.ts +9 -0
- package/dist/chunk-DU7H4TEX.js +0 -1
- package/dist/chunk-UCK64LMS.js +0 -1
- package/dist/shell-mode-RPV7AVA4.js +0 -1
package/dist/setup.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as n,d as o}from"./chunk-
|
|
1
|
+
import{a as n,d as o}from"./chunk-HC3P6VXJ.js";import"./chunk-KLPQTFVH.js";import"./chunk-RBHY7UDS.js";import"./chunk-LMXFSXO6.js";import"./chunk-HHUTDVTM.js";import"./chunk-5HZI7HRR.js";import"./chunk-2BS2OWWH.js";import"./chunk-J47R52WX.js";import"./chunk-VX6XCU4E.js";import"./chunk-4HBBEVFK.js";function r(r){return(t={})=>o(n({...r,...t}))}var t=r;export{t as defineKomo,r as definePalette};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var e="palette-shell",t="palette:shell";function o(t,o){let a=new URL(t,location.href);return a.searchParams.delete("komo-shell"),o?a.searchParams.set(e,o):a.searchParams.delete(e),a.href}function a(e,a=""){try{sessionStorage.removeItem(t),sessionStorage.removeItem("komo:shell"),a&&sessionStorage.setItem("palette:shell-off",a)}catch{}location.replace(o(e,""))}function l(e,a,l,r){try{let n=sessionStorage.getItem("palette:shell-off");if(n)return r(n);if(a&&l&&!confirm("Reload in Frame?\n\nUnposted Design changes will be lost."))return r("Reload cancelled.");let s=Array.from(crypto.getRandomValues(new Uint8Array(16)),e=>e.toString(16).padStart(2,"0")).join("");sessionStorage.setItem(t,JSON.stringify({v:1,project:e,nonce:s,origin:location.origin})),location.replace(o(location.href,s))}catch{return r("Storage blocked.")}setTimeout(r,3e3,"Reload cancelled.")}function r(e,t){try{let a=e.location.href,l=o(a,t);a.startsWith(location.origin)&&l!==location.href&&history.replaceState(history.state,"",l)}catch{}}export{l as enterShell,a as leaveShellPage,o as shellUrl,r as syncShell};
|
package/dist/shell-mode.d.ts
CHANGED
|
@@ -3,9 +3,10 @@ export declare function shellUrl(href: string, nonce: string): string;
|
|
|
3
3
|
/** Ends the shell: clears it, notes why when it ended early, and loads `href` as the normal page. */
|
|
4
4
|
export declare function leaveShellPage(href: string, reason?: string): void;
|
|
5
5
|
/**
|
|
6
|
-
* Reloads this page as the shell. `ask
|
|
7
|
-
*
|
|
8
|
-
*
|
|
6
|
+
* Reloads this page as the shell. With `ask`, it confirms only when `edited` (unposted
|
|
7
|
+
* Design changes would be lost); the app's own unsaved-changes guard covers app state.
|
|
8
|
+
* `fallback` runs when the reviewer cancels, storage is blocked, or the page didn't
|
|
9
|
+
* unload (that guard can keep it).
|
|
9
10
|
*/
|
|
10
11
|
export declare function enterShell(project: string, ask: boolean, edited: boolean, fallback: (reason: string) => void): void;
|
|
11
12
|
/** The shell's URL follows the frame's route, so reloading or sharing it keeps the page. */
|
package/dist/types.d.ts
CHANGED
|
@@ -346,12 +346,23 @@ export interface CommentsOptions {
|
|
|
346
346
|
* never captured, nor is anything inside an element with data-palette-no-snapshot (or the older data-komo-no-snapshot).
|
|
347
347
|
*/
|
|
348
348
|
snapshots?: PaletteSnapshots;
|
|
349
|
+
/**
|
|
350
|
+
* Let reviewers keep new comments out of an integration fed by the project's
|
|
351
|
+
* webhooks, e.g. { label: "Post to the GitHub PR" }. Shows an account default and
|
|
352
|
+
* a per-comment toggle; a comment kept in Palette is delivered with `share: false`.
|
|
353
|
+
* Needs a server that advertises `share` in /config. Off by default.
|
|
354
|
+
*/
|
|
355
|
+
share?: {
|
|
356
|
+
label: string;
|
|
357
|
+
};
|
|
349
358
|
}
|
|
350
359
|
export interface CommentsController {
|
|
351
360
|
/** Open a new comment anchored to an element. */
|
|
352
361
|
comment(element: Element): void;
|
|
353
362
|
destroy(): void;
|
|
354
363
|
open(): void;
|
|
364
|
+
/** Bring back a toolbar the reviewer dismissed, without opening the sidebar. */
|
|
365
|
+
restore(): void;
|
|
355
366
|
close(): void;
|
|
356
367
|
refresh(): Promise<void>;
|
|
357
368
|
}
|
package/package.json
CHANGED
package/server/index.ts
CHANGED
|
@@ -202,8 +202,10 @@ async function body(request: Request): Promise<Record<string, unknown>> {
|
|
|
202
202
|
? ["emoji", "active"]
|
|
203
203
|
: path === "/me"
|
|
204
204
|
? ["name", "avatarUrl", "accentColor"]
|
|
205
|
+
: path === "/me/settings"
|
|
206
|
+
? ["shareComments"]
|
|
205
207
|
: path === "/threads"
|
|
206
|
-
? ["body", "page", "anchor", "tags", "scope", "snapshotIntent"]
|
|
208
|
+
? ["body", "page", "anchor", "tags", "scope", "snapshotIntent", "share"]
|
|
207
209
|
: path.endsWith("/comments")
|
|
208
210
|
? ["body"]
|
|
209
211
|
: path.includes("/comments/")
|
|
@@ -241,6 +243,22 @@ async function limit(env: Env, key: string, max: number, seconds = 60) {
|
|
|
241
243
|
}
|
|
242
244
|
/** How a session was signed in, stored from D1 migration 0021 / PostgreSQL 007. */
|
|
243
245
|
type SessionVia = "proxy" | "google" | "github" | "guest";
|
|
246
|
+
/** Before migration 0023 (Postgres 009) every reviewer shares new comments. */
|
|
247
|
+
async function shareComments(env: Env, userId: string) {
|
|
248
|
+
try {
|
|
249
|
+
const row = await env.DB.prepare("SELECT share_comments FROM users WHERE id=?")
|
|
250
|
+
.bind(userId)
|
|
251
|
+
.first<{ share_comments: number | null }>();
|
|
252
|
+
return row?.share_comments !== 0;
|
|
253
|
+
} catch (error) {
|
|
254
|
+
if (missingShareColumn(error)) return true;
|
|
255
|
+
throw error;
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const missingShareColumn = (error: unknown) =>
|
|
259
|
+
error instanceof Error &&
|
|
260
|
+
/no such column|has no column named|column .* does not exist/i.test(error.message) &&
|
|
261
|
+
/share_comments/.test(error.message);
|
|
244
262
|
const missingSessionColumns = (error: unknown) =>
|
|
245
263
|
error instanceof Error &&
|
|
246
264
|
/no such column|has no column named|column .* does not exist/i.test(error.message) &&
|
|
@@ -1151,6 +1169,8 @@ async function route(
|
|
|
1151
1169
|
guestResolve: config.allowGuestResolve !== false,
|
|
1152
1170
|
tokens: !auth.proxy || auth.proxyAccessTokens,
|
|
1153
1171
|
// Element snapshots are opt-in on the client; guests need project consent.
|
|
1172
|
+
// Clients may send `share` on new threads and edit `/me/settings`.
|
|
1173
|
+
share: true,
|
|
1154
1174
|
snapshots: {
|
|
1155
1175
|
readiness: true,
|
|
1156
1176
|
guests: auth.allowGuests && config.allowGuestSnapshots === true,
|
|
@@ -1343,7 +1363,25 @@ async function route(
|
|
|
1343
1363
|
});
|
|
1344
1364
|
}
|
|
1345
1365
|
check(request.method === "GET", 405, "Method not allowed.");
|
|
1346
|
-
return json({ user });
|
|
1366
|
+
return json({ user, settings: { shareComments: await shareComments(env, user.id) } });
|
|
1367
|
+
}
|
|
1368
|
+
if (url.pathname === "/me/settings") {
|
|
1369
|
+
check(request.method === "PATCH", 405, "Method not allowed.");
|
|
1370
|
+
const user = await authenticate(request, env, project);
|
|
1371
|
+
const data = await body(request);
|
|
1372
|
+
check(typeof data.shareComments === "boolean", 400, "Invalid sharing setting.");
|
|
1373
|
+
try {
|
|
1374
|
+
await env.DB.prepare("UPDATE users SET share_comments=? WHERE id=?")
|
|
1375
|
+
.bind(data.shareComments ? 1 : 0, user.id)
|
|
1376
|
+
.run();
|
|
1377
|
+
} catch (error) {
|
|
1378
|
+
if (missingShareColumn(error))
|
|
1379
|
+
throw new ConfigError(
|
|
1380
|
+
"Saving the sharing setting needs D1 migration 0023_user_share_comments (Postgres 009). Apply the migrations."
|
|
1381
|
+
);
|
|
1382
|
+
throw error;
|
|
1383
|
+
}
|
|
1384
|
+
return json({ settings: { shareComments: data.shareComments } });
|
|
1347
1385
|
}
|
|
1348
1386
|
const access: PatAccess = request.method === "GET" ? "read" : "write";
|
|
1349
1387
|
// No anonymous reads. Behind a proxy, authenticate() accepts only sessions
|
|
@@ -1543,6 +1581,7 @@ async function route(
|
|
|
1543
1581
|
const firstCommentId = crypto.randomUUID();
|
|
1544
1582
|
check(data.snapshotIntent === undefined || typeof data.snapshotIntent === "boolean", 400, "Invalid snapshot intent.");
|
|
1545
1583
|
const snapshotStatus = data.snapshotIntent === undefined ? null : data.snapshotIntent ? "pending" : "skipped";
|
|
1584
|
+
check(data.share === undefined || typeof data.share === "boolean", 400, "Invalid sharing choice.");
|
|
1546
1585
|
await env.DB.batch([
|
|
1547
1586
|
// Page-only threads rely on the column default, as before the scope column existed.
|
|
1548
1587
|
scope === "all"
|
|
@@ -1567,7 +1606,7 @@ async function route(
|
|
|
1567
1606
|
user.name,
|
|
1568
1607
|
text,
|
|
1569
1608
|
origin || url.origin
|
|
1570
|
-
), ...(snapshotStatus ? { snapshotStatus } : {}) }, firstCommentId),
|
|
1609
|
+
), ...(snapshotStatus ? { snapshotStatus } : {}), ...(data.share === false ? { share: false } : {}) }, firstCommentId),
|
|
1571
1610
|
...retainReviewerComments(
|
|
1572
1611
|
env.DB,
|
|
1573
1612
|
project,
|