-
-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
961fb2b
commit 84620fe
Showing
6 changed files
with
144 additions
and
0 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,10 @@ | ||
# `@oku-ui/compose-refs` | ||
|
||
## Installation | ||
|
||
```sh | ||
$ pnpm add @oku-ui/compose-refs | ||
``` | ||
|
||
## Usage | ||
... |
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,42 @@ | ||
{ | ||
"name": "@oku-ui/compose-refs", | ||
"type": "module", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
"source": "src/index.ts", | ||
"funding": "https://github.com/sponsors/productdevbook", | ||
"homepage": "https://oku-ui.com/primitives", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/oku-ui/primitives.git" | ||
}, | ||
"bugs": { | ||
"url": "https://github.com/oku-ui/primitives/issues" | ||
}, | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"require": "./dist/compose-refs.cjs", | ||
"import": "./dist/compose-refs.js" | ||
} | ||
}, | ||
"main": "dist/compose-refs.cjs", | ||
"module": "dist/compose-refs.js", | ||
"types": "dist/types/index.d.ts", | ||
"files": [ | ||
"dist", | ||
"README.md" | ||
], | ||
"scripts": { | ||
"clean": "rm -rf dist", | ||
"build": "vite build --mode production", | ||
"lint": "eslint .", | ||
"lint:fix": "eslint . --fix" | ||
}, | ||
"peerDependencies": { | ||
"vue": "^3.2.47" | ||
}, | ||
"devDependencies": { | ||
"tsconfig": "workspace:^" | ||
} | ||
} |
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,34 @@ | ||
import type { Ref } from 'vue' | ||
import { onMounted, onUnmounted, ref } from 'vue' | ||
|
||
function useComposedRefs(refs: Ref[]) { | ||
const composedRef = ref(null) | ||
|
||
onMounted(() => { | ||
composedRef.value = refs.reduce((acc: any, ref) => { | ||
if (!ref || !ref.value) | ||
return acc | ||
if (typeof acc === 'function') { | ||
return (value: any) => { | ||
ref.value = value | ||
acc(value) | ||
} | ||
} | ||
else { | ||
ref.value = acc | ||
return ref.value | ||
} | ||
}, null) | ||
}) | ||
|
||
onUnmounted(() => { | ||
refs.forEach((ref) => { | ||
if (ref && ref.value) | ||
ref.value = null | ||
}) | ||
}) | ||
|
||
return composedRef | ||
} | ||
|
||
export { useComposedRefs } |
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 @@ | ||
export { useComposedRefs } from './compose-refs' |
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,9 @@ | ||
{ | ||
"extends": "./../../../tsconfig.json", | ||
"compilerOptions": { | ||
"baseUrl": "." | ||
}, | ||
"include": [ | ||
"./" | ||
] | ||
} |
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,48 @@ | ||
import path, { resolve } from 'node:path' | ||
|
||
import Vue from '@vitejs/plugin-vue' | ||
import { defineConfig } from 'vite' | ||
|
||
// https://github.com/qmhc/vite-plugin-dts | ||
import dtsPlugin from 'vite-plugin-dts' | ||
|
||
// https://github.com/sxzz/unplugin-vue-macros | ||
import VueMacros from 'unplugin-vue-macros/vite' | ||
|
||
import * as pkg from './package.json' | ||
|
||
const externals = [ | ||
...Object.keys(pkg.peerDependencies || {}), | ||
...Object.keys(pkg.dependencies || {}), | ||
] | ||
export default defineConfig({ | ||
plugins: [ | ||
dtsPlugin({ | ||
include: ['./src/**/*.ts', './src/**/*.tsx', './src/**/*.vue'], | ||
skipDiagnostics: false, | ||
staticImport: true, | ||
outputDir: ['./dist/types'], | ||
cleanVueFileName: false, | ||
}), | ||
VueMacros({ | ||
plugins: { | ||
vue: Vue(), | ||
}, | ||
}), | ||
], | ||
resolve: { | ||
alias: { | ||
'@': resolve(__dirname, 'src'), | ||
}, | ||
}, | ||
build: { | ||
target: 'modules', | ||
lib: { | ||
entry: path.resolve(__dirname, './src/index.ts'), | ||
formats: ['es', 'cjs'], | ||
}, | ||
rollupOptions: { | ||
external: externals, | ||
}, | ||
}, | ||
}) |