@king-design/intact 2.0.11 → 2.0.12

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.
@@ -33,7 +33,7 @@ setDefault(() => {
33
33
  export function makeMenuStyles() {
34
34
  return css`
35
35
  min-width: ${cascader.width} !important;
36
- height: ${cascader.height};
36
+ min-height: ${cascader.height};
37
37
  .k-cascader-arrow {
38
38
  float: right;
39
39
  height: 100%;
@@ -23,7 +23,7 @@ order: 0
23
23
  12. `min {number}`:请输入不小于n的数
24
24
  13. `range {Array<number>}`:请输入min到max之间的数
25
25
  14. `step {number}`:请输入步长为n的数
26
- 15. `equalTo {string}`:两次输入不一致
26
+ 15. `equal {string}`:两次输入不一致
27
27
  3. 给`FormItem`添加`messages`属性,指定验证失败时展示的错误提示。默认内容如上所示
28
28
  4. 给`FormItem`添加`classNames`属性,指定验证失败时错误元素需要额外添加的`className`,默认不添加
29
29
 
@@ -31,9 +31,9 @@ sidebar: doc
31
31
  | fluid | `FormItem`的宽度默认是被子元素撑开的,添加该属性可以渲染`100%`的宽度 | `boolean` | `false` |
32
32
 
33
33
  ```ts
34
- type Method = (value: any, param: any) => boolean | string
35
- type Message = string | ((value: any, param: any) => string)
36
- type ClassName = string | ((value: any, param: any) => string)
34
+ export declare type Method = (value: any, param: any) => boolean | string | Promise<boolean | string>
35
+ export declare type Message = string | ((value: any, param: any) => string)
36
+ export declare type ClassName = string | ((value: any, param: any) => string)
37
37
  ```
38
38
 
39
39
  # 扩展点
@@ -72,9 +72,12 @@ type ClassName = string | ((value: any, param: any) => string)
72
72
 
73
73
  | 方法名 | 说明 | 参数 | 返回值 |
74
74
  | --- | --- | --- | --- |
75
- | addMethod | 添加全局验证规则,这样在所有`FormItem`中如果需要使用该规则,只需要在`rules`中写上该规则名即可 | 1. `name` 指定规则名称,不能重复 <br /> 2. `method` 指定该规则的验证函数,该函数返回`true`或`false`来标识验证成功或失败,如果返回字符串,则直接当做错误文案展示,该函数将传入3个参数:1. 当前验证的值,2. 当前验证的`FormItem`实例,3. 当前规则的参数,即使用该规则时指定的值 <br /> 3. `message` 验证失败时的错误提示文案,该值可以为字符串或者函数,如果为函数,传入参数同`method`,用于个性化文案提示 <br /> 4. `className` 验证失败时添加的类名 | `undefined` |
75
+ | addMethod | 添加全局验证规则,这样在所有`FormItem`中如果需要使用该规则,只需要在`rules`中写上该规则名即可 | 1. `name` 指定规则名称,不能重复 <br /> 2. `method` 指定该规则的验证函数,该函数返回`true`或`false`来标识验证成功或失败,如果返回字符串,则直接当做错误文案展示,该函数将传入2个参数:1. 当前验证的值,2. 当前规则的参数,即使用该规则时指定的值 <br /> 3. `message` 验证失败时的错误提示文案,该值可以为字符串或者函数,如果为函数,传入参数同`method`,用于个性化文案提示 <br /> 4. `className` 验证失败时添加的类名 | `undefined` |
76
76
 
77
77
  ```ts
78
+ export declare type Method = (value: any, param: any) => boolean | string | Promise<boolean | string>
79
+ export declare type Message = string | ((value: any, param: any) => string)
80
+ export declare type ClassName = string | ((value: any, param: any) => string)
78
81
  export declare const addMethod: (
79
82
  name: string,
80
83
  method: Method,
@@ -1,7 +1,8 @@
1
1
  import {_$} from '../../i18n';
2
2
  import {isNumber, isNullOrUndefined, isString} from 'intact-shared';
3
3
 
4
- export type Method = (value: any, param: any) => boolean | string
4
+ export type MethodReturn = boolean | string
5
+ export type Method = (value: any, param: any) => MethodReturn | Promise<MethodReturn>
5
6
  export type Message = string | ((value: any, param: any) => string)
6
7
  export type ClassName = string | ((value: any, param: any) => string)
7
8
 
@@ -185,7 +185,6 @@ export class Table<
185
185
  this.scroll,
186
186
  this.width.tableRef,
187
187
  this.fixedColumns.setScrollPosition,
188
- this.width.tableWidth,
189
188
  );
190
189
 
191
190
  public checkAll() {
@@ -0,0 +1,22 @@
1
+ import {onMounted, onBeforeUnmount, RefObject, useInstance} from "intact";
2
+ import {debounce} from '../utils';
3
+ import ResizeObserver from 'resize-observer-polyfill';
4
+
5
+ export function useResizeObserver(elementRef: RefObject<HTMLElement>, callback: Function) {
6
+ const instance = useInstance()!;
7
+
8
+ let ro: ResizeObserver;
9
+ onMounted(() => {
10
+ // use debounce instead of throttle, because if there is
11
+ // transition on parent container, the width is weired
12
+ // #342
13
+ ro = new ResizeObserver(debounce(() => {
14
+ if (instance.$unmounted) return;
15
+ callback();
16
+ }, 100, true));
17
+ ro.observe(elementRef.value!);
18
+ });
19
+ onBeforeUnmount(() => {
20
+ ro.disconnect();
21
+ });
22
+ }
@@ -5,13 +5,13 @@ import type {Table} from './';
5
5
  import {isStringOrNumber, isNull} from 'intact-shared';
6
6
  import {debounce} from '../utils';
7
7
  import type {useScroll} from './useScroll';
8
+ import {useResizeObserver} from './useResizeObserver';
8
9
 
9
10
  export function useStickyScrollbar(
10
11
  elementRef: RefObject<HTMLElement>,
11
12
  {scrollRef, callbacks}: ReturnType<typeof useScroll>,
12
13
  tableRef: RefObject<HTMLElement>,
13
14
  tableScroll: (scrollLeft: number) => void,
14
- tableWidth: State<number | null>,
15
15
  ) {
16
16
  const instance = useInstance() as Table;
17
17
  const stick = useState<number | null>(null);
@@ -23,13 +23,7 @@ export function useStickyScrollbar(
23
23
  stick.set(v === true ? 0 : isStringOrNumber(v) ? +v : null);
24
24
  });
25
25
 
26
- watchState(tableWidth, v => {
27
- if (v) {
28
- tableActualWidth.set(v + 'px');
29
- } else {
30
- setTableActualWidth();
31
- }
32
- });
26
+ useResizeObserver(scrollRef, setTableActualWidth);
33
27
 
34
28
  onMounted(() => {
35
29
  setTableActualWidth();
@@ -1,10 +1,9 @@
1
- import {useInstance, RefObject, onMounted, onBeforeUnmount, VNodeComponentClass, createRef} from 'intact';
2
- import ResizeObserver from 'resize-observer-polyfill';
1
+ import {useInstance, RefObject, onMounted, VNodeComponentClass, createRef} from 'intact';
3
2
  import type {Table, TableRowKey} from './table';
4
3
  import type {TableColumn} from './column';
5
4
  import {useState} from '../../hooks/useState';
6
- import {debounce} from '../utils';
7
5
  import {scrollbarWidth} from '../position';
6
+ import {useResizeObserver} from './useResizeObserver';
8
7
 
9
8
  const hasLocalStorage = typeof localStorage !== 'undefined';
10
9
 
@@ -19,21 +18,8 @@ export function useWidth(
19
18
 
20
19
  initWidthFromStore();
21
20
 
22
- let ro: ResizeObserver;
23
- onMounted(() => {
24
- checkTableWidth(true);
25
- // use debounce instead of throttle, because if there is
26
- // transition on parent container, the width is weired
27
- // #342
28
- ro = new ResizeObserver(debounce(() => {
29
- if (instance.$unmounted) return;
30
- checkTableWidth(false);
31
- }, 100, true));
32
- ro.observe(scrollRef.value!);
33
- });
34
- onBeforeUnmount(() => {
35
- ro.disconnect();
36
- });
21
+ onMounted(() => checkTableWidth(true));
22
+ useResizeObserver(scrollRef, () => checkTableWidth(false));
37
23
 
38
24
  // if exist widthStoreKey, we get the default width from localStorage
39
25
  function initWidthFromStore() {
@@ -43,7 +43,7 @@ setDefault(function () {
43
43
  }).cascader;
44
44
  });
45
45
  export function makeMenuStyles() {
46
- return /*#__PURE__*/css("min-width:", cascader.width, "!important;height:", cascader.height, ";.k-cascader-arrow{float:right;height:100%;margin-left:", cascader.arrowGap, ";line-height:inherit;}.k-cascader-loading{display:block;text-align:center;margin-top:", cascader.loadingGap, ";}.k-cascader-empty{padding:", cascader.empty.padding, ";color:", cascader.empty.color, ";text-align:center;}.k-cascader-option{&.k-selected{color:", cascader.selectedColor, ";}&.k-active{background:", cascader.activeBgColor, ";}}");
46
+ return /*#__PURE__*/css("min-width:", cascader.width, "!important;min-height:", cascader.height, ";.k-cascader-arrow{float:right;height:100%;margin-left:", cascader.arrowGap, ";line-height:inherit;}.k-cascader-loading{display:block;text-align:center;margin-top:", cascader.loadingGap, ";}.k-cascader-empty{padding:", cascader.empty.padding, ";color:", cascader.empty.color, ";text-align:center;}.k-cascader-option{&.k-selected{color:", cascader.selectedColor, ";}&.k-active{background:", cascader.activeBgColor, ";}}");
47
47
  }
48
48
  export function makeFilterMenuStyles() {
49
49
  return /*#__PURE__*/css("min-width:", _filterInstanceProperty(cascader).minWidth, "!important;height:auto;max-height:", _filterInstanceProperty(cascader).maxHeight, ";em{font-style:normal;color:", _filterInstanceProperty(cascader).highlightColor, ";}");
@@ -1,4 +1,5 @@
1
- export declare type Method = (value: any, param: any) => boolean | string;
1
+ export declare type MethodReturn = boolean | string;
2
+ export declare type Method = (value: any, param: any) => MethodReturn | Promise<MethodReturn>;
2
3
  export declare type Message = string | ((value: any, param: any) => string);
3
4
  export declare type ClassName = string | ((value: any, param: any) => string);
4
5
  export declare const methods: Record<string, Method>;
@@ -106,7 +106,7 @@ export var Table = /*#__PURE__*/function (_Component) {
106
106
  _this.selected = useSelected();
107
107
  _this.resetRowStatus = useRestRowStatus(_this.disableRow.getAllKeys);
108
108
  _this.draggable = useDraggable();
109
- _this.stickyScrollbar = useStickyScrollbar(_this.stickyHeader.elementRef, _this.scroll, _this.width.tableRef, _this.fixedColumns.setScrollPosition, _this.width.tableWidth);
109
+ _this.stickyScrollbar = useStickyScrollbar(_this.stickyHeader.elementRef, _this.scroll, _this.width.tableRef, _this.fixedColumns.setScrollPosition);
110
110
  return _this;
111
111
  }
112
112
 
@@ -0,0 +1,2 @@
1
+ import { RefObject } from "intact";
2
+ export declare function useResizeObserver(elementRef: RefObject<HTMLElement>, callback: Function): void;
@@ -0,0 +1,20 @@
1
+ import { onMounted, onBeforeUnmount, useInstance } from "intact";
2
+ import { debounce } from '../utils';
3
+ import ResizeObserver from 'resize-observer-polyfill';
4
+ export function useResizeObserver(elementRef, callback) {
5
+ var instance = useInstance();
6
+ var ro;
7
+ onMounted(function () {
8
+ // use debounce instead of throttle, because if there is
9
+ // transition on parent container, the width is weired
10
+ // #342
11
+ ro = new ResizeObserver(debounce(function () {
12
+ if (instance.$unmounted) return;
13
+ callback();
14
+ }, 100, true));
15
+ ro.observe(elementRef.value);
16
+ });
17
+ onBeforeUnmount(function () {
18
+ ro.disconnect();
19
+ });
20
+ }
@@ -2,7 +2,7 @@ import { RefObject } from 'intact';
2
2
  import { ShouldFixParam } from '../affix';
3
3
  import { State } from '../../hooks/useState';
4
4
  import type { useScroll } from './useScroll';
5
- export declare function useStickyScrollbar(elementRef: RefObject<HTMLElement>, { scrollRef, callbacks }: ReturnType<typeof useScroll>, tableRef: RefObject<HTMLElement>, tableScroll: (scrollLeft: number) => void, tableWidth: State<number | null>): {
5
+ export declare function useStickyScrollbar(elementRef: RefObject<HTMLElement>, { scrollRef, callbacks }: ReturnType<typeof useScroll>, tableRef: RefObject<HTMLElement>, tableScroll: (scrollLeft: number) => void): {
6
6
  shouldStickScrollbar: ({ offsetBottom, viewportHeight }: ShouldFixParam) => boolean;
7
7
  stick: State<number | null>;
8
8
  style: State<Record<string, string> | null>;
@@ -1,8 +1,9 @@
1
1
  import { createRef, useInstance, onMounted, nextTick } from 'intact';
2
- import { useState, watchState } from '../../hooks/useState';
2
+ import { useState } from '../../hooks/useState';
3
3
  import { isStringOrNumber, isNull } from 'intact-shared';
4
4
  import { debounce } from '../utils';
5
- export function useStickyScrollbar(elementRef, _ref, tableRef, tableScroll, tableWidth) {
5
+ import { useResizeObserver } from './useResizeObserver';
6
+ export function useStickyScrollbar(elementRef, _ref, tableRef, tableScroll) {
6
7
  var scrollRef = _ref.scrollRef,
7
8
  callbacks = _ref.callbacks;
8
9
  var instance = useInstance();
@@ -13,13 +14,7 @@ export function useStickyScrollbar(elementRef, _ref, tableRef, tableScroll, tabl
13
14
  instance.on('$receive:stickScrollbar', function (v) {
14
15
  stick.set(v === true ? 0 : isStringOrNumber(v) ? +v : null);
15
16
  });
16
- watchState(tableWidth, function (v) {
17
- if (v) {
18
- tableActualWidth.set(v + 'px');
19
- } else {
20
- setTableActualWidth();
21
- }
22
- });
17
+ useResizeObserver(scrollRef, setTableActualWidth);
23
18
  onMounted(function () {
24
19
  setTableActualWidth();
25
20
  });
@@ -1,10 +1,9 @@
1
1
  import _mapInstanceProperty from "@babel/runtime-corejs3/core-js/instance/map";
2
2
  import _JSON$stringify from "@babel/runtime-corejs3/core-js/json/stringify";
3
- import { useInstance, onMounted, onBeforeUnmount, createRef } from 'intact';
4
- import ResizeObserver from 'resize-observer-polyfill';
3
+ import { useInstance, onMounted, createRef } from 'intact';
5
4
  import { useState } from '../../hooks/useState';
6
- import { debounce } from '../utils';
7
5
  import { scrollbarWidth } from '../position';
6
+ import { useResizeObserver } from './useResizeObserver';
8
7
  var hasLocalStorage = typeof localStorage !== 'undefined';
9
8
  export function useWidth(scrollRef, getColumns) {
10
9
  var instance = useInstance();
@@ -12,20 +11,11 @@ export function useWidth(scrollRef, getColumns) {
12
11
  var widthMap = useState({});
13
12
  var tableWidth = useState(null);
14
13
  initWidthFromStore();
15
- var ro;
16
14
  onMounted(function () {
17
- checkTableWidth(true); // use debounce instead of throttle, because if there is
18
- // transition on parent container, the width is weired
19
- // #342
20
-
21
- ro = new ResizeObserver(debounce(function () {
22
- if (instance.$unmounted) return;
23
- checkTableWidth(false);
24
- }, 100, true));
25
- ro.observe(scrollRef.value);
15
+ return checkTableWidth(true);
26
16
  });
27
- onBeforeUnmount(function () {
28
- ro.disconnect();
17
+ useResizeObserver(scrollRef, function () {
18
+ return checkTableWidth(false);
29
19
  }); // if exist widthStoreKey, we get the default width from localStorage
30
20
 
31
21
  function initWidthFromStore() {
package/es/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @king-design v2.0.11
2
+ * @king-design v2.0.12
3
3
  *
4
4
  * Copyright (c) Kingsoft Cloud
5
5
  * Released under the MIT License
@@ -57,4 +57,4 @@ export * from './components/tree';
57
57
  export * from './components/treeSelect';
58
58
  export * from './components/upload';
59
59
  export * from './components/wave';
60
- export declare const version = "2.0.11";
60
+ export declare const version = "2.0.12";
package/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @king-design v2.0.11
2
+ * @king-design v2.0.12
3
3
  *
4
4
  * Copyright (c) Kingsoft Cloud
5
5
  * Released under the MIT License
@@ -59,5 +59,5 @@ export * from './components/tree';
59
59
  export * from './components/treeSelect';
60
60
  export * from './components/upload';
61
61
  export * from './components/wave';
62
- export var version = '2.0.11';
62
+ export var version = '2.0.12';
63
63
  /* generate end */
@@ -1,20 +1,41 @@
1
1
  import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
2
2
  import _asyncToGenerator from "@babel/runtime-corejs3/helpers/asyncToGenerator";
3
3
  import _regeneratorRuntime from "@babel/runtime-corejs3/regenerator";
4
- import React from 'react';
4
+ import React, { useState } from 'react';
5
5
  import * as ReactDOM from 'react-dom';
6
6
  import { Drawer, Card, Button } from '../../';
7
7
  import { Component } from 'intact-react';
8
8
  import { wait, dispatchEvent } from '../../../../test/utils';
9
9
  describe('Drawer', function () {
10
+ var container;
11
+ beforeEach(function () {
12
+ container = document.createElement('div');
13
+ document.body.appendChild(container);
14
+ });
15
+ afterEach(function () {
16
+ ReactDOM.unmountComponentAtNode(container);
17
+ document.body.removeChild(container);
18
+ });
10
19
  it('should render react element correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee() {
11
- var container, Test;
20
+ var Test, App;
12
21
  return _regeneratorRuntime.wrap(function _callee$(_context) {
13
22
  while (1) {
14
23
  switch (_context.prev = _context.next) {
15
24
  case 0:
16
- container = document.createElement('div');
17
- document.body.appendChild(container);
25
+ App = function _App() {
26
+ var _useState = useState(false),
27
+ show = _useState[0],
28
+ setShow = _useState[1];
29
+
30
+ return /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement("div", {
31
+ onClick: function onClick() {
32
+ return setShow(true);
33
+ }
34
+ }, "show"), /*#__PURE__*/React.createElement(Drawer, {
35
+ value: show,
36
+ mode: "destroy"
37
+ }, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Test, null))));
38
+ };
18
39
 
19
40
  Test = /*#__PURE__*/function (_Component) {
20
41
  _inheritsLoose(Test, _Component);
@@ -33,11 +54,9 @@ describe('Drawer', function () {
33
54
  }(Component);
34
55
 
35
56
  Test.template = "<div ref=\"a\">test</div>";
36
- ReactDOM.render( /*#__PURE__*/React.createElement(Card, null, /*#__PURE__*/React.createElement(Drawer, null, /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Test, null)))), container);
37
- ReactDOM.unmountComponentAtNode(container);
38
- document.body.removeChild(container);
57
+ ReactDOM.render( /*#__PURE__*/React.createElement(App, null), container);
39
58
 
40
- case 7:
59
+ case 4:
41
60
  case "end":
42
61
  return _context.stop();
43
62
  }
@@ -45,14 +64,12 @@ describe('Drawer', function () {
45
64
  }, _callee);
46
65
  })));
47
66
  it('should handle event correctly', /*#__PURE__*/_asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
48
- var container, click1, click2, _document$querySelect, element1, element2;
67
+ var click1, click2, _document$querySelect, element1, element2;
49
68
 
50
69
  return _regeneratorRuntime.wrap(function _callee2$(_context2) {
51
70
  while (1) {
52
71
  switch (_context2.prev = _context2.next) {
53
72
  case 0:
54
- container = document.createElement('div');
55
- document.body.appendChild(container);
56
73
  click1 = sinon.spy(function () {
57
74
  return console.log(1);
58
75
  });
@@ -83,20 +100,19 @@ describe('Drawer', function () {
83
100
  }, "click")))), container);
84
101
  _document$querySelect = document.querySelectorAll('.click'), element1 = _document$querySelect[0], element2 = _document$querySelect[1];
85
102
  dispatchEvent(element1, 'click');
86
- _context2.next = 9;
103
+ _context2.next = 7;
87
104
  return wait();
88
105
 
89
- case 9:
106
+ case 7:
90
107
  expect(click1.callCount).to.eql(1);
91
108
  dispatchEvent(element2, 'click');
92
- _context2.next = 13;
109
+ _context2.next = 11;
93
110
  return wait();
94
111
 
95
- case 13:
96
- expect(click2.callCount).to.eql(1); // ReactDOM.unmountComponentAtNode(container);
97
- // document.body.removeChild(container);
112
+ case 11:
113
+ expect(click2.callCount).to.eql(1);
98
114
 
99
- case 14:
115
+ case 12:
100
116
  case "end":
101
117
  return _context2.stop();
102
118
  }
package/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @king-design v2.0.11
2
+ * @king-design v2.0.12
3
3
  *
4
4
  * Copyright (c) Kingsoft Cloud
5
5
  * Released under the MIT License
@@ -62,6 +62,6 @@ export * from './components/treeSelect';
62
62
  export * from './components/upload';
63
63
  export * from './components/wave';
64
64
 
65
- export const version = '2.0.11';
65
+ export const version = '2.0.12';
66
66
 
67
67
  /* generate end */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@king-design/intact",
3
- "version": "2.0.11",
3
+ "version": "2.0.12",
4
4
  "description": "A component library written in Intact for Intact, Vue, React and Angular",
5
5
  "main": "es/index.js",
6
6
  "scripts": {
@@ -116,7 +116,7 @@
116
116
  "highlight.js": "^10.4.1",
117
117
  "history": "^5.0.0",
118
118
  "html-webpack-plugin": "5.3.1",
119
- "intact-react": "^3.0.12",
119
+ "intact-react": "^3.0.13",
120
120
  "istanbul-instrumenter-loader": "^3.0.0",
121
121
  "js-yaml": "^4.1.0",
122
122
  "karma": "^6.3.2",
@@ -178,7 +178,7 @@
178
178
  "dayjs": "^1.10.7",
179
179
  "downloadjs": "^1.4.7",
180
180
  "enquire.js": "^2.1.6",
181
- "intact": "^3.0.12",
181
+ "intact": "^3.0.13",
182
182
  "monaco-editor": "^0.26.1",
183
183
  "mxgraphx": "^4.0.7",
184
184
  "resize-observer-polyfill": "^1.5.1",
Binary file