@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.
Files changed (38) hide show
  1. package/assets/login.js +6 -4
  2. package/package.json +3 -3
  3. package/plugin/alias-input.js +85 -0
  4. package/plugin/alias-model.js +36 -0
  5. package/plugin/app-preview/umbraco-package.json +1 -1
  6. package/plugin/approvals-tree-model.js +21 -0
  7. package/plugin/approvals-tree.js +108 -0
  8. package/plugin/content-strip-items.js +20 -10
  9. package/plugin/definition-tree.js +157 -126
  10. package/plugin/dictionary-chip.js +233 -0
  11. package/plugin/dictionary-words-client.js +52 -0
  12. package/plugin/dictionary-words.js +228 -0
  13. package/plugin/form-word-input-model.js +68 -15
  14. package/plugin/form-word-input.js +23 -125
  15. package/plugin/forms-entries.js +1 -0
  16. package/plugin/forms-overview.js +79 -9
  17. package/plugin/localizations/umbraco-package.json +1 -1
  18. package/plugin/page-history-modal.js +279 -0
  19. package/plugin/page-history-model.js +108 -0
  20. package/plugin/page-history.js +89 -0
  21. package/plugin/seo/umbraco-package.json +1 -1
  22. package/plugin/settings-cards.js +8 -1
  23. package/plugin/settings-section.js +43 -18
  24. package/plugin/sign-in/umbraco-package.json +1 -1
  25. package/plugin/template-picker-modal.js +276 -0
  26. package/plugin/template-picker-model.js +77 -0
  27. package/plugin/template-picker.js +43 -0
  28. package/plugin/tsx-editors.js +5 -0
  29. package/plugin/tsx-highlighting.js +81 -0
  30. package/plugin/umbraco-package.json +111 -41
  31. package/plugin/workflow-client.js +3 -0
  32. package/plugin/workflow-designer.js +66 -14
  33. package/plugin/workflow-requests.js +111 -105
  34. package/plugin/workflow-send-condition.js +2 -0
  35. package/plugin/workflow-send-model.js +20 -0
  36. package/plugin/workflow-send-unpublish.js +2 -0
  37. package/plugin/workflow-send.js +231 -0
  38. package/plugin/workflow-tab.js +32 -86
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.53.2",
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.53.2",
36
- "@crombolo/backoffice-dist": "0.53.2"
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.53.2",
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
+ }
@@ -0,0 +1,108 @@
1
+ /**
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
+ */
6
+ import { css, html } from '@umbraco-cms/backoffice/external/lit'
7
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
+ import { pendingForTree } from './approvals-tree-model.js'
9
+ import { inFlight, waitingForMe } from './workflow-client.js'
10
+ import { pageLink } from './workflow-requests.js'
11
+
12
+ const PENDING = 'pending'
13
+
14
+ export default class CromboloApprovalsTreeElement extends UmbLitElement {
15
+ static properties = {
16
+ _items: { state: true },
17
+ _closed: { state: true },
18
+ }
19
+
20
+ #follow = () => {
21
+ if (location.pathname.includes('/section/workflow')) this.#load()
22
+ else this.requestUpdate()
23
+ }
24
+
25
+ connectedCallback() {
26
+ super.connectedCallback()
27
+ this._closed = new Set()
28
+ this.#load()
29
+ window.addEventListener('changestate', this.#follow)
30
+ window.addEventListener('popstate', this.#follow)
31
+ }
32
+
33
+ disconnectedCallback() {
34
+ super.disconnectedCallback()
35
+ window.removeEventListener('changestate', this.#follow)
36
+ window.removeEventListener('popstate', this.#follow)
37
+ }
38
+
39
+ async #load() {
40
+ const [pending, mine] = await Promise.all([
41
+ inFlight().catch(() => undefined),
42
+ waitingForMe().catch(() => undefined),
43
+ ])
44
+ this._items = pendingForTree(pending?.items, mine?.items)
45
+ }
46
+
47
+ #toggle(id, open) {
48
+ const closed = new Set(this._closed)
49
+ if (open) closed.delete(id)
50
+ else closed.add(id)
51
+ this._closed = closed
52
+ }
53
+
54
+ render() {
55
+ // Headed as Umbraco's sidebar menus are, Structure's among them.
56
+ const header = html`<h3>Approvals</h3>`
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)
60
+ return html`${header}<uui-menu-item-list>
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
+ </uui-menu-item-list>`
88
+ }
89
+
90
+ static styles = css`
91
+ umb-icon.mine {
92
+ color: var(--uui-color-warning-standalone, var(--uui-color-warning));
93
+ }
94
+ h3 {
95
+ display: flex;
96
+ align-items: center;
97
+ height: var(--umb-header-layout-height);
98
+ margin: 0;
99
+ padding: var(--uui-size-4) var(--uui-size-8);
100
+ box-sizing: border-box;
101
+ font-size: 14px;
102
+ }
103
+ `
104
+ }
105
+
106
+ customElements.define('crombolo-approvals-tree', CromboloApprovalsTreeElement)
107
+
108
+ export { CromboloApprovalsTreeElement as element }
@@ -2,31 +2,39 @@
2
2
  * What the menu under Content offers (story 289), and which item a page belongs
