context_drop 0.1.2 → 0.1.4
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 +4 -4
- data/README.md +101 -9
- data/app/assets/javascripts/context_drop/context_drop.js +1219 -575
- data/app/controllers/context_drop/dashboard/feedbacks_controller.rb +62 -2
- data/app/helpers/context_drop/dashboard_helper.rb +52 -0
- data/app/javascript/context_drop/__tests__/widget.test.ts +225 -3
- data/app/javascript/context_drop/element-picker.ts +958 -484
- data/app/javascript/context_drop/icons.ts +2 -0
- data/app/javascript/context_drop/screenshot.ts +7 -1
- data/app/javascript/context_drop/styles.ts +88 -39
- data/app/javascript/context_drop/widget.ts +195 -69
- data/app/models/context_drop/feedback.rb +11 -5
- data/app/views/context_drop/dashboard/feedbacks/index.html.erb +161 -60
- data/app/views/context_drop/dashboard/feedbacks/show.html.erb +168 -47
- data/app/views/layouts/context_drop/application.html.erb +415 -70
- data/lib/context_drop/version.rb +1 -1
- metadata +3 -2
|
@@ -4,8 +4,10 @@ module ContextDrop
|
|
|
4
4
|
module Dashboard
|
|
5
5
|
class FeedbacksController < ApplicationController
|
|
6
6
|
layout "context_drop/application"
|
|
7
|
+
helper ContextDrop::DashboardHelper
|
|
7
8
|
|
|
8
9
|
before_action :enforce_dashboard_authorization!
|
|
10
|
+
before_action :resolve_navigation_shortcuts
|
|
9
11
|
|
|
10
12
|
PER_PAGE = 25
|
|
11
13
|
|
|
@@ -18,7 +20,7 @@ module ContextDrop
|
|
|
18
20
|
"dismissed" => ContextDrop::Feedback.dismissed.count
|
|
19
21
|
}
|
|
20
22
|
|
|
21
|
-
scope = ContextDrop::Feedback.includes(:
|
|
23
|
+
scope = ContextDrop::Feedback.includes(:element_references, :attachments).recent
|
|
22
24
|
|
|
23
25
|
@current_status = params[:status].to_s.strip
|
|
24
26
|
if ContextDrop::Feedback::STATUSES.include?(@current_status)
|
|
@@ -48,12 +50,35 @@ module ContextDrop
|
|
|
48
50
|
@page = [params[:page].to_i, 1].max
|
|
49
51
|
@total_pages = [(@total_filtered.to_f / PER_PAGE).ceil, 1].max
|
|
50
52
|
@feedbacks = scope.limit(PER_PAGE).offset((@page - 1) * PER_PAGE)
|
|
53
|
+
|
|
54
|
+
session[:context_drop_dashboard_index_url] = request.fullpath if respond_to?(:session) && request&.get?
|
|
51
55
|
end
|
|
52
56
|
|
|
53
57
|
def show
|
|
54
58
|
@feedback = ContextDrop::Feedback
|
|
55
|
-
.includes(:
|
|
59
|
+
.includes(:element_references, :attachments)
|
|
56
60
|
.find(params[:id])
|
|
61
|
+
|
|
62
|
+
# Newer feedback (previous in chronological newest-first list) and older feedback (next in list)
|
|
63
|
+
@newer_feedback = ContextDrop::Feedback
|
|
64
|
+
.where(
|
|
65
|
+
"created_at > :ts OR (created_at = :ts AND id > :id)",
|
|
66
|
+
ts: @feedback.created_at,
|
|
67
|
+
id: @feedback.id
|
|
68
|
+
)
|
|
69
|
+
.order(created_at: :asc, id: :asc)
|
|
70
|
+
.select(:id, :status)
|
|
71
|
+
.first
|
|
72
|
+
|
|
73
|
+
@older_feedback = ContextDrop::Feedback
|
|
74
|
+
.where(
|
|
75
|
+
"created_at < :ts OR (created_at = :ts AND id < :id)",
|
|
76
|
+
ts: @feedback.created_at,
|
|
77
|
+
id: @feedback.id
|
|
78
|
+
)
|
|
79
|
+
.order(created_at: :desc, id: :desc)
|
|
80
|
+
.select(:id, :status)
|
|
81
|
+
.first
|
|
57
82
|
end
|
|
58
83
|
|
|
59
84
|
def update
|
|
@@ -102,6 +127,41 @@ module ContextDrop
|
|
|
102
127
|
rescue StandardError
|
|
103
128
|
str.to_s.gsub(/[%_\\]/) { |m| "\\#{m}" }
|
|
104
129
|
end
|
|
130
|
+
|
|
131
|
+
def resolve_navigation_shortcuts
|
|
132
|
+
@host_app_path = resolve_host_app_path
|
|
133
|
+
@triage_index_back_path = if respond_to?(:session) && session[:context_drop_dashboard_index_url].present?
|
|
134
|
+
session[:context_drop_dashboard_index_url]
|
|
135
|
+
else
|
|
136
|
+
dashboard_feedbacks_path
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def resolve_host_app_path
|
|
141
|
+
engine_prefix = (request.respond_to?(:script_name) && request.script_name.presence) || "/context_drop"
|
|
142
|
+
if respond_to?(:session) && request&.referer.present?
|
|
143
|
+
begin
|
|
144
|
+
ref_uri = URI.parse(request.referer)
|
|
145
|
+
same_host = ref_uri.host.nil? || (request.respond_to?(:host) && ref_uri.host == request.host)
|
|
146
|
+
if same_host && ref_uri.path.present? && !ref_uri.path.start_with?(engine_prefix)
|
|
147
|
+
full_ref = [ref_uri.path, ref_uri.query].compact.join("?")
|
|
148
|
+
session[:context_drop_return_to] = full_ref
|
|
149
|
+
end
|
|
150
|
+
rescue URI::InvalidURIError
|
|
151
|
+
# Ignore malformed referer headers
|
|
152
|
+
end
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
return session[:context_drop_return_to] if respond_to?(:session) && session[:context_drop_return_to].present?
|
|
156
|
+
|
|
157
|
+
if respond_to?(:main_app) && main_app.respond_to?(:root_path)
|
|
158
|
+
main_app.root_path
|
|
159
|
+
else
|
|
160
|
+
"/"
|
|
161
|
+
end
|
|
162
|
+
rescue StandardError
|
|
163
|
+
"/"
|
|
164
|
+
end
|
|
105
165
|
end
|
|
106
166
|
end
|
|
107
167
|
end
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
module ContextDrop
|
|
6
|
+
module DashboardHelper
|
|
7
|
+
def url_path_and_host(raw_url)
|
|
8
|
+
return ["/", nil] if raw_url.blank?
|
|
9
|
+
|
|
10
|
+
uri = URI.parse(raw_url.to_s)
|
|
11
|
+
host = uri.host.presence
|
|
12
|
+
path = uri.path.presence || "/"
|
|
13
|
+
query = uri.query.present? ? "?#{uri.query}" : ""
|
|
14
|
+
[path + query, host]
|
|
15
|
+
rescue URI::InvalidURIError
|
|
16
|
+
[raw_url.to_s, nil]
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def cd_icon_arrow_left(size: 14)
|
|
20
|
+
%(<svg width="#{size}" height="#{size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="19" y1="12" x2="5" y2="12"></line><polyline points="12 19 5 12 12 5"></polyline></svg>).html_safe
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def cd_icon_arrow_right(size: 14)
|
|
24
|
+
%(<svg width="#{size}" height="#{size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="5" y1="12" x2="19" y2="12"></line><polyline points="12 5 19 12 12 19"></polyline></svg>).html_safe
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def cd_icon_search(size: 14)
|
|
28
|
+
%(<svg width="#{size}" height="#{size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="8"></circle><line x1="21" y1="21" x2="16.65" y2="16.65"></line></svg>).html_safe
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def cd_icon_link(size: 14)
|
|
32
|
+
%(<svg width="#{size}" height="#{size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>).html_safe
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
def cd_icon_external_link(size: 13)
|
|
36
|
+
%(<svg width="#{size}" height="#{size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path><polyline points="15 3 21 3 21 9"></polyline><line x1="10" y1="14" x2="21" y2="3"></line></svg>).html_safe
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def cd_icon_pin(size: 13)
|
|
40
|
+
%(<svg width="#{size}" height="#{size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M12 2a8 8 0 0 0-8 8c0 5.25 8 12 8 12s8-6.75 8-12a8 8 0 0 0-8-8z"></path><circle cx="12" cy="10" r="3"></circle></svg>).html_safe
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def cd_icon_attachment(size: 13)
|
|
44
|
+
%(<svg width="#{size}" height="#{size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M21.44 11.05l-9.19 9.19a6 6 0 0 1-8.49-8.49l9.19-9.19a4 4 0 0 1 5.66 5.66l-9.2 9.19a2 2 0 0 1-2.83-2.83l8.49-8.48"></path></svg>).html_safe
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def cd_icon_user(size: 13)
|
|
48
|
+
%(<svg width="#{size}" height="#{size}" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M20 21v-2a4 4 0 0 0-4-4H8a4 4 0 0 0-4 4v2"></path><circle cx="12" cy="7" r="4"></circle></svg>).html_safe
|
|
49
|
+
end
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
@@ -328,6 +328,13 @@ class MockUiEvent {
|
|
|
328
328
|
public readonly button: number;
|
|
329
329
|
public readonly clientX: number;
|
|
330
330
|
public readonly clientY: number;
|
|
331
|
+
public readonly deltaY: number;
|
|
332
|
+
public readonly deltaMode: number;
|
|
333
|
+
public readonly key: string;
|
|
334
|
+
public readonly shiftKey: boolean;
|
|
335
|
+
public readonly altKey: boolean;
|
|
336
|
+
public readonly ctrlKey: boolean;
|
|
337
|
+
public readonly metaKey: boolean;
|
|
331
338
|
public target: unknown = null;
|
|
332
339
|
public currentTarget: unknown = null;
|
|
333
340
|
public defaultPrevented: boolean = false;
|
|
@@ -335,12 +342,32 @@ class MockUiEvent {
|
|
|
335
342
|
|
|
336
343
|
constructor(
|
|
337
344
|
type: string,
|
|
338
|
-
init: {
|
|
345
|
+
init: {
|
|
346
|
+
button?: number;
|
|
347
|
+
clientX?: number;
|
|
348
|
+
clientY?: number;
|
|
349
|
+
deltaY?: number;
|
|
350
|
+
deltaMode?: number;
|
|
351
|
+
key?: string;
|
|
352
|
+
code?: string;
|
|
353
|
+
shiftKey?: boolean;
|
|
354
|
+
altKey?: boolean;
|
|
355
|
+
ctrlKey?: boolean;
|
|
356
|
+
metaKey?: boolean;
|
|
357
|
+
} = {}
|
|
339
358
|
) {
|
|
340
359
|
this.type = type;
|
|
341
360
|
this.button = init.button ?? 0;
|
|
342
361
|
this.clientX = init.clientX ?? 0;
|
|
343
362
|
this.clientY = init.clientY ?? 0;
|
|
363
|
+
this.deltaY = init.deltaY ?? 0;
|
|
364
|
+
this.deltaMode = init.deltaMode ?? 0;
|
|
365
|
+
this.key = init.key ?? "";
|
|
366
|
+
this.code = init.code ?? "";
|
|
367
|
+
this.shiftKey = init.shiftKey ?? false;
|
|
368
|
+
this.altKey = init.altKey ?? false;
|
|
369
|
+
this.ctrlKey = init.ctrlKey ?? false;
|
|
370
|
+
this.metaKey = init.metaKey ?? false;
|
|
344
371
|
}
|
|
345
372
|
|
|
346
373
|
public preventDefault(): void {
|
|
@@ -350,6 +377,10 @@ class MockUiEvent {
|
|
|
350
377
|
public stopPropagation(): void {
|
|
351
378
|
this.propagationStopped = true;
|
|
352
379
|
}
|
|
380
|
+
|
|
381
|
+
public stopImmediatePropagation(): void {
|
|
382
|
+
this.propagationStopped = true;
|
|
383
|
+
}
|
|
353
384
|
}
|
|
354
385
|
|
|
355
386
|
class MockClassList {
|
|
@@ -469,6 +500,14 @@ class MockDomElement {
|
|
|
469
500
|
return this.attrs.has(name);
|
|
470
501
|
}
|
|
471
502
|
|
|
503
|
+
public getAttributeNames(): string[] {
|
|
504
|
+
return Array.from(this.attrs.keys());
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
public setRect(rect: { left: number; top: number; width: number; height: number }): void {
|
|
508
|
+
this.rect = { ...rect };
|
|
509
|
+
}
|
|
510
|
+
|
|
472
511
|
public appendChild(child: MockDomElement): MockDomElement {
|
|
473
512
|
child.parentElement = this;
|
|
474
513
|
child.parentNode = this;
|
|
@@ -614,6 +653,12 @@ function withMountedWidget(
|
|
|
614
653
|
fn: (ctx: {
|
|
615
654
|
widget: ContextDropWidgetElement;
|
|
616
655
|
shadowRoot: MockDomElement;
|
|
656
|
+
mockBody: MockDomElement;
|
|
657
|
+
mockDocument: {
|
|
658
|
+
body: MockDomElement;
|
|
659
|
+
createElement: (tag: string) => MockDomElement;
|
|
660
|
+
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
661
|
+
};
|
|
617
662
|
mockWindow: MockDomElement & { innerWidth: number; innerHeight: number; location: { href: string } };
|
|
618
663
|
}) => void | Promise<void>
|
|
619
664
|
): Promise<void> {
|
|
@@ -627,7 +672,11 @@ function withMountedWidget(
|
|
|
627
672
|
location: { href: "http://localhost:3000/orders" }
|
|
628
673
|
});
|
|
629
674
|
const mockBody = new MockDomElement("body");
|
|
630
|
-
const mockDocument
|
|
675
|
+
const mockDocument: {
|
|
676
|
+
body: MockDomElement;
|
|
677
|
+
createElement: (tag: string) => MockDomElement;
|
|
678
|
+
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
679
|
+
} = {
|
|
631
680
|
body: mockBody,
|
|
632
681
|
createElement: (tag: string) => new MockDomElement(tag)
|
|
633
682
|
};
|
|
@@ -647,7 +696,7 @@ function withMountedWidget(
|
|
|
647
696
|
widget.connectedCallback();
|
|
648
697
|
|
|
649
698
|
return Promise.resolve()
|
|
650
|
-
.then(() => fn({ widget, shadowRoot, mockWindow }))
|
|
699
|
+
.then(() => fn({ widget, shadowRoot, mockBody, mockDocument, mockWindow }))
|
|
651
700
|
.finally(() => {
|
|
652
701
|
widget.disconnectedCallback();
|
|
653
702
|
if (prevWindow === undefined) {
|
|
@@ -815,4 +864,177 @@ describe("ContextDrop Floating Dock & Drag Handle Interactions", () => {
|
|
|
815
864
|
assert.equal(root.style.top, "90px");
|
|
816
865
|
});
|
|
817
866
|
});
|
|
867
|
+
|
|
868
|
+
it("unifies wheel layer scrubbing with inline HUD list, 1-click pin, toggle-unpin, jitter lock, and Esc exit", async () => {
|
|
869
|
+
await withMountedWidget(({ widget, shadowRoot, mockBody, mockDocument, mockWindow }) => {
|
|
870
|
+
// Build a multi-layer DOM stack on the host page:
|
|
871
|
+
// section#checkout > div.card > button#pay-btn > (span.label-a, span.label-b), plus an overlapping toast
|
|
872
|
+
const section = new MockDomElement("section");
|
|
873
|
+
section.setAttribute("id", "checkout");
|
|
874
|
+
section.setRect({ left: 40, top: 80, width: 600, height: 360 });
|
|
875
|
+
|
|
876
|
+
const card = new MockDomElement("div");
|
|
877
|
+
card.setAttribute("class", "pricing-card");
|
|
878
|
+
card.setRect({ left: 60, top: 100, width: 320, height: 220 });
|
|
879
|
+
|
|
880
|
+
const button = new MockDomElement("button");
|
|
881
|
+
button.setAttribute("id", "pay-btn");
|
|
882
|
+
button.setRect({ left: 80, top: 180, width: 180, height: 42 });
|
|
883
|
+
|
|
884
|
+
const spanA = new MockDomElement("span");
|
|
885
|
+
spanA.setAttribute("class", "label-a");
|
|
886
|
+
spanA.setRect({ left: 88, top: 188, width: 80, height: 22 });
|
|
887
|
+
|
|
888
|
+
const spanB = new MockDomElement("span");
|
|
889
|
+
spanB.setAttribute("class", "label-b");
|
|
890
|
+
spanB.setRect({ left: 170, top: 188, width: 70, height: 22 });
|
|
891
|
+
|
|
892
|
+
const toast = new MockDomElement("div");
|
|
893
|
+
toast.setAttribute("id", "overlapping-toast");
|
|
894
|
+
toast.setRect({ left: 75, top: 175, width: 200, height: 36 });
|
|
895
|
+
|
|
896
|
+
button.appendChild(spanA);
|
|
897
|
+
button.appendChild(spanB);
|
|
898
|
+
card.appendChild(button);
|
|
899
|
+
section.appendChild(card);
|
|
900
|
+
section.appendChild(toast);
|
|
901
|
+
mockBody.appendChild(section);
|
|
902
|
+
|
|
903
|
+
let pointNodes: MockDomElement[] = [toast, spanA, button, card, section];
|
|
904
|
+
mockDocument.elementsFromPoint = () => pointNodes;
|
|
905
|
+
|
|
906
|
+
widget.startPinSelection();
|
|
907
|
+
|
|
908
|
+
const compactBar = shadowRoot.querySelector(".cd-compact-bar");
|
|
909
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
910
|
+
assert.ok(compactBar && composer);
|
|
911
|
+
assert.equal(compactBar.hidden, false);
|
|
912
|
+
assert.equal(composer.hidden, true);
|
|
913
|
+
|
|
914
|
+
// Initial Compact Bar shows Cancel + Esc before any pins
|
|
915
|
+
const doneBtn = compactBar.querySelector("[aria-label='Cancel pinning and return to chatbox']");
|
|
916
|
+
assert.ok(doneBtn);
|
|
917
|
+
|
|
918
|
+
// 1. Hover over overlapping toast: HUD starts in compact hover mode (no layer list yet)
|
|
919
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 120, clientY: 192 }));
|
|
920
|
+
const hud = mockBody.querySelector("[data-context-drop-ui='label']");
|
|
921
|
+
assert.ok(hud);
|
|
922
|
+
assert.equal(hud.style.display, "block");
|
|
923
|
+
assert.equal(hud.querySelector("[data-context-drop-ui='hud-layer-list']"), null);
|
|
924
|
+
|
|
925
|
+
// 2. Scroll the wheel once: inline layer list unfurls inside HUD & steps from #overlapping-toast (0) to #pay-btn / span.label-a (1)
|
|
926
|
+
const wheelEv = new MockUiEvent("wheel", { clientX: 120, clientY: 192, deltaY: 40, deltaMode: 0 });
|
|
927
|
+
mockWindow.dispatchEvent(wheelEv);
|
|
928
|
+
assert.equal(wheelEv.defaultPrevented, true);
|
|
929
|
+
|
|
930
|
+
const inlineList = hud.querySelector("[data-context-drop-ui='hud-layer-list']");
|
|
931
|
+
assert.ok(inlineList, "Expected wheel scroll to unfurl inline HUD layer list");
|
|
932
|
+
|
|
933
|
+
// Step once more via ArrowUp to reach button#pay-btn (index 2 in [toast, span.label-a, button#pay-btn, ...])
|
|
934
|
+
mockWindow.dispatchEvent(new MockUiEvent("keydown", { key: "ArrowUp" }));
|
|
935
|
+
|
|
936
|
+
// 3. Pointer-jitter lock: nudge mouse 12px onto sibling spanB inside button#pay-btn right before clicking
|
|
937
|
+
pointNodes = [spanB, button, card, section];
|
|
938
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 132, clientY: 194 }));
|
|
939
|
+
|
|
940
|
+
// 4. Single Click immediately pins button#pay-btn (no second popover click required!)
|
|
941
|
+
const clickEv = new MockUiEvent("click", { clientX: 132, clientY: 194 });
|
|
942
|
+
mockWindow.dispatchEvent(clickEv);
|
|
943
|
+
assert.equal(clickEv.defaultPrevented, true);
|
|
944
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
945
|
+
assert.equal(widget.getElementReferences()[0].selector, "#pay-btn");
|
|
946
|
+
|
|
947
|
+
// On-page pinned marker badge & cursor confirmation toast appear while staying in Pin Mode
|
|
948
|
+
const pinnedBadge = mockBody.querySelector("[data-context-drop-ui='pinned-badge']");
|
|
949
|
+
const pinToast = mockBody.querySelector("[data-context-drop-ui='pin-toast']");
|
|
950
|
+
assert.ok(pinnedBadge);
|
|
951
|
+
assert.ok(pinToast);
|
|
952
|
+
assert.equal(pinToast.style.display, "inline-flex");
|
|
953
|
+
|
|
954
|
+
// Compact Bar updates to prominent Done (1) + Esc CTA and quick-undo pill
|
|
955
|
+
const finishBtn = compactBar.querySelector(
|
|
956
|
+
"[aria-label='Finish pinning elements and return to chatbox']"
|
|
957
|
+
);
|
|
958
|
+
assert.ok(finishBtn);
|
|
959
|
+
assert.ok(compactBar.querySelector(".cd-compact-pinned-pill"));
|
|
960
|
+
|
|
961
|
+
// 5. Clicking the already-pinned element again toggles/unpins it cleanly
|
|
962
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 90, clientY: 185 }));
|
|
963
|
+
pointNodes = [button, card, section];
|
|
964
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 90, clientY: 185 }));
|
|
965
|
+
mockWindow.dispatchEvent(new MockUiEvent("click", { clientX: 90, clientY: 185 }));
|
|
966
|
+
assert.equal(widget.getElementReferences().length, 0);
|
|
967
|
+
|
|
968
|
+
// Pin again, then press Escape once to exit Pin Mode and restore composer
|
|
969
|
+
mockWindow.dispatchEvent(new MockUiEvent("click", { clientX: 90, clientY: 185 }));
|
|
970
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
971
|
+
|
|
972
|
+
mockWindow.dispatchEvent(new MockUiEvent("keydown", { key: "Escape" }));
|
|
973
|
+
assert.equal(composer.hidden, false);
|
|
974
|
+
assert.equal(compactBar.hidden, true);
|
|
975
|
+
assert.equal(mockBody.querySelector("[data-context-drop-ui='pinned-badge']"), null);
|
|
976
|
+
});
|
|
977
|
+
});
|
|
978
|
+
|
|
979
|
+
it("activates Freeze & Pin via Alt+Shift+P, pins candidate on Space, and suppresses blur events", async () => {
|
|
980
|
+
await withMountedWidget(({ widget, shadowRoot, mockBody, mockDocument, mockWindow }) => {
|
|
981
|
+
const compactBar = shadowRoot.querySelector(".cd-compact-bar");
|
|
982
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
983
|
+
assert.ok(compactBar && composer);
|
|
984
|
+
|
|
985
|
+
const navMenu = new MockDomElement("nav");
|
|
986
|
+
navMenu.setAttribute("id", "transient-dropdown");
|
|
987
|
+
const menuItem = new MockDomElement("a");
|
|
988
|
+
menuItem.setAttribute("id", "dimensions-link");
|
|
989
|
+
menuItem.textContent = "Dimensions";
|
|
990
|
+
menuItem.setRect({ left: 100, top: 60, width: 140, height: 32 });
|
|
991
|
+
navMenu.appendChild(menuItem);
|
|
992
|
+
mockBody.appendChild(navMenu);
|
|
993
|
+
|
|
994
|
+
const pointNodes = [menuItem, navMenu];
|
|
995
|
+
mockDocument.elementsFromPoint = () => pointNodes;
|
|
996
|
+
|
|
997
|
+
// Track pointer at (150, 80)
|
|
998
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 150, clientY: 80 }));
|
|
999
|
+
|
|
1000
|
+
// Press Alt+Shift+P to trigger Freeze & Pin globally
|
|
1001
|
+
const freezeKeyEv = new MockUiEvent("keydown", {
|
|
1002
|
+
key: "p",
|
|
1003
|
+
code: "KeyP",
|
|
1004
|
+
altKey: true,
|
|
1005
|
+
shiftKey: true
|
|
1006
|
+
});
|
|
1007
|
+
mockWindow.dispatchEvent(freezeKeyEv);
|
|
1008
|
+
assert.equal(freezeKeyEv.defaultPrevented, true);
|
|
1009
|
+
assert.equal(compactBar.hidden, false);
|
|
1010
|
+
|
|
1011
|
+
// Verify blur event suppression: blur on host element should be stopped
|
|
1012
|
+
const blurEv = new MockUiEvent("blur", {});
|
|
1013
|
+
mockWindow.dispatchEvent(blurEv);
|
|
1014
|
+
assert.equal(blurEv.propagationStopped, true);
|
|
1015
|
+
|
|
1016
|
+
// Verify Spacebar commits the candidate without firing mouse click
|
|
1017
|
+
const spaceKeyEv = new MockUiEvent("keydown", {
|
|
1018
|
+
key: " ",
|
|
1019
|
+
code: "Space"
|
|
1020
|
+
});
|
|
1021
|
+
mockWindow.dispatchEvent(spaceKeyEv);
|
|
1022
|
+
assert.equal(spaceKeyEv.defaultPrevented, true);
|
|
1023
|
+
|
|
1024
|
+
// Pinned elements list should now contain the candidate
|
|
1025
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
1026
|
+
assert.equal(widget.getElementReferences()[0].selector, "#dimensions-link");
|
|
1027
|
+
|
|
1028
|
+
// Press Alt+Shift+P again to exit Freeze & Pin mode
|
|
1029
|
+
const exitKeyEv = new MockUiEvent("keydown", {
|
|
1030
|
+
key: "p",
|
|
1031
|
+
code: "KeyP",
|
|
1032
|
+
altKey: true,
|
|
1033
|
+
shiftKey: true
|
|
1034
|
+
});
|
|
1035
|
+
mockWindow.dispatchEvent(exitKeyEv);
|
|
1036
|
+
assert.equal(compactBar.hidden, true);
|
|
1037
|
+
assert.equal(composer.hidden, false);
|
|
1038
|
+
});
|
|
1039
|
+
});
|
|
818
1040
|
});
|