@hozo/semantics 0.1.0
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/LICENSE +21 -0
- package/README.md +96 -0
- package/dist/disclosure.native.d.ts +47 -0
- package/dist/disclosure.native.d.ts.map +1 -0
- package/dist/disclosure.native.js +51 -0
- package/dist/disclosure.native.js.map +1 -0
- package/dist/generated/disclosure.d.ts +2 -0
- package/dist/generated/disclosure.d.ts.map +1 -0
- package/dist/generated/disclosure.js +2 -0
- package/dist/generated/disclosure.js.map +1 -0
- package/dist/generated/disclosure.native.d.ts +2 -0
- package/dist/generated/disclosure.native.d.ts.map +1 -0
- package/dist/generated/disclosure.native.js +2 -0
- package/dist/generated/disclosure.native.js.map +1 -0
- package/dist/index.d.ts +60 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +85 -0
- package/dist/index.js.map +1 -0
- package/dist/index.native.d.ts +157 -0
- package/dist/index.native.d.ts.map +1 -0
- package/dist/index.native.js +154 -0
- package/dist/index.native.js.map +1 -0
- package/package.json +81 -0
- package/src/disclosure.native.tsx +127 -0
- package/src/generated/disclosure.native.ts +6 -0
- package/src/generated/disclosure.ts +1 -0
- package/src/index.native.tsx +314 -0
- package/src/index.tsx +250 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { hozoTextChildren } from '@hozo/behaviors';
|
|
3
|
+
import { hozoPreflight } from '@hozo/engine/project';
|
|
4
|
+
import React, {} from 'react';
|
|
5
|
+
// The components rather than their names. These files used to render
|
|
6
|
+
// `React.createElement('View')`, and React Native resolves a string tag
|
|
7
|
+
// through its view config registry, where the registered names are
|
|
8
|
+
// `RCTView` and `RCTText` -- never `View` or `Text`. Every one of these
|
|
9
|
+
// would have thrown "View config getter callback for component `View`
|
|
10
|
+
// must be a function" on the first render. Nothing caught it because
|
|
11
|
+
// nothing imported these files: the tests next to them render the Web
|
|
12
|
+
// half through `react-dom/server`.
|
|
13
|
+
import { Text, View, } from 'react-native';
|
|
14
|
+
import { HozoDetails, HozoSummary } from './disclosure.native.js';
|
|
15
|
+
export function Main({ role = 'main', children, ...props }) {
|
|
16
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
17
|
+
}
|
|
18
|
+
export function Header({ role = 'banner', children, ...props }) {
|
|
19
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
20
|
+
}
|
|
21
|
+
export function Footer({ role = 'contentinfo', children, ...props }) {
|
|
22
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
23
|
+
}
|
|
24
|
+
export function Aside({ role = 'complementary', children, ...props }) {
|
|
25
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* The one landmark React Native has no word for.
|
|
29
|
+
*
|
|
30
|
+
* Its `Role` union carries every other role in this file -- banner,
|
|
31
|
+
* complementary, contentinfo, navigation, main, figure, group, list,
|
|
32
|
+
* separator -- and for search it has `searchbox`, which is the field
|
|
33
|
+
* rather than the region around it. `accessibilityRole: 'search'` means
|
|
34
|
+
* the field too.
|
|
35
|
+
*
|
|
36
|
+
* So this is a plain box here, and says so, rather than claiming a
|
|
37
|
+
* landmark by naming a widget. The Web half is a real `<search>`.
|
|
38
|
+
*/
|
|
39
|
+
export function Search({ children, ...props }) {
|
|
40
|
+
return React.createElement(View, props, hozoTextChildren(children));
|
|
41
|
+
}
|
|
42
|
+
export function Section({ children, ...props }) {
|
|
43
|
+
return React.createElement(View, props, hozoTextChildren(children));
|
|
44
|
+
}
|
|
45
|
+
export function Article({ role = 'article', children, ...props }) {
|
|
46
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
47
|
+
}
|
|
48
|
+
export function Nav({ role = 'navigation', children, ...props }) {
|
|
49
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
50
|
+
}
|
|
51
|
+
export function List({ ordered: _ordered, role = 'list', children, ...props }) {
|
|
52
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
53
|
+
}
|
|
54
|
+
export function ListItem({ role = 'listitem', children, ...props }) {
|
|
55
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
56
|
+
}
|
|
57
|
+
export function Figure({ role = 'figure', children, ...props }) {
|
|
58
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
59
|
+
}
|
|
60
|
+
export function Figcaption(props) {
|
|
61
|
+
return React.createElement(Text, props);
|
|
62
|
+
}
|
|
63
|
+
export function Time(props) {
|
|
64
|
+
return React.createElement(Text, props);
|
|
65
|
+
}
|
|
66
|
+
export function Address({ children, ...props }) {
|
|
67
|
+
return React.createElement(View, props, hozoTextChildren(children));
|
|
68
|
+
}
|
|
69
|
+
export function Fieldset({ role = 'group', children, ...props }) {
|
|
70
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
71
|
+
}
|
|
72
|
+
export function Legend({ style, ...props }) {
|
|
73
|
+
return React.createElement(Text, { style: [{ fontWeight: 'bold' }, style], ...props });
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* The disclosure the Native backend emits, under the names this package
|
|
77
|
+
* publishes.
|
|
78
|
+
*
|
|
79
|
+
* One implementation rather than two. The package-owned pair below is
|
|
80
|
+
* what a compiled `<Details>` becomes; the old copy beside it had the same
|
|
81
|
+
* bug the compiled path had, which
|
|
82
|
+
* is how a second implementation goes wrong: it rendered every child
|
|
83
|
+
* whether it was open or not, so the body never actually hid.
|
|
84
|
+
*/
|
|
85
|
+
/**
|
|
86
|
+
* The one place a Native style has to be handed over as if it were a Web
|
|
87
|
+
* one, and it is a resolver's limit rather than a claim about the value.
|
|
88
|
+
*
|
|
89
|
+
* A package resolves the component's Web types while checking both platform
|
|
90
|
+
* entries
|
|
91
|
+
* whichever platform it is building for, because `exports` carries a
|
|
92
|
+
* single `types` and this package compiles both halves in one `tsc` run.
|
|
93
|
+
* so the cast below is the boundary between CSS and Native style shapes.
|
|
94
|
+
*
|
|
95
|
+
* The alternative was a second disclosure in this file, which is what
|
|
96
|
+
* used to be here: it rendered every child whether it was open or not, so
|
|
97
|
+
* the body never hid. A cast at a known boundary beats a copy that drifts.
|
|
98
|
+
*/
|
|
99
|
+
const asWeb = (style) => style;
|
|
100
|
+
export function Details({ open, defaultOpen, onToggle, children, style, ...props }) {
|
|
101
|
+
return (_jsx(HozoDetails, { open: open, defaultOpen: defaultOpen, onToggle: onToggle, style: asWeb(style), ...props, children: children }));
|
|
102
|
+
}
|
|
103
|
+
export function Summary({ children, style, ...props }) {
|
|
104
|
+
return (_jsx(HozoSummary, { style: asWeb(style), ...props, children: children }));
|
|
105
|
+
}
|
|
106
|
+
export function Term({ style, ...props }) {
|
|
107
|
+
return React.createElement(Text, { style: [{ fontWeight: 'bold' }, style], ...props });
|
|
108
|
+
}
|
|
109
|
+
export function Description({ children, ...props }) {
|
|
110
|
+
return React.createElement(View, props, hozoTextChildren(children));
|
|
111
|
+
}
|
|
112
|
+
export function TermList({ role = 'list', children, ...props }) {
|
|
113
|
+
return React.createElement(View, { role, ...props }, hozoTextChildren(children));
|
|
114
|
+
}
|
|
115
|
+
TermList.Term = Term;
|
|
116
|
+
TermList.Description = Description;
|
|
117
|
+
export function Separator({ orientation = 'horizontal', decorative = false, role = decorative ? 'none' : 'separator', style, children, ...props }) {
|
|
118
|
+
const thickness = hozoPreflight ? 1 : 2;
|
|
119
|
+
const defaultStyle = orientation === 'vertical'
|
|
120
|
+
? { width: thickness, alignSelf: 'stretch' }
|
|
121
|
+
: { height: thickness, alignSelf: 'stretch' };
|
|
122
|
+
// Only `role` carries "separator": React Native's `accessibilityRole`
|
|
123
|
+
// has no such value, so the line that used to set it here was a string
|
|
124
|
+
// the platform would ignore. `none` it does have, and that is the half
|
|
125
|
+
// worth keeping -- a decorative rule should be silent on both props.
|
|
126
|
+
return React.createElement(View, {
|
|
127
|
+
role,
|
|
128
|
+
accessibilityRole: decorative ? 'none' : undefined,
|
|
129
|
+
style: [defaultStyle, style],
|
|
130
|
+
...props,
|
|
131
|
+
}, hozoTextChildren(children));
|
|
132
|
+
}
|
|
133
|
+
export function Progress({ value, max, role = 'progressbar', accessibilityValue, style, children, ...props }) {
|
|
134
|
+
return React.createElement(View, {
|
|
135
|
+
role,
|
|
136
|
+
accessibilityRole: 'progressbar',
|
|
137
|
+
accessibilityValue: accessibilityValue ?? {
|
|
138
|
+
min: 0,
|
|
139
|
+
max: max ?? 100,
|
|
140
|
+
now: value,
|
|
141
|
+
},
|
|
142
|
+
// The box the browser gives `<progress>` and React Native gives
|
|
143
|
+
// nothing. Measured in headless Chrome under this project’s own
|
|
144
|
+
// preflight: 160 x 16. Without it a `View` is zero pixels in both
|
|
145
|
+
// directions -- invisible on screen, and absent from the
|
|
146
|
+
// accessibility tree as well, since Android does not report a
|
|
147
|
+
// zero-area view (#309).
|
|
148
|
+
//
|
|
149
|
+
// The author’s style comes second, so any of it wins.
|
|
150
|
+
style: [{ width: 160, height: 16 }, style],
|
|
151
|
+
...props,
|
|
152
|
+
}, hozoTextChildren(children));
|
|
153
|
+
}
|
|
154
|
+
//# sourceMappingURL=index.native.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.native.js","sourceRoot":"","sources":["../src/index.native.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAA;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAA;AACpD,OAAO,KAAK,EAAE,EAAuC,MAAM,OAAO,CAAA;AAClE,qEAAqE;AACrE,wEAAwE;AACxE,mEAAmE;AACnE,wEAAwE;AACxE,sEAAsE;AACtE,qEAAqE;AACrE,sEAAsE;AACtE,mCAAmC;AACnC,OAAO,EAIL,IAAI,EAEJ,IAAI,GAEL,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE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QAAQ,CAAC,CAC3B,CAAA;AACH,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hozo/semantics",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "Universal landmarks, document sectioning, and semantic page structure primitives for Hozo.",
|
|
5
|
+
"keywords": [
|
|
6
|
+
"react-native",
|
|
7
|
+
"react",
|
|
8
|
+
"semantics",
|
|
9
|
+
"landmarks",
|
|
10
|
+
"accessibility",
|
|
11
|
+
"universal"
|
|
12
|
+
],
|
|
13
|
+
"license": "MIT",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/iray-tno/hozo.git",
|
|
17
|
+
"directory": "packages/semantics"
|
|
18
|
+
},
|
|
19
|
+
"homepage": "https://iray-tno.github.io/hozo/",
|
|
20
|
+
"bugs": {
|
|
21
|
+
"url": "https://github.com/iray-tno/hozo/issues"
|
|
22
|
+
},
|
|
23
|
+
"type": "module",
|
|
24
|
+
"main": "./dist/index.js",
|
|
25
|
+
"types": "./dist/index.d.ts",
|
|
26
|
+
"sideEffects": false,
|
|
27
|
+
"exports": {
|
|
28
|
+
".": {
|
|
29
|
+
"react-native": {
|
|
30
|
+
"types": "./dist/index.native.d.ts",
|
|
31
|
+
"default": "./dist/index.native.js"
|
|
32
|
+
},
|
|
33
|
+
"types": "./dist/index.d.ts",
|
|
34
|
+
"default": "./dist/index.js"
|
|
35
|
+
},
|
|
36
|
+
"./generated/disclosure": {
|
|
37
|
+
"react-native": {
|
|
38
|
+
"types": "./dist/generated/disclosure.native.d.ts",
|
|
39
|
+
"default": "./dist/generated/disclosure.native.js"
|
|
40
|
+
},
|
|
41
|
+
"types": "./dist/generated/disclosure.d.ts",
|
|
42
|
+
"default": "./dist/generated/disclosure.js"
|
|
43
|
+
},
|
|
44
|
+
"./package.json": "./package.json"
|
|
45
|
+
},
|
|
46
|
+
"files": [
|
|
47
|
+
"dist",
|
|
48
|
+
"src",
|
|
49
|
+
"!src/**/*.test.ts",
|
|
50
|
+
"!src/**/*.test.tsx",
|
|
51
|
+
"!src/**/*.bench.ts"
|
|
52
|
+
],
|
|
53
|
+
"publishConfig": {
|
|
54
|
+
"access": "public",
|
|
55
|
+
"provenance": true
|
|
56
|
+
},
|
|
57
|
+
"dependencies": {
|
|
58
|
+
"@hozo/engine": "^0.1.0",
|
|
59
|
+
"@hozo/behaviors": "^0.1.0"
|
|
60
|
+
},
|
|
61
|
+
"peerDependencies": {
|
|
62
|
+
"react": "^19.0.0",
|
|
63
|
+
"react-native": ">=0.86"
|
|
64
|
+
},
|
|
65
|
+
"peerDependenciesMeta": {
|
|
66
|
+
"react-native": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"devDependencies": {
|
|
71
|
+
"@types/react": "^19.2.18",
|
|
72
|
+
"@types/react-dom": "^19.2.4",
|
|
73
|
+
"react-dom": "^19.2.8",
|
|
74
|
+
"react-native": "^0.87.1"
|
|
75
|
+
},
|
|
76
|
+
"scripts": {
|
|
77
|
+
"build": "node ../../scripts/clean-package-dist.mjs && tsc -p .",
|
|
78
|
+
"typecheck": "tsc -p . --noEmit",
|
|
79
|
+
"test": "node -e \"require('node:fs').rmSync('.test-build', { recursive: true, force: true })\" && tsc -p tsconfig.test.json && node --test .test-build/*.test.js"
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
// A disclosure, which React Native has no element for.
|
|
2
|
+
//
|
|
3
|
+
// On the Web `<details>` is the whole feature: the browser opens and
|
|
4
|
+
// closes it, hides everything but the `<summary>` while closed, and puts
|
|
5
|
+
// the expanded state in the accessibility tree without being asked. So
|
|
6
|
+
// the Web backend lowers to the element and there is nothing here for it.
|
|
7
|
+
//
|
|
8
|
+
// React Native has none of that. The compiled output used to be a `View`
|
|
9
|
+
// holding a `Pressable` with a button role and then the body, always --
|
|
10
|
+
// no toggle on the button, and the body visible whether it was open or
|
|
11
|
+
// not. A disclosure that cannot close is not a disclosure, and a button
|
|
12
|
+
// that never says `expanded` tells a screen reader nothing about what it
|
|
13
|
+
// does.
|
|
14
|
+
//
|
|
15
|
+
// The pair here is what the compiler emits instead, for the reason it
|
|
16
|
+
// emits `HozoDialog`: the behaviour is React's, not the compiler's.
|
|
17
|
+
|
|
18
|
+
import { hozoTextChildren } from '@hozo/behaviors'
|
|
19
|
+
import {
|
|
20
|
+
Children,
|
|
21
|
+
createContext,
|
|
22
|
+
isValidElement,
|
|
23
|
+
type ReactNode,
|
|
24
|
+
useCallback,
|
|
25
|
+
useContext,
|
|
26
|
+
useState,
|
|
27
|
+
} from 'react'
|
|
28
|
+
import { Pressable, type StyleProp, View, type ViewStyle } from 'react-native'
|
|
29
|
+
|
|
30
|
+
interface DisclosureState {
|
|
31
|
+
open: boolean
|
|
32
|
+
toggle: () => void
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const DisclosureContext = createContext<DisclosureState>({
|
|
36
|
+
open: false,
|
|
37
|
+
toggle: () => undefined,
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
export interface HozoDetailsProps {
|
|
41
|
+
/**
|
|
42
|
+
* Tailwind classes, the same prop the Web half takes.
|
|
43
|
+
*
|
|
44
|
+
* On a tag the compiler lowers it is gone by runtime, replaced by a
|
|
45
|
+
* `StyleSheet` entry. Anywhere else it is carried and ignored here --
|
|
46
|
+
* this side has no CSS engine to resolve a class list against -- and
|
|
47
|
+
* the type still has to accept it, because an app is type-checked
|
|
48
|
+
* against the source the compiler reads rather than its output.
|
|
49
|
+
*/
|
|
50
|
+
className?: string
|
|
51
|
+
children?: ReactNode
|
|
52
|
+
/** Controlled. Without it the disclosure keeps its own state. */
|
|
53
|
+
open?: boolean
|
|
54
|
+
defaultOpen?: boolean
|
|
55
|
+
onToggle?: (open: boolean) => void
|
|
56
|
+
style?: StyleProp<ViewStyle>
|
|
57
|
+
testID?: string
|
|
58
|
+
accessibilityLabel?: string
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface HozoSummaryProps {
|
|
62
|
+
/**
|
|
63
|
+
* Tailwind classes, the same prop the Web half takes.
|
|
64
|
+
*
|
|
65
|
+
* On a tag the compiler lowers it is gone by runtime, replaced by a
|
|
66
|
+
* `StyleSheet` entry. Anywhere else it is carried and ignored here --
|
|
67
|
+
* this side has no CSS engine to resolve a class list against -- and
|
|
68
|
+
* the type still has to accept it, because an app is type-checked
|
|
69
|
+
* against the source the compiler reads rather than its output.
|
|
70
|
+
*/
|
|
71
|
+
className?: string
|
|
72
|
+
children?: ReactNode
|
|
73
|
+
style?: StyleProp<ViewStyle>
|
|
74
|
+
testID?: string
|
|
75
|
+
accessibilityLabel?: string
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* The trigger, and the only child that survives being closed.
|
|
80
|
+
*
|
|
81
|
+
* Declared before `HozoDetails` because that one compares against it by
|
|
82
|
+
* identity to decide what to hide.
|
|
83
|
+
*/
|
|
84
|
+
export function HozoSummary({ children, ...props }: HozoSummaryProps) {
|
|
85
|
+
const { open, toggle } = useContext(DisclosureContext)
|
|
86
|
+
return (
|
|
87
|
+
<Pressable
|
|
88
|
+
accessibilityRole="button"
|
|
89
|
+
accessibilityState={{ expanded: open }}
|
|
90
|
+
onPress={toggle}
|
|
91
|
+
{...props}
|
|
92
|
+
>
|
|
93
|
+
{hozoTextChildren(children)}
|
|
94
|
+
</Pressable>
|
|
95
|
+
)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export function HozoDetails({
|
|
99
|
+
children,
|
|
100
|
+
open: controlled,
|
|
101
|
+
defaultOpen = false,
|
|
102
|
+
onToggle,
|
|
103
|
+
...props
|
|
104
|
+
}: HozoDetailsProps) {
|
|
105
|
+
const [uncontrolled, setUncontrolled] = useState(defaultOpen)
|
|
106
|
+
const open = controlled ?? uncontrolled
|
|
107
|
+
const toggle = useCallback(() => {
|
|
108
|
+
const next = !open
|
|
109
|
+
setUncontrolled(next)
|
|
110
|
+
onToggle?.(next)
|
|
111
|
+
}, [open, onToggle])
|
|
112
|
+
|
|
113
|
+
// Everything but the summary goes away while it is closed, which is what
|
|
114
|
+
// the browser does with `<details>`. Recognised by identity rather than
|
|
115
|
+
// by position: HTML requires the summary to be the first child and Hozo
|
|
116
|
+
// does not check that, so a body written before it would otherwise be
|
|
117
|
+
// the thing that stayed.
|
|
118
|
+
const visible = Children.toArray(children).filter(
|
|
119
|
+
(child) => open || (isValidElement(child) && child.type === HozoSummary),
|
|
120
|
+
)
|
|
121
|
+
|
|
122
|
+
return (
|
|
123
|
+
<DisclosureContext.Provider value={{ open, toggle }}>
|
|
124
|
+
<View {...props}>{hozoTextChildren(visible)}</View>
|
|
125
|
+
</DisclosureContext.Provider>
|
|
126
|
+
)
|
|
127
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { Details as HozoDetails, Summary as HozoSummary } from '../index.tsx'
|