@vitus-labs/elements 1.2.1 → 1.2.3-alpha.56
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/LICENSE +1 -1
- package/README.md +279 -66
- package/lib/analysis/index.js.html +1 -1
- package/lib/analysis/vitus-labs-elements.native.js.html +1 -1
- package/lib/index.d.ts +835 -850
- package/lib/index.d.ts.map +1 -0
- package/lib/index.js +1290 -1160
- package/lib/index.js.map +1 -1
- package/lib/vitus-labs-elements.native.js +1176 -1060
- package/lib/vitus-labs-elements.native.js.map +1 -1
- package/package.json +24 -24
- package/lib/types/Element/component.d.ts +0 -4
- package/lib/types/Element/component.d.ts.map +0 -1
- package/lib/types/Element/constants.d.ts +0 -51
- package/lib/types/Element/constants.d.ts.map +0 -1
- package/lib/types/Element/index.d.ts +0 -7
- package/lib/types/Element/index.d.ts.map +0 -1
- package/lib/types/Element/types.d.ts +0 -423
- package/lib/types/Element/types.d.ts.map +0 -1
- package/lib/types/Element/utils.d.ts +0 -5
- package/lib/types/Element/utils.d.ts.map +0 -1
- package/lib/types/Element/withEqualSizeBeforeAfter.d.ts +0 -8
- package/lib/types/Element/withEqualSizeBeforeAfter.d.ts.map +0 -1
- package/lib/types/List/component.d.ts +0 -23
- package/lib/types/List/component.d.ts.map +0 -1
- package/lib/types/List/index.d.ts +0 -7
- package/lib/types/List/index.d.ts.map +0 -1
- package/lib/types/List/withActiveState.d.ts +0 -11
- package/lib/types/List/withActiveState.d.ts.map +0 -1
- package/lib/types/Overlay/component.d.ts +0 -52
- package/lib/types/Overlay/component.d.ts.map +0 -1
- package/lib/types/Overlay/context.d.ts +0 -12
- package/lib/types/Overlay/context.d.ts.map +0 -1
- package/lib/types/Overlay/index.d.ts +0 -7
- package/lib/types/Overlay/index.d.ts.map +0 -1
- package/lib/types/Overlay/useOverlay.d.ts +0 -109
- package/lib/types/Overlay/useOverlay.d.ts.map +0 -1
- package/lib/types/Portal/component.d.ts +0 -20
- package/lib/types/Portal/component.d.ts.map +0 -1
- package/lib/types/Portal/index.d.ts +0 -5
- package/lib/types/Portal/index.d.ts.map +0 -1
- package/lib/types/Text/component.d.ts +0 -30
- package/lib/types/Text/component.d.ts.map +0 -1
- package/lib/types/Text/index.d.ts +0 -5
- package/lib/types/Text/index.d.ts.map +0 -1
- package/lib/types/Text/styled.d.ts +0 -3
- package/lib/types/Text/styled.d.ts.map +0 -1
- package/lib/types/Util/component.d.ts +0 -19
- package/lib/types/Util/component.d.ts.map +0 -1
- package/lib/types/Util/index.d.ts +0 -5
- package/lib/types/Util/index.d.ts.map +0 -1
- package/lib/types/constants.d.ts +0 -2
- package/lib/types/constants.d.ts.map +0 -1
- package/lib/types/helpers/Content/component.d.ts +0 -5
- package/lib/types/helpers/Content/component.d.ts.map +0 -1
- package/lib/types/helpers/Content/index.d.ts +0 -3
- package/lib/types/helpers/Content/index.d.ts.map +0 -1
- package/lib/types/helpers/Content/styled.d.ts +0 -3
- package/lib/types/helpers/Content/styled.d.ts.map +0 -1
- package/lib/types/helpers/Content/types.d.ts +0 -31
- package/lib/types/helpers/Content/types.d.ts.map +0 -1
- package/lib/types/helpers/Iterator/component.d.ts +0 -10
- package/lib/types/helpers/Iterator/component.d.ts.map +0 -1
- package/lib/types/helpers/Iterator/index.d.ts +0 -5
- package/lib/types/helpers/Iterator/index.d.ts.map +0 -1
- package/lib/types/helpers/Iterator/types.d.ts +0 -60
- package/lib/types/helpers/Iterator/types.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/component.d.ts +0 -5
- package/lib/types/helpers/Wrapper/component.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/constants.d.ts +0 -6
- package/lib/types/helpers/Wrapper/constants.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/index.d.ts +0 -3
- package/lib/types/helpers/Wrapper/index.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/styled.d.ts +0 -3
- package/lib/types/helpers/Wrapper/styled.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/types.d.ts +0 -42
- package/lib/types/helpers/Wrapper/types.d.ts.map +0 -1
- package/lib/types/helpers/Wrapper/utils.d.ts +0 -4
- package/lib/types/helpers/Wrapper/utils.d.ts.map +0 -1
- package/lib/types/helpers/index.d.ts +0 -4
- package/lib/types/helpers/index.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -18
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/types.d.ts +0 -51
- package/lib/types/types.d.ts.map +0 -1
- package/lib/types/utils.d.ts +0 -2
- package/lib/types/utils.d.ts.map +0 -1
|
@@ -1,1161 +1,1277 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { isFragment } from
|
|
6
|
-
import { createPortal } from
|
|
1
|
+
import { Provider, alignContent, extendCss, makeItResponsive, value } from "@vitus-labs/unistyle";
|
|
2
|
+
import { config, context, isEmpty, omit, pick, render, throttle } from "@vitus-labs/core";
|
|
3
|
+
import { Children, createContext, forwardRef, memo, useCallback, useContext, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
import { isFragment } from "react-is";
|
|
6
|
+
import { createPortal } from "react-dom";
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
//#region src/constants.ts
|
|
9
|
+
const PKG_NAME = "@vitus-labs/elements";
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
//#endregion
|
|
12
|
+
//#region src/utils.ts
|
|
13
|
+
const IS_DEVELOPMENT = process.env.NODE_ENV !== "production";
|
|
11
14
|
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/helpers/Content/styled.ts
|
|
17
|
+
/**
|
|
18
|
+
* Styled component for content areas (before/content/after). Applies
|
|
19
|
+
* responsive flex alignment, gap spacing between slots based on parent
|
|
20
|
+
* direction (margin-right for inline, margin-bottom for rows), and
|
|
21
|
+
* equalCols flex distribution. The "content" slot gets `flex: 1` to
|
|
22
|
+
* fill remaining space between before and after.
|
|
23
|
+
*/
|
|
24
|
+
const { styled: styled$2, css: css$2, component: component$2 } = config;
|
|
25
|
+
const equalColsCSS = `
|
|
15
26
|
flex: 1;
|
|
16
|
-
width: 100%;
|
|
17
|
-
height: 100%;
|
|
18
27
|
`;
|
|
19
|
-
const
|
|
20
|
-
|
|
28
|
+
const typeContentCSS = `
|
|
29
|
+
flex: 1;
|
|
21
30
|
`;
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
31
|
+
const gapDimensions = {
|
|
32
|
+
inline: {
|
|
33
|
+
before: "margin-right",
|
|
34
|
+
after: "margin-left"
|
|
35
|
+
},
|
|
36
|
+
reverseInline: {
|
|
37
|
+
before: "margin-right",
|
|
38
|
+
after: "margin-left"
|
|
39
|
+
},
|
|
40
|
+
rows: {
|
|
41
|
+
before: "margin-bottom",
|
|
42
|
+
after: "margin-top"
|
|
43
|
+
},
|
|
44
|
+
reverseRows: {
|
|
45
|
+
before: "margin-bottom",
|
|
46
|
+
after: "margin-top"
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
const calculateGap = ({ direction, type, value }) => {
|
|
50
|
+
if (!direction || !type || type === "content") return void 0;
|
|
51
|
+
return `${gapDimensions[direction][type]}: ${value};`;
|
|
52
|
+
};
|
|
53
|
+
const styles$2 = ({ css, theme: t, rootSize }) => css`
|
|
25
54
|
${alignContent({
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
55
|
+
direction: t.direction,
|
|
56
|
+
alignX: t.alignX,
|
|
57
|
+
alignY: t.alignY
|
|
29
58
|
})};
|
|
30
59
|
|
|
31
|
-
${t.
|
|
60
|
+
${t.equalCols && equalColsCSS};
|
|
32
61
|
|
|
33
|
-
${
|
|
34
|
-
|
|
35
|
-
|
|
62
|
+
${t.gap && t.contentType && calculateGap({
|
|
63
|
+
direction: t.parentDirection,
|
|
64
|
+
type: t.contentType,
|
|
65
|
+
value: value(t.gap, rootSize)
|
|
66
|
+
})};
|
|
36
67
|
|
|
37
68
|
${t.extraStyles && extendCss(t.extraStyles)};
|
|
38
69
|
`;
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
position: relative;
|
|
42
|
-
${platformCSS$1};
|
|
70
|
+
const StyledComponent = styled$2(component$2)`
|
|
71
|
+
${""};
|
|
43
72
|
|
|
44
|
-
|
|
73
|
+
display: flex;
|
|
74
|
+
align-self: stretch;
|
|
75
|
+
flex-wrap: wrap;
|
|
76
|
+
|
|
77
|
+
${({ $contentType }) => $contentType === "content" && typeContentCSS};
|
|
45
78
|
|
|
46
79
|
${makeItResponsive({
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
80
|
+
key: "$element",
|
|
81
|
+
styles: styles$2,
|
|
82
|
+
css: css$2,
|
|
83
|
+
normalize: true
|
|
51
84
|
})};
|
|
52
85
|
`;
|
|
53
86
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
} }, children));
|
|
76
|
-
}
|
|
77
|
-
});
|
|
87
|
+
//#endregion
|
|
88
|
+
//#region src/helpers/Content/component.tsx
|
|
89
|
+
const Component$9 = ({ contentType, tag, parentDirection, direction, alignX, alignY, equalCols, gap, extendCss, ...props }) => {
|
|
90
|
+
return /* @__PURE__ */ jsx(StyledComponent, {
|
|
91
|
+
as: tag,
|
|
92
|
+
$contentType: contentType,
|
|
93
|
+
$element: {
|
|
94
|
+
contentType,
|
|
95
|
+
parentDirection,
|
|
96
|
+
direction,
|
|
97
|
+
alignX,
|
|
98
|
+
alignY,
|
|
99
|
+
equalCols,
|
|
100
|
+
gap,
|
|
101
|
+
extraStyles: extendCss
|
|
102
|
+
},
|
|
103
|
+
...IS_DEVELOPMENT ? { "data-vl-element": contentType } : {},
|
|
104
|
+
...props
|
|
105
|
+
});
|
|
106
|
+
};
|
|
107
|
+
var component_default = memo(Component$9);
|
|
78
108
|
|
|
79
|
-
|
|
80
|
-
|
|
109
|
+
//#endregion
|
|
110
|
+
//#region src/helpers/Content/index.ts
|
|
111
|
+
var Content_default = component_default;
|
|
112
|
+
|
|
113
|
+
//#endregion
|
|
114
|
+
//#region src/helpers/Wrapper/styled.ts
|
|
115
|
+
/**
|
|
116
|
+
* Styled component for the Element wrapper layer. Handles responsive
|
|
117
|
+
* block/inline-flex display, direction, alignment, and custom CSS injection.
|
|
118
|
+
* Includes special handling for the `parentFix` / `childFix` flags that
|
|
119
|
+
* split flex behavior across two DOM nodes for button/fieldset/legend
|
|
120
|
+
* elements where a single flex container is insufficient.
|
|
121
|
+
*/
|
|
122
|
+
const { styled: styled$1, css: css$1, component: component$1 } = config;
|
|
123
|
+
const childFixCSS = `
|
|
124
|
+
display: flex;
|
|
81
125
|
flex: 1;
|
|
126
|
+
width: 100%;
|
|
127
|
+
height: 100%;
|
|
82
128
|
`;
|
|
83
|
-
const
|
|
84
|
-
|
|
129
|
+
const blockCSS = `
|
|
130
|
+
align-self: stretch;
|
|
85
131
|
`;
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
const gapDimensions = {
|
|
90
|
-
inline: {
|
|
91
|
-
before: 'margin-right',
|
|
92
|
-
after: 'margin-left',
|
|
93
|
-
},
|
|
94
|
-
reverseInline: {
|
|
95
|
-
before: 'margin-right',
|
|
96
|
-
after: 'margin-left',
|
|
97
|
-
},
|
|
98
|
-
rows: {
|
|
99
|
-
before: 'margin-bottom',
|
|
100
|
-
after: 'margin-top',
|
|
101
|
-
},
|
|
102
|
-
reverseRows: {
|
|
103
|
-
before: 'margin-bottom',
|
|
104
|
-
after: 'margin-top',
|
|
105
|
-
},
|
|
106
|
-
};
|
|
107
|
-
const calculateGap = ({ direction, type, value, }) => {
|
|
108
|
-
if (!direction || !type)
|
|
109
|
-
return undefined;
|
|
110
|
-
const finalStyles = `${gapDimensions[direction][type]}: ${value};`;
|
|
111
|
-
return finalStyles;
|
|
112
|
-
};
|
|
113
|
-
// --------------------------------------------------------
|
|
114
|
-
// calculations of styles to be rendered
|
|
115
|
-
// --------------------------------------------------------
|
|
116
|
-
const styles$1 = ({ css, theme: t, rootSize, }) => css `
|
|
132
|
+
const styles$1 = ({ theme: t, css }) => css`
|
|
133
|
+
${false};
|
|
134
|
+
|
|
117
135
|
${alignContent({
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
136
|
+
direction: t.direction,
|
|
137
|
+
alignX: t.alignX,
|
|
138
|
+
alignY: t.alignY
|
|
121
139
|
})};
|
|
122
140
|
|
|
123
|
-
${t.
|
|
141
|
+
${t.block && blockCSS};
|
|
124
142
|
|
|
125
|
-
${
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
direction: t.parentDirection,
|
|
129
|
-
type: t.contentType,
|
|
130
|
-
value: value(t.gap, rootSize),
|
|
131
|
-
})};
|
|
143
|
+
${false};
|
|
144
|
+
${false};
|
|
145
|
+
${false};
|
|
132
146
|
|
|
133
147
|
${t.extraStyles && extendCss(t.extraStyles)};
|
|
134
148
|
`;
|
|
135
|
-
const platformCSS =
|
|
136
|
-
|
|
149
|
+
const platformCSS = `display: flex;`;
|
|
150
|
+
var styled_default$1 = styled$1(component$1)`
|
|
151
|
+
position: relative;
|
|
137
152
|
${platformCSS};
|
|
138
153
|
|
|
139
|
-
|
|
140
|
-
align-self: stretch;
|
|
141
|
-
flex-wrap: wrap;
|
|
142
|
-
|
|
143
|
-
${({ $contentType }) => $contentType === 'content' && typeContentCSS};
|
|
154
|
+
${({ $childFix }) => $childFix && childFixCSS};
|
|
144
155
|
|
|
145
156
|
${makeItResponsive({
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
157
|
+
key: "$element",
|
|
158
|
+
styles: styles$1,
|
|
159
|
+
css: css$1,
|
|
160
|
+
normalize: true
|
|
150
161
|
})};
|
|
151
162
|
`;
|
|
152
163
|
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
164
|
+
//#endregion
|
|
165
|
+
//#region src/helpers/Wrapper/component.tsx
|
|
166
|
+
/**
|
|
167
|
+
* Wrapper component that serves as the outermost styled container for Element.
|
|
168
|
+
* Uses forwardRef for ref forwarding to the underlying DOM node. On web, it
|
|
169
|
+
* detects button/fieldset/legend tags and applies a two-layer flex fix
|
|
170
|
+
* (parent + child Styled) because these HTML elements do not natively
|
|
171
|
+
* support `display: flex` consistently across browsers.
|
|
172
|
+
*/
|
|
173
|
+
const DEV_PROPS = IS_DEVELOPMENT ? { "data-vl-element": "Element" } : {};
|
|
174
|
+
const Component$8 = forwardRef(({ children, tag, block, extendCss, direction, alignX, alignY, equalCols, isInline, ...props }, ref) => {
|
|
175
|
+
return /* @__PURE__ */ jsx(styled_default$1, {
|
|
176
|
+
...props,
|
|
177
|
+
...DEV_PROPS,
|
|
178
|
+
ref,
|
|
179
|
+
as: tag,
|
|
180
|
+
$element: {
|
|
181
|
+
block,
|
|
182
|
+
direction,
|
|
183
|
+
alignX,
|
|
184
|
+
alignY,
|
|
185
|
+
equalCols,
|
|
186
|
+
extraStyles: extendCss
|
|
187
|
+
},
|
|
188
|
+
children
|
|
189
|
+
});
|
|
190
|
+
});
|
|
191
|
+
|
|
192
|
+
//#endregion
|
|
193
|
+
//#region src/helpers/Wrapper/index.ts
|
|
194
|
+
var Wrapper_default = Component$8;
|
|
172
195
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
196
|
+
//#endregion
|
|
197
|
+
//#region src/Element/component.tsx
|
|
198
|
+
/**
|
|
199
|
+
* Core building block of the elements package. Renders a three-section layout
|
|
200
|
+
* (beforeContent / content / afterContent) inside a flex Wrapper. When only
|
|
201
|
+
* content is present, the Wrapper inherits content-level alignment directly
|
|
202
|
+
* to avoid an unnecessary nesting layer. Handles HTML-specific edge cases
|
|
203
|
+
* like void elements (input, img) and inline elements (span, a) by
|
|
204
|
+
* skipping children or switching sub-tags accordingly.
|
|
205
|
+
*/
|
|
206
|
+
const defaultDirection = "inline";
|
|
207
|
+
const defaultContentDirection = "rows";
|
|
208
|
+
const defaultAlignX = "left";
|
|
209
|
+
const defaultAlignY = "center";
|
|
177
210
|
const Component$7 = forwardRef(({ innerRef, tag, label, content, children, beforeContent, afterContent, block, equalCols, gap, direction, alignX = defaultAlignX, alignY = defaultAlignY, css, contentCss, beforeContentCss, afterContentCss, contentDirection = defaultContentDirection, contentAlignX = defaultAlignX, contentAlignY = defaultAlignY, beforeContentDirection = defaultDirection, beforeContentAlignX = defaultAlignX, beforeContentAlignY = defaultAlignY, afterContentDirection = defaultDirection, afterContentAlignX = defaultAlignX, afterContentAlignY = defaultAlignY, ...props }, ref) => {
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
211
|
+
const isSimpleElement = !beforeContent && !afterContent;
|
|
212
|
+
const CHILDREN = children ?? content ?? label;
|
|
213
|
+
const isInline = false;
|
|
214
|
+
const SUB_TAG = void 0;
|
|
215
|
+
const { wrapperDirection, wrapperAlignX, wrapperAlignY } = useMemo(() => {
|
|
216
|
+
let wrapperDirection = direction;
|
|
217
|
+
let wrapperAlignX = alignX;
|
|
218
|
+
let wrapperAlignY = alignY;
|
|
219
|
+
if (isSimpleElement) {
|
|
220
|
+
if (contentDirection) wrapperDirection = contentDirection;
|
|
221
|
+
if (contentAlignX) wrapperAlignX = contentAlignX;
|
|
222
|
+
if (contentAlignY) wrapperAlignY = contentAlignY;
|
|
223
|
+
} else if (direction) wrapperDirection = direction;
|
|
224
|
+
else wrapperDirection = defaultDirection;
|
|
225
|
+
return {
|
|
226
|
+
wrapperDirection,
|
|
227
|
+
wrapperAlignX,
|
|
228
|
+
wrapperAlignY
|
|
229
|
+
};
|
|
230
|
+
}, [
|
|
231
|
+
isSimpleElement,
|
|
232
|
+
contentDirection,
|
|
233
|
+
contentAlignX,
|
|
234
|
+
contentAlignY,
|
|
235
|
+
alignX,
|
|
236
|
+
alignY,
|
|
237
|
+
direction
|
|
238
|
+
]);
|
|
239
|
+
const WRAPPER_PROPS = {
|
|
240
|
+
ref: ref ?? innerRef,
|
|
241
|
+
extendCss: css,
|
|
242
|
+
tag,
|
|
243
|
+
block,
|
|
244
|
+
direction: wrapperDirection,
|
|
245
|
+
alignX: wrapperAlignX,
|
|
246
|
+
alignY: wrapperAlignY,
|
|
247
|
+
as: void 0
|
|
248
|
+
};
|
|
249
|
+
const contentRenderOutput = render(CHILDREN);
|
|
250
|
+
return /* @__PURE__ */ jsxs(Wrapper_default, {
|
|
251
|
+
...props,
|
|
252
|
+
...WRAPPER_PROPS,
|
|
253
|
+
isInline,
|
|
254
|
+
children: [
|
|
255
|
+
beforeContent && /* @__PURE__ */ jsx(Content_default, {
|
|
256
|
+
tag: SUB_TAG,
|
|
257
|
+
contentType: "before",
|
|
258
|
+
parentDirection: wrapperDirection,
|
|
259
|
+
extendCss: beforeContentCss,
|
|
260
|
+
direction: beforeContentDirection,
|
|
261
|
+
alignX: beforeContentAlignX,
|
|
262
|
+
alignY: beforeContentAlignY,
|
|
263
|
+
equalCols,
|
|
264
|
+
gap,
|
|
265
|
+
children: render(beforeContent)
|
|
266
|
+
}),
|
|
267
|
+
isSimpleElement ? contentRenderOutput : /* @__PURE__ */ jsx(Content_default, {
|
|
268
|
+
tag: SUB_TAG,
|
|
269
|
+
contentType: "content",
|
|
270
|
+
parentDirection: wrapperDirection,
|
|
271
|
+
extendCss: contentCss,
|
|
272
|
+
direction: contentDirection,
|
|
273
|
+
alignX: contentAlignX,
|
|
274
|
+
alignY: contentAlignY,
|
|
275
|
+
equalCols,
|
|
276
|
+
children: contentRenderOutput
|
|
277
|
+
}),
|
|
278
|
+
afterContent && /* @__PURE__ */ jsx(Content_default, {
|
|
279
|
+
tag: SUB_TAG,
|
|
280
|
+
contentType: "after",
|
|
281
|
+
parentDirection: wrapperDirection,
|
|
282
|
+
extendCss: afterContentCss,
|
|
283
|
+
direction: afterContentDirection,
|
|
284
|
+
alignX: afterContentAlignX,
|
|
285
|
+
alignY: afterContentAlignY,
|
|
286
|
+
equalCols,
|
|
287
|
+
gap,
|
|
288
|
+
children: render(afterContent)
|
|
289
|
+
})
|
|
290
|
+
]
|
|
291
|
+
});
|
|
234
292
|
});
|
|
235
293
|
const name$5 = `${PKG_NAME}/Element`;
|
|
236
294
|
Component$7.displayName = name$5;
|
|
237
295
|
Component$7.pkgName = PKG_NAME;
|
|
238
296
|
Component$7.VITUS_LABS__COMPONENT = name$5;
|
|
239
297
|
|
|
240
|
-
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/Element/withEqualSizeBeforeAfter.tsx
|
|
300
|
+
/**
|
|
301
|
+
* HOC that equalizes the dimensions of beforeContent and afterContent areas.
|
|
302
|
+
* After render, it measures both DOM nodes via useLayoutEffect and sets the
|
|
303
|
+
* larger dimension on both so they match. Uses width for inline direction
|
|
304
|
+
* and height for rows direction. This is useful for centering the main
|
|
305
|
+
* content when before/after slots have different intrinsic sizes.
|
|
306
|
+
*/
|
|
241
307
|
const types = {
|
|
242
|
-
|
|
243
|
-
|
|
308
|
+
height: "offsetHeight",
|
|
309
|
+
width: "offsetWidth"
|
|
244
310
|
};
|
|
245
|
-
const
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
beforeContent.style[type] = `${afterContentSize}px`;
|
|
255
|
-
afterContent.style[type] = `${afterContentSize}px`;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
311
|
+
const equalize = (beforeEl, afterEl, type) => {
|
|
312
|
+
const prop = types[type];
|
|
313
|
+
const beforeSize = beforeEl[prop];
|
|
314
|
+
const afterSize = afterEl[prop];
|
|
315
|
+
if (Number.isInteger(beforeSize) && Number.isInteger(afterSize)) {
|
|
316
|
+
const maxSize = `${Math.max(beforeSize, afterSize)}px`;
|
|
317
|
+
beforeEl.style[type] = maxSize;
|
|
318
|
+
afterEl.style[type] = maxSize;
|
|
319
|
+
}
|
|
258
320
|
};
|
|
259
321
|
const withEqualBeforeAfter = (WrappedComponent) => {
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
Enhanced.displayName = `withEqualSizeBeforeAfter(${displayName})`;
|
|
282
|
-
return Enhanced;
|
|
322
|
+
const displayName = WrappedComponent.displayName ?? WrappedComponent.name ?? "Component";
|
|
323
|
+
const Enhanced = ({ equalBeforeAfter, direction, afterContent, beforeContent, ref, ...rest }) => {
|
|
324
|
+
const internalRef = useRef(null);
|
|
325
|
+
useImperativeHandle(ref, () => internalRef.current);
|
|
326
|
+
useLayoutEffect(() => {
|
|
327
|
+
if (!equalBeforeAfter || !beforeContent || !afterContent) return;
|
|
328
|
+
if (!internalRef.current) return;
|
|
329
|
+
const el = internalRef.current;
|
|
330
|
+
const beforeEl = el.firstElementChild;
|
|
331
|
+
const afterEl = el.lastElementChild;
|
|
332
|
+
if (beforeEl && afterEl && beforeEl !== afterEl) equalize(beforeEl, afterEl, direction === "rows" ? "height" : "width");
|
|
333
|
+
});
|
|
334
|
+
return /* @__PURE__ */ jsx(WrappedComponent, {
|
|
335
|
+
...rest,
|
|
336
|
+
afterContent,
|
|
337
|
+
beforeContent,
|
|
338
|
+
ref: internalRef
|
|
339
|
+
});
|
|
340
|
+
};
|
|
341
|
+
Enhanced.displayName = `withEqualSizeBeforeAfter(${displayName})`;
|
|
342
|
+
return Enhanced;
|
|
283
343
|
};
|
|
284
344
|
|
|
345
|
+
//#endregion
|
|
346
|
+
//#region src/Element/index.ts
|
|
347
|
+
var Element_default = Component$7;
|
|
348
|
+
|
|
349
|
+
//#endregion
|
|
350
|
+
//#region src/helpers/Iterator/component.tsx
|
|
351
|
+
/**
|
|
352
|
+
* Data-driven list renderer that supports three input modes: React children
|
|
353
|
+
* (including fragments), an array of primitives, or an array of objects.
|
|
354
|
+
* Each item receives positional metadata (first, last, odd, even, position)
|
|
355
|
+
* and optional injected props via `itemProps`. Items can be individually
|
|
356
|
+
* wrapped with `wrapComponent`. Children always take priority over the
|
|
357
|
+
* component+data prop pattern.
|
|
358
|
+
*/
|
|
359
|
+
const classifyData = (data) => {
|
|
360
|
+
const items = data.filter((item) => item != null && !(typeof item === "object" && isEmpty(item)));
|
|
361
|
+
if (items.length === 0) return null;
|
|
362
|
+
let isSimple = true;
|
|
363
|
+
let isComplex = true;
|
|
364
|
+
for (const item of items) if (typeof item === "string" || typeof item === "number") isComplex = false;
|
|
365
|
+
else if (typeof item === "object") isSimple = false;
|
|
366
|
+
else {
|
|
367
|
+
isSimple = false;
|
|
368
|
+
isComplex = false;
|
|
369
|
+
}
|
|
370
|
+
if (isSimple) return {
|
|
371
|
+
type: "simple",
|
|
372
|
+
data: items
|
|
373
|
+
};
|
|
374
|
+
if (isComplex) return {
|
|
375
|
+
type: "complex",
|
|
376
|
+
data: items
|
|
377
|
+
};
|
|
378
|
+
return null;
|
|
379
|
+
};
|
|
285
380
|
const RESERVED_PROPS = [
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
381
|
+
"children",
|
|
382
|
+
"component",
|
|
383
|
+
"wrapComponent",
|
|
384
|
+
"data",
|
|
385
|
+
"itemKey",
|
|
386
|
+
"valueName",
|
|
387
|
+
"itemProps",
|
|
388
|
+
"wrapProps"
|
|
294
389
|
];
|
|
295
|
-
const attachItemProps = ({ i, length
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
390
|
+
const attachItemProps = ({ i, length }) => {
|
|
391
|
+
const position = i + 1;
|
|
392
|
+
return {
|
|
393
|
+
index: i,
|
|
394
|
+
first: position === 1,
|
|
395
|
+
last: position === length,
|
|
396
|
+
odd: position % 2 === 1,
|
|
397
|
+
even: position % 2 === 0,
|
|
398
|
+
position
|
|
399
|
+
};
|
|
305
400
|
};
|
|
306
401
|
const Component$6 = (props) => {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
const extendedProps = attachItemProps({
|
|
407
|
-
i,
|
|
408
|
-
length,
|
|
409
|
-
});
|
|
410
|
-
const finalItemProps = {
|
|
411
|
-
...(itemProps ? injectItemProps(item, extendedProps) : {}),
|
|
412
|
-
...restItem,
|
|
413
|
-
};
|
|
414
|
-
if (Wrapper && !itemComponent) {
|
|
415
|
-
const finalWrapProps = wrapProps
|
|
416
|
-
? injectWrapItemProps(item, extendedProps)
|
|
417
|
-
: {};
|
|
418
|
-
return (React.createElement(Wrapper, { key: key, ...finalWrapProps }, render(renderItem, finalItemProps)));
|
|
419
|
-
}
|
|
420
|
-
return render(renderItem, { key, ...finalItemProps });
|
|
421
|
-
});
|
|
422
|
-
};
|
|
423
|
-
// --------------------------------------------------------
|
|
424
|
-
// render list items
|
|
425
|
-
// --------------------------------------------------------
|
|
426
|
-
const renderItems = () => {
|
|
427
|
-
// --------------------------------------------------------
|
|
428
|
-
// children have priority over props component + data
|
|
429
|
-
// --------------------------------------------------------
|
|
430
|
-
if (children)
|
|
431
|
-
return renderChildren();
|
|
432
|
-
// --------------------------------------------------------
|
|
433
|
-
// render props component + data
|
|
434
|
-
// --------------------------------------------------------
|
|
435
|
-
if (component && Array.isArray(data)) {
|
|
436
|
-
const clearData = data.filter((item) => item !== null && item !== undefined);
|
|
437
|
-
const isSimpleArray = clearData.every((item) => typeof item === 'string' || typeof item === 'number');
|
|
438
|
-
if (isSimpleArray)
|
|
439
|
-
return renderSimpleArray(clearData);
|
|
440
|
-
const isComplexArray = clearData.every((item) => typeof item === 'object');
|
|
441
|
-
if (isComplexArray)
|
|
442
|
-
return renderComplexArray(clearData);
|
|
443
|
-
return null;
|
|
444
|
-
}
|
|
445
|
-
// --------------------------------------------------------
|
|
446
|
-
// if there are no children or valid react component and data as an array,
|
|
447
|
-
// return null to prevent error
|
|
448
|
-
// --------------------------------------------------------
|
|
449
|
-
return null;
|
|
450
|
-
};
|
|
451
|
-
return renderItems();
|
|
402
|
+
const { itemKey, valueName, children, component, data, wrapComponent: Wrapper, wrapProps, itemProps } = props;
|
|
403
|
+
const injectItemProps = useMemo(() => typeof itemProps === "function" ? itemProps : () => itemProps, [itemProps]);
|
|
404
|
+
const injectWrapItemProps = useMemo(() => typeof wrapProps === "function" ? wrapProps : () => wrapProps, [wrapProps]);
|
|
405
|
+
const getKey = useCallback((item, index) => {
|
|
406
|
+
if (typeof itemKey === "function") return itemKey(item, index);
|
|
407
|
+
return index;
|
|
408
|
+
}, [itemKey]);
|
|
409
|
+
const renderChild = (child, total = 1, i = 0) => {
|
|
410
|
+
if (!itemProps && !Wrapper) return child;
|
|
411
|
+
const extendedProps = attachItemProps({
|
|
412
|
+
i,
|
|
413
|
+
length: total
|
|
414
|
+
});
|
|
415
|
+
const finalItemProps = itemProps ? injectItemProps({}, extendedProps) : {};
|
|
416
|
+
if (Wrapper) return /* @__PURE__ */ jsx(Wrapper, {
|
|
417
|
+
...wrapProps ? injectWrapItemProps({}, extendedProps) : {},
|
|
418
|
+
children: render(child, finalItemProps)
|
|
419
|
+
}, i);
|
|
420
|
+
return render(child, {
|
|
421
|
+
key: i,
|
|
422
|
+
...finalItemProps
|
|
423
|
+
});
|
|
424
|
+
};
|
|
425
|
+
const renderChildren = () => {
|
|
426
|
+
if (!children) return null;
|
|
427
|
+
if (Array.isArray(children)) return Children.map(children, (item, i) => renderChild(item, children.length, i));
|
|
428
|
+
if (isFragment(children)) {
|
|
429
|
+
const fragmentChildren = children.props.children;
|
|
430
|
+
const childrenLength = fragmentChildren.length;
|
|
431
|
+
return fragmentChildren.map((item, i) => renderChild(item, childrenLength, i));
|
|
432
|
+
}
|
|
433
|
+
return renderChild(children);
|
|
434
|
+
};
|
|
435
|
+
const renderSimpleArray = (data) => {
|
|
436
|
+
const { length } = data;
|
|
437
|
+
if (length === 0) return null;
|
|
438
|
+
return data.map((item, i) => {
|
|
439
|
+
const key = getKey(item, i);
|
|
440
|
+
const keyName = valueName ?? "children";
|
|
441
|
+
const extendedProps = attachItemProps({
|
|
442
|
+
i,
|
|
443
|
+
length
|
|
444
|
+
});
|
|
445
|
+
const finalItemProps = {
|
|
446
|
+
...itemProps ? injectItemProps({ [keyName]: item }, extendedProps) : {},
|
|
447
|
+
[keyName]: item
|
|
448
|
+
};
|
|
449
|
+
if (Wrapper) return /* @__PURE__ */ jsx(Wrapper, {
|
|
450
|
+
...wrapProps ? injectWrapItemProps({ [keyName]: item }, extendedProps) : {},
|
|
451
|
+
children: render(component, finalItemProps)
|
|
452
|
+
}, key);
|
|
453
|
+
return render(component, {
|
|
454
|
+
key,
|
|
455
|
+
...finalItemProps
|
|
456
|
+
});
|
|
457
|
+
});
|
|
458
|
+
};
|
|
459
|
+
const getObjectKey = (item, index) => {
|
|
460
|
+
if (!itemKey) return item.key ?? item.id ?? item.itemId ?? index;
|
|
461
|
+
if (typeof itemKey === "function") return itemKey(item, index);
|
|
462
|
+
if (typeof itemKey === "string") return item[itemKey];
|
|
463
|
+
return index;
|
|
464
|
+
};
|
|
465
|
+
const renderComplexArray = (data) => {
|
|
466
|
+
const { length } = data;
|
|
467
|
+
if (length === 0) return null;
|
|
468
|
+
return data.map((item, i) => {
|
|
469
|
+
const { component: itemComponent, ...restItem } = item;
|
|
470
|
+
const renderItem = itemComponent ?? component;
|
|
471
|
+
const key = getObjectKey(restItem, i);
|
|
472
|
+
const extendedProps = attachItemProps({
|
|
473
|
+
i,
|
|
474
|
+
length
|
|
475
|
+
});
|
|
476
|
+
const finalItemProps = {
|
|
477
|
+
...itemProps ? injectItemProps(item, extendedProps) : {},
|
|
478
|
+
...restItem
|
|
479
|
+
};
|
|
480
|
+
if (Wrapper && !itemComponent) return /* @__PURE__ */ jsx(Wrapper, {
|
|
481
|
+
...wrapProps ? injectWrapItemProps(item, extendedProps) : {},
|
|
482
|
+
children: render(renderItem, finalItemProps)
|
|
483
|
+
}, key);
|
|
484
|
+
return render(renderItem, {
|
|
485
|
+
key,
|
|
486
|
+
...finalItemProps
|
|
487
|
+
});
|
|
488
|
+
});
|
|
489
|
+
};
|
|
490
|
+
const renderItems = () => {
|
|
491
|
+
if (children) return renderChildren();
|
|
492
|
+
if (component && Array.isArray(data)) {
|
|
493
|
+
const classified = classifyData(data);
|
|
494
|
+
if (!classified) return null;
|
|
495
|
+
if (classified.type === "simple") return renderSimpleArray(classified.data);
|
|
496
|
+
return renderComplexArray(classified.data);
|
|
497
|
+
}
|
|
498
|
+
return null;
|
|
499
|
+
};
|
|
500
|
+
return renderItems();
|
|
452
501
|
};
|
|
453
502
|
Component$6.isIterator = true;
|
|
454
503
|
Component$6.RESERVED_PROPS = RESERVED_PROPS;
|
|
455
504
|
|
|
505
|
+
//#endregion
|
|
506
|
+
//#region src/helpers/Iterator/index.ts
|
|
507
|
+
var Iterator_default = Component$6;
|
|
508
|
+
|
|
509
|
+
//#endregion
|
|
510
|
+
//#region src/List/component.tsx
|
|
511
|
+
/**
|
|
512
|
+
* List component that combines Iterator (data-driven rendering) with an
|
|
513
|
+
* optional Element root wrapper. When `rootElement` is false (default),
|
|
514
|
+
* it renders a bare Iterator as a fragment. When true, the Iterator output
|
|
515
|
+
* is wrapped in an Element that receives all non-iterator props (e.g.,
|
|
516
|
+
* layout, alignment, css), allowing the list to be styled as a single block.
|
|
517
|
+
*/
|
|
456
518
|
const Component$5 = forwardRef(({ rootElement = false, ...props }, ref) => {
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
519
|
+
const renderedList = /* @__PURE__ */ jsx(Iterator_default, { ...pick(props, Iterator_default.RESERVED_PROPS) });
|
|
520
|
+
if (!rootElement) return renderedList;
|
|
521
|
+
return /* @__PURE__ */ jsx(Element_default, {
|
|
522
|
+
ref,
|
|
523
|
+
...omit(props, Iterator_default.RESERVED_PROPS),
|
|
524
|
+
children: renderedList
|
|
525
|
+
});
|
|
461
526
|
});
|
|
462
527
|
const name$4 = `${PKG_NAME}/List`;
|
|
463
528
|
Component$5.displayName = name$4;
|
|
464
529
|
Component$5.pkgName = PKG_NAME;
|
|
465
530
|
Component$5.VITUS_LABS__COMPONENT = name$4;
|
|
466
531
|
|
|
467
|
-
|
|
532
|
+
//#endregion
|
|
533
|
+
//#region src/List/withActiveState.tsx
|
|
534
|
+
/**
|
|
535
|
+
* HOC that adds single or multi selection state management to a list component.
|
|
536
|
+
* Tracks which items are active via a scalar key (single mode) or a Map of
|
|
537
|
+
* key-to-boolean entries (multi mode). Injects `itemProps` callback that
|
|
538
|
+
* provides each item with `active`, `handleItemActive`, `toggleItemActive`,
|
|
539
|
+
* and other selection helpers. Supports `activeItemRequired` to prevent
|
|
540
|
+
* deselecting the last active item.
|
|
541
|
+
*/
|
|
468
542
|
const RESERVED_KEYS = [
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
543
|
+
"type",
|
|
544
|
+
"activeItems",
|
|
545
|
+
"itemProps",
|
|
546
|
+
"activeItemRequired"
|
|
473
547
|
];
|
|
474
548
|
const component = (WrappedComponent) => {
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
if (type === 'single')
|
|
559
|
-
return innerActiveItems === key;
|
|
560
|
-
if (type === 'multi' && innerActiveItems instanceof Map) {
|
|
561
|
-
return !!innerActiveItems.get(key);
|
|
562
|
-
}
|
|
563
|
-
return false;
|
|
564
|
-
};
|
|
565
|
-
const attachMultipleProps = {
|
|
566
|
-
unsetAllItemsActive,
|
|
567
|
-
};
|
|
568
|
-
const attachItemProps = (props) => {
|
|
569
|
-
const { key } = props;
|
|
570
|
-
const defaultItemProps = typeof itemProps === 'object' ? itemProps : itemProps(props);
|
|
571
|
-
const result = {
|
|
572
|
-
...defaultItemProps,
|
|
573
|
-
active: isItemActive(key),
|
|
574
|
-
handleItemActive: () => handleItemActive(key),
|
|
575
|
-
setItemActive,
|
|
576
|
-
unsetItemActive,
|
|
577
|
-
toggleItemActive,
|
|
578
|
-
...(type === 'multi' ? attachMultipleProps : {}),
|
|
579
|
-
};
|
|
580
|
-
return result;
|
|
581
|
-
};
|
|
582
|
-
useEffect(() => {
|
|
583
|
-
if (type === 'single' && Array.isArray(activeItems)) {
|
|
584
|
-
if (process.env.NODE_ENV !== 'production') {
|
|
585
|
-
// eslint-disable-next-line no-console
|
|
586
|
-
console.error('When type=`single` activeItems must be a single value, not an array');
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
}, [type, activeItems]);
|
|
590
|
-
return React.createElement(WrappedComponent, { ...rest, itemProps: attachItemProps });
|
|
591
|
-
};
|
|
592
|
-
Enhanced.RESERVED_KEYS = RESERVED_KEYS;
|
|
593
|
-
Enhanced.displayName = `@vitus-labs/elements/List/withActiveState(${displayName})`;
|
|
594
|
-
return Enhanced;
|
|
549
|
+
const displayName = WrappedComponent.displayName || WrappedComponent.name || "Component";
|
|
550
|
+
const Enhanced = (props) => {
|
|
551
|
+
const { type = "single", activeItemRequired, activeItems, itemProps = {}, ...rest } = props;
|
|
552
|
+
const initActiveItems = () => {
|
|
553
|
+
if (type === "single") {
|
|
554
|
+
if (!Array.isArray(activeItems)) return activeItems;
|
|
555
|
+
} else if (type === "multi") {
|
|
556
|
+
const activeItemsHelper = Array.isArray(activeItems) ? activeItems : [activeItems];
|
|
557
|
+
return new Map(activeItemsHelper.map((id) => [id, true]));
|
|
558
|
+
}
|
|
559
|
+
};
|
|
560
|
+
const [innerActiveItems, setActiveItems] = useState(initActiveItems());
|
|
561
|
+
const countActiveItems = (data) => {
|
|
562
|
+
let result = 0;
|
|
563
|
+
data.forEach((value) => {
|
|
564
|
+
if (value) result += 1;
|
|
565
|
+
});
|
|
566
|
+
return result;
|
|
567
|
+
};
|
|
568
|
+
const updateItemState = (key) => {
|
|
569
|
+
if (type === "single") setActiveItems((prevState) => {
|
|
570
|
+
if (activeItemRequired) return key;
|
|
571
|
+
if (prevState === key) return void 0;
|
|
572
|
+
return key;
|
|
573
|
+
});
|
|
574
|
+
else if (type === "multi") setActiveItems((prevState) => {
|
|
575
|
+
const activeItems = new Map(prevState);
|
|
576
|
+
if (activeItemRequired && activeItems.get(key) && countActiveItems(activeItems) === 1) return activeItems;
|
|
577
|
+
activeItems.set(key, !activeItems.get(key));
|
|
578
|
+
return activeItems;
|
|
579
|
+
});
|
|
580
|
+
else setActiveItems(void 0);
|
|
581
|
+
};
|
|
582
|
+
const handleItemActive = (key) => {
|
|
583
|
+
updateItemState(key);
|
|
584
|
+
};
|
|
585
|
+
const updateAllItemsState = (status) => {
|
|
586
|
+
if (!status) setActiveItems(/* @__PURE__ */ new Map());
|
|
587
|
+
};
|
|
588
|
+
const setItemActive = (key) => {
|
|
589
|
+
updateItemState(key);
|
|
590
|
+
};
|
|
591
|
+
const unsetItemActive = (key) => {
|
|
592
|
+
updateItemState(key);
|
|
593
|
+
};
|
|
594
|
+
const toggleItemActive = (key) => {
|
|
595
|
+
updateItemState(key);
|
|
596
|
+
};
|
|
597
|
+
const unsetAllItemsActive = () => {
|
|
598
|
+
updateAllItemsState(false);
|
|
599
|
+
};
|
|
600
|
+
const isItemActive = (key) => {
|
|
601
|
+
if (!innerActiveItems) return false;
|
|
602
|
+
if (type === "single") return innerActiveItems === key;
|
|
603
|
+
if (type === "multi" && innerActiveItems instanceof Map) return !!innerActiveItems.get(key);
|
|
604
|
+
return false;
|
|
605
|
+
};
|
|
606
|
+
const attachMultipleProps = { unsetAllItemsActive };
|
|
607
|
+
const attachItemProps = (props) => {
|
|
608
|
+
const { key } = props;
|
|
609
|
+
return {
|
|
610
|
+
...typeof itemProps === "object" ? itemProps : itemProps(props),
|
|
611
|
+
active: isItemActive(key),
|
|
612
|
+
handleItemActive: () => handleItemActive(key),
|
|
613
|
+
setItemActive,
|
|
614
|
+
unsetItemActive,
|
|
615
|
+
toggleItemActive,
|
|
616
|
+
...type === "multi" ? attachMultipleProps : {}
|
|
617
|
+
};
|
|
618
|
+
};
|
|
619
|
+
useEffect(() => {
|
|
620
|
+
if (type === "single" && Array.isArray(activeItems)) {
|
|
621
|
+
if (process.env.NODE_ENV !== "production") console.warn("[@vitus-labs/elements] List/withActiveState: `activeItems` was passed as an array but `type` is \"single\". In single selection mode, `activeItems` should be a single key (string | number). The array value will be ignored.");
|
|
622
|
+
}
|
|
623
|
+
}, [type, activeItems]);
|
|
624
|
+
return /* @__PURE__ */ jsx(WrappedComponent, {
|
|
625
|
+
...rest,
|
|
626
|
+
itemProps: attachItemProps
|
|
627
|
+
});
|
|
628
|
+
};
|
|
629
|
+
Enhanced.RESERVED_KEYS = RESERVED_KEYS;
|
|
630
|
+
Enhanced.displayName = `@vitus-labs/elements/List/withActiveState(${displayName})`;
|
|
631
|
+
return Enhanced;
|
|
595
632
|
};
|
|
596
633
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
634
|
+
//#endregion
|
|
635
|
+
//#region src/List/index.ts
|
|
636
|
+
var List_default = Component$5;
|
|
637
|
+
|
|
638
|
+
//#endregion
|
|
639
|
+
//#region src/Portal/component.ts
|
|
640
|
+
/**
|
|
641
|
+
* Portal component that creates a new DOM element on mount, appends it to
|
|
642
|
+
* the target location (defaults to document.body), and uses React's
|
|
643
|
+
* createPortal to render children into it. The DOM element is cleaned up
|
|
644
|
+
* on unmount. Accepts a custom DOMLocation for rendering into specific
|
|
645
|
+
* containers (e.g., a modal root).
|
|
646
|
+
*/
|
|
647
|
+
const Component$4 = ({ DOMLocation, tag = "div", children }) => {
|
|
648
|
+
const [element, setElement] = useState();
|
|
649
|
+
useEffect(() => {
|
|
650
|
+
if (!tag) return void 0;
|
|
651
|
+
const position = DOMLocation ?? document.body;
|
|
652
|
+
const element = document.createElement(tag);
|
|
653
|
+
setElement(element);
|
|
654
|
+
position.appendChild(element);
|
|
655
|
+
return () => {
|
|
656
|
+
position.removeChild(element);
|
|
657
|
+
};
|
|
658
|
+
}, [tag, DOMLocation]);
|
|
659
|
+
if (!tag || !element) return null;
|
|
660
|
+
return createPortal(children, element);
|
|
613
661
|
};
|
|
614
|
-
// ----------------------------------------------
|
|
615
|
-
// DEFINE STATICS
|
|
616
|
-
// ----------------------------------------------
|
|
617
662
|
const name$3 = `${PKG_NAME}/Portal`;
|
|
618
663
|
Component$4.displayName = name$3;
|
|
619
664
|
Component$4.pkgName = PKG_NAME;
|
|
620
665
|
Component$4.VITUS_LABS__COMPONENT = name$3;
|
|
621
666
|
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
667
|
+
//#endregion
|
|
668
|
+
//#region src/Portal/index.ts
|
|
669
|
+
var Portal_default = Component$4;
|
|
670
|
+
|
|
671
|
+
//#endregion
|
|
672
|
+
//#region src/Overlay/context.tsx
|
|
673
|
+
/**
|
|
674
|
+
* Context for nested overlay coordination. When a child overlay opens, it
|
|
675
|
+
* sets the parent's blocked state to true, preventing the parent from
|
|
676
|
+
* closing in response to click/hover events that belong to the child.
|
|
677
|
+
*/
|
|
678
|
+
const context$1 = createContext({});
|
|
679
|
+
const { Provider: Provider$1 } = context$1;
|
|
680
|
+
const useOverlayContext = () => useContext(context$1);
|
|
681
|
+
const Component = ({ children, blocked, setBlocked, setUnblocked }) => {
|
|
682
|
+
return /* @__PURE__ */ jsx(Provider$1, {
|
|
683
|
+
value: useMemo(() => ({
|
|
684
|
+
blocked,
|
|
685
|
+
setBlocked,
|
|
686
|
+
setUnblocked
|
|
687
|
+
}), [
|
|
688
|
+
blocked,
|
|
689
|
+
setBlocked,
|
|
690
|
+
setUnblocked
|
|
691
|
+
]),
|
|
692
|
+
children
|
|
693
|
+
});
|
|
632
694
|
};
|
|
633
695
|
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
|
|
721
|
-
|
|
722
|
-
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
|
|
727
|
-
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
|
|
1039
|
-
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
696
|
+
//#endregion
|
|
697
|
+
//#region src/Overlay/useOverlay.tsx
|
|
698
|
+
/**
|
|
699
|
+
* Core hook powering the Overlay component. Manages open/close state, DOM
|
|
700
|
+
* event listeners (click, hover, scroll, resize, ESC key), and dynamic
|
|
701
|
+
* positioning of overlay content relative to its trigger. Supports dropdown,
|
|
702
|
+
* tooltip, popover, and modal types with automatic edge-of-viewport flipping.
|
|
703
|
+
* Event handlers are throttled for performance, and nested overlay blocking
|
|
704
|
+
* is coordinated through the overlay context.
|
|
705
|
+
*/
|
|
706
|
+
const sel = (cond, a, b) => cond ? a : b;
|
|
707
|
+
const devWarn = (msg) => {
|
|
708
|
+
if (!IS_DEVELOPMENT) return;
|
|
709
|
+
console.warn(msg);
|
|
710
|
+
};
|
|
711
|
+
const calcDropdownVertical = (c, t, align, alignX, offsetX, offsetY) => {
|
|
712
|
+
const pos = {};
|
|
713
|
+
const topPos = t.top - offsetY - c.height;
|
|
714
|
+
const bottomPos = t.bottom + offsetY;
|
|
715
|
+
const leftPos = t.left + offsetX;
|
|
716
|
+
const rightPos = t.right - offsetX - c.width;
|
|
717
|
+
const fitsTop = topPos >= 0;
|
|
718
|
+
const fitsBottom = bottomPos + c.height <= window.innerHeight;
|
|
719
|
+
const fitsLeft = leftPos + c.width <= window.innerWidth;
|
|
720
|
+
const fitsRight = rightPos >= 0;
|
|
721
|
+
const useTop = sel(align === "top", fitsTop, !fitsBottom);
|
|
722
|
+
pos.top = sel(useTop, topPos, bottomPos);
|
|
723
|
+
const resolvedAlignY = sel(useTop, "top", "bottom");
|
|
724
|
+
let resolvedAlignX = alignX;
|
|
725
|
+
if (alignX === "left") {
|
|
726
|
+
pos.left = sel(fitsLeft, leftPos, rightPos);
|
|
727
|
+
resolvedAlignX = sel(fitsLeft, "left", "right");
|
|
728
|
+
} else if (alignX === "right") {
|
|
729
|
+
pos.left = sel(fitsRight, rightPos, leftPos);
|
|
730
|
+
resolvedAlignX = sel(fitsRight, "right", "left");
|
|
731
|
+
} else {
|
|
732
|
+
const center = t.left + (t.right - t.left) / 2 - c.width / 2;
|
|
733
|
+
const fitsCL = center >= 0;
|
|
734
|
+
const fitsCR = center + c.width <= window.innerWidth;
|
|
735
|
+
if (fitsCL && fitsCR) {
|
|
736
|
+
resolvedAlignX = "center";
|
|
737
|
+
pos.left = center;
|
|
738
|
+
} else if (fitsCL) {
|
|
739
|
+
resolvedAlignX = "left";
|
|
740
|
+
pos.left = leftPos;
|
|
741
|
+
} else if (fitsCR) {
|
|
742
|
+
resolvedAlignX = "right";
|
|
743
|
+
pos.left = rightPos;
|
|
744
|
+
}
|
|
745
|
+
}
|
|
746
|
+
return {
|
|
747
|
+
pos,
|
|
748
|
+
resolvedAlignX,
|
|
749
|
+
resolvedAlignY
|
|
750
|
+
};
|
|
751
|
+
};
|
|
752
|
+
const calcDropdownHorizontal = (c, t, align, alignY, offsetX, offsetY) => {
|
|
753
|
+
const pos = {};
|
|
754
|
+
const leftPos = t.left - offsetX - c.width;
|
|
755
|
+
const rightPos = t.right + offsetX;
|
|
756
|
+
const topPos = t.top + offsetY;
|
|
757
|
+
const bottomPos = t.bottom - offsetY - c.height;
|
|
758
|
+
const fitsLeft = leftPos >= 0;
|
|
759
|
+
const fitsRight = rightPos + c.width <= window.innerWidth;
|
|
760
|
+
const fitsTop = topPos + c.height <= window.innerHeight;
|
|
761
|
+
const fitsBottom = bottomPos >= 0;
|
|
762
|
+
const useLeft = sel(align === "left", fitsLeft, !fitsRight);
|
|
763
|
+
pos.left = sel(useLeft, leftPos, rightPos);
|
|
764
|
+
const resolvedAlignX = sel(useLeft, "left", "right");
|
|
765
|
+
let resolvedAlignY = alignY;
|
|
766
|
+
if (alignY === "top") {
|
|
767
|
+
pos.top = sel(fitsTop, topPos, bottomPos);
|
|
768
|
+
resolvedAlignY = sel(fitsTop, "top", "bottom");
|
|
769
|
+
} else if (alignY === "bottom") {
|
|
770
|
+
pos.top = sel(fitsBottom, bottomPos, topPos);
|
|
771
|
+
resolvedAlignY = sel(fitsBottom, "bottom", "top");
|
|
772
|
+
} else {
|
|
773
|
+
const center = t.top + (t.bottom - t.top) / 2 - c.height / 2;
|
|
774
|
+
const fitsCT = center >= 0;
|
|
775
|
+
const fitsCB = center + c.height <= window.innerHeight;
|
|
776
|
+
if (fitsCT && fitsCB) {
|
|
777
|
+
resolvedAlignY = "center";
|
|
778
|
+
pos.top = center;
|
|
779
|
+
} else if (fitsCT) {
|
|
780
|
+
resolvedAlignY = "top";
|
|
781
|
+
pos.top = topPos;
|
|
782
|
+
} else if (fitsCB) {
|
|
783
|
+
resolvedAlignY = "bottom";
|
|
784
|
+
pos.top = bottomPos;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
return {
|
|
788
|
+
pos,
|
|
789
|
+
resolvedAlignX,
|
|
790
|
+
resolvedAlignY
|
|
791
|
+
};
|
|
792
|
+
};
|
|
793
|
+
const calcModalPos = (c, alignX, alignY, offsetX, offsetY) => {
|
|
794
|
+
const pos = {};
|
|
795
|
+
switch (alignX) {
|
|
796
|
+
case "right":
|
|
797
|
+
pos.right = offsetX;
|
|
798
|
+
break;
|
|
799
|
+
case "left":
|
|
800
|
+
pos.left = offsetX;
|
|
801
|
+
break;
|
|
802
|
+
case "center":
|
|
803
|
+
pos.left = window.innerWidth / 2 - c.width / 2;
|
|
804
|
+
break;
|
|
805
|
+
default: pos.right = offsetX;
|
|
806
|
+
}
|
|
807
|
+
switch (alignY) {
|
|
808
|
+
case "top":
|
|
809
|
+
pos.top = offsetY;
|
|
810
|
+
break;
|
|
811
|
+
case "center":
|
|
812
|
+
pos.top = window.innerHeight / 2 - c.height / 2;
|
|
813
|
+
break;
|
|
814
|
+
case "bottom":
|
|
815
|
+
pos.bottom = offsetY;
|
|
816
|
+
break;
|
|
817
|
+
default: pos.top = offsetY;
|
|
818
|
+
}
|
|
819
|
+
return pos;
|
|
820
|
+
};
|
|
821
|
+
const adjustForAncestor = (pos, ancestor) => {
|
|
822
|
+
if (ancestor.top === 0 && ancestor.left === 0) return pos;
|
|
823
|
+
const result = { ...pos };
|
|
824
|
+
if (typeof result.top === "number") result.top -= ancestor.top;
|
|
825
|
+
if (typeof result.bottom === "number") result.bottom += ancestor.top;
|
|
826
|
+
if (typeof result.left === "number") result.left -= ancestor.left;
|
|
827
|
+
if (typeof result.right === "number") result.right += ancestor.left;
|
|
828
|
+
return result;
|
|
829
|
+
};
|
|
830
|
+
const computePosition = (type, align, alignX, alignY, offsetX, offsetY, triggerEl, contentEl, ancestorOffset) => {
|
|
831
|
+
const isDropdown = [
|
|
832
|
+
"dropdown",
|
|
833
|
+
"tooltip",
|
|
834
|
+
"popover"
|
|
835
|
+
].includes(type);
|
|
836
|
+
if (isDropdown && (!triggerEl || !contentEl)) {
|
|
837
|
+
devWarn(`[@vitus-labs/elements] Overlay (${type}): ${triggerEl ? "contentRef" : "triggerRef"} is not attached. Position cannot be calculated without both refs.`);
|
|
838
|
+
return { pos: {} };
|
|
839
|
+
}
|
|
840
|
+
if (isDropdown && triggerEl && contentEl) {
|
|
841
|
+
const c = contentEl.getBoundingClientRect();
|
|
842
|
+
const t = triggerEl.getBoundingClientRect();
|
|
843
|
+
const result = align === "top" || align === "bottom" ? calcDropdownVertical(c, t, align, alignX, offsetX, offsetY) : calcDropdownHorizontal(c, t, align, alignY, offsetX, offsetY);
|
|
844
|
+
return {
|
|
845
|
+
pos: adjustForAncestor(result.pos, ancestorOffset),
|
|
846
|
+
resolvedAlignX: result.resolvedAlignX,
|
|
847
|
+
resolvedAlignY: result.resolvedAlignY
|
|
848
|
+
};
|
|
849
|
+
}
|
|
850
|
+
if (type === "modal") {
|
|
851
|
+
if (!contentEl) {
|
|
852
|
+
devWarn("[@vitus-labs/elements] Overlay (modal): contentRef is not attached. Modal position cannot be calculated without a content element.");
|
|
853
|
+
return { pos: {} };
|
|
854
|
+
}
|
|
855
|
+
return { pos: adjustForAncestor(calcModalPos(contentEl.getBoundingClientRect(), alignX, alignY, offsetX, offsetY), ancestorOffset) };
|
|
856
|
+
}
|
|
857
|
+
return { pos: {} };
|
|
858
|
+
};
|
|
859
|
+
const processVisibilityEvent = (e, active, openOn, closeOn, isTrigger, isContent, showContent, hideContent) => {
|
|
860
|
+
if (!active && openOn === "click" && e.type === "click" && isTrigger(e)) {
|
|
861
|
+
showContent();
|
|
862
|
+
return;
|
|
863
|
+
}
|
|
864
|
+
if (!active) return;
|
|
865
|
+
if (closeOn === "hover" && e.type === "scroll") {
|
|
866
|
+
hideContent();
|
|
867
|
+
return;
|
|
868
|
+
}
|
|
869
|
+
if (e.type !== "click") return;
|
|
870
|
+
if (closeOn === "click") hideContent();
|
|
871
|
+
else if (closeOn === "clickOnTrigger" && isTrigger(e)) hideContent();
|
|
872
|
+
else if (closeOn === "clickOutsideContent" && !isContent(e)) hideContent();
|
|
873
|
+
};
|
|
874
|
+
const useOverlay = ({ isOpen = false, openOn = "click", closeOn = "click", type = "dropdown", position = "fixed", align = "bottom", alignX = "left", alignY = "bottom", offsetX = 0, offsetY = 0, throttleDelay = 200, parentContainer, closeOnEsc = true, disabled, onOpen, onClose } = {}) => {
|
|
875
|
+
const { rootSize } = useContext(context);
|
|
876
|
+
const ctx = useOverlayContext();
|
|
877
|
+
const [isContentLoaded, setContentLoaded] = useState(false);
|
|
878
|
+
const [innerAlignX, setInnerAlignX] = useState(alignX);
|
|
879
|
+
const [innerAlignY, setInnerAlignY] = useState(alignY);
|
|
880
|
+
const [blocked, handleBlocked] = useState(false);
|
|
881
|
+
const [active, handleActive] = useState(isOpen);
|
|
882
|
+
const triggerRef = useRef(null);
|
|
883
|
+
const contentRef = useRef(null);
|
|
884
|
+
const setBlocked = useCallback(() => handleBlocked(true), []);
|
|
885
|
+
const setUnblocked = useCallback(() => handleBlocked(false), []);
|
|
886
|
+
const showContent = useCallback(() => {
|
|
887
|
+
handleActive(true);
|
|
888
|
+
}, []);
|
|
889
|
+
const hideContent = useCallback(() => {
|
|
890
|
+
handleActive(false);
|
|
891
|
+
}, []);
|
|
892
|
+
const getAncestorOffset = useCallback(() => {
|
|
893
|
+
if (position !== "absolute" || !contentRef.current) return {
|
|
894
|
+
top: 0,
|
|
895
|
+
left: 0
|
|
896
|
+
};
|
|
897
|
+
const offsetParent = contentRef.current.offsetParent;
|
|
898
|
+
if (!offsetParent || offsetParent === document.body) return {
|
|
899
|
+
top: 0,
|
|
900
|
+
left: 0
|
|
901
|
+
};
|
|
902
|
+
const rect = offsetParent.getBoundingClientRect();
|
|
903
|
+
return {
|
|
904
|
+
top: rect.top,
|
|
905
|
+
left: rect.left
|
|
906
|
+
};
|
|
907
|
+
}, [position]);
|
|
908
|
+
const calculateContentPosition = useCallback(() => {
|
|
909
|
+
if (!active || !isContentLoaded) return {};
|
|
910
|
+
const result = computePosition(type, align, alignX, alignY, offsetX, offsetY, triggerRef.current, contentRef.current, getAncestorOffset());
|
|
911
|
+
if (result.resolvedAlignX) setInnerAlignX(result.resolvedAlignX);
|
|
912
|
+
if (result.resolvedAlignY) setInnerAlignY(result.resolvedAlignY);
|
|
913
|
+
return result.pos;
|
|
914
|
+
}, [
|
|
915
|
+
isContentLoaded,
|
|
916
|
+
active,
|
|
917
|
+
align,
|
|
918
|
+
alignX,
|
|
919
|
+
alignY,
|
|
920
|
+
offsetX,
|
|
921
|
+
offsetY,
|
|
922
|
+
type,
|
|
923
|
+
getAncestorOffset
|
|
924
|
+
]);
|
|
925
|
+
const assignContentPosition = useCallback((values = {}) => {
|
|
926
|
+
if (!contentRef.current) return;
|
|
927
|
+
const el = contentRef.current;
|
|
928
|
+
const setValue = (param) => value(param, rootSize);
|
|
929
|
+
el.style.position = position;
|
|
930
|
+
el.style.top = values.top != null ? setValue(values.top) : "";
|
|
931
|
+
el.style.bottom = values.bottom != null ? setValue(values.bottom) : "";
|
|
932
|
+
el.style.left = values.left != null ? setValue(values.left) : "";
|
|
933
|
+
el.style.right = values.right != null ? setValue(values.right) : "";
|
|
934
|
+
}, [position, rootSize]);
|
|
935
|
+
const setContentPosition = useCallback(() => {
|
|
936
|
+
assignContentPosition(calculateContentPosition());
|
|
937
|
+
}, [assignContentPosition, calculateContentPosition]);
|
|
938
|
+
const isNodeOrChild = useCallback((ref) => (e) => {
|
|
939
|
+
if (e?.target && ref.current) return ref.current.contains(e.target) || e.target === ref.current;
|
|
940
|
+
return false;
|
|
941
|
+
}, []);
|
|
942
|
+
const handleVisibilityByEventType = useCallback((e) => {
|
|
943
|
+
if (blocked || disabled) return;
|
|
944
|
+
processVisibilityEvent(e, active, openOn, closeOn, isNodeOrChild(triggerRef), isNodeOrChild(contentRef), showContent, hideContent);
|
|
945
|
+
}, [
|
|
946
|
+
active,
|
|
947
|
+
blocked,
|
|
948
|
+
disabled,
|
|
949
|
+
openOn,
|
|
950
|
+
closeOn,
|
|
951
|
+
hideContent,
|
|
952
|
+
showContent,
|
|
953
|
+
isNodeOrChild
|
|
954
|
+
]);
|
|
955
|
+
const latestSetContentPosition = useRef(setContentPosition);
|
|
956
|
+
latestSetContentPosition.current = setContentPosition;
|
|
957
|
+
const latestHandleVisibility = useRef(handleVisibilityByEventType);
|
|
958
|
+
latestHandleVisibility.current = handleVisibilityByEventType;
|
|
959
|
+
const handleContentPosition = useMemo(() => throttle(() => latestSetContentPosition.current(), throttleDelay), [throttleDelay]);
|
|
960
|
+
const handleClick = handleVisibilityByEventType;
|
|
961
|
+
const handleVisibility = useMemo(() => throttle((e) => latestHandleVisibility.current(e), throttleDelay), [throttleDelay]);
|
|
962
|
+
useEffect(() => {
|
|
963
|
+
setInnerAlignX(alignX);
|
|
964
|
+
setInnerAlignY(alignY);
|
|
965
|
+
if (disabled) hideContent();
|
|
966
|
+
}, [
|
|
967
|
+
disabled,
|
|
968
|
+
alignX,
|
|
969
|
+
alignY,
|
|
970
|
+
hideContent
|
|
971
|
+
]);
|
|
972
|
+
useEffect(() => {
|
|
973
|
+
if (!active || !isContentLoaded) return void 0;
|
|
974
|
+
setContentPosition();
|
|
975
|
+
const rafId = requestAnimationFrame(() => setContentPosition());
|
|
976
|
+
return () => cancelAnimationFrame(rafId);
|
|
977
|
+
}, [
|
|
978
|
+
active,
|
|
979
|
+
isContentLoaded,
|
|
980
|
+
setContentPosition
|
|
981
|
+
]);
|
|
982
|
+
const prevActiveRef = useRef(false);
|
|
983
|
+
useEffect(() => {
|
|
984
|
+
const wasActive = prevActiveRef.current;
|
|
985
|
+
prevActiveRef.current = active;
|
|
986
|
+
if (active && !wasActive) {
|
|
987
|
+
onOpen?.();
|
|
988
|
+
ctx.setBlocked?.();
|
|
989
|
+
} else if (!active && wasActive) {
|
|
990
|
+
setContentLoaded(false);
|
|
991
|
+
onClose?.();
|
|
992
|
+
ctx.setUnblocked?.();
|
|
993
|
+
} else if (!active) setContentLoaded(false);
|
|
994
|
+
return () => {
|
|
995
|
+
if (active) {
|
|
996
|
+
onClose?.();
|
|
997
|
+
ctx.setUnblocked?.();
|
|
998
|
+
}
|
|
999
|
+
};
|
|
1000
|
+
}, [
|
|
1001
|
+
active,
|
|
1002
|
+
ctx,
|
|
1003
|
+
onClose,
|
|
1004
|
+
onOpen
|
|
1005
|
+
]);
|
|
1006
|
+
useEffect(() => {
|
|
1007
|
+
if (!closeOnEsc || !active || blocked) return void 0;
|
|
1008
|
+
const handleEscKey = (e) => {
|
|
1009
|
+
if (e.key === "Escape") hideContent();
|
|
1010
|
+
};
|
|
1011
|
+
window.addEventListener("keydown", handleEscKey);
|
|
1012
|
+
return () => {
|
|
1013
|
+
window.removeEventListener("keydown", handleEscKey);
|
|
1014
|
+
};
|
|
1015
|
+
}, [
|
|
1016
|
+
active,
|
|
1017
|
+
blocked,
|
|
1018
|
+
closeOnEsc,
|
|
1019
|
+
hideContent
|
|
1020
|
+
]);
|
|
1021
|
+
useEffect(() => {
|
|
1022
|
+
if (!active) return void 0;
|
|
1023
|
+
const shouldSetOverflow = type === "modal";
|
|
1024
|
+
const onScroll = (e) => {
|
|
1025
|
+
handleContentPosition();
|
|
1026
|
+
handleVisibility(e);
|
|
1027
|
+
};
|
|
1028
|
+
if (shouldSetOverflow) document.body.style.overflow = "hidden";
|
|
1029
|
+
window.addEventListener("resize", handleContentPosition);
|
|
1030
|
+
window.addEventListener("scroll", onScroll, { passive: true });
|
|
1031
|
+
return () => {
|
|
1032
|
+
if (shouldSetOverflow) document.body.style.overflow = "";
|
|
1033
|
+
window.removeEventListener("resize", handleContentPosition);
|
|
1034
|
+
window.removeEventListener("scroll", onScroll);
|
|
1035
|
+
};
|
|
1036
|
+
}, [
|
|
1037
|
+
active,
|
|
1038
|
+
type,
|
|
1039
|
+
handleVisibility,
|
|
1040
|
+
handleContentPosition
|
|
1041
|
+
]);
|
|
1042
|
+
useEffect(() => {
|
|
1043
|
+
if (!active || !parentContainer) return void 0;
|
|
1044
|
+
if (closeOn !== "hover") parentContainer.style.overflow = "hidden";
|
|
1045
|
+
const onScroll = (e) => {
|
|
1046
|
+
handleContentPosition();
|
|
1047
|
+
handleVisibility(e);
|
|
1048
|
+
};
|
|
1049
|
+
parentContainer.addEventListener("scroll", onScroll, { passive: true });
|
|
1050
|
+
return () => {
|
|
1051
|
+
parentContainer.style.overflow = "";
|
|
1052
|
+
parentContainer.removeEventListener("scroll", onScroll);
|
|
1053
|
+
};
|
|
1054
|
+
}, [
|
|
1055
|
+
active,
|
|
1056
|
+
parentContainer,
|
|
1057
|
+
closeOn,
|
|
1058
|
+
handleContentPosition,
|
|
1059
|
+
handleVisibility
|
|
1060
|
+
]);
|
|
1061
|
+
useEffect(() => {
|
|
1062
|
+
if (blocked || disabled) return void 0;
|
|
1063
|
+
if (openOn === "click" || [
|
|
1064
|
+
"click",
|
|
1065
|
+
"clickOnTrigger",
|
|
1066
|
+
"clickOutsideContent"
|
|
1067
|
+
].includes(closeOn)) window.addEventListener("click", handleClick);
|
|
1068
|
+
return () => {
|
|
1069
|
+
window.removeEventListener("click", handleClick);
|
|
1070
|
+
};
|
|
1071
|
+
}, [
|
|
1072
|
+
openOn,
|
|
1073
|
+
closeOn,
|
|
1074
|
+
blocked,
|
|
1075
|
+
disabled,
|
|
1076
|
+
handleClick
|
|
1077
|
+
]);
|
|
1078
|
+
const hoverTimeoutRef = useRef(null);
|
|
1079
|
+
useEffect(() => {
|
|
1080
|
+
if (blocked || disabled || !(openOn === "hover" || closeOn === "hover")) return void 0;
|
|
1081
|
+
const trigger = triggerRef.current;
|
|
1082
|
+
const content = contentRef.current;
|
|
1083
|
+
const clearHoverTimeout = () => {
|
|
1084
|
+
if (hoverTimeoutRef.current != null) {
|
|
1085
|
+
clearTimeout(hoverTimeoutRef.current);
|
|
1086
|
+
hoverTimeoutRef.current = null;
|
|
1087
|
+
}
|
|
1088
|
+
};
|
|
1089
|
+
const scheduleHide = () => {
|
|
1090
|
+
clearHoverTimeout();
|
|
1091
|
+
hoverTimeoutRef.current = setTimeout(hideContent, 100);
|
|
1092
|
+
};
|
|
1093
|
+
const onTriggerEnter = () => {
|
|
1094
|
+
clearHoverTimeout();
|
|
1095
|
+
if (openOn === "hover" && !active) showContent();
|
|
1096
|
+
};
|
|
1097
|
+
const onTriggerLeave = () => {
|
|
1098
|
+
if (closeOn === "hover" && active) scheduleHide();
|
|
1099
|
+
};
|
|
1100
|
+
const onContentEnter = () => {
|
|
1101
|
+
clearHoverTimeout();
|
|
1102
|
+
};
|
|
1103
|
+
const onContentLeave = () => {
|
|
1104
|
+
if (closeOn === "hover" && active) scheduleHide();
|
|
1105
|
+
};
|
|
1106
|
+
if (trigger) {
|
|
1107
|
+
trigger.addEventListener("mouseenter", onTriggerEnter);
|
|
1108
|
+
trigger.addEventListener("mouseleave", onTriggerLeave);
|
|
1109
|
+
}
|
|
1110
|
+
if (content) {
|
|
1111
|
+
content.addEventListener("mouseenter", onContentEnter);
|
|
1112
|
+
content.addEventListener("mouseleave", onContentLeave);
|
|
1113
|
+
}
|
|
1114
|
+
return () => {
|
|
1115
|
+
clearHoverTimeout();
|
|
1116
|
+
if (trigger) {
|
|
1117
|
+
trigger.removeEventListener("mouseenter", onTriggerEnter);
|
|
1118
|
+
trigger.removeEventListener("mouseleave", onTriggerLeave);
|
|
1119
|
+
}
|
|
1120
|
+
if (content) {
|
|
1121
|
+
content.removeEventListener("mouseenter", onContentEnter);
|
|
1122
|
+
content.removeEventListener("mouseleave", onContentLeave);
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
}, [
|
|
1126
|
+
active,
|
|
1127
|
+
isContentLoaded,
|
|
1128
|
+
blocked,
|
|
1129
|
+
disabled,
|
|
1130
|
+
openOn,
|
|
1131
|
+
closeOn,
|
|
1132
|
+
showContent,
|
|
1133
|
+
hideContent
|
|
1134
|
+
]);
|
|
1135
|
+
return {
|
|
1136
|
+
triggerRef,
|
|
1137
|
+
contentRef: useCallback((node) => {
|
|
1138
|
+
if (node) {
|
|
1139
|
+
contentRef.current = node;
|
|
1140
|
+
setContentLoaded(true);
|
|
1141
|
+
}
|
|
1142
|
+
}, []),
|
|
1143
|
+
active,
|
|
1144
|
+
align,
|
|
1145
|
+
alignX: innerAlignX,
|
|
1146
|
+
alignY: innerAlignY,
|
|
1147
|
+
showContent,
|
|
1148
|
+
hideContent,
|
|
1149
|
+
blocked,
|
|
1150
|
+
setBlocked,
|
|
1151
|
+
setUnblocked,
|
|
1152
|
+
Provider: Component
|
|
1153
|
+
};
|
|
1085
1154
|
};
|
|
1086
1155
|
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1156
|
+
//#endregion
|
|
1157
|
+
//#region src/Overlay/component.tsx
|
|
1158
|
+
/**
|
|
1159
|
+
* Overlay component that renders a trigger element and conditionally shows
|
|
1160
|
+
* content via a Portal. The trigger receives a ref and optional show/hide
|
|
1161
|
+
* callbacks; the content is positioned and managed by the useOverlay hook.
|
|
1162
|
+
* A context Provider wraps the content to support nested overlays (e.g.,
|
|
1163
|
+
* a dropdown inside another dropdown) via blocked-state propagation.
|
|
1164
|
+
*/
|
|
1165
|
+
const IS_BROWSER = typeof window !== "undefined";
|
|
1166
|
+
const Component$3 = ({ children, trigger, DOMLocation, triggerRefName = "ref", contentRefName = "ref", ...props }) => {
|
|
1167
|
+
const { active, triggerRef, contentRef, showContent, hideContent, align, alignX, alignY, Provider, ...ctx } = useOverlay(props);
|
|
1168
|
+
const { openOn, closeOn } = props;
|
|
1169
|
+
const passHandlers = useMemo(() => openOn === "manual" || closeOn === "manual" || closeOn === "clickOutsideContent", [openOn, closeOn]);
|
|
1170
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [render(trigger, {
|
|
1171
|
+
[triggerRefName]: triggerRef,
|
|
1172
|
+
active,
|
|
1173
|
+
...passHandlers ? {
|
|
1174
|
+
showContent,
|
|
1175
|
+
hideContent
|
|
1176
|
+
} : {}
|
|
1177
|
+
}), IS_BROWSER && active && /* @__PURE__ */ jsx(Portal_default, {
|
|
1178
|
+
DOMLocation,
|
|
1179
|
+
children: /* @__PURE__ */ jsx(Provider, {
|
|
1180
|
+
...ctx,
|
|
1181
|
+
children: render(children, {
|
|
1182
|
+
[contentRefName]: contentRef,
|
|
1183
|
+
active,
|
|
1184
|
+
align,
|
|
1185
|
+
alignX,
|
|
1186
|
+
alignY,
|
|
1187
|
+
...passHandlers ? {
|
|
1188
|
+
showContent,
|
|
1189
|
+
hideContent
|
|
1190
|
+
} : {}
|
|
1191
|
+
})
|
|
1192
|
+
})
|
|
1193
|
+
})] });
|
|
1109
1194
|
};
|
|
1110
1195
|
const name$2 = `${PKG_NAME}/Overlay`;
|
|
1111
|
-
Component$
|
|
1112
|
-
Component$
|
|
1113
|
-
Component$
|
|
1196
|
+
Component$3.displayName = name$2;
|
|
1197
|
+
Component$3.pkgName = PKG_NAME;
|
|
1198
|
+
Component$3.VITUS_LABS__COMPONENT = name$2;
|
|
1114
1199
|
|
|
1200
|
+
//#endregion
|
|
1201
|
+
//#region src/Overlay/index.ts
|
|
1202
|
+
var Overlay_default = Component$3;
|
|
1203
|
+
|
|
1204
|
+
//#endregion
|
|
1205
|
+
//#region src/Text/styled.ts
|
|
1206
|
+
/**
|
|
1207
|
+
* Styled text primitive that inherits color, font-weight, and line-height
|
|
1208
|
+
* from its parent so it blends seamlessly into any context. Additional
|
|
1209
|
+
* styles can be injected via the responsive `extraStyles` prop processed
|
|
1210
|
+
* through makeItResponsive.
|
|
1211
|
+
*/
|
|
1115
1212
|
const { styled, css, textComponent } = config;
|
|
1116
|
-
const styles = ({ css, theme: t }) => css
|
|
1213
|
+
const styles = ({ css, theme: t }) => css`
|
|
1117
1214
|
${t.extraStyles && extendCss(t.extraStyles)};
|
|
1118
1215
|
`;
|
|
1119
|
-
var
|
|
1216
|
+
var styled_default = styled(textComponent)`
|
|
1120
1217
|
color: inherit;
|
|
1121
1218
|
font-weight: inherit;
|
|
1122
1219
|
line-height: 1;
|
|
1123
1220
|
|
|
1124
1221
|
${makeItResponsive({
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1222
|
+
key: "$text",
|
|
1223
|
+
styles,
|
|
1224
|
+
css,
|
|
1225
|
+
normalize: false
|
|
1129
1226
|
})};
|
|
1130
1227
|
`;
|
|
1131
1228
|
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1229
|
+
//#endregion
|
|
1230
|
+
//#region src/Text/component.tsx
|
|
1231
|
+
const Component$2 = forwardRef(({ paragraph, label, children, tag, css, ...props }, ref) => {
|
|
1232
|
+
const renderContent = (as = void 0) => /* @__PURE__ */ jsx(styled_default, {
|
|
1233
|
+
ref,
|
|
1234
|
+
as,
|
|
1235
|
+
$text: { extraStyles: css },
|
|
1236
|
+
...props,
|
|
1237
|
+
children: children ?? label
|
|
1238
|
+
});
|
|
1239
|
+
let finalTag;
|
|
1240
|
+
return renderContent(finalTag);
|
|
1136
1241
|
});
|
|
1137
|
-
// ----------------------------------------------
|
|
1138
|
-
// DEFINE STATICS
|
|
1139
|
-
// ----------------------------------------------
|
|
1140
1242
|
const name$1 = `${PKG_NAME}/Text`;
|
|
1141
|
-
Component$
|
|
1142
|
-
Component$
|
|
1143
|
-
Component$
|
|
1144
|
-
Component$
|
|
1243
|
+
Component$2.displayName = name$1;
|
|
1244
|
+
Component$2.pkgName = PKG_NAME;
|
|
1245
|
+
Component$2.VITUS_LABS__COMPONENT = name$1;
|
|
1246
|
+
Component$2.isText = true;
|
|
1247
|
+
|
|
1248
|
+
//#endregion
|
|
1249
|
+
//#region src/Text/index.ts
|
|
1250
|
+
var Text_default = Component$2;
|
|
1145
1251
|
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1252
|
+
//#endregion
|
|
1253
|
+
//#region src/Util/component.tsx
|
|
1254
|
+
/**
|
|
1255
|
+
* Utility wrapper that injects className and/or style props into its
|
|
1256
|
+
* children without adding any DOM nodes of its own. Uses the core `render`
|
|
1257
|
+
* helper to clone children with the merged props.
|
|
1258
|
+
*/
|
|
1259
|
+
const Component$1 = ({ children, className, style }) => {
|
|
1260
|
+
const mergedClasses = useMemo(() => Array.isArray(className) ? className.join(" ") : className, [className]);
|
|
1261
|
+
const finalProps = {};
|
|
1262
|
+
if (style) finalProps.style = style;
|
|
1263
|
+
if (mergedClasses) finalProps.className = mergedClasses;
|
|
1264
|
+
return render(children, finalProps);
|
|
1154
1265
|
};
|
|
1155
1266
|
const name = `${PKG_NAME}/Util`;
|
|
1156
|
-
Component.displayName = name;
|
|
1157
|
-
Component.pkgName = PKG_NAME;
|
|
1158
|
-
Component.VITUS_LABS__COMPONENT = name;
|
|
1267
|
+
Component$1.displayName = name;
|
|
1268
|
+
Component$1.pkgName = PKG_NAME;
|
|
1269
|
+
Component$1.VITUS_LABS__COMPONENT = name;
|
|
1270
|
+
|
|
1271
|
+
//#endregion
|
|
1272
|
+
//#region src/Util/index.ts
|
|
1273
|
+
var Util_default = Component$1;
|
|
1159
1274
|
|
|
1160
|
-
|
|
1161
|
-
|
|
1275
|
+
//#endregion
|
|
1276
|
+
export { Element_default as Element, List_default as List, Overlay_default as Overlay, Component as OverlayProvider, Portal_default as Portal, Provider, Text_default as Text, Util_default as Util, useOverlay, component as withActiveState, withEqualBeforeAfter as withEqualSizeBeforeAfter };
|
|
1277
|
+
//# sourceMappingURL=vitus-labs-elements.native.js.map
|