@crombolo/backoffice-host 0.60.0 → 0.62.0
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/package.json +3 -3
- package/plugin/app-preview/umbraco-package.json +1 -1
- package/plugin/branding/localization-en.js +1 -2
- package/plugin/bundles-activity-words.js +72 -0
- package/plugin/bundles-activity.js +171 -0
- package/plugin/bundles-client.js +30 -6
- package/plugin/bundles-installed.js +179 -69
- package/plugin/bundles-level-words.js +79 -0
- package/plugin/bundles-level.js +91 -0
- package/plugin/bundles-marketplace.js +64 -84
- package/plugin/content-strip-items.js +5 -13
- package/plugin/extension-screen-model.js +124 -0
- package/plugin/extension-screen.js +551 -0
- package/plugin/forms-client.js +7 -0
- package/plugin/forms-overview.js +79 -0
- package/plugin/forms-workflows.js +18 -0
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/settings-section.js +1 -31
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/template-picker.js +3 -3
- package/plugin/umbraco-package.json +4 -34
- package/src/bundle-package.ts +105 -13
- package/src/bundle-permissions.ts +152 -6
- package/src/extension-roots.ts +128 -0
- package/src/extensions.ts +24 -1
- package/src/index.ts +1 -0
- package/src/manifests.ts +12 -1
- package/src/registry.ts +1 -0
- package/plugin/bundles-backoffice-code-words.js +0 -34
- package/plugin/bundles-backoffice-code.js +0 -51
|
@@ -0,0 +1,551 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Draws a screen an extension describes (story 323), wherever its manifest
|
|
3
|
+
* places one: a workspace, a dashboard, a side panel or an action's dialog.
|
|
4
|
+
*
|
|
5
|
+
* The extension's server half answers a tree from a small catalogue, and this
|
|
6
|
+
* element renders it with the back office's own components. Every string the
|
|
7
|
+
* extension supplies is set as text and every link checked, so nothing of the
|
|
8
|
+
* extension's runs here. Typing stays in the browser; a button, a row's action
|
|
9
|
+
* or a search is one call, answered with the next screen. docs/extensions.md,
|
|
10
|
+
* "Screens".
|
|
11
|
+
*/
|
|
12
|
+
// For their side effects: the layout and the three pickers are defined in
|
|
13
|
+
// chunks the shell loads lazily.
|
|
14
|
+
import '@umbraco-cms/backoffice/components'
|
|
15
|
+
import '@umbraco-cms/backoffice/document'
|
|
16
|
+
import '@umbraco-cms/backoffice/media'
|
|
17
|
+
import '@umbraco-cms/backoffice/member'
|
|
18
|
+
import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
|
|
19
|
+
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
20
|
+
import { umbConfirmModal } from '@umbraco-cms/backoffice/modal'
|
|
21
|
+
import {
|
|
22
|
+
actionBody,
|
|
23
|
+
fieldProblems,
|
|
24
|
+
hintsFor,
|
|
25
|
+
linkTarget,
|
|
26
|
+
screenUrl,
|
|
27
|
+
sentValues,
|
|
28
|
+
visibleFields,
|
|
29
|
+
} from './extension-screen-model.js'
|
|
30
|
+
|
|
31
|
+
const backOfficeBase = () => document.querySelector('base')?.getAttribute('href') ?? '/umbraco/'
|
|
32
|
+
|
|
33
|
+
const LOOKS = {
|
|
34
|
+
primary: { look: 'primary', color: 'default' },
|
|
35
|
+
secondary: { look: 'secondary', color: 'default' },
|
|
36
|
+
danger: { look: 'primary', color: 'danger' },
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export default class CromboloExtensionScreenElement extends UmbLitElement {
|
|
40
|
+
static properties = {
|
|
41
|
+
manifest: { attribute: false },
|
|
42
|
+
_screen: { state: true },
|
|
43
|
+
_loading: { state: true },
|
|
44
|
+
_busy: { state: true },
|
|
45
|
+
_problem: { state: true },
|
|
46
|
+
_notice: { state: true },
|
|
47
|
+
_values: { state: true },
|
|
48
|
+
_fieldProblems: { state: true },
|
|
49
|
+
_tabs: { state: true },
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
constructor() {
|
|
53
|
+
super()
|
|
54
|
+
this._screen = undefined
|
|
55
|
+
this._loading = true
|
|
56
|
+
this._busy = false
|
|
57
|
+
this._problem = ''
|
|
58
|
+
this._notice = ''
|
|
59
|
+
this._state = {}
|
|
60
|
+
/** Each form's values, by the form as the last answer gave it. */
|
|
61
|
+
this._values = new Map()
|
|
62
|
+
this._typed = new Map()
|
|
63
|
+
this._fieldProblems = new Map()
|
|
64
|
+
this._tabs = new Map()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
connectedCallback() {
|
|
68
|
+
super.connectedCallback()
|
|
69
|
+
this.#call({})
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
get #target() {
|
|
73
|
+
return this.manifest?.meta?.cromboloScreen ?? {}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
async #call(body) {
|
|
77
|
+
const { bundle, screen } = this.#target
|
|
78
|
+
if (!bundle || !screen) {
|
|
79
|
+
this._problem = 'This screen does not say which extension draws it.'
|
|
80
|
+
this._loading = false
|
|
81
|
+
return
|
|
82
|
+
}
|
|
83
|
+
this._busy = true
|
|
84
|
+
try {
|
|
85
|
+
const response = await fetch(screenUrl(backOfficeBase(), bundle, screen), {
|
|
86
|
+
method: 'POST',
|
|
87
|
+
credentials: 'include',
|
|
88
|
+
headers: { accept: 'application/json', 'content-type': 'application/json' },
|
|
89
|
+
body: JSON.stringify({ state: this._state, ...body }),
|
|
90
|
+
})
|
|
91
|
+
const answer = await response.json().catch(() => ({}))
|
|
92
|
+
if (!response.ok) {
|
|
93
|
+
this._problem =
|
|
94
|
+
typeof answer?.message === 'string'
|
|
95
|
+
? answer.message
|
|
96
|
+
: `The extension's screen answered ${response.status}.`
|
|
97
|
+
return
|
|
98
|
+
}
|
|
99
|
+
if (typeof answer.problem === 'string') {
|
|
100
|
+
this._problem = answer.problem
|
|
101
|
+
this._notice = ''
|
|
102
|
+
return
|
|
103
|
+
}
|
|
104
|
+
this.#show(answer)
|
|
105
|
+
} catch (error) {
|
|
106
|
+
this._problem = error instanceof Error ? error.message : String(error)
|
|
107
|
+
} finally {
|
|
108
|
+
this._busy = false
|
|
109
|
+
this._loading = false
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
#show(answer) {
|
|
114
|
+
this._screen = answer.screen
|
|
115
|
+
this._state = answer.state ?? this._state
|
|
116
|
+
this._notice = answer.notice ?? ''
|
|
117
|
+
this._problem = ''
|
|
118
|
+
const values = new Map()
|
|
119
|
+
const walk = (nodes) => {
|
|
120
|
+
for (const node of nodes ?? []) {
|
|
121
|
+
if (node.type === 'form') values.set(node, { ...(node.values ?? {}) })
|
|
122
|
+
if (node.type === 'tabs') for (const tab of node.tabs ?? []) walk(tab.body)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
walk(answer.screen?.body)
|
|
126
|
+
this._values = values
|
|
127
|
+
this._typed = new Map()
|
|
128
|
+
this._fieldProblems = new Map()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
#set(form, field, value) {
|
|
132
|
+
const next = new Map(this._values)
|
|
133
|
+
next.set(form, { ...(next.get(form) ?? {}), [field.name]: value })
|
|
134
|
+
this._values = next
|
|
135
|
+
if (field.kind === 'secret') {
|
|
136
|
+
const typed = new Set(this._typed.get(form) ?? [])
|
|
137
|
+
typed.add(field.name)
|
|
138
|
+
this._typed.set(form, typed)
|
|
139
|
+
}
|
|
140
|
+
if (this._fieldProblems.get(form)?.[field.name]) {
|
|
141
|
+
const problems = new Map(this._fieldProblems)
|
|
142
|
+
const { [field.name]: _, ...rest } = problems.get(form) ?? {}
|
|
143
|
+
problems.set(form, rest)
|
|
144
|
+
this._fieldProblems = problems
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
async #press(button, form) {
|
|
149
|
+
if (button.disabled || this._busy) return
|
|
150
|
+
let values
|
|
151
|
+
if (button.submit && form) {
|
|
152
|
+
const current = this._values.get(form) ?? {}
|
|
153
|
+
const problems = fieldProblems(form.fields, current)
|
|
154
|
+
if (Object.keys(problems).length > 0) {
|
|
155
|
+
this._fieldProblems = new Map(this._fieldProblems).set(form, problems)
|
|
156
|
+
return
|
|
157
|
+
}
|
|
158
|
+
values = sentValues(form.fields, current, this._typed.get(form))
|
|
159
|
+
}
|
|
160
|
+
if (button.confirm) {
|
|
161
|
+
try {
|
|
162
|
+
await umbConfirmModal(this, {
|
|
163
|
+
color: button.look === 'danger' ? 'danger' : 'default',
|
|
164
|
+
headline: button.label,
|
|
165
|
+
content: button.confirm,
|
|
166
|
+
confirmLabel: button.label,
|
|
167
|
+
})
|
|
168
|
+
} catch {
|
|
169
|
+
return
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
await this.#call(actionBody(button, this._state, values))
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
#button(button, form) {
|
|
176
|
+
const look = LOOKS[button.look ?? 'secondary'] ?? LOOKS.secondary
|
|
177
|
+
return html`<uui-button
|
|
178
|
+
look=${look.look}
|
|
179
|
+
color=${look.color}
|
|
180
|
+
label=${button.label}
|
|
181
|
+
?disabled=${button.disabled || this._busy}
|
|
182
|
+
@click=${() => this.#press(button, form)}></uui-button>`
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
#search(item) {
|
|
186
|
+
return html`<uui-input
|
|
187
|
+
type="search"
|
|
188
|
+
label=${item.placeholder ?? 'Search'}
|
|
189
|
+
placeholder=${item.placeholder ?? ''}
|
|
190
|
+
.value=${item.value ?? ''}
|
|
191
|
+
@change=${(event) =>
|
|
192
|
+
this.#call({
|
|
193
|
+
action: item.action,
|
|
194
|
+
input: { query: event.target.value ?? '' },
|
|
195
|
+
})}></uui-input>`
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#cell(cell) {
|
|
199
|
+
switch (cell.type) {
|
|
200
|
+
case 'code':
|
|
201
|
+
return html`<code>${cell.text}</code>`
|
|
202
|
+
case 'tag':
|
|
203
|
+
return html`<uui-tag look=${cell.look ?? 'default'} size="s">${cell.text}</uui-tag>`
|
|
204
|
+
case 'link': {
|
|
205
|
+
const href = linkTarget(cell.href, backOfficeBase())
|
|
206
|
+
if (!href) return html`${cell.text}`
|
|
207
|
+
const external = /^https?:/i.test(href)
|
|
208
|
+
return html`<a
|
|
209
|
+
href=${href}
|
|
210
|
+
target=${external ? '_blank' : nothing}
|
|
211
|
+
rel=${external ? 'noopener noreferrer' : nothing}
|
|
212
|
+
>${cell.text}</a
|
|
213
|
+
>`
|
|
214
|
+
}
|
|
215
|
+
case 'date': {
|
|
216
|
+
const at = new Date(cell.value)
|
|
217
|
+
return html`${Number.isNaN(at.getTime()) ? '' : at.toLocaleString()}`
|
|
218
|
+
}
|
|
219
|
+
default:
|
|
220
|
+
return html`${cell.text ?? ''}`
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
#table(node) {
|
|
225
|
+
const actions = node.rows.some((row) => (row.actions ?? []).length > 0)
|
|
226
|
+
return html`<uui-table>
|
|
227
|
+
<uui-table-head>
|
|
228
|
+
${node.columns.map((column) => html`<uui-table-head-cell>${column}</uui-table-head-cell>`)}
|
|
229
|
+
${actions ? html`<uui-table-head-cell></uui-table-head-cell>` : nothing}
|
|
230
|
+
</uui-table-head>
|
|
231
|
+
${repeat(
|
|
232
|
+
node.rows,
|
|
233
|
+
(row) => row.key,
|
|
234
|
+
(row) => html`<uui-table-row>
|
|
235
|
+
${row.cells.map((cell) => html`<uui-table-cell>${this.#cell(cell)}</uui-table-cell>`)}
|
|
236
|
+
${
|
|
237
|
+
actions
|
|
238
|
+
? html`<uui-table-cell class="actions">
|
|
239
|
+
${(row.actions ?? []).map((button) => this.#button(button))}
|
|
240
|
+
</uui-table-cell>`
|
|
241
|
+
: nothing
|
|
242
|
+
}
|
|
243
|
+
</uui-table-row>`,
|
|
244
|
+
)}
|
|
245
|
+
</uui-table>`
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
/** A list's rows, each sub-field drawn as its own field, with add and remove (story 329). */
|
|
249
|
+
#list(form, field, value) {
|
|
250
|
+
const rows = Array.isArray(value) ? value : []
|
|
251
|
+
const set = (next) => this.#set(form, field, next)
|
|
252
|
+
const blank = Object.fromEntries(
|
|
253
|
+
field.fields.map((sub) => [
|
|
254
|
+
sub.name,
|
|
255
|
+
sub.kind === 'boolean' ? false : sub.kind === 'number' ? null : '',
|
|
256
|
+
]),
|
|
257
|
+
)
|
|
258
|
+
const canAdd = !field.readOnly && (field.max === undefined || rows.length < field.max)
|
|
259
|
+
const canRemove = !field.readOnly && (field.min === undefined || rows.length > field.min)
|
|
260
|
+
return html`<div class="list">
|
|
261
|
+
${rows.map(
|
|
262
|
+
(row, index) => html`<div class="list-row">
|
|
263
|
+
${field.fields.map((sub) =>
|
|
264
|
+
this.#input(
|
|
265
|
+
form,
|
|
266
|
+
{ ...sub, readOnly: field.readOnly || sub.readOnly },
|
|
267
|
+
row[sub.name],
|
|
268
|
+
(next) =>
|
|
269
|
+
set(
|
|
270
|
+
rows.map((other, at) => (at === index ? { ...other, [sub.name]: next } : other)),
|
|
271
|
+
),
|
|
272
|
+
),
|
|
273
|
+
)}
|
|
274
|
+
${
|
|
275
|
+
canRemove
|
|
276
|
+
? html`<uui-button
|
|
277
|
+
look="secondary"
|
|
278
|
+
compact
|
|
279
|
+
label="Remove"
|
|
280
|
+
@click=${() => set(rows.filter((_, at) => at !== index))}></uui-button>`
|
|
281
|
+
: nothing
|
|
282
|
+
}
|
|
283
|
+
</div>`,
|
|
284
|
+
)}
|
|
285
|
+
${
|
|
286
|
+
canAdd
|
|
287
|
+
? html`<uui-button
|
|
288
|
+
look="secondary"
|
|
289
|
+
label=${field.addLabel ?? 'Add'}
|
|
290
|
+
@click=${() => set([...rows, { ...blank }])}></uui-button>`
|
|
291
|
+
: nothing
|
|
292
|
+
}
|
|
293
|
+
</div>`
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
#input(form, field, value, onChange) {
|
|
297
|
+
const set = onChange ?? ((next) => this.#set(form, field, next))
|
|
298
|
+
const locked = field.readOnly === true
|
|
299
|
+
switch (field.kind) {
|
|
300
|
+
case 'list':
|
|
301
|
+
return this.#list(form, field, value)
|
|
302
|
+
case 'boolean':
|
|
303
|
+
return html`<uui-toggle
|
|
304
|
+
label=${field.label}
|
|
305
|
+
?disabled=${locked}
|
|
306
|
+
.checked=${value === true}
|
|
307
|
+
@change=${(event) => set(event.target.checked === true)}></uui-toggle>`
|
|
308
|
+
case 'choice':
|
|
309
|
+
return html`<uui-select
|
|
310
|
+
label=${field.label}
|
|
311
|
+
?disabled=${locked}
|
|
312
|
+
.options=${(field.options ?? []).map((option) => ({
|
|
313
|
+
value: option.value,
|
|
314
|
+
name: option.label,
|
|
315
|
+
selected: option.value === value,
|
|
316
|
+
}))}
|
|
317
|
+
@change=${(event) => set(event.target.value)}></uui-select>`
|
|
318
|
+
case 'page':
|
|
319
|
+
return html`<umb-input-document
|
|
320
|
+
?readonly=${locked}
|
|
321
|
+
max="1"
|
|
322
|
+
.selection=${value ? [value] : []}
|
|
323
|
+
@change=${(event) => set(event.target.selection?.[0] ?? '')}></umb-input-document>`
|
|
324
|
+
case 'media':
|
|
325
|
+
return html`<umb-input-media
|
|
326
|
+
?readonly=${locked}
|
|
327
|
+
max="1"
|
|
328
|
+
.selection=${value ? [value] : []}
|
|
329
|
+
@change=${(event) => set(event.target.selection?.[0] ?? '')}></umb-input-media>`
|
|
330
|
+
case 'member':
|
|
331
|
+
return html`<umb-input-member
|
|
332
|
+
?readonly=${locked}
|
|
333
|
+
max="1"
|
|
334
|
+
.selection=${value ? [value] : []}
|
|
335
|
+
@change=${(event) => set(event.target.selection?.[0] ?? '')}></umb-input-member>`
|
|
336
|
+
case 'text':
|
|
337
|
+
if (field.multiline)
|
|
338
|
+
return html`<uui-textarea
|
|
339
|
+
label=${field.label}
|
|
340
|
+
?readonly=${locked}
|
|
341
|
+
placeholder=${field.placeholder ?? ''}
|
|
342
|
+
.value=${value ?? ''}
|
|
343
|
+
@input=${(event) => set(event.target.value)}></uui-textarea>`
|
|
344
|
+
break
|
|
345
|
+
}
|
|
346
|
+
return html`<uui-input
|
|
347
|
+
label=${field.label}
|
|
348
|
+
?readonly=${locked}
|
|
349
|
+
type=${field.kind === 'secret' ? 'password' : field.kind === 'number' ? 'number' : 'text'}
|
|
350
|
+
placeholder=${field.placeholder ?? ''}
|
|
351
|
+
.value=${value ?? ''}
|
|
352
|
+
@input=${(event) =>
|
|
353
|
+
set(
|
|
354
|
+
field.kind === 'number' && event.target.value !== ''
|
|
355
|
+
? Number(event.target.value)
|
|
356
|
+
: event.target.value,
|
|
357
|
+
)}></uui-input>`
|
|
358
|
+
}
|
|
359
|
+
|
|
360
|
+
#form(node) {
|
|
361
|
+
const values = this._values.get(node) ?? {}
|
|
362
|
+
const problems = this._fieldProblems.get(node) ?? {}
|
|
363
|
+
return html`<uui-box headline=${node.title ?? nothing}>
|
|
364
|
+
${visibleFields(node.fields, values).map(
|
|
365
|
+
(field) => html`<div class="field">
|
|
366
|
+
<label>${field.label}${field.required ? html`<span class="required">*</span>` : nothing}</label>
|
|
367
|
+
${this.#input(node, field, values[field.name])}
|
|
368
|
+
${hintsFor(field, values).map((hint) => html`<small>${hint}</small>`)}
|
|
369
|
+
${problems[field.name] ? html`<small class="invalid">${problems[field.name]}</small>` : nothing}
|
|
370
|
+
</div>`,
|
|
371
|
+
)}
|
|
372
|
+
<div class="form-actions">${node.actions.map((button) => this.#button(button, node))}</div>
|
|
373
|
+
</uui-box>`
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
#tabs(node) {
|
|
377
|
+
const active = this._tabs.get(node) ?? node.tabs[0]?.id
|
|
378
|
+
const shown = node.tabs.find((tab) => tab.id === active) ?? node.tabs[0]
|
|
379
|
+
return html`<uui-tab-group>
|
|
380
|
+
${node.tabs.map(
|
|
381
|
+
(tab) => html`<uui-tab
|
|
382
|
+
label=${tab.label}
|
|
383
|
+
?active=${tab.id === shown?.id}
|
|
384
|
+
@click=${() => {
|
|
385
|
+
this._tabs = new Map(this._tabs).set(node, tab.id)
|
|
386
|
+
}}>${tab.label}</uui-tab>`,
|
|
387
|
+
)}
|
|
388
|
+
</uui-tab-group>
|
|
389
|
+
<div class="tab">${this.#nodes(shown?.body ?? [])}</div>`
|
|
390
|
+
}
|
|
391
|
+
|
|
392
|
+
#node(node) {
|
|
393
|
+
switch (node.type) {
|
|
394
|
+
case 'table':
|
|
395
|
+
return this.#table(node)
|
|
396
|
+
case 'form':
|
|
397
|
+
return this.#form(node)
|
|
398
|
+
case 'button':
|
|
399
|
+
return html`<div>${this.#button(node)}</div>`
|
|
400
|
+
case 'notice':
|
|
401
|
+
return html`<div class="banner notice">${node.text}</div>`
|
|
402
|
+
case 'problem':
|
|
403
|
+
return html`<div class="banner problem">${node.text}</div>`
|
|
404
|
+
case 'empty':
|
|
405
|
+
return html`<uui-box headline=${node.title}>
|
|
406
|
+
${node.text ? html`<p>${node.text}</p>` : nothing}
|
|
407
|
+
${(node.actions ?? []).map((button) => this.#button(button))}
|
|
408
|
+
</uui-box>`
|
|
409
|
+
case 'progress':
|
|
410
|
+
return html`<div class="progress">
|
|
411
|
+
${node.label ? html`<span>${node.label}</span>` : nothing}
|
|
412
|
+
${
|
|
413
|
+
typeof node.value === 'number'
|
|
414
|
+
? html`<uui-progress-bar progress=${node.value}></uui-progress-bar>`
|
|
415
|
+
: html`<uui-loader-bar></uui-loader-bar>`
|
|
416
|
+
}
|
|
417
|
+
</div>`
|
|
418
|
+
case 'tabs':
|
|
419
|
+
return this.#tabs(node)
|
|
420
|
+
default:
|
|
421
|
+
return nothing
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
#nodes(nodes) {
|
|
426
|
+
return nodes.map((node) => this.#node(node))
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
render() {
|
|
430
|
+
const screen = this._screen
|
|
431
|
+
return html`<umb-body-layout headline=${screen?.title ?? ''}>
|
|
432
|
+
<div id="content">
|
|
433
|
+
${
|
|
434
|
+
(screen?.toolbar ?? []).length > 0
|
|
435
|
+
? html`<div id="toolbar">
|
|
436
|
+
${screen.toolbar.map((item) =>
|
|
437
|
+
item.type === 'search' ? this.#search(item) : this.#button(item),
|
|
438
|
+
)}
|
|
439
|
+
</div>`
|
|
440
|
+
: nothing
|
|
441
|
+
}
|
|
442
|
+
${this._problem ? html`<div class="banner problem">${this._problem}</div>` : nothing}
|
|
443
|
+
${this._notice ? html`<div class="banner notice">${this._notice}</div>` : nothing}
|
|
444
|
+
${
|
|
445
|
+
this._loading
|
|
446
|
+
? html`<div id="loader"><uui-loader></uui-loader></div>`
|
|
447
|
+
: this.#nodes(screen?.body ?? [])
|
|
448
|
+
}
|
|
449
|
+
</div>
|
|
450
|
+
</umb-body-layout>`
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
static styles = css`
|
|
454
|
+
:host {
|
|
455
|
+
display: block;
|
|
456
|
+
width: 100%;
|
|
457
|
+
height: 100%;
|
|
458
|
+
}
|
|
459
|
+
#content {
|
|
460
|
+
padding: var(--uui-size-layout-1, 24px);
|
|
461
|
+
display: flex;
|
|
462
|
+
flex-direction: column;
|
|
463
|
+
gap: var(--uui-size-space-5, 18px);
|
|
464
|
+
}
|
|
465
|
+
#toolbar {
|
|
466
|
+
display: flex;
|
|
467
|
+
align-items: center;
|
|
468
|
+
gap: var(--uui-size-space-4, 12px);
|
|
469
|
+
}
|
|
470
|
+
#toolbar uui-input {
|
|
471
|
+
flex: 1;
|
|
472
|
+
}
|
|
473
|
+
#loader {
|
|
474
|
+
display: flex;
|
|
475
|
+
justify-content: center;
|
|
476
|
+
padding: var(--uui-size-layout-3, 48px);
|
|
477
|
+
}
|
|
478
|
+
.field {
|
|
479
|
+
display: flex;
|
|
480
|
+
flex-direction: column;
|
|
481
|
+
gap: var(--uui-size-space-2, 6px);
|
|
482
|
+
margin-bottom: var(--uui-size-space-5, 18px);
|
|
483
|
+
max-width: 48rem;
|
|
484
|
+
}
|
|
485
|
+
.field label {
|
|
486
|
+
font-weight: bold;
|
|
487
|
+
}
|
|
488
|
+
.field small {
|
|
489
|
+
opacity: 0.8;
|
|
490
|
+
line-height: 1.5;
|
|
491
|
+
}
|
|
492
|
+
.field small.invalid {
|
|
493
|
+
color: var(--uui-color-danger, #d42054);
|
|
494
|
+
opacity: 1;
|
|
495
|
+
}
|
|
496
|
+
.required {
|
|
497
|
+
color: var(--uui-color-danger, #d42054);
|
|
498
|
+
margin-left: 2px;
|
|
499
|
+
}
|
|
500
|
+
.form-actions,
|
|
501
|
+
.actions {
|
|
502
|
+
display: flex;
|
|
503
|
+
gap: var(--uui-size-space-2, 6px);
|
|
504
|
+
}
|
|
505
|
+
.actions {
|
|
506
|
+
justify-content: flex-end;
|
|
507
|
+
}
|
|
508
|
+
.banner {
|
|
509
|
+
padding: var(--uui-size-space-4, 12px);
|
|
510
|
+
border-left: 3px solid var(--uui-color-default, #3544b1);
|
|
511
|
+
background: var(--uui-color-surface-alt, #f3f3f5);
|
|
512
|
+
}
|
|
513
|
+
.banner.problem {
|
|
514
|
+
border-left-color: var(--uui-color-danger, #d42054);
|
|
515
|
+
}
|
|
516
|
+
.banner.notice {
|
|
517
|
+
border-left-color: var(--uui-color-positive, #2bc37c);
|
|
518
|
+
}
|
|
519
|
+
.progress {
|
|
520
|
+
display: flex;
|
|
521
|
+
flex-direction: column;
|
|
522
|
+
gap: var(--uui-size-space-2, 6px);
|
|
523
|
+
}
|
|
524
|
+
.list {
|
|
525
|
+
display: flex;
|
|
526
|
+
flex-direction: column;
|
|
527
|
+
gap: var(--uui-size-space-2, 6px);
|
|
528
|
+
}
|
|
529
|
+
.list-row {
|
|
530
|
+
display: flex;
|
|
531
|
+
gap: var(--uui-size-space-2, 6px);
|
|
532
|
+
align-items: center;
|
|
533
|
+
}
|
|
534
|
+
.tab {
|
|
535
|
+
display: flex;
|
|
536
|
+
flex-direction: column;
|
|
537
|
+
gap: var(--uui-size-space-5, 18px);
|
|
538
|
+
padding-top: var(--uui-size-space-4, 12px);
|
|
539
|
+
}
|
|
540
|
+
code {
|
|
541
|
+
word-break: break-all;
|
|
542
|
+
}
|
|
543
|
+
p {
|
|
544
|
+
max-width: 60ch;
|
|
545
|
+
line-height: 1.5;
|
|
546
|
+
}
|
|
547
|
+
`
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
if (!customElements.get('crombolo-extension-screen'))
|
|
551
|
+
customElements.define('crombolo-extension-screen', CromboloExtensionScreenElement)
|
package/plugin/forms-client.js
CHANGED
|
@@ -67,6 +67,13 @@ export const previewChoices = (source) =>
|
|
|
67
67
|
/** Every dictionary item, with its words in the default language. */
|
|
68
68
|
export const listWords = async () => (await call('/words')).body.words ?? []
|
|
69
69
|
|
|
70
|
+
/** Sets a send-to-URL workflow's secret header (story 304), or with no value removes it. */
|
|
71
|
+
export const setSecretHeader = (form, workflow, header, value) =>
|
|
72
|
+
call(
|
|
73
|
+
`/${encodeURIComponent(form)}/workflows/${encodeURIComponent(workflow)}/secrets/${encodeURIComponent(header)}`,
|
|
74
|
+
value === undefined ? { method: 'DELETE' } : { method: 'PUT', body: JSON.stringify({ value }) },
|
|
75
|
+
)
|
|
76
|
+
|
|
70
77
|
export const deleteForm = (key) => call(`/${encodeURIComponent(key)}`, { method: 'DELETE' })
|
|
71
78
|
|
|
72
79
|
export const listEntries = async (key, query = {}) => {
|
package/plugin/forms-overview.js
CHANGED
|
@@ -29,6 +29,7 @@ import {
|
|
|
29
29
|
previewChoices,
|
|
30
30
|
readForm,
|
|
31
31
|
saveForm,
|
|
32
|
+
setSecretHeader,
|
|
32
33
|
} from './forms-client.js'
|
|
33
34
|
import {
|
|
34
35
|
addGroup,
|
|
@@ -52,6 +53,8 @@ import {
|
|
|
52
53
|
addWorkflow,
|
|
53
54
|
describeProblemPath,
|
|
54
55
|
removeWorkflow,
|
|
56
|
+
secretHeaderNames,
|
|
57
|
+
setSecretHeaderName,
|
|
55
58
|
setWorkflowName,
|
|
56
59
|
setWorkflowSetting,
|
|
57
60
|
setWorkflowTrigger,
|
|
@@ -99,6 +102,7 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
|
|
|
99
102
|
_types: { state: true },
|
|
100
103
|
_workflowTypes: { state: true },
|
|
101
104
|
_designs: { state: true },
|
|
105
|
+
_secrets: { state: true },
|
|
102
106
|
_because: { state: true },
|
|
103
107
|
_tab: { state: true },
|
|
104
108
|
}
|
|
@@ -183,6 +187,7 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
|
|
|
183
187
|
this._tab = 'design'
|
|
184
188
|
const detail = await readForm(key)
|
|
185
189
|
this._editing = withLayout(detail.definition)
|
|
190
|
+
this._secrets = detail.secrets ?? []
|
|
186
191
|
this._choices = new Map()
|
|
187
192
|
for (const field of this.#fields) if (field.source) this.#preview(field)
|
|
188
193
|
}
|
|
@@ -792,9 +797,73 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
|
|
|
792
797
|
${hint}
|
|
793
798
|
</label>`
|
|
794
799
|
})}
|
|
800
|
+
${workflow.type === 'sendToUrl' ? this.#secretHeaders(workflow, index) : nothing}
|
|
795
801
|
</div>`
|
|
796
802
|
}
|
|
797
803
|
|
|
804
|
+
/** Headers kept sealed on the site and sent only to the address they were set for (story 304). */
|
|
805
|
+
#secretHeaders(workflow, index) {
|
|
806
|
+
const names = secretHeaderNames(workflow)
|
|
807
|
+
return html`<div class="secret-headers">
|
|
808
|
+
<span>Secret headers</span>
|
|
809
|
+
<small class="offered">For a key or token the address needs. Kept on this site, never shown again, and sent only to the address above: change the address and set them again.</small>
|
|
810
|
+
${names.map((name) => {
|
|
811
|
+
const saved = (this._secrets ?? []).find(
|
|
812
|
+
(secret) => secret.workflow === workflow.key && secret.header === name,
|
|
813
|
+
)
|
|
814
|
+
return html`<div class="secret-header">
|
|
815
|
+
<code>${name}</code>
|
|
816
|
+
<span>${saved ? (saved.set ? 'Set' : 'Not set') : 'Save the form, then set it'}</span>
|
|
817
|
+
${
|
|
818
|
+
saved
|
|
819
|
+
? html`<uui-input
|
|
820
|
+
type="password"
|
|
821
|
+
label=${`A value for ${name}`}
|
|
822
|
+
placeholder=${saved.set ? 'Replace it' : 'Its value'}
|
|
823
|
+
@change=${(event) => this.#setSecret(workflow, name, event.target.value)}
|
|
824
|
+
></uui-input>`
|
|
825
|
+
: nothing
|
|
826
|
+
}
|
|
827
|
+
${
|
|
828
|
+
saved?.set
|
|
829
|
+
? html`<uui-button compact look="secondary" label="Clear"
|
|
830
|
+
@click=${() => this.#setSecret(workflow, name, undefined)}></uui-button>`
|
|
831
|
+
: nothing
|
|
832
|
+
}
|
|
833
|
+
<uui-button compact look="secondary" color="danger" label=${`Stop sending ${name}`}
|
|
834
|
+
@click=${() => this.#apply(setSecretHeaderName, index, name, false)}></uui-button>
|
|
835
|
+
</div>`
|
|
836
|
+
})}
|
|
837
|
+
<uui-input
|
|
838
|
+
label="Add a secret header"
|
|
839
|
+
placeholder="Its name, such as Authorization"
|
|
840
|
+
@change=${(event) => {
|
|
841
|
+
const name = event.target.value.trim()
|
|
842
|
+
if (!name) return
|
|
843
|
+
this.#apply(setSecretHeaderName, index, name, true)
|
|
844
|
+
event.target.value = ''
|
|
845
|
+
}}
|
|
846
|
+
></uui-input>
|
|
847
|
+
</div>`
|
|
848
|
+
}
|
|
849
|
+
|
|
850
|
+
async #setSecret(workflow, header, value) {
|
|
851
|
+
if (value === '') return
|
|
852
|
+
try {
|
|
853
|
+
const result = await setSecretHeader(this._editing.key, workflow.key, header, value)
|
|
854
|
+
if (!result.ok) {
|
|
855
|
+
this._notice = result.body.message ?? 'That header could not be set.'
|
|
856
|
+
return
|
|
857
|
+
}
|
|
858
|
+
this.#notifications?.peek('positive', {
|
|
859
|
+
data: { message: value === undefined ? `${header} cleared` : `${header} set` },
|
|
860
|
+
})
|
|
861
|
+
this._secrets = (await readForm(this._editing.key)).secrets ?? []
|
|
862
|
+
} catch (error) {
|
|
863
|
+
this._notice = error.message
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
|
|
798
867
|
#touch() {
|
|
799
868
|
// Lit tracks the reference, not what is inside it.
|
|
800
869
|
this._editing = { ...this._editing }
|
|
@@ -1120,6 +1189,16 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
|
|
|
1120
1189
|
gap: var(--uui-size-space-3, 9px);
|
|
1121
1190
|
max-width: 60ch;
|
|
1122
1191
|
}
|
|
1192
|
+
.secret-headers {
|
|
1193
|
+
display: grid;
|
|
1194
|
+
gap: var(--uui-size-space-2, 6px);
|
|
1195
|
+
}
|
|
1196
|
+
.secret-header {
|
|
1197
|
+
display: flex;
|
|
1198
|
+
flex-wrap: wrap;
|
|
1199
|
+
align-items: center;
|
|
1200
|
+
gap: var(--uui-size-space-3, 9px);
|
|
1201
|
+
}
|
|
1123
1202
|
.workflow-settings label,
|
|
1124
1203
|
.workflow-settings .switch {
|
|
1125
1204
|
display: grid;
|
|
@@ -145,3 +145,21 @@ export function describeProblemPath(form, path, types = new Map()) {
|
|
|
145
145
|
)
|
|
146
146
|
return `${name}: ${setting?.label ?? FILE_ONLY_LABELS[found[2]] ?? found[2]}`
|
|
147
147
|
}
|
|
148
|
+
|
|
149
|
+
/** The headers a send-to-URL workflow keeps sealed on the site (story 304). */
|
|
150
|
+
export const secretHeaderNames = (workflow) =>
|
|
151
|
+
Object.entries(workflow.settings?.headers ?? {})
|
|
152
|
+
.filter(([, value]) => value && typeof value === 'object' && value.secret === true)
|
|
153
|
+
.map(([name]) => name)
|
|
154
|
+
|
|
155
|
+
/** Names a header as secret, or with `secret` false takes it out. */
|
|
156
|
+
export const setSecretHeaderName = (form, index, name, secret) =>
|
|
157
|
+
replace(form, index, (workflow) => {
|
|
158
|
+
const headers = { ...(workflow.settings?.headers ?? {}) }
|
|
159
|
+
if (secret) headers[name] = { secret: true }
|
|
160
|
+
else delete headers[name]
|
|
161
|
+
const settings = { ...workflow.settings }
|
|
162
|
+
if (Object.keys(headers).length > 0) settings.headers = headers
|
|
163
|
+
else delete settings.headers
|
|
164
|
+
return { settings }
|
|
165
|
+
})
|