@pallasoft/ps-input-components 3.6.0 → 3.7.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.
@@ -0,0 +1,17 @@
1
+ export interface PsTagInputProps {
2
+ className?: string;
3
+ errorText?: string;
4
+ helperText?: string;
5
+ hideLabel?: boolean;
6
+ isDisabled?: boolean;
7
+ isLoading?: boolean;
8
+ label: string;
9
+ max?: number;
10
+ name?: string;
11
+ onChange: (values: string[]) => void;
12
+ placeholder?: string;
13
+ removeLabel: (value: string) => string;
14
+ required?: boolean;
15
+ values: string[];
16
+ }
17
+ export declare const PsTagInput: ({ className, errorText, helperText, hideLabel, isDisabled, isLoading, label, max, name, onChange, placeholder, removeLabel, required, values, }: PsTagInputProps) => import("react").JSX.Element;
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsTagInput = void 0;
4
+ const jsx_runtime_1 = require("react/jsx-runtime");
5
+ const react_1 = require("react");
6
+ const ps_core_components_1 = require("@pallasoft/ps-core-components");
7
+ const ps_design_system_1 = require("@pallasoft/ps-design-system");
8
+ const ps_tag_input_config_1 = require("../constants/ps-tag-input-config");
9
+ const ps_tag_input_service_1 = require("../services/ps-tag-input-service");
10
+ const ps_field_skeleton_1 = require("./ps-field-skeleton");
11
+ const ps_form_control_1 = require("./ps-form-control");
12
+ const ps_required_mark_1 = require("./ps-required-mark");
13
+ const PsTagInput = ({ className, errorText, helperText, hideLabel, isDisabled = false, isLoading = false, label, max, name, onChange, placeholder, removeLabel, required, values, }) => {
14
+ const [draft, setDraft] = (0, react_1.useState)('');
15
+ const isFull = max !== undefined && values.length >= max;
16
+ if (isLoading)
17
+ return (0, jsx_runtime_1.jsx)(ps_field_skeleton_1.PsFieldSkeleton, { className: className, hideLabel: hideLabel, label: label });
18
+ const commit = (text) => {
19
+ if (text.trim() !== '')
20
+ onChange(ps_tag_input_service_1.PsTagInputService.add(values, text, max));
21
+ setDraft('');
22
+ };
23
+ const handleKeyDown = (event) => {
24
+ if (event.key === ps_tag_input_config_1.PsTagInputConfig.addKey) {
25
+ event.preventDefault();
26
+ commit(draft);
27
+ return;
28
+ }
29
+ if (event.key === ps_tag_input_config_1.PsTagInputConfig.removeKey && draft === '' && values.length > 0)
30
+ onChange(ps_tag_input_service_1.PsTagInputService.removeLast(values));
31
+ };
32
+ return ((0, jsx_runtime_1.jsx)(ps_form_control_1.PsFormControl, { className: className, errorText: errorText, helperText: helperText, children: (0, jsx_runtime_1.jsxs)("label", { className: 'block', children: [(0, jsx_runtime_1.jsxs)("span", { className: hideLabel ? 'sr-only' : 'ps-input-label', children: [label, (0, jsx_runtime_1.jsx)(ps_required_mark_1.PsRequiredMark, { isRequired: required })] }), (0, jsx_runtime_1.jsxs)("span", { className: ps_design_system_1.PallasoftClassNameService.merge('ps-input-control flex flex-wrap items-center gap-1.5 py-1.5', hideLabel ? '' : 'mt-2', isDisabled ? 'opacity-60' : ''), children: [values.map((value) => ((0, jsx_runtime_1.jsx)(ps_core_components_1.PsActiveFilterChip, { label: value, onRemove: () => {
33
+ if (!isDisabled)
34
+ onChange(ps_tag_input_service_1.PsTagInputService.remove(values, value));
35
+ }, removeLabel: removeLabel(value) }, value))), (0, jsx_runtime_1.jsx)("input", { "aria-invalid": errorText ? true : undefined, className: 'min-w-24 flex-1 bg-transparent text-sm font-semibold outline-none placeholder:font-medium placeholder:text-ink/45 disabled:cursor-not-allowed', disabled: isDisabled || isFull, name: name, onBlur: () => commit(draft), onChange: (event) => {
36
+ const text = event.target.value;
37
+ if (text.includes(ps_tag_input_config_1.PsTagInputConfig.separator))
38
+ commit(text);
39
+ else
40
+ setDraft(text);
41
+ }, onKeyDown: handleKeyDown, placeholder: values.length === 0 ? placeholder : undefined, value: draft })] })] }) }));
42
+ };
43
+ exports.PsTagInput = PsTagInput;
@@ -0,0 +1,5 @@
1
+ export declare const PsTagInputConfig: {
2
+ readonly addKey: "Enter";
3
+ readonly removeKey: "Backspace";
4
+ readonly separator: ",";
5
+ };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsTagInputConfig = void 0;
4
+ exports.PsTagInputConfig = {
5
+ addKey: 'Enter',
6
+ removeKey: 'Backspace',
7
+ separator: ',',
8
+ };
@@ -0,0 +1,39 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useState } from 'react';
3
+ import { PsActiveFilterChip } from '@pallasoft/ps-core-components';
4
+ import { PallasoftClassNameService } from '@pallasoft/ps-design-system';
5
+ import { PsTagInputConfig } from '../constants/ps-tag-input-config';
6
+ import { PsTagInputService } from '../services/ps-tag-input-service';
7
+ import { PsFieldSkeleton } from './ps-field-skeleton';
8
+ import { PsFormControl } from './ps-form-control';
9
+ import { PsRequiredMark } from './ps-required-mark';
10
+ export const PsTagInput = ({ className, errorText, helperText, hideLabel, isDisabled = false, isLoading = false, label, max, name, onChange, placeholder, removeLabel, required, values, }) => {
11
+ const [draft, setDraft] = useState('');
12
+ const isFull = max !== undefined && values.length >= max;
13
+ if (isLoading)
14
+ return _jsx(PsFieldSkeleton, { className: className, hideLabel: hideLabel, label: label });
15
+ const commit = (text) => {
16
+ if (text.trim() !== '')
17
+ onChange(PsTagInputService.add(values, text, max));
18
+ setDraft('');
19
+ };
20
+ const handleKeyDown = (event) => {
21
+ if (event.key === PsTagInputConfig.addKey) {
22
+ event.preventDefault();
23
+ commit(draft);
24
+ return;
25
+ }
26
+ if (event.key === PsTagInputConfig.removeKey && draft === '' && values.length > 0)
27
+ onChange(PsTagInputService.removeLast(values));
28
+ };
29
+ return (_jsx(PsFormControl, { className: className, errorText: errorText, helperText: helperText, children: _jsxs("label", { className: 'block', children: [_jsxs("span", { className: hideLabel ? 'sr-only' : 'ps-input-label', children: [label, _jsx(PsRequiredMark, { isRequired: required })] }), _jsxs("span", { className: PallasoftClassNameService.merge('ps-input-control flex flex-wrap items-center gap-1.5 py-1.5', hideLabel ? '' : 'mt-2', isDisabled ? 'opacity-60' : ''), children: [values.map((value) => (_jsx(PsActiveFilterChip, { label: value, onRemove: () => {
30
+ if (!isDisabled)
31
+ onChange(PsTagInputService.remove(values, value));
32
+ }, removeLabel: removeLabel(value) }, value))), _jsx("input", { "aria-invalid": errorText ? true : undefined, className: 'min-w-24 flex-1 bg-transparent text-sm font-semibold outline-none placeholder:font-medium placeholder:text-ink/45 disabled:cursor-not-allowed', disabled: isDisabled || isFull, name: name, onBlur: () => commit(draft), onChange: (event) => {
33
+ const text = event.target.value;
34
+ if (text.includes(PsTagInputConfig.separator))
35
+ commit(text);
36
+ else
37
+ setDraft(text);
38
+ }, onKeyDown: handleKeyDown, placeholder: values.length === 0 ? placeholder : undefined, value: draft })] })] }) }));
39
+ };
@@ -0,0 +1,5 @@
1
+ export const PsTagInputConfig = {
2
+ addKey: 'Enter',
3
+ removeKey: 'Backspace',
4
+ separator: ',',
5
+ };
package/dist/esm/index.js CHANGED
@@ -11,6 +11,9 @@ export * from './components/ps-field-skeleton';
11
11
  export * from './components/ps-form-control';
