@tvolden/block-code-editor 0.1.1 → 0.2.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 (39) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +41 -0
  3. package/dist/block-editor.cjs +9 -1
  4. package/dist/block-editor.js +2147 -2101
  5. package/dist/blockRegistry.d.ts +9 -2
  6. package/dist/collaboration/presence.d.ts +23 -0
  7. package/dist/collaboration/sync.d.ts +71 -0
  8. package/dist/collaboration/types.d.ts +93 -0
  9. package/dist/commands/apply.d.ts +18 -0
  10. package/dist/commands/build.d.ts +31 -0
  11. package/dist/commands/index.d.ts +4 -0
  12. package/dist/commands/invert.d.ts +6 -0
  13. package/dist/commands/types.d.ts +84 -0
  14. package/dist/components/BlockPalette.d.ts +4 -5
  15. package/dist/components/BlockRenderer.d.ts +12 -2
  16. package/dist/components/Canvas.d.ts +6 -0
  17. package/dist/components/ExportMenu.d.ts +6 -0
  18. package/dist/components/MouthDecorations.d.ts +13 -0
  19. package/dist/components/PackagesTab.d.ts +20 -0
  20. package/dist/components/PeersOverlay.d.ts +14 -0
  21. package/dist/components/SocketHint.d.ts +11 -0
  22. package/dist/components/UndoRedoBar.d.ts +11 -0
  23. package/dist/demo/LocalServer.d.ts +38 -0
  24. package/dist/demo/pythonWriter.d.ts +6 -0
  25. package/dist/editor/BlockEditor.d.ts +27 -6
  26. package/dist/editor/activeEditor.d.ts +12 -0
  27. package/dist/export/program.d.ts +55 -0
  28. package/dist/index.d.ts +10 -5
  29. package/dist/types.d.ts +39 -0
  30. package/dist/utils/blockLayout.d.ts +60 -4
  31. package/dist/utils/blockShapes.d.ts +12 -1
  32. package/dist/utils/packages.d.ts +17 -0
  33. package/dist/utils/storage.d.ts +6 -0
  34. package/package.json +11 -2
  35. package/dist/carddesigner/CardCanvas.d.ts +0 -10
  36. package/dist/carddesigner/CardDesigner.d.ts +0 -47
  37. package/dist/carddesigner/CardPreview.d.ts +0 -11
  38. package/dist/carddesigner/cardDesignTypes.d.ts +0 -85
  39. package/dist/packages.json +0 -23
@@ -11,7 +11,10 @@ export interface LoadedPackage {
11
11
  blockIds: string[];
12
12
  conflictIds: string[];
13
13
  }
14
- /** Fetch a package JSON and merge its blocks into the registry (first-registered wins). */
14
+ /**
15
+ * Fetch a package JSON and merge its blocks into the registry (first-registered wins). A package already loaded under
16
+ * the same id from the same URL is kept as it is (several editors on a page share the registry).
17
+ */
15
18
  export declare function loadPackage(info: PackageInfo): Promise<LoadedPackage>;
16
19
  /** Remove all blocks that belong to a package. No-op if not loaded. */
17
20
  export declare function unloadPackage(packageId: string): void;
@@ -25,5 +28,9 @@ export declare function getAllDefinitions(): BlockDefinition[];
25
28
  export declare function getCategories(): string[];
26
29
  /** Register block definitions directly (no URL fetch). First-registered wins on conflicts. */
27
30
  export declare function loadInlinePackage(info: PackageInfo, defs: BlockDefinition[]): LoadedPackage;
28
- /** Load the initial/core block set. Clears all prior registry state first. */
31
+ /**
32
+ * Load the initial/core block set. Clears all prior registry state first, unless the core set from this URL is loaded
33
+ * already: then everything stays (another editor on the page uses it; the editors' dependency sync unloads what they
34
+ * no longer need).
35
+ */
29
36
  export declare function loadBlockRegistry(url: string): Promise<void>;
