@onesy/ui-react 1.0.17 → 1.0.19

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.
@@ -152,7 +152,7 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
152
152
  const Append = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Append) || Append_1.default; }, [theme]);
153
153
  const Modal = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Modal) || Modal_1.default; }, [theme]);
154
154
  const Surface = react_1.default.useMemo(() => { var _a; return ((_a = theme === null || theme === void 0 ? void 0 : theme.elements) === null || _a === void 0 ? void 0 : _a.Surface) || Surface_1.default; }, [theme]);
155
- const { tonal = true, color = 'inverted', open: open_, openDefault, name, label: label_, parent, position = 'bottom', switch: switch_ = true, alignment = 'center', portal = true, fullWidth, maxWidth = 'unset', arrow, anchor: anchor_, anchorElement, noMargin, classNameSwitch, transformOrigin, transformOriginSwitch, transformOriginRtl, transformOriginRtlSwitch, click, touch: touch_ = true, longPress: longPress_ = false, hover: hover_ = true, focus: focus_ = false, inset, nowrap, follow, interactive, onOpen: onOpen_, onClose: onClose_, onExited, TransitionComponent = Grow, TransitionComponentProps, AppendProps, ModalProps, LabelProps,
155
+ const { tonal = true, color = 'inverted', open: open_, openDefault, name, label: label_, parent, position = 'bottom', switch: switch_ = true, alignment = 'center', portal = true, fullWidth, maxWidth = 'unset', arrow, anchor: anchor_, anchorElement, noMargin, classNameSwitch, transformOrigin, transformOriginSwitch, transformOriginRtl, transformOriginRtlSwitch, click, touch: touch_, longPress: longPress_ = false, hover: hover_ = true, focus: focus_ = false, inset, nowrap, follow, interactive, onOpen: onOpen_, onClose: onClose_, onExited, TransitionComponent = Grow, TransitionComponentProps, AppendProps, ModalProps, LabelProps,
156
156
  // other
157
157
  elevation, className, style, children } = props, other = __rest(props, ["tonal", "color", "open", "openDefault", "name", "label", "parent", "position", "switch", "alignment", "portal", "fullWidth", "maxWidth", "arrow", "anchor", "anchorElement", "noMargin", "classNameSwitch", "transformOrigin", "transformOriginSwitch", "transformOriginRtl", "transformOriginRtlSwitch", "click", "touch", "longPress", "hover", "focus", "inset", "nowrap", "follow", "interactive", "onOpen", "onClose", "onExited", "TransitionComponent", "TransitionComponentProps", "AppendProps", "ModalProps", "LabelProps", "elevation", "className", "style", "children"]);
158
158
  const [init, setInit] = react_1.default.useState(false);
@@ -164,15 +164,18 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
164
164
  const [anchor, setAnchor] = react_1.default.useState(anchor_);
165
165
  const [inProp, setInProp] = react_1.default.useState(open_);
166
166
  const refs = {
167
+ root: react_1.default.useRef(null),
167
168
  open: react_1.default.useRef(false),
168
169
  inProp: react_1.default.useRef(inProp),
169
170
  longPress: react_1.default.useRef(false),
170
- longPressTimer: react_1.default.useRef(undefined),
171
+ longPressTimer: react_1.default.useRef(null),
172
+ touchProps: react_1.default.useRef(touch_),
171
173
  props: react_1.default.useRef(undefined)
172
174
  };
173
175
  refs.props.current = props;
174
176
  refs.open.current = open;
175
177
  refs.inProp.current = inProp;
178
+ refs.touchProps.current = touch_;
176
179
  const { classes } = useStyle();
177
180
  const styles = {
178
181
  name: {},
@@ -203,7 +206,7 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
203
206
  if (refs.longPress.current) {
204
207
  setLongPress(false);
205
208
  if (refs.props.current.open === undefined) {
206
- if (!inProp)
209
+ if (!refs.inProp.current)
207
210
  onClose();
208
211
  else
209
212
  setInProp(false);
@@ -215,17 +218,19 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
215
218
  children.props.onMouseLeave(event);
216
219
  }, []);
217
220
  const onTouchStart = react_1.default.useCallback((event) => {
218
- if (touch_)
219
- setTouch(true);
221
+ if (!refs.touchProps.current)
222
+ return;
223
+ setTouch(true);
220
224
  if ((0, utils_1.is)('function', children === null || children === void 0 ? void 0 : children.props.onTouchStart))
221
225
  children.props.onTouchStart(event);
222
- }, []);
226
+ }, [touch_]);
223
227
  const onTouchEnd = react_1.default.useCallback((event) => {
224
- if (touch_)
225
- setTouch(false);
228
+ if (!refs.touchProps.current)
229
+ return;
230
+ setTouch(false);
226
231
  if ((0, utils_1.is)('function', children === null || children === void 0 ? void 0 : children.props.onTouchEnd))
227
232
  children.props.onTouchEnd(event);
228
- }, []);
233
+ }, [touch_]);
229
234
  const onFocus = react_1.default.useCallback((event) => {
230
235
  if (focus_)
231
236
  setFocus(true);
@@ -236,7 +241,7 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
236
241
  if (refs.longPress.current) {
237
242
  setLongPress(false);
238
243
  if (refs.props.current.open === undefined) {
239
- if (!inProp)
244
+ if (!refs.inProp.current)
240
245
  onClose();
241
246
  else
242
247
  setInProp(false);
@@ -262,7 +267,7 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
262
267
  const onOpen = () => {
263
268
  if (!open)
264
269
  setOpen(true);
265
- if (!inProp)
270
+ if (!refs.inProp.current)
266
271
  setInProp(true);
267
272
  if ((0, utils_1.is)('function', onOpen_) && !open)
268
273
  onOpen_();
@@ -284,7 +289,13 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
284
289
  !refs.open.current ? onOpen() : onPreClose();
285
290
  }, [onOpen, onPreClose]);
286
291
  react_1.default.useEffect(() => {
292
+ var _a;
287
293
  setInit(true);
294
+ const rootDocument = (0, utils_1.isEnvironment)('browser') ? (((_a = refs.root.current) === null || _a === void 0 ? void 0 : _a.ownerDocument) || window.document) : undefined;
295
+ rootDocument.addEventListener('touchend', onTouchEnd);
296
+ return () => {
297
+ rootDocument.removeEventListener('touchend', onTouchEnd);
298
+ };
288
299
  }, []);
289
300
  react_1.default.useEffect(() => {
290
301
  setAnchor(anchor_);
@@ -304,7 +315,7 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
304
315
  if (refs.open.current)
305
316
  onOpen();
306
317
  else {
307
- if (!inProp)
318
+ if (!refs.inProp.current)
308
319
  onClose();
309
320
  else
310
321
  setInProp(false);
@@ -317,7 +328,7 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
317
328
  if (refs.open.current)
318
329
  onOpen();
319
330
  else {
320
- if (!inProp)
331
+ if (!refs.inProp.current)
321
332
  onClose();
322
333
  else
323
334
  setInProp(false);
@@ -419,9 +430,18 @@ const Tooltip = react_1.default.forwardRef((props_, ref) => {
419
430
  ]
420
431
  ])
421
432
  }) })) })) })));
