wargerm 0.5.39 → 0.6.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.
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function demo1(): JSX.Element;
@@ -0,0 +1,2 @@
1
+ /// <reference types="react" />
2
+ export default function demo1(): JSX.Element;
@@ -0,0 +1,14 @@
1
+ declare let run: (fn: () => void) => void;
2
+ declare type State = Record<string, any>;
3
+ declare type GetSetStore<T> = {
4
+ (): T;
5
+ (s: Partial<T> | ((state: T) => Partial<T>)): void;
6
+ };
7
+ declare type InitStore<T> = (getSetStore: GetSetStore<T>) => T;
8
+ declare const create: {
9
+ <T extends State>(initStore: InitStore<T>): () => T;
10
+ config({ batch }: {
11
+ batch: typeof run;
12
+ }): void;
13
+ };
14
+ export default create;
@@ -0,0 +1,10 @@
1
+ declare type Callback = () => void;
2
+ declare type State = Record<string, unknown>;
3
+ declare let run: (fn: Callback) => void;
4
+ declare const wmox: {
5
+ <T extends State>(state: T): T;
6
+ config({ batch }: {
7
+ batch: typeof run;
8
+ }): void;
9
+ };
10
+ export default wmox;
package/dist/index.d.ts CHANGED
@@ -3,6 +3,8 @@ import './styles/index-dark.less';
3
3
  import './styles/index-light.less';
4
4
  import './styles/index-nt.less';
5
5
  export { default as useEventEmitter } from '@/hooks/useEventEmitter';
6
+ export { default as whox } from '@/hooks/whox';
7
+ export { default as wmox } from '@/hooks/wmox';
6
8
  export { default as Button } from './components/Button';
7
9
  export { default as IconFont } from './components/IconFont';
8
10
  export { default as Input } from './components/Input';
package/dist/index.esm.js CHANGED
@@ -1,5 +1,6 @@
1
- import React, { useRef, useEffect, useMemo, useState, useImperativeHandle, memo, forwardRef, createRef, useCallback } from 'react';
1
+ import React, { useRef, useEffect, useMemo, useState, useCallback, useImperativeHandle, memo, forwardRef, createRef } from 'react';
2
2
  import { cloneDeep, isEmpty } from 'lodash';
3
+ import { useSyncExternalStore } from 'use-sync-external-store/shim';
3
4
  import 'antd/es/button/style';
4
5
  import _Button from 'antd/es/button';
5
6
  import 'antd/es/dropdown/style';
@@ -542,6 +543,203 @@ function useEventEmitter(options) {
542
543
  return ref.current;
543
544
  }
544
545
 
