first commit -push
This commit is contained in:
42
RobotNet.WebApp/wwwroot/js/app.js
Normal file
42
RobotNet.WebApp/wwwroot/js/app.js
Normal file
@@ -0,0 +1,42 @@
|
||||
function downloadFile(fileName, content, contentType) {
|
||||
const blob = new Blob([content], { type: contentType });
|
||||
const url = window.URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = fileName;
|
||||
document.body.appendChild(a);
|
||||
a.click();
|
||||
document.body.removeChild(a);
|
||||
window.URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function setFullscreen(isFull) {
|
||||
const sidebar = document.querySelector('.sidebar');
|
||||
const mainContent = document.querySelector('main');
|
||||
|
||||
if (sidebar && mainContent) {
|
||||
if (!isFull) {
|
||||
sidebar.classList.remove('hidden');
|
||||
if (document.exitFullscreen) {
|
||||
document.exitFullscreen();
|
||||
} else if (document.mozCancelFullScreen) {
|
||||
document.mozCancelFullScreen();
|
||||
} else if (document.webkitExitFullscreen) {
|
||||
document.webkitExitFullscreen();
|
||||
} else if (document.msExitFullscreen) {
|
||||
document.msExitFullscreen();
|
||||
}
|
||||
} else {
|
||||
sidebar.classList.add('hidden');
|
||||
if (document.documentElement.requestFullscreen) {
|
||||
document.documentElement.requestFullscreen();
|
||||
} else if (document.documentElement.mozRequestFullScreen) {
|
||||
document.documentElement.mozRequestFullScreen();
|
||||
} else if (document.documentElement.webkitRequestFullscreen) {
|
||||
document.documentElement.webkitRequestFullscreen();
|
||||
} else if (document.documentElement.msRequestFullscreen) {
|
||||
document.documentElement.msRequestFullscreen();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
14
RobotNet.WebApp/wwwroot/js/chart.umd.js
Normal file
14
RobotNet.WebApp/wwwroot/js/chart.umd.js
Normal file
File diff suppressed because one or more lines are too long
1
RobotNet.WebApp/wwwroot/js/chart.umd.js.map
Normal file
1
RobotNet.WebApp/wwwroot/js/chart.umd.js.map
Normal file
File diff suppressed because one or more lines are too long
1351
RobotNet.WebApp/wwwroot/js/chartjs-plugin-datalabels.esm.js
Normal file
1351
RobotNet.WebApp/wwwroot/js/chartjs-plugin-datalabels.esm.js
Normal file
File diff suppressed because it is too large
Load Diff
1356
RobotNet.WebApp/wwwroot/js/chartjs-plugin-datalabels.js
Normal file
1356
RobotNet.WebApp/wwwroot/js/chartjs-plugin-datalabels.js
Normal file
File diff suppressed because it is too large
Load Diff
7
RobotNet.WebApp/wwwroot/js/chartjs-plugin-datalabels.min.js
vendored
Normal file
7
RobotNet.WebApp/wwwroot/js/chartjs-plugin-datalabels.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
256
RobotNet.WebApp/wwwroot/js/map.js
Normal file
256
RobotNet.WebApp/wwwroot/js/map.js
Normal file
@@ -0,0 +1,256 @@
|
||||
window.InputClick = (elementId) => {
|
||||
document.getElementById(elementId).click();
|
||||
}
|
||||
|
||||
window.DownloadImage = (url, fileName) => {
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
}
|
||||
|
||||
window.DownloadImageBase64 = (base64Data, fileName) => {
|
||||
// Chuyển đổi Base64 thành Blob
|
||||
const byteCharacters = atob(base64Data.split(',')[1]);
|
||||
const byteNumbers = new Array(byteCharacters.length);
|
||||
for (let i = 0; i < byteCharacters.length; i++) {
|
||||
byteNumbers[i] = byteCharacters.charCodeAt(i);
|
||||
}
|
||||
const byteArray = new Uint8Array(byteNumbers);
|
||||
const blob = new Blob([byteArray], { type: 'image/png' }); // Thay đổi type nếu cần
|
||||
|
||||
// Tạo Object URL từ Blob
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
// Tạo thẻ `<a>` để tải về
|
||||
const link = document.createElement('a');
|
||||
link.href = url;
|
||||
link.download = fileName;
|
||||
document.body.appendChild(link);
|
||||
link.click();
|
||||
document.body.removeChild(link);
|
||||
|
||||
// Giải phóng bộ nhớ
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
window.setCssVariable = (variable, value) => {
|
||||
document.documentElement.style.setProperty(variable, value);
|
||||
localStorage.setItem(variable, value);
|
||||
};
|
||||
|
||||
window.getCssVariable = (variable) => {
|
||||
return localStorage.getItem(variable);
|
||||
};
|
||||
|
||||
window.DOMCssLoaded = () => {
|
||||
const width = localStorage.getItem('--edge-stroke-width');
|
||||
if (width) {
|
||||
document.documentElement.style.setProperty('--edge-stroke-width', width);
|
||||
}
|
||||
else {
|
||||
document.documentElement.style.setProperty('--edge-stroke-width', "0.15px");
|
||||
}
|
||||
|
||||
const directionwidth = localStorage.getItem('--edge-direction-stroke-width');
|
||||
if (directionwidth) {
|
||||
document.documentElement.style.setProperty('--edge-direction-stroke-width', directionwidth);
|
||||
}
|
||||
else {
|
||||
document.documentElement.style.setProperty('--edge-direction-stroke-width', "0.3px");
|
||||
}
|
||||
|
||||
const radius = localStorage.getItem('--node-r');
|
||||
if (radius) {
|
||||
document.documentElement.style.setProperty('--node-r', radius);
|
||||
}
|
||||
else {
|
||||
document.documentElement.style.setProperty('--node-r', "0.1px");
|
||||
}
|
||||
|
||||
const originwidth = localStorage.getItem('--origin-vector-stroke-width');
|
||||
if (originwidth) {
|
||||
document.documentElement.style.setProperty('--origin-vector-stroke-width', originwidth);
|
||||
}
|
||||
else {
|
||||
document.documentElement.style.setProperty('--origin-vector-stroke-width', "0.35px");
|
||||
}
|
||||
};
|
||||
|
||||
window.UpdateViewContainerRect = async (dotnetRef, divElement, funcName) => {
|
||||
var rect = divElement.getBoundingClientRect();
|
||||
await dotnetRef.invokeMethodAsync(funcName, rect.x, rect.y, rect.width, rect.height, rect.top, rect.right, rect.bottom, rect.left);
|
||||
};
|
||||
|
||||
window.ResizeObserverRegister = (dotnetRef, divElement, funcName) => {
|
||||
const resizeObserver = new ResizeObserver(async (entries) => {
|
||||
await window.UpdateViewContainerRect(dotnetRef, divElement, funcName);
|
||||
});
|
||||
|
||||
resizeObserver.observe(divElement);
|
||||
};
|
||||
|
||||
window.AddEventListener = (dotnetRef, element, eventName, funcName, stopPropagation = true) => {
|
||||
element.addEventListener(eventName, async (ev) => {
|
||||
ev.preventDefault();
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
await dotnetRef.invokeMethodAsync(funcName);
|
||||
})
|
||||
};
|
||||
|
||||
window.AddMouseMoveEventListener = (dotnetRef, element, funcName, stopPropagation = true) => {
|
||||
element.addEventListener("mousemove", async (ev) => {
|
||||
ev.preventDefault();
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
await dotnetRef.invokeMethodAsync(funcName, ev.clientX, ev.clientY, ev.buttons, ev.ctrlKey, ev.movementX, ev.movementY);
|
||||
})
|
||||
};
|
||||
|
||||
window.AddKeyUpEventListener = (dotnetRef, element, funcName, stopPropagation = true) => {
|
||||
element.addEventListener("keyup", async (ev) => {
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
await dotnetRef.invokeMethodAsync(funcName, ev.code, ev.key, ev.altKey, ev.ctrlKey, ev.shiftKey);
|
||||
})
|
||||
};
|
||||
|
||||
window.AddMouseWheelEventListener = (dotnetRef, element, funcName, stopPropagation = true) => {
|
||||
element.addEventListener("mousewheel", async (ev) => {
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
await dotnetRef.invokeMethodAsync(funcName, ev.deltaY, ev.offsetX, ev.offsetY);
|
||||
}, { passive: true })
|
||||
};
|
||||
|
||||
window.AddMouseUpEventListener = (dotnetRef, element, funcName, stopPropagation = true) => {
|
||||
element.addEventListener("mouseup", async (ev) => {
|
||||
ev.preventDefault();
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
await dotnetRef.invokeMethodAsync(funcName, ev.button, ev.altKey, ev.ctrlKey, ev.shiftKey);
|
||||
})
|
||||
};
|
||||
|
||||
window.AddMouseDownEventListener = (dotnetRef, element, funcName, stopPropagation = true) => {
|
||||
element.addEventListener("mousedown", async (ev) => {
|
||||
ev.preventDefault();
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
await dotnetRef.invokeMethodAsync(funcName, ev.button, ev.altKey, ev.ctrlKey, ev.shiftKey);
|
||||
})
|
||||
};
|
||||
|
||||
window.SetMapSvgConfig = (element, width, height, originX, originY) => {
|
||||
if (element && element.nodeName && element.nodeName.toLowerCase() === "svg") {
|
||||
element.setAttribute("width", width );
|
||||
element.setAttribute("height", height );
|
||||
element.setAttribute("viewBox", `${originX} ${originY} ${width} ${height}`);
|
||||
}
|
||||
};
|
||||
|
||||
window.SetMapSvgRect = (element, width, height) => {
|
||||
if (element && element.nodeName && element.nodeName.toLowerCase() === "svg") {
|
||||
element.setAttribute("width", width);
|
||||
element.setAttribute("height", height);
|
||||
}
|
||||
};
|
||||
|
||||
window.SetImageAttribute = (element, width, height, originX, originY, href) => {
|
||||
if (element && element.nodeName && element.nodeName.toLowerCase() === "image") {
|
||||
element.setAttribute("width", width );
|
||||
element.setAttribute("height", height );
|
||||
element.setAttribute("x", originX);
|
||||
element.setAttribute("y", originY);
|
||||
element.setAttribute("href", href);
|
||||
}
|
||||
};
|
||||
|
||||
window.SetMapMovement = (element, top, left) => {
|
||||
if (element && element.nodeName && element.nodeName.toLowerCase() === "div") {
|
||||
element.setAttribute("style", `top: ${top}px; left: ${left}px;`);
|
||||
}
|
||||
};
|
||||
|
||||
window.SetMapScale = (element, scale) => {
|
||||
if (element && element.nodeName && element.nodeName.toLowerCase() === "div") {
|
||||
element.setAttribute("style", `transform: scale(${scale });`);
|
||||
}
|
||||
};
|
||||
|
||||
window.SetNodePosition = (circleRef, textRef, x, y) => {
|
||||
if (circleRef && circleRef.setAttribute) {
|
||||
circleRef.setAttribute("cx", x);
|
||||
circleRef.setAttribute("cy", y);
|
||||
}
|
||||
if (textRef && textRef.setAttribute) {
|
||||
const radius = parseFloat(localStorage.getItem('--node-r'));
|
||||
if (!radius) {
|
||||
radius = 0.1;
|
||||
}
|
||||
textRef.setAttribute("x", x);
|
||||
textRef.setAttribute("y", - y - radius - 0.08);
|
||||
}
|
||||
};
|
||||
|
||||
window.AddSelected = (element) => {
|
||||
element.classList.add("active");
|
||||
};
|
||||
|
||||
window.RemoveSelected = (element) => {
|
||||
element.classList.remove("active");
|
||||
};
|
||||
|
||||
window.ElementSetAttribute = (element, attr, value) => {
|
||||
if (element && element.setAttribute) element.setAttribute(attr, value);
|
||||
}
|
||||
|
||||
window.AddTouchMoveEventListener = (dotnetRef, element, funcName, stopPropagation = true) => {
|
||||
let lastX = 0, lastY = 0;
|
||||
element.addEventListener("touchmove", async (ev) => {
|
||||
ev.preventDefault();
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
|
||||
const touch = ev.touches[0];
|
||||
const movementX = touch.clientX - lastX;
|
||||
const movementY = touch.clientY - lastY;
|
||||
|
||||
lastX = touch.clientX;
|
||||
lastY = touch.clientY;
|
||||
await dotnetRef.invokeMethodAsync(funcName, touch.clientX, touch.clientY, ev.touches.length, movementX, movementY);
|
||||
});
|
||||
|
||||
element.addEventListener("touchstart", (ev) => {
|
||||
const touch = ev.touches[0];
|
||||
lastX = touch.clientX;
|
||||
lastY = touch.clientY;
|
||||
});
|
||||
};
|
||||
|
||||
window.DownloadMap = async (filename, content) => {
|
||||
const arrayBuffer = await content.arrayBuffer();
|
||||
const blob = new Blob([arrayBuffer]);
|
||||
const url = URL.createObjectURL(blob);
|
||||
|
||||
const anchor = document.createElement('a');
|
||||
anchor.href = url;
|
||||
anchor.download = filename;
|
||||
anchor.click();
|
||||
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
window.SetElementPosition = (robotRef, nameRef, x, y, theta, originX, originY) => {
|
||||
if (robotRef && robotRef.setAttribute) {
|
||||
robotRef.setAttribute("x", x + originX);
|
||||
robotRef.setAttribute("y", y + originY);
|
||||
robotRef.setAttribute("transform", `rotate(${theta} ${x} ${y})`);
|
||||
}
|
||||
if (nameRef && nameRef.setAttribute) {
|
||||
nameRef.setAttribute("x", x);
|
||||
nameRef.setAttribute("y", -y);
|
||||
}
|
||||
}
|
||||
|
||||
window.ScrollToBottom = (objDiv) => {
|
||||
if (objDiv.scrollTop != objDiv.scrollHeight) {
|
||||
objDiv.scrollTop = objDiv.scrollHeight;
|
||||
}
|
||||
}
|
||||
176
RobotNet.WebApp/wwwroot/js/robonet.chart.js
Normal file
176
RobotNet.WebApp/wwwroot/js/robonet.chart.js
Normal file
@@ -0,0 +1,176 @@
|
||||
if (!window.blazorChart) {
|
||||
window.blazorChart = {};
|
||||
}
|
||||
|
||||
|
||||
window.blazorChart = {
|
||||
addDatasetData: (elementId, dataLabel, data) => {
|
||||
let chart = window.blazorChart.get(elementId);
|
||||
if (chart) {
|
||||
const chartData = chart.data;
|
||||
const chartDatasetData = data;
|
||||
|
||||
if (!chartData.labels.includes(dataLabel))
|
||||
chartData.labels.push(dataLabel);
|
||||
|
||||
const chartDatasets = chartData.datasets;
|
||||
|
||||
if (chartDatasets.length > 0) {
|
||||
let datasetIndex = chartDatasets.findIndex(dataset => dataset.label === chartDatasetData.datasetLabel);
|
||||
if (datasetIndex > -1) {
|
||||
chartDatasets[datasetIndex].data.push(chartDatasetData.data);
|
||||
chart.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
addDatasetsData: (elementId, dataLabel, data) => {
|
||||
let chart = window.blazorChart.get(elementId);
|
||||
if (chart && data) {
|
||||
const chartData = chart.data;
|
||||
|
||||
if (!chartData.labels.includes(dataLabel)) {
|
||||
chartData.labels.push(dataLabel);
|
||||
|
||||
if (chartData.datasets.length > 0 && chartData.datasets.length === data.length) {
|
||||
data.forEach(chartDatasetData => {
|
||||
let datasetIndex = chartData.datasets.findIndex(dataset => dataset.label === chartDatasetData.datasetLabel);
|
||||
chartData.datasets[datasetIndex].data.push(chartDatasetData.data);
|
||||
});
|
||||
chart.update();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
addDataset: (elementId, newDataset) => {
|
||||
let chart = window.blazorChart.get(elementId);
|
||||
if (chart) {
|
||||
chart.data.datasets.push(newDataset);
|
||||
chart.update();
|
||||
}
|
||||
},
|
||||
create: (elementId, type, data, options) => {
|
||||
let chartEl = document.getElementById(elementId);
|
||||
let _plugins = [];
|
||||
|
||||
_plugins.push(ChartDataLabels);
|
||||
const config = {
|
||||
type: type,
|
||||
data: data,
|
||||
options: options,
|
||||
plugins: _plugins
|
||||
};
|
||||
|
||||
if (type === 'line') {
|
||||
const tooltipLine = {
|
||||
id: 'tooltipLine',
|
||||
beforeDraw: chart => {
|
||||
if (chart.tooltip?._active && chart.tooltip?._active.length) {
|
||||
const ctx = chart.ctx;
|
||||
ctx.save();
|
||||
const activePoint = chart.tooltip._active[0];
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.setLineDash([5, 5]);
|
||||
ctx.moveTo(activePoint.element.x, chart.chartArea.top);
|
||||
ctx.lineTo(activePoint.element.x, activePoint.element.y);
|
||||
ctx.linewidth = 2;
|
||||
ctx.strokeStyle = 'grey';
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
|
||||
ctx.beginPath();
|
||||
ctx.setLineDash([5, 5]);
|
||||
ctx.moveTo(activePoint.element.x, activePoint.element.y);
|
||||
ctx.lineTo(activePoint.element.x, chart.chartArea.bottom);
|
||||
ctx.linewidth = 2;
|
||||
ctx.strokeStyle = 'grey';
|
||||
ctx.stroke();
|
||||
ctx.restore();
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
config.plugins.push(tooltipLine);
|
||||
}
|
||||
|
||||
const chart = new Chart(
|
||||
chartEl,
|
||||
config
|
||||
);
|
||||
},
|
||||
get: (elementId) => {
|
||||
let chart;
|
||||
Chart.helpers.each(Chart.instances, function (instance) {
|
||||
if (instance.canvas.id === elementId) {
|
||||
chart = instance;
|
||||
}
|
||||
});
|
||||
|
||||
return chart;
|
||||
},
|
||||
initialize: (elementId, type, data, options) => {
|
||||
let chart = window.blazorChart.get(elementId);
|
||||
if (chart) return;
|
||||
else
|
||||
window.blazorChart.create(elementId, type, data, options);
|
||||
},
|
||||
resize: (elementId, width, height) => {
|
||||
let chart = window.blazorChart.get(elementId);
|
||||
if (chart) {
|
||||
chart.canvas.parentNode.style.height = height;
|
||||
chart.canvas.parentNode.style.width = width;
|
||||
}
|
||||
},
|
||||
update: (elementId, data, options) => {
|
||||
let chart = window.blazorChart.get(elementId);
|
||||
if (chart) {
|
||||
chart.data = data;
|
||||
chart.options = options;
|
||||
chart.update();
|
||||
}
|
||||
else {
|
||||
console.warn(`The chart is not initialized. Initialize it and then call update.`);
|
||||
}
|
||||
},
|
||||
updateData: (elementId, data) => {
|
||||
let chart = window.blazorChart.get(elementId);
|
||||
if (chart) {
|
||||
window.blazorChart.mergeDatasets(chart.data.datasets, data.datasets);
|
||||
window.blazorChart.mergeLabels(chart.data, data);
|
||||
chart.update();
|
||||
}
|
||||
},
|
||||
mergeDatasets(oldDatasets, newDatasets) {
|
||||
for (let i = oldDatasets.length - 1; i >= 0; i--) {
|
||||
let sameDatasetInNewConfig = newDatasets.find(newD => newD.label === oldDatasets[i].label);
|
||||
if (sameDatasetInNewConfig === undefined) {
|
||||
oldDatasets.splice(i, 1);
|
||||
}
|
||||
else {
|
||||
oldDatasets[i].data = sameDatasetInNewConfig.data;
|
||||
}
|
||||
}
|
||||
let currentIds = oldDatasets.map(dataset => dataset.label);
|
||||
newDatasets.filter(newDataset => !currentIds.includes(newDataset.label)).forEach(newDataset => oldDatasets.push(newDataset));
|
||||
},
|
||||
mergeLabels(oldChartData, newChartData) {
|
||||
const innerFunc = (oldLabels, newLabels) => {
|
||||
if (newLabels == null || newLabels.length === 0) {
|
||||
if (oldLabels) {
|
||||
oldLabels.length = 0;
|
||||
}
|
||||
return oldLabels;
|
||||
}
|
||||
if (oldLabels == null) {
|
||||
return newLabels;
|
||||
}
|
||||
oldLabels.length = 0;
|
||||
for (var i = 0; i < newLabels.length; i++) {
|
||||
oldLabels.push(newLabels[i]);
|
||||
}
|
||||
return oldLabels;
|
||||
};
|
||||
oldChartData.labels = innerFunc(oldChartData.labels, newChartData.labels);
|
||||
},
|
||||
}
|
||||
119
RobotNet.WebApp/wwwroot/js/robot-design.js
Normal file
119
RobotNet.WebApp/wwwroot/js/robot-design.js
Normal file
@@ -0,0 +1,119 @@
|
||||
window.ElementSetAttribute = (element, attr, value) => {
|
||||
if (element && element.setAttribute) element.setAttribute(attr, value);
|
||||
}
|
||||
|
||||
window.SetImageAttribute = (element, width, height, originX, originY, href) => {
|
||||
if (element && element.nodeName && element.nodeName.toLowerCase() === "image") {
|
||||
element.setAttribute("width", width);
|
||||
element.setAttribute("height", height);
|
||||
element.setAttribute("x", originX);
|
||||
element.setAttribute("y", originY);
|
||||
element.setAttribute("href", href);
|
||||
}
|
||||
};
|
||||
|
||||
window.SetRobotPosition = (robotRef, nameRef, x, y, theta, originX, originY) => {
|
||||
if (robotRef && robotRef.setAttribute) {
|
||||
robotRef.setAttribute("x", x + originX);
|
||||
robotRef.setAttribute("y", y + originY);
|
||||
robotRef.setAttribute("transform", `rotate(${theta} ${x} ${y})`);
|
||||
}
|
||||
if (nameRef && nameRef.setAttribute) {
|
||||
nameRef.setAttribute("x", x);
|
||||
nameRef.setAttribute("y", -y);
|
||||
}
|
||||
}
|
||||
|
||||
window.SetNodePosition = (circleRef, textRef, x, y) => {
|
||||
if (circleRef && circleRef.setAttribute) {
|
||||
circleRef.setAttribute("cx", x);
|
||||
circleRef.setAttribute("cy", y);
|
||||
}
|
||||
if (textRef && textRef.setAttribute) {
|
||||
const radius = parseFloat(localStorage.getItem('--node-r'));
|
||||
if (!radius) {
|
||||
radius = 0.1;
|
||||
}
|
||||
textRef.setAttribute("x", x);
|
||||
textRef.setAttribute("y", - y - radius - 0.08);
|
||||
}
|
||||
};
|
||||
|
||||
window.UpdateViewContainerRect = async (dotnetRef, divElement, funcName) => {
|
||||
var rect = divElement.getBoundingClientRect();
|
||||
await dotnetRef.invokeMethodAsync(funcName, rect.x, rect.y, rect.width, rect.height, rect.top, rect.right, rect.bottom, rect.left);
|
||||
};
|
||||
|
||||
window.ResizeObserverRegister = (dotnetRef, divElement, funcName) => {
|
||||
const resizeObserver = new ResizeObserver(async (entries) => {
|
||||
await window.UpdateViewContainerRect(dotnetRef, divElement, funcName);
|
||||
});
|
||||
|
||||
resizeObserver.observe(divElement);
|
||||
};
|
||||
|
||||
window.AddEventListener = (dotnetRef, element, eventName, funcName, stopPropagation = true) => {
|
||||
element.addEventListener(eventName, async (ev) => {
|
||||
ev.preventDefault();
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
await dotnetRef.invokeMethodAsync(funcName);
|
||||
})
|
||||
};
|
||||
|
||||
window.AddMouseMoveEventListener = (dotnetRef, element, funcName, stopPropagation = true) => {
|
||||
element.addEventListener("mousemove", async (ev) => {
|
||||
ev.preventDefault();
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
await dotnetRef.invokeMethodAsync(funcName, ev.clientX, ev.clientY, ev.buttons, ev.ctrlKey, ev.movementX, ev.movementY);
|
||||
})
|
||||
};
|
||||
|
||||
window.AddMouseWheelEventListener = (dotnetRef, element, funcName, stopPropagation = true) => {
|
||||
element.addEventListener("mousewheel", async (ev) => {
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
await dotnetRef.invokeMethodAsync(funcName, ev.deltaY, ev.offsetX, ev.offsetY);
|
||||
}, { passive: true })
|
||||
};
|
||||
|
||||
window.AddTouchMoveEventListener = (dotnetRef, element, funcName, stopPropagation = true) => {
|
||||
let lastX = 0, lastY = 0;
|
||||
element.addEventListener("touchmove", async (ev) => {
|
||||
ev.preventDefault();
|
||||
if (stopPropagation) ev.stopPropagation();
|
||||
|
||||
const touch = ev.touches[0];
|
||||
const movementX = touch.clientX - lastX;
|
||||
const movementY = touch.clientY - lastY;
|
||||
|
||||
lastX = touch.clientX;
|
||||
lastY = touch.clientY;
|
||||
await dotnetRef.invokeMethodAsync(funcName, touch.clientX, touch.clientY, ev.touches.length, movementX, movementY);
|
||||
});
|
||||
|
||||
element.addEventListener("touchstart", (ev) => {
|
||||
const touch = ev.touches[0];
|
||||
lastX = touch.clientX;
|
||||
lastY = touch.clientY;
|
||||
});
|
||||
};
|
||||
|
||||
window.SetMapSvgConfig = (element, width, height, originX, originY) => {
|
||||
if (element && element.nodeName && element.nodeName.toLowerCase() === "svg") {
|
||||
element.setAttribute("width", width);
|
||||
element.setAttribute("height", height);
|
||||
element.setAttribute("viewBox", `${originX} ${originY} ${width} ${height}`);
|
||||
}
|
||||
};
|
||||
|
||||
window.SetMapMovement = (element, top, left) => {
|
||||
if (element && element.nodeName && element.nodeName.toLowerCase() === "div") {
|
||||
element.setAttribute("style", `top: ${top}px; left: ${left}px;`);
|
||||
}
|
||||
};
|
||||
|
||||
window.SetMapSvgRect = (element, width, height) => {
|
||||
if (element && element.nodeName && element.nodeName.toLowerCase() === "svg") {
|
||||
element.setAttribute("width", width);
|
||||
element.setAttribute("height", height);
|
||||
}
|
||||
};
|
||||
76
RobotNet.WebApp/wwwroot/js/script.js
Normal file
76
RobotNet.WebApp/wwwroot/js/script.js
Normal file
@@ -0,0 +1,76 @@
|
||||
window.monaco = monaco;
|
||||
|
||||
window.MonacoRuntime = {
|
||||
OnCodeEditorDidChangeModelContent: (codeEditor, dotnetRef, method) => {
|
||||
codeEditor.onDidChangeModelContent(function (e) {
|
||||
dotnetRef.invokeMethodAsync(method, e);
|
||||
});
|
||||
},
|
||||
CSharpLanguageRegisterCompletionItemProvider: (dotnetRef, getCompletionMethod) => {
|
||||
return monaco.languages.registerCompletionItemProvider("csharp", {
|
||||
triggerCharacters: ["."],
|
||||
//resolveCompletionItem: (model, position, item) => {
|
||||
// return this.resolveCompletionItem(item, dotnetHelper)
|
||||
//},
|
||||
provideCompletionItems: async (model, position, context, token) => {
|
||||
return await dotnetRef.invokeMethodAsync(getCompletionMethod, position.lineNumber, position.column, context.triggerKind, context.triggerCharacter);
|
||||
}
|
||||
});
|
||||
},
|
||||
CSharpLanguageRegisterSignatureHelpProvider: (dotnetRef, getSignatureHelpMethod) => {
|
||||
return monaco.languages.registerSignatureHelpProvider("csharp", {
|
||||
signatureHelpTriggerCharacters: ['('],
|
||||
provideSignatureHelp: async (model, position, token, context) => {
|
||||
let signature = await dotnetRef.invokeMethodAsync(getSignatureHelpMethod, position.lineNumber, position.column);
|
||||
if (!signature) {
|
||||
return undefined;
|
||||
}
|
||||
return {
|
||||
value: signature.value,
|
||||
dispose: () => { },
|
||||
}
|
||||
}
|
||||
});
|
||||
},
|
||||
CSharpLanguageRegisterHoverProvider: (dotnetRef, getHoverProviderMethod) => {
|
||||
return monaco.languages.registerHoverProvider("csharp", {
|
||||
provideHover: async (model, position, token, context) => {
|
||||
var mess = await dotnetRef.invokeMethodAsync(getHoverProviderMethod, position.lineNumber, position.column);
|
||||
return {
|
||||
contents: [
|
||||
{
|
||||
value: mess
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("keydown", function (e) {
|
||||
if ((e.key === 's' || e.key == 'S') && e.ctrlKey) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
}, false);
|
||||
|
||||
window.addEventListener("contextmenu", function (e) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}, false);
|
||||
|
||||
window.SetRadioChecked = function (id) {
|
||||
document.getElementById(id).checked = true;
|
||||
};
|
||||
|
||||
window.UncheckRadioAll = function (name) {
|
||||
const radios = document.querySelectorAll(`input[type="radio"][name="${name}"]`);
|
||||
radios.forEach(radio => radio.checked = false);
|
||||
};
|
||||
|
||||
window.ScrollToBottom = (element) => {
|
||||
if (element) {
|
||||
element.scrollTop = element.scrollHeight;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user