@molecule/app-ui-react-native 2.0.1 → 2.2.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/README.md +81 -10
- package/dist/components/Alert.d.ts.map +1 -1
- package/dist/components/Alert.js +2 -3
- package/dist/components/Button.d.ts +3 -1
- package/dist/components/Button.d.ts.map +1 -1
- package/dist/components/Button.js +35 -3
- package/dist/components/Skeleton.d.ts.map +1 -1
- package/dist/components/Skeleton.js +13 -12
- package/dist/components/Spinner.js +2 -2
- package/dist/elements/Anchor.d.ts +15 -0
- package/dist/elements/Anchor.d.ts.map +1 -0
- package/dist/elements/Anchor.js +57 -0
- package/dist/elements/Box.d.ts +19 -0
- package/dist/elements/Box.d.ts.map +1 -0
- package/dist/elements/Box.js +157 -0
- package/dist/elements/CheckField.d.ts +18 -0
- package/dist/elements/CheckField.d.ts.map +1 -0
- package/dist/elements/CheckField.js +103 -0
- package/dist/elements/Disclosure.d.ts +11 -0
- package/dist/elements/Disclosure.d.ts.map +1 -0
- package/dist/elements/Disclosure.js +67 -0
- package/dist/elements/Fieldset.d.ts +16 -0
- package/dist/elements/Fieldset.d.ts.map +1 -0
- package/dist/elements/Fieldset.js +34 -0
- package/dist/elements/FileField.d.ts +12 -0
- package/dist/elements/FileField.d.ts.map +1 -0
- package/dist/elements/FileField.js +111 -0
- package/dist/elements/FormArea.d.ts +18 -0
- package/dist/elements/FormArea.d.ts.map +1 -0
- package/dist/elements/FormArea.js +42 -0
- package/dist/elements/GlyphIcon.d.ts +19 -0
- package/dist/elements/GlyphIcon.d.ts.map +1 -0
- package/dist/elements/GlyphIcon.js +43 -0
- package/dist/elements/Image.d.ts +17 -0
- package/dist/elements/Image.d.ts.map +1 -0
- package/dist/elements/Image.js +26 -0
- package/dist/elements/Link.d.ts +20 -0
- package/dist/elements/Link.d.ts.map +1 -0
- package/dist/elements/Link.js +53 -0
- package/dist/elements/Pressable.d.ts +18 -0
- package/dist/elements/Pressable.d.ts.map +1 -0
- package/dist/elements/Pressable.js +108 -0
- package/dist/elements/PulseDots.d.ts +15 -0
- package/dist/elements/PulseDots.d.ts.map +1 -0
- package/dist/elements/PulseDots.js +78 -0
- package/dist/elements/RangeField.d.ts +11 -0
- package/dist/elements/RangeField.d.ts.map +1 -0
- package/dist/elements/RangeField.js +266 -0
- package/dist/elements/RichText.d.ts +23 -0
- package/dist/elements/RichText.d.ts.map +1 -0
- package/dist/elements/RichText.js +55 -0
- package/dist/elements/Rule.d.ts +11 -0
- package/dist/elements/Rule.d.ts.map +1 -0
- package/dist/elements/Rule.js +19 -0
- package/dist/elements/ScrollArea.d.ts +21 -0
- package/dist/elements/ScrollArea.d.ts.map +1 -0
- package/dist/elements/ScrollArea.js +101 -0
- package/dist/elements/SelectAction.d.ts +20 -0
- package/dist/elements/SelectAction.d.ts.map +1 -0
- package/dist/elements/SelectAction.js +117 -0
- package/dist/elements/SelectField.d.ts +11 -0
- package/dist/elements/SelectField.d.ts.map +1 -0
- package/dist/elements/SelectField.js +220 -0
- package/dist/elements/SelectMenu.d.ts +19 -0
- package/dist/elements/SelectMenu.d.ts.map +1 -0
- package/dist/elements/SelectMenu.js +122 -0
- package/dist/elements/Svg.d.ts +155 -0
- package/dist/elements/Svg.d.ts.map +1 -0
- package/dist/elements/Svg.js +535 -0
- package/dist/elements/TableBox.d.ts +19 -0
- package/dist/elements/TableBox.d.ts.map +1 -0
- package/dist/elements/TableBox.js +87 -0
- package/dist/elements/TableCell.d.ts +16 -0
- package/dist/elements/TableCell.d.ts.map +1 -0
- package/dist/elements/TableCell.js +69 -0
- package/dist/elements/Text.d.ts +17 -0
- package/dist/elements/Text.d.ts.map +1 -0
- package/dist/elements/Text.js +96 -0
- package/dist/elements/TextField.d.ts +25 -0
- package/dist/elements/TextField.d.ts.map +1 -0
- package/dist/elements/TextField.js +257 -0
- package/dist/elements/accessibility.d.ts +36 -0
- package/dist/elements/accessibility.d.ts.map +1 -0
- package/dist/elements/accessibility.js +244 -0
- package/dist/elements/className.d.ts +45 -0
- package/dist/elements/className.d.ts.map +1 -0
- package/dist/elements/className.js +8 -0
- package/dist/elements/decimal.d.ts +5 -0
- package/dist/elements/decimal.d.ts.map +1 -0
- package/dist/elements/decimal.js +11 -0
- package/dist/elements/documentUrl.d.ts +35 -0
- package/dist/elements/documentUrl.d.ts.map +1 -0
- package/dist/elements/documentUrl.js +89 -0
- package/dist/elements/drag-drop.d.ts +11 -0
- package/dist/elements/drag-drop.d.ts.map +1 -0
- package/dist/elements/drag-drop.js +277 -0
- package/dist/elements/drag.d.ts +53 -0
- package/dist/elements/drag.d.ts.map +1 -0
- package/dist/elements/drag.js +520 -0
- package/dist/elements/dragModifiers.d.ts +22 -0
- package/dist/elements/dragModifiers.d.ts.map +1 -0
- package/dist/elements/dragModifiers.js +62 -0
- package/dist/elements/events.d.ts +45 -0
- package/dist/elements/events.d.ts.map +1 -0
- package/dist/elements/events.js +101 -0
- package/dist/elements/fieldBounds.d.ts +5 -0
- package/dist/elements/fieldBounds.d.ts.map +1 -0
- package/dist/elements/fieldBounds.js +60 -0
- package/dist/elements/flow.d.ts +36 -0
- package/dist/elements/flow.d.ts.map +1 -0
- package/dist/elements/flow.js +47 -0
- package/dist/elements/form.d.ts +48 -0
- package/dist/elements/form.d.ts.map +1 -0
- package/dist/elements/form.js +112 -0
- package/dist/elements/grid.d.ts +96 -0
- package/dist/elements/grid.d.ts.map +1 -0
- package/dist/elements/grid.js +272 -0
- package/dist/elements/index.d.ts +36 -0
- package/dist/elements/index.d.ts.map +1 -0
- package/dist/elements/index.js +35 -0
- package/dist/elements/inherited.d.ts +181 -0
- package/dist/elements/inherited.d.ts.map +1 -0
- package/dist/elements/inherited.js +512 -0
- package/dist/elements/labels.d.ts +39 -0
- package/dist/elements/labels.d.ts.map +1 -0
- package/dist/elements/labels.js +163 -0
- package/dist/elements/measure.d.ts +27 -0
- package/dist/elements/measure.d.ts.map +1 -0
- package/dist/elements/measure.js +24 -0
- package/dist/elements/outsidePress.d.ts +31 -0
- package/dist/elements/outsidePress.d.ts.map +1 -0
- package/dist/elements/outsidePress.js +94 -0
- package/dist/elements/paste.d.ts +22 -0
- package/dist/elements/paste.d.ts.map +1 -0
- package/dist/elements/paste.js +49 -0
- package/dist/elements/press.d.ts +41 -0
- package/dist/elements/press.d.ts.map +1 -0
- package/dist/elements/press.js +131 -0
- package/dist/elements/rangeKeyboard.d.ts +41 -0
- package/dist/elements/rangeKeyboard.d.ts.map +1 -0
- package/dist/elements/rangeKeyboard.js +58 -0
- package/dist/elements/rangeValues.d.ts +20 -0
- package/dist/elements/rangeValues.d.ts.map +1 -0
- package/dist/elements/rangeValues.js +101 -0
- package/dist/elements/ref.d.ts +16 -0
- package/dist/elements/ref.d.ts.map +1 -0
- package/dist/elements/ref.js +22 -0
- package/dist/elements/reveal.d.ts +8 -0
- package/dist/elements/reveal.d.ts.map +1 -0
- package/dist/elements/reveal.js +10 -0
- package/dist/elements/scrollReveal.d.ts +19 -0
- package/dist/elements/scrollReveal.d.ts.map +1 -0
- package/dist/elements/scrollReveal.js +52 -0
- package/dist/elements/selectOptions.d.ts +25 -0
- package/dist/elements/selectOptions.d.ts.map +1 -0
- package/dist/elements/selectOptions.js +60 -0
- package/dist/elements/style.d.ts +30 -0
- package/dist/elements/style.d.ts.map +1 -0
- package/dist/elements/style.js +368 -0
- package/dist/elements/svgHover.d.ts +41 -0
- package/dist/elements/svgHover.d.ts.map +1 -0
- package/dist/elements/svgHover.js +152 -0
- package/dist/elements/table.d.ts +52 -0
- package/dist/elements/table.d.ts.map +1 -0
- package/dist/elements/table.js +104 -0
- package/dist/elements/types.d.ts +25 -0
- package/dist/elements/types.d.ts.map +1 -0
- package/dist/elements/types.js +8 -0
- package/dist/elements/viewport.d.ts +53 -0
- package/dist/elements/viewport.d.ts.map +1 -0
- package/dist/elements/viewport.js +62 -0
- package/dist/elements/wheelZoom.d.ts +12 -0
- package/dist/elements/wheelZoom.d.ts.map +1 -0
- package/dist/elements/wheelZoom.js +8 -0
- package/dist/index.d.ts +9 -4
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +9 -4
- package/dist/platform/focus.d.ts +31 -0
- package/dist/platform/focus.d.ts.map +1 -0
- package/dist/platform/focus.js +93 -0
- package/dist/platform/index.d.ts +31 -0
- package/dist/platform/index.d.ts.map +1 -0
- package/dist/platform/index.js +179 -0
- package/dist/platform/layout.d.ts +13 -0
- package/dist/platform/layout.d.ts.map +1 -0
- package/dist/platform/layout.js +15 -0
- package/dist/platform/position.d.ts +5 -0
- package/dist/platform/position.d.ts.map +1 -0
- package/dist/platform/position.js +177 -0
- package/dist/platform/stack.d.ts +86 -0
- package/dist/platform/stack.d.ts.map +1 -0
- package/dist/platform/stack.js +318 -0
- package/package.json +67 -8
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Web-shaped events for the handlers of native elements.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* The members every kit event has, over a native event.
|
|
8
|
+
*
|
|
9
|
+
* @param stop - Stops the native event's propagation.
|
|
10
|
+
* @param target - The field whose value changed.
|
|
11
|
+
* @returns The event members.
|
|
12
|
+
*/
|
|
13
|
+
export function kitEvent(stop = () => undefined, target = null) {
|
|
14
|
+
let prevented = false;
|
|
15
|
+
return {
|
|
16
|
+
target,
|
|
17
|
+
currentTarget: target,
|
|
18
|
+
get defaultPrevented() {
|
|
19
|
+
return prevented;
|
|
20
|
+
},
|
|
21
|
+
preventDefault() {
|
|
22
|
+
prevented = true;
|
|
23
|
+
},
|
|
24
|
+
stopPropagation: stop,
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
/** A change event whose target carries the input's current properties. */
|
|
28
|
+
export function fieldEvent(properties) {
|
|
29
|
+
const target = Object.assign({
|
|
30
|
+
addEventListener() { },
|
|
31
|
+
removeEventListener() { },
|
|
32
|
+
dispatchEvent: () => false,
|
|
33
|
+
}, properties);
|
|
34
|
+
return kitEvent(undefined, target);
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* A press, hover or click as the mouse event a handler written for the web receives.
|
|
38
|
+
*
|
|
39
|
+
* @param event - The native event.
|
|
40
|
+
* @param button - The mouse button that changed state.
|
|
41
|
+
* @returns The mouse event.
|
|
42
|
+
*/
|
|
43
|
+
export function mouseEvent(event, button = 0) {
|
|
44
|
+
const x = event?.nativeEvent.pageX ?? 0;
|
|
45
|
+
const y = event?.nativeEvent.pageY ?? 0;
|
|
46
|
+
return Object.assign(kitEvent(() => event?.stopPropagation()), {
|
|
47
|
+
altKey: false,
|
|
48
|
+
ctrlKey: false,
|
|
49
|
+
metaKey: false,
|
|
50
|
+
shiftKey: false,
|
|
51
|
+
button,
|
|
52
|
+
buttons: 0,
|
|
53
|
+
clientX: x,
|
|
54
|
+
clientY: y,
|
|
55
|
+
pageX: x,
|
|
56
|
+
pageY: y,
|
|
57
|
+
detail: 1,
|
|
58
|
+
relatedTarget: null,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* The physical key (`code`) the web reports for a key value a device's keyboard sends.
|
|
63
|
+
*
|
|
64
|
+
* @param key - The key value (`'a'`, `'Enter'`, `' '`).
|
|
65
|
+
* @returns The code (`'KeyA'`, `'Enter'`, `'Space'`), or `''` when there is none.
|
|
66
|
+
*/
|
|
67
|
+
function keyCode(key) {
|
|
68
|
+
if (key === ' ')
|
|
69
|
+
return 'Space';
|
|
70
|
+
if (/^[a-z]$/i.test(key))
|
|
71
|
+
return `Key${key.toUpperCase()}`;
|
|
72
|
+
if (/^\d$/.test(key))
|
|
73
|
+
return `Digit${key}`;
|
|
74
|
+
return key.length > 1 ? key : '';
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* A key a device's keyboard sent to a text field, as the keyboard event a handler written for the
|
|
78
|
+
* web receives. A device's keyboard holds no modifiers and does not repeat.
|
|
79
|
+
*
|
|
80
|
+
* @param key - The key value React Native reports (`'a'`, `'Enter'`, `'Backspace'`).
|
|
81
|
+
* @returns The keyboard event.
|
|
82
|
+
*/
|
|
83
|
+
export function keyboardEvent(key) {
|
|
84
|
+
return Object.assign(kitEvent(() => undefined), {
|
|
85
|
+
altKey: false,
|
|
86
|
+
ctrlKey: false,
|
|
87
|
+
metaKey: false,
|
|
88
|
+
shiftKey: false,
|
|
89
|
+
key,
|
|
90
|
+
code: keyCode(key),
|
|
91
|
+
repeat: false,
|
|
92
|
+
});
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* A native focus or blur as the focus event a handler written for the web receives.
|
|
96
|
+
*
|
|
97
|
+
* @returns The focus event.
|
|
98
|
+
*/
|
|
99
|
+
export function focusEvent() {
|
|
100
|
+
return Object.assign(kitEvent(() => undefined), { relatedTarget: null });
|
|
101
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** Number and date constraints used when a native form is submitted. */
|
|
2
|
+
import type { TextFieldProps } from '@molecule/app-ui';
|
|
3
|
+
/** Validates a nonempty field answer without changing the text in the input. */
|
|
4
|
+
export declare function validBoundedField(props: TextFieldProps, text: string): boolean;
|
|
5
|
+
//# sourceMappingURL=fieldBounds.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"fieldBounds.d.ts","sourceRoot":"","sources":["../../src/elements/fieldBounds.ts"],"names":[],"mappings":"AAAA,wEAAwE;AAExE,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAuDtD,gFAAgF;AAChF,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAuB9E"}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/** Number and date constraints used when a native form is submitted. */
|
|
2
|
+
import { decimalPlaces, scaled } from './decimal.js';
|
|
3
|
+
const FLOAT = /^-?(?:\d+|\d*\.\d+)(?:[eE][+-]?\d+)?$/;
|
|
4
|
+
const DATE = /^(\d{4,})-(\d{2})-(\d{2})$/;
|
|
5
|
+
const DAYS_BEFORE_MONTH = [0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365];
|
|
6
|
+
const EPOCH_DAY = 719162n; // January 1, 1970 as a zero-based Gregorian day number.
|
|
7
|
+
/** Converts an HTML floating-point string or a numeric attribute to a finite number. */
|
|
8
|
+
function fieldNumber(text) {
|
|
9
|
+
if (typeof text === 'string' && FLOAT.exec(text)?.[0] !== text)
|
|
10
|
+
return undefined;
|
|
11
|
+
const value = Number(text);
|
|
12
|
+
return Number.isFinite(value) ? value : undefined;
|
|
13
|
+
}
|
|
14
|
+
/** Parses an HTML calendar date and gives its day number without a local time zone. */
|
|
15
|
+
function calendarDay(text) {
|
|
16
|
+
if (text === undefined)
|
|
17
|
+
return undefined;
|
|
18
|
+
const match = DATE.exec(text);
|
|
19
|
+
if (!match || match[0] !== text)
|
|
20
|
+
return undefined;
|
|
21
|
+
const [, yearText, monthText, dateText] = match;
|
|
22
|
+
const year = BigInt(yearText);
|
|
23
|
+
const month = Number(monthText);
|
|
24
|
+
const date = Number(dateText);
|
|
25
|
+
if (year === 0n || month < 1 || month > 12 || date < 1)
|
|
26
|
+
return undefined;
|
|
27
|
+
const leap = year % 4n === 0n && (year % 100n !== 0n || year % 400n === 0n);
|
|
28
|
+
const beforeMonth = DAYS_BEFORE_MONTH[month - 1];
|
|
29
|
+
const monthLength = DAYS_BEFORE_MONTH[month] - beforeMonth + (month === 2 && leap ? 1 : 0);
|
|
30
|
+
if (date > monthLength)
|
|
31
|
+
return undefined;
|
|
32
|
+
const previous = year - 1n;
|
|
33
|
+
const withinYear = beforeMonth + date - 1 + (month > 2 && leap ? 1 : 0);
|
|
34
|
+
return previous * 365n + previous / 4n - previous / 100n + previous / 400n + BigInt(withinYear);
|
|
35
|
+
}
|
|
36
|
+
/** Checks inclusive bounds and exact decimal alignment for the allowed step. */
|
|
37
|
+
function satisfiesBounds(value, minimum, maximum, base, step) {
|
|
38
|
+
if (value === undefined ||
|
|
39
|
+
(minimum !== undefined && value < minimum) ||
|
|
40
|
+
(maximum !== undefined && value > maximum))
|
|
41
|
+
return false;
|
|
42
|
+
if (step === 'any')
|
|
43
|
+
return true;
|
|
44
|
+
const increment = step !== undefined && Number.isFinite(step) && step > 0 ? step : 1;
|
|
45
|
+
const places = Math.max(decimalPlaces(value), decimalPlaces(base), decimalPlaces(increment));
|
|
46
|
+
return (scaled(value, places) - scaled(base, places)) % scaled(increment, places) === 0n;
|
|
47
|
+
}
|
|
48
|
+
/** Validates a nonempty field answer without changing the text in the input. */
|
|
49
|
+
export function validBoundedField(props, text) {
|
|
50
|
+
const attributeValue = props.value ?? props.defaultValue;
|
|
51
|
+
if (props.type === 'number') {
|
|
52
|
+
const min = fieldNumber(props.min);
|
|
53
|
+
return satisfiesBounds(fieldNumber(text), min, fieldNumber(props.max), min ?? fieldNumber(attributeValue) ?? 0, props.step);
|
|
54
|
+
}
|
|
55
|
+
if (props.type === 'date') {
|
|
56
|
+
const min = calendarDay(props.min);
|
|
57
|
+
return satisfiesBounds(calendarDay(text), min, calendarDay(props.max), min ?? calendarDay(attributeValue) ?? EPOCH_DAY, props.step);
|
|
58
|
+
}
|
|
59
|
+
return true;
|
|
60
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How components flow in a line, for the native layout of inline content.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { InlineKind } from '@molecule/app-ui';
|
|
7
|
+
/** Registers a provider that can share its parent's layout using display contents. */
|
|
8
|
+
export declare function registerContents(component: unknown, hasContents: (props: Record<string, unknown>) => boolean): void;
|
|
9
|
+
/** Whether the element's children take part directly in its parent's layout. */
|
|
10
|
+
export declare function displaysContents(component: unknown, props: Record<string, unknown>): boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Registers how a component flows inside a container that is not a flex container: as inline
|
|
13
|
+
* text (it renders a `Text` that joins the line), as an inline box (it sits in the line beside
|
|
14
|
+
* text), or as a block. Every element registers itself; a component that renders an inline
|
|
15
|
+
* element at its root (a button, a badge, an icon) registers too, or it is laid out as a block.
|
|
16
|
+
*
|
|
17
|
+
* @param component - The component.
|
|
18
|
+
* @param kind - Its kind for given props.
|
|
19
|
+
*/
|
|
20
|
+
export declare function registerInline(component: unknown, kind: (props: Record<string, unknown>) => InlineKind): void;
|
|
21
|
+
/**
|
|
22
|
+
* How a registered component flows with the given props.
|
|
23
|
+
*
|
|
24
|
+
* @param component - The component.
|
|
25
|
+
* @param props - Its props.
|
|
26
|
+
* @returns Its kind, or `undefined` when it never registered.
|
|
27
|
+
*/
|
|
28
|
+
export declare function registeredKind(component: unknown, props: Record<string, unknown>): InlineKind | undefined;
|
|
29
|
+
/**
|
|
30
|
+
* Whether a component registered how it flows.
|
|
31
|
+
*
|
|
32
|
+
* @param component - The component.
|
|
33
|
+
* @returns Whether it did.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isRegistered(component: unknown): boolean;
|
|
36
|
+
//# sourceMappingURL=flow.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"flow.d.ts","sourceRoot":"","sources":["../../src/elements/flow.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAMlD,sFAAsF;AACtF,wBAAgB,gBAAgB,CAC9B,SAAS,EAAE,OAAO,EAClB,WAAW,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,OAAO,GACvD,IAAI,CAEN;AAED,gFAAgF;AAChF,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAE5F;AAED;;;;;;;;GAQG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,OAAO,EAClB,IAAI,EAAE,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,UAAU,GACnD,IAAI,CAEN;AAED;;;;;;GAMG;AACH,wBAAgB,cAAc,CAC5B,SAAS,EAAE,OAAO,EAClB,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC7B,UAAU,GAAG,SAAS,CAExB;AAED;;;;;GAKG;AACH,wBAAgB,YAAY,CAAC,SAAS,EAAE,OAAO,GAAG,OAAO,CAExD"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* How components flow in a line, for the native layout of inline content.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
/** How each registered component flows, by its props. */
|
|
7
|
+
const INLINE = new Map();
|
|
8
|
+
const CONTENTS = new Map();
|
|
9
|
+
/** Registers a provider that can share its parent's layout using display contents. */
|
|
10
|
+
export function registerContents(component, hasContents) {
|
|
11
|
+
CONTENTS.set(component, hasContents);
|
|
12
|
+
}
|
|
13
|
+
/** Whether the element's children take part directly in its parent's layout. */
|
|
14
|
+
export function displaysContents(component, props) {
|
|
15
|
+
return CONTENTS.get(component)?.(props) ?? false;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Registers how a component flows inside a container that is not a flex container: as inline
|
|
19
|
+
* text (it renders a `Text` that joins the line), as an inline box (it sits in the line beside
|
|
20
|
+
* text), or as a block. Every element registers itself; a component that renders an inline
|
|
21
|
+
* element at its root (a button, a badge, an icon) registers too, or it is laid out as a block.
|
|
22
|
+
*
|
|
23
|
+
* @param component - The component.
|
|
24
|
+
* @param kind - Its kind for given props.
|
|
25
|
+
*/
|
|
26
|
+
export function registerInline(component, kind) {
|
|
27
|
+
INLINE.set(component, kind);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* How a registered component flows with the given props.
|
|
31
|
+
*
|
|
32
|
+
* @param component - The component.
|
|
33
|
+
* @param props - Its props.
|
|
34
|
+
* @returns Its kind, or `undefined` when it never registered.
|
|
35
|
+
*/
|
|
36
|
+
export function registeredKind(component, props) {
|
|
37
|
+
return INLINE.get(component)?.(props);
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* Whether a component registered how it flows.
|
|
41
|
+
*
|
|
42
|
+
* @param component - The component.
|
|
43
|
+
* @returns Whether it did.
|
|
44
|
+
*/
|
|
45
|
+
export function isRegistered(component) {
|
|
46
|
+
return INLINE.has(component) || CONTENTS.has(component);
|
|
47
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form registration and default actions for native elements.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import type { FormAreaProps, FormEntries, PressableProps } from '@molecule/app-ui';
|
|
7
|
+
/** A mounted control, read when the form is submitted or reset. */
|
|
8
|
+
export interface FormField {
|
|
9
|
+
entries(): FormEntries;
|
|
10
|
+
valid(): boolean;
|
|
11
|
+
reset(): void;
|
|
12
|
+
focus(): void;
|
|
13
|
+
singleLine?: boolean;
|
|
14
|
+
/** The name of the radio group this checked control belongs to. */
|
|
15
|
+
checkedRadio?(): string | undefined;
|
|
16
|
+
}
|
|
17
|
+
/** A mounted button that can be used to submit the form. */
|
|
18
|
+
export interface FormButton {
|
|
19
|
+
type: PressableProps['type'];
|
|
20
|
+
disabled: boolean;
|
|
21
|
+
activate(): void;
|
|
22
|
+
}
|
|
23
|
+
interface FormControls {
|
|
24
|
+
fields: Set<() => FormField>;
|
|
25
|
+
buttons: Set<() => FormButton>;
|
|
26
|
+
submit(): void;
|
|
27
|
+
hasCheckedRadio(name: string): boolean;
|
|
28
|
+
reset(): void;
|
|
29
|
+
submitImplicitly(): void;
|
|
30
|
+
}
|
|
31
|
+
/** A native form's mounted fields, buttons and default actions. */
|
|
32
|
+
export declare function createFormScope(readProps: () => Pick<FormAreaProps, 'onSubmit' | 'onReset' | 'noValidate'>): FormControls;
|
|
33
|
+
/** The form nearest a control. Registrations are in native mount order. */
|
|
34
|
+
export declare const FormScope: import("react").Context<FormControls | null>;
|
|
35
|
+
/** Whether a fieldset above the control has disabled it. */
|
|
36
|
+
export declare const DisabledScope: import("react").Context<boolean>;
|
|
37
|
+
/** Keeps a mounted registration in place while its props change. */
|
|
38
|
+
export declare function useFormRegistration<T>(registry: Set<() => T> | undefined, registration: T): void;
|
|
39
|
+
interface FieldValue<T> {
|
|
40
|
+
displayed: T;
|
|
41
|
+
read(): T;
|
|
42
|
+
change(next: T, notify: () => void): void;
|
|
43
|
+
reset(): void;
|
|
44
|
+
}
|
|
45
|
+
/** Tracks the value a form can read immediately, including during a change handler. */
|
|
46
|
+
export declare function useFieldValue<T>(value: T | undefined, defaultValue: T): FieldValue<T>;
|
|
47
|
+
export {};
|
|
48
|
+
//# sourceMappingURL=form.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../../src/elements/form.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH,OAAO,KAAK,EAAE,aAAa,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAA;AAIlF,mEAAmE;AACnE,MAAM,WAAW,SAAS;IACxB,OAAO,IAAI,WAAW,CAAA;IACtB,KAAK,IAAI,OAAO,CAAA;IAChB,KAAK,IAAI,IAAI,CAAA;IACb,KAAK,IAAI,IAAI,CAAA;IACb,UAAU,CAAC,EAAE,OAAO,CAAA;IACpB,mEAAmE;IACnE,YAAY,CAAC,IAAI,MAAM,GAAG,SAAS,CAAA;CACpC;AAED,4DAA4D;AAC5D,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,cAAc,CAAC,MAAM,CAAC,CAAA;IAC5B,QAAQ,EAAE,OAAO,CAAA;IACjB,QAAQ,IAAI,IAAI,CAAA;CACjB;AAED,UAAU,YAAY;IACpB,MAAM,EAAE,GAAG,CAAC,MAAM,SAAS,CAAC,CAAA;IAC5B,OAAO,EAAE,GAAG,CAAC,MAAM,UAAU,CAAC,CAAA;IAC9B,MAAM,IAAI,IAAI,CAAA;IACd,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAA;IACtC,KAAK,IAAI,IAAI,CAAA;IACb,gBAAgB,IAAI,IAAI,CAAA;CACzB;AAED,mEAAmE;AACnE,wBAAgB,eAAe,CAC7B,SAAS,EAAE,MAAM,IAAI,CAAC,aAAa,EAAE,UAAU,GAAG,SAAS,GAAG,YAAY,CAAC,GAC1E,YAAY,CA2Cd;AAED,2EAA2E;AAC3E,eAAO,MAAM,SAAS,8CAAiE,CAAA;AAEvF,4DAA4D;AAC5D,eAAO,MAAM,aAAa,kCAAuB,CAAA;AAEjD,oEAAoE;AACpE,wBAAgB,mBAAmB,CAAC,CAAC,EAAE,QAAQ,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC,GAAG,SAAS,EAAE,YAAY,EAAE,CAAC,GAAG,IAAI,CAahG;AAED,UAAU,UAAU,CAAC,CAAC;IACpB,SAAS,EAAE,CAAC,CAAA;IACZ,IAAI,IAAI,CAAC,CAAA;IACT,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,IAAI,GAAG,IAAI,CAAA;IACzC,KAAK,IAAI,IAAI,CAAA;CACd;AAED,uFAAuF;AACvF,wBAAgB,aAAa,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,SAAS,EAAE,YAAY,EAAE,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC,CAiCrF"}
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Form registration and default actions for native elements.
|
|
3
|
+
*
|
|
4
|
+
* @module
|
|
5
|
+
*/
|
|
6
|
+
import { createContext, useCallback, useLayoutEffect, useRef, useState } from 'react';
|
|
7
|
+
import { kitEvent } from './events.js';
|
|
8
|
+
/** A native form's mounted fields, buttons and default actions. */
|
|
9
|
+
export function createFormScope(readProps) {
|
|
10
|
+
const fields = new Set();
|
|
11
|
+
const buttons = new Set();
|
|
12
|
+
const submit = () => {
|
|
13
|
+
const { onSubmit, noValidate } = readProps();
|
|
14
|
+
const controls = Array.from(fields, (read) => read());
|
|
15
|
+
if (!noValidate) {
|
|
16
|
+
const invalid = controls.find((field) => !field.valid());
|
|
17
|
+
if (invalid) {
|
|
18
|
+
invalid.focus();
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (onSubmit) {
|
|
23
|
+
const entries = controls.flatMap((field) => field.entries());
|
|
24
|
+
onSubmit(kitEvent(), entries);
|
|
25
|
+
}
|
|
26
|
+
};
|
|
27
|
+
return {
|
|
28
|
+
fields,
|
|
29
|
+
buttons,
|
|
30
|
+
submit,
|
|
31
|
+
hasCheckedRadio(name) {
|
|
32
|
+
return Array.from(fields).some((read) => read().checkedRadio?.() === name);
|
|
33
|
+
},
|
|
34
|
+
reset() {
|
|
35
|
+
const event = kitEvent();
|
|
36
|
+
readProps().onReset?.(event);
|
|
37
|
+
if (!event.defaultPrevented)
|
|
38
|
+
fields.forEach((read) => read().reset());
|
|
39
|
+
},
|
|
40
|
+
submitImplicitly() {
|
|
41
|
+
for (const read of buttons) {
|
|
42
|
+
const button = read();
|
|
43
|
+
if (button.type === undefined || button.type === 'submit') {
|
|
44
|
+
if (!button.disabled)
|
|
45
|
+
button.activate();
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (Array.from(fields).filter((read) => read().singleLine).length === 1)
|
|
50
|
+
submit();
|
|
51
|
+
},
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
/** The form nearest a control. Registrations are in native mount order. */
|
|
55
|
+
export const FormScope = createContext(null);
|
|
56
|
+
/** Whether a fieldset above the control has disabled it. */
|
|
57
|
+
export const DisabledScope = createContext(false);
|
|
58
|
+
/** Keeps a mounted registration in place while its props change. */
|
|
59
|
+
export function useFormRegistration(registry, registration) {
|
|
60
|
+
const latest = useRef(registration);
|
|
61
|
+
useLayoutEffect(() => {
|
|
62
|
+
latest.current = registration;
|
|
63
|
+
}, [registration]);
|
|
64
|
+
useLayoutEffect(() => {
|
|
65
|
+
if (!registry)
|
|
66
|
+
return;
|
|
67
|
+
const read = () => latest.current;
|
|
68
|
+
registry.add(read);
|
|
69
|
+
return () => {
|
|
70
|
+
registry.delete(read);
|
|
71
|
+
};
|
|
72
|
+
}, [registry]);
|
|
73
|
+
}
|
|
74
|
+
/** Tracks the value a form can read immediately, including during a change handler. */
|
|
75
|
+
export function useFieldValue(value, defaultValue) {
|
|
76
|
+
const [uncontrolled, setUncontrolled] = useState(() => defaultValue);
|
|
77
|
+
const displayed = value === undefined ? uncontrolled : value;
|
|
78
|
+
const controlled = useRef(value);
|
|
79
|
+
const current = useRef(displayed);
|
|
80
|
+
const proposal = useRef(null);
|
|
81
|
+
const read = useCallback(() => (proposal.current ? proposal.current.value : current.current), []);
|
|
82
|
+
useLayoutEffect(() => {
|
|
83
|
+
controlled.current = value;
|
|
84
|
+
current.current = displayed;
|
|
85
|
+
}, [displayed, value]);
|
|
86
|
+
return {
|
|
87
|
+
displayed,
|
|
88
|
+
read,
|
|
89
|
+
change(next, notify) {
|
|
90
|
+
const previous = proposal.current;
|
|
91
|
+
// A callback can synchronously render new controlled props before submitting the proposal.
|
|
92
|
+
proposal.current = { value: next };
|
|
93
|
+
current.current = next;
|
|
94
|
+
if (value === undefined)
|
|
95
|
+
setUncontrolled(() => next);
|
|
96
|
+
try {
|
|
97
|
+
notify();
|
|
98
|
+
}
|
|
99
|
+
finally {
|
|
100
|
+
proposal.current = previous;
|
|
101
|
+
if (controlled.current !== undefined)
|
|
102
|
+
current.current = controlled.current;
|
|
103
|
+
}
|
|
104
|
+
},
|
|
105
|
+
reset() {
|
|
106
|
+
if (value !== undefined)
|
|
107
|
+
return;
|
|
108
|
+
current.current = defaultValue;
|
|
109
|
+
setUncontrolled(() => defaultValue);
|
|
110
|
+
},
|
|
111
|
+
};
|
|
112
|
+
}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CSS grid on a device, which has no grid layout: a grid's children are placed in its tracks as
|
|
3
|
+
* the web's auto-placement does, each row a flex row whose items stretch to its height.
|
|
4
|
+
*
|
|
5
|
+
* @module
|
|
6
|
+
*/
|
|
7
|
+
import { type ReactElement, type ReactNode } from 'react';
|
|
8
|
+
import type { NativeClassSplit, NativeGridClasses, WebStyle } from '@molecule/app-ui';
|
|
9
|
+
/**
|
|
10
|
+
* The style the grid cell around an element gives it: its width, when a grid placed it.
|
|
11
|
+
*
|
|
12
|
+
* @returns The style, or `undefined` outside a grid cell.
|
|
13
|
+
*/
|
|
14
|
+
export declare function useGridCell(): {
|
|
15
|
+
width: number;
|
|
16
|
+
} | undefined;
|
|
17
|
+
/**
|
|
18
|
+
* Ends the cell an element sits in for its children: a grid places only its own children.
|
|
19
|
+
*
|
|
20
|
+
* @param props - The children.
|
|
21
|
+
* @returns The children outside any cell.
|
|
22
|
+
*/
|
|
23
|
+
export declare function NoGridCell({ children }: {
|
|
24
|
+
children?: ReactNode;
|
|
25
|
+
}): ReactElement;
|
|
26
|
+
/** One track of a track list: a fixed size in pixels, a share of the free space, or a percentage. */
|
|
27
|
+
type Track = {
|
|
28
|
+
px: number;
|
|
29
|
+
} | {
|
|
30
|
+
fr: number;
|
|
31
|
+
} | {
|
|
32
|
+
percent: number;
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* A track list's tracks (`repeat(3, minmax(0, 1fr))`, `1fr 2fr`, `200px 1fr`). `auto` and
|
|
36
|
+
* `minmax(…, 1fr)` share the free space as `1fr` does: a device cannot size a track to its content.
|
|
37
|
+
*
|
|
38
|
+
* @param list - The CSS track list.
|
|
39
|
+
* @returns The tracks, or `null` when the list is empty.
|
|
40
|
+
*/
|
|
41
|
+
export declare function parseTracks(list: string): Track[] | null;
|
|
42
|
+
/**
|
|
43
|
+
* The widths of a grid's columns in a container this wide, as CSS grid sizes them: fixed and
|
|
44
|
+
* percentage tracks first, then the free space shared by `fr`.
|
|
45
|
+
*
|
|
46
|
+
* @param tracks - The tracks.
|
|
47
|
+
* @param width - The container's content width.
|
|
48
|
+
* @param gap - The gap between columns.
|
|
49
|
+
* @returns Each column's width.
|
|
50
|
+
*/
|
|
51
|
+
export declare function trackWidths(tracks: readonly Track[], width: number, gap: number): number[];
|
|
52
|
+
/**
|
|
53
|
+
* The heights of a grid's explicit rows when its own height is unset, as CSS grid sizes them: a
|
|
54
|
+
* fixed track keeps its size, and the flexible ones share one unit, the largest of their content
|
|
55
|
+
* heights over their `fr` (equal `1fr` rows are all as tall as the tallest). A percentage of an
|
|
56
|
+
* unset height is its content's height, as `auto` is.
|
|
57
|
+
*
|
|
58
|
+
* @param tracks - The explicit row tracks.
|
|
59
|
+
* @param natural - Each explicit row's content height (`0` for a row with no item).
|
|
60
|
+
* @returns Each explicit row's height, or `undefined` for a row its content sizes.
|
|
61
|
+
*/
|
|
62
|
+
export declare function rowHeights(tracks: readonly Track[], natural: readonly number[]): Array<number | undefined>;
|
|
63
|
+
/**
|
|
64
|
+
* The value of a breakpoint-keyed grid entry at a window width: the entry of the widest
|
|
65
|
+
* breakpoint the window reaches, as the web's min-width media queries apply.
|
|
66
|
+
*
|
|
67
|
+
* @param values - The values by breakpoint variant (`''` at the base size).
|
|
68
|
+
* @param windowWidth - The window's width.
|
|
69
|
+
* @returns The value, or `undefined` when none applies.
|
|
70
|
+
*/
|
|
71
|
+
export declare function atBreakpoint<T>(values: Readonly<Record<string, T>>, windowWidth: number): T | undefined;
|
|
72
|
+
/**
|
|
73
|
+
* A grid container's native layout: the style its view takes (a column of rows, the row gap) and
|
|
74
|
+
* its children placed in rows of cells.
|
|
75
|
+
*
|
|
76
|
+
* @param props - The grid's classes (`grid`), its web style (a track list, gaps), its text classes
|
|
77
|
+
* (for a bare string among its children), a splitter for its children's classes, and the children.
|
|
78
|
+
* @returns The layout's view style and its rows (the first measures the content width).
|
|
79
|
+
*/
|
|
80
|
+
export declare function useGridLayout({ grid, webStyle, text, split, children, }: {
|
|
81
|
+
grid: NativeGridClasses;
|
|
82
|
+
webStyle: WebStyle | undefined;
|
|
83
|
+
text: string;
|
|
84
|
+
split: (className: string | undefined) => NativeClassSplit;
|
|
85
|
+
children: ReactNode;
|
|
86
|
+
}): {
|
|
87
|
+
style: {
|
|
88
|
+
flexDirection: 'column';
|
|
89
|
+
alignItems: 'stretch';
|
|
90
|
+
rowGap: number;
|
|
91
|
+
columnGap: 0;
|
|
92
|
+
};
|
|
93
|
+
rows: ReactNode;
|
|
94
|
+
};
|
|
95
|
+
export {};
|
|
96
|
+
//# sourceMappingURL=grid.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"grid.d.ts","sourceRoot":"","sources":["../../src/elements/grid.tsx"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAKL,KAAK,YAAY,EACjB,KAAK,SAAS,EAIf,MAAM,OAAO,CAAA;AAGd,OAAO,KAAK,EAAE,gBAAgB,EAAE,iBAAiB,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAA;AAMrF;;;;GAIG;AACH,wBAAgB,WAAW,IAAI;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,GAAG,SAAS,CAE3D;AAED;;;;;GAKG;AACH,wBAAgB,UAAU,CAAC,EAAE,QAAQ,EAAE,EAAE;IAAE,QAAQ,CAAC,EAAE,SAAS,CAAA;CAAE,GAAG,YAAY,CAE/E;AAED,qGAAqG;AACrG,KAAK,KAAK,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,GAAG;IAAE,OAAO,EAAE,MAAM,CAAA;CAAE,CAAA;AAElE;;;;;;GAMG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,GAAG,KAAK,EAAE,GAAG,IAAI,CAiCxD;AAED;;;;;;;;GAQG;AACH,wBAAgB,WAAW,CAAC,MAAM,EAAE,SAAS,KAAK,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,GAAG,MAAM,EAAE,CAY1F;AAED;;;;;;;;;GASG;AACH,wBAAgB,UAAU,CACxB,MAAM,EAAE,SAAS,KAAK,EAAE,EACxB,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,KAAK,CAAC,MAAM,GAAG,SAAS,CAAC,CAQ3B;AAED;;;;;;;GAOG;AACH,wBAAgB,YAAY,CAAC,CAAC,EAC5B,MAAM,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,EACnC,WAAW,EAAE,MAAM,GAClB,CAAC,GAAG,SAAS,CAaf;AA8CD;;;;;;;GAOG;AACH,wBAAgB,aAAa,CAAC,EAC5B,IAAI,EACJ,QAAQ,EACR,IAAI,EACJ,KAAK,EACL,QAAQ,GACT,EAAE;IACD,IAAI,EAAE,iBAAiB,CAAA;IACvB,QAAQ,EAAE,QAAQ,GAAG,SAAS,CAAA;IAC9B,IAAI,EAAE,MAAM,CAAA;IACZ,KAAK,EAAE,CAAC,SAAS,EAAE,MAAM,GAAG,SAAS,KAAK,gBAAgB,CAAA;IAC1D,QAAQ,EAAE,SAAS,CAAA;CACpB,GAAG;IACF,KAAK,EAAE;QAAE,aAAa,EAAE,QAAQ,CAAC;QAAC,UAAU,EAAE,SAAS,CAAC;QAAC,MAAM,EAAE,MAAM,CAAC;QAAC,SAAS,EAAE,CAAC,CAAA;KAAE,CAAA;IACvF,IAAI,EAAE,SAAS,CAAA;CAChB,CA8GA"}
|