pages_core 3.15.3 → 3.15.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useRef, useState } from "react";
1
+ import React, { useCallback, useState } from "react";
2
2
 
3
3
  import * as Crop from "../types/Crop";
4
4
 
@@ -24,28 +24,28 @@ function focalPoint(state: Crop.State): Crop.Position {
24
24
  }
25
25
  }
26
26
 
27
- export default function ImageCropper(props: Props) {
28
- const containerRef = useRef<HTMLDivElement>();
27
+ function useContainerSize(): [(node?: HTMLDivElement) => void, Crop.Size] {
29
28
  const [containerSize, setContainerSize] = useState<Crop.Size>();
30
29
 
31
- const handleResize = () => {
32
- const elem = containerRef.current;
33
- if (elem) {
30
+ const ref = useCallback((node?: HTMLDivElement) => {
31
+ const measure = () => {
34
32
  setContainerSize({
35
- width: elem.offsetWidth - 2,
36
- height: elem.offsetHeight - 2
33
+ width: node.offsetWidth - 2,
34
+ height: node.offsetHeight - 2
37
35
  });
36
+ };
37
+ if (node !== null) {
38
+ measure();
39
+ const observer = new ResizeObserver(measure);
40
+ observer.observe(node);
38
41
  }
39
- };
42
+ }, []);
40
43
 
41
- useEffect(() => {
42
- window.addEventListener("resize", handleResize);
43
- return function cleanup() {
44
- window.removeEventListener("resize", handleResize);
45
- };
46
- });
44
+ return [ref, containerSize];
45
+ }
47
46
 
48
- useEffect(handleResize, []);
47
+ export default function ImageCropper(props: Props) {
48
+ const [containerRef, containerSize] = useContainerSize();
49
49
 
50
50
  const setAspect = (aspect: number) => {
51
51
  props.dispatch({ type: "setAspect", payload: aspect });
@@ -107,6 +107,13 @@ export default function PageForm(props: Props) {
107
107
  } else {
108
108
  filesState.update(response.page_files);
109
109
  imagesState.update(response.page_images);
110
+ tagsDispatch({
111
+ type: "update",
112
+ payload: {
113
+ tags: response.tags_and_suggestions,
114
+ enabled: response.enabled_tags
115
+ }
116
+ });
110
117
  noticeToast("Your changes were saved");
111
118
  }
112
119
  })
@@ -32,15 +32,17 @@ function toggle(tag: string, state: Tags.State) {
32
32
 
33
33
  function reducer(state: Tags.State, action: Tags.Action) {
34
34
  const { type, payload } = action;
35
- const normalized = normalize(payload, state);
36
35
  switch (type) {
37
36
  case "addTag":
37
+ const normalized = normalize(payload, state);
38
38
  return {
39
39
  tags: [...state.tags, normalized].filter(onlyUnique),
40
40
  enabled: [...state.enabled, normalized].filter(onlyUnique)
41
41
  };
42
42
  case "toggleTag":
43
- return toggle(normalized, state);
43
+ return toggle(normalize(payload, state), state);
44
+ case "update":
45
+ return payload;
44
46
  default:
45
47
  return state;
46
48
  }
@@ -1,7 +1,6 @@
1
- export interface Action {
2
- type: "addTag" | "toggleTag";
3
- payload: string;
4
- }
1
+ export type Action =
2
+ | { type: "addTag" | "toggleTag"; payload: string }
3
+ | { type: "update"; payload: State };
5
4
 
6
5
  export interface State {
7
6
  enabled: string[];
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pages_core
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.15.3
4
+ version: 3.15.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Inge Jørgensen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-06-12 00:00:00.000000000 Z
11
+ date: 2024-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails