@crombolo/backoffice-host 0.39.1 → 0.41.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 +2 -2
- package/plugin/app-preview/umbraco-package.json +1 -1
- package/plugin/bundle-editor-code.js +2 -0
- package/plugin/bundle-editor-content.js +2 -0
- package/plugin/bundle-editor-context.js +95 -0
- package/plugin/bundle-editor-forms.js +2 -0
- package/plugin/bundle-editor-language.js +2 -0
- package/plugin/bundle-editor-routing.js +13 -0
- package/plugin/bundle-editor-sections.js +389 -0
- package/plugin/bundle-editor-types.js +2 -0
- package/plugin/bundle-editor-user-groups.js +2 -0
- package/plugin/bundle-editor-workflows.js +2 -0
- package/plugin/bundle-editor.js +140 -0
- package/plugin/bundles-client.js +12 -0
- package/plugin/bundles-created.js +2 -1
- package/plugin/localizations/umbraco-package.json +1 -1
- package/plugin/seo/umbraco-package.json +1 -1
- package/plugin/sign-in/umbraco-package.json +1 -1
- package/plugin/umbraco-package.json +137 -7
- package/plugin/branding/bundle-builder-labels.js +0 -92
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@crombolo/backoffice-host",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.41.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.
|
|
35
|
+
"@crombolo/core": "0.41.1",
|
|
36
36
|
"@crombolo/backoffice-dist": "18.2.0"
|
|
37
37
|
}
|
|
38
38
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the Bundle Editor's tabs share (story 233): the bundle's definition as
|
|
3
|
+
* Umbraco's package repository reads and saves it, so a definition made in
|
|
4
|
+
* Umbraco's builder opens here unchanged; and its forms, workflows and user
|
|
5
|
+
* groups (story 226), which Umbraco's definition has no fields for.
|
|
6
|
+
*/
|
|
7
|
+
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'
|
|
8
|
+
import { UmbContextToken } from '@umbraco-cms/backoffice/context-api'
|
|
9
|
+
import { UmbObjectState } from '@umbraco-cms/backoffice/observable-api'
|
|
10
|
+
import { UmbPackageRepository } from '@umbraco-cms/backoffice/package'
|
|
11
|
+
import { blobDownload } from '@umbraco-cms/backoffice/utils'
|
|
12
|
+
import { carriedSchema, readSchemaPicks, saveSchemaPicks, schemaChoices } from './bundles-client.js'
|
|
13
|
+
|
|
14
|
+
const NO_PICKS = { forms: [], workflows: [], userGroups: [], excluded: [] }
|
|
15
|
+
|
|
16
|
+
export const CROMBOLO_BUNDLE_EDITOR_CONTEXT = new UmbContextToken('CromboloBundleEditorContext')
|
|
17
|
+
|
|
18
|
+
/** Provides itself to the editor's tabs, as Umbraco's contexts do. */
|
|
19
|
+
export class CromboloBundleEditorContext extends UmbContextBase {
|
|
20
|
+
#repository
|
|
21
|
+
#state = new UmbObjectState(undefined)
|
|
22
|
+
/** The definition, as it stands in the editor. */
|
|
23
|
+
definition = this.#state.asObservable()
|
|
24
|
+
#picks = new UmbObjectState(NO_PICKS)
|
|
25
|
+
/** The forms, workflows and user groups picked, and the dependencies unticked. */
|
|
26
|
+
picks = this.#picks.asObservable()
|
|
27
|
+
#carried = new UmbObjectState([])
|
|
28
|
+
#asked = 0
|
|
29
|
+
/** What the picks carry: each pick, and what it brings and why. */
|
|
30
|
+
carried = this.#carried.asObservable()
|
|
31
|
+
#choices = new UmbObjectState({ forms: [], workflows: [], userGroups: [] })
|
|
32
|
+
/** The site's forms, workflows and user groups. */
|
|
33
|
+
choices = this.#choices.asObservable()
|
|
34
|
+
|
|
35
|
+
constructor(host) {
|
|
36
|
+
super(host, CROMBOLO_BUNDLE_EDITOR_CONTEXT)
|
|
37
|
+
this.#repository = new UmbPackageRepository(host)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/** Reads a saved definition, or a new one when `unique` is undefined. */
|
|
41
|
+
async load(unique) {
|
|
42
|
+
this.#state.setValue(await this.#repository.getCreatedPackage(unique))
|
|
43
|
+
const [choices, picks] = await Promise.all([
|
|
44
|
+
schemaChoices().catch(() => undefined),
|
|
45
|
+
unique ? readSchemaPicks(unique).catch(() => undefined) : undefined,
|
|
46
|
+
])
|
|
47
|
+
if (choices) this.#choices.setValue(choices)
|
|
48
|
+
await this.updatePicks(picks ?? NO_PICKS)
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** Changes some of the picks, and works out again what they carry. */
|
|
52
|
+
async updatePicks(patch) {
|
|
53
|
+
const picks = { ...this.#picks.getValue(), ...patch }
|
|
54
|
+
this.#picks.setValue(picks)
|
|
55
|
+
const asked = ++this.#asked
|
|
56
|
+
const { carried } = await carriedSchema(picks).catch(() => ({ carried: [] }))
|
|
57
|
+
if (asked === this.#asked) this.#carried.setValue(carried ?? [])
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
get value() {
|
|
61
|
+
return this.#state.getValue()
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Changes some of the definition's fields. */
|
|
65
|
+
update(patch) {
|
|
66
|
+
const current = this.#state.getValue()
|
|
67
|
+
if (current) this.#state.setValue({ ...current, ...patch })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Saves it, creating it the first time; resolves to its unique, or undefined. */
|
|
71
|
+
async save() {
|
|
72
|
+
const current = this.#state.getValue()
|
|
73
|
+
if (!current) return undefined
|
|
74
|
+
let unique = current.unique
|
|
75
|
+
if (unique) {
|
|
76
|
+
if (!(await this.#repository.updateCreatedPackage(current))) return undefined
|
|
77
|
+
} else {
|
|
78
|
+
unique = await this.#repository.saveCreatedPackage(current)
|
|
79
|
+
if (!unique || typeof unique !== 'string') return undefined
|
|
80
|
+
this.update({ unique })
|
|
81
|
+
}
|
|
82
|
+
await saveSchemaPicks(unique, this.#picks.getValue())
|
|
83
|
+
return unique
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/** Downloads the built bundle. */
|
|
87
|
+
async download() {
|
|
88
|
+
const unique = this.#state.getValue()?.unique
|
|
89
|
+
if (!unique) return
|
|
90
|
+
const data = await this.#repository.getCreatePackageDownload(unique)
|
|
91
|
+
if (!data) return
|
|
92
|
+
const zip = typeof data === 'object'
|
|
93
|
+
blobDownload(data, zip ? 'bundle.zip' : 'bundle.xml', zip ? 'application/zip' : 'text/xml')
|
|
94
|
+
}
|
|
95
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which workspace the Created view opens (story 233): Crombolo's Bundle Editor
|
|
3
|
+
* alone when it is registered. Its manifest overwrites Umbraco's builder, but
|
|
4
|
+
* the routes are ours, so they do not rely on that alone. Pure, for a test.
|
|
5
|
+
*/
|
|
6
|
+
export const BUNDLE_EDITOR_ALIAS = 'Crombolo.Workspace.BundleEditor'
|
|
7
|
+
export const UMBRACO_BUILDER_ALIAS = 'Umb.Workspace.PackageBuilder'
|
|
8
|
+
|
|
9
|
+
export function editorsOf(workspaces) {
|
|
10
|
+
return workspaces.some((workspace) => workspace.alias === BUNDLE_EDITOR_ALIAS)
|
|
11
|
+
? workspaces.filter((workspace) => workspace.alias !== UMBRACO_BUILDER_ALIAS)
|
|
12
|
+
: workspaces
|
|
13
|
+
}
|
|
@@ -0,0 +1,389 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Bundle Editor's tabs (story 233): each a workspace view drawing part of
|
|
3
|
+
* the definition with the inputs Umbraco's own package builder is made of, and
|
|
4
|
+
* writing back through the editor's context.
|
|
5
|
+
*/
|
|
6
|
+
import { UmbDictionaryPickerInputContext } from '@umbraco-cms/backoffice/dictionary'
|
|
7
|
+
import { css, html, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
8
|
+
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
9
|
+
import { UmbPartialViewPickerInputContext } from '@umbraco-cms/backoffice/partial-view'
|
|
10
|
+
import { UmbScriptPickerInputContext } from '@umbraco-cms/backoffice/script'
|
|
11
|
+
import { UmbServerFilePathUniqueSerializer } from '@umbraco-cms/backoffice/server-file-system'
|
|
12
|
+
import { UmbTextStyles } from '@umbraco-cms/backoffice/style'
|
|
13
|
+
import { UmbStylesheetPickerInputContext } from '@umbraco-cms/backoffice/stylesheet'
|
|
14
|
+
import { UmbTemplatePickerInputContext } from '@umbraco-cms/backoffice/template'
|
|
15
|
+
import { CROMBOLO_BUNDLE_EDITOR_CONTEXT } from './bundle-editor-context.js'
|
|
16
|
+
|
|
17
|
+
const paths = new UmbServerFilePathUniqueSerializer()
|
|
18
|
+
|
|
19
|
+
/** One tab: the definition from the editor's context, and a box of fields. */
|
|
20
|
+
export class CromboloBundleEditorView extends UmbLitElement {
|
|
21
|
+
static properties = { _definition: { state: true } }
|
|
22
|
+
|
|
23
|
+
/** The tab's headline. */
|
|
24
|
+
headline = ''
|
|
25
|
+
|
|
26
|
+
constructor() {
|
|
27
|
+
super()
|
|
28
|
+
this.consumeContext(CROMBOLO_BUNDLE_EDITOR_CONTEXT, (context) => {
|
|
29
|
+
this.context = context
|
|
30
|
+
// Called again with nothing as the tab is taken down.
|
|
31
|
+
if (!context) return
|
|
32
|
+
this.observe(context.definition, (definition) => {
|
|
33
|
+
this._definition = definition
|
|
34
|
+
})
|
|
35
|
+
})
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** Writes part of the definition back. */
|
|
39
|
+
set(patch) {
|
|
40
|
+
this.context?.update(patch)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** The tab's fields, given the definition. */
|
|
44
|
+
fields() {
|
|
45
|
+
return nothing
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
render() {
|
|
49
|
+
if (!this._definition) return nothing
|
|
50
|
+
return html`<uui-box headline=${this.headline}>${this.fields(this._definition)}</uui-box>`
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
static styles = [
|
|
54
|
+
UmbTextStyles,
|
|
55
|
+
css`
|
|
56
|
+
:host {
|
|
57
|
+
display: block;
|
|
58
|
+
padding: var(--uui-size-layout-1);
|
|
59
|
+
}
|
|
60
|
+
uui-checkbox {
|
|
61
|
+
margin-top: var(--uui-size-space-4);
|
|
62
|
+
}
|
|
63
|
+
`,
|
|
64
|
+
]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const field = (label, editor, description) =>
|
|
68
|
+
html`<umb-property-layout label=${label} description=${description ?? ''}>
|
|
69
|
+
<div slot="editor">${editor}</div>
|
|
70
|
+
</umb-property-layout>`
|
|
71
|
+
|
|
72
|
+
/** Content: a page and optionally its children, media, and Library elements. */
|
|
73
|
+
export class CromboloBundleContentView extends CromboloBundleEditorView {
|
|
74
|
+
headline = 'Content'
|
|
75
|
+
|
|
76
|
+
fields(d) {
|
|
77
|
+
return html`
|
|
78
|
+
${field(
|
|
79
|
+
'Content',
|
|
80
|
+
html`<umb-input-document
|
|
81
|
+
max="1"
|
|
82
|
+
.value=${d.contentNodeId ?? undefined}
|
|
83
|
+
@change=${(event) => {
|
|
84
|
+
const contentNodeId = event.target.selection[0]
|
|
85
|
+
this.set({
|
|
86
|
+
contentNodeId,
|
|
87
|
+
contentLoadChildNodes: contentNodeId ? d.contentLoadChildNodes : false,
|
|
88
|
+
})
|
|
89
|
+
}}></umb-input-document>
|
|
90
|
+
<uui-checkbox
|
|
91
|
+
label="Include the pages below it"
|
|
92
|
+
.checked=${d.contentLoadChildNodes ?? false}
|
|
93
|
+
.disabled=${!d.contentNodeId}
|
|
94
|
+
@change=${(event) => this.set({ contentLoadChildNodes: event.target.checked })}
|
|
95
|
+
>Include the pages below it</uui-checkbox
|
|
96
|
+
>`,
|
|
97
|
+
'The page the bundle starts from',
|
|
98
|
+
)}
|
|
99
|
+
${field(
|
|
100
|
+
'Media',
|
|
101
|
+
html`<umb-input-media
|
|
102
|
+
multiple
|
|
103
|
+
.selection=${d.mediaIds ?? []}
|
|
104
|
+
@change=${(event) => {
|
|
105
|
+
const mediaIds = event.target.selection ?? []
|
|
106
|
+
this.set({
|
|
107
|
+
mediaIds,
|
|
108
|
+
mediaLoadChildNodes: mediaIds.length ? d.mediaLoadChildNodes : false,
|
|
109
|
+
})
|
|
110
|
+
}}></umb-input-media>
|
|
111
|
+
<uui-checkbox
|
|
112
|
+
label="Include what is inside them"
|
|
113
|
+
.checked=${d.mediaLoadChildNodes ?? false}
|
|
114
|
+
.disabled=${!d.mediaIds?.length}
|
|
115
|
+
@change=${(event) => this.set({ mediaLoadChildNodes: event.target.checked })}
|
|
116
|
+
>Include what is inside them</uui-checkbox
|
|
117
|
+
>`,
|
|
118
|
+
)}
|
|
119
|
+
${field(
|
|
120
|
+
'Library elements',
|
|
121
|
+
html`<umb-input-element
|
|
122
|
+
.selection=${d.elementIds ?? []}
|
|
123
|
+
@change=${(event) => this.set({ elementIds: event.target.selection ?? [] })}></umb-input-element>`,
|
|
124
|
+
)}
|
|
125
|
+
`
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** Types: document, media and data types. */
|
|
130
|
+
export class CromboloBundleTypesView extends CromboloBundleEditorView {
|
|
131
|
+
headline = 'Types'
|
|
132
|
+
|
|
133
|
+
fields(d) {
|
|
134
|
+
return html`
|
|
135
|
+
${field(
|
|
136
|
+
'Document types',
|
|
137
|
+
html`<umb-input-document-type
|
|
138
|
+
.selection=${d.documentTypes ?? []}
|
|
139
|
+
@change=${(event) => this.set({ documentTypes: event.target.selection ?? [] })}></umb-input-document-type>`,
|
|
140
|
+
)}
|
|
141
|
+
${field(
|
|
142
|
+
'Media types',
|
|
143
|
+
html`<umb-input-media-type
|
|
144
|
+
.selection=${d.mediaTypes ?? []}
|
|
145
|
+
@change=${(event) => this.set({ mediaTypes: event.target.selection ?? [] })}></umb-input-media-type>`,
|
|
146
|
+
)}
|
|
147
|
+
${field(
|
|
148
|
+
'Data types',
|
|
149
|
+
html`<umb-data-type-input
|
|
150
|
+
.selection=${d.dataTypes ?? []}
|
|
151
|
+
@change=${(event) => this.set({ dataTypes: event.target.selection ?? [] })}></umb-data-type-input>`,
|
|
152
|
+
)}
|
|
153
|
+
<crombolo-bundle-brought-types></crombolo-bundle-brought-types>
|
|
154
|
+
`
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** A list of server files (stylesheets, scripts, partial views) as the builder keeps them. */
|
|
159
|
+
const filePicker = (view, d, key, icon, pickerContext) =>
|
|
160
|
+
html`<umb-input-entity
|
|
161
|
+
.getIcon=${() => icon}
|
|
162
|
+
.pickerContext=${pickerContext}
|
|
163
|
+
.selection=${(d[key] ?? []).map((path) => paths.toUnique(path))}
|
|
164
|
+
@change=${(event) =>
|
|
165
|
+
view.set({
|
|
166
|
+
[key]: (event.target.selection ?? []).map((unique) => paths.toServerPath(unique)),
|
|
167
|
+
})}></umb-input-entity>`
|
|
168
|
+
|
|
169
|
+
/** Code: templates, partial views, stylesheets and scripts. */
|
|
170
|
+
export class CromboloBundleCodeView extends CromboloBundleEditorView {
|
|
171
|
+
headline = 'Code'
|
|
172
|
+
|
|
173
|
+
fields(d) {
|
|
174
|
+
return html`
|
|
175
|
+
${field(
|
|
176
|
+
'Templates',
|
|
177
|
+
html`<umb-input-entity
|
|
178
|
+
.getIcon=${() => 'icon-document-html'}
|
|
179
|
+
.pickerContext=${UmbTemplatePickerInputContext}
|
|
180
|
+
.selection=${d.templates ?? []}
|
|
181
|
+
@change=${(event) => this.set({ templates: event.target.selection ?? [] })}></umb-input-entity>`,
|
|
182
|
+
)}
|
|
183
|
+
${field(
|
|
184
|
+
'Partial views',
|
|
185
|
+
filePicker(this, d, 'partialViews', 'icon-document-html', UmbPartialViewPickerInputContext),
|
|
186
|
+
)}
|
|
187
|
+
${field('Stylesheets', filePicker(this, d, 'stylesheets', 'icon-palette', UmbStylesheetPickerInputContext))}
|
|
188
|
+
${field('Scripts', filePicker(this, d, 'scripts', 'icon-document-js', UmbScriptPickerInputContext))}
|
|
189
|
+
`
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
/** Language: languages and dictionary items. */
|
|
194
|
+
export class CromboloBundleLanguageView extends CromboloBundleEditorView {
|
|
195
|
+
headline = 'Language'
|
|
196
|
+
|
|
197
|
+
fields(d) {
|
|
198
|
+
return html`
|
|
199
|
+
${field(
|
|
200
|
+
'Languages',
|
|
201
|
+
html`<umb-input-language
|
|
202
|
+
.value=${(d.languages ?? []).join(',')}
|
|
203
|
+
@change=${(event) => this.set({ languages: event.target.selection ?? [] })}></umb-input-language>`,
|
|
204
|
+
)}
|
|
205
|
+
${field(
|
|
206
|
+
'Dictionary',
|
|
207
|
+
html`<umb-input-entity
|
|
208
|
+
.getIcon=${() => 'icon-book-alt'}
|
|
209
|
+
.pickerContext=${UmbDictionaryPickerInputContext}
|
|
210
|
+
.selection=${d.dictionaryItems ?? []}
|
|
211
|
+
@change=${(event) => this.set({ dictionaryItems: event.target.selection ?? [] })}></umb-input-entity>`,
|
|
212
|
+
)}
|
|
213
|
+
`
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
const LISTS = { form: 'forms', workflow: 'workflows', userGroup: 'userGroups' }
|
|
218
|
+
|
|
219
|
+
const KEY = (kind, alias) => `${kind}:${alias}`.toLowerCase()
|
|
220
|
+
|
|
221
|
+
/** Why a dependency matters, said where it can be unticked. */
|
|
222
|
+
const NEEDS = {
|
|
223
|
+
userGroup: (by) => `${by} needs this group`,
|
|
224
|
+
documentType: (by) => `${by} needs this document type`,
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
/**
|
|
228
|
+
* The forms, approval workflows and user groups tabs (story 226): the site's
|
|
229
|
+
* own, ticked to carry them. What a ticked one needs is ticked with it, saying
|
|
230
|
+
* why; unticking that leaves it out, with a warning.
|
|
231
|
+
*/
|
|
232
|
+
class CromboloBundleSchemaView extends CromboloBundleEditorView {
|
|
233
|
+
static properties = {
|
|
234
|
+
...CromboloBundleEditorView.properties,
|
|
235
|
+
_picks: { state: true },
|
|
236
|
+
_carried: { state: true },
|
|
237
|
+
_choices: { state: true },
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
/** `form`, `workflow` or `userGroup`. */
|
|
241
|
+
kind = ''
|
|
242
|
+
/** Said when the site has none to pick. */
|
|
243
|
+
empty = ''
|
|
244
|
+
|
|
245
|
+
constructor() {
|
|
246
|
+
super()
|
|
247
|
+
this.consumeContext(CROMBOLO_BUNDLE_EDITOR_CONTEXT, (context) => {
|
|
248
|
+
if (!context) return
|
|
249
|
+
this.observe(context.picks, (picks) => {
|
|
250
|
+
this._picks = picks
|
|
251
|
+
})
|
|
252
|
+
this.observe(context.carried, (carried) => {
|
|
253
|
+
this._carried = carried
|
|
254
|
+
})
|
|
255
|
+
this.observe(context.choices, (choices) => {
|
|
256
|
+
this._choices = choices
|
|
257
|
+
})
|
|
258
|
+
})
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
/** Ticks or unticks one, as a pick or as something a pick brought. */
|
|
262
|
+
toggle(kind, alias, on) {
|
|
263
|
+
const picks = this._picks
|
|
264
|
+
const key = KEY(kind, alias)
|
|
265
|
+
const list = LISTS[kind]
|
|
266
|
+
const brought = (this._carried ?? []).some((c) => c.for && KEY(c.kind, c.alias) === key)
|
|
267
|
+
const excluded = picks.excluded.filter((entry) => entry.toLowerCase() !== key)
|
|
268
|
+
if (on) {
|
|
269
|
+
const listed = list ? picks[list] : []
|
|
270
|
+
this.context?.updatePicks({
|
|
271
|
+
excluded,
|
|
272
|
+
...(list && !brought && !listed.includes(alias) ? { [list]: [...listed, alias] } : {}),
|
|
273
|
+
})
|
|
274
|
+
return
|
|
275
|
+
}
|
|
276
|
+
this.context?.updatePicks({
|
|
277
|
+
...(list ? { [list]: picks[list].filter((a) => a !== alias) } : {}),
|
|
278
|
+
excluded: brought ? [...excluded, KEY(kind, alias)] : excluded,
|
|
279
|
+
})
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/** One row: a checkbox, and why it is ticked or what leaving it out means. */
|
|
283
|
+
row(kind, alias, name) {
|
|
284
|
+
const key = KEY(kind, alias)
|
|
285
|
+
const carried = (this._carried ?? []).filter((c) => KEY(c.kind, c.alias) === key)
|
|
286
|
+
const picked = carried.some((c) => !c.for)
|
|
287
|
+
const brought = carried.find((c) => c.for)
|
|
288
|
+
const ticked = picked || (brought && !brought.excluded)
|
|
289
|
+
const note =
|
|
290
|
+
!picked && brought
|
|
291
|
+
? brought.excluded
|
|
292
|
+
? html`<p class="warning">${NEEDS[kind]?.(brought.for.name)}. Leave it out only if the site that installs the bundle already has it.</p>`
|
|
293
|
+
: html`<p class="note">Added for ${brought.for.name}</p>`
|
|
294
|
+
: nothing
|
|
295
|
+
return html`<div class="row">
|
|
296
|
+
<uui-checkbox
|
|
297
|
+
label=${name}
|
|
298
|
+
.checked=${Boolean(ticked)}
|
|
299
|
+
@change=${(event) => this.toggle(kind, alias, event.target.checked)}
|
|
300
|
+
>${name}</uui-checkbox
|
|
301
|
+
>${note}
|
|
302
|
+
</div>`
|
|
303
|
+
}
|
|
304
|
+
|
|
305
|
+
fields() {
|
|
306
|
+
if (!this._picks || !this._choices) return nothing
|
|
307
|
+
const choices = this._choices[LISTS[this.kind]] ?? []
|
|
308
|
+
if (choices.length === 0) return html`<p>${this.empty}</p>`
|
|
309
|
+
return choices.map((choice) => this.row(this.kind, choice.alias, choice.name))
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
static styles = [
|
|
313
|
+
...CromboloBundleEditorView.styles,
|
|
314
|
+
css`
|
|
315
|
+
.row {
|
|
316
|
+
margin-bottom: var(--uui-size-space-4);
|
|
317
|
+
}
|
|
318
|
+
.row uui-checkbox {
|
|
319
|
+
margin-top: 0;
|
|
320
|
+
}
|
|
321
|
+
.note,
|
|
322
|
+
.warning {
|
|
323
|
+
margin: var(--uui-size-space-1) 0 0 var(--uui-size-space-6);
|
|
324
|
+
font-size: var(--uui-type-small-size);
|
|
325
|
+
}
|
|
326
|
+
.note {
|
|
327
|
+
color: var(--uui-color-text-alt);
|
|
328
|
+
}
|
|
329
|
+
.warning {
|
|
330
|
+
color: var(--uui-color-warning-standalone);
|
|
331
|
+
}
|
|
332
|
+
`,
|
|
333
|
+
]
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
export class CromboloBundleFormsView extends CromboloBundleSchemaView {
|
|
337
|
+
headline = 'Forms'
|
|
338
|
+
kind = 'form'
|
|
339
|
+
empty = 'This site has no forms.'
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
export class CromboloBundleWorkflowsView extends CromboloBundleSchemaView {
|
|
343
|
+
headline = 'Approval workflows'
|
|
344
|
+
kind = 'workflow'
|
|
345
|
+
empty = 'This site has no approval workflows.'
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
export class CromboloBundleUserGroupsView extends CromboloBundleSchemaView {
|
|
349
|
+
headline = 'User groups'
|
|
350
|
+
kind = 'userGroup'
|
|
351
|
+
empty = 'This site declares no user groups of its own.'
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
/** The document types the forms and workflows bring, on the Types tab. */
|
|
355
|
+
class CromboloBundleBroughtTypes extends CromboloBundleSchemaView {
|
|
356
|
+
kind = 'documentType'
|
|
357
|
+
|
|
358
|
+
fields() {
|
|
359
|
+
const brought = (this._carried ?? []).filter((c) => c.kind === 'documentType')
|
|
360
|
+
if (brought.length === 0) return nothing
|
|
361
|
+
return field(
|
|
362
|
+
'Added for forms and workflows',
|
|
363
|
+
brought.map((c) => this.row('documentType', c.alias, c.alias)),
|
|
364
|
+
'Carried as well as the document types picked above',
|
|
365
|
+
)
|
|
366
|
+
}
|
|
367
|
+
|
|
368
|
+
render() {
|
|
369
|
+
return this.fields()
|
|
370
|
+
}
|
|
371
|
+
|
|
372
|
+
static styles = [
|
|
373
|
+
...CromboloBundleSchemaView.styles,
|
|
374
|
+
css`
|
|
375
|
+
:host {
|
|
376
|
+
padding: 0;
|
|
377
|
+
}
|
|
378
|
+
`,
|
|
379
|
+
]
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
customElements.define('crombolo-bundle-content-view', CromboloBundleContentView)
|
|
383
|
+
customElements.define('crombolo-bundle-types-view', CromboloBundleTypesView)
|
|
384
|
+
customElements.define('crombolo-bundle-code-view', CromboloBundleCodeView)
|
|
385
|
+
customElements.define('crombolo-bundle-language-view', CromboloBundleLanguageView)
|
|
386
|
+
customElements.define('crombolo-bundle-forms-view', CromboloBundleFormsView)
|
|
387
|
+
customElements.define('crombolo-bundle-workflows-view', CromboloBundleWorkflowsView)
|
|
388
|
+
customElements.define('crombolo-bundle-user-groups-view', CromboloBundleUserGroupsView)
|
|
389
|
+
customElements.define('crombolo-bundle-brought-types', CromboloBundleBroughtTypes)
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The Bundle Editor (story 233), in place of Umbraco's package builder: its
|
|
3
|
+
* manifest declares `overwrites: ['Umb.Workspace.PackageBuilder']`, so the
|
|
4
|
+
* Created view's routes open this one. Umbraco's builder draws its form as the
|
|
5
|
+
* workspace editor's default content, which no added tab can sit beside; here
|
|
6
|
+
* every part of the bundle is a workspace view, so another tab is one more
|
|
7
|
+
* registration (docs/bundles.md, "Created packages").
|
|
8
|
+
*/
|
|
9
|
+
import { UmbContextBase } from '@umbraco-cms/backoffice/class-api'
|
|
10
|
+
import { css, html, ifDefined, nothing } from '@umbraco-cms/backoffice/external/lit'
|
|
11
|
+
import { UmbLitElement, umbFocus } from '@umbraco-cms/backoffice/lit-element'
|
|
12
|
+
import { UMB_NOTIFICATION_CONTEXT } from '@umbraco-cms/backoffice/notification'
|
|
13
|
+
import { UmbTextStyles } from '@umbraco-cms/backoffice/style'
|
|
14
|
+
import { UMB_WORKSPACE_CONTEXT } from '@umbraco-cms/backoffice/workspace'
|
|
15
|
+
import { CromboloBundleEditorContext } from './bundle-editor-context.js'
|
|
16
|
+
import { BUNDLE_EDITOR_ALIAS } from './bundle-editor-routing.js'
|
|
17
|
+
|
|
18
|
+
/** The workspace this is, as the views' conditions and Umbraco's workspace editor read it. */
|
|
19
|
+
class CromboloBundleWorkspaceContext extends UmbContextBase {
|
|
20
|
+
workspaceAlias = BUNDLE_EDITOR_ALIAS
|
|
21
|
+
#unique
|
|
22
|
+
|
|
23
|
+
constructor(host, unique) {
|
|
24
|
+
super(host, UMB_WORKSPACE_CONTEXT)
|
|
25
|
+
this.#unique = unique
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
getEntityType() {
|
|
29
|
+
return 'package-builder'
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
getUnique() {
|
|
33
|
+
return this.#unique()
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export default class CromboloBundleEditorElement extends UmbLitElement {
|
|
38
|
+
static properties = {
|
|
39
|
+
entityUnique: { type: String },
|
|
40
|
+
_definition: { state: true },
|
|
41
|
+
_submitState: { state: true },
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
#context = new CromboloBundleEditorContext(this)
|
|
45
|
+
#notifications
|
|
46
|
+
|
|
47
|
+
constructor() {
|
|
48
|
+
super()
|
|
49
|
+
// What a workspace view's `Umb.Condition.WorkspaceAlias` reads, so the tabs
|
|
50
|
+
// registered for this workspace are shown.
|
|
51
|
+
new CromboloBundleWorkspaceContext(this, () => this.#context.value?.unique)
|
|
52
|
+
this.consumeContext(UMB_NOTIFICATION_CONTEXT, (context) => {
|
|
53
|
+
this.#notifications = context
|
|
54
|
+
})
|
|
55
|
+
this.observe(this.#context.definition, (definition) => {
|
|
56
|
+
this._definition = definition
|
|
57
|
+
})
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
connectedCallback() {
|
|
61
|
+
super.connectedCallback()
|
|
62
|
+
void this.#context.load(this.entityUnique)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
async #save() {
|
|
66
|
+
if (!this._definition?.name?.trim()) {
|
|
67
|
+
this.#notifications?.peek('danger', { data: { message: 'Give the bundle a name first' } })
|
|
68
|
+
return
|
|
69
|
+
}
|
|
70
|
+
const created = !this._definition.unique
|
|
71
|
+
this._submitState = 'waiting'
|
|
72
|
+
try {
|
|
73
|
+
const unique = await this.#context.save()
|
|
74
|
+
if (!unique) throw new Error('not saved')
|
|
75
|
+
this._submitState = 'success'
|
|
76
|
+
this.#notifications?.peek('positive', {
|
|
77
|
+
data: { message: created ? 'Bundle created' : 'Bundle saved' },
|
|
78
|
+
})
|
|
79
|
+
} catch {
|
|
80
|
+
this._submitState = 'failed'
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
render() {
|
|
85
|
+
return html`
|
|
86
|
+
<umb-workspace-editor back-path="section/packages/view/created">
|
|
87
|
+
${
|
|
88
|
+
this._definition
|
|
89
|
+
? html`<div id="header" slot="header">
|
|
90
|
+
<uui-input
|
|
91
|
+
id="name"
|
|
92
|
+
required
|
|
93
|
+
label="Name of the bundle"
|
|
94
|
+
placeholder="Enter a name"
|
|
95
|
+
${umbFocus()}
|
|
96
|
+
.value=${this._definition.name ?? ''}
|
|
97
|
+
@input=${(event) => this.#context.update({ name: event.target.value })}></uui-input>
|
|
98
|
+
</div>`
|
|
99
|
+
: nothing
|
|
100
|
+
}
|
|
101
|
+
<div slot="actions">
|
|
102
|
+
${
|
|
103
|
+
this._definition?.unique
|
|
104
|
+
? html`<uui-button
|
|
105
|
+
look="secondary"
|
|
106
|
+
label="Download"
|
|
107
|
+
@click=${() => this.#context.download()}></uui-button>`
|
|
108
|
+
: nothing
|
|
109
|
+
}
|
|
110
|
+
<uui-button
|
|
111
|
+
color="positive"
|
|
112
|
+
look="primary"
|
|
113
|
+
state=${ifDefined(this._submitState)}
|
|
114
|
+
label=${this._definition?.unique ? 'Save' : 'Create'}
|
|
115
|
+
@click=${this.#save}></uui-button>
|
|
116
|
+
</div>
|
|
117
|
+
</umb-workspace-editor>
|
|
118
|
+
`
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
static styles = [
|
|
122
|
+
UmbTextStyles,
|
|
123
|
+
css`
|
|
124
|
+
:host {
|
|
125
|
+
display: block;
|
|
126
|
+
height: 100%;
|
|
127
|
+
}
|
|
128
|
+
#header {
|
|
129
|
+
display: flex;
|
|
130
|
+
width: 100%;
|
|
131
|
+
margin-right: var(--uui-size-layout-1);
|
|
132
|
+
}
|
|
133
|
+
uui-input {
|
|
134
|
+
width: 100%;
|
|
135
|
+
}
|
|
136
|
+
`,
|
|
137
|
+
]
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
customElements.define('crombolo-bundle-editor', CromboloBundleEditorElement)
|
package/plugin/bundles-client.js
CHANGED
|
@@ -59,3 +59,15 @@ export const readCreatedPackage = (id) => json(`/created/${encodeURIComponent(id
|
|
|
59
59
|
|
|
60
60
|
export const saveCreatedPackage = (id, pkg) =>
|
|
61
61
|
json(`/created/${encodeURIComponent(id)}/package`, { method: 'PUT', body: JSON.stringify(pkg) })
|
|
62
|
+
|
|
63
|
+
/** The site's forms, approval workflows and user groups a created bundle can carry (story 226). */
|
|
64
|
+
export const schemaChoices = () => json('/schema')
|
|
65
|
+
|
|
66
|
+
/** What a set of picks carries: the picks, and what they bring. */
|
|
67
|
+
export const carriedSchema = (picks) =>
|
|
68
|
+
json('/schema/carried', { method: 'POST', body: JSON.stringify(picks) })
|
|
69
|
+
|
|
70
|
+
export const readSchemaPicks = (id) => json(`/created/${encodeURIComponent(id)}/schema`)
|
|
71
|
+
|
|
72
|
+
export const saveSchemaPicks = (id, picks) =>
|
|
73
|
+
json(`/created/${encodeURIComponent(id)}/schema`, { method: 'PUT', body: JSON.stringify(picks) })
|
|
@@ -14,6 +14,7 @@ import { createExtensionElement } from '@umbraco-cms/backoffice/extension-api'
|
|
|
14
14
|
import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry'
|
|
15
15
|
import { html } from '@umbraco-cms/backoffice/external/lit'
|
|
16
16
|
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element'
|
|
17
|
+
import { editorsOf } from './bundle-editor-routing.js'
|
|
17
18
|
|
|
18
19
|
/** The entity type Umbraco's builder workspace declares, and the route segment. */
|
|
19
20
|
export const BUILDER_ENTITY_TYPE = 'package-builder'
|
|
@@ -46,7 +47,7 @@ export default class CromboloBundlesCreatedElement extends UmbLitElement {
|
|
|
46
47
|
/** Umbraco's own route table, with our overview in place of its own. */
|
|
47
48
|
export function routesFor(workspaces) {
|
|
48
49
|
const routes = [{ path: 'overview', component: () => import('./bundles-created-overview.js') }]
|
|
49
|
-
for (const workspace of workspaces) {
|
|
50
|
+
for (const workspace of editorsOf(workspaces)) {
|
|
50
51
|
routes.push({
|
|
51
52
|
path: `${workspace.meta.entityType}/edit/:unique`,
|
|
52
53
|
component: () => createExtensionElement(workspace),
|
|
@@ -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.41.1",
|
|
6
6
|
"allowPublicAccess": false,
|
|
7
7
|
"extensions": [
|
|
8
8
|
{
|
|
@@ -170,6 +170,142 @@
|
|
|
170
170
|
}
|
|
171
171
|
]
|
|
172
172
|
},
|
|
173
|
+
{
|
|
174
|
+
"type": "workspace",
|
|
175
|
+
"alias": "Crombolo.Workspace.BundleEditor",
|
|
176
|
+
"name": "Crombolo Bundle Editor",
|
|
177
|
+
"element": "/crombolo-plugin/bundle-editor.js",
|
|
178
|
+
"overwrites": ["Umb.Workspace.PackageBuilder"],
|
|
179
|
+
"meta": {
|
|
180
|
+
"entityType": "package-builder"
|
|
181
|
+
}
|
|
182
|
+
},
|
|
183
|
+
{
|
|
184
|
+
"type": "workspaceView",
|
|
185
|
+
"alias": "Crombolo.WorkspaceView.BundleEditor.Content",
|
|
186
|
+
"name": "Crombolo Bundle Editor Content",
|
|
187
|
+
"element": "/crombolo-plugin/bundle-editor-content.js",
|
|
188
|
+
"weight": 400,
|
|
189
|
+
"meta": {
|
|
190
|
+
"label": "Content",
|
|
191
|
+
"pathname": "content",
|
|
192
|
+
"icon": "icon-document"
|
|
193
|
+
},
|
|
194
|
+
"conditions": [
|
|
195
|
+
{
|
|
196
|
+
"alias": "Umb.Condition.WorkspaceAlias",
|
|
197
|
+
"match": "Crombolo.Workspace.BundleEditor"
|
|
198
|
+
}
|
|
199
|
+
]
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
"type": "workspaceView",
|
|
203
|
+
"alias": "Crombolo.WorkspaceView.BundleEditor.Types",
|
|
204
|
+
"name": "Crombolo Bundle Editor Types",
|
|
205
|
+
"element": "/crombolo-plugin/bundle-editor-types.js",
|
|
206
|
+
"weight": 300,
|
|
207
|
+
"meta": {
|
|
208
|
+
"label": "Types",
|
|
209
|
+
"pathname": "types",
|
|
210
|
+
"icon": "icon-item-arrangement"
|
|
211
|
+
},
|
|
212
|
+
"conditions": [
|
|
213
|
+
{
|
|
214
|
+
"alias": "Umb.Condition.WorkspaceAlias",
|
|
215
|
+
"match": "Crombolo.Workspace.BundleEditor"
|
|
216
|
+
}
|
|
217
|
+
]
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"type": "workspaceView",
|
|
221
|
+
"alias": "Crombolo.WorkspaceView.BundleEditor.Code",
|
|
222
|
+
"name": "Crombolo Bundle Editor Code",
|
|
223
|
+
"element": "/crombolo-plugin/bundle-editor-code.js",
|
|
224
|
+
"weight": 200,
|
|
225
|
+
"meta": {
|
|
226
|
+
"label": "Code",
|
|
227
|
+
"pathname": "code",
|
|
228
|
+
"icon": "icon-code"
|
|
229
|
+
},
|
|
230
|
+
"conditions": [
|
|
231
|
+
{
|
|
232
|
+
"alias": "Umb.Condition.WorkspaceAlias",
|
|
233
|
+
"match": "Crombolo.Workspace.BundleEditor"
|
|
234
|
+
}
|
|
235
|
+
]
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
"type": "workspaceView",
|
|
239
|
+
"alias": "Crombolo.WorkspaceView.BundleEditor.Language",
|
|
240
|
+
"name": "Crombolo Bundle Editor Language",
|
|
241
|
+
"element": "/crombolo-plugin/bundle-editor-language.js",
|
|
242
|
+
"weight": 100,
|
|
243
|
+
"meta": {
|
|
244
|
+
"label": "Language",
|
|
245
|
+
"pathname": "language",
|
|
246
|
+
"icon": "icon-globe"
|
|
247
|
+
},
|
|
248
|
+
"conditions": [
|
|
249
|
+
{
|
|
250
|
+
"alias": "Umb.Condition.WorkspaceAlias",
|
|
251
|
+
"match": "Crombolo.Workspace.BundleEditor"
|
|
252
|
+
}
|
|
253
|
+
]
|
|
254
|
+
},
|
|
255
|
+
{
|
|
256
|
+
"type": "workspaceView",
|
|
257
|
+
"alias": "Crombolo.WorkspaceView.BundleEditor.Forms",
|
|
258
|
+
"name": "Crombolo Bundle Editor Forms",
|
|
259
|
+
"element": "/crombolo-plugin/bundle-editor-forms.js",
|
|
260
|
+
"weight": 90,
|
|
261
|
+
"meta": {
|
|
262
|
+
"label": "Forms",
|
|
263
|
+
"pathname": "forms",
|
|
264
|
+
"icon": "icon-autofill"
|
|
265
|
+
},
|
|
266
|
+
"conditions": [
|
|
267
|
+
{
|
|
268
|
+
"alias": "Umb.Condition.WorkspaceAlias",
|
|
269
|
+
"match": "Crombolo.Workspace.BundleEditor"
|
|
270
|
+
}
|
|
271
|
+
]
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
"type": "workspaceView",
|
|
275
|
+
"alias": "Crombolo.WorkspaceView.BundleEditor.Workflows",
|
|
276
|
+
"name": "Crombolo Bundle Editor Workflows",
|
|
277
|
+
"element": "/crombolo-plugin/bundle-editor-workflows.js",
|
|
278
|
+
"weight": 80,
|
|
279
|
+
"meta": {
|
|
280
|
+
"label": "Workflows",
|
|
281
|
+
"pathname": "workflows",
|
|
282
|
+
"icon": "icon-mindmap"
|
|
283
|
+
},
|
|
284
|
+
"conditions": [
|
|
285
|
+
{
|
|
286
|
+
"alias": "Umb.Condition.WorkspaceAlias",
|
|
287
|
+
"match": "Crombolo.Workspace.BundleEditor"
|
|
288
|
+
}
|
|
289
|
+
]
|
|
290
|
+
},
|
|
291
|
+
{
|
|
292
|
+
"type": "workspaceView",
|
|
293
|
+
"alias": "Crombolo.WorkspaceView.BundleEditor.UserGroups",
|
|
294
|
+
"name": "Crombolo Bundle Editor User groups",
|
|
295
|
+
"element": "/crombolo-plugin/bundle-editor-user-groups.js",
|
|
296
|
+
"weight": 70,
|
|
297
|
+
"meta": {
|
|
298
|
+
"label": "User groups",
|
|
299
|
+
"pathname": "user-groups",
|
|
300
|
+
"icon": "icon-users"
|
|
301
|
+
},
|
|
302
|
+
"conditions": [
|
|
303
|
+
{
|
|
304
|
+
"alias": "Umb.Condition.WorkspaceAlias",
|
|
305
|
+
"match": "Crombolo.Workspace.BundleEditor"
|
|
306
|
+
}
|
|
307
|
+
]
|
|
308
|
+
},
|
|
173
309
|
{
|
|
174
310
|
"type": "sectionView",
|
|
175
311
|
"alias": "Crombolo.SectionView.Bundles.Installed",
|
|
@@ -458,12 +594,6 @@
|
|
|
458
594
|
"name": "Crombolo Client Credential Prefix",
|
|
459
595
|
"js": "/crombolo-plugin/branding/client-credentials.js"
|
|
460
596
|
},
|
|
461
|
-
{
|
|
462
|
-
"type": "backofficeEntryPoint",
|
|
463
|
-
"alias": "Crombolo.EntryPoint.BundleBuilderLabels",
|
|
464
|
-
"name": "Crombolo Bundle Builder Labels",
|
|
465
|
-
"js": "/crombolo-plugin/branding/bundle-builder-labels.js"
|
|
466
|
-
},
|
|
467
597
|
{
|
|
468
598
|
"type": "backofficeEntryPoint",
|
|
469
599
|
"alias": "Crombolo.EntryPoint.ComponentsTree",
|
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* The two labels and two toasts Umbraco's bundle builder hard-codes.
|
|
3
|
-
*
|
|
4
|
-
* The builder workspace is vendored and its copy is English in the template
|
|
5
|
-
* rather than dictionary keys, so there is no key to override: `Name of the
|
|
6
|
-
* package` labels the name input and `Package Content` heads the picker box.
|
|
7
|
-
* Everything else in that screen is already a key or a field name.
|
|
8
|
-
*
|
|
9
|
-
* Corrected after the element's first render, the same way the client
|
|
10
|
-
* credential dialog's prefix is, because both strings are written by the
|
|
11
|
-
* element's own template and there is nothing further upstream to intercept.
|
|
12
|
-
*
|
|
13
|
-
* Does nothing if upstream changes either string, so the cost of a vendor bump
|
|
14
|
-
* is the correction and never an error — `tests/bundles-backoffice.test.ts`
|
|
15
|
-
* asserts both are still there to correct.
|
|
16
|
-
*/
|
|
17
|
-
|
|
18
|
-
/** Vendored text to the text that replaces it. */
|
|
19
|
-
export const BUILDER_LABELS = [
|
|
20
|
-
['Name of the package', 'Name of the bundle'],
|
|
21
|
-
['Package Content', 'Bundle content'],
|
|
22
|
-
]
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* The builder's toasts on saving a definition. Shown through the notification
|
|
26
|
-
* context, so they are corrected where every toast passes rather than in the
|
|
27
|
-
* element, whose `peek` call is its own.
|
|
28
|
-
*/
|
|
29
|
-
export const BUILDER_TOASTS = [
|
|
30
|
-
['Package saved', 'Bundle saved'],
|
|
31
|
-
['Package updated', 'Bundle saved'],
|
|
32
|
-
]
|
|
33
|
-
|
|
34
|
-
/** The replacement for a vendored string, or undefined when it is not one of ours. */
|
|
35
|
-
export function correctionFor(text) {
|
|
36
|
-
if (typeof text !== 'string') return undefined
|
|
37
|
-
const trimmed = text.trim()
|
|
38
|
-
return BUILDER_LABELS.find(([before]) => before === trimmed)?.[1]
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
function correct(root) {
|
|
42
|
-
const input = root?.querySelector('#package-name-input')
|
|
43
|
-
const label = correctionFor(input?.getAttribute('label'))
|
|
44
|
-
if (label) input.setAttribute('label', label)
|
|
45
|
-
|
|
46
|
-
for (const box of root?.querySelectorAll('uui-box') ?? []) {
|
|
47
|
-
const headline = correctionFor(box.getAttribute('headline'))
|
|
48
|
-
if (headline) box.setAttribute('headline', headline)
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* Wraps the element's own `updated`, not `firstUpdated`: the builder renders
|
|
54
|
-
* its header before the definition has loaded and fills it in afterwards, so a
|
|
55
|
-
* one-shot correction would run against a template that is not there yet.
|
|
56
|
-
*/
|
|
57
|
-
function patch(element) {
|
|
58
|
-
const proto = element?.prototype
|
|
59
|
-
const original = proto?.updated
|
|
60
|
-
if (typeof original !== 'function') return false
|
|
61
|
-
proto.updated = function updated(changed) {
|
|
62
|
-
original.call(this, changed)
|
|
63
|
-
correct(this.shadowRoot)
|
|
64
|
-
}
|
|
65
|
-
return true
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
// Loaded here rather than at the top, so the module's pure parts import
|
|
69
|
-
// anywhere — the tests read `BUILDER_LABELS` and `BUILDER_TOASTS` outside a browser.
|
|
70
|
-
async function correctToasts() {
|
|
71
|
-
const { UmbNotificationContext } = await import('@umbraco-cms/backoffice/notification')
|
|
72
|
-
const proto = UmbNotificationContext.prototype
|
|
73
|
-
const peek = proto.peek
|
|
74
|
-
if (typeof peek !== 'function') return
|
|
75
|
-
proto.peek = function correctedPeek(color, options) {
|
|
76
|
-
const message = options?.data?.message
|
|
77
|
-
const replacement = BUILDER_TOASTS.find(([before]) => before === message)?.[1]
|
|
78
|
-
return peek.call(
|
|
79
|
-
this,
|
|
80
|
-
color,
|
|
81
|
-
replacement ? { ...options, data: { ...options.data, message: replacement } } : options,
|
|
82
|
-
)
|
|
83
|
-
}
|
|
84
|
-
}
|
|
85
|
-
|
|
86
|
-
export const onInit = () => {
|
|
87
|
-
correctToasts().catch(() => {})
|
|
88
|
-
customElements
|
|
89
|
-
.whenDefined('umb-workspace-package-builder')
|
|
90
|
-
.then(patch)
|
|
91
|
-
.catch(() => {})
|
|
92
|
-
}
|