morphic-blocks 0.2.1 → 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 +93 -53
- package/definitions.schema.json +112 -26
- package/dist/cli.js +25 -0
- package/dist/copy-media-CllRyMqQ.js +21 -0
- package/dist/copy-media.d.ts +8 -0
- package/dist/esbuild.d.ts +3 -0
- package/dist/esbuild.js +10 -0
- package/dist/index.d.ts +2 -1
- package/dist/morphic/MorphicBlocks.d.ts +180 -59
- package/dist/morphic/block-view.d.ts +36 -0
- package/dist/morphic/code-editor.d.ts +30 -4
- package/dist/morphic/constants.d.ts +6 -0
- package/dist/morphic/element-types.d.ts +11 -3
- package/dist/morphic/resize.d.ts +7 -2
- package/dist/morphic/styles.d.ts +26 -3
- package/dist/morphic/syntax-highlight.d.ts +13 -0
- package/dist/morphic/template-codegen.d.ts +5 -1
- package/dist/morphic/template.d.ts +11 -1
- package/dist/morphic/toolbar.d.ts +13 -11
- package/dist/morphic/toolbox-canvas.d.ts +75 -5
- package/dist/morphic/types.d.ts +351 -74
- package/dist/morphic/validate-definitions.d.ts +5 -3
- package/dist/morphic/value-format.d.ts +8 -0
- package/dist/morphic/value-type.d.ts +13 -0
- package/dist/morphic/view-resolver.d.ts +5 -0
- package/dist/morphic-blocks.js +3671 -2420
- package/dist/morphic-blocks.umd.cjs +39 -30
- package/dist/plugin-h3QH8ods.js +19 -0
- package/dist/plugin.d.ts +9 -0
- package/dist/rollup.d.ts +3 -0
- package/dist/rollup.js +10 -0
- package/dist/rspack.d.ts +3 -0
- package/dist/rspack.js +10 -0
- package/dist/vite.d.ts +3 -0
- package/dist/vite.js +10 -0
- package/dist/webpack.d.ts +3 -0
- package/dist/webpack.js +10 -0
- package/package.json +42 -8
|
@@ -1,10 +1,12 @@
|
|
|
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 } 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;
|
|
7
|
-
|
|
7
|
+
/** Element types with the mounted `code` settings folded in (see withCodeSettings). */
|
|
8
|
+
private elementTypes;
|
|
9
|
+
private readonly formatElementTypes;
|
|
8
10
|
private readonly styles;
|
|
9
11
|
private readonly registeredBlockTypes;
|
|
10
12
|
private readonly toolbars;
|
|
@@ -16,11 +18,18 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
16
18
|
private workspace?;
|
|
17
19
|
private flyoutWorkspace?;
|
|
18
20
|
private toolboxCanvas?;
|
|
21
|
+
/** Codespaces a tile dragged by touch or pen can be dropped on. */
|
|
22
|
+
private readonly tileDropTargets;
|
|
19
23
|
private codeEditor?;
|
|
20
|
-
|
|
21
|
-
private
|
|
24
|
+
/** Views added with `addView()`, beside the ones `mount()` sets up. */
|
|
25
|
+
private readonly views;
|
|
26
|
+
/** The mode of each added workspace, read when its blocks are built. */
|
|
27
|
+
private readonly viewWorkspaceElements;
|
|
28
|
+
/** Numbers added views that are not given a name. */
|
|
29
|
+
private viewCount;
|
|
22
30
|
private selectionSync?;
|
|
23
31
|
private toolboxDefinition?;
|
|
32
|
+
/** Container the preview editor was mounted into. */
|
|
24
33
|
private blockCategoryIndex;
|
|
25
34
|
private appliedWorkspaceClasses;
|
|
26
35
|
private appliedToolboxFlyoutClasses;
|
|
@@ -28,7 +37,6 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
28
37
|
/** Offscreen div created when no user-supplied workspaceContainer is present. */
|
|
29
38
|
private headlessWorkspaceHost?;
|
|
30
39
|
/** Teardown fn for codespace drag/drop listeners; set when codespace is mounted. */
|
|
31
|
-
private codespaceDropTeardown?;
|
|
32
40
|
/** Redraws the workspace whenever its container changes size. */
|
|
33
41
|
private workspaceResizeObserver?;
|
|
34
42
|
/** Preset most recently applied, at mount or via `applyPreset`. */
|
|
@@ -45,7 +53,10 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
45
53
|
* runtime `mount()` call only carries DOM / runtime concerns. */
|
|
46
54
|
private readonly formatModes?;
|
|
47
55
|
private readonly formatPresets?;
|
|
48
|
-
private readonly
|
|
56
|
+
private readonly formatViews?;
|
|
57
|
+
private readonly formatCode?;
|
|
58
|
+
/** The definitions still use the old top level `highlighting` map. */
|
|
59
|
+
private readonly formatHasHighlighting;
|
|
49
60
|
private readonly formatCategories?;
|
|
50
61
|
/**
|
|
51
62
|
* Build an engine from a whole definitions file plus its behaviors — the two
|
|
@@ -67,6 +78,12 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
67
78
|
* when the engine was disposed or mounted again meanwhile.
|
|
68
79
|
*/
|
|
69
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();
|
|
70
87
|
/** Presets declared at mount (empty when none were provided). */
|
|
71
88
|
getPresets(): MorphicPresetDefinition[];
|
|
72
89
|
/**
|
|
@@ -97,6 +114,13 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
97
114
|
* directly (e.g. creating blocks from code). Everyday use goes through the
|
|
98
115
|
* engine. `undefined` before `mount`.
|
|
99
116
|
*/
|
|
117
|
+
/**
|
|
118
|
+
* Measure blocks and toolbox tiles again. Blockly measures block text only
|
|
119
|
+
* when it draws a block, so call this after the app changes the block font
|
|
120
|
+
* through its own CSS (a font size switch, say). Stylesheets and web fonts
|
|
121
|
+
* that finish loading are handled already.
|
|
122
|
+
*/
|
|
123
|
+
refresh(): void;
|
|
100
124
|
getWorkspace(): Blockly.WorkspaceSvg | undefined;
|
|
101
125
|
/**
|
|
102
126
|
* The declared mode names (`modes[].name` from the mount config). Empty until
|
|
@@ -104,21 +128,23 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
104
128
|
* `icon` or `python` is not a mode unless a mode is named after it.
|
|
105
129
|
*/
|
|
106
130
|
getAvailableModes(): MorphicModeName[];
|
|
107
|
-
/**
|
|
108
|
-
|
|
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[];
|
|
109
135
|
/**
|
|
110
|
-
*
|
|
111
|
-
*
|
|
136
|
+
* Change which elements a mode shows while the app runs, e.g. to let the
|
|
137
|
+
* user pick what a toolbox tile shows. Every view using the mode is redrawn;
|
|
138
|
+
* a mode a codespace or preview renders must keep a code element.
|
|
112
139
|
*/
|
|
113
|
-
|
|
114
|
-
/** Preview mode name, or `undefined` when no preview mode is set. */
|
|
115
|
-
getPreviewMode(): MorphicModeName | undefined;
|
|
140
|
+
setModeElements(mode: MorphicModeName, elements: string[]): void;
|
|
116
141
|
/** Mode definition by name, or `undefined`. */
|
|
117
142
|
private modeDef;
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
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;
|
|
122
148
|
/**
|
|
123
149
|
* Mount a toolbar into the developer-provided container, bound to one of the
|
|
124
150
|
* three editor surfaces. When `items` is omitted, the default set for the
|
|
@@ -155,13 +181,27 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
155
181
|
}): MorphicRunResult;
|
|
156
182
|
/** Whether the framework's internal clipboard has a copyable to paste. */
|
|
157
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;
|
|
158
193
|
/**
|
|
159
194
|
* Copy the currently active block to the framework's internal clipboard and
|
|
160
|
-
*
|
|
195
|
+
* its own text, as the view writes it, to the system clipboard. Resolution order:
|
|
161
196
|
* (1) Blockly's selected block, (2) for codespace/preview, the deepest block
|
|
162
197
|
* enclosing the active line. Returns true when something was copied.
|
|
163
198
|
*/
|
|
164
|
-
copyActiveBlock(
|
|
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;
|
|
165
205
|
/**
|
|
166
206
|
* Paste the last copied block at the active pane's natural location.
|
|
167
207
|
* Workspace: Blockly's default (workspace centre, slightly offset).
|
|
@@ -170,46 +210,37 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
170
210
|
* specific slot is deferred; the current behaviour matches Ctrl+V in
|
|
171
211
|
* standard Blockly.) Returns true if something was pasted.
|
|
172
212
|
*/
|
|
173
|
-
pasteActiveBlock(
|
|
213
|
+
pasteActiveBlock(_view: string): boolean;
|
|
174
214
|
private resolveActiveBlock;
|
|
175
215
|
/** Serialize the workspace to a plain object (Blockly's native format). */
|
|
176
216
|
serializeWorkspace(): unknown;
|
|
177
217
|
/** Restore the workspace from a previously serialized state. */
|
|
178
218
|
loadWorkspace(state: unknown): void;
|
|
179
219
|
/**
|
|
180
|
-
* Adjust
|
|
181
|
-
* the workspace
|
|
182
|
-
* `zoomToFit()`. For
|
|
220
|
+
* Adjust a view's zoom level, by view name. Direction is `"in" | "out" |
|
|
221
|
+
* "fit"`. For the workspace this maps to `workspace.zoomCenter(±1)` /
|
|
222
|
+
* `zoomToFit()`. For a text view it scales the editor's font-size.
|
|
183
223
|
*/
|
|
184
|
-
zoomPane(
|
|
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;
|
|
185
227
|
private ensureToolbarBlocklyListener;
|
|
186
228
|
private teardownToolbarBlocklyListener;
|
|
187
|
-
setModes(modes: {
|
|
188
|
-
workspaceMode?: MorphicModeName;
|
|
189
|
-
toolboxMode?: MorphicModeName;
|
|
190
|
-
/** Per-element block/text override for toolbox tiles. `null` clears it (all code elements render as blocks). */
|
|
191
|
-
toolboxRender?: Record<string, "block" | "text"> | null;
|
|
192
|
-
/** Independent codespace mode. `null` clears the override (falls back to workspaceMode). */
|
|
193
|
-
codespaceMode?: MorphicModeName | null;
|
|
194
|
-
/** Preview mode. `null` clears it (preview renders nothing unless the workspace mode declares a legacy `preview`). */
|
|
195
|
-
previewMode?: MorphicModeName | null;
|
|
196
|
-
}): void;
|
|
197
229
|
/**
|
|
198
|
-
*
|
|
199
|
-
*
|
|
200
|
-
*
|
|
201
|
-
*
|
|
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.
|
|
202
234
|
*/
|
|
203
|
-
|
|
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;
|
|
204
241
|
generateJavaScript(): string;
|
|
205
242
|
generateJavaScriptWithMetadata(): MorphicCodeGenerationResult;
|
|
206
243
|
mountCodeEditor(container: HTMLElement, options?: MorphicCodeEditorOptions): Promise<void>;
|
|
207
|
-
/**
|
|
208
|
-
* Mounts the primary text editor (codespace) into the `codespaceContainer`
|
|
209
|
-
* declared at `mount()`. Renders the workspace as text using the codespace
|
|
210
|
-
* mode's source element. Read-only for now; Task 4 adds drops.
|
|
211
|
-
*/
|
|
212
|
-
mountCodespace(options?: MorphicCodeEditorOptions): Promise<void>;
|
|
213
244
|
private attachCodespaceDropTarget;
|
|
214
245
|
/** Innermost (smallest-range) block in metadata whose char range contains `charOffset`. */
|
|
215
246
|
private findInnermostBlockAtChar;
|
|
@@ -252,6 +283,18 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
252
283
|
* Connects to the slot directly when the slot is empty; otherwise walks to
|
|
253
284
|
* the chain's tail and connects there.
|
|
254
285
|
*/
|
|
286
|
+
/**
|
|
287
|
+
* The drop as it will happen: unchanged when its connections fit, turned into
|
|
288
|
+
* its own stack when it was aimed into a top level chain, `null` otherwise.
|
|
289
|
+
*/
|
|
290
|
+
private fitOrLoose;
|
|
291
|
+
/**
|
|
292
|
+
* Whether a codespace drop makes only connections the workspace would make:
|
|
293
|
+
* every connection it plans passes Blockly's connection checker, and no
|
|
294
|
+
* block is left behind outside the chain. Checked before anything changes,
|
|
295
|
+
* so a refused drop leaves the program as it was.
|
|
296
|
+
*/
|
|
297
|
+
private codespaceDropAllowed;
|
|
255
298
|
private connectIntoSlot;
|
|
256
299
|
/**
|
|
257
300
|
* Resolve a char-offset in the codespace to the value slot the drop should
|
|
@@ -270,6 +313,12 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
270
313
|
private findValueSlotDropAtChar;
|
|
271
314
|
/** Find the value-input that holds `child`, returning its parent + input name. */
|
|
272
315
|
private resolveValueParent;
|
|
316
|
+
/**
|
|
317
|
+
* Add a block chosen on a tile with the keyboard: after the selected block
|
|
318
|
+
* when its connections fit there, else as a new stack below the others.
|
|
319
|
+
* The new block is selected, so choosing again builds a chain.
|
|
320
|
+
*/
|
|
321
|
+
private addBlockFromTile;
|
|
273
322
|
/**
|
|
274
323
|
* Place a freshly-orphaned block at a clear workspace coordinate, below the
|
|
275
324
|
* current bottom-most top block. Keeps replaced value children visible in
|
|
@@ -280,11 +329,13 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
280
329
|
private isDescendantOf;
|
|
281
330
|
/**
|
|
282
331
|
* Connect `source`'s output into the value input named `inputName` on
|
|
283
|
-
* `parent`. A real (non-shadow) child currently in the slot
|
|
284
|
-
*
|
|
285
|
-
*
|
|
286
|
-
*
|
|
287
|
-
*
|
|
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.
|
|
288
339
|
*/
|
|
289
340
|
private connectIntoValueSlot;
|
|
290
341
|
private computeBlockDepth;
|
|
@@ -293,26 +344,88 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
293
344
|
/** Connect `source` into `target`'s statement chain before/after `target`. */
|
|
294
345
|
private connectStatement;
|
|
295
346
|
private applyTopBlockOrder;
|
|
347
|
+
/** Write every text view again, added views included. */
|
|
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;
|
|
296
353
|
/**
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* 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.
|
|
300
356
|
*/
|
|
301
|
-
|
|
302
|
-
|
|
357
|
+
private defaultElement;
|
|
358
|
+
/**
|
|
359
|
+
* Add a view beside the ones `mount()` sets up, e.g. a second preview in
|
|
360
|
+
* another mode. Returns a handle to change its mode or remove it; a new
|
|
361
|
+
* `mount()` removes every added view.
|
|
362
|
+
*/
|
|
363
|
+
addView(options: MorphicViewOptions): MorphicViewHandle;
|
|
364
|
+
/**
|
|
365
|
+
* A read only Blockly workspace in its own mode that mirrors the main one:
|
|
366
|
+
* it starts from a copy of the program and replays every change, the way
|
|
367
|
+
* Blockly mirrors workspaces. Selection runs both ways through the main
|
|
368
|
+
* workspace, so the text views follow a click in the mirror too.
|
|
369
|
+
*/
|
|
370
|
+
private addWorkspaceView;
|
|
371
|
+
/** The element's classes and block font on an added workspace. */
|
|
372
|
+
private styleWorkspaceView;
|
|
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
|
+
*/
|
|
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;
|
|
384
|
+
/** Remove an added view and everything it set up. */
|
|
385
|
+
private disposeView;
|
|
386
|
+
/**
|
|
387
|
+
* Take a ready added view into selection sync: relink an active sync, or
|
|
388
|
+
* start one now that more than one view is shown, as `mount()` would have,
|
|
389
|
+
* unless the host turned it off.
|
|
390
|
+
*/
|
|
391
|
+
private linkAddedView;
|
|
392
|
+
/** A view by name, built in or added; `undefined` when there is none. */
|
|
393
|
+
private resolveView;
|
|
394
|
+
/** The element a view shows, by name. */
|
|
395
|
+
getViewElement(name: string): string | undefined;
|
|
396
|
+
/** A view shows a code element. */
|
|
397
|
+
private checkViewElement;
|
|
303
398
|
/**
|
|
304
399
|
* Write `newValue` to `edit.fieldName` on the Blockly block identified by
|
|
305
400
|
* `edit.blockId`. The change event listener will trigger codespace re-sync.
|
|
306
401
|
*/
|
|
307
402
|
private applyPlaceholderEdit;
|
|
403
|
+
/**
|
|
404
|
+
* Whether a codespace grip may move the block: statement blocks
|
|
405
|
+
* (previousConnection) and value blocks (outputConnection), so the
|
|
406
|
+
* codespace mirrors Blockly's full set of moveable blocks.
|
|
407
|
+
*/
|
|
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
|
+
*/
|
|
308
414
|
private deleteBlockAtCodespaceLine;
|
|
309
|
-
|
|
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;
|
|
310
423
|
showCodeEditor(): void;
|
|
311
424
|
hideCodeEditor(): void;
|
|
312
425
|
isCodeEditorVisible(): boolean;
|
|
313
426
|
setCodeEditorTheme(theme: MorphicCodeEditorTheme): void;
|
|
314
|
-
|
|
315
|
-
|
|
427
|
+
/** Colours of a text view, by name, e.g. on a light and dark switch. */
|
|
428
|
+
setViewTheme(view: string, theme: MorphicCodeEditorTheme): void;
|
|
316
429
|
/**
|
|
317
430
|
* Enable bidirectional selection sync between the Blockly workspace and every
|
|
318
431
|
* currently-mounted editor (code editor, codespace, preview). Requires at
|
|
@@ -331,10 +444,16 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
331
444
|
private registerBlocks;
|
|
332
445
|
/** Build a newly created block with this engine's definition, mode and behavior. */
|
|
333
446
|
private initManagedBlock;
|
|
334
|
-
private
|
|
447
|
+
private validateViews;
|
|
335
448
|
private createHeadlessHost;
|
|
336
449
|
private resolveMode;
|
|
337
450
|
private applyView;
|
|
451
|
+
/**
|
|
452
|
+
* The classes and colours a block's drawing takes from its definition and
|
|
453
|
+
* the mode's CSS. Needs the block's SVG, so a block built before it had one
|
|
454
|
+
* is styled again once it does.
|
|
455
|
+
*/
|
|
456
|
+
private styleBlock;
|
|
338
457
|
private applyWorkspaceContainerClass;
|
|
339
458
|
/**
|
|
340
459
|
* Measure block text with the font the workspace mode's CSS draws it in.
|
|
@@ -343,6 +462,8 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
343
462
|
* overrides it, exactly like real block text.
|
|
344
463
|
*/
|
|
345
464
|
private syncWorkspaceFont;
|
|
465
|
+
/** Measure a workspace's blocks with the font its host's mode CSS sets. */
|
|
466
|
+
private syncFontOf;
|
|
346
467
|
private readonly onStylesLoaded;
|
|
347
468
|
private applyFlyoutClass;
|
|
348
469
|
private renderWorkspaceBlocks;
|
|
@@ -12,6 +12,12 @@ export type MorphicManagedBlock = Blockly.BlockSvg & {
|
|
|
12
12
|
* lifecycle and restores them by design.
|
|
13
13
|
*/
|
|
14
14
|
__morphicPlaceholderSlots?: Set<string>;
|
|
15
|
+
/**
|
|
16
|
+
* Every field value the block has had, by field name. A mode whose template
|
|
17
|
+
* leaves a field out rebuilds the block without it; the value waits here
|
|
18
|
+
* until a mode that shows the field again restores it.
|
|
19
|
+
*/
|
|
20
|
+
__morphicFieldMemory?: Map<string, unknown>;
|
|
15
21
|
};
|
|
16
22
|
export interface MorphicApplyBlockViewParams {
|
|
17
23
|
block: Blockly.BlockSvg;
|
|
@@ -33,8 +39,19 @@ export interface MorphicApplyBlockViewParams {
|
|
|
33
39
|
* stock Blockly types pass through. Defaults to identity when omitted.
|
|
34
40
|
*/
|
|
35
41
|
resolveBlocklyType?: (ref: string) => string;
|
|
42
|
+
/**
|
|
43
|
+
* Element types with their `code` settings, for the names `%1:type` shows.
|
|
44
|
+
* Unlike `elementTypes`, it adds no slot defaults. Falls back to `elementTypes`.
|
|
45
|
+
*/
|
|
46
|
+
codeSettings?: Record<string, MorphicElementTypeEntry>;
|
|
36
47
|
}
|
|
37
48
|
export declare function applyBlockView(params: MorphicApplyBlockViewParams): void;
|
|
49
|
+
/**
|
|
50
|
+
* Whether a block is drawn on its workspace yet. Blockly calls a new block
|
|
51
|
+
* `rendered` before its SVG is placed; drawing it then draws it at 0,0, and
|
|
52
|
+
* Blockly pushes blocks there out of its way.
|
|
53
|
+
*/
|
|
54
|
+
export declare function isOnCanvas(block: Blockly.BlockSvg): boolean;
|
|
38
55
|
export declare function applyRootModeClasses(root: Element, mode: MorphicModeName, context: MorphicRenderContext, rootClassName: string): void;
|
|
39
56
|
export declare function getManagedBlockMode(block: Blockly.Block): string | undefined;
|
|
40
57
|
export declare function applyBlockCategoryClass(block: Blockly.BlockSvg, categoryToken?: string): void;
|
|
@@ -50,5 +67,24 @@ export declare function applyBlockIdentifierClass(block: Blockly.BlockSvg, ident
|
|
|
50
67
|
* when a value is found. This lets mode CSS files drive block colours declaratively.
|
|
51
68
|
*/
|
|
52
69
|
export declare function applyBlockColorFromCSS(block: Blockly.BlockSvg): void;
|
|
70
|
+
/**
|
|
71
|
+
* Mark a view's container with combinable classes, so app CSS can style it:
|
|
72
|
+
* `morphic-view` and `morphic-view-<name>`, `morphic-shows-<element>` for
|
|
73
|
+
* the element it shows, its kind's root class (`morphic-workspace-root`,
|
|
74
|
+
* `morphic-codespace-root`) and any others given (`morphic-read-only`).
|
|
75
|
+
*/
|
|
76
|
+
export declare function applyViewClasses(root: Element, view: {
|
|
77
|
+
name?: string;
|
|
78
|
+
element?: string;
|
|
79
|
+
classNames: string[];
|
|
80
|
+
}): void;
|
|
81
|
+
/** Mark a view's container with the preset applied last, `morphic-preset-<name>`. */
|
|
82
|
+
export declare function applyPresetClass(root: Element, preset: string | undefined): void;
|
|
83
|
+
/**
|
|
84
|
+
* Mark a block's drawing: a workspace block with the element it shows
|
|
85
|
+
* (`morphic-shows-<element>`), a toolbox block with its mode
|
|
86
|
+
* (`morphic-mode-<mode>`), and both with the context.
|
|
87
|
+
*/
|
|
88
|
+
export declare function decorateBlockRoot(block: Blockly.BlockSvg, shown: string, context: MorphicRenderContext): void;
|
|
53
89
|
export declare function captureFieldValues(block: Blockly.BlockSvg): Map<string, unknown>;
|
|
54
90
|
export declare function restoreFieldValues(block: Blockly.BlockSvg, values: Map<string, unknown>): void;
|
|
@@ -18,6 +18,8 @@ export declare function getActiveGripDragSourceId(): string | undefined;
|
|
|
18
18
|
/** Mark a block id as the active grip-drag source (e.g. from a placeholder-range drag). */
|
|
19
19
|
export declare function setActiveGripDragSourceId(id: string | undefined): void;
|
|
20
20
|
export declare class MorphicCodeEditor {
|
|
21
|
+
/** Use JavaScript language support; only the code editor does. */
|
|
22
|
+
private readonly javascript;
|
|
21
23
|
private editorView?;
|
|
22
24
|
private container;
|
|
23
25
|
private options;
|
|
@@ -72,16 +74,23 @@ export declare class MorphicCodeEditor {
|
|
|
72
74
|
private themeCompartment?;
|
|
73
75
|
private syntaxHighlightCompartment?;
|
|
74
76
|
private highlightEffect?;
|
|
75
|
-
|
|
77
|
+
/** The host's highlight colour; without one, the theme's selection colour is used. */
|
|
78
|
+
private themeSelection;
|
|
79
|
+
/** The lines highlighted now, drawn again when the colour changes. */
|
|
80
|
+
private activeHighlight?;
|
|
76
81
|
private metadataEffect?;
|
|
77
82
|
private placeholderEffect?;
|
|
78
83
|
private dropIndicatorEffect?;
|
|
79
84
|
private valueSlotHighlightEffect?;
|
|
80
85
|
private hoverHighlightEffect?;
|
|
86
|
+
/** Hands the code view the line ranges of the groups of blocks. */
|
|
87
|
+
private groupsEffect?;
|
|
81
88
|
private editableHoverHighlightEffect?;
|
|
82
89
|
private emptyClickListener?;
|
|
83
90
|
private disposed;
|
|
84
|
-
constructor(container: HTMLElement, workspace: Blockly.WorkspaceSvg, generateWithMetadata: () => MorphicCodeGenerationResult, options?: MorphicCodeEditorOptions
|
|
91
|
+
constructor(container: HTMLElement, workspace: Blockly.WorkspaceSvg, generateWithMetadata: () => MorphicCodeGenerationResult, options?: MorphicCodeEditorOptions,
|
|
92
|
+
/** Use JavaScript language support; only the code editor does. */
|
|
93
|
+
javascript?: boolean);
|
|
85
94
|
mount(): Promise<void>;
|
|
86
95
|
private buildDeleteExtensions;
|
|
87
96
|
private buildGripExtensions;
|
|
@@ -99,6 +108,14 @@ export declare class MorphicCodeEditor {
|
|
|
99
108
|
* before they act. Driven from `setHoverHighlight` (called by MorphicBlocks
|
|
100
109
|
* on the codespace container's `mousemove`/`mouseleave`).
|
|
101
110
|
*/
|
|
111
|
+
/**
|
|
112
|
+
* Classes on the lines of each group of connected blocks, and on their
|
|
113
|
+
* gutter (line numbers, delete, grip): `morphic-group-start`, `-end`,
|
|
114
|
+
* `-line` (groups of more than one line), `-odd` / `-even` (every other
|
|
115
|
+
* group) and `-hover` (the group under the mouse). They change nothing
|
|
116
|
+
* visible; the app styles them.
|
|
117
|
+
*/
|
|
118
|
+
private buildGroupExtensions;
|
|
102
119
|
private buildHoverHighlightExtensions;
|
|
103
120
|
/** Highlight the char range of the block currently under the mouse cursor. */
|
|
104
121
|
setHoverHighlight(range: {
|
|
@@ -124,8 +141,6 @@ export declare class MorphicCodeEditor {
|
|
|
124
141
|
highlightLines(spans: LineSpan | LineSpan[]): void;
|
|
125
142
|
/** Remove all line highlights. */
|
|
126
143
|
clearHighlight(): void;
|
|
127
|
-
/** Update the highlight background colour. */
|
|
128
|
-
setHighlightColor(color: string): void;
|
|
129
144
|
/** Show a drop-position indicator above (or below) the given 1-based line. */
|
|
130
145
|
showDropIndicator(line: number, position?: "above" | "below"): void;
|
|
131
146
|
/** Hide the drop-position indicator if currently shown. */
|
|
@@ -156,6 +171,17 @@ export declare class MorphicCodeEditor {
|
|
|
156
171
|
refresh(): void;
|
|
157
172
|
/** Current editor text. Empty string when the editor is not mounted yet. */
|
|
158
173
|
getValue(): string;
|
|
174
|
+
/** The 1-based lines the selection covers, or `null` when nothing is selected. */
|
|
175
|
+
getSelectedLines(): {
|
|
176
|
+
first: number;
|
|
177
|
+
last: number;
|
|
178
|
+
} | null;
|
|
179
|
+
/**
|
|
180
|
+
* Drop the selection, also the browser's: while the editor is not focused
|
|
181
|
+
* (e.g. a toolbar button was clicked), the browser keeps showing it on
|
|
182
|
+
* whatever text moves into its place.
|
|
183
|
+
*/
|
|
184
|
+
clearSelection(): void;
|
|
159
185
|
/** 1-based line number under the cursor. Returns 1 when no cursor / not mounted. */
|
|
160
186
|
getCursorLine(): number;
|
|
161
187
|
/**
|
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
export declare const MODE_CLASS_PREFIX = "morphic-mode-";
|
|
2
2
|
export declare const CONTEXT_CLASS_PREFIX = "morphic-context-";
|
|
3
|
+
/** On a view and its blocks: the element the view shows. */
|
|
4
|
+
export declare const SHOWS_CLASS_PREFIX = "morphic-shows-";
|
|
5
|
+
/** On a view: its name. */
|
|
6
|
+
export declare const VIEW_CLASS_PREFIX = "morphic-view-";
|
|
7
|
+
/** On a view: the preset applied last. */
|
|
8
|
+
export declare const PRESET_CLASS_PREFIX = "morphic-preset-";
|
|
3
9
|
export declare const CATEGORY_CLASS_PREFIX = "morphic-category-";
|
|
4
10
|
export declare const BLOCK_CLASS_PREFIX = "morphic-block-";
|
|
5
11
|
export declare const ALIGN_LEFT = -1;
|
|
@@ -1,6 +1,14 @@
|
|
|
1
|
-
import type { MorphicElementType, MorphicElementTypeEntry, MorphicEmptyDefaultConfig, MorphicInputSlotDefinition } from "./types";
|
|
1
|
+
import type { MorphicCodeElementConfig, MorphicElementType, MorphicElementTypeConfig, MorphicElementTypeEntry, MorphicEmptyDefaultConfig, MorphicInputSlotDefinition } from "./types";
|
|
2
2
|
/** Get the rendering type of an entry, normalising bare strings vs config. */
|
|
3
3
|
export declare function resolveElementType(entry: MorphicElementTypeEntry | undefined): MorphicElementType | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* An element type entry with its code element's settings from the `code`
|
|
6
|
+
* section folded in. Internal: the renderers read the settings from the entry
|
|
7
|
+
* they already hold for the element.
|
|
8
|
+
*/
|
|
9
|
+
export type MorphicElementTypeWithCode = MorphicElementTypeConfig & Pick<MorphicCodeElementConfig, "empty" | "stringQuote" | "emptyStatement" | "types">;
|
|
10
|
+
/** `elementTypes` with each code element's `code` settings folded in. */
|
|
11
|
+
export declare function withCodeSettings(elementTypes: Record<string, MorphicElementTypeEntry>, code: Record<string, MorphicCodeElementConfig> | undefined): Record<string, MorphicElementTypeEntry>;
|
|
4
12
|
/**
|
|
5
13
|
* Resolve the display size for a `type: "image"` element. Reads the optional
|
|
6
14
|
* `size` field on `MorphicElementTypeConfig`; falls back to 16×16. Accepts a
|
|
@@ -12,8 +20,8 @@ export declare function resolveImageSize(entry: MorphicElementTypeEntry | undefi
|
|
|
12
20
|
};
|
|
13
21
|
/**
|
|
14
22
|
* Resolve the empty-state default config for a value slot. Honours the
|
|
15
|
-
* priority chain: per-slot `default` (highest) →
|
|
16
|
-
*
|
|
23
|
+
* priority chain: per-slot `default` (highest) → the code element's
|
|
24
|
+
* `empty[check]` → its `empty.default` (catch-all, also used when the slot has no
|
|
17
25
|
* `check`). Returns undefined when nothing is configured — callers should treat
|
|
18
26
|
* that as "show the codespace marker / empty workspace socket."
|
|
19
27
|
*/
|
package/dist/morphic/resize.d.ts
CHANGED
|
@@ -24,12 +24,17 @@ export interface MorphicResizeOptions {
|
|
|
24
24
|
invert?: boolean;
|
|
25
25
|
/** Called with the new pixel size on every move (e.g. to trigger a reflow). */
|
|
26
26
|
onResize?: (size: number) => void;
|
|
27
|
+
/**
|
|
28
|
+
* Pixels an arrow key moves the divider; with Shift five times as far.
|
|
29
|
+
* Default 10. Home and End go to `min` and `max`.
|
|
30
|
+
*/
|
|
31
|
+
step?: number;
|
|
27
32
|
}
|
|
28
33
|
export interface MorphicResizeHandle {
|
|
29
34
|
dispose(): void;
|
|
30
35
|
}
|
|
31
36
|
/**
|
|
32
|
-
* Make `gutter` drag-resize `opts.target
|
|
33
|
-
* detaches the
|
|
37
|
+
* Make `gutter` drag-resize `opts.target`, with the pointer or the keyboard.
|
|
38
|
+
* Returns a handle whose `dispose()` detaches the listeners.
|
|
34
39
|
*/
|
|
35
40
|
export declare function makeResizable(gutter: HTMLElement, opts: MorphicResizeOptions): MorphicResizeHandle;
|
package/dist/morphic/styles.d.ts
CHANGED
|
@@ -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,30 @@ 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;
|
|
55
|
+
/**
|
|
56
|
+
* The toolbox's scroll hints: no scrollbar, and a fade at each edge where more
|
|
57
|
+
* tiles wait. `:where()` gives them no weight, so any rule of the app wins.
|
|
58
|
+
*/
|
|
59
|
+
export declare function ensureToolboxScrollStyles(): 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 {};
|