react-zoom-pan-pinch 2.2.1 → 2.3.0

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 (81) hide show
  1. package/dist/components/transform-component.d.ts +10 -0
  2. package/dist/components/transform-wrapper.d.ts +8 -0
  3. package/dist/constants/state.constants.d.ts +6 -0
  4. package/dist/core/animations/animations.constants.d.ts +16 -0
  5. package/dist/core/animations/animations.utils.d.ts +4 -0
  6. package/dist/core/bounds/bounds.types.d.ts +8 -0
  7. package/dist/core/bounds/bounds.utils.d.ts +15 -0
  8. package/dist/core/double-click/double-click.logic.d.ts +3 -0
  9. package/dist/core/handlers/handlers.logic.d.ts +8 -0
  10. package/dist/core/handlers/handlers.utils.d.ts +13 -0
  11. package/dist/core/instance.core.d.ts +68 -0
  12. package/dist/core/pan/panning.logic.d.ts +5 -0
  13. package/dist/core/pan/panning.utils.d.ts +10 -0
  14. package/dist/core/pan/velocity.logic.d.ts +5 -0
  15. package/dist/core/pan/velocity.utils.d.ts +5 -0
  16. package/dist/core/pinch/pinch.logic.d.ts +4 -0
  17. package/dist/core/pinch/pinch.utils.d.ts +6 -0
  18. package/dist/core/wheel/wheel.logic.d.ts +4 -0
  19. package/dist/core/wheel/wheel.utils.d.ts +7 -0
  20. package/dist/core/zoom/zoom.logic.d.ts +3 -0
  21. package/dist/core/zoom/zoom.utils.d.ts +3 -0
  22. package/dist/hooks/use-transform-context.d.ts +3 -0
  23. package/dist/index.cjs.js +270 -267
  24. package/dist/index.cjs.js.map +1 -1
  25. package/dist/index.d.ts +63 -57
  26. package/dist/index.esm.js +270 -267
  27. package/dist/index.esm.js.map +1 -1
  28. package/dist/models/calculations.model.d.ts +25 -0
  29. package/dist/models/context.model.d.ts +117 -0
  30. package/dist/models/helpers.model.d.ts +5 -0
  31. package/dist/models/index.d.ts +3 -0
  32. package/dist/stories/docs/handlers.d.ts +12 -0
  33. package/dist/stories/docs/props.d.ts +14 -0
  34. package/dist/stories/examples/content-rerendering/example.d.ts +2 -0
  35. package/dist/stories/examples/stress/example.d.ts +2 -0
  36. package/dist/stories/examples/zoom-to-element/example.d.ts +2 -0
  37. package/dist/stories/types/args.types.d.ts +268 -0
  38. package/dist/stories/utils/args.utils.d.ts +3 -0
  39. package/dist/stories/utils/code.utils.d.ts +6 -0
  40. package/dist/stories/utils/controls.utils.d.ts +3 -0
  41. package/dist/stories/utils/index.d.ts +3 -0
  42. package/dist/utils/calculations.utils.d.ts +11 -0
  43. package/dist/utils/callback.utils.d.ts +2 -0
  44. package/dist/utils/context.utils.d.ts +2 -0
  45. package/dist/utils/event.utils.d.ts +1 -0
  46. package/dist/utils/helpers.utils.d.ts +2 -0
  47. package/dist/utils/index.d.ts +7 -0
  48. package/dist/utils/state.utils.d.ts +3 -0
  49. package/dist/utils/styles.utils.d.ts +3 -0
  50. package/package.json +30 -25
  51. package/src/.eslintrc.json +90 -0
  52. package/src/components/transform-component.tsx +2 -1
  53. package/src/components/transform-wrapper.tsx +27 -5
  54. package/src/constants/state.constants.ts +0 -2
  55. package/src/core/animations/animations.constants.ts +14 -12
  56. package/src/core/animations/animations.utils.ts +15 -11
  57. package/src/core/bounds/bounds.utils.ts +20 -20
  58. package/src/core/double-click/double-click.logic.ts +6 -12
  59. package/src/core/handlers/handlers.logic.ts +98 -89
  60. package/src/core/handlers/handlers.utils.ts +22 -24
  61. package/src/{components/transform-context.tsx → core/instance.core.ts} +85 -118
  62. package/src/core/pan/panning.logic.ts +20 -19
  63. package/src/core/pan/panning.utils.ts +4 -7
  64. package/src/core/pan/velocity.logic.ts +1 -0
  65. package/src/core/pinch/pinch.logic.ts +4 -6
  66. package/src/core/pinch/pinch.utils.ts +2 -2
  67. package/src/core/wheel/wheel.logic.ts +1 -0
  68. package/src/core/wheel/wheel.utils.ts +12 -11
  69. package/src/core/zoom/zoom.logic.ts +29 -29
  70. package/src/core/zoom/zoom.utils.ts +2 -2
  71. package/src/hooks/use-transform-context.tsx +3 -2
  72. package/src/models/context.model.ts +6 -2
  73. package/src/stories/docs/handlers.tsx +30 -30
  74. package/src/stories/examples/content-rerendering/content-updating.stories.mdx +3 -0
  75. package/src/stories/examples/stress/example.tsx +24 -0
  76. package/src/stories/examples/stress/stress-test.stories.mdx +28 -0
  77. package/src/stories/examples/zoom-to-element/example.tsx +4 -0
  78. package/src/stories/utils/code.utils.tsx +1 -0
  79. package/src/stories/utils/controls.utils.tsx +21 -4
  80. package/src/stories/utils/styles.module.css +5 -0
  81. package/src/.eslintrc.js +0 -36
