context_drop 0.1.0 → 0.1.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5bc93ce0b4c5324da60fbf4c153de9c014b31713a675d81a77ba5341c25fecef
4
- data.tar.gz: b576481d6c94f9a4f154251a29ac7c4db68bfef5bc07b3dc6920c3472a15b26a
3
+ metadata.gz: b855def0db5d6f6454e2429252dbcc669582200110b4ae56b69a0c55b812b73e
4
+ data.tar.gz: 586ad999fd1c189c4e5de95f79b738cf5d498037577b18d12ae4ac6d479db906
5
5
  SHA512:
6
- metadata.gz: d11821d98ea7218e3806d59cb14c555ccb25e3a8455e27ed7cafe807dbdcd9972aba85f194b7be2d20c843fb21969b4740d99d81a306544d89c7ef8c03a67742
7
- data.tar.gz: 3b9f7d4b7b4c1bc9a4414b2d571f203ad60cf158a86689588785be3d4d1133f0fff8a50a8e9018731f05fc42ac47180c2c128cff5d8c39f07e5b9af70f374199
6
+ metadata.gz: 145a0543c31ef2757d1516511cc099a3075120aa294b9c83bc1a9feb5184064413e15da49f6d6b4309a308584474d343369305d25ae4cb082bf51ac88855ce8c
7
+ data.tar.gz: 315aff4a23c88134c511179008797fb7754e6db784a9c0003987db540d87680e55a08c2bceec1ed9b107ba907430fecb210578b679dd48f9c22e38b73972a6cc
data/README.md CHANGED
@@ -1,17 +1,26 @@
1
1
  <p align="center">
2
- <img src="docs/images/context-drop-hero.svg" alt="ContextDrop — Self-hosted contextual feedback engine, tactile DOM pin-drop widget, and IDE MCP server for Ruby on Rails" width="100%" />
2
+ <img src="docs/images/context-drop-hero.svg" alt="ContextDrop, Self-hosted contextual feedback engine, tactile DOM pin-drop widget, and IDE MCP server for Ruby on Rails" width="100%" />
3
3
  </p>
4
4
 
5
5
  <p align="center">
6
- <strong>Stop decoding vague bug reports. Let users and teammates pin the exact DOM element right on your Rails app.</strong><br />
7
- Self-hosted Mountable Rails Engine · Shadow DOM Widget · Overlapping Layer Picker · Active Storage · Built-in MCP Server
6
+ <strong>Stop decoding vague bug reports! Let users pin the problem with your Rails app</strong><br />
7
+ Mountable Rails Engine · Shadow DOM Widget · Overlapping Layer Picker · Active Storage · MCP Server
8
8
  </p>
9
9
 
10
10
  <p align="center">
11
- <a href="#60-second-quickstart">Quickstart</a> ·
12
- <a href="#see-it-in-action">Live Demo</a> ·
13
- <a href="#precision-dom-pinning--layer-disambiguation">Layer Picker</a> ·
14
- <a href="#connect-your-ide--ai-coding-agent-mcp">MCP Server</a> ·
11
+ <a href="https://rubygems.org/gems/context_drop"><img src="https://img.shields.io/gem/v/context_drop?label=RubyGems&color=2563eb" alt="Gem Version" /></a>
12
+ <a href="https://rubygems.org/gems/context_drop"><img src="https://img.shields.io/gem/dt/context_drop?label=Downloads&color=0f172a" alt="Gem Downloads" /></a>
13
+ <img src="https://img.shields.io/badge/Ruby-%3E%3D%203.1-CC342D?logo=ruby&logoColor=white" alt="Ruby >= 3.1" />
14
+ <img src="https://img.shields.io/badge/Rails-%3E%3D%207.1-D30001?logo=rubyonrails&logoColor=white" alt="Rails >= 7.1" />
15
+ <a href="MIT-LICENSE"><img src="https://img.shields.io/badge/License-MIT-16a34a" alt="MIT License" /></a>
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="https://rubygems.org/gems/context_drop">RubyGems</a> ·
20
+ <a href="#quickstart">Quickstart</a> ·
21
+ <a href="#interactive-playground">Live Demo</a> ·
22
+ <a href="#dom-pinning--layer-disambiguation">Layer Picker</a> ·
23
+ <a href="#mcp">MCP Server</a> ·
15
24
  <a href="#zero-trust-privacy--redaction">Privacy &amp; Redaction</a> ·
16
25
  <a href="#configuration">Configuration</a>
17
26
  </p>
@@ -22,7 +31,7 @@
22
31
 
23
32
  When someone reports *"the button on the checkout card isn't working,"* engineers usually spend 20 minutes hunting down which view partial, feature flag, viewport width, or overlapping toast banner caused the problem.
24
33
 
