lilact 0.2.1 → 0.2.2
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/dist/lilact.development.min.js +198 -238
- package/dist/lilact.development.min.js.map +1 -1
- package/dist/lilact.production.min.js +8139 -1
- package/dist/lilact.production.min.js.map +1 -1
- package/docs/classes/accessories.ErrorBoundary.html +8 -8
- package/docs/classes/accessories.Suspense.html +7 -7
- package/docs/classes/components.Component.html +10 -10
- package/docs/classes/components.HTMLComponent.html +10 -10
- package/docs/classes/components.RootComponent.html +10 -10
- package/docs/functions/components.createComponent.html +1 -1
- package/docs/functions/components.createRoot.html +1 -1
- package/docs/functions/components.render.html +1 -1
- package/docs/functions/hooks.useActionState.html +3 -2
- package/docs/functions/hooks.useEffect.html +3 -2
- package/docs/functions/hooks.useImperativeHandle.html +1 -1
- package/docs/functions/hooks.useLayoutEffect.html +3 -2
- package/docs/functions/hooks.useLocalStorage.html +3 -2
- package/docs/functions/hooks.useMemo.html +3 -2
- package/docs/functions/hooks.useRef.html +3 -2
- package/docs/static/demos/pane.jsx +31 -0
- package/docs/static/index.html +1 -0
- package/docs/static/lilact.development.min.js +198 -238
- package/docs/static/lilact.production.min.js +8139 -1
- package/package.json +1 -1
- package/root/demos/pane.jsx +31 -0
- package/root/index.html +1 -0
- package/root/lilact.development.min.js +198 -238
- package/root/lilact.production.min.js +8139 -1
- package/src/components.jsx +4 -1
- package/src/hooks.jsx +15 -15
- package/src/misc.jsx +13 -1
- package/src/pane.jsx +207 -269
- package/webpack.config.js +1 -1
- package/docs/static/index 2.html +0 -95
- package/root/index 2.html +0 -95
package/src/components.jsx
CHANGED
|
@@ -401,6 +401,9 @@ class ComponentCore
|
|
|
401
401
|
this.event_detachers[al] = Lilact.addWrappedEventListener(this.element, al.substring(2), patch[a]);
|
|
402
402
|
}
|
|
403
403
|
else if(al==='style') {
|
|
404
|
+
for(const x in patch[a]) {
|
|
405
|
+
if(isFinite(patch[a][x])) patch[a][x]+='px';
|
|
406
|
+
}
|
|
404
407
|
Object.assign(this.element.style, patch[a]);
|
|
405
408
|
}
|
|
406
409
|
else {
|
|
@@ -418,7 +421,7 @@ class ComponentCore
|
|
|
418
421
|
}
|
|
419
422
|
|
|
420
423
|
ʔ if(DEBUG) {
|
|
421
|
-
this.element.setAttribute('key', this.props.key);
|
|
424
|
+
//this.element.setAttribute('key', this.props.key);
|
|
422
425
|
ʔ }
|
|
423
426
|
|
|
424
427
|
this.updateElementClass(patch);
|
package/src/hooks.jsx
CHANGED
|
@@ -207,7 +207,7 @@ export function useTransition()
|
|
|
207
207
|
* @param {any} initialValue - Initial value used if nothing exists in localStorage.
|
|
208
208
|
* @returns {any} Stored state/result.
|
|
209
209
|
*/
|
|
210
|
-
export function useLocalStorage(key,
|
|
210
|
+
export function useLocalStorage(key, initialValue)
|
|
211
211
|
{
|
|
212
212
|
|
|
213
213
|
const hk = Lilact.useHook();
|
|
@@ -220,8 +220,8 @@ export function useLocalStorage(key, default_val)
|
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
if(val===undefined) {
|
|
223
|
-
if(typeof(
|
|
224
|
-
val =
|
|
223
|
+
if(typeof(initialValue)==='function') initialValue = initialValue();
|
|
224
|
+
val = initialValue;
|
|
225
225
|
localStorage[key] = JSON.stringify(val);
|
|
226
226
|
}
|
|
227
227
|
|
|
@@ -251,12 +251,12 @@ export function useLocalStorage(key, default_val)
|
|
|
251
251
|
* @param {any} initialValue - Initial ref value.
|
|
252
252
|
* @returns {Object} Ref object with `.current`.
|
|
253
253
|
*/
|
|
254
|
-
export function useRef(
|
|
254
|
+
export function useRef(initialValue = null)
|
|
255
255
|
{
|
|
256
256
|
const hk = Lilact.useHook();
|
|
257
257
|
|
|
258
258
|
if( Lilact.isEmpty(hk) ) {
|
|
259
|
-
hk.current =
|
|
259
|
+
hk.current = initialValue;
|
|
260
260
|
}
|
|
261
261
|
|
|
262
262
|
return hk;
|
|
@@ -269,7 +269,7 @@ export function useRef(val = null)
|
|
|
269
269
|
* @param {Array<any>} [deps] - Dependency list.
|
|
270
270
|
* @returns {void}
|
|
271
271
|
*/
|
|
272
|
-
export function useLayoutEffect(
|
|
272
|
+
export function useLayoutEffect(effect, deps=undefined)
|
|
273
273
|
{
|
|
274
274
|
if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
|
|
275
275
|
throw "layout effect dependencies must be an array or omitted.";
|
|
@@ -286,7 +286,7 @@ export function useLayoutEffect(setup, deps=undefined)
|
|
|
286
286
|
}
|
|
287
287
|
|
|
288
288
|
hk.deps = deps;
|
|
289
|
-
Lilact.layout_effects.add( ()=>{ hk.cleanup =
|
|
289
|
+
Lilact.layout_effects.add( ()=>{ hk.cleanup = effect(); });
|
|
290
290
|
Lilact.current_component[0].component.forceUpdate();
|
|
291
291
|
}
|
|
292
292
|
|
|
@@ -297,7 +297,7 @@ export function useLayoutEffect(setup, deps=undefined)
|
|
|
297
297
|
* @param {Array<any>} [deps] - Dependency list.
|
|
298
298
|
* @returns {void}
|
|
299
299
|
*/
|
|
300
|
-
export function useEffect(
|
|
300
|
+
export function useEffect(effect, deps=undefined)
|
|
301
301
|
{
|
|
302
302
|
if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
|
|
303
303
|
throw "effect dependencies must be an array or omitted.";
|
|
@@ -314,7 +314,7 @@ export function useEffect(setup, deps=[{}])
|
|
|
314
314
|
}
|
|
315
315
|
|
|
316
316
|
hk.deps = deps;
|
|
317
|
-
Lilact.setTimeout( ()=>{ hk.cleanup =
|
|
317
|
+
Lilact.setTimeout( ()=>{ hk.cleanup = effect(); }, 0 );
|
|
318
318
|
|
|
319
319
|
}
|
|
320
320
|
|
|
@@ -325,7 +325,7 @@ export function useEffect(setup, deps=[{}])
|
|
|
325
325
|
* @param {Array<any>} deps - Dependency list.
|
|
326
326
|
* @returns {any} Memoized value.
|
|
327
327
|
*/
|
|
328
|
-
export function useMemo(
|
|
328
|
+
export function useMemo(factory,deps=undefined)
|
|
329
329
|
{
|
|
330
330
|
if( deps!==undefined && (typeof(deps)!=='object' || deps.constructor.name!=='Array') ) {
|
|
331
331
|
throw "memo dependencies must be an array or omitted.";
|
|
@@ -338,7 +338,7 @@ export function useMemo(fn,deps=undefined)
|
|
|
338
338
|
}
|
|
339
339
|
|
|
340
340
|
hk.deps = deps;
|
|
341
|
-
hk.value =
|
|
341
|
+
hk.value = factory(hk.value);
|
|
342
342
|
|
|
343
343
|
return hk.value;
|
|
344
344
|
}
|
|
@@ -350,14 +350,14 @@ export function useMemo(fn,deps=undefined)
|
|
|
350
350
|
* @param {any} initialState - Initial state for the hook.
|
|
351
351
|
* @returns {any} Hook result
|
|
352
352
|
*/
|
|
353
|
-
export function useActionState(fn,
|
|
353
|
+
export function useActionState(fn, initialState)
|
|
354
354
|
{
|
|
355
355
|
const hk = Lilact.useHook();
|
|
356
356
|
const [is_pending, tran_start_func] = Lilact.useTransition();
|
|
357
357
|
|
|
358
358
|
if( Lilact.isEmpty(hk) ) {
|
|
359
359
|
|
|
360
|
-
hk.state =
|
|
360
|
+
hk.state = initialState;
|
|
361
361
|
|
|
362
362
|
hk.form_action = (sub)=>{
|
|
363
363
|
event.preventDefault();
|
|
@@ -486,7 +486,7 @@ export function forwardRef(render)
|
|
|
486
486
|
* Dependency list that controls when the exposed value is recalculated.
|
|
487
487
|
* @returns {void}
|
|
488
488
|
*/
|
|
489
|
-
export function useImperativeHandle(ref, factory, deps)
|
|
489
|
+
export function useImperativeHandle(ref, factory, deps=undefined)
|
|
490
490
|
{
|
|
491
491
|
if(deps!==undefined && ref?.deps!==undefined && Lilact.shallowEqual(deps, ref.deps)) return;
|
|
492
492
|
|
|
@@ -497,6 +497,6 @@ export function useImperativeHandle(ref, factory, deps)
|
|
|
497
497
|
ref.current = {};
|
|
498
498
|
}
|
|
499
499
|
Object.assign( ref.current, factory(), 0 );
|
|
500
|
-
});
|
|
500
|
+
}, 0);
|
|
501
501
|
}
|
|
502
502
|
|
package/src/misc.jsx
CHANGED
|
@@ -414,6 +414,18 @@ export let events_set = new Set([
|
|
|
414
414
|
"onabort","oncanplay","oncanplaythrough","oncuechange","ondurationchange","onemptied","onended","onerror",
|
|
415
415
|
"onloadeddata","onloadedmetadata","onloadstart","onpause","onplay","onplaying","onprogress","onratechange",
|
|
416
416
|
"onseeked","onseeking","onstalled","onsuspend","ontimeupdate","onvolumechange","onwaiting",
|
|
417
|
-
"ontoggle"
|
|
417
|
+
"ontoggle",
|
|
418
|
+
|
|
419
|
+
"onpointerdown", "onpointerup", "onpointermove", "onpointercancel", "onpointerover", "onpointerout",
|
|
420
|
+
"onpointerenter", "onpointerleave"
|
|
421
|
+
])
|
|
422
|
+
/** @ignore */
|
|
423
|
+
export let length_css_attributes_set = new Set([
|
|
424
|
+
"width","height","minWidth","minHeight","maxWidth","maxHeight","top","right","bottom","left","margin",
|
|
425
|
+
"marginTop","marginRight","marginBottom","marginLeft","padding","paddingTop","paddingRight","paddingBottom",
|
|
426
|
+
"paddingLeft","borderWidth","borderTopWidth","borderRightWidth","borderBottomWidth","borderLeftWidth",
|
|
427
|
+
"outlineWidth","fontSize","lineHeight","letterSpacing","wordSpacing","textIndent","borderRadius",
|
|
428
|
+
"borderTopLeftRadius","borderTopRightRadius","borderBottomLeftRadius","borderBottomRightRadius",
|
|
429
|
+
"columnGap","rowGap","gap"
|
|
418
430
|
])
|
|
419
431
|
|
package/src/pane.jsx
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { useEffect, useLayoutEffect, useMemo, useRef, useState, forwardRef, useImperativeHandle } from "./hooks.jsx";
|
|
2
2
|
import { Children } from "./misc.jsx";
|
|
3
3
|
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
4
|
+
|
|
5
|
+
const clamp = (n, min, max) => {
|
|
6
|
+
if (!Number.isFinite(n)) return n;
|
|
7
|
+
return Math.min(max, Math.max(min, n));
|
|
8
|
+
};
|
|
7
9
|
|
|
8
10
|
/**
|
|
9
11
|
* ResizablePane
|
|
@@ -17,271 +19,207 @@ function clamp(n, min, max) {
|
|
|
17
19
|
* - Callback when size changes via onSizeChange
|
|
18
20
|
* - Children are rendered in two separate containers (no portals)
|
|
19
21
|
*/
|
|
20
|
-
export const ResizablePane = forwardRef(function
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
ref
|
|
22
|
+
export const ResizablePane = forwardRef(function ResizablePane(
|
|
23
|
+
{
|
|
24
|
+
mode = "horizontal",
|
|
25
|
+
position, // controlled: number | undefined/null
|
|
26
|
+
defaultPosition = 0.5,
|
|
27
|
+
min = 0.1,
|
|
28
|
+
max = 0.9,
|
|
29
|
+
splitterSize = 8,
|
|
30
|
+
onSizeChange,
|
|
31
|
+
style,
|
|
32
|
+
className,
|
|
33
|
+
leftPaneStyle,
|
|
34
|
+
rightPaneStyle,
|
|
35
|
+
splitterStyle,
|
|
36
|
+
children,
|
|
37
|
+
},
|
|
38
|
+
ref
|
|
38
39
|
) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
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
|
-
flex: `1 1 auto`,
|
|
225
|
-
overflow: "auto",
|
|
226
|
-
...(rightPaneStyle || {}),
|
|
227
|
-
};
|
|
228
|
-
|
|
229
|
-
const splitterComputed =
|
|
230
|
-
modeResolved === "horizontal"
|
|
231
|
-
? {
|
|
232
|
-
width: `${splitterSize}px`,
|
|
233
|
-
flex: `0 0 ${splitterSize}px`,
|
|
234
|
-
cursor: "col-resize",
|
|
235
|
-
background: "transparent",
|
|
236
|
-
...(splitterStyle || {}),
|
|
237
|
-
}
|
|
238
|
-
: {
|
|
239
|
-
height: `${splitterSize}px`,
|
|
240
|
-
flex: `0 0 ${splitterSize}px`,
|
|
241
|
-
cursor: "row-resize",
|
|
242
|
-
background: "transparent",
|
|
243
|
-
...(splitterStyle || {}),
|
|
244
|
-
};
|
|
245
|
-
|
|
246
|
-
const dividerVisualStyle =
|
|
247
|
-
modeResolved === "horizontal"
|
|
248
|
-
? {
|
|
249
|
-
height: "100%",
|
|
250
|
-
width: "100%",
|
|
251
|
-
background: "rgba(0,0,0,0.08)",
|
|
252
|
-
}
|
|
253
|
-
: {
|
|
254
|
-
width: "100%",
|
|
255
|
-
height: "100%",
|
|
256
|
-
background: "rgba(0,0,0,0.08)",
|
|
257
|
-
};
|
|
258
|
-
|
|
259
|
-
return (
|
|
260
|
-
<div
|
|
261
|
-
ref={containerRef}
|
|
262
|
-
className={className}
|
|
263
|
-
style={rootStyle}
|
|
264
|
-
onPointerMove={onPointerMove}
|
|
265
|
-
>
|
|
266
|
-
<div style={leftPaneComputed}>{leftChild}</div>
|
|
267
|
-
|
|
268
|
-
<div
|
|
269
|
-
role="separator"
|
|
270
|
-
aria-orientation={modeResolved === "horizontal" ? "vertical" : "horizontal"}
|
|
271
|
-
aria-valuemin={min}
|
|
272
|
-
aria-valuemax={max}
|
|
273
|
-
aria-valuenow={posResolved}
|
|
274
|
-
tabIndex={0}
|
|
275
|
-
onPointerDown={onPointerDown}
|
|
276
|
-
onPointerUp={stopDragging}
|
|
277
|
-
onPointerCancel={stopDragging}
|
|
278
|
-
onKeyDown={onSplitterKeyDown}
|
|
279
|
-
style={splitterComputed}
|
|
280
|
-
>
|
|
281
|
-
<div style={dividerVisualStyle} />
|
|
282
|
-
</div>
|
|
283
|
-
|
|
284
|
-
<div style={rightPaneComputed}>{rightChild}</div>
|
|
285
|
-
</div>
|
|
286
|
-
);
|
|
40
|
+
const containerRef = useRef(null);
|
|
41
|
+
const panes = Children.toArray(children);
|
|
42
|
+
const leftChild = panes[0] ?? null;
|
|
43
|
+
const rightChild = panes[1] ?? null;
|
|
44
|
+
|
|
45
|
+
const isControlled = position != null;
|
|
46
|
+
|
|
47
|
+
const [internalMode, setInternalMode] = useState(mode);
|
|
48
|
+
|
|
49
|
+
const [posUncontrolled, setPosUncontrolled] = useState(() =>
|
|
50
|
+
clamp(
|
|
51
|
+
position ?? defaultPosition,
|
|
52
|
+
min,
|
|
53
|
+
max
|
|
54
|
+
)
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
useEffect(() => {
|
|
58
|
+
if (mode != null) setInternalMode(mode);
|
|
59
|
+
}, [mode]);
|
|
60
|
+
|
|
61
|
+
// keep internal position clamped if min/max change (uncontrolled only)
|
|
62
|
+
useLayoutEffect(() => {
|
|
63
|
+
if (isControlled) return;
|
|
64
|
+
setPosUncontrolled((p) => clamp(p, min, max));
|
|
65
|
+
}, [min, max, isControlled]);
|
|
66
|
+
|
|
67
|
+
const posResolved = isControlled ? clamp(position, min, max) : posUncontrolled;
|
|
68
|
+
|
|
69
|
+
const setPosition = (next) => {
|
|
70
|
+
const clamped = clamp(next, min, max);
|
|
71
|
+
if (!isControlled) setPosUncontrolled(clamped);
|
|
72
|
+
onSizeChange?.(clamped);
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
const draggingRef = useRef(false);
|
|
76
|
+
const pointerIdRef = useRef(null);
|
|
77
|
+
|
|
78
|
+
const updateFromClient = (clientX, clientY) => {
|
|
79
|
+
const el = containerRef.current;
|
|
80
|
+
if (!el) return;
|
|
81
|
+
|
|
82
|
+
const rect = el.getBoundingClientRect();
|
|
83
|
+
|
|
84
|
+
if (internalMode === "horizontal") {
|
|
85
|
+
const usable = rect.width;
|
|
86
|
+
if (!Number.isFinite(usable) || usable <= 0) return; // no jump on init
|
|
87
|
+
const raw = (clientX - rect.left) / usable;
|
|
88
|
+
if (!Number.isFinite(raw)) return;
|
|
89
|
+
setPosition(raw);
|
|
90
|
+
} else {
|
|
91
|
+
const usable = rect.height;
|
|
92
|
+
if (!Number.isFinite(usable) || usable <= 0) return; // no jump on init
|
|
93
|
+
const raw = (clientY - rect.top) / usable;
|
|
94
|
+
if (!Number.isFinite(raw)) return;
|
|
95
|
+
setPosition(raw);
|
|
96
|
+
}
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
// stable global listeners: only act while draggingRef.current === true
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const onMove = (e) => {
|
|
102
|
+
if (!draggingRef.current) return;
|
|
103
|
+
if (pointerIdRef.current != null && e.pointerId !== pointerIdRef.current) return;
|
|
104
|
+
updateFromClient(e.clientX, e.clientY);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const stop = (e) => {
|
|
108
|
+
if (!draggingRef.current) return;
|
|
109
|
+
if (pointerIdRef.current != null && e.pointerId !== pointerIdRef.current) return;
|
|
110
|
+
draggingRef.current = false;
|
|
111
|
+
pointerIdRef.current = null;
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
window.addEventListener("pointermove", onMove, { passive: true });
|
|
115
|
+
window.addEventListener("pointerup", stop, { passive: true });
|
|
116
|
+
window.addEventListener("pointercancel", stop, { passive: true });
|
|
117
|
+
|
|
118
|
+
return () => {
|
|
119
|
+
window.removeEventListener("pointermove", onMove);
|
|
120
|
+
window.removeEventListener("pointerup", stop);
|
|
121
|
+
window.removeEventListener("pointercancel", stop);
|
|
122
|
+
};
|
|
123
|
+
}, [internalMode]); // updateFromClient uses internalMode
|
|
124
|
+
|
|
125
|
+
const onPointerDown = (e) => {
|
|
126
|
+
if (e.button != null && e.button !== 0) return;
|
|
127
|
+
e.preventDefault();
|
|
128
|
+
|
|
129
|
+
draggingRef.current = true;
|
|
130
|
+
pointerIdRef.current = e.pointerId;
|
|
131
|
+
|
|
132
|
+
try {
|
|
133
|
+
e.currentTarget.setPointerCapture?.(e.pointerId);
|
|
134
|
+
} catch {}
|
|
135
|
+
|
|
136
|
+
updateFromClient(e.clientX, e.clientY); // first update only if rect is sane
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
const onKeyDown = (e) => {
|
|
140
|
+
const step = 0.02;
|
|
141
|
+
let delta = 0;
|
|
142
|
+
|
|
143
|
+
if (internalMode === "horizontal") {
|
|
144
|
+
if (e.key === "ArrowLeft") delta = -step;
|
|
145
|
+
if (e.key === "ArrowRight") delta = step;
|
|
146
|
+
} else {
|
|
147
|
+
if (e.key === "ArrowUp") delta = -step;
|
|
148
|
+
if (e.key === "ArrowDown") delta = step;
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
if (delta !== 0) {
|
|
152
|
+
e.preventDefault();
|
|
153
|
+
setPosition(posResolved + delta);
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
|
|
157
|
+
const sizes = useMemo(() => {
|
|
158
|
+
const leftPct = `${posResolved * 100}%`;
|
|
159
|
+
const rightCalc = `calc(${100 - posResolved * 100}% - ${splitterSize}px)`;
|
|
160
|
+
return { leftPct, rightCalc };
|
|
161
|
+
}, [posResolved, splitterSize]);
|
|
162
|
+
|
|
163
|
+
const rootStyle = {
|
|
164
|
+
display: "flex",
|
|
165
|
+
width: "100%",
|
|
166
|
+
height: "100%",
|
|
167
|
+
overflow: "hidden",
|
|
168
|
+
touchAction: "none",
|
|
169
|
+
...(style || {}),
|
|
170
|
+
flexDirection: internalMode === "horizontal" ? "row" : "column",
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
const leftPaneComputed =
|
|
174
|
+
internalMode === "horizontal"
|
|
175
|
+
? { width: sizes.leftPct, flex: `0 0 ${sizes.leftPct}`, overflow: "auto", ...(leftPaneStyle || {}) }
|
|
176
|
+
: { height: sizes.leftPct, flex: `0 0 ${sizes.leftPct}`, overflow: "auto", ...(leftPaneStyle || {}) };
|
|
177
|
+
|
|
178
|
+
const rightPaneComputed =
|
|
179
|
+
internalMode === "horizontal"
|
|
180
|
+
? { width: sizes.rightCalc, flex: "1 1 auto", overflow: "auto", ...(rightPaneStyle || {}) }
|
|
181
|
+
: { height: sizes.rightCalc, flex: "1 1 auto", overflow: "auto", ...(rightPaneStyle || {}) };
|
|
182
|
+
|
|
183
|
+
const splitterComputed =
|
|
184
|
+
internalMode === "horizontal"
|
|
185
|
+
? { width: `${splitterSize}px`, height: '100%', flex: `0 0 ${splitterSize}px`, background: "rgba(0,0,0,0.08)", cursor: "col-resize", ...(splitterStyle || {}) }
|
|
186
|
+
: { height: `${splitterSize}px`, width: '100%', flex: `0 0 ${splitterSize}px`, background: "rgba(0,0,0,0.08)", cursor: "row-resize", ...(splitterStyle || {}) };
|
|
187
|
+
|
|
188
|
+
const dividerVisualStyle =
|
|
189
|
+
internalMode === "horizontal"
|
|
190
|
+
? { height: "100%", width: "100%" }
|
|
191
|
+
: { width: "100%", height: "100%" };
|
|
192
|
+
|
|
193
|
+
useImperativeHandle(ref, () => ({
|
|
194
|
+
setPosition,
|
|
195
|
+
setMode: (nextMode) => setInternalMode(nextMode === "vertical" ? "vertical" : "horizontal"),
|
|
196
|
+
getPosition: () => posResolved,
|
|
197
|
+
getMode: () => internalMode,
|
|
198
|
+
}));
|
|
199
|
+
|
|
200
|
+
return (
|
|
201
|
+
<div ref={containerRef} className={className} style={rootStyle}>
|
|
202
|
+
<div style={leftPaneComputed}>{leftChild}</div>
|
|
203
|
+
|
|
204
|
+
<div
|
|
205
|
+
role="separator"
|
|
206
|
+
aria-orientation={internalMode === "horizontal" ? "vertical" : "horizontal"}
|
|
207
|
+
aria-valuemin={min}
|
|
208
|
+
aria-valuemax={max}
|
|
209
|
+
aria-valuenow={posResolved}
|
|
210
|
+
tabIndex={0}
|
|
211
|
+
onPointerDown={onPointerDown}
|
|
212
|
+
onPointerCancel={() => {
|
|
213
|
+
draggingRef.current = false;
|
|
214
|
+
pointerIdRef.current = null;
|
|
215
|
+
}}
|
|
216
|
+
onKeyDown={onKeyDown}
|
|
217
|
+
style={splitterComputed}
|
|
218
|
+
>
|
|
219
|
+
<div style={dividerVisualStyle} />
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
<div style={rightPaneComputed}>{rightChild}</div>
|
|
223
|
+
</div>
|
|
224
|
+
);
|
|
287
225
|
});
|
package/webpack.config.js
CHANGED
|
@@ -56,7 +56,7 @@ export default (env, argv) => {
|
|
|
56
56
|
optimization: {
|
|
57
57
|
concatenateModules: true, // scope hoisting
|
|
58
58
|
moduleIds: 'deterministic', // smaller stable ids (or 'hashed')
|
|
59
|
-
minimize: mode === 'production',
|
|
59
|
+
minimize: false, //mode === 'production',
|
|
60
60
|
},
|
|
61
61
|
experiments: {
|
|
62
62
|
outputModule: true // enable module output
|