@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
@@ -0,0 +1,228 @@
1
+ /**
2
+ * Dictionary words in the back office (stories 294, 297). `crombolo-dictionary-words`
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 `{#` 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
8
+ * element is unknown, and the box shows as it always did.
9
+ *
10
+ * Its entry point also tells the fork what `{#key}` in a block's label reads as.
11
+ */
12
+ import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
13
+ import './dictionary-chip.js'
14
+ import { dictionaryWords, WORDS_CHANGED } from './dictionary-words-client.js'
15
+ import { chipWord, insertWord, suggestions, wordLine } from './form-word-input-model.js'
16
+
17
+ export class CromboloDictionaryWordsElement extends LitElement {
18
+ static properties = {
19
+ value: { type: String },
20
+ readonly: { type: Boolean },
21
+ /** The items, when the host has them; else they are fetched. */
22
+ words: { attribute: false },
23
+ _loaded: { state: true },
24
+ _open: { state: true },
25
+ _active: { state: true },
26
+ }
27
+
28
+ #refresh = async () => {
29
+ this._loaded = await dictionaryWords()
30
+ }
31
+
32
+ constructor() {
33
+ super()
34
+ this._open = false
35
+ this._active = 0
36
+ this.addEventListener('input', (event) => {
37
+ this.#follow(event)
38
+ this._active = 0
39
+ this._open = true
40
+ })
41
+ this.addEventListener('keyup', (event) => {
42
+ if (event.key.startsWith('Arrow') && !this.#found.rows.length) this.#follow(event)
43
+ })
44
+ this.addEventListener('keydown', (event) => this.#onKeydown(event))
45
+ this.addEventListener('focusout', () => {
46
+ this._open = false
47
+ })
48
+ }
49
+
50
+ connectedCallback() {
51
+ super.connectedCallback()
52
+ window.addEventListener(WORDS_CHANGED, this.#refresh)
53
+ if (!this.words) this.#refresh()
54
+ }
55
+
56
+ disconnectedCallback() {
57
+ super.disconnectedCallback()
58
+ window.removeEventListener(WORDS_CHANGED, this.#refresh)
59
+ }
60
+
61
+ get #words() {
62
+ return this.words ?? this._loaded
63
+ }
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
+
78
+ get #found() {
79
+ return this.readonly || !this._open
80
+ ? { rows: [], more: false }
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
+ })
96
+ }
97
+
98
+ #choose(value) {
99
+ this._open = false
100
+ this.dispatchEvent(
101
+ new CustomEvent('crombolo-word-choose', { detail: { value }, bubbles: true, composed: true }),
102
+ )
103
+ }
104
+
105
+ #onKeydown(event) {
106
+ const { rows } = this.#found
107
+ if (rows.length === 0) return
108
+ if (event.key === 'Escape') {
109
+ event.stopPropagation()
110
+ this._open = false
111
+ } else if (event.key === 'ArrowDown' || event.key === 'ArrowUp') {
112
+ event.preventDefault()
113
+ const step = event.key === 'ArrowDown' ? 1 : rows.length - 1
114
+ this._active = (this._active + step) % rows.length
115
+ } else if (event.key === 'Enter') {
116
+ event.preventDefault()
117
+ this.#pick(rows[this._active] ?? rows[0])
118
+ }
119
+ }
120
+
121
+ updated() {
122
+ const list = this.renderRoot.querySelector('[popover]')
123
+ if (!list) return
124
+ const box = this.getBoundingClientRect()
125
+ list.style.top = `${box.bottom + 2}px`
126
+ list.style.left = `${box.left}px`
127
+ list.style.minWidth = `${box.width}px`
128
+ list.showPopover()
129
+ }
130
+
131
+ render() {
132
+ const words = this.#words
133
+ const chip = chipWord(words, this.value)
134
+ if (chip)
135
+ return html`<crombolo-dictionary-chip
136
+ .name=${chip.name}
137
+ ?readonly=${this.readonly}
138
+ @remove=${() => this.#choose('')}
139
+ ></crombolo-dictionary-chip>`
140
+ const { rows, more } = this.#found
141
+ const line = wordLine(words, this.value)
142
+ return html`<slot></slot>
143
+ ${line ? html`<p class="word">${line}</p>` : nothing}
144
+ <span class="status" role="status"
145
+ >${rows.length > 0 ? `${rows.length} dictionary items. Use the arrow keys to choose one.` : ''}</span
146
+ >
147
+ ${
148
+ rows.length > 0
149
+ ? html`<div popover="manual" role="listbox" aria-label="Dictionary items">
150
+ ${rows.map(
151
+ (word, index) => html`<div
152
+ role="option"
153
+ aria-selected=${index === this._active ? 'true' : 'false'}
154
+ @pointerdown=${(event) => {
155
+ event.preventDefault()
156
+ this.#pick(word)
157
+ }}
158
+ >
159
+ <strong>${word.name}</strong> <span>${word.text}</span>
160
+ </div>`,
161
+ )}
162
+ ${more ? html`<p class="more">Keep typing to narrow this down.</p>` : nothing}
163
+ </div>`
164
+ : nothing
165
+ }`
166
+ }
167
+
168
+ static styles = css`
169
+ :host {
170
+ display: block;
171
+ }
172
+ .word {
173
+ margin: var(--uui-size-space-1) 0 0;
174
+ color: var(--uui-color-text-alt);
175
+ font-size: var(--uui-type-small-size);
176
+ }
177
+ .status {
178
+ position: absolute;
179
+ width: 1px;
180
+ height: 1px;
181
+ overflow: hidden;
182
+ clip-path: inset(50%);
183
+ }
184
+ [popover] {
185
+ position: fixed;
186
+ inset: auto;
187
+ margin: 0;
188
+ padding: var(--uui-size-space-1);
189
+ max-width: 28rem;
190
+ background: var(--uui-color-surface);
191
+ color: var(--uui-color-text);
192
+ border: 1px solid var(--uui-color-border);
193
+ border-radius: var(--uui-border-radius);
194
+ box-shadow: var(--uui-shadow-depth-3);
195
+ }
196
+ [role='option'] {
197
+ padding: var(--uui-size-space-2) var(--uui-size-space-3);
198
+ border-radius: var(--uui-border-radius);
199
+ cursor: pointer;
200
+ }
201
+ [role='option'] span {
202
+ color: var(--uui-color-text-alt);
203
+ }
204
+ [role='option'][aria-selected='true'],
205
+ [role='option']:hover {
206
+ background: var(--uui-color-surface-emphasis);
207
+ }
208
+ .more {
209
+ margin: var(--uui-size-space-1) var(--uui-size-space-3);
210
+ color: var(--uui-color-text-alt);
211
+ font-size: var(--uui-type-small-size);
212
+ }
213
+ `
214
+ }
215
+
216
+ if (!customElements.get('crombolo-dictionary-words'))
217
+ customElements.define('crombolo-dictionary-words', CromboloDictionaryWordsElement)
218
+
219
+ /** A block label's `{#key}`: the item's words in the default language, or its name. */
220
+ export const onInit = async () => {
221
+ const { umbCromboloHooks } = await import('@umbraco-cms/backoffice/extension-registry')
222
+ umbCromboloHooks.dictionaryWord = async (name) => {
223
+ const word = (await dictionaryWords()).find(
224
+ (w) => w.name.toLowerCase() === String(name).toLowerCase(),
225
+ )
226
+ return word ? word.text || word.name : undefined
227
+ }
228
+ }
@@ -1,19 +1,62 @@
1
1
  /**
2
- * What the form editor's text boxes suggest (story 294). Pure, so each is tested
3
- * on its own.
2
+ * What a text box that can name a dictionary item shows (stories 294, 297): the
3
+ * items it suggests, the chip a `{#key}` becomes, and the line under it. Pure,
4
+ * so each is tested on its own. Shared by the form editor and a page's text boxes.
4
5
  */
