@linzjs/windows 10.3.1 → 11.0.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.
Files changed (223) hide show
  1. package/dist/LuiModalAsync/LuiModalAsync.d.ts +14 -0
  2. package/dist/LuiModalAsync/LuiModalAsync.js +45 -0
  3. package/dist/LuiModalAsync/LuiModalAsync.js.map +1 -0
  4. package/dist/LuiModalAsync/LuiModalAsync.scss +1 -2
  5. package/dist/LuiModalAsync/LuiModalAsyncButtonGroup.d.ts +19 -0
  6. package/dist/LuiModalAsync/LuiModalAsyncButtonGroup.js +27 -0
  7. package/dist/LuiModalAsync/LuiModalAsyncButtonGroup.js.map +1 -0
  8. package/dist/LuiModalAsync/LuiModalAsyncContent.d.ts +6 -0
  9. package/dist/LuiModalAsync/LuiModalAsyncContent.js +7 -0
  10. package/dist/LuiModalAsync/LuiModalAsyncContent.js.map +1 -0
  11. package/dist/LuiModalAsync/LuiModalAsyncContext.d.ts +28 -0
  12. package/dist/LuiModalAsync/LuiModalAsyncContext.js +9 -0
  13. package/dist/LuiModalAsync/LuiModalAsyncContext.js.map +1 -0
  14. package/dist/LuiModalAsync/LuiModalAsyncContextProvider.d.ts +54 -0
  15. package/dist/LuiModalAsync/LuiModalAsyncContextProvider.js +160 -0
  16. package/dist/LuiModalAsync/LuiModalAsyncContextProvider.js.map +1 -0
  17. package/dist/LuiModalAsync/LuiModalAsyncHeader.d.ts +15 -0
  18. package/dist/LuiModalAsync/LuiModalAsyncHeader.js +23 -0
  19. package/dist/LuiModalAsync/LuiModalAsyncHeader.js.map +1 -0
  20. package/dist/LuiModalAsync/LuiModalAsyncInstanceContext.d.ts +13 -0
  21. package/dist/LuiModalAsync/LuiModalAsyncInstanceContext.js +13 -0
  22. package/dist/LuiModalAsync/LuiModalAsyncInstanceContext.js.map +1 -0
  23. package/dist/LuiModalAsync/LuiModalAsyncMain.d.ts +5 -0
  24. package/dist/LuiModalAsync/LuiModalAsyncMain.js +6 -0
  25. package/dist/LuiModalAsync/LuiModalAsyncMain.js.map +1 -0
  26. package/dist/LuiModalAsync/index.js +12 -0
  27. package/dist/LuiModalAsync/index.js.map +1 -0
  28. package/dist/LuiModalAsync/useLuiModalPrefab.d.ts +56 -0
  29. package/dist/LuiModalAsync/useLuiModalPrefab.js +118 -0
  30. package/dist/LuiModalAsync/useLuiModalPrefab.js.map +1 -0
  31. package/dist/LuiModalAsync/useLuiModalUpload.d.ts +16 -0
  32. package/dist/LuiModalAsync/useLuiModalUpload.js +34 -0
  33. package/dist/LuiModalAsync/useLuiModalUpload.js.map +1 -0
  34. package/dist/LuiModalAsync/useShowAsyncModal.d.ts +6 -0
  35. package/dist/LuiModalAsync/useShowAsyncModal.js +13 -0
  36. package/dist/LuiModalAsync/useShowAsyncModal.js.map +1 -0
  37. package/dist/common/debug.d.ts +1 -0
  38. package/dist/common/debug.js +11 -0
  39. package/dist/common/debug.js.map +1 -0
  40. package/dist/common/index.js +3 -0
  41. package/dist/common/index.js.map +1 -0
  42. package/dist/common/useConstFunction.d.ts +5 -0
  43. package/dist/common/useConstFunction.js +17 -0
  44. package/dist/common/useConstFunction.js.map +1 -0
  45. package/dist/common/useInterval.d.ts +17 -0
  46. package/dist/common/{useInterval.ts → useInterval.js} +21 -25
  47. package/dist/common/useInterval.js.map +1 -0
  48. package/dist/common/useIsomorphicLayoutEffect.d.ts +17 -0
  49. package/dist/common/{useIsomorphicLayoutEffect.ts → useIsomorphicLayoutEffect.js} +1 -1
  50. package/dist/common/useIsomorphicLayoutEffect.js.map +1 -0
  51. package/dist/common/util.d.ts +3 -0
  52. package/dist/common/util.js +25 -0
  53. package/dist/common/util.js.map +1 -0
  54. package/dist/common/uuid.d.ts +1 -0
  55. package/dist/common/{uuid.ts → uuid.js} +1 -1
  56. package/dist/common/uuid.js.map +1 -0
  57. package/dist/components/CopyableText.d.ts +9 -0
  58. package/dist/components/CopyableText.js +29 -0
  59. package/dist/components/CopyableText.js.map +1 -0
  60. package/dist/components/index.js +2 -0
  61. package/dist/components/index.js.map +1 -0
  62. package/dist/index.js +7 -0
  63. package/dist/index.js.map +1 -0
  64. package/dist/panel/OpenPanelButton.d.ts +8 -0
  65. package/dist/panel/OpenPanelButton.js +11 -0
  66. package/dist/panel/OpenPanelButton.js.map +1 -0
  67. package/dist/panel/Panel.d.ts +10 -0
  68. package/dist/panel/Panel.js +122 -0
  69. package/dist/panel/Panel.js.map +1 -0
  70. package/dist/panel/PanelContext.d.ts +10 -0
  71. package/dist/panel/PanelContext.js +13 -0
  72. package/dist/panel/PanelContext.js.map +1 -0
  73. package/dist/panel/PanelDock.d.ts +5 -0
  74. package/dist/panel/PanelDock.js +9 -0
  75. package/dist/panel/PanelDock.js.map +1 -0
  76. package/dist/panel/PanelHeader.d.ts +15 -0
  77. package/dist/panel/PanelHeader.js +33 -0
  78. package/dist/panel/PanelHeader.js.map +1 -0
  79. package/dist/panel/PanelHeaderButton.d.ts +8 -0
  80. package/dist/panel/PanelHeaderButton.js +16 -0
  81. package/dist/panel/PanelHeaderButton.js.map +1 -0
  82. package/dist/panel/PanelInline.d.ts +10 -0
  83. package/dist/panel/PanelInline.js +26 -0
  84. package/dist/panel/PanelInline.js.map +1 -0
  85. package/dist/panel/PanelInstanceContext.d.ts +21 -0
  86. package/dist/panel/PanelInstanceContext.js +25 -0
  87. package/dist/panel/PanelInstanceContext.js.map +1 -0
  88. package/dist/panel/PanelInstanceContextProvider.d.ts +11 -0
  89. package/dist/panel/PanelInstanceContextProvider.js +50 -0
  90. package/dist/panel/PanelInstanceContextProvider.js.map +1 -0
  91. package/dist/panel/PanelsContext.d.ts +33 -0
  92. package/dist/panel/PanelsContext.js +19 -0
  93. package/dist/panel/PanelsContext.js.map +1 -0
  94. package/dist/panel/PanelsContextProvider.d.ts +12 -0
  95. package/dist/panel/PanelsContextProvider.js +145 -0
  96. package/dist/panel/PanelsContextProvider.js.map +1 -0
  97. package/dist/panel/PopinWIndow.d.ts +11 -0
  98. package/dist/panel/PopinWIndow.js +74 -0
  99. package/dist/panel/PopinWIndow.js.map +1 -0
  100. package/dist/panel/PopoutWindow.d.ts +17 -0
  101. package/dist/panel/PopoutWindow.js +72 -0
  102. package/dist/panel/PopoutWindow.js.map +1 -0
  103. package/dist/panel/generateId.d.ts +6 -0
  104. package/dist/panel/{generateId.ts → generateId.js} +3 -4
  105. package/dist/panel/generateId.js.map +1 -0
  106. package/dist/panel/handleStyleSheetsChanges.d.ts +9 -0
  107. package/dist/panel/handleStyleSheetsChanges.js +65 -0
  108. package/dist/panel/handleStyleSheetsChanges.js.map +1 -0
  109. package/dist/panel/index.js +13 -0
  110. package/dist/panel/index.js.map +1 -0
  111. package/dist/panel/openExternalWindow.d.ts +23 -0
  112. package/dist/panel/openExternalWindow.js +62 -0
  113. package/dist/panel/openExternalWindow.js.map +1 -0
  114. package/dist/panel/types/{PanelPosition.ts → PanelPosition.d.ts} +2 -2
  115. package/dist/panel/types/PanelPosition.js +2 -0
  116. package/dist/panel/types/PanelPosition.js.map +1 -0
  117. package/dist/panel/types/PanelProps.d.ts +19 -0
  118. package/dist/panel/types/PanelProps.js +2 -0
  119. package/dist/panel/types/PanelProps.js.map +1 -0
  120. package/dist/panel/types/{PanelRestoredState.ts → PanelRestoredState.d.ts} +3 -4
  121. package/dist/panel/types/PanelRestoredState.js +2 -0
  122. package/dist/panel/types/PanelRestoredState.js.map +1 -0
  123. package/dist/panel/types/PanelSize.d.ts +8 -0
  124. package/dist/panel/types/PanelSize.js +2 -0
  125. package/dist/panel/types/PanelSize.js.map +1 -0
  126. package/dist/panel/types/{PanelState.ts → PanelState.d.ts} +5 -8
  127. package/dist/panel/types/PanelState.js +2 -0
  128. package/dist/panel/types/PanelState.js.map +1 -0
  129. package/dist/panel/types/{PanelStateOptions.ts → PanelStateOptions.d.ts} +4 -6
  130. package/dist/panel/types/PanelStateOptions.js +2 -0
  131. package/dist/panel/types/PanelStateOptions.js.map +1 -0
  132. package/dist/panel/types/index.js +7 -0
  133. package/dist/panel/types/index.js.map +1 -0
  134. package/dist/panel/usePanelStateHandler.d.ts +8 -0
  135. package/dist/panel/usePanelStateHandler.js +81 -0
  136. package/dist/panel/usePanelStateHandler.js.map +1 -0
  137. package/dist/ribbon/RibbonButton.d.ts +21 -0
  138. package/dist/ribbon/RibbonButton.js +28 -0
  139. package/dist/ribbon/RibbonButton.js.map +1 -0
  140. package/dist/ribbon/RibbonButtonLink.d.ts +12 -0
  141. package/dist/ribbon/RibbonButtonLink.js +11 -0
  142. package/dist/ribbon/RibbonButtonLink.js.map +1 -0
  143. package/dist/ribbon/RibbonButtonOpenPanel.d.ts +5 -0
  144. package/dist/ribbon/RibbonButtonOpenPanel.js +11 -0
  145. package/dist/ribbon/RibbonButtonOpenPanel.js.map +1 -0
  146. package/dist/ribbon/RibbonButtonSlider.d.ts +11 -0
  147. package/dist/ribbon/RibbonButtonSlider.js +28 -0
  148. package/dist/ribbon/RibbonButtonSlider.js.map +1 -0
  149. package/dist/ribbon/RibbonButtonSliderContext.d.ts +25 -0
  150. package/dist/ribbon/RibbonButtonSliderContext.js +25 -0
  151. package/dist/ribbon/RibbonButtonSliderContext.js.map +1 -0
  152. package/dist/ribbon/RibbonContainer.d.ts +10 -0
  153. package/dist/ribbon/RibbonContainer.js +7 -0
  154. package/dist/ribbon/RibbonContainer.js.map +1 -0
  155. package/dist/ribbon/RibbonDeprecated.d.ts +10 -0
  156. package/dist/ribbon/RibbonDeprecated.js +13 -0
  157. package/dist/ribbon/RibbonDeprecated.js.map +1 -0
  158. package/dist/ribbon/RibbonMenu.d.ts +7 -0
  159. package/dist/ribbon/RibbonMenu.js +12 -0
  160. package/dist/ribbon/RibbonMenu.js.map +1 -0
  161. package/dist/ribbon/RibbonMenuOption.d.ts +17 -0
  162. package/dist/ribbon/RibbonMenuOption.js +26 -0
  163. package/dist/ribbon/RibbonMenuOption.js.map +1 -0
  164. package/dist/ribbon/RibbonMenuSeparator.d.ts +2 -0
  165. package/dist/ribbon/RibbonMenuSeparator.js +6 -0
  166. package/dist/ribbon/RibbonMenuSeparator.js.map +1 -0
  167. package/dist/ribbon/RibbonSeparator.d.ts +2 -0
  168. package/dist/ribbon/RibbonSeparator.js +4 -0
  169. package/dist/ribbon/RibbonSeparator.js.map +1 -0
  170. package/dist/ribbon/index.js +12 -0
  171. package/dist/ribbon/index.js.map +1 -0
  172. package/package.json +15 -8
  173. package/dist/LuiModalAsync/LuiModalAsync.tsx +0 -82
  174. package/dist/LuiModalAsync/LuiModalAsyncButtonGroup.tsx +0 -55
  175. package/dist/LuiModalAsync/LuiModalAsyncContent.tsx +0 -9
  176. package/dist/LuiModalAsync/LuiModalAsyncContext.tsx +0 -52
  177. package/dist/LuiModalAsync/LuiModalAsyncContextProvider.tsx +0 -223
  178. package/dist/LuiModalAsync/LuiModalAsyncHeader.tsx +0 -67
  179. package/dist/LuiModalAsync/LuiModalAsyncInstanceContext.ts +0 -24
  180. package/dist/LuiModalAsync/LuiModalAsyncMain.tsx +0 -8
  181. package/dist/LuiModalAsync/useLuiModalPrefab.tsx +0 -227
  182. package/dist/LuiModalAsync/useLuiModalUpload.tsx +0 -79
  183. package/dist/LuiModalAsync/useShowAsyncModal.ts +0 -34
  184. package/dist/common/debug.ts +0 -9
  185. package/dist/common/useConstFunction.ts +0 -22
  186. package/dist/common/util.ts +0 -31
  187. package/dist/components/CopyableText.tsx +0 -58
  188. package/dist/panel/OpenPanelButton.tsx +0 -52
  189. package/dist/panel/Panel.tsx +0 -211
  190. package/dist/panel/PanelContext.ts +0 -22
  191. package/dist/panel/PanelDock.tsx +0 -20
  192. package/dist/panel/PanelHeader.tsx +0 -105
  193. package/dist/panel/PanelHeaderButton.tsx +0 -26
  194. package/dist/panel/PanelInline.tsx +0 -46
  195. package/dist/panel/PanelInstanceContext.ts +0 -44
  196. package/dist/panel/PanelInstanceContextProvider.tsx +0 -75
  197. package/dist/panel/PanelsContext.tsx +0 -56
  198. package/dist/panel/PanelsContextProvider.tsx +0 -220
  199. package/dist/panel/PopinWIndow.tsx +0 -147
  200. package/dist/panel/PopoutWindow.tsx +0 -117
  201. package/dist/panel/handleStyleSheetsChanges.ts +0 -71
  202. package/dist/panel/openExternalWindow.ts +0 -98
  203. package/dist/panel/types/PanelProps.ts +0 -22
  204. package/dist/panel/types/PanelSize.ts +0 -9
  205. package/dist/panel/usePanelStateHandler.tsx +0 -102
  206. package/dist/ribbon/RibbonButton.tsx +0 -112
  207. package/dist/ribbon/RibbonButtonLink.tsx +0 -27
  208. package/dist/ribbon/RibbonButtonOpenPanel.tsx +0 -23
  209. package/dist/ribbon/RibbonButtonSlider.tsx +0 -66
  210. package/dist/ribbon/RibbonButtonSliderContext.tsx +0 -34
  211. package/dist/ribbon/RibbonContainer.tsx +0 -19
  212. package/dist/ribbon/RibbonDeprecated.tsx +0 -27
  213. package/dist/ribbon/RibbonMenu.tsx +0 -25
  214. package/dist/ribbon/RibbonMenuOption.tsx +0 -67
  215. package/dist/ribbon/RibbonMenuSeparator.tsx +0 -5
  216. package/dist/ribbon/RibbonSeparator.tsx +0 -3
  217. /package/dist/LuiModalAsync/{index.ts → index.d.ts} +0 -0
  218. /package/dist/common/{index.ts → index.d.ts} +0 -0
  219. /package/dist/components/{index.ts → index.d.ts} +0 -0
  220. /package/dist/{index.ts → index.d.ts} +0 -0
  221. /package/dist/panel/{index.ts → index.d.ts} +0 -0
  222. /package/dist/panel/types/{index.ts → index.d.ts} +0 -0
  223. /package/dist/ribbon/{index.ts → index.d.ts} +0 -0
