@brillout/docpress 0.16.50 → 0.17.1

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.
@@ -1,7 +1,7 @@
1
1
  export { ChoiceGroup, ChoiceGroupContainer }
2
2
 
3
3
  import type { ChoiceGroup as TChoiceGroup, ChoiceGroupWithParent } from '../types.js'
4
- import React, { useId, useState } from 'react'
4
+ import React, { useId, useRef, useState } from 'react'
5
5
  import { usePageContext } from '../../renderer/usePageContext.js'
6
6
  import { useCurrentSelection } from '../hooks/useCurrentSelection.js'
7
7
  import { useRestoreScroll } from '../hooks/useRestoreScroll.js'
@@ -59,6 +59,8 @@ function CustomSelect({ choiceGroup }: { choiceGroup: ChoiceGroupWithParent }) {
59
59
  const selectedChoice = getAvailableChoice(selectedChoiceStored, choices, emptyChoices, defaultChoice)
60
60
  const [expanded, setExpanded] = useState(false)
61
61
  const [isHovered, setIsHovered] = useState(false)
62
+ const lastPointerType = useRef<React.PointerEvent['pointerType']>('mouse')
63
+
62
64
  let [parentSelectedChoice] = useCurrentSelection(parentChoiceGroup?.name || '', parentChoiceGroup?.default || '')
63
65
  let isHidden = hidden
64
66
  const setPrevPosition = useRestoreScroll([selectedChoice])
@@ -83,7 +85,10 @@ function CustomSelect({ choiceGroup }: { choiceGroup: ChoiceGroupWithParent }) {
83
85
  isHovered && 'hovered',
84
86
  ])}
85
87
  style={{ '--option-height': `${OPTION_HEIGHT}px`, '--choice-count': filteredChoices.length }}
86
- onMouseEnter={() => {
88
+ onPointerDownCapture={(e) => (lastPointerType.current = e.pointerType)}
89
+ onPointerEnter={(e) => {
90
+ lastPointerType.current = e.pointerType
91
+ if (lastPointerType.current !== 'mouse') return
87
92
  setExpanded(true)
88
93
  setIsHovered(true)
89
94
  }}
@@ -92,11 +97,10 @@ function CustomSelect({ choiceGroup }: { choiceGroup: ChoiceGroupWithParent }) {
92
97
  if (!expanded) setIsHovered(false)
93
98
  }}
94
99
  onClick={() => {
95
- if (!expanded) next()
100
+ if (lastPointerType.current === 'mouse' && !expanded) next()
96
101
  }}
97
102
  data-choice-group={groupName}
98
103
  >
99
- <div className="choice-select__border" />
100
104
  {filteredChoices.map(({ name: choice, icon, iconStyle, iconStyleDropdown }) => (
101
105
  <label
102
106
  id={`choice-${choice}`}
@@ -118,6 +122,7 @@ function CustomSelect({ choiceGroup }: { choiceGroup: ChoiceGroupWithParent }) {
118
122
  </span>
119
123
  <span className="choice-select__option-label">{choice}</span>
120
124
  </span>
125
+ <div className="choice-select__border" />
121
126
  </label>
122
127
  ))}
123
128
  </div>
@@ -129,6 +134,13 @@ function CustomSelect({ choiceGroup }: { choiceGroup: ChoiceGroupWithParent }) {
129
134
  }
130
135
  function handleOnClick(e: React.MouseEvent<HTMLLabelElement, MouseEvent>, choice: string) {
131
136
  e.preventDefault()
137
+
138
+ if (!expanded) {
139
+ setExpanded(true)
140
+ setIsHovered(true)
141
+ return
142
+ }
143
+
132
144
  const el = e.currentTarget
133
145
  setPrevPosition(el)
134
146
  const isSame = selectedChoice === choice
@@ -30,9 +30,11 @@ function Link({
30
30
  href.startsWith('/') || href.startsWith('#'),
31
31
  `<Link href /> prop \`href==='${href}'\` but should start with '/' or '#'`,
32
32
  )
33
- assertUsage(!text || !children, 'Cannot use both `text` or `children`')
34
- // assertWarning(!text, 'prop `text` is deprecated')
35
- text = text ?? children
33
+ assertUsage(
34
+ !text,
35
+ 'The `text` prop of `<Link>` is deprecated, use `<Link>...</Link>` instead of `<Link text="..." />`',
36
+ )
37
+ text = children
36
38
 
37
39
  const linkTextData = getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning })
38
40
  if (!text) {
@@ -7,9 +7,8 @@ import pc from '@brillout/picocolors';
7
7
  function Link({ href, text, noBreadcrumb, doNotInferSectionTitle, noWarning, children, ...props }) {
8
8
  const pageContext = usePageContext();
9
9
  assertUsage(href.startsWith('/') || href.startsWith('#'), `<Link href /> prop \`href==='${href}'\` but should start with '/' or '#'`);
10
- assertUsage(!text || !children, 'Cannot use both `text` or `children`');
11
- // assertWarning(!text, 'prop `text` is deprecated')
12
- text = text ?? children;
10
+ assertUsage(!text, 'The `text` prop of `<Link>` is deprecated, use `<Link>...</Link>` instead of `<Link text="..." />`');
11
+ text = children;
13
12
  const linkTextData = getLinkTextData({ href, pageContext, doNotInferSectionTitle, noWarning });
14
13
  if (!text) {
15
14
  if (linkTextData) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@brillout/docpress",
3
- "version": "0.16.50",
3
+ "version": "0.17.1",
4
4
  "type": "module",
5
5
  "dependencies": {
6
6
  "@brillout/picocolors": "^1.0.10",