@sydsoft/base 1.41.0 → 1.43.0

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.
@@ -1,7 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  export declare const isDev: boolean;
3
3
  export declare const isServerReq: (context: any) => boolean;
4
- export declare function tumuBuyukCevir(e: React.ChangeEvent<HTMLInputElement>): void;
5
- export declare function tumuKucukCevir(e: React.ChangeEvent<HTMLInputElement>): void;
6
- export declare function seoCevirFunction(e: React.ChangeEvent<HTMLInputElement>): void;
4
+ export declare const padNumber: (num: number, padLength?: number, padString?: string) => string;
5
+ export declare function inputTumuBuyukCevir(e: React.ChangeEvent<HTMLInputElement>): void;
6
+ export declare function inputTumuKucukCevir(e: React.ChangeEvent<HTMLInputElement>): void;
7
+ export declare const convertLowerCase: (text?: any) => any;
8
+ export declare const convertForSearch: (value: string) => string;
9
+ export declare function convertForSEO(e: React.ChangeEvent<HTMLInputElement>): void;
7
10
  export declare function getDomain(context?: any): string;
11
+ export declare const uniqueID: (key?: string, length?: number) => string;
@@ -1,24 +1,45 @@
1
1
  export var isDev = !process.env.NODE_ENV || process.env.NODE_ENV === 'development';
2
2
  export var isServerReq = function (context) { var _a, _b; return !((_b = (_a = context === null || context === void 0 ? void 0 : context.req) === null || _a === void 0 ? void 0 : _a.url) === null || _b === void 0 ? void 0 : _b.startsWith('/_next')); };
3
- export function tumuBuyukCevir(e) {
3
+ export var padNumber = function (num, padLength, padString) {
4
+ if (padLength === void 0) { padLength = 2; }
5
+ if (padString === void 0) { padString = '0'; }
6
+ return String(num).padStart(padLength, padString);
7
+ };
8
+ export function inputTumuBuyukCevir(e) {
4
9
  var _a;
5
10
  if ((e === null || e === void 0 ? void 0 : e.target) && ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.setSelectionRange)) {
6
11
  var start = e.target.selectionStart;
7
12
  var end = e.target.selectionEnd;
8
- e.target.value = e.target.value.toString().toLocaleUpperCase('tr');
13
+ e.target.value = e.target.value.toString().toLocaleUpperCase('tr-TR');
9
14
  e.target.setSelectionRange(start, end);
10
15
  }
11
16
  }
12
- export function tumuKucukCevir(e) {
17
+ export function inputTumuKucukCevir(e) {
13
18
  var _a;
14
19
  if ((e === null || e === void 0 ? void 0 : e.target) && ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.setSelectionRange)) {
15
20
  var start = e.target.selectionStart;
16
21
  var end = e.target.selectionEnd;
17
- e.target.value = e.target.value.toString().toLocaleLowerCase('tr');
22
+ e.target.value = e.target.value.toString().toLocaleLowerCase('tr-TR');
18
23
  e.target.setSelectionRange(start, end);
19
24
  }
20
25
  }
