From d04ec7bfc7d6a281a9b0025f1b4d676f3739e2ae Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=E7=8E=8B=E7=AB=8B=E5=B8=AE?= <3294713004@qq.com>
Date: Sun, 27 Apr 2025 15:49:16 +0800
Subject: [PATCH] =?UTF-8?q?feat(core):=20=E5=B0=86Mixly.MJSON=E8=B0=83?=
=?UTF-8?q?=E6=95=B4=E4=B8=BAMixly.MJson?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
.../modules/mixly-modules/common/command.js | 6 ++--
.../mixly-modules/common/editor-mix.js | 8 ++---
common/modules/mixly-modules/common/mjson.js | 24 ++++++-------
common/modules/mixly-modules/common/msg.js | 10 +++---
common/modules/mixly-modules/deps.json | 35 ++++++++++++++-----
.../modules/mixly-modules/electron/ampy-fs.js | 6 ++--
.../mixly-modules/electron/cloud-download.js | 6 ++--
.../mixly-modules/web-socket/ampy-fs.js | 6 ++--
.../mixly-modules/web/footerlayer-example.js | 6 ++--
mixly-sw/mixly-modules/common/msg.js | 10 +++---
mixly-sw/mixly-modules/common/setting.js | 4 +--
mixly-sw/mixly-modules/deps.json | 6 ++--
mixly-sw/mixly-modules/web-socket/socket.js | 8 ++---
13 files changed, 76 insertions(+), 59 deletions(-)
diff --git a/common/modules/mixly-modules/common/command.js b/common/modules/mixly-modules/common/command.js
index daac7d8b..f9388bf6 100644
--- a/common/modules/mixly-modules/common/command.js
+++ b/common/modules/mixly-modules/common/command.js
@@ -1,14 +1,14 @@
goog.loadJs('common', () => {
goog.require('Mixly.Config');
-goog.require('Mixly.MJSON')
+goog.require('Mixly.MJson')
goog.require('Mixly.Debug');
goog.provide('Mixly.Command');
const {
Config,
Command,
- MJSON,
+ MJson,
Debug
} = Mixly;
@@ -21,7 +21,7 @@ Command.DEFAULT = {
}
Command.parse = (commandStr) => {
- return MJSON.decode(MJSON.parse(commandStr));
+ return MJson.decode(MJson.parse(commandStr));
}
Command.run = (commandObj) => {
diff --git a/common/modules/mixly-modules/common/editor-mix.js b/common/modules/mixly-modules/common/editor-mix.js
index d2c1b4db..07398a02 100644
--- a/common/modules/mixly-modules/common/editor-mix.js
+++ b/common/modules/mixly-modules/common/editor-mix.js
@@ -15,7 +15,7 @@ goog.require('Mixly.ContextMenu');
goog.require('Mixly.Debug');
goog.require('Mixly.Menu');
goog.require('Mixly.Boards');
-goog.require('Mixly.MJSON');
+goog.require('Mixly.MJson');
goog.require('Mixly.HTMLTemplate');
goog.require('Mixly.EditorBlockly');
goog.require('Mixly.EditorCode');
@@ -37,7 +37,7 @@ const {
Debug,
Menu,
Boards,
- MJSON,
+ MJson,
HTMLTemplate,
LayerExt
} = Mixly;
@@ -436,7 +436,7 @@ class EditorMix extends EditorBase {
}
xml = $xml[0].outerHTML;
if (config) {
- xml += `${MJSON.stringify(config)}`;
+ xml += `${MJson.stringify(config)}`;
}
xml += `${Base64.encode(code)}`;
return xml;
@@ -523,7 +523,7 @@ class EditorMix extends EditorBase {
}
}
let config, configStr = configDom && configDom.html();
- config = configStr? MJSON.parse(configStr) : {};
+ config = configStr? MJson.parse(configStr) : {};
let boardName = xmlDom.attr('board') ?? '';
blockPage.getEditor().clear();
Boards.setSelectedBoard(boardName, config);
diff --git a/common/modules/mixly-modules/common/mjson.js b/common/modules/mixly-modules/common/mjson.js
index 5a3e6bf3..06545592 100644
--- a/common/modules/mixly-modules/common/mjson.js
+++ b/common/modules/mixly-modules/common/mjson.js
@@ -1,17 +1,17 @@
goog.loadJs('common', () => {
goog.require('Mixly.Debug');
-goog.provide('Mixly.MJSON');
+goog.provide('Mixly.MJson');
-const { Debug, MJSON } = Mixly;
+const { Debug, MJson } = Mixly;
-MJSON.operate = (jsonObj, optFunc) => {
+MJson.operate = (jsonObj, optFunc) => {
// 循环所有键
for (var key in jsonObj) {
//如果对象类型为object类型且数组长度大于0 或者 是对象 ,继续递归解析
var element = jsonObj[key];
if (element.length > 0 && typeof (element) == "object" || typeof (element) == "object") {
- let data = MJSON.operate(element, optFunc);
+ let data = MJson.operate(element, optFunc);
for (let i in data) {
jsonObj[key][i] = data[i];
}
@@ -28,19 +28,19 @@ MJSON.operate = (jsonObj, optFunc) => {
return jsonObj;
}
-MJSON.decode = (jsonObj) => {
+MJson.decode = (jsonObj) => {
// 深度拷贝对象,防止解码或编码时篡改原有对象
let newJsonObj = structuredClone(jsonObj);
- return MJSON.operate(newJsonObj, decodeURIComponent);
+ return MJson.operate(newJsonObj, decodeURIComponent);
}
-MJSON.encode = (jsonObj) => {
+MJson.encode = (jsonObj) => {
// 深度拷贝对象,防止解码或编码时篡改原有对象
let newJsonObj = structuredClone(jsonObj);
- return MJSON.operate(newJsonObj, encodeURIComponent);;
+ return MJson.operate(newJsonObj, encodeURIComponent);;
}
-MJSON.parse = (jsonStr) => {
+MJson.parse = (jsonStr) => {
let jsonObj = null;
try {
jsonStr = jsonStr.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m);
@@ -51,7 +51,7 @@ MJSON.parse = (jsonStr) => {
return jsonObj;
}
-MJSON.stringify = (jsonObj) => {
+MJson.stringify = (jsonObj) => {
let jsonStr = '';
try {
jsonStr = JSON.stringify(jsonObj);
@@ -61,8 +61,8 @@ MJSON.stringify = (jsonObj) => {
return jsonStr;
}
-MJSON.get = (inPath) => {
- return goog.getJSON(inPath);
+MJson.get = (inPath) => {
+ return goog.readJsonSync(inPath);
}
});
\ No newline at end of file
diff --git a/common/modules/mixly-modules/common/msg.js b/common/modules/mixly-modules/common/msg.js
index d325247c..049d01bc 100644
--- a/common/modules/mixly-modules/common/msg.js
+++ b/common/modules/mixly-modules/common/msg.js
@@ -1,7 +1,7 @@
goog.loadJs('common', () => {
goog.require('path');
-goog.require('Mixly.MJSON');
+goog.require('Mixly.MJson');
goog.require('Mixly.Config');
goog.require('Mixly.Env');
goog.require('Blockly');
@@ -12,7 +12,7 @@ goog.provide('Mixly.Msg');
const {
Msg,
- MJSON,
+ MJson,
Config,
Env
} = Mixly;
@@ -32,9 +32,9 @@ Msg.PATH = {
}
Msg.LANG = {
- "zh-hans": MJSON.get(Msg.PATH["zh-hans"]),
- "zh-hant": MJSON.get(Msg.PATH["zh-hant"]),
- "en": MJSON.get(Msg.PATH["en"])
+ "zh-hans": MJson.get(Msg.PATH["zh-hans"]),
+ "zh-hant": MJson.get(Msg.PATH["zh-hant"]),
+ "en": MJson.get(Msg.PATH["en"])
}
Msg.nowLang = USER.language ?? 'zh-hans';
diff --git a/common/modules/mixly-modules/deps.json b/common/modules/mixly-modules/deps.json
index b8b446e3..963d5e38 100644
--- a/common/modules/mixly-modules/deps.json
+++ b/common/modules/mixly-modules/deps.json
@@ -112,7 +112,7 @@
"path": "/common/command.js",
"require": [
"Mixly.Config",
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.Debug"
],
"provide": [
@@ -309,7 +309,7 @@
"Mixly.Debug",
"Mixly.Menu",
"Mixly.Boards",
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.HTMLTemplate",
"Mixly.EditorBlockly",
"Mixly.EditorCode",
@@ -597,10 +597,25 @@
"Mixly.LayerExt"
]
},
+ {
+ "path": "/common/layer-progress.js",
+ "require": [
+ "Mixly.Env",
+ "Mixly.Layer",
+ "Mixly.HTMLTemplate"
+ ],
+ "provide": [
+ "Mixly.LayerProgress"
+ ]
+ },
{
"path": "/common/layer.js",
"require": [
- "Mixly.Registry"
+ "dialog",
+ "Mixly.Env",
+ "Mixly.Registry",
+ "Mixly.Component",
+ "Mixly.HTMLTemplate"
],
"provide": [
"Mixly.Layer"
@@ -712,14 +727,14 @@
"Mixly.Debug"
],
"provide": [
- "Mixly.MJSON"
+ "Mixly.MJson"
]
},
{
"path": "/common/msg.js",
"require": [
"path",
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.Config",
"Mixly.Env",
"Blockly",
@@ -1210,7 +1225,7 @@
"Mixly.Env",
"Mixly.FS",
"Mixly.Debug",
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.Electron.Ampy"
],
"provide": [
@@ -1279,7 +1294,7 @@
"require": [
"path",
"Mixly.Env",
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.Electron"
],
"provide": [
@@ -1584,7 +1599,7 @@
"path",
"Mixly.Config",
"Mixly.Env",
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.FooterLayerExample",
"Mixly.Boards"
],
@@ -1720,7 +1735,7 @@
"Mixly.Env",
"Mixly.FS",
"Mixly.Debug",
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.WebSocket.Ampy"
],
"provide": [
@@ -1751,6 +1766,7 @@
"Mixly.LayerExt",
"Mixly.Msg",
"Mixly.Workspace",
+ "Mixly.LayerProgress",
"Mixly.WebSocket.Serial"
],
"provide": [
@@ -1770,6 +1786,7 @@
"Mixly.Config",
"Mixly.Workspace",
"Mixly.MString",
+ "Mixly.LayerProgress",
"Mixly.WebSocket.Serial"
],
"provide": [
diff --git a/common/modules/mixly-modules/electron/ampy-fs.js b/common/modules/mixly-modules/electron/ampy-fs.js
index 2b55a0bf..8563a0bb 100644
--- a/common/modules/mixly-modules/electron/ampy-fs.js
+++ b/common/modules/mixly-modules/electron/ampy-fs.js
@@ -4,7 +4,7 @@ goog.require('path');
goog.require('Mixly.Env');
goog.require('Mixly.FS');
goog.require('Mixly.Debug');
-goog.require('Mixly.MJSON');
+goog.require('Mixly.MJson');
goog.require('Mixly.Electron.Ampy');
goog.provide('Mixly.Electron.AmpyFS');
@@ -12,7 +12,7 @@ const {
Env,
FS,
Debug,
- MJSON,
+ MJson,
Electron
} = Mixly;
const { Ampy } = Electron;
@@ -136,7 +136,7 @@ class AmpyFS extends FS {
if (!dirs[i]) {
continue;
}
- stdout.push(MJSON.parse(dirs[i].replaceAll('\'', '"')));
+ stdout.push(MJson.parse(dirs[i].replaceAll('\'', '"')));
}
} catch (e) {
error = e;
diff --git a/common/modules/mixly-modules/electron/cloud-download.js b/common/modules/mixly-modules/electron/cloud-download.js
index 413823e9..1cc4fc79 100644
--- a/common/modules/mixly-modules/electron/cloud-download.js
+++ b/common/modules/mixly-modules/electron/cloud-download.js
@@ -2,13 +2,13 @@ goog.loadJs('electron', () => {
goog.require('path');
goog.require('Mixly.Env');
-goog.require('Mixly.MJSON');
+goog.require('Mixly.MJson');
goog.require('Mixly.Electron');
goog.provide('Mixly.Electron.CloudDownload');
const {
Env,
- MJSON,
+ MJson,
Electron
} = Mixly;
@@ -29,7 +29,7 @@ CloudDownload.getJson = (url, downloadDir, endFunc) => {
let jsonObj = null;
if (fs_plus.isFileSync(message[1])) {
let data = fs.readFileSync(message[1], 'utf-8');
- jsonObj = MJSON.parse(data);
+ jsonObj = MJson.parse(data);
}
if (jsonObj) {
return jsonObj;
diff --git a/common/modules/mixly-modules/web-socket/ampy-fs.js b/common/modules/mixly-modules/web-socket/ampy-fs.js
index 5e96c853..5623b151 100644
--- a/common/modules/mixly-modules/web-socket/ampy-fs.js
+++ b/common/modules/mixly-modules/web-socket/ampy-fs.js
@@ -4,7 +4,7 @@ goog.require('path');
goog.require('Mixly.Env');
goog.require('Mixly.FS');
goog.require('Mixly.Debug');
-goog.require('Mixly.MJSON');
+goog.require('Mixly.MJson');
goog.require('Mixly.WebSocket.Ampy');
goog.provide('Mixly.WebSocket.AmpyFS');
@@ -12,7 +12,7 @@ const {
Env,
FS,
Debug,
- MJSON,
+ MJson,
WebSocket
} = Mixly;
@@ -128,7 +128,7 @@ class AmpyFS extends FS {
if (!dirs[i]) {
continue;
}
- stdout.push(MJSON.parse(dirs[i].replaceAll('\'', '"')));
+ stdout.push(MJson.parse(dirs[i].replaceAll('\'', '"')));
}
} catch (e) {
error = e;
diff --git a/common/modules/mixly-modules/web/footerlayer-example.js b/common/modules/mixly-modules/web/footerlayer-example.js
index a869bbe9..75b44f49 100644
--- a/common/modules/mixly-modules/web/footerlayer-example.js
+++ b/common/modules/mixly-modules/web/footerlayer-example.js
@@ -3,7 +3,7 @@ goog.loadJs('web', () => {
goog.require('path');
goog.require('Mixly.Config');
goog.require('Mixly.Env');
-goog.require('Mixly.MJSON');
+goog.require('Mixly.MJson');
goog.require('Mixly.FooterLayerExample');
goog.require('Mixly.Boards');
goog.provide('Mixly.Web.FooterLayerExample');
@@ -12,7 +12,7 @@ const {
Config,
Env,
FooterLayerExample,
- MJSON,
+ MJson,
Boards,
Web
} = Mixly;
@@ -20,7 +20,7 @@ const {
const { BOARD } = Config;
class FooterLayerExampleExt extends FooterLayerExample {
- static DIR_TREE = MJSON.get(path.join(Env.boardDirPath, 'examples/map.json')) ?? [];
+ static DIR_TREE = MJson.get(path.join(Env.boardDirPath, 'examples/map.json')) ?? [];
constructor(element) {
super(element);
diff --git a/mixly-sw/mixly-modules/common/msg.js b/mixly-sw/mixly-modules/common/msg.js
index 54708782..97fab300 100644
--- a/mixly-sw/mixly-modules/common/msg.js
+++ b/mixly-sw/mixly-modules/common/msg.js
@@ -1,10 +1,10 @@
(() => {
-goog.require('Mixly.MJSON');
+goog.require('Mixly.MJson');
goog.require('Mixly.Config');
goog.provide('Mixly.Msg');
-const { Msg, MJSON, Config } = Mixly;
+const { Msg, MJson, Config } = Mixly;
const { USER } = Config;
@@ -15,9 +15,9 @@ Msg.LANG_PATH = {
}
Msg.LANG = {
- "zh-hans": MJSON.get(Msg.LANG_PATH["zh-hans"]),
- "zh-hant": MJSON.get(Msg.LANG_PATH["zh-hant"]),
- "en": MJSON.get(Msg.LANG_PATH["en"])
+ "zh-hans": MJson.get(Msg.LANG_PATH["zh-hans"]),
+ "zh-hant": MJson.get(Msg.LANG_PATH["zh-hant"]),
+ "en": MJson.get(Msg.LANG_PATH["en"])
}
Msg.nowLang = USER.language ?? 'zh-hans';
diff --git a/mixly-sw/mixly-modules/common/setting.js b/mixly-sw/mixly-modules/common/setting.js
index d258ac8f..549b0dfe 100644
--- a/mixly-sw/mixly-modules/common/setting.js
+++ b/mixly-sw/mixly-modules/common/setting.js
@@ -11,7 +11,7 @@ goog.require('Mixly.Msg');
goog.require('Mixly.BoardManager');
goog.require('Mixly.Config');
goog.require('Mixly.Env');
-goog.require('Mixly.MJSON');
+goog.require('Mixly.MJson');
goog.require('Mixly.Storage');
goog.require('Mixly.WebSocket.Socket');
goog.provide('Mixly.Setting');
@@ -23,7 +23,7 @@ const {
BoardManager,
Config,
Env,
- MJSON,
+ MJson,
Storage,
Setting
} = Mixly;
diff --git a/mixly-sw/mixly-modules/deps.json b/mixly-sw/mixly-modules/deps.json
index 825d7a4b..0020e66a 100644
--- a/mixly-sw/mixly-modules/deps.json
+++ b/mixly-sw/mixly-modules/deps.json
@@ -74,7 +74,7 @@
{
"path": "/common/msg.js",
"require": [
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.Config"
],
"provide": [
@@ -95,7 +95,7 @@
"Mixly.BoardManager",
"Mixly.Config",
"Mixly.Env",
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.Storage",
"Mixly.WebSocket.Socket"
],
@@ -130,7 +130,7 @@
"require": [
"Mixly.Env",
"Mixly.Config",
- "Mixly.MJSON",
+ "Mixly.MJson",
"Mixly.WebSocket",
"Mixly.LayerExt",
"Mixly.Command"
diff --git a/mixly-sw/mixly-modules/web-socket/socket.js b/mixly-sw/mixly-modules/web-socket/socket.js
index b453492e..10d8f0e3 100644
--- a/mixly-sw/mixly-modules/web-socket/socket.js
+++ b/mixly-sw/mixly-modules/web-socket/socket.js
@@ -2,7 +2,7 @@
goog.require('Mixly.Env');
goog.require('Mixly.Config');
-goog.require('Mixly.MJSON');
+goog.require('Mixly.MJson');
goog.require('Mixly.WebSocket');
goog.require('Mixly.LayerExt');
goog.require('Mixly.Command');
@@ -11,7 +11,7 @@ goog.provide('Mixly.WebSocket.Socket');
const {
Env,
Config,
- MJSON,
+ MJson,
LayerExt,
Command
} = Mixly;
@@ -130,7 +130,7 @@ Socket.init = (onopenFunc = (data) => {}, doFunc = () => {}) => {
WS.obj.onmessage = (event) => {
heartCheck.reset().start();
let command = Command.parse(event.data);
- command = MJSON.decode(command);
+ command = MJson.decode(command);
if (Socket.debug)
console.log('receive -> ', event.data);
Command.run(command);
@@ -170,7 +170,7 @@ Socket.sendCommand = (command) => {
let commandStr = '';
try {
- commandStr = JSON.stringify(MJSON.encode(command));
+ commandStr = JSON.stringify(MJson.encode(command));
if (Socket.debug)
console.log('send -> ', commandStr);
} catch (e) {