@@ -0,0 +1,23 @@
1
+ import type { Presence } from './types';
2
+ export declare const DEFAULT_PRESENCE_INTERVAL_MS = 66;
3
+ /**
4
+ * Keeps this client's presence and publishes it at most once per interval: an update within the interval is sent when
5
+ * it ends (only the latest), while `updateNow` (a drag or typing starting or ending) is sent at once.
6
+ */
7
+ export declare class PresencePublisher {
8
+ private presence;
9
+ private lastSent;
10
+ private timer;
11
+ private readonly send;
12
+ private readonly intervalMs;
13
+ private readonly now;
14
+ constructor(send: (presence: Presence) => void, intervalMs?: number, now?: () => number);
15
+ get current(): Presence;
16
+ /** A change sent within the interval (e.g. the cursor moving). */
17
+ update(change: Partial<Presence>): void;
18
+ /** A change sent at once (a drag or typing starting or ending). */
19
+ updateNow(change: Partial<Presence>): void;
20
+ /** Stops a pending send. */
21
+ dispose(): void;
22
+ private flush;
23
+ }
@@ -0,0 +1,71 @@
1
+ /**
2
+ * Command sourcing, client side: the confirmed state (the snapshot plus the applied commands, in order), this client's
3
+ * pending actions, and its own history for undo/redo. Pure: every function returns a new SyncState.
4
+ */
5
+ import type { CanvasState, Command } from '../commands/types';
6
+ import type { CommandEnvelope } from './types';
7
+ /** What a pending action does to the history once it is confirmed. */
8
+ export type ActionKind = 'do' | 'undo' | 'redo';
9
+ export interface PendingAction {
10
+ id: string;
11
+ /** The command submitted. */
12
+ command: Command;
13
+ kind: ActionKind;
14
+ /** The history entry it concerns: the action itself ('do'), or the original action undone / redone. */
15
+ original: Command;
16
+ }
17
+ export interface SyncState {
18
+ confirmed: CanvasState;
19
+ /** The version of the confirmed state. */
20
+ version: number;
21
+ /** This client's submitted actions, oldest first. */
22
+ pending: PendingAction[];
23
+ /** This client's confirmed actions that can be undone (last is next), and those that can be redone. */
24
+ undo: Command[];
25
+ redo: Command[];
26
+ }
27
+ export declare function initialSync(state: CanvasState, version?: number): SyncState;
28
+ /** A user action submitted (and pending). */
29
+ export declare function submitAction(sync: SyncState, id: string, command: Command): SyncState;
30
+ /** Undo submitted: the inverse of the last confirmed own action. Null when there is nothing to undo. */
31
+ export declare function submitUndo(sync: SyncState, id: string): {
32
+ sync: SyncState;
33
+ command: Command;
34
+ } | null;
35
+ /** Redo submitted: the last undone action again. Null when there is nothing to redo. */
36
+ export declare function submitRedo(sync: SyncState, id: string): {
37
+ sync: SyncState;
38
+ command: Command;
39
+ } | null;
40
+ /** Undo and redo wait until no own action is pending (an in-flight action could depend on what they'd change). */
41
+ export declare function canUndoRedo(sync: SyncState): boolean;
42
+ /** A snapshot replaces the confirmed state; pending actions and the history are dropped. Returns how many were dropped. */
43
+ export declare function onSnapshot(state: CanvasState, version: number, sync: SyncState): {
44
+ sync: SyncState;
45
+ dropped: number;
46
+ };
47
+ /**
48
+ * A command applied by the backend. Confirms the pending action with its id (when it is this client's). `outOfSync`
49
+ * when the command doesn't apply to the confirmed state (the client missed something): the host should resync.
50
+ */
51
+ export declare function onApplied(sync: SyncState, envelope: CommandEnvelope, version: number): {
52
+ sync: SyncState;
53
+ outOfSync: boolean;
54
+ };
55
+ /**
56
+ * One of this client's commands, rejected: the pending action goes. A rejected undo or redo also drops its history
57
+ * step (it can no longer be applied). Returns the action (null when it wasn't pending).
58
+ */
59
+ export declare function onRejected(sync: SyncState, id: string): {
60
+ sync: SyncState;
61
+ action: PendingAction | null;
62
+ };
63
+ /**
64
+ * What the user sees: the confirmed state with the pending actions applied on top, in order, up to the first that no
65
+ * longer applies (the ones after it may depend on it). `provisionalIds`: the blocks the shown pending actions add or
66
+ * change.
67
+ */
68
+ export declare function preview(sync: SyncState): {
69
+ state: CanvasState;
70
+ provisionalIds: Set<string>;
71
+ };
@@ -0,0 +1,93 @@
1
+ import type { PackageRef, PlacedBlock } from '../types';
2
+ import type { Command, Position, RejectionCode } from '../commands/types';
3
+ /** A canvas state that can be sent over a wire: the blocks (by id) and the dependencies. */
4
+ export interface SerializedCanvasState {
5
+ blocks: [string, PlacedBlock][];
6
+ dependencies: PackageRef[];
7
+ }
8
+ /** A command as a client submits it, and as it comes back once applied. */
9
+ export interface CommandEnvelope {
10
+ /** Unique per submission (the editor makes a UUID). */
11
+ id: string;
12
+ /** The submitting client. */
13
+ clientId: string;
14
+ /** The last version the client had applied when it made the command (informational: commands check themselves). */
15
+ baseVersion: number;
16
+ command: Command;
17
+ }
18
+ /** What the host feeds the editor. */
19
+ export type CommandEvent =
20
+ /** The state to start from: on connecting, and after a resync. */
21
+ {
22
+ type: 'snapshot';
23
+ state: SerializedCanvasState;
24
+ version: number;
25
+ }
26
+ /** A command applied by the backend (anyone's), in log order; `version` is the state's version after it. */
27
+ | {
28
+ type: 'applied';
29
+ envelope: CommandEnvelope;
30
+ version: number;
31
+ }
32
+ /** One of this client's commands, rejected. */
33
+ | {
34
+ type: 'rejected';
35
+ id: string;
36
+ code: RejectionCode;
37
+ message: string;
38
+ };
39
+ /**
40
+ * Command sourcing: the editor submits every user action as a command and changes its state only by the events the
41
+ * host feeds back. The host implements this over its own transport.
42
+ */
43
+ export interface CommandChannel {
44
+ submit(envelope: CommandEnvelope): void;
45
+ /** Starts delivering events; returns the function that stops it. */
46
+ subscribe(listener: (event: CommandEvent) => void): () => void;
47
+ /** Asks for a new snapshot: called when an applied command doesn't fit the editor's state (it missed something). */
48
+ resync?(): void;
49
+ }
50
+ /** What a client shows the others while it edits. All positions are canvas (SVG) coordinates. */
51
+ export interface Presence {
52
+ /** The pointer over the canvas, or null when it is elsewhere. */
53
+ cursor: Position | null;
54
+ /** A drag: of canvas blocks (by the lead block) or of a new block from the palette, with the ghost's top-left. */
55
+ drag: {
56
+ leadId: string;
57
+ at: Position;
58
+ } | {
59
+ definitionId: string;
60
+ at: Position;
61
+ } | null;
62
+ /** A parameter being typed into, with the text typed so far. */
63
+ typing: {
64
+ blockId: string;
65
+ slot: number;
66
+ text: string;
67
+ } | null;
68
+ }
69
+ /** Another client's presence, with how to show them. */
70
+ export interface PeerPresence extends Presence {
71
+ clientId: string;
72
+ name: string;
73
+ /** A CSS colour. */
74
+ color: string;
75
+ }
76
+ /** Multiplayer presence: published by the editor (throttled), the others' delivered by the host. */
77
+ export interface PresenceChannel {
78
+ publish(presence: Presence): void;
79
+ /** Starts delivering the other clients' presence (the full list each time); returns the function that stops it. */
80
+ subscribe(listener: (peers: PeerPresence[]) => void): () => void;
81
+ }
82
+ /**
83
+ * How the editor collaborates. Without it the editor is standalone; with `commands` it is command-sourced; with
84
+ * `presence` it shows and shares cursors, drags and typing.
85
+ */
86
+ export interface Collaboration {
87
+ /** This client's id: its envelopes carry it, and its own presence is left out of the peers. */
88
+ clientId: string;
89
+ commands?: CommandChannel;
90
+ presence?: PresenceChannel;
91
+ /** The least time between two presence updates (default 66 ms, about 15 a second). */
92
+ presenceIntervalMs?: number;
93
+ }
@@ -0,0 +1,18 @@
1
+ import type { ParamSlot, PlacedBlock } from '../types';
2
+ import type { CanvasState, Command } from './types';
3
+ /**
4
+ * Applies a command to the state and returns the new state; throws `CommandRejected` (leaving the state unchanged)
5
+ * when one of its checks fails. Pure: the given state is never modified. See docs/commands.md.
6
+ */
7
+ export declare function applyCommand(state: CanvasState, command: Command): CanvasState;
8
+ /** A slot in its canonical form: all three fields present. */
9
+ export declare function normalizeSlot(slot: ParamSlot | undefined): ParamSlot;
10
+ /**
11
+ * A block in its canonical form: all slot fields present, and a linked block at (0, 0) (only a root's position means
12
+ * anything; the others are laid out by the block they hang off).
13
+ */
14
+ export declare function normalizeBlock(block: PlacedBlock): PlacedBlock;
15
+ /** Empty text is no text. */
16
+ export declare function normalizeText(text: string | null | undefined): string | null;
17
+ /** The ids of a block and everything hanging off it: the blocks below it, its queries and its mouths' chains. */
18
+ export declare function fragmentOf(blocks: Map<string, PlacedBlock>, id: string): string[];
@@ -0,0 +1,31 @@
1
+ /**
2
+ * Builders: the commands a user action becomes. Each builds against a scratch copy of the state, applying every
3
+ * command as it is added, so later commands see what earlier ones did (and a builder can never produce a command that
4
+ * would be rejected against the state it was given).
5
+ */
6
+ import type { PackageRef, PlacedBlock } from '../types';
7
+ import type { CanvasState, Command, Place, Position } from './types';
8
+ /** Commands use integer positions. */
9
+ export declare function roundPosition(p: Position): Position;
10
+ /** Where a block is linked, or null for a root. */
11
+ export declare function placeOf(state: CanvasState, block: PlacedBlock): Place | null;
12
+ export declare function samePlace(a: Place, b: Place): boolean;
13
+ /** A new block from the palette, at `at` (a root) or linked into `place`. */
14
+ export declare function placeNewBlock(state: CanvasState, block: PlacedBlock, at: Position, place: Place | null): Command | null;
15
+ /**
16
+ * A block (with what hangs off it) dragged and dropped: linked into `place`, or a root at `drop`. Nothing when it is
17
+ * dropped back where it is.
18
+ */
19
+ export declare function moveChain(state: CanvasState, leadId: string, drop: Position, place: Place | null): Command | null;
20
+ /** A block (with what hangs off it) deleted. */
21
+ export declare function deleteChain(state: CanvasState, leadId: string): Command | null;
22
+ /**
23
+ * A parameter's typed value changed from `from` (the text when editing started, so a change someone else made
24
+ * meanwhile is rejected rather than overwritten) to `to`; nothing when they are the same.
25
+ */
26
+ export declare function setSocketText(blockId: string, slot: number, from: string | null, to: string | null): Command | null;
27
+ /**
28
+ * The dependencies changed to `to`, removing the blocks `removedIds` (those of removed packages) first. A removed
29
+ * block takes what it holds (its queries and mouths) with it; the block under it moves up into its place.
30
+ */
31
+ export declare function changeDependencies(state: CanvasState, to: PackageRef[], removedIds: string[]): Command | null;
@@ -0,0 +1,4 @@
1
+ export * from './types';
2
+ export { applyCommand, fragmentOf, normalizeBlock, normalizeSlot, normalizeText } from './apply';
3
+ export { invertCommand } from './invert';
4
+ export { placeNewBlock, moveChain, deleteChain, setSocketText, changeDependencies, placeOf, samePlace, roundPosition, } from './build';
@@ -0,0 +1,6 @@
1
+ import type { Command } from './types';
2
+ /**
3
+ * The command that undoes `command`: applied right after it, it restores the state from before. Computed from the
4
+ * command alone (it never looks at the state). See docs/commands.md.
5
+ */
6
+ export declare function invertCommand(command: Command): Command;
@@ -0,0 +1,84 @@
1
+ import type { PackageRef, PlacedBlock } from '../types';
2
+ /** The version of the command contract (docs/commands.md). Bumped on any incompatible change. */
3
+ export declare const COMMANDS_VERSION = 1;
4
+ /** What commands change: the canvas's blocks (by id) and the packages it depends on. */
5
+ export interface CanvasState {
6
+ blocks: Map<string, PlacedBlock>;
7
+ dependencies: PackageRef[];
8
+ }
9
+ /** A canvas position. Commands use integer coordinates. */
10
+ export interface Position {
11
+ x: number;
12
+ y: number;
13
+ }
14
+ /**
15
+ * Where a block can be linked: under a block (its `next`), at the top of a block's mouth (a command parameter of a
16
+ * command block), or in a block's socket (a query in a parameter).
17
+ */
18
+ export type Place = {
19
+ next: string;
20
+ } | {
21
+ mouth: string;
22
+ slot: number;
23
+ } | {
24
+ socket: string;
25
+ slot: number;
26
+ };
27
+ /** Adds a detached fragment: one root block and everything hanging off it, linked among themselves. */
28
+ export interface InsertBlocks {
29
+ type: 'InsertBlocks';
30
+ blocks: PlacedBlock[];
31
+ }
32
+ /** Removes a detached fragment, given exactly as it is. */
33
+ export interface RemoveBlocks {
34
+ type: 'RemoveBlocks';
35
+ blocks: PlacedBlock[];
36
+ }
37
+ /** Moves a root block. */
38
+ export interface MoveBlock {
39
+ type: 'MoveBlock';
40
+ id: string;
41
+ from: Position;
42
+ to: Position;
43
+ }
44
+ /** Links a root block (at `from`) into an empty place. */
45
+ export interface Attach {
46
+ type: 'Attach';
47
+ id: string;
48
+ to: Place;
49
+ from: Position;
50
+ }
51
+ /** Unlinks a block (with what hangs off it) from its place, making it a root at `to`. */
52
+ export interface Detach {
53
+ type: 'Detach';
54
+ id: string;
55
+ from: Place;
56
+ to: Position;
57
+ }
58
+ /** Sets or clears (null) a parameter's typed value. */
59
+ export interface SetText {
60
+ type: 'SetText';
61
+ blockId: string;
62
+ slot: number;
63
+ from: string | null;
64
+ to: string | null;
65
+ }
66
+ /** Changes the packages the canvas depends on. */
67
+ export interface SetDependencies {
68
+ type: 'SetDependencies';
69
+ from: PackageRef[];
70
+ to: PackageRef[];
71
+ }
72
+ /** Applies its commands in order, all or nothing. */
73
+ export interface Batch {
74
+ type: 'Batch';
75
+ commands: Command[];
76
+ }
77
+ export type Command = InsertBlocks | RemoveBlocks | MoveBlock | Attach | Detach | SetText | SetDependencies | Batch;
78
+ /** Why a command was rejected; machine-readable, shared with the backend's implementation. */
79
+ export type RejectionCode = 'BLOCK_NOT_FOUND' | 'ID_EXISTS' | 'NOT_A_FRAGMENT' | 'BLOCK_CHANGED' | 'LINKED_FROM_OUTSIDE' | 'NOT_A_ROOT' | 'POSITION_CHANGED' | 'NO_SUCH_SLOT' | 'PLACE_OCCUPIED' | 'CYCLE' | 'NOT_AT_PLACE' | 'SLOT_HAS_QUERY' | 'TEXT_CHANGED' | 'DEPENDENCIES_CHANGED' | 'INVALID_COMMAND' | 'HOST_REJECTED';
80
+ /** Thrown by `applyCommand` when a command's checks fail. The state is unchanged. */
81
+ export declare class CommandRejected extends Error {
82
+ readonly code: RejectionCode;
83
+ constructor(code: RejectionCode, message: string);
84
+ }
@@ -1,14 +1,13 @@
1
1
  import React from 'react';
