@v-c/select 0.0.1
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/LICENSE +21 -0
- package/dist/BaseSelect/Polite.cjs +37 -0
- package/dist/BaseSelect/Polite.d.ts +7 -0
- package/dist/BaseSelect/Polite.js +34 -0
- package/dist/BaseSelect/index.cjs +763 -0
- package/dist/BaseSelect/index.d.ts +133 -0
- package/dist/BaseSelect/index.js +759 -0
- package/dist/OptGroup.cjs +5 -0
- package/dist/OptGroup.d.ts +6 -0
- package/dist/OptGroup.js +4 -0
- package/dist/Option.cjs +5 -0
- package/dist/Option.d.ts +8 -0
- package/dist/Option.js +4 -0
- package/dist/OptionList.cjs +255 -0
- package/dist/OptionList.d.ts +17 -0
- package/dist/OptionList.js +249 -0
- package/dist/Select.cjs +833 -0
- package/dist/Select.d.ts +96 -0
- package/dist/Select.js +828 -0
- package/dist/SelectContext.cjs +11 -0
- package/dist/SelectContext.d.ts +32 -0
- package/dist/SelectContext.js +9 -0
- package/dist/SelectInput/Affix.cjs +16 -0
- package/dist/SelectInput/Affix.d.ts +2 -0
- package/dist/SelectInput/Affix.js +13 -0
- package/dist/SelectInput/Content/MultipleContent.cjs +142 -0
- package/dist/SelectInput/Content/MultipleContent.d.ts +3 -0
- package/dist/SelectInput/Content/MultipleContent.js +138 -0
- package/dist/SelectInput/Content/Placeholder.cjs +33 -0
- package/dist/SelectInput/Content/Placeholder.d.ts +5 -0
- package/dist/SelectInput/Content/Placeholder.js +30 -0
- package/dist/SelectInput/Content/SingleContent.cjs +80 -0
- package/dist/SelectInput/Content/SingleContent.d.ts +3 -0
- package/dist/SelectInput/Content/SingleContent.js +77 -0
- package/dist/SelectInput/Content/index.cjs +40 -0
- package/dist/SelectInput/Content/index.d.ts +6 -0
- package/dist/SelectInput/Content/index.js +36 -0
- package/dist/SelectInput/Input.cjs +176 -0
- package/dist/SelectInput/Input.d.ts +22 -0
- package/dist/SelectInput/Input.js +173 -0
- package/dist/SelectInput/context.cjs +11 -0
- package/dist/SelectInput/context.d.ts +5 -0
- package/dist/SelectInput/context.js +9 -0
- package/dist/SelectInput/index.cjs +330 -0
- package/dist/SelectInput/index.d.ts +44 -0
- package/dist/SelectInput/index.js +325 -0
- package/dist/SelectTrigger.cjs +189 -0
- package/dist/SelectTrigger.d.ts +26 -0
- package/dist/SelectTrigger.js +185 -0
- package/dist/TransBtn.cjs +69 -0
- package/dist/TransBtn.d.ts +22 -0
- package/dist/TransBtn.js +66 -0
- package/dist/_virtual/rolldown_runtime.cjs +21 -0
- package/dist/hooks/index.cjs +23 -0
- package/dist/hooks/index.d.ts +17 -0
- package/dist/hooks/index.js +12 -0
- package/dist/hooks/useAllowClear.cjs +17 -0
- package/dist/hooks/useAllowClear.d.ts +9 -0
- package/dist/hooks/useAllowClear.js +16 -0
- package/dist/hooks/useBaseProps.cjs +12 -0
- package/dist/hooks/useBaseProps.d.ts +10 -0
- package/dist/hooks/useBaseProps.js +9 -0
- package/dist/hooks/useCache.cjs +36 -0
- package/dist/hooks/useCache.d.ts +7 -0
- package/dist/hooks/useCache.js +34 -0
- package/dist/hooks/useComponents.cjs +15 -0
- package/dist/hooks/useComponents.d.ts +8 -0
- package/dist/hooks/useComponents.js +13 -0
- package/dist/hooks/useFilterOptions.cjs +39 -0
- package/dist/hooks/useFilterOptions.d.ts +3 -0
- package/dist/hooks/useFilterOptions.js +37 -0
- package/dist/hooks/useLock.cjs +26 -0
- package/dist/hooks/useLock.d.ts +1 -0
- package/dist/hooks/useLock.js +24 -0
- package/dist/hooks/useOpen.cjs +58 -0
- package/dist/hooks/useOpen.d.ts +19 -0
- package/dist/hooks/useOpen.js +56 -0
- package/dist/hooks/useOptions.cjs +38 -0
- package/dist/hooks/useOptions.d.ts +13 -0
- package/dist/hooks/useOptions.js +36 -0
- package/dist/hooks/useRefFunc.cjs +12 -0
- package/dist/hooks/useRefFunc.d.ts +6 -0
- package/dist/hooks/useRefFunc.js +10 -0
- package/dist/hooks/useSearchConfig.cjs +21 -0
- package/dist/hooks/useSearchConfig.d.ts +11 -0
- package/dist/hooks/useSearchConfig.js +19 -0
- package/dist/hooks/useSelectTriggerControl.cjs +18 -0
- package/dist/hooks/useSelectTriggerControl.d.ts +2 -0
- package/dist/hooks/useSelectTriggerControl.js +16 -0
- package/dist/index.cjs +16 -0
- package/dist/index.d.ts +10 -0
- package/dist/index.js +8 -0
- package/dist/interface.cjs +0 -0
- package/dist/interface.d.ts +23 -0
- package/dist/interface.js +0 -0
- package/dist/utils/commonUtil.cjs +37 -0
- package/dist/utils/commonUtil.d.ts +12 -0
- package/dist/utils/commonUtil.js +30 -0
- package/dist/utils/keyUtil.cjs +36 -0
- package/dist/utils/keyUtil.d.ts +2 -0
- package/dist/utils/keyUtil.js +34 -0
- package/dist/utils/legacyUtil.cjs +32 -0
- package/dist/utils/legacyUtil.d.ts +3 -0
- package/dist/utils/legacyUtil.js +31 -0
- package/dist/utils/platformUtil.cjs +5 -0
- package/dist/utils/platformUtil.d.ts +1 -0
- package/dist/utils/platformUtil.js +5 -0
- package/dist/utils/valueUtil.cjs +79 -0
- package/dist/utils/valueUtil.d.ts +18 -0
- package/dist/utils/valueUtil.js +75 -0
- package/package.json +43 -0
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
2
|
+
const require_OptGroup = require("./OptGroup.cjs");
|
|
3
|
+
const require_Option = require("./Option.cjs");
|
|
4
|
+
const require_SelectContext = require("./SelectContext.cjs");
|
|
5
|
+
const require_OptionList = require("./OptionList.cjs");
|
|
6
|
+
const require_index = require("./BaseSelect/index.cjs");
|
|
7
|
+
const require_Select = require("./Select.cjs");
|
|
8
|
+
var src_default = require_Select.default;
|
|
9
|
+
exports.BaseSelect = require_index.BaseSelect;
|
|
10
|
+
exports.OptGroup = require_OptGroup.default;
|
|
11
|
+
exports.Option = require_Option.default;
|
|
12
|
+
exports.OptionList = require_OptionList.default;
|
|
13
|
+
exports.Select = require_Select.default;
|
|
14
|
+
exports.default = src_default;
|
|
15
|
+
exports.useSelectContext = require_SelectContext.useSelectContext;
|
|
16
|
+
exports.useSelectProvider = require_SelectContext.useSelectProvider;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { BaseSelectProps, BaseSelectRef, CustomTagProps, RefOptionListProps, BaseSelect } from './BaseSelect';
|
|
2
|
+
import { DisplayInfoType, DisplayValueType, FlattenOptionData, Mode, Placement, RawValueType, RenderNode } from './interface';
|
|
3
|
+
import { BaseOptionType, DefaultOptionType, DraftValueType, FieldNames, FilterFunc, LabelInValueType, OnActiveValue, OnInternalSelect, SearchConfig, SelectHandler, SelectProps, default as Select } from './Select';
|
|
4
|
+
import { default as OptGroup } from './OptGroup';
|
|
5
|
+
import { default as Option } from './Option';
|
|
6
|
+
import { default as OptionList } from './OptionList';
|
|
7
|
+
import { useSelectContext, useSelectProvider } from './SelectContext';
|
|
8
|
+
export { BaseSelect, OptGroup, Option, OptionList, Select, useSelectContext, useSelectProvider, };
|
|
9
|
+
export type { BaseOptionType, BaseSelectProps, BaseSelectRef, CustomTagProps, DefaultOptionType, DisplayInfoType, DisplayValueType, DraftValueType, FieldNames, FilterFunc, FlattenOptionData, LabelInValueType, Mode, OnActiveValue, OnInternalSelect, Placement, RawValueType, RefOptionListProps, RenderNode, SearchConfig, SelectHandler, SelectProps, };
|
|
10
|
+
export default Select;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import OptGroup_default from "./OptGroup.js";
|
|
2
|
+
import Option_default from "./Option.js";
|
|
3
|
+
import { useSelectContext, useSelectProvider } from "./SelectContext.js";
|
|
4
|
+
import OptionList_default from "./OptionList.js";
|
|
5
|
+
import { BaseSelect } from "./BaseSelect/index.js";
|
|
6
|
+
import Select_default from "./Select.js";
|
|
7
|
+
var src_default = Select_default;
|
|
8
|
+
export { BaseSelect, OptGroup_default as OptGroup, Option_default as Option, OptionList_default as OptionList, Select_default as Select, src_default as default, useSelectContext, useSelectProvider };
|
|
File without changes
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Key, VueNode } from '@v-c/util/dist/type';
|
|
2
|
+
export type RawValueType = string | number;
|
|
3
|
+
export interface FlattenOptionData<OptionType = any> {
|
|
4
|
+
label?: VueNode;
|
|
5
|
+
data: OptionType;
|
|
6
|
+
key: Key;
|
|
7
|
+
value?: RawValueType;
|
|
8
|
+
groupOption?: boolean;
|
|
9
|
+
group?: boolean;
|
|
10
|
+
}
|
|
11
|
+
export interface DisplayValueType {
|
|
12
|
+
key?: Key;
|
|
13
|
+
value?: RawValueType;
|
|
14
|
+
label?: VueNode;
|
|
15
|
+
title?: VueNode;
|
|
16
|
+
disabled?: boolean;
|
|
17
|
+
index?: number;
|
|
18
|
+
}
|
|
19
|
+
export type RenderNode = VueNode | ((props: any) => VueNode);
|
|
20
|
+
export type RenderDOMFunc = (props: any) => HTMLElement;
|
|
21
|
+
export type Mode = 'multiple' | 'tags' | 'combobox';
|
|
22
|
+
export type Placement = 'bottomLeft' | 'bottomRight' | 'topLeft' | 'topRight';
|
|
23
|
+
export type DisplayInfoType = 'add' | 'remove' | 'clear';
|
|
File without changes
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
function toArray(value) {
|
|
2
|
+
if (value === null || value === void 0) return [];
|
|
3
|
+
return Array.isArray(value) ? value : [value];
|
|
4
|
+
}
|
|
5
|
+
function isTitleType(title) {
|
|
6
|
+
return ["string", "number"].includes(typeof title);
|
|
7
|
+
}
|
|
8
|
+
function injectPropsWithOption(option) {
|
|
9
|
+
return { ...option };
|
|
10
|
+
}
|
|
11
|
+
function toVueNode(value) {
|
|
12
|
+
return toArray(value);
|
|
13
|
+
}
|
|
14
|
+
function getTitle(item) {
|
|
15
|
+
let title;
|
|
16
|
+
if (item) {
|
|
17
|
+
if (isTitleType(item.title)) title = item.title.toString();
|
|
18
|
+
else if (isTitleType(item.label)) title = item.label.toString();
|
|
19
|
+
}
|
|
20
|
+
return title;
|
|
21
|
+
}
|
|
22
|
+
const isClient = typeof window !== "undefined" && window.document && window.document.documentElement;
|
|
23
|
+
const isBrowserClient = typeof process !== "undefined" && process.env.NODE_ENV !== "test" && isClient;
|
|
24
|
+
function hasValue(value) {
|
|
25
|
+
return value !== void 0 && value !== null;
|
|
26
|
+
}
|
|
27
|
+
function isComboNoValue(value) {
|
|
28
|
+
return !value && value !== 0;
|
|
29
|
+
}
|
|
30
|
+
exports.getTitle = getTitle;
|
|
31
|
+
exports.hasValue = hasValue;
|
|
32
|
+
exports.injectPropsWithOption = injectPropsWithOption;
|
|
33
|
+
exports.isBrowserClient = isBrowserClient;
|
|
34
|
+
exports.isClient = isClient;
|
|
35
|
+
exports.isComboNoValue = isComboNoValue;
|
|
36
|
+
exports.toArray = toArray;
|
|
37
|
+
exports.toVueNode = toVueNode;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { VueNode } from '@v-c/util/dist/type';
|
|
2
|
+
import { DisplayValueType } from '../interface';
|
|
3
|
+
export declare function toArray<T>(value: T | T[] | null | undefined): T[];
|
|
4
|
+
export declare function injectPropsWithOption(option: any): any;
|
|
5
|
+
export declare function toVueNode(value: VueNode | VueNode[]): VueNode[];
|
|
6
|
+
export declare function getTitle(item: DisplayValueType): string | undefined;
|
|
7
|
+
export declare const isClient: false | HTMLElement;
|
|
8
|
+
/** Is client side and not jsdom */
|
|
9
|
+
export declare const isBrowserClient: false | HTMLElement;
|
|
10
|
+
export declare function hasValue(value: any): boolean;
|
|
11
|
+
/** combo mode no value judgment function */
|
|
12
|
+
export declare function isComboNoValue(value: any): boolean;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
function toArray(value) {
|
|
2
|
+
if (value === null || value === void 0) return [];
|
|
3
|
+
return Array.isArray(value) ? value : [value];
|
|
4
|
+
}
|
|
5
|
+
function isTitleType(title) {
|
|
6
|
+
return ["string", "number"].includes(typeof title);
|
|
7
|
+
}
|
|
8
|
+
function injectPropsWithOption(option) {
|
|
9
|
+
return { ...option };
|
|
10
|
+
}
|
|
11
|
+
function toVueNode(value) {
|
|
12
|
+
return toArray(value);
|
|
13
|
+
}
|
|
14
|
+
function getTitle(item) {
|
|
15
|
+
let title;
|
|
16
|
+
if (item) {
|
|
17
|
+
if (isTitleType(item.title)) title = item.title.toString();
|
|
18
|
+
else if (isTitleType(item.label)) title = item.label.toString();
|
|
19
|
+
}
|
|
20
|
+
return title;
|
|
21
|
+
}
|
|
22
|
+
const isClient = typeof window !== "undefined" && window.document && window.document.documentElement;
|
|
23
|
+
const isBrowserClient = typeof process !== "undefined" && process.env.NODE_ENV !== "test" && isClient;
|
|
24
|
+
function hasValue(value) {
|
|
25
|
+
return value !== void 0 && value !== null;
|
|
26
|
+
}
|
|
27
|
+
function isComboNoValue(value) {
|
|
28
|
+
return !value && value !== 0;
|
|
29
|
+
}
|
|
30
|
+
export { getTitle, hasValue, injectPropsWithOption, isBrowserClient, isClient, isComboNoValue, toArray, toVueNode };
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
2
|
+
let __v_c_util_dist_KeyCode = require("@v-c/util/dist/KeyCode");
|
|
3
|
+
__v_c_util_dist_KeyCode = require_rolldown_runtime.__toESM(__v_c_util_dist_KeyCode);
|
|
4
|
+
function isValidateOpenKey(currentKeyCode) {
|
|
5
|
+
return !!currentKeyCode && ![
|
|
6
|
+
__v_c_util_dist_KeyCode.default.ESC,
|
|
7
|
+
__v_c_util_dist_KeyCode.default.SHIFT,
|
|
8
|
+
__v_c_util_dist_KeyCode.default.BACKSPACE,
|
|
9
|
+
__v_c_util_dist_KeyCode.default.TAB,
|
|
10
|
+
__v_c_util_dist_KeyCode.default.WIN_KEY,
|
|
11
|
+
__v_c_util_dist_KeyCode.default.ALT,
|
|
12
|
+
__v_c_util_dist_KeyCode.default.META,
|
|
13
|
+
__v_c_util_dist_KeyCode.default.WIN_KEY_RIGHT,
|
|
14
|
+
__v_c_util_dist_KeyCode.default.CTRL,
|
|
15
|
+
__v_c_util_dist_KeyCode.default.SEMICOLON,
|
|
16
|
+
__v_c_util_dist_KeyCode.default.EQUALS,
|
|
17
|
+
__v_c_util_dist_KeyCode.default.CAPS_LOCK,
|
|
18
|
+
__v_c_util_dist_KeyCode.default.CONTEXT_MENU,
|
|
19
|
+
__v_c_util_dist_KeyCode.default.UP,
|
|
20
|
+
__v_c_util_dist_KeyCode.default.LEFT,
|
|
21
|
+
__v_c_util_dist_KeyCode.default.RIGHT,
|
|
22
|
+
__v_c_util_dist_KeyCode.default.F1,
|
|
23
|
+
__v_c_util_dist_KeyCode.default.F2,
|
|
24
|
+
__v_c_util_dist_KeyCode.default.F3,
|
|
25
|
+
__v_c_util_dist_KeyCode.default.F4,
|
|
26
|
+
__v_c_util_dist_KeyCode.default.F5,
|
|
27
|
+
__v_c_util_dist_KeyCode.default.F6,
|
|
28
|
+
__v_c_util_dist_KeyCode.default.F7,
|
|
29
|
+
__v_c_util_dist_KeyCode.default.F8,
|
|
30
|
+
__v_c_util_dist_KeyCode.default.F9,
|
|
31
|
+
__v_c_util_dist_KeyCode.default.F10,
|
|
32
|
+
__v_c_util_dist_KeyCode.default.F11,
|
|
33
|
+
__v_c_util_dist_KeyCode.default.F12
|
|
34
|
+
].includes(currentKeyCode);
|
|
35
|
+
}
|
|
36
|
+
exports.isValidateOpenKey = isValidateOpenKey;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import KeyCode from "@v-c/util/dist/KeyCode";
|
|
2
|
+
function isValidateOpenKey(currentKeyCode) {
|
|
3
|
+
return !!currentKeyCode && ![
|
|
4
|
+
KeyCode.ESC,
|
|
5
|
+
KeyCode.SHIFT,
|
|
6
|
+
KeyCode.BACKSPACE,
|
|
7
|
+
KeyCode.TAB,
|
|
8
|
+
KeyCode.WIN_KEY,
|
|
9
|
+
KeyCode.ALT,
|
|
10
|
+
KeyCode.META,
|
|
11
|
+
KeyCode.WIN_KEY_RIGHT,
|
|
12
|
+
KeyCode.CTRL,
|
|
13
|
+
KeyCode.SEMICOLON,
|
|
14
|
+
KeyCode.EQUALS,
|
|
15
|
+
KeyCode.CAPS_LOCK,
|
|
16
|
+
KeyCode.CONTEXT_MENU,
|
|
17
|
+
KeyCode.UP,
|
|
18
|
+
KeyCode.LEFT,
|
|
19
|
+
KeyCode.RIGHT,
|
|
20
|
+
KeyCode.F1,
|
|
21
|
+
KeyCode.F2,
|
|
22
|
+
KeyCode.F3,
|
|
23
|
+
KeyCode.F4,
|
|
24
|
+
KeyCode.F5,
|
|
25
|
+
KeyCode.F6,
|
|
26
|
+
KeyCode.F7,
|
|
27
|
+
KeyCode.F8,
|
|
28
|
+
KeyCode.F9,
|
|
29
|
+
KeyCode.F10,
|
|
30
|
+
KeyCode.F11,
|
|
31
|
+
KeyCode.F12
|
|
32
|
+
].includes(currentKeyCode);
|
|
33
|
+
}
|
|
34
|
+
export { isValidateOpenKey };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const require_rolldown_runtime = require("../_virtual/rolldown_runtime.cjs");
|
|
2
|
+
let vue = require("vue");
|
|
3
|
+
function convertNodeToOption(node) {
|
|
4
|
+
const { key, props, children } = node;
|
|
5
|
+
const { value, label,...restProps } = props || {};
|
|
6
|
+
let finalChildren = children;
|
|
7
|
+
if (typeof children === "function") finalChildren = children();
|
|
8
|
+
else if (children && typeof children === "object" && "default" in children) finalChildren = typeof children.default === "function" ? children.default() : children.default;
|
|
9
|
+
const finalLabel = label ?? restProps.children ?? finalChildren;
|
|
10
|
+
return {
|
|
11
|
+
key,
|
|
12
|
+
value: value !== void 0 ? value : key,
|
|
13
|
+
label: finalLabel,
|
|
14
|
+
...restProps
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
function convertChildrenToData(nodes, optionOnly = false) {
|
|
18
|
+
return nodes.map((node, index) => {
|
|
19
|
+
if (!(0, vue.isVNode)(node) || !node.type) return null;
|
|
20
|
+
const { type, key, props } = node;
|
|
21
|
+
const isSelectOptGroup = type?.isSelectOptGroup;
|
|
22
|
+
if (optionOnly || !isSelectOptGroup) return convertNodeToOption(node);
|
|
23
|
+
const { children,...restProps } = props || {};
|
|
24
|
+
return {
|
|
25
|
+
key: `__VC_SELECT_GRP__${key === null ? index : String(key)}__`,
|
|
26
|
+
label: key,
|
|
27
|
+
...restProps,
|
|
28
|
+
options: convertChildrenToData(children || [])
|
|
29
|
+
};
|
|
30
|
+
}).filter((data) => data !== null);
|
|
31
|
+
}
|
|
32
|
+
exports.convertChildrenToData = convertChildrenToData;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { isVNode } from "vue";
|
|
2
|
+
function convertNodeToOption(node) {
|
|
3
|
+
const { key, props, children } = node;
|
|
4
|
+
const { value, label,...restProps } = props || {};
|
|
5
|
+
let finalChildren = children;
|
|
6
|
+
if (typeof children === "function") finalChildren = children();
|
|
7
|
+
else if (children && typeof children === "object" && "default" in children) finalChildren = typeof children.default === "function" ? children.default() : children.default;
|
|
8
|
+
const finalLabel = label ?? restProps.children ?? finalChildren;
|
|
9
|
+
return {
|
|
10
|
+
key,
|
|
11
|
+
value: value !== void 0 ? value : key,
|
|
12
|
+
label: finalLabel,
|
|
13
|
+
...restProps
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
function convertChildrenToData(nodes, optionOnly = false) {
|
|
17
|
+
return nodes.map((node, index) => {
|
|
18
|
+
if (!isVNode(node) || !node.type) return null;
|
|
19
|
+
const { type, key, props } = node;
|
|
20
|
+
const isSelectOptGroup = type?.isSelectOptGroup;
|
|
21
|
+
if (optionOnly || !isSelectOptGroup) return convertNodeToOption(node);
|
|
22
|
+
const { children,...restProps } = props || {};
|
|
23
|
+
return {
|
|
24
|
+
key: `__VC_SELECT_GRP__${key === null ? index : String(key)}__`,
|
|
25
|
+
label: key,
|
|
26
|
+
...restProps,
|
|
27
|
+
options: convertChildrenToData(children || [])
|
|
28
|
+
};
|
|
29
|
+
}).filter((data) => data !== null);
|
|
30
|
+
}
|
|
31
|
+
export { convertChildrenToData };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isPlatformMac(): boolean;
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
function getKey(data, index) {
|
|
2
|
+
const { key } = data;
|
|
3
|
+
let value;
|
|
4
|
+
if ("value" in data) value = data.value;
|
|
5
|
+
if (key !== null && key !== void 0) return key;
|
|
6
|
+
if (value !== void 0) return value;
|
|
7
|
+
return `vc-index-key-${index}`;
|
|
8
|
+
}
|
|
9
|
+
function isValidCount(value) {
|
|
10
|
+
return typeof value !== "undefined" && !Number.isNaN(value);
|
|
11
|
+
}
|
|
12
|
+
function fillFieldNames(fieldNames, childrenAsData) {
|
|
13
|
+
const { label, value, options, groupLabel } = fieldNames || {};
|
|
14
|
+
const mergedLabel = label || (childrenAsData ? "children" : "label");
|
|
15
|
+
return {
|
|
16
|
+
label: mergedLabel,
|
|
17
|
+
value: value || "value",
|
|
18
|
+
options: options || "options",
|
|
19
|
+
groupLabel: groupLabel || mergedLabel
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function flattenOptions(options, { fieldNames, childrenAsData } = {}) {
|
|
23
|
+
const flattenList = [];
|
|
24
|
+
const { label: fieldLabel, value: fieldValue, options: fieldOptions, groupLabel } = fillFieldNames(fieldNames, false);
|
|
25
|
+
function dig(list, isGroupOption) {
|
|
26
|
+
if (!Array.isArray(list)) return;
|
|
27
|
+
list.forEach((data) => {
|
|
28
|
+
if (isGroupOption || !(fieldOptions in data)) {
|
|
29
|
+
const value = data[fieldValue];
|
|
30
|
+
flattenList.push({
|
|
31
|
+
key: getKey(data, flattenList.length),
|
|
32
|
+
groupOption: isGroupOption,
|
|
33
|
+
data,
|
|
34
|
+
label: data[fieldLabel],
|
|
35
|
+
value
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
let grpLabel = data[groupLabel];
|
|
39
|
+
if (grpLabel === void 0 && childrenAsData) grpLabel = data.label;
|
|
40
|
+
flattenList.push({
|
|
41
|
+
key: getKey(data, flattenList.length),
|
|
42
|
+
group: true,
|
|
43
|
+
data,
|
|
44
|
+
label: grpLabel
|
|
45
|
+
});
|
|
46
|
+
dig(data[fieldOptions], true);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
dig(options, false);
|
|
51
|
+
return flattenList;
|
|
52
|
+
}
|
|
53
|
+
function injectPropsWithOption(option) {
|
|
54
|
+
if (!option) return option;
|
|
55
|
+
const newOption = { ...option };
|
|
56
|
+
if (!("props" in newOption)) Object.defineProperty(newOption, "props", { get() {
|
|
57
|
+
console.warn("Return type is option instead of Option instance. Please read value directly instead of reading from `props`.");
|
|
58
|
+
return newOption;
|
|
59
|
+
} });
|
|
60
|
+
return newOption;
|
|
61
|
+
}
|
|
62
|
+
function getSeparatedContent(text, tokens, end) {
|
|
63
|
+
if (!tokens || !tokens.length) return null;
|
|
64
|
+
let match = false;
|
|
65
|
+
const separate = (str, [token, ...restTokens]) => {
|
|
66
|
+
if (!token) return [str];
|
|
67
|
+
const list$1 = str.split(token);
|
|
68
|
+
match = match || list$1.length > 1;
|
|
69
|
+
return list$1.reduce((prevList, unitStr) => [...prevList, ...separate(unitStr, restTokens)], []).filter(Boolean);
|
|
70
|
+
};
|
|
71
|
+
const list = separate(text, tokens);
|
|
72
|
+
if (match) return typeof end !== "undefined" ? list.slice(0, end) : list;
|
|
73
|
+
else return null;
|
|
74
|
+
}
|
|
75
|
+
exports.fillFieldNames = fillFieldNames;
|
|
76
|
+
exports.flattenOptions = flattenOptions;
|
|
77
|
+
exports.getSeparatedContent = getSeparatedContent;
|
|
78
|
+
exports.injectPropsWithOption = injectPropsWithOption;
|
|
79
|
+
exports.isValidCount = isValidCount;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { FlattenOptionData } from '../interface';
|
|
2
|
+
import { BaseOptionType, DefaultOptionType, FieldNames } from '../Select';
|
|
3
|
+
export declare function isValidCount(value?: number): boolean;
|
|
4
|
+
export declare function fillFieldNames(fieldNames: FieldNames | undefined, childrenAsData: boolean): Required<FieldNames>;
|
|
5
|
+
/**
|
|
6
|
+
* Flat options into flatten list.
|
|
7
|
+
* We use `optionOnly` here is aim to avoid user use nested option group.
|
|
8
|
+
* Here is simply set `key` to the index if not provided.
|
|
9
|
+
*/
|
|
10
|
+
export declare function flattenOptions<OptionType extends BaseOptionType = DefaultOptionType>(options: OptionType[], { fieldNames, childrenAsData }?: {
|
|
11
|
+
fieldNames?: FieldNames;
|
|
12
|
+
childrenAsData?: boolean;
|
|
13
|
+
}): FlattenOptionData<OptionType>[];
|
|
14
|
+
/**
|
|
15
|
+
* Inject `props` into `option` for legacy usage
|
|
16
|
+
*/
|
|
17
|
+
export declare function injectPropsWithOption<T extends object>(option: T | undefined): T | undefined;
|
|
18
|
+
export declare function getSeparatedContent(text: string, tokens: string[], end?: number): string[] | null;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
function getKey(data, index) {
|
|
2
|
+
const { key } = data;
|
|
3
|
+
let value;
|
|
4
|
+
if ("value" in data) value = data.value;
|
|
5
|
+
if (key !== null && key !== void 0) return key;
|
|
6
|
+
if (value !== void 0) return value;
|
|
7
|
+
return `vc-index-key-${index}`;
|
|
8
|
+
}
|
|
9
|
+
function isValidCount(value) {
|
|
10
|
+
return typeof value !== "undefined" && !Number.isNaN(value);
|
|
11
|
+
}
|
|
12
|
+
function fillFieldNames(fieldNames, childrenAsData) {
|
|
13
|
+
const { label, value, options, groupLabel } = fieldNames || {};
|
|
14
|
+
const mergedLabel = label || (childrenAsData ? "children" : "label");
|
|
15
|
+
return {
|
|
16
|
+
label: mergedLabel,
|
|
17
|
+
value: value || "value",
|
|
18
|
+
options: options || "options",
|
|
19
|
+
groupLabel: groupLabel || mergedLabel
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
function flattenOptions(options, { fieldNames, childrenAsData } = {}) {
|
|
23
|
+
const flattenList = [];
|
|
24
|
+
const { label: fieldLabel, value: fieldValue, options: fieldOptions, groupLabel } = fillFieldNames(fieldNames, false);
|
|
25
|
+
function dig(list, isGroupOption) {
|
|
26
|
+
if (!Array.isArray(list)) return;
|
|
27
|
+
list.forEach((data) => {
|
|
28
|
+
if (isGroupOption || !(fieldOptions in data)) {
|
|
29
|
+
const value = data[fieldValue];
|
|
30
|
+
flattenList.push({
|
|
31
|
+
key: getKey(data, flattenList.length),
|
|
32
|
+
groupOption: isGroupOption,
|
|
33
|
+
data,
|
|
34
|
+
label: data[fieldLabel],
|
|
35
|
+
value
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
let grpLabel = data[groupLabel];
|
|
39
|
+
if (grpLabel === void 0 && childrenAsData) grpLabel = data.label;
|
|
40
|
+
flattenList.push({
|
|
41
|
+
key: getKey(data, flattenList.length),
|
|
42
|
+
group: true,
|
|
43
|
+
data,
|
|
44
|
+
label: grpLabel
|
|
45
|
+
});
|
|
46
|
+
dig(data[fieldOptions], true);
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
dig(options, false);
|
|
51
|
+
return flattenList;
|
|
52
|
+
}
|
|
53
|
+
function injectPropsWithOption(option) {
|
|
54
|
+
if (!option) return option;
|
|
55
|
+
const newOption = { ...option };
|
|
56
|
+
if (!("props" in newOption)) Object.defineProperty(newOption, "props", { get() {
|
|
57
|
+
console.warn("Return type is option instead of Option instance. Please read value directly instead of reading from `props`.");
|
|
58
|
+
return newOption;
|
|
59
|
+
} });
|
|
60
|
+
return newOption;
|
|
61
|
+
}
|
|
62
|
+
function getSeparatedContent(text, tokens, end) {
|
|
63
|
+
if (!tokens || !tokens.length) return null;
|
|
64
|
+
let match = false;
|
|
65
|
+
const separate = (str, [token, ...restTokens]) => {
|
|
66
|
+
if (!token) return [str];
|
|
67
|
+
const list$1 = str.split(token);
|
|
68
|
+
match = match || list$1.length > 1;
|
|
69
|
+
return list$1.reduce((prevList, unitStr) => [...prevList, ...separate(unitStr, restTokens)], []).filter(Boolean);
|
|
70
|
+
};
|
|
71
|
+
const list = separate(text, tokens);
|
|
72
|
+
if (match) return typeof end !== "undefined" ? list.slice(0, end) : list;
|
|
73
|
+
else return null;
|
|
74
|
+
}
|
|
75
|
+
export { fillFieldNames, flattenOptions, getSeparatedContent, injectPropsWithOption, isValidCount };
|
package/package.json
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@v-c/select",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"description": "",
|
|
6
|
+
"author": "",
|
|
7
|
+
"license": "MIT",
|
|
8
|
+
"publishConfig": {
|
|
9
|
+
"access": "public"
|
|
10
|
+
},
|
|
11
|
+
"keywords": [
|
|
12
|
+
"slider"
|
|
13
|
+
],
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"types": "./dist/index.d.ts",
|
|
17
|
+
"import": "./dist/index.js",
|
|
18
|
+
"require": "./dist/index.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./dist/*": "./dist/*",
|
|
21
|
+
"./package.json": "./package.json"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"files": [
|
|
25
|
+
"dist",
|
|
26
|
+
"package.json"
|
|
27
|
+
],
|
|
28
|
+
"peerDependencies": {
|
|
29
|
+
"vue": "^3.0.0"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@v-c/trigger": "^1.0.1",
|
|
33
|
+
"@v-c/overflow": "^1.0.0",
|
|
34
|
+
"@v-c/virtual-list": "^1.0.0",
|
|
35
|
+
"@v-c/util": "^1.0.1"
|
|
36
|
+
},
|
|
37
|
+
"scripts": {
|
|
38
|
+
"build": "vite build",
|
|
39
|
+
"test": "vitest run",
|
|
40
|
+
"prepublish": "pnpm build",
|
|
41
|
+
"bump": "bumpp --release patch"
|
|
42
|
+
}
|
|
43
|
+
}
|