@brilo/base-blocks 0.1.38 → 0.1.39

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 +1 @@
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
+ {"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,iCAiNF"}
@@ -20,7 +20,7 @@ function sanitizeHtmlName(raw) {
20
20
  }
21
21
  export function createFormFieldEdit(_options) {
22
22
  return function Edit({ attributes, setAttributes, }) {
23
- var _a, _b, _c, _d, _e, _f;
23
+ var _a, _b, _c, _d, _e, _f, _g, _h;
24
24
  const currentColumns = Math.max(MIN_COLUMNS, Math.min(MAX_COLUMNS, attributes.columns || MIN_COLUMNS));
25
25
  const blockProps = useBlockProps({
26
26
  className: clsx('i-form-field', `--type-${attributes.type}`, `--cols-${currentColumns}`, attributes.required && '--required'),
@@ -37,6 +37,8 @@ export function createFormFieldEdit(_options) {
37
37
  { label: __('Žádná', 'brilo-blocks'), value: '' },
38
38
  ...optionRows.map((row) => ({ label: row.label, value: row.label })),
39
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: "+" })] })] })) }) })] }));
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' && (_jsxs(_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: (textType) => setAttributes(textType === 'email'
41
+ ? { textType: textType }
42
+ : { textType: textType, isReplyTo: false }) }), attributes.textType === 'email' && (_jsx(ToggleControl, { label: __('Použít jako Reply-To pole', 'brilo-blocks'), help: __('Hodnota tohoto pole se použije jako Reply-To adresa notifikačního e-mailu.', 'brilo-blocks'), checked: (_a = attributes.isReplyTo) !== null && _a !== void 0 ? _a : false, onChange: (isReplyTo) => setAttributes({ isReplyTo }) }))] })), 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 }) }), _jsx(ToggleControl, { label: __('Odesílat do GTM (dataLayer)', 'brilo-blocks'), help: __('Po úspěšném odeslání formuláře se do dataLayer pushne klíč podle názvu html atributu s vyplněnou/vybranou hodnotou tohoto pole.', 'brilo-blocks'), checked: (_b = attributes.gtmEnabled) !== null && _b !== void 0 ? _b : false, onChange: (gtmEnabled) => setAttributes({ gtmEnabled }) })] })), attributes.type === 'select' && (_jsxs(_Fragment, { children: [_jsx(SelectControl, { label: __('Režim selectu', 'brilo-blocks'), value: (_c = attributes.selectMode) !== null && _c !== void 0 ? _c : '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: ((_d = attributes.selectMode) !== null && _d !== void 0 ? _d : 'classic') === 'email', onClose: () => setIsOptionsModalOpen(false) }) })), _jsx(SelectControl, { label: __('Výchozí hodnota', 'brilo-blocks'), value: (_e = attributes.defaultValue) !== null && _e !== void 0 ? _e : '', 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: (_f = attributes.value) !== null && _f !== void 0 ? _f : '', 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'), ": ", (_g = attributes.value) !== null && _g !== void 0 ? _g : ''] }), _jsxs("div", { children: [__('Název', 'brilo-blocks'), ": ", (_h = attributes.name) !== null && _h !== void 0 ? _h : ''] })] })) : (_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: "+" })] })] })) }) })] }));
41
43
  };
42
44
  }
@@ -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,CAyBvG"}
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,CA2BvG"}
@@ -23,6 +23,8 @@ export function createFormFieldBlock(options) {
23
23
  selectMode: { type: 'string', default: 'classic' },
24
24
  defaultValue: { type: 'string', default: '' },
25
25
  value: { type: 'string', default: '' },
26
+ isReplyTo: { type: 'boolean', default: false },
27
+ gtmEnabled: { type: 'boolean', default: false },
26
28
  },
27
29
  edit: createFormFieldEdit(options),
28
30
  save: () => null,
@@ -20,6 +20,8 @@ export interface FormFieldAttributes extends Record<string, unknown> {
20
20
  selectMode: FormFieldSelectMode;
21
21
  defaultValue: string;
22
22
  value: string;
23
+ isReplyTo: boolean;
24
+ gtmEnabled: boolean;
23
25
  }
24
26
  export interface FormFieldOptions extends BriloBlockType {
25
27
  }
