@onoxm/react-tools 0.1.5

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.
package/LICENSE.md ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 ONO
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.
@@ -0,0 +1 @@
1
+ import{selectProperties as r}from "./utils/dist/utils/common/selectProperties.js";import{useShallow as s}from "zustand/shallow";const m=(e)=>(o)=>e(s((t)=>r(t,o)));export{m as createDesignateStore};
@@ -0,0 +1 @@
1
+ import{jsx as n}from "react/jsx-runtime";import{c as o}from "react/compiler-runtime";import{useContext as l,createContext as h,useReducer as u}from "react";const y={get:(e)=>e,set:(e,t)=>({...e,[t.key]:t.value}),del:(e,t)=>{const r={...e};return delete r[t.key],r;}},v=(e,t)=>y[t.type](e,t),p=h(null),x=(e)=>{const t=o(5),{initData:r,children:d}=e,[i,s]=u(v,r);let a,c;return t[0]!==i ?(a={data:i,dispatch:s},t[0]=i,t[1]=a):a=t[1],t[2]!==d||t[3]!==a ?(c=n(p.Provider,{value:a,children:d}),t[2]=d,t[3]=a,t[4]=c):c=t[4],c;},f=()=>{const e=o(6),t=l(p);if(!t)throw new Error("useData must be used within a DataProvider");let r;e[0]!==t ?(r={set:(s,a)=>{typeof a=="function" ? t.dispatch({type:"set",key:s,value:a(t.data[s])}):t.dispatch({type:"set",key:s,value:a});},setAll:(s)=>Object.keys(s).forEach((a)=>t.dispatch({type:"set",key:a,value:s[a]})),del:(s)=>t.dispatch({type:"del",key:s})},e[0]=t,e[1]=r):r=e[1];const d=r;let i;return e[2]!==t.data||e[3]!==t.dispatch||e[4]!==d ?(i={data:t.data,dispatch:d,originDispatch:t.dispatch},e[2]=t.data,e[3]=t.dispatch,e[4]=d,e[5]=i):i=e[5],i;},w=(e)=>f;export{x as DataProvider,w as createContextData};
@@ -0,0 +1 @@
1
+ import{createDesignateStore as t}from "./createDesignateStore.js";import{DataProvider as a,createContextData as p}from "./createStateManagementHook.js";import{portalRenderer as f}from "./portalRenderer.js";export{a as DataProvider,p as createContextData,t as createDesignateStore,f as portalRenderer};
@@ -0,0 +1 @@
1
+ import{jsx as C}from "react/jsx-runtime";import $ from "react-dom/client";const r=new Map(),E=(h,g,d,i)=>{const{target:y,root:m,reactRoot:l}=((n,o)=>{const a=n||`${o}-${Math.random().toString(36)}`;if(r.has(a)){const s=r.get(a);if(document.contains(s.target))return s;r.delete(a);}let e,c,t=null;o&&(t=document.getElementById(o),t||(t=document.createElement("div"),t.id=o,document.body.appendChild(t))),n ?(e=document.getElementById(n)?? document.createElement("div"),e.id||(e.id=n,t ? t.appendChild(e):document.body.appendChild(e))):(e=document.createElement("div"),t ? t.appendChild(e):document.body.appendChild(e)),e.__reactContainer$ ? c=e.__reactContainer$:(c=$.createRoot(e),e.__reactContainer$=c);const p={target:e,root:t,reactRoot:c};return r.set(a,p),p;})(d,i),u=(n)=>{try{typeof n=="function"&&n();const o=d||`${i}-${Math.random().toString(36)}`;r.delete(o),l.unmount(),d ? document.getElementById(d)?.remove():y.remove(),requestAnimationFrame(()=>{m&&m.children.length===0&&m.remove();});}catch{}};return l.render(C(h,{...g,destroy:u})),u;};export{E as portalRenderer};
@@ -0,0 +1 @@
1
+ const n=(e)=>{const t=new Set();for(const s of e){if(t.has(s))return!0;t.add(s);}return!1;};export{n as hasDuplicates};
@@ -0,0 +1 @@
1
+ import{hasDuplicates as i}from "./hasDuplicates.js";const f=(r,e=[],n=!0)=>{if(e.length===0)return r;if(i(e))throw new Error("Each item in properties must be unique");if(n){const s={};for(const t of e)s[t]=r[t];return s;}{const s=new Set(e),t={};for(const o in r)s.has(o)||(t[o]=r[o]);return t;}};export{f as selectProperties};
@@ -0,0 +1,2 @@
1
+ import { StoreApi, UseBoundStore } from 'zustand';
2
+ export declare const createDesignateStore: <T extends Record<string, unknown>, K extends keyof T>(useStore: UseBoundStore<StoreApi<T>>) => (designateStates: K[]) => Pick<T, K>;
@@ -0,0 +1,26 @@
1
+ import { ReactNode } from 'react';
2
+ type Action<T> = {
3
+ type: 'get' | 'set' | 'del';
4
+ key: keyof T;
5
+ value?: unknown;
6
+ };
7
+ export declare const DataProvider: <T extends Record<string, unknown>>({ initData, children }: {
8
+ initData: T;
9
+ children: ReactNode;
10
+ }) => import("react/jsx-runtime").JSX.Element;
11
+ export declare const createContextData: <T extends Record<string, unknown>>(initData: T) => () => {
12
+ data: T;
13
+ dispatch: {
14
+ set: <K extends keyof T>(key: K, value: T[K] | ((prev: T[K]) => T[K])) => void;
15
+ setAll: (data: Partial<T>) => void;
16
+ del: <K extends keyof T>(key: K) => void;
17
+ };
18
+ originDispatch: import('react').Dispatch<Action<T>>;
19
+ };
20
+ export declare const createContextData2: <T extends Record<string, unknown>>() => {
21
+ (designateParams?: Partial<keyof T>): Partial<T>;
22
+ set<K extends keyof T>(key: K, value: T[K] | ((prev: T[K]) => T[K])): void;
23
+ setAll(data: Partial<T>): void;
24
+ del<K extends keyof T>(key: K): void;
25
+ };
26
+ export {};
@@ -0,0 +1,3 @@
1
+ export { createDesignateStore } from './createDesignateStore';
2
+ export { createContextData, DataProvider } from './createStateManagementHook';
3
+ export { portalRenderer } from './portalRenderer';
@@ -0,0 +1,2 @@
1
+ import { JSX } from 'react';
2
+ export declare const portalRenderer: <T>(Component: (props: T) => JSX.Element, props: Omit<T, "destroy">, id?: string, rootId?: string) => (onDestroy?: () => void) => void;
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@onoxm/react-tools",
3
+ "private": false,
4
+ "version": "0.1.5",
5
+ "description": "Component library by React + Typescript",
6
+ "type": "module",
7
+ "main": "./dist/tools/index.js",
8
+ "module": "./dist/tools/index.js",
9
+ "types": "./dist/index.d.ts",
10
+ "files": [
11
+ "dist",
12
+ "LICENSE.md"
13
+ ],
14
+ "exports": {
15
+ ".": {
16
+ "types": "./dist/types/index.d.ts",
17
+ "import": "./dist/tools/index.js",
18
+ "require": "./dist/tools/index.js"
19
+ },
20
+ "./dist/": {
21
+ "import": "./dist/",
22
+ "require": "./dist/"
23
+ }
24
+ },
25
+ "sideEffects": false,
26
+ "keywords": [
27
+ "react",
28
+ "typescript"
29
+ ],
30
+ "author": "ono",
31
+ "license": "MIT",
32
+ "dependencies": {
33
+ "@onoxm/utils": "0.1.5"
34
+ },
35
+ "peerDependencies": {
36
+ "@types/react": ">=18",
37
+ "@types/react-dom": ">=18",
38
+ "react": ">=18",
39
+ "react-dom": ">=18",
40
+ "zustand": ">=5"
41
+ },
42
+ "peerDependenciesMeta": {
43
+ "@types/react": {
44
+ "optional": true
45
+ },
46
+ "@types/react-dom": {
47
+ "optional": true
48
+ },
49
+ "zustand": {
50
+ "optional": true
51
+ }
52
+ },
53
+ "publishConfig": {
54
+ "access": "public"
55
+ },
56
+ "scripts": {
57
+ "build": "vite build"
58
+ }
59
+ }