Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,12 @@
"@wordpress/i18n__non-shim",
"@wordpress/api-fetch__non-shim"
],
"import/parsers": {
"@typescript-eslint/parser": [
".ts",
".tsx"
]
},
"import/resolver": {
"alias": {
"map": [
Expand All @@ -149,10 +155,41 @@
"@wordpress"
]
]
},
"node": {
"extensions": [
".js",
".jsx",
".ts",
".tsx"
]
},
"typescript": {
"alwaysTryTypes": true
}
}
},
"overrides": [
{
"files": [
"**/*.ts",
"**/*.tsx"
],
"extends": [
"plugin:@typescript-eslint/recommended"
],
"parser": "@typescript-eslint/parser",
"parserOptions": {
"ecmaVersion": 2024
},
"env": {
"browser": true
},
"globals": {
"browser": true,
"page": true
}
},
{
"files": [
"tests/e2e/**/*.js"
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
14
16
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This PR should probably be rebased on the current develop as it's out of date with the current version of Node, deps, etc.

Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,21 @@

import { useWindowWidth } from './useWindowSize';

/**
* Breakpoint for an extra large screen (over `1280px` wide).
*/
export const BREAKPOINT_XLARGE = 'xlarge';
/**
* Breakpoint for a desktop screen (over `960px` wide).
*/
export const BREAKPOINT_DESKTOP = 'desktop';
/**
* Breakpoint for a tablet screen (over `600px` wide).
*/
export const BREAKPOINT_TABLET = 'tablet';
/**
* Breakpoint for a mobile phone screen (any screen `600px` wide or less).
*/
export const BREAKPOINT_SMALL = 'small';

/**
Expand All @@ -31,17 +43,17 @@ export const BREAKPOINT_SMALL = 'small';
* @return {string} The current breakpoint according to the window size.
*/
export function useBreakpoint() {
const onlyWidth = useWindowWidth();
const windowWidth = useWindowWidth();

if ( onlyWidth > 1280 ) {
if ( windowWidth > 1280 ) {
return BREAKPOINT_XLARGE;
}

if ( onlyWidth > 960 ) {
if ( windowWidth > 960 ) {
return BREAKPOINT_DESKTOP;
}

if ( onlyWidth > 600 ) {
if ( windowWidth > 600 ) {
return BREAKPOINT_TABLET;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,24 @@
import { useThrottle } from '@react-hook/throttle';
import useEvent from '@react-hook/event';

const emptyObj = {};

const win = typeof global === 'undefined' ? null : global;
function getSize() {
return [ global.innerWidth, global.innerHeight ];
}

export function useWindowSize( options = emptyObj ) {
const { fps, leading, initialWidth = 0, initialHeight = 0 } = options;
type UseWindowSizeOptions = {
fps?: number;
leading?: boolean;
initialWidth?: number;
initialHeight?: number;
};

export function useWindowSize( {
fps = 60,
leading = false,
initialWidth = 0,
initialHeight = 0,
}: UseWindowSizeOptions = {} ) {
const [ size, setThrottledSize ] = useThrottle(
/* istanbul ignore next */
typeof document === 'undefined'
Expand All @@ -42,20 +51,21 @@ export function useWindowSize( options = emptyObj ) {
fps,
leading
);

function setSize() {
return setThrottledSize( getSize );
}

useEvent( win, 'resize', setSize );
useEvent( win, 'orientationchange', setSize );
useEvent( win as unknown as Window, 'resize', setSize );
useEvent( win as unknown as Window, 'orientationchange', setSize );

return size;
}

export function useWindowHeight( options ) {
export function useWindowHeight( options: UseWindowSizeOptions = {} ): number {
return useWindowSize( options )[ 1 ];
}

export function useWindowWidth( options ) {
export function useWindowWidth( options: UseWindowSizeOptions = {} ): number {
return useWindowSize( options )[ 0 ];
}
File renamed without changes.
13 changes: 10 additions & 3 deletions assets/js/util/escape-uri.js → assets/js/util/escape-uri.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* limitations under the License.
*/

/**

Check failure on line 19 in assets/js/util/escape-uri.ts

View workflow job for this annotation

GitHub Actions / JS + CSS

Missing JSDoc for parameter 'strings'

Check failure on line 19 in assets/js/util/escape-uri.ts

View workflow job for this annotation

GitHub Actions / JS + CSS

Missing JSDoc @param "values" declaration

Check failure on line 19 in assets/js/util/escape-uri.ts

View workflow job for this annotation

GitHub Actions / JS + CSS

Missing JSDoc @param "strings" declaration
* Escapes URI components in a template string as a tag function.
*
* @example
Expand All @@ -26,11 +26,18 @@
*
* @since 1.11.0
*
* @param {string[]} strings The array of static strings in the template.
* @param {...*} values The array of expressions used in the template.
* @return {string} Escaped URI string.
*/
export function escapeURI( strings, ...values ) {
export function escapeURI(
/**

Check failure on line 32 in assets/js/util/escape-uri.ts

View workflow job for this annotation

GitHub Actions / JS + CSS

The first word in a function’s description should be a third-person verb (eg "runs" not "run")
* The array of static strings in the template.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Strange that this flags the inner comment as if it's a doc block for the function

*/
strings: TemplateStringsArray,
/**
* The array of expressions used in the template.
*/
...values: string[]
): string {
return strings.reduce( ( acc, string, idx ) => {
return acc + string + encodeURIComponent( values[ idx ] || '' );
}, '' );
Expand Down
Loading
Loading