@tarojs/plugin-platform-harmony-ets 4.0.0-beta.10 → 4.0.0-beta.12

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 (44) hide show
  1. package/dist/apis/base/system.ts +40 -22
  2. package/dist/components-harmony-ets/button.ets +34 -31
  3. package/dist/components-harmony-ets/checkbox.ets +5 -4
  4. package/dist/components-harmony-ets/form.ets +31 -28
  5. package/dist/components-harmony-ets/icon.ets +22 -18
  6. package/dist/components-harmony-ets/image.ets +15 -11
  7. package/dist/components-harmony-ets/innerHtml.ets +9 -5
  8. package/dist/components-harmony-ets/input.ets +1 -1
  9. package/dist/components-harmony-ets/label.ets +44 -40
  10. package/dist/components-harmony-ets/movableArea.ets +67 -0
  11. package/dist/components-harmony-ets/movableView.ets +66 -0
  12. package/dist/components-harmony-ets/picker.ets +7 -6
  13. package/dist/components-harmony-ets/progress.ets +45 -0
  14. package/dist/components-harmony-ets/radio.ets +5 -5
  15. package/dist/components-harmony-ets/richText.ets +14 -9
  16. package/dist/components-harmony-ets/scrollView.ets +40 -35
  17. package/dist/components-harmony-ets/slider.ets +1 -1
  18. package/dist/components-harmony-ets/swiper.ets +23 -19
  19. package/dist/components-harmony-ets/switch.ets +1 -1
  20. package/dist/components-harmony-ets/text.ets +28 -22
  21. package/dist/components-harmony-ets/textArea.ets +1 -1
  22. package/dist/components-harmony-ets/utils/styles.ets +2 -2
  23. package/dist/components-harmony-ets/video.ets +26 -21
  24. package/dist/components-harmony-ets/view.ets +34 -30
  25. package/dist/components-harmony-ets/webView.ets +37 -32
  26. package/dist/index.js +36 -16
  27. package/dist/index.js.map +1 -1
  28. package/dist/runtime-ets/dom/element/element.ts +0 -4
  29. package/dist/runtime-ets/dom/element/form.ts +11 -4
  30. package/dist/runtime-ets/dom/element/index.ts +9 -1
  31. package/dist/runtime-ets/dom/element/movableArea.ts +12 -0
  32. package/dist/runtime-ets/dom/element/movableView.ts +12 -0
  33. package/dist/runtime-ets/dom/element/normal.ts +8 -2
  34. package/dist/runtime-ets/dom/element/progress.ts +13 -0
  35. package/dist/runtime-ets/dom/element/scrollView.ts +1 -0
  36. package/dist/runtime-ets/dom/element/text.ts +1 -0
  37. package/dist/runtime-ets/dom/element/video.ts +1 -0
  38. package/dist/runtime-ets/dom/element/webView.ts +8 -0
  39. package/dist/runtime-ets/dom/node.ts +18 -17
  40. package/dist/runtime-utils.js +43 -21
  41. package/dist/runtime-utils.js.map +1 -1
  42. package/dist/runtime.js +43 -21
  43. package/dist/runtime.js.map +1 -1
  44. package/package.json +8 -8
@@ -14,37 +14,42 @@ interface IError {
14
14
  error: WebResourceError
15
15
  }
16
16
 
