@babylonjs/shared-ui-components 7.34.1 → 7.34.3

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 (116) hide show
  1. package/components/Button.js +1 -1
  2. package/components/Button.js.map +1 -1
  3. package/components/Icon.js +1 -1
  4. package/components/Icon.js.map +1 -1
  5. package/components/Label.js +1 -1
  6. package/components/Label.js.map +1 -1
  7. package/components/MessageDialog.js +1 -1
  8. package/components/MessageDialog.js.map +1 -1
  9. package/components/TextInputWithSubmit.js +1 -1
  10. package/components/TextInputWithSubmit.js.map +1 -1
  11. package/components/Toggle.js +1 -1
  12. package/components/Toggle.js.map +1 -1
  13. package/components/bars/CommandBarComponent.js +1 -1
  14. package/components/bars/CommandBarComponent.js.map +1 -1
  15. package/components/bars/CommandButtonComponent.js +1 -1
  16. package/components/bars/CommandButtonComponent.js.map +1 -1
  17. package/components/bars/CommandDropdownComponent.js +1 -1
  18. package/components/bars/CommandDropdownComponent.js.map +1 -1
  19. package/components/colorPicker/ColorComponentEntry.js +1 -1
  20. package/components/colorPicker/ColorComponentEntry.js.map +1 -1
  21. package/components/colorPicker/ColorPicker.js +1 -1
  22. package/components/colorPicker/ColorPicker.js.map +1 -1
  23. package/components/colorPicker/HexColor.js +1 -1
  24. package/components/colorPicker/HexColor.js.map +1 -1
  25. package/components/layout/FlexibleColumn.js +1 -1
  26. package/components/layout/FlexibleColumn.js.map +1 -1
  27. package/components/layout/FlexibleDropZone.js +1 -1
  28. package/components/layout/FlexibleDropZone.js.map +1 -1
  29. package/components/layout/FlexibleGridContainer.js +1 -1
  30. package/components/layout/FlexibleGridContainer.js.map +1 -1
  31. package/components/layout/FlexibleResizeBar.js +1 -1
  32. package/components/layout/FlexibleResizeBar.js.map +1 -1
  33. package/components/layout/FlexibleTab.js +1 -1
  34. package/components/layout/FlexibleTab.js.map +1 -1
  35. package/components/layout/FlexibleTabsContainer.js +1 -1
  36. package/components/layout/FlexibleTabsContainer.js.map +1 -1
  37. package/components/lines/ColorLineComponent.js +1 -1
  38. package/components/lines/ColorLineComponent.js.map +1 -1
  39. package/components/lines/ColorPickerLineComponent.js +1 -1
  40. package/components/lines/ColorPickerLineComponent.js.map +1 -1
  41. package/components/lines/FileButtonLineComponent.js +1 -1
  42. package/components/lines/FileButtonLineComponent.js.map +1 -1
  43. package/components/lines/NumericInputComponent.js +1 -1
  44. package/components/lines/NumericInputComponent.js.map +1 -1
  45. package/components/lines/OptionsLineComponent.js +1 -1
  46. package/components/lines/OptionsLineComponent.js.map +1 -1
  47. package/components/reactGraphSystem/GraphConnectorHandle.js +1 -1
  48. package/components/reactGraphSystem/GraphConnectorHandle.js.map +1 -1
  49. package/components/reactGraphSystem/GraphContainer.js +1 -1
  50. package/components/reactGraphSystem/GraphContainer.js.map +1 -1
  51. package/components/reactGraphSystem/GraphNode.js +1 -1
  52. package/components/reactGraphSystem/GraphNode.js.map +1 -1
  53. package/nodeGraphSystem/frameNodePort.js +1 -1
  54. package/nodeGraphSystem/frameNodePort.js.map +1 -1
  55. package/nodeGraphSystem/graphCanvas.js +2 -2
  56. package/nodeGraphSystem/graphCanvas.js.map +1 -1
  57. package/nodeGraphSystem/graphFrame.js +3 -3
  58. package/nodeGraphSystem/graphFrame.js.map +1 -1
  59. package/nodeGraphSystem/graphNode.js +4 -4
  60. package/nodeGraphSystem/graphNode.js.map +1 -1
  61. package/nodeGraphSystem/{graphNode.modules.scss → graphNode.module.scss} +1 -1
  62. package/nodeGraphSystem/nodeLink.js +2 -2
  63. package/nodeGraphSystem/nodeLink.js.map +1 -1
  64. package/nodeGraphSystem/nodePort.js +2 -2
  65. package/nodeGraphSystem/nodePort.js.map +1 -1
  66. package/package.json +1 -1
  67. package/popupHelper.d.ts +12 -0
  68. package/popupHelper.js +57 -0
  69. package/popupHelper.js.map +1 -0
  70. package/split/splitContainer.d.ts +58 -0
  71. package/split/splitContainer.js +232 -0
  72. package/split/splitContainer.js.map +1 -0
  73. package/split/splitContainer.module.scss +25 -0
  74. package/split/splitContext.d.ts +43 -0
  75. package/split/splitContext.js +14 -0
  76. package/split/splitContext.js.map +1 -0
  77. package/split/splitter.d.ts +41 -0
  78. package/split/splitter.js +69 -0
  79. package/split/splitter.js.map +1 -0
  80. package/styleHelper.d.ts +6 -0
  81. package/styleHelper.js +21 -0
  82. package/styleHelper.js.map +1 -0
  83. package/lines/popup.d.ts +0 -4
  84. package/lines/popup.js +0 -69
  85. package/lines/popup.js.map +0 -1
  86. /package/components/{Button.modules.scss → Button.module.scss} +0 -0
  87. /package/components/{Icon.modules.scss → Icon.module.scss} +0 -0
  88. /package/components/{Label.modules.scss → Label.module.scss} +0 -0
  89. /package/components/{MessageDialog.modules.scss → MessageDialog.module.scss} +0 -0
  90. /package/components/{TextInputWithSubmit.modules.scss → TextInputWithSubmit.module.scss} +0 -0
  91. /package/components/{Toggle.modules.scss → Toggle.module.scss} +0 -0
  92. /package/components/bars/{CommandBar.modules.scss → CommandBar.module.scss} +0 -0
  93. /package/components/bars/{CommandButton.modules.scss → CommandButton.module.scss} +0 -0
  94. /package/components/bars/{CommandDropdown.modules.scss → CommandDropdown.module.scss} +0 -0
  95. /package/components/colorPicker/{ColorComponentEntry.modules.scss → ColorComponentEntry.module.scss} +0 -0
  96. /package/components/colorPicker/{ColorPicker.modules.scss → ColorPicker.module.scss} +0 -0
  97. /package/components/colorPicker/{HexColor.modules.scss → HexColor.module.scss} +0 -0
  98. /package/components/layout/{FlexibleColumn.modules.scss → FlexibleColumn.module.scss} +0 -0
  99. /package/components/layout/{FlexibleDropZone.modules.scss → FlexibleDropZone.module.scss} +0 -0
  100. /package/components/layout/{FlexibleGridContainer.modules.scss → FlexibleGridContainer.module.scss} +0 -0
  101. /package/components/layout/{FlexibleResizeBar.modules.scss → FlexibleResizeBar.module.scss} +0 -0
  102. /package/components/layout/{FlexibleTab.modules.scss → FlexibleTab.module.scss} +0 -0
  103. /package/components/layout/{FlexibleTabsContainer.modules.scss → FlexibleTabsContainer.module.scss} +0 -0
  104. /package/components/lines/{ColorLineComponent.modules.scss → ColorLineComponent.module.scss} +0 -0
  105. /package/components/lines/{ColorPickerLineComponent.modules.scss → ColorPickerLineComponent.module.scss} +0 -0
  106. /package/components/lines/{FileButtonLineComponent.modules.scss → FileButtonLineComponent.module.scss} +0 -0
  107. /package/components/lines/{NumericInputComponent.modules.scss → NumericInputComponent.module.scss} +0 -0
  108. /package/components/lines/{OptionsLineComponent.modules.scss → OptionsLineComponent.module.scss} +0 -0
  109. /package/components/reactGraphSystem/{GraphConnectorHandle.modules.scss → GraphConnectorHandle.module.scss} +0 -0
  110. /package/components/reactGraphSystem/{GraphContainer.modules.scss → GraphContainer.module.scss} +0 -0
  111. /package/components/reactGraphSystem/{GraphNode.modules.scss → GraphNode.module.scss} +0 -0
  112. /package/nodeGraphSystem/{common.modules.scss → common.module.scss} +0 -0
  113. /package/nodeGraphSystem/{graphCanvas.modules.scss → graphCanvas.module.scss} +0 -0
  114. /package/nodeGraphSystem/{graphFrame.modules.scss → graphFrame.module.scss} +0 -0
  115. /package/nodeGraphSystem/{nodeLink.modules.scss → nodeLink.module.scss} +0 -0
  116. /package/nodeGraphSystem/{nodePort.modules.scss → nodePort.module.scss} +0 -0
