@almadar/ui 2.42.0 → 2.43.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.
@@ -2460,6 +2460,98 @@ function usePinchZoom(options = {}) {
2460
2460
  resetZoom
2461
2461
  };
2462
2462
  }
2463
+ var ALMADAR_DND_MIME = "application/x-almadar-dnd";
2464
+ function useDraggable({ payload, disabled = false }) {
2465
+ const [isDragging, setIsDragging] = React2.useState(false);
2466
+ const eventBus = useEventBus();
2467
+ const handleDragStart = React2.useCallback(
2468
+ (e) => {
2469
+ if (disabled) {
2470
+ e.preventDefault();
2471
+ return;
2472
+ }
2473
+ e.dataTransfer.setData(ALMADAR_DND_MIME, JSON.stringify(payload));
2474
+ e.dataTransfer.effectAllowed = "copy";
2475
+ setIsDragging(true);
2476
+ eventBus.emit("UI:DRAG_START", { kind: payload.kind, data: payload.data });
2477
+ },
2478
+ [disabled, payload, eventBus]
2479
+ );
2480
+ const handleDragEnd = React2.useCallback(
2481
+ (e) => {
2482
+ setIsDragging(false);
2483
+ eventBus.emit("UI:DRAG_END", { kind: payload.kind, data: payload.data });
2484
+ },
2485
+ [payload, eventBus]
2486
+ );
2487
+ const dragProps = React2.useMemo(
2488
+ () => ({
2489
+ draggable: !disabled,
2490
+ onDragStart: handleDragStart,
2491
+ onDragEnd: handleDragEnd,
2492
+ "aria-grabbed": isDragging
2493
+ }),
2494
+ [disabled, handleDragStart, handleDragEnd, isDragging]
2495
+ );
2496
+ return { dragProps, isDragging };
2497
+ }
2498
+ function parsePayload(e) {
2499
+ try {
2500
+ const raw = e.dataTransfer.getData(ALMADAR_DND_MIME);
2501
+ if (!raw) return null;
2502
+ const parsed = JSON.parse(raw);
2503
+ if (typeof parsed.kind !== "string" || !parsed.data) return null;
2504
+ return parsed;
2505
+ } catch {
2506
+ return null;
2507
+ }
2508
+ }
2509
+ function hasAlmadarPayload(e) {
2510
+ return e.dataTransfer.types.includes(ALMADAR_DND_MIME);
2511
+ }
2512
+ function useDropZone({ accepts, onDrop, disabled = false }) {
2513
+ const [isOver, setIsOver] = React2.useState(false);
2514
+ const eventBus = useEventBus();
2515
+ const handleDragOver = React2.useCallback(
2516
+ (e) => {
2517
+ if (disabled) return;
2518
+ if (!hasAlmadarPayload(e)) return;
2519
+ e.preventDefault();
2520
+ e.dataTransfer.dropEffect = "copy";
2521
+ setIsOver(true);
2522
+ },
2523
+ [disabled]
2524
+ );
2525
+ const handleDragLeave = React2.useCallback(
2526
+ (e) => {
2527
+ setIsOver(false);
2528
+ },
2529
+ []
2530
+ );
2531
+ const handleDrop = React2.useCallback(
2532
+ (e) => {
2533
+ e.preventDefault();
2534
+ setIsOver(false);
2535
+ if (disabled) return;
2536
+ const payload = parsePayload(e);
2537
+ if (!payload) return;
2538
+ if (!accepts.includes(payload.kind)) return;
2539
+ const position = { x: e.clientX, y: e.clientY };
2540
+ onDrop(payload, position);
2541
+ eventBus.emit("UI:DROP", { kind: payload.kind, data: payload.data, ...position });
2542
+ },
2543
+ [disabled, accepts, onDrop, eventBus]
2544
+ );
2545
+ const dropProps = React2.useMemo(
2546
+ () => ({
2547
+ onDragOver: handleDragOver,
2548
+ onDragLeave: handleDragLeave,
2549
+ onDrop: handleDrop
2550
+ }),
2551
+ [handleDragOver, handleDragLeave, handleDrop]
2552
+ );
2553
+ return { dropProps, isOver };
2554
+ }
2463
2555
  var API_BASE = typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "http://localhost:3000";
