morphic-blocks 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.
@@ -1,4 +1,4 @@
1
- import type { MorphicModeDefinition, MorphicModeName, MorphicStyleBundle, MorphicToolboxCategory } from "./types";
1
+ import type { MorphicHighlightDefinition, MorphicModeDefinition, MorphicModeName, MorphicStyleBundle, MorphicToolboxCategory } from "./types";
2
2
  /**
3
3
  * One mode's stylesheet, a link or the CSS itself. Hosts pass `modesFolder` or
4
4
  * the `modeStyles` map; the engine merges both into a list of these.
@@ -20,7 +20,7 @@ export declare class MorphicStyleManager {
20
20
  * Hides all morphic elements by default, then shows only those listed
21
21
  * in each mode's `elements` array. Developer CSS only needs to handle styling.
22
22
  */
23
- ensureModeVisibilityStyles(modes: MorphicModeDefinition[]): void;
23
+ ensureModeVisibilityStyles(modes: MorphicModeDefinition[], previousModes?: MorphicModeDefinition[]): void;
24
24
  ensureStyles(baseStyle: MorphicStyleBundle | undefined, modeStyles: MorphicModeStyle[]): void;
25
25
  /**
26
26
  * Inject the framework-shipped toolbar layout CSS once per document. The
@@ -30,7 +30,25 @@ export declare class MorphicStyleManager {
30
30
  * the host theme without overriding class selectors.
31
31
  */
32
32
  ensureToolbarStyles(): Promise<void>;
33
+ /**
34
+ * Blockly outlines the workspace background with a grey line. It is left
35
+ * out by default and styleable through two CSS variables, e.g.
36
+ * `--morphic-workspace-border-color: #ccc`.
37
+ */
38
+ ensureWorkspaceStyles(): void;
33
39
  ensureCategoryStyles(categories: MorphicToolboxCategory[]): void;
34
- validateModeCoverage(modeStyles: MorphicModeStyle[], definitionModes: MorphicModeName[]): void;
40
+ validateModeCoverage(modeStyles: MorphicModeStyle[], definitionModes: MorphicModeName[], warn?: (message: string) => void): void;
35
41
  private ensureStyleBundle;
36
42
  }
43
+ /**
44
+ * Token colours for code shown as text on toolbox tiles, per code element:
45
+ * the element's own `highlighting.colors`, or the codespace's defaults.
46
+ */
47
+ export declare function ensureTileHighlightStyles(elementName: string, colors?: MorphicHighlightDefinition["colors"]): void;
48
+ /**
49
+ * Tiles leave up and down swipes to the browser, so the toolbox scrolls; a
50
+ * sideways swipe drags the tile. A long press drags too, so the press must not
51
+ * select text or open the phone's menu. Apps with a sideways toolbox set
52
+ * `touch-action: pan-x` on their tiles.
53
+ */
54
+ export declare function ensureTileTouchStyles(): void;
@@ -11,4 +11,17 @@ type Extension = import("@codemirror/state").Extension;
11
11
  * result through a `Compartment` unconditionally.
12
12
  */
13
13
  export declare function buildHighlightExtensions(cmView: typeof import("@codemirror/view"), cmState: typeof import("@codemirror/state"), rules: MorphicHighlightDefinition | undefined): Extension[];
14
+ export type MorphicTokenKind = "keyword" | "string" | "number" | "comment";
15
+ /** A highlighted stretch of one line, by character offsets. */
16
+ export interface MorphicToken {
17
+ from: number;
18
+ to: number;
19
+ kind: MorphicTokenKind;
20
+ }
21
+ /**
22
+ * The tokens one line of text holds under a set of highlight rules, in line
23
+ * order. Shared by the text views and the toolbox tiles, so both colour code
24
+ * the same way.
25
+ */
26
+ export declare function tokenMatcher(rules: MorphicHighlightDefinition): (line: string) => MorphicToken[];
14
27
  export {};
