musae 0.3.0 → 0.3.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.
- package/dist/components/date-picker/hooks.d.ts +1 -1
- package/dist/components/date-range-picker/hooks.d.ts +1 -1
- package/dist/components/form/hooks.d.ts +3 -2
- package/dist/components/icon/icons/action/index.cjs +18 -1
- package/dist/components/icon/icons/action/index.d.ts +16 -0
- package/dist/components/icon/icons/action/index.mjs +31 -13
- package/dist/components/icon/icons/alert/index.cjs +12 -1
- package/dist/components/icon/icons/alert/index.d.ts +10 -0
- package/dist/components/icon/icons/alert/index.mjs +19 -7
- package/dist/components/icon/icons/content/index.cjs +10 -1
- package/dist/components/icon/icons/content/index.d.ts +8 -0
- package/dist/components/icon/icons/content/index.mjs +15 -5
- package/dist/components/icon/icons/editor/index.cjs +14 -1
- package/dist/components/icon/icons/editor/index.d.ts +12 -0
- package/dist/components/icon/icons/editor/index.mjs +23 -9
- package/dist/components/icon/icons/hardware/index.cjs +11 -1
- package/dist/components/icon/icons/hardware/index.d.ts +9 -0
- package/dist/components/icon/icons/hardware/index.mjs +17 -6
- package/dist/components/icon/icons/image/index.cjs +16 -1
- package/dist/components/icon/icons/image/index.d.ts +14 -0
- package/dist/components/icon/icons/image/index.mjs +27 -11
- package/dist/components/icon/icons/mock/index.cjs +7 -1
- package/dist/components/icon/icons/mock/index.d.ts +5 -0
- package/dist/components/icon/icons/mock/index.mjs +9 -2
- package/dist/components/icon/icons/navigation/index.cjs +10 -1
- package/dist/components/icon/icons/navigation/index.d.ts +8 -0
- package/dist/components/icon/icons/navigation/index.mjs +15 -5
- package/dist/components/icon/icons/toggle/index.cjs +8 -1
- package/dist/components/icon/icons/toggle/index.d.ts +6 -0
- package/dist/components/icon/icons/toggle/index.mjs +11 -3
- package/dist/components/pagination/hooks.cjs +24 -15
- package/dist/components/pagination/hooks.d.ts +7 -4
- package/dist/components/pagination/hooks.mjs +25 -16
- package/dist/components/pagination/item.cjs +9 -9
- package/dist/components/pagination/item.d.ts +2 -2
- package/dist/components/pagination/item.mjs +9 -9
- package/dist/components/pagination/pagination.cjs +16 -10
- package/dist/components/pagination/pagination.d.ts +2 -2
- package/dist/components/pagination/pagination.mjs +16 -10
- package/dist/components/picker/context.d.ts +1 -1
- package/dist/components/picker/index.d.ts +1 -2
- package/dist/components/picker/picker.cjs +4 -2
- package/dist/components/picker/picker.d.ts +1 -1
- package/dist/components/picker/picker.mjs +4 -2
- package/dist/components/rich-text-editor/dropdown.d.ts +1 -1
- package/dist/components/rich-text-editor/index.cjs +6 -3
- package/dist/components/rich-text-editor/index.d.ts +9 -2
- package/dist/components/rich-text-editor/index.mjs +7 -4
- package/dist/components/rich-text-editor/plugins/controlled-state/index.cjs +13 -5
- package/dist/components/rich-text-editor/plugins/controlled-state/index.d.ts +6 -3
- package/dist/components/rich-text-editor/plugins/controlled-state/index.mjs +14 -6
- package/dist/components/rich-text-editor/rich-text-editor.cjs +16 -5
- package/dist/components/rich-text-editor/rich-text-editor.d.ts +9 -2
- package/dist/components/rich-text-editor/rich-text-editor.mjs +17 -6
- package/dist/components/select/hooks.cjs +25 -50
- package/dist/components/select/hooks.d.ts +3 -3
- package/dist/components/select/hooks.mjs +26 -51
- package/dist/components/select/select.cjs +11 -5
- package/dist/components/select/select.d.ts +2 -2
- package/dist/components/select/select.mjs +11 -5
- package/dist/components/select/selections.d.ts +1 -1
- package/dist/components/select/selector.cjs +25 -13
- package/dist/components/select/selector.d.ts +1 -1
- package/dist/components/select/selector.mjs +25 -13
- package/dist/components/select/utils.d.ts +1 -1
- package/dist/components/table/header/cell.cjs +6 -7
- package/dist/components/table/header/cell.mjs +7 -8
- package/dist/components/table/hooks.cjs +3 -2
- package/dist/components/table/hooks.d.ts +2 -2
- package/dist/components/table/hooks.mjs +3 -2
- package/dist/components/time-picker/hooks.d.ts +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.mjs +1 -1
- package/dist/types/form.d.ts +5 -0
- package/dist/{components/pagination/types.d.ts → types/pagination.d.ts} +20 -9
- package/dist/{components/picker/types.d.ts → types/picker.d.ts} +2 -2
- package/dist/{components/rich-text-editor/types.d.ts → types/rich-text-editor.d.ts} +15 -0
- package/dist/{components/select/types.d.ts → types/select.d.ts} +9 -3
- package/dist/types/table.d.ts +9 -4
- package/package.json +3 -3
- package/dist/components/pagination/types.cjs +0 -11
- package/dist/components/pagination/types.mjs +0 -13
|
@@ -8,21 +8,24 @@ var LexicalOnChangePlugin = require('@lexical/react/LexicalOnChangePlugin');
|
|
|
8
8
|
var markdown = require('@lexical/markdown');
|
|
9
9
|
var index = require('../markdown-shortcut/index.cjs');
|
|
10
10
|
|
|
11
|
-
var ControlledStatePlugin = function
|
|
11
|
+
var ControlledStatePlugin = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
12
12
|
var value = _ref.value,
|
|
13
13
|
_use = _ref.use,
|
|
14
14
|
onChange = _ref.onChange;
|
|
15
15
|
var _useLexicalComposerCo = LexicalComposerContext.useLexicalComposerContext(),
|
|
16
16
|
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
17
17
|
editor = _useLexicalComposerCo2[0];
|
|
18
|
-
|
|
19
|
-
if (relax.isUndefined(value)) return;
|
|
18
|
+
var setValue = React.useCallback(function (_value) {
|
|
20
19
|
try {
|
|
21
|
-
var editorState = editor.parseEditorState(
|
|
20
|
+
var editorState = editor.parseEditorState(_value);
|
|
22
21
|
editor.setEditorState(editorState);
|
|
23
22
|
} catch (error) {
|
|
24
23
|
console.error(error);
|
|
25
24
|
}
|
|
25
|
+
}, [editor]);
|
|
26
|
+
relax.useUpdateEffect(function () {
|
|
27
|
+
if (relax.isUndefined(value)) return;
|
|
28
|
+
setValue(value);
|
|
26
29
|
}, [value, editor]);
|
|
27
30
|
var change = relax.useEvent(function (state, editor) {
|
|
28
31
|
var _value = JSON.stringify(state.toJSON());
|
|
@@ -37,9 +40,14 @@ var ControlledStatePlugin = function ControlledStatePlugin(_ref) {
|
|
|
37
40
|
onChange === null || onChange === void 0 || onChange(markdown$1);
|
|
38
41
|
});
|
|
39
42
|
});
|
|
43
|
+
React.useImperativeHandle(ref, function () {
|
|
44
|
+
return {
|
|
45
|
+
setValue: setValue
|
|
46
|
+
};
|
|
47
|
+
});
|
|
40
48
|
return /*#__PURE__*/React.createElement(LexicalOnChangePlugin.OnChangePlugin, {
|
|
41
49
|
onChange: change
|
|
42
50
|
});
|
|
43
|
-
};
|
|
51
|
+
});
|
|
44
52
|
|
|
45
53
|
exports.default = ControlledStatePlugin;
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type { Use } from "
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { Use } from "../../../../types/rich-text-editor";
|
|
3
3
|
interface Props {
|
|
4
4
|
value?: string;
|
|
5
5
|
onChange?: (value: string) => void;
|
|
6
6
|
use: Use;
|
|
7
7
|
}
|
|
8
|
-
|
|
8
|
+
export type Ref = {
|
|
9
|
+
setValue: (value: string) => void;
|
|
10
|
+
};
|
|
11
|
+
declare const ControlledStatePlugin: React.ForwardRefExoticComponent<Props & React.RefAttributes<Ref>>;
|
|
9
12
|
export default ControlledStatePlugin;
|
|
@@ -1,26 +1,29 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
|
-
import React from 'react';
|
|
2
|
+
import React, { forwardRef, useCallback, useImperativeHandle } from 'react';
|
|
3
3
|
import { useUpdateEffect, isUndefined, useEvent } from '@aiszlab/relax';
|
|
4
4
|
import { useLexicalComposerContext } from '@lexical/react/LexicalComposerContext';
|
|
5
5
|
import { OnChangePlugin } from '@lexical/react/LexicalOnChangePlugin';
|
|
6
6
|
import { $convertToMarkdownString } from '@lexical/markdown';
|
|
7
7
|
import { TRANSFORMERS } from '../markdown-shortcut/index.mjs';
|
|
8
8
|
|
|
9
|
-
var ControlledStatePlugin = function
|
|
9
|
+
var ControlledStatePlugin = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
10
10
|
var value = _ref.value,
|
|
11
11
|
_use = _ref.use,
|
|
12
12
|
onChange = _ref.onChange;
|
|
13
13
|
var _useLexicalComposerCo = useLexicalComposerContext(),
|
|
14
14
|
_useLexicalComposerCo2 = _slicedToArray(_useLexicalComposerCo, 1),
|
|
15
15
|
editor = _useLexicalComposerCo2[0];
|
|
16
|
-
|
|
17
|
-
if (isUndefined(value)) return;
|
|
16
|
+
var setValue = useCallback(function (_value) {
|
|
18
17
|
try {
|
|
19
|
-
var editorState = editor.parseEditorState(
|
|
18
|
+
var editorState = editor.parseEditorState(_value);
|
|
20
19
|
editor.setEditorState(editorState);
|
|
21
20
|
} catch (error) {
|
|
22
21
|
console.error(error);
|
|
23
22
|
}
|
|
23
|
+
}, [editor]);
|
|
24
|
+
useUpdateEffect(function () {
|
|
25
|
+
if (isUndefined(value)) return;
|
|
26
|
+
setValue(value);
|
|
24
27
|
}, [value, editor]);
|
|
25
28
|
var change = useEvent(function (state, editor) {
|
|
26
29
|
var _value = JSON.stringify(state.toJSON());
|
|
@@ -35,9 +38,14 @@ var ControlledStatePlugin = function ControlledStatePlugin(_ref) {
|
|
|
35
38
|
onChange === null || onChange === void 0 || onChange(markdown);
|
|
36
39
|
});
|
|
37
40
|
});
|
|
41
|
+
useImperativeHandle(ref, function () {
|
|
42
|
+
return {
|
|
43
|
+
setValue: setValue
|
|
44
|
+
};
|
|
45
|
+
});
|
|
38
46
|
return /*#__PURE__*/React.createElement(OnChangePlugin, {
|
|
39
47
|
onChange: change
|
|
40
48
|
});
|
|
41
|
-
};
|
|
49
|
+
});
|
|
42
50
|
|
|
43
51
|
export { ControlledStatePlugin as default };
|
|
@@ -31,7 +31,7 @@ require('../checkbox/index.cjs');
|
|
|
31
31
|
var markdown = require('@lexical/markdown');
|
|
32
32
|
var styles$1 = require('../checkbox/styles.cjs');
|
|
33
33
|
|
|
34
|
-
var _excluded = ["placeholder", "disabled", "defaultValue", "onChange"];
|
|
34
|
+
var _excluded = ["placeholder", "disabled", "defaultValue", "onChange", "value"];
|
|
35
35
|
var styles = {
|
|
36
36
|
shell: function shell(props) {
|
|
37
37
|
return [{
|
|
@@ -73,14 +73,15 @@ var styles = {
|
|
|
73
73
|
$$css: true
|
|
74
74
|
}
|
|
75
75
|
};
|
|
76
|
-
var RichTextEditor = function
|
|
76
|
+
var RichTextEditor = /*#__PURE__*/React.forwardRef(function (_ref, ref) {
|
|
77
77
|
var _props$ariaPlacehold;
|
|
78
78
|
var placeholder = _ref.placeholder,
|
|
79
79
|
_ref$disabled = _ref.disabled,
|
|
80
80
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
81
81
|
defaultValue = _ref.defaultValue,
|
|
82
|
-
onChange = _ref.onChange
|
|
83
|
-
|
|
82
|
+
onChange = _ref.onChange;
|
|
83
|
+
_ref.value;
|
|
84
|
+
var props = _objectWithoutProperties(_ref, _excluded);
|
|
84
85
|
var _useIdentity = relax.useIdentity(),
|
|
85
86
|
_useIdentity2 = _slicedToArray(_useIdentity, 1),
|
|
86
87
|
id = _useIdentity2[0];
|
|
@@ -93,6 +94,7 @@ var RichTextEditor = function RichTextEditor(_ref) {
|
|
|
93
94
|
var _props$use;
|
|
94
95
|
return (_props$use = props.use) !== null && _props$use !== void 0 ? _props$use : "serialized";
|
|
95
96
|
});
|
|
97
|
+
var controlledStatePluginRef = React.useRef(null);
|
|
96
98
|
var styled = {
|
|
97
99
|
shell: stylex.default.props(styles.shell({
|
|
98
100
|
backgroundColor: theme$1.colors[colors.ColorToken.SurfaceContainer]
|
|
@@ -182,6 +184,14 @@ var RichTextEditor = function RichTextEditor(_ref) {
|
|
|
182
184
|
}
|
|
183
185
|
};
|
|
184
186
|
});
|
|
187
|
+
React.useImperativeHandle(ref, function () {
|
|
188
|
+
return {
|
|
189
|
+
setValue: function setValue(_value) {
|
|
190
|
+
var _controlledStatePlugi;
|
|
191
|
+
(_controlledStatePlugi = controlledStatePluginRef.current) === null || _controlledStatePlugi === void 0 || _controlledStatePlugi.setValue(_value);
|
|
192
|
+
}
|
|
193
|
+
};
|
|
194
|
+
});
|
|
185
195
|
return /*#__PURE__*/React.createElement(LexicalComposer.LexicalComposer, {
|
|
186
196
|
initialConfig: initialConfig
|
|
187
197
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -201,9 +211,10 @@ var RichTextEditor = function RichTextEditor(_ref) {
|
|
|
201
211
|
disabled: !disabled,
|
|
202
212
|
newTab: true
|
|
203
213
|
}), /*#__PURE__*/React.createElement(LexicalListPlugin.ListPlugin, null), /*#__PURE__*/React.createElement(index$2.default, null), /*#__PURE__*/React.createElement(index$3.default, {
|
|
214
|
+
ref: controlledStatePluginRef,
|
|
204
215
|
use: _use,
|
|
205
216
|
onChange: onChange
|
|
206
217
|
}), holder));
|
|
207
|
-
};
|
|
218
|
+
});
|
|
208
219
|
|
|
209
220
|
exports.default = RichTextEditor;
|
|
@@ -1,4 +1,11 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type {
|
|
3
|
-
declare const RichTextEditor:
|
|
2
|
+
import type { RichTextEditorRef } from "musae/types/rich-text-editor";
|
|
3
|
+
declare const RichTextEditor: React.ForwardRefExoticComponent<Pick<React.HTMLAttributes<HTMLDivElement>, "aria-placeholder"> & {
|
|
4
|
+
placeholder?: import("@lexical/react/LexicalContentEditable").Props["placeholder"];
|
|
5
|
+
disabled?: boolean;
|
|
6
|
+
defaultValue?: string;
|
|
7
|
+
use?: import("musae/types/rich-text-editor").Use;
|
|
8
|
+
onChange?: (value: string) => void;
|
|
9
|
+
value?: string;
|
|
10
|
+
} & React.RefAttributes<RichTextEditorRef>>;
|
|
4
11
|
export default RichTextEditor;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
2
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
|
-
import React from 'react';
|
|
3
|
+
import React, { forwardRef, useRef, useImperativeHandle } from 'react';
|
|
4
4
|
import { LexicalComposer } from '@lexical/react/LexicalComposer';
|
|
5
5
|
import { ContentEditable } from '@lexical/react/LexicalContentEditable';
|
|
6
6
|
import { LexicalErrorBoundary } from '@lexical/react/LexicalErrorBoundary';
|
|
@@ -29,7 +29,7 @@ import '../checkbox/index.mjs';
|
|
|
29
29
|
import { $convertFromMarkdownString } from '@lexical/markdown';
|
|
30
30
|
import styles$1 from '../checkbox/styles.mjs';
|
|
31
31
|
|
|
32
|
-
var _excluded = ["placeholder", "disabled", "defaultValue", "onChange"];
|
|
32
|
+
var _excluded = ["placeholder", "disabled", "defaultValue", "onChange", "value"];
|
|
33
33
|
var styles = {
|
|
34
34
|
shell: function shell(props) {
|
|
35
35
|
return [{
|
|
@@ -71,14 +71,15 @@ var styles = {
|
|
|
71
71
|
$$css: true
|
|
72
72
|
}
|
|
73
73
|
};
|
|
74
|
-
var RichTextEditor = function
|
|
74
|
+
var RichTextEditor = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
75
75
|
var _props$ariaPlacehold;
|
|
76
76
|
var placeholder = _ref.placeholder,
|
|
77
77
|
_ref$disabled = _ref.disabled,
|
|
78
78
|
disabled = _ref$disabled === void 0 ? false : _ref$disabled,
|
|
79
79
|
defaultValue = _ref.defaultValue,
|
|
80
|
-
onChange = _ref.onChange
|
|
81
|
-
|
|
80
|
+
onChange = _ref.onChange;
|
|
81
|
+
_ref.value;
|
|
82
|
+
var props = _objectWithoutProperties(_ref, _excluded);
|
|
82
83
|
var _useIdentity = useIdentity(),
|
|
83
84
|
_useIdentity2 = _slicedToArray(_useIdentity, 1),
|
|
84
85
|
id = _useIdentity2[0];
|
|
@@ -91,6 +92,7 @@ var RichTextEditor = function RichTextEditor(_ref) {
|
|
|
91
92
|
var _props$use;
|
|
92
93
|
return (_props$use = props.use) !== null && _props$use !== void 0 ? _props$use : "serialized";
|
|
93
94
|
});
|
|
95
|
+
var controlledStatePluginRef = useRef(null);
|
|
94
96
|
var styled = {
|
|
95
97
|
shell: _stylex.props(styles.shell({
|
|
96
98
|
backgroundColor: theme.colors[ColorToken.SurfaceContainer]
|
|
@@ -180,6 +182,14 @@ var RichTextEditor = function RichTextEditor(_ref) {
|
|
|
180
182
|
}
|
|
181
183
|
};
|
|
182
184
|
});
|
|
185
|
+
useImperativeHandle(ref, function () {
|
|
186
|
+
return {
|
|
187
|
+
setValue: function setValue(_value) {
|
|
188
|
+
var _controlledStatePlugi;
|
|
189
|
+
(_controlledStatePlugi = controlledStatePluginRef.current) === null || _controlledStatePlugi === void 0 || _controlledStatePlugi.setValue(_value);
|
|
190
|
+
}
|
|
191
|
+
};
|
|
192
|
+
});
|
|
183
193
|
return /*#__PURE__*/React.createElement(LexicalComposer, {
|
|
184
194
|
initialConfig: initialConfig
|
|
185
195
|
}, /*#__PURE__*/React.createElement("div", {
|
|
@@ -199,9 +209,10 @@ var RichTextEditor = function RichTextEditor(_ref) {
|
|
|
199
209
|
disabled: !disabled,
|
|
200
210
|
newTab: true
|
|
201
211
|
}), /*#__PURE__*/React.createElement(ListPlugin, null), /*#__PURE__*/React.createElement(CheckListPlugin, null), /*#__PURE__*/React.createElement(ControlledStatePlugin, {
|
|
212
|
+
ref: controlledStatePluginRef,
|
|
202
213
|
use: _use,
|
|
203
214
|
onChange: onChange
|
|
204
215
|
}), holder));
|
|
205
|
-
};
|
|
216
|
+
});
|
|
206
217
|
|
|
207
218
|
export { RichTextEditor as default };
|
|
@@ -4,8 +4,7 @@ var React = require('react');
|
|
|
4
4
|
var relax = require('@aiszlab/relax');
|
|
5
5
|
var utils = require('./utils.cjs');
|
|
6
6
|
|
|
7
|
-
var _excluded = ["mode", "close", "isComplex", "readableOptions"]
|
|
8
|
-
_excluded2 = ["options", "onSearch"];
|
|
7
|
+
var _excluded = ["mode", "close", "isComplex", "readableOptions", "onChange"];
|
|
9
8
|
/**
|
|
10
9
|
* @description
|
|
11
10
|
* use value
|
|
@@ -15,15 +14,15 @@ var useValue = function useValue(_ref) {
|
|
|
15
14
|
close = _ref.close,
|
|
16
15
|
isComplex = _ref.isComplex,
|
|
17
16
|
readableOptions = _ref.readableOptions,
|
|
17
|
+
_onChange = _ref.onChange,
|
|
18
18
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
19
|
-
var isControlled = !relax.isUndefined(props.value);
|
|
20
19
|
var _useControlledState = relax.useControlledState(props.value),
|
|
21
20
|
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
22
21
|
value = _useControlledState2[0],
|
|
23
22
|
setValue = _useControlledState2[1];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
// convert prop value into a map
|
|
24
|
+
// in this component, only use map for controlled state
|
|
25
|
+
// only effect by value change
|
|
27
26
|
var readableValues = React.useMemo(function () {
|
|
28
27
|
return utils.toValues(value).reduce(function (prev, _value) {
|
|
29
28
|
var _ref2, _value$label;
|
|
@@ -44,11 +43,7 @@ var useValue = function useValue(_ref) {
|
|
|
44
43
|
close();
|
|
45
44
|
// same value, do not toggle again
|
|
46
45
|
if (readableValues.has(key)) return;
|
|
47
|
-
|
|
48
|
-
var _props$onChange;
|
|
49
|
-
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, isComplex ? _value : key);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
46
|
+
_onChange === null || _onChange === void 0 || _onChange(isComplex ? _value : key);
|
|
52
47
|
setValue(_value);
|
|
53
48
|
return;
|
|
54
49
|
}
|
|
@@ -58,28 +53,17 @@ var useValue = function useValue(_ref) {
|
|
|
58
53
|
var prev = new Map(readableValues);
|
|
59
54
|
var isRemoved = prev.has(key) && prev["delete"](key);
|
|
60
55
|
var next = isRemoved ? prev : prev.set(key, _value.label);
|
|
61
|
-
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
value = _ref4[0],
|
|
66
|
-
label = _ref4[1];
|
|
67
|
-
return {
|
|
68
|
-
value: value,
|
|
69
|
-
label: label
|
|
70
|
-
};
|
|
71
|
-
}) : Array.from(next.keys()));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
setValue(Array.from(next.entries()).map(function (_ref5) {
|
|
75
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
76
|
-
value = _ref6[0],
|
|
77
|
-
label = _ref6[1];
|
|
56
|
+
var _changedValues = isComplex ? Array.from(next.entries()).map(function (_ref3) {
|
|
57
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
58
|
+
value = _ref4[0],
|
|
59
|
+
label = _ref4[1];
|
|
78
60
|
return {
|
|
79
61
|
value: value,
|
|
80
62
|
label: label
|
|
81
63
|
};
|
|
82
|
-
}));
|
|
64
|
+
}) : Array.from(next.keys());
|
|
65
|
+
_onChange === null || _onChange === void 0 || _onChange(_changedValues);
|
|
66
|
+
setValue(_changedValues);
|
|
83
67
|
});
|
|
84
68
|
return {
|
|
85
69
|
value: value,
|
|
@@ -91,36 +75,27 @@ var useValue = function useValue(_ref) {
|
|
|
91
75
|
* @description
|
|
92
76
|
* options
|
|
93
77
|
*/
|
|
94
|
-
var useOptions = function useOptions(
|
|
95
|
-
var options =
|
|
96
|
-
onSearch =
|
|
97
|
-
|
|
78
|
+
var useOptions = function useOptions(_ref5) {
|
|
79
|
+
var options = _ref5.options,
|
|
80
|
+
onSearch = _ref5.onSearch,
|
|
81
|
+
onFilter = _ref5.onFilter;
|
|
98
82
|
var _useState = React.useState(""),
|
|
99
83
|
_useState2 = _slicedToArray(_useState, 2),
|
|
100
84
|
searched = _useState2[0],
|
|
101
85
|
setSearched = _useState2[1];
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
86
|
+
var filter = relax.useEvent(function (option) {
|
|
87
|
+
if (!searched) return true;
|
|
88
|
+
if (relax.isNull(onFilter) || onFilter === false) return true;
|
|
89
|
+
if (relax.isFunction(onFilter)) return onFilter(searched, option);
|
|
90
|
+
var regExp = new RegExp(searched, "i");
|
|
91
|
+
return regExp.test(option.value.toString()) || !!(option.label && regExp.test(option.label));
|
|
105
92
|
});
|
|
106
|
-
|
|
107
|
-
if (!searched) return null;
|
|
108
|
-
var onFilter = onFilterGetter();
|
|
109
|
-
if (!onFilter) return null;
|
|
110
|
-
if (relax.isFunction(onFilter)) return function (option) {
|
|
111
|
-
return onFilter(searched, option);
|
|
112
|
-
};
|
|
113
|
-
return function (option) {
|
|
114
|
-
var _option$label;
|
|
115
|
-
return !!((_option$label = option.label) !== null && _option$label !== void 0 && _option$label.includes(searched));
|
|
116
|
-
};
|
|
117
|
-
}, [searched, onFilterGetter]);
|
|
118
|
-
/// wrapper search handler, set react state
|
|
93
|
+
// wrapper search handler, set react state
|
|
119
94
|
var search = relax.useEvent(function (searched) {
|
|
120
95
|
setSearched(searched);
|
|
121
96
|
onSearch === null || onSearch === void 0 || onSearch(searched);
|
|
122
97
|
});
|
|
123
|
-
|
|
98
|
+
// reset search value
|
|
124
99
|
var reset = relax.useEvent(function () {
|
|
125
100
|
return setSearched("");
|
|
126
101
|
});
|
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { type Key } from "react";
|
|
2
|
-
import type { Mode, ReadableOptions, SelectProps, ValueOrValues } from "
|
|
2
|
+
import type { Mode, ReadableOptions, SelectProps, ValueOrValues } from "../../types/select";
|
|
3
3
|
import type { Option } from "musae/types/option";
|
|
4
4
|
/**
|
|
5
5
|
* @description
|
|
6
6
|
* use value
|
|
7
7
|
*/
|
|
8
|
-
export declare const useValue: <T extends ValueOrValues = ValueOrValues>({ mode, close, isComplex, readableOptions, ...props }: {
|
|
8
|
+
export declare const useValue: <T extends ValueOrValues = ValueOrValues>({ mode, close, isComplex, readableOptions, onChange: _onChange, ...props }: {
|
|
9
9
|
value: ValueOrValues | undefined;
|
|
10
10
|
readableOptions: ReadableOptions;
|
|
11
11
|
mode: Mode | undefined;
|
|
@@ -22,7 +22,7 @@ export declare const useValue: <T extends ValueOrValues = ValueOrValues>({ mode,
|
|
|
22
22
|
* @description
|
|
23
23
|
* options
|
|
24
24
|
*/
|
|
25
|
-
export declare const useOptions: ({ options, onSearch,
|
|
25
|
+
export declare const useOptions: ({ options, onSearch, onFilter, }: {
|
|
26
26
|
options: Option[];
|
|
27
27
|
onFilter: SelectProps["onFilter"];
|
|
28
28
|
onSearch: SelectProps["onSearch"];
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import _slicedToArray from '@babel/runtime/helpers/slicedToArray';
|
|
2
2
|
import _objectWithoutProperties from '@babel/runtime/helpers/objectWithoutProperties';
|
|
3
3
|
import { useMemo, useState } from 'react';
|
|
4
|
-
import {
|
|
4
|
+
import { useControlledState, useEvent, isNull, isFunction } from '@aiszlab/relax';
|
|
5
5
|
import { toValues, toKey, readOptions as _readOptions, toMenuItems } from './utils.mjs';
|
|
6
6
|
|
|
7
|
-
var _excluded = ["mode", "close", "isComplex", "readableOptions"]
|
|
8
|
-
_excluded2 = ["options", "onSearch"];
|
|
7
|
+
var _excluded = ["mode", "close", "isComplex", "readableOptions", "onChange"];
|
|
9
8
|
/**
|
|
10
9
|
* @description
|
|
11
10
|
* use value
|
|
@@ -15,15 +14,15 @@ var useValue = function useValue(_ref) {
|
|
|
15
14
|
close = _ref.close,
|
|
16
15
|
isComplex = _ref.isComplex,
|
|
17
16
|
readableOptions = _ref.readableOptions,
|
|
17
|
+
_onChange = _ref.onChange,
|
|
18
18
|
props = _objectWithoutProperties(_ref, _excluded);
|
|
19
|
-
var isControlled = !isUndefined(props.value);
|
|
20
19
|
var _useControlledState = useControlledState(props.value),
|
|
21
20
|
_useControlledState2 = _slicedToArray(_useControlledState, 2),
|
|
22
21
|
value = _useControlledState2[0],
|
|
23
22
|
setValue = _useControlledState2[1];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
// convert prop value into a map
|
|
24
|
+
// in this component, only use map for controlled state
|
|
25
|
+
// only effect by value change
|
|
27
26
|
var readableValues = useMemo(function () {
|
|
28
27
|
return toValues(value).reduce(function (prev, _value) {
|
|
29
28
|
var _ref2, _value$label;
|
|
@@ -44,11 +43,7 @@ var useValue = function useValue(_ref) {
|
|
|
44
43
|
close();
|
|
45
44
|
// same value, do not toggle again
|
|
46
45
|
if (readableValues.has(key)) return;
|
|
47
|
-
|
|
48
|
-
var _props$onChange;
|
|
49
|
-
(_props$onChange = props.onChange) === null || _props$onChange === void 0 || _props$onChange.call(props, isComplex ? _value : key);
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
46
|
+
_onChange === null || _onChange === void 0 || _onChange(isComplex ? _value : key);
|
|
52
47
|
setValue(_value);
|
|
53
48
|
return;
|
|
54
49
|
}
|
|
@@ -58,28 +53,17 @@ var useValue = function useValue(_ref) {
|
|
|
58
53
|
var prev = new Map(readableValues);
|
|
59
54
|
var isRemoved = prev.has(key) && prev["delete"](key);
|
|
60
55
|
var next = isRemoved ? prev : prev.set(key, _value.label);
|
|
61
|
-
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
value = _ref4[0],
|
|
66
|
-
label = _ref4[1];
|
|
67
|
-
return {
|
|
68
|
-
value: value,
|
|
69
|
-
label: label
|
|
70
|
-
};
|
|
71
|
-
}) : Array.from(next.keys()));
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
setValue(Array.from(next.entries()).map(function (_ref5) {
|
|
75
|
-
var _ref6 = _slicedToArray(_ref5, 2),
|
|
76
|
-
value = _ref6[0],
|
|
77
|
-
label = _ref6[1];
|
|
56
|
+
var _changedValues = isComplex ? Array.from(next.entries()).map(function (_ref3) {
|
|
57
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
58
|
+
value = _ref4[0],
|
|
59
|
+
label = _ref4[1];
|
|
78
60
|
return {
|
|
79
61
|
value: value,
|
|
80
62
|
label: label
|
|
81
63
|
};
|
|
82
|
-
}));
|
|
64
|
+
}) : Array.from(next.keys());
|
|
65
|
+
_onChange === null || _onChange === void 0 || _onChange(_changedValues);
|
|
66
|
+
setValue(_changedValues);
|
|
83
67
|
});
|
|
84
68
|
return {
|
|
85
69
|
value: value,
|
|
@@ -91,36 +75,27 @@ var useValue = function useValue(_ref) {
|
|
|
91
75
|
* @description
|
|
92
76
|
* options
|
|
93
77
|
*/
|
|
94
|
-
var useOptions = function useOptions(
|
|
95
|
-
var options =
|
|
96
|
-
onSearch =
|
|
97
|
-
|
|
78
|
+
var useOptions = function useOptions(_ref5) {
|
|
79
|
+
var options = _ref5.options,
|
|
80
|
+
onSearch = _ref5.onSearch,
|
|
81
|
+
onFilter = _ref5.onFilter;
|
|
98
82
|
var _useState = useState(""),
|
|
99
83
|
_useState2 = _slicedToArray(_useState, 2),
|
|
100
84
|
searched = _useState2[0],
|
|
101
85
|
setSearched = _useState2[1];
|
|
102
|
-
var
|
|
103
|
-
|
|
104
|
-
|
|
86
|
+
var filter = useEvent(function (option) {
|
|
87
|
+
if (!searched) return true;
|
|
88
|
+
if (isNull(onFilter) || onFilter === false) return true;
|
|
89
|
+
if (isFunction(onFilter)) return onFilter(searched, option);
|
|
90
|
+
var regExp = new RegExp(searched, "i");
|
|
91
|
+
return regExp.test(option.value.toString()) || !!(option.label && regExp.test(option.label));
|
|
105
92
|
});
|
|
106
|
-
|
|
107
|
-
if (!searched) return null;
|
|
108
|
-
var onFilter = onFilterGetter();
|
|
109
|
-
if (!onFilter) return null;
|
|
110
|
-
if (isFunction(onFilter)) return function (option) {
|
|
111
|
-
return onFilter(searched, option);
|
|
112
|
-
};
|
|
113
|
-
return function (option) {
|
|
114
|
-
var _option$label;
|
|
115
|
-
return !!((_option$label = option.label) !== null && _option$label !== void 0 && _option$label.includes(searched));
|
|
116
|
-
};
|
|
117
|
-
}, [searched, onFilterGetter]);
|
|
118
|
-
/// wrapper search handler, set react state
|
|
93
|
+
// wrapper search handler, set react state
|
|
119
94
|
var search = useEvent(function (searched) {
|
|
120
95
|
setSearched(searched);
|
|
121
96
|
onSearch === null || onSearch === void 0 || onSearch(searched);
|
|
122
97
|
});
|
|
123
|
-
|
|
98
|
+
// reset search value
|
|
124
99
|
var reset = useEvent(function () {
|
|
125
100
|
return setSearched("");
|
|
126
101
|
});
|
|
@@ -24,7 +24,8 @@ var Select = function Select(_ref) {
|
|
|
24
24
|
_ref$complex = _ref.complex,
|
|
25
25
|
complex = _ref$complex === void 0 ? false : _ref$complex,
|
|
26
26
|
value = _ref.value,
|
|
27
|
-
_onChange = _ref.onChange
|
|
27
|
+
_onChange = _ref.onChange,
|
|
28
|
+
onBlur = _ref.onBlur;
|
|
28
29
|
var ref = React.useRef(null);
|
|
29
30
|
var selectorRef = React.useRef(null);
|
|
30
31
|
var classNames = useClassNames.useClassNames(componentToken.ComponentToken.Select);
|
|
@@ -65,7 +66,7 @@ var Select = function Select(_ref) {
|
|
|
65
66
|
className: "musaex-1pgy25r"
|
|
66
67
|
}
|
|
67
68
|
};
|
|
68
|
-
return /*#__PURE__*/React.createElement(picker.default, {
|
|
69
|
+
return /*#__PURE__*/React.createElement(picker.default, _objectSpread({
|
|
69
70
|
ref: ref,
|
|
70
71
|
pickable: /*#__PURE__*/React.createElement(selections.default, {
|
|
71
72
|
items: menuItems,
|
|
@@ -78,14 +79,19 @@ var Select = function Select(_ref) {
|
|
|
78
79
|
pickableClassName: styled.pickable.className,
|
|
79
80
|
pickableStyle: styled.pickable.style,
|
|
80
81
|
onPopperExite: reset
|
|
81
|
-
},
|
|
82
|
+
}, !searchable && {
|
|
83
|
+
onBlur: onBlur
|
|
84
|
+
}), /*#__PURE__*/React.createElement(selector.default, _objectSpread({
|
|
82
85
|
value: readableValues,
|
|
83
86
|
mode: mode,
|
|
84
87
|
searchable: searchable,
|
|
85
88
|
ref: selectorRef,
|
|
86
89
|
searched: searched,
|
|
87
|
-
onSearch: search
|
|
88
|
-
|
|
90
|
+
onSearch: search,
|
|
91
|
+
onChange: onChange
|
|
92
|
+
}, searchable && {
|
|
93
|
+
onBlur: onBlur
|
|
94
|
+
})));
|
|
89
95
|
};
|
|
90
96
|
|
|
91
97
|
exports.default = Select;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import type { SelectProps, ValueOrValues } from "
|
|
3
|
-
declare const Select: <T extends ValueOrValues = ValueOrValues>({ mode, searchable, onSearch, className, style, options, onFilter, complex, value, onChange: _onChange, }: SelectProps<T>) => React.JSX.Element;
|
|
2
|
+
import type { SelectProps, ValueOrValues } from "musae/types/select";
|
|
3
|
+
declare const Select: <T extends ValueOrValues = ValueOrValues>({ mode, searchable, onSearch, className, style, options, onFilter, complex, value, onChange: _onChange, onBlur, }: SelectProps<T>) => React.JSX.Element;
|
|
4
4
|
export default Select;
|
|
@@ -22,7 +22,8 @@ var Select = function Select(_ref) {
|
|
|
22
22
|
_ref$complex = _ref.complex,
|
|
23
23
|
complex = _ref$complex === void 0 ? false : _ref$complex,
|
|
24
24
|
value = _ref.value,
|
|
25
|
-
_onChange = _ref.onChange
|
|
25
|
+
_onChange = _ref.onChange,
|
|
26
|
+
onBlur = _ref.onBlur;
|
|
26
27
|
var ref = useRef(null);
|
|
27
28
|
var selectorRef = useRef(null);
|
|
28
29
|
var classNames = useClassNames(ComponentToken.Select);
|
|
@@ -63,7 +64,7 @@ var Select = function Select(_ref) {
|
|
|
63
64
|
className: "musaex-1pgy25r"
|
|
64
65
|
}
|
|
65
66
|
};
|
|
66
|
-
return /*#__PURE__*/React.createElement(Picker, {
|
|
67
|
+
return /*#__PURE__*/React.createElement(Picker, _objectSpread({
|
|
67
68
|
ref: ref,
|
|
68
69
|
pickable: /*#__PURE__*/React.createElement(Selections, {
|
|
69
70
|
items: menuItems,
|
|
@@ -76,14 +77,19 @@ var Select = function Select(_ref) {
|
|
|
76
77
|
pickableClassName: styled.pickable.className,
|
|
77
78
|
pickableStyle: styled.pickable.style,
|
|
78
79
|
onPopperExite: reset
|
|
79
|
-
},
|
|
80
|
+
}, !searchable && {
|
|
81
|
+
onBlur: onBlur
|
|
82
|
+
}), /*#__PURE__*/React.createElement(Selector, _objectSpread({
|
|
80
83
|
value: readableValues,
|
|
81
84
|
mode: mode,
|
|
82
85
|
searchable: searchable,
|
|
83
86
|
ref: selectorRef,
|
|
84
87
|
searched: searched,
|
|
85
|
-
onSearch: search
|
|
86
|
-
|
|
88
|
+
onSearch: search,
|
|
89
|
+
onChange: onChange
|
|
90
|
+
}, searchable && {
|
|
91
|
+
onBlur: onBlur
|
|
92
|
+
})));
|
|
87
93
|
};
|
|
88
94
|
|
|
89
95
|
export { Select as default };
|