jsonpath-picker-vanilla
Advanced tools
Comparing version 1.1.0 to 1.1.1
278
index.js
@@ -236,181 +236,186 @@ "use strict"; | ||
} | ||
/** | ||
* Plugin method | ||
* @param source: Element | ||
* @param json: a javascript object | ||
* @param target: NodeListOf<Element> | Element | { value: String }[] | { value: String } | ||
* @param opt: an optional options hash | ||
*/ | ||
function HandlerEventToggle(elm, event) { | ||
// Change class | ||
elm.classList.toggle('collapsed'); // Fetch every json-dict and json-array to toggle them | ||
function jsonPathPicker(source, json, target, opt) { | ||
var options = opt || {}; | ||
var subTarget = siblings(elm, 'ul.json-dict, ol.json-array', function (el) { | ||
el.style.display = el.style.display === '' || el.style.display === 'block' ? 'none' : 'block'; | ||
}); // ForEach subtarget, previous siblings return array so we parse it | ||
if (!source instanceof Element) { | ||
return 1; | ||
} | ||
for (var i = 0; i < subTarget.length; i += 1) { | ||
if (!isHidden(subTarget[i])) { | ||
// Parse every siblings with '.json-placehoder' and remove them (previous add by else) | ||
siblings(subTarget[i], '.json-placeholder', function (el) { | ||
return el.parentNode.removeChild(el); | ||
}); | ||
} else { | ||
// count item in object / array | ||
var childs = subTarget[i].children; | ||
var count = 0; | ||
var targetList = []; | ||
for (var j = 0; j < childs.length; j += 1) { | ||
if (childs[j].tagName === 'LI') { | ||
count += 1; | ||
} | ||
} | ||
if (target) { | ||
if (target.length) { | ||
targetList = target; | ||
} else if (target.value) { | ||
targetList = [target]; | ||
} else { | ||
return 3; | ||
var placeholder = count + (count > 1 ? ' items' : ' item'); // Append a placeholder | ||
subTarget[i].insertAdjacentHTML('afterend', "<a href class=\"json-placeholder\">".concat(placeholder, "</a>")); | ||
} | ||
} else { | ||
return 3; | ||
} | ||
} // Prevent propagation | ||
options.pathQuotesType = options.pathQuotesType !== undefined ? options.pathQuotesType : 'single'; // Transform to HTML | ||
options.pickerIcon = options.pickerIcon || '#x1f4cb'; | ||
var html = json2html(json, options); | ||
if (isCollapsable(json)) html = "<a href class=\"json-toggle\"></a>".concat(html); // Insert HTML in target DOM element | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
source.innerHTML = html; // Bind click on toggle buttons | ||
function ToggleEventListener(event) { | ||
var t = event.target; | ||
off('click', source); | ||
while (t && t !== this) { | ||
if (t.matches('a.json-toggle')) { | ||
HandlerEventToggle.call(null, t, event); | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
function HandlerEventToggle(elm, event) { | ||
// Change class | ||
elm.classList.toggle('collapsed'); // Fetch every json-dict and json-array to toggle them | ||
t = t.parentNode; | ||
} | ||
} | ||
var subTarget = siblings(elm, 'ul.json-dict, ol.json-array', function (el) { | ||
el.style.display = el.style.display === '' || el.style.display === 'block' ? 'none' : 'block'; | ||
}); // ForEach subtarget, previous siblings return array so we parse it | ||
; // Simulate click on toggle button when placeholder is clicked | ||
for (var i = 0; i < subTarget.length; i += 1) { | ||
if (!isHidden(subTarget[i])) { | ||
// Parse every siblings with '.json-placehoder' and remove them (previous add by else) | ||
siblings(subTarget[i], '.json-placeholder', function (el) { | ||
return el.parentNode.removeChild(el); | ||
}); | ||
} else { | ||
// count item in object / array | ||
var childs = subTarget[i].children; | ||
var count = 0; | ||
function SimulateClickHandler(elm, event) { | ||
siblings(elm, 'a.json-toggle', function (el) { | ||
return fireClick(el, 'click'); | ||
}); | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
for (var j = 0; j < childs.length; j += 1) { | ||
if (childs[j].tagName === 'LI') { | ||
count += 1; | ||
} | ||
} | ||
function SimulateClickEventListener(event) { | ||
var t = event.target; | ||
var placeholder = count + (count > 1 ? ' items' : ' item'); // Append a placeholder | ||
while (t && t !== this) { | ||
if (t.matches('a.json-placeholder')) { | ||
SimulateClickHandler.call(null, t, event); | ||
} | ||
subTarget[i].insertAdjacentHTML('afterend', "<a href class=\"json-placeholder\">".concat(placeholder, "</a>")); | ||
} | ||
} // Prevent propagation | ||
t = t.parentNode; | ||
} | ||
} | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
function PickPathHandler(elm) { | ||
if (targetList.length === 0) { | ||
return; | ||
} | ||
source.addEventListener('click', function ToggleEventListener(event) { | ||
var t = event.target; | ||
var $parentsList = getParents(elm, 'li').reverse(); | ||
var pathSegments = []; | ||
while (t && t !== this) { | ||
if (t.matches('a.json-toggle')) { | ||
HandlerEventToggle.call(null, t, event); | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
for (var i = 0; i < $parentsList.length; i += 1) { | ||
var key = $parentsList[i].dataset.key; | ||
var keyType = $parentsList[i].dataset.keyType; | ||
t = t.parentNode; | ||
if (keyType === 'object' && typeof key !== 'number' && options.processKeys && options.keyReplaceRegexPattern !== undefined) { | ||
var keyReplaceRegex = new RegExp(options.keyReplaceRegexPattern, options.keyReplaceRegexFlags); | ||
var keyReplacementText = options.keyReplacementText === undefined ? '' : options.keyReplacementText; | ||
key = key.replace(keyReplaceRegex, keyReplacementText); | ||
} | ||
}); // Simulate click on toggle button when placeholder is clicked | ||
function SimulateClickHandler(elm, event) { | ||
siblings(elm, 'a.json-toggle', function (el) { | ||
return fireClick(el, 'click'); | ||
pathSegments.push({ | ||
key: key, | ||
keyType: keyType | ||
}); | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
source.addEventListener('click', function SimulateClickEventListener(event) { | ||
var t = event.target; | ||
var quotes = { | ||
none: '', | ||
single: '\'', | ||
"double": '"' | ||
}; | ||
var quote = quotes[options.pathQuotesType]; | ||
pathSegments = pathSegments.map(function (segment, idx) { | ||
var isBracketsNotation = options.pathNotation === 'brackets'; | ||
var isKeyForbiddenInDotNotation = !/^\w+$/.test(segment.key) || typeof segment.key === 'number'; | ||
while (t && t !== this) { | ||
if (t.matches('a.json-placeholder')) { | ||
SimulateClickHandler.call(null, t, event); | ||
} | ||
if (segment.keyType === 'array' || segment.isKeyANumber) { | ||
return "[".concat(segment.key, "]"); | ||
} | ||
t = t.parentNode; | ||
if (isBracketsNotation || isKeyForbiddenInDotNotation) { | ||
return "[".concat(quote).concat(segment.key).concat(quote, "]"); | ||
} | ||
}); | ||
function PickPathHandler(elm) { | ||
if (targetList.length === 0) { | ||
return; | ||
if (idx > 0) { | ||
return ".".concat(segment.key); | ||
} | ||
var $parentsList = getParents(elm, 'li').reverse(); | ||
var pathSegments = []; | ||
return segment.key; | ||
}); | ||
var path = pathSegments.join(''); | ||
for (var i = 0; i < $parentsList.length; i += 1) { | ||
var key = $parentsList[i].dataset.key; | ||
var keyType = $parentsList[i].dataset.keyType; | ||
for (var _i2 = 0; _i2 < targetList.length; _i2 += 1) { | ||
if (targetList[_i2].value !== undefined) { | ||
targetList[_i2].value = path; | ||
} | ||
} | ||
} | ||
if (keyType === 'object' && typeof key !== 'number' && options.processKeys && options.keyReplaceRegexPattern !== undefined) { | ||
var keyReplaceRegex = new RegExp(options.keyReplaceRegexPattern, options.keyReplaceRegexFlags); | ||
var keyReplacementText = options.keyReplacementText === undefined ? '' : options.keyReplacementText; | ||
key = key.replace(keyReplaceRegex, keyReplacementText); | ||
} | ||
function PickEventListener(event) { | ||
var t = event.target; | ||
pathSegments.push({ | ||
key: key, | ||
keyType: keyType | ||
}); | ||
while (t && t !== this) { | ||
if (t.matches('.pick-path')) { | ||
PickPathHandler.call(null, t, event); | ||
} | ||
var quotes = { | ||
none: '', | ||
single: '\'', | ||
"double": '"' | ||
}; | ||
var quote = quotes[options.pathQuotesType]; | ||
pathSegments = pathSegments.map(function (segment, idx) { | ||
var isBracketsNotation = options.pathNotation === 'brackets'; | ||
var isKeyForbiddenInDotNotation = !/^\w+$/.test(segment.key) || typeof segment.key === 'number'; | ||
t = t.parentNode; | ||
} | ||
} | ||
if (segment.keyType === 'array' || segment.isKeyANumber) { | ||
return "[".concat(segment.key, "]"); | ||
} | ||
var targetList = []; | ||
var options = {}; | ||
/** | ||
* Plugin method | ||
* @param source: Element | ||
* @param json: a javascript object | ||
* @param target: NodeListOf<Element> | Element | { value: String }[] | { value: String } | ||
* @param opt: an optional options hash | ||
*/ | ||
if (isBracketsNotation || isKeyForbiddenInDotNotation) { | ||
return "[".concat(quote).concat(segment.key).concat(quote, "]"); | ||
} | ||
function jsonPathPicker(source, json, target, opt) { | ||
options = opt || {}; | ||
if (idx > 0) { | ||
return ".".concat(segment.key); | ||
} | ||
if (!source instanceof Element) { | ||
return 1; | ||
} | ||
return segment.key; | ||
}); | ||
var path = pathSegments.join(''); | ||
for (var _i2 = 0; _i2 < targetList.length; _i2 += 1) { | ||
if (targetList[_i2].value !== undefined) { | ||
targetList[_i2].value = path; | ||
} | ||
if (target) { | ||
if (target.length) { | ||
targetList = target; | ||
} else if (target.value) { | ||
targetList = [target]; | ||
} else { | ||
return 3; | ||
} | ||
} else { | ||
return 3; | ||
} | ||
source.addEventListener('click', function PickEventListener(event) { | ||
var t = event.target; | ||
options.pathQuotesType = options.pathQuotesType !== undefined ? options.pathQuotesType : 'single'; // Transform to HTML | ||
while (t && t !== this) { | ||
if (t.matches('.pick-path')) { | ||
PickPathHandler.call(null, t, event); | ||
} | ||
options.pickerIcon = options.pickerIcon || '#x1f4cb'; | ||
var html = json2html(json, options); | ||
if (isCollapsable(json)) html = "<a href class=\"json-toggle\"></a>".concat(html); // Insert HTML in target DOM element | ||
t = t.parentNode; | ||
} | ||
}); | ||
source.innerHTML = html; // Bind click on toggle buttons | ||
off('click', source); | ||
source.addEventListener('click', ToggleEventListener); | ||
source.addEventListener('click', SimulateClickEventListener); | ||
source.addEventListener('click', PickEventListener); | ||
if (options.outputCollapsed === true) { | ||
@@ -432,3 +437,10 @@ // Trigger click to collapse all nodes | ||
function clearJsonPathPicker(source) { | ||
source.removeEventListener('click'); | ||
if (!source instanceof Element) { | ||
return 1; | ||
} //Remove event listener | ||
source.removeEventListener('click', PickEventListener); | ||
source.removeEventListener('click', ToggleEventListener); | ||
source.removeEventListener('click', SimulateClickEventListener); | ||
} | ||
@@ -435,0 +447,0 @@ |
@@ -246,181 +246,186 @@ (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
} | ||
/** | ||
* Plugin method | ||
* @param source: Element | ||
* @param json: a javascript object | ||
* @param target: NodeListOf<Element> | Element | { value: String }[] | { value: String } | ||
* @param opt: an optional options hash | ||
*/ | ||
function HandlerEventToggle(elm, event) { | ||
// Change class | ||
elm.classList.toggle('collapsed'); // Fetch every json-dict and json-array to toggle them | ||
function jsonPathPicker(source, json, target, opt) { | ||
var options = opt || {}; | ||
var subTarget = siblings(elm, 'ul.json-dict, ol.json-array', function (el) { | ||
el.style.display = el.style.display === '' || el.style.display === 'block' ? 'none' : 'block'; | ||
}); // ForEach subtarget, previous siblings return array so we parse it | ||
if (!source instanceof Element) { | ||
return 1; | ||
} | ||
for (var i = 0; i < subTarget.length; i += 1) { | ||
if (!isHidden(subTarget[i])) { | ||
// Parse every siblings with '.json-placehoder' and remove them (previous add by else) | ||
siblings(subTarget[i], '.json-placeholder', function (el) { | ||
return el.parentNode.removeChild(el); | ||
}); | ||
} else { | ||
// count item in object / array | ||
var childs = subTarget[i].children; | ||
var count = 0; | ||
var targetList = []; | ||
for (var j = 0; j < childs.length; j += 1) { | ||
if (childs[j].tagName === 'LI') { | ||
count += 1; | ||
} | ||
} | ||
if (target) { | ||
if (target.length) { | ||
targetList = target; | ||
} else if (target.value) { | ||
targetList = [target]; | ||
} else { | ||
return 3; | ||
var placeholder = count + (count > 1 ? ' items' : ' item'); // Append a placeholder | ||
subTarget[i].insertAdjacentHTML('afterend', "<a href class=\"json-placeholder\">".concat(placeholder, "</a>")); | ||
} | ||
} else { | ||
return 3; | ||
} | ||
} // Prevent propagation | ||
options.pathQuotesType = options.pathQuotesType !== undefined ? options.pathQuotesType : 'single'; // Transform to HTML | ||
options.pickerIcon = options.pickerIcon || '#x1f4cb'; | ||
var html = json2html(json, options); | ||
if (isCollapsable(json)) html = "<a href class=\"json-toggle\"></a>".concat(html); // Insert HTML in target DOM element | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
source.innerHTML = html; // Bind click on toggle buttons | ||
function ToggleEventListener(event) { | ||
var t = event.target; | ||
off('click', source); | ||
while (t && t !== this) { | ||
if (t.matches('a.json-toggle')) { | ||
HandlerEventToggle.call(null, t, event); | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
function HandlerEventToggle(elm, event) { | ||
// Change class | ||
elm.classList.toggle('collapsed'); // Fetch every json-dict and json-array to toggle them | ||
t = t.parentNode; | ||
} | ||
} | ||
var subTarget = siblings(elm, 'ul.json-dict, ol.json-array', function (el) { | ||
el.style.display = el.style.display === '' || el.style.display === 'block' ? 'none' : 'block'; | ||
}); // ForEach subtarget, previous siblings return array so we parse it | ||
; // Simulate click on toggle button when placeholder is clicked | ||
for (var i = 0; i < subTarget.length; i += 1) { | ||
if (!isHidden(subTarget[i])) { | ||
// Parse every siblings with '.json-placehoder' and remove them (previous add by else) | ||
siblings(subTarget[i], '.json-placeholder', function (el) { | ||
return el.parentNode.removeChild(el); | ||
}); | ||
} else { | ||
// count item in object / array | ||
var childs = subTarget[i].children; | ||
var count = 0; | ||
function SimulateClickHandler(elm, event) { | ||
siblings(elm, 'a.json-toggle', function (el) { | ||
return fireClick(el, 'click'); | ||
}); | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
for (var j = 0; j < childs.length; j += 1) { | ||
if (childs[j].tagName === 'LI') { | ||
count += 1; | ||
} | ||
} | ||
function SimulateClickEventListener(event) { | ||
var t = event.target; | ||
var placeholder = count + (count > 1 ? ' items' : ' item'); // Append a placeholder | ||
while (t && t !== this) { | ||
if (t.matches('a.json-placeholder')) { | ||
SimulateClickHandler.call(null, t, event); | ||
} | ||
subTarget[i].insertAdjacentHTML('afterend', "<a href class=\"json-placeholder\">".concat(placeholder, "</a>")); | ||
} | ||
} // Prevent propagation | ||
t = t.parentNode; | ||
} | ||
} | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
function PickPathHandler(elm) { | ||
if (targetList.length === 0) { | ||
return; | ||
} | ||
source.addEventListener('click', function ToggleEventListener(event) { | ||
var t = event.target; | ||
var $parentsList = getParents(elm, 'li').reverse(); | ||
var pathSegments = []; | ||
while (t && t !== this) { | ||
if (t.matches('a.json-toggle')) { | ||
HandlerEventToggle.call(null, t, event); | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
for (var i = 0; i < $parentsList.length; i += 1) { | ||
var key = $parentsList[i].dataset.key; | ||
var keyType = $parentsList[i].dataset.keyType; | ||
t = t.parentNode; | ||
if (keyType === 'object' && typeof key !== 'number' && options.processKeys && options.keyReplaceRegexPattern !== undefined) { | ||
var keyReplaceRegex = new RegExp(options.keyReplaceRegexPattern, options.keyReplaceRegexFlags); | ||
var keyReplacementText = options.keyReplacementText === undefined ? '' : options.keyReplacementText; | ||
key = key.replace(keyReplaceRegex, keyReplacementText); | ||
} | ||
}); // Simulate click on toggle button when placeholder is clicked | ||
function SimulateClickHandler(elm, event) { | ||
siblings(elm, 'a.json-toggle', function (el) { | ||
return fireClick(el, 'click'); | ||
pathSegments.push({ | ||
key: key, | ||
keyType: keyType | ||
}); | ||
event.stopPropagation(); | ||
event.preventDefault(); | ||
} | ||
source.addEventListener('click', function SimulateClickEventListener(event) { | ||
var t = event.target; | ||
var quotes = { | ||
none: '', | ||
single: '\'', | ||
"double": '"' | ||
}; | ||
var quote = quotes[options.pathQuotesType]; | ||
pathSegments = pathSegments.map(function (segment, idx) { | ||
var isBracketsNotation = options.pathNotation === 'brackets'; | ||
var isKeyForbiddenInDotNotation = !/^\w+$/.test(segment.key) || typeof segment.key === 'number'; | ||
while (t && t !== this) { | ||
if (t.matches('a.json-placeholder')) { | ||
SimulateClickHandler.call(null, t, event); | ||
} | ||
if (segment.keyType === 'array' || segment.isKeyANumber) { | ||
return "[".concat(segment.key, "]"); | ||
} | ||
t = t.parentNode; | ||
if (isBracketsNotation || isKeyForbiddenInDotNotation) { | ||
return "[".concat(quote).concat(segment.key).concat(quote, "]"); | ||
} | ||
}); | ||
function PickPathHandler(elm) { | ||
if (targetList.length === 0) { | ||
return; | ||
if (idx > 0) { | ||
return ".".concat(segment.key); | ||
} | ||
var $parentsList = getParents(elm, 'li').reverse(); | ||
var pathSegments = []; | ||
return segment.key; | ||
}); | ||
var path = pathSegments.join(''); | ||
for (var i = 0; i < $parentsList.length; i += 1) { | ||
var key = $parentsList[i].dataset.key; | ||
var keyType = $parentsList[i].dataset.keyType; | ||
for (var _i2 = 0; _i2 < targetList.length; _i2 += 1) { | ||
if (targetList[_i2].value !== undefined) { | ||
targetList[_i2].value = path; | ||
} | ||
} | ||
} | ||
if (keyType === 'object' && typeof key !== 'number' && options.processKeys && options.keyReplaceRegexPattern !== undefined) { | ||
var keyReplaceRegex = new RegExp(options.keyReplaceRegexPattern, options.keyReplaceRegexFlags); | ||
var keyReplacementText = options.keyReplacementText === undefined ? '' : options.keyReplacementText; | ||
key = key.replace(keyReplaceRegex, keyReplacementText); | ||
} | ||
function PickEventListener(event) { | ||
var t = event.target; | ||
pathSegments.push({ | ||
key: key, | ||
keyType: keyType | ||
}); | ||
while (t && t !== this) { | ||
if (t.matches('.pick-path')) { | ||
PickPathHandler.call(null, t, event); | ||
} | ||
var quotes = { | ||
none: '', | ||
single: '\'', | ||
"double": '"' | ||
}; | ||
var quote = quotes[options.pathQuotesType]; | ||
pathSegments = pathSegments.map(function (segment, idx) { | ||
var isBracketsNotation = options.pathNotation === 'brackets'; | ||
var isKeyForbiddenInDotNotation = !/^\w+$/.test(segment.key) || typeof segment.key === 'number'; | ||
t = t.parentNode; | ||
} | ||
} | ||
if (segment.keyType === 'array' || segment.isKeyANumber) { | ||
return "[".concat(segment.key, "]"); | ||
} | ||
var targetList = []; | ||
var options = {}; | ||
/** | ||
* Plugin method | ||
* @param source: Element | ||
* @param json: a javascript object | ||
* @param target: NodeListOf<Element> | Element | { value: String }[] | { value: String } | ||
* @param opt: an optional options hash | ||
*/ | ||
if (isBracketsNotation || isKeyForbiddenInDotNotation) { | ||
return "[".concat(quote).concat(segment.key).concat(quote, "]"); | ||
} | ||
function jsonPathPicker(source, json, target, opt) { | ||
options = opt || {}; | ||
if (idx > 0) { | ||
return ".".concat(segment.key); | ||
} | ||
if (!source instanceof Element) { | ||
return 1; | ||
} | ||
return segment.key; | ||
}); | ||
var path = pathSegments.join(''); | ||
for (var _i2 = 0; _i2 < targetList.length; _i2 += 1) { | ||
if (targetList[_i2].value !== undefined) { | ||
targetList[_i2].value = path; | ||
} | ||
if (target) { | ||
if (target.length) { | ||
targetList = target; | ||
} else if (target.value) { | ||
targetList = [target]; | ||
} else { | ||
return 3; | ||
} | ||
} else { | ||
return 3; | ||
} | ||
source.addEventListener('click', function PickEventListener(event) { | ||
var t = event.target; | ||
options.pathQuotesType = options.pathQuotesType !== undefined ? options.pathQuotesType : 'single'; // Transform to HTML | ||
while (t && t !== this) { | ||
if (t.matches('.pick-path')) { | ||
PickPathHandler.call(null, t, event); | ||
} | ||
options.pickerIcon = options.pickerIcon || '#x1f4cb'; | ||
var html = json2html(json, options); | ||
if (isCollapsable(json)) html = "<a href class=\"json-toggle\"></a>".concat(html); // Insert HTML in target DOM element | ||
t = t.parentNode; | ||
} | ||
}); | ||
source.innerHTML = html; // Bind click on toggle buttons | ||
off('click', source); | ||
source.addEventListener('click', ToggleEventListener); | ||
source.addEventListener('click', SimulateClickEventListener); | ||
source.addEventListener('click', PickEventListener); | ||
if (options.outputCollapsed === true) { | ||
@@ -442,3 +447,10 @@ // Trigger click to collapse all nodes | ||
function clearJsonPathPicker(source) { | ||
source.removeEventListener('click'); | ||
if (!source instanceof Element) { | ||
return 1; | ||
} //Remove event listener | ||
source.removeEventListener('click', PickEventListener); | ||
source.removeEventListener('click', ToggleEventListener); | ||
source.removeEventListener('click', SimulateClickEventListener); | ||
} | ||
@@ -445,0 +457,0 @@ |
@@ -1,1 +0,1 @@ | ||
!function a(c,i,s){function l(t,e){if(!i[t]){if(!c[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(p)return p(t,!0);var o=new Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}var r=i[t]={exports:{}};c[t][0].call(r.exports,function(e){return l(c[t][1][e]||e)},r,r.exports,a,c,i,s)}return i[t].exports}for(var p="function"==typeof require&&require,e=0;e<s.length;e++)l(s[e]);return l}({1:[function(e,t,n){"use strict";var o=e("./jsonpath-picker"),r=window.JPPicker||{};r.render=o.jsonPathPicker,r.destory=o.clearJsonPathPicker,window.JPPicker=r},{"./jsonpath-picker":2}],2:[function(e,t,n){"use strict";function p(e){return(p="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function y(e){return e instanceof Object&&0<Object.keys(e).length}function h(e,t,n){for(var o=[],r=0;r<e.parentNode.children.length;r+=1){var a=e.parentNode.children[r];a===e||t&&!a.matches(t)||o.push(a)}if(n&&"function"==typeof n)for(var c=0;c<o.length;c+=1)n(o[c]);return o}function v(e){var t;if(e.ownerDocument)t=e.ownerDocument;else{if(9!==e.nodeType)throw new Error("Invalid node passed to fireEvent: ".concat(e.id));t=e}if(e.dispatchEvent){var n=t.createEvent("MouseEvents");n.initEvent("click",!0,!0),n.synthetic=!0,e.dispatchEvent(n,!0)}else if(e.fireEvent){var o=t.createEventObject();o.synthetic=!0,e.fireEvent("onclick",o)}}t.exports={jsonPathPicker:function(e,t,n,o){var f=o||{};if(!e instanceof Element)return 1;var u=[];if(!n)return 3;if(n.length)u=n;else{if(!n.value)return 3;u=[n]}f.pathQuotesType=void 0!==f.pathQuotesType?f.pathQuotesType:"single",f.pickerIcon=f.pickerIcon||"#x1f4cb";var r=function e(t,n){var o="";if("string"==typeof t){var r=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");!function(e){return/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(e)}(r)?o+='<span class="json-string">"'.concat(r,'"</span>'):o+='<a href="'.concat(r,'" class="json-string">').concat(r,"</a>")}else if("number"==typeof t)o+='<span class="json-literal">'.concat(t,"</span>");else if("boolean"==typeof t)o+='<span class="json-literal">'.concat(t,"</span>");else if(null===t)o+='<span class="json-literal">null</span>';else if(t instanceof Array)if(0<t.length){o+='[<ol class="json-array">';for(var a=0;a<t.length;a+=1)o+='<li data-key-type="array" data-key="'.concat(a,'">'),y(t[a])&&(o+='<a href class="json-toggle"></a>'),o+=e(t[a],n),a<t.length-1&&(o+=","),o+="</li>";o+="</ol>]"}else o+="[]";else if("object"===p(t)){var c=Object.keys(t).length;if(0<c){for(var i in o+='{<ul class="json-dict">',t)if(t.hasOwnProperty(i)){o+='<li data-key-type="object" data-key="'.concat(i,'">');var s=n.outputWithQuotes?'<span class="json-string">"'.concat(i,'"</span>'):i;y(t[i])?o+='<a href class="json-toggle">'.concat(s,"</a>"):o+=s,o+='<span class="pick-path" title="Pick path">&'+n.pickerIcon+";</span>",o+=": ".concat(e(t[i],n)),0<(c-=1)&&(o+=","),o+="</li>"}o+="</ul>}"}else o+="{}"}return o}(t,f);function a(e,t){e.classList.toggle("collapsed");for(var n,o,r,a=h(e,"ul.json-dict, ol.json-array",function(e){e.style.display=""===e.style.display||"block"===e.style.display?"none":"block"}),c=0;c<a.length;c+=1)if(n=a[c],void 0,o=n.offsetWidth,r=n.offsetHeight,0===o&&0===r||"none"===window.getComputedStyle(n).display){for(var i=a[c].children,s=0,l=0;l<i.length;l+=1)"LI"===i[l].tagName&&(s+=1);var p=s+(1<s?" items":" item");a[c].insertAdjacentHTML("afterend",'<a href class="json-placeholder">'.concat(p,"</a>"))}else h(a[c],".json-placeholder",function(e){return e.parentNode.removeChild(e)});t.stopPropagation(),t.preventDefault()}function c(e,t){h(e,"a.json-toggle",function(e){return v(e)}),t.stopPropagation(),t.preventDefault()}function i(e){if(0!==u.length){for(var t=function(e,t){for(var n=[],o=e&&e.parentElement;o;o=o.parentElement)t&&!o.matches(t)||n.push(o);return n}(e,"li").reverse(),n=[],o=0;o<t.length;o+=1){var r=t[o].dataset.key,a=t[o].dataset.keyType;if("object"===a&&"number"!=typeof r&&f.processKeys&&void 0!==f.keyReplaceRegexPattern){var c=new RegExp(f.keyReplaceRegexPattern,f.keyReplaceRegexFlags),i=void 0===f.keyReplacementText?"":f.keyReplacementText;r=r.replace(c,i)}n.push({key:r,keyType:a})}for(var s={none:"",single:"'",double:'"'}[f.pathQuotesType],l=(n=n.map(function(e,t){var n="brackets"===f.pathNotation,o=!/^\w+$/.test(e.key)||"number"==typeof e.key;return"array"===e.keyType||e.isKeyANumber?"[".concat(e.key,"]"):n||o?"[".concat(s).concat(e.key).concat(s,"]"):0<t?".".concat(e.key):e.key})).join(""),p=0;p<u.length;p+=1)void 0!==u[p].value&&(u[p].value=l)}}if(y(t)&&(r='<a href class="json-toggle"></a>'.concat(r)),e.innerHTML=r,function(e,t,n,o){var r=o,a=n,c=t;"function"==typeof t&&(r=n,a=t,c=window),r=!!r,(c="string"==typeof c?document.querySelector(c):c)&&c.removeEventListener(e,a,r)}("click",e),e.addEventListener("click",function(e){for(var t=e.target;t&&t!==this;)t.matches("a.json-toggle")&&(a.call(null,t,e),e.stopPropagation(),e.preventDefault()),t=t.parentNode}),e.addEventListener("click",function(e){for(var t=e.target;t&&t!==this;)t.matches("a.json-placeholder")&&c.call(null,t,e),t=t.parentNode}),e.addEventListener("click",function(e){for(var t=e.target;t&&t!==this;)t.matches(".pick-path")&&i.call(null,t,e),t=t.parentNode}),!0===f.outputCollapsed)for(var s=document.querySelectorAll("a.json-toggle"),l=0;l<s.length;l+=1)v(s[l])},clearJsonPathPicker:function(e){e.removeEventListener("click")}}},{}]},{},[1]); | ||
!function a(c,i,s){function l(t,e){if(!i[t]){if(!c[t]){var n="function"==typeof require&&require;if(!e&&n)return n(t,!0);if(p)return p(t,!0);var o=new Error("Cannot find module '"+t+"'");throw o.code="MODULE_NOT_FOUND",o}var r=i[t]={exports:{}};c[t][0].call(r.exports,function(e){return l(c[t][1][e]||e)},r,r.exports,a,c,i,s)}return i[t].exports}for(var p="function"==typeof require&&require,e=0;e<s.length;e++)l(s[e]);return l}({1:[function(e,t,n){"use strict";var o=e("./jsonpath-picker"),r=window.JPPicker||{};r.render=o.jsonPathPicker,r.destory=o.clearJsonPathPicker,window.JPPicker=r},{"./jsonpath-picker":2}],2:[function(e,t,n){"use strict";function l(e){return(l="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e})(e)}function p(e){return e instanceof Object&&0<Object.keys(e).length}function f(e,t,n){for(var o=[],r=0;r<e.parentNode.children.length;r+=1){var a=e.parentNode.children[r];a===e||t&&!a.matches(t)||o.push(a)}if(n&&"function"==typeof n)for(var c=0;c<o.length;c+=1)n(o[c]);return o}function i(e){var t;if(e.ownerDocument)t=e.ownerDocument;else{if(9!==e.nodeType)throw new Error("Invalid node passed to fireEvent: ".concat(e.id));t=e}if(e.dispatchEvent){var n=t.createEvent("MouseEvents");n.initEvent("click",!0,!0),n.synthetic=!0,e.dispatchEvent(n,!0)}else if(e.fireEvent){var o=t.createEventObject();o.synthetic=!0,e.fireEvent("onclick",o)}}function o(e,t){e.classList.toggle("collapsed");for(var n,o,r,a=f(e,"ul.json-dict, ol.json-array",function(e){e.style.display=""===e.style.display||"block"===e.style.display?"none":"block"}),c=0;c<a.length;c+=1)if(n=a[c],void 0,o=n.offsetWidth,r=n.offsetHeight,0===o&&0===r||"none"===window.getComputedStyle(n).display){for(var i=a[c].children,s=0,l=0;l<i.length;l+=1)"LI"===i[l].tagName&&(s+=1);var p=s+(1<s?" items":" item");a[c].insertAdjacentHTML("afterend",'<a href class="json-placeholder">'.concat(p,"</a>"))}else f(a[c],".json-placeholder",function(e){return e.parentNode.removeChild(e)});t.stopPropagation(),t.preventDefault()}function s(e){for(var t=e.target;t&&t!==this;)t.matches("a.json-toggle")&&(o.call(null,t,e),e.stopPropagation(),e.preventDefault()),t=t.parentNode}function r(e,t){f(e,"a.json-toggle",function(e){return i(e)}),t.stopPropagation(),t.preventDefault()}function u(e){for(var t=e.target;t&&t!==this;)t.matches("a.json-placeholder")&&r.call(null,t,e),t=t.parentNode}function a(e){if(0!==v.length){for(var t=function(e,t){for(var n=[],o=e&&e.parentElement;o;o=o.parentElement)t&&!o.matches(t)||n.push(o);return n}(e,"li").reverse(),n=[],o=0;o<t.length;o+=1){var r=t[o].dataset.key,a=t[o].dataset.keyType;if("object"===a&&"number"!=typeof r&&h.processKeys&&void 0!==h.keyReplaceRegexPattern){var c=new RegExp(h.keyReplaceRegexPattern,h.keyReplaceRegexFlags),i=void 0===h.keyReplacementText?"":h.keyReplacementText;r=r.replace(c,i)}n.push({key:r,keyType:a})}for(var s={none:"",single:"'",double:'"'}[h.pathQuotesType],l=(n=n.map(function(e,t){var n="brackets"===h.pathNotation,o=!/^\w+$/.test(e.key)||"number"==typeof e.key;return"array"===e.keyType||e.isKeyANumber?"[".concat(e.key,"]"):n||o?"[".concat(s).concat(e.key).concat(s,"]"):0<t?".".concat(e.key):e.key})).join(""),p=0;p<v.length;p+=1)void 0!==v[p].value&&(v[p].value=l)}}function y(e){for(var t=e.target;t&&t!==this;)t.matches(".pick-path")&&a.call(null,t,e),t=t.parentNode}var v=[],h={};t.exports={jsonPathPicker:function(e,t,n,o){if(h=o||{},!e instanceof Element)return 1;if(!n)return 3;if(n.length)v=n;else{if(!n.value)return 3;v=[n]}h.pathQuotesType=void 0!==h.pathQuotesType?h.pathQuotesType:"single",h.pickerIcon=h.pickerIcon||"#x1f4cb";var r=function e(t,n){var o="";if("string"==typeof t){var r=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");!function(e){return/^(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0-9]+)?(\/|\/([\w#!:.?+=&%@!\-/]))?/.test(e)}(r)?o+='<span class="json-string">"'.concat(r,'"</span>'):o+='<a href="'.concat(r,'" class="json-string">').concat(r,"</a>")}else if("number"==typeof t)o+='<span class="json-literal">'.concat(t,"</span>");else if("boolean"==typeof t)o+='<span class="json-literal">'.concat(t,"</span>");else if(null===t)o+='<span class="json-literal">null</span>';else if(t instanceof Array)if(0<t.length){o+='[<ol class="json-array">';for(var a=0;a<t.length;a+=1)o+='<li data-key-type="array" data-key="'.concat(a,'">'),p(t[a])&&(o+='<a href class="json-toggle"></a>'),o+=e(t[a],n),a<t.length-1&&(o+=","),o+="</li>";o+="</ol>]"}else o+="[]";else if("object"===l(t)){var c=Object.keys(t).length;if(0<c){for(var i in o+='{<ul class="json-dict">',t)if(t.hasOwnProperty(i)){o+='<li data-key-type="object" data-key="'.concat(i,'">');var s=n.outputWithQuotes?'<span class="json-string">"'.concat(i,'"</span>'):i;p(t[i])?o+='<a href class="json-toggle">'.concat(s,"</a>"):o+=s,o+='<span class="pick-path" title="Pick path">&'+n.pickerIcon+";</span>",o+=": ".concat(e(t[i],n)),0<(c-=1)&&(o+=","),o+="</li>"}o+="</ul>}"}else o+="{}"}return o}(t,h);if(p(t)&&(r='<a href class="json-toggle"></a>'.concat(r)),e.innerHTML=r,function(e,t,n,o){var r=o,a=n,c=t;"function"==typeof t&&(r=n,a=t,c=window),r=!!r,(c="string"==typeof c?document.querySelector(c):c)&&c.removeEventListener(e,a,r)}("click",e),e.addEventListener("click",s),e.addEventListener("click",u),e.addEventListener("click",y),!0===h.outputCollapsed)for(var a=document.querySelectorAll("a.json-toggle"),c=0;c<a.length;c+=1)i(a[c])},clearJsonPathPicker:function(e){if(!e instanceof Element)return 1;e.removeEventListener("click",y),e.removeEventListener("click",s),e.removeEventListener("click",u)}}},{}]},{},[1]); |
{ | ||
"name": "jsonpath-picker-vanilla", | ||
"version": "1.1.0", | ||
"version": "1.1.1", | ||
"description": "JS native script for displaying JSON data with path picker feature", | ||
@@ -14,7 +14,9 @@ "author": "Oscar Marie--Taillefer", | ||
"min:css": "uglifycss --output lib/jsonpath-picker.min.css lib/jsonpath-picker.css", | ||
"min": "npm run min:js && npm run min:css", | ||
"min": "npm run min:js && npm run min:css && npm run post:min", | ||
"post:min": "cp lib/*.min.* public", | ||
"build:babel": "babel src -d build", | ||
"build:browser": "browserify build/jsonpath-picker.browser.js -o lib/jsonpath-picker.js", | ||
"build:node": "cp build/jsonpath-picker.js index.js", | ||
"build": "npm run build:babel && npm run build:browser && npm run build:node" | ||
"build": "npm run build:babel && npm run build:browser && npm run build:node", | ||
"deploy": "npm run build && npm run min" | ||
}, | ||
@@ -21,0 +23,0 @@ "keywords": [ |
@@ -0,1 +1,3 @@ | ||
[![npm version](https://badge.fury.io/js/jsonpath-picker-vanilla.svg)](https://badge.fury.io/js/jsonpath-picker-vanilla) | ||
# [JSON path picker](https://ryshu.github.io/jsonpath-picker/) | ||
@@ -2,0 +4,0 @@ |
42006
9
777
107