Skip to content

Commit

Permalink
fix: fix type and circular dep
Browse files Browse the repository at this point in the history
  • Loading branch information
wzhudev committed Oct 14, 2024
1 parent 64aced9 commit ad29a04
Show file tree
Hide file tree
Showing 11 changed files with 99 additions and 56 deletions.
2 changes: 1 addition & 1 deletion examples-node/src/cases/basic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import process from 'node:process';
import { awaitTime, FUniver } from '@univerjs/core';
import { createUniverOnNode } from '../sdk';

import '@univerjs/sheets/facade';
import '../sdk/facade';

// From now on, Univer is a full-stack SDK.

Expand Down
24 changes: 24 additions & 0 deletions examples-node/src/sdk/facade.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/**
* 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.
*/

// Facade API here are part of packages/facade/src/apis/everything.ts
// However some plugins are implemented incorrectly, so they are not included here.

import '@univerjs/sheets/facade';
import '@univerjs/sheets-data-validation/facade';
import '@univerjs/engine-formula/facade';
import '@univerjs/sheets-filter/facade';
import '@univerjs/sheets-formula/facade';
2 changes: 1 addition & 1 deletion packages-experimental/action-recorder/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"@univerjs/design": "workspace:*",
"@univerjs/icons": "^0.1.79",
"@univerjs/sheets": "workspace:*",
"@univerjs/sheets-filter-ui": "workspace:*",
"@univerjs/sheets-filter": "workspace:*",
"@univerjs/sheets-ui": "workspace:*",
"@univerjs/ui": "workspace:*",
"clsx": "^2.1.1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { AddWorksheetMergeAllCommand,
AddWorksheetMergeCommand,
AddWorksheetMergeHorizontalCommand,
AddWorksheetMergeVerticalCommand,
CancelFrozenCommand,
CopySheetCommand,
DeleteRangeMoveLeftCommand,
DeleteRangeMoveUpCommand,
Expand All @@ -31,7 +32,6 @@ import { AddWorksheetMergeAllCommand,
InsertRowBeforeCommand,
InsertSheetCommand,
RemoveSheetCommand,
SetFrozenCancelCommand,
SetFrozenCommand,
SetHorizontalTextAlignCommand,
SetOverlineCommand,
Expand All @@ -47,7 +47,7 @@ import { AddWorksheetMergeAllCommand,
SetWorksheetActivateCommand,
SetWorksheetActiveOperation,
} from '@univerjs/sheets';
import { RemoveSheetFilterCommand, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand } from '@univerjs/sheets-filter-ui';
import { RemoveSheetFilterCommand, SetSheetFilterRangeCommand, SetSheetsFilterCriteriaCommand } from '@univerjs/sheets-filter';
import { SetRangeBoldCommand,
SetRangeFontFamilyCommand,
SetRangeFontSizeCommand,
Expand Down Expand Up @@ -142,8 +142,8 @@ export class ActionRecorderController extends Disposable {
// SetBoldCommand,
// SetFontFamilyCommand,
// SetFontSizeCommand,
SetFrozenCancelCommand,
SetFrozenCommand,
CancelFrozenCommand,
SetHorizontalTextAlignCommand,
// SetItalicCommand,
SetOverlineCommand,
Expand Down
53 changes: 53 additions & 0 deletions packages/core/src/facade/f-base.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/**
* 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.
*/

/**
* `FBase` is a base class for all facade classes.
* It provides a way to extend classes with static and instance methods.
* The `_initialize` as a special method that will be called after the constructor. You should never call it directly.
*/
export abstract class FBase {
private static _constructorQueue: Array<() => void> = [];

constructor() {
FBase._constructorQueue.forEach((fn) => {
fn();
});
}

_initialize() { }

static extend(source: any): void {
Object.getOwnPropertyNames(source.prototype).forEach((name) => {
if (name === '_initialize') {
FBase._constructorQueue.push(
source.prototype._initialize.bind(this)
);
} else if (name !== 'constructor') {
// @ts-ignore
this.prototype[name] = source.prototype[name];
}
});

Object.getOwnPropertyNames(source).forEach((name) => {
if (name !== 'prototype' && name !== 'name' && name !== 'length') {
// @ts-ignore
this[name] = source[name];
}
});
}
}

2 changes: 1 addition & 1 deletion packages/core/src/facade/f-hooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import { LifecycleStages } from '../services/lifecycle/lifecycle';
import { LifecycleService } from '../services/lifecycle/lifecycle.service';
import { IUndoRedoService, RedoCommand, UndoCommand } from '../services/undoredo/undoredo.service';
import { toDisposable } from '../shared/lifecycle';
import { FBase } from './f-univer';
import { FBase } from './f-base';

export class FHooks extends FBase {
constructor(
Expand Down
38 changes: 1 addition & 37 deletions packages/core/src/facade/f-univer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,45 +23,9 @@ import { IUniverInstanceService } from '../services/instance/instance.service';
import { LifecycleService } from '../services/lifecycle/lifecycle.service';
import { RedoCommand, UndoCommand } from '../services/undoredo/undoredo.service';
import { Univer } from '../univer';
import { FBase } from './f-base';
import { FHooks } from './f-hooks';

/**
* `FBase` is a base class for all facade classes.
* It provides a way to extend classes with static and instance methods.
* The `_initialize` as a special method that will be called after the constructor. You should never call it directly.
*/
export abstract class FBase {
private static _constructorQueue: Array<() => void> = [];

constructor() {
FBase._constructorQueue.forEach((fn) => {
fn();
});
}

_initialize() { }

static extend(source: any): void {
Object.getOwnPropertyNames(source.prototype).forEach((name) => {
if (name === '_initialize') {
FBase._constructorQueue.push(
source.prototype._initialize.bind(this)
);
} else if (name !== 'constructor') {
// @ts-ignore
this.prototype[name] = source.prototype[name];
}
});

Object.getOwnPropertyNames(source).forEach((name) => {
if (name !== 'prototype' && name !== 'name' && name !== 'length') {
// @ts-ignore
this[name] = source[name];
}
});
}
}

export class FUniver extends FBase {
/**
* Create an FUniver instance, if the injector is not provided, it will create a new Univer instance.
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export { composeInterceptors, createInterceptorKey, InterceptorEffectEnum, Inter
export type { Serializable } from './common/json';
export { MemoryCursor } from './common/memory-cursor';
export { mixinClass } from './common/mixin';
export { FBase, FUniver } from './facade/f-univer';
export { FBase } from './facade/f-base';
export { FUniver } from './facade/f-univer';
export { FHooks } from './facade/f-hooks';
export { isNumeric, isSafeNumeric } from './common/number';
export { Registry, RegistryAsMap } from './common/registry';
Expand Down
5 changes: 3 additions & 2 deletions packages/facade/src/apis/everything.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ import '@univerjs/sheets-data-validation/facade';
import '@univerjs/engine-formula/facade';
import '@univerjs/sheets-filter/facade';
import '@univerjs/sheets-formula/facade';
import '@univerjs/sheets-numfmt/facade'; // TODO: extract
import '@univerjs/sheets-hyper-link-ui/facade'; // TODO: extract
import '@univerjs/sheets-numfmt/facade'; // TODO@Gggpound: extract
import '@univerjs/sheets-hyper-link-ui/facade'; // TODO@weird94: extract
import '@univerjs/sheets-thread-comment/facade'; // TODO@weird94: extract

export { FHooks, FUniver } from '@univerjs/core';
export { FFormula } from '@univerjs/engine-formula/facade';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,20 @@
* limitations under the License.
*/

import { afterEach, beforeEach, describe, expect, it } from 'vitest';

import type { Dependency, IWorkbookData, Worksheet } from '@univerjs/core';
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Univer } from '@univerjs/core';

import type { IFindQuery } from '@univerjs/find-replace';
import { ILogService, IUniverInstanceService, LocaleType, LogLevel, Univer } from '@univerjs/core';
import { FindBy, FindDirection, FindScope } from '@univerjs/find-replace';
import { afterEach, beforeEach, describe, expect, it } from 'vitest';
import { hitCell } from '../sheet-find-replace.controller';
import {
isBeforePositionWithColumnPriority,
isBeforePositionWithRowPriority,
isBehindPositionWithColumnPriority,
isBehindPositionWithRowPriority,
isSamePosition,
} from '../utils';
import { hitCell } from '../sheet-find-replace.controller';

describe('Test sheet find replace utils', () => {
it('Should "isSamePosition" work as expected', () => {
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ad29a04

Please sign in to comment.