@brilo/base-blocks 0.1.21 → 0.1.23
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/build/.tsbuildinfo +1 -1
- package/build/blocks/form/form-field/SelectOptionsRepeater.d.ts +10 -0
- package/build/blocks/form/form-field/SelectOptionsRepeater.d.ts.map +1 -0
- package/build/blocks/form/form-field/SelectOptionsRepeater.js +20 -0
- package/build/blocks/form/form-field/constants.d.ts +8 -0
- package/build/blocks/form/form-field/constants.d.ts.map +1 -1
- package/build/blocks/form/form-field/constants.js +5 -0
- package/build/blocks/form/form-field/edit.d.ts.map +1 -1
- package/build/blocks/form/form-field/edit.js +20 -11
- package/build/blocks/form/form-field/factory.d.ts.map +1 -1
- package/build/blocks/form/form-field/factory.js +1 -0
- package/build/blocks/form/form-field/normalizeOptions.d.ts +18 -0
- package/build/blocks/form/form-field/normalizeOptions.d.ts.map +1 -0
- package/build/blocks/form/form-field/normalizeOptions.js +39 -0
- package/build/blocks/form/form-field/types.d.ts +9 -2
- package/build/blocks/form/form-field/types.d.ts.map +1 -1
- package/build/blocks/layout/layout-aside/constants.d.ts +2 -0
- package/build/blocks/layout/layout-aside/constants.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/constants.js +1 -0
- package/build/blocks/layout/layout-aside/edit.d.ts +4 -0
- package/build/blocks/layout/layout-aside/edit.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/edit.js +13 -0
- package/build/blocks/layout/layout-aside/factory.d.ts +4 -0
- package/build/blocks/layout/layout-aside/factory.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/factory.js +20 -0
- package/build/blocks/layout/layout-aside/icon.d.ts +3 -0
- package/build/blocks/layout/layout-aside/icon.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/icon.js +2 -0
- package/build/blocks/layout/layout-aside/index.d.ts +5 -0
- package/build/blocks/layout/layout-aside/index.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/index.js +5 -0
- package/build/blocks/layout/layout-aside/types.d.ts +6 -0
- package/build/blocks/layout/layout-aside/types.d.ts.map +1 -0
- package/build/blocks/layout/layout-aside/types.js +1 -0
- package/build/blocks/layout/layout-content/constants.d.ts +2 -0
- package/build/blocks/layout/layout-content/constants.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/constants.js +1 -0
- package/build/blocks/layout/layout-content/edit.d.ts +4 -0
- package/build/blocks/layout/layout-content/edit.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/edit.js +13 -0
- package/build/blocks/layout/layout-content/factory.d.ts +4 -0
- package/build/blocks/layout/layout-content/factory.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/factory.js +20 -0
- package/build/blocks/layout/layout-content/icon.d.ts +3 -0
- package/build/blocks/layout/layout-content/icon.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/icon.js +2 -0
- package/build/blocks/layout/layout-content/index.d.ts +5 -0
- package/build/blocks/layout/layout-content/index.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/index.js +5 -0
- package/build/blocks/layout/layout-content/types.d.ts +6 -0
- package/build/blocks/layout/layout-content/types.d.ts.map +1 -0
- package/build/blocks/layout/layout-content/types.js +1 -0
- package/build/blocks/layout/layout-content-w-aside/constants.d.ts +11 -0
- package/build/blocks/layout/layout-content-w-aside/constants.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/constants.js +6 -0
- package/build/blocks/layout/layout-content-w-aside/edit.d.ts +7 -0
- package/build/blocks/layout/layout-content-w-aside/edit.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/edit.js +22 -0
- package/build/blocks/layout/layout-content-w-aside/factory.d.ts +6 -0
- package/build/blocks/layout/layout-content-w-aside/factory.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/factory.js +26 -0
- package/build/blocks/layout/layout-content-w-aside/icon.d.ts +3 -0
- package/build/blocks/layout/layout-content-w-aside/icon.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/icon.js +2 -0
- package/build/blocks/layout/layout-content-w-aside/index.d.ts +5 -0
- package/build/blocks/layout/layout-content-w-aside/index.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/index.js +9 -0
- package/build/blocks/layout/layout-content-w-aside/types.d.ts +10 -0
- package/build/blocks/layout/layout-content-w-aside/types.d.ts.map +1 -0
- package/build/blocks/layout/layout-content-w-aside/types.js +1 -0
- package/build/blocks/post/posts-grid/constants.d.ts +4 -0
- package/build/blocks/post/posts-grid/constants.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/constants.js +3 -0
- package/build/blocks/post/posts-grid/edit.d.ts +6 -0
- package/build/blocks/post/posts-grid/edit.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/edit.js +21 -0
- package/build/blocks/post/posts-grid/factory.d.ts +5 -0
- package/build/blocks/post/posts-grid/factory.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/factory.js +59 -0
- package/build/blocks/post/posts-grid/icon.d.ts +2 -0
- package/build/blocks/post/posts-grid/icon.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/icon.js +2 -0
- package/build/blocks/post/posts-grid/index.d.ts +5 -0
- package/build/blocks/post/posts-grid/index.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/index.js +5 -0
- package/build/blocks/post/posts-grid/types.d.ts +22 -0
- package/build/blocks/post/posts-grid/types.d.ts.map +1 -0
- package/build/blocks/post/posts-grid/types.js +1 -0
- package/build/blocks/sections/base-section/attributes.d.ts +4 -0
- package/build/blocks/sections/base-section/attributes.d.ts.map +1 -1
- package/build/blocks/sections/base-section/attributes.js +4 -0
- package/build/blocks/sections/base-section/constants.d.ts +7 -0
- package/build/blocks/sections/base-section/constants.d.ts.map +1 -1
- package/build/blocks/sections/base-section/constants.js +7 -0
- package/build/blocks/sections/base-section/controls.d.ts.map +1 -1
- package/build/blocks/sections/base-section/controls.js +23 -5
- package/build/blocks/sections/base-section/types.d.ts +18 -1
- package/build/blocks/sections/base-section/types.d.ts.map +1 -1
- package/build/blocks/signpost/signpost-group/constants.d.ts +1 -1
- package/build/blocks/signpost/signpost-group/constants.d.ts.map +1 -1
- package/build/blocks/signpost/signpost-group/constants.js +1 -1
- package/build/index.d.ts +8 -0
- package/build/index.d.ts.map +1 -1
- package/build/index.js +4 -0
- package/package.json +5 -2
- package/src/blocks/form/form-field/SelectOptionsRepeater.tsx +111 -0
- package/src/blocks/form/form-field/constants.ts +7 -0
- package/src/blocks/form/form-field/edit.tsx +42 -16
- package/src/blocks/form/form-field/editor.scss +28 -0
- package/src/blocks/form/form-field/factory.tsx +1 -0
- package/src/blocks/form/form-field/normalizeOptions.ts +58 -0
- package/src/blocks/form/form-field/types.ts +6 -2
- package/src/blocks/layout/layout-aside/constants.ts +1 -0
- package/src/blocks/layout/layout-aside/edit.tsx +20 -0
- package/src/blocks/layout/layout-aside/editor.scss +9 -0
- package/src/blocks/layout/layout-aside/factory.tsx +24 -0
- package/src/blocks/layout/layout-aside/icon.tsx +12 -0
- package/src/blocks/layout/layout-aside/index.ts +9 -0
- package/src/blocks/layout/layout-aside/types.ts +5 -0
- package/src/blocks/layout/layout-content/constants.ts +1 -0
- package/src/blocks/layout/layout-content/edit.tsx +20 -0
- package/src/blocks/layout/layout-content/editor.scss +9 -0
- package/src/blocks/layout/layout-content/factory.tsx +24 -0
- package/src/blocks/layout/layout-content/icon.tsx +12 -0
- package/src/blocks/layout/layout-content/index.ts +9 -0
- package/src/blocks/layout/layout-content/types.ts +5 -0
- package/src/blocks/layout/layout-content-w-aside/constants.ts +7 -0
- package/src/blocks/layout/layout-content-w-aside/edit.tsx +52 -0
- package/src/blocks/layout/layout-content-w-aside/editor.scss +35 -0
- package/src/blocks/layout/layout-content-w-aside/factory.tsx +34 -0
- package/src/blocks/layout/layout-content-w-aside/icon.tsx +12 -0
- package/src/blocks/layout/layout-content-w-aside/index.ts +13 -0
- package/src/blocks/layout/layout-content-w-aside/types.ts +12 -0
- package/src/blocks/post/posts-grid/constants.ts +3 -0
- package/src/blocks/post/posts-grid/edit.tsx +105 -0
- package/src/blocks/post/posts-grid/factory.tsx +63 -0
- package/src/blocks/post/posts-grid/icon.tsx +8 -0
- package/src/blocks/post/posts-grid/index.ts +9 -0
- package/src/blocks/post/posts-grid/types.ts +25 -0
- package/src/blocks/sections/base-section/attributes.ts +4 -0
- package/src/blocks/sections/base-section/constants.ts +10 -0
- package/src/blocks/sections/base-section/controls.tsx +83 -4
- package/src/blocks/sections/base-section/types.ts +20 -1
- package/src/blocks/signpost/signpost-group/constants.ts +1 -1
- package/src/editor.scss +3 -0
- package/src/index.ts +8 -0
|
@@ -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,
|
|
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 {
|
|
6
|
-
import {
|
|
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
|
-
|
|
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
|
|
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
|
-
<
|
|
89
|
-
label={__('
|
|
90
|
-
value={
|
|
91
|
-
|
|
92
|
-
|
|
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
|
+
}
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import {FIELD_TEXT_TYPES, FIELD_TEXT_TYPE_VALUES, FIELD_TYPE_VALUES} from './constants'
|
|
1
|
+
import {FIELD_SELECT_MODE_VALUES, FIELD_TEXT_TYPES, FIELD_TEXT_TYPE_VALUES, FIELD_TYPE_VALUES} from './constants'
|
|
2
2
|
import type {BriloBlockType} from '~/types'
|
|
3
3
|
|
|
4
4
|
export type FormFieldType = (typeof FIELD_TYPE_VALUES)[number]
|
|
5
5
|
export type FormFieldTextType = (typeof FIELD_TEXT_TYPE_VALUES)[number]
|
|
6
|
+
export type FormFieldSelectMode = (typeof FIELD_SELECT_MODE_VALUES)[number]
|
|
7
|
+
|
|
8
|
+
export type FormFieldOption = string | {label?: string; value?: string; email?: string}
|
|
6
9
|
|
|
7
10
|
export interface FormFieldAttributes extends Record<string, unknown> {
|
|
8
11
|
type: FormFieldType
|
|
@@ -12,7 +15,8 @@ export interface FormFieldAttributes extends Record<string, unknown> {
|
|
|
12
15
|
name: string
|
|
13
16
|
placeholder: string
|
|
14
17
|
required: boolean
|
|
15
|
-
options:
|
|
18
|
+
options: FormFieldOption[]
|
|
19
|
+
selectMode: FormFieldSelectMode
|
|
16
20
|
defaultValue: string
|
|
17
21
|
value: string
|
|
18
22
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const ASIDE_DEFAULTS = {}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {useGroupBlock} from '~/hooks/useGroupBlock'
|
|
3
|
+
import type {AsideAttributes, AsideOptions} from './types'
|
|
4
|
+
|
|
5
|
+
export function createAsideEdit(options: AsideOptions) {
|
|
6
|
+
return function Edit() {
|
|
7
|
+
const {blockProps, innerBlocksProps} = useGroupBlock({
|
|
8
|
+
blockClassName: 'l-content-w-aside__aside',
|
|
9
|
+
containerClassName: 'l-content-w-aside__aside-container',
|
|
10
|
+
layout: {type: 'default'},
|
|
11
|
+
orientation: 'vertical',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<aside {...blockProps}>
|
|
16
|
+
<div {...innerBlocksProps} />
|
|
17
|
+
</aside>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {InnerBlocks} from '@wordpress/block-editor'
|
|
2
|
+
import type {BlockConfiguration} from '@wordpress/blocks'
|
|
3
|
+
import {__} from '@wordpress/i18n'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import {createAsideEdit} from './edit'
|
|
6
|
+
import {icon as defaultIcon} from './icon'
|
|
7
|
+
import type {AsideAttributes, AsideOptions} from './types'
|
|
8
|
+
|
|
9
|
+
export function createAsideBlock(
|
|
10
|
+
options: AsideOptions,
|
|
11
|
+
): BlockConfiguration<AsideAttributes> {
|
|
12
|
+
return {
|
|
13
|
+
name: options.name,
|
|
14
|
+
title: options.title ?? __('Postranní panel', 'brilo-blocks'),
|
|
15
|
+
description: options.description,
|
|
16
|
+
category: options.category ?? 'layout',
|
|
17
|
+
parent: options.parent,
|
|
18
|
+
icon: options.icon ?? {src: defaultIcon},
|
|
19
|
+
supports: {html: false, customClassName: false},
|
|
20
|
+
attributes: {},
|
|
21
|
+
edit: createAsideEdit(options),
|
|
22
|
+
save: () => <InnerBlocks.Content />,
|
|
23
|
+
} as BlockConfiguration<AsideAttributes>
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
export const icon = (
|
|
4
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
5
|
+
<path
|
|
6
|
+
fillRule="evenodd"
|
|
7
|
+
clipRule="evenodd"
|
|
8
|
+
d="M8 4H20V20H8V4ZM10 6H18V18H10V6Z"
|
|
9
|
+
fill="currentColor"
|
|
10
|
+
/>
|
|
11
|
+
</svg>
|
|
12
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type {AsideAttributes, AsideOptions} from './types'
|
|
2
|
+
export {createAsideBlock} from './factory'
|
|
3
|
+
|
|
4
|
+
import type {AsideOptions} from './types'
|
|
5
|
+
|
|
6
|
+
export const asideDefaults: AsideOptions = {
|
|
7
|
+
name: 'brilo/layout-aside',
|
|
8
|
+
parent: ['brilo/layout-content-w-aside'],
|
|
9
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const CONTENT_DEFAULTS = {}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
import {useGroupBlock} from '~/hooks/useGroupBlock'
|
|
3
|
+
import type {ContentAttributes, ContentOptions} from './types'
|
|
4
|
+
|
|
5
|
+
export function createContentEdit(options: ContentOptions) {
|
|
6
|
+
return function Edit() {
|
|
7
|
+
const {blockProps, innerBlocksProps} = useGroupBlock({
|
|
8
|
+
blockClassName: 'l-content-w-aside__content',
|
|
9
|
+
containerClassName: 'l-content-w-aside__content-container',
|
|
10
|
+
layout: {type: 'default'},
|
|
11
|
+
orientation: 'vertical',
|
|
12
|
+
})
|
|
13
|
+
|
|
14
|
+
return (
|
|
15
|
+
<div {...blockProps}>
|
|
16
|
+
<div {...innerBlocksProps} />
|
|
17
|
+
</div>
|
|
18
|
+
)
|
|
19
|
+
}
|
|
20
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import {InnerBlocks} from '@wordpress/block-editor'
|
|
2
|
+
import type {BlockConfiguration} from '@wordpress/blocks'
|
|
3
|
+
import {__} from '@wordpress/i18n'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import {createContentEdit} from './edit'
|
|
6
|
+
import {icon as defaultIcon} from './icon'
|
|
7
|
+
import type {ContentAttributes, ContentOptions} from './types'
|
|
8
|
+
|
|
9
|
+
export function createContentBlock(
|
|
10
|
+
options: ContentOptions,
|
|
11
|
+
): BlockConfiguration<ContentAttributes> {
|
|
12
|
+
return {
|
|
13
|
+
name: options.name,
|
|
14
|
+
title: options.title ?? __('Obsah', 'brilo-blocks'),
|
|
15
|
+
description: options.description,
|
|
16
|
+
category: options.category ?? 'layout',
|
|
17
|
+
parent: options.parent,
|
|
18
|
+
icon: options.icon ?? {src: defaultIcon},
|
|
19
|
+
supports: {html: false, customClassName: false},
|
|
20
|
+
attributes: {},
|
|
21
|
+
edit: createContentEdit(options),
|
|
22
|
+
save: () => <InnerBlocks.Content />,
|
|
23
|
+
} as BlockConfiguration<ContentAttributes>
|
|
24
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
export const icon = (
|
|
4
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
5
|
+
<path
|
|
6
|
+
fillRule="evenodd"
|
|
7
|
+
clipRule="evenodd"
|
|
8
|
+
d="M4 4H16V20H4V4ZM6 6H14V18H6V6Z"
|
|
9
|
+
fill="currentColor"
|
|
10
|
+
/>
|
|
11
|
+
</svg>
|
|
12
|
+
)
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type {ContentAttributes, ContentOptions} from './types'
|
|
2
|
+
export {createContentBlock} from './factory'
|
|
3
|
+
|
|
4
|
+
import type {ContentOptions} from './types'
|
|
5
|
+
|
|
6
|
+
export const contentDefaults: ContentOptions = {
|
|
7
|
+
name: 'brilo/layout-content',
|
|
8
|
+
parent: ['brilo/layout-content-w-aside'],
|
|
9
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import {InspectorControls} from '@wordpress/block-editor'
|
|
2
|
+
import {PanelBody, __experimentalToggleGroupControl as ToggleGroupControl, __experimentalToggleGroupControlOption as ToggleGroupControlOption} from '@wordpress/components'
|
|
3
|
+
import {__} from '@wordpress/i18n'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import {useGroupBlock} from '~/hooks/useGroupBlock'
|
|
6
|
+
import {ASIDE_SIZES} from './constants'
|
|
7
|
+
import type {AsideSize, ContentWithAsideAttributes, ContentWithAsideOptions} from './types'
|
|
8
|
+
|
|
9
|
+
export function createContentWithAsideEdit(options: ContentWithAsideOptions) {
|
|
10
|
+
const ASIDE_SIZES_OPTIONS = options.asideSizes ?? ASIDE_SIZES
|
|
11
|
+
|
|
12
|
+
return function Edit({
|
|
13
|
+
attributes,
|
|
14
|
+
setAttributes,
|
|
15
|
+
}: {
|
|
16
|
+
attributes: ContentWithAsideAttributes
|
|
17
|
+
setAttributes: (a: Partial<ContentWithAsideAttributes>) => void
|
|
18
|
+
}) {
|
|
19
|
+
const {asideSize} = attributes
|
|
20
|
+
|
|
21
|
+
const {blockProps, innerBlocksProps} = useGroupBlock({
|
|
22
|
+
blockClassName: 'l-content-w-aside',
|
|
23
|
+
containerClassName: `l-content-w-aside__container --aside-${asideSize}`,
|
|
24
|
+
template: options.template,
|
|
25
|
+
allowedBlocks: options.allowedBlocks,
|
|
26
|
+
orientation: 'horizontal',
|
|
27
|
+
layout: {type: 'default'},
|
|
28
|
+
})
|
|
29
|
+
|
|
30
|
+
return (
|
|
31
|
+
<>
|
|
32
|
+
<InspectorControls>
|
|
33
|
+
<PanelBody title={__('Nastavení', 'brilo-blocks')}>
|
|
34
|
+
<ToggleGroupControl
|
|
35
|
+
isBlock
|
|
36
|
+
label={__('Velikost postranního panelu', 'brilo-blocks')}
|
|
37
|
+
value={asideSize}
|
|
38
|
+
onChange={(v) => setAttributes({asideSize: v as AsideSize})}
|
|
39
|
+
>
|
|
40
|
+
{ASIDE_SIZES_OPTIONS.map((s) => (
|
|
41
|
+
<ToggleGroupControlOption key={s.value} value={s.value} label={s.label} />
|
|
42
|
+
))}
|
|
43
|
+
</ToggleGroupControl>
|
|
44
|
+
</PanelBody>
|
|
45
|
+
</InspectorControls>
|
|
46
|
+
<div {...blockProps}>
|
|
47
|
+
<div {...innerBlocksProps} />
|
|
48
|
+
</div>
|
|
49
|
+
</>
|
|
50
|
+
)
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
@layer base {
|
|
2
|
+
.l-content-w-aside {
|
|
3
|
+
padding: 16px;
|
|
4
|
+
border: 2px dashed #0073aa;
|
|
5
|
+
flex-shrink: 0;
|
|
6
|
+
|
|
7
|
+
&__container {
|
|
8
|
+
display: flex;
|
|
9
|
+
gap: 16px;
|
|
10
|
+
|
|
11
|
+
&.--aside-small {
|
|
12
|
+
--aside-width: 15%;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
&.--aside-medium {
|
|
16
|
+
--aside-width: 25%;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
&.--aside-large {
|
|
20
|
+
--aside-width: 35%;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
&::before {
|
|
25
|
+
content: "Obsah s postranním panelem";
|
|
26
|
+
display: block;
|
|
27
|
+
font-size: 10px;
|
|
28
|
+
font-weight: 600;
|
|
29
|
+
text-transform: uppercase;
|
|
30
|
+
color: #0073aa;
|
|
31
|
+
letter-spacing: 0.5px;
|
|
32
|
+
margin-bottom: 8px;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import {InnerBlocks} from '@wordpress/block-editor'
|
|
2
|
+
import type {BlockConfiguration} from '@wordpress/blocks'
|
|
3
|
+
import {__} from '@wordpress/i18n'
|
|
4
|
+
import React from 'react'
|
|
5
|
+
import type {OptionArray} from '~/types'
|
|
6
|
+
import {ASIDE_SIZES} from './constants'
|
|
7
|
+
import {createContentWithAsideEdit} from './edit'
|
|
8
|
+
import {icon as defaultIcon} from './icon'
|
|
9
|
+
import type {ContentWithAsideAttributes, ContentWithAsideOptions} from './types'
|
|
10
|
+
|
|
11
|
+
export function createContentWithAsideBlock<
|
|
12
|
+
TAsideSizes extends OptionArray = typeof ASIDE_SIZES,
|
|
13
|
+
>(
|
|
14
|
+
options: ContentWithAsideOptions<TAsideSizes>,
|
|
15
|
+
): BlockConfiguration<ContentWithAsideAttributes<TAsideSizes[number]['value']>> {
|
|
16
|
+
const asideSizes = options.asideSizes ?? ASIDE_SIZES
|
|
17
|
+
|
|
18
|
+
return {
|
|
19
|
+
name: options.name,
|
|
20
|
+
title: options.title ?? __('Obsah s postranním panelem', 'brilo-blocks'),
|
|
21
|
+
description: options.description,
|
|
22
|
+
category: options.category ?? 'layout',
|
|
23
|
+
icon: options.icon ?? {src: defaultIcon},
|
|
24
|
+
supports: {html: false, customClassName: false},
|
|
25
|
+
attributes: {
|
|
26
|
+
asideSize: {
|
|
27
|
+
type: 'string',
|
|
28
|
+
default: asideSizes[1].value, // medium
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
edit: createContentWithAsideEdit(options as unknown as ContentWithAsideOptions),
|
|
32
|
+
save: () => <InnerBlocks.Content />,
|
|
33
|
+
} as unknown as BlockConfiguration<ContentWithAsideAttributes<TAsideSizes[number]['value']>>
|
|
34
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import React from 'react'
|
|
2
|
+
|
|
3
|
+
export const icon = (
|
|
4
|
+
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
5
|
+
<path
|
|
6
|
+
fillRule="evenodd"
|
|
7
|
+
clipRule="evenodd"
|
|
8
|
+
d="M4 4H20V20H4V4ZM6 6H13V18H6V6ZM15 6H18V18H15V6Z"
|
|
9
|
+
fill="currentColor"
|
|
10
|
+
/>
|
|
11
|
+
</svg>
|
|
12
|
+
)
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export type {ContentWithAsideAttributes, ContentWithAsideOptions} from './types'
|
|
2
|
+
export {createContentWithAsideBlock} from './factory'
|
|
3
|
+
|
|
4
|
+
import type {ContentWithAsideOptions} from './types'
|
|
5
|
+
|
|
6
|
+
export const contentWithAsideDefaults: ContentWithAsideOptions = {
|
|
7
|
+
name: 'brilo/layout-content-w-aside',
|
|
8
|
+
allowedBlocks: ['brilo/layout-content', 'brilo/layout-aside'],
|
|
9
|
+
template: [
|
|
10
|
+
['brilo/layout-content', {}],
|
|
11
|
+
['brilo/layout-aside', {}],
|
|
12
|
+
],
|
|
13
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type {BriloBlockType, OptionArray} from '~/types'
|
|
2
|
+
import type {ASIDE_SIZES} from './constants'
|
|
3
|
+
|
|
4
|
+
export type AsideSize = (typeof ASIDE_SIZES)[number]['value']
|
|
5
|
+
|
|
6
|
+
export interface ContentWithAsideAttributes<TAsideSize extends string = AsideSize> extends Record<string, unknown> {
|
|
7
|
+
asideSize: TAsideSize
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export interface ContentWithAsideOptions<TAsideSizes extends OptionArray = typeof ASIDE_SIZES> extends BriloBlockType {
|
|
11
|
+
asideSizes?: TAsideSizes
|
|
12
|
+
}
|