react-zoom-pan-pinch 4.0.0 → 4.0.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.
- package/package.json +4 -3
- package/src/stories/assets/big-image.jpeg +0 -0
- package/src/stories/assets/map.jpg +0 -0
- package/src/stories/assets/medium-image.jpg +0 -0
- package/src/stories/assets/pin.svg +0 -1
- package/src/stories/assets/small-image.jpg +0 -0
- package/src/stories/assets/svg-example.svg +0 -14
- package/src/stories/docs/DocTable.tsx +0 -59
- package/src/stories/docs/HandlerCards.tsx +0 -102
- package/src/stories/docs/Introduction.stories.mdx +0 -135
- package/src/stories/docs/PropTable.tsx +0 -116
- package/src/stories/docs/docs.module.css +0 -370
- package/src/stories/docs/handlers.stories.mdx +0 -7
- package/src/stories/docs/handlers.tsx +0 -111
- package/src/stories/docs/props.stories.mdx +0 -11
- package/src/stories/docs/props.tsx +0 -571
- package/src/stories/examples/axis-lock/axis-lock.stories.mdx +0 -35
- package/src/stories/examples/axis-lock/example.tsx +0 -114
- package/src/stories/examples/bounds/bounds.data.tsx +0 -191
- package/src/stories/examples/bounds/bounds.stories.mdx +0 -99
- package/src/stories/examples/center-zoomed-out/center-zoomed-out.stories.mdx +0 -206
- package/src/stories/examples/cinema/cinema-data.tsx +0 -578
- package/src/stories/examples/cinema/cinema.stories.mdx +0 -30
- package/src/stories/examples/cinema/example.tsx +0 -378
- package/src/stories/examples/cinema/image.png +0 -0
- package/src/stories/examples/content/content.stories.mdx +0 -172
- package/src/stories/examples/content/mixed-content.data.tsx +0 -624
- package/src/stories/examples/content-rerendering/content-updating.stories.mdx +0 -34
- package/src/stories/examples/content-rerendering/example.tsx +0 -631
- package/src/stories/examples/controls/controls.stories.mdx +0 -120
- package/src/stories/examples/image/example.tsx +0 -149
- package/src/stories/examples/image/image.stories.mdx +0 -46
- package/src/stories/examples/image-annotations/example.tsx +0 -1442
- package/src/stories/examples/image-annotations/image-annotations.stories.mdx +0 -39
- package/src/stories/examples/image-responsive/example.tsx +0 -152
- package/src/stories/examples/image-responsive/image-responsive.stories.mdx +0 -51
- package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +0 -107
- package/src/stories/examples/initial-transform/example.tsx +0 -233
- package/src/stories/examples/initial-transform/initial-transform.stories.mdx +0 -37
- package/src/stories/examples/keep-scale/example.tsx +0 -882
- package/src/stories/examples/keep-scale/keep-scale.stories.mdx +0 -30
- package/src/stories/examples/keep-scale/map.stories.mdx +0 -28
- package/src/stories/examples/medical-viewer/chest-xray.tsx +0 -246
- package/src/stories/examples/medical-viewer/example.tsx +0 -690
- package/src/stories/examples/medical-viewer/medical-viewer.stories.mdx +0 -49
- package/src/stories/examples/mini-map/example.tsx +0 -122
- package/src/stories/examples/mini-map/mini-map.stories.mdx +0 -26
- package/src/stories/examples/miro/example.tsx +0 -1573
- package/src/stories/examples/miro/miro.stories.mdx +0 -31
- package/src/stories/examples/padding/example.tsx +0 -147
- package/src/stories/examples/padding/padding.stories.mdx +0 -35
- package/src/stories/examples/product-card/example.tsx +0 -594
- package/src/stories/examples/product-card/product-card.stories.mdx +0 -29
- package/src/stories/examples/stadium/example.tsx +0 -1040
- package/src/stories/examples/stadium/stadium-data.ts +0 -224
- package/src/stories/examples/stadium/stadium.stories.mdx +0 -32
- package/src/stories/examples/stress/example.tsx +0 -59
- package/src/stories/examples/stress/stress-test.stories.mdx +0 -28
- package/src/stories/examples/svg-zoom-to-element/creativity.svg +0 -143
- package/src/stories/examples/svg-zoom-to-element/example.tsx +0 -95
- package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +0 -28
- package/src/stories/examples/text-selection/example.tsx +0 -221
- package/src/stories/examples/text-selection/text-selection.stories.mdx +0 -31
- package/src/stories/examples/velocity/example.tsx +0 -908
- package/src/stories/examples/velocity/velocity.stories.mdx +0 -35
- package/src/stories/examples/virtualize/example.tsx +0 -239
- package/src/stories/examples/virtualize/virtualize.stories.mdx +0 -84
- package/src/stories/examples/zoom-to-element/example.tsx +0 -219
- package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +0 -31
- package/src/stories/hooks/use-controls.stories.mdx +0 -86
- package/src/stories/hooks/use-transform-component.stories.mdx +0 -108
- package/src/stories/hooks/use-transform-context.stories.mdx +0 -92
- package/src/stories/hooks/use-transform-effect.stories.mdx +0 -114
- package/src/stories/hooks/use-transform-init.stories.mdx +0 -105
- package/src/stories/types/args.types.ts +0 -192
- package/src/stories/utils/args.utils.ts +0 -35
- package/src/stories/utils/bounds-overlay.tsx +0 -168
- package/src/stories/utils/code.utils.tsx +0 -22
- package/src/stories/utils/controls.utils.tsx +0 -347
- package/src/stories/utils/index.ts +0 -5
- package/src/stories/utils/styles.module.css +0 -223
- package/src/stories/utils/viewer.styles.ts +0 -34
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import { Meta } from "@storybook/blocks";
|
|
2
|
-
|
|
3
|
-
import { DocTable } from "../docs/DocTable.tsx";
|
|
4
|
-
|
|
5
|
-
<Meta title="Hooks/useTransformComponent" />
|
|
6
|
-
|
|
7
|
-
# useTransformComponent
|
|
8
|
-
|
|
9
|
-
Subscribe to every transform change and **return a value** — typically JSX —
|
|
10
|
-
that updates in real time. This hook is the primary way to build UI that
|
|
11
|
-
reflects the current zoom, pan, or scale state without manual event wiring.
|
|
12
|
-
|
|
13
|
-
## Signature
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
function useTransformComponent<T>(
|
|
17
|
-
callback: (state: ReactZoomPanPinchContextState) => T,
|
|
18
|
-
): T
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
**`state`** contains:
|
|
22
|
-
|
|
23
|
-
```ts
|
|
24
|
-
{
|
|
25
|
-
state: {
|
|
26
|
-
previousScale: number;
|
|
27
|
-
scale: number;
|
|
28
|
-
positionX: number;
|
|
29
|
-
positionY: number;
|
|
30
|
-
};
|
|
31
|
-
instance: ReactZoomPanPinchContext;
|
|
32
|
-
}
|
|
33
|
-
```
|
|
34
|
-
|
|
35
|
-
## How It Works
|
|
36
|
-
|
|
37
|
-
Internally, `useTransformComponent` subscribes to the library's `onChange`
|
|
38
|
-
event and calls your callback on every transform update. The return value is
|
|
39
|
-
stored in React state (`useState`), so the consuming component re-renders
|
|
40
|
-
whenever the transform changes.
|
|
41
|
-
|
|
42
|
-
## When to Use
|
|
43
|
-
|
|
44
|
-
- **Scale badges** — show the current zoom level (`state.scale`)
|
|
45
|
-
- **Coordinate displays** — show positionX / positionY
|
|
46
|
-
- **Conditional rendering** — show/hide elements based on zoom level
|
|
47
|
-
- Any UI element that should **visually update** on every transform tick
|
|
48
|
-
|
|
49
|
-
## Examples
|
|
50
|
-
|
|
51
|
-
### Scale Indicator
|
|
52
|
-
|
|
53
|
-
```tsx
|
|
54
|
-
function ScaleBadge() {
|
|
55
|
-
return useTransformComponent(({ state }) => (
|
|
56
|
-
<div className="badge">{state.scale.toFixed(2)}x</div>
|
|
57
|
-
));
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### Zoom Percentage
|
|
62
|
-
|
|
63
|
-
```tsx
|
|
64
|
-
function ZoomPercent() {
|
|
65
|
-
return useTransformComponent(({ state }) => (
|
|
66
|
-
<span>{Math.round(state.scale * 100)}%</span>
|
|
67
|
-
));
|
|
68
|
-
}
|
|
69
|
-
```
|
|
70
|
-
|
|
71
|
-
### Coordinates
|
|
72
|
-
|
|
73
|
-
```tsx
|
|
74
|
-
function Coords() {
|
|
75
|
-
return useTransformComponent(({ state }) => (
|
|
76
|
-
<div>
|
|
77
|
-
X: {state.positionX.toFixed(0)}, Y: {state.positionY.toFixed(0)}
|
|
78
|
-
</div>
|
|
79
|
-
));
|
|
80
|
-
}
|
|
81
|
-
```
|
|
82
|
-
|
|
83
|
-
## Performance
|
|
84
|
-
|
|
85
|
-
The callback fires on **every** transform event — every mouse move during a
|
|
86
|
-
pan, every wheel tick, every pinch frame. Keep the callback lightweight.
|
|
87
|
-
Avoid expensive computations or large JSX trees inside it. If you only need
|
|
88
|
-
to run side-effects (not render UI), use `useTransformEffect` instead.
|
|
89
|
-
|
|
90
|
-
## vs Other Hooks
|
|
91
|
-
|
|
92
|
-
<DocTable
|
|
93
|
-
columns={[
|
|
94
|
-
{ header: "Hook", style: "name" },
|
|
95
|
-
{ header: "Purpose", style: "type" },
|
|
96
|
-
{ header: "Re-renders?", style: "text" },
|
|
97
|
-
]}
|
|
98
|
-
rows={[
|
|
99
|
-
["useTransformComponent", "Render UI from state", "Yes"],
|
|
100
|
-
["useTransformEffect", "Side-effects on change", "No"],
|
|
101
|
-
["useControls", "Trigger actions", "No"],
|
|
102
|
-
["useTransformContext", "Raw instance access", "No"],
|
|
103
|
-
]}
|
|
104
|
-
/>
|
|
105
|
-
|
|
106
|
-
## Requirements
|
|
107
|
-
|
|
108
|
-
Must be called inside a descendant of `TransformWrapper`.
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import { Meta } from "@storybook/blocks";
|
|
2
|
-
|
|
3
|
-
import { DocTable } from "../docs/DocTable.tsx";
|
|
4
|
-
|
|
5
|
-
<Meta title="Hooks/useTransformContext" />
|
|
6
|
-
|
|
7
|
-
# useTransformContext
|
|
8
|
-
|
|
9
|
-
The **lowest-level** hook — returns the raw library context (the `ZoomPanPinch`
|
|
10
|
-
instance). All other hooks (`useControls`, `useTransformComponent`,
|
|
11
|
-
`useTransformEffect`, `useTransformInit`) are built on top of this one.
|
|
12
|
-
|
|
13
|
-
## Signature
|
|
14
|
-
|
|
15
|
-
```ts
|
|
16
|
-
function useTransformContext(): ReactZoomPanPinchContext
|
|
17
|
-
```
|
|
18
|
-
|
|
19
|
-
## Return Value
|
|
20
|
-
|
|
21
|
-
The returned context object provides:
|
|
22
|
-
|
|
23
|
-
<DocTable
|
|
24
|
-
columns={[
|
|
25
|
-
{ header: "Property", style: "name" },
|
|
26
|
-
{ header: "Type", style: "type" },
|
|
27
|
-
{ header: "Description", style: "text" },
|
|
28
|
-
]}
|
|
29
|
-
rows={[
|
|
30
|
-
["state", "{ scale, positionX, positionY, previousScale }", "Current mutable transform state"],
|
|
31
|
-
["setup", "object", "Resolved configuration (minScale, maxScale, etc.)"],
|
|
32
|
-
["wrapperComponent", "HTMLDivElement | null", "The wrapper DOM element"],
|
|
33
|
-
["contentComponent", "HTMLDivElement | null", "The content DOM element"],
|
|
34
|
-
["onChange", "(callback) => unsubscribe", "Subscribe to transform changes"],
|
|
35
|
-
["onInit", "(callback) => unsubscribe", "Subscribe to initialization"],
|
|
36
|
-
]}
|
|
37
|
-
/>
|
|
38
|
-
|
|
39
|
-
## When to Use
|
|
40
|
-
|
|
41
|
-
- **Building custom hooks** on top of the library internals
|
|
42
|
-
- **Direct DOM access** to wrapper/content elements for measurements
|
|
43
|
-
- **Advanced integrations** that need the raw instance (e.g., syncing with
|
|
44
|
-
external renderers like Canvas or WebGL)
|
|
45
|
-
|
|
46
|
-
Most applications should use `useControls` (for actions) or
|
|
47
|
-
`useTransformComponent` (for reactive state) instead.
|
|
48
|
-
|
|
49
|
-
## Example — Custom Scale Logger
|
|
50
|
-
|
|
51
|
-
```tsx
|
|
52
|
-
import { useEffect } from "react";
|
|
53
|
-
import { useTransformContext } from "react-zoom-pan-pinch";
|
|
54
|
-
|
|
55
|
-
function useLogScale() {
|
|
56
|
-
const ctx = useTransformContext();
|
|
57
|
-
|
|
58
|
-
useEffect(() => {
|
|
59
|
-
const unsub = ctx.onChange((ref) => {
|
|
60
|
-
console.log("Scale:", ref.instance.state.scale);
|
|
61
|
-
});
|
|
62
|
-
return unsub;
|
|
63
|
-
}, [ctx]);
|
|
64
|
-
}
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## Example — Wrapper Dimensions
|
|
68
|
-
|
|
69
|
-
```tsx
|
|
70
|
-
function useWrapperSize() {
|
|
71
|
-
const ctx = useTransformContext();
|
|
72
|
-
const wrapper = ctx.wrapperComponent;
|
|
73
|
-
|
|
74
|
-
if (!wrapper) return { width: 0, height: 0 };
|
|
75
|
-
return {
|
|
76
|
-
width: wrapper.offsetWidth,
|
|
77
|
-
height: wrapper.offsetHeight,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
```
|
|
81
|
-
|
|
82
|
-
## Error Handling
|
|
83
|
-
|
|
84
|
-
Throws if called outside of `TransformWrapper`:
|
|
85
|
-
|
|
86
|
-
```
|
|
87
|
-
Error: Transform context must be placed inside TransformWrapper
|
|
88
|
-
```
|
|
89
|
-
|
|
90
|
-
## Requirements
|
|
91
|
-
|
|
92
|
-
Must be called inside a descendant of `TransformWrapper`.
|
|
@@ -1,114 +0,0 @@
|
|
|
1
|
-
import { Meta } from "@storybook/blocks";
|
|
2
|
-
|
|
3
|
-
import { DocTable } from "../docs/DocTable.tsx";
|
|
4
|
-
|
|
5
|
-
<Meta title="Hooks/useTransformEffect" />
|
|
6
|
-
|
|
7
|
-
# useTransformEffect
|
|
8
|
-
|
|
9
|
-
Run a **side-effect** on every transform change — without triggering React
|
|
10
|
-
re-renders. Think of it as `useEffect` for transform state: your callback
|
|
11
|
-
fires on every pan, zoom, or pinch event, and can optionally return a cleanup
|
|
12
|
-
function.
|
|
13
|
-
|
|
14
|
-
## Signature
|
|
15
|
-
|
|
16
|
-
```ts
|
|
17
|
-
function useTransformEffect(
|
|
18
|
-
callback: (state: ReactZoomPanPinchContextState) => void | (() => void),
|
|
19
|
-
): void
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
**`state`** contains:
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
{
|
|
26
|
-
state: { previousScale, scale, positionX, positionY };
|
|
27
|
-
instance: ReactZoomPanPinchContext;
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
The callback can return a **cleanup function** that runs before the next
|
|
32
|
-
invocation and on unmount — the same pattern as `useEffect`.
|
|
33
|
-
|
|
34
|
-
## When to Use
|
|
35
|
-
|
|
36
|
-
- **Analytics** — log zoom events or viewport positions
|
|
37
|
-
- **URL sync** — update query parameters with the current viewport
|
|
38
|
-
- **External state** — push transform data to a store (Redux, Zustand, etc.)
|
|
39
|
-
- **DOM mutations** — update a canvas overlay or external tooltip positions
|
|
40
|
-
- **Debounced saves** — persist viewport state after interaction stops
|
|
41
|
-
|
|
42
|
-
For rendering UI that updates with transform state, use
|
|
43
|
-
`useTransformComponent` instead — it manages React state and re-renders for you.
|
|
44
|
-
|
|
45
|
-
## Examples
|
|
46
|
-
|
|
47
|
-
### Sync to URL
|
|
48
|
-
|
|
49
|
-
```tsx
|
|
50
|
-
import { useTransformEffect } from "react-zoom-pan-pinch";
|
|
51
|
-
|
|
52
|
-
function ViewportSync() {
|
|
53
|
-
useTransformEffect(({ state }) => {
|
|
54
|
-
const params = new URLSearchParams(window.location.search);
|
|
55
|
-
params.set("x", String(Math.round(state.positionX)));
|
|
56
|
-
params.set("y", String(Math.round(state.positionY)));
|
|
57
|
-
params.set("s", state.scale.toFixed(2));
|
|
58
|
-
window.history.replaceState(null, "", `?${params}`);
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
return null;
|
|
62
|
-
}
|
|
63
|
-
```
|
|
64
|
-
|
|
65
|
-
### Analytics Logging
|
|
66
|
-
|
|
67
|
-
```tsx
|
|
68
|
-
function ZoomAnalytics() {
|
|
69
|
-
useTransformEffect(({ state }) => {
|
|
70
|
-
if (state.scale !== state.previousScale) {
|
|
71
|
-
analytics.track("zoom_changed", { scale: state.scale });
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
return null;
|
|
76
|
-
}
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
### Cleanup Pattern
|
|
80
|
-
|
|
81
|
-
```tsx
|
|
82
|
-
function Overlay() {
|
|
83
|
-
useTransformEffect(({ state }) => {
|
|
84
|
-
const overlay = document.getElementById("canvas-overlay");
|
|
85
|
-
overlay?.style.setProperty("--scale", String(state.scale));
|
|
86
|
-
|
|
87
|
-
return () => {
|
|
88
|
-
overlay?.style.removeProperty("--scale");
|
|
89
|
-
};
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
return null;
|
|
93
|
-
}
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
## Key Differences
|
|
97
|
-
|
|
98
|
-
<DocTable
|
|
99
|
-
columns={[
|
|
100
|
-
{ header: "" },
|
|
101
|
-
{ header: "useTransformEffect", style: "type" },
|
|
102
|
-
{ header: "useTransformComponent", style: "text" },
|
|
103
|
-
]}
|
|
104
|
-
rows={[
|
|
105
|
-
["Purpose", "Side-effects", "Render UI"],
|
|
106
|
-
["Returns", "void", "T (your callback's return)"],
|
|
107
|
-
["Re-renders?", "No", "Yes"],
|
|
108
|
-
["Use case", "Logging, syncing, DOM", "Badges, labels, indicators"],
|
|
109
|
-
]}
|
|
110
|
-
/>
|
|
111
|
-
|
|
112
|
-
## Requirements
|
|
113
|
-
|
|
114
|
-
Must be called inside a descendant of `TransformWrapper`.
|
|
@@ -1,105 +0,0 @@
|
|
|
1
|
-
import { Meta } from "@storybook/blocks";
|
|
2
|
-
|
|
3
|
-
import { DocTable } from "../docs/DocTable.tsx";
|
|
4
|
-
|
|
5
|
-
<Meta title="Hooks/useTransformInit" />
|
|
6
|
-
|
|
7
|
-
# useTransformInit
|
|
8
|
-
|
|
9
|
-
Run a callback **once** when the `TransformWrapper` content and wrapper DOM
|
|
10
|
-
elements are ready. If the components are already mounted when the hook runs,
|
|
11
|
-
the callback fires immediately. Otherwise, it waits for the internal `onInit`
|
|
12
|
-
event.
|
|
13
|
-
|
|
14
|
-
## Signature
|
|
15
|
-
|
|
16
|
-
```ts
|
|
17
|
-
function useTransformInit(
|
|
18
|
-
callback: (state: ReactZoomPanPinchContextState) => void | (() => void),
|
|
19
|
-
): void
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
**`state`** contains:
|
|
23
|
-
|
|
24
|
-
```ts
|
|
25
|
-
{
|
|
26
|
-
state: { previousScale, scale, positionX, positionY };
|
|
27
|
-
instance: ReactZoomPanPinchContext;
|
|
28
|
-
}
|
|
29
|
-
```
|
|
30
|
-
|
|
31
|
-
The callback can return a **cleanup function** that runs on unmount.
|
|
32
|
-
|
|
33
|
-
## When to Use
|
|
34
|
-
|
|
35
|
-
- **Initial measurements** — read wrapper/content dimensions after mount
|
|
36
|
-
- **One-time setup** — configure external systems that depend on viewport size
|
|
37
|
-
- **Initial state logging** — record the starting transform values
|
|
38
|
-
|
|
39
|
-
For reacting to **every** transform change, use `useTransformEffect` instead.
|
|
40
|
-
This hook fires only once.
|
|
41
|
-
|
|
42
|
-
## Examples
|
|
43
|
-
|
|
44
|
-
### Read Initial Dimensions
|
|
45
|
-
|
|
46
|
-
```tsx
|
|
47
|
-
import { useTransformInit } from "react-zoom-pan-pinch";
|
|
48
|
-
|
|
49
|
-
function Setup() {
|
|
50
|
-
useTransformInit(({ instance }) => {
|
|
51
|
-
const wrapper = instance.wrapperComponent;
|
|
52
|
-
if (wrapper) {
|
|
53
|
-
console.log("Viewport:", wrapper.offsetWidth, "x", wrapper.offsetHeight);
|
|
54
|
-
}
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
return null;
|
|
58
|
-
}
|
|
59
|
-
```
|
|
60
|
-
|
|
61
|
-
### External System Setup
|
|
62
|
-
|
|
63
|
-
```tsx
|
|
64
|
-
function CanvasSetup() {
|
|
65
|
-
useTransformInit(({ state, instance }) => {
|
|
66
|
-
const canvas = initExternalCanvas({
|
|
67
|
-
width: instance.wrapperComponent?.offsetWidth ?? 0,
|
|
68
|
-
height: instance.wrapperComponent?.offsetHeight ?? 0,
|
|
69
|
-
initialScale: state.scale,
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
return () => {
|
|
73
|
-
canvas.destroy();
|
|
74
|
-
};
|
|
75
|
-
});
|
|
76
|
-
|
|
77
|
-
return null;
|
|
78
|
-
}
|
|
79
|
-
```
|
|
80
|
-
|
|
81
|
-
## Key Differences
|
|
82
|
-
|
|
83
|
-
<DocTable
|
|
84
|
-
columns={[
|
|
85
|
-
{ header: "" },
|
|
86
|
-
{ header: "useTransformInit", style: "type" },
|
|
87
|
-
{ header: "useTransformEffect", style: "text" },
|
|
88
|
-
]}
|
|
89
|
-
rows={[
|
|
90
|
-
["Fires", "Once (on mount)", "On every transform change"],
|
|
91
|
-
["Purpose", "Setup / measurements", "Ongoing side-effects"],
|
|
92
|
-
["Deps", "[] (captured once)", "[callback, context]"],
|
|
93
|
-
]}
|
|
94
|
-
/>
|
|
95
|
-
|
|
96
|
-
## Caveat
|
|
97
|
-
|
|
98
|
-
The dependency array is **empty** internally (`[]`), so the callback is
|
|
99
|
-
captured once at mount time. If your callback references props or state that
|
|
100
|
-
change over time, those values will be stale. For dynamic callbacks, use
|
|
101
|
-
`useTransformEffect`.
|
|
102
|
-
|
|
103
|
-
## Requirements
|
|
104
|
-
|
|
105
|
-
Must be called inside a descendant of `TransformWrapper`.
|
|
@@ -1,192 +0,0 @@
|
|
|
1
|
-
import { initialSetup } from "../../constants/state.constants";
|
|
2
|
-
|
|
3
|
-
export const argsTypes = {
|
|
4
|
-
wheel: {
|
|
5
|
-
table: {
|
|
6
|
-
disable: true,
|
|
7
|
-
},
|
|
8
|
-
},
|
|
9
|
-
"wheel.step": {
|
|
10
|
-
defaultValue: initialSetup.wheel.step,
|
|
11
|
-
control: {
|
|
12
|
-
type: "number",
|
|
13
|
-
min: 0,
|
|
14
|
-
},
|
|
15
|
-
table: {
|
|
16
|
-
defaultValue: { summary: "0" },
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
"wheel.disabled": {
|
|
20
|
-
defaultValue: initialSetup.wheel.disabled,
|
|
21
|
-
control: { type: "boolean" },
|
|
22
|
-
table: {
|
|
23
|
-
defaultValue: { summary: "false" },
|
|
24
|
-
type: { summary: "boolean" },
|
|
25
|
-
},
|
|
26
|
-
},
|
|
27
|
-
"wheel.wheelDisabled": {
|
|
28
|
-
defaultValue: initialSetup.wheel.wheelDisabled,
|
|
29
|
-
control: { type: "boolean" },
|
|
30
|
-
table: {
|
|
31
|
-
defaultValue: { summary: "false" },
|
|
32
|
-
type: { summary: "boolean" },
|
|
33
|
-
},
|
|
34
|
-
},
|
|
35
|
-
"wheel.touchPadDisabled": {
|
|
36
|
-
defaultValue: initialSetup.wheel.touchPadDisabled,
|
|
37
|
-
control: { type: "boolean" },
|
|
38
|
-
table: {
|
|
39
|
-
defaultValue: { summary: "false" },
|
|
40
|
-
type: { summary: "boolean" },
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
"wheel.activationKeys": {
|
|
44
|
-
defaultValue: initialSetup.wheel.activationKeys,
|
|
45
|
-
control: { type: "text" },
|
|
46
|
-
table: {
|
|
47
|
-
defaultValue: { summary: "" },
|
|
48
|
-
type: { summary: "string" },
|
|
49
|
-
},
|
|
50
|
-
},
|
|
51
|
-
"wheel.excluded": {
|
|
52
|
-
defaultValue: initialSetup.wheel.excluded,
|
|
53
|
-
control: { type: "array" },
|
|
54
|
-
table: {
|
|
55
|
-
defaultValue: { summary: "" },
|
|
56
|
-
type: { summary: "array" },
|
|
57
|
-
},
|
|
58
|
-
},
|
|
59
|
-
panning: {
|
|
60
|
-
table: {
|
|
61
|
-
disable: true,
|
|
62
|
-
},
|
|
63
|
-
},
|
|
64
|
-
"panning.disabled": {
|
|
65
|
-
defaultValue: initialSetup.panning.disabled,
|
|
66
|
-
control: { type: "boolean" },
|
|
67
|
-
table: {
|
|
68
|
-
defaultValue: { summary: "false" },
|
|
69
|
-
type: { summary: "boolean" },
|
|
70
|
-
},
|
|
71
|
-
},
|
|
72
|
-
"panning.lockAxisX": {
|
|
73
|
-
defaultValue: initialSetup.panning.lockAxisX,
|
|
74
|
-
control: { type: "boolean" },
|
|
75
|
-
table: {
|
|
76
|
-
defaultValue: { summary: "false" },
|
|
77
|
-
type: { summary: "boolean" },
|
|
78
|
-
},
|
|
79
|
-
},
|
|
80
|
-
"panning.lockAxisY": {
|
|
81
|
-
defaultValue: initialSetup.panning.lockAxisY,
|
|
82
|
-
control: { type: "boolean" },
|
|
83
|
-
table: {
|
|
84
|
-
defaultValue: { summary: "false" },
|
|
85
|
-
type: { summary: "boolean" },
|
|
86
|
-
},
|
|
87
|
-
},
|
|
88
|
-
"panning.activationKeys": {
|
|
89
|
-
defaultValue: initialSetup.panning.activationKeys,
|
|
90
|
-
control: { type: "text" },
|
|
91
|
-
table: {
|
|
92
|
-
defaultValue: { summary: "" },
|
|
93
|
-
type: { summary: "string" },
|
|
94
|
-
},
|
|
95
|
-
},
|
|
96
|
-
"panning.excluded": {
|
|
97
|
-
defaultValue: initialSetup.panning.excluded,
|
|
98
|
-
control: { type: "array" },
|
|
99
|
-
table: {
|
|
100
|
-
defaultValue: { summary: "" },
|
|
101
|
-
type: { summary: "array" },
|
|
102
|
-
},
|
|
103
|
-
},
|
|
104
|
-
pinch: {
|
|
105
|
-
table: {
|
|
106
|
-
disable: true,
|
|
107
|
-
},
|
|
108
|
-
},
|
|
109
|
-
"pinch.step": {
|
|
110
|
-
defaultValue: initialSetup.pinch.step,
|
|
111
|
-
control: {
|
|
112
|
-
type: "number",
|
|
113
|
-
min: 0,
|
|
114
|
-
},
|
|
115
|
-
table: {
|
|
116
|
-
defaultValue: { summary: "0" },
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
"pinch.disabled": {
|
|
120
|
-
defaultValue: initialSetup.pinch.disabled,
|
|
121
|
-
control: { type: "boolean" },
|
|
122
|
-
table: {
|
|
123
|
-
defaultValue: { summary: "false" },
|
|
124
|
-
type: { summary: "boolean" },
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
"pinch.excluded": {
|
|
128
|
-
defaultValue: initialSetup.pinch.excluded,
|
|
129
|
-
control: { type: "array" },
|
|
130
|
-
table: {
|
|
131
|
-
defaultValue: { summary: "" },
|
|
132
|
-
type: { summary: "array" },
|
|
133
|
-
},
|
|
134
|
-
},
|
|
135
|
-
doubleClick: {
|
|
136
|
-
table: {
|
|
137
|
-
disable: true,
|
|
138
|
-
},
|
|
139
|
-
},
|
|
140
|
-
"doubleClick.step": {
|
|
141
|
-
defaultValue: initialSetup.doubleClick.step,
|
|
142
|
-
control: {
|
|
143
|
-
type: "number",
|
|
144
|
-
min: 0,
|
|
145
|
-
},
|
|
146
|
-
table: {
|
|
147
|
-
defaultValue: { summary: "0" },
|
|
148
|
-
},
|
|
149
|
-
},
|
|
150
|
-
"doubleClick.disabled": {
|
|
151
|
-
defaultValue: initialSetup.doubleClick.disabled,
|
|
152
|
-
control: { type: "boolean" },
|
|
153
|
-
table: {
|
|
154
|
-
defaultValue: { summary: "false" },
|
|
155
|
-
type: { summary: "boolean" },
|
|
156
|
-
},
|
|
157
|
-
},
|
|
158
|
-
"doubleClick.excluded": {
|
|
159
|
-
defaultValue: initialSetup.doubleClick.excluded,
|
|
160
|
-
control: { type: "array" },
|
|
161
|
-
table: {
|
|
162
|
-
defaultValue: { summary: "" },
|
|
163
|
-
type: { summary: "array" },
|
|
164
|
-
},
|
|
165
|
-
},
|
|
166
|
-
};
|
|
167
|
-
// doubleClick: {
|
|
168
|
-
// disabled: false,
|
|
169
|
-
// step: 20,
|
|
170
|
-
// mode: "zoomIn",
|
|
171
|
-
// animation: true,
|
|
172
|
-
// animationType: "easeOut",
|
|
173
|
-
// animationTime: 200,
|
|
174
|
-
// },
|
|
175
|
-
// zoomAnimation: {
|
|
176
|
-
// disabled: false,
|
|
177
|
-
// size: 0.4,
|
|
178
|
-
// animationTime: 200,
|
|
179
|
-
// animationType: "easeOut",
|
|
180
|
-
// },
|
|
181
|
-
// autoAlignment: {
|
|
182
|
-
// disabled: false,
|
|
183
|
-
// size: 30,
|
|
184
|
-
// animationTime: 200,
|
|
185
|
-
// animationType: "easeOut",
|
|
186
|
-
// },
|
|
187
|
-
// velocityAnimation: {
|
|
188
|
-
// disabled: false,
|
|
189
|
-
// sensitivity: 1,
|
|
190
|
-
// animationTime: 600,
|
|
191
|
-
// animationType: "easeOut",
|
|
192
|
-
// },
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
export const normalizeArgs = (args: { [key: string]: any }): any => {
|
|
2
|
-
const newArgs: Record<string, any> = {};
|
|
3
|
-
|
|
4
|
-
Object.keys(args).forEach((key) => {
|
|
5
|
-
const normalizedKey = key.split(".");
|
|
6
|
-
const isNested = normalizedKey.length === 2;
|
|
7
|
-
|
|
8
|
-
if (isNested) {
|
|
9
|
-
if (!newArgs[normalizedKey[0]]) {
|
|
10
|
-
newArgs[normalizedKey[0]] = {};
|
|
11
|
-
}
|
|
12
|
-
newArgs[normalizedKey[0]][normalizedKey[1]] = args[key];
|
|
13
|
-
} else {
|
|
14
|
-
newArgs[key] = args[key];
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return {
|
|
19
|
-
...newArgs,
|
|
20
|
-
// DO NOT REMOVE - it will lag out the storybook!!
|
|
21
|
-
onTransform: undefined,
|
|
22
|
-
onWheelStart: undefined,
|
|
23
|
-
onWheel: undefined,
|
|
24
|
-
onWheelStop: undefined,
|
|
25
|
-
onZoomStart: undefined,
|
|
26
|
-
onZoom: undefined,
|
|
27
|
-
onZoomStop: undefined,
|
|
28
|
-
onPanningStart: undefined,
|
|
29
|
-
onPanning: undefined,
|
|
30
|
-
onPanningStop: undefined,
|
|
31
|
-
onPinchStart: undefined,
|
|
32
|
-
onPinch: undefined,
|
|
33
|
-
onPinchStop: undefined,
|
|
34
|
-
};
|
|
35
|
-
};
|