17
- @Builder
18
- export default function TaroWebView (node: TaroWebViewElement) {
19
- Web({ src: node._attrs.src, controller: node.controller })
20
- .attributeModifier(commonStyleModify.setNode(node))
21
- .onPageEnd((e: IPageLoad) => {
22
- // 1. 创建消息端口
23
- node.ports = node.controller.createWebMessagePorts(true)
24
- // 2. 发送端口1到HTML5
25
- node.controller.postMessage('init_web_messageport', [node.ports[1]], '*');
26
- // 3. 保存端口0到本地
27
- node.nativePort = node.ports[0]
28
- // 4. 设置回调函数
29
- node.nativePort.onMessageEventExt((result) => {
30
- const message = node.handleMessageFromWeb(result)
31
- const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, node)
32
-
33
- eventHandler(messageEvent, 'message', node)
17
+ @Component
18
+ export default struct TaroWebView {
19
+ @ObjectLink node: TaroWebViewElement
20
+
21
+ build () {
22
+ Web({ src: this.node._attrs.src, controller: this.node.controller })
23
+ .attributeModifier(commonStyleModify.setNode(this.node))
24
+ .onPageEnd((e: IPageLoad) => {
25
+ // 1. 创建消息端口
26
+ this.node.ports = this.node.controller.createWebMessagePorts(true)
27
+ // 2. 发送端口1到HTML5
28
+ this.node.controller.postMessage('init_web_messageport', [this.node.ports[1]], '*');
29
+ // 3. 保存端口0到本地
30
+ this.node.nativePort = this.node.ports[0]
31
+ // 4. 设置回调函数
32
+ this.node.nativePort.onMessageEventExt((result) => {
33
+ const message = this.node.handleMessageFromWeb(result)
34
+ const messageEvent: TaroEvent = createTaroEvent('message', { detail: { data: message } }, this.node)
35
+
36
+ eventHandler(messageEvent, 'message', this.node)
37
+ })
38
+
39
+ const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: this.node._attrs.src } }, this.node)
40
+
41
+ eventHandler(onLoadEvent, 'load', this.node)
34
42
  })
35
-
36
- const onLoadEvent: TaroEvent = createTaroEvent('load', { detail: { src: node._attrs.src } }, node)
37
-
38
- eventHandler(onLoadEvent, 'load', node)
39
- })
40
- .onErrorReceive(shouldBindEvent((e: IError) => {
41
- const event: TaroEvent = createTaroEvent('error', { detail: { url: node._attrs.src, fullUrl: e.request.getRequestUrl() } }, node)
42
-
43
- eventHandler(event, 'error', node)
44
- }, node, ['error']))
45
- .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', node), node, ['click']))
46
- .onAreaChange(getComponentEventCallback(node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
47
- node._nodeInfo.areaInfo = res[1]
48
- }))
49
- .onVisibleAreaChange(getNodeThresholds(node) || [0.0, 1.0], getComponentEventCallback(node, VISIBLE_CHANGE_EVENT_NAME))
43
+ .onErrorReceive(shouldBindEvent((e: IError) => {
44
+ const event: TaroEvent = createTaroEvent('error', { detail: { url: this.node._attrs.src, fullUrl: e.request.getRequestUrl() } }, this.node)
45
+
46
+ eventHandler(event, 'error', this.node)
47
+ }, this.node, ['error']))
48
+ .onClick(shouldBindEvent((e: ClickEvent) => eventHandler(e, 'click', this.node), this.node, ['click']))
49
+ .onAreaChange(getComponentEventCallback(this.node, AREA_CHANGE_EVENT_NAME, (res: TaroAny) => {
50
+ this.node._nodeInfo.areaInfo = res[1]
51
+ }))
52
+ .onVisibleAreaChange(getNodeThresholds(this.node) || [0.0, 1.0], getComponentEventCallback(this.node, VISIBLE_CHANGE_EVENT_NAME))
53
+
54
+ }
50
55
  }
