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.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) => {

View File

@@ -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 += `<config>${MJSON.stringify(config)}</config>`;
xml += `<config>${MJson.stringify(config)}</config>`;
}
xml += `<code>${Base64.encode(code)}</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);

View File

@@ -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);
}
});

View File

@@ -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';

View File

@@ -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": [

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);