@@ -13,4 +13,8 @@ import type { MorphicBlockDefinition, MorphicCodeGenerationResult, MorphicElemen
13
13
  * covers the first-line-emitted-from-its-template through the last; a block
14
14
  * whose template wraps children (e.g. `if`) covers its children's lines too.
15
15
  */
16
- export declare function generateTextFromWorkspace(workspace: Blockly.Workspace, mode: MorphicModeName, definitions: ReadonlyMap<string, MorphicBlockDefinition>, elementTypes: Record<string, MorphicElementTypeEntry>, modeDefs: MorphicModeDefinition[], elementOverride?: string): MorphicCodeGenerationResult;
16
+ export declare function generateTextFromWorkspace(workspace: Blockly.Workspace, mode: MorphicModeName, definitions: ReadonlyMap<string, MorphicBlockDefinition>, elementTypes: Record<string, MorphicElementTypeEntry>, modeDefs: MorphicModeDefinition[], elementOverride?: string,
17
+ /** `emptyStatements: false` leaves empty statement slots empty (toolbox tiles). */
18
+ options?: {
19
+ emptyStatements?: boolean;
20
+ }): MorphicCodeGenerationResult;
@@ -4,7 +4,10 @@ export type MorphicRunEventDetail = MorphicRunResult;
4
4
  export interface MorphicToolbarHandle {
5
5
  refresh: () => void;
6
6
  dispose: () => void;
7
+ /** The kind of view the toolbar acts on. */
7
8
  pane: MorphicToolbarPane;
9
+ /** The name of the view the toolbar acts on. */
10
+ view: string;
8
11
  }
9
12
  export declare const toolbarItems: {
10
13
  /** "Mode: <name>" label for the pane's active mode. */
@@ -43,6 +46,8 @@ export declare const toolbarItems: {
43
46
  togglePreview(): MorphicToolbarItem;
44
47
  readOnlyBadge(): MorphicToolbarItem;
45
48
  spacer(): MorphicToolbarItem;
49
+ /** Items for a view that shows the program but cannot change it. */
50
+ readOnlyDefaults(): MorphicToolbarItem[];
46
51
  defaultsFor(pane: MorphicToolbarPane): MorphicToolbarItem[];
47
52
  };
48
53
  export declare function renderToolbar(container: HTMLElement, config: MorphicToolbarConfig, ctx: MorphicToolbarCtx): MorphicToolbarHandle;
@@ -1,6 +1,18 @@
1
1
  import * as Blockly from "blockly";
2
- import type { MorphicBehaviorMap, MorphicBlockDefinition, MorphicElementTypeEntry, MorphicModeDefinition, MorphicModeName, MorphicToolboxCanvasOptions } from "./types";
2
+ import type { MorphicBehaviorMap, MorphicBlockDefinition, MorphicElementTypeEntry, MorphicModeDefinition, MorphicCodeElementConfig, MorphicModeName, MorphicToolboxCanvasOptions } from "./types";
3
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
+ }
4
16
  export declare class MorphicToolboxCanvas {
5
17
  private readonly container;
6
18
  private readonly workspaceContainer;
@@ -12,6 +24,7 @@ export declare class MorphicToolboxCanvas {
12
24
  private readonly options;
13
25
  private readonly modes;
14
26
  private currentMode;
27
+ private readonly code;
15
28
  /** Per-element block/text override for code elements in tiles (from the active preset). */
16
29
  private renderOverride?;
17
30
  private previewWorkspace?;
@@ -21,6 +34,10 @@ export declare class MorphicToolboxCanvas {
21
34
  private previewBase?;
22
35
  private readonly onDragOver;
23
36
  private readonly onDrop;
37
+ /** Targets besides the workspace, such as codespaces, for touch drags. */
38
+ private readonly dropTargets;
39
+ /** Adds a tile's block when the tile is chosen with the keyboard. */
40
+ private readonly onChoose?;
24
41
  constructor(params: {
25
42
  container: HTMLElement;
26
43
  workspaceContainer: HTMLElement;
@@ -32,20 +49,58 @@ export declare class MorphicToolboxCanvas {
32
49
  mode: MorphicModeName;
33
50
  render?: Record<string, "block" | "text">;
34
51
  modes?: MorphicModeDefinition[];
52
+ /** Code element settings; their highlighting colours code shown as text. */
53
+ code?: Record<string, MorphicCodeElementConfig>;
35
54
  options?: MorphicToolboxCanvasOptions;
36
55
  /** Called once with the hidden workspace used to draw block previews. */
37
56
  onPreviewWorkspace?: (workspace: Blockly.WorkspaceSvg) => void;
57
+ dropTargets?: () => TileDropTarget[];
58
+ onChoose?: (blockType: string) => void;
38
59
  });
39
60
  rerender(mode: MorphicModeName, render?: Record<string, "block" | "text">): void;
40
61
  dispose(): void;
62
+ /**
63
+ * Draw the tiles and publish the widest block's width as
64
+ * `--morphic-toolbox-block-width` on the container. The layout stays the
65
+ * app's: one that wants every block to fit gives the container
66
+ * `min-width: calc(var(--morphic-toolbox-block-width) + <padding>)` and
67
+ * lets its column grow to it (`minmax(250px, min-content)`). Only blocks
68
+ * count, so long descriptions, which wrap, do not widen it.
69
+ */
41
70
  private render;
71
+ /** Widest block drawn on a tile in the current render, in pixels. */
72
+ private widestBlock;
73
+ private renderTiles;
42
74
  private createTile;
75
+ /**
76
+ * What a screen reader calls the tile: what the tile shows, in the mode's
77
+ * order. Code is read as the codespace would write it, text as it is, and
78
+ * images by their alt text. The identifier when the mode shows nothing.
79
+ */
80
+ private tileName;
81
+ /** The target under a point: a codespace, else the workspace. */
82
+ private dropTargetAt;
83
+ /**
84
+ * Drag a tile with a finger or pen: a copy of the tile follows the pointer
85
+ * and the block is made where it is let go.
86
+ */
87
+ private attachTouchDrag;
43
88
  private ensurePreviewWorkspace;
44
89
  /**
45
90
  * The tile shows a copy of the rendered block outside Blockly, so its text
46
91
  * takes the font the tile's CSS gives that element. Measure with that font.
47
92
  */
48
93
  private syncPreviewFont;
94
+ /**
95
+ * A block for one code element of a tile, built like a workspace block,
96
+ * slot defaults included, in the hidden tile workspace. Not drawn yet.
97
+ */
98
+ private createPreviewBlock;
99
+ /**
100
+ * A code element shown as text reads exactly like the codespace would
101
+ * write the block: field values, slot defaults and all.
102
+ */
103
+ private createCodeText;
49
104
  private createBlockPreviewSvg;
50
105
  private createBlockAtPosition;
51
106
  private resolveBlockIds;
@@ -9,7 +9,7 @@ export type MorphicModeName = string;
9
9
  export type MorphicElementType = "text" | "code" | "image";
10
10
  /**
11
11
  * Configuration for a value slot's empty-state default. Keyed by slot
12
- * `check` in `elementTypes[name].empty[check]`, or set per-slot via
12
+ * `check` in `code[element].empty[check]`, or set per-slot via
13
13
  * `inputSlot.default`. Both `shadow` and `placeholder` are optional; when
14
14
  * both are configured, the placeholder is created first and Blockly's
15
15
  * native shadow restoration brings the shadow up if the user removes the
@@ -41,11 +41,30 @@ export interface MorphicEmptyDefaultConfig {
41
41
  }
42
42
  /**
43
43
  * Optional per-element configuration. Used in place of a bare type string in
44
- * `elementTypes` when the developer needs to declare extras (e.g. shadows /
45
- * placeholders for empty value slots).
44
+ * `elementTypes` when an image element needs its display `size`. How a code
45
+ * element's language is written lives in the `code` section instead.
46
46
  */
47
47
  export interface MorphicElementTypeConfig {
48
48
  type: MorphicElementType;
49
+ /**
50
+ * Display size for `type: "image"` elements. Used when the element value is
51
+ * a file path (e.g. `"assets/icon.svg"`) and the framework auto-wraps it as
52
+ * an `<img>` tag. Accepted formats:
53
+ * - number: square, e.g. `32` → 32×32
54
+ * - `"32"`: square
55
+ * - `"32x32"`: explicit width × height
56
+ * Defaults to 16×16 if omitted. Ignored for non-image element types and for
57
+ * values that are already `<img>` HTML.
58
+ */
59
+ size?: number | string;
60
+ }
61
+ /** Either a bare type or a config object with extras. */
62
+ /**
63
+ * How one code element's language is written, in the `code` section keyed by
64
+ * element name: the literals the framework writes into empty slots and how
65
+ * the codespace and preview colour it.
66
+ */
67
+ export interface MorphicCodeElementConfig {
49
68
  /**
50
69
  * Per-slot-check defaults for empty value inputs. Keys are the slot's
51
70
  * `check` string (e.g. `"Number"`, `"String"`, or any developer-defined
@@ -66,18 +85,40 @@ export interface MorphicElementTypeConfig {
66
85
  */
67
86
  stringQuote?: string;
68
87
  /**
69
- * Display size for `type: "image"` elements. Used when the element value is
70
- * a file path (e.g. `"assets/icon.svg"`) and the framework auto-wraps it as
71
- * an `<img>` tag. Accepted formats:
72
- * - number: square, e.g. `32` → 32×32
73
- * - `"32"`: square
74
- * - `"32x32"`: explicit width × height
75
- * Defaults to 16×16 if omitted. Ignored for non-image element types and for
76
- * values that are already `<img>` HTML.
88
+ * Written by the codespace and preview into an empty statement slot, for
89
+ * languages where an empty body is invalid (`"pass"` for Python). Omit to
90
+ * leave empty bodies empty.
77
91
  */
78
- size?: number | string;
92
+ emptyStatement?: string;
93
+ /** Token highlighting for the codespace and preview showing this element. */
94
+ highlighting?: MorphicHighlightDefinition;
95
+ /**
96
+ * How `runJavaScript()` writes printed values while the codespace shows this
97
+ * element. Programs run as JavaScript, so values otherwise read like it.
98
+ */
99
+ values?: MorphicValueFormat;
100
+ }
101
+ /**
102
+ * Printed values in a language's own spelling, e.g. Python:
103
+ * `{ "true": "True", "false": "False", "null": "None", "list": { "quote": "'" } }`.
104
+ * Each entry replaces JavaScript's text for that value; left out, it stays.
105
+ */
106
+ export interface MorphicValueFormat {
107
+ true?: string;
108
+ false?: string;
109
+ null?: string;
110
+ undefined?: string;
111
+ NaN?: string;
112
+ Infinity?: string;
113
+ "-Infinity"?: string;
114
+ /** Lists: brackets, separator and quotes around texts in them. Left out, lists read `1,2,3`. */
115
+ list?: {
116
+ open?: string;
117
+ close?: string;
118
+ separator?: string;
119
+ quote?: string;
120
+ };
79
121
  }
80
- /** Either a bare type or a config object with extras. */
81
122
  export type MorphicElementTypeEntry = MorphicElementType | MorphicElementTypeConfig;
82
123
  export type MorphicConnectionSpec = boolean | string | string[];
83
124
  /**
@@ -186,6 +227,12 @@ export interface MorphicPresetDefinition {
186
227
  workspace?: MorphicModeName;
187
228
  codespace?: MorphicModeName;
188
229
  preview?: MorphicModeName;
230
+ /**
231
+ * Modes of views added with `addView()`, by view name. Applying the preset
232
+ * switches each listed view that exists; the app shows or hides views, as
233
+ * for the built-in ones.
234
+ */
235
+ views?: Record<string, MorphicModeName>;
189
236
  }
190
237
  /**
191
238
  * Declares which elements are visible for a given mode.
@@ -248,10 +295,14 @@ export interface MorphicBlockDefinition {
248
295
  * Blocks treats text as a rendered view, not a freeform editing surface.
249
296
  */
250
297
  export interface MorphicHighlightDefinition {
251
- /** Words to highlight as keywords (exact match against `[A-Za-z_]\w*` tokens). */
298
+ /** Words to highlight as keywords, matched as whole words in any script (`if`, `اطبع`). */
252
299
  keywords?: string[];
253
- /** String delimiters (e.g. `["\"", "'"]`). Span until matching close on same line. */
254
- strings?: string[];
300
+ /**
301
+ * String delimiters. A mark that opens and closes (`"\""`, `"'"`), or an
302
+ * `[open, close]` pair for quotes that differ (`["„", "“"]`, `["«", "»"]`).
303
+ * A string spans to its close on the same line.
304
+ */
305
+ strings?: (string | [open: string, close: string])[];
255
306
  /** Line-comment marker (e.g. `"#"`, `"//"`). Highlights from the marker to end of line. */
256
307
  comment?: string;
257
308
  /** Highlight integer/decimal numeric literals. Defaults to true; pass `false` to disable. */
@@ -287,7 +338,7 @@ export interface MorphicBlocksFormat {
287
338
  /**
288
339
  * Global element type registry.
289
340
  * Maps each element name to either a bare type ("text" | "code" | "image")
290
- * or a config object (`{ type, empty? }`). Declared once here; per-block
341
+ * or a config object (`{ type, size? }`). Declared once here; per-block
291
342
  * elements remain plain name→content strings.
292
343
  */
293
344
  elementTypes?: Record<string, MorphicElementTypeEntry>;
@@ -296,10 +347,10 @@ export interface MorphicBlocksFormat {
296
347
  /** Named per-view mode configurations. Used as the mount default for `presets`. */
297
348
  presets?: MorphicPresetDefinition[];
298
349
  /**
299
- * Per-element highlight rules, keyed by element name. The codespace and
300
- * preview modes' source elements look up entries here for their editors.
350
+ * How each code element's language is written, keyed by element name:
351
+ * string quotes, empty slot defaults and highlighting.
301
352
  */
302
- highlighting?: Record<string, MorphicHighlightDefinition>;
353
+ code?: Record<string, MorphicCodeElementConfig>;
303
354
  /** Optional category metadata. Blocks reference categories by name. */
304
355
  categories?: MorphicToolboxCategory[];
305
356
  /** Flat array of block definitions. */
@@ -370,13 +421,47 @@ export interface MorphicToolboxCategory {
370
421
  export type MorphicToolboxLayout = "flyout" | "category";
371
422
  export interface MorphicToolboxConfig {
372
423
  kind?: "flyoutToolbox" | "categoryToolbox";
424
+ /** Show only these blocks, in the HTML toolbox and in Blockly's own. */
373
425
  blocks?: string[];
374
426
  categories?: MorphicToolboxCategory[];
427
+ /** Header of the HTML toolbox; see {@link MorphicToolboxModeLabel}. */
428
+ modeLabel?: MorphicToolboxModeLabel;
429
+ /** Colour code shown as text on tiles like the codespace does. Default `true`. */
430
+ highlight?: boolean;
431
+ /** Tiles can be dragged with a finger or pen. Default `true`. */
432
+ touch?: boolean;
433
+ /** Tiles can be reached with Tab and added with Enter or Space. Default `true`. */
434
+ keyboard?: boolean;
375
435
  }
436
+ /**
437
+ * Header of the HTML toolbox: `true` shows "Mode: <name>" (the default),
438
+ * `false` none, a string that text, and a function the text it returns for
439
+ * the active mode (`(mode) => mode` shows the bare name).
440
+ */
441
+ export type MorphicToolboxModeLabel = boolean | string | ((mode: string) => string);
376
442
  /** Options for the custom HTML toolbox canvas (mountToolbox). */
377
443
  export interface MorphicToolboxCanvasOptions {
378
- /** Render a "Mode: <name>" header at the top of the toolbox. Defaults to true. */
379
- modeLabel?: boolean;
444
+ /** Header of the toolbox; see {@link MorphicToolboxModeLabel}. Defaults to "Mode: <name>". */
445
+ modeLabel?: MorphicToolboxModeLabel;
446
+ /**
447
+ * Colour code shown as text on tiles (`render: "text"`) with its element's
448
+ * `code.<element>.highlighting`, as the codespace does. Default `true`.
449
+ */
450
+ highlight?: boolean;
451
+ /**
452
+ * Tiles can be dragged with a finger or pen into the workspace and the
453
+ * codespace. Default `true`. A tile starts moving when dragged sideways (the
454
+ * toolbox still scrolls up and down) or after a long press.
455
+ */
456
+ touch?: boolean;
457
+ /**
458
+ * Tiles can be reached with Tab and read by screen readers as buttons named
459
+ * after what they show (code as the codespace writes it, text, image alt
460
+ * text). Enter or Space adds the block after
461
+ * the selected one when it fits there, else as a new stack, and selects it,
462
+ * so pressing again builds a chain. Default `true`.
463
+ */
464
+ keyboard?: boolean;
380
465
  /** Show only a subset of blocks. Defaults to all blocks in definitions. */
381
466
  blocks?: string[];
382
467
  /**
@@ -443,6 +528,12 @@ export interface MorphicMountConfig {
443
528
  * present on the preset).
444
529
  */
445
530
  onPresetApplied?: (preset: MorphicPresetDefinition) => void;
531
+ /**
532
+ * Receives every framework warning (definition warnings, modes without
533
+ * CSS, missing Blockly media) instead of the browser console, e.g. to show
534
+ * them in the app's own development mode.
535
+ */
536
+ onWarning?: (message: string) => void;
446
537
  toolbox?: MorphicToolboxConfig;
447
538
  toolboxLayout?: MorphicToolboxLayout;
448
539
  /**
@@ -470,15 +561,19 @@ export interface MorphicMountConfig {
470
561
  */
471
562
  modesFolder?: Record<string, unknown>;
472
563
  baseStyle?: MorphicStyleBundle;
473
- /** Options passed through to Blockly's `inject` (zoom, grid, trashcan, and so on). */
564
+ /**
565
+ * Options passed through to Blockly's `inject` (zoom, grid, trashcan, and so
566
+ * on). `media` defaults to `"blockly-media/"` next to the page, filled by
567
+ * `npx morphic-blocks copy-media`, so Blockly never loads from another server
568
+ * unless the host sets it.
569
+ */
474
570
  blockly?: Blockly.BlocklyOptions;
475
571
  javascript?: MorphicJavaScriptConfig;
476
572
  /**
477
- * Per-element highlight rules, keyed by element name. The codespace and
478
- * preview modes' source elements are used to look up entries here for
479
- * their editors. Optional — when absent, editors render plain text.
573
+ * How each code element's language is written, keyed by element name.
574
+ * Defaults to the definitions' `code` section.
480
575
  */
481
- highlighting?: Record<string, MorphicHighlightDefinition>;
576
+ code?: Record<string, MorphicCodeElementConfig>;
482
577
  }
483
578
  /**
484
579
  * Resolved workspace template for a block in a given mode.
@@ -592,6 +687,46 @@ export interface MorphicCodeEditorTheme {
592
687
  /** Text selection highlight colour. */
593
688
  selectionBackground?: string;
594
689
  }
690
+ /** Kinds of view `addView()` adds beside the ones `mount()` sets up. */
691
+ export type MorphicViewKind = "preview" | "codespace" | "workspace";
692
+ /** A view added with `engine.addView()`. */
693
+ export interface MorphicViewOptions {
694
+ kind: MorphicViewKind;
695
+ /** Element the view renders into. */
696
+ container: HTMLElement;
697
+ /** Mode the view shows; a preview renders its source element. */
698
+ mode: MorphicModeName;
699
+ /** Unique among the engine's added views. */
700
+ name?: string;
701
+ /**
702
+ * An added workspace shows the program as blocks in its own mode and follows
703
+ * every change of the main workspace. It is read only: `false` is the only
704
+ * value for now, and the default.
705
+ */
706
+ editable?: false;
707
+ /** Colours of a text view, like `previewTheme`. */
708
+ theme?: MorphicCodeEditorTheme;
709
+ /** A toolbar for this view, removed with it. Items default to its kind's. */
710
+ toolbar?: {
711
+ container: HTMLElement;
712
+ items?: MorphicToolbarItem[];
713
+ display?: MorphicToolbarDisplay;
714
+ };
715
+ }
716
+ /** Controls a view added with `engine.addView()`. */
717
+ export interface MorphicViewHandle {
718
+ readonly kind: MorphicViewKind;
719
+ /** The given name, or `view-1`, `view-2`, … when none was given. */
720
+ readonly name: string;
721
+ /** Settles once the view is ready; text views load their editor in the background. */
722
+ readonly ready: Promise<void>;
723
+ getMode(): MorphicModeName;
724
+ setMode(mode: MorphicModeName): void;
725
+ /** Colours of a text view, e.g. when the app switches between light and dark. No effect on a workspace. */
726
+ setTheme(theme: MorphicCodeEditorTheme): void;
727
+ /** Removes the view. `mount()` again removes every added view too. */
728
+ dispose(): void;
729
+ }
595
730
  /** Options for `mountCodeEditor()`. */
596
731
  export interface MorphicCodeEditorOptions {
597
732
  /** Visual theme — the framework provides sensible defaults. */
@@ -633,7 +768,7 @@ export interface MorphicCodeEditorOptions {
633
768
  }
634
769
  /** Options for `enableSelectionSync()`. */
635
770
  export interface MorphicSelectionSyncOptions {
636
- /** CSS background colour for highlighted code lines. Defaults to a semi-transparent blue. */
771
+ /** CSS background colour for highlighted code lines. Defaults to each editor's theme `selectionBackground`, a little lighter. */
637
772
  highlightColor?: string;
638
773
  /** Enable block → code direction. Defaults to true. */
639
774
  blockToCode?: boolean;
@@ -651,7 +786,10 @@ export type MorphicToolbarDisplay = "icon" | "label" | "both";
651
786
  */
652
787
  export interface MorphicToolbarCtx {
653
788
  engine: import("./MorphicBlocks").MorphicBlocks;
789
+ /** The kind of view the toolbar acts on. */
654
790
  pane: MorphicToolbarPane;
791
+ /** The name of the view the toolbar acts on; pass it to engine methods such as `zoomPane`. */
792
+ view: string;
655
793
  /** Current rendered text for the bound pane. Empty for workspace pane unless
656
794
  * the engine has a codespace/preview mounted to derive text from. */
657
795
  getText: () => string;
@@ -686,10 +824,12 @@ export interface MorphicToolbarItem {
686
824
  }
687
825
  /** Configuration for `engine.mountToolbar(container, config)`. */
688
826
  export interface MorphicToolbarConfig {
689
- /** Which pane this toolbar reflects. */
690
- pane: MorphicToolbarPane;
827
+ /** The view this toolbar acts on, by name: `workspace`, `codespace`, `preview`, or an added view's. */
828
+ view?: string;
829
+ /** Same as `view` for the views `mount()` sets up. One of `view` and `pane` is required. */
830
+ pane?: MorphicToolbarPane;
691
831
  /** Items to render. When omitted, the framework uses
692
- * `toolbarItems.defaultsFor(pane)`. To render no items, pass `[]`. */
832
+ * `toolbarItems.defaultsFor(<kind of view>)`. To render no items, pass `[]`. */
693
833
  items?: MorphicToolbarItem[];
694
834
  /** Display mode for items that have both icon and label. Defaults to "icon". */
695
835
  display?: MorphicToolbarDisplay;
@@ -1,8 +1,8 @@
1
- import type { MorphicBehaviorMap, MorphicBlockDefinition, MorphicElementTypeEntry, MorphicHighlightDefinition, MorphicModeDefinition, MorphicPresetDefinition, MorphicToolboxCategory } from "./types";
1
+ import type { MorphicBehaviorMap, MorphicBlockDefinition, MorphicCodeElementConfig, MorphicElementTypeEntry, MorphicModeDefinition, MorphicPresetDefinition, MorphicToolboxCategory } from "./types";
2
2
  /**
3
3
  * Inputs for a definitions validation pass. Everything is optional except the
4
4
  * definitions + elementTypes (available at construction); the cross-reference
5
- * data (modes / highlighting / categories) arrives from the mount config.
5
+ * data (modes / code / categories) arrives from the mount config.
6
6
  */
7
7
  export interface ValidateDefinitionsArgs {
8
8
  definitions: ReadonlyMap<string, MorphicBlockDefinition>;
@@ -10,7 +10,7 @@ export interface ValidateDefinitionsArgs {
10
10
  behaviors: MorphicBehaviorMap;
11
11
  modes?: MorphicModeDefinition[];
12
12
  presets?: MorphicPresetDefinition[];
13
- highlighting?: Record<string, MorphicHighlightDefinition>;
13
+ code?: Record<string, MorphicCodeElementConfig>;
14
14
  categories?: MorphicToolboxCategory[];
15
15
  }
16
16
  export interface DefinitionValidationResult {
@@ -0,0 +1,8 @@
1
+ import type { MorphicValueFormat } from "./types";
2
+ /**
3
+ * A printed value the way the shown language writes it. Programs run as
4
+ * JavaScript, so without a format a value reads like JavaScript (`true`,
5
+ * `null`, `1,2,3`); a code element's `values` format rewrites the primitive
6
+ * values and lists (`True`, `None`, `[1, 2, 3]`).
7
+ */
8
+ export declare function formatValue(value: unknown, format: MorphicValueFormat | undefined, nested?: boolean): string;