@crombolo/backoffice-host 0.51.0 → 0.52.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 +3 -3
- package/plugin/app-preview/umbraco-package.json +1 -1
- package/plugin/branding/localization-en.js +2 -8
- package/plugin/breadcrumb.js +6 -2
- package/plugin/content-home-dashboard.js +115 -0
- package/plugin/content-strip-items.js +50 -0
- package/plugin/content-strip.js +118 -0
- package/plugin/definition-tree-model.js +43 -0
- package/plugin/definition-tree.js +308 -0
- package/plugin/document-links.js +19 -0
- package/plugin/form-word-input-model.js +45 -0
- package/plugin/form-word-input.js +170 -0
- package/plugin/forms-client.js +21 -2
- package/plugin/forms-entries.js +77 -32
- package/plugin/forms-layout.js +6 -0
- package/plugin/forms-overview.js +200 -42
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/overview-dashboard.js +77 -7
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/session-guard-model.js +54 -0
- package/plugin/session-guard.js +50 -0
- package/plugin/settings-cards.js +14 -31
- package/plugin/settings-section.js +103 -15
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/theme-sync.js +69 -0
- package/plugin/tsx-editors.js +8 -5
- package/plugin/umbraco-package.json +92 -17
- package/plugin/view-parts.js +24 -0
- package/plugin/workflow-client.js +7 -2
- package/plugin/workflow-designer.js +44 -4
- package/src/paths.ts +1 -0
- package/plugin/theme-switch.js +0 -135
|
@@ -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.52.2",
|
|
6
6
|
"allowPublicAccess": false,
|
|
7
7
|
"extensions": [
|
|
8
8
|
{
|
|
@@ -21,11 +21,16 @@
|
|
|
21
21
|
"weight": 250
|
|
22
22
|
},
|
|
23
23
|
{
|
|
24
|
-
"type": "
|
|
25
|
-
"alias": "Crombolo.
|
|
26
|
-
"name": "
|
|
27
|
-
"
|
|
28
|
-
|
|
24
|
+
"type": "backofficeEntryPoint",
|
|
25
|
+
"alias": "Crombolo.EntryPoint.SessionGuard",
|
|
26
|
+
"name": "Crombolo Session Guard",
|
|
27
|
+
"js": "/crombolo-plugin/session-guard.js"
|
|
28
|
+
},
|
|
29
|
+
{
|
|
30
|
+
"type": "backofficeEntryPoint",
|
|
31
|
+
"alias": "Crombolo.EntryPoint.ThemeSync",
|
|
32
|
+
"name": "Crombolo Theme Sync",
|
|
33
|
+
"js": "/crombolo-plugin/theme-sync.js"
|
|
29
34
|
},
|
|
30
35
|
{
|
|
31
36
|
"type": "entityUserPermission",
|
|
@@ -423,16 +428,22 @@
|
|
|
423
428
|
}
|
|
424
429
|
]
|
|
425
430
|
},
|
|
431
|
+
{
|
|
432
|
+
"type": "homeView",
|
|
433
|
+
"alias": "Crombolo.HomeView.Overview",
|
|
434
|
+
"name": "Crombolo Home",
|
|
435
|
+
"element": "/crombolo-plugin/overview-dashboard.js"
|
|
436
|
+
},
|
|
426
437
|
{
|
|
427
438
|
"type": "dashboard",
|
|
428
|
-
"alias": "Crombolo.Dashboard.
|
|
429
|
-
"name": "Crombolo
|
|
430
|
-
"element": "/crombolo-plugin/
|
|
439
|
+
"alias": "Crombolo.Dashboard.ContentHome",
|
|
440
|
+
"name": "Crombolo Content Home Dashboard",
|
|
441
|
+
"element": "/crombolo-plugin/content-home-dashboard.js",
|
|
431
442
|
"weight": 20,
|
|
432
443
|
"overwrites": ["Umb.Dashboard.UmbracoNews"],
|
|
433
444
|
"meta": {
|
|
434
|
-
"label": "
|
|
435
|
-
"pathname": "
|
|
445
|
+
"label": "Home",
|
|
446
|
+
"pathname": "home"
|
|
436
447
|
},
|
|
437
448
|
"conditions": [
|
|
438
449
|
{
|
|
@@ -547,15 +558,75 @@
|
|
|
547
558
|
"pathname": "forms"
|
|
548
559
|
}
|
|
549
560
|
},
|
|
561
|
+
{
|
|
562
|
+
"type": "entityAction",
|
|
563
|
+
"kind": "default",
|
|
564
|
+
"alias": "Crombolo.EntityAction.Document.EditContentType",
|
|
565
|
+
"name": "Edit Content Type",
|
|
566
|
+
"forEntityTypes": ["document"],
|
|
567
|
+
"api": "/crombolo-plugin/document-links.js",
|
|
568
|
+
"weight": 50,
|
|
569
|
+
"meta": {
|
|
570
|
+
"icon": "icon-document-dashed-line",
|
|
571
|
+
"label": "Edit content type",
|
|
572
|
+
"target": "document-type"
|
|
573
|
+
},
|
|
574
|
+
"conditions": [
|
|
575
|
+
{
|
|
576
|
+
"alias": "Umb.Condition.SectionUserPermission",
|
|
577
|
+
"match": "Umb.Section.Settings"
|
|
578
|
+
}
|
|
579
|
+
]
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
"type": "entityAction",
|
|
583
|
+
"kind": "default",
|
|
584
|
+
"alias": "Crombolo.EntityAction.Document.EditTemplate",
|
|
585
|
+
"name": "Edit Template",
|
|
586
|
+
"forEntityTypes": ["document"],
|
|
587
|
+
"api": "/crombolo-plugin/document-links.js",
|
|
588
|
+
"weight": 49,
|
|
589
|
+
"meta": {
|
|
590
|
+
"icon": "icon-layout",
|
|
591
|
+
"label": "Edit template",
|
|
592
|
+
"target": "template"
|
|
593
|
+
},
|
|
594
|
+
"conditions": [
|
|
595
|
+
{
|
|
596
|
+
"alias": "Umb.Condition.SectionUserPermission",
|
|
597
|
+
"match": "Umb.Section.Settings"
|
|
598
|
+
}
|
|
599
|
+
]
|
|
600
|
+
},
|
|
601
|
+
{
|
|
602
|
+
"type": "backofficeEntryPoint",
|
|
603
|
+
"alias": "Crombolo.EntryPoint.ContentStrip",
|
|
604
|
+
"name": "Crombolo Menu Under Content",
|
|
605
|
+
"js": "/crombolo-plugin/content-strip.js"
|
|
606
|
+
},
|
|
607
|
+
{
|
|
608
|
+
"type": "sectionSidebarApp",
|
|
609
|
+
"alias": "Crombolo.SectionSidebarApp.DefinitionTree",
|
|
610
|
+
"name": "Crombolo Forms And Workflows Tree",
|
|
611
|
+
"element": "/crombolo-plugin/definition-tree.js",
|
|
612
|
+
"weight": 100,
|
|
613
|
+
"conditions": [
|
|
614
|
+
{
|
|
615
|
+
"alias": "Umb.Condition.SectionAlias",
|
|
616
|
+
"match": "Crombolo.Section.Forms"
|
|
617
|
+
}
|
|
618
|
+
]
|
|
619
|
+
},
|
|
550
620
|
{
|
|
551
621
|
"type": "sectionView",
|
|
552
622
|
"alias": "Crombolo.SectionView.Forms.Overview",
|
|
553
623
|
"name": "Crombolo Forms Overview",
|
|
554
624
|
"element": "/crombolo-plugin/forms-overview.js",
|
|
555
|
-
"weight":
|
|
625
|
+
"weight": 200,
|
|
556
626
|
"meta": {
|
|
557
627
|
"label": "Forms",
|
|
558
628
|
"pathname": "forms",
|
|
629
|
+
"noTab": true,
|
|
559
630
|
"icon": "icon-notepad"
|
|
560
631
|
},
|
|
561
632
|
"conditions": [
|
|
@@ -570,10 +641,11 @@
|
|
|
570
641
|
"alias": "Crombolo.SectionView.Forms.Entries",
|
|
571
642
|
"name": "Crombolo Forms Entries",
|
|
572
643
|
"element": "/crombolo-plugin/forms-entries.js",
|
|
573
|
-
"weight":
|
|
644
|
+
"weight": 100,
|
|
574
645
|
"meta": {
|
|
575
646
|
"label": "Entries",
|
|
576
647
|
"pathname": "entries",
|
|
648
|
+
"noTab": true,
|
|
577
649
|
"icon": "icon-inbox"
|
|
578
650
|
},
|
|
579
651
|
"conditions": [
|
|
@@ -709,18 +781,21 @@
|
|
|
709
781
|
]
|
|
710
782
|
},
|
|
711
783
|
{
|
|
712
|
-
"type": "
|
|
713
|
-
"alias": "Crombolo.
|
|
784
|
+
"type": "sectionView",
|
|
785
|
+
"alias": "Crombolo.SectionView.Workflows",
|
|
714
786
|
"name": "Crombolo Workflow Designer",
|
|
715
787
|
"element": "/crombolo-plugin/workflow-designer.js",
|
|
788
|
+
"weight": 50,
|
|
716
789
|
"meta": {
|
|
717
790
|
"label": "Workflows",
|
|
718
|
-
"pathname": "workflows"
|
|
791
|
+
"pathname": "workflows",
|
|
792
|
+
"noTab": true,
|
|
793
|
+
"icon": "icon-mindmap"
|
|
719
794
|
},
|
|
720
795
|
"conditions": [
|
|
721
796
|
{
|
|
722
797
|
"alias": "Umb.Condition.SectionAlias",
|
|
723
|
-
"match": "
|
|
798
|
+
"match": "Crombolo.Section.Forms"
|
|
724
799
|
},
|
|
725
800
|
{
|
|
726
801
|
"alias": "Umb.Condition.CurrentUser.IsAdmin"
|
package/plugin/view-parts.js
CHANGED
|
@@ -127,3 +127,27 @@ export const personalisedPartInsert = {
|
|
|
127
127
|
return chosen?.path ? personalisedPartSnippet(chosen.path) : undefined
|
|
128
128
|
},
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
/** The folder a view sits in under `components/`: `/pages`, or nothing for the top. */
|
|
132
|
+
export const folderOf = (file) => {
|
|
133
|
+
const folder = (file ?? '').replace(/^\/*/, '/').replace(/\/[^/]*$/, '')
|
|
134
|
+
return folder === '/' ? '' : folder
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/** The extension a view opens with in the editor: a module's `.ts`, else a component's `.tsx`. */
|
|
138
|
+
export const modelExtension = (file) => (file?.endsWith('.ts') ? '.ts' : '.tsx')
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* The file a create page will make, as a path under `components/`, from its address.
|
|
142
|
+
* Its name isn't known yet, but its folder and kind are, and they are what the editor needs.
|
|
143
|
+
*
|
|
144
|
+
* @param {string} pathname
|
|
145
|
+
*/
|
|
146
|
+
export function fileBeingCreated(pathname) {
|
|
147
|
+
const found = /\/workspace\/partial-view\/create\/parent\/[^/]+\/([^/]+)(\/module)?/.exec(
|
|
148
|
+
pathname,
|
|
149
|
+
)
|
|
150
|
+
if (!found) return undefined
|
|
151
|
+
const folder = found[1] === 'null' ? '' : decodeURIComponent(found[1]).replace(/\/$/, '')
|
|
152
|
+
return `${folder}/new${found[2] ? '.ts' : '.tsx'}`
|
|
153
|
+
}
|
|
@@ -31,11 +31,16 @@ export const finished = (skip = 0, take = 25) => call(`history?skip=${skip}&take
|
|
|
31
31
|
export const listWorkflows = () => call('workflows')
|
|
32
32
|
export const previewWorkflow = (alias, workflow) =>
|
|
33
33
|
post(`workflows/${encodeURIComponent(alias)}/preview`, { workflow })
|
|
34
|
-
export const saveWorkflow = (alias, workflow) =>
|
|
34
|
+
export const saveWorkflow = (alias, workflow, folder) =>
|
|
35
35
|
call(`workflows/${encodeURIComponent(alias)}`, {
|
|
36
36
|
method: 'PUT',
|
|
37
|
-
body: JSON.stringify({ workflow }),
|
|
37
|
+
body: JSON.stringify({ workflow, folder }),
|
|
38
38
|
})
|
|
39
|
+
/** A folder made (`POST`), renamed (`PUT`) or deleted (`DELETE`). */
|
|
40
|
+
export const sendWorkflowFolder = (method, body) =>
|
|
41
|
+
call('workflows/tree-folders', { method, body: JSON.stringify(body) })
|
|
42
|
+
export const moveWorkflow = (alias, folder) =>
|
|
43
|
+
call('workflows/tree-move', { method: 'POST', body: JSON.stringify({ alias, folder }) })
|
|
39
44
|
export const deleteWorkflow = (alias) =>
|
|
40
45
|
call(`workflows/${encodeURIComponent(alias)}`, { method: 'DELETE' })
|
|
41
46
|
export const previewDelete = (alias) =>
|
|
@@ -13,6 +13,7 @@ import { css, html, nothing, unsafeCSS } from '@umbraco-cms/backoffice/external/
|
|
|
13
13
|
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
14
14
|
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification'
|
|
15
15
|
import { approvalsChanged } from './approvals-active.js'
|
|
16
|
+
import { readOnlyWords } from './definition-tree-model.js'
|
|
16
17
|
import {
|
|
17
18
|
deleteWorkflow,
|
|
18
19
|
listWorkflows,
|
|
@@ -101,6 +102,21 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
101
102
|
|
|
102
103
|
#drag
|
|
103
104
|
#notifications
|
|
105
|
+
/** The folder a new workflow goes in, from the tree's link. */
|
|
106
|
+
#folder
|
|
107
|
+
#query
|
|
108
|
+
|
|
109
|
+
#follow = () => {
|
|
110
|
+
if (!this._list || location.search === this.#query) return
|
|
111
|
+
this.#query = location.search
|
|
112
|
+
const asked = new URLSearchParams(location.search)
|
|
113
|
+
const named = this._list.items.find((w) => w.alias === asked.get('workflow'))
|
|
114
|
+
if (named) this.#edit(named)
|
|
115
|
+
else if (asked.has('new')) {
|
|
116
|
+
this.#edit(blank())
|
|
117
|
+
this.#folder = asked.get('new') || undefined
|
|
118
|
+
} else this._editing = undefined
|
|
119
|
+
}
|
|
104
120
|
|
|
105
121
|
constructor() {
|
|
106
122
|
super()
|
|
@@ -112,6 +128,14 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
112
128
|
connectedCallback() {
|
|
113
129
|
super.connectedCallback()
|
|
114
130
|
this.#load()
|
|
131
|
+
window.addEventListener('changestate', this.#follow)
|
|
132
|
+
window.addEventListener('popstate', this.#follow)
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
disconnectedCallback() {
|
|
136
|
+
super.disconnectedCallback()
|
|
137
|
+
window.removeEventListener('changestate', this.#follow)
|
|
138
|
+
window.removeEventListener('popstate', this.#follow)
|
|
115
139
|
}
|
|
116
140
|
|
|
117
141
|
async #load() {
|
|
@@ -121,9 +145,11 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
121
145
|
return
|
|
122
146
|
}
|
|
123
147
|
this._list = result
|
|
148
|
+
this.#follow()
|
|
124
149
|
}
|
|
125
150
|
|
|
126
151
|
#edit(workflow) {
|
|
152
|
+
this.#folder = undefined
|
|
127
153
|
const copy = structuredClone(workflow)
|
|
128
154
|
// Every stage gets the place the canvas would draw it, so dragging starts from there.
|
|
129
155
|
const positions = layout(copy.stages)
|
|
@@ -271,7 +297,11 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
271
297
|
return
|
|
272
298
|
}
|
|
273
299
|
}
|
|
274
|
-
const saved = await saveWorkflow(
|
|
300
|
+
const saved = await saveWorkflow(
|
|
301
|
+
this._originalAlias ?? this._editing.alias,
|
|
302
|
+
this._editing,
|
|
303
|
+
this.#folder,
|
|
304
|
+
)
|
|
275
305
|
if (!saved.ok) {
|
|
276
306
|
this._problems = saved.problems ?? [{ message: saved.message }]
|
|
277
307
|
return
|
|
@@ -280,7 +310,9 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
280
310
|
// The green toast every workspace shows on a save.
|
|
281
311
|
this.#notifications?.peek('positive', { data: { message: 'Workflow saved' } })
|
|
282
312
|
this._originalAlias = this._editing.alias
|
|
313
|
+
this.#folder = undefined
|
|
283
314
|
approvalsChanged()
|
|
315
|
+
window.dispatchEvent(new Event('crombolo:definitions-changed'))
|
|
284
316
|
await this.#load()
|
|
285
317
|
}
|
|
286
318
|
|
|
@@ -305,6 +337,8 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
305
337
|
}
|
|
306
338
|
this._editing = undefined
|
|
307
339
|
approvalsChanged()
|
|
340
|
+
window.dispatchEvent(new Event('crombolo:definitions-changed'))
|
|
341
|
+
if (location.search) history.replaceState(null, '', location.pathname)
|
|
308
342
|
await this.#load()
|
|
309
343
|
}
|
|
310
344
|
|
|
@@ -317,6 +351,11 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
317
351
|
return this.#renderEditor()
|
|
318
352
|
}
|
|
319
353
|
|
|
354
|
+
#readOnly() {
|
|
355
|
+
const words = readOnlyWords('Workflows', this._list.readOnlyBecause)
|
|
356
|
+
return words ? html`<p role="status">${words}</p>` : nothing
|
|
357
|
+
}
|
|
358
|
+
|
|
320
359
|
#renderList() {
|
|
321
360
|
const { items, editable } = this._list
|
|
322
361
|
// The create button above the list, as the Created bundles view has it.
|
|
@@ -328,10 +367,10 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
328
367
|
}
|
|
329
368
|
${this._message ? html`<uui-box><p class="message">${this._message}</p></uui-box>` : nothing}
|
|
330
369
|
<uui-box headline="Workflows">
|
|
331
|
-
${
|
|
370
|
+
${this.#readOnly()}
|
|
332
371
|
${
|
|
333
372
|
items.length === 0
|
|
334
|
-
? html`<p>No
|
|
373
|
+
? html`<p>No workflows yet, so a page publishes as soon as someone who may publish does.</p>`
|
|
335
374
|
: html`<uui-table>
|
|
336
375
|
<uui-table-head>
|
|
337
376
|
<uui-table-head-cell>Workflow</uui-table-head-cell>
|
|
@@ -372,6 +411,7 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
372
411
|
this._editing = undefined
|
|
373
412
|
this._message = undefined
|
|
374
413
|
this._problems = undefined
|
|
414
|
+
if (location.search) history.replaceState(null, '', location.pathname)
|
|
375
415
|
}
|
|
376
416
|
const tab = (id, label, icon) => html`<uui-tab
|
|
377
417
|
label=${label}
|
|
@@ -554,7 +594,7 @@ export default class CromboloWorkflowDesignerElement extends UmbLitElement {
|
|
|
554
594
|
this.#touch()
|
|
555
595
|
}
|
|
556
596
|
return html`<div class="settings">
|
|
557
|
-
${
|
|
597
|
+
${readOnlyWords('Workflows', this._list.readOnlyBecause) ? html`<uui-box class="notice">${this.#readOnly()}</uui-box>` : nothing}
|
|
558
598
|
<uui-box headline="Workflow">
|
|
559
599
|
${property(
|
|
560
600
|
'Name',
|
package/src/paths.ts
CHANGED
package/plugin/theme-switch.js
DELETED
|
@@ -1,135 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Light, dark or the computer's choice, from the header (story 049).
|
|
3
|
-
*
|
|
4
|
-
* The choice is Umbraco's theme context's — it links the stylesheet and keeps
|
|
5
|
-
* the alias in `localStorage` for the shell's early script to apply before the
|
|
6
|
-
* next paint. This adds the menu, and keeps the choice for the person in user
|
|
7
|
-
* data, so it follows them to another browser.
|
|
8
|
-
*/
|
|
9
|
-
import { css, html } from '@umbraco-cms/backoffice/external/lit'
|
|
10
|
-
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
11
|
-
import { UMB_THEME_CONTEXT } from '@umbraco-cms/backoffice/themes'
|
|
12
|
-
|
|
13
|
-
/** The Management API, under the back office wherever it is mounted. */
|
|
14
|
-
const USER_DATA = `${(document.querySelector('base')?.getAttribute('href') ?? '/crombolo/').replace(/\/$/, '')}/management/api/v1/user-data`
|
|
15
|
-
const GROUP = 'crombolo'
|
|
16
|
-
const IDENTIFIER = 'theme'
|
|
17
|
-
const EARLY = 'crombolo-early-theme'
|
|
18
|
-
|
|
19
|
-
const CHOICES = [
|
|
20
|
-
{ alias: 'umb-light-theme', label: 'Light', icon: 'icon-sunny' },
|
|
21
|
-
{ alias: 'Crombolo.Theme.Dark', label: 'Dark', icon: 'icon-contrast' },
|
|
22
|
-
{ alias: 'Crombolo.Theme.System', label: 'Match my system', icon: 'icon-lightbulb' },
|
|
23
|
-
]
|
|
24
|
-
|
|
25
|
-
export default class CromboloThemeSwitchElement extends UmbLitElement {
|
|
26
|
-
static properties = { _alias: { state: true } }
|
|
27
|
-
|
|
28
|
-
#context
|
|
29
|
-
#savedKey
|
|
30
|
-
|
|
31
|
-
constructor() {
|
|
32
|
-
super()
|
|
33
|
-
this._alias = 'umb-light-theme'
|
|
34
|
-
this.consumeContext(UMB_THEME_CONTEXT, (context) => {
|
|
35
|
-
this.#context = context
|
|
36
|
-
this.observe(context.theme, (alias) => {
|
|
37
|
-
this._alias = alias || 'umb-light-theme'
|
|
38
|
-
// The shell's early stylesheet stood in until the context took over;
|
|
39
|
-
// once the choice differs from it, it would only fight the new one.
|
|
40
|
-
const early = document.getElementById(EARLY)
|
|
41
|
-
if (early && early.dataset.theme !== this._alias) early.remove()
|
|
42
|
-
})
|
|
43
|
-
this.#restore()
|
|
44
|
-
})
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/** The person's saved choice, when this browser's differs from it. */
|
|
48
|
-
async #restore() {
|
|
49
|
-
try {
|
|
50
|
-
const query = new URLSearchParams({ groups: GROUP, identifiers: IDENTIFIER, take: '1' })
|
|
51
|
-
const response = await fetch(`${USER_DATA}?${query}`, { credentials: 'include' })
|
|
52
|
-
if (!response.ok) return
|
|
53
|
-
const found = (await response.json()).items?.[0]
|
|
54
|
-
if (!found) return
|
|
55
|
-
this.#savedKey = found.key
|
|
56
|
-
if (found.value && found.value !== this._alias) this.#context?.setThemeByAlias(found.value)
|
|
57
|
-
} catch {
|
|
58
|
-
// This browser's choice stands.
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
async #save(alias) {
|
|
63
|
-
const body = { group: GROUP, identifier: IDENTIFIER, value: alias }
|
|
64
|
-
try {
|
|
65
|
-
if (this.#savedKey) {
|
|
66
|
-
await fetch(USER_DATA, {
|
|
67
|
-
method: 'PUT',
|
|
68
|
-
credentials: 'include',
|
|
69
|
-
headers: { 'content-type': 'application/json' },
|
|
70
|
-
body: JSON.stringify({ ...body, key: this.#savedKey }),
|
|
71
|
-
})
|
|
72
|
-
return
|
|
73
|
-
}
|
|
74
|
-
const response = await fetch(USER_DATA, {
|
|
75
|
-
method: 'POST',
|
|
76
|
-
credentials: 'include',
|
|
77
|
-
headers: { 'content-type': 'application/json' },
|
|
78
|
-
body: JSON.stringify(body),
|
|
79
|
-
})
|
|
80
|
-
this.#savedKey = response.headers.get('umb-generated-resource') ?? undefined
|
|
81
|
-
} catch {
|
|
82
|
-
// Kept in this browser regardless; another will start from its own.
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
#choose(alias) {
|
|
87
|
-
this.#context?.setThemeByAlias(alias)
|
|
88
|
-
this.#save(alias)
|
|
89
|
-
this.renderRoot.querySelector('#crombolo-theme-menu')?.hidePopover?.()
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
render() {
|
|
93
|
-
const current = CHOICES.find((choice) => choice.alias === this._alias) ?? CHOICES[0]
|
|
94
|
-
return html`
|
|
95
|
-
<uui-button
|
|
96
|
-
compact
|
|
97
|
-
look="primary"
|
|
98
|
-
label="Light or dark: ${current.label}"
|
|
99
|
-
popovertarget="crombolo-theme-menu">
|
|
100
|
-
<umb-icon name=${current.icon}></umb-icon>
|
|
101
|
-
</uui-button>
|
|
102
|
-
<uui-popover-container id="crombolo-theme-menu" placement="bottom-end">
|
|
103
|
-
<umb-popover-layout>
|
|
104
|
-
${CHOICES.map(
|
|
105
|
-
(choice) => html`<uui-menu-item
|
|
106
|
-
label=${choice.label}
|
|
107
|
-
?active=${choice.alias === this._alias}
|
|
108
|
-
@click-label=${() => this.#choose(choice.alias)}>
|
|
109
|
-
<umb-icon slot="icon" name=${choice.icon}></umb-icon>
|
|
110
|
-
</uui-menu-item>`,
|
|
111
|
-
)}
|
|
112
|
-
</umb-popover-layout>
|
|
113
|
-
</uui-popover-container>
|
|
114
|
-
`
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
static styles = css`
|
|
118
|
-
uui-button {
|
|
119
|
-
font-size: 18px;
|
|
120
|
-
--uui-button-background-color: var(--umb-header-app-button-background-color, transparent);
|
|
121
|
-
--uui-button-background-color-hover: var(
|
|
122
|
-
--umb-header-app-button-background-color-hover,
|
|
123
|
-
var(--uui-color-emphasis)
|
|
124
|
-
);
|
|
125
|
-
}
|
|
126
|
-
:host {
|
|
127
|
-
--uui-menu-item-flat-structure: 1;
|
|
128
|
-
}
|
|
129
|
-
umb-popover-layout {
|
|
130
|
-
min-width: 12rem;
|
|
131
|
-
}
|
|
132
|
-
`
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
customElements.define('crombolo-theme-switch', CromboloThemeSwitchElement)
|