546
+ var run = function run(fn) {
547
+ fn();
548
+ };
549
+
550
+ var __DEV__ = process.env.NODE_ENV !== 'production';
551
+
552
+ var create = function create(initStore) {
553
+ if (__DEV__ && typeof initStore !== 'function') {
554
+ throw new Error('Expected a function');
555
+ }
556
+
557
+ var store;
558
+ var listeners = new Set();
559
+
560
+ function getSetStore(s) {
561
+ if (typeof s === 'undefined') return store;
562
+ var partial = typeof s === 'function' ? s(store) : s;
563
+ store = _objectSpread2(_objectSpread2({}, store), partial);
564
+ run(function () {
565
+ return listeners.forEach(function (listener) {
566
+ return listener(partial);
567
+ });
568
+ });
569
+ }
570
+
571
+ store = initStore(getSetStore);
572
+ return function useStore() {
573
+ var proxy = useRef({});
574
+ var handler = useRef({});
575
+ var hasState = useRef(false);
576
+ var hasUpdate = useRef(false);
577
+
578
+ var _useState = useState(false),
579
+ _useState2 = _slicedToArray(_useState, 2),
580
+ setState = _useState2[1];
581
+
582
+ useMemo(function () {
583
+ handler.current = {
584
+ get: function get(target, key) {
585
+ var val = store[key];
586
+
587
+ if (typeof val !== 'function') {
588
+ hasState.current = true;
589
+ target[key] = val;
590
+ return target[key];
591
+ }
592
+
593
+ target[key] = new Proxy(val, {
594
+ get: function get(fn, fnKey) {
595
+ if (fnKey === 'loading' && !('loading' in fn)) {
596
+ fn.loading = false;
597
+ }
598
+
599
+ return fn[fnKey];
600
+ },
601
+ apply: function apply(fn, _this, args) {
602
+ var res = fn.apply(void 0, _toConsumableArray(args));
603
+
604
+ if (!('loading' in fn) || !res || typeof res.then !== 'function') {
605
+ target[key] = fn;
606
+ return res;
607
+ }
608
+
609
+ var setLoading = function setLoading(loading) {
610
+ target[key].loading = loading;
611
+ setState(function (s) {
612
+ return !s;
613
+ });
614
+ };
615
+
616
+ target[key] = function () {
617
+ var newRes = fn.apply(void 0, arguments);
618
+ setLoading(true);
619
+ return newRes.finally(function () {
620
+ return setLoading(false);
621
+ });
622
+ };
623
+
624
+ setLoading(true);
625
+ return res.finally(function () {
626
+ return setLoading(false);
627
+ });
628
+ }
629
+ });
630
+ return target[key];
631
+ },
632
+ set: function set(target, key, val) {
633
+ if (key in target && val !== target[key]) {
634
+ hasUpdate.current = true;
635
+ target[key] = val;
636
+ }
637
+
638
+ return true;
639
+ }
640
+ };
641
+ proxy.current = new Proxy({}, handler.current);
642
+ }, []);
643
+ useEffect(function () {
644
+ handler.current.get = function (target, key) {
645
+ return target[key];
646
+ };
647
+ }, []);
648
+ var subscribe = useCallback(function (update) {
649
+ if (!hasState.current) return function () {
650
+ return undefined;
651
+ };
652
+
653
+ var listener = function listener(partial) {
654
+ Object.assign(proxy.current, partial);
655
+
656
+ if (hasUpdate.current) {
657
+ hasUpdate.current = false;
658
+ update();
659
+ }
660
+ };
661
+
662
+ listeners.add(listener);
663
+ return function () {
664
+ return listeners.delete(listener);
665
+ };
666
+ }, []);
667
+ var getSnapshot = useCallback(function () {
668
+ return store;
669
+ }, []);
670
+ useSyncExternalStore(subscribe, getSnapshot);
671
+ return proxy.current;
672
+ };
673
+ };
674
+
675
+ create.config = function (_ref) {
676
+ var batch = _ref.batch;
677
+ run = batch;
678
+ };
679
+
680
+ var run$1 = function run(fn) {
681
+ fn();
682
+ };
683
+
684
+ var __DEV__$1 = process.env.NODE_ENV !== 'production';
685
+
686
+ var wmox = function wmox(state) {
687
+ if (__DEV__$1 && Object.prototype.toString.call(state) !== '[object Object]') {
688
+ throw new Error('object required');
689
+ }
690
+
691
+ var store = {};
692
+ Object.keys(state).forEach(function (key) {
693
+ if (typeof state[key] === 'function') {
694
+ return;
695
+ }
696
+
697
+ var listeners = new Set();
698
+ store[key] = {
699
+ subscribe: function subscribe(listener) {
700
+ listeners.add(listener);
701
+ return function () {
702
+ return listeners.delete(listener);
703
+ };
704
+ },
705
+ getSnapshot: function getSnapshot() {
706
+ return state[key];
707
+ },
708
+ setSnapshot: function setSnapshot(val) {
709
+ if (val !== state[key]) {
710
+ state[key] = val;
711
+ run$1(function () {
712
+ return listeners.forEach(function (listener) {
713
+ return listener();
714
+ });
715
+ });
716
+ }
717
+ },
718
+ useSnapshot: function useSnapshot() {
719
+ return useSyncExternalStore(store[key].subscribe, store[key].getSnapshot);
720
+ }
721
+ };
722
+ });
723
+ return new Proxy(state, {
724
+ get: function get(_, key) {
725
+ try {
726
+ return store[key].useSnapshot();
727
+ } catch (e) {
728
+ return state[key];
729
+ }
730
+ },
731
+ set: function set(_, key, val) {
732
+ store[key].setSnapshot(val);
733
+ return true;
734
+ }
735
+ });
736
+ };
737
+
738
+ wmox.config = function (_ref) {
739
+ var batch = _ref.batch;
740
+ run$1 = batch;
741
+ };
742
+
545
743
  var _excluded = ["multiple", "children", "disabled"];
