@tvolden/block-code-editor 0.1.1 → 0.3.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 (41) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +52 -0
  3. package/dist/block-editor.cjs +9 -1
  4. package/dist/block-editor.js +2293 -2119
  5. package/dist/blockRegistry.d.ts +9 -2
  6. package/dist/blocks.json +47 -2
  7. package/dist/collaboration/presence.d.ts +23 -0
  8. package/dist/collaboration/sync.d.ts +71 -0
  9. package/dist/collaboration/types.d.ts +93 -0
  10. package/dist/commands/apply.d.ts +18 -0
  11. package/dist/commands/build.d.ts +31 -0
  12. package/dist/commands/index.d.ts +4 -0
  13. package/dist/commands/invert.d.ts +6 -0
  14. package/dist/commands/types.d.ts +84 -0
  15. package/dist/components/BlockPalette.d.ts +4 -5
  16. package/dist/components/BlockRenderer.d.ts +14 -2
  17. package/dist/components/Canvas.d.ts +8 -0
  18. package/dist/components/ExportMenu.d.ts +6 -0
  19. package/dist/components/MouthDecorations.d.ts +13 -0
  20. package/dist/components/OptionalChip.d.ts +12 -0
  21. package/dist/components/PackagesTab.d.ts +20 -0
  22. package/dist/components/PeersOverlay.d.ts +14 -0
  23. package/dist/components/SocketHint.d.ts +11 -0
  24. package/dist/components/UndoRedoBar.d.ts +11 -0
  25. package/dist/demo/LocalServer.d.ts +38 -0
  26. package/dist/demo/pythonWriter.d.ts +6 -0
  27. package/dist/editor/BlockEditor.d.ts +27 -6
  28. package/dist/editor/activeEditor.d.ts +12 -0
  29. package/dist/export/program.d.ts +55 -0
  30. package/dist/index.d.ts +10 -5
  31. package/dist/types.d.ts +45 -0
  32. package/dist/utils/blockLayout.d.ts +89 -4
  33. package/dist/utils/blockShapes.d.ts +12 -1
  34. package/dist/utils/packages.d.ts +17 -0
  35. package/dist/utils/storage.d.ts +6 -0
  36. package/package.json +11 -2
  37. package/dist/carddesigner/CardCanvas.d.ts +0 -10
  38. package/dist/carddesigner/CardDesigner.d.ts +0 -47
  39. package/dist/carddesigner/CardPreview.d.ts +0 -11
  40. package/dist/carddesigner/cardDesignTypes.d.ts +0 -85
  41. package/dist/packages.json +0 -23
@@ -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;
@@ -0,0 +1,55 @@
1
+ /**
2
+ * The canvas as a plain program for script writers: no instance ids or links, just roots with their sequence of
3
+ * blocks, and each block's arguments.
4
+ */
5
+ import type { BlockDefinition, BlockType, ParamType } from '../types';
6
+ import type { CanvasState, Position } from '../commands/types';
7
+ export interface Program {
8
+ /** The chains on the canvas, top to bottom, then left to right (then by id). */
9
+ roots: ProgramRoot[];
10
+ }
11
+ export interface ProgramRoot {
12
+ position: Position;
13
+ /** The chain: its first block (a start block, or a loose command) and the blocks under it, in order. */
14
+ body: ProgramNode[];
15
+ }
16
+ export interface ProgramNode {
17
+ definitionId: string;
18
+ /** The block's name (the definition id for a block whose definition is missing). */
19
+ name: string;
20
+ /** `'missing'` for a block whose definition isn't loaded. */
21
+ blockType: BlockType | 'missing';
22
+ args: ProgramArg[];
23
+ }
24
+ export interface ProgramArg {
25
+ name: string;
26
+ type: ParamType;
27
+ value: ProgramValue;
28
+ }
29
+ export type ProgramValue = {
30
+ kind: 'text';
31
+ text: string;
32
+ }
33
+ /** A query in the socket. */
34
+ | {
35
+ kind: 'query';
36
+ node: ProgramNode;
37
+ }
38
+ /** A mouth's chain (empty for an empty mouth). */
39
+ | {
40
+ kind: 'body';
41
+ body: ProgramNode[];
42
+ } | {
43
+ kind: 'empty';
44
+ };
45
+ /** Turns a script into text. */
46
+ export interface ScriptWriter {
47
+ id: string;
48
+ /** Shown in the Export menu. */
49
+ label: string;
50
+ /** Without the dot, e.g. `py`. */
51
+ fileExtension: string;
52
+ write(program: Program): string;
53
+ }
54
+ /** The canvas as a program; `definitionOf` looks up block definitions (e.g. the editor's registry). */
55
+ export declare function toProgram(state: CanvasState, definitionOf: (id: string) => BlockDefinition | undefined): Program;
package/dist/index.d.ts CHANGED
@@ -1,10 +1,15 @@
1
1
  export { default } from './editor/BlockEditor';
