@brilo/base-blocks 0.1.21 → 0.1.22

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.
Files changed (28) hide show
  1. package/build/.tsbuildinfo +1 -1
  2. package/build/blocks/form/form-field/SelectOptionsRepeater.d.ts +10 -0
  3. package/build/blocks/form/form-field/SelectOptionsRepeater.d.ts.map +1 -0
  4. package/build/blocks/form/form-field/SelectOptionsRepeater.js +20 -0
  5. package/build/blocks/form/form-field/constants.d.ts +8 -0
  6. package/build/blocks/form/form-field/constants.d.ts.map +1 -1
  7. package/build/blocks/form/form-field/constants.js +5 -0
  8. package/build/blocks/form/form-field/edit.d.ts.map +1 -1
  9. package/build/blocks/form/form-field/edit.js +20 -11
  10. package/build/blocks/form/form-field/factory.d.ts.map +1 -1
  11. package/build/blocks/form/form-field/factory.js +1 -0
  12. package/build/blocks/form/form-field/normalizeOptions.d.ts +18 -0
  13. package/build/blocks/form/form-field/normalizeOptions.d.ts.map +1 -0
  14. package/build/blocks/form/form-field/normalizeOptions.js +39 -0
  15. package/build/blocks/form/form-field/types.d.ts +9 -2
  16. package/build/blocks/form/form-field/types.d.ts.map +1 -1
  17. package/build/blocks/signpost/signpost-group/constants.d.ts +1 -1
  18. package/build/blocks/signpost/signpost-group/constants.d.ts.map +1 -1
  19. package/build/blocks/signpost/signpost-group/constants.js +1 -1
  20. package/package.json +5 -2
  21. package/src/blocks/form/form-field/SelectOptionsRepeater.tsx +111 -0
  22. package/src/blocks/form/form-field/constants.ts +7 -0
  23. package/src/blocks/form/form-field/edit.tsx +42 -16
  24. package/src/blocks/form/form-field/editor.scss +28 -0
  25. package/src/blocks/form/form-field/factory.tsx +1 -0
  26. package/src/blocks/form/form-field/normalizeOptions.ts +58 -0
  27. package/src/blocks/form/form-field/types.ts +6 -2
  28. package/src/blocks/signpost/signpost-group/constants.ts +1 -1
@@ -0,0 +1,10 @@
1
+ import type { OptionRow } from './normalizeOptions';
2
+ type Props = {
3
+ rows: OptionRow[];
4
+ onChange: (rows: OptionRow[]) => void;
5
+ showEmail: boolean;
6
+ onClose: () => void;
7
+ };
8
+ export declare function SelectOptionsRepeater({ rows, onChange, showEmail, onClose }: Props): import("react").JSX.Element;
9
+ export {};
10
+ //# sourceMappingURL=SelectOptionsRepeater.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"SelectOptionsRepeater.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/SelectOptionsRepeater.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAC,SAAS,EAAC,MAAM,oBAAoB,CAAA;AAIjD,KAAK,KAAK,GAAG;IACX,IAAI,EAAE,SAAS,EAAE,CAAA;IACjB,QAAQ,EAAE,CAAC,IAAI,EAAE,SAAS,EAAE,KAAK,IAAI,CAAA;IACrC,SAAS,EAAE,OAAO,CAAA;IAClB,OAAO,EAAE,MAAM,IAAI,CAAA;CACpB,CAAA;AAED,wBAAgB,qBAAqB,CAAC,EAAC,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,OAAO,EAAC,EAAE,KAAK,+BAgGhF"}
@@ -0,0 +1,20 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { Button, Card, CardBody, Flex, FlexBlock, FlexItem, TextControl } from '@wordpress/components';
3
+ import { __ } from '@wordpress/i18n';
4
+ import { ReactSortable } from 'react-sortablejs';
5
+ const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
6
+ export function SelectOptionsRepeater({ rows, onChange, showEmail, onClose }) {
7
+ const updateRow = (id, patch) => {
8
+ onChange(rows.map((row) => (row.id === id ? { ...row, ...patch } : row)));
9
+ };
10
+ const removeRow = (id) => {
11
+ onChange(rows.filter((row) => row.id !== id));
12
+ };
13
+ const addRow = () => {
14
+ onChange([...rows, { id: `${Date.now()}-${Math.random()}`, label: '', value: '', email: '' }]);
15
+ };
16
+ return (_jsxs("div", { className: "i-form-field__options-repeater", children: [_jsx(ReactSortable, { list: rows, setList: onChange, handle: ".i-form-field__option-drag-handle", animation: 150, children: rows.map((row) => {
17
+ const isEmailInvalid = row.email.trim() !== '' && !EMAIL_PATTERN.test(row.email.trim());
18
+ return (_jsx(Card, { size: "small", className: "i-form-field__option-row", children: _jsx(CardBody, { children: _jsxs(Flex, { align: "flex-start", gap: 3, children: [_jsx(FlexItem, { children: _jsx("span", { className: "i-form-field__option-drag-handle", "aria-hidden": "true", children: "\u283F" }) }), _jsx(FlexBlock, { children: _jsxs(Flex, { direction: "column", gap: 3, children: [_jsx(FlexItem, { children: _jsx(TextControl, { label: __('Popisek', 'brilo-blocks'), placeholder: __('Popisek možnosti', 'brilo-blocks'), value: row.label, onChange: (label) => updateRow(row.id, { label }) }) }), _jsx(FlexItem, { children: _jsx(TextControl, { label: __('Hodnota', 'brilo-blocks'), placeholder: __('auto (dle popisku)', 'brilo-blocks'), value: row.value, onChange: (value) => updateRow(row.id, { value }), help: __('Volitelné, jinak se odvodí z popisku.', 'brilo-blocks') }) }), showEmail && (_jsx(FlexItem, { children: _jsx(TextControl, { label: __('E-mail', 'brilo-blocks'), type: "email", placeholder: __('Email příjemce (volitelné)', 'brilo-blocks'), value: row.email, onChange: (email) => updateRow(row.id, { email }), help: isEmailInvalid ? __('Neplatný formát emailu.', 'brilo-blocks') : undefined }) }))] }) }), _jsx(FlexItem, { children: _jsx(Button, { icon: "no-alt", size: "small", variant: "tertiary", isDestructive: true, label: __('Odebrat možnost', 'brilo-blocks'), onClick: () => removeRow(row.id) }) })] }) }) }, row.id));
19
+ }) }), _jsxs(Flex, { className: "i-form-field__options-footer", justify: "flex-start", gap: 2, children: [_jsx(FlexItem, { children: _jsx(Button, { variant: "secondary", onClick: addRow, children: __('Přidat možnost', 'brilo-blocks') }) }), _jsx(FlexItem, { children: _jsx(Button, { variant: "tertiary", onClick: onClose, children: __('Zavřít', 'brilo-blocks') }) })] })] }));
20
+ }
@@ -37,4 +37,12 @@ export declare const FIELD_COLUMNS_RANGE: {
37
37
  readonly max: 12;
38
38
  };
