@solostylist/image-editor 1.0.8 → 1.0.10

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 (270) hide show
  1. package/lib/actions/add-filter.js +11 -1
  2. package/lib/actions/change-pointer-icon.js +10 -1
  3. package/lib/actions/change-rotation.js +13 -1
  4. package/lib/actions/clear-annotations-selections.js +10 -1
  5. package/lib/actions/duplicate-annotations.js +26 -1
  6. package/lib/actions/enable-text-content-edit.js +10 -1
  7. package/lib/actions/hide-loader.js +10 -1
  8. package/lib/actions/index.js +36 -1
  9. package/lib/actions/redo.js +27 -1
  10. package/lib/actions/remove-annotations.js +27 -1
  11. package/lib/actions/reset.js +26 -1
  12. package/lib/actions/select-annotation.js +27 -1
  13. package/lib/actions/select-tab.js +16 -1
  14. package/lib/actions/select-tool.js +11 -1
  15. package/lib/actions/set-annotation.js +28 -1
  16. package/lib/actions/set-canvas-size.js +31 -1
  17. package/lib/actions/set-crop.js +25 -1
  18. package/lib/actions/set-feedback.js +11 -1
  19. package/lib/actions/set-finetune.js +13 -1
  20. package/lib/actions/set-latest-color.js +10 -1
  21. package/lib/actions/set-original-image.js +13 -1
  22. package/lib/actions/set-resize.js +14 -1
  23. package/lib/actions/set-saved.js +10 -1
  24. package/lib/actions/set-saving.js +11 -1
  25. package/lib/actions/set-show-tabs-menu.js +10 -1
  26. package/lib/actions/set-shown-image-dimensions.js +12 -1
  27. package/lib/actions/show-loader.js +10 -1
  28. package/lib/actions/toggle-flip.js +13 -1
  29. package/lib/actions/toggle-original-image-display.js +10 -1
  30. package/lib/actions/undo.js +27 -1
  31. package/lib/actions/update-state.js +7 -1
  32. package/lib/actions/zoom-canvas.js +37 -1
  33. package/lib/components/app/index.js +283 -1
  34. package/lib/components/assembly-point/index.js +23 -1
  35. package/lib/components/common/annotation-options/annotation-options.constants.js +10 -1
  36. package/lib/components/common/annotation-options/index.js +140 -1
  37. package/lib/components/common/annotation-options/opacity-field.js +23 -1
  38. package/lib/components/common/annotation-options/position-fields.js +39 -1
  39. package/lib/components/common/annotation-options/shadow-fields.js +62 -1
  40. package/lib/components/common/annotation-options/stroke-fields.js +33 -1
  41. package/lib/components/common/button-with-menu/index.js +86 -1
  42. package/lib/components/common/color-input/index.js +101 -1
  43. package/lib/components/common/color-picker-modal/index.js +70 -1
  44. package/lib/components/common/hidden-upload-input/index.js +17 -1
  45. package/lib/components/common/icon-wrapper/index.js +40 -1
  46. package/lib/components/common/image-preview-tile/index.js +57 -1
  47. package/lib/components/common/slider/index.js +38 -1
  48. package/lib/components/feedback-popup/index.js +41 -1
  49. package/lib/components/layers/design-layer/annotation-nodes/annotation-nodes.constants.js +10 -1
  50. package/lib/components/layers/design-layer/annotation-nodes/arrow-node.js +62 -1
  51. package/lib/components/layers/design-layer/annotation-nodes/ellipse-node.js +64 -1
  52. package/lib/components/layers/design-layer/annotation-nodes/image-node.js +78 -1
  53. package/lib/components/layers/design-layer/annotation-nodes/index.js +22 -1
  54. package/lib/components/layers/design-layer/annotation-nodes/line-node.js +60 -1
  55. package/lib/components/layers/design-layer/annotation-nodes/memoized-annotation.js +16 -1
  56. package/lib/components/layers/design-layer/annotation-nodes/polygon-node.js +63 -1
  57. package/lib/components/layers/design-layer/annotation-nodes/rect-node.js +65 -1
  58. package/lib/components/layers/design-layer/annotation-nodes/text-node.js +80 -1
  59. package/lib/components/layers/design-layer/index.js +202 -1
  60. package/lib/components/layers/design-layer/nodes-common-prop-types.js +16 -1
  61. package/lib/components/layers/design-layer/preview-group.js +9 -1
  62. package/lib/components/layers/index.js +2 -1
  63. package/lib/components/layers/transformers-layer/crop-transformer.js +248 -1
  64. package/lib/components/layers/transformers-layer/index.js +16 -1
  65. package/lib/components/layers/transformers-layer/nodes-transformer.js +73 -1
  66. package/lib/components/layers/transformers-layer/transformers-layer.utils.js +93 -1
  67. package/lib/components/main-canvas/canvas-node.js +177 -1
  68. package/lib/components/main-canvas/index.js +51 -1
  69. package/lib/components/main-canvas/touch-zooming-events.js +69 -1
  70. package/lib/components/node-controls/index.js +79 -1
  71. package/lib/components/tabs/index.js +66 -1
  72. package/lib/components/tabs/tabs.constants.js +27 -1
  73. package/lib/components/tabs-drawer/index.js +109 -1
  74. package/lib/components/tools/arrow/arrow-button.js +17 -1
  75. package/lib/components/tools/arrow/arrow-options.js +19 -1
  76. package/lib/components/tools/arrow/index.js +2 -1
  77. package/lib/components/tools/blur/blur-options.js +35 -1
  78. package/lib/components/tools/blur/blur.js +17 -1
  79. package/lib/components/tools/blur/index.js +2 -1
  80. package/lib/components/tools/brightness/brightness-options.js +36 -1
  81. package/lib/components/tools/brightness/brightness.js +17 -1
  82. package/lib/components/tools/brightness/index.js +2 -1
  83. package/lib/components/tools/contrast/contrast-options.js +35 -1
  84. package/lib/components/tools/contrast/contrast.js +17 -1
  85. package/lib/components/tools/contrast/index.js +2 -1
  86. package/lib/components/tools/crop/crop.constants.js +31 -1
  87. package/lib/components/tools/crop/crop.js +122 -1
  88. package/lib/components/tools/crop/index.js +1 -1
  89. package/lib/components/tools/ellipse/ellipse-button.js +17 -1
  90. package/lib/components/tools/ellipse/ellipse-options.js +17 -1
  91. package/lib/components/tools/ellipse/index.js +2 -1
  92. package/lib/components/tools/filters/filter-item.js +77 -1
  93. package/lib/components/tools/filters/filters.constants.js +139 -1
  94. package/lib/components/tools/filters/filters.js +74 -1
  95. package/lib/components/tools/filters/index.js +1 -1
  96. package/lib/components/tools/flip/flip-x.js +48 -1
  97. package/lib/components/tools/flip/flip-y.js +50 -1
  98. package/lib/components/tools/flip/index.js +2 -1
  99. package/lib/components/tools/hsv/hsv.js +17 -1
  100. package/lib/components/tools/hsv/hsvoptions.js +60 -1
  101. package/lib/components/tools/hsv/index.js +2 -1
  102. package/lib/components/tools/image/image-button.js +17 -1
  103. package/lib/components/tools/image/image-controls.js +12 -1
  104. package/lib/components/tools/image/image-options.js +162 -1
  105. package/lib/components/tools/image/images-gallery.js +55 -1
  106. package/lib/components/tools/image/index.js +2 -1
  107. package/lib/components/tools/line/index.js +2 -1
  108. package/lib/components/tools/line/line-button.js +17 -1
  109. package/lib/components/tools/line/line-options.js +19 -1
  110. package/lib/components/tools/pen/index.js +2 -1
  111. package/lib/components/tools/pen/pen-button.js +17 -1
  112. package/lib/components/tools/pen/pen-options.js +120 -1
  113. package/lib/components/tools/polygon/index.js +2 -1
  114. package/lib/components/tools/polygon/polygon-button.js +17 -1
  115. package/lib/components/tools/polygon/polygon-options.js +22 -1
  116. package/lib/components/tools/polygon/polygon-sides-field.js +23 -1
  117. package/lib/components/tools/polygon/polygon.constants.js +10 -1
  118. package/lib/components/tools/rect/index.js +2 -1
  119. package/lib/components/tools/rect/rect-button.js +17 -1
  120. package/lib/components/tools/rect/rect-corner-field.js +24 -1
  121. package/lib/components/tools/rect/rect-options.js +21 -1
  122. package/lib/components/tools/rect/rect.constants.js +10 -1
  123. package/lib/components/tools/resize/index.js +1 -1
  124. package/lib/components/tools/resize/resize.js +141 -1
  125. package/lib/components/tools/rotate/index.js +2 -1
  126. package/lib/components/tools/rotate/rotate-button.js +17 -1
  127. package/lib/components/tools/rotate/rotate-options.js +97 -1
  128. package/lib/components/tools/text/index.js +2 -1
  129. package/lib/components/tools/text/text-button.js +17 -1
  130. package/lib/components/tools/text/text-options/handle-text-change-area.js +122 -1
  131. package/lib/components/tools/text/text-options/index.js +17 -1
  132. package/lib/components/tools/text/text-options/text-alignment-fields.js +38 -1
  133. package/lib/components/tools/text/text-options/text-controls.js +147 -1
  134. package/lib/components/tools/text/text-options/text-options.constants.js +16 -1
  135. package/lib/components/tools/text/text-options/text-spacings-fields.js +34 -1
  136. package/lib/components/tools/tools.constants.js +98 -1
  137. package/lib/components/tools/warmth/index.js +2 -1
  138. package/lib/components/tools/warmth/warmth-options.js +35 -1
  139. package/lib/components/tools/warmth/warmth.js +17 -1
  140. package/lib/components/tools/watermark/index.js +1 -1
  141. package/lib/components/tools/watermark/watermark-padding.js +59 -1
  142. package/lib/components/tools/watermark/watermark.js +221 -1
  143. package/lib/components/tools/watermark/watermarks-gallery.js +77 -1
  144. package/lib/components/tools-bar/index.js +113 -1
  145. package/lib/components/tools-bar/tools-bar-item-button.js +39 -1
  146. package/lib/components/topbar/canvas-zooming.js +119 -1
  147. package/lib/components/topbar/confirmation-modal.js +53 -1
  148. package/lib/components/topbar/image-dimensions-and-display-toggle.js +68 -1
  149. package/lib/components/topbar/index.js +47 -1
  150. package/lib/components/topbar/redo-button.js +25 -1
  151. package/lib/components/topbar/reset-button.js +21 -1
  152. package/lib/components/topbar/save-button.js +251 -1
  153. package/lib/components/topbar/topbar.constants.js +31 -1
  154. package/lib/components/topbar/undo-button.js +27 -1
  155. package/lib/context/app-context.js +3 -1
  156. package/lib/context/app-provider-overriden-value.js +9 -1
  157. package/lib/context/app-provider.js +48 -1
  158. package/lib/context/app-reducer.js +5 -1
  159. package/lib/context/default-config.js +75 -1
  160. package/lib/context/default-translations.js +115 -1
  161. package/lib/context/get-initial-app-state.js +61 -1
  162. package/lib/context/index.js +4 -1
  163. package/lib/custom/filters/aden.js +8 -1
  164. package/lib/custom/filters/amaro.js +8 -1
  165. package/lib/custom/filters/ashby.js +8 -1
  166. package/lib/custom/filters/base-filters.js +82 -1
  167. package/lib/custom/filters/black-and-white.js +11 -1
  168. package/lib/custom/filters/brannan.js +8 -1
  169. package/lib/custom/filters/brooklyn.js +8 -1
  170. package/lib/custom/filters/charmes.js +8 -1
  171. package/lib/custom/filters/clarendon.js +9 -1
  172. package/lib/custom/filters/crema.js +8 -1
  173. package/lib/custom/filters/dogpatch.js +8 -1
  174. package/lib/custom/filters/earlybird.js +7 -1
  175. package/lib/custom/filters/gingham.js +8 -1
  176. package/lib/custom/filters/ginza.js +8 -1
  177. package/lib/custom/filters/hefe.js +8 -1
  178. package/lib/custom/filters/helena.js +8 -1
  179. package/lib/custom/filters/hudson.js +9 -1
  180. package/lib/custom/filters/index.js +40 -1
  181. package/lib/custom/filters/juno.js +8 -1
  182. package/lib/custom/filters/kelvin.js +9 -1
  183. package/lib/custom/filters/lark.js +9 -1
  184. package/lib/custom/filters/lo-fi.js +8 -1
  185. package/lib/custom/filters/ludwig.js +8 -1
  186. package/lib/custom/filters/maven.js +9 -1
  187. package/lib/custom/filters/mayfair.js +8 -1
  188. package/lib/custom/filters/moon.js +7 -1
  189. package/lib/custom/filters/nashville.js +8 -1
  190. package/lib/custom/filters/ninteen-seventy-seven.js +8 -1
  191. package/lib/custom/filters/perpetua.js +7 -1
  192. package/lib/custom/filters/reyes.js +9 -1
  193. package/lib/custom/filters/rise.js +9 -1
  194. package/lib/custom/filters/sierra.js +8 -1
  195. package/lib/custom/filters/skyline.js +8 -1
  196. package/lib/custom/filters/slumber.js +8 -1
  197. package/lib/custom/filters/stinson.js +8 -1
  198. package/lib/custom/filters/sutro.js +8 -1
  199. package/lib/custom/filters/toaster.js +8 -1
  200. package/lib/custom/filters/valencia.js +9 -1
  201. package/lib/custom/filters/vesper.js +9 -1
  202. package/lib/custom/filters/walden.js +8 -1
  203. package/lib/custom/filters/willow.js +8 -1
  204. package/lib/custom/filters/xpro2.js +9 -1
  205. package/lib/custom/finetunes/custom-threshold.js +19 -1
  206. package/lib/custom/finetunes/index.js +2 -1
  207. package/lib/custom/finetunes/warmth.js +15 -1
  208. package/lib/demo/app.js +175 -1
  209. package/lib/demo/index.js +1 -1
  210. package/lib/hooks/index.js +12 -1
  211. package/lib/hooks/use-annotation/get-bounding-rect-un-scaled.js +14 -1
  212. package/lib/hooks/use-annotation/get-new-annotation-preview.js +83 -1
  213. package/lib/hooks/use-annotation/index.js +138 -1
  214. package/lib/hooks/use-annotation/preview-then-call-annotation-adding.js +159 -1
  215. package/lib/hooks/use-annotation-events.js +83 -1
  216. package/lib/hooks/use-app-reducer.js +53 -1
  217. package/lib/hooks/use-debounced-callback.js +7 -1
  218. package/lib/hooks/use-drag.js +37 -1
  219. package/lib/hooks/use-filter.js +20 -1
  220. package/lib/hooks/use-finetune.js +31 -1
  221. package/lib/hooks/use-phone-screen.js +5 -1
  222. package/lib/hooks/use-popover.js +27 -1
  223. package/lib/hooks/use-resize-observer.js +60 -1
  224. package/lib/hooks/use-store.js +6 -1
  225. package/lib/hooks/use-transformed-img-data.js +156 -1
  226. package/lib/hooks/use-update-effect.js +18 -1
  227. package/lib/index.d.ts +2 -2
  228. package/lib/index.d.ts.map +1 -1
  229. package/lib/index.js +4 -1
  230. package/lib/types/actions.js +31 -1
  231. package/lib/types/annotations.js +42 -1
  232. package/lib/types/common.js +1 -1
  233. package/lib/types/config.js +34 -1
  234. package/lib/types/index.js +5 -1
  235. package/lib/types/state.js +1 -1
  236. package/lib/utils/assign-finetune-names-to-konva.js +7 -1
  237. package/lib/utils/calculate-zoom-data.js +36 -1
  238. package/lib/utils/compare-ratios.js +5 -1
  239. package/lib/utils/constants.js +84 -1
  240. package/lib/utils/crop-image.js +10 -1
  241. package/lib/utils/debounce.js +19 -1
  242. package/lib/utils/deep-merge.js +26 -1
  243. package/lib/utils/extract-current-design-state.js +15 -1
  244. package/lib/utils/extract-name-from-url.js +5 -1
  245. package/lib/utils/filter-str-to-class.js +9 -1
  246. package/lib/utils/finetunes-strs-to-classes.js +13 -1
  247. package/lib/utils/get-center-rotated-point.js +34 -1
  248. package/lib/utils/get-default-save-quality.js +5 -1
  249. package/lib/utils/get-dimensions-minimal-ratio.js +6 -1
  250. package/lib/utils/get-elem-document-coords.js +24 -1
  251. package/lib/utils/get-file-full-name.js +21 -1
  252. package/lib/utils/get-pointer-offset-position-bounded-to-object.js +26 -1
  253. package/lib/utils/get-proper-dimensions.js +21 -1
  254. package/lib/utils/get-proper-image-to-canvas-spacing.js +6 -1
  255. package/lib/utils/get-scroll-offset.js +13 -1
  256. package/lib/utils/get-size-after-rotation.js +31 -1
  257. package/lib/utils/get-zoom-fit-factor.js +5 -1
  258. package/lib/utils/image-to-base64.js +12 -1
  259. package/lib/utils/is-default-zero-values-only.js +6 -1
  260. package/lib/utils/is-same-image.js +4 -1
  261. package/lib/utils/load-image.js +19 -1
  262. package/lib/utils/map-crop-box.js +16 -1
  263. package/lib/utils/map-number.js +4 -1
  264. package/lib/utils/map-position-string-to-point.js +92 -1
  265. package/lib/utils/random-id.js +5 -1
  266. package/lib/utils/restrict-number.js +7 -1
  267. package/lib/utils/serialize-design-state.js +62 -1
  268. package/lib/utils/to-precised-float.js +5 -1
  269. package/lib/utils/translator.js +14 -1
  270. package/package.json +1 -1
