@brilo/base-blocks 0.1.20 → 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 (33) 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/build/blocks/usp/usp-item/buildPreviewStyle.d.ts.map +1 -1
  21. package/build/blocks/usp/usp-item/buildPreviewStyle.js +2 -1
  22. package/package.json +5 -2
  23. package/src/blocks/form/form-field/SelectOptionsRepeater.tsx +111 -0
  24. package/src/blocks/form/form-field/constants.ts +7 -0
  25. package/src/blocks/form/form-field/edit.tsx +42 -16
  26. package/src/blocks/form/form-field/editor.scss +28 -0
  27. package/src/blocks/form/form-field/factory.tsx +1 -0
  28. package/src/blocks/form/form-field/normalizeOptions.ts +58 -0
  29. package/src/blocks/form/form-field/types.ts +6 -2
  30. package/src/blocks/signpost/signpost-group/constants.ts +1 -1
  31. package/src/blocks/usp/usp-group/editor.scss +0 -5
  32. package/src/blocks/usp/usp-item/buildPreviewStyle.ts +3 -1
  33. package/src/blocks/usp/usp-item/editor.scss +12 -5
@@ -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: string[]
18
+ options: FormFieldOption[]
19
+ selectMode: FormFieldSelectMode
16
20
  defaultValue: string
17
21
  value: string
18
22
  }
@@ -1,6 +1,6 @@
1
1
  import {__} from '@wordpress/i18n'
2
2
 
3
- export const COLUMNS = [5, 4, 3, 2] as const
3
+ export const COLUMNS = [4, 3, 2] as const
4
4
  export const RATIOS = ['4:3', '3:2', '16:9', '1:1', '2:1', '3:4'] as const
5
5
  export const HEADING_LEVELS = [2, 3, 4] as const
6
6
 
@@ -8,11 +8,6 @@
8
8
  align-items: flex-start;
9
9
  }
10
10
 
11
- &.--card .i-usp__inner {
12
- background: #fff;
13
- border-color: #d0d5dd;
14
- }
15
-
16
11
  &.--shadow-sm .i-usp__inner {
17
12
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
18
13
  }
@@ -56,7 +56,9 @@ export function buildUspPreviewStyle(shared?: UspSharedStyle, resolveHex: (value
56
56
  if (icon.background && icon.background !== 'none') cssVars['--icon-background-color'] = resolveHex(icon.background)
57
57
  if (icon.color && icon.color !== 'none') cssVars['--icon-color'] = resolveHex(icon.color)
58
58
  if (icon.size) cssVars['--icon-size'] = `${icon.size}px`
59
- if (icon.backgroundSize) cssVars['--icon-background-size'] = `${icon.backgroundSize}px`
59
+ if (icon.background && icon.background !== 'none' && icon.backgroundSize) {
60
+ cssVars['--icon-background-size'] = `${icon.backgroundSize}px`
61
+ }
60
62
  if (icon.borderColor) {
61
63
  cssVars['--icon-outline-color'] = resolveHex(icon.borderColor)
62
64
  cssVars['--icon-outline-width'] = `${icon.borderWidth || 1}px`
@@ -3,6 +3,13 @@
3
3
  margin-inline: 0;
4
4
  text-align: var(--text-align, left);
5
5
  border-radius: 4px;
6
+ --icon-background-size: 0px;
7
+
8
+ // Background size only reserves space when a background or outline is actually selected.
9
+ &.--icon-background,
10
+ &.--icon-bordered {
11
+ --icon-background-size: 88px;
12
+ }
6
13
 
7
14
  &.--shadow {
8
15
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.08);
@@ -59,7 +66,7 @@
59
66
  }
60
67
 
61
68
  .i-usp__icon {
62
- --icon-box-size: max(var(--icon-background-size, 88px), var(--icon-size, 88px));
69
+ --icon-box-size: max(var(--icon-background-size, 0px), var(--icon-size, 88px));
63
70
 
64
71
  width: var(--icon-box-size);
65
72
  height: var(--icon-box-size);
@@ -73,8 +80,8 @@
73
80
  &::after {
74
81
  content: "";
75
82
  grid-area: pile;
76
- width: var(--icon-background-size, 88px);
77
- height: var(--icon-background-size, 88px);
83
+ width: var(--icon-background-size, 0px);
84
+ height: var(--icon-background-size, 0px);
78
85
  border-radius: inherit;
79
86
  clip-path: var(--icon-background-shape, none);
80
87
  }
@@ -86,8 +93,8 @@
86
93
 
87
94
  &::after {
88
95
  z-index: 1;
89
- width: calc(var(--icon-background-size, 88px) - var(--icon-outline-width, 0px) * 2);
90
- height: calc(var(--icon-background-size, 88px) - var(--icon-outline-width, 0px) * 2);
96
+ width: calc(var(--icon-background-size, 0px) - var(--icon-outline-width, 0px) * 2);
97
+ height: calc(var(--icon-background-size, 0px) - var(--icon-outline-width, 0px) * 2);
91
98
  background-color: var(--icon-background-color, transparent);
92
99
  }
93
100