lilact 0.11.4 → 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.
Files changed (46) hide show
  1. package/README.md +3 -2
  2. package/dist/lilact.development.js +159 -27
  3. package/dist/lilact.development.js.map +1 -1
  4. package/dist/lilact.development.min.js +1 -1
  5. package/dist/lilact.development.min.js.map +1 -1
  6. package/dist/lilact.production.min.js +1 -1
  7. package/dist/lilact.production.min.js.map +1 -1
  8. package/docs/assets/hierarchy.js +1 -1
  9. package/docs/assets/navigation.js +1 -1
  10. package/docs/assets/search.js +1 -1
  11. package/docs/classes/accessories.ErrorBoundary.html +11 -11
  12. package/docs/classes/accessories.Suspense.html +10 -10
  13. package/docs/classes/components.Component.html +11 -11
  14. package/docs/classes/components.HTMLComponent.html +11 -11
  15. package/docs/classes/components.RootComponent.html +11 -11
  16. package/docs/functions/accessories.DragHandle.html +6 -0
  17. package/docs/functions/accessories.Spinner.html +1 -1
  18. package/docs/functions/components.createComponent.html +1 -1
  19. package/docs/functions/components.createRoot.html +1 -1
  20. package/docs/functions/components.render.html +1 -1
  21. package/docs/functions/hooks.useActionState.html +1 -1
  22. package/docs/functions/hooks.useDeferredValue.html +1 -1
  23. package/docs/functions/hooks.useImperativeHandle.html +1 -1
  24. package/docs/functions/hooks.useReducer.html +1 -1
  25. package/docs/hierarchy.html +1 -1
  26. package/docs/index.html +3 -2
  27. package/docs/modules/accessories.html +1 -1
  28. package/docs/modules/pane.html +1 -1
  29. package/docs/static/demos/pane.jsx +3 -3
  30. package/docs/static/index.html +1 -1
  31. package/docs/static/lilact.development.js +159 -27
  32. package/docs/static/lilact.development.min.js +1 -1
  33. package/docs/static/lilact.production.min.js +1 -1
  34. package/docs/variables/{pane.ResizablePane.html → pane.SplitPane.html} +2 -2
  35. package/package.json +1 -1
  36. package/root/demos/pane.jsx +3 -3
  37. package/root/index.html +1 -1
  38. package/root/lilact.development.js +159 -27
  39. package/root/lilact.development.min.js +1 -1
  40. package/root/lilact.production.min.js +1 -1
  41. package/src/accessories.jsx +118 -0
  42. package/src/components.jsx +24 -4
  43. package/src/hooks.jsx +9 -7
  44. package/src/lilact.jsx +5 -5
  45. package/src/misc.jsx +1 -1
  46. package/src/pane.jsx +4 -4
@@ -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
+
@@ -195,11 +195,22 @@ class ComponentCore
195
195
 
196
196
 
197
197
  if(next_props.ref) {
198
- if(this.element) {
199
- next_props.ref.current = this.element;
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
- next_props.ref.current = this.component;
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/hooks.jsx CHANGED
@@ -90,11 +90,10 @@ export function useCallback(callback, deps=undefined)
90
90
 
91
91
  const hk = Lilact.useHook();
92
92
 
93
- if( Lilact.isEmpty(hk) ) {
94
- hk.callback = callback;
95
- }
96
- else {
97
- if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return hk.callback;
93
+ if( !Lilact.isEmpty(hk) ) {
94
+ if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) {
95
+ return hk.callback;
96
+ }
98
97
  }
99
98
 
100
99
  if(hk?.cleanup) {
@@ -102,6 +101,7 @@ export function useCallback(callback, deps=undefined)
102
101
  }
103
102
 
104
103
  hk.deps = deps;
104
+ hk.callback = callback;
105
105
 
106
106
  return hk.callback;
107
107
  }
@@ -334,11 +334,13 @@ export function useMemo(factory,deps=undefined)
334
334
  const hk = Lilact.useHook();
335
335
 
336
336
  if( !Lilact.isEmpty(hk) ) {
337
- if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) return hk.value;
337
+ if(deps!==undefined && hk?.deps!==undefined && Lilact.shallowEqual(deps, hk.deps)) {
338
+ return hk.value;
339
+ }
338
340
  }
339
341
 
340
342
  hk.deps = deps;
341
- hk.value = factory(hk.value);
343
+ hk.value = factory();
342
344
 
343
345
  return hk.value;
344
346
  }
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 {ResizablePane} from './pane.jsx';
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 {ResizablePane} from './pane.jsx';
83
+ export {SplitPane} from './pane.jsx';
84
84
  export {transpileJSX, transpilerConfig} from "./jsx";
85
85
 
86
86
 
@@ -94,12 +94,12 @@ export {transpileJSX, transpilerConfig} from "./jsx";
94
94
  export const Lilact =
95
95
  {
96
96
 
97
- VERSION: "beta.11",
97
+ VERSION: "beta.13",
98
98
 
99
99
  // Configuration
100
100
 
101
101
  defaultTransitionTimeout: 300,
102
- defaultIsEqual: Object.is, // note: `Lilact.shallowEqual` and `Lilact.deepEqual` are also available,
102
+ defaultIsEqual: misc.shallowEqual,
103
103
  // user can set it in your initializer code, and can be changed later too.
104
104
 
105
105
  // Units
@@ -117,7 +117,7 @@ export const Lilact =
117
117
  ...router,
118
118
  ...accessories,
119
119
 
120
- ResizablePane,
120
+ SplitPane,
121
121
 
122
122
  transpileJSX,
123
123
  transpilerConfig,
package/src/misc.jsx CHANGED
@@ -361,7 +361,7 @@ export let layout_effects = new Set;
361
361
 
362
362
  /** @ignore */
363
363
  export const special_attributes = new Set([
364
- "classname", "classname", "ref", "action", "lilact_jsx_loc", "children", "key",
364
+ "classname", "ref", "action", "lilact_jsx_loc", "children", "key",
365
365
  "defaultvalue", "defaultchecked"
366
366
  ]);
367
367
 
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<ResizablePaneHandle>(null);
51
+ * const ref = useRef<SplitPaneHandle>(null);
52
52
  *
53
- * <ResizablePane
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
- * </ResizablePane>
62
+ * </SplitPane>
63
63
  * ```
64
64
  */
65
- export const ResizablePane = forwardRef(function ResizablePane(
65
+ export const SplitPane = forwardRef(function SplitPane(
66
66
  {
67
67
  mode = "horizontal",
68
68
  position, // controlled: number | undefined/null