@rainbow-oh/yee-c 0.4.2 → 0.4.4
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.
- package/dist/cjs/Cascader/cascader.js +53 -62
- package/dist/cjs/Cascader/interface.d.ts +19 -2
- package/dist/cjs/Cascader/node.js +11 -6
- package/dist/cjs/Cascader/search-list.js +2 -1
- package/dist/cjs/Cascader/utils/index.d.ts +58 -14
- package/dist/cjs/Cascader/utils/index.js +57 -73
- package/dist/cjs/Form/form-store.js +3 -0
- package/dist/cjs/Form/hooks/useWatch.js +4 -2
- package/dist/cjs/Input/style/index.less +19 -0
- package/dist/cjs/Popover/style/index.less +1 -0
- package/dist/cjs/Select/interface.d.ts +77 -0
- package/dist/cjs/Select/option.d.ts +2 -1
- package/dist/cjs/Select/option.js +6 -3
- package/dist/cjs/Select/options.d.ts +3 -2
- package/dist/cjs/Select/options.js +53 -47
- package/dist/cjs/Select/select.js +1 -1
- package/dist/cjs/Select/style/index.less +8 -0
- package/dist/cjs/Selector/interface.d.ts +4 -0
- package/dist/cjs/Selector/selector.js +3 -0
- package/dist/cjs/Selector/style/index.less +135 -116
- package/dist/cjs/Table/hooks/useFilter.js +1 -1
- package/dist/cjs/Table/interface.d.ts +4 -0
- package/dist/cjs/Table/style/index.less +2 -0
- package/dist/cjs/Table/theader/filter.js +2 -1
- package/dist/cjs/Tabs/demo/basic.js +8 -1
- package/dist/cjs/Tabs/tabs.js +3 -1
- package/dist/cjs/Tag/demo/checkable.js +1 -0
- package/dist/cjs/Tag/tag.js +1 -1
- package/dist/cjs/TextArea/textarea.js +0 -1
- package/dist/cjs/Trigger/trigger.js +1 -1
- package/dist/cjs/style/color.css +1 -1
- package/dist/cjs/style/size.css +10 -2
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +12 -4
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Cascader/cascader.js +49 -56
- package/dist/esm/Cascader/interface.d.ts +19 -2
- package/dist/esm/Cascader/node.js +8 -11
- package/dist/esm/Cascader/search-list.js +2 -1
- package/dist/esm/Cascader/utils/index.d.ts +58 -14
- package/dist/esm/Cascader/utils/index.js +124 -75
- package/dist/esm/Form/form-store.js +4 -0
- package/dist/esm/Form/hooks/useWatch.js +7 -2
- package/dist/esm/Input/style/index.less +19 -0
- package/dist/esm/Popover/style/index.less +1 -0
- package/dist/esm/Select/interface.d.ts +77 -0
- package/dist/esm/Select/option.d.ts +2 -1
- package/dist/esm/Select/option.js +11 -2
- package/dist/esm/Select/options.d.ts +3 -2
- package/dist/esm/Select/options.js +3 -1
- package/dist/esm/Select/select.js +1 -3
- package/dist/esm/Select/style/index.less +8 -0
- package/dist/esm/Selector/interface.d.ts +4 -0
- package/dist/esm/Selector/selector.js +4 -2
- package/dist/esm/Selector/style/index.less +135 -116
- package/dist/esm/Table/hooks/useFilter.js +1 -1
- package/dist/esm/Table/interface.d.ts +4 -0
- package/dist/esm/Table/style/index.less +2 -0
- package/dist/esm/Table/theader/filter.js +3 -4
- package/dist/esm/Tabs/demo/basic.js +4 -1
- package/dist/esm/Tabs/tabs.js +3 -1
- package/dist/esm/Tag/demo/checkable.js +1 -0
- package/dist/esm/Tag/tag.js +1 -1
- package/dist/esm/TextArea/textarea.js +0 -1
- package/dist/esm/Trigger/trigger.js +1 -1
- package/dist/esm/style/color.css +1 -1
- package/dist/esm/style/size.css +10 -2
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +12 -4
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +2 -2
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Cascader/cascader.tsx +65 -62
- package/src/Cascader/interface.ts +19 -2
- package/src/Cascader/node.tsx +12 -7
- package/src/Cascader/search-list.tsx +1 -1
- package/src/Cascader/utils/index.ts +130 -68
- package/src/Form/form-store.ts +4 -0
- package/src/Form/hooks/useWatch.ts +9 -2
- package/src/Input/style/index.less +19 -0
- package/src/Popover/style/index.less +1 -0
- package/src/Select/interface.ts +87 -0
- package/src/Select/option.tsx +13 -4
- package/src/Select/options.tsx +49 -43
- package/src/Select/select.tsx +5 -2
- package/src/Select/style/index.less +8 -0
- package/src/Selector/interface.ts +4 -0
- package/src/Selector/selector.tsx +2 -0
- package/src/Selector/style/index.less +135 -116
- package/src/Table/hooks/useFilter.ts +1 -1
- package/src/Table/interface.ts +4 -0
- package/src/Table/style/index.less +2 -0
- package/src/Table/theader/filter.tsx +2 -2
- package/src/Tabs/demo/basic.tsx +7 -1
- package/src/Tabs/tabs.tsx +3 -2
- package/src/Tag/demo/checkable.tsx +1 -0
- package/src/Tag/tag.tsx +1 -1
- package/src/TextArea/textarea.tsx +0 -2
- package/src/Trigger/trigger.tsx +1 -1
- package/src/style/color.css +1 -1
- package/src/style/size.css +10 -2
- package/src/version.ts +1 -1
|
@@ -1,19 +1,9 @@
|
|
|
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
|
-
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; }
|
|
3
|
-
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; }
|
|
4
|
-
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; }
|
|
5
|
-
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
-
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
1
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
2
|
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
|
+
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
9
4
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
10
5
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
11
|
-
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
12
|
-
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
13
|
-
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
14
6
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
|
-
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
|
-
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
7
|
/**
|
|
18
8
|
* Check if a data object has children
|
|
19
9
|
* @param data - The data object to check
|
|
@@ -26,64 +16,99 @@ export function hasChild(data) {
|
|
|
26
16
|
}
|
|
27
17
|
|
|
28
18
|
/**
|
|
29
|
-
*
|
|
19
|
+
* Separator used to build a node's `uid` from its value path. A control
|
|
20
|
+
* character is used on purpose so it can never appear inside a user value —
|
|
21
|
+
* this prevents collisions like value `"a-1"` vs path `["a", "1"]` that a plain
|
|
22
|
+
* `'-'` separator would produce.
|
|
23
|
+
*/
|
|
24
|
+
export var UID_SEP = '';
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Build the canonical uid for a value path. Use this everywhere a path needs
|
|
28
|
+
* to be turned into a key (nodeMap lookups, selected keys, comparisons) so the
|
|
29
|
+
* format stays consistent with the `uid`/`pid` produced by `flattenOptions`.
|
|
30
|
+
* @param path - The value path
|
|
31
|
+
*/
|
|
32
|
+
export var pathToUid = function pathToUid(path) {
|
|
33
|
+
return path.map(String).join(UID_SEP);
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Get the direct flattened children of the node identified by `uid`.
|
|
38
|
+
*
|
|
39
|
+
* Flattened nodes intentionally do not carry a `children` reference (it used to
|
|
40
|
+
* point at the raw, un-flattened subtree and caused type lies). Derive children
|
|
41
|
+
* from the flat list via `pid` instead — single source of truth.
|
|
42
|
+
* @param data - The flattened options data
|
|
43
|
+
* @param uid - The parent node's uid
|
|
44
|
+
*/
|
|
45
|
+
export var getChildren = function getChildren(data, uid) {
|
|
46
|
+
return data.filter(function (item) {
|
|
47
|
+
return item.pid === uid;
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* Find the node in `data` whose parent is `pid` and whose value is `value`.
|
|
30
53
|
* @internal
|
|
31
54
|
*/
|
|
32
|
-
var
|
|
33
|
-
|
|
34
|
-
return
|
|
35
|
-
}
|
|
36
|
-
for (var i = 0; i < data.length; i++) {
|
|
37
|
-
var item = data[i];
|
|
38
|
-
if (item.uid === value) {
|
|
39
|
-
var nexts = hasChild(item) ? item.children.filter(function (c) {
|
|
40
|
-
return c.pid === value;
|
|
41
|
-
}) : [];
|
|
42
|
-
return [nexts, {
|
|
43
|
-
id: item.value,
|
|
44
|
-
text: item.label
|
|
45
|
-
}];
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return [];
|
|
55
|
+
var findInColumn = function findInColumn(data, pid, value) {
|
|
56
|
+
return data.find(function (item) {
|
|
57
|
+
return item.pid === pid && item.value === value;
|
|
58
|
+
});
|
|
49
59
|
};
|
|
50
60
|
|
|
51
61
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
62
|
+
* Reconstruct cascade columns and the highlight path from a value path.
|
|
63
|
+
*
|
|
64
|
+
* Walks the flattened options level by level, matching each value segment
|
|
65
|
+
* against the correct parent column via `pid` + `value`. Returns:
|
|
66
|
+
* - `queue`: the columns to render (column 0 = root, then each matched
|
|
67
|
+
* node's children column).
|
|
68
|
+
* - `path`: the highlight breadcrumb shaped as `{ key: uid, label }`, so it
|
|
69
|
+
* aligns with `expandedPath[level].key === uid` in the node view.
|
|
70
|
+
*
|
|
71
|
+
* Stops safely at the last valid segment if the value path does not exist in
|
|
72
|
+
* the data source.
|
|
73
|
+
*
|
|
74
|
+
* @param arr - The selected path. In `multiple` mode the value is an array of
|
|
75
|
+
* paths; the first path is used to drive which columns get expanded.
|
|
54
76
|
* @param data - The flattened options data
|
|
55
77
|
* @param options - Optional configuration
|
|
56
|
-
* @returns A tuple of [queue, path]
|
|
78
|
+
* @returns A tuple of `[queue, path]`
|
|
57
79
|
*/
|
|
58
80
|
export var changeToView = function changeToView(arr, data, options) {
|
|
59
81
|
var _ref = options || {},
|
|
60
|
-
needNext = _ref.needNext,
|
|
61
82
|
multiple = _ref.multiple;
|
|
62
|
-
var
|
|
63
|
-
var
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
83
|
+
var queue = [];
|
|
84
|
+
var path = [];
|
|
85
|
+
|
|
86
|
+
// Column 0 (root level) is always present so the popup can open even with
|
|
87
|
+
// no selection.
|
|
88
|
+
queue.push(data.filter(function (item) {
|
|
89
|
+
return item.level === 0;
|
|
90
|
+
}));
|
|
91
|
+
if (!Array.isArray(arr) || arr.length === 0) {
|
|
92
|
+
return [queue, path];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// In multiple mode the value is an array of paths; use the first one to
|
|
96
|
+
// drive column expansion.
|
|
97
|
+
var segments = multiple && Array.isArray(arr[0]) ? arr[0] : arr;
|
|
98
|
+
var currentPid = '';
|
|
99
|
+
for (var i = 0; i < segments.length; i++) {
|
|
100
|
+
var matched = findInColumn(data, currentPid, segments[i]);
|
|
101
|
+
if (!matched) break; // value path doesn't exist in the data source
|
|
102
|
+
path.push({
|
|
103
|
+
key: matched.uid,
|
|
104
|
+
label: matched.label
|
|
72
105
|
});
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
var _result = _slicedToArray(result, 2),
|
|
78
|
-
_dataNext = _result[0],
|
|
79
|
-
_pathItem = _result[1];
|
|
80
|
-
_data = _dataNext;
|
|
81
|
-
_path.push(_pathItem);
|
|
82
|
-
}
|
|
83
|
-
i++;
|
|
84
|
-
} while (needNext ? i <= _arr.length : i < _arr.length);
|
|
106
|
+
if (!matched.isLeaf) {
|
|
107
|
+
queue.push(getChildren(data, matched.uid));
|
|
108
|
+
}
|
|
109
|
+
currentPid = matched.uid;
|
|
85
110
|
}
|
|
86
|
-
return [
|
|
111
|
+
return [queue, path];
|
|
87
112
|
};
|
|
88
113
|
|
|
89
114
|
// Assemble Tags Options
|
|
@@ -306,12 +331,12 @@ export var changeToView = function changeToView(arr, data, options) {
|
|
|
306
331
|
// }
|
|
307
332
|
|
|
308
333
|
/**
|
|
309
|
-
* Format a path
|
|
334
|
+
* Format a value path into a key string. Alias of `pathToUid` so all path→key
|
|
335
|
+
* conversions share one collision-safe format.
|
|
310
336
|
* @param val - The path array
|
|
311
|
-
* @returns A string key joined by '-'
|
|
312
337
|
*/
|
|
313
338
|
export var formatKey = function formatKey(val) {
|
|
314
|
-
return val
|
|
339
|
+
return pathToUid(val);
|
|
315
340
|
};
|
|
316
341
|
|
|
317
342
|
/**
|
|
@@ -333,11 +358,12 @@ export var isSamePrefixPath = function isSamePrefixPath(prefix, target) {
|
|
|
333
358
|
* Determine if a node is fully selected or half selected (indeterminate)
|
|
334
359
|
* @param value - The selected value paths
|
|
335
360
|
* @param item - The flatten option node to check
|
|
361
|
+
* @param children - The node's direct flattened children (derive via `getChildren`)
|
|
336
362
|
* @returns A tuple [checkedAll, indeterminate]
|
|
337
363
|
*/
|
|
338
|
-
export function isHalfChecked(value, item) {
|
|
339
|
-
if (!
|
|
340
|
-
var total =
|
|
364
|
+
export function isHalfChecked(value, item, children) {
|
|
365
|
+
if (!children.length) return [false, false];
|
|
366
|
+
var total = children.length;
|
|
341
367
|
var prefixPath = item.path;
|
|
342
368
|
var filtered = value.filter(function (path) {
|
|
343
369
|
return isSamePrefixPath(prefixPath, path);
|
|
@@ -349,12 +375,27 @@ export function isHalfChecked(value, item) {
|
|
|
349
375
|
}
|
|
350
376
|
|
|
351
377
|
/**
|
|
352
|
-
*
|
|
378
|
+
* Default maximum tree depth accepted by `flattenOptions`. Guards against
|
|
379
|
+
* stack overflow on pathological/deeply-nested input.
|
|
380
|
+
*/
|
|
381
|
+
var DEFAULT_MAX_DEPTH = 100;
|
|
382
|
+
|
|
383
|
+
/**
|
|
384
|
+
* Flatten a tree structure into an array for easier searching and traversal.
|
|
385
|
+
*
|
|
386
|
+
* The flattened nodes intentionally do NOT carry a `children` field — use
|
|
387
|
+
* `getChildren(data, uid)` to read a node's children. `uid`/`pid` are built
|
|
388
|
+
* via `pathToUid` (collision-safe). Includes a depth cap and a cycle guard so
|
|
389
|
+
* malformed input (very deep or self-referencing trees) cannot overflow the
|
|
390
|
+
* stack.
|
|
391
|
+
*
|
|
353
392
|
* @param tree - The tree data to flatten
|
|
354
393
|
* @param fieldNames - Custom field names for label, value, and children
|
|
394
|
+
* @param maxDepth - Maximum nesting depth (default 100)
|
|
355
395
|
* @returns An array of flattened options with additional metadata
|
|
356
396
|
*/
|
|
357
397
|
export var flattenOptions = function flattenOptions(tree, fieldNames) {
|
|
398
|
+
var maxDepth = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEFAULT_MAX_DEPTH;
|
|
358
399
|
var res = [];
|
|
359
400
|
var _ref2 = fieldNames || {},
|
|
360
401
|
_ref2$label = _ref2.label,
|
|
@@ -363,26 +404,34 @@ export var flattenOptions = function flattenOptions(tree, fieldNames) {
|
|
|
363
404
|
value = _ref2$value === void 0 ? 'value' : _ref2$value,
|
|
364
405
|
_ref2$children = _ref2.children,
|
|
365
406
|
children = _ref2$children === void 0 ? 'children' : _ref2$children;
|
|
407
|
+
// Object-identity set of nodes on the current DFS path, for cycle detection.
|
|
408
|
+
var seen = new Set();
|
|
366
409
|
var dfs = function dfs(nodes) {
|
|
367
410
|
var parents = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : [];
|
|
411
|
+
var labelParents = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
368
412
|
nodes.forEach(function (node) {
|
|
369
|
-
|
|
413
|
+
if (parents.length >= maxDepth) return; // depth guard
|
|
414
|
+
if (seen.has(node)) return; // cycle guard (back-edge to an ancestor)
|
|
415
|
+
var nodeLabel = node[label];
|
|
416
|
+
var path = [].concat(_toConsumableArray(parents), [node[value]]);
|
|
417
|
+
var labelPath = [].concat(_toConsumableArray(labelParents), [nodeLabel]);
|
|
418
|
+
var uid = pathToUid(path);
|
|
419
|
+
res.push({
|
|
370
420
|
$source: node,
|
|
371
|
-
label:
|
|
421
|
+
label: nodeLabel,
|
|
372
422
|
value: node[value],
|
|
373
|
-
|
|
374
|
-
};
|
|
375
|
-
var path = [].concat(_toConsumableArray(parents), [wrappered['value']]);
|
|
376
|
-
var uid = path.join('-');
|
|
377
|
-
var pid = parents.join('-');
|
|
378
|
-
res.push(_objectSpread(_objectSpread({}, wrappered), {}, {
|
|
379
|
-
pid: pid,
|
|
423
|
+
pid: pathToUid(parents),
|
|
380
424
|
uid: uid,
|
|
381
425
|
path: path,
|
|
426
|
+
labelPath: labelPath,
|
|
382
427
|
level: parents.length,
|
|
383
|
-
isLeaf: !hasChild(
|
|
384
|
-
})
|
|
385
|
-
if (
|
|
428
|
+
isLeaf: !hasChild(node, children)
|
|
429
|
+
});
|
|
430
|
+
if (hasChild(node, children)) {
|
|
431
|
+
seen.add(node);
|
|
432
|
+
dfs(node[children], path, labelPath);
|
|
433
|
+
seen.delete(node);
|
|
434
|
+
}
|
|
386
435
|
});
|
|
387
436
|
};
|
|
388
437
|
dfs(tree);
|
|
@@ -445,6 +445,10 @@ export var FormStore = /*#__PURE__*/function () {
|
|
|
445
445
|
} else {
|
|
446
446
|
_this.store = _objectSpread(_objectSpread({}, _this.store), {}, _defineProperty({}, normalizedName, value));
|
|
447
447
|
}
|
|
448
|
+
// When value is not undefined, notify watchers to trigger re-rendering of useWatch
|
|
449
|
+
if (value !== undefined) {
|
|
450
|
+
_this.notifyWatchers(normalizedName);
|
|
451
|
+
}
|
|
448
452
|
}
|
|
449
453
|
}
|
|
450
454
|
(_entity$onStoreChange = entity.onStoreChange) === null || _entity$onStoreChange === void 0 || _entity$onStoreChange.call(entity);
|
|
@@ -20,12 +20,17 @@ function useWatch(namePath, form) {
|
|
|
20
20
|
var getWatchedValue = function getWatchedValue() {
|
|
21
21
|
return isWatchAll ? formInstance.getFieldsValue() : formInstance.getFieldValue(Array.isArray(namePath) ? namePath.join('.') : namePath);
|
|
22
22
|
};
|
|
23
|
-
var
|
|
23
|
+
var update = function update() {
|
|
24
24
|
var newValue = getWatchedValue();
|
|
25
25
|
setValue(function (prev) {
|
|
26
26
|
return prev === newValue ? prev : newValue;
|
|
27
27
|
});
|
|
28
|
-
}
|
|
28
|
+
};
|
|
29
|
+
var unsubscribe = formInstance.subscribe(namePath, update);
|
|
30
|
+
// Re-read immediately after subscribing: the parent's useWatch captured its
|
|
31
|
+
// initial snapshot before child Form.Field wrote its initialValue, and the
|
|
32
|
+
// subscription may not yet exist when that write happens. This covers the gap.
|
|
33
|
+
update();
|
|
29
34
|
return unsubscribe;
|
|
30
35
|
}, [formInstance, namePath]);
|
|
31
36
|
return value;
|
|
@@ -69,6 +69,25 @@
|
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
// size
|
|
73
|
+
&-small {
|
|
74
|
+
height: var(--yee-input-small-height, 24px);
|
|
75
|
+
padding: var(--yee-input-small-padding, 0 6px);
|
|
76
|
+
font-size: var(--yee-input-small-font-size);
|
|
77
|
+
line-height: var(--yee-input-small-line-height);
|
|
78
|
+
|
|
79
|
+
&::placeholder {
|
|
80
|
+
font-size: var(--yee-input-small-font-size);
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
&-large {
|
|
85
|
+
height: var(--yee-input-large-height, 40px);
|
|
86
|
+
padding: var(--yee-input-large-padding, 4px 12px);
|
|
87
|
+
font-size: var(--yee-input-large-font-size);
|
|
88
|
+
line-height: var(--yee-input-large-line-height);
|
|
89
|
+
}
|
|
90
|
+
|
|
72
91
|
&-password {
|
|
73
92
|
flex: 1;
|
|
74
93
|
outline: none;
|
|
@@ -95,3 +95,80 @@ export interface SelectProps extends DataAttributeProps {
|
|
|
95
95
|
*/
|
|
96
96
|
onFilter?: (value: string, options: Array<Option>) => Array<Option>;
|
|
97
97
|
}
|
|
98
|
+
/**
|
|
99
|
+
* Props for the internal Option component (renders a single dropdown option).
|
|
100
|
+
*/
|
|
101
|
+
export interface OptionProps {
|
|
102
|
+
/**
|
|
103
|
+
* Display label
|
|
104
|
+
*/
|
|
105
|
+
label: string;
|
|
106
|
+
/**
|
|
107
|
+
* Value
|
|
108
|
+
*/
|
|
109
|
+
value: string | number;
|
|
110
|
+
/**
|
|
111
|
+
* Whether disabled
|
|
112
|
+
*/
|
|
113
|
+
disabled?: boolean;
|
|
114
|
+
/**
|
|
115
|
+
* Native title attribute
|
|
116
|
+
*/
|
|
117
|
+
title?: string;
|
|
118
|
+
/**
|
|
119
|
+
* Test id forwarded to the option element
|
|
120
|
+
*/
|
|
121
|
+
dataTestId?: string;
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* Context value shared between Options and each Option.
|
|
125
|
+
*/
|
|
126
|
+
export interface OptionsContextValue {
|
|
127
|
+
prefixCls: string;
|
|
128
|
+
selectedKeys: Array<string | number>;
|
|
129
|
+
focusedKey: string | number;
|
|
130
|
+
multiple: boolean;
|
|
131
|
+
onSelect: (key: string | number, e?: React.MouseEvent | React.KeyboardEvent) => void;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Props for the internal Options (popup list) component.
|
|
135
|
+
*/
|
|
136
|
+
export interface OptionsProps extends Omit<React.HTMLAttributes<HTMLDivElement>, 'onSelect'> {
|
|
137
|
+
/**
|
|
138
|
+
* Custom class name prefix
|
|
139
|
+
*/
|
|
140
|
+
prefixCls: string;
|
|
141
|
+
/**
|
|
142
|
+
* Dropdown options
|
|
143
|
+
*/
|
|
144
|
+
options: Array<Option>;
|
|
145
|
+
/**
|
|
146
|
+
* Popup container class name
|
|
147
|
+
*/
|
|
148
|
+
popupClassName?: string;
|
|
149
|
+
/**
|
|
150
|
+
* Popup container inline style
|
|
151
|
+
*/
|
|
152
|
+
popupStyle?: React.CSSProperties;
|
|
153
|
+
/**
|
|
154
|
+
* Selected option values
|
|
155
|
+
*/
|
|
156
|
+
selectedKeys: Array<string | number>;
|
|
157
|
+
/**
|
|
158
|
+
* Currently focused option value
|
|
159
|
+
*/
|
|
160
|
+
focusedKey: string | number;
|
|
161
|
+
/**
|
|
162
|
+
* Test id prefix used to generate each option's test id.
|
|
163
|
+
* Accepts any `data-*` attribute value (see DataAttributeProps).
|
|
164
|
+
*/
|
|
165
|
+
dataTestId?: string | number | boolean;
|
|
166
|
+
/**
|
|
167
|
+
* Whether multiple selection mode is active
|
|
168
|
+
*/
|
|
169
|
+
multiple: boolean;
|
|
170
|
+
/**
|
|
171
|
+
* Callback when an option is selected
|
|
172
|
+
*/
|
|
173
|
+
onSelect: (key: string | number, e?: React.MouseEvent | React.KeyboardEvent) => void;
|
|
174
|
+
}
|
|
@@ -3,6 +3,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
|
|
|
3
3
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
4
4
|
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
5
5
|
import clsx from 'clsx';
|
|
6
|
+
import { Check } from 'lucide-react';
|
|
6
7
|
import React, { useContext } from 'react';
|
|
7
8
|
import { OptionsCtx } from "./options";
|
|
8
9
|
var Option = function Option(props) {
|
|
@@ -15,6 +16,7 @@ var Option = function Option(props) {
|
|
|
15
16
|
prefixCls = _useContext.prefixCls,
|
|
16
17
|
selectedKeys = _useContext.selectedKeys,
|
|
17
18
|
focusedKey = _useContext.focusedKey,
|
|
19
|
+
multiple = _useContext.multiple,
|
|
18
20
|
onSelect = _useContext.onSelect;
|
|
19
21
|
var handleClick = function handleClick(e) {
|
|
20
22
|
if (!disabled) {
|
|
@@ -22,8 +24,9 @@ var Option = function Option(props) {
|
|
|
22
24
|
}
|
|
23
25
|
};
|
|
24
26
|
var htmlTitle = title ? title : typeof label === 'string' ? label : undefined;
|
|
27
|
+
var selected = selectedKeys.includes(value);
|
|
25
28
|
return /*#__PURE__*/React.createElement("div", {
|
|
26
|
-
className: clsx("".concat(prefixCls, "-option"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-option-selected"),
|
|
29
|
+
className: clsx("".concat(prefixCls, "-option"), _defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-option-selected"), selected), "".concat(prefixCls, "-option-focused"), focusedKey === value), "".concat(prefixCls, "-option-disabled"), disabled)),
|
|
27
30
|
"aria-label": "option",
|
|
28
31
|
onClick: handleClick,
|
|
29
32
|
onKeyDown: function onKeyDown(e) {
|
|
@@ -35,6 +38,12 @@ var Option = function Option(props) {
|
|
|
35
38
|
tabIndex: disabled ? undefined : 0,
|
|
36
39
|
title: htmlTitle,
|
|
37
40
|
"data-testid": dataTestId
|
|
38
|
-
},
|
|
41
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
42
|
+
className: "".concat(prefixCls, "-option-content")
|
|
43
|
+
}, label), multiple && selected && /*#__PURE__*/React.createElement("span", {
|
|
44
|
+
className: "".concat(prefixCls, "-option-state")
|
|
45
|
+
}, /*#__PURE__*/React.createElement(Check, {
|
|
46
|
+
size: 16
|
|
47
|
+
})));
|
|
39
48
|
};
|
|
40
49
|
export default Option;
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
|
|
3
|
-
declare const
|
|
2
|
+
import type { OptionsContextValue, OptionsProps } from './interface';
|
|
3
|
+
export declare const OptionsCtx: React.Context<OptionsContextValue>;
|
|
4
|
+
declare const Options: React.ForwardRefExoticComponent<OptionsProps & React.RefAttributes<HTMLDivElement>>;
|
|
4
5
|
export default Options;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var _excluded = ["prefixCls", "options", "popupClassName", "popupStyle", "selectedKeys", "focusedKey", "dataTestId", "onSelect"];
|
|
1
|
+
var _excluded = ["prefixCls", "options", "popupClassName", "popupStyle", "selectedKeys", "focusedKey", "dataTestId", "multiple", "onSelect"];
|
|
2
2
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
3
3
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
4
4
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
@@ -18,6 +18,7 @@ var Options = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
18
18
|
selectedKeys = props.selectedKeys,
|
|
19
19
|
focusedKey = props.focusedKey,
|
|
20
20
|
dataTestId = props.dataTestId,
|
|
21
|
+
multiple = props.multiple,
|
|
21
22
|
onSelect = props.onSelect,
|
|
22
23
|
rest = _objectWithoutProperties(props, _excluded);
|
|
23
24
|
|
|
@@ -35,6 +36,7 @@ var Options = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
|
35
36
|
prefixCls: prefixCls,
|
|
36
37
|
selectedKeys: selectedKeys,
|
|
37
38
|
focusedKey: focusedKey,
|
|
39
|
+
multiple: multiple,
|
|
38
40
|
onSelect: onSelect
|
|
39
41
|
}
|
|
40
42
|
}, options.map(function (option, index) {
|
|
@@ -156,14 +156,12 @@ var Select = function Select(baseprops) {
|
|
|
156
156
|
onKeyDown = _useSelectKeyboard.onKeyDown;
|
|
157
157
|
var popup = /*#__PURE__*/React.createElement(Options, {
|
|
158
158
|
prefixCls: prefixCls,
|
|
159
|
+
multiple: mode === 'multiple' || mode === 'tags',
|
|
159
160
|
options: filteredOpts,
|
|
160
161
|
focusedKey: focusedKey,
|
|
161
162
|
selectedKeys: mergedValue,
|
|
162
163
|
dataTestId: rest['data-testid'],
|
|
163
164
|
onSelect: handleSelect,
|
|
164
|
-
onClose: function onClose() {
|
|
165
|
-
return setOpen(false);
|
|
166
|
-
},
|
|
167
165
|
ref: popupRef
|
|
168
166
|
});
|
|
169
167
|
return /*#__PURE__*/React.createElement(Trigger, _extends({}, rest, {
|
|
@@ -9,12 +9,20 @@
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
&-option {
|
|
12
|
+
display: flex;
|
|
12
13
|
padding: var(--yee-select-option-padding);
|
|
13
14
|
overflow: hidden;
|
|
14
15
|
white-space: nowrap;
|
|
15
16
|
text-overflow: ellipsis;
|
|
16
17
|
cursor: pointer;
|
|
17
18
|
|
|
19
|
+
&-content {
|
|
20
|
+
flex: 1;
|
|
21
|
+
overflow: hidden;
|
|
22
|
+
white-space: nowrap;
|
|
23
|
+
text-overflow: ellipsis;
|
|
24
|
+
}
|
|
25
|
+
|
|
18
26
|
&:not(&-disabled):hover {
|
|
19
27
|
background-color: var(--yee-select-option-hover-bg-color);
|
|
20
28
|
}
|
|
@@ -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", "mode", "className", "style", "optionLabelProp", "searchable", "disabled", "options", "selectedKeys", "allowClear", "placeholder", "closable", "suffix", "value", "open", "loading", "onSearch", "onRemove", "onClear", "onOpenChange", "onKeyDown"];
|
|
2
|
+
var _excluded = ["prefixCls", "mode", "className", "style", "optionLabelProp", "searchable", "disabled", "options", "selectedKeys", "allowClear", "placeholder", "closable", "suffix", "value", "open", "loading", "size", "onSearch", "onRemove", "onClear", "onOpenChange", "onKeyDown"];
|
|
3
3
|
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
4
4
|
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; }
|
|
5
5
|
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; }
|
|
@@ -46,6 +46,8 @@ var Selector = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
46
46
|
value = props.value,
|
|
47
47
|
open = props.open,
|
|
48
48
|
loading = props.loading,
|
|
49
|
+
_props$size = props.size,
|
|
50
|
+
size = _props$size === void 0 ? 'default' : _props$size,
|
|
49
51
|
onSearch = props.onSearch,
|
|
50
52
|
onRemove = props.onRemove,
|
|
51
53
|
onClear = props.onClear,
|
|
@@ -92,7 +94,7 @@ var Selector = /*#__PURE__*/React.forwardRef(function (props, ref) {
|
|
|
92
94
|
e.stopPropagation();
|
|
93
95
|
onRemove === null || onRemove === void 0 || onRemove(option);
|
|
94
96
|
};
|
|
95
|
-
var cls = clsx(prefixCls, ["".concat(prefixCls, "-searchable")], ["".concat(prefixCls, "-").concat(mode || 'single')], _defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-allow-clear"), allowClear), "".concat(prefixCls, "-disabled"), disabled), "".concat(prefixCls, "-open"), open), className);
|
|
97
|
+
var cls = clsx(prefixCls, ["".concat(prefixCls, "-").concat(size)], ["".concat(prefixCls, "-searchable")], ["".concat(prefixCls, "-").concat(mode || 'single')], _defineProperty(_defineProperty(_defineProperty({}, "".concat(prefixCls, "-allow-clear"), allowClear), "".concat(prefixCls, "-disabled"), disabled), "".concat(prefixCls, "-open"), open), className);
|
|
96
98
|
var renderSearch = function renderSearch() {
|
|
97
99
|
return /*#__PURE__*/React.createElement("div", {
|
|
98
100
|
className: clsx("".concat(prefixCls, "-input-wrapper"), {
|