3
3
  * to. Pure, so each is tested on its own. Structure and Code stay in
4
4
  * Settings: the client links to them there, and the menu is what puts them
5
- * together. Forms is a node in Structure, and Workflows stays in the Forms section.
5
+ * together. Forms and Workflows are nodes in Structure; Approvals is its own section,
6
+ * with no tab in the header.
6
7
  */
7
8
  import { treeFor } from './settings-cards.js'
8
9
 
9
10
  const STRUCTURE = 'Crombolo.Section.Structure'
10
11
  const COMPONENTS = 'Crombolo.Section.Components'
11
12
  const WORKFLOW_SETUP = 'Crombolo.Section.WorkflowSetup'
13
+ const APPROVALS = 'Crombolo.Section.Workflow'
12
14
  /** Reading forms, which is what a group's Forms comes to. */
13
15
  const FORM_READ = 'Crombolo.Form.Read'
14
16
  const FORMS = 'Crombolo.Section.Forms'
15
17
  const CONTENT = 'Umb.Section.Content'
16
18
 
17
- /** Forms is a node in Structure; someone with Forms alone gets it where it always was. */
18
- const STRUCTURE_FORMS = { path: 'section/forms', section: FORMS, verb: FORM_READ }
19
+ /**
20
+ * Forms and Workflows are nodes in Structure; someone with either alone, and not
21
+ * Structure, gets it beside the other in the Forms section.
22
+ */
23
+ const STRUCTURE_ELSE = [
24
+ { path: 'section/forms', section: FORMS, verb: FORM_READ },
25
+ { path: 'section/forms/view/workflows', section: WORKFLOW_SETUP },
26
+ ]
19
27
 
20
28
  const ITEMS = [
21
29
  { label: 'Pages', path: 'section/content', section: CONTENT },
30
+ { label: 'Approvals', path: 'section/workflow', section: APPROVALS },
22
31
  {
23
32
  label: 'Structure',
24
33
  path: 'section/settings/structure',
25
34
  section: STRUCTURE,
26
- or: STRUCTURE_FORMS,
35
+ or: STRUCTURE_ELSE,
27
36
  },
28
37
  { label: 'Code', path: 'section/settings/code', section: COMPONENTS },
29
- { label: 'Workflows', path: 'section/forms/view/workflows', section: WORKFLOW_SETUP },
30
38
  ]
31
39
 
32
40
  /**
@@ -39,9 +47,10 @@ export function stripItems(user) {
39
47
  const may = (verb) => user?.isAdmin === true || (user?.fallbackPermissions ?? []).includes(verb)
40
48
  const items = ITEMS.flatMap((item) => {
41
49
  if (allowed.includes(item.section)) return [item]
42
- return item.or && allowed.includes(item.or.section) && may(item.or.verb)
43
- ? [{ ...item, ...item.or }]
44
- : []
50
+ const other = (item.or ?? []).find(
51
+ (or) => allowed.includes(or.section) && (!or.verb || may(or.verb)),
52
+ )
53
+ return other ? [{ ...item, ...other }] : []
45
54
  })
46
55
  return items.length > 1 ? items : []
47
56
  }
@@ -56,9 +65,10 @@ export function activeItem(path) {
56
65
  if (!section) return undefined
57
66
  const [, name, rest = ''] = section
58
67
  if (name === 'content') return 'Pages'
59
- if (name === 'forms') return rest.startsWith('view/workflows') ? 'Workflows' : 'Structure'
68
+ if (name === 'forms') return 'Structure'
69
+ if (name === 'workflow') return 'Approvals'
60
70
  if (name !== 'settings') return undefined
61
- if (rest.startsWith('structure') || rest.startsWith('forms')) return 'Structure'
71
+ if (['structure', 'forms', 'workflows'].some((tree) => rest.startsWith(tree))) return 'Structure'
62
72
  if (rest.startsWith('code')) return 'Code'
63
73
  const tree = treeFor(/^workspace\/([^/]+)/.exec(rest)?.[1])
64
74
  return tree === 'structure' ? 'Structure' : tree === 'code' ? 'Code' : undefined