Skip to content

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.

fix(sheet): move function to a file and export (#3125)

VicKun8483725c38dc
diff --git a/packages/core/src/common/mixin.ts b/packages/core/src/common/mixin.ts
new file mode 100644
index 0000000000..151b228f7b
--- /dev/null
+++ b/packages/core/src/common/mixin.ts
@@ -0,0 +1,35 @@
+/**
+ * Copyright 2023-present DreamNum Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+interface IMixinProperty<T> {
+ // eslint-disable-next-line ts/no-explicit-any
+ [fnName: string]: (this: T, ...args: any[]) => any;
+}
+
+/**
+ * Mixin some methods to targetObject as prototype, the static methods will not be mixed in
+ * @param {T} targetClass The target class to mixin
+ * @param {IMixinProperty<T>} mixin The mixin object which contains the methods to mixin.
+ */
+export function mixinClass<T>(targetClass: T, mixin: IMixinProperty<T>): void {
+ for (const key in mixin) {
+ // eslint-disable-next-line no-prototype-builtins
+ if (mixin.hasOwnProperty(key)) {
+ // @ts-ignore
+ targetClass.prototype[key] = mixin[key];
+ }
+ }
+}
diff --git a/packages/core/src/index.ts b/packages/core/src/index.ts
index 9b59de6021..c5a232b055 100644
--- a/packages/core/src/index.ts
+++ b/packages/core/src/index.ts
@@ -198,5 +198,6 @@ export { normalizeBody, getCustomRangeSlice, getCustomDecorationSlice } from './
export { updateAttributeByDelete } from './docs/data-model/text-x/apply-utils/delete-apply';
export { updateAttributeByInsert } from './docs/data-model/text-x/apply-utils/insert-apply';
export { nameCharacterCheck } from './shared/name';
+export { mixinClass } from './common/mixin';
export * from './common/di';