morphic-blocks 0.5.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 +2 -1
- package/dist/index.d.ts +1 -1
- package/dist/morphic/MorphicBlocks.d.ts +70 -4
- package/dist/morphic/code-editor.d.ts +74 -3
- package/dist/morphic/dropdown-fields.d.ts +6 -0
- package/dist/morphic/styles.d.ts +18 -0
- package/dist/morphic/text-to-blocks.d.ts +26 -1
- package/dist/morphic/tile-drop.d.ts +160 -0
- package/dist/morphic/toolbox-canvas.d.ts +30 -21
- package/dist/morphic/typed-values.d.ts +23 -0
- package/dist/morphic/types.d.ts +69 -4
- package/dist/morphic-blocks.js +3557 -2660
- package/dist/morphic-blocks.umd.cjs +44 -39
- package/package.json +1 -1
package/dist/morphic/types.d.ts
CHANGED
|
@@ -748,6 +748,13 @@ export interface MorphicMountConfig {
|
|
|
748
748
|
* them in the app's own development mode.
|
|
749
749
|
*/
|
|
750
750
|
onWarning?: (message: string) => void;
|
|
751
|
+
/**
|
|
752
|
+
* Called when a value typed into a view is not taken (see
|
|
753
|
+
* `MorphicValueRejection`). The program is unchanged and the input stays
|
|
754
|
+
* open with the class `morphic-value-rejected`; what to tell the person
|
|
755
|
+
* is the app's to decide.
|
|
756
|
+
*/
|
|
757
|
+
onValueRejected?: (rejected: MorphicRejectedValue) => void;
|
|
751
758
|
/**
|
|
752
759
|
* Where an image the definitions name is loaded from: a template's `<img>`,
|
|
753
760
|
* an image element's path, a dropdown picture. Return its address, or
|
|
@@ -857,6 +864,12 @@ export interface MorphicPlaceholderEditTarget {
|
|
|
857
864
|
fieldType: "text" | "number" | "dropdown";
|
|
858
865
|
/** Dropdown options as `[label, value]` pairs (only when `fieldType === "dropdown"`). */
|
|
859
866
|
options?: [string, string][];
|
|
867
|
+
/**
|
|
868
|
+
* Set when the field's block is a whole value (a number, a name), in a
|
|
869
|
+
* slot or loose: its editor takes any value written as text, which then
|
|
870
|
+
* replaces the block.
|
|
871
|
+
*/
|
|
872
|
+
value?: boolean;
|
|
860
873
|
}
|
|
861
874
|
/**
|
|
862
875
|
* Range in the generated code occupied by a value slot. The codespace overlays
|
|
@@ -894,6 +907,38 @@ export type MorphicTextLoadResult = {
|
|
|
894
907
|
line: number;
|
|
895
908
|
message: string;
|
|
896
909
|
};
|
|
910
|
+
/**
|
|
911
|
+
* Why a typed value was not taken: no block writes the text (`"no-block"`),
|
|
912
|
+
* it names something nothing declares at that place (`"unknown-name"`), or
|
|
913
|
+
* the slot does not take the value (`"wrong-slot"`).
|
|
914
|
+
*/
|
|
915
|
+
export type MorphicValueRejection = "no-block" | "unknown-name" | "wrong-slot";
|
|
916
|
+
/**
|
|
917
|
+
* What `loadValueText()` returns: how many blocks the text became, or why
|
|
918
|
+
* nothing changed. `name` is the unknown name; `message` says the reason in
|
|
919
|
+
* English, for logs or as a text to start from.
|
|
920
|
+
*/
|
|
921
|
+
export type MorphicValueLoadResult = {
|
|
922
|
+
ok: true;
|
|
923
|
+
blocks: number;
|
|
924
|
+
} | {
|
|
925
|
+
ok: false;
|
|
926
|
+
reason: MorphicValueRejection;
|
|
927
|
+
name?: string;
|
|
928
|
+
message: string;
|
|
929
|
+
};
|
|
930
|
+
/** A typed value that was not taken, as `onValueRejected` gets it. */
|
|
931
|
+
export interface MorphicRejectedValue {
|
|
932
|
+
/** The view it was typed in. */
|
|
933
|
+
view: string;
|
|
934
|
+
/** The text as typed. */
|
|
935
|
+
text: string;
|
|
936
|
+
reason: MorphicValueRejection;
|
|
937
|
+
/** The name nothing declares, for `"unknown-name"`. */
|
|
938
|
+
name?: string;
|
|
939
|
+
/** The reason in English, for logs or as a text to start from. */
|
|
940
|
+
message: string;
|
|
941
|
+
}
|
|
897
942
|
/** Where the entries of a repeating slot end in generated text; text views put the slot's buttons there. */
|
|
898
943
|
export interface MorphicRepeatRange {
|
|
899
944
|
blockId: string;
|
|
@@ -939,6 +984,12 @@ export interface MorphicCodeEditorTheme {
|
|
|
939
984
|
gutterForeground?: string;
|
|
940
985
|
/** Text selection highlight colour. */
|
|
941
986
|
selectionBackground?: string;
|
|
987
|
+
/**
|
|
988
|
+
* Colour of the line that marks where dragged code would go
|
|
989
|
+
* (`morphic-drop-indicator-above` / `-below`). The app's CSS can set
|
|
990
|
+
* another look for these classes, or none.
|
|
991
|
+
*/
|
|
992
|
+
dropIndicator?: string;
|
|
942
993
|
/**
|
|
943
994
|
* A CodeMirror theme (an extension, e.g. `oneDark` from
|
|
944
995
|
* `@codemirror/theme-one-dark`) for the editor's colours. The colours above
|
|
@@ -955,6 +1006,8 @@ export interface MorphicCodespaceDeleteOptions {
|
|
|
955
1006
|
keys?: boolean;
|
|
956
1007
|
/** The toolbar button that deletes the blocks of the selected lines. */
|
|
957
1008
|
toolbarButton?: boolean;
|
|
1009
|
+
/** Backspace in the emptied input of a value: the value leaves its slot, as when it is dragged out on blocks. */
|
|
1010
|
+
values?: boolean;
|
|
958
1011
|
}
|
|
959
1012
|
/** A view added with `engine.addView()`. */
|
|
960
1013
|
export interface MorphicViewOptions {
|
|
@@ -1022,11 +1075,12 @@ export interface MorphicCodeEditorOptions {
|
|
|
1022
1075
|
deleteKeys?: boolean;
|
|
1023
1076
|
/**
|
|
1024
1077
|
* If provided, a "grip" gutter (⋮⋮) appears on the start line of every block
|
|
1025
|
-
* id for which this returns `true`.
|
|
1026
|
-
*
|
|
1027
|
-
* the host can then handle the drop (e.g. reorder).
|
|
1078
|
+
* id for which this returns `true`. A press on a grip goes to `onBlockGrab`,
|
|
1079
|
+
* and the host moves the block.
|
|
1028
1080
|
*/
|
|
1029
1081
|
canDragBlock?: (blockId: string) => boolean;
|
|
1082
|
+
/** A grip was pressed, with the mouse's main button, a finger, or a pen. */
|
|
1083
|
+
onBlockGrab?: (blockId: string, press: PointerEvent, grip: HTMLElement) => void;
|
|
1030
1084
|
/**
|
|
1031
1085
|
* Token-level syntax highlighting rules. When set, the editor installs a
|
|
1032
1086
|
* CodeMirror `ViewPlugin` that emits `Decoration.mark` ranges for keywords,
|
|
@@ -1039,7 +1093,18 @@ export interface MorphicCodeEditorOptions {
|
|
|
1039
1093
|
* write `newValue` to `edit.fieldName` on the Blockly block identified by
|
|
1040
1094
|
* `edit.blockId`. Re-codegen + re-render then refresh the codespace.
|
|
1041
1095
|
*/
|
|
1042
|
-
|
|
1096
|
+
/** `false` when the value was not taken; the editor then stays open. */
|
|
1097
|
+
onPlaceholderApply?: (edit: MorphicPlaceholderEditTarget, newValue: string) => boolean | void;
|
|
1098
|
+
/** A value typed into an empty slot; `false` when it was not taken. */
|
|
1099
|
+
onValueApply?: (slot: {
|
|
1100
|
+
parentBlockId: string;
|
|
1101
|
+
inputName: string;
|
|
1102
|
+
}, text: string) => boolean;
|
|
1103
|
+
/**
|
|
1104
|
+
* Backspace in the already empty input of a whole value: take the value
|
|
1105
|
+
* away. `false` when there was nothing to take away; the input then stays.
|
|
1106
|
+
*/
|
|
1107
|
+
onValueRemove?: (edit: MorphicPlaceholderEditTarget) => boolean | void;
|
|
1043
1108
|
/**
|
|
1044
1109
|
* Called when a plus or minus button of a repeating slot is pressed, with
|
|
1045
1110
|
* the block, the slot's name and +1 or -1. When set, the editor shows the
|