morphic-blocks 0.4.0 → 0.6.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 +98 -1
- package/dist/index.d.ts +4 -1
- package/dist/morphic/MorphicBlocks.d.ts +122 -5
- 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 +75 -3
- package/dist/morphic/dropdown-fields.d.ts +78 -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/styles.d.ts +18 -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 +59 -0
- package/dist/morphic/tile-drop.d.ts +160 -0
- package/dist/morphic/toolbox-canvas.d.ts +39 -22
- package/dist/morphic/typed-values.d.ts +23 -0
- package/dist/morphic/types.d.ts +219 -8
- package/dist/morphic/validate-definitions.d.ts +2 -1
- package/dist/morphic-blocks.js +5017 -2660
- package/dist/morphic-blocks.umd.cjs +48 -28
- 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'].",
|
|
@@ -160,7 +192,8 @@
|
|
|
160
192
|
"properties": {
|
|
161
193
|
"lineButtons": { "type": "boolean" },
|
|
162
194
|
"keys": { "type": "boolean" },
|
|
163
|
-
"toolbarButton": { "type": "boolean" }
|
|
195
|
+
"toolbarButton": { "type": "boolean" },
|
|
196
|
+
"values": { "type": "boolean" }
|
|
164
197
|
},
|
|
165
198
|
"additionalProperties": false
|
|
166
199
|
}
|
|
@@ -169,6 +202,22 @@
|
|
|
169
202
|
}
|
|
170
203
|
]
|
|
171
204
|
},
|
|
205
|
+
"blockSet": {
|
|
206
|
+
"description": "A list of block identifiers, or another set with blocks added at the end and removed.",
|
|
207
|
+
"oneOf": [
|
|
208
|
+
{ "type": "array", "items": { "type": "string" } },
|
|
209
|
+
{
|
|
210
|
+
"type": "object",
|
|
211
|
+
"required": ["extends"],
|
|
212
|
+
"properties": {
|
|
213
|
+
"extends": { "type": "string" },
|
|
214
|
+
"add": { "type": "array", "items": { "type": "string" } },
|
|
215
|
+
"remove": { "type": "array", "items": { "type": "string" } }
|
|
216
|
+
},
|
|
217
|
+
"additionalProperties": false
|
|
218
|
+
}
|
|
219
|
+
]
|
|
220
|
+
},
|
|
172
221
|
"preset": {
|
|
173
222
|
"type": "object",
|
|
174
223
|
"required": ["name", "toolbox", "views"],
|
|
@@ -180,6 +229,11 @@
|
|
|
180
229
|
"description": "What each view the preset shows shows, by view name.",
|
|
181
230
|
"type": "object",
|
|
182
231
|
"additionalProperties": { "type": "string" }
|
|
232
|
+
},
|
|
233
|
+
"blockSet": { "description": "The block set the toolbox shows; without it, all blocks.", "type": "string" },
|
|
234
|
+
"categories": {
|
|
235
|
+
"description": "false shows the toolbox's tiles as one list instead of under their categories. Default true.",
|
|
236
|
+
"type": "boolean"
|
|
183
237
|
}
|
|
184
238
|
},
|
|
185
239
|
"additionalProperties": false
|
|
@@ -237,6 +291,22 @@
|
|
|
237
291
|
"type": ["string", "array"],
|
|
238
292
|
"items": { "type": "string" }
|
|
239
293
|
},
|
|
294
|
+
"strict": { "type": "boolean" },
|
|
295
|
+
"repeat": {
|
|
296
|
+
"description": "Let a value slot hold any number of values, written one after the other.",
|
|
297
|
+
"type": "object",
|
|
298
|
+
"properties": {
|
|
299
|
+
"separator": {
|
|
300
|
+
"description": "What is written between two entries: one text, or a text per element name. \", \" by default.",
|
|
301
|
+
"oneOf": [
|
|
302
|
+
{ "type": "string" },
|
|
303
|
+
{ "type": "object", "additionalProperties": { "type": "string" } }
|
|
304
|
+
]
|
|
305
|
+
},
|
|
306
|
+
"count": { "description": "Entries a new block starts with (1 by default).", "type": "integer", "minimum": 0 }
|
|
307
|
+
},
|
|
308
|
+
"additionalProperties": false
|
|
309
|
+
},
|
|
240
310
|
"align": { "enum": ["left", "centre", "right"] },
|
|
241
311
|
"label": { "type": "string" },
|
|
242
312
|
"default": { "$ref": "#/$defs/emptyDefault" }
|
|
@@ -297,6 +367,29 @@
|
|
|
297
367
|
},
|
|
298
368
|
"additionalProperties": false
|
|
299
369
|
},
|
|
370
|
+
{
|
|
371
|
+
"type": "object",
|
|
372
|
+
"required": ["type", "to"],
|
|
373
|
+
"properties": {
|
|
374
|
+
"type": { "const": "reference" },
|
|
375
|
+
"to": {
|
|
376
|
+
"description": "The field whose values this field lists, as \"block.FIELD\" (e.g. \"class_define.NAME\"), or a list of them.",
|
|
377
|
+
"oneOf": [
|
|
378
|
+
{ "type": "string" },
|
|
379
|
+
{ "type": "array", "items": { "type": "string" }, "minItems": 1 }
|
|
380
|
+
]
|
|
381
|
+
},
|
|
382
|
+
"default": { "type": "string" },
|
|
383
|
+
"scope": {
|
|
384
|
+
"description": "A block identifier, or a list: only names declared inside the nearest such block around the field are listed.",
|
|
385
|
+
"oneOf": [
|
|
386
|
+
{ "type": "string" },
|
|
387
|
+
{ "type": "array", "items": { "type": "string" }, "minItems": 1 }
|
|
388
|
+
]
|
|
389
|
+
}
|
|
390
|
+
},
|
|
391
|
+
"additionalProperties": false
|
|
392
|
+
},
|
|
300
393
|
{
|
|
301
394
|
"type": "object",
|
|
302
395
|
"required": ["type"],
|
|
@@ -359,6 +452,10 @@
|
|
|
359
452
|
"output": { "$ref": "#/$defs/connectionSpec" },
|
|
360
453
|
"previousStatement": { "$ref": "#/$defs/connectionSpec" },
|
|
361
454
|
"nextStatement": { "$ref": "#/$defs/connectionSpec" },
|
|
455
|
+
"strict": {
|
|
456
|
+
"description": "Let the block go only where the place above it has a check matching its previousStatement or output check.",
|
|
457
|
+
"type": "boolean"
|
|
458
|
+
},
|
|
362
459
|
"inputsInline": { "type": "boolean" },
|
|
363
460
|
"tooltip": { "type": "string" },
|
|
364
461
|
"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, MorphicRejectedValue, MorphicValueLoadResult, MorphicValueRejection, 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, MorphicValueLoadResult, 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;
|
|
@@ -23,6 +25,8 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
23
25
|
private codeEditor?;
|
|
24
26
|
/** Views added with `addView()`, beside the ones `mount()` sets up. */
|
|
25
27
|
private readonly views;
|
|
28
|
+
/** Starts the move of a block whose grip was pressed, per codespace. */
|
|
29
|
+
private readonly codeGrabbers;
|
|
26
30
|
/** The mode of each added workspace, read when its blocks are built. */
|
|
27
31
|
private readonly viewWorkspaceElements;
|
|
28
32
|
/** Numbers added views that are not given a name. */
|
|
@@ -58,6 +62,13 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
58
62
|
/** The definitions still use the old top level `highlighting` map. */
|
|
59
63
|
private readonly formatHasHighlighting;
|
|
60
64
|
private readonly formatCategories?;
|
|
65
|
+
private readonly formatBlockSets?;
|
|
66
|
+
/** Every block set's blocks, resolved at mount. */
|
|
67
|
+
private blockSetLists;
|
|
68
|
+
/** The block set the toolbox shows; `undefined` shows the toolbox's own blocks. */
|
|
69
|
+
private activeBlockSet?;
|
|
70
|
+
/** Whether the toolbox groups its tiles under the categories; presets and show() switch it. */
|
|
71
|
+
private categoriesShown;
|
|
61
72
|
/**
|
|
62
73
|
* Build an engine from a whole definitions file plus its behaviors — the two
|
|
63
74
|
* artifacts a developer authors. `blocks` and `elementTypes` configure the
|
|
@@ -178,6 +189,12 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
178
189
|
* since lines always go to a console the host passes in.
|
|
179
190
|
*/
|
|
180
191
|
logToConsole?: boolean;
|
|
192
|
+
/**
|
|
193
|
+
* Values the program can use by name, e.g. `{ turtle, canvas }` for the
|
|
194
|
+
* host's own functions. Each name must be a JavaScript identifier;
|
|
195
|
+
* `console` has its own option.
|
|
196
|
+
*/
|
|
197
|
+
globals?: Record<string, unknown>;
|
|
181
198
|
}): MorphicRunResult;
|
|
182
199
|
/** Whether the framework's internal clipboard has a copyable to paste. */
|
|
183
200
|
hasClipboardContents(): boolean;
|
|
@@ -228,20 +245,76 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
228
245
|
private teardownToolbarBlocklyListener;
|
|
229
246
|
/**
|
|
230
247
|
* Switch what the toolbox and the views show, in the shape of a preset:
|
|
231
|
-
* `show({ toolbox: "pseudo", views: { blocks: "pseudo", code: "python" } })`.
|
|
248
|
+
* `show({ toolbox: "pseudo", blockSet: "level-2-blocks", categories: false, views: { blocks: "pseudo", code: "python" } })`.
|
|
232
249
|
* Everything left out stays as it is; showing and hiding the views'
|
|
233
250
|
* containers stays the app's job.
|
|
234
251
|
*/
|
|
235
252
|
show(shown: {
|
|
236
253
|
toolbox?: MorphicModeName;
|
|
237
254
|
views?: Record<string, string>;
|
|
255
|
+
/** The block set the toolbox shows; `null` shows all of the toolbox's blocks again. */
|
|
256
|
+
blockSet?: string | null;
|
|
257
|
+
/** Whether the toolbox groups its tiles under the categories; `false` shows one list. */
|
|
258
|
+
categories?: boolean;
|
|
238
259
|
}): void;
|
|
239
260
|
/** Moved in 0.4.0: `show()` takes its place. */
|
|
240
261
|
setModes(_modes: unknown): never;
|
|
241
262
|
generateJavaScript(): string;
|
|
263
|
+
/**
|
|
264
|
+
* The program as a code element writes it, the text a codespace showing
|
|
265
|
+
* that element has: `engine.generateText("python")`. Works without a view
|
|
266
|
+
* of that element.
|
|
267
|
+
*/
|
|
268
|
+
generateText(element: string): string;
|
|
269
|
+
/**
|
|
270
|
+
* Replace the program with the blocks that write `text` in a code element:
|
|
271
|
+
* `engine.loadText("print(1)", { element: "python" })`. The text must be
|
|
272
|
+
* valid and written with the blocks' templates; when a line fits no block,
|
|
273
|
+
* nothing changes and the result names the line. One undo brings the old
|
|
274
|
+
* program back.
|
|
275
|
+
*/
|
|
276
|
+
loadText(text: string, options: {
|
|
277
|
+
element: string;
|
|
278
|
+
}): MorphicTextLoadResult;
|
|
279
|
+
/**
|
|
280
|
+
* Put the value that `text` writes in a code element into a value slot of
|
|
281
|
+
* a block: `engine.loadValueText("x + 1", { element: "python", block, slot: "TIMES" })`.
|
|
282
|
+
* The text becomes the blocks that write it (a name, a number, an operator
|
|
283
|
+
* with its parts) and takes the place of what the slot held; one undo
|
|
284
|
+
* brings that back. When no block writes the text, a name in it is declared
|
|
285
|
+
* nowhere the slot can see, or the slot does not take the value, nothing
|
|
286
|
+
* changes and the result says which.
|
|
287
|
+
*
|
|
288
|
+
* Without `slot`, `block` is a value itself and the text takes its place:
|
|
289
|
+
* in the slot it sits in, or, when it lies loose, where it lies (no slot
|
|
290
|
+
* decides then what fits, and a name counts where nothing surrounds it).
|
|
291
|
+
*/
|
|
292
|
+
loadValueText(text: string, options: {
|
|
293
|
+
element: string;
|
|
294
|
+
block: Blockly.Block | string;
|
|
295
|
+
slot?: string;
|
|
296
|
+
}): MorphicValueLoadResult;
|
|
297
|
+
/** `loadValueText()`, or with `check` only its answer: nothing changes then. */
|
|
298
|
+
private readValueText;
|
|
299
|
+
/** Every name the program declares, as the text reader knows names: `<block>.<FIELD>=<name>`. */
|
|
300
|
+
private declaredNameKeys;
|
|
301
|
+
/**
|
|
302
|
+
* The first name in blocks read from text that nothing declares where they
|
|
303
|
+
* are meant to go: `inside` is the block whose slot takes them. Each
|
|
304
|
+
* reference is asked as its menu would be, scope included.
|
|
305
|
+
*/
|
|
306
|
+
private unknownNameIn;
|
|
242
307
|
generateJavaScriptWithMetadata(): MorphicCodeGenerationResult;
|
|
243
308
|
mountCodeEditor(container: HTMLElement, options?: MorphicCodeEditorOptions): Promise<void>;
|
|
244
309
|
private attachCodespaceDropTarget;
|
|
310
|
+
/** What a held tile shows over a codespace: the block as the view writes it, in the view's font. */
|
|
311
|
+
private tileTextLook;
|
|
312
|
+
/**
|
|
313
|
+
* Where the text of a block shows for a drop in a codespace: in the value's
|
|
314
|
+
* place, on the empty line of a body, or on a line of its own, indented
|
|
315
|
+
* like the block it goes beside.
|
|
316
|
+
*/
|
|
317
|
+
private dropPreviewPlace;
|
|
245
318
|
/** Innermost (smallest-range) block in metadata whose char range contains `charOffset`. */
|
|
246
319
|
private findInnermostBlockAtChar;
|
|
247
320
|
/**
|
|
@@ -376,9 +449,9 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
376
449
|
*/
|
|
377
450
|
private renderWorkspaceView;
|
|
378
451
|
/**
|
|
379
|
-
* Tiles
|
|
380
|
-
* add
|
|
381
|
-
* with its next copy. Returns the teardown.
|
|
452
|
+
* Tiles dragged to an added workspace show as their block there and, let
|
|
453
|
+
* go over an editable one, add it to the main workspace at the same spot;
|
|
454
|
+
* the view shows it with its next copy. Returns the teardown.
|
|
382
455
|
*/
|
|
383
456
|
private attachWorkspaceTileDrop;
|
|
384
457
|
/** Remove an added view and everything it set up. */
|
|
@@ -400,6 +473,34 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
400
473
|
* `edit.blockId`. The change event listener will trigger codespace re-sync.
|
|
401
474
|
*/
|
|
402
475
|
private applyPlaceholderEdit;
|
|
476
|
+
/**
|
|
477
|
+
* Where a value typed over a value block goes: the slot the block sits in,
|
|
478
|
+
* or, for a block that lies loose, the block's own place.
|
|
479
|
+
*/
|
|
480
|
+
private valuePlaceOf;
|
|
481
|
+
/**
|
|
482
|
+
* Take the value an input in a codespace stands for away, as dragging it
|
|
483
|
+
* out of its slot does on blocks: the slot is empty again, or shows its own
|
|
484
|
+
* default. `false` when there is nothing to take away (a slot's default is
|
|
485
|
+
* no value of the program).
|
|
486
|
+
*/
|
|
487
|
+
private removeValue;
|
|
488
|
+
/**
|
|
489
|
+
* Read a value typed in a view into its place (a slot, or where a loose
|
|
490
|
+
* value lies), as the view's element writes it. With `others`, text the
|
|
491
|
+
* view's element does not know is tried in the other code elements, in
|
|
492
|
+
* their order: blocks may show words (`Variable x`) where a person types
|
|
493
|
+
* the code they know (`x`). A value that is not taken changes nothing and
|
|
494
|
+
* goes to the app's `onValueRejected`; `false` then.
|
|
495
|
+
*/
|
|
496
|
+
private typeValue;
|
|
497
|
+
/**
|
|
498
|
+
* What a workspace view does with text typed into a field: for the one
|
|
499
|
+
* field of a block that is a whole value (in a slot or loose), read it as a
|
|
500
|
+
* value for that place, as the view's element writes it, or else as another
|
|
501
|
+
* code element does. Nothing for any other field.
|
|
502
|
+
*/
|
|
503
|
+
private typedValueTaker;
|
|
403
504
|
/**
|
|
404
505
|
* Whether a codespace grip may move the block: statement blocks
|
|
405
506
|
* (previousConnection) and value blocks (outputConnection), so the
|
|
@@ -444,6 +545,18 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
444
545
|
private registerBlocks;
|
|
445
546
|
/** Build a newly created block with this engine's definition, mode and behavior. */
|
|
446
547
|
private initManagedBlock;
|
|
548
|
+
/** Take the state saved with a block: the placeholder slots it had dealt with, and how many entries its repeating slots have. */
|
|
549
|
+
private loadBlockState;
|
|
550
|
+
/** Whether the block in a slot is the slot's placeholder default (a real block the framework put there). */
|
|
551
|
+
private isSlotDefault;
|
|
552
|
+
/** Build a block again as its view shows it now, e.g. after a repeating slot got or lost an entry. */
|
|
553
|
+
private rebuildBlock;
|
|
554
|
+
/**
|
|
555
|
+
* Give a repeating slot one entry more or less (`delta` +1 or -1). The last
|
|
556
|
+
* entry goes; a block in it is set free first, so nothing is deleted. One
|
|
557
|
+
* undo takes the change back, and other views follow like any other edit.
|
|
558
|
+
*/
|
|
559
|
+
changeRepeat(block: Blockly.Block, slotName: string, delta: number): void;
|
|
447
560
|
private validateViews;
|
|
448
561
|
private createHeadlessHost;
|
|
449
562
|
private resolveMode;
|
|
@@ -470,6 +583,10 @@ export declare class MorphicBlocks extends EventTarget {
|
|
|
470
583
|
private renderFlyoutBlocks;
|
|
471
584
|
private refreshToolbox;
|
|
472
585
|
private bindFlyoutWorkspace;
|
|
586
|
+
/** Each block with its image paths passed through the mount's `assetUrl`; as loaded without one. */
|
|
587
|
+
private resolveAssetUrls;
|
|
588
|
+
/** The blocks the toolbox shows: the active block set's, else the mount's `toolbox.blocks` (all when unset). */
|
|
589
|
+
private toolboxBlocks;
|
|
473
590
|
private resolveToolboxDefinition;
|
|
474
591
|
private createBehaviorContext;
|
|
475
592
|
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;
|
|
@@ -12,10 +12,42 @@ export interface DropIndicator {
|
|
|
12
12
|
line: number;
|
|
13
13
|
position: "above" | "below";
|
|
14
14
|
}
|
|
15
|
-
/**
|
|
16
|
-
|
|
15
|
+
/**
|
|
16
|
+
* Where the text of a block that is dragged in is shown, as it would stand
|
|
17
|
+
* after the drop: on a line of its own above or below a line, indented like
|
|
18
|
+
* `indentLine` (the first line of the block it goes beside); on the empty
|
|
19
|
+
* line of a body, which holds the body's indentation; or in a value's place.
|
|
20
|
+
*/
|
|
21
|
+
export type DropPreviewPlace = {
|
|
22
|
+
kind: "line";
|
|
23
|
+
line: number;
|
|
24
|
+
position: "above" | "below";
|
|
25
|
+
indentLine?: number;
|
|
26
|
+
} | {
|
|
27
|
+
kind: "fill";
|
|
28
|
+
line: number;
|
|
29
|
+
} | {
|
|
30
|
+
kind: "value";
|
|
31
|
+
from: number;
|
|
32
|
+
to: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* The place code is dragged away from: the lines of a block that has lines of
|
|
36
|
+
* its own (1-based, inclusive), or the characters of a value inside a line.
|
|
37
|
+
*/
|
|
38
|
+
export type DragSource = {
|
|
39
|
+
lines: {
|
|
40
|
+
from: number;
|
|
41
|
+
to: number;
|
|
42
|
+
};
|
|
43
|
+
} | {
|
|
44
|
+
range: {
|
|
45
|
+
from: number;
|
|
46
|
+
to: number;
|
|
47
|
+
};
|
|
48
|
+
};
|
|
17
49
|
export declare function getActiveGripDragSourceId(): string | undefined;
|
|
18
|
-
/**
|
|
50
|
+
/** Say which block is moved, or that none is any more. */
|
|
19
51
|
export declare function setActiveGripDragSourceId(id: string | undefined): void;
|
|
20
52
|
export declare class MorphicCodeEditor {
|
|
21
53
|
/** Use JavaScript language support; only the code editor does. */
|
|
@@ -50,6 +82,7 @@ export declare class MorphicCodeEditor {
|
|
|
50
82
|
private findPlaceholderAtPos;
|
|
51
83
|
/** DOM root of the active inline placeholder editor (input/select), if open. */
|
|
52
84
|
private placeholderEditorEl?;
|
|
85
|
+
private placeholderEditorList?;
|
|
53
86
|
private placeholderEditorScrollHandler?;
|
|
54
87
|
private placeholderEditorOutsideHandler?;
|
|
55
88
|
private closePlaceholderEditor;
|
|
@@ -59,6 +92,15 @@ export declare class MorphicCodeEditor {
|
|
|
59
92
|
* read-only; this overlay is a separate DOM element positioned via
|
|
60
93
|
* `coordsAtPos`. Closed on Enter/blur (apply), Escape (cancel), or doc
|
|
61
94
|
* change / scroll.
|
|
95
|
+
*
|
|
96
|
+
* A whole value (a number, a name) and an empty slot are typed as text:
|
|
97
|
+
* any value the view's language writes, `x + 1` as well as `42`. A value
|
|
98
|
+
* that is not taken stays in the input, marked with
|
|
99
|
+
* `morphic-value-rejected`, until it is changed or Escape closes it.
|
|
100
|
+
*
|
|
101
|
+
* An emptied input follows the blocks: Enter leaves a text empty, makes a
|
|
102
|
+
* number 0, and leaves a name as it was. Taking the value away is a second
|
|
103
|
+
* step, Backspace in the already empty input.
|
|
62
104
|
*/
|
|
63
105
|
private openPlaceholderEditor;
|
|
64
106
|
/** Called when the user's cursor line changes in the editor. */
|
|
@@ -80,7 +122,10 @@ export declare class MorphicCodeEditor {
|
|
|
80
122
|
private activeHighlight?;
|
|
81
123
|
private metadataEffect?;
|
|
82
124
|
private placeholderEffect?;
|
|
125
|
+
private repeatEffect?;
|
|
83
126
|
private dropIndicatorEffect?;
|
|
127
|
+
private dropPreviewEffect?;
|
|
128
|
+
private dragSourceEffect?;
|
|
84
129
|
private valueSlotHighlightEffect?;
|
|
85
130
|
private hoverHighlightEffect?;
|
|
86
131
|
/** Hands the code view the line ranges of the groups of blocks. */
|
|
@@ -95,6 +140,22 @@ export declare class MorphicCodeEditor {
|
|
|
95
140
|
private buildDeleteExtensions;
|
|
96
141
|
private buildGripExtensions;
|
|
97
142
|
private buildDropIndicatorExtensions;
|
|
143
|
+
/**
|
|
144
|
+
* The text of a block that is dragged in, shown where it would stand: the
|
|
145
|
+
* lines after it move down and the rest of a line moves aside, so the view
|
|
146
|
+
* reads as it would after the drop. It is a widget, not text of the
|
|
147
|
+
* program, and goes with the next change.
|
|
148
|
+
*/
|
|
149
|
+
private buildDropPreviewExtensions;
|
|
150
|
+
/**
|
|
151
|
+
* The place code is dragged away from. The lines of a block close up, with
|
|
152
|
+
* their line numbers and markers, so the code reads as it would without the
|
|
153
|
+
* block; a value inside a line fades. Both are classes on what is there
|
|
154
|
+
* (`morphic-drag-source`, `morphic-drag-source-value`), nothing is taken out
|
|
155
|
+
* of the page: the grip that is dragged has to stay in it for the drag to
|
|
156
|
+
* go on. Gone with the next change of the text.
|
|
157
|
+
*/
|
|
158
|
+
private buildDragSourceExtensions;
|
|
98
159
|
/**
|
|
99
160
|
* Highlight the char range of the value slot a dragged block would land in.
|
|
100
161
|
* Distinct from `dropIndicator` (a horizontal line above/below a line) so the
|
|
@@ -145,6 +206,17 @@ export declare class MorphicCodeEditor {
|
|
|
145
206
|
showDropIndicator(line: number, position?: "above" | "below"): void;
|
|
146
207
|
/** Hide the drop-position indicator if currently shown. */
|
|
147
208
|
hideDropIndicator(): void;
|
|
209
|
+
/** Show the text of a block that is dragged in where it would stand after the drop. */
|
|
210
|
+
showDropPreview(text: string, place: DropPreviewPlace): void;
|
|
211
|
+
/**
|
|
212
|
+
* Whether a point of the page is on the text shown by `showDropPreview()`:
|
|
213
|
+
* in the band of lines it takes up.
|
|
214
|
+
*/
|
|
215
|
+
isOnDropPreview(x: number, y: number): boolean;
|
|
216
|
+
/** Take the text shown by `showDropPreview()` away. */
|
|
217
|
+
hideDropPreview(): void;
|
|
218
|
+
/** Mark the place code is dragged away from, or take the mark away (`null`). */
|
|
219
|
+
setDragSource(source: DragSource | null): void;
|
|
148
220
|
/** Outline the char range of the value slot the drop would land in. */
|
|
149
221
|
showValueSlotHighlight(from: number, to: number): void;
|
|
150
222
|
/** Clear the value-slot highlight if currently shown. */
|