25
- **ContextDrop** (`context_drop`) embeds a tactile, zero-bleed **Shadow DOM feedback composer and DOM pin selector** directly into your Ruby on Rails application (`Rails >= 7.1`, including `Rails 8+`). Reporters click **Pin Element**, point at any UI component—even underneath floating badges or cascading overlays—attach a privacy-redacted screenshot, and send.
34
+ **ContextDrop** (`context_drop`) embeds a tactile, zero-bleed **Shadow DOM feedback composer and DOM pin selector** directly into your Ruby on Rails application (`Rails >= 7.1`, including `Rails 8+`). Reporters click **Pin Element**, point at any UI component (even underneath floating badges or cascading overlays) attach a privacy-redacted screenshot, and send.
26
35
 
27
36
  <p align="center">
28
37
  <img src="docs/images/demo-pinning-layers.jpg" alt="ContextDrop Pin Mode highlighting an overlapping DOM layer with live dimensions and the Compact Pinning Bar" width="100%" />
@@ -84,6 +93,8 @@
84
93
 
85
94
  ### 1. Install the Gem & Run the Generator
86
95
 
96
+ Install [`context_drop` from RubyGems.org](https://rubygems.org/gems/context_drop) (or add `gem "context_drop"` to your `Gemfile`):
97
+
87
98
  ```bash
88
99
  bundle add context_drop
89
100
  bin/rails generate context_drop:install
@@ -183,7 +194,7 @@ Real-world Rails interfaces have sticky navbars, floating promo ribbons, translu
183
194
  1. **Top-Left Pin Selector & Freely Draggable Dock:** Click **Pin Element** in the top-left corner of the chatbox (or from the floating dock). The chatbox collapses into the **Compact Pinning Bar** so it never blocks the page.
184
195
  2. **Scroll-Wheel & Keyboard Depth Cycling:** While hovering any coordinate, roll your mouse wheel (`wheel`) or press `ArrowUp` / `ArrowDown` (`[` / `]`) to cycle through overlapping sibling layers (`document.elementsFromPoint`), child nodes, and parent containers while keeping a dashed ghost outline on the original leaf node.
185
196
  3. **Click-to-Pick Layer Stack Popover:** Clicking a multi-layer spot anchors the pin and opens a Figma-style **Layer & Hierarchy Picker** displaying every candidate layer (`Topmost`, `Overlap`, `Child`, `Parent` badges with pixel dimensions) with live hover preview on the page. Hold `Shift+Click` or press `Enter` to pin immediately.
186
- 4. **Interactive DOM Breadcrumb Bar:** Both the Compact Pinning Bar and the Layer Popover render an interactive ancestor trail (`main.demo-shell > section#scenario > button`)—hover any segment to preview or click to pin it directly.
197
+ 4. **Interactive DOM Breadcrumb Bar:** Both the Compact Pinning Bar and the Layer Popover render an interactive ancestor trail (`main.demo-shell > section#scenario > button`) hover any segment to preview or click to pin it directly.
187
198
  5. **Capture-Phase Host Protection:** All `pointerdown`, `mousedown`, `mouseup`, `click`, and `wheel` events are intercepted in the capture phase during Pin Mode so underlying links, forms, and buttons are never triggered by mistake.
188
199
 
189
200
  ---
@@ -250,13 +261,13 @@ ContextDrop is engineered for production environments where customer privacy and
250
261
 
251
262
  ---
252
263
 
253
- ## Self-Hosted Triage Dashboard
264
+ ## Triage Dashboard
254
265
 
255
- ContextDrop includes a zero-dependency triage interface mounted inside your Rails application at `/context_drop/dashboard/feedbacks`:
266
+ ContextDrop includes a triage interface mounted inside your Rails application at `/context_drop/dashboard/feedbacks`:
256
267
 
257
268
  - **Filter & Search:** Filter submissions by status (`new`, `reviewed`, `resolved`, `dismissed`), originating `page_url`, or free-text query across messages, CSS selectors, and DOM paths.
258
- - **Inspect Full Engineering Context:** View submitter attribution, browser/viewport metadata, inline Active Storage screenshot galleries, and structured `ElementReference` cards (`selector`, `dom_path`, `bounding_rect`, `attributes_snapshot`).
259
- - **One-Click Triage Actions:** Transition feedback status between `Mark Reviewed`, `Mark Resolved`, and `Dismiss`.
269
+ - **Inspect Context:** View submitter attribution, browser/viewport metadata, inline Active Storage screenshot galleries, and structured `ElementReference` cards (`selector`, `dom_path`, `bounding_rect`, `attributes_snapshot`).
270
+ - **Triage Actions:** Transition feedback status between `Mark Reviewed`, `Mark Resolved`, and `Dismiss`.
260
271
 
261
272
  ---
262
273
 
@@ -275,7 +286,7 @@ ContextDrop.configure do |config|
275
286
  # Allow unauthenticated visitors to submit feedback
276
287
  config.allow_anonymous = true
277
288
 
278
- # Polymorphic submitter attribution — return any ActiveRecord model (User, Employee, AdminUser) or nil
289
+ # Polymorphic submitter attribution, return any ActiveRecord model (User, Employee, AdminUser) or nil
279
290
  config.current_submitter = ->(controller) { controller.try(:current_user) }
280
291
 
281
292
  # Authorization hooks
@@ -2681,6 +2681,28 @@
2681
2681
  let initialTop = 0;
2682
2682
  let dragging = false;
2683
2683
  let moved = false;
2684
+ let suppressNextClick = false;
2685
+ let suppressClickTimer = null;
2686
+
2687
+ const clearSuppressClick = () => {
2688
+ suppressNextClick = false;
2689
+ if (suppressClickTimer !== null) {
2690
+ clearTimeout(suppressClickTimer);
2691
+ suppressClickTimer = null;
2692
+ }
2693
+ };
2694
+
2695
+ if (onClickFallback) {
2696
+ handleEl.addEventListener("click", (ev ) => {
2697
+ if (suppressNextClick) {
2698
+ clearSuppressClick();
2699
+ ev.preventDefault();
2700
+ ev.stopPropagation();
2701
+ return;
2702
+ }
2703
+ onClickFallback();
2704
+ });
2705
+ }
2684
2706
 
2685
2707
  const onPointerMove = (ev ) => {
2686
2708
  if (!dragging) return;
@@ -2695,30 +2717,48 @@
2695
2717
  }
2696
2718
  };
