This commit is contained in:
2026-05-25 17:08:18 +08:00
parent df501f6151
commit f1259b71b5
9178 changed files with 1626125 additions and 0 deletions
+21
View File
@@ -0,0 +1,21 @@
/// <reference types="react" />
export declare const STATUS_ADD: "add";
export declare const STATUS_KEEP: "keep";
export declare const STATUS_REMOVE: "remove";
export declare const STATUS_REMOVED: "removed";
export type DiffStatus = typeof STATUS_ADD | typeof STATUS_KEEP | typeof STATUS_REMOVE | typeof STATUS_REMOVED;
type RawKeyType = string | number;
export interface KeyObject {
key: RawKeyType;
status?: DiffStatus;
}
export declare function wrapKeyToObject(key: React.Key | KeyObject): {
key: string;
status?: DiffStatus;
};
export declare function parseKeys(keys?: any[]): {
key: string;
status?: DiffStatus;
}[];
export declare function diffKeys(prevKeys?: KeyObject[], currentKeys?: KeyObject[]): KeyObject[];
export {};
+106
View File
@@ -0,0 +1,106 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.STATUS_REMOVED = exports.STATUS_REMOVE = exports.STATUS_KEEP = exports.STATUS_ADD = void 0;
exports.diffKeys = diffKeys;
exports.parseKeys = parseKeys;
exports.wrapKeyToObject = wrapKeyToObject;
const STATUS_ADD = exports.STATUS_ADD = 'add';
const STATUS_KEEP = exports.STATUS_KEEP = 'keep';
const STATUS_REMOVE = exports.STATUS_REMOVE = 'remove';
const STATUS_REMOVED = exports.STATUS_REMOVED = 'removed';
function wrapKeyToObject(key) {
let keyObj;
if (key && typeof key === 'object' && 'key' in key) {
keyObj = key;
} else {
keyObj = {
key: key
};
}
return {
...keyObj,
key: String(keyObj.key)
};
}
function parseKeys(keys = []) {
return keys.map(wrapKeyToObject);
}
function diffKeys(prevKeys = [], currentKeys = []) {
let list = [];
let currentIndex = 0;
const currentLen = currentKeys.length;
const prevKeyObjects = parseKeys(prevKeys);
const currentKeyObjects = parseKeys(currentKeys);
// Check prev keys to insert or keep
prevKeyObjects.forEach(keyObj => {
let hit = false;
for (let i = currentIndex; i < currentLen; i += 1) {
const currentKeyObj = currentKeyObjects[i];
if (currentKeyObj.key === keyObj.key) {
// New added keys should add before current key
if (currentIndex < i) {
list = list.concat(currentKeyObjects.slice(currentIndex, i).map(obj => ({
...obj,
status: STATUS_ADD
})));
currentIndex = i;
}
list.push({
...currentKeyObj,
status: STATUS_KEEP
});
currentIndex += 1;
hit = true;
break;
}
}
// If not hit, it means key is removed
if (!hit) {
list.push({
...keyObj,
status: STATUS_REMOVE
});
}
});
// Add rest to the list
if (currentIndex < currentLen) {
list = list.concat(currentKeyObjects.slice(currentIndex).map(obj => ({
...obj,
status: STATUS_ADD
})));
}
/**
* Merge same key when it remove and add again:
* [1 - add, 2 - keep, 1 - remove] -> [1 - keep, 2 - keep]
*/
const keys = {};
list.forEach(({
key
}) => {
keys[key] = (keys[key] || 0) + 1;
});
const duplicatedKeys = Object.keys(keys).filter(key => keys[key] > 1);
duplicatedKeys.forEach(matchKey => {
// Remove `STATUS_REMOVE` node.
list = list.filter(({
key,
status
}) => key !== matchKey || status !== STATUS_REMOVE);
// Update `STATUS_ADD` to `STATUS_KEEP`
list.forEach(node => {
if (node.key === matchKey) {
// eslint-disable-next-line no-param-reassign
node.status = STATUS_KEEP;
}
});
});
return list;
}
+10
View File
@@ -0,0 +1,10 @@
import type { MotionName } from '../CSSMotion';
export declare function getVendorPrefixes(domSupport: boolean, win: object): {
animationend: Record<string, string>;
transitionend: Record<string, string>;
};
export declare function getVendorPrefixedEventName(eventName: string): any;
export declare const supportTransition: boolean;
export declare const animationEndName: any;
export declare const transitionEndName: any;
export declare function getTransitionName(transitionName: MotionName, transitionType: string): any;
+77
View File
@@ -0,0 +1,77 @@
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.animationEndName = void 0;
exports.getTransitionName = getTransitionName;
exports.getVendorPrefixedEventName = getVendorPrefixedEventName;
exports.getVendorPrefixes = getVendorPrefixes;
exports.transitionEndName = exports.supportTransition = void 0;
var _canUseDom = _interopRequireDefault(require("@rc-component/util/lib/Dom/canUseDom"));
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
// ================= Transition =================
// Event wrapper. Copy from react source code
function makePrefixMap(styleProp, eventName) {
const prefixes = {};
prefixes[styleProp.toLowerCase()] = eventName.toLowerCase();
prefixes[`Webkit${styleProp}`] = `webkit${eventName}`;
prefixes[`Moz${styleProp}`] = `moz${eventName}`;
prefixes[`ms${styleProp}`] = `MS${eventName}`;
prefixes[`O${styleProp}`] = `o${eventName.toLowerCase()}`;
return prefixes;
}
function getVendorPrefixes(domSupport, win) {
const prefixes = {
animationend: makePrefixMap('Animation', 'AnimationEnd'),
transitionend: makePrefixMap('Transition', 'TransitionEnd')
};
if (domSupport) {
if (!('AnimationEvent' in win)) {
delete prefixes.animationend.animation;
}
if (!('TransitionEvent' in win)) {
delete prefixes.transitionend.transition;
}
}
return prefixes;
}
const vendorPrefixes = getVendorPrefixes((0, _canUseDom.default)(), typeof window !== 'undefined' ? window : {});
let style = {};
if ((0, _canUseDom.default)()) {
({
style
} = document.createElement('div'));
}
const prefixedEventNames = {};
function getVendorPrefixedEventName(eventName) {
if (prefixedEventNames[eventName]) {
return prefixedEventNames[eventName];
}
const prefixMap = vendorPrefixes[eventName];
if (prefixMap) {
const stylePropList = Object.keys(prefixMap);
const len = stylePropList.length;
for (let i = 0; i < len; i += 1) {
const styleProp = stylePropList[i];
if (Object.prototype.hasOwnProperty.call(prefixMap, styleProp) && styleProp in style) {
prefixedEventNames[eventName] = prefixMap[styleProp];
return prefixedEventNames[eventName];
}
}
}
return '';
}
const internalAnimationEndName = getVendorPrefixedEventName('animationend');
const internalTransitionEndName = getVendorPrefixedEventName('transitionend');
const supportTransition = exports.supportTransition = !!(internalAnimationEndName && internalTransitionEndName);
const animationEndName = exports.animationEndName = internalAnimationEndName || 'animationend';
const transitionEndName = exports.transitionEndName = internalTransitionEndName || 'transitionend';
function getTransitionName(transitionName, transitionType) {
if (!transitionName) return null;
if (typeof transitionName === 'object') {
const type = transitionType.replace(/-\w/g, match => match[1].toUpperCase());
return transitionName[type];
}
return `${transitionName}-${transitionType}`;
}