@tvolden/block-code-editor 0.2.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -0
- package/dist/block-editor.cjs +4 -4
- package/dist/block-editor.js +1569 -1312
- package/dist/blocks.json +47 -2
- package/dist/commands/build.d.ts +5 -0
- package/dist/components/BlockRenderer.d.ts +6 -0
- package/dist/components/Canvas.d.ts +6 -0
- package/dist/components/MouthDecorations.d.ts +9 -1
- package/dist/components/OptionalChip.d.ts +12 -0
- package/dist/types.d.ts +6 -0
- package/dist/utils/blockLayout.d.ts +87 -3
- package/package.json +1 -1
package/dist/blocks.json
CHANGED
|
@@ -4,9 +4,41 @@
|
|
|
4
4
|
"name": "When Played",
|
|
5
5
|
"blockType": "start",
|
|
6
6
|
"params": [],
|
|
7
|
+
"provides": [
|
|
8
|
+
{ "name": "card", "id": "$when-played.card" },
|
|
9
|
+
{ "name": "player", "id": "$when-played.player" },
|
|
10
|
+
{ "name": "target", "id": "$when-played.target" }
|
|
11
|
+
],
|
|
7
12
|
"category": "Events",
|
|
8
13
|
"color": "#7A1C2A"
|
|
9
14
|
},
|
|
15
|
+
{
|
|
16
|
+
"id": "$when-played.card",
|
|
17
|
+
"name": "card",
|
|
18
|
+
"blockType": "query",
|
|
19
|
+
"returnType": "Card",
|
|
20
|
+
"params": [],
|
|
21
|
+
"category": "$when-played",
|
|
22
|
+
"color": "#7A1C2A"
|
|
23
|
+
},
|
|
24
|
+
{
|
|
25
|
+
"id": "$when-played.player",
|
|
26
|
+
"name": "player",
|
|
27
|
+
"blockType": "query",
|
|
28
|
+
"returnType": "Player",
|
|
29
|
+
"params": [],
|
|
30
|
+
"category": "$when-played",
|
|
31
|
+
"color": "#7A1C2A"
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
"id": "$when-played.target",
|
|
35
|
+
"name": "target",
|
|
36
|
+
"blockType": "query",
|
|
37
|
+
"returnType": "Player",
|
|
38
|
+
"params": [],
|
|
39
|
+
"category": "$when-played",
|
|
40
|
+
"color": "#7A1C2A"
|
|
41
|
+
},
|
|
10
42
|
{
|
|
11
43
|
"id": "when-active",
|
|
12
44
|
"name": "When Active",
|
|
@@ -20,16 +52,29 @@
|
|
|
20
52
|
"name": "When Drawn",
|
|
21
53
|
"blockType": "start",
|
|
22
54
|
"params": [],
|
|
55
|
+
"provides": [
|
|
56
|
+
{ "name": "card", "id": "$when-drawn.card" }
|
|
57
|
+
],
|
|
23
58
|
"category": "Events",
|
|
24
59
|
"color": "#7A1C2A"
|
|
25
60
|
},
|
|
61
|
+
{
|
|
62
|
+
"id": "$when-drawn.card",
|
|
63
|
+
"name": "card",
|
|
64
|
+
"blockType": "query",
|
|
65
|
+
"returnType": "Card",
|
|
66
|
+
"params": [],
|
|
67
|
+
"category": "$when-drawn",
|
|
68
|
+
"color": "#7A1C2A"
|
|
69
|
+
},
|
|
26
70
|
{
|
|
27
71
|
"id": "DrawCard",
|
|
28
72
|
"name": "Draw Card",
|
|
29
73
|
"blockType": "command",
|
|
30
74
|
"params": [
|
|
31
75
|
{ "name": "deck", "type": "Deck" },
|
|
32
|
-
{ "name": "hand", "type": "string" }
|
|
76
|
+
{ "name": "hand", "type": "string" },
|
|
77
|
+
{ "name": "count", "type": "number", "optional": true }
|
|
33
78
|
],
|
|
34
79
|
"category": "Actions",
|
|
35
80
|
"color": "#1C3A7A"
|
|
@@ -40,7 +85,7 @@
|
|
|
40
85
|
"blockType": "command",
|
|
41
86
|
"params": [
|
|
42
87
|
{ "name": "card", "type": "Card" },
|
|
43
|
-
{ "name": "target", "type": "Player" }
|
|
88
|
+
{ "name": "target", "type": "Player", "optional": true }
|
|
44
89
|
],
|
|
45
90
|
"category": "Actions",
|
|
46
91
|
"color": "#1C3A7A"
|
package/dist/commands/build.d.ts
CHANGED
|
@@ -17,6 +17,11 @@ export declare function placeNewBlock(state: CanvasState, block: PlacedBlock, at
|
|
|
17
17
|
* dropped back where it is.
|
|
18
18
|
*/
|
|
19
19
|
export declare function moveChain(state: CanvasState, leadId: string, drop: Position, place: Place | null): Command | null;
|
|
20
|
+
/**
|
|
21
|
+
* An optional mouth closed (its `×`): the chain it holds taken out and put down at `at`, as if dragged out, so nothing is
|
|
22
|
+
* lost. Nothing when the mouth holds no chain: closing an empty mouth only changes the view.
|
|
23
|
+
*/
|
|
24
|
+
export declare function closeMouth(state: CanvasState, blockId: string, slot: number, at: Position): Command | null;
|
|
20
25
|
/** A block (with what hangs off it) deleted. */
|
|
21
26
|
export declare function deleteChain(state: CanvasState, leadId: string): Command | null;
|
|
22
27
|
/**
|
|
@@ -21,6 +21,12 @@ interface Props {
|
|
|
21
21
|
provisionalIds?: Set<string>;
|
|
22
22
|
/** The text of the socket being typed into, on every keystroke. */
|
|
23
23
|
onSocketInput?: (blockId: string, slotIndex: number, text: string) => void;
|
|
24
|
+
/** Called when the user removes an added optional parameter (its `×`): its text is cleared, or its query detached. */
|
|
25
|
+
onParamRemove?: (blockId: string, slotIndex: number) => void;
|
|
26
|
+
/** Called when the user clicks the `+ name` chip of an optional mouth: open it. */
|
|
27
|
+
onMouthOpen?: (blockId: string, slotIndex: number) => void;
|
|
28
|
+
/** Called when the user clicks the `×` of an open optional mouth: close it, taking out any chain it holds. */
|
|
29
|
+
onMouthClose?: (blockId: string, slotIndex: number) => void;
|
|
24
30
|
embedded?: boolean;
|
|
25
31
|
}
|
|
26
32
|
/**
|
|
@@ -16,6 +16,12 @@ interface Props {
|
|
|
16
16
|
onSocketInput?: (blockId: string, slotIndex: number, text: string) => void;
|
|
17
17
|
onSocketCommit?: (blockId: string, slotIndex: number, value: string) => void;
|
|
18
18
|
onSocketCancelEdit?: () => void;
|
|
19
|
+
/** The `×` of an added optional parameter: leave it out again. */
|
|
20
|
+
onParamRemove?: (blockId: string, slotIndex: number) => void;
|
|
21
|
+
/** The `+ name` chip of an optional mouth: open it. */
|
|
22
|
+
onMouthOpen?: (blockId: string, slotIndex: number) => void;
|
|
23
|
+
/** The `×` of an open optional mouth: close it, taking out any chain it holds. */
|
|
24
|
+
onMouthClose?: (blockId: string, slotIndex: number) => void;
|
|
19
25
|
onOutputDrag: (e: React.PointerEvent, defId: string) => void;
|
|
20
26
|
/** Drawn over the blocks (e.g. other users' cursors). */
|
|
21
27
|
overlay?: React.ReactNode;
|
|
@@ -1,4 +1,12 @@
|
|
|
1
|
-
import type { MouthInfo } from '../utils/blockLayout';
|
|
1
|
+
import type { MouthChip, MouthInfo } from '../utils/blockLayout';
|
|
2
|
+
/**
|
|
3
|
+
* The `+ name` chips of a C-block's optional mouths that aren't open, on its bottom bar. With `onOpen` (a block on the
|
|
4
|
+
* canvas) clicking one opens its mouth; in the palette and on a drag ghost they are only a picture.
|
|
5
|
+
*/
|
|
6
|
+
export declare function MouthChips({ chips, onOpen }: {
|
|
7
|
+
chips: MouthChip[];
|
|
8
|
+
onOpen?: (index: number) => void;
|
|
9
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
2
10
|
/**
|
|
3
11
|
* What a C-block draws around its mouths: each divider bar's parameter name, and a dashed placeholder with the
|
|
4
12
|
* parameter's name in every empty mouth. Both show the parameter's name and type on hover (pressing them drags the
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** An optional parameter that isn't added: a small dashed `+ name` chip, `w` × `h`, in the socket's place. */
|
|
2
|
+
export declare function OptionalChip({ name, w, h }: {
|
|
3
|
+
name: string;
|
|
4
|
+
w: number;
|
|
5
|
+
h: number;
|
|
6
|
+
}): import("react/jsx-runtime").JSX.Element;
|
|
7
|
+
/** The `×` at the top-right corner of an added optional parameter (`w` wide), which leaves it out again. */
|
|
8
|
+
export declare function RemoveParamButton({ w, title, onRemove }: {
|
|
9
|
+
w: number;
|
|
10
|
+
title: string;
|
|
11
|
+
onRemove: () => void;
|
|
12
|
+
}): import("react/jsx-runtime").JSX.Element;
|
package/dist/types.d.ts
CHANGED
|
@@ -6,6 +6,12 @@ export declare const COMMAND_PARAM_TYPE = "command";
|
|
|
6
6
|
export interface BlockParam {
|
|
7
7
|
name: string;
|
|
8
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;
|
|
9
15
|
}
|
|
10
16
|
/**
|
|
11
17
|
* A guarantee that a particular query block (`id`) will return valid data
|
|
@@ -13,6 +13,8 @@ export declare const MOUTH_MIN_H = 24;
|
|
|
13
13
|
export declare const MOUTH_DIVIDER_H = 24;
|
|
14
14
|
/** Height of the bar under the last mouth. */
|
|
15
15
|
export declare const MOUTH_FOOTER_H = 16;
|
|
16
|
+
/** Height of that bar when it carries the chips of optional mouths that aren't open. */
|
|
17
|
+
export declare const MOUTH_FOOTER_CHIPS_H = 26;
|
|
16
18
|
/** Height of each scope-output pill rendered in the event block's variable panel. */
|
|
17
19
|
export declare const OUTPUT_PILL_H = 20;
|
|
18
20
|
/**
|
|
@@ -22,6 +24,11 @@ export declare const OUTPUT_PILL_H = 20;
|
|
|
22
24
|
export declare const OUTPUT_ROW_H = 26;
|
|
23
25
|
/** Types whose shape already communicates the type; no text label needed. */
|
|
24
26
|
export declare const PRIMITIVE_TYPES: Set<string>;
|
|
27
|
+
/** The size of an empty socket of the type. */
|
|
28
|
+
export declare function getSocketSize(type: ParamType): {
|
|
29
|
+
w: number;
|
|
30
|
+
h: number;
|
|
31
|
+
};
|
|
25
32
|
/**
|
|
26
33
|
* Whether a parameter of the block is drawn as a C-shaped mouth holding a chain of commands. Only command blocks have
|
|
27
34
|
* mouths; on a query or start block a command parameter stays a plain socket that nothing fits.
|
|
@@ -36,7 +43,18 @@ export interface SocketInfo {
|
|
|
36
43
|
h: number;
|
|
37
44
|
type: ParamType;
|
|
38
45
|
index: number;
|
|
46
|
+
/**
|
|
47
|
+
* An optional parameter that isn't added (its slot holds no text and no query): drawn as a small `[+] name` chip
|
|
48
|
+
* instead of a socket. It is still a socket: a fitting query dropped on it, or text typed into it, adds it.
|
|
49
|
+
*/
|
|
50
|
+
collapsed: boolean;
|
|
39
51
|
}
|
|
52
|
+
/** Height of the chip an optional parameter that isn't added is drawn as. */
|
|
53
|
+
export declare const CHIP_H = 18;
|
|
54
|
+
/** Whether a parameter is an optional one that isn't added: nothing is in its slot (empty text counts as nothing). */
|
|
55
|
+
export declare function isCollapsed(param: BlockParam, slot: ParamSlot | undefined): boolean;
|
|
56
|
+
/** The text on an optional parameter's chip. */
|
|
57
|
+
export declare function chipLabel(name: string): string;
|
|
40
58
|
export interface MouthInfo {
|
|
41
59
|
/** Index of the command parameter. */
|
|
42
60
|
index: number;
|
|
@@ -45,9 +63,42 @@ export interface MouthInfo {
|
|
|
45
63
|
x: number;
|
|
46
64
|
y: number;
|
|
47
65
|
h: number;
|
|
48
|
-
/** Top of the divider bar above the mouth (every mouth
|
|
66
|
+
/** Top of the divider bar above the mouth (every mouth but the block's first command parameter has one), or null. */
|
|
49
67
|
dividerY: number | null;
|
|
68
|
+
/** Whether the parameter is optional: an open optional mouth can be closed again (its `×`). */
|
|
69
|
+
optional: boolean;
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* A parameter slot as the editor lays it out. `opened` is view state only, never in the canvas state or a command: an
|
|
73
|
+
* optional mouth the user opened (its chip clicked) that holds no chain yet, or no longer.
|
|
74
|
+
*/
|
|
75
|
+
export interface ViewSlot extends ParamSlot {
|
|
76
|
+
opened?: boolean;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Whether a parameter of the block is an optional mouth that isn't open: it holds no chain and the user hasn't opened it.
|
|
80
|
+
* It's drawn as a `+ name` chip on the block's bottom bar, not as an empty mouth; an empty mouth is "not given" anyway.
|
|
81
|
+
*/
|
|
82
|
+
export declare function isMouthCollapsed(def: BlockDefinition, param: BlockParam, slot: ViewSlot | undefined): boolean;
|
|
83
|
+
/** The chip of an optional mouth that isn't open, relative to the block. Clicking it opens the mouth; a command dropped on it goes in. */
|
|
84
|
+
export interface MouthChip {
|
|
85
|
+
/** Index of the command parameter. */
|
|
86
|
+
index: number;
|
|
87
|
+
name: string;
|
|
88
|
+
x: number;
|
|
89
|
+
y: number;
|
|
90
|
+
w: number;
|
|
91
|
+
h: number;
|
|
50
92
|
}
|
|
93
|
+
/**
|
|
94
|
+
* The blocks with the optional mouths in `open` (keys from `mouthKey`) marked as opened, for the layout: only those that
|
|
95
|
+
* hold no chain change (a mouth holding a chain is open anyway). Blocks that don't change are the same objects.
|
|
96
|
+
*/
|
|
97
|
+
export declare function withOpenedMouths(blocks: Map<string, PlacedBlock>, open: ReadonlySet<string>): Map<string, PlacedBlock>;
|
|
98
|
+
/** The key of a block's mouth in the set of mouths opened in the view. */
|
|
99
|
+
export declare function mouthKey(blockId: string, index: number): string;
|
|
100
|
+
/** The keys of the optional mouths that hold a chain: they stay open in the view when their chain is taken out. */
|
|
101
|
+
export declare function optionalMouthsHoldingChains(blocks: Map<string, PlacedBlock>): string[];
|
|
51
102
|
/**
|
|
52
103
|
* The text cut with an ellipsis to fit inside a socket of the type and width: number (round caps) and boolean (pointed
|
|
53
104
|
* ends) sockets lose their ends (`w - h`), others a little padding.
|
|
@@ -55,8 +106,21 @@ export interface MouthInfo {
|
|
|
55
106
|
export declare function fitLabel(text: string, socketType: ParamType, width: number): string;
|
|
56
107
|
/** A socket's (or mouth's) tooltip: its parameter's name and type. */
|
|
57
108
|
export declare function socketTitle(name: string, type: ParamType): string;
|
|
109
|
+
/** A parameter's tooltip: its name and type, and whether it is optional. */
|
|
110
|
+
export declare function paramTitle(param: BlockParam): string;
|
|
58
111
|
/** Minimum pill width based on label text only (type is implicit in the query block itself). */
|
|
59
112
|
export declare function getPillWidth(name: string): number;
|
|
113
|
+
/**
|
|
114
|
+
* Where a start block's context-variable pills go: side by side, one column each, in a single row below the header
|
|
115
|
+
* divider. Positions are relative to the block.
|
|
116
|
+
*/
|
|
117
|
+
export declare function getPillPositions(def: BlockDefinition): {
|
|
118
|
+
id: string;
|
|
119
|
+
name: string;
|
|
120
|
+
x: number;
|
|
121
|
+
y: number;
|
|
122
|
+
w: number;
|
|
123
|
+
}[];
|
|
60
124
|
/** Width of a block, accounting for embedded query blocks in param slots. Mouths don't widen it. */
|
|
61
125
|
export declare function getBlockWidth(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): number;
|
|
62
126
|
/** Height of the header row: the label and the sockets. */
|
|
@@ -66,12 +130,32 @@ export declare function getHeaderHeight(def: BlockDefinition): number;
|
|
|
66
130
|
* and blocks its mouths are empty.
|
|
67
131
|
*/
|
|
68
132
|
export declare function getBlockHeight(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): number;
|
|
133
|
+
/** The chips of a C-block's optional mouths that aren't open, side by side on its bottom bar, relative to the block. */
|
|
134
|
+
export declare function getMouthChips(def: BlockDefinition, paramSlots?: ViewSlot[], allBlocks?: Map<string, PlacedBlock>): MouthChip[];
|
|
69
135
|
/** Height of a placed block, including a placeholder for a missing definition. */
|
|
70
136
|
export declare function getPlacedBlockHeight(block: PlacedBlock, allBlocks: Map<string, PlacedBlock>): number;
|
|
71
137
|
/** Height of the chain starting at `firstId`: its blocks stacked. */
|
|
72
138
|
export declare function getChainHeight(firstId: string, allBlocks: Map<string, PlacedBlock>): number;
|
|
73
|
-
/**
|
|
74
|
-
|
|
139
|
+
/**
|
|
140
|
+
* The open mouths of a C-block in parameter order, relative to the block; an optional mouth that isn't open is a chip
|
|
141
|
+
* (`getMouthChips`) instead. Empty for other blocks. Every mouth but the block's first command parameter has a divider
|
|
142
|
+
* bar with its name, also when the first is a chip: it is filled from a section of its own in a script.
|
|
143
|
+
*/
|
|
144
|
+
export declare function getMouthPositions(def: BlockDefinition, paramSlots?: ViewSlot[], allBlocks?: Map<string, PlacedBlock>): MouthInfo[];
|
|
145
|
+
/**
|
|
146
|
+
* Where a command chain can be dropped into a C-block, relative to the block: the top of each open mouth, and each
|
|
147
|
+
* mouth chip (a chain dropped there goes in the mouth and opens it). `slot` is the command parameter's index.
|
|
148
|
+
*/
|
|
149
|
+
export declare function getMouthDropTargets(def: BlockDefinition, paramSlots?: ViewSlot[], allBlocks?: Map<string, PlacedBlock>): {
|
|
150
|
+
slot: number;
|
|
151
|
+
x: number;
|
|
152
|
+
y: number;
|
|
153
|
+
}[];
|
|
154
|
+
/** Where the `×` that closes an open optional mouth goes, relative to the block: the right of its divider bar. */
|
|
155
|
+
export declare function getMouthCloseButton(mouth: MouthInfo, blockW: number): {
|
|
156
|
+
x: number;
|
|
157
|
+
y: number;
|
|
158
|
+
};
|
|
75
159
|
/** Socket positions relative to block (x, y). Mouths are not sockets. */
|
|
76
160
|
export declare function getSocketPositions(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): SocketInfo[];
|
|
77
161
|
/**
|
package/package.json
CHANGED