svelte-tree-view
Version:
Display JSON objects in a customizable tree-view
1,774 lines • 61.2 kB
JavaScript
var __defProp = Object.defineProperty;
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
var __publicField = (obj, key, value) => {
__defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
return value;
};
function noop() {
}
function assign(tar, src) {
for (const k in src)
tar[k] = src[k];
return (
/** @type {T & S} */
tar
);
}
function run(fn) {
return fn();
}
function blank_object() {
return /* @__PURE__ */ Object.create(null);
}
function run_all(fns) {
fns.forEach(run);
}
function is_function(thing) {
return typeof thing === "function";
}
function safe_not_equal(a, b) {
return a != a ? b == b : a !== b || a && typeof a === "object" || typeof a === "function";
}
function is_empty(obj) {
return Object.keys(obj).length === 0;
}
function subscribe(store, ...callbacks) {
if (store == null) {
for (const callback of callbacks) {
callback(void 0);
}
return noop;
}
const unsub = store.subscribe(...callbacks);
return unsub.unsubscribe ? () => unsub.unsubscribe() : unsub;
}
function get_store_value(store) {
let value;
subscribe(store, (_) => value = _)();
return value;
}
function component_subscribe(component, store, callback) {
component.$$.on_destroy.push(subscribe(store, callback));
}
function exclude_internal_props(props) {
const result = {};
for (const k in props)
if (k[0] !== "$")
result[k] = props[k];
return result;
}
function null_to_empty(value) {
return value == null ? "" : value;
}
let is_hydrating = false;
function start_hydrating() {
is_hydrating = true;
}
function end_hydrating() {
is_hydrating = false;
}
function upper_bound(low, high, key, value) {
while (low < high) {
const mid = low + (high - low >> 1);
if (key(mid) <= value) {
low = mid + 1;
} else {
high = mid;
}
}
return low;
}
function init_hydrate(target) {
if (target.hydrate_init)
return;
target.hydrate_init = true;
let children2 = (
/** @type {ArrayLike<NodeEx2>} */
target.childNodes
);
if (target.nodeName === "HEAD") {
const myChildren = [];
for (let i = 0; i < children2.length; i++) {
const node = children2[i];
if (node.claim_order !== void 0) {
myChildren.push(node);
}
}
children2 = myChildren;
}
const m = new Int32Array(children2.length + 1);
const p = new Int32Array(children2.length);
m[0] = -1;
let longest = 0;
for (let i = 0; i < children2.length; i++) {
const current = children2[i].claim_order;
const seqLen = (longest > 0 && children2[m[longest]].claim_order <= current ? longest + 1 : upper_bound(1, longest, (idx) => children2[m[idx]].claim_order, current)) - 1;
p[i] = m[seqLen] + 1;
const newLen = seqLen + 1;
m[newLen] = i;
longest = Math.max(newLen, longest);
}
const lis = [];
const toMove = [];
let last = children2.length - 1;
for (let cur = m[longest] + 1; cur != 0; cur = p[cur - 1]) {
lis.push(children2[cur - 1]);
for (; last >= cur; last--) {
toMove.push(children2[last]);
}
last--;
}
for (; last >= 0; last--) {
toMove.push(children2[last]);
}
lis.reverse();
toMove.sort((a, b) => a.claim_order - b.claim_order);
for (let i = 0, j = 0; i < toMove.length; i++) {
while (j < lis.length && toMove[i].claim_order >= lis[j].claim_order) {
j++;
}
const anchor = j < lis.length ? lis[j] : null;
target.insertBefore(toMove[i], anchor);
}
}
function append(target, node) {
target.appendChild(node);
}
function append_styles(target, style_sheet_id, styles) {
const append_styles_to = get_root_for_style(target);
if (!append_styles_to.getElementById(style_sheet_id)) {
const style = element("style");
style.id = style_sheet_id;
style.textContent = styles;
append_stylesheet(append_styles_to, style);
}
}
function get_root_for_style(node) {
if (!node)
return document;
const root = node.getRootNode ? node.getRootNode() : node.ownerDocument;
if (root && /** @type {ShadowRoot} */
root.host) {
return (
/** @type {ShadowRoot} */
root
);
}
return node.ownerDocument;
}
function append_stylesheet(node, style) {
append(
/** @type {Document} */
node.head || node,
style
);
return style.sheet;
}
function append_hydration(target, node) {
if (is_hydrating) {
init_hydrate(target);
if (target.actual_end_child === void 0 || target.actual_end_child !== null && target.actual_end_child.parentNode !== target) {
target.actual_end_child = target.firstChild;
}
while (target.actual_end_child !== null && target.actual_end_child.claim_order === void 0) {
target.actual_end_child = target.actual_end_child.nextSibling;
}
if (node !== target.actual_end_child) {
if (node.claim_order !== void 0 || node.parentNode !== target) {
target.insertBefore(node, target.actual_end_child);
}
} else {
target.actual_end_child = node.nextSibling;
}
} else if (node.parentNode !== target || node.nextSibling !== null) {
target.appendChild(node);
}
}
function insert_hydration(target, node, anchor) {
if (is_hydrating && !anchor) {
append_hydration(target, node);
} else if (node.parentNode !== target || node.nextSibling != anchor) {
target.insertBefore(node, anchor || null);
}
}
function detach(node) {
if (node.parentNode) {
node.parentNode.removeChild(node);
}
}
function destroy_each(iterations, detaching) {
for (let i = 0; i < iterations.length; i += 1) {
if (iterations[i])
iterations[i].d(detaching);
}
}
function element(name) {
return document.createElement(name);
}
function text(data) {
return document.createTextNode(data);
}
function space() {
return text(" ");
}
function empty() {
return text("");
}
function listen(node, event, handler, options) {
node.addEventListener(event, handler, options);
return () => node.removeEventListener(event, handler, options);
}
function attr(node, attribute, value) {
if (value == null)
node.removeAttribute(attribute);
else if (node.getAttribute(attribute) !== value)
node.setAttribute(attribute, value);
}
function get_svelte_dataset(node) {
return node.dataset.svelteH;
}
function children(element2) {
return Array.from(element2.childNodes);
}
function init_claim_info(nodes) {
if (nodes.claim_info === void 0) {
nodes.claim_info = { last_index: 0, total_claimed: 0 };
}
}
function claim_node(nodes, predicate, processNode, createNode2, dontUpdateLastIndex = false) {
init_claim_info(nodes);
const resultNode = (() => {
for (let i = nodes.claim_info.last_index; i < nodes.length; i++) {
const node = nodes[i];
if (predicate(node)) {
const replacement = processNode(node);
if (replacement === void 0) {
nodes.splice(i, 1);
} else {
nodes[i] = replacement;
}
if (!dontUpdateLastIndex) {
nodes.claim_info.last_index = i;
}
return node;
}
}
for (let i = nodes.claim_info.last_index - 1; i >= 0; i--) {
const node = nodes[i];
if (predicate(node)) {
const replacement = processNode(node);
if (replacement === void 0) {
nodes.splice(i, 1);
} else {
nodes[i] = replacement;
}
if (!dontUpdateLastIndex) {
nodes.claim_info.last_index = i;
} else if (replacement === void 0) {
nodes.claim_info.last_index--;
}
return node;
}
}
return createNode2();
})();
resultNode.claim_order = nodes.claim_info.total_claimed;
nodes.claim_info.total_claimed += 1;
return resultNode;
}
function claim_element_base(nodes, name, attributes, create_element) {
return claim_node(
nodes,
/** @returns {node is Element | SVGElement} */
(node) => node.nodeName === name,
/** @param {Element} node */
(node) => {
const remove = [];
for (let j = 0; j < node.attributes.length; j++) {
const attribute = node.attributes[j];
if (!attributes[attribute.name]) {
remove.push(attribute.name);
}
}
remove.forEach((v) => node.removeAttribute(v));
return void 0;
},
() => create_element(name)
);
}
function claim_element(nodes, name, attributes) {
return claim_element_base(nodes, name, attributes, element);
}
function claim_text(nodes, data) {
return claim_node(
nodes,
/** @returns {node is Text} */
(node) => node.nodeType === 3,
/** @param {Text} node */
(node) => {
const dataStr = "" + data;
if (node.data.startsWith(dataStr)) {
if (node.data.length !== dataStr.length) {
return node.splitText(dataStr.length);
}
} else {
node.data = dataStr;
}
},
() => text(data),
true
// Text nodes should not update last index since it is likely not worth it to eliminate an increasing subsequence of actual elements
);
}
function claim_space(nodes) {
return claim_text(nodes, " ");
}
function set_data(text2, data) {
data = "" + data;
if (text2.data === data)
return;
text2.data = /** @type {string} */
data;
}
function toggle_class(element2, name, toggle) {
element2.classList.toggle(name, !!toggle);
}
function construct_svelte_component(component, props) {
return new component(props);
}
let current_component;
function set_current_component(component) {
current_component = component;
}
function get_current_component() {
if (!current_component)
throw new Error("Function called outside component initialization");
return current_component;
}
function onMount(fn) {
get_current_component().$$.on_mount.push(fn);
}
function setContext(key, context) {
get_current_component().$$.context.set(key, context);
return context;
}
function getContext(key) {
return get_current_component().$$.context.get(key);
}
const dirty_components = [];
const binding_callbacks = [];
let render_callbacks = [];
const flush_callbacks = [];
const resolved_promise = /* @__PURE__ */ Promise.resolve();
let update_scheduled = false;
function schedule_update() {
if (!update_scheduled) {
update_scheduled = true;
resolved_promise.then(flush);
}
}
function add_render_callback(fn) {
render_callbacks.push(fn);
}
const seen_callbacks = /* @__PURE__ */ new Set();
let flushidx = 0;
function flush() {
if (flushidx !== 0) {
return;
}
const saved_component = current_component;
do {
try {
while (flushidx < dirty_components.length) {
const component = dirty_components[flushidx];
flushidx++;
set_current_component(component);
update(component.$$);
}
} catch (e) {
dirty_components.length = 0;
flushidx = 0;
throw e;
}
set_current_component(null);
dirty_components.length = 0;
flushidx = 0;
while (binding_callbacks.length)
binding_callbacks.pop()();
for (let i = 0; i < render_callbacks.length; i += 1) {
const callback = render_callbacks[i];
if (!seen_callbacks.has(callback)) {
seen_callbacks.add(callback);
callback();
}
}
render_callbacks.length = 0;
} while (dirty_components.length);
while (flush_callbacks.length) {
flush_callbacks.pop()();
}
update_scheduled = false;
seen_callbacks.clear();
set_current_component(saved_component);
}
function update($$) {
if ($$.fragment !== null) {
$$.update();
run_all($$.before_update);
const dirty = $$.dirty;
$$.dirty = [-1];
$$.fragment && $$.fragment.p($$.ctx, dirty);
$$.after_update.forEach(add_render_callback);
}
}
function flush_render_callbacks(fns) {
const filtered = [];
const targets = [];
render_callbacks.forEach((c) => fns.indexOf(c) === -1 ? filtered.push(c) : targets.push(c));
targets.forEach((c) => c());
render_callbacks = filtered;
}
const outroing = /* @__PURE__ */ new Set();
let outros;
function group_outros() {
outros = {
r: 0,
c: [],
p: outros
// parent group
};
}
function check_outros() {
if (!outros.r) {
run_all(outros.c);
}
outros = outros.p;
}
function transition_in(block, local) {
if (block && block.i) {
outroing.delete(block);
block.i(local);
}
}
function transition_out(block, local, detach2, callback) {
if (block && block.o) {
if (outroing.has(block))
return;
outroing.add(block);
outros.c.push(() => {
outroing.delete(block);
if (callback) {
if (detach2)
block.d(1);
callback();
}
});
block.o(local);
} else if (callback) {
callback();
}
}
function ensure_array_like(array_like_or_iterator) {
return (array_like_or_iterator == null ? void 0 : array_like_or_iterator.length) !== void 0 ? array_like_or_iterator : Array.from(array_like_or_iterator);
}
function create_component(block) {
block && block.c();
}
function claim_component(block, parent_nodes) {
block && block.l(parent_nodes);
}
function mount_component(component, target, anchor) {
const { fragment, after_update } = component.$$;
fragment && fragment.m(target, anchor);
add_render_callback(() => {
const new_on_destroy = component.$$.on_mount.map(run).filter(is_function);
if (component.$$.on_destroy) {
component.$$.on_destroy.push(...new_on_destroy);
} else {
run_all(new_on_destroy);
}
component.$$.on_mount = [];
});
after_update.forEach(add_render_callback);
}
function destroy_component(component, detaching) {
const $$ = component.$$;
if ($$.fragment !== null) {
flush_render_callbacks($$.after_update);
run_all($$.on_destroy);
$$.fragment && $$.fragment.d(detaching);
$$.on_destroy = $$.fragment = null;
$$.ctx = [];
}
}
function make_dirty(component, i) {
if (component.$$.dirty[0] === -1) {
dirty_components.push(component);
schedule_update();
component.$$.dirty.fill(0);
}
component.$$.dirty[i / 31 | 0] |= 1 << i % 31;
}
function init(component, options, instance2, create_fragment2, not_equal, props, append_styles2, dirty = [-1]) {
const parent_component = current_component;
set_current_component(component);
const $$ = component.$$ = {
fragment: null,
ctx: [],
// state
props,
update: noop,
not_equal,
bound: blank_object(),
// lifecycle
on_mount: [],
on_destroy: [],
on_disconnect: [],
before_update: [],
after_update: [],
context: new Map(options.context || (parent_component ? parent_component.$$.context : [])),
// everything else
callbacks: blank_object(),
dirty,
skip_bound: false,
root: options.target || parent_component.$$.root
};
append_styles2 && append_styles2($$.root);
let ready = false;
$$.ctx = instance2 ? instance2(component, options.props || {}, (i, ret, ...rest) => {
const value = rest.length ? rest[0] : ret;
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
if (!$$.skip_bound && $$.bound[i])
$$.bound[i](value);
if (ready)
make_dirty(component, i);
}
return ret;
}) : [];
$$.update();
ready = true;
run_all($$.before_update);
$$.fragment = create_fragment2 ? create_fragment2($$.ctx) : false;
if (options.target) {
if (options.hydrate) {
start_hydrating();
const nodes = children(options.target);
$$.fragment && $$.fragment.l(nodes);
nodes.forEach(detach);
} else {
$$.fragment && $$.fragment.c();
}
if (options.intro)
transition_in(component.$$.fragment);
mount_component(component, options.target, options.anchor);
end_hydrating();
flush();
}
set_current_component(parent_component);
}
class SvelteComponent {
constructor() {
/**
* ### PRIVATE API
*
* Do not use, may change at any time
*
* @type {any}
*/
__publicField(this, "$$");
/**
* ### PRIVATE API
*
* Do not use, may change at any time
*
* @type {any}
*/
__publicField(this, "$$set");
}
/** @returns {void} */
$destroy() {
destroy_component(this, 1);
this.$destroy = noop;
}
/**
* @template {Extract<keyof Events, string>} K
* @param {K} type
* @param {((e: Events[K]) => void) | null | undefined} callback
* @returns {() => void}
*/
$on(type, callback) {
if (!is_function(callback)) {
return noop;
}
const callbacks = this.$$.callbacks[type] || (this.$$.callbacks[type] = []);
callbacks.push(callback);
return () => {
const index = callbacks.indexOf(callback);
if (index !== -1)
callbacks.splice(index, 1);
};
}
/**
* @param {Partial<Props>} props
* @returns {void}
*/
$set(props) {
if (this.$$set && !is_empty(props)) {
this.$$.skip_bound = true;
this.$$set(props);
this.$$.skip_bound = false;
}
}
}
const PUBLIC_VERSION = "4";
if (typeof window !== "undefined")
(window.__svelte || (window.__svelte = { v: /* @__PURE__ */ new Set() })).v.add(PUBLIC_VERSION);
const subscriber_queue = [];
function readable(value, start) {
return {
subscribe: writable(value, start).subscribe
};
}
function writable(value, start = noop) {
let stop;
const subscribers = /* @__PURE__ */ new Set();
function set(new_value) {
if (safe_not_equal(value, new_value)) {
value = new_value;
if (stop) {
const run_queue = !subscriber_queue.length;
for (const subscriber of subscribers) {
subscriber[1]();
subscriber_queue.push(subscriber, value);
}
if (run_queue) {
for (let i = 0; i < subscriber_queue.length; i += 2) {
subscriber_queue[i][0](subscriber_queue[i + 1]);
}
subscriber_queue.length = 0;
}
}
}
}
function update2(fn) {
set(fn(value));
}
function subscribe2(run2, invalidate = noop) {
const subscriber = [run2, invalidate];
subscribers.add(subscriber);
if (subscribers.size === 1) {
stop = start(set, update2) || noop;
}
run2(value);
return () => {
subscribers.delete(subscriber);
if (subscribers.size === 0 && stop) {
stop();
stop = null;
}
};
}
return { set, update: update2, subscribe: subscribe2 };
}
function derived(stores, fn, initial_value) {
const single = !Array.isArray(stores);
const stores_array = single ? [stores] : stores;
if (!stores_array.every(Boolean)) {
throw new Error("derived() expects stores as input, got a falsy value");
}
const auto = fn.length < 2;
return readable(initial_value, (set, update2) => {
let started = false;
const values = [];
let pending = 0;
let cleanup = noop;
const sync = () => {
if (pending) {
return;
}
cleanup();
const result = fn(single ? values[0] : values, set, update2);
if (auto) {
set(result);
} else {
cleanup = is_function(result) ? result : noop;
}
};
const unsubscribers = stores_array.map(
(store, i) => subscribe(
store,
(value) => {
values[i] = value;
pending &= ~(1 << i);
if (started) {
sync();
}
},
() => {
pending |= 1 << i;
}
)
);
started = true;
sync();
return function stop() {
run_all(unsubscribers);
cleanup();
started = false;
};
});
}
function createNode(index, key, value, depth, parent) {
const path = parent ? [...parent.path, index] : [];
return {
id: `[${path.join(",")}]`,
index,
key,
value,
depth,
collapsed: true,
type: getValueType(value),
path,
parentId: parent ? parent.id : null,
circularOfId: null,
children: []
};
}
function getValueType(value) {
if (Array.isArray(value)) {
return "array";
} else if (value instanceof Map) {
return "map";
} else if (value instanceof Set) {
return "set";
} else if (value instanceof Date) {
return "date";
} else if (value === null) {
return "null";
} else {
return typeof value;
}
}
function getChildren(value, type) {
switch (type) {
case "array":
return value.map((v, i) => [i.toString(), v]);
case "map":
const entries = Array.from(value.entries());
return entries.map(([key, value2], i) => [
`[map entry ${i}]`,
{
"[key]": key,
"[value]": value2
}
]);
case "set":
return Array.from(value.values()).map((v, i) => [`[set entry ${i}]`, v]);
case "object":
return Object.entries(value);
default:
return [];
}
}
function shouldRecurseChildren(node, parent, iteratedValues, opts) {
if (!parent) {
return true;
} else if (node.collapsed && (parent == null ? void 0 : parent.collapsed)) {
return false;
} else if (!opts.stopCircularRecursion) {
return true;
} else if (opts.isCircularNode) {
return opts.isCircularNode(node, iteratedValues);
} else if (node.type === "object" || node.type === "array") {
const existingNodeWithValue = iteratedValues.get(node.value);
if (existingNodeWithValue && node.id !== existingNodeWithValue.id) {
node.circularOfId = existingNodeWithValue.id;
return false;
}
iteratedValues.set(node.value, node);
}
return true;
}
function recurseObjectProperties(index, key, value, depth, ensureNotCollapsed, parent, treeMap, oldTreeMap, iteratedValues, recomputeExpandNode, opts) {
var _a;
if (((_a = opts.omitKeys) == null ? void 0 : _a.includes(key)) || opts.maxDepth && depth > opts.maxDepth) {
return null;
}
const node = createNode(index, key, value, depth, parent);
const oldNode = oldTreeMap.get(node.id);
if (ensureNotCollapsed) {
node.collapsed = false;
} else if (oldNode && !recomputeExpandNode) {
node.collapsed = oldNode.collapsed;
} else if (opts.shouldExpandNode) {
node.collapsed = !opts.shouldExpandNode(node);
}
treeMap.set(node.id, node);
if (shouldRecurseChildren(node, parent, iteratedValues, opts)) {
const mappedChildren = opts.mapChildren && opts.mapChildren(value, getValueType(value), node);
const children2 = mappedChildren ?? getChildren(value, getValueType(value));
node.children = children2.map(
([key2, val], idx) => recurseObjectProperties(
idx,
key2,
val,
depth + 1,
false,
node,
treeMap,
oldTreeMap,
iteratedValues,
recomputeExpandNode,
opts
)
).filter((n) => n !== null);
}
return node;
}
function recomputeTree(data, oldTreeMap, recursionOpts, recomputeExpandNode) {
const treeMap = /* @__PURE__ */ new Map();
const iteratedValues = /* @__PURE__ */ new Map();
const newTree = recurseObjectProperties(
-1,
"root",
data,
0,
true,
null,
treeMap,
oldTreeMap,
iteratedValues,
recomputeExpandNode,
recursionOpts
);
return { treeMap, tree: newTree, iteratedValues };
}
const createPropsStore = (initialProps) => {
const props = writable(initialProps);
const recursionOpts = derived(props, (p) => p.recursionOpts);
return {
props,
recursionOpts,
setProps(newProps) {
props.set(newProps);
},
formatValue(val, node) {
const { valueFormatter } = get_store_value(props);
const customFormat = valueFormatter ? valueFormatter(val, node) : void 0;
if (customFormat) {
return customFormat;
}
switch (node.type) {
case "array":
return `${node.circularOfId ? "circular" : ""} [] ${val.length} items`;
case "object":
return `${node.circularOfId ? "circular" : ""} {} ${Object.keys(val).length} keys`;
case "map":
case "set":
return `${node.circularOfId ? "circular" : ""} () ${val.size} entries`;
case "date":
return `${val.toISOString()}`;
case "string":
return `"${val}"`;
case "boolean":
return val ? "true" : "false";
case "symbol":
return String(val);
default:
return val;
}
}
};
};
const createRootElementStore = () => {
const rootElementStore = writable(null);
return {
set: rootElementStore.set,
subscribe: rootElementStore.subscribe
};
};
const createTreeStore = (propsStore) => {
const defaultRootNode = createNode(0, "root", [], 0, null);
const tree = writable(defaultRootNode);
const treeMap = writable(/* @__PURE__ */ new Map());
const iteratedValues = writable(/* @__PURE__ */ new Map());
return {
tree,
treeMap,
defaultRootNode,
init(newTree, newTreeMap, iterated) {
if (newTree) {
tree.set(newTree);
} else {
tree.set(defaultRootNode);
}
treeMap.set(newTreeMap);
iteratedValues.set(iterated);
},
getNode(id) {
return get_store_value(treeMap).get(id);
},
toggleCollapse(id) {
const node = get_store_value(treeMap).get(id);
if (!node) {
console.warn(`Attempted to collapse non-existent node: ${id}`);
return;
}
const updatedNode = { ...node, collapsed: !node.collapsed };
treeMap.update((m) => new Map(m.set(node.id, updatedNode)));
const recursionOpts = get_store_value(propsStore.recursionOpts);
if (recursionOpts) {
this.expandNodeChildren(updatedNode, recursionOpts);
}
},
expandNodeChildren(node, recursionOpts) {
const parent = this.getNode((node == null ? void 0 : node.parentId) || "") || null;
if (!parent) {
throw Error("No parent in expandNodeChildren for node: " + node);
}
const newTreeMap = new Map(get_store_value(treeMap));
const oldTreeMap = get_store_value(treeMap);
const previouslyIterated = get_store_value(iteratedValues);
const nodeWithUpdatedChildren = recurseObjectProperties(
node.index,
node.key,
node.value,
node.depth,
!node.collapsed,
// Ensure that when uncollapsed the node's children are always recursed
parent,
newTreeMap,
oldTreeMap,
previouslyIterated,
false,
// Never recompute shouldExpandNode since it may override the collapsing of this node
recursionOpts
);
if (!nodeWithUpdatedChildren)
return;
parent.children = parent.children.map(
(c) => c.id === nodeWithUpdatedChildren.id ? nodeWithUpdatedChildren : c
);
newTreeMap.set(nodeWithUpdatedChildren.id, nodeWithUpdatedChildren);
newTreeMap.set(parent.id, parent);
treeMap.set(newTreeMap);
iteratedValues.set(previouslyIterated);
},
expandAllNodesToNode(id) {
function recurseNodeUpwards(updated2, node) {
if (!node)
return;
updated2.set(node.id, { ...node, collapsed: false });
if (node.parentId) {
recurseNodeUpwards(updated2, updated2.get(node.parentId));
}
}
const updated = new Map(get_store_value(treeMap));
recurseNodeUpwards(updated, updated.get(id));
treeMap.set(updated);
}
};
};
function add_css$1(target) {
append_styles(target, "svelte-ngcjq5", "ul.svelte-ngcjq5.svelte-ngcjq5{display:flex;flex-direction:column;height:max-content;list-style:none;padding:0;padding-left:var(--tree-view-left-indent);margin:0;width:100%}li.svelte-ngcjq5.svelte-ngcjq5{align-items:baseline;display:flex;height:max-content;line-height:var(--tree-view-line-height);list-style:none;width:100%}li.svelte-ngcjq5+li.svelte-ngcjq5{margin-top:0.25em}.empty-block.svelte-ngcjq5.svelte-ngcjq5{visibility:hidden}.node-key.svelte-ngcjq5.svelte-ngcjq5{color:var(--tree-view-base0D);margin-right:var(--tree-view-key-margin-right)}.node-key.has-children.svelte-ngcjq5.svelte-ngcjq5{cursor:pointer}.node-key.p-left.svelte-ngcjq5.svelte-ngcjq5{padding-left:1.1em}.node-value.svelte-ngcjq5.svelte-ngcjq5{color:var(--tree-view-base0B);margin-right:0.5em;word-break:break-all}.node-value[data-type=number].svelte-ngcjq5.svelte-ngcjq5,.node-value[data-type=boolean].svelte-ngcjq5.svelte-ngcjq5{color:var(--tree-view-base09)}.node-value[data-type=null].svelte-ngcjq5.svelte-ngcjq5,.node-value[data-type=undefined].svelte-ngcjq5.svelte-ngcjq5{color:var(--tree-view-base08)}.node-value.expanded.svelte-ngcjq5.svelte-ngcjq5{color:var(--tree-view-base03)}.node-value.has-children.svelte-ngcjq5.svelte-ngcjq5{cursor:pointer}.arrow-btn.svelte-ngcjq5.svelte-ngcjq5{background:transparent;border:0;color:var(--tree-view-base0D);cursor:pointer;margin-right:0.7em;padding:0;transition:all 150ms ease 0s;transform:rotateZ(90deg);transform-origin:47% 43%;position:relative;line-height:1.1em;font-size:0.75em}.arrow-btn.collapsed.svelte-ngcjq5.svelte-ngcjq5{transform:rotateZ(0deg)}.buttons.svelte-ngcjq5.svelte-ngcjq5{display:flex;flex-wrap:wrap}.log-copy-button.svelte-ngcjq5.svelte-ngcjq5{background:transparent;border:0;color:var(--tree-view-base0D);cursor:pointer;margin:0;padding:0 0.5em}.log-copy-button.svelte-ngcjq5.svelte-ngcjq5:hover{background:rgba(255, 162, 177, 0.4);border-radius:2px;color:var(--tree-view-base07)}");
}
function get_each_context$1(ctx, list, i) {
const child_ctx = ctx.slice();
child_ctx[14] = list[i];
return child_ctx;
}
function create_if_block_4(ctx) {
let button;
let t;
let button_class_value;
let mounted;
let dispose;
return {
c() {
button = element("button");
t = text("▶");
this.h();
},
l(nodes) {
button = claim_element(nodes, "BUTTON", { class: true });
var button_nodes = children(button);
t = claim_text(button_nodes, "▶");
button_nodes.forEach(detach);
this.h();
},
h() {
attr(button, "class", button_class_value = null_to_empty(`arrow-btn ${/*node*/
ctx[0].collapsed ? "collapsed" : ""}`) + " svelte-ngcjq5");
},
m(target, anchor) {
insert_hydration(target, button, anchor);
append_hydration(button, t);
if (!mounted) {
dispose = listen(
button,
"click",
/*handleToggleCollapse*/
ctx[9]
);
mounted = true;
}
},
p(ctx2, dirty) {
if (dirty & /*node*/
1 && button_class_value !== (button_class_value = null_to_empty(`arrow-btn ${/*node*/
ctx2[0].collapsed ? "collapsed" : ""}`) + " svelte-ngcjq5")) {
attr(button, "class", button_class_value);
}
},
d(detaching) {
if (detaching) {
detach(button);
}
mounted = false;
dispose();
}
};
}
function create_else_block(ctx) {
let t_value = (
/*propsStore*/
ctx[5].formatValue(
/*node*/
ctx[0].value,
/*node*/
ctx[0]
) + ""
);
let t;
return {
c() {
t = text(t_value);
},
l(nodes) {
t = claim_text(nodes, t_value);
},
m(target, anchor) {
insert_hydration(target, t, anchor);
},
p(ctx2, dirty) {
if (dirty & /*node*/
1 && t_value !== (t_value = /*propsStore*/
ctx2[5].formatValue(
/*node*/
ctx2[0].value,
/*node*/
ctx2[0]
) + ""))
set_data(t, t_value);
},
i: noop,
o: noop,
d(detaching) {
if (detaching) {
detach(t);
}
}
};
}
function create_if_block_3(ctx) {
let switch_instance;
let switch_instance_anchor;
let current;
var switch_value = (
/*valueComponent*/
ctx[3]
);
function switch_props(ctx2) {
return {
props: {
value: (
/*node*/
ctx2[0].value
),
node: (
/*node*/
ctx2[0]
),
defaultFormatter: (
/*valueComponentDefaultFormatter*/
ctx2[10]
)
}
};
}
if (switch_value) {
switch_instance = construct_svelte_component(switch_value, switch_props(ctx));
}
return {
c() {
if (switch_instance)
create_component(switch_instance.$$.fragment);
switch_instance_anchor = empty();
},
l(nodes) {
if (switch_instance)
claim_component(switch_instance.$$.fragment, nodes);
switch_instance_anchor = empty();
},
m(target, anchor) {
if (switch_instance)
mount_component(switch_instance, target, anchor);
insert_hydration(target, switch_instance_anchor, anchor);
current = true;
},
p(ctx2, dirty) {
if (dirty & /*valueComponent*/
8 && switch_value !== (switch_value = /*valueComponent*/
ctx2[3])) {
if (switch_instance) {
group_outros();
const old_component = switch_instance;
transition_out(old_component.$$.fragment, 1, 0, () => {
destroy_component(old_component, 1);
});
check_outros();
}
if (switch_value) {
switch_instance = construct_svelte_component(switch_value, switch_props(ctx2));
create_component(switch_instance.$$.fragment);
transition_in(switch_instance.$$.fragment, 1);
mount_component(switch_instance, switch_instance_anchor.parentNode, switch_instance_anchor);
} else {
switch_instance = null;
}
} else if (switch_value) {
const switch_instance_changes = {};
if (dirty & /*node*/
1)
switch_instance_changes.value = /*node*/
ctx2[0].value;
if (dirty & /*node*/
1)
switch_instance_changes.node = /*node*/
ctx2[0];
switch_instance.$set(switch_instance_changes);
}
},
i(local) {
if (current)
return;
if (switch_instance)
transition_in(switch_instance.$$.fragment, local);
current = true;
},
o(local) {
if (switch_instance)
transition_out(switch_instance.$$.fragment, local);
current = false;
},
d(detaching) {
if (detaching) {
detach(switch_instance_anchor);
}
if (switch_instance)
destroy_component(switch_instance, detaching);
}
};
}
function create_if_block_2(ctx) {
let button;
let textContent = "log";
let mounted;
let dispose;
return {
c() {
button = element("button");
button.textContent = textContent;
this.h();
},
l(nodes) {
button = claim_element(nodes, "BUTTON", { class: true, ["data-svelte-h"]: true });
if (get_svelte_dataset(button) !== "svelte-vf5gek")
button.textContent = textContent;
this.h();
},
h() {
attr(button, "class", "log-copy-button svelte-ngcjq5");
},
m(target, anchor) {
insert_hydration(target, button, anchor);
if (!mounted) {
dispose = listen(
button,
"click",
/*handleLogNode*/
ctx[7]
);
mounted = true;
}
},
p: noop,
d(detaching) {
if (detaching) {
detach(button);
}
mounted = false;
dispose();
}
};
}
function create_if_block_1(ctx) {
let button;
let textContent = "copy";
let mounted;
let dispose;
return {
c() {
button = element("button");
button.textContent = textContent;
this.h();
},
l(nodes) {
button = claim_element(nodes, "BUTTON", { class: true, ["data-svelte-h"]: true });
if (get_svelte_dataset(button) !== "svelte-172tjq5")
button.textContent = textContent;
this.h();
},
h() {
attr(button, "class", "log-copy-button svelte-ngcjq5");
},
m(target, anchor) {
insert_hydration(target, button, anchor);
if (!mounted) {
dispose = listen(
button,
"click",
/*handleCopyNodeToClipboard*/
ctx[8]
);
mounted = true;
}
},
p: noop,
d(detaching) {
if (detaching) {
detach(button);
}
mounted = false;
dispose();
}
};
}
function create_if_block(ctx) {
let li;
let ul;
let current;
let each_value = ensure_array_like(
/*node*/
ctx[0].children
);
let each_blocks = [];
for (let i = 0; i < each_value.length; i += 1) {
each_blocks[i] = create_each_block$1(get_each_context$1(ctx, each_value, i));
}
const out = (i) => transition_out(each_blocks[i], 1, 1, () => {
each_blocks[i] = null;
});
return {
c() {
li = element("li");
ul = element("ul");
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].c();
}
this.h();
},
l(nodes) {
li = claim_element(nodes, "LI", { class: true });
var li_nodes = children(li);
ul = claim_element(li_nodes, "UL", { class: true });
var ul_nodes = children(ul);
for (let i = 0; i < each_blocks.length; i += 1) {
each_blocks[i].l(ul_nodes);
}
ul_nodes.forEach(detach);
li_nodes.forEach(detach);
this.h();
},
h() {
attr(ul, "class", "svelte-ngcjq5");
attr(li, "class", "row svelte-ngcjq5");
},
m(target, anchor) {
insert_hydration(target, li, anchor);
append_hydration(li, ul);
for (let i = 0; i < each_blocks.length; i += 1) {
if (each_blocks[i]) {
each_blocks[i].m(ul, null);
}
}
current = true;
},
p(ctx2, dirty) {
if (dirty & /*node*/
1) {
each_value = ensure_array_like(
/*node*/
ctx2[0].children
);
let i;
for (i = 0; i < each_value.length; i += 1) {
const child_ctx = get_each_context$1(ctx2, each_value, i);
if (each_blocks[i]) {
each_blocks[i].p(child_ctx, dirty);
transition_in(each_blocks[i], 1);
} else {
each_blocks[i] = create_each_block$1(child_ctx);
each_blocks[i].c();
transition_in(each_blocks[i], 1);
each_blocks[i].m(ul, null);
}
}
group_outros();
for (i = each_value.length; i < each_blocks.length; i += 1) {
out(i);
}
check_outros();
}
},
i(local) {
if (current)
return;
for (let i = 0; i < each_value.length; i += 1) {
transition_in(each_blocks[i]);
}
current = true;
},
o(local) {
each_blocks = each_blocks.filter(Boolean);
for (let i = 0; i < each_blocks.length; i += 1) {
transition_out(each_blocks[i]);
}
current = false;
},
d(detaching) {
if (detaching) {
detach(li);
}
destroy_each(each_blocks, detaching);
}
};
}
function create_each_block$1(ctx) {
let treeviewnode;
let current;
treeviewnode = new TreeViewNode({ props: { id: (
/*child*/
ctx[14].id
) } });
return {
c() {
create_component(treeviewnode.$$.fragment);
},
l(nodes) {
claim_component(treeviewnode.$$.fragment, nodes);
},
m(target, anchor) {
mount_component(treeviewnode, target, anchor);
current = true;
},
p(ctx2, dirty) {
const treeviewnode_changes = {};
if (dirty & /*node*/
1)
treeviewnode_changes.id = /*child*/
ctx2[14].id;
treeviewnode.$set(treeviewnode_changes);
},
i(local) {
if (current)
return;
transition_in(treeviewnode.$$.fragment, local);
current = true;
},
o(local) {
transition_out(treeviewnode.$$.fragment, local);
current = false;
},
d(detaching) {
destroy_component(treeviewnode, detaching);
}
};
}
function create_fragment$1(ctx) {
let li;
let t0;
let div0;
let t1_value = (
/*node*/
ctx[0].key + ""
);
let t1;
let t2;
let t3;
let div1;
let current_block_type_index;
let if_block1;
let div1_data_type_value;
let t4;
let div2;
let t5;
let li_data_tree_id_value;
let t6;
let if_block4_anchor;
let current;
let mounted;
let dispose;
let if_block0 = (
/*hasChildren*/
ctx[2] && create_if_block_4(ctx)
);
const if_block_creators = [create_if_block_3, create_else_block];
const if_blocks = [];
function select_block_type(ctx2, dirty) {
if (
/*valueComponent*/
ctx2[3]
)
return 0;
return 1;
}
current_block_type_index = select_block_type(ctx);
if_block1 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx);
let if_block2 = (
/*$props*/
ctx[1].showLogButton && create_if_block_2(ctx)
);
let if_block3 = (
/*$props*/
ctx[1].showCopyButton && create_if_block_1(ctx)
);
let if_block4 = !/*node*/
ctx[0].collapsed && /*hasChildren*/
ctx[2] && create_if_block(ctx);
return {
c() {
li = element("li");
if (if_block0)
if_block0.c();
t0 = space();
div0 = element("div");
t1 = text(t1_value);
t2 = text(":");
t3 = space();
div1 = element("div");
if_block1.c();
t4 = space();
div2 = element("div");
if (if_block2)
if_block2.c();
t5 = space();
if (if_block3)
if_block3.c();
t6 = space();
if (if_block4)
if_block4.c();
if_block4_anchor = empty();
this.h();
},
l(nodes) {
li = claim_element(nodes, "LI", { class: true, "data-tree-id": true });
var li_nodes = children(li);
if (if_block0)
if_block0.l(li_nodes);
t0 = claim_space(li_nodes);
div0 = claim_element(li_nodes, "DIV", { class: true, role: true });
var div0_nodes = children(div0);
t1 = claim_text(div0_nodes, t1_value);
t2 = claim_text(div0_nodes, ":");
div0_nodes.forEach(detach);
t3 = claim_space(li_nodes);
div1 = claim_element(li_nodes, "DIV", {
class: true,
"data-type": true,
role: true
});
var div1_nodes = children(div1);
if_block1.l(div1_nodes);
div1_nodes.forEach(detach);
t4 = claim_space(li_nodes);
div2 = claim_element(li_nodes, "DIV", { class: true });
var div2_nodes = children(div2);
if (if_block2)
if_block2.l(div2_nodes);
t5 = claim_space(div2_nodes);
if (if_block3)
if_block3.l(div2_nodes);
div2_nodes.forEach(detach);
li_nodes.forEach(detach);
t6 = claim_space(nodes);
if (if_block4)
if_block4.l(nodes);
if_block4_anchor = empty();
this.h();
},
h() {
attr(div0, "class", "node-key svelte-ngcjq5");
attr(div0, "role", "presentation");
toggle_class(
div0,
"has-children",
/*hasChildren*/
ctx[2]
);
toggle_class(div0, "p-left", !/*hasChildren*/
ctx[2]);
attr(div1, "class", "node-value svelte-ngcjq5");
attr(div1, "data-type", div1_data_type_value = /*node*/
ctx[0].type);
attr(div1, "role", "presentation");
toggle_class(div1, "expanded", !/*node*/
ctx[0].collapsed && /*hasChildren*/
ctx[2]);
toggle_class(
div1,
"has-children",
/*hasChildren*/
ctx[2]
);
attr(div2, "class", "buttons svelte-ngcjq5");
attr(li, "class", "row svelte-ngcjq5");
attr(li, "data-tree-id", li_data_tree_id_value = /*node*/
ctx[0].id);
toggle_class(
li,
"collapsed",
/*node*/
ctx[0].collapsed && /*hasChildren*/
ctx[2]
);
},
m(target, anchor) {
insert_hydration(target, li, anchor);
if (if_block0)
if_block0.m(li, null);
append_hydration(li, t0);
append_hydration(li, div0);
append_hydration(div0, t1);
append_hydration(div0, t2);
append_hydration(li, t3);
append_hydration(li, div1);
if_blocks[current_block_type_index].m(div1, null);
append_hydration(li, t4);
append_hydration(li, div2);
if (if_block2)
if_block2.m(div2, null);
append_hydration(div2, t5);
if (if_block3)
if_block3.m(div2, null);
insert_hydration(target, t6, anchor);
if (if_block4)
if_block4.m(target, anchor);
insert_hydration(target, if_block4_anchor, anchor);
current = true;
if (!mounted) {
dispose = [
listen(
div0,
"click",
/*handleToggleCollapse*/
ctx[9]
),
listen(
div1,
"click",
/*handleToggleCollapse*/
ctx[9]
)
];
mounted = true;
}
},
p(ctx2, [dirty]) {
if (
/*hasChildren*/
ctx2[2]
) {
if (if_block0) {
if_block0.p(ctx2, dirty);
} else {
if_block0 = create_if_block_4(ctx2);
if_block0.c();
if_block0.m(li, t0);
}
} else if (if_block0) {
if_block0.d(1);
if_block0 = null;
}
if ((!current || dirty & /*node*/
1) && t1_value !== (t1_value = /*node*/
ctx2[0].key + ""))
set_data(t1, t1_value);
if (!current || dirty & /*hasChildren*/
4) {
toggle_class(
div0,
"has-children",
/*hasChildren*/
ctx2[2]
);
}
if (!current || dirty & /*hasChildren*/
4) {
toggle_class(div0, "p-left", !/*hasChildren*/
ctx2[2]);
}
let previous_block_index = current_block_type_index;
current_block_type_index = select_block_type(ctx2);
if (current_block_type_index === previous_block_index) {
if_blocks[current_block_type_index].p(ctx2, dirty);
} else {
group_outros();
transition_out(if_blocks[previous_block_index], 1, 1, () => {
if_blocks[previous_block_index] = null;
});
check_outros();
if_block1 = if_blocks[current_block_type_index];
if (!if_block1) {
if_block1 = if_blocks[current_block_type_index] = if_block_creators[current_block_type_index](ctx2);
if_block1.c();
} else {
if_block1.p(ctx2, dirty);
}
transition_in(if_block1, 1);
if_block1.m(div1, null);
}
if (!current || dirty & /*node*/
1 && div1_data_type_value !== (div1_data_type_value = /*node*/
ctx2[0].type)) {
attr(div1, "data-type", div1_data_type_value);
}
if (!current || dirty & /*node, hasChildren*/
5) {
toggle_class(div1, "expanded", !/*node*/
ctx2[0].collapsed && /*hasChildren*/
ctx2[2]);
}
if (!current || dirty & /*hasChildren*/
4) {
toggle_class(
div1,
"has-children",
/*hasChildren*/
ctx2[2]
);
}
if (
/*$props*/
ctx2[1].showLogButton
) {
if (if_block2) {
if_block2.p(ctx2, dirty);
} else {
if_block2 = create_if_block_2(ctx2);
if_block2.c();
if_block2.m(div2, t5);
}
} else if (if_block2) {
if_block2.d(1);
if_block2 = null;
}
if (
/*$props*/
ctx2[1].showCopyButton
) {
if (if_block3) {
if_block3.p(ctx2, dirty);
} else {
if_block3 = create_if_block_1(ctx2);
if_block3.c();
if_block3.m(div2, null);
}
} else if (if_block3) {
if_block3.d(1);
if_block3 = null;
}
if (!current || dirty & /*node*/
1 && li_data_tree_id_value !== (li_data_tree_id_value = /*node*/
ctx2[0].id)) {
attr(li, "data-tree-id", li_data_tree_id_value);
}
if (!current || dirty & /*node, hasChildren*/
5) {
toggle_class(
li,
"collapsed",
/*node*/
ctx2[0].collapsed && /*hasChildren*/
ctx2[2]
);
}
if (!/*node*/
ctx2[0].collapsed && /*hasChildren*/
ctx2[2]) {
if (if_block4) {
if_block4.p(ctx2, dirty);
if (dirty & /*node, hasChildren*/
5) {
transition_in(if_block4, 1);
}
} else {
if_block4 = create_if_block(ctx2);
if_block4.c();
transition_in(if_block4, 1);
if_block4.m(if_block4_anchor.parentNode, if_block4_anchor);
}
} else if (if_block4) {
group_outros();
transition_out(if_block4, 1, 1, () => {
if_block4 = null;
});
check_outros();
}
},
i(local) {
if (current)
return;
transition_in(if_block1);
transition_in(if_block4);
current = true;
},
o(local) {
transition_out(if_block1);
transition_out(if_block4);
current = false;
},
d(detaching) {
if (detaching) {
detach(li);
detach(t6);
detach(if_block4_anchor);
}
if (if_block0)
if_block0.d();
if_blocks[current_block_type_index].d();
if (if_block2)
if_block2.d();
if (if_block3)
if_block3.d();
if (if_block4)
if_block4.d(detaching);
mounted = false;
run_all(dispose);
}
};
}
function instance$1($$self, $$props, $$invalidate) {
let hasChildren;
let props;
let valueComponent;
let $rootElementStore;
let $props, $$unsubscribe_props = noop, $$subscribe_props = () => ($$unsubscribe_props(), $$unsubscribe_props = subscribe(props, ($$value) => $$invalidate(1, $props = $$value)), props);
$$self.$$.on_destroy.push(() => $$unsubscribe_props());
let { id } = $$props;
const { treeStore, propsStore, rootElementStore } = getContext("svelte-tree-view");
component_subscribe($$self, rootElementStore, (value) => $$invalidate(12, $rootElementStore = value));
let node;
treeStore.treeMap.subscribe((value) => {
const n = value.get(id);
if (n && node