@king-design/intact 3.4.3-beta.1 → 3.4.3-beta.2

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.
@@ -276,6 +276,9 @@ export const makeMenuStyles = cache(function makeMenuStyles(k: string) {
276
276
  .${k}-menu-header {
277
277
  padding: 0;
278
278
  }
279
+ .${k}-menu-header {
280
+ padding: 0;
281
+ }
279
282
  .${k}-menu-body {
280
283
  overflow: hidden;
281
284
  padding: 0;
@@ -19,6 +19,7 @@ import {useFocusout} from './useFocusout';
19
19
  import type {Events} from '../types';
20
20
  import {isNullOrUndefined} from 'intact-shared';
21
21
  import { useDraggable } from './useDraggble';
22
+ import { useImmutable } from './useImmutable';
22
23
  import { useConfigContext } from '../config';
23
24
 
24
25
  export interface BaseSelectProps<V, Multipe extends boolean = boolean, Attach = V | null> {
@@ -107,6 +108,7 @@ export abstract class BaseSelect<
107
108
  public input = useInput(this.resetKeywords);
108
109
  private focusout = useFocusout();
109
110
  private draggable = useDraggable();
111
+ public immutable = useImmutable();
110
112
  protected config = useConfigContext();
111
113
 
112
114
  init() {
@@ -160,7 +162,10 @@ export abstract class BaseSelect<
160
162
  @bind
161
163
  protected clear(e: MouseEvent) {
162
164
  e.stopPropagation();
163
- this.set('value', this.get('multiple') ? [] : null);
165
+ const {value, multiple} = this.get();
166
+ const immutableValues = this.immutable.immutableValues.value;
167
+
168
+ this.set('value', multiple ? (Array.isArray(value) ? value.filter(key => immutableValues.includes(key)) : []) : null);
164
169
  }
165
170
 
166
171
  @bind
@@ -39,6 +39,7 @@ const label = this.getLabel();
39
39
  const hasValue = this.hasValue();
40
40
  const {onInput, inputRef, keywords: {value: keywords}} = this.input;
41
41
  const {onFocusout, triggerRef} = this.focusout;
42
+ const {isClosable} = this.immutable;
42
43
  const filterInput = <Input v-if={filterable}
43
44
  class={`${k}-select-input`}
44
45
  value={keywords}
@@ -122,7 +123,7 @@ const filterInput = <Input v-if={filterable}
122
123
  value[$key] :
123
124
  $key
124
125
  }
125
- closable
126
+ closable={isClosable(value[$key])}
126
127
  ev-close={this.delete.bind(this, $key)}
127
128
  disabled={disabled}
128
129
  size={size}
@@ -0,0 +1,37 @@
1
+ ---
2
+ title: 禁用选项不可删除
3
+ order: 14
4
+ ---
5
+
6
+ 在指定`multiple`多选的情况下,`Select`指定`value`包含`disabled Option`,则禁止删除
7
+
8
+ ```vdt
9
+ import {Select, Option, OptionGroup} from 'kpc';
10
+ <div>
11
+ <Select v-model="day" multiple filterable clearable>
12
+ <Option value="Monday">星期一</Option>
13
+ <Option value="Tuesday" disabled>星期二</Option>
14
+ <Option value="Wednesday">星期三</Option>
15
+ <Option value="Thursday">星期四</Option>
16
+ <Option value="Friday" disabled>星期五</Option>
17
+ <Option value="Saturday">星期六</Option>
18
+ <Option value="Sunday">星期天</Option>
19
+ </Select>
20
+ You selected: {JSON.stringify(this.get('day'))}
21
+ </div>
22
+ ```
23
+
24
+ ```ts
25
+ interface Props {
26
+ day?: string[]
27
+ }
28
+
29
+ export default class extends Component {
30
+ static template = template;
31
+ static defaults() {
32
+ return {
33
+ day: ['Tuesday', 'Sunday', 'Wednesday'],
34
+ } as Props;
35
+ }
36
+ }
37
+ ```
@@ -0,0 +1,44 @@
1
+ import { useInstance, Children } from 'intact';
2
+ import type { Select } from './select';
3
+ import { Option, OptionProps } from './option';
4
+ import { OptionGroup } from './group';
5
+ import { eachChildren, isComponentVNode } from '../utils';
6
+ import { useState } from '../../hooks/useState';
7
+
8
+ export function useImmutable() {
9
+ const instance = useInstance() as Select<any, true>;
10
+ const immutableValues = useState<any[]>([]);
11
+
12
+ function setImmutableValues() {
13
+ const { children, multiple } = instance.get();
14
+ if (!multiple) return;
15
+ updateImmutableValues(children);
16
+ }
17
+
18
+ function updateImmutableValues(children: Children) {
19
+ const _immutableValues: any[] = [];
20
+ const loop = (children: Children) => {
21
+ eachChildren(children, vNode => {
22
+ if (isComponentVNode(vNode, Option)) {
23
+ const { disabled, value } = vNode.props as OptionProps;
24
+ if (disabled) {
25
+ _immutableValues.push(value);
26
+ }
27
+ } else if (isComponentVNode(vNode, OptionGroup)) {
28
+ loop(vNode.props!.children);
29
+ }
30
+ });
31
+ }
32
+
33
+ loop(children);
34
+ immutableValues.set(_immutableValues);
35
+ }
36
+
37
+ function isClosable(key: string) {
38
+ return !immutableValues.value.includes(key);
39
+ }
40
+
41
+ instance.on('$receive:children', setImmutableValues);
42
+
43
+ return { immutableValues, isClosable };
44
+ }
@@ -115,7 +115,7 @@ export var makeMenuStyles = cache(function makeMenuStyles(k) {
115
115
  return /*#__PURE__*/css("&.", k, "-menu{width:", menu.width, ";transition:width ", menu.transition, ";background:", menu.bgColor, ";font-size:", menu.fontSize, ";position:relative;}.", k, "-icon{width:", menu.icon.width, ";margin-right:", menu.icon.gap, ";text-align:center;flex-shrink:0;}.", k, "-menu-header{height:", menu.header.height, ";padding:0 16px;color:", menu.header.color, ";font-size:", menu.header.fontSize, ";font-weight:bold;}.", k, "-menu-body{padding:", menu.item.bodyPadding, ";max-height:calc(100% - ", menu.header.height, ");overflow-y:auto;overflow-x:hidden;scrollbar-width:none;}.", k, "-menu-title{height:", menu.title.height, ";border-top:", menu.border, ";margin-top:4px;.", k, "-menu-name{transition:all ", menu.transition, ";height:", menu.title.height, ";color:", menu.title.color, ";font-weight:bold;}}.", k, "-menu-arrow-box{width:14px;height:60px;cursor:pointer;background:", menu.bgColor, ";border-radius:0 8px 8px 0;position:absolute;display:flex;align-items:center;justify-content:center;top:50%;left:calc(", menu.width, " - 2px);transition:left ", menu.transition, ";transform:translateY(-50%);border:", menu.border, ";border-left:none;.", k, "-icon{margin-right:0;}&:hover{.", k, "-menu-arrow:before{color:", menu.item.activeBgColor, ";}}}&.", k, "-light{border-right:1px solid ", theme.color.disabledBg, ";background:", menu.light.bgColor, ";.", k, "-menu-header{color:", menu.light.title.color, ";}.", k, "-menu-item{.", k, "-menu-item-title{color:", menu.light.item.color, ";&:hover{background:", menu.light.item.hoverBg, ";}}.", k, "-menu-item-arrow{color:", menu.light.item.color, ";}&.", k, "-highlighted{>.", k, "-menu-item-title{color:", menu.light.item.hoverColor, ";}}&.", k, "-disabled{>.", k, "-menu-item-title{color:", menu.light.item.disabledColor, "!important;}}}.", k, "-menu-title{border-top:", menu.light.border, ";.", k, "-menu-name{color:", menu.light.title.color, ";}}.", k, "-menu-arrow-box{background:", menu.light.bgColor, ";border:", menu.light.border, ";border-left:none;&:hover{.", k, "-menu-arrow:before{color:", menu.light.active.color, ";}}}.", k, "-menu:not(.", k, "-dropdown-menu){background:", menu.light.bgColor, ";}&.", k, "-horizontal{.", k, "-menu-header{border-right:", menu.light.border, ";}.", k, "-menu-body>.", k, "-menu-title{border-right:", menu.light.border, ";}}.", k, "-menu-item.", k, "-active{>.", k, "-menu-item-title{color:", menu.light.active.color, "!important;background:", menu.light.active.bgColor, ";}}.", k, "-sub-menu{.", k, "-menu-item-title,.", k, "-menu-item-arrow{color:", menu.light.item.subTitleColor, "!important;}}}", _mapInstanceProperty(sizes).call(sizes, function (size) {
116
116
  var styles = menu[size];
117
117
  return /*#__PURE__*/css("&.", k, "-", size, "{width:", styles.width, ";font-size:", styles.fontSize, ";.", k, "-menu{font-size:", styles.fontSize, ";}.", k, "-menu-arrow-box{left:calc(", styles.width, " - 2px);}}");
118
- }), "&.", k, "-collapsed{width:calc(", menu.icon.width, " + (", getLeft(menu.item.padding), " + ", getLeft(menu.item.bodyPadding), ") * 2);.", k, "-icon{margin-right:0;}.", k, "-menu-item-arrow{display:none;}}&.", k, "-collapsed-arrow{width:0px;border-left:none;.", k, "-menu-header{padding:0;}.", k, "-menu-body{overflow:hidden;padding:0;}.", k, "-menu-arrow-box{left:0;.", k, "-menu-arrow:before{transform:rotateY(180deg);}}}&.", k, "-dropdown-menu{width:fit-content;min-width:", menu.dropdown.minWidth, ";.", k, "-menu-item-arrow{transform:rotate(-90deg);}}&.", k, "-horizontal{width:auto;display:flex;.", k, "-menu-body{display:flex;align-items:center;.", k, "-menu-title{border-top:none;border-right:", menu.border, ";}}}");
118
+ }), "&.", k, "-collapsed{width:calc(", menu.icon.width, " + (", getLeft(menu.item.padding), " + ", getLeft(menu.item.bodyPadding), ") * 2);.", k, "-icon{margin-right:0;}.", k, "-menu-item-arrow{display:none;}}&.", k, "-collapsed-arrow{width:0px;border-left:none;.", k, "-menu-header{padding:0;}.", k, "-menu-header{padding:0;}.", k, "-menu-body{overflow:hidden;padding:0;}.", k, "-menu-arrow-box{left:0;.", k, "-menu-arrow:before{transform:rotateY(180deg);}}}&.", k, "-dropdown-menu{width:fit-content;min-width:", menu.dropdown.minWidth, ";.", k, "-menu-item-arrow{transform:rotate(-90deg);}}&.", k, "-horizontal{width:auto;display:flex;.", k, "-menu-body{display:flex;align-items:center;.", k, "-menu-title{border-top:none;border-right:", menu.border, ";}}}");
119
119
  });
120
120
  export var makeTitleStyles = cache(function makeTitleStyles(k) {
121
121
  var item = menu.item;
@@ -51,6 +51,10 @@ export declare abstract class BaseSelect<T extends BaseSelectProps<any> = BaseSe
51
51
  };
52
52
  private focusout;
53
53
  private draggable;
54
+ immutable: {
55
+ immutableValues: State<any[]>;
56
+ isClosable: (key: string) => boolean;
57
+ };
54
58
  protected config: {
55
59
  cls: (name: string) => string;
56
60
  readonly k: string;
@@ -2,6 +2,8 @@ import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
2
2
  import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
3
3
  import _sliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/slice";
4
4
  import _spliceInstanceProperty from "@babel/runtime-corejs3/core-js/instance/splice";
5
+ import _filterInstanceProperty from "@babel/runtime-corejs3/core-js/instance/filter";
6
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js/instance/includes";
5
7
  import { __decorate } from "tslib";
6
8
  import { Component, provide, createRef } from 'intact';
7
9
  import template from './base.vdt';
@@ -14,6 +16,7 @@ import { useInput } from './useInput';
14
16
  import { useFocusout } from './useFocusout';
15
17
  import { isNullOrUndefined } from 'intact-shared';
16
18
  import { useDraggable } from './useDraggble';
19
+ import { useImmutable } from './useImmutable';
17
20
  import { useConfigContext } from '../config';
18
21
  var typeDefs = {
19
22
  value: null,
@@ -60,6 +63,7 @@ export var BaseSelect = /*#__PURE__*/function (_Component) {
60
63
  _this.input = useInput(_this.resetKeywords);
61
64
  _this.focusout = useFocusout();
62
65
  _this.draggable = useDraggable();
66
+ _this.immutable = useImmutable();
63
67
  _this.config = useConfigContext();
64
68
  return _this;
65
69
  }
@@ -104,7 +108,13 @@ export var BaseSelect = /*#__PURE__*/function (_Component) {
104
108
  };
105
109
  _proto.clear = function clear(e) {
106
110
  e.stopPropagation();
107
- this.set('value', this.get('multiple') ? [] : null);
111
+ var _this$get2 = this.get(),
112
+ value = _this$get2.value,
113
+ multiple = _this$get2.multiple;
114
+ var immutableValues = this.immutable.immutableValues.value;
115
+ this.set('value', multiple ? Array.isArray(value) ? _filterInstanceProperty(value).call(value, function (key) {
116
+ return _includesInstanceProperty(immutableValues).call(immutableValues, key);
117
+ }) : [] : null);
108
118
  };
109
119
  _proto.onKeydown = function onKeydown(e) {
110
120
  this.trigger('keydown', e);
@@ -57,6 +57,7 @@ export default function ($props, $blocks, $__proto__) {
57
57
  var _this$focusout = this.focusout,
58
58
  onFocusout = _this$focusout.onFocusout,
59
59
  triggerRef = _this$focusout.triggerRef;
60
+ var isClosable = this.immutable.isClosable;
60
61
  var filterInput = filterable ? _$cc(Input, {
61
62
  'className': _$cn(k + "-select-input"),
62
63
  'value': keywords,
@@ -139,7 +140,7 @@ export default function ($props, $blocks, $__proto__) {
139
140
  'children': _$ma(label, function ($label, $key) {
140
141
  return _$cc(Tag, {
141
142
  'key': isStringOrNumber($label) ? $label : isStringOrNumber(value[$key]) ? value[$key] : $key,
142
- 'closable': true,
143
+ 'closable': isClosable(value[$key]),
143
144
  'ev-close': this.delete.bind(this, $key),
144
145
  'disabled': disabled,
145
146
  'size': size,
@@ -0,0 +1,4 @@
1
+ export declare function useImmutable(): {
2
+ immutableValues: import("../../hooks/useState").State<any[]>;
3
+ isClosable: (key: string) => boolean;
4
+ };
@@ -0,0 +1,45 @@
1
+ import _includesInstanceProperty from "@babel/runtime-corejs3/core-js/instance/includes";
2
+ import { useInstance } from 'intact';
3
+ import { Option } from './option';
4
+ import { OptionGroup } from './group';
5
+ import { eachChildren, isComponentVNode } from '../utils';
6
+ import { useState } from '../../hooks/useState';
7
+ export function useImmutable() {
8
+ var instance = useInstance();
9
+ var immutableValues = useState([]);
10
+ function setImmutableValues() {
11
+ var _instance$get = instance.get(),
12
+ children = _instance$get.children,
13
+ multiple = _instance$get.multiple;
14
+ if (!multiple) return;
15
+ updateImmutableValues(children);
16
+ }
17
+ function updateImmutableValues(children) {
18
+ var _immutableValues = [];
19
+ var loop = function loop(children) {
20
+ eachChildren(children, function (vNode) {
21
+ if (isComponentVNode(vNode, Option)) {
22
+ var _vNode$props = vNode.props,
23
+ disabled = _vNode$props.disabled,
24
+ value = _vNode$props.value;
25
+ if (disabled) {
26
+ _immutableValues.push(value);
27
+ }
28
+ } else if (isComponentVNode(vNode, OptionGroup)) {
29
+ loop(vNode.props.children);
30
+ }
31
+ });
32
+ };
33
+ loop(children);
34
+ immutableValues.set(_immutableValues);
35
+ }
36
+ function isClosable(key) {
37
+ var _context;
38
+ return !_includesInstanceProperty(_context = immutableValues.value).call(_context, key);
39
+ }
40
+ instance.on('$receive:children', setImmutableValues);
41
+ return {
42
+ immutableValues: immutableValues,
43
+ isClosable: isClosable
44
+ };
45
+ }
package/es/index.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @king-design v3.4.3-beta.1
2
+ * @king-design v3.4.3-beta.2
3
3
  *
4
4
  * Copyright (c) Kingsoft Cloud
5
5
  * Released under the MIT License
@@ -64,4 +64,4 @@ export * from './components/treeSelect';
64
64
  export * from './components/upload';
65
65
  export * from './components/view';
66
66
  export * from './components/wave';
67
- export declare const version = "3.4.3-beta.1";
67
+ export declare const version = "3.4.3-beta.2";
package/es/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @king-design v3.4.3-beta.1
2
+ * @king-design v3.4.3-beta.2
3
3
  *
4
4
  * Copyright (c) Kingsoft Cloud
5
5
  * Released under the MIT License
@@ -65,5 +65,5 @@ export * from './components/treeSelect';
65
65
  export * from './components/upload';
66
66
  export * from './components/view';
67
67
  export * from './components/wave';
68
- export var version = '3.4.3-beta.1';
68
+ export var version = '3.4.3-beta.2';
69
69
  /* generate end */
@@ -0,0 +1,9 @@
1
+ export { default as data } from './index.json';
2
+ import { Component } from 'intact';
3
+ interface Props {
4
+ day?: string[];
5
+ }
6
+ export default class extends Component {
7
+ static template: string | import("intact").Template<any>;
8
+ static defaults(): Props;
9
+ }
@@ -0,0 +1,18 @@
1
+ import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
2
+ export { default as data } from './index.json';
3
+ import { Component } from 'intact';
4
+ import template from './index.vdt';
5
+ var default_1 = /*#__PURE__*/function (_Component) {
6
+ _inheritsLoose(default_1, _Component);
7
+ function default_1() {
8
+ return _Component.apply(this, arguments) || this;
9
+ }
10
+ default_1.defaults = function defaults() {
11
+ return {
12
+ day: ['Tuesday', 'Sunday', 'Wednesday']
13
+ };
14
+ };
15
+ return default_1;
16
+ }(Component);
17
+ default_1.template = template;
18
+ export { default_1 as default };
@@ -0,0 +1,9 @@
1
+ import React from 'react';
2
+ interface Props {
3
+ day?: string[];
4
+ }
5
+ export default class Demo extends React.Component<{}, Props> {
6
+ state: Props;
7
+ render(): React.JSX.Element;
8
+ }
9
+ export {};
@@ -0,0 +1,53 @@
1
+ import _inheritsLoose from "@babel/runtime-corejs3/helpers/inheritsLoose";
2
+ import _concatInstanceProperty from "@babel/runtime-corejs3/core-js/instance/concat";
3
+ import _JSON$stringify from "@babel/runtime-corejs3/core-js/json/stringify";
4
+ import React from 'react';
5
+ import { Select, Option } from '@king-design/react';
6
+ var Demo = /*#__PURE__*/function (_React$Component) {
7
+ _inheritsLoose(Demo, _React$Component);
8
+ function Demo() {
9
+ var _context;
10
+ var _this;
11
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
12
+ args[_key] = arguments[_key];
13
+ }
14
+ _this = _React$Component.call.apply(_React$Component, _concatInstanceProperty(_context = [this]).call(_context, args)) || this;
15
+ _this.state = {
16
+ day: ['Tuesday', 'Sunday', 'Wednesday']
17
+ };
18
+ return _this;
19
+ }
20
+ var _proto = Demo.prototype;
21
+ _proto.render = function render() {
22
+ var _this2 = this;
23
+ return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement(Select, {
24
+ value: this.state.day,
25
+ onChangeValue: function onChangeValue(day) {
26
+ return _this2.setState({
27
+ day: day
28
+ });
29
+ },
30
+ multiple: true,
31
+ filterable: true,
32
+ clearable: true
33
+ }, /*#__PURE__*/React.createElement(Option, {
34
+ value: "Monday"
35
+ }, "\u661F\u671F\u4E00"), /*#__PURE__*/React.createElement(Option, {
36
+ value: "Tuesday",
37
+ disabled: true
38
+ }, "\u661F\u671F\u4E8C"), /*#__PURE__*/React.createElement(Option, {
39
+ value: "Wednesday"
40
+ }, "\u661F\u671F\u4E09"), /*#__PURE__*/React.createElement(Option, {
41
+ value: "Thursday"
42
+ }, "\u661F\u671F\u56DB"), /*#__PURE__*/React.createElement(Option, {
43
+ value: "Friday",
44
+ disabled: true
45
+ }, "\u661F\u671F\u4E94"), /*#__PURE__*/React.createElement(Option, {
46
+ value: "Saturday"
47
+ }, "\u661F\u671F\u516D"), /*#__PURE__*/React.createElement(Option, {
48
+ value: "Sunday"
49
+ }, "\u661F\u671F\u5929")), "You selected: ", _JSON$stringify(this.state.day));
50
+ };
51
+ return Demo;
52
+ }(React.Component);
53
+ export { Demo as default };
package/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  /*!
2
- * @king-design v3.4.3-beta.1
2
+ * @king-design v3.4.3-beta.2
3
3
  *
4
4
  * Copyright (c) Kingsoft Cloud
5
5
  * Released under the MIT License
@@ -69,6 +69,6 @@ export * from './components/upload';
69
69
  export * from './components/view';
70
70
  export * from './components/wave';
71
71
 
72
- export const version = '3.4.3-beta.1';
72
+ export const version = '3.4.3-beta.2';
73
73
 
74
74
  /* generate end */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@king-design/intact",
3
- "version": "3.4.3-beta.1",
3
+ "version": "3.4.3-beta.2",
4
4
  "description": "A component library written in Intact for Intact, Vue, React and Angular",
5
5
  "main": "es/index.js",
6
6
  "engines": {