Skip to content

Commit

Permalink
fix: avoid using deprecated jQuery functions to prepare for jQuery 4 … (
Browse files Browse the repository at this point in the history
#780)

* fix: avoid using deprecated jQuery functions to prepare for jQuery 4 (#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]>
  • Loading branch information
onestep and josteink authored Mar 7, 2024
1 parent 9776166 commit 7cd405b
Show file tree
Hide file tree
Showing 11 changed files with 94 additions and 114 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ trim_trailing_whitespace = true
max_line_length = off
trim_trailing_whitespace = false

[*.{js,json}]
[*.{ts,js,json}]
quote_type = double
indent_style = space
indent_size = 4
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
.idea
node_modules
**/*~
**/.#*
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

## Version 1.1.13

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

## Version 1.1.12
Expand Down
22 changes: 2 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,9 @@
"gmail chrome extension",
"gmail firefox extension"
],
"dependencies": {
"jquery": "^3.6.1"
},
"devDependencies": {
"@types/jquery": "^3.5.14",
"eslint": "^8.23.1",
"gmail-js": "^1.1.0",
"jest": "^29.5.0",
"jest-junit": "^16.0.0",
"jsdom": "^20.0.0",
Expand Down
69 changes: 36 additions & 33 deletions src/gmail.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ declare type StringDict = {
//
////////////////////////////////////////////////////////////////////////////////

interface GmailTracker {
interface GmailTracker<T extends string = never> {
dom_observers: { [observer in GmailDomObserver | T]?: DomObserverConfig };
globals: any[];
view_data: any[];
ik: string;
hangouts: any;
events: {}[];
actions: {}[];
watchdog: {
before: {},
on: {},
after: {},
dom: {}
before: { [action in GmailBindAction | T]?: Function[] };
on: { [action in GmailBindAction | T]?: Function[] };
after: { [action in GmailBindAction | T]?: Function[] };
dom: { [observer in GmailDomObserver | T]?: Function[] };
};
}

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

declare type GmailDomComposeRecipients = {
to: string[];
cc: string[];
bcc: string[];
to: string[];
cc: string[];
bcc: string[];
}

declare type GmailAttachmentDetails = {
Expand Down Expand Up @@ -489,7 +490,7 @@ interface GmailDomEmail {

declare type GmailDomComposeLookup =
'to' | 'cc' | 'bcc' | 'id' | 'draft' | 'subject' | 'subjectbox'
| 'all_subjects' | 'body' | 'quoted_reply' |'reply' | 'forward' | 'from' | 'send_button' | 'show_cc' | 'show_bcc';
| 'all_subjects' | 'body' | 'quoted_reply' | 'reply' | 'forward' | 'from' | 'send_button' | 'show_cc' | 'show_bcc';

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

make_request(link: string, method: GmailHttpRequestMethod, disable_cache: boolean): string;
make_request_async(link: string, method: GmailHttpRequestMethod, callback: (data: string) => void, disable_cache: boolean): void;
Expand Down Expand Up @@ -718,11 +719,11 @@ interface GmailTools {
add_right_toolbar_button(content_html: string, onClickFunction: Function, styleClass: string): JQuery;
add_compose_button(composeWindow: GmailDomCompose, content_html: string, onClickFunction: Function, styleClass?: string): JQuery;
add_more_send_option(
composeWindow: GmailDomCompose,
buttonText: string,
onClickFunction: Function,
styleClass?: string | undefined,
imgClass?: string | undefined
composeWindow: GmailDomCompose,
buttonText: string,
onClickFunction: Function,
styleClass?: string | undefined,
imgClass?: string | undefined
): JQuery;
/**
adds a button to an email attachment.
Expand Down Expand Up @@ -764,23 +765,25 @@ declare type GmailBindAction =
| 'new_email' | 'refresh' | 'open_email' | 'upload_attachment' | 'compose'
| 'compose_cancelled' | 'recipient_change' | 'view_thread' | 'view_email'
| 'load_email_menu';
declare type GmailDomObserver =
'view_thread' | 'view_email' | 'load_email_menu' | 'recipient_change' | 'compose'

interface HttpEventRequestParams {
url: object,
url_raw: string;
body: string;
body_params: object;
method: string;
url: object,
url_raw: string;
body: string;
body_params: object;
method: string;
}

interface DomObserverConfig {
class: string | string[];
selector?: string;
sub_selector?: string;
handler?: Function;
}
class: string | string[];
selector?: string;
sub_selector?: string;
handler?: Function;
}

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

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

initialize_dom_observers(): void;

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

declare class Gmail<T extends string=never> {
constructor(localJQuery?: JQueryStatic);
declare class Gmail<T extends string = never> {
constructor(localJQuery: JQueryStatic | false);

version: string;
/**
These are some of the variables that are tracked and kept in
memory while the rest of the methods are in use.
*/
tracker: GmailTracker;
tracker: GmailTracker<T>;
get: GmailGet;
check: GmailCheck;
/**
Expand Down
Loading

0 comments on commit 7cd405b

Please sign in to comment.