21
- export function seoCevirFunction(e) {
26
+ export var convertLowerCase = function (text) {
27
+ if (text === void 0) { text = ''; }
28
+ return text.toString().toLocaleLowerCase('tr-TR');
29
+ };
30
+ export var convertForSearch = function (value) {
31
+ var data = value === null || value === void 0 ? void 0 : value.toString().toLocaleLowerCase('tr-TR');
32
+ data = data.replace(/ö/g, 'o');
33
+ data = data.replace(/ç/g, 'c');
34
+ data = data.replace(/ş/g, 's');
35
+ data = data.replace(/ı/g, 'i');
36
+ data = data.replace(/ğ/g, 'g');
37
+ data = data.replace(/ü/g, 'u');
38
+ data = data.replace(/[^a-z\d]/g, ''); // %_- are allowed
39
+ data = data.replace(/^\s+|\s+$/g, '');
40
+ return data;
41
+ };
42
+ export function convertForSEO(e) {
22
43
  var _a;
23
44
  if ((e === null || e === void 0 ? void 0 : e.target) && ((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.setSelectionRange)) {
24
45
  var start = e.target.selectionStart;
@@ -61,3 +82,12 @@ export function getDomain(context) {
61
82
  }
62
83
  return url;
63
84
  }
85
+ export var uniqueID = function (key, length) {
86
+ if (key === void 0) { key = ''; }
87
+ if (length === void 0) { length = 16; }
88
+ return (key +
89
+ parseInt(Math.ceil(Math.random() * Date.now())
90
+ .toPrecision(length)
91
+ .toString()
92
+ .replace('.', '')));
93
+ };
@@ -0,0 +1,2 @@
1
+ export declare const onKeyboardSelection: ({ e, targetElement, itemClass, selectedClass, checkByValue, checkByInput, clear }: any) => null | undefined;
2
+ export declare function setScrollListPosition(targetElement: any): void;
@@ -0,0 +1,114 @@
1
+ export var onKeyboardSelection = function (_a) {
2
+ var e = _a.e, targetElement = _a.targetElement, _b = _a.itemClass, itemClass = _b === void 0 ? "item" : _b, _c = _a.selectedClass, selectedClass = _c === void 0 ? "selected" : _c, checkByValue = _a.checkByValue, checkByInput = _a.checkByInput, clear = _a.clear;
3
+ if (!targetElement.current)
4
+ return null;
5
+ var config = {
6
+ e: e,
7
+ itemClass: itemClass,
8
+ selectedClass: selectedClass,
9
+ };
10
+ function selectEnter() {
11
+ if (!targetElement.current)
12
+ return null;
13
+ var text = targetElement.current.querySelector("".concat(config.itemClass, ".").concat(config.selectedClass));
14
+ if (text) {
15
+ checkByValue(text.dataset.value);
16
+ }
17
+ else if (targetElement.current.querySelectorAll("".concat(config.itemClass)).length > 0) {
18
+ var target = targetElement.current.querySelectorAll("".concat(config.itemClass, ".").concat(config.selectedClass))[0];
19
+ checkByValue(target.dataset.value);
20
+ }
21
+ else {
22
+ clear(true, true);
23
+ }
24
+ }
25
+ function selectFirst() {
26
+ if (!targetElement.current)
27
+ return null;
28
+ var showList = targetElement.current.querySelectorAll("".concat(config.itemClass));
29
+ if (showList.length > 0) {
30
+ showList[0].classList.add(config.selectedClass);
31
+ }
32
+ }
33
+ function selectLast() {
34
+ if (!targetElement.current)
35
+ return null;
36
+ var showList = targetElement.current.querySelectorAll("".concat(config.itemClass));
37
+ if (showList.length > 0) {
38
+ showList[showList.length - 1].classList.add(config.selectedClass);
39
+ }
40
+ }
41
+ function selectNext(element) {
42
+ element.classList.remove(config.selectedClass);
43
+ var next = element.nextElementSibling;
44
+ if (next && next.nodeType !== -1) {
45
+ if (next.classList.contains("item")) {
46
+ next.classList.add(config.selectedClass);
47
+ }
48
+ else {
49
+ selectNext(next);
50
+ }
51
+ }
52
+ else {
53
+ selectFirst();
54
+ }
55
+ }
56
+ function selectPrev(element) {
57
+ element.classList.remove(config.selectedClass);
58
+ var next = element.previousElementSibling;
59
+ if (next && next.nodeType !== -1) {
60
+ if (next.classList.contains("item")) {
61
+ next.classList.add(config.selectedClass);
62
+ }
63
+ else {
64
+ selectPrev(next);
65
+ }
66
+ }
67
+ else {
68
+ selectLast();
69
+ }
70
+ }
71
+ var selected = targetElement.current.querySelector("".concat(config.itemClass, ".").concat(config.selectedClass));
72
+ if (e.which == 40) {
73
+ if (selected) {
74
+ selectNext(selected);
75
+ }
76
+ else {
77
+ selectFirst();
78
+ }
79
+ }
80
+ else if (e.which == 38) {
81
+ if (selected) {
82
+ selectPrev(selected);
83
+ }
84
+ else {
85
+ selectLast();
86
+ }
87
+ }
88
+ else if (e.which == 35) {
89
+ selectLast();
90
+ }
91
+ else if (e.which == 36) {
92
+ selectFirst();
93
+ }
94
+ else if (e.which == 13) {
95
+ selectEnter();
96
+ }
97
+ else if (e.which == 9) {
98
+ checkByInput();
99
+ }
100
+ setScrollListPosition(targetElement);
101
+ };
102
+ export function setScrollListPosition(targetElement) {
103
+ if (targetElement.current) {
104
+ var position = 0;
105
+ var text = targetElement.current.querySelector(".selected");
106
+ if (text) {
107
+ position = text.offsetTop - 35;
108
+ }
109
+ else if (targetElement.current.querySelector(".active")) {
110
+ position = targetElement.current.querySelector(".active").offsetTop - 35;
111
+ }
112
+ targetElement.current.scrollTop = position;
113
+ }
114
+ }
@@ -1,6 +1,6 @@
1
- import { decData, encData } from "./encData";
2
- import { isDev } from "../baseFunctions";
3
- var storageAvailable = typeof Storage === "undefined" || !window.localStorage ? false : true;
1
+ import { decData, encData } from './encData';
2
+ import { isDev } from '../baseFunctions';
3
+ var storageAvailable = typeof Storage === 'undefined' || !window.localStorage ? false : true;
4
4
  export var setLocalStorage = function (key, value) {
5
5
  if (!storageAvailable)
6
6
  return false;
@@ -9,7 +9,7 @@ export var setLocalStorage = function (key, value) {
9
9
  return true;
10
10
  }
11
11
  catch (e) {
12
- isDev && console.log("ERROR => localStorage =>", e);
12
+ isDev && console.log('ERROR => localStorage =>', e);
13
13
  return false;
14
14
  }
15
15
  };
@@ -21,7 +21,7 @@ export var getLocalStorage = function (key) {
21
21
  return saved ? decData(saved) : null;
22
22
  }
23
23
  catch (e) {
24
- isDev && console.log("ERROR => localStorage =>", e);
24
+ isDev && console.log('ERROR => localStorage =>', e);
25
25
  return null;
26
26
  }
27
27
  };
@@ -33,7 +33,7 @@ export var removeLocalStorage = function (key) {
33
33
  return true;
34
34
  }
35
35
  catch (e) {
36
- isDev && console.log("ERROR => localStorage =>", e);
36
+ isDev && console.log('ERROR => localStorage =>', e);
37
37
  return false;
38
38
  }
39
39
  };
@@ -45,7 +45,7 @@ export var clearLocalStorage = function () {
45
45
  return true;
46
46
  }
47
47
  catch (e) {
48
- isDev && console.log("ERROR => localStorage =>", e);
48
+ isDev && console.log('ERROR => localStorage =>', e);
49
49
  return false;
50
50
  }
51
51
  };
@@ -1,10 +1,10 @@
1
1
  import { __assign } from "tslib";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useCallback, useEffect, useRef, useState } from 'react';
4
- import { seoCevirFunction, tumuBuyukCevir, tumuKucukCevir } from '../_lib/baseFunctions';
5
- import { applyInputMask } from '../_lib/inputMask';
6
- import { alert_add } from '../alert';
4
+ import { convertForSEO, inputTumuBuyukCevir, inputTumuKucukCevir } from '../_lib/baseFunctions';
7
5
  import { Dialog } from './Dialog';
