@brillout/docpress 0.16.36 → 0.16.38
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/code-blocks/components/ChoiceGroup.css +1 -2
- package/code-blocks/components/ChoiceGroup.tsx +12 -24
- package/code-blocks/components/Pre.css +0 -1
- package/code-blocks/components/Pre.tsx +1 -1
- package/code-blocks/components/Tabs.tsx +9 -6
- package/code-blocks/remarkChoiceGroup.ts +4 -1
- package/code-blocks/utils/generateChoiceGroupCode.ts +2 -2
- package/dist/code-blocks/components/Tabs.d.ts +2 -1
- package/dist/code-blocks/components/Tabs.js +9 -7
- package/dist/code-blocks/remarkChoiceGroup.js +4 -2
- package/dist/code-blocks/utils/generateChoiceGroupCode.js +2 -2
- package/package.json +1 -1
|
@@ -17,7 +17,6 @@
|
|
|
17
17
|
.choice-select {
|
|
18
18
|
background: #eee;
|
|
19
19
|
font-size: 13.3333px;
|
|
20
|
-
z-index: 3;
|
|
21
20
|
|
|
22
21
|
-webkit-user-select: none; /* Safari */
|
|
23
22
|
-moz-user-select: none; /* Firefox */
|
|
@@ -58,7 +57,7 @@
|
|
|
58
57
|
.choice-select[aria-expanded='true'] {
|
|
59
58
|
overflow: visible;
|
|
60
59
|
border-width: 0;
|
|
61
|
-
z-index:
|
|
60
|
+
z-index: 1;
|
|
62
61
|
|
|
63
62
|
.choice-select__list {
|
|
64
63
|
border-style: solid;
|
|
@@ -9,8 +9,8 @@ import './ChoiceGroup.css'
|
|
|
9
9
|
type TChoiceGroup = {
|
|
10
10
|
name: string
|
|
11
11
|
choices: string[]
|
|
12
|
+
emptyChoices: string[]
|
|
12
13
|
default: string
|
|
13
|
-
disabled: string[]
|
|
14
14
|
hidden: boolean
|
|
15
15
|
lvl: number
|
|
16
16
|
}
|
|
@@ -124,31 +124,20 @@ function ChoiceGroup({ children, choiceGroup, parentChoiceGroup }: ChoiceGroupPr
|
|
|
124
124
|
}
|
|
125
125
|
|
|
126
126
|
function CustomSelect({ choiceGroup }: { choiceGroup: ChoiceGroupWithParent }) {
|
|
127
|
-
const {
|
|
128
|
-
name: groupName,
|
|
129
|
-
choices,
|
|
130
|
-
default: defaultChoice,
|
|
131
|
-
disabled: disabledChoices,
|
|
132
|
-
hidden,
|
|
133
|
-
parentChoiceGroup,
|
|
134
|
-
} = choiceGroup
|
|
127
|
+
const { name: groupName, choices, emptyChoices, default: defaultChoice, hidden, parentChoiceGroup } = choiceGroup
|
|
135
128
|
const [selectedChoice, setSelectedChoice] = useCurrentSelection(groupName, defaultChoice)
|
|
136
129
|
const setPrevPosition = useRestoreScroll([selectedChoice])
|
|
137
130
|
const [expanded, setExpanded] = useState(false)
|
|
138
|
-
|
|
131
|
+
|
|
132
|
+
const isEmptyChoice = (choice: string) => emptyChoices.includes(choice)
|
|
133
|
+
const filteredChoices = choices.filter((choice) => !isEmptyChoice(choice))
|
|
134
|
+
const selectedIndex = filteredChoices.indexOf(selectedChoice)
|
|
139
135
|
const height = 25
|
|
140
136
|
const rectTop = -selectedIndex * height
|
|
141
137
|
|
|
142
|
-
const isDisabled = (choice: string) => disabledChoices.includes(choice)
|
|
143
138
|
function next() {
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
nextIndex = (nextIndex + 1) % choices.length
|
|
147
|
-
if (!isDisabled(choices[nextIndex]!)) {
|
|
148
|
-
setSelectedChoice(choices[nextIndex]!)
|
|
149
|
-
return
|
|
150
|
-
}
|
|
151
|
-
}
|
|
139
|
+
const nextIndex = (selectedIndex + 1) % filteredChoices.length
|
|
140
|
+
setSelectedChoice(filteredChoices[nextIndex]!)
|
|
152
141
|
}
|
|
153
142
|
function isHidden() {
|
|
154
143
|
if (parentChoiceGroup) {
|
|
@@ -163,7 +152,7 @@ function CustomSelect({ choiceGroup }: { choiceGroup: ChoiceGroupWithParent }) {
|
|
|
163
152
|
id={`choicesFor-${groupName}`}
|
|
164
153
|
aria-haspopup="listbox"
|
|
165
154
|
aria-expanded={expanded}
|
|
166
|
-
className={cls(['choice-select', (isHidden() ||
|
|
155
|
+
className={cls(['choice-select', (isHidden() || isEmptyChoice(selectedChoice)) && 'hidden'])}
|
|
167
156
|
style={{ height }}
|
|
168
157
|
onMouseEnter={() => setExpanded(true)}
|
|
169
158
|
onMouseLeave={() => setExpanded(false)}
|
|
@@ -175,14 +164,13 @@ function CustomSelect({ choiceGroup }: { choiceGroup: ChoiceGroupWithParent }) {
|
|
|
175
164
|
aria-activedescendant={`choice-${selectedChoice}`}
|
|
176
165
|
role="listbox"
|
|
177
166
|
className="choice-select__list"
|
|
178
|
-
style={{ top: rectTop, height:
|
|
167
|
+
style={{ top: rectTop, height: filteredChoices.length * height }}
|
|
179
168
|
>
|
|
180
|
-
{
|
|
169
|
+
{filteredChoices.map((choice, i) => (
|
|
181
170
|
<div
|
|
182
171
|
id={choice}
|
|
183
172
|
key={i}
|
|
184
173
|
aria-selected={i === selectedIndex}
|
|
185
|
-
aria-disabled={isDisabled(choice)}
|
|
186
174
|
role="option"
|
|
187
175
|
className="choice-select__option"
|
|
188
176
|
style={{ height }}
|
|
@@ -200,7 +188,7 @@ function CustomSelect({ choiceGroup }: { choiceGroup: ChoiceGroupWithParent }) {
|
|
|
200
188
|
setPrevPosition(el)
|
|
201
189
|
if (el.getAttribute('aria-selected') === 'true') {
|
|
202
190
|
next()
|
|
203
|
-
} else
|
|
191
|
+
} else {
|
|
204
192
|
setSelectedChoice(el.id)
|
|
205
193
|
}
|
|
206
194
|
}
|
|
@@ -30,8 +30,8 @@ function Pre({ children, ...props }: React.ComponentPropsWithoutRef<'pre'> & Add
|
|
|
30
30
|
className={cls([className, props['file-added'] && classAdded, props['file-removed'] && classRemoved])}
|
|
31
31
|
{...rest}
|
|
32
32
|
>
|
|
33
|
-
{!props['hide-menu'] && <CopyButton />}
|
|
34
33
|
{children}
|
|
34
|
+
{!props['hide-menu'] && <CopyButton />}
|
|
35
35
|
</pre>
|
|
36
36
|
)
|
|
37
37
|
}
|
|
@@ -7,7 +7,7 @@ import { usePageContext } from '../../renderer/usePageContext.js'
|
|
|
7
7
|
import { assertUsage } from '../../utils/assert.js'
|
|
8
8
|
import './Tabs.css'
|
|
9
9
|
|
|
10
|
-
function Tabs({ choice }: { choice: string }) {
|
|
10
|
+
function Tabs({ choice, hiddenChoices = [] }: { choice: string; hiddenChoices: string[] }) {
|
|
11
11
|
const groupName = choice
|
|
12
12
|
const pageContext = usePageContext()
|
|
13
13
|
const choicesAll = pageContext.config.docpress.choices
|
|
@@ -16,7 +16,9 @@ function Tabs({ choice }: { choice: string }) {
|
|
|
16
16
|
const { choices, default: defaultChoice } = choicesAll[groupName]
|
|
17
17
|
const [selectedChoice, setSelectedChoice] = useCurrentSelection(groupName, defaultChoice)
|
|
18
18
|
const setPrevPosition = useRestoreScroll([selectedChoice])
|
|
19
|
-
const
|
|
19
|
+
const isHidden = (choice: string) => hiddenChoices.includes(choice)
|
|
20
|
+
const filteredChoices = choices.filter((choice) => !isHidden(choice))
|
|
21
|
+
const selectedIndex = filteredChoices.indexOf(selectedChoice)
|
|
20
22
|
|
|
21
23
|
return (
|
|
22
24
|
<div className="choice-tabs" data-choice-group={groupName}>
|
|
@@ -33,6 +35,7 @@ function Tabs({ choice }: { choice: string }) {
|
|
|
33
35
|
<li
|
|
34
36
|
key={i}
|
|
35
37
|
id={choice}
|
|
38
|
+
style={{ display: isHidden(choice) ? 'none' : undefined }}
|
|
36
39
|
className="choice-tabs__tab"
|
|
37
40
|
role="tab"
|
|
38
41
|
aria-selected={i === selectedIndex}
|
|
@@ -59,16 +62,16 @@ function Tabs({ choice }: { choice: string }) {
|
|
|
59
62
|
|
|
60
63
|
switch (e.key) {
|
|
61
64
|
case 'ArrowRight':
|
|
62
|
-
nextIndex = (selectedIndex + 1) %
|
|
65
|
+
nextIndex = (selectedIndex + 1) % filteredChoices.length
|
|
63
66
|
break
|
|
64
67
|
case 'ArrowLeft':
|
|
65
|
-
nextIndex = (selectedIndex - 1 +
|
|
68
|
+
nextIndex = (selectedIndex - 1 + filteredChoices.length) % filteredChoices.length
|
|
66
69
|
break
|
|
67
70
|
case 'Home':
|
|
68
71
|
nextIndex = 0
|
|
69
72
|
break
|
|
70
73
|
case 'End':
|
|
71
|
-
nextIndex =
|
|
74
|
+
nextIndex = filteredChoices.length - 1
|
|
72
75
|
break
|
|
73
76
|
default:
|
|
74
77
|
return
|
|
@@ -76,7 +79,7 @@ function Tabs({ choice }: { choice: string }) {
|
|
|
76
79
|
|
|
77
80
|
e.preventDefault()
|
|
78
81
|
setPrevPosition(el)
|
|
79
|
-
const nextChoice =
|
|
82
|
+
const nextChoice = filteredChoices[nextIndex]!
|
|
80
83
|
setSelectedChoice(nextChoice)
|
|
81
84
|
const tabEl = el.parentElement?.parentElement as HTMLDivElement
|
|
82
85
|
|
|
@@ -16,7 +16,10 @@ function remarkChoiceGroup() {
|
|
|
16
16
|
const { choice } = meta.props
|
|
17
17
|
node.meta = meta.rest
|
|
18
18
|
|
|
19
|
-
if (choice)
|
|
19
|
+
if (choice) {
|
|
20
|
+
const filter = ['jsx', 'tsx', 'vue'].includes(node.lang ?? '') ? 'code-component' : `code-${node.lang}`
|
|
21
|
+
node.data ??= { customDataChoice: choice, customDataFilter: filter }
|
|
22
|
+
}
|
|
20
23
|
}
|
|
21
24
|
if (node.type === 'containerDirective' && node.name === 'Choice') {
|
|
22
25
|
if (!node.attributes) return
|
|
@@ -108,12 +108,12 @@ function resolveChoiceGroupNodes(choiceNodes: ChoiceNode[]) {
|
|
|
108
108
|
})
|
|
109
109
|
assertUsage(groupName, `Missing group name for [${choices}]. Define it in +docpress.choices.`)
|
|
110
110
|
|
|
111
|
-
const
|
|
111
|
+
const emptyChoices = choicesAll[groupName]!.choices.filter((choice) => !choices.includes(choice))
|
|
112
112
|
|
|
113
113
|
const choiceGroup = {
|
|
114
114
|
name: groupName,
|
|
115
115
|
...choicesAll[groupName]!,
|
|
116
|
-
|
|
116
|
+
emptyChoices,
|
|
117
117
|
}
|
|
118
118
|
|
|
119
119
|
const mergedChoiceNodes: ChoiceNode[] = choiceGroup.choices.map((choice) => {
|
|
@@ -5,7 +5,7 @@ import { useRestoreScroll } from '../hooks/useRestoreScroll.js';
|
|
|
5
5
|
import { usePageContext } from '../../renderer/usePageContext.js';
|
|
6
6
|
import { assertUsage } from '../../utils/assert.js';
|
|
7
7
|
import './Tabs.css';
|
|
8
|
-
function Tabs({ choice }) {
|
|
8
|
+
function Tabs({ choice, hiddenChoices = [] }) {
|
|
9
9
|
const groupName = choice;
|
|
10
10
|
const pageContext = usePageContext();
|
|
11
11
|
const choicesAll = pageContext.config.docpress.choices;
|
|
@@ -13,10 +13,12 @@ function Tabs({ choice }) {
|
|
|
13
13
|
const { choices, default: defaultChoice } = choicesAll[groupName];
|
|
14
14
|
const [selectedChoice, setSelectedChoice] = useCurrentSelection(groupName, defaultChoice);
|
|
15
15
|
const setPrevPosition = useRestoreScroll([selectedChoice]);
|
|
16
|
-
const
|
|
16
|
+
const isHidden = (choice) => hiddenChoices.includes(choice);
|
|
17
|
+
const filteredChoices = choices.filter((choice) => !isHidden(choice));
|
|
18
|
+
const selectedIndex = filteredChoices.indexOf(selectedChoice);
|
|
17
19
|
return (React.createElement("div", { className: "choice-tabs", "data-choice-group": groupName },
|
|
18
20
|
React.createElement("select", { name: `choicesFor-${groupName}`, value: selectedChoice, hidden: true, disabled: true }, choices.map((choice, i) => (React.createElement("option", { key: i, value: choice }, choice)))),
|
|
19
|
-
React.createElement("ul", { id: `choicesFor-${groupName}`, className: "choice-tabs__tab-list", role: "tablist" }, choices.map((choice, i) => (React.createElement("li", { key: i, id: choice, className: "choice-tabs__tab", role: "tab", "aria-selected": i === selectedIndex, tabIndex: i === selectedIndex ? 0 : -1, onClick: (e) => handleOnClick(e, i), onKeyDown: handleOnKeyDown }, choice))))));
|
|
21
|
+
React.createElement("ul", { id: `choicesFor-${groupName}`, className: "choice-tabs__tab-list", role: "tablist" }, choices.map((choice, i) => (React.createElement("li", { key: i, id: choice, style: { display: isHidden(choice) ? 'none' : undefined }, className: "choice-tabs__tab", role: "tab", "aria-selected": i === selectedIndex, tabIndex: i === selectedIndex ? 0 : -1, onClick: (e) => handleOnClick(e, i), onKeyDown: handleOnKeyDown }, choice))))));
|
|
20
22
|
function handleOnClick(e, index) {
|
|
21
23
|
const el = e.currentTarget;
|
|
22
24
|
setPrevPosition(el);
|
|
@@ -27,23 +29,23 @@ function Tabs({ choice }) {
|
|
|
27
29
|
let nextIndex = selectedIndex;
|
|
28
30
|
switch (e.key) {
|
|
29
31
|
case 'ArrowRight':
|
|
30
|
-
nextIndex = (selectedIndex + 1) %
|
|
32
|
+
nextIndex = (selectedIndex + 1) % filteredChoices.length;
|
|
31
33
|
break;
|
|
32
34
|
case 'ArrowLeft':
|
|
33
|
-
nextIndex = (selectedIndex - 1 +
|
|
35
|
+
nextIndex = (selectedIndex - 1 + filteredChoices.length) % filteredChoices.length;
|
|
34
36
|
break;
|
|
35
37
|
case 'Home':
|
|
36
38
|
nextIndex = 0;
|
|
37
39
|
break;
|
|
38
40
|
case 'End':
|
|
39
|
-
nextIndex =
|
|
41
|
+
nextIndex = filteredChoices.length - 1;
|
|
40
42
|
break;
|
|
41
43
|
default:
|
|
42
44
|
return;
|
|
43
45
|
}
|
|
44
46
|
e.preventDefault();
|
|
45
47
|
setPrevPosition(el);
|
|
46
|
-
const nextChoice =
|
|
48
|
+
const nextChoice = filteredChoices[nextIndex];
|
|
47
49
|
setSelectedChoice(nextChoice);
|
|
48
50
|
const tabEl = el.parentElement?.parentElement;
|
|
49
51
|
if (!isInViewport(tabEl))
|
|
@@ -11,8 +11,10 @@ function remarkChoiceGroup() {
|
|
|
11
11
|
const meta = parseMetaString(node.meta, ['choice']);
|
|
12
12
|
const { choice } = meta.props;
|
|
13
13
|
node.meta = meta.rest;
|
|
14
|
-
if (choice)
|
|
15
|
-
|
|
14
|
+
if (choice) {
|
|
15
|
+
const filter = ['jsx', 'tsx', 'vue'].includes(node.lang ?? '') ? 'code-component' : `code-${node.lang}`;
|
|
16
|
+
node.data ?? (node.data = { customDataChoice: choice, customDataFilter: filter });
|
|
17
|
+
}
|
|
16
18
|
}
|
|
17
19
|
if (node.type === 'containerDirective' && node.name === 'Choice') {
|
|
18
20
|
if (!node.attributes)
|
|
@@ -82,11 +82,11 @@ function resolveChoiceGroupNodes(choiceNodes) {
|
|
|
82
82
|
return true;
|
|
83
83
|
});
|
|
84
84
|
assertUsage(groupName, `Missing group name for [${choices}]. Define it in +docpress.choices.`);
|
|
85
|
-
const
|
|
85
|
+
const emptyChoices = choicesAll[groupName].choices.filter((choice) => !choices.includes(choice));
|
|
86
86
|
const choiceGroup = {
|
|
87
87
|
name: groupName,
|
|
88
88
|
...choicesAll[groupName],
|
|
89
|
-
|
|
89
|
+
emptyChoices,
|
|
90
90
|
};
|
|
91
91
|
const mergedChoiceNodes = choiceGroup.choices.map((choice) => {
|
|
92
92
|
const node = choiceNodes.find((node) => node.choiceValue === choice);
|