reactive-vscode 0.2.5 → 0.2.6

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/README.md CHANGED
@@ -1,108 +1,108 @@
1
- # reactive-vscode
2
-
3
- [![npm version][npm-version-src]][npm-version-href]
4
- [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
- [![License][license-src]][license-href]
6
-
7
- <img src="./docs/public/header.png" width="60%" />
8
-
9
- **Develop VSCode extension with Vue Reactivity API**
10
-
11
- - [**Documentation**](https://kermanx.github.io/reactive-vscode/)
12
- - [**Why reactive-vscode**](https://kermanx.github.io/reactive-vscode/guide/why)
13
- - [**All Functions**](https://kermanx.github.io/reactive-vscode/functions/)
14
- - [**Examples**](https://kermanx.github.io/reactive-vscode/examples/)
15
-
16
- ### Project Status
17
-
18
- Currently, most of the VSCode APIs are covered, and this project has been used in:
19
-
20
- - [Slidev for VSCode <sub><sub>![downloads](https://img.shields.io/visual-studio-marketplace/d/antfu.slidev.svg)</sub></sub>](https://github.com/slidevjs/slidev/tree/main/packages/vscode)
21
- - [Iconify IntelliSense <sub><sub>![downloads](https://img.shields.io/visual-studio-marketplace/d/antfu.iconify.svg)</sub></sub>](https://github.com/antfu/vscode-iconify)
22
-
23
- The [documentation](https://kermanx.github.io/reactive-vscode/) is complete, and the [VueUse integration](https://kermanx.github.io/reactive-vscode/guide/vueuse.html) is also available.
24
-
25
- However, the project is still in beta and may have minor API changes. If you encounter any problems, please feel free to [open an issue](https://github.com/KermanX/reactive-vscode/issues/new).
26
-
27
- ### Counter Example
28
-
29
- ```ts
30
- import { defineExtension, ref, useCommands, useStatusBarItem } from 'reactive-vscode'
31
- import { StatusBarAlignment } from 'vscode'
32
-
33
- export = defineExtension(() => {
34
- const counter = ref(0)
35
-
36
- useStatusBarItem({
37
- alignment: StatusBarAlignment.Right,
38
- priority: 100,
39
- text: () => `$(megaphone) Hello*${counter.value}`,
40
- })
41
-
42
- useCommands({
43
- 'extension.sayHello': () => counter.value++,
44
- 'extension.sayGoodbye': () => counter.value--,
45
- })
46
- })
47
- ```
48
-
49
- <details>
50
- <summary> Implementation with original VSCode API </summary>
51
-
52
- ```ts
53
- import type { ExtensionContext } from 'vscode'
54
- import { StatusBarAlignment, commands, window } from 'vscode'
55
-
56
- export function activate(extensionContext: ExtensionContext) {
57
- let counter = 0
58
-
59
- const item = window.createStatusBarItem(StatusBarAlignment.Right, 100)
60
-
61
- function updateStatusBar() {
62
- item.text = `$(megaphone) Hello*${counter}`
63
- item.show()
64
- }
65
-
66
- updateStatusBar()
67
-
68
- extensionContext.subscriptions.push(
69
- commands.registerCommand('extension.sayHello', () => {
70
- counter++
71
- updateStatusBar()
72
- }),
73
- commands.registerCommand('extension.sayGoodbye', () => {
74
- counter--
75
- updateStatusBar()
76
- }),
77
- )
78
- }
79
- ```
80
-
81
- </details>
82
-
83
- [More examples](https://kermanx.github.io/reactive-vscode/examples/).
84
-
85
- ### License
86
-
87
- [MIT](./LICENSE) License © 2024-PRESENT [_Kerman](https://github.com/KermanX)
88
-
89
- Source code in [the `./packages/reactivity` directory](https://github.com/KermanX/reactive-vscode/blob/main/packages/core/src/reactivity) is ported from [`@vue/runtime-core`](https://github.com/vuejs/core/blob/main/packages/runtime-core). Licensed under a [MIT License](https://github.com/vueuse/vueuse/blob/main/LICENSE).
90
-
91
- Source code in [the `./packages/mock` directory](https://github.com/KermanX/reactive-vscode/blob/main/packages/core/src/mock) references the implementation of [`VSCode`](https://github.com/microsoft/vscode). Licensed under a [MIT License](https://github.com/microsoft/vscode/blob/main/LICENSE.txt).
92
-
93
- The logo <img src="https://kermanx.github.io/reactive-vscode/logo.svg" width="14"> is modified from [Vue Reactity Artworks](https://github.com/vue-reactivity/art). Licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-nc-sa/4.0/).
94
-
95
- Part of the docs website is ported from [VueUse](https://github.com/vueuse/vueuse). Licensed under a [MIT License](https://github.com/vueuse/vueuse/blob/main/LICENSE).
96
-
97
- <!-- Badges -->
98
-
99
- [npm-version-src]: https://img.shields.io/npm/v/reactive-vscode?style=flat&colorA=080f12&colorB=1fa669
100
- [npm-version-href]: https://npmjs.com/package/reactive-vscode
101
- [npm-downloads-src]: https://img.shields.io/npm/dm/reactive-vscode?style=flat&colorA=080f12&colorB=1fa669
102
- [npm-downloads-href]: https://npmjs.com/package/reactive-vscode
103
- [bundle-src]: https://img.shields.io/bundlephobia/minzip/reactive-vscode?style=flat&colorA=080f12&colorB=1fa669&label=minzip
104
- [bundle-href]: https://bundlephobia.com/result?p=reactive-vscode
105
- [license-src]: https://img.shields.io/github/license/KermanX/reactive-vscode.svg?style=flat&colorA=080f12&colorB=1fa669
106
- [license-href]: https://github.com/KermanX/reactive-vscode/blob/main/LICENSE
107
- [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
108
- [jsdocs-href]: https://www.jsdocs.io/package/reactive-vscode
1
+ # reactive-vscode
2
+
3
+ [![npm version][npm-version-src]][npm-version-href]
4
+ [![npm downloads][npm-downloads-src]][npm-downloads-href]
5
+ [![License][license-src]][license-href]
6
+
7
+ <img src="./docs/public/header.png" width="60%" />
8
+
9
+ **Develop VSCode extension with Vue Reactivity API**
10
+
11
+ - [**Documentation**](https://kermanx.github.io/reactive-vscode/)
12
+ - [**Why reactive-vscode**](https://kermanx.github.io/reactive-vscode/guide/why)
13
+ - [**All Functions**](https://kermanx.github.io/reactive-vscode/functions/)
14
+ - [**Examples**](https://kermanx.github.io/reactive-vscode/examples/)
15
+
16
+ ### Project Status
17
+
18
+ Currently, most of the VSCode APIs are covered, and this project has been used in:
19
+
20
+ - [Slidev for VSCode <sub><sub>![downloads](https://img.shields.io/visual-studio-marketplace/d/antfu.slidev.svg)</sub></sub>](https://github.com/slidevjs/slidev/tree/main/packages/vscode)
21
+ - [Iconify IntelliSense <sub><sub>![downloads](https://img.shields.io/visual-studio-marketplace/d/antfu.iconify.svg)</sub></sub>](https://github.com/antfu/vscode-iconify)
22
+
23
+ The [documentation](https://kermanx.github.io/reactive-vscode/) is complete, and the [VueUse integration](https://kermanx.github.io/reactive-vscode/guide/vueuse.html) is also available.
24
+
25
+ However, the project is still in beta and may have minor API changes. If you encounter any problems, please feel free to [open an issue](https://github.com/KermanX/reactive-vscode/issues/new).
26
+
27
+ ### Counter Example
28
+
29
+ ```ts
30
+ import { defineExtension, ref, useCommands, useStatusBarItem } from 'reactive-vscode'
31
+ import { StatusBarAlignment } from 'vscode'
32
+
33
+ export = defineExtension(() => {
34
+ const counter = ref(0)
35
+
36
+ useStatusBarItem({
37
+ alignment: StatusBarAlignment.Right,
38
+ priority: 100,
39
+ text: () => `$(megaphone) Hello*${counter.value}`,
40
+ })
41
+
42
+ useCommands({
43
+ 'extension.sayHello': () => counter.value++,
44
+ 'extension.sayGoodbye': () => counter.value--,
45
+ })
46
+ })
47
+ ```
48
+
49
+ <details>
50
+ <summary> Implementation with original VSCode API </summary>
51
+
52
+ ```ts
53
+ import type { ExtensionContext } from 'vscode'
54
+ import { commands, StatusBarAlignment, window } from 'vscode'
55
+
56
+ export function activate(extensionContext: ExtensionContext) {
57
+ let counter = 0
58
+
59
+ const item = window.createStatusBarItem(StatusBarAlignment.Right, 100)
60
+
61
+ function updateStatusBar() {
62
+ item.text = `$(megaphone) Hello*${counter}`
63
+ item.show()
64
+ }
65
+
66
+ updateStatusBar()
67
+
68
+ extensionContext.subscriptions.push(
69
+ commands.registerCommand('extension.sayHello', () => {
70
+ counter++
71
+ updateStatusBar()
72
+ }),
73
+ commands.registerCommand('extension.sayGoodbye', () => {
74
+ counter--
75
+ updateStatusBar()
76
+ }),
77
+ )
78
+ }
79
+ ```
80
+
81
+ </details>
82
+
83
+ [More examples](https://kermanx.github.io/reactive-vscode/examples/).
84
+
85
+ ### License
86
+
87
+ [MIT](./LICENSE) License © 2024-PRESENT [_Kerman](https://github.com/KermanX)
88
+
89
+ Source code in [the `./packages/reactivity` directory](https://github.com/KermanX/reactive-vscode/blob/main/packages/core/src/reactivity) is ported from [`@vue/runtime-core`](https://github.com/vuejs/core/blob/main/packages/runtime-core). Licensed under a [MIT License](https://github.com/vueuse/vueuse/blob/main/LICENSE).
90
+
91
+ Source code in [the `./packages/mock` directory](https://github.com/KermanX/reactive-vscode/blob/main/packages/core/src/mock) references the implementation of [`VSCode`](https://github.com/microsoft/vscode). Licensed under a [MIT License](https://github.com/microsoft/vscode/blob/main/LICENSE.txt).
92
+
93
+ The logo <img src="https://kermanx.github.io/reactive-vscode/logo.svg" width="14"> is modified from [Vue Reactity Artworks](https://github.com/vue-reactivity/art). Licensed under a [Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License](https://creativecommons.org/licenses/by-nc-sa/4.0/).
94
+
95
+ Part of the docs website is ported from [VueUse](https://github.com/vueuse/vueuse). Licensed under a [MIT License](https://github.com/vueuse/vueuse/blob/main/LICENSE).
96
+
97
+ <!-- Badges -->
98
+
99
+ [npm-version-src]: https://img.shields.io/npm/v/reactive-vscode?style=flat&colorA=080f12&colorB=1fa669
100
+ [npm-version-href]: https://npmjs.com/package/reactive-vscode
101
+ [npm-downloads-src]: https://img.shields.io/npm/dm/reactive-vscode?style=flat&colorA=080f12&colorB=1fa669
102
+ [npm-downloads-href]: https://npmjs.com/package/reactive-vscode
103
+ [bundle-src]: https://img.shields.io/bundlephobia/minzip/reactive-vscode?style=flat&colorA=080f12&colorB=1fa669&label=minzip
104
+ [bundle-href]: https://bundlephobia.com/result?p=reactive-vscode
105
+ [license-src]: https://img.shields.io/github/license/KermanX/reactive-vscode.svg?style=flat&colorA=080f12&colorB=1fa669
106
+ [license-href]: https://github.com/KermanX/reactive-vscode/blob/main/LICENSE
107
+ [jsdocs-src]: https://img.shields.io/badge/jsdocs-reference-080f12?style=flat&colorA=080f12&colorB=1fa669
108
+ [jsdocs-href]: https://www.jsdocs.io/package/reactive-vscode
package/dist/index.cjs ADDED
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const n=require("@reactive-vscode/reactivity"),s=require("vscode");function y(e){return n.getCurrentScope()?(n.onScopeDispose(e),!0):!1}function p(e,t){const a=new Map;return(...o)=>{const i=t(...o);let c=a.get(i);return c?c.refCount++:(c={data:e(...o),refCount:1},a.set(i,c)),y(()=>{--c.refCount===0&&a.delete(i)}),c.data}}function v(e){let t;return()=>t??(t=e())}const E=[];function B(e){E.push(e)}const C=n.shallowRef(null),T=n.effectScope();function H(e){return{activate:t=>(C.value=t,T.run(()=>(S.map(a=>a(t)),e()))),deactivate:()=>{E.map(t=>t()),T.stop()}}}const S=[];function x(e){C.value?e(C.value):S.push(e)}function A(e,t,a){const o=!e,i=s.workspace.getConfiguration(o?void 0:e,a);function c(l,d){const w=n.shallowRef(d),h=n.computed({get:()=>w.value,set:f=>{w.value=f,i.update(l,f)}});return h.update=async(f,g,m)=>{await i.update(l,f,g,m),h.value=f},h.set=f=>{w.value=f},h}const u=Object.fromEntries(Object.keys(t).map(l=>[l,c(l,i.get(l))]));return x(()=>{r(s.workspace.onDidChangeConfiguration(o?l=>{const d=s.workspace.getConfiguration();for(const w in t)l.affectsConfiguration(w)&&u[w].set(d.get(w))}:l=>{if(!l.affectsConfiguration(e))return;const d=s.workspace.getConfiguration(e);for(const w in t)l.affectsConfiguration(`${e}.${w}`)&&u[w].set(d.get(w))}))}),u}function K(e,t,a){const o=A(e,t,a);return n.reactive({...o,$update(i,c,u,l){return o[i].update(c,u,l)},$set(i,c){return o[i].set(c)}})}function q(e,t){const a=n.shallowRef(null),o=[],i=c=>(...u)=>a.value?a.value[c](...u):(o.push([c,u]),null);return x(()=>{a.value=N(e,t);for(const[c,u]of o)a.value[c](...u)}),{logger:a,outputChannel:n.computed(()=>{var c;return(c=a.value)==null?void 0:c.outputChannel}),info:i("info"),warn:i("warn"),error:i("error"),append:i("append"),appendLine:i("appendLine"),replace:i("replace"),clear:i("clear"),show:i("show"),hide:i("hide")}}function Q(e,...t){return s.commands.executeCommand(e,...t)}function U(e,t=!1){const a=C.value;if(!a&&!t)throw new Error("Cannot get absolute path because the extension is not activated yet");return a==null?void 0:a.asAbsolutePath(e)}function z(e,t=!1){return n.computed(()=>U(n.toValue(e),t))}function r(e){return(n.getCurrentScope()??T).cleanups.push(e.dispose.bind(e)),e}const I=v(()=>{const e=n.shallowRef(s.window.activeColorTheme);return r(s.window.onDidChangeActiveColorTheme(t=>{e.value=t})),e}),Y=v(()=>{const e=n.shallowRef(s.debug.activeDebugSession);return r(s.debug.onDidChangeActiveDebugSession(t=>{e.value=t})),n.computed(()=>e.value)}),O=v(()=>{const e=n.shallowRef(s.window.activeTextEditor);return r(s.window.onDidChangeActiveTextEditor(t=>{e.value=t})),e});function P(e){var a;const t=n.shallowRef((a=n.toValue(e))==null?void 0:a.getText());return n.watchEffect(()=>{var o;t.value=(o=n.toValue(e))==null?void 0:o.getText()}),r(s.workspace.onDidChangeTextDocument(o=>{o.document===n.toValue(e)&&(t.value=o.document.getText())})),t}function W(e,t,a,o={}){const{updateOn:i=["effect","documentChanged"]}=o,c="key"in t?t:r(s.window.createTextEditorDecorationType(t)),u=async()=>{const d=n.toValue(e);d&&d.setDecorations(c,typeof a=="function"?await a(d):n.toValue(a))},l=i.includes("documentChanged")?P(()=>{var d;return(d=n.toValue(e))==null?void 0:d.document}):null;return i.includes("effect")?n.watchEffect(async()=>{l==null||l.value,await u()}):l&&n.watch(l,u),{update:u}}function G(e,t){const a=O();W(a,e,t)}const J=v(()=>{const e=n.shallowRef(s.window.activeNotebookEditor);return r(s.window.onDidChangeActiveNotebookEditor(t=>{e.value=t})),e}),X=v(()=>{const e=n.shallowRef(s.window.activeTerminal);return r(s.window.onDidChangeActiveTerminal(t=>{e.value=t})),e}),Z=v(()=>{const e=n.shallowRef(s.extensions.all);return r(s.extensions.onDidChange(()=>{e.value=s.extensions.all})),n.computed(()=>e.value)});function F(e,t){r(s.commands.registerCommand(e,t))}function _(e){for(const[t,a]of Object.entries(e))a&&F(t,a)}function ee(e,t){return r(s.comments.createCommentController(e,t))}function R(e){var a;const t=n.shallowRef((a=n.toValue(e))==null?void 0:a.state);return n.watch(e,()=>{var o;t.value=(o=n.toValue(e))==null?void 0:o.state}),r(s.window.onDidChangeTerminalState(o=>{o===n.toValue(e)&&(t.value=o.state)})),n.computed(()=>t.value)}function te(...e){const t=n.ref(null);function a(){return!!t.value&&t.value.exitStatus==null}function o(){return a()?t.value:t.value=s.window.createTerminal(...e)}function i(l){o().sendText(l)}function c(){o().show()}function u(){a()&&(t.value.sendText(""),t.value.dispose(),t.value=null)}return n.onScopeDispose(u),{terminal:t,getIsActive:a,show:c,sendText:i,close:u,state:R(t)}}const ne=v(()=>{const e=n.shallowRef(s.env.shell);return r(s.env.onDidChangeShell(t=>{e.value=t})),n.computed(()=>e.value)});function b(e,t){const a=(o,i,c)=>{r(e(o,i,c))};return t==null||t.forEach(o=>a(o)),a}function V(e,t=[]){const a=Array.isArray(e)?e:t??[],o=r(Array.isArray(e)||e==null?new s.EventEmitter:e),i=b(o.event,a);for(const c of a)i(c);return{event:o.event,fire:o.fire.bind(o),addListener:i}}async function ae(e){const t=C.value.secrets,a=n.ref(await t.get(e));return a.set=async o=>{a.value=o,await t.store(e,o)},a.remove=async()=>{a.value=void 0,await t.delete(e)},r(t.onDidChange(async o=>{o.key===e&&(a.value=await t.get(e))})),n.watch(a,o=>{o===void 0?t.delete(e):t.store(e,o)}),a}function oe(e){return n.computed(()=>s.tasks.fetchTasks(n.toValue(e)))}function ie(e){return n.computed(()=>s.Uri.file(n.toValue(e)))}function se(e,t){const a=new s.EventEmitter,o=n.shallowRef();n.watchEffect(()=>{o.value&&a.fire(),o.value=n.toValue(t)}),r(s.languages.registerFoldingRangeProvider(e,{onDidChangeFoldingRanges:a.event,provideFoldingRanges(i,c,u){var l;return(l=o.value)==null?void 0:l.call(o,i,c,u)}}))}function ue(e,t,a,o){const i=n.shallowReactive(new Map),c=V(),u=V(),l=V(),d=n.computed(()=>{const f=n.toValue(e);return Array.isArray(f)?f:f instanceof Set?Array.from(f):[f]});function w(){const f=d.value;for(const[g,m]of i)f.includes(g)||(m.dispose(),i.delete(g));for(const g of f)if(!i.has(g)){const m=s.workspace.createFileSystemWatcher(g,n.toValue(t)||!1,n.toValue(a)||!1,n.toValue(o)||!1);m.onDidCreate(c.fire),m.onDidChange(u.fire),m.onDidDelete(l.fire),i.set(g,m)}}function h(){for(const f of i.values())f.dispose();i.clear()}return w(),n.watch(d,w),n.watch(()=>[n.toValue(t),n.toValue(a),n.toValue(o)],()=>{h(),w()}),n.onScopeDispose(h),{watchers:i,onDidCreate:c.event,onDidChange:u.event,onDidDelete:l.event}}const ce=v(()=>{const e=I();return n.computed(()=>e.value.kind===s.ColorThemeKind.Dark||e.value.kind===s.ColorThemeKind.HighContrast)}),re=v(()=>{const e=n.shallowRef(s.env.isTelemetryEnabled);return r(s.env.onDidChangeTelemetryEnabled(t=>{e.value=t})),n.computed(()=>e.value)});function le(e,...t){return n.computed(()=>typeof t[0]=="object"?s.l10n.t(n.toValue(e),n.toRaw(t[0])):s.l10n.t(n.toValue(e),...t.map(n.toValue)))}function L(e,t){return r(s.window.createOutputChannel(e,t))}function de(e){const t=new Date,a=String(t.getFullYear()).padStart(4,"0"),o=String(t.getMonth()+1).padStart(2,"0"),i=String(t.getDate()).padStart(2,"0"),c=String(t.getHours()).padStart(2,"0"),u=String(t.getMinutes()).padStart(2,"0"),l=String(t.getSeconds()).padStart(2,"0"),d=String(t.getMilliseconds()).padStart(3,"0");return`${a}-${o}-${i} ${c}:${u}:${l}.${d} [${e}] `}function N(e,t={}){const a=t.outputChannel??L(e),o=i=>(...c)=>{var u;a.appendLine((((u=t.getPrefix)==null?void 0:u.call(t,i))??"")+c.join(" "))};return{outputChannel:a,createLoggerFunc:o,info:o("INFO"),warn:o("WARN"),error:o("ERROR"),append:a.append.bind(a),appendLine:a.appendLine.bind(a),replace:a.replace.bind(a),clear:a.clear.bind(a),show:a.show.bind(a),hide:a.hide.bind(a)}}const fe=v(()=>{const e=n.shallowRef(s.env.logLevel);return r(s.env.onDidChangeLogLevel(t=>{e.value=t})),n.computed(()=>e.value)});function M(e){var a;const t=n.shallowRef(((a=n.toValue(e))==null?void 0:a.selections)??[]);return n.watch(e,()=>{var o;t.value=((o=n.toValue(e))==null?void 0:o.selections)??[]}),r(s.window.onDidChangeNotebookEditorSelection(o=>{o.notebookEditor===n.toValue(e)&&(t.value=o.selections)})),n.computed({get(){return t.value},set(o){t.value=o;const i=n.toValue(e);i&&(i.selections=o)}})}function we(e){const t=M(e);return n.computed({get(){return t.value[0]},set(a){t.value=t.value.toSpliced(0,1,a)}})}function ve(e){var a;const t=n.shallowRef(((a=n.toValue(e))==null?void 0:a.visibleRanges)??[]);return n.watch(e,()=>{var o;t.value=((o=n.toValue(e))==null?void 0:o.visibleRanges)??[]}),r(s.window.onDidChangeNotebookEditorVisibleRanges(o=>{o.notebookEditor===n.toValue(e)&&(t.value=o.visibleRanges)})),n.computed(()=>t.value)}const he=v(()=>{const e=n.shallowRef(s.window.terminals);function t(){e.value=s.window.terminals}return r(s.window.onDidOpenTerminal(t)),r(s.window.onDidCloseTerminal(t)),e});function ge(e={}){const t=r(s.window.createQuickPick()),a=b(t.onDidChangeActive),o=b(t.onDidChangeSelection),i=b(t.onDidAccept),c=b(t.onDidHide),u=b(t.onDidTriggerButton),l=b(t.onDidChangeValue);["items","buttons","title","step","totalSteps","enabled","busy","ignoreFocusOut","placeholder","canSelectMany","matchOnDescription","matchOnDetail","keepScrollPosition"].forEach(f=>{e[f]&&n.watchEffect(()=>t[f]=n.toValue(e[f]))}),e.value&&(t.value=e.value);const d=n.shallowRef(t.value);l(f=>d.value=f),e.activeItems&&(t.activeItems=e.activeItems);const w=n.shallowRef(t.activeItems);a(f=>w.value=f),e.selectedItems&&(t.selectedItems=e.selectedItems);const h=n.shallowRef(t.selectedItems);return o(f=>h.value=f),{...t,onDidChangeActive:a,onDidChangeSelection:o,onDidAccept:i,onDidHide:c,onDidTriggerButton:u,onDidChangeValue:l,value:d,activeItems:w,selectedItems:h}}function me(e){const t=r(e.id?s.window.createStatusBarItem(e.id,e.alignment,e.priority):s.window.createStatusBarItem(e.alignment,e.priority));function a(o){const i=e[o];i!=null&&n.watchEffect(()=>t[o]=n.toValue(i))}return["name","text","tooltip","color","backgroundColor","command","accessibilityInformation"].forEach(a),t}const be=v(()=>{const e=n.shallowRef(s.tasks.taskExecutions);function t(){e.value=s.tasks.taskExecutions}return r(s.tasks.onDidStartTask(t)),r(s.tasks.onDidEndTask(t)),n.computed(()=>e.value)});function Ce(...e){const t=r(s.window.createTerminal(...e));return{terminal:t,get name(){return t.name},get processId(){return t.processId},get creationOptions(){return t.creationOptions},get exitStatus(){return t.exitStatus},get shellIntegration(){return t.shellIntegration},sendText:t.sendText.bind(t),show:t.show.bind(t),hide:t.hide.bind(t),state:R(t)}}function $(e,t){r(s.commands.registerTextEditorCommand(e,t))}function Ve(e){for(const[t,a]of Object.entries(e))$(t,a)}function j(e,t){var o;const a=n.shallowRef(((o=n.toValue(e))==null?void 0:o.selections)??[]);return n.watch(e,()=>{var i;a.value=((i=n.toValue(e))==null?void 0:i.selections)??[]}),r(s.window.onDidChangeTextEditorSelection(i=>{const c=n.toValue(e),u=n.toValue(t);i.textEditor===c&&(!u||u.includes(i.kind))&&(a.value=i.selections)})),n.computed({get(){return a.value},set(i){a.value=i;const c=n.toValue(e);c&&(c.selections=i)}})}function Te(e,t){const a=j(e,t);return n.computed({get(){return a.value[0]},set(o){a.value=a.value.toSpliced(0,1,o)}})}function De(e){var a;const t=n.shallowRef((a=n.toValue(e))==null?void 0:a.viewColumn);return n.watch(e,()=>{var o;t.value=(o=n.toValue(e))==null?void 0:o.viewColumn}),r(s.window.onDidChangeTextEditorViewColumn(o=>{o.textEditor===n.toValue(e)&&(t.value=o.viewColumn)})),n.computed(()=>t.value)}function pe(e){var a;const t=n.shallowRef(((a=n.toValue(e))==null?void 0:a.visibleRanges)??[]);return n.watch(e,()=>{var o;t.value=((o=n.toValue(e))==null?void 0:o.visibleRanges)??[]}),r(s.window.onDidChangeTextEditorVisibleRanges(o=>{o.textEditor===n.toValue(e)&&(t.value=o.visibleRanges)})),n.computed(()=>t.value)}function k(e,t){n.watchEffect(()=>{const a=n.toValue(e);a&&(a.badge=n.toValue(t))})}function D(e,t){n.watchEffect(()=>{const a=n.toValue(e);a&&(a.title=n.toValue(t))})}const Ee=p((e,t,a)=>{const o=V();n.watch(t,()=>o.fire()),a!=null&&a.watchSource&&n.watch(a.watchSource,()=>o.fire());const i=new WeakMap,c=r(s.window.createTreeView(e,{...a,treeDataProvider:{...a,onDidChangeTreeData:o.event,getTreeItem(u){return u.treeItem},getChildren(u){var l;return u?((l=u.children)==null||l.forEach(d=>i.set(d,u)),u.children):n.toValue(t)},getParent(u){return i.get(u)}}}));return a!=null&&a.title&&D(c,a.title),a!=null&&a.badge&&k(c,a.badge),c},e=>e);function Se(e){var o;const t=n.ref((o=n.toValue(e))==null?void 0:o.visible);function a(){var i;t.value=(i=n.toValue(e))==null?void 0:i.visible}return n.watchEffect(i=>{const c=n.toValue(e);if(c){const u=c.onDidChangeVisibility(a);i(()=>u.dispose())}}),n.watchEffect(a),n.computed(()=>!!t.value)}const xe=v(()=>{const e=n.shallowRef(s.window.visibleNotebookEditors);return r(s.window.onDidChangeVisibleNotebookEditors(t=>{e.value=t})),e}),Re=v(()=>{const e=n.shallowRef(s.window.visibleTextEditors);return r(s.window.onDidChangeVisibleTextEditors(t=>{e.value=t})),e});function ke(e,t,a=!0){const o=n.isRef(t)?t:typeof t=="function"?n.computed(t):n.ref(t);return n.watchEffect(()=>{n.toValue(a)&&s.commands.executeCommand("setContext",e,o.value)}),o}function ye(e,t,a,o,i){const c=n.shallowRef(),u=r(s.window.createWebviewPanel(e,n.toValue(t),o,{enableFindWidget:i==null?void 0:i.enableFindWidget,retainContextWhenHidden:i==null?void 0:i.retainContextWhenHidden,...n.toValue(i==null?void 0:i.webviewOptions)}));i!=null&&i.onDidReceiveMessage&&u.webview.onDidReceiveMessage(i.onDidReceiveMessage);const l=n.ref(0);function d(){l.value++}if(n.watchEffect(()=>{u.webview.html=`${n.toValue(a)}<!--${l.value}-->`}),i!=null&&i.webviewOptions){const g=i.webviewOptions;n.watchEffect(()=>{u.webview.options=n.toValue(g)})}D(u,t);function w(g){return u.webview.postMessage(g)}const h=n.ref(u.active),f=n.ref(u.visible);return r(u.onDidChangeViewState(()=>{h.value=u.active,f.value=u.visible})),{panel:u,context:c,active:h,visible:f,postMessage:w,forceRefresh:d}}const Ae=p((e,t,a)=>{const o=n.shallowRef(),i=n.shallowRef();r(s.window.registerWebviewViewProvider(e,{resolveWebviewView(d,w){o.value=d,i.value=w,a!=null&&a.onDidReceiveMessage&&d.webview.onDidReceiveMessage(a.onDidReceiveMessage)}},{webviewOptions:{retainContextWhenHidden:a==null?void 0:a.retainContextWhenHidden}}));const c=n.ref(0);function u(){c.value++}if(n.watchEffect(()=>{o.value&&(o.value.webview.html=`${n.toValue(t)}<!--${c.value}-->`)}),a!=null&&a.webviewOptions){const d=a.webviewOptions;n.watchEffect(()=>{o.value&&(o.value.webview.options=n.toValue(d))})}a!=null&&a.title&&D(o,a.title),a!=null&&a.badge&&k(o,a.badge);function l(d){var w;return(w=o.value)==null?void 0:w.webview.postMessage(d)}return{view:o,context:i,postMessage:l,forceRefresh:u}},e=>e),Ie=v(()=>{const e=n.shallowRef(s.window.state);return r(s.window.onDidChangeWindowState(t=>{e.value=t})),{focused:n.computed(()=>e.value.focused),active:n.computed(()=>e.value.active)}}),Oe=v(()=>{const e=n.shallowRef(s.workspace.workspaceFolders);return r(s.workspace.onDidChangeWorkspaceFolders(()=>{e.value=s.workspace.workspaceFolders})),n.computed(()=>e.value)});exports.activateCbs=S;exports.createKeyedComposable=p;exports.createSingletonComposable=v;exports.deactivateCbs=E;exports.defineConfigObject=K;exports.defineConfigs=A;exports.defineExtension=H;exports.defineLogger=q;exports.executeCommand=Q;exports.extensionContext=C;exports.extensionScope=T;exports.getDefaultLoggerPrefix=de;exports.onActivate=x;exports.onDeactivate=B;exports.tryOnScopeDispose=y;exports.useAbsolutePath=z;exports.useActiveColorTheme=I;exports.useActiveDebugSession=Y;exports.useActiveEditorDecorations=G;exports.useActiveNotebookEditor=J;exports.useActiveTerminal=X;exports.useActiveTextEditor=O;exports.useAllExtensions=Z;exports.useCommand=F;exports.useCommands=_;exports.useCommentController=ee;exports.useControlledTerminal=te;exports.useDefaultShell=ne;exports.useDisposable=r;exports.useDocumentText=P;exports.useEditorDecorations=W;exports.useEvent=b;exports.useEventEmitter=V;exports.useExtensionSecret=ae;exports.useFetchTasks=oe;exports.useFileUri=ie;exports.useFoldingRangeProvider=se;exports.useFsWatcher=ue;exports.useIsDarkTheme=ce;exports.useIsTelemetryEnabled=re;exports.useL10nText=le;exports.useLogLevel=fe;exports.useLogger=N;exports.useNotebookEditorSelection=we;exports.useNotebookEditorSelections=M;exports.useNotebookEditorVisibleRanges=ve;exports.useOpenedTerminals=he;exports.useOutputChannel=L;exports.useQuickPick=ge;exports.useStatusBarItem=me;exports.useTaskExecutions=be;exports.useTerminal=Ce;exports.useTerminalState=R;exports.useTextEditorCommand=$;exports.useTextEditorCommands=Ve;exports.useTextEditorSelection=Te;exports.useTextEditorSelections=j;exports.useTextEditorViewColumn=De;exports.useTextEditorVisibleRanges=pe;exports.useTreeView=Ee;exports.useViewBadge=k;exports.useViewTitle=D;exports.useViewVisibility=Se;exports.useVisibleNotebookEditors=xe;exports.useVisibleTextEditors=Re;exports.useVscodeContext=ke;exports.useWebviewPanel=ye;exports.useWebviewView=Ae;exports.useWindowState=Ie;exports.useWorkspaceFolders=Oe;Object.keys(n).forEach(e=>{e!=="default"&&!Object.prototype.hasOwnProperty.call(exports,e)&&Object.defineProperty(exports,e,{enumerable:!0,get:()=>n[e]})});
package/dist/index.d.ts CHANGED
@@ -177,6 +177,21 @@ export declare function defineLogger(name: string, options?: UseLoggerOptions):
177
177
  (column?: ViewColumn, preserveFocus?: boolean): void;
178
178
  };
179
179
  hide: () => void;
180
+ } | null, {
181
+ outputChannel: OutputChannel;
182
+ createLoggerFunc: (type: string) => (...message: any[]) => void;
183
+ info: (...message: any[]) => void;
184
+ warn: (...message: any[]) => void;
185
+ error: (...message: any[]) => void;
186
+ append: (value: string) => void;
187
+ appendLine: (value: string) => void;
188
+ replace: (value: string) => void;
189
+ clear: () => void;
190
+ show: {
191
+ (preserveFocus?: boolean): void;
192
+ (column?: ViewColumn, preserveFocus?: boolean): void;
193
+ };
194
+ hide: () => void;
180
195
  } | null>;
181
196
  outputChannel: ComputedRef<OutputChannel | undefined>;
182
197
  info: (...args: any[]) => void | null;
@@ -197,7 +212,7 @@ export declare function defineLogger(name: string, options?: UseLoggerOptions):
197
212
  */
198
213
  export declare function executeCommand<K extends Extract<keyof Commands, string>>(command: K, ...args: Parameters<Commands[K]>): Thenable<unknown>;
199
214
 
200
- export declare const extensionContext: ShallowRef<ExtensionContext | null>;
215
+ export declare const extensionContext: ShallowRef<ExtensionContext | null, ExtensionContext | null>;
201
216
 
202
217
  /* Excluded from this release type: extensionScope */
203
218
 
@@ -334,7 +349,7 @@ export declare function useAbsolutePath(relativePath: MaybeRefOrGetter<string>,
334
349
  /**
335
350
  * @reactive `window.activeColorTheme`
336
351
  */
337
- export declare const useActiveColorTheme: () => ShallowRef<ColorTheme>;
352
+ export declare const useActiveColorTheme: () => ShallowRef<ColorTheme, ColorTheme>;
338
353
 
339
354
  /**
340
355
  * @reactive `debug.activeDebugSession`
@@ -352,19 +367,19 @@ export declare function useActiveEditorDecorations(decorationTypeOrOptions: Text
352
367
  * @reactive `window.activeNotebookEditor`
353
368
  * @category editor
354
369
  */
355
- export declare const useActiveNotebookEditor: () => ShallowRef<NotebookEditor | undefined>;
370
+ export declare const useActiveNotebookEditor: () => ShallowRef<NotebookEditor | undefined, NotebookEditor | undefined>;
356
371
 
357
372
  /**
358
373
  * @reactive `window.activeTerminal`
359
374
  * @category terminal
360
375
  */
361
- export declare const useActiveTerminal: () => ShallowRef<Terminal | undefined>;
376
+ export declare const useActiveTerminal: () => ShallowRef<Terminal | undefined, Terminal | undefined>;
362
377
 
363
378
  /**
364
379
  * @reactive `window.activeTextEditor`
365
380
  * @category editor
366
381
  */
367
- export declare const useActiveTextEditor: () => ShallowRef<TextEditor | undefined>;
382
+ export declare const useActiveTextEditor: () => ShallowRef<TextEditor | undefined, TextEditor | undefined>;
368
383
 
369
384
  /**
370
385
  * @reactive `extensions.all`
@@ -427,7 +442,7 @@ export declare function useDisposable<T extends Disposable_2>(disposable: T): T;
427
442
  * @reactive `TextDocument.getText`
428
443
  * @category document
429
444
  */
430
- export declare function useDocumentText(doc: MaybeRefOrGetter<TextDocument | undefined>): ShallowRef<string | undefined>;
445
+ export declare function useDocumentText(doc: MaybeRefOrGetter<TextDocument | undefined>): ShallowRef<string | undefined, string | undefined>;
431
446
 
432
447
  /**
433
448
  * Reactively set decorations on the given editor. See `vscode::TextEditor.setDecorations`.
@@ -476,7 +491,7 @@ declare interface UseEventEmitterReturn<T> {
476
491
  * @reactive `ExtensionContext.secrets`
477
492
  * @category extension
478
493
  */
479
- export declare function useExtensionSecret(key: string): Promise<Ref<string | undefined> & {
494
+ export declare function useExtensionSecret(key: string): Promise<Ref<string | undefined, string | undefined> & {
480
495
  set: (newValue: string) => Promise<void>;
481
496
  remove: () => Promise<void>;
482
497
  }>;
@@ -564,13 +579,13 @@ export declare const useLogLevel: () => ComputedRef<LogLevel>;
564
579
  * @reactive `NotebookEditor.selection`
565
580
  * @category editor
566
581
  */
567
- export declare function useNotebookEditorSelection(notebookEditor: MaybeNullableRefOrGetter<NotebookEditor>): WritableComputedRef<NotebookRange>;
582
+ export declare function useNotebookEditorSelection(notebookEditor: MaybeNullableRefOrGetter<NotebookEditor>): WritableComputedRef<NotebookRange, NotebookRange>;
568
583
 
569
584
  /**
570
585
  * @reactive `NotebookEditor.selections`
571
586
  * @category editor
572
587
  */
573
- export declare function useNotebookEditorSelections(notebookEditor: MaybeNullableRefOrGetter<NotebookEditor>): WritableComputedRef<readonly NotebookRange[]>;
588
+ export declare function useNotebookEditorSelections(notebookEditor: MaybeNullableRefOrGetter<NotebookEditor>): WritableComputedRef<readonly NotebookRange[], readonly NotebookRange[]>;
574
589
 
575
590
  /**
576
591
  * @reactive `NotebookEditor.visibleRanges`
@@ -582,7 +597,7 @@ export declare function useNotebookEditorVisibleRanges(notebookEditor: MaybeNull
582
597
  * @reactive `window.terminals`
583
598
  * @category terminal
584
599
  */
585
- export declare const useOpenedTerminals: () => ShallowRef<readonly Terminal[]>;
600
+ export declare const useOpenedTerminals: () => ShallowRef<readonly Terminal[], readonly Terminal[]>;
586
601
 
587
602
  /**
588
603
  * @reactive `window.createOutputChannel`
@@ -602,9 +617,9 @@ export declare function useQuickPick<T extends QuickPickItem>(options?: QuickPic
602
617
  onDidHide: (listener: (e: void) => any, thisArgs?: any, disposables?: Disposable_2[]) => void;
603
618
  onDidTriggerButton: (listener: (e: QuickInputButton) => any, thisArgs?: any, disposables?: Disposable_2[]) => void;
604
619
  onDidChangeValue: (listener: (e: string) => any, thisArgs?: any, disposables?: Disposable_2[]) => void;
605
- value: ShallowRef<string>;
606
- activeItems: ShallowRef<readonly T[]>;
607
- selectedItems: ShallowRef<readonly T[]>;
620
+ value: ShallowRef<string, string>;
621
+ activeItems: ShallowRef<readonly T[], readonly T[]>;
622
+ selectedItems: ShallowRef<readonly T[], readonly T[]>;
608
623
  placeholder: string | undefined;
609
624
  buttons: readonly QuickInputButton[];
610
625
  onDidTriggerItemButton: Event_2<QuickPickItemButtonEvent<T>>;
@@ -686,13 +701,13 @@ export declare function useTextEditorCommands(commands: Record<string, TextEdito
686
701
  * @reactive `TextEditor.selection`
687
702
  * @category editor
688
703
  */
689
- export declare function useTextEditorSelection(textEditor: MaybeNullableRefOrGetter<TextEditor>, acceptKind?: MaybeRefOrGetter<(TextEditorSelectionChangeKind | undefined)[]>): WritableComputedRef<Selection>;
704
+ export declare function useTextEditorSelection(textEditor: MaybeNullableRefOrGetter<TextEditor>, acceptKind?: MaybeRefOrGetter<(TextEditorSelectionChangeKind | undefined)[]>): WritableComputedRef<Selection, Selection>;
690
705
 
691
706
  /**
692
707
  * @reactive `TextEditor.selections`
693
708
  * @category editor
694
709
  */
695
- export declare function useTextEditorSelections(textEditor: MaybeNullableRefOrGetter<TextEditor>, acceptKind?: MaybeRefOrGetter<(TextEditorSelectionChangeKind | undefined)[]>): WritableComputedRef<readonly Selection[]>;
710
+ export declare function useTextEditorSelections(textEditor: MaybeNullableRefOrGetter<TextEditor>, acceptKind?: MaybeRefOrGetter<(TextEditorSelectionChangeKind | undefined)[]>): WritableComputedRef<readonly Selection[], readonly Selection[]>;
696
711
 
697
712
  /**
698
713
  * @reactive `TextEditor.viewColumn`
@@ -747,18 +762,18 @@ export declare function useViewVisibility(view: MaybeNullableRefOrGetter<ViewWit
747
762
  * @reactive `window.visibleNotebookEditors`
748
763
  * @category editor
749
764
  */
750
- export declare const useVisibleNotebookEditors: () => ShallowRef<readonly NotebookEditor[]>;
765
+ export declare const useVisibleNotebookEditors: () => ShallowRef<readonly NotebookEditor[], readonly NotebookEditor[]>;
751
766
 
752
767
  /**
753
768
  * @reactive `window.visibleTextEditors`
754
769
  * @category editor
755
770
  */
756
- export declare const useVisibleTextEditors: () => ShallowRef<readonly TextEditor[]>;
757
-
758
- export declare function useVscodeContext<T>(name: string, value: ComputedRef<T> | (() => T), shouldUpdate?: MaybeRefOrGetter<boolean>): ComputedRef<T>;
771
+ export declare const useVisibleTextEditors: () => ShallowRef<readonly TextEditor[], readonly TextEditor[]>;
759
772
 
760
773
  export declare function useVscodeContext<T>(name: string, value: WritableComputedRef<T>, shouldUpdate?: MaybeRefOrGetter<boolean>): WritableComputedRef<T>;
761
774
 
775
+ export declare function useVscodeContext<T>(name: string, value: ComputedRef<T> | (() => T), shouldUpdate?: MaybeRefOrGetter<boolean>): ComputedRef<T>;
776
+
762
777
  export declare function useVscodeContext<T>(name: string, value: MaybeRef<T>, shouldUpdate?: MaybeRefOrGetter<boolean>): Ref<T>;
763
778
 
764
779
  /**
@@ -768,9 +783,9 @@ export declare function useVscodeContext<T>(name: string, value: MaybeRef<T>, sh
768
783
  */
769
784
  export declare function useWebviewPanel(viewType: string, title: MaybeRefOrGetter<string>, html: MaybeRefOrGetter<string>, showOptions: Parameters<typeof window.createWebviewPanel>[2], options?: WebviewPanelRegisterOptions): {
770
785
  panel: WebviewPanel;
771
- context: ShallowRef<unknown>;
772
- active: Ref<boolean>;
773
- visible: Ref<boolean>;
786
+ context: ShallowRef<unknown, unknown>;
787
+ active: Ref<boolean, boolean>;
788
+ visible: Ref<boolean, boolean>;
774
789
  postMessage: (message: any) => Thenable<boolean>;
775
790
  forceRefresh: () => void;
776
791
  };
@@ -781,8 +796,8 @@ export declare function useWebviewPanel(viewType: string, title: MaybeRefOrGette
781
796
  * @category view
782
797
  */
783
798
  export declare const useWebviewView: (viewId: string, html: MaybeRefOrGetter<string>, options?: WebviewViewRegisterOptions | undefined) => {
784
- view: ShallowRef<WebviewView | undefined>;
785
- context: ShallowRef<WebviewViewResolveContext<unknown> | undefined>;
799
+ view: ShallowRef<WebviewView | undefined, WebviewView | undefined>;
800
+ context: ShallowRef<WebviewViewResolveContext<unknown> | undefined, WebviewViewResolveContext<unknown> | undefined>;
786
801
  postMessage: (message: any) => Thenable<boolean> | undefined;
787
802
  forceRefresh: () => void;
788
803
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "reactive-vscode",
3
3
  "type": "module",
4
- "version": "0.2.5",
4
+ "version": "0.2.6",
5
5
  "description": "Develop VSCode extension with Vue Reactivity API",
6
6
  "author": "_Kerman <kermanx@qq.com>",
7
7
  "license": "MIT",
@@ -24,10 +24,11 @@
24
24
  "exports": {
25
25
  ".": {
26
26
  "types": "./dist/index.d.ts",
27
- "import": "./dist/index.js"
27
+ "import": "./dist/index.js",
28
+ "require": "./dist/index.cjs"
28
29
  }
29
30
  },
30
- "main": "./dist/index.js",
31
+ "main": "./dist/index.cjs",
31
32
  "types": "./dist/index.d.ts",
32
33
  "files": [
33
34
  "README.md",
@@ -37,14 +38,14 @@
37
38
  "@types/vscode": "^1.89.0"
38
39
  },
39
40
  "dependencies": {
40
- "@reactive-vscode/reactivity": "0.2.5"
41
+ "@reactive-vscode/reactivity": "0.2.6"
41
42
  },
42
43
  "devDependencies": {
43
- "@types/node": "^20.16.10",
44
- "@types/vscode": "^1.93.0",
45
- "typescript": "^5.6.2",
46
- "vite": "^5.4.8",
47
- "vite-plugin-dts": "^4.2.1"
44
+ "@types/node": "^20.17.0",
45
+ "@types/vscode": "^1.94.0",
46
+ "typescript": "^5.6.3",
47
+ "vite": "^5.4.10",
48
+ "vite-plugin-dts": "^4.3.0"
48
49
  },
49
50
  "scripts": {
50
51
  "typecheck": "tsc --noEmit",