Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(vue2.7): WIP support vue2.7 #1033

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 18 additions & 25 deletions docs/api/vue-composable.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -729,9 +729,7 @@ export interface LocalStorageReturn<T> {
clear: () => void;
remove: () => void;
setSync: (sync: boolean) => void;
// (undocumented)
storage: Ref<T>;
// (undocumented)
storage: Ref<T | undefined>;
supported: boolean;
}

Expand Down Expand Up @@ -1071,6 +1069,14 @@ export interface ScrollResult {
scrollTopTo: (y: number) => void;
}

// @public (undocumented)
export interface sessionStorageReturn<T> {
clear: () => void;
remove: () => void;
storage: Ref<T | undefined>;
supported: boolean;
}

// Warning: (ae-forgotten-export) The symbol "TailwindConfigEmpty" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ExtractTailwindScreens" needs to be exported by the entry point index.d.ts
//
Expand Down Expand Up @@ -1749,17 +1755,11 @@ export function useLanguage(): {
};

// @public (undocumented)
export function useLocalStorage(
key: RefTyped<string>,
defaultValue?: RefTyped<string>,
sync?: boolean
): LocalStorageReturn<string>;

// @public (undocumented)
export function useLocalStorage<T>(
export function useLocalStorage<T = string>(
key: RefTyped<string>,
defaultValue?: RefTyped<T>,
sync?: boolean
sync?: boolean,
useDebounce?: boolean
): LocalStorageReturn<T>;

// @public (undocumented)
Expand Down Expand Up @@ -2169,18 +2169,11 @@ export function useRetry<T, TArgs extends Array<any>>(
): RetryReturnFactory<T, TArgs>;

// @public (undocumented)
export function useSessionStorage(
key: RefTyped<string>,
defaultValue?: RefTyped<string>,
sync?: boolean
): LocalStorageReturn<string>;

// @public (undocumented)
export function useSessionStorage<T>(
export function useSessionStorage<T = string>(
key: RefTyped<string>,
defaultValue?: RefTyped<T>,
sync?: boolean
): LocalStorageReturn<T>;
useDebounce?: boolean
): sessionStorageReturn<T>;

// Warning: (ae-forgotten-export) The symbol "NavigatorShareData" needs to be exported by the entry point index.d.ts
// Warning: (ae-forgotten-export) The symbol "ShareReturn" needs to be exported by the entry point index.d.ts
Expand Down Expand Up @@ -2302,7 +2295,7 @@ export function useWorkerFunction<T, TArgs extends Array<any>>(
export const VERSION: string;

// @public (undocumented)
export const VUE_VERSION: "2" | "3";
export const VUE_VERSION: "2" | "2.7" | "3";

// @public (undocumented)
export const VueComposableDevtools: {
Expand Down Expand Up @@ -2351,7 +2344,7 @@ export interface WebStorage {
$watchHandlers: Map<string, Function>;
clear(): void;
getItem<T = any>(key: string): Ref<T> | null;
getRef<T = any>(key: RefTyped<string>): Ref<T>;
getRef<T = any>(key: RefTyped<string>, useDebounce?: boolean): Ref<T>;
key(index: number): string | null;
readonly length: number;
removeItem(key: string): void;
Expand Down Expand Up @@ -2401,7 +2394,7 @@ export type WrapRef<T> = T extends Ref<any> ? T : Ref<T>;

// Warnings were encountered during analysis:
//
// dist/v3/packages/vue-composable/src/validation/validation.d.ts:72:5 - (ae-forgotten-export) The symbol "ToObjectOutput" needs to be exported by the entry point index.d.ts
// src/validation/validation.ts:397:46 - (ae-forgotten-export) The symbol "ToObjectOutput" needs to be exported by the entry point index.d.ts

// (No @packageDocumentation comment for this package)
```
1 change: 1 addition & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ module.exports = {
__SSR__: true,
__VERSION__: pkg.version,
__VUE_2__: process.env.VUE === "2",
__VUE_2Dot7__: process.env.VUE === "2.7",
__COMMIT__: "none",
},
setupFiles: [
Expand Down
3 changes: 3 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,14 @@
"scripts": {
"build": "node scripts/build.js",
"build:vue2": "yarn build --version=2",
"build:vue2.7": "yarn build --version=2.7",
"changelog": "conventional-changelog -p angular -i CHANGELOG.md -s -r 1",
"release": "node scripts/publish.js",
"test": "jest --coverage",
"test:watch": "jest --coverage --watch",
"test:prod": "npm run lint && npm run test -- --no-cache",
"test:vue2": "cross-env VUE=2 yarn test",
"test:vue2.7": "cross-env VUE=2.7 yarn test",
"docs:dev": "vuepress dev docs",
"docs:build": "vuepress build docs",
"lint": "prettier \"packages/**/*.ts\" \"docs/(.vuepress|Examples|composable)/**/*.md\" \"docs/.vuepress/*.js\" \"docs/**/*.vue\" --write"
Expand Down Expand Up @@ -98,6 +100,7 @@
"vue": "^2.6.14",
"vue-server-renderer": "^2.6.14",
"vue-template-compiler": "^2.6.14",
"vue2.7": "npm:vue@^2.7.0",
"vuepress": "^1.8.2",
"yorkie": "^2.0.0",
"zlib": "^1.0.5"
Expand Down
7 changes: 7 additions & 0 deletions packages/axios/api-extractor.v2.7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/v2.7/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/v2.7/<unscopedPackageName>.d.ts"
}
}
6 changes: 5 additions & 1 deletion packages/axios/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,9 @@
"@types/node": "^16.4.7",
"@vue/runtime-core": "^3.0.7",
"typescript": "^4.2.4"
},
"peerDependencies": {
"vue": "^3.0.0",
"axios": "^0.22.0"
}
}
}
18 changes: 18 additions & 0 deletions packages/axios/src/api.2.7.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/* istanbul ignore file */

export {
ref,
unref,
isRef,
Ref,
onMounted,
onUnmounted,
inject,
InjectionKey,
provide,
reactive,
computed,
UnwrapRef,
ComputedRef,
getCurrentInstance,
} from "vue2.7";
7 changes: 7 additions & 0 deletions packages/cookie/api-extractor.v2.7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/v2.7/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/v2.7/<unscopedPackageName>.d.ts"
}
}
7 changes: 6 additions & 1 deletion packages/cookie/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,10 @@
"@types/node": "^16.4.7",
"@vue/runtime-core": "^3.0.7",
"typescript": "^4.2.4"
},
"peerDependencies": {
"vue": "^3.0.0",
"@types/js-cookie": "^2.2.6",
"js-cookie": "^2.2.1"
}
}
}
3 changes: 3 additions & 0 deletions packages/cookie/src/api.2.7.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/* istanbul ignore file */

export { ref, Ref, onMounted, watch } from "vue2.7";
1 change: 1 addition & 0 deletions packages/global.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@ declare var __JSDOM__: boolean;
declare var __COMMIT__: string;
declare var __VERSION__: string;
declare var __VUE_2__: boolean;
declare var __VUE_2Dot7__: boolean;
declare var __SSR__: boolean;
7 changes: 7 additions & 0 deletions packages/vue-composable/api-extractor.v2.7.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "../../api-extractor.json",
"mainEntryPointFilePath": "./dist/v2.7/packages/<unscopedPackageName>/src/index.d.ts",
"dtsRollup": {
"untrimmedFilePath": "./dist/v2.7/<unscopedPackageName>.d.ts"
}
}
8 changes: 7 additions & 1 deletion packages/vue-composable/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,11 @@
"peerDependencies2": {
"@vue/composition-api": "^1.0.0-beta.14",
"vue": "^2.6.10"
},
"peerDependencies2.7": {
"vue": "^2.7.0"
},
"peerDependencies": {
"vue": "^3.0.0"
}
}
}
2 changes: 2 additions & 0 deletions packages/vue-composable/scripts/postinstall.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@ if (!Vue || typeof Vue.version !== "string") {
console.warn(
"[vue-composable] Vue is not detected in the dependencies. Please install Vue first."
);
} else if (Vue.version.startsWith("2.7")) {
switchVersion(2.7);
} else if (Vue.version.startsWith("2.")) {
const VCA = loadModule("@vue/composition-api");
if (!VCA) {
Expand Down
52 changes: 52 additions & 0 deletions packages/vue-composable/src/api.2.7.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/* istanbul ignore file */

export {
ref,
isRef,
unref,
Ref,
inject,
InjectionKey,
provide,
watch,
reactive,
computed,
getCurrentInstance,
onMounted,
onUnmounted,
onActivated,
onBeforeMount,
onBeforeUnmount,
onDeactivated,
ComputedRef,
toRaw,
UnwrapRef, // Plugin,
customRef,
watchEffect,
} from "vue2.7";
export { VueConstructor as App } from "vue2.7";

import Vue, { PluginFunction } from "vue2.7";
import { computed, Ref, set } from "vue2.7";
import { unwrap } from "./utils";

export type Plugin = PluginFunction<any>;

export const vueDelete = (x: any, o: string) => Vue.delete(x, o);
export const vueSet = set;

// FAKE readonly
export function readonly<T extends object>(
target: T
): T extends Ref ? DeepReadonly<T> : DeepReadonly<Ref<T>> {
return computed(() => unwrap(target)) as any;
}

// FAKE DeepReadonly
export type DeepReadonly<T> = Readonly<T>;

declare module "vue2.7" {
interface VueConstructor {
provide(key: any, value: any): void;
}
}
6 changes: 5 additions & 1 deletion packages/vue-composable/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,9 @@ export * from "./dom";

export const VERSION = __VERSION__;
// istanbul ignore next
export const VUE_VERSION: "2" | "3" = __VUE_2__ ? "2" : "3";
export const VUE_VERSION: "2" | "2.7" | "3" = __VUE_2Dot7__
? "2.7"
: __VUE_2__
? "2"
: "3";
export const COMMIT = __COMMIT__;
6 changes: 3 additions & 3 deletions packages/vue-composable/src/web/pageVisibility.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ref, Ref } from "../api";
import { isClient, PASSIVE_EV } from "../utils";

let visibility: Ref<DocumentVisibilityState> | undefined = undefined;
let visibility: Ref<VisibilityState> | undefined = undefined;
let hidden: Ref<boolean> | undefined = undefined;

export function usePageVisibility() {
Expand All @@ -21,11 +21,11 @@ export function usePageVisibility() {
PASSIVE_EV
);
} else {
visibility = ref<DocumentVisibilityState>("visible");
visibility = ref<VisibilityState>("visible");
}
}
return {
visibility,
hidden
hidden,
};
}
1 change: 1 addition & 0 deletions rollup.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ function createReplacePlugin(
: "'production'",

__VUE_2__: process.env.VUE_VERSION === "2",
__VUE_2Dot7__: process.env.VUE_VERSION === "2.7",
},
});
}
Expand Down
Loading