morphic-blocks 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 CHANGED
@@ -28,21 +28,22 @@ npm i morphic-blocks
28
28
 
29
29
  Blockly comes with it. Its images and sounds (trash can, zoom buttons, clicks)
30
30
  load from your own site, so visitors' browsers never contact another server.
31
- Copy them to `blockly-media/` next to your page before `dev` and `build`:
31
+ A bundler plugin copies them to `public/blockly-media/` when `dev` or `build`
32
+ starts:
32
33
 
33
- ```json
34
- "scripts": {
35
- "dev": "morphic-blocks copy-media public/blockly-media && vite",
36
- "build": "morphic-blocks copy-media public/blockly-media && vite build"
37
- }
34
+ ```ts
35
+ // vite.config.ts (also morphic-blocks/webpack, /rspack, /rollup, /esbuild)
36
+ import blocklyMedia from "morphic-blocks/vite";
37
+ export default { plugins: [blocklyMedia()] };
38
38
  ```
39
39
 
40
- `public/` is Vite's folder for static files; use your bundler's equivalent.
41
- You can still load them from Blockly's server instead; see
40
+ With Parcel, Turbopack or no bundler, run `morphic-blocks copy-media
41
+ public/blockly-media` before `dev` and `build` instead. You can still load them
42
+ from Blockly's server; see
42
43
  [Privacy & External Requests](https://docs.morphicblocks.com/guides/privacy/).
43
44
 
44
- The text views (codespace, preview, code editor) use CodeMirror. Install it
45
- only if you use them:
45
+ The text views (codespace, code editor) use CodeMirror. Install it only if
46
+ you use them:
46
47
 
47
48
  ```sh
48
49
  npm i @codemirror/state @codemirror/view @codemirror/lang-javascript
