@g9tm/lynxcontrols 1.4.7 → 1.5.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/dist/.tsbuildinfo +1 -1
- package/dist/anchor/context.d.ts +15 -0
- package/dist/anchor/context.d.ts.map +1 -0
- package/dist/anchor/context.jsx +10 -0
- package/dist/anchor/context.jsx.map +1 -0
- package/dist/anchor/hooks.d.ts +72 -0
- package/dist/anchor/hooks.d.ts.map +1 -0
- package/dist/anchor/hooks.jsx +147 -0
- package/dist/anchor/hooks.jsx.map +1 -0
- package/dist/anchor/index.d.ts +6 -0
- package/dist/anchor/index.d.ts.map +1 -0
- package/dist/anchor/index.jsx +5 -0
- package/dist/anchor/measure.d.ts +22 -0
- package/dist/anchor/measure.d.ts.map +1 -0
- package/dist/anchor/measure.jsx +110 -0
- package/dist/anchor/measure.jsx.map +1 -0
- package/dist/anchor/registry.d.ts +108 -0
- package/dist/anchor/registry.d.ts.map +1 -0
- package/dist/anchor/registry.jsx +142 -0
- package/dist/anchor/registry.jsx.map +1 -0
- package/dist/anchor/scroll.d.ts +34 -0
- package/dist/anchor/scroll.d.ts.map +1 -0
- package/dist/anchor/scroll.jsx +255 -0
- package/dist/anchor/scroll.jsx.map +1 -0
- package/dist/base/control.d.ts +10 -3
- package/dist/base/control.d.ts.map +1 -1
- package/dist/base/control.jsx +17 -2
- package/dist/base/control.jsx.map +1 -1
- package/dist/base/index.d.ts +1 -1
- package/dist/base/index.d.ts.map +1 -1
- package/dist/base/index.jsx +1 -1
- package/dist/base/pressable.d.ts.map +1 -1
- package/dist/base/pressable.jsx +7 -1
- package/dist/base/pressable.jsx.map +1 -1
- package/dist/base/selection-item.d.ts +9 -1
- package/dist/base/selection-item.d.ts.map +1 -1
- package/dist/base/selection-item.jsx +10 -1
- package/dist/base/selection-item.jsx.map +1 -1
- package/dist/button/button.css +20 -0
- package/dist/button/button.css.map +1 -1
- package/dist/button/button.d.ts.map +1 -1
- package/dist/button/button.jsx +11 -1
- package/dist/button/button.jsx.map +1 -1
- package/dist/button/header-action-button.d.ts +5 -0
- package/dist/button/header-action-button.d.ts.map +1 -1
- package/dist/button/header-action-button.jsx +16 -2
- package/dist/button/header-action-button.jsx.map +1 -1
- package/dist/button/icon-button.d.ts.map +1 -1
- package/dist/button/icon-button.jsx +11 -1
- package/dist/button/icon-button.jsx.map +1 -1
- package/dist/button/nav-card.d.ts.map +1 -1
- package/dist/button/nav-card.jsx +10 -1
- package/dist/button/nav-card.jsx.map +1 -1
- package/dist/button/vertical-icon-text-button.d.ts.map +1 -1
- package/dist/button/vertical-icon-text-button.jsx +10 -1
- package/dist/button/vertical-icon-text-button.jsx.map +1 -1
- package/dist/button/visuals.d.ts.map +1 -1
- package/dist/button/visuals.jsx +1 -1
- package/dist/button/visuals.jsx.map +1 -1
- package/dist/expander/expander.d.ts.map +1 -1
- package/dist/expander/expander.jsx +14 -1
- package/dist/expander/expander.jsx.map +1 -1
- package/dist/fields/editor.d.ts.map +1 -1
- package/dist/fields/editor.jsx +18 -2
- package/dist/fields/editor.jsx.map +1 -1
- package/dist/fields/fields.css +21 -0
- package/dist/fields/fields.css.map +1 -1
- package/dist/fields/index.d.ts +1 -1
- package/dist/fields/index.d.ts.map +1 -1
- package/dist/fields/index.jsx +1 -1
- package/dist/fields/outlined-field.d.ts +33 -1
- package/dist/fields/outlined-field.d.ts.map +1 -1
- package/dist/fields/outlined-field.jsx +43 -5
- package/dist/fields/outlined-field.jsx.map +1 -1
- package/dist/fields/text-entry.d.ts.map +1 -1
- package/dist/fields/text-entry.jsx +18 -2
- package/dist/fields/text-entry.jsx.map +1 -1
- package/dist/guide/guide.css +453 -0
- package/dist/guide/guide.css.map +1 -0
- package/dist/guide/index.d.ts +5 -0
- package/dist/guide/index.d.ts.map +1 -0
- package/dist/guide/index.jsx +4 -0
- package/dist/guide/journey.d.ts +46 -0
- package/dist/guide/journey.d.ts.map +1 -0
- package/dist/guide/journey.jsx +464 -0
- package/dist/guide/journey.jsx.map +1 -0
- package/dist/guide/placement.d.ts +44 -0
- package/dist/guide/placement.d.ts.map +1 -0
- package/dist/guide/placement.jsx +119 -0
- package/dist/guide/placement.jsx.map +1 -0
- package/dist/guide/service.d.ts +85 -0
- package/dist/guide/service.d.ts.map +1 -0
- package/dist/guide/service.jsx +620 -0
- package/dist/guide/service.jsx.map +1 -0
- package/dist/guide/settings.d.ts +50 -0
- package/dist/guide/settings.d.ts.map +1 -0
- package/dist/guide/settings.jsx +60 -0
- package/dist/guide/settings.jsx.map +1 -0
- package/dist/host/host.d.ts +5 -1
- package/dist/host/host.d.ts.map +1 -1
- package/dist/host/host.jsx +12 -0
- package/dist/host/host.jsx.map +1 -1
- package/dist/host/layers.d.ts +3 -1
- package/dist/host/layers.d.ts.map +1 -1
- package/dist/host/layers.jsx +4 -2
- package/dist/host/layers.jsx.map +1 -1
- package/dist/host/registry.d.ts +3 -0
- package/dist/host/registry.d.ts.map +1 -1
- package/dist/host/registry.jsx.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/pickers/combo-box.d.ts +8 -0
- package/dist/pickers/combo-box.d.ts.map +1 -1
- package/dist/pickers/combo-box.jsx +51 -9
- package/dist/pickers/combo-box.jsx.map +1 -1
- package/dist/pickers/date-time-picker.d.ts +2 -2
- package/dist/pickers/date-time-picker.d.ts.map +1 -1
- package/dist/pickers/date-time-picker.jsx +4 -3
- package/dist/pickers/date-time-picker.jsx.map +1 -1
- package/dist/pickers/date-time.d.ts +5 -2
- package/dist/pickers/date-time.d.ts.map +1 -1
- package/dist/pickers/date-time.jsx +1 -1
- package/dist/pickers/date-time.jsx.map +1 -1
- package/dist/pickers/picker-sheet.d.ts +6 -2
- package/dist/pickers/picker-sheet.d.ts.map +1 -1
- package/dist/pickers/picker-sheet.jsx +2 -3
- package/dist/pickers/picker-sheet.jsx.map +1 -1
- package/dist/pickers/picker.d.ts.map +1 -1
- package/dist/pickers/picker.jsx +3 -2
- package/dist/pickers/picker.jsx.map +1 -1
- package/dist/pickers/pickers.css +27 -0
- package/dist/pickers/pickers.css.map +1 -1
- package/dist/pickers/timespan-picker.d.ts.map +1 -1
- package/dist/pickers/timespan-picker.jsx +3 -2
- package/dist/pickers/timespan-picker.jsx.map +1 -1
- package/dist/pickers/trigger.d.ts +3 -1
- package/dist/pickers/trigger.d.ts.map +1 -1
- package/dist/pickers/trigger.jsx +6 -1
- package/dist/pickers/trigger.jsx.map +1 -1
- package/dist/provider/contexts.d.ts +3 -0
- package/dist/provider/contexts.d.ts.map +1 -1
- package/dist/provider/contexts.jsx.map +1 -1
- package/dist/provider/provider.d.ts.map +1 -1
- package/dist/provider/provider.jsx +24 -17
- package/dist/provider/provider.jsx.map +1 -1
- package/dist/provider/settings.d.ts +16 -0
- package/dist/provider/settings.d.ts.map +1 -1
- package/dist/provider/settings.jsx +7 -3
- package/dist/provider/settings.jsx.map +1 -1
- package/dist/provider/theme.css +4 -0
- package/dist/provider/theme.css.map +1 -1
- package/dist/range-slider/math.d.ts +14 -4
- package/dist/range-slider/math.d.ts.map +1 -1
- package/dist/range-slider/math.jsx +16 -4
- package/dist/range-slider/math.jsx.map +1 -1
- package/dist/range-slider/range-slider.css +17 -0
- package/dist/range-slider/range-slider.css.map +1 -1
- package/dist/range-slider/range-slider.d.ts +11 -0
- package/dist/range-slider/range-slider.d.ts.map +1 -1
- package/dist/range-slider/range-slider.jsx +35 -13
- package/dist/range-slider/range-slider.jsx.map +1 -1
- package/dist/route/hooks.d.ts +34 -0
- package/dist/route/hooks.d.ts.map +1 -0
- package/dist/route/hooks.jsx +147 -0
- package/dist/route/hooks.jsx.map +1 -0
- package/dist/route/index.d.ts +3 -0
- package/dist/route/index.d.ts.map +1 -0
- package/dist/route/index.jsx +2 -0
- package/dist/route/router.d.ts +201 -0
- package/dist/route/router.d.ts.map +1 -0
- package/dist/route/router.jsx +810 -0
- package/dist/route/router.jsx.map +1 -0
- package/dist/selection/index.d.ts +2 -1
- package/dist/selection/index.d.ts.map +1 -1
- package/dist/selection/index.jsx +2 -1
- package/dist/selection/selection-sheet.d.ts +3 -1
- package/dist/selection/selection-sheet.d.ts.map +1 -1
- package/dist/selection/selection-sheet.jsx +57 -8
- package/dist/selection/selection-sheet.jsx.map +1 -1
- package/dist/selection/selection.css +7 -0
- package/dist/selection/selection.css.map +1 -1
- package/dist/selection/window.d.ts +29 -0
- package/dist/selection/window.d.ts.map +1 -0
- package/dist/selection/window.jsx +24 -0
- package/dist/selection/window.jsx.map +1 -0
- package/dist/sheet/frame.d.ts +3 -1
- package/dist/sheet/frame.d.ts.map +1 -1
- package/dist/sheet/frame.jsx +72 -26
- package/dist/sheet/frame.jsx.map +1 -1
- package/dist/sheet/header.d.ts.map +1 -1
- package/dist/sheet/header.jsx +3 -1
- package/dist/sheet/header.jsx.map +1 -1
- package/dist/sheet/index.d.ts +1 -1
- package/dist/sheet/index.d.ts.map +1 -1
- package/dist/sheet/index.jsx +1 -1
- package/dist/sheet/options.d.ts +30 -0
- package/dist/sheet/options.d.ts.map +1 -1
- package/dist/sheet/options.jsx +2 -1
- package/dist/sheet/options.jsx.map +1 -1
- package/dist/sheet/service.d.ts +13 -0
- package/dist/sheet/service.d.ts.map +1 -1
- package/dist/sheet/service.jsx +27 -4
- package/dist/sheet/service.jsx.map +1 -1
- package/dist/sheet/sheet.css +9 -0
- package/dist/sheet/sheet.css.map +1 -1
- package/dist/sheet/sizing.d.ts +2 -0
- package/dist/sheet/sizing.d.ts.map +1 -1
- package/dist/sheet/sizing.jsx +2 -1
- package/dist/sheet/sizing.jsx.map +1 -1
- package/dist/tabs/tab-view.d.ts +14 -0
- package/dist/tabs/tab-view.d.ts.map +1 -1
- package/dist/tabs/tab-view.jsx +59 -3
- package/dist/tabs/tab-view.jsx.map +1 -1
- package/dist/toggle/checkbox.d.ts.map +1 -1
- package/dist/toggle/checkbox.jsx +15 -1
- package/dist/toggle/checkbox.jsx.map +1 -1
- package/dist/toggle/chip-group.d.ts +9 -1
- package/dist/toggle/chip-group.d.ts.map +1 -1
- package/dist/toggle/chip-group.jsx +63 -13
- package/dist/toggle/chip-group.jsx.map +1 -1
- package/dist/toggle/switch.d.ts +1 -1
- package/dist/toggle/switch.d.ts.map +1 -1
- package/dist/toggle/switch.jsx +18 -3
- package/dist/toggle/switch.jsx.map +1 -1
- package/dist/toggle/toggle.css +20 -0
- package/dist/toggle/toggle.css.map +1 -1
- package/package.json +17 -2
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor/context.jsx","sources":["../../src/anchor/context.ts"],"sourcesContent":["import { createContext } from '@lynx-js/react';\nimport type { G9AnchorRegistry } from './registry';\n\n/** The provider's anchor registry (`G9Provider` supplies it). */\nexport const G9AnchorRegistryContext = createContext<G9AnchorRegistry | null>(null);\n\n/** The scroller the anchors below sit in. */\nexport const G9ScrollerContext = createContext<string | null>(null);\n\n/** Which overlay layer the anchors below render in (a sheet supplies `sheet` and its handle id). */\nexport interface G9AnchorLayerValue {\n readonly layer: 'page' | 'sheet' | 'popup' | 'floating';\n readonly sheetId?: number;\n}\n\n/** The default layer: the page itself. */\nexport const g9PageAnchorLayer: G9AnchorLayerValue = Object.freeze({ layer: 'page' });\n\n/** The overlay layer the anchors below render in (a sheet provides `sheet` with its handle id). */\nexport const G9AnchorLayerContext = createContext<G9AnchorLayerValue>(g9PageAnchorLayer);\n"],"names":["G9AnchorRegistryContext","createContext","G9ScrollerContext","g9PageAnchorLayer","Object","G9AnchorLayerContext"],"mappings":";AAIO,MAAMA,0BAA0BC,cAAuC;AAGvE,MAAMC,oBAAoBD,cAA6B;AASvD,MAAME,oBAAwCC,OAAO,MAAM,CAAC;IAAE,OAAO;AAAO;AAG5E,MAAMC,uBAAuBJ,cAAkCE"}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
import { type ReactNode } from '@lynx-js/react';
|
|
2
|
+
import type { NodesRef } from '@lynx-js/types';
|
|
3
|
+
import type { G9AnchorInfo, G9AnchorKind, G9AnchorRegistry } from './registry.js';
|
|
4
|
+
/** A callback ref of a Lynx element. */
|
|
5
|
+
export type G9AnchorRef = (node: NodesRef | null) => void;
|
|
6
|
+
/** An element id a selector can address: every character outside [A-Za-z0-9_-] becomes `_` (a selector reads `.` as a class). */
|
|
7
|
+
export declare function g9AnchorDomId(id: string): string;
|
|
8
|
+
/** The provider's anchor registry, or null outside a provider. */
|
|
9
|
+
export declare function useG9AnchorRegistry(): G9AnchorRegistry | null;
|
|
10
|
+
/** What {@link useG9Anchor} returns. */
|
|
11
|
+
export interface G9AnchorHandle {
|
|
12
|
+
/** Spread onto the element: its `id` (selector-safe) and the `ref` that binds it. */
|
|
13
|
+
readonly props: {
|
|
14
|
+
readonly id?: string;
|
|
15
|
+
readonly ref: G9AnchorRef;
|
|
16
|
+
};
|
|
17
|
+
readonly ref: G9AnchorRef;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Registers the element as an anchor while mounted (no id = nothing is registered). `info` may change every render:
|
|
21
|
+
* the registry reads the latest. Pass the element's own `ref` in `options.ref` when it has one; both are called.
|
|
22
|
+
*/
|
|
23
|
+
export declare function useG9Anchor(id: string | null | undefined, info: G9AnchorInfo, options?: {
|
|
24
|
+
readonly ref?: G9AnchorRef;
|
|
25
|
+
readonly domId?: string;
|
|
26
|
+
}): G9AnchorHandle;
|
|
27
|
+
/** Props of {@link G9Anchor}. */
|
|
28
|
+
export interface G9AnchorProps extends Omit<G9AnchorInfo, 'kind'> {
|
|
29
|
+
readonly id: string;
|
|
30
|
+
readonly kind?: G9AnchorKind;
|
|
31
|
+
readonly children?: ReactNode;
|
|
32
|
+
readonly className?: string;
|
|
33
|
+
readonly style?: Record<string, string | number>;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Makes any part of a page an anchor: a layout-neutral wrapper (a flex column unless a class is given) that carries
|
|
37
|
+
* the id. Prefer {@link useG9Anchor} on the element itself when there is one.
|
|
38
|
+
*/
|
|
39
|
+
export declare function G9Anchor(props: G9AnchorProps): ReactNode;
|
|
40
|
+
/** Options of {@link useG9Scroller}. */
|
|
41
|
+
export interface G9ScrollerOptions {
|
|
42
|
+
readonly id: string;
|
|
43
|
+
readonly kind: 'list' | 'scroll-view';
|
|
44
|
+
readonly orientation?: 'vertical' | 'horizontal';
|
|
45
|
+
/** A list: its item keys in order (the same strings as `item-key`). */
|
|
46
|
+
readonly itemKeys?: () => readonly string[];
|
|
47
|
+
/** A list: the anchor id of the row with a key. */
|
|
48
|
+
readonly itemAnchor?: (key: string) => string;
|
|
49
|
+
/** A list: the key of a row anchor id, or null. Default: the inverse of a prefix `itemAnchor` (`Prefix.<key>`). */
|
|
50
|
+
readonly anchorKey?: (anchorId: string) => string | null;
|
|
51
|
+
}
|
|
52
|
+
/** What {@link useG9Scroller} returns. */
|
|
53
|
+
export interface G9ScrollerHandle {
|
|
54
|
+
readonly id: string;
|
|
55
|
+
/** Spread onto the `<list>` / `<scroll-view>`. */
|
|
56
|
+
readonly props: {
|
|
57
|
+
readonly id: string;
|
|
58
|
+
readonly ref: G9AnchorRef;
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Registers a scroll container, so a scroll position can be named by the control in view (never pixels) and a control
|
|
63
|
+
* inside it can be brought into view — also a list row that is not mounted yet, by its item key. Anchors below
|
|
64
|
+
* {@link G9ScrollerScope} (or a list's rows named by `itemAnchor`) count as inside it.
|
|
65
|
+
*/
|
|
66
|
+
export declare function useG9Scroller(options: G9ScrollerOptions): G9ScrollerHandle;
|
|
67
|
+
/** The anchors below sit in scroller `id` (renders no element). */
|
|
68
|
+
export declare function G9ScrollerScope(props: {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly children?: ReactNode;
|
|
71
|
+
}): ReactNode;
|
|
72
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../src/anchor/hooks.tsx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|
|
2
|
+
import { G9AnchorLayerContext, G9AnchorRegistryContext, G9ScrollerContext } from "./context.jsx";
|
|
3
|
+
function g9AnchorDomId(id) {
|
|
4
|
+
return id.replace(/[^A-Za-z0-9_-]/g, '_');
|
|
5
|
+
}
|
|
6
|
+
function useG9AnchorRegistry() {
|
|
7
|
+
return useContext(G9AnchorRegistryContext);
|
|
8
|
+
}
|
|
9
|
+
function useG9Anchor(id, info, options = {}) {
|
|
10
|
+
var _options_domId;
|
|
11
|
+
const registry = useContext(G9AnchorRegistryContext);
|
|
12
|
+
const scrollerId = useContext(G9ScrollerContext);
|
|
13
|
+
const layer = useContext(G9AnchorLayerContext);
|
|
14
|
+
const latest = useRef(info);
|
|
15
|
+
latest.current = info;
|
|
16
|
+
const node = useRef(null);
|
|
17
|
+
const external = useRef(options.ref);
|
|
18
|
+
external.current = options.ref;
|
|
19
|
+
const [ref] = useState(()=>{
|
|
20
|
+
const bind = (n)=>{
|
|
21
|
+
var _external_current;
|
|
22
|
+
node.current = n;
|
|
23
|
+
null == (_external_current = external.current) || _external_current.call(external, n);
|
|
24
|
+
};
|
|
25
|
+
return bind;
|
|
26
|
+
});
|
|
27
|
+
useEffect(()=>{
|
|
28
|
+
if (!registry || !id) return;
|
|
29
|
+
return registry.register(id, ()=>latest.current, {
|
|
30
|
+
node: ()=>node.current,
|
|
31
|
+
scrollerId,
|
|
32
|
+
layer: layer.layer,
|
|
33
|
+
...void 0 !== layer.sheetId ? {
|
|
34
|
+
sheetId: layer.sheetId
|
|
35
|
+
} : {}
|
|
36
|
+
});
|
|
37
|
+
}, [
|
|
38
|
+
registry,
|
|
39
|
+
id,
|
|
40
|
+
scrollerId,
|
|
41
|
+
layer
|
|
42
|
+
]);
|
|
43
|
+
return {
|
|
44
|
+
props: id ? {
|
|
45
|
+
id: null != (_options_domId = options.domId) ? _options_domId : g9AnchorDomId(id),
|
|
46
|
+
ref
|
|
47
|
+
} : {
|
|
48
|
+
ref
|
|
49
|
+
},
|
|
50
|
+
ref
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
function G9Anchor(props) {
|
|
54
|
+
const { id, kind = 'view', children, className, style, ...rest } = props;
|
|
55
|
+
const anchor = useG9Anchor(id, {
|
|
56
|
+
kind,
|
|
57
|
+
...rest
|
|
58
|
+
});
|
|
59
|
+
const layout = className ? style : {
|
|
60
|
+
display: 'flex',
|
|
61
|
+
flexDirection: 'column',
|
|
62
|
+
...style
|
|
63
|
+
};
|
|
64
|
+
return <view {...anchor.props} {...className ? {
|
|
65
|
+
className
|
|
66
|
+
} : {}} {...layout ? {
|
|
67
|
+
style: layout
|
|
68
|
+
} : {}}>
|
|
69
|
+
{children}
|
|
70
|
+
</view>;
|
|
71
|
+
}
|
|
72
|
+
function prefixInverse(itemAnchor) {
|
|
73
|
+
const probe = itemAnchor('\u0001');
|
|
74
|
+
const at = probe.indexOf('\u0001');
|
|
75
|
+
if (at < 0) return ()=>null;
|
|
76
|
+
const prefix = probe.slice(0, at);
|
|
77
|
+
const suffix = probe.slice(at + 1);
|
|
78
|
+
return (anchorId)=>{
|
|
79
|
+
if (anchorId.length <= prefix.length + suffix.length || anchorId.slice(0, prefix.length) !== prefix) return null;
|
|
80
|
+
if (suffix && anchorId.slice(-suffix.length) !== suffix) return null;
|
|
81
|
+
return anchorId.slice(prefix.length, anchorId.length - suffix.length);
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
function useG9Scroller(options) {
|
|
85
|
+
var _options_orientation;
|
|
86
|
+
const registry = useContext(G9AnchorRegistryContext);
|
|
87
|
+
const parentId = useContext(G9ScrollerContext);
|
|
88
|
+
const latest = useRef(options);
|
|
89
|
+
latest.current = options;
|
|
90
|
+
const node = useRef(null);
|
|
91
|
+
const [ref] = useState(()=>{
|
|
92
|
+
const bind = (n)=>{
|
|
93
|
+
node.current = n;
|
|
94
|
+
};
|
|
95
|
+
return bind;
|
|
96
|
+
});
|
|
97
|
+
const { id, kind } = options;
|
|
98
|
+
const orientation = null != (_options_orientation = options.orientation) ? _options_orientation : 'vertical';
|
|
99
|
+
const hasItems = !!options.itemKeys;
|
|
100
|
+
const hasAnchor = !!options.itemAnchor;
|
|
101
|
+
useEffect(()=>{
|
|
102
|
+
if (!registry) return;
|
|
103
|
+
const spec = {
|
|
104
|
+
id,
|
|
105
|
+
kind,
|
|
106
|
+
orientation,
|
|
107
|
+
parentId: parentId === id ? null : parentId,
|
|
108
|
+
node: ()=>node.current,
|
|
109
|
+
...hasItems ? {
|
|
110
|
+
itemKeys: ()=>{
|
|
111
|
+
var _ref;
|
|
112
|
+
var _latest_current_itemKeys, _latest_current;
|
|
113
|
+
return null != (_ref = null == (_latest_current_itemKeys = (_latest_current = latest.current).itemKeys) ? void 0 : _latest_current_itemKeys.call(_latest_current)) ? _ref : [];
|
|
114
|
+
}
|
|
115
|
+
} : {},
|
|
116
|
+
...hasAnchor ? {
|
|
117
|
+
itemAnchor: (key)=>latest.current.itemAnchor(key),
|
|
118
|
+
anchorKey: (anchorId)=>{
|
|
119
|
+
var _latest_current_anchorKey;
|
|
120
|
+
return (null != (_latest_current_anchorKey = latest.current.anchorKey) ? _latest_current_anchorKey : prefixInverse(latest.current.itemAnchor))(anchorId);
|
|
121
|
+
}
|
|
122
|
+
} : {}
|
|
123
|
+
};
|
|
124
|
+
return registry.registerScroller(spec);
|
|
125
|
+
}, [
|
|
126
|
+
registry,
|
|
127
|
+
id,
|
|
128
|
+
kind,
|
|
129
|
+
orientation,
|
|
130
|
+
parentId,
|
|
131
|
+
hasItems,
|
|
132
|
+
hasAnchor
|
|
133
|
+
]);
|
|
134
|
+
return {
|
|
135
|
+
id,
|
|
136
|
+
props: {
|
|
137
|
+
id: g9AnchorDomId(id),
|
|
138
|
+
ref
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
|
+
function G9ScrollerScope(props) {
|
|
143
|
+
return <G9ScrollerContext.Provider value={props.id}>{props.children}</G9ScrollerContext.Provider>;
|
|
144
|
+
}
|
|
145
|
+
export { G9Anchor, G9ScrollerScope, g9AnchorDomId, useG9Anchor, useG9AnchorRegistry, useG9Scroller };
|
|
146
|
+
|
|
147
|
+
//# sourceMappingURL=hooks.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor/hooks.jsx","sources":["../../src/anchor/hooks.tsx"],"sourcesContent":["import { type ReactNode, useContext, useEffect, useRef, useState } from '@lynx-js/react';\nimport type { NodesRef } from '@lynx-js/types';\nimport { G9AnchorLayerContext, G9AnchorRegistryContext, G9ScrollerContext } from './context';\nimport type { G9AnchorInfo, G9AnchorKind, G9AnchorRegistry, G9ScrollerSpec } from './registry';\n\n/** A callback ref of a Lynx element. */\nexport type G9AnchorRef = (node: NodesRef | null) => void;\n\n/** An element id a selector can address: every character outside [A-Za-z0-9_-] becomes `_` (a selector reads `.` as a class). */\nexport function g9AnchorDomId(id: string): string {\n return id.replace(/[^A-Za-z0-9_-]/g, '_');\n}\n\n/** The provider's anchor registry, or null outside a provider. */\nexport function useG9AnchorRegistry(): G9AnchorRegistry | null {\n return useContext(G9AnchorRegistryContext);\n}\n\n/** What {@link useG9Anchor} returns. */\nexport interface G9AnchorHandle {\n /** Spread onto the element: its `id` (selector-safe) and the `ref` that binds it. */\n readonly props: { readonly id?: string; readonly ref: G9AnchorRef };\n readonly ref: G9AnchorRef;\n}\n\n/**\n * Registers the element as an anchor while mounted (no id = nothing is registered). `info` may change every render:\n * the registry reads the latest. Pass the element's own `ref` in `options.ref` when it has one; both are called.\n */\nexport function useG9Anchor(\n id: string | null | undefined,\n info: G9AnchorInfo,\n options: { readonly ref?: G9AnchorRef; readonly domId?: string } = {},\n): G9AnchorHandle {\n const registry = useContext(G9AnchorRegistryContext);\n const scrollerId = useContext(G9ScrollerContext);\n const layer = useContext(G9AnchorLayerContext);\n const latest = useRef(info);\n latest.current = info;\n const node = useRef<NodesRef | null>(null);\n const external = useRef(options.ref);\n external.current = options.ref;\n const [ref] = useState(() => {\n const bind: G9AnchorRef = (n) => {\n node.current = n;\n external.current?.(n);\n };\n return bind;\n });\n useEffect(() => {\n if (!registry || !id) return undefined;\n return registry.register(id, () => latest.current, {\n node: () => node.current,\n scrollerId,\n layer: layer.layer,\n ...(layer.sheetId !== undefined ? { sheetId: layer.sheetId } : {}),\n });\n }, [registry, id, scrollerId, layer]);\n return { props: id ? { id: options.domId ?? g9AnchorDomId(id), ref } : { ref }, ref };\n}\n\n/** Props of {@link G9Anchor}. */\nexport interface G9AnchorProps extends Omit<G9AnchorInfo, 'kind'> {\n readonly id: string;\n readonly kind?: G9AnchorKind;\n readonly children?: ReactNode;\n readonly className?: string;\n readonly style?: Record<string, string | number>;\n}\n\n/**\n * Makes any part of a page an anchor: a layout-neutral wrapper (a flex column unless a class is given) that carries\n * the id. Prefer {@link useG9Anchor} on the element itself when there is one.\n */\nexport function G9Anchor(props: G9AnchorProps): ReactNode {\n const { id, kind = 'view', children, className, style, ...rest } = props;\n const anchor = useG9Anchor(id, { kind, ...rest });\n const layout = className ? style : { display: 'flex', flexDirection: 'column', ...style };\n return (\n <view {...anchor.props} {...(className ? { className } : {})} {...(layout ? { style: layout } : {})}>\n {children}\n </view>\n );\n}\n\n/** Options of {@link useG9Scroller}. */\nexport interface G9ScrollerOptions {\n readonly id: string;\n readonly kind: 'list' | 'scroll-view';\n readonly orientation?: 'vertical' | 'horizontal';\n /** A list: its item keys in order (the same strings as `item-key`). */\n readonly itemKeys?: () => readonly string[];\n /** A list: the anchor id of the row with a key. */\n readonly itemAnchor?: (key: string) => string;\n /** A list: the key of a row anchor id, or null. Default: the inverse of a prefix `itemAnchor` (`Prefix.<key>`). */\n readonly anchorKey?: (anchorId: string) => string | null;\n}\n\n/** What {@link useG9Scroller} returns. */\nexport interface G9ScrollerHandle {\n readonly id: string;\n /** Spread onto the `<list>` / `<scroll-view>`. */\n readonly props: { readonly id: string; readonly ref: G9AnchorRef };\n}\n\nfunction prefixInverse(itemAnchor: (key: string) => string): (anchorId: string) => string | null {\n const probe = itemAnchor('\\u0001');\n const at = probe.indexOf('\\u0001');\n if (at < 0) return () => null;\n const prefix = probe.slice(0, at);\n const suffix = probe.slice(at + 1);\n return (anchorId) => {\n if (anchorId.length <= prefix.length + suffix.length || anchorId.slice(0, prefix.length) !== prefix) return null;\n if (suffix && anchorId.slice(-suffix.length) !== suffix) return null;\n return anchorId.slice(prefix.length, anchorId.length - suffix.length);\n };\n}\n\n/**\n * Registers a scroll container, so a scroll position can be named by the control in view (never pixels) and a control\n * inside it can be brought into view — also a list row that is not mounted yet, by its item key. Anchors below\n * {@link G9ScrollerScope} (or a list's rows named by `itemAnchor`) count as inside it.\n */\nexport function useG9Scroller(options: G9ScrollerOptions): G9ScrollerHandle {\n const registry = useContext(G9AnchorRegistryContext);\n const parentId = useContext(G9ScrollerContext);\n const latest = useRef(options);\n latest.current = options;\n const node = useRef<NodesRef | null>(null);\n const [ref] = useState(() => {\n const bind: G9AnchorRef = (n) => {\n node.current = n;\n };\n return bind;\n });\n const { id, kind } = options;\n const orientation = options.orientation ?? 'vertical';\n const hasItems = !!options.itemKeys;\n const hasAnchor = !!options.itemAnchor;\n useEffect(() => {\n if (!registry) return undefined;\n const spec: G9ScrollerSpec = {\n id,\n kind,\n orientation,\n parentId: parentId === id ? null : parentId,\n node: () => node.current,\n ...(hasItems ? { itemKeys: () => latest.current.itemKeys?.() ?? [] } : {}),\n ...(hasAnchor\n ? {\n itemAnchor: (key: string) => (latest.current.itemAnchor as (k: string) => string)(key),\n anchorKey: (anchorId: string) =>\n (latest.current.anchorKey ?? prefixInverse(latest.current.itemAnchor as (k: string) => string))(anchorId),\n }\n : {}),\n };\n return registry.registerScroller(spec);\n }, [registry, id, kind, orientation, parentId, hasItems, hasAnchor]);\n return { id, props: { id: g9AnchorDomId(id), ref } };\n}\n\n/** The anchors below sit in scroller `id` (renders no element). */\nexport function G9ScrollerScope(props: { readonly id: string; readonly children?: ReactNode }): ReactNode {\n return <G9ScrollerContext.Provider value={props.id}>{props.children}</G9ScrollerContext.Provider>;\n}\n"],"names":["g9AnchorDomId","id","useG9AnchorRegistry","useContext","G9AnchorRegistryContext","useG9Anchor","info","options","_options_domId","registry","scrollerId","G9ScrollerContext","layer","G9AnchorLayerContext","latest","useRef","node","external","ref","useState","bind","n","useEffect","undefined","G9Anchor","props","kind","children","className","style","rest","anchor","layout","view","prefixInverse","itemAnchor","probe","at","prefix","suffix","anchorId","useG9Scroller","_options_orientation","parentId","orientation","hasItems","hasAnchor","spec","_latest_current","key","_latest_current_anchorKey","G9ScrollerScope"],"mappings":";;AASO,SAASA,cAAcC,EAAU;IACtC,OAAOA,GAAG,OAAO,CAAC,mBAAmB;AACvC;AAGO,SAASC;IACd,OAAOC,WAAWC;AACpB;AAaO,SAASC,YACdJ,EAA6B,EAC7BK,IAAkB,EAClBC,UAAmE,CAAC,CAAC;QA0B1CC;IAxB3B,MAAMC,WAAWN,WAAWC;IAC5B,MAAMM,aAAaP,WAAWQ;IAC9B,MAAMC,QAAQT,WAAWU;IACzB,MAAMC,SAASC,OAAOT;IACtBQ,OAAO,OAAO,GAAGR;IACjB,MAAMU,OAAOD,OAAwB;IACrC,MAAME,WAAWF,OAAOR,QAAQ,GAAG;IACnCU,SAAS,OAAO,GAAGV,QAAQ,GAAG;IAC9B,MAAM,CAACW,IAAI,GAAGC,SAAS;QACrB,MAAMC,OAAoB,CAACC;gBAEzBJ;YADAD,KAAK,OAAO,GAAGK;oBACfJ,CAAAA,oBAAAA,SAAS,OAAO,AAAD,KAAfA,kBAAAA,IAAAA,CAAAA,UAAmBI;QACrB;QACA,OAAOD;IACT;IACAE,UAAU;QACR,IAAI,CAACb,YAAY,CAACR,IAAI;QACtB,OAAOQ,SAAS,QAAQ,CAACR,IAAI,IAAMa,OAAO,OAAO,EAAE;YACjD,MAAM,IAAME,KAAK,OAAO;YACxBN;YACA,OAAOE,MAAM,KAAK;YAClB,GAAIA,AAAkBW,WAAlBX,MAAM,OAAO,GAAiB;gBAAE,SAASA,MAAM,OAAO;YAAC,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C;QAAUR;QAAIyB;QAAMkB;QAAaD;QAAUE;QAAUC;KAAU;IACnE,OAAO;QAAE7C;QAAI,OAAO;YAAE,IAAID,cAAcC;YAAKiB;QAAI;IAAE;AACrD;AAGO,SAASiC,gBAAgB1B,KAA6D;IAC3F,QAAQd,kBAAkB,SAAS,OAAOc,MAAM,EAAE,GAAGA,MAAM,QAAQ,GAAGd,kBAAkB;AAC1F"}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export { G9AnchorLayerContext, type G9AnchorLayerValue, G9AnchorRegistryContext, G9ScrollerContext, g9PageAnchorLayer, } from './context.js';
|
|
2
|
+
export { G9Anchor, type G9AnchorHandle, type G9AnchorProps, type G9AnchorRef, type G9ScrollerHandle, type G9ScrollerOptions, G9ScrollerScope, g9AnchorDomId, useG9Anchor, useG9AnchorRegistry, useG9Scroller, } from './hooks.js';
|
|
3
|
+
export { anchorRect, intersect, invokeNode, measureNode, settleFrame, visibleFraction, windowRect } from './measure.js';
|
|
4
|
+
export { createAnchorRegistry, type G9AnchorBinding, type G9AnchorCapabilities, type G9AnchorEntry, type G9AnchorInfo, type G9AnchorKind, type G9AnchorRect, type G9AnchorRegistry, type G9AnchorResolver, type G9ScrollerSpec, type G9VirtualAnchor, } from './registry.js';
|
|
5
|
+
export { applyScrollMark, type G9RevealOptions, type G9RevealResult, readScrollMark, revealAnchor } from './scroll.js';
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/anchor/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,uBAAuB,EACvB,iBAAiB,EACjB,iBAAiB,GAClB,MAAM,WAAW,CAAC;AACnB,OAAO,EACL,QAAQ,EACR,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,WAAW,EAChB,KAAK,gBAAgB,EACrB,KAAK,iBAAiB,EACtB,eAAe,EACf,aAAa,EACb,WAAW,EACX,mBAAmB,EACnB,aAAa,GACd,MAAM,SAAS,CAAC;AACjB,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,WAAW,EAAE,eAAe,EAAE,UAAU,EAAE,MAAM,WAAW,CAAC;AACrH,OAAO,EACL,oBAAoB,EACpB,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,aAAa,EAClB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,EACrB,KAAK,cAAc,EACnB,KAAK,eAAe,GACrB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,eAAe,EAAE,KAAK,eAAe,EAAE,KAAK,cAAc,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,UAAU,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { G9AnchorLayerContext, G9AnchorRegistryContext, G9ScrollerContext, g9PageAnchorLayer } from "./context.jsx";
|
|
2
|
+
export { G9Anchor, G9ScrollerScope, g9AnchorDomId, useG9Anchor, useG9AnchorRegistry, useG9Scroller } from "./hooks.jsx";
|
|
3
|
+
export { anchorRect, intersect, invokeNode, measureNode, settleFrame, visibleFraction, windowRect } from "./measure.jsx";
|
|
4
|
+
export { createAnchorRegistry } from "./registry.jsx";
|
|
5
|
+
export { applyScrollMark, readScrollMark, revealAnchor } from "./scroll.jsx";
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { NodesRef } from '@lynx-js/types';
|
|
2
|
+
import type { G9AnchorEntry, G9AnchorRect } from './registry.js';
|
|
3
|
+
/** One element method; `ok: false` when it failed, the node is gone or it did not answer within `timeoutMs`. */
|
|
4
|
+
export declare function invokeNode<T = unknown>(node: NodesRef | null | undefined, method: string, params?: Record<string, unknown>, timeoutMs?: number): Promise<{
|
|
5
|
+
readonly ok: true;
|
|
6
|
+
readonly value: T;
|
|
7
|
+
} | {
|
|
8
|
+
readonly ok: false;
|
|
9
|
+
}>;
|
|
10
|
+
/** The element's rect (null when it cannot be measured now). */
|
|
11
|
+
export declare function measureNode(node: NodesRef | null | undefined): Promise<G9AnchorRect | null>;
|
|
12
|
+
/** An anchor's rect: a virtual one's own function, else its element's. */
|
|
13
|
+
export declare function anchorRect(anchor: G9AnchorEntry): Promise<G9AnchorRect | null>;
|
|
14
|
+
/** The window in dp (`SystemInfo` is in physical pixels); 0 × 0 when unknown. */
|
|
15
|
+
export declare function windowRect(): G9AnchorRect;
|
|
16
|
+
/** The intersection of two rects (null when they do not overlap). */
|
|
17
|
+
export declare function intersect(a: G9AnchorRect, b: G9AnchorRect): G9AnchorRect | null;
|
|
18
|
+
/** Share (0..1) of `rect` inside `view`; 0 for an empty rect. */
|
|
19
|
+
export declare function visibleFraction(rect: G9AnchorRect, view: G9AnchorRect): number;
|
|
20
|
+
/** A pause for the native view to settle after a scroll. */
|
|
21
|
+
export declare function settleFrame(ms?: number): Promise<void>;
|
|
22
|
+
//# sourceMappingURL=measure.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"measure.d.ts","sourceRoot":"","sources":["../../src/anchor/measure.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EAAE,aAAa,EAAE,YAAY,EAAE,MAAM,YAAY,CAAC;AAe9D,gHAAgH;AAChH,wBAAgB,UAAU,CAAC,CAAC,GAAG,OAAO,EACpC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,EACjC,MAAM,EAAE,MAAM,EACd,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,EACpC,SAAS,SAAO,GACf,OAAO,CAAC;IAAE,QAAQ,CAAC,EAAE,EAAE,IAAI,CAAC;IAAC,QAAQ,CAAC,KAAK,EAAE,CAAC,CAAA;CAAE,GAAG;IAAE,QAAQ,CAAC,EAAE,EAAE,KAAK,CAAA;CAAE,CAAC,CA6B5E;AAWD,gEAAgE;AAChE,wBAAsB,WAAW,CAAC,IAAI,EAAE,QAAQ,GAAG,IAAI,GAAG,SAAS,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CAUjG;AAED,0EAA0E;AAC1E,wBAAsB,UAAU,CAAC,MAAM,EAAE,aAAa,GAAG,OAAO,CAAC,YAAY,GAAG,IAAI,CAAC,CASpF;AAED,iFAAiF;AACjF,wBAAgB,UAAU,IAAI,YAAY,CASzC;AAED,qEAAqE;AACrE,wBAAgB,SAAS,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EAAE,YAAY,GAAG,YAAY,GAAG,IAAI,CAM/E;AAED,iEAAiE;AACjE,wBAAgB,eAAe,CAAC,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,YAAY,GAAG,MAAM,CAK9E;AAED,4DAA4D;AAC5D,wBAAgB,WAAW,CAAC,EAAE,SAAK,GAAG,OAAO,CAAC,IAAI,CAAC,CAIlD"}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
import { g9RuntimeTimers } from "@g9tm/lynxcontrols-foundation";
|
|
2
|
+
function invokeNode(node, method, params = {}, timeoutMs = 1500) {
|
|
3
|
+
return new Promise((resolve)=>{
|
|
4
|
+
let settled = false;
|
|
5
|
+
let timer = null;
|
|
6
|
+
const done = (r)=>{
|
|
7
|
+
if (settled) return;
|
|
8
|
+
settled = true;
|
|
9
|
+
if (null !== timer) g9RuntimeTimers.clearTimeout(timer);
|
|
10
|
+
resolve(r);
|
|
11
|
+
};
|
|
12
|
+
const target = node;
|
|
13
|
+
if (!target || 'function' != typeof target.invoke) return void done({
|
|
14
|
+
ok: false
|
|
15
|
+
});
|
|
16
|
+
timer = g9RuntimeTimers.setTimeout(()=>done({
|
|
17
|
+
ok: false
|
|
18
|
+
}), timeoutMs);
|
|
19
|
+
try {
|
|
20
|
+
target.invoke({
|
|
21
|
+
method,
|
|
22
|
+
params,
|
|
23
|
+
success: (value)=>done({
|
|
24
|
+
ok: true,
|
|
25
|
+
value: value
|
|
26
|
+
}),
|
|
27
|
+
fail: ()=>done({
|
|
28
|
+
ok: false
|
|
29
|
+
})
|
|
30
|
+
}).exec();
|
|
31
|
+
} catch {
|
|
32
|
+
done({
|
|
33
|
+
ok: false
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
async function measureNode(node) {
|
|
39
|
+
var _v_left, _v_top, _v_width, _v_right, _v_height, _v_bottom;
|
|
40
|
+
const r = await invokeNode(node, 'boundingClientRect', {
|
|
41
|
+
androidEnableTransformProps: true
|
|
42
|
+
});
|
|
43
|
+
if (!r.ok || !r.value) return null;
|
|
44
|
+
const v = r.value;
|
|
45
|
+
const x = null != (_v_left = v.left) ? _v_left : 0;
|
|
46
|
+
const y = null != (_v_top = v.top) ? _v_top : 0;
|
|
47
|
+
const width = null != (_v_width = v.width) ? _v_width : (null != (_v_right = v.right) ? _v_right : x) - x;
|
|
48
|
+
const height = null != (_v_height = v.height) ? _v_height : (null != (_v_bottom = v.bottom) ? _v_bottom : y) - y;
|
|
49
|
+
if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(width) || !Number.isFinite(height)) return null;
|
|
50
|
+
return {
|
|
51
|
+
x,
|
|
52
|
+
y,
|
|
53
|
+
width,
|
|
54
|
+
height
|
|
55
|
+
};
|
|
56
|
+
}
|
|
57
|
+
async function anchorRect(anchor) {
|
|
58
|
+
if (anchor.binding.rect) try {
|
|
59
|
+
return await anchor.binding.rect();
|
|
60
|
+
} catch {
|
|
61
|
+
return null;
|
|
62
|
+
}
|
|
63
|
+
return measureNode(anchor.binding.node());
|
|
64
|
+
}
|
|
65
|
+
function windowRect() {
|
|
66
|
+
try {
|
|
67
|
+
var _ref, _ref1;
|
|
68
|
+
const info = globalThis.SystemInfo;
|
|
69
|
+
const ratio = (null == info ? void 0 : info.pixelRatio) || 1;
|
|
70
|
+
return {
|
|
71
|
+
x: 0,
|
|
72
|
+
y: 0,
|
|
73
|
+
width: (null != (_ref = null == info ? void 0 : info.pixelWidth) ? _ref : 0) / ratio,
|
|
74
|
+
height: (null != (_ref1 = null == info ? void 0 : info.pixelHeight) ? _ref1 : 0) / ratio
|
|
75
|
+
};
|
|
76
|
+
} catch {
|
|
77
|
+
return {
|
|
78
|
+
x: 0,
|
|
79
|
+
y: 0,
|
|
80
|
+
width: 0,
|
|
81
|
+
height: 0
|
|
82
|
+
};
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
function intersect(a, b) {
|
|
86
|
+
const x = Math.max(a.x, b.x);
|
|
87
|
+
const y = Math.max(a.y, b.y);
|
|
88
|
+
const right = Math.min(a.x + a.width, b.x + b.width);
|
|
89
|
+
const bottom = Math.min(a.y + a.height, b.y + b.height);
|
|
90
|
+
return right > x && bottom > y ? {
|
|
91
|
+
x,
|
|
92
|
+
y,
|
|
93
|
+
width: right - x,
|
|
94
|
+
height: bottom - y
|
|
95
|
+
} : null;
|
|
96
|
+
}
|
|
97
|
+
function visibleFraction(rect, view) {
|
|
98
|
+
const area = rect.width * rect.height;
|
|
99
|
+
if (area <= 0) return 0;
|
|
100
|
+
const i = intersect(rect, view);
|
|
101
|
+
return i ? Math.min(1, i.width * i.height / area) : 0;
|
|
102
|
+
}
|
|
103
|
+
function settleFrame(ms = 34) {
|
|
104
|
+
return new Promise((resolve)=>{
|
|
105
|
+
g9RuntimeTimers.setTimeout(resolve, ms);
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
export { anchorRect, intersect, invokeNode, measureNode, settleFrame, visibleFraction, windowRect };
|
|
109
|
+
|
|
110
|
+
//# sourceMappingURL=measure.jsx.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"anchor/measure.jsx","sources":["../../src/anchor/measure.ts"],"sourcesContent":["import { g9RuntimeTimers } from '@g9tm/lynxcontrols-foundation';\nimport type { NodesRef } from '@lynx-js/types';\nimport type { G9AnchorEntry, G9AnchorRect } from './registry';\n\n// Element methods through NodesRef.invoke, bounded: every call settles (success, failure or a timeout), so a guide or\n// a navigation never waits on an element that went away. Rects are boundingClientRect WITH transforms (a sheet sliding\n// in reports where it is drawn), in dp, relative to the LynxView.\n\ninterface Invokable {\n invoke(options: {\n method: string;\n params?: Record<string, unknown>;\n success?: (r: unknown) => void;\n fail?: (e: unknown) => void;\n }): { exec(): void };\n}\n\n/** One element method; `ok: false` when it failed, the node is gone or it did not answer within `timeoutMs`. */\nexport function invokeNode<T = unknown>(\n node: NodesRef | null | undefined,\n method: string,\n params: Record<string, unknown> = {},\n timeoutMs = 1500,\n): Promise<{ readonly ok: true; readonly value: T } | { readonly ok: false }> {\n return new Promise((resolve) => {\n let settled = false;\n let timer: unknown = null;\n const done = (r: { readonly ok: true; readonly value: T } | { readonly ok: false }) => {\n if (settled) return;\n settled = true;\n if (timer !== null) g9RuntimeTimers.clearTimeout(timer);\n resolve(r);\n };\n const target = node as unknown as Invokable | null | undefined;\n if (!target || typeof target.invoke !== 'function') {\n done({ ok: false });\n return;\n }\n timer = g9RuntimeTimers.setTimeout(() => done({ ok: false }), timeoutMs);\n try {\n target\n .invoke({\n method,\n params,\n success: (value) => done({ ok: true, value: value as T }),\n fail: () => done({ ok: false }),\n })\n .exec();\n } catch {\n done({ ok: false });\n }\n });\n}\n\ninterface RawRect {\n readonly left?: number;\n readonly top?: number;\n readonly width?: number;\n readonly height?: number;\n readonly right?: number;\n readonly bottom?: number;\n}\n\n/** The element's rect (null when it cannot be measured now). */\nexport async function measureNode(node: NodesRef | null | undefined): Promise<G9AnchorRect | null> {\n const r = await invokeNode<RawRect>(node, 'boundingClientRect', { androidEnableTransformProps: true });\n if (!r.ok || !r.value) return null;\n const v = r.value;\n const x = v.left ?? 0;\n const y = v.top ?? 0;\n const width = v.width ?? (v.right ?? x) - x;\n const height = v.height ?? (v.bottom ?? y) - y;\n if (!Number.isFinite(x) || !Number.isFinite(y) || !Number.isFinite(width) || !Number.isFinite(height)) return null;\n return { x, y, width, height };\n}\n\n/** An anchor's rect: a virtual one's own function, else its element's. */\nexport async function anchorRect(anchor: G9AnchorEntry): Promise<G9AnchorRect | null> {\n if (anchor.binding.rect) {\n try {\n return await anchor.binding.rect();\n } catch {\n return null;\n }\n }\n return measureNode(anchor.binding.node());\n}\n\n/** The window in dp (`SystemInfo` is in physical pixels); 0 × 0 when unknown. */\nexport function windowRect(): G9AnchorRect {\n try {\n const info = (globalThis as { SystemInfo?: { pixelWidth?: number; pixelHeight?: number; pixelRatio?: number } })\n .SystemInfo;\n const ratio = info?.pixelRatio || 1;\n return { x: 0, y: 0, width: (info?.pixelWidth ?? 0) / ratio, height: (info?.pixelHeight ?? 0) / ratio };\n } catch {\n return { x: 0, y: 0, width: 0, height: 0 };\n }\n}\n\n/** The intersection of two rects (null when they do not overlap). */\nexport function intersect(a: G9AnchorRect, b: G9AnchorRect): G9AnchorRect | null {\n const x = Math.max(a.x, b.x);\n const y = Math.max(a.y, b.y);\n const right = Math.min(a.x + a.width, b.x + b.width);\n const bottom = Math.min(a.y + a.height, b.y + b.height);\n return right > x && bottom > y ? { x, y, width: right - x, height: bottom - y } : null;\n}\n\n/** Share (0..1) of `rect` inside `view`; 0 for an empty rect. */\nexport function visibleFraction(rect: G9AnchorRect, view: G9AnchorRect): number {\n const area = rect.width * rect.height;\n if (area <= 0) return 0;\n const i = intersect(rect, view);\n return i ? Math.min(1, (i.width * i.height) / area) : 0;\n}\n\n/** A pause for the native view to settle after a scroll. */\nexport function settleFrame(ms = 34): Promise<void> {\n return new Promise((resolve) => {\n g9RuntimeTimers.setTimeout(resolve, ms);\n });\n}\n"],"names":["invokeNode","node","method","params","timeoutMs","Promise","resolve","settled","timer","done","r","g9RuntimeTimers","target","value","measureNode","_v_left","_v_top","_v_width","_v_right","_v_height","_v_bottom","v","x","y","width","height","Number","anchorRect","anchor","windowRect","info","globalThis","ratio","intersect","a","b","Math","right","bottom","visibleFraction","rect","view","area","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AEC,EAAE,CAAC;IAC3B,MAAME,QAAQD,KAAK,GAAG,CAACF,EAAE,CAAC,GAAGA,EAAE,KAAK,EAAEC,EAAE,CAAC,GAAGA,EAAE,KAAK;IACnD,MAAMG,SAASF,KAAK,GAAG,CAACF,EAAE,CAAC,GAAGA,EAAE,MAAM,EAAEC,EAAE,CAAC,GAAGA,EAAE,MAAM;IACtD,OAAOE,QAAQf,KAAKgB,SAASf,IAAI;QAAED;QAAGC;QAAG,OAAOc,QAAQf;QAAG,QAAQgB,SAASf;IAAE,IAAI;AACpF;AAGO,SAASgB,gBAAgBC,IAAkB,EAAEC,IAAkB;IACpE,MAAMC,OAAOF,KAAK,KAAK,GAAGA,KAAK,MAAM;IACrC,IAAIE,QAAQ,GAAG,OAAO;IACtB,MAAMC,IAAIV,UAAUO,MAAMC;IAC1B,OAAOE,IAAIP,KAAK,GAAG,CAAC,GAAIO,EAAE,KAAK,GAAGA,EAAE,MAAM,GAAID,QAAQ;AACxD;AAGO,SAASE,YAAYC,KAAK,EAAE;IACjC,OAAO,IAAIxC,QAAQ,CAACC;QAClBK,gBAAgB,UAAU,CAACL,SAASuC;IACtC;AACF"}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import type { G9AnchorRisk, G9ChangeLine } from '@g9tm/lynxcontrols-foundation';
|
|
2
|
+
import type { NodesRef } from '@lynx-js/types';
|
|
3
|
+
/** What kind of thing an anchor is. */
|
|
4
|
+
export type G9AnchorKind = 'button' | 'entry' | 'toggle' | 'picker' | 'chips' | 'tab' | 'tab-view' | 'list' | 'scroll' | 'item' | 'card' | 'label' | 'image' | 'map' | 'view';
|
|
5
|
+
/** What an anchor can do, through the control's OWN paths (the same handler a finger triggers, with its guards). */
|
|
6
|
+
export interface G9AnchorCapabilities {
|
|
7
|
+
activate?(): void | Promise<void>;
|
|
8
|
+
getValue?(): string | null | undefined;
|
|
9
|
+
/** Sets the value; returns the value actually applied when it can read it back. */
|
|
10
|
+
setValue?(value: string): unknown;
|
|
11
|
+
focus?(): void | Promise<void>;
|
|
12
|
+
itemKeys?(): readonly string[];
|
|
13
|
+
selectItem?(key: string): void | Promise<void>;
|
|
14
|
+
expand?(open: boolean): void | Promise<void>;
|
|
15
|
+
}
|
|
16
|
+
/** What an anchor is (read live: the latest render's values). */
|
|
17
|
+
export interface G9AnchorInfo {
|
|
18
|
+
readonly kind: G9AnchorKind;
|
|
19
|
+
label?(): string | null | undefined;
|
|
20
|
+
enabled?(): boolean;
|
|
21
|
+
/** What pressing it does to data. Default `none`. The journey policy reads it. */
|
|
22
|
+
readonly risk?: G9AnchorRisk;
|
|
23
|
+
/** What pressing it would change (a save button's confirmation lists these). */
|
|
24
|
+
changes?(): readonly G9ChangeLine[];
|
|
25
|
+
readonly capabilities?: G9AnchorCapabilities;
|
|
26
|
+
}
|
|
27
|
+
/** A rectangle in logical pixels (dp), in the LynxView's coordinates. */
|
|
28
|
+
export interface G9AnchorRect {
|
|
29
|
+
readonly x: number;
|
|
30
|
+
readonly y: number;
|
|
31
|
+
readonly width: number;
|
|
32
|
+
readonly height: number;
|
|
33
|
+
}
|
|
34
|
+
/** Where a mounted anchor lives. */
|
|
35
|
+
export interface G9AnchorBinding {
|
|
36
|
+
/** The element; null while unmounted or for a virtual anchor. */
|
|
37
|
+
node(): NodesRef | null;
|
|
38
|
+
/** Measures a virtual anchor (instead of the node). */
|
|
39
|
+
rect?(): Promise<G9AnchorRect | null>;
|
|
40
|
+
/** Brings a virtual anchor into view (the map lands on a tree). */
|
|
41
|
+
reveal?(): Promise<boolean>;
|
|
42
|
+
/** The enclosing scroller's id (context), or null. */
|
|
43
|
+
readonly scrollerId: string | null;
|
|
44
|
+
readonly layer: 'page' | 'sheet' | 'popup' | 'floating';
|
|
45
|
+
/** The sheet's handle id when inside a G9 sheet. */
|
|
46
|
+
readonly sheetId?: number;
|
|
47
|
+
}
|
|
48
|
+
/** A registered anchor. */
|
|
49
|
+
export interface G9AnchorEntry {
|
|
50
|
+
readonly id: string;
|
|
51
|
+
/** Registration order: the newest mounted anchor with an id wins. */
|
|
52
|
+
readonly seq: number;
|
|
53
|
+
readonly virtual: boolean;
|
|
54
|
+
info(): G9AnchorInfo;
|
|
55
|
+
readonly binding: G9AnchorBinding;
|
|
56
|
+
}
|
|
57
|
+
/** Something that is not an element but can be pointed at (resolved by id pattern). */
|
|
58
|
+
export interface G9VirtualAnchor extends G9AnchorInfo {
|
|
59
|
+
rect(): Promise<G9AnchorRect | null>;
|
|
60
|
+
reveal?(): Promise<boolean>;
|
|
61
|
+
}
|
|
62
|
+
/** Makes virtual anchors for ids it recognises (a tree on the map: `Map.Tree.<id>`). */
|
|
63
|
+
export interface G9AnchorResolver {
|
|
64
|
+
match(id: string): boolean;
|
|
65
|
+
resolve(id: string): G9VirtualAnchor | null;
|
|
66
|
+
}
|
|
67
|
+
/** A registered scroll container. */
|
|
68
|
+
export interface G9ScrollerSpec {
|
|
69
|
+
readonly id: string;
|
|
70
|
+
readonly kind: 'list' | 'scroll-view';
|
|
71
|
+
readonly orientation: 'vertical' | 'horizontal';
|
|
72
|
+
node(): NodesRef | null;
|
|
73
|
+
/** The scroller this one sits in (context), or null. */
|
|
74
|
+
readonly parentId: string | null;
|
|
75
|
+
/** A list: its item keys in order (the `item-key` strings). */
|
|
76
|
+
itemKeys?(): readonly string[];
|
|
77
|
+
/** A list: the anchor id of the row with this key (a row that is not mounted can still be revealed). */
|
|
78
|
+
itemAnchor?(key: string): string;
|
|
79
|
+
/** A list: the item key of a row anchor, or null when the anchor is not one of its rows. */
|
|
80
|
+
anchorKey?(anchorId: string): string | null;
|
|
81
|
+
}
|
|
82
|
+
/** Every anchor and scroller of one provider (one LynxView): registered while mounted, found by id. */
|
|
83
|
+
export interface G9AnchorRegistry {
|
|
84
|
+
/** Registers an anchor; the returned function removes exactly this registration. */
|
|
85
|
+
register(id: string, info: () => G9AnchorInfo, binding: G9AnchorBinding): () => void;
|
|
86
|
+
/** The newest mounted anchor with this id, else one a resolver makes, else null. */
|
|
87
|
+
find(id: string): G9AnchorEntry | null;
|
|
88
|
+
/** Every mounted anchor, oldest first. */
|
|
89
|
+
all(): readonly G9AnchorEntry[];
|
|
90
|
+
/** Called after any anchor or scroller came or went. */
|
|
91
|
+
subscribe(listener: () => void): () => void;
|
|
92
|
+
addResolver(resolver: G9AnchorResolver): () => void;
|
|
93
|
+
registerScroller(spec: G9ScrollerSpec): () => void;
|
|
94
|
+
scroller(id: string): G9ScrollerSpec | null;
|
|
95
|
+
/** The anchors inside a scroller: bound to it by context, or rows its `anchorKey` names. */
|
|
96
|
+
anchorsIn(scrollerId: string): readonly G9AnchorEntry[];
|
|
97
|
+
/** The list that holds the (maybe not mounted) row anchor `anchorId`, with the row's key. */
|
|
98
|
+
listFor(anchorId: string): {
|
|
99
|
+
readonly scroller: G9ScrollerSpec;
|
|
100
|
+
readonly key: string;
|
|
101
|
+
} | null;
|
|
102
|
+
/** The scroller of a mounted anchor: its context one, else a list whose rows include it. */
|
|
103
|
+
scrollerOf(anchor: G9AnchorEntry): G9ScrollerSpec | null;
|
|
104
|
+
readonly revision: number;
|
|
105
|
+
}
|
|
106
|
+
/** Creates an empty registry. */
|
|
107
|
+
export declare function createAnchorRegistry(): G9AnchorRegistry;
|
|
108
|
+
//# sourceMappingURL=registry.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/anchor/registry.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAChF,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAO/C,uCAAuC;AACvC,MAAM,MAAM,YAAY,GACpB,QAAQ,GACR,OAAO,GACP,QAAQ,GACR,QAAQ,GACR,OAAO,GACP,KAAK,GACL,UAAU,GACV,MAAM,GACN,QAAQ,GACR,MAAM,GACN,MAAM,GACN,OAAO,GACP,OAAO,GACP,KAAK,GACL,MAAM,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