@codonsplice/vue 0.2.3 → 0.2.5

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/index.js +45 -2
  2. package/package.json +2 -2
package/index.js CHANGED
@@ -1,10 +1,53 @@
1
- // @codonsplice/vue — a useSpliceQL() composable over @codonsplice/wasm.
2
- import { ref } from 'vue'
1
+ // @codonsplice/vue — a useSpliceQL() composable + <SpliceEditor> over @codonsplice/wasm.
2
+ import { ref, defineComponent, h, onMounted, onBeforeUnmount, watch } from 'vue'
3
3
  import { execute as csExecute } from '@codonsplice/wasm/helpers'
4
+ import { mountSpliceEditor } from '@codonsplice/editor'
4
5
 
5
6
  // Re-export the core tooling so apps can `import { useSpliceQL, compile, check }
6
7
  // from '@codonsplice/vue'` without depending on @codonsplice/wasm directly.
7
8
  export { execute, stream, compile, check, ast, initEngine } from '@codonsplice/wasm/helpers'
9
+ // Re-export the editor primitives for apps that want to mount their own view.
10
+ export { spliceqlExtensions, mountSpliceEditor } from '@codonsplice/editor'
11
+
12
+ // A controlled CodeMirror 6 SpliceQL editor. Uses v-model:
13
+ //
14
+ // import { SpliceEditor } from '@codonsplice/vue'
15
+ // <SpliceEditor v-model="query" />
16
+ //
17
+ // Props/events:
18
+ // modelValue — the editor's document (v-model; external changes reconciled)
19
+ // update:modelValue — emitted (docString) on every edit (v-model write-back)
20
+ export const SpliceEditor = defineComponent({
21
+ name: 'SpliceEditor',
22
+ props: { modelValue: { type: String, default: '' } },
23
+ emits: ['update:modelValue'],
24
+ setup(props, { emit }) {
25
+ const host = ref(null)
26
+ let view = null
27
+
28
+ onMounted(() => {
29
+ view = mountSpliceEditor(host.value, {
30
+ doc: props.modelValue,
31
+ onChange: (v) => emit('update:modelValue', v),
32
+ })
33
+ })
34
+
35
+ onBeforeUnmount(() => {
36
+ if (view) { view.destroy(); view = null }
37
+ })
38
+
39
+ // Reconcile an external modelValue change without clobbering live typing.
40
+ watch(() => props.modelValue, (value) => {
41
+ if (!view) return
42
+ const current = view.state.doc.toString()
43
+ if (value !== current) {
44
+ view.dispatch({ changes: { from: 0, to: current.length, insert: value ?? '' } })
45
+ }
46
+ })
47
+
48
+ return () => h('div', { ref: host })
49
+ },
50
+ })
8
51
 
9
52
  export function useSpliceQL() {
10
53
  const result = ref(null)
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "@codonsplice/vue",
3
- "version": "0.2.3",
3
+ "version": "0.2.5",
4
4
  "type": "module",
5
5
  "main": "index.js",
6
- "dependencies": { "@codonsplice/wasm": "^0.2.3" },
6
+ "dependencies": { "@codonsplice/wasm": "^0.2.5", "@codonsplice/editor": "^0.2.5" },
7
7
  "peerDependencies": { "vue": "*" },
8
8
  "license": "MIT"
9
9
  }