feat(core): 将Mixly.MJSON调整为Mixly.MJson

This commit is contained in:
王立帮
2025-04-27 15:49:16 +08:00
parent 291667cccf
commit d04ec7bfc7
13 changed files with 76 additions and 59 deletions

View File

@@ -1,14 +1,14 @@
goog.loadJs('common', () => { goog.loadJs('common', () => {
goog.require('Mixly.Config'); goog.require('Mixly.Config');
goog.require('Mixly.MJSON') goog.require('Mixly.MJson')
goog.require('Mixly.Debug'); goog.require('Mixly.Debug');
goog.provide('Mixly.Command'); goog.provide('Mixly.Command');
const { const {
Config, Config,
Command, Command,
MJSON, MJson,
Debug Debug
} = Mixly; } = Mixly;
@@ -21,7 +21,7 @@ Command.DEFAULT = {
} }
Command.parse = (commandStr) => { Command.parse = (commandStr) => {
return MJSON.decode(MJSON.parse(commandStr)); return MJson.decode(MJson.parse(commandStr));
} }
Command.run = (commandObj) => { Command.run = (commandObj) => {

View File

@@ -15,7 +15,7 @@ goog.require('Mixly.ContextMenu');
goog.require('Mixly.Debug'); goog.require('Mixly.Debug');
goog.require('Mixly.Menu'); goog.require('Mixly.Menu');
goog.require('Mixly.Boards'); goog.require('Mixly.Boards');
goog.require('Mixly.MJSON'); goog.require('Mixly.MJson');
goog.require('Mixly.HTMLTemplate'); goog.require('Mixly.HTMLTemplate');
goog.require('Mixly.EditorBlockly'); goog.require('Mixly.EditorBlockly');
goog.require('Mixly.EditorCode'); goog.require('Mixly.EditorCode');
@@ -37,7 +37,7 @@ const {
Debug, Debug,
Menu, Menu,
Boards, Boards,
MJSON, MJson,
HTMLTemplate, HTMLTemplate,
LayerExt LayerExt
} = Mixly; } = Mixly;
@@ -436,7 +436,7 @@ class EditorMix extends EditorBase {
} }
xml = $xml[0].outerHTML; xml = $xml[0].outerHTML;
if (config) { if (config) {
xml += `<config>${MJSON.stringify(config)}</config>`; xml += `<config>${MJson.stringify(config)}</config>`;
} }
xml += `<code>${Base64.encode(code)}</code>`; xml += `<code>${Base64.encode(code)}</code>`;
return xml; return xml;
@@ -523,7 +523,7 @@ class EditorMix extends EditorBase {
} }
} }
let config, configStr = configDom && configDom.html(); let config, configStr = configDom && configDom.html();
config = configStr? MJSON.parse(configStr) : {}; config = configStr? MJson.parse(configStr) : {};
let boardName = xmlDom.attr('board') ?? ''; let boardName = xmlDom.attr('board') ?? '';
blockPage.getEditor().clear(); blockPage.getEditor().clear();
Boards.setSelectedBoard(boardName, config); Boards.setSelectedBoard(boardName, config);

View File

