@tvolden/block-code-editor 0.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.
@@ -0,0 +1,85 @@
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;
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import type { PackageInfo, LoadedPackage } from '../blockRegistry';
3
+ interface Props {
4
+ onPointerDown: (e: React.PointerEvent, definitionId: string) => void;
5
+ isDropTarget?: boolean;
6
+ registryVersion: number;
7
+ availablePackages: PackageInfo[];
8
+ loadedPackages: LoadedPackage[];
9
+ onPackageToggle: (pkg: PackageInfo, currentlyLoaded: boolean) => Promise<void>;
10
+ /** Definition IDs of start (event) blocks already placed on the canvas. */
11
+ placedStartIds: Set<string>;
12
+ }
13
+ export default function BlockPalette({ onPointerDown, isDropTarget, registryVersion, availablePackages, loadedPackages, onPackageToggle, placedStartIds, }: Props): import("react/jsx-runtime").JSX.Element;
14
+ export {};
@@ -0,0 +1,22 @@
1
+ import React from 'react';
2
+ import type { PlacedBlock } from '../types';
3
+ interface Props {
4
+ block: PlacedBlock;
5
+ allBlocks: Map<string, PlacedBlock>;
6
+ onPointerDown?: (e: React.PointerEvent, id: string) => void;
7
+ onBlockClick?: (id: string) => void;
8
+ onSocketClick?: (blockId: string, slotIndex: number) => void;
9
+ editingSocket?: {
10
+ blockId: string;
11
+ slotIndex: number;
12
+ } | null;
13
+ onSocketCommit?: (blockId: string, slotIndex: number, value: string) => void;
14
+ onSocketCancelEdit?: () => void;
15
+ /** Called when the user starts dragging an output pill from a start block. */
16
+ onOutputDrag?: (e: React.PointerEvent, defId: string) => void;
17
+ isGhost?: boolean;
18
+ isDragging?: boolean;
19
+ embedded?: boolean;
20
+ }
21
+ export declare function BlockRenderer({ block, allBlocks, onPointerDown, onBlockClick, onSocketClick, editingSocket, onSocketCommit, onSocketCancelEdit, onOutputDrag, isGhost, isDragging, embedded, }: Props): import("react/jsx-runtime").JSX.Element;
22
+ export {};
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import type { PlacedBlock } from '../types';
3
+ interface Props {
4
+ blocks: Map<string, PlacedBlock>;
5
+ draggingIds: Set<string>;
6
+ onBlockPointerDown: (e: React.PointerEvent, id: string) => void;
7
+ onBlockClick: (id: string) => void;
8
+ onSocketClick: (blockId: string, slotIndex: number) => void;
9
+ editingSocket?: {
10
+ blockId: string;
11
+ slotIndex: number;
12
+ } | null;
13
+ onSocketCommit?: (blockId: string, slotIndex: number, value: string) => void;
14
+ onSocketCancelEdit?: () => void;
15
+ onOutputDrag: (e: React.PointerEvent, defId: string) => void;
16
+ }
17
+ declare const Canvas: React.ForwardRefExoticComponent<Props & React.RefAttributes<SVGSVGElement>>;
18
+ export default Canvas;
@@ -0,0 +1,6 @@
1
+ import type { Theme } from '../theme';
2
+ interface Props {
3
+ onSelect: (t: Theme) => void;
4
+ }
5
+ export default function ThemeSwitcher({ onSelect }: Props): import("react/jsx-runtime").JSX.Element;
6
+ export {};
@@ -0,0 +1,54 @@
1
+ /**
2
+ * BlockEditor.tsx
3
+ *
4
+ * The self-contained block editor: palette on the left, canvas on the right.
5
+ * Does NOT include the output console — use the `onRun` callback to handle
6
+ * sequence output however you like (display in a console, fire an event, etc.)
7
+ *
8
+ * Props:
9
+ * blocksUrl — URL for blocks.json (default: '/blocks.json')
10
+ * onRun — called with an ordered list of output lines when the user
11
+ * clicks a block sequence
12
+ */
13
+ import React from 'react';
14
+ import type { SerializedCanvas } from '../types';
15
+ 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
+ import type { Theme, ThemeId } from '../theme';
21
+ interface Props {
22
+ blocksUrl?: string;
23
+ /** Load multiple block packages in order. Takes precedence over blocksUrl. */
24
+ blocksUrls?: string[];
25
+ onRun?: (lines: string[]) => void;
26
+ onThemeChange?: (theme: Theme) => void;
27
+ /** Optional nav tabs rendered in the title bar between the subtitle and theme switcher. */
28
+ navTabs?: React.ReactNode;
29
+ /** Pre-populate the canvas from a previously serialized state. */
30
+ initialState?: SerializedCanvas;
31
+ /** Called with the current canvas state when the user clicks Save. */
32
+ onSave?: (state: SerializedCanvas) => void;
33
+ /**
34
+ * When provided, the editor runs in controlled-theme mode: it applies this
35
+ * theme and hides the built-in theme-switcher buttons. The platform is then
36
+ * responsible for toggling dark/light.
37
+ */
38
+ themeId?: ThemeId;
39
+ /** When true, the built-in title bar is not rendered. */
40
+ hideTitleBar?: boolean;
41
+ /**
42
+ * When provided, the ref is populated with a function that returns the
43
+ * current canvas state. Lets a parent component read state on demand
44
+ * (e.g. to implement its own Save button).
45
+ */
46
+ getStateRef?: React.MutableRefObject<(() => SerializedCanvas) | null>;
47
+ /**
48
+ * Extra block definitions injected into the registry after the core blocks
49
+ * load. Registered under the synthetic package '__inline__'. Changing this
50
+ * prop unregisters the previous set and registers the new one.
51
+ */
52
+ additionalBlocks?: import('../types').BlockDefinition[];
53
+ }
54
+ export default function BlockEditor({ blocksUrl, blocksUrls, onRun, onThemeChange, navTabs, initialState, onSave, themeId, hideTitleBar, getStateRef, additionalBlocks }: Props): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,7 @@
1
+ export { default } from './editor/BlockEditor';
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';
@@ -0,0 +1,67 @@
1
+ [
2
+ {
3
+ "id": "hl-set-limit",
4
+ "name": "Set Hand Limit",
5
+ "blockType": "command",
6
+ "params": [
7
+ { "name": "player", "type": "Player" },
8
+ { "name": "limit", "type": "number" }
9
+ ],
10
+ "category": "Hand Limit",
11
+ "color": "#7A3C1C"
12
+ },
13
+ {
14
+ "id": "hl-enforce",
15
+ "name": "Enforce Limit",
16
+ "blockType": "command",
17
+ "params": [
18
+ { "name": "player", "type": "Player" }
19
+ ],
20
+ "category": "Hand Limit",
21
+ "color": "#7A3C1C"
22
+ },
23
+ {
24
+ "id": "hl-discard-to",
25
+ "name": "Discard To Limit",
26
+ "blockType": "command",
27
+ "params": [
28
+ { "name": "player", "type": "Player" },
29
+ { "name": "deck", "type": "Deck" }
30
+ ],
31
+ "category": "Hand Limit",
32
+ "color": "#7A3C1C"
33
+ },
34
+ {
35
+ "id": "hl-get-limit",
36
+ "name": "Hand Limit",
37
+ "blockType": "query",
38
+ "returnType": "number",
39
+ "params": [
40
+ { "name": "player", "type": "Player" }
41
+ ],
42
+ "category": "Hand Limit",
43
+ "color": "#7A3C1C"
44
+ },
45
+ {
46
+ "id": "hl-hand-size",
47
+ "name": "Hand Size",
48
+ "blockType": "query",
49
+ "returnType": "number",
50
+ "params": [
51
+ { "name": "player", "type": "Player" }
52
+ ],
53
+ "category": "Hand Limit",
54
+ "color": "#7A3C1C"
55
+ },
56
+ {
57
+ "id": "hl-over-limit",
58
+ "name": "Over Limit?",
59
+ "blockType": "query",
60
+ "returnType": "boolean",
61
+ "params": [
62
+ { "name": "player", "type": "Player" }
63
+ ],
64
+ "category": "Hand Limit",
65
+ "color": "#7A3C1C"
66
+ }
67
+ ]
@@ -0,0 +1,246 @@
1
+ [
2
+ {
3
+ "id": "move",
4
+ "name": "Move",
5
+ "blockType": "command",
6
+ "params": [{ "name": "steps", "type": "number" }],
7
+ "category": "Motion",
8
+ "color": "#4C97FF"
9
+ },
10
+ {
11
+ "id": "turn-cw",
12
+ "name": "Turn CW",
13
+ "blockType": "command",
14
+ "params": [{ "name": "degrees", "type": "number" }],
15
+ "category": "Motion",
16
+ "color": "#4C97FF"
17
+ },
18
+ {
19
+ "id": "go-to",
20
+ "name": "Go To",
21
+ "blockType": "command",
22
+ "params": [
23
+ { "name": "x", "type": "number" },
24
+ { "name": "y", "type": "number" }
25
+ ],
26
+ "category": "Motion",
27
+ "color": "#4C97FF"
28
+ },
29
+ {
30
+ "id": "point-dir",
31
+ "name": "Point Dir",
32
+ "blockType": "command",
33
+ "params": [{ "name": "dir", "type": "number" }],
34
+ "category": "Motion",
35
+ "color": "#4C97FF"
36
+ },
37
+ {
38
+ "id": "say",
39
+ "name": "Say",
40
+ "blockType": "command",
41
+ "params": [{ "name": "message", "type": "string" }],
42
+ "category": "Looks",
43
+ "color": "#9966FF"
44
+ },
45
+ {
46
+ "id": "show",
47
+ "name": "Show",
48
+ "blockType": "command",
49
+ "params": [],
50
+ "category": "Looks",
51
+ "color": "#9966FF"
52
+ },
53
+ {
54
+ "id": "hide",
55
+ "name": "Hide",
56
+ "blockType": "command",
57
+ "params": [],
58
+ "category": "Looks",
59
+ "color": "#9966FF"
60
+ },
61
+ {
62
+ "id": "set-color",
63
+ "name": "Set Color",
64
+ "blockType": "command",
65
+ "params": [{ "name": "color", "type": "string" }],
66
+ "category": "Looks",
67
+ "color": "#9966FF"
68
+ },
69
+ {
70
+ "id": "wait",
71
+ "name": "Wait",
72
+ "blockType": "command",
73
+ "params": [{ "name": "secs", "type": "number" }],
74
+ "category": "Control",
75
+ "color": "#FFAB19"
76
+ },
77
+ {
78
+ "id": "repeat",
79
+ "name": "Repeat",
80
+ "blockType": "command",
81
+ "params": [{ "name": "times", "type": "number" }],
82
+ "category": "Control",
83
+ "color": "#FFAB19"
84
+ },
85
+ {
86
+ "id": "if",
87
+ "name": "If",
88
+ "blockType": "command",
89
+ "params": [{ "name": "cond", "type": "boolean" }],
90
+ "category": "Control",
91
+ "color": "#FFAB19"
92
+ },
93
+ {
94
+ "id": "x-position",
95
+ "name": "X Position",
96
+ "blockType": "query",
97
+ "returnType": "number",
98
+ "params": [],
99
+ "category": "Sensing",
100
+ "color": "#5CB1D6"
101
+ },
102
+ {
103
+ "id": "y-position",
104
+ "name": "Y Position",
105
+ "blockType": "query",
106
+ "returnType": "number",
107
+ "params": [],
108
+ "category": "Sensing",
109
+ "color": "#5CB1D6"
110
+ },
111
+ {
112
+ "id": "direction",
113
+ "name": "Direction",
114
+ "blockType": "query",
115
+ "returnType": "number",
116
+ "params": [],
117
+ "category": "Sensing",
118
+ "color": "#5CB1D6"
119
+ },
120
+ {
121
+ "id": "timer",
122
+ "name": "Timer",
123
+ "blockType": "query",
124
+ "returnType": "number",
125
+ "params": [],
126
+ "category": "Sensing",
127
+ "color": "#5CB1D6"
128
+ },
129
+ {
130
+ "id": "is-touching",
131
+ "name": "Is Touching",
132
+ "blockType": "query",
133
+ "returnType": "boolean",
134
+ "params": [{ "name": "obj", "type": "object" }],
135
+ "category": "Sensing",
136
+ "color": "#5CB1D6"
137
+ },
138
+ {
139
+ "id": "key-pressed",
140
+ "name": "Key Pressed",
141
+ "blockType": "query",
142
+ "returnType": "boolean",
143
+ "params": [{ "name": "key", "type": "string" }],
144
+ "category": "Sensing",
145
+ "color": "#5CB1D6"
146
+ },
147
+ {
148
+ "id": "get-name",
149
+ "name": "Get Name",
150
+ "blockType": "query",
151
+ "returnType": "string",
152
+ "params": [],
153
+ "category": "Sensing",
154
+ "color": "#5CB1D6"
155
+ },
156
+ {
157
+ "id": "get-self",
158
+ "name": "Get Self",
159
+ "blockType": "query",
160
+ "returnType": "object",
161
+ "params": [],
162
+ "category": "Sensing",
163
+ "color": "#5CB1D6"
164
+ },
165
+ {
166
+ "id": "add",
167
+ "name": "Add",
168
+ "blockType": "query",
169
+ "returnType": "number",
170
+ "params": [
171
+ { "name": "a", "type": "number" },
172
+ { "name": "b", "type": "number" }
173
+ ],
174
+ "category": "Operators",
175
+ "color": "#59C059"
176
+ },
177
+ {
178
+ "id": "subtract",
179
+ "name": "Subtract",
180
+ "blockType": "query",
181
+ "returnType": "number",
182
+ "params": [
183
+ { "name": "a", "type": "number" },
184
+ { "name": "b", "type": "number" }
185
+ ],
186
+ "category": "Operators",
187
+ "color": "#59C059"
188
+ },
189
+ {
190
+ "id": "multiply",
191
+ "name": "Multiply",
192
+ "blockType": "query",
193
+ "returnType": "number",
194
+ "params": [
195
+ { "name": "a", "type": "number" },
196
+ { "name": "b", "type": "number" }
197
+ ],
198
+ "category": "Operators",
199
+ "color": "#59C059"
200
+ },
201
+ {
202
+ "id": "and",
203
+ "name": "And",
204
+ "blockType": "query",
205
+ "returnType": "boolean",
206
+ "params": [
207
+ { "name": "a", "type": "boolean" },
208
+ { "name": "b", "type": "boolean" }
209
+ ],
210
+ "category": "Operators",
211
+ "color": "#59C059"
212
+ },
213
+ {
214
+ "id": "or",
215
+ "name": "Or",
216
+ "blockType": "query",
217
+ "returnType": "boolean",
218
+ "params": [
219
+ { "name": "a", "type": "boolean" },
220
+ { "name": "b", "type": "boolean" }
221
+ ],
222
+ "category": "Operators",
223
+ "color": "#59C059"
224
+ },
225
+ {
226
+ "id": "not",
227
+ "name": "Not",
228
+ "blockType": "query",
229
+ "returnType": "boolean",
230
+ "params": [{ "name": "cond", "type": "boolean" }],
231
+ "category": "Operators",
232
+ "color": "#59C059"
233
+ },
234
+ {
235
+ "id": "join",
236
+ "name": "Join",
237
+ "blockType": "query",
238
+ "returnType": "string",
239
+ "params": [
240
+ { "name": "a", "type": "string" },
241
+ { "name": "b", "type": "string" }
242
+ ],
243
+ "category": "Operators",
244
+ "color": "#59C059"
245
+ }
246
+ ]
@@ -0,0 +1,66 @@
1
+ [
2
+ {
3
+ "id": "sc-award-points",
4
+ "name": "Award Points",
5
+ "blockType": "command",
6
+ "params": [
7
+ { "name": "player", "type": "Player" },
8
+ { "name": "amount", "type": "number" }
9
+ ],
10
+ "category": "Scoring",
11
+ "color": "#7A1C5A"
12
+ },
13
+ {
14
+ "id": "sc-deduct-points",
15
+ "name": "Deduct Points",
16
+ "blockType": "command",
17
+ "params": [
18
+ { "name": "player", "type": "Player" },
19
+ { "name": "amount", "type": "number" }
20
+ ],
21
+ "category": "Scoring",
22
+ "color": "#7A1C5A"
23
+ },
24
+ {
25
+ "id": "sc-reset-score",
26
+ "name": "Reset Score",
27
+ "blockType": "command",
28
+ "params": [
29
+ { "name": "player", "type": "Player" }
30
+ ],
31
+ "category": "Scoring",
32
+ "color": "#7A1C5A"
33
+ },
34
+ {
35
+ "id": "sc-get-score",
36
+ "name": "Score",
37
+ "blockType": "query",
38
+ "returnType": "number",
39
+ "params": [
40
+ { "name": "player", "type": "Player" }
41
+ ],
42
+ "category": "Scoring",
43
+ "color": "#7A1C5A"
44
+ },
45
+ {
46
+ "id": "sc-leading",
47
+ "name": "Leading Player",
48
+ "blockType": "query",
49
+ "returnType": "Player",
50
+ "params": [],
51
+ "category": "Scoring",
52
+ "color": "#7A1C5A"
53
+ },
54
+ {
55
+ "id": "sc-score-gt",
56
+ "name": "Score Greater?",
57
+ "blockType": "query",
58
+ "returnType": "boolean",
59
+ "params": [
60
+ { "name": "player", "type": "Player" },
61
+ { "name": "amount", "type": "number" }
62
+ ],
63
+ "category": "Scoring",
64
+ "color": "#7A1C5A"
65
+ }
66
+ ]
@@ -0,0 +1,23 @@
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
+ ]
@@ -0,0 +1,48 @@
1
+ export type ThemeId = 'dark' | 'light';
2
+ export interface Theme {
3
+ id: ThemeId;
4
+ label: string;
5
+ appBg: string;
6
+ paletteBg: string;
7
+ paletteHeaderBg: string;
8
+ canvasBg: string;
9
+ consoleBg: string;
10
+ consoleHeaderBg: string;
11
+ border: string;
12
+ accent: string;
13
+ textPrimary: string;
14
+ textSecondary: string;
15
+ textMuted: string;
16
+ inputBg: string;
17
+ inputBorder: string;
18
+ gridDot: string;
19
+ blockBody: string;
20
+ blockBorder: string;
21
+ blockText: string;
22
+ socketBody: string;
23
+ consoleOutput: string;
24
+ consoleSeparator: string;
25
+ deleteBorder: string;
26
+ deleteText: string;
27
+ deleteActiveBg: string;
28
+ deleteActiveBorder: string;
29
+ deleteActiveText: string;
30
+ titleBg: string;
31
+ titlePrimaryText: string;
32
+ titleSecondaryText: string;
33
+ pkgBg: string;
34
+ pkgBorder: string;
35
+ pkgActiveBg: string;
36
+ pkgActiveBorder: string;
37
+ pkgText: string;
38
+ pkgActiveText: string;
39
+ pkgSubText: string;
40
+ switcherBg: string;
41
+ switcherActiveBg: string;
42
+ switcherText: string;
43
+ switcherActiveText: string;
44
+ switcherBorder: string;
45
+ }
46
+ export declare const darkTheme: Theme;
47
+ export declare const proTheme: Theme;
48
+ export declare const THEMES: Theme[];