better display and also temporary fallback for lowerLevelBackground

This commit is contained in:
Henry Jameson 2024-09-25 00:46:58 +03:00
parent e1d3ebc943
commit e7eb1059c3
9 changed files with 50 additions and 10 deletions

View file

@ -22,6 +22,10 @@ export default {
// Overall the compuation difficulty is N*((1/6)M^3+M) where M is number of distinct states and N is number of variants. // Overall the compuation difficulty is N*((1/6)M^3+M) where M is number of distinct states and N is number of variants.
// This (currently) is further multipled by number of places where component can exist. // This (currently) is further multipled by number of places where component can exist.
}, },
editor: {
aspect: '6:1',
border: 0
},
// This lists all other components that can possibly exist within one. Recursion is currently not supported (and probably won't be supported ever). // This lists all other components that can possibly exist within one. Recursion is currently not supported (and probably won't be supported ever).
validInnerComponents: [ validInnerComponents: [
'Text', 'Text',

View file

@ -1,6 +1,7 @@
export default { export default {
name: 'ButtonUnstyled', name: 'ButtonUnstyled',
selector: '.button-unstyled', selector: '.button-unstyled',
notEditable: true,
states: { states: {
toggled: '.toggled', toggled: '.toggled',
disabled: ':disabled', disabled: ':disabled',

View file

@ -2,6 +2,7 @@ export default {
name: 'Modals', name: 'Modals',
selector: '.modal-view', selector: '.modal-view',
lazy: true, lazy: true,
notEditable: true,
validInnerComponents: [ validInnerComponents: [
'Panel' 'Panel'
], ],

View file

@ -1,6 +1,7 @@
export default { export default {
name: 'Scrollbar', name: 'Scrollbar',
selector: '::-webkit-scrollbar', selector: '::-webkit-scrollbar',
notEditable: true, // for now
defaultRules: [ defaultRules: [
{ {
directives: { directives: {

View file

@ -31,6 +31,7 @@ const hoverGlow = {
export default { export default {
name: 'ScrollbarElement', name: 'ScrollbarElement',
selector: '::-webkit-scrollbar-button', selector: '::-webkit-scrollbar-button',
notEditable: true, // for now
states: { states: {
pressed: ':active', pressed: ':active',
hover: ':hover:not(:disabled)', hover: ':hover:not(:disabled)',

View file

@ -67,7 +67,7 @@ export default {
componentKeysRaw componentKeysRaw
.map( .map(
key => [key, componentsContext(key).default] key => [key, componentsContext(key).default]
).filter(([key, component]) => !component.virtual) ).filter(([key, component]) => !component.virtual && !component.notEditable)
) )
const componentKeys = [...componentsMap.keys()] const componentKeys = [...componentsMap.keys()]
@ -108,20 +108,37 @@ export default {
const previewRules = reactive([]) const previewRules = reactive([])
const previewClass = computed(() => { const previewClass = computed(() => {
const selectors = [] const selectors = []
selectors.push(selectedComponentValue.value.variants[selectedVariant.value]) if (!!selectedComponentValue.value.variants?.normal || selectedVariant.value !== 'normal') {
selectors.push(selectedComponentValue.value.variants[selectedVariant.value])
}
if (selectedStates.size > 0) { if (selectedStates.size > 0) {
selectedStates.forEach(state => { selectedStates.forEach(state => {
const original = selectedComponentValue.value.states[state] const original = selectedComponentValue.value.states[state]
selectors.push(simulatePseudoSelectors(original)) selectors.push(simulatePseudoSelectors(original))
}) })
} }
console.log(selectors)
return selectors.map(x => x.substring(1)).join('') return selectors.map(x => x.substring(1)).join('')
}) })
const editorHintStyle = computed(() => {
const editorHint = selectedComponentValue.value.editor
const styles = []
if (editorHint && Object.keys(editorHint).length > 0) {
console.log('EH', editorHint)
if (editorHint.aspect != null) {
styles.push(`aspect-ratio: ${editorHint.aspect} !important;`)
}
if (editorHint.border != null) {
styles.push(`border-width: ${editorHint.border}px !important;`)
}
}
console.log('EH', styles)
return styles.join('; ')
})
const previewCss = computed(() => { const previewCss = computed(() => {
console.log(previewRules) const scoped = getCssRules(previewRules)
const scoped = getCssRules(previewRules).map(simulatePseudoSelectors) .map(simulatePseudoSelectors)
return scoped.join('\n') return scoped.join('\n')
}) })
@ -170,6 +187,7 @@ export default {
getFriendlyNamePath, getFriendlyNamePath,
getStatePath, getStatePath,
getVariantPath, getVariantPath,
editorHintStyle,
previewCss, previewCss,
previewClass, previewClass,
fallbackI18n (translated, fallback) { fallbackI18n (translated, fallback) {

View file

@ -132,6 +132,7 @@
<ComponentPreview <ComponentPreview
class="component-preview" class="component-preview"
:previewClass="previewClass" :previewClass="previewClass"
:previewStyle="editorHintStyle"
@update:shadow="({ axis, value }) => updateProperty(axis, value)" @update:shadow="({ axis, value }) => updateProperty(axis, value)"
/> />
</div> </div>

View file

@ -769,8 +769,16 @@
"only_state": "Component only has default state", "only_state": "Component only has default state",
"components": { "components": {
"normal": { "normal": {
"normal": "Normal state", "state": "Normal",
"variant": "Default variant" "variant": "Default"
},
"Alert": {
"friendlyName": "Alert",
"variants": {
"error": "Error",
"warning": "Warning",
"success": "Success"
}
}, },
"Button": { "Button": {
"friendlyName": "Button", "friendlyName": "Button",

View file

@ -231,6 +231,7 @@ export const init = ({
.map(({ data }) => data) .map(({ data }) => data)
const virtualComponents = new Set(Object.values(components).filter(c => c.virtual).map(c => c.name)) const virtualComponents = new Set(Object.values(components).filter(c => c.virtual).map(c => c.name))
const nonEditableComponents = new Set(Object.values(components).filter(c => c.notEditable).map(c => c.name))
const processCombination = (combination) => { const processCombination = (combination) => {
const selector = ruleToSelector(combination, true) const selector = ruleToSelector(combination, true)
@ -240,7 +241,11 @@ export const init = ({
const soloSelector = selector.split(/ /g).slice(-1)[0] const soloSelector = selector.split(/ /g).slice(-1)[0]
const lowerLevelSelector = parentSelector const lowerLevelSelector = parentSelector
const lowerLevelBackground = computed[lowerLevelSelector]?.background let lowerLevelBackground = computed[lowerLevelSelector]?.background
if (editMode && !lowerLevelBackground) {
// FIXME hack for editor until it supports handling component backgrounds
lowerLevelBackground = '#00FFFF'
}
const lowerLevelVirtualDirectives = computed[lowerLevelSelector]?.virtualDirectives const lowerLevelVirtualDirectives = computed[lowerLevelSelector]?.virtualDirectives
const lowerLevelVirtualDirectivesRaw = computed[lowerLevelSelector]?.virtualDirectivesRaw const lowerLevelVirtualDirectivesRaw = computed[lowerLevelSelector]?.virtualDirectivesRaw
@ -448,8 +453,8 @@ export const init = ({
let validInnerComponents let validInnerComponents
if (editMode) { if (editMode) {
const temp = (component.validInnerComponentsLite || component.validInnerComponents || []) const temp = (component.validInnerComponentsLite || component.validInnerComponents || [])
validInnerComponents = temp.filter(c => virtualComponents.has(c)) validInnerComponents = temp.filter(c => virtualComponents.has(c) && !nonEditableComponents.has(c))
} else if (editMode) { } else if (liteMode) {
validInnerComponents = (component.validInnerComponentsLite || component.validInnerComponents || []) validInnerComponents = (component.validInnerComponentsLite || component.validInnerComponents || [])
} else { } else {
validInnerComponents = component.validInnerComponents || [] validInnerComponents = component.validInnerComponents || []