@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
@@ -11,6 +11,8 @@
11
11
  * refusal a hand-written file would get.
12
12
  */
13
13
  // For its side effect: registers `umb-input-document`, which the shell loads lazily.
14
+ import './alias-input.js'
15
+ import { camelAlias } from './alias-model.js'
14
16
  import '@umbraco-cms/backoffice/document'
15
17
  import './form-word-input.js'
16
18
  import './forms-entries.js'
@@ -64,6 +66,9 @@ const WORD_SETTINGS = ['messageOnSubmit', 'submitLabel', 'nextLabel', 'previousL
64
66
  /** The settings of a field's type that can name one. */
65
67
  const WORD_FIELD_SETTINGS = ['placeholder', 'content']
66
68
 
69
+ /** Whose default value is words in the box, as `WORDY_DEFAULT_TYPES` in `@crombolo/core`. */
70
+ const WORDY_DEFAULT_TYPES = ['shortAnswer', 'longAnswer']
71
+
67
72
  /** The tree beside the list hears of a change this way. */
68
73
  const definitionsChanged = () => window.dispatchEvent(new Event('crombolo:definitions-changed'))
69
74
 
@@ -281,7 +286,10 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
281
286
  .checked=${value === true}
282
287
  @change=${(event) => write(setting.key, event.target.checked || undefined)}
283
288
  ></uui-toggle>`
284
- if (WORD_FIELD_SETTINGS.includes(setting.key))
289
+ if (
290
+ WORD_FIELD_SETTINGS.includes(setting.key) ||
291
+ (setting.key === 'defaultValue' && WORDY_DEFAULT_TYPES.includes(field.type))
292
+ )
285
293
  return html`<label>
286
294
  <span>${label}</span>
287
295
  <crombolo-form-word-input
@@ -295,6 +303,7 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
295
303
  return html`<label>
296
304
  <span>${label}</span>
297
305
  <uui-input
306
+ label=${label}
298
307
  title=${setting.description ?? ''}
299
308
  type=${setting.kind === 'number' ? 'number' : 'text'}
300
309
  .value=${value === undefined ? '' : setting.kind === 'list' ? value.join(', ') : String(value)}
@@ -401,6 +410,27 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
401
410
  pages: [{ groups: [{ columns: 1, fields: [] }] }],
402
411
  workflows: [],
403
412
  }
413
+ this.#freshForm = this._editing.key
414
+ this.#ownFormAlias = false
415
+ }
416
+
417
+ /**
418
+ * What is new in this editor and not saved yet, whose alias follows its name
419
+ * until it is written by hand. Fields by the object, which an edit keeps; the
420
+ * form by its key, since every edit copies it. A saved one is reloaded afresh.
421
+ */
422
+ #fresh = new WeakSet()
423
+ #own = new WeakSet()
424
+ #freshForm
425
+ #ownFormAlias = false
426
+
427
+ #isFresh(item) {
428
+ return item === this._editing ? item.key === this.#freshForm : this.#fresh.has(item)
429
+ }
430
+
431
+ #follows(item) {
432
+ if (item === this._editing) return this.#isFresh(item) && !this.#ownFormAlias
433
+ return this.#fresh.has(item) && !this.#own.has(item)
404
434
  }
405
435
 
406
436
  /** Every field, in order: for the previews, which a layout change does not touch. */
@@ -489,7 +519,7 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
489
519
  look="secondary"
490
520
  label="Add a field"
491
521
  @click=${() => {
492
- group.fields.push({
522
+ const field = {
493
523
  alias: '',
494
524
  type: 'shortAnswer',
495
525
  caption: '',
@@ -497,7 +527,9 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
497
527
  sensitive: false,
498
528
  values: [],
499
529
  accept: [],
500
- })
530
+ }
531
+ this.#fresh.add(field)
532
+ group.fields.push(field)
501
533
  this.#touch()
502
534
  }}
503
535
  ></uui-button>
@@ -550,22 +582,32 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
550
582
  .value=${field.caption ?? ''}
551
583
  .words=${this._words}
552
584
  ?readonly=${Boolean(this._because)}
585
+ @input=${(event) => {
586
+ field.caption = event.target.value
587
+ if (this.#follows(field)) {
588
+ field.alias = camelAlias(field.caption)
589
+ this.requestUpdate()
590
+ }
591
+ }}
553
592
  @change=${(event) => {
554
593
  field.caption = event.target.value
594
+ if (this.#follows(field)) field.alias = camelAlias(field.caption)
555
595
  this.#touch()
556
596
  }}
557
597
  ></crombolo-form-word-input>
558
598
  ${this.#fieldDetails(field)}
559
599
  </uui-table-cell>
560
600
  <uui-table-cell>
561
- <uui-input
562
- label="Alias"
601
+ <crombolo-alias-input
563
602
  .value=${field.alias ?? ''}
603
+ ?saved=${!this.#fresh.has(field)}
604
+ ?readonly=${Boolean(this._because)}
564
605
  @change=${(event) => {
565
606
  field.alias = event.target.value
607
+ this.#own.add(field)
566
608
  this.#touch()
567
609
  }}
568
- ></uui-input>
610
+ ></crombolo-alias-input>
569
611
  </uui-table-cell>
570
612
  <uui-table-cell>
571
613
  <select
@@ -767,6 +809,8 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
767
809
  if (result.ok) {
768
810
  // The green toast every workspace shows on a save.
769
811
  this.#notifications?.peek('positive', { data: { message: 'Form saved' } })
812
+ // Saved, its alias is what things will name it by: no longer following its name.
813
+ this.#freshForm = undefined
770
814
  this._editing = undefined
771
815
  this.#changed()
772
816
  await this.#load()
@@ -850,13 +894,38 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
850
894
  /** The form's own settings and layout, which is what its Design tab shows. */
851
895
  #design(form, text) {
852
896
  return html` <uui-box>
853
- ${text('name', 'Name')}
854
- ${text('alias', 'Alias', 'Letters and numbers, starting with a letter. The file is named after it.')}
897
+ <uui-form-layout-item>
898
+ <uui-label slot="label">Name</uui-label>
899
+ <uui-input
900
+ label="Name"
901
+ .value=${form.name ?? ''}
902
+ ?readonly=${Boolean(this._because)}
903
+ @input=${(event) => {
904
+ form.name = event.target.value
905
+ if (this.#follows(form)) form.alias = camelAlias(form.name)
906
+ this.#touch()
907
+ }}
908
+ ></uui-input>
909
+ </uui-form-layout-item>
910
+ <uui-form-layout-item>
911
+ <uui-label slot="label">Alias</uui-label>
912
+ <crombolo-alias-input
913
+ .value=${form.alias ?? ''}
914
+ ?saved=${!this.#isFresh(form)}
915
+ ?readonly=${Boolean(this._because)}
916
+ @change=${(event) => {
917
+ form.alias = event.target.value
918
+ this.#ownFormAlias = true
919
+ this.#touch()
920
+ }}
921
+ ></crombolo-alias-input>
922
+ </uui-form-layout-item>
855
923
  ${text('messageOnSubmit', 'Message on submit')}
856
924
  ${text('submitLabel', 'Submit button')}
857
925
  <uui-form-layout-item>
858
926
  <uui-label slot="label">Store entries</uui-label>
859
927
  <uui-toggle
928
+ label="Store entries"
860
929
  .checked=${form.storeEntries !== false}
861
930
  @change=${(event) => {
862
931
  form.storeEntries = event.target.checked
@@ -870,6 +939,7 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
870
939
  <uui-label slot="label">Show one page at a time</uui-label>
871
940
  <span slot="description">Each page is checked before the next. Without JavaScript the pages show together.</span>
872
941
  <uui-toggle
942
+ label="Show one page at a time"
873
943
  .checked=${form.stepPages === true}
874
944
  @change=${(event) => {
875
945
  if (event.target.checked) form.stepPages = true
@@ -931,7 +1001,7 @@ export default class CromboloFormsOverviewElement extends UmbLitElement {
931
1001
  ?readonly=${Boolean(this._because)}
932
1002
  @change=${change}
933
1003
  ></crombolo-form-word-input>`
934
- : html`<uui-input .value=${form[key] ?? ''} @change=${change}></uui-input>`
1004
+ : html`<uui-input label=${label} .value=${form[key] ?? ''} @change=${change}></uui-input>`
935
1005
  }
936
1006
  </uui-form-layout-item>
937
1007
  `
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Localizations",
4
4
  "id": "Crombolo.Localizations",
5
- "version": "0.53.2",
5
+ "version": "0.55.0",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,279 @@
1
+ /**
2
+ * A page's history, in a panel that slides in from the right (`page-history.js`):
3
+ * every version of the page, newest first, with who saved it and when. Choosing
4
+ * one shows, in the panel, what changed from the version before it.
5
+ */
6
+ import {
7
+ DocumentTypeService,
8
+ DocumentVersionService,
9
+ LanguageService,
10
+ UserService,
11
+ } from '@umbraco-cms/backoffice/external/backend-api'
12
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
13
+ import { UmbModalBaseElement } from '@umbraco-cms/backoffice/modal'
14
+ import { changeCultures, changesIn, versionChanges } from './page-history-model.js'
15
+
16
+ const when = (iso) =>
17
+ new Date(iso).toLocaleString(undefined, { dateStyle: 'medium', timeStyle: 'short' })
18
+
19
+ /** Each property's name by alias, the type's own and its compositions'. */
20
+ async function propertyNames(documentTypeUnique) {
21
+ const names = new Map()
22
+ const seen = new Set()
23
+ const read = async (id) => {
24
+ if (!id || seen.has(id)) return
25
+ seen.add(id)
26
+ const { data } = await DocumentTypeService.getDocumentTypeById({ path: { id } }).catch(
27
+ () => ({}),
28
+ )
29
+ for (const property of data?.properties ?? []) names.set(property.alias, property.name)
30
+ for (const composition of data?.compositions ?? []) await read(composition.documentType?.id)
31
+ }
32
+ await read(documentTypeUnique)
33
+ return names
34
+ }
35
+
36
+ export default class CromboloPageHistoryModalElement extends UmbModalBaseElement {
37
+ static properties = {
38
+ _versions: { state: true },
39
+ _users: { state: true },
40
+ _open: { state: true },
41
+ _changes: { state: true },
42
+ _culture: { state: true },
43
+ _pageCultures: { state: true },
44
+ _problem: { state: true },
45
+ }
46
+
47
+ #names
48
+ /** The site's languages, by ISO code, and which is the default. */
49
+ #languages
50
+
51
+ async connectedCallback() {
52
+ super.connectedCallback()
53
+ try {
54
+ const { data } = await DocumentVersionService.getDocumentVersion({
55
+ query: { documentId: this.data.unique, skip: 0, take: 200 },
56
+ })
57
+ this._versions = data?.items ?? []
58
+ const ids = [...new Set(this._versions.map((v) => v.user?.id).filter(Boolean))]
59
+ const users = ids.length
60
+ ? ((await UserService.getItemUser({ query: { id: ids } }).catch(() => ({}))).data ?? [])
61
+ : []
62
+ this._users = new Map(users.map((u) => [u.id, u.name]))
63
+ } catch {
64
+ this._problem = 'The history of this page could not be read.'
65
+ this._versions = []
66
+ }
67
+ }
68
+
69
+ #who(version) {
70
+ return this._users?.get(version.user?.id) ?? 'Unknown user'
71
+ }
72
+
73
+ async #show(index) {
74
+ const version = this._versions[index]
75
+ const older = this._versions[index + 1]
76
+ this._open = index
77
+ this._changes = undefined
78
+ try {
79
+ this.#names ??= await propertyNames(this.data.documentTypeUnique)
80
+ this.#languages ??= await LanguageService.getLanguage({ query: { skip: 0, take: 100 } })
81
+ .then(({ data }) => data?.items ?? [])
82
+ .catch(() => [])
83
+ const read = async (v) =>
84
+ v
85
+ ? (await DocumentVersionService.getDocumentVersionById({ path: { id: v.id } })).data
86
+ : undefined
87
+ const [after, before] = await Promise.all([read(version), read(older)])
88
+ this._changes = versionChanges(before, after, this.#names)
89
+ this._pageCultures = (after?.variants ?? []).map((v) => v.culture).filter(Boolean)
90
+ const fallback = this.#languages.find((l) => l.isDefault)?.isoCode
91
+ this._culture = changeCultures(this._changes, fallback, this._pageCultures)[0]
92
+ } catch {
93
+ this._changes = []
94
+ this._problem = 'This change could not be read.'
95
+ }
96
+ }
97
+
98
+ #flags(version) {
99
+ return html`${
100
+ version.isCurrentPublishedVersion
101
+ ? html`<uui-tag color="positive" look="secondary">Published</uui-tag>`
102
+ : nothing
103
+ }${version.isCurrentDraftVersion ? html`<uui-tag look="secondary">Current</uui-tag>` : nothing}`
104
+ }
105
+
106
+ #list() {
107
+ if (!this._versions) return html`<uui-loader></uui-loader>`
108
+ if (this._versions.length === 0) return html`<p>This page has no history yet.</p>`
109
+ return html`<ul class="versions" aria-label="Changes to the page">
110
+ ${this._versions.map(
111
+ (version, index) => html`<li>
112
+ <button type="button" @click=${() => this.#show(index)}>
113
+ <span class="when">${when(version.versionDate)}</span>
114
+ <span class="who">${this.#who(version)}</span>
115
+ <span class="flags">${this.#flags(version)}</span>
116
+ </button>
117
+ </li>`,
118
+ )}
119
+ </ul>`
120
+ }
121
+
122
+ /** A chip for each language the changes are in, the default first; the one chosen shows its own. */
123
+ #chips() {
124
+ const fallback = this.#languages?.find((l) => l.isDefault)?.isoCode
125
+ const cultures = this._changes
126
+ ? changeCultures(this._changes, fallback, this._pageCultures ?? [])
127
+ : []
128
+ if (cultures.length === 0) return nothing
129
+ const name = (iso) => this.#languages?.find((l) => l.isoCode === iso)?.name ?? iso
130
+ return html`<div class="chips" role="radiogroup" aria-label="Language">
131
+ ${cultures.map(
132
+ (culture) => html`<button
133
+ type="button"
134
+ role="radio"
135
+ class="chip"
136
+ aria-checked=${culture === this._culture ? 'true' : 'false'}
137
+ title=${name(culture)}
138
+ @click=${() => {
139
+ this._culture = culture
140
+ }}
141
+ >
142
+ ${culture}
143
+ </button>`,
144
+ )}
145
+ </div>`
146
+ }
147
+
148
+ #detail() {
149
+ const version = this._versions[this._open]
150
+ const first = this._open === this._versions.length - 1
151
+ return html`<uui-button look="secondary" compact label="All changes" @click=${() => {
152
+ this._open = undefined
153
+ this._problem = undefined
154
+ }}>← All changes</uui-button>
155
+ <dl class="facts">
156
+ <dt>When</dt><dd>${when(version.versionDate)}</dd>
157
+ <dt>By</dt><dd>${this.#who(version)}</dd>
158
+ ${
159
+ version.isCurrentPublishedVersion || version.isCurrentDraftVersion
160
+ ? html`<dt>Now</dt><dd>${this.#flags(version)}</dd>`
161
+ : nothing
162
+ }
163
+ </dl>
164
+ <h4>${first ? 'What the page was made with' : 'What changed from the version before'}</h4>
165
+ ${this.#chips()}
166
+ ${
167
+ !this._changes
168
+ ? html`<uui-loader></uui-loader>`
169
+ : this._changes.length === 0
170
+ ? html`<p>Nothing changed: the page was saved as it was.</p>`
171
+ : changesIn(this._changes, this._culture).length === 0
172
+ ? html`<p>Nothing changed in ${this._culture}.</p>`
173
+ : html`<uui-table aria-label="Changed properties">
174
+ <uui-table-head>
175
+ <uui-table-head-cell>Property</uui-table-head-cell>
176
+ <uui-table-head-cell>Before</uui-table-head-cell>
177
+ <uui-table-head-cell>After</uui-table-head-cell>
178
+ </uui-table-head>
179
+ ${changesIn(this._changes, this._culture).map(
180
+ (change) => html`<uui-table-row>
181
+ <uui-table-cell
182
+ >${change.label}${change.culture ? html`<small>${change.culture}</small>` : nothing}</uui-table-cell
183
+ >
184
+ <uui-table-cell class="before">${change.before}</uui-table-cell>
185
+ <uui-table-cell>${change.after}</uui-table-cell>
186
+ </uui-table-row>`,
187
+ )}
188
+ </uui-table>`
189
+ }`
190
+ }
191
+
192
+ render() {
193
+ return html`<umb-body-layout headline="Page history">
194
+ <uui-box>
195
+ ${this._problem ? html`<p role="alert">${this._problem}</p>` : nothing}
196
+ ${this._open === undefined ? this.#list() : this.#detail()}
197
+ </uui-box>
198
+ <uui-button slot="actions" label="Close" @click=${() => this._rejectModal()}>Close</uui-button>
199
+ </umb-body-layout>`
200
+ }
201
+
202
+ static styles = css`
203
+ .versions {
204
+ list-style: none;
205
+ margin: 0;
206
+ padding: 0;
207
+ }
208
+ .versions button {
209
+ display: grid;
210
+ /* The same columns in every row, whatever tags a row has, so they line up. */
211
+ grid-template-columns: minmax(0, 13rem) minmax(0, 1fr) 11rem;
212
+ align-items: center;
213
+ gap: var(--uui-size-space-3);
214
+ width: 100%;
215
+ padding: var(--uui-size-space-3);
216
+ border: 0;
217
+ border-bottom: 1px solid var(--uui-color-divider);
218
+ background: none;
219
+ color: inherit;
220
+ font: inherit;
221
+ text-align: left;
222
+ cursor: pointer;
223
+ }
224
+ .versions button:hover {
225
+ background: var(--uui-color-surface-emphasis);
226
+ }
227
+ .who {
228
+ color: var(--uui-color-text-alt);
229
+ }
230
+ .chips {
231
+ display: flex;
232
+ flex-wrap: wrap;
233
+ gap: var(--uui-size-space-2);
234
+ margin-bottom: var(--uui-size-space-4);
235
+ }
236
+ .chip {
237
+ padding: var(--uui-size-space-1) var(--uui-size-space-4);
238
+ border: 1px solid var(--uui-color-border-emphasis);
239
+ border-radius: 999px;
240
+ background: none;
241
+ color: inherit;
242
+ font: inherit;
243
+ cursor: pointer;
244
+ }
245
+ .chip[aria-checked='true'] {
246
+ border-color: var(--uui-color-selected);
247
+ background: var(--uui-color-selected);
248
+ color: var(--uui-color-selected-contrast);
249
+ }
250
+ .flags {
251
+ justify-content: flex-end;
252
+ display: inline-flex;
253
+ gap: var(--uui-size-space-1);
254
+ }
255
+ .facts {
256
+ display: grid;
257
+ grid-template-columns: max-content 1fr;
258
+ gap: var(--uui-size-space-2) var(--uui-size-space-4);
259
+ margin: var(--uui-size-space-4) 0;
260
+ }
261
+ dt {
262
+ font-weight: 700;
263
+ }
264
+ dd {
265
+ margin: 0;
266
+ }
267
+ small {
268
+ display: block;
269
+ color: var(--uui-color-text-alt);
270
+ }
271
+ .before {
272
+ color: var(--uui-color-text-alt);
273
+ }
274
+ `
275
+ }
276
+
277
+ customElements.define('crombolo-page-history-modal', CromboloPageHistoryModalElement)
278
+
279
+ export { CromboloPageHistoryModalElement as element }
@@ -0,0 +1,108 @@
1
+ /**
2
+ * What a page's history panel says of a version (`page-history-modal.js`): what
3
+ * changed from the version before it, a property and a language at a time, each
4
+ * value told in a line. Pure, so it is tested on its own.
5
+ */
6
+
7
+ const LONGEST = 140
8
+
9
+ /** A value in a line: words for text and markup, a count for lists and blocks. */
10
+ export function describeValue(value) {
11
+ if (value === null || value === undefined || value === '') return '(empty)'
12
+ if (typeof value === 'string') return shorten(plain(value))
13
+ if (typeof value === 'number' || typeof value === 'boolean') return String(value)
14
+ if (Array.isArray(value)) {
15
+ if (value.every((item) => typeof item === 'string'))
16
+ return shorten(value.join(', ')) || '(empty)'
17
+ return value.length === 1 ? '1 item' : `${value.length} items`
18
+ }
19
+ if (typeof value === 'object') {
20
+ if (typeof value.markup === 'string') return shorten(plain(value.markup)) || '(empty)'
21
+ const blocks =
22
+ value.contentData ??
23
+ value.layout?.['Umbraco.BlockList'] ??
24
+ value.layout?.['Umbraco.BlockGrid']
25
+ if (Array.isArray(blocks)) return blocks.length === 1 ? '1 block' : `${blocks.length} blocks`
26
+ if (typeof value.src === 'string') return value.src || '(empty)'
27
+ return shorten(JSON.stringify(value))
28
+ }
29
+ return shorten(String(value))
30
+ }
31
+
32
+ const plain = (text) =>
33
+ text
34
+ .replace(/<[^>]*>/g, ' ')
35
+ .replace(/&nbsp;/g, ' ')
36
+ .replace(/\s+/g, ' ')
37
+ .trim()
38
+
39
+ const shorten = (text) => (text.length > LONGEST ? `${text.slice(0, LONGEST - 1)}…` : text)
40
+
41
+ const keyOf = (value) => `${value.alias}|${value.culture ?? ''}|${value.segment ?? ''}`
42
+
43
+ /**
44
+ * What changed from `before` to `after`: the name in each language, then each
45
+ * property, in the order the newer version lists them. With no `before`, the
46
+ * page was made, and everything it held is listed.
47
+ *
48
+ * @param {{ values?: { alias: string, culture?: string | null, segment?: string | null, value: unknown }[], variants?: { culture?: string | null, name?: string }[] } | undefined} before
49
+ * @param {{ values?: { alias: string, culture?: string | null, segment?: string | null, value: unknown }[], variants?: { culture?: string | null, name?: string }[] }} after
50
+ * @param {Map<string, string>} [names] each property's name, by alias
51
+ * @returns {{ label: string, culture: string | null, before: string, after: string }[]}
52
+ */
53
+ export function versionChanges(before, after, names = new Map()) {
54
+ const changes = []
55
+ const oldNames = new Map((before?.variants ?? []).map((v) => [v.culture ?? '', v.name ?? '']))
56
+ for (const variant of after.variants ?? []) {
57
+ const was = oldNames.get(variant.culture ?? '')
58
+ if (was !== (variant.name ?? ''))
59
+ changes.push({
60
+ label: 'Name',
61
+ culture: variant.culture ?? null,
62
+ before: was === undefined ? '(none)' : describeValue(was),
63
+ after: describeValue(variant.name),
64
+ })
65
+ }
66
+ const old = new Map((before?.values ?? []).map((v) => [keyOf(v), v.value]))
67
+ const seen = new Set()
68
+ for (const value of after.values ?? []) {
69
+ const key = keyOf(value)
70
+ seen.add(key)
71
+ const was = old.get(key)
72
+ if (JSON.stringify(was ?? null) === JSON.stringify(value.value ?? null)) continue
73
+ changes.push({
74
+ label: names.get(value.alias) ?? value.alias,
75
+ culture: value.culture ?? null,
76
+ before: describeValue(was),
77
+ after: describeValue(value.value),
78
+ })
79
+ }
80
+ // A value the newer version no longer has was emptied.
81
+ for (const value of before?.values ?? []) {
82
+ if (seen.has(keyOf(value)) || value.value === null || value.value === '') continue
83
+ changes.push({
84
+ label: names.get(value.alias) ?? value.alias,
85
+ culture: value.culture ?? null,
86
+ before: describeValue(value.value),
87
+ after: '(empty)',
88
+ })
89
+ }
90
+ return changes
91
+ }
92
+
93
+ /**
94
+ * The languages to choose between: the page's, and any its changes are in, the
95
+ * default first; none for a page that does not vary by language.
96
+ */
97
+ export function changeCultures(changes, defaultCulture, pageCultures = []) {
98
+ const cultures = [
99
+ ...new Set([...pageCultures, ...changes.map((c) => c.culture)].filter(Boolean)),
100
+ ].sort()
101
+ const first = cultures.find((c) => c.toLowerCase() === (defaultCulture ?? '').toLowerCase())
102
+ return first ? [first, ...cultures.filter((c) => c !== first)] : cultures
103
+ }
104
+
105
+ /** The changes to show for a language: its own, and those every language shares. */
106
+ export function changesIn(changes, culture) {
107
+ return culture ? changes.filter((c) => c.culture === null || c.culture === culture) : changes
108
+ }
@@ -0,0 +1,89 @@
1
+ /**
2
+ * The History box on a page's Info view, in place of Umbraco's list: when the page
3
+ * last changed and by whom, and View all changes, which opens its history in a
4
+ * panel that slides in (`page-history-modal.js`).
5
+ */
6
+ import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/document'
7
+ import { DocumentVersionService, UserService } from '@umbraco-cms/backoffice/external/backend-api'
8
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
9
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
10
+ import { UmbModalToken, umbOpenModal } from '@umbraco-cms/backoffice/modal'
11
+
12
+ export const PAGE_HISTORY_MODAL = 'Crombolo.Modal.PageHistory'
13
+
14
+ const token = new UmbModalToken(PAGE_HISTORY_MODAL, { modal: { type: 'sidebar', size: 'medium' } })
15
+
16
+ export default class CromboloPageHistoryElement extends UmbLitElement {
17
+ static properties = {
18
+ _unique: { state: true },
19
+ _latest: { state: true },
20
+ }
21
+
22
+ #documentTypeUnique
23
+
24
+ constructor() {
25
+ super()
26
+ this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (context) => {
27
+ this.observe(context?.unique, (unique) => {
28
+ this._unique = unique ?? undefined
29
+ this.#documentTypeUnique = context?.getContentTypeUnique?.()
30
+ this.#load()
31
+ })
32
+ })
33
+ }
34
+
35
+ async #load() {
36
+ const unique = this._unique
37
+ if (!unique) return
38
+ const { data } = await DocumentVersionService.getDocumentVersion({
39
+ query: { documentId: unique, skip: 0, take: 1 },
40
+ }).catch(() => ({}))
41
+ if (unique !== this._unique) return
42
+ const latest = data?.items?.[0]
43
+ if (!latest) {
44
+ this._latest = undefined
45
+ return
46
+ }
47
+ const who = latest.user?.id
48
+ ? (await UserService.getItemUser({ query: { id: [latest.user.id] } }).catch(() => ({})))
49
+ .data?.[0]?.name
50
+ : undefined
51
+ this._latest = { date: latest.versionDate, who }
52
+ }
53
+
54
+ async #view() {
55
+ await umbOpenModal(this, token, {
56
+ data: { unique: this._unique, documentTypeUnique: this.#documentTypeUnique },
57
+ }).catch(() => undefined)
58
+ }
59
+
60
+ render() {
61
+ if (!this._unique) return nothing
62
+ const latest = this._latest
63
+ return html`<uui-box headline="History">
64
+ <p>
65
+ ${
66
+ latest
67
+ ? html`Last changed ${new Date(latest.date).toLocaleString(undefined, {
68
+ dateStyle: 'medium',
69
+ timeStyle: 'short',
70
+ })}${latest.who ? ` by ${latest.who}` : ''}.`
71
+ : 'No changes yet.'
72
+ }
73
+ </p>
74
+ <uui-button look="primary" label="View all changes" @click=${this.#view}
75
+ >View all changes</uui-button
76
+ >
77
+ </uui-box>`
78
+ }
79
+
80
+ static styles = css`
81
+ p {
82
+ margin: 0 0 var(--uui-size-space-4);
83
+ }
84
+ `
85
+ }
86
+
87
+ customElements.define('crombolo-page-history', CromboloPageHistoryElement)
88
+
89
+ export { CromboloPageHistoryElement as element }
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Search & sharing",
4
4
  "id": "Crombolo.Seo",
5
- "version": "0.53.2",
5
+ "version": "0.55.0",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {