@babylonjs/shared-ui-components 7.34.2 → 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.
- package/nodeGraphSystem/graphFrame.js +1 -1
- package/nodeGraphSystem/graphFrame.js.map +1 -1
- package/nodeGraphSystem/graphNode.js +2 -2
- package/nodeGraphSystem/graphNode.js.map +1 -1
- package/nodeGraphSystem/graphNode.module.scss +1 -1
- package/package.json +1 -1
- package/popupHelper.d.ts +12 -0
- package/popupHelper.js +57 -0
- package/popupHelper.js.map +1 -0
- package/split/splitContainer.d.ts +58 -0
- package/split/splitContainer.js +232 -0
- package/split/splitContainer.js.map +1 -0
- package/split/splitContainer.module.scss +25 -0
- package/split/splitContext.d.ts +43 -0
- package/split/splitContext.js +14 -0
- package/split/splitContext.js.map +1 -0
- package/split/splitter.d.ts +41 -0
- package/split/splitter.js +69 -0
- package/split/splitter.js.map +1 -0
- package/styleHelper.d.ts +6 -0
- package/styleHelper.js +21 -0
- package/styleHelper.js.map +1 -0
- package/lines/popup.d.ts +0 -4
- package/lines/popup.js +0 -69
- package/lines/popup.js.map +0 -1
@@ -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,MA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QACD,WAAW,CAAC,KAAK,CAAC,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;QACjC,aAAa,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC;IAChC,CAAC,CAAC;IAEF,OAAO,CACH,KAAC,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
|
@@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ACV;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"]}
|
package/styleHelper.d.ts
ADDED
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"]}
|
package/lines/popup.d.ts
DELETED
package/lines/popup.js
DELETED
@@ -1,69 +0,0 @@
|
|
1
|
-
export class Popup {
|
2
|
-
static CreatePopup(title, windowVariableName, width = 300, height = 800) {
|
3
|
-
const windowCreationOptionsList = {
|
4
|
-
width: width,
|
5
|
-
height: height,
|
6
|
-
top: (window.innerHeight - width) / 2 + window.screenY,
|
7
|
-
left: (window.innerWidth - height) / 2 + window.screenX,
|
8
|
-
};
|
9
|
-
const windowCreationOptions = Object.keys(windowCreationOptionsList)
|
10
|
-
.map((key) => key + "=" + windowCreationOptionsList[key])
|
11
|
-
.join(",");
|
12
|
-
const popupWindow = window.open("", title, windowCreationOptions);
|
13
|
-
if (!popupWindow) {
|
14
|
-
return null;
|
15
|
-
}
|
16
|
-
const parentDocument = popupWindow.document;
|
17
|
-
// Font
|
18
|
-
const newLinkEl = parentDocument.createElement("link");
|
19
|
-
newLinkEl.rel = "stylesheet";
|
20
|
-
newLinkEl.href = "https://use.typekit.net/cta4xsb.css";
|
21
|
-
parentDocument.head.appendChild(newLinkEl);
|
22
|
-
parentDocument.title = title;
|
23
|
-
parentDocument.body.style.width = "100%";
|
24
|
-
parentDocument.body.style.height = "100%";
|
25
|
-
parentDocument.body.style.margin = "0";
|
26
|
-
parentDocument.body.style.padding = "0";
|
27
|
-
const parentControl = parentDocument.createElement("div");
|
28
|
-
parentControl.style.width = "100%";
|
29
|
-
parentControl.style.height = "100%";
|
30
|
-
parentControl.style.margin = "0";
|
31
|
-
parentControl.style.padding = "0";
|
32
|
-
popupWindow.document.body.appendChild(parentControl);
|
33
|
-
this._CopyStyles(window.document, parentDocument);
|
34
|
-
setTimeout(() => {
|
35
|
-
// need this for late bindings
|
36
|
-
this._CopyStyles(window.document, parentDocument);
|
37
|
-
}, 0);
|
38
|
-
this[windowVariableName] = popupWindow;
|
39
|
-
return parentControl;
|
40
|
-
}
|
41
|
-
static _CopyStyles(sourceDoc, targetDoc) {
|
42
|
-
for (let index = 0; index < sourceDoc.styleSheets.length; index++) {
|
43
|
-
const styleSheet = sourceDoc.styleSheets[index];
|
44
|
-
try {
|
45
|
-
if (styleSheet.cssRules) {
|
46
|
-
// for <style> elements
|
47
|
-
const newStyleEl = sourceDoc.createElement("style");
|
48
|
-
for (const cssRule of styleSheet.cssRules) {
|
49
|
-
// write the text of each rule into the body of the style element
|
50
|
-
newStyleEl.appendChild(sourceDoc.createTextNode(cssRule.cssText));
|
51
|
-
}
|
52
|
-
targetDoc.head.appendChild(newStyleEl);
|
53
|
-
}
|
54
|
-
else if (styleSheet.href) {
|
55
|
-
// for <link> elements loading CSS from a URL
|
56
|
-
const newLinkEl = sourceDoc.createElement("link");
|
57
|
-
newLinkEl.rel = "stylesheet";
|
58
|
-
newLinkEl.href = styleSheet.href;
|
59
|
-
targetDoc.head.appendChild(newLinkEl);
|
60
|
-
}
|
61
|
-
}
|
62
|
-
catch (e) {
|
63
|
-
// eslint-disable-next-line no-console
|
64
|
-
console.log(e);
|
65
|
-
}
|
66
|
-
}
|
67
|
-
}
|
68
|
-
}
|
69
|
-
//# sourceMappingURL=popup.js.map
|
package/lines/popup.js.map
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"popup.js","sourceRoot":"","sources":["../../../../dev/sharedUiComponents/src/lines/popup.ts"],"names":[],"mappings":"AAAA,MAAM,OAAO,KAAK;IACP,MAAM,CAAC,WAAW,CAAC,KAAa,EAAE,kBAA0B,EAAE,KAAK,GAAG,GAAG,EAAE,MAAM,GAAG,GAAG;QAC1F,MAAM,yBAAyB,GAAG;YAC9B,KAAK,EAAE,KAAK;YACZ,MAAM,EAAE,MAAM;YACd,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,GAAG,KAAK,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO;YACtD,IAAI,EAAE,CAAC,MAAM,CAAC,UAAU,GAAG,MAAM,CAAC,GAAG,CAAC,GAAG,MAAM,CAAC,OAAO;SAC1D,CAAC;QAEF,MAAM,qBAAqB,GAAG,MAAM,CAAC,IAAI,CAAC,yBAAyB,CAAC;aAC/D,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,GAAG,GAAG,GAAG,GAAI,yBAAiC,CAAC,GAAG,CAAC,CAAC;aACjE,IAAI,CAAC,GAAG,CAAC,CAAC;QAEf,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,CAAC,EAAE,EAAE,KAAK,EAAE,qBAAqB,CAAC,CAAC;QAClE,IAAI,CAAC,WAAW,EAAE;YACd,OAAO,IAAI,CAAC;SACf;QAED,MAAM,cAAc,GAAG,WAAW,CAAC,QAAQ,CAAC;QAE5C,OAAO;QACP,MAAM,SAAS,GAAG,cAAc,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;QA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AG,SAAS,CAAC,WAAW,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;YAC/D,MAAM,UAAU,GAAQ,SAAS,CAAC,WAAW,CAAC,KAAK,CAAC,CAAC;YACrD,IAAI;gBACA,IAAI,UAAU,CAAC,QAAQ,EAAE;oBACrB,uBAAuB;oBACvB,MAAM,UAAU,GAAG,SAAS,CAAC,aAAa,CAAC,OAAO,CAAC,CAAC;oBAEpD,KAAK,MAAM,OAAO,IAAI,UAAU,CAAC,QAAQ,EAAE;wBACvC,iEAAiE;wBACjE,UAAU,CAAC,WAAW,CAAC,SAAS,CAAC,cAAc,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;qBACrE;oBAED,SAAS,CAAC,IAAK,CAAC,WAAW,CAAC,UAAU,CAAC,CAAC;iBAC3C;qBAAM,IAAI,UAAU,CAAC,IAAI,EAAE;oBACxB,6CAA6C;oBAC7C,MAAM,SAAS,GAAG,SAAS,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;oBAElD,SAAS,CAAC,GAAG,GAAG,YAAY,CAAC;oBAC7B,SAAS,CAAC,IAAI,GAAG,UAAU,CAAC,IAAI,CAAC;oBACjC,SAAS,CAAC,IAAK,CAAC,WAAW,CAAC,SAAS,CAAC,CAAC;iBAC1C;aACJ;YAAC,OAAO,CAAC,EAAE;gBACR,sCAAsC;gBACtC,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;aAClB;SACJ;IACL,CAAC;CACJ","sourcesContent":["export class Popup {\r\n public static CreatePopup(title: string, windowVariableName: string, width = 300, height = 800) {\r\n const windowCreationOptionsList = {\r\n width: width,\r\n height: height,\r\n top: (window.innerHeight - width) / 2 + window.screenY,\r\n left: (window.innerWidth - 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 popupWindow.document.body.appendChild(parentControl);\r\n this._CopyStyles(window.document, parentDocument);\r\n setTimeout(() => {\r\n // need this for late bindings\r\n this._CopyStyles(window.document, parentDocument);\r\n }, 0);\r\n\r\n (this as any)[windowVariableName] = popupWindow;\r\n\r\n return parentControl;\r\n }\r\n\r\n private static _CopyStyles(sourceDoc: HTMLDocument, targetDoc: HTMLDocument) {\r\n for (let index = 0; index < sourceDoc.styleSheets.length; index++) {\r\n const styleSheet: any = sourceDoc.styleSheets[index];\r\n try {\r\n if (styleSheet.cssRules) {\r\n // for <style> elements\r\n const newStyleEl = sourceDoc.createElement(\"style\");\r\n\r\n for (const cssRule of styleSheet.cssRules) {\r\n // write the text of each rule into the body of the style element\r\n newStyleEl.appendChild(sourceDoc.createTextNode(cssRule.cssText));\r\n }\r\n\r\n targetDoc.head!.appendChild(newStyleEl);\r\n } else if (styleSheet.href) {\r\n // for <link> elements loading CSS from a URL\r\n const newLinkEl = sourceDoc.createElement(\"link\");\r\n\r\n newLinkEl.rel = \"stylesheet\";\r\n newLinkEl.href = styleSheet.href;\r\n targetDoc.head!.appendChild(newLinkEl);\r\n }\r\n } catch (e) {\r\n // eslint-disable-next-line no-console\r\n console.log(e);\r\n }\r\n }\r\n }\r\n}\r\n"]}
|