@@ -16,36 +16,6 @@ export type ComponentProps = Record<
16
16
  | Record<string, Omit<ControlsFnOptionsType, "name" | "isObjectRow">>
17
17
  >;
18
18
 
19
- export const getHandlersTable = (): ControlsFnOptionsType[] => {
20
- return Object.keys(handlersTable).reduce<ControlsFnOptionsType[]>(
21
- (acc, key) => {
22
- if (Array.isArray(handlersTable[key]?.type)) {
23
- acc.push({
24
- ...handlersTable[key],
25
- name: key,
26
- });
27
- } else {
28
- Object.keys(handlersTable[key]).forEach((prop) => {
29
- acc.push({
30
- ...handlersTable[key][prop],
31
- isObjectRow: key === prop,
32
- name:
33
- key === prop ? (
34
- <b>{prop}</b>
35
- ) : (
36
- <>
37
- {key}.<b>{prop}</b>
38
- </>
39
- ),
40
- });
41
- });
42
- }
43
- return acc;
44
- },
45
- [],
46
- );
47
- };
48
-
49
19
  export const handlersTable: ComponentProps = {
50
20
  zoomIn: {
51
21
  type: ["function(step, animationTime, animationName)"],
@@ -105,3 +75,33 @@ export const handlersTable: ComponentProps = {
105
75
  "This function make a transition for certain node provided to the function(as node element or it's id string). It allows only to zoom elements with offsetWidth and offsetHeight properties - since SVG's doesn't have those, it is impossible to perform it on such elements.",
106
76
  },
107
77
  };
78
+
79
+ export const getHandlersTable = (): ControlsFnOptionsType[] => {
80
+ return Object.keys(handlersTable).reduce<ControlsFnOptionsType[]>(
81
+ (acc, key) => {
82
+ if (Array.isArray(handlersTable[key]?.type)) {
83
+ acc.push({
84
+ ...handlersTable[key],
85
+ name: key,
86
+ });
87
+ } else {
88
+ Object.keys(handlersTable[key]).forEach((prop) => {
89
+ acc.push({
90
+ ...handlersTable[key][prop],
91
+ isObjectRow: key === prop,
92
+ name:
93
+ key === prop ? (
94
+ <b>{prop}</b>
95
+ ) : (
96
+ <>
97
+ {key}.<b>{prop}</b>
98
+ </>
99
+ ),
100
+ });
101
+ });
102
+ }
103
+ return acc;
104
+ },
105
+ [],
106
+ );
107
+ };
@@ -24,6 +24,9 @@ export const Template = (args) => <Example {...args} />;
24
24
  ...argsTypes["pinch.excluded"],
25
25
  defaultValue: ["pinchDisabled"],
26
26
  },
27
+ centerOnInit: {
28
+ defaultValue: true,
29
+ },
27
30
  }}
28
31
  />
29
32
 
