PHP 8.2.30
Preview: useCreatable-09aaeb9a.esm.js Size: 5.05 KB
/home/byroehnu/.trash/node_modules11/react-select/dist/useCreatable-09aaeb9a.esm.js

import _objectSpread from '@babel/runtime/helpers/esm/objectSpread2';
import _toConsumableArray from '@babel/runtime/helpers/esm/toConsumableArray';
import _objectWithoutProperties from '@babel/runtime/helpers/esm/objectWithoutProperties';
import { useMemo, useCallback } from 'react';
import { H as cleanValue, D as valueTernary } from './index-641ee5b8.esm.js';
import { g as getOptionValue, b as getOptionLabel } from './Select-ef7c0426.esm.js';

var _excluded = ["allowCreateWhileLoading", "createOptionPosition", "formatCreateLabel", "isValidNewOption", "getNewOptionData", "onCreateOption", "options", "onChange"];
var compareOption = function compareOption() {
  var inputValue = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : '';
  var option = arguments.length > 1 ? arguments[1] : undefined;
  var accessors = arguments.length > 2 ? arguments[2] : undefined;
  var candidate = String(inputValue).toLowerCase();
  var optionValue = String(accessors.getOptionValue(option)).toLowerCase();
  var optionLabel = String(accessors.getOptionLabel(option)).toLowerCase();
  return optionValue === candidate || optionLabel === candidate;
};
var builtins = {
  formatCreateLabel: function formatCreateLabel(inputValue) {
    return "Create \"".concat(inputValue, "\"");
  },
  isValidNewOption: function isValidNewOption(inputValue, selectValue, selectOptions, accessors) {
    return !(!inputValue || selectValue.some(function (option) {
      return compareOption(inputValue, option, accessors);
    }) || selectOptions.some(function (option) {
      return compareOption(inputValue, option, accessors);
    }));
  },
  getNewOptionData: function getNewOptionData(inputValue, optionLabel) {
    return {
      label: optionLabel,
      value: inputValue,
      __isNew__: true
    };
  }
};
function useCreatable(_ref) {
  var _ref$allowCreateWhile = _ref.allowCreateWhileLoading,
    allowCreateWhileLoading = _ref$allowCreateWhile === void 0 ? false : _ref$allowCreateWhile,
    _ref$createOptionPosi = _ref.createOptionPosition,
    createOptionPosition = _ref$createOptionPosi === void 0 ? 'last' : _ref$createOptionPosi,
    _ref$formatCreateLabe = _ref.formatCreateLabel,
    formatCreateLabel = _ref$formatCreateLabe === void 0 ? builtins.formatCreateLabel : _ref$formatCreateLabe,
    _ref$isValidNewOption = _ref.isValidNewOption,
    isValidNewOption = _ref$isValidNewOption === void 0 ? builtins.isValidNewOption : _ref$isValidNewOption,
    _ref$getNewOptionData = _ref.getNewOptionData,
    getNewOptionData = _ref$getNewOptionData === void 0 ? builtins.getNewOptionData : _ref$getNewOptionData,
    onCreateOption = _ref.onCreateOption,
    _ref$options = _ref.options,
    propsOptions = _ref$options === void 0 ? [] : _ref$options,
    propsOnChange = _ref.onChange,
    restSelectProps = _objectWithoutProperties(_ref, _excluded);
  var _restSelectProps$getO = restSelectProps.getOptionValue,
    getOptionValue$1 = _restSelectProps$getO === void 0 ? getOptionValue : _restSelectProps$getO,
    _restSelectProps$getO2 = restSelectProps.getOptionLabel,
    getOptionLabel$1 = _restSelectProps$getO2 === void 0 ? getOptionLabel : _restSelectProps$getO2,
    inputValue = restSelectProps.inputValue,
    isLoading = restSelectProps.isLoading,
    isMulti = restSelectProps.isMulti,
    value = restSelectProps.value,
    name = restSelectProps.name;
  var newOption = useMemo(function () {
    return isValidNewOption(inputValue, cleanValue(value), propsOptions, {
      getOptionValue: getOptionValue$1,
      getOptionLabel: getOptionLabel$1
    }) ? getNewOptionData(inputValue, formatCreateLabel(inputValue)) : undefined;
  }, [formatCreateLabel, getNewOptionData, getOptionLabel$1, getOptionValue$1, inputValue, isValidNewOption, propsOptions, value]);
  var options = useMemo(function () {
    return (allowCreateWhileLoading || !isLoading) && newOption ? createOptionPosition === 'first' ? [newOption].concat(_toConsumableArray(propsOptions)) : [].concat(_toConsumableArray(propsOptions), [newOption]) : propsOptions;
  }, [allowCreateWhileLoading, createOptionPosition, isLoading, newOption, propsOptions]);
  var onChange = useCallback(function (newValue, actionMeta) {
    if (actionMeta.action !== 'select-option') {
      return propsOnChange(newValue, actionMeta);
    }
    var valueArray = Array.isArray(newValue) ? newValue : [newValue];
    if (valueArray[valueArray.length - 1] === newOption) {
      if (onCreateOption) onCreateOption(inputValue);else {
        var newOptionData = getNewOptionData(inputValue, inputValue);
        var newActionMeta = {
          action: 'create-option',
          name: name,
          option: newOptionData
        };
        propsOnChange(valueTernary(isMulti, [].concat(_toConsumableArray(cleanValue(value)), [newOptionData]), newOptionData), newActionMeta);
      }
      return;
    }
    propsOnChange(newValue, actionMeta);
  }, [getNewOptionData, inputValue, isMulti, name, newOption, onCreateOption, propsOnChange, value]);
  return _objectSpread(_objectSpread({}, restSelectProps), {}, {
    options: options,
    onChange: onChange
  });
}