package/popupHelper.js ADDED
@@ -0,0 +1,57 @@
1
+ import { CopyStyles } from "./styleHelper.js";
2
+ /**
3
+ * Create a popup window
4
+ * @param title default title for the popup
5
+ * @param options options for the popup
6
+ * @returns the parent control of the popup
7
+ */
8
+ export function CreatePopup(title, options) {
9
+ const localOptions = {
10
+ width: 300,
11
+ height: 800,
12
+ ...options,
13
+ };
14
+ const windowCreationOptionsList = {
15
+ width: localOptions.width,
16
+ height: localOptions.height,
17
+ top: (window.innerHeight - localOptions.width) / 2 + window.screenY,
18
+ left: (window.innerWidth - localOptions.height) / 2 + window.screenX,
19
+ };
20
+ const windowCreationOptions = Object.keys(windowCreationOptionsList)
21
+ .map((key) => key + "=" + windowCreationOptionsList[key])
22
+ .join(",");
23
+ const popupWindow = window.open("", title, windowCreationOptions);
24
+ if (!popupWindow) {
25
+ return null;
26
+ }
27
+ const parentDocument = popupWindow.document;
28
+ // Font
29
+ const newLinkEl = parentDocument.createElement("link");
30
+ newLinkEl.rel = "stylesheet";
31
+ newLinkEl.href = "https://use.typekit.net/cta4xsb.css";
32
+ parentDocument.head.appendChild(newLinkEl);
33
+ parentDocument.title = title;
34
+ parentDocument.body.style.width = "100%";
35
+ parentDocument.body.style.height = "100%";
36
+ parentDocument.body.style.margin = "0";
37
+ parentDocument.body.style.padding = "0";
38
+ const parentControl = parentDocument.createElement("div");
39
+ parentControl.style.width = "100%";
40
+ parentControl.style.height = "100%";
41
+ parentControl.style.margin = "0";
42
+ parentControl.style.padding = "0";
43
+ if (localOptions.onParentControlCreateCallback) {
44
+ localOptions.onParentControlCreateCallback(parentControl);
45
+ }
46
+ popupWindow.document.body.appendChild(parentControl);
47
+ CopyStyles(window.document, parentDocument);
48
+ setTimeout(() => {
49
+ // need this for late bindings
50
+ CopyStyles(window.document, parentDocument);
51
+ }, 0);
52
+ if (localOptions.onWindowCreateCallback) {
53
+ localOptions.onWindowCreateCallback(popupWindow);
54
+ }
55
+ return parentControl;
56
+ }
57
+ //# sourceMappingURL=popupHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"popupHelper.js","sourceRoot":"","sources":["../../../dev/sharedUiComponents/src/popupHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAE3C;;;;;GAKG;AACH,MAAM,UAAU,WAAW,CACvB,KAAa,EACb,OAKE;IAEF,MAAM,YAAY,GAAG;QACjB,KAAK,EAAE,GAAG;QACV,MAAM,EAAE,GAAG;QACX,GAAG,OAAO;KACb,CAAC;IAEF,MAAM,yBAAyB,GAAG;QAC9B,KAAK,EAAE,YAAY,CAAC,KAAK;QACzB,MAAM,EAAE,YAAY,CAAC,MAAM;QAC3B,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,GAAG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G,MAAM,CAAC;IACnC,aAAa,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;IACpC,aAAa,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,CAAC;IACjC,aAAa,CAAC,KAAK,CAAC,OAAO,GAAG,GAAG,CAAC;IAElC,IAAI,YAAY,CAAC,6BAA6B,EAAE;QAC5C,YAAY,CAAC,6BAA6B,CAAC,aAAa,CAAC,CAAC;KAC7D;IAED,WAAW,CAAC,QAAQ,CAAC,IAAI,CAAC,WAAW,CAAC,aAAa,CAAC,CAAC;IACrD,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAC5C,UAAU,CAAC,GAAG,EAAE;QACZ,8BAA8B;QAC9B,UAAU,CAAC,MAAM,CAAC,QAAQ,EAAE,cAAc,CAAC,CAAC;IAChD,CAAC,EAAE,CAAC,CAAC,CAAC;IAEN,IAAI,YAAY,CAAC,sBAAsB,EAAE;QACrC,YAAY,CAAC,sBAAsB,CAAC,WAAW,CAAC,CAAC;KACpD;IAED,OAAO,aAAa,CAAC;AACzB,CAAC","sourcesContent":["import { CopyStyles } from \"./styleHelper\";\r\n\r\n/**\r\n * Create a popup window\r\n * @param title default title for the popup\r\n * @param options options for the popup\r\n * @returns the parent control of the popup\r\n */\r\nexport function CreatePopup(\r\n title: string,\r\n options: Partial<{\r\n onParentControlCreateCallback?: (parentControl: HTMLDivElement) => void;\r\n onWindowCreateCallback?: (newWindow: Window) => void;\r\n width?: number;\r\n height?: number;\r\n }>\r\n) {\r\n const localOptions = {\r\n width: 300,\r\n height: 800,\r\n ...options,\r\n };\r\n\r\n const windowCreationOptionsList = {\r\n width: localOptions.width,\r\n height: localOptions.height,\r\n top: (window.innerHeight - localOptions.width) / 2 + window.screenY,\r\n left: (window.innerWidth - localOptions.height) / 2 + window.screenX,\r\n };\r\n\r\n const windowCreationOptions = Object.keys(windowCreationOptionsList)\r\n .map((key) => key + \"=\" + (windowCreationOptionsList as any)[key])\r\n .join(\",\");\r\n\r\n const popupWindow = window.open(\"\", title, windowCreationOptions);\r\n if (!popupWindow) {\r\n return null;\r\n }\r\n\r\n const parentDocument = popupWindow.document;\r\n\r\n // Font\r\n const newLinkEl = parentDocument.createElement(\"link\");\r\n\r\n newLinkEl.rel = \"stylesheet\";\r\n newLinkEl.href = \"https://use.typekit.net/cta4xsb.css\";\r\n parentDocument.head!.appendChild(newLinkEl);\r\n\r\n parentDocument.title = title;\r\n parentDocument.body.style.width = \"100%\";\r\n parentDocument.body.style.height = \"100%\";\r\n parentDocument.body.style.margin = \"0\";\r\n parentDocument.body.style.padding = \"0\";\r\n\r\n const parentControl = parentDocument.createElement(\"div\");\r\n parentControl.style.width = \"100%\";\r\n parentControl.style.height = \"100%\";\r\n parentControl.style.margin = \"0\";\r\n parentControl.style.padding = \"0\";\r\n\r\n if (localOptions.onParentControlCreateCallback) {\r\n localOptions.onParentControlCreateCallback(parentControl);\r\n }\r\n\r\n popupWindow.document.body.appendChild(parentControl);\r\n CopyStyles(window.document, parentDocument);\r\n setTimeout(() => {\r\n // need this for late bindings\r\n CopyStyles(window.document, parentDocument);\r\n }, 0);\r\n\r\n if (localOptions.onWindowCreateCallback) {\r\n localOptions.onWindowCreateCallback(popupWindow);\r\n }\r\n\r\n return parentControl;\r\n}\r\n"]}
@@ -0,0 +1,58 @@
1
+ /// <reference types="react" />
2
+ import { SplitDirection } from "./splitContext";
3
+ /**
4
+ * Split container properties
5
+ */
6
+ export interface ISplitContainerProps {
7
+ /**
8
+ * Unique identifier
9
+ */
10
+ id?: string;
11
+ /**
12
+ * Split direction
13
+ */
14
+ direction: SplitDirection;
15
+ /**
16
+ * Minimum size for the floating elements
17
+ */
18
+ floatingMinSize?: number;
19
+ /**
20
+ * RefObject to the root div element
21
+ */
22
+ containerRef?: React.RefObject<HTMLDivElement>;
23
+ /**
24
+ * Optional class name
25
+ */
26
+ className?: string;
27
+ /**
28
+ * Pointer down
29
+ * @param event pointer events
30
+ */
31
+ onPointerDown?: (event: React.PointerEvent) => void;
32
+ /**
33
+ * Pointer move
34
+ * @param event pointer events
35
+ */
36
+ onPointerMove?: (event: React.PointerEvent) => void;
37
+ /**
38
+ * Pointer up
39
+ * @param event pointer events
40
+ */
41
+ onPointerUp?: (event: React.PointerEvent) => void;
42
+ /**
43
+ * Drop
44
+ * @param event drag events
45
+ */
46
+ onDrop?: (event: React.DragEvent<HTMLDivElement>) => void;
47
+ /**
48
+ * Drag over
49
+ * @param event drag events
50
+ */
51
+ onDragOver?: (event: React.DragEvent<HTMLDivElement>) => void;
52
+ }
53
+ /**
54
+ * Creates a split container component
55
+ * @param props defines the split container properties
56
+ * @returns the split container component
57
+ */
58
+ export declare const SplitContainer: React.FC<ISplitContainerProps>;
@@ -0,0 +1,232 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useEffect, useRef } from "react";
3
+ import styles from "./splitContainer.module.scss";
4
+ import { ControlledSize, SplitDirection, SplitContext } from "./splitContext.js";
5
+ /**
6
+ * Creates a split container component
7
+ * @param props defines the split container properties
8
+ * @returns the split container component
9
+ */
10
+ export const SplitContainer = (props) => {
11
+ const elementRef = props.containerRef || useRef(null);
12
+ const sizes = [];
13
+ const floatingCells = [];
14
+ const noInitialSizes = [];
15
+ const floatingMinSize = props.floatingMinSize || 200;
16
+ const controllers = [];
17
+ const minSizes = [];
18
+ const maxSizes = [];
19
+ const buildGridDefinition = () => {
20
+ if (!elementRef.current) {
21
+ return;
22
+ }
23
+ const children = elementRef.current.children;
24
+ let gridIndex = 1;
25
+ const pickArray = Array.from(children);
26
+ let gridDefinition = "";
27
+ for (const child of children) {
28
+ const childElement = child;
29
+ if (child.classList.contains(styles["splitter"])) {
30
+ gridDefinition += "auto ";
31
+ }
32
+ else {
33
+ const sourceIndex = pickArray.indexOf(child);
34
+ if (floatingCells[sourceIndex] || noInitialSizes[sourceIndex]) {
35
+ gridDefinition += "1fr ";
36
+ }
37
+ else {
38
+ gridDefinition += "auto ";
39
+ }
40
+ }
41
+ if (props.direction === SplitDirection.Horizontal) {
42
+ childElement.style.gridRow = "1";
43
+ childElement.style.gridColumn = gridIndex.toString();
44
+ }
45
+ else {
46
+ childElement.style.gridColumn = "1";
47
+ childElement.style.gridRow = gridIndex.toString();
48
+ }
49
+ gridIndex++;
50
+ }
51
+ if (props.direction === SplitDirection.Horizontal) {
52
+ elementRef.current.style.gridTemplateRows = "100%";
53
+ elementRef.current.style.gridTemplateColumns = gridDefinition;
54
+ }
55
+ else {
56
+ elementRef.current.style.gridTemplateColumns = "100%";
57
+ elementRef.current.style.gridTemplateRows = gridDefinition;
58
+ }
59
+ };
60
+ const handleResize = () => {
61
+ if (!elementRef.current) {
62
+ return;
63
+ }
64
+ // Check if we have enough room for everyone
65
+ const children = elementRef.current.children;
66
+ for (let i = 0; i < children.length; i++) {
67
+ if (!floatingCells[i]) {
68
+ continue;
69
+ }
70
+ const child = children[i];
71
+ let childsize = 0;
72
+ if (props.direction === SplitDirection.Horizontal) {
73
+ childsize = child.getBoundingClientRect().width;
74
+ }
75
+ else {
76
+ childsize = child.getBoundingClientRect().height;
77
+ }
78
+ if (childsize < floatingMinSize) {
79
+ const missing = Math.floor(floatingMinSize - childsize);
80
+ let done = 0;
81
+ // picking the controller in order and try to reduce their size to fit
82
+ for (let j = 0; j < controllers[i].length; j++) {
83
+ const controllerIndex = controllers[i][j];
84
+ const controller = children[controllerIndex];
85
+ const currentSize = props.direction === SplitDirection.Horizontal ? controller.getBoundingClientRect().width : controller.getBoundingClientRect().height;
86
+ let newSize = currentSize - missing;
87
+ if (minSizes[controllerIndex]) {
88
+ newSize = Math.max(newSize, minSizes[controllerIndex]);
89
+ }
90
+ if (props.direction === SplitDirection.Horizontal) {
91
+ controller.style.width = `${newSize}px`;
92
+ }
93
+ else {
94
+ controller.style.height = `${newSize}px`;
95
+ }
96
+ done += currentSize - newSize;
97
+ if (done === missing) {
98
+ // We made it
99
+ break;
100
+ }
101
+ }
102
+ }
103
+ }
104
+ };
105
+ useEffect(() => {
106
+ buildGridDefinition();
107
+ // Add event listener for window resize
108
+ window.addEventListener("resize", handleResize);
109
+ // Cleanup the event listener on component unmount
110
+ return () => {
111
+ window.removeEventListener("resize", handleResize);
112
+ };
113
+ }, []);
114
+ const drag = (offset, source, controlledSide) => {
115
+ if (!elementRef.current) {
116
+ return;
117
+ }
118
+ const children = elementRef.current.children;
119
+ const childArray = Array.from(children);
120
+ const sourceIndex = childArray.indexOf(source);
121
+ if (sourceIndex <= 0) {
122
+ return;
123
+ }
124
+ let current = 0;
125
+ if (controlledSide === ControlledSize.First) {
126
+ current = sourceIndex - 1;
127
+ }
128
+ else {
129
+ current = sourceIndex + 1;
130
+ }
131
+ const minSize = minSizes[current] || 0;
132
+ const maxSize = maxSizes[current];
133
+ noInitialSizes[current] = false;
134
+ buildGridDefinition();
135
+ let newSize = Math.floor(controlledSide === ControlledSize.First ? sizes[current] + offset : sizes[current] - offset);
136
+ // Min size check
137
+ if (newSize < minSize) {
138
+ newSize = minSize;
139
+ }
140
+ // Max size check
141
+ if (maxSize && newSize > maxSize) {
142
+ newSize = maxSize;
143
+ }
144
+ // Max size check across the whole container
145
+ const maxContainerSize = sizes.reduce((a, b) => a + b, 0) || 0;
146
+ let totalSize = 0;
147
+ let totalFloating = 0;
148
+ for (let i = 0; i < children.length; i++) {
149
+ if (floatingCells[i]) {
150
+ totalFloating++;
151
+ }
152
+ else {
153
+ totalSize += i === current ? newSize : sizes[i];
154
+ }
155
+ }
156
+ if (maxContainerSize - totalSize < floatingMinSize * totalFloating) {
157
+ newSize = maxContainerSize - floatingMinSize * totalFloating;
158
+ }
159
+ if (props.direction === SplitDirection.Horizontal) {
160
+ childArray[current].style.width = `${newSize}px`;
161
+ }
162
+ else {
163
+ childArray[current].style.height = `${newSize}px`;
164
+ }
165
+ };
166
+ const beginDrag = () => {
167
+ if (!elementRef.current) {
168
+ return;
169
+ }
170
+ const children = elementRef.current.children;
171
+ sizes.length = 0;
172
+ for (const child of children) {
173
+ const childElement = child;
174
+ if (props.direction === SplitDirection.Horizontal) {
175
+ sizes.push(childElement.getBoundingClientRect().width);
176
+ }
177
+ else {
178
+ sizes.push(childElement.getBoundingClientRect().height);
179
+ }
180
+ }
181
+ };
182
+ const endDrag = () => {
183
+ sizes.length = 0;
184
+ };
185
+ // We assume splitter are not flagging floating cells in a different way
186
+ const sync = (source, controlledSide, size, minSize, maxSize) => {
187
+ if (!elementRef.current) {
188
+ return;
189
+ }
190
+ const children = elementRef.current.children;
191
+ const childArray = Array.from(children);
192
+ const sourceIndex = childArray.indexOf(source);
193
+ if (sourceIndex <= 0) {
194
+ return;
195
+ }
196
+ let current = 0;
197
+ let other = 0;
198
+ if (controlledSide === ControlledSize.First) {
199
+ current = sourceIndex - 1;
200
+ other = sourceIndex + 1;
201
+ }
202
+ else {
203
+ current = sourceIndex + 1;
204
+ other = sourceIndex - 1;
205
+ }
206
+ if (size !== undefined) {
207
+ const sizeString = `${size | 0}px`;
208
+ if (props.direction === SplitDirection.Horizontal) {
209
+ childArray[current].style.width = sizeString;
210
+ }
211
+ else {
212
+ childArray[current].style.height = sizeString;
213
+ }
214
+ }
215
+ else {
216
+ noInitialSizes[current] = true;
217
+ }
218
+ if (minSize !== undefined) {
219
+ minSizes[current] = minSize;
220
+ }
221
+ if (maxSize !== undefined) {
222
+ maxSizes[current] = maxSize;
223
+ }
224
+ if (!controllers[other]) {
225
+ controllers[other] = [];
226
+ }
227
+ controllers[other].push(current);
228
+ floatingCells[other] = true;
229
+ };
230
+ return (_jsx(SplitContext.Provider, { value: { direction: props.direction, drag, beginDrag, endDrag, sync }, children: _jsx("div", { id: props.id, className: styles["split-container"] + " " + props.className, ref: elementRef, onPointerDown: (evt) => props.onPointerDown && props.onPointerDown(evt), onPointerMove: (evt) => props.onPointerMove && props.onPointerMove(evt), onPointerUp: (evt) => props.onPointerUp && props.onPointerUp(evt), onDrop: (evt) => props.onDrop && props.onDrop(evt), onDragOver: (evt) => props.onDragOver && props.onDragOver(evt), children: props.children }) }));
231
+ };
232
+ //# sourceMappingURL=splitContainer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitContainer.js","sourceRoot":"","sources":["../../../../dev/sharedUiComponents/src/split/splitContainer.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,MAAM,MAAM,8BAA8B,CAAC;AAClD,OAAO,EAAE,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AA8D9E;;;;GAIG;AACH,MAAM,CAAC,MAAM,cAAc,GAAmC,CAAC,KAAK,EAAE,EAAE;IACpE,MAAM,UAAU,GAAoC,KAAK,CAAC,YAAY,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IACvF,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,aAAa,GAAc,EAAE,CAAC;IACpC,MAAM,cAAc,GAAc,EAAE,CAAC;IACrC,MAAM,eAAe,GAAG,KAAK,CAAC,eAAe,IAAI,GAAG,CAAC;IACrD,MAAM,WAAW,GAAe,EAAE,CAAC;IACnC,MAAM,QAAQ,GAAa,EAAE,CAAC;IAC9B,MAAM,QAAQ,GAAa,EAAE,CAAC;IAE9B,MAAM,mBAAmB,GAAG,GAAG,EAAE;QAC7B,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACrB,OAAO;SACV;QACD,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,QAAQ,CAAC;QAE7C,IAAI,SAAS,GAAG,CAAC,CAAC;QAClB,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,CAAC;QACvC,IAAI,cAAc,GAAG,EAAE,CAAC;QACxB,KAAK,MAAM,KAAK,IAAI,QAAQ,EAAE;YAC1B,MAAM,YAAY,GAAG,KAAoB,CAAC;YAC1C,IAAI,KAAK,CAAC,SAAS,CAAC,QAAQ,CAAC,MAAM,CAAC,UAAU,CAAC,CAAC,EA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AC,YAAY,CAAC,QAAQ,IAAC,KAAK,EAAE,EAAE,SAAS,EAAE,KAAK,CAAC,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,OAAO,EAAE,IAAI,EAAE,YACxF,cACI,EAAE,EAAE,KAAK,CAAC,EAAE,EACZ,SAAS,EAAE,MAAM,CAAC,iBAAiB,CAAC,GAAG,GAAG,GAAG,KAAK,CAAC,SAAS,EAC5D,GAAG,EAAE,UAAU,EACf,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,EACvE,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,aAAa,IAAI,KAAK,CAAC,aAAa,CAAC,GAAG,CAAC,EACvE,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,WAAW,IAAI,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,EACjE,MAAM,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,IAAI,KAAK,CAAC,MAAM,CAAC,GAAG,CAAC,EAClD,UAAU,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,UAAU,IAAI,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,YAE7D,KAAK,CAAC,QAAQ,GACb,GACc,CAC3B,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { useEffect, useRef } from \"react\";\r\nimport styles from \"./splitContainer.module.scss\";\r\nimport { ControlledSize, SplitDirection, SplitContext } from \"./splitContext\";\r\n\r\n/**\r\n * Split container properties\r\n */\r\nexport interface ISplitContainerProps {\r\n /**\r\n * Unique identifier\r\n */\r\n id?: string;\r\n\r\n /**\r\n * Split direction\r\n */\r\n direction: SplitDirection;\r\n\r\n /**\r\n * Minimum size for the floating elements\r\n */\r\n floatingMinSize?: number;\r\n\r\n /**\r\n * RefObject to the root div element\r\n */\r\n containerRef?: React.RefObject<HTMLDivElement>;\r\n\r\n /**\r\n * Optional class name\r\n */\r\n className?: string;\r\n\r\n /**\r\n * Pointer down\r\n * @param event pointer events\r\n */\r\n onPointerDown?: (event: React.PointerEvent) => void;\r\n\r\n /**\r\n * Pointer move\r\n * @param event pointer events\r\n */\r\n onPointerMove?: (event: React.PointerEvent) => void;\r\n\r\n /**\r\n * Pointer up\r\n * @param event pointer events\r\n */\r\n onPointerUp?: (event: React.PointerEvent) => void;\r\n\r\n /**\r\n * Drop\r\n * @param event drag events\r\n */\r\n onDrop?: (event: React.DragEvent<HTMLDivElement>) => void;\r\n\r\n /**\r\n * Drag over\r\n * @param event drag events\r\n */\r\n onDragOver?: (event: React.DragEvent<HTMLDivElement>) => void;\r\n}\r\n\r\n/**\r\n * Creates a split container component\r\n * @param props defines the split container properties\r\n * @returns the split container component\r\n */\r\nexport const SplitContainer: React.FC<ISplitContainerProps> = (props) => {\r\n const elementRef: React.RefObject<HTMLDivElement> = props.containerRef || useRef(null);\r\n const sizes: number[] = [];\r\n const floatingCells: boolean[] = [];\r\n const noInitialSizes: boolean[] = [];\r\n const floatingMinSize = props.floatingMinSize || 200;\r\n const controllers: number[][] = [];\r\n const minSizes: number[] = [];\r\n const maxSizes: number[] = [];\r\n\r\n const buildGridDefinition = () => {\r\n if (!elementRef.current) {\r\n return;\r\n }\r\n const children = elementRef.current.children;\r\n\r\n let gridIndex = 1;\r\n const pickArray = Array.from(children);\r\n let gridDefinition = \"\";\r\n for (const child of children) {\r\n const childElement = child as HTMLElement;\r\n if (child.classList.contains(styles[\"splitter\"])) {\r\n gridDefinition += \"auto \";\r\n } else {\r\n const sourceIndex = pickArray.indexOf(child);\r\n if (floatingCells[sourceIndex] || noInitialSizes[sourceIndex]) {\r\n gridDefinition += \"1fr \";\r\n } else {\r\n gridDefinition += \"auto \";\r\n }\r\n }\r\n\r\n if (props.direction === SplitDirection.Horizontal) {\r\n childElement.style.gridRow = \"1\";\r\n childElement.style.gridColumn = gridIndex.toString();\r\n } else {\r\n childElement.style.gridColumn = \"1\";\r\n childElement.style.gridRow = gridIndex.toString();\r\n }\r\n\r\n gridIndex++;\r\n }\r\n\r\n if (props.direction === SplitDirection.Horizontal) {\r\n elementRef.current.style.gridTemplateRows = \"100%\";\r\n elementRef.current.style.gridTemplateColumns = gridDefinition;\r\n } else {\r\n elementRef.current.style.gridTemplateColumns = \"100%\";\r\n elementRef.current.style.gridTemplateRows = gridDefinition;\r\n }\r\n };\r\n\r\n const handleResize = () => {\r\n if (!elementRef.current) {\r\n return;\r\n }\r\n\r\n // Check if we have enough room for everyone\r\n const children = elementRef.current.children;\r\n for (let i = 0; i < children.length; i++) {\r\n if (!floatingCells[i]) {\r\n continue;\r\n }\r\n\r\n const child = children[i] as HTMLElement;\r\n let childsize = 0;\r\n if (props.direction === SplitDirection.Horizontal) {\r\n childsize = child.getBoundingClientRect().width;\r\n } else {\r\n childsize = child.getBoundingClientRect().height;\r\n }\r\n\r\n if (childsize < floatingMinSize) {\r\n const missing = Math.floor(floatingMinSize - childsize);\r\n let done = 0;\r\n\r\n // picking the controller in order and try to reduce their size to fit\r\n for (let j = 0; j < controllers[i].length; j++) {\r\n const controllerIndex = controllers[i][j];\r\n const controller = children[controllerIndex] as HTMLElement;\r\n const currentSize = props.direction === SplitDirection.Horizontal ? controller.getBoundingClientRect().width : controller.getBoundingClientRect().height;\r\n let newSize = currentSize - missing;\r\n if (minSizes[controllerIndex]) {\r\n newSize = Math.max(newSize, minSizes[controllerIndex]);\r\n }\r\n if (props.direction === SplitDirection.Horizontal) {\r\n controller.style.width = `${newSize}px`;\r\n } else {\r\n controller.style.height = `${newSize}px`;\r\n }\r\n\r\n done += currentSize - newSize;\r\n\r\n if (done === missing) {\r\n // We made it\r\n break;\r\n }\r\n }\r\n }\r\n }\r\n };\r\n\r\n useEffect(() => {\r\n buildGridDefinition();\r\n\r\n // Add event listener for window resize\r\n window.addEventListener(\"resize\", handleResize);\r\n\r\n // Cleanup the event listener on component unmount\r\n return () => {\r\n window.removeEventListener(\"resize\", handleResize);\r\n };\r\n }, []);\r\n\r\n const drag = (offset: number, source: HTMLElement, controlledSide: ControlledSize) => {\r\n if (!elementRef.current) {\r\n return;\r\n }\r\n\r\n const children = elementRef.current.children;\r\n const childArray = Array.from(children) as HTMLElement[];\r\n const sourceIndex = childArray.indexOf(source);\r\n if (sourceIndex <= 0) {\r\n return;\r\n }\r\n\r\n let current = 0;\r\n if (controlledSide === ControlledSize.First) {\r\n current = sourceIndex - 1;\r\n } else {\r\n current = sourceIndex + 1;\r\n }\r\n const minSize = minSizes[current] || 0;\r\n const maxSize = maxSizes[current];\r\n\r\n noInitialSizes[current] = false;\r\n buildGridDefinition();\r\n\r\n let newSize = Math.floor(controlledSide === ControlledSize.First ? sizes[current] + offset : sizes[current] - offset);\r\n\r\n // Min size check\r\n if (newSize < minSize) {\r\n newSize = minSize;\r\n }\r\n\r\n // Max size check\r\n if (maxSize && newSize > maxSize) {\r\n newSize = maxSize;\r\n }\r\n\r\n // Max size check across the whole container\r\n const maxContainerSize = sizes.reduce((a, b) => a + b, 0) || 0;\r\n let totalSize = 0;\r\n let totalFloating = 0;\r\n for (let i = 0; i < children.length; i++) {\r\n if (floatingCells[i]) {\r\n totalFloating++;\r\n } else {\r\n totalSize += i === current ? newSize : sizes[i];\r\n }\r\n }\r\n\r\n if (maxContainerSize - totalSize < floatingMinSize * totalFloating) {\r\n newSize = maxContainerSize - floatingMinSize * totalFloating;\r\n }\r\n\r\n if (props.direction === SplitDirection.Horizontal) {\r\n childArray[current].style.width = `${newSize}px`;\r\n } else {\r\n childArray[current].style.height = `${newSize}px`;\r\n }\r\n };\r\n\r\n const beginDrag = () => {\r\n if (!elementRef.current) {\r\n return;\r\n }\r\n const children = elementRef.current.children;\r\n sizes.length = 0;\r\n for (const child of children) {\r\n const childElement = child as HTMLElement;\r\n\r\n if (props.direction === SplitDirection.Horizontal) {\r\n sizes.push(childElement.getBoundingClientRect().width);\r\n } else {\r\n sizes.push(childElement.getBoundingClientRect().height);\r\n }\r\n }\r\n };\r\n\r\n const endDrag = () => {\r\n sizes.length = 0;\r\n };\r\n\r\n // We assume splitter are not flagging floating cells in a different way\r\n const sync = (source: HTMLElement, controlledSide: ControlledSize, size?: number, minSize?: number, maxSize?: number) => {\r\n if (!elementRef.current) {\r\n return;\r\n }\r\n\r\n const children = elementRef.current.children;\r\n const childArray = Array.from(children) as HTMLElement[];\r\n const sourceIndex = childArray.indexOf(source);\r\n if (sourceIndex <= 0) {\r\n return;\r\n }\r\n\r\n let current = 0;\r\n let other = 0;\r\n if (controlledSide === ControlledSize.First) {\r\n current = sourceIndex - 1;\r\n other = sourceIndex + 1;\r\n } else {\r\n current = sourceIndex + 1;\r\n other = sourceIndex - 1;\r\n }\r\n\r\n if (size !== undefined) {\r\n const sizeString = `${size | 0}px`;\r\n\r\n if (props.direction === SplitDirection.Horizontal) {\r\n childArray[current].style.width = sizeString;\r\n } else {\r\n childArray[current].style.height = sizeString;\r\n }\r\n } else {\r\n noInitialSizes[current] = true;\r\n }\r\n\r\n if (minSize !== undefined) {\r\n minSizes[current] = minSize;\r\n }\r\n\r\n if (maxSize !== undefined) {\r\n maxSizes[current] = maxSize;\r\n }\r\n\r\n if (!controllers[other]) {\r\n controllers[other] = [];\r\n }\r\n controllers[other].push(current);\r\n floatingCells[other] = true;\r\n };\r\n\r\n return (\r\n <SplitContext.Provider value={{ direction: props.direction, drag, beginDrag, endDrag, sync }}>\r\n <div\r\n id={props.id}\r\n className={styles[\"split-container\"] + \" \" + props.className}\r\n ref={elementRef}\r\n onPointerDown={(evt) => props.onPointerDown && props.onPointerDown(evt)}\r\n onPointerMove={(evt) => props.onPointerMove && props.onPointerMove(evt)}\r\n onPointerUp={(evt) => props.onPointerUp && props.onPointerUp(evt)}\r\n onDrop={(evt) => props.onDrop && props.onDrop(evt)}\r\n onDragOver={(evt) => props.onDragOver && props.onDragOver(evt)}\r\n >\r\n {props.children}\r\n </div>\r\n </SplitContext.Provider>\r\n );\r\n};\r\n"]}
@@ -0,0 +1,25 @@
1
+ :local .split-container {
2
+ display: grid;
3
+
4
+ .splitter {
5
+ width: 100%;
6
+ height: 100%;
7
+ padding: 0;
8
+ margin: 0;
9
+ background-color: #444;
10
+ border: 0px;
11
+ overlay: hidden;
12
+
13
+ &.vertical {
14
+ cursor: row-resize;
15
+ }
16
+
17
+ &.horizontal {
18
+ cursor: col-resize;
19
+ }
20
+
21
+ &:hover {
22
+ background-color: #666;
23
+ }
24
+ }
25
+ }
@@ -0,0 +1,43 @@
1
+ /// <reference types="react" />
2
+ export declare enum ControlledSize {
3
+ First = 0,
4
+ Second = 1
5
+ }
6
+ export declare enum SplitDirection {
7
+ Horizontal = 0,
8
+ Vertical = 1
9
+ }
10
+ /**
11
+ * Context used to share data with splitters
12
+ */
13
+ export interface ISplitContext {
14
+ /**
15
+ * Split direction
16
+ */
17
+ direction: SplitDirection;
18
+ /**
19
+ * Function called by splitters to update the offset
20
+ * @param offset new offet
21
+ * @param source source element
22
+ * @param controlledSide defined controlled element
23
+ */
24
+ drag: (offset: number, source: HTMLElement, controlledSide: ControlledSize) => void;
25
+ /**
26
+ * Function called by splitters to begin dragging
27
+ */
28
+ beginDrag: () => void;
29
+ /**
30
+ * Function called by splitters to end dragging
31
+ */
32
+ endDrag: () => void;
33
+ /**
34
+ * Sync sizes for the elements
35
+ * @param source source element
36
+ * @param controlledSide defined controlled element
37
+ * @param size size of the controlled element
38
+ * @param minSize minimum size for the controlled element
39
+ * @param maxSize maximum size for the controlled element
40
+ */
41
+ sync: (source: HTMLElement, controlledSide: ControlledSize, size?: number, minSize?: number, maxSize?: number) => void;
42
+ }
43
+ export declare const SplitContext: import("react").Context<ISplitContext>;
@@ -0,0 +1,14 @@
1
+ import { createContext } from "react";
2
+ export var ControlledSize;
3
+ (function (ControlledSize) {
4
+ ControlledSize[ControlledSize["First"] = 0] = "First";
5
+ ControlledSize[ControlledSize["Second"] = 1] = "Second";
6
+ })(ControlledSize || (ControlledSize = {}));
7
+ export var SplitDirection;
8
+ (function (SplitDirection) {
9
+ SplitDirection[SplitDirection["Horizontal"] = 0] = "Horizontal";
10
+ SplitDirection[SplitDirection["Vertical"] = 1] = "Vertical";
11
+ })(SplitDirection || (SplitDirection = {}));
12
+ // Create the context
13
+ export const SplitContext = createContext({ direction: SplitDirection.Horizontal, drag: () => { }, beginDrag: () => { }, endDrag: () => { }, sync: () => { } });
14
+ //# sourceMappingURL=splitContext.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitContext.js","sourceRoot":"","sources":["../../../../dev/sharedUiComponents/src/split/splitContext.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAC;AAEtC,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACtB,qDAAK,CAAA;IACL,uDAAM,CAAA;AACV,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAED,MAAM,CAAN,IAAY,cAGX;AAHD,WAAY,cAAc;IACtB,+DAAU,CAAA;IACV,2DAAQ,CAAA;AACZ,CAAC,EAHW,cAAc,KAAd,cAAc,QAGzB;AAqCD,qBAAqB;AACrB,MAAM,CAAC,MAAM,YAAY,GAAG,aAAa,CAAgB,EAAE,SAAS,EAAE,cAAc,CAAC,UAAU,EAAE,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,OAAO,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,IAAI,EAAE,GAAG,EAAE,GAAE,CAAC,EAAE,CAAC,CAAC","sourcesContent":["import { createContext } from \"react\";\r\n\r\nexport enum ControlledSize {\r\n First,\r\n Second,\r\n}\r\n\r\nexport enum SplitDirection {\r\n Horizontal,\r\n Vertical,\r\n}\r\n\r\n/**\r\n * Context used to share data with splitters\r\n */\r\nexport interface ISplitContext {\r\n /**\r\n * Split direction\r\n */\r\n direction: SplitDirection;\r\n /**\r\n * Function called by splitters to update the offset\r\n * @param offset new offet\r\n * @param source source element\r\n * @param controlledSide defined controlled element\r\n */\r\n drag: (offset: number, source: HTMLElement, controlledSide: ControlledSize) => void;\r\n /**\r\n * Function called by splitters to begin dragging\r\n */\r\n beginDrag: () => void;\r\n /**\r\n * Function called by splitters to end dragging\r\n */\r\n endDrag: () => void;\r\n\r\n /**\r\n * Sync sizes for the elements\r\n * @param source source element\r\n * @param controlledSide defined controlled element\r\n * @param size size of the controlled element\r\n * @param minSize minimum size for the controlled element\r\n * @param maxSize maximum size for the controlled element\r\n */\r\n sync: (source: HTMLElement, controlledSide: ControlledSize, size?: number, minSize?: number, maxSize?: number) => void;\r\n}\r\n\r\n// Create the context\r\nexport const SplitContext = createContext<ISplitContext>({ direction: SplitDirection.Horizontal, drag: () => {}, beginDrag: () => {}, endDrag: () => {}, sync: () => {} });\r\n"]}
@@ -0,0 +1,41 @@
1
+ /// <reference types="react" />
2
+ import type { ControlledSize } from "./splitContext";
3
+ /**
4
+ * Splitter component properties
5
+ */
6
+ export interface ISplitterProps {
7
+ /**
8
+ * Unique identifier
9
+ */
10
+ id?: string;
11
+ /**
12
+ * Splitter size
13
+ */
14
+ size: number;
15
+ /**
16
+ * Minimum size for the controlled element
17
+ */
18
+ minSize?: number;
19
+ /**
20
+ * Maximum size for the controlled element
21
+ */
22
+ maxSize?: number;
23
+ /**
24
+ * Initial size for the controlled element
25
+ */
26
+ initialSize?: number;
27
+ /**
28
+ * Defines the controlled side
29
+ */
30
+ controlledSide: ControlledSize;
31
+ /**
32
+ * refObject to the splitter element
33
+ */
34
+ refObject?: React.RefObject<HTMLDivElement>;
35
+ }
36
+ /**
37
+ * Creates a splitter component
38
+ * @param props defines the splitter properties
39
+ * @returns the splitter component
40
+ */
41
+ export declare const Splitter: React.FC<ISplitterProps>;
@@ -0,0 +1,69 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { useContext, useEffect, useRef } from "react";
3
+ import styles from "./splitContainer.module.scss";
4
+ import { SplitContext, SplitDirection } from "./splitContext.js";
5
+ /**
6
+ * Creates a splitter component
7
+ * @param props defines the splitter properties
8
+ * @returns the splitter component
9
+ */
10
+ export const Splitter = (props) => {
11
+ const elementRef = props.refObject || useRef(null);
12
+ const splitContext = useContext(SplitContext);
13
+ let isCaptured = false;
14
+ let startValue;
15
+ useEffect(() => {
16
+ if (!elementRef.current) {
17
+ return;
18
+ }
19
+ if (splitContext.direction === SplitDirection.Horizontal) {
20
+ elementRef.current.style.width = `${props.size}px`;
21
+ elementRef.current.style.height = `100%`;
22
+ elementRef.current.classList.add(styles["horizontal"]);
23
+ }
24
+ else {
25
+ elementRef.current.style.height = `${props.size}px`;
26
+ elementRef.current.style.width = `100%`;
27
+ elementRef.current.classList.add(styles["vertical"]);
28
+ }
29
+ splitContext.sync(elementRef.current, props.controlledSide, props.initialSize, props.minSize, props.maxSize);
30
+ });
31
+ const onPointerDown = (evt) => {
32
+ if (!elementRef.current) {
33
+ return;
34
+ }
35
+ elementRef.current.setPointerCapture(evt.pointerId);
36
+ isCaptured = true;
37
+ splitContext.beginDrag();
38
+ if (splitContext.direction === SplitDirection.Horizontal) {
39
+ startValue = evt.clientX;
40
+ }
41
+ else {
42
+ startValue = evt.clientY;
43
+ }
44
+ evt.preventDefault();
45
+ };
46
+ const onPointerMove = (evt) => {
47
+ if (!elementRef.current || !isCaptured) {
48
+ return;
49
+ }
50
+ if (splitContext.direction === SplitDirection.Horizontal) {
51
+ splitContext.drag(evt.clientX - startValue, elementRef.current, props.controlledSide);
52
+ }
53
+ else {
54
+ splitContext.drag(evt.clientY - startValue, elementRef.current, props.controlledSide);
55
+ }
56
+ evt.preventDefault();
57
+ };
58
+ const onPointerUp = (evt) => {
59
+ if (!elementRef.current) {
60
+ return;
61
+ }
62
+ elementRef.current.releasePointerCapture(evt.pointerId);
63
+ isCaptured = false;
64
+ splitContext.endDrag();
65
+ evt.preventDefault();
66
+ };
67
+ return (_jsx("div", { id: props.id, className: styles["splitter"], ref: elementRef, onPointerDown: (evt) => onPointerDown(evt), onPointerUp: (evt) => onPointerUp(evt), onPointerMove: (evt) => onPointerMove(evt) }));
68
+ };
69
+ //# sourceMappingURL=splitter.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"splitter.js","sourceRoot":"","sources":["../../../../dev/sharedUiComponents/src/split/splitter.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AACtD,OAAO,MAAM,MAAM,8BAA8B,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AA0C9D;;;;GAIG;AACH,MAAM,CAAC,MAAM,QAAQ,GAA6B,CAAC,KAAK,EAAE,EAAE;IACxD,MAAM,UAAU,GAAoC,KAAK,CAAC,SAAS,IAAI,MAAM,CAAC,IAAI,CAAC,CAAC;IACpF,MAAM,YAAY,GAAG,UAAU,CAAC,YAAY,CAAC,CAAC;IAC9C,IAAI,UAAU,GAAG,KAAK,CAAC;IACvB,IAAI,UAAkB,CAAC;IAEvB,SAAS,CAAC,GAAG,EAAE;QACX,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACrB,OAAO;SACV;QAED,IAAI,YAAY,CAAC,SAAS,KAAK,cAAc,CAAC,UAAU,EAAE;YACtD,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,GAAG,KAAK,CAAC,IAAI,IAAI,CAAC;YACnD,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,MAAM,CAAC;YACzC,UAAU,CAAC,OAAO,CAAC,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;SAC1D;aAAM;YACH,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,IAAI,CAAC;YACpD,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,CAAC;YACxC,UAAU,CAA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,WAAW,GAAG,CAAC,GAAuB,EAAE,EAAE;QAC5C,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE;YACrB,OAAO;SACV;QACD,UAAU,CAAC,OAAO,CAAC,qBAAqB,CAAC,GAAG,CAAC,SAAS,CAAC,CAAC;QACxD,UAAU,GAAG,KAAK,CAAC;QACnB,YAAY,CAAC,OAAO,EAAE,CAAC;QACvB,GAAG,CAAC,cAAc,EAAE,CAAC;IACzB,CAAC,CAAC;IAEF,OAAO,CACH,cACI,EAAE,EAAE,KAAK,CAAC,EAAE,EACZ,SAAS,EAAE,MAAM,CAAC,UAAU,CAAC,EAC7B,GAAG,EAAE,UAAU,EACf,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,EAC1C,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,WAAW,CAAC,GAAG,CAAC,EACtC,aAAa,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,aAAa,CAAC,GAAG,CAAC,GACvC,CACV,CAAC;AACN,CAAC,CAAC","sourcesContent":["import { useContext, useEffect, useRef } from \"react\";\r\nimport styles from \"./splitContainer.module.scss\";\r\nimport type { ControlledSize } from \"./splitContext\";\r\nimport { SplitContext, SplitDirection } from \"./splitContext\";\r\n\r\n/**\r\n * Splitter component properties\r\n */\r\nexport interface ISplitterProps {\r\n /**\r\n * Unique identifier\r\n */\r\n id?: string;\r\n\r\n /**\r\n * Splitter size\r\n */\r\n size: number;\r\n\r\n /**\r\n * Minimum size for the controlled element\r\n */\r\n minSize?: number;\r\n\r\n /**\r\n * Maximum size for the controlled element\r\n */\r\n maxSize?: number;\r\n\r\n /**\r\n * Initial size for the controlled element\r\n */\r\n initialSize?: number;\r\n\r\n /**\r\n * Defines the controlled side\r\n */\r\n controlledSide: ControlledSize;\r\n\r\n /**\r\n * refObject to the splitter element\r\n */\r\n refObject?: React.RefObject<HTMLDivElement>;\r\n}\r\n\r\n/**\r\n * Creates a splitter component\r\n * @param props defines the splitter properties\r\n * @returns the splitter component\r\n */\r\nexport const Splitter: React.FC<ISplitterProps> = (props) => {\r\n const elementRef: React.RefObject<HTMLDivElement> = props.refObject || useRef(null);\r\n const splitContext = useContext(SplitContext);\r\n let isCaptured = false;\r\n let startValue: number;\r\n\r\n useEffect(() => {\r\n if (!elementRef.current) {\r\n return;\r\n }\r\n\r\n if (splitContext.direction === SplitDirection.Horizontal) {\r\n elementRef.current.style.width = `${props.size}px`;\r\n elementRef.current.style.height = `100%`;\r\n elementRef.current.classList.add(styles[\"horizontal\"]);\r\n } else {\r\n elementRef.current.style.height = `${props.size}px`;\r\n elementRef.current.style.width = `100%`;\r\n elementRef.current.classList.add(styles[\"vertical\"]);\r\n }\r\n\r\n splitContext.sync(elementRef.current, props.controlledSide, props.initialSize, props.minSize, props.maxSize);\r\n });\r\n\r\n const onPointerDown = (evt: React.PointerEvent) => {\r\n if (!elementRef.current) {\r\n return;\r\n }\r\n elementRef.current.setPointerCapture(evt.pointerId);\r\n isCaptured = true;\r\n splitContext.beginDrag();\r\n\r\n if (splitContext.direction === SplitDirection.Horizontal) {\r\n startValue = evt.clientX;\r\n } else {\r\n startValue = evt.clientY;\r\n }\r\n evt.preventDefault();\r\n };\r\n const onPointerMove = (evt: React.PointerEvent) => {\r\n if (!elementRef.current || !isCaptured) {\r\n return;\r\n }\r\n if (splitContext.direction === SplitDirection.Horizontal) {\r\n splitContext.drag(evt.clientX - startValue, elementRef.current, props.controlledSide);\r\n } else {\r\n splitContext.drag(evt.clientY - startValue, elementRef.current, props.controlledSide);\r\n }\r\n evt.preventDefault();\r\n };\r\n const onPointerUp = (evt: React.PointerEvent) => {\r\n if (!elementRef.current) {\r\n return;\r\n }\r\n elementRef.current.releasePointerCapture(evt.pointerId);\r\n isCaptured = false;\r\n splitContext.endDrag();\r\n evt.preventDefault();\r\n };\r\n\r\n return (\r\n <div\r\n id={props.id}\r\n className={styles[\"splitter\"]}\r\n ref={elementRef}\r\n onPointerDown={(evt) => onPointerDown(evt)}\r\n onPointerUp={(evt) => onPointerUp(evt)}\r\n onPointerMove={(evt) => onPointerMove(evt)}\r\n ></div>\r\n );\r\n};\r\n"]}
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Copy all styles from a document to another document or shadow root
3
+ * @param source document to copy styles from
4
+ * @param target document or shadow root to copy styles to
5
+ */
6
+ export declare function CopyStyles(source: Document, target: Document): void;
package/styleHelper.js ADDED
@@ -0,0 +1,21 @@
1
+ /**
2
+ * Copy all styles from a document to another document or shadow root
3
+ * @param source document to copy styles from
4
+ * @param target document or shadow root to copy styles to
5
+ */
6
+ export function CopyStyles(source, target) {
7
+ // Copy all <style> elements
8
+ Array.from(source.querySelectorAll("style")).forEach((style) => {
9
+ const newStyle = target.createElement("style");
10
+ newStyle.textContent = style.textContent;
11
+ target.head.appendChild(newStyle);
12
+ });
13
+ // Copy all <link> elements for stylesheets
14
+ Array.from(source.querySelectorAll('link[rel="stylesheet"]')).forEach((link) => {
15
+ const newLink = target.createElement("link");
16
+ newLink.rel = "stylesheet";
17
+ newLink.href = link.href;
18
+ target.head.appendChild(newLink);
19
+ });
20
+ }
21
+ //# sourceMappingURL=styleHelper.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"styleHelper.js","sourceRoot":"","sources":["../../../dev/sharedUiComponents/src/styleHelper.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,UAAU,UAAU,CAAC,MAAgB,EAAE,MAAgB;IACzD,4BAA4B;IAC5B,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,KAAK,EAAE,EAAE;QAC3D,MAAM,QAAQ,GAAG,MAAM,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;QAC/C,QAAQ,CAAC,WAAW,GAAG,KAAK,CAAC,WAAW,CAAC;QACzC,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,2CAA2C;IAC3C,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,gBAAgB,CAAC,wBAAwB,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,IAAI,EAAE,EAAE;QAC3E,MAAM,OAAO,GAAG,MAAM,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QAC7C,OAAO,CAAC,GAAG,GAAG,YAAY,CAAC;QAC3B,OAAO,CAAC,IAAI,GAAI,IAAwB,CAAC,IAAI,CAAC;QAC9C,MAAM,CAAC,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACrC,CAAC,CAAC,CAAC;AACP,CAAC","sourcesContent":["/**\r\n * Copy all styles from a document to another document or shadow root\r\n * @param source document to copy styles from\r\n * @param target document or shadow root to copy styles to\r\n */\r\nexport function CopyStyles(source: Document, target: Document) {\r\n // Copy all <style> elements\r\n Array.from(source.querySelectorAll(\"style\")).forEach((style) => {\r\n const newStyle = target.createElement(\"style\");\r\n newStyle.textContent = style.textContent;\r\n target.head.appendChild(newStyle);\r\n });\r\n\r\n // Copy all <link> elements for stylesheets\r\n Array.from(source.querySelectorAll('link[rel=\"stylesheet\"]')).forEach((link) => {\r\n const newLink = target.createElement(\"link\");\r\n newLink.rel = \"stylesheet\";\r\n newLink.href = (link as HTMLLinkElement).href;\r\n target.head.appendChild(newLink);\r\n });\r\n}\r\n"]}