@lingxia/page-runtime 0.5.0 → 0.6.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.
Files changed (54) hide show
  1. package/dist/index.d.ts +1 -1
  2. package/dist/index.js +1 -1
  3. package/dist/shared/runtime.d.ts +1 -12
  4. package/dist/shared/runtime.js +72 -43
  5. package/package.json +6 -32
  6. package/dist/react/LxInput.d.ts +0 -47
  7. package/dist/react/LxInput.js +0 -128
  8. package/dist/react/LxNavigator.d.ts +0 -23
  9. package/dist/react/LxNavigator.js +0 -61
  10. package/dist/react/LxPicker.d.ts +0 -27
  11. package/dist/react/LxPicker.js +0 -113
  12. package/dist/react/LxTextarea.d.ts +0 -47
  13. package/dist/react/LxTextarea.js +0 -118
  14. package/dist/react/LxVideo.d.ts +0 -5
  15. package/dist/react/LxVideo.js +0 -113
  16. package/dist/react/hook.d.ts +0 -39
  17. package/dist/react/hook.js +0 -212
  18. package/dist/react/index.d.ts +0 -6
  19. package/dist/react/index.js +0 -6
  20. package/dist/react/text_component_shared.d.ts +0 -5
  21. package/dist/react/text_component_shared.js +0 -33
  22. package/dist/vue/LxInput.vue +0 -92
  23. package/dist/vue/LxNavigator.vue +0 -79
  24. package/dist/vue/LxPicker.vue +0 -144
  25. package/dist/vue/LxTextarea.vue +0 -90
  26. package/dist/vue/LxVideo.vue +0 -111
  27. package/dist/vue/hook.d.ts +0 -42
  28. package/dist/vue/hook.js +0 -194
  29. package/dist/vue/index.d.ts +0 -7
  30. package/dist/vue/index.js +0 -6
  31. package/dist/vue/text_component_shared.d.ts +0 -3
  32. package/dist/vue/text_component_shared.js +0 -26
  33. package/dist/vue/types.d.ts +0 -101
  34. package/dist/vue/types.js +0 -1
  35. package/src/index.ts +0 -21
  36. package/src/react/LxInput.tsx +0 -224
  37. package/src/react/LxNavigator.tsx +0 -132
  38. package/src/react/LxPicker.tsx +0 -205
  39. package/src/react/LxTextarea.tsx +0 -216
  40. package/src/react/LxVideo.tsx +0 -166
  41. package/src/react/hook.ts +0 -317
  42. package/src/react/index.ts +0 -14
  43. package/src/react/text_component_shared.ts +0 -43
  44. package/src/shared/runtime.ts +0 -186
  45. package/src/vue/LxInput.vue +0 -92
  46. package/src/vue/LxNavigator.vue +0 -79
  47. package/src/vue/LxPicker.vue +0 -144
  48. package/src/vue/LxTextarea.vue +0 -90
  49. package/src/vue/LxVideo.vue +0 -111
  50. package/src/vue/hook.ts +0 -313
  51. package/src/vue/index.ts +0 -22
  52. package/src/vue/shims-vue.d.ts +0 -5
  53. package/src/vue/text_component_shared.ts +0 -33
  54. package/src/vue/types.ts +0 -107
package/dist/index.d.ts CHANGED
@@ -1 +1 @@
1
- export { ensurePageBridgeSubscription, getPageActions, getPageSnapshot, getPageStateInfo, subscribePageData, subscribePageSnapshot, toBridgeError, resolveParams, stableParamKey, invokeMethod, getMethodKey, type ActionMap, type Snapshot, type ParamsSource, type MethodParams, type StreamData, type StreamResult, type ChannelIn, type ChannelOut, } from "./shared/runtime.js";
1
+ export { ensurePageBridgeSubscription, getPageActions, getPageSnapshot, getPageStateInfo, subscribePageData, subscribePageSnapshot, type ActionMap, type Snapshot, } from "./shared/runtime.js";
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { ensurePageBridgeSubscription, getPageActions, getPageSnapshot, getPageStateInfo, subscribePageData, subscribePageSnapshot, toBridgeError, resolveParams, stableParamKey, invokeMethod, getMethodKey, } from "./shared/runtime.js";
1
+ export { ensurePageBridgeSubscription, getPageActions, getPageSnapshot, getPageStateInfo, subscribePageData, subscribePageSnapshot, } from "./shared/runtime.js";
@@ -1,18 +1,7 @@
1
- import type { DataSubscriber, LxBridgeError, LxChannel, LxStream, StateInfo } from "@lingxia/bridge";
1
+ import { type DataSubscriber, type StateInfo } from "@lingxia/bridge";
2
2
  export type ActionMap = Record<string, (...args: unknown[]) => unknown>;
