@@ -1347,12 +1347,22 @@ Vvveb.Builder = {
1347
1347
1348
1348
try {
1349
1349
let pos = offset ( target ) ;
1350
+ let top = ( pos . top - ( self . frameDoc . scrollTop ?? 0 ) - self . selectPadding ) ;
1350
1351
1351
- SelectBox . style . top = ( pos . top - ( self . frameDoc . scrollTop ?? 0 ) - self . selectPadding ) + "px" ;
1352
+ SelectBox . style . top = top + "px" ;
1352
1353
SelectBox . style . left = ( pos . left - ( self . frameDoc . scrollLeft ?? 0 ) - self . selectPadding ) + "px" ;
1353
1354
SelectBox . style . width = ( ( target . offsetWidth ?? target . clientWidth ) + self . selectPadding * 2 ) + "px" ;
1354
1355
SelectBox . style . height = ( ( target . offsetHeight ?? target . clientHeight ) + self . selectPadding * 2 ) + "px" ;
1355
1356
SelectBox . style . display = "block" ;
1357
+
1358
+ //move actions toolbar to bottom if there is no space on top
1359
+ if ( top < 30 ) {
1360
+ SelectActions . style . top = "unset" ;
1361
+ SelectActions . style . bottom = "-25px" ;
1362
+ } else {
1363
+ SelectActions . style . top = "" ;
1364
+ SelectActions . style . bottom = "" ;
1365
+ }
1356
1366
1357
1367
Vvveb . Breadcrumb . loadBreadcrumb ( target ) ;
1358
1368
@@ -1468,7 +1478,7 @@ Vvveb.Builder = {
1468
1478
br : true ,
1469
1479
wbr : true
1470
1480
} ;
1471
-
1481
+
1472
1482
let parent = self . highlightEl ;
1473
1483
1474
1484
if ( self . dragType == "section" ) {
@@ -1477,11 +1487,18 @@ Vvveb.Builder = {
1477
1487
}
1478
1488
1479
1489
let parentTagName = parent . tagName . toLowerCase ( ) ;
1480
-
1490
+ let isVattribute = false ;
1491
+ //check if node is a data-v-attribute dynamic node that will overrite the content if added inside
1492
+ for ( let attr of parent . attributes ) {
1493
+ if ( attr . name . indexOf ( "data-v-" ) == 0 ) {
1494
+ isVattribute = true ;
1495
+ false ;
1496
+ }
1497
+ }
1481
1498
1482
1499
try {
1483
1500
if ( ( pos . top < ( y - halfHeight ) ) || ( pos . left < ( x - halfWidth ) ) ) {
1484
- if ( noChildren [ parentTagName ] ) {
1501
+ if ( noChildren [ parentTagName ] || isVattribute ) {
1485
1502
parent . after ( self . dragElement ) ;
1486
1503
} else {
1487
1504
if ( parent == self . dragElement . parenNode ) {
@@ -1493,7 +1510,7 @@ Vvveb.Builder = {
1493
1510
1494
1511
prepend = true ;
1495
1512
} else {
1496
- if ( noChildren [ parentTagName ] ) {
1513
+ if ( noChildren [ parentTagName ] || isVattribute ) {
1497
1514
parent . parentNode . insertBefore ( self . dragElement , parent ) ;
1498
1515
} else {
1499
1516
parent . prepend ( self . dragElement ) ;
@@ -1827,15 +1844,59 @@ Vvveb.Builder = {
1827
1844
1828
1845
document . getElementById ( "translate-code-btn" ) ?. addEventListener ( "click" , function ( event ) {
1829
1846
let selectedEl = Vvveb . Builder . selectedEl ;
1830
- let value = selectedEl . innerHTML . trim ( ) ;
1847
+ let text = selectedEl . innerHTML . trim ( ) ;
1831
1848
// uncomment to use outerHTML, not recommended
1832
- //let value = selectedEl.outerHTML;
1849
+ //let text = selectedEl.outerHTML;
1850
+
1851
+ fetch ( namespaceUrl + "/translate&action=get" , { method : "POST" , body : new URLSearchParams ( { text} ) } )
1852
+ . then ( ( response ) => {
1853
+ if ( ! response . ok ) { throw new Error ( response ) }
1854
+ return response . json ( )
1855
+ } )
1856
+ . then ( ( data ) => {
1857
+ for ( code in data ) {
1858
+ let translation = data [ code ] ;
1859
+ document . querySelector ( "#lang-" + code + "-editor textarea" ) . value = translation ;
1860
+ }
1861
+ } )
1862
+ . catch ( error => {
1863
+ console . log ( error . statusText ) ;
1864
+ displayToast ( "bg-danger" , "Error" , "Error loading translations!" ) ;
1865
+ } ) ;
1866
+
1867
+
1833
1868
Vvveb . ModalTranslateEditor . show ( ) ;
1834
- Vvveb . ModalTranslateEditor . setValue ( value ) ;
1869
+ Vvveb . ModalTranslateEditor . setValue ( text ) ;
1835
1870
1836
1871
let onSave = function ( event ) {
1872
+ let data = Object . fromEntries ( new FormData ( document . getElementById ( "translateForm" ) ) ) ;
1873
+
1874
+ fetch ( namespaceUrl + "/translate&action=save" , { method : "POST" , body : new URLSearchParams ( data ) } )
1875
+ . then ( ( response ) => {
1876
+ if ( ! response . ok ) { throw new Error ( response ) }
1877
+ return response . json ( )
1878
+ } )
1879
+ . then ( ( data ) => {
1880
+ let bg = "bg-success" ;
1881
+
1882
+ if ( data . success || text == "success" ) {
1883
+ } else {
1884
+ bg = "bg-danger" ;
1885
+ }
1886
+
1887
+ displayToast ( bg , "Save" , data . message ?? data ) ;
1888
+ } )
1889
+ . catch ( error => {
1890
+ console . log ( error . statusText ) ;
1891
+ displayToast ( "bg-danger" , "Error" , "Error saving translations!" ) ;
1892
+ } ) ;
1893
+ /*
1894
+ Vvveb.Builder.frameBody.querySelectorAll("form").forEach(f => {
1895
+ console.log( JSON.stringify(Object.fromEntries(new FormData(f))) );
1896
+ });
1897
+ */
1837
1898
selectedEl . innerHTML = event . detail ;
1838
- //selectedEl.outerHTML = value ;
1899
+ //selectedEl.outerHTML = text ;
1839
1900
} ;
1840
1901
1841
1902
window . removeEventListener ( "vvveb.ModalTranslateEditor.save" , onSave ) ;
@@ -1851,12 +1912,14 @@ Vvveb.Builder = {
1851
1912
node = self . selectedEl ;
1852
1913
1853
1914
Vvveb . Undo . addMutation ( { type : 'childList' ,
1854
- target : node . parentNode ,
1855
- removedNodes : [ node ] ,
1856
- nextSibling : node . nextSibling } ) ;
1915
+ target : node . parentNode ,
1916
+ removedNodes : [ node ] ,
1917
+ nextSibling : node . nextSibling } ) ;
1857
1918
1858
1919
self . selectedEl . remove ( ) ;
1859
-
1920
+ Vvveb . TreeList . loadComponents ( ) ;
1921
+ Vvveb . SectionList . loadSections ( ) ;
1922
+
1860
1923
event . preventDefault ( ) ;
1861
1924
return false ;
1862
1925
} ) ;
@@ -2243,6 +2306,7 @@ Vvveb.Builder = {
2243
2306
Vvveb . ModalCodeEditor = {
2244
2307
modal : false ,
2245
2308
modalId : 'codeEditorModal' ,
2309
+ name : 'ModalCodeEditor' ,
2246
2310
editor : false ,
2247
2311
2248
2312
init : function ( modal = false , editor = false ) {
@@ -2260,7 +2324,7 @@ Vvveb.ModalCodeEditor = {
2260
2324
let self = this ;
2261
2325
2262
2326
this . modal . querySelector ( '.save-btn' ) . addEventListener ( "click" , function ( event ) {
2263
- window . dispatchEvent ( new CustomEvent ( "vvveb.ModalCodeEditor .save" , { detail : self . getValue ( ) } ) ) ;
2327
+ window . dispatchEvent ( new CustomEvent ( "vvveb." + self . name + " .save", { detail : self . getValue ( ) } ) ) ;
2264
2328
self . hide ( ) ;
2265
2329
return false ;
2266
2330
} ) ;
@@ -2295,6 +2359,7 @@ Vvveb.ModalCodeEditor = {
2295
2359
//Vvveb.ModalTranslateEditor = structuredClone(Vvveb.ModalCodeEditor);
2296
2360
Vvveb . ModalTranslateEditor = Object . assign ( { } , Vvveb . ModalCodeEditor ) ;
2297
2361
Vvveb . ModalTranslateEditor . modalId = 'translateEditorModal' ;
2362
+ Vvveb . ModalTranslateEditor . name = 'ModalTranslateEditor' ;
2298
2363
2299
2364
Vvveb . CodeEditor = {
2300
2365
@@ -2427,7 +2492,7 @@ Vvveb.Gui = {
2427
2492
folder = ( folder = / ( .+ ) \/ / . exec ( filename ) ) ? folder [ 1 ] : '/' ;
2428
2493
2429
2494
page = Vvveb . FileManager . getCurrentUrl ( ) ;
2430
- page = ( page = / [ ^ \/ ] + $ / . exec ( page ) ) ? page [ 0 ] : '' ;
2495
+ page = ( page = / [ ^ \/ ] + \? $ / . exec ( page ) ) ? page [ 0 ] : '' ;
2431
2496
page = page . replace ( ".html" , "" ) ;
2432
2497
page = page ? page : "new-template" ;
2433
2498
page += ".html" ;
@@ -2702,7 +2767,7 @@ Vvveb.Gui = {
2702
2767
setState : function ( ) {
2703
2768
Vvveb . StyleManager . setState ( this . value ) ;
2704
2769
Vvveb . Builder . reloadComponent ( ) ;
2705
- }
2770
+ }
2706
2771
}
2707
2772
2708
2773
Vvveb . StyleManager = {
@@ -2930,7 +2995,7 @@ Vvveb.StyleManager = {
2930
2995
2931
2996
el = element ;
2932
2997
if ( el != this . currentElement ) {
2933
- selector = this . getSelectorForElement ( el ) ;
2998
+ selector = this . getSelectorForElement ( el ) ;
2934
2999
this . currentElement = el ;
2935
3000
this . currentSelector = selector
2936
3001
} else {
@@ -3152,6 +3217,7 @@ Vvveb.SectionList = {
3152
3217
let node = section . _node ;
3153
3218
node . remove ( ) ;
3154
3219
section . remove ( ) ;
3220
+ Vvveb . TreeList . loadComponents ( ) ;
3155
3221
3156
3222
e . stopPropagation ( ) ;
3157
3223
e . preventDefault ( ) ;
@@ -3316,8 +3382,9 @@ Vvveb.SectionList = {
3316
3382
3317
3383
loadSections : function ( ) {
3318
3384
let sections = this . getSections ( ) ;
3385
+ let container = document . querySelector ( this . selector ) ;
3319
3386
3320
- document . querySelector ( this . selector ) . replaceChildren ( ) ;
3387
+ container . replaceChildren ( ) ;
3321
3388
for ( i in sections ) {
3322
3389
this . addSection ( sections [ i ] ) ;
3323
3390
}
@@ -3600,7 +3667,7 @@ Vvveb.FileManager = {
3600
3667
3601
3668
deletePage : function ( element , e ) {
3602
3669
let page = element . dataset ;
3603
- let post_id = element . dataset . post_id ;
3670
+ let post_id = element . dataset . post_id ?? 0 ;
3604
3671
let name ;
3605
3672
let _self = this ;
3606
3673
@@ -3651,14 +3718,15 @@ Vvveb.FileManager = {
3651
3718
} ,
3652
3719
3653
3720
renamePage : function ( element , e , duplicate = false ) {
3654
- let page = element . dataset ;
3655
- let post_id = element . dataset . post_id ?? 0 ;
3721
+ let page = element . dataset ;
3722
+ let post_id = element . dataset . post_id ?? 0 ;
3723
+ let product_id = element . dataset . product_id ?? 0 ;
3656
3724
let newfile ;
3657
3725
let name ;
3658
3726
let _self = this ;
3659
3727
3660
3728
name = element . querySelector ( 'label span' ) ?. textContent . replace ( '.html' , '' ) ;
3661
- if ( post_id ) {
3729
+ if ( post_id || product_id ) {
3662
3730
name = prompt ( `Enter new name for "${ name } "` , name ) ;
3663
3731
if ( name ) {
3664
3732
newfile = page . file ;
@@ -3675,7 +3743,7 @@ Vvveb.FileManager = {
3675
3743
3676
3744
if ( page ) {
3677
3745
3678
- fetch ( renameFileUrl , { method : "POST" , body : new URLSearchParams ( { file :page . file , newfile :newfile , name, duplicate, post_id} ) } )
3746
+ fetch ( renameFileUrl , { method : "POST" , body : new URLSearchParams ( { file :page . file , newfile :newfile , name, duplicate, post_id, product_id } ) } )
3679
3747
. then ( ( response ) => {
3680
3748
if ( ! response . ok ) { return Promise . reject ( response ) ; }
3681
3749
return response . json ( )
@@ -3691,17 +3759,20 @@ Vvveb.FileManager = {
3691
3759
newfile = data . newfile ?? newfile ;
3692
3760
displayToast ( bg , "Rename" , data . message ?? data ) ;
3693
3761
let baseName = newfile . replace ( '.html' , '' ) ;
3694
- let newName = name || friendlyName ( newfile . replace ( / .* [ \/ \\ ] + / , '' ) ) . replace ( '.html' , '' ) ;
3762
+ let newName = data . name ?? name ?? friendlyName ( newfile . replace ( / .* [ \/ \\ ] + / , '' ) ) . replace ( '.html' , '' ) ;
3695
3763
3696
3764
if ( duplicate ) {
3697
3765
let addPage = _self . pages [ page . page ] ;
3698
- addPage [ "name" ] = baseName ;
3699
- addPage [ "file" ] = newfile ;
3700
- addPage [ "title" ] = newName ;
3701
- addPage [ "url" ] = data . url ;
3766
+ addPage [ "name" ] = data . name ?? baseName ;
3767
+ addPage [ "file" ] = newfile ;
3768
+ addPage [ "title" ] = newName ;
3769
+ addPage [ "url" ] = data . url ;
3770
+ addPage [ "post_id" ] = data . post_id ;
3771
+ addPage [ "product_id" ] = data . product_id ;
3772
+
3702
3773
if ( data . newfile ) {
3703
3774
//addPage["url"] = Vvveb.themeBaseUrl + addPage["url"]
3704
- addPage [ "url" ] = page . url . substring ( 0 , page . url . lastIndexOf ( "/" ) + 1 ) + addPage [ "url" ] ;
3775
+ // addPage["url"] = page.url.substring(0, page.url.lastIndexOf("/") + 1) + addPage["url"];
3705
3776
}
3706
3777
3707
3778
let newPage = Vvveb . FileManager . addPage ( baseName , addPage , page . page ) ;
@@ -4050,7 +4121,7 @@ Vvveb.FontsManager = {
4050
4121
4051
4122
activeFonts :[ ] ,
4052
4123
providers : { } , //{"google":GoogleFontsManager};
4053
-
4124
+
4054
4125
addFontList : function ( provider , groupName , fontList ) {
4055
4126
let fonts = { } ;
4056
4127
let fontNames = [ ] ;
0 commit comments