2464
2556
  function getUserId() {
2465
2557
  return localStorage.getItem("userId") || "anonymous";
@@ -2536,6 +2628,7 @@ function useGitHubBranches(owner, repo, enabled = true) {
2536
2628
  });
2537
2629
  }
2538
2630
 
2631
+ exports.ALMADAR_DND_MIME = ALMADAR_DND_MIME;
2539
2632
  exports.DEFAULT_SLOTS = DEFAULT_SLOTS;
2540
2633
  exports.ENTITY_EVENTS = ENTITY_EVENTS;
2541
2634
  exports.EntityDataProvider = EntityDataProvider;
@@ -2561,6 +2654,8 @@ exports.useDeepAgentGeneration = useDeepAgentGeneration;
2561
2654
  exports.useDeleteEntity = useDeleteEntity;
2562
2655
  exports.useDisconnectGitHub = useDisconnectGitHub;
2563
2656
  exports.useDragReorder = useDragReorder;
2657
+ exports.useDraggable = useDraggable;
2658
+ exports.useDropZone = useDropZone;
2564
2659
  exports.useEmitEvent = useEmitEvent;
2565
2660
  exports.useEntities = useEntities;
2566
2661
  exports.useEntitiesByType = useEntitiesByType;
@@ -28,4 +28,6 @@ export { useDragReorder, type DragReorderResult, } from './useDragReorder';
28
28
  export { useInfiniteScroll, type InfiniteScrollOptions, type InfiniteScrollResult, } from './useInfiniteScroll';
29
29
  export { usePullToRefresh, type PullToRefreshOptions, type PullToRefreshResult, } from './usePullToRefresh';
30
30
  export { usePinchZoom, type PinchZoomOptions, type PinchZoomResult, } from './usePinchZoom';
31
+ export { useDraggable, ALMADAR_DND_MIME, type DraggablePayload, type UseDraggableOptions, type UseDraggableResult, } from './useDraggable';
32
+ export { useDropZone, type UseDropZoneOptions, type UseDropZoneResult, } from './useDropZone';
31
33
  export { useGitHubStatus, useConnectGitHub, useDisconnectGitHub, useGitHubRepos, useGitHubRepo, useGitHubBranches, type GitHubStatus, type GitHubRepo, } from './useGitHub';
@@ -2454,6 +2454,98 @@ function usePinchZoom(options = {}) {
2454
2454
  resetZoom
2455
2455
  };
2456
2456
  }
