@rainbow-oh/yee-c 0.8.16 → 0.8.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -61,6 +61,13 @@ export type TreeNode<T> = {
61
61
  * All descendant uids (collected bottom-up). Used for check/uncheck propagation.
62
62
  */
63
63
  childUids?: Array<string>;
64
+ /**
65
+ * Extra content rendered after the label (e.g. tags, badges, action buttons).
66
+ * Only takes effect when `labelRender` is NOT provided at the Tree level.
67
+ * When `labelRender` is present, access this value via `node.extra` in your
68
+ * custom render function.
69
+ */
70
+ extra?: React.ReactNode | ((node: T) => React.ReactNode);
64
71
  /**
65
72
  * Original data
66
73
  */
@@ -157,6 +164,14 @@ export interface TreeProps<T> extends DataAttributeProps {
157
164
  * @default false
158
165
  */
159
166
  multiple?: boolean;
167
+ /**
168
+ * Custom render function for node label.
169
+ * When provided, takes full control of the label area rendering.
170
+ * The node's `extra` will NOT be appended automatically in this case;
171
+ * access it via `node.extra` if you need it in your custom render.
172
+ * The original `label` string is still used for `title` attribute fallback.
173
+ */
174
+ labelRender?: (node: TreeNode<T>) => React.ReactNode;
160
175
  /**
161
176
  * Customize node key, title, children field names
162
177
  */
@@ -164,6 +179,7 @@ export interface TreeProps<T> extends DataAttributeProps {
164
179
  key?: keyof T;
165
180
  label?: keyof T;
166
181
  children?: keyof T;
182
+ extra?: keyof T;
167
183
  };
168
184
  /**
169
185
  * Asynchronous data loading
@@ -64,6 +64,7 @@ var Node = (props) => {
64
64
  disabled,
65
65
  depth,
66
66
  icon,
67
+ extra,
67
68
  original,
68
69
  lines
69
70
  } = node;
@@ -78,6 +79,7 @@ var Node = (props) => {
78
79
  indeterminateUids,
79
80
  expandedUids,
80
81
  switcherIcon,
82
+ labelRender,
81
83
  draggable,
82
84
  draggingUid,
83
85
  dropState,
@@ -132,6 +134,8 @@ var Node = (props) => {
132
134
  const _title = title || (typeof label === "string" ? label : void 0);
133
135
  const mergedIcon = icon || contextIcon;
134
136
  const _icon = typeof mergedIcon === "function" ? mergedIcon(original) : mergedIcon;
137
+ const content = labelRender ? labelRender(node) : label;
138
+ const _extra = !labelRender && extra ? typeof extra === "function" ? extra(original) : extra : null;
135
139
  return /* @__PURE__ */ import_react.default.createElement(
136
140
  import_Button.default,
137
141
  {
@@ -144,7 +148,8 @@ var Node = (props) => {
144
148
  icon: showIcon ? _icon : void 0,
145
149
  onClick: disabled ? void 0 : () => onSelect(uid)
146
150
  },
147
- label
151
+ content,
152
+ _extra && /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefixCls}-node-extra` }, _extra)
148
153
  );
149
154
  };
150
155
  const renderEmptyNodes = (depth2) => {
@@ -166,7 +171,7 @@ var Node = (props) => {
166
171
  {
167
172
  "aria-hidden": "true",
168
173
  className: `${prefixCls}-node-indent`,
169
- key: index
174
+ key: `node-empty-${index}`
170
175
  }
171
176
  ));
172
177
  };
@@ -1,5 +1,5 @@
1
1
  import React, { ChangeEvent } from 'react';
2
- import type { DragPosition, TreeProps } from './interface';
2
+ import type { DragPosition, TreeNode, TreeProps } from './interface';
3
3
  import './style/index.less';
4
4
  type DropState = {
5
5
  uid: string;
@@ -12,6 +12,7 @@ export declare const TreeContext: React.Context<{
12
12
  icon?: React.ReactNode | ((props: any) => React.ReactNode);
13
13
  showLine?: boolean | undefined;
14
14
  switcherIcon?: [React.ReactNode, React.ReactNode] | undefined;
15
+ labelRender?: ((node: TreeNode<any>) => React.ReactNode) | undefined;
15
16
  selectedUids: Set<string>;
16
17
  checkedUids: Set<string>;
17
18
  indeterminateUids: Set<string>;
@@ -184,6 +184,7 @@ var Tree = (baseprops) => {
184
184
  onSelect,
185
185
  onCheck,
186
186
  onExpand,
187
+ labelRender,
187
188
  virtual = false,
188
189
  height,
189
190
  itemHeight = 28
@@ -212,6 +213,7 @@ var Tree = (baseprops) => {
212
213
  "onSelect",
213
214
  "onCheck",
214
215
  "onExpand",
216
+ "labelRender",
215
217
  "virtual",
216
218
  "height",
217
219
  "itemHeight"
@@ -498,6 +500,7 @@ var Tree = (baseprops) => {
498
500
  icon,
499
501
  showLine,
500
502
  switcherIcon,
503
+ labelRender,
501
504
  selectedUids: selectedUidSet,
502
505
  checkedUids: checkedUidSet,
503
506
  indeterminateUids: indeterminateUidSet,
@@ -520,6 +523,7 @@ var Tree = (baseprops) => {
520
523
  icon,
521
524
  showLine,
522
525
  switcherIcon,
526
+ labelRender,
523
527
  selectedUidSet,
524
528
  checkedUidSet,
525
529
  indeterminateUidSet,
@@ -609,14 +613,14 @@ var Tree = (baseprops) => {
609
613
  role: "tree",
610
614
  onDragEnd: handleDragEnd
611
615
  }, dataAttrs),
612
- /* @__PURE__ */ import_react2.default.createElement(TreeContext.Provider, { value: contextValue }, /* @__PURE__ */ import_react2.default.createElement(import_react.AnimatePresence, { initial: false }, segments.map((segment) => {
616
+ /* @__PURE__ */ import_react2.default.createElement(TreeContext.Provider, { value: contextValue }, /* @__PURE__ */ import_react2.default.createElement(import_react.AnimatePresence, { initial: false }, segments.map((segment, index) => {
613
617
  if (segment.type === "node") {
614
618
  return /* @__PURE__ */ import_react2.default.createElement(import_tree_node.default, { node: segment.node, key: segment.node.uid });
615
619
  }
616
620
  return /* @__PURE__ */ import_react2.default.createElement(
617
621
  import_react.motion.div,
618
622
  {
619
- key: segment.pUid + "children",
623
+ key: segment.pUid + index + "children",
620
624
  initial: { height: 0, opacity: 0 },
621
625
  animate: { height: "auto", opacity: 1 },
622
626
  exit: { height: 0, opacity: 0 },
@@ -49,6 +49,7 @@ export declare function tree2array<T extends Record<string, unknown>>(tree: T |
49
49
  key: keyof T;
50
50
  label: keyof T;
51
51
  children: keyof T;
52
+ extra?: keyof T;
52
53
  }): [TreeNode<T>[], Map<string, TreeNode<T>>];
53
54
  /**
54
55
  * Check whether array `a` contains every element in `b`.
@@ -135,7 +135,7 @@ function tree2array(tree, fieldNames) {
135
135
  const data = Array.isArray(tree) ? tree : [tree];
136
136
  const res = [];
137
137
  const map = /* @__PURE__ */ new Map();
138
- const { key, label, children } = fieldNames;
138
+ const { key, label, children, extra } = fieldNames;
139
139
  function walk({
140
140
  data: node,
141
141
  pUid,
@@ -147,6 +147,7 @@ function tree2array(tree, fieldNames) {
147
147
  const rawKey = node[key];
148
148
  const _label = node[label];
149
149
  const _children = node[children];
150
+ const _extra = extra ? node[extra] : node.extra;
150
151
  const nextPath = [...path, rawKey];
151
152
  const uid = pUid ? `${pUid}\0${String(rawKey)}` : String(rawKey);
152
153
  const isParent = Array.isArray(_children) && _children.length > 0;
@@ -155,6 +156,7 @@ function tree2array(tree, fieldNames) {
155
156
  key: rawKey,
156
157
  label: _label,
157
158
  title: node.title,
159
+ extra: _extra,
158
160
  path,
159
161
  pUid,
160
162
  depth,
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-08-03T08:40:43.552Z
4
+ * Generated on 2026-08-05T09:43:58.935Z
5
5
  */
6
6
 
7
7
  /* ========== color.blue.css ========== */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-08-03T08:40:43.552Z
4
+ * Generated on 2026-08-05T09:43:58.935Z
5
5
  */
6
6
 
7
7
  /* ========== color.css ========== */
@@ -3,4 +3,4 @@ declare global {
3
3
  __yee_c_version__: string;
4
4
  }
5
5
  }
6
- export declare const version = "0.8.16";
6
+ export declare const version = "0.8.17";
@@ -22,7 +22,7 @@ __export(version_exports, {
22
22
  version: () => version
23
23
  });
24
24
  module.exports = __toCommonJS(version_exports);
25
- var version = "0.8.16";
25
+ var version = "0.8.17";
26
26
  if (typeof window !== "undefined") {
27
27
  window.__yee_c_version__ = version;
28
28
  }
@@ -61,6 +61,13 @@ export type TreeNode<T> = {
61
61
  * All descendant uids (collected bottom-up). Used for check/uncheck propagation.
62
62
  */
63
63
  childUids?: Array<string>;
64
+ /**
65
+ * Extra content rendered after the label (e.g. tags, badges, action buttons).
66
+ * Only takes effect when `labelRender` is NOT provided at the Tree level.
67
+ * When `labelRender` is present, access this value via `node.extra` in your
68
+ * custom render function.
69
+ */
70
+ extra?: React.ReactNode | ((node: T) => React.ReactNode);
64
71
  /**
65
72
  * Original data
66
73
  */
@@ -157,6 +164,14 @@ export interface TreeProps<T> extends DataAttributeProps {
157
164
  * @default false
158
165
  */
159
166
  multiple?: boolean;
167
+ /**
168
+ * Custom render function for node label.
169
+ * When provided, takes full control of the label area rendering.
170
+ * The node's `extra` will NOT be appended automatically in this case;
171
+ * access it via `node.extra` if you need it in your custom render.
172
+ * The original `label` string is still used for `title` attribute fallback.
173
+ */
174
+ labelRender?: (node: TreeNode<T>) => React.ReactNode;
160
175
  /**
161
176
  * Customize node key, title, children field names
162
177
  */
@@ -164,6 +179,7 @@ export interface TreeProps<T> extends DataAttributeProps {
164
179
  key?: keyof T;
165
180
  label?: keyof T;
166
181
  children?: keyof T;
182
+ extra?: keyof T;
167
183
  };
168
184
  /**
169
185
  * Asynchronous data loading
@@ -21,6 +21,7 @@ var Node = function Node(props) {
21
21
  disabled = node.disabled,
22
22
  depth = node.depth,
23
23
  icon = node.icon,
24
+ extra = node.extra,
24
25
  original = node.original,
25
26
  lines = node.lines;
26
27
  var _useContext = useContext(TreeContext),
@@ -34,6 +35,7 @@ var Node = function Node(props) {
34
35
  indeterminateUids = _useContext.indeterminateUids,
35
36
  expandedUids = _useContext.expandedUids,
36
37
  switcherIcon = _useContext.switcherIcon,
38
+ labelRender = _useContext.labelRender,
37
39
  draggable = _useContext.draggable,
38
40
  draggingUid = _useContext.draggingUid,
39
41
  dropState = _useContext.dropState,
@@ -86,6 +88,12 @@ var Node = function Node(props) {
86
88
  var _title = title || (typeof label === 'string' ? label : undefined);
87
89
  var mergedIcon = icon || contextIcon;
88
90
  var _icon = typeof mergedIcon === 'function' ? mergedIcon(original) : mergedIcon;
91
+
92
+ // labelRender takes full control of the label content when provided
93
+ var content = labelRender ? labelRender(node) : label;
94
+
95
+ // extra: appended after the label content (only when labelRender is NOT used)
96
+ var _extra = !labelRender && extra ? typeof extra === 'function' ? extra(original) : extra : null;
89
97
  return /*#__PURE__*/React.createElement(Button, {
90
98
  className: clsx("".concat(prefixCls, "-node-label"), _defineProperty({}, "".concat(prefixCls, "-node-label-selected"), selected)),
91
99
  size: "small",
@@ -95,7 +103,9 @@ var Node = function Node(props) {
95
103
  onClick: disabled ? undefined : function () {
96
104
  return onSelect(uid);
97
105
  }
98
- }, label);
106
+ }, content, _extra && /*#__PURE__*/React.createElement("span", {
107
+ className: "".concat(prefixCls, "-node-extra")
108
+ }, _extra));
99
109
  };
100
110
  var renderEmptyNodes = function renderEmptyNodes(depth) {
101
111
  var temp = new Array(depth).fill(0);
@@ -111,7 +121,7 @@ var Node = function Node(props) {
111
121
  return /*#__PURE__*/React.createElement("span", {
112
122
  "aria-hidden": "true",
113
123
  className: "".concat(prefixCls, "-node-indent"),
114
- key: index
124
+ key: "node-empty-".concat(index)
115
125
  });
116
126
  });
117
127
  };
@@ -1,5 +1,5 @@
1
1
  import React, { ChangeEvent } from 'react';
2
- import type { DragPosition, TreeProps } from './interface';
2
+ import type { DragPosition, TreeNode, TreeProps } from './interface';
3
3
  import './style/index.less';
4
4
  type DropState = {
5
5
  uid: string;
@@ -12,6 +12,7 @@ export declare const TreeContext: React.Context<{
12
12
  icon?: React.ReactNode | ((props: any) => React.ReactNode);
13
13
  showLine?: boolean | undefined;
14
14
  switcherIcon?: [React.ReactNode, React.ReactNode] | undefined;
15
+ labelRender?: ((node: TreeNode<any>) => React.ReactNode) | undefined;
15
16
  selectedUids: Set<string>;
16
17
  checkedUids: Set<string>;
17
18
  indeterminateUids: Set<string>;
@@ -1,5 +1,5 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- var _excluded = ["prefixCls", "className", "style", "dataSource", "fieldNames", "defaultExpandAll", "expandedKeys", "defaultExpandedKeys", "selectedKeys", "defaultSelectedKeys", "checkedKeys", "defaultCheckedKeys", "checkable", "multiple", "showIcon", "icon", "showLine", "switcherIcon", "draggable", "allowDrop", "onDrop", "onSelect", "onCheck", "onExpand", "virtual", "height", "itemHeight"];
2
+ var _excluded = ["prefixCls", "className", "style", "dataSource", "fieldNames", "defaultExpandAll", "expandedKeys", "defaultExpandedKeys", "selectedKeys", "defaultSelectedKeys", "checkedKeys", "defaultCheckedKeys", "checkable", "multiple", "showIcon", "icon", "showLine", "switcherIcon", "draggable", "allowDrop", "onDrop", "onSelect", "onCheck", "onExpand", "labelRender", "virtual", "height", "itemHeight"];
3
3
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
4
4
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
5
5
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
@@ -134,8 +134,8 @@ function uidsToKeys(uids, map) {
134
134
  try {
135
135
  for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
136
136
  var _uid = _step2.value;
137
- var node = map.get(_uid);
138
- if (node) keys.push(node.key);
137
+ var _node = map.get(_uid);
138
+ if (_node) keys.push(_node.key);
139
139
  }
140
140
  } catch (err) {
141
141
  _iterator2.e(err);
@@ -210,6 +210,7 @@ var Tree = function Tree(baseprops) {
210
210
  onSelect = props.onSelect,
211
211
  onCheck = props.onCheck,
212
212
  onExpand = props.onExpand,
213
+ labelRender = props.labelRender,
213
214
  _props$virtual = props.virtual,
214
215
  virtual = _props$virtual === void 0 ? false : _props$virtual,
215
216
  height = props.height,
@@ -570,6 +571,7 @@ var Tree = function Tree(baseprops) {
570
571
  icon: icon,
571
572
  showLine: showLine,
572
573
  switcherIcon: switcherIcon,
574
+ labelRender: labelRender,
573
575
  selectedUids: selectedUidSet,
574
576
  checkedUids: checkedUidSet,
575
577
  indeterminateUids: indeterminateUidSet,
@@ -585,7 +587,7 @@ var Tree = function Tree(baseprops) {
585
587
  onNodeDragLeave: handleDragLeave,
586
588
  onNodeDrop: handleDrop
587
589
  };
588
- }, [prefixCls, checkable, showIcon, icon, showLine, switcherIcon, selectedUidSet, checkedUidSet, indeterminateUidSet, expandedUidSet, draggable, draggingUid, dropState,
590
+ }, [prefixCls, checkable, showIcon, icon, showLine, switcherIcon, labelRender, selectedUidSet, checkedUidSet, indeterminateUidSet, expandedUidSet, draggable, draggingUid, dropState,
589
591
  // handlers are stable (useEvent), but listed for correctness
590
592
  handleCheck, handleSelect, handleExpand, handleDragStart, handleDragOver, handleDragLeave, handleDrop]);
591
593
 
@@ -652,8 +654,8 @@ var Tree = function Tree(baseprops) {
652
654
  _step9;
653
655
  try {
654
656
  for (_iterator9.s(); !(_step9 = _iterator9.n()).done;) {
655
- var node = _step9.value;
656
- if (node.depth === 0) {
657
+ var _node2 = _step9.value;
658
+ if (_node2.depth === 0) {
657
659
  // Root nodes are always visible, render directly without animation
658
660
  if (currentGroup) {
659
661
  segments.push(_objectSpread({
@@ -663,12 +665,12 @@ var Tree = function Tree(baseprops) {
663
665
  }
664
666
  segments.push({
665
667
  type: 'node',
666
- node: node
668
+ node: _node2
667
669
  });
668
670
  } else {
669
671
  // Non-root: group consecutive children under the same parent
670
- if (currentGroup && currentGroup.pUid === node.pUid) {
671
- currentGroup.nodes.push(node);
672
+ if (currentGroup && currentGroup.pUid === _node2.pUid) {
673
+ currentGroup.nodes.push(_node2);
672
674
  } else {
673
675
  if (currentGroup) {
674
676
  segments.push(_objectSpread({
@@ -676,8 +678,8 @@ var Tree = function Tree(baseprops) {
676
678
  }, currentGroup));
677
679
  }
678
680
  currentGroup = {
679
- pUid: node.pUid,
680
- nodes: [node]
681
+ pUid: _node2.pUid,
682
+ nodes: [_node2]
681
683
  };
682
684
  }
683
685
  }
@@ -701,7 +703,7 @@ var Tree = function Tree(baseprops) {
701
703
  value: contextValue
702
704
  }, /*#__PURE__*/React.createElement(AnimatePresence, {
703
705
  initial: false
704
- }, segments.map(function (segment) {
706
+ }, segments.map(function (segment, index) {
705
707
  if (segment.type === 'node') {
706
708
  return /*#__PURE__*/React.createElement(TreeNodeComp, {
707
709
  node: segment.node,
@@ -712,7 +714,7 @@ var Tree = function Tree(baseprops) {
712
714
  // Replacing this tree after dragStart removes the browser's drag
713
715
  // source and cancels the drag before dragOver/drop can fire.
714
716
  return /*#__PURE__*/React.createElement(motion.div, {
715
- key: segment.pUid + '\x01children',
717
+ key: segment.pUid + index + '\x01children',
716
718
  initial: {
717
719
  height: 0,
718
720
  opacity: 0
@@ -49,6 +49,7 @@ export declare function tree2array<T extends Record<string, unknown>>(tree: T |
49
49
  key: keyof T;
50
50
  label: keyof T;
51
51
  children: keyof T;
52
+ extra?: keyof T;
52
53
  }): [TreeNode<T>[], Map<string, TreeNode<T>>];
53
54
  /**
54
55
  * Check whether array `a` contains every element in `b`.
@@ -172,7 +172,8 @@ export function tree2array(tree, fieldNames) {
172
172
  var map = new Map();
173
173
  var key = fieldNames.key,
174
174
  label = fieldNames.label,
175
- children = fieldNames.children;
175
+ children = fieldNames.children,
176
+ extra = fieldNames.extra;
176
177
 
177
178
  /**
178
179
  * Walk returns the list of descendant uids so the parent can collect them
@@ -190,6 +191,7 @@ export function tree2array(tree, fieldNames) {
190
191
  var rawKey = node[key];
191
192
  var _label = node[label];
192
193
  var _children = node[children];
194
+ var _extra = extra ? node[extra] : node.extra;
193
195
  var nextPath = [].concat(_toConsumableArray(path), [rawKey]);
194
196
  var uid = pUid ? "".concat(pUid, "\0").concat(String(rawKey)) : String(rawKey);
195
197
  var isParent = Array.isArray(_children) && _children.length > 0;
@@ -200,6 +202,7 @@ export function tree2array(tree, fieldNames) {
200
202
  key: rawKey,
201
203
  label: _label,
202
204
  title: node.title,
205
+ extra: _extra,
203
206
  path: path,
204
207
  pUid: pUid,
205
208
  depth: depth,
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-08-03T08:40:43.552Z
4
+ * Generated on 2026-08-05T09:43:58.935Z
5
5
  */
6
6
 
7
7
  /* ========== color.blue.css ========== */
@@ -1,7 +1,7 @@
1
1
  /*!
2
2
  * @rainbow-oh/yee-c CSS Variables
3
3
  * Auto-generated, do not edit manually
4
- * Generated on 2026-08-03T08:40:43.552Z
4
+ * Generated on 2026-08-05T09:43:58.935Z
5
5
  */
6
6
 
7
7
  /* ========== color.css ========== */
@@ -3,4 +3,4 @@ declare global {
3
3
  __yee_c_version__: string;
4
4
  }
5
5
  }
6
- export declare const version = "0.8.16";
6
+ export declare const version = "0.8.17";
@@ -1,4 +1,4 @@
1
- export var version = "0.8.16";
1
+ export var version = "0.8.17";
2
2
  if (typeof window !== 'undefined') {
3
3
  window.__yee_c_version__ = version;
4
4
  }