6
+ import { alert_add } from '../alert';
7
+ import { applyInputMask } from '../_lib/inputMask';
8
8
  import styles from './styles/Input.module.css';
9
9
  export var Input = function (_a) {
10
10
  var componentRef = _a.componentRef, inputRef = _a.inputRef, className = _a.className, propsComponent = _a.propsComponent, propsInput = _a.propsInput, id = _a.id, name = _a.name, value = _a.value, type = _a.type, label = _a.label, startAdornment = _a.startAdornment, endAdornment = _a.endAdornment, placeholder = _a.placeholder, onChange = _a.onChange, onFocus = _a.onFocus, onBlur = _a.onBlur, onClick = _a.onClick, onKeyPress = _a.onKeyPress, onKeyUp = _a.onKeyUp, onKeyDown = _a.onKeyDown, disabled = _a.disabled, required = _a.required, loading = _a.loading, autoFocus = _a.autoFocus, select = _a.select, _b = _a.valueKey, valueKey = _b === void 0 ? 'value' : _b, _c = _a.labelKey, labelKey = _c === void 0 ? 'label' : _c, ilkSec = _a.ilkSec, multiline = _a.multiline, rows = _a.rows, sadeceYazi = _a.sadeceYazi, sadeceSayi = _a.sadeceSayi, tumuBuyuk = _a.tumuBuyuk, tumuKucuk = _a.tumuKucuk, seoCevir = _a.seoCevir, dosyaNoGiris = _a.dosyaNoGiris, fileNameGiris = _a.fileNameGiris, dateGecmisKontrol = _a.dateGecmisKontrol, autoSelectText = _a.autoSelectText, _d = _a.mask, mask = _d === void 0 ? '' : _d, _e = _a.maskSettings, maskSettings = _e === void 0 ? {
@@ -66,11 +66,11 @@ export var Input = function (_a) {
66
66
  }, [mask]);
67
67
  var Change = useCallback(function (e) {
68
68
  if (tumuBuyuk)
69
- tumuBuyukCevir(e);
69
+ inputTumuBuyukCevir(e);
70
70
  if (tumuKucuk)
71
- tumuKucukCevir(e);
71
+ inputTumuKucukCevir(e);
72
72
  if (seoCevir)
73
- seoCevirFunction(e);
73
+ convertForSEO(e);
74
74
  setInputFilled(e.target.value.length > 0);
75
75
  onChange ? onChange(e) : null;
76
76
  }, [onChange, seoCevir, tumuBuyuk, tumuKucuk]);
@@ -1,22 +1,23 @@
1
- import React from 'react';
2
- import { PropsInput } from './Input';
1
+ /// <reference types="react" />
2
+ import { PropsInput } from './index';
3
3
  type typeList = {
4
4
  value?: string;
5
5
  label?: string;
6
- [key: string | number]: any;
7
- }[];
6
+ [key: string]: any;
7
+ };
8
+ type typeValue = string | number | undefined;
9
+ type typeVoidFunction = () => void;
8
10
  interface Props extends PropsInput {
9
- autoCompleteList?: typeList;
10
- onChange?: (e: any) => void;
11
- value: string | number | undefined;
11
+ autoCompleteList?: typeList[];
12
+ isDataFromApi: boolean;
13
+ value: typeValue;
12
14
  valueKey?: string;
13
15
  labelKey?: string;
14
- itemComponent?: any;
15
- isDataFromApi?: boolean;
16
- parentInputValue?: string | number | undefined;
16
+ itemComponent?: (option: typeList) => React.ReactNode;
17
+ parentInputValue?: typeValue;
18
+ onChange?: (e: any) => void;
17
19
  onText?: (text: string) => void;
18
20
  onSelect?: (item: any) => void;
19
- onLoad?: (value: string | number) => void;
20
21
  ilkSec?: boolean;
21
22
  newCreate?: boolean;
22
23
  style?: React.CSSProperties;
@@ -25,13 +26,13 @@ interface Props extends PropsInput {
25
26
  loadingMessage?: string;
26
27
  notFoundMessage?: string;
27
28
  }
28
- type handle = {
29
+ export interface SearchableInputRef {
30
+ setAutoCompleteList: (list: typeList[], value?: typeValue, callback?: typeVoidFunction) => void;
31
+ clear: (openList?: boolean, focusInput?: boolean) => void;
29
32
  open: () => void;
30
33
  close: () => void;
31
- checkByValue: (value: string, openList: boolean) => void;
34
+ checkByValue: (value: typeValue, openList?: boolean) => void;
32
35
  setLoading: (loading: boolean) => void;
33
- setAutoCompleteList: (list: typeList, value?: string | null) => void;
34
- clear: (openList?: boolean, focusInput?: boolean) => void;
35
- };
36
- export declare const SearchableInput: React.ForwardRefExoticComponent<Props & React.RefAttributes<handle>>;
36
+ }
37
+ export declare const SearchableInput: import("react").ForwardRefExoticComponent<Props & import("react").RefAttributes<SearchableInputRef>>;
37
38
  export {};
@@ -1,24 +1,41 @@
1
1
  import { __assign, __rest, __spreadArray } from "tslib";
2
2
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import React, { useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
4
- import { Input } from './Input';
5
- import { isDev } from '../_lib/baseFunctions';
3
+ import { Button, Input } from './index';
4
+ import { convertForSearch, convertLowerCase } from '../_lib/baseFunctions';
5
+ import { forwardRef, useCallback, useEffect, useImperativeHandle, useLayoutEffect, useMemo, useRef, useState } from 'react';
6
+ import { onKeyboardSelection, setScrollListPosition } from '../_lib/listFunctions';
6
7
  import { Icon } from '../icon';
7
- import { Button } from './Button';
8
8
  import styles from './styles/SearchableInput.module.css';
9
- var Component = function (_a, forwardedRef) {
10
- var _b = _a.autoCompleteList, autoCompleteList = _b === void 0 ? [] : _b, _c = _a.isDataFromApi, isDataFromApi = _c === void 0 ? false : _c, onText = _a.onText, onSelect = _a.onSelect, onLoad = _a.onLoad, onChange = _a.onChange, _d = _a.newCreate, newCreate = _d === void 0 ? false : _d, name = _a.name, value = _a.value, itemComponent = _a.itemComponent, inputRef = _a.inputRef, _e = _a.valueKey, valueKey = _e === void 0 ? 'value' : _e, _f = _a.labelKey, labelKey = _f === void 0 ? 'label' : _f, placeholder = _a.placeholder, endAdornment = _a.endAdornment, style = _a.style, disabled = _a.disabled, parentInputValue = _a.parentInputValue, _g = _a.listPositionRelative, listPositionRelative = _g === void 0 ? false : _g, _h = _a.loadingMessage, loadingMessage = _h === void 0 ? 'Lütfen bekleyiniz...' : _h, _j = _a.notFoundMessage, notFoundMessage = _j === void 0 ? 'Kayıt bulunamadı...' : _j, _k = _a.ilkSec, ilkSec = _k === void 0 ? false : _k, other = __rest(_a, ["autoCompleteList", "isDataFromApi", "onText", "onSelect", "onLoad", "onChange", "newCreate", "name", "value", "itemComponent", "inputRef", "valueKey", "labelKey", "placeholder", "endAdornment", "style", "disabled", "parentInputValue", "listPositionRelative", "loadingMessage", "notFoundMessage", "ilkSec"]);
9
+ export var SearchableInput = forwardRef(function (_a, ref) {
10
+ var autoCompleteList = _a.autoCompleteList, isDataFromApi = _a.isDataFromApi, name = _a.name, value = _a.value, parentInputValue = _a.parentInputValue, disabled = _a.disabled, itemComponent = _a.itemComponent, _b = _a.valueKey, valueKey = _b === void 0 ? 'value' : _b, _c = _a.labelKey, labelKey = _c === void 0 ? 'label' : _c, onSelect = _a.onSelect, onChange = _a.onChange, onText = _a.onText, style = _a.style, _d = _a.listPositionRelative, listPositionRelative = _d === void 0 ? false : _d, _e = _a.loadingMessage, loadingMessage = _e === void 0 ? 'Lütfen bekleyiniz...' : _e, _f = _a.notFoundMessage, notFoundMessage = _f === void 0 ? 'Kayıt bulunamadı...' : _f, placeholder = _a.placeholder, endAdornment = _a.endAdornment, _g = _a.ilkSec, ilkSec = _g === void 0 ? false : _g, _h = _a.newCreate, newCreate = _h === void 0 ? false : _h, inputRef = _a.inputRef, other = __rest(_a, ["autoCompleteList", "isDataFromApi", "name", "value", "parentInputValue", "disabled", "itemComponent", "valueKey", "labelKey", "onSelect", "onChange", "onText", "style", "listPositionRelative", "loadingMessage", "notFoundMessage", "placeholder", "endAdornment", "ilkSec", "newCreate", "inputRef"]);
11
11
  var refMain = useRef(null);
12
12
  var refInput = useRef(null);
13
- var refComponentInput = useRef(null);
14
13
  var refList = useRef(null);
15
- var _l = useState([]), data = _l[0], setData = _l[1];
14
+ var _j = useState(autoCompleteList !== null && autoCompleteList !== void 0 ? autoCompleteList : []), data = _j[0], setData = _j[1];
15
+ var _k = useState(value !== null && value !== void 0 ? value : undefined), selectedValue = _k[0], setSelectedValue = _k[1];
16
+ var _l = useState(parentInputValue !== null && parentInputValue !== void 0 ? parentInputValue : undefined), parentValue = _l[0], setParentValue = _l[1];
16
17
  var _m = useState(''), text = _m[0], setText = _m[1]; //Inputta görünen
17
18
  var _o = useState(''), filter = _o[0], setFilter = _o[1]; // Filtrelemeye tabi tutulan
18
- var _p = useState(false), open = _p[0], setOpen = _p[1];
19
- var _q = useState(isDataFromApi && autoCompleteList.length === 0), loading = _q[0], setLoading = _q[1];
20
- var _r = useState({ created: false }), newItemCreate = _r[0], setNewItemCreate = _r[1];
21
- useImperativeHandle(forwardedRef, function () { return ({
19
+ var _p = useState({ created: false }), newItemCreate = _p[0], setNewItemCreate = _p[1];
20
+ var _q = useState(false), open = _q[0], setOpen = _q[1];
21
+ var _r = useState(isDataFromApi && (!autoCompleteList || (autoCompleteList === null || autoCompleteList === void 0 ? void 0 : autoCompleteList.length) == 0)), loading = _r[0], setLoading = _r[1];
22
+ useImperativeHandle(ref, function () { return ({
23
+ setAutoCompleteList: function (list, value) {
24
+ if (value === void 0) { value = undefined; }
25
+ if (autoCompleteList && (autoCompleteList === null || autoCompleteList === void 0 ? void 0 : autoCompleteList.length) > 0) {
26
+ alert('AutoCompleteList zaten tanımlı olduğundan dışardan data seti değiştirilemez.');
27
+ return;
28
+ }
29
+ setData(list);
30
+ value && sendChange(value);
31
+ setLoading(false);
32
+ // isDev && console.log('setAutoCompleteList =>', name, value, list);
33
+ },
34
+ clear: function (openList, focusInput) {
35
+ if (openList === void 0) { openList = false; }
36
+ if (focusInput === void 0) { focusInput = false; }
37
+ return clear(openList, focusInput);
38
+ },
22
39
  open: function () {
23
40
  setOpen(true);
24
41
  refInput.current && refInput.current.focus();
@@ -28,68 +45,46 @@ var Component = function (_a, forwardedRef) {
28
45
  if (openList === void 0) { openList = false; }
29
46
  return checkByValue(value, openList);
30
47
  },
31
- setLoading: function (value) { return setLoading(value); },
32
- setAutoCompleteList: function (list, value) {
33
- if (value === void 0) { value = null; }
34
- setData(list);
35
- if (value)
36
- checkByValue(value, false, list);
37
- setLoading(false);
38
- },
39
- clear: function (openList, focusInput) {
40
- if (openList === void 0) { openList = false; }
41
- if (focusInput === void 0) { focusInput = false; }
42
- return clear(openList, focusInput);
43
- }
44
- }); });
45
- var handleUpdatePosition = function () {
46
- if (open && !listPositionRelative && refMain) {
47
- setFixedPosition(refMain);
48
- }
49
- };
50
- useEffect(function () {
51
- if (onLoad)
52
- onLoad(value !== null && value !== void 0 ? value : '');
53
- }, []);
48
+ setLoading: function (value) { return setLoading(value); }
49
+ }); }, [autoCompleteList, data, value]);
54
50
  useEffect(function () {
55
51
  if (inputRef)
56
52
  inputRef.current = refInput.current;
57
53
  }, [refInput.current]);
58
54
  useEffect(function () {
59
- if (parentInputValue !== undefined && parentInputValue !== null) {
60
- clear(false);
61
- isDev && console.log(name, 'parentInputValueDeğişti =>', parentInputValue);
62
- }
63
- }, [parentInputValue]);
64
- useEffect(function () {
65
- if (autoCompleteList && Array.isArray(autoCompleteList) && autoCompleteList.length > 0) {
55
+ if (autoCompleteList && Array.isArray(autoCompleteList) && JSON.stringify(autoCompleteList) !== JSON.stringify(data) && autoCompleteList.length > 0) {
66
56
  setData(autoCompleteList);
67
- isDev && console.log('autoCompleteList =>', name, autoCompleteList);
57
+ // isDev && console.log('autoCompleteList =>', name, autoCompleteList, data);
68
58
  }
69
59
  }, [autoCompleteList]);
70
60
  useEffect(function () {
61
+ // isDev && console.log('data =>', name, data, 'selectedValue =>', selectedValue, 'value =>', value);
71
62
  if (data.length > 0) {
72
- if (value && value.toString().length > 0) {
73
- if (!isDataFromApi)
74
- checkByValue(value, open);
75
- }
76
- else {
77
- if (ilkSec)
78
- checkByValue(data[0][valueKey], false);
63
+ setLoading(false);
64
+ checkByValue(selectedValue, open);
65
+ if (!value) {
66
+ ilkSec && checkByValue(data[0][valueKey], false);
79
67
  }
80
68
  }
69
+ else {
70
+ !isDataFromApi && clear();
71
+ }
81
72
  }, [data]);
73
+ // Seçim değişikliğinde parent'ı bilgilendir
82
74
  useEffect(function () {
83
- if (data.length > 0) {
84
- if (value && value.toString().length > 0) {
85
- checkByValue(value, open);
86
- }
87
- else {
88
- if (!isDataFromApi)
89
- clear(false);
90
- }
75
+ // isDev && console.log('selectedValue =>', name, selectedValue, 'value =>', value);
76
+ if ((value === null || value === void 0 ? void 0 : value.toString()) != (selectedValue === null || selectedValue === void 0 ? void 0 : selectedValue.toString())) {
77
+ checkByValue(value, open);
78
+ // isDev && console.log('value Kontrol ediliyor', value, selectedValue);
91
79
  }
92
80
  }, [value]);
81
+ useEffect(function () {
82
+ if (parentInputValue !== parentValue) {
83
+ setParentValue(parentInputValue);
84
+ clear(false);
85
+ // isDev && console.log(name, 'parentInputValueDeğişti =>', parentInputValue);
86
+ }
87
+ }, [parentInputValue]);
93
88
  useEffect(function () {
94
89
  var checkHideBackDrop = function (e) {
95
90
  if (open && refMain.current && !refMain.current.contains(e.target)) {
@@ -104,7 +99,7 @@ var Component = function (_a, forwardedRef) {
104
99
  if (refMain.current)
105
100
  refMain.current.addEventListener('keydown', checkESC);
106
101
  if (open) {
107
- setScrollPosition();
102
+ setScrollListPosition(refList);
108
103
  if (!listPositionRelative) {
109
104
  window.addEventListener('scroll', handleUpdatePosition, true);
110
105
  window.addEventListener('resize', handleUpdatePosition);
@@ -119,84 +114,39 @@ var Component = function (_a, forwardedRef) {
119
114
  };
120
115
  }, [open]);
121
116
  useLayoutEffect(function () { return handleUpdatePosition(); }, [open]);
122
- var cevirTumuKucuk = function (text) {
123
- if (text === void 0) { text = ''; }
124
- return text.toString().toLocaleLowerCase('tr-TR');
125
- };
126
- var convertForSearch = useCallback(function (value) {
127
- var data = cevirTumuKucuk(value);
128
- data = data.replace(/ö/g, 'o');
129
- data = data.replace(/ç/g, 'c');
130
- data = data.replace(/ş/g, 's');
131
- data = data.replace(/ı/g, 'i');
132
- data = data.replace(/ğ/g, 'g');
133
- data = data.replace(/ü/g, 'u');
134
- data = data.replace(/[^a-z\d]/g, ''); // %_- are allowed
135
- data = data.replace(/^\s+|\s+$/g, '');
136
- return data;
137
- }, [cevirTumuKucuk]);
138
- var filteredData = useMemo(function () {
139
- var _a;
140
- var list;
141
- if (filter.length > 0) {
142
- list = data.filter(function (item) { return convertForSearch(item[labelKey]).includes(convertForSearch(filter)) || item[labelKey] == filter; });
143
- }
144
- else {
145
- list = data;
146
- }
147
- if (newCreate && text.length > 0) {
148
- var filterText = data.find(function (item) { return item[labelKey].toString().toLowerCase() === text.toString().toLowerCase(); });
149
- if (!filterText) {
150
- var newItem = (_a = {}, _a[labelKey] = text, _a[valueKey] = text, _a.create = true, _a);
151
- list = __spreadArray([newItem], list, true);
152
- setNewItemCreate(newItem);
153
- }
154
- else {
155
- if (newItemCreate.create)
156
- setNewItemCreate({ create: false });
157
- }
158
- }
159
- return list;
160
- }, [data, filter, newCreate, text, valueKey, labelKey]);
161
- var setValue = useCallback(function (result, openList) {
117
+ var setValue = useCallback(function (item, openList) {
118
+ var newValue = item && item[valueKey] ? item[valueKey] : '';
119
+ var newLabel = item && item[labelKey] ? item[labelKey] : '';
162
120
  setOpen(openList);
163
- var newValue = result && result[valueKey] ? result[valueKey] : '';
164
- if (result) {
165
- var newLabel = result && result[labelKey] ? result[labelKey] : '';
166
- setText(newLabel);
167
- }
121
+ setText(newLabel);
122
+ // isDev && console.log('setValue', newValue, 'item', item, 'value', value);
123
+ if (newValue === selectedValue)
124
+ return;
168
125
  setFilter('');
169
- if (onChange && newValue != value) {
170
- onChange({
171
- target: {
172
- name: name,
173
- value: newValue
174
- }
175
- });
176
- }
177
- if (onSelect)
178
- onSelect(result);
179
- }, [onChange, onSelect, name, value, valueKey, labelKey]);
180
- var Change = useCallback(function (e) {
181
- setValue(false, true);
126
+ setSelectedValue(newValue);
127
+ onChange && sendChange(newValue);
128
+ onSelect && onSelect(item);
129
+ }, [onChange, onSelect, name, selectedValue, valueKey, labelKey]);
130
+ var textInputOnChange = useCallback(function (e) {
131
+ setSelectedValue(undefined);
182
132
  setText(e.target.value);
183
133
  setFilter(e.target.value.trim());
184
134
  setOpen(true);
185
- if (onText)
186
- onText(e.target.value);
135
+ onText && onText(e.target.value);
187
136
  }, [setValue, onText]);
188
137
  var checkByValue = useCallback(function (value, openList, list) {
189
138
  if (openList === void 0) { openList = false; }
190
139
  if (list === void 0) { list = []; }
191
140
  var targetList = list.length > 0 ? list : data;
192
- var find = Object.values(targetList).find(function (item) { return cevirTumuKucuk(item[valueKey]) === cevirTumuKucuk(value); });
141
+ var find = Object.values(targetList).find(function (item) { return convertLowerCase(item[valueKey]) === convertLowerCase(value); });
193
142
  if (!find && newCreate && newItemCreate.create) {
194
143
  find = newItemCreate;
195
144
  }
145
+ // isDev && console.log('find', find, 'value', value, data);
196
146
  setValue(find, openList);
197
147
  }, [data, valueKey, newCreate, newItemCreate, setValue]);
198
148
  var checkByInput = useCallback(function () {
199
- var findByLabel = data.find(function (item) { return cevirTumuKucuk(item[labelKey]) === cevirTumuKucuk(refInput.current.value); });
149
+ var findByLabel = data.find(function (item) { var _a; return convertLowerCase(item[labelKey]) === convertLowerCase((_a = refInput.current) === null || _a === void 0 ? void 0 : _a.value); });
200
150
  if (findByLabel && value == findByLabel[valueKey]) {
201
151
  setOpen(false);
202
152
  return;
@@ -215,120 +165,62 @@ var Component = function (_a, forwardedRef) {
215
165
  if (focusInput === void 0) { focusInput = false; }
216
166
  setFilter('');
217
167
  setText('');
218
- setValue(false, openList);
219
- if (onText)
220
- onText('');
221
- if (focusInput)
222
- (_a = refInput === null || refInput === void 0 ? void 0 : refInput.current) === null || _a === void 0 ? void 0 : _a.focus();
168
+ setValue(undefined, openList);
169
+ onText && onText('');
170
+ focusInput && ((_a = refInput === null || refInput === void 0 ? void 0 : refInput.current) === null || _a === void 0 ? void 0 : _a.focus());
223
171
  }, [setValue, onText]);
224
- function setScrollPosition() {
225
- if (refList.current) {
226
- var position = 0;
227
- var text_1 = refList.current.querySelector('li.item.selected');
228
- if (text_1) {
229
- position = text_1.offsetTop - 35;
230
- }
231
- else if (refList.current.querySelector('li.item.active')) {
232
- position = refList.current.querySelector('li.item.active').offsetTop - 35;
233
- }
234
- refList.current.scrollTop = position;
235
- }
236
- }
237
- var onKeyDown = function (e) {
238
- if (!open)
239
- return null;
240
- function selectEnter() {
241
- var text = refList.current.querySelector('li.item.selected');
242
- if (text) {
243
- checkByValue(text.dataset.value);
244
- }
245
- else if (refList.current.querySelectorAll('li.item').length > 0) {
246
- checkByValue(refList.current.querySelectorAll('li.item')[0].dataset.value);
247
- }
248
- else {
249
- clear(true, true);
250
- }
251
- }
252
- function selectFirst() {
253
- var showList = refList.current.querySelectorAll('li.item');
254
- if (showList.length > 0) {
255
- showList[0].classList.add('selected');
256
- }
257
- }
258
- function selectLast() {
259
- var showList = refList.current.querySelectorAll('li.item');
260
- if (showList.length > 0) {
261
- showList[showList.length - 1].classList.add('selected');
262
- }
172
+ var sendChange = useCallback(function (value) {
173
+ if (onChange && value !== selectedValue) {
174
+ onChange({ target: { name: name, value: value } });
263
175
  }
264
- function selectNext(element) {
265
- element.classList.remove('selected');
266
- var next = element.nextElementSibling;
267
- if (next && next.nodeType !== -1) {
268
- if (next.classList.contains('item')) {
269
- next.classList.add('selected');
270
- }
271
- else {
272
- selectNext(next);
273
- }
274
- }
275
- else {
276
- selectFirst();
277
- }
278
- }
279
- function selectPrev(element) {
280
- element.classList.remove('selected');
281
- var next = element.previousElementSibling;
282
- if (next && next.nodeType !== -1) {
283
- if (next.classList.contains('item')) {
284
- next.classList.add('selected');
285
- }
286
- else {
287
- selectPrev(next);
288
- }
289
- }
290
- else {
291
- selectLast();
292
- }
176
+ }, [onChange, name]);
177
+ var filteredData = useMemo(function () {
178
+ var _a;
179
+ var list;
180
+ if (filter.length > 0) {
181
+ list = data.filter(function (item) { return convertForSearch(item[labelKey]).includes(convertForSearch(filter)) || item[labelKey] == filter; });
293
182
  }
294
- var selected = refList.current.querySelector('li.item.selected');
295
- if (e.which == 40) {
296
- if (selected) {
297
- selectNext(selected);
298
- }
299
- else {
300
- selectFirst();
301
- }
183
+ else {
184
+ list = data;
302
185
  }
303
- else if (e.which == 38) {
304
- if (selected) {
305
- selectPrev(selected);
186
+ if (newCreate && text.length > 0) {
187
+ var filterText = data.find(function (item) { return item[labelKey].toString().toLowerCase() === text.toString().toLowerCase(); });
188
+ if (!filterText) {
189
+ var newItem = (_a = {}, _a[labelKey] = text, _a[valueKey] = text, _a.create = true, _a);
190
+ list = __spreadArray([newItem], list, true);
191
+ setNewItemCreate(newItem);
306
192
  }
307
193
  else {
308
- selectLast();
194
+ if (newItemCreate.create)
195
+ setNewItemCreate({ create: false });
309
196
  }
310
197
  }
311
- else if (e.which == 35) {
312
- selectLast();
313
- }
314
- else if (e.which == 36) {
315
- selectFirst();
316
- }
317
- else if (e.which == 13) {
318
- selectEnter();
319
- }
320
- else if (e.which == 9) {
321
- checkByInput();
198
+ return list;
199
+ }, [data, filter, newCreate, text, valueKey, labelKey]);
200
+ var handleUpdatePosition = function () {
201
+ if (open && !listPositionRelative && refMain) {
202
+ setFixedPosition(refMain);
322
203
  }
323
- setScrollPosition();
324
204
  };
325
- return (_jsxs("div", { ref: refMain, className: styles.searchableInputComponent, onKeyDown: onKeyDown, style: style, children: [_jsx(Input, __assign({}, other, { name: name, value: text, inputRef: refInput, componentRef: refComponentInput, onFocus: function () { return setOpen(true); }, onChange: Change, endAdornment: !disabled && (_jsxs("div", { style: { marginRight: 5 }, tabIndex: -1, children: [_jsx(Button, { title: 'Temizle', tabIndex: -1, hidden: !(text && text.length > 0), onClick: function () { return clear(true, true); }, onlyIcon: _jsx(Icon, { name: 'close', style: { color: '#444' } }) }), endAdornment, _jsx(Button, { tabIndex: -1, hidden: !(data.length > 0), onClick: function () { return setOpen(!open); }, onlyIcon: _jsx(Icon, { name: open ? 'keyboard_arrow_up' : 'keyboard_arrow_down', style: { color: '#444' } }) })] })), placeholder: loading ? 'Lütfen bekleyiniz...' : placeholder, loading: loading, disabled: disabled, propsInput: __assign(__assign({}, other === null || other === void 0 ? void 0 : other.propsInput), { autoComplete: 'off' }) })), open && (_jsx("div", { className: 'listDiv', "data-relative": listPositionRelative, children: _jsxs("ul", { ref: refList, className: "list ".concat(open ? 'open' : ''), children: [(filteredData.length === 0 || loading) && _jsx("div", { className: "message ".concat(loading ? 'loading' : ''), children: loading ? loadingMessage : notFoundMessage }), filteredData.map(function (item, key) {
205
+ var onKeyDown = function (e) {
206
+ if (!open || !refList.current)
207
+ return null;
208
+ onKeyboardSelection({
209
+ e: e,
210
+ targetElement: refList,
211
+ checkByInput: checkByInput,
212
+ checkByValue: checkByValue,
213
+ clear: clear,
214
+ itemClass: 'li.item',
215
+ selectedClass: 'selected'
216
+ });
217
+ };
218
+ return (_jsxs("div", { ref: refMain, className: styles.searchableInputComponent, onKeyDown: onKeyDown, style: style, children: [_jsx(Input, __assign({}, other, { inputRef: refInput, name: name, value: text, onFocus: function () { return !disabled && setOpen(true); }, onChange: textInputOnChange, endAdornment: !disabled && (_jsxs("div", { style: { marginRight: 5 }, tabIndex: -1, children: [_jsx(Button, { title: 'Temizle', tabIndex: -1, hidden: !(text && text.length > 0), onClick: function () { return clear(true, true); }, onlyIcon: _jsx(Icon, { name: 'close', style: { color: '#444' } }) }), endAdornment, _jsx(Button, { tabIndex: -1, hidden: !(data.length > 0), onClick: function () { return !disabled && setOpen(!open); }, onlyIcon: _jsx(Icon, { name: open ? 'keyboard_arrow_up' : 'keyboard_arrow_down', style: { color: '#444' } }) })] })), placeholder: loading ? 'Lütfen bekleyiniz...' : placeholder, loading: loading, disabled: disabled, propsInput: __assign(__assign({}, other === null || other === void 0 ? void 0 : other.propsInput), { autoComplete: 'off' }) })), open && (_jsx("div", { className: 'listDiv', "data-relative": listPositionRelative, children: _jsxs("ul", { ref: refList, className: "list ".concat(open ? 'open' : ''), children: [(filteredData.length === 0 || loading) && _jsx("div", { className: "message ".concat(loading ? 'loading' : ''), children: loading ? loadingMessage : notFoundMessage }), filteredData.map(function (item, key) {
326
219
  var itemValue = item[valueKey];
327
220
  var itemLabel = item[labelKey];
328
- return (_jsxs("li", { className: "item ".concat(itemValue === value ? 'active' : ''), "data-value": itemValue, "data-label": itemLabel, onClick: function () { return setValue(item, false); }, children: [item.create && _jsx("span", { className: 'newCreate', children: "Yeni Olu\u015Ftur: " }), itemComponent ? itemComponent(item) : itemLabel] }, key));
221
+ return (_jsxs("li", { className: "item ".concat(itemValue === selectedValue ? 'active' : ''), "data-value": itemValue, "data-label": itemLabel, onClick: function () { return setValue(item, false); }, children: [item.create && _jsx("span", { className: 'newCreate', children: "Yeni Olu\u015Ftur: " }), itemComponent ? itemComponent(item) : itemLabel] }, key));
329
222
  })] }) }))] }));
330
- };
331
- export var SearchableInput = React.forwardRef(Component);
223
+ });
332
224
  var setFixedPosition = function (refMain) {
333
225
  if (!refMain.current)
334
226
  return;
@@ -14,12 +14,12 @@
14
14
  border-radius: 6px;
15
15
  }
16
16
 
17
- .component[data-disabled="true"] {
17
+ .component[data-disabled='true'] {
18
18
  background: #ebebeb;
19
19
  }
20
20
 
21
- .component[data-disabled="true"],
22
- .component[data-disabled="true"] * {
21
+ .component[data-disabled='true'],
22
+ .component[data-disabled='true'] * {
23
23
  pointer-events: none;
24
24
  cursor: not-allowed;
25
25
  }
@@ -41,7 +41,7 @@
41
41
  color: transparent;
42
42
  }
43
43
 
44
- .component[data-disabled="true"] .loading:before {
44
+ .component[data-disabled='true'] .loading:before {
45
45
  background: #ebebeb;
46
46
  }
47
47
 
@@ -125,15 +125,15 @@
125
125
  display: block;
126
126
  min-width: 0;
127
127
  width: 100%;
128
- padding: 12px 14px;
128
+ padding: 9px 14px;
129
129
  border: none;
130
130
  outline: none;
131
131
  z-index: 1;
132
132
  text-overflow: ellipsis;
133
133
  border-radius: 6px;
134
134
  }
135
- .input[type="number"]::-webkit-outer-spin-button,
136
- .input[type="number"]::-webkit-inner-spin-button {
135
+ .input[type='number']::-webkit-outer-spin-button,
136
+ .input[type='number']::-webkit-inner-spin-button {
137
137
  appearance: none;
138
138
  }
139
139
 
@@ -169,7 +169,7 @@
169
169
  .loading:before {
170
170
  position: absolute;
171
171
  display: block;
172
- content: "";
172
+ content: '';
173
173
  z-index: 12;
174
174
  top: 2px;
175
175
  left: 2px;
@@ -182,7 +182,7 @@
182
182
  .loading:after {
183
183
  position: absolute;
184
184
  display: block;
185
- content: "";
185
+ content: '';
186
186
  z-index: 11;
187
187
  width: 12px;
188
188
  height: 12px;
@@ -2,7 +2,7 @@
2
2
  cursor: unset;
3
3
  }
4
4
  .searchableInputComponent input {
5
- padding: 12px 14px;
5
+
6
6
  }
7
7
 
8
8
  .searchableInputComponent :global(.listDiv) {
@@ -1,5 +1,6 @@
1
1
  export * from './_lib/baseFunctions';
2
2
  export * from './_lib/inputMask';
3
+ export * from './_lib/listFunctions';
3
4
  export * from './_lib/storage/cookies';
4
5
  export * from './_lib/storage/encData';
5
6
  export * from './_lib/storage/localStorage';
package/dist/esm/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  export * from './_lib/baseFunctions';
2
2
  export * from './_lib/inputMask';
3
+ export * from './_lib/listFunctions';
3
4
  export * from './_lib/storage/cookies';
4
5
  export * from './_lib/storage/encData';
5
6
  export * from './_lib/storage/localStorage';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@sydsoft/base",
3
3
  "private": false,
4
- "version": "1.41.0",
4
+ "version": "1.43.0",
5
5
  "description": "",
6
6
  "main": "./dist/cjs/index.js",
7
7
  "module": "./dist/esm/index.js",