x-block-lib 0.9.27 → 0.9.29
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.
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import * as Blockly from 'blockly/core';
|
|
2
2
|
import { Type } from 'x-essential-lib';
|
|
3
3
|
import { PropertyKind } from 'x-runtime-lib';
|
|
4
|
-
import {
|
|
4
|
+
import { BindKind } from '@/core/utils/app';
|
|
5
5
|
type AppBindEntryV1Type = typeof APP_BIND_ENTRY_V1;
|
|
6
6
|
interface AppBindEntryV1 extends AppBindEntryV1Type {
|
|
7
|
-
|
|
7
|
+
kind: BindKind;
|
|
8
8
|
node: {
|
|
9
9
|
id: string;
|
|
10
10
|
key: string;
|
|
@@ -25,7 +25,7 @@ export type AppBindEntryBlockV1 = Blockly.BlockSvg & AppBindEntryV1;
|
|
|
25
25
|
declare const APP_BIND_ENTRY_V1: {
|
|
26
26
|
init: (this: AppBindEntryBlockV1) => void;
|
|
27
27
|
saveExtraState: (this: AppBindEntryBlockV1) => {
|
|
28
|
-
|
|
28
|
+
kind: BindKind;
|
|
29
29
|
node: {
|
|
30
30
|
id: string;
|
|
31
31
|
key: string;
|
|
@@ -43,12 +43,12 @@ declare const APP_BIND_ENTRY_V1: {
|
|
|
43
43
|
};
|
|
44
44
|
};
|
|
45
45
|
loadExtraState: (this: AppBindEntryBlockV1, state: any) => void;
|
|
46
|
-
|
|
46
|
+
genKindOpts_: (this: AppBindEntryBlockV1) => Blockly.MenuOption[];
|
|
47
47
|
genNodeOpts_: (this: AppBindEntryBlockV1) => Blockly.MenuOption[];
|
|
48
48
|
genPropertyOpts_: (this: AppBindEntryBlockV1) => Blockly.MenuOption[];
|
|
49
49
|
genStateOpts_: (this: AppBindEntryBlockV1) => Blockly.MenuOption[];
|
|
50
50
|
onchange: (this: AppBindEntryBlockV1, event: Blockly.Events.Abstract) => void;
|
|
51
|
-
|
|
51
|
+
onKindChange_: (this: AppBindEntryBlockV1, value: BindKind) => void;
|
|
52
52
|
onNodeChange_: (this: AppBindEntryBlockV1, value: string) => void;
|
|
53
53
|
onPropertyChange_: (this: AppBindEntryBlockV1, value: string) => void;
|
|
54
54
|
onStateChange_: (this: AppBindEntryBlockV1, value: string) => void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import * as Blockly from 'blockly/core';
|
|
2
|
-
export type
|
|
3
|
-
export declare function
|
|
4
|
-
export declare function
|
|
2
|
+
export type BindKind = 'notSet' | 'property' | 'state';
|
|
3
|
+
export declare function getAllBindKinds(): BindKind[];
|
|
4
|
+
export declare function genBindKindOpts(): Blockly.MenuOption[];
|
|
@@ -10,5 +10,6 @@ export declare function shadowOfTypesV1(types: string): Element;
|
|
|
10
10
|
export declare function shadowOfSelectCompV1(): Element;
|
|
11
11
|
export declare function shadowOfSelectSlotV1(): Element;
|
|
12
12
|
export declare function shadowOfColorPickerV1(value: string): Element;
|
|
13
|
+
export declare function shadowOfAppBindEntryV1(): Element;
|
|
13
14
|
export declare function genTypeShadowV1(type: Type): Element | null;
|
|
14
15
|
export declare function genPropShadowV1(property: ZProperty): Element | null;
|
package/dist/index.js
CHANGED
|
@@ -163,6 +163,9 @@ function shadowOfColorPickerV1(e) {
|
|
|
163
163
|
let y = `<shadow type="color_picker_v1"><field name="COLOR">${e}</field></shadow>`;
|
|
164
164
|
return utils.xml.textToDom(y);
|
|
165
165
|
}
|
|
166
|
+
function shadowOfAppBindEntryV1() {
|
|
167
|
+
return utils.xml.textToDom("\n<shadow type=\"app_bind_entry_v1\">\n <field name=\"KIND\">notSet</field>\n</shadow>");
|
|
168
|
+
}
|
|
166
169
|
function genTypeShadowV1(e) {
|
|
167
170
|
let y = null;
|
|
168
171
|
return e === "string" ? y = shadowOfTextV1("") : e === "number" ? y = shadowOfMathNumberV1(0) : e === "boolean" ? y = shadowOfLogicBooleanV1(!1) : e === "array" ? y = shadowOfListCreateV1() : e === "object" ? y = shadowOfObjectCreateV1() : e === "any" ? y = null : console.assert(!1), y;
|
|
@@ -644,12 +647,13 @@ function genStateOpts() {
|
|
|
644
647
|
for (let { id: b, name: x } of y) e.push([x, b]);
|
|
645
648
|
return ensureOpts(e);
|
|
646
649
|
}
|
|
647
|
-
function
|
|
648
|
-
let e = [];
|
|
650
|
+
function getAllBindKinds() {
|
|
651
|
+
let e = ["notSet"];
|
|
649
652
|
return getAllNodeInfos("setProperty").length > 0 && e.push("property"), getAllStateInfos().length > 0 && e.push("state"), e;
|
|
650
653
|
}
|
|
651
|
-
function
|
|
652
|
-
|
|
654
|
+
function genBindKindOpts() {
|
|
655
|
+
let { i18n: e } = globalObjects;
|
|
656
|
+
return ensureOpts(getAllBindKinds().map((y) => y === "notSet" ? [e.global.t(`x-runtime-lib.${y}`), y] : [localeMsg(`APP_${upperCase_default(y)}`), y]));
|
|
653
657
|
}
|
|
654
658
|
function getAllCompInfos() {
|
|
655
659
|
let { activeApp: e } = globalState.app, y = [{
|
|
@@ -1907,50 +1911,6 @@ function genSlotOpts_() {
|
|
|
1907
1911
|
}
|
|
1908
1912
|
return ensureOpts(y);
|
|
1909
1913
|
}
|
|
1910
|
-
function ensureBindEntryBlocks(e) {
|
|
1911
|
-
if (!(getAllBindTypes().length <= 0)) for (let y = 0; e.getInput("ADD" + y); y++) {
|
|
1912
|
-
let b = e.getInput("ADD" + y).connection;
|
|
1913
|
-
b.targetBlock() || ensureBindEntryBlock(b, e.workspace);
|
|
1914
|
-
}
|
|
1915
|
-
}
|
|
1916
|
-
function ensureBindEntryBlock(e, y) {
|
|
1917
|
-
let b = {
|
|
1918
|
-
bindType: "",
|
|
1919
|
-
node: {
|
|
1920
|
-
id: "",
|
|
1921
|
-
key: "",
|
|
1922
|
-
alias: ""
|
|
1923
|
-
},
|
|
1924
|
-
property: {
|
|
1925
|
-
id: "",
|
|
1926
|
-
kind: "",
|
|
1927
|
-
names: []
|
|
1928
|
-
},
|
|
1929
|
-
state: {
|
|
1930
|
-
id: "",
|
|
1931
|
-
name: "",
|
|
1932
|
-
type: "string"
|
|
1933
|
-
}
|
|
1934
|
-
}, x = {}, S = getAllBindTypes()?.[0];
|
|
1935
|
-
if (!S) return;
|
|
1936
|
-
if (b.bindType = S, x.BIND_TYPE = S, b.bindType === "property") {
|
|
1937
|
-
let e = getAllNodeInfos("setProperty")?.[0];
|
|
1938
|
-
if (e) {
|
|
1939
|
-
b.node.id = e.id, b.node.key = e.key, b.node.alias = e.alias, x.NODE = e.id;
|
|
1940
|
-
let y = getAllPropertyInfos(e.id, "write")?.[0];
|
|
1941
|
-
y && (b.property.id = y.id, b.property.kind = y.kind, b.property.names = y.names, x.PROPERTY = y.id);
|
|
1942
|
-
}
|
|
1943
|
-
} else if (b.bindType === "state") {
|
|
1944
|
-
let e = getAllStateInfos()?.[0];
|
|
1945
|
-
e && (b.state.id = e.id, b.state.name = e.name, b.state.type = e.type, x.STATE = e.id);
|
|
1946
|
-
}
|
|
1947
|
-
let C = {
|
|
1948
|
-
type: "app_bind_entry_v1",
|
|
1949
|
-
extraState: b,
|
|
1950
|
-
fields: x
|
|
1951
|
-
}, w = serialization.blocks.append(C, y);
|
|
1952
|
-
e.connect(w.outputConnection);
|
|
1953
|
-
}
|
|
1954
1914
|
var xmlUtils$11 = utils.xml;
|
|
1955
1915
|
Blocks.app_bind_container_v1 = { init: function() {
|
|
1956
1916
|
this.appendDummyInput().appendField("%{BKY_APP_V1_APP_BIND_CONTAINER_TITLE}"), this.appendStatementInput("STACK"), this.setStyle("event_blocks"), this.contextMenu = !1;
|
|
@@ -1968,16 +1928,16 @@ Blocks.app_bind_container_v1 = { init: function() {
|
|
|
1968
1928
|
},
|
|
1969
1929
|
domToMutation: function(e) {
|
|
1970
1930
|
let y = e.getAttribute("items") ?? "";
|
|
1971
|
-
this.itemCount_ = parseInt(y, 0), this.updateShape_(), setTimeout(() => {
|
|
1972
|
-
this.
|
|
1931
|
+
this.itemCount_ = parseInt(y, 0), this.updateShape_(), this.updateShadow_(), setTimeout(() => {
|
|
1932
|
+
this.checkWarning_();
|
|
1973
1933
|
}, 0);
|
|
1974
1934
|
},
|
|
1975
1935
|
saveExtraState: function() {
|
|
1976
1936
|
return { itemCount: this.itemCount_ };
|
|
1977
1937
|
},
|
|
1978
1938
|
loadExtraState: function(e) {
|
|
1979
|
-
this.itemCount_ = e.itemCount ?? 0, this.updateShape_(), setTimeout(() => {
|
|
1980
|
-
this.
|
|
1939
|
+
this.itemCount_ = e.itemCount ?? 0, this.updateShape_(), this.updateShadow_(), setTimeout(() => {
|
|
1940
|
+
this.checkWarning_();
|
|
1981
1941
|
}, 0);
|
|
1982
1942
|
},
|
|
1983
1943
|
decompose: function(e) {
|
|
@@ -2003,10 +1963,10 @@ Blocks.app_bind_container_v1 = { init: function() {
|
|
|
2003
1963
|
let y = this.getInput("ADD" + e).connection.targetConnection;
|
|
2004
1964
|
y && !b.includes(y) && y.disconnect();
|
|
2005
1965
|
}
|
|
2006
|
-
this.itemCount_ = b.length, this.updateShape_();
|
|
1966
|
+
this.itemCount_ = b.length, this.updateShape_(), this.updateShadow_();
|
|
2007
1967
|
for (let e = 0; e < this.itemCount_; e++) b[e]?.reconnect(this, "ADD" + e);
|
|
2008
1968
|
setTimeout(() => {
|
|
2009
|
-
this.
|
|
1969
|
+
this.checkWarning_();
|
|
2010
1970
|
}, 0);
|
|
2011
1971
|
},
|
|
2012
1972
|
saveConnections: function(e) {
|
|
@@ -2028,8 +1988,8 @@ Blocks.app_bind_container_v1 = { init: function() {
|
|
|
2028
1988
|
for (let e = 0; e < this.itemCount_; e++) this.getInput("ADD" + e) || (this.appendValueInput("ADD" + e).setCheck("BindEntry"), e === 0 && this.getInput("ADD" + e).setAlign(inputs.Align.RIGHT).appendField("%{BKY_APP_V1_APP_BIND_TITLE}"));
|
|
2029
1989
|
for (let e = this.itemCount_; this.getInput("ADD" + e); e++) this.removeInput("ADD" + e);
|
|
2030
1990
|
},
|
|
2031
|
-
|
|
2032
|
-
this.isInsertionMarker()
|
|
1991
|
+
updateShadow_: function() {
|
|
1992
|
+
if (!this.isInsertionMarker()) for (let e = 0; e < this.itemCount_; e++) this.getInput("ADD" + e).setCheck("BindEntry").setShadowDom(shadowOfAppBindEntryV1());
|
|
2033
1993
|
},
|
|
2034
1994
|
checkWarning_: function() {
|
|
2035
1995
|
let e;
|
|
@@ -2037,10 +1997,10 @@ Blocks.app_bind_container_v1 = { init: function() {
|
|
|
2037
1997
|
let b = this.getInput("ADD" + y)?.connection?.targetBlock();
|
|
2038
1998
|
if (!b) continue;
|
|
2039
1999
|
let x;
|
|
2040
|
-
if (b.
|
|
2000
|
+
if (b.kind === "property") {
|
|
2041
2001
|
let e = getPropertyInfo(b.property.id);
|
|
2042
2002
|
e && (x = e.meta.element ? getPropCheck(e.meta.raw) : getTypeCheck(e.meta.raw.type));
|
|
2043
|
-
} else if (b.
|
|
2003
|
+
} else if (b.kind === "state") {
|
|
2044
2004
|
let e = getStateInfo(b.state.id);
|
|
2045
2005
|
e && (x = getTypeCheck(e.type));
|
|
2046
2006
|
}
|
|
@@ -2055,7 +2015,7 @@ Blocks.app_bind_container_v1 = { init: function() {
|
|
|
2055
2015
|
return "";
|
|
2056
2016
|
}, Blocks.app_bind_entry_v1 = {
|
|
2057
2017
|
init: function() {
|
|
2058
|
-
this.
|
|
2018
|
+
this.kind = "notSet", this.node = {
|
|
2059
2019
|
id: "",
|
|
2060
2020
|
key: "",
|
|
2061
2021
|
alias: ""
|
|
@@ -2067,52 +2027,53 @@ Blocks.app_bind_container_v1 = { init: function() {
|
|
|
2067
2027
|
id: "",
|
|
2068
2028
|
name: "",
|
|
2069
2029
|
type: "string"
|
|
2070
|
-
}, this.appendDummyInput().appendField(new FieldDropdown(() => this.
|
|
2030
|
+
}, this.appendDummyInput().appendField(new FieldDropdown(() => this.genKindOpts_()), "KIND").appendField(new FieldDropdown(() => this.genNodeOpts_()), "NODE").appendField(new FieldDropdown(() => this.genPropertyOpts_()), "PROPERTY").appendField(new FieldDropdown(() => this.genStateOpts_()), "STATE"), this.setOutput(!0, "BindEntry"), this.updateShape_();
|
|
2071
2031
|
},
|
|
2072
2032
|
saveExtraState: function() {
|
|
2073
2033
|
return {
|
|
2074
|
-
|
|
2034
|
+
kind: this.kind,
|
|
2075
2035
|
node: this.node,
|
|
2076
2036
|
property: this.property,
|
|
2077
2037
|
state: this.state
|
|
2078
2038
|
};
|
|
2079
2039
|
},
|
|
2080
2040
|
loadExtraState: function(e) {
|
|
2081
|
-
this.
|
|
2041
|
+
this.kind = e.kind ?? "notSet", this.node.id = e.node?.id ?? "", this.node.key = e.node?.key ?? "", this.node.alias = e.node?.alias ?? "", this.property.id = e.property?.id ?? "", this.property.kind = e.property?.kind ?? "", this.property.names = e.property?.names ?? [], this.state.id = e.state?.id ?? "", this.state.name = e.state?.name ?? "", this.state.type = e.state?.type ?? "string", this.updateShape_(), setTimeout(() => {
|
|
2082
2042
|
this.checkWarning_();
|
|
2083
2043
|
}, 0);
|
|
2084
2044
|
},
|
|
2085
|
-
|
|
2086
|
-
return
|
|
2045
|
+
genKindOpts_: function() {
|
|
2046
|
+
return genBindKindOpts();
|
|
2087
2047
|
},
|
|
2088
2048
|
genNodeOpts_: function() {
|
|
2089
|
-
return this.
|
|
2049
|
+
return this.kind === "property" ? genNodeOpts("setProperty") : ensureOpts([]);
|
|
2090
2050
|
},
|
|
2091
2051
|
genPropertyOpts_: function() {
|
|
2092
|
-
return this.
|
|
2052
|
+
return this.kind === "property" ? genPropertyOpts(this.node.id, "write") : ensureOpts([]);
|
|
2093
2053
|
},
|
|
2094
2054
|
genStateOpts_: function() {
|
|
2095
|
-
return this.
|
|
2055
|
+
return this.kind === "state" ? genStateOpts() : ensureOpts([]);
|
|
2096
2056
|
},
|
|
2097
2057
|
onchange: function(e) {
|
|
2098
2058
|
if (e.type === CustomEventType.STATE_CHANGE) this.checkWarning_();
|
|
2099
2059
|
else if (e.type === Events.BLOCK_CHANGE) {
|
|
2100
2060
|
let y = e;
|
|
2101
|
-
y.blockId === this.id && (y.element === "field" && (y.name === "
|
|
2061
|
+
y.blockId === this.id && (y.element === "field" && (y.name === "KIND" ? this.onKindChange_(y.newValue) : y.name === "NODE" ? this.onNodeChange_(y.newValue) : y.name === "PROPERTY" ? this.onPropertyChange_(y.newValue) : y.name === "STATE" && this.onStateChange_(y.newValue)), setTimeout(() => {
|
|
2102
2062
|
this.checkWarning_();
|
|
2103
2063
|
}));
|
|
2104
2064
|
}
|
|
2105
2065
|
},
|
|
2106
|
-
|
|
2107
|
-
let y = this.
|
|
2108
|
-
if (this.
|
|
2066
|
+
onKindChange_: function(e) {
|
|
2067
|
+
let y = this.kind !== e;
|
|
2068
|
+
if (this.kind = e, this.kind === "notSet") this.updateShape_();
|
|
2069
|
+
else if (this.kind === "property") {
|
|
2109
2070
|
let e = this.getField("NODE");
|
|
2110
2071
|
if (e.getOptions(!1), y || !getNodeInfo(this.node.id)) {
|
|
2111
2072
|
let y = getAllNodeInfos("setProperty")?.[0];
|
|
2112
2073
|
e.setValue(y?.id ?? "");
|
|
2113
2074
|
}
|
|
2114
2075
|
this.onNodeChange_(e.getValue());
|
|
2115
|
-
} else if (this.
|
|
2076
|
+
} else if (this.kind === "state") {
|
|
2116
2077
|
let e = this.getField("STATE");
|
|
2117
2078
|
if (e.getOptions(!1), y || !getStateInfo(this.state.id)) {
|
|
2118
2079
|
let y = getAllStateInfos()?.[0];
|
|
@@ -2153,13 +2114,12 @@ Blocks.app_bind_container_v1 = { init: function() {
|
|
|
2153
2114
|
this.state.id = y.id, this.state.name = y.name, this.state.type = y.type, this.updateShape_();
|
|
2154
2115
|
},
|
|
2155
2116
|
updateShape_: function() {
|
|
2156
|
-
|
|
2157
|
-
e === "property" ? (this.setStyle("property_blocks"), this.getField("NODE").setVisible(!0), this.getField("PROPERTY").setVisible(!0), this.getField("STATE").setVisible(!1)) : e === "state" && (this.setStyle("state_blocks"), this.getField("NODE").setVisible(!1), this.getField("PROPERTY").setVisible(!1), this.getField("STATE").setVisible(!0)), setTimeout(() => {
|
|
2117
|
+
this.kind === "notSet" ? (this.setStyle("event_blocks"), this.getField("NODE").setVisible(!1), this.getField("PROPERTY").setVisible(!1), this.getField("STATE").setVisible(!1)) : this.kind === "property" ? (this.setStyle("property_blocks"), this.getField("NODE").setVisible(!0), this.getField("PROPERTY").setVisible(!0), this.getField("STATE").setVisible(!1)) : this.kind === "state" && (this.setStyle("state_blocks"), this.getField("NODE").setVisible(!1), this.getField("PROPERTY").setVisible(!1), this.getField("STATE").setVisible(!0)), setTimeout(() => {
|
|
2158
2118
|
this.render();
|
|
2159
2119
|
}, 0);
|
|
2160
2120
|
},
|
|
2161
2121
|
checkWarning_: function() {
|
|
2162
|
-
if (this.
|
|
2122
|
+
if (this.kind === "property") {
|
|
2163
2123
|
let e = getNodeInfo(this.node.id);
|
|
2164
2124
|
if (!e) {
|
|
2165
2125
|
this.setWarningText(localeMsg("WARN_NODE_NOT_FOUND"));
|
|
@@ -2180,7 +2140,7 @@ Blocks.app_bind_container_v1 = { init: function() {
|
|
|
2180
2140
|
return;
|
|
2181
2141
|
}
|
|
2182
2142
|
isEqual_default(y.names, this.property.names) || (this.property.names = y.names);
|
|
2183
|
-
} else if (this.
|
|
2143
|
+
} else if (this.kind === "state") {
|
|
2184
2144
|
let e = getStateInfo(this.state.id);
|
|
2185
2145
|
if (!e) {
|
|
2186
2146
|
this.setWarningText(localeMsg("WARN_STATE_NOT_FOUND"));
|
|
@@ -8689,7 +8649,7 @@ function makeAppBindBlocks(e) {
|
|
|
8689
8649
|
for (let b of e) {
|
|
8690
8650
|
if (b.type !== "app_bind_entry_v1") continue;
|
|
8691
8651
|
let e = b;
|
|
8692
|
-
e.
|
|
8652
|
+
e.kind === "property" ? addUnique(y, makeTriggerId("propertyTrigger", e.property.id)) : e.kind === "state" && addUnique(y, makeTriggerId("stateTrigger", e.state.id));
|
|
8693
8653
|
}
|
|
8694
8654
|
return y;
|
|
8695
8655
|
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "x-block-lib",
|
|
3
3
|
"private": false,
|
|
4
|
-
"version": "0.9.
|
|
4
|
+
"version": "0.9.29",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"module": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"peerDependencies": {
|
|
43
43
|
"x-essential-lib": "^0.9.24",
|
|
44
|
-
"x-runtime-lib": "^0.8.
|
|
44
|
+
"x-runtime-lib": "^0.8.203",
|
|
45
45
|
"x-state-lib": "^0.3.38"
|
|
46
46
|
},
|
|
47
47
|
"devDependencies": {
|