@crombolo/backoffice-host 0.53.2 → 0.55.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/assets/login.js +6 -4
- package/package.json +3 -3
- package/plugin/alias-input.js +85 -0
- package/plugin/alias-model.js +36 -0
- package/plugin/app-preview/umbraco-package.json +1 -1
- package/plugin/approvals-tree-model.js +21 -0
- package/plugin/approvals-tree.js +108 -0
- package/plugin/content-strip-items.js +20 -10
- package/plugin/definition-tree.js +157 -126
- package/plugin/dictionary-chip.js +233 -0
- package/plugin/dictionary-words-client.js +52 -0
- package/plugin/dictionary-words.js +228 -0
- package/plugin/form-word-input-model.js +68 -15
- package/plugin/form-word-input.js +23 -125
- package/plugin/forms-entries.js +1 -0
- package/plugin/forms-overview.js +79 -9
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/page-history-modal.js +279 -0
- package/plugin/page-history-model.js +108 -0
- package/plugin/page-history.js +89 -0
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/settings-cards.js +8 -1
- package/plugin/settings-section.js +43 -18
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/template-picker-modal.js +276 -0
- package/plugin/template-picker-model.js +77 -0
- package/plugin/template-picker.js +43 -0
- package/plugin/tsx-editors.js +5 -0
- package/plugin/tsx-highlighting.js +81 -0
- package/plugin/umbraco-package.json +111 -41
- package/plugin/workflow-client.js +3 -0
- package/plugin/workflow-designer.js +66 -14
- package/plugin/workflow-requests.js +111 -105
- package/plugin/workflow-send-condition.js +2 -0
- package/plugin/workflow-send-model.js +20 -0
- package/plugin/workflow-send-unpublish.js +2 -0
- package/plugin/workflow-send.js +231 -0
- package/plugin/workflow-tab.js +32 -86
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* The tree
|
|
2
|
+
* The tree of forms or of workflows (story 289), in Structure or beside them: their folders
|
|
3
|
+
* and their items,
|
|
3
4
|
* with making, renaming and moving, or a word saying why they cannot be changed.
|
|
4
5
|
* Forms' root opens every submission; a folder is a real folder of files.
|
|
5
6
|
*/
|
|
6
7
|
import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
|
|
7
8
|
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
8
|
-
import { activeItem } from './content-strip-items.js'
|
|
9
9
|
import { definitionTree, readOnlyWords } from './definition-tree-model.js'
|
|
10
10
|
import { formsTree, moveForm, sendFormFolder } from './forms-client.js'
|
|
11
11
|
import { listWorkflows, moveWorkflow, sendWorkflowFolder } from './workflow-client.js'
|
|
@@ -21,6 +21,10 @@ const formsAt = (view) =>
|
|
|
21
21
|
? `section/settings/forms${view === 'entries' ? '/entries' : ''}`
|
|
22
22
|
: `section/forms/view/${view}`
|
|
23
23
|
|
|
24
|
+
/** The workflow designer, in Structure for those who have it, else beside forms. */
|
|
25
|
+
const workflowsAt = (query = '') =>
|
|
26
|
+
`${here().startsWith('section/settings') ? 'section/settings/workflows' : 'section/forms/view/workflows'}${query}`
|
|
27
|
+
|
|
24
28
|
const KINDS = {
|
|
25
29
|
Forms: {
|
|
26
30
|
label: 'Forms',
|
|
@@ -28,6 +32,8 @@ const KINDS = {
|
|
|
28
32
|
return formsAt('entries')
|
|
29
33
|
},
|
|
30
34
|
rootLabel: 'Forms',
|
|
35
|
+
itemNoun: 'form',
|
|
36
|
+
icon: 'icon-autofill',
|
|
31
37
|
open: (item) => `${formsAt('forms')}?form=${encodeURIComponent(item.key)}`,
|
|
32
38
|
create: (folder) => `${formsAt('forms')}?new=${encodeURIComponent(folder)}`,
|
|
33
39
|
load: formsTree,
|
|
@@ -36,10 +42,14 @@ const KINDS = {
|
|
|
36
42
|
},
|
|
37
43
|
Workflows: {
|
|
38
44
|
label: 'Workflows',
|
|
39
|
-
root
|
|
45
|
+
get root() {
|
|
46
|
+
return workflowsAt()
|
|
47
|
+
},
|
|
40
48
|
rootLabel: 'Workflows',
|
|
41
|
-
|
|
42
|
-
|
|
49
|
+
itemNoun: 'workflow',
|
|
50
|
+
icon: 'icon-mindmap',
|
|
51
|
+
open: (item) => workflowsAt(`?workflow=${encodeURIComponent(item.alias)}`),
|
|
52
|
+
create: (folder) => workflowsAt(`?new=${encodeURIComponent(folder)}`),
|
|
43
53
|
load: async () => {
|
|
44
54
|
const list = await listWorkflows()
|
|
45
55
|
return {
|
|
@@ -58,8 +68,10 @@ const url = (path) =>
|
|
|
58
68
|
|
|
59
69
|
export default class CromboloDefinitionTreeElement extends UmbLitElement {
|
|
60
70
|
static properties = {
|
|
61
|
-
/** The tree to show; without it, whichever the address belongs to. */
|
|
71
|
+
/** The tree to show; without it, the menu item's, else whichever the address belongs to. */
|
|
62
72
|
kind: { type: String },
|
|
73
|
+
/** Set by the menu, as for any menu item: its `meta.kind` names the tree. */
|
|
74
|
+
manifest: { attribute: false },
|
|
63
75
|
_kind: { state: true },
|
|
64
76
|
_tree: { state: true },
|
|
65
77
|
_because: { state: true },
|
|
@@ -68,7 +80,10 @@ export default class CromboloDefinitionTreeElement extends UmbLitElement {
|
|
|
68
80
|
}
|
|
69
81
|
|
|
70
82
|
#follow = () => {
|
|
71
|
-
const kind =
|
|
83
|
+
const kind =
|
|
84
|
+
this.kind ??
|
|
85
|
+
this.manifest?.meta?.kind ??
|
|
86
|
+
(/^section\/forms\/view\/workflows/.test(here()) ? 'Workflows' : 'Forms')
|
|
72
87
|
if (kind === this._kind) return
|
|
73
88
|
this._kind = kind
|
|
74
89
|
this.#load()
|
|
@@ -76,6 +91,10 @@ export default class CromboloDefinitionTreeElement extends UmbLitElement {
|
|
|
76
91
|
|
|
77
92
|
#reload = () => this.#load()
|
|
78
93
|
|
|
94
|
+
willUpdate(changed) {
|
|
95
|
+
if (changed.has('manifest')) this.#follow()
|
|
96
|
+
}
|
|
97
|
+
|
|
79
98
|
connectedCallback() {
|
|
80
99
|
super.connectedCallback()
|
|
81
100
|
this.#follow()
|
|
@@ -96,7 +115,10 @@ export default class CromboloDefinitionTreeElement extends UmbLitElement {
|
|
|
96
115
|
}
|
|
97
116
|
|
|
98
117
|
async #load() {
|
|
118
|
+
const kind = this._kind
|
|
99
119
|
const { items, folders, readOnlyBecause } = await this.#config.load()
|
|
120
|
+
// A menu item names its tree after it is made: a load for the tree it had is dropped.
|
|
121
|
+
if (kind !== this._kind) return
|
|
100
122
|
this._tree = definitionTree(items, folders)
|
|
101
123
|
this._folders = folders
|
|
102
124
|
this._because = readOnlyBecause
|
|
@@ -147,156 +169,164 @@ export default class CromboloDefinitionTreeElement extends UmbLitElement {
|
|
|
147
169
|
</form>`
|
|
148
170
|
}
|
|
149
171
|
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
172
|
+
/** Which folders are open, by path; the root is `''`. Everything starts open. */
|
|
173
|
+
#closed = new Set()
|
|
174
|
+
|
|
175
|
+
#toggle(path, open) {
|
|
176
|
+
if (open) this.#closed.delete(path)
|
|
177
|
+
else this.#closed.add(path)
|
|
178
|
+
this.requestUpdate()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/** The popovers this render made: drawn after the tree, since a closed folder hides its children. */
|
|
182
|
+
#popovers = []
|
|
183
|
+
|
|
184
|
+
/**
|
|
185
|
+
* A row's actions, as Umbraco's tree draws them: "…" for a popover of choices, then the
|
|
186
|
+
* first choice as a button of its own when it is marked `quick`, e.g. "+" for a new item.
|
|
187
|
+
*/
|
|
188
|
+
#menu(id, label, choices) {
|
|
189
|
+
if (choices.length === 0) return nothing
|
|
190
|
+
const pick = (run) => () => {
|
|
191
|
+
this.renderRoot.querySelector(`#${id}`)?.hidePopover?.()
|
|
192
|
+
run()
|
|
193
|
+
}
|
|
194
|
+
this.#popovers.push(html`<uui-popover-container id=${id} placement="bottom-start">
|
|
195
|
+
<umb-popover-layout>
|
|
196
|
+
${choices.map(
|
|
197
|
+
(choice) =>
|
|
198
|
+
html`<uui-menu-item label=${choice.label} @click-label=${pick(choice.run)}>
|
|
199
|
+
<umb-icon slot="icon" name=${choice.icon}></umb-icon>
|
|
200
|
+
</uui-menu-item>`,
|
|
201
|
+
)}
|
|
202
|
+
</umb-popover-layout>
|
|
203
|
+
</uui-popover-container>`)
|
|
204
|
+
const [first] = choices
|
|
205
|
+
return html`<uui-action-bar slot="actions">
|
|
206
|
+
<uui-button compact label=${`Actions for ${label}`} popovertarget=${id}
|
|
207
|
+
><uui-symbol-more></uui-symbol-more
|
|
208
|
+
></uui-button>
|
|
162
209
|
${
|
|
163
|
-
|
|
164
|
-
? html`<button
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
aria-label="Rename"
|
|
168
|
-
@click=${() => {
|
|
169
|
-
this._asking = { verb: 'rename', path }
|
|
170
|
-
}}
|
|
171
|
-
>✎</button>
|
|
172
|
-
<button
|
|
173
|
-
type="button"
|
|
174
|
-
title="Delete"
|
|
175
|
-
aria-label="Delete"
|
|
176
|
-
@click=${() => this.#send(() => this.#config.folder('DELETE', { path }))}
|
|
177
|
-
>×</button>`
|
|
210
|
+
first.quick
|
|
211
|
+
? html`<uui-button compact label=${first.label} title=${first.label} @click=${first.run}
|
|
212
|
+
><umb-icon name=${first.icon}></umb-icon
|
|
213
|
+
></uui-button>`
|
|
178
214
|
: nothing
|
|
179
215
|
}
|
|
180
|
-
</
|
|
216
|
+
</uui-action-bar>`
|
|
181
217
|
}
|
|
182
218
|
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
return
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
(
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
219
|
+
/** What a folder offers: a new item or folder in it, and, below the root, renaming or deleting it. */
|
|
220
|
+
#folderChoices(path) {
|
|
221
|
+
if (!this.#editable) return []
|
|
222
|
+
const go = (to) => () => window.history.pushState(null, '', url(to))
|
|
223
|
+
return [
|
|
224
|
+
{
|
|
225
|
+
label: `New ${this.#config.itemNoun}`,
|
|
226
|
+
icon: 'icon-add',
|
|
227
|
+
quick: true,
|
|
228
|
+
run: go(this.#config.create(path)),
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
label: 'New folder…',
|
|
232
|
+
icon: 'icon-folder',
|
|
233
|
+
run: () => {
|
|
234
|
+
this._asking = { verb: 'new', path }
|
|
235
|
+
},
|
|
236
|
+
},
|
|
237
|
+
...(path
|
|
238
|
+
? [
|
|
239
|
+
{
|
|
240
|
+
label: 'Rename…',
|
|
241
|
+
icon: 'icon-edit',
|
|
242
|
+
run: () => {
|
|
243
|
+
this._asking = { verb: 'rename', path }
|
|
244
|
+
},
|
|
245
|
+
},
|
|
246
|
+
{
|
|
247
|
+
label: 'Delete',
|
|
248
|
+
icon: 'icon-trash',
|
|
249
|
+
run: () => this.#send(() => this.#config.folder('DELETE', { path })),
|
|
250
|
+
},
|
|
251
|
+
]
|
|
252
|
+
: []),
|
|
253
|
+
]
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
/** What an item offers: moving it to another folder. */
|
|
257
|
+
#itemChoices(item) {
|
|
258
|
+
if (!this.#editable || (this._folders ?? []).length === 0) return []
|
|
259
|
+
return ['', ...this._folders]
|
|
260
|
+
.filter((folder) => folder !== (item.folder ?? ''))
|
|
261
|
+
.map((folder) => ({
|
|
262
|
+
label: folder ? `Move to ${folder}` : 'Move to the top',
|
|
263
|
+
icon: 'icon-enter',
|
|
264
|
+
run: () => this.#send(() => this.#config.move(item.alias, folder)),
|
|
265
|
+
}))
|
|
196
266
|
}
|
|
197
267
|
|
|
198
|
-
#
|
|
199
|
-
return
|
|
268
|
+
#idFor(kind, key) {
|
|
269
|
+
return `${kind}-${key.replace(/[^a-z0-9]/gi, '-')}`
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
#folder(node, label, href) {
|
|
273
|
+
const children = node.folders.length + node.items.length > 0
|
|
274
|
+
return html`<uui-menu-item
|
|
275
|
+
label=${label}
|
|
276
|
+
href=${href ?? nothing}
|
|
277
|
+
.hasChildren=${children}
|
|
278
|
+
.showChildren=${children && !this.#closed.has(node.path)}
|
|
279
|
+
?active=${href !== undefined && url(this.#config.root) === location.pathname}
|
|
280
|
+
@show-children=${() => this.#toggle(node.path, true)}
|
|
281
|
+
@hide-children=${() => this.#toggle(node.path, false)}
|
|
282
|
+
@click-label=${href ? nothing : () => this.#toggle(node.path, this.#closed.has(node.path))}
|
|
283
|
+
>
|
|
284
|
+
<umb-icon slot="icon" name="icon-folder"></umb-icon>
|
|
285
|
+
${this.#menu(this.#idFor('folder', node.path || 'root'), label, this.#folderChoices(node.path))}
|
|
200
286
|
${repeat(
|
|
201
287
|
node.folders,
|
|
202
288
|
(folder) => folder.path,
|
|
203
|
-
(folder) =>
|
|
204
|
-
<details open>
|
|
205
|
-
<summary><span>${folder.name}</span>${this.#folderActions(folder.path)}</summary>
|
|
206
|
-
${this.#items(folder)}
|
|
207
|
-
</details>
|
|
208
|
-
</li>`,
|
|
289
|
+
(folder) => this.#folder(folder, folder.name),
|
|
209
290
|
)}
|
|
210
291
|
${repeat(
|
|
211
292
|
node.items,
|
|
212
293
|
(item) => item.alias,
|
|
213
|
-
(item) =>
|
|
214
|
-
|
|
215
|
-
|
|
294
|
+
(item) => {
|
|
295
|
+
const href = url(this.#config.open(item))
|
|
296
|
+
return html`<uui-menu-item
|
|
297
|
+
label=${item.name}
|
|
298
|
+
href=${href}
|
|
299
|
+
?active=${`${location.pathname}${location.search}` === href}
|
|
300
|
+
>
|
|
301
|
+
<umb-icon slot="icon" name=${this.#config.icon}></umb-icon>
|
|
302
|
+
${this.#menu(this.#idFor('item', item.alias), item.name, this.#itemChoices(item))}
|
|
303
|
+
</uui-menu-item>`
|
|
304
|
+
},
|
|
216
305
|
)}
|
|
217
|
-
</
|
|
306
|
+
</uui-menu-item>`
|
|
218
307
|
}
|
|
219
308
|
|
|
220
309
|
render() {
|
|
221
310
|
if (!this._tree) return html`<uui-loader></uui-loader>`
|
|
222
311
|
const words = readOnlyWords(this.#config.label, this._because)
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
</div>
|
|
227
|
-
${this.#asking()}
|
|
312
|
+
this.#popovers = []
|
|
313
|
+
const tree = this.#folder(this._tree, this.#config.rootLabel, url(this.#config.root))
|
|
314
|
+
return html`${this.#asking()}
|
|
228
315
|
${this._problem ? html`<p class="problem" role="alert">${this._problem}</p>` : nothing}
|
|
229
316
|
${words ? html`<p class="note" role="status">${words}</p>` : nothing}
|
|
230
|
-
|
|
317
|
+
<uui-menu-item-list>${tree}</uui-menu-item-list>
|
|
318
|
+
${this.#popovers}`
|
|
231
319
|
}
|
|
232
320
|
|
|
233
321
|
static styles = css`
|
|
234
322
|
:host {
|
|
235
323
|
display: block;
|
|
236
|
-
padding: var(--uui-size-space-3) var(--uui-size-space-4);
|
|
237
|
-
}
|
|
238
|
-
a {
|
|
239
|
-
color: var(--uui-color-text);
|
|
240
|
-
text-decoration: none;
|
|
241
|
-
}
|
|
242
|
-
a:hover {
|
|
243
|
-
text-decoration: underline;
|
|
244
|
-
}
|
|
245
|
-
.root {
|
|
246
|
-
display: flex;
|
|
247
|
-
justify-content: space-between;
|
|
248
|
-
align-items: center;
|
|
249
|
-
font-weight: 700;
|
|
250
|
-
padding-bottom: var(--uui-size-space-2);
|
|
251
|
-
}
|
|
252
|
-
ul {
|
|
253
|
-
list-style: none;
|
|
254
|
-
margin: 0;
|
|
255
|
-
padding: 0 0 0 var(--uui-size-space-4);
|
|
256
|
-
}
|
|
257
|
-
:host > ul {
|
|
258
|
-
padding-left: 0;
|
|
259
|
-
}
|
|
260
|
-
li {
|
|
261
|
-
padding: var(--uui-size-space-1) 0;
|
|
262
|
-
}
|
|
263
|
-
.item {
|
|
264
|
-
display: flex;
|
|
265
|
-
justify-content: space-between;
|
|
266
|
-
gap: var(--uui-size-space-2);
|
|
267
|
-
}
|
|
268
|
-
summary {
|
|
269
|
-
display: flex;
|
|
270
|
-
justify-content: space-between;
|
|
271
|
-
cursor: pointer;
|
|
272
|
-
list-style-position: inside;
|
|
273
|
-
}
|
|
274
|
-
.actions {
|
|
275
|
-
display: inline-flex;
|
|
276
|
-
gap: var(--uui-size-space-1);
|
|
277
|
-
}
|
|
278
|
-
.actions button,
|
|
279
|
-
.actions a {
|
|
280
|
-
background: none;
|
|
281
|
-
border: 0;
|
|
282
|
-
padding: 0 var(--uui-size-space-1);
|
|
283
|
-
cursor: pointer;
|
|
284
|
-
color: var(--uui-color-text-alt);
|
|
285
|
-
font: inherit;
|
|
286
|
-
}
|
|
287
|
-
select {
|
|
288
|
-
max-width: 5rem;
|
|
289
|
-
font: inherit;
|
|
290
|
-
font-size: var(--uui-type-small-size);
|
|
291
|
-
color: var(--uui-color-text-alt);
|
|
292
|
-
background: none;
|
|
293
|
-
border: 0;
|
|
294
324
|
}
|
|
295
325
|
.ask {
|
|
296
326
|
display: flex;
|
|
297
327
|
flex-wrap: wrap;
|
|
298
328
|
gap: var(--uui-size-space-2);
|
|
299
|
-
padding
|
|
329
|
+
padding: var(--uui-size-space-2) var(--uui-size-space-4);
|
|
300
330
|
}
|
|
301
331
|
.ask input {
|
|
302
332
|
flex: 1 1 100%;
|
|
@@ -304,7 +334,8 @@ export default class CromboloDefinitionTreeElement extends UmbLitElement {
|
|
|
304
334
|
}
|
|
305
335
|
.note,
|
|
306
336
|
.problem {
|
|
307
|
-
margin: 0
|
|
337
|
+
margin: 0;
|
|
338
|
+
padding: var(--uui-size-space-2) var(--uui-size-space-4);
|
|
308
339
|
font-size: var(--uui-type-small-size);
|
|
309
340
|
line-height: 1.5;
|
|
310
341
|
color: var(--uui-color-text-alt);
|
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `{#key}` as a chip (story 297): the item's words in the default language, and
|
|
3
|
+
* an × that removes it. Clicking the words opens an overlay with the item's words
|
|
4
|
+
* in each language, which someone with Translation can change.
|
|
5
|
+
*/
|
|
6
|
+
import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
7
|
+
import {
|
|
8
|
+
dictionaryWord,
|
|
9
|
+
dictionaryWords,
|
|
10
|
+
saveDictionaryWord,
|
|
11
|
+
WORDS_CHANGED,
|
|
12
|
+
} from './dictionary-words-client.js'
|
|
13
|
+
|
|
14
|
+
export class CromboloDictionaryChipElement extends LitElement {
|
|
15
|
+
static properties = {
|
|
16
|
+
/** The item's name. */
|
|
17
|
+
name: { type: String },
|
|
18
|
+
readonly: { type: Boolean },
|
|
19
|
+
_text: { state: true },
|
|
20
|
+
_item: { state: true },
|
|
21
|
+
_language: { state: true },
|
|
22
|
+
_draft: { state: true },
|
|
23
|
+
_saving: { state: true },
|
|
24
|
+
_problem: { state: true },
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
#refresh = () => this.#loadText()
|
|
28
|
+
|
|
29
|
+
connectedCallback() {
|
|
30
|
+
super.connectedCallback()
|
|
31
|
+
window.addEventListener(WORDS_CHANGED, this.#refresh)
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
disconnectedCallback() {
|
|
35
|
+
super.disconnectedCallback()
|
|
36
|
+
window.removeEventListener(WORDS_CHANGED, this.#refresh)
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
willUpdate(changed) {
|
|
40
|
+
if (changed.has('name')) this.#loadText()
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
async #loadText() {
|
|
44
|
+
const name = (this.name ?? '').toLowerCase()
|
|
45
|
+
const word = (await dictionaryWords()).find((w) => w.name.toLowerCase() === name)
|
|
46
|
+
this._text = word?.text || word?.name || this.name
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
async #open() {
|
|
50
|
+
this._problem = undefined
|
|
51
|
+
this._item = undefined
|
|
52
|
+
this.renderRoot.querySelector('dialog')?.showModal()
|
|
53
|
+
const answer = await dictionaryWord(this.name)
|
|
54
|
+
if (!answer.ok) {
|
|
55
|
+
this._problem = answer.body.message ?? 'This dictionary item could not be read.'
|
|
56
|
+
return
|
|
57
|
+
}
|
|
58
|
+
this._item = answer.body
|
|
59
|
+
this._draft = Object.fromEntries(answer.body.languages.map((l) => [l.isoCode, l.text]))
|
|
60
|
+
this._language = answer.body.languages[0]?.isoCode
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
#close() {
|
|
64
|
+
this.renderRoot.querySelector('dialog')?.close()
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async #save() {
|
|
68
|
+
this._saving = true
|
|
69
|
+
const answer = await saveDictionaryWord(this.name, this._draft)
|
|
70
|
+
this._saving = false
|
|
71
|
+
if (!answer.ok) {
|
|
72
|
+
this._problem = answer.body.message ?? 'The words could not be saved.'
|
|
73
|
+
return
|
|
74
|
+
}
|
|
75
|
+
this.#close()
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
#remove(event) {
|
|
79
|
+
event.stopPropagation()
|
|
80
|
+
this.dispatchEvent(new CustomEvent('remove', { bubbles: true, composed: true }))
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
#overlay() {
|
|
84
|
+
const item = this._item
|
|
85
|
+
if (this._problem && !item) return html`<p role="alert">${this._problem}</p>`
|
|
86
|
+
if (!item) return html`<uui-loader></uui-loader>`
|
|
87
|
+
const language = item.languages.find((l) => l.isoCode === this._language) ?? item.languages[0]
|
|
88
|
+
return html`<uui-tab-group>
|
|
89
|
+
${item.languages.map(
|
|
90
|
+
(l) =>
|
|
91
|
+
html`<uui-tab
|
|
92
|
+
label=${l.name}
|
|
93
|
+
?active=${l.isoCode === language?.isoCode}
|
|
94
|
+
@click=${() => {
|
|
95
|
+
this._language = l.isoCode
|
|
96
|
+
}}
|
|
97
|
+
>${l.name}${l.isDefault ? ' (default)' : ''}</uui-tab
|
|
98
|
+
>`,
|
|
99
|
+
)}
|
|
100
|
+
</uui-tab-group>
|
|
101
|
+
${
|
|
102
|
+
language
|
|
103
|
+
? html`<uui-textarea
|
|
104
|
+
label=${`Words in ${language.name}`}
|
|
105
|
+
.value=${this._draft?.[language.isoCode] ?? ''}
|
|
106
|
+
?readonly=${!item.mayChange}
|
|
107
|
+
@input=${(event) => {
|
|
108
|
+
this._draft = { ...this._draft, [language.isoCode]: event.target.value }
|
|
109
|
+
}}
|
|
110
|
+
></uui-textarea>`
|
|
111
|
+
: html`<p>This site has no languages.</p>`
|
|
112
|
+
}
|
|
113
|
+
${
|
|
114
|
+
item.mayChange
|
|
115
|
+
? nothing
|
|
116
|
+
: html`<p class="note" role="status">
|
|
117
|
+
You can see these words. Changing the dictionary needs access to Translation.
|
|
118
|
+
</p>`
|
|
119
|
+
}
|
|
120
|
+
${this._problem ? html`<p role="alert">${this._problem}</p>` : nothing}`
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
render() {
|
|
124
|
+
const label = this._text ?? this.name
|
|
125
|
+
return html`<span class="chip">
|
|
126
|
+
<button type="button" class="words" title=${`From the dictionary: ${this.name}`} @click=${this.#open}>
|
|
127
|
+
<umb-icon name="icon-book-alt"></umb-icon>${label}
|
|
128
|
+
</button>
|
|
129
|
+
${
|
|
130
|
+
this.readonly
|
|
131
|
+
? nothing
|
|
132
|
+
: html`<button type="button" class="remove" aria-label=${`Remove ${this.name}`} @click=${this.#remove}>
|
|
133
|
+
×
|
|
134
|
+
</button>`
|
|
135
|
+
}
|
|
136
|
+
</span>
|
|
137
|
+
<dialog aria-label=${`Dictionary item ${this.name}`} @close=${() => {
|
|
138
|
+
this._item = undefined
|
|
139
|
+
}}>
|
|
140
|
+
<h3>${this.name}</h3>
|
|
141
|
+
${this.#overlay()}
|
|
142
|
+
<div class="actions">
|
|
143
|
+
<uui-button look="secondary" label="Close" @click=${this.#close}>Close</uui-button>
|
|
144
|
+
${
|
|
145
|
+
this._item?.mayChange
|
|
146
|
+
? html`<uui-button
|
|
147
|
+
look="primary"
|
|
148
|
+
color="positive"
|
|
149
|
+
label="Save"
|
|
150
|
+
.state=${this._saving ? 'waiting' : undefined}
|
|
151
|
+
@click=${this.#save}
|
|
152
|
+
>Save</uui-button
|
|
153
|
+
>`
|
|
154
|
+
: nothing
|
|
155
|
+
}
|
|
156
|
+
</div>
|
|
157
|
+
</dialog>`
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
static styles = css`
|
|
161
|
+
:host {
|
|
162
|
+
display: inline-block;
|
|
163
|
+
max-width: 100%;
|
|
164
|
+
}
|
|
165
|
+
.chip {
|
|
166
|
+
display: inline-flex;
|
|
167
|
+
align-items: stretch;
|
|
168
|
+
max-width: 100%;
|
|
169
|
+
border: 1px solid var(--uui-color-selected);
|
|
170
|
+
border-radius: var(--uui-border-radius);
|
|
171
|
+
background: var(--uui-color-surface-alt);
|
|
172
|
+
color: var(--uui-color-text);
|
|
173
|
+
font: inherit;
|
|
174
|
+
}
|
|
175
|
+
button {
|
|
176
|
+
font: inherit;
|
|
177
|
+
color: inherit;
|
|
178
|
+
background: none;
|
|
179
|
+
border: 0;
|
|
180
|
+
cursor: pointer;
|
|
181
|
+
}
|
|
182
|
+
.words {
|
|
183
|
+
display: inline-flex;
|
|
184
|
+
align-items: center;
|
|
185
|
+
gap: var(--uui-size-space-2);
|
|
186
|
+
padding: var(--uui-size-space-2) var(--uui-size-space-3);
|
|
187
|
+
overflow: hidden;
|
|
188
|
+
text-overflow: ellipsis;
|
|
189
|
+
white-space: nowrap;
|
|
190
|
+
}
|
|
191
|
+
.words:hover,
|
|
192
|
+
.remove:hover {
|
|
193
|
+
background: var(--uui-color-surface-emphasis);
|
|
194
|
+
}
|
|
195
|
+
.remove {
|
|
196
|
+
padding: 0 var(--uui-size-space-3);
|
|
197
|
+
border-left: 1px solid var(--uui-color-border);
|
|
198
|
+
font-size: 1.1em;
|
|
199
|
+
}
|
|
200
|
+
dialog {
|
|
201
|
+
width: min(36rem, calc(100vw - 2rem));
|
|
202
|
+
padding: var(--uui-size-space-5);
|
|
203
|
+
border: 1px solid var(--uui-color-border);
|
|
204
|
+
border-radius: var(--uui-border-radius);
|
|
205
|
+
background: var(--uui-color-surface);
|
|
206
|
+
color: var(--uui-color-text);
|
|
207
|
+
box-shadow: var(--uui-shadow-depth-5);
|
|
208
|
+
}
|
|
209
|
+
dialog::backdrop {
|
|
210
|
+
background: rgb(0 0 0 / 0.35);
|
|
211
|
+
}
|
|
212
|
+
h3 {
|
|
213
|
+
margin: 0 0 var(--uui-size-space-4);
|
|
214
|
+
}
|
|
215
|
+
uui-textarea {
|
|
216
|
+
width: 100%;
|
|
217
|
+
margin-top: var(--uui-size-space-4);
|
|
218
|
+
}
|
|
219
|
+
.note {
|
|
220
|
+
color: var(--uui-color-text-alt);
|
|
221
|
+
font-size: var(--uui-type-small-size);
|
|
222
|
+
}
|
|
223
|
+
.actions {
|
|
224
|
+
display: flex;
|
|
225
|
+
justify-content: flex-end;
|
|
226
|
+
gap: var(--uui-size-space-3);
|
|
227
|
+
margin-top: var(--uui-size-space-5);
|
|
228
|
+
}
|
|
229
|
+
`
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
if (!customElements.get('crombolo-dictionary-chip'))
|
|
233
|
+
customElements.define('crombolo-dictionary-chip', CromboloDictionaryChipElement)
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The dictionary as a `{#key}` chip reads and changes it (story 297), at
|
|
3
|
+
* <backoffice>/crombolo/api/dictionary/*. The session cookie carries the auth.
|
|
4
|
+
* The list is fetched once and shared, and fetched again after a change.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/** Sent on `window` after a word is saved, so every chip shows the new words. */
|
|
8
|
+
export const WORDS_CHANGED = 'crombolo:dictionary-words-changed'
|
|
9
|
+
|
|
10
|
+
const base = () => {
|
|
11
|
+
const href = document.querySelector('base')?.getAttribute('href') ?? '/umbraco/'
|
|
12
|
+
return `${href.replace(/\/$/, '')}/crombolo/api/dictionary`
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const call = async (path, init) => {
|
|
16
|
+
const response = await fetch(`${base()}${path}`, {
|
|
17
|
+
credentials: 'include',
|
|
18
|
+
headers: {
|
|
19
|
+
accept: 'application/json',
|
|
20
|
+
...(init?.body ? { 'content-type': 'application/json' } : {}),
|
|
21
|
+
},
|
|
22
|
+
...init,
|
|
23
|
+
})
|
|
24
|
+
const body = await response.json().catch(() => ({}))
|
|
25
|
+
return { ok: response.ok, status: response.status, body }
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
let listed
|
|
29
|
+
|
|
30
|
+
/** Every dictionary item, with its words in the default language. */
|
|
31
|
+
export const dictionaryWords = () => {
|
|
32
|
+
listed ??= call('/words')
|
|
33
|
+
.then((answer) => (answer.ok ? (answer.body.words ?? []) : []))
|
|
34
|
+
.catch(() => [])
|
|
35
|
+
return listed
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One item: its words in each language, and whether this user may change them. */
|
|
39
|
+
export const dictionaryWord = (name) => call(`/words/${encodeURIComponent(name)}`)
|
|
40
|
+
|
|
41
|
+
/** Saves an item's words, by language; a language left empty has none. */
|
|
42
|
+
export const saveDictionaryWord = async (name, words) => {
|
|
43
|
+
const answer = await call(`/words/${encodeURIComponent(name)}`, {
|
|
44
|
+
method: 'PUT',
|
|
45
|
+
body: JSON.stringify({ words }),
|
|
46
|
+
})
|
|
47
|
+
if (answer.ok) {
|
|
48
|
+
listed = undefined
|
|
49
|
+
window.dispatchEvent(new CustomEvent(WORDS_CHANGED, { detail: { name } }))
|
|
50
|
+
}
|
|
51
|
+
return answer
|
|
52
|
+
}
|