12
12
  export * from './components/ps-multi-select-input';
13
13
  export * from './components/ps-select-input';
14
+ export * from './components/ps-tag-input';
15
+ export * from './constants/ps-tag-input-config';
16
+ export * from './services/ps-tag-input-service';
14
17
  export * from './components/ps-text-area-input';
15
18
  export * from './components/ps-text-input';
16
19
  export * from './components/ps-toggle';
@@ -1 +1 @@
1
- {"type":"module"}
1
+ {"type":"module","sideEffects":false}
@@ -0,0 +1,27 @@
1
+ import { PsTagInputConfig } from '../constants/ps-tag-input-config';
2
+ export class PsTagInputService {
3
+ static parse(text) {
4
+ return text
5
+ .split(PsTagInputConfig.separator)
6
+ .map((entry) => entry.trim())
7
+ .filter((entry) => entry !== '');
8
+ }
9
+ static add(values, text, max) {
10
+ const taken = new Set(values.map((value) => value.toLowerCase()));
11
+ const next = [...values];
12
+ for (const entry of PsTagInputService.parse(text)) {
13
+ const key = entry.toLowerCase();
14
+ if (taken.has(key) || (max !== undefined && next.length >= max))
15
+ continue;
16
+ taken.add(key);
17
+ next.push(entry);
18
+ }
19
+ return next;
20
+ }
21
+ static remove(values, value) {
22
+ return values.filter((entry) => entry !== value);
23
+ }
24
+ static removeLast(values) {
25
+ return values.slice(0, values.length - 1);
26
+ }
27
+ }
package/dist/index.d.ts CHANGED
@@ -11,6 +11,9 @@ export * from './components/ps-field-skeleton';
11
11
  export * from './components/ps-form-control';
