Skip to content

Commit 7cd405b

Browse files
onestepjosteink
andauthored
fix: avoid using deprecated jQuery functions to prepare for jQuery 4 … (KartikTalwar#780)
* fix: avoid using deprecated jQuery functions to prepare for jQuery 4 (KartikTalwar#779) - some DOM check functions were rewritten to use native DOM API - jquery 3 dependency was removed from package.json - updated some function signatures in type definitions * Fixup constructor parameter types. Fix editor-config for typescript too. --------- Co-authored-by: Jostein Kjønigsen <[email protected]>
1 parent 9776166 commit 7cd405b

11 files changed

+94
-114
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trim_trailing_whitespace = true
1111
max_line_length = off
1212
trim_trailing_whitespace = false
1313

14-
[*.{js,json}]
14+
[*.{ts,js,json}]
1515
quote_type = double
1616
indent_style = space
1717
indent_size = 4

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
2+
.idea
23
node_modules
34
**/*~
45
**/.#*

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
## Version 1.1.13
55

6+
- Drop bundled jQuery, support jQuery 4, support explicit no-jQuery mode
67
- Fix reply button selector to support Gmail in text labels mode
78

89
## Version 1.1.12

package-lock.json

+2-20
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

-4
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,9 @@
2222
"gmail chrome extension",
2323
"gmail firefox extension"
2424
],
25-
"dependencies": {
26-
"jquery": "^3.6.1"
27-
},
2825
"devDependencies": {
2926
"@types/jquery": "^3.5.14",
3027
"eslint": "^8.23.1",
31-
"gmail-js": "^1.1.0",
3228
"jest": "^29.5.0",
3329
"jest-junit": "^16.0.0",
3430
"jsdom": "^20.0.0",

src/gmail.d.ts

+36-33
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,19 @@ declare type StringDict = {
2323
//
2424
////////////////////////////////////////////////////////////////////////////////
2525

26-
interface GmailTracker {
26+
interface GmailTracker<T extends string = never> {
27+
dom_observers: { [observer in GmailDomObserver | T]?: DomObserverConfig };
2728
globals: any[];
2829
view_data: any[];
2930
ik: string;
3031
hangouts: any;
3132
events: {}[];
3233
actions: {}[];
3334
watchdog: {
34-
before: {},
35-
on: {},
36-
after: {},
37-
dom: {}
35+
before: { [action in GmailBindAction | T]?: Function[] };
36+
on: { [action in GmailBindAction | T]?: Function[] };
37+
after: { [action in GmailBindAction | T]?: Function[] };
38+
dom: { [observer in GmailDomObserver | T]?: Function[] };
3839
};
3940
}
4041

@@ -55,9 +56,9 @@ declare type GmailPageType =
5556
declare type GmailEmailAddress = string[];
5657

5758
declare type GmailDomComposeRecipients = {
58-
to: string[];
59-
cc: string[];
60-
bcc: string[];
59+
to: string[];
60+
cc: string[];
61+
bcc: string[];
6162
}
6263

6364
declare type GmailAttachmentDetails = {
@@ -489,7 +490,7 @@ interface GmailDomEmail {
489490

490491
declare type GmailDomComposeLookup =
491492
'to' | 'cc' | 'bcc' | 'id' | 'draft' | 'subject' | 'subjectbox'
492-
| 'all_subjects' | 'body' | 'quoted_reply' |'reply' | 'forward' | 'from' | 'send_button' | 'show_cc' | 'show_bcc';
493+
| 'all_subjects' | 'body' | 'quoted_reply' | 'reply' | 'forward' | 'from' | 'send_button' | 'show_cc' | 'show_bcc';
493494

494495
interface GmailMessageRow {
495496
summary: string;
@@ -671,7 +672,7 @@ interface GmailTools {
671672
observes every element inserted into the DOM by Gmail and looks at the classes on those elements,
672673
checking for any configured observers related to those classes
673674
*/
674-
insertion_observer(target: HTMLElement | string, dom_observers: any, dom_observer_map: any, sub: any): void;
675+
insertion_observer(target: HTMLElement | string, dom_observers: { [observer: string]: DomObserverConfig }, dom_observer_map: { [className: string]: string[] }, sub?: string): void;
675676

676677
make_request(link: string, method: GmailHttpRequestMethod, disable_cache: boolean): string;
677678
make_request_async(link: string, method: GmailHttpRequestMethod, callback: (data: string) => void, disable_cache: boolean): void;
@@ -718,11 +719,11 @@ interface GmailTools {
718719
add_right_toolbar_button(content_html: string, onClickFunction: Function, styleClass: string): JQuery;
719720
add_compose_button(composeWindow: GmailDomCompose, content_html: string, onClickFunction: Function, styleClass?: string): JQuery;
720721
add_more_send_option(
721-
composeWindow: GmailDomCompose,
722-
buttonText: string,
723-
onClickFunction: Function,
724-
styleClass?: string | undefined,
725-
imgClass?: string | undefined
722+
composeWindow: GmailDomCompose,
723+
buttonText: string,
724+
onClickFunction: Function,
725+
styleClass?: string | undefined,
726+
imgClass?: string | undefined
726727
): JQuery;
727728
/**
728729
adds a button to an email attachment.
@@ -764,23 +765,25 @@ declare type GmailBindAction =
764765
| 'new_email' | 'refresh' | 'open_email' | 'upload_attachment' | 'compose'
765766
| 'compose_cancelled' | 'recipient_change' | 'view_thread' | 'view_email'
766767
| 'load_email_menu';
768+
declare type GmailDomObserver =
769+
'view_thread' | 'view_email' | 'load_email_menu' | 'recipient_change' | 'compose'
767770

768771
interface HttpEventRequestParams {
769-
url: object,
770-
url_raw: string;
771-
body: string;
772-
body_params: object;
773-
method: string;
772+
url: object,
773+
url_raw: string;
774+
body: string;
775+
body_params: object;
776+
method: string;
774777
}
775778

776779
interface DomObserverConfig {
777-
class: string | string[];
778-
selector?: string;
779-
sub_selector?: string;
780-
handler?: Function;
781-
}
780+
class: string | string[];
781+
selector?: string;
782+
sub_selector?: string;
783+
handler?: Function;
784+
}
782785

783-
interface GmailObserve<T extends string=never> {
786+
interface GmailObserve<T extends string = never> {
784787
/**
785788
After an observer has been bound through gmail.observe.bind() (via a
786789
call to events gmail.observe.before(), gmail.observe.on(), or
@@ -798,7 +801,7 @@ interface GmailObserve<T extends string=never> {
798801
/**
799802
Bind a specified callback to an array of callbacks against a specified type & action
800803
*/
801-
bind(type: GmailBindType, action: Function, callback: Function): void;
804+
bind(type: GmailBindType, action: GmailBindAction | T, callback: Function): void;
802805

803806
/**
804807
an on event is observed just after gmail sends an xhr request
@@ -850,11 +853,11 @@ interface GmailObserve<T extends string=never> {
850853
Trigger any specified events bound to the passed type
851854
Returns true or false depending if any events were fired
852855
*/
853-
trigger(type: GmailBindType, events: any, xhr: XMLHttpRequest): boolean;
856+
trigger(type: GmailBindType, events: { [action in GmailBindAction | T]?: any[] }, xhr: XMLHttpRequest): boolean;
854857
/**
855858
Trigger any specified DOM events passing a specified element & optional handler
856859
*/
857-
trigger_dom(observer: any, element: HTMLElement, handler?: Function): void;
860+
trigger_dom(observer: GmailDomObserver | T, element: HTMLElement, handler?: Function): void;
858861

859862
initialize_dom_observers(): void;
860863

@@ -867,7 +870,7 @@ interface GmailObserve<T extends string=never> {
867870
className / args - for a simple observer, this arg can simply be the class on an inserted DOM element that identifies this event should be
868871
triggered. For a more complicated observer, this can be an object containing properties for each of the supported DOM observer config arguments
869872
*/
870-
register(action: string, args: string | DomObserverConfig): void;
873+
register(action: T, args: string | DomObserverConfig): void;
871874
/**
872875
Observe DOM nodes being inserted. When a node with a class defined in api.tracker.dom_observers is inserted,
873876
trigger the related event and fire off any relevant bound callbacks
@@ -1030,15 +1033,15 @@ interface GmailCache {
10301033
//
10311034
////////////////////////////////////////////////////////////////////////////////
10321035

1033-
declare class Gmail<T extends string=never> {
1034-
constructor(localJQuery?: JQueryStatic);
1036+
declare class Gmail<T extends string = never> {
1037+
constructor(localJQuery: JQueryStatic | false);
10351038

10361039
version: string;
10371040
/**
10381041
These are some of the variables that are tracked and kept in
10391042
memory while the rest of the methods are in use.
10401043
*/
1041-
tracker: GmailTracker;
1044+
tracker: GmailTracker<T>;
10421045
get: GmailGet;
10431046
check: GmailCheck;
10441047
/**

0 commit comments

Comments
 (0)