-
-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(reactivity-transform-vue2): init
closes #92
- Loading branch information
Showing
32 changed files
with
691 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
'unplugin-vue-macros': minor | ||
'@vue-macros/reactivity-transform-vue2': patch | ||
--- | ||
|
||
support reactivity transform in Vue 2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ coverage | |
.turbo | ||
.idea | ||
dev-dist | ||
docs/.vitepress/cache | ||
|
||
.DS_Store | ||
.pnpm-debug.log* | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Reactivity Transform on Vue 2 | ||
|
||
<small>Stability: <code class="!text-yellow-600">unstable</code></small> | ||
|
||
See also [official docs](https://vuejs.org/guide/extras/reactivity-transform.html) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# @vue-macros/reactivity-transform-vue2 [![npm](https://img.shields.io/npm/v/@vue-macros/reactivity-transform-vue2.svg)](https://npmjs.com/package/@vue-macros/reactivity-transform-vue2) | ||
|
||
Please refer to [README.md](https://github.com/sxzz/unplugin-vue-macros#readme) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import type { | ||
$ as _$, | ||
$$ as _$$, | ||
$computed as _$computed, | ||
$customRef as _$customRef, | ||
$ref as _$ref, | ||
$shallowRef as _$shallowRef, | ||
$toRef as _$toRef, | ||
} from './macros' | ||
|
||
declare global { | ||
const $: typeof _$ | ||
const $$: typeof _$$ | ||
const $ref: typeof _$ref | ||
const $shallowRef: typeof _$shallowRef | ||
const $computed: typeof _$computed | ||
const $customRef: typeof _$customRef | ||
const $toRef: typeof _$toRef | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
import type { | ||
ComputedRef, | ||
CustomRefFactory, | ||
DebuggerOptions, | ||
Ref, | ||
UnwrapRef, | ||
WritableComputedOptions, | ||
WritableComputedRef, | ||
} from 'vue' | ||
|
||
export declare const RefType: unique symbol | ||
|
||
export declare const enum RefTypes { | ||
Ref = 1, | ||
ComputedRef = 2, | ||
WritableComputedRef = 3, | ||
} | ||
|
||
type RefValue<T> = T extends null | undefined ? T : ReactiveVariable<T> | ||
|
||
type ReactiveVariable<T> = T & { [RefType]?: RefTypes.Ref } | ||
|
||
type ComputedRefValue<T> = T extends null | undefined ? T : ComputedVariable<T> | ||
|
||
type ComputedVariable<T> = T & { [RefType]?: RefTypes.ComputedRef } | ||
|
||
type WritableComputedRefValue<T> = T extends null | undefined | ||
? T | ||
: WritableComputedVariable<T> | ||
|
||
type WritableComputedVariable<T> = T & { | ||
[RefType]?: RefTypes.WritableComputedRef | ||
} | ||
|
||
type NormalObject<T extends object> = T & { [RefType]?: never } | ||
|
||
/** | ||
* Vue ref transform macro for binding refs as reactive variables. | ||
*/ | ||
export declare function $<T>(arg: ComputedRef<T>): ComputedRefValue<T> | ||
export declare function $<T>( | ||
arg: WritableComputedRef<T> | ||
): WritableComputedRefValue<T> | ||
export declare function $<T>(arg: Ref<T>): RefValue<T> | ||
export declare function $<T extends object>(arg?: T): DestructureRefs<T> | ||
|
||
type DestructureRefs<T extends object> = { | ||
[K in keyof T]: T[K] extends ComputedRef<infer V> | ||
? ComputedRefValue<V> | ||
: T[K] extends WritableComputedRef<infer V> | ||
? WritableComputedRefValue<V> | ||
: T[K] extends Ref<infer V> | ||
? RefValue<V> | ||
: T[K] | ||
} | ||
|
||
/** | ||
* Vue ref transform macro for accessing underlying refs of reactive variables. | ||
*/ | ||
export declare function $$<T extends object>(arg: NormalObject<T>): ToRawRefs<T> | ||
export declare function $$<T>(value: RefValue<T>): Ref<T> | ||
export declare function $$<T>(value: ComputedRefValue<T>): ComputedRef<T> | ||
export declare function $$<T>( | ||
value: WritableComputedRefValue<T> | ||
): WritableComputedRef<T> | ||
|
||
type ToRawRefs<T extends object> = { | ||
[K in keyof T]: T[K] extends RefValue<infer V> | ||
? Ref<V> | ||
: T[K] extends ComputedRefValue<infer V> | ||
? ComputedRef<V> | ||
: T[K] extends WritableComputedRefValue<infer V> | ||
? WritableComputedRef<V> | ||
: T[K] extends object | ||
? T[K] extends | ||
| Function | ||
| Map<any, any> | ||
| Set<any> | ||
| WeakMap<any, any> | ||
| WeakSet<any> | ||
? T[K] | ||
: ToRawRefs<T[K]> | ||
: T[K] | ||
} | ||
|
||
export declare function $ref<T>(): RefValue<T | undefined> | ||
export declare function $ref<T>(arg: T | Ref<T>): RefValue<UnwrapRef<T>> | ||
|
||
export declare function $shallowRef<T>(): RefValue<T | undefined> | ||
export declare function $shallowRef<T>(arg: T): RefValue<T> | ||
|
||
export declare function $toRef<T extends object, K extends keyof T>( | ||
object: T, | ||
key: K | ||
): RefValue<T[K]> | ||
|
||
export declare function $toRef<T extends object, K extends keyof T>( | ||
object: T, | ||
key: K, | ||
defaultValue: T[K] | ||
): RefValue<Exclude<T[K], undefined>> | ||
|
||
export declare function $customRef<T>(factory: CustomRefFactory<T>): RefValue<T> | ||
|
||
export declare function $computed<T>( | ||
getter: () => T, | ||
debuggerOptions?: DebuggerOptions | ||
): ComputedRefValue<T> | ||
export declare function $computed<T>( | ||
options: WritableComputedOptions<T>, | ||
debuggerOptions?: DebuggerOptions | ||
): WritableComputedRefValue<T> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
"name": "@vue-macros/reactivity-transform-vue2", | ||
"version": "0.0.0", | ||
"packageManager": "pnpm@7.20.0", | ||
"description": "", | ||
"keywords": [ | ||
"unplugin", | ||
"vue", | ||
"sfc", | ||
"setup", | ||
"macros", | ||
"script-setup", | ||
"reactivity-transform-vue2" | ||
], | ||
"license": "MIT", | ||
"homepage": "https://github.com/sxzz/unplugin-vue-macros#readme", | ||
"bugs": { | ||
"url": "https://github.com/sxzz/unplugin-vue-macros/issues" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/sxzz/unplugin-vue-macros.git" | ||
}, | ||
"author": "三咲智子 <sxzz@sxzz.moe>", | ||
"files": [ | ||
"dist", | ||
"macros.d.ts", | ||
"macros-global.d.ts" | ||
], | ||
"main": "dist/index.js", | ||
"module": "dist/index.mjs", | ||
"types": "index.d.ts", | ||
"exports": { | ||
".": { | ||
"require": "./dist/index.js", | ||
"import": "./dist/index.mjs" | ||
}, | ||
"./vite": { | ||
"require": "./dist/vite.js", | ||
"import": "./dist/vite.mjs" | ||
}, | ||
"./webpack": { | ||
"require": "./dist/webpack.js", | ||
"import": "./dist/webpack.mjs" | ||
}, | ||
"./rollup": { | ||
"require": "./dist/rollup.js", | ||
"import": "./dist/rollup.mjs" | ||
}, | ||
"./esbuild": { | ||
"require": "./dist/esbuild.js", | ||
"import": "./dist/esbuild.mjs" | ||
}, | ||
"./macros": "./macros.d.ts", | ||
"./macros-global": "./macros-global.d.ts", | ||
"./*": "./*" | ||
}, | ||
"typesVersions": { | ||
"*": { | ||
"*": [ | ||
"./dist/*", | ||
"./*" | ||
] | ||
} | ||
}, | ||
"scripts": { | ||
"build": "tsup && tsx ../../scripts/postbuild.mts", | ||
"dev": "DEV=1 tsup" | ||
}, | ||
"peerDependencies": { | ||
"vue": "^2.7.0" | ||
}, | ||
"dependencies": { | ||
"@rollup/pluginutils": "^5.0.2", | ||
"@vue-macros/common": "workspace:~", | ||
"@vue/reactivity-transform": "^3.2.45", | ||
"unplugin": "^1.0.1" | ||
}, | ||
"devDependencies": { | ||
"vue": "^2.7.14" | ||
}, | ||
"engines": { | ||
"node": ">=14.19.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
export const helperId = '/vue2-reactivity-transform-helper' | ||
export const helperCode = `export function createPropsRestProxy(props, excludedKeys) { | ||
const ret = {} | ||
for (const key in props) { | ||
if (!excludedKeys.includes(key)) { | ||
Object.defineProperty(ret, key, { | ||
enumerable: true, | ||
get: () => props[key], | ||
}) | ||
} | ||
} | ||
return ret | ||
}` |
Oops, something went wrong.