@hairy/react-lib 1.44.0 → 1.46.0

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/dist/index.cjs CHANGED
@@ -207,7 +207,7 @@ var Deferred = class extends Promise {
207
207
  };
208
208
 
209
209
  // ../util-core/src/util/json.ts
210
- function jsonTryParse(text) {
210
+ function tryParseJson(text) {
211
211
  try {
212
212
  return JSON.parse(text || "");
213
213
  } catch {
@@ -227,20 +227,20 @@ function track(fn, ...args) {
227
227
 
228
228
  // src/utils/wrapper.ts
229
229
  var import_react = require("react");
230
- function wrapper(tag, props, children) {
231
- return tag ? (0, import_react.createElement)(tag, props, children) : children;
230
+ function wrapper(asChild, props, children) {
231
+ return asChild ? (0, import_react.createElement)(asChild, props, children) : children;
232
232
  }
233
233
 
234
234
  // src/components/condition/Case.ts
235
235
  function Case(props) {
236
- const { cond, children, tag, ...attrs } = props;
237
- return wrapper(tag, attrs, children);
236
+ const { cond, children, tag, as: asChild, ...attrs } = props;
237
+ return wrapper(tag || asChild, attrs, children);
238
238
  }
239
239
 
240
240
  // src/components/condition/Default.ts
241
241
  function Default(props) {
242
- const { children, tag, ...attrs } = props;
243
- return wrapper(tag, attrs, children);
242
+ const { children, tag, as: asChild, ...attrs } = props;
243
+ return wrapper(tag || asChild, attrs, children);
244
244
  }
245
245
 
246
246
  // src/components/condition/If.ts
@@ -248,24 +248,24 @@ var import_react2 = require("react");
248
248
 
249
249
  // src/components/condition/Then.ts
250
250
  function Then(props) {
251
- const { children, cond, else: _else, then, tag, ...attrs } = props;
252
- return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag, attrs, children);
251
+ const { children, cond, else: _else, then, tag, as: asChild, ...attrs } = props;
252
+ return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
253
253
  }
254
254
 
255
255
  // src/components/condition/If.ts
256
256
  function If(props) {
257
- const { then, cond, else: _else, children = props.then, tag, ...attrs } = props;
257
+ const { then, cond, else: _else, children = props.then, tag, as: asChild, ...attrs } = props;
258
258
  const elements = import_react2.Children.toArray(children);
259
259
  const thenChild = elements.find((c) => c.type === Then);
260
260
  const elseChild = elements.find((c) => c.type === Else);
261
261
  const child = thenChild || elseChild ? cond ? thenChild : elseChild : cond ? children : _else;
262
- return wrapper(tag, attrs, child);
262
+ return wrapper(tag || asChild, attrs, child);
263
263
  }
264
264
 
265
265
  // src/components/condition/Else.ts
266
266
  function Else(props) {
267
- const { children, tag, ...attrs } = props;
268
- return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag, attrs, children);
267
+ const { children, tag, as: asChild, ...attrs } = props;
268
+ return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
269
269
  }
270
270
 
271
271
  // src/components/condition/Switch.ts
@@ -293,12 +293,12 @@ function Switch(props) {
293
293
  // src/components/condition/Unless.ts
294
294
  var import_react4 = require("react");
295
295
  function Unless(props) {
296
- const { cond, then, else: _else, tag, children = props.then, ...attrs } = props;
296
+ const { cond, then, else: _else, tag, as: asChild, children = props.then, ...attrs } = props;
297
297
  const elements = import_react4.Children.toArray(children);
298
298
  const thenChild = elements.find((c) => c.type === Then);
299
299
  const elseChild = elements.find((c) => c.type === Else);
300
300
  const child = thenChild || elseChild ? !cond ? elseChild : thenChild : !cond ? children : _else;
301
- return wrapper(tag, attrs, child);
301
+ return wrapper(tag || asChild, attrs, child);
302
302
  }
303
303
 
304
304
  // src/components/utils/Injector.ts
@@ -639,7 +639,7 @@ function proxyWithPersistant(keyOrOptions, initialObject) {
639
639
  }
640
640
  const storage = options.storage || (typeof localStorage !== "undefined" ? localStorage : void 0);
641
641
  typeof keyOrOptions === "string" && (keyOrOptions = { id: keyOrOptions });
642
- const state = (0, import_valtio3.proxy)(jsonTryParse(storage?.getItem(options.id)) || initialObject);
642
+ const state = (0, import_valtio3.proxy)(tryParseJson(storage?.getItem(options.id)) || initialObject);
643
643
  (0, import_valtio3.subscribe)(state, () => {
644
644
  const pick = options.pick || Object.keys(state);
645
645
  const statePick = {};
package/dist/index.d.ts CHANGED
@@ -32,10 +32,12 @@ declare namespace cls {
32
32
  declare function track<T extends AnyFn>(fn: T, ...args: Parameters<T>): Promise<ReturnType<T>>;
33
33
 
34
34
  type WrapperTag = keyof JSX.IntrinsicElements | Function;
35
- type WrapperProps<Kag extends keyof JSX.IntrinsicElements | React.FC | unknown> = {
36
- tag?: Kag;
37
- } & (Kag extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[Kag] : unknown) & (Kag extends React.FC<infer P> ? P : unknown);
38
- declare function wrapper(tag: any, props: unknown, children?: React.ReactNode): react.ReactNode;
35
+ type WrapperProps<As extends keyof JSX.IntrinsicElements | React.FC | unknown> = {
36
+ /** @deprecated use `as` instead */
37
+ tag?: As;
38
+ as?: As;
39
+ } & (As extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[As] : unknown) & (As extends React.FC<infer P> ? P : unknown);
40
+ declare function wrapper(asChild: any, props: unknown, children?: React.ReactNode): react.ReactNode;
39
41
 
40
42
  type CaseProps<Kag> = WrapperProps<Kag> & {
41
43
  cond?: BooleanLike;
@@ -231,6 +233,10 @@ interface PersistantOptions {
231
233
  storage?: Storage;
232
234
  pick?: string[];
233
235
  }
236
+ /**
237
+ *
238
+ * @deprecated please use `valtio-define`
239
+ */
234
240
  declare function proxyWithPersistant<T extends object>(key: string, initialObject?: T, options?: Omit<PersistantOptions, 'key'>): T;
235
241
  declare function proxyWithPersistant<T extends object>(options: PersistantOptions, initialObject?: T): T;
236
242
 
@@ -281,6 +287,7 @@ type Store<S, A extends Actions<S>, G extends Getters<S>> = {
281
287
 
282
288
  /**
283
289
  * @description Define a store
290
+ * @deprecated please use `valtio-define`
284
291
  * @example
285
292
  * ```tsx
286
293
  * const store = defineStore({
@@ -329,6 +336,7 @@ type StoreAsync<T extends AnyFn, Initial = StoreAsyncInitial<T> | undefined> = S
329
336
  }, {}>;
330
337
  /**
331
338
  * @description Define a store async
339
+ * @deprecated please use `valtio-define`
332
340
  * @example
333
341
  * ```tsx
334
342
  * const store = defineStoreAsync(
@@ -349,8 +357,16 @@ declare function defineStoreAsync<T extends AnyFn>(fetch: T, options?: StoreAsyn
349
357
  */
350
358
  declare const defienAsyncStore: typeof defineStoreAsync;
351
359
 
360
+ /**
361
+ *
362
+ * @deprecated please use `valtio-define`
363
+ */
352
364
  declare function useStatus<S extends object, A extends Actions<S>, G extends Getters<S>>(store: Store<S, A, G>): valtio.Snapshot<ActionsStatus<A>>;
353
365
 
366
+ /**
367
+ *
368
+ * @deprecated please use `valtio-define`
369
+ */
354
370
  declare function useStore<S extends object, A extends Actions<S>, G extends Getters<S>>(store: Store<S, A, G>): valtio.Snapshot<S & GettersReturnType<G> & ActionsOmitThisParameter<A>>;
355
371
 
356
372
  type PropsWithDetailedHTML<T = HTMLDivElement> = DetailedHTMLProps<HTMLAttributes<T>, T>;
@@ -218,7 +218,7 @@ var LibReact = (() => {
218
218
  };
219
219
 
220
220
  // ../util-core/src/util/json.ts
221
- function jsonTryParse(text) {
221
+ function tryParseJson(text) {
222
222
  try {
223
223
  return JSON.parse(text || "");
224
224
  } catch {
@@ -743,20 +743,20 @@ var LibReact = (() => {
743
743
 
744
744
  // src/utils/wrapper.ts
745
745
  var import_react2 = __toESM(require_react(), 1);
746
- function wrapper(tag, props, children) {
747
- return tag ? (0, import_react2.createElement)(tag, props, children) : children;
746
+ function wrapper(asChild, props, children) {
747
+ return asChild ? (0, import_react2.createElement)(asChild, props, children) : children;
748
748
  }
749
749
 
750
750
  // src/components/condition/Case.ts
751
751
  function Case(props) {
752
- const { cond, children, tag, ...attrs } = props;
753
- return wrapper(tag, attrs, children);
752
+ const { cond, children, tag, as: asChild, ...attrs } = props;
753
+ return wrapper(tag || asChild, attrs, children);
754
754
  }
755
755
 
756
756
  // src/components/condition/Default.ts
757
757
  function Default(props) {
758
- const { children, tag, ...attrs } = props;
759
- return wrapper(tag, attrs, children);
758
+ const { children, tag, as: asChild, ...attrs } = props;
759
+ return wrapper(tag || asChild, attrs, children);
760
760
  }
761
761
 
762
762
  // src/components/condition/If.ts
@@ -764,24 +764,24 @@ var LibReact = (() => {
764
764
 
765
765
  // src/components/condition/Then.ts
766
766
  function Then(props) {
767
- const { children, cond, else: _else, then, tag, ...attrs } = props;
768
- return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag, attrs, children);
767
+ const { children, cond, else: _else, then, tag, as: asChild, ...attrs } = props;
768
+ return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
769
769
  }
770
770
 
771
771
  // src/components/condition/If.ts
772
772
  function If(props) {
773
- const { then, cond, else: _else, children = props.then, tag, ...attrs } = props;
773
+ const { then, cond, else: _else, children = props.then, tag, as: asChild, ...attrs } = props;
774
774
  const elements = import_react3.Children.toArray(children);
775
775
  const thenChild = elements.find((c) => c.type === Then);
776
776
  const elseChild = elements.find((c) => c.type === Else);
777
777
  const child = thenChild || elseChild ? cond ? thenChild : elseChild : cond ? children : _else;
778
- return wrapper(tag, attrs, child);
778
+ return wrapper(tag || asChild, attrs, child);
779
779
  }
780
780
 
781
781
  // src/components/condition/Else.ts
782
782
  function Else(props) {
783
- const { children, tag, ...attrs } = props;
784
- return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag, attrs, children);
783
+ const { children, tag, as: asChild, ...attrs } = props;
784
+ return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
785
785
  }
786
786
 
787
787
  // src/components/condition/Switch.ts
@@ -809,12 +809,12 @@ var LibReact = (() => {
809
809
  // src/components/condition/Unless.ts
810
810
  var import_react5 = __toESM(require_react(), 1);
811
811
  function Unless(props) {
812
- const { cond, then, else: _else, tag, children = props.then, ...attrs } = props;
812
+ const { cond, then, else: _else, tag, as: asChild, children = props.then, ...attrs } = props;
813
813
  const elements = import_react5.Children.toArray(children);
814
814
  const thenChild = elements.find((c) => c.type === Then);
815
815
  const elseChild = elements.find((c) => c.type === Else);
816
816
  const child = thenChild || elseChild ? !cond ? elseChild : thenChild : !cond ? children : _else;
817
- return wrapper(tag, attrs, child);
817
+ return wrapper(tag || asChild, attrs, child);
818
818
  }
819
819
 
820
820
  // src/components/utils/Injector.ts
@@ -1367,7 +1367,7 @@ var LibReact = (() => {
1367
1367
  }
1368
1368
  const storage = options.storage || (typeof localStorage !== "undefined" ? localStorage : void 0);
1369
1369
  typeof keyOrOptions === "string" && (keyOrOptions = { id: keyOrOptions });
1370
- const state = proxy(jsonTryParse(storage?.getItem(options.id)) || initialObject);
1370
+ const state = proxy(tryParseJson(storage?.getItem(options.id)) || initialObject);
1371
1371
  subscribe(state, () => {
1372
1372
  const pick = options.pick || Object.keys(state);
1373
1373
  const statePick = {};
package/dist/index.js CHANGED
@@ -136,7 +136,7 @@ var Deferred = class extends Promise {
136
136
  };
137
137
 
138
138
  // ../util-core/src/util/json.ts
139
- function jsonTryParse(text) {
139
+ function tryParseJson(text) {
140
140
  try {
141
141
  return JSON.parse(text || "");
142
142
  } catch {
@@ -156,20 +156,20 @@ function track(fn, ...args) {
156
156
 
157
157
  // src/utils/wrapper.ts
158
158
  import { createElement } from "react";
159
- function wrapper(tag, props, children) {
160
- return tag ? createElement(tag, props, children) : children;
159
+ function wrapper(asChild, props, children) {
160
+ return asChild ? createElement(asChild, props, children) : children;
161
161
  }
162
162
 
163
163
  // src/components/condition/Case.ts
164
164
  function Case(props) {
165
- const { cond, children, tag, ...attrs } = props;
166
- return wrapper(tag, attrs, children);
165
+ const { cond, children, tag, as: asChild, ...attrs } = props;
166
+ return wrapper(tag || asChild, attrs, children);
167
167
  }
168
168
 
169
169
  // src/components/condition/Default.ts
170
170
  function Default(props) {
171
- const { children, tag, ...attrs } = props;
172
- return wrapper(tag, attrs, children);
171
+ const { children, tag, as: asChild, ...attrs } = props;
172
+ return wrapper(tag || asChild, attrs, children);
173
173
  }
174
174
 
175
175
  // src/components/condition/If.ts
@@ -177,24 +177,24 @@ import { Children } from "react";
177
177
 
178
178
  // src/components/condition/Then.ts
179
179
  function Then(props) {
180
- const { children, cond, else: _else, then, tag, ...attrs } = props;
181
- return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag, attrs, children);
180
+ const { children, cond, else: _else, then, tag, as: asChild, ...attrs } = props;
181
+ return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
182
182
  }
183
183
 
184
184
  // src/components/condition/If.ts
185
185
  function If(props) {
186
- const { then, cond, else: _else, children = props.then, tag, ...attrs } = props;
186
+ const { then, cond, else: _else, children = props.then, tag, as: asChild, ...attrs } = props;
187
187
  const elements = Children.toArray(children);
188
188
  const thenChild = elements.find((c) => c.type === Then);
189
189
  const elseChild = elements.find((c) => c.type === Else);
190
190
  const child = thenChild || elseChild ? cond ? thenChild : elseChild : cond ? children : _else;
191
- return wrapper(tag, attrs, child);
191
+ return wrapper(tag || asChild, attrs, child);
192
192
  }
193
193
 
194
194
  // src/components/condition/Else.ts
195
195
  function Else(props) {
196
- const { children, tag, ...attrs } = props;
197
- return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag, attrs, children);
196
+ const { children, tag, as: asChild, ...attrs } = props;
197
+ return Object.keys(props).includes("cond") ? wrapper(If, props, children) : wrapper(tag || asChild, attrs, children);
198
198
  }
199
199
 
200
200
  // src/components/condition/Switch.ts
@@ -222,12 +222,12 @@ function Switch(props) {
222
222
  // src/components/condition/Unless.ts
223
223
  import { Children as Children3 } from "react";
224
224
  function Unless(props) {
225
- const { cond, then, else: _else, tag, children = props.then, ...attrs } = props;
225
+ const { cond, then, else: _else, tag, as: asChild, children = props.then, ...attrs } = props;
226
226
  const elements = Children3.toArray(children);
227
227
  const thenChild = elements.find((c) => c.type === Then);
228
228
  const elseChild = elements.find((c) => c.type === Else);
229
229
  const child = thenChild || elseChild ? !cond ? elseChild : thenChild : !cond ? children : _else;
230
- return wrapper(tag, attrs, child);
230
+ return wrapper(tag || asChild, attrs, child);
231
231
  }
232
232
 
233
233
  // src/components/utils/Injector.ts
@@ -568,7 +568,7 @@ function proxyWithPersistant(keyOrOptions, initialObject) {
568
568
  }
569
569
  const storage = options.storage || (typeof localStorage !== "undefined" ? localStorage : void 0);
570
570
  typeof keyOrOptions === "string" && (keyOrOptions = { id: keyOrOptions });
571
- const state = proxy(jsonTryParse(storage?.getItem(options.id)) || initialObject);
571
+ const state = proxy(tryParseJson(storage?.getItem(options.id)) || initialObject);
572
572
  subscribe(state, () => {
573
573
  const pick = options.pick || Object.keys(state);
574
574
  const statePick = {};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hairy/react-lib",
3
3
  "type": "module",
4
- "version": "1.44.0",
4
+ "version": "1.46.0",
5
5
  "description": "Library for react",
6
6
  "author": "Hairyf <wwu710632@gmail.com>",
7
7
  "license": "MIT",
@@ -38,7 +38,7 @@
38
38
  "react-dom": "^19.1.0",
39
39
  "react-i18next": "^14.1.2",
40
40
  "react-use": "^17.6.0",
41
- "@hairy/utils": "1.44.0"
41
+ "@hairy/utils": "1.46.0"
42
42
  },
43
43
  "scripts": {
44
44
  "build": "tsup",