igniteui-react-core
Version:
Ignite UI React Core.
275 lines (274 loc) • 11 kB
JavaScript
/*
THIS INFRAGISTICS ULTIMATE SOFTWARE LICENSE AGREEMENT ("AGREEMENT") LOCATED HERE:
https://www.infragistics.com/legal/license/igultimate-la
https://www.infragistics.com/legal/license/igultimate-eula
GOVERNS THE LICENSING, INSTALLATION AND USE OF INFRAGISTICS SOFTWARE. BY DOWNLOADING AND/OR INSTALLING AND USING INFRAGISTICS SOFTWARE: you are indicating that you have read and understand this Agreement, and agree to be legally bound by it on behalf of the yourself and your company.
*/
import { Base, String_$type, typeCast, fromEnum, Number_$type, markType } from "./type";
import { ICodeGenerationRendererTemplate_$type } from "./ICodeGenerationRendererTemplate";
import { List$1 } from "./List$1";
import { JsonDictionaryObject } from "./JsonDictionaryObject";
import { JsonDictionaryArray } from "./JsonDictionaryArray";
import { JsonDictionaryItem } from "./JsonDictionaryItem";
import { JsonDictionaryValue } from "./JsonDictionaryValue";
import { JsonDictionaryParser } from "./JsonDictionaryParser";
import { HashSet$1 } from "./HashSet$1";
import { CodeGeneratingImportManager } from "./CodeGeneratingImportManager";
import { CodeGeneratingRegexHelper } from "./CodeGeneratingRegexHelper";
import { Tuple$3 } from "./Tuple$3";
import { StringBuilder } from "./StringBuilder";
import { stringReplace, stringStartsWith, stringEndsWith } from "./string";
/**
* @hidden
*/
export let CodeGenerationFolderTemplate = /*@__PURE__*/ (() => {
class CodeGenerationFolderTemplate extends Base {
constructor() {
super(...arguments);
this.e = new List$1(String_$type, 0);
this.c = new List$1(String_$type, 0);
this.d = new List$1(String_$type, 0);
}
addFile(a, b) {
this.e.add(a);
this.c.add(b);
}
getFilePaths() {
return this.e.toArray();
}
getFileOuutput(a) {
for (let b = 0; b < this.e.count; b++) {
if (this.e._inner[b] == a) {
return this.d._inner[b];
}
}
return null;
}
b(a, b) {
if (a == null) {
return false;
}
let c = stringReplace(a, "\r\n", "\n").split('\n');
for (let e = 0; e < c.length; e++) {
let d = c[e];
let f = !stringStartsWith(d.trim(), "import") && !stringStartsWith(d.trim(), "@using") && !stringStartsWith(d.trim(), "@inject") && !stringStartsWith(d.trim(), "using");
if (d.trim().length > 0 && (b || f)) {
return true;
}
}
return false;
}
saveTemplateToJson() {
let a = new JsonDictionaryObject();
let b = new JsonDictionaryArray();
let c = new List$1(JsonDictionaryItem.$, 0);
for (let d = 0; d < this.e.count; d++) {
let e = new JsonDictionaryObject();
let f = ((() => {
let $ret = new JsonDictionaryValue();
$ret.e = 2;
$ret.value = this.e._inner[d];
return $ret;
})());
let g = ((() => {
let $ret = new JsonDictionaryValue();
$ret.e = 2;
$ret.value = this.c._inner[d];
return $ret;
})());
e.item("path", f);
e.item("content", g);
c.add(e);
}
b.items = c.toArray();
a.item("files", b);
return a.b();
}
loadTemplateFromJson(a) {
let b = new JsonDictionaryParser();
let c = b.parse(a);
if (typeCast(JsonDictionaryObject.$, c) !== null) {
let d = c;
if (d.g("files")) {
let e = d.item("Files");
if (typeCast(JsonDictionaryArray.$, e) !== null) {
let f = e;
for (let g = 0; g < f.items.length; g++) {
let h = f.items[g];
if (typeCast(JsonDictionaryObject.$, h) !== null) {
let i = h;
if (i.g("path") && i.g("content")) {
this.e.add(i.item("path").value.toString());
this.c.add(i.item("content").value.toString());
}
}
}
}
}
}
}
execute(a) {
this.d.clear();
for (let b = 0; b < this.c.count; b++) {
this.d.add(this.c._inner[b]);
}
let c = a.getKeys();
let d = new HashSet$1(String_$type, 0);
for (let e = 0; e < c.length; e++) {
if (this.b(a.getContentForKey(c[e]), true)) {
d.add_1(c[e]);
}
}
let f = a.getImportsKeys();
for (let g = 0; g < f.length; g++) {
d.add_1(f[g]);
}
let h = a.getStringNames();
for (let i = 0; i < h.length; i++) {
d.add_1(h[i]);
}
let j = a.getPackages();
for (let k = 0; k < j.length; k++) {
d.add_1(j[k]);
}
for (let l = 0; l < this.c.count; l++) {
let m = this.d._inner[l];
m = this.i(m, d);
this.d._inner[l] = m;
}
for (let n = 0; n < this.c.count; n++) {
let o = new List$1(String_$type, 0);
let r = a.getImportsKeys();
for (let q = 0; q < r.length; q++) {
let p = r[q];
o.add(p);
}
let s = this.d._inner[n];
let t = this.e._inner[n];
s = this.k(t, s, o.toArray(), a);
this.d._inner[n] = s;
}
let w = a.getKeys();
for (let v = 0; v < w.length; v++) {
let u = w[v];
for (let x = 0; x < this.c.count; x++) {
let y = this.d._inner[x];
let z = a.getContentForKey(u);
y = this.j(y, u, z, a);
this.d._inner[x] = y;
}
}
let ac = a.getStringNames();
for (let ab = 0; ab < ac.length; ab++) {
let aa = ac[ab];
for (let ad = 0; ad < this.c.count; ad++) {
let ae = this.d._inner[ad];
ae = stringReplace(ae, "$$" + aa, a.getString(aa));
this.d._inner[ad] = ae;
}
}
for (let af of fromEnum(a.getNewFiles())) {
let ag = a.getNewFileContent(af);
let ah = "";
for (let ai of fromEnum(this.e)) {
if (stringStartsWith(ai, "src")) {
ah = "src/";
}
}
this.e.add(ah + af);
this.d.add(ag);
}
}
i(a, b) {
return a;
}
k(a, b, c, d) {
let e = new List$1(Tuple$3.$.specialize(Number_$type, String_$type, CodeGeneratingImportManager.$), 0);
for (let g = 0; g < c.length; g++) {
let f = c[g];
let h = new CodeGeneratingRegexHelper("(?:(<!--)|(\\/\\/))\\s*insert " + f + "(?:(\\s*-->)?)[\\w\\W\\r\\n]*?(?:(<!--)|(\\/\\/))\\s*end " + f + "(?:(\\s*-->)?)((\\r\\n)|(\\n))");
b = h.execute(b, (i, j, k) => {
let l = d.r(f);
let m = new CodeGeneratingImportManager();
for (let n of fromEnum(l)) {
m = CodeGeneratingImportManager.merge(m, n);
}
e.add(new Tuple$3(Number_$type, String_$type, CodeGeneratingImportManager.$, j, f, m));
return null;
});
}
e.aa((i, j) => Base.compareSimple(i.c, j.c));
let i = new CodeGeneratingImportManager();
for (let j of fromEnum(e)) {
let k = j.d;
let l = j.e;
let m = l.removeDuplicates(i);
i = CodeGeneratingImportManager.merge(i, l);
let n = new CodeGeneratingRegexHelper("(?:(<!--)|(\\/\\/))\\s*insert " + k + "(?:(\\s*-->)?)[\\w\\W\\r\\n]*?(?:(<!--)|(\\/\\/))\\s*end " + k + "(?:(\\s*-->)?)((\\r\\n)|(\\n))");
b = n.execute(b, (o, p, q) => {
let r = this.h(a, m, d);
if (r != null && r.length > 0) {
r = this.f(r, b, p, d);
}
return r;
});
}
return b;
}
f(a, b, c, d) {
let e = c;
let f = 0;
let g = 0;
let h = "";
while (e > 0) {
if (b.charAt(e) == ' ') {
h += ' ';
}
if (b.charAt(e) == '\t') {
h += '\t';
}
if (b.charAt(e) == '\n') {
break;
}
e--;
}
let i = new StringBuilder(0);
let j = stringReplace(a, "\r\n", "\n").split('\n');
for (let k = 0; k < j.length; k++) {
if (k == j.length - 1 && j[k].length == 0) {
continue;
}
let l = j[k];
if (k > 0) {
i.l(h);
}
i.u(l);
}
return i.toString();
}
h(a, b, c) {
if (b.hasPackageImports) {
return b.packageImportsToString();
}
else {
let d = false;
if (stringEndsWith(a, ".razor")) {
d = true;
}
return b.usingsToString(d);
}
}
j(a, b, c, d) {
let e = new CodeGeneratingRegexHelper("(?:(<!--)|(\\/\\/))\\s*insert " + b + "(?:(\\s*-->)?)[\\w\\W\\r\\n]*?(?:(<!--)|(\\/\\/))\\s*end " + b + "(?:(\\s*-->)?)((\\r\\n)|(\\n))");
a = e.execute(a, (f, g, h) => {
if (c != null && c.length > 0) {
c = this.f(c, a, g, d);
}
return c;
});
return a;
}
}
CodeGenerationFolderTemplate.$t = /*@__PURE__*/ markType(CodeGenerationFolderTemplate, 'CodeGenerationFolderTemplate', Base.$, [ICodeGenerationRendererTemplate_$type]);
return CodeGenerationFolderTemplate;
})();