@difizen/mana-app
Version:
38 lines • 1.66 kB
JavaScript
import { notEmpty } from '@difizen/mana-common';
import { ViewInstance } from '@difizen/mana-core';
import { useInject } from '@difizen/mana-observable';
import * as React from 'react';
import { TREE_NODE_SEGMENT_CLASS, TREE_NODE_SEGMENT_GROW_CLASS } from "../tree-protocol";
import { TreeViewDecorationStyles } from "../tree-view-decoration";
import { TreeViewDecorator } from "../view/tree-view-decorator";
import { jsx as _jsx, Fragment as _Fragment } from "react/jsx-runtime";
export var TreeNodeCaptionAffixes = function TreeNodeCaptionAffixes(props) {
var treeViewDecorator = useInject(TreeViewDecorator);
var treeView = useInject(ViewInstance);
var affixKey = props.affixKey,
node = props.node;
var suffix = affixKey === 'captionSuffixes';
var affixClass = suffix ? TreeViewDecorationStyles.CAPTION_SUFFIX_CLASS : TreeViewDecorationStyles.CAPTION_PREFIX_CLASS;
var classes = [TREE_NODE_SEGMENT_CLASS, affixClass];
var affixes = treeViewDecorator.getDecorationData(node, affixKey).filter(notEmpty).reduce(function (acc, current) {
return acc.concat(current);
}, []);
var children = [];
for (var i = 0; i < affixes.length; i += 1) {
var affix = affixes[i];
if (suffix && i === affixes.length - 1) {
classes.push(TREE_NODE_SEGMENT_GROW_CLASS);
}
var style = treeView.applyFontStyles({}, affix.fontData);
var className = classes.join(' ');
var key = "".concat(node.id, "_").concat(i);
children.push( /*#__PURE__*/_jsx("div", {
className: className,
style: style,
children: affix.data
}, key));
}
return /*#__PURE__*/_jsx(_Fragment, {
children: children
});
};