2
- import type { PackageInfo, LoadedPackage } from '../blockRegistry';
2
+ import type { PackagesTabProps } from './PackagesTab';
3
3
  interface Props {
4
4
  onPointerDown: (e: React.PointerEvent, definitionId: string) => void;
5
5
  isDropTarget?: boolean;
6
6
  registryVersion: number;
7
- availablePackages: PackageInfo[];
8
- loadedPackages: LoadedPackage[];
9
- onPackageToggle: (pkg: PackageInfo, currentlyLoaded: boolean) => Promise<void>;
7
+ /** The Packages tab's contents; without it the palette has no Packages tab. */
8
+ packages?: PackagesTabProps;
10
9
  /** Definition IDs of start (event) blocks already placed on the canvas. */
11
10
  placedStartIds: Set<string>;
12
11
  }
13
- export default function BlockPalette({ onPointerDown, isDropTarget, registryVersion, availablePackages, loadedPackages, onPackageToggle, placedStartIds, }: Props): import("react/jsx-runtime").JSX.Element;
12
+ export default function BlockPalette({ onPointerDown, isDropTarget, registryVersion, packages, placedStartIds, }: Props): import("react/jsx-runtime").JSX.Element;
14
13
  export {};
@@ -15,8 +15,18 @@ interface Props {
15
15
  /** Called when the user starts dragging an output pill from a start block. */
16
16
  onOutputDrag?: (e: React.PointerEvent, defId: string) => void;
17
17
  isGhost?: boolean;
18
- isDragging?: boolean;
18
+ /** Blocks being dragged: drawn faded where they are (with everything hanging off them) until the drop. */
19
+ draggingIds?: Set<string>;
20
+ /** Blocks changed by actions not confirmed yet: drawn with a dashed outline and italic text. */
21
+ provisionalIds?: Set<string>;
22
+ /** The text of the socket being typed into, on every keystroke. */
23
+ onSocketInput?: (blockId: string, slotIndex: number, text: string) => void;
19
24
  embedded?: boolean;
20
25
  }