39
39
  export declare const FIELD_COLUMNS_DEFAULT = 6;
40
+ export declare const FIELD_SELECT_MODE_VALUES: readonly ['classic', 'email'];
41
+ export declare const FIELD_SELECT_MODES: readonly [{
42
+ readonly value: "classic";
43
+ readonly label: import("@wordpress/i18n").TransformedText<"Klasický">;
44
+ }, {
45
+ readonly value: "email";
46
+ readonly label: import("@wordpress/i18n").TransformedText<"Výběr s routováním e-mailu">;
47
+ }];
40
48
  //# sourceMappingURL=constants.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,YAAI,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAA;AAElF,eAAO,MAAM,WAAW;aACrB,KAAK;aAAwB,KAAK;;aAClC,KAAK;aAAwB,KAAK;;aAClC,KAAK;aAAwB,KAAK;;aAClC,KAAK;aAAwB,KAAK;EAC3B,CAAA;AAEV,eAAO,MAAM,sBAAsB,YAAI,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAU,CAAA;AACjG,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;IAO5B,CAAA;AAED,eAAO,MAAM,mBAAmB;aAAI,GAAG,EAAE,CAAC;aAAE,GAAG,EAAE,EAAE;CAAU,CAAA;AAE7D,eAAO,MAAM,qBAAqB,IAAI,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,YAAI,MAAM,EAAE,UAAU,EAAE,QAAQ,EAAE,QAAQ,CAAU,CAAA;AAElF,eAAO,MAAM,WAAW;aACrB,KAAK;aAAwB,KAAK;;aAClC,KAAK;aAAwB,KAAK;;aAClC,KAAK;aAAwB,KAAK;;aAClC,KAAK;aAAwB,KAAK;EAC3B,CAAA;AAEV,eAAO,MAAM,sBAAsB,YAAI,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,MAAM,CAAU,CAAA;AACjG,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;IAO5B,CAAA;AAED,eAAO,MAAM,mBAAmB;aAAI,GAAG,EAAE,CAAC;aAAE,GAAG,EAAE,EAAE;CAAU,CAAA;AAE7D,eAAO,MAAM,qBAAqB,IAAI,CAAA;AAEtC,eAAO,MAAM,wBAAwB,YAAI,SAAS,EAAE,OAAO,CAAU,CAAA;AAErE,eAAO,MAAM,kBAAkB;aAC5B,KAAK;aAA+B,KAAK;;aACzC,KAAK;aAA+B,KAAK;EAClC,CAAA"}
@@ -17,3 +17,8 @@ export const FIELD_TEXT_TYPES = [
17
17
  ];
18
18
  export const FIELD_COLUMNS_RANGE = { min: 1, max: 12 };
19
19
  export const FIELD_COLUMNS_DEFAULT = 6;
