lilact 0.11.5 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/lilact.development.js +146 -16
- package/dist/lilact.development.js.map +1 -1
- package/dist/lilact.development.min.js +1 -1
- package/dist/lilact.development.min.js.map +1 -1
- package/dist/lilact.production.min.js +1 -1
- package/dist/lilact.production.min.js.map +1 -1
- package/docs/assets/hierarchy.js +1 -1
- package/docs/assets/navigation.js +1 -1
- package/docs/assets/search.js +1 -1
- package/docs/classes/accessories.ErrorBoundary.html +11 -11
- package/docs/classes/accessories.Suspense.html +10 -10
- package/docs/classes/components.Component.html +11 -11
- package/docs/classes/components.HTMLComponent.html +11 -11
- package/docs/classes/components.RootComponent.html +11 -11
- package/docs/functions/accessories.DragHandle.html +6 -0
- package/docs/functions/accessories.Spinner.html +1 -1
- 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/hierarchy.html +1 -1
- package/docs/index.html +3 -2
- package/docs/modules/accessories.html +1 -1
- package/docs/modules/pane.html +1 -1
- package/docs/static/demos/pane.jsx +3 -3
- package/docs/static/index.html +1 -1
- package/docs/static/lilact.development.js +146 -16
- package/docs/static/lilact.development.min.js +1 -1
- package/docs/static/lilact.production.min.js +1 -1
- package/docs/variables/{pane.ResizablePane.html → pane.SplitPane.html} +2 -2
- package/package.json +1 -1
- package/root/demos/pane.jsx +3 -3
- package/root/index.html +1 -1
- package/root/lilact.development.js +146 -16
- package/root/lilact.development.min.js +1 -1
- package/root/lilact.production.min.js +1 -1
- package/src/accessories.jsx +118 -0
- package/src/components.jsx +24 -4
- package/src/lilact.jsx +4 -4
- package/src/pane.jsx +4 -4
package/src/accessories.jsx
CHANGED
|
@@ -31,6 +31,9 @@
|
|
|
31
31
|
import {isThenable} from "./misc.jsx"
|
|
32
32
|
import {setTimeout, clearTimeout} from "./timers.jsx"
|
|
33
33
|
import {Component} from "./components.jsx"
|
|
34
|
+
import {useRef, useState, useCallback} from './hooks.jsx'
|
|
35
|
+
import {emotion} from "./lilact.jsx"
|
|
36
|
+
const {css,cx} = emotion;
|
|
34
37
|
|
|
35
38
|
/**
|
|
36
39
|
* A CSS-only loading spinner component.
|
|
@@ -284,3 +287,118 @@ export class Suspense extends Component
|
|
|
284
287
|
}
|
|
285
288
|
}
|
|
286
289
|
|
|
290
|
+
/**
|
|
291
|
+
* DragHandle - helper component to wire up drag interactions.
|
|
292
|
+
*
|
|
293
|
+
* This component does not implement dragging/movement itself. Instead, it listens
|
|
294
|
+
* for drag gesture updates and delegates them to the provided callbacks.
|
|
295
|
+
*
|
|
296
|
+
* @param onDelta - Called when the drag position changes. Receives the delta as
|
|
297
|
+
* `{ x, y, data }`.
|
|
298
|
+
* @param onStart - Called when the drag begins. Receives the provided `data`.
|
|
299
|
+
* @param onEnd - Called when the drag finishes or is cancelled.
|
|
300
|
+
* Receives `(event, data)` where `event` is either `"up"` (completed) or `"cancel"`.
|
|
301
|
+
* @param data - Arbitrary user data passed back to callbacks.
|
|
302
|
+
* @param style - Optional style applied to the rendered wrapper.
|
|
303
|
+
* @param className - Optional CSS class applied to the rendered wrapper.
|
|
304
|
+
* @param children - Content to render inside the drag handle.
|
|
305
|
+
*/
|
|
306
|
+
export function DragHandle({
|
|
307
|
+
onDelta,
|
|
308
|
+
onStart,
|
|
309
|
+
onEnd,
|
|
310
|
+
style,
|
|
311
|
+
className,
|
|
312
|
+
children,
|
|
313
|
+
data
|
|
314
|
+
}) {
|
|
315
|
+
const activePointerIdRef = useRef(null);
|
|
316
|
+
const startClientXRef = useRef(0);
|
|
317
|
+
const startClientYRef = useRef(0);
|
|
318
|
+
const lastClientXRef = useRef(0);
|
|
319
|
+
const lastClientYRef = useRef(0);
|
|
320
|
+
const draggingRef = useRef(false);
|
|
321
|
+
|
|
322
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
323
|
+
|
|
324
|
+
const resetDrag = useCallback(() => {
|
|
325
|
+
activePointerIdRef.current = null;
|
|
326
|
+
draggingRef.current = false;
|
|
327
|
+
startClientXRef.current = 0;
|
|
328
|
+
startClientYRef.current = 0;
|
|
329
|
+
lastClientXRef.current = 0;
|
|
330
|
+
lastClientYRef.current = 0;
|
|
331
|
+
setIsDragging(false);
|
|
332
|
+
}, []);
|
|
333
|
+
|
|
334
|
+
const computeDeltaFromStart = useCallback((clientX, clientY) => {
|
|
335
|
+
const dx = clientX - startClientXRef.current;
|
|
336
|
+
const dy = clientY - startClientYRef.current;
|
|
337
|
+
return { dx, dy };
|
|
338
|
+
}, []);
|
|
339
|
+
|
|
340
|
+
const endDrag = useCallback((reason = "up") => {
|
|
341
|
+
if (!draggingRef.current) return;
|
|
342
|
+
onEnd?.(reason);
|
|
343
|
+
resetDrag();
|
|
344
|
+
}, [onEnd, resetDrag]);
|
|
345
|
+
|
|
346
|
+
const onPointerDown = useCallback((e) => {
|
|
347
|
+
// todo: only left mouse / primary touch, should other buttons be supported too?
|
|
348
|
+
if (e.button != null && e.button !== 0) return;
|
|
349
|
+
|
|
350
|
+
draggingRef.current = true;
|
|
351
|
+
activePointerIdRef.current = e.pointerId;
|
|
352
|
+
|
|
353
|
+
startClientXRef.current = e.clientX;
|
|
354
|
+
startClientYRef.current = e.clientY;
|
|
355
|
+
lastClientXRef.current = e.clientX;
|
|
356
|
+
lastClientYRef.current = e.clientY;
|
|
357
|
+
|
|
358
|
+
setIsDragging(true);
|
|
359
|
+
onStart?.(data);
|
|
360
|
+
|
|
361
|
+
try {
|
|
362
|
+
e.currentTarget.setPointerCapture(e.pointerId);
|
|
363
|
+
} catch {
|
|
364
|
+
// ignore if unsupported
|
|
365
|
+
}
|
|
366
|
+
}, [onStart]);
|
|
367
|
+
|
|
368
|
+
const onPointerMove = useCallback((e) => {
|
|
369
|
+
if (!draggingRef.current) return;
|
|
370
|
+
if (activePointerIdRef.current !== e.pointerId) return;
|
|
371
|
+
|
|
372
|
+
const { dx, dy } = computeDeltaFromStart(e.clientX, e.clientY);
|
|
373
|
+
onDelta?.(dx, dy, data);
|
|
374
|
+
|
|
375
|
+
lastClientXRef.current = e.clientX;
|
|
376
|
+
lastClientYRef.current = e.clientY;
|
|
377
|
+
}, [computeDeltaFromStart, onDelta]);
|
|
378
|
+
|
|
379
|
+
const onPointerUp = useCallback((e) => {
|
|
380
|
+
if (activePointerIdRef.current !== e.pointerId) return;
|
|
381
|
+
endDrag("up", data);
|
|
382
|
+
}, [endDrag]);
|
|
383
|
+
|
|
384
|
+
const onPointerCancel = useCallback((e) => {
|
|
385
|
+
if (activePointerIdRef.current !== e.pointerId) return;
|
|
386
|
+
endDrag("cancel", data);
|
|
387
|
+
}, [endDrag]);
|
|
388
|
+
|
|
389
|
+
return (
|
|
390
|
+
<div
|
|
391
|
+
role="button"
|
|
392
|
+
tabIndex={0}
|
|
393
|
+
style={{ ...style, touchAction: "none" }}
|
|
394
|
+
className={cx(className, isDragging?"dragging":"")}
|
|
395
|
+
onPointerDown={onPointerDown}
|
|
396
|
+
onPointerMove={onPointerMove}
|
|
397
|
+
onPointerUp={onPointerUp}
|
|
398
|
+
onPointerCancel={onPointerCancel}
|
|
399
|
+
>
|
|
400
|
+
{children}
|
|
401
|
+
</div>
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
|
package/src/components.jsx
CHANGED
|
@@ -195,11 +195,22 @@ class ComponentCore
|
|
|
195
195
|
|
|
196
196
|
|
|
197
197
|
if(next_props.ref) {
|
|
198
|
-
if(
|
|
199
|
-
|
|
198
|
+
if(typeof(next_props.ref)==='function') {
|
|
199
|
+
if(this.element) {
|
|
200
|
+
next_props.ref(this.element);
|
|
201
|
+
}
|
|
202
|
+
else {
|
|
203
|
+
next_props.ref(this.component);
|
|
204
|
+
}
|
|
205
|
+
|
|
200
206
|
}
|
|
201
207
|
else {
|
|
202
|
-
|
|
208
|
+
if(this.element) {
|
|
209
|
+
next_props.ref.current = this.element;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
next_props.ref.current = this.component;
|
|
213
|
+
}
|
|
203
214
|
}
|
|
204
215
|
}
|
|
205
216
|
|
|
@@ -311,7 +322,16 @@ class ComponentCore
|
|
|
311
322
|
{
|
|
312
323
|
try {
|
|
313
324
|
const promises = [];
|
|
314
|
-
|
|
325
|
+
|
|
326
|
+
if(this.props?.ref) {
|
|
327
|
+
if(typeof(this.props.ref)==='function') {
|
|
328
|
+
this.props.ref(null);
|
|
329
|
+
}
|
|
330
|
+
else {
|
|
331
|
+
this.props.current = null;
|
|
332
|
+
}
|
|
333
|
+
}
|
|
334
|
+
|
|
315
335
|
if(this.component.componentWillUnmount) {
|
|
316
336
|
this.component.componentWillUnmount();
|
|
317
337
|
}
|
package/src/lilact.jsx
CHANGED
|
@@ -63,7 +63,7 @@ import * as misc from './misc.jsx';
|
|
|
63
63
|
import * as errors from './errors.jsx';
|
|
64
64
|
import * as router from './router.jsx';
|
|
65
65
|
import * as accessories from './accessories.jsx';
|
|
66
|
-
import {
|
|
66
|
+
import {SplitPane} from './pane.jsx';
|
|
67
67
|
import {transpileJSX, transpilerConfig} from "./jsx";
|
|
68
68
|
|
|
69
69
|
|
|
@@ -80,7 +80,7 @@ export * from './misc.jsx';
|
|
|
80
80
|
export * from './errors.jsx';
|
|
81
81
|
export * from './router.jsx';
|
|
82
82
|
export * from './accessories.jsx';
|
|
83
|
-
export {
|
|
83
|
+
export {SplitPane} from './pane.jsx';
|
|
84
84
|
export {transpileJSX, transpilerConfig} from "./jsx";
|
|
85
85
|
|
|
86
86
|
|
|
@@ -94,7 +94,7 @@ export {transpileJSX, transpilerConfig} from "./jsx";
|
|
|
94
94
|
export const Lilact =
|
|
95
95
|
{
|
|
96
96
|
|
|
97
|
-
VERSION: "beta.
|
|
97
|
+
VERSION: "beta.13",
|
|
98
98
|
|
|
99
99
|
// Configuration
|
|
100
100
|
|
|
@@ -117,7 +117,7 @@ export const Lilact =
|
|
|
117
117
|
...router,
|
|
118
118
|
...accessories,
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
SplitPane,
|
|
121
121
|
|
|
122
122
|
transpileJSX,
|
|
123
123
|
transpilerConfig,
|
package/src/pane.jsx
CHANGED
|
@@ -48,9 +48,9 @@ const clamp = (n, min, max) => {
|
|
|
48
48
|
*
|
|
49
49
|
* @example
|
|
50
50
|
* ```tsx
|
|
51
|
-
* const ref = useRef<
|
|
51
|
+
* const ref = useRef<SplitPaneHandle>(null);
|
|
52
52
|
*
|
|
53
|
-
* <
|
|
53
|
+
* <SplitPane
|
|
54
54
|
* ref={ref}
|
|
55
55
|
* mode="horizontal"
|
|
56
56
|
* defaultPosition={0.5}
|
|
@@ -59,10 +59,10 @@ const clamp = (n, min, max) => {
|
|
|
59
59
|
* onSizeChange={(pos) => console.log(pos)}
|
|
60
60
|
* >
|
|
61
61
|
* <div /> <div />
|
|
62
|
-
* </
|
|
62
|
+
* </SplitPane>
|
|
63
63
|
* ```
|
|
64
64
|
*/
|
|
65
|
-
export const
|
|
65
|
+
export const SplitPane = forwardRef(function SplitPane(
|
|
66
66
|
{
|
|
67
67
|
mode = "horizontal",
|
|
68
68
|
position, // controlled: number | undefined/null
|