@@ -14,25 +14,36 @@ const { meta, filter } = defineProps({
1414 required: true ,
1515 }
1616})
17- const displayRuleCount = computed (() => {
18- const maxRule = meta .features .length > 0 ? 2 : 5
19- return Math .min (meta .rules .length , maxRule )
20- })
21- const displayedRules = computed (() => {
22- // display selected rules first
17+
18+ // display selected options first
19+ function sortedOptions(options : string [], selected : string []) {
2320 const result = []
2421 const notSelected = []
25- for (const rule of meta . rules ) {
26- if (filter . selectedRuleFilters . includes (rule )) {
27- result .push (rule )
22+ for (const option of options ) {
23+ if (selected . includes (option )) {
24+ result .push (option )
2825 } else {
29- notSelected .push (rule )
26+ notSelected .push (option )
3027 }
3128 }
32- return result .concat (notSelected ).slice (0 , displayRuleCount .value )
29+ return result .concat (notSelected )
30+ }
31+
32+ const displayRuleCount = computed (() => {
33+ const maxRule = meta .features .length > 0 ? 2 : 5
34+ return Math .min (meta .rules .length , maxRule )
35+ })
36+ const displayedRules = computed (() => {
37+ const result = sortedOptions (meta .rules , filter .selectedRuleFilters )
38+ return result .slice (0 , displayRuleCount .value )
3339})
3440const moreRules = computed (() => meta .rules .length - displayRuleCount .value )
35- const moreFeatures = computed (() => Math .max (meta .features .length - 2 , 0 ))
41+
42+ const displayFeatures = computed (() => {
43+ const result = sortedOptions (meta .features , filter .selectedFeatures )
44+ return result .slice (0 , 2 )
45+ })
46+ const moreFeatures = computed (() => Math .max (displayFeatures .value .length - 2 , 0 ))
3647 </script >
3748
3849<template >
@@ -52,7 +63,9 @@ const moreFeatures = computed(() => Math.max(meta.features.length - 2, 0))
5263 </div >
5364 <div class =" rule-details" >
5465 <div class =" rule-badges" >
55- <Badge v-if =" meta.type === 'Pattern'" type =" info" text =" Simple Pattern Example" />
66+ <template v-if =" meta .type === ' Pattern' " >
67+ <Badge type =" info" text =" Simple Pattern Example" />
68+ </template >
5669 <template v-else >
5770 <span title =" Used Rules" >📏</span >
5871 <span class =" emoji-offset" />
@@ -69,10 +82,10 @@ const moreFeatures = computed(() => Math.max(meta.features.length - 2, 0))
6982 />
7083 </template >
7184 </div >
72- <div class =" rule-badges" v-if =" meta.features .length > 0" >
85+ <div class =" rule-badges" v-if =" displayFeatures .length > 0" >
7386 <span title =" Used Features" >💡</span >
7487 <Option
75- v-for =" feature in meta.features "
88+ v-for =" feature in displayFeatures "
7689 :key =" feature"
7790 :text =" feature"
7891 :highlight =" filter.selectedFeatures.includes(feature)"
0 commit comments