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 +26 -21
- package/definitions.schema.json +51 -14
- package/dist/cli.js +6 -17
- 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 +1 -1
- package/dist/morphic/MorphicBlocks.d.ts +90 -66
- package/dist/morphic/block-view.d.ts +22 -4
- package/dist/morphic/code-editor.d.ts +21 -3
- package/dist/morphic/constants.d.ts +6 -0
- package/dist/morphic/element-types.d.ts +1 -1
- package/dist/morphic/resize.d.ts +7 -2
- package/dist/morphic/styles.d.ts +5 -0
- package/dist/morphic/template.d.ts +11 -1
- package/dist/morphic/toolbar.d.ts +8 -11
- package/dist/morphic/toolbox-canvas.d.ts +25 -10
- package/dist/morphic/types.d.ts +202 -65
- package/dist/morphic/validate-definitions.d.ts +2 -0
- package/dist/morphic/value-type.d.ts +13 -0
- package/dist/morphic/view-resolver.d.ts +5 -0
- package/dist/morphic-blocks.js +2265 -1804
- package/dist/morphic-blocks.umd.cjs +28 -23
- 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 +24 -3
|
@@ -39,6 +39,11 @@ export interface MorphicApplyBlockViewParams {
|
|
|
39
39
|
* stock Blockly types pass through. Defaults to identity when omitted.
|
|
40
40
|
*/
|
|
41
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>;
|
|
42
47
|
}
|
|
43
48
|
export declare function applyBlockView(params: MorphicApplyBlockViewParams): void;
|
|
44
49
|
/**
|
|
@@ -63,10 +68,23 @@ export declare function applyBlockIdentifierClass(block: Blockly.BlockSvg, ident
|
|
|
63
68
|
*/
|
|
64
69
|
export declare function applyBlockColorFromCSS(block: Blockly.BlockSvg): void;
|
|
65
70
|
/**
|
|
66
|
-
* Mark a
|
|
67
|
-
*
|
|
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.
|
|
68
87
|
*/
|
|
69
|
-
export declare function
|
|
70
|
-
export declare function decorateBlockRoot(block: Blockly.BlockSvg, mode: MorphicModeName, context: MorphicRenderContext): void;
|
|
88
|
+
export declare function decorateBlockRoot(block: Blockly.BlockSvg, shown: string, context: MorphicRenderContext): void;
|
|
71
89
|
export declare function captureFieldValues(block: Blockly.BlockSvg): Map<string, unknown>;
|
|
72
90
|
export declare function restoreFieldValues(block: Blockly.BlockSvg, values: Map<string, unknown>): void;
|
|
@@ -75,7 +75,6 @@ export declare class MorphicCodeEditor {
|
|
|
75
75
|
private syntaxHighlightCompartment?;
|
|
76
76
|
private highlightEffect?;
|
|
77
77
|
/** The host's highlight colour; without one, the theme's selection colour is used. */
|
|
78
|
-
private highlightColor?;
|
|
79
78
|
private themeSelection;
|
|
80
79
|
/** The lines highlighted now, drawn again when the colour changes. */
|
|
81
80
|
private activeHighlight?;
|
|
@@ -84,6 +83,8 @@ export declare class MorphicCodeEditor {
|
|
|
84
83
|
private dropIndicatorEffect?;
|
|
85
84
|
private valueSlotHighlightEffect?;
|
|
86
85
|
private hoverHighlightEffect?;
|
|
86
|
+
/** Hands the code view the line ranges of the groups of blocks. */
|
|
87
|
+
private groupsEffect?;
|
|
87
88
|
private editableHoverHighlightEffect?;
|
|
88
89
|
private emptyClickListener?;
|
|
89
90
|
private disposed;
|
|
@@ -107,6 +108,14 @@ export declare class MorphicCodeEditor {
|
|
|
107
108
|
* before they act. Driven from `setHoverHighlight` (called by MorphicBlocks
|
|
108
109
|
* on the codespace container's `mousemove`/`mouseleave`).
|
|
109
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;
|
|
110
119
|
private buildHoverHighlightExtensions;
|
|
111
120
|
/** Highlight the char range of the block currently under the mouse cursor. */
|
|
112
121
|
setHoverHighlight(range: {
|
|
@@ -132,8 +141,6 @@ export declare class MorphicCodeEditor {
|
|
|
132
141
|
highlightLines(spans: LineSpan | LineSpan[]): void;
|
|
133
142
|
/** Remove all line highlights. */
|
|
134
143
|
clearHighlight(): void;
|
|
135
|
-
/** Update the highlight background colour; `undefined` follows the theme's selection colour. */
|
|
136
|
-
setHighlightColor(color: string | undefined): void;
|
|
137
144
|
/** Show a drop-position indicator above (or below) the given 1-based line. */
|
|
138
145
|
showDropIndicator(line: number, position?: "above" | "below"): void;
|
|
139
146
|
/** Hide the drop-position indicator if currently shown. */
|
|
@@ -164,6 +171,17 @@ export declare class MorphicCodeEditor {
|
|
|
164
171
|
refresh(): void;
|
|
165
172
|
/** Current editor text. Empty string when the editor is not mounted yet. */
|
|
166
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;
|
|
167
185
|
/** 1-based line number under the cursor. Returns 1 when no cursor / not mounted. */
|
|
168
186
|
getCursorLine(): number;
|
|
169
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;
|
|
@@ -6,7 +6,7 @@ export declare function resolveElementType(entry: MorphicElementTypeEntry | unde
|
|
|
6
6
|
* section folded in. Internal: the renderers read the settings from the entry
|
|
7
7
|
* they already hold for the element.
|
|
8
8
|
*/
|
|
9
|
-
export type MorphicElementTypeWithCode = MorphicElementTypeConfig & Pick<MorphicCodeElementConfig, "empty" | "stringQuote" | "emptyStatement">;
|
|
9
|
+
export type MorphicElementTypeWithCode = MorphicElementTypeConfig & Pick<MorphicCodeElementConfig, "empty" | "stringQuote" | "emptyStatement" | "types">;
|
|
10
10
|
/** `elementTypes` with each code element's `code` settings folded in. */
|
|
11
11
|
export declare function withCodeSettings(elementTypes: Record<string, MorphicElementTypeEntry>, code: Record<string, MorphicCodeElementConfig> | undefined): Record<string, MorphicElementTypeEntry>;
|
|
12
12
|
/**
|
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
|
@@ -52,3 +52,8 @@ export declare function ensureTileHighlightStyles(elementName: string, colors?:
|
|
|
52
52
|
* `touch-action: pan-x` on their tiles.
|
|
53
53
|
*/
|
|
54
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;
|
|
@@ -13,13 +13,23 @@ export interface MorphicPlaceholderToken {
|
|
|
13
13
|
kind: "placeholder";
|
|
14
14
|
index: number;
|
|
15
15
|
}
|
|
16
|
+
/** `%1:type`: the name of the type of the value in slot 1, from the element's `code.types`. */
|
|
17
|
+
export interface MorphicValueTypeToken {
|
|
18
|
+
kind: "valueType";
|
|
19
|
+
index: number;
|
|
20
|
+
}
|
|
16
21
|
export interface MorphicFieldToken {
|
|
17
22
|
kind: "field";
|
|
18
23
|
name: string;
|
|
19
24
|
}
|
|
20
|
-
export type MorphicTemplateToken = MorphicImageToken | MorphicTextToken | MorphicPlaceholderToken | MorphicFieldToken;
|
|
25
|
+
export type MorphicTemplateToken = MorphicImageToken | MorphicTextToken | MorphicPlaceholderToken | MorphicValueTypeToken | MorphicFieldToken;
|
|
21
26
|
export declare function parseTemplate(template: string): MorphicTemplateToken[];
|
|
22
27
|
export declare function normalizeTemplateText(text: string): string;
|
|
28
|
+
/**
|
|
29
|
+
* A name as a CSS class part. The name is kept as written (`icon-tiles`,
|
|
30
|
+
* `iconTiles`, `icon_tiles` all work), so the app's CSS uses the same name as
|
|
31
|
+
* its definitions; only characters a class cannot hold become `-`.
|
|
32
|
+
*/
|
|
23
33
|
export declare function toModeClassToken(mode: string): string;
|
|
24
34
|
/**
|
|
25
35
|
* Converts parsed template tokens into an HTML string for toolbox canvas rendering.
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import type { MorphicToolbarConfig, MorphicToolbarCtx, MorphicToolbarItem,
|
|
1
|
+
import type { MorphicToolbarConfig, MorphicToolbarCtx, MorphicToolbarItem, MorphicViewKind, MorphicRunResult } from "./types";
|
|
2
2
|
/** Detail of the `morphic-run` event: the same result `runJavaScript` returns. */
|
|
3
3
|
export type MorphicRunEventDetail = MorphicRunResult;
|
|
4
4
|
export interface MorphicToolbarHandle {
|
|
5
5
|
refresh: () => void;
|
|
6
6
|
dispose: () => void;
|
|
7
7
|
/** The kind of view the toolbar acts on. */
|
|
8
|
-
|
|
8
|
+
kind: MorphicViewKind;
|
|
9
9
|
/** The name of the view the toolbar acts on. */
|
|
10
10
|
view: string;
|
|
11
11
|
}
|
|
12
12
|
export declare const toolbarItems: {
|
|
13
|
-
/**
|
|
14
|
-
|
|
13
|
+
/** The name of the element the view shows, e.g. "python". */
|
|
14
|
+
viewLabel(): MorphicToolbarItem;
|
|
15
15
|
/**
|
|
16
16
|
* Block-aware copy. Resolves the active block via selection-sync or cursor
|
|
17
17
|
* line, then copies it to the framework's internal clipboard. Mirrors the
|
|
@@ -24,6 +24,8 @@ export declare const toolbarItems: {
|
|
|
24
24
|
zoomIn(): MorphicToolbarItem;
|
|
25
25
|
zoomOut(): MorphicToolbarItem;
|
|
26
26
|
zoomFit(): MorphicToolbarItem;
|
|
27
|
+
/** Delete the blocks of the lines selected in a codespace; disabled while none are. */
|
|
28
|
+
deleteSelection(): MorphicToolbarItem;
|
|
27
29
|
clear(): MorphicToolbarItem;
|
|
28
30
|
/**
|
|
29
31
|
* Run the workspace's generated JavaScript and dispatch a "morphic-run"
|
|
@@ -38,16 +40,11 @@ export declare const toolbarItems: {
|
|
|
38
40
|
load(): MorphicToolbarItem;
|
|
39
41
|
/** Reset the workspace to empty. With confirm. Not in defaults. */
|
|
40
42
|
reset(): MorphicToolbarItem;
|
|
41
|
-
/**
|
|
42
|
-
* Toggle the preview pane's host container visibility. Not in defaults — the
|
|
43
|
-
* developer decides whether the user controls this. Looks for an element
|
|
44
|
-
* with `data-morphic-preview-host` and flips its `hidden` attribute.
|
|
45
|
-
*/
|
|
46
|
-
togglePreview(): MorphicToolbarItem;
|
|
47
43
|
readOnlyBadge(): MorphicToolbarItem;
|
|
48
44
|
spacer(): MorphicToolbarItem;
|
|
49
45
|
/** Items for a view that shows the program but cannot change it. */
|
|
50
46
|
readOnlyDefaults(): MorphicToolbarItem[];
|
|
51
|
-
|
|
47
|
+
/** The default items of a view of this kind; a view that shows the program without changing it gets `readOnlyDefaults()`. */
|
|
48
|
+
defaultsFor(kind: MorphicViewKind, readOnly?: boolean): MorphicToolbarItem[];
|
|
52
49
|
};
|
|
53
50
|
export declare function renderToolbar(container: HTMLElement, config: MorphicToolbarConfig, ctx: MorphicToolbarCtx): MorphicToolbarHandle;
|
|
@@ -25,8 +25,6 @@ export declare class MorphicToolboxCanvas {
|
|
|
25
25
|
private readonly modes;
|
|
26
26
|
private currentMode;
|
|
27
27
|
private readonly code;
|
|
28
|
-
/** Per-element block/text override for code elements in tiles (from the active preset). */
|
|
29
|
-
private renderOverride?;
|
|
30
28
|
private previewWorkspace?;
|
|
31
29
|
private readonly onPreviewWorkspace?;
|
|
32
30
|
private previewContainer?;
|
|
@@ -36,6 +34,14 @@ export declare class MorphicToolboxCanvas {
|
|
|
36
34
|
private readonly onDrop;
|
|
37
35
|
/** Targets besides the workspace, such as codespaces, for touch drags. */
|
|
38
36
|
private readonly dropTargets;
|
|
37
|
+
/** Names of the collapsed categories; kept across redraws. */
|
|
38
|
+
private readonly collapsedCategories;
|
|
39
|
+
/** Each drawn category's parts, to collapse or expand without a redraw. */
|
|
40
|
+
private categoryParts;
|
|
41
|
+
/** The category shown with the `"tabs"` layout; the first one until chosen. */
|
|
42
|
+
private activeCategory?;
|
|
43
|
+
private readonly onScroll;
|
|
44
|
+
private readonly resizeObserver;
|
|
39
45
|
/** Adds a tile's block when the tile is chosen with the keyboard. */
|
|
40
46
|
private readonly onChoose?;
|
|
41
47
|
constructor(params: {
|
|
@@ -47,7 +53,6 @@ export declare class MorphicToolboxCanvas {
|
|
|
47
53
|
behaviors: MorphicBehaviorMap;
|
|
48
54
|
elementTypes?: Record<string, MorphicElementTypeEntry>;
|
|
49
55
|
mode: MorphicModeName;
|
|
50
|
-
render?: Record<string, "block" | "text">;
|
|
51
56
|
modes?: MorphicModeDefinition[];
|
|
52
57
|
/** Code element settings; their highlighting colours code shown as text. */
|
|
53
58
|
code?: Record<string, MorphicCodeElementConfig>;
|
|
@@ -57,20 +62,30 @@ export declare class MorphicToolboxCanvas {
|
|
|
57
62
|
dropTargets?: () => TileDropTarget[];
|
|
58
63
|
onChoose?: (blockType: string) => void;
|
|
59
64
|
});
|
|
60
|
-
rerender(mode: MorphicModeName
|
|
65
|
+
rerender(mode: MorphicModeName): void;
|
|
61
66
|
dispose(): void;
|
|
62
67
|
/**
|
|
63
|
-
* Draw the tiles and publish the widest block
|
|
64
|
-
* `--morphic-toolbox-block-width` on the container. The layout
|
|
65
|
-
* app's: one that wants every
|
|
68
|
+
* Draw the tiles and publish the width of the widest block or code shown
|
|
69
|
+
* as text as `--morphic-toolbox-block-width` on the container. The layout
|
|
70
|
+
* stays the app's: one that wants every tile to fit gives the container
|
|
66
71
|
* `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
|
|
72
|
+
* lets its column grow to it (`minmax(250px, min-content)`). Only blocks and
|
|
73
|
+
* code count, neither of which wraps, so long descriptions do not widen it.
|
|
69
74
|
*/
|
|
70
75
|
private render;
|
|
71
|
-
/** Widest block
|
|
76
|
+
/** Widest block or code text on a tile in the current render, in pixels. */
|
|
72
77
|
private widestBlock;
|
|
73
78
|
private renderTiles;
|
|
79
|
+
/** Collapse or expand a category, without drawing the tiles again. */
|
|
80
|
+
private toggleCategory;
|
|
81
|
+
/** Mark the container while tiles wait above or below its visible part. */
|
|
82
|
+
private showScrollHints;
|
|
83
|
+
/**
|
|
84
|
+
* Hide the tiles of collapsed categories and tell their headings; with
|
|
85
|
+
* tabs, show only the chosen category.
|
|
86
|
+
*/
|
|
87
|
+
private showCategories;
|
|
88
|
+
private showCategoryState;
|
|
74
89
|
private createTile;
|
|
75
90
|
/**
|
|
76
91
|
* What a screen reader calls the tile: what the tile shows, in the mode's
|