@opentiny/vue-docs 2.0.0 → 2.0.1

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 (2) hide show
  1. package/package.json +5 -4
  2. package/playground/App.vue +28 -14
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentiny/vue-docs",
3
- "version": "2.0.0",
3
+ "version": "2.0.1",
4
4
  "dependencies": {
5
5
  "@unocss/reset": "0.38.2",
6
6
  "@vue/repl": "^2.5.5",
@@ -15,15 +15,16 @@
15
15
  "dompurify": "^3.0.1",
16
16
  "@playwright/test": "^1.29.2",
17
17
  "sortablejs": "1.15.0",
18
+ "@opentiny/vue-repl": "^1.0.2",
18
19
  "@opentiny/vue": "~3.10.0",
19
20
  "@opentiny/vue-common": "~3.10.0",
20
21
  "@opentiny/vue-icon": "~3.10.0",
21
- "@opentiny/vue-design-smb": "~3.10.0",
22
22
  "@opentiny/vue-design-aurora": "~3.10.0",
23
+ "@opentiny/vue-design-smb": "~3.10.0",
24
+ "@opentiny/vue-theme": "~3.10.0",
23
25
  "@opentiny/vue-theme-saas": "~3.10.0",
24
- "@opentiny/vue-theme-mobile": "~3.10.0",
25
26
  "@opentiny/vue-vite-import": "~1.1.5",
26
- "@opentiny/vue-theme": "~3.10.0"
27
+ "@opentiny/vue-theme-mobile": "~3.10.0"
27
28
  },
28
29
  "devDependencies": {
29
30
  "@types/markdown-it": "^12.2.3",
@@ -1,8 +1,8 @@
1
1
  <script setup>
2
2
  import { reactive, ref } from 'vue'
3
- import { Repl, ReplStore, File } from '@vue/repl'
3
+ import { Repl, useStore, File } from '@opentiny/vue-repl'
4
+ import '@opentiny/vue-repl/dist/style.css'
4
5
  import Monaco from '@vue/repl/monaco-editor'
5
- import '@vue/repl/style.css'
6
6
  import { ButtonGroup as TinyButtonGroup, Select as TinySelect, Option as TinyOption, Notify } from '@opentiny/vue'
7
7
  import { staticDemoPath, getWebdocPath } from '@/views/components/cmpConfig'
8
8
  import { fetchDemosFile } from '@/tools/utils'
@@ -12,16 +12,17 @@ import Sun from './icons/Sun.vue'
12
12
  import Moon from './icons/Moon.vue'
13
13
  import Share from './icons/Share.vue'
14
14
 
15
- const versions = ['3.9.1', '3.8.4']
15
+ const versions = ['3.10.0', '3.9.1', '3.8.4']
16
16
  const latestVersion = versions[0]
17
+ const cdnHost = 'https://unpkg.com'
17
18
 
18
19
  const createImportMap = (version) => {
19
20
  return {
20
21
  imports: {
21
- '@opentiny/vue': `https://unpkg.com/@opentiny/vue@${version}/runtime/tiny-vue.mjs`,
22
- '@opentiny/vue-icon': `https://unpkg.com/@opentiny/vue@${version}/runtime/tiny-vue-icon.mjs`,
23
- '@opentiny/vue-locale': `https://unpkg.com/@opentiny/vue@${version}/runtime/tiny-vue-locale.mjs`,
24
- '@opentiny/vue-common': `https://unpkg.com/@opentiny/vue@${version}/runtime/tiny-vue-common.mjs`
22
+ '@opentiny/vue': `${cdnHost}/@opentiny/vue@${version}/runtime/tiny-vue.mjs`,
23
+ '@opentiny/vue-icon': `${cdnHost}/@opentiny/vue@${version}/runtime/tiny-vue-icon.mjs`,
24
+ '@opentiny/vue-locale': `${cdnHost}/@opentiny/vue@${version}/runtime/tiny-vue-locale.mjs`,
25
+ '@opentiny/vue-common': `${cdnHost}/@opentiny/vue@${version}/runtime/tiny-vue-common.mjs`
25
26
  }
26
27
  }
27
28
  }
@@ -29,10 +30,15 @@ const createImportMap = (version) => {
29
30
  const hash = location.hash.slice(1)
30
31
  const shareData = hash.split('|')
31
32
 
32
- const store = new ReplStore({
33
+ const store = new useStore({
33
34
  serializedState: shareData.length === 2 ? shareData[1] : '',
34
35
  showOutput: true,
35
- outputMode: 'preview'
36
+ outputMode: 'preview',
37
+ versions: {
38
+ vue: '3.2.47',
39
+ opentiny: latestVersion,
40
+ typescript: '5.1.3'
41
+ }
36
42
  })
37
43
 
38
44
  // 切换主题
@@ -58,10 +64,19 @@ const state = reactive({
58
64
  function versionChange(version) {
59
65
  const importMap = createImportMap(version)
60
66
  store.setImportMap(importMap)
61
- state.previewOptions.headHTML = `<link rel="stylesheet" href="https://unpkg.com/@opentiny/vue-theme@${version}/index.css">`
62
- }
63
67
 
64
- const langReg = / lang="jsx"/
68
+ const iframeWin = document.querySelector('iframe').contentWindow
69
+ const styleDom = iframeWin.document.getElementById('tiny-theme')
70
+ if (styleDom) {
71
+ styleDom.href = `${cdnHost}/@opentiny/vue-theme@${version}/index.css`
72
+ } else {
73
+ const link = iframeWin.document.createElement('link')
74
+ link.id = 'tiny-theme'
75
+ link.rel = 'stylesheet'
76
+ link.href = `${cdnHost}/@opentiny/vue-theme@${version}/index.css`
77
+ iframeWin.document.head.append(link)
78
+ }
79
+ }
65
80
 
66
81
  function getDemoName(name, apiMode) {
67
82
  return name.replace(/\.vue$/, `${apiMode === 'Options' ? '' : '-composition-api'}.vue`)
@@ -83,10 +98,9 @@ const getDemoCode = async ({ cmpId, fileName, apiMode }) => {
83
98
 
84
99
  const loadFileCode = async ({ cmpId, fileName, apiMode }) => {
85
100
  const code = await getDemoCode({ cmpId, fileName, apiMode })
86
- const resultCode = code.replace(langReg, '')
87
101
  store.state.mainFile = fileName
88
102
  store.state.activeFile = fileName
89
- store.addFile(new File(fileName, resultCode, false))
103
+ store.addFile(new File(fileName, code, false))
90
104
  versionChange(latestVersion)
91
105
  }
92
106