jsx-repl 0.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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2021-present, Yuxi (Evan) You
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,105 @@
1
+ # jsx-repl
2
+
3
+ JSX REPL, support Vite plugins and Volar plugins.
4
+
5
+ ## Basic Usage
6
+
7
+ **Note: `jsx-repl` supports Monaco Editor, but also requires explicitly passing in the editor to be used for tree-shaking.**
8
+
9
+ ```ts
10
+ // vite.config.ts
11
+ import { defineConfig } from 'vite'
12
+ export default defineConfig({
13
+ optimizeDeps: {
14
+ exclude: ['jsx-repl'],
15
+ },
16
+ // ...
17
+ })
18
+ ```
19
+
20
+ ### With CodeMirror Editor
21
+
22
+ Basic editing experience with no intellisense. Lighter weight, fewer network requests, better for embedding use cases.
23
+
24
+ ```vue
25
+ <script setup>
26
+ import { Repl } from 'jsx-repl'
27
+ import CodeMirror from 'jsx-repl/codemirror-editor'
28
+ </script>
29
+
30
+ <template>
31
+ <Repl :editor="CodeMirror" />
32
+ </template>
33
+ ```
34
+
35
+ ### With Monaco Editor
36
+
37
+ With Volar support, autocomplete, type inference, and semantic highlighting. Heavier bundle, loads dts files from CDN, better for standalone use cases.
38
+
39
+ ```vue
40
+ <script setup>
41
+ import { Repl } from 'jsx-repl'
42
+ import Monaco from 'jsx-repl/monaco-editor'
43
+ </script>
44
+
45
+ <template>
46
+ <Repl :editor="Monaco" />
47
+ </template>
48
+ ```
49
+
50
+ ## Advanced Usage
51
+
52
+ Customize the behavior of the REPL by manually initializing the store.
53
+
54
+ See [v4 Migration Guide](https://github.com/vuejs/repl/releases/tag/v4.0.0)
55
+
56
+ ```vue
57
+ <script setup>
58
+ import { watchEffect, ref } from 'vue'
59
+ import { Repl, useStore, useVueImportMap } from 'jsx-repl'
60
+ import Monaco from 'jsx-repl/monaco-editor'
61
+
62
+ // retrieve some configuration options from the URL
63
+ const query = new URLSearchParams(location.search)
64
+
65
+ const {
66
+ importMap: builtinImportMap,
67
+ vueVersion,
68
+ productionMode,
69
+ } = useVueImportMap({
70
+ // specify the default URL to import Vue runtime from in the sandbox
71
+ // default is the CDN link from jsdelivr.com with version matching Vue's version
72
+ // from peerDependency
73
+ runtimeDev: 'cdn link to vue.runtime.esm-browser.js',
74
+ runtimeProd: 'cdn link to vue.runtime.esm-browser.prod.js',
75
+ serverRenderer: 'cdn link to server-renderer.esm-browser.js',
76
+ })
77
+
78
+ const store = useStore(
79
+ {
80
+ // pre-set import map
81
+ builtinImportMap,
82
+ vueVersion,
83
+ // starts on the output pane (mobile only) if the URL has a showOutput query
84
+ showOutput: ref(query.has('showOutput')),
85
+ // starts on a different tab on the output pane if the URL has a outputMode query
86
+ // and default to the "preview" tab
87
+ outputMode: ref(query.get('outputMode') || 'preview'),
88
+ },
89
+ // initialize repl with previously serialized state
90
+ location.hash,
91
+ )
92
+
93
+ // persist state to URL hash
94
+ watchEffect(() => history.replaceState({}, '', store.serialize()))
95
+
96
+ // use a specific version of Vue
97
+ vueVersion.value = '3.2.8'
98
+ // production mode is enabled
99
+ productionMode.value = true
100
+ </script>
101
+
102
+ <template>
103
+ <Repl :store="store" :editor="Monaco" :showCompileOutput="true" />
104
+ </template>
105
+ ```