morphic-blocks 0.4.0 → 0.5.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/definitions.schema.json +96 -0
- package/dist/index.d.ts +4 -1
- package/dist/morphic/MorphicBlocks.d.ts +53 -2
- package/dist/morphic/asset-urls.d.ts +9 -0
- package/dist/morphic/block-sets.d.ts +12 -0
- package/dist/morphic/block-view.d.ts +50 -0
- package/dist/morphic/check-definitions.d.ts +31 -0
- package/dist/morphic/code-editor.d.ts +1 -0
- package/dist/morphic/dropdown-fields.d.ts +72 -0
- package/dist/morphic/element-types.d.ts +1 -1
- package/dist/morphic/operators.d.ts +73 -0
- package/dist/morphic/parent-field.d.ts +7 -0
- package/dist/morphic/repeat-slots.d.ts +31 -0
- package/dist/morphic/strict-slots.d.ts +10 -0
- package/dist/morphic/template-codegen.d.ts +16 -0
- package/dist/morphic/template.d.ts +32 -1
- package/dist/morphic/text-to-blocks.d.ts +34 -0
- package/dist/morphic/toolbox-canvas.d.ts +9 -1
- package/dist/morphic/types.d.ts +150 -4
- package/dist/morphic/validate-definitions.d.ts +2 -1
- package/dist/morphic-blocks.js +3739 -2279
- package/dist/morphic-blocks.umd.cjs +42 -27
- package/package.json +1 -1
package/definitions.schema.json
CHANGED
|
@@ -30,6 +30,11 @@
|
|
|
30
30
|
"type": "array",
|
|
31
31
|
"items": { "$ref": "#/$defs/preset" }
|
|
32
32
|
},
|
|
33
|
+
"blockSets": {
|
|
34
|
+
"description": "Named lists of blocks for the toolbox, used by presets and show({ blockSet }).",
|
|
35
|
+
"type": "object",
|
|
36
|
+
"additionalProperties": { "$ref": "#/$defs/blockSet" }
|
|
37
|
+
},
|
|
33
38
|
"code": {
|
|
34
39
|
"description": "How each code element's language is written, keyed by code element name.",
|
|
35
40
|
"type": "object",
|
|
@@ -87,6 +92,33 @@
|
|
|
87
92
|
"type": "object",
|
|
88
93
|
"additionalProperties": { "type": "string" }
|
|
89
94
|
},
|
|
95
|
+
"operators": {
|
|
96
|
+
"description": "The order of this language's operators, by the sign as it is written. The common signs have an order without it; an entry changes one sign, null takes a sign's order away, false turns the order off (every value built from others is written in brackets).",
|
|
97
|
+
"oneOf": [
|
|
98
|
+
{ "const": false },
|
|
99
|
+
{
|
|
100
|
+
"type": "object",
|
|
101
|
+
"additionalProperties": {
|
|
102
|
+
"oneOf": [
|
|
103
|
+
{ "type": "null" },
|
|
104
|
+
{ "type": "number", "description": "The rank between two values: the higher, the tighter the sign binds." },
|
|
105
|
+
{
|
|
106
|
+
"type": "object",
|
|
107
|
+
"properties": {
|
|
108
|
+
"rank": { "type": "number", "description": "The rank between two values: the higher, the tighter the sign binds." },
|
|
109
|
+
"direction": {
|
|
110
|
+
"enum": ["left", "right", "none", "any"],
|
|
111
|
+
"description": "How the same rank reads without brackets: from the left (default), from the right, or not at all. \"any\": the grouping of this sign does not matter, so no brackets are written between two of it."
|
|
112
|
+
},
|
|
113
|
+
"prefix": { "type": "number", "description": "The rank of the sign in front of one value (-x, not x)." }
|
|
114
|
+
},
|
|
115
|
+
"additionalProperties": false
|
|
116
|
+
}
|
|
117
|
+
]
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
]
|
|
121
|
+
},
|
|
90
122
|
"highlighting": { "$ref": "#/$defs/highlight" },
|
|
91
123
|
"values": {
|
|
92
124
|
"description": "How printed values are written while this element is shown, e.g. Python's True, None and ['a', 'b'].",
|
|
@@ -169,6 +201,22 @@
|
|
|
169
201
|
}
|
|
170
202
|
]
|
|
171
203
|
},
|
|
204
|
+
"blockSet": {
|
|
205
|
+
"description": "A list of block identifiers, or another set with blocks added at the end and removed.",
|
|
206
|
+
"oneOf": [
|
|
207
|
+
{ "type": "array", "items": { "type": "string" } },
|
|
208
|
+
{
|
|
209
|
+
"type": "object",
|
|
210
|
+
"required": ["extends"],
|
|
211
|
+
"properties": {
|
|
212
|
+
"extends": { "type": "string" },
|
|
213
|
+
"add": { "type": "array", "items": { "type": "string" } },
|
|
214
|
+
"remove": { "type": "array", "items": { "type": "string" } }
|
|
215
|
+
},
|
|
216
|
+
"additionalProperties": false
|
|
217
|
+
}
|
|
218
|
+
]
|
|
219
|
+
},
|
|
172
220
|
"preset": {
|
|
173
221
|
"type": "object",
|
|
174
222
|
"required": ["name", "toolbox", "views"],
|
|
@@ -180,6 +228,11 @@
|
|
|
180
228
|
"description": "What each view the preset shows shows, by view name.",
|
|
181
229
|
"type": "object",
|
|
182
230
|
"additionalProperties": { "type": "string" }
|
|
231
|
+
},
|
|
232
|
+
"blockSet": { "description": "The block set the toolbox shows; without it, all blocks.", "type": "string" },
|
|
233
|
+
"categories": {
|
|
234
|
+
"description": "false shows the toolbox's tiles as one list instead of under their categories. Default true.",
|
|
235
|
+
"type": "boolean"
|
|
183
236
|
}
|
|
184
237
|
},
|
|
185
238
|
"additionalProperties": false
|
|
@@ -237,6 +290,22 @@
|
|
|
237
290
|
"type": ["string", "array"],
|
|
238
291
|
"items": { "type": "string" }
|
|
239
292
|
},
|
|
293
|
+
"strict": { "type": "boolean" },
|
|
294
|
+
"repeat": {
|
|
295
|
+
"description": "Let a value slot hold any number of values, written one after the other.",
|
|
296
|
+
"type": "object",
|
|
297
|
+
"properties": {
|
|
298
|
+
"separator": {
|
|
299
|
+
"description": "What is written between two entries: one text, or a text per element name. \", \" by default.",
|
|
300
|
+
"oneOf": [
|
|
301
|
+
{ "type": "string" },
|
|
302
|
+
{ "type": "object", "additionalProperties": { "type": "string" } }
|
|
303
|
+
]
|
|
304
|
+
},
|
|
305
|
+
"count": { "description": "Entries a new block starts with (1 by default).", "type": "integer", "minimum": 0 }
|
|
306
|
+
},
|
|
307
|
+
"additionalProperties": false
|
|
308
|
+
},
|
|
240
309
|
"align": { "enum": ["left", "centre", "right"] },
|
|
241
310
|
"label": { "type": "string" },
|
|
242
311
|
"default": { "$ref": "#/$defs/emptyDefault" }
|
|
@@ -297,6 +366,29 @@
|
|
|
297
366
|
},
|
|
298
367
|
"additionalProperties": false
|
|
299
368
|
},
|
|
369
|
+
{
|
|
370
|
+
"type": "object",
|
|
371
|
+
"required": ["type", "to"],
|
|
372
|
+
"properties": {
|
|
373
|
+
"type": { "const": "reference" },
|
|
374
|
+
"to": {
|
|
375
|
+
"description": "The field whose values this field lists, as \"block.FIELD\" (e.g. \"class_define.NAME\"), or a list of them.",
|
|
376
|
+
"oneOf": [
|
|
377
|
+
{ "type": "string" },
|
|
378
|
+
{ "type": "array", "items": { "type": "string" }, "minItems": 1 }
|
|
379
|
+
]
|
|
380
|
+
},
|
|
381
|
+
"default": { "type": "string" },
|
|
382
|
+
"scope": {
|
|
383
|
+
"description": "A block identifier, or a list: only names declared inside the nearest such block around the field are listed.",
|
|
384
|
+
"oneOf": [
|
|
385
|
+
{ "type": "string" },
|
|
386
|
+
{ "type": "array", "items": { "type": "string" }, "minItems": 1 }
|
|
387
|
+
]
|
|
388
|
+
}
|
|
389
|
+
},
|
|
390
|
+
"additionalProperties": false
|
|
391
|
+
},
|
|
300
392
|
{
|
|
301
393
|
"type": "object",
|
|
302
394
|
"required": ["type"],
|
|
@@ -359,6 +451,10 @@
|
|
|
359
451
|
"output": { "$ref": "#/$defs/connectionSpec" },
|
|
360
452
|
"previousStatement": { "$ref": "#/$defs/connectionSpec" },
|
|
361
453
|
"nextStatement": { "$ref": "#/$defs/connectionSpec" },
|
|
454
|
+
"strict": {
|
|
455
|
+
"description": "Let the block go only where the place above it has a check matching its previousStatement or output check.",
|
|
456
|
+
"type": "boolean"
|
|
457
|
+
},
|
|
362
458
|
"inputsInline": { "type": "boolean" },
|
|
363
459
|
"tooltip": { "type": "string" },
|
|
364
460
|
"helpUrl": { "type": "string" }
|
package/dist/index.d.ts
CHANGED
|
@@ -2,10 +2,13 @@ import "blockly/blocks";
|
|
|
2
2
|
export { MorphicBlocks } from "./morphic/MorphicBlocks";
|
|
3
3
|
export { MorphicToolboxCanvas } from "./morphic/toolbox-canvas";
|
|
4
4
|
export { toCleanId } from "./morphic/block-namespace";
|
|
5
|
+
export { toModeClassToken as toClassToken } from "./morphic/template";
|
|
5
6
|
export { toolbarItems, renderToolbar } from "./morphic/toolbar";
|
|
6
7
|
export type { MorphicRunEventDetail, MorphicToolbarHandle, } from "./morphic/toolbar";
|
|
7
8
|
export { makeResizable } from "./morphic/resize";
|
|
8
9
|
export { validateDefinitions } from "./morphic/validate-definitions";
|
|
10
|
+
export { checkDefinitions } from "./morphic/check-definitions";
|
|
11
|
+
export { resolveBlockSets, type ResolvedBlockSets } from "./morphic/block-sets";
|
|
9
12
|
export type { ValidateDefinitionsArgs, DefinitionValidationResult, } from "./morphic/validate-definitions";
|
|
10
13
|
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, 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";
|
|
14
|
+
export type { MorphicElementType, MorphicElementTypeConfig, MorphicElementTypeEntry, MorphicEmptyDefaultConfig, MorphicHighlightDefinition, MorphicJavaScriptConfig, MorphicBehaviorContext, MorphicBehaviorDefinition, MorphicBehaviorMap, MorphicBehaviorProxy, MorphicBlockBehavior, MorphicBlockDefinition, MorphicBlockShape, MorphicBlocksFormat, MorphicBlocksFormatJson, MorphicCodeElementConfig, MorphicOperatorOrder, 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, MorphicRepeatConfig, MorphicRepeatRange, MorphicTextLoadResult, MorphicRenderContext, MorphicResolvedView, MorphicStyleBundle, MorphicToolbarConfig, MorphicToolbarCtx, MorphicToolbarDisplay, MorphicToolbarItem, MorphicToolbarRender, MorphicToolboxCanvasOptions, MorphicToolboxCategory, MorphicToolboxConfig, MorphicToolboxLayout, MorphicToolboxModeLabel, MorphicBlockElements, MorphicModeDefinition, MorphicTileRender, MorphicPresetDefinition, MorphicBlockSet, MorphicRunOutputLine, MorphicRunResult, MorphicSelectionSyncOptions, } from "./morphic/types";
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import * as Blockly from "blockly";
|
|
2
2
|
import { type MorphicToolbarHandle } from "./toolbar";
|
|
3
|
-
import type { MorphicBehaviorMap, MorphicBlocksFormat, MorphicBlocksFormatJson, MorphicCodeEditorOptions, MorphicCodeEditorTheme, MorphicCodespaceDeleteOptions, MorphicCodeGenerationResult, MorphicModeName, MorphicMountConfig, MorphicPresetDefinition, MorphicRunResult, MorphicSelectionSyncOptions, MorphicToolbarConfig, MorphicToolboxCanvasOptions, MorphicViewHandle, MorphicViewOptions } from "./types";
|
|
3
|
+
import type { MorphicBehaviorMap, MorphicBlocksFormat, MorphicBlocksFormatJson, MorphicCodeEditorOptions, MorphicCodeEditorTheme, MorphicCodespaceDeleteOptions, MorphicCodeGenerationResult, MorphicModeName, MorphicMountConfig, MorphicTextLoadResult, MorphicPresetDefinition, MorphicRunResult, MorphicSelectionSyncOptions, MorphicToolbarConfig, MorphicToolboxCanvasOptions, MorphicViewHandle, MorphicViewOptions } from "./types";
|
|
4
4
|
export declare class MorphicBlocks extends EventTarget {
|
|
5
5
|
private readonly definitions;
|
|
6
|
+
/** The blocks as loaded; each mount resolves their images (`assetUrl`) from these. */
|
|
7
|
+
private readonly loadedDefinitions;
|
|
6
8
|
private readonly behaviors;
|
|
7
9
|
/** Element types with the mounted `code` settings folded in (see withCodeSettings). */
|
|
8
10
|
private elementTypes;
|
|
@@ -58,6 +60,13 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
58
60
|
/** The definitions still use the old top level `highlighting` map. */
|
|
59
61
|
private readonly formatHasHighlighting;
|
|
60
62
|
private readonly formatCategories?;
|
|
63
|
+
private readonly formatBlockSets?;
|
|
64
|
+
/** Every block set's blocks, resolved at mount. */
|
|
65
|
+
private blockSetLists;
|
|
66
|
+
/** The block set the toolbox shows; `undefined` shows the toolbox's own blocks. */
|
|
67
|
+
private activeBlockSet?;
|
|
68
|
+
/** Whether the toolbox groups its tiles under the categories; presets and show() switch it. */
|
|
69
|
+
private categoriesShown;
|
|
61
70
|
/**
|
|
62
71
|
* Build an engine from a whole definitions file plus its behaviors — the two
|
|
63
72
|
* artifacts a developer authors. `blocks` and `elementTypes` configure the
|
|
@@ -178,6 +187,12 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
178
187
|
* since lines always go to a console the host passes in.
|
|
179
188
|
*/
|
|
180
189
|
logToConsole?: boolean;
|
|
190
|
+
/**
|
|
191
|
+
* Values the program can use by name, e.g. `{ turtle, canvas }` for the
|
|
192
|
+
* host's own functions. Each name must be a JavaScript identifier;
|
|
193
|
+
* `console` has its own option.
|
|
194
|
+
*/
|
|
195
|
+
globals?: Record<string, unknown>;
|
|
181
196
|
}): MorphicRunResult;
|
|
182
197
|
/** Whether the framework's internal clipboard has a copyable to paste. */
|
|
183
198
|
hasClipboardContents(): boolean;
|
|
@@ -228,17 +243,37 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
228
243
|
private teardownToolbarBlocklyListener;
|
|
229
244
|
/**
|
|
230
245
|
* Switch what the toolbox and the views show, in the shape of a preset:
|
|
231
|
-
* `show({ toolbox: "pseudo", views: { blocks: "pseudo", code: "python" } })`.
|
|
246
|
+
* `show({ toolbox: "pseudo", blockSet: "level-2-blocks", categories: false, views: { blocks: "pseudo", code: "python" } })`.
|
|
232
247
|
* Everything left out stays as it is; showing and hiding the views'
|
|
233
248
|
* containers stays the app's job.
|
|
234
249
|
*/
|
|
235
250
|
show(shown: {
|
|
236
251
|
toolbox?: MorphicModeName;
|
|
237
252
|
views?: Record<string, string>;
|
|
253
|
+
/** The block set the toolbox shows; `null` shows all of the toolbox's blocks again. */
|
|
254
|
+
blockSet?: string | null;
|
|
255
|
+
/** Whether the toolbox groups its tiles under the categories; `false` shows one list. */
|
|
256
|
+
categories?: boolean;
|
|
238
257
|
}): void;
|
|
239
258
|
/** Moved in 0.4.0: `show()` takes its place. */
|
|
240
259
|
setModes(_modes: unknown): never;
|
|
241
260
|
generateJavaScript(): string;
|
|
261
|
+
/**
|
|
262
|
+
* The program as a code element writes it, the text a codespace showing
|
|
263
|
+
* that element has: `engine.generateText("python")`. Works without a view
|
|
264
|
+
* of that element.
|
|
265
|
+
*/
|
|
266
|
+
generateText(element: string): string;
|
|
267
|
+
/**
|
|
268
|
+
* Replace the program with the blocks that write `text` in a code element:
|
|
269
|
+
* `engine.loadText("print(1)", { element: "python" })`. The text must be
|
|
270
|
+
* valid and written with the blocks' templates; when a line fits no block,
|
|
271
|
+
* nothing changes and the result names the line. One undo brings the old
|
|
272
|
+
* program back.
|
|
273
|
+
*/
|
|
274
|
+
loadText(text: string, options: {
|
|
275
|
+
element: string;
|
|
276
|
+
}): MorphicTextLoadResult;
|
|
242
277
|
generateJavaScriptWithMetadata(): MorphicCodeGenerationResult;
|
|
243
278
|
mountCodeEditor(container: HTMLElement, options?: MorphicCodeEditorOptions): Promise<void>;
|
|
244
279
|
private attachCodespaceDropTarget;
|
|
@@ -444,6 +479,18 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
444
479
|
private registerBlocks;
|
|
445
480
|
/** Build a newly created block with this engine's definition, mode and behavior. */
|
|
446
481
|
private initManagedBlock;
|
|
482
|
+
/** Take the state saved with a block: the placeholder slots it had dealt with, and how many entries its repeating slots have. */
|
|
483
|
+
private loadBlockState;
|
|
484
|
+
/** Whether the block in a slot is the slot's placeholder default (a real block the framework put there). */
|
|
485
|
+
private isSlotDefault;
|
|
486
|
+
/** Build a block again as its view shows it now, e.g. after a repeating slot got or lost an entry. */
|
|
487
|
+
private rebuildBlock;
|
|
488
|
+
/**
|
|
489
|
+
* Give a repeating slot one entry more or less (`delta` +1 or -1). The last
|
|
490
|
+
* entry goes; a block in it is set free first, so nothing is deleted. One
|
|
491
|
+
* undo takes the change back, and other views follow like any other edit.
|
|
492
|
+
*/
|
|
493
|
+
changeRepeat(block: Blockly.Block, slotName: string, delta: number): void;
|
|
447
494
|
private validateViews;
|
|
448
495
|
private createHeadlessHost;
|
|
449
496
|
private resolveMode;
|
|
@@ -470,6 +517,10 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
470
517
|
private renderFlyoutBlocks;
|
|
471
518
|
private refreshToolbox;
|
|
472
519
|
private bindFlyoutWorkspace;
|
|
520
|
+
/** Each block with its image paths passed through the mount's `assetUrl`; as loaded without one. */
|
|
521
|
+
private resolveAssetUrls;
|
|
522
|
+
/** The blocks the toolbox shows: the active block set's, else the mount's `toolbox.blocks` (all when unset). */
|
|
523
|
+
private toolboxBlocks;
|
|
473
524
|
private resolveToolboxDefinition;
|
|
474
525
|
private createBehaviorContext;
|
|
475
526
|
private resolveClassNames;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { MorphicBlockDefinition, MorphicElementTypeEntry } from "./types";
|
|
2
|
+
/** Where the app loads an image the definitions name; `undefined` keeps the path. */
|
|
3
|
+
export type MorphicAssetUrl = (path: string) => string | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* A block with every image path it names passed through `assetUrl`: the
|
|
6
|
+
* `<img>` in its templates, its image elements, and its dropdown pictures.
|
|
7
|
+
* Returns the block itself when nothing changes.
|
|
8
|
+
*/
|
|
9
|
+
export declare function withAssetUrls(block: MorphicBlockDefinition, elementTypes: Record<string, MorphicElementTypeEntry>, assetUrl: MorphicAssetUrl): MorphicBlockDefinition;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { MorphicBlockSet } from "./types";
|
|
2
|
+
export interface ResolvedBlockSets {
|
|
3
|
+
/** Each set's blocks, in the set's order (the toolbox's order when categories are off). */
|
|
4
|
+
lists: Map<string, string[]>;
|
|
5
|
+
errors: string[];
|
|
6
|
+
warnings: string[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* The blocks of every set in `blockSets`. A set is a list, or another set
|
|
10
|
+
* (`extends`) with blocks added at the end and blocks removed.
|
|
11
|
+
*/
|
|
12
|
+
export declare function resolveBlockSets(blockSets: Record<string, MorphicBlockSet> | undefined, isBlock: (identifier: string) => boolean): ResolvedBlockSets;
|
|
@@ -18,7 +18,29 @@ export type MorphicManagedBlock = Blockly.BlockSvg & {
|
|
|
18
18
|
* until a mode that shows the field again restores it.
|
|
19
19
|
*/
|
|
20
20
|
__morphicFieldMemory?: Map<string, unknown>;
|
|
21
|
+
/** The state of every default (shadow) the block has had, by input name. */
|
|
22
|
+
__morphicShadowMemory?: Map<string, Blockly.serialization.blocks.State>;
|
|
23
|
+
/**
|
|
24
|
+
* Set while a block is being made. A state loaded then belongs to a saved
|
|
25
|
+
* block (a program, a paste, an undo), not to an edit of this one.
|
|
26
|
+
*/
|
|
27
|
+
__morphicFresh?: boolean;
|
|
21
28
|
};
|
|
29
|
+
/** The slots whose placeholder default a block has dealt with, to save with it; `undefined` when it has none. */
|
|
30
|
+
export declare function savedPlaceholderSlots(block: Blockly.Block): string[] | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Give a block that is being made from a saved one the placeholder slots it
|
|
33
|
+
* had dealt with. The placeholders it was just built with are not its own:
|
|
34
|
+
* the saved block had kept, replaced or deleted them, and what it held is
|
|
35
|
+
* loaded next. Returns whether the state was taken.
|
|
36
|
+
*/
|
|
37
|
+
export declare function loadPlaceholderSlots(block: Blockly.Block, saved: unknown): boolean;
|
|
38
|
+
/**
|
|
39
|
+
* Make an input of a block new again: it gets its default like the input of
|
|
40
|
+
* a new block, not what an earlier input of that name held. For the entry a
|
|
41
|
+
* repeating slot gets with plus.
|
|
42
|
+
*/
|
|
43
|
+
export declare function forgetInputDefaults(block: Blockly.Block, inputName: string): void;
|
|
22
44
|
export interface MorphicApplyBlockViewParams {
|
|
23
45
|
block: Blockly.BlockSvg;
|
|
24
46
|
definition: MorphicBlockDefinition;
|
|
@@ -44,6 +66,12 @@ export interface MorphicApplyBlockViewParams {
|
|
|
44
66
|
* Unlike `elementTypes`, it adds no slot defaults. Falls back to `elementTypes`.
|
|
45
67
|
*/
|
|
46
68
|
codeSettings?: Record<string, MorphicElementTypeEntry>;
|
|
69
|
+
/**
|
|
70
|
+
* Called when a plus or minus button of a repeating slot is pressed, with
|
|
71
|
+
* the slot's name and +1 or -1. Without it the block has no such buttons
|
|
72
|
+
* (toolbox tiles, read only views).
|
|
73
|
+
*/
|
|
74
|
+
onRepeat?: (slotName: string, delta: number) => void;
|
|
47
75
|
}
|
|
48
76
|
export declare function applyBlockView(params: MorphicApplyBlockViewParams): void;
|
|
49
77
|
/**
|
|
@@ -86,5 +114,27 @@ export declare function applyPresetClass(root: Element, preset: string | undefin
|
|
|
86
114
|
* (`morphic-mode-<mode>`), and both with the context.
|
|
87
115
|
*/
|
|
88
116
|
export declare function decorateBlockRoot(block: Blockly.BlockSvg, shown: string, context: MorphicRenderContext): void;
|
|
117
|
+
/**
|
|
118
|
+
* The plus or minus button of a repeating slot: a small field that is pressed
|
|
119
|
+
* instead of edited. It is text, so app CSS styles it through its classes,
|
|
120
|
+
* `morphic-repeat-button` and `morphic-repeat-add` / `morphic-repeat-remove`.
|
|
121
|
+
*/
|
|
122
|
+
export declare class MorphicRepeatButton extends Blockly.Field<string> {
|
|
123
|
+
readonly action: "add" | "remove";
|
|
124
|
+
private readonly press;
|
|
125
|
+
EDITABLE: boolean;
|
|
126
|
+
SERIALIZABLE: boolean;
|
|
127
|
+
CURSOR: string;
|
|
128
|
+
constructor(action: "add" | "remove", press: () => void);
|
|
129
|
+
initView(): void;
|
|
130
|
+
protected showEditor_(): void;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Give a block the declared fields its template leaves out, on a row that is
|
|
134
|
+
* not drawn. The template decides what a block shows, `fields` what it has,
|
|
135
|
+
* so text views, generated code and saved programs find every field whatever
|
|
136
|
+
* the workspace shows.
|
|
137
|
+
*/
|
|
138
|
+
export declare function keepOmittedFields(block: Blockly.BlockSvg, definition: MorphicBlockDefinition, elementName: string | undefined): void;
|
|
89
139
|
export declare function captureFieldValues(block: Blockly.BlockSvg): Map<string, unknown>;
|
|
90
140
|
export declare function restoreFieldValues(block: Blockly.BlockSvg, values: Map<string, unknown>): void;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type { MorphicBehaviorMap } from "./types";
|
|
2
|
+
import { type DefinitionValidationResult } from "./validate-definitions";
|
|
3
|
+
import type { MorphicBlocksFormat, MorphicBlocksFormatJson, MorphicElementTypeEntry, MorphicModeDefinition, MorphicPresetDefinition, MorphicViewDeclaration, MorphicViewKind } from "./types";
|
|
4
|
+
/** The views without a `views` section: one workspace, one codespace. */
|
|
5
|
+
export declare const DEFAULT_VIEWS: Record<string, MorphicViewKind>;
|
|
6
|
+
/** The views in their long form; a bare kind is the short form. */
|
|
7
|
+
export declare function normalizeViews(views: Record<string, MorphicViewKind | MorphicViewDeclaration> | undefined): Record<string, MorphicViewDeclaration>;
|
|
8
|
+
/** Each declared view's kind. */
|
|
9
|
+
export declare function checkViewDeclarations(views: Record<string, MorphicViewDeclaration>): string[];
|
|
10
|
+
/**
|
|
11
|
+
* The presets against the modes, views and elements: duplicate names, an
|
|
12
|
+
* unknown toolbox mode, views that show no code element. A view no one
|
|
13
|
+
* declared only warns, since a view added later may carry the name.
|
|
14
|
+
*/
|
|
15
|
+
export declare function checkPresets(args: {
|
|
16
|
+
presets: MorphicPresetDefinition[] | undefined;
|
|
17
|
+
modes: MorphicModeDefinition[] | undefined;
|
|
18
|
+
views: Record<string, MorphicViewDeclaration>;
|
|
19
|
+
elementTypes: Record<string, MorphicElementTypeEntry>;
|
|
20
|
+
}): DefinitionValidationResult;
|
|
21
|
+
/** Settings that moved in an earlier version, named so an upgrade fails with directions. */
|
|
22
|
+
export declare function movedDefinitionErrors(presets: MorphicPresetDefinition[] | undefined, hasHighlighting: boolean): string[];
|
|
23
|
+
/**
|
|
24
|
+
* Every check `mount()` runs on a definitions file, without mounting: the
|
|
25
|
+
* blocks themselves, the definitions, the presets and the views. Errors stop
|
|
26
|
+
* a mount; warnings do not. With `modeStyles` (the modes that have a
|
|
27
|
+
* stylesheet), a mode without one warns too.
|
|
28
|
+
*/
|
|
29
|
+
export declare function checkDefinitions(format: MorphicBlocksFormat | MorphicBlocksFormatJson, behaviors?: MorphicBehaviorMap, options?: {
|
|
30
|
+
modeStyles?: string[];
|
|
31
|
+
}): DefinitionValidationResult;
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import * as Blockly from "blockly";
|
|
2
|
+
/**
|
|
3
|
+
* A declared dropdown whose open menu carries classes for app CSS:
|
|
4
|
+
* `morphic-menu` and `morphic-menu-<FIELD>` (the field's name), e.g. to lay
|
|
5
|
+
* picture choices out in a grid or hide the check marks.
|
|
6
|
+
*/
|
|
7
|
+
export declare class MorphicDropdown extends Blockly.FieldDropdown {
|
|
8
|
+
protected showEditor_(event?: MouseEvent): void;
|
|
9
|
+
}
|
|
10
|
+
/** The parts of a reference's target, `"class_define.NAME"`: a block and one of its fields. */
|
|
11
|
+
export declare function parseReferenceTarget(target: unknown): {
|
|
12
|
+
block: string;
|
|
13
|
+
field: string;
|
|
14
|
+
} | null;
|
|
15
|
+
/**
|
|
16
|
+
* A reference field (`{ "type": "reference", "to": "class_define.NAME" }`): a
|
|
17
|
+
* dropdown of the names the program declares, i.e. what the `NAME` field of
|
|
18
|
+
* every `class_define` block holds. Its value is the name itself, so text
|
|
19
|
+
* views, generated code and saved programs read it like any other field. A
|
|
20
|
+
* name whose declaration is gone stays as it is.
|
|
21
|
+
*/
|
|
22
|
+
export declare class MorphicReference extends MorphicDropdown {
|
|
23
|
+
private readonly initial;
|
|
24
|
+
private readonly targets;
|
|
25
|
+
private readonly scopes;
|
|
26
|
+
constructor(to: string | string[], initial?: string, scope?: string | string[]);
|
|
27
|
+
/** Whether this field lists what `field` of `declaration` holds: a target of it, and in its scope. */
|
|
28
|
+
refersTo(declaration: Blockly.Block, field: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* The block a scoped reference looks inside: the nearest block around it
|
|
31
|
+
* of a `scope` type (the class around `self.name`). `undefined` without a
|
|
32
|
+
* scope, `null` when no such block is around it.
|
|
33
|
+
*/
|
|
34
|
+
private scopeBlock;
|
|
35
|
+
/** Whether the field lists only what a block around it holds. */
|
|
36
|
+
isScoped(): boolean;
|
|
37
|
+
/** Whether a declaration is one this reference may name: anywhere, or inside its scope block. */
|
|
38
|
+
private sees;
|
|
39
|
+
/**
|
|
40
|
+
* The names the program declares for this field, each once, in alphabetical
|
|
41
|
+
* order. `known` keeps the lists of one pass over many references, which
|
|
42
|
+
* mostly ask for the same one.
|
|
43
|
+
*/
|
|
44
|
+
declaredNames(known?: Map<string, string[]>): string[];
|
|
45
|
+
/** Whether the name is one nothing declares (its declaration was deleted, or never made). */
|
|
46
|
+
isMissing(known?: Map<string, string[]>): boolean;
|
|
47
|
+
/** Mark the field with `morphic-reference-missing` while its name is one nothing declares. */
|
|
48
|
+
showMissing(known?: Map<string, string[]>): void;
|
|
49
|
+
initView(): void;
|
|
50
|
+
/**
|
|
51
|
+
* A new reference that names nothing declared takes the first declared
|
|
52
|
+
* name. One that was set to something else is left alone.
|
|
53
|
+
*/
|
|
54
|
+
pickDeclared(): void;
|
|
55
|
+
private nameOptions;
|
|
56
|
+
/** The names change with the program, so they are never read from a cache. */
|
|
57
|
+
getOptions(): Blockly.MenuOption[];
|
|
58
|
+
/** Any name is kept: its declaration may be loaded later, or be gone. */
|
|
59
|
+
protected doClassValidation_(newValue?: string): string | null;
|
|
60
|
+
protected doValueUpdate_(newValue: string): void;
|
|
61
|
+
}
|
|
62
|
+
/** Let the references of one edit keep the names they have, declared or not. */
|
|
63
|
+
export declare function keepNamesOf(group: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Keep a program's references in step with its declarations: a renamed
|
|
66
|
+
* declaration renames the references that named it (unless another
|
|
67
|
+
* declaration still has the old name), a reference that is new or moved
|
|
68
|
+
* takes a declared name when its own names nothing, and every reference
|
|
69
|
+
* shows whether its name is declared. The changes join the edit that caused
|
|
70
|
+
* them, so one undo takes both back.
|
|
71
|
+
*/
|
|
72
|
+
export declare function keepReferencesInStep(workspace: Blockly.Workspace): void;
|
|
@@ -6,7 +6,7 @@ export declare function resolveElementType(entry: MorphicElementTypeEntry | unde
|
|
|
6
6
|
* section folded in. Internal: the renderers read the settings from the entry
|
|
7
7
|
* they already hold for the element.
|
|
8
8
|
*/
|
|
9
|
-
export type MorphicElementTypeWithCode = MorphicElementTypeConfig & Pick<MorphicCodeElementConfig, "empty" | "stringQuote" | "emptyStatement" | "types">;
|
|
9
|
+
export type MorphicElementTypeWithCode = MorphicElementTypeConfig & Pick<MorphicCodeElementConfig, "empty" | "stringQuote" | "emptyStatement" | "types" | "operators">;
|
|
10
10
|
/** `elementTypes` with each code element's `code` settings folded in. */
|
|
11
11
|
export declare function withCodeSettings(elementTypes: Record<string, MorphicElementTypeEntry>, code: Record<string, MorphicCodeElementConfig> | undefined): Record<string, MorphicElementTypeEntry>;
|
|
12
12
|
/**
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { type MorphicTemplateToken } from "./template";
|
|
2
|
+
import type { MorphicBlockDefinition, MorphicCodeElementConfig } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* The order of operators in text. Blocks need none: a block in a slot is one
|
|
5
|
+
* value. Text does: `2 + 3 * 4` says which part belongs together only through
|
|
6
|
+
* the order of `+` and `*`. The writer (template-codegen.ts) and the reader
|
|
7
|
+
* (text-to-blocks.ts) ask the same questions here, so what one writes without
|
|
8
|
+
* brackets the other reads as the same blocks.
|
|
9
|
+
*
|
|
10
|
+
* An operator is known by its template: two values with a sign between them
|
|
11
|
+
* (`%1 + %2`, `%1 %OP %2`), a sign in front of one value (`not %1`, `-%1`), or
|
|
12
|
+
* a list of values with the sign as separator. The sign, as the language
|
|
13
|
+
* writes it, has a rank; a sign without one keeps the rule there was before
|
|
14
|
+
* ranks: brackets around every value built from others.
|
|
15
|
+
*/
|
|
16
|
+
type OperatorSettings = MorphicCodeElementConfig["operators"];
|
|
17
|
+
/**
|
|
18
|
+
* What may stand in a slot without brackets: a value of this rank, or
|
|
19
|
+
* (`above`) only a higher one. `sign` names an operator that stands free
|
|
20
|
+
* there all the same: one whose grouping does not matter, beside itself.
|
|
21
|
+
*/
|
|
22
|
+
export interface OperandBound {
|
|
23
|
+
rank: number;
|
|
24
|
+
above: boolean;
|
|
25
|
+
sign?: string;
|
|
26
|
+
}
|
|
27
|
+
/** A slot that takes any value as it is: nothing around it binds. */
|
|
28
|
+
export declare const WHOLE: OperandBound;
|
|
29
|
+
/** A slot that takes only a value that is one piece: a name, a number, a call. */
|
|
30
|
+
export declare const ATOM: OperandBound;
|
|
31
|
+
export declare function allows(bound: OperandBound, rank: number, sign?: string): boolean;
|
|
32
|
+
type SignPart = {
|
|
33
|
+
text: string;
|
|
34
|
+
} | {
|
|
35
|
+
field: string;
|
|
36
|
+
};
|
|
37
|
+
/** A template that is an operator, with the slot numbers of its values. */
|
|
38
|
+
export type OperatorForm = {
|
|
39
|
+
kind: "infix";
|
|
40
|
+
left: number;
|
|
41
|
+
right: number;
|
|
42
|
+
sign: SignPart[];
|
|
43
|
+
} | {
|
|
44
|
+
kind: "prefix";
|
|
45
|
+
slot: number;
|
|
46
|
+
sign: SignPart[];
|
|
47
|
+
} | {
|
|
48
|
+
kind: "chain";
|
|
49
|
+
slot: number;
|
|
50
|
+
sign: string;
|
|
51
|
+
};
|
|
52
|
+
/** Whether a value block's template is an operator, and of which shape. */
|
|
53
|
+
export declare function operatorForm(tokens: MorphicTemplateToken[], definition: MorphicBlockDefinition, element: string | undefined): OperatorForm | null;
|
|
54
|
+
/** An operator whose sign has a rank: the sign, its rank, and what each of its slots takes. */
|
|
55
|
+
export interface RankedOperator {
|
|
56
|
+
sign: string;
|
|
57
|
+
rank: number;
|
|
58
|
+
bound(slot: number): OperandBound;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* The rank of an operator as it is written right now. `shown` gives the text
|
|
62
|
+
* a field shows (`%OP` as `and`); `null` when the sign has no rank.
|
|
63
|
+
*/
|
|
64
|
+
export declare function rankOperator(form: OperatorForm, shown: (field: string) => string | undefined, settings: OperatorSettings): RankedOperator | null;
|
|
65
|
+
/**
|
|
66
|
+
* What a slot takes without brackets in a template that is no operator
|
|
67
|
+
* itself, from the text right around it. A sign with a rank there makes the
|
|
68
|
+
* slot its operand (`std::cout << %1 << std::endl;`, `i < %1;`, `if not %1:`);
|
|
69
|
+
* without one, the slot takes any value where it stands free (`max(%1, %2)`,
|
|
70
|
+
* `return %1`) and one piece only where the text binds to it (`%1.length`).
|
|
71
|
+
*/
|
|
72
|
+
export declare function slotBound(tokens: MorphicTemplateToken[], index: number, statement: boolean, settings: OperatorSettings): OperandBound;
|
|
73
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type * as Blockly from "blockly";
|
|
2
|
+
/**
|
|
3
|
+
* The field a `%parent.NAME` token shows: the field of that name on the
|
|
4
|
+
* nearest block around this one that has it (the class around a method), or
|
|
5
|
+
* `null` when no block around it has one.
|
|
6
|
+
*/
|
|
7
|
+
export declare function findParentField(block: Blockly.Block, name: string): Blockly.Field | null;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import type * as Blockly from "blockly";
|
|
2
|
+
import type { MorphicBlockDefinition, MorphicInputSlotDefinition } from "./types";
|
|
3
|
+
/** What a saved block holds about its repeating slots: entries per slot name. */
|
|
4
|
+
export interface MorphicRepeatState {
|
|
5
|
+
repeat: Record<string, number>;
|
|
6
|
+
}
|
|
7
|
+
export declare function isRepeating(slot: MorphicInputSlotDefinition | undefined): boolean;
|
|
8
|
+
/** The Blockly input name of a slot: its `name`, or `ARG<n>` after its placeholder. */
|
|
9
|
+
export declare function slotInputName(slot: MorphicInputSlotDefinition | undefined, placeholderIndex: number | string): string;
|
|
10
|
+
/** The Blockly input name of one entry of a repeating slot. */
|
|
11
|
+
export declare function repeatInputName(slotName: string, index: number): string;
|
|
12
|
+
/** A block's repeating slots, by input name. */
|
|
13
|
+
export declare function repeatingSlots(definition: MorphicBlockDefinition): Map<string, MorphicInputSlotDefinition>;
|
|
14
|
+
/** How many entries a repeating slot has on a block; a new block starts with `repeat.count` (1). */
|
|
15
|
+
export declare function repeatCount(block: Blockly.Block, slotName: string, slot: MorphicInputSlotDefinition): number;
|
|
16
|
+
export declare function setRepeatCount(block: Blockly.Block, slotName: string, count: number): void;
|
|
17
|
+
/** The input names of a repeating slot's entries on a block, in order. */
|
|
18
|
+
export declare function repeatEntries(block: Blockly.Block, slotName: string, slot: MorphicInputSlotDefinition): string[];
|
|
19
|
+
/** What is written between two entries in an element: `repeat.separator` (a text, or one per element), `, ` by default. */
|
|
20
|
+
export declare function repeatSeparator(slot: MorphicInputSlotDefinition, elementName: string | undefined): string;
|
|
21
|
+
/**
|
|
22
|
+
* Whether the entries are operands of an operator (`" + "`), so a composed
|
|
23
|
+
* entry needs brackets, or simply listed (`, `), where it does not.
|
|
24
|
+
*/
|
|
25
|
+
export declare function separatorComposes(separator: string): boolean;
|
|
26
|
+
/** The slot an input belongs to: the input of a plain slot, or an entry of a repeating one. */
|
|
27
|
+
export declare function slotOfInput(definition: MorphicBlockDefinition, inputName: string): MorphicInputSlotDefinition | undefined;
|
|
28
|
+
/** The state Blockly saves with a block that has repeating slots, `null` for one without. */
|
|
29
|
+
export declare function saveRepeatState(block: Blockly.Block, definition: MorphicBlockDefinition): MorphicRepeatState | null;
|
|
30
|
+
/** Take the counts of a saved state; returns whether any count changed. */
|
|
31
|
+
export declare function loadRepeatState(block: Blockly.Block, definition: MorphicBlockDefinition, state: unknown): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type * as Blockly from "blockly";
|
|
2
|
+
/** Mark a slot's connection as strict; a rebuilt slot is marked again. */
|
|
3
|
+
export declare function markStrictSlot(connection: Blockly.Connection): void;
|
|
4
|
+
/** Mark the connection a block hangs by (above it, or its output) as strict. */
|
|
5
|
+
export declare function markStrictBlock(block: Blockly.Block): void;
|
|
6
|
+
/**
|
|
7
|
+
* Make a workspace refuse what strict slots and blocks refuse. It adds to the checker the
|
|
8
|
+
* workspace has, so a checker the app plugged in keeps deciding first.
|
|
9
|
+
*/
|
|
10
|
+
export declare function enforceStrictSlots(workspace: Blockly.Workspace): void;
|
|
@@ -18,3 +18,19 @@ export declare function generateTextFromWorkspace(workspace: Blockly.Workspace,
|
|
|
18
18
|
options?: {
|
|
19
19
|
emptyStatements?: boolean;
|
|
20
20
|
}): MorphicCodeGenerationResult;
|
|
21
|
+
/**
|
|
22
|
+
* Whether a template's values all sit inside brackets of its own, with only
|
|
23
|
+
* a name in front: `random(%1, %2)`, `%NAME(%1)`, `new List(%1)`, `[%1]`,
|
|
24
|
+
* and `!(%1)`, which binds before any operator. A slot or another operator
|
|
25
|
+
* outside the brackets (`%1.get(%2)`, `-(%1)`, `f(%1) + %2`) means it is an
|
|
26
|
+
* operand like any other.
|
|
27
|
+
*/
|
|
28
|
+
export declare function closesItself(template: string): boolean;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a template only goes on from the value in front: `%1[%2]`,
|
|
31
|
+
* `%1.size()`, `%1.%NAME`. What goes on from a value binds before every
|
|
32
|
+
* operator, so the whole is one piece like a name (`items[1] + 1`). Anything
|
|
33
|
+
* else behind the first slot (`%1 + %2`, `%1.length as x`) makes it an
|
|
34
|
+
* operand like any other.
|
|
35
|
+
*/
|
|
36
|
+
export declare function goesOnFromValue(template: string): boolean;
|