Files
mixly3-server/mixly/common/modules/mixly-modules/web/footerlayer-example.js
2026-01-24 16:12:04 +08:00

87 lines
2.1 KiB
JavaScript

goog.loadJs('web', () => {
goog.require('path');
goog.require('Mixly.Config');
goog.require('Mixly.Env');
goog.require('Mixly.MJson');
goog.require('Mixly.FooterLayerExample');
goog.require('Mixly.Boards');
goog.provide('Mixly.Web.FooterLayerExample');
const {
Config,
Env,
FooterLayerExample,
MJson,
Boards,
Web
} = Mixly;
const { BOARD } = Config;
class FooterLayerExampleExt extends FooterLayerExample {
static DIR_TREE = MJson.get(path.join(Env.boardDirPath, 'examples/map.json')) ?? [];
constructor(element) {
super(element);
}
getRoot() {
const { DIR_TREE } = FooterLayerExampleExt;
let exampleList = [];
if (DIR_TREE instanceof Object) {
exampleList = [{
title: BOARD.boardType,
id: '',
children: []
}];
}
return exampleList;
}
getChildren(inPath) {
const { DIR_TREE } = FooterLayerExampleExt;
let pathList = [];
if (inPath) {
pathList = inPath.split('/');
}
let obj = DIR_TREE;
for (let key of pathList) {
if (!key) {
continue;
}
if (obj[key]) {
obj = obj[key];
} else {
return [];
}
}
if (!(obj instanceof Object)) {
return [];
}
let exampleList = [];
for (let key in obj) {
if (!(obj[key] instanceof Object)) {
continue;
}
const exampleObj = {
title: obj[key]['__name__'],
id: inPath ? (inPath + '/' + key) : key
};
if (!obj[key]['__file__']) {
exampleObj.children = [];
}
exampleList.push(exampleObj);
}
return exampleList;
}
dataToWorkspace(inPath) {
const data = goog.readFileSync(path.join(Env.boardDirPath, 'examples', inPath));
this.updateCode(path.extname(inPath), data);
}
}
Web.FooterLayerExample = FooterLayerExampleExt;
});