@mirohq/design-system-utils
Advanced tools
Comparing version 0.14.0 to 0.14.1
@@ -7,10 +7,2 @@ 'use strict'; | ||
const createConstants = (...constants) => constants.reduce( | ||
(result, key) => ({ | ||
...result, | ||
[key]: key | ||
}), | ||
{} | ||
); | ||
const isFragment = (fragment) => (fragment == null ? void 0 : fragment.type) === react.Fragment || fragment === react.Fragment; | ||
@@ -45,3 +37,48 @@ const addPropsToChildren = (children, containsComponent, props) => { | ||
}; | ||
const removeEventProps = (props, exceptions) => Object.entries(props).reduce((result, [key, fn]) => { | ||
if (key.startsWith("on") && !exceptions.includes(key)) { | ||
return result; | ||
} | ||
return { | ||
...result, | ||
[key]: fn | ||
}; | ||
}, {}); | ||
const isOverTarget = (point, target) => { | ||
const rect = target.getBoundingClientRect(); | ||
const pointRect = getPointClientRect(point); | ||
return areRectanglesOverlapping(rect, pointRect); | ||
}; | ||
const getPointClientRect = (point) => { | ||
var _a, _b, _c, _d; | ||
const width = (_a = point.width) != null ? _a : 0; | ||
const height = (_b = point.height) != null ? _b : 0; | ||
const offsetX = (_c = width !== 0 ? width / 2 : point.radiusX) != null ? _c : 0; | ||
const offsetY = (_d = height !== 0 ? height / 2 : point.radiusY) != null ? _d : 0; | ||
return { | ||
top: point.clientY - offsetY, | ||
right: point.clientX + offsetX, | ||
bottom: point.clientY + offsetY, | ||
left: point.clientX - offsetX | ||
}; | ||
}; | ||
const areRectanglesOverlapping = (a, b) => { | ||
if (a.left > b.right || b.left > a.right) { | ||
return false; | ||
} | ||
if (a.top > b.bottom || b.top > a.bottom) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
const createConstants = (...constants) => constants.reduce( | ||
(result, key) => ({ | ||
...result, | ||
[key]: key | ||
}), | ||
{} | ||
); | ||
const mapKeysToVariants = (map, prop) => Object.keys(map).reduce((acc, key) => { | ||
@@ -68,7 +105,11 @@ let newProp = {}; | ||
exports.addPropsToChildren = addPropsToChildren; | ||
exports.areRectanglesOverlapping = areRectanglesOverlapping; | ||
exports.booleanify = booleanify; | ||
exports.createConstants = createConstants; | ||
exports.getPointClientRect = getPointClientRect; | ||
exports.isFragment = isFragment; | ||
exports.isOverTarget = isOverTarget; | ||
exports.mapKeysToVariants = mapKeysToVariants; | ||
exports.mergeRefs = mergeRefs; | ||
exports.removeEventProps = removeEventProps; | ||
//# sourceMappingURL=main.js.map |
import { Fragment, Children, cloneElement } from 'react'; | ||
const createConstants = (...constants) => constants.reduce( | ||
(result, key) => ({ | ||
...result, | ||
[key]: key | ||
}), | ||
{} | ||
); | ||
const isFragment = (fragment) => (fragment == null ? void 0 : fragment.type) === Fragment || fragment === Fragment; | ||
@@ -40,3 +32,48 @@ const addPropsToChildren = (children, containsComponent, props) => { | ||
}; | ||
const removeEventProps = (props, exceptions) => Object.entries(props).reduce((result, [key, fn]) => { | ||
if (key.startsWith("on") && !exceptions.includes(key)) { | ||
return result; | ||
} | ||
return { | ||
...result, | ||
[key]: fn | ||
}; | ||
}, {}); | ||
const isOverTarget = (point, target) => { | ||
const rect = target.getBoundingClientRect(); | ||
const pointRect = getPointClientRect(point); | ||
return areRectanglesOverlapping(rect, pointRect); | ||
}; | ||
const getPointClientRect = (point) => { | ||
var _a, _b, _c, _d; | ||
const width = (_a = point.width) != null ? _a : 0; | ||
const height = (_b = point.height) != null ? _b : 0; | ||
const offsetX = (_c = width !== 0 ? width / 2 : point.radiusX) != null ? _c : 0; | ||
const offsetY = (_d = height !== 0 ? height / 2 : point.radiusY) != null ? _d : 0; | ||
return { | ||
top: point.clientY - offsetY, | ||
right: point.clientX + offsetX, | ||
bottom: point.clientY + offsetY, | ||
left: point.clientX - offsetX | ||
}; | ||
}; | ||
const areRectanglesOverlapping = (a, b) => { | ||
if (a.left > b.right || b.left > a.right) { | ||
return false; | ||
} | ||
if (a.top > b.bottom || b.top > a.bottom) { | ||
return false; | ||
} | ||
return true; | ||
}; | ||
const createConstants = (...constants) => constants.reduce( | ||
(result, key) => ({ | ||
...result, | ||
[key]: key | ||
}), | ||
{} | ||
); | ||
const mapKeysToVariants = (map, prop) => Object.keys(map).reduce((acc, key) => { | ||
@@ -62,3 +99,3 @@ let newProp = {}; | ||
export { addPropsToChildren, booleanify, createConstants, isFragment, mapKeysToVariants, mergeRefs }; | ||
export { addPropsToChildren, areRectanglesOverlapping, booleanify, createConstants, getPointClientRect, isFragment, isOverTarget, mapKeysToVariants, mergeRefs, removeEventProps }; | ||
//# sourceMappingURL=module.js.map |
@@ -7,4 +7,2 @@ import * as react from 'react'; | ||
declare const createConstants: <T extends string | number>(...constants: readonly T[]) => { [K in T]: K; }; | ||
declare const isFragment: (fragment: any) => boolean; | ||
@@ -24,4 +22,31 @@ /** | ||
*/ | ||
declare const mergeRefs: <T = any>(refs: (react.MutableRefObject<T> | react.LegacyRef<T>)[]) => (instance: T | null) => void; | ||
declare const mergeRefs: <T = any>(refs: (react.MutableRefObject<T> | react.LegacyRef<T>)[]) => react.Ref<T>; | ||
/** | ||
* Remove any `on` prop from an object | ||
* @param props object | ||
* @param exceptions array string starting with `on` | ||
* @returns props without keys starting by `on` | ||
*/ | ||
declare const removeEventProps: <T extends {}, Exceptions extends ("onCopy" | "onCopyCapture" | "onCut" | "onCutCapture" | "onPaste" | "onPasteCapture" | "onCompositionEnd" | "onCompositionEndCapture" | "onCompositionStart" | "onCompositionStartCapture" | "onCompositionUpdate" | "onCompositionUpdateCapture" | "onFocus" | "onFocusCapture" | "onBlur" | "onBlurCapture" | "onChange" | "onChangeCapture" | "onBeforeInput" | "onBeforeInputCapture" | "onInput" | "onInputCapture" | "onReset" | "onResetCapture" | "onSubmit" | "onSubmitCapture" | "onInvalid" | "onInvalidCapture" | "onLoad" | "onLoadCapture" | "onError" | "onErrorCapture" | "onKeyDown" | "onKeyDownCapture" | "onKeyPress" | "onKeyPressCapture" | "onKeyUp" | "onKeyUpCapture" | "onAbort" | "onAbortCapture" | "onCanPlay" | "onCanPlayCapture" | "onCanPlayThrough" | "onCanPlayThroughCapture" | "onDurationChange" | "onDurationChangeCapture" | "onEmptied" | "onEmptiedCapture" | "onEncrypted" | "onEncryptedCapture" | "onEnded" | "onEndedCapture" | "onLoadedData" | "onLoadedDataCapture" | "onLoadedMetadata" | "onLoadedMetadataCapture" | "onLoadStart" | "onLoadStartCapture" | "onPause" | "onPauseCapture" | "onPlay" | "onPlayCapture" | "onPlaying" | "onPlayingCapture" | "onProgress" | "onProgressCapture" | "onRateChange" | "onRateChangeCapture" | "onResize" | "onResizeCapture" | "onSeeked" | "onSeekedCapture" | "onSeeking" | "onSeekingCapture" | "onStalled" | "onStalledCapture" | "onSuspend" | "onSuspendCapture" | "onTimeUpdate" | "onTimeUpdateCapture" | "onVolumeChange" | "onVolumeChangeCapture" | "onWaiting" | "onWaitingCapture" | "onAuxClick" | "onAuxClickCapture" | "onClick" | "onClickCapture" | "onContextMenu" | "onContextMenuCapture" | "onDoubleClick" | "onDoubleClickCapture" | "onDrag" | "onDragCapture" | "onDragEnd" | "onDragEndCapture" | "onDragEnter" | "onDragEnterCapture" | "onDragExit" | "onDragExitCapture" | "onDragLeave" | "onDragLeaveCapture" | "onDragOver" | "onDragOverCapture" | "onDragStart" | "onDragStartCapture" | "onDrop" | "onDropCapture" | "onMouseDown" | "onMouseDownCapture" | "onMouseEnter" | "onMouseLeave" | "onMouseMove" | "onMouseMoveCapture" | "onMouseOut" | "onMouseOutCapture" | "onMouseOver" | "onMouseOverCapture" | "onMouseUp" | "onMouseUpCapture" | "onSelect" | "onSelectCapture" | "onTouchCancel" | "onTouchCancelCapture" | "onTouchEnd" | "onTouchEndCapture" | "onTouchMove" | "onTouchMoveCapture" | "onTouchStart" | "onTouchStartCapture" | "onPointerDown" | "onPointerDownCapture" | "onPointerMove" | "onPointerMoveCapture" | "onPointerUp" | "onPointerUpCapture" | "onPointerCancel" | "onPointerCancelCapture" | "onPointerEnter" | "onPointerEnterCapture" | "onPointerLeave" | "onPointerLeaveCapture" | "onPointerOver" | "onPointerOverCapture" | "onPointerOut" | "onPointerOutCapture" | "onGotPointerCapture" | "onGotPointerCaptureCapture" | "onLostPointerCapture" | "onLostPointerCaptureCapture" | "onScroll" | "onScrollCapture" | "onWheel" | "onWheelCapture" | "onAnimationStart" | "onAnimationStartCapture" | "onAnimationEnd" | "onAnimationEndCapture" | "onAnimationIteration" | "onAnimationIterationCapture" | "onTransitionEnd" | "onTransitionEndCapture")[] = []>(props: T, exceptions: Exceptions) => { [K in keyof T as K extends Exceptions ? never : K]: T[K]; }; | ||
interface Rect { | ||
top: number; | ||
right: number; | ||
bottom: number; | ||
left: number; | ||
} | ||
interface EventPoint { | ||
clientX: number; | ||
clientY: number; | ||
width?: number; | ||
height?: number; | ||
radiusX?: number; | ||
radiusY?: number; | ||
} | ||
declare const isOverTarget: (point: EventPoint, target: Element) => boolean; | ||
declare const getPointClientRect: (point: EventPoint) => Rect; | ||
declare const areRectanglesOverlapping: (a: Rect, b: Rect) => boolean; | ||
declare const createConstants: <T extends string | number>(...constants: readonly T[]) => { [K in T]: K; }; | ||
declare type KeyVariants<KeyMap, Prop extends keyof CSSProperties> = { | ||
@@ -48,2 +73,2 @@ [K in keyof KeyMap]: { | ||
export { addPropsToChildren, booleanify, createConstants, isFragment, mapKeysToVariants, mergeRefs }; | ||
export { addPropsToChildren, areRectanglesOverlapping, booleanify, createConstants, getPointClientRect, isFragment, isOverTarget, mapKeysToVariants, mergeRefs, removeEventProps }; |
{ | ||
"name": "@mirohq/design-system-utils", | ||
"version": "0.14.0", | ||
"version": "0.14.1", | ||
"description": "", | ||
@@ -29,3 +29,3 @@ "author": "Miro", | ||
"dependencies": { | ||
"@mirohq/design-system-types": "^0.5.0" | ||
"@mirohq/design-system-types": "^0.6.0" | ||
}, | ||
@@ -32,0 +32,0 @@ "scripts": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
31272
273
+ Added@mirohq/design-system-types@0.6.2(transitive)
- Removed@mirohq/design-system-types@0.5.0(transitive)