@jiovan-labs/react-condition 0.0.0-stage → 2.0.1

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.
Files changed (42) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +303 -2
  3. package/README.zh-CN.md +304 -0
  4. package/README.zh-TW.md +304 -0
  5. package/dist/cjs/index.d.ts +8 -0
  6. package/dist/cjs/index.js +50 -0
  7. package/dist/cjs/util/Do.d.ts +6 -0
  8. package/dist/cjs/util/Do.js +44 -0
  9. package/dist/cjs/util/For.d.ts +6 -0
  10. package/dist/cjs/util/For.js +39 -0
  11. package/dist/cjs/util/If.d.ts +10 -0
  12. package/dist/cjs/util/If.js +69 -0
  13. package/dist/cjs/util/MapIterator.d.ts +6 -0
  14. package/dist/cjs/util/MapIterator.js +39 -0
  15. package/dist/cjs/util/ObjectIterator.d.ts +6 -0
  16. package/dist/cjs/util/ObjectIterator.js +42 -0
  17. package/dist/cjs/util/SetIterator.d.ts +6 -0
  18. package/dist/cjs/util/SetIterator.js +39 -0
  19. package/dist/cjs/util/Switch.d.ts +12 -0
  20. package/dist/cjs/util/Switch.js +80 -0
  21. package/dist/cjs/util/While.d.ts +6 -0
  22. package/dist/cjs/util/While.js +44 -0
  23. package/dist/esm/index.d.ts +8 -0
  24. package/dist/esm/index.js +8 -0
  25. package/dist/esm/util/Do.d.ts +6 -0
  26. package/dist/esm/util/Do.js +18 -0
  27. package/dist/esm/util/For.d.ts +6 -0
  28. package/dist/esm/util/For.js +15 -0
  29. package/dist/esm/util/If.d.ts +10 -0
  30. package/dist/esm/util/If.js +32 -0
  31. package/dist/esm/util/MapIterator.d.ts +6 -0
  32. package/dist/esm/util/MapIterator.js +15 -0
  33. package/dist/esm/util/ObjectIterator.d.ts +6 -0
  34. package/dist/esm/util/ObjectIterator.js +18 -0
  35. package/dist/esm/util/SetIterator.d.ts +6 -0
  36. package/dist/esm/util/SetIterator.js +15 -0
  37. package/dist/esm/util/Switch.d.ts +12 -0
  38. package/dist/esm/util/Switch.js +47 -0
  39. package/dist/esm/util/While.d.ts +6 -0
  40. package/dist/esm/util/While.js +18 -0
  41. package/dist/umd/react-condition.min.js +1 -0
  42. package/package.json +122 -5
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ export type SwitchProps = React.PropsWithChildren<{
3
+ validation?: boolean;
4
+ }>;
5
+ export type SwitchCaseProps = React.PropsWithChildren<{
6
+ condition: boolean | number | string | null | undefined;
7
+ render?: () => React.ReactNode;
8
+ }>;
9
+ export type SwitchDefaultProps = React.PropsWithChildren<{
10
+ render?: () => React.ReactNode;
11
+ }>;
12
+ export declare const Switch: any;
@@ -0,0 +1,80 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
+ // If the importer is in node compatibility mode or this is not an ESM
21
+ // file that has been converted to a CommonJS file using a Babel-
22
+ // compatible transform (i.e. "__esModule" has not been set), then set
23
+ // "default" to the CommonJS "module.exports" for node compatibility.
24
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
+ mod
26
+ ));
27
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
+
29
+ // src/util/Switch.tsx
30
+ var Switch_exports = {};
31
+ __export(Switch_exports, {
32
+ Switch: () => Switch
33
+ });
34
+ module.exports = __toCommonJS(Switch_exports);
35
+ var import_react = __toESM(require("react"));
36
+ var Switch = (props) => {
37
+ if (!(props == null ? void 0 : props.children)) {
38
+ return void 0;
39
+ }
40
+ if ((props == null ? void 0 : props.validation) !== false) {
41
+ let caseCount = 0, defaultCount = 0;
42
+ import_react.default.Children.forEach(props.children, (item) => {
43
+ const childType = item == null ? void 0 : item.type;
44
+ if (childType === Switch.Case) {
45
+ caseCount++;
46
+ }
47
+ if (childType === Switch.Default) {
48
+ defaultCount++;
49
+ }
50
+ });
51
+ if (caseCount === 0 && defaultCount === 0) {
52
+ throw SyntaxError(`[Switch] must has any statements of 'Switch.Case/Switch.Default' at least!`);
53
+ }
54
+ if (defaultCount > 1) {
55
+ throw SyntaxError(`Statement of 'Switch.Default' for [Switch] must be a single one at most!`);
56
+ }
57
+ }
58
+ let caseValue = void 0, defaultValue = void 0;
59
+ import_react.default.Children.forEach(props.children, (item) => {
60
+ var _a, _b, _c;
61
+ const childType = item == null ? void 0 : item.type;
62
+ if (childType === Switch.Case && ((_a = item.props) == null ? void 0 : _a.condition)) {
63
+ caseValue = (_b = item.props) == null ? void 0 : _b.children;
64
+ }
65
+ if (childType === Switch.Default) {
66
+ defaultValue = (_c = item.props) == null ? void 0 : _c.children;
67
+ }
68
+ });
69
+ return caseValue ?? defaultValue;
70
+ };
71
+ Switch.Case = (props) => {
72
+ return !props.condition ? void 0 : (props == null ? void 0 : props.render) ? props.render() : props.children;
73
+ };
74
+ Switch.Default = (props) => {
75
+ return (props == null ? void 0 : props.render) ? props.render() : props == null ? void 0 : props.children;
76
+ };
77
+ // Annotate the CommonJS export names for ESM import in node:
78
+ 0 && (module.exports = {
79
+ Switch
80
+ });
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export type WhileProps = React.PropsWithChildren<{
3
+ condition: () => boolean | number | string | undefined | null;
4
+ render?: (index: number) => React.ReactNode;
5
+ }>;
6
+ export declare const While: any;
@@ -0,0 +1,44 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/util/While.tsx
20
+ var While_exports = {};
21
+ __export(While_exports, {
22
+ While: () => While
23
+ });
24
+ module.exports = __toCommonJS(While_exports);
25
+ var import_jsx_runtime = require("react/jsx-runtime");
26
+ var While = (props) => {
27
+ const result = [];
28
+ let index = 0;
29
+ while (props.condition()) {
30
+ if (props.render) {
31
+ result.push(props == null ? void 0 : props.render(index));
32
+ } else if (!props.render && props.children) {
33
+ result.push(
34
+ /* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "condition-while", children: props.children }, index)
35
+ );
36
+ }
37
+ index++;
38
+ }
39
+ return result;
40
+ };
41
+ // Annotate the CommonJS export names for ESM import in node:
42
+ 0 && (module.exports = {
43
+ While
44
+ });
@@ -0,0 +1,8 @@
1
+ export { Do, type DoProps } from './util/Do';
2
+ export { For, type ForProps } from './util/For';
3
+ export { If, type IfProps, type IfThenProps, type IfElseProps } from './util/If';
4
+ export { MapIterator, type MapIteratorProps } from './util/MapIterator';
5
+ export { ObjectIterator, type ObjectIteratorProps } from './util/ObjectIterator';
6
+ export { SetIterator, type SetIteratorProps } from './util/SetIterator';
7
+ export { Switch, type SwitchCaseProps, type SwitchDefaultProps } from './util/Switch';
8
+ export { While, type WhileProps } from './util/While';
@@ -0,0 +1,8 @@
1
+ export { Do } from "./util/Do";
2
+ export { For } from "./util/For";
3
+ export { If } from "./util/If";
4
+ export { MapIterator } from "./util/MapIterator";
5
+ export { ObjectIterator } from "./util/ObjectIterator";
6
+ export { SetIterator } from "./util/SetIterator";
7
+ export { Switch } from "./util/Switch";
8
+ export { While } from "./util/While";
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export type DoProps = React.PropsWithChildren<{
3
+ condition: () => boolean | number | string | undefined | null;
4
+ render?: (index: number) => React.ReactNode;
5
+ }>;
6
+ export declare const Do: any;
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var Do = function Do(props) {
4
+ var result = [];
5
+ var index = 0;
6
+ do {
7
+ if (props.render) {
8
+ result.push(props === null || props === void 0 ? void 0 : props.render(index));
9
+ } else if (!props.render && props.children) {
10
+ result.push( /*#__PURE__*/_jsx("div", {
11
+ className: "condition-do",
12
+ children: props.children
13
+ }, index));
14
+ }
15
+ index++;
16
+ } while (props.condition());
17
+ return result;
18
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export type ForProps = React.PropsWithChildren<{
3
+ of: any[];
4
+ render?: (item: any, index: number) => React.ReactNode;
5
+ }>;
6
+ export declare const For: any;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var For = function For(props) {
4
+ return props.of.map(function (item, index) {
5
+ if (props.render) {
6
+ return props.render(item, index);
7
+ } else if (!props.render && props.children) {
8
+ return /*#__PURE__*/_jsx("div", {
9
+ className: "condition-for",
10
+ children: props.children
11
+ }, index);
12
+ }
13
+ return undefined;
14
+ });
15
+ };
@@ -0,0 +1,10 @@
1
+ import React from 'react';
2
+ export type IfProps = React.PropsWithChildren<{
3
+ condition: boolean | number | string | undefined | null;
4
+ validation?: boolean;
5
+ }>;
6
+ export type IfThenProps = IfProps & {
7
+ render?: () => React.ReactNode;
8
+ };
9
+ export type IfElseProps = IfThenProps;
10
+ export declare const If: any;
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ export var If = function If(props) {
3
+ if (!props.children) {
4
+ return undefined;
5
+ }
6
+ if (props.validation !== false) {
7
+ var thenCount = 0,
8
+ elseCount = 0;
9
+ React.Children.forEach(props.children, function (item) {
10
+ var childType = item === null || item === void 0 ? void 0 : item.type;
11
+ if (childType === If.Then) {
12
+ thenCount++;
13
+ }
14
+ if (childType === If.Else) {
15
+ elseCount++;
16
+ }
17
+ });
18
+ if (thenCount > 1 || elseCount > 1) {
19
+ throw SyntaxError("Each statement of 'If.Then/If.Else' for [If condition='".concat(props.condition, "'] must be a single one!"));
20
+ }
21
+ }
22
+ return React.Children.map(props.children, function (item) {
23
+ var isElse = (item === null || item === void 0 ? void 0 : item.type) === If.Else;
24
+ return props.condition && !isElse || !props.condition && isElse ? item : undefined;
25
+ });
26
+ };
27
+ If.Then = function (props) {
28
+ return props !== null && props !== void 0 && props.render ? props.render() : props === null || props === void 0 ? void 0 : props.children;
29
+ };
30
+ If.Else = function (props) {
31
+ return props !== null && props !== void 0 && props.render ? props.render() : props === null || props === void 0 ? void 0 : props.children;
32
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export type MapIteratorProps = React.PropsWithChildren<{
3
+ of: Map<any, any> | ReadonlyMap<any, any>;
4
+ render?: (value: any, key: any, index: number) => React.ReactNode;
5
+ }>;
6
+ export declare const MapIterator: any;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var MapIterator = function MapIterator(props) {
4
+ return Array.from(props.of).map(function (item, index) {
5
+ if (props.render) {
6
+ return (item === null || item === void 0 ? void 0 : item.length) > 1 ? props.render(item[1], item[0], index) : undefined;
7
+ } else if (!props.render && props.children) {
8
+ return /*#__PURE__*/_jsx("div", {
9
+ className: "condition-map-iterator",
10
+ children: props.children
11
+ }, index);
12
+ }
13
+ return undefined;
14
+ });
15
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export type ObjectIteratorProps<T extends object> = React.PropsWithChildren<{
3
+ of: T;
4
+ render?: (value: any, key: string, index: number) => React.ReactNode;
5
+ }>;
6
+ export declare const ObjectIterator: any;
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var ObjectIterator = function ObjectIterator(props) {
4
+ if (!props.of) {
5
+ return undefined;
6
+ }
7
+ return Object.keys(props.of).map(function (item, index) {
8
+ if (props.render) {
9
+ return props.render(props.of[item], item, index);
10
+ } else if (!props.render && props.children) {
11
+ return /*#__PURE__*/_jsx("div", {
12
+ className: "condition-object-iterator",
13
+ children: props.children
14
+ }, index);
15
+ }
16
+ return undefined;
17
+ });
18
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export type SetIteratorProps = React.PropsWithChildren<{
3
+ of: Set<any>;
4
+ render?: (item: any, index: number) => React.ReactNode;
5
+ }>;
6
+ export declare const SetIterator: any;
@@ -0,0 +1,15 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var SetIterator = function SetIterator(props) {
4
+ return Array.from(props.of).map(function (item, index) {
5
+ if (props.render) {
6
+ return props.render(item, index);
7
+ } else if (!props.render && props.children) {
8
+ return /*#__PURE__*/_jsx("div", {
9
+ className: "condition-set-iterator",
10
+ children: props.children
11
+ }, index);
12
+ }
13
+ return undefined;
14
+ });
15
+ };
@@ -0,0 +1,12 @@
1
+ import React from 'react';
2
+ export type SwitchProps = React.PropsWithChildren<{
3
+ validation?: boolean;
4
+ }>;
5
+ export type SwitchCaseProps = React.PropsWithChildren<{
6
+ condition: boolean | number | string | null | undefined;
7
+ render?: () => React.ReactNode;
8
+ }>;
9
+ export type SwitchDefaultProps = React.PropsWithChildren<{
10
+ render?: () => React.ReactNode;
11
+ }>;
12
+ export declare const Switch: any;
@@ -0,0 +1,47 @@
1
+ import React from 'react';
2
+ export var Switch = function Switch(props) {
3
+ var _caseValue;
4
+ if (!(props !== null && props !== void 0 && props.children)) {
5
+ return undefined;
6
+ }
7
+ if ((props === null || props === void 0 ? void 0 : props.validation) !== false) {
8
+ var caseCount = 0,
9
+ defaultCount = 0;
10
+ React.Children.forEach(props.children, function (item) {
11
+ var childType = item === null || item === void 0 ? void 0 : item.type;
12
+ if (childType === Switch.Case) {
13
+ caseCount++;
14
+ }
15
+ if (childType === Switch.Default) {
16
+ defaultCount++;
17
+ }
18
+ });
19
+ if (caseCount === 0 && defaultCount === 0) {
20
+ throw SyntaxError("[Switch] must has any statements of 'Switch.Case/Switch.Default' at least!");
21
+ }
22
+ if (defaultCount > 1) {
23
+ throw SyntaxError("Statement of 'Switch.Default' for [Switch] must be a single one at most!");
24
+ }
25
+ }
26
+ var caseValue = undefined,
27
+ defaultValue = undefined;
28
+ React.Children.forEach(props.children, function (item) {
29
+ var _item$props;
30
+ var childType = item === null || item === void 0 ? void 0 : item.type;
31
+ if (childType === Switch.Case && (_item$props = item.props) !== null && _item$props !== void 0 && _item$props.condition) {
32
+ var _item$props2;
33
+ caseValue = (_item$props2 = item.props) === null || _item$props2 === void 0 ? void 0 : _item$props2.children;
34
+ }
35
+ if (childType === Switch.Default) {
36
+ var _item$props3;
37
+ defaultValue = (_item$props3 = item.props) === null || _item$props3 === void 0 ? void 0 : _item$props3.children;
38
+ }
39
+ });
40
+ return (_caseValue = caseValue) !== null && _caseValue !== void 0 ? _caseValue : defaultValue;
41
+ };
42
+ Switch.Case = function (props) {
43
+ return !props.condition ? undefined : props !== null && props !== void 0 && props.render ? props.render() : props.children;
44
+ };
45
+ Switch.Default = function (props) {
46
+ return props !== null && props !== void 0 && props.render ? props.render() : props === null || props === void 0 ? void 0 : props.children;
47
+ };
@@ -0,0 +1,6 @@
1
+ import React from 'react';
2
+ export type WhileProps = React.PropsWithChildren<{
3
+ condition: () => boolean | number | string | undefined | null;
4
+ render?: (index: number) => React.ReactNode;
5
+ }>;
6
+ export declare const While: any;
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var While = function While(props) {
4
+ var result = [];
5
+ var index = 0;
6
+ while (props.condition()) {
7
+ if (props.render) {
8
+ result.push(props === null || props === void 0 ? void 0 : props.render(index));
9
+ } else if (!props.render && props.children) {
10
+ result.push( /*#__PURE__*/_jsx("div", {
11
+ className: "condition-while",
12
+ children: props.children
13
+ }, index));
14
+ }
15
+ index++;
16
+ }
17
+ return result;
18
+ };
@@ -0,0 +1 @@
1
+ !function(e,t){"object"==typeof exports&&"object"==typeof module?module.exports=t():"function"==typeof define&&define.amd?define([],t):"object"==typeof exports?exports.ReactCondition=t():e.ReactCondition=t()}(self,(function(){return function(){var e={822:function(e){var t,n,r=e.exports={};function o(){throw new Error("setTimeout has not been defined")}function i(){throw new Error("clearTimeout has not been defined")}function u(e){if(t===setTimeout)return setTimeout(e,0);if((t===o||!t)&&setTimeout)return t=setTimeout,setTimeout(e,0);try{return t(e,0)}catch(n){try{return t.call(null,e,0)}catch(n){return t.call(this,e,0)}}}!function(){try{t="function"==typeof setTimeout?setTimeout:o}catch(e){t=o}try{n="function"==typeof clearTimeout?clearTimeout:i}catch(e){n=i}}();var c,l=[],a=!1,f=-1;function s(){a&&c&&(a=!1,c.length?l=c.concat(l):f=-1,l.length&&d())}function d(){if(!a){var e=u(s);a=!0;for(var t=l.length;t;){for(c=l,l=[];++f<t;)c&&c[f].run();f=-1,t=l.length}c=null,a=!1,function(e){if(n===clearTimeout)return clearTimeout(e);if((n===i||!n)&&clearTimeout)return n=clearTimeout,clearTimeout(e);try{n(e)}catch(t){try{return n.call(null,e)}catch(t){return n.call(this,e)}}}(e)}}function p(e,t){this.fun=e,this.array=t}function h(){}r.nextTick=function(e){var t=new Array(arguments.length-1);if(arguments.length>1)for(var n=1;n<arguments.length;n++)t[n-1]=arguments[n];l.push(new p(e,t)),1!==l.length||a||u(d)},p.prototype.run=function(){this.fun.apply(null,this.array)},r.title="browser",r.browser=!0,r.env={},r.argv=[],r.version="",r.versions={},r.on=h,r.addListener=h,r.once=h,r.off=h,r.removeListener=h,r.removeAllListeners=h,r.emit=h,r.prependListener=h,r.prependOnceListener=h,r.listeners=function(e){return[]},r.binding=function(e){throw new Error("process.binding is not supported")},r.cwd=function(){return"/"},r.chdir=function(e){throw new Error("process.chdir is not supported")},r.umask=function(){return 0}},362:function(e,t){"use strict";var n=Symbol.for("react.transitional.element");function r(e,t,r){var o=null;if(void 0!==r&&(o=""+r),void 0!==t.key&&(o=""+t.key),"key"in t)for(var i in r={},t)"key"!==i&&(r[i]=t[i]);else r=t;return t=r.ref,{$$typeof:n,type:e,key:o,ref:void 0!==t?t:null,props:r}}Symbol.for("react.fragment"),t.jsx=r},997:function(e,t,n){"use strict";var r=n(822),o=n(65).default,i=Symbol.for("react.transitional.element"),u=Symbol.for("react.portal"),c=Symbol.for("react.fragment"),l=Symbol.for("react.strict_mode"),a=Symbol.for("react.profiler"),f=Symbol.for("react.consumer"),s=Symbol.for("react.context"),d=Symbol.for("react.forward_ref"),p=Symbol.for("react.suspense"),h=Symbol.for("react.memo"),y=Symbol.for("react.lazy"),v=Symbol.for("react.activity"),m=Symbol.for("react.view_transition"),b=Symbol.iterator;var w={isMounted:function(){return!1},enqueueForceUpdate:function(){},enqueueReplaceState:function(){},enqueueSetState:function(){}},S=Object.assign,g={};function j(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||w}function x(){}function E(e,t,n){this.props=e,this.context=t,this.refs=g,this.updater=n||w}j.prototype.isReactComponent={},j.prototype.setState=function(e,t){if("object"!==o(e)&&"function"!=typeof e&&null!=e)throw Error("takes an object of state variables to update or a function which returns an object of state variables.");this.updater.enqueueSetState(this,e,t,"setState")},j.prototype.forceUpdate=function(e){this.updater.enqueueForceUpdate(this,e,"forceUpdate")},x.prototype=j.prototype;var _=E.prototype=new x;_.constructor=E,S(_,j.prototype),_.isPureReactComponent=!0;var T=Array.isArray;function k(){}var C={H:null,A:null,T:null,S:null},O=Object.prototype.hasOwnProperty;function $(e,t,n){var r=n.ref;return{$$typeof:i,type:e,key:t,ref:void 0!==r?r:null,props:n}}function A(e){return"object"===o(e)&&null!==e&&e.$$typeof===i}var I=/\/+/g;function R(e,t){return"object"===o(e)&&null!==e&&null!=e.key?(n=""+e.key,r={"=":"=0",":":"=2"},"$"+n.replace(/[=:]/g,(function(e){return r[e]}))):t.toString(36);var n,r}function D(e,t,n,r,c){var l=o(e);"undefined"!==l&&"boolean"!==l||(e=null);var a,f,s=!1;if(null===e)s=!0;else switch(l){case"bigint":case"string":case"number":s=!0;break;case"object":switch(e.$$typeof){case i:case u:s=!0;break;case y:return D((s=e._init)(e._payload),t,n,r,c)}}if(s)return c=c(e),s=""===r?"."+R(e,0):r,T(c)?(n="",null!=s&&(n=s.replace(I,"$&/")+"/"),D(c,t,n,"",(function(e){return e}))):null!=c&&(A(c)&&(a=c,f=n+(null==c.key||e&&e.key===c.key?"":(""+c.key).replace(I,"$&/")+"/")+s,c=$(a.type,f,a.props)),t.push(c)),1;s=0;var d,p=""===r?".":r+":";if(T(e))for(var h=0;h<e.length;h++)s+=D(r=e[h],t,n,l=p+R(r,h),c);else if("function"==typeof(h=null===(d=e)||"object"!==o(d)?null:"function"==typeof(d=b&&d[b]||d["@@iterator"])?d:null))for(e=h.call(e),h=0;!(r=e.next()).done;)s+=D(r=r.value,t,n,l=p+R(r,h++),c);else if("object"===l){if("function"==typeof e.then)return D(function(e){switch(e.status){case"fulfilled":return e.value;case"rejected":throw e.reason;default:switch("string"==typeof e.status?e.then(k,k):(e.status="pending",e.then((function(t){"pending"===e.status&&(e.status="fulfilled",e.value=t)}),(function(t){"pending"===e.status&&(e.status="rejected",e.reason=t)}))),e.status){case"fulfilled":return e.value;case"rejected":throw e.reason}}throw e}(e),t,n,r,c);throw t=String(e),Error("Objects are not valid as a React child (found: "+("[object Object]"===t?"object with keys {"+Object.keys(e).join(", ")+"}":t)+"). If you meant to render a collection of children, use an array instead.")}return s}function M(e,t,n){if(null==e)return e;var r=[],o=0;return D(e,r,"","",(function(e){return t.call(n,e,o++)})),r}function N(e){if(-1===e._status){var t=(0,e._result)();t.then((function(n){0!==e._status&&-1!==e._status||(e._status=1,e._result=n,void 0===t.status&&(t.status="fulfilled",t.value=n))}),(function(n){0!==e._status&&-1!==e._status||(e._status=2,e._result=n,void 0===t.status&&(t.status="rejected",t.reason=n))})),-1===e._status&&(e._status=0,e._result=t)}if(1===e._status)return e._result.default;throw e._result}var P="function"==typeof reportError?reportError:function(e){if("object"===("undefined"==typeof window?"undefined":o(window))&&"function"==typeof window.ErrorEvent){var t=new window.ErrorEvent("error",{bubbles:!0,cancelable:!0,message:"object"===o(e)&&null!==e&&"string"==typeof e.message?String(e.message):String(e),error:e});if(!window.dispatchEvent(t))return}else if("object"===(void 0===r?"undefined":o(r))&&"function"==typeof r.emit)return void r.emit("uncaughtException",e);console.error(e)};function q(e){var t=C.T,n={};n.types=null!==t?t.types:null,C.T=n;try{var r=e(),i=C.S;null!==i&&i(n,r),"object"===o(r)&&null!==r&&"function"==typeof r.then&&r.then(k,P)}catch(e){P(e)}finally{null!==t&&null!==n.types&&(t.types=n.types),C.T=t}}var L={map:M,forEach:function(e,t,n){M(e,(function(){t.apply(this,arguments)}),n)},count:function(e){var t=0;return M(e,(function(){t++})),t},toArray:function(e){return M(e,(function(e){return e}))||[]},only:function(e){if(!A(e))throw Error("React.Children.only expected to receive a single React element child.");return e}};t.Children=L},636:function(e,t,n){"use strict";e.exports=n(997)},472:function(e,t,n){"use strict";e.exports=n(362)},65:function(e){function t(n){return e.exports=t="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},e.exports.__esModule=!0,e.exports.default=e.exports,t(n)}e.exports=t,e.exports.__esModule=!0,e.exports.default=e.exports}},t={};function n(r){var o=t[r];if(void 0!==o)return o.exports;var i=t[r]={exports:{}};return e[r](i,i.exports,n),i.exports}n.d=function(e,t){for(var r in t)n.o(t,r)&&!n.o(e,r)&&Object.defineProperty(e,r,{enumerable:!0,get:t[r]})},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var r={};return function(){"use strict";n.r(r),n.d(r,{Do:function(){return o},For:function(){return i},If:function(){return u},MapIterator:function(){return c},ObjectIterator:function(){return l},SetIterator:function(){return a},Switch:function(){return f},While:function(){return s}});var e=n(636),t=n(472),o=function(e){var n=[],r=0;do{e.render?n.push(null==e?void 0:e.render(r)):!e.render&&e.children&&n.push((0,t.jsx)("div",{className:"condition-do",children:e.children},r)),r++}while(e.condition());return n},i=function(e){return e.of.map((function(n,r){return e.render?e.render(n,r):!e.render&&e.children?(0,t.jsx)("div",{className:"condition-for",children:e.children},r):void 0}))},u=function t(n){if(n.children){if(!1!==n.validation){var r=0,o=0;if(e.Children.forEach(n.children,(function(e){var n=null==e?void 0:e.type;n===t.Then&&r++,n===t.Else&&o++})),r>1||o>1)throw SyntaxError("Each statement of 'If.Then/If.Else' for [If condition='".concat(n.condition,"'] must be a single one!"))}return e.Children.map(n.children,(function(e){var r=(null==e?void 0:e.type)===t.Else;return n.condition&&!r||!n.condition&&r?e:void 0}))}};u.Then=function(e){return null!=e&&e.render?e.render():null==e?void 0:e.children},u.Else=function(e){return null!=e&&e.render?e.render():null==e?void 0:e.children};var c=function(e){return Array.from(e.of).map((function(n,r){return e.render?(null==n?void 0:n.length)>1?e.render(n[1],n[0],r):void 0:!e.render&&e.children?(0,t.jsx)("div",{className:"condition-map-iterator",children:e.children},r):void 0}))},l=function(e){if(e.of)return Object.keys(e.of).map((function(n,r){return e.render?e.render(e.of[n],n,r):!e.render&&e.children?(0,t.jsx)("div",{className:"condition-object-iterator",children:e.children},r):void 0}))},a=function(e){return Array.from(e.of).map((function(n,r){return e.render?e.render(n,r):!e.render&&e.children?(0,t.jsx)("div",{className:"condition-set-iterator",children:e.children},r):void 0}))},f=function t(n){var r;if(null!=n&&n.children){if(!1!==(null==n?void 0:n.validation)){var o=0,i=0;if(e.Children.forEach(n.children,(function(e){var n=null==e?void 0:e.type;n===t.Case&&o++,n===t.Default&&i++})),0===o&&0===i)throw SyntaxError("[Switch] must has any statements of 'Switch.Case/Switch.Default' at least!");if(i>1)throw SyntaxError("Statement of 'Switch.Default' for [Switch] must be a single one at most!")}var u=void 0,c=void 0;return e.Children.forEach(n.children,(function(e){var n,r,o,i=null==e?void 0:e.type;i===t.Case&&null!==(n=e.props)&&void 0!==n&&n.condition&&(u=null===(r=e.props)||void 0===r?void 0:r.children);i===t.Default&&(c=null===(o=e.props)||void 0===o?void 0:o.children)})),null!==(r=u)&&void 0!==r?r:c}};f.Case=function(e){return e.condition?null!=e&&e.render?e.render():e.children:void 0},f.Default=function(e){return null!=e&&e.render?e.render():null==e?void 0:e.children};var s=function(e){for(var n=[],r=0;e.condition();)e.render?n.push(null==e?void 0:e.render(r)):!e.render&&e.children&&n.push((0,t.jsx)("div",{className:"condition-while",children:e.children},r)),r++;return n}}(),r}()}));
package/package.json CHANGED
@@ -1,6 +1,123 @@
1
1
  {
2
- "name": "@jiovan-labs/react-condition",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
2
+ "name": "@jiovan-labs/react-condition",
3
+ "version": "2.0.1",
4
+ "title": "React Condition",
5
+ "description": "Render components conditionally for react",
6
+ "homepage": "https://jiovan-labs.github.io/react-condition",
7
+ "organization": "Jiovan Ltd",
8
+ "private": false,
9
+ "license": "MIT",
10
+ "keywords": [
11
+ "react-condition",
12
+ "if",
13
+ "if-then",
14
+ "if-else",
15
+ "if-then-else",
16
+ "for",
17
+ "switch",
18
+ "while",
19
+ "do-while",
20
+ "while-do",
21
+ "map-iterator",
22
+ "set-iterator",
23
+ "object-iterator",
24
+ "condition",
25
+ "condition-render",
26
+ "control-statement"
27
+ ],
28
+ "files": [
29
+ "dist"
30
+ ],
31
+ "main": "dist/cjs/index.js",
32
+ "module": "dist/esm/index.js",
33
+ "unpkg": "dist/umd/react-condition.min.js",
34
+ "types": "dist/esm/index.d.ts",
35
+ "sideEffects": false,
36
+ "scripts": {
37
+ "approve": "npm approve-scripts --allow-scripts-pending",
38
+ "build": "del-cli ./dist && father build",
39
+ "build:doctor": "father doctor",
40
+ "build:watch": "father dev",
41
+ "docs:build": "typedoc --out ./docs-dist",
42
+ "docs:publish": "gh-pages -d ./docs-dist",
43
+ "lint": "eslint \"{src,test}/**/*.{js,jsx,ts,tsx}\"",
44
+ "test": "jest",
45
+ "test:coverage": "del-cli ./coverage && jest --coverage --coverageDirectory ./coverage",
46
+ "upgrade": "npx npm-check-updates --target semver -u"
47
+ },
48
+ "dependencies": {
49
+ "@babel/runtime": "^7.29.10"
50
+ },
51
+ "devDependencies": {
52
+ "@eslint/js": "^10.0.1",
53
+ "@testing-library/jest-dom": "^6.10.0",
54
+ "@testing-library/react": "^16.3.3",
55
+ "@types/jest": "^30.0.0",
56
+ "@types/react": "^19.3.0",
57
+ "@types/react-dom": "^19.3.0",
58
+ "@jiovan-labs/babel-plugin-remove-comment": "^2.0.0",
59
+ "@jiovan-labs/typedoc-plugin-raw-content": "^2.0.0",
60
+ "@jiovan-labs/typedoc-theme-dumi": "^2.0.0",
61
+ "del-cli": "^7.0.0",
62
+ "eslint": "^10.14.0",
63
+ "eslint-plugin-jest": "^29.17.0",
64
+ "father": "^4.6.41",
65
+ "gh-pages": "^6.3.0",
66
+ "globals": "^17.14.0",
67
+ "jest-environment-jsdom": "^30.5.2",
68
+ "react": "^19.3.1",
69
+ "react-dom": "^19.3.1",
70
+ "ts-jest": "^29.4.15",
71
+ "typedoc": "~0.28.20",
72
+ "typescript": "^6.0.3",
73
+ "typescript-eslint": "^8.72.1"
74
+ },
75
+ "peerDependencies": {
76
+ "react": ">=17.0.0",
77
+ "react-dom": ">=17.0.0",
78
+ "typescript": ">=4.0.0"
79
+ },
80
+ "repository": {
81
+ "type": "git",
82
+ "url": "git+https://github.com/joivan-labs/react-condition.git"
83
+ },
84
+ "bugs": {
85
+ "url": "https://github.com/joivan-labs/react-condition/issues"
86
+ },
87
+ "publishConfig": {
88
+ "access": "public",
89
+ "registry": "https://registry.npmjs.org"
90
+ },
91
+ "collective": {
92
+ "url": "https://opencollective.com/joivan-labs"
93
+ },
94
+ "funding": [
95
+ {
96
+ "type": "opencollective",
97
+ "url": "https://opencollective.com/joivan-labs"
98
+ },
99
+ {
100
+ "type": "individual",
101
+ "url": "https://joivan.com/donation"
102
+ }
103
+ ],
104
+ "author": {
105
+ "name": "Jiovan Ltd",
106
+ "url": "https://joivan.com"
107
+ },
108
+ "contributors": [
109
+ {
110
+ "name": "David Hsing",
111
+ "email": "davidhsing@163.com",
112
+ "url": "https://github.com/davidhsing"
113
+ }
114
+ ],
115
+ "allowScripts": {
116
+ "@parcel/watcher": true,
117
+ "core-js": true,
118
+ "core-js-pure": true,
119
+ "esbuild": true,
120
+ "fsevents": true,
121
+ "unrs-resolver": true
122
+ }
123
+ }