@linzjs/windows 8.8.1 → 8.9.0

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.
@@ -0,0 +1,34 @@
1
+ @use "@linzjs/lui/dist/scss/Core" as lui;
2
+
3
+ .CopyToClipboard {
4
+ cursor: pointer;
5
+ }
6
+
7
+ .windows_tooltip {
8
+ position: relative;
9
+ cursor: pointer;
10
+
11
+ .windows_tooltiptext {
12
+ opacity: 0;
13
+ transition: opacity 0.3s ease, width 0.3s ease;
14
+ pointer-events: none;
15
+ background-color: white;
16
+ color: rgb(46 52 56);
17
+ text-align: left;
18
+ padding: 4px 8px;
19
+ position: absolute;
20
+ z-index: 1;
21
+ line-height: 18px;
22
+ font-size: 13px;
23
+ overflow: hidden;
24
+
25
+ left: calc(100% + 8px);
26
+ transform: translateY(42%);
27
+ box-shadow: 0 2px 3px #00000040, 0 0 3px #00000026;
28
+ }
29
+
30
+ &:hover .windows_tooltiptext {
31
+ visibility: visible;
32
+ opacity: 1;
33
+ }
34
+ }
@@ -0,0 +1,57 @@
1
+ import './CopyableText.scss';
2
+
3
+ import clsx from 'clsx';
4
+ import { CSSProperties, ReactElement, useEffect, useRef, useState } from 'react';
5
+
6
+ export interface CopyableTextProps {
7
+ dataTestId?: string;
8
+ style?: CSSProperties;
9
+ className?: string;
10
+ text: string | number;
11
+ }
12
+
13
+ export const CopyableText = (props: CopyableTextProps): ReactElement => {
14
+ const [copied, setCopied] = useState(false);
15
+
16
+ const { dataTestId, style, className, text } = props;
17
+ const timeoutRefDisplay = useRef<ReturnType<typeof setTimeout> | null>(null);
18
+
19
+ const copy = () => {
20
+ window.navigator.clipboard.writeText(String(text)).then(
21
+ () => {
22
+ setCopied(true);
23
+ timeoutRefDisplay.current = setTimeout(() => void setCopied(false), 3000);
24
+ },
25
+ (err: Error) => {
26
+ alert(`Data copy failed: ${err.message}`);
27
+ },
28
+ );
29
+ };
30
+
31
+ useEffect(
32
+ () => () => {
33
+ if (timeoutRefDisplay.current) {
34
+ clearTimeout(timeoutRefDisplay.current);
35
+ timeoutRefDisplay.current = null;
36
+ }
37
+ },
38
+ [],
39
+ );
40
+
41
+ return (
42
+ <span
43
+ data-testid={dataTestId}
44
+ style={style}
45
+ className={clsx('windows_tooltip', className)}
46
+ onClick={(event) => {
47
+ event.stopPropagation();
48
+ copy();
49
+ }}
50
+ >
51
+ <span className="windows_tooltiptext" style={{ width: copied ? '62px' : '47px' }}>
52
+ {copied ? 'Copied!' : 'Copy'}
53
+ </span>
54
+ {text}
55
+ </span>
56
+ );
57
+ };
@@ -0,0 +1 @@
1
+ export * from './CopyableText';
@@ -51,24 +51,28 @@ export const PanelsContextProvider = ({
51
51
 
52
52
  const bringPanelToFront = useCallback(
53
53
  (panelUniqueId: string) => {
54
- const panelInstance = panelInstances.find((panelInstance) => panelInstance.uniqueId === panelUniqueId);
55
- if (!panelInstance) {
56
- console.warn(`bringPanelToFront cannot find panel with uniqueId: ${panelUniqueId}`);
57
- return;
58
- }
59
- if (panelInstance.window) {
60
- panelInstance.window.focus();
61
- } else {
54
+ setPanelInstances((panelInstances): PanelInstance[] => {
55
+ const panelInstance = panelInstances.find((panelInstance) => panelInstance.uniqueId === panelUniqueId);
56
+ if (!panelInstance) {
57
+ console.warn(`bringPanelToFront cannot find panel with uniqueId: ${panelUniqueId}`);
58
+ return panelInstances;
59
+ }
60
+ if (panelInstance.window) {
61
+ panelInstance.window.focus();
62
+ return panelInstances;
63
+ }
62
64
  const maxZIndexPanelInstance = maxBy(panelInstances, 'zIndex');
63
65
  // Prevent unnecessary state updates
64
- if (maxZIndexPanelInstance === panelInstance) return;
66
+ if (maxZIndexPanelInstance === panelInstance) {
67
+ return panelInstances;
68
+ }
65
69
  sortBy(panelInstances, (pi) => (panelInstance === pi ? 32768 : pi.zIndex)).forEach(
66
70
  (pi, i) => (pi.zIndex = baseZIndex + i),
67
71
  );
68
- setPanelInstances([...panelInstances]);
69
- }
72
+ return [...panelInstances];
73
+ });
70
74
  },
71
- [baseZIndex, panelInstances],
75
+ [baseZIndex],
72
76
  );
73
77
 
74
78
  const showHidePanel = useCallback((hidePanelIds: string | string[], hidden: boolean) => {
@@ -104,39 +108,40 @@ export const PanelsContextProvider = ({
104
108
  const openPanel = useCallback(
105
109
  ({ componentFn, poppedOut = false, uniqueId = v4(), onClose }: OpenPanelOptions): string | null => {
106
110
  try {
107
- const existingPanelInstance = panelInstances.find((pi) => pi.uniqueId === uniqueId);
108
- if (existingPanelInstance) {
109
- if (existingPanelInstance.window) {
110
- existingPanelInstance.window?.focus();
111
- } else {
112
- if (existingPanelInstance.hidden) {
113
- unhidePanel(uniqueId);
111
+ setPanelInstances((panelInstances) => {
112
+ const existingPanelInstance = panelInstances.find((pi) => pi.uniqueId === uniqueId);
113
+ if (existingPanelInstance) {
114
+ if (existingPanelInstance.window) {
115
+ existingPanelInstance.window?.focus();
116
+ } else {
117
+ if (existingPanelInstance.hidden) {
118
+ setTimeout(() => unhidePanel(uniqueId), 0);
119
+ }
120
+ setTimeout(() => bringPanelToFront(uniqueId), 0);
114
121
  }
115
- bringPanelToFront(uniqueId);
122
+ return panelInstances;
116
123
  }
117
- return existingPanelInstance.uniqueId;
118
- }
119
124
 
120
- // If there are any exceptions the modal won't show
121
- setPanelInstances([
122
- ...panelInstances,
123
- {
124
- uniqueId,
125
- componentInstance: componentFn(),
126
- zIndex: baseZIndex + panelInstances.length,
127
- poppedOut,
128
- window: null,
129
- onClose,
130
- hidden: false,
131
- },
132
- ]);
125
+ return [
126
+ ...panelInstances,
127
+ {
128
+ uniqueId,
129
+ componentInstance: componentFn(),
130
+ zIndex: baseZIndex + panelInstances.length,
131
+ poppedOut,
132
+ window: null,
133
+ onClose,
134
+ hidden: false,
135
+ },
136
+ ];
137
+ });
133
138
  return uniqueId;
134
139
  } catch (e) {
135
140
  console.error(e);
136
141
  return null;
137
142
  }
138
143
  },
139
- [baseZIndex, bringPanelToFront, panelInstances, unhidePanel],
144
+ [baseZIndex, bringPanelToFront, unhidePanel],
140
145
  );
141
146
 
142
147
  const closePanel = useCallback((closePanelUniqueIds: string | string[]) => {
package/package.json CHANGED
@@ -13,7 +13,7 @@
13
13
  "popout"
14
14
  ],
15
15
  "main": "./dist/index.ts",
16
- "version": "8.8.1",
16
+ "version": "8.9.0",
17
17
  "peerDependencies": {
18
18
  "@linzjs/lui": ">=23",
19
19
  "lodash-es": ">=4",