1
1
import { UmbBlockGridEntryContext } from '../../context/block-grid-entry.context.js' ;
2
2
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
3
3
import { html , css , customElement , property , state , nothing } from '@umbraco-cms/backoffice/external/lit' ;
4
+ import type { PropertyValueMap } from '@umbraco-cms/backoffice/external/lit' ;
4
5
import type { UmbPropertyEditorUiElement } from '@umbraco-cms/backoffice/extension-registry' ;
5
6
import type { UmbBlockViewPropsType } from '@umbraco-cms/backoffice/block' ;
6
7
import type { UmbBlockGridLayoutModel } from '@umbraco-cms/backoffice/block-grid' ;
@@ -14,7 +15,7 @@ import '../block-scale-handler/index.js';
14
15
@customElement ( 'umb-block-grid-entry' )
15
16
export class UmbBlockGridEntryElement extends UmbLitElement implements UmbPropertyEditorUiElement {
16
17
//
17
- @property ( { type : Number } )
18
+ @property ( { type : Number , reflect : true } )
18
19
public get index ( ) : number | undefined {
19
20
return this . #context. getIndex ( ) ;
20
21
}
@@ -37,6 +38,7 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
37
38
//
38
39
39
40
#context = new UmbBlockGridEntryContext ( this ) ;
41
+ #renderTimeout: number | undefined ;
40
42
41
43
@state ( )
42
44
_columnSpan ?: number ;
@@ -51,7 +53,9 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
51
53
52
54
// If _createPath is undefined, its because no blocks are allowed to be created here[NL]
53
55
@state ( )
54
- _createPath ?: string ;
56
+ _createBeforePath ?: string ;
57
+ @state ( )
58
+ _createAfterPath ?: string ;
55
59
56
60
@state ( )
57
61
_label = '' ;
@@ -68,6 +72,13 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
68
72
@state ( )
69
73
_canScale ?: boolean ;
70
74
75
+ @state ( )
76
+ _showInlineCreateBefore ?: boolean ;
77
+ @state ( )
78
+ _showInlineCreateAfter ?: boolean ;
79
+ @state ( )
80
+ _inlineCreateAboveWidth ?: string ;
81
+
71
82
// TODO: use this type on the Element Interface for the Manifest.
72
83
@state ( )
73
84
_blockViewProps : UmbBlockViewPropsType < UmbBlockGridLayoutModel > = { contentUdi : undefined ! , urls : { } } ; // Set to undefined cause it will be set before we render.
@@ -110,10 +121,15 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
110
121
} ) ;
111
122
112
123
// Paths:
113
- this . observe ( this . #context. createPath , ( createPath ) => {
114
- const oldValue = this . _createPath ;
115
- this . _createPath = createPath ;
116
- this . requestUpdate ( '_createPath' , oldValue ) ;
124
+ this . observe ( this . #context. createBeforePath , ( createPath ) => {
125
+ //const oldValue = this._createBeforePath;
126
+ this . _createBeforePath = createPath ;
127
+ //this.requestUpdate('_createPath', oldValue);
128
+ } ) ;
129
+ this . observe ( this . #context. createAfterPath , ( createPath ) => {
130
+ //const oldValue = this._createAfterPath;
131
+ this . _createAfterPath = createPath ;
132
+ //this.requestUpdate('_createPath', oldValue);
117
133
} ) ;
118
134
this . observe ( this . #context. workspaceEditContentPath , ( path ) => {
119
135
this . _workspaceEditContentPath = path ;
@@ -156,8 +172,52 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
156
172
this . setAttribute ( 'data-content-element-type-alias' , contentElementTypeAlias ) ;
157
173
}
158
174
} ) ;
175
+
176
+ this . #callUpdateInlineCreateButtons( ) ;
159
177
}
160
178
179
+ protected updated ( _changedProperties : PropertyValueMap < any > | Map < PropertyKey , unknown > ) : void {
180
+ super . updated ( _changedProperties ) ;
181
+ if ( _changedProperties . has ( '_blockViewProps' ) || _changedProperties . has ( '_columnSpan' ) ) {
182
+ this . #callUpdateInlineCreateButtons( ) ;
183
+ }
184
+ }
185
+
186
+ #callUpdateInlineCreateButtons( ) {
187
+ clearTimeout ( this . #renderTimeout) ;
188
+ this . #renderTimeout = setTimeout ( this . #updateInlineCreateButtons, 100 ) as unknown as number ;
189
+ }
190
+
191
+ #updateInlineCreateButtons = ( ) => {
192
+ // TODO: Could we optimize this, so it wont break?, cause currently we trust blindly that parentElement is '.umb-block-grid__layout-container' [NL]
193
+ const layoutContainer = this . parentElement ;
194
+ if ( ! layoutContainer ) return ;
195
+ const layoutContainerRect = layoutContainer . getBoundingClientRect ( ) ;
196
+
197
+ if ( layoutContainerRect . width === 0 ) {
198
+ this . _showInlineCreateBefore = false ;
199
+ this . _showInlineCreateAfter = false ;
200
+ this . _inlineCreateAboveWidth = undefined ;
201
+ this . #renderTimeout = setTimeout ( this . #updateInlineCreateButtons, 100 ) as unknown as number ;
202
+ return ;
203
+ }
204
+
205
+ const layoutItemRect = this . getBoundingClientRect ( ) ;
206
+ if ( layoutItemRect . right > layoutContainerRect . right - 5 ) {
207
+ this . _showInlineCreateAfter = false ;
208
+ } else {
209
+ this . _showInlineCreateAfter = true ;
210
+ }
211
+
212
+ if ( layoutItemRect . left > layoutContainerRect . left + 5 ) {
213
+ this . _showInlineCreateBefore = false ;
214
+ this . _inlineCreateAboveWidth = undefined ;
215
+ } else {
216
+ this . _inlineCreateAboveWidth = getComputedStyle ( layoutContainer ) . width ;
217
+ this . _showInlineCreateBefore = true ;
218
+ }
219
+ } ;
220
+
161
221
#renderInlineEditBlock( ) {
162
222
return html `<umb- block- grid- block- inline
163
223
.contentUdi = ${ this . contentUdi }
@@ -171,8 +231,13 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
171
231
#renderBlock( ) {
172
232
return this . contentUdi
173
233
? html `
174
- ${ this . _createPath
175
- ? html `<uui- butto n- inline-create href= ${ this . _createPath } > </ uui- butto n- inline-create> `
234
+ ${ this . _createBeforePath && this . _showInlineCreateBefore
235
+ ? html `<uui- butto n- inline-create
236
+ href= ${ this . _createBeforePath }
237
+ label= ${ this . localize . term ( 'blockEditor_addBlock' ) }
238
+ style= ${ this . _inlineCreateAboveWidth
239
+ ? `width: ${ this . _inlineCreateAboveWidth } `
240
+ : '' } > </ uui- butto n- inline-create> `
176
241
: nothing }
177
242
<div class= "umb-block-grid__block" part = "umb- block- grid__block">
178
243
<umb- extension- slot
@@ -204,6 +269,12 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
204
269
</ umb- block- scale-handler> `
205
270
: nothing }
206
271
</ div>
272
+ ${ this . _createAfterPath && this . _showInlineCreateAfter
273
+ ? html `<uui- butto n- inline-create
274
+ vertical
275
+ label= ${ this . localize . term ( 'blockEditor_addBlock' ) }
276
+ href= ${ this . _createAfterPath } > </ uui- butto n- inline-create> `
277
+ : nothing }
207
278
`
208
279
: nothing ;
209
280
}
@@ -223,6 +294,24 @@ export class UmbBlockGridEntryElement extends UmbLitElement implements UmbProper
223
294
top : var (--uui-size-2 );
224
295
right : var (--uui-size-2 );
225
296
}
297
+ uui-button-inline-create {
298
+ top : 0px ;
299
+ position : absolute;
300
+
301
+ // Avoid showing inline-create in dragging-mode
302
+ --umb-block-grid__block--inline-create-button-display--condition : var (--umb-block-grid--dragging-mode ) none;
303
+ display : var (--umb-block-grid__block--inline-create-button-display--condition );
304
+ }
305
+ uui-button-inline-create : not ([vertical ]) {
306
+ left : 0 ;
307
+ width : var (--umb-block-grid-editor--inline-create-width , 100% );
308
+ }
309
+ : host (: not ([index = '0' ])) uui- butto n- inline-create: not ([vertical ]) {
310
+ top : calc (var (--umb-block-grid--row-gap , 0px ) * -0.5 );
311
+ }
312
+ uui-button-inline-create [vertical ] {
313
+ right : calc (1px - (var (--umb-block-grid--column-gap , 0px ) * 0.5 ));
314
+ }
226
315
227
316
: host ([drag-placeholder ]) {
228
317
opacity : 0.2 ;
0 commit comments