@stacksjs/stx-vscode 0.2.574 → 0.2.576

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.
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stacksjs/stx-typescript-plugin",
3
- "version": "0.2.574",
3
+ "version": "0.2.576",
4
4
  "private": true,
5
5
  "main": "index.js"
6
6
  }
@@ -71,6 +71,7 @@ declare module 'stx' {
71
71
  export const setResponseHeader: (name: string, value: string) => void // <script server> only
72
72
  export const setResponseStatus: (status: number) => void // <script server> only
73
73
  export const setRouteParams: typeof globalThis.setRouteParams
74
+ export const sharedRequest: typeof globalThis.sharedRequest
74
75
  export const state: typeof globalThis.state
75
76
  export const untrack: typeof globalThis.untrack
76
77
  export const useAsync: typeof globalThis.useAsync
@@ -113,6 +114,7 @@ declare module 'stx' {
113
114
  export const useServerRuntimeConfig: () => Readonly<{ public: Record<string, any>, private: Record<string, any> }> // <script server> only
114
115
  export const useSessionStorage: typeof globalThis.useSessionStorage
115
116
  export const keptState: typeof globalThis.keptState
117
+ export const memo: typeof globalThis.memo
116
118
  export const forgetKeptState: typeof globalThis.forgetKeptState
117
119
  export const setKeptScope: typeof globalThis.setKeptScope
118
120
  export const flushKeptState: typeof globalThis.flushKeptState
@@ -68,9 +68,18 @@ type StxCleanup = () => void
68
68
  // ============================================================================
69
69
 
70
70
  declare function state<T>(_initial: T): StxSignal<T>
71
- declare function derived<T>(_compute: () => T): StxDerivedSignal<T>
71
+ /**
72
+ * A computed value. With `equals`, a change upstream recomputes it at once
73
+ * (while anything reads it) and reaches its readers only when
74
+ * `equals(previous, next)` is false; without it, it is lazy and every upstream
75
+ * change reaches them.
76
+ */
77
+ declare function derived<T>(_compute: () => T, _options?: { equals?: (_previous: T, _next: T) => boolean }): StxDerivedSignal<T>
78
+ /** A derived value that reaches its readers only when it changes (`Object.is`, or `equals`). */
79
+ declare function memo<T>(_compute: () => T, _equals?: (_previous: T, _next: T) => boolean): StxDerivedSignal<T>
72
80
  declare function effect(_fn: () => void | StxCleanup): StxCleanup
73
81
  declare function batch(_fn: () => void): void
82
+ /** Read a signal without subscribing the running effect to it; anything else is returned as it is. */
74
83
  declare function untrack<T>(_value: T | StxSignal<T> | StxDerivedSignal<T>): T
75
84
  declare function peek<T>(_fn: () => T): T
76
85
  declare function isSignal(value: unknown): value is StxSignal<unknown>
@@ -536,6 +545,19 @@ interface StxCachedQuery<T> {
536
545
  /** Data kept per account, shown at once from last time and refreshed behind. Same key, same query. */
537
546
  declare function cachedQuery<T = any>(_key: string, _options?: StxCachedQueryOptions<T>): StxCachedQuery<T>
538
547
 
548
+ /** One request for every caller that wants the same answer: see shared-request.ts. */
549
+ interface StxSharedRequest<K, T> {
550
+ /** Join a request in flight whose key covers `key` (or a waiting fresh rerun), or start one. */
551
+ run: (_key: K, _start: () => Promise<T>) => Promise<T>
552
+ /** Never joins: waits out a request in flight for `key`, then starts once more (one rerun for every caller meanwhile). */
553
+ fresh: (_key: K, _start: () => Promise<T>) => Promise<T>
554
+ /** A checker that stays true until latest() is called again. */
555
+ latest: () => () => boolean
556
+ /** True while a request is out or a fresh rerun is waiting. */
557
+ readonly busy: boolean
558
+ }
559
+ declare function sharedRequest<K = string, T = any>(_options?: { covers?: (_running: K, _wanted: K) => boolean }): StxSharedRequest<K, T>
560
+
539
561
  /**
540
562
  * Options accepted by the auto-imported `useCookie` global.
541
563
  *
@@ -698,10 +720,36 @@ declare function definePageMeta(_meta: Record<string, unknown>): void
698
720
  declare function ref<T>(_value: T): StxRef<T>
699
721
  declare function reactive<T extends object>(_target: T): T
700
722
  declare function computed<T>(_getter: () => T): StxRef<T>
723
+ type StxWatchSource<T> = (() => T) | StxRef<T> | StxSignal<T> | StxDerivedSignal<T>
724
+ interface StxWatchOptions {
725
+ /** Call back at once with the current value (and no previous one). */
726
+ immediate?: boolean
727
+ /** Compare structurally rather than with Object.is (a reactive object source is deep by default). */
728
+ deep?: boolean
729
+ /** When to call back: after the next render ('post', the default), on a microtask ('pre') or inside the change ('sync'). */
730
+ flush?: 'post' | 'pre' | 'sync'
731
+ /** Stop after the first call. */
732
+ once?: boolean
733
+ }
734
+ /**
735
+ * Call back with (next, previous) when the source's value changes - not at
736
+ * creation unless `immediate`. The source is a signal, derived, getter,
737
+ * reactive object, or an array of those. Returns a stop function.
738
+ */
739
+ declare function watch<const S extends readonly StxWatchSource<unknown>[]>(
740
+ _source: S,
741
+ _callback: (_value: { [K in keyof S]: S[K] extends StxWatchSource<infer V> ? V : never }, _oldValue: { [K in keyof S]: S[K] extends StxWatchSource<infer V> ? V : never } | undefined, _onCleanup: (_fn: () => void) => void) => void,
742
+ _options?: StxWatchOptions,
743
+ ): StxCleanup
701
744
  declare function watch<T>(
702
- _source: (() => T) | StxRef<T> | StxSignal<T>,
703
- _callback: (value: T, oldValue: T) => void,
704
- _options?: { immediate?: boolean, deep?: boolean },
745
+ _source: StxWatchSource<T>,
746
+ _callback: (_value: T, _oldValue: T | undefined, _onCleanup: (_fn: () => void) => void) => void,
747
+ _options?: StxWatchOptions,
748
+ ): StxCleanup
749
+ declare function watch<T extends object>(
750
+ _source: T,
751
+ _callback: (_value: T, _oldValue: T | undefined, _onCleanup: (_fn: () => void) => void) => void,
752
+ _options?: StxWatchOptions,
705
753
  ): StxCleanup
706
754
  declare function watchEffect(_fn: () => void): StxCleanup
707
755
  declare function watchMultiple(
@@ -909,6 +957,7 @@ interface StxRuntimeRegistry {
909
957
  // Signals
910
958
  state: typeof state
911
959
  derived: typeof derived
960
+ memo: typeof memo
912
961
  effect: typeof effect
913
962
  batch: typeof batch
914
963
  untrack: typeof untrack
@@ -980,6 +1029,7 @@ interface StxRuntimeRegistry {
980
1029
  setKeptScope: typeof setKeptScope
981
1030
  flushKeptState: typeof flushKeptState
982
1031
  cachedQuery: typeof cachedQuery
1032
+ sharedRequest: typeof sharedRequest
983
1033
  useEventListener: typeof useEventListener
984
1034
  useScrollLock: typeof useScrollLock
985
1035
  useWebSocket: typeof useWebSocket
@@ -7,7 +7,7 @@ var yt=Object.create;var{getPrototypeOf:wt,defineProperty:Ee,getOwnPropertyNames
7
7
  `?`
8
8
  `:" ",t++}s+=" ",t++,n=W,i="";continue}if(r==="/"&&$e(n,i)){let a=Te(e,t);if(a!==-1){s+=`/${" ".repeat(a-t-2)}/`,t=a,n=W,i="";continue}}if(r==="`"){s+=" ",t++;while(t<e.length&&e[t]!=="`"){if(e[t]==="\\"){s+=" ",t+=2;continue}if(e[t]==="$"&&e[t+1]==="{"){let a=t+2,c=_e(e,a);if(s+=" ",s+=L(e.slice(a,c)),c<e.length)s+=" ";t=c+1;continue}s+=e[t]===`
9
9
  `?`
10
- `:" ",t++}s+=" ",t++,n=W,i="";continue}if(s+=r,t++,/[\w$]/.test(r))i=/[\w$]/.test(n)?i+r:r,n=r;else if(!/\s/.test(r))n=r,i=""}return s}function Q(e){let s=new Uint16Array(e.length),t=0,n=!0;for(let i=0;i<e.length;i++){let o=e[i];if(o===")"||o==="]"||o==="}")if(t===0)n=!1;else t--;if(s[i]=t,o==="("||o==="["||o==="{")t++}return{depths:s,balanced:n&&t===0}}function Ce(e){let s=e.indexOf(" as ");if(s!==-1){let o=e.slice(0,s).trim(),r=e.slice(s+4).trim();return o&&r?{arrayExpr:o,itemVar:r}:null}let t=/^\s*(.+?)\s+in\s+([\s\S]+)$/.exec(e);if(!t)return null;let n=t[1].trim().replace(/^\(([\s\S]*)\)$/,"$1").trim(),i=t[2].trim();return n&&i?{arrayExpr:i,itemVar:n}:null}var G=["batch","cachedQuery","clearServerData","computed","configureFetch","defineEmits","defineExpose","definePageMeta","defineProps","defineSlots","defineStore","derived","effect","flushKeptState","forgetKeptState","goBack","goForward","inject","invalidateRoute","isDerived","isSignal","keptState","navigate","nextTick","onBeforeMount","onBeforeUnmount","onDestroy","onMount","onMounted","onUnmounted","peek","provide","reactive","ref","refDebounced","refresh","registerStoresClient","setKeptScope","setRouteParams","state","untrack","useAsync","useClickOutside","useColorMode","useCookie","useCounter","useDark","useDebounce","useDebounceFn","useDebouncedValue","useDocumentVisibility","useEventListener","useFetch","useFocus","useHead","useId","useInterval","useLocalStorage","useMediaQuery","useModel","useMutation","useOptimistic","usePreferredContrast","usePreferredDark","usePreferredLight","usePreferredReducedMotion","useQuery","useReactiveProp","useRef","useRoute","useRouteParam","useRouteParams","useScrollLock","useSearchParams","useSeoMeta","useSessionStorage","useSlots","useStore","useThrottle","useThrottleFn","useTimeout","useTimeoutFn","useToggle","useWebSocket","watch","watchEffect","watchMultiple","withDefaults"];var At=["defineEmits","defineExpose","definePageMeta","defineProps","defineSlots","withDefaults"];var Cn=G.filter((e)=>!At.includes(e));var Rt=["x-text","x-html","x-model","x-show","x-if","x-for","x-cloak","x-ref","x-data","x-bind","x-class","x-style","x-tooltip","x-tooltip-position"],Dt=["x-init","x-transition","x-effect","x-on"],kn=[...Rt,...Dt];var J=V(require("node:fs"),1),K=V(require("node:path"),1);function ke(e,s,t,n){let i=0;for(let o=s;o<e.length;o++)if(e[o]===t)i++;else if(e[o]===n&&!(n===">"&&e[o-1]==="=")){if(--i===0)return o}return-1}function Pt(e){let s=L(e),t=0,n=0,i=[];for(let o=0;o<s.length;o++)if("([{".includes(s[o]))t++;else if(")]}".includes(s[o]))t--;else if(s[o]===","&&t===0)i.push(e.slice(n,o).trim()),n=o+1;return i.push(e.slice(n).trim()),i}function ce(e,s){let t=L(e),n=new RegExp(`\\b(?:${s.map((i)=>i.replace(/[$]/g,"\\$&")).join("|")})\\s*(?=[<(])`,"g");for(let i of t.matchAll(n)){let o=i.index+i[0].length,r="";if(t[o]==="<"){let c=ke(t,o,"<",">");if(c<0)continue;r=e.slice(o+1,c),o=c+1;while(/\s/.test(t[o]||"")&&o<t.length)o++}if(t[o]!=="(")continue;let a=ke(t,o,"(",")");if(a>=0)return{type:r,args:Pt(e.slice(o+1,a))}}return null}var Ae=`
10
+ `:" ",t++}s+=" ",t++,n=W,i="";continue}if(s+=r,t++,/[\w$]/.test(r))i=/[\w$]/.test(n)?i+r:r,n=r;else if(!/\s/.test(r))n=r,i=""}return s}function Q(e){let s=new Uint16Array(e.length),t=0,n=!0;for(let i=0;i<e.length;i++){let o=e[i];if(o===")"||o==="]"||o==="}")if(t===0)n=!1;else t--;if(s[i]=t,o==="("||o==="["||o==="{")t++}return{depths:s,balanced:n&&t===0}}function Ce(e){let s=e.indexOf(" as ");if(s!==-1){let o=e.slice(0,s).trim(),r=e.slice(s+4).trim();return o&&r?{arrayExpr:o,itemVar:r}:null}let t=/^\s*(.+?)\s+in\s+([\s\S]+)$/.exec(e);if(!t)return null;let n=t[1].trim().replace(/^\(([\s\S]*)\)$/,"$1").trim(),i=t[2].trim();return n&&i?{arrayExpr:i,itemVar:n}:null}var G=["batch","cachedQuery","clearServerData","computed","configureFetch","defineEmits","defineExpose","definePageMeta","defineProps","defineSlots","defineStore","derived","effect","flushKeptState","forgetKeptState","goBack","goForward","inject","invalidateRoute","isDerived","isSignal","keptState","memo","navigate","nextTick","onBeforeMount","onBeforeUnmount","onDestroy","onMount","onMounted","onUnmounted","peek","provide","reactive","ref","refDebounced","refresh","registerStoresClient","setKeptScope","setRouteParams","sharedRequest","state","untrack","useAsync","useClickOutside","useColorMode","useCookie","useCounter","useDark","useDebounce","useDebounceFn","useDebouncedValue","useDocumentVisibility","useEventListener","useFetch","useFocus","useHead","useId","useInterval","useLocalStorage","useMediaQuery","useModel","useMutation","useOptimistic","usePreferredContrast","usePreferredDark","usePreferredLight","usePreferredReducedMotion","useQuery","useReactiveProp","useRef","useRoute","useRouteParam","useRouteParams","useScrollLock","useSearchParams","useSeoMeta","useSessionStorage","useSlots","useStore","useThrottle","useThrottleFn","useTimeout","useTimeoutFn","useToggle","useWebSocket","watch","watchEffect","watchMultiple","withDefaults"];var At=["defineEmits","defineExpose","definePageMeta","defineProps","defineSlots","withDefaults"];var Cn=G.filter((e)=>!At.includes(e));var Rt=["x-text","x-html","x-model","x-show","x-if","x-for","x-cloak","x-ref","x-data","x-bind","x-class","x-style","x-tooltip","x-tooltip-position"],Dt=["x-init","x-transition","x-effect","x-on"],kn=[...Rt,...Dt];var J=V(require("node:fs"),1),K=V(require("node:path"),1);function ke(e,s,t,n){let i=0;for(let o=s;o<e.length;o++)if(e[o]===t)i++;else if(e[o]===n&&!(n===">"&&e[o-1]==="=")){if(--i===0)return o}return-1}function Pt(e){let s=L(e),t=0,n=0,i=[];for(let o=0;o<s.length;o++)if("([{".includes(s[o]))t++;else if(")]}".includes(s[o]))t--;else if(s[o]===","&&t===0)i.push(e.slice(n,o).trim()),n=o+1;return i.push(e.slice(n).trim()),i}function ce(e,s){let t=L(e),n=new RegExp(`\\b(?:${s.map((i)=>i.replace(/[$]/g,"\\$&")).join("|")})\\s*(?=[<(])`,"g");for(let i of t.matchAll(n)){let o=i.index+i[0].length,r="";if(t[o]==="<"){let c=ke(t,o,"<",">");if(c<0)continue;r=e.slice(o+1,c),o=c+1;while(/\s/.test(t[o]||"")&&o<t.length)o++}if(t[o]!=="(")continue;let a=ke(t,o,"(",")");if(a>=0)return{type:r,args:Pt(e.slice(o+1,a))}}return null}var Ae=`
11
11
  type __StxCtor<T> = T extends StringConstructor ? string : T extends NumberConstructor ? number : T extends BooleanConstructor ? boolean : T extends ArrayConstructor ? unknown[] : T extends ObjectConstructor ? object : T extends readonly unknown[] ? __StxCtor<T[number]> : T extends abstract new (...args: any[]) => infer V ? V : unknown;
12
12
  type __StxWiden<T> = T extends string ? string : T extends number ? number : T extends boolean ? boolean : T;
13
13
  type __StxOption<T> = T extends { type: infer C } ? __StxCtor<C> : T extends { default: infer D } ? D extends (...args: any[]) => infer V ? V : __StxWiden<D> : __StxCtor<T>;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@stacksjs/stx-vscode",
3
3
  "type": "module",
4
- "version": "0.2.574",
4
+ "version": "0.2.576",
5
5
  "description": "stx language support for VS Code extensions to embed: the hovers, completions, diagnostics, grammar, snippets, language configuration and TypeScript server plugin behind the stx extension.",
6
6
  "author": "Chris Breuer <chris@stacksjs.org>",
7
7
  "license": "MIT",