Skip to content

Commit f35b95f

Browse files
test: added new dev mode button in the design library for exporting purposes
1 parent 7b1e9e0 commit f35b95f

File tree

4 files changed

+73
-43
lines changed

4 files changed

+73
-43
lines changed

src/block/design-library/edit.js

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
srcUrl,
88
settings,
99
cdnUrl,
10+
devMode,
1011
} from 'stackable'
1112
import {
1213
Button,
@@ -163,9 +164,12 @@ const Edit = props => {
163164

164165
const customAttributes = block.attributes.customAttributes
165166

166-
const indexToDelete = customAttributes?.findIndex( attribute => attribute[ 0 ] === 'stk-design-library__bg-target' )
167-
if ( customAttributes && indexToDelete !== -1 ) {
168-
block.attributes.customAttributes.splice( indexToDelete, 1 )
167+
const isDesignLibraryDevMode = devMode && localStorage.getItem( 'stk__design_library__dev_mode' ) === '1'
168+
if ( ! isDesignLibraryDevMode ) {
169+
const indexToDelete = customAttributes?.findIndex( attribute => attribute[ 0 ] === 'stk-design-library__bg-target' )
170+
if ( customAttributes && indexToDelete !== -1 ) {
171+
block.attributes.customAttributes.splice( indexToDelete, 1 )
172+
}
169173
}
170174

171175
for ( const attributeName in block.attributes ) {
@@ -189,30 +193,33 @@ const Edit = props => {
189193
attributes = block[ 0 ].attributes
190194
innerBlocks = block[ 0 ].innerBlocks
191195

192-
if ( category !== 'Header' ) {
193-
if ( ! parentClientId && attributes.hasBackground ) {
194-
attributes.blockMargin = {
195-
top: '',
196-
right: '',
197-
bottom: '0',
198-
left: '',
199-
}
200-
} else if ( ! parentClientId ) {
201-
attributes.blockMargin = {
202-
top: spacingSize,
203-
right: '',
204-
bottom: spacingSize,
205-
left: '',
196+
const isDesignLibraryDevMode = devMode && localStorage.getItem( 'stk__design_library__dev_mode' ) === '1'
197+
if ( ! isDesignLibraryDevMode ) {
198+
if ( category !== 'Header' ) {
199+
if ( ! parentClientId && attributes.hasBackground ) {
200+
attributes.blockMargin = {
201+
top: '',
202+
right: '',
203+
bottom: '0',
204+
left: '',
205+
}
206+
} else if ( ! parentClientId ) {
207+
attributes.blockMargin = {
208+
top: spacingSize,
209+
right: '',
210+
bottom: spacingSize,
211+
left: '',
212+
}
206213
}
207-
}
208214

209-
const blockLayouts = select( 'stackable/global-spacing-and-borders' ).getBlockLayouts()
210-
if ( attributes.hasBackground && typeof blockLayouts === 'object' && ! blockLayouts[ 'block-background-padding' ] ) {
211-
attributes.blockPadding = {
212-
top: spacingSize,
213-
right: spacingSize,
214-
bottom: spacingSize,
215-
left: spacingSize,
215+
const blockLayouts = select( 'stackable/global-spacing-and-borders' ).getBlockLayouts()
216+
if ( attributes.hasBackground && typeof blockLayouts === 'object' && ! blockLayouts[ 'block-background-padding' ] ) {
217+
attributes.blockPadding = {
218+
top: spacingSize,
219+
right: spacingSize,
220+
bottom: spacingSize,
221+
left: spacingSize,
222+
}
216223
}
217224
}
218225
}

src/components/design-library-list/design-library-list-item.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import {
1515
*/
1616
import { createRoot } from '~stackable/util'
1717
import {
18-
isPro, i18n, wpGlobalStylesInlineCss,
18+
isPro, i18n, wpGlobalStylesInlineCss, devMode,
1919
} from 'stackable'
2020
import classnames from 'classnames'
2121
import { Tooltip } from '~stackable/components'
@@ -162,7 +162,9 @@ const DesignLibraryListItem = forwardRef( ( props, ref ) => {
162162
useEffect( () => {
163163
const defaultValues = DEFAULT_CONTENT[ category ]
164164
let _content = template
165-
if ( defaultValues ) {
165+
166+
const isDesignLibraryDevMode = devMode && localStorage.getItem( 'stk__design_library__dev_mode' ) === '1'
167+
if ( defaultValues && ! isDesignLibraryDevMode ) {
166168
Object.keys( defaultValues ).forEach( key => {
167169
_content = _content.replaceAll( key, defaultValues[ key ] )
168170
} )

src/components/modal-design-library/editor.scss

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,8 @@ div.ugb-modal-design-library__enable-background {
319319
margin-bottom: 0 !important;
320320
margin: 0 auto;
321321

322-
.components-base-control__field, .stk-control-label {
322+
.components-base-control__field,
323+
.stk-control-label {
323324
margin: 0;
324325
}
325326
.components-button-group {
@@ -357,16 +358,16 @@ div.ugb-modal-design-library__enable-background {
357358

358359

359360
.ugb-modal-design-library__stk-color-scheme {
360-
display: flex;
361-
align-items: center;
362-
gap: 8px;
363-
outline: 1px solid #e0e0e0;
364-
border-radius: 2px;
361+
display: flex;
362+
align-items: center;
363+
gap: 8px;
364+
outline: 1px solid #e0e0e0;
365+
border-radius: 2px;
365366
margin-bottom: 8px;
366367
padding: 0;
367368
height: auto;
368369
width: 100%;
369-
&:hover {
370+
&:hover {
370371
&.stk-color-scheme__toggle .stk-color-scheme__none,
371372
.stk-global-color-scheme__preview {
372373
color: initial;
@@ -377,7 +378,8 @@ div.ugb-modal-design-library__enable-background {
377378
}
378379

379380
&.stk-color-scheme__selected {
380-
&, &:active {
381+
&,
382+
&:active {
381383
outline: 2px solid var(--wp-admin-theme-color, #f00069);
382384
color: var(--wp-admin-theme-color, #f00069);
383385
}
@@ -408,8 +410,12 @@ div.ugb-modal-design-library__enable-background {
408410
display: flex;
409411
gap: 10px;
410412
align-items: center;
413+
.components-toggle-control {
414+
margin-bottom: 0;
415+
}
411416
}
412-
.stk-design-library__plan-dropdown, .ugb-design-library__color-scheme-popover {
417+
.stk-design-library__plan-dropdown,
418+
.ugb-design-library__color-scheme-popover {
413419
--wp-admin-theme-color: #f00069;
414420
--wp-admin-theme-color-darker-10: #{ darken(#f00069, 10%) };
415421
--wp-admin-theme-color-darker-20: #{ darken(#f00069, 20%) };
@@ -444,7 +450,7 @@ div.ugb-modal-design-library__enable-background {
444450
max-width: 800px;
445451
ul {
446452
list-style: circle;
447-
margin-inline-start: 20px;
453+
margin-inline-start: 20px;
448454
}
449455
}
450456

@@ -462,11 +468,11 @@ div.ugb-modal-design-library__enable-background {
462468
}
463469

464470
.ugb-modal-design-library__stk-color-scheme-list-header {
465-
display: flex;
466-
justify-content: space-between;
467-
padding: 0;
468-
margin: 0 0 4px;
469-
border-bottom: 1px solid #e0e0e0;
471+
display: flex;
472+
justify-content: space-between;
473+
padding: 0;
474+
margin: 0 0 4px;
475+
border-bottom: 1px solid #e0e0e0;
470476

471477
p {
472478
margin: 6px 6px 4px;

src/components/modal-design-library/modal.js

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ import { getDesigns, filterDesigns } from '~stackable/design-library'
1111
/**
1212
* External deprendencies
1313
*/
14-
import { i18n, isPro } from 'stackable'
14+
import {
15+
i18n, isPro, devMode,
16+
} from 'stackable'
1517
import classnames from 'classnames'
1618
import { useLocalStorage } from '~stackable/util'
1719

@@ -155,6 +157,19 @@ export const ModalDesignLibrary = props => {
155157
/> */ }
156158

157159
<div className="stk-design-library__header-settings">
160+
{ devMode && (
161+
<ToggleControl
162+
label="Dev Mode"
163+
checked={ !! localStorage.getItem( 'stk__design_library__dev_mode' ) || false }
164+
onChange={ value => {
165+
localStorage.setItem( 'stk__design_library__dev_mode', value ? '1' : '' )
166+
setTimeout( () => {
167+
document?.querySelector( '.ugb-insert-library-button__wrapper .ugb-insert-library-button' ).click()
168+
}, 100 )
169+
props.onClose()
170+
} }
171+
/>
172+
) }
158173
<Button
159174
icon="image-rotate"
160175
iconSize={ 14 }

0 commit comments

Comments
 (0)