12
12
  export * from './components/ps-multi-select-input';
13
13
  export * from './components/ps-select-input';
14
+ export * from './components/ps-tag-input';
15
+ export * from './constants/ps-tag-input-config';
16
+ export * from './services/ps-tag-input-service';
14
17
  export * from './components/ps-text-area-input';
15
18
  export * from './components/ps-text-input';
16
19
  export * from './components/ps-toggle';
package/dist/index.js CHANGED
@@ -27,6 +27,9 @@ __exportStar(require("./components/ps-field-skeleton"), exports);
27
27
  __exportStar(require("./components/ps-form-control"), exports);
28
28
  __exportStar(require("./components/ps-multi-select-input"), exports);
29
29
  __exportStar(require("./components/ps-select-input"), exports);
30
+ __exportStar(require("./components/ps-tag-input"), exports);
31
+ __exportStar(require("./constants/ps-tag-input-config"), exports);
32
+ __exportStar(require("./services/ps-tag-input-service"), exports);
30
33
  __exportStar(require("./components/ps-text-area-input"), exports);
31
34
  __exportStar(require("./components/ps-text-input"), exports);
32
35
  __exportStar(require("./components/ps-toggle"), exports);
@@ -0,0 +1,6 @@
1
+ export declare class PsTagInputService {
2
+ static parse(text: string): string[];
3
+ static add(values: string[], text: string, max: number | undefined): string[];
4
+ static remove(values: string[], value: string): string[];
5
+ static removeLast(values: string[]): string[];
6
+ }
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PsTagInputService = void 0;
4
+ const ps_tag_input_config_1 = require("../constants/ps-tag-input-config");
5
+ class PsTagInputService {
6
+ static parse(text) {
7
+ return text
8
+ .split(ps_tag_input_config_1.PsTagInputConfig.separator)
9
+ .map((entry) => entry.trim())
10
+ .filter((entry) => entry !== '');
11
+ }
12
+ static add(values, text, max) {
13
+ const taken = new Set(values.map((value) => value.toLowerCase()));
14
+ const next = [...values];
15
+ for (const entry of PsTagInputService.parse(text)) {
16
+ const key = entry.toLowerCase();
17
+ if (taken.has(key) || (max !== undefined && next.length >= max))
18
+ continue;
19
+ taken.add(key);
20
+ next.push(entry);
21
+ }
22
+ return next;
23
+ }
24
+ static remove(values, value) {
25
+ return values.filter((entry) => entry !== value);
26
+ }
27
+ static removeLast(values) {
28
+ return values.slice(0, values.length - 1);
29
+ }
30
+ }
31
+ exports.PsTagInputService = PsTagInputService;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pallasoft/ps-input-components",
3
- "version": "3.6.0",
3
+ "version": "3.7.1",
4
4
  "private": false,
5
5
  "main": "./dist/index.js",
6
6
  "module": "./dist/esm/index.js",
@@ -45,7 +45,7 @@
45
45
  ],
46
46
  "scripts": {
47
47
  "husky:prepare": "npx husky",
48
- "build": "tsc && tsc -p tsconfig.esm.json && node -e \"require('fs').writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module' }))\"",
48
+ "build": "tsc && tsc -p tsconfig.esm.json && node -e \"require('fs').writeFileSync('dist/esm/package.json', JSON.stringify({ type: 'module', sideEffects: false }))\"",
49
49
  "setup:graphify": "sh scripts/graphify-setup.sh",
50
50
  "update:graphify": "sh scripts/graphify-update.sh",
51
51
  "lint": "npm run lint:eslint",
@@ -61,7 +61,7 @@
61
61
  "@internationalized/date": "^3.12.2",
62
62
  "@pallasoft/ps-core-components": "^2.21.0",
63
63
  "@pallasoft/ps-icons": "^1.5.4",
64
- "@pallasoft/ps-models": "^1.4.0",
64
+ "@pallasoft/ps-models": "^2.0.0",
65
65
  "@pallasoft/ps-popovers": "^1.7.0",
66
66
  "@pallasoft/ps-utilities": "^2.13.0",
67
67
  "@portabletext/schema": "^2.2.4",