tycho-components 0.41.1 → 0.41.2

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.
@@ -10,7 +10,9 @@ declare const CommentUtils: {
10
10
  persistDrawerWidth: (width: number) => void;
11
11
  persistDrawerHeight: (height: number) => void;
12
12
  readStoredDockPosition: () => DockPosition;
13
- persistDockPosition: (position: DockedPosition) => void;
13
+ persistDockPosition: (position: DockPosition) => void;
14
+ readStoredLastDocked: () => DockedPosition;
15
+ persistLastDocked: (position: DockedPosition) => void;
14
16
  getUndockedPopupSize: () => {
15
17
  width: number;
16
18
  height: number;
@@ -1,6 +1,7 @@
1
1
  const DRAWER_WIDTH_STORAGE_KEY = 'tycho-comments-drawer-width';
2
2
  const DRAWER_HEIGHT_STORAGE_KEY = 'tycho-comments-drawer-height';
3
3
  const DOCK_POSITION_STORAGE_KEY = 'tycho-comments-dock-position';
4
+ const LAST_DOCKED_STORAGE_KEY = 'tycho-comments-last-docked';
4
5
  const DRAWER_MIN_WIDTH = 320;
5
6
  const DRAWER_MIN_HEIGHT = 200;
6
7
  const POPUP_NAME = 'tycho-comments';
@@ -87,7 +88,7 @@ const persistDrawerHeight = (height) => {
87
88
  const readStoredDockPosition = () => {
88
89
  try {
89
90
  const stored = localStorage.getItem(DOCK_POSITION_STORAGE_KEY);
90
- if (isDockPosition(stored) && stored !== 'undocked') {
91
+ if (isDockPosition(stored)) {
91
92
  return stored;
92
93
  }
93
94
  }
@@ -104,6 +105,30 @@ const persistDockPosition = (position) => {
104
105
  // ignore storage access errors
105
106
  }
106
107
  };
108
+ const readStoredLastDocked = () => {
109
+ try {
110
+ const stored = localStorage.getItem(LAST_DOCKED_STORAGE_KEY);
111
+ if (stored === 'left' || stored === 'right' || stored === 'bottom') {
112
+ return stored;
113
+ }
114
+ const dock = localStorage.getItem(DOCK_POSITION_STORAGE_KEY);
115
+ if (dock === 'left' || dock === 'right' || dock === 'bottom') {
116
+ return dock;
117
+ }
118
+ }
119
+ catch {
120
+ // ignore storage access errors
121
+ }
122
+ return 'right';
123
+ };
124
+ const persistLastDocked = (position) => {
125
+ try {
126
+ localStorage.setItem(LAST_DOCKED_STORAGE_KEY, position);
127
+ }
128
+ catch {
129
+ // ignore storage access errors
130
+ }
131
+ };
107
132
  const getUndockedPopupSize = () => {
108
133
  if (typeof window === 'undefined') {
109
134
  return { width: POPUP_MIN_WIDTH, height: POPUP_MIN_HEIGHT };
@@ -168,6 +193,8 @@ const CommentUtils = {
168
193
  persistDrawerHeight,
169
194
  readStoredDockPosition,
170
195
  persistDockPosition,
196
+ readStoredLastDocked,
197
+ persistLastDocked,
171
198
  getUndockedPopupSize,
172
199
  copyStylesToPopup,
173
200
  openCommentsPopup,
@@ -41,12 +41,11 @@ export default function Comments({ uid, keywords, references, mode, onClose, onC
41
41
  const popupRef = useRef(null);
42
42
  const popupPollRef = useRef(null);
43
43
  const ignorePopupCloseRef = useRef(false);
44
+ const popupCloseHandledRef = useRef(false);
45
+ const restoredUndockRef = useRef(false);
44
46
  const lastDockedRef = useRef(null);
45
47
  if (lastDockedRef.current === null) {
46
- const initial = CommentUtils.readStoredDockPosition();
47
- lastDockedRef.current = CommentUtils.isDockedPosition(initial)
48
- ? initial
49
- : 'right';
48
+ lastDockedRef.current = CommentUtils.readStoredLastDocked();
50
49
  }
51
50
  const load = async () => {
52
51
  try {
@@ -70,22 +69,21 @@ export default function Comments({ uid, keywords, references, mode, onClose, onC
70
69
  popupPollRef.current = null;
71
70
  }
72
71
  }, []);
73
- const redockFromPopup = useCallback(() => {
72
+ const handlePopupClosed = useCallback(() => {
74
73
  clearPopupPoll();
75
74
  popupRef.current = null;
76
75
  setExternalContainer(null);
77
76
  if (ignorePopupCloseRef.current) {
78
77
  ignorePopupCloseRef.current = false;
78
+ popupCloseHandledRef.current = true;
79
79
  return;
80
80
  }
81
- setDockPosition((prev) => {
82
- if (prev !== 'undocked')
83
- return prev;
84
- const next = lastDockedRef.current ?? 'right';
85
- CommentUtils.persistDockPosition(next);
86
- return next;
87
- });
88
- }, [clearPopupPoll]);
81
+ if (popupCloseHandledRef.current)
82
+ return;
83
+ popupCloseHandledRef.current = true;
84
+ // Do not redock keep undocked so the main Drawer stays closed.
85
+ onClose();
86
+ }, [clearPopupPoll, onClose]);
89
87
  const closePopup = useCallback(() => {
90
88
  clearPopupPoll();
91
89
  const popup = popupRef.current;
@@ -105,6 +103,7 @@ export default function Comments({ uid, keywords, references, mode, onClose, onC
105
103
  if (existing && !existing.closed) {
106
104
  existing.focus();
107
105
  setDockPosition('undocked');
106
+ CommentUtils.persistDockPosition('undocked');
108
107
  return;
109
108
  }
110
109
  const opened = CommentUtils.openCommentsPopup();
@@ -112,22 +111,25 @@ export default function Comments({ uid, keywords, references, mode, onClose, onC
112
111
  return;
113
112
  const { popup, container } = opened;
114
113
  ignorePopupCloseRef.current = false;
114
+ popupCloseHandledRef.current = false;
115
115
  popupRef.current = popup;
116
116
  setExternalContainer(container);
117
117
  setDockPosition('undocked');
118
+ CommentUtils.persistDockPosition('undocked');
118
119
  popup.addEventListener('beforeunload', () => {
119
- redockFromPopup();
120
+ handlePopupClosed();
120
121
  });
121
122
  clearPopupPoll();
122
123
  popupPollRef.current = window.setInterval(() => {
123
124
  if (!popupRef.current || popupRef.current.closed) {
124
- redockFromPopup();
125
+ handlePopupClosed();
125
126
  }
126
127
  }, 500);
127
- }, [clearPopupPoll, redockFromPopup]);
128
+ }, [clearPopupPoll, handlePopupClosed]);
128
129
  const setDockedPosition = useCallback((position) => {
129
130
  lastDockedRef.current = position;
130
131
  CommentUtils.persistDockPosition(position);
132
+ CommentUtils.persistLastDocked(position);
131
133
  closePopup();
132
134
  setDockPosition(position);
133
135
  }, [closePopup]);
@@ -176,6 +178,14 @@ export default function Comments({ uid, keywords, references, mode, onClose, onC
176
178
  useEffect(() => {
177
179
  load();
178
180
  }, []);
181
+ useEffect(() => {
182
+ if (restoredUndockRef.current)
183
+ return;
184
+ if (CommentUtils.readStoredDockPosition() !== 'undocked')
185
+ return;
186
+ restoredUndockRef.current = true;
187
+ openUndockedWindow();
188
+ }, [openUndockedWindow]);
179
189
  useEffect(() => {
180
190
  if (!openAddComment || !comments)
181
191
  return;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "tycho-components",
3
3
  "private": false,
4
- "version": "0.41.1",
4
+ "version": "0.41.2",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
7
7
  "exports": {