@rectify-dev/core 2.0.3 → 2.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +70 -39
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -2
- package/dist/index.d.ts +7 -2
- package/dist/index.js +70 -40
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RectifyNode, FC, Fiber } from '@rectify-dev/shared';
|
|
2
|
-
export { AnchorHTMLAttributes, AriaAttributes, AudioHTMLAttributes, ButtonHTMLAttributes, CSSProperties, FC, FormHTMLAttributes, HTMLAttributes, IframeHTMLAttributes, ImgHTMLAttributes, InputHTMLAttributes, LabelHTMLAttributes, MetaHTMLAttributes, OptGroupHTMLAttributes, OptionHTMLAttributes, RectifyEventHandlers, RectifyIntrinsicElements, ScriptHTMLAttributes, SelectHTMLAttributes, SyntheticAnimationEvent, SyntheticChangeEvent, SyntheticClipboardEvent, SyntheticDragEvent, SyntheticEvent as SyntheticEventType, SyntheticFocusEvent, SyntheticInputEvent, SyntheticKeyboardEvent, SyntheticMouseEvent, SyntheticPointerEvent, SyntheticSubmitEvent, SyntheticTouchEvent, SyntheticTransitionEvent, SyntheticWheelEvent, TextareaHTMLAttributes, VideoHTMLAttributes } from '@rectify-dev/shared';
|
|
2
|
+
export { AnchorHTMLAttributes, AriaAttributes, AudioHTMLAttributes, ButtonHTMLAttributes, CSSProperties, FC, FormHTMLAttributes, HTMLAttributes, IframeHTMLAttributes, ImgHTMLAttributes, InputHTMLAttributes, LabelHTMLAttributes, MetaHTMLAttributes, OptGroupHTMLAttributes, OptionHTMLAttributes, RectifyEventHandlers, RectifyIntrinsicElements, RectifyNode, ScriptHTMLAttributes, SelectHTMLAttributes, SyntheticAnimationEvent, SyntheticChangeEvent, SyntheticClipboardEvent, SyntheticDragEvent, SyntheticEvent as SyntheticEventType, SyntheticFocusEvent, SyntheticInputEvent, SyntheticKeyboardEvent, SyntheticMouseEvent, SyntheticPointerEvent, SyntheticSubmitEvent, SyntheticTouchEvent, SyntheticTransitionEvent, SyntheticWheelEvent, TextareaHTMLAttributes, VideoHTMLAttributes } from '@rectify-dev/shared';
|
|
3
3
|
export { Fragment, jsx } from './runtime.cjs';
|
|
4
4
|
|
|
5
5
|
type RectifyDomRoot = {
|
|
@@ -51,6 +51,11 @@ declare function useState<S>(): [S | undefined, StateDispatcher<S | undefined>];
|
|
|
51
51
|
declare function useState<S>(initialState: S): [S, StateDispatcher<S>];
|
|
52
52
|
declare function useState<S>(initialState: () => S): [S, StateDispatcher<S>];
|
|
53
53
|
|
|
54
|
+
type Reducer<S, A> = (state: S, action: A) => S;
|
|
55
|
+
type Dispatch<A> = (action: A) => void;
|
|
56
|
+
declare function useReducer<S, A>(reducer: Reducer<S, A>, initialState: S): [S, Dispatch<A>];
|
|
57
|
+
declare function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I, init: (arg: I) => S): [S, Dispatch<A>];
|
|
58
|
+
|
|
54
59
|
declare function useEffect(create: () => void | (() => void), deps?: any[]): void;
|
|
55
60
|
|
|
56
61
|
/**
|
|
@@ -157,4 +162,4 @@ declare function createContext<T>(defaultValue: T): RectifyContext<T>;
|
|
|
157
162
|
*/
|
|
158
163
|
declare function useContext<T>(context: RectifyContext<T>): T;
|
|
159
164
|
|
|
160
|
-
export { type MemoComponent, type RectifyContext, type RefObject, SyntheticEvent, createContext, createRoot, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState };
|
|
165
|
+
export { type Dispatch, type MemoComponent, type RectifyContext, type Reducer, type RefObject, SyntheticEvent, createContext, createRoot, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { RectifyNode, FC, Fiber } from '@rectify-dev/shared';
|
|
2
|
-
export { AnchorHTMLAttributes, AriaAttributes, AudioHTMLAttributes, ButtonHTMLAttributes, CSSProperties, FC, FormHTMLAttributes, HTMLAttributes, IframeHTMLAttributes, ImgHTMLAttributes, InputHTMLAttributes, LabelHTMLAttributes, MetaHTMLAttributes, OptGroupHTMLAttributes, OptionHTMLAttributes, RectifyEventHandlers, RectifyIntrinsicElements, ScriptHTMLAttributes, SelectHTMLAttributes, SyntheticAnimationEvent, SyntheticChangeEvent, SyntheticClipboardEvent, SyntheticDragEvent, SyntheticEvent as SyntheticEventType, SyntheticFocusEvent, SyntheticInputEvent, SyntheticKeyboardEvent, SyntheticMouseEvent, SyntheticPointerEvent, SyntheticSubmitEvent, SyntheticTouchEvent, SyntheticTransitionEvent, SyntheticWheelEvent, TextareaHTMLAttributes, VideoHTMLAttributes } from '@rectify-dev/shared';
|
|
2
|
+
export { AnchorHTMLAttributes, AriaAttributes, AudioHTMLAttributes, ButtonHTMLAttributes, CSSProperties, FC, FormHTMLAttributes, HTMLAttributes, IframeHTMLAttributes, ImgHTMLAttributes, InputHTMLAttributes, LabelHTMLAttributes, MetaHTMLAttributes, OptGroupHTMLAttributes, OptionHTMLAttributes, RectifyEventHandlers, RectifyIntrinsicElements, RectifyNode, ScriptHTMLAttributes, SelectHTMLAttributes, SyntheticAnimationEvent, SyntheticChangeEvent, SyntheticClipboardEvent, SyntheticDragEvent, SyntheticEvent as SyntheticEventType, SyntheticFocusEvent, SyntheticInputEvent, SyntheticKeyboardEvent, SyntheticMouseEvent, SyntheticPointerEvent, SyntheticSubmitEvent, SyntheticTouchEvent, SyntheticTransitionEvent, SyntheticWheelEvent, TextareaHTMLAttributes, VideoHTMLAttributes } from '@rectify-dev/shared';
|
|
3
3
|
export { Fragment, jsx } from './runtime.js';
|
|
4
4
|
|
|
5
5
|
type RectifyDomRoot = {
|
|
@@ -51,6 +51,11 @@ declare function useState<S>(): [S | undefined, StateDispatcher<S | undefined>];
|
|
|
51
51
|
declare function useState<S>(initialState: S): [S, StateDispatcher<S>];
|
|
52
52
|
declare function useState<S>(initialState: () => S): [S, StateDispatcher<S>];
|
|
53
53
|
|
|
54
|
+
type Reducer<S, A> = (state: S, action: A) => S;
|
|
55
|
+
type Dispatch<A> = (action: A) => void;
|
|
56
|
+
declare function useReducer<S, A>(reducer: Reducer<S, A>, initialState: S): [S, Dispatch<A>];
|
|
57
|
+
declare function useReducer<S, A, I>(reducer: Reducer<S, A>, initialArg: I, init: (arg: I) => S): [S, Dispatch<A>];
|
|
58
|
+
|
|
54
59
|
declare function useEffect(create: () => void | (() => void), deps?: any[]): void;
|
|
55
60
|
|
|
56
61
|
/**
|
|
@@ -157,4 +162,4 @@ declare function createContext<T>(defaultValue: T): RectifyContext<T>;
|
|
|
157
162
|
*/
|
|
158
163
|
declare function useContext<T>(context: RectifyContext<T>): T;
|
|
159
164
|
|
|
160
|
-
export { type MemoComponent, type RectifyContext, type RefObject, SyntheticEvent, createContext, createRoot, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useRef, useState };
|
|
165
|
+
export { type Dispatch, type MemoComponent, type RectifyContext, type Reducer, type RefObject, SyntheticEvent, createContext, createRoot, memo, useCallback, useContext, useEffect, useLayoutEffect, useMemo, useReducer, useRef, useState };
|
package/dist/index.js
CHANGED
|
@@ -246,6 +246,7 @@ var PlacementFlag = 1 << 0;
|
|
|
246
246
|
var UpdateFlag = 1 << 1;
|
|
247
247
|
var DeletionFlag = 1 << 2;
|
|
248
248
|
var MoveFlag = 1 << 3;
|
|
249
|
+
var RefFlag = 1 << 4;
|
|
249
250
|
|
|
250
251
|
// ../rectify-reconciler/src/RectifyFiberLanes.ts
|
|
251
252
|
var NoLanes = 0;
|
|
@@ -366,7 +367,8 @@ var createFiber = /* @__PURE__ */ __name((workTag, pendingProps, key = null) =>
|
|
|
366
367
|
childLanes: NoLanes,
|
|
367
368
|
subtreeFlags: NoFlags,
|
|
368
369
|
flags: NoFlags,
|
|
369
|
-
memoizedState: null
|
|
370
|
+
memoizedState: null,
|
|
371
|
+
refCleanup: null
|
|
370
372
|
};
|
|
371
373
|
}, "createFiber");
|
|
372
374
|
var createHostRootFiber = /* @__PURE__ */ __name((containerDom) => {
|
|
@@ -393,6 +395,7 @@ var createWorkInProgress = /* @__PURE__ */ __name((current, pendingProps) => {
|
|
|
393
395
|
}
|
|
394
396
|
wip.memoizedProps = current.memoizedProps;
|
|
395
397
|
wip.memoizedState = current.memoizedState;
|
|
398
|
+
wip.refCleanup = current.refCleanup;
|
|
396
399
|
wip.return = current.return;
|
|
397
400
|
wip.child = current.child;
|
|
398
401
|
wip.sibling = current.sibling;
|
|
@@ -481,23 +484,14 @@ function useState(initialState) {
|
|
|
481
484
|
}
|
|
482
485
|
const hookIndex = getHookIndex();
|
|
483
486
|
nextHookIndex();
|
|
484
|
-
let state = fiber
|
|
485
|
-
let prevHook = null;
|
|
486
|
-
for (let i = 0; i < hookIndex; i++) {
|
|
487
|
-
prevHook = state;
|
|
488
|
-
state = state?.next ?? null;
|
|
489
|
-
}
|
|
487
|
+
let { hook: state, prevHook } = getHookSlot(fiber, hookIndex);
|
|
490
488
|
if (!state) {
|
|
491
489
|
state = {
|
|
492
490
|
memoizedState: getInitialState(initialState),
|
|
493
491
|
queue: null,
|
|
494
492
|
next: null
|
|
495
493
|
};
|
|
496
|
-
|
|
497
|
-
prevHook.next = state;
|
|
498
|
-
} else {
|
|
499
|
-
fiber.memoizedState = state;
|
|
500
|
-
}
|
|
494
|
+
attachHook(fiber, state, prevHook);
|
|
501
495
|
}
|
|
502
496
|
let update = state.queue;
|
|
503
497
|
while (update) {
|
|
@@ -522,6 +516,42 @@ function useState(initialState) {
|
|
|
522
516
|
}
|
|
523
517
|
__name(useState, "useState");
|
|
524
518
|
var RectifyHookUseState_default = useState;
|
|
519
|
+
function useReducer(reducer, initialArg, init) {
|
|
520
|
+
const fiber = getFiberRendering();
|
|
521
|
+
if (!fiber) {
|
|
522
|
+
throw new Error("useReducer must be used within a function component.");
|
|
523
|
+
}
|
|
524
|
+
const hookIndex = getHookIndex();
|
|
525
|
+
nextHookIndex();
|
|
526
|
+
let { hook, prevHook } = getHookSlot(fiber, hookIndex);
|
|
527
|
+
if (!hook) {
|
|
528
|
+
const initialState = isFunction(init) ? init(initialArg) : initialArg;
|
|
529
|
+
hook = { memoizedState: initialState, queue: null, next: null };
|
|
530
|
+
attachHook(fiber, hook, prevHook);
|
|
531
|
+
}
|
|
532
|
+
let update = hook.queue;
|
|
533
|
+
while (update) {
|
|
534
|
+
hook.memoizedState = reducer(hook.memoizedState, update.action);
|
|
535
|
+
update = update.next;
|
|
536
|
+
}
|
|
537
|
+
hook.queue = null;
|
|
538
|
+
const dispatch = /* @__PURE__ */ __name((action) => {
|
|
539
|
+
const update2 = { action, next: null };
|
|
540
|
+
if (!hook.queue) {
|
|
541
|
+
hook.queue = update2;
|
|
542
|
+
} else {
|
|
543
|
+
let last = hook.queue;
|
|
544
|
+
while (last.next) {
|
|
545
|
+
last = last.next;
|
|
546
|
+
}
|
|
547
|
+
last.next = update2;
|
|
548
|
+
}
|
|
549
|
+
scheduleRerender(fiber);
|
|
550
|
+
}, "dispatch");
|
|
551
|
+
return [hook.memoizedState, dispatch];
|
|
552
|
+
}
|
|
553
|
+
__name(useReducer, "useReducer");
|
|
554
|
+
var RectifyHookUseReducer_default = useReducer;
|
|
525
555
|
|
|
526
556
|
// ../rectify-hook/src/RectifyHookDeps.ts
|
|
527
557
|
var depsChanged = /* @__PURE__ */ __name((prev, next) => {
|
|
@@ -632,20 +662,11 @@ function useRef(initialValue) {
|
|
|
632
662
|
}
|
|
633
663
|
const hookIndex = getHookIndex();
|
|
634
664
|
nextHookIndex();
|
|
635
|
-
|
|
636
|
-
let prevHook = null;
|
|
637
|
-
for (let i = 0; i < hookIndex; i++) {
|
|
638
|
-
prevHook = hook;
|
|
639
|
-
hook = hook?.next ?? null;
|
|
640
|
-
}
|
|
665
|
+
const { hook, prevHook } = getHookSlot(fiber, hookIndex);
|
|
641
666
|
if (!hook) {
|
|
642
667
|
const ref = { current: initialValue };
|
|
643
668
|
const newHook = { memoizedState: ref, queue: null, next: null };
|
|
644
|
-
|
|
645
|
-
prevHook.next = newHook;
|
|
646
|
-
} else {
|
|
647
|
-
fiber.memoizedState = newHook;
|
|
648
|
-
}
|
|
669
|
+
attachHook(fiber, newHook, prevHook);
|
|
649
670
|
return ref;
|
|
650
671
|
}
|
|
651
672
|
return hook.memoizedState;
|
|
@@ -661,20 +682,10 @@ function useMemo(factory, deps) {
|
|
|
661
682
|
}
|
|
662
683
|
const hookIndex = getHookIndex();
|
|
663
684
|
nextHookIndex();
|
|
664
|
-
|
|
665
|
-
let prevHook = null;
|
|
666
|
-
for (let i = 0; i < hookIndex; i++) {
|
|
667
|
-
prevHook = hook;
|
|
668
|
-
hook = hook?.next ?? null;
|
|
669
|
-
}
|
|
685
|
+
const { hook, prevHook } = getHookSlot(fiber, hookIndex);
|
|
670
686
|
if (!hook) {
|
|
671
687
|
const state = { value: factory(), deps };
|
|
672
|
-
|
|
673
|
-
if (prevHook) {
|
|
674
|
-
prevHook.next = newHook;
|
|
675
|
-
} else {
|
|
676
|
-
fiber.memoizedState = newHook;
|
|
677
|
-
}
|
|
688
|
+
attachHook(fiber, { memoizedState: state, queue: null, next: null }, prevHook);
|
|
678
689
|
return state.value;
|
|
679
690
|
}
|
|
680
691
|
const prev = hook.memoizedState;
|
|
@@ -1043,6 +1054,9 @@ var reuseOrCreate = /* @__PURE__ */ __name((oldFiber, element, wip) => {
|
|
|
1043
1054
|
if (hasPropsChanged(oldFiber.memoizedProps, element.props)) {
|
|
1044
1055
|
addFlagToFiber(newFiber, UpdateFlag);
|
|
1045
1056
|
}
|
|
1057
|
+
if ((oldFiber.memoizedProps?.ref ?? null) !== (element.props?.ref ?? null)) {
|
|
1058
|
+
addFlagToFiber(newFiber, RefFlag);
|
|
1059
|
+
}
|
|
1046
1060
|
newFiber.return = wip;
|
|
1047
1061
|
return newFiber;
|
|
1048
1062
|
}, "reuseOrCreate");
|
|
@@ -1140,7 +1154,7 @@ var reconcileChildren = /* @__PURE__ */ __name((wip, children) => {
|
|
|
1140
1154
|
}, "reconcileChildren");
|
|
1141
1155
|
|
|
1142
1156
|
// ../rectify-reconciler/src/RectifyFiberCommitWork.ts
|
|
1143
|
-
var MutationMask = PlacementFlag | UpdateFlag | MoveFlag;
|
|
1157
|
+
var MutationMask = PlacementFlag | UpdateFlag | MoveFlag | RefFlag;
|
|
1144
1158
|
var commitWork = /* @__PURE__ */ __name((finishedWork) => {
|
|
1145
1159
|
if (finishedWork.deletions?.length) {
|
|
1146
1160
|
finishedWork.deletions.forEach(removeHostTree);
|
|
@@ -1165,13 +1179,25 @@ var syncMemoizedProps = /* @__PURE__ */ __name((wip) => {
|
|
|
1165
1179
|
}, "syncMemoizedProps");
|
|
1166
1180
|
var attachRef = /* @__PURE__ */ __name((wip) => {
|
|
1167
1181
|
const ref = wip.pendingProps?.ref;
|
|
1168
|
-
if (ref
|
|
1182
|
+
if (!ref) return;
|
|
1183
|
+
if (typeof ref === "function") {
|
|
1184
|
+
const cleanup = ref(wip.stateNode);
|
|
1185
|
+
wip.refCleanup = typeof cleanup === "function" ? cleanup : null;
|
|
1186
|
+
} else if (typeof ref === "object" && "current" in ref) {
|
|
1169
1187
|
ref.current = wip.stateNode;
|
|
1170
1188
|
}
|
|
1171
1189
|
}, "attachRef");
|
|
1172
1190
|
var detachRef = /* @__PURE__ */ __name((fiber) => {
|
|
1191
|
+
if (fiber.refCleanup) {
|
|
1192
|
+
fiber.refCleanup();
|
|
1193
|
+
fiber.refCleanup = null;
|
|
1194
|
+
return;
|
|
1195
|
+
}
|
|
1173
1196
|
const ref = fiber.memoizedProps?.ref;
|
|
1174
|
-
if (ref
|
|
1197
|
+
if (!ref) return;
|
|
1198
|
+
if (typeof ref === "function") {
|
|
1199
|
+
ref(null);
|
|
1200
|
+
} else if (typeof ref === "object" && "current" in ref) {
|
|
1175
1201
|
ref.current = null;
|
|
1176
1202
|
}
|
|
1177
1203
|
}, "detachRef");
|
|
@@ -1215,9 +1241,13 @@ var commitMutationHostComponent = /* @__PURE__ */ __name((wip) => {
|
|
|
1215
1241
|
if (hasFlagOnFiber(wip, UpdateFlag)) {
|
|
1216
1242
|
applyPropsToDom(wip.stateNode, wip.memoizedProps, wip.pendingProps);
|
|
1217
1243
|
precacheFiberNode(wip, wip.stateNode);
|
|
1218
|
-
attachRef(wip);
|
|
1219
1244
|
removeFlagFromFiber(wip, UpdateFlag);
|
|
1220
1245
|
}
|
|
1246
|
+
if (hasFlagOnFiber(wip, RefFlag)) {
|
|
1247
|
+
detachRef(wip);
|
|
1248
|
+
attachRef(wip);
|
|
1249
|
+
removeFlagFromFiber(wip, RefFlag);
|
|
1250
|
+
}
|
|
1221
1251
|
}, "commitMutationHostComponent");
|
|
1222
1252
|
var commitMutationHostText = /* @__PURE__ */ __name((wip) => {
|
|
1223
1253
|
if (!wip.stateNode) {
|
|
@@ -1417,6 +1447,6 @@ function memo(Component, compare) {
|
|
|
1417
1447
|
}
|
|
1418
1448
|
__name(memo, "memo");
|
|
1419
1449
|
|
|
1420
|
-
export { SyntheticEvent_default as SyntheticEvent, createContext, createRoot, memo, RectifyHookUseCallback_default as useCallback, useContext, RectifyHookUseEffect_default as useEffect, RectifyHookUseLayoutEffect_default as useLayoutEffect, RectifyHookUseMemo_default as useMemo, RectifyHookUseRef_default as useRef, RectifyHookUseState_default as useState };
|
|
1450
|
+
export { SyntheticEvent_default as SyntheticEvent, createContext, createRoot, memo, RectifyHookUseCallback_default as useCallback, useContext, RectifyHookUseEffect_default as useEffect, RectifyHookUseLayoutEffect_default as useLayoutEffect, RectifyHookUseMemo_default as useMemo, RectifyHookUseReducer_default as useReducer, RectifyHookUseRef_default as useRef, RectifyHookUseState_default as useState };
|
|
1421
1451
|
//# sourceMappingURL=index.js.map
|
|
1422
1452
|
//# sourceMappingURL=index.js.map
|