@vuu-ui/vuu-layout 0.5.4 → 0.5.6
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/README.md +1 -0
- package/cjs/index.js +4 -7379
- package/cjs/index.js.map +7 -0
- package/esm/index.js +20 -0
- package/esm/index.js.map +7 -0
- package/index.css +1 -951
- package/index.css.map +3 -3
- package/package.json +5 -9
- package/src/Component.css +0 -2
- package/src/Component.tsx +0 -20
- package/src/DraggableLayout.css +0 -18
- package/src/DraggableLayout.tsx +0 -29
- package/src/__tests__/flexbox-utils.spec.js +0 -90
- package/src/action-buttons/index.ts +0 -1
- package/src/chest-of-drawers/Chest.css +0 -36
- package/src/chest-of-drawers/Chest.tsx +0 -42
- package/src/chest-of-drawers/Drawer.css +0 -159
- package/src/chest-of-drawers/Drawer.tsx +0 -118
- package/src/chest-of-drawers/index.ts +0 -2
- package/src/common-types.ts +0 -9
- package/src/debug.ts +0 -16
- package/src/dialog/Dialog.css +0 -16
- package/src/dialog/Dialog.tsx +0 -59
- package/src/dialog/index.ts +0 -1
- package/src/drag-drop/BoxModel.ts +0 -546
- package/src/drag-drop/DragState.ts +0 -222
- package/src/drag-drop/Draggable.ts +0 -282
- package/src/drag-drop/DropMenu.css +0 -71
- package/src/drag-drop/DropMenu.tsx +0 -61
- package/src/drag-drop/DropTarget.ts +0 -392
- package/src/drag-drop/DropTargetRenderer.css +0 -40
- package/src/drag-drop/DropTargetRenderer.tsx +0 -279
- package/src/drag-drop/dragDropTypes.ts +0 -49
- package/src/drag-drop/index.ts +0 -4
- package/src/editable-label/EditableLabel.css +0 -28
- package/src/editable-label/EditableLabel.tsx +0 -99
- package/src/editable-label/index.ts +0 -1
- package/src/flexbox/Flexbox.css +0 -45
- package/src/flexbox/Flexbox.tsx +0 -70
- package/src/flexbox/FlexboxLayout.jsx +0 -26
- package/src/flexbox/FluidGrid.css +0 -134
- package/src/flexbox/FluidGrid.tsx +0 -84
- package/src/flexbox/FluidGridLayout.tsx +0 -10
- package/src/flexbox/Splitter.css +0 -140
- package/src/flexbox/Splitter.tsx +0 -135
- package/src/flexbox/flexbox-utils.ts +0 -128
- package/src/flexbox/flexboxTypes.ts +0 -63
- package/src/flexbox/index.ts +0 -4
- package/src/flexbox/useResponsiveSizing.ts +0 -85
- package/src/flexbox/useSplitterResizing.ts +0 -272
- package/src/index.ts +0 -21
- package/src/layout-action.ts +0 -21
- package/src/layout-header/ActionButton.tsx +0 -23
- package/src/layout-header/Header.css +0 -8
- package/src/layout-header/Header.tsx +0 -222
- package/src/layout-header/index.ts +0 -1
- package/src/layout-provider/LayoutProvider.tsx +0 -160
- package/src/layout-provider/LayoutProviderContext.ts +0 -17
- package/src/layout-provider/index.ts +0 -2
- package/src/layout-provider/useLayoutDragDrop.ts +0 -241
- package/src/layout-reducer/flexUtils.ts +0 -281
- package/src/layout-reducer/index.ts +0 -4
- package/src/layout-reducer/insert-layout-element.ts +0 -365
- package/src/layout-reducer/layout-reducer.ts +0 -255
- package/src/layout-reducer/layoutTypes.ts +0 -151
- package/src/layout-reducer/layoutUtils.ts +0 -302
- package/src/layout-reducer/remove-layout-element.ts +0 -240
- package/src/layout-reducer/replace-layout-element.ts +0 -118
- package/src/layout-reducer/resize-flex-children.ts +0 -56
- package/src/layout-reducer/wrap-layout-element.ts +0 -317
- package/src/layout-view/View.css +0 -61
- package/src/layout-view/View.tsx +0 -149
- package/src/layout-view/ViewContext.ts +0 -31
- package/src/layout-view/index.ts +0 -4
- package/src/layout-view/useView.tsx +0 -104
- package/src/layout-view/useViewActionDispatcher.ts +0 -133
- package/src/layout-view/useViewResize.ts +0 -53
- package/src/layout-view/viewTypes.ts +0 -37
- package/src/menu/ContextMenu.css +0 -22
- package/src/menu/ContextMenu.jsx +0 -121
- package/src/menu/MenuList.css +0 -150
- package/src/menu/MenuList.jsx +0 -179
- package/src/menu/aim/aim.js +0 -92
- package/src/menu/aim/corners.js +0 -114
- package/src/menu/aim/point-in-polygon.js +0 -25
- package/src/menu/aim/utils.js +0 -19
- package/src/menu/context-menu-provider.jsx +0 -135
- package/src/menu/index.js +0 -4
- package/src/menu/key-code.js +0 -61
- package/src/menu/list-dom-utils.js +0 -22
- package/src/menu/use-cascade.js +0 -292
- package/src/menu/use-click-away.js +0 -22
- package/src/menu/use-items-with-ids.js +0 -75
- package/src/menu/use-keyboard-navigation.js +0 -162
- package/src/menu/utils.js +0 -5
- package/src/palette/Palette.css +0 -37
- package/src/palette/Palette.tsx +0 -140
- package/src/palette/PaletteSalt.css +0 -9
- package/src/palette/PaletteSalt.tsx +0 -79
- package/src/palette/index.ts +0 -2
- package/src/placeholder/Placeholder.css +0 -10
- package/src/placeholder/Placeholder.tsx +0 -39
- package/src/placeholder/index.ts +0 -1
- package/src/popup/index.js +0 -2
- package/src/popup/popup-provider.js +0 -0
- package/src/popup/popup-service.css +0 -15
- package/src/popup/popup-service.js +0 -281
- package/src/portal/Portal.jsx +0 -50
- package/src/portal/index.ts +0 -3
- package/src/portal/render-portal.jsx +0 -68
- package/src/portal/utils.js +0 -16
- package/src/registry/ComponentRegistry.ts +0 -35
- package/src/registry/index.ts +0 -1
- package/src/responsive/OverflowMenu.css +0 -31
- package/src/responsive/OverflowMenu.jsx +0 -56
- package/src/responsive/breakpoints.ts +0 -62
- package/src/responsive/index.ts +0 -4
- package/src/responsive/measureMinimumNodeSize.ts +0 -23
- package/src/responsive/overflowUtils.js +0 -14
- package/src/responsive/use-breakpoints.ts +0 -100
- package/src/responsive/useOverflowObserver.ts +0 -606
- package/src/responsive/useResizeObserver.ts +0 -154
- package/src/responsive/utils.ts +0 -37
- package/src/stack/Stack.css +0 -39
- package/src/stack/Stack.tsx +0 -161
- package/src/stack/StackLayout.tsx +0 -137
- package/src/stack/index.ts +0 -3
- package/src/stack/stackTypes.ts +0 -19
- package/src/tabs/TabPanel.css +0 -12
- package/src/tabs/TabPanel.tsx +0 -17
- package/src/tabs/index.ts +0 -1
- package/src/tools/config-wrapper/ConfigWrapper.jsx +0 -53
- package/src/tools/config-wrapper/index.js +0 -1
- package/src/tools/devtools-box/layout-configurator.css +0 -112
- package/src/tools/devtools-box/layout-configurator.jsx +0 -369
- package/src/tools/devtools-tree/layout-tree-viewer.css +0 -15
- package/src/tools/devtools-tree/layout-tree-viewer.jsx +0 -36
- package/src/tools/index.js +0 -3
- package/src/use-persistent-state.ts +0 -115
- package/src/utils/apply-handlers.js +0 -15
- package/src/utils/componentFromLayout.tsx +0 -30
- package/src/utils/index.ts +0 -6
- package/src/utils/pathUtils.ts +0 -294
- package/src/utils/propUtils.ts +0 -24
- package/src/utils/refUtils.ts +0 -16
- package/src/utils/styleUtils.ts +0 -14
- package/src/utils/typeOf.ts +0 -22
package/src/palette/Palette.tsx
DELETED
|
@@ -1,140 +0,0 @@
|
|
|
1
|
-
import { List, ListItem, ListItemProps } from "@heswell/salt-lab";
|
|
2
|
-
import { uuid } from "@vuu-ui/vuu-utils";
|
|
3
|
-
import cx from "classnames";
|
|
4
|
-
import {
|
|
5
|
-
cloneElement,
|
|
6
|
-
HTMLAttributes,
|
|
7
|
-
memo,
|
|
8
|
-
MouseEvent,
|
|
9
|
-
ReactElement,
|
|
10
|
-
} from "react";
|
|
11
|
-
import { useLayoutProviderDispatch } from "../layout-provider";
|
|
12
|
-
import { View } from "../layout-view";
|
|
13
|
-
import { registerComponent } from "../registry/ComponentRegistry";
|
|
14
|
-
|
|
15
|
-
import "./Palette.css";
|
|
16
|
-
|
|
17
|
-
const clonePaletteItem = (paletteItem: HTMLElement) => {
|
|
18
|
-
const dolly = paletteItem.cloneNode(true) as HTMLElement;
|
|
19
|
-
dolly.id = "";
|
|
20
|
-
delete dolly.dataset.idx;
|
|
21
|
-
return dolly;
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
export interface PaletteItemProps extends ListItemProps {
|
|
25
|
-
children: ReactElement;
|
|
26
|
-
closeable?: boolean;
|
|
27
|
-
header?: boolean;
|
|
28
|
-
idx?: number;
|
|
29
|
-
resize?: "defer";
|
|
30
|
-
resizeable?: boolean;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
export const PaletteItem = memo(
|
|
34
|
-
({
|
|
35
|
-
className,
|
|
36
|
-
children: component,
|
|
37
|
-
idx,
|
|
38
|
-
resizeable,
|
|
39
|
-
header,
|
|
40
|
-
closeable,
|
|
41
|
-
...props
|
|
42
|
-
}: PaletteItemProps) => {
|
|
43
|
-
return (
|
|
44
|
-
<ListItem
|
|
45
|
-
className={cx("vuuPaletteItem", className)}
|
|
46
|
-
data-icon="grab-handle"
|
|
47
|
-
{...props}
|
|
48
|
-
/>
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
|
|
53
|
-
PaletteItem.displayName = "PaletteItem";
|
|
54
|
-
|
|
55
|
-
export interface PaletteProps
|
|
56
|
-
extends Omit<HTMLAttributes<HTMLDivElement>, "onSelect"> {
|
|
57
|
-
children: ReactElement[];
|
|
58
|
-
orientation: "horizontal" | "vertical";
|
|
59
|
-
selection?: string;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
export const Palette = ({
|
|
63
|
-
children,
|
|
64
|
-
className,
|
|
65
|
-
orientation = "horizontal",
|
|
66
|
-
...props
|
|
67
|
-
}: PaletteProps) => {
|
|
68
|
-
const dispatch = useLayoutProviderDispatch();
|
|
69
|
-
const classBase = "vuuPalette";
|
|
70
|
-
|
|
71
|
-
function handleMouseDown(evt: MouseEvent) {
|
|
72
|
-
const target = evt.target as HTMLElement;
|
|
73
|
-
const listItemElement = target.closest(".vuuPaletteItem") as HTMLElement;
|
|
74
|
-
const idx = parseInt(listItemElement.dataset.idx ?? "-1");
|
|
75
|
-
if (idx !== -1) {
|
|
76
|
-
console.log({
|
|
77
|
-
children,
|
|
78
|
-
idx,
|
|
79
|
-
listItemElement,
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
const {
|
|
83
|
-
props: { caption, children: payload, template, ...props },
|
|
84
|
-
} = children[idx];
|
|
85
|
-
const { height, left, top, width } =
|
|
86
|
-
listItemElement.getBoundingClientRect();
|
|
87
|
-
const id = uuid();
|
|
88
|
-
const identifiers = { id, key: id };
|
|
89
|
-
const component = template ? (
|
|
90
|
-
payload
|
|
91
|
-
) : (
|
|
92
|
-
<View {...identifiers} {...props} title={props.label}>
|
|
93
|
-
{payload}
|
|
94
|
-
</View>
|
|
95
|
-
);
|
|
96
|
-
|
|
97
|
-
dispatch({
|
|
98
|
-
dragRect: {
|
|
99
|
-
left,
|
|
100
|
-
top,
|
|
101
|
-
right: left + width,
|
|
102
|
-
bottom: top + 150,
|
|
103
|
-
width,
|
|
104
|
-
height,
|
|
105
|
-
},
|
|
106
|
-
dragElement: clonePaletteItem(listItemElement),
|
|
107
|
-
evt: evt.nativeEvent,
|
|
108
|
-
instructions: {
|
|
109
|
-
DoNotRemove: true,
|
|
110
|
-
DoNotTransform: true,
|
|
111
|
-
RemoveDraggableOnDragEnd: true,
|
|
112
|
-
dragThreshold: 10,
|
|
113
|
-
},
|
|
114
|
-
path: "*",
|
|
115
|
-
payload: component,
|
|
116
|
-
type: "drag-start",
|
|
117
|
-
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return (
|
|
121
|
-
<List
|
|
122
|
-
{...props}
|
|
123
|
-
borderless
|
|
124
|
-
className={cx(classBase, className, `${classBase}-${orientation}`)}
|
|
125
|
-
maxHeight={800}
|
|
126
|
-
selected={null}
|
|
127
|
-
>
|
|
128
|
-
{children.map((child, idx) =>
|
|
129
|
-
child.type === PaletteItem
|
|
130
|
-
? cloneElement(child, {
|
|
131
|
-
key: idx,
|
|
132
|
-
onMouseDown: handleMouseDown,
|
|
133
|
-
})
|
|
134
|
-
: child
|
|
135
|
-
)}
|
|
136
|
-
</List>
|
|
137
|
-
);
|
|
138
|
-
};
|
|
139
|
-
|
|
140
|
-
registerComponent("Palette", Palette, "view");
|
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
import { List, ListItem, ListItemProps, ListProps } from "@heswell/salt-lab";
|
|
2
|
-
import { uuid } from "@vuu-ui/vuu-utils";
|
|
3
|
-
import cx from "classnames";
|
|
4
|
-
import { MouseEvent, ReactElement } from "react";
|
|
5
|
-
import { useLayoutProviderDispatch } from "../layout-provider";
|
|
6
|
-
import { View } from "../layout-view";
|
|
7
|
-
import { registerComponent } from "../registry/ComponentRegistry";
|
|
8
|
-
|
|
9
|
-
import "./PaletteSalt.css";
|
|
10
|
-
|
|
11
|
-
const classBase = "vuuPalette";
|
|
12
|
-
|
|
13
|
-
export interface PaletteListItemProps extends ListItemProps {
|
|
14
|
-
children: ReactElement;
|
|
15
|
-
ViewProps: {
|
|
16
|
-
header?: boolean;
|
|
17
|
-
closeable?: boolean;
|
|
18
|
-
resizeable?: boolean;
|
|
19
|
-
};
|
|
20
|
-
template: boolean;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
export const PaletteListItem = (props: PaletteListItemProps) => {
|
|
24
|
-
const { children, ViewProps, label, onMouseDown, template, ...restProps } =
|
|
25
|
-
props;
|
|
26
|
-
const dispatch = useLayoutProviderDispatch();
|
|
27
|
-
|
|
28
|
-
const handleMouseDown = (evt: MouseEvent<HTMLDivElement>) => {
|
|
29
|
-
const { left, top, width } = evt.currentTarget.getBoundingClientRect();
|
|
30
|
-
const id = uuid();
|
|
31
|
-
const identifiers = { id, key: id };
|
|
32
|
-
const component = template ? (
|
|
33
|
-
children
|
|
34
|
-
) : (
|
|
35
|
-
<View {...identifiers} {...ViewProps} title={props.label}>
|
|
36
|
-
{children}
|
|
37
|
-
</View>
|
|
38
|
-
);
|
|
39
|
-
|
|
40
|
-
dispatch({
|
|
41
|
-
type: "drag-start",
|
|
42
|
-
evt: evt.nativeEvent,
|
|
43
|
-
path: "*",
|
|
44
|
-
payload: component,
|
|
45
|
-
instructions: {
|
|
46
|
-
DoNotRemove: true,
|
|
47
|
-
DoNotTransform: true,
|
|
48
|
-
RemoveDraggableOnDragEnd: true,
|
|
49
|
-
dragThreshold: 10,
|
|
50
|
-
},
|
|
51
|
-
dragRect: {
|
|
52
|
-
left,
|
|
53
|
-
top,
|
|
54
|
-
right: left + width,
|
|
55
|
-
bottom: top + 150,
|
|
56
|
-
width,
|
|
57
|
-
height: 100,
|
|
58
|
-
},
|
|
59
|
-
});
|
|
60
|
-
};
|
|
61
|
-
return (
|
|
62
|
-
<ListItem onMouseDown={handleMouseDown} {...restProps}>
|
|
63
|
-
{label}
|
|
64
|
-
</ListItem>
|
|
65
|
-
);
|
|
66
|
-
};
|
|
67
|
-
|
|
68
|
-
export const PaletteSalt = ({ className, ...props }: ListProps) => {
|
|
69
|
-
return (
|
|
70
|
-
<List
|
|
71
|
-
{...props}
|
|
72
|
-
className={cx(classBase, className)}
|
|
73
|
-
height="100%"
|
|
74
|
-
selectionStrategy="none"
|
|
75
|
-
/>
|
|
76
|
-
);
|
|
77
|
-
};
|
|
78
|
-
|
|
79
|
-
registerComponent("PaletteSalt", PaletteSalt, "view");
|
package/src/palette/index.ts
DELETED
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import React, { HTMLAttributes } from "react";
|
|
2
|
-
import cx from "classnames";
|
|
3
|
-
import { registerComponent } from "../registry/ComponentRegistry";
|
|
4
|
-
|
|
5
|
-
import "./Placeholder.css";
|
|
6
|
-
|
|
7
|
-
const classBase = "vuuPlaceholder";
|
|
8
|
-
|
|
9
|
-
export interface PlaceholderProps extends HTMLAttributes<HTMLDivElement> {
|
|
10
|
-
closeable?: boolean;
|
|
11
|
-
flexFill?: boolean;
|
|
12
|
-
resizeable?: boolean;
|
|
13
|
-
shim?: boolean;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
export const Placeholder = ({
|
|
17
|
-
className,
|
|
18
|
-
closeable,
|
|
19
|
-
flexFill,
|
|
20
|
-
resizeable,
|
|
21
|
-
shim,
|
|
22
|
-
...props
|
|
23
|
-
}: PlaceholderProps) => {
|
|
24
|
-
return (
|
|
25
|
-
<div
|
|
26
|
-
className={cx(classBase, className, {
|
|
27
|
-
[`${classBase}-shim`]: shim,
|
|
28
|
-
})}
|
|
29
|
-
{...props}
|
|
30
|
-
data-placeholder
|
|
31
|
-
data-resizeable
|
|
32
|
-
>
|
|
33
|
-
{/* <LayoutProviderVersion /> */}
|
|
34
|
-
</div>
|
|
35
|
-
);
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
Placeholder.displayName = "Placeholder";
|
|
39
|
-
registerComponent("Placeholder", Placeholder);
|
package/src/placeholder/index.ts
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './Placeholder';
|
package/src/popup/index.js
DELETED
|
File without changes
|
|
@@ -1,281 +0,0 @@
|
|
|
1
|
-
import React, { createElement, useEffect, useRef } from "react";
|
|
2
|
-
import ReactDOM from "react-dom";
|
|
3
|
-
import { renderPortal } from "../portal";
|
|
4
|
-
import cx from "classnames";
|
|
5
|
-
|
|
6
|
-
import "./popup-service.css";
|
|
7
|
-
window.popupReact = React;
|
|
8
|
-
|
|
9
|
-
let _dialogOpen = false;
|
|
10
|
-
const _popups = [];
|
|
11
|
-
|
|
12
|
-
function specialKeyHandler(e) {
|
|
13
|
-
if (e.keyCode === 27 /* ESC */) {
|
|
14
|
-
if (_popups.length) {
|
|
15
|
-
closeAllPopups();
|
|
16
|
-
} else if (_dialogOpen) {
|
|
17
|
-
ReactDOM.unmountComponentAtNode(
|
|
18
|
-
document.body.querySelector(".hwReactDialog")
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
function outsideClickHandler(e) {
|
|
25
|
-
if (_popups.length) {
|
|
26
|
-
// onsole.log(`Popup.outsideClickHandler`);
|
|
27
|
-
const popupContainers = document.body.querySelectorAll(".hwReactPopup");
|
|
28
|
-
for (let i = 0; i < popupContainers.length; i++) {
|
|
29
|
-
if (popupContainers[i].contains(e.target)) {
|
|
30
|
-
return;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
closeAllPopups();
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
function closeAllPopups() {
|
|
38
|
-
if (_popups.length) {
|
|
39
|
-
// onsole.log(`closeAllPopups`);
|
|
40
|
-
const popupContainers = document.body.querySelectorAll(".hwReactPopup");
|
|
41
|
-
for (let i = 0; i < popupContainers.length; i++) {
|
|
42
|
-
ReactDOM.unmountComponentAtNode(popupContainers[i]);
|
|
43
|
-
}
|
|
44
|
-
popupClosed("*");
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
function dialogOpened() {
|
|
49
|
-
if (_dialogOpen === false) {
|
|
50
|
-
_dialogOpen = true;
|
|
51
|
-
window.addEventListener("keydown", specialKeyHandler, true);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function dialogClosed() {
|
|
56
|
-
if (_dialogOpen) {
|
|
57
|
-
_dialogOpen = false;
|
|
58
|
-
window.removeEventListener("keydown", specialKeyHandler, true);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
function popupOpened(name /*, group*/) {
|
|
63
|
-
if (_popups.indexOf(name) === -1) {
|
|
64
|
-
_popups.push(name);
|
|
65
|
-
//onsole.log('PopupService, popup opened ' + name + ' popups : ' + _popups);
|
|
66
|
-
if (_dialogOpen === false) {
|
|
67
|
-
window.addEventListener("keydown", specialKeyHandler, true);
|
|
68
|
-
window.addEventListener("click", outsideClickHandler, true);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
function popupClosed(name /*, group=null*/) {
|
|
74
|
-
if (_popups.length) {
|
|
75
|
-
if (name === "*") {
|
|
76
|
-
_popups.length = 0;
|
|
77
|
-
} else {
|
|
78
|
-
const pos = _popups.indexOf(name);
|
|
79
|
-
if (pos !== -1) {
|
|
80
|
-
_popups.splice(pos, 1);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
//onsole.log('PopupService, popup closed ' + name + ' popups : ' + _popups);
|
|
84
|
-
if (_popups.length === 0 && _dialogOpen === false) {
|
|
85
|
-
window.removeEventListener("keydown", specialKeyHandler, true);
|
|
86
|
-
window.removeEventListener("click", outsideClickHandler, true);
|
|
87
|
-
}
|
|
88
|
-
}
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
const PopupComponent = ({ children, position, style }) => {
|
|
92
|
-
const className = cx("hwPopup", "hwPopupContainer", position);
|
|
93
|
-
return createElement("div", { className, style }, children);
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
let incrementingKey = 1;
|
|
97
|
-
|
|
98
|
-
export class PopupService {
|
|
99
|
-
static showPopup({
|
|
100
|
-
name = "anon",
|
|
101
|
-
group = "all",
|
|
102
|
-
position = "",
|
|
103
|
-
left = 0,
|
|
104
|
-
right = "auto",
|
|
105
|
-
top = 0,
|
|
106
|
-
width = "auto",
|
|
107
|
-
component,
|
|
108
|
-
}) {
|
|
109
|
-
if (!component) {
|
|
110
|
-
throw Error(`PopupService showPopup, no component supplied`);
|
|
111
|
-
}
|
|
112
|
-
popupOpened(name, group);
|
|
113
|
-
let el = document.body.querySelector(".hwReactPopup." + group);
|
|
114
|
-
if (el === null) {
|
|
115
|
-
el = document.createElement("div");
|
|
116
|
-
el.className = "hwReactPopup " + group;
|
|
117
|
-
document.body.appendChild(el);
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
const style = { width };
|
|
121
|
-
|
|
122
|
-
renderPortal(
|
|
123
|
-
createElement(
|
|
124
|
-
PopupComponent,
|
|
125
|
-
{ key: incrementingKey++, position, style },
|
|
126
|
-
component
|
|
127
|
-
),
|
|
128
|
-
el,
|
|
129
|
-
left,
|
|
130
|
-
top,
|
|
131
|
-
() => {
|
|
132
|
-
PopupService.keepWithinThePage(el, right);
|
|
133
|
-
}
|
|
134
|
-
);
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
static hidePopup(name = "anon", group = "all") {
|
|
138
|
-
//onsole.log('PopupService.hidePopup name=' + name + ', group=' + group)
|
|
139
|
-
|
|
140
|
-
if (_popups.indexOf(name) !== -1) {
|
|
141
|
-
popupClosed(name, group);
|
|
142
|
-
ReactDOM.unmountComponentAtNode(
|
|
143
|
-
document.body.querySelector(`.hwReactPopup.${group}`)
|
|
144
|
-
);
|
|
145
|
-
}
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
static keepWithinThePage(el, right = "auto") {
|
|
149
|
-
const target = el.querySelector(".hwPopupContainer > *");
|
|
150
|
-
if (target) {
|
|
151
|
-
const {
|
|
152
|
-
top,
|
|
153
|
-
left,
|
|
154
|
-
width,
|
|
155
|
-
height,
|
|
156
|
-
right: currentRight,
|
|
157
|
-
} = target.getBoundingClientRect();
|
|
158
|
-
|
|
159
|
-
const w = window.innerWidth;
|
|
160
|
-
const h = window.innerHeight;
|
|
161
|
-
|
|
162
|
-
const overflowH = h - (top + height);
|
|
163
|
-
if (overflowH < 0) {
|
|
164
|
-
target.style.top = parseInt(top, 10) + overflowH + "px";
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
const overflowW = w - (left + width);
|
|
168
|
-
if (overflowW < 0) {
|
|
169
|
-
target.style.left = parseInt(left, 10) + overflowW + "px";
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
if (typeof right === "number" && right !== currentRight) {
|
|
173
|
-
const adjustment = right - currentRight;
|
|
174
|
-
target.style.left = left + adjustment + "px";
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
export class DialogService {
|
|
181
|
-
static showDialog(dialog) {
|
|
182
|
-
const containerEl = ".hwReactDialog";
|
|
183
|
-
const onClose = dialog.props.onClose;
|
|
184
|
-
|
|
185
|
-
dialogOpened();
|
|
186
|
-
|
|
187
|
-
ReactDOM.render(
|
|
188
|
-
React.cloneElement(dialog, {
|
|
189
|
-
container: containerEl,
|
|
190
|
-
onClose: () => {
|
|
191
|
-
DialogService.closeDialog();
|
|
192
|
-
if (onClose) {
|
|
193
|
-
onClose();
|
|
194
|
-
}
|
|
195
|
-
},
|
|
196
|
-
}),
|
|
197
|
-
document.body.querySelector(containerEl)
|
|
198
|
-
);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
static closeDialog() {
|
|
202
|
-
dialogClosed();
|
|
203
|
-
ReactDOM.unmountComponentAtNode(
|
|
204
|
-
document.body.querySelector(".hwReactDialog")
|
|
205
|
-
);
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
export const Popup = (props) => {
|
|
210
|
-
const pendingTask = useRef(null);
|
|
211
|
-
const ref = useRef(null);
|
|
212
|
-
|
|
213
|
-
const show = (props, boundingClientRect) => {
|
|
214
|
-
const { name, group, depth, width } = props;
|
|
215
|
-
let left, top;
|
|
216
|
-
|
|
217
|
-
if (pendingTask.current) {
|
|
218
|
-
clearTimeout(pendingTask.current);
|
|
219
|
-
pendingTask.current = null;
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
if (props.close === true) {
|
|
223
|
-
PopupService.hidePopup(name, group);
|
|
224
|
-
} else {
|
|
225
|
-
const { position, children: component } = props;
|
|
226
|
-
const {
|
|
227
|
-
left: targetLeft,
|
|
228
|
-
top: targetTop,
|
|
229
|
-
width: clientWidth,
|
|
230
|
-
bottom: targetBottom,
|
|
231
|
-
} = boundingClientRect;
|
|
232
|
-
|
|
233
|
-
if (position === "below") {
|
|
234
|
-
left = targetLeft;
|
|
235
|
-
top = targetBottom;
|
|
236
|
-
} else if (position === "above") {
|
|
237
|
-
left = targetLeft;
|
|
238
|
-
top = targetTop;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
pendingTask.current = setTimeout(() => {
|
|
242
|
-
PopupService.showPopup({
|
|
243
|
-
name,
|
|
244
|
-
group,
|
|
245
|
-
depth,
|
|
246
|
-
position,
|
|
247
|
-
left,
|
|
248
|
-
top,
|
|
249
|
-
width: width || clientWidth,
|
|
250
|
-
component,
|
|
251
|
-
});
|
|
252
|
-
}, 10);
|
|
253
|
-
}
|
|
254
|
-
};
|
|
255
|
-
|
|
256
|
-
useEffect(() => {
|
|
257
|
-
if (ref.current) {
|
|
258
|
-
const el = ref.current.parentElement;
|
|
259
|
-
const boundingClientRect = el.getBoundingClientRect();
|
|
260
|
-
//onsole.log(`%cPopup.componentDidMount about to call show`,'color:green');
|
|
261
|
-
show(props, boundingClientRect);
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
return () => {
|
|
265
|
-
PopupService.hidePopup(props.name, props.group);
|
|
266
|
-
};
|
|
267
|
-
}, [props]);
|
|
268
|
-
|
|
269
|
-
return React.createElement("div", { className: "popup-proxy", ref });
|
|
270
|
-
|
|
271
|
-
// componentWillReceiveProps(nextProps) {
|
|
272
|
-
|
|
273
|
-
// const domNode = ReactDOM.findDOMNode(this);
|
|
274
|
-
// if (domNode) {
|
|
275
|
-
// const el = domNode.parentElement;
|
|
276
|
-
// const boundingClientRect = el.getBoundingClientRect();
|
|
277
|
-
// //onsole.log(`%cPopup.componentWillReceiveProps about to call show`,'color:green');
|
|
278
|
-
// this.show(nextProps, boundingClientRect);
|
|
279
|
-
// }
|
|
280
|
-
// }
|
|
281
|
-
};
|
package/src/portal/Portal.jsx
DELETED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import { useLayoutEffect, useMemo } from 'react';
|
|
2
|
-
import * as ReactDOM from 'react-dom';
|
|
3
|
-
import { createContainer, renderPortal } from './render-portal';
|
|
4
|
-
|
|
5
|
-
export const Portal = function Portal(props) {
|
|
6
|
-
// Do we need to accept container here as a prop ?
|
|
7
|
-
const { children, x, y, onRender } = props;
|
|
8
|
-
let renderContainer = useMemo(() => {
|
|
9
|
-
return createContainer();
|
|
10
|
-
}, []);
|
|
11
|
-
|
|
12
|
-
// console.log(`Portal render x ${x} y ${y}`);
|
|
13
|
-
|
|
14
|
-
// useEffect(() => {
|
|
15
|
-
// console.log(`Portal mounted`);
|
|
16
|
-
// return () => {
|
|
17
|
-
// console.log('Portal unmounted');
|
|
18
|
-
// };
|
|
19
|
-
// }, []);
|
|
20
|
-
|
|
21
|
-
useLayoutEffect(() => {
|
|
22
|
-
renderPortal(children, renderContainer, x, y, onRender);
|
|
23
|
-
}, [children, onRender, renderContainer, x, y]);
|
|
24
|
-
|
|
25
|
-
useLayoutEffect(() => {
|
|
26
|
-
return () => {
|
|
27
|
-
if (renderContainer) {
|
|
28
|
-
ReactDOM.unmountComponentAtNode(renderContainer);
|
|
29
|
-
if (renderContainer.classList.contains('hwReactPopup')) {
|
|
30
|
-
renderContainer.parentElement.removeChild(renderContainer);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
};
|
|
34
|
-
}, [renderContainer]);
|
|
35
|
-
|
|
36
|
-
// useLayoutEffect(() => {
|
|
37
|
-
// renderContainer.current = renderPortal(children, x, y, container)
|
|
38
|
-
// return () => {
|
|
39
|
-
// if (renderContainer.current){
|
|
40
|
-
// console.log('EXPLICIT UNMOUNT')
|
|
41
|
-
// ReactDOM.unmountComponentAtNode(renderContainer.current);
|
|
42
|
-
// if (renderContainer.current.classList.contains('hwReactPopup')){
|
|
43
|
-
// renderContainer.current.parentElement.removeChild(renderContainer.current);
|
|
44
|
-
// renderContainer.current = null;
|
|
45
|
-
// }
|
|
46
|
-
// }
|
|
47
|
-
// }
|
|
48
|
-
// },[])
|
|
49
|
-
return null;
|
|
50
|
-
};
|
package/src/portal/index.ts
DELETED