@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.
- package/LICENSE +21 -0
- package/README.md +41 -0
- package/dist/block-editor.cjs +9 -1
- package/dist/block-editor.js +2147 -2101
- package/dist/blockRegistry.d.ts +9 -2
- package/dist/collaboration/presence.d.ts +23 -0
- package/dist/collaboration/sync.d.ts +71 -0
- package/dist/collaboration/types.d.ts +93 -0
- package/dist/commands/apply.d.ts +18 -0
- package/dist/commands/build.d.ts +31 -0
- package/dist/commands/index.d.ts +4 -0
- package/dist/commands/invert.d.ts +6 -0
- package/dist/commands/types.d.ts +84 -0
- package/dist/components/BlockPalette.d.ts +4 -5
- package/dist/components/BlockRenderer.d.ts +12 -2
- package/dist/components/Canvas.d.ts +6 -0
- package/dist/components/ExportMenu.d.ts +6 -0
- package/dist/components/MouthDecorations.d.ts +13 -0
- package/dist/components/PackagesTab.d.ts +20 -0
- package/dist/components/PeersOverlay.d.ts +14 -0
- package/dist/components/SocketHint.d.ts +11 -0
- package/dist/components/UndoRedoBar.d.ts +11 -0
- package/dist/demo/LocalServer.d.ts +38 -0
- package/dist/demo/pythonWriter.d.ts +6 -0
- package/dist/editor/BlockEditor.d.ts +27 -6
- package/dist/editor/activeEditor.d.ts +12 -0
- package/dist/export/program.d.ts +55 -0
- package/dist/index.d.ts +10 -5
- package/dist/types.d.ts +39 -0
- package/dist/utils/blockLayout.d.ts +60 -4
- package/dist/utils/blockShapes.d.ts +12 -1
- package/dist/utils/packages.d.ts +17 -0
- package/dist/utils/storage.d.ts +6 -0
- package/package.json +11 -2
- package/dist/carddesigner/CardCanvas.d.ts +0 -10
- package/dist/carddesigner/CardDesigner.d.ts +0 -47
- package/dist/carddesigner/CardPreview.d.ts +0 -11
- package/dist/carddesigner/cardDesignTypes.d.ts +0 -85
- package/dist/packages.json +0 -23
|
@@ -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 {
|
|
5
|
-
export {
|
|
6
|
-
export type {
|
|
7
|
-
export {
|
|
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,6 +1,8 @@
|
|
|
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;
|
|
@@ -23,6 +25,11 @@ export interface BlockDefinition {
|
|
|
23
25
|
name: string;
|
|
24
26
|
blockType: BlockType;
|
|
25
27
|
returnType?: ParamType;
|
|
28
|
+
/**
|
|
29
|
+
* 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
|
|
30
|
+
* a 'CardCollection', or an 'int' that is a 'double').
|
|
31
|
+
*/
|
|
32
|
+
usableAs?: ParamType[];
|
|
26
33
|
params: BlockParam[];
|
|
27
34
|
/** Context queries this event guarantees are valid. Only meaningful on start blocks. */
|
|
28
35
|
provides?: BlockProvide[];
|
|
@@ -32,6 +39,12 @@ export interface BlockDefinition {
|
|
|
32
39
|
export interface ParamSlot {
|
|
33
40
|
textValue: string | null;
|
|
34
41
|
queryBlockId: string | null;
|
|
42
|
+
/**
|
|
43
|
+
* For a command parameter of a command block (a C-shaped mouth): the first block of the chain it holds, or null when
|
|
44
|
+
* empty. That block has `embeddedInBlockId` = the host and `embeddedSlotIndex` = the parameter's index; the blocks after
|
|
45
|
+
* it are linked by `nextBlockId` / `parentBlockId` as in any chain. Optional, so canvases saved before mouths load.
|
|
46
|
+
*/
|
|
47
|
+
commandBlockId?: string | null;
|
|
35
48
|
}
|
|
36
49
|
export interface PlacedBlock {
|
|
37
50
|
instanceId: string;
|
|
@@ -44,6 +57,32 @@ export interface PlacedBlock {
|
|
|
44
57
|
embeddedSlotIndex: number;
|
|
45
58
|
paramSlots: ParamSlot[];
|
|
46
59
|
}
|
|
60
|
+
/** One version of a block package that a canvas depends on. */
|
|
61
|
+
export interface PackageRef {
|
|
62
|
+
publisher: string;
|
|
63
|
+
name: string;
|
|
64
|
+
version: string;
|
|
65
|
+
}
|
|
66
|
+
/** A package that may be added in the Packages tab, at the version adding it pins (normally the newest listed). */
|
|
67
|
+
export interface CatalogPackage extends PackageRef {
|
|
68
|
+
description?: string;
|
|
69
|
+
/** Shown as a swatch next to the package. */
|
|
70
|
+
color?: string;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* An extra button in the Packages tab, e.g. "Import game packages". It either runs the host's `onClick`, or gives the
|
|
74
|
+
* dependencies to change to (`dependencies`, from the current ones): a user action like a change made in the tab,
|
|
75
|
+
* so it is undoable and, when command-sourced, submitted.
|
|
76
|
+
*/
|
|
77
|
+
export type PackageAction = {
|
|
78
|
+
label: string;
|
|
79
|
+
title?: string;
|
|
80
|
+
onClick: () => void;
|
|
81
|
+
} | {
|
|
82
|
+
label: string;
|
|
83
|
+
title?: string;
|
|
84
|
+
dependencies: (current: PackageRef[]) => PackageRef[];
|
|
85
|
+
};
|
|
47
86
|
/**
|
|
48
87
|
* Serialized form of the block canvas — safe to JSON.stringify/parse and
|
|
49
88
|
* 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,13 @@ 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
|
+
/**
|
|
26
|
+
* Whether a parameter of the block is drawn as a C-shaped mouth holding a chain of commands. Only command blocks have
|
|
27
|
+
* mouths; on a query or start block a command parameter stays a plain socket that nothing fits.
|
|
28
|
+
*/
|
|
29
|
+
export declare function isCommandParam(def: BlockDefinition, param: BlockParam): boolean;
|
|
30
|
+
/** Whether the block has at least one mouth (and is drawn as a C-block). */
|
|
31
|
+
export declare function hasMouths(def: BlockDefinition): boolean;
|
|
15
32
|
export interface SocketInfo {
|
|
16
33
|
x: number;
|
|
17
34
|
y: number;
|
|
@@ -20,10 +37,49 @@ export interface SocketInfo {
|
|
|
20
37
|
type: ParamType;
|
|
21
38
|
index: number;
|
|
22
39
|
}
|
|
40
|
+
export interface MouthInfo {
|
|
41
|
+
/** Index of the command parameter. */
|
|
42
|
+
index: number;
|
|
43
|
+
name: string;
|
|
44
|
+
/** Where the mouth's chain starts, relative to the block. */
|
|
45
|
+
x: number;
|
|
46
|
+
y: number;
|
|
47
|
+
h: number;
|
|
48
|
+
/** Top of the divider bar above the mouth (every mouth after the first has one), or null. */
|
|
49
|
+
dividerY: number | null;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* The text cut with an ellipsis to fit inside a socket of the type and width: number (round caps) and boolean (pointed
|
|
53
|
+
* ends) sockets lose their ends (`w - h`), others a little padding.
|
|
54
|
+
*/
|
|
55
|
+
export declare function fitLabel(text: string, socketType: ParamType, width: number): string;
|
|
56
|
+
/** A socket's (or mouth's) tooltip: its parameter's name and type. */
|
|
57
|
+
export declare function socketTitle(name: string, type: ParamType): string;
|
|
23
58
|
/** Minimum pill width based on label text only (type is implicit in the query block itself). */
|
|
24
59
|
export declare function getPillWidth(name: string): number;
|
|
25
|
-
/** Width of a block, accounting for embedded query blocks in param slots */
|
|
60
|
+
/** Width of a block, accounting for embedded query blocks in param slots. Mouths don't widen it. */
|
|
26
61
|
export declare function getBlockWidth(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): number;
|
|
27
|
-
|
|
28
|
-
|
|
62
|
+
/** Height of the header row: the label and the sockets. */
|
|
63
|
+
export declare function getHeaderHeight(def: BlockDefinition): number;
|
|
64
|
+
/**
|
|
65
|
+
* Height of a block. A C-block grows with the chains in its mouths (and so with mouths nested in them); without slots
|
|
66
|
+
* and blocks its mouths are empty.
|
|
67
|
+
*/
|
|
68
|
+
export declare function getBlockHeight(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): number;
|
|
69
|
+
/** Height of a placed block, including a placeholder for a missing definition. */
|
|
70
|
+
export declare function getPlacedBlockHeight(block: PlacedBlock, allBlocks: Map<string, PlacedBlock>): number;
|
|
71
|
+
/** Height of the chain starting at `firstId`: its blocks stacked. */
|
|
72
|
+
export declare function getChainHeight(firstId: string, allBlocks: Map<string, PlacedBlock>): number;
|
|
73
|
+
/** The mouths of a C-block in parameter order, relative to the block. Empty for other blocks. */
|
|
74
|
+
export declare function getMouthPositions(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): MouthInfo[];
|
|
75
|
+
/** Socket positions relative to block (x, y). Mouths are not sockets. */
|
|
29
76
|
export declare function getSocketPositions(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): SocketInfo[];
|
|
77
|
+
/**
|
|
78
|
+
* The absolute position of every block on the canvas. Roots (not chained, not embedded) sit at their own x/y; a chained
|
|
79
|
+
* block sits under its predecessor; a mouth's chain sits indented inside its host; an embedded query sits in its socket.
|
|
80
|
+
* The stored x/y of non-root blocks are not used.
|
|
81
|
+
*/
|
|
82
|
+
export declare function computeLayout(allBlocks: Map<string, PlacedBlock>): Map<string, {
|
|
83
|
+
x: number;
|
|
84
|
+
y: number;
|
|
85
|
+
}>;
|
|
@@ -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.
|
|
3
|
+
"version": "0.2.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.
|
|
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;
|
package/dist/packages.json
DELETED
|
@@ -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
|
-
]
|