@@ -120,7 +120,8 @@ var SnippetEditor = Widget.extend({
120
120
}
121
121
} else {
122
122
this . $ ( '.o_overlay_move_options' ) . addClass ( 'd-none' ) ;
123
- $customize . find ( '.oe_snippet_clone' ) . addClass ( 'd-none' ) ;
123
+ const cloneButtonEl = $customize [ 0 ] . querySelector ( ".oe_snippet_clone" ) ;
124
+ cloneButtonEl . classList . toggle ( "d-none" , ! this . forceDuplicateButton ) ;
124
125
}
125
126
126
127
if ( ! this . isTargetRemovable ) {
@@ -196,10 +197,14 @@ var SnippetEditor = Widget.extend({
196
197
/**
197
198
* Notifies all the associated snippet options that the snippet has just
198
199
* been dropped in the page.
200
+ *
201
+ * @param {HTMLElement } targetEl the snippet dropped in the page
199
202
*/
200
- buildSnippet : async function ( ) {
203
+ async buildSnippet ( targetEl ) {
201
204
for ( var i in this . styles ) {
202
- await this . styles [ i ] . onBuilt ( ) ;
205
+ await this . styles [ i ] . onBuilt ( {
206
+ isCurrent : targetEl === this . $target [ 0 ] ,
207
+ } ) ;
203
208
}
204
209
await this . toggleTargetVisibility ( true ) ;
205
210
} ,
@@ -339,6 +344,9 @@ var SnippetEditor = Widget.extend({
339
344
if ( this . $target . is ( '#wrapwrap > main' ) ) {
340
345
return _t ( "Page Options" ) ;
341
346
}
347
+ if ( this . $target [ 0 ] . matches ( ".btn" ) ) {
348
+ return _t ( "Button" ) ;
349
+ }
342
350
return _t ( "Block" ) ;
343
351
} ,
344
352
/**
@@ -774,6 +782,10 @@ var SnippetEditor = Widget.extend({
774
782
this . displayOverlayOptions = true ;
775
783
}
776
784
785
+ if ( option . forceDuplicateButton ) {
786
+ this . forceDuplicateButton = true ;
787
+ }
788
+
777
789
return option . appendTo ( document . createDocumentFragment ( ) ) ;
778
790
} ) ;
779
791
@@ -1063,6 +1075,7 @@ var SnippetEditor = Widget.extend({
1063
1075
}
1064
1076
1065
1077
const openModalEl = this . $target [ 0 ] . closest ( '.modal' ) ;
1078
+ const toInsertInline = window . getComputedStyle ( this . $target [ 0 ] ) . display . includes ( 'inline' ) ;
1066
1079
1067
1080
this . dropped = false ;
1068
1081
this . _dropSiblings = {
@@ -1148,6 +1161,7 @@ var SnippetEditor = Widget.extend({
1148
1161
$selectorSiblings : $selectorSiblings ,
1149
1162
$selectorChildren : $selectorChildren ,
1150
1163
canBeSanitizedUnless : canBeSanitizedUnless ,
1164
+ toInsertInline : toInsertInline ,
1151
1165
selectorGrids : selectorGrids ,
1152
1166
} ) ;
1153
1167
@@ -2217,7 +2231,7 @@ var SnippetsMenu = Widget.extend({
2217
2231
// First call the onBuilt of all options of each item in the snippet
2218
2232
// (and so build their editor instance first).
2219
2233
await this . _callForEachChildSnippet ( $target , function ( editor , $snippet ) {
2220
- return editor . buildSnippet ( ) ;
2234
+ return editor . buildSnippet ( $target [ 0 ] ) ;
2221
2235
} ) ;
2222
2236
// The snippet is now fully built, notify the editor for changed
2223
2237
// content.
@@ -2270,11 +2284,13 @@ var SnippetsMenu = Widget.extend({
2270
2284
* true: always allows,
2271
2285
* false: always forbid,
2272
2286
* string: specific type of forbidden sanitization
2287
+ * @param {Boolean } [toInsertInline=false]
2288
+ * elements which are inline as the "s_badge" snippet for example
2273
2289
* @param {Object } [selectorGrids = []]
2274
2290
* elements which are in grid mode and for which a grid dropzone
2275
2291
* needs to be inserted
2276
2292
*/
2277
- _activateInsertionZones ( $selectorSiblings , $selectorChildren , canBeSanitizedUnless , selectorGrids = [ ] ) {
2293
+ _activateInsertionZones ( $selectorSiblings , $selectorChildren , canBeSanitizedUnless , toInsertInline , selectorGrids = [ ] ) {
2278
2294
var self = this ;
2279
2295
2280
2296
// If a modal or a dropdown is open, the drop zones must be created
@@ -2290,20 +2306,27 @@ var SnippetsMenu = Widget.extend({
2290
2306
}
2291
2307
2292
2308
// Check if the drop zone should be horizontal or vertical
2293
- function setDropZoneDirection ( $elem , $parent , $sibling ) {
2294
- var vertical = false ;
2295
- var style = { } ;
2309
+ function setDropZoneDirection ( $elem , $parent , toInsertInline , $sibling ) {
2310
+ let vertical = false ;
2311
+ let style = { } ;
2296
2312
$sibling = $sibling || $elem ;
2297
- var css = window . getComputedStyle ( $elem [ 0 ] ) ;
2298
- var parentCss = window . getComputedStyle ( $parent [ 0 ] ) ;
2299
- var float = css . float || css . cssFloat ;
2300
- var display = parentCss . display ;
2301
- var flex = parentCss . flexDirection ;
2302
- if ( float === 'left' || float === 'right' || ( display === 'flex' && flex === 'row' ) ) {
2303
- style [ 'float' ] = float ;
2304
- if ( $sibling . parent ( ) . width ( ) !== $sibling . outerWidth ( true ) ) {
2313
+ const css = window . getComputedStyle ( $elem [ 0 ] ) ;
2314
+ const parentCss = window . getComputedStyle ( $parent [ 0 ] ) ;
2315
+ const float = css . float || css . cssFloat ;
2316
+ const display = parentCss . display ;
2317
+ const flex = parentCss . flexDirection ;
2318
+ if ( toInsertInline || float === 'left' || float === 'right' || ( display === 'flex' && flex === 'row' ) ) {
2319
+ if ( ! toInsertInline ) {
2320
+ style [ 'float' ] = float ;
2321
+ }
2322
+ if ( ( parseInt ( $sibling . parent ( ) . width ( ) ) !== parseInt ( $sibling . outerWidth ( true ) ) ) ) {
2305
2323
vertical = true ;
2306
2324
style [ 'height' ] = Math . max ( $sibling . outerHeight ( ) , 30 ) + 'px' ;
2325
+ if ( toInsertInline ) {
2326
+ style [ "display" ] = "inline-block" ;
2327
+ style [ "verticalAlign" ] = "middle" ;
2328
+ style [ "float" ] = "none" ;
2329
+ }
2307
2330
}
2308
2331
}
2309
2332
return {
@@ -2337,7 +2360,7 @@ var SnippetsMenu = Widget.extend({
2337
2360
}
2338
2361
var data ;
2339
2362
if ( $neighbor . length ) {
2340
- data = setDropZoneDirection ( $neighbor , $neighbor . parent ( ) ) ;
2363
+ data = setDropZoneDirection ( $neighbor , $neighbor . parent ( ) , toInsertInline ) ;
2341
2364
} else {
2342
2365
data = {
2343
2366
vertical : false ,
@@ -2355,13 +2378,13 @@ var SnippetsMenu = Widget.extend({
2355
2378
2356
2379
if ( ! $zone . children ( ) . last ( ) . is ( '.oe_drop_zone' ) ) {
2357
2380
data = testPreviousSibling ( $zone [ 0 ] . lastChild , $zone )
2358
- || setDropZoneDirection ( $zone , $zone , $children . last ( ) ) ;
2381
+ || setDropZoneDirection ( $zone , $zone , toInsertInline , $children . last ( ) ) ;
2359
2382
self . _insertDropzone ( $ ( '<we-hook/>' ) . appendTo ( $zone ) , data . vertical , data . style , canBeSanitizedUnless ) ;
2360
2383
}
2361
2384
2362
2385
if ( ! $zone . children ( ) . first ( ) . is ( '.oe_drop_clone' ) ) {
2363
2386
data = testPreviousSibling ( $zone [ 0 ] . firstChild , $zone )
2364
- || setDropZoneDirection ( $zone , $zone , $children . first ( ) ) ;
2387
+ || setDropZoneDirection ( $zone , $zone , toInsertInline , $children . first ( ) ) ;
2365
2388
self . _insertDropzone ( $ ( '<we-hook/>' ) . prependTo ( $zone ) , data . vertical , data . style , canBeSanitizedUnless ) ;
2366
2389
}
2367
2390
} ) ;
@@ -2381,7 +2404,7 @@ var SnippetsMenu = Widget.extend({
2381
2404
$zoneToCheck = $zoneToCheck . prev ( ) ;
2382
2405
}
2383
2406
if ( ! $zoneToCheck . prev ( '.oe_drop_zone:visible, .oe_drop_clone' ) . length ) {
2384
- data = setDropZoneDirection ( $zone , $zone . parent ( ) ) ;
2407
+ data = setDropZoneDirection ( $zone , $zone . parent ( ) , toInsertInline ) ;
2385
2408
self . _insertDropzone ( $ ( '<we-hook/>' ) . insertBefore ( $zone ) , data . vertical , data . style , canBeSanitizedUnless ) ;
2386
2409
}
2387
2410
@@ -2390,7 +2413,7 @@ var SnippetsMenu = Widget.extend({
2390
2413
$zoneToCheck = $zoneToCheck . next ( ) ;
2391
2414
}
2392
2415
if ( ! $zoneToCheck . next ( '.oe_drop_zone:visible, .oe_drop_clone' ) . length ) {
2393
- data = setDropZoneDirection ( $zone , $zone . parent ( ) ) ;
2416
+ data = setDropZoneDirection ( $zone , $zone . parent ( ) , toInsertInline ) ;
2394
2417
self . _insertDropzone ( $ ( '<we-hook/>' ) . insertAfter ( $zone ) , data . vertical , data . style , canBeSanitizedUnless ) ;
2395
2418
}
2396
2419
} ) ;
@@ -3319,7 +3342,11 @@ var SnippetsMenu = Widget.extend({
3319
3342
3320
3343
const forbidSanitize = $snippet . data ( 'oeForbidSanitize' ) ;
3321
3344
const canBeSanitizedUnless = forbidSanitize === 'form' ? 'form' : ! forbidSanitize ;
3322
- self . _activateInsertionZones ( $selectorSiblings , $selectorChildren , canBeSanitizedUnless ) ;
3345
+ // Specific case for inline snippet (e.g. "s_badge")
3346
+ $baseBody [ 0 ] . classList . remove ( "oe_snippet_body" ) ;
3347
+ const toInsertInline = window . getComputedStyle ( $baseBody [ 0 ] ) . display . includes ( 'inline' ) ;
3348
+ $baseBody [ 0 ] . classList . add ( "oe_snippet_body" ) ;
3349
+ self . _activateInsertionZones ( $selectorSiblings , $selectorChildren , canBeSanitizedUnless , toInsertInline ) ;
3323
3350
$dropZones = self . getEditableArea ( ) . find ( '.oe_drop_zone' ) ;
3324
3351
if ( forbidSanitize === 'form' ) {
3325
3352
$dropZones = $dropZones . filter ( ( i , el ) => ! el . closest ( '[data-oe-sanitize]:not([data-oe-sanitize="allow_form"]) .oe_drop_zone' ) ) ;
@@ -3414,6 +3441,15 @@ var SnippetsMenu = Widget.extend({
3414
3441
3415
3442
var $target = $toInsert ;
3416
3443
3444
+ if ( $target [ 0 ] . classList . contains ( "o_snippet_drop_in_only" ) ) {
3445
+ // If it's a "drop in only" snippet, after dropping
3446
+ // it, we modify it so that it's no longer a
3447
+ // draggable snippet but rather simple HTML code, as
3448
+ // if the element had been created with the editor.
3449
+ $target [ 0 ] . classList . remove ( "o_snippet_drop_in_only" ) ;
3450
+ delete $target [ 0 ] . dataset . snippet ;
3451
+ delete $target [ 0 ] . dataset . name ;
3452
+ }
3417
3453
3418
3454
self . options . wysiwyg . odooEditor . observerUnactive ( 'dragAndDropCreateSnippet' ) ;
3419
3455
await self . _scrollToSnippet ( $target , self . $scrollable ) ;
@@ -3683,7 +3719,7 @@ var SnippetsMenu = Widget.extend({
3683
3719
* @param {OdooEvent } ev
3684
3720
*/
3685
3721
_onActivateInsertionZones : function ( ev ) {
3686
- this . _activateInsertionZones ( ev . data . $selectorSiblings , ev . data . $selectorChildren , ev . data . canBeSanitizedUnless , ev . data . selectorGrids ) ;
3722
+ this . _activateInsertionZones ( ev . data . $selectorSiblings , ev . data . $selectorChildren , ev . data . canBeSanitizedUnless , ev . data . toInsertInline , ev . data . selectorGrids ) ;
3687
3723
} ,
3688
3724
/**
3689
3725
* Called when a child editor asks to deactivate the current snippet
0 commit comments