Skip to content

Commit c56d600

Browse files
committed
Package ace editor with addon (no CDN/external JS)
1 parent cdbf6b1 commit c56d600

17 files changed

+792
-522
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ For now, the all modules are currently locked away behind only a usergroup == su
5757
- [Meta Construct](https://github.com/Metastruct "Meta Construct")
5858
- GLua mode for Ace Editor
5959
- [Phoenixf](https://github.com/phoen1xf/ "Phoenixf")
60-
- Hosting the Ace Editor glua mode & being an awesome friend <3
60+
- Being an awesome friend <3

js/mode-glua.js

Lines changed: 0 additions & 505 deletions
This file was deleted.

lua/autorun/blobsprofiler_autorun.lua

Lines changed: 47 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,24 @@ end
2020

2121
MsgN("- blobsProfiler initializing files -")
2222

23-
local function incFile(path, CL, SV)
23+
local function incFile(fileData)
24+
local CL = fileData.CL or false
25+
local SV = fileData.SV or false
26+
local filePath = fileData.File or error("blobsProfiler: Failed to load file no .File provided!")
27+
2428
if SV && SERVER && !CL then
25-
print("[blobsProfiler] SV Load: " .. path)
26-
include("blobsprofiler/" .. path)
29+
print("[blobsProfiler] SV Load: " .. filePath)
30+
include("blobsprofiler/" .. filePath)
2731
else
2832
if SERVER then
29-
print("[blobsProfiler] " .. (SV && "SH" || "CL") .. " DL: " .. path)
30-
AddCSLuaFile("blobsprofiler/" .. path)
33+
print("[blobsProfiler] " .. (SV && "SH" || "CL") .. " DL: " .. filePath)
34+
AddCSLuaFile("blobsprofiler/" .. filePath)
3135
end
3236

3337
if (SV && CL) || (CL && CLIENT) then
34-
print("[blobsProfiler] " .. (SV && "SH" || "CL") .. " Load: " .. path)
35-
include("blobsprofiler/" .. path)
38+
print("[blobsProfiler] " .. (SV && "SH" || "CL") .. " Load: " .. filePath)
39+
if CLIENT and fileData.CL_NoInclude then print("[blobsProfiler] " .. (SV && "SH" || "CL") .. " CL_NoInclude: " .. filePath) return end
40+
include("blobsprofiler/" .. filePath)
3641
end
3742
end
3843
end
@@ -77,12 +82,12 @@ blobsProfiler.FileList = {
7782
{
7883
File = "server/sv_blobsprofiler.lua",
7984
SV = true,
80-
},
85+
}
8186
}
8287

8388
blobsProfiler.LoadFiles = function()
84-
for _, fileList in ipairs(blobsProfiler.FileList) do
85-
incFile(fileList.File, fileList.CL, fileList.SV)
89+
for _, fileData in ipairs(blobsProfiler.FileList) do
90+
incFile(fileData)
8691
end
8792
end
8893

@@ -101,4 +106,35 @@ blobsProfiler.LoadModules = function()
101106
end
102107
end
103108

104-
blobsProfiler.LoadModules()
109+
blobsProfiler.LoadModules()
110+
111+
local JSFiles = {
112+
{ FileName = "ace", Parts = 8 },
113+
{ FileName = "mode-sql" },
114+
{ FileName = "mode-glua", Parts = 4}
115+
}
116+
117+
blobsProfiler.JSFileData = blobsProfiler.JSFileData or {}
118+
119+
blobsProfiler.LoadJSFiles = function()
120+
for _, JSFile in ipairs(JSFiles) do
121+
local basePath = "blobsProfiler/client/js/" .. JSFile.FileName
122+
local partCount = JSFile.Parts or 1
123+
local parts = {}
124+
125+
for i = 1, partCount do
126+
local filePath = basePath .. (partCount > 1 and i or "") .. ".js.lua"
127+
if SERVER then
128+
AddCSLuaFile(filePath)
129+
else
130+
parts[i] = include(filePath)
131+
end
132+
end
133+
134+
if not SERVER then
135+
blobsProfiler.JSFileData[JSFile.FileName] = table.concat(parts)
136+
end
137+
end
138+
end
139+
140+
blobsProfiler.LoadJSFiles()

lua/blobsprofiler/client/cl_blobsprofiler.lua

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -113,9 +113,11 @@ blobsProfiler.generateAceEditorPanel = function(parentPanel, content, editorMode
113113
content = content or [[print("Hello world!")]]
114114
editorMode = editorMode or "Lua"
115115
local useMode = "ace/mode/glua"
116+
local useModeFile = "mode-glua"
116117

117118
if editorMode == "SQL" then
118119
useMode = "ace/mode/sql"
120+
useModeFile = "mode-sql"
119121
end
120122

121123
dhtmlPanel:SetHTML([[
@@ -133,15 +135,12 @@ blobsProfiler.generateAceEditorPanel = function(parentPanel, content, editorMode
133135
</head>
134136
<body>
135137
<div id="editor">]].. content ..[[</div>
136-
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.13/ace.js" type="text/javascript" charset="utf-8"></script>
137-
<script src="https://cdn.hbn.gg/thirdparty/mode-glua.js" type="text/javascript"></script>
138+
<script>]].. blobsProfiler.JSFileData["ace"] ..[[</script>
139+
<script>]].. blobsProfiler.JSFileData[useModeFile] ..[[</script>
138140
<script>
139141
var editor = ace.edit("editor");
140142
editor.session.setMode("]].. useMode ..[[");
141143
editor.setOptions({
142-
enableBasicAutocompletion: true,
143-
enableSnippets: true,
144-
enableLiveAutocompletion: true,
145144
showLineNumbers: true,
146145
tabSize: 2
147146
});
@@ -1178,6 +1177,7 @@ concommand.Add("blobsprofiler", function(ply, cmd, args, argStr)
11781177
subPropertySheetText = " - " .. subActiveTab:GetText()
11791178
end
11801179
blobsProfiler.Menu.MenuFrame:SetTitle("blobsProfiler - " .. blobsProfiler.Menu.selectedRealm .. subPropertySheetText)
1180+
if not subActiveTab then return end
11811181

11821182
if blobsProfiler.Modules[subActiveTab:GetText()] and firstSubModule[subActiveTab:GetText()] then
11831183
if pnlNew:GetText() == "Server" and firstSubModule[subActiveTab:GetText()].data.UpdateRealmData then

lua/blobsprofiler/client/js/ace1.js.lua

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/ace2.js.lua

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/ace3.js.lua

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/ace4.js.lua

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/ace5.js.lua

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/ace6.js.lua

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/ace7.js.lua

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/ace8.js.lua

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/mode-glua1.js.lua

Lines changed: 11 additions & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/mode-glua2.js.lua

Lines changed: 5 additions & 0 deletions
Large diffs are not rendered by default.

lua/blobsprofiler/client/js/mode-glua3.js.lua

Lines changed: 451 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
return [==[ var tokens = this.getTokenizer().getLineTokens(line.trim(), state).tokens;
2+
3+
if (!tokens || !tokens.length)
4+
return false;
5+
6+
return (tokens[0].type == "keyword" && outdentKeywords.indexOf(tokens[0].value) != -1);
7+
};
8+
9+
this.autoOutdent = function(state, session, row) {
10+
var prevLine = session.getLine(row - 1);
11+
var prevIndent = this.$getIndent(prevLine).length;
12+
var prevTokens = this.getTokenizer().getLineTokens(prevLine, "start").tokens;
13+
var tabLength = session.getTabString().length;
14+
var expectedIndent = prevIndent + tabLength * getNetIndentLevel(prevTokens);
15+
var curIndent = this.$getIndent(session.getLine(row)).length;
16+
if (curIndent < expectedIndent) {
17+
return;
18+
}
19+
session.outdentRows(new Range(row, 0, row + 2, 0));
20+
};
21+
this.createWorker = function(session) {
22+
var worker = new WorkerClient(["ace"], "ace/mode/glua_worker", "Worker");
23+
worker.attachToDocument(session.getDocument());
24+
25+
return worker;
26+
};
27+
28+
this.$id = "ace/mode/glua";
29+
30+
this.completer = {
31+
"getCompletions":function(state, session, pos, prefix, cb) {
32+
var completions = session.$mode.getCompletions(state, session, pos, prefix);
33+
cb(null, completions);
34+
}, "identifierRegexps":Array( ID_REGEX, ID_REGEX2 )
35+
};
36+
37+
}).call(Mode.prototype);
38+
39+
exports.Mode = Mode;
40+
});
41+
]==]
Lines changed: 223 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,223 @@
1+
return [==[
2+
define("ace/mode/sql_highlight_rules",["require","exports","module","ace/lib/oop","ace/mode/text_highlight_rules"], function(require, exports, module){"use strict";
3+
var oop = require("../lib/oop");
4+
var TextHighlightRules = require("./text_highlight_rules").TextHighlightRules;
5+
var SqlHighlightRules = function () {
6+
var keywords = ("select|insert|update|delete|from|where|and|or|group|by|order|limit|offset|having|as|case|" +
7+
"when|then|else|end|type|left|right|join|on|outer|desc|asc|union|create|table|primary|key|if|" +
8+
"foreign|not|references|default|null|inner|cross|natural|database|drop|grant|distinct|is|in|" +
9+
"all|alter|any|array|at|authorization|between|both|cast|check|collate|column|commit|constraint|" +
10+
"cube|current|current_date|current_time|current_timestamp|current_user|describe|escape|except|" +
11+
"exists|external|extract|fetch|filter|for|full|function|global|grouping|intersect|interval|" +
12+
"into|leading|like|local|no|of|only|out|overlaps|partition|position|range|revoke|rollback|rollup|" +
13+
"row|rows|session_user|set|some|start|tablesample|time|to|trailing|truncate|unique|unknown|" +
14+
"user|using|values|window|with");
15+
var builtinConstants = ("true|false");
16+
var builtinFunctions = ("avg|count|first|last|max|min|sum|ucase|lcase|mid|len|round|rank|now|format|" +
17+
"coalesce|ifnull|isnull|nvl");
18+
var dataTypes = ("int|numeric|decimal|date|varchar|char|bigint|float|double|bit|binary|text|set|timestamp|" +
19+
"money|real|number|integer|string");
20+
var keywordMapper = this.createKeywordMapper({
21+
"support.function": builtinFunctions,
22+
"keyword": keywords,
23+
"constant.language": builtinConstants,
24+
"storage.type": dataTypes
25+
}, "identifier", true);
26+
this.$rules = {
27+
"start": [{
28+
token: "comment",
29+
regex: "--.*$"
30+
}, {
31+
token: "comment",
32+
start: "/\\*",
33+
end: "\\*/"
34+
}, {
35+
token: "string", // " string
36+
regex: '".*?"'
37+
}, {
38+
token: "string", // ' string
39+
regex: "'.*?'"
40+
}, {
41+
token: "string", // ` string (apache drill)
42+
regex: "`.*?`"
43+
}, {
44+
token: "constant.numeric", // float
45+
regex: "[+-]?\\d+(?:(?:\\.\\d*)?(?:[eE][+-]?\\d+)?)?\\b"
46+
}, {
47+
token: keywordMapper,
48+
regex: "[a-zA-Z_$][a-zA-Z0-9_$]*\\b"
49+
}, {
50+
token: "keyword.operator",
51+
regex: "\\+|\\-|\\/|\\/\\/|%|<@>|@>|<@|&|\\^|~|<|>|<=|=>|==|!=|<>|="
52+
}, {
53+
token: "paren.lparen",
54+
regex: "[\\(]"
55+
}, {
56+
token: "paren.rparen",
57+
regex: "[\\)]"
58+
}, {
59+
token: "text",
60+
regex: "\\s+"
61+
}]
62+
};
63+
this.normalizeRules();
64+
};
65+
oop.inherits(SqlHighlightRules, TextHighlightRules);
66+
exports.SqlHighlightRules = SqlHighlightRules;
67+
68+
});
69+
70+
define("ace/mode/folding/cstyle",["require","exports","module","ace/lib/oop","ace/range","ace/mode/folding/fold_mode"], function(require, exports, module){"use strict";
71+
var oop = require("../../lib/oop");
72+
var Range = require("../../range").Range;
73+
var BaseFoldMode = require("./fold_mode").FoldMode;
74+
var FoldMode = exports.FoldMode = function (commentRegex) {
75+
if (commentRegex) {
76+
this.foldingStartMarker = new RegExp(this.foldingStartMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.start));
77+
this.foldingStopMarker = new RegExp(this.foldingStopMarker.source.replace(/\|[^|]*?$/, "|" + commentRegex.end));
78+
}
79+
};
80+
oop.inherits(FoldMode, BaseFoldMode);
81+
(function () {
82+
this.foldingStartMarker = /([\{\[\(])[^\}\]\)]*$|^\s*(\/\*)/;
83+
this.foldingStopMarker = /^[^\[\{\(]*([\}\]\)])|^[\s\*]*(\*\/)/;
84+
this.singleLineBlockCommentRe = /^\s*(\/\*).*\*\/\s*$/;
85+
this.tripleStarBlockCommentRe = /^\s*(\/\*\*\*).*\*\/\s*$/;
86+
this.startRegionRe = /^\s*(\/\*|\/\/)#?region\b/;
87+
this._getFoldWidgetBase = this.getFoldWidget;
88+
this.getFoldWidget = function (session, foldStyle, row) {
89+
var line = session.getLine(row);
90+
if (this.singleLineBlockCommentRe.test(line)) {
91+
if (!this.startRegionRe.test(line) && !this.tripleStarBlockCommentRe.test(line))
92+
return "";
93+
}
94+
var fw = this._getFoldWidgetBase(session, foldStyle, row);
95+
if (!fw && this.startRegionRe.test(line))
96+
return "start"; // lineCommentRegionStart
97+
return fw;
98+
};
99+
this.getFoldWidgetRange = function (session, foldStyle, row, forceMultiline) {
100+
var line = session.getLine(row);
101+
if (this.startRegionRe.test(line))
102+
return this.getCommentRegionBlock(session, line, row);
103+
var match = line.match(this.foldingStartMarker);
104+
if (match) {
105+
var i = match.index;
106+
if (match[1])
107+
return this.openingBracketBlock(session, match[1], row, i);
108+
var range = session.getCommentFoldRange(row, i + match[0].length, 1);
109+
if (range && !range.isMultiLine()) {
110+
if (forceMultiline) {
111+
range = this.getSectionRange(session, row);
112+
}
113+
else if (foldStyle != "all")
114+
range = null;
115+
}
116+
return range;
117+
}
118+
if (foldStyle === "markbegin")
119+
return;
120+
var match = line.match(this.foldingStopMarker);
121+
if (match) {
122+
var i = match.index + match[0].length;
123+
if (match[1])
124+
return this.closingBracketBlock(session, match[1], row, i);
125+
return session.getCommentFoldRange(row, i, -1);
126+
}
127+
};
128+
this.getSectionRange = function (session, row) {
129+
var line = session.getLine(row);
130+
var startIndent = line.search(/\S/);
131+
var startRow = row;
132+
var startColumn = line.length;
133+
row = row + 1;
134+
var endRow = row;
135+
var maxRow = session.getLength();
136+
while (++row < maxRow) {
137+
line = session.getLine(row);
138+
var indent = line.search(/\S/);
139+
if (indent === -1)
140+
continue;
141+
if (startIndent > indent)
142+
break;
143+
var subRange = this.getFoldWidgetRange(session, "all", row);
144+
if (subRange) {
145+
if (subRange.start.row <= startRow) {
146+
break;
147+
}
148+
else if (subRange.isMultiLine()) {
149+
row = subRange.end.row;
150+
}
151+
else if (startIndent == indent) {
152+
break;
153+
}
154+
}
155+
endRow = row;
156+
}
157+
return new Range(startRow, startColumn, endRow, session.getLine(endRow).length);
158+
};
159+
this.getCommentRegionBlock = function (session, line, row) {
160+
var startColumn = line.search(/\s*$/);
161+
var maxRow = session.getLength();
162+
var startRow = row;
163+
var re = /^\s*(?:\/\*|\/\/|--)#?(end)?region\b/;
164+
var depth = 1;
165+
while (++row < maxRow) {
166+
line = session.getLine(row);
167+
var m = re.exec(line);
168+
if (!m)
169+
continue;
170+
if (m[1])
171+
depth--;
172+
else
173+
depth++;
174+
if (!depth)
175+
break;
176+
}
177+
var endRow = row;
178+
if (endRow > startRow) {
179+
return new Range(startRow, startColumn, endRow, line.length);
180+
}
181+
};
182+
}).call(FoldMode.prototype);
183+
184+
});
185+
186+
define("ace/mode/folding/sql",["require","exports","module","ace/lib/oop","ace/mode/folding/cstyle"], function(require, exports, module){"use strict";
187+
var oop = require("../../lib/oop");
188+
var BaseFoldMode = require("./cstyle").FoldMode;
189+
var FoldMode = exports.FoldMode = function () { };
190+
oop.inherits(FoldMode, BaseFoldMode);
191+
(function () {
192+
}).call(FoldMode.prototype);
193+
194+
});
195+
196+
define("ace/mode/sql",["require","exports","module","ace/lib/oop","ace/mode/text","ace/mode/sql_highlight_rules","ace/mode/folding/sql"], function(require, exports, module){"use strict";
197+
var oop = require("../lib/oop");
198+
var TextMode = require("./text").Mode;
199+
var SqlHighlightRules = require("./sql_highlight_rules").SqlHighlightRules;
200+
var SqlFoldMode = require("./folding/sql").FoldMode;
201+
var Mode = function () {
202+
this.HighlightRules = SqlHighlightRules;
203+
this.foldingRules = new SqlFoldMode();
204+
this.$behaviour = this.$defaultBehaviour;
205+
};
206+
oop.inherits(Mode, TextMode);
207+
(function () {
208+
this.lineCommentStart = "--";
209+
this.blockComment = { start: "/*", end: "*/" };
210+
this.$id = "ace/mode/sql";
211+
this.snippetFileId = "ace/snippets/sql";
212+
}).call(Mode.prototype);
213+
exports.Mode = Mode;
214+
215+
}); (function() {
216+
window.require(["ace/mode/sql"], function(m) {
217+
if (typeof module == "object" && typeof exports == "object" && module) {
218+
module.exports = m;
219+
}
220+
});
221+
})();
222+
223+
]==]

0 commit comments

Comments
 (0)