@@ -1,17 +1,17 @@
goog.loadJs('common', () => { goog.loadJs('common', () => {
goog.require('Mixly.Debug'); 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) { for (var key in jsonObj) {
//如果对象类型为object类型且数组长度大于0 或者 是对象 ,继续递归解析 //如果对象类型为object类型且数组长度大于0 或者 是对象 ,继续递归解析
var element = jsonObj[key]; var element = jsonObj[key];
if (element.length > 0 && typeof (element) == "object" || typeof (element) == "object") { 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) { for (let i in data) {
jsonObj[key][i] = data[i]; jsonObj[key][i] = data[i];
} }
@@ -28,19 +28,19 @@ MJSON.operate = (jsonObj, optFunc) => {
return jsonObj; return jsonObj;
} }
MJSON.decode = (jsonObj) => { MJson.decode = (jsonObj) => {
// 深度拷贝对象,防止解码或编码时篡改原有对象 // 深度拷贝对象,防止解码或编码时篡改原有对象
let newJsonObj = structuredClone(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); let newJsonObj = structuredClone(jsonObj);
return MJSON.operate(newJsonObj, encodeURIComponent);; return MJson.operate(newJsonObj, encodeURIComponent);;
} }
MJSON.parse = (jsonStr) => { MJson.parse = (jsonStr) => {
let jsonObj = null; let jsonObj = null;
try { try {
jsonStr = jsonStr.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m); jsonStr = jsonStr.replace(/\\"|"(?:\\"|[^"])*"|(\/\/.*|\/\*[\s\S]*?\*\/)/g, (m, g) => g ? "" : m);
@@ -51,7 +51,7 @@ MJSON.parse = (jsonStr) => {
return jsonObj; return jsonObj;
} }
MJSON.stringify = (jsonObj) => { MJson.stringify = (jsonObj) => {
let jsonStr = ''; let jsonStr = '';
try { try {
jsonStr = JSON.stringify(jsonObj); jsonStr = JSON.stringify(jsonObj);
@@ -61,8 +61,8 @@ MJSON.stringify = (jsonObj) => {
return jsonStr; return jsonStr;
} }
MJSON.get = (inPath) => { MJson.get = (inPath) => {
return goog.getJSON(inPath); return goog.readJsonSync(inPath);
} }
}); });

View File

@@ -1,7 +1,7 @@
goog.loadJs('common', () => { goog.loadJs('common', () => {
goog.require('path'); goog.require('path');
goog.require('Mixly.MJSON'); goog.require('Mixly.MJson');
goog.require('Mixly.Config'); goog.require('Mixly.Config');
goog.require('Mixly.Env'); goog.require('Mixly.Env');
goog.require('Blockly'); goog.require('Blockly');
@@ -12,7 +12,7 @@ goog.provide('Mixly.Msg');
const { const {
Msg, Msg,
MJSON, MJson,
Config, Config,
Env Env
} = Mixly; } = Mixly;
@@ -32,9 +32,9 @@ Msg.PATH = {
} }
Msg.LANG = { Msg.LANG = {
"zh-hans": MJSON.get(Msg.PATH["zh-hans"]), "zh-hans": MJson.get(Msg.PATH["zh-hans"]),
"zh-hant": MJSON.get(Msg.PATH["zh-hant"]), "zh-hant": MJson.get(Msg.PATH["zh-hant"]),
"en": MJSON.get(Msg.PATH["en"]) "en": MJson.get(Msg.PATH["en"])
} }
Msg.nowLang = USER.language ?? 'zh-hans'; Msg.nowLang = USER.language ?? 'zh-hans';

View File

@@ -112,7 +112,7 @@
"path": "/common/command.js", "path": "/common/command.js",
"require": [ "require": [
"Mixly.Config", "Mixly.Config",
"Mixly.MJSON", "Mixly.MJson",
"Mixly.Debug" "Mixly.Debug"
], ],
"provide": [ "provide": [
@@ -309,7 +309,7 @@
"Mixly.Debug", "Mixly.Debug",
"Mixly.Menu", "Mixly.Menu",
"Mixly.Boards", "Mixly.Boards",
"Mixly.MJSON", "Mixly.MJson",
"Mixly.HTMLTemplate", "Mixly.HTMLTemplate",
"Mixly.EditorBlockly", "Mixly.EditorBlockly",
"Mixly.EditorCode", "Mixly.EditorCode",
@@ -597,10 +597,25 @@
"Mixly.LayerExt" "Mixly.LayerExt"
] ]
}, },
{
"path": "/common/layer-progress.js",
"require": [
"Mixly.Env",
"Mixly.Layer",
"Mixly.HTMLTemplate"
],
"provide": [
"Mixly.LayerProgress"
]
},
{ {
"path": "/common/layer.js", "path": "/common/layer.js",
"require": [ "require": [
"Mixly.Registry" "dialog",
"Mixly.Env",
"Mixly.Registry",
"Mixly.Component",
"Mixly.HTMLTemplate"
], ],
"provide": [ "provide": [
"Mixly.Layer" "Mixly.Layer"
@@ -712,14 +727,14 @@
"Mixly.Debug" "Mixly.Debug"
], ],
"provide": [ "provide": [
"Mixly.MJSON" "Mixly.MJson"
] ]
}, },
{ {
"path": "/common/msg.js", "path": "/common/msg.js",
"require": [ "require": [
"path", "path",
"Mixly.MJSON", "Mixly.MJson",
"Mixly.Config", "Mixly.Config",
"Mixly.Env", "Mixly.Env",
"Blockly", "Blockly",
@@ -1210,7 +1225,7 @@
"Mixly.Env", "Mixly.Env",
"Mixly.FS", "Mixly.FS",
"Mixly.Debug", "Mixly.Debug",
"Mixly.MJSON", "Mixly.MJson",
"Mixly.Electron.Ampy" "Mixly.Electron.Ampy"
], ],
"provide": [ "provide": [
@@ -1279,7 +1294,7 @@
"require": [ "require": [
"path", "path",
"Mixly.Env", "Mixly.Env",
"Mixly.MJSON", "Mixly.MJson",
"Mixly.Electron" "Mixly.Electron"
], ],
"provide": [ "provide": [
@@ -1584,7 +1599,7 @@
"path", "path",
"Mixly.Config", "Mixly.Config",
"Mixly.Env", "Mixly.Env",
"Mixly.MJSON", "Mixly.MJson",
"Mixly.FooterLayerExample", "Mixly.FooterLayerExample",
"Mixly.Boards" "Mixly.Boards"
], ],
@@ -1720,7 +1735,7 @@
"Mixly.Env", "Mixly.Env",
"Mixly.FS", "Mixly.FS",
"Mixly.Debug", "Mixly.Debug",
"Mixly.MJSON", "Mixly.MJson",
"Mixly.WebSocket.Ampy" "Mixly.WebSocket.Ampy"
], ],
"provide": [ "provide": [
@@ -1751,6 +1766,7 @@
"Mixly.LayerExt", "Mixly.LayerExt",
"Mixly.Msg", "Mixly.Msg",
"Mixly.Workspace", "Mixly.Workspace",
"Mixly.LayerProgress",
"Mixly.WebSocket.Serial" "Mixly.WebSocket.Serial"
], ],
"provide": [ "provide": [
@@ -1770,6 +1786,7 @@
"Mixly.Config", "Mixly.Config",
"Mixly.Workspace", "Mixly.Workspace",
"Mixly.MString", "Mixly.MString",
"Mixly.LayerProgress",
"Mixly.WebSocket.Serial" "Mixly.WebSocket.Serial"
], ],
"provide": [ "provide": [

View File

@@ -4,7 +4,7 @@ goog.require('path');
goog.require('Mixly.Env'); goog.require('Mixly.Env');
goog.require('Mixly.FS'); goog.require('Mixly.FS');
goog.require('Mixly.Debug'); goog.require('Mixly.Debug');
goog.require('Mixly.MJSON'); goog.require('Mixly.MJson');
goog.require('Mixly.Electron.Ampy'); goog.require('Mixly.Electron.Ampy');
goog.provide('Mixly.Electron.AmpyFS'); goog.provide('Mixly.Electron.AmpyFS');
@@ -12,7 +12,7 @@ const {
Env, Env,
FS, FS,
Debug, Debug,
MJSON, MJson,
Electron Electron
} = Mixly; } = Mixly;
const { Ampy } = Electron; const { Ampy } = Electron;
@@ -136,7 +136,7 @@ class AmpyFS extends FS {
if (!dirs[i]) { if (!dirs[i]) {
continue; continue;
} }
stdout.push(MJSON.parse(dirs[i].replaceAll('\'', '"'))); stdout.push(MJson.parse(dirs[i].replaceAll('\'', '"')));
} }
} catch (e) { } catch (e) {
error = e; error = e;

View File

@@ -2,13 +2,13 @@ goog.loadJs('electron', () => {
goog.require('path'); goog.require('path');
goog.require('Mixly.Env'); goog.require('Mixly.Env');
goog.require('Mixly.MJSON'); goog.require('Mixly.MJson');
goog.require('Mixly.Electron'); goog.require('Mixly.Electron');
goog.provide('Mixly.Electron.CloudDownload'); goog.provide('Mixly.Electron.CloudDownload');
const { const {
Env, Env,
MJSON, MJson,
Electron Electron
} = Mixly; } = Mixly;
@@ -29,7 +29,7 @@ CloudDownload.getJson = (url, downloadDir, endFunc) => {
let jsonObj = null; let jsonObj = null;
if (fs_plus.isFileSync(message[1])) { if (fs_plus.isFileSync(message[1])) {
let data = fs.readFileSync(message[1], 'utf-8'); let data = fs.readFileSync(message[1], 'utf-8');
jsonObj = MJSON.parse(data); jsonObj = MJson.parse(data);
} }
if (jsonObj) { if (jsonObj) {
return jsonObj; return jsonObj;

View File

@@ -4,7 +4,7 @@ goog.require('path');
goog.require('Mixly.Env'); goog.require('Mixly.Env');
goog.require('Mixly.FS'); goog.require('Mixly.FS');
goog.require('Mixly.Debug'); goog.require('Mixly.Debug');
goog.require('Mixly.MJSON'); goog.require('Mixly.MJson');
goog.require('Mixly.WebSocket.Ampy'); goog.require('Mixly.WebSocket.Ampy');
goog.provide('Mixly.WebSocket.AmpyFS'); goog.provide('Mixly.WebSocket.AmpyFS');
@@ -12,7 +12,7 @@ const {
Env, Env,
FS, FS,
Debug, Debug,
MJSON, MJson,
WebSocket WebSocket
} = Mixly; } = Mixly;
@@ -128,7 +128,7 @@ class AmpyFS extends FS {
if (!dirs[i]) { if (!dirs[i]) {
continue; continue;
} }
stdout.push(MJSON.parse(dirs[i].replaceAll('\'', '"'))); stdout.push(MJson.parse(dirs[i].replaceAll('\'', '"')));
} }
} catch (e) { } catch (e) {
error = e; error = e;

View File

@@ -3,7 +3,7 @@ goog.loadJs('web', () => {
goog.require('path'); goog.require('path');
goog.require('Mixly.Config'); goog.require('Mixly.Config');
goog.require('Mixly.Env'); goog.require('Mixly.Env');
goog.require('Mixly.MJSON'); goog.require('Mixly.MJson');
goog.require('Mixly.FooterLayerExample'); goog.require('Mixly.FooterLayerExample');
goog.require('Mixly.Boards'); goog.require('Mixly.Boards');
goog.provide('Mixly.Web.FooterLayerExample'); goog.provide('Mixly.Web.FooterLayerExample');
@@ -12,7 +12,7 @@ const {
Config, Config,
Env, Env,
FooterLayerExample, FooterLayerExample,
MJSON, MJson,
Boards, Boards,
Web Web
} = Mixly; } = Mixly;
@@ -20,7 +20,7 @@ const {
const { BOARD } = Config; const { BOARD } = Config;
class FooterLayerExampleExt extends FooterLayerExample { 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) { constructor(element) {
super(element); super(element);

View File

@@ -1,10 +1,10 @@
(() => { (() => {
goog.require('Mixly.MJSON'); goog.require('Mixly.MJson');
goog.require('Mixly.Config'); goog.require('Mixly.Config');
goog.provide('Mixly.Msg'); goog.provide('Mixly.Msg');
const { Msg, MJSON, Config } = Mixly; const { Msg, MJson, Config } = Mixly;
const { USER } = Config; const { USER } = Config;
@@ -15,9 +15,9 @@ Msg.LANG_PATH = {
} }
Msg.LANG = { Msg.LANG = {
"zh-hans": MJSON.get(Msg.LANG_PATH["zh-hans"]), "zh-hans": MJson.get(Msg.LANG_PATH["zh-hans"]),
"zh-hant": MJSON.get(Msg.LANG_PATH["zh-hant"]), "zh-hant": MJson.get(Msg.LANG_PATH["zh-hant"]),
"en": MJSON.get(Msg.LANG_PATH["en"]) "en": MJson.get(Msg.LANG_PATH["en"])
} }
Msg.nowLang = USER.language ?? 'zh-hans'; Msg.nowLang = USER.language ?? 'zh-hans';

View File

@@ -11,7 +11,7 @@ goog.require('Mixly.Msg');
goog.require('Mixly.BoardManager'); goog.require('Mixly.BoardManager');
goog.require('Mixly.Config'); goog.require('Mixly.Config');
goog.require('Mixly.Env'); goog.require('Mixly.Env');
goog.require('Mixly.MJSON'); goog.require('Mixly.MJson');
goog.require('Mixly.Storage'); goog.require('Mixly.Storage');
goog.require('Mixly.WebSocket.Socket'); goog.require('Mixly.WebSocket.Socket');
goog.provide('Mixly.Setting'); goog.provide('Mixly.Setting');
@@ -23,7 +23,7 @@ const {
BoardManager, BoardManager,
Config, Config,
Env, Env,
MJSON, MJson,
Storage, Storage,
Setting Setting
} = Mixly; } = Mixly;

View File

@@ -74,7 +74,7 @@
{ {
"path": "/common/msg.js", "path": "/common/msg.js",
"require": [ "require": [
"Mixly.MJSON", "Mixly.MJson",
"Mixly.Config" "Mixly.Config"
], ],
"provide": [ "provide": [
@@ -95,7 +95,7 @@
"Mixly.BoardManager", "Mixly.BoardManager",
"Mixly.Config", "Mixly.Config",
"Mixly.Env", "Mixly.Env",
"Mixly.MJSON", "Mixly.MJson",
"Mixly.Storage", "Mixly.Storage",
"Mixly.WebSocket.Socket" "Mixly.WebSocket.Socket"
], ],
@@ -130,7 +130,7 @@
"require": [ "require": [
"Mixly.Env", "Mixly.Env",
"Mixly.Config", "Mixly.Config",
"Mixly.MJSON", "Mixly.MJson",
"Mixly.WebSocket", "Mixly.WebSocket",
"Mixly.LayerExt", "Mixly.LayerExt",
"Mixly.Command" "Mixly.Command"

View File

@@ -2,7 +2,7 @@
goog.require('Mixly.Env'); goog.require('Mixly.Env');
goog.require('Mixly.Config'); goog.require('Mixly.Config');
goog.require('Mixly.MJSON'); goog.require('Mixly.MJson');
goog.require('Mixly.WebSocket'); goog.require('Mixly.WebSocket');
goog.require('Mixly.LayerExt'); goog.require('Mixly.LayerExt');
goog.require('Mixly.Command'); goog.require('Mixly.Command');
@@ -11,7 +11,7 @@ goog.provide('Mixly.WebSocket.Socket');
const { const {
Env, Env,
Config, Config,
MJSON, MJson,
LayerExt, LayerExt,
Command Command
} = Mixly; } = Mixly;
@@ -130,7 +130,7 @@ Socket.init = (onopenFunc = (data) => {}, doFunc = () => {}) => {
WS.obj.onmessage = (event) => { WS.obj.onmessage = (event) => {
heartCheck.reset().start(); heartCheck.reset().start();
let command = Command.parse(event.data); let command = Command.parse(event.data);
command = MJSON.decode(command); command = MJson.decode(command);
if (Socket.debug) if (Socket.debug)
console.log('receive -> ', event.data); console.log('receive -> ', event.data);
Command.run(command); Command.run(command);
@@ -170,7 +170,7 @@ Socket.sendCommand = (command) => {
let commandStr = ''; let commandStr = '';
try { try {
commandStr = JSON.stringify(MJSON.encode(command)); commandStr = JSON.stringify(MJson.encode(command));
if (Socket.debug) if (Socket.debug)
console.log('send -> ', commandStr); console.log('send -> ', commandStr);
} catch (e) { } catch (e) {