2457
+ var ALMADAR_DND_MIME = "application/x-almadar-dnd";
2458
+ function useDraggable({ payload, disabled = false }) {
2459
+ const [isDragging, setIsDragging] = useState(false);
2460
+ const eventBus = useEventBus();
2461
+ const handleDragStart = useCallback(
2462
+ (e) => {
2463
+ if (disabled) {
2464
+ e.preventDefault();
2465
+ return;
2466
+ }
2467
+ e.dataTransfer.setData(ALMADAR_DND_MIME, JSON.stringify(payload));
2468
+ e.dataTransfer.effectAllowed = "copy";
2469
+ setIsDragging(true);
2470
+ eventBus.emit("UI:DRAG_START", { kind: payload.kind, data: payload.data });
2471
+ },
2472
+ [disabled, payload, eventBus]
2473
+ );
2474
+ const handleDragEnd = useCallback(
2475
+ (e) => {
2476
+ setIsDragging(false);
2477
+ eventBus.emit("UI:DRAG_END", { kind: payload.kind, data: payload.data });
2478
+ },
2479
+ [payload, eventBus]
2480
+ );
2481
+ const dragProps = useMemo(
2482
+ () => ({
2483
+ draggable: !disabled,
2484
+ onDragStart: handleDragStart,
2485
+ onDragEnd: handleDragEnd,
2486
+ "aria-grabbed": isDragging
2487
+ }),
2488
+ [disabled, handleDragStart, handleDragEnd, isDragging]
2489
+ );
2490
+ return { dragProps, isDragging };
2491
+ }
2492
+ function parsePayload(e) {
2493
+ try {
2494
+ const raw = e.dataTransfer.getData(ALMADAR_DND_MIME);
2495
+ if (!raw) return null;
2496
+ const parsed = JSON.parse(raw);
2497
+ if (typeof parsed.kind !== "string" || !parsed.data) return null;
2498
+ return parsed;
2499
+ } catch {
2500
+ return null;
2501
+ }
2502
+ }
2503
+ function hasAlmadarPayload(e) {
2504
+ return e.dataTransfer.types.includes(ALMADAR_DND_MIME);
2505
+ }
2506
+ function useDropZone({ accepts, onDrop, disabled = false }) {
2507
+ const [isOver, setIsOver] = useState(false);
2508
+ const eventBus = useEventBus();
2509
+ const handleDragOver = useCallback(
2510
+ (e) => {
2511
+ if (disabled) return;
2512
+ if (!hasAlmadarPayload(e)) return;
2513
+ e.preventDefault();
2514
+ e.dataTransfer.dropEffect = "copy";
2515
+ setIsOver(true);
2516
+ },
2517
+ [disabled]
2518
+ );
2519
+ const handleDragLeave = useCallback(
2520
+ (e) => {
2521
+ setIsOver(false);
2522
+ },
2523
+ []
2524
+ );
2525
+ const handleDrop = useCallback(
2526
+ (e) => {
2527
+ e.preventDefault();
2528
+ setIsOver(false);
2529
+ if (disabled) return;
2530
+ const payload = parsePayload(e);
2531
+ if (!payload) return;
2532
+ if (!accepts.includes(payload.kind)) return;
2533
+ const position = { x: e.clientX, y: e.clientY };
2534
+ onDrop(payload, position);
2535
+ eventBus.emit("UI:DROP", { kind: payload.kind, data: payload.data, ...position });
2536
+ },
2537
+ [disabled, accepts, onDrop, eventBus]
2538
+ );
2539
+ const dropProps = useMemo(
2540
+ () => ({
2541
+ onDragOver: handleDragOver,
2542
+ onDragLeave: handleDragLeave,
2543
+ onDrop: handleDrop
2544
+ }),
2545
+ [handleDragOver, handleDragLeave, handleDrop]
2546
+ );
2547
+ return { dropProps, isOver };
2548
+ }
2457
2549
  var API_BASE = typeof process !== "undefined" && process.env?.VITE_API_URL ? process.env.VITE_API_URL : "http://localhost:3000";
2458
2550
  function getUserId() {
2459
2551
  return localStorage.getItem("userId") || "anonymous";
@@ -2530,4 +2622,4 @@ function useGitHubBranches(owner, repo, enabled = true) {
2530
2622
  });
2531
2623
  }
2532
2624
 
