react-zoom-pan-pinch 3.0.2 → 3.0.3

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.
Files changed (72) hide show
  1. package/.storybook/main.js +23 -0
  2. package/.storybook/preview-head.html +5 -0
  3. package/.storybook/preview.js +11 -0
  4. package/.storybook/theme-overrides.css +49 -0
  5. package/__tests__/features/props.spec.tsx +11 -0
  6. package/__tests__/features/rendering.spec.tsx +36 -0
  7. package/__tests__/shared/render.shared.tsx +41 -0
  8. package/__tests__/utils/controls.utils.tsx +25 -0
  9. package/__tests__/utils/example.tsx +81 -0
  10. package/dist/__tests__/features/props.spec.d.ts +1 -0
  11. package/dist/__tests__/features/rendering.spec.d.ts +1 -0
  12. package/dist/__tests__/shared/render.shared.d.ts +11 -0
  13. package/dist/__tests__/utils/controls.utils.d.ts +3 -0
  14. package/dist/__tests__/utils/example.d.ts +6 -0
  15. package/dist/src/stories/docs/handlers.d.ts +12 -0
  16. package/dist/src/stories/docs/props.d.ts +14 -0
  17. package/dist/src/stories/examples/content-rerendering/example.d.ts +2 -0
  18. package/dist/src/stories/examples/image-responsive/example.d.ts +2 -0
  19. package/dist/src/stories/examples/keep-scale/example.d.ts +2 -0
  20. package/dist/src/stories/examples/mini-map/example.d.ts +1 -0
  21. package/dist/src/stories/examples/stress/example.d.ts +2 -0
  22. package/dist/src/stories/examples/svg-zoom-to-element/example.d.ts +2 -0
  23. package/dist/src/stories/examples/zoom-to-element/example.d.ts +2 -0
  24. package/dist/src/stories/types/args.types.d.ts +268 -0
  25. package/dist/src/stories/utils/args.utils.d.ts +3 -0
  26. package/dist/src/stories/utils/code.utils.d.ts +6 -0
  27. package/dist/src/stories/utils/controls.utils.d.ts +3 -0
  28. package/dist/src/stories/utils/index.d.ts +3 -0
  29. package/jest.config.ts +45 -0
  30. package/package.json +1 -1
  31. package/src/stories/assets/big-image.jpeg +0 -0
  32. package/src/stories/assets/map.jpg +0 -0
  33. package/src/stories/assets/medium-image.jpg +0 -0
  34. package/src/stories/assets/pin.svg +1 -0
  35. package/src/stories/assets/small-image.jpg +0 -0
  36. package/src/stories/assets/svg-example.svg +14 -0
  37. package/src/stories/docs/Introduction.stories.mdx +174 -0
  38. package/src/stories/docs/handlers.stories.mdx +48 -0
  39. package/src/stories/docs/handlers.tsx +107 -0
  40. package/src/stories/docs/props.stories.mdx +92 -0
  41. package/src/stories/docs/props.tsx +496 -0
  42. package/src/stories/examples/content/content.stories.mdx +121 -0
  43. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +45 -0
  44. package/src/stories/examples/content-rerendering/example.tsx +73 -0
  45. package/src/stories/examples/controls/controls.stories.mdx +71 -0
  46. package/src/stories/examples/image-big/image-big.stories.mdx +43 -0
  47. package/src/stories/examples/image-medium/image-medium.stories.mdx +41 -0
  48. package/src/stories/examples/image-responsive/example.tsx +103 -0
  49. package/src/stories/examples/image-responsive/image-responsive.stories.mdx +32 -0
  50. package/src/stories/examples/image-small/image-small.stories.mdx +41 -0
  51. package/src/stories/examples/image-zoomed-out/image-zoomed-out.stories.mdx +46 -0
  52. package/src/stories/examples/keep-scale/example.tsx +92 -0
  53. package/src/stories/examples/keep-scale/keep-scale.stories.mdx +45 -0
  54. package/src/stories/examples/mini-map/example.tsx +54 -0
  55. package/src/stories/examples/mini-map/mini-map.stories.mdx +33 -0
  56. package/src/stories/examples/stress/example.tsx +23 -0
  57. package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
  58. package/src/stories/examples/svg-zoom-to-element/creativity.svg +143 -0
  59. package/src/stories/examples/svg-zoom-to-element/example.tsx +57 -0
  60. package/src/stories/examples/svg-zoom-to-element/svg-zoom-to-element.stories.mdx +28 -0
  61. package/src/stories/examples/zoom-to-element/example.tsx +94 -0
  62. package/src/stories/examples/zoom-to-element/zoom-to-element.stories.mdx +28 -0
  63. package/src/stories/hooks/use-controls.stories.mdx +24 -0
  64. package/src/stories/hooks/use-transform-context.stories.mdx +15 -0
  65. package/src/stories/hooks/use-transform-effect.stories.mdx +29 -0
  66. package/src/stories/hooks/use-transform-init.stories.mdx +25 -0
  67. package/src/stories/types/args.types.ts +201 -0
  68. package/src/stories/utils/args.utils.ts +34 -0
  69. package/src/stories/utils/code.utils.tsx +24 -0
  70. package/src/stories/utils/controls.utils.tsx +43 -0
  71. package/src/stories/utils/index.ts +3 -0
  72. package/src/stories/utils/styles.module.css +34 -0
@@ -0,0 +1,201 @@
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.velocityDisabled": {
73
+ defaultValue: initialSetup.panning.velocityDisabled,
74
+ control: { type: "boolean" },
75
+ table: {
76
+ defaultValue: { summary: "false" },
77
+ type: { summary: "boolean" },
78
+ },
79
+ },
80
+ "panning.lockAxisX": {
81
+ defaultValue: initialSetup.panning.lockAxisX,
82
+ control: { type: "boolean" },
83
+ table: {
84
+ defaultValue: { summary: "false" },
85
+ type: { summary: "boolean" },
86
+ },
87
+ },
88
+ "panning.lockAxisY": {
89
+ defaultValue: initialSetup.panning.lockAxisY,
90
+ control: { type: "boolean" },
91
+ table: {
92
+ defaultValue: { summary: "false" },
93
+ type: { summary: "boolean" },
94
+ },
95
+ },
96
+ "panning.activationKeys": {
97
+ defaultValue: initialSetup.panning.activationKeys,
98
+ control: { type: "text" },
99
+ table: {
100
+ defaultValue: { summary: "" },
101
+ type: { summary: "string" },
102
+ },
103
+ },
104
+ "panning.excluded": {
105
+ defaultValue: initialSetup.panning.excluded,
106
+ control: { type: "array" },
107
+ table: {
108
+ defaultValue: { summary: "" },
109
+ type: { summary: "array" },
110
+ },
111
+ },
112
+ pinch: {
113
+ table: {
114
+ disable: true,
115
+ },
116
+ },
117
+ "pinch.step": {
118
+ defaultValue: initialSetup.pinch.step,
119
+ control: {
120
+ type: "number",
121
+ min: 0,
122
+ },
123
+ table: {
124
+ defaultValue: { summary: "0" },
125
+ },
126
+ },
127
+ "pinch.disabled": {
128
+ defaultValue: initialSetup.pinch.disabled,
129
+ control: { type: "boolean" },
130
+ table: {
131
+ defaultValue: { summary: "false" },
132
+ type: { summary: "boolean" },
133
+ },
134
+ },
135
+ "pinch.excluded": {
136
+ defaultValue: initialSetup.pinch.excluded,
137
+ control: { type: "array" },
138
+ table: {
139
+ defaultValue: { summary: "" },
140
+ type: { summary: "array" },
141
+ },
142
+ },
143
+ doubleClick: {
144
+ table: {
145
+ disable: true,
146
+ },
147
+ },
148
+ "doubleClick.step": {
149
+ defaultValue: initialSetup.doubleClick.step,
150
+ control: {
151
+ type: "number",
152
+ min: 0,
153
+ },
154
+ table: {
155
+ defaultValue: { summary: "0" },
156
+ },
157
+ },
158
+ "doubleClick.disabled": {
159
+ defaultValue: initialSetup.doubleClick.disabled,
160
+ control: { type: "boolean" },
161
+ table: {
162
+ defaultValue: { summary: "false" },
163
+ type: { summary: "boolean" },
164
+ },
165
+ },
166
+ "doubleClick.excluded": {
167
+ defaultValue: initialSetup.doubleClick.excluded,
168
+ control: { type: "array" },
169
+ table: {
170
+ defaultValue: { summary: "" },
171
+ type: { summary: "array" },
172
+ },
173
+ },
174
+ };
175
+ // doubleClick: {
176
+ // disabled: false,
177
+ // step: 20,
178
+ // mode: "zoomIn",
179
+ // animation: true,
180
+ // animationType: "easeOut",
181
+ // animationTime: 200,
182
+ // },
183
+ // zoomAnimation: {
184
+ // disabled: false,
185
+ // size: 0.4,
186
+ // animationTime: 200,
187
+ // animationType: "easeOut",
188
+ // },
189
+ // alignmentAnimation: {
190
+ // disabled: false,
191
+ // size: 30,
192
+ // animationTime: 200,
193
+ // animationType: "easeOut",
194
+ // },
195
+ // velocityAnimation: {
196
+ // disabled: false,
197
+ // sensitivity: 1,
198
+ // animationTime: 600,
199
+ // animationType: "easeOut",
200
+ // equalToMove: true,
201
+ // },
@@ -0,0 +1,34 @@
1
+ export const normalizeArgs = (args: { [key: string]: any }): any => {
2
+ const newArgs = {};
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
+ onTransformed: undefined,
21
+ onWheelStart: undefined,
22
+ onWheel: undefined,
23
+ onWheelStop: undefined,
24
+ onZoomStart: undefined,
25
+ onZoom: undefined,
26
+ onZoomStop: undefined,
27
+ onPanningStart: undefined,
28
+ onPanning: undefined,
29
+ onPanningStop: undefined,
30
+ onPinchStart: undefined,
31
+ onPinch: undefined,
32
+ onPinchStop: undefined,
33
+ };
34
+ };
@@ -0,0 +1,24 @@
1
+ /* eslint-disable react/no-array-index-key */
2
+ import React from "react";
3
+ import Highlight, { defaultProps } from "prism-react-renderer";
4
+ import vsLight from "prism-react-renderer/themes/vsLight";
5
+
6
+ type Props = { code: string };
7
+
8
+ export const Code: React.FC<Props> = ({ code }: Props) => (
9
+ // eslint-disable-next-line @typescript-eslint/ban-ts-comment
10
+ // @ts-ignore
11
+ <Highlight {...defaultProps} code={code} theme={vsLight} language="tsx">
12
+ {({ className, style, tokens, getLineProps, getTokenProps }) => (
13
+ <pre className={className} style={style}>
14
+ {tokens.map((line, i) => (
15
+ <div key={i} {...getLineProps({ line, key: i })}>
16
+ {line.map((token, key) => (
17
+ <span key={key} {...getTokenProps({ token, key })} />
18
+ ))}
19
+ </div>
20
+ ))}
21
+ </pre>
22
+ )}
23
+ </Highlight>
24
+ );
@@ -0,0 +1,43 @@
1
+ import React from "react";
2
+
3
+ import { ReactZoomPanPinchContentRef } from "../../models/context.model";
4
+
5
+ import styles from "./styles.module.css";
6
+
7
+ export const Controls: React.FC<ReactZoomPanPinchContentRef> = ({
8
+ zoomIn,
9
+ zoomOut,
10
+ resetTransform,
11
+ centerView,
12
+ }: ReactZoomPanPinchContentRef) => (
13
+ <div className={styles.controlPanel}>
14
+ <button
15
+ type="button"
16
+ className={styles.controlBtn}
17
+ onClick={() => zoomIn()}
18
+ >
19
+ Zoom In +
20
+ </button>
21
+ <button
22
+ type="button"
23
+ className={styles.controlBtn}
24
+ onClick={() => zoomOut()}
25
+ >
26
+ Zoom Out -
27
+ </button>
28
+ <button
29
+ type="button"
30
+ className={styles.controlBtn}
31
+ onClick={() => resetTransform()}
32
+ >
33
+ Reset
34
+ </button>
35
+ <button
36
+ type="button"
37
+ className={styles.controlBtn}
38
+ onClick={() => centerView()}
39
+ >
40
+ Center
41
+ </button>
42
+ </div>
43
+ );
@@ -0,0 +1,3 @@
1
+ export * from "./args.utils";
2
+ export * from "./code.utils";
3
+ export * from "./controls.utils";
@@ -0,0 +1,34 @@
1
+ .controlPanel {
2
+ position: absolute;
3
+ z-index: 2;
4
+ transform: translate(10px, 10px);
5
+ max-width: calc(100% - 20px);
6
+ }
7
+ .controlBtn {
8
+ padding: 6px 12px;
9
+ background: white;
10
+ border: 1px solid grey;
11
+ border-radius: 5px;
12
+ margin-right: 10px;
13
+ font-size: 12px;
14
+ text-transform: uppercase;
15
+ font-weight: 600;
16
+ cursor: pointer;
17
+ }
18
+
19
+ .controlBtn:focus {
20
+ filter: brightness(90%);
21
+ }
22
+
23
+ .controlBtn:hover {
24
+ filter: brightness(120%);
25
+ }
26
+
27
+ .controlBtn:active {
28
+ opacity: 0.9;
29
+ }
30
+
31
+ .grid {
32
+ display: grid;
33
+ grid-template-columns: repeat(100, 1fr);
34
+ }