@pallasoft/ps-input-components 3.0.0 → 3.2.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.
- package/dist/components/ps-combobox-input.d.ts +3 -1
- package/dist/components/ps-combobox-input.js +2 -2
- package/dist/components/ps-rating-input.d.ts +12 -0
- package/dist/components/ps-rating-input.js +12 -0
- package/dist/constants/ps-rating-input-config.d.ts +14 -0
- package/dist/constants/ps-rating-input-config.js +18 -0
- package/dist/constants/ps-rating-input-size.d.ts +4 -0
- package/dist/constants/ps-rating-input-size.js +8 -0
- package/dist/esm/components/ps-combobox-input.js +2 -2
- package/dist/esm/components/ps-rating-input.js +8 -0
- package/dist/esm/constants/ps-rating-input-config.js +15 -0
- package/dist/esm/constants/ps-rating-input-size.js +5 -0
- package/dist/esm/index.js +2 -0
- package/dist/esm/portable-text-core/components/ps-portable-text-core-editor.js +7 -2
- package/dist/esm/portable-text-core/index.js +1 -0
- package/dist/esm/portable-text-core/interfaces/ps-portable-text-editor-handle.js +1 -0
- package/dist/esm/portable-text-core/services/ps-portable-text-command-service.js +20 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/portable-text-core/components/ps-portable-text-core-editor.d.ts +1 -1
- package/dist/portable-text-core/components/ps-portable-text-core-editor.js +6 -1
- package/dist/portable-text-core/index.d.ts +1 -0
- package/dist/portable-text-core/index.js +1 -0
- package/dist/portable-text-core/interfaces/ps-portable-text-core-props.d.ts +3 -1
- package/dist/portable-text-core/interfaces/ps-portable-text-editor-handle.d.ts +6 -0
- package/dist/portable-text-core/interfaces/ps-portable-text-editor-handle.js +2 -0
- package/dist/portable-text-core/services/ps-portable-text-command-service.d.ts +3 -0
- package/dist/portable-text-core/services/ps-portable-text-command-service.js +20 -0
- package/package.json +1 -1
|
@@ -6,9 +6,11 @@ export interface PsComboboxInputProps<T> {
|
|
|
6
6
|
getItemLabel: (item: T) => string;
|
|
7
7
|
hideLabel?: boolean;
|
|
8
8
|
inputValue?: string;
|
|
9
|
+
isDisabled?: boolean;
|
|
9
10
|
isLoading?: boolean;
|
|
10
11
|
items: T[];
|
|
11
12
|
label?: string;
|
|
13
|
+
menuTrigger?: 'focus' | 'input' | 'manual';
|
|
12
14
|
onInputChange?: (value: string) => void;
|
|
13
15
|
onSelectionChange?: (item: T | null) => void;
|
|
14
16
|
placeholder?: string;
|
|
@@ -16,4 +18,4 @@ export interface PsComboboxInputProps<T> {
|
|
|
16
18
|
required?: boolean;
|
|
17
19
|
selectedKey?: string | null;
|
|
18
20
|
}
|
|
19
|
-
export declare const PsComboboxInput: <T>({ className, emptyText, getItemKey, getItemLabel, hideLabel, inputValue, isLoading, items, label, onInputChange, onSelectionChange, placeholder, renderItem, required, selectedKey, }: PsComboboxInputProps<T>) => import("react").JSX.Element;
|
|
21
|
+
export declare const PsComboboxInput: <T>({ className, emptyText, getItemKey, getItemLabel, hideLabel, inputValue, isDisabled, isLoading, items, label, menuTrigger, onInputChange, onSelectionChange, placeholder, renderItem, required, selectedKey, }: PsComboboxInputProps<T>) => import("react").JSX.Element;
|
|
@@ -7,8 +7,8 @@ const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
|
7
7
|
const react_aria_components_1 = require("react-aria-components");
|
|
8
8
|
const ps_combobox_input_service_1 = require("../services/ps-combobox-input-service");
|
|
9
9
|
const ps_required_mark_1 = require("./ps-required-mark");
|
|
10
|
-
const PsComboboxInput = ({ className, emptyText, getItemKey, getItemLabel, hideLabel = false, inputValue, isLoading = false, items, label, onInputChange, onSelectionChange, placeholder, renderItem, required, selectedKey, }) => {
|
|
10
|
+
const PsComboboxInput = ({ className, emptyText, getItemKey, getItemLabel, hideLabel = false, inputValue, isDisabled = false, isLoading = false, items, label, menuTrigger = 'input', onInputChange, onSelectionChange, placeholder, renderItem, required, selectedKey, }) => {
|
|
11
11
|
const itemsByKey = new Map(items.map((item) => [getItemKey(item), item]));
|
|
12
|
-
return ((0, jsx_runtime_1.jsxs)(react_aria_components_1.ComboBox, { allowsEmptyCollection: true, "aria-label": hideLabel ? label : undefined, className: ps_design_system_1.PallasoftClassNameService.merge('block', className), defaultFilter: () => true, inputValue: inputValue, items: items, onInputChange: onInputChange, selectedKey: selectedKey, onSelectionChange: (key) => onSelectionChange?.(key === null ? null : ps_combobox_input_service_1.PsComboboxInputService.getItem(itemsByKey, key)), children: [label && !hideLabel ? ((0, jsx_runtime_1.jsxs)(react_aria_components_1.Label, { className: 'ps-input-label', children: [label, (0, jsx_runtime_1.jsx)(ps_required_mark_1.PsRequiredMark, { isRequired: required })] })) : null, (0, jsx_runtime_1.jsx)("span", { className: hideLabel || !label ? 'relative block' : 'relative mt-2 block', children: (0, jsx_runtime_1.jsx)(react_aria_components_1.Input, { className: 'ps-input-control ps-focus-ring w-full text-sm font-semibold', placeholder: placeholder }) }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Popover, { className: 'w-[--trigger-width] rounded-2xl border border-line bg-white/95 p-1.5 shadow-lg dark:border-white/10 dark:bg-slate-900/95', children: isLoading ? ((0, jsx_runtime_1.jsx)("div", { className: 'flex items-center justify-center py-4', children: (0, jsx_runtime_1.jsx)(ps_core_components_1.PsSpinner, { label: 'Loading results', size: 'small' }) })) : ((0, jsx_runtime_1.jsx)(react_aria_components_1.ListBox, { className: 'max-h-72 overflow-y-auto outline-none', items: items, renderEmptyState: () => emptyText ? (0, jsx_runtime_1.jsx)("div", { className: 'px-3 py-2 text-sm text-ink/55', children: emptyText }) : null, children: (item) => ((0, jsx_runtime_1.jsx)(react_aria_components_1.ListBoxItem, { className: 'ps-focus-ring cursor-pointer rounded-ps-control px-3 py-2 text-sm font-semibold text-ink selected:bg-primary-soft selected:text-primary hover:bg-slate-50 dark:hover:bg-white/6', id: getItemKey(item), textValue: getItemLabel(item), children: renderItem ? renderItem(item) : getItemLabel(item) })) })) })] }));
|
|
12
|
+
return ((0, jsx_runtime_1.jsxs)(react_aria_components_1.ComboBox, { allowsEmptyCollection: true, "aria-label": hideLabel ? label : undefined, className: ps_design_system_1.PallasoftClassNameService.merge('block', className), defaultFilter: () => true, inputValue: inputValue, isDisabled: isDisabled, items: items, menuTrigger: menuTrigger, onInputChange: onInputChange, selectedKey: selectedKey, onSelectionChange: (key) => onSelectionChange?.(key === null ? null : ps_combobox_input_service_1.PsComboboxInputService.getItem(itemsByKey, key)), children: [label && !hideLabel ? ((0, jsx_runtime_1.jsxs)(react_aria_components_1.Label, { className: 'ps-input-label', children: [label, (0, jsx_runtime_1.jsx)(ps_required_mark_1.PsRequiredMark, { isRequired: required })] })) : null, (0, jsx_runtime_1.jsx)("span", { className: hideLabel || !label ? 'relative block' : 'relative mt-2 block', children: (0, jsx_runtime_1.jsx)(react_aria_components_1.Input, { className: 'ps-input-control ps-focus-ring w-full text-sm font-semibold', placeholder: placeholder }) }), (0, jsx_runtime_1.jsx)(react_aria_components_1.Popover, { className: 'w-[--trigger-width] rounded-2xl border border-line bg-white/95 p-1.5 shadow-lg dark:border-white/10 dark:bg-slate-900/95', children: isLoading && items.length === 0 ? ((0, jsx_runtime_1.jsx)("div", { className: 'flex items-center justify-center py-4', children: (0, jsx_runtime_1.jsx)(ps_core_components_1.PsSpinner, { label: 'Loading results', size: 'small' }) })) : ((0, jsx_runtime_1.jsx)(react_aria_components_1.ListBox, { "aria-busy": isLoading, className: 'max-h-72 overflow-y-auto outline-none', items: items, renderEmptyState: () => emptyText ? (0, jsx_runtime_1.jsx)("div", { className: 'px-3 py-2 text-sm text-ink/55', children: emptyText }) : null, children: (item) => ((0, jsx_runtime_1.jsx)(react_aria_components_1.ListBoxItem, { className: 'ps-focus-ring cursor-pointer rounded-ps-control px-3 py-2 text-sm font-semibold text-ink selected:bg-primary-soft selected:text-primary hover:bg-slate-50 dark:hover:bg-white/6', id: getItemKey(item), textValue: getItemLabel(item), children: renderItem ? renderItem(item) : getItemLabel(item) })) })) })] }));
|
|
13
13
|
};
|
|
14
14
|
exports.PsComboboxInput = PsComboboxInput;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { PsRatingInputSize } from '../constants/ps-rating-input-size';
|
|
2
|
+
export interface PsRatingInputProps {
|
|
3
|
+
isDisabled?: boolean;
|
|
4
|
+
label: string;
|
|
5
|
+
max?: number;
|
|
6
|
+
name?: string;
|
|
7
|
+
onChange: (score: number) => void;
|
|
8
|
+
optionLabel: (score: number) => string;
|
|
9
|
+
size?: PsRatingInputSize;
|
|
10
|
+
value: number;
|
|
11
|
+
}
|
|
12
|
+
export declare const PsRatingInput: ({ isDisabled, label, max, name, onChange, optionLabel, size, value, }: PsRatingInputProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsRatingInput = void 0;
|
|
4
|
+
const jsx_runtime_1 = require("react/jsx-runtime");
|
|
5
|
+
const ps_design_system_1 = require("@pallasoft/ps-design-system");
|
|
6
|
+
const ps_icons_1 = require("@pallasoft/ps-icons");
|
|
7
|
+
const ps_rating_input_config_1 = require("../constants/ps-rating-input-config");
|
|
8
|
+
const ps_rating_input_size_1 = require("../constants/ps-rating-input-size");
|
|
9
|
+
const PsRatingInput = ({ isDisabled = false, label, max = ps_rating_input_config_1.PsRatingInputConfig.defaultMax, name, onChange, optionLabel, size = ps_rating_input_size_1.PsRatingInputSize.Medium, value, }) => ((0, jsx_runtime_1.jsxs)("fieldset", { className: 'm-0 min-w-0 border-0 p-0', disabled: isDisabled, children: [(0, jsx_runtime_1.jsx)("legend", { className: 'sr-only', children: label }), (0, jsx_runtime_1.jsx)("div", { className: '-ml-1.5 flex items-center', children: Array.from({ length: max }, (_, index) => index + 1).map((score) => ((0, jsx_runtime_1.jsxs)("label", { className: ps_design_system_1.PallasoftClassNameService.merge('relative flex cursor-pointer items-center justify-center', ps_rating_input_config_1.PsRatingInputConfig.targetClassNames[size], isDisabled && 'cursor-not-allowed opacity-60'), title: optionLabel(score), children: [(0, jsx_runtime_1.jsx)("input", { "aria-label": optionLabel(score), checked: score === value, className: 'peer sr-only', name: name, onChange: () => onChange(score), type: 'radio', value: score }), (0, jsx_runtime_1.jsx)(ps_icons_1.PsIcon, { className: ps_design_system_1.PallasoftClassNameService.merge('transition-colors', ps_rating_input_config_1.PsRatingInputConfig.iconClassNames[size], score <= value
|
|
10
|
+
? ps_rating_input_config_1.PsRatingInputConfig.filledClassName
|
|
11
|
+
: ps_rating_input_config_1.PsRatingInputConfig.emptyClassName, ps_rating_input_config_1.PsRatingInputConfig.focusClassName), iconKey: ps_icons_1.PsIconKey.Star })] }, score))) })] }));
|
|
12
|
+
exports.PsRatingInput = PsRatingInput;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare const PsRatingInputConfig: {
|
|
2
|
+
readonly defaultMax: 5;
|
|
3
|
+
readonly filledClassName: "fill-current text-primary";
|
|
4
|
+
readonly emptyClassName: "text-ink/30 hover:text-primary dark:text-white/30";
|
|
5
|
+
readonly focusClassName: "peer-focus-visible:rounded-ps-control peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-primary";
|
|
6
|
+
readonly iconClassNames: {
|
|
7
|
+
readonly large: "h-10 w-10";
|
|
8
|
+
readonly medium: "h-8 w-8";
|
|
9
|
+
};
|
|
10
|
+
readonly targetClassNames: {
|
|
11
|
+
readonly large: "h-14 w-14";
|
|
12
|
+
readonly medium: "h-12 w-12";
|
|
13
|
+
};
|
|
14
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsRatingInputConfig = void 0;
|
|
4
|
+
const ps_rating_input_size_1 = require("./ps-rating-input-size");
|
|
5
|
+
exports.PsRatingInputConfig = {
|
|
6
|
+
defaultMax: 5,
|
|
7
|
+
filledClassName: 'fill-current text-primary',
|
|
8
|
+
emptyClassName: 'text-ink/30 hover:text-primary dark:text-white/30',
|
|
9
|
+
focusClassName: 'peer-focus-visible:rounded-ps-control peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-primary',
|
|
10
|
+
iconClassNames: {
|
|
11
|
+
[ps_rating_input_size_1.PsRatingInputSize.Large]: 'h-10 w-10',
|
|
12
|
+
[ps_rating_input_size_1.PsRatingInputSize.Medium]: 'h-8 w-8',
|
|
13
|
+
},
|
|
14
|
+
targetClassNames: {
|
|
15
|
+
[ps_rating_input_size_1.PsRatingInputSize.Large]: 'h-14 w-14',
|
|
16
|
+
[ps_rating_input_size_1.PsRatingInputSize.Medium]: 'h-12 w-12',
|
|
17
|
+
},
|
|
18
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.PsRatingInputSize = void 0;
|
|
4
|
+
var PsRatingInputSize;
|
|
5
|
+
(function (PsRatingInputSize) {
|
|
6
|
+
PsRatingInputSize["Large"] = "large";
|
|
7
|
+
PsRatingInputSize["Medium"] = "medium";
|
|
8
|
+
})(PsRatingInputSize || (exports.PsRatingInputSize = PsRatingInputSize = {}));
|
|
@@ -4,7 +4,7 @@ import { PallasoftClassNameService } from '@pallasoft/ps-design-system';
|
|
|
4
4
|
import { ComboBox, Input, Label, ListBox, ListBoxItem, Popover } from 'react-aria-components';
|
|
5
5
|
import { PsComboboxInputService } from '../services/ps-combobox-input-service';
|
|
6
6
|
import { PsRequiredMark } from './ps-required-mark';
|
|
7
|
-
export const PsComboboxInput = ({ className, emptyText, getItemKey, getItemLabel, hideLabel = false, inputValue, isLoading = false, items, label, onInputChange, onSelectionChange, placeholder, renderItem, required, selectedKey, }) => {
|
|
7
|
+
export const PsComboboxInput = ({ className, emptyText, getItemKey, getItemLabel, hideLabel = false, inputValue, isDisabled = false, isLoading = false, items, label, menuTrigger = 'input', onInputChange, onSelectionChange, placeholder, renderItem, required, selectedKey, }) => {
|
|
8
8
|
const itemsByKey = new Map(items.map((item) => [getItemKey(item), item]));
|
|
9
|
-
return (_jsxs(ComboBox, { allowsEmptyCollection: true, "aria-label": hideLabel ? label : undefined, className: PallasoftClassNameService.merge('block', className), defaultFilter: () => true, inputValue: inputValue, items: items, onInputChange: onInputChange, selectedKey: selectedKey, onSelectionChange: (key) => onSelectionChange?.(key === null ? null : PsComboboxInputService.getItem(itemsByKey, key)), children: [label && !hideLabel ? (_jsxs(Label, { className: 'ps-input-label', children: [label, _jsx(PsRequiredMark, { isRequired: required })] })) : null, _jsx("span", { className: hideLabel || !label ? 'relative block' : 'relative mt-2 block', children: _jsx(Input, { className: 'ps-input-control ps-focus-ring w-full text-sm font-semibold', placeholder: placeholder }) }), _jsx(Popover, { className: 'w-[--trigger-width] rounded-2xl border border-line bg-white/95 p-1.5 shadow-lg dark:border-white/10 dark:bg-slate-900/95', children: isLoading ? (_jsx("div", { className: 'flex items-center justify-center py-4', children: _jsx(PsSpinner, { label: 'Loading results', size: 'small' }) })) : (_jsx(ListBox, { className: 'max-h-72 overflow-y-auto outline-none', items: items, renderEmptyState: () => emptyText ? _jsx("div", { className: 'px-3 py-2 text-sm text-ink/55', children: emptyText }) : null, children: (item) => (_jsx(ListBoxItem, { className: 'ps-focus-ring cursor-pointer rounded-ps-control px-3 py-2 text-sm font-semibold text-ink selected:bg-primary-soft selected:text-primary hover:bg-slate-50 dark:hover:bg-white/6', id: getItemKey(item), textValue: getItemLabel(item), children: renderItem ? renderItem(item) : getItemLabel(item) })) })) })] }));
|
|
9
|
+
return (_jsxs(ComboBox, { allowsEmptyCollection: true, "aria-label": hideLabel ? label : undefined, className: PallasoftClassNameService.merge('block', className), defaultFilter: () => true, inputValue: inputValue, isDisabled: isDisabled, items: items, menuTrigger: menuTrigger, onInputChange: onInputChange, selectedKey: selectedKey, onSelectionChange: (key) => onSelectionChange?.(key === null ? null : PsComboboxInputService.getItem(itemsByKey, key)), children: [label && !hideLabel ? (_jsxs(Label, { className: 'ps-input-label', children: [label, _jsx(PsRequiredMark, { isRequired: required })] })) : null, _jsx("span", { className: hideLabel || !label ? 'relative block' : 'relative mt-2 block', children: _jsx(Input, { className: 'ps-input-control ps-focus-ring w-full text-sm font-semibold', placeholder: placeholder }) }), _jsx(Popover, { className: 'w-[--trigger-width] rounded-2xl border border-line bg-white/95 p-1.5 shadow-lg dark:border-white/10 dark:bg-slate-900/95', children: isLoading && items.length === 0 ? (_jsx("div", { className: 'flex items-center justify-center py-4', children: _jsx(PsSpinner, { label: 'Loading results', size: 'small' }) })) : (_jsx(ListBox, { "aria-busy": isLoading, className: 'max-h-72 overflow-y-auto outline-none', items: items, renderEmptyState: () => emptyText ? _jsx("div", { className: 'px-3 py-2 text-sm text-ink/55', children: emptyText }) : null, children: (item) => (_jsx(ListBoxItem, { className: 'ps-focus-ring cursor-pointer rounded-ps-control px-3 py-2 text-sm font-semibold text-ink selected:bg-primary-soft selected:text-primary hover:bg-slate-50 dark:hover:bg-white/6', id: getItemKey(item), textValue: getItemLabel(item), children: renderItem ? renderItem(item) : getItemLabel(item) })) })) })] }));
|
|
10
10
|
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { PallasoftClassNameService } from '@pallasoft/ps-design-system';
|
|
3
|
+
import { PsIcon, PsIconKey } from '@pallasoft/ps-icons';
|
|
4
|
+
import { PsRatingInputConfig } from '../constants/ps-rating-input-config';
|
|
5
|
+
import { PsRatingInputSize } from '../constants/ps-rating-input-size';
|
|
6
|
+
export const PsRatingInput = ({ isDisabled = false, label, max = PsRatingInputConfig.defaultMax, name, onChange, optionLabel, size = PsRatingInputSize.Medium, value, }) => (_jsxs("fieldset", { className: 'm-0 min-w-0 border-0 p-0', disabled: isDisabled, children: [_jsx("legend", { className: 'sr-only', children: label }), _jsx("div", { className: '-ml-1.5 flex items-center', children: Array.from({ length: max }, (_, index) => index + 1).map((score) => (_jsxs("label", { className: PallasoftClassNameService.merge('relative flex cursor-pointer items-center justify-center', PsRatingInputConfig.targetClassNames[size], isDisabled && 'cursor-not-allowed opacity-60'), title: optionLabel(score), children: [_jsx("input", { "aria-label": optionLabel(score), checked: score === value, className: 'peer sr-only', name: name, onChange: () => onChange(score), type: 'radio', value: score }), _jsx(PsIcon, { className: PallasoftClassNameService.merge('transition-colors', PsRatingInputConfig.iconClassNames[size], score <= value
|
|
7
|
+
? PsRatingInputConfig.filledClassName
|
|
8
|
+
: PsRatingInputConfig.emptyClassName, PsRatingInputConfig.focusClassName), iconKey: PsIconKey.Star })] }, score))) })] }));
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { PsRatingInputSize } from './ps-rating-input-size';
|
|
2
|
+
export const PsRatingInputConfig = {
|
|
3
|
+
defaultMax: 5,
|
|
4
|
+
filledClassName: 'fill-current text-primary',
|
|
5
|
+
emptyClassName: 'text-ink/30 hover:text-primary dark:text-white/30',
|
|
6
|
+
focusClassName: 'peer-focus-visible:rounded-ps-control peer-focus-visible:outline peer-focus-visible:outline-2 peer-focus-visible:outline-offset-2 peer-focus-visible:outline-primary',
|
|
7
|
+
iconClassNames: {
|
|
8
|
+
[PsRatingInputSize.Large]: 'h-10 w-10',
|
|
9
|
+
[PsRatingInputSize.Medium]: 'h-8 w-8',
|
|
10
|
+
},
|
|
11
|
+
targetClassNames: {
|
|
12
|
+
[PsRatingInputSize.Large]: 'h-14 w-14',
|
|
13
|
+
[PsRatingInputSize.Medium]: 'h-12 w-12',
|
|
14
|
+
},
|
|
15
|
+
};
|
package/dist/esm/index.js
CHANGED
|
@@ -54,3 +54,5 @@ export * from './interfaces/ps-checkbox-matrix-group';
|
|
|
54
54
|
export * from './interfaces/ps-checkbox-matrix-labels';
|
|
55
55
|
export * from './interfaces/ps-checkbox-matrix-row';
|
|
56
56
|
export * from './services/ps-checkbox-matrix-service';
|
|
57
|
+
export * from './components/ps-rating-input';
|
|
58
|
+
export * from './constants/ps-rating-input-size';
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
-
import { useEffect, useRef, useState } from 'react';
|
|
2
|
+
import { useEffect, useImperativeHandle, useRef, useState } from 'react';
|
|
3
3
|
import { EditorContent, useEditor, useEditorState } from '@tiptap/react';
|
|
4
4
|
import { PsPortableTextCoreContext } from '../contexts/ps-portable-text-core-context';
|
|
5
5
|
import { PsPortableTextCommandService } from '../services/ps-portable-text-command-service';
|
|
6
6
|
import { PsPortableTextConverterService } from '../services/ps-portable-text-converter-service';
|
|
7
7
|
import { PsPortableTextEditorService } from '../services/ps-portable-text-editor-service';
|
|
8
8
|
import { PsPortableTextExtensionService } from '../services/ps-portable-text-extension-service';
|
|
9
|
-
export const PsPortableTextCoreEditor = ({ className, classNames, disabled = false, editableClassName = '', label, minRows = 4, onChange, placeholder = '', toolbar, value, }) => {
|
|
9
|
+
export const PsPortableTextCoreEditor = ({ className, classNames, disabled = false, handleRef, editableClassName = '', label, minRows = 4, onChange, placeholder = '', toolbar, value, }) => {
|
|
10
10
|
const [isLinkOpen, setIsLinkOpen] = useState(false);
|
|
11
11
|
const lastValue = useRef(value);
|
|
12
12
|
const editor = useEditor({
|
|
@@ -32,6 +32,11 @@ export const PsPortableTextCoreEditor = ({ className, classNames, disabled = fal
|
|
|
32
32
|
editor,
|
|
33
33
|
selector: ({ editor: current }) => PsPortableTextCommandService.state(current),
|
|
34
34
|
});
|
|
35
|
+
useImperativeHandle(handleRef, () => ({
|
|
36
|
+
focus: () => PsPortableTextCommandService.focus(editor),
|
|
37
|
+
insertBlocks: (blocks) => PsPortableTextCommandService.insertBlocks(editor, blocks),
|
|
38
|
+
isCurrentBlockEmpty: () => PsPortableTextCommandService.isCurrentBlockEmpty(editor),
|
|
39
|
+
}), [editor]);
|
|
35
40
|
useEffect(() => {
|
|
36
41
|
editor.setEditable(!disabled, false);
|
|
37
42
|
}, [editor, disabled]);
|
|
@@ -5,6 +5,7 @@ export * from './hooks/use-ps-portable-text-toolbar';
|
|
|
5
5
|
export * from './interfaces/ps-portable-text-active-formats';
|
|
6
6
|
export * from './interfaces/ps-portable-text-core-class-names';
|
|
7
7
|
export * from './interfaces/ps-portable-text-core-props';
|
|
8
|
+
export * from './interfaces/ps-portable-text-editor-handle';
|
|
8
9
|
export * from './interfaces/ps-portable-text-editor-labels';
|
|
9
10
|
export * from './services/ps-portable-text-converter-service';
|
|
10
11
|
export * from './services/ps-portable-text-editor-service';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PsPortableTextCoreConfig } from '../constants/ps-portable-text-core-config';
|
|
2
|
+
import { PsPortableTextConverterService } from './ps-portable-text-converter-service';
|
|
2
3
|
import { PsPortableTextEditorService } from './ps-portable-text-editor-service';
|
|
3
4
|
export class PsPortableTextCommandService {
|
|
4
5
|
static state(editor) {
|
|
@@ -70,4 +71,23 @@ export class PsPortableTextCommandService {
|
|
|
70
71
|
if (editor !== null)
|
|
71
72
|
editor.commands.focus();
|
|
72
73
|
}
|
|
74
|
+
static insertBlocks(editor, blocks) {
|
|
75
|
+
if (editor === null || blocks.length === 0)
|
|
76
|
+
return;
|
|
77
|
+
const content = PsPortableTextConverterService.toDocument(blocks).content;
|
|
78
|
+
if (content === undefined)
|
|
79
|
+
return;
|
|
80
|
+
const [first] = content;
|
|
81
|
+
const isOneLine = content.length === 1 &&
|
|
82
|
+
first.type === PsPortableTextCoreConfig.nodes.paragraph &&
|
|
83
|
+
first.content !== undefined;
|
|
84
|
+
editor
|
|
85
|
+
.chain()
|
|
86
|
+
.focus()
|
|
87
|
+
.insertContent(isOneLine && first.content !== undefined ? first.content : content)
|
|
88
|
+
.run();
|
|
89
|
+
}
|
|
90
|
+
static isCurrentBlockEmpty(editor) {
|
|
91
|
+
return editor === null ? true : editor.state.selection.$from.parent.content.size === 0;
|
|
92
|
+
}
|
|
73
93
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -54,3 +54,5 @@ export * from './interfaces/ps-checkbox-matrix-group';
|
|
|
54
54
|
export * from './interfaces/ps-checkbox-matrix-labels';
|
|
55
55
|
export * from './interfaces/ps-checkbox-matrix-row';
|
|
56
56
|
export * from './services/ps-checkbox-matrix-service';
|
|
57
|
+
export * from './components/ps-rating-input';
|
|
58
|
+
export * from './constants/ps-rating-input-size';
|
package/dist/index.js
CHANGED
|
@@ -70,3 +70,5 @@ __exportStar(require("./interfaces/ps-checkbox-matrix-group"), exports);
|
|
|
70
70
|
__exportStar(require("./interfaces/ps-checkbox-matrix-labels"), exports);
|
|
71
71
|
__exportStar(require("./interfaces/ps-checkbox-matrix-row"), exports);
|
|
72
72
|
__exportStar(require("./services/ps-checkbox-matrix-service"), exports);
|
|
73
|
+
__exportStar(require("./components/ps-rating-input"), exports);
|
|
74
|
+
__exportStar(require("./constants/ps-rating-input-size"), exports);
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import type { PsPortableTextCoreProps } from '../interfaces/ps-portable-text-core-props';
|
|
2
|
-
export declare const PsPortableTextCoreEditor: ({ className, classNames, disabled, editableClassName, label, minRows, onChange, placeholder, toolbar, value, }: PsPortableTextCoreProps) => import("react").JSX.Element;
|
|
2
|
+
export declare const PsPortableTextCoreEditor: ({ className, classNames, disabled, handleRef, editableClassName, label, minRows, onChange, placeholder, toolbar, value, }: PsPortableTextCoreProps) => import("react").JSX.Element;
|
|
@@ -9,7 +9,7 @@ const ps_portable_text_command_service_1 = require("../services/ps-portable-text
|
|
|
9
9
|
const ps_portable_text_converter_service_1 = require("../services/ps-portable-text-converter-service");
|
|
10
10
|
const ps_portable_text_editor_service_1 = require("../services/ps-portable-text-editor-service");
|
|
11
11
|
const ps_portable_text_extension_service_1 = require("../services/ps-portable-text-extension-service");
|
|
12
|
-
const PsPortableTextCoreEditor = ({ className, classNames, disabled = false, editableClassName = '', label, minRows = 4, onChange, placeholder = '', toolbar, value, }) => {
|
|
12
|
+
const PsPortableTextCoreEditor = ({ className, classNames, disabled = false, handleRef, editableClassName = '', label, minRows = 4, onChange, placeholder = '', toolbar, value, }) => {
|
|
13
13
|
const [isLinkOpen, setIsLinkOpen] = (0, react_1.useState)(false);
|
|
14
14
|
const lastValue = (0, react_1.useRef)(value);
|
|
15
15
|
const editor = (0, react_2.useEditor)({
|
|
@@ -35,6 +35,11 @@ const PsPortableTextCoreEditor = ({ className, classNames, disabled = false, edi
|
|
|
35
35
|
editor,
|
|
36
36
|
selector: ({ editor: current }) => ps_portable_text_command_service_1.PsPortableTextCommandService.state(current),
|
|
37
37
|
});
|
|
38
|
+
(0, react_1.useImperativeHandle)(handleRef, () => ({
|
|
39
|
+
focus: () => ps_portable_text_command_service_1.PsPortableTextCommandService.focus(editor),
|
|
40
|
+
insertBlocks: (blocks) => ps_portable_text_command_service_1.PsPortableTextCommandService.insertBlocks(editor, blocks),
|
|
41
|
+
isCurrentBlockEmpty: () => ps_portable_text_command_service_1.PsPortableTextCommandService.isCurrentBlockEmpty(editor),
|
|
42
|
+
}), [editor]);
|
|
38
43
|
(0, react_1.useEffect)(() => {
|
|
39
44
|
editor.setEditable(!disabled, false);
|
|
40
45
|
}, [editor, disabled]);
|
|
@@ -5,6 +5,7 @@ export * from './hooks/use-ps-portable-text-toolbar';
|
|
|
5
5
|
export * from './interfaces/ps-portable-text-active-formats';
|
|
6
6
|
export * from './interfaces/ps-portable-text-core-class-names';
|
|
7
7
|
export * from './interfaces/ps-portable-text-core-props';
|
|
8
|
+
export * from './interfaces/ps-portable-text-editor-handle';
|
|
8
9
|
export * from './interfaces/ps-portable-text-editor-labels';
|
|
9
10
|
export * from './services/ps-portable-text-converter-service';
|
|
10
11
|
export * from './services/ps-portable-text-editor-service';
|
|
@@ -21,6 +21,7 @@ __exportStar(require("./hooks/use-ps-portable-text-toolbar"), exports);
|
|
|
21
21
|
__exportStar(require("./interfaces/ps-portable-text-active-formats"), exports);
|
|
22
22
|
__exportStar(require("./interfaces/ps-portable-text-core-class-names"), exports);
|
|
23
23
|
__exportStar(require("./interfaces/ps-portable-text-core-props"), exports);
|
|
24
|
+
__exportStar(require("./interfaces/ps-portable-text-editor-handle"), exports);
|
|
24
25
|
__exportStar(require("./interfaces/ps-portable-text-editor-labels"), exports);
|
|
25
26
|
__exportStar(require("./services/ps-portable-text-converter-service"), exports);
|
|
26
27
|
__exportStar(require("./services/ps-portable-text-editor-service"), exports);
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
import type { ReactNode } from 'react';
|
|
1
|
+
import type { ReactNode, Ref } from 'react';
|
|
2
2
|
import type { PortableTextBlock } from '@portabletext/schema';
|
|
3
3
|
import type { PsPortableTextCoreClassNames } from './ps-portable-text-core-class-names';
|
|
4
|
+
import type { PsPortableTextEditorHandle } from './ps-portable-text-editor-handle';
|
|
4
5
|
export interface PsPortableTextCoreProps {
|
|
5
6
|
className?: string;
|
|
6
7
|
classNames: PsPortableTextCoreClassNames;
|
|
7
8
|
disabled?: boolean;
|
|
8
9
|
editableClassName?: string;
|
|
9
10
|
fallback?: ReactNode;
|
|
11
|
+
handleRef?: Ref<PsPortableTextEditorHandle>;
|
|
10
12
|
label?: string;
|
|
11
13
|
minRows?: number;
|
|
12
14
|
onChange: (value: PortableTextBlock[]) => void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { PortableTextBlock } from '@portabletext/schema';
|
|
1
2
|
import type { Editor } from '@tiptap/core';
|
|
2
3
|
import type { PsPortableTextActiveFormats } from '../interfaces/ps-portable-text-active-formats';
|
|
3
4
|
import type { PsPortableTextToolbarState } from '../interfaces/ps-portable-text-toolbar-state';
|
|
@@ -11,4 +12,6 @@ export declare class PsPortableTextCommandService {
|
|
|
11
12
|
static setLink(editor: Editor | null, href: string): void;
|
|
12
13
|
static removeLink(editor: Editor | null): void;
|
|
13
14
|
static focus(editor: Editor | null): void;
|
|
15
|
+
static insertBlocks(editor: Editor | null, blocks: PortableTextBlock[]): void;
|
|
16
|
+
static isCurrentBlockEmpty(editor: Editor | null): boolean;
|
|
14
17
|
}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.PsPortableTextCommandService = void 0;
|
|
4
4
|
const ps_portable_text_core_config_1 = require("../constants/ps-portable-text-core-config");
|
|
5
|
+
const ps_portable_text_converter_service_1 = require("./ps-portable-text-converter-service");
|
|
5
6
|
const ps_portable_text_editor_service_1 = require("./ps-portable-text-editor-service");
|
|
6
7
|
class PsPortableTextCommandService {
|
|
7
8
|
static state(editor) {
|
|
@@ -73,5 +74,24 @@ class PsPortableTextCommandService {
|
|
|
73
74
|
if (editor !== null)
|
|
74
75
|
editor.commands.focus();
|
|
75
76
|
}
|
|
77
|
+
static insertBlocks(editor, blocks) {
|
|
78
|
+
if (editor === null || blocks.length === 0)
|
|
79
|
+
return;
|
|
80
|
+
const content = ps_portable_text_converter_service_1.PsPortableTextConverterService.toDocument(blocks).content;
|
|
81
|
+
if (content === undefined)
|
|
82
|
+
return;
|
|
83
|
+
const [first] = content;
|
|
84
|
+
const isOneLine = content.length === 1 &&
|
|
85
|
+
first.type === ps_portable_text_core_config_1.PsPortableTextCoreConfig.nodes.paragraph &&
|
|
86
|
+
first.content !== undefined;
|
|
87
|
+
editor
|
|
88
|
+
.chain()
|
|
89
|
+
.focus()
|
|
90
|
+
.insertContent(isOneLine && first.content !== undefined ? first.content : content)
|
|
91
|
+
.run();
|
|
92
|
+
}
|
|
93
|
+
static isCurrentBlockEmpty(editor) {
|
|
94
|
+
return editor === null ? true : editor.state.selection.$from.parent.content.size === 0;
|
|
95
|
+
}
|
|
76
96
|
}
|
|
77
97
|
exports.PsPortableTextCommandService = PsPortableTextCommandService;
|