@lobehub/ui
Version:
Lobe UI is an open-source UI component library for building AIGC web apps
1 lines • 2.75 kB
Source Map (JSON)
{"version":3,"file":"helpers.mjs","names":[],"sources":["../../../src/base-ui/Select/helpers.ts"],"sourcesContent":["import { type SelectOption, type SelectOptionGroup, type SelectOptions } from './type';\n\nexport const isGroupOption = <Value>(\n option: SelectOption<Value> | SelectOptionGroup<Value>,\n): option is SelectOptionGroup<Value> => Boolean((option as SelectOptionGroup<Value>).options);\n\nexport const getOptionSearchText = <Value>(option: SelectOption<Value>) => {\n if (typeof option.label === 'string' || typeof option.label === 'number') {\n return String(option.label);\n }\n if (option.title) return option.title;\n if (typeof option.value === 'string' || typeof option.value === 'number') {\n return String(option.value);\n }\n return '';\n};\n\nconst escapeRegExp = (value: string) => value.replaceAll(/[$()*+.?[\\\\\\]^{|}]/g, '\\\\$&');\n\nexport const splitBySeparators = (value: string, separators?: string[]) => {\n if (!separators || separators.length === 0) return [value];\n const pattern = separators.map(escapeRegExp).join('|');\n return value.split(new RegExp(pattern, 'g'));\n};\n\nexport const countVirtualItems = (items: SelectOptions) =>\n items.reduce((count, item) => {\n if (isGroupOption(item)) {\n return count + item.options.length + 1;\n }\n return count + 1;\n }, 0);\n\nexport const isValueEmpty = (value: unknown) =>\n value === null || value === undefined || value === '';\n\nexport const normalizeValueFor = (isMultiple: boolean) => (nextValue: any) => {\n if (isMultiple) {\n if (Array.isArray(nextValue)) return nextValue;\n if (nextValue === null || nextValue === undefined) return [];\n return [nextValue];\n }\n if (Array.isArray(nextValue)) return nextValue[0] ?? null;\n return nextValue === undefined ? null : nextValue;\n};\n"],"mappings":";AAEA,MAAa,iBACX,WACuC,QAAS,OAAoC,OAAO;AAE7F,MAAa,uBAA8B,WAAgC;CACzE,IAAI,OAAO,OAAO,UAAU,YAAY,OAAO,OAAO,UAAU,UAC9D,OAAO,OAAO,OAAO,KAAK;CAE5B,IAAI,OAAO,OAAO,OAAO,OAAO;CAChC,IAAI,OAAO,OAAO,UAAU,YAAY,OAAO,OAAO,UAAU,UAC9D,OAAO,OAAO,OAAO,KAAK;CAE5B,OAAO;AACT;AAEA,MAAM,gBAAgB,UAAkB,MAAM,WAAW,uBAAuB,MAAM;AAEtF,MAAa,qBAAqB,OAAe,eAA0B;CACzE,IAAI,CAAC,cAAc,WAAW,WAAW,GAAG,OAAO,CAAC,KAAK;CACzD,MAAM,UAAU,WAAW,IAAI,YAAY,CAAC,CAAC,KAAK,GAAG;CACrD,OAAO,MAAM,MAAM,IAAI,OAAO,SAAS,GAAG,CAAC;AAC7C;AAEA,MAAa,qBAAqB,UAChC,MAAM,QAAQ,OAAO,SAAS;CAC5B,IAAI,cAAc,IAAI,GACpB,OAAO,QAAQ,KAAK,QAAQ,SAAS;CAEvC,OAAO,QAAQ;AACjB,GAAG,CAAC;AAEN,MAAa,gBAAgB,UAC3B,UAAU,QAAQ,UAAU,KAAA,KAAa,UAAU;AAErD,MAAa,qBAAqB,gBAAyB,cAAmB;CAC5E,IAAI,YAAY;EACd,IAAI,MAAM,QAAQ,SAAS,GAAG,OAAO;EACrC,IAAI,cAAc,QAAQ,cAAc,KAAA,GAAW,OAAO,CAAC;EAC3D,OAAO,CAAC,SAAS;CACnB;CACA,IAAI,MAAM,QAAQ,SAAS,GAAG,OAAO,UAAU,MAAM;CACrD,OAAO,cAAc,KAAA,IAAY,OAAO;AAC1C"}