@crombolo/backoffice-host 0.29.1 → 0.30.3
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 +2 -2
- package/plugin/app-preview/umbraco-package.json +1 -1
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/side-panel/context.js +128 -0
- package/plugin/side-panel/host.js +333 -0
- package/plugin/side-panel/layout.js +94 -0
- package/plugin/side-panel/toggle.js +73 -0
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/umbraco-package.json +13 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/backoffice-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.30.3",
|
|
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.
|
|
34
|
+
"@crombolo/core": "0.30.3",
|
|
35
35
|
"@crombolo/backoffice-dist": "18.2.0"
|
|
36
36
|
}
|
|
37
37
|
}
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The side-panel context (story 182), provided for the whole back office and
|
|
3
|
+
* consumed by its string alias, `Crombolo.Context.SidePanel`, so an extension
|
|
4
|
+
* imports nothing of ours. One panel is open at a time; which one and how wide
|
|
5
|
+
* are remembered per user in this browser.
|
|
6
|
+
*/
|
|
7
|
+
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'
|
|
8
|
+
import { UMB_CURRENT_USER_CONTEXT } from '@umbraco-cms/backoffice/current-user'
|
|
9
|
+
import {
|
|
10
|
+
UmbNumberState,
|
|
11
|
+
UmbObjectState,
|
|
12
|
+
UmbStringState,
|
|
13
|
+
} from '@umbraco-cms/backoffice/observable-api'
|
|
14
|
+
import { clampWidth, limitsOf, maxWidthFor, SIDE_PANEL_CONTEXT, store, stored } from './layout.js'
|
|
15
|
+
|
|
16
|
+
export class CromboloSidePanelContext extends UmbContextBase {
|
|
17
|
+
#active = new UmbStringState(null)
|
|
18
|
+
#width = new UmbNumberState(0)
|
|
19
|
+
#available = new UmbObjectState({})
|
|
20
|
+
/** alias → the panel's meta, as the host found it registered. */
|
|
21
|
+
#panels = new Map()
|
|
22
|
+
#userKey = undefined
|
|
23
|
+
#remembered = { open: null, widths: {} }
|
|
24
|
+
#restored = false
|
|
25
|
+
/** Set by `open(…, { focus, returnFocusTo })`, read once by the host. */
|
|
26
|
+
focusRequest = undefined
|
|
27
|
+
|
|
28
|
+
/** The open panel's alias, or null. */
|
|
29
|
+
active = this.#active.asObservable()
|
|
30
|
+
/** The open panel's width in pixels. */
|
|
31
|
+
width = this.#width.asObservable()
|
|
32
|
+
/** alias → false for a panel its extension has said is unavailable. */
|
|
33
|
+
available = this.#available.asObservable()
|
|
34
|
+
|
|
35
|
+
constructor(host) {
|
|
36
|
+
super(host, SIDE_PANEL_CONTEXT)
|
|
37
|
+
this.consumeContext(UMB_CURRENT_USER_CONTEXT, (user) => {
|
|
38
|
+
this.observe(user?.unique, (unique) => {
|
|
39
|
+
if (!unique || unique === this.#userKey) return
|
|
40
|
+
this.#userKey = unique
|
|
41
|
+
this.#remembered = stored(unique)
|
|
42
|
+
this.#restored = false
|
|
43
|
+
this.#restore()
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** The host's list of declared panels; a closed one that is gone stays closed. */
|
|
49
|
+
setPanels(manifests) {
|
|
50
|
+
this.#panels = new Map(manifests.map((m) => [m.alias, m.meta ?? {}]))
|
|
51
|
+
const active = this.#active.getValue()
|
|
52
|
+
if (active && !this.#panels.has(active)) this.#active.setValue(null)
|
|
53
|
+
this.#restore()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
isAvailable(alias) {
|
|
57
|
+
return this.#panels.has(alias) && this.#available.getValue()[alias] !== false
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
open(alias, options = {}) {
|
|
61
|
+
if (!this.isAvailable(alias)) return false
|
|
62
|
+
this.focusRequest = options.focus ? options : undefined
|
|
63
|
+
this.#width.setValue(this.#widthFor(alias, this.#remembered.widths[alias]))
|
|
64
|
+
this.#active.setValue(alias)
|
|
65
|
+
this.#save()
|
|
66
|
+
return true
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
close() {
|
|
70
|
+
if (this.#active.getValue() === null) return
|
|
71
|
+
this.#active.setValue(null)
|
|
72
|
+
this.#save()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
toggle(alias, options = {}) {
|
|
76
|
+
if (this.#active.getValue() === alias) this.close()
|
|
77
|
+
else this.open(alias, options)
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
/** The splitter's width for the open panel, within its limits. */
|
|
81
|
+
setWidth(width) {
|
|
82
|
+
const alias = this.#active.getValue()
|
|
83
|
+
if (!alias) return
|
|
84
|
+
const clamped = this.#widthFor(alias, width)
|
|
85
|
+
this.#width.setValue(clamped)
|
|
86
|
+
this.#remembered.widths = { ...this.#remembered.widths, [alias]: clamped }
|
|
87
|
+
this.#save()
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The open panel's limits, for the splitter's aria values. */
|
|
91
|
+
limits() {
|
|
92
|
+
const alias = this.#active.getValue()
|
|
93
|
+
const meta = alias ? this.#panels.get(alias) : undefined
|
|
94
|
+
const { min } = limitsOf(meta)
|
|
95
|
+
return { min, max: maxWidthFor(meta, globalThis.innerWidth ?? 1280) }
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** An extension's say on whether its panel can be used now; an open one closes. */
|
|
99
|
+
setAvailable(alias, available) {
|
|
100
|
+
this.#available.setValue({ ...this.#available.getValue(), [alias]: available !== false })
|
|
101
|
+
if (available === false && this.#active.getValue() === alias) this.close()
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/** The window changed size: the open panel's width is clamped again. */
|
|
105
|
+
refit() {
|
|
106
|
+
const alias = this.#active.getValue()
|
|
107
|
+
if (alias) this.#width.setValue(this.#widthFor(alias, this.#width.getValue()))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
#widthFor(alias, width) {
|
|
111
|
+
return clampWidth(width, this.#panels.get(alias), globalThis.innerWidth ?? 1280)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
#restore() {
|
|
115
|
+
if (this.#restored || this.#userKey === undefined || this.#panels.size === 0) return
|
|
116
|
+
this.#restored = true
|
|
117
|
+
const open = this.#remembered.open
|
|
118
|
+
if (open && this.isAvailable(open)) this.open(open)
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
#save() {
|
|
122
|
+
if (this.#userKey === undefined) return
|
|
123
|
+
this.#remembered = { ...this.#remembered, open: this.#active.getValue() }
|
|
124
|
+
store(this.#userKey, this.#remembered)
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
export { CromboloSidePanelContext as api }
|
|
@@ -0,0 +1,333 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side panels (story 182): a column beside the back office's main view that an
|
|
3
|
+
* extension's `sidePanel` docks into. `umb-backoffice` renders its header, main
|
|
4
|
+
* and a slot in a column. This adds the panel host beside main inside the
|
|
5
|
+
* shell's shadow root, and a grid stylesheet that puts main and the panel side
|
|
6
|
+
* by side under the header. Main is never re-rendered or moved, so its router
|
|
7
|
+
* and everything open in it carry on; the panel sits outside the router, so
|
|
8
|
+
* moving around keeps it.
|
|
9
|
+
*
|
|
10
|
+
* When the shell no longer has its header and main as expected, nothing is
|
|
11
|
+
* changed: a back office without panels rather than a broken one.
|
|
12
|
+
* `tests/side-panel-plugin.test.ts` fails first.
|
|
13
|
+
*/
|
|
14
|
+
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'
|
|
15
|
+
import { UmbExtensionsElementInitializer } from '@umbraco-cms/backoffice/extension-api'
|
|
16
|
+
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'
|
|
17
|
+
import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
18
|
+
import {
|
|
19
|
+
modeFor,
|
|
20
|
+
SIDE_PANEL_CONTEXT,
|
|
21
|
+
SIDE_PANEL_TYPE,
|
|
22
|
+
shellIsAsExpected,
|
|
23
|
+
widthForKey,
|
|
24
|
+
} from './layout.js'
|
|
25
|
+
import './toggle.js'
|
|
26
|
+
|
|
27
|
+
const SHELL_STYLES = css`
|
|
28
|
+
:host {
|
|
29
|
+
display: grid;
|
|
30
|
+
grid-template-columns: minmax(0, 1fr) auto;
|
|
31
|
+
grid-template-rows: auto minmax(0, 1fr);
|
|
32
|
+
}
|
|
33
|
+
umb-backoffice-header {
|
|
34
|
+
grid-column: 1 / -1;
|
|
35
|
+
}
|
|
36
|
+
umb-backoffice-main {
|
|
37
|
+
grid-column: 1;
|
|
38
|
+
grid-row: 2;
|
|
39
|
+
height: 100%;
|
|
40
|
+
min-width: 0;
|
|
41
|
+
}
|
|
42
|
+
crombolo-side-panel-host {
|
|
43
|
+
grid-column: 2;
|
|
44
|
+
grid-row: 2;
|
|
45
|
+
min-height: 0;
|
|
46
|
+
}
|
|
47
|
+
`
|
|
48
|
+
|
|
49
|
+
/** Docks the panel host into a live shell once; true when this call did. */
|
|
50
|
+
export function dockInto(shell) {
|
|
51
|
+
const root = shell?.shadowRoot
|
|
52
|
+
if (!root || root.querySelector('crombolo-side-panel-host')) return false
|
|
53
|
+
const children = [...root.children].map((child) => `<${child.localName}`)
|
|
54
|
+
// `:scope` matches nothing on a shadow root, so main is found among its children.
|
|
55
|
+
const main = [...root.children].find((child) => child.localName === 'umb-backoffice-main')
|
|
56
|
+
if (!main || !shellIsAsExpected(children)) {
|
|
57
|
+
console.warn('Side panels are off: the back office shell no longer renders as expected.')
|
|
58
|
+
return false
|
|
59
|
+
}
|
|
60
|
+
const sheet = SHELL_STYLES.styleSheet
|
|
61
|
+
if (sheet && !root.adoptedStyleSheets.includes(sheet))
|
|
62
|
+
root.adoptedStyleSheets = [...root.adoptedStyleSheets, sheet]
|
|
63
|
+
main.after(document.createElement('crombolo-side-panel-host'))
|
|
64
|
+
return true
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** The header toggles registered for panels that asked for one, by panel alias. */
|
|
68
|
+
const toggles = new Map()
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* A panel with `meta.toggle` gets a header button that opens and closes it, so
|
|
72
|
+
* an extension declares one manifest, not two. Removed with its panel.
|
|
73
|
+
*/
|
|
74
|
+
function syncToggles(manifests) {
|
|
75
|
+
const wanted = new Map(manifests.filter((m) => m.meta?.toggle).map((m) => [m.alias, m]))
|
|
76
|
+
for (const [alias, toggleAlias] of toggles)
|
|
77
|
+
if (!wanted.has(alias)) {
|
|
78
|
+
umbExtensionsRegistry.unregister(toggleAlias)
|
|
79
|
+
toggles.delete(alias)
|
|
80
|
+
}
|
|
81
|
+
for (const [alias, manifest] of wanted) {
|
|
82
|
+
if (toggles.has(alias)) continue
|
|
83
|
+
const toggleAlias = `${alias}.Toggle`
|
|
84
|
+
umbExtensionsRegistry.register({
|
|
85
|
+
type: 'headerApp',
|
|
86
|
+
alias: toggleAlias,
|
|
87
|
+
name: `${manifest.name ?? alias} toggle`,
|
|
88
|
+
elementName: 'crombolo-side-panel-toggle',
|
|
89
|
+
weight: manifest.weight ?? 0,
|
|
90
|
+
meta: {
|
|
91
|
+
panel: alias,
|
|
92
|
+
label: manifest.meta?.label ?? manifest.name,
|
|
93
|
+
icon: manifest.meta?.icon,
|
|
94
|
+
},
|
|
95
|
+
})
|
|
96
|
+
toggles.set(alias, toggleAlias)
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
export class CromboloSidePanelHostElement extends UmbElementMixin(LitElement) {
|
|
101
|
+
static properties = {
|
|
102
|
+
_active: { state: true },
|
|
103
|
+
_width: { state: true },
|
|
104
|
+
_windowWidth: { state: true },
|
|
105
|
+
_panels: { state: true },
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
#context = undefined
|
|
109
|
+
#onResize = () => {
|
|
110
|
+
this._windowWidth = window.innerWidth
|
|
111
|
+
this.#context?.refit()
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
constructor() {
|
|
115
|
+
super()
|
|
116
|
+
this._active = null
|
|
117
|
+
this._width = 0
|
|
118
|
+
this._windowWidth = window.innerWidth
|
|
119
|
+
this._panels = []
|
|
120
|
+
this.consumeContext(SIDE_PANEL_CONTEXT, (context) => {
|
|
121
|
+
this.#context = context
|
|
122
|
+
if (!context) return
|
|
123
|
+
this.observe(context.active, (active) => {
|
|
124
|
+
const was = this._active
|
|
125
|
+
this._active = active
|
|
126
|
+
if (was && !active) this.#returnFocus()
|
|
127
|
+
if (active) this.updateComplete.then(() => this.#takeFocus())
|
|
128
|
+
})
|
|
129
|
+
this.observe(context.width, (width) => {
|
|
130
|
+
this._width = width
|
|
131
|
+
})
|
|
132
|
+
context.setPanels(this._panels.map((c) => c.manifest))
|
|
133
|
+
})
|
|
134
|
+
new UmbExtensionsElementInitializer(
|
|
135
|
+
this,
|
|
136
|
+
umbExtensionsRegistry,
|
|
137
|
+
SIDE_PANEL_TYPE,
|
|
138
|
+
null,
|
|
139
|
+
(permitted) => {
|
|
140
|
+
this._panels = permitted
|
|
141
|
+
this.#context?.setPanels(permitted.map((c) => c.manifest))
|
|
142
|
+
syncToggles(permitted.map((c) => c.manifest))
|
|
143
|
+
},
|
|
144
|
+
)
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
connectedCallback() {
|
|
148
|
+
super.connectedCallback()
|
|
149
|
+
window.addEventListener('resize', this.#onResize)
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
disconnectedCallback() {
|
|
153
|
+
super.disconnectedCallback()
|
|
154
|
+
window.removeEventListener('resize', this.#onResize)
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
get #mode() {
|
|
158
|
+
return modeFor(this._windowWidth, this._width)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
get #manifest() {
|
|
162
|
+
return this._panels.find((c) => c.manifest.alias === this._active)?.manifest
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
#takeFocus() {
|
|
166
|
+
const request = this.#context?.focusRequest
|
|
167
|
+
if (!request) return
|
|
168
|
+
this.#returnTo = request.returnFocusTo
|
|
169
|
+
this.#context.focusRequest = undefined
|
|
170
|
+
this.renderRoot.querySelector('#panel')?.focus()
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
/** The toggle that opened the panel from the keyboard, given focus back on close. */
|
|
174
|
+
#returnTo = undefined
|
|
175
|
+
#returnFocus() {
|
|
176
|
+
const target = this.#returnTo
|
|
177
|
+
this.#returnTo = undefined
|
|
178
|
+
target?.focus?.()
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
#onKeydown(event) {
|
|
182
|
+
if (event.key === 'Escape' && this.#mode === 'sheet') {
|
|
183
|
+
event.stopPropagation()
|
|
184
|
+
this.#context?.close()
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
#onSplitterKey(event) {
|
|
189
|
+
const next = widthForKey(event.key, this._width, this.#manifest?.meta, this._windowWidth)
|
|
190
|
+
if (next === undefined) return
|
|
191
|
+
event.preventDefault()
|
|
192
|
+
this.#context?.setWidth(next)
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
#onSplitterDown(event) {
|
|
196
|
+
const splitter = event.currentTarget
|
|
197
|
+
splitter.setPointerCapture(event.pointerId)
|
|
198
|
+
const move = (e) => this.#context?.setWidth(window.innerWidth - e.clientX)
|
|
199
|
+
const up = () => {
|
|
200
|
+
splitter.removeEventListener('pointermove', move)
|
|
201
|
+
splitter.removeEventListener('pointerup', up)
|
|
202
|
+
}
|
|
203
|
+
splitter.addEventListener('pointermove', move)
|
|
204
|
+
splitter.addEventListener('pointerup', up)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
render() {
|
|
208
|
+
const manifest = this.#manifest
|
|
209
|
+
const open = Boolean(manifest)
|
|
210
|
+
const sheet = this.#mode === 'sheet'
|
|
211
|
+
const label = manifest?.meta?.label ?? manifest?.name ?? ''
|
|
212
|
+
const limits = this.#context?.limits() ?? { min: 0, max: 0 }
|
|
213
|
+
this.toggleAttribute('open', open)
|
|
214
|
+
this.toggleAttribute('sheet', open && sheet)
|
|
215
|
+
// Every panel's element stays mounted, hidden while another is open, so its
|
|
216
|
+
// state outlives closing and opening as well as navigation.
|
|
217
|
+
const bodies = this._panels.map(
|
|
218
|
+
(c) =>
|
|
219
|
+
html`<div class="body" ?hidden=${c.manifest.alias !== this._active}>${c.component}</div>`,
|
|
220
|
+
)
|
|
221
|
+
return html`
|
|
222
|
+
${
|
|
223
|
+
open && !sheet
|
|
224
|
+
? html`<div
|
|
225
|
+
class="splitter"
|
|
226
|
+
role="separator"
|
|
227
|
+
tabindex="0"
|
|
228
|
+
aria-orientation="vertical"
|
|
229
|
+
aria-label=${`Resize ${label}`}
|
|
230
|
+
aria-controls="panel"
|
|
231
|
+
aria-valuenow=${this._width}
|
|
232
|
+
aria-valuemin=${limits.min}
|
|
233
|
+
aria-valuemax=${limits.max}
|
|
234
|
+
@keydown=${this.#onSplitterKey}
|
|
235
|
+
@pointerdown=${this.#onSplitterDown}></div>`
|
|
236
|
+
: nothing
|
|
237
|
+
}
|
|
238
|
+
<div
|
|
239
|
+
id="panel"
|
|
240
|
+
tabindex="-1"
|
|
241
|
+
role=${sheet ? 'dialog' : 'complementary'}
|
|
242
|
+
aria-modal=${sheet ? 'true' : nothing}
|
|
243
|
+
aria-label=${label || nothing}
|
|
244
|
+
?hidden=${!open}
|
|
245
|
+
style=${sheet ? '' : `width: ${this._width}px`}
|
|
246
|
+
@keydown=${this.#onKeydown}>
|
|
247
|
+
<div class="header">
|
|
248
|
+
<span class="label">${label}</span>
|
|
249
|
+
<uui-button compact look="secondary" label="Close" @click=${() => this.#context?.close()}>
|
|
250
|
+
<uui-icon name="icon-delete"></uui-icon>
|
|
251
|
+
</uui-button>
|
|
252
|
+
</div>
|
|
253
|
+
${bodies}
|
|
254
|
+
</div>
|
|
255
|
+
`
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
static styles = css`
|
|
259
|
+
:host {
|
|
260
|
+
display: none;
|
|
261
|
+
height: 100%;
|
|
262
|
+
background: var(--uui-color-surface);
|
|
263
|
+
}
|
|
264
|
+
:host([open]) {
|
|
265
|
+
display: flex;
|
|
266
|
+
}
|
|
267
|
+
:host([sheet]) {
|
|
268
|
+
position: fixed;
|
|
269
|
+
inset: 0;
|
|
270
|
+
z-index: 1000;
|
|
271
|
+
}
|
|
272
|
+
.splitter {
|
|
273
|
+
width: 6px;
|
|
274
|
+
cursor: col-resize;
|
|
275
|
+
background: var(--uui-color-divider);
|
|
276
|
+
flex: none;
|
|
277
|
+
}
|
|
278
|
+
.splitter:focus-visible {
|
|
279
|
+
outline: 2px solid var(--uui-color-focus);
|
|
280
|
+
}
|
|
281
|
+
#panel {
|
|
282
|
+
display: flex;
|
|
283
|
+
flex-direction: column;
|
|
284
|
+
min-width: 0;
|
|
285
|
+
height: 100%;
|
|
286
|
+
animation: slide 160ms ease-out;
|
|
287
|
+
}
|
|
288
|
+
#panel[hidden] {
|
|
289
|
+
display: none;
|
|
290
|
+
}
|
|
291
|
+
:host([sheet]) #panel {
|
|
292
|
+
width: 100%;
|
|
293
|
+
}
|
|
294
|
+
.header {
|
|
295
|
+
display: flex;
|
|
296
|
+
align-items: center;
|
|
297
|
+
justify-content: space-between;
|
|
298
|
+
padding: var(--uui-size-space-3) var(--uui-size-space-4);
|
|
299
|
+
border-bottom: 1px solid var(--uui-color-divider);
|
|
300
|
+
}
|
|
301
|
+
.label {
|
|
302
|
+
font-weight: 700;
|
|
303
|
+
}
|
|
304
|
+
.body {
|
|
305
|
+
flex: 1;
|
|
306
|
+
min-height: 0;
|
|
307
|
+
overflow: auto;
|
|
308
|
+
}
|
|
309
|
+
.body[hidden] {
|
|
310
|
+
display: none;
|
|
311
|
+
}
|
|
312
|
+
@keyframes slide {
|
|
313
|
+
from {
|
|
314
|
+
transform: translateX(16px);
|
|
315
|
+
opacity: 0;
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
@media (prefers-reduced-motion: reduce) {
|
|
319
|
+
#panel {
|
|
320
|
+
animation: none;
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
`
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
customElements.define('crombolo-side-panel-host', CromboloSidePanelHostElement)
|
|
327
|
+
|
|
328
|
+
// A back-office entry point's host is the live `umb-backoffice`, rendered by
|
|
329
|
+
// the time this module loads; a new shell (after signing in again) runs it again.
|
|
330
|
+
export const onInit = async (host) => {
|
|
331
|
+
await host?.updateComplete
|
|
332
|
+
dockInto(host)
|
|
333
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Side panels (story 182): the rules a docked panel follows, kept apart from the
|
|
3
|
+
* DOM so they are tested on their own. How wide it may be, when it becomes a
|
|
4
|
+
* sheet over the view instead, and what is remembered between visits.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
export const SIDE_PANEL_CONTEXT = 'Crombolo.Context.SidePanel'
|
|
8
|
+
export const SIDE_PANEL_TYPE = 'sidePanel'
|
|
9
|
+
export const DEFAULTS = { defaultWidth: 400, minWidth: 280, maxWidth: 720 }
|
|
10
|
+
/** Below this window width, a panel is a sheet. */
|
|
11
|
+
export const SHEET_BELOW = 768
|
|
12
|
+
/** A docked panel never leaves main narrower than this. */
|
|
13
|
+
export const MAIN_MIN = 480
|
|
14
|
+
/** How far an arrow key moves the splitter. */
|
|
15
|
+
export const STEP = 16
|
|
16
|
+
|
|
17
|
+
/** A panel's own limits, with the defaults filled in and kept in order. */
|
|
18
|
+
export function limitsOf(meta = {}) {
|
|
19
|
+
const min = Number(meta.minWidth) > 0 ? Number(meta.minWidth) : DEFAULTS.minWidth
|
|
20
|
+
const max = Math.max(min, Number(meta.maxWidth) > 0 ? Number(meta.maxWidth) : DEFAULTS.maxWidth)
|
|
21
|
+
const preferred =
|
|
22
|
+
Number(meta.defaultWidth) > 0 ? Number(meta.defaultWidth) : DEFAULTS.defaultWidth
|
|
23
|
+
return { min, max, preferred: Math.min(max, Math.max(min, preferred)) }
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** The widest a panel may be: its maximum, or half the window, never under its minimum. */
|
|
27
|
+
export function maxWidthFor(meta, windowWidth) {
|
|
28
|
+
const { min, max } = limitsOf(meta)
|
|
29
|
+
return Math.max(min, Math.min(max, Math.floor(windowWidth / 2)))
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** A width within the panel's limits and at most half the window. */
|
|
33
|
+
export function clampWidth(width, meta, windowWidth) {
|
|
34
|
+
const { min, preferred } = limitsOf(meta)
|
|
35
|
+
const ceiling = maxWidthFor(meta, windowWidth)
|
|
36
|
+
const wanted = Number.isFinite(width) ? width : preferred
|
|
37
|
+
return Math.round(Math.min(ceiling, Math.max(min, wanted)))
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** `sheet` on a narrow window, or where docking would squeeze main too far. */
|
|
41
|
+
export function modeFor(windowWidth, panelWidth) {
|
|
42
|
+
return windowWidth < SHEET_BELOW || windowWidth - panelWidth < MAIN_MIN ? 'sheet' : 'docked'
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** The splitter's next width for a key, or undefined for a key it ignores. */
|
|
46
|
+
export function widthForKey(key, width, meta, windowWidth) {
|
|
47
|
+
const { min } = limitsOf(meta)
|
|
48
|
+
const ceiling = maxWidthFor(meta, windowWidth)
|
|
49
|
+
// The panel is on the right, so the left arrow drags the splitter left: wider.
|
|
50
|
+
if (key === 'ArrowLeft') return clampWidth(width + STEP, meta, windowWidth)
|
|
51
|
+
if (key === 'ArrowRight') return clampWidth(width - STEP, meta, windowWidth)
|
|
52
|
+
if (key === 'Home') return min
|
|
53
|
+
if (key === 'End') return ceiling
|
|
54
|
+
return undefined
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const keyFor = (userKey) => `crombolo.sidePanel.${userKey || 'anonymous'}`
|
|
58
|
+
|
|
59
|
+
/** What a user had open, and how wide; nothing when storage is unavailable. */
|
|
60
|
+
export function stored(userKey, storage = globalThis.localStorage) {
|
|
61
|
+
try {
|
|
62
|
+
const value = JSON.parse(storage?.getItem(keyFor(userKey)) ?? 'null')
|
|
63
|
+
if (!value || typeof value !== 'object') return { open: null, widths: {} }
|
|
64
|
+
return {
|
|
65
|
+
open: typeof value.open === 'string' ? value.open : null,
|
|
66
|
+
widths: value.widths && typeof value.widths === 'object' ? value.widths : {},
|
|
67
|
+
}
|
|
68
|
+
} catch {
|
|
69
|
+
return { open: null, widths: {} }
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
export function store(userKey, state, storage = globalThis.localStorage) {
|
|
74
|
+
try {
|
|
75
|
+
storage?.setItem(keyFor(userKey), JSON.stringify({ open: state.open, widths: state.widths }))
|
|
76
|
+
} catch {
|
|
77
|
+
// Private windows and blocked storage: the panel simply is not remembered.
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/** The children `umb-backoffice` renders, in order; the layout patch needs all three. */
|
|
82
|
+
export const SHELL = ['<umb-backoffice-header', '<umb-backoffice-main', '<slot']
|
|
83
|
+
|
|
84
|
+
/** Whether a rendered template still has the shell's children in order. */
|
|
85
|
+
export function shellIsAsExpected(strings) {
|
|
86
|
+
const text = Array.isArray(strings) ? strings.join('') : String(strings ?? '')
|
|
87
|
+
let at = -1
|
|
88
|
+
for (const tag of SHELL) {
|
|
89
|
+
const next = text.indexOf(tag, at + 1)
|
|
90
|
+
if (next < 0) return false
|
|
91
|
+
at = next
|
|
92
|
+
}
|
|
93
|
+
return true
|
|
94
|
+
}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A side panel's header button (story 182), registered by the host for a
|
|
3
|
+
* `sidePanel` whose meta says `toggle: true`. It opens and closes that panel,
|
|
4
|
+
* and hides while the panel is unavailable.
|
|
5
|
+
*/
|
|
6
|
+
import { UmbElementMixin } from '@umbraco-cms/backoffice/element-api'
|
|
7
|
+
import { css, html, LitElement, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
8
|
+
import { SIDE_PANEL_CONTEXT } from './layout.js'
|
|
9
|
+
|
|
10
|
+
export default class CromboloSidePanelToggleElement extends UmbElementMixin(LitElement) {
|
|
11
|
+
static properties = {
|
|
12
|
+
manifest: { attribute: false },
|
|
13
|
+
_active: { state: true },
|
|
14
|
+
_available: { state: true },
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
#context = undefined
|
|
18
|
+
|
|
19
|
+
constructor() {
|
|
20
|
+
super()
|
|
21
|
+
this._active = null
|
|
22
|
+
this._available = {}
|
|
23
|
+
this.consumeContext(SIDE_PANEL_CONTEXT, (context) => {
|
|
24
|
+
this.#context = context
|
|
25
|
+
if (!context) return
|
|
26
|
+
this.observe(context.active, (active) => {
|
|
27
|
+
this._active = active
|
|
28
|
+
})
|
|
29
|
+
this.observe(context.available, (available) => {
|
|
30
|
+
this._available = available
|
|
31
|
+
})
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
get #panel() {
|
|
36
|
+
return this.manifest?.meta?.panel
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
#toggle(event) {
|
|
40
|
+
// `detail` is 0 for a click made with the keyboard: only then does focus move in.
|
|
41
|
+
const fromKeyboard = event.detail === 0
|
|
42
|
+
this.#context?.toggle(this.#panel, {
|
|
43
|
+
focus: fromKeyboard,
|
|
44
|
+
returnFocusTo: fromKeyboard ? this.renderRoot.querySelector('uui-button') : undefined,
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
render() {
|
|
49
|
+
const panel = this.#panel
|
|
50
|
+
if (!panel || this._available[panel] === false) return nothing
|
|
51
|
+
const label = this.manifest?.meta?.label ?? this.manifest?.name ?? panel
|
|
52
|
+
const open = this._active === panel
|
|
53
|
+
return html`<uui-button
|
|
54
|
+
compact
|
|
55
|
+
look="primary"
|
|
56
|
+
label=${label}
|
|
57
|
+
title=${label}
|
|
58
|
+
aria-expanded=${open ? 'true' : 'false'}
|
|
59
|
+
aria-controls="panel"
|
|
60
|
+
@click=${this.#toggle}>
|
|
61
|
+
<uui-icon name=${this.manifest?.meta?.icon ?? 'icon-layout'}></uui-icon>
|
|
62
|
+
</uui-button>`
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
static styles = css`
|
|
66
|
+
uui-button {
|
|
67
|
+
font-size: 18px;
|
|
68
|
+
--uui-button-background-color: transparent;
|
|
69
|
+
}
|
|
70
|
+
`
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
customElements.define('crombolo-side-panel-toggle', CromboloSidePanelToggleElement)
|
|
@@ -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.
|
|
5
|
+
"version": "0.30.3",
|
|
6
6
|
"allowPublicAccess": false,
|
|
7
7
|
"extensions": [
|
|
8
8
|
{
|
|
@@ -301,6 +301,18 @@
|
|
|
301
301
|
"element": "/crombolo-plugin/read-only-banner.js",
|
|
302
302
|
"weight": 1000
|
|
303
303
|
},
|
|
304
|
+
{
|
|
305
|
+
"type": "backofficeEntryPoint",
|
|
306
|
+
"alias": "Crombolo.EntryPoint.SidePanels",
|
|
307
|
+
"name": "Crombolo Side Panels",
|
|
308
|
+
"js": "/crombolo-plugin/side-panel/host.js"
|
|
309
|
+
},
|
|
310
|
+
{
|
|
311
|
+
"type": "globalContext",
|
|
312
|
+
"alias": "Crombolo.GlobalContext.SidePanel",
|
|
313
|
+
"name": "Crombolo Side Panel Context",
|
|
314
|
+
"api": "/crombolo-plugin/side-panel/context.js"
|
|
315
|
+
},
|
|
304
316
|
{
|
|
305
317
|
"type": "headerApp",
|
|
306
318
|
"alias": "Crombolo.HeaderApp.BundlesChanged",
|