@crombolo/backoffice-host 0.23.0 → 0.24.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.23.0",
3
+ "version": "0.24.1",
4
4
  "description": "Serves the Umbraco backoffice SPA: shell HTML, import map and package manifests.",
5
5
  "license": "MIT",
6
6
  "author": "Crombolo",
@@ -31,7 +31,7 @@
31
31
  "access": "public"
32
32
  },
33
33
  "dependencies": {
34
- "@crombolo/core": "0.23.0",
34
+ "@crombolo/core": "0.24.1",
35
35
  "@crombolo/backoffice-dist": "18.2.0"
36
36
  }
37
37
  }
@@ -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.23.0",
5
+ "version": "0.24.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -2,7 +2,7 @@
2
2
  "$schema": "../../../backoffice-dist/dist/umbraco-package-schema.json",
3
3
  "name": "Crombolo Assistant",
4
4
  "id": "Crombolo.Assistant",
5
- "version": "0.23.0",
5
+ "version": "0.24.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -0,0 +1,67 @@
1
+ /**
2
+ * Shown in a page's editor when a save was refused because someone else changed
3
+ * the page after it was opened (story 172). The editor's changes stay where
4
+ * they are; the latest version opens in a new tab to compare and copy across.
5
+ */
6
+ import { UMB_DOCUMENT_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/document'
7
+ import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'
8
+ import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
9
+ import { tracker } from './edit-conflicts.js'
10
+
11
+ export default class CromboloEditConflictElement extends UmbElementMixin(LitElement) {
12
+ static properties = { _conflict: { state: true } }
13
+
14
+ constructor() {
15
+ super()
16
+ this._key = undefined
17
+ this._conflict = false
18
+ this.consumeContext(UMB_DOCUMENT_WORKSPACE_CONTEXT, (context) => {
19
+ if (!context) return
20
+ this.observe(context.unique, (unique) => {
21
+ this._key = unique ? String(unique).toLowerCase() : undefined
22
+ this.#refresh()
23
+ })
24
+ })
25
+ }
26
+
27
+ connectedCallback() {
28
+ super.connectedCallback()
29
+ this._unsubscribe = tracker.subscribe(() => this.#refresh())
30
+ }
31
+
32
+ disconnectedCallback() {
33
+ super.disconnectedCallback()
34
+ this._unsubscribe?.()
35
+ }
36
+
37
+ #refresh() {
38
+ this._conflict = this._key ? tracker.hasConflict(this._key) : false
39
+ }
40
+
41
+ #openLatest() {
42
+ window.open(window.location.href, '_blank', 'noopener')
43
+ }
44
+
45
+ render() {
46
+ if (!this._conflict) return nothing
47
+ return html`<div class="conflict" role="alert">
48
+ <uui-icon name="icon-alert"></uui-icon>
49
+ <span>Someone else changed this page after you opened it. Your changes are still here.</span>
50
+ <uui-button look="outline" color="warning" compact @click=${() => this.#openLatest()}>
51
+ Open the latest version in a new tab
52
+ </uui-button>
53
+ </div>`
54
+ }
55
+
56
+ static styles = css`
57
+ :host { display: flex; align-items: center; }
58
+ .conflict {
59
+ display: flex;
60
+ align-items: center;
61
+ gap: var(--uui-size-space-3);
62
+ color: var(--uui-color-warning-standalone);
63
+ }
64
+ `
65
+ }
66
+
67
+ customElements.define('crombolo-edit-conflict', CromboloEditConflictElement)
@@ -0,0 +1,128 @@
1
+ /**
2
+ * An older copy of a page cannot overwrite a newer one (story 172). The server
3
+ * answers a page's read with its revision (`ETag`) and refuses a save based on
4
+ * an older one (412). This remembers, for each page open in an editor, the
5
+ * revision that editor loaded, sends it back with the page's writes, and keeps
6
+ * it current from the editor's own successful writes.
7
+ *
8
+ * Only the editor's own load sets it: another read of the same page (a tree
9
+ * action, the rollback dialog) must not quietly make a stale copy look current.
10
+ */
11
+
12
+ const PAGE_WRITE =
13
+ /\/management\/api\/v1\/document\/([0-9a-f-]{36})(?:\/(update-and-publish|publish|patch))?$/i
14
+ const PAGE_READ = /\/management\/api\/v1\/document\/([0-9a-f-]{36})$/i
15
+
16
+ export function createRevisionTracker() {
17
+ /** The revision each open page was loaded at, by key. */
18
+ const based = new Map()
19
+ /** Pages whose editor is loading them now. */
20
+ const loading = new Map()
21
+ /** Pages a save was refused for, because someone else changed them. */
22
+ const conflicts = new Set()
23
+ const listeners = new Set()
24
+ const changed = () => {
25
+ for (const listener of listeners) listener()
26
+ }
27
+
28
+ const pathOf = (url) => new URL(url, 'http://local').pathname
29
+
30
+ return {
31
+ beginLoad(key) {
32
+ loading.set(key, (loading.get(key) ?? 0) + 1)
33
+ },
34
+ endLoad(key) {
35
+ const count = (loading.get(key) ?? 1) - 1
36
+ if (count > 0) loading.set(key, count)
37
+ else loading.delete(key)
38
+ },
39
+ revisionOf: (key) => based.get(key),
40
+ hasConflict: (key) => conflicts.has(key),
41
+ subscribe(listener) {
42
+ listeners.add(listener)
43
+ return () => listeners.delete(listener)
44
+ },
45
+
46
+ /** Adds `If-Match` to a write of a page whose editor loaded it. */
47
+ onRequest(request) {
48
+ if (request.method === 'GET' || request.headers.has('if-match')) return request
49
+ const write = PAGE_WRITE.exec(pathOf(request.url))
50
+ const revision = write ? based.get(write[1].toLowerCase()) : undefined
51
+ if (revision) request.headers.set('if-match', revision)
52
+ return request
53
+ },
54
+
55
+ /** Learns the revision from the editor's load and its own writes, and hears of a refusal. */
56
+ onResponse(response, request) {
57
+ const path = pathOf(request.url)
58
+ const etag = response.headers.get('etag')
59
+ if (request.method === 'GET') {
60
+ const read = PAGE_READ.exec(path)
61
+ const key = read?.[1].toLowerCase()
62
+ if (key && etag && response.ok && loading.has(key)) {
63
+ based.set(key, etag)
64
+ if (conflicts.delete(key)) changed()
65
+ }
66
+ return response
67
+ }
68
+ const write = PAGE_WRITE.exec(path)
69
+ if (!write) return response
70
+ const key = write[1].toLowerCase()
71
+ if (response.status === 412) {
72
+ conflicts.add(key)
73
+ changed()
74
+ } else if (response.ok && etag) {
75
+ based.set(key, etag)
76
+ if (conflicts.delete(key)) changed()
77
+ }
78
+ return response
79
+ },
80
+ }
81
+ }
82
+
83
+ export const tracker = createRevisionTracker()
84
+
85
+ export const CONFLICT_BANNER = {
86
+ type: 'workspaceFooterApp',
87
+ alias: 'Crombolo.WorkspaceFooterApp.EditConflict',
88
+ name: 'Crombolo Edit Conflict',
89
+ element: () => import('./edit-conflict-banner.js'),
90
+ weight: 1000,
91
+ conditions: [{ alias: 'Umb.Condition.WorkspaceAlias', match: 'Umb.Workspace.Document' }],
92
+ }
93
+
94
+ /**
95
+ * Wraps a workspace's `load` and `reload` so the tracker knows the page's read
96
+ * is the editor's own. Patched on the shared base class, for documents only.
97
+ */
98
+ export function watchLoads(base, revisions = tracker) {
99
+ for (const method of ['load', 'reload']) {
100
+ const original = base.prototype[method]
101
+ if (typeof original !== 'function' || original.cromboloRevisions) continue
102
+ const wrapped = async function (unique) {
103
+ const key = String(unique ?? this.getUnique?.() ?? '').toLowerCase()
104
+ if (this.getEntityType?.() !== 'document' || !key) return original.call(this, unique)
105
+ revisions.beginLoad(key)
106
+ try {
107
+ return await original.call(this, unique)
108
+ } finally {
109
+ revisions.endLoad(key)
110
+ }
111
+ }
112
+ wrapped.cromboloRevisions = true
113
+ base.prototype[method] = wrapped
114
+ }
115
+ }
116
+
117
+ export const onInit = async (_host, extensionRegistry) => {
118
+ const [{ umbHttpClient }, { UmbEntityDetailWorkspaceContextBase }] = await Promise.all([
119
+ import('@umbraco-cms/backoffice/http-client'),
120
+ import('@umbraco-cms/backoffice/workspace'),
121
+ ])
122
+ umbHttpClient.interceptors.request.use((request) => tracker.onRequest(request))
123
+ umbHttpClient.interceptors.response.use((response, request) =>
124
+ tracker.onResponse(response, request),
125
+ )
126
+ watchLoads(UmbEntityDetailWorkspaceContextBase)
127
+ extensionRegistry.register(CONFLICT_BANNER)
128
+ }
@@ -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.23.0",
5
+ "version": "0.24.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 Search & sharing",
4
4
  "id": "Crombolo.Seo",
5
- "version": "0.23.0",
5
+ "version": "0.24.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -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.23.0",
5
+ "version": "0.24.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.23.0",
5
+ "version": "0.24.1",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -99,6 +99,12 @@
99
99
  "name": "Crombolo Media Permissions",
100
100
  "js": "/crombolo-plugin/media-permissions.js"
101
101
  },
102
+ {
103
+ "type": "backofficeEntryPoint",
104
+ "alias": "Crombolo.EntryPoint.EditConflicts",
105
+ "name": "Crombolo Edit Conflicts",
106
+ "js": "/crombolo-plugin/edit-conflicts.js"
107
+ },
102
108
  {
103
109
  "type": "userProfileApp",
104
110
  "alias": "Crombolo.UserProfileApp.SignedInDevices",