2
2
  export { default as BlockEditor } from './editor/BlockEditor';
3
- export type { SerializedCanvas, BlockDefinition, ParamType, BlockType } from './types';
4
- export { default as CardDesigner } from './carddesigner/CardDesigner';
5
- export { default as CardPreview } from './carddesigner/CardPreview';
6
- export type { CardDesign, CardMeta } from './carddesigner/cardDesignTypes';
7
- export { defaultCardDesign } from './carddesigner/cardDesignTypes';
3
+ export type { SerializedCanvas, BlockDefinition, ParamType, BlockType, PlacedBlock, ParamSlot, PackageRef, CatalogPackage, PackageAction, } from './types';
4
+ export { packageKey, compareVersions } from './utils/packages';
5
+ export { COMMANDS_VERSION, CommandRejected, applyCommand, invertCommand, fragmentOf, normalizeBlock, normalizeSlot, normalizeText, placeNewBlock, moveChain, deleteChain, setSocketText, changeDependencies, placeOf, samePlace, roundPosition, } from './commands';
6
+ export type { CanvasState, Command, Place, Position, RejectionCode, InsertBlocks, RemoveBlocks, MoveBlock, Attach, Detach, SetText, SetDependencies, Batch, } from './commands';
7
+ export type { Collaboration, CommandChannel, CommandEnvelope, CommandEvent, PresenceChannel, Presence, PeerPresence, SerializedCanvasState, } from './collaboration/types';
8
+ export { toProgram } from './export/program';
9
+ export type { Program, ProgramRoot, ProgramNode, ProgramArg, ProgramValue, ScriptWriter } from './export/program';
10
+ export { pythonWriter } from './demo/pythonWriter';
11
+ export { LocalServer } from './demo/LocalServer';
12
+ export { COMMAND_PARAM_TYPE } from './types';
8
13
  export { ThemeContext, useTheme } from './ThemeContext';
9
14
  export { darkTheme, THEMES } from './theme';
10
15
  export type { Theme, ThemeId } from './theme';
package/dist/types.d.ts CHANGED
@@ -1,9 +1,17 @@
1
1
  /** Built-in primitive types. Any other string is a custom value type (e.g. 'Card', 'Player', 'Deck'). */
2
2
  export type ParamType = string;
3
3
  export type BlockType = 'command' | 'query' | 'start';
4
+ /** The parameter type that holds a chain of commands; a command block draws it as a C-shaped mouth. */
5
+ export declare const COMMAND_PARAM_TYPE = "command";
4
6
  export interface BlockParam {
5
7
  name: string;
6
8
  type: ParamType;
9
+ /**
10
+ * Whether the parameter may be left out (the host then uses its default). Not added, it is drawn as a small
11
+ * `[+] name` chip rather than an empty socket: dropping a query on it or typing into it adds it, and removing its value
12
+ * leaves it out again. Without it the parameter is required.
13
+ */
14
+ optional?: boolean;
7
15
  }
8
16
  /**
9
17
  * A guarantee that a particular query block (`id`) will return valid data
@@ -23,6 +31,11 @@ export interface BlockDefinition {
23
31
  name: string;
24
32
  blockType: BlockType;
25
33
  returnType?: ParamType;
34
+ /**
35
+ * For a query: the other types its result can be used as, so it also fits sockets of those types (e.g. a 'Deck' that is
36
+ * a 'CardCollection', or an 'int' that is a 'double').
37
+ */
38
+ usableAs?: ParamType[];
26
39
  params: BlockParam[];
27
40
  /** Context queries this event guarantees are valid. Only meaningful on start blocks. */
28
41
  provides?: BlockProvide[];
@@ -32,6 +45,12 @@ export interface BlockDefinition {
32
45
  export interface ParamSlot {
33
46
  textValue: string | null;
34
47
  queryBlockId: string | null;
48
+ /**
49
+ * For a command parameter of a command block (a C-shaped mouth): the first block of the chain it holds, or null when
50
+ * empty. That block has `embeddedInBlockId` = the host and `embeddedSlotIndex` = the parameter's index; the blocks after
51
+ * it are linked by `nextBlockId` / `parentBlockId` as in any chain. Optional, so canvases saved before mouths load.
52
+ */
53
+ commandBlockId?: string | null;
35
54
  }
36
55
  export interface PlacedBlock {
37
56
  instanceId: string;
@@ -44,6 +63,32 @@ export interface PlacedBlock {
44
63
  embeddedSlotIndex: number;
45
64
  paramSlots: ParamSlot[];
46
65
  }
66
+ /** One version of a block package that a canvas depends on. */
67
+ export interface PackageRef {
68
+ publisher: string;
69
+ name: string;
70
+ version: string;
71
+ }
72
+ /** A package that may be added in the Packages tab, at the version adding it pins (normally the newest listed). */
73
+ export interface CatalogPackage extends PackageRef {
74
+ description?: string;
75
+ /** Shown as a swatch next to the package. */
76
+ color?: string;
77
+ }
78
+ /**
79
+ * An extra button in the Packages tab, e.g. "Import game packages". It either runs the host's `onClick`, or gives the
80
+ * dependencies to change to (`dependencies`, from the current ones): a user action like a change made in the tab,
81
+ * so it is undoable and, when command-sourced, submitted.
82
+ */
83
+ export type PackageAction = {
84
+ label: string;
85
+ title?: string;
86
+ onClick: () => void;
87
+ } | {
88
+ label: string;
89
+ title?: string;
90
+ dependencies: (current: PackageRef[]) => PackageRef[];
91
+ };
47
92
  /**
48
93
  * Serialized form of the block canvas — safe to JSON.stringify/parse and
49
94
  * store externally (e.g. on a server). Pass back as `initialState` to restore.
@@ -1,8 +1,18 @@
1
- import type { BlockDefinition, ParamType, ParamSlot, PlacedBlock } from '../types';
1
+ import type { BlockDefinition, BlockParam, ParamType, ParamSlot, PlacedBlock } from '../types';
2
2
  export declare const BLOCK_H = 36;
3
3
  export declare const HAT_H = 50;
4
4
  export declare const QUERY_H = 24;
5
5
  export declare const NOTCH_H = 4;
6
+ /** Height of the placeholder drawn for a block whose definition is missing. */
7
+ export declare const MISSING_H = 24;
8
+ /** How far a mouth's chain is indented from the C-block's left edge. */
9
+ export declare const MOUTH_INDENT = 16;
10
+ /** Height of an empty mouth. */
11
+ export declare const MOUTH_MIN_H = 24;
12
+ /** Height of the bar between two mouths, which carries the second mouth's parameter name. */
13
+ export declare const MOUTH_DIVIDER_H = 24;
14
+ /** Height of the bar under the last mouth. */
15
+ export declare const MOUTH_FOOTER_H = 16;
6
16
  /** Height of each scope-output pill rendered in the event block's variable panel. */
7
17
  export declare const OUTPUT_PILL_H = 20;
8
18
  /**
@@ -12,6 +22,18 @@ export declare const OUTPUT_PILL_H = 20;
12
22
  export declare const OUTPUT_ROW_H = 26;
13
23
  /** Types whose shape already communicates the type; no text label needed. */
14
24
  export declare const PRIMITIVE_TYPES: Set<string>;
25
+ /** The size of an empty socket of the type. */
26
+ export declare function getSocketSize(type: ParamType): {
27
+ w: number;
28
+ h: number;
29
+ };
30
+ /**
31
+ * Whether a parameter of the block is drawn as a C-shaped mouth holding a chain of commands. Only command blocks have
32
+ * mouths; on a query or start block a command parameter stays a plain socket that nothing fits.
33
+ */
34
+ export declare function isCommandParam(def: BlockDefinition, param: BlockParam): boolean;
35
+ /** Whether the block has at least one mouth (and is drawn as a C-block). */
36
+ export declare function hasMouths(def: BlockDefinition): boolean;
15
37
  export interface SocketInfo {
16
38
  x: number;
17
39
  y: number;
@@ -19,11 +41,74 @@ export interface SocketInfo {
19
41
  h: number;
20
42
  type: ParamType;
21
43
  index: number;
44
+ /**
45
+ * An optional parameter that isn't added (its slot holds no text and no query): drawn as a small `[+] name` chip
46
+ * instead of a socket. It is still a socket: a fitting query dropped on it, or text typed into it, adds it.
47
+ */
48
+ collapsed: boolean;
22
49
  }
50
+ /** Height of the chip an optional parameter that isn't added is drawn as. */
51
+ export declare const CHIP_H = 18;
52
+ /** Whether a parameter is an optional one that isn't added: nothing is in its slot (empty text counts as nothing). */
53
+ export declare function isCollapsed(param: BlockParam, slot: ParamSlot | undefined): boolean;
54
+ /** The text on an optional parameter's chip. */
55
+ export declare function chipLabel(name: string): string;
56
+ export interface MouthInfo {
57
+ /** Index of the command parameter. */
58
+ index: number;
59
+ name: string;
60
+ /** Where the mouth's chain starts, relative to the block. */
61
+ x: number;
62
+ y: number;
63
+ h: number;
64
+ /** Top of the divider bar above the mouth (every mouth after the first has one), or null. */
65
+ dividerY: number | null;
66
+ }
67
+ /**
68
+ * The text cut with an ellipsis to fit inside a socket of the type and width: number (round caps) and boolean (pointed
69
+ * ends) sockets lose their ends (`w - h`), others a little padding.
70
+ */
71
+ export declare function fitLabel(text: string, socketType: ParamType, width: number): string;
72
+ /** A socket's (or mouth's) tooltip: its parameter's name and type. */
73
+ export declare function socketTitle(name: string, type: ParamType): string;
74
+ /** A parameter's tooltip: its name and type, and whether it is optional. */
75
+ export declare function paramTitle(param: BlockParam): string;
23
76
  /** Minimum pill width based on label text only (type is implicit in the query block itself). */
24
77
  export declare function getPillWidth(name: string): number;
25
- /** Width of a block, accounting for embedded query blocks in param slots */
78
+ /**
79
+ * Where a start block's context-variable pills go: side by side, one column each, in a single row below the header
80
+ * divider. Positions are relative to the block.
81
+ */
82
+ export declare function getPillPositions(def: BlockDefinition): {
83
+ id: string;
84
+ name: string;
85
+ x: number;
86
+ y: number;
87
+ w: number;
88
+ }[];
89
+ /** Width of a block, accounting for embedded query blocks in param slots. Mouths don't widen it. */
26
90
  export declare function getBlockWidth(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): number;
27
- export declare function getBlockHeight(def: BlockDefinition): number;
28
- /** Socket positions relative to block (x, y) */
91
+ /** Height of the header row: the label and the sockets. */
92
+ export declare function getHeaderHeight(def: BlockDefinition): number;
93
+ /**
94
+ * Height of a block. A C-block grows with the chains in its mouths (and so with mouths nested in them); without slots
95
+ * and blocks its mouths are empty.
96
+ */
97
+ export declare function getBlockHeight(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): number;
98
+ /** Height of a placed block, including a placeholder for a missing definition. */
99
+ export declare function getPlacedBlockHeight(block: PlacedBlock, allBlocks: Map<string, PlacedBlock>): number;
100
+ /** Height of the chain starting at `firstId`: its blocks stacked. */
101
+ export declare function getChainHeight(firstId: string, allBlocks: Map<string, PlacedBlock>): number;
102
+ /** The mouths of a C-block in parameter order, relative to the block. Empty for other blocks. */
103
+ export declare function getMouthPositions(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): MouthInfo[];
104
+ /** Socket positions relative to block (x, y). Mouths are not sockets. */
29
105
  export declare function getSocketPositions(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): SocketInfo[];
106
+ /**
107
+ * The absolute position of every block on the canvas. Roots (not chained, not embedded) sit at their own x/y; a chained
108
+ * block sits under its predecessor; a mouth's chain sits indented inside its host; an embedded query sits in its socket.
109
+ * The stored x/y of non-root blocks are not used.
110
+ */
111
+ export declare function computeLayout(allBlocks: Map<string, PlacedBlock>): Map<string, {
112
+ x: number;
113
+ y: number;
114
+ }>;
@@ -1,5 +1,14 @@
1
- import type { ParamType } from '../types';
1
+ import type { BlockDefinition, ParamSlot, ParamType, PlacedBlock } from '../types';
2
2
  export declare function commandBlockPath(w: number, h: number): string;
3
+ /**
4
+ * A C-block: a command block with a mouth per command parameter (`mouths`: their top and height, relative to the
5
+ * block). Each mouth's roof has an outlet tab for the first block of its chain, and its floor an inlet for the last
6
+ * block's tab, both `indent` in from the left edge. The block's own inlet and outlet sit where a command block's do.
7
+ */
8
+ export declare function cBlockPath(w: number, h: number, indent: number, mouths: {
9
+ y: number;
10
+ h: number;
11
+ }[]): string;
3
12
  export declare function hatBlockPath(w: number, h: number): string;
4
13
  export declare function numberQueryPath(w: number, h: number): string;
5
14
  export declare function boolQueryPath(w: number, h: number): string;
@@ -7,3 +16,5 @@ export declare function stringQueryPath(w: number, h: number): string;
7
16
  export declare function objectQueryPath(w: number, h: number): string;
8
17
  export declare function queryBlockPath(returnType: ParamType, w: number, h: number): string;
9
18
  export declare function socketPath(paramType: ParamType, w: number, h: number): string;
19
+ /** The outline of a block of the definition: a C-block's mouths sized to their chains (empty without slots and blocks). */
20
+ export declare function blockPath(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): string;
@@ -0,0 +1,17 @@
1
+ import type { PackageAction, PackageRef } from '../types';
2
+ /**
3
+ * Runs a Packages tab action: the host's `onClick`, or a change to the dependencies the action gives from the current
4
+ * ones (through `change`, as a change made in the tab).
5
+ */
6
+ export declare function runPackageAction(action: PackageAction, current: PackageRef[], change: (to: PackageRef[]) => void): void;
7
+ /** A package's identity regardless of version: `publisher/name`. */
8
+ export declare function packageKey(p: {
9
+ publisher: string;
10
+ name: string;
11
+ }): string;
12
+ /** The registry id under which a dependency (one version of a package) is loaded. */
13
+ export declare function dependencyPackageId(ref: PackageRef): string;
14
+ /** Registry ids of loaded dependencies start with this; other packages (the core, inline blocks) don't. */
15
+ export declare const DEPENDENCY_PREFIX = "dep:";
16
+ /** Compare dotted versions numerically (prerelease suffixes compare as strings). */
17
+ export declare function compareVersions(a: string, b: string): number;
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Settings in localStorage, where it is available: it throws in some contexts (sandboxed frames, some automation and
3
+ * privacy settings), and a setting is never worth failing for.
4
+ */
5
+ export declare function readSetting(key: string): string | null;
6
+ export declare function writeSetting(key: string, value: string): void;
package/package.json CHANGED
@@ -1,6 +1,13 @@
1
1
  {
2
2
  "name": "@tvolden/block-code-editor",
3
- "version": "0.1.1",
3
+ "version": "0.3.0",
4
+ "description": "A visual block programming editor for React, with command-sourced canvases for collaboration",
5
+ "license": "MIT",
6
+ "author": "Thomas Volden",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "git+https://github.com/TVolden/block-code-editor.git"
10
+ },
4
11
  "type": "module",
5
12
  "main": "./dist/block-editor.cjs",
6
13
  "module": "./dist/block-editor.js",
@@ -21,6 +28,7 @@
21
28
  "build:app": "tsc -b && vite build",
22
29
  "build:embed": "tsc -b && vite build --config vite.embed.config.ts",
23
30
  "lint": "eslint .",
31
+ "test": "vitest run",
24
32
  "preview": "vite preview"
25
33
  },
26
34
  "peerDependencies": {
@@ -43,6 +51,7 @@
43
51
  "tailwindcss": "^4.1.18",
44
52
  "typescript": "~5.9.3",
45
53
  "typescript-eslint": "^8.48.0",
46
- "vite": "^7.3.1"
54
+ "vite": "^7.3.8",
55
+ "vitest": "^5.1.0"
47
56
  }
48
57
  }
@@ -1,10 +0,0 @@
1
- import type { CardDesign } from './cardDesignTypes';
2
- interface Props {
3
- design: CardDesign;
4
- selectedId: string | null;
5
- onSelect: (id: string | null) => void;
6
- onMove: (id: string, x: number, y: number) => void;
7
- onResize: (id: string, x: number, y: number, w: number, h: number) => void;
8
- }
9
- export default function CardCanvas({ design, selectedId, onSelect, onMove, onResize }: Props): import("react/jsx-runtime").JSX.Element;
10
- export {};
@@ -1,47 +0,0 @@
1
- import React from 'react';
2
- import type { Theme, ThemeId } from '../theme';
3
- import type { CardDesign } from './cardDesignTypes';
4
- interface Props {
5
- onThemeChange?: (t: Theme) => void;
6
- navTabs?: React.ReactNode;
7
- /**
8
- * When provided, the designer syncs its theme to the platform's theme and
9
- * sets up its own ThemeContext.Provider (enabling standalone use outside
10
- * of the editor's App shell).
11
- */
12
- themeId?: ThemeId;
13
- /** When true, the built-in title bar is not rendered. */
14
- hideTitleBar?: boolean;
15
- /**
16
- * When true, only the left meta panel is rendered (no card canvas or
17
- * element-properties panel). Width shrinks to match the panel.
18
- */
19
- compactMode?: boolean;
20
- /**
21
- * When true, only the canvas and element-properties panel are rendered
22
- * (no title bar, no meta panel). The component expands to fill available
23
- * space. Combine with compactMode on a sibling instance and shared
24
- * controlled state to split the designer into a persistent left panel and
25
- * a tab-conditional workspace.
26
- */
27
- workspaceOnly?: boolean;
28
- /** External design state. When provided the component is controlled. */
29
- design?: CardDesign;
30
- onDesignChange?: (design: CardDesign) => void;
31
- /** External selection state. Used together with design for controlled mode. */
32
- selectedId?: string | null;
33
- onSelectedIdChange?: (id: string | null) => void;
34
- /**
35
- * When provided, replaces the built-in JSON export with a custom handler
36
- * (e.g. YAML export with combined block-program state from the platform).
37
- */
38
- onExport?: () => void;
39
- /**
40
- * When provided, replaces the built-in JSON import with a custom handler.
41
- * The handler is responsible for opening a file picker and calling
42
- * onDesignChange with the loaded design.
43
- */
44
- onImport?: () => void;
45
- }
46
- export default function CardDesigner({ onThemeChange, navTabs, themeId, hideTitleBar, compactMode, workspaceOnly, design: externalDesign, onDesignChange, selectedId: externalSelectedId, onSelectedIdChange, onExport, onImport, }: Props): import("react/jsx-runtime").JSX.Element;
47
- export {};
@@ -1,11 +0,0 @@
1
- import React from 'react';
2
- import type { CardDesign } from './cardDesignTypes';
3
- interface Props {
4
- design: CardDesign;
5
- /** Unique string used to scope SVG filter/clip IDs — pass the card's id. */
6
- uid: string;
7
- style?: React.CSSProperties;
8
- className?: string;
9
- }
10
- export default function CardPreview({ design, uid, style, className }: Props): import("react/jsx-runtime").JSX.Element;
11
- export {};
@@ -1,85 +0,0 @@
1
- export interface TextEl {
2
- id: string;
3
- type: 'text';
4
- x: number;
5
- y: number;
6
- w: number;
7
- h: number;
8
- content: string;
9
- fontSize: number;
10
- fontWeight: 'normal' | 'bold';
11
- fontStyle: 'normal' | 'italic';
12
- color: string;
13
- align: 'left' | 'center' | 'right';
14
- }
15
- export interface ImageEl {
16
- id: string;
17
- type: 'image';
18
- x: number;
19
- y: number;
20
- w: number;
21
- h: number;
22
- /** https URL or base-64 data URI */
23
- src: string;
24
- }
25
- export interface RectEl {
26
- id: string;
27
- type: 'rectangle';
28
- x: number;
29
- y: number;
30
- w: number;
31
- h: number;
32
- fill: string;
33
- stroke: string;
34
- strokeWidth: number;
35
- rx: number;
36
- }
37
- export interface CircleEl {
38
- id: string;
39
- type: 'circle';
40
- x: number;
41
- y: number;
42
- w: number;
43
- h: number;
44
- fill: string;
45
- stroke: string;
46
- strokeWidth: number;
47
- }
48
- export type CardElement = TextEl | ImageEl | RectEl | CircleEl;
49
- export interface CustomField {
50
- key: string;
51
- value: string;
52
- }
53
- export interface CardMeta {
54
- name: string;
55
- description: string;
56
- cardType: string;
57
- /** comma-separated */
58
- tags: string;
59
- /** User-defined extra key/value pairs */
60
- customFields: CustomField[];
61
- }
62
- export interface CardDesign {
63
- version: '1';
64
- meta: CardMeta;
65
- background: {
66
- color: string;
67
- imageUrl: string;
68
- };
69
- elements: CardElement[];
70
- }
71
- /** Physical card dimensions inside the SVG canvas (px). */
72
- export declare const CARD_W = 280;
73
- export declare const CARD_H = 392;
74
- export declare const CARD_RX = 16;
75
- /** Padding around the card inside the SVG viewport. */
76
- export declare const SVG_PAD = 48;
77
- export declare function defaultCardDesign(): CardDesign;
78
- export declare function genId(): string;
79
- /**
80
- * Replaces {{key}} placeholders in `text` with values from `meta`.
81
- * Built-in keys: name, description, type, tags.
82
- * Custom fields are matched by their key. All matching is case-insensitive.
83
- * Unknown keys are left as-is.
84
- */
85
- export declare function interpolateMeta(text: string, meta: CardMeta): string;
@@ -1,23 +0,0 @@
1
- [
2
- {
3
- "id": "hand-limit",
4
- "name": "Hand Limit",
5
- "description": "Enforce and inspect player hand size limits",
6
- "url": "/packages/hand-limit.json",
7
- "builtIn": false
8
- },
9
- {
10
- "id": "scoring",
11
- "name": "Scoring",
12
- "description": "Score tracking, point awards, and leaderboard queries",
13
- "url": "/packages/scoring.json",
14
- "builtIn": false
15
- },
16
- {
17
- "id": "motion-ops",
18
- "name": "Motion & Operators",
19
- "description": "General-purpose motion, control flow, and math operators",
20
- "url": "/packages/motion-ops.json",
21
- "builtIn": false
22
- }
23
- ]