@tvolden/block-code-editor 0.3.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 +2 -1
- package/dist/block-editor.cjs +4 -4
- package/dist/block-editor.js +1428 -1299
- package/dist/commands/build.d.ts +5 -0
- package/dist/components/BlockRenderer.d.ts +4 -0
- package/dist/components/Canvas.d.ts +4 -0
- package/dist/components/MouthDecorations.d.ts +9 -1
- package/dist/utils/blockLayout.d.ts +58 -3
- package/package.json +1 -1
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
|
/**
|
|
@@ -23,6 +23,10 @@ interface Props {
|
|
|
23
23
|
onSocketInput?: (blockId: string, slotIndex: number, text: string) => void;
|
|
24
24
|
/** Called when the user removes an added optional parameter (its `×`): its text is cleared, or its query detached. */
|
|
25
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;
|
|
26
30
|
embedded?: boolean;
|
|
27
31
|
}
|
|
28
32
|
/**
|
|
@@ -18,6 +18,10 @@ interface Props {
|
|
|
18
18
|
onSocketCancelEdit?: () => void;
|
|
19
19
|
/** The `×` of an added optional parameter: leave it out again. */
|
|
20
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;
|
|
21
25
|
onOutputDrag: (e: React.PointerEvent, defId: string) => void;
|
|
22
26
|
/** Drawn over the blocks (e.g. other users' cursors). */
|
|
23
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
|
|
@@ -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
|
/**
|
|
@@ -61,9 +63,42 @@ export interface MouthInfo {
|
|
|
61
63
|
x: number;
|
|
62
64
|
y: number;
|
|
63
65
|
h: number;
|
|
64
|
-
/** 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. */
|
|
65
67
|
dividerY: number | null;
|
|
68
|
+
/** Whether the parameter is optional: an open optional mouth can be closed again (its `×`). */
|
|
69
|
+
optional: boolean;
|
|
66
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;
|
|
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[];
|
|
67
102
|
/**
|
|
68
103
|
* The text cut with an ellipsis to fit inside a socket of the type and width: number (round caps) and boolean (pointed
|
|
69
104
|
* ends) sockets lose their ends (`w - h`), others a little padding.
|
|
@@ -95,12 +130,32 @@ export declare function getHeaderHeight(def: BlockDefinition): number;
|
|
|
95
130
|
* and blocks its mouths are empty.
|
|
96
131
|
*/
|
|
97
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[];
|
|
98
135
|
/** Height of a placed block, including a placeholder for a missing definition. */
|
|
99
136
|
export declare function getPlacedBlockHeight(block: PlacedBlock, allBlocks: Map<string, PlacedBlock>): number;
|
|
100
137
|
/** Height of the chain starting at `firstId`: its blocks stacked. */
|
|
101
138
|
export declare function getChainHeight(firstId: string, allBlocks: Map<string, PlacedBlock>): number;
|
|
102
|
-
/**
|
|
103
|
-
|
|
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
|
+
};
|
|
104
159
|
/** Socket positions relative to block (x, y). Mouths are not sockets. */
|
|
105
160
|
export declare function getSocketPositions(def: BlockDefinition, paramSlots?: ParamSlot[], allBlocks?: Map<string, PlacedBlock>): SocketInfo[];
|
|
106
161
|
/**
|
package/package.json
CHANGED