@@ -1 +1,83 @@
1
- import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";import _defineProperty from"@babel/runtime/helpers/defineProperty";var _excluded=["width","height","startedX","startedY"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import Konva from"konva";import{TOOLS_IDS}from"utils/constants";var annotationsNamesToKonvaClasses=_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({},TOOLS_IDS.RECT,Konva.Rect),TOOLS_IDS.ELLIPSE,Konva.Ellipse),TOOLS_IDS.POLYGON,Konva.RegularPolygon),TOOLS_IDS.LINE,Konva.Line),TOOLS_IDS.IMAGE,Konva.Image),TOOLS_IDS.TEXT,Konva.Text),TOOLS_IDS.ARROW,Konva.Arrow),ANNOTATIONS_WITH_POINTS=[TOOLS_IDS.LINE,TOOLS_IDS.ARROW];export var NO_WIDTH_HEIGHT_ANNOTATIONS=[].concat(ANNOTATIONS_WITH_POINTS,[TOOLS_IDS.ELLIPSE,TOOLS_IDS.POLYGON]);var getNewAnnotationPreview=function(a){var b,c,d;return new annotationsNamesToKonvaClasses[a.name](_objectSpread(_objectSpread({},a),{},{opacity:null!==(b=a.opacity)&&void 0!==b?b:.7,x:null!==(c=a.x)&&void 0!==c?c:0,y:null!==(d=a.y)&&void 0!==d?d:0,width:Math.abs(a.width)||0,height:Math.abs(a.height)||0},ANNOTATIONS_WITH_POINTS.includes(a.name)?{stroke:a.stroke||"#000000"}:{}))};export var dimensToProperAnnotationDimens=function(a,b,c){var d=a.width,e=a.height,f=a.startedX,g=a.startedY,h=_objectWithoutProperties(a,_excluded),i=Math.abs(d),j=Math.abs(e),k=0>d,l=0>e;switch(b){case TOOLS_IDS.RECT:c?(h.width=Math.sqrt(i*i+j*j),h.height=h.width,h.x-=k?h.width-i:0,h.y-=l?h.height-j:0):(h.width=i,h.height=j);break;case TOOLS_IDS.ELLIPSE:c?(h.radiusX=Math.sqrt(i*i+j*j)/2,h.radiusY=h.radiusX,h.x-=k?2*h.radiusX-i:0,h.y-=l?2*h.radiusY-j:0):(h.radiusX=i/2,h.radiusY=j/2),h.offsetX=-h.radiusX,h.offsetY=-h.radiusY;break;case TOOLS_IDS.POLYGON:h.radius=(i+j)/2,h.x-=k?2*h.radius-i:0,h.y-=l?2*h.radius-j:0,h.offsetX=-h.radius,h.offsetY=-h.radius;break;case TOOLS_IDS.LINE:case TOOLS_IDS.ARROW:h.x=f,h.y=g,h.points=[0,0],c?h.points.push(i>=j?d:0,j>i?e:0):h.points=[0,0,d,e];break;default:h.width=i,h.height=j}return h};export default getNewAnnotationPreview;
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ var _excluded = ["width", "height", "startedX", "startedY"];
4
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
5
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
6
+ import Konva from 'konva';
7
+ import { TOOLS_IDS } from 'utils/constants';
8
+ var annotationsNamesToKonvaClasses = _defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty(_defineProperty({}, TOOLS_IDS.RECT, Konva.Rect), TOOLS_IDS.ELLIPSE, Konva.Ellipse), TOOLS_IDS.POLYGON, Konva.RegularPolygon), TOOLS_IDS.LINE, Konva.Line), TOOLS_IDS.IMAGE, Konva.Image), TOOLS_IDS.TEXT, Konva.Text), TOOLS_IDS.ARROW, Konva.Arrow);
9
+ var ANNOTATIONS_WITH_POINTS = [TOOLS_IDS.LINE, TOOLS_IDS.ARROW];
10
+ export var NO_WIDTH_HEIGHT_ANNOTATIONS = [].concat(ANNOTATIONS_WITH_POINTS, [TOOLS_IDS.ELLIPSE, TOOLS_IDS.POLYGON]);
11
+ var getNewAnnotationPreview = function getNewAnnotationPreview(annotation) {
12
+ var _annotation$opacity, _annotation$x, _annotation$y;
13
+ return new annotationsNamesToKonvaClasses[annotation.name](_objectSpread(_objectSpread({}, annotation), {}, {
14
+ opacity: (_annotation$opacity = annotation.opacity) !== null && _annotation$opacity !== void 0 ? _annotation$opacity : 0.7,
15
+ x: (_annotation$x = annotation.x) !== null && _annotation$x !== void 0 ? _annotation$x : 0,
16
+ y: (_annotation$y = annotation.y) !== null && _annotation$y !== void 0 ? _annotation$y : 0,
17
+ width: Math.abs(annotation.width) || 0,
18
+ height: Math.abs(annotation.height) || 0
19
+ }, ANNOTATIONS_WITH_POINTS.includes(annotation.name) ? {
20
+ stroke: annotation.stroke || '#000000'
21
+ } : {}));
22
+ };
23
+ export var dimensToProperAnnotationDimens = function dimensToProperAnnotationDimens(currentDimensions, annotationName, isShiftKeyPressed) {
24
+ var width = currentDimensions.width,
25
+ height = currentDimensions.height,
26
+ startedX = currentDimensions.startedX,
27
+ startedY = currentDimensions.startedY,
28
+ newAnnotationDimens = _objectWithoutProperties(currentDimensions, _excluded);
29
+ var absWidth = Math.abs(width);
30
+ var absHeight = Math.abs(height);
31
+ var isReversedX = width < 0;
32
+ var isReversedY = height < 0;
33
+ switch (annotationName) {
34
+ case TOOLS_IDS.RECT:
35
+ if (isShiftKeyPressed) {
36
+ newAnnotationDimens.width = Math.sqrt(absWidth * absWidth + absHeight * absHeight);
37
+ newAnnotationDimens.height = newAnnotationDimens.width;
38
+ newAnnotationDimens.x -= isReversedX ? newAnnotationDimens.width - absWidth : 0;
39
+ newAnnotationDimens.y -= isReversedY ? newAnnotationDimens.height - absHeight : 0;
40
+ } else {
41
+ newAnnotationDimens.width = absWidth;
42
+ newAnnotationDimens.height = absHeight;
43
+ }
44
+ break;
45
+ case TOOLS_IDS.ELLIPSE:
46
+ if (isShiftKeyPressed) {
47
+ newAnnotationDimens.radiusX = Math.sqrt(absWidth * absWidth + absHeight * absHeight) / 2;
48
+ newAnnotationDimens.radiusY = newAnnotationDimens.radiusX;
49
+ newAnnotationDimens.x -= isReversedX ? newAnnotationDimens.radiusX * 2 - absWidth : 0;
50
+ newAnnotationDimens.y -= isReversedY ? newAnnotationDimens.radiusY * 2 - absHeight : 0;
51
+ } else {
52
+ newAnnotationDimens.radiusX = absWidth / 2;
53
+ newAnnotationDimens.radiusY = absHeight / 2;
54
+ }
55
+ newAnnotationDimens.offsetX = -newAnnotationDimens.radiusX;
56
+ newAnnotationDimens.offsetY = -newAnnotationDimens.radiusY;
57
+ break;
58
+ case TOOLS_IDS.POLYGON:
59
+ newAnnotationDimens.radius = (absWidth + absHeight) / 2;
60
+ newAnnotationDimens.x -= isReversedX ? newAnnotationDimens.radius * 2 - absWidth : 0;
61
+ newAnnotationDimens.y -= isReversedY ? newAnnotationDimens.radius * 2 - absHeight : 0;
62
+ newAnnotationDimens.offsetX = -newAnnotationDimens.radius;
63
+ newAnnotationDimens.offsetY = -newAnnotationDimens.radius;
64
+ break;
65
+ case TOOLS_IDS.LINE:
66
+ case TOOLS_IDS.ARROW:
67
+ newAnnotationDimens.x = startedX;
68
+ newAnnotationDimens.y = startedY;
69
+ newAnnotationDimens.points = [0, 0];
70
+ if (isShiftKeyPressed) {
71
+ newAnnotationDimens.points.push(absWidth >= absHeight ? width : 0, absHeight > absWidth ? height : 0);
72
+ } else {
73
+ newAnnotationDimens.points = [0, 0, width, height];
74
+ }
75
+ break;
76
+ default:
77
+ newAnnotationDimens.width = absWidth;
78
+ newAnnotationDimens.height = absHeight;
79
+ break;
80
+ }
81
+ return newAnnotationDimens;
82
+ };
83
+ export default getNewAnnotationPreview;
@@ -1 +1,138 @@
1
- import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";import _slicedToArray from"@babel/runtime/helpers/slicedToArray";import _defineProperty from"@babel/runtime/helpers/defineProperty";var _excluded=["fonts","onFontChange"],_excluded2=["x","y","width","height","radius","radiusX","radiusY","points","image","text","scaleX","scaleY","rotation"],_excluded3=["shouldSave","neverSave"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import{useCallback,useEffect,useMemo,useRef,useState}from"react";import{SELECT_ANNOTATION,SET_ANNOTATION}from"actions";import randomId from"utils/random-id";import debounce from"utils/debounce";import{TOOLS_IDS}from"utils/constants";import{useStore}from"hooks";import previewThenCallAnnotationAdding from"./preview-then-call-annotation-adding";import useDebouncedCallback from"../use-debounced-callback";var useAnnotation=function(){var a,b=0<arguments.length&&void 0!==arguments[0]?arguments[0]:{},c=!(1<arguments.length&&void 0!==arguments[1])||arguments[1],d=useStore(),e=d.dispatch,f=d.previewGroup,g=d.annotations,h=d.selectionsIds,i=void 0===h?[]:h,j=d.config,k=_objectSpread(_objectSpread({},j.annotationsCommon),j[(null===(a=g[i[0]])||void 0===a?void 0:a.name)||b.name]),l=useState(function(){return _objectSpread(_objectSpread(_objectSpread({},k),b),g[i[0]])}),m=_slicedToArray(l,2),n=m[0],o=m[1],p=useRef(null),q=null===f||void 0===f?void 0:f.getStage(),r=useCallback(function(a){var c=a.fonts,d=a.onFontChange,f=_objectWithoutProperties(a,_excluded);e({type:SET_ANNOTATION,payload:f}),f.id&&b.name!==TOOLS_IDS.PEN&&debounce(function(){e({type:SELECT_ANNOTATION,payload:{annotationId:f.id}})},30)()},[b.name,e]),s=useDebouncedCallback(function(a){o(function(b){return _objectSpread(_objectSpread({},b),{},{shouldSave:!1,neverSave:!1},"function"==typeof a?a(b):a)})},15),t=useCallback(function(a,c){if(a.name===c){var d=a.x,e=a.y,f=a.width,g=a.height,h=a.radius,i=a.radiusX,j=a.radiusY,l=a.points,m=a.image,n=a.text,o=a.scaleX,p=a.scaleY,q=a.rotation,r=_objectWithoutProperties(a,_excluded2);return _objectSpread(_objectSpread(_objectSpread({},k),b),r)}return _objectSpread(_objectSpread({},k),b)},[k,b]),u=useCallback(function(a){o(function(c){var d=t(c,a.name||b.name);return _objectSpread(_objectSpread(_objectSpread({},d),a),{},{id:a.id||randomId(a.name||c.name),shouldSave:!0,neverSave:!1})})},[b.name,t]);return useEffect(function(){var a=n.shouldSave,b=n.neverSave,c=_objectWithoutProperties(n,_excluded3),d=1===i.length&&g[i[0]];!b&&(a||d)&&r(_objectSpread(_objectSpread({},c),{},{id:a?c.id:d.id}))},[n,i,g,r]),useEffect(function(){setTimeout(function(){1===i.length?(p.current=n,o(_objectSpread(_objectSpread({},g[i[0]]),{},{neverSave:!0}))):p.current&&(o(_objectSpread(_objectSpread({},p.current),{},{neverSave:!0})),p.current=null)})},[i,g]),useEffect(function(){var a=null;if(q&&c){var d=t(n,b.name);a=previewThenCallAnnotationAdding(q,_objectSpread(_objectSpread({},d),{},{name:b.name}),f,u)}return function(){a&&a()}},[q,n,f,t,b.name,u]),useMemo(function(){return[n,s,u]},[n,s,u])};export default useAnnotation;
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ var _excluded = ["fonts", "onFontChange"],
5
+ _excluded2 = ["x", "y", "width", "height", "radius", "radiusX", "radiusY", "points", "image", "text", "scaleX", "scaleY", "rotation"],
6
+ _excluded3 = ["shouldSave", "neverSave"];
7
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
8
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
+ import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
10
+ import { SELECT_ANNOTATION, SET_ANNOTATION } from 'actions';
11
+ import randomId from 'utils/random-id';
12
+ import debounce from 'utils/debounce';
13
+ import { TOOLS_IDS } from 'utils/constants';
14
+ import { useStore } from 'hooks';
15
+ import previewThenCallAnnotationAdding from "./preview-then-call-annotation-adding";
16
+ import useDebouncedCallback from "../use-debounced-callback";
17
+ var useAnnotation = function useAnnotation() {
18
+ var _annotations$selectio;
19
+ var annotation = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
20
+ var enablePreview = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : true;
21
+ var _useStore = useStore(),
22
+ dispatch = _useStore.dispatch,
23
+ previewGroup = _useStore.previewGroup,
24
+ annotations = _useStore.annotations,
25
+ _useStore$selectionsI = _useStore.selectionsIds,
26
+ selectionsIds = _useStore$selectionsI === void 0 ? [] : _useStore$selectionsI,
27
+ config = _useStore.config;
28
+ var annotationDefaults = _objectSpread(_objectSpread({}, config.annotationsCommon), config[((_annotations$selectio = annotations[selectionsIds[0]]) === null || _annotations$selectio === void 0 ? void 0 : _annotations$selectio.name) || annotation.name]);
29
+ var _useState = useState(function () {
30
+ return _objectSpread(_objectSpread(_objectSpread({}, annotationDefaults), annotation), annotations[selectionsIds[0]]);
31
+ }),
32
+ _useState2 = _slicedToArray(_useState, 2),
33
+ tmpAnnotation = _useState2[0],
34
+ setTmpAnnotation = _useState2[1];
35
+ var annotationBeforeSelection = useRef(null);
36
+ var canvas = previewGroup === null || previewGroup === void 0 ? void 0 : previewGroup.getStage();
37
+ var saveAnnotation = useCallback(function (annotationData) {
38
+ var _fonts = annotationData.fonts,
39
+ _onFontChange = annotationData.onFontChange,
40
+ savableAnnotationData = _objectWithoutProperties(annotationData, _excluded);
41
+ dispatch({
42
+ type: SET_ANNOTATION,
43
+ payload: savableAnnotationData
44
+ });
45
+ if (savableAnnotationData.id && annotation.name !== TOOLS_IDS.PEN) {
46
+ debounce(function () {
47
+ dispatch({
48
+ type: SELECT_ANNOTATION,
49
+ payload: {
50
+ annotationId: savableAnnotationData.id
51
+ }
52
+ });
53
+ }, 30)();
54
+ }
55
+ }, [annotation.name, dispatch]);
56
+ var updateTmpAnnotation = useDebouncedCallback(function (updatesObjOrFn) {
57
+ setTmpAnnotation(function (latest) {
58
+ return _objectSpread(_objectSpread({}, latest), {}, {
59
+ shouldSave: false,
60
+ neverSave: false
61
+ }, typeof updatesObjOrFn === 'function' ? updatesObjOrFn(latest) : updatesObjOrFn);
62
+ });
63
+ }, 15);
64
+ var getAnnotationInitialProps = useCallback(function (currentAnnotation, newAnnotationName) {
65
+ if (currentAnnotation.name === newAnnotationName) {
66
+ var _x = currentAnnotation.x,
67
+ _y = currentAnnotation.y,
68
+ _width = currentAnnotation.width,
69
+ _height = currentAnnotation.height,
70
+ _radius = currentAnnotation.radius,
71
+ _radiusX = currentAnnotation.radiusX,
72
+ _radiusY = currentAnnotation.radiusY,
73
+ _points = currentAnnotation.points,
74
+ _image = currentAnnotation.image,
75
+ _text = currentAnnotation.text,
76
+ _scaleX = currentAnnotation.scaleX,
77
+ _scaleY = currentAnnotation.scaleY,
78
+ _rotation = currentAnnotation.rotation,
79
+ dimensionlessProps = _objectWithoutProperties(currentAnnotation, _excluded2);
80
+ return _objectSpread(_objectSpread(_objectSpread({}, annotationDefaults), annotation), dimensionlessProps);
81
+ }
82
+ return _objectSpread(_objectSpread({}, annotationDefaults), annotation);
83
+ }, [annotationDefaults, annotation]);
84
+ var saveAnnotationNoDebounce = useCallback(function (newAnnotationData) {
85
+ setTmpAnnotation(function (latest) {
86
+ var initialProps = getAnnotationInitialProps(latest, newAnnotationData.name || annotation.name);
87
+ return _objectSpread(_objectSpread(_objectSpread({}, initialProps), newAnnotationData), {}, {
88
+ id: newAnnotationData.id || randomId(newAnnotationData.name || latest.name),
89
+ shouldSave: true,
90
+ neverSave: false
91
+ });
92
+ });
93
+ }, [annotation.name, getAnnotationInitialProps]);
94
+ useEffect(function () {
95
+ var shouldSave = tmpAnnotation.shouldSave,
96
+ neverSave = tmpAnnotation.neverSave,
97
+ savableAnnotation = _objectWithoutProperties(tmpAnnotation, _excluded3);
98
+ var selection = selectionsIds.length === 1 && annotations[selectionsIds[0]];
99
+ if (!neverSave && (shouldSave || selection)) {
100
+ saveAnnotation(_objectSpread(_objectSpread({}, savableAnnotation), {}, {
101
+ id: shouldSave ? savableAnnotation.id : selection.id
102
+ }));
103
+ }
104
+ }, [tmpAnnotation, selectionsIds, annotations, saveAnnotation]);
105
+ useEffect(function () {
106
+ setTimeout(function () {
107
+ if (selectionsIds.length === 1) {
108
+ annotationBeforeSelection.current = tmpAnnotation;
109
+ setTmpAnnotation(_objectSpread(_objectSpread({}, annotations[selectionsIds[0]]), {}, {
110
+ neverSave: true
111
+ }));
112
+ } else if (annotationBeforeSelection.current) {
113
+ setTmpAnnotation(_objectSpread(_objectSpread({}, annotationBeforeSelection.current), {}, {
114
+ neverSave: true
115
+ }));
116
+ annotationBeforeSelection.current = null;
117
+ }
118
+ });
119
+ }, [selectionsIds, annotations]);
120
+ useEffect(function () {
121
+ var stopAnnotationEventsListening = null;
122
+ if (canvas && enablePreview) {
123
+ var annotationInitialProps = getAnnotationInitialProps(tmpAnnotation, annotation.name);
124
+ stopAnnotationEventsListening = previewThenCallAnnotationAdding(canvas, _objectSpread(_objectSpread({}, annotationInitialProps), {}, {
125
+ name: annotation.name
126
+ }), previewGroup, saveAnnotationNoDebounce);
127
+ }
128
+ return function () {
129
+ if (stopAnnotationEventsListening) {
130
+ stopAnnotationEventsListening();
131
+ }
132
+ };
133
+ }, [canvas, tmpAnnotation, previewGroup, getAnnotationInitialProps, annotation.name, saveAnnotationNoDebounce]);
134
+ return useMemo(function () {
135
+ return [tmpAnnotation, updateTmpAnnotation, saveAnnotationNoDebounce];
136
+ }, [tmpAnnotation, updateTmpAnnotation, saveAnnotationNoDebounce]);
137
+ };
138
+ export default useAnnotation;
@@ -1 +1,159 @@
1
- import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";import _defineProperty from"@babel/runtime/helpers/defineProperty";var _excluded=["id","x","y","points"],_excluded2=["startedX","startedY","offsetX","offsetY","width","height"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import{TOOLS_IDS}from"utils/constants";import getElemDocumentCoords from"utils/get-elem-document-coords";import getPointerOffsetPositionBoundedToObject from"utils/get-pointer-offset-position-bounded-to-object";import getBoundingRectUnScaled from"./get-bounding-rect-un-scaled";import getNewAnnotationPreview,{dimensToProperAnnotationDimens,NO_WIDTH_HEIGHT_ANNOTATIONS}from"./get-new-annotation-preview";var pointerDown={startedX:void 0,startedY:void 0,isOutOfCanvas:!1},eventsOptions={passive:!0},MIN_PIXELS=1,shownAnnotationPreview=null,textAnnotationWrappedRect=null,latestAnnotationProps=null,previewThenCallAnnotationAdding=function(a,b,c,d){var f=function b(){return getElemDocumentCoords(a.content)},g=function b(a){textAnnotationWrappedRect=getNewAnnotationPreview(_objectSpread(_objectSpread({},a),{},{name:TOOLS_IDS.RECT,fill:"",stroke:"#000000",strokeWidth:2,shadowColor:"#ffffff",shadowBlur:1,shadowOpacity:.7})),c.add(textAnnotationWrappedRect)},h=function b(a){shownAnnotationPreview=getNewAnnotationPreview(a),c.add(shownAnnotationPreview),a.name===TOOLS_IDS.TEXT&&g(a),latestAnnotationProps=a},i=function c(a,b){if(latestAnnotationProps){var d=dimensToProperAnnotationDimens(a,latestAnnotationProps.name,b);textAnnotationWrappedRect&&textAnnotationWrappedRect.setAttrs(d),shownAnnotationPreview.setAttrs(d),latestAnnotationProps=_objectSpread(_objectSpread({},latestAnnotationProps),d)}},j=function b(a){var d=getPointerOffsetPositionBoundedToObject(c,f());i(getBoundingRectUnScaled(d,pointerDown,c),a.shiftKey)},k=function a(){c&&shownAnnotationPreview&&c.destroyChildren()},l=function e(d){var g;if(!(1<(null===(g=d.evt.touches)||void 0===g?void 0:g.length))){var k=getPointerOffsetPositionBoundedToObject(c,f());pointerDown.isOutOfCanvas&&(document.removeEventListener("mousemove",j,eventsOptions),document.removeEventListener("touchmove",j,eventsOptions),pointerDown.isOutOfCanvas=!1);var l=getBoundingRectUnScaled(k,pointerDown,c);if(shownAnnotationPreview)i(l,d.evt.shiftKey);else{var m=b.id,n=b.x,o=b.y,p=b.points,q=_objectWithoutProperties(b,_excluded);h(_objectSpread(_objectSpread({},q),l))}a.setAttrs({isDrawing:!0})}},m=function a(){pointerDown.isOutOfCanvas||(document.addEventListener("mousemove",j,eventsOptions),document.addEventListener("touchmove",j,eventsOptions),pointerDown.isOutOfCanvas=!0)},n=function c(){var e,f;if(k(),latestAnnotationProps&&(latestAnnotationProps.width>=MIN_PIXELS&&latestAnnotationProps.height>=MIN_PIXELS||latestAnnotationProps.radiusX>=MIN_PIXELS&&latestAnnotationProps.radiusY>=MIN_PIXELS||null!==(e=latestAnnotationProps.points)&&void 0!==e&&e[2]||null!==(f=latestAnnotationProps.points)&&void 0!==f&&f[3]||latestAnnotationProps.radius>=MIN_PIXELS)){var g=latestAnnotationProps,h=g.startedX,i=g.startedY,o=g.offsetX,p=g.offsetY,q=g.width,r=g.height,s=_objectWithoutProperties(g,_excluded2);NO_WIDTH_HEIGHT_ANNOTATIONS.includes(b.name)||(s.width=q,s.height=r),d(s,!0)}shownAnnotationPreview=null,textAnnotationWrappedRect=null,latestAnnotationProps=null,a.setAttrs({isDrawing:!1}),a.off("mousemove touchmove",l),a.off("mouseleave touchcancel",m),document.removeEventListener("mouseup",n,eventsOptions),document.removeEventListener("touchend",n,eventsOptions),document.removeEventListener("mouseleave",n,eventsOptions),document.removeEventListener("touchcancel",n,eventsOptions),document.removeEventListener("mousemove",j,eventsOptions),document.removeEventListener("touchmove",j,eventsOptions),pointerDown.isOutOfCanvas=!1},o=function d(b){var e;if(b.evt.preventDefault(),!(b.target.attrs.draggable||1<(null===(e=b.evt.touches)||void 0===e?void 0:e.length))){k();var g=getPointerOffsetPositionBoundedToObject(c,f());pointerDown.startedX=g.offsetX,pointerDown.startedY=g.offsetY,pointerDown.isOutOfCanvas=!1,a.on("mousemove touchmove",l),a.on("mouseleave touchcancel",m),document.addEventListener("mouseup",n,eventsOptions),document.addEventListener("touchend",n,eventsOptions),document.addEventListener("mouseleave",n,eventsOptions),document.addEventListener("touchcancel",n,eventsOptions)}};return a.on("mousedown touchstart",o),function(){k(),a.off("mousedown touchstart",o)}};export default previewThenCallAnnotationAdding;
1
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
2
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
3
+ var _excluded = ["id", "x", "y", "points"],
4
+ _excluded2 = ["startedX", "startedY", "offsetX", "offsetY", "width", "height"];
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ import { TOOLS_IDS } from 'utils/constants';
8
+ import getElemDocumentCoords from 'utils/get-elem-document-coords';
9
+ import getPointerOffsetPositionBoundedToObject from 'utils/get-pointer-offset-position-bounded-to-object';
10
+ import getBoundingRectUnScaled from "./get-bounding-rect-un-scaled";
11
+ import getNewAnnotationPreview, { dimensToProperAnnotationDimens, NO_WIDTH_HEIGHT_ANNOTATIONS } from "./get-new-annotation-preview";
12
+ var pointerDown = {
13
+ startedX: undefined,
14
+ startedY: undefined,
15
+ isOutOfCanvas: false
16
+ };
17
+ var eventsOptions = {
18
+ passive: true
19
+ };
20
+ var MIN_PIXELS = 1;
21
+ var shownAnnotationPreview = null;
22
+ var textAnnotationWrappedRect = null;
23
+ var latestAnnotationProps = null;
24
+ var previewThenCallAnnotationAdding = function previewThenCallAnnotationAdding(canvas, annotation, previewGroup, callbkAfterPreview) {
25
+ var getCanvasBoundingRect = function getCanvasBoundingRect() {
26
+ return getElemDocumentCoords(canvas.content);
27
+ };
28
+ var wrapTextBoundsPreviewByRect = function wrapTextBoundsPreviewByRect(textAnnotation) {
29
+ textAnnotationWrappedRect = getNewAnnotationPreview(_objectSpread(_objectSpread({}, textAnnotation), {}, {
30
+ name: TOOLS_IDS.RECT,
31
+ fill: '',
32
+ stroke: '#000000',
33
+ strokeWidth: 2,
34
+ shadowColor: '#ffffff',
35
+ shadowBlur: 1,
36
+ shadowOpacity: 0.7
37
+ }));
38
+ previewGroup.add(textAnnotationWrappedRect);
39
+ };
40
+ var previewAnnotation = function previewAnnotation(preparedAnnotation) {
41
+ shownAnnotationPreview = getNewAnnotationPreview(preparedAnnotation);
42
+ previewGroup.add(shownAnnotationPreview);
43
+ if (preparedAnnotation.name === TOOLS_IDS.TEXT) {
44
+ wrapTextBoundsPreviewByRect(preparedAnnotation);
45
+ }
46
+ latestAnnotationProps = preparedAnnotation;
47
+ };
48
+ var updateAnnotationPreview = function updateAnnotationPreview(preparedBoundingRect, isShiftKeyPressed) {
49
+ if (!latestAnnotationProps) {
50
+ return;
51
+ }
52
+ var transformedAnnotation = dimensToProperAnnotationDimens(preparedBoundingRect, latestAnnotationProps.name, isShiftKeyPressed);
53
+ if (textAnnotationWrappedRect) {
54
+ textAnnotationWrappedRect.setAttrs(transformedAnnotation);
55
+ }
56
+ shownAnnotationPreview.setAttrs(transformedAnnotation);
57
+ latestAnnotationProps = _objectSpread(_objectSpread({}, latestAnnotationProps), transformedAnnotation);
58
+ };
59
+ var updatePreviewWithBoundedDimens = function updatePreviewWithBoundedDimens(e) {
60
+ var pointerOffsets = getPointerOffsetPositionBoundedToObject(previewGroup, getCanvasBoundingRect());
61
+ updateAnnotationPreview(getBoundingRectUnScaled(pointerOffsets, pointerDown, previewGroup), e.shiftKey);
62
+ };
63
+ var destroyShownPreview = function destroyShownPreview() {
64
+ if (previewGroup && shownAnnotationPreview) {
65
+ previewGroup.destroyChildren();
66
+ }
67
+ };
68
+ var handlePointerMove = function handlePointerMove(e) {
69
+ var _e$evt$touches;
70
+ if (((_e$evt$touches = e.evt.touches) === null || _e$evt$touches === void 0 ? void 0 : _e$evt$touches.length) > 1) {
71
+ return;
72
+ }
73
+ var pointerOffsets = getPointerOffsetPositionBoundedToObject(previewGroup, getCanvasBoundingRect());
74
+ if (pointerDown.isOutOfCanvas) {
75
+ document.removeEventListener('mousemove', updatePreviewWithBoundedDimens, eventsOptions);
76
+ document.removeEventListener('touchmove', updatePreviewWithBoundedDimens, eventsOptions);
77
+ pointerDown.isOutOfCanvas = false;
78
+ }
79
+ var boundingRect = getBoundingRectUnScaled(pointerOffsets, pointerDown, previewGroup);
80
+ if (shownAnnotationPreview) {
81
+ updateAnnotationPreview(boundingRect, e.evt.shiftKey);
82
+ } else {
83
+ var _id = annotation.id,
84
+ _x = annotation.x,
85
+ _y = annotation.y,
86
+ _points = annotation.points,
87
+ currentAnnotationProps = _objectWithoutProperties(annotation, _excluded);
88
+ previewAnnotation(_objectSpread(_objectSpread({}, currentAnnotationProps), boundingRect));
89
+ }
90
+ canvas.setAttrs({
91
+ isDrawing: true
92
+ });
93
+ };
94
+ var handlePointerOut = function handlePointerOut() {
95
+ if (!pointerDown.isOutOfCanvas) {
96
+ document.addEventListener('mousemove', updatePreviewWithBoundedDimens, eventsOptions);
97
+ document.addEventListener('touchmove', updatePreviewWithBoundedDimens, eventsOptions);
98
+ pointerDown.isOutOfCanvas = true;
99
+ }
100
+ };
101
+ var _handlePointerUp = function handlePointerUp() {
102
+ var _latestAnnotationProp, _latestAnnotationProp2;
103
+ destroyShownPreview();
104
+ if (latestAnnotationProps && (latestAnnotationProps.width >= MIN_PIXELS && latestAnnotationProps.height >= MIN_PIXELS || latestAnnotationProps.radiusX >= MIN_PIXELS && latestAnnotationProps.radiusY >= MIN_PIXELS || (_latestAnnotationProp = latestAnnotationProps.points) !== null && _latestAnnotationProp !== void 0 && _latestAnnotationProp[2] || (_latestAnnotationProp2 = latestAnnotationProps.points) !== null && _latestAnnotationProp2 !== void 0 && _latestAnnotationProp2[3] || latestAnnotationProps.radius >= MIN_PIXELS)) {
105
+ var _latestAnnotationProp3 = latestAnnotationProps,
106
+ _startedX = _latestAnnotationProp3.startedX,
107
+ _startedY = _latestAnnotationProp3.startedY,
108
+ _offsetX = _latestAnnotationProp3.offsetX,
109
+ _offsetY = _latestAnnotationProp3.offsetY,
110
+ width = _latestAnnotationProp3.width,
111
+ height = _latestAnnotationProp3.height,
112
+ savableAnnotation = _objectWithoutProperties(_latestAnnotationProp3, _excluded2);
113
+ if (!NO_WIDTH_HEIGHT_ANNOTATIONS.includes(annotation.name)) {
114
+ savableAnnotation.width = width;
115
+ savableAnnotation.height = height;
116
+ }
117
+ callbkAfterPreview(savableAnnotation, true);
118
+ }
119
+ shownAnnotationPreview = null;
120
+ textAnnotationWrappedRect = null;
121
+ latestAnnotationProps = null;
122
+ canvas.setAttrs({
123
+ isDrawing: false
124
+ });
125
+ canvas.off('mousemove touchmove', handlePointerMove);
126
+ canvas.off('mouseleave touchcancel', handlePointerOut);
127
+ document.removeEventListener('mouseup', _handlePointerUp, eventsOptions);
128
+ document.removeEventListener('touchend', _handlePointerUp, eventsOptions);
129
+ document.removeEventListener('mouseleave', _handlePointerUp, eventsOptions);
130
+ document.removeEventListener('touchcancel', _handlePointerUp, eventsOptions);
131
+ document.removeEventListener('mousemove', updatePreviewWithBoundedDimens, eventsOptions);
132
+ document.removeEventListener('touchmove', updatePreviewWithBoundedDimens, eventsOptions);
133
+ pointerDown.isOutOfCanvas = false;
134
+ };
135
+ var handlePointerDown = function handlePointerDown(e) {
136
+ var _e$evt$touches2;
137
+ e.evt.preventDefault();
138
+ if (e.target.attrs.draggable || ((_e$evt$touches2 = e.evt.touches) === null || _e$evt$touches2 === void 0 ? void 0 : _e$evt$touches2.length) > 1) {
139
+ return;
140
+ }
141
+ destroyShownPreview();
142
+ var pointerOffsets = getPointerOffsetPositionBoundedToObject(previewGroup, getCanvasBoundingRect());
143
+ pointerDown.startedX = pointerOffsets.offsetX;
144
+ pointerDown.startedY = pointerOffsets.offsetY;
145
+ pointerDown.isOutOfCanvas = false;
146
+ canvas.on('mousemove touchmove', handlePointerMove);
147
+ canvas.on('mouseleave touchcancel', handlePointerOut);
148
+ document.addEventListener('mouseup', _handlePointerUp, eventsOptions);
149
+ document.addEventListener('touchend', _handlePointerUp, eventsOptions);
150
+ document.addEventListener('mouseleave', _handlePointerUp, eventsOptions);
151
+ document.addEventListener('touchcancel', _handlePointerUp, eventsOptions);
152
+ };
153
+ canvas.on('mousedown touchstart', handlePointerDown);
154
+ return function () {
155
+ destroyShownPreview();
156
+ canvas.off('mousedown touchstart', handlePointerDown);
157
+ };
158
+ };
159
+ export default previewThenCallAnnotationAdding;
@@ -1 +1,83 @@
1
- import{useMemo,useCallback}from"react";import{SET_ANNOTATION,SELECT_ANNOTATION,SELECT_TOOL}from"actions";import{TOOLS_IDS,TABS_IDS,WATERMARK_ANNOTATION_ID}from"utils/constants";import useStore from"./use-store";var useAnnotationEvents=function(){var a=useStore(),b=a.tabId,c=a.dispatch,d=useMemo(function(){return b!==TABS_IDS.ANNOTATE&&b!==TABS_IDS.WATERMARK},[b]),f=useCallback(function(a){c({type:SET_ANNOTATION,payload:a})},[]),g=useCallback(function(a){f({id:a.target.id(),x:a.target.x(),y:a.target.y()})},[]),h=useCallback(function(a){var b={id:a.target.id(),rotation:a.target.rotation(),x:a.target.x(),y:a.target.y()};return a.target.name()===TOOLS_IDS.TEXT?(b.width=a.target.width()*a.target.scaleX(),b.height=a.target.height()*a.target.scaleY(),b.scaleX=1,b.scaleY=1):(b.scaleX=a.target.scaleX(),b.scaleY=a.target.scaleY()),b},[]),i=useCallback(function(a){f(h(a))},[]),j=useCallback(function(a){a.target.name()===TOOLS_IDS.TEXT&&a.target.setAttrs(h(a))},[]),k=useCallback(function(a){var b;if(!(a.target.id()===WATERMARK_ANNOTATION_ID||null!==(b=a.target.getStage())&&void 0!==b&&b.attrs.isDrawing)){var d=a.evt,e="ctrlKey"in d&&(d.ctrlKey||d.shiftKey||d.metaKey)||!1;c({type:SELECT_ANNOTATION,payload:{annotationId:a.target.id(),multiple:e}}),c({type:SELECT_TOOL,payload:{toolId:a.target.name(),keepSelections:e}})}},[]);return useMemo(function(){return d?{}:{onTransform:j,onTransformEnd:i,onDragEnd:g,onClick:k,onTap:k}},[d])};export default useAnnotationEvents;
1
+ import { useMemo, useCallback } from 'react';
2
+ import { SET_ANNOTATION, SELECT_ANNOTATION, SELECT_TOOL } from 'actions';
3
+ import { TOOLS_IDS, TABS_IDS, WATERMARK_ANNOTATION_ID } from 'utils/constants';
4
+ import useStore from "./use-store";
5
+ var useAnnotationEvents = function useAnnotationEvents() {
6
+ var _useStore = useStore(),
7
+ tabId = _useStore.tabId,
8
+ dispatch = _useStore.dispatch;
9
+ var isAnnotationEventsDisabled = useMemo(function () {
10
+ return tabId !== TABS_IDS.ANNOTATE && tabId !== TABS_IDS.WATERMARK;
11
+ }, [tabId]);
12
+ var updateAnnotation = useCallback(function (annotationProps) {
13
+ dispatch({
14
+ type: SET_ANNOTATION,
15
+ payload: annotationProps
16
+ });
17
+ }, []);
18
+ var updatePositionOnDragEnd = useCallback(function (e) {
19
+ updateAnnotation({
20
+ id: e.target.id(),
21
+ x: e.target.x(),
22
+ y: e.target.y()
23
+ });
24
+ }, []);
25
+ var getAnnotationTransformProps = useCallback(function (e) {
26
+ var transformProps = {
27
+ id: e.target.id(),
28
+ rotation: e.target.rotation(),
29
+ x: e.target.x(),
30
+ y: e.target.y()
31
+ };
32
+ if (e.target.name() === TOOLS_IDS.TEXT) {
33
+ transformProps.width = e.target.width() * e.target.scaleX();
34
+ transformProps.height = e.target.height() * e.target.scaleY();
35
+ transformProps.scaleX = 1;
36
+ transformProps.scaleY = 1;
37
+ } else {
38
+ transformProps.scaleX = e.target.scaleX();
39
+ transformProps.scaleY = e.target.scaleY();
40
+ }
41
+ return transformProps;
42
+ }, []);
43
+ var updateAnnotationTransform = useCallback(function (e) {
44
+ updateAnnotation(getAnnotationTransformProps(e));
45
+ }, []);
46
+ var updateTextAnnotationOnTransform = useCallback(function (e) {
47
+ if (e.target.name() === TOOLS_IDS.TEXT) {
48
+ e.target.setAttrs(getAnnotationTransformProps(e));
49
+ }
50
+ }, []);
51
+ var selectAnnotationOnClick = useCallback(function (e) {
52
+ var _e$target$getStage;
53
+ if (e.target.id() === WATERMARK_ANNOTATION_ID || (_e$target$getStage = e.target.getStage()) !== null && _e$target$getStage !== void 0 && _e$target$getStage.attrs.isDrawing) {
54
+ return;
55
+ }
56
+ var evt = e.evt;
57
+ var multiple = 'ctrlKey' in evt && (evt.ctrlKey || evt.shiftKey || evt.metaKey) || false;
58
+ dispatch({
59
+ type: SELECT_ANNOTATION,
60
+ payload: {
61
+ annotationId: e.target.id(),
62
+ multiple: multiple
63
+ }
64
+ });
65
+ dispatch({
66
+ type: SELECT_TOOL,
67
+ payload: {
68
+ toolId: e.target.name(),
69
+ keepSelections: multiple
70
+ }
71
+ });
72
+ }, []);
73
+ return useMemo(function () {
74
+ return isAnnotationEventsDisabled ? {} : {
75
+ onTransform: updateTextAnnotationOnTransform,
76
+ onTransformEnd: updateAnnotationTransform,
77
+ onDragEnd: updatePositionOnDragEnd,
78
+ onClick: selectAnnotationOnClick,
79
+ onTap: selectAnnotationOnClick
80
+ };
81
+ }, [isAnnotationEventsDisabled]);
82
+ };
83
+ export default useAnnotationEvents;
@@ -1 +1,53 @@
1
- import _toConsumableArray from"@babel/runtime/helpers/toConsumableArray";import _objectWithoutProperties from"@babel/runtime/helpers/objectWithoutProperties";import _defineProperty from"@babel/runtime/helpers/defineProperty";var _excluded=["isDesignState"];function ownKeys(a,b){var c=Object.keys(a);if(Object.getOwnPropertySymbols){var d=Object.getOwnPropertySymbols(a);b&&(d=d.filter(function(b){return Object.getOwnPropertyDescriptor(a,b).enumerable})),c.push.apply(c,d)}return c}function _objectSpread(a){for(var b,c=1;c<arguments.length;c++)b=null==arguments[c]?{}:arguments[c],c%2?ownKeys(Object(b),!0).forEach(function(c){_defineProperty(a,c,b[c])}):Object.getOwnPropertyDescriptors?Object.defineProperties(a,Object.getOwnPropertyDescriptors(b)):ownKeys(Object(b)).forEach(function(c){Object.defineProperty(a,c,Object.getOwnPropertyDescriptor(b,c))});return a}import{useReducer}from"react";import{REDO,RESET,UNDO}from"actions";import extractCurrentDesignState from"utils/extract-current-design-state";var timeout,applyModifyFn=function(a,b){timeout=setTimeout(function(){clearTimeout(timeout),"function"==typeof a&&b&&a(b)})},useAppReducer=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:{},d=_objectSpread(_objectSpread({},b),{},{pastDesignStates:[],futureDesignStates:[],hasRedo:!1,hasUndo:!1});return useReducer(function(b,e){var f=a(b,e)||d;if([UNDO,REDO,RESET].includes(e.type))return applyModifyFn(c.onModify,f),f;if(f.isDesignState){var g=extractCurrentDesignState(b,!1),h=f.isDesignState,i=_objectWithoutProperties(f,_excluded),j=_objectSpread(_objectSpread({},i),{},{isDesignState:!1,pastDesignStates:[g].concat(_toConsumableArray(b.pastDesignStates)),hasUndo:!0,hasRedo:!1,futureDesignStates:[],isResetted:!1,haveNotSavedChanges:!0});return applyModifyFn(c.onModify,j),j}return f},d)};export default useAppReducer;
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
+ var _excluded = ["isDesignState"];
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ import { useReducer } from 'react';
8
+ import { REDO, RESET, UNDO } from 'actions';
9
+ import extractCurrentDesignState from 'utils/extract-current-design-state';
10
+ var timeout;
11
+ var applyModifyFn = function applyModifyFn(onModify, newState) {
12
+ timeout = setTimeout(function () {
13
+ clearTimeout(timeout);
14
+ if (typeof onModify === 'function' && newState) {
15
+ onModify(newState);
16
+ }
17
+ });
18
+ };
19
+ var useAppReducer = function useAppReducer(reducer, initialState) {
20
+ var passedConfig = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
21
+ var initialStateWithUndoRedo = _objectSpread(_objectSpread({}, initialState), {}, {
22
+ pastDesignStates: [],
23
+ futureDesignStates: [],
24
+ hasRedo: false,
25
+ hasUndo: false
26
+ });
27
+ var undoRedoResetReducer = function undoRedoResetReducer(state, action) {
28
+ var newPresentState = reducer(state, action) || initialStateWithUndoRedo;
29
+ if ([UNDO, REDO, RESET].includes(action.type)) {
30
+ applyModifyFn(passedConfig.onModify, newPresentState);
31
+ return newPresentState;
32
+ }
33
+ if (newPresentState.isDesignState) {
34
+ var currentState = extractCurrentDesignState(state, false);
35
+ var _isDesignState = newPresentState.isDesignState,
36
+ neededNewPresentState = _objectWithoutProperties(newPresentState, _excluded);
37
+ var newState = _objectSpread(_objectSpread({}, neededNewPresentState), {}, {
38
+ isDesignState: false,
39
+ pastDesignStates: [currentState].concat(_toConsumableArray(state.pastDesignStates)),
40
+ hasUndo: true,
41
+ hasRedo: false,
42
+ futureDesignStates: [],
43
+ isResetted: false,
44
+ haveNotSavedChanges: true
45
+ });
46
+ applyModifyFn(passedConfig.onModify, newState);
47
+ return newState;
48
+ }
49
+ return newPresentState;
50
+ };
51
+ return useReducer(undoRedoResetReducer, initialStateWithUndoRedo);
52
+ };
53
+ export default useAppReducer;
@@ -1 +1,7 @@
1
- import{useCallback}from"react";import debounce from"utils/debounce";var useDebouncedCallback=function(a,b){var c=2<arguments.length&&arguments[2]!==void 0?arguments[2]:[];return useCallback(debounce(a,b),c)};export default useDebouncedCallback;
1
+ import { useCallback } from 'react';
2
+ import debounce from 'utils/debounce';
3
+ var useDebouncedCallback = function useDebouncedCallback(func, timeout) {
4
+ var dependencies = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
5
+ return useCallback(debounce(func, timeout), dependencies);
6
+ };
7
+ export default useDebouncedCallback;
@@ -1 +1,37 @@
1
- var useDrag=function(a,b,c){var d=function(b){if("function"==typeof a){var c;a((null===(c=b.touches)||void 0===c?void 0:c[0])||b)}},f=function(a){if(document.removeEventListener("mousemove",d),document.removeEventListener("mouseup",f),document.removeEventListener("mouseleave",f),document.removeEventListener("touchmove",d),document.removeEventListener("touchend",f),document.removeEventListener("touchcancel",f),"function"==typeof c){var b;c((null===(b=a.touches)||void 0===b?void 0:b[0])||a)}},g=function(a){if(document.addEventListener("mousemove",d),document.addEventListener("mouseup",f),document.addEventListener("mouseleave",f),document.addEventListener("touchmove",d),document.addEventListener("touchend",f),document.addEventListener("touchcancel",f),"function"==typeof b){var c;b((null===(c=a.touches)||void 0===c?void 0:c[0])||a)}};return{onMouseDown:g,onTouchStart:g}};export default useDrag;
1
+ var useDrag = function useDrag(onMove, onStart, onEnd) {
2
+ var onDragging = function onDragging(e) {
3
+ if (typeof onMove === 'function') {
4
+ var _touches;
5
+ onMove(((_touches = e.touches) === null || _touches === void 0 ? void 0 : _touches[0]) || e);
6
+ }
7
+ };
8
+ var _disableSliding = function disableSliding(e) {
9
+ document.removeEventListener('mousemove', onDragging);
10
+ document.removeEventListener('mouseup', _disableSliding);
11
+ document.removeEventListener('mouseleave', _disableSliding);
12
+ document.removeEventListener('touchmove', onDragging);
13
+ document.removeEventListener('touchend', _disableSliding);
14
+ document.removeEventListener('touchcancel', _disableSliding);
15
+ if (typeof onEnd === 'function') {
16
+ var _touches2;
17
+ onEnd(((_touches2 = e.touches) === null || _touches2 === void 0 ? void 0 : _touches2[0]) || e);
18
+ }
19
+ };
20
+ var enableDrag = function enableDrag(e) {
21
+ document.addEventListener('mousemove', onDragging);
22
+ document.addEventListener('mouseup', _disableSliding);
23
+ document.addEventListener('mouseleave', _disableSliding);
24
+ document.addEventListener('touchmove', onDragging);
25
+ document.addEventListener('touchend', _disableSliding);
26
+ document.addEventListener('touchcancel', _disableSliding);
27
+ if (typeof onStart === 'function') {
28
+ var _touches3;
29
+ onStart(((_touches3 = e.touches) === null || _touches3 === void 0 ? void 0 : _touches3[0]) || e);
30
+ }
31
+ };
32
+ return {
33
+ onMouseDown: enableDrag,
34
+ onTouchStart: enableDrag
35
+ };
36
+ };
37
+ export default useDrag;
@@ -1 +1,20 @@
1
- import{useCallback,useMemo}from"react";import{ADD_FILTER}from"actions";import useStore from"./use-store";var useFilter=function(){var a=useStore(),b=a.dispatch,c=a.filter,d=useCallback(function(a){b({type:ADD_FILTER,payload:{filter:a}})},[]);return useMemo(function(){return[c,d]},[c])};export default useFilter;
1
+ import { useCallback, useMemo } from 'react';
2
+ import { ADD_FILTER } from 'actions';
3
+ import useStore from "./use-store";
4
+ var useFilter = function useFilter() {
5
+ var _useStore = useStore(),
6
+ dispatch = _useStore.dispatch,
7
+ filter = _useStore.filter;
8
+ var setFilter = useCallback(function (filterToApply) {
9
+ dispatch({
10
+ type: ADD_FILTER,
11
+ payload: {
12
+ filter: filterToApply
13
+ }
14
+ });
15
+ }, []);
16
+ return useMemo(function () {
17
+ return [filter, setFilter];
18
+ }, [filter]);
19
+ };
20
+ export default useFilter;