@visns-studio/visns-components 6.16.3 → 6.16.4

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/package.json CHANGED
@@ -95,7 +95,7 @@
95
95
  "react-dom": "^17.0.0 || ^18.0.0 || ^19.0.0"
96
96
  },
97
97
  "name": "@visns-studio/visns-components",
98
- "version": "6.16.3",
98
+ "version": "6.16.4",
99
99
  "description": "Various packages to assist in the development of our Custom Applications.",
100
100
  "main": "src/index.js",
101
101
  "files": [
@@ -2883,11 +2883,7 @@ const DataGrid = forwardRef(
2883
2883
  rowProps.columns[columnIndex].link.key;
2884
2884
  const rowData = rowProps.data[linkKey];
2885
2885
 
2886
- window.open(
2887
- `${linkPopup}/${rowData}`,
2888
- '',
2889
- 'width=1440,height=1024,menubar=1,resizable=1,status=1,titlebar=1,toolbar=1'
2890
- );
2886
+ openRecordWindow(`${linkPopup}/${rowData}`);
2891
2887
  } else {
2892
2888
  debugLog('🔍 Checking for update setting:', {
2893
2889
  settings: settingsRef.current,
@@ -1,4 +1,5 @@
1
1
  import React, { useCallback, useEffect, useMemo, useRef, useState } from 'react';
2
+ import { openRecordWindow } from '../utils/popupWindow';
2
3
  import { Link } from 'react-router-dom';
3
4
  import {
4
5
  ChevronDown,
@@ -1061,11 +1062,7 @@ const CallQueuePop = ({
1061
1062
  return;
1062
1063
  }
1063
1064
 
1064
- window.open(
1065
- hrefForTask(task),
1066
- '',
1067
- 'width=1440,height=1024,menubar=1,resizable=1,status=1,titlebar=1,toolbar=1'
1068
- );
1065
+ openRecordWindow(hrefForTask(task));
1069
1066
  };
1070
1067
 
1071
1068
  /**
@@ -1,4 +1,5 @@
1
1
  import { useNavigate } from 'react-router-dom';
2
+ import { openRecordWindow } from '../utils/popupWindow';
2
3
  import { toast } from 'react-toastify';
3
4
  import { saveAs } from 'file-saver';
4
5
  import {
@@ -172,11 +173,7 @@ const DataGridSearch = ({
172
173
  }
173
174
  } else {
174
175
  if (form.url) {
175
- window.open(
176
- form.url,
177
- '',
178
- 'width=1440,height=1024,menubar=1,resizable=1,status=1,titlebar=1,toolbar=1'
179
- );
176
+ openRecordWindow(form.url);
180
177
  }
181
178
  }
182
179
  }}
@@ -194,11 +191,7 @@ const DataGridSearch = ({
194
191
  onClick={(e) => {
195
192
  e.preventDefault();
196
193
 
197
- window.open(
198
- form.url,
199
- '',
200
- 'width=1440,height=1024,menubar=1,resizable=1,status=1,titlebar=1,toolbar=1'
201
- );
194
+ openRecordWindow(form.url);
202
195
  }}
203
196
  >
204
197
  <Plus
@@ -0,0 +1,44 @@
1
+ /**
2
+ * One geometry for every record window the grid opens.
3
+ *
4
+ * The grid used to hard-code 1440×1024, which on a 1080p monitor left a
5
+ * third of the screen unused and on a laptop spilled off it. A record window
6
+ * now takes the whole available screen (inset 12px), on whichever monitor the
7
+ * browser is on, and is named so a second click raises the one already open
8
+ * instead of stacking another.
9
+ */
10
+ export const FEATURE_FLAGS = 'menubar=1,resizable=1,status=1,titlebar=1,toolbar=1';
11
+
12
+ export const popupFeatures = () => {
13
+ if (typeof window === 'undefined' || !window.screen) {
14
+ return `width=1440,height=1024,${FEATURE_FLAGS}`;
15
+ }
16
+
17
+ const { availWidth, availHeight, availLeft = 0, availTop = 0 } = window.screen;
18
+ const width = Math.max(960, (availWidth || 1440) - 24);
19
+ const height = Math.max(640, (availHeight || 1024) - 24);
20
+
21
+ return `width=${width},height=${height},left=${availLeft + 12},top=${availTop + 12},${FEATURE_FLAGS}`;
22
+ };
23
+
24
+ export const popupName = (url) =>
25
+ String(url || '')
26
+ .replace(/^https?:\/\/[^/]+/, '')
27
+ .replace(/[^a-z0-9]+/gi, '-')
28
+ .replace(/^-+|-+$/g, '') || 'record';
29
+
30
+ export const openRecordWindow = (url, name = popupName(url)) => {
31
+ if (typeof window === 'undefined') return null;
32
+
33
+ const popup = window.open(url, name, popupFeatures());
34
+
35
+ try {
36
+ popup?.focus();
37
+ } catch (error) {
38
+ // A blocked popup returns null; nothing to focus.
39
+ }
40
+
41
+ return popup;
42
+ };
43
+
44
+ export default openRecordWindow;