@commentkit/comment-kit 0.7.0 → 0.7.1

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.
Files changed (45) hide show
  1. package/CHANGELOG.md +27 -0
  2. package/dist/angular.es.js +2 -2
  3. package/dist/comment-kit.es.js +5 -5
  4. package/dist/demo.es.js +4 -3
  5. package/dist/headless.es.js +3 -3
  6. package/dist/preact.es.js +2 -2
  7. package/dist/qwik.qwik.mjs +2 -2
  8. package/dist/react.es.js +2 -2
  9. package/dist/shared/{annotation-toolbar-B9SxYqoF.js → annotation-toolbar-cGC1p-SP.js} +379 -379
  10. package/dist/shared/attachment-refresh-CzQFXHkL.js +94 -0
  11. package/dist/shared/{button-group-Cl9CrvvU.js → button-group-CWdKaOlC.js} +14 -16
  12. package/dist/shared/capture-colors-CxSLsU5-.js +74 -0
  13. package/dist/shared/{comment-drawing-canvas-Dzb5YoFw.js → comment-drawing-canvas-DdXlMgbF.js} +2 -2
  14. package/dist/shared/{comment-utils-BycYTSxA.js → comment-icon-Dg9ZWpz-.js} +29 -23
  15. package/dist/shared/comment-image-lightbox-B7iHjnAz.js +190 -0
  16. package/dist/shared/comment-images-content-D7YNUgo5.js +214 -0
  17. package/dist/shared/{comment-kit-core-BaSuMzp9.js → comment-kit-core-C862uNAm.js} +998 -778
  18. package/dist/shared/{comment-kit-ui-CzfdAZs2.js → comment-kit-ui-0vd-DY4S.js} +5206 -5410
  19. package/dist/shared/{comment-screenshot-annotator-C7X-_bm6.js → comment-screenshot-annotator-DcaSSuWB.js} +5 -5
  20. package/dist/shared/{comment-screenshot-overlay-wIrZrcRy.js → comment-screenshot-overlay-D_nFoJmM.js} +6 -5
  21. package/dist/shared/{dev-export-panel-FwFVdady.js → dev-export-panel-pWBlhlse.js} +7 -7
  22. package/dist/shared/dev-grab-eQ9EgEGY.js +210 -0
  23. package/dist/shared/{element-selector-BhJm-NSs.js → element-selector-DC-_XJ0k.js} +311 -272
  24. package/dist/shared/{mount-ui--ijs8pWT.js → mount-ui-B68j8r6I.js} +4 -4
  25. package/dist/shared/{pusher-ipHMJnO_.js → pusher-C1FHQGXV.js} +1 -1
  26. package/dist/shared/realtime-Diqz7G_y.js +317 -0
  27. package/dist/shared/realtime-recovery-DJ_adc-H.js +135 -0
  28. package/dist/shared/{shadow-root-C5v-T8lQ.js → shadow-root-CrO75sED.js} +1 -1
  29. package/dist/shared/{styles-D3yMtaec.js → styles-C9Jwvm0Q.js} +1 -1
  30. package/dist/shared/useRender-D1z_X_BY.js +5 -0
  31. package/dist/shared/{validation-C7QG8j7Z.js → validation-D-8u4M7I.js} +14 -1
  32. package/dist/shared/{websocket-manager-DhLWh3Jr.js → websocket-manager-CFak_YHy.js} +148 -89
  33. package/dist/solid.es.js +2 -2
  34. package/dist/svelte.es.js +2 -2
  35. package/dist/types/core/api-client.d.ts +8 -1
  36. package/dist/types/core/comment-kit-core.d.ts +9 -0
  37. package/dist/types/core/types.d.ts +35 -0
  38. package/dist/types/core/websocket-manager.d.ts +12 -0
  39. package/dist/types/core/write-access.d.ts +9 -0
  40. package/dist/vue.es.js +2 -2
  41. package/docs/api-reference.md +6 -0
  42. package/package.json +3 -2
  43. package/dist/shared/comment-image-lightbox-BPYJT1sB.js +0 -183
  44. package/dist/shared/dev-grab-DDqg0LQf.js +0 -203
  45. package/dist/shared/realtime-Dk41VwKg.js +0 -302
@@ -2,23 +2,23 @@ import { a as e, i as t, m as n, n as r, o as i } from "./dom-Bhf4WFtY.js";
2
2
  import { n as a } from "./dist-De294MVF.js";
3
3
  import { t as o } from "./button-By0hGrJK.js";
4
4
  import { t as s } from "./createReactComponent-BZHeRbD0.js";
