@teamix/pro 1.5.45 → 1.5.46
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/pro.js +46 -27
- package/dist/pro.min.js +1 -1
- package/es/form/Filter/useBindUrl.d.ts +1 -1
- package/es/form/Filter/useBindUrl.js +23 -19
- package/es/index.d.ts +1 -1
- package/es/index.js +1 -1
- package/es/table/utils/genAutoWidthColumns.js +4 -1
- package/lib/form/Filter/useBindUrl.d.ts +1 -1
- package/lib/form/Filter/useBindUrl.js +22 -18
- package/lib/index.d.ts +1 -1
- package/lib/index.js +1 -1
- package/lib/table/utils/genAutoWidthColumns.js +4 -1
- package/package.json +1 -1
@@ -6,7 +6,7 @@ export interface BindUrlInitFunctions {
|
|
6
6
|
onFilter?: (values: Record<string, any>) => void;
|
7
7
|
onReset?: (values: Record<string, any>) => void;
|
8
8
|
}
|
9
|
-
export default function useBindUrl(bindUrl: boolean | UrlStateOptions | undefined, functions: BindUrlInitFunctions, formRef: React.MutableRefObject<Form<any> | undefined>): {
|
9
|
+
export default function useBindUrl<S = unknown>(bindUrl: boolean | UrlStateOptions<S> | undefined, functions: BindUrlInitFunctions, formRef: React.MutableRefObject<Form<any> | undefined>): {
|
10
10
|
onInit?: ((values: Record<string, any>) => void) | undefined;
|
11
11
|
onFilter?: ((values: Record<string, any>) => void) | undefined;
|
12
12
|
onReset?: ((values: Record<string, any>) => void) | undefined;
|
@@ -7,9 +7,10 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
8
8
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
9
9
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
10
|
-
import { useUrlState } from '@teamix/hooks';
|
10
|
+
import { useUpdate, useUrlState } from '@teamix/hooks';
|
11
11
|
import { isUsable, isPlainObj } from '@teamix/utils';
|
12
12
|
export default function useBindUrl(bindUrl, functions, formRef) {
|
13
|
+
var update = useUpdate();
|
13
14
|
// 预处理 bindUrl 参数(主要兼容 SelectGroup 组件)
|
14
15
|
var initializeBindUrl = function initializeBindUrl(options) {
|
15
16
|
return options ? _objectSpread(_objectSpread({}, options), {}, {
|
@@ -39,10 +40,11 @@ export default function useBindUrl(bindUrl, functions, formRef) {
|
|
39
40
|
};
|
40
41
|
// 通过 useUrlState 获取 url 上的参数和 url 配置方法
|
41
42
|
var _ref4 = bindUrl ? useUrlState(undefined, initializeBindUrl(isPlainObj(bindUrl) ? bindUrl : {})) : [],
|
42
|
-
_ref5 = _slicedToArray(_ref4,
|
43
|
+
_ref5 = _slicedToArray(_ref4, 4),
|
43
44
|
urlState = _ref5[0],
|
44
45
|
setUrlState = _ref5[1],
|
45
|
-
queryFromUrl = _ref5[2]
|
46
|
+
queryFromUrl = _ref5[2],
|
47
|
+
stringify = _ref5[3];
|
46
48
|
// 输出配置url参数的函数
|
47
49
|
var initializedFunctions = Object.entries(functions).reduce(function (prev, _ref6) {
|
48
50
|
var _ref7 = _slicedToArray(_ref6, 2),
|
@@ -52,31 +54,33 @@ export default function useBindUrl(bindUrl, functions, formRef) {
|
|
52
54
|
originalFunction === null || originalFunction === void 0 ? void 0 : originalFunction(values);
|
53
55
|
if (bindUrl) {
|
54
56
|
// guard: onInit 会在 mount 时被自动调用,需要避免其在任何情况下都调用 setUrlState。故增加幂等判断
|
55
|
-
var
|
57
|
+
var hasStringifiedDiff = false;
|
58
|
+
var hasValuesDiff = false;
|
56
59
|
for (var paramName in values) {
|
57
60
|
if (Object.hasOwn(values, paramName)) {
|
58
|
-
var simpleTransform = function simpleTransform(value) {
|
59
|
-
if (value instanceof Array) {
|
60
|
-
return value.join(',');
|
61
|
-
}
|
62
|
-
if (value === undefined || value === null) {
|
63
|
-
return '';
|
64
|
-
}
|
65
|
-
if (value instanceof Object) {
|
66
|
-
console.warn('useBindUrl: 无法处理对象类型的 url 参数');
|
67
|
-
}
|
68
|
-
return value;
|
69
|
-
};
|
70
61
|
var oldValue = queryFromUrl === null || queryFromUrl === void 0 ? void 0 : queryFromUrl[paramName];
|
71
62
|
var newValue = values[paramName];
|
72
|
-
|
73
|
-
|
63
|
+
// 这里我们必须使用 stringify 来判断是否有变化,因为 special case 太多。例如,默认配置下:
|
64
|
+
// { a: [undefined, undefined], b: undefined, c: [], d: null, e: ''} 会生成 'd=&e='
|
65
|
+
// 类似地,{ a: [''], b: [null], c: [undefined] } 会生成 'a=&b='。更不用说还有非默认配置的情况
|
66
|
+
// 想要避免这种 hazard,我们必须使用钩子内部导出的、经过柯里化的 stringify 来判断生成的字符串是否无变化。
|
67
|
+
if (stringify({
|
68
|
+
v: newValue
|
69
|
+
}) !== stringify({
|
70
|
+
v: oldValue
|
71
|
+
})) {
|
72
|
+
hasStringifiedDiff = true;
|
74
73
|
break;
|
74
|
+
} else if (oldValue !== newValue) {
|
75
|
+
hasValuesDiff = true;
|
75
76
|
}
|
76
77
|
}
|
77
78
|
}
|
78
|
-
if (
|
79
|
+
if (hasStringifiedDiff) {
|
79
80
|
setUrlState(values);
|
81
|
+
} else if (hasValuesDiff) {
|
82
|
+
// guard: 虽然 url 字符串没有变化,但是 values 变化了,还是需要触发组件的 update 以保证行为一致。
|
83
|
+
update();
|
80
84
|
}
|
81
85
|
}
|
82
86
|
};
|
package/es/index.d.ts
CHANGED
@@ -30,5 +30,5 @@ export * from './sidebar';
|
|
30
30
|
export * from './utils';
|
31
31
|
export * from './timeline';
|
32
32
|
export * from './image';
|
33
|
-
declare const version = "1.5.
|
33
|
+
declare const version = "1.5.46";
|
34
34
|
export { version, ProAction, ProCard, ProField, ProForm, ProInfo, ProPageContainer, ProPageHeader, ProSkeleton, ProTable, ProSidebar, ProTimeline, TeamixIcon, ProImage, hooks, nocode, templates, utils, };
|
package/es/index.js
CHANGED
@@ -38,7 +38,10 @@ export function genAutoWidthColumns(columns, ref, data, size, useRowSelection, a
|
|
38
38
|
return columns;
|
39
39
|
}
|
40
40
|
var finalColumns = [];
|
41
|
-
|
41
|
+
// @FIXME: lodash 的 cloneDeep 无法正确处理 columns 内部含有 ReactNode 的情况。我们也不该用 React 以外的工具来复制 ReactNode
|
42
|
+
// 因为它里面的 fiber node id 等等的在复制后并不会变,对于 React 来讲这就意味着两个 ReactNode 有相同的 fiber node id,不符合预期。
|
43
|
+
// 先注释掉,后续再想办法
|
44
|
+
var filterdColumnsResult = columns; // _.cloneDeep(columns);
|
42
45
|
filterdColumnsResult.forEach(function (column, index) {
|
43
46
|
var render = column.render,
|
44
47
|
_column$valueType = column.valueType,
|
@@ -6,7 +6,7 @@ export interface BindUrlInitFunctions {
|
|
6
6
|
onFilter?: (values: Record<string, any>) => void;
|
7
7
|
onReset?: (values: Record<string, any>) => void;
|
8
8
|
}
|
9
|
-
export default function useBindUrl(bindUrl: boolean | UrlStateOptions | undefined, functions: BindUrlInitFunctions, formRef: React.MutableRefObject<Form<any> | undefined>): {
|
9
|
+
export default function useBindUrl<S = unknown>(bindUrl: boolean | UrlStateOptions<S> | undefined, functions: BindUrlInitFunctions, formRef: React.MutableRefObject<Form<any> | undefined>): {
|
10
10
|
onInit?: ((values: Record<string, any>) => void) | undefined;
|
11
11
|
onFilter?: ((values: Record<string, any>) => void) | undefined;
|
12
12
|
onReset?: ((values: Record<string, any>) => void) | undefined;
|
@@ -16,6 +16,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
|
|
16
16
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
17
17
|
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
18
18
|
function useBindUrl(bindUrl, functions, formRef) {
|
19
|
+
var update = (0, _hooks.useUpdate)();
|
19
20
|
// 预处理 bindUrl 参数(主要兼容 SelectGroup 组件)
|
20
21
|
var initializeBindUrl = function initializeBindUrl(options) {
|
21
22
|
return options ? _objectSpread(_objectSpread({}, options), {}, {
|
@@ -45,10 +46,11 @@ function useBindUrl(bindUrl, functions, formRef) {
|
|
45
46
|
};
|
46
47
|
// 通过 useUrlState 获取 url 上的参数和 url 配置方法
|
47
48
|
var _ref4 = bindUrl ? (0, _hooks.useUrlState)(undefined, initializeBindUrl((0, _utils.isPlainObj)(bindUrl) ? bindUrl : {})) : [],
|
48
|
-
_ref5 = _slicedToArray(_ref4,
|
49
|
+
_ref5 = _slicedToArray(_ref4, 4),
|
49
50
|
urlState = _ref5[0],
|
50
51
|
setUrlState = _ref5[1],
|
51
|
-
queryFromUrl = _ref5[2]
|
52
|
+
queryFromUrl = _ref5[2],
|
53
|
+
stringify = _ref5[3];
|
52
54
|
// 输出配置url参数的函数
|
53
55
|
var initializedFunctions = Object.entries(functions).reduce(function (prev, _ref6) {
|
54
56
|
var _ref7 = _slicedToArray(_ref6, 2),
|
@@ -58,31 +60,33 @@ function useBindUrl(bindUrl, functions, formRef) {
|
|
58
60
|
originalFunction === null || originalFunction === void 0 ? void 0 : originalFunction(values);
|
59
61
|
if (bindUrl) {
|
60
62
|
// guard: onInit 会在 mount 时被自动调用,需要避免其在任何情况下都调用 setUrlState。故增加幂等判断
|
61
|
-
var
|
63
|
+
var hasStringifiedDiff = false;
|
64
|
+
var hasValuesDiff = false;
|
62
65
|
for (var paramName in values) {
|
63
66
|
if (Object.hasOwn(values, paramName)) {
|
64
|
-
var simpleTransform = function simpleTransform(value) {
|
65
|
-
if (value instanceof Array) {
|
66
|
-
return value.join(',');
|
67
|
-
}
|
68
|
-
if (value === undefined || value === null) {
|
69
|
-
return '';
|
70
|
-
}
|
71
|
-
if (value instanceof Object) {
|
72
|
-
console.warn('useBindUrl: 无法处理对象类型的 url 参数');
|
73
|
-
}
|
74
|
-
return value;
|
75
|
-
};
|
76
67
|
var oldValue = queryFromUrl === null || queryFromUrl === void 0 ? void 0 : queryFromUrl[paramName];
|
77
68
|
var newValue = values[paramName];
|
78
|
-
|
79
|
-
|
69
|
+
// 这里我们必须使用 stringify 来判断是否有变化,因为 special case 太多。例如,默认配置下:
|
70
|
+
// { a: [undefined, undefined], b: undefined, c: [], d: null, e: ''} 会生成 'd=&e='
|
71
|
+
// 类似地,{ a: [''], b: [null], c: [undefined] } 会生成 'a=&b='。更不用说还有非默认配置的情况
|
72
|
+
// 想要避免这种 hazard,我们必须使用钩子内部导出的、经过柯里化的 stringify 来判断生成的字符串是否无变化。
|
73
|
+
if (stringify({
|
74
|
+
v: newValue
|
75
|
+
}) !== stringify({
|
76
|
+
v: oldValue
|
77
|
+
})) {
|
78
|
+
hasStringifiedDiff = true;
|
80
79
|
break;
|
80
|
+
} else if (oldValue !== newValue) {
|
81
|
+
hasValuesDiff = true;
|
81
82
|
}
|
82
83
|
}
|
83
84
|
}
|
84
|
-
if (
|
85
|
+
if (hasStringifiedDiff) {
|
85
86
|
setUrlState(values);
|
87
|
+
} else if (hasValuesDiff) {
|
88
|
+
// guard: 虽然 url 字符串没有变化,但是 values 变化了,还是需要触发组件的 update 以保证行为一致。
|
89
|
+
update();
|
86
90
|
}
|
87
91
|
}
|
88
92
|
};
|
package/lib/index.d.ts
CHANGED
@@ -30,5 +30,5 @@ export * from './sidebar';
|
|
30
30
|
export * from './utils';
|
31
31
|
export * from './timeline';
|
32
32
|
export * from './image';
|
33
|
-
declare const version = "1.5.
|
33
|
+
declare const version = "1.5.46";
|
34
34
|
export { version, ProAction, ProCard, ProField, ProForm, ProInfo, ProPageContainer, ProPageHeader, ProSkeleton, ProTable, ProSidebar, ProTimeline, TeamixIcon, ProImage, hooks, nocode, templates, utils, };
|
package/lib/index.js
CHANGED
@@ -299,7 +299,7 @@ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj &&
|
|
299
299
|
if (!((_window = window) === null || _window === void 0 ? void 0 : _window.TEAMIXPRO_WITHOUT_ICON)) {
|
300
300
|
_icon.default.setConfig(_utils.default.getTeamixIconConfig());
|
301
301
|
}
|
302
|
-
var version = '1.5.
|
302
|
+
var version = '1.5.46';
|
303
303
|
// By TeamixTest
|
304
304
|
exports.version = version;
|
305
305
|
window.postMessage({
|
@@ -48,7 +48,10 @@ function genAutoWidthColumns(columns, ref, data, size, useRowSelection, actionCo
|
|
48
48
|
return columns;
|
49
49
|
}
|
50
50
|
var finalColumns = [];
|
51
|
-
|
51
|
+
// @FIXME: lodash 的 cloneDeep 无法正确处理 columns 内部含有 ReactNode 的情况。我们也不该用 React 以外的工具来复制 ReactNode
|
52
|
+
// 因为它里面的 fiber node id 等等的在复制后并不会变,对于 React 来讲这就意味着两个 ReactNode 有相同的 fiber node id,不符合预期。
|
53
|
+
// 先注释掉,后续再想办法
|
54
|
+
var filterdColumnsResult = columns; // _.cloneDeep(columns);
|
52
55
|
filterdColumnsResult.forEach(function (column, index) {
|
53
56
|
var render = column.render,
|
54
57
|
_column$valueType = column.valueType,
|