@@ -57,19 +58,19 @@ A block is defined once, with one element per representation:
57
58
  {
58
59
  "elementTypes": {
59
60
  "title": "text",
60
- "conceptual": "code",
61
+ "concept": "code",
61
62
  "python": "code"
62
63
  },
63
64
  "modes": [
64
- { "name": "conceptual", "elements": ["title", "conceptual"] },
65
- { "name": "python", "elements": ["title", "python"] }
65
+ { "name": "concept-tiles", "elements": ["title", "concept"] },
66
+ { "name": "python-tiles", "elements": ["title", "python"] }
66
67
  ],
67
68
  "blocks": [
68
69
  {
69
70
  "identifier": "text_print",
70
71
  "elements": {
71
72
  "title": "Print",
72
- "conceptual": "Output %1",
73
+ "concept": "Output %1",
73
74
  "python": "print(%1)"
74
75
  },
75
76
  "inputSlots": {
@@ -109,30 +110,34 @@ engine.mount({
109
110
  });
110
111
 
111
112
  // Switch the representation at runtime; the same blocks re-render.
112
- engine.setModes({ workspaceMode: "python", toolboxMode: "python" });
113
+ engine.show({ toolbox: "python-tiles", views: { workspace: "python" } });
113
114
  ```
114
115
 
115
116
  ## How it works
116
117
 
117
118
  1. **Definitions** name each block's elements: labels, images and code
118
119
  templates.
119
- 2. **Modes** choose which elements show, one CSS file per mode styles them.
120
- 3. **Views** (workspace, toolbox, codespace, preview) each show a mode, and
121
- presets switch them together.
120
+ 2. **Modes** choose which elements the toolbox tiles show; one CSS file per
121
+ mode styles them.
122
+ 3. **Views** (workspaces and codespaces, declared by name) each show a code
123
+ element, and presets switch the toolbox and the views together.
122
124
 
123
125
  ## Features
124
126
 
125
127
  - **One definition, many representations:** define a block once and show it
126
128
  as icons, blocks or source text, switchable at runtime.
127
- - **Blocks and text side by side:** an editable text view of the program, a
128
- read only preview and selection that follows across views.
129
+ - **Blocks and text side by side:** editable and read-only text views of the
130
+ program, any number of views, and selection that follows across them.
129
131
  - **Config driven:** blocks in JSON, behaviors in TypeScript, one CSS file per
130
132
  mode, with no duplication per representation.
131
133
  - **Headless and embeddable:** bring your own UI; the framework stays unstyled.
132
134
  - **Accessible toolbox:** tiles work with a mouse, a finger, a pen or the
133
- keyboard, with names for screen readers.
135
+ keyboard, with names for screen readers; categories have headings, collapse,
136
+ or show as tabs.
134
137
  - **No external requests:** the framework never contacts another server,
135
138
  Blockly's media included.
139
+ - **Themes:** ready-made code view colors in
140
+ [`@morphicblocks/themes`](https://www.npmjs.com/package/@morphicblocks/themes).
136
141
 
137
142
  ## Documentation
138
143
 
@@ -21,6 +21,11 @@
21
21
  "type": "array",
22
22
  "items": { "$ref": "#/$defs/mode" }
23
23
  },
24
+ "views": {
25
+ "description": "The views by name; mount() sets up each one it gets a container for. The first workspace with a container holds the program.",
26
+ "type": "object",
27
+ "additionalProperties": { "$ref": "#/$defs/view" }
28
+ },
24
29
  "presets": {
25
30
  "type": "array",
26
31
  "items": { "$ref": "#/$defs/preset" }
@@ -42,7 +47,7 @@
42
47
  "additionalProperties": false,
43
48
  "$defs": {
44
49
  "elementType": {
45
- "enum": ["text", "code", "image"]
50
+ "enum": ["text", "code", "image", "custom"]
46
51
  },
47
52
  "elementTypeEntry": {
48
53
  "oneOf": [
@@ -77,6 +82,11 @@
77
82
  "description": "Written into an empty statement slot where an empty body is invalid, e.g. \"pass\" for Python.",
78
83
  "type": "string"
79
84
  },
85
+ "types": {
86
+ "description": "Names %1:type writes, keyed by the value's type (its output check, or the slot's check while empty), e.g. { \"Number\": \"int\", \"default\": \"var\" }.",
87
+ "type": "object",
88
+ "additionalProperties": { "type": "string" }
89
+ },
80
90
  "highlighting": { "$ref": "#/$defs/highlight" },
81
91
  "values": {
82
92
  "description": "How printed values are written while this element is shown, e.g. Python's True, None and ['a', 'b'].",
@@ -125,21 +135,34 @@
125
135
  "elements": {
126
136
  "type": "array",
127
137
  "items": { "type": "string" }
138
+ },
139
+ "render": {
140
+ "description": "How the mode's code elements are drawn on toolbox tiles, by element name. Blocks unless \"text-based\".",
141
+ "type": "object",
142
+ "additionalProperties": { "enum": ["block-based", "text-based"] }
128
143
  }
129
144
  },
130
145
  "additionalProperties": false
131
146
  },
132
- "presetToolbox": {
147
+ "view": {
133
148
  "oneOf": [
134
- { "type": "string" },
149
+ { "enum": ["workspace", "codespace"] },
135
150
  {
136
151
  "type": "object",
137
- "required": ["mode"],
152
+ "required": ["kind"],
138
153
  "properties": {
139
- "mode": { "type": "string" },
140
- "render": {
154
+ "kind": { "enum": ["workspace", "codespace"] },
155
+ "editable": { "description": "Whether the program can be changed in the view. Default true.", "type": "boolean" },
156
+ "rtl": { "description": "Right to left (true) or left to right (false). Left out, a workspace follows blockly.rtl and a codespace the page.", "type": "boolean" },
157
+ "delete": {
158
+ "description": "How blocks are deleted in a codespace; each way is on unless set to false.",
141
159
  "type": "object",
142
- "additionalProperties": { "enum": ["block", "text"] }
160
+ "properties": {
161
+ "lineButtons": { "type": "boolean" },
162
+ "keys": { "type": "boolean" },
163
+ "toolbarButton": { "type": "boolean" }
164
+ },
165
+ "additionalProperties": false
143
166
  }
144
167
  },
145
168
  "additionalProperties": false
@@ -148,16 +171,13 @@
148
171
  },
149
172
  "preset": {
150
173
  "type": "object",
151
- "required": ["name", "toolbox"],
174
+ "required": ["name", "toolbox", "views"],
152
175
  "properties": {
153
176
  "name": { "type": "string" },
154
177
  "label": { "type": "string" },
155
- "toolbox": { "$ref": "#/$defs/presetToolbox" },
156
- "workspace": { "type": "string" },
157
- "codespace": { "type": "string" },
158
- "preview": { "type": "string" },
178
+ "toolbox": { "description": "The mode of the toolbox tiles.", "type": "string" },
159
179
  "views": {
160
- "description": "Modes of views added with addView(), by view name.",
180
+ "description": "What each view the preset shows shows, by view name.",
161
181
  "type": "object",
162
182
  "additionalProperties": { "type": "string" }
163
183
  }
@@ -237,7 +257,24 @@
237
257
  "required": ["value"],
238
258
  "properties": {
239
259
  "value": { "type": "string" },
240
- "label": { "type": "string" },
260
+ "label": {
261
+ "description": "Text, or a picture (image file or color swatch) shown on the block instead of text (text views still write the value).",
262
+ "oneOf": [
263
+ { "type": "string" },
264
+ {
265
+ "type": "object",
266
+ "oneOf": [{ "required": ["src"] }, { "required": ["color"] }],
267
+ "properties": {
268
+ "src": { "type": "string" },
269
+ "color": { "type": "string", "description": "A CSS color drawn as a swatch, e.g. #e53935." },
270
+ "alt": { "type": "string", "description": "What screen readers say. Default: the value." },
271
+ "width": { "type": "number", "description": "Default 16." },
272
+ "height": { "type": "number", "description": "Default 16." }
273
+ },
274
+ "additionalProperties": false
275
+ }
276
+ ]
277
+ },
241
278
  "display": {
242
279
  "type": "object",
243
280
  "description": "Per-element display text (element name → shown text). Overrides label/value when that element is rendered; the value still drives execution and codegen.",
package/dist/cli.js CHANGED
@@ -1,7 +1,8 @@
1
1
  #!/usr/bin/env node
2
- import { readFileSync, existsSync, cpSync, writeFileSync } from "node:fs";
3
- import { createRequire } from "node:module";
4
- import { dirname, join, resolve } from "node:path";
2
+ import { c as copyBlocklyMedia } from "./copy-media-CllRyMqQ.js";
3
+ import "node:fs";
4
+ import "node:module";
5
+ import "node:path";
5
6
  const USAGE = `Usage: morphic-blocks copy-media <folder>
6
7
 
7
8
  Copies Blockly's images, cursors and sounds into <folder>, so your app serves
@@ -12,7 +13,6 @@ unless you set blockly.media, so copy them to the folder served there:
12
13
 
13
14
  Copies only when the folder is new or Blockly was updated, so it can run
14
15
  before every dev or build.`;
15
- const MARKER = ".blockly-version";
16
16
  const [command, folder, ...rest] = process.argv.slice(2);
17
17
  if (command === "--help" || command === "-h") {
18
18
  console.log(USAGE);
@@ -20,17 +20,6 @@ if (command === "--help" || command === "-h") {
20
20
  console.error(USAGE);
21
21
  process.exitCode = 1;
22
22
  } else {
23
- const require2 = createRequire(import.meta.url);
24
- const blockly = dirname(require2.resolve("blockly"));
25
- const version = JSON.parse(readFileSync(join(blockly, "package.json"), "utf8")).version;
26
- const target = resolve(folder);
27
- const marker = join(target, MARKER);
28
- if (existsSync(marker) && readFileSync(marker, "utf8").trim() === version) {
29
- console.log(`Blockly ${version} media is already in ${folder}`);
30
- } else {
31
- cpSync(join(blockly, "media"), target, { recursive: true });
32
- writeFileSync(marker, `${version}
33
- `);
34
- console.log(`Copied Blockly ${version} media to ${folder}`);
35
- }
23
+ const { version, copied } = copyBlocklyMedia(folder);
24
+ console.log(copied ? `Copied Blockly ${version} media to ${folder}` : `Blockly ${version} media is already in ${folder}`);
36
25
  }
@@ -0,0 +1,21 @@
1
+ import { readFileSync, existsSync, cpSync, writeFileSync } from "node:fs";
2
+ import { createRequire } from "node:module";
3
+ import { dirname, join, resolve } from "node:path";
4
+ const MARKER = ".blockly-version";
5
+ function copyBlocklyMedia(folder) {
6
+ const require2 = createRequire(import.meta.url);
7
+ const blockly = dirname(require2.resolve("blockly"));
8
+ const version = JSON.parse(readFileSync(join(blockly, "package.json"), "utf8")).version;
9
+ const target = resolve(folder);
10
+ const marker = join(target, MARKER);
11
+ if (existsSync(marker) && readFileSync(marker, "utf8").trim() === version) {
12
+ return { version, copied: false };
13
+ }
14
+ cpSync(join(blockly, "media"), target, { recursive: true });
15
+ writeFileSync(marker, `${version}
16
+ `);
17
+ return { version, copied: true };
18
+ }
19
+ export {
20
+ copyBlocklyMedia as c
21
+ };
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Copy Blockly's media into `folder`, unless it holds this Blockly version's
3
+ * media already, so it can run before every dev or build.
4
+ */
5
+ export declare function copyBlocklyMedia(folder: string): {
6
+ version: string;
7
+ copied: boolean;
8
+ };
@@ -0,0 +1,3 @@
1
+ export type { BlocklyMediaOptions } from "./plugin";
2
+ declare const _default: (options?: import("./plugin").BlocklyMediaOptions | undefined) => import("unplugin").EsbuildPlugin;
3
+ export default _default;
@@ -0,0 +1,10 @@
1
+ import { b as blocklyMedia } from "./plugin-h3QH8ods.js";
2
+ import "unplugin";
3
+ import "./copy-media-CllRyMqQ.js";
4
+ import "node:fs";
5
+ import "node:module";
6
+ import "node:path";
7
+ const esbuild = blocklyMedia.esbuild;
8
+ export {
9
+ esbuild as default
10
+ };
package/dist/index.d.ts CHANGED
@@ -8,4 +8,4 @@ export { makeResizable } from "./morphic/resize";
8
8
  export { validateDefinitions } from "./morphic/validate-definitions";
9
9
  export type { ValidateDefinitionsArgs, DefinitionValidationResult, } from "./morphic/validate-definitions";
10
10
  export type { MorphicResizeOptions, MorphicResizeHandle, } from "./morphic/resize";
11
- export type { MorphicElementType, MorphicElementTypeConfig, MorphicElementTypeEntry, MorphicEmptyDefaultConfig, MorphicHighlightDefinition, MorphicJavaScriptConfig, MorphicBehaviorContext, MorphicBehaviorDefinition, MorphicBehaviorMap, MorphicBehaviorProxy, MorphicBlockBehavior, MorphicBlockDefinition, MorphicBlockShape, MorphicBlocksFormat, MorphicBlocksFormatJson, MorphicCodeElementConfig, MorphicValueFormat, MorphicViewHandle, MorphicViewKind, MorphicViewOptions, MorphicCodeBehavior, MorphicCodeBlockPosition, MorphicCodeEditorOptions, MorphicCodeEditorTheme, MorphicCodeGenerationResult, MorphicCodeMetadata, MorphicConnectionSpec, MorphicDropdownOption, MorphicFieldDefinition, MorphicInputAlign, MorphicInputKind, MorphicInputSlotDefinition, MorphicModeName, MorphicMountConfig, MorphicPlaceholderEditTarget, MorphicPlaceholderRange, MorphicRenderContext, MorphicResolvedView, MorphicStyleBundle, MorphicToolbarConfig, MorphicToolbarCtx, MorphicToolbarDisplay, MorphicToolbarItem, MorphicToolbarPane, MorphicToolbarRender, MorphicToolboxCanvasOptions, MorphicToolboxCategory, MorphicToolboxConfig, MorphicToolboxLayout, MorphicToolboxModeLabel, MorphicBlockElements, MorphicModeDefinition, MorphicPresetDefinition, MorphicRunOutputLine, MorphicRunResult, MorphicPresetToolbox, MorphicSelectionSyncOptions, } from "./morphic/types";
11
+ export type { MorphicElementType, MorphicElementTypeConfig, MorphicElementTypeEntry, MorphicEmptyDefaultConfig, MorphicHighlightDefinition, MorphicJavaScriptConfig, MorphicBehaviorContext, MorphicBehaviorDefinition, MorphicBehaviorMap, MorphicBehaviorProxy, MorphicBlockBehavior, MorphicBlockDefinition, MorphicBlockShape, MorphicBlocksFormat, MorphicBlocksFormatJson, MorphicCodeElementConfig, MorphicValueFormat, MorphicViewHandle, MorphicViewDeclaration, MorphicViewKind, MorphicViewOptions, MorphicCodeBehavior, MorphicCodeBlockPosition, MorphicCodeEditorOptions, MorphicCodeEditorTheme, MorphicCodespaceDeleteOptions, MorphicCodeGenerationResult, MorphicCodeMetadata, MorphicConnectionSpec, MorphicDropdownImage, MorphicElementRenderContext, MorphicElementRenderer, MorphicDropdownOption, MorphicFieldDefinition, MorphicInputAlign, MorphicInputKind, MorphicInputSlotDefinition, MorphicModeName, MorphicMountConfig, MorphicPlaceholderEditTarget, MorphicPlaceholderRange, MorphicRenderContext, MorphicResolvedView, MorphicStyleBundle, MorphicToolbarConfig, MorphicToolbarCtx, MorphicToolbarDisplay, MorphicToolbarItem, MorphicToolbarRender, MorphicToolboxCanvasOptions, MorphicToolboxCategory, MorphicToolboxConfig, MorphicToolboxLayout, MorphicToolboxModeLabel, MorphicBlockElements, MorphicModeDefinition, MorphicTileRender, MorphicPresetDefinition, MorphicRunOutputLine, MorphicRunResult, MorphicSelectionSyncOptions, } from "./morphic/types";
@@ -1,6 +1,6 @@
1
1
  import * as Blockly from "blockly";
2
2
  import { type MorphicToolbarHandle } from "./toolbar";
3
- import type { MorphicBehaviorMap, MorphicBlocksFormat, MorphicBlocksFormatJson, MorphicCodeEditorOptions, MorphicCodeEditorTheme, MorphicCodeGenerationResult, MorphicModeName, MorphicMountConfig, MorphicPresetDefinition, MorphicRunResult, MorphicSelectionSyncOptions, MorphicToolbarConfig, MorphicToolboxCanvasOptions, MorphicViewHandle, MorphicViewOptions } from "./types";
3
+ import type { MorphicBehaviorMap, MorphicBlocksFormat, MorphicBlocksFormatJson, MorphicCodeEditorOptions, MorphicCodeEditorTheme, MorphicCodespaceDeleteOptions, MorphicCodeGenerationResult, MorphicModeName, MorphicMountConfig, MorphicPresetDefinition, MorphicRunResult, MorphicSelectionSyncOptions, MorphicToolbarConfig, MorphicToolboxCanvasOptions, MorphicViewHandle, MorphicViewOptions } from "./types";
4
4
  export declare class MorphicBlocks extends EventTarget {
5
5
  private readonly definitions;
6
6
  private readonly behaviors;
@@ -21,18 +21,15 @@ export declare class MorphicBlocks extends EventTarget {
21
21
  /** Codespaces a tile dragged by touch or pen can be dropped on. */
22
22
  private readonly tileDropTargets;
23
23
  private codeEditor?;
24
- private codespace?;
25
- private previewEditor?;
26
24
  /** Views added with `addView()`, beside the ones `mount()` sets up. */
27
25
  private readonly views;
28
26
  /** The mode of each added workspace, read when its blocks are built. */
29
- private readonly viewWorkspaceModes;
27
+ private readonly viewWorkspaceElements;
30
28
  /** Numbers added views that are not given a name. */
31
29
  private viewCount;
32
30
  private selectionSync?;
33
31
  private toolboxDefinition?;
34
32
  /** Container the preview editor was mounted into. */
35
- private previewHost?;
36
33
  private blockCategoryIndex;
37
34
  private appliedWorkspaceClasses;
38
35
  private appliedToolboxFlyoutClasses;
@@ -40,7 +37,6 @@ export declare class MorphicBlocks extends EventTarget {
40
37
  /** Offscreen div created when no user-supplied workspaceContainer is present. */
41
38
  private headlessWorkspaceHost?;
42
39
  /** Teardown fn for codespace drag/drop listeners; set when codespace is mounted. */
43
- private codespaceDropTeardown?;
44
40
  /** Redraws the workspace whenever its container changes size. */
45
41
  private workspaceResizeObserver?;
46
42
  /** Preset most recently applied, at mount or via `applyPreset`. */
@@ -57,6 +53,7 @@ export declare class MorphicBlocks extends EventTarget {
57
53
  * runtime `mount()` call only carries DOM / runtime concerns. */
58
54
  private readonly formatModes?;
59
55
  private readonly formatPresets?;
56
+ private readonly formatViews?;
60
57
  private readonly formatCode?;
61
58
  /** The definitions still use the old top level `highlighting` map. */
62
59
  private readonly formatHasHighlighting;
@@ -81,6 +78,12 @@ export declare class MorphicBlocks extends EventTarget {
81
78
  * when the engine was disposed or mounted again meanwhile.
82
79
  */
83
80
  private mountViews;
81
+ /** Mark every view's container with the preset applied last. */
82
+ private applyPresetClasses;
83
+ /** Whether any text editor is set up, which selection sync needs. */
84
+ private hasTextEditor;
85
+ /** The first codespace that edits the program, if any. */
86
+ private get codespace();
84
87
  /** Presets declared at mount (empty when none were provided). */
85
88
  getPresets(): MorphicPresetDefinition[];
86
89
  /**
@@ -125,15 +128,10 @@ export declare class MorphicBlocks extends EventTarget {
125
128
  * `icon` or `python` is not a mode unless a mode is named after it.
126
129
  */
127
130
  getAvailableModes(): MorphicModeName[];
128
- /** Current workspace mode name, or `undefined` if not mounted. */
129
- getWorkspaceMode(): MorphicModeName | undefined;
130
- /**
131
- * Effective codespace mode name: the independent `codespaceMode` when set,
132
- * else the workspace mode. `undefined` if not mounted.
133
- */
134
- getCodespaceMode(): MorphicModeName | undefined;
135
- /** Preview mode name, or `undefined` when no preview mode is set. */
136
- getPreviewMode(): MorphicModeName | undefined;
131
+ /** The toolbox tiles' mode, or `undefined` if not mounted. */
132
+ getToolboxMode(): MorphicModeName | undefined;
133
+ /** The names of the views that are set up: the declared ones with a container, and added ones. */
134
+ getViewNames(): string[];
137
135
  /**
138
136
  * Change which elements a mode shows while the app runs, e.g. to let the
139
137
  * user pick what a toolbox tile shows. Every view using the mode is redrawn;
@@ -142,10 +140,11 @@ export declare class MorphicBlocks extends EventTarget {
142
140
  setModeElements(mode: MorphicModeName, elements: string[]): void;
143
141
  /** Mode definition by name, or `undefined`. */
144
142
  private modeDef;
145
- /** Source element rendered by the codespace (label + highlighting source). */
146
- getActivePrimarySourceElement(): string | undefined;
147
- /** Source element rendered by the preview (label + highlighting source). */
148
- getActivePreviewElement(): string | undefined;
143
+ /**
144
+ * The element the first codespace writes, else the one the program's
145
+ * workspace shows, e.g. for printed values in its language.
146
+ */
147
+ private codespaceElement;
149
148
  /**
150
149
  * Mount a toolbar into the developer-provided container, bound to one of the
151
150
  * three editor surfaces. When `items` is omitted, the default set for the
@@ -182,13 +181,27 @@ export declare class MorphicBlocks extends EventTarget {
182
181
  }): MorphicRunResult;
183
182
  /** Whether the framework's internal clipboard has a copyable to paste. */
184
183
  hasClipboardContents(): boolean;
184
+ /** The ways to delete blocks in the codespace named `view`, each `true` unless the app turned it off. */
185
+ getDeleteOptions(view: string): Required<MorphicCodespaceDeleteOptions>;
186
+ /** Whether lines are selected in the codespace named `view`, so `deleteSelectedLines()` has something to delete. */
187
+ hasSelectedLines(view: string): boolean;
188
+ /**
189
+ * Delete the blocks of the lines selected in the codespace named `view`, as
190
+ * Delete or Backspace does there. Returns true when lines were selected.
191
+ */
192
+ deleteSelectedLines(view: string): boolean;
185
193
  /**
186
194
  * Copy the currently active block to the framework's internal clipboard and
187
- * mirror its generated code text to the system clipboard. Resolution order:
195
+ * its own text, as the view writes it, to the system clipboard. Resolution order:
188
196
  * (1) Blockly's selected block, (2) for codespace/preview, the deepest block
189
197
  * enclosing the active line. Returns true when something was copied.
190
198
  */
191
199
  copyActiveBlock(view: string): boolean;
200
+ /**
201
+ * A block's own text in a view: its part of the text the view shows (a
202
+ * workspace, the text its mode writes), without the indent it has there.
203
+ */
204
+ private blockTextIn;
192
205
  /**
193
206
  * Paste the last copied block at the active pane's natural location.
194
207
  * Workspace: Blockly's default (workspace centre, slightly offset).
@@ -209,34 +222,25 @@ export declare class MorphicBlocks extends EventTarget {
209
222
  * `zoomToFit()`. For a text view it scales the editor's font-size.
210
223
  */
211
224
  zoomPane(view: string, direction: "in" | "out" | "fit"): void;
225
+ /** Redraw the toolbars of the view named `view`, e.g. when its selected lines change. */
226
+ private refreshToolbars;
212
227
  private ensureToolbarBlocklyListener;
213
228
  private teardownToolbarBlocklyListener;
214
- setModes(modes: {
215
- workspaceMode?: MorphicModeName;
216
- toolboxMode?: MorphicModeName;
217
- /** Per-element block/text override for toolbox tiles. `null` clears it (all code elements render as blocks). */
218
- toolboxRender?: Record<string, "block" | "text"> | null;
219
- /** Independent codespace mode. `null` clears the override (falls back to workspaceMode). */
220
- codespaceMode?: MorphicModeName | null;
221
- /** Preview mode. `null` clears it (preview renders nothing unless the workspace mode declares a legacy `preview`). */
222
- previewMode?: MorphicModeName | null;
223
- }): void;
224
229
  /**
225
- * Resolve the highlight rules for the codespace or preview editor by
226
- * looking up that pane's source element name in the
227
- * `mountConfig.highlighting` registry. Returns `undefined` when no
228
- * matching entry is configured.
230
+ * Switch what the toolbox and the views show, in the shape of a preset:
231
+ * `show({ toolbox: "pseudo", views: { blocks: "pseudo", code: "python" } })`.
232
+ * Everything left out stays as it is; showing and hiding the views'
233
+ * containers stays the app's job.
229
234
  */
230
- private resolveHighlightRules;
235
+ show(shown: {
236
+ toolbox?: MorphicModeName;
237
+ views?: Record<string, string>;
238
+ }): void;
239
+ /** Moved in 0.4.0: `show()` takes its place. */
240
+ setModes(_modes: unknown): never;
231
241
  generateJavaScript(): string;
232
242
  generateJavaScriptWithMetadata(): MorphicCodeGenerationResult;
233
243
  mountCodeEditor(container: HTMLElement, options?: MorphicCodeEditorOptions): Promise<void>;
234
- /**
235
- * Mounts the primary text editor (codespace) into the `codespaceContainer`
236
- * declared at `mount()`. Renders the workspace as text using the codespace
237
- * mode's source element. Read-only for now; Task 4 adds drops.
238
- */
239
- mountCodespace(options?: MorphicCodeEditorOptions): Promise<void>;
240
244
  private attachCodespaceDropTarget;
241
245
  /** Innermost (smallest-range) block in metadata whose char range contains `charOffset`. */
242
246
  private findInnermostBlockAtChar;
@@ -325,11 +329,13 @@ export declare class MorphicBlocks extends EventTarget {
325
329
  private isDescendantOf;
326
330
  /**
327
331
  * Connect `source`'s output into the value input named `inputName` on
328
- * `parent`. A real (non-shadow) child currently in the slot is `unplug`'d
329
- * to top level; a shadow disconnects implicitly when the new block
330
- * connects. The Blockly connection-check (output-type vs slot `check`)
331
- * runs inside `connect`; an incompatible drop throws and is rolled back
332
- * by restoring the prior real child when there was one.
332
+ * `parent`. A real (non-shadow) child currently in the slot goes into the
333
+ * new block's only value input that takes it, as Blockly does on a
334
+ * workspace drop, or else to its own line below the others; a shadow
335
+ * disconnects implicitly when the new block connects. The Blockly
336
+ * connection-check (output-type vs slot `check`) runs inside `connect`; an
337
+ * incompatible drop throws and is rolled back by restoring the prior real
338
+ * child when there was one.
333
339
  */
334
340
  private connectIntoValueSlot;
335
341
  private computeBlockDepth;
@@ -340,17 +346,15 @@ export declare class MorphicBlocks extends EventTarget {
340
346
  private applyTopBlockOrder;
341
347
  /** Write every text view again, added views included. */
342
348
  private refreshTextViews;
349
+ /** The program as `element` writes it, as a codespace shows it. */
350
+ private generateElementText;
351
+ /** Highlight rules of `element`. */
352
+ private highlightRulesFor;
343
353
  /**
344
- * Mounts a read-only preview editor that renders the current mode's
345
- * `preview` element as text. Re-renders on workspace and mode changes.
346
- * If the active mode has no `preview` declared, the editor stays empty.
354
+ * Where nothing says what a view shows: the first code element of the first
355
+ * mode, else the first code element at all.
347
356
  */
348
- mountPreview(container: HTMLElement, options?: MorphicCodeEditorOptions): Promise<void>;
349
- private generatePreviewText;
350
- /** The program as `mode`'s source element writes it, as a preview shows it. */
351
- private generateModeText;
352
- /** Highlight rules of `mode`'s source element. */
353
- private highlightRulesFor;
357
+ private defaultElement;
354
358
  /**
355
359
  * Add a view beside the ones `mount()` sets up, e.g. a second preview in
356
360
  * another mode. Returns a handle to change its mode or remove it; a new
@@ -364,10 +368,19 @@ export declare class MorphicBlocks extends EventTarget {
364
368
  * workspace, so the text views follow a click in the mirror too.
365
369
  */
366
370
  private addWorkspaceView;
367
- /** The mode's classes and block font on an added workspace. */
371
+ /** The element's classes and block font on an added workspace. */
368
372
  private styleWorkspaceView;
369
- /** Draw every block of an added workspace in the view's mode. */
373
+ /**
374
+ * Draw every block of an added workspace in the view's mode, with events
375
+ * off: an editable view would take the redraw for an edit.
376
+ */
370
377
  private renderWorkspaceView;
378
+ /**
379
+ * Tiles dropped on an editable added workspace, with the mouse or by touch,
380
+ * add their block to the main workspace at the same spot; the view shows it
381
+ * with its next copy. Returns the teardown.
382
+ */
383
+ private attachWorkspaceTileDrop;
371
384
  /** Remove an added view and everything it set up. */
372
385
  private disposeView;
373
386
  /**
@@ -378,10 +391,10 @@ export declare class MorphicBlocks extends EventTarget {
378
391
  private linkAddedView;
379
392
  /** A view by name, built in or added; `undefined` when there is none. */
380
393
  private resolveView;
381
- /** The mode a view shows, by name (`workspace`, `codespace`, `preview`, or an added view's). */
382
- getViewMode(name: string): MorphicModeName | undefined;
383
- /** A text view's mode must exist and have a code element to render. */
384
- private checkTextViewMode;
394
+ /** The element a view shows, by name. */
395
+ getViewElement(name: string): string | undefined;
396
+ /** A view shows a code element. */
397
+ private checkViewElement;
385
398
  /**
386
399
  * Write `newValue` to `edit.fieldName` on the Blockly block identified by
387
400
  * `edit.blockId`. The change event listener will trigger codespace re-sync.
@@ -393,14 +406,26 @@ export declare class MorphicBlocks extends EventTarget {
393
406
  * codespace mirrors Blockly's full set of moveable blocks.
394
407
  */
395
408
  private canMoveInCodespace;
409
+ /**
410
+ * Delete the block a line belongs to, or of each line from `line` to
411
+ * `lastLine`: a block inside another one deleted goes with it, and all of
412
+ * it is one undo step.
413
+ */
396
414
  private deleteBlockAtCodespaceLine;
397
- private generateCodespaceText;
415
+ /**
416
+ * The block a line belongs to, as the workspace would delete it: the
417
+ * statement that starts on the line (the innermost, for nested one-line
418
+ * templates), else the innermost statement around it (a closing `}`), and a
419
+ * value only where it stands as its own group. Defaults (shadows) are never
420
+ * picked; deleting one changes nothing.
421
+ */
422
+ private blockOwningLine;
398
423
  showCodeEditor(): void;
399
424
  hideCodeEditor(): void;
400
425
  isCodeEditorVisible(): boolean;
401
426
  setCodeEditorTheme(theme: MorphicCodeEditorTheme): void;
402
- setCodespaceTheme(theme: MorphicCodeEditorTheme): void;
403
- setPreviewTheme(theme: MorphicCodeEditorTheme): void;
427
+ /** Colours of a text view, by name, e.g. on a light and dark switch. */
428
+ setViewTheme(view: string, theme: MorphicCodeEditorTheme): void;
404
429
  /**
405
430
  * Enable bidirectional selection sync between the Blockly workspace and every
406
431
  * currently-mounted editor (code editor, codespace, preview). Requires at
@@ -419,7 +444,7 @@ export declare class MorphicBlocks extends EventTarget {
419
444
  private registerBlocks;
420
445
  /** Build a newly created block with this engine's definition, mode and behavior. */
421
446
  private initManagedBlock;
422
- private validateContainers;
447
+ private validateViews;
423
448
  private createHeadlessHost;
424
449
  private resolveMode;
425
450
  private applyView;
@@ -429,7 +454,6 @@ export declare class MorphicBlocks extends EventTarget {
429
454
  * is styled again once it does.
430
455
  */
431
456
  private styleBlock;
432
- private applyTextViewClasses;
433
457
  private applyWorkspaceContainerClass;
434
458
  /**
435
459
  * Measure block text with the font the workspace mode's CSS draws it in.