Files
FOF-ACE-Editor/js/plugins.js
2025-08-16 16:14:03 +08:00

123 lines
4.8 KiB
JavaScript

/*
* @Author: Qiang 1841747216@qq.com
* @Date: 2025-07-15 15:35:09
* @LastEditors: Qiang 1841747216@qq.com
* @LastEditTime: 2025-08-14 20:02:14
* @FilePath: \编辑器\AceEditor\js\plugins.js
* @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
*/
define(['ace/ext-tern'], function () {
// 第三方插件
TernServer = ace.require("ace/ext/tern").tern_server;
// 这里加载第三方插件
setTimeout(() => {
TernServer.addDefs("lib/tern/defs/layui.json", false)
TernServer.addDefs("lib/tern/defs/jquery.json", false)
}, 1000);
// 加载html+css提示
function selectFile(url, callback) {
console.log(url)
fetch(url)
.then(response => response.json())
.then(data => {
if (data != "404-请求文件不存在") {
callback(data)
}
})
.catch(error => {
console.log('请求错误:', error);
});
}
function getSnippet(data, type) {
let snippetJson = []
data['children'] && data['children'].forEach((v, k) => {
// 判断是否放入提示器
let meta = v.type || '';
snippetJson.push({
"id": v.id,
"p_name": v.p_name || '',
"p_snippet": v.p_name || '',
"type": v.nameType || '',
"title": v.title || '',
"title_en": v.title_en || '',
"name": v.name || v.title,
"body": v.body || v.title,
"href": v.href,
"className": v.ClassName || "",
"static": v.T_static,
"description": v.usage,
"scope": type,
"returnText": v.ReturnText || '',
"returnClass": v.ReturnClass || '',
"parameter": v.parameter || '',
"codeType": v.CodeType || 'html',
"T_prototype": v.T_prototype || "2",
"meta": meta,
"score": v.score || 100000,
"IfType": v.T_IfType || 0,
"values": v.valuess ? true : false,
"explain": v.explain || ''
});
if (v.children && v.children.length > 0) {
snippetJson = [...snippetJson, ...getSnippet(v, type)];
}
});
return snippetJson;
}
function loadHtmlCss(address, type) {
selectFile(address, (data) => {
SnippetManager.register(getSnippet(data, type), type);
});
}
function addClassData(address) {
selectFile(address, (data) => {
if (data) {
if (data.component) {
data.component.forEach((v, k) => {
v.code.forEach((v2, k2) => {
if (v2.tyle === "类名") {
v2.code = '.' + v2.code;
v2.code_en = '.' + v2.code_en;
v2.title = '.' + v2.title;
}
if (/[\u4E00-\u9FA5]/.test(v2.code)) {
v2.caption = pinyin_transliteration(v2.code) + '|' + v2.code_en;
} else {
v2.caption = v2.code + '|' + v2.code_en;
}
v2.content = v2.title;
v2.id = v2.ID;
v2.tabTrigger = v.title;
v2.meta = v2.tyle === "类名" ? "class" : "attr";
v2.score = v2.score || 2000;
v2.description = v2.usage;
let children = [];
if (v2.sub && v2.sub.length > 0) {
v2.sub.forEach(v => {
children.push({
"id": v.ID,
"title": v.code,
"title_en": v.code_en,
"usage": v2.usage,
"explain": v2.explain,
"type": "attr"
});
});
}
})
SnippetManager.register(v.code, "css");
});
}
}
});
}
// 加载html和css提示
loadHtmlCss("/library/html/htmljc.json", "html");
loadHtmlCss("/library/css/cssjc.json", "css");
// 加载layui类名
addClassData("/library/Class/layui.json");
return {
}
});