20
+ export const FIELD_SELECT_MODE_VALUES = ['classic', 'email'];
21
+ export const FIELD_SELECT_MODES = [
22
+ { value: FIELD_SELECT_MODE_VALUES[0], label: __('Klasický', 'brilo-blocks') },
23
+ { value: FIELD_SELECT_MODE_VALUES[1], label: __('Výběr s routováním e-mailu', 'brilo-blocks') },
24
+ ];
@@ -1 +1 @@
1
- {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/edit.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAC,mBAAmB,EAAE,gBAAgB,EAAmC,MAAM,SAAS,CAAA;AAe/F,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,oCAIzD;IACD,UAAU,EAAE,mBAAmB,CAAA;IAC/B,aAAa,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;CACzD,iCAiKF"}
1
+ {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/edit.tsx"],"names":[],"mappings":"AAQA,OAAO,EAAC,mBAAmB,EAAE,gBAAgB,EAAwD,MAAM,SAAS,CAAA;AAepH,wBAAgB,mBAAmB,CAAC,QAAQ,EAAE,gBAAgB,oCAIzD;IACD,UAAU,EAAE,mBAAmB,CAAA;IAC/B,aAAa,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;CACzD,iCAwLF"}
@@ -1,9 +1,12 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { InspectorControls, useBlockProps } from '@wordpress/block-editor';
3
- import { Button, FormTokenField, PanelBody, RangeControl, SelectControl, TextControl, ToggleControl } from '@wordpress/components';
4
- import { __ } from '@wordpress/i18n';
3
+ import { Button, Modal, PanelBody, RangeControl, SelectControl, TextControl, ToggleControl } from '@wordpress/components';
4
+ import { __, sprintf } from '@wordpress/i18n';
5
5
  import clsx from 'clsx';
6
- import { FIELD_COLUMNS_DEFAULT, FIELD_COLUMNS_RANGE, FIELD_TEXT_TYPES, FIELD_TYPES } from './constants';
6
+ import { useState } from 'react';
7
+ import { FIELD_COLUMNS_DEFAULT, FIELD_COLUMNS_RANGE, FIELD_SELECT_MODES, FIELD_TEXT_TYPES, FIELD_TYPES } from './constants';
8
+ import { normalizeOptions, serializeOptions } from './normalizeOptions';
9
+ import { SelectOptionsRepeater } from './SelectOptionsRepeater';
7
10
  const { min: MIN_COLUMNS, max: MAX_COLUMNS } = FIELD_COLUMNS_RANGE;
8
11
  function sanitizeHtmlName(raw) {
9
12
  return (raw !== null && raw !== void 0 ? raw : '')
@@ -17,17 +20,23 @@ function sanitizeHtmlName(raw) {
17
20
  }
18
21
  export function createFormFieldEdit(_options) {
19
22
  return function Edit({ attributes, setAttributes, }) {
20
- var _a, _b, _c, _d;
23
+ var _a, _b, _c, _d, _e, _f;
21
24
  const currentColumns = Math.max(MIN_COLUMNS, Math.min(MAX_COLUMNS, attributes.columns || MIN_COLUMNS));
22
25
  const blockProps = useBlockProps({
23
26
  className: clsx('i-form-field', `--type-${attributes.type}`, `--cols-${currentColumns}`, attributes.required && '--required'),
24
27
  });
25
- const options = Array.isArray(attributes.options) ? attributes.options.filter((opt) => typeof opt === 'string') : [];
26
- const selectOptions = [{ label: __('Žádná', 'brilo-blocks'), value: '' }, ...options.map((opt) => ({ label: opt, value: opt }))];
27
- return (_jsxs(_Fragment, { children: [_jsx(InspectorControls, { children: _jsxs(PanelBody, { title: __('Pole formuláře', 'brilo-blocks'), children: [_jsx(SelectControl, { label: __('Typ inputu', 'brilo-blocks'), value: attributes.type, options: FIELD_TYPES.map((t) => ({ label: t.label, value: t.value })), onChange: (type) => setAttributes({ type: type }) }), attributes.type === 'text' && (_jsx(_Fragment, { children: _jsx(SelectControl, { label: __('Typ textovho inputu', 'brilo-blocks'), value: attributes.textType, options: FIELD_TEXT_TYPES.map((t) => ({ label: t.label, value: t.value })), onChange: (fieldType) => setAttributes({ textType: fieldType }) }) })), attributes.type !== 'hidden' && (_jsxs(_Fragment, { children: [_jsx(TextControl, { label: __('Popisek', 'brilo-blocks'), value: attributes.label, onChange: (label) => setAttributes({ label }) }), _jsx(ToggleControl, { label: __('Povinné', 'brilo-blocks'), checked: attributes.required, onChange: (required) => setAttributes({ required }) }), _jsx(TextControl, { label: __('Název html atributu', 'brilo-blocks'), value: attributes.name, help: __('Použijte pouze bezpečné znaky: a-z, 0-9, pomlčka a podtržítko. Např. city-born-to. Mezery a diakritika se automaticky odstraní.', 'brilo-blocks'), onChange: (name) => setAttributes({ name: sanitizeHtmlName(name) }) }), _jsx(TextControl, { label: __('Placeholder', 'brilo-blocks'), value: attributes.placeholder, onChange: (placeholder) => setAttributes({ placeholder }) })] })), attributes.type === 'select' && (_jsxs(_Fragment, { children: [_jsx(FormTokenField, { label: __('Možnosti', 'brilo-blocks'), value: options, onChange: (nextOptions) => setAttributes({
28
- options: (nextOptions !== null && nextOptions !== void 0 ? nextOptions : [])
29
- .map((opt) => (typeof opt === 'string' ? opt : opt.value))
30
- .filter((opt) => typeof opt === 'string' && opt.length > 0),
31
- }) }), _jsx(SelectControl, { label: __('Výchozí hodnota', 'brilo-blocks'), value: (_a = attributes.defaultValue) !== null && _a !== void 0 ? _a : '', options: selectOptions, onChange: (defaultValue) => setAttributes({ defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : '' }) })] })), attributes.type === 'hidden' && (_jsxs(_Fragment, { children: [_jsx(TextControl, { label: __('Hodnota', 'brilo-blocks'), value: (_b = attributes.value) !== null && _b !== void 0 ? _b : '', onChange: (value) => setAttributes({ value }), help: __('Hodnota, která bude odeslána s formulářem.', 'brilo-blocks') }), _jsx(TextControl, { label: __('Název html atributu', 'brilo-blocks'), value: attributes.name, help: __('Použijte pouze bezpečné znaky: a-z, 0-9, pomlčka a podtržítko. Mezery a diakritika se automaticky odstraní.', 'brilo-blocks'), onChange: (name) => setAttributes({ name: sanitizeHtmlName(name) }) })] })), attributes.type !== 'hidden' && (_jsx(RangeControl, { label: __('Počet sloupců', 'brilo-blocks'), value: currentColumns, min: MIN_COLUMNS, max: MAX_COLUMNS, onChange: (columns) => setAttributes({ columns: Math.max(MIN_COLUMNS, Math.min(MAX_COLUMNS, columns !== null && columns !== void 0 ? columns : FIELD_COLUMNS_DEFAULT)) }) }))] }) }), _jsx("div", { ...blockProps, children: _jsx("div", { className: "i-form-field__wrapper", children: attributes.type === 'hidden' ? (_jsxs(_Fragment, { children: [_jsx("strong", { children: __('Skryté pole', 'brilo-blocks') }), _jsxs("div", { children: [__('Hodnota', 'brilo-blocks'), ": ", (_c = attributes.value) !== null && _c !== void 0 ? _c : ''] }), _jsxs("div", { children: [__('Název', 'brilo-blocks'), ": ", (_d = attributes.name) !== null && _d !== void 0 ? _d : ''] })] })) : (_jsxs(_Fragment, { children: [_jsx("strong", { children: attributes.label || __('Pole', 'brilo-blocks') }), _jsx("div", { children: attributes.type }), _jsxs("div", { className: "i-form-field__columns-control", children: [_jsx(Button, { size: "small", variant: "secondary", onClick: () => setAttributes({ columns: Math.max(MIN_COLUMNS, currentColumns - 1) }), disabled: currentColumns <= MIN_COLUMNS, "aria-label": __('Snížit počet sloupců', 'brilo-blocks'), children: "-" }), _jsx("div", { className: "i-form-field__columns-value", children: `${currentColumns}/${MAX_COLUMNS}` }), _jsx(Button, { size: "small", variant: "secondary", onClick: () => setAttributes({ columns: Math.min(MAX_COLUMNS, currentColumns + 1) }), disabled: currentColumns >= MAX_COLUMNS, "aria-label": __('Zvýšit počet sloupců', 'brilo-blocks'), children: "+" })] })] })) }) })] }));
28
+ // Rows carry a locally-generated id (for React/Sortable identity) that is never persisted;
29
+ // deriving it fresh from attributes on every render would remount inputs and drop focus mid-keystroke.
30
+ const [optionRows, setOptionRows] = useState(() => normalizeOptions(attributes.options));
31
+ const [isOptionsModalOpen, setIsOptionsModalOpen] = useState(false);
32
+ const updateOptionRows = (rows) => {
33
+ setOptionRows(rows);
34
+ setAttributes({ options: serializeOptions(rows) });
35
+ };
36
+ const selectOptions = [
37
+ { label: __('Žádná', 'brilo-blocks'), value: '' },
38
+ ...optionRows.map((row) => ({ label: row.label, value: row.label })),
39
+ ];
40
+ return (_jsxs(_Fragment, { children: [_jsx(InspectorControls, { children: _jsxs(PanelBody, { title: __('Pole formuláře', 'brilo-blocks'), children: [_jsx(SelectControl, { label: __('Typ inputu', 'brilo-blocks'), value: attributes.type, options: FIELD_TYPES.map((t) => ({ label: t.label, value: t.value })), onChange: (type) => setAttributes({ type: type }) }), attributes.type === 'text' && (_jsx(_Fragment, { children: _jsx(SelectControl, { label: __('Typ textovho inputu', 'brilo-blocks'), value: attributes.textType, options: FIELD_TEXT_TYPES.map((t) => ({ label: t.label, value: t.value })), onChange: (fieldType) => setAttributes({ textType: fieldType }) }) })), attributes.type !== 'hidden' && (_jsxs(_Fragment, { children: [_jsx(TextControl, { label: __('Popisek', 'brilo-blocks'), value: attributes.label, onChange: (label) => setAttributes({ label }) }), _jsx(ToggleControl, { label: __('Povinné', 'brilo-blocks'), checked: attributes.required, onChange: (required) => setAttributes({ required }) }), _jsx(TextControl, { label: __('Název html atributu', 'brilo-blocks'), value: attributes.name, help: __('Použijte pouze bezpečné znaky: a-z, 0-9, pomlčka a podtržítko. Např. city-born-to. Mezery a diakritika se automaticky odstraní.', 'brilo-blocks'), onChange: (name) => setAttributes({ name: sanitizeHtmlName(name) }) }), _jsx(TextControl, { label: __('Placeholder', 'brilo-blocks'), value: attributes.placeholder, onChange: (placeholder) => setAttributes({ placeholder }) })] })), attributes.type === 'select' && (_jsxs(_Fragment, { children: [_jsx(SelectControl, { label: __('Režim selectu', 'brilo-blocks'), value: (_a = attributes.selectMode) !== null && _a !== void 0 ? _a : 'classic', options: FIELD_SELECT_MODES.map((m) => ({ label: m.label, value: m.value })), onChange: (selectMode) => setAttributes({ selectMode: selectMode }) }), _jsx("div", { className: "i-form-field__options-trigger", children: _jsx(Button, { variant: "secondary", onClick: () => setIsOptionsModalOpen(true), children: sprintf(__('Upravit možnosti (%d)', 'brilo-blocks'), optionRows.length) }) }), isOptionsModalOpen && (_jsx(Modal, { title: __('Možnosti pole', 'brilo-blocks'), onRequestClose: () => setIsOptionsModalOpen(false), size: "large", children: _jsx(SelectOptionsRepeater, { rows: optionRows, onChange: updateOptionRows, showEmail: ((_b = attributes.selectMode) !== null && _b !== void 0 ? _b : 'classic') === 'email', onClose: () => setIsOptionsModalOpen(false) }) })), _jsx(SelectControl, { label: __('Výchozí hodnota', 'brilo-blocks'), value: (_c = attributes.defaultValue) !== null && _c !== void 0 ? _c : '', options: selectOptions, onChange: (defaultValue) => setAttributes({ defaultValue: defaultValue !== null && defaultValue !== void 0 ? defaultValue : '' }) })] })), attributes.type === 'hidden' && (_jsxs(_Fragment, { children: [_jsx(TextControl, { label: __('Hodnota', 'brilo-blocks'), value: (_d = attributes.value) !== null && _d !== void 0 ? _d : '', onChange: (value) => setAttributes({ value }), help: __('Hodnota, která bude odeslána s formulářem.', 'brilo-blocks') }), _jsx(TextControl, { label: __('Název html atributu', 'brilo-blocks'), value: attributes.name, help: __('Použijte pouze bezpečné znaky: a-z, 0-9, pomlčka a podtržítko. Mezery a diakritika se automaticky odstraní.', 'brilo-blocks'), onChange: (name) => setAttributes({ name: sanitizeHtmlName(name) }) })] })), attributes.type !== 'hidden' && (_jsx(RangeControl, { label: __('Počet sloupců', 'brilo-blocks'), value: currentColumns, min: MIN_COLUMNS, max: MAX_COLUMNS, onChange: (columns) => setAttributes({ columns: Math.max(MIN_COLUMNS, Math.min(MAX_COLUMNS, columns !== null && columns !== void 0 ? columns : FIELD_COLUMNS_DEFAULT)) }) }))] }) }), _jsx("div", { ...blockProps, children: _jsx("div", { className: "i-form-field__wrapper", children: attributes.type === 'hidden' ? (_jsxs(_Fragment, { children: [_jsx("strong", { children: __('Skryté pole', 'brilo-blocks') }), _jsxs("div", { children: [__('Hodnota', 'brilo-blocks'), ": ", (_e = attributes.value) !== null && _e !== void 0 ? _e : ''] }), _jsxs("div", { children: [__('Název', 'brilo-blocks'), ": ", (_f = attributes.name) !== null && _f !== void 0 ? _f : ''] })] })) : (_jsxs(_Fragment, { children: [_jsx("strong", { children: attributes.label || __('Pole', 'brilo-blocks') }), _jsx("div", { children: attributes.type }), _jsxs("div", { className: "i-form-field__columns-control", children: [_jsx(Button, { size: "small", variant: "secondary", onClick: () => setAttributes({ columns: Math.max(MIN_COLUMNS, currentColumns - 1) }), disabled: currentColumns <= MIN_COLUMNS, "aria-label": __('Snížit počet sloupců', 'brilo-blocks'), children: "-" }), _jsx("div", { className: "i-form-field__columns-value", children: `${currentColumns}/${MAX_COLUMNS}` }), _jsx(Button, { size: "small", variant: "secondary", onClick: () => setAttributes({ columns: Math.min(MAX_COLUMNS, currentColumns + 1) }), disabled: currentColumns >= MAX_COLUMNS, "aria-label": __('Zvýšit počet sloupců', 'brilo-blocks'), children: "+" })] })] })) }) })] }));
32
41
  };
33
42
  }
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/factory.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAA;AAIzD,OAAO,KAAK,EAAC,mBAAmB,EAAE,gBAAgB,EAAC,MAAM,SAAS,CAAA;AAElE,YAAY,EAAC,mBAAmB,EAAE,gBAAgB,EAAC,CAAA;AAEnD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAwBvG"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/factory.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAA;AAIzD,OAAO,KAAK,EAAC,mBAAmB,EAAE,gBAAgB,EAAC,MAAM,SAAS,CAAA;AAElE,YAAY,EAAC,mBAAmB,EAAE,gBAAgB,EAAC,CAAA;AAEnD,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,gBAAgB,GAAG,kBAAkB,CAAC,mBAAmB,CAAC,CAyBvG"}
@@ -20,6 +20,7 @@ export function createFormFieldBlock(options) {
20
20
  placeholder: { type: 'string', default: '' },
21
21
  required: { type: 'boolean', default: false },
22
22
  options: { type: 'array', default: [] },
23
+ selectMode: { type: 'string', default: 'classic' },
23
24
  defaultValue: { type: 'string', default: '' },
24
25
  value: { type: 'string', default: '' },
25
26
  },
@@ -0,0 +1,18 @@
1
+ export type PersistedOption = string | {
2
+ label?: unknown;
3
+ value?: unknown;
4
+ email?: unknown;
5
+ };
6
+ export type OptionRow = {
7
+ id: string;
8
+ label: string;
9
+ value: string;
10
+ email: string;
11
+ };
12
+ export declare function normalizeOptions(options: unknown): OptionRow[];
13
+ export declare function serializeOptions(rows: OptionRow[]): Array<{
14
+ label: string;
15
+ value?: string;
16
+ email?: string;
17
+ }>;
18
+ //# sourceMappingURL=normalizeOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"normalizeOptions.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/normalizeOptions.ts"],"names":[],"mappings":"AAAA,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,OAAO,CAAA;CAAC,CAAA;AAE1F,MAAM,MAAM,SAAS,GAAG;IACtB,EAAE,EAAE,MAAM,CAAA;IACV,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,EAAE,MAAM,CAAA;CACd,CAAA;AAMD,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,EAAE,CA0B9D;AAED,wBAAgB,gBAAgB,CAAC,IAAI,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC,CAAC,CAgB1G"}
@@ -0,0 +1,39 @@
1
+ function makeId() {
2
+ return typeof crypto !== 'undefined' && 'randomUUID' in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`;
3
+ }
4
+ export function normalizeOptions(options) {
5
+ if (!Array.isArray(options)) {
6
+ return [];
7
+ }
8
+ return options
9
+ .map((option) => {
10
+ if (typeof option === 'string') {
11
+ return option === '' ? null : { id: makeId(), label: option, value: '', email: '' };
12
+ }
13
+ if (option && typeof option === 'object') {
14
+ const label = typeof option.label === 'string' ? option.label : '';
15
+ const value = typeof option.value === 'string' ? option.value : '';
16
+ const email = typeof option.email === 'string' ? option.email : '';
17
+ if (label === '') {
18
+ return null;
19
+ }
20
+ return { id: makeId(), label, value, email };
21
+ }
22
+ return null;
23
+ })
24
+ .filter((row) => row !== null);
25
+ }
26
+ export function serializeOptions(rows) {
27
+ return rows
28
+ .filter((row) => row.label.trim() !== '')
29
+ .map((row) => {
30
+ const option = { label: row.label };
31
+ if (row.value.trim() !== '') {
32
+ option.value = row.value.trim();
33
+ }
34
+ if (row.email.trim() !== '') {
35
+ option.email = row.email.trim();
36
+ }
37
+ return option;
38
+ });
39
+ }
@@ -1,7 +1,13 @@
1
- import { FIELD_TEXT_TYPE_VALUES, FIELD_TYPE_VALUES } from './constants';
1
+ import { FIELD_SELECT_MODE_VALUES, FIELD_TEXT_TYPE_VALUES, FIELD_TYPE_VALUES } from './constants';
2
2
  import type { BriloBlockType } from '../../../types';
3
3
  export type FormFieldType = (typeof FIELD_TYPE_VALUES)[number];
4
4
  export type FormFieldTextType = (typeof FIELD_TEXT_TYPE_VALUES)[number];
5
+ export type FormFieldSelectMode = (typeof FIELD_SELECT_MODE_VALUES)[number];
6
+ export type FormFieldOption = string | {
7
+ label?: string;
8
+ value?: string;
9
+ email?: string;
10
+ };
5
11
  export interface FormFieldAttributes extends Record<string, unknown> {
6
12
  type: FormFieldType;
7
13
  textType: FormFieldTextType;
@@ -10,7 +16,8 @@ export interface FormFieldAttributes extends Record<string, unknown> {
10
16
  name: string;
11
17
  placeholder: string;
12
18
  required: boolean;
13
- options: string[];
19
+ options: FormFieldOption[];
20
+ selectMode: FormFieldSelectMode;
14
21
  defaultValue: string;
15
22
  value: string;
16
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAmB,sBAAsB,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAA;AACvF,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAA;AAE3C,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAC9D,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;AAEvE,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAClE,IAAI,EAAE,aAAa,CAAA;IACnB,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-field/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,wBAAwB,EAAoB,sBAAsB,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAA;AACjH,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAA;AAE3C,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAA;AAC9D,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAA;AACvE,MAAM,MAAM,mBAAmB,GAAG,CAAC,OAAO,wBAAwB,CAAC,CAAC,MAAM,CAAC,CAAA;AAE3E,MAAM,MAAM,eAAe,GAAG,MAAM,GAAG;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAA;CAAC,CAAA;AAEvF,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAClE,IAAI,EAAE,aAAa,CAAA;IACnB,QAAQ,EAAE,iBAAiB,CAAA;IAC3B,OAAO,EAAE,MAAM,CAAA;IACf,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,EAAE,MAAM,CAAA;IACZ,WAAW,EAAE,MAAM,CAAA;IACnB,QAAQ,EAAE,OAAO,CAAA;IACjB,OAAO,EAAE,eAAe,EAAE,CAAA;IAC1B,UAAU,EAAE,mBAAmB,CAAA;IAC/B,YAAY,EAAE,MAAM,CAAA;IACpB,KAAK,EAAE,MAAM,CAAA;CACd;AAED,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG"}
@@ -1,4 +1,4 @@
1
- export declare const COLUMNS: readonly [5, 4, 3, 2];
1
+ export declare const COLUMNS: readonly [4, 3, 2];
2
2
  export declare const RATIOS: readonly ['4:3', '3:2', '16:9', '1:1', '2:1', '3:4'];
3
3
  export declare const HEADING_LEVELS: readonly [2, 3, 4];
4
4
  export declare const DEFAULT_SHADOWS: readonly [{
@@ -1 +1 @@
1
- {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/blocks/signpost/signpost-group/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,YAAI,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAU,CAAA;AAC5C,eAAO,MAAM,MAAM,YAAI,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU,CAAA;AAC1E,eAAO,MAAM,cAAc,YAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAU,CAAA;AAEhD,eAAO,MAAM,eAAe;aACzB,KAAK,EAAE,MAAM;aAAE,KAAK;;aACpB,KAAK,EAAE,IAAI;aAAE,KAAK;;aAClB,KAAK,EAAE,IAAI;aAAE,KAAK;EACX,CAAA;AAEV,eAAO,MAAM,aAAa;aACvB,KAAK,EAAE,CAAC;aAAE,KAAK,EAAE,GAAG;;aACpB,KAAK,EAAE,GAAG;aAAE,KAAK,EAAE,KAAK;;aACxB,KAAK,EAAE,CAAC;aAAE,KAAK,EAAE,GAAG;;aACpB,KAAK,EAAE,GAAG;aAAE,KAAK,EAAE,KAAK;;aACxB,KAAK,EAAE,CAAC;aAAE,KAAK,EAAE,GAAG;EACb,CAAA"}
1
+ {"version":3,"file":"constants.d.ts","sourceRoot":"","sources":["../../../../src/blocks/signpost/signpost-group/constants.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,OAAO,YAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAU,CAAA;AACzC,eAAO,MAAM,MAAM,YAAI,KAAK,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,CAAU,CAAA;AAC1E,eAAO,MAAM,cAAc,YAAI,CAAC,EAAE,CAAC,EAAE,CAAC,CAAU,CAAA;AAEhD,eAAO,MAAM,eAAe;aACzB,KAAK,EAAE,MAAM;aAAE,KAAK;;aACpB,KAAK,EAAE,IAAI;aAAE,KAAK;;aAClB,KAAK,EAAE,IAAI;aAAE,KAAK;EACX,CAAA;AAEV,eAAO,MAAM,aAAa;aACvB,KAAK,EAAE,CAAC;aAAE,KAAK,EAAE,GAAG;;aACpB,KAAK,EAAE,GAAG;aAAE,KAAK,EAAE,KAAK;;aACxB,KAAK,EAAE,CAAC;aAAE,KAAK,EAAE,GAAG;;aACpB,KAAK,EAAE,GAAG;aAAE,KAAK,EAAE,KAAK;;aACxB,KAAK,EAAE,CAAC;aAAE,KAAK,EAAE,GAAG;EACb,CAAA"}
@@ -1,5 +1,5 @@
1
1
  import { __ } from '@wordpress/i18n';
2
- export const COLUMNS = [5, 4, 3, 2];
2
+ export const COLUMNS = [4, 3, 2];
3
3
  export const RATIOS = ['4:3', '3:2', '16:9', '1:1', '2:1', '3:4'];
4
4
  export const HEADING_LEVELS = [2, 3, 4];
5
5
  export const DEFAULT_SHADOWS = [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brilo/base-blocks",
3
- "version": "0.1.21",
3
+ "version": "0.1.22",
4
4
  "author": "Brilo",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
@@ -22,6 +22,7 @@
22
22
  "devDependencies": {
23
23
  "@biomejs/biome": "2.5.6",
24
24
  "@types/react": "^18.3.12",
25
+ "@types/sortablejs": "^1.15.8",
25
26
  "@types/wordpress__block-editor": "^15.0.6",
26
27
  "@wordpress/block-editor": "^16.1.0",
27
28
  "@wordpress/blocks": "^15.25.0",
@@ -34,7 +35,9 @@
34
35
  "typescript": "^7.0.2"
35
36
  },
36
37
  "dependencies": {
37
- "clsx": "^2.1.1"
38
+ "clsx": "^2.1.1",
39
+ "react-sortablejs": "^6.1.4",
40
+ "sortablejs": "^1.15.7"
38
41
  },
39
42
  "files": [
40
43
  "build",
@@ -0,0 +1,111 @@
1
+ import {Button, Card, CardBody, Flex, FlexBlock, FlexItem, TextControl} from '@wordpress/components'
2
+ import {__} from '@wordpress/i18n'
3
+ import {ReactSortable} from 'react-sortablejs'
4
+ import type {OptionRow} from './normalizeOptions'
5
+
6
+ const EMAIL_PATTERN = /^[^\s@]+@[^\s@]+\.[^\s@]+$/
7
+
8
+ type Props = {
9
+ rows: OptionRow[]
10
+ onChange: (rows: OptionRow[]) => void
11
+ showEmail: boolean
12
+ onClose: () => void
13
+ }
14
+
15
+ export function SelectOptionsRepeater({rows, onChange, showEmail, onClose}: Props) {
16
+ const updateRow = (id: string, patch: Partial<OptionRow>) => {
17
+ onChange(rows.map((row) => (row.id === id ? {...row, ...patch} : row)))
18
+ }
19
+
20
+ const removeRow = (id: string) => {
21
+ onChange(rows.filter((row) => row.id !== id))
22
+ }
23
+
24
+ const addRow = () => {
25
+ onChange([...rows, {id: `${Date.now()}-${Math.random()}`, label: '', value: '', email: ''}])
26
+ }
27
+
28
+ return (
29
+ <div className="i-form-field__options-repeater">
30
+ <ReactSortable list={rows} setList={onChange} handle=".i-form-field__option-drag-handle" animation={150}>
31
+ {rows.map((row) => {
32
+ const isEmailInvalid = row.email.trim() !== '' && !EMAIL_PATTERN.test(row.email.trim())
33
+
34
+ return (
35
+ <Card size="small" className="i-form-field__option-row" key={row.id}>
36
+ <CardBody>
37
+ <Flex align="flex-start" gap={3}>
38
+ <FlexItem>
39
+ <span className="i-form-field__option-drag-handle" aria-hidden="true">
40
+ ⠿
41
+ </span>
42
+ </FlexItem>
43
+
44
+ <FlexBlock>
45
+ <Flex direction="column" gap={3}>
46
+ <FlexItem>
47
+ <TextControl
48
+ label={__('Popisek', 'brilo-blocks')}
49
+ placeholder={__('Popisek možnosti', 'brilo-blocks')}
50
+ value={row.label}
51
+ onChange={(label) => updateRow(row.id, {label})}
52
+ />
53
+ </FlexItem>
54
+
55
+ <FlexItem>
56
+ <TextControl
57
+ label={__('Hodnota', 'brilo-blocks')}
58
+ placeholder={__('auto (dle popisku)', 'brilo-blocks')}
59
+ value={row.value}
60
+ onChange={(value) => updateRow(row.id, {value})}
61
+ help={__('Volitelné, jinak se odvodí z popisku.', 'brilo-blocks')}
62
+ />
63
+ </FlexItem>
64
+
65
+ {showEmail && (
66
+ <FlexItem>
67
+ <TextControl
68
+ label={__('E-mail', 'brilo-blocks')}
69
+ type="email"
70
+ placeholder={__('Email příjemce (volitelné)', 'brilo-blocks')}
71
+ value={row.email}
72
+ onChange={(email) => updateRow(row.id, {email})}
73
+ help={isEmailInvalid ? __('Neplatný formát emailu.', 'brilo-blocks') : undefined}
74
+ />
75
+ </FlexItem>
76
+ )}
77
+ </Flex>
78
+ </FlexBlock>
79
+
80
+ <FlexItem>
81
+ <Button
82
+ icon="no-alt"
83
+ size="small"
84
+ variant="tertiary"
85
+ isDestructive
86
+ label={__('Odebrat možnost', 'brilo-blocks')}
87
+ onClick={() => removeRow(row.id)}
88
+ />
89
+ </FlexItem>
90
+ </Flex>
91
+ </CardBody>
92
+ </Card>
93
+ )
94
+ })}
95
+ </ReactSortable>
96
+
97
+ <Flex className="i-form-field__options-footer" justify="flex-start" gap={2}>
98
+ <FlexItem>
99
+ <Button variant="secondary" onClick={addRow}>
100
+ {__('Přidat možnost', 'brilo-blocks')}
101
+ </Button>
102
+ </FlexItem>
103
+ <FlexItem>
104
+ <Button variant="tertiary" onClick={onClose}>
105
+ {__('Zavřít', 'brilo-blocks')}
106
+ </Button>
107
+ </FlexItem>
108
+ </Flex>
109
+ </div>
110
+ )
111
+ }
@@ -22,3 +22,10 @@ export const FIELD_TEXT_TYPES = [
22
22
  export const FIELD_COLUMNS_RANGE = {min: 1, max: 12} as const
23
23
 
24
24
  export const FIELD_COLUMNS_DEFAULT = 6
25
+
26
+ export const FIELD_SELECT_MODE_VALUES = ['classic', 'email'] as const
27
+
28
+ export const FIELD_SELECT_MODES = [
29
+ {value: FIELD_SELECT_MODE_VALUES[0], label: __('Klasický', 'brilo-blocks')},
30
+ {value: FIELD_SELECT_MODE_VALUES[1], label: __('Výběr s routováním e-mailu', 'brilo-blocks')},
31
+ ] as const
@@ -1,9 +1,12 @@
1
1
  import {InspectorControls, useBlockProps} from '@wordpress/block-editor'
2
- import {Button, FormTokenField, PanelBody, RangeControl, SelectControl, TextControl, ToggleControl} from '@wordpress/components'
3
- import {__} from '@wordpress/i18n'
2
+ import {Button, Modal, PanelBody, RangeControl, SelectControl, TextControl, ToggleControl} from '@wordpress/components'
3
+ import {__, sprintf} from '@wordpress/i18n'
4
4
  import clsx from 'clsx'
5
- import {FIELD_COLUMNS_DEFAULT, FIELD_COLUMNS_RANGE, FIELD_TEXT_TYPES, FIELD_TYPES} from './constants'
6
- import {FormFieldAttributes, FormFieldOptions, FormFieldTextType, FormFieldType} from './types'
5
+ import {useState} from 'react'
6
+ import {FIELD_COLUMNS_DEFAULT, FIELD_COLUMNS_RANGE, FIELD_SELECT_MODES, FIELD_TEXT_TYPES, FIELD_TYPES} from './constants'
7
+ import {normalizeOptions, serializeOptions, type OptionRow} from './normalizeOptions'
8
+ import {SelectOptionsRepeater} from './SelectOptionsRepeater'
9
+ import {FormFieldAttributes, FormFieldOptions, FormFieldSelectMode, FormFieldTextType, FormFieldType} from './types'
7
10
 
8
11
  const {min: MIN_COLUMNS, max: MAX_COLUMNS} = FIELD_COLUMNS_RANGE
9
12
 
@@ -32,9 +35,20 @@ export function createFormFieldEdit(_options: FormFieldOptions) {
32
35
  className: clsx('i-form-field', `--type-${attributes.type}`, `--cols-${currentColumns}`, attributes.required && '--required'),
33
36
  })
34
37
 
35
- const options = Array.isArray(attributes.options) ? attributes.options.filter((opt): opt is string => typeof opt === 'string') : []
38
+ // Rows carry a locally-generated id (for React/Sortable identity) that is never persisted;
39
+ // deriving it fresh from attributes on every render would remount inputs and drop focus mid-keystroke.
40
+ const [optionRows, setOptionRows] = useState<OptionRow[]>(() => normalizeOptions(attributes.options))
41
+ const [isOptionsModalOpen, setIsOptionsModalOpen] = useState(false)
36
42
 
37
- const selectOptions = [{label: __('Žádná', 'brilo-blocks'), value: ''}, ...options.map((opt) => ({label: opt, value: opt}))]
43
+ const updateOptionRows = (rows: OptionRow[]) => {
44
+ setOptionRows(rows)
45
+ setAttributes({options: serializeOptions(rows)})
46
+ }
47
+
48
+ const selectOptions = [
49
+ {label: __('Žádná', 'brilo-blocks'), value: ''},
50
+ ...optionRows.map((row) => ({label: row.label, value: row.label})),
51
+ ]
38
52
 
39
53
  return (
40
54
  <>
@@ -85,18 +99,30 @@ export function createFormFieldEdit(_options: FormFieldOptions) {
85
99
 
86
100
  {attributes.type === 'select' && (
87
101
  <>
88
- <FormTokenField
89
- label={__('Možnosti', 'brilo-blocks')}
90
- value={options}
91
- onChange={(nextOptions) =>
92
- setAttributes({
93
- options: (nextOptions ?? [])
94
- .map((opt) => (typeof opt === 'string' ? opt : (opt as {value?: unknown}).value))
95
- .filter((opt): opt is string => typeof opt === 'string' && opt.length > 0),
96
- })
97
- }
102
+ <SelectControl
103
+ label={__('Režim selectu', 'brilo-blocks')}
104
+ value={attributes.selectMode ?? 'classic'}
105
+ options={FIELD_SELECT_MODES.map((m) => ({label: m.label, value: m.value}))}
106
+ onChange={(selectMode) => setAttributes({selectMode: selectMode as FormFieldSelectMode})}
98
107
  />
99
108
 
109
+ <div className="i-form-field__options-trigger">
110
+ <Button variant="secondary" onClick={() => setIsOptionsModalOpen(true)}>
111
+ {sprintf(__('Upravit možnosti (%d)', 'brilo-blocks'), optionRows.length)}
112
+ </Button>
113
+ </div>
114
+
115
+ {isOptionsModalOpen && (
116
+ <Modal title={__('Možnosti pole', 'brilo-blocks')} onRequestClose={() => setIsOptionsModalOpen(false)} size="large">
117
+ <SelectOptionsRepeater
118
+ rows={optionRows}
119
+ onChange={updateOptionRows}
120
+ showEmail={(attributes.selectMode ?? 'classic') === 'email'}
121
+ onClose={() => setIsOptionsModalOpen(false)}
122
+ />
123
+ </Modal>
124
+ )}
125
+
100
126
  <SelectControl
101
127
  label={__('Výchozí hodnota', 'brilo-blocks')}
102
128
  value={attributes.defaultValue ?? ''}
@@ -69,3 +69,31 @@
69
69
  text-align: center;
70
70
  font-weight: 600;
71
71
  }
72
+
73
+ .i-form-field__options-trigger {
74
+ margin-block: 16px;
75
+ }
76
+
77
+ .i-form-field__options-repeater {
78
+ margin-bottom: 16px;
79
+ }
80
+
81
+ .i-form-field__option-row {
82
+ margin-bottom: 8px;
83
+ }
84
+
85
+ // Sticky within the WP Modal own scrolling content area (.components-modal__content),
86
+ // so it stays visible while the option rows above it scroll.
87
+ .i-form-field__options-footer {
88
+ position: sticky;
89
+ bottom: 0;
90
+ padding-top: 12px;
91
+ margin-top: 8px;
92
+ background: #fff;
93
+ border-top: 1px solid rgba(0, 0, 0, 0.1);
94
+ }
95
+
96
+ .i-form-field__option-drag-handle {
97
+ cursor: grab;
98
+ color: rgba(0, 0, 0, 0.4);
99
+ }
@@ -24,6 +24,7 @@ export function createFormFieldBlock(options: FormFieldOptions): BlockConfigurat
24
24
  placeholder: {type: 'string', default: ''},
25
25
  required: {type: 'boolean', default: false},
26
26
  options: {type: 'array', default: []},
27
+ selectMode: {type: 'string', default: 'classic'},
27
28
  defaultValue: {type: 'string', default: ''},
28
29
  value: {type: 'string', default: ''},
29
30
  },
@@ -0,0 +1,58 @@
1
+ export type PersistedOption = string | {label?: unknown; value?: unknown; email?: unknown}
2
+
3
+ export type OptionRow = {
4
+ id: string
5
+ label: string
6
+ value: string
7
+ email: string
8
+ }
9
+
10
+ function makeId(): string {
11
+ return typeof crypto !== 'undefined' && 'randomUUID' in crypto ? crypto.randomUUID() : `${Date.now()}-${Math.random()}`
12
+ }
13
+
14
+ export function normalizeOptions(options: unknown): OptionRow[] {
15
+ if (!Array.isArray(options)) {
16
+ return []
17
+ }
18
+
19
+ return (options as PersistedOption[])
20
+ .map((option): OptionRow | null => {
21
+ if (typeof option === 'string') {
22
+ return option === '' ? null : {id: makeId(), label: option, value: '', email: ''}
23
+ }
24
+
25
+ if (option && typeof option === 'object') {
26
+ const label = typeof option.label === 'string' ? option.label : ''
27
+ const value = typeof option.value === 'string' ? option.value : ''
28
+ const email = typeof option.email === 'string' ? option.email : ''
29
+
30
+ if (label === '') {
31
+ return null
32
+ }
33
+
34
+ return {id: makeId(), label, value, email}
35
+ }
36
+
37
+ return null
38
+ })
39
+ .filter((row): row is OptionRow => row !== null)
40
+ }
41
+
42
+ export function serializeOptions(rows: OptionRow[]): Array<{label: string; value?: string; email?: string}> {
43
+ return rows
44
+ .filter((row) => row.label.trim() !== '')
45
+ .map((row) => {
46
+ const option: {label: string; value?: string; email?: string} = {label: row.label}
47
+
48
+ if (row.value.trim() !== '') {
49
+ option.value = row.value.trim()
50
+ }
51
+
52
+ if (row.email.trim() !== '') {
53
+ option.email = row.email.trim()
54
+ }
55
+
56
+ return option
57
+ })
58
+ }