@@ -1,211 +0,0 @@
1
- import '../index.scss';
2
-
3
- import clsx from 'clsx';
4
- import { isEqual, pick } from 'lodash-es';
5
- import {
6
- forwardRef,
7
- PropsWithChildren,
8
- ReactElement,
9
- useCallback,
10
- useContext,
11
- useEffect,
12
- useRef,
13
- useState,
14
- } from 'react';
15
- import { createPortal } from 'react-dom';
16
-
17
- import { PanelInstanceContext } from './PanelInstanceContext';
18
- import { PanelsContext } from './PanelsContext';
19
- import { PopinWindow } from './PopinWIndow';
20
- import { PopoutWindow } from './PopoutWindow';
21
- import { PanelPosition } from './types/PanelPosition';
22
- import { PanelProps } from './types/PanelProps';
23
- import { PanelSize } from './types/PanelSize';
24
- import { useRestoreStateFrom } from './usePanelStateHandler';
25
- import { useInterval } from '../common/useInterval';
26
-
27
- const defaultInitialSize = { width: 320, height: 200 };
28
-
29
- export const Panel = (props: PanelProps): ReactElement => {
30
- const panelRef = useRef<HTMLDivElement>(null);
31
- const { title, size = defaultInitialSize, className, dynamicBounds, children } = props;
32
-
33
- const { dockElements, nextStackPosition } = useContext(PanelsContext);
34
- const { panelPoppedOut, uniqueId, setTitle, dockId, docked, hidden } = useContext(PanelInstanceContext);
35
-
36
- const savedState = useRestoreStateFrom({ uniqueId, panelPoppedOut: false });
37
-
38
- const lastPanelHeightRef = useRef(panelRef.current?.clientHeight);
39
- lastPanelHeightRef.current = panelRef.current?.clientHeight ?? lastPanelHeightRef.current ?? 400;
40
-
41
- useEffect(() => {
42
- setTitle(title);
43
- }, [setTitle, title]);
44
-
45
- // We only want to update the title when it changes
46
- useEffect(() => {
47
- if (panelRef.current) {
48
- const doc = panelRef.current.ownerDocument;
49
- if (doc) {
50
- doc.title = title;
51
- }
52
- }
53
- }, [title]);
54
-
55
- const [panelPosition, setPanelPosition] = useState((): PanelPosition => {
56
- if (dynamicBounds) {
57
- const result = dynamicBounds();
58
- if (result) {
59
- return pick(result, ['x', 'y']);
60
- }
61
- }
62
-
63
- const pos = props.position;
64
- if (props.resizeable !== false && savedState?.panelPosition) {
65
- return savedState.panelPosition;
66
- }
67
-
68
- if (pos === 'center') {
69
- const height = size.height === 'auto' ? 400 : size.height;
70
- return {
71
- x: Math.max((window.innerWidth - size.width) / 2, 0),
72
- y: Math.max((window.innerHeight - height) / 2, 0),
73
- };
74
- }
75
-
76
- if (pos != null && pos !== 'tile') {
77
- return pos;
78
- }
79
-
80
- return nextStackPosition();
81
- });
82
-
83
- const cropSizeToWindow = useCallback((size: PanelSize): PanelSize => {
84
- return typeof window !== 'undefined' && window.innerWidth && window.innerHeight
85
- ? {
86
- width: Math.min(window.document.body?.clientWidth ?? window.innerWidth, size.width),
87
- height:
88
- size.height === 'auto'
89
- ? 'auto'
90
- : Math.min(window.document.body?.clientHeight ?? window.innerHeight, size.height),
91
- }
92
- : size;
93
- }, []);
94
-
95
- const [panelSize, _setPanelSize] = useState<PanelSize>(() => {
96
- const result = dynamicBounds?.();
97
- if (result) {
98
- return pick(result, ['width', 'height']);
99
- }
100
-
101
- if (props.resizeable !== false && savedState?.panelSize) {
102
- return cropSizeToWindow(savedState.panelSize);
103
- }
104
-
105
- return size ?? { width: 320, height: 200 };
106
- });
107
-
108
- const setPanelSize = useCallback(
109
- (size: PanelSize) => {
110
- _setPanelSize(cropSizeToWindow(size));
111
- },
112
- [cropSizeToWindow],
113
- );
114
-
115
- const setInitialPanelSize = useCallback(
116
- (size: PanelSize) => {
117
- // If panel was already sized from state, then don't resize
118
- if (props.resizeable !== false && savedState?.panelSize) {
119
- return;
120
- }
121
-
122
- setPanelSize(size);
123
- },
124
- [props.resizeable, savedState?.panelSize, setPanelSize],
125
- );
126
-
127
- const dynamicResize = useCallback(() => {
128
- const bounds = dynamicBounds?.();
129
- if (!bounds) {
130
- return;
131
- }
132
- const newPosition = pick(bounds, ['x', 'y']);
133
- if (!isEqual(newPosition, panelPosition)) {
134
- setPanelPosition(newPosition);
135
- }
136
- const newSize = pick(bounds, ['width', 'height']);
137
- if (!isEqual(newSize, panelSize)) {
138
- setPanelSize(newSize);
139
- }
140
- }, [dynamicBounds, panelPosition, panelSize, setPanelSize]);
141
-
142
- useEffect(() => {
143
- window.addEventListener('resize', dynamicResize);
144
-
145
- return () => {
146
- window.removeEventListener('resize', dynamicResize);
147
- };
148
- }, [dynamicResize]);
149
-
150
- useInterval(dynamicResize, dynamicBounds ? 250 : null);
151
-
152
- const dockElement = docked && dockId && dockElements[dockId];
153
- return (
154
- <>
155
- {dockElement && dockElement.isConnected ? (
156
- createPortal(children, dockElement)
157
- ) : panelPoppedOut ? (
158
- <PopoutWindow
159
- name={uniqueId}
160
- title={title}
161
- size={{ width: size.width, height: lastPanelHeightRef.current }}
162
- popInPanelPosition={panelPosition}
163
- popInPanelSize={{
164
- width: panelSize.width,
165
- height: panelSize.height === 'auto' ? lastPanelHeightRef.current : panelSize.height,
166
- }}
167
- >
168
- <div
169
- ref={panelRef}
170
- style={{
171
- display: 'flex',
172
- flexDirection: 'column',
173
- width: '100%',
174
- height: '100%',
175
- }}
176
- className={className}
177
- >
178
- {children}
179
- </div>
180
- </PopoutWindow>
181
- ) : (
182
- <PopinWindow
183
- {...props}
184
- panelPosition={panelPosition}
185
- setPanelPosition={setPanelPosition}
186
- panelSize={panelSize}
187
- setPanelSize={setPanelSize}
188
- setInitialPanelSize={setInitialPanelSize}
189
- hidden={hidden}
190
- >
191
- {children}
192
- </PopinWindow>
193
- )}
194
- </>
195
- );
196
- };
197
-
198
- export interface PanelContentProps {
199
- className?: string | undefined;
200
- }
201
-
202
- export const PanelContent = forwardRef<HTMLDivElement, PropsWithChildren<PanelContentProps>>(function PanelContentFr(
203
- { children, className },
204
- ref,
205
- ) {
206
- return (
207
- <div className={clsx(`WindowPanel-content`, className)} ref={ref}>
208
- {children}
209
- </div>
210
- );
211
- });
@@ -1,22 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- import { PanelSize } from './types';
4
-
5
- export interface PanelContextType {
6
- resizePanel: (size: Partial<PanelSize>) => void;
7
- initialResizePanel: (size: Partial<PanelSize>) => void;
8
- resizeable: boolean;
9
- }
10
-
11
- const NoContextError = () => {
12
- console.error('Missing PanelContext Provider');
13
- };
14
-
15
- /**
16
- * Provides access to closing/popping panels
17
- */
18
- export const PanelContext = createContext<PanelContextType>({
19
- resizePanel: NoContextError,
20
- initialResizePanel: NoContextError,
21
- resizeable: true,
22
- });
@@ -1,20 +0,0 @@
1
- import { PropsWithChildren, ReactElement, useContext } from 'react';
2
-
3
- import { PanelsContext } from './PanelsContext';
4
-
5
- export interface PanelDockProps {
6
- id: string;
7
- }
8
-
9
- export const PanelDock = ({ id, children }: PropsWithChildren<PanelDockProps>): ReactElement => {
10
- const { setDockElement } = useContext(PanelsContext);
11
-
12
- const setElement = (element: HTMLDivElement) => setDockElement(id, element);
13
-
14
- return (
15
- <div className={'panelDock'}>
16
- <div ref={setElement} className={'panelDock-content'} />
17
- <div className={'panelDock-empty'}>{children}</div>
18
- </div>
19
- );
20
- };
@@ -1,105 +0,0 @@
1
- import { LuiIcon } from '@linzjs/lui';
2
- import { LuiIconName } from '@linzjs/lui/dist/assets/svg-content';
3
- import clsx from 'clsx';
4
- import { ReactElement, useContext, useState } from 'react';
5
-
6
- import { PanelContext } from './PanelContext';
7
- import { PanelHeaderButton } from './PanelHeaderButton';
8
- import { PanelInstanceContext } from './PanelInstanceContext';
9
-
10
- export interface PanelHeaderProps {
11
- icon?: LuiIconName;
12
- extraLeft?: ReactElement;
13
- extraRight?: ReactElement;
14
- helpUrl?: string;
15
- onHelpClick?: () => void;
16
- onDockClick?: () => void;
17
- // Popped out windows are native so will not fire this, if you use this make the panel non popout!
18
- // Return true to close the panel, otherwise false to keep it open.
19
- onCloseClickPoppedInPanelOnly?: () => Promise<boolean> | boolean;
20
- dockTo?: string;
21
- disableClose?: boolean;
22
- disablePopout?: boolean;
23
- }
24
-
25
- export const PanelHeader = ({
26
- icon,
27
- extraLeft,
28
- extraRight,
29
- helpUrl,
30
- onHelpClick,
31
- onDockClick,
32
- onCloseClickPoppedInPanelOnly,
33
- dockTo,
34
- disableClose,
35
- disablePopout,
36
- }: PanelHeaderProps) => {
37
- const { resizeable } = useContext(PanelContext);
38
- const { panelClose, panelTogglePopout, panelPoppedOut, title, dock, undock, docked } =
39
- useContext(PanelInstanceContext);
40
- const [cursor, setCursor] = useState<'grab' | 'grabbing'>('grab');
41
-
42
- const headerMouseDown = () => {
43
- if (!panelPoppedOut) {
44
- setCursor('grabbing');
45
- }
46
- };
47
-
48
- return (
49
- <div
50
- className={clsx('WindowPanel-header', resizeable && 'draggable-handle')}
51
- onMouseDown={headerMouseDown}
52
- onMouseUp={() => !panelPoppedOut && setCursor('grab')}
53
- style={resizeable ? { cursor } : {}}
54
- >
55
- <div className={'WindowPanel-header-title'}>
56
- {icon && <LuiIcon name={icon} alt={'icon'} size={'md'} className={'WindowPanel-header-title-icon'} />}
57
- {title}
58
- </div>
59
- {extraLeft && <div className={'WindowPanel-divider-left'} />}
60
- <div className={'WindowPanel-children'}>{extraLeft}</div>
61
- <div className={'WindowPanel-buttons'}>
62
- {extraRight}
63
- {(helpUrl || onHelpClick) && (
64
- <PanelHeaderButton aria-label={'Get help'} href={helpUrl} onClick={onHelpClick} icon={'ic_help_outline'} />
65
- )}
66
- </div>
67
- {(dockTo || !disablePopout || !disableClose) && <div className={'WindowPanel-divider-right'} />}
68
- <div className={'WindowPanel-buttons'}>
69
- {onDockClick && <PanelHeaderButton aria-label={'Dock'} onClick={() => onDockClick()} icon={'ic_left_col'} />}
70
- {!onDockClick &&
71
- dockTo &&
72
- (docked ? (
73
- <PanelHeaderButton aria-label={'Undock'} onClick={undock} icon={'ic_close_list'} />
74
- ) : (
75
- <PanelHeaderButton aria-label={'Dock'} onClick={() => dock(dockTo)} icon={'ic_left_col'} />
76
- ))}
77
- {!disablePopout && (
78
- <PanelHeaderButton
79
- aria-label={panelPoppedOut ? 'Pop-in' : 'Pop-out'}
80
- onClick={panelTogglePopout}
81
- icon={panelPoppedOut ? 'ic_pop_back' : 'ic_launch_new window_open'}
82
- />
83
- )}
84
- {!disableClose && (
85
- <PanelHeaderButton
86
- aria-label={'Close'}
87
- onClick={() => {
88
- if (onCloseClickPoppedInPanelOnly) {
89
- void (async () => {
90
- const result = await onCloseClickPoppedInPanelOnly();
91
- if (result) {
92
- panelClose();
93
- }
94
- })();
95
- } else {
96
- panelClose();
97
- }
98
- }}
99
- icon={'ic_clear'}
100
- />
101
- )}
102
- </div>
103
- </div>
104
- );
105
- };
@@ -1,26 +0,0 @@
1
- import { LuiButton, LuiIcon } from '@linzjs/lui';
2
- import { LuiIconName } from '@linzjs/lui/dist/assets/svg-content';
3
-
4
- export interface PanelHeaderButtonProps {
5
- 'aria-label': string;
6
- href?: string;
7
- icon: LuiIconName;
8
- onClick?: () => void;
9
- }
10
-
11
- export const PanelHeaderButton = ({ 'aria-label': ariaLabel, href, icon, onClick }: PanelHeaderButtonProps) => (
12
- <LuiButton
13
- level={'plain-text'}
14
- className={'lui-button-icon-only'}
15
- size={'sm'}
16
- href={href}
17
- onClick={onClick}
18
- openInNewTab={!!href}
19
- title={ariaLabel}
20
- buttonProps={{
21
- onTouchStart: onClick,
22
- }}
23
- >
24
- <LuiIcon name={icon} alt={ariaLabel} size={'md'} />
25
- </LuiButton>
26
- );
@@ -1,46 +0,0 @@
1
- import { CSSProperties, forwardRef, PropsWithChildren } from 'react';
2
-
3
- import { PanelContext } from './PanelContext';
4
- import { PanelInstanceContext } from './PanelInstanceContext';
5
- import { v4 } from '../common/uuid';
6
- import clsx from 'clsx';
7
-
8
- export interface PanelInlineProps {
9
- title: string;
10
- className?: string;
11
- width?: CSSProperties['width'];
12
- height?: CSSProperties['height'];
13
- }
14
-
15
- export const PanelInline = forwardRef<HTMLDivElement, PropsWithChildren<PanelInlineProps>>(function PanelInline(
16
- { title, className, width, height, children },
17
- ref,
18
- ) {
19
- return (
20
- <PanelContext.Provider value={{ resizeable: false, resizePanel: () => {}, initialResizePanel: () => {} }}>
21
- <PanelInstanceContext.Provider
22
- value={{
23
- setTitle: () => {},
24
- title,
25
- zIndex: 1500,
26
- uniqueId: v4(),
27
- dock: () => {},
28
- panelClose: () => {},
29
- dockId: undefined,
30
- docked: false,
31
- bringPanelToFront: () => {},
32
- hidden: false,
33
- setPanelWindow: () => {},
34
- panelTogglePopout: () => {},
35
- undock: () => {},
36
- panelPoppedOut: false,
37
- bounds: undefined,
38
- }}
39
- >
40
- <div ref={ref} className={clsx('WindowPanel', className)} title={title} style={{ width, height }}>
41
- {children}
42
- </div>
43
- </PanelInstanceContext.Provider>
44
- </PanelContext.Provider>
45
- );
46
- });
@@ -1,44 +0,0 @@
1
- import { createContext } from 'react';
2
-
3
- export interface PanelInstanceContextType {
4
- title: string;
5
- setTitle: (title: string) => void;
6
- uniqueId: string;
7
- bounds: string | Element | undefined;
8
- panelTogglePopout: () => void;
9
- panelClose: () => void;
10
- setPanelWindow: (w: Window) => void;
11
- bringPanelToFront: () => void;
12
- panelPoppedOut: boolean;
13
- zIndex: number;
14
- dockId: string | undefined;
15
- docked: boolean;
16
- dock: (id: string) => void;
17
- undock: () => void;
18
- hidden?: boolean;
19
- }
20
-
21
- const NoContextError = () => {
22
- console.error('Missing PanelInstanceContext Provider');
23
- };
24
-
25
- /**
26
- * Provides access to closing/popping panels
27
- */
28
- export const PanelInstanceContext = createContext<PanelInstanceContextType>({
29
- title: 'Missing PanelInstanceContext Provider: title',
30
- uniqueId: 'Missing PanelInstanceContext Provider: uniqueId',
31
- bounds: document.body,
32
- setTitle: NoContextError,
33
- panelTogglePopout: NoContextError,
34
- panelClose: NoContextError,
35
- setPanelWindow: NoContextError,
36
- bringPanelToFront: NoContextError,
37
- dock: NoContextError,
38
- undock: NoContextError,
39
- docked: false,
40
- dockId: undefined,
41
- panelPoppedOut: false,
42
- zIndex: 0,
43
- hidden: false,
44
- });
@@ -1,75 +0,0 @@
1
- import { PropsWithChildren, ReactElement, useCallback, useContext, useState } from 'react';
2
-
3
- import { PanelInstanceContext } from './PanelInstanceContext';
4
- import { PanelInstance, PanelsContext } from './PanelsContext';
5
- import { useRestoreStateFrom } from './usePanelStateHandler';
6
-
7
- export interface PanelInstanceContextProviderProps {
8
- hidden?: boolean;
9
- bounds?: string | Element;
10
- panelInstance: PanelInstance;
11
- }
12
-
13
- /**
14
- * Provides access to closing/popping panels
15
- */
16
- export const PanelInstanceContextProvider = ({
17
- panelInstance,
18
- bounds,
19
- hidden,
20
- children,
21
- }: PropsWithChildren<PanelInstanceContextProviderProps>): ReactElement => {
22
- const { closePanel, bringPanelToFront, dockElements } = useContext(PanelsContext);
23
- const [title, setTitle] = useState('');
24
- const [dockId, setDockId] = useState<string>();
25
-
26
- const savedState = useRestoreStateFrom({ uniqueId: panelInstance.uniqueId });
27
- const [poppedOut, setPoppedOut] = useState(savedState?.panelPoppedOut ?? panelInstance.poppedOut);
28
-
29
- const togglePopOut = useCallback(() => {
30
- panelInstance.window = null;
31
- setPoppedOut(!poppedOut);
32
- }, [panelInstance, poppedOut]);
33
-
34
- const dock = useCallback(
35
- (id: string) => {
36
- if (poppedOut) togglePopOut();
37
- setDockId(id);
38
- },
39
- [poppedOut, togglePopOut],
40
- );
41
-
42
- const undock = useCallback(() => setDockId(undefined), []);
43
-
44
- const uniqueId = panelInstance.uniqueId;
45
-
46
- return (
47
- <PanelInstanceContext.Provider
48
- value={{
49
- title,
50
- setTitle,
51
- uniqueId,
52
- bounds,
53
- panelClose: () => {
54
- panelInstance.window?.close();
55
- panelInstance.window = null;
56
- closePanel(uniqueId);
57
- },
58
- panelTogglePopout: togglePopOut,
59
- panelPoppedOut: poppedOut,
60
- setPanelWindow: (w: Window) => {
61
- panelInstance.window = w;
62
- },
63
- bringPanelToFront: () => bringPanelToFront(uniqueId),
64
- zIndex: panelInstance.zIndex,
65
- docked: !poppedOut && !!dockId && !!dockElements[dockId],
66
- dockId,
67
- dock,
68
- undock,
69
- hidden,
70
- }}
71
- >
72
- {children}
73
- </PanelInstanceContext.Provider>
74
- );
75
- };
@@ -1,56 +0,0 @@
1
- import { createContext, ReactElement } from 'react';
2
-
3
- import { PanelPosition } from './types';
4
- import { PanelStateOptions } from './types/PanelStateOptions';
5
-
6
- export interface PanelInstance {
7
- uniqueId: string;
8
- componentInstance: ReactElement;
9
- zIndex: number;
10
- poppedOut: boolean;
11
- window: Window | null;
12
- onClose?: () => void;
13
- hidden: boolean;
14
- }
15
-
16
- export interface OpenPanelOptions {
17
- uniqueId?: string;
18
- componentFn: () => ReactElement;
19
- poppedOut?: boolean;
20
- onClose?: () => void;
21
- }
22
-
23
- export interface PanelsContextType {
24
- openPanels: Set<string>;
25
- hasOpenPanel: (panelId: string) => boolean;
26
- // returns unique id of panel that was created/or already found, otherwise null on error.
27
- openPanel: (args: OpenPanelOptions) => string | null;
28
- closePanel: (uniqueId: string | string[]) => void;
29
- hidePanel: (uniqueId: string | string[]) => void;
30
- unhidePanel: (uniqueId: string | string[]) => void;
31
- hasHiddenPanel: (uniqueId: string) => boolean;
32
- bringPanelToFront: (panelUniqueId: string) => void;
33
- nextStackPosition: () => PanelPosition;
34
- dockElements: Record<string, HTMLDivElement>;
35
- setDockElement: (id: string, element: HTMLDivElement) => void;
36
- panelStateOptions?: PanelStateOptions | null;
37
- }
38
-
39
- const NoContext = <T,>(): T => {
40
- console.error('Missing PanelContext Provider');
41
- return undefined as T;
42
- };
43
-
44
- export const PanelsContext = createContext<PanelsContextType>({
45
- openPanels: new Set(),
46
- hasOpenPanel: () => false,
47
- openPanel: NoContext,
48
- closePanel: NoContext,
49
- hidePanel: NoContext,
50
- unhidePanel: NoContext,
51
- hasHiddenPanel: NoContext,
52
- bringPanelToFront: NoContext,
53
- dockElements: {},
54
- setDockElement: NoContext,
55
- nextStackPosition: () => ({ x: 0, y: 0 }),
56
- });