546
744
 
547
745
  var WButton = function WButton(props) {
@@ -7614,4 +7812,4 @@ if (REACT_APP_ENV == 'development') {
7614
7812
  document.documentElement.setAttribute(COLOR_ATTR_NAME, 'nt');
7615
7813
  }
7616
7814
 
7617
- export { Index$a as AutoScroll, Index$c as Breadcrumb, WButton as Button, index$4 as Calendar, index$2 as Card, WCascader as Cascader, Index$4 as Checkbox, Index$9 as CountUp, Index$2 as DatePicker, DragBox, index as IconFont, Index as Input, WInputNumber as InputNumber, LineEcharts, Modal, ModalForm$1 as ModalForm, Modal$1 as ModalTips, Index$8 as Number, NumericInput, Index$3 as Radio, Select, Index$b as Swiper, WSwitch as Switch, index$3 as TabelCard, index$1 as Table, Index$7 as TreeSelect, Upload, index$6 as Video, index$5 as VideoPlayer, Index$6 as WDatePicker, WForm$1 as WForm, WaterLevelCharts, WebsocketHeart, useEventEmitter };
7815
+ export { Index$a as AutoScroll, Index$c as Breadcrumb, WButton as Button, index$4 as Calendar, index$2 as Card, WCascader as Cascader, Index$4 as Checkbox, Index$9 as CountUp, Index$2 as DatePicker, DragBox, index as IconFont, Index as Input, WInputNumber as InputNumber, LineEcharts, Modal, ModalForm$1 as ModalForm, Modal$1 as ModalTips, Index$8 as Number, NumericInput, Index$3 as Radio, Select, Index$b as Swiper, WSwitch as Switch, index$3 as TabelCard, index$1 as Table, Index$7 as TreeSelect, Upload, index$6 as Video, index$5 as VideoPlayer, Index$6 as WDatePicker, WForm$1 as WForm, WaterLevelCharts, WebsocketHeart, useEventEmitter, create as whox, wmox };
package/dist/index.js CHANGED
@@ -4,6 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var React = require('react');
6
6
  var lodash = require('lodash');
7
+ var shim = require('use-sync-external-store/shim');
7
8
  require('antd/es/button/style');
8
9
  var _Button = require('antd/es/button');
9
10
  require('antd/es/dropdown/style');
@@ -608,6 +609,203 @@ function useEventEmitter(options) {
608
609
  return ref.current;
609
610
  }
610
611
 
612
+ var run = function run(fn) {
613
+ fn();
614
+ };
615
+
616
+ var __DEV__ = process.env.NODE_ENV !== 'production';
617
+
618
+ var create = function create(initStore) {
619
+ if (__DEV__ && typeof initStore !== 'function') {
620
+ throw new Error('Expected a function');
621
+ }
622
+
623
+ var store;
624
+ var listeners = new Set();
625
+
626
+ function getSetStore(s) {
627
+ if (typeof s === 'undefined') return store;
628
+ var partial = typeof s === 'function' ? s(store) : s;
629
+ store = _objectSpread2(_objectSpread2({}, store), partial);
630
+ run(function () {
631
+ return listeners.forEach(function (listener) {
632
+ return listener(partial);
633
+ });
634
+ });
635
+ }
636
+
637
+ store = initStore(getSetStore);
638
+ return function useStore() {
639
+ var proxy = React.useRef({});
640
+ var handler = React.useRef({});
641
+ var hasState = React.useRef(false);
642
+ var hasUpdate = React.useRef(false);
643
+
644
+ var _useState = React.useState(false),
645
+ _useState2 = _slicedToArray(_useState, 2),
646
+ setState = _useState2[1];
647
+
648
+ React.useMemo(function () {
649
+ handler.current = {
650
+ get: function get(target, key) {
651
+ var val = store[key];
652
+
653
+ if (typeof val !== 'function') {
654
+ hasState.current = true;
655
+ target[key] = val;
656
+ return target[key];
657
+ }
658
+
659
+ target[key] = new Proxy(val, {
660
+ get: function get(fn, fnKey) {
661
+ if (fnKey === 'loading' && !('loading' in fn)) {
662
+ fn.loading = false;
663
+ }
664
+
665
+ return fn[fnKey];
666
+ },
667
+ apply: function apply(fn, _this, args) {
668
+ var res = fn.apply(void 0, _toConsumableArray(args));
669
+
670
+ if (!('loading' in fn) || !res || typeof res.then !== 'function') {
671
+ target[key] = fn;
672
+ return res;
673
+ }
674
+
675
+ var setLoading = function setLoading(loading) {
676
+ target[key].loading = loading;
677
+ setState(function (s) {
678
+ return !s;
679
+ });
680
+ };
681
+
682
+ target[key] = function () {
683
+ var newRes = fn.apply(void 0, arguments);
684
+ setLoading(true);
685
+ return newRes.finally(function () {
686
+ return setLoading(false);
687
+ });
688
+ };
689
+
690
+ setLoading(true);
691
+ return res.finally(function () {
692
+ return setLoading(false);
693
+ });
694
+ }
695
+ });
696
+ return target[key];
697
+ },
698
+ set: function set(target, key, val) {
699
+ if (key in target && val !== target[key]) {
700
+ hasUpdate.current = true;
701
+ target[key] = val;
702
+ }
703
+
704
+ return true;
705
+ }
706
+ };
707
+ proxy.current = new Proxy({}, handler.current);
708
+ }, []);
709
+ React.useEffect(function () {
710
+ handler.current.get = function (target, key) {
711
+ return target[key];
712
+ };
713
+ }, []);
714
+ var subscribe = React.useCallback(function (update) {
715
+ if (!hasState.current) return function () {
716
+ return undefined;
717
+ };
718
+
719
+ var listener = function listener(partial) {
720
+ Object.assign(proxy.current, partial);
721
+
722
+ if (hasUpdate.current) {
723
+ hasUpdate.current = false;
724
+ update();
725
+ }
726
+ };
727
+
728
+ listeners.add(listener);
729
+ return function () {
730
+ return listeners.delete(listener);
731
+ };
732
+ }, []);
733
+ var getSnapshot = React.useCallback(function () {
734
+ return store;
735
+ }, []);
736
+ shim.useSyncExternalStore(subscribe, getSnapshot);
737
+ return proxy.current;
738
+ };
739
+ };
740
+
741
+ create.config = function (_ref) {
742
+ var batch = _ref.batch;
743
+ run = batch;
744
+ };
745
+
746
+ var run$1 = function run(fn) {
747
+ fn();
748
+ };
749
+
750
+ var __DEV__$1 = process.env.NODE_ENV !== 'production';
751
+
752
+ var wmox = function wmox(state) {
753
+ if (__DEV__$1 && Object.prototype.toString.call(state) !== '[object Object]') {
754
+ throw new Error('object required');
755
+ }
756
+
757
+ var store = {};
758
+ Object.keys(state).forEach(function (key) {
759
+ if (typeof state[key] === 'function') {
760
+ return;
761
+ }
762
+
763
+ var listeners = new Set();
764
+ store[key] = {
765
+ subscribe: function subscribe(listener) {
766
+ listeners.add(listener);
767
+ return function () {
768
+ return listeners.delete(listener);
769
+ };
770
+ },
771
+ getSnapshot: function getSnapshot() {
772
+ return state[key];
773
+ },
774
+ setSnapshot: function setSnapshot(val) {
775
+ if (val !== state[key]) {
776
+ state[key] = val;
777
+ run$1(function () {
778
+ return listeners.forEach(function (listener) {
779
+ return listener();
780
+ });
781
+ });
782
+ }
783
+ },
784
+ useSnapshot: function useSnapshot() {
785
+ return shim.useSyncExternalStore(store[key].subscribe, store[key].getSnapshot);
786
+ }
787
+ };
788
+ });
789
+ return new Proxy(state, {
790
+ get: function get(_, key) {
791
+ try {
792
+ return store[key].useSnapshot();
793
+ } catch (e) {
794
+ return state[key];
795
+ }
796
+ },
797
+ set: function set(_, key, val) {
798
+ store[key].setSnapshot(val);
799
+ return true;
800
+ }
801
+ });
802
+ };
803
+
804
+ wmox.config = function (_ref) {
805
+ var batch = _ref.batch;
806
+ run$1 = batch;
807
+ };
808
+
611
809
  var _excluded = ["multiple", "children", "disabled"];
612
810
 
613
811
  var WButton = function WButton(props) {
@@ -7714,3 +7912,5 @@ exports.WForm = WForm$1;
7714
7912
  exports.WaterLevelCharts = WaterLevelCharts;
7715
7913
  exports.WebsocketHeart = WebsocketHeart;
7716
7914
  exports.useEventEmitter = useEventEmitter;
7915
+ exports.whox = create;
7916
+ exports.wmox = wmox;
package/package.json CHANGED
@@ -1,89 +1,91 @@
1
- {
2
- "private": false,
3
- "name": "wargerm",
4
- "version": "0.5.39",
5
- "scripts": {
6
- "dev": "dumi dev",
7
- "docs:build": "dumi build",
8
- "docs:deploy": "gh-pages -d docs-dist",
9
- "build": "father-build",
10
- "deploy": "npm run docs:build && npm run docs:deploy",
11
- "release": "npm run build && npm publish",
12
- "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
13
- "test": "umi-test",
14
- "test:coverage": "umi-test --coverage"
15
- },
16
- "main": "dist/index.js",
17
- "module": "dist/index.esm.js",
18
- "unpkg": "dist/index.umd.min.js",
19
- "typings": "dist/index.d.ts",
20
- "author": "jinly2",
21
- "license": "MIT",
22
- "keywords": [
23
- "React",
24
- "Component"
25
- ],
26
- "gitHooks": {
27
- "pre-commit": "lint-staged"
28
- },
29
- "repository": {
30
- "type": "git",
31
- "url": "http://code.eblssmart.com/platform/web/wargerm-components.git",
32
- "branch": "main"
33
- },
34
- "files": [
35
- "dist",
36
- "es",
37
- "lib",
38
- "index.css"
39
- ],
40
- "lint-staged": {
41
- "*.{js,jsx,less,md,json}": [
42
- "prettier --write"
43
- ],
44
- "*.ts?(x)": [
45
- "prettier --parser=typescript --write"
46
- ]
47
- },
48
- "dependencies": {
49
- "@ant-design/pro-table": "^2.79.0",
50
- "animate.css": "^4.1.1",
51
- "echarts": "^5.2.2",
52
- "echarts-for-react": "^3.0.2",
53
- "moment": "^2.29.4",
54
- "react-countup": "^6.0.0",
55
- "react-dom": "^17.0.2",
56
- "react-file-viewer": "^1.2.1",
57
- "swiper": "^6.7.0",
58
- "xgplayer": "^2.31.6",
59
- "xgplayer-flv": "^2.5.1",
60
- "xgplayer-flv.js": "^2.3.0",
61
- "xgplayer-hls": "^2.5.2",
62
- "xgplayer-hls.js": "^2.6.1"
63
- },
64
- "peerDependencies": {
65
- "@ant-design/icons": ">=4.2.0",
66
- "antd": ">=4.7.0",
67
- "classnames": ">=2.2.0",
68
- "echarts": "^5.2.2",
69
- "echarts-for-react": "^3.0.2",
70
- "lodash": ">=4.0.0",
71
- "react": ">=17.0.0"
72
- },
73
- "devDependencies": {
74
- "@ant-design/icons": "^4.6.4",
75
- "@types/lodash": "^4.14.173",
76
- "@types/react-dom": "^17.0.11",
77
- "@umijs/test": "^3.0.5",
78
- "antd": "^4.16.13",
79
- "babel-plugin-import": "^1.13.3",
80
- "classnames": "^2.3.1",
81
- "dumi": "^1.1.31",
82
- "father-build": "^1.19.1",
83
- "gh-pages": "^3.0.0",
84
- "lint-staged": "^10.0.7",
85
- "prettier": "^1.19.1",
86
- "react": "^16.12.0",
87
- "yorkie": "^2.0.0"
88
- }
89
- }
1
+ {
2
+ "private": false,
3
+ "name": "wargerm",
4
+ "version": "0.6.0",
5
+ "scripts": {
6
+ "dev": "dumi dev",
7
+ "docs:build": "dumi build",
8
+ "docs:deploy": "gh-pages -d docs-dist",
9
+ "build": "father-build",
10
+ "deploy": "npm run docs:build && npm run docs:deploy",
11
+ "release": "npm run build && npm publish",
12
+ "prettier": "prettier --write \"**/*.{js,jsx,tsx,ts,less,md,json}\"",
13
+ "test": "umi-test",
14
+ "test:coverage": "umi-test --coverage"
15
+ },
16
+ "main": "dist/index.js",
17
+ "module": "dist/index.esm.js",
18
+ "unpkg": "dist/index.umd.min.js",
19
+ "typings": "dist/index.d.ts",
20
+ "author": "jinly2",
21
+ "license": "MIT",
22
+ "keywords": [
23
+ "React",
24
+ "Component"
25
+ ],
26
+ "gitHooks": {
27
+ "pre-commit": "lint-staged"
28
+ },
29
+ "repository": {
30
+ "type": "git",
31
+ "url": "http://code.eblssmart.com/platform/web/wargerm-components.git",
32
+ "branch": "main"
33
+ },
34
+ "files": [
35
+ "dist",
36
+ "es",
37
+ "lib",
38
+ "index.css"
39
+ ],
40
+ "lint-staged": {
41
+ "*.{js,jsx,less,md,json}": [
42
+ "prettier --write"
43
+ ],
44
+ "*.ts?(x)": [
45
+ "prettier --parser=typescript --write"
46
+ ]
47
+ },
48
+ "dependencies": {
49
+ "@ant-design/pro-table": "^2.79.0",
50
+ "animate.css": "^4.1.1",
51
+ "echarts": "^5.2.2",
52
+ "echarts-for-react": "^3.0.2",
53
+ "moment": "^2.29.4",
54
+ "react-countup": "^6.0.0",
55
+ "react-dom": "^17.0.2",
56
+ "react-file-viewer": "^1.2.1",
57
+ "swiper": "^6.7.0",
58
+ "use-sync-external-store": "^1.2.0",
59
+ "xgplayer": "^2.31.6",
60
+ "xgplayer-flv": "^2.5.1",
61
+ "xgplayer-flv.js": "^2.3.0",
62
+ "xgplayer-hls": "^2.5.2",
63
+ "xgplayer-hls.js": "^2.6.1"
64
+ },
65
+ "peerDependencies": {
66
+ "@ant-design/icons": ">=4.2.0",
67
+ "antd": ">=4.7.0",
68
+ "classnames": ">=2.2.0",
69
+ "echarts": "^5.2.2",
70
+ "echarts-for-react": "^3.0.2",
71
+ "lodash": ">=4.0.0",
72
+ "react": ">=17.0.0"
73
+ },
74
+ "devDependencies": {
75
+ "@ant-design/icons": "^4.6.4",
76
+ "@types/lodash": "^4.14.173",
77
+ "@types/react-dom": "^17.0.11",
78
+ "@types/use-sync-external-store": "^0.0.3",
79
+ "@umijs/test": "^3.0.5",
80
+ "antd": "^4.16.13",
81
+ "babel-plugin-import": "^1.13.3",
82
+ "classnames": "^2.3.1",
83
+ "dumi": "^1.1.31",
84
+ "father-build": "^1.19.1",
85
+ "gh-pages": "^3.0.0",
86
+ "lint-staged": "^10.0.7",
87
+ "prettier": "^1.19.1",
88
+ "react": "^16.12.0",
89
+ "yorkie": "^2.0.0"
90
+ }
91
+ }