2533
- export { DEFAULT_SLOTS, ENTITY_EVENTS, EntityDataProvider, I18nProvider, clearEntities, createTranslate, entityDataKeys, getAllEntities, getByType, getEntity, getSingleton, parseQueryBinding, removeEntity, spawnEntity, updateEntity, updateSingleton, useAgentChat, useAuthContext, useCompile, useConnectGitHub, useCreateEntity, useDeepAgentGeneration, useDeleteEntity, useDisconnectGitHub, useDragReorder, useEmitEvent, useEntities, useEntitiesByType, useEntity, useEntity2 as useEntityById, useEntityDataAdapter, useEntityDetail, useEntityList, useEntityListSuspense, useEntityMutations, useEntitySuspense, useEventBus, useEventListener, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInfiniteScroll, useInput, useLongPress, useOrbitalHistory, useOrbitalMutations, usePhysics, usePinchZoom, usePlayer, usePreview, usePullToRefresh, useQuerySingleton, useResolvedEntity, useSelectedEntity, useSendOrbitalEvent, useSingletonEntity, useSwipeGesture, useTranslate, useUIEvents, useUISlotManager, useUpdateEntity, useValidation };
2625
+ export { ALMADAR_DND_MIME, DEFAULT_SLOTS, ENTITY_EVENTS, EntityDataProvider, I18nProvider, clearEntities, createTranslate, entityDataKeys, getAllEntities, getByType, getEntity, getSingleton, parseQueryBinding, removeEntity, spawnEntity, updateEntity, updateSingleton, useAgentChat, useAuthContext, useCompile, useConnectGitHub, useCreateEntity, useDeepAgentGeneration, useDeleteEntity, useDisconnectGitHub, useDragReorder, useDraggable, useDropZone, useEmitEvent, useEntities, useEntitiesByType, useEntity, useEntity2 as useEntityById, useEntityDataAdapter, useEntityDetail, useEntityList, useEntityListSuspense, useEntityMutations, useEntitySuspense, useEventBus, useEventListener, useExtensions, useFileEditor, useFileSystem, useGitHubBranches, useGitHubRepo, useGitHubRepos, useGitHubStatus, useInfiniteScroll, useInput, useLongPress, useOrbitalHistory, useOrbitalMutations, usePhysics, usePinchZoom, usePlayer, usePreview, usePullToRefresh, useQuerySingleton, useResolvedEntity, useSelectedEntity, useSendOrbitalEvent, useSingletonEntity, useSwipeGesture, useTranslate, useUIEvents, useUISlotManager, useUpdateEntity, useValidation };
@@ -0,0 +1,24 @@
1
+ /** Discriminated payload carried by every drag operation. */
2
+ export interface DraggablePayload {
3
+ kind: 'pattern' | 'behavior' | 'tree-node' | 'event-wire';
4
+ data: Record<string, unknown>;
5
+ }
6
+ export interface UseDraggableOptions {
7
+ /** The payload that will be serialised into dataTransfer. */
8
+ payload: DraggablePayload;
9
+ /** When true the element cannot be dragged. */
10
+ disabled?: boolean;
11
+ }
12
+ export interface UseDraggableResult {
13
+ /** Spread these onto the draggable element. */
14
+ dragProps: {
15
+ draggable: boolean;
16
+ onDragStart: (e: React.DragEvent) => void;
17
+ onDragEnd: (e: React.DragEvent) => void;
18
+ 'aria-grabbed': boolean;
19
+ };
20
+ /** True while the element is being dragged. */
21
+ isDragging: boolean;
22
+ }
23
+ export declare const ALMADAR_DND_MIME = "application/x-almadar-dnd";
24
+ export declare function useDraggable({ payload, disabled }: UseDraggableOptions): UseDraggableResult;
@@ -0,0 +1,23 @@
1
+ import { type DraggablePayload } from './useDraggable';
2
+ export interface UseDropZoneOptions {
3
+ /** Which payload kinds this zone accepts. */
4
+ accepts: DraggablePayload['kind'][];
5
+ /** Called when a valid payload is dropped. */
6
+ onDrop: (payload: DraggablePayload, position: {
7
+ x: number;
8
+ y: number;
9
+ }) => void;
10
+ /** When true the zone rejects all drops. */
11
+ disabled?: boolean;
12
+ }
13
+ export interface UseDropZoneResult {
14
+ /** Spread these onto the drop-target element. */
15
+ dropProps: {
16
+ onDragOver: (e: React.DragEvent) => void;
17
+ onDragLeave: (e: React.DragEvent) => void;
18
+ onDrop: (e: React.DragEvent) => void;
19
+ };
20
+ /** True while a valid drag payload is hovering over this zone. */
21
+ isOver: boolean;
22
+ }
23
+ export declare function useDropZone({ accepts, onDrop, disabled }: UseDropZoneOptions): UseDropZoneResult;
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * EntityStoreProvider
3
3
  *
