morphic-blocks 0.3.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/README.md +26 -21
- package/definitions.schema.json +147 -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 +4 -1
- package/dist/morphic/MorphicBlocks.d.ts +141 -66
- 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 +72 -4
- package/dist/morphic/check-definitions.d.ts +31 -0
- package/dist/morphic/code-editor.d.ts +22 -3
- package/dist/morphic/constants.d.ts +6 -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/resize.d.ts +7 -2
- package/dist/morphic/strict-slots.d.ts +10 -0
- package/dist/morphic/styles.d.ts +5 -0
- package/dist/morphic/template-codegen.d.ts +16 -0
- package/dist/morphic/template.d.ts +42 -1
- package/dist/morphic/text-to-blocks.d.ts +34 -0
- package/dist/morphic/toolbar.d.ts +8 -11
- package/dist/morphic/toolbox-canvas.d.ts +34 -11
- package/dist/morphic/types.d.ts +350 -67
- package/dist/morphic/validate-definitions.d.ts +4 -1
- package/dist/morphic/value-type.d.ts +13 -0
- package/dist/morphic/view-resolver.d.ts +5 -0
- package/dist/morphic-blocks.js +4432 -2511
- package/dist/morphic-blocks.umd.cjs +43 -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
|
@@ -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">;
|
|
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;
|
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;
|
|
@@ -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;
|
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;
|
|
@@ -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;
|
|
@@ -13,13 +13,54 @@ 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
|
-
|
|
25
|
+
/** `%parent.NAME`: the `NAME` field of the nearest block around this one that has it. */
|
|
26
|
+
export interface MorphicParentFieldToken {
|
|
27
|
+
kind: "parentField";
|
|
28
|
+
name: string;
|
|
29
|
+
}
|
|
30
|
+
export type MorphicTemplateToken = MorphicImageToken | MorphicTextToken | MorphicPlaceholderToken | MorphicValueTypeToken | MorphicFieldToken | MorphicParentFieldToken;
|
|
21
31
|
export declare function parseTemplate(template: string): MorphicTemplateToken[];
|
|
32
|
+
/**
|
|
33
|
+
* Whether the text on each side of a slot leaves the value in it alone. A
|
|
34
|
+
* slot between brackets or commas stands free (`len(%1)`, `max(%1, %2)`), and
|
|
35
|
+
* so does the slot of a statement after its keyword or sign (`return %1`,
|
|
36
|
+
* `if %1:`, `x = %1`). An operator or a word in front of it (`not %1`, `-%1`)
|
|
37
|
+
* or something that goes on from it (`%1.length`) binds to the value.
|
|
38
|
+
*/
|
|
39
|
+
export declare function slotSides(tokens: MorphicTemplateToken[], index: number, statement: boolean): {
|
|
40
|
+
before: boolean;
|
|
41
|
+
after: boolean;
|
|
42
|
+
};
|
|
43
|
+
/** Whether the text around a slot binds to the value in it, so a value built from others needs brackets there. */
|
|
44
|
+
export declare function slotIsExposed(tokens: MorphicTemplateToken[], index: number, statement: boolean): boolean;
|
|
45
|
+
/** The mark a field stands between where a template writes it as a text (`"%TEXT"`), else `null`. */
|
|
46
|
+
export declare function quoteAround(before: string | undefined, after: string | undefined): string | null;
|
|
47
|
+
/** A text as it is written between two marks: the mark and the backslash each get a backslash in front. */
|
|
48
|
+
export declare function escapeQuoted(text: string, mark: string): string;
|
|
49
|
+
/**
|
|
50
|
+
* Read a text written between two marks from `pos` on: where the closing
|
|
51
|
+
* mark is, and the text without its backslashes. `null` when the line ends
|
|
52
|
+
* before the mark comes.
|
|
53
|
+
*/
|
|
54
|
+
export declare function readQuoted(source: string, pos: number, mark: string): {
|
|
55
|
+
value: string;
|
|
56
|
+
end: number;
|
|
57
|
+
} | null;
|
|
22
58
|
export declare function normalizeTemplateText(text: string): string;
|
|
59
|
+
/**
|
|
60
|
+
* A name as a CSS class part. The name is kept as written (`icon-tiles`,
|
|
61
|
+
* `iconTiles`, `icon_tiles` all work), so the app's CSS uses the same name as
|
|
62
|
+
* its definitions; only characters a class cannot hold become `-`.
|
|
63
|
+
*/
|
|
23
64
|
export declare function toModeClassToken(mode: string): string;
|
|
24
65
|
/**
|
|
25
66
|
* Converts parsed template tokens into an HTML string for toolbox canvas rendering.
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import type * as Blockly from "blockly";
|
|
2
|
+
import type { MorphicBlockDefinition, MorphicCodeElementConfig } from "./types";
|
|
3
|
+
/**
|
|
4
|
+
* Text to blocks: read the text of a code element back into the blocks that
|
|
5
|
+
* write it. There is no parser per language. Each block's template is its
|
|
6
|
+
* pattern, read the way it is written: `print(%1)` is the text `print(`, a
|
|
7
|
+
* value, and `)`. Statements are read line by line, a body by its
|
|
8
|
+
* indentation, a value down to the blocks without slots.
|
|
9
|
+
*
|
|
10
|
+
* This first version reads valid text only. Where two blocks write the same
|
|
11
|
+
* text (`x = 1` creates a variable or sets one), the names declared so far
|
|
12
|
+
* decide: a reference prefers a name that exists, a declaration one that does
|
|
13
|
+
* not. Operators are read in the order the language gives their signs (see
|
|
14
|
+
* operators.ts), and brackets group whatever is in them; a sign without a
|
|
15
|
+
* rank needs brackets around its parts.
|
|
16
|
+
*/
|
|
17
|
+
type BlockState = Blockly.serialization.blocks.State;
|
|
18
|
+
/** What reading a text gives: the program's stacks, or the line that fits no block. */
|
|
19
|
+
export type MorphicTextParseResult = {
|
|
20
|
+
ok: true;
|
|
21
|
+
stacks: BlockState[];
|
|
22
|
+
blocks: number;
|
|
23
|
+
} | {
|
|
24
|
+
ok: false;
|
|
25
|
+
line: number;
|
|
26
|
+
message: string;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Read `source`, written in the code element `element`, into blocks.
|
|
30
|
+
* `settings` are the element's `code` settings: its keywords are no names,
|
|
31
|
+
* its comment sign and empty statement are read as it writes them.
|
|
32
|
+
*/
|
|
33
|
+
export declare function parseTextToBlocks(source: string, element: string, definitions: ReadonlyMap<string, MorphicBlockDefinition>, settings?: MorphicCodeElementConfig): MorphicTextParseResult;
|
|
34
|
+
export {};
|
|
@@ -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;
|
|
@@ -21,12 +21,10 @@ export declare class MorphicToolboxCanvas {
|
|
|
21
21
|
private readonly blockColors;
|
|
22
22
|
private readonly behaviors;
|
|
23
23
|
private readonly elementTypes;
|
|
24
|
-
private
|
|
24
|
+
private options;
|
|
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,16 @@ 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
|
+
/** Tiles under their categories, or one list; presets switch it. */
|
|
44
|
+
private grouped;
|
|
45
|
+
private readonly onScroll;
|
|
46
|
+
private readonly resizeObserver;
|
|
39
47
|
/** Adds a tile's block when the tile is chosen with the keyboard. */
|
|
40
48
|
private readonly onChoose?;
|
|
41
49
|
constructor(params: {
|
|
@@ -47,30 +55,45 @@ export declare class MorphicToolboxCanvas {
|
|
|
47
55
|
behaviors: MorphicBehaviorMap;
|
|
48
56
|
elementTypes?: Record<string, MorphicElementTypeEntry>;
|
|
49
57
|
mode: MorphicModeName;
|
|
50
|
-
render?: Record<string, "block" | "text">;
|
|
51
58
|
modes?: MorphicModeDefinition[];
|
|
52
59
|
/** Code element settings; their highlighting colours code shown as text. */
|
|
53
60
|
code?: Record<string, MorphicCodeElementConfig>;
|
|
54
61
|
options?: MorphicToolboxCanvasOptions;
|
|
62
|
+
/** Whether tiles are grouped under the categories. Default `true`. */
|
|
63
|
+
grouped?: boolean;
|
|
55
64
|
/** Called once with the hidden workspace used to draw block previews. */
|
|
56
65
|
onPreviewWorkspace?: (workspace: Blockly.WorkspaceSvg) => void;
|
|
57
66
|
dropTargets?: () => TileDropTarget[];
|
|
58
67
|
onChoose?: (blockType: string) => void;
|
|
59
68
|
});
|
|
60
|
-
|
|
69
|
+
/** Group the tiles under the categories (`true`) or show one list, from the next render on. */
|
|
70
|
+
setGrouped(grouped: boolean): void;
|
|
71
|
+
/** Show only these blocks (all when `undefined`) from the next render on. */
|
|
72
|
+
setBlocks(blocks: string[] | undefined): void;
|
|
73
|
+
rerender(mode: MorphicModeName): void;
|
|
61
74
|
dispose(): void;
|
|
62
75
|
/**
|
|
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
|
|
76
|
+
* Draw the tiles and publish the width of the widest block or code shown
|
|
77
|
+
* as text as `--morphic-toolbox-block-width` on the container. The layout
|
|
78
|
+
* stays the app's: one that wants every tile to fit gives the container
|
|
66
79
|
* `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
|
|
80
|
+
* lets its column grow to it (`minmax(250px, min-content)`). Only blocks and
|
|
81
|
+
* code count, neither of which wraps, so long descriptions do not widen it.
|
|
69
82
|
*/
|
|
70
83
|
private render;
|
|
71
|
-
/** Widest block
|
|
84
|
+
/** Widest block or code text on a tile in the current render, in pixels. */
|
|
72
85
|
private widestBlock;
|
|
73
86
|
private renderTiles;
|
|
87
|
+
/** Collapse or expand a category, without drawing the tiles again. */
|
|
88
|
+
private toggleCategory;
|
|
89
|
+
/** Mark the container while tiles wait above or below its visible part. */
|
|
90
|
+
private showScrollHints;
|
|
91
|
+
/**
|
|
92
|
+
* Hide the tiles of collapsed categories and tell their headings; with
|
|
93
|
+
* tabs, show only the chosen category.
|
|
94
|
+
*/
|
|
95
|
+
private showCategories;
|
|
96
|
+
private showCategoryState;
|
|
74
97
|
private createTile;
|
|
75
98
|
/**
|
|
76
99
|
* What a screen reader calls the tile: what the tile shows, in the mode's
|