@basiln/utils 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +11 -5
- package/package.json +2 -3
- package/src/Choose.tsx +18 -10
- package/src/If.tsx +6 -2
- package/src/composeEventHandlers.ts +1 -1
- package/src/createContext.tsx +5 -5
- package/src/getVar.ts +1 -1
- package/src/index.ts +9 -3
- package/tsup.config.ts +5 -5
- package/LICENSE +0 -21
- package/src/types/Choose.ts +0 -14
- package/src/types/If.ts +0 -6
- package/src/types/getVar.ts +0 -1
- package/src/types/index.ts +0 -9
package/CHANGELOG.md
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
# Change Log
|
2
2
|
|
3
|
+
## 0.1.1
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- [#6](https://github.com/seedn-corp/basiln-packages-fe/pull/6) [`a7bb9b2`](https://github.com/seedn-corp/basiln-packages-fe/commit/a7bb9b27f214f4c8d9337dd586a0424fe8a98280) Thanks [@im-binary](https://github.com/im-binary)! - - 폴더 구조 수정
|
8
|
+
- eslint, prettier, settings.json 컨벤션에 맞게 수정
|
9
|
+
- changeset 관련 누락된 패키지 설치
|
10
|
+
|
3
11
|
All notable changes to this project will be documented in this file.
|
4
12
|
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
|
5
13
|
|
6
14
|
# 0.1.0 (2024-11-21)
|
7
15
|
|
8
|
-
|
9
16
|
### Bug Fixes
|
10
17
|
|
11
|
-
|
12
|
-
|
18
|
+
- **util:** build error fix ([cbb6bba](https://github.com/seedn-corp/basiln-packages-fe/commit/cbb6bbaf34ecfa267109961dd9d6853c93a0631f))
|
13
19
|
|
14
20
|
### Features
|
15
21
|
|
16
|
-
|
17
|
-
|
22
|
+
- tsup 세팅 ([c6e1aaf](https://github.com/seedn-corp/basiln-packages-fe/commit/c6e1aaf2f9b0ba6ef2090531bdcbe466581723d4))
|
23
|
+
- 컴포넌트 추가 ([3656d2f](https://github.com/seedn-corp/basiln-packages-fe/commit/3656d2f8c58a14a3fd7931c6349c34b49fce676c))
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@basiln/utils",
|
3
|
-
"version": "0.1.
|
3
|
+
"version": "0.1.1",
|
4
4
|
"exports": {
|
5
5
|
".": "./src/index.ts",
|
6
6
|
"./package.json": "./package.json"
|
@@ -44,6 +44,5 @@
|
|
44
44
|
"peerDependencies": {
|
45
45
|
"react": "^18",
|
46
46
|
"react-dom": "^18"
|
47
|
-
}
|
48
|
-
"gitHead": "dfa7ad216f0cd4359b92e63301de82980780f765"
|
47
|
+
}
|
49
48
|
}
|
package/src/Choose.tsx
CHANGED
@@ -1,18 +1,26 @@
|
|
1
|
-
import
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
}
|
1
|
+
import { isValidElement, type ReactNode, type FC, Children } from 'react';
|
2
|
+
|
3
|
+
export type ChooseWhenProps = {
|
4
|
+
condition: boolean;
|
5
|
+
children: ReactNode;
|
6
|
+
};
|
7
|
+
|
8
|
+
export type ChooseProps = {
|
9
|
+
children: ReactNode;
|
10
|
+
};
|
11
|
+
|
12
|
+
export type ChooseOtherwiseProps = {
|
13
|
+
children: ReactNode;
|
14
|
+
};
|
7
15
|
|
8
16
|
export function Choose({ children }: ChooseProps) {
|
9
|
-
const validChildren =
|
17
|
+
const validChildren = Children.toArray(children);
|
10
18
|
|
11
19
|
const matchingChild = validChildren.find(
|
12
|
-
child =>
|
20
|
+
(child) =>
|
13
21
|
isValidElement<ChooseWhenProps>(child) &&
|
14
22
|
child.type === Choose.When &&
|
15
|
-
child.props.condition
|
23
|
+
child.props.condition
|
16
24
|
);
|
17
25
|
|
18
26
|
if (matchingChild) {
|
@@ -20,7 +28,7 @@ export function Choose({ children }: ChooseProps) {
|
|
20
28
|
}
|
21
29
|
|
22
30
|
const otherwiseChild = validChildren.find(
|
23
|
-
child =>
|
31
|
+
(child) => isValidElement(child) && child.type === Choose.Otherwise
|
24
32
|
);
|
25
33
|
|
26
34
|
return otherwiseChild || <></>;
|
package/src/If.tsx
CHANGED
@@ -1,5 +1,9 @@
|
|
1
|
-
import
|
2
|
-
|
1
|
+
import { type ReactNode } from 'react';
|
2
|
+
|
3
|
+
export type IfProps = {
|
4
|
+
condition: boolean;
|
5
|
+
children: ReactNode;
|
6
|
+
};
|
3
7
|
|
4
8
|
export function If(props: IfProps) {
|
5
9
|
const { condition, children } = props;
|
@@ -3,7 +3,7 @@
|
|
3
3
|
export function composeEventHandlers<E>(
|
4
4
|
originalEventHandler?: (event: E) => void,
|
5
5
|
ourEventHandler?: (event: E) => void,
|
6
|
-
{ checkForDefaultPrevented = true } = {}
|
6
|
+
{ checkForDefaultPrevented = true } = {}
|
7
7
|
) {
|
8
8
|
return function handleEvent(event: E) {
|
9
9
|
originalEventHandler?.(event);
|
package/src/createContext.tsx
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
import
|
1
|
+
import {
|
2
2
|
useMemo,
|
3
3
|
createContext as createContextRaw,
|
4
4
|
useContext as useContextRaw,
|
@@ -7,10 +7,10 @@ import React, {
|
|
7
7
|
|
8
8
|
export function createContext<ContextValueType extends object | null>(
|
9
9
|
rootComponentName: string,
|
10
|
-
defaultContext?: ContextValueType
|
10
|
+
defaultContext?: ContextValueType
|
11
11
|
) {
|
12
12
|
const Context = createContextRaw<ContextValueType | undefined>(
|
13
|
-
defaultContext
|
13
|
+
defaultContext
|
14
14
|
);
|
15
15
|
|
16
16
|
function Provider(props: PropsWithChildren<ContextValueType>) {
|
@@ -18,7 +18,7 @@ export function createContext<ContextValueType extends object | null>(
|
|
18
18
|
|
19
19
|
const value = useMemo(
|
20
20
|
() => contextValues,
|
21
|
-
[contextValues]
|
21
|
+
[contextValues]
|
22
22
|
) as ContextValueType;
|
23
23
|
|
24
24
|
return <Context.Provider value={value}>{children}</Context.Provider>;
|
@@ -28,7 +28,7 @@ export function createContext<ContextValueType extends object | null>(
|
|
28
28
|
const context = useContextRaw(Context);
|
29
29
|
if (context == null) {
|
30
30
|
throw new Error(
|
31
|
-
`${consumerName}은 ${rootComponentName}하위에서 사용해야
|
31
|
+
`${consumerName}은 ${rootComponentName}하위에서 사용해야 합니다.`
|
32
32
|
);
|
33
33
|
}
|
34
34
|
|
package/src/getVar.ts
CHANGED
package/src/index.ts
CHANGED
@@ -1,5 +1,11 @@
|
|
1
|
-
export {
|
1
|
+
export {
|
2
|
+
Choose,
|
3
|
+
type ChooseWhenProps,
|
4
|
+
type ChooseProps,
|
5
|
+
type ChooseOtherwiseProps,
|
6
|
+
} from './Choose';
|
7
|
+
|
2
8
|
export { composeEventHandlers } from './composeEventHandlers';
|
3
9
|
export { createContext } from './createContext';
|
4
|
-
export { getVar } from './getVar';
|
5
|
-
export { If } from './If';
|
10
|
+
export { getVar, type VariableType } from './getVar';
|
11
|
+
export { If, type IfProps } from './If';
|
package/tsup.config.ts
CHANGED
@@ -1,13 +1,13 @@
|
|
1
|
-
import { defineConfig } from
|
2
|
-
import pkgJson from
|
1
|
+
import { defineConfig } from 'tsup';
|
2
|
+
import pkgJson from './package.json';
|
3
3
|
|
4
4
|
const external = [...Object.keys((pkgJson as any).peerDependencies || {})];
|
5
5
|
|
6
6
|
export default defineConfig({
|
7
|
-
entry: [
|
8
|
-
format: [
|
7
|
+
entry: ['src/**/*.{ts,tsx}'],
|
8
|
+
format: ['esm', 'cjs'],
|
9
9
|
sourcemap: true,
|
10
10
|
clean: true,
|
11
|
-
dts:
|
11
|
+
dts: 'src/index.ts',
|
12
12
|
external,
|
13
13
|
});
|
package/LICENSE
DELETED
@@ -1,21 +0,0 @@
|
|
1
|
-
MIT License
|
2
|
-
|
3
|
-
Copyright (c) 2024 SeedN
|
4
|
-
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
7
|
-
in the Software without restriction, including without limitation the rights
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
10
|
-
furnished to do so, subject to the following conditions:
|
11
|
-
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
13
|
-
copies or substantial portions of the Software.
|
14
|
-
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
-
SOFTWARE.
|
package/src/types/Choose.ts
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
import { ReactNode } from 'react';
|
2
|
-
|
3
|
-
export type ChooseWhenProps = {
|
4
|
-
condition: boolean;
|
5
|
-
children: ReactNode;
|
6
|
-
};
|
7
|
-
|
8
|
-
export type ChooseProps = {
|
9
|
-
children: ReactNode;
|
10
|
-
};
|
11
|
-
|
12
|
-
export type ChooseOtherwiseProps = {
|
13
|
-
children: ReactNode;
|
14
|
-
};
|
package/src/types/If.ts
DELETED
package/src/types/getVar.ts
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
export type VariableType = `--${string}`;
|