@doubao-dev/taro-runtime 0.10.3 → 0.11.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 +24 -105
- package/dist/api/canvas/canvas-export.d.ts +31 -0
- package/dist/api/canvas/canvas-export.js +55 -0
- package/dist/api/canvas/index.d.ts +2 -2
- package/dist/api/canvas/index.js +12 -10
- package/dist/api/create-selector-query/index.d.ts +34 -0
- package/dist/api/create-selector-query/index.js +12 -0
- package/dist/api/index.d.ts +2 -2
- package/dist/api/index.js +2 -2
- package/dist/api/router/get-current-pages.d.ts +1 -0
- package/dist/api/router/get-current-pages.js +5 -1
- package/dist/api/router/index.d.ts +1 -1
- package/dist/api/router/index.js +1 -1
- package/dist/components/Canvas/index.d.ts +8 -2
- package/dist/components/Canvas/index.jsx +12 -13
- package/dist/components/RootPortal/index.d.ts +7 -0
- package/dist/components/RootPortal/index.jsx +16 -0
- package/dist/components/index.d.ts +1 -0
- package/dist/components/index.js +1 -0
- package/dist/exports/not-supported.d.ts +3 -0
- package/dist/exports/not-supported.js +5 -0
- package/dist/exports/view-core.d.ts +1 -0
- package/dist/exports/view-core.js +1 -0
- package/dist/internal/class-components.d.ts +1 -1
- package/dist/internal/class-components.js +6 -3
- package/dist/internal/index.d.ts +1 -0
- package/dist/internal/index.js +1 -0
- package/dist/internal/portal.d.ts +7 -0
- package/dist/internal/portal.js +25 -0
- package/dist/internal/query-node.d.ts +4 -3
- package/dist/internal/query-node.js +26 -9
- package/dist/react-dom.d.ts +10 -0
- package/dist/react-dom.js +13 -0
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -1,128 +1,47 @@
|
|
|
1
1
|
# @doubao-dev/taro-runtime
|
|
2
2
|
|
|
3
|
-
豆包应用插件的 Taro
|
|
3
|
+
豆包应用插件的 Taro 运行时适配层(实验阶段)。
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## 安装与接入
|
|
6
6
|
|
|
7
7
|
```sh
|
|
8
8
|
pnpm add @doubao-dev/taro-runtime
|
|
9
9
|
```
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
## React 与 Portal
|
|
12
12
|
|
|
13
|
-
|
|
13
|
+
- **React 入口(`@doubao-dev/taro-runtime/react`)**:复用 `@doubao-dev/framework`,React 类型仍保留在原类型包;`useTransition` 同步执行回调(无时间分片/pending),`useLayoutEffect` 复用 `useEffect`(异步时机)。
|
|
14
|
+
- **`<RootPortal>`**:从 `@tarojs/components` 导入,支持 `enable`(默认 `true`);经 `adaptPage` 包装的页面挂载到页面根容器,`enable={false}` 或非页面环境原地渲染。
|
|
15
|
+
- **`createPortal`**:`react-dom` 映射到 `@doubao-dev/taro-runtime/react-dom`,兼容可选第 3 参数 `key` 与空容器(返回 `null`)。自定义容器需通过 `<View ref={setHost} />` 或 `Taro.createSelectorQuery().select(...)` 获取,不提供 `document` 及 DOM 查询/创建能力。
|
|
16
|
+
- Portal 仅在后台线程渲染,不支持跨页面/跨原生容器挂载,且依赖宿主内置包含 `createPortal` 的 `@doubao-dev/framework`。
|
|
14
17
|
|
|
15
|
-
|
|
16
|
-
平台导出器将业务源码中 `react` 的值引用映射到此入口,支持具名、默认、命名空间导入及重导出;
|
|
17
|
-
React 类型引用仍保留在原类型包。`react-dom` 继续映射到 framework 的原生 Portal 能力。
|
|
18
|
+
## 组件兼容
|
|
18
19
|
|
|
19
|
-
- `
|
|
20
|
-
|
|
21
|
-
- `
|
|
22
|
-
|
|
23
|
-
-
|
|
20
|
+
- **Checkbox / CheckboxGroup**:选中态由各 `Checkbox` 的 `checked` 决定(不传则内部维护);`change` 通过 `event.detail.value` 返回选中数组;支持 `name` 接入 `Form`。
|
|
21
|
+
- **Textarea**:`value` 初始化及变更通过异步 `setValue` 同步(无同步受控保证);`onInput` 原样回写时不重复写入。
|
|
22
|
+
- **Image**:普通图片 `widthFix` / `heightFix` 复用 SDK `autoSize`(固定边由 `className` / `style` 指定);SVG 仍走已有路径;Web 纵向 Flex 下可用 `align-items: flex-start` 避免拉伸。
|
|
23
|
+
- **Text**:支持 `userSelect` / `selectable`(`userSelect` 优先)、`space`(`ensp` / `emsp` / `nbsp`)和 `decode`(先解码再转换空格);嵌套 `Text` 各自独立处理。
|
|
24
|
+
- **Picker**:复用 SDK `Popup` / `PickerView` / `PickerColumn`,支持 `selector`、`multiSelector`、`date`、`time` 及 `onColumnChange`、`headerText`、`textProps`;不支持 `region`。手动示例见 `examples/taro/src/pages/picker`。
|
|
24
25
|
|
|
25
|
-
##
|
|
26
|
+
## API 兼容
|
|
26
27
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
- `checked` 传入时由业务在 change 回调中更新;不传时由组件维护选中状态。
|
|
30
|
-
- 组的 `change` 事件通过 `event.detail.value` 返回选中值数组,只在用户点击或通过 `Label` 切换时触发。
|
|
31
|
-
- 设置 `name` 后接入 `Form` 提交与重置,提交时读取组的当前选中值。
|
|
32
|
-
|
|
33
|
-
## Textarea
|
|
34
|
-
|
|
35
|
-
`value` 由 Taro 适配层在初始化和属性变化时通过原生 `setValue` 同步;SDK TextArea 保持原生 ref 接口,不增加 `value/defaultValue` 属性。初始化也使用 `setValue`,不依赖较新宿主的 `default-value` 属性。
|
|
36
|
-
|
|
37
|
-
Lynx 原生 textarea 没有受控输入协议,跨线程的 `setValue` 是异步更新,不能提供 Web textarea 的同步受控保证。`onInput` 上报实际输入;将该值原样更新到 `value` 时不重复写入原生,也不会因为 `value` 未变化而强制回滚用户输入。Form 跟随实际输入更新,应用主动修改 `value` 时同步更新字段值。
|
|
38
|
-
|
|
39
|
-
## Image 尺寸模式
|
|
40
|
-
|
|
41
|
-
普通图片的 `widthFix` / `heightFix` 复用 SDK Image 的 `autoSize`:`widthFix` 保留宽度并将高度设为 `auto`,`heightFix` 保留高度并将宽度设为 `auto`,原生加载图片后按原图比例计算另一边。固定边的尺寸可以通过 `className` 或 `style` 设置,`style` 支持对象和字符串;自动计算的一边会覆盖样式中原先指定的宽或高。
|
|
42
|
-
|
|
43
|
-
`scaleToFill`、`aspectFit`、`aspectFill`、`center` 继续使用原生缩放模式。SVG 仍走已有的 Svg 渲染路径,不包含在此次尺寸模式兼容范围内。
|
|
44
|
-
|
|
45
|
-
Web runtime 的 `autoSize` 仍受父容器 Flex 拉伸影响;例如纵向 Flex 容器中的 `heightFix`,可设置父容器 `align-items: flex-start`,避免自动宽度被拉伸。示例页包含这一布局设置。
|
|
46
|
-
|
|
47
|
-
## Text
|
|
48
|
-
|
|
49
|
-
`Text` 在 Taro 适配层支持以下属性:
|
|
50
|
-
|
|
51
|
-
- `userSelect` / `selectable`:开启原生文本选择,同时设置 `flatten={false}`。同时传入时以 `userSelect` 为准,包括显式传入 `false`。
|
|
52
|
-
- `space`:将普通空格转换为 `ensp`(半个中文字符宽度)、`emsp`(一个中文字符宽度)或 `nbsp`(不换行空格)。
|
|
53
|
-
- `decode`:默认关闭。开启后解码 `&`、`<`、`>`、`"`、`'`、` `、` `、` ` 和有效的十进制/十六进制数字实体;未知或无效实体保留原文。解码结果仍按文本显示。
|
|
54
|
-
|
|
55
|
-
同时开启 `decode` 和 `space` 时,先解码,再转换普通空格。数组和 Fragment 中的文本同样处理;嵌套 `Text` 按自身的 `decode`、`space` 属性独立处理,保留样式和事件,不继承父级的转换设置。
|
|
56
|
-
|
|
57
|
-
```tsx
|
|
58
|
-
import { Text } from '@tarojs/components';
|
|
59
|
-
|
|
60
|
-
<Text userSelect decode space="ensp">
|
|
61
|
-
{'A & B'}
|
|
62
|
-
<Text decode>{' <C>'}</Text>
|
|
63
|
-
</Text>;
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
文本选择的长按交互和菜单表现由原生组件提供,需在目标版本真机验证。
|
|
67
|
-
|
|
68
|
-
## Picker
|
|
69
|
-
|
|
70
|
-
Taro `Picker` 通过兼容层复用 SDK 已有的 `Popup`、`PickerView` 和 `PickerColumn`。业务继续从
|
|
71
|
-
`@tarojs/components` 导入,SDK 不新增内置 `picker` 标签。
|
|
72
|
-
|
|
73
|
-
- 支持现有 `selector`、`multiSelector`、`date`、`time` 模式及对应的值转换。
|
|
74
|
-
- 支持 `range/rangeKey`、`value/defaultValue`、`disabled`、`headerText`、`textProps` 和确认/取消回调。
|
|
75
|
-
- 多列的 `onColumnChange` 返回列下标及选项下标,业务可更新 `range/value` 实现联动。
|
|
76
|
-
- `value` 为受控值;未传时保留已确认选择。滚动只修改临时值,取消和遮罩关闭不提交。
|
|
77
|
-
- 弹层跟随 SDK 主题,空列不能确认。`region` 仍不支持,不内置行政区数据。
|
|
78
|
-
|
|
79
|
-
`examples/taro/src/pages/picker` 提供这些属性的手动演示。日期与时间的模式约定只保留在 Taro 兼容层。
|
|
80
|
-
|
|
81
|
-
## Portal
|
|
82
|
-
|
|
83
|
-
`react-dom` 的值引用由编译插件映射到 `@doubao-dev/framework`,本包不提供 `react-dom` 入口。支持命名、默认和命名空间导入,调用表达式保持不变。`createPortal(children, container)` 只支持两个参数;参数及成员检查交给生成项目的 TypeScript 类型检查,编译插件不额外检查 JS 调用。容器必须迁移为 Lynx `NodesRef`,可通过原生节点的 ref 或 `lynx.createSelectorQuery().select(...)` 获取;编译插件不会将 DOM 元素自动转换为原生节点,也不提供 `document` 或 DOM 创建、查询能力。
|
|
84
|
-
|
|
85
|
-
Portal 仅在后台线程渲染,不参与主线程首屏渲染;事件按实际节点结构传播,不支持跨页面或跨原生容器挂载。其他 `react-dom` API 不在兼容范围内。
|
|
86
|
-
|
|
87
|
-
需要同时更新包含 `createPortal` 导出的 framework 宿主资源;仅更新 taro-runtime 无法补齐旧宿主的能力。
|
|
88
|
-
|
|
89
|
-
## 节点相交观察
|
|
90
|
-
|
|
91
|
-
`createIntersectionObserver` 由 Taro runtime 直接适配 Lynx 观察器:
|
|
28
|
+
### `createIntersectionObserver`
|
|
92
29
|
|
|
93
30
|
```ts
|
|
94
31
|
import { createIntersectionObserver } from '@tarojs/taro';
|
|
95
32
|
|
|
96
|
-
// 目标节点渲染后调用;使用结束时 disconnect。
|
|
97
33
|
const observer = createIntersectionObserver(null, { thresholds: [0, 0.5, 1] });
|
|
98
|
-
observer.relativeToViewport({ bottom: 100 }).observe('#target', (
|
|
99
|
-
console.log(
|
|
34
|
+
observer.relativeToViewport({ bottom: 100 }).observe('#target', (res) => {
|
|
35
|
+
console.log(res.intersectionRatio, res.boundingClientRect?.width);
|
|
100
36
|
});
|
|
101
|
-
// 页面或卡片销毁时:observer.disconnect();
|
|
102
37
|
```
|
|
103
38
|
|
|
104
|
-
适配层补齐 `
|
|
105
|
-
|
|
106
|
-
Lynx 的 `observe()` 按 ID 查找目标。对于 `.class` 等选择器,Taro runtime 在调用 `observe()` 时通过 Lynx SelectorQuery 查询节点,再按 `unique_id` 注册观察。`observeAll: false` 取首个匹配节点,`true` 取全部匹配节点。
|
|
107
|
-
|
|
108
|
-
### 当前兼容限制
|
|
109
|
-
|
|
110
|
-
- **观察目标**。选择器支持范围取决于 Lynx SelectorQuery。通过查询注册的目标列表在调用 `observe()` 时确定,之后新增的匹配节点需要重新注册。
|
|
111
|
-
- **首次通知**。Taro runtime 向 Lynx 传入 `initialRatio: 0`,并逐节点比较第一条收到的回调。比例等于调用方的 `initialRatio` 时跳过该条回调。初始比例为 0 时,Lynx 可能不发回调,适配层无法补发。此时滚动后的第一条回调也可能被当作首次回调过滤。阈值判断仍由 Lynx 执行。
|
|
112
|
-
- **多个参照区域**。微信可对多个参照区域取交集。豆包真机实测连续调用 `relativeTo()` 时最后一次设置生效,依赖多个区域共同限制可见性的业务可能提前或漏触发回调。
|
|
113
|
-
- **检测时间与节点信息**。`time` 原样转发,当前实测 Lynx 返回 0,无法用于计算检测时间差。微信实测返回的目标节点 `id`、`dataset` 当前未适配。
|
|
114
|
-
- **查询范围**。适配层忽略第一个 Taro 组件参数,在整个 LynxView 内查询,建议传入 `null`。`relativeToViewport()` 使用当前 LynxView 的视口,祖先裁剪遵循 Lynx。
|
|
115
|
-
|
|
116
|
-
请在支持该 API 的视图后台脚本中调用。运行时缺少该 API 时会同步抛错。
|
|
117
|
-
|
|
118
|
-
真机宿主的 framework API bundle 必须包含此 API;仅更新或 link taro-runtime 不会升级宿主资源。本地内网 SDK 调试可使用 `DISABLE_EXTERNAL=1` 将匹配版本的 framework/API 实现打入应用。
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
## 页面路由与实例
|
|
39
|
+
适配层补齐 `width` / `height`,支持 `.class` 等非 ID 选择器,并在 `disconnect()` 后忽略晚到回调。注意:`relativeTo()` 仅最后一次生效;`initialRatio` 为 `0` 时首条回调可能缺失或被过滤;`time` 为 `0`,未适配 `id` / `dataset`;忽略第一个组件参数(建议传 `null`)。需宿主 framework API bundle 包含此 API(内网调试可用 `DISABLE_EXTERNAL=1`)。
|
|
122
40
|
|
|
123
|
-
|
|
41
|
+
### 页面路由与实例
|
|
124
42
|
|
|
125
|
-
-
|
|
126
|
-
-
|
|
127
|
-
-
|
|
128
|
-
-
|
|
43
|
+
- **`useRouter(live?)`**:读取 `{ path, params }`(`path` 以 `/` 开头,`params` 值为字符串);传 `true` 时响应宿主地址更新。
|
|
44
|
+
- **`getCurrentInstance()`**:返回 `{ app, page, router }`(未初始化时对应项为 `null`)。
|
|
45
|
+
- **`getCurrentPage()`**:返回当前页面(未下发页面地址时为 `null`),支持 `path` / `route` 与 `options` / `query`。
|
|
46
|
+
- **`getCurrentPages()`**:返回页面栈,支持 `path` / `route` 与 `options` / `query`。
|
|
47
|
+
- **`getApp()`**:返回已初始化的应用实例,初始化前调用抛错,独立运行环境间不共享。
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
/** 可导出图片的画布。尺寸与裁剪坐标均以画布 buffer 像素为单位。 */
|
|
2
|
+
export interface CanvasExportSource {
|
|
3
|
+
/** 源画布 buffer 宽度,单位 px。 */
|
|
4
|
+
readonly width: number;
|
|
5
|
+
/** 源画布 buffer 高度,单位 px。 */
|
|
6
|
+
readonly height: number;
|
|
7
|
+
/** 将当前已完成的绘图编码为图片 data URL。 */
|
|
8
|
+
toDataURL(type?: string, quality?: number): string | Promise<string>;
|
|
9
|
+
}
|
|
10
|
+
/** 画布图片导出参数。 */
|
|
11
|
+
export interface CanvasExportOptions {
|
|
12
|
+
/** 裁剪横坐标,以源画布 buffer 像素为单位。 @default 0 */
|
|
13
|
+
x?: number;
|
|
14
|
+
/** 裁剪纵坐标,以源画布 buffer 像素为单位。 @default 0 */
|
|
15
|
+
y?: number;
|
|
16
|
+
/** 裁剪宽度,单位 px。 @default 源画布宽度减去 x */
|
|
17
|
+
width?: number;
|
|
18
|
+
/** 裁剪高度,单位 px。 @default 源画布高度减去 y */
|
|
19
|
+
height?: number;
|
|
20
|
+
/** 输出像素宽度。 @default width 乘设备像素密度 */
|
|
21
|
+
destWidth?: number;
|
|
22
|
+
/** 输出像素高度。 @default height 乘设备像素密度 */
|
|
23
|
+
destHeight?: number;
|
|
24
|
+
/** 输出图片格式。 @default png */
|
|
25
|
+
fileType?: 'png' | 'jpg';
|
|
26
|
+
/** 仅 jpg 生效,范围 (0, 1]。 @default 1 */
|
|
27
|
+
quality?: number;
|
|
28
|
+
}
|
|
29
|
+
/** 将画布按裁剪、缩放与格式选项编码后写入临时目录,返回文件路径。 */
|
|
30
|
+
export declare function exportCanvasToTempFilePath(source: CanvasExportSource, options: CanvasExportOptions): Promise<string>;
|
|
31
|
+
//# sourceMappingURL=canvas-export.d.ts.map
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { createOffscreenCanvas, getFileSystemManager, getSystemInfoSync } from '@doubao-dev/framework/api';
|
|
2
|
+
let nextExportId = 0;
|
|
3
|
+
// Each JS realm has its own counter; randomize the realm prefix to avoid cross-page overwrites.
|
|
4
|
+
const exportSessionId = Math.random().toString(36).slice(2);
|
|
5
|
+
/** 将画布按裁剪、缩放与格式选项编码后写入临时目录,返回文件路径。 */
|
|
6
|
+
export async function exportCanvasToTempFilePath(source, options) {
|
|
7
|
+
const { x = 0, y = 0, fileType = 'png', quality = 1 } = options;
|
|
8
|
+
// Component canvases finish attaching and acquire their buffer size during this await.
|
|
9
|
+
const snapshot = await source.toDataURL('image/png');
|
|
10
|
+
const width = options.width ?? source.width - x;
|
|
11
|
+
const height = options.height ?? source.height - y;
|
|
12
|
+
const ratio = options.destWidth === undefined || options.destHeight === undefined ? getSystemInfoSync().pixelRatio : 1;
|
|
13
|
+
const destWidth = Math.floor(options.destWidth ?? width * ratio);
|
|
14
|
+
const destHeight = Math.floor(options.destHeight ?? height * ratio);
|
|
15
|
+
const isUntouched = fileType === 'png' &&
|
|
16
|
+
x === 0 &&
|
|
17
|
+
y === 0 &&
|
|
18
|
+
width === source.width &&
|
|
19
|
+
height === source.height &&
|
|
20
|
+
destWidth === source.width &&
|
|
21
|
+
destHeight === source.height;
|
|
22
|
+
const mime = fileType === 'jpg' ? 'image/jpeg' : 'image/png';
|
|
23
|
+
const dataURL = isUntouched
|
|
24
|
+
? snapshot
|
|
25
|
+
: await redraw(snapshot, [x, y, width, height], [destWidth, destHeight], mime, quality);
|
|
26
|
+
const filePath = `appletfile://temp/canvas-${exportSessionId}-${nextExportId++}.${fileType}`;
|
|
27
|
+
await getFileSystemManager().writeFile({
|
|
28
|
+
filePath,
|
|
29
|
+
data: dataURL.slice(`data:${mime};base64,`.length),
|
|
30
|
+
encoding: 'base64'
|
|
31
|
+
});
|
|
32
|
+
return filePath;
|
|
33
|
+
}
|
|
34
|
+
async function redraw(snapshot, [sx, sy, sw, sh], [dw, dh], mime, quality) {
|
|
35
|
+
const output = createOffscreenCanvas({ width: dw, height: dh });
|
|
36
|
+
try {
|
|
37
|
+
const image = output.createImage();
|
|
38
|
+
await loadImage(image, snapshot);
|
|
39
|
+
output.getContext('2d').drawImage(image, sx, sy, sw, sh, 0, 0, dw, dh);
|
|
40
|
+
return output.toDataURL(mime, quality);
|
|
41
|
+
}
|
|
42
|
+
finally {
|
|
43
|
+
// Release the native buffer right away instead of waiting for GC.
|
|
44
|
+
output.width = 1;
|
|
45
|
+
output.height = 1;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
function loadImage(image, url) {
|
|
49
|
+
return new Promise((resolve, reject) => {
|
|
50
|
+
image.onload = () => resolve();
|
|
51
|
+
image.onerror = reject;
|
|
52
|
+
image.src = url;
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
//# sourceMappingURL=canvas-export.js.map
|
|
@@ -3,8 +3,8 @@ import type Taro from '@tarojs/taro';
|
|
|
3
3
|
type TaroCanvasToTempFilePathOption = Parameters<typeof Taro.canvasToTempFilePath>[0];
|
|
4
4
|
type TaroCanvasToTempFilePathResult = Awaited<ReturnType<typeof Taro.canvasToTempFilePath>>;
|
|
5
5
|
/**
|
|
6
|
-
* Export a canvas by instance or id.
|
|
7
|
-
*
|
|
6
|
+
* Export a canvas by instance or id. `canvasId` resolves to the latest mounted Canvas with that id;
|
|
7
|
+
* when `component` matches a Canvas's `exportScope`, canvases in that scope take precedence.
|
|
8
8
|
*/
|
|
9
9
|
export declare function canvasToTempFilePath(option?: TaroCanvasToTempFilePathOption, component?: TaroGeneral.IAnyObject): Promise<TaroCanvasToTempFilePathResult>;
|
|
10
10
|
export declare function createOffscreenCanvas(options: Taro.createOffscreenCanvas.Option): DoubaoOffscreenCanvas;
|
package/dist/api/canvas/index.js
CHANGED
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
import { createOffscreenCanvas as createCanvas
|
|
1
|
+
import { createOffscreenCanvas as createCanvas } from '@doubao-dev/framework/api';
|
|
2
|
+
import { getQueryCanvas } from '../../internal/query-node.js';
|
|
2
3
|
import { buildOkCallbackResult, runTaroApi } from '../utils.js';
|
|
4
|
+
import { exportCanvasToTempFilePath } from './canvas-export.js';
|
|
3
5
|
/**
|
|
4
|
-
* Export a canvas by instance or id.
|
|
5
|
-
*
|
|
6
|
+
* Export a canvas by instance or id. `canvasId` resolves to the latest mounted Canvas with that id;
|
|
7
|
+
* when `component` matches a Canvas's `exportScope`, canvases in that scope take precedence.
|
|
6
8
|
*/
|
|
7
9
|
export async function canvasToTempFilePath(option, component) {
|
|
8
10
|
return runTaroApi('canvasToTempFilePath', option, async () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
const { canvas, canvasId } = option;
|
|
12
|
+
// Taro types the instance as its own Canvas; both satisfy the export contract at runtime.
|
|
13
|
+
const source = canvas ?? getQueryCanvas(canvasId, component);
|
|
14
|
+
if (!source) {
|
|
15
|
+
throw new Error(`canvasToTempFilePath: canvas "${canvasId}" is not mounted`);
|
|
11
16
|
}
|
|
12
|
-
const
|
|
13
|
-
|
|
14
|
-
canvas: option.canvas
|
|
15
|
-
}, component);
|
|
16
|
-
return { ...result, ...buildOkCallbackResult('canvasToTempFilePath') };
|
|
17
|
+
const tempFilePath = await exportCanvasToTempFilePath(source, option);
|
|
18
|
+
return { tempFilePath, ...buildOkCallbackResult('canvasToTempFilePath') };
|
|
17
19
|
});
|
|
18
20
|
}
|
|
19
21
|
export function createOffscreenCanvas(options) {
|
|
@@ -1,3 +1,37 @@
|
|
|
1
1
|
import type Taro from '@tarojs/taro';
|
|
2
|
+
type AnyRecord = Record<string, unknown>;
|
|
3
|
+
type UniqueId = string | number;
|
|
4
|
+
type LynxStatus = {
|
|
5
|
+
code?: number;
|
|
6
|
+
data?: string;
|
|
7
|
+
};
|
|
8
|
+
type LynxInvokeOptions = {
|
|
9
|
+
method: string;
|
|
10
|
+
params?: AnyRecord;
|
|
11
|
+
success?: (res: unknown) => void;
|
|
12
|
+
fail?: (err: unknown) => void;
|
|
13
|
+
};
|
|
14
|
+
type LynxFieldsOptions = {
|
|
15
|
+
id?: boolean;
|
|
16
|
+
dataset?: boolean;
|
|
17
|
+
query?: boolean;
|
|
18
|
+
unique_id?: boolean;
|
|
19
|
+
};
|
|
20
|
+
type LynxSelectorQuery = {
|
|
21
|
+
select(selector: string): LynxNodesRef;
|
|
22
|
+
selectAll(selector: string): LynxMultiNodesRef;
|
|
23
|
+
selectRoot(): LynxNodesRef;
|
|
24
|
+
setRoot?(uniqueId: UniqueId): LynxSelectorQuery;
|
|
25
|
+
exec(): void;
|
|
26
|
+
};
|
|
27
|
+
type LynxNodesRef = {
|
|
28
|
+
invoke(options: LynxInvokeOptions): LynxSelectorQuery;
|
|
29
|
+
fields(fields: LynxFieldsOptions, callback: (data: AnyRecord | null, status: LynxStatus) => void): LynxSelectorQuery;
|
|
30
|
+
};
|
|
31
|
+
type LynxMultiNodesRef = {
|
|
32
|
+
fields(fields: LynxFieldsOptions, callback: (data: AnyRecord[], status: LynxStatus) => void): LynxSelectorQuery;
|
|
33
|
+
};
|
|
34
|
+
export declare function resolvePortalNodesRef(container: unknown): LynxNodesRef | null;
|
|
2
35
|
export declare function createSelectorQuery(): Taro.SelectorQuery;
|
|
36
|
+
export {};
|
|
3
37
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -746,6 +746,18 @@ function toRecordOrNull(value) {
|
|
|
746
746
|
function createViewSelectorQuery() {
|
|
747
747
|
return new SelectorQueryAdapter();
|
|
748
748
|
}
|
|
749
|
+
export function resolvePortalNodesRef(container) {
|
|
750
|
+
if (!container) {
|
|
751
|
+
return null;
|
|
752
|
+
}
|
|
753
|
+
if (container instanceof NodesRefAdapter) {
|
|
754
|
+
if (container.target.kind !== 'single' || !container.target.selector) {
|
|
755
|
+
return null;
|
|
756
|
+
}
|
|
757
|
+
return getLynxRoot()?.createSelectorQuery().select(container.target.selector) ?? null;
|
|
758
|
+
}
|
|
759
|
+
return container;
|
|
760
|
+
}
|
|
749
761
|
export function createSelectorQuery() {
|
|
750
762
|
return createViewSelectorQuery();
|
|
751
763
|
}
|
package/dist/api/index.d.ts
CHANGED
|
@@ -2,13 +2,13 @@ export { getEnv, ENV_TYPE } from './base/index.js';
|
|
|
2
2
|
export { canIUse } from './base/can-i-use.js';
|
|
3
3
|
export { eventCenter } from './base/event-center.js';
|
|
4
4
|
export { nextTick } from './base/next-tick.js';
|
|
5
|
-
export
|
|
5
|
+
export * from './runtime/system.js';
|
|
6
6
|
export * from './device/index.js';
|
|
7
7
|
export * from './device/index.js';
|
|
8
8
|
export * from './media/index.js';
|
|
9
9
|
export { request } from './request/index.js';
|
|
10
10
|
export { connectSocket, onSocketOpen, onSocketMessage, onSocketError, onSocketClose } from './request/websocket.js';
|
|
11
|
-
export { exitMiniProgram, getApp, getCurrentInstance, navigateBack, navigateTo,
|
|
11
|
+
export { exitMiniProgram, getApp, getCurrentInstance, getCurrentPage, getCurrentPages, navigateBack, navigateTo, reLaunch, redirectTo, useRouter } from './router/index.js';
|
|
12
12
|
export { setStorage, setStorageSync, getStorage, getStorageSync, removeStorage, removeStorageSync, clearStorage, clearStorageSync, getStorageInfo, getStorageInfoSync } from './storage/index.js';
|
|
13
13
|
export * from './system/index.js';
|
|
14
14
|
export * from './location/index.js';
|
package/dist/api/index.js
CHANGED
|
@@ -2,13 +2,13 @@ export { getEnv, ENV_TYPE } from './base/index.js';
|
|
|
2
2
|
export { canIUse } from './base/can-i-use.js';
|
|
3
3
|
export { eventCenter } from './base/event-center.js';
|
|
4
4
|
export { nextTick } from './base/next-tick.js';
|
|
5
|
-
export
|
|
5
|
+
export * from './runtime/system.js';
|
|
6
6
|
export * from './device/index.js';
|
|
7
7
|
export * from './device/index.js';
|
|
8
8
|
export * from './media/index.js';
|
|
9
9
|
export { request } from './request/index.js';
|
|
10
10
|
export { connectSocket, onSocketOpen, onSocketMessage, onSocketError, onSocketClose } from './request/websocket.js';
|
|
11
|
-
export { exitMiniProgram, getApp, getCurrentInstance, navigateBack, navigateTo,
|
|
11
|
+
export { exitMiniProgram, getApp, getCurrentInstance, getCurrentPage, getCurrentPages, navigateBack, navigateTo, reLaunch, redirectTo, useRouter } from './router/index.js';
|
|
12
12
|
export { setStorage, setStorageSync, getStorage, getStorageSync, removeStorage, removeStorageSync, clearStorage, clearStorageSync, getStorageInfo, getStorageInfoSync } from './storage/index.js';
|
|
13
13
|
export * from './system/index.js';
|
|
14
14
|
export * from './location/index.js';
|
|
@@ -10,5 +10,6 @@ export interface TaroCurrentPage {
|
|
|
10
10
|
query: Record<string, string>;
|
|
11
11
|
}
|
|
12
12
|
export declare function toTaroPage({ route, query }: CurrentPage): TaroCurrentPage;
|
|
13
|
+
export declare function getCurrentPage(): TaroCurrentPage | null;
|
|
13
14
|
export declare function getCurrentPages(): TaroCurrentPage[];
|
|
14
15
|
//# sourceMappingURL=get-current-pages.d.ts.map
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
import { getCurrentPages as appGetCurrentPages } from '@doubao-dev/framework';
|
|
1
|
+
import { getCurrentPage as appGetCurrentPage, getCurrentPages as appGetCurrentPages } from '@doubao-dev/framework';
|
|
2
2
|
export function toTaroPage({ route, query }) {
|
|
3
3
|
return { path: route, route, options: query, query };
|
|
4
4
|
}
|
|
5
|
+
export function getCurrentPage() {
|
|
6
|
+
const current = appGetCurrentPage();
|
|
7
|
+
return current && toTaroPage(current);
|
|
8
|
+
}
|
|
5
9
|
export function getCurrentPages() {
|
|
6
10
|
return appGetCurrentPages().map(toTaroPage);
|
|
7
11
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { exitMiniProgram } from './exit-mini-program.js';
|
|
2
2
|
export { getApp, getCurrentInstance, useRouter } from './current-instance.js';
|
|
3
3
|
export { navigateBack } from './navigate-back.js';
|
|
4
|
-
export { getCurrentPages } from './get-current-pages.js';
|
|
4
|
+
export { getCurrentPage, getCurrentPages } from './get-current-pages.js';
|
|
5
5
|
export { navigateTo } from './navigate-to.js';
|
|
6
6
|
export { reLaunch } from './re-launch.js';
|
|
7
7
|
export { redirectTo } from './redirect-to.js';
|
package/dist/api/router/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
export { exitMiniProgram } from './exit-mini-program.js';
|
|
2
2
|
export { getApp, getCurrentInstance, useRouter } from './current-instance.js';
|
|
3
3
|
export { navigateBack } from './navigate-back.js';
|
|
4
|
-
export { getCurrentPages } from './get-current-pages.js';
|
|
4
|
+
export { getCurrentPage, getCurrentPages } from './get-current-pages.js';
|
|
5
5
|
export { navigateTo } from './navigate-to.js';
|
|
6
6
|
export { reLaunch } from './re-launch.js';
|
|
7
7
|
export { redirectTo } from './redirect-to.js';
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { type CanvasRef
|
|
1
|
+
import { type CanvasRef } from '@doubao-dev/framework/components';
|
|
2
2
|
import type { CanvasProps } from '@tarojs/components';
|
|
3
|
-
export declare const Canvas: (props: CanvasProps &
|
|
3
|
+
export declare const Canvas: (props: CanvasProps & {
|
|
4
|
+
/**
|
|
5
|
+
* canvasToTempFilePath 的组件查找作用域:第二个参数与此对象相同时,优先匹配该作用域内的 Canvas。
|
|
6
|
+
* 需要引用稳定的对象(例如 useRef 保存的对象);内联的 exportScope={{}} 无法被第二个参数匹配。
|
|
7
|
+
*/
|
|
8
|
+
exportScope?: object;
|
|
9
|
+
} & import("react").RefAttributes<CanvasRef>) => React.ReactElement | null;
|
|
4
10
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1,25 +1,24 @@
|
|
|
1
1
|
import { Canvas as SDKCanvas } from '@doubao-dev/framework/components';
|
|
2
|
-
import { forwardRef, useCallback,
|
|
3
|
-
import {
|
|
2
|
+
import { forwardRef, useCallback, useEffect, useState } from '@doubao-dev/framework';
|
|
3
|
+
import { registerQueryCanvas, useQueryNodeProps } from '../../internal/query-node.js';
|
|
4
4
|
export const Canvas = forwardRef(function Canvas({ id, canvasId, exportScope, type, className, style, disableScroll, onTouchStart, onTouchMove, onTouchEnd, onTouchCancel, onLongTap, onError }, ref) {
|
|
5
5
|
const queryId = id ?? canvasId;
|
|
6
|
-
const
|
|
6
|
+
const [instance, setInstance] = useState(null);
|
|
7
7
|
useQueryNodeProps(queryId, { canvasId, type, disableScroll });
|
|
8
|
-
|
|
9
|
-
if (queryId && current.current) {
|
|
10
|
-
clearQueryCanvas(queryId, current.current);
|
|
11
|
-
}
|
|
12
|
-
current.current = instance;
|
|
8
|
+
useEffect(() => {
|
|
13
9
|
if (queryId && instance) {
|
|
14
|
-
|
|
10
|
+
return registerQueryCanvas(queryId, instance, exportScope);
|
|
15
11
|
}
|
|
12
|
+
}, [queryId, instance, exportScope]);
|
|
13
|
+
const assignRef = useCallback((next) => {
|
|
14
|
+
setInstance(next);
|
|
16
15
|
if (typeof ref === 'function') {
|
|
17
|
-
ref(
|
|
16
|
+
ref(next);
|
|
18
17
|
}
|
|
19
18
|
else if (ref) {
|
|
20
|
-
ref.current =
|
|
19
|
+
ref.current = next;
|
|
21
20
|
}
|
|
22
|
-
}, [
|
|
23
|
-
return (<SDKCanvas ref={assignRef} id={id ?? canvasId}
|
|
21
|
+
}, [ref]);
|
|
22
|
+
return (<SDKCanvas ref={assignRef} id={id ?? canvasId} className={className} style={style} disableScroll={disableScroll} onTouchStart={onTouchStart} onTouchMove={onTouchMove} onTouchEnd={onTouchEnd} onTouchCancel={onTouchCancel} onLongPress={onLongTap} onError={onError}/>);
|
|
24
23
|
});
|
|
25
24
|
//# sourceMappingURL=index.jsx.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from '@doubao-dev/framework';
|
|
2
|
+
export type RootPortalProps = {
|
|
3
|
+
enable?: boolean;
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
} & Record<string, unknown>;
|
|
6
|
+
export declare function RootPortal({ enable, children, ...rest }: RootPortalProps): any;
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { createPortal } from '@doubao-dev/framework';
|
|
2
|
+
import { usePortalHost } from '../../internal/portal.js';
|
|
3
|
+
import { View } from '../View/index.jsx';
|
|
4
|
+
export function RootPortal({ enable = true, children, ...rest }) {
|
|
5
|
+
const host = usePortalHost();
|
|
6
|
+
const hasWrapperProps = Object.keys(rest).length > 0;
|
|
7
|
+
const content = hasWrapperProps ? <View {...rest}>{children}</View> : <>{children}</>;
|
|
8
|
+
if (!enable || host === undefined) {
|
|
9
|
+
return content;
|
|
10
|
+
}
|
|
11
|
+
if (host === null) {
|
|
12
|
+
return null;
|
|
13
|
+
}
|
|
14
|
+
return createPortal(content, host);
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=index.jsx.map
|
|
@@ -34,4 +34,5 @@ export { View as CustomWrapper } from './View/index.jsx';
|
|
|
34
34
|
export { Icon } from './Icon/index.jsx';
|
|
35
35
|
export { Video } from './Video/index.jsx';
|
|
36
36
|
export { LivePlayer } from './LivePlayer/index.jsx';
|
|
37
|
+
export { RootPortal } from './RootPortal/index.jsx';
|
|
37
38
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/components/index.js
CHANGED
|
@@ -34,4 +34,5 @@ export { View as CustomWrapper } from './View/index.jsx';
|
|
|
34
34
|
export { Icon } from './Icon/index.jsx';
|
|
35
35
|
export { Video } from './Video/index.jsx';
|
|
36
36
|
export { LivePlayer } from './LivePlayer/index.jsx';
|
|
37
|
+
export { RootPortal } from './RootPortal/index.jsx';
|
|
37
38
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './common.js';
|
|
2
2
|
export { onWindowResize, offWindowResize, useResize } from '../api/runtime/resize.js';
|
|
3
3
|
export { useError, useLaunch, usePageNotFound, useDidHide, useDidShow } from '../hooks/lifecycle/app.js';
|
|
4
|
+
export * from './not-supported.js';
|
|
4
5
|
export { useCreated as useLoad, useMounted as useReady, useDestroy as useUnload } from '@doubao-dev/framework';
|
|
5
6
|
//# sourceMappingURL=view-core.d.ts.map
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from './common.js';
|
|
2
2
|
export { onWindowResize, offWindowResize, useResize } from '../api/runtime/resize.js';
|
|
3
3
|
export { useError, useLaunch, usePageNotFound, useDidHide, useDidShow } from '../hooks/lifecycle/app.js';
|
|
4
|
+
export * from './not-supported.js';
|
|
4
5
|
export { useCreated as useLoad, useMounted as useReady, useDestroy as useUnload } from '@doubao-dev/framework';
|
|
5
6
|
//# sourceMappingURL=view-core.js.map
|
|
@@ -5,7 +5,7 @@ type LifecycleProps = {
|
|
|
5
5
|
};
|
|
6
6
|
/** Called by compiled render methods. Hooks own subscription setup and unmount cleanup. */
|
|
7
7
|
export declare function renderClassComponent(instance: object, children: ReactNode): import("react").FunctionComponentElement<LifecycleProps>;
|
|
8
|
-
/**
|
|
8
|
+
/** Wraps every page with a root portal host and forwards `onReady` to class page instances. */
|
|
9
9
|
export declare function adaptPage(Page: ComponentType<any>): ComponentType<any>;
|
|
10
10
|
export {};
|
|
11
11
|
//# sourceMappingURL=class-components.d.ts.map
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { createContext, createElement, useContext, useHide, useMounted, useRef, useShow } from '@doubao-dev/framework';
|
|
2
|
+
import { PortalHostProvider } from './portal.js';
|
|
2
3
|
const LifecycleOwner = createContext(undefined);
|
|
3
4
|
/** Calls a lifecycle method with the instance as `this`; fields of other types are ignored. */
|
|
4
5
|
function invoke(instance, name) {
|
|
@@ -24,10 +25,12 @@ function ClassLifecycle({ instance, children }) {
|
|
|
24
25
|
export function renderClassComponent(instance, children) {
|
|
25
26
|
return createElement(ClassLifecycle, { instance, children });
|
|
26
27
|
}
|
|
27
|
-
/**
|
|
28
|
+
/** Wraps every page with a root portal host and forwards `onReady` to class page instances. */
|
|
28
29
|
export function adaptPage(Page) {
|
|
29
30
|
if (!Page.prototype?.isReactComponent && !Page.prototype?.render) {
|
|
30
|
-
return
|
|
31
|
+
return function TaroFunctionPage(props) {
|
|
32
|
+
return createElement(PortalHostProvider, null, createElement(Page, props));
|
|
33
|
+
};
|
|
31
34
|
}
|
|
32
35
|
return function TaroClassPage(props) {
|
|
33
36
|
const instance = useRef(null);
|
|
@@ -36,7 +39,7 @@ export function adaptPage(Page) {
|
|
|
36
39
|
invoke(instance.current, 'onReady');
|
|
37
40
|
}
|
|
38
41
|
});
|
|
39
|
-
return createElement(Page, { ...props, ref: instance });
|
|
42
|
+
return createElement(PortalHostProvider, null, createElement(Page, { ...props, ref: instance }));
|
|
40
43
|
};
|
|
41
44
|
}
|
|
42
45
|
//# sourceMappingURL=class-components.js.map
|
package/dist/internal/index.d.ts
CHANGED
package/dist/internal/index.js
CHANGED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { type ReactNode } from '@doubao-dev/framework';
|
|
2
|
+
import type { NodesRef } from '@lynx-js/types';
|
|
3
|
+
export declare function PortalHostProvider({ children }: {
|
|
4
|
+
children?: ReactNode;
|
|
5
|
+
}): import("react").FunctionComponentElement<import("react").ProviderProps<NodesRef | null | undefined>>;
|
|
6
|
+
export declare function usePortalHost(): NodesRef | null | undefined;
|
|
7
|
+
//# sourceMappingURL=portal.d.ts.map
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createContext, createElement, useContext, useState } from '@doubao-dev/framework';
|
|
2
|
+
/**
|
|
3
|
+
* `undefined` means no `PortalHostProvider` is present in the tree;
|
|
4
|
+
* `null` means the provider is mounted and waiting for its host `NodesRef` commit.
|
|
5
|
+
*/
|
|
6
|
+
const PortalHostContext = createContext(undefined);
|
|
7
|
+
const portalHostStyle = {
|
|
8
|
+
position: 'fixed',
|
|
9
|
+
left: 0,
|
|
10
|
+
top: 0,
|
|
11
|
+
width: 0,
|
|
12
|
+
height: 0,
|
|
13
|
+
overflow: 'visible'
|
|
14
|
+
};
|
|
15
|
+
export function PortalHostProvider({ children }) {
|
|
16
|
+
const [host, setHost] = useState(null);
|
|
17
|
+
return createElement(PortalHostContext.Provider, { value: host }, children, createElement('view', {
|
|
18
|
+
ref: setHost,
|
|
19
|
+
style: portalHostStyle
|
|
20
|
+
}));
|
|
21
|
+
}
|
|
22
|
+
export function usePortalHost() {
|
|
23
|
+
return useContext(PortalHostContext);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=portal.js.map
|
|
@@ -3,7 +3,8 @@ export declare function useQueryNodeProps(id: unknown, props: Record<string, unk
|
|
|
3
3
|
export declare function getQueryNodeProperties(id: string, names: string[]): {
|
|
4
4
|
[k: string]: unknown;
|
|
5
5
|
};
|
|
6
|
-
|
|
7
|
-
export declare function
|
|
8
|
-
|
|
6
|
+
/** 登记已挂载的 Canvas,返回注销函数。scope 对应 canvasToTempFilePath 的第二个参数。 */
|
|
7
|
+
export declare function registerQueryCanvas(id: string, canvas: CanvasRef, scope?: object): () => void;
|
|
8
|
+
/** 按 id 查找最近挂载的 Canvas;传入 scope 时优先取同 scope 中最近挂载的一个。 */
|
|
9
|
+
export declare function getQueryCanvas(id: string, scope?: object): CanvasRef | undefined;
|
|
9
10
|
//# sourceMappingURL=query-node.d.ts.map
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { useEffect } from '@doubao-dev/framework';
|
|
2
2
|
const propsById = new Map();
|
|
3
|
-
|
|
3
|
+
// Canvases stay registered under the same id while several are mounted; lookups take the latest.
|
|
4
|
+
const canvasesById = new Map();
|
|
4
5
|
export function useQueryNodeProps(id, props) {
|
|
5
6
|
useEffect(() => {
|
|
6
7
|
if (typeof id !== 'string' || !id) {
|
|
@@ -21,15 +22,31 @@ export function getQueryNodeProperties(id, names) {
|
|
|
21
22
|
}
|
|
22
23
|
return Object.fromEntries(names.flatMap((name) => Object.hasOwn(props, name) && typeof props[name] !== 'function' ? [[name, props[name]]] : []));
|
|
23
24
|
}
|
|
24
|
-
|
|
25
|
-
|
|
25
|
+
/** 登记已挂载的 Canvas,返回注销函数。scope 对应 canvasToTempFilePath 的第二个参数。 */
|
|
26
|
+
export function registerQueryCanvas(id, canvas, scope) {
|
|
27
|
+
const entry = { canvas, scope };
|
|
28
|
+
const entries = canvasesById.get(id) ?? [];
|
|
29
|
+
entries.push(entry);
|
|
30
|
+
canvasesById.set(id, entries);
|
|
31
|
+
return () => {
|
|
32
|
+
entries.splice(entries.indexOf(entry), 1);
|
|
33
|
+
if (!entries.length) {
|
|
34
|
+
canvasesById.delete(id);
|
|
35
|
+
}
|
|
36
|
+
};
|
|
26
37
|
}
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
38
|
+
/** 按 id 查找最近挂载的 Canvas;传入 scope 时优先取同 scope 中最近挂载的一个。 */
|
|
39
|
+
export function getQueryCanvas(id, scope) {
|
|
40
|
+
const entries = canvasesById.get(id) ?? [];
|
|
41
|
+
let latest = entries[entries.length - 1];
|
|
42
|
+
if (scope) {
|
|
43
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
44
|
+
if (entries[i].scope === scope) {
|
|
45
|
+
latest = entries[i];
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
30
49
|
}
|
|
31
|
-
|
|
32
|
-
export function getQueryCanvas(id) {
|
|
33
|
-
return canvasById.get(id);
|
|
50
|
+
return latest?.canvas;
|
|
34
51
|
}
|
|
35
52
|
//# sourceMappingURL=query-node.js.map
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type ReactNode } from '@doubao-dev/framework';
|
|
2
|
+
import type { NodesRef } from '@lynx-js/types';
|
|
3
|
+
import type Taro from '@tarojs/taro';
|
|
4
|
+
export type PortalContainer = NodesRef | Taro.NodesRef | null | undefined;
|
|
5
|
+
export declare function createPortal(children: ReactNode, container: PortalContainer, key?: string | number | null): ReactNode;
|
|
6
|
+
declare const ReactDOM: {
|
|
7
|
+
createPortal: typeof createPortal;
|
|
8
|
+
};
|
|
9
|
+
export default ReactDOM;
|
|
10
|
+
//# sourceMappingURL=react-dom.d.ts.map
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { Fragment, createElement, createPortal as frameworkCreatePortal } from '@doubao-dev/framework';
|
|
2
|
+
import { resolvePortalNodesRef } from './api/create-selector-query/index.js';
|
|
3
|
+
export function createPortal(children, container, key) {
|
|
4
|
+
const target = resolvePortalNodesRef(container);
|
|
5
|
+
if (!target) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
const content = key != null ? createElement(Fragment, { key }, children) : children;
|
|
9
|
+
return frameworkCreatePortal(content, target);
|
|
10
|
+
}
|
|
11
|
+
const ReactDOM = { createPortal };
|
|
12
|
+
export default ReactDOM;
|
|
13
|
+
//# sourceMappingURL=react-dom.js.map
|
package/package.json
CHANGED
|
@@ -29,10 +29,15 @@
|
|
|
29
29
|
"import": "./dist/react.js",
|
|
30
30
|
"require": "./dist/react.js"
|
|
31
31
|
},
|
|
32
|
+
"./react-dom": {
|
|
33
|
+
"types": "./dist/react-dom.d.ts",
|
|
34
|
+
"import": "./dist/react-dom.js",
|
|
35
|
+
"require": "./dist/react-dom.js"
|
|
36
|
+
},
|
|
32
37
|
"./package.json": "./package.json"
|
|
33
38
|
},
|
|
34
39
|
"peerDependencies": {
|
|
35
|
-
"@doubao-dev/framework": "^0.
|
|
40
|
+
"@doubao-dev/framework": "^0.11.0",
|
|
36
41
|
"@tarojs/components": "4.1.9",
|
|
37
42
|
"@tarojs/taro": "4.1.9"
|
|
38
43
|
},
|
|
@@ -56,7 +61,7 @@
|
|
|
56
61
|
"access": "public",
|
|
57
62
|
"registry": "https://registry.npmjs.org/"
|
|
58
63
|
},
|
|
59
|
-
"version": "0.
|
|
64
|
+
"version": "0.11.0",
|
|
60
65
|
"dependencies": {
|
|
61
66
|
"@lynx-js/lynx-ui-form": "3.139.0"
|
|
62
67
|
},
|