Skip to content

Commit

Permalink
fix(vue-runtime-help): inject app 无效
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen committed May 31, 2024
1 parent 3b87589 commit aa25aa6
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 67 deletions.
84 changes: 37 additions & 47 deletions pnpm-lock.yaml

Large diffs are not rendered by default.

17 changes: 13 additions & 4 deletions runtime/vue-runtime-help/package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "0.0.2",
"version": "0.0.3",
"name": "@tmagic/vue-runtime-help",
"type": "module",
"sideEffects": false,
Expand All @@ -26,25 +26,34 @@
"url": "https://github.com/Tencent/tmagic-editor.git"
},
"dependencies": {
"@tmagic/stage": "workspace:*",
"vue-demi": "^0.14.7"
},
"peerDependencies": {
"@tmagic/core": "workspace:*",
"@tmagic/data-source": "workspace:*",
"@tmagic/schema": "workspace:*",
"@tmagic/stage": "workspace:*",
"@tmagic/utils": "workspace:*",
"@vue/composition-api": ">=1.7.2",
"typescript": "*",
"vue": ">=2.0.0 || >=3.0.0"
},
"peerDependenciesMeta": {
"@vue/composition-api": {
"optional": true
},
"@tmagic/schema": {
"optional": true
},
"@tmagic/stage": {
"optional": true
},
"typescript": {
"optional": true
}
},
"devDependencies": {
"@types/node": "^18.19.0",
"rimraf": "^3.0.2",
"typescript": "^5.4.5"
"rimraf": "^3.0.2"
}
}
5 changes: 2 additions & 3 deletions runtime/vue-runtime-help/src/hooks/use-dsl.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
import { inject, nextTick, reactive, ref } from 'vue-demi';
import { nextTick, reactive, ref } from 'vue-demi';

import Core from '@tmagic/core';
import type { ChangeEvent } from '@tmagic/data-source';
import type { MNode } from '@tmagic/schema';
import { isPage, replaceChildNode } from '@tmagic/utils';

export const useDsl = () => {
const app = inject<Core | undefined>('app');
export const useDsl = (app: Core | undefined) => {
const pageConfig = ref(app?.page?.data || {});

app?.dataSourceManager?.on('update-data', (nodes: MNode[], sourceId: string, changeEvent: ChangeEvent) => {
Expand Down
6 changes: 2 additions & 4 deletions runtime/vue-runtime-help/src/hooks/use-editor-dsl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { computed, inject, nextTick, reactive, ref, watch } from 'vue-demi';
import { computed, nextTick, reactive, ref, watch } from 'vue-demi';

import Core from '@tmagic/core';
import type { Id, MApp, MNode } from '@tmagic/schema';
Expand All @@ -11,9 +11,7 @@ declare global {
}
}

export const useEditorDsl = (win = window) => {
const app = inject<Core | undefined>('app');

export const useEditorDsl = (app: Core | undefined, win = window) => {
const root = ref<MApp>();
const curPageId = ref<Id>();
const selectedId = ref<Id>();
Expand Down
3 changes: 2 additions & 1 deletion runtime/vue2/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@
"@tmagic/data-source": "1.4.7",
"@tmagic/ui-vue2": "1.4.7",
"@tmagic/schema": "1.4.7",
"@tmagic/stage": "1.4.7",
"@tmagic/utils": "1.4.7",
"@tmagic/vue-runtime-help": "^0.0.2",
"@tmagic/vue-runtime-help": "^0.0.3",
"axios": "^0.25.0",
"terser": "^5.31.0",
"vue": "^2.7.4"
Expand Down
3 changes: 1 addition & 2 deletions runtime/vue2/page/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ export default defineComponent({
name: 'App',
setup() {
const { pageConfig } = useDsl();
const app = inject<Core | undefined>('app');
const { pageConfig } = useDsl(app);
app?.on('page-change', (page?: Page) => {
if (!page) {
Expand Down
5 changes: 3 additions & 2 deletions runtime/vue2/playground/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
</template>

<script lang="ts">
import { defineComponent } from 'vue';
import { defineComponent, inject } from 'vue';
import { useEditorDsl } from '@tmagic/vue-runtime-help';
export default defineComponent({
setup() {
const { pageConfig } = useEditorDsl();
const app = inject<Core | undefined>('app');
const { pageConfig } = useEditorDsl(app);
return {
pageConfig,
Expand Down
3 changes: 2 additions & 1 deletion runtime/vue3/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@
"@tmagic/core": "1.4.7",
"@tmagic/ui": "1.4.7",
"@tmagic/schema": "1.4.7",
"@tmagic/stage": "1.4.7",
"@tmagic/utils": "1.4.7",
"@tmagic/vue-runtime-help": "^0.0.2",
"@tmagic/vue-runtime-help": "^0.0.3",
"axios": "^0.25.0",
"vue": "^3.4.27"
},
Expand Down
3 changes: 1 addition & 2 deletions runtime/vue3/page/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ import Core from '@tmagic/core';
import { addParamToUrl } from '@tmagic/utils';
import { useDsl } from '@tmagic/vue-runtime-help';
const { pageConfig } = useDsl();
const app = inject<Core | undefined>('app');
const { pageConfig } = useDsl(app);
app?.on('page-change', (page?: Page) => {
if (!page) {
Expand Down
5 changes: 4 additions & 1 deletion runtime/vue3/playground/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
</template>

<script lang="ts" setup>
import { inject } from 'vue';
import { useEditorDsl } from '@tmagic/vue-runtime-help';
const { pageConfig } = useEditorDsl();
const app = inject<Core | undefined>('app');
const { pageConfig } = useEditorDsl(app);
</script>

0 comments on commit aa25aa6

Please sign in to comment.