jjsontree.js
Advanced tools
Comparing version 2.2.0 to 2.3.0
@@ -46,23 +46,31 @@ var __getOwnPropNames = Object.getOwnPropertyNames; | ||
e.definedFunction = i; | ||
function a(e) { | ||
function l(e) { | ||
return t(e) && typeof e === "number"; | ||
} | ||
e.definedNumber = a; | ||
function l(e) { | ||
e.definedNumber = l; | ||
function a(e) { | ||
return t(e) && typeof e === "bigint"; | ||
} | ||
e.definedBigInt = a; | ||
function s(e) { | ||
return n(e) && e instanceof Array; | ||
} | ||
e.definedArray = l; | ||
function s(e) { | ||
e.definedArray = s; | ||
function u(e) { | ||
return n(e) && e instanceof Date; | ||
} | ||
e.definedDate = s; | ||
function u(e) { | ||
e.definedDate = u; | ||
function c(e) { | ||
return t(e) && typeof e === "number" && e % 1 !== 0; | ||
} | ||
e.definedDecimal = u; | ||
function c(e, t = 1) { | ||
return !l(e) || e.length < t; | ||
e.definedDecimal = c; | ||
function d(e) { | ||
return t(e) && typeof e === "symbol"; | ||
} | ||
e.invalidOptionArray = c; | ||
function d(e) { | ||
e.definedSymbol = d; | ||
function f(e, t = 1) { | ||
return !s(e) || e.length < t; | ||
} | ||
e.invalidOptionArray = f; | ||
function g(e) { | ||
let t = e.length >= 2 && e.length <= 7; | ||
@@ -74,3 +82,11 @@ if (t && e[0] === "#") { | ||
} | ||
e.hexColor = d; | ||
e.hexColor = g; | ||
function m(e) { | ||
return e.toString().toLowerCase().trim() === "true" || e.toString().toLowerCase().trim() === "false"; | ||
} | ||
e.stringValueBoolean = m; | ||
function p(e) { | ||
return !isNaN(+new Date(e)); | ||
} | ||
e.stringValueDate = p; | ||
})(Is || (Is = {})); | ||
@@ -108,10 +124,10 @@ } | ||
e.getFunction = i; | ||
function a(e, t) { | ||
function l(e, t) { | ||
return Is.definedArray(e) ? e : t; | ||
} | ||
e.getArray = a; | ||
function l(e, t) { | ||
e.getArray = l; | ||
function a(e, t) { | ||
return Is.definedObject(e) ? e : t; | ||
} | ||
e.getObject = l; | ||
e.getObject = a; | ||
function s(e, t) { | ||
@@ -127,3 +143,3 @@ let n = t; | ||
} else { | ||
n = a(e, t); | ||
n = l(e, t); | ||
} | ||
@@ -167,18 +183,18 @@ return n; | ||
const i = o === "text"; | ||
let a = i ? document.createTextNode("") : document.createElement(o); | ||
let l = i ? document.createTextNode("") : document.createElement(o); | ||
if (Is.defined(n)) { | ||
a.className = n; | ||
l.className = n; | ||
} | ||
if (Is.defined(r)) { | ||
e.insertBefore(a, r); | ||
e.insertBefore(l, r); | ||
} else { | ||
e.appendChild(a); | ||
e.appendChild(l); | ||
} | ||
return a; | ||
return l; | ||
} | ||
e.create = t; | ||
function n(e, n, r, o, i = null) { | ||
const a = t(e, n, r, i); | ||
a.innerHTML = o; | ||
return a; | ||
const l = t(e, n, r, i); | ||
l.innerHTML = o; | ||
return l; | ||
} | ||
@@ -195,2 +211,36 @@ e.createWithHTML = n; | ||
e.cancelBubble = o; | ||
function i() { | ||
const e = document.documentElement; | ||
const t = { | ||
left: e.scrollLeft - (e.clientLeft || 0), | ||
top: e.scrollTop - (e.clientTop || 0) | ||
}; | ||
return t; | ||
} | ||
e.getScrollPosition = i; | ||
function l(e, t) { | ||
let n = e.pageX; | ||
let r = e.pageY; | ||
const o = i(); | ||
t.style.display = "block"; | ||
if (n + t.offsetWidth > window.innerWidth) { | ||
n -= t.offsetWidth; | ||
} else { | ||
n++; | ||
} | ||
if (r + t.offsetHeight > window.innerHeight) { | ||
r -= t.offsetHeight; | ||
} else { | ||
r++; | ||
} | ||
if (n < o.left) { | ||
n = e.pageX + 1; | ||
} | ||
if (r < o.top) { | ||
r = e.pageY + 1; | ||
} | ||
t.style.left = `${n}px`; | ||
t.style.top = `${r}px`; | ||
} | ||
e.showElementAtMousePosition = l; | ||
})(DomElement || (DomElement = {})); | ||
@@ -258,3 +308,3 @@ } | ||
let i = o; | ||
const a = t(r); | ||
const l = t(r); | ||
i = i.replace("{hh}", Str.padNumber(r.getHours(), 2)); | ||
@@ -266,4 +316,4 @@ i = i.replace("{h}", r.getHours().toString()); | ||
i = i.replace("{s}", r.getSeconds().toString()); | ||
i = i.replace("{dddd}", e.text.dayNames[a]); | ||
i = i.replace("{ddd}", e.text.dayNamesAbbreviated[a]); | ||
i = i.replace("{dddd}", e.text.dayNames[l]); | ||
i = i.replace("{ddd}", e.text.dayNamesAbbreviated[l]); | ||
i = i.replace("{dd}", Str.padNumber(r.getDate())); | ||
@@ -283,6 +333,2 @@ i = i.replace("{d}", r.getDate().toString()); | ||
e.getCustomFormattedDateText = r; | ||
function o(e) { | ||
return !isNaN(+new Date(e)); | ||
} | ||
e.isDateValid = o; | ||
})(DateTime || (DateTime = {})); | ||
@@ -342,7 +388,9 @@ } | ||
t.fileDroppingEnabled = Default.getBoolean(t.fileDroppingEnabled, true); | ||
t.parseStringsToDates = Default.getBoolean(t.parseStringsToDates, false); | ||
t.copyIndentSpaces = Default.getNumber(t.copyIndentSpaces, 2); | ||
t.showArrayIndexBrackets = Default.getBoolean(t.showArrayIndexBrackets, true); | ||
t = o(t); | ||
t = i(t); | ||
t = l(t); | ||
t = a(t); | ||
t = s(t); | ||
return t; | ||
@@ -371,5 +419,20 @@ } | ||
e.ignore.arrayValues = Default.getBoolean(e.ignore.arrayValues, false); | ||
e.ignore.bigIntValues = Default.getBoolean(e.ignore.bigIntValues, false); | ||
e.ignore.symbolValues = Default.getBoolean(e.ignore.symbolValues, false); | ||
e.ignore.emptyObjects = Default.getBoolean(e.ignore.emptyObjects, true); | ||
return e; | ||
} | ||
function l(e) { | ||
e.tooltip = Default.getObject(e.tooltip, {}); | ||
e.tooltip.delay = Default.getNumber(e.tooltip.delay, 750); | ||
return e; | ||
} | ||
function a(e) { | ||
e.parse = Default.getObject(e.parse, {}); | ||
e.parse.stringsToDates = Default.getBoolean(e.parse.stringsToDates, false); | ||
e.parse.stringsToBooleans = Default.getBoolean(e.parse.stringsToBooleans, false); | ||
e.parse.stringsToNumbers = Default.getBoolean(e.parse.stringsToNumbers, false); | ||
return e; | ||
} | ||
function s(e) { | ||
e.events = Default.getObject(e.events, {}); | ||
@@ -387,2 +450,3 @@ e.events.onBeforeRender = Default.getFunction(e.events.onBeforeRender, null); | ||
e.events.onNumberRender = Default.getFunction(e.events.onNumberRender, null); | ||
e.events.onBigIntRender = Default.getFunction(e.events.onBigIntRender, null); | ||
e.events.onStringRender = Default.getFunction(e.events.onStringRender, null); | ||
@@ -393,2 +457,3 @@ e.events.onDateRender = Default.getFunction(e.events.onDateRender, null); | ||
e.events.onUnknownRender = Default.getFunction(e.events.onUnknownRender, null); | ||
e.events.onSymbolRender = Default.getFunction(e.events.onSymbolRender, null); | ||
return e; | ||
@@ -480,2 +545,63 @@ } | ||
var ToolTip; | ||
var init_tooltip = __esm({ | ||
"src/ts/area/tooltip.ts"() { | ||
"use strict"; | ||
init_dom(); | ||
init_is(); | ||
(e => { | ||
function t(e) { | ||
if (!Is.defined(e._currentView.tooltip)) { | ||
e._currentView.tooltip = DomElement.create(document.body, "div", "jsontree-js-tooltip"); | ||
e._currentView.tooltip.style.display = "none"; | ||
n(e); | ||
} | ||
} | ||
e.renderControl = t; | ||
function n(e, t = true) { | ||
let n = t ? window.addEventListener : window.removeEventListener; | ||
let r = t ? document.addEventListener : document.removeEventListener; | ||
n("mousemove", (() => { | ||
i(e); | ||
})); | ||
r("scroll", (() => { | ||
i(e); | ||
})); | ||
} | ||
e.assignToEvents = n; | ||
function r(e, t, n) { | ||
if (e !== null) { | ||
e.onmousemove = e => { | ||
o(e, t, n); | ||
}; | ||
} | ||
} | ||
e.add = r; | ||
function o(e, t, n) { | ||
DomElement.cancelBubble(e); | ||
i(t); | ||
t._currentView.tooltipTimerId = setTimeout((() => { | ||
t._currentView.tooltip.innerHTML = n; | ||
t._currentView.tooltip.style.display = "block"; | ||
DomElement.showElementAtMousePosition(e, t._currentView.tooltip); | ||
}), t.tooltip.delay); | ||
} | ||
e.show = o; | ||
function i(e) { | ||
if (Is.defined(e._currentView.tooltip)) { | ||
if (e._currentView.tooltipTimerId !== 0) { | ||
clearTimeout(e._currentView.tooltipTimerId); | ||
e._currentView.tooltipTimerId = 0; | ||
} | ||
if (e._currentView.tooltip.style.display !== "none") { | ||
e._currentView.tooltip.style.display = "none"; | ||
} | ||
} | ||
} | ||
e.hide = i; | ||
})(ToolTip || (ToolTip = {})); | ||
} | ||
}); | ||
var require_jsontree = __commonJS({ | ||
@@ -493,2 +619,3 @@ "src/jsontree.ts"(exports, module) { | ||
init_trigger(); | ||
init_tooltip(); | ||
(() => { | ||
@@ -536,2 +663,3 @@ let _configuration = {}; | ||
Trigger.customEvent(e.events.onBeforeRender, e._currentView.element); | ||
ToolTip.renderControl(e); | ||
if (!Is.definedString(e._currentView.element.id)) { | ||
@@ -550,2 +678,3 @@ e._currentView.element.id = Str.newGuid(); | ||
let t = _elements_Data[e._currentView.element.id].data; | ||
ToolTip.hide(e); | ||
e._currentView.element.innerHTML = ""; | ||
@@ -579,9 +708,9 @@ renderControlTitleBar(e, t); | ||
const n = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "copy-all", _configuration.text.copyAllButtonSymbolText); | ||
n.title = _configuration.text.copyAllButtonText; | ||
ToolTip.add(n, e, _configuration.text.copyAllButtonText); | ||
n.onclick = () => { | ||
let n = null; | ||
if (e.copyOnlyCurrentPage && e.showArrayItemsAsSeparateObjects) { | ||
n = JSON.stringify(t[e._currentView.dataArrayCurrentIndex], null, e.copyIndentSpaces); | ||
n = JSON.stringify(t[e._currentView.dataArrayCurrentIndex], jsonStringifyReplacer, e.copyIndentSpaces); | ||
} else { | ||
n = JSON.stringify(t, null, e.copyIndentSpaces); | ||
n = JSON.stringify(t, jsonStringifyReplacer, e.copyIndentSpaces); | ||
} | ||
@@ -594,5 +723,5 @@ navigator.clipboard.writeText(n); | ||
const t = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "openAll", _configuration.text.openAllButtonSymbolText); | ||
t.title = _configuration.text.openAllButtonText; | ||
ToolTip.add(t, e, _configuration.text.openAllButtonText); | ||
const n = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "closeAll", _configuration.text.closeAllButtonSymbolText); | ||
n.title = _configuration.text.closeAllButtonText; | ||
ToolTip.add(n, e, _configuration.text.closeAllButtonText); | ||
t.onclick = () => { | ||
@@ -607,3 +736,3 @@ openAllNodes(e); | ||
const n = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "back", _configuration.text.backButtonSymbolText); | ||
n.title = _configuration.text.backButtonText; | ||
ToolTip.add(n, e, _configuration.text.backButtonText); | ||
if (e._currentView.dataArrayCurrentIndex > 0) { | ||
@@ -619,3 +748,3 @@ n.onclick = () => { | ||
const r = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "next", _configuration.text.nextButtonSymbolText); | ||
r.title = _configuration.text.nextButtonText; | ||
ToolTip.add(r, e, _configuration.text.nextButtonText); | ||
if (e._currentView.dataArrayCurrentIndex < t.length - 1) { | ||
@@ -637,2 +766,12 @@ r.onclick = () => { | ||
} | ||
function jsonStringifyReplacer(e, t) { | ||
if (Is.definedBigInt(t)) { | ||
t = t.toString(); | ||
} else if (Is.definedSymbol(t)) { | ||
t = t.toString(); | ||
} else if (Is.definedFunction(t)) { | ||
t = Default.getFunctionName(t); | ||
} | ||
return t; | ||
} | ||
function openAllNodes(e) { | ||
@@ -651,12 +790,20 @@ e.showAllAsClosed = false; | ||
const i = DomElement.create(e, "div", "object-type-contents"); | ||
const a = t.showArrowToggles ? DomElement.create(o, "div", "down-arrow") : null; | ||
const l = renderObjectValues(a, i, t, n); | ||
const s = DomElement.createWithHTML(o, "span", t.showValueColors ? "object" : "", _configuration.text.objectText); | ||
if (r && t.showArrayItemsAsSeparateObjects) { | ||
let e = t.useZeroIndexingForArrays ? t._currentView.dataArrayCurrentIndex.toString() : (t._currentView.dataArrayCurrentIndex + 1).toString(); | ||
DomElement.createWithHTML(o, "span", t.showValueColors ? "object data-array-index" : "data-array-index", `[${e}]:`, s); | ||
const l = t.showArrowToggles ? DomElement.create(o, "div", "down-arrow") : null; | ||
const a = renderObjectValues(l, i, t, n); | ||
if (a === 0 && t.ignore.emptyObjects) { | ||
e.removeChild(o); | ||
e.removeChild(i); | ||
} else { | ||
const e = DomElement.createWithHTML(o, "span", t.showValueColors ? "object" : "", _configuration.text.objectText); | ||
if (r && t.showArrayItemsAsSeparateObjects) { | ||
let n = t.useZeroIndexingForArrays ? t._currentView.dataArrayCurrentIndex.toString() : (t._currentView.dataArrayCurrentIndex + 1).toString(); | ||
if (t.showArrayIndexBrackets) { | ||
n = `[${n}]:`; | ||
} | ||
DomElement.createWithHTML(o, "span", t.showValueColors ? "object data-array-index" : "data-array-index", n, e); | ||
} | ||
if (t.showCounts && a > 0) { | ||
DomElement.createWithHTML(o, "span", t.showValueColors ? "object count" : "count", `{${a}}`); | ||
} | ||
} | ||
if (t.showCounts && l > 0) { | ||
DomElement.createWithHTML(o, "span", t.showValueColors ? "object count" : "count", `{${l}}`); | ||
} | ||
} | ||
@@ -682,3 +829,7 @@ function renderArray(e, t, n) { | ||
if (n.sortPropertyNames) { | ||
i = i.sort(); | ||
let e = new Intl.Collator(void 0, { | ||
numeric: true, | ||
sensitivity: "base" | ||
}); | ||
i = i.sort(e.compare); | ||
if (!n.sortPropertyNamesInAlphabeticalOrder) { | ||
@@ -688,7 +839,7 @@ i = i.reverse(); | ||
} | ||
const a = i.length; | ||
for (let e = 0; e < a; e++) { | ||
const l = i[e]; | ||
if (r.hasOwnProperty(l)) { | ||
renderValue(t, n, l, r[l], e === a - 1); | ||
const l = i.length; | ||
for (let e = 0; e < l; e++) { | ||
const a = i[e]; | ||
if (r.hasOwnProperty(a)) { | ||
renderValue(t, n, a, r[a], e === l - 1); | ||
o++; | ||
@@ -715,8 +866,7 @@ } | ||
const i = DomElement.create(e, "div", "object-type-value"); | ||
const a = t.showArrowToggles ? DomElement.create(i, "div", "no-arrow") : null; | ||
let l = null; | ||
const l = t.showArrowToggles ? DomElement.create(i, "div", "no-arrow") : null; | ||
let a = null; | ||
let s = null; | ||
let u = false; | ||
let c = null; | ||
let d = true; | ||
DomElement.createWithHTML(i, "span", "title", n); | ||
@@ -726,5 +876,5 @@ DomElement.createWithHTML(i, "span", "split", ":"); | ||
if (!t.ignore.nullValues) { | ||
l = t.showValueColors ? "null" : ""; | ||
s = DomElement.createWithHTML(i, "span", l, "null"); | ||
d = false; | ||
a = t.showValueColors ? "null" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, "null"); | ||
c = "null"; | ||
if (Is.definedFunction(t.events.onNullRender)) { | ||
@@ -739,4 +889,4 @@ Trigger.customEvent(t.events.onNullRender, s); | ||
if (!t.ignore.functionValues) { | ||
l = t.showValueColors ? "function" : ""; | ||
s = DomElement.createWithHTML(i, "span", l, Default.getFunctionName(r)); | ||
a = t.showValueColors ? "function" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, Default.getFunctionName(r)); | ||
c = "function"; | ||
@@ -752,4 +902,4 @@ if (Is.definedFunction(t.events.onFunctionRender)) { | ||
if (!t.ignore.booleanValues) { | ||
l = t.showValueColors ? "boolean" : ""; | ||
s = DomElement.createWithHTML(i, "span", l, r); | ||
a = t.showValueColors ? "boolean" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, r); | ||
c = "boolean"; | ||
@@ -766,4 +916,4 @@ if (Is.definedFunction(t.events.onBooleanRender)) { | ||
const e = Default.getFixedDecimalPlacesValue(r, t.maximumDecimalPlaces); | ||
l = t.showValueColors ? "decimal" : ""; | ||
s = DomElement.createWithHTML(i, "span", l, e); | ||
a = t.showValueColors ? "decimal" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, e); | ||
c = "decimal"; | ||
@@ -779,4 +929,4 @@ if (Is.definedFunction(t.events.onDecimalRender)) { | ||
if (!t.ignore.numberValues) { | ||
l = t.showValueColors ? "number" : ""; | ||
s = DomElement.createWithHTML(i, "span", l, r); | ||
a = t.showValueColors ? "number" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, r); | ||
c = "number"; | ||
@@ -790,5 +940,23 @@ if (Is.definedFunction(t.events.onNumberRender)) { | ||
} | ||
} else if (Is.definedBigInt(r)) { | ||
if (!t.ignore.bigIntValues) { | ||
a = t.showValueColors ? "bigint" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, r); | ||
c = "bigint"; | ||
if (Is.definedFunction(t.events.onBigIntRender)) { | ||
Trigger.customEvent(t.events.onBigIntRender, s); | ||
} | ||
createComma(t, i, o); | ||
} else { | ||
u = true; | ||
} | ||
} else if (Is.definedString(r)) { | ||
if (!t.ignore.stringValues) { | ||
if (t.parseStringsToDates && DateTime.isDateValid(r)) { | ||
if (t.parse.stringsToBooleans && Is.stringValueBoolean(r)) { | ||
renderValue(e, t, n, r.toString().toLowerCase().trim() === "true", o); | ||
u = true; | ||
} else if (t.parse.stringsToNumbers && !isNaN(r)) { | ||
renderValue(e, t, n, parseFloat(r), o); | ||
u = true; | ||
} else if (t.parse.stringsToDates && Is.stringValueDate(r)) { | ||
renderValue(e, t, n, new Date(r), o); | ||
@@ -806,4 +974,4 @@ u = true; | ||
const n = t.showStringQuotes ? `"${r}"` : r; | ||
l = t.showValueColors ? "string" : ""; | ||
s = DomElement.createWithHTML(i, "span", l, n); | ||
a = t.showValueColors ? "string" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, n); | ||
c = "string"; | ||
@@ -823,4 +991,4 @@ if (Is.definedString(e)) { | ||
if (!t.ignore.dateValues) { | ||
l = t.showValueColors ? "date" : ""; | ||
s = DomElement.createWithHTML(i, "span", l, DateTime.getCustomFormattedDateText(_configuration, r, t.dateTimeFormat)); | ||
a = t.showValueColors ? "date" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, DateTime.getCustomFormattedDateText(_configuration, r, t.dateTimeFormat)); | ||
c = "date"; | ||
@@ -834,2 +1002,14 @@ if (Is.definedFunction(t.events.onDateRender)) { | ||
} | ||
} else if (Is.definedSymbol(r)) { | ||
if (!t.ignore.symbolValues) { | ||
a = t.showValueColors ? "symbol" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, r.toString()); | ||
c = "symbol"; | ||
if (Is.definedFunction(t.events.onSymbolRender)) { | ||
Trigger.customEvent(t.events.onSymbolRender, s); | ||
} | ||
createComma(t, i, o); | ||
} else { | ||
u = true; | ||
} | ||
} else if (Is.definedObject(r) && !Is.definedArray(r)) { | ||
@@ -839,9 +1019,13 @@ if (!t.ignore.objectValues) { | ||
const n = DomElement.create(i, "div", "object-type-contents"); | ||
const l = renderObjectValues(a, n, t, r); | ||
DomElement.createWithHTML(e, "span", "title", _configuration.text.objectText); | ||
if (t.showCounts && l > 0) { | ||
DomElement.createWithHTML(e, "span", "count", `{${l}}`); | ||
const a = renderObjectValues(l, n, t, r); | ||
if (a === 0 && t.ignore.emptyObjects) { | ||
u = true; | ||
} else { | ||
DomElement.createWithHTML(e, "span", "title", _configuration.text.objectText); | ||
if (t.showCounts && a > 0) { | ||
DomElement.createWithHTML(e, "span", "count", `{${a}}`); | ||
} | ||
createComma(t, e, o); | ||
c = "object"; | ||
} | ||
createComma(t, e, o); | ||
c = "object"; | ||
} else { | ||
@@ -859,3 +1043,3 @@ u = true; | ||
createComma(t, e, o); | ||
renderArrayValues(a, n, t, r); | ||
renderArrayValues(l, n, t, r); | ||
c = "array"; | ||
@@ -867,4 +1051,4 @@ } else { | ||
if (!t.ignore.unknownValues) { | ||
l = t.showValueColors ? "unknown" : ""; | ||
s = DomElement.createWithHTML(i, "span", l, r.toString()); | ||
a = t.showValueColors ? "unknown" : ""; | ||
s = DomElement.createWithHTML(i, "span", a, r.toString()); | ||
c = "unknown"; | ||
@@ -883,8 +1067,8 @@ if (Is.definedFunction(t.events.onUnknownRender)) { | ||
if (Is.defined(s)) { | ||
addValueClickEvent(t, s, r, c, d); | ||
addValueClickEvent(t, s, r, c); | ||
} | ||
} | ||
} | ||
function addValueClickEvent(e, t, n, r, o) { | ||
if (o && Is.definedFunction(e.events.onValueClick)) { | ||
function addValueClickEvent(e, t, n, r) { | ||
if (Is.definedFunction(e.events.onValueClick)) { | ||
t.onclick = () => { | ||
@@ -926,3 +1110,6 @@ Trigger.customEvent(e.events.onValueClick, n, r); | ||
} | ||
return `[${r}]`; | ||
if (e.showArrayIndexBrackets) { | ||
r = `[${r}]`; | ||
} | ||
return r; | ||
} | ||
@@ -997,2 +1184,3 @@ function makeAreaDroppable(e, t) { | ||
e._currentView.element.className = ""; | ||
ToolTip.assignToEvents(e, false); | ||
Trigger.customEvent(e.events.onDestroy, e._currentView.element); | ||
@@ -1109,3 +1297,3 @@ } | ||
getVersion: function() { | ||
return "2.2.0"; | ||
return "2.3.0"; | ||
} | ||
@@ -1112,0 +1300,0 @@ }; |
@@ -26,23 +26,31 @@ "use strict"; | ||
e.definedFunction = l; | ||
function a(e) { | ||
function i(e) { | ||
return t(e) && typeof e === "number"; | ||
} | ||
e.definedNumber = a; | ||
function i(e) { | ||
e.definedNumber = i; | ||
function a(e) { | ||
return t(e) && typeof e === "bigint"; | ||
} | ||
e.definedBigInt = a; | ||
function s(e) { | ||
return n(e) && e instanceof Array; | ||
} | ||
e.definedArray = i; | ||
function s(e) { | ||
e.definedArray = s; | ||
function u(e) { | ||
return n(e) && e instanceof Date; | ||
} | ||
e.definedDate = s; | ||
function u(e) { | ||
e.definedDate = u; | ||
function c(e) { | ||
return t(e) && typeof e === "number" && e % 1 !== 0; | ||
} | ||
e.definedDecimal = u; | ||
function c(e, t = 1) { | ||
return !i(e) || e.length < t; | ||
e.definedDecimal = c; | ||
function d(e) { | ||
return t(e) && typeof e === "symbol"; | ||
} | ||
e.invalidOptionArray = c; | ||
function d(e) { | ||
e.definedSymbol = d; | ||
function f(e, t = 1) { | ||
return !s(e) || e.length < t; | ||
} | ||
e.invalidOptionArray = f; | ||
function g(e) { | ||
let t = e.length >= 2 && e.length <= 7; | ||
@@ -54,3 +62,11 @@ if (t && e[0] === "#") { | ||
} | ||
e.hexColor = d; | ||
e.hexColor = g; | ||
function m(e) { | ||
return e.toString().toLowerCase().trim() === "true" || e.toString().toLowerCase().trim() === "false"; | ||
} | ||
e.stringValueBoolean = m; | ||
function p(e) { | ||
return !isNaN(+new Date(e)); | ||
} | ||
e.stringValueDate = p; | ||
})(Is || (Is = {})); | ||
@@ -81,10 +97,10 @@ | ||
e.getFunction = l; | ||
function a(e, t) { | ||
function i(e, t) { | ||
return Is.definedArray(e) ? e : t; | ||
} | ||
e.getArray = a; | ||
function i(e, t) { | ||
e.getArray = i; | ||
function a(e, t) { | ||
return Is.definedObject(e) ? e : t; | ||
} | ||
e.getObject = i; | ||
e.getObject = a; | ||
function s(e, t) { | ||
@@ -100,3 +116,3 @@ let n = t; | ||
} else { | ||
n = a(e, t); | ||
n = i(e, t); | ||
} | ||
@@ -133,18 +149,18 @@ return n; | ||
const l = o === "text"; | ||
let a = l ? document.createTextNode("") : document.createElement(o); | ||
let i = l ? document.createTextNode("") : document.createElement(o); | ||
if (Is.defined(n)) { | ||
a.className = n; | ||
i.className = n; | ||
} | ||
if (Is.defined(r)) { | ||
e.insertBefore(a, r); | ||
e.insertBefore(i, r); | ||
} else { | ||
e.appendChild(a); | ||
e.appendChild(i); | ||
} | ||
return a; | ||
return i; | ||
} | ||
e.create = t; | ||
function n(e, n, r, o, l = null) { | ||
const a = t(e, n, r, l); | ||
a.innerHTML = o; | ||
return a; | ||
const i = t(e, n, r, l); | ||
i.innerHTML = o; | ||
return i; | ||
} | ||
@@ -161,2 +177,36 @@ e.createWithHTML = n; | ||
e.cancelBubble = o; | ||
function l() { | ||
const e = document.documentElement; | ||
const t = { | ||
left: e.scrollLeft - (e.clientLeft || 0), | ||
top: e.scrollTop - (e.clientTop || 0) | ||
}; | ||
return t; | ||
} | ||
e.getScrollPosition = l; | ||
function i(e, t) { | ||
let n = e.pageX; | ||
let r = e.pageY; | ||
const o = l(); | ||
t.style.display = "block"; | ||
if (n + t.offsetWidth > window.innerWidth) { | ||
n -= t.offsetWidth; | ||
} else { | ||
n++; | ||
} | ||
if (r + t.offsetHeight > window.innerHeight) { | ||
r -= t.offsetHeight; | ||
} else { | ||
r++; | ||
} | ||
if (n < o.left) { | ||
n = e.pageX + 1; | ||
} | ||
if (r < o.top) { | ||
r = e.pageY + 1; | ||
} | ||
t.style.left = `${n}px`; | ||
t.style.top = `${r}px`; | ||
} | ||
e.showElementAtMousePosition = i; | ||
})(DomElement || (DomElement = {})); | ||
@@ -212,3 +262,3 @@ | ||
let l = o; | ||
const a = t(r); | ||
const i = t(r); | ||
l = l.replace("{hh}", Str.padNumber(r.getHours(), 2)); | ||
@@ -220,4 +270,4 @@ l = l.replace("{h}", r.getHours().toString()); | ||
l = l.replace("{s}", r.getSeconds().toString()); | ||
l = l.replace("{dddd}", e.text.dayNames[a]); | ||
l = l.replace("{ddd}", e.text.dayNamesAbbreviated[a]); | ||
l = l.replace("{dddd}", e.text.dayNames[i]); | ||
l = l.replace("{ddd}", e.text.dayNamesAbbreviated[i]); | ||
l = l.replace("{dd}", Str.padNumber(r.getDate())); | ||
@@ -237,6 +287,2 @@ l = l.replace("{d}", r.getDate().toString()); | ||
e.getCustomFormattedDateText = r; | ||
function o(e) { | ||
return !isNaN(+new Date(e)); | ||
} | ||
e.isDateValid = o; | ||
})(DateTime || (DateTime = {})); | ||
@@ -285,7 +331,9 @@ | ||
t.fileDroppingEnabled = Default.getBoolean(t.fileDroppingEnabled, true); | ||
t.parseStringsToDates = Default.getBoolean(t.parseStringsToDates, false); | ||
t.copyIndentSpaces = Default.getNumber(t.copyIndentSpaces, 2); | ||
t.showArrayIndexBrackets = Default.getBoolean(t.showArrayIndexBrackets, true); | ||
t = o(t); | ||
t = l(t); | ||
t = i(t); | ||
t = a(t); | ||
t = s(t); | ||
return t; | ||
@@ -314,5 +362,20 @@ } | ||
e.ignore.arrayValues = Default.getBoolean(e.ignore.arrayValues, false); | ||
e.ignore.bigIntValues = Default.getBoolean(e.ignore.bigIntValues, false); | ||
e.ignore.symbolValues = Default.getBoolean(e.ignore.symbolValues, false); | ||
e.ignore.emptyObjects = Default.getBoolean(e.ignore.emptyObjects, true); | ||
return e; | ||
} | ||
function i(e) { | ||
e.tooltip = Default.getObject(e.tooltip, {}); | ||
e.tooltip.delay = Default.getNumber(e.tooltip.delay, 750); | ||
return e; | ||
} | ||
function a(e) { | ||
e.parse = Default.getObject(e.parse, {}); | ||
e.parse.stringsToDates = Default.getBoolean(e.parse.stringsToDates, false); | ||
e.parse.stringsToBooleans = Default.getBoolean(e.parse.stringsToBooleans, false); | ||
e.parse.stringsToNumbers = Default.getBoolean(e.parse.stringsToNumbers, false); | ||
return e; | ||
} | ||
function s(e) { | ||
e.events = Default.getObject(e.events, {}); | ||
@@ -330,2 +393,3 @@ e.events.onBeforeRender = Default.getFunction(e.events.onBeforeRender, null); | ||
e.events.onNumberRender = Default.getFunction(e.events.onNumberRender, null); | ||
e.events.onBigIntRender = Default.getFunction(e.events.onBigIntRender, null); | ||
e.events.onStringRender = Default.getFunction(e.events.onStringRender, null); | ||
@@ -336,2 +400,3 @@ e.events.onDateRender = Default.getFunction(e.events.onDateRender, null); | ||
e.events.onUnknownRender = Default.getFunction(e.events.onUnknownRender, null); | ||
e.events.onSymbolRender = Default.getFunction(e.events.onSymbolRender, null); | ||
return e; | ||
@@ -408,2 +473,56 @@ } | ||
var ToolTip; | ||
(e => { | ||
function t(e) { | ||
if (!Is.defined(e._currentView.tooltip)) { | ||
e._currentView.tooltip = DomElement.create(document.body, "div", "jsontree-js-tooltip"); | ||
e._currentView.tooltip.style.display = "none"; | ||
n(e); | ||
} | ||
} | ||
e.renderControl = t; | ||
function n(e, t = true) { | ||
let n = t ? window.addEventListener : window.removeEventListener; | ||
let r = t ? document.addEventListener : document.removeEventListener; | ||
n("mousemove", (() => { | ||
l(e); | ||
})); | ||
r("scroll", (() => { | ||
l(e); | ||
})); | ||
} | ||
e.assignToEvents = n; | ||
function r(e, t, n) { | ||
if (e !== null) { | ||
e.onmousemove = e => { | ||
o(e, t, n); | ||
}; | ||
} | ||
} | ||
e.add = r; | ||
function o(e, t, n) { | ||
DomElement.cancelBubble(e); | ||
l(t); | ||
t._currentView.tooltipTimerId = setTimeout((() => { | ||
t._currentView.tooltip.innerHTML = n; | ||
t._currentView.tooltip.style.display = "block"; | ||
DomElement.showElementAtMousePosition(e, t._currentView.tooltip); | ||
}), t.tooltip.delay); | ||
} | ||
e.show = o; | ||
function l(e) { | ||
if (Is.defined(e._currentView.tooltip)) { | ||
if (e._currentView.tooltipTimerId !== 0) { | ||
clearTimeout(e._currentView.tooltipTimerId); | ||
e._currentView.tooltipTimerId = 0; | ||
} | ||
if (e._currentView.tooltip.style.display !== "none") { | ||
e._currentView.tooltip.style.display = "none"; | ||
} | ||
} | ||
} | ||
e.hide = l; | ||
})(ToolTip || (ToolTip = {})); | ||
(() => { | ||
@@ -451,2 +570,3 @@ let _configuration = {}; | ||
Trigger.customEvent(e.events.onBeforeRender, e._currentView.element); | ||
ToolTip.renderControl(e); | ||
if (!Is.definedString(e._currentView.element.id)) { | ||
@@ -465,2 +585,3 @@ e._currentView.element.id = Str.newGuid(); | ||
let t = _elements_Data[e._currentView.element.id].data; | ||
ToolTip.hide(e); | ||
e._currentView.element.innerHTML = ""; | ||
@@ -494,9 +615,9 @@ renderControlTitleBar(e, t); | ||
const n = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "copy-all", _configuration.text.copyAllButtonSymbolText); | ||
n.title = _configuration.text.copyAllButtonText; | ||
ToolTip.add(n, e, _configuration.text.copyAllButtonText); | ||
n.onclick = () => { | ||
let n = null; | ||
if (e.copyOnlyCurrentPage && e.showArrayItemsAsSeparateObjects) { | ||
n = JSON.stringify(t[e._currentView.dataArrayCurrentIndex], null, e.copyIndentSpaces); | ||
n = JSON.stringify(t[e._currentView.dataArrayCurrentIndex], jsonStringifyReplacer, e.copyIndentSpaces); | ||
} else { | ||
n = JSON.stringify(t, null, e.copyIndentSpaces); | ||
n = JSON.stringify(t, jsonStringifyReplacer, e.copyIndentSpaces); | ||
} | ||
@@ -509,5 +630,5 @@ navigator.clipboard.writeText(n); | ||
const t = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "openAll", _configuration.text.openAllButtonSymbolText); | ||
t.title = _configuration.text.openAllButtonText; | ||
ToolTip.add(t, e, _configuration.text.openAllButtonText); | ||
const n = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "closeAll", _configuration.text.closeAllButtonSymbolText); | ||
n.title = _configuration.text.closeAllButtonText; | ||
ToolTip.add(n, e, _configuration.text.closeAllButtonText); | ||
t.onclick = () => { | ||
@@ -522,3 +643,3 @@ openAllNodes(e); | ||
const n = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "back", _configuration.text.backButtonSymbolText); | ||
n.title = _configuration.text.backButtonText; | ||
ToolTip.add(n, e, _configuration.text.backButtonText); | ||
if (e._currentView.dataArrayCurrentIndex > 0) { | ||
@@ -534,3 +655,3 @@ n.onclick = () => { | ||
const r = DomElement.createWithHTML(e._currentView.titleBarButtons, "button", "next", _configuration.text.nextButtonSymbolText); | ||
r.title = _configuration.text.nextButtonText; | ||
ToolTip.add(r, e, _configuration.text.nextButtonText); | ||
if (e._currentView.dataArrayCurrentIndex < t.length - 1) { | ||
@@ -552,2 +673,12 @@ r.onclick = () => { | ||
} | ||
function jsonStringifyReplacer(e, t) { | ||
if (Is.definedBigInt(t)) { | ||
t = t.toString(); | ||
} else if (Is.definedSymbol(t)) { | ||
t = t.toString(); | ||
} else if (Is.definedFunction(t)) { | ||
t = Default.getFunctionName(t); | ||
} | ||
return t; | ||
} | ||
function openAllNodes(e) { | ||
@@ -566,12 +697,20 @@ e.showAllAsClosed = false; | ||
const l = DomElement.create(e, "div", "object-type-contents"); | ||
const a = t.showArrowToggles ? DomElement.create(o, "div", "down-arrow") : null; | ||
const i = renderObjectValues(a, l, t, n); | ||
const s = DomElement.createWithHTML(o, "span", t.showValueColors ? "object" : "", _configuration.text.objectText); | ||
if (r && t.showArrayItemsAsSeparateObjects) { | ||
let e = t.useZeroIndexingForArrays ? t._currentView.dataArrayCurrentIndex.toString() : (t._currentView.dataArrayCurrentIndex + 1).toString(); | ||
DomElement.createWithHTML(o, "span", t.showValueColors ? "object data-array-index" : "data-array-index", `[${e}]:`, s); | ||
const i = t.showArrowToggles ? DomElement.create(o, "div", "down-arrow") : null; | ||
const a = renderObjectValues(i, l, t, n); | ||
if (a === 0 && t.ignore.emptyObjects) { | ||
e.removeChild(o); | ||
e.removeChild(l); | ||
} else { | ||
const e = DomElement.createWithHTML(o, "span", t.showValueColors ? "object" : "", _configuration.text.objectText); | ||
if (r && t.showArrayItemsAsSeparateObjects) { | ||
let n = t.useZeroIndexingForArrays ? t._currentView.dataArrayCurrentIndex.toString() : (t._currentView.dataArrayCurrentIndex + 1).toString(); | ||
if (t.showArrayIndexBrackets) { | ||
n = `[${n}]:`; | ||
} | ||
DomElement.createWithHTML(o, "span", t.showValueColors ? "object data-array-index" : "data-array-index", n, e); | ||
} | ||
if (t.showCounts && a > 0) { | ||
DomElement.createWithHTML(o, "span", t.showValueColors ? "object count" : "count", `{${a}}`); | ||
} | ||
} | ||
if (t.showCounts && i > 0) { | ||
DomElement.createWithHTML(o, "span", t.showValueColors ? "object count" : "count", `{${i}}`); | ||
} | ||
} | ||
@@ -597,3 +736,7 @@ function renderArray(e, t, n) { | ||
if (n.sortPropertyNames) { | ||
l = l.sort(); | ||
let e = new Intl.Collator(void 0, { | ||
numeric: true, | ||
sensitivity: "base" | ||
}); | ||
l = l.sort(e.compare); | ||
if (!n.sortPropertyNamesInAlphabeticalOrder) { | ||
@@ -603,7 +746,7 @@ l = l.reverse(); | ||
} | ||
const a = l.length; | ||
for (let e = 0; e < a; e++) { | ||
const i = l[e]; | ||
if (r.hasOwnProperty(i)) { | ||
renderValue(t, n, i, r[i], e === a - 1); | ||
const i = l.length; | ||
for (let e = 0; e < i; e++) { | ||
const a = l[e]; | ||
if (r.hasOwnProperty(a)) { | ||
renderValue(t, n, a, r[a], e === i - 1); | ||
o++; | ||
@@ -630,8 +773,7 @@ } | ||
const l = DomElement.create(e, "div", "object-type-value"); | ||
const a = t.showArrowToggles ? DomElement.create(l, "div", "no-arrow") : null; | ||
let i = null; | ||
const i = t.showArrowToggles ? DomElement.create(l, "div", "no-arrow") : null; | ||
let a = null; | ||
let s = null; | ||
let u = false; | ||
let c = null; | ||
let d = true; | ||
DomElement.createWithHTML(l, "span", "title", n); | ||
@@ -641,5 +783,5 @@ DomElement.createWithHTML(l, "span", "split", ":"); | ||
if (!t.ignore.nullValues) { | ||
i = t.showValueColors ? "null" : ""; | ||
s = DomElement.createWithHTML(l, "span", i, "null"); | ||
d = false; | ||
a = t.showValueColors ? "null" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, "null"); | ||
c = "null"; | ||
if (Is.definedFunction(t.events.onNullRender)) { | ||
@@ -654,4 +796,4 @@ Trigger.customEvent(t.events.onNullRender, s); | ||
if (!t.ignore.functionValues) { | ||
i = t.showValueColors ? "function" : ""; | ||
s = DomElement.createWithHTML(l, "span", i, Default.getFunctionName(r)); | ||
a = t.showValueColors ? "function" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, Default.getFunctionName(r)); | ||
c = "function"; | ||
@@ -667,4 +809,4 @@ if (Is.definedFunction(t.events.onFunctionRender)) { | ||
if (!t.ignore.booleanValues) { | ||
i = t.showValueColors ? "boolean" : ""; | ||
s = DomElement.createWithHTML(l, "span", i, r); | ||
a = t.showValueColors ? "boolean" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, r); | ||
c = "boolean"; | ||
@@ -681,4 +823,4 @@ if (Is.definedFunction(t.events.onBooleanRender)) { | ||
const e = Default.getFixedDecimalPlacesValue(r, t.maximumDecimalPlaces); | ||
i = t.showValueColors ? "decimal" : ""; | ||
s = DomElement.createWithHTML(l, "span", i, e); | ||
a = t.showValueColors ? "decimal" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, e); | ||
c = "decimal"; | ||
@@ -694,4 +836,4 @@ if (Is.definedFunction(t.events.onDecimalRender)) { | ||
if (!t.ignore.numberValues) { | ||
i = t.showValueColors ? "number" : ""; | ||
s = DomElement.createWithHTML(l, "span", i, r); | ||
a = t.showValueColors ? "number" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, r); | ||
c = "number"; | ||
@@ -705,5 +847,23 @@ if (Is.definedFunction(t.events.onNumberRender)) { | ||
} | ||
} else if (Is.definedBigInt(r)) { | ||
if (!t.ignore.bigIntValues) { | ||
a = t.showValueColors ? "bigint" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, r); | ||
c = "bigint"; | ||
if (Is.definedFunction(t.events.onBigIntRender)) { | ||
Trigger.customEvent(t.events.onBigIntRender, s); | ||
} | ||
createComma(t, l, o); | ||
} else { | ||
u = true; | ||
} | ||
} else if (Is.definedString(r)) { | ||
if (!t.ignore.stringValues) { | ||
if (t.parseStringsToDates && DateTime.isDateValid(r)) { | ||
if (t.parse.stringsToBooleans && Is.stringValueBoolean(r)) { | ||
renderValue(e, t, n, r.toString().toLowerCase().trim() === "true", o); | ||
u = true; | ||
} else if (t.parse.stringsToNumbers && !isNaN(r)) { | ||
renderValue(e, t, n, parseFloat(r), o); | ||
u = true; | ||
} else if (t.parse.stringsToDates && Is.stringValueDate(r)) { | ||
renderValue(e, t, n, new Date(r), o); | ||
@@ -721,4 +881,4 @@ u = true; | ||
const n = t.showStringQuotes ? `"${r}"` : r; | ||
i = t.showValueColors ? "string" : ""; | ||
s = DomElement.createWithHTML(l, "span", i, n); | ||
a = t.showValueColors ? "string" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, n); | ||
c = "string"; | ||
@@ -738,4 +898,4 @@ if (Is.definedString(e)) { | ||
if (!t.ignore.dateValues) { | ||
i = t.showValueColors ? "date" : ""; | ||
s = DomElement.createWithHTML(l, "span", i, DateTime.getCustomFormattedDateText(_configuration, r, t.dateTimeFormat)); | ||
a = t.showValueColors ? "date" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, DateTime.getCustomFormattedDateText(_configuration, r, t.dateTimeFormat)); | ||
c = "date"; | ||
@@ -749,2 +909,14 @@ if (Is.definedFunction(t.events.onDateRender)) { | ||
} | ||
} else if (Is.definedSymbol(r)) { | ||
if (!t.ignore.symbolValues) { | ||
a = t.showValueColors ? "symbol" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, r.toString()); | ||
c = "symbol"; | ||
if (Is.definedFunction(t.events.onSymbolRender)) { | ||
Trigger.customEvent(t.events.onSymbolRender, s); | ||
} | ||
createComma(t, l, o); | ||
} else { | ||
u = true; | ||
} | ||
} else if (Is.definedObject(r) && !Is.definedArray(r)) { | ||
@@ -754,9 +926,13 @@ if (!t.ignore.objectValues) { | ||
const n = DomElement.create(l, "div", "object-type-contents"); | ||
const i = renderObjectValues(a, n, t, r); | ||
DomElement.createWithHTML(e, "span", "title", _configuration.text.objectText); | ||
if (t.showCounts && i > 0) { | ||
DomElement.createWithHTML(e, "span", "count", `{${i}}`); | ||
const a = renderObjectValues(i, n, t, r); | ||
if (a === 0 && t.ignore.emptyObjects) { | ||
u = true; | ||
} else { | ||
DomElement.createWithHTML(e, "span", "title", _configuration.text.objectText); | ||
if (t.showCounts && a > 0) { | ||
DomElement.createWithHTML(e, "span", "count", `{${a}}`); | ||
} | ||
createComma(t, e, o); | ||
c = "object"; | ||
} | ||
createComma(t, e, o); | ||
c = "object"; | ||
} else { | ||
@@ -774,3 +950,3 @@ u = true; | ||
createComma(t, e, o); | ||
renderArrayValues(a, n, t, r); | ||
renderArrayValues(i, n, t, r); | ||
c = "array"; | ||
@@ -782,4 +958,4 @@ } else { | ||
if (!t.ignore.unknownValues) { | ||
i = t.showValueColors ? "unknown" : ""; | ||
s = DomElement.createWithHTML(l, "span", i, r.toString()); | ||
a = t.showValueColors ? "unknown" : ""; | ||
s = DomElement.createWithHTML(l, "span", a, r.toString()); | ||
c = "unknown"; | ||
@@ -798,8 +974,8 @@ if (Is.definedFunction(t.events.onUnknownRender)) { | ||
if (Is.defined(s)) { | ||
addValueClickEvent(t, s, r, c, d); | ||
addValueClickEvent(t, s, r, c); | ||
} | ||
} | ||
} | ||
function addValueClickEvent(e, t, n, r, o) { | ||
if (o && Is.definedFunction(e.events.onValueClick)) { | ||
function addValueClickEvent(e, t, n, r) { | ||
if (Is.definedFunction(e.events.onValueClick)) { | ||
t.onclick = () => { | ||
@@ -841,3 +1017,6 @@ Trigger.customEvent(e.events.onValueClick, n, r); | ||
} | ||
return `[${r}]`; | ||
if (e.showArrayIndexBrackets) { | ||
r = `[${r}]`; | ||
} | ||
return r; | ||
} | ||
@@ -912,2 +1091,3 @@ function makeAreaDroppable(e, t) { | ||
e._currentView.element.className = ""; | ||
ToolTip.assignToEvents(e, false); | ||
Trigger.customEvent(e.events.onDestroy, e._currentView.element); | ||
@@ -1024,3 +1204,3 @@ } | ||
getVersion: function() { | ||
return "2.2.0"; | ||
return "2.3.0"; | ||
} | ||
@@ -1027,0 +1207,0 @@ }; |
@@ -1,1 +0,1 @@ | ||
"use strict";var Is,Default,DomElement,Str,Str2,DateTime,Constants,Binding,Config,Trigger;(e=>{function t(e){return null!=e&&""!==e.toString()}function n(e){return t(e)&&"object"==typeof e}function r(e){return n(e)&&e instanceof Array}e.defined=t,e.definedObject=n,e.definedBoolean=function(e){return t(e)&&"boolean"==typeof e},e.definedString=function(e){return t(e)&&"string"==typeof e},e.definedFunction=function(e){return t(e)&&"function"==typeof e},e.definedNumber=function(e){return t(e)&&"number"==typeof e},e.definedArray=r,e.definedDate=function(e){return n(e)&&e instanceof Date},e.definedDecimal=function(e){return t(e)&&"number"==typeof e&&e%1!=0},e.invalidOptionArray=function(e,t=1){return!r(e)||e.length<t},e.hexColor=function(e){let t=e.length>=2&&e.length<=7;return t&&"#"===e[0]&&(t=isNaN(+e.substring(1,e.length-1))),t}})(Is||(Is={})),(e=>{function t(e,t){return Is.definedArray(e)?e:t}e.getAnyString=function(e,t){return"string"==typeof e?e:t},e.getString=function(e,t){return Is.definedString(e)?e:t},e.getBoolean=function(e,t){return Is.definedBoolean(e)?e:t},e.getNumber=function(e,t){return Is.definedNumber(e)?e:t},e.getFunction=function(e,t){return Is.definedFunction(e)?e:t},e.getArray=t,e.getObject=function(e,t){return Is.definedObject(e)?e:t},e.getStringOrArray=function(e,n){let r=n;if(Is.definedString(e)){const t=e.toString().split(" ");0===t.length?e=n:r=t}else r=t(e,n);return r},e.getFixedDecimalPlacesValue=function(e,t){var n;const r=new RegExp(`^-?\\d+(?:.\\d{0,${t||-1}})?`);return(null==(n=e.toString().match(r))?void 0:n[0])||""},e.getFunctionName=function(e){let t;const n=e.toString().split("(")[0].split(" ");return t=2===n.length?n[1]:n[0],t+="()",t}})(Default||(Default={})),(e=>{function t(e,t,n="",r=null){const o=t.toLowerCase();let l="text"===o?document.createTextNode(""):document.createElement(o);return Is.defined(n)&&(l.className=n),Is.defined(r)?e.insertBefore(l,r):e.appendChild(l),l}e.create=t,e.createWithHTML=function(e,n,r,o,l=null){const a=t(e,n,r,l);return a.innerHTML=o,a},e.addClass=function(e,t){e.classList.add(t)},e.cancelBubble=function(e){e.preventDefault(),e.stopPropagation()}})(DomElement||(DomElement={})),Str2=Str||(Str={}),Str2.newGuid=function(){const e=[];for(let t=0;t<32;t++){8!==t&&12!==t&&16!==t&&20!==t||e.push("-");const n=Math.floor(16*Math.random()).toString(16);e.push(n)}return e.join("")},Str2.padNumber=function(e,t=1){const n=e.toString();let r=n;if(n.length<t){const e=t-n.length+1;r=Array(e).join("0")+n}return r},(e=>{function t(e){return e.getDay()-1<0?6:e.getDay()-1}function n(e,t){let n=e.text.thText;return 31===t||21===t||1===t?n=e.text.stText:22===t||2===t?n=e.text.ndText:23!==t&&3!==t||(n=e.text.rdText),n}e.getWeekdayNumber=t,e.getDayOrdinal=n,e.getCustomFormattedDateText=function(e,r,o){let l=o;const a=t(r);return l=l.replace("{hh}",Str.padNumber(r.getHours(),2)),l=l.replace("{h}",r.getHours().toString()),l=l.replace("{MM}",Str.padNumber(r.getMinutes(),2)),l=l.replace("{M}",r.getMinutes().toString()),l=l.replace("{ss}",Str.padNumber(r.getSeconds(),2)),l=l.replace("{s}",r.getSeconds().toString()),l=l.replace("{dddd}",e.text.dayNames[a]),l=l.replace("{ddd}",e.text.dayNamesAbbreviated[a]),l=l.replace("{dd}",Str.padNumber(r.getDate())),l=l.replace("{d}",r.getDate().toString()),l=l.replace("{o}",n(e,r.getDate())),l=l.replace("{mmmm}",e.text.monthNames[r.getMonth()]),l=l.replace("{mmm}",e.text.monthNamesAbbreviated[r.getMonth()]),l=l.replace("{mm}",Str.padNumber(r.getMonth()+1)),l=l.replace("{m}",(r.getMonth()+1).toString()),l=l.replace("{yyyy}",r.getFullYear().toString()),l=l.replace("{yyy}",r.getFullYear().toString().substring(1)),l=l.replace("{yy}",r.getFullYear().toString().substring(2)),l=l.replace("{y}",Number.parseInt(r.getFullYear().toString().substring(2)).toString()),l},e.isDateValid=function(e){return!isNaN(+new Date(e))}})(DateTime||(DateTime={})),(Constants||(Constants={})).JSONTREE_JS_ATTRIBUTE_NAME="data-jsontree-js",(e=>{let t;var n;(n=t=e.Options||(e.Options={})).getForNewInstance=function(t,n){const r=e.Options.get(t);return r._currentView={},r._currentView.element=n,r._currentView.dataArrayCurrentIndex=0,r._currentView.titleBarButtons=null,r},n.get=function(e){let t=Default.getObject(e,{});return t.data=Default.getObject(t.data,null),t.showCounts=Default.getBoolean(t.showCounts,!0),t.useZeroIndexingForArrays=Default.getBoolean(t.useZeroIndexingForArrays,!0),t.dateTimeFormat=Default.getString(t.dateTimeFormat,"{dd}{o} {mmmm} {yyyy} {hh}:{MM}:{ss}"),t.showArrowToggles=Default.getBoolean(t.showArrowToggles,!0),t.showStringQuotes=Default.getBoolean(t.showStringQuotes,!0),t.showAllAsClosed=Default.getBoolean(t.showAllAsClosed,!1),t.sortPropertyNames=Default.getBoolean(t.sortPropertyNames,!0),t.sortPropertyNamesInAlphabeticalOrder=Default.getBoolean(t.sortPropertyNamesInAlphabeticalOrder,!0),t.showCommas=Default.getBoolean(t.showCommas,!1),t.reverseArrayValues=Default.getBoolean(t.reverseArrayValues,!1),t.addArrayIndexPadding=Default.getBoolean(t.addArrayIndexPadding,!1),t.showValueColors=Default.getBoolean(t.showValueColors,!0),t.maximumDecimalPlaces=Default.getNumber(t.maximumDecimalPlaces,2),t.maximumStringLength=Default.getNumber(t.maximumStringLength,0),t.showStringHexColors=Default.getBoolean(t.showStringHexColors,!1),t.showArrayItemsAsSeparateObjects=Default.getBoolean(t.showArrayItemsAsSeparateObjects,!1),t.copyOnlyCurrentPage=Default.getBoolean(t.copyOnlyCurrentPage,!1),t.fileDroppingEnabled=Default.getBoolean(t.fileDroppingEnabled,!0),t.parseStringsToDates=Default.getBoolean(t.parseStringsToDates,!1),t.copyIndentSpaces=Default.getNumber(t.copyIndentSpaces,2),t=function(e){return e.title=Default.getObject(e.title,{}),e.title.text=Default.getString(e.title.text,"JsonTree.js"),e.title.show=Default.getBoolean(e.title.show,!0),e.title.showTreeControls=Default.getBoolean(e.title.showTreeControls,!0),e.title.showCopyButton=Default.getBoolean(e.title.showCopyButton,!0),e}(t),t=function(e){return e.ignore=Default.getObject(e.ignore,{}),e.ignore.nullValues=Default.getBoolean(e.ignore.nullValues,!1),e.ignore.functionValues=Default.getBoolean(e.ignore.functionValues,!1),e.ignore.unknownValues=Default.getBoolean(e.ignore.unknownValues,!1),e.ignore.booleanValues=Default.getBoolean(e.ignore.booleanValues,!1),e.ignore.decimalValues=Default.getBoolean(e.ignore.decimalValues,!1),e.ignore.numberValues=Default.getBoolean(e.ignore.numberValues,!1),e.ignore.stringValues=Default.getBoolean(e.ignore.stringValues,!1),e.ignore.dateValues=Default.getBoolean(e.ignore.dateValues,!1),e.ignore.objectValues=Default.getBoolean(e.ignore.objectValues,!1),e.ignore.arrayValues=Default.getBoolean(e.ignore.arrayValues,!1),e}(t),t=function(e){return e.events=Default.getObject(e.events,{}),e.events.onBeforeRender=Default.getFunction(e.events.onBeforeRender,null),e.events.onRenderComplete=Default.getFunction(e.events.onRenderComplete,null),e.events.onValueClick=Default.getFunction(e.events.onValueClick,null),e.events.onRefresh=Default.getFunction(e.events.onRefresh,null),e.events.onCopyAll=Default.getFunction(e.events.onCopyAll,null),e.events.onOpenAll=Default.getFunction(e.events.onOpenAll,null),e.events.onCloseAll=Default.getFunction(e.events.onCloseAll,null),e.events.onDestroy=Default.getFunction(e.events.onDestroy,null),e.events.onBooleanRender=Default.getFunction(e.events.onBooleanRender,null),e.events.onDecimalRender=Default.getFunction(e.events.onDecimalRender,null),e.events.onNumberRender=Default.getFunction(e.events.onNumberRender,null),e.events.onStringRender=Default.getFunction(e.events.onStringRender,null),e.events.onDateRender=Default.getFunction(e.events.onDateRender,null),e.events.onFunctionRender=Default.getFunction(e.events.onFunctionRender,null),e.events.onNullRender=Default.getFunction(e.events.onNullRender,null),e.events.onUnknownRender=Default.getFunction(e.events.onUnknownRender,null),e}(t),t}})(Binding||(Binding={})),(e=>{let t;(t=e.Options||(e.Options={})).get=function(e=null){let t=Default.getObject(e,{});return t.safeMode=Default.getBoolean(t.safeMode,!0),t.domElementTypes=Default.getStringOrArray(t.domElementTypes,["*"]),t=function(e){return e.text=Default.getObject(e.text,{}),e.text.objectText=Default.getAnyString(e.text.objectText,"object"),e.text.arrayText=Default.getAnyString(e.text.arrayText,"array"),e.text.closeAllButtonText=Default.getAnyString(e.text.closeAllButtonText,"Close All"),e.text.openAllButtonText=Default.getAnyString(e.text.openAllButtonText,"Open All"),e.text.copyAllButtonText=Default.getAnyString(e.text.copyAllButtonText,"Copy All"),e.text.objectErrorText=Default.getAnyString(e.text.objectErrorText,"Errors in object: {{error_1}}, {{error_2}}"),e.text.attributeNotValidErrorText=Default.getAnyString(e.text.attributeNotValidErrorText,"The attribute '{{attribute_name}}' is not a valid object."),e.text.attributeNotSetErrorText=Default.getAnyString(e.text.attributeNotSetErrorText,"The attribute '{{attribute_name}}' has not been set correctly."),e.text.stText=Default.getAnyString(e.text.stText,"st"),e.text.ndText=Default.getAnyString(e.text.ndText,"nd"),e.text.rdText=Default.getAnyString(e.text.rdText,"rd"),e.text.thText=Default.getAnyString(e.text.thText,"th"),e.text.ellipsisText=Default.getAnyString(e.text.ellipsisText,"..."),e.text.closeAllButtonSymbolText=Default.getAnyString(e.text.closeAllButtonSymbolText,"↑"),e.text.openAllButtonSymbolText=Default.getAnyString(e.text.openAllButtonSymbolText,"↓"),e.text.copyAllButtonSymbolText=Default.getAnyString(e.text.copyAllButtonSymbolText,"❐"),e.text.backButtonText=Default.getAnyString(e.text.backButtonText,"Back"),e.text.nextButtonText=Default.getAnyString(e.text.nextButtonText,"Next"),e.text.backButtonSymbolText=Default.getAnyString(e.text.backButtonSymbolText,"←"),e.text.nextButtonSymbolText=Default.getAnyString(e.text.nextButtonSymbolText,"→"),e.text.noJsonToViewText=Default.getAnyString(e.text.noJsonToViewText,"There is currently no JSON to view."),Is.invalidOptionArray(e.text.dayNames,7)&&(e.text.dayNames=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]),Is.invalidOptionArray(e.text.dayNamesAbbreviated,7)&&(e.text.dayNamesAbbreviated=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]),Is.invalidOptionArray(e.text.monthNames,12)&&(e.text.monthNames=["January","February","March","April","May","June","July","August","September","October","November","December"]),Is.invalidOptionArray(e.text.monthNamesAbbreviated,12)&&(e.text.monthNamesAbbreviated=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]),e}(t),t}})(Config||(Config={})),(Trigger||(Trigger={})).customEvent=function(e,...t){let n=null;return Is.definedFunction(e)&&(n=e.apply(null,[].slice.call(t,0))),n},(()=>{let _configuration={},_elements_Data={};function render(){const e=_configuration.domElementTypes,t=e.length;for(let n=0;n<t;n++){const t=document.getElementsByTagName(e[n]),r=[].slice.call(t),o=r.length;for(let e=0;e<o&&renderElement(r[e]);e++);}}function renderElement(e){let t=!0;if(Is.defined(e)&&e.hasAttribute(Constants.JSONTREE_JS_ATTRIBUTE_NAME)){const n=e.getAttribute(Constants.JSONTREE_JS_ATTRIBUTE_NAME);if(Is.definedString(n)){const r=getObjectFromString(n);r.parsed&&Is.definedObject(r.object)?renderControl(Binding.Options.getForNewInstance(r.object,e)):_configuration.safeMode||(console.error(_configuration.text.attributeNotValidErrorText.replace("{{attribute_name}}",Constants.JSONTREE_JS_ATTRIBUTE_NAME)),t=!1)}else _configuration.safeMode||(console.error(_configuration.text.attributeNotSetErrorText.replace("{{attribute_name}}",Constants.JSONTREE_JS_ATTRIBUTE_NAME)),t=!1)}return t}function renderControl(e){Trigger.customEvent(e.events.onBeforeRender,e._currentView.element),Is.definedString(e._currentView.element.id)||(e._currentView.element.id=Str.newGuid()),e._currentView.element.className="json-tree-js",e._currentView.element.removeAttribute(Constants.JSONTREE_JS_ATTRIBUTE_NAME),_elements_Data.hasOwnProperty(e._currentView.element.id)||(_elements_Data[e._currentView.element.id]=e),renderControlContainer(e),Trigger.customEvent(e.events.onRenderComplete,e._currentView.element)}function renderControlContainer(e){let t=_elements_Data[e._currentView.element.id].data;e._currentView.element.innerHTML="",renderControlTitleBar(e,t);const n=DomElement.create(e._currentView.element,"div","contents");makeAreaDroppable(n,e),e.showArrayItemsAsSeparateObjects&&Is.definedArray(t)&&(t=t[e._currentView.dataArrayCurrentIndex]),Is.definedObject(t)&&!Is.definedArray(t)?renderObject(n,e,t,!0):Is.definedArray(t)&&renderArray(n,e,t),""===n.innerHTML?(DomElement.createWithHTML(n,"span","no-json-text",_configuration.text.noJsonToViewText),e._currentView.titleBarButtons.style.display="none"):e._currentView.titleBarButtons.style.display="block"}function renderControlTitleBar(e,t){if(e.title.show||e.title.showTreeControls||e.title.showCopyButton){const n=DomElement.create(e._currentView.element,"div","title-bar");if(e._currentView.titleBarButtons=DomElement.create(n,"div","controls"),e.title.show&&DomElement.createWithHTML(n,"div","title",e.title.text,e._currentView.titleBarButtons),e.title.showCopyButton){const n=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","copy-all",_configuration.text.copyAllButtonSymbolText);n.title=_configuration.text.copyAllButtonText,n.onclick=()=>{let n=null;n=e.copyOnlyCurrentPage&&e.showArrayItemsAsSeparateObjects?JSON.stringify(t[e._currentView.dataArrayCurrentIndex],null,e.copyIndentSpaces):JSON.stringify(t,null,e.copyIndentSpaces),navigator.clipboard.writeText(n),Trigger.customEvent(e.events.onCopyAll,n)}}if(e.title.showTreeControls){const t=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","openAll",_configuration.text.openAllButtonSymbolText);t.title=_configuration.text.openAllButtonText;const n=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","closeAll",_configuration.text.closeAllButtonSymbolText);n.title=_configuration.text.closeAllButtonText,t.onclick=()=>{openAllNodes(e)},n.onclick=()=>{closeAllNodes(e)}}if(e.showArrayItemsAsSeparateObjects&&Is.definedArray(t)&&t.length>1){const n=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","back",_configuration.text.backButtonSymbolText);n.title=_configuration.text.backButtonText,e._currentView.dataArrayCurrentIndex>0?n.onclick=()=>{e._currentView.dataArrayCurrentIndex--,renderControlContainer(e),Trigger.customEvent(e.events.onBackPage,e._currentView.element)}:n.disabled=!0;const r=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","next",_configuration.text.nextButtonSymbolText);r.title=_configuration.text.nextButtonText,e._currentView.dataArrayCurrentIndex<t.length-1?r.onclick=()=>{e._currentView.dataArrayCurrentIndex++,renderControlContainer(e),Trigger.customEvent(e.events.onNextPage,e._currentView.element)}:r.disabled=!0}else Is.definedArray(t)&&(e.showArrayItemsAsSeparateObjects=!1)}}function openAllNodes(e){e.showAllAsClosed=!1,renderControlContainer(e),Trigger.customEvent(e.events.onOpenAll,e._currentView.element)}function closeAllNodes(e){e.showAllAsClosed=!0,renderControlContainer(e),Trigger.customEvent(e.events.onCloseAll,e._currentView.element)}function renderObject(e,t,n,r=!1){const o=DomElement.create(e,"div","object-type-title"),l=DomElement.create(e,"div","object-type-contents"),a=renderObjectValues(t.showArrowToggles?DomElement.create(o,"div","down-arrow"):null,l,t,n),i=DomElement.createWithHTML(o,"span",t.showValueColors?"object":"",_configuration.text.objectText);if(r&&t.showArrayItemsAsSeparateObjects){let e=t.useZeroIndexingForArrays?t._currentView.dataArrayCurrentIndex.toString():(t._currentView.dataArrayCurrentIndex+1).toString();DomElement.createWithHTML(o,"span",t.showValueColors?"object data-array-index":"data-array-index",`[${e}]:`,i)}t.showCounts&&a>0&&DomElement.createWithHTML(o,"span",t.showValueColors?"object count":"count",`{${a}}`)}function renderArray(e,t,n){const r=DomElement.create(e,"div","object-type-title"),o=DomElement.create(e,"div","object-type-contents"),l=t.showArrowToggles?DomElement.create(r,"div","down-arrow"):null;DomElement.createWithHTML(r,"span",t.showValueColors?"array":"",_configuration.text.arrayText),renderArrayValues(l,o,t,n),t.showCounts&&DomElement.createWithHTML(r,"span",t.showValueColors?"array count":"count",`[${n.length}]`)}function renderObjectValues(e,t,n,r){let o=0,l=[];for(let e in r)r.hasOwnProperty(e)&&l.push(e);n.sortPropertyNames&&(l=l.sort(),n.sortPropertyNamesInAlphabeticalOrder||(l=l.reverse()));const a=l.length;for(let e=0;e<a;e++){const i=l[e];r.hasOwnProperty(i)&&(renderValue(t,n,i,r[i],e===a-1),o++)}return addArrowEvent(n,e,t),o}function renderArrayValues(e,t,n,r){const o=r.length;if(n.reverseArrayValues)for(let e=o;e--;)renderValue(t,n,getIndexName(n,e,o),r[e],0===e);else for(let e=0;e<o;e++)renderValue(t,n,getIndexName(n,e,o),r[e],e===o-1);addArrowEvent(n,e,t)}function renderValue(e,t,n,r,o){const l=DomElement.create(e,"div","object-type-value"),a=t.showArrowToggles?DomElement.create(l,"div","no-arrow"):null;let i=null,s=null,u=!1,c=null,d=!0;if(DomElement.createWithHTML(l,"span","title",n),DomElement.createWithHTML(l,"span","split",":"),Is.defined(r))if(Is.definedFunction(r))t.ignore.functionValues?u=!0:(i=t.showValueColors?"function":"",s=DomElement.createWithHTML(l,"span",i,Default.getFunctionName(r)),c="function",Is.definedFunction(t.events.onFunctionRender)&&Trigger.customEvent(t.events.onFunctionRender,s),createComma(t,l,o));else if(Is.definedBoolean(r))t.ignore.booleanValues?u=!0:(i=t.showValueColors?"boolean":"",s=DomElement.createWithHTML(l,"span",i,r),c="boolean",Is.definedFunction(t.events.onBooleanRender)&&Trigger.customEvent(t.events.onBooleanRender,s),createComma(t,l,o));else if(Is.definedDecimal(r))if(t.ignore.decimalValues)u=!0;else{const e=Default.getFixedDecimalPlacesValue(r,t.maximumDecimalPlaces);i=t.showValueColors?"decimal":"",s=DomElement.createWithHTML(l,"span",i,e),c="decimal",Is.definedFunction(t.events.onDecimalRender)&&Trigger.customEvent(t.events.onDecimalRender,s),createComma(t,l,o)}else if(Is.definedNumber(r))t.ignore.numberValues?u=!0:(i=t.showValueColors?"number":"",s=DomElement.createWithHTML(l,"span",i,r),c="number",Is.definedFunction(t.events.onNumberRender)&&Trigger.customEvent(t.events.onNumberRender,s),createComma(t,l,o));else if(Is.definedString(r))if(t.ignore.stringValues)u=!0;else if(t.parseStringsToDates&&DateTime.isDateValid(r))renderValue(e,t,n,new Date(r),o),u=!0;else{let e=null;t.showValueColors&&t.showStringHexColors&&Is.hexColor(r)?e=r:t.maximumStringLength>0&&r.length>t.maximumStringLength&&(r=r.substring(0,t.maximumStringLength)+_configuration.text.ellipsisText);const n=t.showStringQuotes?`"${r}"`:r;i=t.showValueColors?"string":"",s=DomElement.createWithHTML(l,"span",i,n),c="string",Is.definedString(e)&&(s.style.color=e),Is.definedFunction(t.events.onStringRender)&&Trigger.customEvent(t.events.onStringRender,s),createComma(t,l,o)}else if(Is.definedDate(r))t.ignore.dateValues?u=!0:(i=t.showValueColors?"date":"",s=DomElement.createWithHTML(l,"span",i,DateTime.getCustomFormattedDateText(_configuration,r,t.dateTimeFormat)),c="date",Is.definedFunction(t.events.onDateRender)&&Trigger.customEvent(t.events.onDateRender,s),createComma(t,l,o));else if(Is.definedObject(r)&&!Is.definedArray(r))if(t.ignore.objectValues)u=!0;else{const e=DomElement.create(l,"span",t.showValueColors?"object":""),n=renderObjectValues(a,DomElement.create(l,"div","object-type-contents"),t,r);DomElement.createWithHTML(e,"span","title",_configuration.text.objectText),t.showCounts&&n>0&&DomElement.createWithHTML(e,"span","count",`{${n}}`),createComma(t,e,o),c="object"}else if(Is.definedArray(r))if(t.ignore.arrayValues)u=!0;else{const e=DomElement.create(l,"span",t.showValueColors?"array":""),n=DomElement.create(l,"div","object-type-contents");DomElement.createWithHTML(e,"span","title",_configuration.text.arrayText),t.showCounts&&DomElement.createWithHTML(e,"span","count",`[${r.length}]`),createComma(t,e,o),renderArrayValues(a,n,t,r),c="array"}else t.ignore.unknownValues?u=!0:(i=t.showValueColors?"unknown":"",s=DomElement.createWithHTML(l,"span",i,r.toString()),c="unknown",Is.definedFunction(t.events.onUnknownRender)&&Trigger.customEvent(t.events.onUnknownRender,s),createComma(t,l,o));else t.ignore.nullValues?u=!0:(i=t.showValueColors?"null":"",s=DomElement.createWithHTML(l,"span",i,"null"),d=!1,Is.definedFunction(t.events.onNullRender)&&Trigger.customEvent(t.events.onNullRender,s),createComma(t,l,o));u?e.removeChild(l):Is.defined(s)&&addValueClickEvent(t,s,r,c,d)}function addValueClickEvent(e,t,n,r,o){o&&Is.definedFunction(e.events.onValueClick)?t.onclick=()=>{Trigger.customEvent(e.events.onValueClick,n,r)}:DomElement.addClass(t,"no-hover")}function addArrowEvent(e,t,n){Is.defined(t)&&(t.onclick=()=>{"down-arrow"===t.className?(n.style.display="none",t.className="right-arrow"):(n.style.display="block",t.className="down-arrow")},e.showAllAsClosed?(n.style.display="none",t.className="right-arrow"):t.className="down-arrow")}function createComma(e,t,n){e.showCommas&&!n&&DomElement.createWithHTML(t,"span","comma",",")}function getIndexName(e,t,n){let r=e.useZeroIndexingForArrays?t.toString():(t+1).toString();return e.addArrayIndexPadding||(r=Str.padNumber(parseInt(r),n.toString().length)),`[${r}]`}function makeAreaDroppable(e,t){t.fileDroppingEnabled&&(e.ondragover=DomElement.cancelBubble,e.ondragenter=DomElement.cancelBubble,e.ondragleave=DomElement.cancelBubble,e.ondrop=e=>{DomElement.cancelBubble(e),Is.defined(window.FileReader)&&e.dataTransfer.files.length>0&&importFromFiles(e.dataTransfer.files,t)})}function importFromFiles(e,t){const n=e.length;for(let r=0;r<n;r++){const n=e[r];"json"===n.name.split(".").pop().toLowerCase()&&importFromJson(n,t)}}function importFromJson(e,t){const n=new FileReader;let r=null;n.onloadend=()=>{t._currentView.dataArrayCurrentIndex=0,t.data=r,renderControlContainer(t),Trigger.customEvent(t.events.onSetJson,t._currentView.element)},n.onload=e=>{const t=getObjectFromString(e.target.result);t.parsed&&Is.definedObject(t.object)&&(r=t.object)},n.readAsText(e)}function getObjectFromString(objectString){const result={parsed:!0,object:null};try{Is.definedString(objectString)&&(result.object=JSON.parse(objectString))}catch(e1){try{result.object=eval(`(${objectString})`),Is.definedFunction(result.object)&&(result.object=result.object())}catch(e){_configuration.safeMode||(console.error(_configuration.text.objectErrorText.replace("{{error_1}}",e1.message).replace("{{error_2}}",e.message)),result.parsed=!1),result.object=null}}return result}function destroyElement(e){e._currentView.element.innerHTML="",e._currentView.element.className="",Trigger.customEvent(e.events.onDestroy,e._currentView.element)}const _public={refresh:function(e){if(Is.definedString(e)&&_elements_Data.hasOwnProperty(e)){const t=_elements_Data[e];renderControlContainer(t),Trigger.customEvent(t.events.onRefresh,t._currentView.element)}return _public},refreshAll:function(){for(let e in _elements_Data)if(_elements_Data.hasOwnProperty(e)){const t=_elements_Data[e];renderControlContainer(t),Trigger.customEvent(t.events.onRefresh,t._currentView.element)}return _public},render:function(e,t){return Is.definedObject(e)&&Is.definedObject(t)&&renderControl(Binding.Options.getForNewInstance(t,e)),_public},renderAll:function(){return render(),_public},openAll:function(e){return Is.definedString(e)&&_elements_Data.hasOwnProperty(e)&&openAllNodes(_elements_Data[e]),_public},closeAll:function(e){return Is.definedString(e)&&_elements_Data.hasOwnProperty(e)&&closeAllNodes(_elements_Data[e]),_public},setJson:function(e,t){if(Is.definedString(e)&&Is.defined(t)&&_elements_Data.hasOwnProperty(e)){let n=null;if(Is.definedString(t)){const e=getObjectFromString(t);e.parsed&&(n=e.object)}else n=t;const r=_elements_Data[e];r._currentView.dataArrayCurrentIndex=0,r.data=n,renderControlContainer(r),Trigger.customEvent(r.events.onSetJson,r._currentView.element)}return _public},getJson:function(e){let t=null;return Is.definedString(e)&&_elements_Data.hasOwnProperty(e)&&(t=_elements_Data[e].data),t},destroy:function(e){return Is.definedString(e)&&_elements_Data.hasOwnProperty(e)&&(destroyElement(_elements_Data[e]),delete _elements_Data[e]),_public},destroyAll:function(){for(let e in _elements_Data)_elements_Data.hasOwnProperty(e)&&destroyElement(_elements_Data[e]);return _elements_Data={},_public},setConfiguration:function(e){if(Is.definedObject(e)){let t=!1;const n=_configuration;for(let r in e)e.hasOwnProperty(r)&&_configuration.hasOwnProperty(r)&&n[r]!==e[r]&&(n[r]=e[r],t=!0);t&&(_configuration=Config.Options.get(n))}return _public},getIds:function(){const e=[];for(let t in _elements_Data)_elements_Data.hasOwnProperty(t)&&e.push(t);return e},getVersion:function(){return"2.2.0"}};_configuration=Config.Options.get(),document.addEventListener("DOMContentLoaded",(function(){render()})),Is.defined(window.$jsontree)||(window.$jsontree=_public)})(); | ||
"use strict";var Is,Default,DomElement,Str,Str2,DateTime,Constants,Binding,Config,Trigger,ToolTip;(e=>{function t(e){return null!=e&&""!==e.toString()}function n(e){return t(e)&&"object"==typeof e}function o(e){return n(e)&&e instanceof Array}e.defined=t,e.definedObject=n,e.definedBoolean=function(e){return t(e)&&"boolean"==typeof e},e.definedString=function(e){return t(e)&&"string"==typeof e},e.definedFunction=function(e){return t(e)&&"function"==typeof e},e.definedNumber=function(e){return t(e)&&"number"==typeof e},e.definedBigInt=function(e){return t(e)&&"bigint"==typeof e},e.definedArray=o,e.definedDate=function(e){return n(e)&&e instanceof Date},e.definedDecimal=function(e){return t(e)&&"number"==typeof e&&e%1!=0},e.definedSymbol=function(e){return t(e)&&"symbol"==typeof e},e.invalidOptionArray=function(e,t=1){return!o(e)||e.length<t},e.hexColor=function(e){let t=e.length>=2&&e.length<=7;return t&&"#"===e[0]&&(t=isNaN(+e.substring(1,e.length-1))),t},e.stringValueBoolean=function(e){return"true"===e.toString().toLowerCase().trim()||"false"===e.toString().toLowerCase().trim()},e.stringValueDate=function(e){return!isNaN(+new Date(e))}})(Is||(Is={})),(e=>{function t(e,t){return Is.definedArray(e)?e:t}e.getAnyString=function(e,t){return"string"==typeof e?e:t},e.getString=function(e,t){return Is.definedString(e)?e:t},e.getBoolean=function(e,t){return Is.definedBoolean(e)?e:t},e.getNumber=function(e,t){return Is.definedNumber(e)?e:t},e.getFunction=function(e,t){return Is.definedFunction(e)?e:t},e.getArray=t,e.getObject=function(e,t){return Is.definedObject(e)?e:t},e.getStringOrArray=function(e,n){let o=n;if(Is.definedString(e)){const t=e.toString().split(" ");0===t.length?e=n:o=t}else o=t(e,n);return o},e.getFixedDecimalPlacesValue=function(e,t){var n;const o=new RegExp(`^-?\\d+(?:.\\d{0,${t||-1}})?`);return(null==(n=e.toString().match(o))?void 0:n[0])||""},e.getFunctionName=function(e){let t;const n=e.toString().split("(")[0].split(" ");return t=2===n.length?n[1]:n[0],t+="()",t}})(Default||(Default={})),(e=>{function t(e,t,n="",o=null){const r=t.toLowerCase();let l="text"===r?document.createTextNode(""):document.createElement(r);return Is.defined(n)&&(l.className=n),Is.defined(o)?e.insertBefore(l,o):e.appendChild(l),l}function n(){const e=document.documentElement;return{left:e.scrollLeft-(e.clientLeft||0),top:e.scrollTop-(e.clientTop||0)}}e.create=t,e.createWithHTML=function(e,n,o,r,l=null){const a=t(e,n,o,l);return a.innerHTML=r,a},e.addClass=function(e,t){e.classList.add(t)},e.cancelBubble=function(e){e.preventDefault(),e.stopPropagation()},e.getScrollPosition=n,e.showElementAtMousePosition=function(e,t){let o=e.pageX,r=e.pageY;const l=n();t.style.display="block",o+t.offsetWidth>window.innerWidth?o-=t.offsetWidth:o++,r+t.offsetHeight>window.innerHeight?r-=t.offsetHeight:r++,o<l.left&&(o=e.pageX+1),r<l.top&&(r=e.pageY+1),t.style.left=`${o}px`,t.style.top=`${r}px`}})(DomElement||(DomElement={})),Str2=Str||(Str={}),Str2.newGuid=function(){const e=[];for(let t=0;t<32;t++){8!==t&&12!==t&&16!==t&&20!==t||e.push("-");const n=Math.floor(16*Math.random()).toString(16);e.push(n)}return e.join("")},Str2.padNumber=function(e,t=1){const n=e.toString();let o=n;if(n.length<t){const e=t-n.length+1;o=Array(e).join("0")+n}return o},(e=>{function t(e){return e.getDay()-1<0?6:e.getDay()-1}function n(e,t){let n=e.text.thText;return 31===t||21===t||1===t?n=e.text.stText:22===t||2===t?n=e.text.ndText:23!==t&&3!==t||(n=e.text.rdText),n}e.getWeekdayNumber=t,e.getDayOrdinal=n,e.getCustomFormattedDateText=function(e,o,r){let l=r;const a=t(o);return l=l.replace("{hh}",Str.padNumber(o.getHours(),2)),l=l.replace("{h}",o.getHours().toString()),l=l.replace("{MM}",Str.padNumber(o.getMinutes(),2)),l=l.replace("{M}",o.getMinutes().toString()),l=l.replace("{ss}",Str.padNumber(o.getSeconds(),2)),l=l.replace("{s}",o.getSeconds().toString()),l=l.replace("{dddd}",e.text.dayNames[a]),l=l.replace("{ddd}",e.text.dayNamesAbbreviated[a]),l=l.replace("{dd}",Str.padNumber(o.getDate())),l=l.replace("{d}",o.getDate().toString()),l=l.replace("{o}",n(e,o.getDate())),l=l.replace("{mmmm}",e.text.monthNames[o.getMonth()]),l=l.replace("{mmm}",e.text.monthNamesAbbreviated[o.getMonth()]),l=l.replace("{mm}",Str.padNumber(o.getMonth()+1)),l=l.replace("{m}",(o.getMonth()+1).toString()),l=l.replace("{yyyy}",o.getFullYear().toString()),l=l.replace("{yyy}",o.getFullYear().toString().substring(1)),l=l.replace("{yy}",o.getFullYear().toString().substring(2)),l=l.replace("{y}",Number.parseInt(o.getFullYear().toString().substring(2)).toString()),l}})(DateTime||(DateTime={})),(Constants||(Constants={})).JSONTREE_JS_ATTRIBUTE_NAME="data-jsontree-js",(e=>{let t;var n;(n=t=e.Options||(e.Options={})).getForNewInstance=function(t,n){const o=e.Options.get(t);return o._currentView={},o._currentView.element=n,o._currentView.dataArrayCurrentIndex=0,o._currentView.titleBarButtons=null,o},n.get=function(e){let t=Default.getObject(e,{});return t.data=Default.getObject(t.data,null),t.showCounts=Default.getBoolean(t.showCounts,!0),t.useZeroIndexingForArrays=Default.getBoolean(t.useZeroIndexingForArrays,!0),t.dateTimeFormat=Default.getString(t.dateTimeFormat,"{dd}{o} {mmmm} {yyyy} {hh}:{MM}:{ss}"),t.showArrowToggles=Default.getBoolean(t.showArrowToggles,!0),t.showStringQuotes=Default.getBoolean(t.showStringQuotes,!0),t.showAllAsClosed=Default.getBoolean(t.showAllAsClosed,!1),t.sortPropertyNames=Default.getBoolean(t.sortPropertyNames,!0),t.sortPropertyNamesInAlphabeticalOrder=Default.getBoolean(t.sortPropertyNamesInAlphabeticalOrder,!0),t.showCommas=Default.getBoolean(t.showCommas,!1),t.reverseArrayValues=Default.getBoolean(t.reverseArrayValues,!1),t.addArrayIndexPadding=Default.getBoolean(t.addArrayIndexPadding,!1),t.showValueColors=Default.getBoolean(t.showValueColors,!0),t.maximumDecimalPlaces=Default.getNumber(t.maximumDecimalPlaces,2),t.maximumStringLength=Default.getNumber(t.maximumStringLength,0),t.showStringHexColors=Default.getBoolean(t.showStringHexColors,!1),t.showArrayItemsAsSeparateObjects=Default.getBoolean(t.showArrayItemsAsSeparateObjects,!1),t.copyOnlyCurrentPage=Default.getBoolean(t.copyOnlyCurrentPage,!1),t.fileDroppingEnabled=Default.getBoolean(t.fileDroppingEnabled,!0),t.copyIndentSpaces=Default.getNumber(t.copyIndentSpaces,2),t.showArrayIndexBrackets=Default.getBoolean(t.showArrayIndexBrackets,!0),t=function(e){return e.title=Default.getObject(e.title,{}),e.title.text=Default.getString(e.title.text,"JsonTree.js"),e.title.show=Default.getBoolean(e.title.show,!0),e.title.showTreeControls=Default.getBoolean(e.title.showTreeControls,!0),e.title.showCopyButton=Default.getBoolean(e.title.showCopyButton,!0),e}(t),t=function(e){return e.ignore=Default.getObject(e.ignore,{}),e.ignore.nullValues=Default.getBoolean(e.ignore.nullValues,!1),e.ignore.functionValues=Default.getBoolean(e.ignore.functionValues,!1),e.ignore.unknownValues=Default.getBoolean(e.ignore.unknownValues,!1),e.ignore.booleanValues=Default.getBoolean(e.ignore.booleanValues,!1),e.ignore.decimalValues=Default.getBoolean(e.ignore.decimalValues,!1),e.ignore.numberValues=Default.getBoolean(e.ignore.numberValues,!1),e.ignore.stringValues=Default.getBoolean(e.ignore.stringValues,!1),e.ignore.dateValues=Default.getBoolean(e.ignore.dateValues,!1),e.ignore.objectValues=Default.getBoolean(e.ignore.objectValues,!1),e.ignore.arrayValues=Default.getBoolean(e.ignore.arrayValues,!1),e.ignore.bigIntValues=Default.getBoolean(e.ignore.bigIntValues,!1),e.ignore.symbolValues=Default.getBoolean(e.ignore.symbolValues,!1),e.ignore.emptyObjects=Default.getBoolean(e.ignore.emptyObjects,!0),e}(t),t=function(e){return e.tooltip=Default.getObject(e.tooltip,{}),e.tooltip.delay=Default.getNumber(e.tooltip.delay,750),e}(t),t=function(e){return e.parse=Default.getObject(e.parse,{}),e.parse.stringsToDates=Default.getBoolean(e.parse.stringsToDates,!1),e.parse.stringsToBooleans=Default.getBoolean(e.parse.stringsToBooleans,!1),e.parse.stringsToNumbers=Default.getBoolean(e.parse.stringsToNumbers,!1),e}(t),t=function(e){return e.events=Default.getObject(e.events,{}),e.events.onBeforeRender=Default.getFunction(e.events.onBeforeRender,null),e.events.onRenderComplete=Default.getFunction(e.events.onRenderComplete,null),e.events.onValueClick=Default.getFunction(e.events.onValueClick,null),e.events.onRefresh=Default.getFunction(e.events.onRefresh,null),e.events.onCopyAll=Default.getFunction(e.events.onCopyAll,null),e.events.onOpenAll=Default.getFunction(e.events.onOpenAll,null),e.events.onCloseAll=Default.getFunction(e.events.onCloseAll,null),e.events.onDestroy=Default.getFunction(e.events.onDestroy,null),e.events.onBooleanRender=Default.getFunction(e.events.onBooleanRender,null),e.events.onDecimalRender=Default.getFunction(e.events.onDecimalRender,null),e.events.onNumberRender=Default.getFunction(e.events.onNumberRender,null),e.events.onBigIntRender=Default.getFunction(e.events.onBigIntRender,null),e.events.onStringRender=Default.getFunction(e.events.onStringRender,null),e.events.onDateRender=Default.getFunction(e.events.onDateRender,null),e.events.onFunctionRender=Default.getFunction(e.events.onFunctionRender,null),e.events.onNullRender=Default.getFunction(e.events.onNullRender,null),e.events.onUnknownRender=Default.getFunction(e.events.onUnknownRender,null),e.events.onSymbolRender=Default.getFunction(e.events.onSymbolRender,null),e}(t),t}})(Binding||(Binding={})),(e=>{let t;(t=e.Options||(e.Options={})).get=function(e=null){let t=Default.getObject(e,{});return t.safeMode=Default.getBoolean(t.safeMode,!0),t.domElementTypes=Default.getStringOrArray(t.domElementTypes,["*"]),t=function(e){return e.text=Default.getObject(e.text,{}),e.text.objectText=Default.getAnyString(e.text.objectText,"object"),e.text.arrayText=Default.getAnyString(e.text.arrayText,"array"),e.text.closeAllButtonText=Default.getAnyString(e.text.closeAllButtonText,"Close All"),e.text.openAllButtonText=Default.getAnyString(e.text.openAllButtonText,"Open All"),e.text.copyAllButtonText=Default.getAnyString(e.text.copyAllButtonText,"Copy All"),e.text.objectErrorText=Default.getAnyString(e.text.objectErrorText,"Errors in object: {{error_1}}, {{error_2}}"),e.text.attributeNotValidErrorText=Default.getAnyString(e.text.attributeNotValidErrorText,"The attribute '{{attribute_name}}' is not a valid object."),e.text.attributeNotSetErrorText=Default.getAnyString(e.text.attributeNotSetErrorText,"The attribute '{{attribute_name}}' has not been set correctly."),e.text.stText=Default.getAnyString(e.text.stText,"st"),e.text.ndText=Default.getAnyString(e.text.ndText,"nd"),e.text.rdText=Default.getAnyString(e.text.rdText,"rd"),e.text.thText=Default.getAnyString(e.text.thText,"th"),e.text.ellipsisText=Default.getAnyString(e.text.ellipsisText,"..."),e.text.closeAllButtonSymbolText=Default.getAnyString(e.text.closeAllButtonSymbolText,"↑"),e.text.openAllButtonSymbolText=Default.getAnyString(e.text.openAllButtonSymbolText,"↓"),e.text.copyAllButtonSymbolText=Default.getAnyString(e.text.copyAllButtonSymbolText,"❐"),e.text.backButtonText=Default.getAnyString(e.text.backButtonText,"Back"),e.text.nextButtonText=Default.getAnyString(e.text.nextButtonText,"Next"),e.text.backButtonSymbolText=Default.getAnyString(e.text.backButtonSymbolText,"←"),e.text.nextButtonSymbolText=Default.getAnyString(e.text.nextButtonSymbolText,"→"),e.text.noJsonToViewText=Default.getAnyString(e.text.noJsonToViewText,"There is currently no JSON to view."),Is.invalidOptionArray(e.text.dayNames,7)&&(e.text.dayNames=["Monday","Tuesday","Wednesday","Thursday","Friday","Saturday","Sunday"]),Is.invalidOptionArray(e.text.dayNamesAbbreviated,7)&&(e.text.dayNamesAbbreviated=["Mon","Tue","Wed","Thu","Fri","Sat","Sun"]),Is.invalidOptionArray(e.text.monthNames,12)&&(e.text.monthNames=["January","February","March","April","May","June","July","August","September","October","November","December"]),Is.invalidOptionArray(e.text.monthNamesAbbreviated,12)&&(e.text.monthNamesAbbreviated=["Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec"]),e}(t),t}})(Config||(Config={})),(Trigger||(Trigger={})).customEvent=function(e,...t){let n=null;return Is.definedFunction(e)&&(n=e.apply(null,[].slice.call(t,0))),n},(e=>{function t(e,t=!0){let n=t?window.addEventListener:window.removeEventListener,r=t?document.addEventListener:document.removeEventListener;n("mousemove",(()=>{o(e)})),r("scroll",(()=>{o(e)}))}function n(e,t,n){DomElement.cancelBubble(e),o(t),t._currentView.tooltipTimerId=setTimeout((()=>{t._currentView.tooltip.innerHTML=n,t._currentView.tooltip.style.display="block",DomElement.showElementAtMousePosition(e,t._currentView.tooltip)}),t.tooltip.delay)}function o(e){Is.defined(e._currentView.tooltip)&&(0!==e._currentView.tooltipTimerId&&(clearTimeout(e._currentView.tooltipTimerId),e._currentView.tooltipTimerId=0),"none"!==e._currentView.tooltip.style.display&&(e._currentView.tooltip.style.display="none"))}e.renderControl=function(e){Is.defined(e._currentView.tooltip)||(e._currentView.tooltip=DomElement.create(document.body,"div","jsontree-js-tooltip"),e._currentView.tooltip.style.display="none",t(e))},e.assignToEvents=t,e.add=function(e,t,o){null!==e&&(e.onmousemove=e=>{n(e,t,o)})},e.show=n,e.hide=o})(ToolTip||(ToolTip={})),(()=>{let _configuration={},_elements_Data={};function render(){const e=_configuration.domElementTypes,t=e.length;for(let n=0;n<t;n++){const t=document.getElementsByTagName(e[n]),o=[].slice.call(t),r=o.length;for(let e=0;e<r&&renderElement(o[e]);e++);}}function renderElement(e){let t=!0;if(Is.defined(e)&&e.hasAttribute(Constants.JSONTREE_JS_ATTRIBUTE_NAME)){const n=e.getAttribute(Constants.JSONTREE_JS_ATTRIBUTE_NAME);if(Is.definedString(n)){const o=getObjectFromString(n);o.parsed&&Is.definedObject(o.object)?renderControl(Binding.Options.getForNewInstance(o.object,e)):_configuration.safeMode||(console.error(_configuration.text.attributeNotValidErrorText.replace("{{attribute_name}}",Constants.JSONTREE_JS_ATTRIBUTE_NAME)),t=!1)}else _configuration.safeMode||(console.error(_configuration.text.attributeNotSetErrorText.replace("{{attribute_name}}",Constants.JSONTREE_JS_ATTRIBUTE_NAME)),t=!1)}return t}function renderControl(e){Trigger.customEvent(e.events.onBeforeRender,e._currentView.element),ToolTip.renderControl(e),Is.definedString(e._currentView.element.id)||(e._currentView.element.id=Str.newGuid()),e._currentView.element.className="json-tree-js",e._currentView.element.removeAttribute(Constants.JSONTREE_JS_ATTRIBUTE_NAME),_elements_Data.hasOwnProperty(e._currentView.element.id)||(_elements_Data[e._currentView.element.id]=e),renderControlContainer(e),Trigger.customEvent(e.events.onRenderComplete,e._currentView.element)}function renderControlContainer(e){let t=_elements_Data[e._currentView.element.id].data;ToolTip.hide(e),e._currentView.element.innerHTML="",renderControlTitleBar(e,t);const n=DomElement.create(e._currentView.element,"div","contents");makeAreaDroppable(n,e),e.showArrayItemsAsSeparateObjects&&Is.definedArray(t)&&(t=t[e._currentView.dataArrayCurrentIndex]),Is.definedObject(t)&&!Is.definedArray(t)?renderObject(n,e,t,!0):Is.definedArray(t)&&renderArray(n,e,t),""===n.innerHTML?(DomElement.createWithHTML(n,"span","no-json-text",_configuration.text.noJsonToViewText),e._currentView.titleBarButtons.style.display="none"):e._currentView.titleBarButtons.style.display="block"}function renderControlTitleBar(e,t){if(e.title.show||e.title.showTreeControls||e.title.showCopyButton){const n=DomElement.create(e._currentView.element,"div","title-bar");if(e._currentView.titleBarButtons=DomElement.create(n,"div","controls"),e.title.show&&DomElement.createWithHTML(n,"div","title",e.title.text,e._currentView.titleBarButtons),e.title.showCopyButton){const n=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","copy-all",_configuration.text.copyAllButtonSymbolText);ToolTip.add(n,e,_configuration.text.copyAllButtonText),n.onclick=()=>{let n=null;n=e.copyOnlyCurrentPage&&e.showArrayItemsAsSeparateObjects?JSON.stringify(t[e._currentView.dataArrayCurrentIndex],jsonStringifyReplacer,e.copyIndentSpaces):JSON.stringify(t,jsonStringifyReplacer,e.copyIndentSpaces),navigator.clipboard.writeText(n),Trigger.customEvent(e.events.onCopyAll,n)}}if(e.title.showTreeControls){const t=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","openAll",_configuration.text.openAllButtonSymbolText);ToolTip.add(t,e,_configuration.text.openAllButtonText);const n=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","closeAll",_configuration.text.closeAllButtonSymbolText);ToolTip.add(n,e,_configuration.text.closeAllButtonText),t.onclick=()=>{openAllNodes(e)},n.onclick=()=>{closeAllNodes(e)}}if(e.showArrayItemsAsSeparateObjects&&Is.definedArray(t)&&t.length>1){const n=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","back",_configuration.text.backButtonSymbolText);ToolTip.add(n,e,_configuration.text.backButtonText),e._currentView.dataArrayCurrentIndex>0?n.onclick=()=>{e._currentView.dataArrayCurrentIndex--,renderControlContainer(e),Trigger.customEvent(e.events.onBackPage,e._currentView.element)}:n.disabled=!0;const o=DomElement.createWithHTML(e._currentView.titleBarButtons,"button","next",_configuration.text.nextButtonSymbolText);ToolTip.add(o,e,_configuration.text.nextButtonText),e._currentView.dataArrayCurrentIndex<t.length-1?o.onclick=()=>{e._currentView.dataArrayCurrentIndex++,renderControlContainer(e),Trigger.customEvent(e.events.onNextPage,e._currentView.element)}:o.disabled=!0}else Is.definedArray(t)&&(e.showArrayItemsAsSeparateObjects=!1)}}function jsonStringifyReplacer(e,t){return Is.definedBigInt(t)||Is.definedSymbol(t)?t=t.toString():Is.definedFunction(t)&&(t=Default.getFunctionName(t)),t}function openAllNodes(e){e.showAllAsClosed=!1,renderControlContainer(e),Trigger.customEvent(e.events.onOpenAll,e._currentView.element)}function closeAllNodes(e){e.showAllAsClosed=!0,renderControlContainer(e),Trigger.customEvent(e.events.onCloseAll,e._currentView.element)}function renderObject(e,t,n,o=!1){const r=DomElement.create(e,"div","object-type-title"),l=DomElement.create(e,"div","object-type-contents"),a=renderObjectValues(t.showArrowToggles?DomElement.create(r,"div","down-arrow"):null,l,t,n);if(0===a&&t.ignore.emptyObjects)e.removeChild(r),e.removeChild(l);else{const e=DomElement.createWithHTML(r,"span",t.showValueColors?"object":"",_configuration.text.objectText);if(o&&t.showArrayItemsAsSeparateObjects){let n=t.useZeroIndexingForArrays?t._currentView.dataArrayCurrentIndex.toString():(t._currentView.dataArrayCurrentIndex+1).toString();t.showArrayIndexBrackets&&(n=`[${n}]:`),DomElement.createWithHTML(r,"span",t.showValueColors?"object data-array-index":"data-array-index",n,e)}t.showCounts&&a>0&&DomElement.createWithHTML(r,"span",t.showValueColors?"object count":"count",`{${a}}`)}}function renderArray(e,t,n){const o=DomElement.create(e,"div","object-type-title"),r=DomElement.create(e,"div","object-type-contents"),l=t.showArrowToggles?DomElement.create(o,"div","down-arrow"):null;DomElement.createWithHTML(o,"span",t.showValueColors?"array":"",_configuration.text.arrayText),renderArrayValues(l,r,t,n),t.showCounts&&DomElement.createWithHTML(o,"span",t.showValueColors?"array count":"count",`[${n.length}]`)}function renderObjectValues(e,t,n,o){let r=0,l=[];for(let e in o)o.hasOwnProperty(e)&&l.push(e);if(n.sortPropertyNames){let e=new Intl.Collator(void 0,{numeric:!0,sensitivity:"base"});l=l.sort(e.compare),n.sortPropertyNamesInAlphabeticalOrder||(l=l.reverse())}const a=l.length;for(let e=0;e<a;e++){const i=l[e];o.hasOwnProperty(i)&&(renderValue(t,n,i,o[i],e===a-1),r++)}return addArrowEvent(n,e,t),r}function renderArrayValues(e,t,n,o){const r=o.length;if(n.reverseArrayValues)for(let e=r;e--;)renderValue(t,n,getIndexName(n,e,r),o[e],0===e);else for(let e=0;e<r;e++)renderValue(t,n,getIndexName(n,e,r),o[e],e===r-1);addArrowEvent(n,e,t)}function renderValue(e,t,n,o,r){const l=DomElement.create(e,"div","object-type-value"),a=t.showArrowToggles?DomElement.create(l,"div","no-arrow"):null;let i=null,s=null,u=!1,c=null;if(DomElement.createWithHTML(l,"span","title",n),DomElement.createWithHTML(l,"span","split",":"),Is.defined(o))if(Is.definedFunction(o))t.ignore.functionValues?u=!0:(i=t.showValueColors?"function":"",s=DomElement.createWithHTML(l,"span",i,Default.getFunctionName(o)),c="function",Is.definedFunction(t.events.onFunctionRender)&&Trigger.customEvent(t.events.onFunctionRender,s),createComma(t,l,r));else if(Is.definedBoolean(o))t.ignore.booleanValues?u=!0:(i=t.showValueColors?"boolean":"",s=DomElement.createWithHTML(l,"span",i,o),c="boolean",Is.definedFunction(t.events.onBooleanRender)&&Trigger.customEvent(t.events.onBooleanRender,s),createComma(t,l,r));else if(Is.definedDecimal(o))if(t.ignore.decimalValues)u=!0;else{const e=Default.getFixedDecimalPlacesValue(o,t.maximumDecimalPlaces);i=t.showValueColors?"decimal":"",s=DomElement.createWithHTML(l,"span",i,e),c="decimal",Is.definedFunction(t.events.onDecimalRender)&&Trigger.customEvent(t.events.onDecimalRender,s),createComma(t,l,r)}else if(Is.definedNumber(o))t.ignore.numberValues?u=!0:(i=t.showValueColors?"number":"",s=DomElement.createWithHTML(l,"span",i,o),c="number",Is.definedFunction(t.events.onNumberRender)&&Trigger.customEvent(t.events.onNumberRender,s),createComma(t,l,r));else if(Is.definedBigInt(o))t.ignore.bigIntValues?u=!0:(i=t.showValueColors?"bigint":"",s=DomElement.createWithHTML(l,"span",i,o),c="bigint",Is.definedFunction(t.events.onBigIntRender)&&Trigger.customEvent(t.events.onBigIntRender,s),createComma(t,l,r));else if(Is.definedString(o))if(t.ignore.stringValues)u=!0;else if(t.parse.stringsToBooleans&&Is.stringValueBoolean(o))renderValue(e,t,n,"true"===o.toString().toLowerCase().trim(),r),u=!0;else if(t.parse.stringsToNumbers&&!isNaN(o))renderValue(e,t,n,parseFloat(o),r),u=!0;else if(t.parse.stringsToDates&&Is.stringValueDate(o))renderValue(e,t,n,new Date(o),r),u=!0;else{let e=null;t.showValueColors&&t.showStringHexColors&&Is.hexColor(o)?e=o:t.maximumStringLength>0&&o.length>t.maximumStringLength&&(o=o.substring(0,t.maximumStringLength)+_configuration.text.ellipsisText);const n=t.showStringQuotes?`"${o}"`:o;i=t.showValueColors?"string":"",s=DomElement.createWithHTML(l,"span",i,n),c="string",Is.definedString(e)&&(s.style.color=e),Is.definedFunction(t.events.onStringRender)&&Trigger.customEvent(t.events.onStringRender,s),createComma(t,l,r)}else if(Is.definedDate(o))t.ignore.dateValues?u=!0:(i=t.showValueColors?"date":"",s=DomElement.createWithHTML(l,"span",i,DateTime.getCustomFormattedDateText(_configuration,o,t.dateTimeFormat)),c="date",Is.definedFunction(t.events.onDateRender)&&Trigger.customEvent(t.events.onDateRender,s),createComma(t,l,r));else if(Is.definedSymbol(o))t.ignore.symbolValues?u=!0:(i=t.showValueColors?"symbol":"",s=DomElement.createWithHTML(l,"span",i,o.toString()),c="symbol",Is.definedFunction(t.events.onSymbolRender)&&Trigger.customEvent(t.events.onSymbolRender,s),createComma(t,l,r));else if(Is.definedObject(o)&&!Is.definedArray(o))if(t.ignore.objectValues)u=!0;else{const e=DomElement.create(l,"span",t.showValueColors?"object":""),n=renderObjectValues(a,DomElement.create(l,"div","object-type-contents"),t,o);0===n&&t.ignore.emptyObjects?u=!0:(DomElement.createWithHTML(e,"span","title",_configuration.text.objectText),t.showCounts&&n>0&&DomElement.createWithHTML(e,"span","count",`{${n}}`),createComma(t,e,r),c="object")}else if(Is.definedArray(o))if(t.ignore.arrayValues)u=!0;else{const e=DomElement.create(l,"span",t.showValueColors?"array":""),n=DomElement.create(l,"div","object-type-contents");DomElement.createWithHTML(e,"span","title",_configuration.text.arrayText),t.showCounts&&DomElement.createWithHTML(e,"span","count",`[${o.length}]`),createComma(t,e,r),renderArrayValues(a,n,t,o),c="array"}else t.ignore.unknownValues?u=!0:(i=t.showValueColors?"unknown":"",s=DomElement.createWithHTML(l,"span",i,o.toString()),c="unknown",Is.definedFunction(t.events.onUnknownRender)&&Trigger.customEvent(t.events.onUnknownRender,s),createComma(t,l,r));else t.ignore.nullValues?u=!0:(i=t.showValueColors?"null":"",s=DomElement.createWithHTML(l,"span",i,"null"),c="null",Is.definedFunction(t.events.onNullRender)&&Trigger.customEvent(t.events.onNullRender,s),createComma(t,l,r));u?e.removeChild(l):Is.defined(s)&&addValueClickEvent(t,s,o,c)}function addValueClickEvent(e,t,n,o){Is.definedFunction(e.events.onValueClick)?t.onclick=()=>{Trigger.customEvent(e.events.onValueClick,n,o)}:DomElement.addClass(t,"no-hover")}function addArrowEvent(e,t,n){Is.defined(t)&&(t.onclick=()=>{"down-arrow"===t.className?(n.style.display="none",t.className="right-arrow"):(n.style.display="block",t.className="down-arrow")},e.showAllAsClosed?(n.style.display="none",t.className="right-arrow"):t.className="down-arrow")}function createComma(e,t,n){e.showCommas&&!n&&DomElement.createWithHTML(t,"span","comma",",")}function getIndexName(e,t,n){let o=e.useZeroIndexingForArrays?t.toString():(t+1).toString();return e.addArrayIndexPadding||(o=Str.padNumber(parseInt(o),n.toString().length)),e.showArrayIndexBrackets&&(o=`[${o}]`),o}function makeAreaDroppable(e,t){t.fileDroppingEnabled&&(e.ondragover=DomElement.cancelBubble,e.ondragenter=DomElement.cancelBubble,e.ondragleave=DomElement.cancelBubble,e.ondrop=e=>{DomElement.cancelBubble(e),Is.defined(window.FileReader)&&e.dataTransfer.files.length>0&&importFromFiles(e.dataTransfer.files,t)})}function importFromFiles(e,t){const n=e.length;for(let o=0;o<n;o++){const n=e[o];"json"===n.name.split(".").pop().toLowerCase()&&importFromJson(n,t)}}function importFromJson(e,t){const n=new FileReader;let o=null;n.onloadend=()=>{t._currentView.dataArrayCurrentIndex=0,t.data=o,renderControlContainer(t),Trigger.customEvent(t.events.onSetJson,t._currentView.element)},n.onload=e=>{const t=getObjectFromString(e.target.result);t.parsed&&Is.definedObject(t.object)&&(o=t.object)},n.readAsText(e)}function getObjectFromString(objectString){const result={parsed:!0,object:null};try{Is.definedString(objectString)&&(result.object=JSON.parse(objectString))}catch(e1){try{result.object=eval(`(${objectString})`),Is.definedFunction(result.object)&&(result.object=result.object())}catch(e){_configuration.safeMode||(console.error(_configuration.text.objectErrorText.replace("{{error_1}}",e1.message).replace("{{error_2}}",e.message)),result.parsed=!1),result.object=null}}return result}function destroyElement(e){e._currentView.element.innerHTML="",e._currentView.element.className="",ToolTip.assignToEvents(e,!1),Trigger.customEvent(e.events.onDestroy,e._currentView.element)}const _public={refresh:function(e){if(Is.definedString(e)&&_elements_Data.hasOwnProperty(e)){const t=_elements_Data[e];renderControlContainer(t),Trigger.customEvent(t.events.onRefresh,t._currentView.element)}return _public},refreshAll:function(){for(let e in _elements_Data)if(_elements_Data.hasOwnProperty(e)){const t=_elements_Data[e];renderControlContainer(t),Trigger.customEvent(t.events.onRefresh,t._currentView.element)}return _public},render:function(e,t){return Is.definedObject(e)&&Is.definedObject(t)&&renderControl(Binding.Options.getForNewInstance(t,e)),_public},renderAll:function(){return render(),_public},openAll:function(e){return Is.definedString(e)&&_elements_Data.hasOwnProperty(e)&&openAllNodes(_elements_Data[e]),_public},closeAll:function(e){return Is.definedString(e)&&_elements_Data.hasOwnProperty(e)&&closeAllNodes(_elements_Data[e]),_public},setJson:function(e,t){if(Is.definedString(e)&&Is.defined(t)&&_elements_Data.hasOwnProperty(e)){let n=null;if(Is.definedString(t)){const e=getObjectFromString(t);e.parsed&&(n=e.object)}else n=t;const o=_elements_Data[e];o._currentView.dataArrayCurrentIndex=0,o.data=n,renderControlContainer(o),Trigger.customEvent(o.events.onSetJson,o._currentView.element)}return _public},getJson:function(e){let t=null;return Is.definedString(e)&&_elements_Data.hasOwnProperty(e)&&(t=_elements_Data[e].data),t},destroy:function(e){return Is.definedString(e)&&_elements_Data.hasOwnProperty(e)&&(destroyElement(_elements_Data[e]),delete _elements_Data[e]),_public},destroyAll:function(){for(let e in _elements_Data)_elements_Data.hasOwnProperty(e)&&destroyElement(_elements_Data[e]);return _elements_Data={},_public},setConfiguration:function(e){if(Is.definedObject(e)){let t=!1;const n=_configuration;for(let o in e)e.hasOwnProperty(o)&&_configuration.hasOwnProperty(o)&&n[o]!==e[o]&&(n[o]=e[o],t=!0);t&&(_configuration=Config.Options.get(n))}return _public},getIds:function(){const e=[];for(let t in _elements_Data)_elements_Data.hasOwnProperty(t)&&e.push(t);return e},getVersion:function(){return"2.3.0"}};_configuration=Config.Options.get(),document.addEventListener("DOMContentLoaded",(function(){render()})),Is.defined(window.$jsontree)||(window.$jsontree=_public)})(); |
@@ -5,3 +5,3 @@ { | ||
"description": "A lightweight JavaScript library that generates customizable tree views to better visualize JSON data.", | ||
"version": "2.2.0", | ||
"version": "2.3.0", | ||
"homepage": "https://www.william-troup.com/jsontree-js/", | ||
@@ -8,0 +8,0 @@ "author": { |
@@ -5,4 +5,4 @@ <h1 align="center"> | ||
[![Tweet](https://img.shields.io/twitter/url/http/shields.io.svg?style=social)](https://twitter.com/intent/tweet?text=JsonTree.js%2C%20a%20free%20JavaScript%json%20treeview&url=https://github.com/williamtroup/JsonTree.js&hashtags=javascript,treeview,json) | ||
[![npm](https://img.shields.io/badge/npmjs-v2.2.0-blue)](https://www.npmjs.com/package/jjsontree.js) | ||
[![nuget](https://img.shields.io/badge/nuget-v2.2.0-purple)](https://www.nuget.org/packages/jJsonTree.js/) | ||
[![npm](https://img.shields.io/badge/npmjs-v2.3.0-blue)](https://www.npmjs.com/package/jjsontree.js) | ||
[![nuget](https://img.shields.io/badge/nuget-v2.3.0-purple)](https://www.nuget.org/packages/jJsonTree.js/) | ||
[![license](https://img.shields.io/badge/license-MIT-green)](https://github.com/williamtroup/JsonTree.js/blob/main/LICENSE.txt) | ||
@@ -14,3 +14,3 @@ [![discussions Welcome](https://img.shields.io/badge/discussions-Welcome-red)](https://github.com/williamtroup/JsonTree.js/discussions) | ||
> <p align="center">🔗 A lightweight JavaScript library that generates customizable tree views to better visualize JSON data.</p> | ||
> <p align="center">v2.2.0</p> | ||
> <p align="center">v2.3.0</p> | ||
<br /> | ||
@@ -29,2 +29,3 @@ | ||
- Full CSS theme support (using :root variables). | ||
- 11 types supported by default (with unknown type support). | ||
- Fully configurable per DOM element! | ||
@@ -54,2 +55,20 @@ - Close/Open all nodes. | ||
<h1>What types are supported?</h1> | ||
- `boolean` Booleans | ||
- `number` Numbers | ||
- `bigint` Big Integers | ||
- `string` Strings | ||
- `object` Objects | ||
- `object Array` Arrays | ||
- `object Date` Dates | ||
- `number` Decimals | ||
- `null` Nulls | ||
- `symbol` Symbols | ||
- `function` Functions | ||
- `any` Unknown | ||
<br> | ||
<br> | ||
<h1>What are the most recent changes?</h1> | ||
@@ -73,4 +92,4 @@ | ||
```markdown | ||
https://cdn.jsdelivr.net/gh/williamtroup/JsonTree.js@2.2.0/dist/jsontree.min.js | ||
https://cdn.jsdelivr.net/gh/williamtroup/JsonTree.js@2.2.0/dist/jsontree.js.min.css | ||
https://cdn.jsdelivr.net/gh/williamtroup/JsonTree.js@2.3.0/dist/jsontree.min.js | ||
https://cdn.jsdelivr.net/gh/williamtroup/JsonTree.js@2.3.0/dist/jsontree.js.min.css | ||
``` | ||
@@ -77,0 +96,0 @@ <br> |
@@ -7,3 +7,3 @@ /** | ||
* @file jsontree.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -20,3 +20,3 @@ * @license MIT License | ||
import { DomElement } from "./ts/dom/dom"; | ||
import { Char } from "./ts/data/enum"; | ||
import { Char, DataType } from "./ts/data/enum"; | ||
import { DateTime } from "./ts/data/datetime"; | ||
@@ -28,2 +28,3 @@ import { Constants } from "./ts/constant"; | ||
import { Trigger } from "./ts/area/trigger"; | ||
import { ToolTip } from "./ts/area/tooltip"; | ||
@@ -102,2 +103,3 @@ | ||
Trigger.customEvent( bindingOptions.events!.onBeforeRender!, bindingOptions._currentView.element ); | ||
ToolTip.renderControl( bindingOptions ); | ||
@@ -122,2 +124,4 @@ if ( !Is.definedString( bindingOptions._currentView.element.id ) ) { | ||
ToolTip.hide( bindingOptions ); | ||
bindingOptions._currentView.element.innerHTML = Char.empty; | ||
@@ -170,4 +174,5 @@ | ||
const copy: HTMLButtonElement = DomElement.createWithHTML( bindingOptions._currentView.titleBarButtons, "button", "copy-all", _configuration.text!.copyAllButtonSymbolText! ) as HTMLButtonElement; | ||
copy.title = _configuration.text!.copyAllButtonText! | ||
ToolTip.add( copy, bindingOptions, _configuration.text!.copyAllButtonText! ); | ||
copy.onclick = () => { | ||
@@ -177,6 +182,6 @@ let copyData: string = null!; | ||
if ( bindingOptions.copyOnlyCurrentPage && bindingOptions.showArrayItemsAsSeparateObjects ) { | ||
copyData = JSON.stringify( data[ bindingOptions._currentView.dataArrayCurrentIndex ], null, bindingOptions.copyIndentSpaces ); | ||
copyData = JSON.stringify( data[ bindingOptions._currentView.dataArrayCurrentIndex ], jsonStringifyReplacer, bindingOptions.copyIndentSpaces ); | ||
} | ||
else { | ||
copyData = JSON.stringify( data, null, bindingOptions.copyIndentSpaces ); | ||
copyData = JSON.stringify( data, jsonStringifyReplacer, bindingOptions.copyIndentSpaces ); | ||
} | ||
@@ -192,7 +197,9 @@ | ||
const openAll: HTMLButtonElement = DomElement.createWithHTML( bindingOptions._currentView.titleBarButtons, "button", "openAll", _configuration.text!.openAllButtonSymbolText! ) as HTMLButtonElement; | ||
openAll.title = _configuration.text!.openAllButtonText! | ||
ToolTip.add( openAll, bindingOptions, _configuration.text!.openAllButtonText! ); | ||
const closeAll: HTMLButtonElement = DomElement.createWithHTML( bindingOptions._currentView.titleBarButtons, "button", "closeAll", _configuration.text!.closeAllButtonSymbolText! ) as HTMLButtonElement; | ||
closeAll.title = _configuration.text!.closeAllButtonText! | ||
ToolTip.add( closeAll, bindingOptions, _configuration.text!.closeAllButtonText! ); | ||
openAll.onclick = () => { | ||
@@ -209,4 +216,5 @@ openAllNodes( bindingOptions ); | ||
const back: HTMLButtonElement = DomElement.createWithHTML( bindingOptions._currentView.titleBarButtons, "button", "back", _configuration.text!.backButtonSymbolText! ) as HTMLButtonElement; | ||
back.title = _configuration.text!.backButtonText! | ||
ToolTip.add( back, bindingOptions, _configuration.text!.backButtonText! ); | ||
if ( bindingOptions._currentView.dataArrayCurrentIndex > 0 ) { | ||
@@ -225,4 +233,5 @@ back.onclick = () => { | ||
const next: HTMLButtonElement = DomElement.createWithHTML( bindingOptions._currentView.titleBarButtons, "button", "next", _configuration.text!.nextButtonSymbolText! ) as HTMLButtonElement; | ||
next.title = _configuration.text!.nextButtonText! | ||
ToolTip.add( next, bindingOptions, _configuration.text!.nextButtonText! ); | ||
if ( bindingOptions._currentView.dataArrayCurrentIndex < data.length - 1 ) { | ||
@@ -249,2 +258,14 @@ next.onclick = () => { | ||
function jsonStringifyReplacer( _: string, value: any ) : void { | ||
if ( Is.definedBigInt( value ) ) { | ||
value = value.toString(); | ||
} else if ( Is.definedSymbol( value ) ) { | ||
value = value.toString(); | ||
} else if ( Is.definedFunction( value ) ) { | ||
value = Default.getFunctionName( value ); | ||
} | ||
return value; | ||
} | ||
function openAllNodes( bindingOptions: BindingOptions ) : void { | ||
@@ -277,12 +298,22 @@ bindingOptions.showAllAsClosed = false; | ||
const titleText: HTMLSpanElement = DomElement.createWithHTML( objectTypeTitle, "span", bindingOptions.showValueColors ? "object" : Char.empty, _configuration.text!.objectText! ) as HTMLSpanElement; | ||
if ( propertyCount === 0 && bindingOptions.ignore!.emptyObjects ) { | ||
container.removeChild( objectTypeTitle ); | ||
container.removeChild( objectTypeContents ); | ||
} else { | ||
if ( showPagingIndex && bindingOptions.showArrayItemsAsSeparateObjects ) { | ||
let dataArrayIndex: string = bindingOptions.useZeroIndexingForArrays ? bindingOptions._currentView.dataArrayCurrentIndex.toString() : ( bindingOptions._currentView.dataArrayCurrentIndex + 1 ).toString(); | ||
const titleText: HTMLSpanElement = DomElement.createWithHTML( objectTypeTitle, "span", bindingOptions.showValueColors ? "object" : Char.empty, _configuration.text!.objectText! ) as HTMLSpanElement; | ||
DomElement.createWithHTML( objectTypeTitle, "span", bindingOptions.showValueColors ? "object data-array-index" : "data-array-index", `[${dataArrayIndex}]:`, titleText ); | ||
} | ||
if ( showPagingIndex && bindingOptions.showArrayItemsAsSeparateObjects ) { | ||
let dataArrayIndex: string = bindingOptions.useZeroIndexingForArrays ? bindingOptions._currentView.dataArrayCurrentIndex.toString() : ( bindingOptions._currentView.dataArrayCurrentIndex + 1 ).toString(); | ||
if ( bindingOptions.showArrayIndexBrackets ) { | ||
dataArrayIndex = `[${dataArrayIndex}]:`; | ||
} | ||
if ( bindingOptions.showCounts && propertyCount > 0 ) { | ||
DomElement.createWithHTML( objectTypeTitle, "span", bindingOptions.showValueColors ? "object count" : "count", `{${propertyCount}}` ); | ||
DomElement.createWithHTML( objectTypeTitle, "span", bindingOptions.showValueColors ? "object data-array-index" : "data-array-index", dataArrayIndex, titleText ); | ||
} | ||
if ( bindingOptions.showCounts && propertyCount > 0 ) { | ||
DomElement.createWithHTML( objectTypeTitle, "span", bindingOptions.showValueColors ? "object count" : "count", `{${propertyCount}}` ); | ||
} | ||
} | ||
@@ -316,4 +347,9 @@ } | ||
if ( bindingOptions.sortPropertyNames ) { | ||
properties = properties.sort(); | ||
let collator: Intl.Collator = new Intl.Collator( undefined, { | ||
numeric: true, | ||
sensitivity: "base" | ||
} ); | ||
properties = properties.sort( collator.compare ); | ||
if ( !bindingOptions.sortPropertyNamesInAlphabeticalOrder ) { | ||
@@ -364,3 +400,2 @@ properties = properties.reverse(); | ||
let type: string = null!; | ||
let addClickEvent: boolean = true; | ||
@@ -374,3 +409,3 @@ DomElement.createWithHTML( objectTypeValue, "span", "title", name ); | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, "null" ); | ||
addClickEvent = false; | ||
type = DataType.null; | ||
@@ -391,3 +426,3 @@ if ( Is.definedFunction( bindingOptions.events!.onNullRender ) ) { | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, Default.getFunctionName( value ) ); | ||
type = "function"; | ||
type = DataType.function; | ||
@@ -408,3 +443,3 @@ if ( Is.definedFunction( bindingOptions.events!.onFunctionRender ) ) { | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, value ); | ||
type = "boolean"; | ||
type = DataType.boolean; | ||
@@ -427,3 +462,3 @@ if ( Is.definedFunction( bindingOptions.events!.onBooleanRender ) ) { | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, newValue ); | ||
type = "decimal"; | ||
type = DataType.decimal; | ||
@@ -444,3 +479,3 @@ if ( Is.definedFunction( bindingOptions.events!.onDecimalRender ) ) { | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, value ); | ||
type = "number"; | ||
type = DataType.number; | ||
@@ -457,5 +492,29 @@ if ( Is.definedFunction( bindingOptions.events!.onNumberRender ) ) { | ||
} else if ( Is.definedBigInt( value ) ) { | ||
if ( !bindingOptions.ignore!.bigIntValues ) { | ||
valueClass = bindingOptions.showValueColors ? "bigint" : Char.empty; | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, value ); | ||
type = DataType.bigint; | ||
if ( Is.definedFunction( bindingOptions.events!.onBigIntRender ) ) { | ||
Trigger.customEvent( bindingOptions.events!.onBigIntRender!, valueElement ); | ||
} | ||
createComma( bindingOptions, objectTypeValue, isLastItem ); | ||
} else { | ||
ignored = true; | ||
} | ||
} else if ( Is.definedString( value ) ) { | ||
if ( !bindingOptions.ignore!.stringValues ) { | ||
if ( bindingOptions.parseStringsToDates && DateTime.isDateValid( value ) ) { | ||
if ( bindingOptions.parse!.stringsToBooleans && Is.stringValueBoolean( value ) ) { | ||
renderValue( container, bindingOptions, name, value.toString().toLowerCase().trim() === "true", isLastItem ); | ||
ignored = true; | ||
} else if ( bindingOptions.parse!.stringsToNumbers && !isNaN( value ) ) { | ||
renderValue( container, bindingOptions, name, parseFloat( value ), isLastItem ); | ||
ignored = true; | ||
} else if ( bindingOptions.parse!.stringsToDates && Is.stringValueDate( value ) ) { | ||
renderValue( container, bindingOptions, name, new Date( value ), isLastItem ); | ||
@@ -480,3 +539,3 @@ ignored = true; | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, newStringValue ); | ||
type = "string"; | ||
type = DataType.string; | ||
@@ -502,3 +561,3 @@ if ( Is.definedString( color ) ) { | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, DateTime.getCustomFormattedDateText( _configuration, value, bindingOptions.dateTimeFormat! ) ); | ||
type = "date"; | ||
type = DataType.date; | ||
@@ -515,2 +574,18 @@ if ( Is.definedFunction( bindingOptions.events!.onDateRender ) ) { | ||
} else if ( Is.definedSymbol( value ) ) { | ||
if ( !bindingOptions.ignore!.symbolValues ) { | ||
valueClass = bindingOptions.showValueColors ? "symbol" : Char.empty; | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, value.toString() ); | ||
type = DataType.symbol; | ||
if ( Is.definedFunction( bindingOptions.events!.onSymbolRender ) ) { | ||
Trigger.customEvent( bindingOptions.events!.onSymbolRender!, valueElement ); | ||
} | ||
createComma( bindingOptions, objectTypeValue, isLastItem ); | ||
} else { | ||
ignored = true; | ||
} | ||
} else if ( Is.definedObject( value ) && !Is.definedArray( value ) ) { | ||
@@ -522,12 +597,17 @@ if ( !bindingOptions.ignore!.objectValues ) { | ||
DomElement.createWithHTML( objectTitle, "span", "title", _configuration.text!.objectText! ); | ||
if ( propertyCount === 0 && bindingOptions.ignore!.emptyObjects ) { | ||
ignored = true; | ||
} else { | ||
if ( bindingOptions.showCounts && propertyCount > 0 ) { | ||
DomElement.createWithHTML( objectTitle, "span", "count", `{${propertyCount}}` ); | ||
DomElement.createWithHTML( objectTitle, "span", "title", _configuration.text!.objectText! ); | ||
if ( bindingOptions.showCounts && propertyCount > 0 ) { | ||
DomElement.createWithHTML( objectTitle, "span", "count", `{${propertyCount}}` ); | ||
} | ||
createComma( bindingOptions, objectTitle, isLastItem ); | ||
type = DataType.object; | ||
} | ||
createComma( bindingOptions, objectTitle, isLastItem ); | ||
type = "object"; | ||
} else { | ||
@@ -552,3 +632,3 @@ ignored = true; | ||
type = "array"; | ||
type = DataType.array; | ||
@@ -563,3 +643,3 @@ } else { | ||
valueElement = DomElement.createWithHTML( objectTypeValue, "span", valueClass, value.toString() ); | ||
type = "unknown"; | ||
type = DataType.unknown; | ||
@@ -582,3 +662,3 @@ if ( Is.definedFunction( bindingOptions.events!.onUnknownRender ) ) { | ||
if ( Is.defined( valueElement ) ) { | ||
addValueClickEvent( bindingOptions, valueElement, value, type, addClickEvent ); | ||
addValueClickEvent( bindingOptions, valueElement, value, type ); | ||
} | ||
@@ -588,4 +668,4 @@ } | ||
function addValueClickEvent( bindingOptions: BindingOptions, valueElement: HTMLElement, value: any, type: string, addClickEvent: boolean ) : void { | ||
if ( addClickEvent && Is.definedFunction( bindingOptions.events!.onValueClick ) ) { | ||
function addValueClickEvent( bindingOptions: BindingOptions, valueElement: HTMLElement, value: any, type: string ) : void { | ||
if ( Is.definedFunction( bindingOptions.events!.onValueClick ) ) { | ||
valueElement.onclick = () => { | ||
@@ -633,4 +713,8 @@ Trigger.customEvent( bindingOptions.events!.onValueClick!, value, type ); | ||
} | ||
if ( bindingOptions.showArrayIndexBrackets ) { | ||
result = `[${result}]`; | ||
} | ||
return `[${result}]`; | ||
return result; | ||
} | ||
@@ -747,2 +831,3 @@ | ||
ToolTip.assignToEvents( bindingOptions, false ); | ||
Trigger.customEvent( bindingOptions.events!.onDestroy!, bindingOptions._currentView.element ); | ||
@@ -939,3 +1024,3 @@ } | ||
getVersion: function () : string { | ||
return "2.2.0"; | ||
return "2.3.0"; | ||
} | ||
@@ -942,0 +1027,0 @@ }; |
@@ -7,3 +7,3 @@ /** | ||
* @file api.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -10,0 +10,0 @@ * @license MIT License |
@@ -7,3 +7,3 @@ /** | ||
* @file trigger.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -10,0 +10,0 @@ * @license MIT License |
@@ -7,3 +7,3 @@ /** | ||
* @file constant.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -10,0 +10,0 @@ * @license MIT License |
@@ -7,3 +7,3 @@ /** | ||
* @file datetime.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -70,6 +70,2 @@ * @license MIT License | ||
} | ||
export function isDateValid( dateTimeString: string ) { | ||
return !isNaN( +new Date( dateTimeString ) ); | ||
} | ||
} |
@@ -7,3 +7,3 @@ /** | ||
* @file default.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -10,0 +10,0 @@ * @license MIT License |
@@ -7,3 +7,3 @@ /** | ||
* @file enum.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -21,2 +21,17 @@ * @license MIT License | ||
hash = "#", | ||
} | ||
export const enum DataType { | ||
null = "null", | ||
function = "function", | ||
boolean = "boolean", | ||
decimal = "decimal", | ||
number = "number", | ||
bigint = "bigint", | ||
string = "string", | ||
date = "date", | ||
symbol = "symbol", | ||
object = "object", | ||
array = "array", | ||
unknown = "unknown", | ||
} |
@@ -7,3 +7,3 @@ /** | ||
* @file is.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -43,2 +43,6 @@ * @license MIT License | ||
export function definedBigInt( object: any ) : boolean { | ||
return defined( object ) && typeof object === "bigint"; | ||
} | ||
export function definedArray( object: any ) : boolean { | ||
@@ -56,2 +60,6 @@ return definedObject( object ) && object instanceof Array; | ||
export function definedSymbol( object: any ) : boolean { | ||
return defined( object ) && typeof object === "symbol"; | ||
} | ||
export function invalidOptionArray( array: any, minimumLength: number = 1 ) : boolean { | ||
@@ -70,2 +78,10 @@ return !definedArray( array ) || array.length < minimumLength; | ||
} | ||
export function stringValueBoolean( object: string ) : boolean { | ||
return object.toString().toLowerCase().trim() === "true" || object.toString().toLowerCase().trim() === "false"; | ||
} | ||
export function stringValueDate( dateTimeString: string ) { | ||
return !isNaN( +new Date( dateTimeString ) ); | ||
} | ||
} |
@@ -7,3 +7,3 @@ /** | ||
* @file str.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -10,0 +10,0 @@ * @license MIT License |
@@ -7,3 +7,3 @@ /** | ||
* @file dom.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -17,2 +17,3 @@ * @license MIT License | ||
import { Is } from "../data/is"; | ||
import { Position } from "../type"; | ||
@@ -55,2 +56,44 @@ | ||
} | ||
export function getScrollPosition() : Position { | ||
const documentElement: HTMLElement = document.documentElement; | ||
const result: Position = { | ||
left: documentElement.scrollLeft - ( documentElement.clientLeft || 0 ), | ||
top: documentElement.scrollTop - ( documentElement.clientTop || 0 ) | ||
} as Position; | ||
return result; | ||
} | ||
export function showElementAtMousePosition( e: any, element: HTMLElement ) : void { | ||
let left: number = e.pageX; | ||
let top: number = e.pageY; | ||
const scrollPosition: Position = getScrollPosition(); | ||
element.style.display = "block"; | ||
if ( left + element.offsetWidth > window.innerWidth ) { | ||
left -= element.offsetWidth; | ||
} else { | ||
left++; | ||
} | ||
if ( top + element.offsetHeight > window.innerHeight ) { | ||
top -= element.offsetHeight; | ||
} else { | ||
top++; | ||
} | ||
if ( left < scrollPosition.left ) { | ||
left = e.pageX + 1; | ||
} | ||
if ( top < scrollPosition.top ) { | ||
top = e.pageY + 1; | ||
} | ||
element.style.left = `${left}px`; | ||
element.style.top = `${top}px`; | ||
} | ||
} |
@@ -7,3 +7,3 @@ /** | ||
* @file binding.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -17,2 +17,4 @@ * @license MIT License | ||
BindingOptionsCurrentView, | ||
BindingOptionsParse, | ||
BindingOptionsTooltip, | ||
type BindingOptions, | ||
@@ -59,7 +61,9 @@ type BindingOptionsEvents, | ||
options.fileDroppingEnabled = Default.getBoolean( options.fileDroppingEnabled, true ); | ||
options.parseStringsToDates = Default.getBoolean( options.parseStringsToDates, false ); | ||
options.copyIndentSpaces = Default.getNumber( options.copyIndentSpaces, 2 ); | ||
options.showArrayIndexBrackets = Default.getBoolean( options.showArrayIndexBrackets, true ); | ||
options = getTitle( options ); | ||
options = getIgnore( options ); | ||
options = getToolTip( options ); | ||
options = getParse( options ); | ||
options = getCustomTriggers( options ); | ||
@@ -92,5 +96,24 @@ | ||
options.ignore!.arrayValues = Default.getBoolean( options.ignore!.arrayValues, false ); | ||
options.ignore!.bigIntValues = Default.getBoolean( options.ignore!.bigIntValues, false ); | ||
options.ignore!.symbolValues = Default.getBoolean( options.ignore!.symbolValues, false ); | ||
options.ignore!.emptyObjects = Default.getBoolean( options.ignore!.emptyObjects, true ); | ||
return options; | ||
} | ||
function getToolTip( options: BindingOptions ) : BindingOptions { | ||
options.tooltip = Default.getObject( options.tooltip, {} as BindingOptionsTooltip ); | ||
options.tooltip!.delay = Default.getNumber( options.tooltip!.delay, 750 ); | ||
return options; | ||
} | ||
function getParse( options: BindingOptions ) : BindingOptions { | ||
options.parse = Default.getObject( options.parse, {} as BindingOptionsParse ); | ||
options.parse!.stringsToDates = Default.getBoolean( options.parse!.stringsToDates, false ); | ||
options.parse!.stringsToBooleans = Default.getBoolean( options.parse!.stringsToBooleans, false ); | ||
options.parse!.stringsToNumbers = Default.getBoolean( options.parse!.stringsToNumbers, false ); | ||
return options; | ||
} | ||
@@ -109,3 +132,4 @@ function getCustomTriggers( options: BindingOptions ) : BindingOptions { | ||
options.events!.onDecimalRender = Default.getFunction( options.events!.onDecimalRender, null! ); | ||
options.events!.onNumberRender =Default.getFunction( options.events!.onNumberRender, null! ); | ||
options.events!.onNumberRender = Default.getFunction( options.events!.onNumberRender, null! ); | ||
options.events!.onBigIntRender = Default.getFunction( options.events!.onBigIntRender, null! ); | ||
options.events!.onStringRender = Default.getFunction( options.events!.onStringRender, null! ); | ||
@@ -116,3 +140,4 @@ options.events!.onDateRender = Default.getFunction( options.events!.onDateRender, null! ); | ||
options.events!.onUnknownRender = Default.getFunction( options.events!.onUnknownRender, null! ); | ||
options.events!.onSymbolRender = Default.getFunction( options.events!.onSymbolRender, null! ); | ||
return options; | ||
@@ -119,0 +144,0 @@ } |
@@ -7,3 +7,3 @@ /** | ||
* @file config.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -10,0 +10,0 @@ * @license MIT License |
@@ -7,3 +7,3 @@ /** | ||
* @file type.ts | ||
* @version v2.2.0 | ||
* @version v2.3.0 | ||
* @author Bunoon | ||
@@ -15,2 +15,7 @@ * @license MIT License | ||
export type Position = { | ||
left: number; | ||
top: number; | ||
}; | ||
export type Configuration = { | ||
@@ -71,6 +76,8 @@ safeMode?: boolean; | ||
fileDroppingEnabled?: boolean; | ||
parseStringsToDates?: boolean; | ||
copyIndentSpaces?: number; | ||
showArrayIndexBrackets?: boolean; | ||
title?: BindingOptionsTitle; | ||
ignore?: BindingOptionsIgnore; | ||
tooltip?: BindingOptionsTooltip; | ||
parse?: BindingOptionsParse; | ||
events?: BindingOptionsEvents; | ||
@@ -83,4 +90,12 @@ }; | ||
titleBarButtons: HTMLElement; | ||
tooltip: HTMLElement; | ||
tooltipTimerId: number; | ||
}; | ||
export type BindingOptionsParse = { | ||
stringsToDates?: boolean; | ||
stringsToBooleans?: boolean; | ||
stringsToNumbers?: boolean; | ||
}; | ||
export type BindingOptionsTitle = { | ||
@@ -104,4 +119,11 @@ text?: string; | ||
numberValues?: boolean; | ||
bigIntValues?: boolean; | ||
symbolValues?: boolean; | ||
emptyObjects?: boolean; | ||
}; | ||
export type BindingOptionsTooltip = { | ||
delay?: number; | ||
}; | ||
export type BindingOptionsEvents = { | ||
@@ -124,2 +146,4 @@ onBeforeRender?: ( element: HTMLElement ) => void; | ||
onUnknownRender?: ( element: HTMLElement ) => void; | ||
onBigIntRender?: ( element: HTMLElement ) => void; | ||
onSymbolRender?: ( element: HTMLElement ) => void; | ||
onBackPage?: ( element: HTMLElement ) => void; | ||
@@ -126,0 +150,0 @@ onNextPage?: ( element: HTMLElement ) => void; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
521212
31
4536
167