Skip to content

Commit

Permalink
fix(kit/applet): parse state field types, closes #295
Browse files Browse the repository at this point in the history
  • Loading branch information
webfansplz committed Mar 26, 2024
1 parent ad832b7 commit d4f7bbe
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 3 deletions.
6 changes: 4 additions & 2 deletions packages/applet/src/components/state/StateFieldViewer.vue
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,10 @@ const normalizedDisplayedValue = computed(() => {
}
else {
const _value = type.value === 'custom' && !(props.data.value as InspectorCustomState)._custom?.type ? `"${displayedValue.value}"` : (displayedValue.value === '' ? `""` : displayedValue.value)
const result = `<span class="${type.value}-state-type">${_value}</span>`
const _type = (props.data.value as InspectorCustomState)._custom?.type
const _value = type.value === 'custom' && !_type ? `"${displayedValue.value}"` : (displayedValue.value === '' ? `""` : displayedValue.value)
const normalizedType = type.value === 'custom' && _type === 'ref' ? getInspectorStateValueType(_value) : type.value
const result = `<span class="${normalizedType}-state-type">${_value}</span>`
if (extraDisplayedValue)
return `${result} <span class="text-gray-500">(${extraDisplayedValue})</span>`
Expand Down
2 changes: 2 additions & 0 deletions packages/applet/uno.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,12 @@ export default defineConfig(mergeConfigs([unoConfig, {
'string-state-type': 'text-#e74c3c dark:(text-#c41a16)',
'literal-state-type': 'text-#03c dark:(text-#997fff)',
'boolean-state-type': 'text-#27ae60 dark:(text-#abebc6)',
'null-state-type': 'text-#999',
}, [/^theme-card-(\w+)$/, $ => `p2 flex gap2 border border-base bg-base items-center rounded min-w-40 min-h-25 justify-center transition-all saturate-0 op50 shadow hover:(op100 bg-${$[1]}/10 text-${$[1]}6 saturate-100)`]],
safelist: [
'string-state-type',
'literal-state-type',
'boolean-state-type',
'null-state-type',
],
}])) as any
2 changes: 1 addition & 1 deletion packages/devtools-kit/src/core/component/state/format.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { reviver } from './reviver'

export function getInspectorStateValueType(value, raw = true) {
const type = typeof value
if (value == null || value === UNDEFINED) {
if (value == null || value === UNDEFINED || value === 'undefined') {
return 'null'
}
else if (
Expand Down

0 comments on commit d4f7bbe

Please sign in to comment.