4
- * Reactive entity store for Orbital applications. Holds per-entity-type snapshots.
5
- * When `advance()` is called (after a persist/set/swap!/atomic response from the server),
6
- * all `useEntityRef` subscribers for that entity type re-render with fresh data.
7
- * `useEntityWatch` callbacks fire for side effects (toasts, cross-orbital emits).
4
+ * Normalized reactive entity store for Orbital applications.
5
+ * Stores entities in ID-keyed Maps with ordered ID lists.
6
+ * Provides operation-specific methods (setAll, upsertOne, addOne,
7
+ * updateOne, removeOne) and selector hooks (useEntityRef for
8
+ * collections, useEntityById for single entities).
8
9
  *
9
- * This is the client-side half of the `ref` operator. The server-side half is the
10
- * initial DB query and auto-fetch-after-mutation in the generated handler / runtime.
10
+ * Every mutation creates new Map/array objects (immutable values).
11
+ * Identity (the store key) advances to a new value on each write.
12
+ * Follows the Clojure epochal time model from Almadar_Orb_IO.md.
11
13
  *
12
14
  * @packageDocumentation
13
15
  */
@@ -16,26 +18,38 @@ type StoreListener = () => void;
16
18
  type WatchCallback = (oldData: unknown[], newData: unknown[]) => void;
17
19
  export declare function subscribeToStore(listener: StoreListener): () => void;
18
20
  /**
19
- * Subscribe to an entity type's data reactively.
20
- * Re-renders only when the data for this specific entity type changes.
21
+ * Subscribe to an entity collection reactively.
22
+ * Returns the full ordered array. Re-renders when the collection changes.
21
23
  *
22
- * This is the client-side implementation of the `["ref", "EntityType"]` operator.
24
+ * Client-side implementation of `["ref", "EntityType"]`.
23
25
  */
24
26
  export declare function useEntityRef(entityType: string): unknown[];
25
27
  /**
26
- * Register a callback that fires when an entity type's data changes.
28
+ * Subscribe to a single entity by ID reactively.
29
+ * Returns the entity record or null. Re-renders when the entity changes.
27
30
  *
28
- * This is the client-side implementation of the `["watch", "EntityType", effects]` operator.
29
- * The callback receives (oldData, newData) and should execute side effects (notify, emit, log).
31
+ * Client-side implementation of `["fetch", "EntityType", { id: ... }]`.
32
+ */
33
+ export declare function useEntityById(entityType: string, id: string | undefined): Record<string, unknown> | null;
34
+ /**
35
+ * Register a callback that fires when an entity collection changes.
36
+ * Receives (oldData, newData) for side effects (notify, emit, log).
37
+ *
38
+ * Client-side implementation of `["watch", "EntityType", effects]`.
30
39
  */
31
40
  export declare function useEntityWatch(entityType: string, callback: WatchCallback): void;
32
41
  export interface EntityStoreContextValue {
33
- advance: (entityType: string, data: unknown[]) => void;
42
+ setAll: (entityType: string, records: unknown[]) => void;
43
+ upsertOne: (entityType: string, record: Record<string, unknown>) => void;
44
+ addOne: (entityType: string, record: Record<string, unknown>) => void;
45
+ updateOne: (entityType: string, id: string, changes: Partial<Record<string, unknown>>) => void;
46
+ removeOne: (entityType: string, id: string) => void;
34
47
  getSnapshot: (entityType: string) => unknown[];
48
+ getById: (entityType: string, id: string) => Record<string, unknown> | null;
35
49
  }
36
50
  export declare const EntityStoreContext: React.Context<EntityStoreContextValue>;
37
51
  /**
38
- * Access the entity store's advance function.
52
+ * Access the entity store operations.
39
53
  * Used by useOrbitalBridge and OrbPreview to push server response data into the store.
40
54
  */
41
55
  export declare function useEntityStore(): EntityStoreContextValue;