@squiz/formatted-text-editor 1.65.1 → 1.66.1

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/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # Change Log
2
2
 
3
+ ## 1.66.1
4
+
5
+ ### Patch Changes
6
+
7
+ - e01fd51: Fixed FTE floating toolbar overlap
8
+
9
+ ## 1.66.0
10
+
11
+ ### Minor Changes
12
+
13
+ - a5b0869: Update fte toolbar to max height 100% so that it can be flexible at any width and position placeholder
14
+
3
15
  ## 1.65.1
4
16
 
5
17
  ### Patch Changes
package/lib/index.css CHANGED
@@ -822,6 +822,7 @@
822
822
  outline-width: 0px;
823
823
  }
824
824
  .squiz-fte-scope.squiz-fte-scope__editor .remirror-editor p {
825
+ position: relative;
825
826
  display: block;
826
827
  }
827
828
  .squiz-fte-scope.squiz-fte-scope__editor--bordered {
@@ -909,7 +910,7 @@
909
910
  }
910
911
  .squiz-fte-scope .header-toolbar.show-toolbar {
911
912
  opacity: 1;
912
- max-height: 15vh;
913
+ max-height: 108px;
913
914
  }
914
915
  .squiz-fte-scope__floating-popover {
915
916
  display: flex;
@@ -74,11 +74,20 @@ const createToolbarPositioner = ({ types }) => {
74
74
  const leftmost = Math.min(from.left, to.left);
75
75
  // The position nearest the top.
76
76
  const topmost = Math.min(from.top, to.top);
77
+ const bottommost = Math.max(from.bottom, to.bottom);
77
78
  const left = parent.scrollLeft + (spansMultipleLines ? to.left - parentRect.left : leftmost - parentRect.left);
78
79
  const top = parent.scrollTop + topmost - parentRect.top;
79
80
  const width = spansMultipleLines ? 1 : Math.abs(from.left - to.right);
80
81
  const rect = new DOMRect(spansMultipleLines ? to.left : leftmost, topmost, width, height);
81
- return { rect, y: top, x: left, height, width, visible };
82
+ // Get header toolbar by class inside the current element/editor
83
+ const headerToolbar = element.parentElement?.getElementsByClassName('header-toolbar')?.[0];
84
+ const headerBarRects = headerToolbar?.getBoundingClientRect();
85
+ const headerBarHeight = headerBarRects?.height ?? 0;
86
+ const headerBarBottom = (headerBarRects?.top ?? 0) + headerBarHeight;
87
+ // If floating toolbar will overlap fixed toolbar, set position to under selection
88
+ const isOverlapping = headerBarBottom + headerBarHeight > topmost;
89
+ const y = isOverlapping ? bottommost + 62 : top; // FIXME: need to calculate rather than hard-code
90
+ return { rect, y, x: left, height, width, visible };
82
91
  },
83
92
  });
84
93
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@squiz/formatted-text-editor",
3
- "version": "1.65.1",
3
+ "version": "1.66.1",
4
4
  "main": "lib/index.js",
5
5
  "types": "lib/index.d.ts",
6
6
  "private": false,
@@ -35,7 +35,7 @@
35
35
  "@testing-library/jest-dom": "5.16.5",
36
36
  "@testing-library/react": "14.0.0",
37
37
  "@testing-library/user-event": "14.4.3",
38
- "@types/node": "18.15.2",
38
+ "@types/node": "20.11.24",
39
39
  "@types/react": "^18.2.45",
40
40
  "@types/react-dom": "^18.2.18",
41
41
  "@vitejs/plugin-react": "3.0.0",
@@ -23,6 +23,7 @@
23
23
  }
24
24
 
25
25
  p {
26
+ position: relative; // ensures that the placeholder text is positioned correctly
26
27
  /* Make sure content aligned with "text-align: justify" is justified */
27
28
  @apply block;
28
29
  }
@@ -32,6 +32,6 @@
32
32
 
33
33
  &.show-toolbar {
34
34
  opacity: 1;
35
- max-height: 15vh;
35
+ max-height: 108px; // this should mean at least 3 icons can git vertically if needed
36
36
  }
37
37
  }
@@ -103,13 +103,24 @@ export const createToolbarPositioner = ({ types }: ToolbarPositionerProps) => {
103
103
 
104
104
  // The position nearest the top.
105
105
  const topmost = Math.min(from.top, to.top);
106
+ const bottommost = Math.max(from.bottom, to.bottom);
106
107
 
107
108
  const left = parent.scrollLeft + (spansMultipleLines ? to.left - parentRect.left : leftmost - parentRect.left);
108
109
  const top = parent.scrollTop + topmost - parentRect.top;
109
110
  const width = spansMultipleLines ? 1 : Math.abs(from.left - to.right);
110
111
  const rect = new DOMRect(spansMultipleLines ? to.left : leftmost, topmost, width, height);
111
112
 
112
- return { rect, y: top, x: left, height, width, visible };
113
+ // Get header toolbar by class inside the current element/editor
114
+ const headerToolbar = element.parentElement?.getElementsByClassName('header-toolbar')?.[0];
115
+ const headerBarRects = headerToolbar?.getBoundingClientRect();
116
+ const headerBarHeight = headerBarRects?.height ?? 0;
117
+ const headerBarBottom = (headerBarRects?.top ?? 0) + headerBarHeight;
118
+
119
+ // If floating toolbar will overlap fixed toolbar, set position to under selection
120
+ const isOverlapping = headerBarBottom + headerBarHeight > topmost;
121
+ const y = isOverlapping ? bottommost + 62 : top; // FIXME: need to calculate rather than hard-code
122
+
123
+ return { rect, y, x: left, height, width, visible };
113
124
  },
114
125
  });
115
126
  };