@@ -0,0 +1,24 @@
1
+ import React, { useRef } from "react";
2
+
3
+ import { TransformWrapper } from "../../../components/transform-wrapper";
4
+ import { TransformComponent } from "../../../components/transform-component";
5
+ import { normalizeArgs } from "../../utils";
6
+ import exampleImg from "../../assets/small-image.jpg";
7
+
8
+ import styles from "../../utils/styles.module.css";
9
+
10
+ export const Example: React.FC<any> = (args: any) => {
11
+ const ref = useRef<any>(null);
12
+
13
+ return (
14
+ <TransformWrapper {...normalizeArgs(args)} ref={ref}>
15
+ <TransformComponent>
16
+ <div className={styles.grid}>
17
+ {Array.from(Array(1000).keys()).map((key) => (
18
+ <img key={key} src={exampleImg} alt="" />
19
+ ))}
20
+ </div>
21
+ </TransformComponent>
22
+ </TransformWrapper>
23
+ );
24
+ };
@@ -0,0 +1,28 @@
1
+ import { Meta, Story, ArgsTable, Canvas } from "@storybook/addon-docs/blocks";
2
+ import { action } from "@storybook/addon-actions";
3
+
4
+ import { TransformWrapper } from "../../../components/transform-wrapper";
5
+ import { argsTypes } from "../../types/args.types";
6
+ import { Example } from "./example";
7
+
8
+ export const Template = (args) => <Example {...args} />;
9
+
10
+ <Meta
11
+ title="Examples/Stress test"
12
+ component={TransformWrapper}
13
+ argTypes={argsTypes}
14
+ />
15
+
16
+ # Stress test
17
+
18
+ <br />
19
+
20
+ ### Preview:
21
+
22
+ <Canvas>
23
+ <Story name="Stress test">{(args) => <Template {...args} />}</Story>
24
+ </Canvas>
25
+
26
+ ## Component API
27
+
28
+ <ArgsTable story="Stress test" />
@@ -13,24 +13,28 @@ export const Example: React.FC<any> = (args: any) => {
13
13
  <>
14
14
  <div>
15
15
  <button
16
+ type="button"
16
17
  className={styles.controlBtn}
17
18
  onClick={() => zoomToElement("element1")}
18
19
  >
19
20
  Zoom to element 1
20
21
  </button>
21
22
  <button
23
+ type="button"
22
24
  className={styles.controlBtn}
23
25
  onClick={() => zoomToElement("element2")}
24
26
  >
25
27
  Zoom to element 2
26
28
  </button>
27
29
  <button
30
+ type="button"
28
31
  className={styles.controlBtn}
29
32
  onClick={() => zoomToElement("element3")}
30
33
  >
31
34
  Zoom to element 3
32
35
  </button>
33
36
  <button
37
+ type="button"
34
38
  className={styles.controlBtn}
35
39
  onClick={() => resetTransform()}
36
40
  >
@@ -1,3 +1,4 @@
1
+ /* eslint-disable react/no-array-index-key */
1
2
  import React from "react";
2
3
  import Highlight, { defaultProps } from "prism-react-renderer";
3
4
  import vsLight from "prism-react-renderer/themes/vsLight";
@@ -1,4 +1,5 @@
1
1
  import React from "react";
2
+
2
3
  import { ReactZoomPanPinchRef } from "../../models/context.model";
3
4
 
4
5
  import styles from "./styles.module.css";
@@ -10,16 +11,32 @@ export const Controls: React.FC<ReactZoomPanPinchRef> = ({
10
11
  centerView,
11
12
  }: ReactZoomPanPinchRef) => (
12
13
  <div className={styles.controlPanel}>
13
- <button className={styles.controlBtn} onClick={() => zoomIn()}>
14
+ <button
15
+ type="button"
16
+ className={styles.controlBtn}
17
+ onClick={() => zoomIn()}
18
+ >
14
19
  Zoom In +
15
20
  </button>
16
- <button className={styles.controlBtn} onClick={() => zoomOut()}>
21
+ <button
22
+ type="button"
23
+ className={styles.controlBtn}
24
+ onClick={() => zoomOut()}
25
+ >
17
26
  Zoom Out -
18
27
  </button>
19
- <button className={styles.controlBtn} onClick={() => resetTransform()}>
28
+ <button
29
+ type="button"
30
+ className={styles.controlBtn}
31
+ onClick={() => resetTransform()}
32
+ >
20
33
  Reset
21
34
  </button>
22
- <button className={styles.controlBtn} onClick={() => centerView()}>
35
+ <button
36
+ type="button"
37
+ className={styles.controlBtn}
38
+ onClick={() => centerView()}
39
+ >
23
40
  Center
24
41
  </button>
25
42
  </div>
@@ -27,3 +27,8 @@
27
27
  .controlBtn:active {
28
28
  opacity: 0.9;
29
29
  }
30
+
31
+ .grid {
32
+ display: grid;
33
+ grid-template-columns: repeat(100, 1fr);
34
+ }
package/src/.eslintrc.js DELETED
@@ -1,36 +0,0 @@
1
- module.exports = {
2
- root: true,
3
- parser: "@typescript-eslint/parser",
4
- plugins: ["react", "react-hooks", "prettier", "@typescript-eslint"],
5
- extends: [
6
- "plugin:react/recommended",
7
- "plugin:@typescript-eslint/recommended",
8
- ],
9
- parserOptions: {
10
- sourceType: "module",
11
- ecmaFeatures: {
12
- jsx: true,
13
- },
14
- },
15
- rules: {
16
- "react/jsx-uses-react": "error",
17
- "react/jsx-uses-vars": "error",
18
- "no-console": ["error", { allow: ["warn", "error"] }],
19
- "no-unused-vars": "off",
20
- "@typescript-eslint/no-unused-vars": "off",
21
- "@typescript-eslint/no-unused-vars-experimental": "error",
22
- "react/no-unescaped-entities": 0,
23
- "react/display-name": 0,
24
- "react/jsx-filename-extension": [
25
- 2,
26
- { extensions: [".js", ".jsx", ".ts", ".tsx"] },
27
- ],
28
- },
29
- settings: {
30
- "import/resolver": {
31
- node: {
32
- moduleDirectory: ["node_modules", "src/"],
33
- },
34
- },
35
- },
36
- };