2697
2719
 
2698
- const onPointerUp = () => {
2699
- if (!dragging) return;
2720
+ const cleanupDrag = () => {
2700
2721
  dragging = false;
2701
2722
  this.pinDockEl?.classList.remove("is-dragging");
2702
2723
  window.removeEventListener("pointermove", onPointerMove);
2703
2724
  window.removeEventListener("pointerup", onPointerUp);
2704
- if (!moved && onClickFallback) {
2705
- onClickFallback();
2725
+ window.removeEventListener("pointercancel", onPointerCancel);
2726
+ };
2727
+
2728
+ const onPointerUp = () => {
2729
+ if (!dragging) return;
2730
+ cleanupDrag();
2731
+ if (moved && onClickFallback) {
2732
+ suppressNextClick = true;
2733
+ if (suppressClickTimer !== null) {
2734
+ clearTimeout(suppressClickTimer);
2735
+ }
2736
+ suppressClickTimer = setTimeout(() => {
2737
+ suppressNextClick = false;
2738
+ suppressClickTimer = null;
2739
+ }, 0);
2706
2740
  }
2707
2741
  };
2708
2742
 
2743
+ const onPointerCancel = () => {
2744
+ if (!dragging) return;
2745
+ cleanupDrag();
2746
+ clearSuppressClick();
2747
+ };
2748
+
2709
2749
  handleEl.addEventListener("pointerdown", (ev ) => {
2710
2750
  // Only primary mouse button or touch
2711
2751
  if (ev.button !== 0) return;
2712
- const targetEl = ev.target instanceof Element ? ev.target : null;
2713
- if (
2714
- targetEl &&
2715
- handleEl !== this.pinDockEl &&
2716
- targetEl.closest("button")
2717
- ) {
2752
+ const targetEl =
2753
+ ev.target && typeof (ev.target ).closest === "function"
2754
+ ? (ev.target )
2755
+ : null;
2756
+ const closestBtn = targetEl?.closest("button");
2757
+ if (closestBtn && closestBtn !== handleEl && handleEl.contains(closestBtn)) {
2718
2758
  return;
2719
2759
  }
2720
2760
 
2721
- if (!this.rootContainer) return;
2761
+ if (!this.rootContainer || typeof window === "undefined") return;
2722
2762
  const rect = this.rootContainer.getBoundingClientRect();
2723
2763
  startX = ev.clientX;
2724
2764
  startY = ev.clientY;
@@ -2726,9 +2766,11 @@
2726
2766
  initialTop = this.freePos ? this.freePos.top : rect.top;
2727
2767
  dragging = true;
2728
2768
  moved = false;
2769
+ clearSuppressClick();
2729
2770
 
2730
2771
  window.addEventListener("pointermove", onPointerMove);
2731
2772
  window.addEventListener("pointerup", onPointerUp);
2773
+ window.addEventListener("pointercancel", onPointerCancel);
2732
2774
  });
2733
2775
  }
2734
2776
 
@@ -317,3 +317,502 @@ describe("ContextDrop Frontend DOM Sanitizer & Snapshot Capture", () => {
317
317
  assert.equal(selectedRef, "#submit-order");
318
318
  });
319
319
  });