export { useCreatable as u };

Directory Contents

Dirs: 1 × Files: 26

Name Size Perms Modified Actions
- drwxr-xr-x 2026-02-28 00:29:48
Edit Download
68.65 KB lrw-r--r-- 2026-02-28 00:26:54
Edit Download
67.45 KB lrw-r--r-- 2026-02-28 00:27:14
Edit Download
45.85 KB lrw-r--r-- 2026-02-28 00:27:30
Edit Download
162 B lrw-r--r-- 2026-02-28 00:29:48
Edit Download
135 B lrw-r--r-- 2026-02-28 00:29:38
Edit Download
141 B lrw-r--r-- 2026-02-28 00:30:14
Edit Download
134 B lrw-r--r-- 2026-02-28 00:29:40
Edit Download
66 B lrw-r--r-- 2026-02-28 00:30:14
Edit Download
61 B lrw-r--r-- 2026-02-28 00:28:54
Edit Download
2.72 KB lrw-r--r-- 2026-02-28 00:28:56
Edit Download
186 B lrw-r--r-- 2026-02-28 00:28:58
Edit Download
206 B lrw-r--r-- 2026-02-28 00:29:44
Edit Download
2.72 KB lrw-r--r-- 2026-02-28 00:28:58
Edit Download
1.88 KB lrw-r--r-- 2026-02-28 00:28:58
Edit Download
102.63 KB lrw-r--r-- 2026-02-28 00:29:00
Edit Download
94.42 KB lrw-r--r-- 2026-02-28 00:29:02
Edit Download
101.88 KB lrw-r--r-- 2026-02-28 00:29:06
Edit Download
5.84 KB lrw-r--r-- 2026-02-28 00:29:08
Edit Download
5.84 KB lrw-r--r-- 2026-02-28 00:29:08
Edit Download
5.78 KB lrw-r--r-- 2026-02-28 00:29:08
Edit Download
5.05 KB lrw-r--r-- 2026-02-28 00:29:10
Edit Download
5.04 KB lrw-r--r-- 2026-02-28 00:29:10
Edit Download
5.04 KB lrw-r--r-- 2026-02-28 00:29:10
Edit Download
3.18 KB lrw-r--r-- 2026-02-28 00:29:12
Edit Download
3.22 KB lrw-r--r-- 2026-02-28 00:29:12
Edit Download
3.22 KB lrw-r--r-- 2026-02-28 00:29:14
Edit Download

If ZipArchive is unavailable, a .tar will be created (no compression).