@crombolo/backoffice-host 0.51.1 → 0.53.2

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.51.1",
3
+ "version": "0.53.2",
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.51.1",
36
- "@crombolo/backoffice-dist": "0.51.1"
35
+ "@crombolo/core": "0.53.2",
36
+ "@crombolo/backoffice-dist": "0.53.2"
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.51.1",
5
+ "version": "0.53.2",
6
6
  "allowPublicAccess": false,
7
7
  "extensions": [
8
8
  {
@@ -32,6 +32,8 @@ export default {
32
32
  'Welcome to Crombolo! Unfortunately your invite has expired. Please contact your administrator to get a new one.',
33
33
  },
34
34
  user: {
35
+ sectionsHelp:
36
+ 'Pages needs Content. Structure, Components and Workflow setup change the whole site, so give them with care.',
35
37
  changePasswordDescription:
36
38
  "You can change your password for accessing the Crombolo backoffice by filling out the form below and click the 'Change Password' button",
37
39
  createUserHelp:
@@ -54,13 +56,6 @@ export default {
54
56
  general: {
55
57
  umbracoInfo: 'Crombolo info',
56
58
  },
57
- buttons: {
58
- // The accessible name of the header logo button, on every page of the editor.
59
- // Nothing renders it as visible text, which is why the first sweep through
60
- // these dictionaries missed it; it surfaced in the accessibility snapshot
61
- // attached to an unrelated Playwright failure.
62
- viewSystemDetails: 'View Crombolo system information and version number',
63
- },
64
59
  visuallyHiddenTexts: {
65
60
  searchOverlayTitle: 'Search the Crombolo backoffice',
66
61
  },
@@ -92,10 +87,13 @@ export default {
92
87
  create: {
93
88
  // The create options on the Components tree. The folder option is Umbraco's
94
89
  // own and already reads correctly.
95
- newEmptyPartialView: 'Empty component',
90
+ newEmptyPartialView: 'Component',
91
+ newModule: 'Module',
96
92
  newPartialViewFromSnippet: 'Component from snippet',
97
93
  },
98
94
  treeHeaders: {
95
+ // Components, modules, stylesheets and scripts: more than templates.
96
+ templatingGroup: 'Code',
99
97
  // One tree over one directory: templates and partial views are the same
100
98
  // kind of file here, and what makes one a template is that a content type
101
99
  // names it, not where it sits.
@@ -3,7 +3,7 @@
3
3
  * Umbraco's own editors show them, given `items` of `{ label, href? }`. The last
4
4
  * item is the page itself; an item without `href` is not a link.
5
5
  */
6
- import { html, ifDefined } from '@umbraco-cms/backoffice/external/lit'
6
+ import { html, ifDefined, repeat } from '@umbraco-cms/backoffice/external/lit'
7
7
  import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
8
 
9
9
  export class CromboloBreadcrumbElement extends UmbLitElement {
@@ -17,7 +17,11 @@ export class CromboloBreadcrumbElement extends UmbLitElement {
17
17
  render() {
18
18
  return html`<nav aria-label="Breadcrumb">
19
19
  <uui-breadcrumbs>
20
- ${this.items.map(
20
+ ${repeat(
21
+ this.items,
22
+ // Keyed on the length: UUI marks the last crumb and never unmarks it, so one
23
+ // kept while the trail grows would stay the page itself and lose its link.
24
+ (_, index) => `${this.items.length}:${index}`,
21
25
  (item) =>
22
26
  html`<uui-breadcrumb-item href=${ifDefined(item.href)}>${item.label}</uui-breadcrumb-item>`,
23
27
  )}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * What the Content section opens on (story 288): the first page in the tree this
3
+ * user may open, or a word saying there is none. The address is
4
+ * replaced, so the back button leaves the section rather than coming back here.
5
+ */
6
+ import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user'
7
+ import {
8
+ UMB_DOCUMENT_CREATE_OPTIONS_MODAL,
9
+ UmbDocumentTreeRepository,
10
+ } from '@umbraco-cms/backoffice/document'
11
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
12
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
13
+ import { umbOpenModal } from '@umbraco-cms/backoffice/modal'
14
+
15
+ const base = () =>
16
+ (document.querySelector('base')?.getAttribute('href') ?? '/umbraco/').replace(/\/$/, '')
17
+
18
+ const here = () => location.pathname.slice(base().length)
19
+
20
+ const CREATE = 'Umb.Document.Create'
21
+ const PAGE = 100
22
+
23
+ export default class CromboloContentHomeDashboardElement extends UmbLitElement {
24
+ static properties = {
25
+ _empty: { state: true },
26
+ _mayCreate: { state: true },
27
+ }
28
+
29
+ constructor() {
30
+ super()
31
+ this.consumeContext(UMB_CURRENT_USER_CONTEXT, (user) => {
32
+ this.observe(user?.currentUser, (current) => {
33
+ this._mayCreate = current?.fallbackPermissions.includes(CREATE) ?? false
34
+ })
35
+ })
36
+ }
37
+
38
+ connectedCallback() {
39
+ super.connectedCallback()
40
+ this.#open()
41
+ }
42
+
43
+ /**
44
+ * The first page this user may open. The tree also lists the pages above their
45
+ * start node, marked `noAccess`, to show where it sits, so those are looked inside.
46
+ */
47
+ async #firstPage(repository, parent) {
48
+ const page = { skip: 0, take: PAGE }
49
+ const { data } = await (parent
50
+ ? repository.requestTreeItemsOf({ ...page, parent })
51
+ : repository.requestTreeRootItems(page))
52
+ const items = data?.items ?? []
53
+ const open = items.find((item) => !item.noAccess)
54
+ if (open) return open
55
+ for (const item of items) {
56
+ if (!item.hasChildren) continue
57
+ const found = await this.#firstPage(repository, {
58
+ unique: item.unique,
59
+ entityType: item.entityType,
60
+ })
61
+ if (found) return found
62
+ }
63
+ return undefined
64
+ }
65
+
66
+ async #open() {
67
+ const home = await this.#firstPage(new UmbDocumentTreeRepository(this))
68
+ // Someone may have gone elsewhere from the menu while this was looking.
69
+ if (!this.isConnected || !/^\/section\/content(\/dashboard\/.*|\/)?$/.test(here())) return
70
+ if (!home) {
71
+ this._empty = true
72
+ return
73
+ }
74
+ history.replaceState(
75
+ null,
76
+ '',
77
+ `${base()}/section/content/workspace/document/edit/${home.unique}`,
78
+ )
79
+ }
80
+
81
+ #newPage() {
82
+ umbOpenModal(this, UMB_DOCUMENT_CREATE_OPTIONS_MODAL, {
83
+ data: { parent: { unique: null, entityType: 'document-root' }, documentType: null },
84
+ }).catch(() => undefined)
85
+ }
86
+
87
+ render() {
88
+ if (!this._empty) return html`<uui-loader></uui-loader>`
89
+ return html`<uui-box>
90
+ <h2>No pages yet</h2>
91
+ <p>There are no pages here for you to open.</p>
92
+ ${
93
+ this._mayCreate
94
+ ? html`<uui-button
95
+ look="primary"
96
+ label="New content"
97
+ @click=${() => this.#newPage()}
98
+ ></uui-button>`
99
+ : nothing
100
+ }
101
+ </uui-box>`
102
+ }
103
+
104
+ static styles = css`
105
+ :host {
106
+ display: block;
107
+ padding: var(--uui-size-layout-1);
108
+ max-width: 40rem;
109
+ }
110
+ h2 { margin: 0 0 var(--uui-size-space-3); }
111
+ p { margin: 0 0 var(--uui-size-space-5); color: var(--uui-color-text-alt); }
112
+ `
113
+ }
114
+
115
+ customElements.define('crombolo-content-home-dashboard', CromboloContentHomeDashboardElement)
@@ -0,0 +1,65 @@
1
+ /**
2
+ * What the menu under Content offers (story 289), and which item a page belongs
3
+ * to. Pure, so each is tested on its own. Structure and Code stay in
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.
6
+ */
7
+ import { treeFor } from './settings-cards.js'
8
+
9
+ const STRUCTURE = 'Crombolo.Section.Structure'
10
+ const COMPONENTS = 'Crombolo.Section.Components'
11
+ const WORKFLOW_SETUP = 'Crombolo.Section.WorkflowSetup'
12
+ /** Reading forms, which is what a group's Forms comes to. */
13
+ const FORM_READ = 'Crombolo.Form.Read'
14
+ const FORMS = 'Crombolo.Section.Forms'
15
+ const CONTENT = 'Umb.Section.Content'
16
+
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
+ const ITEMS = [
21
+ { label: 'Pages', path: 'section/content', section: CONTENT },
22
+ {
23
+ label: 'Structure',
24
+ path: 'section/settings/structure',
25
+ section: STRUCTURE,
26
+ or: STRUCTURE_FORMS,
27
+ },
28
+ { label: 'Code', path: 'section/settings/code', section: COMPONENTS },
29
+ { label: 'Workflows', path: 'section/forms/view/workflows', section: WORKFLOW_SETUP },
30
+ ]
31
+
32
+ /**
33
+ * The items this user may open. One alone is no menu, so it offers none.
34
+ *
35
+ * @param {{ allowedSections?: string[], fallbackPermissions?: string[], isAdmin?: boolean } | undefined} user
36
+ */
37
+ export function stripItems(user) {
38
+ const allowed = user?.allowedSections ?? []
39
+ const may = (verb) => user?.isAdmin === true || (user?.fallbackPermissions ?? []).includes(verb)
40
+ const items = ITEMS.flatMap((item) => {
41
+ 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
+ : []
45
+ })
46
+ return items.length > 1 ? items : []
47
+ }
48
+
49
+ /**
50
+ * The item a path below the back office belongs to, or undefined.
51
+ *
52
+ * @param {string} path e.g. `section/settings/workspace/document-type/edit/1`
53
+ */
54
+ export function activeItem(path) {
55
+ const section = /^section\/([^/]+)(?:\/(.*))?$/.exec(path)
56
+ if (!section) return undefined
57
+ const [, name, rest = ''] = section
58
+ if (name === 'content') return 'Pages'
59
+ if (name === 'forms') return rest.startsWith('view/workflows') ? 'Workflows' : 'Structure'
60
+ if (name !== 'settings') return undefined
61
+ if (rest.startsWith('structure') || rest.startsWith('forms')) return 'Structure'
62
+ if (rest.startsWith('code')) return 'Code'
63
+ const tree = treeFor(/^workspace\/([^/]+)/.exec(rest)?.[1])
64
+ return tree === 'structure' ? 'Structure' : tree === 'code' ? 'Code' : undefined
65
+ }
@@ -0,0 +1,120 @@
1
+ /**
2
+ * The menu under Content (story 289): Pages, Structure, Code and Workflows, for whoever may open them. A row of its own under the header, shown
3
+ * wherever one of them is open, and it keeps Content's tab marked while it shows.
4
+ */
5
+ import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user'
6
+ import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
7
+ import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
8
+ import { activeItem, stripItems } from './content-strip-items.js'
9
+
10
+ const CONTENT = 'Umb.Section.Content'
11
+ const ROW_HEIGHT = '--crombolo-content-strip-height'
12
+
13
+ const pathHere = () => {
14
+ const base = new URL(document.baseURI).pathname
15
+ return location.pathname.startsWith(base) ? location.pathname.slice(base.length) : ''
16
+ }
17
+
18
+ const mark = (section) =>
19
+ window.dispatchEvent(new CustomEvent('crombolo:mark-section', { detail: section }))
20
+
21
+ export default class CromboloContentStripElement extends UmbLitElement {
22
+ static properties = {
23
+ _items: { state: true },
24
+ _active: { state: true },
25
+ }
26
+
27
+ #follow = () => {
28
+ this._active = activeItem(pathHere())
29
+ this.#sync()
30
+ }
31
+
32
+ /** The header marks Content, and the back office makes room, only while the row shows. */
33
+ #sync() {
34
+ const shown = this.#shown()
35
+ mark(shown ? CONTENT : undefined)
36
+ if (shown) document.documentElement.style.setProperty(ROW_HEIGHT, '41px')
37
+ else document.documentElement.style.removeProperty(ROW_HEIGHT)
38
+ }
39
+
40
+ #shown() {
41
+ return this._items.length > 0 && this._active !== undefined
42
+ }
43
+
44
+ constructor() {
45
+ super()
46
+ this._items = []
47
+ this.consumeContext(UMB_CURRENT_USER_CONTEXT, (user) => {
48
+ this.observe(user?.currentUser, (current) => {
49
+ this._items = stripItems(current)
50
+ this.#sync()
51
+ })
52
+ })
53
+ }
54
+
55
+ connectedCallback() {
56
+ super.connectedCallback()
57
+ this.#follow()
58
+ window.addEventListener('changestate', this.#follow)
59
+ window.addEventListener('popstate', this.#follow)
60
+ // A route the router settles on without a state change of its own, such as Home.
61
+ window.addEventListener('navigationend', this.#follow)
62
+ }
63
+
64
+ disconnectedCallback() {
65
+ super.disconnectedCallback()
66
+ window.removeEventListener('changestate', this.#follow)
67
+ window.removeEventListener('popstate', this.#follow)
68
+ window.removeEventListener('navigationend', this.#follow)
69
+ mark(undefined)
70
+ document.documentElement.style.removeProperty(ROW_HEIGHT)
71
+ }
72
+
73
+ render() {
74
+ if (!this.#shown()) return nothing
75
+ return html`<nav aria-label="Content">
76
+ ${this._items.map(
77
+ (item) =>
78
+ html`<a
79
+ href=${new URL(item.path, document.baseURI).pathname}
80
+ aria-current=${item.label === this._active ? 'page' : 'false'}
81
+ >${item.label}</a
82
+ >`,
83
+ )}
84
+ </nav>`
85
+ }
86
+
87
+ static styles = css`
88
+ nav {
89
+ box-sizing: border-box;
90
+ display: flex;
91
+ align-items: center;
92
+ gap: var(--uui-size-space-2);
93
+ height: 41px;
94
+ padding: 0 var(--uui-size-space-5);
95
+ overflow-x: auto;
96
+ background: var(--uui-color-surface);
97
+ border-bottom: 1px solid var(--uui-color-border);
98
+ }
99
+ a {
100
+ padding: var(--uui-size-space-1) var(--uui-size-space-3);
101
+ white-space: nowrap;
102
+ border-radius: var(--uui-border-radius);
103
+ color: var(--uui-color-text);
104
+ font-size: var(--uui-type-small-size);
105
+ text-decoration: none;
106
+ }
107
+ a:hover {
108
+ background: var(--uui-color-surface-emphasis);
109
+ }
110
+ a[aria-current='page'] {
111
+ background: var(--crombolo-terracotta-tint, var(--uui-color-surface-alt));
112
+ font-weight: 700;
113
+ }
114
+ `
115
+ }
116
+
117
+ customElements.define('crombolo-content-strip', CromboloContentStripElement)
118
+
119
+ /** Loaded on its own so that the element the header draws is defined. */
120
+ export const onInit = () => {}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Forms and workflows as a tree (story 289): folders from their paths, each
3
+ * with its folders and its items. Pure, so it is tested on its own.
4
+ */
5
+
6
+ const byName = (a, b) => a.name.localeCompare(b.name)
7
+
8
+ /**
9
+ * @param {{ alias: string, name: string, folder?: string }[]} items
10
+ * @param {string[]} folders every folder as `a/b`, empty ones included
11
+ * @returns {{ name: string, path: string, folders: any[], items: any[] }}
12
+ */
13
+ export function definitionTree(items, folders) {
14
+ const root = { name: '', path: '', folders: [], items: [] }
15
+ const nodes = new Map([['', root]])
16
+ const nodeFor = (path) => {
17
+ const found = nodes.get(path)
18
+ if (found) return found
19
+ const slash = path.lastIndexOf('/')
20
+ const parent = nodeFor(slash === -1 ? '' : path.slice(0, slash))
21
+ const node = { name: path.slice(slash + 1), path, folders: [], items: [] }
22
+ parent.folders.push(node)
23
+ nodes.set(path, node)
24
+ return node
25
+ }
26
+ for (const folder of folders) nodeFor(folder)
27
+ for (const item of items) nodeFor(item.folder ?? '').items.push(item)
28
+ const sort = (node) => {
29
+ node.folders.sort(byName)
30
+ node.items.sort(byName)
31
+ node.folders.forEach(sort)
32
+ }
33
+ sort(root)
34
+ return root
35
+ }
36
+
37
+ /** Why a kind cannot be changed here, in words for the person reading it, or undefined. */
38
+ export function readOnlyWords(kind, because) {
39
+ if (because === 'site')
40
+ return `${kind} are kept with this site's files, so they can't be changed here. To change one, edit it in the site's code and deploy it.`
41
+ if (because === 'permission') return `Your group can't change ${kind.toLowerCase()}.`
42
+ return undefined
43
+ }