@crombolo/backoffice-host 0.51.1 → 0.53.2
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 +6 -8
- package/plugin/breadcrumb.js +6 -2
- package/plugin/content-home-dashboard.js +115 -0
- package/plugin/content-strip-items.js +65 -0
- package/plugin/content-strip.js +120 -0
- package/plugin/definition-tree-model.js +43 -0
- package/plugin/definition-tree.js +318 -0
- package/plugin/document-links.js +19 -0
- package/plugin/form-create-option.js +13 -0
- package/plugin/form-word-input-model.js +45 -0
- package/plugin/form-word-input.js +170 -0
- package/plugin/forms-client.js +21 -2
- package/plugin/forms-entries.js +77 -32
- package/plugin/forms-layout.js +6 -0
- package/plugin/forms-overview.js +200 -42
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/overview-dashboard.js +77 -7
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/session-guard-model.js +54 -0
- package/plugin/session-guard.js +50 -0
- package/plugin/settings-cards.js +14 -31
- package/plugin/settings-section.js +157 -16
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/theme-sync.js +69 -0
- package/plugin/tsx-editors.js +8 -5
- package/plugin/umbraco-package.json +132 -18
- package/plugin/view-parts.js +24 -0
- package/plugin/workflow-client.js +7 -2
- package/plugin/workflow-designer.js +44 -4
- package/src/paths.ts +1 -0
- package/plugin/theme-switch.js +0 -135
|
@@ -0,0 +1,318 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tree beside forms and workflows (story 289): their folders and their items,
|
|
3
|
+
* with making, renaming and moving, or a word saying why they cannot be changed.
|
|
4
|
+
* Forms' root opens every submission; a folder is a real folder of files.
|
|
5
|
+
*/
|
|
6
|
+
import { css, html, nothing, repeat } from '@umbraco-cms/backoffice/external/lit'
|
|
7
|
+
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
8
|
+
import { activeItem } from './content-strip-items.js'
|
|
9
|
+
import { definitionTree, readOnlyWords } from './definition-tree-model.js'
|
|
10
|
+
import { formsTree, moveForm, sendFormFolder } from './forms-client.js'
|
|
11
|
+
import { listWorkflows, moveWorkflow, sendWorkflowFolder } from './workflow-client.js'
|
|
12
|
+
|
|
13
|
+
const here = () => {
|
|
14
|
+
const base = new URL(document.baseURI).pathname
|
|
15
|
+
return location.pathname.startsWith(base) ? location.pathname.slice(base.length) : ''
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A form's screens, in Structure for those who have it, else in the Forms section. */
|
|
19
|
+
const formsAt = (view) =>
|
|
20
|
+
here().startsWith('section/settings')
|
|
21
|
+
? `section/settings/forms${view === 'entries' ? '/entries' : ''}`
|
|
22
|
+
: `section/forms/view/${view}`
|
|
23
|
+
|
|
24
|
+
const KINDS = {
|
|
25
|
+
Forms: {
|
|
26
|
+
label: 'Forms',
|
|
27
|
+
get root() {
|
|
28
|
+
return formsAt('entries')
|
|
29
|
+
},
|
|
30
|
+
rootLabel: 'Forms',
|
|
31
|
+
open: (item) => `${formsAt('forms')}?form=${encodeURIComponent(item.key)}`,
|
|
32
|
+
create: (folder) => `${formsAt('forms')}?new=${encodeURIComponent(folder)}`,
|
|
33
|
+
load: formsTree,
|
|
34
|
+
folder: sendFormFolder,
|
|
35
|
+
move: moveForm,
|
|
36
|
+
},
|
|
37
|
+
Workflows: {
|
|
38
|
+
label: 'Workflows',
|
|
39
|
+
root: 'section/forms/view/workflows',
|
|
40
|
+
rootLabel: 'Workflows',
|
|
41
|
+
open: (item) => `section/forms/view/workflows?workflow=${encodeURIComponent(item.alias)}`,
|
|
42
|
+
create: (folder) => `section/forms/view/workflows?new=${encodeURIComponent(folder)}`,
|
|
43
|
+
load: async () => {
|
|
44
|
+
const list = await listWorkflows()
|
|
45
|
+
return {
|
|
46
|
+
items: list.items ?? [],
|
|
47
|
+
folders: list.folders ?? [],
|
|
48
|
+
readOnlyBecause: list.readOnlyBecause,
|
|
49
|
+
}
|
|
50
|
+
},
|
|
51
|
+
folder: sendWorkflowFolder,
|
|
52
|
+
move: moveWorkflow,
|
|
53
|
+
},
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const url = (path) =>
|
|
57
|
+
new URL(path, document.baseURI).pathname + new URL(path, document.baseURI).search
|
|
58
|
+
|
|
59
|
+
export default class CromboloDefinitionTreeElement extends UmbLitElement {
|
|
60
|
+
static properties = {
|
|
61
|
+
/** The tree to show; without it, whichever the address belongs to. */
|
|
62
|
+
kind: { type: String },
|
|
63
|
+
_kind: { state: true },
|
|
64
|
+
_tree: { state: true },
|
|
65
|
+
_because: { state: true },
|
|
66
|
+
_asking: { state: true },
|
|
67
|
+
_problem: { state: true },
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
#follow = () => {
|
|
71
|
+
const kind = this.kind ?? (activeItem(here()) === 'Workflows' ? 'Workflows' : 'Forms')
|
|
72
|
+
if (kind === this._kind) return
|
|
73
|
+
this._kind = kind
|
|
74
|
+
this.#load()
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
#reload = () => this.#load()
|
|
78
|
+
|
|
79
|
+
connectedCallback() {
|
|
80
|
+
super.connectedCallback()
|
|
81
|
+
this.#follow()
|
|
82
|
+
window.addEventListener('changestate', this.#follow)
|
|
83
|
+
window.addEventListener('popstate', this.#follow)
|
|
84
|
+
window.addEventListener('crombolo:definitions-changed', this.#reload)
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
disconnectedCallback() {
|
|
88
|
+
super.disconnectedCallback()
|
|
89
|
+
window.removeEventListener('changestate', this.#follow)
|
|
90
|
+
window.removeEventListener('popstate', this.#follow)
|
|
91
|
+
window.removeEventListener('crombolo:definitions-changed', this.#reload)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get #config() {
|
|
95
|
+
return KINDS[this._kind]
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
async #load() {
|
|
99
|
+
const { items, folders, readOnlyBecause } = await this.#config.load()
|
|
100
|
+
this._tree = definitionTree(items, folders)
|
|
101
|
+
this._folders = folders
|
|
102
|
+
this._because = readOnlyBecause
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get #editable() {
|
|
106
|
+
return !this._because
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** A folder change, and what stopped it, if anything did. */
|
|
110
|
+
async #send(change) {
|
|
111
|
+
this._problem = undefined
|
|
112
|
+
const result = await change()
|
|
113
|
+
if (result.ok === false) this._problem = result.message ?? 'That could not be done.'
|
|
114
|
+
this._asking = undefined
|
|
115
|
+
await this.#load()
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
#submit(event) {
|
|
119
|
+
event.preventDefault()
|
|
120
|
+
const name = new FormData(event.target).get('name')?.toString().trim()
|
|
121
|
+
if (!name) return
|
|
122
|
+
const { verb, path } = this._asking
|
|
123
|
+
const parent = path.includes('/') ? path.slice(0, path.lastIndexOf('/')) : ''
|
|
124
|
+
if (verb === 'new') {
|
|
125
|
+
const target = path ? `${path}/${name}` : name
|
|
126
|
+
this.#send(() => this.#config.folder('POST', { path: target }))
|
|
127
|
+
} else {
|
|
128
|
+
const to = parent ? `${parent}/${name}` : name
|
|
129
|
+
this.#send(() => this.#config.folder('PUT', { from: path, to }))
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#asking() {
|
|
134
|
+
if (!this._asking) return nothing
|
|
135
|
+
return html`<form class="ask" @submit=${(event) => this.#submit(event)}>
|
|
136
|
+
<input
|
|
137
|
+
name="name"
|
|
138
|
+
aria-label="Folder name"
|
|
139
|
+
placeholder="Folder name"
|
|
140
|
+
.value=${this._asking.verb === 'rename' ? this._asking.path.split('/').pop() : ''}
|
|
141
|
+
autofocus
|
|
142
|
+
/>
|
|
143
|
+
<button type="submit">${this._asking.verb === 'rename' ? 'Rename' : 'Add'}</button>
|
|
144
|
+
<button type="button" @click=${() => {
|
|
145
|
+
this._asking = undefined
|
|
146
|
+
}}>Cancel</button>
|
|
147
|
+
</form>`
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
#folderActions(path) {
|
|
151
|
+
if (!this.#editable) return nothing
|
|
152
|
+
return html`<span class="actions">
|
|
153
|
+
<a href=${url(this.#config.create(path))} title="New in this folder" aria-label="New in this folder">+</a>
|
|
154
|
+
<button
|
|
155
|
+
type="button"
|
|
156
|
+
title="New folder"
|
|
157
|
+
aria-label="New folder"
|
|
158
|
+
@click=${() => {
|
|
159
|
+
this._asking = { verb: 'new', path }
|
|
160
|
+
}}
|
|
161
|
+
>▸</button>
|
|
162
|
+
${
|
|
163
|
+
path
|
|
164
|
+
? html`<button
|
|
165
|
+
type="button"
|
|
166
|
+
title="Rename"
|
|
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>`
|
|
178
|
+
: nothing
|
|
179
|
+
}
|
|
180
|
+
</span>`
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
#move(item) {
|
|
184
|
+
if (!this.#editable || (this._folders ?? []).length === 0) return nothing
|
|
185
|
+
return html`<select
|
|
186
|
+
aria-label="Move to a folder"
|
|
187
|
+
title="Move to a folder"
|
|
188
|
+
@change=${(event) => this.#send(() => this.#config.move(item.alias, event.target.value))}
|
|
189
|
+
>
|
|
190
|
+
<option value="" ?selected=${!item.folder}>Top</option>
|
|
191
|
+
${this._folders.map(
|
|
192
|
+
(folder) =>
|
|
193
|
+
html`<option value=${folder} ?selected=${folder === item.folder}>${folder}</option>`,
|
|
194
|
+
)}
|
|
195
|
+
</select>`
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
#items(node) {
|
|
199
|
+
return html`<ul>
|
|
200
|
+
${repeat(
|
|
201
|
+
node.folders,
|
|
202
|
+
(folder) => folder.path,
|
|
203
|
+
(folder) => html`<li>
|
|
204
|
+
<details open>
|
|
205
|
+
<summary><span>${folder.name}</span>${this.#folderActions(folder.path)}</summary>
|
|
206
|
+
${this.#items(folder)}
|
|
207
|
+
</details>
|
|
208
|
+
</li>`,
|
|
209
|
+
)}
|
|
210
|
+
${repeat(
|
|
211
|
+
node.items,
|
|
212
|
+
(item) => item.alias,
|
|
213
|
+
(item) => html`<li class="item">
|
|
214
|
+
<a href=${url(this.#config.open(item))}>${item.name}</a>${this.#move(item)}
|
|
215
|
+
</li>`,
|
|
216
|
+
)}
|
|
217
|
+
</ul>`
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
render() {
|
|
221
|
+
if (!this._tree) return html`<uui-loader></uui-loader>`
|
|
222
|
+
const words = readOnlyWords(this.#config.label, this._because)
|
|
223
|
+
return html`<div class="root">
|
|
224
|
+
<a href=${url(this.#config.root)}>${this.#config.rootLabel}</a>
|
|
225
|
+
${this.#folderActions('')}
|
|
226
|
+
</div>
|
|
227
|
+
${this.#asking()}
|
|
228
|
+
${this._problem ? html`<p class="problem" role="alert">${this._problem}</p>` : nothing}
|
|
229
|
+
${words ? html`<p class="note" role="status">${words}</p>` : nothing}
|
|
230
|
+
${this.#items(this._tree)}`
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
static styles = css`
|
|
234
|
+
:host {
|
|
235
|
+
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
|
+
}
|
|
295
|
+
.ask {
|
|
296
|
+
display: flex;
|
|
297
|
+
flex-wrap: wrap;
|
|
298
|
+
gap: var(--uui-size-space-2);
|
|
299
|
+
padding-bottom: var(--uui-size-space-2);
|
|
300
|
+
}
|
|
301
|
+
.ask input {
|
|
302
|
+
flex: 1 1 100%;
|
|
303
|
+
font: inherit;
|
|
304
|
+
}
|
|
305
|
+
.note,
|
|
306
|
+
.problem {
|
|
307
|
+
margin: 0 0 var(--uui-size-space-3);
|
|
308
|
+
font-size: var(--uui-type-small-size);
|
|
309
|
+
line-height: 1.5;
|
|
310
|
+
color: var(--uui-color-text-alt);
|
|
311
|
+
}
|
|
312
|
+
.problem {
|
|
313
|
+
color: var(--uui-color-danger);
|
|
314
|
+
}
|
|
315
|
+
`
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
customElements.define('crombolo-definition-tree', CromboloDefinitionTreeElement)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* From a page to what defines it (story 289): its content type or its template,
|
|
3
|
+
* as a tree action, for whoever may open Settings, where those live.
|
|
4
|
+
*/
|
|
5
|
+
import { UmbDocumentDetailRepository } from '@umbraco-cms/backoffice/document'
|
|
6
|
+
import { UmbEntityActionBase } from '@umbraco-cms/backoffice/entity-action'
|
|
7
|
+
|
|
8
|
+
class CromboloDocumentLinkAction extends UmbEntityActionBase {
|
|
9
|
+
async execute() {
|
|
10
|
+
const target = this.args.meta.target
|
|
11
|
+
const { data } = await new UmbDocumentDetailRepository(this).requestByUnique(this.args.unique)
|
|
12
|
+
const unique = target === 'template' ? data?.template?.unique : data?.documentType?.unique
|
|
13
|
+
if (!unique) return
|
|
14
|
+
const path = `section/settings/workspace/${target}/edit/${unique}`
|
|
15
|
+
history.pushState(null, '', new URL(path, document.baseURI).pathname)
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { CromboloDocumentLinkAction as api }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form, in the Create menu of Content Types: forms sit beside content types in
|
|
3
|
+
* Structure, so a new one starts from the same place. It is saved under Forms.
|
|
4
|
+
*/
|
|
5
|
+
import { UmbEntityCreateOptionActionBase } from '@umbraco-cms/backoffice/entity-create-option-action'
|
|
6
|
+
|
|
7
|
+
export class CromboloFormCreateOptionAction extends UmbEntityCreateOptionActionBase {
|
|
8
|
+
async getHref() {
|
|
9
|
+
return 'section/settings/forms?new='
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { CromboloFormCreateOptionAction as api }
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the form editor's text boxes suggest (story 294). Pure, so each is tested
|
|
3
|
+
* on its own.
|
|
4
|
+
*/
|
|
5
|
+
const ROWS = 8
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The dictionary items to offer for what has been typed: names starting with it
|
|
9
|
+
* first, then those containing it, then those whose words do. Only after a `#`.
|
|
10
|
+
*
|
|
11
|
+
* @param {{ name: string, text: string }[]} words
|
|
12
|
+
* @param {string} value
|
|
13
|
+
*/
|
|
14
|
+
export function suggestions(words, value) {
|
|
15
|
+
if (!/^#\S*$/.test(value)) return { rows: [], more: false }
|
|
16
|
+
const typed = value.slice(1).toLowerCase()
|
|
17
|
+
const rank = ({ name, text }) => {
|
|
18
|
+
const lower = name.toLowerCase()
|
|
19
|
+
if (lower.startsWith(typed)) return 0
|
|
20
|
+
if (lower.includes(typed)) return 1
|
|
21
|
+
return text.toLowerCase().includes(typed) ? 2 : 3
|
|
22
|
+
}
|
|
23
|
+
const matching = words
|
|
24
|
+
.map((word) => ({ word, rank: rank(word) }))
|
|
25
|
+
.filter((found) => found.rank < 3)
|
|
26
|
+
.sort((a, b) => a.rank - b.rank || a.word.name.localeCompare(b.word.name))
|
|
27
|
+
.map((found) => found.word)
|
|
28
|
+
return { rows: matching.slice(0, ROWS), more: matching.length > ROWS }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* What goes under a box: what a `#name` reads as, or that nothing has that name.
|
|
33
|
+
* Nothing for ordinary text, or when `#` starts a few words, or before the list has loaded.
|
|
34
|
+
*
|
|
35
|
+
* @param {{ name: string, text: string }[] | undefined} words
|
|
36
|
+
* @param {string} value
|
|
37
|
+
*/
|
|
38
|
+
export function wordLine(words, value) {
|
|
39
|
+
if (!words || !/^#\S+$/.test(value)) return undefined
|
|
40
|
+
const name = value.slice(1).toLowerCase()
|
|
41
|
+
const word = words.find((candidate) => candidate.name.toLowerCase() === name)
|
|
42
|
+
return word
|
|
43
|
+
? `From the dictionary: ${word.text || word.name}`
|
|
44
|
+
: 'No dictionary item has this name, so it shows as written.'
|
|
45
|
+
}
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A form text that can name a dictionary item (story 294): typing `#` offers the
|
|
3
|
+
* items, and what one reads as shows underneath. It sends `change`, with `value`,
|
|
4
|
+
* as `uui-input` does. The list is a popover so a table cell doesn't clip it.
|
|
5
|
+
*/
|
|
6
|
+
import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
7
|
+
import { suggestions, wordLine } from './form-word-input-model.js'
|
|
8
|
+
|
|
9
|
+
export default class CromboloFormWordInputElement extends LitElement {
|
|
10
|
+
static properties = {
|
|
11
|
+
label: { type: String },
|
|
12
|
+
placeholder: { type: String },
|
|
13
|
+
value: { type: String },
|
|
14
|
+
readonly: { type: Boolean },
|
|
15
|
+
words: { attribute: false },
|
|
16
|
+
_open: { state: true },
|
|
17
|
+
_active: { state: true },
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
constructor() {
|
|
21
|
+
super()
|
|
22
|
+
this.value = ''
|
|
23
|
+
this.words = []
|
|
24
|
+
this._open = false
|
|
25
|
+
this._active = 0
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
get #found() {
|
|
29
|
+
return this.readonly ? { rows: [], more: false } : suggestions(this.words ?? [], this.value)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
#choose(word) {
|
|
33
|
+
this.value = `#${word.name}`
|
|
34
|
+
this._open = false
|
|
35
|
+
this.#changed()
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
#changed() {
|
|
39
|
+
this.dispatchEvent(new Event('change', { bubbles: true }))
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
#onInput(event) {
|
|
43
|
+
event.stopPropagation()
|
|
44
|
+
this.value = event.target.value ?? ''
|
|
45
|
+
this._active = 0
|
|
46
|
+
this._open = this.#found.rows.length > 0
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
#onKeydown(event) {
|
|
50
|
+
const { rows } = this.#found
|
|
51
|
+
if (!this._open || rows.length === 0) return
|
|
52
|
+
if (event.key === 'Escape') {
|
|
53
|
+
event.stopPropagation()
|
|
54
|
+
this._open = false
|
|
55
|
+
} else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
|
|
56
|
+
event.preventDefault()
|
|
57
|
+
const step = event.key === 'ArrowDown' ? 1 : rows.length - 1
|
|
58
|
+
this._active = (this._active + step) % rows.length
|
|
59
|
+
} else if (event.key === 'Enter') {
|
|
60
|
+
event.preventDefault()
|
|
61
|
+
this.#choose(rows[this._active] ?? rows[0])
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
updated() {
|
|
66
|
+
const list = this.renderRoot.querySelector('[popover]')
|
|
67
|
+
if (!list) return
|
|
68
|
+
const box = this.renderRoot.querySelector('uui-input').getBoundingClientRect()
|
|
69
|
+
list.style.top = `${box.bottom + 2}px`
|
|
70
|
+
list.style.left = `${box.left}px`
|
|
71
|
+
list.style.minWidth = `${box.width}px`
|
|
72
|
+
list.showPopover()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
render() {
|
|
76
|
+
const { rows, more } = this.#found
|
|
77
|
+
const line = wordLine(this.words, this.value)
|
|
78
|
+
const open = this._open && rows.length > 0
|
|
79
|
+
return html`<uui-input
|
|
80
|
+
label=${this.label}
|
|
81
|
+
placeholder=${this.placeholder ?? ''}
|
|
82
|
+
.value=${this.value ?? ''}
|
|
83
|
+
?readonly=${this.readonly}
|
|
84
|
+
@input=${this.#onInput}
|
|
85
|
+
@keydown=${this.#onKeydown}
|
|
86
|
+
@change=${(event) => {
|
|
87
|
+
event.stopPropagation()
|
|
88
|
+
this.#changed()
|
|
89
|
+
}}
|
|
90
|
+
@blur=${() => {
|
|
91
|
+
this._open = false
|
|
92
|
+
}}
|
|
93
|
+
></uui-input>
|
|
94
|
+
${line ? html`<p class="word">${line}</p>` : nothing}
|
|
95
|
+
<span class="status" role="status"
|
|
96
|
+
>${open ? `${rows.length} dictionary items. Use the arrow keys to choose one.` : ''}</span
|
|
97
|
+
>
|
|
98
|
+
${
|
|
99
|
+
open
|
|
100
|
+
? html`<div popover="manual" role="listbox" aria-label="Dictionary items">
|
|
101
|
+
${rows.map(
|
|
102
|
+
(word, index) => html`<div
|
|
103
|
+
role="option"
|
|
104
|
+
aria-selected=${index === this._active ? 'true' : 'false'}
|
|
105
|
+
@pointerdown=${(event) => {
|
|
106
|
+
event.preventDefault()
|
|
107
|
+
this.#choose(word)
|
|
108
|
+
}}
|
|
109
|
+
>
|
|
110
|
+
<strong>${word.name}</strong> <span>${word.text}</span>
|
|
111
|
+
</div>`,
|
|
112
|
+
)}
|
|
113
|
+
${more ? html`<p class="more">Keep typing to narrow this down.</p>` : nothing}
|
|
114
|
+
</div>`
|
|
115
|
+
: nothing
|
|
116
|
+
}`
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
static styles = css`
|
|
120
|
+
:host {
|
|
121
|
+
display: block;
|
|
122
|
+
}
|
|
123
|
+
uui-input {
|
|
124
|
+
width: 100%;
|
|
125
|
+
}
|
|
126
|
+
.word {
|
|
127
|
+
margin: var(--uui-size-space-1) 0 0;
|
|
128
|
+
color: var(--uui-color-text-alt);
|
|
129
|
+
font-size: var(--uui-type-small-size);
|
|
130
|
+
}
|
|
131
|
+
.status {
|
|
132
|
+
position: absolute;
|
|
133
|
+
width: 1px;
|
|
134
|
+
height: 1px;
|
|
135
|
+
overflow: hidden;
|
|
136
|
+
clip-path: inset(50%);
|
|
137
|
+
}
|
|
138
|
+
[popover] {
|
|
139
|
+
position: fixed;
|
|
140
|
+
inset: auto;
|
|
141
|
+
margin: 0;
|
|
142
|
+
padding: var(--uui-size-space-1);
|
|
143
|
+
max-width: 28rem;
|
|
144
|
+
background: var(--uui-color-surface);
|
|
145
|
+
color: var(--uui-color-text);
|
|
146
|
+
border: 1px solid var(--uui-color-border);
|
|
147
|
+
border-radius: var(--uui-border-radius);
|
|
148
|
+
box-shadow: var(--uui-shadow-depth-3);
|
|
149
|
+
}
|
|
150
|
+
[role='option'] {
|
|
151
|
+
padding: var(--uui-size-space-2) var(--uui-size-space-3);
|
|
152
|
+
border-radius: var(--uui-border-radius);
|
|
153
|
+
cursor: pointer;
|
|
154
|
+
}
|
|
155
|
+
[role='option'] span {
|
|
156
|
+
color: var(--uui-color-text-alt);
|
|
157
|
+
}
|
|
158
|
+
[role='option'][aria-selected='true'],
|
|
159
|
+
[role='option']:hover {
|
|
160
|
+
background: var(--uui-color-surface-emphasis);
|
|
161
|
+
}
|
|
162
|
+
.more {
|
|
163
|
+
margin: var(--uui-size-space-1) var(--uui-size-space-3);
|
|
164
|
+
color: var(--uui-color-text-alt);
|
|
165
|
+
font-size: var(--uui-type-small-size);
|
|
166
|
+
}
|
|
167
|
+
`
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
customElements.define('crombolo-form-word-input', CromboloFormWordInputElement)
|
package/plugin/forms-client.js
CHANGED
|
@@ -27,6 +27,19 @@ const call = async (path, init) => {
|
|
|
27
27
|
|
|
28
28
|
export const listForms = async () => (await call('')).body.items ?? []
|
|
29
29
|
|
|
30
|
+
/** The forms with their folders, and why they cannot be changed here, if they cannot. */
|
|
31
|
+
export const formsTree = async () => (await call('')).body
|
|
32
|
+
|
|
33
|
+
const treeCall = async (path, method, body) => {
|
|
34
|
+
const result = await call(path, { method, body: JSON.stringify(body) })
|
|
35
|
+
return { ok: result.ok, message: result.body.message }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** A folder made (`POST`), renamed (`PUT`) or deleted (`DELETE`). */
|
|
39
|
+
export const sendFormFolder = (method, body) => treeCall('/tree-folders', method, body)
|
|
40
|
+
|
|
41
|
+
export const moveForm = (alias, folder) => treeCall('/tree-move', 'POST', { alias, folder })
|
|
42
|
+
|
|
30
43
|
/** The content types made from forms (story 239), by key, with each form's name. */
|
|
31
44
|
export const listLibraryTypes = async () => (await call('/library-types')).body.items ?? []
|
|
32
45
|
|
|
@@ -41,13 +54,19 @@ export const listEmailTemplates = async () => (await call('/email-templates')).b
|
|
|
41
54
|
|
|
42
55
|
export const readForm = async (key) => (await call(`/${encodeURIComponent(key)}`)).body
|
|
43
56
|
|
|
44
|
-
export const saveForm = (definition) =>
|
|
45
|
-
call(
|
|
57
|
+
export const saveForm = (definition, folder) =>
|
|
58
|
+
call(folder ? `?folder=${encodeURIComponent(folder)}` : '', {
|
|
59
|
+
method: 'PUT',
|
|
60
|
+
body: JSON.stringify(definition),
|
|
61
|
+
})
|
|
46
62
|
|
|
47
63
|
/** The options a choice source offers right now, as a visitor would see them. */
|
|
48
64
|
export const previewChoices = (source) =>
|
|
49
65
|
call('/choices', { method: 'POST', body: JSON.stringify({ source }) })
|
|
50
66
|
|
|
67
|
+
/** Every dictionary item, with its words in the default language. */
|
|
68
|
+
export const listWords = async () => (await call('/words')).body.words ?? []
|
|
69
|
+
|
|
51
70
|
export const deleteForm = (key) => call(`/${encodeURIComponent(key)}`, { method: 'DELETE' })
|
|
52
71
|
|
|
53
72
|
export const listEntries = async (key, query = {}) => {
|