morphic-blocks 0.4.0 → 0.6.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,78 @@
1
+ import * as Blockly from "blockly";
2
+ /**
3
+ * A declared dropdown whose open menu carries classes for app CSS:
4
+ * `morphic-menu` and `morphic-menu-<FIELD>` (the field's name), e.g. to lay
5
+ * picture choices out in a grid or hide the check marks.
6
+ */
7
+ export declare class MorphicDropdown extends Blockly.FieldDropdown {
8
+ protected showEditor_(event?: MouseEvent): void;
9
+ }
10
+ /** The parts of a reference's target, `"class_define.NAME"`: a block and one of its fields. */
11
+ export declare function parseReferenceTarget(target: unknown): {
12
+ block: string;
13
+ field: string;
14
+ } | null;
15
+ /**
16
+ * A reference field (`{ "type": "reference", "to": "class_define.NAME" }`): a
17
+ * dropdown of the names the program declares, i.e. what the `NAME` field of
18
+ * every `class_define` block holds. Its value is the name itself, so text
19
+ * views, generated code and saved programs read it like any other field. A
20
+ * name whose declaration is gone stays as it is.
21
+ */
22
+ export declare class MorphicReference extends MorphicDropdown {
23
+ private readonly initial;
24
+ private readonly targets;
25
+ private readonly scopes;
26
+ constructor(to: string | string[], initial?: string, scope?: string | string[]);
27
+ /** Whether this field lists what `field` of `declaration` holds: a target of it, and in its scope. */
28
+ refersTo(declaration: Blockly.Block, field: string): boolean;
29
+ /**
30
+ * The block a scoped reference looks inside: the nearest block around it
31
+ * of a `scope` type (the class around `self.name`). `undefined` without a
32
+ * scope, `null` when no such block is around it.
33
+ */
34
+ private scopeBlock;
35
+ /** Whether the field lists only what a block around it holds. */
36
+ isScoped(): boolean;
37
+ /** Whether a declaration is one this reference may name: anywhere, or inside its scope block. */
38
+ private sees;
39
+ /**
40
+ * The names the program declares for this field, each once, in alphabetical
41
+ * order. `known` keeps the lists of one pass over many references, which
42
+ * mostly ask for the same one.
43
+ */
44
+ declaredNames(known?: Map<string, string[]>): string[];
45
+ /** Whether the name is one nothing declares (its declaration was deleted, or never made). */
46
+ isMissing(known?: Map<string, string[]>): boolean;
47
+ /** Mark the field with `morphic-reference-missing` while its name is one nothing declares. */
48
+ showMissing(known?: Map<string, string[]>): void;
49
+ initView(): void;
50
+ /**
51
+ * A new reference that names nothing declared takes the first declared
52
+ * name. One that was set to something else is left alone.
53
+ */
54
+ pickDeclared(): void;
55
+ private nameOptions;
56
+ /** The names change with the program, so they are never read from a cache. */
57
+ getOptions(): Blockly.MenuOption[];
58
+ /** Any name is kept: its declaration may be loaded later, or be gone. */
59
+ protected doClassValidation_(newValue?: string): string | null;
60
+ protected doValueUpdate_(newValue: string): void;
61
+ }
62
+ /**
63
+ * The names a reference field would list at a place where no block is yet:
64
+ * `inside` is the block the reference would sit in. What `declaredNames()`
65
+ * gives a reference that is on the workspace.
66
+ */
67
+ export declare function declaredNamesAt(workspace: Blockly.Workspace, to: string | string[], scope: string | string[] | undefined, inside: Blockly.Block | null): string[];
68
+ /** Let the references of one edit keep the names they have, declared or not. */
69
+ export declare function keepNamesOf(group: string): void;
70
+ /**
71
+ * Keep a program's references in step with its declarations: a renamed
72
+ * declaration renames the references that named it (unless another
73
+ * declaration still has the old name), a reference that is new or moved
74
+ * takes a declared name when its own names nothing, and every reference
75
+ * shows whether its name is declared. The changes join the edit that caused
76
+ * them, so one undo takes both back.
77
+ */
78
+ export declare function keepReferencesInStep(workspace: Blockly.Workspace): void;
@@ -6,7 +6,7 @@ export declare function resolveElementType(entry: MorphicElementTypeEntry | unde
6
6
  * section folded in. Internal: the renderers read the settings from the entry
7
7
  * they already hold for the element.
8
8
  */
9
- export type MorphicElementTypeWithCode = MorphicElementTypeConfig & Pick<MorphicCodeElementConfig, "empty" | "stringQuote" | "emptyStatement" | "types">;
9
+ export type MorphicElementTypeWithCode = MorphicElementTypeConfig & Pick<MorphicCodeElementConfig, "empty" | "stringQuote" | "emptyStatement" | "types" | "operators">;
10
10
  /** `elementTypes` with each code element's `code` settings folded in. */
11
11
  export declare function withCodeSettings(elementTypes: Record<string, MorphicElementTypeEntry>, code: Record<string, MorphicCodeElementConfig> | undefined): Record<string, MorphicElementTypeEntry>;
12
12
  /**
@@ -0,0 +1,73 @@
1
+ import { type MorphicTemplateToken } from "./template";
2
+ import type { MorphicBlockDefinition, MorphicCodeElementConfig } from "./types";
3
+ /**
4
+ * The order of operators in text. Blocks need none: a block in a slot is one
5
+ * value. Text does: `2 + 3 * 4` says which part belongs together only through
6
+ * the order of `+` and `*`. The writer (template-codegen.ts) and the reader
7
+ * (text-to-blocks.ts) ask the same questions here, so what one writes without
8
+ * brackets the other reads as the same blocks.
9
+ *
10
+ * An operator is known by its template: two values with a sign between them
11
+ * (`%1 + %2`, `%1 %OP %2`), a sign in front of one value (`not %1`, `-%1`), or
12
+ * a list of values with the sign as separator. The sign, as the language
13
+ * writes it, has a rank; a sign without one keeps the rule there was before
14
+ * ranks: brackets around every value built from others.
15
+ */
16
+ type OperatorSettings = MorphicCodeElementConfig["operators"];
17
+ /**
18
+ * What may stand in a slot without brackets: a value of this rank, or
19
+ * (`above`) only a higher one. `sign` names an operator that stands free
20
+ * there all the same: one whose grouping does not matter, beside itself.
21
+ */
22
+ export interface OperandBound {
23
+ rank: number;
24
+ above: boolean;
25
+ sign?: string;
26
+ }
27
+ /** A slot that takes any value as it is: nothing around it binds. */
28
+ export declare const WHOLE: OperandBound;
29
+ /** A slot that takes only a value that is one piece: a name, a number, a call. */
30
+ export declare const ATOM: OperandBound;
31
+ export declare function allows(bound: OperandBound, rank: number, sign?: string): boolean;
32
+ type SignPart = {
33
+ text: string;
34
+ } | {
35
+ field: string;
36
+ };
37
+ /** A template that is an operator, with the slot numbers of its values. */
38
+ export type OperatorForm = {
39
+ kind: "infix";
40
+ left: number;
41
+ right: number;
42
+ sign: SignPart[];
43
+ } | {
44
+ kind: "prefix";
45
+ slot: number;
46
+ sign: SignPart[];
47
+ } | {
48
+ kind: "chain";
49
+ slot: number;
50
+ sign: string;
51
+ };
52
+ /** Whether a value block's template is an operator, and of which shape. */
53
+ export declare function operatorForm(tokens: MorphicTemplateToken[], definition: MorphicBlockDefinition, element: string | undefined): OperatorForm | null;
54
+ /** An operator whose sign has a rank: the sign, its rank, and what each of its slots takes. */
55
+ export interface RankedOperator {
56
+ sign: string;
57
+ rank: number;
58
+ bound(slot: number): OperandBound;
59
+ }
60
+ /**
61
+ * The rank of an operator as it is written right now. `shown` gives the text
62
+ * a field shows (`%OP` as `and`); `null` when the sign has no rank.
63
+ */
64
+ export declare function rankOperator(form: OperatorForm, shown: (field: string) => string | undefined, settings: OperatorSettings): RankedOperator | null;
65
+ /**
66
+ * What a slot takes without brackets in a template that is no operator
67
+ * itself, from the text right around it. A sign with a rank there makes the
68
+ * slot its operand (`std::cout << %1 << std::endl;`, `i < %1;`, `if not %1:`);
69
+ * without one, the slot takes any value where it stands free (`max(%1, %2)`,
70
+ * `return %1`) and one piece only where the text binds to it (`%1.length`).
71
+ */
72
+ export declare function slotBound(tokens: MorphicTemplateToken[], index: number, statement: boolean, settings: OperatorSettings): OperandBound;
73
+ export {};
@@ -0,0 +1,7 @@
1
+ import type * as Blockly from "blockly";
2
+ /**
3
+ * The field a `%parent.NAME` token shows: the field of that name on the
4
+ * nearest block around this one that has it (the class around a method), or
5
+ * `null` when no block around it has one.
6
+ */
7
+ export declare function findParentField(block: Blockly.Block, name: string): Blockly.Field | null;
@@ -0,0 +1,31 @@
1
+ import type * as Blockly from "blockly";
2
+ import type { MorphicBlockDefinition, MorphicInputSlotDefinition } from "./types";
3
+ /** What a saved block holds about its repeating slots: entries per slot name. */
4
+ export interface MorphicRepeatState {
5
+ repeat: Record<string, number>;
6
+ }
7
+ export declare function isRepeating(slot: MorphicInputSlotDefinition | undefined): boolean;
8
+ /** The Blockly input name of a slot: its `name`, or `ARG<n>` after its placeholder. */
9
+ export declare function slotInputName(slot: MorphicInputSlotDefinition | undefined, placeholderIndex: number | string): string;
10
+ /** The Blockly input name of one entry of a repeating slot. */
11
+ export declare function repeatInputName(slotName: string, index: number): string;
12
+ /** A block's repeating slots, by input name. */
13
+ export declare function repeatingSlots(definition: MorphicBlockDefinition): Map<string, MorphicInputSlotDefinition>;
14
+ /** How many entries a repeating slot has on a block; a new block starts with `repeat.count` (1). */
15
+ export declare function repeatCount(block: Blockly.Block, slotName: string, slot: MorphicInputSlotDefinition): number;
16
+ export declare function setRepeatCount(block: Blockly.Block, slotName: string, count: number): void;
17
+ /** The input names of a repeating slot's entries on a block, in order. */
18
+ export declare function repeatEntries(block: Blockly.Block, slotName: string, slot: MorphicInputSlotDefinition): string[];
19
+ /** What is written between two entries in an element: `repeat.separator` (a text, or one per element), `, ` by default. */
20
+ export declare function repeatSeparator(slot: MorphicInputSlotDefinition, elementName: string | undefined): string;
21
+ /**
22
+ * Whether the entries are operands of an operator (`" + "`), so a composed
23
+ * entry needs brackets, or simply listed (`, `), where it does not.
24
+ */
25
+ export declare function separatorComposes(separator: string): boolean;
26
+ /** The slot an input belongs to: the input of a plain slot, or an entry of a repeating one. */
27
+ export declare function slotOfInput(definition: MorphicBlockDefinition, inputName: string): MorphicInputSlotDefinition | undefined;
28
+ /** The state Blockly saves with a block that has repeating slots, `null` for one without. */
29
+ export declare function saveRepeatState(block: Blockly.Block, definition: MorphicBlockDefinition): MorphicRepeatState | null;
30
+ /** Take the counts of a saved state; returns whether any count changed. */
31
+ export declare function loadRepeatState(block: Blockly.Block, definition: MorphicBlockDefinition, state: unknown): boolean;
@@ -0,0 +1,10 @@
1
+ import type * as Blockly from "blockly";
2
+ /** Mark a slot's connection as strict; a rebuilt slot is marked again. */
3
+ export declare function markStrictSlot(connection: Blockly.Connection): void;
4
+ /** Mark the connection a block hangs by (above it, or its output) as strict. */
5
+ export declare function markStrictBlock(block: Blockly.Block): void;
6
+ /**
7
+ * Make a workspace refuse what strict slots and blocks refuse. It adds to the checker the
8
+ * workspace has, so a checker the app plugged in keeps deciding first.
9
+ */
10
+ export declare function enforceStrictSlots(workspace: Blockly.Workspace): void;
@@ -51,6 +51,24 @@ export declare function ensureTileHighlightStyles(elementName: string, colors?:
51
51
  * select text or open the phone's menu. Apps with a sideways toolbox set
52
52
  * `touch-action: pan-x` on their tiles.
53
53
  */
54
+ /**
55
+ * How the text of a dragged tile looks over a codespace: as code, in the
56
+ * font the codespace hands over, coloured like the element. `:where()` gives
57
+ * the rules no weight, so any rule of the app wins.
58
+ */
59
+ export declare function ensureDragTextStyles(elementName: string, colors?: MorphicHighlightDefinition["colors"]): void;
60
+ /**
61
+ * A typed value that was not taken stays in its input, marked. `:where()`
62
+ * gives the rule no weight, so any rule of the app wins.
63
+ */
64
+ export declare function ensureRejectedValueStyles(): void;
65
+ /**
66
+ * Code that is dragged in a codespace: the line that marks its new place, in
67
+ * the colour of the view's theme, its old place, where its lines close up
68
+ * and a value fades, and the cursors of the grip. `:where()` gives the rules
69
+ * no weight, so any rule of the app wins.
70
+ */
71
+ export declare function ensureCodeDragStyles(): void;
54
72
  export declare function ensureTileTouchStyles(): void;
55
73
  /**
56
74
  * The toolbox's scroll hints: no scrollbar, and a fade at each edge where more
@@ -18,3 +18,19 @@ export declare function generateTextFromWorkspace(workspace: Blockly.Workspace,
18
18
  options?: {
19
19
  emptyStatements?: boolean;
20
20
  }): MorphicCodeGenerationResult;
21
+ /**
22
+ * Whether a template's values all sit inside brackets of its own, with only
23
+ * a name in front: `random(%1, %2)`, `%NAME(%1)`, `new List(%1)`, `[%1]`,
24
+ * and `!(%1)`, which binds before any operator. A slot or another operator
25
+ * outside the brackets (`%1.get(%2)`, `-(%1)`, `f(%1) + %2`) means it is an
26
+ * operand like any other.
27
+ */
28
+ export declare function closesItself(template: string): boolean;
29
+ /**
30
+ * Whether a template only goes on from the value in front: `%1[%2]`,
31
+ * `%1.size()`, `%1.%NAME`. What goes on from a value binds before every
32
+ * operator, so the whole is one piece like a name (`items[1] + 1`). Anything
33
+ * else behind the first slot (`%1 + %2`, `%1.length as x`) makes it an
34
+ * operand like any other.
35
+ */
36
+ export declare function goesOnFromValue(template: string): boolean;
@@ -22,8 +22,39 @@ export interface MorphicFieldToken {
22
22
  kind: "field";
23
23
  name: string;
24
24
  }
25
- export type MorphicTemplateToken = MorphicImageToken | MorphicTextToken | MorphicPlaceholderToken | MorphicValueTypeToken | MorphicFieldToken;
25
+ /** `%parent.NAME`: the `NAME` field of the nearest block around this one that has it. */
26
+ export interface MorphicParentFieldToken {
27
+ kind: "parentField";
28
+ name: string;
29
+ }
30
+ export type MorphicTemplateToken = MorphicImageToken | MorphicTextToken | MorphicPlaceholderToken | MorphicValueTypeToken | MorphicFieldToken | MorphicParentFieldToken;
26
31
  export declare function parseTemplate(template: string): MorphicTemplateToken[];
32
+ /**
33
+ * Whether the text on each side of a slot leaves the value in it alone. A
34
+ * slot between brackets or commas stands free (`len(%1)`, `max(%1, %2)`), and
35
+ * so does the slot of a statement after its keyword or sign (`return %1`,
36
+ * `if %1:`, `x = %1`). An operator or a word in front of it (`not %1`, `-%1`)
37
+ * or something that goes on from it (`%1.length`) binds to the value.
38
+ */
39
+ export declare function slotSides(tokens: MorphicTemplateToken[], index: number, statement: boolean): {
40
+ before: boolean;
41
+ after: boolean;
42
+ };
43
+ /** Whether the text around a slot binds to the value in it, so a value built from others needs brackets there. */
44
+ export declare function slotIsExposed(tokens: MorphicTemplateToken[], index: number, statement: boolean): boolean;
45
+ /** The mark a field stands between where a template writes it as a text (`"%TEXT"`), else `null`. */
46
+ export declare function quoteAround(before: string | undefined, after: string | undefined): string | null;
47
+ /** A text as it is written between two marks: the mark and the backslash each get a backslash in front. */
48
+ export declare function escapeQuoted(text: string, mark: string): string;
49
+ /**
50
+ * Read a text written between two marks from `pos` on: where the closing
51
+ * mark is, and the text without its backslashes. `null` when the line ends
52
+ * before the mark comes.
53
+ */
54
+ export declare function readQuoted(source: string, pos: number, mark: string): {
55
+ value: string;
56
+ end: number;
57
+ } | null;
27
58
  export declare function normalizeTemplateText(text: string): string;
28
59
  /**
29
60
  * A name as a CSS class part. The name is kept as written (`icon-tiles`,
@@ -0,0 +1,59 @@
1
+ import type * as Blockly from "blockly";
2
+ import type { MorphicBlockDefinition, MorphicCodeElementConfig, MorphicInputSlotDefinition } from "./types";
3
+ /**
4
+ * Text to blocks: read the text of a code element back into the blocks that
5
+ * write it. There is no parser per language. Each block's template is its
6
+ * pattern, read the way it is written: `print(%1)` is the text `print(`, a
7
+ * value, and `)`. Statements are read line by line, a body by its
8
+ * indentation, a value down to the blocks without slots.
9
+ *
10
+ * This first version reads valid text only. Where two blocks write the same
11
+ * text (`x = 1` creates a variable or sets one), the names declared so far
12
+ * decide: a reference prefers a name that exists, a declaration one that does
13
+ * not. Operators are read in the order the language gives their signs (see
14
+ * operators.ts), and brackets group whatever is in them; a sign without a
15
+ * rank needs brackets around its parts.
16
+ */
17
+ type BlockState = Blockly.serialization.blocks.State;
18
+ /** What reading a text gives: the program's stacks, or the line that fits no block. */
19
+ export type MorphicTextParseResult = {
20
+ ok: true;
21
+ stacks: BlockState[];
22
+ blocks: number;
23
+ } | {
24
+ ok: false;
25
+ line: number;
26
+ message: string;
27
+ };
28
+ /** Where one typed value is meant to go: the slot, and the names the program declares. */
29
+ export interface MorphicValuePlace {
30
+ /** The slot's definition; without one, any value fits. */
31
+ slot?: MorphicInputSlotDefinition;
32
+ /** Every name the program declares, as `<block>.<FIELD>=<name>`. */
33
+ names: ReadonlySet<string>;
34
+ }
35
+ /** What reading one value gives: its block (with the blocks in it), or why the text is none. */
36
+ export type MorphicValueParseResult = {
37
+ ok: true;
38
+ block: BlockState;
39
+ blocks: number;
40
+ } | {
41
+ ok: false;
42
+ reason: "no-block" | "wrong-slot";
43
+ message: string;
44
+ };
45
+ /**
46
+ * Read `source`, written in the code element `element`, into blocks.
47
+ * `settings` are the element's `code` settings: its keywords are no names,
48
+ * its comment sign and empty statement are read as it writes them.
49
+ */
50
+ export declare function parseTextToBlocks(source: string, element: string, definitions: ReadonlyMap<string, MorphicBlockDefinition>, settings?: MorphicCodeElementConfig): MorphicTextParseResult;
51
+ /**
52
+ * Read `source` as one value written in the code element `element`, for a
53
+ * slot: `x + 1` gives the operator's block with a name and a number in it.
54
+ * The slot's check and strict rule decide what fits, as they do for a block
55
+ * dragged there, and the order of operators groups the parts. Brackets
56
+ * around the whole value are never needed: the blocks hold the structure.
57
+ */
58
+ export declare function parseValueToBlocks(source: string, element: string, definitions: ReadonlyMap<string, MorphicBlockDefinition>, settings: MorphicCodeElementConfig | undefined, place: MorphicValuePlace): MorphicValueParseResult;
59
+ export {};
@@ -0,0 +1,160 @@
1
+ import * as Blockly from "blockly";
2
+ /**
3
+ * Tiles dragged to a workspace. The HTML toolbox drags its tiles itself, so
4
+ * Blockly's own drag, which shows where a block would go and connects it
5
+ * when it is let go near a connection, never runs. What it would do is done
6
+ * here: over a workspace the tile becomes the block, its place is shown as
7
+ * Blockly shows it, and the block let go goes there.
8
+ */
9
+ /** A code element a target shows as text, and the font it writes it in. */
10
+ export interface TileTextPreview {
11
+ element: string;
12
+ font?: string;
13
+ }
14
+ /** Where a dragged tile can land. */
15
+ export interface TileDropTarget {
16
+ element: HTMLElement;
17
+ /**
18
+ * What the tile turns into over the target, which is what the target
19
+ * shows: `"block"` when the target draws the block itself, or the code
20
+ * element the block is written in as text. Without it the tile stays as
21
+ * it is.
22
+ */
23
+ preview?: () => "block" | TileTextPreview | undefined;
24
+ /**
25
+ * Whether the target takes the tile. One that does not (a read only view)
26
+ * still shows what the tile would be there, and the toolbox marks the drag
27
+ * as refused (`morphic-drag-refused`). Without it the target takes the tile.
28
+ */
29
+ takes?: () => boolean;
30
+ /**
31
+ * The tile is over the target at this point. `text` is the block as the
32
+ * target's code element writes it, for a target that shows text. Such a
33
+ * target says whether it shows the text at the block's place: `true`, and
34
+ * the text beside the pointer is not shown as well; `false`, and the target
35
+ * takes the block, but not at this spot (`morphic-drag-no-place`).
36
+ */
37
+ over?(x: number, y: number, blockType: string, text?: string): boolean | void;
38
+ /** The tile left the target or the drag ended. */
39
+ leave?(): void;
40
+ drop(blockType: string, x: number, y: number): void;
41
+ }
42
+ /** A connection of a block and the one on the workspace it would take. */
43
+ export interface SnapCandidate {
44
+ local: Blockly.RenderedConnection;
45
+ neighbour: Blockly.RenderedConnection;
46
+ }
47
+ /**
48
+ * The connection in reach of a block lying loose on the workspace: the
49
+ * nearest one within Blockly's snap radius that the workspace's connection
50
+ * checker lets it take (so checks and strict slots decide, as in a drag).
51
+ * The block must be drawn; its connections have no place before.
52
+ */
53
+ export declare function nearestConnection(block: Blockly.BlockSvg): SnapCandidate | null;
54
+ /**
55
+ * A connection a block would take, told by its place in its block: the
56
+ * connections of a block come in the same order in every copy of the program,
57
+ * so a place found in one view holds in another.
58
+ */
59
+ export interface SnapPlace {
60
+ /** The block on the workspace. */
61
+ blockId: string;
62
+ /** Which of that block's connections. */
63
+ index: number;
64
+ /** Which of the new block's connections goes there. */
65
+ local: number;
66
+ }
67
+ /**
68
+ * Add a block to a workspace at a place (in workspace coordinates) and
69
+ * connect it: to `shown`, the connection a preview showed as its place, else
70
+ * to the nearest one in reach; without one it stays loose at the place.
71
+ * Adding and connecting are one undo step.
72
+ */
73
+ export declare function addBlockAt(workspace: Blockly.WorkspaceSvg, type: string, at: Blockly.utils.Coordinate, shown?: SnapPlace): Blockly.BlockSvg;
74
+ /** A point of the page in the coordinates of a workspace. */
75
+ export declare function workspacePoint(workspace: Blockly.WorkspaceSvg, clientX: number, clientY: number): Blockly.utils.Coordinate;
76
+ /**
77
+ * A layer for what follows the pointer in a drag. It stays inside `parent`,
78
+ * so the styles that reach the parent's content reach it too, but the browser
79
+ * draws it on top of the page (as a popover), where nothing around the parent
80
+ * cuts it off. `onTop` is false in a browser without that: the layer then
81
+ * stays where the parent's edge ends it.
82
+ */
83
+ export declare function openDragLayer(parent: HTMLElement): {
84
+ layer: HTMLElement;
85
+ onTop: boolean;
86
+ };
87
+ /**
88
+ * The state of a workspace without the blocks that only show a held tile:
89
+ * what a copy of the program is made from.
90
+ */
91
+ export declare function saveProgram(workspace: Blockly.Workspace): {
92
+ [key: string]: unknown;
93
+ };
94
+ /**
95
+ * What a dragged tile shows over a workspace: its block, drawn as the view
96
+ * draws blocks, under the pointer, and where it would go, shown as Blockly
97
+ * shows it in its own drags: a gray copy at the place while the blocks after
98
+ * it make room, or, where the block would take a value's place, that value
99
+ * faded. Nothing of it is part of the program: it is made with events off and
100
+ * Blockly never moves it, so it is no undo step, no copy or save of the
101
+ * program has it (`saveProgram`), and it goes when the tile leaves or is let
102
+ * go.
103
+ */
104
+ export declare class TileBlockPreview {
105
+ private readonly view;
106
+ private readonly program;
107
+ private block;
108
+ private type;
109
+ private previewer;
110
+ private shown;
111
+ private replaced;
112
+ private raised;
113
+ /**
114
+ * @param view The workspace the block is shown in.
115
+ * @param program The workspace that holds the program, when `view` is a copy of it.
116
+ */
117
+ constructor(view: Blockly.WorkspaceSvg, program?: () => Blockly.WorkspaceSvg | null | undefined);
118
+ /**
119
+ * Show the block of a Blockly type at a place, in workspace coordinates,
120
+ * and where it would go; `placed: false` shows the block alone, for a view
121
+ * that takes none.
122
+ */
123
+ show(type: string, at: Blockly.utils.Coordinate, placed?: boolean): void;
124
+ /** The connection shown as the block's place, for the block that is added in its stead. */
125
+ place(): SnapPlace | undefined;
126
+ /** Take the block and what shows its place away. */
127
+ hide(): void;
128
+ /**
129
+ * The block, not drawn yet. In a copy of the program it is made as the
130
+ * program makes it: the program gives a block its slot defaults, so the
131
+ * block is made there, off the record, and its state loaded into the view,
132
+ * which is how the view gets every block it shows.
133
+ */
134
+ private make;
135
+ /**
136
+ * Show the block on top of the page. Inside the workspace its edge cuts a
137
+ * block held near it, and the next view covers the rest. Blockly needs the
138
+ * block where it is, so what is shown on top is a copy of its drawing, in a
139
+ * layer inside the workspace (the view's styles reach it), and the block
140
+ * itself is hidden. Without a place on top of the page the block stays as
141
+ * it is, cut like a block Blockly drags.
142
+ */
143
+ private raise;
144
+ /** Keep the layer where the workspace is, and as far scrolled and zoomed. */
145
+ private alignLayer;
146
+ /**
147
+ * The place to show: the nearest connection, but the one shown stays until
148
+ * another is clearly nearer, as in a Blockly drag. Showing a place moves
149
+ * the blocks around it, and without this the place would flicker between two.
150
+ */
151
+ private placeFor;
152
+ private showPlace;
153
+ }
154
+ /**
155
+ * A workspace as a place for tiles. Over `view` the tile shows as its block;
156
+ * let go, the block is added to the program (the view itself, or the
157
+ * workspace a copy of the program forwards to) at the same place. A read
158
+ * only view shows the block and takes nothing.
159
+ */
160
+ export declare function workspaceDropTarget(element: HTMLElement, view: Blockly.WorkspaceSvg, program: () => Blockly.WorkspaceSvg | null | undefined, blocklyType: (blockType: string) => string): TileDropTarget;
@@ -1,18 +1,8 @@
1
1
  import * as Blockly from "blockly";
2
- import type { MorphicBehaviorMap, MorphicBlockDefinition, MorphicElementTypeEntry, MorphicModeDefinition, MorphicCodeElementConfig, MorphicModeName, MorphicToolboxCanvasOptions } from "./types";
3
- export declare const DRAG_DATA_KEY = "morphic/block-type";
4
- /**
5
- * Where a tile dragged by touch or pen can land. HTML drag and drop, which
6
- * mouse drags use, does not start from a finger in most browsers.
7
- */
8
- export interface TileDropTarget {
9
- element: HTMLElement;
10
- /** The tile is over the target at this point. */
11
- over?(x: number, y: number): void;
12
- /** The tile left the target or the drag ended. */
13
- leave?(): void;
14
- drop(blockType: string, x: number, y: number): void;
15
- }
2
+ import { type TileDropTarget } from "./tile-drop";
3
+ import type { MorphicBehaviorMap, MorphicBlockDefinition, MorphicElementTypeEntry, MorphicModeDefinition, MorphicCodeElementConfig, MorphicHighlightDefinition, MorphicModeName, MorphicToolboxCanvasOptions } from "./types";
4
+ /** Text as HTML with its tokens wrapped in the classes the codespace uses. */
5
+ export declare function highlightedHtml(text: string, rules: MorphicHighlightDefinition): string;
16
6
  export declare class MorphicToolboxCanvas {
17
7
  private readonly container;
18
8
  private readonly workspaceContainer;
@@ -21,7 +11,7 @@ export declare class MorphicToolboxCanvas {
21
11
  private readonly blockColors;
22
12
  private readonly behaviors;
23
13
  private readonly elementTypes;
24
- private readonly options;
14
+ private options;
25
15
  private readonly modes;
26
16
  private currentMode;
27
17
  private readonly code;
@@ -30,16 +20,19 @@ export declare class MorphicToolboxCanvas {
30
20
  private previewContainer?;
31
21
  /** The preview workspace's own theme and font, before any tile font. */
32
22
  private previewBase?;
33
- private readonly onDragOver;
34
- private readonly onDrop;
35
23
  /** Targets besides the workspace, such as codespaces, for touch drags. */
36
24
  private readonly dropTargets;
25
+ private readonly workspaceTarget;
26
+ /** Ends the drag of a tile that is going on, without a drop. */
27
+ private endDrag;
37
28
  /** Names of the collapsed categories; kept across redraws. */
38
29
  private readonly collapsedCategories;
39
30
  /** Each drawn category's parts, to collapse or expand without a redraw. */
40
31
  private categoryParts;
41
32
  /** The category shown with the `"tabs"` layout; the first one until chosen. */
42
33
  private activeCategory?;
34
+ /** Tiles under their categories, or one list; presets switch it. */
35
+ private grouped;
43
36
  private readonly onScroll;
44
37
  private readonly resizeObserver;
45
38
  /** Adds a tile's block when the tile is chosen with the keyboard. */
@@ -57,11 +50,17 @@ export declare class MorphicToolboxCanvas {
57
50
  /** Code element settings; their highlighting colours code shown as text. */
58
51
  code?: Record<string, MorphicCodeElementConfig>;
59
52
  options?: MorphicToolboxCanvasOptions;
53
+ /** Whether tiles are grouped under the categories. Default `true`. */
54
+ grouped?: boolean;
60
55
  /** Called once with the hidden workspace used to draw block previews. */
61
56
  onPreviewWorkspace?: (workspace: Blockly.WorkspaceSvg) => void;
62
57
  dropTargets?: () => TileDropTarget[];
63
58
  onChoose?: (blockType: string) => void;
64
59
  });
60
+ /** Group the tiles under the categories (`true`) or show one list, from the next render on. */
61
+ setGrouped(grouped: boolean): void;
62
+ /** Show only these blocks (all when `undefined`) from the next render on. */
63
+ setBlocks(blocks: string[] | undefined): void;
65
64
  rerender(mode: MorphicModeName): void;
66
65
  dispose(): void;
67
66
  /**
@@ -93,13 +92,32 @@ export declare class MorphicToolboxCanvas {
93
92
  * images by their alt text. The identifier when the mode shows nothing.
94
93
  */
95
94
  private tileName;
96
- /** The target under a point: a codespace, else the workspace. */
95
+ /** The target under a point: a codespace or an added workspace, else the workspace. */
97
96
  private dropTargetAt;
98
97
  /**
99
- * Drag a tile with a finger or pen: a copy of the tile follows the pointer
100
- * and the block is made where it is let go.
98
+ * The target for a dragged tile at a point, and the point in it. A view
99
+ * that was just left stays the target a little past its edge: views lie
100
+ * side by side with a divider between them, and there the tile would show
101
+ * as a tile again for a moment, or flicker when it is held on the line.
102
+ * Over the toolbox, or over another view, the old one is left at once.
103
+ */
104
+ private heldTargetAt;
105
+ /**
106
+ * Drag a tile: a copy of the tile follows the pointer and the block is made
107
+ * where it is let go. The mouse drags once it moves; a finger or pen once it
108
+ * moves sideways or is held, since up and down scrolls the toolbox.
109
+ */
110
+ private attachDrag;
111
+ /**
112
+ * The layer a dragged tile is shown in. It stays inside the toolbox, so the
113
+ * toolbox's and the mode's styles reach the copy, but the browser draws it
114
+ * on top of the page (as a popover), where nothing around the toolbox cuts
115
+ * it off. A browser without that keeps it in the toolbox, which then drops
116
+ * the fade at its edges for as long as the drag lasts.
101
117
  */
102
- private attachTouchDrag;
118
+ private createDragLayer;
119
+ /** The block as a code element writes it, as what follows the pointer over a codespace. */
120
+ private createDragText;
103
121
  private ensurePreviewWorkspace;
104
122
  /**
105
123
  * The tile shows a copy of the rendered block outside Blockly, so its text
@@ -117,7 +135,6 @@ export declare class MorphicToolboxCanvas {
117
135
  */
118
136
  private createCodeText;
119
137
  private createBlockPreviewSvg;
120
- private createBlockAtPosition;
121
138
  private resolveBlockIds;
122
139
  private resolveCategoryBlockIds;
123
140
  }