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 @@