@@ -1 +1 @@
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
+ {"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;IACb,SAAS,EAAE,OAAO,CAAA;IAClB,UAAU,EAAE,OAAO,CAAA;CACpB;AAED,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG"}
@@ -1 +1 @@
1
- {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-group/edit.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAiB,mBAAmB,EAAE,gBAAgB,EAAyC,MAAM,SAAS,CAAA;AAW1H,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,8CAKxD;IACD,UAAU,EAAE,mBAAmB,CAAA;IAC/B,aAAa,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;IACxD,QAAQ,EAAE,MAAM,CAAA;CACjB,iCAwLF"}
1
+ {"version":3,"file":"edit.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-group/edit.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAiB,mBAAmB,EAAE,gBAAgB,EAAyC,MAAM,SAAS,CAAA;AA8C1H,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,gBAAgB,8CAKxD;IACD,UAAU,EAAE,mBAAmB,CAAA;IAC/B,aAAa,EAAE,CAAC,CAAC,EAAE,OAAO,CAAC,mBAAmB,CAAC,KAAK,IAAI,CAAA;IACxD,QAAQ,EAAE,MAAM,CAAA;CACjB,iCAyRF"}
@@ -1,11 +1,11 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { InspectorControls, RichText } from '@wordpress/block-editor';
3
3
  import { FormTokenField, Notice, PanelBody, SelectControl, TextControl, ToggleControl } from '@wordpress/components';
4
- import { useDispatch } from '@wordpress/data';
4
+ import { useDispatch, useSelect } from '@wordpress/data';
5
5
  import { __ } from '@wordpress/i18n';
6
6
  import { cleanForSlug } from '@wordpress/url';
7
7
  import clsx from 'clsx';
8
- import { useEffect } from 'react';
8
+ import { useEffect, useMemo } from 'react';
9
9
  import { useGroupBlock } from '../../../hooks/useGroupBlock';
10
10
  import { EXTERNAL_METHODS, INTERNAL_SUBMIT_BEHAVIORS, PROCESSING_MODES } from './constants';
11
11
  const ALLOWED_BLOCKS = ['brilo/form-field'];
@@ -14,10 +14,38 @@ function generateFormId(formName) {
14
14
  const hash = Math.random().toString(36).slice(2, 8);
15
15
  return `form-${slug}-${hash}`;
16
16
  }
17
+ function slugifyFieldName(raw) {
18
+ return (raw !== null && raw !== void 0 ? raw : '')
19
+ .normalize('NFD')
20
+ .replace(/\p{Diacritic}/gu, '')
21
+ .replace(/[\s_]+/g, '-')
22
+ .replace(/[^a-zA-Z0-9_-]/g, '')
23
+ .replace(/[-_]{2,}/g, '-')
24
+ .replace(/^[-_]+/g, '')
25
+ .toLowerCase();
26
+ }
27
+ function gtmPlaceholderValue(type, textType) {
28
+ if (type === 'select') {
29
+ return '<vybraná možnost>';
30
+ }
31
+ if (type === 'textarea') {
32
+ return '<vyplněný text>';
33
+ }
34
+ if (textType === 'email') {
35
+ return '<vyplněný email>';
36
+ }
37
+ if (textType === 'tel') {
38
+ return '<vyplněné telefonní číslo>';
39
+ }
40
+ if (textType === 'number') {
41
+ return '<vyplněné číslo>';
42
+ }
43
+ return '<vyplněná hodnota>';
44
+ }
17
45
  export function createFormGroupEdit(options) {
18
46
  return function Edit({ attributes, setAttributes, clientId, }) {
19
47
  var _a, _b, _c;
20
- var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w;
48
+ var _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0;
21
49
  const { lockPostSaving, unlockPostSaving } = useDispatch('core/editor');
22
50
  const processingMode = (_d = attributes.processingMode) !== null && _d !== void 0 ? _d : 'internal';
23
51
  const isInternal = processingMode === 'internal';
@@ -25,16 +53,37 @@ export function createFormGroupEdit(options) {
25
53
  const recipients = Array.isArray(attributes.senders) ? attributes.senders : [];
26
54
  const isRecipientsMissing = isInternal && recipients.length === 0;
27
55
  const isExternalUrlMissing = isExternal && ((_e = attributes.externalUrl) !== null && _e !== void 0 ? _e : '').trim() === '';
56
+ const { replyToCount, gtmFields } = useSelect((select) => {
57
+ const editor = select('core/block-editor');
58
+ const blocks = editor.getBlocks(clientId) || [];
59
+ const replyToCount = blocks.filter((block) => block.attributes.type === 'text' && block.attributes.textType === 'email' && block.attributes.isReplyTo === true).length;
60
+ const gtmFields = blocks.filter((block) => block.attributes.gtmEnabled).map((block) => block.attributes);
61
+ return { replyToCount, gtmFields };
62
+ }, [clientId]);
63
+ const hasMultipleReplyTo = replyToCount > 1;
64
+ const gtmPreview = useMemo(() => {
65
+ var _a;
66
+ const preview = {
67
+ event: ((_a = attributes.gtmEventName) !== null && _a !== void 0 ? _a : '').trim() || '<název eventu>',
68
+ url: '<URL stránky, odkud bylo odesláno>',
69
+ };
70
+ gtmFields.forEach((field) => {
71
+ var _a;
72
+ const name = (field.name && field.name.trim() !== '' ? field.name : slugifyFieldName((_a = field.label) !== null && _a !== void 0 ? _a : '')) || '<pole-bez-nazvu>';
73
+ preview[name] = gtmPlaceholderValue(field.type, field.textType);
74
+ });
75
+ return preview;
76
+ }, [attributes.gtmEventName, gtmFields]);
28
77
  useEffect(() => {
29
78
  const lockName = `brilo-form-group-${clientId}`;
30
- if (isRecipientsMissing || isExternalUrlMissing) {
79
+ if (isRecipientsMissing || isExternalUrlMissing || hasMultipleReplyTo) {
31
80
  lockPostSaving(lockName);
32
81
  }
33
82
  else {
34
83
  unlockPostSaving(lockName);
35
84
  }
36
85
  return () => unlockPostSaving(lockName);
37
- }, [clientId, isRecipientsMissing, isExternalUrlMissing, lockPostSaving, unlockPostSaving]);
86
+ }, [clientId, isRecipientsMissing, isExternalUrlMissing, hasMultipleReplyTo, lockPostSaving, unlockPostSaving]);
38
87
  // Generated once and persisted into the block's attributes so it stays stable across edits.
39
88
  // biome-ignore lint/correctness/useExhaustiveDependencies: must run once on mount only
40
89
  useEffect(() => {
@@ -51,10 +100,10 @@ export function createFormGroupEdit(options) {
51
100
  orientation: 'horizontal',
52
101
  layout: { type: 'default' },
53
102
  });
54
- return (_jsxs(_Fragment, { children: [_jsx(InspectorControls, { children: _jsxs(PanelBody, { title: __('Formulář', 'brilo-blocks'), children: [_jsx(TextControl, { label: __('ID formuláře', 'brilo-blocks'), value: (_j = attributes.formId) !== null && _j !== void 0 ? _j : '', readOnly: true, onChange: () => { }, help: __('Generuje se automaticky, slouží k jednoznačné identifikaci formuláře.', 'brilo-blocks') }), _jsx(TextControl, { label: __('Název formuláře (volitelné)', 'brilo-blocks'), value: (_k = attributes.formName) !== null && _k !== void 0 ? _k : '', placeholder: __('Např. Kontaktní formulář', 'brilo-blocks'), onChange: (formName) => setAttributes({ formName }) }), _jsx(SelectControl, { label: __('Zpracování', 'brilo-blocks'), value: processingMode, options: PROCESSING_MODES.map((m) => ({ label: m.label, value: m.value })), onChange: (mode) => setAttributes({ processingMode: mode }) }), isExternal && (_jsxs(_Fragment, { children: [_jsx(SelectControl, { label: __('Metoda odeslání', 'brilo-blocks'), value: (_l = attributes.externalMethod) !== null && _l !== void 0 ? _l : 'POST', options: EXTERNAL_METHODS.map((m) => ({ label: m.label, value: m.value })), onChange: (externalMethod) => setAttributes({ externalMethod: externalMethod }) }), _jsx(TextControl, { label: __('Externí URL', 'brilo-blocks'), value: (_m = attributes.externalUrl) !== null && _m !== void 0 ? _m : '', onChange: (externalUrl) => setAttributes({ externalUrl }) }), isExternalUrlMissing && (_jsx(Notice, { status: "warning", isDismissible: false, children: __('Pole „Externí URL“ je povinné pro externí zpracování.', 'brilo-blocks') }))] })), isInternal && (_jsxs(_Fragment, { children: [_jsx(FormTokenField, { label: __('Komu (příjemci)', 'brilo-blocks'), value: recipients, __next40pxDefaultSize: true, onChange: (senders) => setAttributes({
55
- senders: (senders !== null && senders !== void 0 ? senders : [])
56
- .map((item) => (typeof item === 'string' ? item.trim() : ''))
57
- .filter((item) => item.length > 0),
58
- }) }), isRecipientsMissing && (_jsx(Notice, { status: "warning", isDismissible: false, children: __('Pole „Komu (příjemci)“ je povinné. Vyplňte alespoň jeden e-mail příjemce.', 'brilo-blocks') })), _jsx(TextControl, { label: __('Od koho (From email)', 'brilo-blocks'), value: (_o = attributes.fromEmail) !== null && _o !== void 0 ? _o : '', onChange: (fromEmail) => setAttributes({ fromEmail }) }), _jsx(TextControl, { label: __('Předmět emailu', 'brilo-blocks'), value: (_p = attributes.subject) !== null && _p !== void 0 ? _p : '', placeholder: __('Potvrzení odeslaného formuláře', 'brilo-blocks'), onChange: (subject) => setAttributes({ subject }) }), _jsx(SelectControl, { label: __('Po odeslání', 'brilo-blocks'), value: (_q = attributes.internalSubmitBehavior) !== null && _q !== void 0 ? _q : 'stay', options: INTERNAL_SUBMIT_BEHAVIORS.map((b) => ({ label: b.label, value: b.value })), onChange: (internalSubmitBehavior) => setAttributes({ internalSubmitBehavior: internalSubmitBehavior }) }), ((_r = attributes.internalSubmitBehavior) !== null && _r !== void 0 ? _r : 'stay') === 'redirect' && (_jsx(TextControl, { label: __('URL děkovné stránky', 'brilo-blocks'), value: (_s = attributes.internalRedirectUrl) !== null && _s !== void 0 ? _s : '', onChange: (internalRedirectUrl) => setAttributes({ internalRedirectUrl }) })), _jsx(TextControl, { label: __('Úspěšná zpráva', 'brilo-blocks'), value: (_t = attributes.successMessage) !== null && _t !== void 0 ? _t : '', onChange: (successMessage) => setAttributes({ successMessage }) })] })), _jsx(TextControl, { label: __('Titulek tlačítka odeslání', 'brilo-blocks'), value: (_u = (_a = attributes.submit) === null || _a === void 0 ? void 0 : _a.label) !== null && _u !== void 0 ? _u : 'Odeslat', onChange: (label) => setAttributes({ submit: { label } }) })] }) }), _jsxs("div", { ...blockProps, children: [_jsx("div", { ...innerBlocksProps }), _jsxs("div", { className: "g-form__gdpr", children: [_jsxs("div", { className: "g-form__gdpr-header", children: [_jsx("strong", { children: __('GDPR obsah', 'brilo-blocks') }), _jsx(ToggleControl, { label: __('S checkboxem?', 'brilo-blocks'), checked: (_v = (_b = attributes.gdpr) === null || _b === void 0 ? void 0 : _b.checkbox) !== null && _v !== void 0 ? _v : true, onChange: (checkbox) => { var _a; var _b; return setAttributes({ gdpr: { content: (_b = (_a = attributes.gdpr) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : '', checkbox } }); } })] }), _jsx(RichText, { className: "g-form__gdpr-content", tagName: "div", value: (_w = (_c = attributes.gdpr) === null || _c === void 0 ? void 0 : _c.content) !== null && _w !== void 0 ? _w : '', allowedFormats: ['core/bold', 'core/link'], onChange: (content) => { var _a; var _b; return setAttributes({ gdpr: { content, checkbox: (_b = (_a = attributes.gdpr) === null || _a === void 0 ? void 0 : _a.checkbox) !== null && _b !== void 0 ? _b : true } }); }, placeholder: __('Text GDPR souhlasu…', 'brilo-blocks') })] })] })] }));
103
+ return (_jsxs(_Fragment, { children: [_jsxs(InspectorControls, { children: [_jsxs(PanelBody, { title: __('Formulář', 'brilo-blocks'), children: [_jsx(TextControl, { label: __('ID formuláře', 'brilo-blocks'), value: (_j = attributes.formId) !== null && _j !== void 0 ? _j : '', readOnly: true, onChange: () => { }, help: __('Generuje se automaticky, slouží k jednoznačné identifikaci formuláře.', 'brilo-blocks') }), _jsx(TextControl, { label: __('Název formuláře (volitelné)', 'brilo-blocks'), value: (_k = attributes.formName) !== null && _k !== void 0 ? _k : '', placeholder: __('Např. Kontaktní formulář', 'brilo-blocks'), onChange: (formName) => setAttributes({ formName }) }), _jsx(SelectControl, { label: __('Zpracování', 'brilo-blocks'), value: processingMode, options: PROCESSING_MODES.map((m) => ({ label: m.label, value: m.value })), onChange: (mode) => setAttributes({ processingMode: mode }) }), isExternal && (_jsxs(_Fragment, { children: [_jsx(SelectControl, { label: __('Metoda odeslání', 'brilo-blocks'), value: (_l = attributes.externalMethod) !== null && _l !== void 0 ? _l : 'POST', options: EXTERNAL_METHODS.map((m) => ({ label: m.label, value: m.value })), onChange: (externalMethod) => setAttributes({ externalMethod: externalMethod }) }), _jsx(TextControl, { label: __('Externí URL', 'brilo-blocks'), value: (_m = attributes.externalUrl) !== null && _m !== void 0 ? _m : '', onChange: (externalUrl) => setAttributes({ externalUrl }) }), isExternalUrlMissing && (_jsx(Notice, { status: "warning", isDismissible: false, children: __('Pole „Externí URL“ je povinné pro externí zpracování.', 'brilo-blocks') }))] })), isInternal && (_jsxs(_Fragment, { children: [_jsx(FormTokenField, { label: __('Komu (příjemci)', 'brilo-blocks'), value: recipients, __next40pxDefaultSize: true, onChange: (senders) => setAttributes({
104
+ senders: (senders !== null && senders !== void 0 ? senders : [])
105
+ .map((item) => (typeof item === 'string' ? item.trim() : ''))
106
+ .filter((item) => item.length > 0),
107
+ }) }), isRecipientsMissing && (_jsx(Notice, { status: "warning", isDismissible: false, children: __('Pole „Komu (příjemci)“ je povinné. Vyplňte alespoň jeden e-mail příjemce.', 'brilo-blocks') })), _jsx(TextControl, { label: __('Od koho (From email)', 'brilo-blocks'), value: (_o = attributes.fromEmail) !== null && _o !== void 0 ? _o : '', onChange: (fromEmail) => setAttributes({ fromEmail }) }), _jsx(TextControl, { label: __('Předmět emailu', 'brilo-blocks'), value: (_p = attributes.subject) !== null && _p !== void 0 ? _p : '', placeholder: __('Potvrzení odeslaného formuláře', 'brilo-blocks'), onChange: (subject) => setAttributes({ subject }) }), _jsx(SelectControl, { label: __('Po odeslání', 'brilo-blocks'), value: (_q = attributes.internalSubmitBehavior) !== null && _q !== void 0 ? _q : 'stay', options: INTERNAL_SUBMIT_BEHAVIORS.map((b) => ({ label: b.label, value: b.value })), onChange: (internalSubmitBehavior) => setAttributes({ internalSubmitBehavior: internalSubmitBehavior }) }), ((_r = attributes.internalSubmitBehavior) !== null && _r !== void 0 ? _r : 'stay') === 'redirect' && (_jsx(TextControl, { label: __('URL děkovné stránky', 'brilo-blocks'), value: (_s = attributes.internalRedirectUrl) !== null && _s !== void 0 ? _s : '', onChange: (internalRedirectUrl) => setAttributes({ internalRedirectUrl }) })), _jsx(TextControl, { label: __('Úspěšná zpráva', 'brilo-blocks'), value: (_t = attributes.successMessage) !== null && _t !== void 0 ? _t : '', onChange: (successMessage) => setAttributes({ successMessage }) })] })), hasMultipleReplyTo && (_jsx(Notice, { status: "warning", isDismissible: false, children: __('Formulář obsahuje více polí označených jako Reply-To. Podporováno je pouze jedno takové pole.', 'brilo-blocks') })), _jsx(TextControl, { label: __('Titulek tlačítka odeslání', 'brilo-blocks'), value: (_u = (_a = attributes.submit) === null || _a === void 0 ? void 0 : _a.label) !== null && _u !== void 0 ? _u : 'Odeslat', onChange: (label) => setAttributes({ submit: { label } }) })] }), isInternal && (_jsxs(PanelBody, { title: __('Google Tag Manager', 'brilo-blocks'), initialOpen: false, children: [_jsx(ToggleControl, { label: __('Odesílat data do dataLayer', 'brilo-blocks'), help: __('Po úspěšném odeslání formuláře se pushne event do window.dataLayer. Zbytek (cíle, tagy) se nastavuje v GTM.', 'brilo-blocks'), checked: (_v = attributes.gtmEnabled) !== null && _v !== void 0 ? _v : false, onChange: (gtmEnabled) => setAttributes({ gtmEnabled }) }), ((_w = attributes.gtmEnabled) !== null && _w !== void 0 ? _w : false) && (_jsxs(_Fragment, { children: [_jsx(TextControl, { label: __('Název GTM eventu', 'brilo-blocks'), placeholder: __('napr. website_form', 'brilo-blocks'), value: (_x = attributes.gtmEventName) !== null && _x !== void 0 ? _x : '', onChange: (gtmEventName) => setAttributes({ gtmEventName }), help: __('Pushne se { event: <tento název>, url: <stránka, odkud bylo odesláno>, ...pole s GTM }. Jednotlivá pole si zapnete u nich ("Odesílat do GTM").', 'brilo-blocks') }), ((_y = attributes.gtmEventName) !== null && _y !== void 0 ? _y : '').trim() === '' && (_jsx(Notice, { status: "warning", isDismissible: false, children: __('Bez názvu eventu se dataLayer push neodešle.', 'brilo-blocks') })), _jsx("p", { children: _jsx("strong", { children: __('Náhled objektu při úspěšném odeslání:', 'brilo-blocks') }) }), _jsx("pre", { className: "g-form__gtm-preview", children: JSON.stringify(gtmPreview, null, 2) }), gtmFields.length === 0 && (_jsx(Notice, { status: "info", isDismissible: false, children: __('Žádné pole formuláře nemá zapnuté "Odesílat do GTM" - do dataLayer půjde jen event a url. Zapněte to u polí, jejichž hodnotu chcete v dataLayer mít.', 'brilo-blocks') }))] }))] }))] }), _jsxs("div", { ...blockProps, children: [_jsx("div", { ...innerBlocksProps }), _jsxs("div", { className: "g-form__gdpr", children: [_jsxs("div", { className: "g-form__gdpr-header", children: [_jsx("strong", { children: __('GDPR obsah', 'brilo-blocks') }), _jsx(ToggleControl, { label: __('S checkboxem?', 'brilo-blocks'), checked: (_z = (_b = attributes.gdpr) === null || _b === void 0 ? void 0 : _b.checkbox) !== null && _z !== void 0 ? _z : true, onChange: (checkbox) => { var _a; var _b; return setAttributes({ gdpr: { content: (_b = (_a = attributes.gdpr) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : '', checkbox } }); } })] }), _jsx(RichText, { className: "g-form__gdpr-content", tagName: "div", value: (_0 = (_c = attributes.gdpr) === null || _c === void 0 ? void 0 : _c.content) !== null && _0 !== void 0 ? _0 : '', allowedFormats: ['core/bold', 'core/link'], onChange: (content) => { var _a; var _b; return setAttributes({ gdpr: { content, checkbox: (_b = (_a = attributes.gdpr) === null || _a === void 0 ? void 0 : _a.checkbox) !== null && _b !== void 0 ? _b : true } }); }, placeholder: __('Text GDPR souhlasu…', 'brilo-blocks') })] })] })] }));
59
108
  };
60
109
  }
@@ -1 +1 @@
1
- {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-group/factory.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAA;AAGzD,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,CA2BvG"}
1
+ {"version":3,"file":"factory.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-group/factory.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAC,kBAAkB,EAAC,MAAM,mBAAmB,CAAA;AAGzD,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,CA6BvG"}
@@ -26,6 +26,8 @@ export function createFormGroupBlock(options) {
26
26
  submit: { type: 'object', default: { label: 'Odeslat' } },
27
27
  gdpr: { type: 'object', default: { content: '', checkbox: true } },
28
28
  successMessage: { type: 'string', default: 'Formulář byl úspěšně odeslán.' },
29
+ gtmEnabled: { type: 'boolean', default: false },
30
+ gtmEventName: { type: 'string', default: '' },
29
31
  },
30
32
  edit: createFormGroupEdit(options),
31
33
  save: () => _jsx(InnerBlocks.Content, {}),
@@ -21,6 +21,8 @@ export interface FormGroupAttributes extends Record<string, unknown> {
21
21
  checkbox: boolean;
22
22
  };
23
23
  successMessage: string;
24
+ gtmEnabled: boolean;
25
+ gtmEventName: string;
24
26
  }
25
27
  export interface FormGroupOptions extends BriloBlockType {
26
28
  }
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-group/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAA;AAE3C,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,UAAU,CAAA;AACpD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,CAAA;AAC3C,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,UAAU,CAAA;AAExD,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAClE,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,cAAc,CAAA;IAC9B,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,EAAE,MAAM,CAAA;IACnB,sBAAsB,EAAE,sBAAsB,CAAA;IAC9C,mBAAmB,EAAE,MAAM,CAAA;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAA;IACvB,IAAI,EAAE;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAC,CAAA;IAC1C,cAAc,EAAE,MAAM,CAAA;CACvB;AAED,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG"}
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/blocks/form/form-group/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,cAAc,EAAC,MAAM,SAAS,CAAA;AAE3C,MAAM,MAAM,cAAc,GAAG,UAAU,GAAG,UAAU,CAAA;AACpD,MAAM,MAAM,cAAc,GAAG,MAAM,GAAG,KAAK,CAAA;AAC3C,MAAM,MAAM,sBAAsB,GAAG,MAAM,GAAG,UAAU,CAAA;AAExD,MAAM,WAAW,mBAAoB,SAAQ,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IAClE,MAAM,EAAE,MAAM,CAAA;IACd,QAAQ,EAAE,MAAM,CAAA;IAChB,cAAc,EAAE,cAAc,CAAA;IAC9B,cAAc,EAAE,cAAc,CAAA;IAC9B,WAAW,EAAE,MAAM,CAAA;IACnB,sBAAsB,EAAE,sBAAsB,CAAA;IAC9C,mBAAmB,EAAE,MAAM,CAAA;IAC3B,SAAS,EAAE,MAAM,CAAA;IACjB,OAAO,EAAE,MAAM,EAAE,CAAA;IACjB,OAAO,EAAE,MAAM,CAAA;IACf,MAAM,EAAE;QAAC,KAAK,EAAE,MAAM,CAAA;KAAC,CAAA;IACvB,IAAI,EAAE;QAAC,OAAO,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,OAAO,CAAA;KAAC,CAAA;IAC1C,cAAc,EAAE,MAAM,CAAA;IACtB,UAAU,EAAE,OAAO,CAAA;IACnB,YAAY,EAAE,MAAM,CAAA;CACrB;AAED,MAAM,WAAW,gBAAiB,SAAQ,cAAc;CAAG"}
package/package.json CHANGED
@@ -1,9 +1,10 @@
1
1
  {
2
2
  "name": "@brilo/base-blocks",
3
- "version": "0.1.38",
3
+ "version": "0.1.39",
4
4
  "author": "Brilo",
5
5
  "main": "./build/index.js",
6
6
  "types": "./build/index.d.ts",
7
+ "sideEffects": false,
7
8
  "scripts": {
8
9
  "build": "tsc && tsc-alias",
9
10
  "watch": "tsc --watch",
@@ -67,8 +67,23 @@ export function createFormFieldEdit(_options: FormFieldOptions) {
67
67
  label={__('Typ textovho inputu', 'brilo-blocks')}
68
68
  value={attributes.textType}
69
69
  options={FIELD_TEXT_TYPES.map((t) => ({label: t.label, value: t.value}))}
70
- onChange={(fieldType) => setAttributes({textType: fieldType as FormFieldTextType})}
70
+ onChange={(textType) =>
71
+ setAttributes(
72
+ textType === 'email'
73
+ ? {textType: textType as FormFieldTextType}
74
+ : {textType: textType as FormFieldTextType, isReplyTo: false},
75
+ )
76
+ }
71
77
  />
78
+
79
+ {attributes.textType === 'email' && (
80
+ <ToggleControl
81
+ label={__('Použít jako Reply-To pole', 'brilo-blocks')}
82
+ help={__('Hodnota tohoto pole se použije jako Reply-To adresa notifikačního e-mailu.', 'brilo-blocks')}
83
+ checked={attributes.isReplyTo ?? false}
84
+ onChange={(isReplyTo) => setAttributes({isReplyTo})}
85
+ />
86
+ )}
72
87
  </>
73
88
  )}
74
89
 
@@ -94,6 +109,16 @@ export function createFormFieldEdit(_options: FormFieldOptions) {
94
109
  value={attributes.placeholder}
95
110
  onChange={(placeholder) => setAttributes({placeholder})}
96
111
  />
112
+
113
+ <ToggleControl
114
+ label={__('Odesílat do GTM (dataLayer)', 'brilo-blocks')}
115
+ help={__(
116
+ 'Po úspěšném odeslání formuláře se do dataLayer pushne klíč podle názvu html atributu s vyplněnou/vybranou hodnotou tohoto pole.',
117
+ 'brilo-blocks',
118
+ )}
119
+ checked={attributes.gtmEnabled ?? false}
120
+ onChange={(gtmEnabled) => setAttributes({gtmEnabled})}
121
+ />
97
122
  </>
98
123
  )}
99
124
 
@@ -27,6 +27,8 @@ export function createFormFieldBlock(options: FormFieldOptions): BlockConfigurat
27
27
  selectMode: {type: 'string', default: 'classic'},
28
28
  defaultValue: {type: 'string', default: ''},
29
29
  value: {type: 'string', default: ''},
30
+ isReplyTo: {type: 'boolean', default: false},
31
+ gtmEnabled: {type: 'boolean', default: false},
30
32
  },
31
33
  edit: createFormFieldEdit(options),
32
34
  save: () => null,
@@ -19,6 +19,8 @@ export interface FormFieldAttributes extends Record<string, unknown> {
19
19
  selectMode: FormFieldSelectMode
20
20
  defaultValue: string
21
21
  value: string
22
+ isReplyTo: boolean
23
+ gtmEnabled: boolean
22
24
  }
23
25
 
24
26
  export interface FormFieldOptions extends BriloBlockType {}
@@ -1,10 +1,10 @@
1
1
  import {InspectorControls, RichText} from '@wordpress/block-editor'
2
2
  import {FormTokenField, Notice, PanelBody, SelectControl, TextControl, ToggleControl} from '@wordpress/components'
3
- import {useDispatch} from '@wordpress/data'
3
+ import {useDispatch, useSelect} from '@wordpress/data'
4
4
  import {__} from '@wordpress/i18n'
5
5
  import {cleanForSlug} from '@wordpress/url'
6
6
  import clsx from 'clsx'
7
- import {useEffect} from 'react'
7
+ import {useEffect, useMemo} from 'react'
8
8
  import {useGroupBlock} from '~/hooks/useGroupBlock'
9
9
  import {EXTERNAL_METHODS, INTERNAL_SUBMIT_BEHAVIORS, PROCESSING_MODES} from './constants'
10
10
  import type {ExternalMethod, FormGroupAttributes, FormGroupOptions, InternalSubmitBehavior, ProcessingMode} from './types'
@@ -18,6 +18,41 @@ function generateFormId(formName: string): string {
18
18
  return `form-${slug}-${hash}`
19
19
  }
20
20
 
21
+ function slugifyFieldName(raw: string): string {
22
+ return (raw ?? '')
23
+ .normalize('NFD')
24
+ .replace(/\p{Diacritic}/gu, '')
25
+ .replace(/[\s_]+/g, '-')
26
+ .replace(/[^a-zA-Z0-9_-]/g, '')
27
+ .replace(/[-_]{2,}/g, '-')
28
+ .replace(/^[-_]+/g, '')
29
+ .toLowerCase()
30
+ }
31
+
32
+ function gtmPlaceholderValue(type?: string, textType?: string): string {
33
+ if (type === 'select') {
34
+ return '<vybraná možnost>'
35
+ }
36
+
37
+ if (type === 'textarea') {
38
+ return '<vyplněný text>'
39
+ }
40
+
41
+ if (textType === 'email') {
42
+ return '<vyplněný email>'
43
+ }
44
+
45
+ if (textType === 'tel') {
46
+ return '<vyplněné telefonní číslo>'
47
+ }
48
+
49
+ if (textType === 'number') {
50
+ return '<vyplněné číslo>'
51
+ }
52
+
53
+ return '<vyplněná hodnota>'
54
+ }
55
+
21
56
  export function createFormGroupEdit(options: FormGroupOptions) {
22
57
  return function Edit({
23
58
  attributes,
@@ -40,17 +75,59 @@ export function createFormGroupEdit(options: FormGroupOptions) {
40
75
  const isRecipientsMissing = isInternal && recipients.length === 0
41
76
  const isExternalUrlMissing = isExternal && (attributes.externalUrl ?? '').trim() === ''
42
77
 
78
+ type ChildFieldAttributes = {
79
+ type?: string
80
+ selectMode?: string
81
+ textType?: string
82
+ isReplyTo?: boolean
83
+ gtmEnabled?: boolean
84
+ name?: string
85
+ label?: string
86
+ }
87
+
88
+ const {replyToCount, gtmFields} = useSelect(
89
+ (select) => {
90
+ const editor = select('core/block-editor') as unknown as {
91
+ getBlocks: (rootClientId: string) => Array<{attributes: ChildFieldAttributes}>
92
+ }
93
+ const blocks = editor.getBlocks(clientId) || []
94
+ const replyToCount = blocks.filter(
95
+ (block) => block.attributes.type === 'text' && block.attributes.textType === 'email' && block.attributes.isReplyTo === true,
96
+ ).length
97
+ const gtmFields = blocks.filter((block) => block.attributes.gtmEnabled).map((block) => block.attributes)
98
+
99
+ return {replyToCount, gtmFields}
100
+ },
101
+ [clientId],
102
+ )
103
+
104
+ const hasMultipleReplyTo = replyToCount > 1
105
+
106
+ const gtmPreview = useMemo(() => {
107
+ const preview: Record<string, string> = {
108
+ event: (attributes.gtmEventName ?? '').trim() || '<název eventu>',
109
+ url: '<URL stránky, odkud bylo odesláno>',
110
+ }
111
+
112
+ gtmFields.forEach((field) => {
113
+ const name = (field.name && field.name.trim() !== '' ? field.name : slugifyFieldName(field.label ?? '')) || '<pole-bez-nazvu>'
114
+ preview[name] = gtmPlaceholderValue(field.type, field.textType)
115
+ })
116
+
117
+ return preview
118
+ }, [attributes.gtmEventName, gtmFields])
119
+
43
120
  useEffect(() => {
44
121
  const lockName = `brilo-form-group-${clientId}`
45
122
 
46
- if (isRecipientsMissing || isExternalUrlMissing) {
123
+ if (isRecipientsMissing || isExternalUrlMissing || hasMultipleReplyTo) {
47
124
  lockPostSaving(lockName)
48
125
  } else {
49
126
  unlockPostSaving(lockName)
50
127
  }
51
128
 
52
129
  return () => unlockPostSaving(lockName)
53
- }, [clientId, isRecipientsMissing, isExternalUrlMissing, lockPostSaving, unlockPostSaving])
130
+ }, [clientId, isRecipientsMissing, isExternalUrlMissing, hasMultipleReplyTo, lockPostSaving, unlockPostSaving])
54
131
 
55
132
  // Generated once and persisted into the block's attributes so it stays stable across edits.
56
133
  // biome-ignore lint/correctness/useExhaustiveDependencies: must run once on mount only
@@ -177,12 +254,67 @@ export function createFormGroupEdit(options: FormGroupOptions) {
177
254
  </>
178
255
  )}
179
256
 
257
+ {hasMultipleReplyTo && (
258
+ <Notice status="warning" isDismissible={false}>
259
+ {__('Formulář obsahuje více polí označených jako Reply-To. Podporováno je pouze jedno takové pole.', 'brilo-blocks')}
260
+ </Notice>
261
+ )}
262
+
180
263
  <TextControl
181
264
  label={__('Titulek tlačítka odeslání', 'brilo-blocks')}
182
265
  value={attributes.submit?.label ?? 'Odeslat'}
183
266
  onChange={(label) => setAttributes({submit: {label}})}
184
267
  />
185
268
  </PanelBody>
269
+
270
+ {isInternal && (
271
+ <PanelBody title={__('Google Tag Manager', 'brilo-blocks')} initialOpen={false}>
272
+ <ToggleControl
273
+ label={__('Odesílat data do dataLayer', 'brilo-blocks')}
274
+ help={__(
275
+ 'Po úspěšném odeslání formuláře se pushne event do window.dataLayer. Zbytek (cíle, tagy) se nastavuje v GTM.',
276
+ 'brilo-blocks',
277
+ )}
278
+ checked={attributes.gtmEnabled ?? false}
279
+ onChange={(gtmEnabled) => setAttributes({gtmEnabled})}
280
+ />
281
+
282
+ {(attributes.gtmEnabled ?? false) && (
283
+ <>
284
+ <TextControl
285
+ label={__('Název GTM eventu', 'brilo-blocks')}
286
+ placeholder={__('napr. website_form', 'brilo-blocks')}
287
+ value={attributes.gtmEventName ?? ''}
288
+ onChange={(gtmEventName) => setAttributes({gtmEventName})}
289
+ help={__(
290
+ 'Pushne se { event: <tento název>, url: <stránka, odkud bylo odesláno>, ...pole s GTM }. Jednotlivá pole si zapnete u nich ("Odesílat do GTM").',
291
+ 'brilo-blocks',
292
+ )}
293
+ />
294
+
295
+ {(attributes.gtmEventName ?? '').trim() === '' && (
296
+ <Notice status="warning" isDismissible={false}>
297
+ {__('Bez názvu eventu se dataLayer push neodešle.', 'brilo-blocks')}
298
+ </Notice>
299
+ )}
300
+
301
+ <p>
302
+ <strong>{__('Náhled objektu při úspěšném odeslání:', 'brilo-blocks')}</strong>
303
+ </p>
304
+ <pre className="g-form__gtm-preview">{JSON.stringify(gtmPreview, null, 2)}</pre>
305
+
306
+ {gtmFields.length === 0 && (
307
+ <Notice status="info" isDismissible={false}>
308
+ {__(
309
+ 'Žádné pole formuláře nemá zapnuté "Odesílat do GTM" - do dataLayer půjde jen event a url. Zapněte to u polí, jejichž hodnotu chcete v dataLayer mít.',
310
+ 'brilo-blocks',
311
+ )}
312
+ </Notice>
313
+ )}
314
+ </>
315
+ )}
316
+ </PanelBody>
317
+ )}
186
318
  </InspectorControls>
187
319
 
188
320
  <div {...blockProps}>
@@ -1,41 +1,54 @@
1
1
  .g-form {
2
2
  width: 100%;
3
+ }
3
4
 
4
- &__fields {
5
- display: grid;
6
- grid-template-columns: repeat(12, minmax(0, 1fr));
7
- gap: 16px;
8
- padding: 16px;
9
- padding-bottom: 56px;
10
- outline: 1px dashed #ddd;
5
+ .g-form__fields {
6
+ display: grid;
7
+ grid-template-columns: repeat(12, minmax(0, 1fr));
8
+ gap: 16px;
9
+ padding: 16px;
10
+ padding-bottom: 56px;
11
+ outline: 1px dashed #ddd;
12
+ }
11
13
 
12
- > * {
13
- max-width: 100%;
14
- }
15
- }
14
+ .g-form__fields > * {
15
+ max-width: 100%;
16
+ }
16
17
 
17
- &__gdpr {
18
- margin-top: 16px;
19
- padding: 16px;
20
- border: 1px solid #ddd;
21
- border-radius: 4px;
22
- background: #fff;
23
- }
18
+ .g-form__gdpr {
19
+ margin-top: 16px;
20
+ padding: 16px;
21
+ border: 1px solid #ddd;
22
+ border-radius: 4px;
23
+ background: #fff;
24
+ }
24
25
 
25
- &__gdpr-header {
26
- display: flex;
27
- flex-wrap: wrap;
28
- justify-content: space-between;
29
- align-items: center;
30
- gap: 12px;
31
- margin-bottom: 12px;
32
- }
26
+ .g-form__gdpr-header {
27
+ display: flex;
28
+ flex-wrap: wrap;
29
+ justify-content: space-between;
30
+ align-items: center;
31
+ gap: 12px;
32
+ margin-bottom: 12px;
33
+ }
34
+
35
+ .g-form__gdpr-content {
36
+ min-height: 56px;
37
+ padding: 10px 12px;
38
+ border: 1px solid #ddd;
39
+ border-radius: 4px;
40
+ background: #fff;
41
+ }
33
42
 
34
- &__gdpr-content {
35
- min-height: 56px;
36
- padding: 10px 12px;
37
- border: 1px solid #ddd;
38
- border-radius: 4px;
39
- background: #fff;
40
- }
43
+ // Rendered inside InspectorControls, not inside the block content area itself.
44
+ .g-form__gtm-preview {
45
+ max-width: 100%;
46
+ padding: 8px;
47
+ overflow-x: auto;
48
+ border: 1px solid #ddd;
49
+ border-radius: 4px;
50
+ background: #f0f0f0;
51
+ font-size: 11px;
52
+ white-space: pre-wrap;
53
+ word-break: break-word;
41
54
  }
@@ -29,6 +29,8 @@ export function createFormGroupBlock(options: FormGroupOptions): BlockConfigurat
29
29
  submit: {type: 'object', default: {label: 'Odeslat'}},
30
30
  gdpr: {type: 'object', default: {content: '', checkbox: true}},
31
31
  successMessage: {type: 'string', default: 'Formulář byl úspěšně odeslán.'},
32
+ gtmEnabled: {type: 'boolean', default: false},
33
+ gtmEventName: {type: 'string', default: ''},
32
34
  },
33
35
  edit: createFormGroupEdit(options),
34
36
  save: () => <InnerBlocks.Content />,
@@ -18,6 +18,8 @@ export interface FormGroupAttributes extends Record<string, unknown> {
18
18
  submit: {label: string}
19
19
  gdpr: {content: string; checkbox: boolean}
20
20
  successMessage: string
21
+ gtmEnabled: boolean
22
+ gtmEventName: string
21
23
  }
22
24
 
23
25
  export interface FormGroupOptions extends BriloBlockType {}