@babylonjs/shared-ui-components 7.53.3 → 7.54.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/nodeGraphSystem/frameNodePort.js +2 -2
- package/nodeGraphSystem/frameNodePort.js.map +1 -1
- package/nodeGraphSystem/graphCanvas.js +2 -2
- package/nodeGraphSystem/graphCanvas.js.map +1 -1
- package/nodeGraphSystem/graphNode.d.ts +1 -0
- package/nodeGraphSystem/graphNode.js +4 -4
- package/nodeGraphSystem/graphNode.js.map +1 -1
- package/nodeGraphSystem/graphNode.module.scss +11 -2
- package/nodeGraphSystem/nodePort.d.ts +1 -1
- package/nodeGraphSystem/nodePort.js +14 -5
- package/nodeGraphSystem/nodePort.js.map +1 -1
- package/nodeGraphSystem/nodePort.module.scss +7 -2
- package/nodeGraphSystem/stateManager.d.ts +1 -1
- package/nodeGraphSystem/stateManager.js.map +1 -1
- package/nodeGraphSystem/tools.d.ts +11 -1
- package/nodeGraphSystem/tools.js +42 -1
- package/nodeGraphSystem/tools.js.map +1 -1
- package/package.json +1 -1
@@ -4,4 +4,14 @@ import type { NodeLink } from "./nodeLink";
|
|
4
4
|
import type { FramePortData } from "./types/framePortData";
|
5
5
|
export declare const IsFramePortData: (variableToCheck: any) => variableToCheck is FramePortData;
|
6
6
|
export declare const RefreshNode: (node: GraphNode, visitedNodes?: Set<GraphNode>, visitedLinks?: Set<NodeLink>, canvas?: GraphCanvasComponent) => void;
|
7
|
-
export declare const BuildFloatUI: (container: HTMLDivElement, document: Document, displayName: string, isInteger: boolean, source: any, propertyName: string, onChange: () => void, min?: number, max?: number, visualPropertiesRefresh?: Array<() => void
|
7
|
+
export declare const BuildFloatUI: (container: HTMLDivElement, document: Document, displayName: string, isInteger: boolean, source: any, propertyName: string, onChange: () => void, min?: number, max?: number, visualPropertiesRefresh?: Array<() => void>, additionalClassName?: string) => void;
|
8
|
+
export declare function GetListOfAcceptedTypes<T extends Record<string, string | number>>(types: T, allValue: number, autoDetectValue: number, port: {
|
9
|
+
acceptedConnectionPointTypes: number[];
|
10
|
+
excludedConnectionPointTypes: number[];
|
11
|
+
type: number;
|
12
|
+
}, skips?: number[]): string[];
|
13
|
+
export declare function GetConnectionErrorMessage<T extends Record<string, string | number>>(sourceType: number, types: T, allValue: number, autoDetectValue: number, port: {
|
14
|
+
acceptedConnectionPointTypes: number[];
|
15
|
+
excludedConnectionPointTypes: number[];
|
16
|
+
type: number;
|
17
|
+
}, skips?: number[]): string;
|
package/nodeGraphSystem/tools.js
CHANGED
@@ -49,13 +49,16 @@ export const RefreshNode = (node, visitedNodes, visitedLinks, canvas) => {
|
|
49
49
|
});
|
50
50
|
};
|
51
51
|
let idGenerator = 0;
|
52
|
-
export const BuildFloatUI = (container, document, displayName, isInteger, source, propertyName, onChange, min, max, visualPropertiesRefresh) => {
|
52
|
+
export const BuildFloatUI = (container, document, displayName, isInteger, source, propertyName, onChange, min, max, visualPropertiesRefresh, additionalClassName) => {
|
53
53
|
const cantDisplaySlider = min === undefined || max === undefined || isNaN(min) || isNaN(max) || min === max;
|
54
54
|
if (cantDisplaySlider) {
|
55
55
|
container.classList.add(localStyles.floatContainer);
|
56
56
|
const numberInput = document.createElement("input");
|
57
57
|
numberInput.type = "number";
|
58
58
|
numberInput.id = `number-${idGenerator++}`;
|
59
|
+
if (additionalClassName) {
|
60
|
+
numberInput.classList.add(additionalClassName);
|
61
|
+
}
|
59
62
|
if (visualPropertiesRefresh) {
|
60
63
|
visualPropertiesRefresh.push(() => {
|
61
64
|
numberInput.value = source[propertyName];
|
@@ -74,6 +77,9 @@ export const BuildFloatUI = (container, document, displayName, isInteger, source
|
|
74
77
|
container.appendChild(numberInput);
|
75
78
|
const label = document.createElement("div");
|
76
79
|
label.innerText = displayName;
|
80
|
+
if (additionalClassName) {
|
81
|
+
label.classList.add(additionalClassName);
|
82
|
+
}
|
77
83
|
container.appendChild(label);
|
78
84
|
let shouldCapture = false;
|
79
85
|
numberInput.onpointerdown = (evt) => {
|
@@ -136,4 +142,39 @@ export const BuildFloatUI = (container, document, displayName, isInteger, source
|
|
136
142
|
};
|
137
143
|
}
|
138
144
|
};
|
145
|
+
export function GetListOfAcceptedTypes(types, allValue, autoDetectValue, port, skips = []) {
|
146
|
+
let acceptedTypes = [];
|
147
|
+
if (port.type !== autoDetectValue) {
|
148
|
+
acceptedTypes = [types[port.type]];
|
149
|
+
}
|
150
|
+
if (port.acceptedConnectionPointTypes.length !== 0) {
|
151
|
+
acceptedTypes = port.acceptedConnectionPointTypes.filter((t) => t && t !== port.type).map((t) => types[t]);
|
152
|
+
}
|
153
|
+
if (skips.indexOf(autoDetectValue) === -1) {
|
154
|
+
skips.push(autoDetectValue);
|
155
|
+
}
|
156
|
+
if (port.excludedConnectionPointTypes.length !== 0) {
|
157
|
+
let bitmask = 0;
|
158
|
+
let val = 2 ** bitmask;
|
159
|
+
const candidates = [];
|
160
|
+
while (val < allValue) {
|
161
|
+
if (port.excludedConnectionPointTypes.indexOf(val) === -1 && skips.indexOf(val) === -1) {
|
162
|
+
if (candidates.indexOf(val) === -1) {
|
163
|
+
candidates.push(val);
|
164
|
+
}
|
165
|
+
}
|
166
|
+
bitmask++;
|
167
|
+
val = 2 ** bitmask;
|
168
|
+
}
|
169
|
+
acceptedTypes = Object.values(types)
|
170
|
+
.filter((t) => candidates.indexOf(t) !== -1 && t !== port.type)
|
171
|
+
.map((t) => types[t])
|
172
|
+
.filter((t) => t);
|
173
|
+
}
|
174
|
+
return acceptedTypes;
|
175
|
+
}
|
176
|
+
export function GetConnectionErrorMessage(sourceType, types, allValue, autoDetectValue, port, skips = []) {
|
177
|
+
const list = GetListOfAcceptedTypes(types, allValue, autoDetectValue, port, skips).join(", ");
|
178
|
+
return `Cannot connect two different connection types:\nSource is ${types[sourceType]} but destination only accepts ${list}`;
|
179
|
+
}
|
139
180
|
//# sourceMappingURL=tools.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"tools.js","sourceRoot":"","s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M,CAAC,YAAY,CAAC,CAAC;YACvC,QAAQ,EAAE,CAAC;QACf,CAAC,CAAC;IACN,CAAC;AACL,CAAC,CAAC","sourcesContent":["import type { GraphCanvasComponent } from \"./graphCanvas\";\r\nimport type { GraphNode } from \"./graphNode\";\r\nimport type { NodeLink } from \"./nodeLink\";\r\nimport type { FramePortData } from \"./types/framePortData\";\r\nimport * as localStyles from \"./graphNode.module.scss\";\r\n\r\nexport const IsFramePortData = (variableToCheck: any): variableToCheck is FramePortData => {\r\n if (variableToCheck) {\r\n return (variableToCheck as FramePortData).port !== undefined;\r\n } else {\r\n return false;\r\n }\r\n};\r\n\r\nexport const RefreshNode = (node: GraphNode, visitedNodes?: Set<GraphNode>, visitedLinks?: Set<NodeLink>, canvas?: GraphCanvasComponent) => {\r\n node.refresh();\r\n\r\n const links = node.links;\r\n\r\n if (visitedNodes) {\r\n // refresh first the nodes so that the right types are assigned to the auto-detect ports\r\n links.forEach((link) => {\r\n const nodeA = link.nodeA,\r\n nodeB = link.nodeB;\r\n\r\n if (!visitedNodes.has(nodeA)) {\r\n visitedNodes.add(nodeA);\r\n RefreshNode(nodeA, visitedNodes, visitedLinks);\r\n }\r\n\r\n if (nodeB && !visitedNodes.has(nodeB)) {\r\n visitedNodes.add(nodeB);\r\n RefreshNode(nodeB, visitedNodes, visitedLinks);\r\n }\r\n });\r\n }\r\n\r\n // Invisible endpoints (for teleport nodes)\r\n const invisibleEndpoints = node.content.invisibleEndpoints;\r\n if (invisibleEndpoints && invisibleEndpoints.length) {\r\n for (const endpoint of invisibleEndpoints) {\r\n const graphNode = canvas?.findNodeFromData(endpoint);\r\n if (graphNode) {\r\n if (visitedNodes) {\r\n visitedNodes.add(graphNode);\r\n }\r\n RefreshNode(graphNode, visitedNodes, visitedLinks);\r\n }\r\n }\r\n }\r\n\r\n if (!visitedLinks) {\r\n return;\r\n }\r\n\r\n // then refresh the links to display the right color between ports\r\n links.forEach((link) => {\r\n if (!visitedLinks.has(link)) {\r\n visitedLinks.add(link);\r\n link.update();\r\n }\r\n });\r\n};\r\n\r\nlet idGenerator = 0;\r\nexport const BuildFloatUI = (\r\n container: HTMLDivElement,\r\n document: Document,\r\n displayName: string,\r\n isInteger: boolean,\r\n source: any,\r\n propertyName: string,\r\n onChange: () => void,\r\n min?: number,\r\n max?: number,\r\n visualPropertiesRefresh?: Array<() => void>\r\n) => {\r\n const cantDisplaySlider = min === undefined || max === undefined || isNaN(min) || isNaN(max) || min === max;\r\n if (cantDisplaySlider) {\r\n container.classList.add(localStyles.floatContainer);\r\n const numberInput = document.createElement(\"input\");\r\n numberInput.type = \"number\";\r\n numberInput.id = `number-${idGenerator++}`;\r\n\r\n if (visualPropertiesRefresh) {\r\n visualPropertiesRefresh.push(() => {\r\n numberInput.value = source[propertyName];\r\n });\r\n } else {\r\n numberInput.value = source[propertyName];\r\n }\r\n numberInput.onchange = () => {\r\n source[propertyName] = parseFloat(numberInput.value);\r\n onChange();\r\n };\r\n\r\n if (isInteger) {\r\n numberInput.step = \"1\";\r\n }\r\n\r\n container.appendChild(numberInput);\r\n const label = document.createElement(\"div\");\r\n label.innerText = displayName;\r\n container.appendChild(label);\r\n\r\n let shouldCapture = false;\r\n numberInput.onpointerdown = (evt) => {\r\n shouldCapture = true;\r\n evt.preventDefault();\r\n };\r\n numberInput.onpointerup = (evt) => {\r\n if (numberInput.hasPointerCapture(evt.pointerId)) {\r\n numberInput.releasePointerCapture(evt.pointerId);\r\n shouldCapture = false;\r\n evt.preventDefault();\r\n } else {\r\n numberInput.focus();\r\n numberInput.select();\r\n }\r\n };\r\n numberInput.onpointermove = (evt) => {\r\n if (shouldCapture) {\r\n numberInput.setPointerCapture(evt.pointerId);\r\n }\r\n\r\n if (numberInput.hasPointerCapture(evt.pointerId)) {\r\n const delta = isInteger ? Math.sign(evt.movementX) : evt.movementX * 0.01;\r\n numberInput.value = (parseFloat(numberInput.value) + delta).toFixed(isInteger ? 0 : 2);\r\n\r\n source[propertyName] = isInteger ? parseInt(numberInput.value) : parseFloat(numberInput.value);\r\n onChange();\r\n evt.preventDefault();\r\n }\r\n };\r\n } else {\r\n container.classList.add(localStyles.sliderContainer);\r\n const label = document.createElement(\"label\");\r\n container.appendChild(label);\r\n const value = document.createElement(\"div\");\r\n container.appendChild(value);\r\n const slider = document.createElement(\"input\");\r\n slider.type = \"range\";\r\n slider.id = `slider-${idGenerator++}`;\r\n slider.step = isInteger ? \"1\" : (Math.abs(max - min) / 100.0).toString();\r\n slider.min = min.toString();\r\n slider.max = max.toString();\r\n container.appendChild(slider);\r\n label.innerText = displayName;\r\n label.htmlFor = slider.id;\r\n if (visualPropertiesRefresh) {\r\n visualPropertiesRefresh.push(() => {\r\n slider.value = source[propertyName];\r\n value.innerText = source[propertyName];\r\n });\r\n } else {\r\n slider.value = source[propertyName];\r\n value.innerText = source[propertyName];\r\n }\r\n slider.oninput = () => {\r\n source[propertyName] = parseFloat(slider.value);\r\n value.innerText = source[propertyName];\r\n onChange();\r\n };\r\n }\r\n};\r\n"]}
|
1
|
+
{"version":3,"file":"tools.js","sourceRoot":"","sources":["../../../../dev/sharedUiComponents/src/nodeGraphSystem/tools.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,WAAW,MAAM,yBAAyB,CAAC;AAEvD,MAAM,CAAC,MAAM,eAAe,GAAG,CAAC,eAAoB,EAAoC,EAAE;IACtF,IAAI,eAAe,EAAE,CAAC;QAClB,OAAQ,eAAiC,CAAC,IAAI,KAAK,SAAS,CAAC;IACjE,CAAC;SAAM,CAAC;QACJ,OAAO,KAAK,CAAC;IACjB,CAAC;AACL,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,IAAe,EAAE,YAA6B,EAAE,YAA4B,EAAE,MAA6B,EAAE,EAAE;IACvI,IAAI,CAAC,OAAO,EAAE,CAAC;IAEf,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC;IAEzB,IAAI,YAAY,EAAE,CAAC;QACf,wFAAwF;QACxF,KAAK,CAA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C,IAAI,CAAC,KAAK,IAAI,CAAC,IAAI,CAAC;aACxE,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,KAAK,CAAC,CAAW,CAAW,CAAC;aACxC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC;IAC1B,CAAC;IACD,OAAO,aAAa,CAAC;AACzB,CAAC;AAED,MAAM,UAAU,yBAAyB,CACrC,UAAkB,EAClB,KAAQ,EACR,QAAgB,EAChB,eAAuB,EACvB,IAAsG,EACtG,QAAkB,EAAE;IAEpB,MAAM,IAAI,GAAG,sBAAsB,CAAC,KAAK,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE9F,OAAO,6DAA6D,KAAK,CAAC,UAAU,CAAC,iCAAiC,IAAI,EAAE,CAAC;AACjI,CAAC","sourcesContent":["import type { GraphCanvasComponent } from \"./graphCanvas\";\r\nimport type { GraphNode } from \"./graphNode\";\r\nimport type { NodeLink } from \"./nodeLink\";\r\nimport type { FramePortData } from \"./types/framePortData\";\r\nimport * as localStyles from \"./graphNode.module.scss\";\r\n\r\nexport const IsFramePortData = (variableToCheck: any): variableToCheck is FramePortData => {\r\n if (variableToCheck) {\r\n return (variableToCheck as FramePortData).port !== undefined;\r\n } else {\r\n return false;\r\n }\r\n};\r\n\r\nexport const RefreshNode = (node: GraphNode, visitedNodes?: Set<GraphNode>, visitedLinks?: Set<NodeLink>, canvas?: GraphCanvasComponent) => {\r\n node.refresh();\r\n\r\n const links = node.links;\r\n\r\n if (visitedNodes) {\r\n // refresh first the nodes so that the right types are assigned to the auto-detect ports\r\n links.forEach((link) => {\r\n const nodeA = link.nodeA,\r\n nodeB = link.nodeB;\r\n\r\n if (!visitedNodes.has(nodeA)) {\r\n visitedNodes.add(nodeA);\r\n RefreshNode(nodeA, visitedNodes, visitedLinks);\r\n }\r\n\r\n if (nodeB && !visitedNodes.has(nodeB)) {\r\n visitedNodes.add(nodeB);\r\n RefreshNode(nodeB, visitedNodes, visitedLinks);\r\n }\r\n });\r\n }\r\n\r\n // Invisible endpoints (for teleport nodes)\r\n const invisibleEndpoints = node.content.invisibleEndpoints;\r\n if (invisibleEndpoints && invisibleEndpoints.length) {\r\n for (const endpoint of invisibleEndpoints) {\r\n const graphNode = canvas?.findNodeFromData(endpoint);\r\n if (graphNode) {\r\n if (visitedNodes) {\r\n visitedNodes.add(graphNode);\r\n }\r\n RefreshNode(graphNode, visitedNodes, visitedLinks);\r\n }\r\n }\r\n }\r\n\r\n if (!visitedLinks) {\r\n return;\r\n }\r\n\r\n // then refresh the links to display the right color between ports\r\n links.forEach((link) => {\r\n if (!visitedLinks.has(link)) {\r\n visitedLinks.add(link);\r\n link.update();\r\n }\r\n });\r\n};\r\n\r\nlet idGenerator = 0;\r\nexport const BuildFloatUI = (\r\n container: HTMLDivElement,\r\n document: Document,\r\n displayName: string,\r\n isInteger: boolean,\r\n source: any,\r\n propertyName: string,\r\n onChange: () => void,\r\n min?: number,\r\n max?: number,\r\n visualPropertiesRefresh?: Array<() => void>,\r\n additionalClassName?: string\r\n) => {\r\n const cantDisplaySlider = min === undefined || max === undefined || isNaN(min) || isNaN(max) || min === max;\r\n if (cantDisplaySlider) {\r\n container.classList.add(localStyles.floatContainer);\r\n const numberInput = document.createElement(\"input\");\r\n numberInput.type = \"number\";\r\n numberInput.id = `number-${idGenerator++}`;\r\n if (additionalClassName) {\r\n numberInput.classList.add(additionalClassName);\r\n }\r\n\r\n if (visualPropertiesRefresh) {\r\n visualPropertiesRefresh.push(() => {\r\n numberInput.value = source[propertyName];\r\n });\r\n } else {\r\n numberInput.value = source[propertyName];\r\n }\r\n numberInput.onchange = () => {\r\n source[propertyName] = parseFloat(numberInput.value);\r\n onChange();\r\n };\r\n\r\n if (isInteger) {\r\n numberInput.step = \"1\";\r\n }\r\n\r\n container.appendChild(numberInput);\r\n const label = document.createElement(\"div\");\r\n label.innerText = displayName;\r\n if (additionalClassName) {\r\n label.classList.add(additionalClassName);\r\n }\r\n container.appendChild(label);\r\n\r\n let shouldCapture = false;\r\n numberInput.onpointerdown = (evt) => {\r\n shouldCapture = true;\r\n evt.preventDefault();\r\n };\r\n numberInput.onpointerup = (evt) => {\r\n if (numberInput.hasPointerCapture(evt.pointerId)) {\r\n numberInput.releasePointerCapture(evt.pointerId);\r\n shouldCapture = false;\r\n evt.preventDefault();\r\n } else {\r\n numberInput.focus();\r\n numberInput.select();\r\n }\r\n };\r\n numberInput.onpointermove = (evt) => {\r\n if (shouldCapture) {\r\n numberInput.setPointerCapture(evt.pointerId);\r\n }\r\n\r\n if (numberInput.hasPointerCapture(evt.pointerId)) {\r\n const delta = isInteger ? Math.sign(evt.movementX) : evt.movementX * 0.01;\r\n numberInput.value = (parseFloat(numberInput.value) + delta).toFixed(isInteger ? 0 : 2);\r\n\r\n source[propertyName] = isInteger ? parseInt(numberInput.value) : parseFloat(numberInput.value);\r\n onChange();\r\n evt.preventDefault();\r\n }\r\n };\r\n } else {\r\n container.classList.add(localStyles.sliderContainer);\r\n const label = document.createElement(\"label\");\r\n container.appendChild(label);\r\n const value = document.createElement(\"div\");\r\n container.appendChild(value);\r\n const slider = document.createElement(\"input\");\r\n slider.type = \"range\";\r\n slider.id = `slider-${idGenerator++}`;\r\n slider.step = isInteger ? \"1\" : (Math.abs(max - min) / 100.0).toString();\r\n slider.min = min.toString();\r\n slider.max = max.toString();\r\n container.appendChild(slider);\r\n label.innerText = displayName;\r\n label.htmlFor = slider.id;\r\n if (visualPropertiesRefresh) {\r\n visualPropertiesRefresh.push(() => {\r\n slider.value = source[propertyName];\r\n value.innerText = source[propertyName];\r\n });\r\n } else {\r\n slider.value = source[propertyName];\r\n value.innerText = source[propertyName];\r\n }\r\n slider.oninput = () => {\r\n source[propertyName] = parseFloat(slider.value);\r\n value.innerText = source[propertyName];\r\n onChange();\r\n };\r\n }\r\n};\r\n\r\nexport function GetListOfAcceptedTypes<T extends Record<string, string | number>>(\r\n types: T,\r\n allValue: number,\r\n autoDetectValue: number,\r\n port: { acceptedConnectionPointTypes: number[]; excludedConnectionPointTypes: number[]; type: number },\r\n skips: number[] = []\r\n) {\r\n let acceptedTypes: string[] = [];\r\n\r\n if (port.type !== autoDetectValue) {\r\n acceptedTypes = [types[port.type] as string];\r\n }\r\n\r\n if (port.acceptedConnectionPointTypes.length !== 0) {\r\n acceptedTypes = port.acceptedConnectionPointTypes.filter((t) => t && t !== port.type).map((t) => types[t as number] as string);\r\n }\r\n\r\n if (skips.indexOf(autoDetectValue) === -1) {\r\n skips.push(autoDetectValue);\r\n }\r\n\r\n if (port.excludedConnectionPointTypes.length !== 0) {\r\n let bitmask = 0;\r\n let val = 2 ** bitmask;\r\n const candidates: number[] = [];\r\n while (val < allValue) {\r\n if (port.excludedConnectionPointTypes.indexOf(val) === -1 && skips.indexOf(val) === -1) {\r\n if (candidates.indexOf(val) === -1) {\r\n candidates.push(val);\r\n }\r\n }\r\n bitmask++;\r\n val = 2 ** bitmask;\r\n }\r\n acceptedTypes = (Object.values(types) as T[keyof T][])\r\n .filter((t) => candidates.indexOf(t as number) !== -1 && t !== port.type)\r\n .map((t) => types[t as number] as string)\r\n .filter((t) => t);\r\n }\r\n return acceptedTypes;\r\n}\r\n\r\nexport function GetConnectionErrorMessage<T extends Record<string, string | number>>(\r\n sourceType: number,\r\n types: T,\r\n allValue: number,\r\n autoDetectValue: number,\r\n port: { acceptedConnectionPointTypes: number[]; excludedConnectionPointTypes: number[]; type: number },\r\n skips: number[] = []\r\n) {\r\n const list = GetListOfAcceptedTypes(types, allValue, autoDetectValue, port, skips).join(\", \");\r\n\r\n return `Cannot connect two different connection types:\\nSource is ${types[sourceType]} but destination only accepts ${list}`;\r\n}\r\n"]}
|