anu-verzum 2.3.0 → 2.3.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.
- package/dist/core/components/AnulyticsProvider.d.ts +2 -2
- package/dist/core/components/AnulyticsProvider.js +3 -2
- package/dist/core/components/Component.d.ts +2 -2
- package/dist/core/components/Connector.d.ts +2 -2
- package/dist/core/components/Connector.js +2 -2
- package/dist/core/components/Context.js +8 -9
- package/dist/core/components/Feature.js +1 -1
- package/dist/core/components/Fragment.d.ts +2 -2
- package/dist/core/components/Fragment.js +3 -2
- package/dist/core/elements.d.ts +2 -0
- package/dist/core/elements.js +22 -9
- package/dist/core/reconciler.js +1 -2
- package/dist/index.d.ts +1 -1
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component } from './Component';
|
|
2
|
-
import {
|
|
2
|
+
import { AnuChild, Props } from '../elements';
|
|
3
3
|
type UserActionEvent = {
|
|
4
4
|
type: string;
|
|
5
5
|
keyCode?: number | null;
|
|
@@ -26,7 +26,7 @@ declare class AnulyticsProvider extends Component<AnulyticsProviderProps> {
|
|
|
26
26
|
componentDidMount(): void;
|
|
27
27
|
componentWillUnmount(): void;
|
|
28
28
|
handleVisibilityChange(): void;
|
|
29
|
-
render():
|
|
29
|
+
render(): AnuChild[] | null;
|
|
30
30
|
}
|
|
31
31
|
export default AnulyticsProvider;
|
|
32
32
|
export declare const __testing: {
|
|
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.trackStateChange = exports.trackRouteChange = exports.trackEvent = exports.default = exports.__testing = void 0;
|
|
7
7
|
var _Component = require("./Component");
|
|
8
|
+
var _elements = require("../elements");
|
|
8
9
|
var _serverApi = _interopRequireDefault(require("../../server-api/server-api"));
|
|
9
10
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
10
11
|
const EventTypes = {
|
|
@@ -206,9 +207,9 @@ class AnulyticsProvider extends _Component.Component {
|
|
|
206
207
|
}
|
|
207
208
|
}
|
|
208
209
|
render() {
|
|
209
|
-
const children = this.props.children;
|
|
210
|
+
const children = (0, _elements.toChildArray)(this.props.children);
|
|
210
211
|
try {
|
|
211
|
-
if (
|
|
212
|
+
if (children.length !== 1) {
|
|
212
213
|
throw new Error('Provider must have one child element!');
|
|
213
214
|
}
|
|
214
215
|
return children;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { AnuNode, Props } from '../elements';
|
|
2
2
|
export declare abstract class Component<P extends Record<string, any> = Props, S extends Record<string, any> = Record<string, any>> {
|
|
3
3
|
props: P;
|
|
4
4
|
state: S;
|
|
@@ -7,7 +7,7 @@ export declare abstract class Component<P extends Record<string, any> = Props, S
|
|
|
7
7
|
static isAnuComponent: boolean;
|
|
8
8
|
constructor(props: P, context?: Record<string, any>);
|
|
9
9
|
setState(partialState?: Partial<S> | ((prevState: S, prevProps: P) => Partial<S>)): void;
|
|
10
|
-
abstract render():
|
|
10
|
+
abstract render(): AnuNode;
|
|
11
11
|
componentDidMount(): void;
|
|
12
12
|
componentDidUpdate(_prevProps: P, _prevState: S): void;
|
|
13
13
|
componentWillUnmount(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Component } from './Component';
|
|
2
|
-
import {
|
|
2
|
+
import { AnuChild, Props, ComponentConstructor } from '../elements';
|
|
3
3
|
type StoreShape = {
|
|
4
4
|
getState: () => any;
|
|
5
5
|
dispatch: (action: any) => any;
|
|
@@ -14,7 +14,7 @@ export interface ConnectorProviderProps extends Props {
|
|
|
14
14
|
declare class Provider extends Component<ConnectorProviderProps> {
|
|
15
15
|
store: StoreShape;
|
|
16
16
|
constructor(props: ConnectorProviderProps, context?: Record<string, any>);
|
|
17
|
-
render():
|
|
17
|
+
render(): AnuChild[] | null;
|
|
18
18
|
}
|
|
19
19
|
declare const Connector: {
|
|
20
20
|
connect: <TState = any, TOwnProps extends Record<string, any> = Record<string, any>, TStateProps extends Record<string, any> = Record<string, any>, TDispatchProps extends Record<string, any> = Record<string, any>>(mapStateToProps?: MapStateToProps<TState, TOwnProps, TStateProps> | null, mapDispatchToProps?: MapDispatchToProps<any, TOwnProps, TDispatchProps> | null) => (WrappedComponent: ComponentConstructor<TStateProps & TDispatchProps & TOwnProps>) => ComponentConstructor;
|
|
@@ -40,9 +40,9 @@ class Provider extends _Component.Component {
|
|
|
40
40
|
});
|
|
41
41
|
}
|
|
42
42
|
render() {
|
|
43
|
-
const children = this.props.children;
|
|
43
|
+
const children = (0, _elements.toChildArray)(this.props.children);
|
|
44
44
|
try {
|
|
45
|
-
if (
|
|
45
|
+
if (children.length !== 1) {
|
|
46
46
|
throw new Error('Provider must have one child element!');
|
|
47
47
|
}
|
|
48
48
|
return children;
|
|
@@ -6,6 +6,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
6
6
|
exports.createContext = void 0;
|
|
7
7
|
var _utils = require("../../misc/utils");
|
|
8
8
|
var _Component = require("./Component");
|
|
9
|
+
var _elements = require("../elements");
|
|
9
10
|
const createContext = context => {
|
|
10
11
|
const defaultContext = {
|
|
11
12
|
value: context
|
|
@@ -37,9 +38,9 @@ const createContext = context => {
|
|
|
37
38
|
}
|
|
38
39
|
}
|
|
39
40
|
render() {
|
|
40
|
-
const children = this.props.children;
|
|
41
|
+
const children = (0, _elements.toChildArray)(this.props.children);
|
|
41
42
|
try {
|
|
42
|
-
if (
|
|
43
|
+
if (children.length !== 1) {
|
|
43
44
|
throw new Error('Context Component must have exactly one child element!');
|
|
44
45
|
}
|
|
45
46
|
return children;
|
|
@@ -80,23 +81,21 @@ const createContext = context => {
|
|
|
80
81
|
}
|
|
81
82
|
}
|
|
82
83
|
render() {
|
|
83
|
-
const children = this.props.children;
|
|
84
|
+
const children = (0, _elements.toChildArray)(this.props.children);
|
|
84
85
|
try {
|
|
85
|
-
if (
|
|
86
|
+
if (children.length !== 1) {
|
|
86
87
|
throw new Error('Context Component must have exactly one child element!');
|
|
87
88
|
}
|
|
88
89
|
const provider = resolveProvider(this);
|
|
89
90
|
this.subscribeTo(provider);
|
|
90
91
|
const value = provider ? provider.value : defaultContext.value;
|
|
91
|
-
const
|
|
92
|
-
type
|
|
93
|
-
} = children[0];
|
|
92
|
+
const renderChild = children[0];
|
|
94
93
|
const childProps = {
|
|
95
94
|
value,
|
|
96
95
|
defaultContext
|
|
97
96
|
};
|
|
98
|
-
if (typeof
|
|
99
|
-
return
|
|
97
|
+
if (typeof renderChild === 'function') {
|
|
98
|
+
return renderChild(childProps);
|
|
100
99
|
} else {
|
|
101
100
|
throw new Error('Context component child element must be a function!');
|
|
102
101
|
}
|
|
@@ -12,7 +12,7 @@ const defaultFeatures = {};
|
|
|
12
12
|
const FeaturesContext = (0, _Context.createContext)(defaultFeatures);
|
|
13
13
|
const resolveDefault = defaultComponent => {
|
|
14
14
|
if (defaultComponent && !Array.isArray(defaultComponent) && defaultComponent.type === _Fragment.Fragment) {
|
|
15
|
-
return defaultComponent.props.children
|
|
15
|
+
return (0, _elements.toChildArray)(defaultComponent.props.children);
|
|
16
16
|
}
|
|
17
17
|
return defaultComponent;
|
|
18
18
|
};
|
|
@@ -5,11 +5,12 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.Fragment = void 0;
|
|
7
7
|
var _Component = require("./Component");
|
|
8
|
+
var _elements = require("../elements");
|
|
8
9
|
class Fragment extends _Component.Component {
|
|
9
10
|
render() {
|
|
10
|
-
const children = this.props.children;
|
|
11
|
+
const children = (0, _elements.toChildArray)(this.props.children);
|
|
11
12
|
try {
|
|
12
|
-
if (!children
|
|
13
|
+
if (!children.length) {
|
|
13
14
|
throw new Error('Fragment must have at least one child element!');
|
|
14
15
|
}
|
|
15
16
|
return children;
|
package/dist/core/elements.d.ts
CHANGED
|
@@ -22,3 +22,5 @@ export type AnuElement<P = Props, T extends ElementType = ElementType> = {
|
|
|
22
22
|
ref: Ref<any> | null;
|
|
23
23
|
};
|
|
24
24
|
export declare const createElement: (type: ElementType, config: Props | null, ...args: any[]) => AnuElement;
|
|
25
|
+
export declare const toChildArray: (children: AnuNode) => AnuChild[];
|
|
26
|
+
export declare const normalizeChildren: (children: AnuNode) => AnuElement[];
|
package/dist/core/elements.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.createElement = exports.TEXT_ELEMENT = exports.PORTAL_ELEMENT = void 0;
|
|
6
|
+
exports.toChildArray = exports.normalizeChildren = exports.createElement = exports.TEXT_ELEMENT = exports.PORTAL_ELEMENT = void 0;
|
|
7
7
|
const TEXT_ELEMENT = exports.TEXT_ELEMENT = 'TEXT_ELEMENT';
|
|
8
8
|
const PORTAL_ELEMENT = exports.PORTAL_ELEMENT = Symbol('portal');
|
|
9
9
|
const createTextElement = value => ({
|
|
@@ -20,13 +20,10 @@ const createElement = (type, config, ...args) => {
|
|
|
20
20
|
const props = Object.assign({}, config);
|
|
21
21
|
delete props.key;
|
|
22
22
|
delete props.ref;
|
|
23
|
-
if (args.length
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}) : c instanceof Object ? c : createTextElement(c));
|
|
28
|
-
} else {
|
|
29
|
-
props.children = props.children ?? [];
|
|
23
|
+
if (args.length === 1) {
|
|
24
|
+
props.children = args[0];
|
|
25
|
+
} else if (args.length > 1) {
|
|
26
|
+
props.children = args;
|
|
30
27
|
}
|
|
31
28
|
return {
|
|
32
29
|
type,
|
|
@@ -35,4 +32,20 @@ const createElement = (type, config, ...args) => {
|
|
|
35
32
|
ref
|
|
36
33
|
};
|
|
37
34
|
};
|
|
38
|
-
exports.createElement = createElement;
|
|
35
|
+
exports.createElement = createElement;
|
|
36
|
+
const flattenChildren = (children, acc = []) => {
|
|
37
|
+
if (Array.isArray(children)) {
|
|
38
|
+
for (const child of children) {
|
|
39
|
+
flattenChildren(child, acc);
|
|
40
|
+
}
|
|
41
|
+
} else if (children !== null && children !== undefined && typeof children !== 'boolean') {
|
|
42
|
+
acc.push(children);
|
|
43
|
+
}
|
|
44
|
+
return acc;
|
|
45
|
+
};
|
|
46
|
+
const toChildArray = children => flattenChildren(children);
|
|
47
|
+
exports.toChildArray = toChildArray;
|
|
48
|
+
const normalizeChildren = children => flattenChildren(children).map(c => typeof c === 'function' ? createElement(c, {
|
|
49
|
+
...(c.props || {})
|
|
50
|
+
}) : c instanceof Object ? c : createTextElement(c));
|
|
51
|
+
exports.normalizeChildren = normalizeChildren;
|
package/dist/core/reconciler.js
CHANGED
|
@@ -204,7 +204,6 @@ const updateClassComponent = wipFiber => {
|
|
|
204
204
|
const newChildElements = wipFiber.stateNode.render();
|
|
205
205
|
reconcileChildrenArray(wipFiber, newChildElements);
|
|
206
206
|
};
|
|
207
|
-
const arrify = val => !val ? [] : Array.isArray(val) ? val : [val];
|
|
208
207
|
const getTag = element => {
|
|
209
208
|
if (element.type === _elements.PORTAL_ELEMENT) {
|
|
210
209
|
return PORTAL;
|
|
@@ -218,7 +217,7 @@ const getTag = element => {
|
|
|
218
217
|
return CLASS_COMPONENT;
|
|
219
218
|
};
|
|
220
219
|
const reconcileChildrenArray = (wipFiber, newChildElements) => {
|
|
221
|
-
const elements =
|
|
220
|
+
const elements = (0, _elements.normalizeChildren)(newChildElements);
|
|
222
221
|
const oldFiberMap = new Map();
|
|
223
222
|
let oldFiber = wipFiber.alternate ? wipFiber.alternate.child : undefined;
|
|
224
223
|
let oldIndex = 0;
|
package/dist/index.d.ts
CHANGED
|
@@ -118,7 +118,7 @@ declare const Anu: {
|
|
|
118
118
|
subscribe: (listener: () => void) => void;
|
|
119
119
|
unsubscribe: (listener: () => void) => void;
|
|
120
120
|
};
|
|
121
|
-
render():
|
|
121
|
+
render(): import(".").AnuChild[] | null;
|
|
122
122
|
props: import("./core/components/Connector").ConnectorProviderProps;
|
|
123
123
|
state: Record<string, any>;
|
|
124
124
|
context: Record<string, any>;
|
package/package.json
CHANGED