@crombolo/backoffice-host 0.57.0 → 0.58.1

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@crombolo/backoffice-host",
3
- "version": "0.57.0",
3
+ "version": "0.58.1",
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.57.0",
36
- "@crombolo/backoffice-dist": "0.57.0"
35
+ "@crombolo/core": "0.58.1",
36
+ "@crombolo/backoffice-dist": "0.58.1"
37
37
  }
38
38
  }
@@ -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.57.0",
5
+ "version": "0.58.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -28,6 +28,9 @@ export function signatureWords(provenance, refused, policy) {
28
28
  } else if (provenance?.state === 'local') {
29
29
  label = 'From this site'
30
30
  detail = "Linked from this site's own code, not from a package registry."
31
+ } else if (provenance?.state === 'vouched') {
32
+ label = 'From the host'
33
+ detail = 'Applied by the platform that runs this site, which checked where it came from.'
31
34
  } else if (provenance?.state === 'unchecked') {
32
35
  tone = 'warning'
33
36
  label = "Couldn't be checked right now"
@@ -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.57.0",
5
+ "version": "0.58.1",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -33,3 +33,7 @@ export const readPreview = (documentKey, culture) => {
33
33
  if (culture) query.set('culture', culture)
34
34
  return json(`/preview?${query}`)
35
35
  }
36
+
37
+ /** Every page of a type's values (story 317): `{ title, description, image, canonical }`. */
38
+ export const saveTypeValues = (contentType, seo) =>
39
+ json('/type', { method: 'PUT', body: JSON.stringify({ contentType, seo }) })
@@ -5,34 +5,55 @@
5
5
  * The values come from the server, which works them out with the same code the
6
6
  * page's head uses, so the preview cannot disagree with what is served. It
7
7
  * reads the last saved version, so an editor sees a change once it is saved.
8
+ *
9
+ * An administrator may set where each value comes from (story 317), for this
10
+ * page, in its own field, or for every page of its type.
8
11
  */
9
12
  import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/document'
10
13
  import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
11
14
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
12
15
  import { UMB_PROPERTY_DATASET_CONTEXT } from '@umbraco-cms/backoffice/property'
13
- import { readPreview } from './client.js'
16
+ import { UmbVariantId } from '@umbraco-cms/backoffice/variant'
17
+ import { readPreview, saveTypeValues } from './client.js'
18
+ import './value-input.js'
14
19
 
15
20
  const SOURCES = {
16
21
  page: 'From this page',
22
+ type: "This type's setting",
23
+ metadata: 'From the page design',
17
24
  template: 'From the page design',
18
25
  site: 'Site setting',
19
26
  name: 'Page name',
20
27
  none: 'Not configured',
21
28
  }
22
29
 
30
+ /** Each value, the page's own field for it, and what it is called. */
31
+ const FIELDS = {
32
+ title: { label: 'Title', alias: 'seoTitle' },
33
+ description: { label: 'Description', alias: 'seoDescription' },
34
+ image: { label: 'Sharing image', alias: 'seoImage' },
35
+ canonical: { label: 'Preferred address', alias: 'seoCanonical' },
36
+ }
37
+
23
38
  export default class CromboloSeoDocumentViewElement extends UmbLitElement {
24
39
  static properties = {
25
40
  _preview: { state: true },
26
41
  _error: { state: true },
42
+ _editing: { state: true },
43
+ _draft: { state: true },
44
+ _saving: { state: true },
45
+ _problem: { state: true },
27
46
  }
28
47
 
29
48
  #unique = undefined
30
49
  #culture = null
50
+ #workspace = undefined
31
51
 
32
52
  constructor() {
33
53
  super()
34
54
  this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (context) => {
35
55
  if (!context) return
56
+ this.#workspace = context
36
57
  this.observe(context.unique, (unique) => {
37
58
  this.#unique = unique
38
59
  this.#load()
@@ -54,10 +75,11 @@ export default class CromboloSeoDocumentViewElement extends UmbLitElement {
54
75
  }
55
76
  }
56
77
 
57
- #row(label, item, render = (value) => value) {
78
+ #row(field, item, render = (value) => value) {
79
+ const canEdit = this._preview?.mapping?.canEdit
58
80
  return html`
59
81
  <tr>
60
- <th>${label}</th>
82
+ <th>${FIELDS[field].label}</th>
61
83
  <td>${item.value ? render(item.value) : '-'}</td>
62
84
  <td>
63
85
  ${
@@ -65,6 +87,163 @@ export default class CromboloSeoDocumentViewElement extends UmbLitElement {
65
87
  ? html`<span class="unset"><uui-icon name="icon-alert"></uui-icon>Not configured</span>`
66
88
  : html`<uui-tag look="secondary">${SOURCES[item.source] ?? item.source}</uui-tag>`
67
89
  }
90
+ ${
91
+ item.over === 'type'
92
+ ? html`<div class="note">The page design overrides this type's setting.</div>`
93
+ : nothing
94
+ }
95
+ </td>
96
+ ${
97
+ canEdit
98
+ ? html`<td class="action">
99
+ <uui-button
100
+ look="secondary"
101
+ compact
102
+ label="Change where the ${FIELDS[field].label.toLowerCase()} comes from"
103
+ @click=${() => this.#edit(field)}
104
+ >Change</uui-button>
105
+ </td>`
106
+ : nothing
107
+ }
108
+ </tr>
109
+ ${this._editing === field ? this.#editor(field) : nothing}
110
+ `
111
+ }
112
+
113
+ /** The variant a page's own field is set in: its culture's, when the field varies. */
114
+ async #variantFor(alias) {
115
+ const property = await this.#workspace?.structure?.getPropertyStructureByAlias?.(alias)
116
+ return property?.variesByCulture && this.#culture
117
+ ? UmbVariantId.CreateFromPartial({ culture: this.#culture })
118
+ : UmbVariantId.CreateInvariant()
119
+ }
120
+
121
+ async #edit(field) {
122
+ const { alias } = FIELDS[field]
123
+ const typeValue = this._preview?.mapping?.type?.seo?.[field] ?? ''
124
+ const own =
125
+ field === 'image'
126
+ ? ''
127
+ : this.#workspace?.getPropertyValue?.(alias, await this.#variantFor(alias))
128
+ this._draft = typeof own === 'string' && own.trim() ? own : typeValue
129
+ this._problem = undefined
130
+ this._editing = field
131
+ }
132
+
133
+ async #saveForPage(field) {
134
+ const { alias } = FIELDS[field]
135
+ this._saving = true
136
+ try {
137
+ await this.#workspace.setPropertyValue(
138
+ alias,
139
+ this._draft ?? '',
140
+ await this.#variantFor(alias),
141
+ )
142
+ await this.#workspace.requestSave()
143
+ this._editing = undefined
144
+ await this.#load()
145
+ } catch (error) {
146
+ this._problem = error.message
147
+ } finally {
148
+ this._saving = false
149
+ }
150
+ }
151
+
152
+ async #saveForType(field) {
153
+ const type = this._preview.mapping.type
154
+ this._saving = true
155
+ try {
156
+ await saveTypeValues(type.alias, { ...type.seo, [field]: this._draft ?? '' })
157
+ this._editing = undefined
158
+ await this.#load()
159
+ } catch (error) {
160
+ this._problem = error.message
161
+ } finally {
162
+ this._saving = false
163
+ }
164
+ }
165
+
166
+ #editor(field) {
167
+ const { mapping } = this._preview
168
+ const type = mapping.type
169
+ const span = mapping.canEdit ? 4 : 3
170
+ const pages = `${type.pages} ${type.pages === 1 ? 'page' : 'pages'}`
171
+ return html`
172
+ <tr class="editing">
173
+ <td colspan=${span}>
174
+ ${
175
+ field === 'image'
176
+ ? html`<uui-select
177
+ label="Sharing image"
178
+ .options=${[
179
+ { name: 'None', value: '', selected: !this._draft },
180
+ ...mapping.properties
181
+ .filter((p) => p.mediaPicker)
182
+ .map((p) => ({
183
+ name: p.name,
184
+ value: p.alias,
185
+ selected: this._draft === p.alias,
186
+ })),
187
+ ]}
188
+ @change=${(event) => {
189
+ this._draft = event.target.value
190
+ }}
191
+ ></uui-select>
192
+ <p class="note">
193
+ The first image the chosen picker holds. A page's own sharing image is picked
194
+ in its Search &amp; sharing fields.
195
+ </p>`
196
+ : html`<crombolo-seo-value-input
197
+ label=${FIELDS[field].label}
198
+ .value=${this._draft ?? ''}
199
+ .properties=${mapping.properties.map(({ alias, name }) => ({ alias, name }))}
200
+ @change=${(event) => {
201
+ this._draft = event.target.value
202
+ }}
203
+ ></crombolo-seo-value-input>
204
+ <p class="note">
205
+ Type text, <code>{</code> for one of this page's values, or <code>{#</code> for a
206
+ dictionary word.
207
+ </p>`
208
+ }
209
+ ${this._problem ? html`<p class="warning">${this._problem}</p>` : nothing}
210
+ <div class="choices">
211
+ ${
212
+ field === 'image'
213
+ ? nothing
214
+ : html`<uui-button
215
+ look="primary"
216
+ label="This page only"
217
+ ?disabled=${this._saving}
218
+ @click=${() => this.#saveForPage(field)}
219
+ ></uui-button>`
220
+ }
221
+ ${
222
+ type.editable
223
+ ? html`<uui-button
224
+ look=${field === 'image' ? 'primary' : 'secondary'}
225
+ label="Every ${type.name} page (${pages})"
226
+ ?disabled=${this._saving}
227
+ @click=${() => this.#saveForType(field)}
228
+ ></uui-button>`
229
+ : nothing
230
+ }
231
+ <uui-button
232
+ look="default"
233
+ label="Cancel"
234
+ @click=${() => {
235
+ this._editing = undefined
236
+ }}
237
+ ></uui-button>
238
+ </div>
239
+ ${
240
+ type.editable
241
+ ? nothing
242
+ : html`<p class="note">
243
+ Every ${type.name} page's setting is kept with the site's files here, so it
244
+ changes with a deploy.
245
+ </p>`
246
+ }
68
247
  </td>
69
248
  </tr>
70
249
  `
@@ -104,10 +283,10 @@ export default class CromboloSeoDocumentViewElement extends UmbLitElement {
104
283
  }
105
284
  <h4>Searchable property values</h4>
106
285
  <table>
107
- ${this.#row('Title', meta.title)}
108
- ${this.#row('Description', meta.description)}
109
- ${this.#row('Sharing image', meta.image, (src) => html`<img src=${src} alt="" />`)}
110
- ${this.#row('Preferred address', meta.canonical)}
286
+ ${this.#row('title', meta.title)}
287
+ ${this.#row('description', meta.description)}
288
+ ${this.#row('image', meta.image, (src) => html`<img src=${src} alt="" />`)}
289
+ ${this.#row('canonical', meta.canonical)}
111
290
  </table>
112
291
  </uui-box>
113
292
  `
@@ -183,6 +362,19 @@ export default class CromboloSeoDocumentViewElement extends UmbLitElement {
183
362
  max-width: 240px;
184
363
  max-height: 140px;
185
364
  }
365
+ td.action {
366
+ width: 1%;
367
+ white-space: nowrap;
368
+ }
369
+ tr.editing td {
370
+ background: var(--uui-color-surface-alt);
371
+ }
372
+ .choices {
373
+ display: flex;
374
+ flex-wrap: wrap;
375
+ gap: var(--uui-size-space-2);
376
+ margin-top: var(--uui-size-space-3);
377
+ }
186
378
  `
187
379
  }
188
380
 
@@ -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.57.0",
5
+ "version": "0.58.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,101 @@
1
+ /**
2
+ * A search and sharing value's box (story 317): fixed text, `{alias}` for a
3
+ * property of the page, suggested after `{`, and `{#key}` for a dictionary item,
4
+ * suggested after `{#`. It sends `change`, with `value`, as `uui-input` does.
5
+ */
6
+ import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
7
+ import '../form-word-input.js'
8
+ import { insertProperty, propertySuggestions } from './value-model.js'
9
+
10
+ export default class CromboloSeoValueInputElement extends LitElement {
11
+ static properties = {
12
+ label: { type: String },
13
+ value: { type: String },
14
+ /** The page type's properties: `{ alias, name }`. */
15
+ properties: { attribute: false },
16
+ _typing: { state: true },
17
+ }
18
+
19
+ constructor() {
20
+ super()
21
+ this.value = ''
22
+ this.properties = []
23
+ this._typing = ''
24
+ }
25
+
26
+ #choose(alias) {
27
+ this.value = insertProperty(this.value, alias)
28
+ this._typing = ''
29
+ this.dispatchEvent(new Event('change', { bubbles: true }))
30
+ }
31
+
32
+ render() {
33
+ const offered = propertySuggestions(this.properties ?? [], this._typing)
34
+ return html`
35
+ <crombolo-form-word-input
36
+ label=${this.label}
37
+ .value=${this.value ?? ''}
38
+ @input=${(event) => {
39
+ event.stopPropagation()
40
+ this._typing = event.target.value ?? ''
41
+ }}
42
+ @change=${(event) => {
43
+ event.stopPropagation()
44
+ this.value = event.target.value ?? ''
45
+ this._typing = ''
46
+ this.dispatchEvent(new Event('change', { bubbles: true }))
47
+ }}
48
+ ></crombolo-form-word-input>
49
+ ${
50
+ offered.length > 0
51
+ ? html`<ul role="listbox" aria-label="Properties of this page">
52
+ ${offered.map(
53
+ (property) => html`<li
54
+ role="option"
55
+ @mousedown=${(event) => {
56
+ event.preventDefault()
57
+ this.value = this._typing
58
+ this.#choose(property.alias)
59
+ }}
60
+ >
61
+ <strong>${property.name}</strong> <code>{${property.alias}}</code>
62
+ </li>`,
63
+ )}
64
+ </ul>`
65
+ : nothing
66
+ }
67
+ `
68
+ }
69
+
70
+ static styles = css`
71
+ :host {
72
+ display: block;
73
+ position: relative;
74
+ }
75
+ ul {
76
+ position: absolute;
77
+ z-index: 10;
78
+ left: 0;
79
+ right: 0;
80
+ margin: 2px 0 0;
81
+ padding: var(--uui-size-space-1) 0;
82
+ list-style: none;
83
+ background: var(--uui-color-surface);
84
+ border: 1px solid var(--uui-color-border);
85
+ border-radius: var(--uui-border-radius);
86
+ box-shadow: var(--uui-shadow-depth-2);
87
+ }
88
+ li {
89
+ padding: var(--uui-size-space-2) var(--uui-size-space-4);
90
+ cursor: pointer;
91
+ }
92
+ li:hover {
93
+ background: var(--uui-color-surface-emphasis);
94
+ }
95
+ code {
96
+ color: var(--uui-color-text-alt);
97
+ }
98
+ `
99
+ }
100
+
101
+ customElements.define('crombolo-seo-value-input', CromboloSeoValueInputElement)
@@ -0,0 +1,36 @@
1
+ /**
2
+ * What a search and sharing value's box suggests (story 317): typing `{` offers
3
+ * the page type's properties, chosen as `{alias}`; `{#` is the dictionary's, which
4
+ * `crombolo-form-word-input` offers. Pure, so it is tested on its own.
5
+ */
6
+ const ROWS = 8
7
+ /** A property's alias being typed at the end of the text: after a `{` that is not `{{` or `{#`. */
8
+ const TYPING = /(?<!\{)\{(?!#)([^{}\s]*)$/
9
+
10
+ /** What has been typed of a property's alias at the end of the text, and where its `{` is. */
11
+ export function typedProperty(value) {
12
+ const match = TYPING.exec(value ?? '')
13
+ return match ? { typed: match[1] ?? '', start: match.index } : undefined
14
+ }
15
+
16
+ /** The properties to offer for what has been typed: aliases or names starting with it first. */
17
+ export function propertySuggestions(properties, value) {
18
+ const at = typedProperty(value)
19
+ if (!at) return []
20
+ const typed = at.typed.toLowerCase()
21
+ const starts = (p) =>
22
+ p.alias.toLowerCase().startsWith(typed) || p.name.toLowerCase().startsWith(typed)
23
+ const contains = (p) =>
24
+ p.alias.toLowerCase().includes(typed) || p.name.toLowerCase().includes(typed)
25
+ return [
26
+ ...properties.filter(starts),
27
+ ...properties.filter((p) => !starts(p) && contains(p)),
28
+ ].slice(0, ROWS)
29
+ }
30
+
31
+ /** The text with the alias being typed at its end made `{alias}`. */
32
+ export function insertProperty(value, alias) {
33
+ const at = typedProperty(value)
34
+ const start = at ? at.start : (value ?? '').length
35
+ return `${(value ?? '').slice(0, start)}{${alias}}`
36
+ }
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Sign-in Dialog",
4
4
  "id": "Crombolo.SignInDialog",
5
- "version": "0.57.0",
5
+ "version": "0.58.1",
6
6
  "allowPublicAccess": true,
7
7
  "extensions": [
8
8
  {
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo",
4
4
  "id": "Crombolo.Core",
5
- "version": "0.57.0",
5
+ "version": "0.58.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {