Skip to content

Commit b5820e9

Browse files
committed
feat: new email template editing
1 parent 75c46d7 commit b5820e9

File tree

19 files changed

+315
-17
lines changed

19 files changed

+315
-17
lines changed

blueprints/fields/success.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@ fields:
33
label: dreamform.form.successMessage.label
44
placeholder: dreamform.form.successMessage.default
55
type: writer
6-
extends: dreamform/fields/writer
6+
extends: dreamform/fields/writer-with-fields

blueprints/fields/writer-with-fields.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,15 @@
33
use tobimori\DreamForm\DreamForm;
44

55
return function () {
6-
// TODO: this should contain the custom nodes to select field from dropdown
7-
// but this needs Kirby 5 (probably), expect this with DreamForm 2.0
8-
96
return [
107
'type' => 'writer',
118
'toolbar' => [
129
'inline' => false
1310
],
1411
'marks' => DreamForm::option('marks'),
12+
'nodes' => [
13+
DreamForm::option('nodes'),
14+
'dreamformFormField' // custom node for field placeholders
15+
]
1516
];
1617
};

config/areas.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,77 @@
138138
];
139139
}
140140
],
141+
'dreamform/form-fields' => [
142+
'load' => function () {
143+
$fieldKey = App::instance()->request()->get('field');
144+
$formId = App::instance()->request()->get('form');
145+
146+
// get form from referrer if not provided
147+
if (!$formId) {
148+
$path = App::instance()->request()->header('x-fiber-referrer');
149+
if ($path && preg_match('/pages\/([^\/]+\+[^\/]+)/', $path, $matches)) {
150+
$formId = Str::replace($matches[1], '+', '/');
151+
}
152+
}
153+
154+
$options = [];
155+
$currentValue = null;
156+
157+
if ($formId && $formPage = App::instance()->site()->find($formId)) {
158+
// get available fields from form
159+
foreach ($formPage->fields() as $field) {
160+
if (!$field::hasValue() || $field->block()->type() === 'file-upload-field') {
161+
continue;
162+
}
163+
164+
$key = $field->key();
165+
$label = $field->label() ?: $key;
166+
$type = Str::replace($field->block()->type(), '-field', '');
167+
168+
// store both key and label in value for JS to use
169+
$options[] = [
170+
'value' => json_encode(['key' => $key, 'label' => $label]),
171+
'text' => $label,
172+
'info' => $type
173+
];
174+
175+
// set current value if field matches
176+
if ($fieldKey === $key) {
177+
$currentValue = json_encode(['key' => $key, 'label' => $label]);
178+
}
179+
}
180+
}
181+
182+
// default to first option if no selection
183+
if (!$currentValue && !empty($options)) {
184+
$currentValue = $options[0]['value'];
185+
}
186+
187+
return [
188+
'component' => 'k-form-dialog',
189+
'props' => [
190+
'fields' => [
191+
'field' => [
192+
'type' => 'select',
193+
'label' => t('dreamform.writerNodes.selectField'),
194+
'options' => $options,
195+
'required' => true,
196+
'empty' => empty($options) ? t('dreamform.common.noFields') : false
197+
]
198+
],
199+
'value' => [
200+
'field' => $currentValue
201+
],
202+
'submitButton' => [
203+
'text' => $fieldKey ? t('dreamform.common.update') : t('dreamform.common.insert')
204+
]
205+
]
206+
];
207+
},
208+
'submit' => function () {
209+
return true;
210+
}
211+
]
141212
]
142213
]
143214
];

config/options.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929
'page' => 'page://forms', // Slug or URI to the page where the forms are located
3030
'secret' => null, // Encryption secret for htmx attributes
3131
'marks' => ['bold', 'italic', 'underline', 'strike', 'link', 'email'], // Marks to be used in writer fields
32+
'nodes' => [
33+
'heading',
34+
'bulletList',
35+
'orderedList'
36+
], // Nodes to be used in writer fields
3237
'metadata' => [
3338
'collect' => [] // 'ip' | 'userAgent'
3439
],

i18n.lock

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,8 @@ checksums:
119119
common.firstName: cf040a5d6a9fd696be400380cc99f54b
120120
common.lastName: 2c9a7de7738ca007ba9023c385149c26
121121
common.source: 6e87903ef260da661b2bf6d858ba68ca
122+
common.insert: 51f001c133c6754ade95b64291f7c2d9
123+
common.update: 079fc039262fd31b10532929685c2d1b
122124
field: cfd632297d7809a3539e90c9cd4728d9
123125
fields: dc5e476f6beca227b505d21489e8d365
124126
fields.button.label.label: 7c91ef5f747eea9f77a9c4f23e19fb2e
@@ -226,3 +228,5 @@ checksums:
226228
submissions.recent: 8f45c21623deafe714652f6e2631aaab
227229
validation: 1317a0978c579e81f3c4e50e7696189f
228230
workflow: 0240772c838117f1c837f4913fce9384
231+
writerNodes.formField: a4b5ac94cb709ed99aaa503d9c3fe135
232+
writerNodes.selectField: e61a273dafca0df32f7de68f6fc18875

index.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

index.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/components/field-header.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ const props = defineProps({
1212
const emit = defineEmits(["update"])
1313
const update = (value) => emit("update", { ...props.content, ...value })
1414
15-
// use the composable for key syncing
1615
const { handleManualInput } = useSyncedSlug({
1716
initialValue: props.content?.key,
1817
syncField: "label",

src/fields/field-slug-field.vue

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ const props = defineProps({
5050
5151
const emit = defineEmits(["input"])
5252
53-
// use the composable for slug syncing
5453
const { slug, handleManualInput } = useSyncedSlug({
5554
initialValue: props.value,
5655
syncField: props.sync,

src/index.css

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,34 @@
99
display: none;
1010
}
1111
}
12+
13+
.k-writer span[data-dreamform-field] {
14+
background: var(--color-purple-200);
15+
color: var(--color-purple-700);
16+
padding: var(--spacing-1) var(--spacing-2);
17+
border-radius: var(--rounded-sm);
18+
display: inline-flex;
19+
gap: 0.25rem;
20+
white-space: nowrap;
21+
align-items: center;
22+
font-size: 0.875em;
23+
line-height: 1;
24+
cursor: pointer;
25+
margin-inline: 2px;
26+
font-weight: 500;
27+
transition: all 0.2s;
28+
29+
&:hover {
30+
background: var(--color-purple-300);
31+
color: var(--color-purple-800);
32+
}
33+
}
34+
35+
.k-writer-input .k-toolbar-button:nth-child(3) {
36+
padding-inline: var(--spacing-5);
37+
--button-width: auto;
38+
39+
&::after {
40+
content: attr(title);
41+
}
42+
}

0 commit comments

Comments
 (0)