3
3
  export type Snapshot = Record<string, unknown>;
4
4
  export type Listener = () => void;
5
- export type ParamsSource<T> = T | (() => T);
6
- export type MethodParams<TMethod> = TMethod extends () => any ? undefined : TMethod extends (params: infer P) => any ? P : never;
7
- export type StreamData<TMethod> = TMethod extends (...args: any[]) => LxStream<infer TData, any> ? TData : never;
8
- export type StreamResult<TMethod> = TMethod extends (...args: any[]) => LxStream<any, infer TResult> ? TResult : never;
9
- export type ChannelIn<TMethod> = TMethod extends (...args: any[]) => Promise<LxChannel<infer TIn, any>> ? TIn : never;
10
- export type ChannelOut<TMethod> = TMethod extends (...args: any[]) => Promise<LxChannel<any, infer TOut>> ? TOut : never;
11
- export declare function toBridgeError(err: unknown): LxBridgeError;
12
- export declare function resolveParams<T>(source?: ParamsSource<T>): T | undefined;
13
- export declare function stableParamKey(value: unknown): string;
14
- export declare function invokeMethod<TMethod extends (...args: any[]) => any>(method: TMethod, params: unknown): ReturnType<TMethod>;
15
- export declare function getMethodKey(method: unknown): string | undefined;
16
5
  export declare function ensurePageBridgeSubscription(): void;
17
6
  export declare function subscribePageSnapshot(listener: Listener): () => void;
18
7
  export declare function subscribePageData(callback: DataSubscriber): () => void;
@@ -5,43 +5,6 @@ let subscribeRetryTimer = null;
5
5
  let initialSnapshotResolved = false;
6
6
  let snapshotRequestInFlight = false;
7
7
  const listeners = new Set();
