feat(core): 将Mixly.MJSON调整为Mixly.MJson
This commit is contained in:
@@ -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) => {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
});
|
||||
@@ -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';
|
||||
|
||||
Reference in New Issue
Block a user