@wordpress/compose 8.1.0 → 8.1.2-next.v.202606191442.0
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.
- package/CHANGELOG.md +20 -1
- package/README.md +46 -42
- package/build/higher-order/pure/index.cjs +15 -0
- package/build/higher-order/pure/index.cjs.map +3 -3
- package/build/hooks/use-constrained-tabbing/index.cjs +3 -9
- package/build/hooks/use-constrained-tabbing/index.cjs.map +3 -3
- package/build/hooks/use-debounce/index.cjs +1 -1
- package/build/hooks/use-debounce/index.cjs.map +3 -3
- package/build/hooks/use-disabled/index.cjs.map +2 -2
- package/build/hooks/use-dragging/index.cjs +27 -22
- package/build/hooks/use-dragging/index.cjs.map +4 -4
- package/build/hooks/use-dragging/types.cjs +19 -0
- package/build/hooks/use-dragging/types.cjs.map +7 -0
- package/build/hooks/use-drop-zone/index.cjs +2 -5
- package/build/hooks/use-drop-zone/index.cjs.map +3 -3
- package/build/hooks/use-drop-zone/types.cjs +19 -0
- package/build/hooks/use-drop-zone/types.cjs.map +7 -0
- package/build/hooks/use-fixed-window-list/index.cjs +10 -8
- package/build/hooks/use-fixed-window-list/index.cjs.map +3 -3
- package/build/hooks/use-focus-return/index.cjs +12 -9
- package/build/hooks/use-focus-return/index.cjs.map +3 -3
- package/build/hooks/use-isomorphic-layout-effect/index.cjs +1 -1
- package/build/hooks/use-isomorphic-layout-effect/index.cjs.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.cjs +1 -4
- package/build/hooks/use-keyboard-shortcut/index.cjs.map +3 -3
- package/build/hooks/use-media-query/index.cjs +2 -2
- package/build/hooks/use-media-query/index.cjs.map +2 -2
- package/build/hooks/use-merge-refs/index.cjs +28 -8
- package/build/hooks/use-merge-refs/index.cjs.map +2 -2
- package/build/hooks/use-reduced-motion/index.cjs +1 -1
- package/build/hooks/use-reduced-motion/index.cjs.map +2 -2
- package/build/hooks/use-throttle/index.cjs +1 -1
- package/build/hooks/use-throttle/index.cjs.map +3 -3
- package/build/hooks/use-viewport-match/index.cjs +3 -6
- package/build/hooks/use-viewport-match/index.cjs.map +3 -3
- package/build/hooks/use-warn-on-change/index.cjs +3 -10
- package/build/hooks/use-warn-on-change/index.cjs.map +3 -3
- package/build/utils/subscribe-delegated-listener/index.cjs.map +1 -1
- package/build-module/higher-order/pure/index.mjs +5 -0
- package/build-module/higher-order/pure/index.mjs.map +2 -2
- package/build-module/hooks/use-constrained-tabbing/index.mjs +3 -9
- package/build-module/hooks/use-constrained-tabbing/index.mjs.map +3 -3
- package/build-module/hooks/use-debounce/index.mjs +1 -1
- package/build-module/hooks/use-debounce/index.mjs.map +3 -3
- package/build-module/hooks/use-disabled/index.mjs.map +2 -2
- package/build-module/hooks/use-dragging/index.mjs +27 -22
- package/build-module/hooks/use-dragging/index.mjs.map +4 -4
- package/build-module/hooks/use-dragging/types.mjs +1 -0
- package/build-module/hooks/use-dragging/types.mjs.map +7 -0
- package/build-module/hooks/use-drop-zone/index.mjs +2 -5
- package/build-module/hooks/use-drop-zone/index.mjs.map +3 -3
- package/build-module/hooks/use-drop-zone/types.mjs +1 -0
- package/build-module/hooks/use-drop-zone/types.mjs.map +7 -0
- package/build-module/hooks/use-fixed-window-list/index.mjs +10 -8
- package/build-module/hooks/use-fixed-window-list/index.mjs.map +3 -3
- package/build-module/hooks/use-focus-return/index.mjs +12 -9
- package/build-module/hooks/use-focus-return/index.mjs.map +3 -3
- package/build-module/hooks/use-isomorphic-layout-effect/index.mjs +1 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.mjs.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.mjs +1 -4
- package/build-module/hooks/use-keyboard-shortcut/index.mjs.map +3 -3
- package/build-module/hooks/use-media-query/index.mjs +2 -2
- package/build-module/hooks/use-media-query/index.mjs.map +2 -2
- package/build-module/hooks/use-merge-refs/index.mjs +28 -8
- package/build-module/hooks/use-merge-refs/index.mjs.map +2 -2
- package/build-module/hooks/use-reduced-motion/index.mjs +1 -1
- package/build-module/hooks/use-reduced-motion/index.mjs.map +2 -2
- package/build-module/hooks/use-throttle/index.mjs +1 -1
- package/build-module/hooks/use-throttle/index.mjs.map +3 -3
- package/build-module/hooks/use-viewport-match/index.mjs +3 -6
- package/build-module/hooks/use-viewport-match/index.mjs.map +3 -3
- package/build-module/hooks/use-warn-on-change/index.mjs +3 -10
- package/build-module/hooks/use-warn-on-change/index.mjs.map +3 -3
- package/build-module/utils/subscribe-delegated-listener/index.mjs.map +1 -1
- package/build-types/higher-order/pure/index.d.ts.map +1 -1
- package/build-types/hooks/use-constrained-tabbing/index.d.ts +2 -2
- package/build-types/hooks/use-constrained-tabbing/index.d.ts.map +1 -1
- package/build-types/hooks/use-debounce/index.d.ts +7 -6
- package/build-types/hooks/use-debounce/index.d.ts.map +1 -1
- package/build-types/hooks/use-disabled/index.d.ts +1 -1
- package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
- package/build-types/hooks/use-dragging/index.d.ts +9 -13
- package/build-types/hooks/use-dragging/index.d.ts.map +1 -1
- package/build-types/hooks/use-dragging/types.d.ts +11 -0
- package/build-types/hooks/use-dragging/types.d.ts.map +1 -0
- package/build-types/hooks/use-drop-zone/index.d.ts +4 -21
- package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
- package/build-types/hooks/use-drop-zone/types.d.ts +35 -0
- package/build-types/hooks/use-drop-zone/types.d.ts.map +1 -0
- package/build-types/hooks/use-fixed-window-list/index.d.ts +22 -26
- package/build-types/hooks/use-fixed-window-list/index.d.ts.map +1 -1
- package/build-types/hooks/use-focus-return/index.d.ts +3 -3
- package/build-types/hooks/use-focus-return/index.d.ts.map +1 -1
- package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts.map +1 -1
- package/build-types/hooks/use-keyboard-shortcut/index.d.ts +29 -23
- package/build-types/hooks/use-keyboard-shortcut/index.d.ts.map +1 -1
- package/build-types/hooks/use-media-query/index.d.ts +1 -1
- package/build-types/hooks/use-media-query/index.d.ts.map +1 -1
- package/build-types/hooks/use-merge-refs/index.d.ts +7 -5
- package/build-types/hooks/use-merge-refs/index.d.ts.map +1 -1
- package/build-types/hooks/use-reduced-motion/index.d.ts +1 -1
- package/build-types/hooks/use-reduced-motion/index.d.ts.map +1 -1
- package/build-types/hooks/use-throttle/index.d.ts +8 -6
- package/build-types/hooks/use-throttle/index.d.ts.map +1 -1
- package/build-types/hooks/use-viewport-match/index.d.ts +3 -3
- package/build-types/hooks/use-viewport-match/index.d.ts.map +1 -1
- package/build-types/hooks/use-warn-on-change/index.d.ts +7 -7
- package/build-types/hooks/use-warn-on-change/index.d.ts.map +1 -1
- package/package.json +21 -12
- package/src/higher-order/pure/index.tsx +6 -0
- package/src/higher-order/pure/test/index.js +14 -81
- package/src/hooks/use-constrained-tabbing/{index.js → index.ts} +7 -11
- package/src/hooks/use-debounce/{index.js → index.ts} +11 -6
- package/src/hooks/use-disabled/index.ts +3 -1
- package/src/hooks/use-dragging/index.ts +78 -0
- package/src/hooks/use-dragging/types.ts +11 -0
- package/src/hooks/use-drop-zone/README.md +1 -1
- package/src/hooks/use-drop-zone/{index.js → index.ts} +17 -31
- package/src/hooks/use-drop-zone/types.ts +34 -0
- package/src/hooks/use-fixed-window-list/{index.js → index.ts} +46 -37
- package/src/hooks/use-focus-return/{index.js → index.ts} +26 -21
- package/src/hooks/use-keyboard-shortcut/{index.js → index.ts} +43 -28
- package/src/hooks/use-media-query/index.ts +10 -3
- package/src/hooks/use-media-query/test/ssr.js +47 -0
- package/src/hooks/use-merge-refs/index.ts +49 -18
- package/src/hooks/use-merge-refs/test/index.js +288 -0
- package/src/hooks/use-reduced-motion/{index.js → index.ts} +2 -2
- package/src/hooks/use-throttle/{index.js → index.ts} +12 -6
- package/src/hooks/use-viewport-match/{index.js → index.ts} +33 -26
- package/src/hooks/use-warn-on-change/index.ts +42 -0
- package/src/higher-order/with-network-connectivity/README.md +0 -20
- package/src/higher-order/with-network-connectivity/index.native.js +0 -19
- package/src/higher-order/with-preferred-color-scheme/index.native.js +0 -40
- package/src/hooks/use-constrained-tabbing/index.native.js +0 -14
- package/src/hooks/use-dragging/index.js +0 -74
- package/src/hooks/use-focus-outside/index.native.js +0 -170
- package/src/hooks/use-keyboard-shortcut/index.native.js +0 -2
- package/src/hooks/use-network-connectivity/index.native.js +0 -59
- package/src/hooks/use-network-connectivity/test/index.native.js +0 -87
- package/src/hooks/use-preferred-color-scheme/index.android.js +0 -30
- package/src/hooks/use-preferred-color-scheme/index.ios.js +0 -13
- package/src/hooks/use-preferred-color-scheme-style/index.native.js +0 -33
- package/src/hooks/use-resize-observer/index.native.js +0 -1
- package/src/hooks/use-resize-observer/legacy/index.native.js +0 -59
- package/src/hooks/use-resize-observer/legacy/test/index.native.js +0 -46
- package/src/hooks/use-warn-on-change/index.js +0 -43
- package/src/index.native.js +0 -44
- /package/src/hooks/use-isomorphic-layout-effect/{index.js → index.ts} +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/subscribe-delegated-listener/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Adds a callback to a shared `addEventListener`. Only one underlying\n * native listener is attached per (root, event type, phase); subscribers\n * join an in-JS registry that dispatches events along the DOM ancestry\n * of `event.target`.\n *\n * The model mirrors React's synthetic event system: a single root\n * listener handles every event of a given type, and callbacks bound to\n * an `Element` only fire when that element is on the target's path.\n * Callbacks bound to a `Document` always fire (document is the root of\n * every event in that document); callbacks bound to a `Window` always\n * fire as a flat fan-out, since `window` isn't on the DOM tree.\n *\n * @param target `Element`, `Document`, or `Window` to bind the\n * callback to. For `Element`, the callback only fires\n * when the event happens on the element or a\n * descendant.\n * @param eventType DOM event name.\n * @param callback Listener to be invoked with the event.\n * @param capture Use the capture phase. Required when ancestor\n * listeners gate on `event.defaultPrevented`, since a\n * bubble-phase root listener fires after them. Defaults\n * to `false`.\n * @return Unsubscribe function.\n */\n// root -> eventTypeKey -> subscribedTarget -> Set<callback>\n//\n// Inner registry is a `WeakMap`: element subscribers are held weakly so\n// an iframe removal lets the iframe's Elements (and through them, its\n// `ownerDocument`) be garbage-collected. The native listener is\n// attached to the document itself, so it goes when the document goes.\nconst registries = new WeakMap<\n\tEventTarget,\n\tMap< string, WeakMap< EventTarget, Set< EventListener > > >\n>();\n\nexport default function subscribeDelegatedListener(\n\ttarget: EventTarget,\n\teventType: string,\n\tcallback: EventListener,\n\tcapture: boolean = false\n): () => void {\n\t// Where the native listener is attached:\n\t// Element
|
|
4
|
+
"sourcesContent": ["/**\n * Adds a callback to a shared `addEventListener`. Only one underlying\n * native listener is attached per (root, event type, phase); subscribers\n * join an in-JS registry that dispatches events along the DOM ancestry\n * of `event.target`.\n *\n * The model mirrors React's synthetic event system: a single root\n * listener handles every event of a given type, and callbacks bound to\n * an `Element` only fire when that element is on the target's path.\n * Callbacks bound to a `Document` always fire (document is the root of\n * every event in that document); callbacks bound to a `Window` always\n * fire as a flat fan-out, since `window` isn't on the DOM tree.\n *\n * @param target `Element`, `Document`, or `Window` to bind the\n * callback to. For `Element`, the callback only fires\n * when the event happens on the element or a\n * descendant.\n * @param eventType DOM event name.\n * @param callback Listener to be invoked with the event.\n * @param capture Use the capture phase. Required when ancestor\n * listeners gate on `event.defaultPrevented`, since a\n * bubble-phase root listener fires after them. Defaults\n * to `false`.\n * @return Unsubscribe function.\n */\n// root -> eventTypeKey -> subscribedTarget -> Set<callback>\n//\n// Inner registry is a `WeakMap`: element subscribers are held weakly so\n// an iframe removal lets the iframe's Elements (and through them, its\n// `ownerDocument`) be garbage-collected. The native listener is\n// attached to the document itself, so it goes when the document goes.\nconst registries = new WeakMap<\n\tEventTarget,\n\tMap< string, WeakMap< EventTarget, Set< EventListener > > >\n>();\n\nexport default function subscribeDelegatedListener(\n\ttarget: EventTarget,\n\teventType: string,\n\tcallback: EventListener,\n\tcapture: boolean = false\n): () => void {\n\t// Where the native listener is attached:\n\t// Element → its `ownerDocument`\n\t// Document → itself (own `ownerDocument` is `null`)\n\t// Window → itself (no `ownerDocument` property)\n\t// `undefined` (Window) → use a fan-out branch on dispatch since\n\t// events bubble *to* window but never *from* it via `parentNode`.\n\tconst ownerDoc = ( target as Node ).ownerDocument;\n\tconst root = ownerDoc ?? target;\n\tconst isWindow = ownerDoc === undefined;\n\n\tlet perRoot = registries.get( root );\n\tif ( ! perRoot ) {\n\t\tperRoot = new Map();\n\t\tregistries.set( root, perRoot );\n\t}\n\tconst key = capture ? `${ eventType }:capture` : eventType;\n\tlet perEvent = perRoot.get( key );\n\tif ( ! perEvent ) {\n\t\tperEvent = new WeakMap< EventTarget, Set< EventListener > >();\n\t\tperRoot.set( key, perEvent );\n\t\tconst subscribers = perEvent;\n\t\troot.addEventListener(\n\t\t\teventType,\n\t\t\t( event ) => {\n\t\t\t\tif ( isWindow ) {\n\t\t\t\t\t// Window has no DOM ancestry — all subscribers share\n\t\t\t\t\t// the window key; fetch its set and fan out.\n\t\t\t\t\tconst set = subscribers.get( root );\n\t\t\t\t\tif ( set ) {\n\t\t\t\t\t\tfor ( const cb of set ) {\n\t\t\t\t\t\t\tcb( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Walk the target → root ancestry, dispatching callbacks\n\t\t\t\t// for any node in the path. Bubble order matches the walk\n\t\t\t\t// direction, so dispatch inline (no path array). Capture\n\t\t\t\t// has to materialise the path to iterate in reverse.\n\t\t\t\tif ( capture ) {\n\t\t\t\t\tconst path: Array< Node | Document > = [];\n\t\t\t\t\tlet current: Node | null = event.target as Node | null;\n\t\t\t\t\twhile ( current ) {\n\t\t\t\t\t\tpath.push( current );\n\t\t\t\t\t\tif ( current === root ) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrent = current.parentNode;\n\t\t\t\t\t}\n\t\t\t\t\tfor ( let i = path.length - 1; i >= 0; i-- ) {\n\t\t\t\t\t\tconst set = subscribers.get( path[ i ] );\n\t\t\t\t\t\tif ( set ) {\n\t\t\t\t\t\t\tfor ( const cb of set ) {\n\t\t\t\t\t\t\t\tcb( event );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlet current: Node | null = event.target as Node | null;\n\t\t\t\t\twhile ( current ) {\n\t\t\t\t\t\tconst set = subscribers.get( current );\n\t\t\t\t\t\tif ( set ) {\n\t\t\t\t\t\t\tfor ( const cb of set ) {\n\t\t\t\t\t\t\t\tcb( event );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( current === root ) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrent = current.parentNode;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tcapture\n\t\t);\n\t}\n\tlet set = perEvent.get( target );\n\tif ( ! set ) {\n\t\tset = new Set();\n\t\tperEvent.set( target, set );\n\t}\n\tset.add( callback );\n\treturn () => {\n\t\tset.delete( callback );\n\t};\n}\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA+BA,IAAM,aAAa,oBAAI,QAGrB;AAEa,SAAR,2BACN,QACA,WACA,UACA,UAAmB,OACN;AAOb,QAAM,WAAa,OAAiB;AACpC,QAAM,OAAO,YAAY;AACzB,QAAM,WAAW,aAAa;AAE9B,MAAI,UAAU,WAAW,IAAK,IAAK;AACnC,MAAK,CAAE,SAAU;AAChB,cAAU,oBAAI,IAAI;AAClB,eAAW,IAAK,MAAM,OAAQ;AAAA,EAC/B;AACA,QAAM,MAAM,UAAU,GAAI,SAAU,aAAa;AACjD,MAAI,WAAW,QAAQ,IAAK,GAAI;AAChC,MAAK,CAAE,UAAW;AACjB,eAAW,oBAAI,QAA6C;AAC5D,YAAQ,IAAK,KAAK,QAAS;AAC3B,UAAM,cAAc;AACpB,SAAK;AAAA,MACJ;AAAA,MACA,CAAE,UAAW;AACZ,YAAK,UAAW;AAGf,gBAAMA,OAAM,YAAY,IAAK,IAAK;AAClC,cAAKA,MAAM;AACV,uBAAY,MAAMA,MAAM;AACvB,iBAAI,KAAM;AAAA,YACX;AAAA,UACD;AACA;AAAA,QACD;AAKA,YAAK,SAAU;AACd,gBAAM,OAAiC,CAAC;AACxC,cAAI,UAAuB,MAAM;AACjC,iBAAQ,SAAU;AACjB,iBAAK,KAAM,OAAQ;AACnB,gBAAK,YAAY,MAAO;AACvB;AAAA,YACD;AACA,sBAAU,QAAQ;AAAA,UACnB;AACA,mBAAU,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG,KAAM;AAC5C,kBAAMA,OAAM,YAAY,IAAK,KAAM,CAAE,CAAE;AACvC,gBAAKA,MAAM;AACV,yBAAY,MAAMA,MAAM;AACvB,mBAAI,KAAM;AAAA,cACX;AAAA,YACD;AAAA,UACD;AAAA,QACD,OAAO;AACN,cAAI,UAAuB,MAAM;AACjC,iBAAQ,SAAU;AACjB,kBAAMA,OAAM,YAAY,IAAK,OAAQ;AACrC,gBAAKA,MAAM;AACV,yBAAY,MAAMA,MAAM;AACvB,mBAAI,KAAM;AAAA,cACX;AAAA,YACD;AACA,gBAAK,YAAY,MAAO;AACvB;AAAA,YACD;AACA,sBAAU,QAAQ;AAAA,UACnB;AAAA,QACD;AAAA,MACD;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACA,MAAI,MAAM,SAAS,IAAK,MAAO;AAC/B,MAAK,CAAE,KAAM;AACZ,UAAM,oBAAI,IAAI;AACd,aAAS,IAAK,QAAQ,GAAI;AAAA,EAC3B;AACA,MAAI,IAAK,QAAS;AAClB,SAAO,MAAM;AACZ,QAAI,OAAQ,QAAS;AAAA,EACtB;AACD;",
|
|
6
6
|
"names": ["set"]
|
|
7
7
|
}
|
|
@@ -1,9 +1,14 @@
|
|
|
1
1
|
// packages/compose/src/higher-order/pure/index.tsx
|
|
2
2
|
import { isShallowEqual } from "@wordpress/is-shallow-equal";
|
|
3
3
|
import { Component } from "@wordpress/element";
|
|
4
|
+
import deprecated from "@wordpress/deprecated";
|
|
4
5
|
import { createHigherOrderComponent } from "../../utils/create-higher-order-component/index.mjs";
|
|
5
6
|
import { jsx } from "react/jsx-runtime";
|
|
6
7
|
var pure = createHigherOrderComponent(function(WrappedComponent) {
|
|
8
|
+
deprecated("wp.compose.pure", {
|
|
9
|
+
since: "7.1",
|
|
10
|
+
alternative: "Use `memo` or `PureComponent` instead"
|
|
11
|
+
});
|
|
7
12
|
if (WrappedComponent.prototype instanceof Component) {
|
|
8
13
|
return class extends WrappedComponent {
|
|
9
14
|
shouldComponentUpdate(nextProps, nextState) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/higher-order/pure/index.tsx"],
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentType, ComponentClass } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * Given a component returns the enhanced component augmented with a component\n * only re-rendering when its props/state change\n *\n * @deprecated Use `memo` or `PureComponent` instead.\n */\nconst pure = createHigherOrderComponent( function < Props extends {} >(\n\tWrappedComponent: ComponentType< Props >\n): ComponentType< Props > {\n\tif ( WrappedComponent.prototype instanceof Component ) {\n\t\treturn class extends ( WrappedComponent as ComponentClass< Props > ) {\n\t\t\tshouldComponentUpdate( nextProps: Props, nextState: any ) {\n\t\t\t\treturn (\n\t\t\t\t\t! isShallowEqual( nextProps, this.props ) ||\n\t\t\t\t\t! isShallowEqual( nextState, this.state )\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}\n\n\treturn class extends Component< Props > {\n\t\tshouldComponentUpdate( nextProps: Props ) {\n\t\t\treturn ! isShallowEqual( nextProps, this.props );\n\t\t}\n\n\t\trender() {\n\t\t\treturn <WrappedComponent { ...this.props } />;\n\t\t}\n\t};\n}, 'pure' );\n\nexport default pure;\n"],
|
|
5
|
-
"mappings": ";AAQA,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentType, ComponentClass } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { isShallowEqual } from '@wordpress/is-shallow-equal';\nimport { Component } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * Given a component returns the enhanced component augmented with a component\n * only re-rendering when its props/state change\n *\n * @deprecated Use `memo` or `PureComponent` instead.\n */\nconst pure = createHigherOrderComponent( function < Props extends {} >(\n\tWrappedComponent: ComponentType< Props >\n): ComponentType< Props > {\n\tdeprecated( 'wp.compose.pure', {\n\t\tsince: '7.1',\n\t\talternative: 'Use `memo` or `PureComponent` instead',\n\t} );\n\n\tif ( WrappedComponent.prototype instanceof Component ) {\n\t\treturn class extends ( WrappedComponent as ComponentClass< Props > ) {\n\t\t\tshouldComponentUpdate( nextProps: Props, nextState: any ) {\n\t\t\t\treturn (\n\t\t\t\t\t! isShallowEqual( nextProps, this.props ) ||\n\t\t\t\t\t! isShallowEqual( nextState, this.state )\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}\n\n\treturn class extends Component< Props > {\n\t\tshouldComponentUpdate( nextProps: Props ) {\n\t\t\treturn ! isShallowEqual( nextProps, this.props );\n\t\t}\n\n\t\trender() {\n\t\t\treturn <WrappedComponent { ...this.props } />;\n\t\t}\n\t};\n}, 'pure' );\n\nexport default pure;\n"],
|
|
5
|
+
"mappings": ";AAQA,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AAKvB,SAAS,kCAAkC;AAiCjC;AAzBV,IAAM,OAAO,2BAA4B,SACxC,kBACyB;AACzB,aAAY,mBAAmB;AAAA,IAC9B,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,MAAK,iBAAiB,qBAAqB,WAAY;AACtD,WAAO,cAAgB,iBAA8C;AAAA,MACpE,sBAAuB,WAAkB,WAAiB;AACzD,eACC,CAAE,eAAgB,WAAW,KAAK,KAAM,KACxC,CAAE,eAAgB,WAAW,KAAK,KAAM;AAAA,MAE1C;AAAA,IACD;AAAA,EACD;AAEA,SAAO,cAAc,UAAmB;AAAA,IACvC,sBAAuB,WAAmB;AACzC,aAAO,CAAE,eAAgB,WAAW,KAAK,KAAM;AAAA,IAChD;AAAA,IAEA,SAAS;AACR,aAAO,oBAAC,oBAAmB,GAAG,KAAK,OAAQ;AAAA,IAC5C;AAAA,EACD;AACD,GAAG,MAAO;AAEV,IAAO,eAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-constrained-tabbing/index.
|
|
1
|
+
// packages/compose/src/hooks/use-constrained-tabbing/index.ts
|
|
2
2
|
import { focus } from "@wordpress/dom";
|
|
3
3
|
import useRefEffect from "../use-ref-effect/index.mjs";
|
|
4
4
|
function useConstrainedTabbing() {
|
|
@@ -9,14 +9,8 @@ function useConstrainedTabbing() {
|
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
const action = shiftKey ? "findPrevious" : "findNext";
|
|
12
|
-
const nextElement = focus.tabbable[action](
|
|
13
|
-
|
|
14
|
-
target
|
|
15
|
-
) || null;
|
|
16
|
-
if (
|
|
17
|
-
/** @type {HTMLElement} */
|
|
18
|
-
target.contains(nextElement)
|
|
19
|
-
) {
|
|
12
|
+
const nextElement = focus.tabbable[action](target) || null;
|
|
13
|
+
if (target.contains(nextElement)) {
|
|
20
14
|
event.preventDefault();
|
|
21
15
|
nextElement?.focus();
|
|
22
16
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-constrained-tabbing/index.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In Dialogs/modals, the tabbing must be constrained to the content of\n * the wrapper element. This hook adds the behavior to the returned ref.\n *\n * @return
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa;AAKtB,OAAO,kBAAkB;AAuBzB,SAAS,
|
|
3
|
+
"sources": ["../../../src/hooks/use-constrained-tabbing/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In Dialogs/modals, the tabbing must be constrained to the content of\n * the wrapper element. This hook adds the behavior to the returned ref.\n *\n * @return Element Ref.\n *\n * @example\n * ```ts\n * import { useConstrainedTabbing } from '@wordpress/compose';\n *\n * const ConstrainedTabbingExample = () => {\n * const constrainedTabbingRef = useConstrainedTabbing()\n * return (\n * <div ref={ constrainedTabbingRef }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useConstrainedTabbing(): React.RefCallback< Element > {\n\treturn useRefEffect( ( node: HTMLElement ) => {\n\t\tfunction onKeyDown( event: KeyboardEvent ): void {\n\t\t\tconst { key, shiftKey, target } = event;\n\n\t\t\tif ( key !== 'Tab' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst action = shiftKey ? 'findPrevious' : 'findNext';\n\t\t\tconst nextElement =\n\t\t\t\tfocus.tabbable[ action ]( target as HTMLElement ) || null;\n\n\t\t\t// When the target element contains the element that is about to\n\t\t\t// receive focus, for example when the target is a tabbable\n\t\t\t// container, browsers may disagree on where to move focus next.\n\t\t\t// In this case we can't rely on native browsers behavior. We need\n\t\t\t// to manage focus instead.\n\t\t\t// See https://github.com/WordPress/gutenberg/issues/46041.\n\t\t\tif ( ( target as HTMLElement ).contains( nextElement ) ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tnextElement?.focus();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the element that is about to receive focus is inside the\n\t\t\t// area, rely on native browsers behavior and let tabbing follow\n\t\t\t// the native tab sequence.\n\t\t\tif ( node.contains( nextElement ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the element that is about to receive focus is outside the\n\t\t\t// area, move focus to a div and insert it at the start or end of\n\t\t\t// the area, depending on the direction. Without preventing default\n\t\t\t// behaviour, the browser will then move focus to the next element.\n\t\t\tconst domAction = shiftKey ? 'append' : 'prepend';\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst trap = ownerDocument.createElement( 'div' );\n\n\t\t\ttrap.tabIndex = -1;\n\t\t\tnode[ domAction ]( trap );\n\n\t\t\t// Remove itself when the trap loses focus.\n\t\t\ttrap.addEventListener( 'blur', () => node.removeChild( trap ) );\n\n\t\t\ttrap.focus();\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n\nexport default useConstrainedTabbing;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa;AAKtB,OAAO,kBAAkB;AAuBzB,SAAS,wBAAsD;AAC9D,SAAO,aAAc,CAAE,SAAuB;AAC7C,aAAS,UAAW,OAA6B;AAChD,YAAM,EAAE,KAAK,UAAU,OAAO,IAAI;AAElC,UAAK,QAAQ,OAAQ;AACpB;AAAA,MACD;AAEA,YAAM,SAAS,WAAW,iBAAiB;AAC3C,YAAM,cACL,MAAM,SAAU,MAAO,EAAG,MAAsB,KAAK;AAQtD,UAAO,OAAwB,SAAU,WAAY,GAAI;AACxD,cAAM,eAAe;AACrB,qBAAa,MAAM;AACnB;AAAA,MACD;AAKA,UAAK,KAAK,SAAU,WAAY,GAAI;AACnC;AAAA,MACD;AAMA,YAAM,YAAY,WAAW,WAAW;AACxC,YAAM,EAAE,cAAc,IAAI;AAC1B,YAAM,OAAO,cAAc,cAAe,KAAM;AAEhD,WAAK,WAAW;AAChB,WAAM,SAAU,EAAG,IAAK;AAGxB,WAAK,iBAAkB,QAAQ,MAAM,KAAK,YAAa,IAAK,CAAE;AAE9D,WAAK,MAAM;AAAA,IACZ;AAEA,SAAK,iBAAkB,WAAW,SAAU;AAC5C,WAAO,MAAM;AACZ,WAAK,oBAAqB,WAAW,SAAU;AAAA,IAChD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;AAEA,IAAO,kCAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-debounce/index.
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\n\n/**\n * Debounces a function similar to Lodash's `debounce`. A new debounced function will\n * be returned and any scheduled calls cancelled if any of the arguments change,\n * including the function to debounce, so please wrap functions created on\n * render in components in `useCallback`.\n *\n * @see https://lodash.com/docs/4#debounce\n *\n * @template
|
|
5
|
-
"mappings": ";AAGA,SAAS,kBAAkB;AAK3B,SAAS,iBAAiB;AAK1B,SAAS,gBAAgB;
|
|
3
|
+
"sources": ["../../../src/hooks/use-debounce/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\nimport type { DebounceOptions, DebouncedFunc } from '../../utils/debounce';\n\n/**\n * Debounces a function similar to Lodash's `debounce`. A new debounced function will\n * be returned and any scheduled calls cancelled if any of the arguments change,\n * including the function to debounce, so please wrap functions created on\n * render in components in `useCallback`.\n *\n * @see https://lodash.com/docs/4#debounce\n *\n * @template TFunc\n *\n * @param fn The function to debounce.\n * @param wait The number of milliseconds to delay.\n * @param options The options object.\n * @return Debounced function.\n */\nexport default function useDebounce< TFunc extends ( ...args: any[] ) => void >(\n\tfn: TFunc,\n\twait?: number,\n\toptions?: DebounceOptions\n): DebouncedFunc< TFunc > {\n\tconst debounced = useMemoOne(\n\t\t() => debounce( fn, wait ?? 0, options ),\n\t\t[ fn, wait, options?.leading, options?.trailing, options?.maxWait ]\n\t);\n\tuseEffect( () => () => debounced.cancel(), [ debounced ] );\n\treturn debounced;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,kBAAkB;AAK3B,SAAS,iBAAiB;AAK1B,SAAS,gBAAgB;AAkBV,SAAR,YACN,IACA,MACA,SACyB;AACzB,QAAM,YAAY;AAAA,IACjB,MAAM,SAAU,IAAI,QAAQ,GAAG,OAAQ;AAAA,IACvC,CAAE,IAAI,MAAM,SAAS,SAAS,SAAS,UAAU,SAAS,OAAQ;AAAA,EACnE;AACA,YAAW,MAAM,MAAM,UAAU,OAAO,GAAG,CAAE,SAAU,CAAE;AACzD,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/use-disabled/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In some circumstances, such as block previews, all focusable DOM elements\n * (input fields, links, buttons, etc.) need to be disabled. This hook adds the\n * behavior to disable nested DOM elements to the returned ref.\n *\n * If you can, prefer the use of the inert HTML attribute.\n *\n * @param {Object} config Configuration object.\n * @param {boolean=} config.isDisabled Whether the element should be disabled.\n * @return {React.RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useDisabled } from '@wordpress/compose';\n *\n * const DisabledExample = () => {\n * \tconst disabledRef = useDisabled();\n *\treturn (\n *\t\t<div ref={ disabledRef }>\n *\t\t\t<a href=\"#\">This link will have tabindex set to -1</a>\n *\t\t\t<input placeholder=\"This input will have the disabled attribute added to it.\" type=\"text\" />\n *\t\t</div>\n *\t);\n * };\n * ```\n */\nexport default function useDisabled( {\n\tisDisabled: isDisabledProp = false,\n} = {} ) {\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( isDisabledProp ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultView = node?.ownerDocument?.defaultView;\n\t\t\tif ( ! defaultView ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/** A variable keeping track of the previous updates in order to restore them. */\n\t\t\tconst updates:
|
|
5
|
-
"mappings": ";AAGA,SAAS,gBAAgB;AACzB,OAAO,kBAAkB;AA4BV,SAAR,YAA8B;AAAA,EACpC,YAAY,iBAAiB;AAC9B,
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In some circumstances, such as block previews, all focusable DOM elements\n * (input fields, links, buttons, etc.) need to be disabled. This hook adds the\n * behavior to disable nested DOM elements to the returned ref.\n *\n * If you can, prefer the use of the inert HTML attribute.\n *\n * @param {Object} config Configuration object.\n * @param {boolean=} config.isDisabled Whether the element should be disabled.\n * @return {React.RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useDisabled } from '@wordpress/compose';\n *\n * const DisabledExample = () => {\n * \tconst disabledRef = useDisabled();\n *\treturn (\n *\t\t<div ref={ disabledRef }>\n *\t\t\t<a href=\"#\">This link will have tabindex set to -1</a>\n *\t\t\t<input placeholder=\"This input will have the disabled attribute added to it.\" type=\"text\" />\n *\t\t</div>\n *\t);\n * };\n * ```\n */\nexport default function useDisabled( {\n\tisDisabled: isDisabledProp = false,\n}: {\n\tisDisabled?: boolean;\n} = {} ) {\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( isDisabledProp ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultView = node?.ownerDocument?.defaultView;\n\t\t\tif ( ! defaultView ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/** A variable keeping track of the previous updates in order to restore them. */\n\t\t\tconst updates: ( () => void )[] = [];\n\t\t\tconst disable = () => {\n\t\t\t\tnode.childNodes.forEach( ( child ) => {\n\t\t\t\t\tif ( ! ( child instanceof defaultView.HTMLElement ) ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif ( ! child.getAttribute( 'inert' ) ) {\n\t\t\t\t\t\tchild.setAttribute( 'inert', 'true' );\n\t\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\t\tchild.removeAttribute( 'inert' );\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Debounce re-disable since disabling process itself will incur\n\t\t\t// additional mutations which should be ignored.\n\t\t\tconst debouncedDisable = debounce( disable, 0, {\n\t\t\t\tleading: true,\n\t\t\t} );\n\t\t\tdisable();\n\n\t\t\t/** @type {MutationObserver | undefined} */\n\t\t\tconst observer = new window.MutationObserver( debouncedDisable );\n\t\t\tobserver.observe( node, {\n\t\t\t\tchildList: true,\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tif ( observer ) {\n\t\t\t\t\tobserver.disconnect();\n\t\t\t\t}\n\t\t\t\tdebouncedDisable.cancel();\n\t\t\t\tupdates.forEach( ( update ) => update() );\n\t\t\t};\n\t\t},\n\t\t[ isDisabledProp ]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,gBAAgB;AACzB,OAAO,kBAAkB;AA4BV,SAAR,YAA8B;AAAA,EACpC,YAAY,iBAAiB;AAC9B,IAEI,CAAC,GAAI;AACR,SAAO;AAAA,IACN,CAAE,SAAU;AACX,UAAK,gBAAiB;AACrB;AAAA,MACD;AAEA,YAAM,cAAc,MAAM,eAAe;AACzC,UAAK,CAAE,aAAc;AACpB;AAAA,MACD;AAGA,YAAM,UAA4B,CAAC;AACnC,YAAM,UAAU,MAAM;AACrB,aAAK,WAAW,QAAS,CAAE,UAAW;AACrC,cAAK,EAAI,iBAAiB,YAAY,cAAgB;AACrD;AAAA,UACD;AACA,cAAK,CAAE,MAAM,aAAc,OAAQ,GAAI;AACtC,kBAAM,aAAc,SAAS,MAAO;AACpC,oBAAQ,KAAM,MAAM;AACnB,oBAAM,gBAAiB,OAAQ;AAAA,YAChC,CAAE;AAAA,UACH;AAAA,QACD,CAAE;AAAA,MACH;AAIA,YAAM,mBAAmB,SAAU,SAAS,GAAG;AAAA,QAC9C,SAAS;AAAA,MACV,CAAE;AACF,cAAQ;AAGR,YAAM,WAAW,IAAI,OAAO,iBAAkB,gBAAiB;AAC/D,eAAS,QAAS,MAAM;AAAA,QACvB,WAAW;AAAA,MACZ,CAAE;AAEF,aAAO,MAAM;AACZ,YAAK,UAAW;AACf,mBAAS,WAAW;AAAA,QACrB;AACA,yBAAiB,OAAO;AACxB,gBAAQ,QAAS,CAAE,WAAY,OAAO,CAAE;AAAA,MACzC;AAAA,IACD;AAAA,IACA,CAAE,cAAe;AAAA,EAClB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-dragging/index.
|
|
1
|
+
// packages/compose/src/hooks/use-dragging/index.ts
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "@wordpress/element";
|
|
3
3
|
import useIsomorphicLayoutEffect from "../use-isomorphic-layout-effect/index.mjs";
|
|
4
|
-
function useDragging({
|
|
4
|
+
function useDragging({
|
|
5
|
+
onDragStart,
|
|
6
|
+
onDragMove,
|
|
7
|
+
onDragEnd
|
|
8
|
+
}) {
|
|
5
9
|
const [isDragging, setIsDragging] = useState(false);
|
|
6
10
|
const eventsRef = useRef({
|
|
7
11
|
onDragStart,
|
|
@@ -13,26 +17,27 @@ function useDragging({ onDragStart, onDragMove, onDragEnd }) {
|
|
|
13
17
|
eventsRef.current.onDragMove = onDragMove;
|
|
14
18
|
eventsRef.current.onDragEnd = onDragEnd;
|
|
15
19
|
}, [onDragStart, onDragMove, onDragEnd]);
|
|
16
|
-
const onMouseMove = useCallback(
|
|
17
|
-
|
|
18
|
-
[]
|
|
19
|
-
);
|
|
20
|
-
const endDrag = useCallback((event) => {
|
|
21
|
-
if (eventsRef.current.onDragEnd) {
|
|
22
|
-
eventsRef.current.onDragEnd(event);
|
|
23
|
-
}
|
|
24
|
-
document.removeEventListener("mousemove", onMouseMove);
|
|
25
|
-
document.removeEventListener("mouseup", endDrag);
|
|
26
|
-
setIsDragging(false);
|
|
27
|
-
}, []);
|
|
28
|
-
const startDrag = useCallback((event) => {
|
|
29
|
-
if (eventsRef.current.onDragStart) {
|
|
30
|
-
eventsRef.current.onDragStart(event);
|
|
31
|
-
}
|
|
32
|
-
document.addEventListener("mousemove", onMouseMove);
|
|
33
|
-
document.addEventListener("mouseup", endDrag);
|
|
34
|
-
setIsDragging(true);
|
|
20
|
+
const onMouseMove = useCallback((event) => {
|
|
21
|
+
eventsRef.current.onDragMove?.(event);
|
|
35
22
|
}, []);
|
|
23
|
+
const endDrag = useCallback(
|
|
24
|
+
function endDrag2(event) {
|
|
25
|
+
eventsRef.current.onDragEnd?.(event);
|
|
26
|
+
document.removeEventListener("mousemove", onMouseMove);
|
|
27
|
+
document.removeEventListener("mouseup", endDrag2);
|
|
28
|
+
setIsDragging(false);
|
|
29
|
+
},
|
|
30
|
+
[onMouseMove]
|
|
31
|
+
);
|
|
32
|
+
const startDrag = useCallback(
|
|
33
|
+
(event) => {
|
|
34
|
+
eventsRef.current.onDragStart?.(event);
|
|
35
|
+
document.addEventListener("mousemove", onMouseMove);
|
|
36
|
+
document.addEventListener("mouseup", endDrag);
|
|
37
|
+
setIsDragging(true);
|
|
38
|
+
},
|
|
39
|
+
[onMouseMove, endDrag]
|
|
40
|
+
);
|
|
36
41
|
useEffect(() => {
|
|
37
42
|
return () => {
|
|
38
43
|
if (isDragging) {
|
|
@@ -40,7 +45,7 @@ function useDragging({ onDragStart, onDragMove, onDragEnd }) {
|
|
|
40
45
|
document.removeEventListener("mouseup", endDrag);
|
|
41
46
|
}
|
|
42
47
|
};
|
|
43
|
-
}, [isDragging]);
|
|
48
|
+
}, [isDragging, onMouseMove, endDrag]);
|
|
44
49
|
return {
|
|
45
50
|
startDrag,
|
|
46
51
|
endDrag,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-dragging/index.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useIsomorphicLayoutEffect from '../use-isomorphic-layout-effect';\
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAKzD,OAAO,+BAA+B;
|
|
6
|
-
"names": []
|
|
3
|
+
"sources": ["../../../src/hooks/use-dragging/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useIsomorphicLayoutEffect from '../use-isomorphic-layout-effect';\nimport type { DraggingProps, DraggingReturn } from './types';\n\n/**\n * Hook to manage drag events with proper event handling\n *\n * @param props Drag handlers\n * @param props.onDragStart\n * @param props.onDragMove\n * @param props.onDragEnd\n * @return Drag state and handlers\n */\nexport default function useDragging( {\n\tonDragStart,\n\tonDragMove,\n\tonDragEnd,\n}: DraggingProps ): DraggingReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\n\tconst eventsRef = useRef< DraggingProps >( {\n\t\tonDragStart,\n\t\tonDragMove,\n\t\tonDragEnd,\n\t} );\n\tuseIsomorphicLayoutEffect( () => {\n\t\teventsRef.current.onDragStart = onDragStart;\n\t\teventsRef.current.onDragMove = onDragMove;\n\t\teventsRef.current.onDragEnd = onDragEnd;\n\t}, [ onDragStart, onDragMove, onDragEnd ] );\n\n\tconst onMouseMove = useCallback( ( event: MouseEvent ): void => {\n\t\teventsRef.current.onDragMove?.( event );\n\t}, [] );\n\n\tconst endDrag = useCallback(\n\t\tfunction endDrag( event?: MouseEvent ): void {\n\t\t\teventsRef.current.onDragEnd?.( event );\n\t\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\t\tsetIsDragging( false );\n\t\t},\n\t\t[ onMouseMove ]\n\t);\n\n\tconst startDrag = useCallback(\n\t\t( event: React.MouseEvent ): void => {\n\t\t\teventsRef.current.onDragStart?.( event );\n\t\t\tdocument.addEventListener( 'mousemove', onMouseMove );\n\t\t\tdocument.addEventListener( 'mouseup', endDrag );\n\t\t\tsetIsDragging( true );\n\t\t},\n\t\t[ onMouseMove, endDrag ]\n\t);\n\n\t// Remove the global events when unmounting if needed.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( isDragging ) {\n\t\t\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\t\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\t\t}\n\t\t};\n\t}, [ isDragging, onMouseMove, endDrag ] );\n\n\treturn {\n\t\tstartDrag,\n\t\tendDrag,\n\t\tisDragging,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAKzD,OAAO,+BAA+B;AAYvB,SAAR,YAA8B;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AACD,GAAmC;AAClC,QAAM,CAAE,YAAY,aAAc,IAAI,SAAU,KAAM;AAEtD,QAAM,YAAY,OAAyB;AAAA,IAC1C;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AACF,4BAA2B,MAAM;AAChC,cAAU,QAAQ,cAAc;AAChC,cAAU,QAAQ,aAAa;AAC/B,cAAU,QAAQ,YAAY;AAAA,EAC/B,GAAG,CAAE,aAAa,YAAY,SAAU,CAAE;AAE1C,QAAM,cAAc,YAAa,CAAE,UAA6B;AAC/D,cAAU,QAAQ,aAAc,KAAM;AAAA,EACvC,GAAG,CAAC,CAAE;AAEN,QAAM,UAAU;AAAA,IACf,SAASA,SAAS,OAA2B;AAC5C,gBAAU,QAAQ,YAAa,KAAM;AACrC,eAAS,oBAAqB,aAAa,WAAY;AACvD,eAAS,oBAAqB,WAAWA,QAAQ;AACjD,oBAAe,KAAM;AAAA,IACtB;AAAA,IACA,CAAE,WAAY;AAAA,EACf;AAEA,QAAM,YAAY;AAAA,IACjB,CAAE,UAAmC;AACpC,gBAAU,QAAQ,cAAe,KAAM;AACvC,eAAS,iBAAkB,aAAa,WAAY;AACpD,eAAS,iBAAkB,WAAW,OAAQ;AAC9C,oBAAe,IAAK;AAAA,IACrB;AAAA,IACA,CAAE,aAAa,OAAQ;AAAA,EACxB;AAGA,YAAW,MAAM;AAChB,WAAO,MAAM;AACZ,UAAK,YAAa;AACjB,iBAAS,oBAAqB,aAAa,WAAY;AACvD,iBAAS,oBAAqB,WAAW,OAAQ;AAAA,MAClD;AAAA,IACD;AAAA,EACD,GAAG,CAAE,YAAY,aAAa,OAAQ,CAAE;AAExC,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["endDrag"]
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-drop-zone/index.
|
|
1
|
+
// packages/compose/src/hooks/use-drop-zone/index.ts
|
|
2
2
|
import useRefEffect from "../use-ref-effect/index.mjs";
|
|
3
3
|
import useEvent from "../use-event/index.mjs";
|
|
4
4
|
function useDropZone({
|
|
@@ -51,10 +51,7 @@ function useDropZone({
|
|
|
51
51
|
}
|
|
52
52
|
function onDragEnter(event) {
|
|
53
53
|
event.preventDefault();
|
|
54
|
-
if (element.contains(
|
|
55
|
-
/** @type {Node} */
|
|
56
|
-
event.relatedTarget
|
|
57
|
-
)) {
|
|
54
|
+
if (element.contains(event.relatedTarget)) {
|
|
58
55
|
return;
|
|
59
56
|
}
|
|
60
57
|
if (_onDragEnter) {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-drop-zone/index.
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\nimport useEvent from '../use-event';\n\n/**\n * A hook to facilitate drag and drop handling.\n *\n * @param {
|
|
5
|
-
"mappings": ";AAGA,OAAO,kBAAkB;AACzB,OAAO,cAAc;
|
|
3
|
+
"sources": ["../../../src/hooks/use-drop-zone/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\nimport useEvent from '../use-event';\nimport type { UseDropZoneProps } from './types';\n\n/**\n * A hook to facilitate drag and drop handling.\n *\n * @param {UseDropZoneProps} props Hook options\n * @return Ref callback to be passed to the drop zone element.\n */\nexport default function useDropZone( {\n\tdropZoneElement,\n\tisDisabled,\n\tonDrop: _onDrop,\n\tonDragStart: _onDragStart,\n\tonDragEnter: _onDragEnter,\n\tonDragLeave: _onDragLeave,\n\tonDragEnd: _onDragEnd,\n\tonDragOver: _onDragOver,\n}: UseDropZoneProps ): React.RefCallback< HTMLElement > {\n\tconst onDropEvent = useEvent( _onDrop );\n\tconst onDragStartEvent = useEvent( _onDragStart );\n\tconst onDragEnterEvent = useEvent( _onDragEnter );\n\tconst onDragLeaveEvent = useEvent( _onDragLeave );\n\tconst onDragEndEvent = useEvent( _onDragEnd );\n\tconst onDragOverEvent = useEvent( _onDragOver );\n\n\treturn useRefEffect(\n\t\t( elem: HTMLElement ) => {\n\t\t\tif ( isDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If a custom dropZoneRef is passed, use that instead of the element.\n\t\t\t// This allows the dropzone to cover an expanded area, rather than\n\t\t\t// be restricted to the area of the ref returned by this hook.\n\t\t\tconst element = dropZoneElement ?? elem;\n\n\t\t\tlet isDragging = false;\n\n\t\t\tconst { ownerDocument } = element;\n\n\t\t\t/**\n\t\t\t * Checks if an element is in the drop zone.\n\t\t\t *\n\t\t\t * @param {EventTarget|null} targetToCheck\n\t\t\t *\n\t\t\t * @return {boolean} True if in drop zone, false if not.\n\t\t\t */\n\t\t\tfunction isElementInZone(\n\t\t\t\ttargetToCheck: EventTarget | null\n\t\t\t): boolean {\n\t\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\t\tif (\n\t\t\t\t\t! targetToCheck ||\n\t\t\t\t\t! defaultView ||\n\t\t\t\t\t! ( targetToCheck instanceof defaultView.HTMLElement ) ||\n\t\t\t\t\t! element.contains( targetToCheck )\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\tlet elementToCheck: HTMLElement | null = targetToCheck;\n\n\t\t\t\tdo {\n\t\t\t\t\tif ( elementToCheck.dataset.isDropZone ) {\n\t\t\t\t\t\treturn elementToCheck === element;\n\t\t\t\t\t}\n\t\t\t\t} while ( ( elementToCheck = elementToCheck.parentElement ) );\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfunction maybeDragStart( event: DragEvent ): void {\n\t\t\t\tif ( isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = true;\n\n\t\t\t\t// Note that `dragend` doesn't fire consistently for file and\n\t\t\t\t// HTML drag events where the drag origin is outside the browser\n\t\t\t\t// window. In Firefox it may also not fire if the originating\n\t\t\t\t// node is removed.\n\t\t\t\townerDocument.addEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.addEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( _onDragStart ) {\n\t\t\t\t\tonDragStartEvent( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragEnter( event: DragEvent ): void {\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// The `dragenter` event will also fire when entering child\n\t\t\t\t// elements, but we only want to call `onDragEnter` when\n\t\t\t\t// entering the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been left) should be outside the drop zone.\n\t\t\t\tif ( element.contains( event.relatedTarget as Node ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( _onDragEnter ) {\n\t\t\t\t\tonDragEnterEvent( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragOver( event: DragEvent ): void {\n\t\t\t\tif ( ! event.defaultPrevented && _onDragOver ) {\n\t\t\t\t\tonDragOverEvent( event );\n\t\t\t\t}\n\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\n\t\t\tfunction onDragLeave( event: DragEvent ): void {\n\t\t\t\t// The `dragleave` event will also fire when leaving child\n\t\t\t\t// elements, but we only want to call `onDragLeave` when\n\t\t\t\t// leaving the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been entered) should be outside the drop\n\t\t\t\t// zone.\n\t\t\t\t// Note: This is not entirely reliable in Safari due to this bug\n\t\t\t\t// https://bugs.webkit.org/show_bug.cgi?id=66547\n\n\t\t\t\tif ( isElementInZone( event.relatedTarget ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( _onDragLeave ) {\n\t\t\t\t\tonDragLeaveEvent( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDrop( event: DragEvent ): void {\n\t\t\t\t// Don't handle drop if an inner drop zone already handled it.\n\t\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Prevent the browser default while also signalling to parent\n\t\t\t\t// drop zones that `onDrop` is already handled.\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// This seemingly useless line has been shown to resolve a\n\t\t\t\t// Safari issue where files dragged directly from the dock are\n\t\t\t\t// not recognized.\n\t\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\t\tevent.dataTransfer && event.dataTransfer.files.length;\n\n\t\t\t\tif ( _onDrop ) {\n\t\t\t\t\tonDropEvent( event );\n\t\t\t\t}\n\n\t\t\t\tmaybeDragEnd( event );\n\t\t\t}\n\n\t\t\tfunction maybeDragEnd( event: Event ): void {\n\t\t\t\tif ( ! isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = false;\n\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( _onDragEnd ) {\n\t\t\t\t\tonDragEndEvent( event as MouseEvent );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\telement.setAttribute( 'data-is-drop-zone', 'true' );\n\t\t\telement.addEventListener( 'drop', onDrop );\n\t\t\telement.addEventListener( 'dragenter', onDragEnter );\n\t\t\telement.addEventListener( 'dragover', onDragOver );\n\t\t\telement.addEventListener( 'dragleave', onDragLeave );\n\t\t\t// The `dragstart` event doesn't fire if the drag started outside\n\t\t\t// the document.\n\t\t\townerDocument.addEventListener( 'dragenter', maybeDragStart );\n\n\t\t\treturn () => {\n\t\t\t\telement.removeAttribute( 'data-is-drop-zone' );\n\t\t\t\telement.removeEventListener( 'drop', onDrop );\n\t\t\t\telement.removeEventListener( 'dragenter', onDragEnter );\n\t\t\t\telement.removeEventListener( 'dragover', onDragOver );\n\t\t\t\telement.removeEventListener( 'dragleave', onDragLeave );\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'dragenter',\n\t\t\t\t\tmaybeDragStart\n\t\t\t\t);\n\t\t\t};\n\t\t},\n\t\t[ isDisabled, dropZoneElement ] // Refresh when the passed in dropZoneElement changes.\n\t);\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-fixed-window-list/index.
|
|
1
|
+
// packages/compose/src/hooks/use-fixed-window-list/index.ts
|
|
2
2
|
import { useState, useLayoutEffect } from "@wordpress/element";
|
|
3
3
|
import { getScrollContainer } from "@wordpress/dom";
|
|
4
4
|
import { PAGEUP, PAGEDOWN, HOME, END } from "@wordpress/keycodes";
|
|
@@ -7,14 +7,16 @@ var DEFAULT_INIT_WINDOW_SIZE = 30;
|
|
|
7
7
|
function useFixedWindowList(elementRef, itemHeight, totalItems, options) {
|
|
8
8
|
const initWindowSize = options?.initWindowSize ?? DEFAULT_INIT_WINDOW_SIZE;
|
|
9
9
|
const useWindowing = options?.useWindowing ?? true;
|
|
10
|
-
const [fixedListWindow, setFixedListWindow] = useState(
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
const [fixedListWindow, setFixedListWindow] = useState(
|
|
11
|
+
{
|
|
12
|
+
visibleItems: initWindowSize,
|
|
13
|
+
start: 0,
|
|
14
|
+
end: initWindowSize,
|
|
15
|
+
itemInView: (index) => {
|
|
16
|
+
return index >= 0 && index <= initWindowSize;
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
|
-
|
|
19
|
+
);
|
|
18
20
|
useLayoutEffect(() => {
|
|
19
21
|
if (!useWindowing) {
|
|
20
22
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-fixed-window-list/index.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useLayoutEffect } from '@wordpress/element';\nimport { getScrollContainer } from '@wordpress/dom';\nimport { PAGEUP, PAGEDOWN, HOME, END } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\n\nconst DEFAULT_INIT_WINDOW_SIZE = 30;\n\
|
|
5
|
-
"mappings": ";AAGA,SAAS,UAAU,uBAAuB;AAC1C,SAAS,0BAA0B;AACnC,SAAS,QAAQ,UAAU,MAAM,WAAW;AAK5C,SAAS,gBAAgB;AAEzB,IAAM,2BAA2B;
|
|
3
|
+
"sources": ["../../../src/hooks/use-fixed-window-list/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useLayoutEffect } from '@wordpress/element';\nimport { getScrollContainer } from '@wordpress/dom';\nimport { PAGEUP, PAGEDOWN, HOME, END } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\n\nconst DEFAULT_INIT_WINDOW_SIZE = 30;\n\ninterface FixedWindowList {\n\t/** Items visible in the current viewport */\n\tvisibleItems: number;\n\t/** Start index of the window */\n\tstart: number;\n\t/** End index of the window */\n\tend: number;\n\t/** Returns true if item is in the window */\n\titemInView: ( index: number ) => boolean;\n}\n\ninterface FixedWindowListOptions {\n\t/** Renders windowOverscan number of items before and after the calculated visible window. */\n\twindowOverscan?: number;\n\t/** When false avoids calculating the window size */\n\tuseWindowing?: boolean;\n\t/** Initial window size to use on first render before we can calculate the window size. */\n\tinitWindowSize?: number;\n\t/** Used to recalculate the window size when the expanded state of a list changes. */\n\texpandedState?: any;\n}\n\n/**\n *\n * @param elementRef Used to find the closest scroll container that contains element.\n * @param itemHeight Fixed item height in pixels\n * @param totalItems Total items in list\n * @param [options] Options object\n * @return Array with the fixed window list and setter\n */\nexport default function useFixedWindowList(\n\telementRef: React.RefObject< HTMLElement >,\n\titemHeight: number,\n\ttotalItems: number,\n\toptions?: FixedWindowListOptions\n): [\n\tFixedWindowList,\n\tReact.Dispatch< React.SetStateAction< FixedWindowList > >,\n] {\n\tconst initWindowSize = options?.initWindowSize ?? DEFAULT_INIT_WINDOW_SIZE;\n\tconst useWindowing = options?.useWindowing ?? true;\n\n\tconst [ fixedListWindow, setFixedListWindow ] = useState< FixedWindowList >(\n\t\t{\n\t\t\tvisibleItems: initWindowSize,\n\t\t\tstart: 0,\n\t\t\tend: initWindowSize,\n\t\t\titemInView: ( index: number ) => {\n\t\t\t\treturn index >= 0 && index <= initWindowSize;\n\t\t\t},\n\t\t}\n\t);\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\t/**\n\t\t * Measures and sets the window of items to render based on the scroll position\n\t\t *\n\t\t * @param {boolean} [initRender] Indicates if this is the initial render\n\t\t * @return {void}\n\t\t */\n\t\tconst measureWindow = ( initRender?: boolean ) => {\n\t\t\tif ( ! scrollContainer ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst visibleItems = Math.ceil(\n\t\t\t\tscrollContainer.clientHeight / itemHeight\n\t\t\t);\n\t\t\t// Aim to keep opening list view fast, afterward we can optimize for scrolling.\n\t\t\tconst windowOverscan = initRender\n\t\t\t\t? visibleItems\n\t\t\t\t: options?.windowOverscan ?? visibleItems;\n\t\t\tconst firstViewableIndex = Math.floor(\n\t\t\t\tscrollContainer.scrollTop / itemHeight\n\t\t\t);\n\t\t\tconst start = Math.max( 0, firstViewableIndex - windowOverscan );\n\t\t\tconst end = Math.min(\n\t\t\t\ttotalItems - 1,\n\t\t\t\tfirstViewableIndex + visibleItems + windowOverscan\n\t\t\t);\n\t\t\tsetFixedListWindow( ( lastWindow ) => {\n\t\t\t\tconst nextWindow = {\n\t\t\t\t\tvisibleItems,\n\t\t\t\t\tstart,\n\t\t\t\t\tend,\n\t\t\t\t\titemInView: ( index: number ) => {\n\t\t\t\t\t\treturn start <= index && index <= end;\n\t\t\t\t\t},\n\t\t\t\t};\n\t\t\t\tif (\n\t\t\t\t\tlastWindow.start !== nextWindow.start ||\n\t\t\t\t\tlastWindow.end !== nextWindow.end ||\n\t\t\t\t\tlastWindow.visibleItems !== nextWindow.visibleItems\n\t\t\t\t) {\n\t\t\t\t\treturn nextWindow;\n\t\t\t\t}\n\t\t\t\treturn lastWindow;\n\t\t\t} );\n\t\t};\n\n\t\tmeasureWindow( true );\n\t\tconst debounceMeasureList = debounce( () => {\n\t\t\tmeasureWindow();\n\t\t}, 16 );\n\t\tscrollContainer?.addEventListener( 'scroll', debounceMeasureList );\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'resize',\n\t\t\tdebounceMeasureList\n\t\t);\n\n\t\treturn () => {\n\t\t\tscrollContainer?.removeEventListener(\n\t\t\t\t'scroll',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'resize',\n\t\t\t\tdebounceMeasureList\n\t\t\t);\n\t\t};\n\t}, [\n\t\titemHeight,\n\t\telementRef,\n\t\ttotalItems,\n\t\toptions?.expandedState,\n\t\toptions?.windowOverscan,\n\t\tuseWindowing,\n\t] );\n\n\tuseLayoutEffect( () => {\n\t\tif ( ! useWindowing ) {\n\t\t\treturn;\n\t\t}\n\t\tconst scrollContainer = getScrollContainer( elementRef.current );\n\t\tconst handleKeyDown = ( event: KeyboardEvent ) => {\n\t\t\tswitch ( event.keyCode ) {\n\t\t\t\tcase HOME: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( { top: 0 } );\n\t\t\t\t}\n\t\t\t\tcase END: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop: totalItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEUP: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop -\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t\tcase PAGEDOWN: {\n\t\t\t\t\treturn scrollContainer?.scrollTo( {\n\t\t\t\t\t\ttop:\n\t\t\t\t\t\t\tscrollContainer.scrollTop +\n\t\t\t\t\t\t\tfixedListWindow.visibleItems * itemHeight,\n\t\t\t\t\t} );\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tscrollContainer?.ownerDocument?.defaultView?.addEventListener(\n\t\t\t'keydown',\n\t\t\thandleKeyDown\n\t\t);\n\t\treturn () => {\n\t\t\tscrollContainer?.ownerDocument?.defaultView?.removeEventListener(\n\t\t\t\t'keydown',\n\t\t\t\thandleKeyDown\n\t\t\t);\n\t\t};\n\t}, [\n\t\ttotalItems,\n\t\titemHeight,\n\t\telementRef,\n\t\tfixedListWindow.visibleItems,\n\t\tuseWindowing,\n\t\toptions?.expandedState,\n\t] );\n\n\treturn [ fixedListWindow, setFixedListWindow ];\n}\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,33 +1,36 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-focus-return/index.
|
|
1
|
+
// packages/compose/src/hooks/use-focus-return/index.ts
|
|
2
2
|
import { useRef, useEffect, useCallback } from "@wordpress/element";
|
|
3
3
|
var origin = null;
|
|
4
4
|
function useFocusReturn(onFocusReturn) {
|
|
5
5
|
const ref = useRef(null);
|
|
6
|
-
const
|
|
7
|
-
const onFocusReturnRef = useRef(
|
|
6
|
+
const focusedBeforeMountRef = useRef(null);
|
|
7
|
+
const onFocusReturnRef = useRef(
|
|
8
|
+
onFocusReturn
|
|
9
|
+
);
|
|
8
10
|
useEffect(() => {
|
|
9
11
|
onFocusReturnRef.current = onFocusReturn;
|
|
10
12
|
}, [onFocusReturn]);
|
|
11
13
|
return useCallback((node) => {
|
|
12
14
|
if (node) {
|
|
13
15
|
ref.current = node;
|
|
14
|
-
if (
|
|
16
|
+
if (focusedBeforeMountRef.current) {
|
|
15
17
|
return;
|
|
16
18
|
}
|
|
17
19
|
const activeDocument = node.ownerDocument.activeElement instanceof window.HTMLIFrameElement ? node.ownerDocument.activeElement.contentDocument : node.ownerDocument;
|
|
18
|
-
|
|
19
|
-
} else if (
|
|
20
|
+
focusedBeforeMountRef.current = activeDocument?.activeElement ?? null;
|
|
21
|
+
} else if (focusedBeforeMountRef.current) {
|
|
20
22
|
const isFocused = ref.current?.contains(
|
|
21
|
-
ref.current?.ownerDocument.activeElement
|
|
23
|
+
ref.current?.ownerDocument.activeElement ?? null
|
|
22
24
|
);
|
|
23
25
|
if (ref.current?.isConnected && !isFocused) {
|
|
24
|
-
origin ??=
|
|
26
|
+
origin ??= focusedBeforeMountRef.current;
|
|
25
27
|
return;
|
|
26
28
|
}
|
|
27
29
|
if (onFocusReturnRef.current) {
|
|
28
30
|
onFocusReturnRef.current();
|
|
29
31
|
} else {
|
|
30
|
-
|
|
32
|
+
const elementToFocus = !focusedBeforeMountRef.current.isConnected ? origin : focusedBeforeMountRef.current;
|
|
33
|
+
elementToFocus?.focus();
|
|
31
34
|
}
|
|
32
35
|
origin = null;
|
|
33
36
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-focus-return/index.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\n\
|
|
5
|
-
"mappings": ";AAGA,SAAS,QAAQ,WAAW,mBAAmB;
|
|
3
|
+
"sources": ["../../../src/hooks/use-focus-return/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\n\nlet origin: Element | null = null;\n\n/**\n * Adds the unmount behavior of returning focus to the element which had it\n * previously as is expected for roles like menus or dialogs.\n *\n * @param onFocusReturn Overrides the default return behavior.\n * @return Element Ref.\n *\n * @example\n * ```ts\n * import { useFocusReturn } from '@wordpress/compose';\n *\n * const WithFocusReturn = () => {\n * const ref = useFocusReturn()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useFocusReturn(\n\tonFocusReturn?: () => void\n): React.RefCallback< HTMLElement > {\n\tconst ref = useRef< HTMLElement | null >( null );\n\tconst focusedBeforeMountRef = useRef< Element | null >( null );\n\tconst onFocusReturnRef = useRef< ( () => void ) | undefined >(\n\t\tonFocusReturn\n\t);\n\n\tuseEffect( () => {\n\t\tonFocusReturnRef.current = onFocusReturn;\n\t}, [ onFocusReturn ] );\n\n\treturn useCallback( ( node: HTMLElement | null ) => {\n\t\tif ( node ) {\n\t\t\t// Set ref to be used when unmounting.\n\t\t\tref.current = node;\n\n\t\t\t// Only set when the node mounts.\n\t\t\tif ( focusedBeforeMountRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst activeDocument =\n\t\t\t\tnode.ownerDocument.activeElement instanceof\n\t\t\t\twindow.HTMLIFrameElement\n\t\t\t\t\t? node.ownerDocument.activeElement.contentDocument\n\t\t\t\t\t: node.ownerDocument;\n\n\t\t\tfocusedBeforeMountRef.current =\n\t\t\t\tactiveDocument?.activeElement ?? null;\n\t\t} else if ( focusedBeforeMountRef.current ) {\n\t\t\tconst isFocused = ref.current?.contains(\n\t\t\t\tref.current?.ownerDocument.activeElement ?? null\n\t\t\t);\n\n\t\t\tif ( ref.current?.isConnected && ! isFocused ) {\n\t\t\t\torigin ??= focusedBeforeMountRef.current;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Defer to the component's own explicit focus return behavior, if\n\t\t\t// specified. This allows for support that the `onFocusReturn`\n\t\t\t// decides to allow the default behavior to occur under some\n\t\t\t// conditions.\n\t\t\tif ( onFocusReturnRef.current ) {\n\t\t\t\tonFocusReturnRef.current();\n\t\t\t} else {\n\t\t\t\tconst elementToFocus = (\n\t\t\t\t\t! focusedBeforeMountRef.current.isConnected\n\t\t\t\t\t\t? origin\n\t\t\t\t\t\t: focusedBeforeMountRef.current\n\t\t\t\t) as HTMLElement | SVGElement | null;\n\n\t\t\t\telementToFocus?.focus();\n\t\t\t}\n\t\t\torigin = null;\n\t\t}\n\t}, [] );\n}\n\nexport default useFocusReturn;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,QAAQ,WAAW,mBAAmB;AAE/C,IAAI,SAAyB;AAwB7B,SAAS,eACR,eACmC;AACnC,QAAM,MAAM,OAA8B,IAAK;AAC/C,QAAM,wBAAwB,OAA0B,IAAK;AAC7D,QAAM,mBAAmB;AAAA,IACxB;AAAA,EACD;AAEA,YAAW,MAAM;AAChB,qBAAiB,UAAU;AAAA,EAC5B,GAAG,CAAE,aAAc,CAAE;AAErB,SAAO,YAAa,CAAE,SAA8B;AACnD,QAAK,MAAO;AAEX,UAAI,UAAU;AAGd,UAAK,sBAAsB,SAAU;AACpC;AAAA,MACD;AAEA,YAAM,iBACL,KAAK,cAAc,yBACnB,OAAO,oBACJ,KAAK,cAAc,cAAc,kBACjC,KAAK;AAET,4BAAsB,UACrB,gBAAgB,iBAAiB;AAAA,IACnC,WAAY,sBAAsB,SAAU;AAC3C,YAAM,YAAY,IAAI,SAAS;AAAA,QAC9B,IAAI,SAAS,cAAc,iBAAiB;AAAA,MAC7C;AAEA,UAAK,IAAI,SAAS,eAAe,CAAE,WAAY;AAC9C,mBAAW,sBAAsB;AACjC;AAAA,MACD;AAMA,UAAK,iBAAiB,SAAU;AAC/B,yBAAiB,QAAQ;AAAA,MAC1B,OAAO;AACN,cAAM,iBACL,CAAE,sBAAsB,QAAQ,cAC7B,SACA,sBAAsB;AAG1B,wBAAgB,MAAM;AAAA,MACvB;AACA,eAAS;AAAA,IACV;AAAA,EACD,GAAG,CAAC,CAAE;AACP;AAEA,IAAO,2BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-isomorphic-layout-effect/index.
|
|
1
|
+
// packages/compose/src/hooks/use-isomorphic-layout-effect/index.ts
|
|
2
2
|
import { useEffect, useLayoutEffect } from "@wordpress/element";
|
|
3
3
|
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
4
4
|
var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-isomorphic-layout-effect/index.
|
|
3
|
+
"sources": ["../../../src/hooks/use-isomorphic-layout-effect/index.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useLayoutEffect } from '@wordpress/element';\n\n/**\n * Preferred over direct usage of `useLayoutEffect` when supporting\n * server rendered components (SSR) because currently React\n * throws a warning when using useLayoutEffect in that environment.\n */\nconst useIsomorphicLayoutEffect =\n\ttypeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport default useIsomorphicLayoutEffect;\n"],
|
|
5
5
|
"mappings": ";AAGA,SAAS,WAAW,uBAAuB;AAO3C,IAAM,4BACL,OAAO,WAAW,cAAc,kBAAkB;AAEnD,IAAO,uCAAQ;",
|
|
6
6
|
"names": []
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-keyboard-shortcut/index.
|
|
1
|
+
// packages/compose/src/hooks/use-keyboard-shortcut/index.ts
|
|
2
2
|
import Mousetrap from "mousetrap";
|
|
3
3
|
import "mousetrap/plugins/global-bind/mousetrap-global-bind.js";
|
|
4
4
|
import { useEffect, useRef } from "@wordpress/element";
|
|
@@ -7,7 +7,6 @@ function useKeyboardShortcut(shortcuts, callback, {
|
|
|
7
7
|
bindGlobal = false,
|
|
8
8
|
eventName = "keydown",
|
|
9
9
|
isDisabled = false,
|
|
10
|
-
// This is important for performance considerations.
|
|
11
10
|
target
|
|
12
11
|
} = {}) {
|
|
13
12
|
const currentCallbackRef = useRef(callback);
|
|
@@ -23,8 +22,6 @@ function useKeyboardShortcut(shortcuts, callback, {
|
|
|
23
22
|
// We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
|
|
24
23
|
// Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's
|
|
25
24
|
// necessary to maintain the existing behavior.
|
|
26
|
-
/** @type {Element} */
|
|
27
|
-
/** @type {unknown} */
|
|
28
25
|
document
|
|
29
26
|
)
|
|
30
27
|
);
|