Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.
TypeScript boardcollaborationdocdocxexceloffce365officepdfpptpptxpresentationsdksheetslidesspreadsheetuniverwordwordprocessorworkspacexlsx
feat(core): add polyfills for Array.prototype.findLast and Array.prototype.findLastIndex (#5373)
白熱33afa8b92f6d
diff --git a/package.json b/package.jsonindex 719dc84ae1..9fbfd37e65 100644--- a/package.json+++ b/package.json@@ -25,7 +25,7 @@"scripts": {"prepare": "husky","pre-commit": "lint-staged",- "dev": "turbo dev:demo -- --host 0.0.0.0",+ "dev": "pnpm --filter univer-examples dev:demo -- --host 0.0.0.0","dev:libs": "pnpm --filter univer-examples dev:demo-libs","dev:e2e": "pnpm --filter univer-examples dev:e2e","use:react16": "tsx ./scripts/react-version-manager.ts --react=16",diff --git a/packages/core/src/common/shims.ts b/packages/core/src/common/shims.tsindex 45039f9f18..f0f8099a80 100644--- a/packages/core/src/common/shims.ts+++ b/packages/core/src/common/shims.ts@@ -16,6 +16,9 @@const glob = typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : window;+/**+ * Polyfill for requestIdleCallback and cancelIdleCallback+ */function installRequestIdleCallback() {const TIME_WINDOW = 50;@@ -54,6 +57,37 @@ function installRequestIdleCallback() {}}+/**+ * Polyfill for Array.prototype.findLastIndex and Array.prototype.findLast+ */+function installArrayFindLastIndex() {+ if (typeof glob.Array.prototype.findLastIndex !== 'function') {+ glob.Array.prototype.findLastIndex = function findLastIndex(callback: (value: any, index: number, array: any[]) => boolean, thisArg?: any): number {+ if (this == null) {+ throw new TypeError('Array.prototype.findLastIndex called on null or undefined');+ }+ if (typeof callback !== 'function') {+ throw new TypeError('callback must be a function');+ }++ const len = this.length >>> 0;+ for (let i = len - 1; i >= 0; i--) {+ if (i in this && callback.call(thisArg, this[i], i, this)) {+ return i;+ }+ }+ return -1;+ };+ }+ if (typeof glob.Array.prototype.findLast !== 'function') {+ glob.Array.prototype.findLast = function findLast(callback: (value: any, index: number, array: any[]) => boolean, thisArg?: any): any {+ const index = this.findLastIndex(callback, thisArg);+ return index !== -1 ? this[index] : undefined;+ };+ }+}+export function installShims() {installRequestIdleCallback();+ installArrayFindLastIndex();}diff --git a/turbo.json b/turbo.jsonindex 38862ca6e1..056c67f4f0 100644--- a/turbo.json+++ b/turbo.json@@ -16,10 +16,6 @@"build:e2e": {},- "dev:demo": {- "cache": false- },-"lint:types": {}}}