@colixsystems/widget-sdk 0.302.0 → 0.304.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 +9 -1
- package/dist/contract.cjs +4 -2
- package/dist/contract.js +4 -2
- package/dist/index.d.ts +10 -0
- package/dist/pressable.js +36 -0
- package/dist/primitives.js +4 -2
- package/dist/scroll-view.js +173 -0
- package/package.json +1 -1
- package/src/contract.js +4 -2
package/README.md
CHANGED
|
@@ -90,7 +90,15 @@ See the design reference for the full architecture: [`docs/architecture/widget-m
|
|
|
90
90
|
|
|
91
91
|
## Status
|
|
92
92
|
|
|
93
|
-
`v0.
|
|
93
|
+
`v0.304.0` — pre-publish. The package surface (types, function names, export paths) is the v1 contract; runtime behaviour for some hooks is stubbed (each hook documents what's wired and what isn't). It is **not yet published to npm**.
|
|
94
|
+
|
|
95
|
+
### What's new in 0.304.0 (contract 1.248.0)
|
|
96
|
+
|
|
97
|
+
**A horizontal `ScrollView` shows mouse users that it scrolls.** A card carousel or chip row in `<ScrollView horizontal showsHorizontalScrollIndicator={false}>` is fine on a phone, where you swipe, but on a computer nothing showed that it scrolls and a mouse had no easy way to scroll it, so the last card looked cut off. On the web, a horizontal `ScrollView` whose content overflows now fades the edge that has more content, and hovering it with a mouse shows previous / next arrow buttons that scroll smoothly by about one view width (instantly when the visitor prefers reduced motion). The arrows are 36px round buttons in the theme's surface, border and `onSurface` colours; they stay out of the tab order, because the row itself is focusable and scrolls with the arrow keys, and shift-wheel and trackpad scrolling work as before. A row that fits shows nothing, and the edges update as the row scrolls or its content or width changes. Touch screens on the web and the exported app are unchanged: a swipe is their affordance. It is on by default, so published widgets get it with no code change; pass `showsScrollAffordance={false}` to a widget that draws its own arrows. Vertical scrollers are unchanged. A short set of chips on a wide layout reads better wrapped in a `<ChipGroup>` than scrolled.
|
|
98
|
+
|
|
99
|
+
### What's new in 0.303.0 (contract 1.247.0)
|
|
100
|
+
|
|
101
|
+
**A card keeps its lift while the pointer is over a button inside it (web).** react-native-web ends a `Pressable`'s hover when the pointer enters a pressable nested in it, so a card styled with `pressableLift(state)` dropped back while the pointer sat on its own button. The SDK `Pressable` now reports `hovered` for as long as the pointer is anywhere inside it, as CSS `:hover` does, in both its style function and its children function. A press on the inner button still runs only that button's action, and a touch still never hovers. Native is unchanged: there is no hover there.
|
|
94
102
|
|
|
95
103
|
### What's new in 0.302.0 (contract 1.247.0)
|
|
96
104
|
|
package/dist/contract.cjs
CHANGED
|
@@ -3520,7 +3520,7 @@ const PRIMITIVES = [
|
|
|
3520
3520
|
{
|
|
3521
3521
|
name: "ScrollView",
|
|
3522
3522
|
description:
|
|
3523
|
-
"Scrollable container. Pass `horizontal` to scroll on the x-axis. See https://reactnative.dev/docs/scrollview.",
|
|
3523
|
+
"Scrollable container. Pass `horizontal` to scroll on the x-axis. On the web, a horizontal row whose content overflows shows mouse users that it scrolls: the edge with more content fades, and hovering shows previous / next arrows that scroll about one view width. Touch screens and the exported app swipe as before, and a row that fits shows nothing. Pass `showsScrollAffordance={false}` only when the widget draws its own arrows. A short set of chips is better wrapped in a `<ChipGroup>` than scrolled. See https://reactnative.dev/docs/scrollview.",
|
|
3524
3524
|
rnComponent: "ScrollView",
|
|
3525
3525
|
docsUrl: "https://reactnative.dev/docs/scrollview",
|
|
3526
3526
|
},
|
|
@@ -6915,7 +6915,9 @@ const CONTRACT = deepFreeze({
|
|
|
6915
6915
|
// 1.247.0: the four status tokens are fixed again (danger #dc2626, success
|
|
6916
6916
|
// #059669, warning #d97706, info #0284c7); hosts no longer derive them from
|
|
6917
6917
|
// the palette. `deriveStatusColors` stays exported, unused by the hosts.
|
|
6918
|
-
|
|
6918
|
+
// 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
|
|
6919
|
+
// the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
|
|
6920
|
+
version: "1.248.0",
|
|
6919
6921
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6920
6922
|
hooks: HOOKS,
|
|
6921
6923
|
primitives: PRIMITIVES,
|
package/dist/contract.js
CHANGED
|
@@ -3515,7 +3515,7 @@ const PRIMITIVES = [
|
|
|
3515
3515
|
{
|
|
3516
3516
|
name: "ScrollView",
|
|
3517
3517
|
description:
|
|
3518
|
-
"Scrollable container. Pass `horizontal` to scroll on the x-axis. See https://reactnative.dev/docs/scrollview.",
|
|
3518
|
+
"Scrollable container. Pass `horizontal` to scroll on the x-axis. On the web, a horizontal row whose content overflows shows mouse users that it scrolls: the edge with more content fades, and hovering shows previous / next arrows that scroll about one view width. Touch screens and the exported app swipe as before, and a row that fits shows nothing. Pass `showsScrollAffordance={false}` only when the widget draws its own arrows. A short set of chips is better wrapped in a `<ChipGroup>` than scrolled. See https://reactnative.dev/docs/scrollview.",
|
|
3519
3519
|
rnComponent: "ScrollView",
|
|
3520
3520
|
docsUrl: "https://reactnative.dev/docs/scrollview",
|
|
3521
3521
|
},
|
|
@@ -6910,7 +6910,9 @@ const CONTRACT = deepFreeze({
|
|
|
6910
6910
|
// 1.247.0: the four status tokens are fixed again (danger #dc2626, success
|
|
6911
6911
|
// #059669, warning #d97706, info #0284c7); hosts no longer derive them from
|
|
6912
6912
|
// the palette. `deriveStatusColors` stays exported, unused by the hosts.
|
|
6913
|
-
|
|
6913
|
+
// 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
|
|
6914
|
+
// the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
|
|
6915
|
+
version: "1.248.0",
|
|
6914
6916
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6915
6917
|
hooks: HOOKS,
|
|
6916
6918
|
primitives: PRIMITIVES,
|
package/dist/index.d.ts
CHANGED
|
@@ -4140,6 +4140,16 @@ export const Text: any;
|
|
|
4140
4140
|
export const View: any;
|
|
4141
4141
|
export const Pressable: any;
|
|
4142
4142
|
export const Image: any;
|
|
4143
|
+
/**
|
|
4144
|
+
* React Native's ScrollView, with one SDK prop:
|
|
4145
|
+
*
|
|
4146
|
+
* - `showsScrollAffordance` (boolean, default true) — on the web, a
|
|
4147
|
+
* `horizontal` scroller whose content overflows fades the edge with more
|
|
4148
|
+
* content and, on hover with a mouse, shows previous / next arrows that
|
|
4149
|
+
* scroll about one view width. Touch screens and the exported app are
|
|
4150
|
+
* unchanged; keyboard and shift-wheel scrolling keep working. Pass false
|
|
4151
|
+
* only when the widget draws its own arrows.
|
|
4152
|
+
*/
|
|
4143
4153
|
export const ScrollView: any;
|
|
4144
4154
|
export const TextInput: any;
|
|
4145
4155
|
export const FlatList: any;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
// The web `<Pressable>`: react-native-web's, with `hovered` following the
|
|
2
|
+
// pointer. The native build re-exports React Native's (./primitives.native.js),
|
|
3
|
+
// where no hover exists.
|
|
4
|
+
import React from "react";
|
|
5
|
+
import { ReactNative } from "./text-scale.js";
|
|
6
|
+
|
|
7
|
+
const Base = ReactNative.Pressable;
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* react-native-web ends a Pressable's hover when the pointer enters a Pressable
|
|
11
|
+
* nested in it. Here `hovered` stays true while the pointer is anywhere inside,
|
|
12
|
+
* as CSS `:hover` does, so a card keeps its lift over its own button.
|
|
13
|
+
*/
|
|
14
|
+
export const Pressable = React.forwardRef(function Pressable(props, ref) {
|
|
15
|
+
const { style, children, disabled, onPointerEnter, onPointerLeave } = props;
|
|
16
|
+
const [inside, setInside] = React.useState(false);
|
|
17
|
+
const withInside = (state) => ({ ...state, hovered: state.hovered || (inside && !disabled) });
|
|
18
|
+
return React.createElement(
|
|
19
|
+
Base,
|
|
20
|
+
{
|
|
21
|
+
...props,
|
|
22
|
+
ref,
|
|
23
|
+
onPointerEnter: (e) => {
|
|
24
|
+
if (e.pointerType !== "touch") setInside(true);
|
|
25
|
+
onPointerEnter?.(e);
|
|
26
|
+
},
|
|
27
|
+
onPointerLeave: (e) => {
|
|
28
|
+
setInside(false);
|
|
29
|
+
onPointerLeave?.(e);
|
|
30
|
+
},
|
|
31
|
+
style: typeof style === "function" ? (state) => style(withInside(state)) : style,
|
|
32
|
+
},
|
|
33
|
+
typeof children === "function" ? (state) => children(withInside(state)) : children,
|
|
34
|
+
);
|
|
35
|
+
});
|
|
36
|
+
Pressable.displayName = "Pressable";
|
package/dist/primitives.js
CHANGED
|
@@ -41,12 +41,14 @@
|
|
|
41
41
|
// `react-native` alias path on the web.
|
|
42
42
|
import { ReactNative } from "./text-scale.js";
|
|
43
43
|
import { makeTextInput } from "./text-input-view.js";
|
|
44
|
+
import { makeScrollView } from "./scroll-view.js";
|
|
44
45
|
|
|
45
46
|
export const Text = ReactNative.Text;
|
|
46
47
|
export const View = ReactNative.View;
|
|
47
|
-
export
|
|
48
|
+
export { Pressable } from "./pressable.js";
|
|
48
49
|
export const Image = ReactNative.Image;
|
|
49
|
-
|
|
50
|
+
// A horizontal row shows mouse users that it scrolls; see ./scroll-view.js.
|
|
51
|
+
export const ScrollView = makeScrollView(ReactNative);
|
|
50
52
|
export const TextInput = makeTextInput(ReactNative.TextInput);
|
|
51
53
|
// Additional cross-platform primitives the AI agent + handwritten
|
|
52
54
|
// widgets commonly reach for. All work in both react-native-web and
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
// The web `<ScrollView>`: react-native-web's, plus an overflow affordance for
|
|
2
|
+
// mouse users on a horizontal row. A mouse has no swipe, so a row whose
|
|
3
|
+
// scrollbar is hidden reads as cut off. Where the content overflows, the edge
|
|
4
|
+
// with more content fades out, and hovering shows previous / next arrows.
|
|
5
|
+
//
|
|
6
|
+
// Native re-exports React Native's ScrollView as is (./primitives.native.js):
|
|
7
|
+
// a swipe is the native affordance. Scrolling is the same capability on both
|
|
8
|
+
// hosts; only the input differs. Touch screens on the web are left unchanged.
|
|
9
|
+
|
|
10
|
+
import React from "react";
|
|
11
|
+
import { useHostSharedText, useHostTheme } from "./hooks.js";
|
|
12
|
+
import { DEFAULT_THEME_TOKENS } from "./_theme-tokens.js";
|
|
13
|
+
import { flattenStyle } from "./flatten-style.js";
|
|
14
|
+
import { Icon } from "./icon.js";
|
|
15
|
+
|
|
16
|
+
const h = React.createElement;
|
|
17
|
+
const FINE_POINTER = "(hover: hover) and (pointer: fine)";
|
|
18
|
+
// The smallest tap target the design findings accept.
|
|
19
|
+
export const SCROLL_ARROW_SIZE = 36;
|
|
20
|
+
export const SCROLL_FADE_PX = 32;
|
|
21
|
+
// Leaves a sliver of the last item in view, so the step reads as continuous.
|
|
22
|
+
const STEP_FRACTION = 0.9;
|
|
23
|
+
// Sub-pixel layouts leave a fraction of a pixel to scroll at either end.
|
|
24
|
+
const EDGE_SLACK_PX = 1;
|
|
25
|
+
|
|
26
|
+
// Placement keys move to the wrapper so the row sits where the author put it.
|
|
27
|
+
const OUTER_STYLE_KEYS = Object.freeze([
|
|
28
|
+
"width", "minWidth", "maxWidth", "height", "minHeight", "maxHeight", "aspectRatio",
|
|
29
|
+
"flex", "flexBasis", "flexGrow", "flexShrink", "alignSelf", "display",
|
|
30
|
+
"position", "top", "right", "bottom", "left", "start", "end", "zIndex",
|
|
31
|
+
"margin", "marginTop", "marginRight", "marginBottom", "marginLeft",
|
|
32
|
+
"marginHorizontal", "marginVertical", "marginStart", "marginEnd",
|
|
33
|
+
]);
|
|
34
|
+
|
|
35
|
+
function splitStyle(style) {
|
|
36
|
+
const outer = {};
|
|
37
|
+
const inner = {};
|
|
38
|
+
for (const [key, value] of Object.entries(flattenStyle(style))) {
|
|
39
|
+
if (value === undefined) continue;
|
|
40
|
+
(OUTER_STYLE_KEYS.includes(key) ? outer : inner)[key] = value;
|
|
41
|
+
}
|
|
42
|
+
return { outer, inner };
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
function matches(query) {
|
|
46
|
+
return typeof window !== "undefined" && typeof window.matchMedia === "function" && window.matchMedia(query).matches;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Which edges have more content: "start", "end", "both" or "none". */
|
|
50
|
+
export function overflowEdges({ scrollLeft, scrollWidth, clientWidth }) {
|
|
51
|
+
const x = Math.abs(scrollLeft);
|
|
52
|
+
const start = x > EDGE_SLACK_PX;
|
|
53
|
+
const end = scrollWidth - clientWidth - x > EDGE_SLACK_PX;
|
|
54
|
+
return start && end ? "both" : start ? "start" : end ? "end" : "none";
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/** A mask that fades the content out toward each edge with more of it. */
|
|
58
|
+
export function fadeMask(edges) {
|
|
59
|
+
if (edges === "none") return null;
|
|
60
|
+
const from = edges === "end" ? "#000" : "transparent";
|
|
61
|
+
const to = edges === "start" ? "#000" : "transparent";
|
|
62
|
+
const mask = `linear-gradient(to right, ${from} 0, #000 ${SCROLL_FADE_PX}px, #000 calc(100% - ${SCROLL_FADE_PX}px), ${to} 100%)`;
|
|
63
|
+
return { maskImage: mask, WebkitMaskImage: mask };
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function assignRef(ref, node) {
|
|
67
|
+
if (typeof ref === "function") ref(node);
|
|
68
|
+
else if (ref && typeof ref === "object") ref.current = node;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function chain(own, theirs) {
|
|
72
|
+
return (...args) => {
|
|
73
|
+
own(...args);
|
|
74
|
+
if (typeof theirs === "function") theirs(...args);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* @param {{ ScrollView: any, View: any, Pressable: any }} rn react-native-web's primitives.
|
|
80
|
+
*/
|
|
81
|
+
export function makeScrollView({ ScrollView: BaseScrollView, View, Pressable }) {
|
|
82
|
+
function Arrow({ side, label, onPress, theme }) {
|
|
83
|
+
const { colors, spacing } = theme;
|
|
84
|
+
return h(
|
|
85
|
+
Pressable,
|
|
86
|
+
{
|
|
87
|
+
accessibilityRole: "button",
|
|
88
|
+
accessibilityLabel: label,
|
|
89
|
+
// Keyboard users scroll the focused row itself; the arrows serve the mouse.
|
|
90
|
+
tabIndex: -1,
|
|
91
|
+
onPress,
|
|
92
|
+
testID: `scroll-arrow-${side}`,
|
|
93
|
+
style: {
|
|
94
|
+
position: "absolute",
|
|
95
|
+
top: "50%",
|
|
96
|
+
marginTop: -SCROLL_ARROW_SIZE / 2,
|
|
97
|
+
[side === "previous" ? "left" : "right"]: spacing.xs,
|
|
98
|
+
width: SCROLL_ARROW_SIZE,
|
|
99
|
+
height: SCROLL_ARROW_SIZE,
|
|
100
|
+
borderRadius: SCROLL_ARROW_SIZE / 2,
|
|
101
|
+
alignItems: "center",
|
|
102
|
+
justifyContent: "center",
|
|
103
|
+
backgroundColor: colors.surface,
|
|
104
|
+
borderWidth: 1,
|
|
105
|
+
borderColor: colors.border,
|
|
106
|
+
...(theme.elevation && theme.elevation.md),
|
|
107
|
+
},
|
|
108
|
+
},
|
|
109
|
+
h(Icon, { name: side === "previous" ? "chevron-left" : "chevron-right", size: 20, color: colors.onSurface }),
|
|
110
|
+
);
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
const ScrollView = React.forwardRef(function ScrollView(props, ref) {
|
|
114
|
+
const { showsScrollAffordance = true, ...rest } = props;
|
|
115
|
+
const theme = useHostTheme() || DEFAULT_THEME_TOKENS;
|
|
116
|
+
const previousLabel = useHostSharedText("previous", "Previous");
|
|
117
|
+
const nextLabel = useHostSharedText("next", "Next");
|
|
118
|
+
const [finePointer] = React.useState(() => matches(FINE_POINTER));
|
|
119
|
+
const [edges, setEdges] = React.useState("none");
|
|
120
|
+
const [hovered, setHovered] = React.useState(false);
|
|
121
|
+
const node = React.useRef(null);
|
|
122
|
+
|
|
123
|
+
const setRef = React.useCallback(
|
|
124
|
+
(value) => {
|
|
125
|
+
node.current = value;
|
|
126
|
+
assignRef(ref, value);
|
|
127
|
+
},
|
|
128
|
+
[ref],
|
|
129
|
+
);
|
|
130
|
+
// The string state bails out of re-rendering while the edges stay put.
|
|
131
|
+
const measure = React.useCallback(() => {
|
|
132
|
+
if (node.current) setEdges(overflowEdges(node.current));
|
|
133
|
+
}, []);
|
|
134
|
+
|
|
135
|
+
if (!rest.horizontal || !showsScrollAffordance || !finePointer) {
|
|
136
|
+
return h(BaseScrollView, { ...rest, ref });
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const step = (direction) => {
|
|
140
|
+
const el = node.current;
|
|
141
|
+
if (!el) return;
|
|
142
|
+
const behavior = matches("(prefers-reduced-motion: reduce)") ? "auto" : "smooth";
|
|
143
|
+
el.scrollBy({ left: direction * el.clientWidth * STEP_FRACTION, behavior });
|
|
144
|
+
};
|
|
145
|
+
const { outer, inner } = splitStyle(rest.style);
|
|
146
|
+
const showArrows = hovered && edges !== "none";
|
|
147
|
+
|
|
148
|
+
return h(
|
|
149
|
+
View,
|
|
150
|
+
{
|
|
151
|
+
style: { flexGrow: 1, flexShrink: 1, ...outer },
|
|
152
|
+
onMouseEnter: () => setHovered(true),
|
|
153
|
+
onMouseLeave: () => setHovered(false),
|
|
154
|
+
},
|
|
155
|
+
h(BaseScrollView, {
|
|
156
|
+
...rest,
|
|
157
|
+
ref: setRef,
|
|
158
|
+
style: [inner, fadeMask(edges)],
|
|
159
|
+
onLayout: chain(measure, rest.onLayout),
|
|
160
|
+
onContentSizeChange: chain(measure, rest.onContentSizeChange),
|
|
161
|
+
onScroll: chain(measure, rest.onScroll),
|
|
162
|
+
}),
|
|
163
|
+
showArrows && edges !== "end"
|
|
164
|
+
? h(Arrow, { side: "previous", label: previousLabel, onPress: () => step(-1), theme })
|
|
165
|
+
: null,
|
|
166
|
+
showArrows && edges !== "start"
|
|
167
|
+
? h(Arrow, { side: "next", label: nextLabel, onPress: () => step(1), theme })
|
|
168
|
+
: null,
|
|
169
|
+
);
|
|
170
|
+
});
|
|
171
|
+
ScrollView.displayName = "ScrollView";
|
|
172
|
+
return ScrollView;
|
|
173
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@colixsystems/widget-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.304.0",
|
|
4
4
|
"description": "Common widget interface for AppStudio. Implements WidgetManifest, WidgetContext, property schema, and helper hooks.",
|
|
5
5
|
"homepage": "https://github.com/Colix-AB/AppStudio",
|
|
6
6
|
"type": "module",
|
package/src/contract.js
CHANGED
|
@@ -3515,7 +3515,7 @@ const PRIMITIVES = [
|
|
|
3515
3515
|
{
|
|
3516
3516
|
name: "ScrollView",
|
|
3517
3517
|
description:
|
|
3518
|
-
"Scrollable container. Pass `horizontal` to scroll on the x-axis. See https://reactnative.dev/docs/scrollview.",
|
|
3518
|
+
"Scrollable container. Pass `horizontal` to scroll on the x-axis. On the web, a horizontal row whose content overflows shows mouse users that it scrolls: the edge with more content fades, and hovering shows previous / next arrows that scroll about one view width. Touch screens and the exported app swipe as before, and a row that fits shows nothing. Pass `showsScrollAffordance={false}` only when the widget draws its own arrows. A short set of chips is better wrapped in a `<ChipGroup>` than scrolled. See https://reactnative.dev/docs/scrollview.",
|
|
3519
3519
|
rnComponent: "ScrollView",
|
|
3520
3520
|
docsUrl: "https://reactnative.dev/docs/scrollview",
|
|
3521
3521
|
},
|
|
@@ -6910,7 +6910,9 @@ const CONTRACT = deepFreeze({
|
|
|
6910
6910
|
// 1.247.0: the four status tokens are fixed again (danger #dc2626, success
|
|
6911
6911
|
// #059669, warning #d97706, info #0284c7); hosts no longer derive them from
|
|
6912
6912
|
// the palette. `deriveStatusColors` stays exported, unused by the hosts.
|
|
6913
|
-
|
|
6913
|
+
// 1.248.0: additive — a horizontal `ScrollView` shows a scroll affordance on
|
|
6914
|
+
// the web for pointer devices when it overflows; `showsScrollAffordance` turns it off.
|
|
6915
|
+
version: "1.248.0",
|
|
6914
6916
|
sharedTranslationKeys: SHARED_TRANSLATION_KEYS,
|
|
6915
6917
|
hooks: HOOKS,
|
|
6916
6918
|
primitives: PRIMITIVES,
|