package/dist/index.js CHANGED
@@ -158,7 +158,7 @@ export {
158
158
  const PLATFORM_NAME = 'harmony';
159
159
  const PACKAGE_NAME = '@tarojs/plugin-platform-harmony-ets';
160
160
  const PLUGIN_NAME = 'TaroHarmony';
161
- const HARMONY_SCOPES = [/^@system\./, /^@ohos\./, /^@hmscore\//];
161
+ const HARMONY_SCOPES = [/^@system\./, /^@ohos\./, /^@hmscore\//, /^@jd-oh\//];
162
162
 
163
163
  function parseRelativePath(from, to) {
164
164
  const relativePath = path.relative(from, to).replace(/\\/g, '/');
@@ -372,8 +372,8 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
372
372
  return;
373
373
  if (this.excludeLibraries.some(e => typeof e === 'string' ? e === lib : e.test(lib)))
374
374
  return;
375
+ const { outputRoot, chorePackagePrefix } = this.ctx.runOpts.config;
375
376
  if (sync) {
376
- const { outputRoot } = this.ctx.runOpts.config;
377
377
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES);
378
378
  // FIXME 不支持 alias 配置
379
379
  const libName = lib;
@@ -479,6 +479,7 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
479
479
  code = apiLoader(code);
480
480
  }
481
481
  if (this.extensions.includes(path__namespace.extname(lib))) {
482
+ // Note: 查询 externals 内的依赖,并将它们添加到 externalDeps 中
482
483
  code = code.replace(/(?:import\s|from\s|require\()['"]([^.][^'"\s]+)['"]\)?/g, (src, p1) => {
483
484
  const { outputRoot } = this.ctx.runOpts.config;
484
485
  const targetPath = path__namespace.join(outputRoot, helper.NODE_MODULES, p1);
@@ -502,8 +503,10 @@ let Harmony$1 = class Harmony extends TaroPlatformHarmony {
502
503
  code = '// @ts-nocheck\n' + code;
503
504
  }
504
505
  }
505
- if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
506
- code = `/// <reference path="global.d.ts" />
506
+ // Note: 传入 chorePackagePrefix 时,不生成核心依赖库
507
+ if (!chorePackagePrefix) {
508
+ if (/tarojs[\\/]taro[\\/]types[\\/]index.d.ts/.test(target)) {
509
+ code = `/// <reference path="global.d.ts" />
507
510
 
508
511
  /// <reference path="taro.api.d.ts" />
509
512
  /// <reference path="taro.component.d.ts" />
@@ -523,14 +526,15 @@ declare global {
523
526
  const defineAppConfig: (config: Taro.Config) => Taro.Config
524
527
  const definePageConfig: (config: Taro.Config) => Taro.Config
525
528
  }`;
526
- }
527
- try {
528
- const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
529
- helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
530
- helper.fs.writeFileSync(targetPath, code);
531
- }
532
- catch (e) {
533
- console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
529
+ }
530
+ try {
531
+ const targetPath = target.replace(new RegExp(`\\b${helper.NODE_MODULES}\\b`), 'npm');
532
+ helper.fs.ensureDirSync(path__namespace.dirname(targetPath));
533
+ helper.fs.writeFileSync(targetPath, code);
534
+ }
535
+ catch (e) {
536
+ console.error(`[taro-arkts] inject ${lib} to ${target} failed`, e);
537
+ }
534
538
  }
535
539
  }
536
540
  else if (stat.isSymbolicLink()) {
@@ -552,7 +556,7 @@ declare global {
552
556
  const that = this;
553
557
  const { appPath } = that.ctx.paths;
554
558
  const { config } = that.ctx.runOpts;
555
- const { outputRoot } = config;
559
+ const { outputRoot, ohPackage = {}, chorePackagePrefix } = config;
556
560
  if (!that.framework.includes('vue')) {
557
561
  that.excludeLibraries.push(/\bvue\b/);
558
562
  }
@@ -568,7 +572,22 @@ declare global {
568
572
  /^solid-js\/universal$/,
569
573
  ]);
570
574
  }
575
+ const externals = Object.keys(ohPackage.dependencies || []).concat(Object.keys(ohPackage.devDependencies || []));
571
576
  function modifyResolveId({ source = '', importer = '', options = {}, name = 'modifyResolveId', resolve }) {
577
+ if (externals.includes(source)) {
578
+ return {
579
+ external: true,
580
+ id: source,
581
+ resolvedBy: name,
582
+ };
583
+ }
584
+ if (chorePackagePrefix && that.indexOfLibraries(source) > -1) {
585
+ return {
586
+ external: true,
587
+ id: path__namespace.join(chorePackagePrefix, source),
588
+ resolvedBy: name,
589
+ };
590
+ }
572
591
  if (shared.isFunction(resolve)) {
573
592
  if (source === that.runtimePath || that.runtimePath.includes(source)) {
574
593
  return resolve('@tarojs/runtime', importer, options);
@@ -1151,7 +1170,7 @@ class Harmony extends service.TaroPlatformBase {
1151
1170
  const outDir = path.join(compsOutDir, name);
1152
1171
  helper.fs.copy(src, outDir);
1153
1172
  });
1154
- this.modifyHostPackageDep(outDir);
1173
+ this.modifyHostPackage(config.harmony);
1155
1174
  });
1156
1175
  }
1157
1176
  modifyWebpackConfig() {
@@ -1214,13 +1233,13 @@ class Harmony extends service.TaroPlatformBase {
1214
1233
  console.warn(helper.chalk.red('设置鸿蒙 Hap 配置失败:', err));
1215
1234
  });
1216
1235
  }
1217
- modifyHostPackageDep(dest) {
1236
+ modifyHostPackage({ projectPath, hapName = 'entry' }) {
1218
1237
  return __awaiter(this, void 0, void 0, function* () {
1238
+ const packageJsonFile = path.join(projectPath, hapName, 'package.json');
1219
1239
  const hmsDeps = {
1220
1240
  '@hmscore/hms-js-base': '^6.1.0-300',
1221
1241
  '@hmscore/hms-jsb-account': '^1.0.300'
1222
1242
  };
1223
- const packageJsonFile = path.resolve(dest, '../../../../../package.json');
1224
1243
  const isExists = yield helper.fs.pathExists(packageJsonFile);
1225
1244
  if (!isExists)
1226
1245
  return;
@@ -1237,6 +1256,7 @@ class Harmony extends service.TaroPlatformBase {
1237
1256
  }
1238
1257
  packageJson = JSON.stringify(packageJson);
1239
1258
  yield helper.fs.writeFile(packageJsonFile, packageJson);
1259
+ return packageJson;
1240
1260
  });
1241
1261
  }
1242
1262
  getChunkEntryModule(compilation, chunk, compiler = 'webpack4') {