21
- export declare function BlockRenderer({ block, allBlocks, onPointerDown, onBlockClick, onSocketClick, editingSocket, onSocketCommit, onSocketCancelEdit, onOutputDrag, isGhost, isDragging, embedded, }: Props): import("react/jsx-runtime").JSX.Element;
26
+ /**
27
+ * Draws a block and everything that hangs off it: the queries in its sockets, the chains in its mouths, and the block
28
+ * chained under it (recursively), so a growing C-block moves the blocks below it and never hides its contents.
29
+ * Roots are placed at their own x/y; everything else (`embedded`) is placed by the block that draws it.
30
+ */
31
+ export declare function BlockRenderer(props: Props): import("react/jsx-runtime").JSX.Element;
22
32
  export {};
@@ -3,6 +3,8 @@ import type { PlacedBlock } from '../types';
3
3
  interface Props {
4
4
  blocks: Map<string, PlacedBlock>;
5
5
  draggingIds: Set<string>;
6
+ /** Blocks changed by actions still waiting for the host's confirmation: drawn provisionally. */
7
+ provisionalIds?: Set<string>;
6
8
  onBlockPointerDown: (e: React.PointerEvent, id: string) => void;
7
9
  onBlockClick: (id: string) => void;
8
10
  onSocketClick: (blockId: string, slotIndex: number) => void;
@@ -10,9 +12,13 @@ interface Props {
10
12
  blockId: string;
11
13
  slotIndex: number;
12
14
  } | null;
15
+ /** The text of the socket being typed into, on every keystroke. */
16
+ onSocketInput?: (blockId: string, slotIndex: number, text: string) => void;
13
17
  onSocketCommit?: (blockId: string, slotIndex: number, value: string) => void;
14
18
  onSocketCancelEdit?: () => void;
15
19
  onOutputDrag: (e: React.PointerEvent, defId: string) => void;
20
+ /** Drawn over the blocks (e.g. other users' cursors). */
21
+ overlay?: React.ReactNode;
16
22
  }