422
- } }, { children: children && (react_1.default.cloneElement(children, Object.assign(Object.assign({ onMouseMove }, (click && {
433
+ } }, { children: children && (react_1.default.cloneElement(children, Object.assign(Object.assign({ ref: item => {
434
+ if (children === null || children === void 0 ? void 0 : children.ref) {
435
+ if ((0, utils_1.is)('function', children === null || children === void 0 ? void 0 : children.ref))
436
+ children === null || children === void 0 ? void 0 : children.ref(item);
437
+ else
438
+ children.ref.current = item;
439
+ }
440
+ refs.root.current = item;
441
+ }, onMouseMove }, (click && {
423
442
  onClick: (event) => {
424
443
  var _a, _b;
444
+ event.stopPropagation();
425
445
  if ((0, utils_1.is)('function', (_a = children === null || children === void 0 ? void 0 : children.props) === null || _a === void 0 ? void 0 : _a.onClick))
426
446
  (_b = children === null || children === void 0 ? void 0 : children.props) === null || _b === void 0 ? void 0 : _b.onClick(event);
427
447
  onClick(event);
@@ -199,7 +199,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
199
199
  transformOriginRtl,
200
200
  transformOriginRtlSwitch,
201
201
  click,
202
- touch: touch_ = true,
202
+ touch: touch_,
203
203
  longPress: longPress_ = false,
204
204
  hover: hover_ = true,
205
205
  focus: focus_ = false,
@@ -231,15 +231,18 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
231
231
  const [anchor, setAnchor] = React.useState(anchor_);
232
232
  const [inProp, setInProp] = React.useState(open_);
233
233
  const refs = {
234
+ root: React.useRef(null),
234
235
  open: React.useRef(false),
235
236
  inProp: React.useRef(inProp),
236
237
  longPress: React.useRef(false),
237
- longPressTimer: React.useRef(undefined),
238
+ longPressTimer: React.useRef(null),
239
+ touchProps: React.useRef(touch_),
238
240
  props: React.useRef(undefined)
239
241
  };
240
242
  refs.props.current = props;
241
243
  refs.open.current = open;
242
244
  refs.inProp.current = inProp;
245
+ refs.touchProps.current = touch_;
243
246
  const {
244
247
  classes
245
248
  } = useStyle();
@@ -267,20 +270,22 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
267
270
  if (refs.longPress.current) {
268
271
  setLongPress(false);
269
272
  if (refs.props.current.open === undefined) {
270
- if (!inProp) onClose();else setInProp(false);
273
+ if (!refs.inProp.current) onClose();else setInProp(false);
271
274
  }
272
275
  }
273
276
  if (hover_) setHover(false);
274
277
  if (is('function', children?.props.onMouseLeave)) children.props.onMouseLeave(event);
275
278
  }, []);
276
279
  const onTouchStart = React.useCallback(event => {
277
- if (touch_) setTouch(true);
280
+ if (!refs.touchProps.current) return;
281
+ setTouch(true);
278
282
  if (is('function', children?.props.onTouchStart)) children.props.onTouchStart(event);
279
- }, []);
283
+ }, [touch_]);
280
284
  const onTouchEnd = React.useCallback(event => {
281
- if (touch_) setTouch(false);
285
+ if (!refs.touchProps.current) return;
286
+ setTouch(false);
282
287
  if (is('function', children?.props.onTouchEnd)) children.props.onTouchEnd(event);
283
- }, []);
288
+ }, [touch_]);
284
289
  const onFocus = React.useCallback(event => {
285
290
  if (focus_) setFocus(true);
286
291
  if (is('function', children?.props.onFocus)) children.props.onFocus(event);
@@ -289,7 +294,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
289
294
  if (refs.longPress.current) {
290
295
  setLongPress(false);
291
296
  if (refs.props.current.open === undefined) {
292
- if (!inProp) onClose();else setInProp(false);
297
+ if (!refs.inProp.current) onClose();else setInProp(false);
293
298
  }
294
299
  }
295
300
  if (focus_) setFocus(false);
@@ -308,7 +313,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
308
313
  }, []);
309
314
  const onOpen = () => {
310
315
  if (!open) setOpen(true);
311
- if (!inProp) setInProp(true);
316
+ if (!refs.inProp.current) setInProp(true);
312
317
  if (is('function', onOpen_) && !open) onOpen_();
313
318
  };
314
319
  const onClose = () => {
@@ -324,6 +329,11 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
324
329
  }, [onOpen, onPreClose]);
325
330
  React.useEffect(() => {
326
331
  setInit(true);
332
+ const rootDocument = isEnvironment('browser') ? refs.root.current?.ownerDocument || window.document : undefined;
333
+ rootDocument.addEventListener('touchend', onTouchEnd);
334
+ return () => {
335
+ rootDocument.removeEventListener('touchend', onTouchEnd);
336
+ };
327
337
  }, []);
328
338
  React.useEffect(() => {
329
339
  setAnchor(anchor_);
@@ -338,7 +348,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
338
348
  if (init && refs.props.current.open === undefined) {
339
349
  refs.open.current = touch || hover || longPress;
340
350
  if (refs.open.current) onOpen();else {
341
- if (!inProp) onClose();else setInProp(false);
351
+ if (!refs.inProp.current) onClose();else setInProp(false);
342
352
  }
343
353
  }
344
354
  }, [touch, hover, longPress]);
@@ -346,7 +356,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
346
356
  if (init && refs.props.current.open === undefined) {
347
357
  refs.open.current = focus;
348
358
  if (refs.open.current) onOpen();else {
349
- if (!inProp) onClose();else setInProp(false);
359
+ if (!refs.inProp.current) onClose();else setInProp(false);
350
360
  }
351
361
  }
352
362
  }, [focus]);
@@ -432,9 +442,16 @@ const Tooltip = /*#__PURE__*/React.forwardRef((props_, ref) => {
432
442
  }))));
433
443
  }