5
- import { R as c, n as ee, y as te } from "./comment-kit-ui-CzfdAZs2.js";
6
- import * as l from "react";
7
- import { Fragment as u, jsx as d, jsxs as f } from "react/jsx-runtime";
8
- var ne = s("outline", "paperclip", "Paperclip", [["path", {
5
+ import { G as c, K as ee, S as te, V as l, n as ne } from "./comment-kit-ui-0vd-DY4S.js";
6
+ import * as u from "react";
7
+ import { Fragment as d, jsx as f, jsxs as p } from "react/jsx-runtime";
8
+ var re = s("outline", "paperclip", "Paperclip", [["path", {
9
9
  d: "M15 7l-6.5 6.5a1.5 1.5 0 0 0 3 3l6.5 -6.5a3 3 0 0 0 -6 -6l-6.5 6.5a4.5 4.5 0 0 0 9 9l6.5 -6.5",
10
10
  key: "svg-0"
11
- }]]), re = s("outline", "x", "X", [["path", {
11
+ }]]), ie = s("outline", "x", "X", [["path", {
12
12
  d: "M18 6l-12 12",
13
13
  key: "svg-0"
14
14
  }], ["path", {
15
15
  d: "M6 6l12 12",
16
16
  key: "svg-1"
17
- }]]), p = ".ck-element-selector{z-index:calc(var(--z-ck-fab) - 1);pointer-events:none;position:fixed;inset:0}.ck-element-selector-outline,.ck-element-selector-mark{pointer-events:none;border-radius:4px;position:fixed}.ck-element-selector-outline{z-index:calc(var(--z-ck-fab) - 1);border:2px solid var(--primary);background-color:color-mix(in oklch, var(--primary) 8%, transparent);box-shadow:0 0 0 1px color-mix(in oklch, var(--background) 95%, transparent), 0 0 0 4px color-mix(in oklch, var(--primary) 18%, transparent)}.ck-element-selector-outline[data-state=selected]{background-color:color-mix(in oklch, var(--primary) 12%, transparent);border-style:solid}.ck-element-selector-outline[data-state=multi]{border-style:dashed;border-color:color-mix(in oklch, var(--primary) 70%, var(--foreground));background-color:color-mix(in oklch, var(--primary) 6%, transparent)}.ck-element-selector-outline[data-state=multi]:before{content:attr(data-multi-index);top:-10px;background:var(--primary);min-width:20px;height:20px;color:var(--primary-foreground,white);text-align:center;border-radius:999px;padding:0 6px;font:600 11px/20px ui-monospace,SF Mono,Menlo,monospace;position:absolute;inset-inline-start:-10px;box-shadow:0 1px 3px #00000040}.ck-element-selector-multibar{bottom:24px;z-index:calc(var(--z-ck-fab) + 1);border:1px solid var(--border);background-color:var(--popover);color:var(--popover-foreground);box-shadow:0 18px 30px -12px #00000047, 0 0 0 1px color-mix(in oklch, var(--foreground) 8%, transparent);pointer-events:auto;border-radius:999px;align-items:center;gap:8px;padding:6px 10px;font:13px/1 system-ui,sans-serif;display:inline-flex;position:fixed;inset-inline-start:50%;transform:translate(-50%)}.ck-element-selector-multibar-count{color:var(--popover-foreground);padding:0 4px}.ck-element-selector-marquee{z-index:calc(var(--z-ck-fab) - 1);border:1px dashed var(--primary);background-color:color-mix(in oklch, var(--primary) 12%, transparent);pointer-events:none;border-radius:4px;position:fixed}.ck-element-selector-context-menu{z-index:calc(var(--z-ck-fab) + 2);border:1px solid var(--border);background-color:var(--popover);min-width:200px;color:var(--popover-foreground);box-shadow:0 18px 30px -12px #0000004d, 0 0 0 1px color-mix(in oklch, var(--foreground) 8%, transparent);pointer-events:auto;border-radius:8px;margin:0;padding:4px;font:13px/1 system-ui,sans-serif;list-style:none;position:fixed}.ck-element-selector-context-menu li{list-style:none}.ck-element-selector-context-menu button{width:100%;color:inherit;text-align:left;cursor:pointer;font:inherit;background:0 0;border:0;border-radius:4px;padding:8px 10px}.ck-element-selector-context-menu button:hover,.ck-element-selector-context-menu button:focus-visible{background-color:color-mix(in oklch, var(--primary) 14%, transparent);outline:none}.ck-element-selector-mark{z-index:calc(var(--z-ck-fab) - 2);border:2px solid color-mix(in oklch, var(--primary) 78%, var(--foreground));box-shadow:inset 0 0 0 1px color-mix(in oklch, var(--background) 80%, transparent), 0 0 0 3px color-mix(in oklch, var(--primary) 14%, transparent)}.ck-element-selector-composer{z-index:var(--z-ck-fab);border:1px solid var(--border);background-color:var(--popover);width:min(28rem,100vw - 1rem);color:var(--popover-foreground);box-shadow:0 22px 42px -16px #00000052, 0 0 0 1px color-mix(in oklch, var(--foreground) 8%, transparent);pointer-events:auto;border-radius:8px;align-items:stretch;gap:.625rem;padding:.75rem;display:grid;position:fixed}.ck-element-selector-input-row{min-width:0}.ck-element-selector-composer .ck-input{border-radius:7px;width:100%;min-width:0;min-height:3rem;padding-inline:.875rem;font-size:.875rem;line-height:1.25rem}.ck-element-selector-actions{align-items:center;gap:.5rem;width:100%;display:flex}.ck-element-selector-actions .ck-button{min-height:2.375rem}.ck-element-selector-attach-action{gap:.375rem;margin-inline-end:auto}.ck-element-selector-grab-action{min-width:8.75rem}.ck-element-selector-action-icon{flex:none;width:.95rem;height:.95rem}.ck-element-selector-file-input{clip:rect(0 0 0 0);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.ck-element-selector-attachment{border:1px solid color-mix(in oklch, var(--border) 80%, transparent);background-color:color-mix(in oklch, var(--muted) 55%, transparent);border-radius:7px;align-items:center;gap:.625rem;width:100%;min-width:0;padding:.5rem;display:flex}.ck-element-selector-attachment-image{object-fit:cover;border-radius:6px;flex:none;width:2.5rem;height:2.5rem}.ck-element-selector-attachment-meta{flex:1;gap:.125rem;min-width:0;display:grid}.ck-element-selector-attachment-name,.ck-element-selector-attachment-path,.ck-element-selector-attachment-size{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.ck-element-selector-attachment-name{color:var(--foreground);font-size:.75rem;font-weight:600;line-height:1rem}.ck-element-selector-attachment-path,.ck-element-selector-attachment-size{color:var(--muted-foreground);font-size:.6875rem;line-height:.875rem}.ck-element-selector-error{width:100%;color:var(--destructive);font-size:.75rem;line-height:1rem}@media (width<=420px){.ck-element-selector-actions{flex-wrap:wrap}.ck-element-selector-attach-action{margin-inline-end:0}.ck-element-selector-save-action,.ck-element-selector-grab-action{flex:auto}}", m = "data-commentkit-freeze", h = "\n*, *::before, *::after {\n animation-play-state: paused !important;\n transition: none !important;\n}\n", g = 0, _ = null, v = [];
17
+ }]]), m = ".ck-element-selector{z-index:calc(var(--z-ck-fab) - 1);pointer-events:none;position:fixed;inset:0}.ck-element-selector-outline,.ck-element-selector-mark{pointer-events:none;border-radius:4px;position:fixed}.ck-element-selector-outline{z-index:calc(var(--z-ck-fab) - 1);border:2px solid var(--primary);background-color:color-mix(in oklch, var(--primary) 8%, transparent);box-shadow:0 0 0 1px color-mix(in oklch, var(--background) 95%, transparent), 0 0 0 4px color-mix(in oklch, var(--primary) 18%, transparent)}.ck-element-selector-outline[data-state=selected]{background-color:color-mix(in oklch, var(--primary) 12%, transparent);border-style:solid}.ck-element-selector-outline[data-state=multi]{border-style:dashed;border-color:color-mix(in oklch, var(--primary) 70%, var(--foreground));background-color:color-mix(in oklch, var(--primary) 6%, transparent)}.ck-element-selector-outline[data-state=multi]:before{content:attr(data-multi-index);top:-10px;background:var(--primary);min-width:20px;height:20px;color:var(--primary-foreground,white);text-align:center;border-radius:999px;padding:0 6px;font:600 11px/20px ui-monospace,SF Mono,Menlo,monospace;position:absolute;inset-inline-start:-10px;box-shadow:0 1px 3px #00000040}.ck-element-selector-multibar{bottom:24px;z-index:calc(var(--z-ck-fab) + 1);border:1px solid var(--border);background-color:var(--popover);color:var(--popover-foreground);box-shadow:0 18px 30px -12px #00000047, 0 0 0 1px color-mix(in oklch, var(--foreground) 8%, transparent);pointer-events:auto;border-radius:999px;align-items:center;gap:8px;padding:6px 10px;font:13px/1 system-ui,sans-serif;display:inline-flex;position:fixed;inset-inline-start:50%;transform:translate(-50%)}.ck-element-selector-multibar-count{color:var(--popover-foreground);padding:0 4px}.ck-element-selector-marquee{z-index:calc(var(--z-ck-fab) - 1);border:1px dashed var(--primary);background-color:color-mix(in oklch, var(--primary) 12%, transparent);pointer-events:none;border-radius:4px;position:fixed}.ck-element-selector-context-menu{z-index:calc(var(--z-ck-fab) + 2);border:1px solid var(--border);background-color:var(--popover);min-width:200px;color:var(--popover-foreground);box-shadow:0 18px 30px -12px #0000004d, 0 0 0 1px color-mix(in oklch, var(--foreground) 8%, transparent);pointer-events:auto;border-radius:8px;margin:0;padding:4px;font:13px/1 system-ui,sans-serif;list-style:none;position:fixed}.ck-element-selector-context-menu li{list-style:none}.ck-element-selector-context-menu button{width:100%;color:inherit;text-align:left;cursor:pointer;font:inherit;background:0 0;border:0;border-radius:4px;padding:8px 10px}.ck-element-selector-context-menu button:hover,.ck-element-selector-context-menu button:focus-visible{background-color:color-mix(in oklch, var(--primary) 14%, transparent);outline:none}.ck-element-selector-mark{z-index:calc(var(--z-ck-fab) - 2);border:2px solid color-mix(in oklch, var(--primary) 78%, var(--foreground));box-shadow:inset 0 0 0 1px color-mix(in oklch, var(--background) 80%, transparent), 0 0 0 3px color-mix(in oklch, var(--primary) 14%, transparent)}.ck-element-selector-composer{z-index:var(--z-ck-fab);border:1px solid var(--border);background-color:var(--popover);width:min(28rem,100vw - 1rem);color:var(--popover-foreground);box-shadow:0 22px 42px -16px #00000052, 0 0 0 1px color-mix(in oklch, var(--foreground) 8%, transparent);pointer-events:auto;border-radius:8px;align-items:stretch;gap:.625rem;padding:.75rem;display:grid;position:fixed}.ck-element-selector-input-row{min-width:0}.ck-element-selector-composer .ck-input{border-radius:7px;width:100%;min-width:0;min-height:3rem;padding-inline:.875rem;font-size:.875rem;line-height:1.25rem}.ck-element-selector-actions{align-items:center;gap:.5rem;width:100%;display:flex}.ck-element-selector-actions .ck-button{min-height:2.375rem}.ck-element-selector-attach-action{gap:.375rem;margin-inline-end:auto}.ck-element-selector-grab-action{min-width:8.75rem}.ck-element-selector-action-icon{flex:none;width:.95rem;height:.95rem}.ck-element-selector-file-input{clip:rect(0 0 0 0);white-space:nowrap;border:0;width:1px;height:1px;margin:-1px;padding:0;position:absolute;overflow:hidden}.ck-element-selector-attachment{border:1px solid color-mix(in oklch, var(--border) 80%, transparent);background-color:color-mix(in oklch, var(--muted) 55%, transparent);border-radius:7px;align-items:center;gap:.625rem;width:100%;min-width:0;padding:.5rem;display:flex}.ck-element-selector-attachment-image{object-fit:cover;border-radius:6px;flex:none;width:2.5rem;height:2.5rem}.ck-element-selector-attachment-meta{flex:1;gap:.125rem;min-width:0;display:grid}.ck-element-selector-attachment-name,.ck-element-selector-attachment-path,.ck-element-selector-attachment-size{text-overflow:ellipsis;white-space:nowrap;overflow:hidden}.ck-element-selector-attachment-name{color:var(--foreground);font-size:.75rem;font-weight:600;line-height:1rem}.ck-element-selector-attachment-path,.ck-element-selector-attachment-size{color:var(--muted-foreground);font-size:.6875rem;line-height:.875rem}.ck-element-selector-error{width:100%;color:var(--destructive);font-size:.75rem;line-height:1rem}@media (width<=420px){.ck-element-selector-actions{flex-wrap:wrap}.ck-element-selector-attach-action{margin-inline-end:0}.ck-element-selector-save-action,.ck-element-selector-grab-action{flex:auto}}", ae = "data-commentkit-freeze", h = "\n*, *::before, *::after {\n animation-play-state: paused !important;\n transition: none !important;\n}\n", g = 0, _ = null, v = [];
18
18
  function y() {
19
19
  if (_ || typeof document > "u") return;
20
20
  let e = document.createElement("style");
21
- e.setAttribute(m, ""), e.textContent = h, document.head.appendChild(e), _ = e;
21
+ e.setAttribute(ae, ""), e.textContent = h, document.head.appendChild(e), _ = e;
22
22
  }
