@dnd-block-tree/svelte 2.1.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 +62 -0
- package/dist/bridge.d.ts +13 -0
- package/dist/bridge.d.ts.map +1 -0
- package/dist/bridge.js +55 -0
- package/dist/components/BlockTree.svelte +368 -0
- package/dist/components/BlockTree.svelte.d.ts +32 -0
- package/dist/components/BlockTree.svelte.d.ts.map +1 -0
- package/dist/components/BlockTreeDevTools.svelte +54 -0
- package/dist/components/BlockTreeDevTools.svelte.d.ts +12 -0
- package/dist/components/BlockTreeDevTools.svelte.d.ts.map +1 -0
- package/dist/components/BlockTreeSSR.svelte +22 -0
- package/dist/components/BlockTreeSSR.svelte.d.ts +9 -0
- package/dist/components/BlockTreeSSR.svelte.d.ts.map +1 -0
- package/dist/components/DragOverlay.svelte +48 -0
- package/dist/components/DragOverlay.svelte.d.ts +11 -0
- package/dist/components/DragOverlay.svelte.d.ts.map +1 -0
- package/dist/components/DraggableBlock.svelte +43 -0
- package/dist/components/DraggableBlock.svelte.d.ts +17 -0
- package/dist/components/DraggableBlock.svelte.d.ts.map +1 -0
- package/dist/components/DropZone.svelte +50 -0
- package/dist/components/DropZone.svelte.d.ts +13 -0
- package/dist/components/DropZone.svelte.d.ts.map +1 -0
- package/dist/components/GhostPreview.svelte +13 -0
- package/dist/components/GhostPreview.svelte.d.ts +8 -0
- package/dist/components/GhostPreview.svelte.d.ts.map +1 -0
- package/dist/components/TreeRenderer.svelte +197 -0
- package/dist/components/TreeRenderer.svelte.d.ts +35 -0
- package/dist/components/TreeRenderer.svelte.d.ts.map +1 -0
- package/dist/index.d.ts +22 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/state/block-history.svelte.d.ts +18 -0
- package/dist/state/block-history.svelte.d.ts.map +1 -0
- package/dist/state/block-history.svelte.js +30 -0
- package/dist/state/block-state.svelte.d.ts +27 -0
- package/dist/state/block-state.svelte.d.ts.map +1 -0
- package/dist/state/block-state.svelte.js +91 -0
- package/dist/state/tree-state.svelte.d.ts +39 -0
- package/dist/state/tree-state.svelte.d.ts.map +1 -0
- package/dist/state/tree-state.svelte.js +118 -0
- package/dist/types.d.ts +46 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +1 -0
- package/dist/utils/haptic.d.ts +6 -0
- package/dist/utils/haptic.d.ts.map +1 -0
- package/dist/utils/haptic.js +9 -0
- package/dist/utils/sensors.d.ts +11 -0
- package/dist/utils/sensors.d.ts.map +1 -0
- package/dist/utils/sensors.js +10 -0
- package/package.json +56 -0
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { BaseBlock } from '@dnd-block-tree/core'
|
|
3
|
+
import type { Snippet } from 'svelte'
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
activeBlock: BaseBlock | null
|
|
7
|
+
selectedCount?: number
|
|
8
|
+
children?: Snippet<[BaseBlock]>
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let {
|
|
12
|
+
activeBlock,
|
|
13
|
+
selectedCount = 0,
|
|
14
|
+
children,
|
|
15
|
+
}: Props = $props()
|
|
16
|
+
|
|
17
|
+
const showBadge = $derived(selectedCount > 1)
|
|
18
|
+
</script>
|
|
19
|
+
|
|
20
|
+
<!-- DragOverlay renders outside the normal tree flow -->
|
|
21
|
+
{#if activeBlock}
|
|
22
|
+
<div style="position: relative;">
|
|
23
|
+
{#if showBadge}
|
|
24
|
+
<!-- Stacked card effect -->
|
|
25
|
+
<div
|
|
26
|
+
style="position: absolute; top: 4px; left: 4px; right: -4px; bottom: -4px; border-radius: 8px; border: 1px solid #d1d5db; background: #f3f4f6; opacity: 0.6; z-index: -1;"
|
|
27
|
+
></div>
|
|
28
|
+
<!-- Count badge -->
|
|
29
|
+
<div
|
|
30
|
+
style="position: absolute; top: -8px; right: -8px; background: #3b82f6; color: white; border-radius: 50%; width: 22px; height: 22px; display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; z-index: 10; box-shadow: 0 1px 3px rgba(0,0,0,0.2);"
|
|
31
|
+
>
|
|
32
|
+
{selectedCount}
|
|
33
|
+
</div>
|
|
34
|
+
{/if}
|
|
35
|
+
{#if children}
|
|
36
|
+
{@render children(activeBlock)}
|
|
37
|
+
{:else}
|
|
38
|
+
<div style="background: white; border: 1px solid #d1d5db; box-shadow: 0 4px 6px -1px rgba(0,0,0,0.1); border-radius: 6px; padding: 12px; font-size: 14px; width: 256px; pointer-events: none;">
|
|
39
|
+
<div style="color: #6b7280; text-transform: uppercase; font-size: 11px; letter-spacing: 0.05em; margin-bottom: 4px;">
|
|
40
|
+
{activeBlock.type}
|
|
41
|
+
</div>
|
|
42
|
+
<div style="font-weight: 600; color: #1f2937;">
|
|
43
|
+
Block {activeBlock.id.slice(0, 8)}
|
|
44
|
+
</div>
|
|
45
|
+
</div>
|
|
46
|
+
{/if}
|
|
47
|
+
</div>
|
|
48
|
+
{/if}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { BaseBlock } from '@dnd-block-tree/core';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
interface Props {
|
|
4
|
+
activeBlock: BaseBlock | null;
|
|
5
|
+
selectedCount?: number;
|
|
6
|
+
children?: Snippet<[BaseBlock]>;
|
|
7
|
+
}
|
|
8
|
+
declare const DragOverlay: import("svelte").Component<Props, {}, "">;
|
|
9
|
+
type DragOverlay = ReturnType<typeof DragOverlay>;
|
|
10
|
+
export default DragOverlay;
|
|
11
|
+
//# sourceMappingURL=DragOverlay.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DragOverlay.svelte.d.ts","sourceRoot":"","sources":["../../src/components/DragOverlay.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGpC,UAAU,KAAK;IACb,WAAW,EAAE,SAAS,GAAG,IAAI,CAAA;IAC7B,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,CAAA;CAChC;AA2CH,QAAA,MAAM,WAAW,2CAAwC,CAAC;AAC1D,KAAK,WAAW,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAC;AAClD,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createDraggable } from '@dnd-kit/svelte'
|
|
3
|
+
import type { BaseBlock } from '@dnd-block-tree/core'
|
|
4
|
+
import type { Snippet } from 'svelte'
|
|
5
|
+
|
|
6
|
+
interface Props {
|
|
7
|
+
block: BaseBlock
|
|
8
|
+
disabled?: boolean
|
|
9
|
+
isContainer?: boolean
|
|
10
|
+
isExpanded?: boolean
|
|
11
|
+
isSelected?: boolean
|
|
12
|
+
depth?: number
|
|
13
|
+
children: Snippet<[{ isDragging: boolean }]>
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let {
|
|
17
|
+
block,
|
|
18
|
+
disabled = false,
|
|
19
|
+
isContainer = false,
|
|
20
|
+
isExpanded = false,
|
|
21
|
+
isSelected = false,
|
|
22
|
+
depth = 0,
|
|
23
|
+
children,
|
|
24
|
+
}: Props = $props()
|
|
25
|
+
|
|
26
|
+
const draggable = createDraggable({ get id() { return block.id }, get disabled() { return disabled } })
|
|
27
|
+
</script>
|
|
28
|
+
|
|
29
|
+
<div
|
|
30
|
+
{@attach draggable.attach}
|
|
31
|
+
data-block-id={block.id}
|
|
32
|
+
style:touch-action="none"
|
|
33
|
+
style:min-width="0"
|
|
34
|
+
style:outline="none"
|
|
35
|
+
role="treeitem"
|
|
36
|
+
aria-level={depth + 1}
|
|
37
|
+
aria-expanded={isContainer ? isExpanded : undefined}
|
|
38
|
+
aria-selected={isSelected || undefined}
|
|
39
|
+
data-selected={isSelected || undefined}
|
|
40
|
+
tabindex="-1"
|
|
41
|
+
>
|
|
42
|
+
{@render children({ isDragging: draggable.isDragging })}
|
|
43
|
+
</div>
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { BaseBlock } from '@dnd-block-tree/core';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
interface Props {
|
|
4
|
+
block: BaseBlock;
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
isContainer?: boolean;
|
|
7
|
+
isExpanded?: boolean;
|
|
8
|
+
isSelected?: boolean;
|
|
9
|
+
depth?: number;
|
|
10
|
+
children: Snippet<[{
|
|
11
|
+
isDragging: boolean;
|
|
12
|
+
}]>;
|
|
13
|
+
}
|
|
14
|
+
declare const DraggableBlock: import("svelte").Component<Props, {}, "">;
|
|
15
|
+
type DraggableBlock = ReturnType<typeof DraggableBlock>;
|
|
16
|
+
export default DraggableBlock;
|
|
17
|
+
//# sourceMappingURL=DraggableBlock.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DraggableBlock.svelte.d.ts","sourceRoot":"","sources":["../../src/components/DraggableBlock.svelte.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGpC,UAAU,KAAK;IACb,KAAK,EAAE,SAAS,CAAA;IAChB,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;IACrB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,OAAO,CAAC,CAAC;QAAE,UAAU,EAAE,OAAO,CAAA;KAAE,CAAC,CAAC,CAAA;CAC7C;AA0BH,QAAA,MAAM,cAAc,2CAAwC,CAAC;AAC7D,KAAK,cAAc,GAAG,UAAU,CAAC,OAAO,cAAc,CAAC,CAAC;AACxD,eAAe,cAAc,CAAC"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { createDroppable } from '@dnd-kit/svelte'
|
|
3
|
+
import { extractUUID } from '@dnd-block-tree/core'
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
id: string
|
|
7
|
+
parentId: string | null
|
|
8
|
+
onHover: (zoneId: string, parentId: string | null) => void
|
|
9
|
+
activeId: string | null
|
|
10
|
+
height?: number
|
|
11
|
+
class?: string
|
|
12
|
+
activeClass?: string
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
let {
|
|
16
|
+
id,
|
|
17
|
+
parentId,
|
|
18
|
+
onHover,
|
|
19
|
+
activeId,
|
|
20
|
+
height = 4,
|
|
21
|
+
class: className = '',
|
|
22
|
+
activeClass = '',
|
|
23
|
+
}: Props = $props()
|
|
24
|
+
|
|
25
|
+
const droppable = createDroppable({ get id() { return id } })
|
|
26
|
+
|
|
27
|
+
// Hide "into-" zones for the active block (can't drop a container into itself)
|
|
28
|
+
const zoneBlockId = $derived(extractUUID(id))
|
|
29
|
+
const isIntoZone = $derived(id.startsWith('into-'))
|
|
30
|
+
const shouldHide = $derived(isIntoZone && activeId != null && zoneBlockId === activeId)
|
|
31
|
+
|
|
32
|
+
// Fire hover callback when drop target is active
|
|
33
|
+
$effect(() => {
|
|
34
|
+
if (droppable.isDropTarget) {
|
|
35
|
+
onHover(id, parentId)
|
|
36
|
+
}
|
|
37
|
+
})
|
|
38
|
+
</script>
|
|
39
|
+
|
|
40
|
+
{#if !shouldHide}
|
|
41
|
+
<div
|
|
42
|
+
{@attach droppable.attach}
|
|
43
|
+
data-zone-id={id}
|
|
44
|
+
data-parent-id={parentId ?? ''}
|
|
45
|
+
style:height="{droppable.isDropTarget ? height * 2 : height}px"
|
|
46
|
+
style:transition="height 150ms ease, background-color 150ms ease"
|
|
47
|
+
class={droppable.isDropTarget ? `${className} ${activeClass}` : className}
|
|
48
|
+
data-zone-active={droppable.isDropTarget || undefined}
|
|
49
|
+
></div>
|
|
50
|
+
{/if}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
interface Props {
|
|
2
|
+
id: string;
|
|
3
|
+
parentId: string | null;
|
|
4
|
+
onHover: (zoneId: string, parentId: string | null) => void;
|
|
5
|
+
activeId: string | null;
|
|
6
|
+
height?: number;
|
|
7
|
+
class?: string;
|
|
8
|
+
activeClass?: string;
|
|
9
|
+
}
|
|
10
|
+
declare const DropZone: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type DropZone = ReturnType<typeof DropZone>;
|
|
12
|
+
export default DropZone;
|
|
13
|
+
//# sourceMappingURL=DropZone.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"DropZone.svelte.d.ts","sourceRoot":"","sources":["../../src/components/DropZone.svelte.ts"],"names":[],"mappings":"AAOE,UAAU,KAAK;IACb,EAAE,EAAE,MAAM,CAAA;IACV,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IAC1D,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,MAAM,CAAC,EAAE,MAAM,CAAA;IACf,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAqCH,QAAA,MAAM,QAAQ,2CAAwC,CAAC;AACvD,KAAK,QAAQ,GAAG,UAAU,CAAC,OAAO,QAAQ,CAAC,CAAC;AAC5C,eAAe,QAAQ,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte'
|
|
3
|
+
|
|
4
|
+
interface Props {
|
|
5
|
+
children: Snippet
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
let { children }: Props = $props()
|
|
9
|
+
</script>
|
|
10
|
+
|
|
11
|
+
<div data-dnd-ghost style="opacity: 0.5; pointer-events: none;">
|
|
12
|
+
{@render children()}
|
|
13
|
+
</div>
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Snippet } from 'svelte';
|
|
2
|
+
interface Props {
|
|
3
|
+
children: Snippet;
|
|
4
|
+
}
|
|
5
|
+
declare const GhostPreview: import("svelte").Component<Props, {}, "">;
|
|
6
|
+
type GhostPreview = ReturnType<typeof GhostPreview>;
|
|
7
|
+
export default GhostPreview;
|
|
8
|
+
//# sourceMappingURL=GhostPreview.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GhostPreview.svelte.d.ts","sourceRoot":"","sources":["../../src/components/GhostPreview.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAC;AAGpC,UAAU,KAAK;IACb,QAAQ,EAAE,OAAO,CAAA;CAClB;AAcH,QAAA,MAAM,YAAY,2CAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
|
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { BaseBlock, CanDragFn, AnimationConfig } from '@dnd-block-tree/core'
|
|
3
|
+
import type { Snippet } from 'svelte'
|
|
4
|
+
import DropZone from './DropZone.svelte'
|
|
5
|
+
import DraggableBlock from './DraggableBlock.svelte'
|
|
6
|
+
import GhostPreview from './GhostPreview.svelte'
|
|
7
|
+
import Self from './TreeRenderer.svelte'
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
blocks: BaseBlock[]
|
|
11
|
+
blocksByParent: Map<string | null, BaseBlock[]>
|
|
12
|
+
parentId: string | null
|
|
13
|
+
activeId: string | null
|
|
14
|
+
expandedMap: Record<string, boolean>
|
|
15
|
+
containerTypes: readonly string[]
|
|
16
|
+
onHover: (zoneId: string, parentId: string | null) => void
|
|
17
|
+
onToggleExpand: (id: string) => void
|
|
18
|
+
renderBlock: Snippet<[{ block: BaseBlock; isDragging: boolean; depth: number; isExpanded: boolean; onToggleExpand: (() => void) | null; children: Snippet | null }]>
|
|
19
|
+
depth?: number
|
|
20
|
+
dropZoneClass?: string
|
|
21
|
+
dropZoneActiveClass?: string
|
|
22
|
+
canDrag?: CanDragFn<BaseBlock>
|
|
23
|
+
previewPosition?: { parentId: string | null; index: number } | null
|
|
24
|
+
draggedBlock?: BaseBlock | null
|
|
25
|
+
selectedIds?: Set<string>
|
|
26
|
+
animation?: AnimationConfig
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
let {
|
|
30
|
+
blocks,
|
|
31
|
+
blocksByParent,
|
|
32
|
+
parentId,
|
|
33
|
+
activeId,
|
|
34
|
+
expandedMap,
|
|
35
|
+
containerTypes,
|
|
36
|
+
onHover,
|
|
37
|
+
onToggleExpand,
|
|
38
|
+
renderBlock,
|
|
39
|
+
depth = 0,
|
|
40
|
+
dropZoneClass = '',
|
|
41
|
+
dropZoneActiveClass = '',
|
|
42
|
+
canDrag,
|
|
43
|
+
previewPosition = null,
|
|
44
|
+
draggedBlock = null,
|
|
45
|
+
selectedIds,
|
|
46
|
+
animation,
|
|
47
|
+
}: Props = $props()
|
|
48
|
+
|
|
49
|
+
const items = $derived(blocksByParent.get(parentId) ?? [])
|
|
50
|
+
const filteredBlocks = $derived(items.filter(block => block.id !== activeId))
|
|
51
|
+
const showGhostHere = $derived(previewPosition?.parentId === parentId && draggedBlock != null)
|
|
52
|
+
</script>
|
|
53
|
+
|
|
54
|
+
<div style:min-width="0" role={depth === 0 ? 'tree' : 'group'}>
|
|
55
|
+
<!-- Start zone -->
|
|
56
|
+
<DropZone
|
|
57
|
+
id={parentId ? `into-${parentId}` : 'root-start'}
|
|
58
|
+
{parentId}
|
|
59
|
+
{onHover}
|
|
60
|
+
{activeId}
|
|
61
|
+
class={dropZoneClass}
|
|
62
|
+
activeClass={dropZoneActiveClass}
|
|
63
|
+
/>
|
|
64
|
+
|
|
65
|
+
{#each filteredBlocks as block, index (block.id)}
|
|
66
|
+
{@const isContainer = containerTypes.includes(block.type)}
|
|
67
|
+
{@const isExpanded = expandedMap[block.id] !== false}
|
|
68
|
+
{@const isDragDisabled = canDrag ? !canDrag(block) : false}
|
|
69
|
+
{@const ghostBeforeThis = showGhostHere && previewPosition!.index === index}
|
|
70
|
+
{@const originalIndex = items.findIndex(b => b.id === block.id)}
|
|
71
|
+
{@const isLastInOriginal = originalIndex === items.length - 1}
|
|
72
|
+
{@const isSelected = selectedIds?.has(block.id) ?? false}
|
|
73
|
+
|
|
74
|
+
<!-- Ghost preview before this block -->
|
|
75
|
+
{#if ghostBeforeThis && draggedBlock}
|
|
76
|
+
<GhostPreview>
|
|
77
|
+
{#snippet children()}
|
|
78
|
+
{@render renderBlock({
|
|
79
|
+
block: draggedBlock,
|
|
80
|
+
isDragging: true,
|
|
81
|
+
depth,
|
|
82
|
+
isExpanded: false,
|
|
83
|
+
onToggleExpand: null,
|
|
84
|
+
children: null,
|
|
85
|
+
})}
|
|
86
|
+
{/snippet}
|
|
87
|
+
</GhostPreview>
|
|
88
|
+
{/if}
|
|
89
|
+
|
|
90
|
+
<!-- The block itself -->
|
|
91
|
+
<DraggableBlock
|
|
92
|
+
{block}
|
|
93
|
+
disabled={isDragDisabled}
|
|
94
|
+
{isContainer}
|
|
95
|
+
{isExpanded}
|
|
96
|
+
{isSelected}
|
|
97
|
+
{depth}
|
|
98
|
+
>
|
|
99
|
+
{#snippet children({ isDragging })}
|
|
100
|
+
{#if isContainer}
|
|
101
|
+
{@const animated = animation?.expandDuration && animation.expandDuration > 0}
|
|
102
|
+
{@const easing = animation?.easing ?? 'ease'}
|
|
103
|
+
{@const duration = animation?.expandDuration ?? 0}
|
|
104
|
+
|
|
105
|
+
{#snippet childContent()}
|
|
106
|
+
<Self
|
|
107
|
+
{blocks}
|
|
108
|
+
{blocksByParent}
|
|
109
|
+
parentId={block.id}
|
|
110
|
+
{activeId}
|
|
111
|
+
{expandedMap}
|
|
112
|
+
{containerTypes}
|
|
113
|
+
{onHover}
|
|
114
|
+
{onToggleExpand}
|
|
115
|
+
{renderBlock}
|
|
116
|
+
depth={depth + 1}
|
|
117
|
+
{dropZoneClass}
|
|
118
|
+
{dropZoneActiveClass}
|
|
119
|
+
{canDrag}
|
|
120
|
+
{previewPosition}
|
|
121
|
+
{draggedBlock}
|
|
122
|
+
{selectedIds}
|
|
123
|
+
{animation}
|
|
124
|
+
/>
|
|
125
|
+
{/snippet}
|
|
126
|
+
|
|
127
|
+
{#if animated}
|
|
128
|
+
{@render renderBlock({
|
|
129
|
+
block,
|
|
130
|
+
isDragging,
|
|
131
|
+
depth,
|
|
132
|
+
isExpanded,
|
|
133
|
+
onToggleExpand: () => onToggleExpand(block.id),
|
|
134
|
+
children: childContent,
|
|
135
|
+
})}
|
|
136
|
+
{:else}
|
|
137
|
+
{@render renderBlock({
|
|
138
|
+
block,
|
|
139
|
+
isDragging,
|
|
140
|
+
depth,
|
|
141
|
+
isExpanded,
|
|
142
|
+
onToggleExpand: () => onToggleExpand(block.id),
|
|
143
|
+
children: isExpanded ? childContent : null,
|
|
144
|
+
})}
|
|
145
|
+
{/if}
|
|
146
|
+
{:else}
|
|
147
|
+
{@render renderBlock({
|
|
148
|
+
block,
|
|
149
|
+
isDragging,
|
|
150
|
+
depth,
|
|
151
|
+
isExpanded: false,
|
|
152
|
+
onToggleExpand: null,
|
|
153
|
+
children: null,
|
|
154
|
+
})}
|
|
155
|
+
{/if}
|
|
156
|
+
{/snippet}
|
|
157
|
+
</DraggableBlock>
|
|
158
|
+
|
|
159
|
+
<!-- After-zone for non-last blocks -->
|
|
160
|
+
{#if !isLastInOriginal}
|
|
161
|
+
<DropZone
|
|
162
|
+
id={`after-${block.id}`}
|
|
163
|
+
parentId={block.parentId}
|
|
164
|
+
{onHover}
|
|
165
|
+
{activeId}
|
|
166
|
+
class={dropZoneClass}
|
|
167
|
+
activeClass={dropZoneActiveClass}
|
|
168
|
+
/>
|
|
169
|
+
{/if}
|
|
170
|
+
{/each}
|
|
171
|
+
|
|
172
|
+
<!-- Ghost at end of container -->
|
|
173
|
+
{#if showGhostHere && previewPosition!.index >= filteredBlocks.length && draggedBlock}
|
|
174
|
+
<GhostPreview>
|
|
175
|
+
{#snippet children()}
|
|
176
|
+
{@render renderBlock({
|
|
177
|
+
block: draggedBlock,
|
|
178
|
+
isDragging: true,
|
|
179
|
+
depth,
|
|
180
|
+
isExpanded: false,
|
|
181
|
+
onToggleExpand: null,
|
|
182
|
+
children: null,
|
|
183
|
+
})}
|
|
184
|
+
{/snippet}
|
|
185
|
+
</GhostPreview>
|
|
186
|
+
{/if}
|
|
187
|
+
|
|
188
|
+
<!-- End zone -->
|
|
189
|
+
<DropZone
|
|
190
|
+
id={parentId ? `end-${parentId}` : 'root-end'}
|
|
191
|
+
{parentId}
|
|
192
|
+
{onHover}
|
|
193
|
+
{activeId}
|
|
194
|
+
class={dropZoneClass}
|
|
195
|
+
activeClass={dropZoneActiveClass}
|
|
196
|
+
/>
|
|
197
|
+
</div>
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type { BaseBlock, CanDragFn, AnimationConfig } from '@dnd-block-tree/core';
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
interface Props {
|
|
4
|
+
blocks: BaseBlock[];
|
|
5
|
+
blocksByParent: Map<string | null, BaseBlock[]>;
|
|
6
|
+
parentId: string | null;
|
|
7
|
+
activeId: string | null;
|
|
8
|
+
expandedMap: Record<string, boolean>;
|
|
9
|
+
containerTypes: readonly string[];
|
|
10
|
+
onHover: (zoneId: string, parentId: string | null) => void;
|
|
11
|
+
onToggleExpand: (id: string) => void;
|
|
12
|
+
renderBlock: Snippet<[{
|
|
13
|
+
block: BaseBlock;
|
|
14
|
+
isDragging: boolean;
|
|
15
|
+
depth: number;
|
|
16
|
+
isExpanded: boolean;
|
|
17
|
+
onToggleExpand: (() => void) | null;
|
|
18
|
+
children: Snippet | null;
|
|
19
|
+
}]>;
|
|
20
|
+
depth?: number;
|
|
21
|
+
dropZoneClass?: string;
|
|
22
|
+
dropZoneActiveClass?: string;
|
|
23
|
+
canDrag?: CanDragFn<BaseBlock>;
|
|
24
|
+
previewPosition?: {
|
|
25
|
+
parentId: string | null;
|
|
26
|
+
index: number;
|
|
27
|
+
} | null;
|
|
28
|
+
draggedBlock?: BaseBlock | null;
|
|
29
|
+
selectedIds?: Set<string>;
|
|
30
|
+
animation?: AnimationConfig;
|
|
31
|
+
}
|
|
32
|
+
declare const TreeRenderer: import("svelte").Component<Props, {}, "">;
|
|
33
|
+
type TreeRenderer = ReturnType<typeof TreeRenderer>;
|
|
34
|
+
export default TreeRenderer;
|
|
35
|
+
//# sourceMappingURL=TreeRenderer.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TreeRenderer.svelte.d.ts","sourceRoot":"","sources":["../../src/components/TreeRenderer.svelte.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAA;AACjF,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,QAAQ,CAAA;AAOnC,UAAU,KAAK;IACb,MAAM,EAAE,SAAS,EAAE,CAAA;IACnB,cAAc,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,SAAS,EAAE,CAAC,CAAA;IAC/C,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAA;IACvB,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAA;IACpC,cAAc,EAAE,SAAS,MAAM,EAAE,CAAA;IACjC,OAAO,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,KAAK,IAAI,CAAA;IAC1D,cAAc,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAA;IACpC,WAAW,EAAE,OAAO,CAAC,CAAC;QAAE,KAAK,EAAE,SAAS,CAAC;QAAC,UAAU,EAAE,OAAO,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,OAAO,CAAC;QAAC,cAAc,EAAE,CAAC,MAAM,IAAI,CAAC,GAAG,IAAI,CAAC;QAAC,QAAQ,EAAE,OAAO,GAAG,IAAI,CAAA;KAAE,CAAC,CAAC,CAAA;IACpK,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,mBAAmB,CAAC,EAAE,MAAM,CAAA;IAC5B,OAAO,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAA;IAC9B,eAAe,CAAC,EAAE;QAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,GAAG,IAAI,CAAA;IACnE,YAAY,CAAC,EAAE,SAAS,GAAG,IAAI,CAAA;IAC/B,WAAW,CAAC,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACzB,SAAS,CAAC,EAAE,eAAe,CAAA;CAC5B;AAwIH,QAAA,MAAM,YAAY,2CAAwC,CAAC;AAC3D,KAAK,YAAY,GAAG,UAAU,CAAC,OAAO,YAAY,CAAC,CAAC;AACpD,eAAe,YAAY,CAAC"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
export type { BaseBlock, BlockIndex, BlockAction, BlockTreeConfig, BlockStateContextValue, DropZoneType, BlockPosition, DragStartEvent, DragMoveEvent, DragEndEvent, BlockMoveEvent, BlockAddEvent, BlockDeleteEvent, MoveOperation, ExpandChangeEvent, HoverChangeEvent, BlockTreeCallbacks, CanDragFn, CanDropFn, IdGeneratorFn, SensorConfig, DropZoneConfig, AnimationConfig, AutoExpandConfig, BlockTreeCustomization as CoreBlockTreeCustomization, OrderingStrategy, Rect, CollisionCandidate, CollisionResult, CoreCollisionDetection, SnapshotRectsRef, ExpandAction, HistoryState, HistoryAction, BlockTreeOptions, BlockTreeEvents, BlockTreeInstance, TreeValidationResult, NestedBlock, } from '@dnd-block-tree/core';
|
|
2
|
+
export { getDropZoneType, extractBlockId, weightedVerticalCollision, closestCenterCollision, createStickyCollision, EventEmitter, blockReducer, expandReducer, historyReducer, createBlockTree, cloneMap, cloneParentMap, computeNormalizedIndex, buildOrderedBlocks, reparentBlockIndex, getDescendantIds, deleteBlockAndDescendants, getBlockDepth, getSubtreeDepth, reparentMultipleBlocks, validateBlockTree, extractUUID, debounce, generateId, flatToNested, nestedToFlat, generateKeyBetween, generateNKeysBetween, generateInitialKeys, initFractionalOrder, compareFractionalKeys, } from '@dnd-block-tree/core';
|
|
3
|
+
export type { BlockRendererProps, ContainerRendererProps, RendererPropsFor, BlockRenderers, InternalRenderers, BlockStateOptions, TreeStateContextValue, BlockTreeCustomization, } from './types';
|
|
4
|
+
export { adaptCollisionDetection } from './bridge';
|
|
5
|
+
export { triggerHaptic } from './utils/haptic';
|
|
6
|
+
export { getSensorConfig } from './utils/sensors';
|
|
7
|
+
export type { SensorConfigResult } from './utils/sensors';
|
|
8
|
+
export { createBlockState, setBlockStateContext, getBlockStateContext, } from './state/block-state.svelte';
|
|
9
|
+
export type { BlockState } from './state/block-state.svelte';
|
|
10
|
+
export { createTreeState, setTreeStateContext, getTreeStateContext, } from './state/tree-state.svelte';
|
|
11
|
+
export type { TreeState, TreeStateOptions } from './state/tree-state.svelte';
|
|
12
|
+
export { createBlockHistory } from './state/block-history.svelte';
|
|
13
|
+
export type { BlockHistoryOptions, BlockHistoryState } from './state/block-history.svelte';
|
|
14
|
+
export { default as BlockTree } from './components/BlockTree.svelte';
|
|
15
|
+
export { default as TreeRenderer } from './components/TreeRenderer.svelte';
|
|
16
|
+
export { default as DropZone } from './components/DropZone.svelte';
|
|
17
|
+
export { default as DraggableBlock } from './components/DraggableBlock.svelte';
|
|
18
|
+
export { default as DragOverlay } from './components/DragOverlay.svelte';
|
|
19
|
+
export { default as GhostPreview } from './components/GhostPreview.svelte';
|
|
20
|
+
export { default as BlockTreeSSR } from './components/BlockTreeSSR.svelte';
|
|
21
|
+
export { default as BlockTreeDevTools } from './components/BlockTreeDevTools.svelte';
|
|
22
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EACV,SAAS,EACT,UAAU,EACV,WAAW,EACX,eAAe,EACf,sBAAsB,EACtB,YAAY,EACZ,aAAa,EACb,cAAc,EACd,aAAa,EACb,YAAY,EACZ,cAAc,EACd,aAAa,EACb,gBAAgB,EAChB,aAAa,EACb,iBAAiB,EACjB,gBAAgB,EAChB,kBAAkB,EAClB,SAAS,EACT,SAAS,EACT,aAAa,EACb,YAAY,EACZ,cAAc,EACd,eAAe,EACf,gBAAgB,EAChB,sBAAsB,IAAI,0BAA0B,EACpD,gBAAgB,EAChB,IAAI,EACJ,kBAAkB,EAClB,eAAe,EACf,sBAAsB,EACtB,gBAAgB,EAChB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,gBAAgB,EAChB,eAAe,EACf,iBAAiB,EACjB,oBAAoB,EACpB,WAAW,GACZ,MAAM,sBAAsB,CAAA;AAG7B,OAAO,EACL,eAAe,EACf,cAAc,EACd,yBAAyB,EACzB,sBAAsB,EACtB,qBAAqB,EACrB,YAAY,EACZ,YAAY,EACZ,aAAa,EACb,cAAc,EACd,eAAe,EACf,QAAQ,EACR,cAAc,EACd,sBAAsB,EACtB,kBAAkB,EAClB,kBAAkB,EAClB,gBAAgB,EAChB,yBAAyB,EACzB,aAAa,EACb,eAAe,EACf,sBAAsB,EACtB,iBAAiB,EACjB,WAAW,EACX,QAAQ,EACR,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,oBAAoB,EACpB,mBAAmB,EACnB,mBAAmB,EACnB,qBAAqB,GACtB,MAAM,sBAAsB,CAAA;AAG7B,YAAY,EACV,kBAAkB,EAClB,sBAAsB,EACtB,gBAAgB,EAChB,cAAc,EACd,iBAAiB,EACjB,iBAAiB,EACjB,qBAAqB,EACrB,sBAAsB,GACvB,MAAM,SAAS,CAAA;AAGhB,OAAO,EAAE,uBAAuB,EAAE,MAAM,UAAU,CAAA;AAGlD,OAAO,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAA;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAA;AACjD,YAAY,EAAE,kBAAkB,EAAE,MAAM,iBAAiB,CAAA;AAGzD,OAAO,EACL,gBAAgB,EAChB,oBAAoB,EACpB,oBAAoB,GACrB,MAAM,4BAA4B,CAAA;AACnC,YAAY,EAAE,UAAU,EAAE,MAAM,4BAA4B,CAAA;AAE5D,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,mBAAmB,GACpB,MAAM,2BAA2B,CAAA;AAClC,YAAY,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAA;AAE5E,OAAO,EAAE,kBAAkB,EAAE,MAAM,8BAA8B,CAAA;AACjE,YAAY,EAAE,mBAAmB,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAA;AAG1F,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,+BAA+B,CAAA;AACpE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,8BAA8B,CAAA;AAClE,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,oCAAoC,CAAA;AAC9E,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,iCAAiC,CAAA;AACxE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,kCAAkC,CAAA;AAC1E,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,uCAAuC,CAAA"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// Re-export core functions
|
|
2
|
+
export { getDropZoneType, extractBlockId, weightedVerticalCollision, closestCenterCollision, createStickyCollision, EventEmitter, blockReducer, expandReducer, historyReducer, createBlockTree, cloneMap, cloneParentMap, computeNormalizedIndex, buildOrderedBlocks, reparentBlockIndex, getDescendantIds, deleteBlockAndDescendants, getBlockDepth, getSubtreeDepth, reparentMultipleBlocks, validateBlockTree, extractUUID, debounce, generateId, flatToNested, nestedToFlat, generateKeyBetween, generateNKeysBetween, generateInitialKeys, initFractionalOrder, compareFractionalKeys, } from '@dnd-block-tree/core';
|
|
3
|
+
// Bridge
|
|
4
|
+
export { adaptCollisionDetection } from './bridge';
|
|
5
|
+
// Utils
|
|
6
|
+
export { triggerHaptic } from './utils/haptic';
|
|
7
|
+
export { getSensorConfig } from './utils/sensors';
|
|
8
|
+
// State (rune-based .svelte.ts modules)
|
|
9
|
+
export { createBlockState, setBlockStateContext, getBlockStateContext, } from './state/block-state.svelte';
|
|
10
|
+
export { createTreeState, setTreeStateContext, getTreeStateContext, } from './state/tree-state.svelte';
|
|
11
|
+
export { createBlockHistory } from './state/block-history.svelte';
|
|
12
|
+
// Components
|
|
13
|
+
export { default as BlockTree } from './components/BlockTree.svelte';
|
|
14
|
+
export { default as TreeRenderer } from './components/TreeRenderer.svelte';
|
|
15
|
+
export { default as DropZone } from './components/DropZone.svelte';
|
|
16
|
+
export { default as DraggableBlock } from './components/DraggableBlock.svelte';
|
|
17
|
+
export { default as DragOverlay } from './components/DragOverlay.svelte';
|
|
18
|
+
export { default as GhostPreview } from './components/GhostPreview.svelte';
|
|
19
|
+
export { default as BlockTreeSSR } from './components/BlockTreeSSR.svelte';
|
|
20
|
+
export { default as BlockTreeDevTools } from './components/BlockTreeDevTools.svelte';
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { BaseBlock } from '@dnd-block-tree/core';
|
|
2
|
+
export interface BlockHistoryOptions {
|
|
3
|
+
maxSteps?: number;
|
|
4
|
+
}
|
|
5
|
+
export interface BlockHistoryState<T extends BaseBlock> {
|
|
6
|
+
readonly blocks: T[];
|
|
7
|
+
readonly canUndo: boolean;
|
|
8
|
+
readonly canRedo: boolean;
|
|
9
|
+
set(blocks: T[]): void;
|
|
10
|
+
undo(): void;
|
|
11
|
+
redo(): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Reactive undo/redo history using $state runes.
|
|
15
|
+
* Wraps core's historyReducer.
|
|
16
|
+
*/
|
|
17
|
+
export declare function createBlockHistory<T extends BaseBlock>(initialBlocks: T[], options?: BlockHistoryOptions): BlockHistoryState<T>;
|
|
18
|
+
//# sourceMappingURL=block-history.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-history.svelte.d.ts","sourceRoot":"","sources":["../../src/state/block-history.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAgB,MAAM,sBAAsB,CAAA;AAGnE,MAAM,WAAW,mBAAmB;IAClC,QAAQ,CAAC,EAAE,MAAM,CAAA;CAClB;AAED,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,SAAS;IACpD,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,CAAA;IACpB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAA;IACzB,GAAG,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAA;IACtB,IAAI,IAAI,IAAI,CAAA;IACZ,IAAI,IAAI,IAAI,CAAA;CACb;AAED;;;GAGG;AACH,wBAAgB,kBAAkB,CAAC,CAAC,SAAS,SAAS,EACpD,aAAa,EAAE,CAAC,EAAE,EAClB,OAAO,GAAE,mBAAwB,GAChC,iBAAiB,CAAC,CAAC,CAAC,CA8BtB"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { historyReducer } from '@dnd-block-tree/core';
|
|
2
|
+
/**
|
|
3
|
+
* Reactive undo/redo history using $state runes.
|
|
4
|
+
* Wraps core's historyReducer.
|
|
5
|
+
*/
|
|
6
|
+
export function createBlockHistory(initialBlocks, options = {}) {
|
|
7
|
+
const { maxSteps = 50 } = options;
|
|
8
|
+
let state = $state({
|
|
9
|
+
past: [],
|
|
10
|
+
present: initialBlocks,
|
|
11
|
+
future: [],
|
|
12
|
+
});
|
|
13
|
+
const blocks = $derived(state.present);
|
|
14
|
+
const canUndo = $derived(state.past.length > 0);
|
|
15
|
+
const canRedo = $derived(state.future.length > 0);
|
|
16
|
+
return {
|
|
17
|
+
get blocks() { return blocks; },
|
|
18
|
+
get canUndo() { return canUndo; },
|
|
19
|
+
get canRedo() { return canRedo; },
|
|
20
|
+
set(newBlocks) {
|
|
21
|
+
state = historyReducer(state, { type: 'SET', payload: newBlocks, maxSteps });
|
|
22
|
+
},
|
|
23
|
+
undo() {
|
|
24
|
+
state = historyReducer(state, { type: 'UNDO' });
|
|
25
|
+
},
|
|
26
|
+
redo() {
|
|
27
|
+
state = historyReducer(state, { type: 'REDO' });
|
|
28
|
+
},
|
|
29
|
+
};
|
|
30
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { BaseBlock, BlockIndex, OrderingStrategy, BlockAddEvent, BlockDeleteEvent } from '@dnd-block-tree/core';
|
|
2
|
+
export interface BlockStateOptions<T extends BaseBlock> {
|
|
3
|
+
initialBlocks?: T[];
|
|
4
|
+
containerTypes?: readonly string[];
|
|
5
|
+
orderingStrategy?: OrderingStrategy;
|
|
6
|
+
maxDepth?: number;
|
|
7
|
+
onChange?: (blocks: T[]) => void;
|
|
8
|
+
onBlockAdd?: (event: BlockAddEvent<T>) => void;
|
|
9
|
+
onBlockDelete?: (event: BlockDeleteEvent<T>) => void;
|
|
10
|
+
}
|
|
11
|
+
export interface BlockState<T extends BaseBlock> {
|
|
12
|
+
readonly blocks: T[];
|
|
13
|
+
readonly blockMap: Map<string, T>;
|
|
14
|
+
readonly childrenMap: Map<string | null, T[]>;
|
|
15
|
+
readonly normalizedIndex: BlockIndex<T>;
|
|
16
|
+
createItem(type: T['type'], parentId?: string | null): T;
|
|
17
|
+
insertItem(type: T['type'], referenceId: string, position: 'before' | 'after'): T;
|
|
18
|
+
deleteItem(id: string): void;
|
|
19
|
+
moveItem(activeId: string, targetZone: string): void;
|
|
20
|
+
setAll(blocks: T[]): void;
|
|
21
|
+
}
|
|
22
|
+
export declare function createBlockState<T extends BaseBlock>(options?: BlockStateOptions<T>): BlockState<T>;
|
|
23
|
+
/** Set block state in context */
|
|
24
|
+
export declare function setBlockStateContext<T extends BaseBlock>(state: BlockState<T>): void;
|
|
25
|
+
/** Get block state from context */
|
|
26
|
+
export declare function getBlockStateContext<T extends BaseBlock>(): BlockState<T>;
|
|
27
|
+
//# sourceMappingURL=block-state.svelte.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"block-state.svelte.d.ts","sourceRoot":"","sources":["../../src/state/block-state.svelte.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,SAAS,EACT,UAAU,EAGV,gBAAgB,EAChB,aAAa,EACb,gBAAgB,EACjB,MAAM,sBAAsB,CAAA;AAa7B,MAAM,WAAW,iBAAiB,CAAC,CAAC,SAAS,SAAS;IACpD,aAAa,CAAC,EAAE,CAAC,EAAE,CAAA;IACnB,cAAc,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;IAClC,gBAAgB,CAAC,EAAE,gBAAgB,CAAA;IACnC,QAAQ,CAAC,EAAE,MAAM,CAAA;IACjB,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,CAAC,EAAE,KAAK,IAAI,CAAA;IAChC,UAAU,CAAC,EAAE,CAAC,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;IAC9C,aAAa,CAAC,EAAE,CAAC,KAAK,EAAE,gBAAgB,CAAC,CAAC,CAAC,KAAK,IAAI,CAAA;CACrD;AAED,MAAM,WAAW,UAAU,CAAC,CAAC,SAAS,SAAS;IAC7C,QAAQ,CAAC,MAAM,EAAE,CAAC,EAAE,CAAA;IACpB,QAAQ,CAAC,QAAQ,EAAE,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAA;IACjC,QAAQ,CAAC,WAAW,EAAE,GAAG,CAAC,MAAM,GAAG,IAAI,EAAE,CAAC,EAAE,CAAC,CAAA;IAC7C,QAAQ,CAAC,eAAe,EAAE,UAAU,CAAC,CAAC,CAAC,CAAA;IACvC,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,QAAQ,CAAC,EAAE,MAAM,GAAG,IAAI,GAAG,CAAC,CAAA;IACxD,UAAU,CAAC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,EAAE,WAAW,EAAE,MAAM,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,GAAG,CAAC,CAAA;IACjF,UAAU,CAAC,EAAE,EAAE,MAAM,GAAG,IAAI,CAAA;IAC5B,QAAQ,CAAC,QAAQ,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,GAAG,IAAI,CAAA;IACpD,MAAM,CAAC,MAAM,EAAE,CAAC,EAAE,GAAG,IAAI,CAAA;CAC1B;AAED,wBAAgB,gBAAgB,CAAC,CAAC,SAAS,SAAS,EAClD,OAAO,GAAE,iBAAiB,CAAC,CAAC,CAAM,GACjC,UAAU,CAAC,CAAC,CAAC,CAoGf;AAED,iCAAiC;AACjC,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,IAAI,CAEpF;AAED,mCAAmC;AACnC,wBAAgB,oBAAoB,CAAC,CAAC,SAAS,SAAS,KAAK,UAAU,CAAC,CAAC,CAAC,CAIzE"}
|