@tvolden/block-code-editor 0.2.0 → 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.
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"
@@ -21,6 +21,8 @@ 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;
24
26
  embedded?: boolean;
25
27
  }
26
28
  /**
@@ -16,6 +16,8 @@ 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;
19
21
  onOutputDrag: (e: React.PointerEvent, defId: string) => void;
20
22
  /** Drawn over the blocks (e.g. other users' cursors). */
21
23
  overlay?: React.ReactNode;
@@ -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
@@ -22,6 +22,11 @@ export declare const OUTPUT_PILL_H = 20;
22
22
  export declare const OUTPUT_ROW_H = 26;
23
23
  /** Types whose shape already communicates the type; no text label needed. */
24
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
+ };
25
30
  /**
26
31
  * Whether a parameter of the block is drawn as a C-shaped mouth holding a chain of commands. Only command blocks have
27
32
  * mouths; on a query or start block a command parameter stays a plain socket that nothing fits.
@@ -36,7 +41,18 @@ export interface SocketInfo {
36
41
  h: number;
37
42
  type: ParamType;
38
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;
39
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;
40
56
  export interface MouthInfo {
41
57
  /** Index of the command parameter. */
42
58
  index: number;
@@ -55,8 +71,21 @@ export interface MouthInfo {
55
71
  export declare function fitLabel(text: string, socketType: ParamType, width: number): string;
56
72
  /** A socket's (or mouth's) tooltip: its parameter's name and type. */
57
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;
58
76
  /** Minimum pill width based on label text only (type is implicit in the query block itself). */
59
77
  export declare function getPillWidth(name: string): number;
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
+ }[];
60
89
  /** Width of a block, accounting for embedded query blocks in param slots. Mouths don't widen it. */
61
90
  export declare function getBlockWidth(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): number;
62
91
  /** Height of the header row: the label and the sockets. */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tvolden/block-code-editor",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "A visual block programming editor for React, with command-sourced canvases for collaboration",
5
5
  "license": "MIT",
6
6
  "author": "Thomas Volden",