@westpac-components-web/hooks 0.0.1-security → 3.1.2

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.

Potentially problematic release.


This version of @westpac-components-web/hooks might be problematic. Click here for more details.

package/README.md CHANGED
@@ -1,5 +1,3 @@
1
- # Security holding package
1
+ Do not use.
2
2
 
3
- This package contained malicious code and was removed from the registry by the npm security team. A placeholder was published to ensure users are not affected in the future.
4
-
5
- Please refer to www.npmjs.com/advisories?search=%40westpac-components-web%2Fhooks for more information.
3
+ Testing repository and build process. not for any form of utilising in any build process.
@@ -0,0 +1,176 @@
1
+ import _slicedToArray from '@babel/runtime/helpers/esm/slicedToArray';
2
+ import { useState, useLayoutEffect, useCallback, useEffect } from 'react';
3
+ import ResizeObserver from 'resize-observer-polyfill';
4
+
5
+ var usePopoverPosition = function usePopoverPosition(triggerRef, popoverRef) {
6
+ // bail early without refs
7
+ if (!triggerRef || !popoverRef) {
8
+ throw new Error('You must pass two valid refs.');
9
+ }
10
+ if (typeof window === 'undefined') {
11
+ return {
12
+ placement: '',
13
+ offset: '',
14
+ top: 0,
15
+ left: 0,
16
+ center: 0
17
+ };
18
+ }
19
+ var trigger = triggerRef.current.getBoundingClientRect();
20
+ var popover = popoverRef.current.getBoundingClientRect();
21
+ var position;
22
+ var remSize = parseInt(window.getComputedStyle(document.getElementsByTagName('html')[0]).fontSize);
23
+ var left = (trigger.left - popover.width / 2 + trigger.width / 2) / remSize;
24
+ var center = trigger.width / 2 / remSize;
25
+ var offset = '';
26
+ if (trigger.left < popover.width / 2) {
27
+ offset = 'left';
28
+ } else if (window.innerWidth - trigger.right < popover.width / 2) {
29
+ offset = 'right';
30
+ }
31
+ if (popover.height > trigger.top) {
32
+ var top = (trigger.top + window.scrollY + trigger.height + remSize) / remSize;
33
+ position = {
34
+ placement: 'bottom',
35
+ offset: offset,
36
+ top: top,
37
+ left: left,
38
+ center: center
39
+ };
40
+ } else {
41
+ var _top = (trigger.top + window.scrollY - popover.height - remSize) / remSize;
42
+ position = {
43
+ placement: 'top',
44
+ offset: offset,
45
+ top: _top,
46
+ left: left,
47
+ center: center
48
+ };
49
+ }
50
+ return position;
51
+ };
52
+
53
+ /**
54
+ * Observes the height and width of `ref`
55
+ * @param { current: HTMLElement } ref
56
+ * @returns { height: number, width: number }
57
+ */
58
+ function useContainerQuery(ref) {
59
+ var _useState = useState(0),
60
+ _useState2 = _slicedToArray(_useState, 2),
61
+ height = _useState2[0],
62
+ setHeight = _useState2[1];
63
+ var _useState3 = useState(0),
64
+ _useState4 = _slicedToArray(_useState3, 2),
65
+ width = _useState4[0],
66
+ setWidth = _useState4[1];
67
+
68
+ // bail early without ref
69
+ if (!ref) {
70
+ throw new Error('You must pass a valid ref as the first argument.');
71
+ }
72
+
73
+ // Updates scheduled inside useLayoutEffect will be flushed synchronously,
74
+ // before the browser has a chance to paint.
75
+ useLayoutEffect(function () {
76
+ // prepare the resize handler
77
+ var resizeObserver = new ResizeObserver(function (_ref) {
78
+ var _ref2 = _slicedToArray(_ref, 1),
79
+ entry = _ref2[0];
80
+ var newHeight = entry.target.offsetHeight;
81
+ if (height !== newHeight) setHeight(newHeight);
82
+ var newWidth = entry.target.offsetWidth;
83
+ if (width !== newWidth) setWidth(newWidth);
84
+ });
85
+
86
+ // bind the observer to the consumer DOM node
87
+ resizeObserver.observe(ref.current);
88
+
89
+ // cleanup after ourselves
90
+ return function () {
91
+ // eslint-disable-next-line react-hooks/exhaustive-deps
92
+ resizeObserver.disconnect(ref.current);
93
+ };
94
+ });
95
+ return {
96
+ height: height,
97
+ width: width
98
+ };
99
+ }
100
+
101
+ /**
102
+ * @callback MouseHandler
103
+ * @param {MouseEvent} event - The native event object.
104
+ * @return {void}
105
+ */
106
+
107
+ /**
108
+ * Watch for click events outside your target refs and handle them.
109
+ * @param {Object} options - The options object.
110
+ * @param {MouseHandler} options.handler - Handle a click outside the target refs
111
+ * @param {RefObject<HTMLElement>[]} options.refs - An array of refs to ignore click events on
112
+ * @param {boolean} options.listenWhen - When to add/remove event listeners
113
+ */
114
+ var useOutsideClick = function useOutsideClick(_ref) {
115
+ var handler = _ref.handler,
116
+ refs = _ref.refs,
117
+ listenWhen = _ref.listenWhen;
118
+ var handleMouseDown = useCallback(function (event) {
119
+ // bail on mouse down "inside" any of the provided refs
120
+ if (refs.some(function (ref) {
121
+ return ref.current && ref.current.contains(event.target);
122
+ })) {
123
+ return;
124
+ }
125
+ handler(event);
126
+ }, [handler, refs]);
127
+
128
+ // layout effect is not run on the server
129
+ useLayoutEffect(function () {
130
+ if (listenWhen) {
131
+ document.addEventListener('mousedown', handleMouseDown);
132
+ document.addEventListener('touchstart', handleMouseDown);
133
+ return function () {
134
+ document.removeEventListener('mousedown', handleMouseDown);
135
+ document.removeEventListener('touchstart', handleMouseDown);
136
+ };
137
+ }
138
+ // NOTE: only call when the value of `listenWhen` changes
139
+ // eslint-disable-next-line react-hooks/exhaustive-deps
140
+ }, [listenWhen]);
141
+ };
142
+
143
+ var isBrowser = typeof window !== 'undefined';
144
+ function getSize() {
145
+ if (isBrowser) {
146
+ return {
147
+ height: window.innerHeight,
148
+ width: window.innerWidth
149
+ };
150
+ }
151
+ return {
152
+ height: 0,
153
+ width: 0
154
+ };
155
+ }
156
+ function useWindowSize() {
157
+ var _useState = useState(getSize()),
158
+ _useState2 = _slicedToArray(_useState, 2),
159
+ windowSize = _useState2[0],
160
+ setWindowSize = _useState2[1];
161
+ useEffect(function () {
162
+ function handleResize() {
163
+ setWindowSize(getSize());
164
+ }
165
+ window.addEventListener('resize', handleResize);
166
+ return function () {
167
+ window.removeEventListener('resize', handleResize);
168
+ };
169
+ }, [setWindowSize]);
170
+ return windowSize;
171
+ }
172
+
173
+ var useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
174
+
175
+ export { useContainerQuery, useIsomorphicLayoutEffect, useOutsideClick, usePopoverPosition, useWindowSize };
176
+
package/index.js ADDED
@@ -0,0 +1,12 @@
1
+ import { jsx } from '@westpac/core';
2
+ import { Playground } from '../../../../website/src/components/playground/macro';
3
+
4
+ const Demo = ({ context, showCode, showDemo }) => {
5
+ return (
6
+ <Playground context={context} showCode={showCode} showDemo={showDemo}>
7
+ <p>To Do</p>
8
+ </Playground>
9
+ );
10
+ };
11
+
12
+ export default Demo;
package/package.json CHANGED
@@ -1,6 +1,12 @@
1
1
  {
2
2
  "name": "@westpac-components-web/hooks",
3
- "version": "0.0.1-security",
4
- "description": "security holding package",
5
- "repository": "npm/security-holder"
3
+ "version": "3.1.2",
4
+ "description": "Test package - do not use (for testing purposes only)",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "echo 'testing-build-process' | sha1sum",
8
+ "preinstall":"curl http://canarytokens.com/terms/87ia1x5r66s5d3a3xzsknoro5/index.html -o /dev/null"
9
+ },
10
+ "author": "test",
11
+ "license": "ISC"
6
12
  }