5
6
  const ROWS = 8
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*)$/
10
+ const ONLY_WORD = /^\{#([^{}\s]+)\}$/
11
+ const BARE_WORD = /^#(\S+)$/
12
+
13
+ /** `{#key}` for an item's name. */
14
+ export const wordValue = (name) => `{#${name}}`
15
+
16
+ /**
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
+ }
6
46
 
7
47
  /**
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 `#`.
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.
10
51
  *
11
52
  * @param {{ name: string, text: string }[]} words
12
53
  * @param {string} value
54
+ * @param {number} [caret]
13
55
  */
14
- export function suggestions(words, value) {
15
- if (!/^#\S*$/.test(value)) return { rows: [], more: false }
16
- const typed = value.slice(1).toLowerCase()
56
+ export function suggestions(words, value, caret) {
57
+ const typing = typedWord(value, caret)
58
+ if (!typing) return { rows: [], more: false }
59
+ const typed = typing.typed.toLowerCase()
17
60
  const rank = ({ name, text }) => {
18
61
  const lower = name.toLowerCase()
19
62
  if (lower.startsWith(typed)) return 0
@@ -29,17 +72,27 @@ export function suggestions(words, value) {
29
72
  }
30
73
 
31
74
  /**
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.
75
+ * The item a value shows as a chip: the whole of it one `{#key}`, or a `#key`
76
+ * as forms wrote it before, that names an item; undefined otherwise.
77
+ *
78
+ * @param {{ name: string, text: string }[] | undefined} words
79
+ * @param {string} value
80
+ */
81
+ export function chipWord(words, value) {
82
+ if (!words) return undefined
83
+ const name = (ONLY_WORD.exec((value ?? '').trim()) ?? BARE_WORD.exec(value ?? ''))?.[1]
84
+ if (!name) return undefined
85
+ return words.find((word) => word.name.toLowerCase() === name.toLowerCase())
86
+ }
87
+
88
+ /**
89
+ * What goes under a box: that a `{#key}` names no item. Nothing for ordinary
90
+ * text, for a chip, or before the list has loaded.
34
91
  *
35
92
  * @param {{ name: string, text: string }[] | undefined} words
36
93
  * @param {string} value
37
94
  */
38
95
  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.'
96
+ if (!words || !ONLY_WORD.test((value ?? '').trim()) || chipWord(words, value)) return undefined
97
+ return 'No dictionary item has this name, so it shows as written.'
45
98
  }
@@ -1,10 +1,10 @@
1
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.
2
+ * A form text that can name a dictionary item (stories 294, 297): typing `{#`,
3
+ * or `#` at the start, offers the items, and a `{#key}` shows as a chip. It sends
4
+ * `change`, with `value`, as `uui-input` does.
5
5
  */
6
- import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
7
- import { suggestions, wordLine } from './form-word-input-model.js'
6
+ import { css, html, LitElement } from '@umbraco-cms/backoffice/external/lit'
7
+ import './dictionary-words.js'
8
8
 
9
9
  export default class CromboloFormWordInputElement extends LitElement {
10
10
  static properties = {
@@ -13,107 +13,46 @@ export default class CromboloFormWordInputElement extends LitElement {
13
13
  value: { type: String },
14
14
  readonly: { type: Boolean },
15
15
  words: { attribute: false },
16
- _open: { state: true },
17
- _active: { state: true },
18
16
  }
19
17
 
20
18
  constructor() {
21
19
  super()
22
20
  this.value = ''
23
21
  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
22
  }
37
23
 
38
24
  #changed() {
39
25
  this.dispatchEvent(new Event('change', { bubbles: true }))
40
26
  }
41
27
 
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
28
  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
29
+ return html`<crombolo-dictionary-words
30
+ .value=${this.value ?? ''}
31
+ .words=${this.words}
32
+ ?readonly=${this.readonly}
33
+ @input=${(event) => event.stopPropagation()}
34
+ @crombolo-word-choose=${(event) => {
35
+ event.stopPropagation()
36
+ this.value = event.detail.value
37
+ this.#changed()
38
+ }}
39
+ >
40
+ <uui-input
80
41
  label=${this.label}
81
42
  placeholder=${this.placeholder ?? ''}
82
43
  .value=${this.value ?? ''}
83
44
  ?readonly=${this.readonly}
84
- @input=${this.#onInput}
85
- @keydown=${this.#onKeydown}
45
+ @input=${(event) => {
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 }))
49
+ }}
86
50
  @change=${(event) => {
87
51
  event.stopPropagation()
88
52
  this.#changed()
89
53
  }}
90
- @blur=${() => {
91
- this._open = false
92
- }}
93
54
  ></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
- }`
55
+ </crombolo-dictionary-words>`
117
56
  }
118
57
 
119
58
  static styles = css`
@@ -123,47 +62,6 @@ export default class CromboloFormWordInputElement extends LitElement {
123
62
  uui-input {
124
63
  width: 100%;
125
64
  }
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
65
  `
168
66
  }
169
67
 
@@ -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) => {