Skip to content

Commit

Permalink
feat: support string.length
Browse files Browse the repository at this point in the history
  • Loading branch information
lisonge committed Sep 3, 2023
1 parent 1294bb5 commit ff06f52
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
26 changes: 19 additions & 7 deletions src/components/AttrCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,26 @@ import DraggableCard from './DraggableCard.vue';
const props = withDefaults(defineProps<{ focusNode: RawNode }>(), {});
const lenAttrNames = [`text`, `desc`];
const attrs = computed(() => {
return Object.entries(props.focusNode.attr).map(([name, value]) => {
value = JSON.stringify(value);
return {
name,
value,
};
});
return Object.entries(props.focusNode.attr)
.map(([name, value]) => {
const attr = {
name,
value: JSON.stringify(value),
};
if (lenAttrNames.includes(name)) {
return [
attr,
{
name: name + `.length`,
value: JSON.stringify((value as string)?.length || null),
},
];
}
return attr;
})
.flat();
});
</script>

Expand Down
8 changes: 7 additions & 1 deletion src/utils/selector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,13 @@ const { CommonSelector, CommonTransform } = SelectorKit;

const transform = new CommonTransform<RawNode>(
(node, name) => {
return Reflect.get(node.attr, name);
const [key, subKey] = name.split('.');
if (subKey) {
// @ts-ignore
return node.attr[key]?.[subKey];
}
// @ts-ignore
return node.attr[key];
},
(node) => node.attr.name,
(node) => node.children,
Expand Down

0 comments on commit ff06f52

Please sign in to comment.