From 60d2b64aa5a321c0b3d8845e5862673d20c8d83d Mon Sep 17 00:00:00 2001 From: roymondchen Date: Tue, 13 Aug 2024 20:24:24 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E8=BF=AD=E4=BB=A3=E5=99=A8=E5=86=85?= =?UTF-8?q?=E7=9A=84=E7=BB=84=E4=BB=B6=E9=85=8D=E7=BD=AE=E4=BA=86=E5=A3=B0?= =?UTF-8?q?=E6=98=8E=E5=91=A8=E6=9C=9F=E4=BB=A3=E7=A0=81=E5=9D=97=E6=97=A0?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/data-source/src/DataSourceManager.ts | 21 ++---- packages/schema/src/index.ts | 5 ++ packages/utils/src/index.ts | 5 +- runtime/vue-runtime-help/package.json | 2 +- .../src/{useApp.ts => hooks/use-app.ts} | 14 ++-- runtime/vue-runtime-help/src/index.ts | 2 +- vue-components/button/src/index.vue | 15 ++-- vue-components/container/src/Container.vue | 33 ++++++--- vue-components/img/src/index.vue | 15 ++-- .../iterator-container/package.json | 1 - .../src/IteratorContainer.vue | 72 +++++++++---------- vue-components/overlay/package.json | 1 - vue-components/overlay/src/index.vue | 20 +++--- vue-components/overlay/src/initValue.ts | 1 + .../page-fragment-container/package.json | 1 - .../src/PageFragmentContainer.vue | 25 ++++--- vue-components/page-fragment/package.json | 1 - .../page-fragment/src/PageFragment.vue | 18 +++-- vue-components/page/package.json | 1 - vue-components/page/src/index.vue | 13 ++-- vue-components/qrcode/src/index.vue | 16 ++++- vue-components/text/src/index.vue | 14 +++- 22 files changed, 163 insertions(+), 133 deletions(-) rename runtime/vue-runtime-help/src/{useApp.ts => hooks/use-app.ts} (75%) diff --git a/packages/data-source/src/DataSourceManager.ts b/packages/data-source/src/DataSourceManager.ts index 4007c961..433421b2 100644 --- a/packages/data-source/src/DataSourceManager.ts +++ b/packages/data-source/src/DataSourceManager.ts @@ -20,7 +20,7 @@ import EventEmitter from 'events'; import { cloneDeep } from 'lodash-es'; -import type { default as TMagicApp, IteratorContainer as TMagicIteratorContainer } from '@tmagic/core'; +import type { default as TMagicApp } from '@tmagic/core'; import type { DataSourceSchema, DisplayCond, Id, MNode, NODE_CONDS_KEY } from '@tmagic/schema'; import { compiledNode } from '@tmagic/utils'; @@ -227,7 +227,7 @@ class DataSourceManager extends EventEmitter { * @returns {boolean}是否显示 */ public compliedIteratorItemConds( - itemData: any[], + itemData: any, node: { [NODE_CONDS_KEY]?: DisplayCond[] }, dataSourceField: string[] = [], ) { @@ -239,23 +239,10 @@ class DataSourceManager extends EventEmitter { return compliedConditions(node, ctxData); } - public compliedIteratorItems( - nodeId: Id, - itemData: any, - nodes: MNode[], - dataSourceField: string[] = [], - dataIteratorContainerId?: Id[], - dataIteratorIndex?: number[], - ) { - const iteratorContainer = this.app.getNode( - nodeId, - dataIteratorContainerId, - dataIteratorIndex, - ); - + public compliedIteratorItems(itemData: any, nodes: MNode[], dataSourceField: string[] = []): MNode[] { const [dsId, ...keys] = dataSourceField; const ds = this.get(dsId); - if (!ds || !iteratorContainer) return nodes; + if (!ds) return nodes; const ctxData = createIteratorContentData(itemData, ds.id, keys, this.data); diff --git a/packages/schema/src/index.ts b/packages/schema/src/index.ts index 0974ba97..93f07227 100644 --- a/packages/schema/src/index.ts +++ b/packages/schema/src/index.ts @@ -206,6 +206,11 @@ export interface PastePosition { export type MNode = MComponent | MContainer | MIteratorContainer | MPage | MApp | MPageFragment; +export interface MNodeInstance extends Omit { + id?: Id; + type?: string; +} + export enum HookType { /** 代码块钩子标识 */ CODE = 'code', diff --git a/packages/utils/src/index.ts b/packages/utils/src/index.ts index 115054cc..89134869 100644 --- a/packages/utils/src/index.ts +++ b/packages/utils/src/index.ts @@ -20,7 +20,7 @@ import dayjs from 'dayjs'; import utc from 'dayjs/plugin/utc'; import { cloneDeep, set as objectSet } from 'lodash-es'; -import type { DataSchema, DataSourceDeps, Id, MComponent, MNode } from '@tmagic/schema'; +import type { DataSchema, DataSourceDeps, Id, MComponent, MNode, MNodeInstance } from '@tmagic/schema'; import { NodeType } from '@tmagic/schema'; export * from './dom'; @@ -449,3 +449,6 @@ export const addParamToUrl = (obj: Record, global = globalThis, nee }; export const dataSourceTemplateRegExp = /\$\{([\s\S]+?)\}/g; + +export const isDslNode = (config: MNodeInstance) => + typeof config[IS_DSL_NODE_KEY] === 'undefined' || config[IS_DSL_NODE_KEY] === true; diff --git a/runtime/vue-runtime-help/package.json b/runtime/vue-runtime-help/package.json index 5c20f54c..3437ce18 100644 --- a/runtime/vue-runtime-help/package.json +++ b/runtime/vue-runtime-help/package.json @@ -7,7 +7,7 @@ "types": "dist/index.d.ts", "exports": { ".": { - "types": "./types/index.d.ts", + "types": "./dist/index.d.ts", "import": "./dist/index.js" }, "./*": "./*" diff --git a/runtime/vue-runtime-help/src/useApp.ts b/runtime/vue-runtime-help/src/hooks/use-app.ts similarity index 75% rename from runtime/vue-runtime-help/src/useApp.ts rename to runtime/vue-runtime-help/src/hooks/use-app.ts index 34329cc8..04111342 100644 --- a/runtime/vue-runtime-help/src/useApp.ts +++ b/runtime/vue-runtime-help/src/hooks/use-app.ts @@ -19,10 +19,10 @@ import { inject, onBeforeUnmount, onMounted } from 'vue-demi'; import type TMagicApp from '@tmagic/core'; -import type { Id, MNode } from '@tmagic/schema'; -import { IS_DSL_NODE_KEY } from '@tmagic/utils'; +import type { Id, MNodeInstance } from '@tmagic/schema'; +import { isDslNode } from '@tmagic/utils'; -interface UseAppOptions { +interface UseAppOptions { config: T; iteratorContainerId?: Id[]; iteratorIndex?: number[]; @@ -31,9 +31,7 @@ interface UseAppOptions { }; } -const isDslNode = (config: MNode) => typeof config[IS_DSL_NODE_KEY] === 'undefined' || config[IS_DSL_NODE_KEY] === true; - -export default ({ methods, config, iteratorContainerId, iteratorIndex }: UseAppOptions) => { +export const useApp = ({ methods = {}, config, iteratorContainerId, iteratorIndex }: UseAppOptions) => { const app: TMagicApp | undefined = inject('app'); const emitData = { @@ -41,7 +39,7 @@ export default ({ methods, config, iteratorContainerId, iteratorIndex }: UseAppO ...methods, }; - const display = (config: T) => { + const display = (config: T) => { if (config.visible === false) return false; if (config.condResult === false) return false; @@ -54,7 +52,7 @@ export default ({ methods, config, iteratorContainerId, iteratorIndex }: UseAppO return displayCfg !== false; }; - const node = isDslNode(config) ? app?.getNode(config.id || '', iteratorContainerId, iteratorIndex) : undefined; + const node = isDslNode(config) && config.id ? app?.getNode(config.id, iteratorContainerId, iteratorIndex) : undefined; if (node) { node.emit('created', emitData); diff --git a/runtime/vue-runtime-help/src/index.ts b/runtime/vue-runtime-help/src/index.ts index f3f9685c..2898095d 100644 --- a/runtime/vue-runtime-help/src/index.ts +++ b/runtime/vue-runtime-help/src/index.ts @@ -1,3 +1,3 @@ export * from './hooks/use-editor-dsl'; export * from './hooks/use-dsl'; -export { default as useApp } from './useApp'; +export * from './hooks/use-app'; diff --git a/vue-components/button/src/index.vue b/vue-components/button/src/index.vue index 72c27a35..5e27a758 100644 --- a/vue-components/button/src/index.vue +++ b/vue-components/button/src/index.vue @@ -1,7 +1,7 @@ @@ -9,11 +9,12 @@ diff --git a/vue-components/page/package.json b/vue-components/page/package.json index 547a0bd5..a03c5c10 100644 --- a/vue-components/page/package.json +++ b/vue-components/page/package.json @@ -19,7 +19,6 @@ "peerDependencies": { "@tmagic/utils": "workspace:*", "@tmagic/schema": "workspace:*", - "@tmagic/vue-container": "workspace:*", "@tmagic/vue-runtime-help": "workspace:*", "typescript": "*" }, diff --git a/vue-components/page/src/index.vue b/vue-components/page/src/index.vue index b01f03ff..db334beb 100644 --- a/vue-components/page/src/index.vue +++ b/vue-components/page/src/index.vue @@ -1,19 +1,14 @@ diff --git a/vue-components/qrcode/src/index.vue b/vue-components/qrcode/src/index.vue index 3dc476d2..71798f35 100644 --- a/vue-components/qrcode/src/index.vue +++ b/vue-components/qrcode/src/index.vue @@ -1,20 +1,28 @@