mirror of
https://github.com/Tencent/tmagic-editor.git
synced 2025-04-05 19:41:40 +08:00
1 line
10 KiB
Plaintext
1 line
10 KiB
Plaintext
{"version":3,"file":"playground.js","sources":["../../vite/preload-helper","../../src/playground/App.vue","../../src/playground/main.ts"],"sourcesContent":["const scriptRel = 'modulepreload';const seen = {};const base = '/tmagic-editor/playground/runtime/vue3/';export const __vitePreload = function preload(baseModule, deps) {\n // @ts-ignore\n if (!__VITE_IS_MODERN__ || !deps || deps.length === 0) {\n return baseModule();\n }\n return Promise.all(deps.map((dep) => {\n // @ts-ignore\n dep = `${base}${dep}`;\n // @ts-ignore\n if (dep in seen)\n return;\n // @ts-ignore\n seen[dep] = true;\n const isCss = dep.endsWith('.css');\n const cssSelector = isCss ? '[rel=\"stylesheet\"]' : '';\n // @ts-ignore check if the file is already preloaded by SSR markup\n if (document.querySelector(`link[href=\"${dep}\"]${cssSelector}`)) {\n return;\n }\n // @ts-ignore\n const link = document.createElement('link');\n // @ts-ignore\n link.rel = isCss ? 'stylesheet' : scriptRel;\n if (!isCss) {\n link.as = 'script';\n link.crossOrigin = '';\n }\n link.href = dep;\n // @ts-ignore\n document.head.appendChild(link);\n if (isCss) {\n return new Promise((res, rej) => {\n link.addEventListener('load', res);\n link.addEventListener('error', () => rej(new Error(`Unable to preload CSS for ${dep}`)));\n });\n }\n })).then(() => baseModule());\n}","<template>\n <magic-ui-page v-if=\"pageConfig\" :config=\"pageConfig\"></magic-ui-page>\n</template>\n\n<script lang=\"ts\">\nimport { computed, defineComponent, nextTick, onMounted, provide, reactive, ref, watch } from 'vue';\n\nimport Core from '@tmagic/core';\nimport { Id, MApp, MNode } from '@tmagic/schema';\nimport { Magic, RemoveData, UpdateData } from '@tmagic/stage';\nimport { getNodePath } from '@tmagic/utils';\n\ndeclare global {\n interface Window {\n magic: Magic;\n }\n}\n\nexport default defineComponent({\n setup() {\n const root = ref<MApp>();\n const curPageId = ref<Id>();\n const selectedId = ref<Id>();\n\n const pageConfig = computed(\n () => root.value?.items?.find((item: MNode) => item.id === curPageId.value) || root.value?.items?.[0],\n );\n\n const app = new Core({\n config: root.value,\n platform: 'editor',\n });\n\n provide('app', app);\n\n watch(pageConfig, async () => {\n await nextTick();\n const page = document.querySelector<HTMLElement>('.magic-ui-page');\n page && window.magic.onPageElUpdate(page);\n });\n\n onMounted(() => {\n window.magic?.onRuntimeReady({\n updateRootConfig(config: MApp) {\n console.log('update config', config);\n root.value = config;\n app?.setConfig(config, curPageId.value);\n },\n\n updatePageId(id: Id) {\n console.log('update page id', id);\n curPageId.value = id;\n app?.setPage(id);\n },\n\n getSnapElements() {\n return Array.from(document.querySelectorAll<HTMLElement>('[class*=magic-ui][id]'));\n },\n\n select(id: Id) {\n console.log('select config', id);\n selectedId.value = id;\n const el = document.getElementById(`${id}`);\n if (el) return el;\n // 未在当前文档下找到目标元素,可能是还未渲染,等待渲染完成后再尝试获取\n return nextTick().then(() => document.getElementById(`${id}`) as HTMLElement);\n },\n\n add({ config }: UpdateData) {\n console.log('add config', config);\n if (!root.value) throw new Error('error');\n if (!selectedId.value) throw new Error('error');\n const path = getNodePath(selectedId.value, [root.value]);\n const node = path.pop();\n const parent = node?.items ? node : path.pop();\n if (!parent) throw new Error('未找到父节点');\n parent.items?.push(config);\n },\n\n update({ config }: UpdateData) {\n console.log('update config', config);\n if (!root.value) throw new Error('error');\n const path = getNodePath(config.id, [root.value]);\n const node = path.pop();\n const parent = path.pop();\n if (!node) throw new Error('未找到目标节点');\n if (!parent) throw new Error('未找到父节点');\n const index = parent.items?.findIndex((child: MNode) => child.id === node.id);\n parent.items.splice(index, 1, reactive(config));\n },\n\n remove({ id }: RemoveData) {\n if (!root.value) throw new Error('error');\n const path = getNodePath(id, [root.value]);\n const node = path.pop();\n if (!node) throw new Error('未找到目标元素');\n const parent = path.pop();\n if (!parent) throw new Error('未找到父元素');\n const index = parent.items?.findIndex((child: MNode) => child.id === node.id);\n parent.items.splice(index, 1);\n },\n });\n });\n\n return {\n pageConfig,\n };\n },\n});\n</script>\n\n<style lang=\"scss\">\nhtml,\nbody,\n#app {\n width: 100%;\n height: 100%;\n}\n\n#app {\n position: relative;\n overflow: auto;\n\n &::-webkit-scrollbar {\n width: 0;\n }\n}\n\n.magic-ui-container {\n background-color: rgba(136, 136, 136, 0.5);\n}\n\n.action-area {\n background-color: rgba(51, 153, 255, 0.5) !important;\n}\n</style>\n","/*\n * Tencent is pleased to support the open source community by making TMagicEditor available.\n *\n * Copyright (C) 2021 THL A29 Limited, a Tencent company. All rights reserved.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\");\n * you may not use this file except in compliance with the License.\n * You may obtain a copy of the License at\n *\n * http://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS,\n * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n * See the License for the specific language governing permissions and\n * limitations under the License.\n */\n\nimport { createApp } from 'vue';\n\nimport App from './App.vue';\n\nconst componentUrl = '/tmagic-editor/playground/runtime/vue3/assets/components.js';\n\nimport(componentUrl).then(() => {\n const magicApp = createApp(App);\n const { components, plugins } = window.magicPresetComponents;\n\n Object.values(components).forEach((component: any) => {\n magicApp.component(component.name, component);\n });\n\n Object.values(plugins).forEach((plugin: any) => {\n magicApp.use(plugin);\n });\n\n magicApp.mount('#app');\n});\n"],"names":["Core"],"mappings":";;;AAAA,MAAM,YAAY;AAAgB,MAAM,OAAO,CAAE;AAAC,MAAM,OAAO;AAAiD,MAAM,gBAAgB,iBAAiB,YAAY,MAAM;AAErK,MAAI,AAAuB,CAAC,QAAQ,KAAK,WAAW,GAAG;AACnD,WAAO,WAAU;AAAA,EACpB;AACD,SAAO,QAAQ,IAAI,KAAK,IAAI,CAAC,QAAQ;AAEjC,UAAM,GAAG,OAAO;AAEhB,QAAI,OAAO;AACP;AAEJ,SAAK,OAAO;AACZ,UAAM,QAAQ,IAAI,SAAS,MAAM;AACjC,UAAM,cAAc,Q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