@ark-ui/vue
Version:
A collection of unstyled, accessible UI components for Vue, utilizing state machines for seamless interaction.
84 lines (81 loc) • 2.89 kB
JavaScript
import { defineComponent, mergeDefaults, computed, createBlock, openBlock, unref, mergeProps, withCtx, renderSlot } from 'vue';
import { getRootNode, nodeToString, nodeToValue } from '@zag-js/json-tree-utils';
import { createSplitProps } from '../create-split-props.js';
import { createTreeCollection } from '../collection/tree-collection.js';
import * as treeView from '../tree-view/tree-view.js';
import { getBranchValues } from './get-branch-value.js';
import { JsonTreeViewPropsProvider } from './json-tree-view-props-context.js';
const _sfc_main = /* @__PURE__ */ defineComponent({
__name: "json-tree-view-root",
props: /* @__PURE__ */ mergeDefaults({
data: {},
defaultExpandedDepth: {},
quotesOnKeys: { type: Boolean },
maxPreviewItems: {},
collapseStringsAfterLength: {},
groupArraysAfterLength: {},
showNonenumerable: { type: Boolean },
defaultExpandedValue: {},
defaultSelectedValue: {},
defaultCheckedValue: {},
defaultFocusedValue: {},
checkedValue: {},
expandOnClick: { type: Boolean },
expandedValue: {},
focusedValue: {},
id: {},
ids: {},
selectedValue: {},
selectionMode: {},
typeahead: { type: Boolean },
loadChildren: { type: Function },
lazyMount: { type: Boolean },
unmountOnExit: { type: Boolean },
asChild: { type: Boolean }
}, {
expandOnClick: void 0,
typeahead: void 0,
lazyMount: void 0,
unmountOnExit: void 0,
asChild: void 0,
showNonenumerable: void 0,
quotesOnKeys: void 0
}),
setup(__props) {
const props = __props;
const splitJsonTreeViewProps = createSplitProps();
const [jsonTreeProps, localProps] = splitJsonTreeViewProps(props, [
"maxPreviewItems",
"collapseStringsAfterLength",
"quotesOnKeys",
"groupArraysAfterLength",
"showNonenumerable"
]);
const { data, defaultExpandedDepth, ...restProps } = localProps;
const collection = computed(() => {
return createTreeCollection({
nodeToValue,
nodeToString,
rootNode: getRootNode(data)
});
});
const defaultExpandedValue = computed(() => {
const expandedValue = defaultExpandedDepth != null ? getBranchValues(collection.value, defaultExpandedDepth) : void 0;
return props.defaultExpandedValue || expandedValue;
});
JsonTreeViewPropsProvider(computed(() => jsonTreeProps));
return (_ctx, _cache) => {
return openBlock(), createBlock(unref(treeView).Root, mergeProps({ "data-scope": "json-tree-view" }, restProps, {
collection: collection.value,
defaultExpandedValue: defaultExpandedValue.value,
typeahead: false
}), {
default: withCtx(() => [
renderSlot(_ctx.$slots, "default")
]),
_: 3
}, 16, ["collection", "defaultExpandedValue"]);
};
}
});
export { _sfc_main as default };