context_drop 0.1.2 → 0.1.3
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/app/assets/javascripts/context_drop/context_drop.js +1109 -570
- data/app/javascript/context_drop/__tests__/widget.test.ts +158 -3
- data/app/javascript/context_drop/element-picker.ts +894 -485
- 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 +147 -61
- data/lib/context_drop/version.rb +1 -1
- metadata +1 -1
|
@@ -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,27 @@ 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
|
+
shiftKey?: boolean;
|
|
353
|
+
} = {}
|
|
339
354
|
) {
|
|
340
355
|
this.type = type;
|
|
341
356
|
this.button = init.button ?? 0;
|
|
342
357
|
this.clientX = init.clientX ?? 0;
|
|
343
358
|
this.clientY = init.clientY ?? 0;
|
|
359
|
+
this.deltaY = init.deltaY ?? 0;
|
|
360
|
+
this.deltaMode = init.deltaMode ?? 0;
|
|
361
|
+
this.key = init.key ?? "";
|
|
362
|
+
this.shiftKey = init.shiftKey ?? false;
|
|
363
|
+
this.altKey = false;
|
|
364
|
+
this.ctrlKey = false;
|
|
365
|
+
this.metaKey = false;
|
|
344
366
|
}
|
|
345
367
|
|
|
346
368
|
public preventDefault(): void {
|
|
@@ -350,6 +372,10 @@ class MockUiEvent {
|
|
|
350
372
|
public stopPropagation(): void {
|
|
351
373
|
this.propagationStopped = true;
|
|
352
374
|
}
|
|
375
|
+
|
|
376
|
+
public stopImmediatePropagation(): void {
|
|
377
|
+
this.propagationStopped = true;
|
|
378
|
+
}
|
|
353
379
|
}
|
|
354
380
|
|
|
355
381
|
class MockClassList {
|
|
@@ -469,6 +495,14 @@ class MockDomElement {
|
|
|
469
495
|
return this.attrs.has(name);
|
|
470
496
|
}
|
|
471
497
|
|
|
498
|
+
public getAttributeNames(): string[] {
|
|
499
|
+
return Array.from(this.attrs.keys());
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
public setRect(rect: { left: number; top: number; width: number; height: number }): void {
|
|
503
|
+
this.rect = { ...rect };
|
|
504
|
+
}
|
|
505
|
+
|
|
472
506
|
public appendChild(child: MockDomElement): MockDomElement {
|
|
473
507
|
child.parentElement = this;
|
|
474
508
|
child.parentNode = this;
|
|
@@ -614,6 +648,12 @@ function withMountedWidget(
|
|
|
614
648
|
fn: (ctx: {
|
|
615
649
|
widget: ContextDropWidgetElement;
|
|
616
650
|
shadowRoot: MockDomElement;
|
|
651
|
+
mockBody: MockDomElement;
|
|
652
|
+
mockDocument: {
|
|
653
|
+
body: MockDomElement;
|
|
654
|
+
createElement: (tag: string) => MockDomElement;
|
|
655
|
+
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
656
|
+
};
|
|
617
657
|
mockWindow: MockDomElement & { innerWidth: number; innerHeight: number; location: { href: string } };
|
|
618
658
|
}) => void | Promise<void>
|
|
619
659
|
): Promise<void> {
|
|
@@ -627,7 +667,11 @@ function withMountedWidget(
|
|
|
627
667
|
location: { href: "http://localhost:3000/orders" }
|
|
628
668
|
});
|
|
629
669
|
const mockBody = new MockDomElement("body");
|
|
630
|
-
const mockDocument
|
|
670
|
+
const mockDocument: {
|
|
671
|
+
body: MockDomElement;
|
|
672
|
+
createElement: (tag: string) => MockDomElement;
|
|
673
|
+
elementsFromPoint?: (x: number, y: number) => MockDomElement[];
|
|
674
|
+
} = {
|
|
631
675
|
body: mockBody,
|
|
632
676
|
createElement: (tag: string) => new MockDomElement(tag)
|
|
633
677
|
};
|
|
@@ -647,7 +691,7 @@ function withMountedWidget(
|
|
|
647
691
|
widget.connectedCallback();
|
|
648
692
|
|
|
649
693
|
return Promise.resolve()
|
|
650
|
-
.then(() => fn({ widget, shadowRoot, mockWindow }))
|
|
694
|
+
.then(() => fn({ widget, shadowRoot, mockBody, mockDocument, mockWindow }))
|
|
651
695
|
.finally(() => {
|
|
652
696
|
widget.disconnectedCallback();
|
|
653
697
|
if (prevWindow === undefined) {
|
|
@@ -815,4 +859,115 @@ describe("ContextDrop Floating Dock & Drag Handle Interactions", () => {
|
|
|
815
859
|
assert.equal(root.style.top, "90px");
|
|
816
860
|
});
|
|
817
861
|
});
|
|
862
|
+
|
|
863
|
+
it("unifies wheel layer scrubbing with inline HUD list, 1-click pin, toggle-unpin, jitter lock, and Esc exit", async () => {
|
|
864
|
+
await withMountedWidget(({ widget, shadowRoot, mockBody, mockDocument, mockWindow }) => {
|
|
865
|
+
// Build a multi-layer DOM stack on the host page:
|
|
866
|
+
// section#checkout > div.card > button#pay-btn > (span.label-a, span.label-b), plus an overlapping toast
|
|
867
|
+
const section = new MockDomElement("section");
|
|
868
|
+
section.setAttribute("id", "checkout");
|
|
869
|
+
section.setRect({ left: 40, top: 80, width: 600, height: 360 });
|
|
870
|
+
|
|
871
|
+
const card = new MockDomElement("div");
|
|
872
|
+
card.setAttribute("class", "pricing-card");
|
|
873
|
+
card.setRect({ left: 60, top: 100, width: 320, height: 220 });
|
|
874
|
+
|
|
875
|
+
const button = new MockDomElement("button");
|
|
876
|
+
button.setAttribute("id", "pay-btn");
|
|
877
|
+
button.setRect({ left: 80, top: 180, width: 180, height: 42 });
|
|
878
|
+
|
|
879
|
+
const spanA = new MockDomElement("span");
|
|
880
|
+
spanA.setAttribute("class", "label-a");
|
|
881
|
+
spanA.setRect({ left: 88, top: 188, width: 80, height: 22 });
|
|
882
|
+
|
|
883
|
+
const spanB = new MockDomElement("span");
|
|
884
|
+
spanB.setAttribute("class", "label-b");
|
|
885
|
+
spanB.setRect({ left: 170, top: 188, width: 70, height: 22 });
|
|
886
|
+
|
|
887
|
+
const toast = new MockDomElement("div");
|
|
888
|
+
toast.setAttribute("id", "overlapping-toast");
|
|
889
|
+
toast.setRect({ left: 75, top: 175, width: 200, height: 36 });
|
|
890
|
+
|
|
891
|
+
button.appendChild(spanA);
|
|
892
|
+
button.appendChild(spanB);
|
|
893
|
+
card.appendChild(button);
|
|
894
|
+
section.appendChild(card);
|
|
895
|
+
section.appendChild(toast);
|
|
896
|
+
mockBody.appendChild(section);
|
|
897
|
+
|
|
898
|
+
let pointNodes: MockDomElement[] = [toast, spanA, button, card, section];
|
|
899
|
+
mockDocument.elementsFromPoint = () => pointNodes;
|
|
900
|
+
|
|
901
|
+
widget.startPinSelection();
|
|
902
|
+
|
|
903
|
+
const compactBar = shadowRoot.querySelector(".cd-compact-bar");
|
|
904
|
+
const composer = shadowRoot.querySelector(".cd-composer");
|
|
905
|
+
assert.ok(compactBar && composer);
|
|
906
|
+
assert.equal(compactBar.hidden, false);
|
|
907
|
+
assert.equal(composer.hidden, true);
|
|
908
|
+
|
|
909
|
+
// Initial Compact Bar shows Cancel + Esc before any pins
|
|
910
|
+
const doneBtn = compactBar.querySelector("[aria-label='Cancel pinning and return to chatbox']");
|
|
911
|
+
assert.ok(doneBtn);
|
|
912
|
+
|
|
913
|
+
// 1. Hover over overlapping toast: HUD starts in compact hover mode (no layer list yet)
|
|
914
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 120, clientY: 192 }));
|
|
915
|
+
const hud = mockBody.querySelector("[data-context-drop-ui='label']");
|
|
916
|
+
assert.ok(hud);
|
|
917
|
+
assert.equal(hud.style.display, "block");
|
|
918
|
+
assert.equal(hud.querySelector("[data-context-drop-ui='hud-layer-list']"), null);
|
|
919
|
+
|
|
920
|
+
// 2. Scroll the wheel once: inline layer list unfurls inside HUD & steps from #overlapping-toast (0) to #pay-btn / span.label-a (1)
|
|
921
|
+
const wheelEv = new MockUiEvent("wheel", { clientX: 120, clientY: 192, deltaY: 40, deltaMode: 0 });
|
|
922
|
+
mockWindow.dispatchEvent(wheelEv);
|
|
923
|
+
assert.equal(wheelEv.defaultPrevented, true);
|
|
924
|
+
|
|
925
|
+
const inlineList = hud.querySelector("[data-context-drop-ui='hud-layer-list']");
|
|
926
|
+
assert.ok(inlineList, "Expected wheel scroll to unfurl inline HUD layer list");
|
|
927
|
+
|
|
928
|
+
// Step once more via ArrowUp to reach button#pay-btn (index 2 in [toast, span.label-a, button#pay-btn, ...])
|
|
929
|
+
mockWindow.dispatchEvent(new MockUiEvent("keydown", { key: "ArrowUp" }));
|
|
930
|
+
|
|
931
|
+
// 3. Pointer-jitter lock: nudge mouse 12px onto sibling spanB inside button#pay-btn right before clicking
|
|
932
|
+
pointNodes = [spanB, button, card, section];
|
|
933
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 132, clientY: 194 }));
|
|
934
|
+
|
|
935
|
+
// 4. Single Click immediately pins button#pay-btn (no second popover click required!)
|
|
936
|
+
const clickEv = new MockUiEvent("click", { clientX: 132, clientY: 194 });
|
|
937
|
+
mockWindow.dispatchEvent(clickEv);
|
|
938
|
+
assert.equal(clickEv.defaultPrevented, true);
|
|
939
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
940
|
+
assert.equal(widget.getElementReferences()[0].selector, "#pay-btn");
|
|
941
|
+
|
|
942
|
+
// On-page pinned marker badge & cursor confirmation toast appear while staying in Pin Mode
|
|
943
|
+
const pinnedBadge = mockBody.querySelector("[data-context-drop-ui='pinned-badge']");
|
|
944
|
+
const pinToast = mockBody.querySelector("[data-context-drop-ui='pin-toast']");
|
|
945
|
+
assert.ok(pinnedBadge);
|
|
946
|
+
assert.ok(pinToast);
|
|
947
|
+
assert.equal(pinToast.style.display, "inline-flex");
|
|
948
|
+
|
|
949
|
+
// Compact Bar updates to prominent Done (1) + Esc CTA and quick-undo pill
|
|
950
|
+
const finishBtn = compactBar.querySelector(
|
|
951
|
+
"[aria-label='Finish pinning elements and return to chatbox']"
|
|
952
|
+
);
|
|
953
|
+
assert.ok(finishBtn);
|
|
954
|
+
assert.ok(compactBar.querySelector(".cd-compact-pinned-pill"));
|
|
955
|
+
|
|
956
|
+
// 5. Clicking the already-pinned element again toggles/unpins it cleanly
|
|
957
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 90, clientY: 185 }));
|
|
958
|
+
pointNodes = [button, card, section];
|
|
959
|
+
mockWindow.dispatchEvent(new MockUiEvent("mousemove", { clientX: 90, clientY: 185 }));
|
|
960
|
+
mockWindow.dispatchEvent(new MockUiEvent("click", { clientX: 90, clientY: 185 }));
|
|
961
|
+
assert.equal(widget.getElementReferences().length, 0);
|
|
962
|
+
|
|
963
|
+
// Pin again, then press Escape once to exit Pin Mode and restore composer
|
|
964
|
+
mockWindow.dispatchEvent(new MockUiEvent("click", { clientX: 90, clientY: 185 }));
|
|
965
|
+
assert.equal(widget.getElementReferences().length, 1);
|
|
966
|
+
|
|
967
|
+
mockWindow.dispatchEvent(new MockUiEvent("keydown", { key: "Escape" }));
|
|
968
|
+
assert.equal(composer.hidden, false);
|
|
969
|
+
assert.equal(compactBar.hidden, true);
|
|
970
|
+
assert.equal(mockBody.querySelector("[data-context-drop-ui='pinned-badge']"), null);
|
|
971
|
+
});
|
|
972
|
+
});
|
|
818
973
|
});
|