8
- export function toBridgeError(err) {
9
- return err && typeof err === "object" && "code" in err
10
- ? err
11
- : {
12
- code: "BRIDGE_INTERNAL_ERROR",
13
- message: err instanceof Error ? err.message : String(err),
14
- };
15
- }
16
- export function resolveParams(source) {
17
- if (typeof source === "function") {
18
- return source();
19
- }
20
- return source;
21
- }
22
- export function stableParamKey(value) {
23
- var _a;
24
- if (value === undefined)
25
- return "undefined";
26
- try {
27
- return (_a = JSON.stringify(value)) !== null && _a !== void 0 ? _a : "undefined";
28
- }
29
- catch {
30
- return String(value);
31
- }
32
- }
33
- export function invokeMethod(method, params) {
34
- if (params === undefined) {
35
- return method();
36
- }
37
- return method(params);
38
- }
39
- export function getMethodKey(method) {
40
- if (typeof method !== "function")
41
- return undefined;
42
- const candidate = method.__funcName;
43
- return typeof candidate === "string" && candidate !== "" ? candidate : undefined;
44
- }
45
8
  function notifyListeners() {
46
9
  listeners.forEach((listener) => {
47
10
  try {
@@ -68,11 +31,11 @@ function scheduleSubscribeRetry() {
68
31
  function requestInitialSnapshot(bridge) {
69
32
  if (initialSnapshotResolved || snapshotRequestInFlight)
70
33
  return;
71
- if (!(bridge === null || bridge === void 0 ? void 0 : bridge.call))
34
+ if (!bridge?.raw?.call)
72
35
  return;
73
36
  snapshotRequestInFlight = true;
74
37
  bridge
75
- .call("state.getSnapshot", { scope: "page" })
38
+ .raw.call("state.getSnapshot", { scope: "page" })
76
39
  .then(() => {
77
40
  initialSnapshotResolved = true;
78
41
  })
@@ -84,11 +47,10 @@ function requestInitialSnapshot(bridge) {
84
47
  });
85
48
  }
86
49
  export function ensurePageBridgeSubscription() {
87
- var _a;
88
50
  if (subscribed)
89
51
  return;
90
52
  const bridge = window.LingXiaBridge;
91
- const subscribeState = (_a = bridge === null || bridge === void 0 ? void 0 : bridge.state) === null || _a === void 0 ? void 0 : _a.subscribe;
53
+ const subscribeState = bridge?.state?.subscribe;
92
54
  if (!subscribeState) {
93
55
  scheduleSubscribeRetry();
94
56
  return;
@@ -124,13 +86,13 @@ export function getPageSnapshot() {
124
86
  export function getPageActions() {
125
87
  const actions = {};
126
88
  const bridge = window.__pageBridge;
127
- if (!(bridge === null || bridge === void 0 ? void 0 : bridge.__names)) {
89
+ if (!bridge?.__names) {
128
90
  return actions;
129
91
  }
130
92
  for (const name of bridge.__names) {
131
93
  if (typeof name !== "string")
132
94
  continue;
133
- const fn = bridge[name];
95
+ const fn = getOrCreatePageAction(bridge, name);
134
96
  if (typeof fn === "function") {
135
97
  actions[name] = fn;
136
98
  }
@@ -140,3 +102,70 @@ export function getPageActions() {
140
102
  export function getPageStateInfo() {
141
103
  return stateInfo;
142
104
  }
105
+ function getOrCreatePageAction(bridge, name) {
106
+ const existing = bridge[name];
107
+ if (typeof existing === "function") {
108
+ return existing;
109
+ }
110
+ const mode = resolvePageActionMode(bridge, name);
111
+ const created = definePageBridgeAction(name, mode);
112
+ bridge[name] = created;
113
+ return created;
114
+ }
115
+ function resolvePageActionMode(bridge, name) {
116
+ const mode = bridge.__modes?.[name];
117
+ return mode === "call" || mode === "stream" ? mode : "notify";
118
+ }
119
+ function definePageBridgeAction(name, mode) {
120
+ function action(...args) {
121
+ const payload = filterPayload(name, args);
122
+ const bridge = window.LingXiaBridge;
123
+ if (!bridge) {
124
+ throw new Error(`LingXiaBridge is not ready for page action '${name}'`);
125
+ }
126
+ if (mode === "stream") {
127
+ const handle = bridge.raw.stream(name, payload);
128
+ if (handle && handle.result && typeof handle.result.catch === "function") {
129
+ handle.result.catch((err) => {
130
+ console.warn(`[PageFunc] ${name} failed:`, err instanceof Error ? err.message : err);
131
+ });
132
+ }
133
+ return handle;
134
+ }
135
+ if (mode === "call") {
136
+ const promise = bridge.raw.call(name, payload);
137
+ if (promise && typeof promise.catch === "function") {
138
+ promise.catch((err) => {
139
+ console.warn(`[PageFunc] ${name} failed:`, err instanceof Error ? err.message : err);
140
+ });
141
+ }
142
+ return promise;
143
+ }
144
+ bridge.raw.notify(name, payload);
145
+ return undefined;
146
+ }
147
+ Object.assign(action, {
148
+ __logicFunc: true,
149
+ __funcName: name,
150
+ __bridgeMode: mode,
151
+ });
152
+ return action;
153
+ }
154
+ function filterPayload(name, args) {
155
+ const clean = [];
156
+ for (const value of args) {
157
+ if (value instanceof Event)
158
+ continue;
159
+ if (value &&
160
+ typeof value === "object" &&
161
+ "stopPropagation" in value &&
162
+ typeof value.stopPropagation === "function") {
163
+ continue;
164
+ }
165
+ clean.push(value);
166
+ }
167
+ if (clean.length > 1) {
168
+ throw new Error(`Page action '${name}' accepts at most one payload argument`);
169
+ }
170
+ return clean[0];
171
+ }
package/package.json CHANGED
@@ -1,8 +1,8 @@
1
1
  {
2
2
  "name": "@lingxia/page-runtime",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "private": false,
5
- "description": "LingXia page runtime for HTML, React, and Vue lxapp views",
5
+ "description": "Shared page runtime core for LingXia lxapp frameworks",
6
6
  "type": "module",
7
7
  "main": "dist/index.js",
8
8
  "types": "dist/index.d.ts",
@@ -11,48 +11,22 @@
11
11
  "types": "./dist/index.d.ts",
12
12
  "default": "./dist/index.js"
13
13
  },
14
- "./react": {
15
- "types": "./dist/react/index.d.ts",
16
- "default": "./dist/react/index.js"
17
- },
18
- "./vue": {
19
- "types": "./dist/vue/index.d.ts",
20
- "default": "./dist/vue/index.js"
21
- },
22
14
  "./package.json": "./package.json"
23
15
  },
24
16
  "scripts": {
25
- "build": "npm run clean && tsc -p tsconfig.json && mkdir -p dist/vue && cp src/vue/*.vue dist/vue/",
17
+ "build": "npm run clean && npm --prefix ../lingxia-bridge run build:types && tsc -p tsconfig.json",
26
18
  "clean": "rm -rf dist",
27
19
  "prepublishOnly": "npm run build"
28
20
  },
29
21
  "dependencies": {
30
- "@lingxia/bridge": ">=0.5.0",
31
- "@lingxia/elements": ">=0.5.0"
32
- },
33
- "peerDependencies": {
34
- "react": "^19.0.0",
35
- "vue": ">=3.5.0"
36
- },
37
- "peerDependenciesMeta": {
38
- "react": {
39
- "optional": true
40
- },
41
- "vue": {
42
- "optional": true
43
- }
22
+ "@lingxia/bridge": "0.6.0"
44
23
  },
45
24
  "devDependencies": {
46
25
  "@lingxia/bridge": "file:../lingxia-bridge",
47
- "@lingxia/elements": "file:../lingxia-elements",
48
- "@types/react": "^19.2.7",
49
- "react": "^19.0.0",
50
- "typescript": "^5.7.2",
51
- "vue": "^3.5.0"
26
+ "typescript": "^5.7.2"
52
27
  },
53
28
  "files": [
54
- "dist",
55
- "src"
29
+ "dist"
56
30
  ],
57
31
  "publishConfig": {
58
32
  "registry": "https://registry.npmjs.org",
@@ -1,47 +0,0 @@
1
- import React from "react";
2
- export interface LxInputEventDetail {
3
- value?: string;
4
- cursor?: number;
5
- keyCode?: number;
6
- height?: number;
7
- duration?: number;
8
- encryptedValue?: string;
9
- encryptError?: string;
10
- pass?: boolean;
11
- timeout?: boolean;
12
- }
13
- export interface LxInputProps {
14
- id?: string;
15
- value?: string;
16
- defaultValue?: string;
17
- type?: "text" | "number" | "password" | "digit";
18
- password?: boolean;
19
- placeholder?: string;
20
- placeholderStyle?: string;
21
- placeholderClass?: string;
22
- maxlength?: number;
23
- cursorSpacing?: number;
24
- autoFocus?: boolean;
25
- disabled?: boolean;
26
- focus?: boolean;
27
- confirmType?: "send" | "search" | "next" | "go" | "done";
28
- alwaysEmbed?: boolean;
29
- confirmHold?: boolean;
30
- cursor?: number;
31
- cursorColor?: string;
32
- selectionStart?: number;
33
- selectionEnd?: number;
34
- adjustPosition?: boolean;
35
- holdKeyboard?: boolean;
36
- onInput?: (detail: LxInputEventDetail) => void;
37
- onChange?: (detail: LxInputEventDetail) => void;
38
- onFocus?: (detail: LxInputEventDetail) => void;
39
- onBlur?: (detail: LxInputEventDetail) => void;
40
- onConfirm?: (detail: LxInputEventDetail) => void;
41
- onKeyboardHeightChange?: (detail: LxInputEventDetail) => void;
42
- onNicknameReview?: (detail: LxInputEventDetail) => void;
43
- pageBindings?: Record<string, string>;
44
- className?: string;
45
- style?: React.CSSProperties;
46
- }
47
- export declare const LxInput: React.ForwardRefExoticComponent<LxInputProps & React.RefAttributes<HTMLElement>>;
@@ -1,128 +0,0 @@
1
- import React, { forwardRef, useCallback, useEffect, useRef } from "react";
2
- import { registerInputComponent } from "@lingxia/elements";
3
- import { buildInputNativeAttrs } from "@lingxia/elements";
4
- import { assignForwardedRef, bindElementEvents, getCustomEventDetail, unbindElementEvents, } from "./text_component_shared.js";
5
- if (typeof window !== "undefined") {
6
- registerInputComponent();
7
- }
8
- export const LxInput = forwardRef(({ value, defaultValue, type, password, placeholder, placeholderStyle, placeholderClass, maxlength, cursorSpacing, autoFocus, disabled, focus, confirmType, alwaysEmbed, confirmHold, cursor, cursorColor, selectionStart, selectionEnd, adjustPosition, holdKeyboard, onInput, onChange, onFocus, onBlur, onConfirm, onKeyboardHeightChange, onNicknameReview, pageBindings, className, style, id, ...rest }, ref) => {
9
- const elementRef = useRef(null);
10
- const boundElementRef = useRef(null);
11
- const handlerRef = useRef({
12
- onInput,
13
- onChange,
14
- onFocus,
15
- onBlur,
16
- onConfirm,
17
- onKeyboardHeightChange,
18
- onNicknameReview,
19
- });
20
- handlerRef.current = {
21
- onInput,
22
- onChange,
23
- onFocus,
24
- onBlur,
25
- onConfirm,
26
- onKeyboardHeightChange,
27
- onNicknameReview,
28
- };
29
- const listenerMapRef = useRef({
30
- input: {
31
- handleEvent: (event) => { var _a, _b; return (_b = (_a = handlerRef.current).onInput) === null || _b === void 0 ? void 0 : _b.call(_a, getCustomEventDetail(event)); },
32
- },
33
- change: {
34
- handleEvent: (event) => { var _a, _b; return (_b = (_a = handlerRef.current).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, getCustomEventDetail(event)); },
35
- },
36
- focus: {
37
- handleEvent: (event) => { var _a, _b; return (_b = (_a = handlerRef.current).onFocus) === null || _b === void 0 ? void 0 : _b.call(_a, getCustomEventDetail(event)); },
38
- },
39
- blur: {
40
- handleEvent: (event) => { var _a, _b; return (_b = (_a = handlerRef.current).onBlur) === null || _b === void 0 ? void 0 : _b.call(_a, getCustomEventDetail(event)); },
41
- },
42
- confirm: {
43
- handleEvent: (event) => { var _a, _b; return (_b = (_a = handlerRef.current).onConfirm) === null || _b === void 0 ? void 0 : _b.call(_a, getCustomEventDetail(event)); },
44
- },
45
- keyboardheightchange: {
46
- handleEvent: (event) => { var _a, _b; return (_b = (_a = handlerRef.current).onKeyboardHeightChange) === null || _b === void 0 ? void 0 : _b.call(_a, getCustomEventDetail(event)); },
47
- },
48
- nicknamereview: {
49
- handleEvent: (event) => { var _a, _b; return (_b = (_a = handlerRef.current).onNicknameReview) === null || _b === void 0 ? void 0 : _b.call(_a, getCustomEventDetail(event)); },
50
- },
51
- });
52
- const elementRefCallback = useCallback((element) => {
53
- boundElementRef.current = bindElementEvents(boundElementRef.current, element, listenerMapRef.current);
54
- elementRef.current = element;
55
- assignForwardedRef(ref, element);
56
- }, [ref]);
57
- useEffect(() => () => {
58
- unbindElementEvents(boundElementRef.current, listenerMapRef.current);
59
- boundElementRef.current = null;
60
- elementRef.current = null;
61
- }, []);
62
- useEffect(() => {
63
- const el = elementRef.current;
64
- if (!el)
65
- return;
66
- const setAttr = (name, next) => {
67
- if (next === null) {
68
- el.removeAttribute(name);
69
- return;
70
- }
71
- el.setAttribute(name, next);
72
- };
73
- if (type && String(type).trim().length > 0) {
74
- el.setAttribute("type", String(type).trim().toLowerCase());
75
- }
76
- else {
77
- el.removeAttribute("type");
78
- }
79
- if (password) {
80
- el.setAttribute("password", "true");
81
- }
82
- else {
83
- el.removeAttribute("password");
84
- }
85
- setAttr("value", value !== undefined ? String(value) : null);
86
- setAttr("focus", focus !== undefined ? (focus ? "true" : "false") : null);
87
- setAttr("maxlength", maxlength !== undefined ? String(maxlength) : null);
88
- setAttr("placeholder-style", placeholderStyle ? String(placeholderStyle) : null);
89
- }, [type, password, value, focus, maxlength, placeholderStyle]);
90
- // Set pageBindings property on custom element
91
- useEffect(() => {
92
- const el = elementRef.current;
93
- if (el && pageBindings) {
94
- el.pageBindings = pageBindings;
95
- }
96
- }, [pageBindings]);
97
- const inputProps = buildInputNativeAttrs({
98
- id,
99
- value,
100
- defaultValue,
101
- type,
102
- password,
103
- placeholder,
104
- placeholderStyle,
105
- placeholderClass,
106
- maxlength,
107
- cursorSpacing,
108
- autoFocus,
109
- disabled,
110
- focus,
111
- confirmType,
112
- alwaysEmbed,
113
- confirmHold,
114
- cursor,
115
- cursorColor,
116
- selectionStart,
117
- selectionEnd,
118
- adjustPosition,
119
- holdKeyboard,
120
- }, rest, boundElementRef.current !== null);
121
- return React.createElement("lx-input", {
122
- ref: elementRefCallback,
123
- className,
124
- style,
125
- ...inputProps,
126
- });
127
- });
128
- LxInput.displayName = "LxInput";
@@ -1,23 +0,0 @@
1
- import React from 'react';
2
- import type { LxNavigatorAttributes, LxNavigatorEvent, NavigatorOpenType, NavigatorTarget } from '@lingxia/elements';
3
- import '@lingxia/elements';
4
- export interface LxNavigatorProps extends Omit<LxNavigatorAttributes, 'onSuccess' | 'onFail' | 'onComplete'> {
5
- url?: string;
6
- openType?: NavigatorOpenType;
7
- target?: NavigatorTarget;
8
- delta?: number;
9
- appId?: string;
10
- path?: string;
11
- phoneNumber?: string;
12
- hoverClass?: string;
13
- hoverStopPropagation?: boolean;
14
- hoverStartTime?: number;
15
- hoverStayTime?: number;
16
- className?: string;
17
- style?: React.CSSProperties;
18
- onSuccess?: (e: LxNavigatorEvent) => void;
19
- onFail?: (e: LxNavigatorEvent) => void;
20
- onComplete?: (e: LxNavigatorEvent) => void;
21
- children?: React.ReactNode;
22
- }
23
- export declare const LxNavigator: React.ForwardRefExoticComponent<Omit<LxNavigatorProps, "ref"> & React.RefAttributes<HTMLElement>>;
@@ -1,61 +0,0 @@
1
- import React from 'react';
2
- import { buildNavigatorNativeAttrs } from '@lingxia/elements';
3
- // Import to ensure custom element is registered
4
- import '@lingxia/elements';
5
- export const LxNavigator = React.forwardRef((props, ref) => {
6
- const { url, openType = 'navigate', target, // Auto-inferred, no default
7
- delta = 1, appId, path, phoneNumber, hoverClass = 'navigator-hover', hoverStopPropagation = false, hoverStartTime = 20, hoverStayTime = 70, className, style, onSuccess, onFail, onComplete, children, ...rest } = props;
8
- const elementRef = React.useRef(null);
9
- React.useImperativeHandle(ref, () => elementRef.current);
10
- React.useEffect(() => {
11
- const element = elementRef.current;
12
- if (!element)
13
- return;
14
- const handleSuccess = (e) => {
15
- if (onSuccess) {
16
- onSuccess(e);
17
- }
18
- };
19
- const handleFail = (e) => {
20
- if (onFail) {
21
- onFail(e);
22
- }
23
- };
24
- const handleComplete = (e) => {
25
- if (onComplete) {
26
- onComplete(e);
27
- }
28
- };
29
- const successListener = { handleEvent: handleSuccess };
30
- const failListener = { handleEvent: handleFail };
31
- const completeListener = { handleEvent: handleComplete };
32
- element.addEventListener('success', successListener);
33
- element.addEventListener('fail', failListener);
34
- element.addEventListener('complete', completeListener);
35
- return () => {
36
- element.removeEventListener('success', successListener);
37
- element.removeEventListener('fail', failListener);
38
- element.removeEventListener('complete', completeListener);
39
- };
40
- }, [onSuccess, onFail, onComplete]);
41
- const navigatorProps = buildNavigatorNativeAttrs({
42
- url,
43
- openType,
44
- target,
45
- delta,
46
- appId,
47
- path,
48
- phoneNumber,
49
- hoverClass,
50
- hoverStopPropagation,
51
- hoverStartTime,
52
- hoverStayTime,
53
- }, rest);
54
- return React.createElement('lx-navigator', {
55
- ref: elementRef,
56
- className,
57
- style,
58
- ...navigatorProps
59
- }, children);
60
- });
61
- LxNavigator.displayName = 'LxNavigator';
@@ -1,27 +0,0 @@
1
- import React from 'react';
2
- export interface LxPickerProps extends Omit<React.HTMLAttributes<HTMLElement>, 'onChange' | 'onScroll'> {
3
- columns?: string[][] | [string[], Record<string, string[]>];
4
- mode?: 'date' | 'time';
5
- start?: string;
6
- end?: string;
7
- fields?: 'year' | 'month' | 'day' | 'range';
8
- value?: string | string[];
9
- onConfirm?: (value: string | string[]) => void;
10
- onCancel?: () => void;
11
- onScroll?: (value: string | string[]) => void;
12
- onChange?: (event: CustomEvent) => void;
13
- onNativeScroll?: (event: CustomEvent) => void;
14
- pageBindings?: Record<string, string>;
15
- placeholder?: string;
16
- className?: string;
17
- style?: React.CSSProperties;
18
- disabled?: boolean;
19
- cancelText?: string;
20
- cancelTextColor?: string;
21
- cancelButtonColor?: string;
22
- confirmText?: string;
23
- confirmTextColor?: string;
24
- confirmButtonColor?: string;
25
- children?: React.ReactNode;
26
- }
27
- export declare const LxPicker: React.ForwardRefExoticComponent<LxPickerProps & React.RefAttributes<HTMLElement>>;
@@ -1,113 +0,0 @@
1
- import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
- import React, { forwardRef, useCallback, useId, useRef, useState } from 'react';
3
- import { registerPickerComponent } from '@lingxia/elements';
4
- import { buildPickerNativeAttrs, getPickerDisplayText, getPickerValueFromIndex, } from '@lingxia/elements';
5
- import { assignForwardedRef, bindElementEvents, getCustomEventDetail, unbindElementEvents, } from './text_component_shared.js';
6
- if (typeof window !== "undefined") {
7
- registerPickerComponent();
8
- }
9
- export const LxPicker = forwardRef(({ id, columns, mode, start, end, fields, value, onConfirm, onCancel, onScroll, placeholder = 'Please select', onChange, onNativeScroll, pageBindings, className, style, disabled, cancelText, cancelTextColor, cancelButtonColor, confirmText, confirmTextColor, confirmButtonColor, children, ...rest }, ref) => {
10
- const [visible, setVisible] = useState(false);
11
- const reactId = useId();
12
- const pickerId = id !== null && id !== void 0 ? id : `lx-picker-${reactId.replace(/[:]/g, "")}`;
13
- const elementRef = useRef(null);
14
- const boundElementRef = useRef(null);
15
- const handlerRef = useRef({
16
- columns,
17
- mode,
18
- onConfirm,
19
- onCancel,
20
- onScroll,
21
- onChange,
22
- onNativeScroll,
23
- });
24
- handlerRef.current = {
25
- columns,
26
- mode,
27
- onConfirm,
28
- onCancel,
29
- onScroll,
30
- onChange,
31
- onNativeScroll,
32
- };
33
- const listenerMapRef = useRef({
34
- change: {
35
- handleEvent: (event) => {
36
- var _a, _b, _c, _d, _e, _f, _g;
37
- const detail = getCustomEventDetail(event);
38
- (_b = (_a = handlerRef.current).onChange) === null || _b === void 0 ? void 0 : _b.call(_a, event);
39
- if (detail.confirmed) {
40
- const nextValue = handlerRef.current.mode === 'date' || handlerRef.current.mode === 'time'
41
- ? ((_c = detail.value) !== null && _c !== void 0 ? _c : '')
42
- : detail.index !== undefined
43
- ? getPickerValueFromIndex(handlerRef.current.columns, detail.index)
44
- : '';
45
- (_e = (_d = handlerRef.current).onConfirm) === null || _e === void 0 ? void 0 : _e.call(_d, nextValue);
46
- setVisible(false);
47
- return;
48
- }
49
- if (detail.cancelled) {
50
- (_g = (_f = handlerRef.current).onCancel) === null || _g === void 0 ? void 0 : _g.call(_f);
51
- setVisible(false);
52
- }
53
- },
54
- },
55
- scroll: {
56
- handleEvent: (event) => {
57
- var _a, _b, _c, _d, _e, _f;
58
- const detail = getCustomEventDetail(event);
59
- (_b = (_a = handlerRef.current).onNativeScroll) === null || _b === void 0 ? void 0 : _b.call(_a, event);
60
- if (detail.value !== undefined) {
61
- (_d = (_c = handlerRef.current).onScroll) === null || _d === void 0 ? void 0 : _d.call(_c, detail.value);
62
- return;
63
- }
64
- if (detail.index !== undefined) {
65
- (_f = (_e = handlerRef.current).onScroll) === null || _f === void 0 ? void 0 : _f.call(_e, getPickerValueFromIndex(handlerRef.current.columns, detail.index));
66
- }
67
- },
68
- },
69
- });
70
- const elementRefCallback = useCallback((element) => {
71
- boundElementRef.current = bindElementEvents(boundElementRef.current, element, listenerMapRef.current);
72
- elementRef.current = element;
73
- assignForwardedRef(ref, element);
74
- // Set pageBindings on custom element
75
- if (element && pageBindings) {
76
- element.pageBindings = pageBindings;
77
- }
78
- }, [ref, pageBindings]);
79
- React.useEffect(() => () => {
80
- unbindElementEvents(boundElementRef.current, listenerMapRef.current);
81
- boundElementRef.current = null;
82
- elementRef.current = null;
83
- }, []);
84
- const handleClick = () => !disabled && setVisible(true);
85
- const pickerProps = buildPickerNativeAttrs({
86
- id: pickerId,
87
- columns,
88
- mode,
89
- start,
90
- end,
91
- fields,
92
- value,
93
- cancelText,
94
- cancelTextColor,
95
- cancelButtonColor,
96
- confirmText,
97
- confirmTextColor,
98
- confirmButtonColor,
99
- }, rest);
100
- const displayText = getPickerDisplayText(value, fields);
101
- return (_jsxs(_Fragment, { children: [children ? (_jsx("div", { onClick: handleClick, className: className, style: {
102
- cursor: disabled ? 'not-allowed' : 'pointer',
103
- opacity: disabled ? 0.5 : 1,
104
- ...style,
105
- }, children: children })) : (_jsxs("div", { onClick: handleClick, className: className, style: {
106
- display: 'flex', alignItems: 'center', justifyContent: 'space-between',
107
- padding: '12px 14px', backgroundColor: '#fff', border: '1px solid #e5e7eb',
108
- borderRadius: '8px', cursor: disabled ? 'not-allowed' : 'pointer',
109
- opacity: disabled ? 0.5 : 1, width: '100%', boxSizing: 'border-box',
110
- ...style,
111
- }, children: [_jsx("span", { style: { color: value ? '#111' : '#9ca3af' }, children: displayText || placeholder }), _jsx("svg", { width: "16", height: "16", viewBox: "0 0 24 24", fill: "none", stroke: "#9ca3af", strokeWidth: "2", children: _jsx("path", { d: "M6 9l6 6 6-6" }) })] })), visible && React.createElement('lx-picker', { ref: elementRefCallback, ...pickerProps })] }));
112
- });
113
- LxPicker.displayName = 'LxPicker';