23
23
  function b() {
24
24
  _ &&= (_.remove(), null);
@@ -39,14 +39,14 @@ function S() {
39
39
  } catch {}
40
40
  v = [];
41
41
  }
42
- function ie() {
42
+ function oe() {
43
43
  g++, g === 1 && (y(), x());
44
44
  let e = !1;
45
45
  return () => {
46
46
  e || (e = !0, g = Math.max(0, g - 1), g === 0 && (b(), S()));
47
47
  };
48
48
  }
49
- var C = 448, ae = 236, w = 8, T = .9, E = 1e3, D = 2147483600;
49
+ var C = 448, se = 236, w = 8, T = .9, E = 1e3, D = 2147483600;
50
50
  function O(e) {
51
51
  return typeof Element < "u" && e instanceof Element;
52
52
  }
@@ -55,7 +55,7 @@ function k() {
55
55
  for (; e?.shadowRoot?.activeElement;) e = e.shadowRoot.activeElement;
56
56
  return e;
57
57
  }
58
- function oe(e) {
58
+ function ce(e) {
59
59
  let t = typeof e.composedPath == "function" ? e.composedPath()[0] ?? e.target : e.target;
60
60
  if (!O(t)) return !1;
61
61
  let n = t.tagName.toLowerCase();
@@ -67,7 +67,7 @@ function A(e) {
67
67
  }
68
68
  function j(e, t = B(e)) {
69
69
  let n = e.tagName.toLowerCase();
70
- if (n === "html" || n === "body" || A(e) || e.closest("[data-commentkit-ignore], [data-react-grab-ignore]") || !le(t)) return !1;
70
+ if (n === "html" || n === "body" || A(e) || e.closest("[data-commentkit-ignore], [data-react-grab-ignore]") || !V(t)) return !1;
71
71
  let r = window.getComputedStyle(e);
72
72
  if (r.display === "none" || r.visibility === "hidden") return !1;
73
73
  let i = Number.parseFloat(r.opacity || "1");
@@ -89,7 +89,7 @@ function P(e, t) {
89
89
  function F(e, t) {
90
90
  return P(e, t).find((e) => j(e)) ?? null;
91
91
  }
92
- function se(e) {
92
+ function le(e) {
93
93
  let t = Math.min(e.startX, e.x), n = Math.min(e.startY, e.y), r = Math.abs(e.x - e.startX), i = Math.abs(e.y - e.startY);
94
94
  return {
95
95
  left: t,
@@ -108,13 +108,13 @@ function z(e) {
108
108
  let t = window.getComputedStyle(e), n = (e) => e === "hidden" || e === "clip";
109
109
  return n(t.overflowX) || n(t.overflowY) || n(t.overflow);
110
110
  }
111
- function ce(e) {
111
+ function ue(e) {
112
112
  let t = [];
113
113
  if (typeof document > "u") return t;
114
114
  let n = 0, r = document.createTreeWalker(document.body, NodeFilter.SHOW_ELEMENT, { acceptNode(r) {
115
115
  if (n >= R || t.length >= L) return NodeFilter.FILTER_REJECT;
116
116
  n += 1;
117
- let i = r, a = B(i), o = le(a) && I(a, e);
117
+ let i = r, a = B(i), o = V(a) && I(a, e);
118
118
  return !o && z(i) ? NodeFilter.FILTER_REJECT : o && j(i, a) ? NodeFilter.FILTER_ACCEPT : NodeFilter.FILTER_SKIP;
119
119
  } }), i = r.nextNode();
120
120
  for (; i && (t.push(i), !(t.length >= L || n >= R));) i = r.nextNode();
@@ -131,10 +131,10 @@ function B(e) {
131
131
  right: t.right
132
132
  };
133
133
  }
134
- function le(e) {
134
+ function V(e) {
135
135
  return e.width > 0 && e.height > 0;
136
136
  }
137
- function V(n) {
137
+ function H(n) {
138
138
  return {
139
139
  element: n,
140
140
  selector: t(n),
@@ -142,27 +142,27 @@ function V(n) {
142
142
  rect: B(n)
143
143
  };
144
144
  }
145
- function H(e, t, n) {
145
+ function U(e, t, n) {
146
146
  return Math.min(n, Math.max(t, e));
147
147
  }
148
- function U() {
148
+ function W() {
149
149
  return {
150
150
  width: Math.max(window.innerWidth || 0, 16),
151
151
  height: Math.max(window.innerHeight || 0, 16)
152
152
  };
153
153
  }
154
- function ue(e) {
155
- let t = U(), r = H(e.rect.left + e.rect.width / 2, 0, t.width), i = H(e.rect.top + e.rect.height / 2, 0, t.height);
154
+ function de(e) {
155
+ let t = W(), r = U(e.rect.left + e.rect.width / 2, 0, t.width), i = U(e.rect.top + e.rect.height / 2, 0, t.height);
156
156
  return {
157
157
  ...n(r, i, t),
158
158
  element: e.selector,
159
159
  xpath: e.xpath
160
160
  };
161
161
  }
162
- function de(e) {
162
+ function fe(e) {
163
163
  return typeof e != "number" || !Number.isFinite(e) ? "" : e < 1024 ? `${e} B` : e < 1048576 ? `${(e / 1024).toFixed(1)} KB` : `${(e / 1024 / 1024).toFixed(1)} MB`;
164
164
  }
165
- function W(e, t) {
165
+ function pe(e, t) {
166
166
  let n = e.path;
167
167
  if (typeof n == "string" && n.trim()) return {
168
168
  path: n.trim(),
@@ -181,9 +181,10 @@ function W(e, t) {
181
181
  pathSource: "browser-fallback"
182
182
  };
183
183
  }
184
- function fe(e, t) {
185
- let { path: n, pathSource: r } = W(e, t);
184
+ function me(e, t) {
185
+ let { path: n, pathSource: r } = pe(e, t);
186
186
  return {
187
+ file: e,
187
188
  name: e.name,
188
189
  path: n,
189
190
  pathSource: r,
@@ -196,7 +197,7 @@ function fe(e, t) {
196
197
  function G(e) {
197
198
  e && typeof URL.revokeObjectURL == "function" && URL.revokeObjectURL(e);
198
199
  }
199
- async function pe(e, t) {
200
+ async function he(e, t) {
200
201
  try {
201
202
  if (!navigator.clipboard?.writeText) throw Error("clipboard unavailable");
202
203
  await navigator.clipboard.writeText(e);
@@ -217,27 +218,27 @@ function K(e) {
217
218
  height: e.height
218
219
  };
219
220
  }
220
- function me(e, t = ae) {
221
- let n = U(), r = Math.max(w, n.width - C - w), i = H(e.left, w, r), a = e.bottom + w, o = e.top - t - w;
221
+ function ge(e, t = se) {
222
+ let n = W(), r = Math.max(w, n.width - C - w), i = U(e.left, w, r), a = e.bottom + w, o = e.top - t - w;
222
223
  return {
223
224
  left: i,
224
- top: a + t <= n.height - w ? a : H(o, w, n.height - t - w)
225
+ top: a + t <= n.height - w ? a : U(o, w, n.height - t - w)
225
226
  };
226
227
  }
227
- var he = 220, ge = 200;
228
- function _e(e) {
229
- let t = U();
228
+ var _e = 220, q = 200;
229
+ function ve(e) {
230
+ let t = W();
230
231
  return {
231
- left: H(e.x, w, Math.max(w, t.width - he - w)),
232
- top: H(e.y, w, Math.max(w, t.height - ge - w))
232
+ left: U(e.x, w, Math.max(w, t.width - _e - w)),
233
+ top: U(e.y, w, Math.max(w, t.height - q - w))
233
234
  };
234
235
  }
235
- function ve(e) {
236
+ function ye(e) {
236
237
  return e.status === "open" && !!(e.position.element || e.position.xpath);
237
238
  }
238
- function ye(e) {
239
+ function be(e) {
239
240
  return e.flatMap((e) => {
240
- if (!ve(e)) return [];
241
+ if (!ye(e)) return [];
241
242
  let t = r(e.position.element ?? "", e.position.xpath);
242
243
  if (!t) return [];
243
244
  let n = B(t);
@@ -247,9 +248,9 @@ function ye(e) {
247
248
  }] : [];
248
249
  });
249
250
  }
250
- function be(e) {
251
- let [t, n] = l.useState(0);
252
- return l.useEffect(() => {
251
+ function xe(e) {
252
+ let [t, n] = u.useState(0);
253
+ return u.useEffect(() => {
253
254
  if (!e) return;
254
255
  let t = 0, r = () => {
255
256
  t ||= window.requestAnimationFrame(() => {
@@ -273,59 +274,67 @@ function be(e) {
273
274
  };
274
275
  }, [e]), t;
275
276
  }
276
- var xe = l.memo(function({ core: n, state: r, active: a }) {
277
- let s = c(), [p, m] = l.useState(null), [h, g] = l.useState(null), [_, v] = l.useState([]), [y, b] = l.useState(null), [x, S] = l.useState(null), [C, w] = l.useState(""), [T, E] = l.useState(null), [D, O] = l.useState(!1), [A, j] = l.useState(!1), [M, P] = l.useState(null), I = l.useRef(null), L = l.useRef(null), R = l.useRef(null), z = l.useRef(null), [le, H] = l.useState(ae), U = i().path, W = l.useMemo(() => r.comments.filter((e) => e.page?.path === U), [r.comments, U]), he = W.some(ve), ge = be(a || he || !!h || _.length > 0), xe = l.useRef(null), q = l.useRef([]), Se = l.useRef(""), Ce = l.useRef(null);
278
- l.useEffect(() => {
279
- xe.current = h?.element ?? p?.element ?? null;
280
- }, [p, h]), l.useEffect(() => {
281
- q.current = _;
282
- }, [_]), l.useEffect(() => {
283
- Se.current = C;
284
- }, [C]), l.useEffect(() => {
285
- Ce.current = T;
286
- }, [T]);
287
- let we = l.useMemo(() => ye(W), [W, ge]);
288
- l.useEffect(() => {
289
- a || (m(null), g(null), v([]), S(null), w(""), E((e) => (G(e?.previewUrl), null)), O(!1), P(null), b(null), Z.current = null, Q.current = !1);
290
- }, [a]), l.useEffect(() => () => {
291
- G(Ce.current?.previewUrl);
292
- }, []), l.useEffect(() => {
277
+ var J = u.memo(function({ core: n, state: r, active: a }) {
278
+ let s = l(), { canWrite: m, message: ae } = ee(), [h, g] = u.useState(null), [_, v] = u.useState(null), [y, b] = u.useState([]), [x, S] = u.useState(null), [C, w] = u.useState(null), [T, E] = u.useState(""), [D, O] = u.useState(null), [A, j] = u.useState(!1), M = u.useRef(null), [P, I] = u.useState(!1), [L, R] = u.useState(null), z = u.useRef(null), V = u.useRef(null), U = u.useRef(null), W = u.useRef(null), [pe, _e] = u.useState(se), q = i().path, J = u.useMemo(() => r.comments.filter((e) => e.page?.path === q), [r.comments, q]), Se = J.some(ye), Ce = xe(a || Se || !!_ || y.length > 0), we = u.useRef(null), Te = u.useRef([]), Ee = u.useRef(""), De = u.useRef(null);
279
+ u.useEffect(() => {
280
+ we.current = _?.element ?? h?.element ?? null;
281
+ }, [h, _]), u.useEffect(() => {
282
+ Te.current = y;
283
+ }, [y]), u.useEffect(() => {
284
+ Ee.current = T;
285
+ }, [T]), u.useEffect(() => {
286
+ De.current = D;
287
+ }, [D]);
288
+ let Oe = u.useMemo(() => be(J), [J, Ce]);
289
+ u.useEffect(() => {
290
+ let e = M.current;
291
+ (e && (r.currentUser?.id !== e.userId || (r.activeBranch ?? null) !== e.branch || q !== e.page || !e.submitting && r.activeTool === null || r.activeTool !== null && r.activeTool !== "select") || !a && !A) && (M.current = null, g(null), v(null), b([]), w(null), E(""), O((e) => (G(e?.previewUrl), null)), j(!1), R(null), S(null), Q.current = null, $.current = !1);
292
+ }, [
293
+ a,
294
+ A,
295
+ r.activeTool,
296
+ r.activeBranch,
297
+ r.currentUser?.id,
298
+ q
299
+ ]), u.useEffect(() => () => {
300
+ M.current = null, G(De.current?.previewUrl);
301
+ }, []), u.useEffect(() => {
293
302
  if (!a) return;
294
303
  let e = document.body.style.cursor;
295
304
  document.body.style.cursor = "crosshair";
296
- let t = ie();
305
+ let t = oe();
297
306
  return () => {
298
307
  document.body.style.cursor = e, t();
299
308
  };
300
309
  }, [a]);
301
- let J = a && !!h;
302
- l.useEffect(() => {
303
- if (!J) return;
310
+ let Y = a && !!_;
311
+ u.useEffect(() => {
312
+ if (!Y) return;
304
313
  let e = k();
305
- return e instanceof HTMLElement && !I.current?.contains(e) && (z.current = e), I.current?.querySelector("[data-ck-composer-input]")?.focus({ preventScroll: !0 }), () => {
306
- let e = z.current;
307
- z.current = null, e && e.isConnected && e.focus({ preventScroll: !0 });
314
+ return e instanceof HTMLElement && !z.current?.contains(e) && (W.current = e), z.current?.querySelector("[data-ck-composer-input]")?.focus({ preventScroll: !0 }), () => {
315
+ let e = W.current;
316
+ W.current = null, e && e.isConnected && e.focus({ preventScroll: !0 });
308
317
  };
309
- }, [J]);
310
- let Te = l.useRef(r.isAuthenticated);
311
- l.useEffect(() => {
312
- let e = !Te.current && r.isAuthenticated;
313
- if (Te.current = r.isAuthenticated, !e || !J || !C.trim()) return;
314
- let t = I.current?.querySelector("[data-ck-composer-input]");
318
+ }, [Y]);
319
+ let ke = u.useRef(r.isAuthenticated);
320
+ u.useEffect(() => {
321
+ let e = !ke.current && r.isAuthenticated;
322
+ if (ke.current = r.isAuthenticated, !e || !Y || !T.trim()) return;
323
+ let t = z.current?.querySelector("[data-ck-composer-input]");
315
324
  t?.focus({ preventScroll: !0 });
316
325
  let n = t?.value.length ?? 0;
317
- t?.setSelectionRange?.(n, n), P((e) => e && e.startsWith("Sign in to save comments") ? null : e);
326
+ t?.setSelectionRange?.(n, n), R((e) => e && e.startsWith("Sign in to save comments") ? null : e);
318
327
  }, [
319
328
  r.isAuthenticated,
320
- J,
321
- C
322
- ]), l.useLayoutEffect(() => {
323
- if (!J) return;
324
- let e = I.current;
329
+ Y,
330
+ T
331
+ ]), u.useLayoutEffect(() => {
332
+ if (!Y) return;
333
+ let e = z.current;
325
334
  if (!e) return;
326
335
  let t = () => {
327
336
  let t = e.getBoundingClientRect().height;
328
- t > 0 && H((e) => Math.abs(e - t) > 1 ? t : e);
337
+ t > 0 && _e((e) => Math.abs(e - t) > 1 ? t : e);
329
338
  };
330
339
  t();
331
340
  let n = null;
@@ -336,19 +345,19 @@ var xe = l.memo(function({ core: n, state: r, active: a }) {
336
345
  }
337
346
  return () => n?.disconnect();
338
347
  }, [
339
- J,
340
- T,
341
- M
342
- ]), l.useEffect(() => {
348
+ Y,
349
+ D,
350
+ L
351
+ ]), u.useEffect(() => {
343
352
  if (!a) return;
344
353
  let e = () => {
345
- g((e) => e && {
354
+ v((e) => e && {
346
355
  ...e,
347
356
  rect: B(e.element)
348
- }), m((e) => e && {
357
+ }), g((e) => e && {
349
358
  ...e,
350
359
  rect: B(e.element)
351
- }), v((e) => e.map((e) => ({
360
+ }), b((e) => e.map((e) => ({
352
361
  ...e,
353
362
  rect: B(e.element)
354
363
  })));
@@ -357,9 +366,9 @@ var xe = l.memo(function({ core: n, state: r, active: a }) {
357
366
  window.removeEventListener("scroll", e, !0), window.removeEventListener("resize", e);
358
367
  };
359
368
  }, [a]);
360
- let Y = l.useCallback(async (e, t, r) => {
361
- if (!e || A) return !1;
362
- j(!0), P(null);
369
+ let X = u.useCallback(async (e, t, r) => {
370
+ if (!e || P) return !1;
371
+ I(!0), R(null);
363
372
  try {
364
373
  let i = t?.trim(), a = r ? [{
365
374
  name: r.name,
@@ -372,41 +381,41 @@ var xe = l.memo(function({ core: n, state: r, active: a }) {
372
381
  ...i ? { comment: i } : {},
373
382
  ...a.length > 0 ? { attachments: a } : {}
374
383
  } : void 0, s = o ? await n.grabElement(e, o) : await n.grabElement(e);
375
- return j(!1), s ? (g(null), m(null), w(""), E((e) => (G(e?.previewUrl), null)), n.setTool(null), !0) : (P("Could not grab this element."), !1);
384
+ return I(!1), s ? (v(null), g(null), E(""), O((e) => (G(e?.previewUrl), null)), n.setTool(null), !0) : (R("Could not grab this element."), !1);
376
385
  } catch {
377
- return j(!1), P("Could not copy this element for the agent."), !1;
386
+ return I(!1), R("Could not copy this element for the agent."), !1;
378
387
  }
379
- }, [n, A]), X = l.useCallback(async (e) => {
380
- if (e.length === 0 || A) return !1;
381
- j(!0), P(null);
388
+ }, [n, P]), Z = u.useCallback(async (e) => {
389
+ if (e.length === 0 || P) return !1;
390
+ I(!0), R(null);
382
391
  try {
383
392
  let t = await n.grabElements(e);
384
- return j(!1), t ? (v([]), g(null), m(null), w(""), E((e) => (G(e?.previewUrl), null)), n.setTool(null), !0) : (P("Could not grab these elements."), !1);
393
+ return I(!1), t ? (b([]), v(null), g(null), E(""), O((e) => (G(e?.previewUrl), null)), n.setTool(null), !0) : (R("Could not grab these elements."), !1);
385
394
  } catch {
386
- return j(!1), P("Could not copy these elements for the agent."), !1;
395
+ return I(!1), R("Could not copy these elements for the agent."), !1;
387
396
  }
388
- }, [n, A]), Ee = l.useCallback(() => {
389
- let e = q.current.map((e) => e.element);
390
- X(e);
391
- }, [X]), De = l.useCallback(() => {
392
- v([]);
393
- }, []), Z = l.useRef(null), Q = l.useRef(!1), $ = l.useRef(null);
394
- $.current = y;
395
- let Oe = l.useRef(null);
396
- Oe.current = x, l.useEffect(() => {
397
- if (!x) return;
397
+ }, [n, P]), Ae = u.useCallback(() => {
398
+ let e = Te.current.map((e) => e.element);
399
+ Z(e);
400
+ }, [Z]), je = u.useCallback(() => {
401
+ b([]);
402
+ }, []), Q = u.useRef(null), $ = u.useRef(!1), Me = u.useRef(null);
403
+ Me.current = x;
404
+ let Ne = u.useRef(null);
405
+ Ne.current = C, u.useEffect(() => {
406
+ if (!C) return;
398
407
  let e = n.blockEscape();
399
408
  return () => e();
400
- }, [x, n]), l.useEffect(() => {
401
- if (!x) return;
409
+ }, [C, n]), u.useEffect(() => {
410
+ if (!C) return;
402
411
  let e = k();
403
- return e instanceof HTMLElement && !R.current?.contains(e) && (z.current = e), R.current?.querySelector("[role=\"menuitem\"]")?.focus({ preventScroll: !0 }), () => {
404
- let e = z.current;
405
- z.current = null, e && e.isConnected && e.focus({ preventScroll: !0 });
412
+ return e instanceof HTMLElement && !U.current?.contains(e) && (W.current = e), U.current?.querySelector("[role=\"menuitem\"]")?.focus({ preventScroll: !0 }), () => {
413
+ let e = W.current;
414
+ W.current = null, e && e.isConnected && e.focus({ preventScroll: !0 });
406
415
  };
407
- }, [x]);
408
- let ke = l.useCallback((e) => {
409
- let t = R.current;
416
+ }, [C]);
417
+ let Pe = u.useCallback((e) => {
418
+ let t = U.current;
410
419
  if (!t) return;
411
420
  let n = Array.from(t.querySelectorAll("[role=\"menuitem\"]"));
412
421
  if (n.length === 0) return;
@@ -430,17 +439,17 @@ var xe = l.memo(function({ core: n, state: r, active: a }) {
430
439
  case " ": e.preventDefault(), e.stopPropagation(), k()?.click();
431
440
  }
432
441
  }, []);
433
- l.useEffect(() => {
434
- if (!a) return;
442
+ u.useEffect(() => {
443
+ if (!a && !A) return;
435
444
  let r = (e) => {
436
- e.button !== 0 || N(e) || h || (S(null), Z.current = {
445
+ e.button !== 0 || N(e) || _ || (w(null), Q.current = {
437
446
  x: e.clientX,
438
447
  y: e.clientY
439
- }, Q.current = !1);
448
+ }, $.current = !1);
440
449
  }, i = (n) => {
441
450
  if (N(n)) return;
442
451
  let r = F(n.clientX, n.clientY);
443
- r && (n.preventDefault(), n.stopPropagation(), S({
452
+ r && (n.preventDefault(), n.stopPropagation(), w({
444
453
  element: r,
445
454
  selector: t(r),
446
455
  xpath: e(r),
@@ -459,7 +468,7 @@ var xe = l.memo(function({ core: n, state: r, active: a }) {
459
468
  y: r.clientY,
460
469
  element: i
461
470
  }, o = setTimeout(() => {
462
- s && (S({
471
+ s && (w({
463
472
  element: s.element,
464
473
  selector: t(s.element),
465
474
  xpath: e(s.element),
@@ -475,87 +484,87 @@ var xe = l.memo(function({ core: n, state: r, active: a }) {
475
484
  (Math.abs(n) > 10 || Math.abs(r) > 10) && c();
476
485
  }, l = () => {
477
486
  c();
478
- }, u = (e) => {
487
+ }, ne = (e) => {
479
488
  if (N(e)) return;
480
- let t = Z.current;
489
+ let t = Q.current;
481
490
  if (t) {
482
- if (e.pointerType === "mouse" && !(e.buttons & 1)) Z.current = null, Q.current = !1, b(null);
491
+ if (e.pointerType === "mouse" && !(e.buttons & 1)) Q.current = null, $.current = !1, S(null);
483
492
  else {
484
493
  let n = e.clientX - t.x, r = e.clientY - t.y;
485
- if ($.current || Math.abs(n) > 6 || Math.abs(r) > 6) {
486
- Q.current = !0, b({
494
+ if (Me.current || Math.abs(n) > 6 || Math.abs(r) > 6) {
495
+ $.current = !0, S({
487
496
  startX: t.x,
488
497
  startY: t.y,
489
498
  x: e.clientX,
490
499
  y: e.clientY
491
- }), m(null);
500
+ }), g(null);
492
501
  return;
493
502
  }
494
503
  }
495
504
  }
496
- if (h) return;
505
+ if (_) return;
497
506
  let n = F(e.clientX, e.clientY);
498
- m(n ? V(n) : null);
499
- }, d = () => {
500
- Z.current = null, Q.current = !1, b(null);
501
- }, f = (e) => {
502
- let t = Z.current;
503
- Z.current = null;
504
- let n = $.current;
507
+ g(n ? H(n) : null);
508
+ }, u = () => {
509
+ Q.current = null, $.current = !1, S(null);
510
+ }, d = (e) => {
511
+ let t = Q.current;
512
+ Q.current = null;
513
+ let n = Me.current;
505
514
  if (!t || !n) return;
506
- let r = se({
515
+ let r = le({
507
516
  ...n,
508
517
  x: e.clientX,
509
518
  y: e.clientY
510
519
  });
511
520
  if (r.width < 6 || r.height < 6) {
512
- b(null);
521
+ S(null);
513
522
  return;
514
523
  }
515
- let i = ce(r);
524
+ let i = ue(r);
516
525
  if (i.length > 0) {
517
- let e = i.map(V);
518
- v((t) => {
526
+ let e = i.map(H);
527
+ b((t) => {
519
528
  let n = new Set(t.map((e) => e.element)), r = [...t];
520
529
  for (let t of e) n.has(t.element) || r.push(t);
521
530
  return r;
522
531
  });
523
532
  }
524
- b(null);
525
- }, ne = (e) => {
526
- if (N(e)) return;
527
- if (Q.current) {
528
- Q.current = !1, e.preventDefault(), e.stopPropagation();
533
+ S(null);
534
+ }, f = (e) => {
535
+ if (N(e) || A) return;
536
+ if ($.current) {
537
+ $.current = !1, e.preventDefault(), e.stopPropagation();
529
538
  return;
530
539
  }
531
540
  e.preventDefault(), e.stopPropagation();
532
541
  let t = F(e.clientX, e.clientY);
533
- h && !e.shiftKey ? (g(null), m(null), w(""), E((e) => (G(e?.previewUrl), null)), P(null)) : t && (e.shiftKey ? (v((e) => e.some((e) => e.element === t) ? e.filter((e) => e.element !== t) : [...h && !e.some((e) => e.element === h.element) ? [...e, h] : e, V(t)]), m(null), g(null), w(""), E((e) => (G(e?.previewUrl), null)), P(null)) : (g(V(t)), m(null), w(""), E((e) => (G(e?.previewUrl), null)), P(null)));
534
- }, re = (e) => {
542
+ _ && !e.shiftKey ? (v(null), g(null), E(""), O((e) => (G(e?.previewUrl), null)), R(null)) : t && (e.shiftKey ? (b((e) => e.some((e) => e.element === t) ? e.filter((e) => e.element !== t) : [..._ && !e.some((e) => e.element === _.element) ? [...e, _] : e, H(t)]), g(null), v(null), E(""), O((e) => (G(e?.previewUrl), null)), R(null)) : (v(H(t)), g(null), E(""), O((e) => (G(e?.previewUrl), null)), R(null)));
543
+ }, p = (e) => {
535
544
  if (e.key === "Escape") {
536
545
  if (e.isComposing) return;
537
- if (Oe.current) {
538
- e.preventDefault(), e.stopPropagation(), S(null);
546
+ if (Ne.current) {
547
+ e.preventDefault(), e.stopPropagation(), w(null);
539
548
  return;
540
549
  }
541
- e.preventDefault(), e.stopPropagation(), g(null), m(null), w(""), E((e) => (G(e?.previewUrl), null)), P(null), n.setTool(null);
550
+ e.preventDefault(), e.stopPropagation(), M.current = null, j(!1), v(null), g(null), E(""), O((e) => (G(e?.previewUrl), null)), R(null), n.setTool(null);
542
551
  return;
543
552
  }
544
- if (!e.metaKey && !e.ctrlKey || e.shiftKey || e.altKey || e.key !== "c" && e.key !== "C" && e.code !== "KeyC" || oe(e)) return;
553
+ if (A || !e.metaKey && !e.ctrlKey || e.shiftKey || e.altKey || e.key !== "c" && e.key !== "C" && e.code !== "KeyC" || ce(e)) return;
545
554
  let t = typeof window < "u" ? window.getSelection() : null;
546
555
  if (t && !t.isCollapsed && t.toString().length > 0) return;
547
- let r = q.current;
556
+ let r = Te.current;
548
557
  if (r.length > 0) {
549
- e.preventDefault(), e.stopPropagation(), X(r.map((e) => e.element));
558
+ e.preventDefault(), e.stopPropagation(), Z(r.map((e) => e.element));
550
559
  return;
551
560
  }
552
- let i = xe.current;
561
+ let i = we.current;
553
562
  if (!i) return;
554
563
  e.preventDefault(), e.stopPropagation();
555
- let a = h?.element === i;
556
- Y(i, a ? Se.current : void 0, a ? Ce.current : null);
564
+ let a = _?.element === i;
565
+ X(i, a ? Ee.current : void 0, a ? De.current : null);
557
566
  };
558
- return document.addEventListener("pointerdown", r, !0), document.addEventListener("pointermove", u, !0), document.addEventListener("pointerup", f, !0), document.addEventListener("pointercancel", d, !0), document.addEventListener("click", ne, !0), document.addEventListener("contextmenu", i, !0), document.addEventListener("touchstart", ee, {
567
+ return document.addEventListener("pointerdown", r, !0), document.addEventListener("pointermove", ne, !0), document.addEventListener("pointerup", d, !0), document.addEventListener("pointercancel", u, !0), document.addEventListener("click", f, !0), document.addEventListener("contextmenu", i, !0), document.addEventListener("touchstart", ee, {
559
568
  capture: !0,
560
569
  passive: !0
561
570
  }), document.addEventListener("touchmove", te, {
@@ -567,292 +576,322 @@ var xe = l.memo(function({ core: n, state: r, active: a }) {
567
576
  }), document.addEventListener("touchcancel", l, {
568
577
  capture: !0,
569
578
  passive: !0
570
- }), window.addEventListener("keydown", re, !0), () => {
571
- document.removeEventListener("pointerdown", r, !0), document.removeEventListener("pointermove", u, !0), document.removeEventListener("pointerup", f, !0), document.removeEventListener("pointercancel", d, !0), document.removeEventListener("click", ne, !0), document.removeEventListener("contextmenu", i, !0), document.removeEventListener("touchstart", ee, !0), document.removeEventListener("touchmove", te, !0), document.removeEventListener("touchend", l, !0), document.removeEventListener("touchcancel", l, !0), window.removeEventListener("keydown", re, !0), c();
579
+ }), window.addEventListener("keydown", p, !0), () => {
580
+ document.removeEventListener("pointerdown", r, !0), document.removeEventListener("pointermove", ne, !0), document.removeEventListener("pointerup", d, !0), document.removeEventListener("pointercancel", u, !0), document.removeEventListener("click", f, !0), document.removeEventListener("contextmenu", i, !0), document.removeEventListener("touchstart", ee, !0), document.removeEventListener("touchmove", te, !0), document.removeEventListener("touchend", l, !0), document.removeEventListener("touchcancel", l, !0), window.removeEventListener("keydown", p, !0), c();
572
581
  };
573
582
  }, [
574
583
  a,
584
+ A,
575
585
  n,
576
- Y,
577
586
  X,
578
- h
587
+ Z,
588
+ _
579
589
  ]);
580
- let Ae = l.useCallback(async (e) => {
590
+ let Fe = u.useCallback(async (e) => {
581
591
  e.preventDefault();
582
- let t = C.trim();
583
- if (h && t && !D) {
584
- if (!r.currentUser) P("Sign in to save comments. You can still use Grab for agent without signing in."), n.toggleLoginModal();
585
- else {
586
- O(!0), P(null);
587
- try {
588
- await n.createComment("pin", t, ue(h)), O(!1), g(null), w(""), E((e) => (G(e?.previewUrl), null)), n.setTool(null);
589
- } catch {
590
- O(!1), P("Could not save this comment. Try again.");
591
- }
592
- }
592
+ let t = T.trim();
593
+ if (!_ || !t || A) return;
594
+ if (!r.currentUser) {
595
+ R("Sign in to save comments. You can still use Grab for agent without signing in."), n.toggleLoginModal();
596
+ return;
597
+ }
598
+ let a = {
599
+ userId: r.currentUser.id,
600
+ branch: r.activeBranch ?? null,
601
+ page: q,
602
+ submitting: !1
603
+ };
604
+ M.current = a;
605
+ let o = () => {
606
+ let e = n.getState();
607
+ return M.current === a && e.isAuthenticated && e.currentUser?.id === a.userId && (e.activeBranch ?? null) === a.branch && (e.activeTool === null || e.activeTool === "select") && i().path === a.page;
608
+ }, s = n.on("auth:logout", () => {
609
+ M.current === a && (M.current = null, j(!1));
610
+ });
611
+ j(!0), R(null);
612
+ try {
613
+ let e = await c(n, t, de(_), { files: D ? [D.file] : [] }, () => !o() || n.getState().activeTool !== "select" ? !1 : (a.submitting = !0, !0));
614
+ if (!o()) return;
615
+ if (e.status === "failed") throw Error(e.message);
616
+ v(null), E(""), O((e) => (G(e?.previewUrl), null)), n.setTool(null);
617
+ } catch {
618
+ if (!o()) return;
619
+ n.getState().activeTool === null && n.setTool("select"), R("Could not save this comment. Try again.");
620
+ } finally {
621
+ s(), M.current === a && (M.current = null, j(!1));
593
622
  }
594
623
  }, [
595
- C,
596
- n,
597
624
  D,
598
- h,
625
+ T,
626
+ n,
627
+ q,
628
+ A,
629
+ _,
630
+ r.activeBranch,
599
631
  r.currentUser
600
- ]), je = l.useCallback(() => {
601
- Y(h?.element ?? null, C, T);
632
+ ]), Ie = u.useCallback(() => {
633
+ X(_?.element ?? null, T, D);
602
634
  }, [
635
+ D,
603
636
  T,
604
- C,
605
- Y,
606
- h
607
- ]), Me = l.useCallback(() => {
608
- L.current?.click();
609
- }, []), Ne = l.useCallback((e) => {
637
+ X,
638
+ _
639
+ ]), Le = u.useCallback(() => {
640
+ V.current?.click();
641
+ }, []), Re = u.useCallback((e) => {
610
642
  let t = e.currentTarget, n = t.files?.[0] ?? null;
611
- E((e) => (G(e?.previewUrl), n ? fe(n, t) : null)), t.value = "";
612
- }, []), Pe = l.useCallback(() => {
613
- E((e) => (G(e?.previewUrl), null));
614
- }, []), Fe = l.useMemo(() => ee(), []);
615
- return !a && we.length === 0 ? null : /* @__PURE__ */ f("div", {
643
+ O((e) => (G(e?.previewUrl), n ? me(n, t) : null)), t.value = "";
644
+ }, []), ze = u.useCallback(() => {
645
+ O((e) => (G(e?.previewUrl), null));
646
+ }, []), Be = u.useMemo(() => ne(), []);
647
+ return !a && !A && Oe.length === 0 ? null : /* @__PURE__ */ p("div", {
616
648
  className: "ck-element-selector",
617
649
  "data-testid": "ck-element-selector",
618
650
  children: [
619
- we.map((e) => /* @__PURE__ */ d("div", {
651
+ Oe.map((e) => /* @__PURE__ */ f("div", {
620
652
  "aria-hidden": "true",
621
653
  className: "ck-element-selector-mark",
622
654
  "data-comment-id": e.id,
623
655
  style: K(e.rect)
624
656
  }, e.id)),
625
- a && p && !y && /* @__PURE__ */ d("div", {
657
+ a && h && !x && /* @__PURE__ */ f("div", {
626
658
  "aria-hidden": "true",
627
659
  className: "ck-element-selector-outline",
628
660
  "data-state": "hover",
629
- style: K(p.rect)
661
+ style: K(h.rect)
630
662
  }),
631
- a && y && /* @__PURE__ */ d("div", {
663
+ a && x && /* @__PURE__ */ f("div", {
632
664
  "aria-hidden": "true",
633
665
  className: "ck-element-selector-marquee",
634
666
  "data-testid": "ck-element-selector-marquee",
635
667
  style: {
636
- left: Math.min(y.startX, y.x),
637
- top: Math.min(y.startY, y.y),
638
- width: Math.abs(y.x - y.startX),
639
- height: Math.abs(y.y - y.startY)
668
+ left: Math.min(x.startX, x.x),
669
+ top: Math.min(x.startY, x.y),
670
+ width: Math.abs(x.x - x.startX),
671
+ height: Math.abs(x.y - x.startY)
640
672
  }
641
673
  }),
642
- a && _.map((e, t) => /* @__PURE__ */ d("div", {
674
+ a && y.map((e, t) => /* @__PURE__ */ f("div", {
643
675
  "aria-hidden": "true",
644
676
  className: "ck-element-selector-outline",
645
677
  "data-state": "multi",
646
678
  "data-multi-index": t + 1,
647
679
  style: K(e.rect)
648
680
  }, `multi-${t}-${e.selector}-${e.xpath}`)),
649
- a && x && /* @__PURE__ */ f("ul", {
650
- ref: R,
681
+ a && C && /* @__PURE__ */ p("ul", {
682
+ ref: U,
651
683
  className: "ck-element-selector-context-menu",
652
684
  "data-testid": "ck-element-selector-context-menu",
653
685
  role: "menu",
654
686
  "aria-label": "Element actions",
655
- onKeyDown: ke,
656
- style: _e(x),
687
+ onKeyDown: Pe,
688
+ style: ve(C),
657
689
  children: [
658
- /* @__PURE__ */ d("li", { children: /* @__PURE__ */ d("button", {
690
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f("button", {
659
691
  type: "button",
660
692
  role: "menuitem",
661
693
  "data-testid": "ck-context-menu-grab",
662
694
  onClick: () => {
663
- let e = x.element;
664
- S(null), Y(e);
695
+ let e = C.element;
696
+ w(null), X(e);
665
697
  },
666
698
  children: "Grab for agent"
667
699
  }) }),
668
- /* @__PURE__ */ d("li", { children: /* @__PURE__ */ d("button", {
700
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f("button", {
669
701
  type: "button",
670
702
  role: "menuitem",
671
703
  "data-testid": "ck-context-menu-comment",
704
+ disabled: !m,
672
705
  onClick: () => {
673
- let e = V(x.element);
674
- S(null), g(e);
706
+ let e = H(C.element);
707
+ w(null), v(e);
675
708
  },
676
709
  children: "Add comment"
677
710
  }) }),
678
- /* @__PURE__ */ d("li", { children: /* @__PURE__ */ d("button", {
711
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f("button", {
679
712
  type: "button",
680
713
  role: "menuitem",
681
714
  "data-testid": "ck-context-menu-copy-selector",
682
715
  onClick: () => {
683
- let e = x.selector;
684
- S(null), pe(e, "CSS selector");
716
+ let e = C.selector;
717
+ w(null), he(e, "CSS selector");
685
718
  },
686
719
  children: "Copy CSS selector"
687
720
  }) }),
688
- /* @__PURE__ */ d("li", { children: /* @__PURE__ */ d("button", {
721
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f("button", {
689
722
  type: "button",
690
723
  role: "menuitem",
691
724
  "data-testid": "ck-context-menu-copy-xpath",
692
725
  onClick: () => {
693
- let e = x.xpath;
694
- S(null), pe(e, "XPath");
726
+ let e = C.xpath;
727
+ w(null), he(e, "XPath");
695
728
  },
696
729
  children: "Copy XPath"
697
730
  }) }),
698
- /* @__PURE__ */ d("li", { children: /* @__PURE__ */ d("button", {
731
+ /* @__PURE__ */ f("li", { children: /* @__PURE__ */ f("button", {
699
732
  type: "button",
700
733
  role: "menuitem",
701
734
  "data-testid": "ck-context-menu-inspect",
702
735
  onClick: () => {
703
- console.log("[CommentKit] inspect", x.element), S(null);
736
+ console.log("[CommentKit] inspect", C.element), w(null);
704
737
  },
705
738
  children: "Inspect (log to console)"
706
739
  }) })
707
740
  ]
708
741
  }),
709
- a && _.length > 0 && /* @__PURE__ */ f("div", {
742
+ a && y.length > 0 && /* @__PURE__ */ p("div", {
710
743
  className: "ck-element-selector-multibar",
711
744
  "data-testid": "ck-element-selector-multibar",
712
745
  children: [
713
- /* @__PURE__ */ f("span", {
746
+ /* @__PURE__ */ p("span", {
714
747
  className: "ck-element-selector-multibar-count",
715
- children: [_.length, " selected"]
748
+ children: [y.length, " selected"]
716
749
  }),
717
- /* @__PURE__ */ d(o, {
750
+ /* @__PURE__ */ f(o, {
718
751
  type: "button",
719
752
  size: "sm",
720
- onClick: Ee,
721
- disabled: A,
753
+ onClick: Ae,
754
+ disabled: P,
722
755
  "data-testid": "ck-element-grab-many-button",
723
- children: A ? "Grabbing…" : `Grab ${_.length} for agent`
756
+ children: P ? "Grabbing…" : `Grab ${y.length} for agent`
724
757
  }),
725
- /* @__PURE__ */ d(o, {
758
+ /* @__PURE__ */ f(o, {
726
759
  type: "button",
727
760
  size: "sm",
728
761
  variant: "ghost",
729
- onClick: De,
730
- disabled: A,
762
+ onClick: je,
763
+ disabled: P,
731
764
  "data-testid": "ck-element-grab-clear-button",
732
765
  children: "Clear"
733
766
  })
734
767
  ]
735
768
  }),
736
- a && h && /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("div", {
769
+ (a || A) && _ && /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("div", {
737
770
  "aria-hidden": "true",
738
771
  className: "ck-element-selector-outline",
739
772
  "data-state": "selected",
740
- style: K(h.rect)
741
- }), /* @__PURE__ */ f("form", {
742
- ref: I,
773
+ style: K(_.rect)
774
+ }), /* @__PURE__ */ p("form", {
775
+ ref: z,
743
776
  className: "ck-element-selector-composer",
744
- style: me(h.rect, le),
745
- onSubmit: Ae,
777
+ style: ge(_.rect, pe),
778
+ onSubmit: Fe,
746
779
  children: [
747
- /* @__PURE__ */ d("div", {
780
+ /* @__PURE__ */ f("div", {
748
781
  className: "ck-element-selector-input-row",
749
- children: /* @__PURE__ */ d(te, {
782
+ children: /* @__PURE__ */ f(te, {
750
783
  "data-ck-composer-input": "",
751
784
  "aria-label": "Element comment",
752
- value: C,
785
+ value: T,
753
786
  placeholder: "Add comment",
754
- disabled: D || A,
787
+ disabled: A || P,
755
788
  onChange: (e) => {
756
- w(e.currentTarget.value), M && P(null);
789
+ E(e.currentTarget.value), L && R(null);
757
790
  }
758
791
  })
759
792
  }),
760
- !s && /* @__PURE__ */ d("input", {
761
- ref: L,
793
+ !s && /* @__PURE__ */ f("input", {
794
+ ref: V,
762
795
  "aria-label": "Attach file",
763
796
  className: "ck-element-selector-file-input",
764
797
  type: "file",
765
- onChange: Ne
798
+ disabled: A || P,
799
+ onChange: Re
766
800
  }),
767
- T && /* @__PURE__ */ f("div", {
801
+ D && /* @__PURE__ */ p("div", {
768
802
  className: "ck-element-selector-attachment",
769
803
  "data-testid": "ck-element-attachment-preview",
770
804
  children: [
771
- T.previewUrl && /* @__PURE__ */ d("img", {
805
+ D.previewUrl && /* @__PURE__ */ f("img", {
772
806
  alt: "",
773
807
  "aria-hidden": "true",
774
808
  className: "ck-element-selector-attachment-image",
775
- src: T.previewUrl
809
+ src: D.previewUrl
776
810
  }),
777
- /* @__PURE__ */ f("div", {
811
+ /* @__PURE__ */ p("div", {
778
812
  className: "ck-element-selector-attachment-meta",
779
813
  children: [
780
- /* @__PURE__ */ d("span", {
814
+ /* @__PURE__ */ f("span", {
781
815
  className: "ck-element-selector-attachment-name",
782
- children: T.name
816
+ children: D.name
783
817
  }),
784
- /* @__PURE__ */ d("span", {
818
+ /* @__PURE__ */ f("span", {
785
819
  className: "ck-element-selector-attachment-path",
786
- title: T.path,
787
- children: T.path
820
+ title: D.path,
821
+ children: D.path
788
822
  }),
789
- /* @__PURE__ */ d("span", {
823
+ /* @__PURE__ */ f("span", {
790
824
  className: "ck-element-selector-attachment-size",
791
- children: de(T.size)
825
+ children: fe(D.size)
792
826
  })
793
827
  ]
794
828
  }),
795
- /* @__PURE__ */ d(o, {
829
+ /* @__PURE__ */ f(o, {
796
830
  type: "button",
797
831
  size: "icon-xs",
798
832
  variant: "ghost",
799
833
  "aria-label": "Remove attachment",
800
- disabled: D || A,
801
- onClick: Pe,
802
- children: /* @__PURE__ */ d(re, {
834
+ disabled: A || P,
835
+ onClick: ze,
836
+ children: /* @__PURE__ */ f(ie, {
803
837
  className: "ck-element-selector-action-icon",
804
838
  "aria-hidden": "true"
805
839
  })
806
840
  })
807
841
  ]
808
842
  }),
809
- /* @__PURE__ */ f("div", {
843
+ /* @__PURE__ */ p("div", {
810
844
  className: "ck-element-selector-actions",
811
845
  children: [
812
- !s && /* @__PURE__ */ f(o, {
846
+ !s && /* @__PURE__ */ p(o, {
813
847
  type: "button",
814
848
  variant: "outline",
815
849
  className: "ck-element-selector-attach-action",
816
- disabled: D || A,
817
- onClick: Me,
850
+ disabled: A || P,
851
+ onClick: Le,
818
852
  "data-testid": "ck-element-attach-button",
819
- children: [/* @__PURE__ */ d(ne, {
853
+ children: [/* @__PURE__ */ f(re, {
820
854
  className: "ck-element-selector-action-icon",
821
855
  "aria-hidden": "true"
822
- }), /* @__PURE__ */ d("span", { children: "Attach" })]
856
+ }), /* @__PURE__ */ f("span", { children: "Attach" })]
823
857
  }),
824
- /* @__PURE__ */ d(o, {
858
+ /* @__PURE__ */ f(o, {
825
859
  type: "submit",
826
860
  className: "ck-element-selector-save-action",
827
- disabled: !C.trim() || D || A,
828
- children: D ? "Saving" : "Save"
861
+ disabled: !m || !T.trim() || A || P,
862
+ children: A ? "Saving" : "Save"
829
863
  }),
830
- /* @__PURE__ */ d(o, {
864
+ /* @__PURE__ */ f(o, {
831
865
  type: "button",
832
866
  className: "ck-element-selector-grab-action",
833
- variant: Fe ? "default" : "outline",
834
- disabled: D || A,
835
- onClick: je,
867
+ variant: Be ? "default" : "outline",
868
+ disabled: A || P,
869
+ onClick: Ie,
836
870
  title: s ? "Copy element context to clipboard for your agent" : "Copy element source + screenshot to clipboard for your agent",
837
871
  "data-testid": "ck-element-grab-button",
838
- children: A ? "Grabbing…" : "Grab for agent"
872
+ children: P ? "Grabbing…" : "Grab for agent"
839
873
  })
840
874
  ]
841
875
  }),
842
- M && /* @__PURE__ */ d("p", {
876
+ !m && /* @__PURE__ */ f("p", {
877
+ role: "status",
878
+ className: "ck-element-selector-error",
879
+ children: ae
880
+ }),
881
+ L && /* @__PURE__ */ f("p", {
843
882
  className: "ck-element-selector-error",
844
883
  role: "alert",
845
- children: M
884
+ children: L
846
885
  })
847
886
  ]
848
887
  })] })
849
888
  ]
850
889
  });
851
890
  });
852
- function q(e) {
853
- return /* @__PURE__ */ f(u, { children: [/* @__PURE__ */ d("style", {
891
+ function Se(e) {
892
+ return /* @__PURE__ */ p(d, { children: [/* @__PURE__ */ f("style", {
854
893
  "data-ck-tool-styles": "element-selector",
855
- children: p
856
- }), /* @__PURE__ */ d(xe, { ...e })] });
894
+ children: m
895
+ }), /* @__PURE__ */ f(J, { ...e })] });
857
896
  }
858
- export { q as ElementSelector };
897
+ export { Se as ElementSelector };