@viewfly/core 2.0.0-alpha.5 → 2.0.0-alpha.7
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/bundles/index.d.ts +13 -6
- package/bundles/index.esm.js +81 -73
- package/bundles/index.js +81 -73
- package/package.json +2 -2
package/bundles/index.d.ts
CHANGED
|
@@ -211,7 +211,7 @@ declare function comparePropsWithCallbacks(oldProps: Record<string, any>, newPro
|
|
|
211
211
|
declare const TextAtomType: unique symbol;
|
|
212
212
|
declare const ElementAtomType: unique symbol;
|
|
213
213
|
declare const ComponentAtomType: unique symbol;
|
|
214
|
-
type ElementNamespace = string |
|
|
214
|
+
type ElementNamespace = string | void;
|
|
215
215
|
interface TextAtom {
|
|
216
216
|
type: typeof TextAtomType;
|
|
217
217
|
index: number;
|
|
@@ -264,6 +264,7 @@ declare abstract class NativeRenderer<ElementNode = NativeNode, TextNode = Nativ
|
|
|
264
264
|
abstract cleanChildren(node: ElementNode, namespace: ElementNamespace): void;
|
|
265
265
|
abstract syncTextContent(target: TextNode, content: string, namespace: ElementNamespace): void;
|
|
266
266
|
abstract insertAfter(newNode: ElementNode | TextNode, ref: ElementNode | TextNode, namespace: ElementNamespace): void;
|
|
267
|
+
abstract getNameSpace(type: string, namespace: ElementNamespace): string | void;
|
|
267
268
|
}
|
|
268
269
|
|
|
269
270
|
interface RefListener<T> {
|
|
@@ -439,6 +440,16 @@ declare function getCurrentInstance(): Component;
|
|
|
439
440
|
declare function registryComponentDestroyCallback(fn: () => void): void;
|
|
440
441
|
|
|
441
442
|
declare function createContext(providers: Provider[], scope?: Scope | null, parentInjector?: Injector): (props: Props) => () => JSXNode | JSXNode[];
|
|
443
|
+
interface ContextProviderParams<T> {
|
|
444
|
+
provide: Type<T> | AbstractType<T> | InjectionToken<T>;
|
|
445
|
+
}
|
|
446
|
+
interface ContextProvider<T> extends Props {
|
|
447
|
+
useClass?: ClassProvider<T>['useClass'];
|
|
448
|
+
useFactory?: FactoryProvider<T>['useFactory'];
|
|
449
|
+
useValue?: ValueProvider<T>['useValue'];
|
|
450
|
+
useExisting?: ExistingProvider<T>['useExisting'];
|
|
451
|
+
}
|
|
452
|
+
declare function createContextProvider<T>(params: ContextProviderParams<T>): (props: ContextProvider<T>) => () => ViewFlyNode<string | ComponentSetup<any>>;
|
|
442
453
|
/**
|
|
443
454
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
444
455
|
*/
|
|
@@ -480,10 +491,6 @@ declare function popDepContext(): void;
|
|
|
480
491
|
|
|
481
492
|
declare function withMemo<T extends Props = Props>(canUseMemo: ComponentInstance<T>['$useMemo'], render: () => JSXNode): ComponentInstance<T>;
|
|
482
493
|
|
|
483
|
-
declare const ElementNamespaceMap: {
|
|
484
|
-
readonly svg: "svg";
|
|
485
|
-
readonly math: "mathml";
|
|
486
|
-
};
|
|
487
494
|
declare function createRenderer(component: Component, nativeRenderer: NativeRenderer, namespace: ElementNamespace): (host: NativeNode) => void;
|
|
488
495
|
|
|
489
496
|
/**
|
|
@@ -711,4 +718,4 @@ declare function createEffect<T, T1, T2, T3, T4, T5, T6, T7>(deps: [Signal<T>, S
|
|
|
711
718
|
declare function createEffect<T>(deps: () => T, callback: EffectCallback<T>): () => void;
|
|
712
719
|
declare function createEffect<T = any>(deps: Signal<any>[], callback: EffectCallback<T[]>): () => void;
|
|
713
720
|
|
|
714
|
-
export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, ArrayReactiveHandler, type Atom, type ClassNames, type ClassProvider, Component, type ComponentAnnotation, type ComponentInstance, type ComponentSetup, type ComponentViewMetadata, type Computed, type Config, type ConstructorProvider, Dep, DynamicRef, type EffectCallback, type ElementNamespace,
|
|
721
|
+
export { type AbstractInstanceType, type AbstractProvider, type AbstractType, type Application, ArrayReactiveHandler, type Atom, type ClassNames, type ClassProvider, Component, type ComponentAnnotation, type ComponentInstance, type ComponentSetup, type ComponentViewMetadata, type Computed, type Config, type ConstructorProvider, type ContextProvider, type ContextProviderParams, Dep, DynamicRef, type EffectCallback, type ElementNamespace, type ExistingProvider, type ExtractInstanceType, type ExtractValueType, type FactoryProvider, ForwardRef, Fragment, Inject, type InjectDecorator, InjectFlags, Injectable, type InjectableDecorator, type InjectableOptions, InjectionToken, Injector, JSX, type JSXNode, JSXNodeFactory, type Key, type LifeCycleCallback, MapReactiveHandler, type Module, type NativeNode, NativeRenderer, type NormalizedProvider, NullInjector, ObjectReactiveHandler, Optional, type OptionalDecorator, Prop, type PropDecorator, type Props, type ProvideScope, type Provider, type ReactiveConfig, type RefListener, type ReflectiveDependency, ReflectiveInjector, RootComponent, Scope, Self, type SelfDecorator, SetReactiveHandler, type Signal, SkipSelf, type SkipSelfDecorator, type StaticProvider, StaticRef, THROW_IF_NOT_FOUND, TrackOpTypes, TriggerOpTypes, Type, type TypeProvider, type ValueProvider, type ViewFlyNode, comparePropsWithCallbacks, computed, createContext, createContextProvider, createDerived, createDynamicRef, createEffect, createRef, createRenderer, createSignal, defaultArrayReactiveHandler, defaultMapReactiveHandler, defaultObjectReactiveHandler, defaultSetReactiveHandler, defaultShallowArrayReactiveHandler, defaultShallowMapReactiveHandler, defaultShallowObjectReactiveHandler, defaultShallowSetReactiveHandler, forwardRef, getCurrentInstance, getDepContext, getSetupContext, inject, internalWrite, isReactive, jsx, jsxs, makeError, normalizeProvider, onMounted, onUnmounted, onUpdated, popDepContext, proxyToRawCache, pushDepContext, rawToProxyCache, reactive, readonlyProxyHandler, registryComponentDestroyCallback, shallowReactive, toRaw, track, trigger, viewfly, watch, withAnnotation, withMemo };
|
package/bundles/index.esm.js
CHANGED
|
@@ -1167,12 +1167,13 @@ class ObjectReactiveHandler {
|
|
|
1167
1167
|
if (this.isReadonly && !fromInternalWrite) {
|
|
1168
1168
|
throw reactiveErrorFn('Object is readonly!');
|
|
1169
1169
|
}
|
|
1170
|
-
|
|
1170
|
+
const rawValue = toRaw(newValue);
|
|
1171
1171
|
const oldValue = target[p];
|
|
1172
|
-
|
|
1173
|
-
|
|
1172
|
+
const v = this.isShallow ? newValue : rawValue;
|
|
1173
|
+
if (oldValue === rawValue) {
|
|
1174
|
+
return Reflect.set(target, p, v, receiver);
|
|
1174
1175
|
}
|
|
1175
|
-
const b = Reflect.set(target, p,
|
|
1176
|
+
const b = Reflect.set(target, p, v, receiver);
|
|
1176
1177
|
fromInternalWrite = false;
|
|
1177
1178
|
if (hasOwn(target, p)) {
|
|
1178
1179
|
trigger(target, TriggerOpTypes.Set, p);
|
|
@@ -1634,6 +1635,53 @@ function registryComponentDestroyCallback(fn) {
|
|
|
1634
1635
|
}
|
|
1635
1636
|
}
|
|
1636
1637
|
|
|
1638
|
+
function Fragment(props) {
|
|
1639
|
+
return () => {
|
|
1640
|
+
return props.children;
|
|
1641
|
+
};
|
|
1642
|
+
}
|
|
1643
|
+
function jsx(type, props, key) {
|
|
1644
|
+
return JSXNodeFactory.createNode(type, props, key);
|
|
1645
|
+
}
|
|
1646
|
+
const jsxs = jsx;
|
|
1647
|
+
const JSXNodeFactory = {
|
|
1648
|
+
createNode(type, props, key) {
|
|
1649
|
+
return {
|
|
1650
|
+
type,
|
|
1651
|
+
props,
|
|
1652
|
+
key
|
|
1653
|
+
};
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
|
|
1657
|
+
function watch(trigger, callback) {
|
|
1658
|
+
let prevFn;
|
|
1659
|
+
const dep = new Dep(() => {
|
|
1660
|
+
pushDepContext(dep);
|
|
1661
|
+
const newValue = trigger();
|
|
1662
|
+
popDepContext();
|
|
1663
|
+
if (newValue === oldValue) {
|
|
1664
|
+
return;
|
|
1665
|
+
}
|
|
1666
|
+
if (prevFn) {
|
|
1667
|
+
prevFn();
|
|
1668
|
+
}
|
|
1669
|
+
prevFn = callback(newValue, oldValue);
|
|
1670
|
+
oldValue = newValue;
|
|
1671
|
+
});
|
|
1672
|
+
pushDepContext(dep);
|
|
1673
|
+
let oldValue = trigger();
|
|
1674
|
+
popDepContext();
|
|
1675
|
+
dep.destroyCallbacks.push(() => {
|
|
1676
|
+
prevFn === null || prevFn === void 0 ? void 0 : prevFn();
|
|
1677
|
+
});
|
|
1678
|
+
function unWatch() {
|
|
1679
|
+
dep.destroy();
|
|
1680
|
+
}
|
|
1681
|
+
registryComponentDestroyCallback(unWatch);
|
|
1682
|
+
return unWatch;
|
|
1683
|
+
}
|
|
1684
|
+
|
|
1637
1685
|
const injectMap = new WeakMap();
|
|
1638
1686
|
function getInjector(start) {
|
|
1639
1687
|
while (start) {
|
|
@@ -1655,6 +1703,19 @@ function createContext(providers, scope, parentInjector) {
|
|
|
1655
1703
|
};
|
|
1656
1704
|
};
|
|
1657
1705
|
}
|
|
1706
|
+
function createContextProvider(params) {
|
|
1707
|
+
return function contextProvider(props) {
|
|
1708
|
+
let Context = createContext([Object.assign({ provide: params.provide }, props)]);
|
|
1709
|
+
watch(() => {
|
|
1710
|
+
return props.useClass || props.useFactory || props.useValue || props.useExisting;
|
|
1711
|
+
}, () => {
|
|
1712
|
+
Context = createContext([Object.assign({ provide: params.provide }, props)]);
|
|
1713
|
+
});
|
|
1714
|
+
return () => {
|
|
1715
|
+
return jsx(Context, { children: props.children });
|
|
1716
|
+
};
|
|
1717
|
+
};
|
|
1718
|
+
}
|
|
1658
1719
|
/**
|
|
1659
1720
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
1660
1721
|
*/
|
|
@@ -1700,25 +1761,6 @@ function withAnnotation(annotation, componentSetup) {
|
|
|
1700
1761
|
class NativeRenderer {
|
|
1701
1762
|
}
|
|
1702
1763
|
|
|
1703
|
-
function Fragment(props) {
|
|
1704
|
-
return () => {
|
|
1705
|
-
return props.children;
|
|
1706
|
-
};
|
|
1707
|
-
}
|
|
1708
|
-
function jsx(type, props, key) {
|
|
1709
|
-
return JSXNodeFactory.createNode(type, props, key);
|
|
1710
|
-
}
|
|
1711
|
-
const jsxs = jsx;
|
|
1712
|
-
const JSXNodeFactory = {
|
|
1713
|
-
createNode(type, props, key) {
|
|
1714
|
-
return {
|
|
1715
|
-
type,
|
|
1716
|
-
props,
|
|
1717
|
-
key
|
|
1718
|
-
};
|
|
1719
|
-
}
|
|
1720
|
-
};
|
|
1721
|
-
|
|
1722
1764
|
function withMemo(canUseMemo, render) {
|
|
1723
1765
|
return {
|
|
1724
1766
|
$useMemo: canUseMemo,
|
|
@@ -1726,10 +1768,6 @@ function withMemo(canUseMemo, render) {
|
|
|
1726
1768
|
};
|
|
1727
1769
|
}
|
|
1728
1770
|
|
|
1729
|
-
const ElementNamespaceMap = {
|
|
1730
|
-
svg: 'svg',
|
|
1731
|
-
math: 'mathml',
|
|
1732
|
-
};
|
|
1733
1771
|
const listenerReg = /^on[A-Z]/;
|
|
1734
1772
|
function createRenderer(component, nativeRenderer, namespace) {
|
|
1735
1773
|
let isInit = true;
|
|
@@ -1780,7 +1818,7 @@ function buildElementChildren(atom, nativeRenderer, parentComponent, context) {
|
|
|
1780
1818
|
}
|
|
1781
1819
|
function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, context, needMove) {
|
|
1782
1820
|
const newTemplate = component.rerender();
|
|
1783
|
-
newAtom.child = createChildChain(newTemplate, newAtom.namespace);
|
|
1821
|
+
newAtom.child = createChildChain(newTemplate, nativeRenderer, newAtom.namespace);
|
|
1784
1822
|
diff(nativeRenderer, component, newAtom.child, oldChildAtom, context, needMove);
|
|
1785
1823
|
}
|
|
1786
1824
|
function deepUpdateByComponentDirtyTree(nativeRenderer, component, needMove) {
|
|
@@ -2003,7 +2041,7 @@ function cleanChildren(atom, nativeRenderer, needClean) {
|
|
|
2003
2041
|
}
|
|
2004
2042
|
function componentRender(nativeRenderer, component, from, context) {
|
|
2005
2043
|
component.render((template, portalHost) => {
|
|
2006
|
-
from.child = createChildChain(template, from.namespace);
|
|
2044
|
+
from.child = createChildChain(template, nativeRenderer, from.namespace);
|
|
2007
2045
|
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
2008
2046
|
component.viewMetadata = Object.assign({ atom: from }, context);
|
|
2009
2047
|
let child = from.child;
|
|
@@ -2028,7 +2066,7 @@ function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, namespace, key)
|
|
|
2028
2066
|
prevAtom.sibling = atom;
|
|
2029
2067
|
return atom;
|
|
2030
2068
|
}
|
|
2031
|
-
function createChainByNode(jsxNode, prevAtom, elementNamespace) {
|
|
2069
|
+
function createChainByNode(jsxNode, prevAtom, nativeRenderer, elementNamespace) {
|
|
2032
2070
|
const type = typeof jsxNode;
|
|
2033
2071
|
if (jsxNode != null && type !== 'boolean') {
|
|
2034
2072
|
if (type === 'string') {
|
|
@@ -2036,11 +2074,11 @@ function createChainByNode(jsxNode, prevAtom, elementNamespace) {
|
|
|
2036
2074
|
}
|
|
2037
2075
|
if (type === 'object') {
|
|
2038
2076
|
if (Array.isArray(jsxNode)) {
|
|
2039
|
-
return createChainByChildren(jsxNode, prevAtom, elementNamespace);
|
|
2077
|
+
return createChainByChildren(jsxNode, prevAtom, nativeRenderer, elementNamespace);
|
|
2040
2078
|
}
|
|
2041
2079
|
const nodeType = typeof jsxNode.type;
|
|
2042
2080
|
if (nodeType === 'string') {
|
|
2043
|
-
return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom,
|
|
2081
|
+
return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, nativeRenderer.getNameSpace(jsxNode.type, elementNamespace), jsxNode.key);
|
|
2044
2082
|
}
|
|
2045
2083
|
else if (nodeType === 'function') {
|
|
2046
2084
|
return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, elementNamespace, jsxNode.key);
|
|
@@ -2051,17 +2089,17 @@ function createChainByNode(jsxNode, prevAtom, elementNamespace) {
|
|
|
2051
2089
|
}
|
|
2052
2090
|
return prevAtom;
|
|
2053
2091
|
}
|
|
2054
|
-
function createChainByChildren(children, prevAtom, elementNamespace) {
|
|
2092
|
+
function createChainByChildren(children, prevAtom, nativeRenderer, elementNamespace) {
|
|
2055
2093
|
const len = children.length;
|
|
2056
2094
|
for (let i = 0; i < len; i++) {
|
|
2057
2095
|
const item = children[i];
|
|
2058
|
-
prevAtom = createChainByNode(item, prevAtom, elementNamespace);
|
|
2096
|
+
prevAtom = createChainByNode(item, prevAtom, nativeRenderer, elementNamespace);
|
|
2059
2097
|
}
|
|
2060
2098
|
return prevAtom;
|
|
2061
2099
|
}
|
|
2062
|
-
function createChildChain(template, namespace) {
|
|
2100
|
+
function createChildChain(template, nativeRenderer, namespace) {
|
|
2063
2101
|
const beforeAtom = { sibling: null, index: -1 };
|
|
2064
|
-
createChainByNode(template, beforeAtom, namespace);
|
|
2102
|
+
createChainByNode(template, beforeAtom, nativeRenderer, namespace);
|
|
2065
2103
|
return beforeAtom.sibling;
|
|
2066
2104
|
}
|
|
2067
2105
|
function insertNode(nativeRenderer, atom, context) {
|
|
@@ -2077,11 +2115,9 @@ function insertNode(nativeRenderer, atom, context) {
|
|
|
2077
2115
|
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.namespace);
|
|
2078
2116
|
}
|
|
2079
2117
|
}
|
|
2080
|
-
function createElementChildren(type, children, namespace) {
|
|
2081
|
-
|
|
2082
|
-
|
|
2083
|
-
}
|
|
2084
|
-
return createChildChain(children, namespace);
|
|
2118
|
+
function createElementChildren(type, children, nativeRenderer, namespace) {
|
|
2119
|
+
const ns = nativeRenderer.getNameSpace(type, namespace);
|
|
2120
|
+
return createChildChain(children, nativeRenderer, ns);
|
|
2085
2121
|
}
|
|
2086
2122
|
function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
2087
2123
|
const { namespace, jsxNode } = atom;
|
|
@@ -2090,7 +2126,7 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
|
2090
2126
|
let bindingRefs;
|
|
2091
2127
|
for (const key in props) {
|
|
2092
2128
|
if (key === 'children') {
|
|
2093
|
-
atom.child = createElementChildren(jsxNode.type, props.children, namespace);
|
|
2129
|
+
atom.child = createElementChildren(jsxNode.type, props.children, nativeRenderer, namespace);
|
|
2094
2130
|
continue;
|
|
2095
2131
|
}
|
|
2096
2132
|
if (key === 'class') {
|
|
@@ -2181,7 +2217,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
2181
2217
|
}, (key, value) => {
|
|
2182
2218
|
if (key === 'children') {
|
|
2183
2219
|
updatedChildren = true;
|
|
2184
|
-
newAtom.child = createElementChildren(newVNode.type, value, isSvg);
|
|
2220
|
+
newAtom.child = createElementChildren(newVNode.type, value, nativeRenderer, isSvg);
|
|
2185
2221
|
buildElementChildren(newAtom, nativeRenderer, parentComponent, context);
|
|
2186
2222
|
return;
|
|
2187
2223
|
}
|
|
@@ -2210,7 +2246,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
2210
2246
|
}, (key, newValue, oldValue) => {
|
|
2211
2247
|
if (key === 'children') {
|
|
2212
2248
|
updatedChildren = true;
|
|
2213
|
-
newAtom.child = createElementChildren(newVNode.type, newValue, isSvg);
|
|
2249
|
+
newAtom.child = createElementChildren(newVNode.type, newValue, nativeRenderer, isSvg);
|
|
2214
2250
|
if (!newAtom.child) {
|
|
2215
2251
|
cleanElementChildren(oldAtom, nativeRenderer);
|
|
2216
2252
|
}
|
|
@@ -2471,34 +2507,6 @@ function shallowReactive(raw) {
|
|
|
2471
2507
|
return proxy;
|
|
2472
2508
|
}
|
|
2473
2509
|
|
|
2474
|
-
function watch(trigger, callback) {
|
|
2475
|
-
let prevFn;
|
|
2476
|
-
const dep = new Dep(() => {
|
|
2477
|
-
pushDepContext(dep);
|
|
2478
|
-
const newValue = trigger();
|
|
2479
|
-
popDepContext();
|
|
2480
|
-
if (newValue === oldValue) {
|
|
2481
|
-
return;
|
|
2482
|
-
}
|
|
2483
|
-
if (prevFn) {
|
|
2484
|
-
prevFn();
|
|
2485
|
-
}
|
|
2486
|
-
prevFn = callback(newValue, oldValue);
|
|
2487
|
-
oldValue = newValue;
|
|
2488
|
-
});
|
|
2489
|
-
pushDepContext(dep);
|
|
2490
|
-
let oldValue = trigger();
|
|
2491
|
-
popDepContext();
|
|
2492
|
-
dep.destroyCallbacks.push(() => {
|
|
2493
|
-
prevFn === null || prevFn === void 0 ? void 0 : prevFn();
|
|
2494
|
-
});
|
|
2495
|
-
function unWatch() {
|
|
2496
|
-
dep.destroy();
|
|
2497
|
-
}
|
|
2498
|
-
registryComponentDestroyCallback(unWatch);
|
|
2499
|
-
return unWatch;
|
|
2500
|
-
}
|
|
2501
|
-
|
|
2502
2510
|
/**
|
|
2503
2511
|
* 组件状态管理器
|
|
2504
2512
|
* @param state 初始状态
|
|
@@ -2618,4 +2626,4 @@ function createEffect(deps, callback) {
|
|
|
2618
2626
|
return unWatch;
|
|
2619
2627
|
}
|
|
2620
2628
|
|
|
2621
|
-
export { ArrayReactiveHandler, Component, Dep, DynamicRef,
|
|
2629
|
+
export { ArrayReactiveHandler, Component, Dep, DynamicRef, ForwardRef, Fragment, Inject, InjectFlags, Injectable, InjectionToken, Injector, JSXNodeFactory, MapReactiveHandler, NativeRenderer, NullInjector, ObjectReactiveHandler, Optional, Prop, ReflectiveInjector, RootComponent, Scope, Self, SetReactiveHandler, SkipSelf, StaticRef, THROW_IF_NOT_FOUND, TrackOpTypes, TriggerOpTypes, Type, comparePropsWithCallbacks, computed, createContext, createContextProvider, createDerived, createDynamicRef, createEffect, createRef, createRenderer, createSignal, defaultArrayReactiveHandler, defaultMapReactiveHandler, defaultObjectReactiveHandler, defaultSetReactiveHandler, defaultShallowArrayReactiveHandler, defaultShallowMapReactiveHandler, defaultShallowObjectReactiveHandler, defaultShallowSetReactiveHandler, forwardRef, getCurrentInstance, getDepContext, getSetupContext, inject, internalWrite, isReactive, jsx, jsxs, makeError, normalizeProvider, onMounted, onUnmounted, onUpdated, popDepContext, proxyToRawCache, pushDepContext, rawToProxyCache, reactive, readonlyProxyHandler, registryComponentDestroyCallback, shallowReactive, toRaw, track, trigger, viewfly, watch, withAnnotation, withMemo };
|
package/bundles/index.js
CHANGED
|
@@ -1169,12 +1169,13 @@ class ObjectReactiveHandler {
|
|
|
1169
1169
|
if (this.isReadonly && !fromInternalWrite) {
|
|
1170
1170
|
throw reactiveErrorFn('Object is readonly!');
|
|
1171
1171
|
}
|
|
1172
|
-
|
|
1172
|
+
const rawValue = toRaw(newValue);
|
|
1173
1173
|
const oldValue = target[p];
|
|
1174
|
-
|
|
1175
|
-
|
|
1174
|
+
const v = this.isShallow ? newValue : rawValue;
|
|
1175
|
+
if (oldValue === rawValue) {
|
|
1176
|
+
return Reflect.set(target, p, v, receiver);
|
|
1176
1177
|
}
|
|
1177
|
-
const b = Reflect.set(target, p,
|
|
1178
|
+
const b = Reflect.set(target, p, v, receiver);
|
|
1178
1179
|
fromInternalWrite = false;
|
|
1179
1180
|
if (hasOwn(target, p)) {
|
|
1180
1181
|
trigger(target, exports.TriggerOpTypes.Set, p);
|
|
@@ -1636,6 +1637,53 @@ function registryComponentDestroyCallback(fn) {
|
|
|
1636
1637
|
}
|
|
1637
1638
|
}
|
|
1638
1639
|
|
|
1640
|
+
function Fragment(props) {
|
|
1641
|
+
return () => {
|
|
1642
|
+
return props.children;
|
|
1643
|
+
};
|
|
1644
|
+
}
|
|
1645
|
+
function jsx(type, props, key) {
|
|
1646
|
+
return JSXNodeFactory.createNode(type, props, key);
|
|
1647
|
+
}
|
|
1648
|
+
const jsxs = jsx;
|
|
1649
|
+
const JSXNodeFactory = {
|
|
1650
|
+
createNode(type, props, key) {
|
|
1651
|
+
return {
|
|
1652
|
+
type,
|
|
1653
|
+
props,
|
|
1654
|
+
key
|
|
1655
|
+
};
|
|
1656
|
+
}
|
|
1657
|
+
};
|
|
1658
|
+
|
|
1659
|
+
function watch(trigger, callback) {
|
|
1660
|
+
let prevFn;
|
|
1661
|
+
const dep = new Dep(() => {
|
|
1662
|
+
pushDepContext(dep);
|
|
1663
|
+
const newValue = trigger();
|
|
1664
|
+
popDepContext();
|
|
1665
|
+
if (newValue === oldValue) {
|
|
1666
|
+
return;
|
|
1667
|
+
}
|
|
1668
|
+
if (prevFn) {
|
|
1669
|
+
prevFn();
|
|
1670
|
+
}
|
|
1671
|
+
prevFn = callback(newValue, oldValue);
|
|
1672
|
+
oldValue = newValue;
|
|
1673
|
+
});
|
|
1674
|
+
pushDepContext(dep);
|
|
1675
|
+
let oldValue = trigger();
|
|
1676
|
+
popDepContext();
|
|
1677
|
+
dep.destroyCallbacks.push(() => {
|
|
1678
|
+
prevFn === null || prevFn === void 0 ? void 0 : prevFn();
|
|
1679
|
+
});
|
|
1680
|
+
function unWatch() {
|
|
1681
|
+
dep.destroy();
|
|
1682
|
+
}
|
|
1683
|
+
registryComponentDestroyCallback(unWatch);
|
|
1684
|
+
return unWatch;
|
|
1685
|
+
}
|
|
1686
|
+
|
|
1639
1687
|
const injectMap = new WeakMap();
|
|
1640
1688
|
function getInjector(start) {
|
|
1641
1689
|
while (start) {
|
|
@@ -1657,6 +1705,19 @@ function createContext(providers, scope, parentInjector) {
|
|
|
1657
1705
|
};
|
|
1658
1706
|
};
|
|
1659
1707
|
}
|
|
1708
|
+
function createContextProvider(params) {
|
|
1709
|
+
return function contextProvider(props) {
|
|
1710
|
+
let Context = createContext([Object.assign({ provide: params.provide }, props)]);
|
|
1711
|
+
watch(() => {
|
|
1712
|
+
return props.useClass || props.useFactory || props.useValue || props.useExisting;
|
|
1713
|
+
}, () => {
|
|
1714
|
+
Context = createContext([Object.assign({ provide: params.provide }, props)]);
|
|
1715
|
+
});
|
|
1716
|
+
return () => {
|
|
1717
|
+
return jsx(Context, { children: props.children });
|
|
1718
|
+
};
|
|
1719
|
+
};
|
|
1720
|
+
}
|
|
1660
1721
|
/**
|
|
1661
1722
|
* 通过组件上下文获取 IoC 容器内数据的勾子方法
|
|
1662
1723
|
*/
|
|
@@ -1702,25 +1763,6 @@ function withAnnotation(annotation, componentSetup) {
|
|
|
1702
1763
|
class NativeRenderer {
|
|
1703
1764
|
}
|
|
1704
1765
|
|
|
1705
|
-
function Fragment(props) {
|
|
1706
|
-
return () => {
|
|
1707
|
-
return props.children;
|
|
1708
|
-
};
|
|
1709
|
-
}
|
|
1710
|
-
function jsx(type, props, key) {
|
|
1711
|
-
return JSXNodeFactory.createNode(type, props, key);
|
|
1712
|
-
}
|
|
1713
|
-
const jsxs = jsx;
|
|
1714
|
-
const JSXNodeFactory = {
|
|
1715
|
-
createNode(type, props, key) {
|
|
1716
|
-
return {
|
|
1717
|
-
type,
|
|
1718
|
-
props,
|
|
1719
|
-
key
|
|
1720
|
-
};
|
|
1721
|
-
}
|
|
1722
|
-
};
|
|
1723
|
-
|
|
1724
1766
|
function withMemo(canUseMemo, render) {
|
|
1725
1767
|
return {
|
|
1726
1768
|
$useMemo: canUseMemo,
|
|
@@ -1728,10 +1770,6 @@ function withMemo(canUseMemo, render) {
|
|
|
1728
1770
|
};
|
|
1729
1771
|
}
|
|
1730
1772
|
|
|
1731
|
-
const ElementNamespaceMap = {
|
|
1732
|
-
svg: 'svg',
|
|
1733
|
-
math: 'mathml',
|
|
1734
|
-
};
|
|
1735
1773
|
const listenerReg = /^on[A-Z]/;
|
|
1736
1774
|
function createRenderer(component, nativeRenderer, namespace) {
|
|
1737
1775
|
let isInit = true;
|
|
@@ -1782,7 +1820,7 @@ function buildElementChildren(atom, nativeRenderer, parentComponent, context) {
|
|
|
1782
1820
|
}
|
|
1783
1821
|
function patchComponent(nativeRenderer, component, oldChildAtom, newAtom, context, needMove) {
|
|
1784
1822
|
const newTemplate = component.rerender();
|
|
1785
|
-
newAtom.child = createChildChain(newTemplate, newAtom.namespace);
|
|
1823
|
+
newAtom.child = createChildChain(newTemplate, nativeRenderer, newAtom.namespace);
|
|
1786
1824
|
diff(nativeRenderer, component, newAtom.child, oldChildAtom, context, needMove);
|
|
1787
1825
|
}
|
|
1788
1826
|
function deepUpdateByComponentDirtyTree(nativeRenderer, component, needMove) {
|
|
@@ -2005,7 +2043,7 @@ function cleanChildren(atom, nativeRenderer, needClean) {
|
|
|
2005
2043
|
}
|
|
2006
2044
|
function componentRender(nativeRenderer, component, from, context) {
|
|
2007
2045
|
component.render((template, portalHost) => {
|
|
2008
|
-
from.child = createChildChain(template, from.namespace);
|
|
2046
|
+
from.child = createChildChain(template, nativeRenderer, from.namespace);
|
|
2009
2047
|
context = portalHost ? { isParent: true, host: portalHost, rootHost: portalHost } : context;
|
|
2010
2048
|
component.viewMetadata = Object.assign({ atom: from }, context);
|
|
2011
2049
|
let child = from.child;
|
|
@@ -2030,7 +2068,7 @@ function createChainByJSXNode(type, jsxNode, nodeType, prevAtom, namespace, key)
|
|
|
2030
2068
|
prevAtom.sibling = atom;
|
|
2031
2069
|
return atom;
|
|
2032
2070
|
}
|
|
2033
|
-
function createChainByNode(jsxNode, prevAtom, elementNamespace) {
|
|
2071
|
+
function createChainByNode(jsxNode, prevAtom, nativeRenderer, elementNamespace) {
|
|
2034
2072
|
const type = typeof jsxNode;
|
|
2035
2073
|
if (jsxNode != null && type !== 'boolean') {
|
|
2036
2074
|
if (type === 'string') {
|
|
@@ -2038,11 +2076,11 @@ function createChainByNode(jsxNode, prevAtom, elementNamespace) {
|
|
|
2038
2076
|
}
|
|
2039
2077
|
if (type === 'object') {
|
|
2040
2078
|
if (Array.isArray(jsxNode)) {
|
|
2041
|
-
return createChainByChildren(jsxNode, prevAtom, elementNamespace);
|
|
2079
|
+
return createChainByChildren(jsxNode, prevAtom, nativeRenderer, elementNamespace);
|
|
2042
2080
|
}
|
|
2043
2081
|
const nodeType = typeof jsxNode.type;
|
|
2044
2082
|
if (nodeType === 'string') {
|
|
2045
|
-
return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom,
|
|
2083
|
+
return createChainByJSXNode(ElementAtomType, jsxNode, jsxNode.type, prevAtom, nativeRenderer.getNameSpace(jsxNode.type, elementNamespace), jsxNode.key);
|
|
2046
2084
|
}
|
|
2047
2085
|
else if (nodeType === 'function') {
|
|
2048
2086
|
return createChainByJSXNode(ComponentAtomType, jsxNode, jsxNode.type, prevAtom, elementNamespace, jsxNode.key);
|
|
@@ -2053,17 +2091,17 @@ function createChainByNode(jsxNode, prevAtom, elementNamespace) {
|
|
|
2053
2091
|
}
|
|
2054
2092
|
return prevAtom;
|
|
2055
2093
|
}
|
|
2056
|
-
function createChainByChildren(children, prevAtom, elementNamespace) {
|
|
2094
|
+
function createChainByChildren(children, prevAtom, nativeRenderer, elementNamespace) {
|
|
2057
2095
|
const len = children.length;
|
|
2058
2096
|
for (let i = 0; i < len; i++) {
|
|
2059
2097
|
const item = children[i];
|
|
2060
|
-
prevAtom = createChainByNode(item, prevAtom, elementNamespace);
|
|
2098
|
+
prevAtom = createChainByNode(item, prevAtom, nativeRenderer, elementNamespace);
|
|
2061
2099
|
}
|
|
2062
2100
|
return prevAtom;
|
|
2063
2101
|
}
|
|
2064
|
-
function createChildChain(template, namespace) {
|
|
2102
|
+
function createChildChain(template, nativeRenderer, namespace) {
|
|
2065
2103
|
const beforeAtom = { sibling: null, index: -1 };
|
|
2066
|
-
createChainByNode(template, beforeAtom, namespace);
|
|
2104
|
+
createChainByNode(template, beforeAtom, nativeRenderer, namespace);
|
|
2067
2105
|
return beforeAtom.sibling;
|
|
2068
2106
|
}
|
|
2069
2107
|
function insertNode(nativeRenderer, atom, context) {
|
|
@@ -2079,11 +2117,9 @@ function insertNode(nativeRenderer, atom, context) {
|
|
|
2079
2117
|
nativeRenderer.insertAfter(atom.nativeNode, context.host, atom.namespace);
|
|
2080
2118
|
}
|
|
2081
2119
|
}
|
|
2082
|
-
function createElementChildren(type, children, namespace) {
|
|
2083
|
-
|
|
2084
|
-
|
|
2085
|
-
}
|
|
2086
|
-
return createChildChain(children, namespace);
|
|
2120
|
+
function createElementChildren(type, children, nativeRenderer, namespace) {
|
|
2121
|
+
const ns = nativeRenderer.getNameSpace(type, namespace);
|
|
2122
|
+
return createChildChain(children, nativeRenderer, ns);
|
|
2087
2123
|
}
|
|
2088
2124
|
function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
2089
2125
|
const { namespace, jsxNode } = atom;
|
|
@@ -2092,7 +2128,7 @@ function createElement(nativeRenderer, atom, parentComponent, context) {
|
|
|
2092
2128
|
let bindingRefs;
|
|
2093
2129
|
for (const key in props) {
|
|
2094
2130
|
if (key === 'children') {
|
|
2095
|
-
atom.child = createElementChildren(jsxNode.type, props.children, namespace);
|
|
2131
|
+
atom.child = createElementChildren(jsxNode.type, props.children, nativeRenderer, namespace);
|
|
2096
2132
|
continue;
|
|
2097
2133
|
}
|
|
2098
2134
|
if (key === 'class') {
|
|
@@ -2183,7 +2219,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
2183
2219
|
}, (key, value) => {
|
|
2184
2220
|
if (key === 'children') {
|
|
2185
2221
|
updatedChildren = true;
|
|
2186
|
-
newAtom.child = createElementChildren(newVNode.type, value, isSvg);
|
|
2222
|
+
newAtom.child = createElementChildren(newVNode.type, value, nativeRenderer, isSvg);
|
|
2187
2223
|
buildElementChildren(newAtom, nativeRenderer, parentComponent, context);
|
|
2188
2224
|
return;
|
|
2189
2225
|
}
|
|
@@ -2212,7 +2248,7 @@ function updateNativeNodeProperties(nativeRenderer, newAtom, oldAtom, parentComp
|
|
|
2212
2248
|
}, (key, newValue, oldValue) => {
|
|
2213
2249
|
if (key === 'children') {
|
|
2214
2250
|
updatedChildren = true;
|
|
2215
|
-
newAtom.child = createElementChildren(newVNode.type, newValue, isSvg);
|
|
2251
|
+
newAtom.child = createElementChildren(newVNode.type, newValue, nativeRenderer, isSvg);
|
|
2216
2252
|
if (!newAtom.child) {
|
|
2217
2253
|
cleanElementChildren(oldAtom, nativeRenderer);
|
|
2218
2254
|
}
|
|
@@ -2473,34 +2509,6 @@ function shallowReactive(raw) {
|
|
|
2473
2509
|
return proxy;
|
|
2474
2510
|
}
|
|
2475
2511
|
|
|
2476
|
-
function watch(trigger, callback) {
|
|
2477
|
-
let prevFn;
|
|
2478
|
-
const dep = new Dep(() => {
|
|
2479
|
-
pushDepContext(dep);
|
|
2480
|
-
const newValue = trigger();
|
|
2481
|
-
popDepContext();
|
|
2482
|
-
if (newValue === oldValue) {
|
|
2483
|
-
return;
|
|
2484
|
-
}
|
|
2485
|
-
if (prevFn) {
|
|
2486
|
-
prevFn();
|
|
2487
|
-
}
|
|
2488
|
-
prevFn = callback(newValue, oldValue);
|
|
2489
|
-
oldValue = newValue;
|
|
2490
|
-
});
|
|
2491
|
-
pushDepContext(dep);
|
|
2492
|
-
let oldValue = trigger();
|
|
2493
|
-
popDepContext();
|
|
2494
|
-
dep.destroyCallbacks.push(() => {
|
|
2495
|
-
prevFn === null || prevFn === void 0 ? void 0 : prevFn();
|
|
2496
|
-
});
|
|
2497
|
-
function unWatch() {
|
|
2498
|
-
dep.destroy();
|
|
2499
|
-
}
|
|
2500
|
-
registryComponentDestroyCallback(unWatch);
|
|
2501
|
-
return unWatch;
|
|
2502
|
-
}
|
|
2503
|
-
|
|
2504
2512
|
/**
|
|
2505
2513
|
* 组件状态管理器
|
|
2506
2514
|
* @param state 初始状态
|
|
@@ -2624,7 +2632,6 @@ exports.ArrayReactiveHandler = ArrayReactiveHandler;
|
|
|
2624
2632
|
exports.Component = Component;
|
|
2625
2633
|
exports.Dep = Dep;
|
|
2626
2634
|
exports.DynamicRef = DynamicRef;
|
|
2627
|
-
exports.ElementNamespaceMap = ElementNamespaceMap;
|
|
2628
2635
|
exports.ForwardRef = ForwardRef;
|
|
2629
2636
|
exports.Fragment = Fragment;
|
|
2630
2637
|
exports.Inject = Inject;
|
|
@@ -2650,6 +2657,7 @@ exports.Type = Type;
|
|
|
2650
2657
|
exports.comparePropsWithCallbacks = comparePropsWithCallbacks;
|
|
2651
2658
|
exports.computed = computed;
|
|
2652
2659
|
exports.createContext = createContext;
|
|
2660
|
+
exports.createContextProvider = createContextProvider;
|
|
2653
2661
|
exports.createDerived = createDerived;
|
|
2654
2662
|
exports.createDynamicRef = createDynamicRef;
|
|
2655
2663
|
exports.createEffect = createEffect;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@viewfly/core",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.7",
|
|
4
4
|
"description": "Viewfly is a simple and easy-to-use JavaScript framework with an intuitive development experience.",
|
|
5
5
|
"main": "./bundles/index.js",
|
|
6
6
|
"module": "./bundles/index.esm.js",
|
|
@@ -50,7 +50,7 @@
|
|
|
50
50
|
"bugs": {
|
|
51
51
|
"url": "https://github.com/viewfly/viewfly.git/issues"
|
|
52
52
|
},
|
|
53
|
-
"gitHead": "
|
|
53
|
+
"gitHead": "b66ca589f7662cd518fc2e5955b3e3ff9de83f94",
|
|
54
54
|
"dependencies": {
|
|
55
55
|
"reflect-metadata": "^0.2.2"
|
|
56
56
|
}
|