From df07010d73ecc2f015284f1008b86eb7b9aadaf7 Mon Sep 17 00:00:00 2001 From: Hugues Hertout Date: Fri, 23 Feb 2024 17:30:22 +0100 Subject: [PATCH 1/9] feat: adding renderer --- README.md | 2 +- dist/dto/Renderer.d.ts | 5 + dist/lx_dt.js | 32890 +++++++++++++------------ dist/utils/renderer.d.ts | 0 example/w_bootstrap/data.js | 163 +- example/w_bootstrap/main.js | 21 +- lib/core/LyxeaDatatable.ts | 14 +- lib/dto/Renderer.ts | 134 +- lib/utils/fixToFixed.ts | 22 +- lib/utils/renderer.ts | 174 - package-lock.json | 6 + package.json | 1 + tests/specs/utils/fixToFixed.test.ts | 18 +- 13 files changed, 16791 insertions(+), 16659 deletions(-) delete mode 100644 dist/utils/renderer.d.ts delete mode 100644 lib/utils/renderer.ts diff --git a/README.md b/README.md index 2e7d1c2..522f746 100644 --- a/README.md +++ b/README.md @@ -63,7 +63,7 @@ You can provide Datatable native configuration in the main object. It works prop If you want more info about the base configuration, please refer to the official documentation. -If you want to add the specific Lyxea custom object, you need to add the key `lxConfig`. +If you want to add the specific Lyxea custom object, you need to add the key `lxConfig`. Then you can add your own custom configuration depend on your needs. The following sections are dedicated to this configuration. diff --git a/dist/dto/Renderer.d.ts b/dist/dto/Renderer.d.ts index baff2e9..75887dd 100644 --- a/dist/dto/Renderer.d.ts +++ b/dist/dto/Renderer.d.ts @@ -3,5 +3,10 @@ export type RendederConfig = {}; declare class LxRenderer { renderers: Array; constructor(config: LxConfigObject); + number2DigitMax(data: any | null): any; + booleanString: (data: boolean) => "Oui" | "Non"; + cutLongText: (data: any) => any; + uppercase: (data: any) => any; + numberToFixed: (data: any) => string | undefined; } export default LxRenderer; diff --git a/dist/lx_dt.js b/dist/lx_dt.js index ed534bf..e6278ef 100644 --- a/dist/lx_dt.js +++ b/dist/lx_dt.js @@ -1,32 +1,32 @@ -import Va from "jquery"; +import Ca from "jquery"; /*! DataTables 2.0.0 * © SpryMedia Ltd - datatables.net/license */ -var Xt = Va, ge = function(s, g) { - if (ge.factory(s, g)) +var Xt = Ca, ge = function(s, p) { + if (ge.factory(s, p)) return ge; if (this instanceof ge) - return Xt(s).DataTable(g); - g = s; - var x = this, C = g === void 0, B = this.length; - return C && (g = {}), this.api = function() { + return Xt(s).DataTable(p); + p = s; + var b = this, A = p === void 0, R = this.length; + return A && (p = {}), this.api = function() { return new Sr(this); }, this.each(function() { - var O = {}, c = B > 1 ? ( + var B = {}, u = R > 1 ? ( // optimisation for single table case - Qs(O, g, !0) - ) : g, d = 0, t, o = this.getAttribute("id"), r = !1, n = ge.defaults, i = Xt(this); + $0(B, p, !0) + ) : p, d = 0, t, o = this.getAttribute("id"), r = !1, n = ge.defaults, i = Xt(this); if (this.nodeName.toLowerCase() != "table") { qn(null, 0, "Non-table node initialisation (" + this.nodeName + ")", 2); return; } - Xt(this).trigger("options.dt", c), js(n), uf(n.column), Oa(n, n, !0), Oa(n.column, n.column, !0), Oa(n, Xt.extend(c, i.data()), !0); + Xt(this).trigger("options.dt", u), G0(n), cf(n.column), Ba(n, n, !0), Ba(n.column, n.column, !0), Ba(n, Xt.extend(u, i.data()), !0); var f = ge.settings; for (d = 0, t = f.length; d < t; d++) { var l = f[d]; if (l.nTable == this || l.nTHead && l.nTHead.parentNode == this || l.nTFoot && l.nTFoot.parentNode == this) { - var u = c.bRetrieve !== void 0 ? c.bRetrieve : n.bRetrieve, h = c.bDestroy !== void 0 ? c.bDestroy : n.bDestroy; - if (C || u) + var c = u.bRetrieve !== void 0 ? u.bRetrieve : n.bRetrieve, h = u.bDestroy !== void 0 ? u.bDestroy : n.bDestroy; + if (A || c) return l.oInstance; if (h) { new ge.Api(l).destroy(); @@ -47,11 +47,11 @@ var Xt = Va, ge = function(s, g) { sInstance: o, sTableId: o, colgroup: Xt("").prependTo(this), - fastData: function(T, A, F) { - return ta(a, T, A, F); + fastData: function(C, E, F) { + return ta(a, C, E, F); } }); - a.nTable = this, a.oInit = c, f.push(a), a.api = new Sr(a), a.oInstance = x.length === 1 ? x : i.dataTable(), js(c), c.aLengthMenu && !c.iDisplayLength && (c.iDisplayLength = Array.isArray(c.aLengthMenu[0]) ? c.aLengthMenu[0][0] : Xt.isPlainObject(c.aLengthMenu[0]) ? c.aLengthMenu[0].value : c.aLengthMenu[0]), c = Qs(Xt.extend(!0, {}, n), c), Ra(a.oFeatures, c, [ + a.nTable = this, a.oInit = u, f.push(a), a.api = new Sr(a), a.oInstance = b.length === 1 ? b : i.dataTable(), G0(u), u.aLengthMenu && !u.iDisplayLength && (u.iDisplayLength = Array.isArray(u.aLengthMenu[0]) ? u.aLengthMenu[0][0] : Xt.isPlainObject(u.aLengthMenu[0]) ? u.aLengthMenu[0].value : u.aLengthMenu[0]), u = $0(Xt.extend(!0, {}, n), u), La(a.oFeatures, u, [ "bPaginate", "bLengthChange", "bFilter", @@ -63,7 +63,7 @@ var Xt = Va, ge = function(s, g) { "bSortClasses", "bServerSide", "bDeferRender" - ]), Ra(a, c, [ + ]), La(a, u, [ "ajax", "fnFormatNumber", "sServerMethod", @@ -87,77 +87,77 @@ var Xt = Va, ge = function(s, g) { ["oSearch", "oPreviousSearch"], ["aoSearchCols", "aoPreSearchCols"], ["iDisplayLength", "_iDisplayLength"] - ]), Ra(a.oScroll, c, [ + ]), La(a.oScroll, u, [ ["sScrollX", "sX"], ["sScrollXInner", "sXInner"], ["sScrollY", "sY"], ["bScrollCollapse", "bCollapse"] - ]), Ra(a.oLanguage, c, "fnInfoCallback"), $n(a, "aoDrawCallback", c.fnDrawCallback), $n(a, "aoStateSaveParams", c.fnStateSaveParams), $n(a, "aoStateLoadParams", c.fnStateLoadParams), $n(a, "aoStateLoaded", c.fnStateLoaded), $n(a, "aoRowCallback", c.fnRowCallback), $n(a, "aoRowCreatedCallback", c.fnCreatedRow), $n(a, "aoHeaderCallback", c.fnHeaderCallback), $n(a, "aoFooterCallback", c.fnFooterCallback), $n(a, "aoInitComplete", c.fnInitComplete), $n(a, "aoPreDrawCallback", c.fnPreDrawCallback), a.rowIdFn = li(c.rowId), jh(a); + ]), La(a.oLanguage, u, "fnInfoCallback"), $n(a, "aoDrawCallback", u.fnDrawCallback), $n(a, "aoStateSaveParams", u.fnStateSaveParams), $n(a, "aoStateLoadParams", u.fnStateLoadParams), $n(a, "aoStateLoaded", u.fnStateLoaded), $n(a, "aoRowCallback", u.fnRowCallback), $n(a, "aoRowCreatedCallback", u.fnCreatedRow), $n(a, "aoHeaderCallback", u.fnHeaderCallback), $n(a, "aoFooterCallback", u.fnFooterCallback), $n(a, "aoInitComplete", u.fnInitComplete), $n(a, "aoPreDrawCallback", u.fnPreDrawCallback), a.rowIdFn = ui(u.rowId), Xh(a); var v = a.oClasses; - Xt.extend(v, ge.ext.classes, c.oClasses), i.addClass(v.table), a.oFeatures.bPaginate || (c.iDisplayStart = 0), a.iInitDisplayStart === void 0 && (a.iInitDisplayStart = c.iDisplayStart, a._iDisplayStart = c.iDisplayStart); + Xt.extend(v, ge.ext.classes, u.oClasses), i.addClass(v.table), a.oFeatures.bPaginate || (u.iDisplayStart = 0), a.iInitDisplayStart === void 0 && (a.iInitDisplayStart = u.iDisplayStart, a._iDisplayStart = u.iDisplayStart); var y = a.oLanguage; - Xt.extend(!0, y, c.oLanguage), y.sUrl ? (Xt.ajax({ + Xt.extend(!0, y, u.oLanguage), y.sUrl ? (Xt.ajax({ dataType: "json", url: y.sUrl, - success: function(T) { - Oa(n.oLanguage, T), Xt.extend(!0, y, T, a.oInit.oLanguage), Nr(a, null, "i18n", [a]), To(a); + success: function(C) { + Ba(n.oLanguage, C), Xt.extend(!0, y, C, a.oInit.oLanguage), Nr(a, null, "i18n", [a]), Fo(a); }, error: function() { - qn(a, 0, "i18n file loading error", 21), To(a); + qn(a, 0, "i18n file loading error", 21), Fo(a); } }), r = !0) : Nr(a, null, "i18n", [a]); - var p = [], e = this.getElementsByTagName("thead"), m = mf(a, e[0]); - if (c.aoColumns) - p = c.aoColumns; + var g = [], e = this.getElementsByTagName("thead"), m = xf(a, e[0]); + if (u.aoColumns) + g = u.aoColumns; else if (m.length) for (d = 0, t = m[0].length; d < t; d++) - p.push(null); - for (d = 0, t = p.length; d < t; d++) - cf(a); - Xh(a, c.aoColumnDefs, p, m, function(T, A) { - p0(a, T, A); + g.push(null); + for (d = 0, t = g.length; d < t; d++) + hf(a); + Kh(a, u.aoColumnDefs, g, m, function(C, E) { + gs(a, C, E); }); var w = i.children("tbody").find("tr").eq(0); if (w.length) { - var D = function(T, A) { - return T.getAttribute("data-" + A) !== null ? A : null; + var D = function(C, E) { + return C.getAttribute("data-" + E) !== null ? E : null; }; - Xt(w[0]).children("th, td").each(function(T, A) { - var F = a.aoColumns[T]; - if (F || qn(a, 0, "Incorrect column count", 18), F.mData === T) { - var b = D(A, "sort") || D(A, "order"), R = D(A, "filter") || D(A, "search"); - (b !== null || R !== null) && (F.mData = { - _: T + ".display", - sort: b !== null ? T + ".@data-" + b : void 0, - type: b !== null ? T + ".@data-" + b : void 0, - filter: R !== null ? T + ".@data-" + R : void 0 - }, F._isArrayHost = !0, p0(a, T)); + Xt(w[0]).children("th, td").each(function(C, E) { + var F = a.aoColumns[C]; + if (F || qn(a, 0, "Incorrect column count", 18), F.mData === C) { + var x = D(E, "sort") || D(E, "order"), P = D(E, "filter") || D(E, "search"); + (x !== null || P !== null) && (F.mData = { + _: C + ".display", + sort: x !== null ? C + ".@data-" + x : void 0, + type: x !== null ? C + ".@data-" + x : void 0, + filter: P !== null ? C + ".@data-" + P : void 0 + }, F._isArrayHost = !0, gs(a, C)); } }); } - var I = a.oFeatures, E = function() { - if (c.aaSorting === void 0) { - var T = a.aaSorting; - for (d = 0, t = T.length; d < t; d++) - T[d][1] = a.aoColumns[d].asSorting[0]; + var I = a.oFeatures, T = function() { + if (u.aaSorting === void 0) { + var C = a.aaSorting; + for (d = 0, t = C.length; d < t; d++) + C[d][1] = a.aoColumns[d].asSorting[0]; } - y0(a), $n(a, "aoDrawCallback", function() { - (a.bSorted || Zn(a) === "ssp" || I.bDeferRender) && y0(a); + ms(a), $n(a, "aoDrawCallback", function() { + (a.bSorted || Zn(a) === "ssp" || I.bDeferRender) && ms(a); }); - var A = i.children("caption"); - a.caption && (A.length === 0 && (A = Xt("").appendTo(i)), A.html(a.caption)), A.length && (A[0]._captionSide = A.css("caption-side"), a.captionNode = A[0]), e.length === 0 && (e = Xt("").appendTo(i)), a.nTHead = e[0], Xt("tr", e).addClass(v.thead.row); + var E = i.children("caption"); + a.caption && (E.length === 0 && (E = Xt("").appendTo(i)), E.html(a.caption)), E.length && (E[0]._captionSide = E.css("caption-side"), a.captionNode = E[0]), e.length === 0 && (e = Xt("").appendTo(i)), a.nTHead = e[0], Xt("tr", e).addClass(v.thead.row); var F = i.children("tbody"); F.length === 0 && (F = Xt("").insertAfter(e)), a.nTBody = F[0]; - var b = i.children("tfoot"); - if (b.length === 0 && (b = Xt("").appendTo(i)), a.nTFoot = b[0], Xt("tr", b).addClass(v.tfoot.row), c.aaData) - for (d = 0; d < c.aaData.length; d++) - Za(a, c.aaData[d]); + var x = i.children("tfoot"); + if (x.length === 0 && (x = Xt("").appendTo(i)), a.nTFoot = x[0], Xt("tr", x).addClass(v.tfoot.row), u.aaData) + for (d = 0; d < u.aaData.length; d++) + Za(a, u.aaData[d]); else - Zn(a) == "dom" && P0(a, Xt(a.nTBody).children("tr")); - a.aiDisplay = a.aiDisplayMaster.slice(), a.bInitialised = !0, r === !1 && To(a); + Zn(a) == "dom" && Ps(a, Xt(a.nTBody).children("tr")); + a.aiDisplay = a.aiDisplayMaster.slice(), a.bInitialised = !0, r === !1 && Fo(a); }; - $n(a, "aoDrawCallback", zo), c.bStateSave ? (I.bStateSave = !0, ud(a, c, E)) : E(); - }), x = null, this; + $n(a, "aoDrawCallback", Wo), u.bStateSave ? (I.bStateSave = !0, dd(a, u, T)) : T(); + }), b = null, this; }; ge.ext = Vr = { /** @@ -662,96 +662,96 @@ Xt.extend(ge.ext.classes, { disabled: "disabled" } }); -var Vr, Sr, Ke, Xr, f0 = {}, kh = /[\r\n\u2028]/g, A0 = /<.*?>/g, Uh = /^\d{2,4}[./-]\d{1,2}[./-]\d{1,2}([T ]{1}\d{1,2}[:.]\d{2}([.:]\d{2})?)?$/, zh = new RegExp("(\\" + ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^", "-"].join("|\\") + ")", "g"), C0 = /['\u00A0,$£€¥%\u2009\u202F\u20BD\u20a9\u20BArfkɃΞ]/gi, Aa = function(s) { +var Vr, Sr, Ke, Xr, ls = {}, Wh = /[\r\n\u2028]/g, Cs = /<.*?>/g, Hh = /^\d{2,4}[./-]\d{1,2}[./-]\d{1,2}([T ]{1}\d{1,2}[:.]\d{2}([.:]\d{2})?)?$/, jh = new RegExp("(\\" + ["/", ".", "*", "+", "?", "|", "(", ")", "[", "]", "{", "}", "\\", "$", "^", "-"].join("|\\") + ")", "g"), Es = /['\u00A0,$£€¥%\u2009\u202F\u20BD\u20a9\u20BArfkɃΞ]/gi, Aa = function(s) { return !s || s === !0 || s === "-"; -}, of = function(s) { - var g = parseInt(s, 10); - return !isNaN(g) && isFinite(s) ? g : null; -}, sf = function(s, g) { - return f0[g] || (f0[g] = new RegExp(g0(g), "g")), typeof s == "string" && g !== "." ? s.replace(/\./g, "").replace(f0[g], ".") : s; -}, E0 = function(s, g, x) { - var C = typeof s, B = C === "string"; - return C === "number" || C === "bigint" || Aa(s) ? !0 : (g && B && (s = sf(s, g)), x && B && (s = s.replace(C0, "")), !isNaN(parseFloat(s)) && isFinite(s)); -}, Wh = function(s) { +}, sf = function(s) { + var p = parseInt(s, 10); + return !isNaN(p) && isFinite(s) ? p : null; +}, ff = function(s, p) { + return ls[p] || (ls[p] = new RegExp(ys(p), "g")), typeof s == "string" && p !== "." ? s.replace(/\./g, "").replace(ls[p], ".") : s; +}, Ts = function(s, p, b) { + var A = typeof s, R = A === "string"; + return A === "number" || A === "bigint" || Aa(s) ? !0 : (p && R && (s = ff(s, p)), b && R && (s = s.replace(Es, "")), !isNaN(parseFloat(s)) && isFinite(s)); +}, Gh = function(s) { return Aa(s) || typeof s == "string"; -}, ff = function(s, g, x) { +}, lf = function(s, p, b) { if (Aa(s)) return !0; if (typeof s == "string" && s.match(/<(input|select)/i)) return null; - var C = Wh(s); - return C && E0(fi(s), g, x) ? !0 : null; -}, Xn = function(s, g, x) { - var C = [], B = 0, O = s.length; - if (x !== void 0) - for (; B < O; B++) - s[B] && s[B][g] && C.push(s[B][g][x]); + var A = Gh(s); + return A && Ts(li(s), p, b) ? !0 : null; +}, Xn = function(s, p, b) { + var A = [], R = 0, B = s.length; + if (b !== void 0) + for (; R < B; R++) + s[R] && s[R][p] && A.push(s[R][p][b]); else - for (; B < O; B++) - s[B] && C.push(s[B][g]); - return C; -}, Gi = function(s, g, x, C) { - var B = [], O = 0, c = g.length; - if (C !== void 0) - for (; O < c; O++) - s[g[O]][x] && B.push(s[g[O]][x][C]); + for (; R < B; R++) + s[R] && A.push(s[R][p]); + return A; +}, Gi = function(s, p, b, A) { + var R = [], B = 0, u = p.length; + if (A !== void 0) + for (; B < u; B++) + s[p[B]][b] && R.push(s[p[B]][b][A]); else - for (; O < c; O++) - s[g[O]] && B.push(s[g[O]][x]); - return B; -}, Pa = function(s, g) { - var x = [], C; - g === void 0 ? (g = 0, C = s) : (C = g, g = s); - for (var B = g; B < C; B++) - x.push(B); - return x; -}, lf = function(s) { - for (var g = [], x = 0, C = s.length; x < C; x++) - s[x] && g.push(s[x]); - return g; -}, fi = function(s) { - return s.replace(A0, "").replace(/