@crombolo/backoffice-host 0.54.1 → 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 CHANGED
@@ -245,7 +245,7 @@ class CromboloLoginElement extends LitElement {
245
245
  <form @submit=${this.#verifyTwoFactor}>
246
246
  <uui-form-layout-item>
247
247
  <uui-label for="code" slot="label" required>Code</uui-label>
248
- <uui-input id="code" name="code" autocomplete="one-time-code" required ?disabled=${this._busy}></uui-input>
248
+ <uui-input id="code" label="Code" name="code" autocomplete="one-time-code" required ?disabled=${this._busy}></uui-input>
249
249
  </uui-form-layout-item>
250
250
  ${this.#messages()}
251
251
  <uui-button type="submit" look="primary" color="positive" .state=${this._busy ? 'waiting' : undefined} label="Verify"></uui-button>
@@ -268,11 +268,11 @@ class CromboloLoginElement extends LitElement {
268
268
  <form @submit=${this.#setPassword}>
269
269
  <uui-form-layout-item>
270
270
  <uui-label for="password" slot="label" required>Password</uui-label>
271
- <uui-input id="password" name="password" type="password" autocomplete="new-password" required></uui-input>
271
+ <uui-input id="password" label="Password" name="password" type="password" autocomplete="new-password" required></uui-input>
272
272
  </uui-form-layout-item>
273
273
  <uui-form-layout-item>
274
274
  <uui-label for="confirm" slot="label" required>Confirm password</uui-label>
275
- <uui-input id="confirm" name="confirm" type="password" autocomplete="new-password" required></uui-input>
275
+ <uui-input id="confirm" label="Confirm password" name="confirm" type="password" autocomplete="new-password" required></uui-input>
276
276
  </uui-form-layout-item>
277
277
  ${this.#messages()}
278
278
  <uui-button type="submit" look="primary" color="positive" .state=${this._busy ? 'waiting' : undefined} label="Set password"></uui-button>
@@ -286,7 +286,7 @@ class CromboloLoginElement extends LitElement {
286
286
  <form @submit=${this.#requestReset}>
287
287
  <uui-form-layout-item>
288
288
  <uui-label for="email" slot="label" required>Email</uui-label>
289
- <uui-input id="email" name="email" type="email" autocomplete="email" required></uui-input>
289
+ <uui-input id="email" label="Email" name="email" type="email" autocomplete="email" required></uui-input>
290
290
  </uui-form-layout-item>
291
291
  ${this.#messages()}
292
292
  <uui-button type="submit" look="primary" .state=${this._busy ? 'waiting' : undefined} label="Send reset link"></uui-button>
@@ -346,6 +346,7 @@ class CromboloLoginElement extends LitElement {
346
346
  </uui-label>
347
347
  <uui-input
348
348
  id="username"
349
+ label=${this.usernameIsEmail ? 'Email' : 'Username'}
349
350
  name="username"
350
351
  type=${this.usernameIsEmail ? 'email' : 'text'}
351
352
  autocomplete="username"
@@ -357,6 +358,7 @@ class CromboloLoginElement extends LitElement {
357
358
  <uui-label for="password" slot="label" required>Password</uui-label>
358
359
  <uui-input
359
360
  id="password"
361
+ label="Password"
360
362
  name="password"
361
363
  type="password"
362
364
  autocomplete="current-password"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/backoffice-host",
3
- "version": "0.54.1",
3
+ "version": "0.55.0",
4
4
  "description": "Internal to crombolo, with no compatibility promise: use @crombolo/crombolo. Serves the Umbraco backoffice SPA: shell HTML, import map and package manifests.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -32,7 +32,7 @@
32
32
  "access": "public"
33
33
  },
34
34
  "dependencies": {
35
- "@crombolo/core": "0.54.1",
36
- "@crombolo/backoffice-dist": "0.54.1"
35
+ "@crombolo/core": "0.55.0",
36
+ "@crombolo/backoffice-dist": "0.55.0"
37
37
  }
38
38
  }
@@ -0,0 +1,85 @@
1
+ /**
2
+ * An alias beside a name, locked as Umbraco's own editors lock it: while locked
3
+ * it shows what the editor gave it, which for something new follows its name.
4
+ * The lock opens it to be written by hand; for something already saved, it says
5
+ * what that changes. It sends `change` with `value`, as `uui-input` does.
6
+ */
7
+ import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
8
+
9
+ export class CromboloAliasInputElement extends LitElement {
10
+ static properties = {
11
+ value: { type: String },
12
+ label: { type: String },
13
+ readonly: { type: Boolean },
14
+ /** Saved already: changing the alias by hand breaks what names it. */
15
+ saved: { type: Boolean },
16
+ _unlocked: { state: true },
17
+ }
18
+
19
+ constructor() {
20
+ super()
21
+ this.value = ''
22
+ this.label = 'Alias'
23
+ this._unlocked = false
24
+ }
25
+
26
+ #toggle() {
27
+ this._unlocked = !this._unlocked
28
+ if (this._unlocked)
29
+ this.updateComplete.then(() => this.renderRoot.querySelector('uui-input')?.focus())
30
+ }
31
+
32
+ render() {
33
+ const locked = this.readonly || !this._unlocked
34
+ return html`<uui-input
35
+ label=${this.label}
36
+ .value=${this.value ?? ''}
37
+ ?readonly=${locked}
38
+ @change=${(event) => {
39
+ event.stopPropagation()
40
+ this.value = event.target.value.trim()
41
+ this.dispatchEvent(new Event('change', { bubbles: true }))
42
+ }}
43
+ >
44
+ ${
45
+ this.readonly
46
+ ? nothing
47
+ : html`<uui-button
48
+ slot="prepend"
49
+ compact
50
+ label=${locked ? `Unlock ${this.label} to change it` : `Lock ${this.label}`}
51
+ @click=${this.#toggle}
52
+ >
53
+ <umb-icon name=${locked ? 'icon-lock' : 'icon-unlocked'}></umb-icon>
54
+ </uui-button>`
55
+ }
56
+ </uui-input>
57
+ ${
58
+ this._unlocked && this.saved
59
+ ? html`<p class="warning" role="status">
60
+ Anything that uses the old alias stops finding this once it is saved.
61
+ </p>`
62
+ : nothing
63
+ }`
64
+ }
65
+
66
+ static styles = css`
67
+ :host {
68
+ display: block;
69
+ }
70
+ uui-input {
71
+ width: 100%;
72
+ }
73
+ uui-input[readonly] {
74
+ color: var(--uui-color-text-alt);
75
+ }
76
+ .warning {
77
+ margin: var(--uui-size-space-1) 0 0;
78
+ color: var(--uui-color-warning-standalone, var(--uui-color-warning));
79
+ font-size: var(--uui-type-small-size);
80
+ }
81
+ `
82
+ }
83
+
84
+ if (!customElements.get('crombolo-alias-input'))
85
+ customElements.define('crombolo-alias-input', CromboloAliasInputElement)
@@ -0,0 +1,36 @@
1
+ /**
2
+ * An alias made from a name, as Umbraco's editors make one: for a form and its
3
+ * fields, letters and digits in camel case (`visitorName`); for a workflow and
4
+ * its stages, the words of its file name (`policy-sign-off`). A caption naming
5
+ * a dictionary item, `{#contact.name}`, gives the item's name. Pure.
6
+ */
7
+
8
+ /** The words a name is made of: a dictionary item's name for `{#key}` or `#key`. */
9
+ function wordsOf(text) {
10
+ return (
11
+ (text ?? '')
12
+ .replace(/\{#([^{}\s]+)\}/g, ' $1 ')
13
+ .replace(/^#(\S+)$/, '$1')
14
+ .match(/[A-Z]{2,}(?=[A-Z][a-z]+[0-9]*|\b)|[A-Z]?[a-z]+[0-9]*|[A-Z]|[0-9]+/g) ?? []
15
+ )
16
+ }
17
+
18
+ /** `Visitor name` → `visitorName`; it starts with a letter, or is empty. */
19
+ export function camelAlias(text) {
20
+ const words = wordsOf(text)
21
+ while (words.length > 0 && /^[0-9]/.test(words[0])) words.shift()
22
+ return words
23
+ .map((word, index) =>
24
+ index === 0
25
+ ? word.toLowerCase()
26
+ : word.slice(0, 1).toUpperCase() + word.slice(1).toLowerCase(),
27
+ )
28
+ .join('')
29
+ }
30
+
31
+ /** `Policy sign-off` → `policy-sign-off`. */
32
+ export function kebabAlias(text) {
33
+ return wordsOf(text)
34
+ .map((word) => word.toLowerCase())
35
+ .join('-')
36
+ }
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo App Preview",
4
4
  "id": "Crombolo.AppPreview",
5
- "version": "0.54.1",
5
+ "version": "0.55.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,21 @@
1
+ /**
2
+ * What the tree beside Approvals lists under Pending (`approvals-tree.js`): every
3
+ * request still pending, those waiting on the reader first and marked so, each
4
+ * group in the order the requests were sent. Pure.
5
+ */
6
+
7
+ /**
8
+ * @param {{ key: string, state: string }[] | undefined} pending every request in flight
9
+ * @param {{ key: string }[] | undefined} mine those waiting on a stage the reader may decide
10
+ * @returns {Array<{ key: string, mine: boolean }>}
11
+ */
12
+ export function pendingForTree(pending, mine) {
13
+ const waitingOnMe = new Set((mine ?? []).map((request) => request.key))
14
+ const open = (pending ?? []).filter(
15
+ (request) => request.state === 'waiting' || request.state === 'scheduled',
16
+ )
17
+ return [
18
+ ...open.filter((request) => waitingOnMe.has(request.key)),
19
+ ...open.filter((request) => !waitingOnMe.has(request.key)),
20
+ ].map((request) => ({ ...request, mine: waitingOnMe.has(request.key) }))
21
+ }
@@ -1,20 +1,15 @@
1
1
  /**
2
- * The tree beside Approvals: a folder of the requests waiting for the reader, and
3
- * one of the latest decided. Each request opens its page's Workflow tab, where
4
- * it is acted on.
2
+ * The tree beside Approvals: one folder, Pending, of every request still waiting
3
+ * for a decision or its time, those waiting on the reader first and marked so.
4
+ * Each opens its page's Workflow tab, where it is acted on.
5
5
  */
6
6
  import { css, html } from '@umbraco-cms/backoffice/external/lit'
7
7
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
- import { finished, waitingForMe } from './workflow-client.js'
8
+ import { pendingForTree } from './approvals-tree-model.js'
9
+ import { inFlight, waitingForMe } from './workflow-client.js'
9
10
  import { pageLink } from './workflow-requests.js'
10
11
 
11
- /** How many of the decided the tree shows: the list has the rest. */
12
- const DECIDED_SHOWN = 25
13
-
14
- const FOLDERS = [
15
- { id: 'waiting', label: 'Waiting for me', load: () => waitingForMe() },
16
- { id: 'decided', label: 'Decided', load: () => finished(0, DECIDED_SHOWN) },
17
- ]
12
+ const PENDING = 'pending'
18
13
 
19
14
  export default class CromboloApprovalsTreeElement extends UmbLitElement {
20
15
  static properties = {
@@ -42,10 +37,11 @@ export default class CromboloApprovalsTreeElement extends UmbLitElement {
42
37
  }
43
38
 
44
39
  async #load() {
45
- const answers = await Promise.all(FOLDERS.map((folder) => folder.load().catch(() => undefined)))
46
- this._items = Object.fromEntries(
47
- FOLDERS.map((folder, index) => [folder.id, answers[index]?.items ?? []]),
48
- )
40
+ const [pending, mine] = await Promise.all([
41
+ inFlight().catch(() => undefined),
42
+ waitingForMe().catch(() => undefined),
43
+ ])
44
+ this._items = pendingForTree(pending?.items, mine?.items)
49
45
  }
50
46
 
51
47
  #toggle(id, open) {
@@ -59,35 +55,42 @@ export default class CromboloApprovalsTreeElement extends UmbLitElement {
59
55
  // Headed as Umbraco's sidebar menus are, Structure's among them.
60
56
  const header = html`<h3>Approvals</h3>`
61
57
  if (!this._items) return html`${header}<uui-loader></uui-loader>`
58
+ const items = this._items
59
+ const open = items.length > 0 && !this._closed.has(PENDING)
62
60
  return html`${header}<uui-menu-item-list>
63
- ${FOLDERS.map((folder) => {
64
- const items = this._items[folder.id]
65
- return html`<uui-menu-item
66
- label=${folder.label}
67
- .hasChildren=${items.length > 0}
68
- .showChildren=${items.length > 0 && !this._closed.has(folder.id)}
69
- @show-children=${() => this.#toggle(folder.id, true)}
70
- @hide-children=${() => this.#toggle(folder.id, false)}
71
- @click-label=${() => this.#toggle(folder.id, this._closed.has(folder.id))}
72
- >
73
- <umb-icon slot="icon" name="icon-folder"></umb-icon>
74
- ${items.map((request) => {
75
- const href = pageLink(request)
76
- return html`<uui-menu-item
77
- label=${request.nodeName}
78
- href=${href}
79
- ?active=${location.pathname === new URL(href, location.href).pathname}
80
- title=${`${request.workflow.name}: ${request.action === 'unpublish' ? 'taking it down' : 'publishing'}`}
81
- >
82
- <umb-icon slot="icon" name="icon-document"></umb-icon>
83
- </uui-menu-item>`
84
- })}
85
- </uui-menu-item>`
86
- })}
61
+ <uui-menu-item
62
+ label="Pending"
63
+ .hasChildren=${items.length > 0}
64
+ .showChildren=${open}
65
+ @show-children=${() => this.#toggle(PENDING, true)}
66
+ @hide-children=${() => this.#toggle(PENDING, false)}
67
+ @click-label=${() => this.#toggle(PENDING, this._closed.has(PENDING))}
68
+ >
69
+ <umb-icon slot="icon" name="icon-folder"></umb-icon>
70
+ ${items.map((request) => {
71
+ const href = pageLink(request)
72
+ const what = request.action === 'unpublish' ? 'taking it down' : 'publishing'
73
+ return html`<uui-menu-item
74
+ label=${request.nodeName}
75
+ href=${href}
76
+ ?active=${location.pathname === new URL(href, location.href).pathname}
77
+ title=${`${request.mine ? 'Waiting for you. ' : ''}${request.workflow.name}: ${what}`}
78
+ >
79
+ <umb-icon
80
+ slot="icon"
81
+ name=${request.mine ? 'icon-inbox' : 'icon-document'}
82
+ class=${request.mine ? 'mine' : ''}
83
+ ></umb-icon>
84
+ </uui-menu-item>`
85
+ })}
86
+ </uui-menu-item>
87
87
  </uui-menu-item-list>`
88
88
  }
89
89
 
90
90
  static styles = css`
91
+ umb-icon.mine {
92
+ color: var(--uui-color-warning-standalone, var(--uui-color-warning));
93
+ }
91
94
  h3 {
92
95
  display: flex;
93
96
  align-items: center;
@@ -1,9 +1,10 @@
1
1
  /**
2
2
  * Dictionary words in the back office (stories 294, 297). `crombolo-dictionary-words`
3
3
  * goes around a text box, the form editor's and the text boxes and text areas
4
- * of a page: a `{#key}` naming an item shows as a chip, and typing `{#`, or `#`
5
- * at the start, offers the items. It sends `crombolo-word-choose` with the new
6
- * value; the box it holds sends its own input as before. Without this module the
4
+ * of a page: a `{#key}` naming an item shows as a chip, and typing `{#` anywhere,
5
+ * or `#` at the start, offers the items, the chosen one going in at the cursor.
6
+ * It sends `crombolo-word-choose` with the new value; the box it holds sends its
7
+ * own input as before. Without this module the
7
8
  * element is unknown, and the box shows as it always did.
8
9
  *
9
10
  * Its entry point also tells the fork what `{#key}` in a block's label reads as.
@@ -11,7 +12,7 @@
11
12
  import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
12
13
  import './dictionary-chip.js'
13
14
  import { dictionaryWords, WORDS_CHANGED } from './dictionary-words-client.js'
14
- import { chipWord, suggestions, wordLine, wordValue } from './form-word-input-model.js'
15
+ import { chipWord, insertWord, suggestions, wordLine } from './form-word-input-model.js'
15
16
 
16
17
  export class CromboloDictionaryWordsElement extends LitElement {
17
18
  static properties = {
@@ -32,10 +33,14 @@ export class CromboloDictionaryWordsElement extends LitElement {
32
33
  super()
33
34
  this._open = false
34
35
  this._active = 0
35
- this.addEventListener('input', () => {
36
+ this.addEventListener('input', (event) => {
37
+ this.#follow(event)
36
38
  this._active = 0
37
39
  this._open = true
38
40
  })
41
+ this.addEventListener('keyup', (event) => {
42
+ if (event.key.startsWith('Arrow') && !this.#found.rows.length) this.#follow(event)
43
+ })
39
44
  this.addEventListener('keydown', (event) => this.#onKeydown(event))
40
45
  this.addEventListener('focusout', () => {
41
46
  this._open = false
@@ -57,10 +62,37 @@ export class CromboloDictionaryWordsElement extends LitElement {
57
62
  return this.words ?? this._loaded
58
63
  }
59
64
 
65
+ /** The box being typed in, and where its cursor is. */
66
+ #box
67
+ #caret
68
+
69
+ #follow(event) {
70
+ const box = event
71
+ .composedPath()
72
+ .find((el) => el instanceof HTMLInputElement || el instanceof HTMLTextAreaElement)
73
+ if (!box) return
74
+ this.#box = box
75
+ this.#caret = box.selectionStart ?? undefined
76
+ }
77
+
60
78
  get #found() {
61
79
  return this.readonly || !this._open
62
80
  ? { rows: [], more: false }
63
- : suggestions(this.#words ?? [], this.value ?? '')
81
+ : suggestions(this.#words ?? [], this.value ?? '', this.#caret)
82
+ }
83
+
84
+ /** The item chosen, made `{#key}` where the cursor is. */
85
+ #pick(word) {
86
+ const value = this.value ?? ''
87
+ const at = insertWord(value, this.#caret ?? value.length, word.name)
88
+ this.#choose(at.value)
89
+ const box = this.#box
90
+ if (box)
91
+ requestAnimationFrame(() => {
92
+ box.focus()
93
+ box.setSelectionRange?.(at.caret, at.caret)
94
+ this.#caret = at.caret
95
+ })
64
96
  }
65
97
 
66
98
  #choose(value) {
@@ -82,7 +114,7 @@ export class CromboloDictionaryWordsElement extends LitElement {
82
114
  this._active = (this._active + step) % rows.length
83
115
  } else if (event.key === 'Enter') {
84
116
  event.preventDefault()
85
- this.#choose(wordValue((rows[this._active] ?? rows[0]).name))
117
+ this.#pick(rows[this._active] ?? rows[0])
86
118
  }
87
119
  }
88
120
 
@@ -121,7 +153,7 @@ export class CromboloDictionaryWordsElement extends LitElement {
121
153
  aria-selected=${index === this._active ? 'true' : 'false'}
122
154
  @pointerdown=${(event) => {
123
155
  event.preventDefault()
124
- this.#choose(wordValue(word.name))
156
+ this.#pick(word)
125
157
  }}
126
158
  >
127
159
  <strong>${word.name}</strong> <span>${word.text}</span>
@@ -4,8 +4,9 @@
4
4
  * so each is tested on its own. Shared by the form editor and a page's text boxes.
5
5
  */
6
6
  const ROWS = 8
7
- /** What has been typed of a name: after `{#`, or after a `#` that starts the box. */
8
- const TYPING = /^(?:\{#([^{}\s]*)|#(\S*))$/
7
+ /** What has been typed of a name, up to the cursor: after `{#`, or a `#` that starts the box. */
8
+ const TYPING_IN_TEXT = /\{#([^{}\s]*)$/
9
+ const TYPING_ALONE = /^#(\S*)$/
9
10
  const ONLY_WORD = /^\{#([^{}\s]+)\}$/
10
11
  const BARE_WORD = /^#(\S+)$/
11
12
 
@@ -13,17 +14,49 @@ const BARE_WORD = /^#(\S+)$/
13
14
  export const wordValue = (name) => `{#${name}}`
14
15
 
15
16
  /**
16
- * The dictionary items to offer for what has been typed: names starting with it
17
- * first, then those containing it, then those whose words do. Only after `{#`,
18
- * or a `#` at the start.
17
+ * The name being typed at the cursor, and where its mark starts: after `{#`
18
+ * anywhere, or after a `#` that is the whole box. Undefined when none is.
19
+ *
20
+ * @param {string} value
21
+ * @param {number} [caret] where the cursor is; the end when not known
22
+ */
23
+ export function typedWord(value, caret = (value ?? '').length) {
24
+ const before = (value ?? '').slice(0, caret)
25
+ const inText = TYPING_IN_TEXT.exec(before)
26
+ if (inText) return { typed: inText[1] ?? '', start: inText.index, end: caret }
27
+ const alone = TYPING_ALONE.exec(value ?? '')
28
+ if (alone && caret === value.length) return { typed: alone[1] ?? '', start: 0, end: caret }
29
+ return undefined
30
+ }
31
+
32
+ /**
33
+ * The value with the name being typed at the cursor made `{#name}`, and where the
34
+ * cursor goes after it. The rest of the text stays as it was.
35
+ *
36
+ * @param {string} value
37
+ * @param {number} caret
38
+ * @param {string} name
39
+ */
40
+ export function insertWord(value, caret, name) {
41
+ const at = typedWord(value, caret) ?? { start: caret, end: caret }
42
+ const rest = value.slice(at.end).replace(/^[^{}\s]*\}/, '')
43
+ const word = wordValue(name)
44
+ return { value: value.slice(0, at.start) + word + rest, caret: at.start + word.length }
45
+ }
46
+
47
+ /**
48
+ * The dictionary items to offer for what has been typed at the cursor: names
49
+ * starting with it first, then those containing it, then those whose words do.
50
+ * Only after `{#`, or a `#` at the start.
19
51
  *
20
52
  * @param {{ name: string, text: string }[]} words
21
53
  * @param {string} value
54
+ * @param {number} [caret]
22
55
  */
23
- export function suggestions(words, value) {
24
- const typing = TYPING.exec(value ?? '')
56
+ export function suggestions(words, value, caret) {
57
+ const typing = typedWord(value, caret)
25
58
  if (!typing) return { rows: [], more: false }
26
- const typed = (typing[1] ?? typing[2] ?? '').toLowerCase()
59
+ const typed = typing.typed.toLowerCase()
27
60
  const rank = ({ name, text }) => {
28
61
  const lower = name.toLowerCase()
29
62
  if (lower.startsWith(typed)) return 0
@@ -44,6 +44,8 @@ export default class CromboloFormWordInputElement extends LitElement {
44
44
  ?readonly=${this.readonly}
45
45
  @input=${(event) => {
46
46
  this.value = event.target.value ?? ''
47
+ // Each keystroke, for a host that follows the text (an alias from a caption).
48
+ this.dispatchEvent(new Event('input', { bubbles: true }))
47
49
  }}
48
50
  @change=${(event) => {
49
51
  event.stopPropagation()
@@ -196,6 +196,7 @@ export default class CromboloFormsEntriesElement extends UmbLitElement {
196
196
  : nothing
197
197
  }
198
198
  <uui-input
199
+ label="Search the answers"
199
200
  placeholder="Search the answers"
200
201
  .value=${this._search}
201
202
  @change=${(event) => {