320
+
321
+ interface MockListenerEntry {
322
+ listener: (ev: MockUiEvent) => void;
323
+ capture: boolean;
324
+ }
325
+
326
+ class MockUiEvent {
327
+ public readonly type: string;
328
+ public readonly button: number;
329
+ public readonly clientX: number;
330
+ public readonly clientY: number;
331
+ public target: unknown = null;
332
+ public currentTarget: unknown = null;
333
+ public defaultPrevented: boolean = false;
334
+ public propagationStopped: boolean = false;
335
+
336
+ constructor(
337
+ type: string,
338
+ init: { button?: number; clientX?: number; clientY?: number } = {}
339
+ ) {
340
+ this.type = type;
341
+ this.button = init.button ?? 0;
342
+ this.clientX = init.clientX ?? 0;
343
+ this.clientY = init.clientY ?? 0;
344
+ }
345
+
346
+ public preventDefault(): void {
347
+ this.defaultPrevented = true;
348
+ }
349
+
350
+ public stopPropagation(): void {
351
+ this.propagationStopped = true;
352
+ }
353
+ }
354
+
355
+ class MockClassList {
356
+ private classes: Set<string> = new Set();
357
+
358
+ public syncFromString(raw: string): void {
359
+ this.classes.clear();
360
+ for (const token of raw.split(/\s+/)) {
361
+ if (token) this.classes.add(token);
362
+ }
363
+ }
364
+
365
+ public toString(): string {
366
+ return Array.from(this.classes).join(" ");
367
+ }
368
+
369
+ public add(...tokens: string[]): void {
370
+ for (const token of tokens) {
371
+ if (token) this.classes.add(token);
372
+ }
373
+ }
374
+
375
+ public remove(...tokens: string[]): void {
376
+ for (const token of tokens) {
377
+ this.classes.delete(token);
378
+ }
379
+ }
380
+
381
+ public toggle(token: string, force?: boolean): boolean {
382
+ const shouldHave = force !== undefined ? force : !this.classes.has(token);
383
+ if (shouldHave) {
384
+ this.classes.add(token);
385
+ } else {
386
+ this.classes.delete(token);
387
+ }
388
+ return shouldHave;
389
+ }
390
+
391
+ public contains(token: string): boolean {
392
+ return this.classes.has(token);
393
+ }
394
+ }
395
+
396
+ class MockDomElement {
397
+ public readonly nodeType: number = 1;
398
+ public readonly tagName: string;
399
+ public readonly classList: MockClassList = new MockClassList();
400
+ public readonly style: Record<string, string> = { cssText: "", left: "", top: "", cursor: "" };
401
+ public parentElement: MockDomElement | null = null;
402
+ public parentNode: MockDomElement | null = null;
403
+ public childNodes: MockDomElement[] = [];
404
+ public hidden: boolean = false;
405
+ public type: string = "";
406
+ public title: string = "";
407
+ public textContent: string = "";
408
+ public placeholder: string = "";
409
+ public value: string = "";
410
+ public disabled: boolean = false;
411
+ public multiple: boolean = false;
412
+ public accept: string = "";
413
+ public scrollTop: number = 0;
414
+ public scrollHeight: number = 0;
415
+ private rawHtml: string = "";
416
+ private attrs: Map<string, string> = new Map();
417
+ private listeners: Map<string, MockListenerEntry[]> = new Map();
418
+ private rect: { left: number; top: number; width: number; height: number } = {
419
+ left: 20,
420
+ top: 20,
421
+ width: 220,
422
+ height: 40
423
+ };
424
+
425
+ constructor(tagName: string) {
426
+ this.tagName = tagName.toUpperCase();
427
+ }
428
+
429
+ public get className(): string {
430
+ return this.classList.toString();
431
+ }
432
+
433
+ public set className(val: string) {
434
+ this.classList.syncFromString(val);
435
+ this.attrs.set("class", val);
436
+ }
437
+
438
+ public get innerHTML(): string {
439
+ return this.rawHtml;
440
+ }
441
+
442
+ public set innerHTML(html: string) {
443
+ this.rawHtml = html;
444
+ this.childNodes = [];
445
+ if (html.includes("<svg")) {
446
+ this.appendChild(new MockDomElement("svg"));
447
+ }
448
+ const spanMatches = html.matchAll(/<span(?:\s+class="([^"]*)")?>([^<]*)<\/span>/g);
449
+ for (const match of spanMatches) {
450
+ const span = new MockDomElement("span");
451
+ if (match[1]) span.className = match[1];
452
+ span.textContent = match[2] || "";
453
+ this.appendChild(span);
454
+ }
455
+ }
456
+
457
+ public setAttribute(name: string, value: string): void {
458
+ this.attrs.set(name, value);
459
+ if (name === "class") {
460
+ this.classList.syncFromString(value);
461
+ }
462
+ }
463
+
464
+ public getAttribute(name: string): string | null {
465
+ return this.attrs.get(name) ?? null;
466
+ }
467
+
468
+ public hasAttribute(name: string): boolean {
469
+ return this.attrs.has(name);
470
+ }
471
+
472
+ public appendChild(child: MockDomElement): MockDomElement {
473
+ child.parentElement = this;
474
+ child.parentNode = this;
475
+ this.childNodes.push(child);
476
+ return child;
477
+ }
478
+
479
+ public removeChild(child: MockDomElement): MockDomElement {
480
+ const idx = this.childNodes.indexOf(child);
481
+ if (idx !== -1) {
482
+ this.childNodes.splice(idx, 1);
483
+ child.parentElement = null;
484
+ child.parentNode = null;
485
+ }
486
+ return child;
487
+ }
488
+
489
+ public contains(other: unknown): boolean {
490
+ let cur = other as MockDomElement | null;
491
+ while (cur) {
492
+ if (cur === this) return true;
493
+ cur = cur.parentNode;
494
+ }
495
+ return false;
496
+ }
497
+
498
+ public matches(selector: string): boolean {
499
+ if (selector.startsWith(".")) {
500
+ return this.classList.contains(selector.slice(1));
501
+ }
502
+ if (selector.startsWith("#")) {
503
+ return this.getAttribute("id") === selector.slice(1);
504
+ }
505
+ const attrMatch = selector.match(/^\[([a-zA-Z0-9_-]+)(?:=['"]([^'"]*)['"])?\]$/);
506
+ if (attrMatch) {
507
+ if (!this.hasAttribute(attrMatch[1])) return false;
508
+ return attrMatch[2] === undefined || this.getAttribute(attrMatch[1]) === attrMatch[2];
509
+ }
510
+ return this.tagName.toLowerCase() === selector.toLowerCase();
511
+ }
512
+
513
+ public closest(selector: string): MockDomElement | null {
514
+ let cur: MockDomElement | null = this;
515
+ while (cur) {
516
+ if (cur.matches(selector)) return cur;
517
+ cur = cur.parentElement;
518
+ }
519
+ return null;
520
+ }
521
+
522
+ public querySelector(selector: string): MockDomElement | null {
523
+ for (const child of this.childNodes) {
524
+ if (child.matches(selector)) return child;
525
+ const nested = child.querySelector(selector);
526
+ if (nested) return nested;
527
+ }
528
+ return null;
529
+ }
530
+
531
+ public getBoundingClientRect(): {
532
+ x: number;
533
+ y: number;
534
+ left: number;
535
+ top: number;
536
+ width: number;
537
+ height: number;
538
+ } {
539
+ const parsedLeft = this.style.left ? Number.parseFloat(this.style.left) : this.rect.left;
540
+ const parsedTop = this.style.top ? Number.parseFloat(this.style.top) : this.rect.top;
541
+ return {
542
+ x: parsedLeft,
543
+ y: parsedTop,
544
+ left: parsedLeft,
545
+ top: parsedTop,
546
+ width: this.rect.width,
547
+ height: this.rect.height
548
+ };
549
+ }
550
+
551
+ public focus(): void {}
552
+
553
+ public addEventListener(
554
+ type: string,
555
+ listener: (ev: MockUiEvent) => void,
556
+ options?: boolean | { capture?: boolean }
557
+ ): void {
558
+ const capture = typeof options === "boolean" ? options : Boolean(options?.capture);
559
+ const list = this.listeners.get(type) ?? [];
560
+ list.push({ listener, capture });
561
+ this.listeners.set(type, list);
562
+ }
563
+
564
+ public removeEventListener(
565
+ type: string,
566
+ listener: (ev: MockUiEvent) => void,
567
+ options?: boolean | { capture?: boolean }
568
+ ): void {
569
+ const capture = typeof options === "boolean" ? options : Boolean(options?.capture);
570
+ const list = this.listeners.get(type);
571
+ if (!list) return;
572
+ this.listeners.set(
573
+ type,
574
+ list.filter((entry) => !(entry.listener === listener && entry.capture === capture))
575
+ );
576
+ }
577
+
578
+ public dispatchEvent(ev: MockUiEvent): boolean {
579
+ if (!ev.target) {
580
+ ev.target = this;
581
+ }
582
+ const path: MockDomElement[] = [];
583
+ let cur: MockDomElement | null = this;
584
+ while (cur) {
585
+ path.push(cur);
586
+ cur = cur.parentElement;
587
+ }
588
+
589
+ for (let i = path.length - 1; i >= 0 && !ev.propagationStopped; i -= 1) {
590
+ const node = path[i];
591
+ ev.currentTarget = node;
592
+ for (const entry of [...(node.listeners.get(ev.type) ?? [])]) {
593
+ if (entry.capture) {
594
+ entry.listener(ev);
595
+ }
596
+ }
597
+ }
598
+
599
+ for (let i = 0; i < path.length && !ev.propagationStopped; i += 1) {
600
+ const node = path[i];
601
+ ev.currentTarget = node;
602
+ for (const entry of [...(node.listeners.get(ev.type) ?? [])]) {
603
+ if (!entry.capture) {
604
+ entry.listener(ev);
605
+ }
606
+ }
607
+ }
608
+
609
+ return !ev.defaultPrevented;
610
+ }
611
+ }
612
+
613
+ function withMountedWidget(
614
+ fn: (ctx: {
615
+ widget: ContextDropWidgetElement;
616
+ shadowRoot: MockDomElement;
617
+ mockWindow: MockDomElement & { innerWidth: number; innerHeight: number; location: { href: string } };
618
+ }) => void | Promise<void>
619
+ ): Promise<void> {
620
+ const g = globalThis as Record<string, unknown>;
621
+ const prevWindow = g.window;
622
+ const prevDocument = g.document;
623
+
624
+ const mockWindow = Object.assign(new MockDomElement("window"), {
625
+ innerWidth: 1280,
626
+ innerHeight: 800,
627
+ location: { href: "http://localhost:3000/orders" }
628
+ });
629
+ const mockBody = new MockDomElement("body");
630
+ const mockDocument = {
631
+ body: mockBody,
632
+ createElement: (tag: string) => new MockDomElement(tag)
633
+ };
634
+
635
+ g.window = mockWindow;
636
+ g.document = mockDocument;
637
+
638
+ const shadowRoot = new MockDomElement("shadow-root");
639
+ const widget = new ContextDropWidgetElement();
640
+ const hostShim = widget as unknown as {
641
+ attachShadow: () => ShadowRoot;
642
+ getAttribute: (name: string) => string | null;
643
+ };
644
+ hostShim.attachShadow = () => shadowRoot as unknown as ShadowRoot;
645
+ hostShim.getAttribute = () => null;
646
+
647
+ widget.connectedCallback();
648
+
649
+ return Promise.resolve()
650
+ .then(() => fn({ widget, shadowRoot, mockWindow }))
651
+ .finally(() => {
652
+ widget.disconnectedCallback();
653
+ if (prevWindow === undefined) {
654
+ delete g.window;
655
+ } else {
656
+ g.window = prevWindow;
657
+ }
658
+ if (prevDocument === undefined) {
659
+ delete g.document;
660
+ } else {
661
+ g.document = prevDocument;
662
+ }
663
+ });
664
+ }
665
+
666
+ describe("ContextDrop Floating Dock & Drag Handle Interactions", () => {
667
+ it("activates Pin and ContextDrop floating dock buttons on pointer click (including nested label spans)", async () => {
668
+ await withMountedWidget(({ shadowRoot, mockWindow }) => {
669
+ const pinDock = shadowRoot.querySelector(".cd-pin-dock");
670
+ const floatingPinBtn = shadowRoot.querySelector(".cd-floating-pin-btn");
671
+ const triggerBtn = shadowRoot.querySelector(".cd-trigger");
672
+ const composer = shadowRoot.querySelector(".cd-composer");
673
+ const compactBar = shadowRoot.querySelector(".cd-compact-bar");
674
+
675
+ assert.ok(pinDock && floatingPinBtn && triggerBtn && composer && compactBar);
676
+ assert.equal(composer.hidden, true);
677
+ assert.equal(compactBar.hidden, true);
678
+ assert.equal(pinDock.hidden, false);
679
+
680
+ // Click nested <span>ContextDrop</span> inside .cd-trigger
681
+ const triggerSpan = triggerBtn.querySelector("span") ?? triggerBtn;
682
+ triggerSpan.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 40, clientY: 30 }));
683
+ mockWindow.dispatchEvent(new MockUiEvent("pointerup", { button: 0, clientX: 40, clientY: 30 }));
684
+ triggerSpan.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 40, clientY: 30 }));
685
+
686
+ assert.equal(composer.hidden, false);
687
+ assert.equal(pinDock.hidden, true);
688
+ assert.equal(triggerBtn.getAttribute("aria-expanded"), "true");
689
+
690
+ // Close composer to return to floating dock
691
+ const closeBtn = shadowRoot.querySelector("[aria-label='Close feedback composer']");
692
+ assert.ok(closeBtn);
693
+ closeBtn.dispatchEvent(new MockUiEvent("click"));
694
+ assert.equal(composer.hidden, true);
695
+ assert.equal(pinDock.hidden, false);
696
+
697
+ // Click nested <span>Pin</span> inside .cd-floating-pin-btn
698
+ const pinSpan = floatingPinBtn.querySelector("span") ?? floatingPinBtn;
699
+ pinSpan.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 30, clientY: 30 }));
700
+ mockWindow.dispatchEvent(new MockUiEvent("pointerup", { button: 0, clientX: 30, clientY: 30 }));
701
+ pinSpan.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 30, clientY: 30 }));
702
+
703
+ assert.equal(compactBar.hidden, false);
704
+ assert.equal(floatingPinBtn.getAttribute("aria-pressed"), "true");
705
+ });
706
+ });
707
+
708
+ it("repositions the dock when dragging >5px from Pin or ContextDrop buttons and suppresses synthetic click", async () => {
709
+ await withMountedWidget(({ shadowRoot, mockWindow }) => {
710
+ const root = shadowRoot.querySelector(".cd-root");
711
+ const pinDock = shadowRoot.querySelector(".cd-pin-dock");
712
+ const floatingPinBtn = shadowRoot.querySelector(".cd-floating-pin-btn");
713
+ const triggerBtn = shadowRoot.querySelector(".cd-trigger");
714
+ const composer = shadowRoot.querySelector(".cd-composer");
715
+ const compactBar = shadowRoot.querySelector(".cd-compact-bar");
716
+
717
+ assert.ok(root && pinDock && floatingPinBtn && triggerBtn && composer && compactBar);
718
+
719
+ // Drag >5px starting from .cd-floating-pin-btn
720
+ floatingPinBtn.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 50, clientY: 50 }));
721
+ mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 150, clientY: 120 }));
722
+ assert.equal(pinDock.classList.contains("is-dragging"), true);
723
+ assert.equal(root.classList.contains("is-free-positioned"), true);
724
+ assert.equal(root.style.left, "120px");
725
+ assert.equal(root.style.top, "90px");
726
+
727
+ mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 150, clientY: 120 }));
728
+ assert.equal(pinDock.classList.contains("is-dragging"), false);
729
+
730
+ // Browser dispatches synthetic click after pointerup over the dragged button
731
+ const syntheticClick = new MockUiEvent("click", { clientX: 150, clientY: 120 });
732
+ floatingPinBtn.dispatchEvent(syntheticClick);
733
+ assert.equal(syntheticClick.defaultPrevented, true);
734
+ assert.equal(compactBar.hidden, true);
735
+ assert.equal(composer.hidden, true);
736
+
737
+ // Drag >5px starting from .cd-trigger
738
+ triggerBtn.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 150, clientY: 120 }));
739
+ mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 210, clientY: 180 }));
740
+ mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 210, clientY: 180 }));
741
+ const triggerSyntheticClick = new MockUiEvent("click", { clientX: 210, clientY: 180 });
742
+ triggerBtn.dispatchEvent(triggerSyntheticClick);
743
+ assert.equal(triggerSyntheticClick.defaultPrevented, true);
744
+ assert.equal(composer.hidden, true);
745
+ assert.equal(root.style.left, "180px");
746
+ assert.equal(root.style.top, "150px");
747
+
748
+ // Subsequent normal click on .cd-trigger opens composer as expected
749
+ triggerBtn.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 210, clientY: 180 }));
750
+ mockWindow.dispatchEvent(new MockUiEvent("pointerup", { button: 0, clientX: 210, clientY: 180 }));
751
+ triggerBtn.dispatchEvent(new MockUiEvent("click", { button: 0, clientX: 210, clientY: 180 }));
752
+ assert.equal(composer.hidden, false);
753
+ });
754
+ });
755
+
756
+ it("supports keyboard activation (click without pointerdown/pointerup) on Pin and ContextDrop buttons", async () => {
757
+ await withMountedWidget(async ({ shadowRoot, mockWindow }) => {
758
+ const floatingPinBtn = shadowRoot.querySelector(".cd-floating-pin-btn");
759
+ const triggerBtn = shadowRoot.querySelector(".cd-trigger");
760
+ const composer = shadowRoot.querySelector(".cd-composer");
761
+ const compactBar = shadowRoot.querySelector(".cd-compact-bar");
762
+
763
+ assert.ok(floatingPinBtn && triggerBtn && composer && compactBar);
764
+
765
+ // Keyboard Enter/Space dispatches click directly with no pointer events
766
+ triggerBtn.dispatchEvent(new MockUiEvent("click"));
767
+ assert.equal(composer.hidden, false);
768
+
769
+ // Close via close button
770
+ const closeBtn = shadowRoot.querySelector("[aria-label='Close feedback composer']");
771
+ assert.ok(closeBtn);
772
+ closeBtn.dispatchEvent(new MockUiEvent("click"));
773
+ assert.equal(composer.hidden, true);
774
+
775
+ // Simulate a drag where pointerup occurred outside the button (no synthetic click dispatched)
776
+ floatingPinBtn.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 30, clientY: 30 }));
777
+ mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 90, clientY: 90 }));
778
+ mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 90, clientY: 90 }));
779
+
780
+ await new Promise((resolve) => setTimeout(resolve, 5));
781
+
782
+ // Subsequent keyboard activation on floatingPinBtn still works
783
+ floatingPinBtn.dispatchEvent(new MockUiEvent("click"));
784
+ assert.equal(compactBar.hidden, false);
785
+ });
786
+ });
787
+
788
+ it("ignores nested buttons inside container drag bars (.cd-composer-header, .cd-compact-bar)", async () => {
789
+ await withMountedWidget(({ widget, shadowRoot, mockWindow }) => {
790
+ widget.openComposer();
791
+
792
+ const root = shadowRoot.querySelector(".cd-root");
793
+ const header = shadowRoot.querySelector(".cd-composer-header");
794
+ const minBtn = shadowRoot.querySelector("[aria-label='Minimize chatbox to compact bar']");
795
+ const compactBar = shadowRoot.querySelector(".cd-compact-bar");
796
+
797
+ assert.ok(root && header && minBtn && compactBar);
798
+
799
+ // Pointerdown + move on nested minimize button must NOT drag .cd-root
800
+ minBtn.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 100, clientY: 40 }));
801
+ mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 250, clientY: 160 }));
802
+ mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 250, clientY: 160 }));
803
+ assert.equal(root.classList.contains("is-free-positioned"), false);
804
+
805
+ // Clicking nested minimize button minimizes to compact bar
806
+ minBtn.dispatchEvent(new MockUiEvent("click"));
807
+ assert.equal(compactBar.hidden, false);
808
+
809
+ // Dragging non-button area of .cd-compact-bar DOES reposition .cd-root
810
+ compactBar.dispatchEvent(new MockUiEvent("pointerdown", { button: 0, clientX: 60, clientY: 40 }));
811
+ mockWindow.dispatchEvent(new MockUiEvent("pointermove", { clientX: 140, clientY: 110 }));
812
+ mockWindow.dispatchEvent(new MockUiEvent("pointerup", { clientX: 140, clientY: 110 }));
813
+ assert.equal(root.classList.contains("is-free-positioned"), true);
814
+ assert.equal(root.style.left, "100px");
815
+ assert.equal(root.style.top, "90px");
816
+ });
817
+ });
818
+ });
@@ -296,6 +296,28 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
296
296
  let initialTop = 0;