434
444
  }), children && (/*#__PURE__*/React.cloneElement(children, _objectSpread(_objectSpread({
445
+ ref: item => {
446
+ if (children?.ref) {
447
+ if (is('function', children?.ref)) children?.ref(item);else children.ref.current = item;
448
+ }
449
+ refs.root.current = item;
450
+ },
435
451
  onMouseMove
436
452
  }, click && {
437
453
  onClick: event => {
454
+ event.stopPropagation();
438
455
  if (is('function', children?.props?.onClick)) children?.props?.onClick(event);
439
456
  onClick(event);
440
457
  }
package/esm/index.js CHANGED
@@ -1,4 +1,4 @@
1
- /** @license UiReact v1.0.17
1
+ /** @license UiReact v1.0.19
2
2
  *
3
3
  * This source code is licensed under the MIT license found in the
4
4
  * LICENSE file in the root directory of this source tree.
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@onesy/ui-react",
3
- "version": "1.0.17",
3
+ "version": "1.0.19",
4
4
  "description": "UI for React",
5
- "repository": "https://github.com/onesy-org/onesy.git",
5
+ "repository": "https://github.com/onesy-me/onesy.git",
6
6
  "author": "Lazar <lazareric2@gmail.com>",
7
7
  "license": "MIT",
8
8
  "private": false,