17
23
  declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<SVGSVGElement>>;
18
24
  export default Canvas;
@@ -0,0 +1,6 @@
1
+ import type { ScriptWriter } from '../export/program';
2
+ /** An Export button with a menu of the script writers. */
3
+ export default function ExportMenu({ writers, onExport }: {
4
+ writers: ScriptWriter[];
5
+ onExport: (writer: ScriptWriter) => void;
6
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,13 @@
1
+ import type { MouthInfo } from '../utils/blockLayout';
2
+ /**
3
+ * What a C-block draws around its mouths: each divider bar's parameter name, and a dashed placeholder with the
4
+ * parameter's name in every empty mouth. Both show the parameter's name and type on hover (pressing them drags the
5
+ * block, as they are part of it). The chains in the mouths are drawn by the caller.
6
+ */
7
+ export declare function MouthDecorations({ mouths, w, isEmpty }: {
8
+ mouths: MouthInfo[];
9
+ /** The block's width, which the divider bars span. */
10
+ w: number;
11
+ /** Whether the mouth of the parameter at this index holds no chain. */
12
+ isEmpty: (index: number) => boolean;
13
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,20 @@
1
+ import type { CatalogPackage, PackageAction, PackageRef } from '../types';
2
+ export interface PackagesTabProps {
3
+ /** Packages that may be added (the caller decides which: e.g. only those usable here). */
4
+ available: CatalogPackage[];
5
+ /** The chosen packages. */
6
+ dependencies: PackageRef[];
7
+ onChange: (dependencies: PackageRef[]) => void;
8
+ /** Extra buttons below the add row. */
9
+ actions?: PackageAction[];
10
+ /** Blocks on the canvas per chosen package, by `packageKey`. */
11
+ blockCounts: Map<string, number>;
12
+ /** Blocks of a chosen package skipped because another package already defines their id, by `packageKey`. */
13
+ conflictCounts: Map<string, number>;
14
+ }
15
+ /**
16
+ * The chosen packages of a canvas, maintained by the user: adding pins the listed version (a specific version is an
17
+ * advanced option), a badge offers a newer listed version, and removing asks first, because the package's blocks are
18
+ * deleted from the canvas. Versions are never updated automatically.
19
+ */
20
+ export default function PackagesTab({ available, dependencies, onChange, actions, blockCounts, conflictCounts }: PackagesTabProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,14 @@
1
+ import type { PlacedBlock } from '../types';
2
+ import type { PeerPresence } from '../collaboration/types';
3
+ /**
4
+ * The other users, drawn over the canvas (never hit by the pointer): their cursors with names, the blocks they drag
5
+ * (a ghost where they are, an outline on the originals) and the parameter they are typing into, with their text.
6
+ */
7
+ export default function PeersOverlay({ peers, blocks, layout }: {
8
+ peers: PeerPresence[];
9
+ blocks: Map<string, PlacedBlock>;
10
+ layout: Map<string, {
11
+ x: number;
12
+ y: number;
13
+ }>;
14
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import type { ParamType } from '../types';
2
+ /**
3
+ * The name of an empty socket's parameter, centred in the socket and cut to fit. The type is on hover (the socket's
4
+ * title): primitive types are told apart by the socket's shape.
5
+ */
6
+ export declare function SocketHint({ name, type, w, h }: {
7
+ name: string;
8
+ type: ParamType;
9
+ w: number;
10
+ h: number;
11
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,11 @@
1
+ import type React from 'react';
2
+ /** Undo and redo buttons over the canvas's top-right corner, with a short notice (e.g. a step that couldn't be undone). */
3
+ export default function UndoRedoBar({ canUndo, canRedo, onUndo, onRedo, notice, extra }: {
4
+ canUndo: boolean;
5
+ canRedo: boolean;
6
+ onUndo: () => void;
7
+ onRedo: () => void;
8
+ notice: string | null;
9
+ /** More controls before the buttons (e.g. the Export menu). */
10
+ extra?: React.ReactNode;
11
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,38 @@
1
+ /**
2
+ * An in-memory stand-in for a collaboration backend, for the dev app's multiplayer demo and the tests. It does what
3
+ * a real backend does (and is the reference for one): checks and applies each submitted command against its state
4
+ * (`applyCommand`), numbers the applied commands, broadcasts them to every client (or rejects them to the submitter),
5
+ * and relays presence with a name and colour per client.
6
+ */
7
+ import type { CanvasState } from '../commands/types';
8
+ import type { CommandChannel, PresenceChannel } from '../collaboration/types';
9
+ export declare class LocalServer {
10
+ private state;
11
+ private version;
12
+ private readonly clients;
13
+ /** How long the server takes to answer a command (to make pending actions visible). */
14
+ private delayMs;
15
+ constructor(state: CanvasState, delayMs?: number);
16
+ get delay(): number;
17
+ setDelay(ms: number): void;
18
+ /** The server's current state and version. */
19
+ get current(): {
20
+ state: CanvasState;
21
+ version: number;
22
+ };
23
+ /** A client's channels. Connecting again with the same id gives channels to the same client (its listeners stay). */
24
+ connect(clientId: string, name: string, color: string): {
25
+ commands: CommandChannel;
26
+ presence: PresenceChannel;
27
+ };
28
+ /**
29
+ * A client went away (closed, or timed out on a real transport): its listeners are dropped and it leaves the
30
+ * others' peer lists.
31
+ */
32
+ disconnect(clientId: string): void;
33
+ private later;
34
+ private snapshot;
35
+ private receive;
36
+ private peersOf;
37
+ private broadcastPresence;
38
+ }
@@ -0,0 +1,6 @@
1
+ import type { ScriptWriter } from '../export/program';
2
+ /**
3
+ * A sample script writer for the dev app: Python, one function per chain. A start block becomes a decorated handler,
4
+ * a block with a mouth a `with` block.
5
+ */
6
+ export declare const pythonWriter: ScriptWriter;
@@ -11,12 +11,10 @@
11
11
  * clicks a block sequence
12
12
  */
13
13
  import React from 'react';
14
- import type { SerializedCanvas } from '../types';
14
+ import type { SerializedCanvas, PackageRef, CatalogPackage, PackageAction } from '../types';
15
+ import type { Collaboration } from '../collaboration/types';
16
+ import type { ScriptWriter } from '../export/program';
15
17
  export type { SerializedCanvas, BlockDefinition } from '../types';
16
- export { default as CardDesigner } from '../carddesigner/CardDesigner';
17
- export { default as CardPreview } from '../carddesigner/CardPreview';
18
- export type { CardDesign, CardMeta } from '../carddesigner/cardDesignTypes';
19
- export { defaultCardDesign } from '../carddesigner/cardDesignTypes';
20
18
  import type { Theme, ThemeId } from '../theme';
21
19
  interface Props {
22
20
  blocksUrl?: string;
@@ -50,5 +48,28 @@ interface Props {
50
48
  * prop unregisters the previous set and registers the new one.
51
49
  */
52
50
  additionalBlocks?: import('../types').BlockDefinition[];
51
+ /**
52
+ * The packages the canvas depends on, maintained in the palette's Packages tab (which shows only with this prop).
53
+ * Controlled: a change is reported with `onDependenciesChange`, and the editor loads what it is given back. Their
54
+ * blocks are fetched from `packageBlocksUrl`, after the `blocksUrl(s)`, which stay the core set.
55
+ */
56
+ dependencies?: PackageRef[];
57
+ onDependenciesChange?: (dependencies: PackageRef[]) => void;
58
+ /** Where a package version's blocks (`BlockDefinition[]`) are fetched. Required with `dependencies`. */
59
+ packageBlocksUrl?: (ref: PackageRef) => string;
60
+ /** The packages the Packages tab offers to add, each at the version adding it pins. */
61
+ availablePackages?: CatalogPackage[];
62
+ /** Extra buttons in the Packages tab. */
63
+ packageActions?: PackageAction[];
64
+ /**
65
+ * Collaboration: with `commands` the editor is command-sourced (it submits every action and changes its state only
66
+ * by the host's events); with `presence` it shares and shows cursors, drags and typing. Without it, standalone.
67
+ * The channels are read when the editor mounts and whenever they change identity.
68
+ */
69
+ collaboration?: Collaboration;
70
+ /** Script writers offered in the Export menu (the canvas as a program, see `toProgram`). */
71
+ scriptWriters?: ScriptWriter[];
72
+ /** Receives an exported script; without it the script is downloaded as `behavior.<extension>`. */
73
+ onExport?: (script: string, writer: ScriptWriter) => void;
53
74
  }
54
- export default function BlockEditor({ blocksUrl, blocksUrls, onRun, onThemeChange, navTabs, initialState, onSave, themeId, hideTitleBar, getStateRef, additionalBlocks }: Props): import("react/jsx-runtime").JSX.Element;
75
+ export default function BlockEditor({ blocksUrl, blocksUrls, onRun, onThemeChange, navTabs, initialState, onSave, themeId, hideTitleBar, getStateRef, additionalBlocks, dependencies, onDependenciesChange, packageBlocksUrl, availablePackages, packageActions, collaboration, scriptWriters, onExport, }: Props): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Which editor on the page keyboard shortcuts (undo/redo) act on: the one last pointed into or focused. Until then,
3
+ * the first one mounted. Several editors can share a page, and each listens to the whole window's keys.
4
+ */
5
+ /** An editor mounted: it is active if none is yet. */
6
+ export declare function registerEditor(id: symbol): void;
7
+ /** An editor unmounted: it is no longer active (the next one pointed into becomes active). */
8
+ export declare function unregisterEditor(id: symbol): void;
9
+ /** The user pointed into or focused this editor. */
10
+ export declare function activateEditor(id: symbol): void;
11
+ /** Whether this editor handles the keyboard shortcuts (also when no editor is active). */
12
+ export declare function isActiveEditor(id: symbol): boolean;