297
297
  let dragging = false;
298
298
  let moved = false;
299
+ let suppressNextClick = false;
300
+ let suppressClickTimer: ReturnType<typeof setTimeout> | null = null;
301
+
302
+ const clearSuppressClick = (): void => {
303
+ suppressNextClick = false;
304
+ if (suppressClickTimer !== null) {
305
+ clearTimeout(suppressClickTimer);
306
+ suppressClickTimer = null;
307
+ }
308
+ };
309
+
310
+ if (onClickFallback) {
311
+ handleEl.addEventListener("click", (ev: MouseEvent) => {
312
+ if (suppressNextClick) {
313
+ clearSuppressClick();
314
+ ev.preventDefault();
315
+ ev.stopPropagation();
316
+ return;
317
+ }
318
+ onClickFallback();
319
+ });
320
+ }
299
321
 
300
322
  const onPointerMove = (ev: PointerEvent): void => {
301
323
  if (!dragging) return;
@@ -310,30 +332,48 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
310
332
  }
311
333
  };
312
334
 
313
- const onPointerUp = (): void => {
314
- if (!dragging) return;
335
+ const cleanupDrag = (): void => {
315
336
  dragging = false;
316
337
  this.pinDockEl?.classList.remove("is-dragging");
317
338
  window.removeEventListener("pointermove", onPointerMove);
318
339
  window.removeEventListener("pointerup", onPointerUp);
319
- if (!moved && onClickFallback) {
320
- onClickFallback();
340
+ window.removeEventListener("pointercancel", onPointerCancel);
341
+ };
342
+
343
+ const onPointerUp = (): void => {
344
+ if (!dragging) return;
345
+ cleanupDrag();
346
+ if (moved && onClickFallback) {
347
+ suppressNextClick = true;
348
+ if (suppressClickTimer !== null) {
349
+ clearTimeout(suppressClickTimer);
350
+ }
351
+ suppressClickTimer = setTimeout(() => {
352
+ suppressNextClick = false;
353
+ suppressClickTimer = null;
354
+ }, 0);
321
355
  }
322
356
  };
323
357
 
358
+ const onPointerCancel = (): void => {
359
+ if (!dragging) return;
360
+ cleanupDrag();
361
+ clearSuppressClick();
362
+ };
363
+
324
364
  handleEl.addEventListener("pointerdown", (ev: PointerEvent) => {
325
365
  // Only primary mouse button or touch
326
366
  if (ev.button !== 0) return;
327
- const targetEl = ev.target instanceof Element ? ev.target : null;
328
- if (
329
- targetEl &&
330
- handleEl !== this.pinDockEl &&
331
- targetEl.closest("button")
332
- ) {
367
+ const targetEl =
368
+ ev.target && typeof (ev.target as Element).closest === "function"
369
+ ? (ev.target as Element)
370
+ : null;
371
+ const closestBtn = targetEl?.closest("button");
372
+ if (closestBtn && closestBtn !== handleEl && handleEl.contains(closestBtn)) {
333
373
  return;
334
374
  }
335
375
 
336
- if (!this.rootContainer) return;
376
+ if (!this.rootContainer || typeof window === "undefined") return;
337
377
  const rect = this.rootContainer.getBoundingClientRect();
338
378
  startX = ev.clientX;
339
379
  startY = ev.clientY;
@@ -341,9 +381,11 @@ export class ContextDropWidgetElement extends BaseHTMLElement {
341
381
  initialTop = this.freePos ? this.freePos.top : rect.top;
342
382
  dragging = true;
343
383
  moved = false;
384
+ clearSuppressClick();
344
385
 
345
386
  window.addEventListener("pointermove", onPointerMove);
346
387
  window.addEventListener("pointerup", onPointerUp);
388
+ window.addEventListener("pointercancel", onPointerCancel);
347
389
  });
348
390
  }
349
391
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContextDrop
4
- VERSION = "0.1.0"
4
+ VERSION = '0.1.1'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: context_drop
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kemal Elmizan
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-11-10 00:00:00.000000000 Z
11
+ date: 2026-11-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionpack